Skip to content

Commit

Permalink
feat(core): make context id factory getter configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed May 31, 2022
1 parent d0bb082 commit ac1c066
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/core/helpers/context-id-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ export class ContextIdFactory {
*/
public static getByRequest<T extends Record<any, any> = any>(
request: T,
propsToInspect: string[] = ['raw'],
): ContextId {
if (!request) {
return createContextId();
return ContextIdFactory.create();
}
if (request[REQUEST_CONTEXT_ID as any]) {
return request[REQUEST_CONTEXT_ID as any];
}
if (request.raw && request.raw[REQUEST_CONTEXT_ID]) {
return request.raw[REQUEST_CONTEXT_ID];
for (const key of propsToInspect) {
if (request[key]?.[REQUEST_CONTEXT_ID]) {
return request[key][REQUEST_CONTEXT_ID];
}
}
return createContextId();
return ContextIdFactory.create();
}
}

0 comments on commit ac1c066

Please sign in to comment.