Skip to content

Commit

Permalink
Merge branch 'master' into renovate-npm-definitely-typed
Browse files Browse the repository at this point in the history
  • Loading branch information
72636c authored Oct 10, 2023
2 parents 9d7f043 + fbc6f25 commit 5dd5558
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/serializers/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@ import { DEFAULT_OMIT_HEADER_NAMES, createSerializers } from '.';

const serializers = createSerializers({});

describe('DEFAULT_OMIT_HEADER_NAMES', () => {
it('disallows mutation', () => {
const firstElement = DEFAULT_OMIT_HEADER_NAMES[0];

expect(() => {
// @ts-expect-error - We're trying to break the read-only array (TS2542).
DEFAULT_OMIT_HEADER_NAMES[0] = 'badness!';
}).toThrowErrorMatchingInlineSnapshot(
`"Cannot assign to read only property '0' of object '[object Array]'"`,
);

expect(() => {
// @ts-expect-error - We're trying to break the read-only array (TS2542).
delete DEFAULT_OMIT_HEADER_NAMES[0];
}).toThrowErrorMatchingInlineSnapshot(
`"Cannot delete property '0' of [object Array]"`,
);

// Assignment didn't take effect!
expect(DEFAULT_OMIT_HEADER_NAMES[0]).toBe(firstElement);
});
});

describe('req', () => {
const remoteAddress = '::ffff:123.45.67.89';
const remotePort = 12345;
Expand Down
6 changes: 3 additions & 3 deletions src/serializers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { err, errWithCause } from 'pino-std-serializers';
import { createOmitPropertiesSerializer } from './omitPropertiesSerializer';
import type { SerializerFn } from './types';

export const DEFAULT_OMIT_HEADER_NAMES = [
export const DEFAULT_OMIT_HEADER_NAMES = Object.freeze([
'x-envoy-attempt-count',
'x-envoy-decorator-operation',
'x-envoy-expected-rq-timeout-ms',
Expand All @@ -13,7 +13,7 @@ export const DEFAULT_OMIT_HEADER_NAMES = [
'x-envoy-peer-metadata',
'x-envoy-peer-metadata-id',
'x-envoy-upstream-service-time',
];
]);

export interface SerializerOptions {
/**
Expand All @@ -28,7 +28,7 @@ export interface SerializerOptions {
* Defaults to `DEFAULT_OMIT_HEADER_NAMES`,
* and can be disabled by supplying an empty array `[]`.
*/
omitHeaderNames?: string[];
omitHeaderNames?: readonly string[];
}

interface Socket {
Expand Down
2 changes: 1 addition & 1 deletion src/serializers/omitPropertiesSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const createOmitPropertiesSerializer = (
/**
* A list of properties that should not be logged.
*/
properties: string[],
properties: readonly string[],
): SerializerFn => {
const uniquePropertySet = new Set(properties);

Expand Down

0 comments on commit 5dd5558

Please sign in to comment.