refactor: Components.js supports Record now.

This commit is contained in:
Ruben Verborgh 2020-11-30 09:40:05 +01:00
parent 6b4088723d
commit 961662b692
5 changed files with 4 additions and 21 deletions

View File

@ -10,9 +10,7 @@ import { MetadataWriter } from './MetadataWriter';
export class LinkRelMetadataWriter extends MetadataWriter { export class LinkRelMetadataWriter extends MetadataWriter {
private readonly linkRelMap: Record<string, string>; private readonly linkRelMap: Record<string, string>;
// Not supported by Components.js yet public constructor(linkRelMap: Record<string, string>) {
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
public constructor(linkRelMap: { [predicate: string]: string }) {
super(); super();
this.linkRelMap = linkRelMap; this.linkRelMap = linkRelMap;
} }

View File

@ -10,9 +10,7 @@ import { MetadataWriter } from './MetadataWriter';
export class MappedMetadataWriter extends MetadataWriter { export class MappedMetadataWriter extends MetadataWriter {
private readonly headerMap: Record<string, string>; private readonly headerMap: Record<string, string>;
// Not supported by Components.js yet public constructor(headerMap: Record<string, string>) {
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
public constructor(headerMap: { [predicate: string]: string }) {
super(); super();
this.headerMap = headerMap; this.headerMap = headerMap;
} }

View File

@ -7,9 +7,7 @@ import type { HttpResponse } from '../HttpResponse';
export class HeaderHandler extends HttpHandler { export class HeaderHandler extends HttpHandler {
private readonly headers: Record<string, string>; private readonly headers: Record<string, string>;
// Not supported by Components.js yet public constructor(headers: Record<string, string>) {
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
public constructor(headers: { [header: string]: string } = {}) {
super(); super();
this.headers = { ...headers }; this.headers = { ...headers };
} }

View File

@ -21,8 +21,7 @@ export class RegexRouterRule extends RouterRule {
/** /**
* The keys of the `storeMap` will be converted into actual RegExp objects that will be used for testing. * The keys of the `storeMap` will be converted into actual RegExp objects that will be used for testing.
*/ */
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style public constructor(base: string, storeMap: Record<string, ResourceStore>) {
public constructor(base: string, storeMap: { [ regex: string ]: ResourceStore }) {
super(); super();
this.base = trimTrailingSlashes(base); this.base = trimTrailingSlashes(base);
this.regexes = new Map(Object.keys(storeMap).map((regex): [ RegExp, ResourceStore ] => this.regexes = new Map(Object.keys(storeMap).map((regex): [ RegExp, ResourceStore ] =>

View File

@ -3,16 +3,6 @@ import { HeaderHandler } from '../../../../src/server/middleware/HeaderHandler';
import { guardStream } from '../../../../src/util/GuardedStream'; import { guardStream } from '../../../../src/util/GuardedStream';
describe('a HeaderHandler', (): void => { describe('a HeaderHandler', (): void => {
it('adds no headers when none are configured.', async(): Promise<void> => {
const handler = new HeaderHandler();
const request = guardStream(createRequest());
const response = createResponse();
await handler.handleSafe({ request, response });
expect(response.getHeaders()).toEqual({});
});
it('adds all configured headers.', async(): Promise<void> => { it('adds all configured headers.', async(): Promise<void> => {
const headers = { custom: 'Custom', other: 'Other' }; const headers = { custom: 'Custom', other: 'Other' };
const handler = new HeaderHandler(headers); const handler = new HeaderHandler(headers);