Skip to content

Commit ece71aa

Browse files
committed
feat: restrict allowed context values to serializable object
1 parent c751beb commit ece71aa

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/factories/createLogger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const createLogger = (
7979
...parentContext,
8080
};
8181
} else {
82-
context = parentContext || defaultContext;
82+
context = parentContext ?? defaultContext;
8383
}
8484
} else {
8585
context = {
@@ -161,7 +161,7 @@ export const createLogger = (
161161
log.getContext = () => {
162162
return {
163163
...getAsyncLocalContext(),
164-
...parentContext || defaultContext,
164+
...parentContext ?? defaultContext,
165165
};
166166
};
167167

src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import type {
22
AsyncLocalStorage,
33
} from 'async_hooks';
44

5+
export type JsonObject = { [key: string]: JsonValue, };
6+
7+
export type JsonValue = JsonObject | JsonValue[] | boolean | number | string | null;
8+
59
export type LogWriter = (message: string) => void;
610

7-
export type MessageContext = any;
11+
export type MessageContext = JsonObject;
812

913
export type RoarrGlobalState = {
1014
asyncLocalStorage?: AsyncLocalStorage<MessageContext>,

0 commit comments

Comments
 (0)