@venizia/ignis-helpers 0.4.7-1 → 0.4.7-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +3 -3
  2. package/dist/esm/core.d.ts +1 -2
  3. package/dist/esm/core.d.ts.map +1 -1
  4. package/dist/esm/core.js +3 -2
  5. package/dist/esm/core.js.map +1 -1
  6. package/dist/esm/modules/base.d.ts +1 -1
  7. package/dist/esm/modules/base.d.ts.map +1 -1
  8. package/dist/esm/modules/base.js +14 -5
  9. package/dist/esm/modules/base.js.map +1 -1
  10. package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts +15 -5
  11. package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts.map +1 -1
  12. package/dist/esm/modules/crypto/algorithms/hash.algorithm.js +16 -4
  13. package/dist/esm/modules/crypto/algorithms/hash.algorithm.js.map +1 -1
  14. package/dist/esm/modules/logger/base/base.d.ts.map +1 -1
  15. package/dist/esm/modules/logger/base/base.js +3 -3
  16. package/dist/esm/modules/logger/base/base.js.map +1 -1
  17. package/dist/esm/modules/logger/base/console.d.ts +9 -4
  18. package/dist/esm/modules/logger/base/console.d.ts.map +1 -1
  19. package/dist/esm/modules/logger/base/console.js +15 -4
  20. package/dist/esm/modules/logger/base/console.js.map +1 -1
  21. package/dist/esm/modules/logger/common/constants.d.ts +0 -1
  22. package/dist/esm/modules/logger/common/constants.d.ts.map +1 -1
  23. package/dist/esm/modules/logger/common/constants.js +0 -6
  24. package/dist/esm/modules/logger/common/constants.js.map +1 -1
  25. package/dist/esm/modules/logger/common/debug-gate.d.ts +33 -0
  26. package/dist/esm/modules/logger/common/debug-gate.d.ts.map +1 -0
  27. package/dist/esm/modules/logger/common/debug-gate.js +51 -0
  28. package/dist/esm/modules/logger/common/debug-gate.js.map +1 -0
  29. package/dist/esm/modules/logger/common/index.d.ts +1 -0
  30. package/dist/esm/modules/logger/common/index.d.ts.map +1 -1
  31. package/dist/esm/modules/logger/common/index.js +1 -0
  32. package/dist/esm/modules/logger/common/index.js.map +1 -1
  33. package/dist/esm/modules/logger/common/types.d.ts +7 -0
  34. package/dist/esm/modules/logger/common/types.d.ts.map +1 -1
  35. package/dist/esm/modules/logger/common/types.js +16 -0
  36. package/dist/esm/modules/logger/common/types.js.map +1 -1
  37. package/dist/esm/modules/logger/factory.d.ts +29 -12
  38. package/dist/esm/modules/logger/factory.d.ts.map +1 -1
  39. package/dist/esm/modules/logger/factory.js +108 -50
  40. package/dist/esm/modules/logger/factory.js.map +1 -1
  41. package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
  42. package/dist/esm/modules/logger/hf/logger.js +3 -3
  43. package/dist/esm/modules/logger/hf/logger.js.map +1 -1
  44. package/dist/esm/modules/logger/index.d.ts +0 -1
  45. package/dist/esm/modules/logger/index.d.ts.map +1 -1
  46. package/dist/esm/modules/logger/index.js +0 -1
  47. package/dist/esm/modules/logger/index.js.map +1 -1
  48. package/dist/esm/utilities/module.utility.d.ts.map +1 -1
  49. package/dist/esm/utilities/module.utility.js +1 -0
  50. package/dist/esm/utilities/module.utility.js.map +1 -1
  51. package/dist/esm/utilities/request.utility.d.ts.map +1 -1
  52. package/dist/esm/utilities/request.utility.js +1 -0
  53. package/dist/esm/utilities/request.utility.js.map +1 -1
  54. package/package.json +2 -2
  55. package/dist/esm/modules/logger/resolver.d.ts +0 -33
  56. package/dist/esm/modules/logger/resolver.d.ts.map +0 -1
  57. package/dist/esm/modules/logger/resolver.js +0 -95
  58. package/dist/esm/modules/logger/resolver.js.map +0 -1
  59. package/dist/esm/modules/logger/slot.d.ts +0 -44
  60. package/dist/esm/modules/logger/slot.d.ts.map +0 -1
  61. package/dist/esm/modules/logger/slot.js +0 -126
  62. package/dist/esm/modules/logger/slot.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"module.utility.js","sourceRoot":"","sources":["../../../src/utilities/module.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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ACH,MAAM,CAAC,QAAQ,CAAc,IAAwB;QACnD,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAExB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAM,CAAC;QAC1C,CAAC;QAED,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,CAAM,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,eAAe,CAAC,IAItB;QACC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;QACzD,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAErC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,eAAe,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBACnD,SAAS;YACX,CAAC;YAED,IAAI,CAAC;gBACH,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;IACH,CAAC","sourcesContent":["import { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { AnyType } from '@/common/types';\nimport { LoggerFactory } from '@/modules/logger';\nimport { getError } from '@/modules/error';\nimport { ProjectRootRegistry } from './project-root.utility';\n\nconst logger = LoggerFactory.getLogger(['ModuleUtility']);\n\n/** Loads an optional peer without letting `Bun.build` see it: every specifier stays a parameter, so there is no literal (nor a `minify.syntax`-folded const) for the bundler to resolve. */\nexport class ModuleUtility {\n /** Peers handed over by the application, keyed by specifier. Checked before any filesystem lookup. The map lives in a globalThis slot because a process (or a compiled bundle) can carry two copies of this module, and a peer registered through one copy must be found by the other. */\n private static readonly registered: Map<string, AnyType> = ModuleUtility.sharedRegistry();\n\n private static sharedRegistry(): Map<string, AnyType> {\n const slot = Symbol.for('ignis:module-registry');\n const shared: Map<string, AnyType> | undefined = Reflect.get(globalThis, slot);\n if (shared) {\n return shared;\n }\n\n const created = new Map<string, AnyType>();\n Reflect.set(globalThis, slot, created);\n\n return created;\n }\n\n /** Called by the application once it knows its root (`configs.projectRoot` or the cwd); every peer lookup below follows it. Delegates to `ProjectRootRegistry`, which a browser Worker host reaches too through `/core` - the two must share ONE slot. */\n static setProjectRoot(opts: { projectRoot: string }): void {\n ProjectRootRegistry.set(opts);\n }\n\n static getProjectRoot(): string {\n return ProjectRootRegistry.getShared() ?? process.cwd();\n }\n\n /** Resolves peers against the APP's node_modules (under the project root), not this package's own `dist/` location. */\n private static appRequire() {\n return createRequire(path.join(this.getProjectRoot(), 'node_modules'));\n }\n\n private static fail(opts: { method: string; module: string; error: unknown; scope?: string }) {\n const { method, module, error, scope } = opts;\n const reason = error instanceof Error ? error.message : String(error);\n\n logger.for(method).error(\"Failed to load '%s' | Error: %s\", module, reason);\n\n return getError({\n message: `[ModuleUtility.${method}] ${module} is required, resolved from ${this.getProjectRoot()}${\n scope ? ` for ${scope}` : ''\n }. Please install '${module}' | Error: ${reason}`,\n });\n }\n\n /**\n * Hands the framework a peer the application already holds, so no filesystem lookup is needed.\n * A `bun build --compile` binary ships without `node_modules`, which leaves runtime resolution\n * nothing to resolve against: the application imports such a peer statically - that import is\n * what gets it into the binary - and registers it here before the consuming component boots.\n *\n * Deliberately does not log. It runs at the entrypoint of exactly the deployment that has no\n * logger provider yet, where `LoggerFactory` throws - and a throw mid-loop would drop every\n * module after the first.\n */\n static register(opts: { modules: Record<string, AnyType> }): void {\n const modulesEntries = Object.entries(opts.modules);\n for (const [module, value] of modulesEntries) {\n this.registered.set(module, value);\n }\n }\n\n /**\n * The file `module` resolves to from the project root under the ES module conditions (`import`), so\n * the peer is the very instance an application's own `import` of it gets. `undefined` when it does not\n * resolve there or the runtime has no resolver: the caller falls back to a plain `import()`.\n */\n private static resolveEsmFile(opts: { module: string }): string | undefined {\n if (typeof Bun === 'undefined') {\n return undefined;\n }\n\n try {\n const file = Bun.resolveSync(opts.module, this.getProjectRoot());\n return path.isAbsolute(file) ? file : undefined;\n } catch {\n return undefined;\n }\n }\n\n /**\n * Loads the module as an ES module, resolved from the project root: a peer that ships both builds\n * (`bullmq`, `socket.io-client`) is loaded as the copy the application's own `import` gets, not a second\n * one. A module handed over with {@link register} wins; one that does not resolve from the project root is\n * imported by name as before. Use this everywhere except a constructor, which cannot await - see {@link preload}.\n */\n static async load<T = AnyType>(opts: { module: string }): Promise<T> {\n const { module } = opts;\n\n if (this.registered.has(module)) {\n return this.registered.get(module) as T;\n }\n\n try {\n const file = this.resolveEsmFile({ module });\n const result = await import(file === undefined ? module : pathToFileURL(file).href);\n return result as T;\n } catch (error) {\n throw this.fail({ method: 'load', module, error });\n }\n }\n\n /**\n * The explicit register path for what a constructor needs: loads each module with {@link load} and\n * registers it, so the synchronous {@link loadSync} returns that ES module copy afterwards. Call it once\n * at the entrypoint, before the helpers are constructed. A module already registered is kept; every module\n * is loaded before any is registered, so one that is missing registers nothing.\n */\n static async preload(opts: { modules: Array<string> }): Promise<void> {\n const loaded: Record<string, AnyType> = {};\n\n for (const module of opts.modules) {\n // `load` answers from the registry first, so a module the application handed over comes back as itself.\n const result = await this.load({ module });\n loaded[module] = result;\n }\n\n this.register({ modules: loaded });\n }\n\n /**\n * Sync twin of {@link load}, for a constructor or any path that cannot await. It resolves with\n * `require`, so a peer that ships both builds comes back as its CommonJS copy - a second instance next to\n * the one an application's `import` holds, and `instanceof` across the two fails. `await preload(...)` at the\n * entrypoint registers the ES module copy first, and this returns that.\n */\n static loadSync<T = AnyType>(opts: { module: string }): T {\n const { module } = opts;\n\n if (this.registered.has(module)) {\n return this.registered.get(module) as T;\n }\n\n try {\n return this.appRequire()(module) as T;\n } catch (error) {\n throw this.fail({ method: 'loadSync', module, error });\n }\n }\n\n /**\n * Presence check only - throws naming what to install, without executing the module.\n *\n * `allowRegistered` must be set only where {@link load} or {@link loadSync} is what finally loads\n * the module. Where the consumer resolves the specifier itself - `pino.transport()` inside a\n * worker thread, or any caller with its own `createRequire` - the registry cannot reach it, and\n * counting a registration as installed would replace this precise error with an opaque one.\n */\n static assertInstalled(opts: {\n modules: Array<string>;\n scope?: string;\n allowRegistered?: boolean;\n }): void {\n const { modules, scope, allowRegistered = false } = opts;\n const appRequire = this.appRequire();\n\n for (const module of modules) {\n if (allowRegistered && this.registered.has(module)) {\n continue;\n }\n\n try {\n appRequire.resolve(module);\n } catch (error) {\n throw this.fail({ method: 'assertInstalled', module, error, scope });\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"module.utility.js","sourceRoot":"","sources":["../../../src/utilities/module.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;AAE1D,4LAA4L;AAC5L,MAAM,OAAO,aAAa;IACxB,0RAA0R;aAClQ,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AAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,eAAe,CAAC,IAItB;QACC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;QACzD,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAErC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,eAAe,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBACnD,SAAS;YACX,CAAC;YAED,IAAI,CAAC;gBACH,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;IACH,CAAC","sourcesContent":["import { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { AnyType } from '@/common/types';\nimport { LoggerFactory } from '@/modules/logger';\nimport { getError } from '@/modules/error';\nimport { ProjectRootRegistry } from './project-root.utility';\n\nconst logger = LoggerFactory.getLogger(['ModuleUtility']);\n\n/** Loads an optional peer without letting `Bun.build` see it: every specifier stays a parameter, so there is no literal (nor a `minify.syntax`-folded const) for the bundler to resolve. */\nexport class ModuleUtility {\n /** Peers handed over by the application, keyed by specifier. Checked before any filesystem lookup. The map lives in a globalThis slot because a process (or a compiled bundle) can carry two copies of this module, and a peer registered through one copy must be found by the other. */\n private static readonly registered: Map<string, AnyType> = ModuleUtility.sharedRegistry();\n\n private static sharedRegistry(): Map<string, AnyType> {\n const slot = Symbol.for('ignis:module-registry');\n const shared: Map<string, AnyType> | undefined = Reflect.get(globalThis, slot);\n if (shared) {\n return shared;\n }\n\n const created = new Map<string, AnyType>();\n Reflect.set(globalThis, slot, created);\n\n return created;\n }\n\n /** Called by the application once it knows its root (`configs.projectRoot` or the cwd); every peer lookup below follows it. Delegates to `ProjectRootRegistry`, which a browser Worker host reaches too through `/core` - the two must share ONE slot. */\n static setProjectRoot(opts: { projectRoot: string }): void {\n ProjectRootRegistry.set(opts);\n }\n\n static getProjectRoot(): string {\n return ProjectRootRegistry.getShared() ?? process.cwd();\n }\n\n /** Resolves peers against the APP's node_modules (under the project root), not this package's own `dist/` location. */\n private static appRequire() {\n return createRequire(path.join(this.getProjectRoot(), 'node_modules'));\n }\n\n private static fail(opts: { method: string; module: string; error: unknown; scope?: string }) {\n const { method, module, error, scope } = opts;\n const reason = error instanceof Error ? error.message : String(error);\n\n logger.for(method).error(\"Failed to load '%s' | Error: %s\", module, reason);\n\n return getError({\n message: `[ModuleUtility.${method}] ${module} is required, resolved from ${this.getProjectRoot()}${\n scope ? ` for ${scope}` : ''\n }. Please install '${module}' | Error: ${reason}`,\n });\n }\n\n /**\n * Hands the framework a peer the application already holds, so no filesystem lookup is needed.\n * A `bun build --compile` binary ships without `node_modules`, which leaves runtime resolution\n * nothing to resolve against: the application imports such a peer statically - that import is\n * what gets it into the binary - and registers it here before the consuming component boots.\n *\n * Deliberately does not log. It runs at the entrypoint of exactly the deployment that has no\n * logger provider yet, where `LoggerFactory` throws - and a throw mid-loop would drop every\n * module after the first.\n */\n static register(opts: { modules: Record<string, AnyType> }): void {\n const modulesEntries = Object.entries(opts.modules);\n for (const [module, value] of modulesEntries) {\n this.registered.set(module, value);\n }\n }\n\n /**\n * The file `module` resolves to from the project root under the ES module conditions (`import`), so\n * the peer is the very instance an application's own `import` of it gets. `undefined` when it does not\n * resolve there or the runtime has no resolver: the caller falls back to a plain `import()`.\n */\n private static resolveEsmFile(opts: { module: string }): string | undefined {\n if (typeof Bun === 'undefined') {\n return undefined;\n }\n\n try {\n const file = Bun.resolveSync(opts.module, this.getProjectRoot());\n return path.isAbsolute(file) ? file : undefined;\n // eslint-disable-next-line venizia/no-silent-catch -- documented contract: an unresolvable module is `undefined` and the caller falls back to a plain `import()`\n } catch {\n return undefined;\n }\n }\n\n /**\n * Loads the module as an ES module, resolved from the project root: a peer that ships both builds\n * (`bullmq`, `socket.io-client`) is loaded as the copy the application's own `import` gets, not a second\n * one. A module handed over with {@link register} wins; one that does not resolve from the project root is\n * imported by name as before. Use this everywhere except a constructor, which cannot await - see {@link preload}.\n */\n static async load<T = AnyType>(opts: { module: string }): Promise<T> {\n const { module } = opts;\n\n if (this.registered.has(module)) {\n return this.registered.get(module) as T;\n }\n\n try {\n const file = this.resolveEsmFile({ module });\n const result = await import(file === undefined ? module : pathToFileURL(file).href);\n return result as T;\n } catch (error) {\n throw this.fail({ method: 'load', module, error });\n }\n }\n\n /**\n * The explicit register path for what a constructor needs: loads each module with {@link load} and\n * registers it, so the synchronous {@link loadSync} returns that ES module copy afterwards. Call it once\n * at the entrypoint, before the helpers are constructed. A module already registered is kept; every module\n * is loaded before any is registered, so one that is missing registers nothing.\n */\n static async preload(opts: { modules: Array<string> }): Promise<void> {\n const loaded: Record<string, AnyType> = {};\n\n for (const module of opts.modules) {\n // `load` answers from the registry first, so a module the application handed over comes back as itself.\n const result = await this.load({ module });\n loaded[module] = result;\n }\n\n this.register({ modules: loaded });\n }\n\n /**\n * Sync twin of {@link load}, for a constructor or any path that cannot await. It resolves with\n * `require`, so a peer that ships both builds comes back as its CommonJS copy - a second instance next to\n * the one an application's `import` holds, and `instanceof` across the two fails. `await preload(...)` at the\n * entrypoint registers the ES module copy first, and this returns that.\n */\n static loadSync<T = AnyType>(opts: { module: string }): T {\n const { module } = opts;\n\n if (this.registered.has(module)) {\n return this.registered.get(module) as T;\n }\n\n try {\n return this.appRequire()(module) as T;\n } catch (error) {\n throw this.fail({ method: 'loadSync', module, error });\n }\n }\n\n /**\n * Presence check only - throws naming what to install, without executing the module.\n *\n * `allowRegistered` must be set only where {@link load} or {@link loadSync} is what finally loads\n * the module. Where the consumer resolves the specifier itself - `pino.transport()` inside a\n * worker thread, or any caller with its own `createRequire` - the registry cannot reach it, and\n * counting a registration as installed would replace this precise error with an opaque one.\n */\n static assertInstalled(opts: {\n modules: Array<string>;\n scope?: string;\n allowRegistered?: boolean;\n }): void {\n const { modules, scope, allowRegistered = false } = opts;\n const appRequire = this.appRequire();\n\n for (const module of modules) {\n if (allowRegistered && this.registered.has(module)) {\n continue;\n }\n\n try {\n appRequire.resolve(module);\n } catch (error) {\n throw this.fail({ method: 'assertInstalled', module, error, scope });\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"request.utility.d.ts","sourceRoot":"","sources":["../../../src/utilities/request.utility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMlD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CAC/B;AAED,4HAA4H;AAC5H,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAE9B,MAAM,CAAC,QAAQ,CAAC,UAAU,cAA6C;IAEvE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGvC;AAED,sCAAsC;AACtC,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEtE,UAAU,sBAAsB,CAAC,CAAC,SAAS;IAAE,GAAG,EAAE,GAAG,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,GAAG,CAAA;CAAE;IACpE,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,SAAS,CAAC,EAAE,MAA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AAC;KAC/B,GAAG,MAAM;IAaV;;;;;;;;;OASG;IACH,MAAM,CAAC,uBAAuB,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;KAAE,GAAG;QAC3E,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;CAgCF"}
@@ -128,6 +128,7 @@ export class RequestUtility {
128
128
  const encoded = value.slice(value.lastIndexOf("'") + 1);
129
129
  try {
130
130
  return { type, filename: decodeURIComponent(encoded) };
131
+ // eslint-disable-next-line venizia/no-silent-catch -- a malformed `filename*` falls through to the plain `filename` parameter; only the extended name is lost
131
132
  }
132
133
  catch {
133
134
  // A malformed sequence is not worth failing a download over - fall through to `filename`.
@@ -1 +1 @@
1
- {"version":3,"file":"request.utility.js","sourceRoot":"","sources":["../../../src/utilities/request.utility.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAS7B,4HAA4H;AAC5H,MAAM,OAAO,iBAAiB;aACZ,WAAM,GAAG,QAAQ,CAAC;aAClB,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEvE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AA6BH,8SAA8S;AAC9S,MAAM,+BAA+B,GAAG,gCAAgC,CAAC;AACzE,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B,4EAA4E;AAC5E,MAAM,OAAO,uBAAuB;aAClB,eAAU,GAAG,Y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AO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAC/D,CAAC;CACF","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { getError } from '@/modules/error';\nimport { FormBodyUtility } from './form-body.utility';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface IRequestedRemark {\n id: string;\n url: string;\n method: string;\n [extra: string | symbol]: any;\n}\n\n/** Where `RequestUtility.parseMultipartBody` keeps an uploaded file: MEMORY (a buffer) or DISK (spooled to `uploadDir`). */\nexport class MultipartStorages {\n static readonly MEMORY = 'memory';\n static readonly DISK = 'disk';\n\n static readonly SCHEME_SET = new Set<string>([this.MEMORY, this.DISK]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid multipart storage values. */\nexport type TMultipartStorage = TConstValue<typeof MultipartStorages>;\n\ninterface IParseMultipartOptions<C extends { req: any } = { req: any }> {\n storage?: TMultipartStorage;\n uploadDir?: string;\n context: C;\n}\n\ninterface IParsedFile {\n fieldname: string;\n originalname: string;\n encoding: string;\n mimetype: string;\n size: number;\n buffer?: Buffer;\n filename?: string;\n path?: string;\n}\n\n/** Files and the text fields posted beside them - dropping the second silently loses what the client sent. */\nexport interface IParsedMultipartBody {\n files: IParsedFile[];\n fields: Record<string, string>;\n}\n\n/** Control, format (bidi overrides, zero-width space) and lone surrogate characters: a format character reorders the name a client shows, a lone surrogate makes `encodeURIComponent` throw. The zero-width joiner and non-joiner stay: they build emoji sequences and Persian words, and reorder nothing. */\nconst UNENCODABLE_FILENAME_CHARACTERS = /(?![‌‍])[\\p{Cc}\\p{Cf}\\p{Cs}]/gu;\nconst LEADING_DOTS = /^\\.+/;\n\n/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */\nexport class ContentDispositionTypes {\n static readonly ATTACHMENT = 'attachment';\n static readonly INLINE = 'inline';\n\n static readonly SCHEME_SET = new Set<string>([this.ATTACHMENT, this.INLINE]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid Content-Disposition type values. */\nexport type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;\n\nexport class RequestUtility {\n static async parseMultipartBody<C extends { req: any } = { req: any }>(\n opts: IParseMultipartOptions<C>,\n ): Promise<IParsedMultipartBody> {\n const { storage = MultipartStorages.MEMORY, uploadDir = './uploads', context } = opts;\n\n if (storage === MultipartStorages.DISK && !fs.existsSync(uploadDir)) {\n fs.mkdirSync(uploadDir, { recursive: true });\n }\n\n const formData = await FormBodyUtility.readFormBody({ req: context.req });\n const files: IParsedFile[] = [];\n const fields: Record<string, string> = {};\n\n const entries = formData.entries();\n for (const [fieldname, value] of entries) {\n if (typeof value === 'string') {\n // Last one wins, like a repeated query parameter.\n fields[fieldname] = value;\n continue;\n }\n\n const file = value as File;\n const arrayBuffer = await file.arrayBuffer();\n const buffer = Buffer.from(arrayBuffer);\n\n const parsedFile: IParsedFile = {\n fieldname,\n originalname: file.name,\n encoding: 'utf8',\n mimetype: file.type,\n size: file.size,\n };\n\n switch (storage) {\n case MultipartStorages.MEMORY: {\n parsedFile.buffer = buffer;\n break;\n }\n case MultipartStorages.DISK: {\n const timestamp = Date.now();\n const randomString = Math.random().toString(36).substring(7);\n // Sanitize filename to prevent path traversal\n const sanitizedName = path.basename(file.name).replace(/[^a-zA-Z0-9._-]/g, '_');\n const filename = `${timestamp}-${randomString}-${sanitizedName}`;\n const filepath = path.join(uploadDir, filename);\n\n fs.writeFileSync(filepath, buffer);\n\n parsedFile.filename = filename;\n parsedFile.path = filepath;\n break;\n }\n default: {\n throw getError({\n message: `[parseMultipartBody] storage: ${storage} | Invalid storage type | Valids: ['memory', 'disk']`,\n });\n }\n }\n\n files.push(parsedFile);\n }\n\n return { files, fields };\n }\n\n /** Sanitizes a filename by removing path components and dangerous characters. The result is printable ASCII. */\n static sanitizeFilename(opts: { filename: string }): string {\n const basename = path.basename(opts.filename);\n let sanitized = basename.replace(/[^\\w .-]/g, '_');\n sanitized = sanitized.replace(/^\\.+/, '');\n sanitized = sanitized.replace(/\\.{2,}/g, '.');\n sanitized = sanitized.replace(/\\.\\./g, '.');\n if (!sanitized || sanitized === '.' || sanitized.includes('..')) {\n sanitized = 'download';\n }\n return sanitized;\n }\n\n static encodeRfc5987(opts: { filename: string }): string {\n return encodeURIComponent(opts.filename)\n .replace(/['()]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase())\n .replace(/\\*/g, '%2A');\n }\n\n static buildContentDispositionHeader(opts: {\n filename: string;\n type: TContentDispositionType;\n }): string {\n const { filename, type } = opts;\n const sanitized = RequestUtility.sanitizeFilename({ filename });\n const extendedName = path\n .basename(filename)\n .replace(UNENCODABLE_FILENAME_CHARACTERS, '_')\n .replace(LEADING_DOTS, '');\n const encoded = RequestUtility.encodeRfc5987({ filename: extendedName || sanitized });\n\n // filename= is the ASCII fallback for old browsers, filename*= the UTF-8 form for modern ones.\n return `${type}; filename=\"${sanitized}\"; filename*=UTF-8''${encoded}`;\n }\n\n /**\n * Reads a filename out of a `Content-Disposition` value.\n *\n * Three forms, in the order the RFC gives them precedence: `filename*=UTF-8''...` (percent-encoded,\n * and the one hand-rolled parsers miss), a quoted `filename=\"...\"`, and a bare `filename=...`.\n * Splitting on `filename=` alone returns the percent-encoded bytes for any non-ASCII name, which in\n * a product with non-English filenames is most of them.\n *\n * The pair of {@link RequestUtility.buildContentDispositionHeader}: one writes the header, this one reads it.\n */\n static parseContentDisposition(opts: { header: string | null | undefined }): {\n type?: string;\n filename?: string;\n } {\n const { header } = opts;\n\n if (!header) {\n return {};\n }\n\n const type = header.split(';')[0]?.trim() || undefined;\n\n // `filename*` wins when both are present - it is the one that can carry a non-ASCII name.\n const extended = header.match(/filename\\*\\s*=\\s*([^;]+)/i);\n if (extended) {\n const value = extended[1].trim();\n // `UTF-8''name` or `UTF-8'lang'name`; anything before the last quote is charset and language.\n const encoded = value.slice(value.lastIndexOf(\"'\") + 1);\n\n try {\n return { type, filename: decodeURIComponent(encoded) };\n } catch {\n // A malformed sequence is not worth failing a download over - fall through to `filename`.\n }\n }\n\n const quoted = header.match(/filename\\s*=\\s*\"([^\"]*)\"/i);\n if (quoted) {\n return { type, filename: quoted[1] };\n }\n\n const bare = header.match(/filename\\s*=\\s*([^;]+)/i);\n return { type, filename: bare ? bare[1].trim() : undefined };\n }\n}\n"]}
1
+ {"version":3,"file":"request.utility.js","sourceRoot":"","sources":["../../../src/utilities/request.utility.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAS7B,4HAA4H;AAC5H,MAAM,OAAO,iBAAiB;aACZ,WAAM,GAAG,QAAQ,CAAC;aAClB,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEvE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AA6BH,8SAA8S;AAC9S,MAAM,+BAA+B,GAAG,gCAAgC,CAAC;AACzE,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B,4EAA4E;AAC5E,MAAM,OAAO,uBAAuB;aAClB,eAAU,GAAG,YAAY,CAAC;aAC1B,WAAM,GAAG,QAAQ,C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AAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAC/D,CAAC;CACF","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { getError } from '@/modules/error';\nimport { FormBodyUtility } from './form-body.utility';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface IRequestedRemark {\n id: string;\n url: string;\n method: string;\n [extra: string | symbol]: any;\n}\n\n/** Where `RequestUtility.parseMultipartBody` keeps an uploaded file: MEMORY (a buffer) or DISK (spooled to `uploadDir`). */\nexport class MultipartStorages {\n static readonly MEMORY = 'memory';\n static readonly DISK = 'disk';\n\n static readonly SCHEME_SET = new Set<string>([this.MEMORY, this.DISK]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid multipart storage values. */\nexport type TMultipartStorage = TConstValue<typeof MultipartStorages>;\n\ninterface IParseMultipartOptions<C extends { req: any } = { req: any }> {\n storage?: TMultipartStorage;\n uploadDir?: string;\n context: C;\n}\n\ninterface IParsedFile {\n fieldname: string;\n originalname: string;\n encoding: string;\n mimetype: string;\n size: number;\n buffer?: Buffer;\n filename?: string;\n path?: string;\n}\n\n/** Files and the text fields posted beside them - dropping the second silently loses what the client sent. */\nexport interface IParsedMultipartBody {\n files: IParsedFile[];\n fields: Record<string, string>;\n}\n\n/** Control, format (bidi overrides, zero-width space) and lone surrogate characters: a format character reorders the name a client shows, a lone surrogate makes `encodeURIComponent` throw. The zero-width joiner and non-joiner stay: they build emoji sequences and Persian words, and reorder nothing. */\nconst UNENCODABLE_FILENAME_CHARACTERS = /(?![‌‍])[\\p{Cc}\\p{Cf}\\p{Cs}]/gu;\nconst LEADING_DOTS = /^\\.+/;\n\n/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */\nexport class ContentDispositionTypes {\n static readonly ATTACHMENT = 'attachment';\n static readonly INLINE = 'inline';\n\n static readonly SCHEME_SET = new Set<string>([this.ATTACHMENT, this.INLINE]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid Content-Disposition type values. */\nexport type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;\n\nexport class RequestUtility {\n static async parseMultipartBody<C extends { req: any } = { req: any }>(\n opts: IParseMultipartOptions<C>,\n ): Promise<IParsedMultipartBody> {\n const { storage = MultipartStorages.MEMORY, uploadDir = './uploads', context } = opts;\n\n if (storage === MultipartStorages.DISK && !fs.existsSync(uploadDir)) {\n fs.mkdirSync(uploadDir, { recursive: true });\n }\n\n const formData = await FormBodyUtility.readFormBody({ req: context.req });\n const files: IParsedFile[] = [];\n const fields: Record<string, string> = {};\n\n const entries = formData.entries();\n for (const [fieldname, value] of entries) {\n if (typeof value === 'string') {\n // Last one wins, like a repeated query parameter.\n fields[fieldname] = value;\n continue;\n }\n\n const file = value as File;\n const arrayBuffer = await file.arrayBuffer();\n const buffer = Buffer.from(arrayBuffer);\n\n const parsedFile: IParsedFile = {\n fieldname,\n originalname: file.name,\n encoding: 'utf8',\n mimetype: file.type,\n size: file.size,\n };\n\n switch (storage) {\n case MultipartStorages.MEMORY: {\n parsedFile.buffer = buffer;\n break;\n }\n case MultipartStorages.DISK: {\n const timestamp = Date.now();\n const randomString = Math.random().toString(36).substring(7);\n // Sanitize filename to prevent path traversal\n const sanitizedName = path.basename(file.name).replace(/[^a-zA-Z0-9._-]/g, '_');\n const filename = `${timestamp}-${randomString}-${sanitizedName}`;\n const filepath = path.join(uploadDir, filename);\n\n fs.writeFileSync(filepath, buffer);\n\n parsedFile.filename = filename;\n parsedFile.path = filepath;\n break;\n }\n default: {\n throw getError({\n message: `[parseMultipartBody] storage: ${storage} | Invalid storage type | Valids: ['memory', 'disk']`,\n });\n }\n }\n\n files.push(parsedFile);\n }\n\n return { files, fields };\n }\n\n /** Sanitizes a filename by removing path components and dangerous characters. The result is printable ASCII. */\n static sanitizeFilename(opts: { filename: string }): string {\n const basename = path.basename(opts.filename);\n let sanitized = basename.replace(/[^\\w .-]/g, '_');\n sanitized = sanitized.replace(/^\\.+/, '');\n sanitized = sanitized.replace(/\\.{2,}/g, '.');\n sanitized = sanitized.replace(/\\.\\./g, '.');\n if (!sanitized || sanitized === '.' || sanitized.includes('..')) {\n sanitized = 'download';\n }\n return sanitized;\n }\n\n static encodeRfc5987(opts: { filename: string }): string {\n return encodeURIComponent(opts.filename)\n .replace(/['()]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase())\n .replace(/\\*/g, '%2A');\n }\n\n static buildContentDispositionHeader(opts: {\n filename: string;\n type: TContentDispositionType;\n }): string {\n const { filename, type } = opts;\n const sanitized = RequestUtility.sanitizeFilename({ filename });\n const extendedName = path\n .basename(filename)\n .replace(UNENCODABLE_FILENAME_CHARACTERS, '_')\n .replace(LEADING_DOTS, '');\n const encoded = RequestUtility.encodeRfc5987({ filename: extendedName || sanitized });\n\n // filename= is the ASCII fallback for old browsers, filename*= the UTF-8 form for modern ones.\n return `${type}; filename=\"${sanitized}\"; filename*=UTF-8''${encoded}`;\n }\n\n /**\n * Reads a filename out of a `Content-Disposition` value.\n *\n * Three forms, in the order the RFC gives them precedence: `filename*=UTF-8''...` (percent-encoded,\n * and the one hand-rolled parsers miss), a quoted `filename=\"...\"`, and a bare `filename=...`.\n * Splitting on `filename=` alone returns the percent-encoded bytes for any non-ASCII name, which in\n * a product with non-English filenames is most of them.\n *\n * The pair of {@link RequestUtility.buildContentDispositionHeader}: one writes the header, this one reads it.\n */\n static parseContentDisposition(opts: { header: string | null | undefined }): {\n type?: string;\n filename?: string;\n } {\n const { header } = opts;\n\n if (!header) {\n return {};\n }\n\n const type = header.split(';')[0]?.trim() || undefined;\n\n // `filename*` wins when both are present - it is the one that can carry a non-ASCII name.\n const extended = header.match(/filename\\*\\s*=\\s*([^;]+)/i);\n if (extended) {\n const value = extended[1].trim();\n // `UTF-8''name` or `UTF-8'lang'name`; anything before the last quote is charset and language.\n const encoded = value.slice(value.lastIndexOf(\"'\") + 1);\n\n try {\n return { type, filename: decodeURIComponent(encoded) };\n // eslint-disable-next-line venizia/no-silent-catch -- a malformed `filename*` falls through to the plain `filename` parameter; only the extended name is lost\n } catch {\n // A malformed sequence is not worth failing a download over - fall through to `filename`.\n }\n }\n\n const quoted = header.match(/filename\\s*=\\s*\"([^\"]*)\"/i);\n if (quoted) {\n return { type, filename: quoted[1] };\n }\n\n const bare = header.match(/filename\\s*=\\s*([^;]+)/i);\n return { type, filename: bare ? bare[1].trim() : undefined };\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/ignis-helpers",
3
- "version": "0.4.7-1",
3
+ "version": "0.4.7-2",
4
4
  "description": "Production-ready TypeScript utility library: pluggable logging (winston or pino behind one ILogger contract), Redis single/cluster/sentinel with pub/sub, BullMQ/MQTT/Kafka message queues, MinIO/Disk/Bun-S3 object storage, AES-256/RSA/ECDH cryptography, Snowflake UID generation, cron scheduling, Socket.IO/WebSocket, TCP/TLS/UDP networking, HTTP clients, secrets/Vault, worker thread pools, and environment management. Sub-path imports isolate optional peer dependencies so the root barrel never forces a peer into your bundle.",
5
5
  "keywords": [
6
6
  "aes",
@@ -188,7 +188,7 @@
188
188
  "@socket.io/redis-emitter": "^5.1.0",
189
189
  "@types/bun": "^1.4.3",
190
190
  "@types/luxon": "^3.7.6",
191
- "@venizia/dev-configs": "0.4.7-1",
191
+ "@venizia/dev-configs": "0.4.7-2",
192
192
  "axios": "^1.20.0",
193
193
  "bullmq": "^6.4.0",
194
194
  "cron": "^4.4.0",
@@ -1,33 +0,0 @@
1
- import { type ILogger } from './common/types.js';
2
- export type TLoggerResolver = (opts: {
3
- scopes: Array<string>;
4
- }) => ILogger;
5
- /** The only logger code `BaseHelper` reaches, so this module must stay free of node imports - `BaseHelper` sits under every base class in the framework. */
6
- export declare class LoggerResolver {
7
- /** Declared before `active` because static field initialisers run in declaration order. */
8
- private static readonly consoleResolver;
9
- private static active;
10
- private static generation;
11
- /** `LoggerFactory` installs itself here from its own module body, so importing `LoggerFactory` as a value is what wires the real logger up - a side-effect-only import would not survive `sideEffects: false`. */
12
- static use(opts: {
13
- resolver: TLoggerResolver;
14
- }): void;
15
- static reset(): void;
16
- /** Internal to this module - `ResolvedLogger` reads it to decide whether its cached target is stale. */
17
- static currentGeneration(): number;
18
- /** Internal to this module - resolves through whatever is installed right now. */
19
- static resolveNow(opts: {
20
- scopes: Array<string>;
21
- }): ILogger;
22
- /**
23
- * Without this, a node process logs to stdout while `APP_ENV_LOGGER_FOLDER_PATH` silently receives
24
- * nothing. A guarded property read, never an import: even a dynamic `import('@venizia/ignis-helpers')`
25
- * behind a node check puts the root barrel in this bundle and turns `/core` impure.
26
- */
27
- static warnConsoleFallbackOnce(): void;
28
- static resolve(opts: {
29
- scopes: Array<string>;
30
- }): ILogger;
31
- private static hasWarnedConsoleFallback;
32
- }
33
- //# sourceMappingURL=resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/resolver.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAAkB,MAAM,gBAAgB,CAAC;AAG9D,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,KAAK,OAAO,CAAC;AAoD3E,4JAA4J;AAC5J,qBAAa,cAAc;IACzB,2FAA2F;IAC3F,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAIrC;IAEF,OAAO,CAAC,MAAM,CAAC,MAAM,CAAyC;IAC9D,OAAO,CAAC,MAAM,CAAC,UAAU,CAAK;IAE9B,kNAAkN;IAClN,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,eAAe,CAAA;KAAE,GAAG,IAAI;IAKrD,MAAM,CAAC,KAAK,IAAI,IAAI;IAKpB,wGAAwG;IACxG,MAAM,CAAC,iBAAiB,IAAI,MAAM;IAIlC,kFAAkF;IAClF,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO;IAI3D;;;;OAIG;IACH,MAAM,CAAC,uBAAuB,IAAI,IAAI;IAetC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO;IAIxD,OAAO,CAAC,MAAM,CAAC,wBAAwB,CAAS;CACjD"}
@@ -1,95 +0,0 @@
1
- import { AbstractLogger } from './base/abstract.js';
2
- import { ConsoleLogger } from './base/console.js';
3
- import { LoggerSlot } from './slot.js';
4
- /** Caches the resolved target and re-reads it only when `LoggerResolver`'s generation moves - one integer compare per call, so an instance built before `LoggerFactory` loaded upgrades the moment it does, without being reconstructed. Mutual reference with LoggerResolver is by design - hence the `no-use-before-define` disables. */
5
- class ResolvedLogger extends AbstractLogger {
6
- constructor(scopes) {
7
- super();
8
- this.scopes = scopes;
9
- this.targetGeneration = -1;
10
- }
11
- resolveTarget() {
12
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
13
- const generation = LoggerResolver.currentGeneration();
14
- if (!this.target || this.targetGeneration !== generation) {
15
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
16
- this.target = LoggerResolver.resolveNow({ scopes: this.scopes });
17
- this.targetGeneration = generation;
18
- }
19
- return this.target;
20
- }
21
- debug(message, ...args) {
22
- this.resolveTarget().debug(message, ...args);
23
- }
24
- info(message, ...args) {
25
- this.resolveTarget().info(message, ...args);
26
- }
27
- warn(message, ...args) {
28
- this.resolveTarget().warn(message, ...args);
29
- }
30
- error(message, ...args) {
31
- this.resolveTarget().error(message, ...args);
32
- }
33
- emerg(message, ...args) {
34
- this.resolveTarget().emerg(message, ...args);
35
- }
36
- log(level, message, ...args) {
37
- this.resolveTarget().log(level, message, ...args);
38
- }
39
- for(methodName) {
40
- return new ResolvedLogger([...this.scopes, methodName]);
41
- }
42
- }
43
- /** The only logger code `BaseHelper` reaches, so this module must stay free of node imports - `BaseHelper` sits under every base class in the framework. */
44
- export class LoggerResolver {
45
- /** Declared before `active` because static field initialisers run in declaration order. */
46
- static { this.consoleResolver = (opts) => {
47
- // Warned here, on the first line actually routed to the console, not when a helper merely acquires its logger: a script that imports the barrel and installs a provider before logging must stay silent.
48
- LoggerResolver.warnConsoleFallbackOnce();
49
- return ConsoleLogger.get({ scope: opts.scopes.filter((el) => el && el.length > 0).join('-') });
50
- }; }
51
- static { this.active = this.consoleResolver; }
52
- static { this.generation = 0; }
53
- /** `LoggerFactory` installs itself here from its own module body, so importing `LoggerFactory` as a value is what wires the real logger up - a side-effect-only import would not survive `sideEffects: false`. */
54
- static use(opts) {
55
- this.active = opts.resolver;
56
- this.generation += 1;
57
- }
58
- static reset() {
59
- this.active = this.consoleResolver;
60
- this.generation += 1;
61
- }
62
- /** Internal to this module - `ResolvedLogger` reads it to decide whether its cached target is stale. */
63
- static currentGeneration() {
64
- return this.generation;
65
- }
66
- /** Internal to this module - resolves through whatever is installed right now. */
67
- static resolveNow(opts) {
68
- return this.active({ scopes: opts.scopes });
69
- }
70
- /**
71
- * Without this, a node process logs to stdout while `APP_ENV_LOGGER_FOLDER_PATH` silently receives
72
- * nothing. A guarded property read, never an import: even a dynamic `import('@venizia/ignis-helpers')`
73
- * behind a node check puts the root barrel in this bundle and turns `/core` impure.
74
- */
75
- static warnConsoleFallbackOnce() {
76
- if (this.hasWarnedConsoleFallback || this.generation > 0) {
77
- return;
78
- }
79
- if (!globalThis.process?.versions?.node) {
80
- return;
81
- }
82
- this.hasWarnedConsoleFallback = true;
83
- ConsoleLogger.get({ scope: LoggerResolver.name }).warn('Logging to the console: no logger provider is installed. Import `LoggerFactory` from `@venizia/ignis-helpers` once at startup - `@venizia/ignis` does it for you, a connectors-only or script-only import graph does not. Loggers built before that import upgrade themselves on their next call.');
84
- }
85
- static resolve(opts) {
86
- return new ResolvedLogger(opts.scopes);
87
- }
88
- static { this.hasWarnedConsoleFallback = false; }
89
- }
90
- // Registers the real resolver with the slot `BaseHelper` reads. Importing this module - which any
91
- // graph carrying `LoggerFactory` does - is what upgrades every helper from the console fallback,
92
- // including helpers constructed before it loaded: the logger is resolved on first use, not in the
93
- // constructor.
94
- LoggerSlot.resolve = (opts) => LoggerResolver.resolve({ scopes: opts.scopes });
95
- //# sourceMappingURL=resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../../src/modules/logger/resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAIpC,2UAA2U;AAC3U,MAAM,cAAe,SAAQ,cAAc;IAIzC,YAA6B,MAAqB;QAChD,KAAK,EAAE,CAAC;QADmB,WAAM,GAAN,MAAM,CAAe;QAF1C,qBAAgB,GAAG,CAAC,CAAC,CAAC;IAI9B,CAAC;IAEO,aAAa;QACnB,mEAAmE;QACnE,MAAM,UAAU,GAAG,cAAc,CAAC,iBAAiB,EAAE,CAAC;QACtD,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;YACzD,mEAAmE;YACnE,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YACjE,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC;QACr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AC,OAAO,CAAC,IAA+B;QAC5C,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;aAEc,6BAAwB,GAAG,KAAK,CAAC;;AAGlD,kGAAkG;AAClG,iGAAiG;AACjG,kGAAkG;AAClG,eAAe;AACf,UAAU,CAAC,OAAO,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC","sourcesContent":["import { type AnyType } from '@/common/types';\nimport { AbstractLogger } from './base/abstract';\nimport { ConsoleLogger } from './base/console';\nimport { type ILogger, type TLogLevel } from './common/types';\nimport { LoggerSlot } from './slot';\n\nexport type TLoggerResolver = (opts: { scopes: Array<string> }) => ILogger;\n\n/** Caches the resolved target and re-reads it only when `LoggerResolver`'s generation moves - one integer compare per call, so an instance built before `LoggerFactory` loaded upgrades the moment it does, without being reconstructed. Mutual reference with LoggerResolver is by design - hence the `no-use-before-define` disables. */\nclass ResolvedLogger extends AbstractLogger {\n private target?: ILogger;\n private targetGeneration = -1;\n\n constructor(private readonly scopes: Array<string>) {\n super();\n }\n\n private resolveTarget(): ILogger {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n const generation = LoggerResolver.currentGeneration();\n if (!this.target || this.targetGeneration !== generation) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n this.target = LoggerResolver.resolveNow({ scopes: this.scopes });\n this.targetGeneration = generation;\n }\n\n return this.target;\n }\n\n debug(message: string, ...args: AnyType[]) {\n this.resolveTarget().debug(message, ...args);\n }\n\n info(message: string, ...args: AnyType[]) {\n this.resolveTarget().info(message, ...args);\n }\n\n warn(message: string, ...args: AnyType[]) {\n this.resolveTarget().warn(message, ...args);\n }\n\n error(message: string, ...args: AnyType[]) {\n this.resolveTarget().error(message, ...args);\n }\n\n emerg(message: string, ...args: AnyType[]) {\n this.resolveTarget().emerg(message, ...args);\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]) {\n this.resolveTarget().log(level, message, ...args);\n }\n\n for(methodName: string): ILogger {\n return new ResolvedLogger([...this.scopes, methodName]);\n }\n}\n\n/** The only logger code `BaseHelper` reaches, so this module must stay free of node imports - `BaseHelper` sits under every base class in the framework. */\nexport class LoggerResolver {\n /** Declared before `active` because static field initialisers run in declaration order. */\n private static readonly consoleResolver: TLoggerResolver = (opts) => {\n // Warned here, on the first line actually routed to the console, not when a helper merely acquires its logger: a script that imports the barrel and installs a provider before logging must stay silent.\n LoggerResolver.warnConsoleFallbackOnce();\n return ConsoleLogger.get({ scope: opts.scopes.filter((el) => el && el.length > 0).join('-') });\n };\n\n private static active: TLoggerResolver = this.consoleResolver;\n private static generation = 0;\n\n /** `LoggerFactory` installs itself here from its own module body, so importing `LoggerFactory` as a value is what wires the real logger up - a side-effect-only import would not survive `sideEffects: false`. */\n static use(opts: { resolver: TLoggerResolver }): void {\n this.active = opts.resolver;\n this.generation += 1;\n }\n\n static reset(): void {\n this.active = this.consoleResolver;\n this.generation += 1;\n }\n\n /** Internal to this module - `ResolvedLogger` reads it to decide whether its cached target is stale. */\n static currentGeneration(): number {\n return this.generation;\n }\n\n /** Internal to this module - resolves through whatever is installed right now. */\n static resolveNow(opts: { scopes: Array<string> }): ILogger {\n return this.active({ scopes: opts.scopes });\n }\n\n /**\n * Without this, a node process logs to stdout while `APP_ENV_LOGGER_FOLDER_PATH` silently receives\n * nothing. A guarded property read, never an import: even a dynamic `import('@venizia/ignis-helpers')`\n * behind a node check puts the root barrel in this bundle and turns `/core` impure.\n */\n static warnConsoleFallbackOnce(): void {\n if (this.hasWarnedConsoleFallback || this.generation > 0) {\n return;\n }\n\n if (!globalThis.process?.versions?.node) {\n return;\n }\n\n this.hasWarnedConsoleFallback = true;\n ConsoleLogger.get({ scope: LoggerResolver.name }).warn(\n 'Logging to the console: no logger provider is installed. Import `LoggerFactory` from `@venizia/ignis-helpers` once at startup - `@venizia/ignis` does it for you, a connectors-only or script-only import graph does not. Loggers built before that import upgrade themselves on their next call.',\n );\n }\n\n static resolve(opts: { scopes: Array<string> }): ILogger {\n return new ResolvedLogger(opts.scopes);\n }\n\n private static hasWarnedConsoleFallback = false;\n}\n\n// Registers the real resolver with the slot `BaseHelper` reads. Importing this module - which any\n// graph carrying `LoggerFactory` does - is what upgrades every helper from the console fallback,\n// including helpers constructed before it loaded: the logger is resolved on first use, not in the\n// constructor.\nLoggerSlot.resolve = (opts) => LoggerResolver.resolve({ scopes: opts.scopes });\n"]}
@@ -1,44 +0,0 @@
1
- import type { ILogger } from './common/types.js';
2
- export type TLoggerResolver = (opts: {
3
- scopes: Array<string>;
4
- }) => ILogger;
5
- export declare class LoggerSlot {
6
- /**
7
- * Where the logger module installs its resolver, and the only reference `BaseHelper` holds to it.
8
- *
9
- * A slot rather than an import: `BaseHelper` sits under every class in the framework, so importing
10
- * the resolver put 1033 B gzipped into every browser bundle that touched any helper.
11
- */
12
- static resolve?: TLoggerResolver;
13
- /**
14
- * Installs the logger every helper writes to. A browser app calls it once at startup, because `LoggerFactory` is
15
- * node-only: `LoggerSlot.use({ resolver: ({ scopes }) => ConsoleLogger.get({ scope: scopes.join('-') }) })`.
16
- *
17
- * Call it BEFORE the first log line. A helper that logs before a resolver exists keeps writing to the console, and
18
- * the logger it resolves on its first line after one is installed is the one it keeps.
19
- */
20
- static use(opts: {
21
- resolver: TLoggerResolver;
22
- }): void;
23
- /** Writes one line to the console; `emerg` and anything unrecognised land on `error`. */
24
- private static writeToConsole;
25
- /** Hands a line to the level's own method, so the logger's gates apply - `debug` checks `DEBUG`. */
26
- private static writeToLogger;
27
- /** Node only: a browser has no `LoggerFactory` to import, so the advice would be noise there. */
28
- private static warnNoResolverOnce;
29
- /**
30
- * Writes to the console until a resolver is installed, then hands every call to the real logger - a
31
- * helper that logs before the resolver module loads would otherwise stay on the console for good.
32
- */
33
- private static createDeferredLogger;
34
- /** The real logger when a resolver is installed, else one that upgrades itself the moment one is. */
35
- static resolveHelperLogger(opts: {
36
- scopes: Array<string>;
37
- }): ILogger;
38
- /** Pins a logger on a helper instance: later reads are a plain property read, not its getter. */
39
- static pinHelperLogger(opts: {
40
- helper: object;
41
- logger: ILogger;
42
- }): void;
43
- }
44
- //# sourceMappingURL=slot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/slot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,gBAAgB,CAAC;AAEzD,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,KAAK,OAAO,CAAC;AAQ3E,qBAAa,UAAU;IACrB;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC;IAEjC;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,eAAe,CAAA;KAAE,GAAG,IAAI;IAIrD,yFAAyF;IACzF,OAAO,CAAC,MAAM,CAAC,cAAc;IA6B7B,oGAAoG;IACpG,OAAO,CAAC,MAAM,CAAC,aAAa;IAoC5B,iGAAiG;IACjG,OAAO,CAAC,MAAM,CAAC,kBAAkB;IASjC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAmCnC,qGAAqG;IACrG,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO;IAOpE,iGAAiG;IACjG,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;CAQxE"}
@@ -1,126 +0,0 @@
1
- import { LogLevels } from './common/types.js';
2
- const NO_RESOLVER_WARNING = '[BaseHelper] Logging to the console - no logger provider is installed. Import `LoggerFactory` from `@venizia/ignis-helpers` at startup.';
3
- /** Global, so a process holding both the CJS and the ESM copy of this module still warns once. */
4
- const NO_RESOLVER_WARNED = Symbol.for('@venizia/ignis-helpers:no-logger-provider-warned');
5
- export class LoggerSlot {
6
- /**
7
- * Installs the logger every helper writes to. A browser app calls it once at startup, because `LoggerFactory` is
8
- * node-only: `LoggerSlot.use({ resolver: ({ scopes }) => ConsoleLogger.get({ scope: scopes.join('-') }) })`.
9
- *
10
- * Call it BEFORE the first log line. A helper that logs before a resolver exists keeps writing to the console, and
11
- * the logger it resolves on its first line after one is installed is the one it keeps.
12
- */
13
- static use(opts) {
14
- LoggerSlot.resolve = opts.resolver;
15
- }
16
- /** Writes one line to the console; `emerg` and anything unrecognised land on `error`. */
17
- static writeToConsole(opts) {
18
- const { prefix, level, message, args } = opts;
19
- const line = `${prefix} ${message}`;
20
- switch (level) {
21
- case LogLevels.DEBUG: {
22
- globalThis.console.debug(line, ...args);
23
- break;
24
- }
25
- case LogLevels.INFO: {
26
- globalThis.console.info(line, ...args);
27
- break;
28
- }
29
- case LogLevels.WARN: {
30
- globalThis.console.warn(line, ...args);
31
- break;
32
- }
33
- default: {
34
- globalThis.console.error(line, ...args);
35
- break;
36
- }
37
- }
38
- }
39
- /** Hands a line to the level's own method, so the logger's gates apply - `debug` checks `DEBUG`. */
40
- static writeToLogger(opts) {
41
- const { logger, level, message, args } = opts;
42
- switch (level) {
43
- case LogLevels.DEBUG: {
44
- logger.debug(message, ...args);
45
- break;
46
- }
47
- case LogLevels.INFO: {
48
- logger.info(message, ...args);
49
- break;
50
- }
51
- case LogLevels.WARN: {
52
- logger.warn(message, ...args);
53
- break;
54
- }
55
- case LogLevels.ERROR: {
56
- logger.error(message, ...args);
57
- break;
58
- }
59
- case LogLevels.EMERG: {
60
- logger.emerg(message, ...args);
61
- break;
62
- }
63
- default: {
64
- logger.log(level, message, ...args);
65
- break;
66
- }
67
- }
68
- }
69
- /** Node only: a browser has no `LoggerFactory` to import, so the advice would be noise there. */
70
- static warnNoResolverOnce() {
71
- if (Reflect.get(globalThis, NO_RESOLVER_WARNED) || !globalThis.process?.versions?.node) {
72
- return;
73
- }
74
- Reflect.set(globalThis, NO_RESOLVER_WARNED, true);
75
- globalThis.console.warn(NO_RESOLVER_WARNING);
76
- }
77
- /**
78
- * Writes to the console until a resolver is installed, then hands every call to the real logger - a
79
- * helper that logs before the resolver module loads would otherwise stay on the console for good.
80
- */
81
- static createDeferredLogger(opts) {
82
- const { scopes } = opts;
83
- const prefix = `[${scopes.join('-')}]`;
84
- let resolved;
85
- const write = (level, message, args) => {
86
- const resolve = LoggerSlot.resolve;
87
- if (!resolved && resolve) {
88
- resolved = resolve({ scopes });
89
- }
90
- if (resolved) {
91
- LoggerSlot.writeToLogger({ logger: resolved, level, message, args });
92
- return;
93
- }
94
- LoggerSlot.warnNoResolverOnce();
95
- LoggerSlot.writeToConsole({ prefix, level, message, args });
96
- };
97
- return {
98
- debug: (message, ...args) => write(LogLevels.DEBUG, message, args),
99
- info: (message, ...args) => write(LogLevels.INFO, message, args),
100
- warn: (message, ...args) => write(LogLevels.WARN, message, args),
101
- error: (message, ...args) => write(LogLevels.ERROR, message, args),
102
- emerg: (message, ...args) => write(LogLevels.EMERG, message, args),
103
- log: (level, message, ...args) => write(level, message, args),
104
- for: (methodName) => resolved
105
- ? resolved.for(methodName)
106
- : LoggerSlot.createDeferredLogger({ scopes: [...scopes, methodName] }),
107
- };
108
- }
109
- /** The real logger when a resolver is installed, else one that upgrades itself the moment one is. */
110
- static resolveHelperLogger(opts) {
111
- const resolve = LoggerSlot.resolve;
112
- return resolve
113
- ? resolve({ scopes: opts.scopes })
114
- : LoggerSlot.createDeferredLogger({ scopes: opts.scopes });
115
- }
116
- /** Pins a logger on a helper instance: later reads are a plain property read, not its getter. */
117
- static pinHelperLogger(opts) {
118
- Object.defineProperty(opts.helper, 'logger', {
119
- value: opts.logger,
120
- writable: true,
121
- configurable: true,
122
- enumerable: false,
123
- });
124
- }
125
- }
126
- //# sourceMappingURL=slot.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slot.js","sourceRoot":"","sources":["../../../../src/modules/logger/slot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAK3C,MAAM,mBAAmB,GACvB,yIAAyI,CAAC;AAE5I,kGAAkG;AAClG,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;AAE1F,MAAM,OAAO,UAAU;IASrB;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,IAAmC;QAC5C,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;IACrC,CAAC;IAED,yFAAyF;IACjF,MAAM,CAAC,cAAc,CAAC,IAK7B;QACC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAC9C,MAAM,IAAI,GAAG,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;QAEpC,QAAQ,KAAK,EAAE,CAAC;YACd,KAAK,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;gBACrB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;gBACxC,MAAM;YACR,CAAC;YACD,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;gBACpB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;gBACvC,MAAM;YACR,CAAC;YACD,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;gBACpB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;gBACvC,MAAM;YACR,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;g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I;YACd,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { AnyType } from '@/common/types';\nimport { LogLevels } from './common/types';\nimport type { ILogger, TLogLevel } from './common/types';\n\nexport type TLoggerResolver = (opts: { scopes: Array<string> }) => ILogger;\n\nconst NO_RESOLVER_WARNING =\n '[BaseHelper] Logging to the console - no logger provider is installed. Import `LoggerFactory` from `@venizia/ignis-helpers` at startup.';\n\n/** Global, so a process holding both the CJS and the ESM copy of this module still warns once. */\nconst NO_RESOLVER_WARNED = Symbol.for('@venizia/ignis-helpers:no-logger-provider-warned');\n\nexport class LoggerSlot {\n /**\n * Where the logger module installs its resolver, and the only reference `BaseHelper` holds to it.\n *\n * A slot rather than an import: `BaseHelper` sits under every class in the framework, so importing\n * the resolver put 1033 B gzipped into every browser bundle that touched any helper.\n */\n static resolve?: TLoggerResolver;\n\n /**\n * Installs the logger every helper writes to. A browser app calls it once at startup, because `LoggerFactory` is\n * node-only: `LoggerSlot.use({ resolver: ({ scopes }) => ConsoleLogger.get({ scope: scopes.join('-') }) })`.\n *\n * Call it BEFORE the first log line. A helper that logs before a resolver exists keeps writing to the console, and\n * the logger it resolves on its first line after one is installed is the one it keeps.\n */\n static use(opts: { resolver: TLoggerResolver }): void {\n LoggerSlot.resolve = opts.resolver;\n }\n\n /** Writes one line to the console; `emerg` and anything unrecognised land on `error`. */\n private static writeToConsole(opts: {\n prefix: string;\n level: TLogLevel;\n message: string;\n args: Array<AnyType>;\n }): void {\n const { prefix, level, message, args } = opts;\n const line = `${prefix} ${message}`;\n\n switch (level) {\n case LogLevels.DEBUG: {\n globalThis.console.debug(line, ...args);\n break;\n }\n case LogLevels.INFO: {\n globalThis.console.info(line, ...args);\n break;\n }\n case LogLevels.WARN: {\n globalThis.console.warn(line, ...args);\n break;\n }\n default: {\n globalThis.console.error(line, ...args);\n break;\n }\n }\n }\n\n /** Hands a line to the level's own method, so the logger's gates apply - `debug` checks `DEBUG`. */\n private static writeToLogger(opts: {\n logger: ILogger;\n level: TLogLevel;\n message: string;\n args: Array<AnyType>;\n }): void {\n const { logger, level, message, args } = opts;\n\n switch (level) {\n case LogLevels.DEBUG: {\n logger.debug(message, ...args);\n break;\n }\n case LogLevels.INFO: {\n logger.info(message, ...args);\n break;\n }\n case LogLevels.WARN: {\n logger.warn(message, ...args);\n break;\n }\n case LogLevels.ERROR: {\n logger.error(message, ...args);\n break;\n }\n case LogLevels.EMERG: {\n logger.emerg(message, ...args);\n break;\n }\n default: {\n logger.log(level, message, ...args);\n break;\n }\n }\n }\n\n /** Node only: a browser has no `LoggerFactory` to import, so the advice would be noise there. */\n private static warnNoResolverOnce(): void {\n if (Reflect.get(globalThis, NO_RESOLVER_WARNED) || !globalThis.process?.versions?.node) {\n return;\n }\n\n Reflect.set(globalThis, NO_RESOLVER_WARNED, true);\n globalThis.console.warn(NO_RESOLVER_WARNING);\n }\n\n /**\n * Writes to the console until a resolver is installed, then hands every call to the real logger - a\n * helper that logs before the resolver module loads would otherwise stay on the console for good.\n */\n private static createDeferredLogger(opts: { scopes: Array<string> }): ILogger {\n const { scopes } = opts;\n const prefix = `[${scopes.join('-')}]`;\n let resolved: ILogger | undefined;\n\n const write = (level: TLogLevel, message: string, args: Array<AnyType>): void => {\n const resolve = LoggerSlot.resolve;\n if (!resolved && resolve) {\n resolved = resolve({ scopes });\n }\n\n if (resolved) {\n LoggerSlot.writeToLogger({ logger: resolved, level, message, args });\n return;\n }\n\n LoggerSlot.warnNoResolverOnce();\n LoggerSlot.writeToConsole({ prefix, level, message, args });\n };\n\n return {\n debug: (message: string, ...args: Array<AnyType>) => write(LogLevels.DEBUG, message, args),\n info: (message: string, ...args: Array<AnyType>) => write(LogLevels.INFO, message, args),\n warn: (message: string, ...args: Array<AnyType>) => write(LogLevels.WARN, message, args),\n error: (message: string, ...args: Array<AnyType>) => write(LogLevels.ERROR, message, args),\n emerg: (message: string, ...args: Array<AnyType>) => write(LogLevels.EMERG, message, args),\n log: (level: TLogLevel, message: string, ...args: Array<AnyType>) =>\n write(level, message, args),\n for: (methodName: string) =>\n resolved\n ? resolved.for(methodName)\n : LoggerSlot.createDeferredLogger({ scopes: [...scopes, methodName] }),\n };\n }\n\n /** The real logger when a resolver is installed, else one that upgrades itself the moment one is. */\n static resolveHelperLogger(opts: { scopes: Array<string> }): ILogger {\n const resolve = LoggerSlot.resolve;\n return resolve\n ? resolve({ scopes: opts.scopes })\n : LoggerSlot.createDeferredLogger({ scopes: opts.scopes });\n }\n\n /** Pins a logger on a helper instance: later reads are a plain property read, not its getter. */\n static pinHelperLogger(opts: { helper: object; logger: ILogger }): void {\n Object.defineProperty(opts.helper, 'logger', {\n value: opts.logger,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n }\n}\n"]}