From 6688b020867445541041980650190c32a32b398c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0vanda?= <46406259+Papooch@users.noreply.github.com> Date: Wed, 21 Sep 2022 11:56:18 +0200 Subject: [PATCH] fix: expose terminal type (#43) --- src/index.ts | 1 + src/lib/cls.service.spec.ts | 2 +- src/types/recursive-key-of.type.ts | 8 ++------ src/types/terminal.type.ts | 10 ++++++++++ 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 src/types/terminal.type.ts diff --git a/src/index.ts b/src/index.ts index 26020f66..52c5307d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,3 +7,4 @@ export * from './lib/cls.module'; export * from './lib/cls.service'; export * from './lib/cls.decorators'; export * from './lib/cls.interfaces'; +export { Terminal } from './types/terminal.type'; diff --git a/src/lib/cls.service.spec.ts b/src/lib/cls.service.spec.ts index 6e7cf720..b6f8b3f3 100644 --- a/src/lib/cls.service.spec.ts +++ b/src/lib/cls.service.spec.ts @@ -1,5 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { Terminal } from '../types/recursive-key-of.type'; +import { Terminal } from '../types/terminal.type'; import { ClsServiceManager } from './cls-service-manager'; import { CLS_DEFAULT_NAMESPACE, CLS_ID } from './cls.constants'; import { ClsStore } from './cls.interfaces'; diff --git a/src/types/recursive-key-of.type.ts b/src/types/recursive-key-of.type.ts index 1eaeec8d..fffe5ec7 100644 --- a/src/types/recursive-key-of.type.ts +++ b/src/types/recursive-key-of.type.ts @@ -1,3 +1,5 @@ +import { BrandedTerminal } from './terminal.type'; + type TerminalType = | string | number @@ -13,12 +15,6 @@ type TerminalType = | BrandedTerminal | ((...args: any) => any); -const TERMINAL_BRAND = Symbol(); -class BrandedTerminal { - private [TERMINAL_BRAND]?: void; -} -export type Terminal = T & BrandedTerminal; - /** * Deep nested keys of an interface with dot syntax * diff --git a/src/types/terminal.type.ts b/src/types/terminal.type.ts new file mode 100644 index 00000000..4a42eb65 --- /dev/null +++ b/src/types/terminal.type.ts @@ -0,0 +1,10 @@ +const TERMINAL_BRAND = Symbol(); +export class BrandedTerminal { + private [TERMINAL_BRAND]?: void; +} + +/** + * Use the terminal type to prevent generation of property + * paths to nested properties of the type within the ClsStore + */ +export type Terminal = T & BrandedTerminal;