@venizia/ignis-kernel 0.4.8 → 0.5.0-1

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 (60) hide show
  1. package/dist/esm/base/applications/rest.d.ts +2 -2
  2. package/dist/esm/base/applications/rest.js.map +1 -1
  3. package/dist/esm/base/auth/authenticate/common/keys.d.ts +21 -7
  4. package/dist/esm/base/auth/authenticate/common/keys.js +34 -7
  5. package/dist/esm/base/auth/authenticate/common/keys.js.map +1 -1
  6. package/dist/esm/base/auth/authenticate/common/types/jwt.d.ts +8 -17
  7. package/dist/esm/base/auth/authenticate/common/types/jwt.js.map +1 -1
  8. package/dist/esm/base/auth/authenticate/common/types/rest.d.ts +3 -1
  9. package/dist/esm/base/auth/authenticate/common/types/rest.js.map +1 -1
  10. package/dist/esm/base/auth/authenticate/common/types/service.d.ts +3 -3
  11. package/dist/esm/base/auth/authenticate/common/types/service.js.map +1 -1
  12. package/dist/esm/base/auth/authorize/common/constants/binding-keys.d.ts +6 -3
  13. package/dist/esm/base/auth/authorize/common/constants/binding-keys.js +8 -3
  14. package/dist/esm/base/auth/authorize/common/constants/binding-keys.js.map +1 -1
  15. package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.js.map +1 -1
  16. package/dist/esm/base/auth/base/abstract-auth-registry.d.ts +2 -1
  17. package/dist/esm/base/auth/base/abstract-auth-registry.js +2 -2
  18. package/dist/esm/base/auth/base/abstract-auth-registry.js.map +1 -1
  19. package/dist/esm/base/components/base.d.ts +3 -3
  20. package/dist/esm/base/components/base.js +3 -3
  21. package/dist/esm/base/components/base.js.map +1 -1
  22. package/dist/esm/base/components/controller/rest/common/types.d.ts +2 -1
  23. package/dist/esm/base/components/controller/rest/common/types.js +3 -1
  24. package/dist/esm/base/components/controller/rest/common/types.js.map +1 -1
  25. package/dist/esm/base/components/controller/rest/rest.component.js.map +1 -1
  26. package/dist/esm/base/controllers/factory/controller.js +4 -1
  27. package/dist/esm/base/controllers/factory/controller.js.map +1 -1
  28. package/dist/esm/base/controllers/factory/definition.d.ts +48 -48
  29. package/dist/esm/base/events/common/types.d.ts +2 -1
  30. package/dist/esm/base/events/common/types.js.map +1 -1
  31. package/dist/esm/base/events/event-bus.js.map +1 -1
  32. package/dist/esm/base/metadata/artifact-keys.d.ts +2 -1
  33. package/dist/esm/base/metadata/artifact-keys.js.map +1 -1
  34. package/dist/esm/base/metadata/injectable.d.ts +2 -1
  35. package/dist/esm/base/metadata/injectable.js.map +1 -1
  36. package/dist/esm/base/metadata/persistents/repository/injection.js.map +1 -1
  37. package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.js +2 -1
  38. package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.js.map +1 -1
  39. package/dist/esm/base/models/common/schemas.d.ts +9 -9
  40. package/dist/esm/base/models/common/schemas.js +1 -1
  41. package/dist/esm/base/models/common/schemas.js.map +1 -1
  42. package/dist/esm/base/repositories/common/response-reader.d.ts +15 -5
  43. package/dist/esm/base/repositories/common/response-reader.js +21 -6
  44. package/dist/esm/base/repositories/common/response-reader.js.map +1 -1
  45. package/dist/esm/common/bindings.d.ts +7 -7
  46. package/dist/esm/common/bindings.js +21 -7
  47. package/dist/esm/common/bindings.js.map +1 -1
  48. package/dist/esm/helpers/inversion/common/types/artifact.d.ts +2 -2
  49. package/dist/esm/helpers/inversion/common/types/artifact.js.map +1 -1
  50. package/dist/esm/helpers/inversion/index.d.ts +1 -1
  51. package/dist/esm/helpers/inversion/index.js.map +1 -1
  52. package/dist/esm/helpers/inversion/mixins/artifact.mixin.d.ts +5 -5
  53. package/dist/esm/helpers/inversion/mixins/controllers/controller.d.ts +5 -5
  54. package/dist/esm/helpers/inversion/mixins/controllers/grpc.d.ts +5 -5
  55. package/dist/esm/helpers/inversion/mixins/controllers/rest.d.ts +5 -5
  56. package/dist/esm/helpers/inversion/mixins/datasource.mixin.d.ts +5 -5
  57. package/dist/esm/helpers/inversion/mixins/model.mixin.d.ts +5 -5
  58. package/dist/esm/helpers/inversion/mixins/repository.mixin.d.ts +5 -5
  59. package/dist/esm/helpers/inversion/registry.d.ts +35 -35
  60. package/package.json +5 -5
@@ -1,9 +1,14 @@
1
+ import { BindingKeys } from '../../../../../helpers/inversion/index.js';
1
2
  /** Container binding keys for the authorize options, the always-allow roles, and (through `enforcerOptions`) the options of one named enforcer. */
2
3
  export class AuthorizeBindingKeys {
3
- static { this.OPTIONS = '@app/authorize/options'; }
4
- static { this.ALWAYS_ALLOW_ROLES = '@app/authorize/always-allow-roles'; }
4
+ static { this.OPTIONS = BindingKeys.build({ key: '@app/authorize/options' }); }
5
+ static { this.ALWAYS_ALLOW_ROLES = BindingKeys.build({
6
+ key: '@app/authorize/always-allow-roles',
7
+ }); }
8
+ /** The options of the enforcer named `name`; their type is the enforcer's, so the caller names it: `enforcerOptions<ICasbinOptions>(name)`. */
5
9
  static enforcerOptions(name) {
6
- return `@app/authorize/enforcers/${name}/options`;
10
+ // A key built for `unknown` is the key of any `T`: the brand is bivariant.
11
+ return BindingKeys.build({ key: `@app/authorize/enforcers/${name}/options` });
7
12
  }
8
13
  }
9
14
  //# sourceMappingURL=binding-keys.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"binding-keys.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/binding-keys.ts"],"names":[],"mappings":"AAAA,mJAAmJ;AACnJ,MAAM,OAAO,oBAAoB;aACf,YAAO,GAAG,wBAAwB,CAAC;aACnC,uBAAkB,GAAG,mCAAmC,CAAC;IAEzE,MAAM,CAAC,eAAe,CAAC,IAAY;QACjC,OAAO,4BAA4B,IAAI,UAAU,CAAC;IACpD,CAAC","sourcesContent":["/** Container binding keys for the authorize options, the always-allow roles, and (through `enforcerOptions`) the options of one named enforcer. */\nexport class AuthorizeBindingKeys {\n static readonly OPTIONS = '@app/authorize/options';\n static readonly ALWAYS_ALLOW_ROLES = '@app/authorize/always-allow-roles';\n\n static enforcerOptions(name: string): string {\n return `@app/authorize/enforcers/${name}/options`;\n }\n}\n"]}
1
+ {"version":3,"file":"binding-keys.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/binding-keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,qBAAqB,CAAC;AAGpE,mJAAmJ;AACnJ,MAAM,OAAO,oBAAoB;aACf,YAAO,GAAG,WAAW,CAAC,KAAK,CAAoB,EAAE,GAAG,EAAE,wBAAwB,EAAE,CAAC,CAAC;aAClF,uBAAkB,GAAG,WAAW,CAAC,KAAK,CAAW;QAC/D,GAAG,EAAE,mCAAmC;KACzC,CAAC,CAAC;IAEH,+IAA+I;IAC/I,MAAM,CAAC,eAAe,CAAc,IAAY;QAC9C,2EAA2E;QAC3E,OAAO,WAAW,CAAC,KAAK,CAAU,EAAE,GAAG,EAAE,4BAA4B,IAAI,UAAU,EAAE,CAAC,CAAC;IACzF,CAAC","sourcesContent":["import { BindingKeys, type TBindingKey } from '@/helpers/inversion';\nimport type { IAuthorizeOptions } from '../types';\n\n/** Container binding keys for the authorize options, the always-allow roles, and (through `enforcerOptions`) the options of one named enforcer. */\nexport class AuthorizeBindingKeys {\n static readonly OPTIONS = BindingKeys.build<IAuthorizeOptions>({ key: '@app/authorize/options' });\n static readonly ALWAYS_ALLOW_ROLES = BindingKeys.build<string[]>({\n key: '@app/authorize/always-allow-roles',\n });\n\n /** The options of the enforcer named `name`; their type is the enforcer's, so the caller names it: `enforcerOptions<ICasbinOptions>(name)`. */\n static enforcerOptions<T = unknown>(name: string): TBindingKey<T> {\n // A key built for `unknown` is the key of any `T`: the brand is bivariant.\n return BindingKeys.build<unknown>({ key: `@app/authorize/enforcers/${name}/options` });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"enforcer-registry.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authorize/enforcers/enforcer-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CA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IAC3D,CAAC;IAED,2FAA2F;IAC3F,KAAK,CAAC,gBAAgB,CAAC,IAGtB;QACC,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAChE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAEtD,IAAI,OAAO,QAAQ,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;YACpD,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,6CAA6C,IAAI,uCAAuC;aAClG,CAAC,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,qEAAqE;IACrE,UAAU,CAAC,IAAoC;QAC7C,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC;IACzC,CAAC;IAED,cAAc;QACZ,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,kBAAkB,CAAC;QACjC,CAAC;QAED,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;YAC/B,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAoB;gBAC/C,GAAG,EAAE,oBAAoB,CAAC,OAAO;gBACjC,UAAU,EAAE,IAAI;aACjB,CAAC,CAAC;YAEH,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,OAAO,CAAC;YACjB,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC","sourcesContent":["import { SingletonRealm } from '@/helpers/singleton-realm';\nimport type { Container } from '@/helpers/inversion/container';\nimport type { TClass, TNullable } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IAuthUser } from '../../authenticate/common/types';\nimport { AbstractAuthRegistry } from '../../base';\nimport type {\n AuthorizationEnforcerTypes,\n IAuthorizationEnforcer,\n IAuthorizationUser,\n IAuthorizeOptions,\n ICasbinEnforcerOptions,\n} from '../common';\nimport { Authorization, AuthorizeBindingKeys } from '../common';\n\n/** Singleton registry of named authorization enforcers. An enforcer is configured once, on first resolve; concurrent first resolves share one `configure()` call. */\nexport class AuthorizationEnforcerRegistry extends AbstractAuthRegistry<IAuthorizationEnforcer> {\n static readonly SINGLETON_REAL_KEY = 'authorization-enforcer-registry';\n\n private configuredEnforcers: Set<string>;\n\n /** In-flight `configure()` calls, so concurrent first requests share one warmup instead of racing. */\n private pendingConfigurations: Map<string, Promise<void>>;\n\n /** Set by AuthorizeComponent from the application container. Held here because the descriptor scan\n * below sees only registered enforcers, and `defaultDecision` has to be readable when there are none. */\n private applicationOptions: TNullable<IAuthorizeOptions> = null;\n\n constructor() {\n super({ scope: AuthorizationEnforcerRegistry.name });\n this.configuredEnforcers = new Set();\n this.pendingConfigurations = new Map();\n }\n\n static getInstance() {\n return SingletonRealm.resolve({\n key: AuthorizationEnforcerRegistry.SINGLETON_REAL_KEY,\n create: () => new AuthorizationEnforcerRegistry(),\n });\n }\n\n override reset(): void {\n super.reset();\n this.configuredEnforcers.clear();\n this.pendingConfigurations.clear();\n this.applicationOptions = null;\n }\n\n protected getBindingPrefix(): string {\n return Authorization.ENFORCER;\n }\n\n register(opts: {\n container: Container;\n enforcers: Array<\n | {\n enforcer: TClass<IAuthorizationEnforcer>;\n name: string;\n type: typeof AuthorizationEnforcerTypes.CASBIN;\n options?: ICasbinEnforcerOptions;\n }\n | {\n enforcer: TClass<IAuthorizationEnforcer>;\n name: string;\n type: typeof AuthorizationEnforcerTypes.CUSTOM;\n options?: unknown;\n }\n >;\n }) {\n const { container, enforcers } = opts;\n\n const names = enforcers.map((e) => e.name);\n const duplicateNames = names.filter((n, i) => names.indexOf(n) !== i);\n\n if (duplicateNames.length) {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Duplicate enforcer name(s): ${[...new Set(duplicateNames)].join(', ')}`,\n });\n }\n\n for (const { enforcer, name, options } of enforcers) {\n if (this.descriptors.has(name)) {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer already registered: ${name}`,\n });\n }\n\n this.registerDescriptor({ container, target: enforcer, name });\n\n if (options) {\n container.bind({ key: AuthorizeBindingKeys.enforcerOptions(name) }).toValue(options);\n }\n }\n\n return this;\n }\n\n hasEnforcers(): boolean {\n return this.descriptors.size > 0;\n }\n\n getDefaultEnforcerName(): string {\n return this.getDefaultName();\n }\n\n /**\n * The PROMISE is memoised, not just the completed flag.\n *\n * `configure()` yields (it dynamic-imports casbin), and the flag was only set after the await -\n * so a burst of first requests each saw an unconfigured enforcer and each built a full pool.\n * Measured: 40 concurrent first requests produced 40 configure() calls and 640 enforcers.\n * The entry is dropped on rejection so a failed warmup does not poison every later request.\n */\n async resolveEnforcer(opts: { name: string }): Promise<IAuthorizationEnforcer> {\n const enforcer = this.resolveDescriptor(opts);\n\n if (this.configuredEnforcers.has(opts.name)) {\n return enforcer;\n }\n\n const inFlight = this.pendingConfigurations.get(opts.name);\n\n if (inFlight) {\n await inFlight;\n\n return enforcer;\n }\n\n // `Promise.resolve` because `configure()` is declared `ValueOrPromise<void>` - a synchronous\n // implementation returns plain `void`, which has no `.then`.\n const pending = Promise.resolve(enforcer.configure())\n .then(() => {\n this.configuredEnforcers.add(opts.name);\n })\n .finally(() => {\n this.pendingConfigurations.delete(opts.name);\n });\n\n this.pendingConfigurations.set(opts.name, pending);\n\n await pending;\n\n return enforcer;\n }\n\n /** Drop a user's cached policies on the resolved enforcer. Lazy - next request rebuilds. */\n async invalidateUserCache(opts: {\n user: IAuthorizationUser;\n enforcerName?: string;\n }): Promise<{ invalidatedKeys: number }> {\n const name = opts.enforcerName ?? this.getDefaultEnforcerName();\n const enforcer = await this.resolveEnforcer({ name });\n\n // Cache management is an optional IAuthorizationEnforcer capability - feature-detect it.\n if (typeof enforcer.invalidateUserCache !== 'function') {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer \"${name}\" does not support cache invalidation`,\n });\n }\n\n return enforcer.invalidateUserCache({ user: opts.user });\n }\n\n /** Drop then immediately rebuild + re-cache a user's policies on the resolved enforcer. */\n async rebuildUserCache(opts: {\n user: { principalType: string } & IAuthUser;\n enforcerName?: string;\n }): Promise<{ cacheKey: string; lineCount: number }> {\n const name = opts.enforcerName ?? this.getDefaultEnforcerName();\n const enforcer = await this.resolveEnforcer({ name });\n\n if (typeof enforcer.rebuildUserCache !== 'function') {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer \"${name}\" does not support cache invalidation`,\n });\n }\n\n return enforcer.rebuildUserCache({ user: opts.user });\n }\n\n /** Options bound on the application, independent of any enforcer. */\n setOptions(opts: { options: IAuthorizeOptions }): void {\n this.applicationOptions = opts.options;\n }\n\n resolveOptions(): IAuthorizeOptions | undefined {\n if (this.applicationOptions) {\n return this.applicationOptions;\n }\n\n for (const [, metadata] of this.descriptors) {\n const { container } = metadata;\n const options = container.get<IAuthorizeOptions>({\n key: AuthorizeBindingKeys.OPTIONS,\n isOptional: true,\n });\n\n if (options) {\n return options;\n }\n }\n\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"enforcer-registry.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authorize/enforcers/enforcer-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAQlD,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEhE,qKAAqK;AACrK,MAAM,OAAO,6BAA8B,SAAQ,oBAA4C;aAC7E,uBAAkB,GAAG,iCAAiC,AAApC,CAAqC;IAWvE;QACE,K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AAE,CAAC;YACpD,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,6CAA6C,IAAI,uCAAuC;aAClG,CAAC,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,qEAAqE;IACrE,UAAU,CAAC,IAAoC;QAC7C,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC;IACzC,CAAC;IAED,cAAc;QACZ,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,kBAAkB,CAAC;QACjC,CAAC;QAED,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;YAC/B,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC;gBAC5B,GAAG,EAAE,oBAAoB,CAAC,OAAO;gBACjC,UAAU,EAAE,IAAI;aACjB,CAAC,CAAC;YAEH,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,OAAO,CAAC;YACjB,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC","sourcesContent":["import { SingletonRealm } from '@/helpers/singleton-realm';\nimport type { Container } from '@/helpers/inversion/container';\nimport type { TClass, TNullable } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IAuthUser } from '../../authenticate/common/types';\nimport { AbstractAuthRegistry } from '../../base';\nimport type {\n AuthorizationEnforcerTypes,\n IAuthorizationEnforcer,\n IAuthorizationUser,\n IAuthorizeOptions,\n ICasbinEnforcerOptions,\n} from '../common';\nimport { Authorization, AuthorizeBindingKeys } from '../common';\n\n/** Singleton registry of named authorization enforcers. An enforcer is configured once, on first resolve; concurrent first resolves share one `configure()` call. */\nexport class AuthorizationEnforcerRegistry extends AbstractAuthRegistry<IAuthorizationEnforcer> {\n static readonly SINGLETON_REAL_KEY = 'authorization-enforcer-registry';\n\n private configuredEnforcers: Set<string>;\n\n /** In-flight `configure()` calls, so concurrent first requests share one warmup instead of racing. */\n private pendingConfigurations: Map<string, Promise<void>>;\n\n /** Set by AuthorizeComponent from the application container. Held here because the descriptor scan\n * below sees only registered enforcers, and `defaultDecision` has to be readable when there are none. */\n private applicationOptions: TNullable<IAuthorizeOptions> = null;\n\n constructor() {\n super({ scope: AuthorizationEnforcerRegistry.name });\n this.configuredEnforcers = new Set();\n this.pendingConfigurations = new Map();\n }\n\n static getInstance() {\n return SingletonRealm.resolve({\n key: AuthorizationEnforcerRegistry.SINGLETON_REAL_KEY,\n create: () => new AuthorizationEnforcerRegistry(),\n });\n }\n\n override reset(): void {\n super.reset();\n this.configuredEnforcers.clear();\n this.pendingConfigurations.clear();\n this.applicationOptions = null;\n }\n\n protected getBindingPrefix(): string {\n return Authorization.ENFORCER;\n }\n\n register(opts: {\n container: Container;\n enforcers: Array<\n | {\n enforcer: TClass<IAuthorizationEnforcer>;\n name: string;\n type: typeof AuthorizationEnforcerTypes.CASBIN;\n options?: ICasbinEnforcerOptions;\n }\n | {\n enforcer: TClass<IAuthorizationEnforcer>;\n name: string;\n type: typeof AuthorizationEnforcerTypes.CUSTOM;\n options?: unknown;\n }\n >;\n }) {\n const { container, enforcers } = opts;\n\n const names = enforcers.map((e) => e.name);\n const duplicateNames = names.filter((n, i) => names.indexOf(n) !== i);\n\n if (duplicateNames.length) {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Duplicate enforcer name(s): ${[...new Set(duplicateNames)].join(', ')}`,\n });\n }\n\n for (const { enforcer, name, options } of enforcers) {\n if (this.descriptors.has(name)) {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer already registered: ${name}`,\n });\n }\n\n this.registerDescriptor({ container, target: enforcer, name });\n\n if (options) {\n container.bind({ key: AuthorizeBindingKeys.enforcerOptions(name) }).toValue(options);\n }\n }\n\n return this;\n }\n\n hasEnforcers(): boolean {\n return this.descriptors.size > 0;\n }\n\n getDefaultEnforcerName(): string {\n return this.getDefaultName();\n }\n\n /**\n * The PROMISE is memoised, not just the completed flag.\n *\n * `configure()` yields (it dynamic-imports casbin), and the flag was only set after the await -\n * so a burst of first requests each saw an unconfigured enforcer and each built a full pool.\n * Measured: 40 concurrent first requests produced 40 configure() calls and 640 enforcers.\n * The entry is dropped on rejection so a failed warmup does not poison every later request.\n */\n async resolveEnforcer(opts: { name: string }): Promise<IAuthorizationEnforcer> {\n const enforcer = this.resolveDescriptor(opts);\n\n if (this.configuredEnforcers.has(opts.name)) {\n return enforcer;\n }\n\n const inFlight = this.pendingConfigurations.get(opts.name);\n\n if (inFlight) {\n await inFlight;\n\n return enforcer;\n }\n\n // `Promise.resolve` because `configure()` is declared `ValueOrPromise<void>` - a synchronous\n // implementation returns plain `void`, which has no `.then`.\n const pending = Promise.resolve(enforcer.configure())\n .then(() => {\n this.configuredEnforcers.add(opts.name);\n })\n .finally(() => {\n this.pendingConfigurations.delete(opts.name);\n });\n\n this.pendingConfigurations.set(opts.name, pending);\n\n await pending;\n\n return enforcer;\n }\n\n /** Drop a user's cached policies on the resolved enforcer. Lazy - next request rebuilds. */\n async invalidateUserCache(opts: {\n user: IAuthorizationUser;\n enforcerName?: string;\n }): Promise<{ invalidatedKeys: number }> {\n const name = opts.enforcerName ?? this.getDefaultEnforcerName();\n const enforcer = await this.resolveEnforcer({ name });\n\n // Cache management is an optional IAuthorizationEnforcer capability - feature-detect it.\n if (typeof enforcer.invalidateUserCache !== 'function') {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer \"${name}\" does not support cache invalidation`,\n });\n }\n\n return enforcer.invalidateUserCache({ user: opts.user });\n }\n\n /** Drop then immediately rebuild + re-cache a user's policies on the resolved enforcer. */\n async rebuildUserCache(opts: {\n user: { principalType: string } & IAuthUser;\n enforcerName?: string;\n }): Promise<{ cacheKey: string; lineCount: number }> {\n const name = opts.enforcerName ?? this.getDefaultEnforcerName();\n const enforcer = await this.resolveEnforcer({ name });\n\n if (typeof enforcer.rebuildUserCache !== 'function') {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer \"${name}\" does not support cache invalidation`,\n });\n }\n\n return enforcer.rebuildUserCache({ user: opts.user });\n }\n\n /** Options bound on the application, independent of any enforcer. */\n setOptions(opts: { options: IAuthorizeOptions }): void {\n this.applicationOptions = opts.options;\n }\n\n resolveOptions(): IAuthorizeOptions | undefined {\n if (this.applicationOptions) {\n return this.applicationOptions;\n }\n\n for (const [, metadata] of this.descriptors) {\n const { container } = metadata;\n const options = container.get({\n key: AuthorizeBindingKeys.OPTIONS,\n isOptional: true,\n });\n\n if (options) {\n return options;\n }\n }\n\n return undefined;\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { type TBindingKey } from '@venizia/ignis-inversion';
1
2
  import type { Container } from '../../../helpers/inversion/container.js';
2
3
  import type { TClass } from '@venizia/ignis-helpers/common';
3
4
  import { BaseHelper } from '@venizia/ignis-helpers/core';
@@ -15,7 +16,7 @@ export declare abstract class AbstractAuthRegistry<TItem> extends BaseHelper {
15
16
  protected abstract getBindingPrefix(): string;
16
17
  getKey(opts: {
17
18
  name: string;
18
- }): string;
19
+ }): TBindingKey;
19
20
  /**
20
21
  * Whether a name resolves. The registry is the only source of truth for that: the strategy type is
21
22
  * open (`TAuthStrategy` accepts any string), so nothing upstream can tell a registered name from a
@@ -1,5 +1,5 @@
1
1
  import { ObjectUtility } from '@venizia/ignis-helpers/common';
2
- import { BindingScopes } from '@venizia/ignis-inversion';
2
+ import { BindingKeys, BindingScopes } from '@venizia/ignis-inversion';
3
3
  import { BaseHelper, getError } from '@venizia/ignis-helpers/core';
4
4
  /** Base of the auth registries. Registers classes under a name as singletons in a container and resolves them by name. Subclasses supply the binding key prefix. */
5
5
  export class AbstractAuthRegistry extends BaseHelper {
@@ -11,7 +11,7 @@ export class AbstractAuthRegistry extends BaseHelper {
11
11
  if (!opts?.name || ObjectUtility.isEmpty({ value: opts.name })) {
12
12
  throw getError({ message: `[getKey] Invalid name | name: ${opts.name}` });
13
13
  }
14
- return [this.getBindingPrefix(), opts.name].join('.');
14
+ return BindingKeys.build({ namespace: this.getBindingPrefix(), key: opts.name });
15
15
  }
16
16
  /**
17
17
  * Whether a name resolves. The registry is the only source of truth for that: the strategy type is
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-auth-registry.js","sourceRoot":"","sources":["../../../../../src/base/auth/base/abstract-auth-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAQnE,oKAAoK;AACpK,MAAM,OAAgB,oBAA4B,SAAQ,UAAU;IAGlE,YAAY,IAAuB;QACjC,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;IAC/B,CAAC;IAID,MAAM,CAAC,IAAsB;QAC3B,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YAC/D,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,iCAAiC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5E,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,IAAsB;QACxB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,8FAA8F;IAC9F,QAAQ;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AAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAQ;YACpC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;SAC3B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,wBAAwB,IAAI,EAAE;aACjE,CAAC,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-helpers/common';\nimport { BindingScopes } from '@venizia/ignis-inversion';\nimport type { Container } from '@/helpers/inversion/container';\nimport type { TClass } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\n\n/** A registered item: its class and the container that resolves it. */\nexport type TRegistryDescriptor<TItem> = {\n container: Container;\n targetClass: TClass<TItem>;\n};\n\n/** Base of the auth registries. Registers classes under a name as singletons in a container and resolves them by name. Subclasses supply the binding key prefix. */\nexport abstract class AbstractAuthRegistry<TItem> extends BaseHelper {\n protected descriptors: Map<string, TRegistryDescriptor<TItem>>;\n\n constructor(opts: { scope: string }) {\n super(opts);\n this.descriptors = new Map();\n }\n\n protected abstract getBindingPrefix(): string;\n\n getKey(opts: { name: string }): string {\n if (!opts?.name || ObjectUtility.isEmpty({ value: opts.name })) {\n throw getError({ message: `[getKey] Invalid name | name: ${opts.name}` });\n }\n\n return [this.getBindingPrefix(), opts.name].join('.');\n }\n\n /**\n * Whether a name resolves. The registry is the only source of truth for that: the strategy type is\n * open (`TAuthStrategy` accepts any string), so nothing upstream can tell a registered name from a\n * typo. `AuthenticateStrategy.isValid` knows the two built-ins only and must not be used here.\n */\n has(opts: { name: string }): boolean {\n return this.descriptors.has(opts.name);\n }\n\n /** Every registered name, for a caller building its own startup check or an error message. */\n getNames(): string[] {\n return [...this.descriptors.keys()];\n }\n\n getDefaultName(): string {\n const firstName = this.descriptors.keys().next().value;\n\n if (!firstName) {\n throw getError({\n message: `[${this.constructor.name}] No items registered`,\n });\n }\n\n return firstName;\n }\n\n protected registerDescriptor(opts: {\n container: Container;\n target: TClass<TItem>;\n name: string;\n }): void {\n const { container, target, name } = opts;\n\n this.descriptors.set(name, { container, targetClass: target });\n container\n .bind({ key: this.getKey({ name }) })\n .toClass(target)\n .setScope(BindingScopes.SINGLETON);\n }\n\n reset(): void {\n this.descriptors.clear();\n }\n\n protected resolveDescriptor(opts: { name: string }): TItem {\n const { name } = opts;\n const metadata = this.descriptors.get(name);\n\n if (!metadata) {\n throw getError({\n message: `[${this.constructor.name}] Descriptor not found: ${name}`,\n });\n }\n\n const { container } = metadata;\n const instance = container.get<TItem>({\n key: this.getKey({ name }),\n });\n\n if (!instance) {\n throw getError({\n message: `[${this.constructor.name}] Failed to resolve: ${name}`,\n });\n }\n\n return instance;\n }\n}\n"]}
1
+ {"version":3,"file":"abstract-auth-registry.js","sourceRoot":"","sources":["../../../../../src/base/auth/base/abstract-auth-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAoB,MAAM,0BAA0B,CAAC;AAGxF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAQnE,oKAAoK;AACpK,MAAM,OAAgB,oBAA4B,SAAQ,UAAU;IAGlE,YAAY,IAAuB;QACjC,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;IAC/B,CAAC;IAID,MAAM,CAAC,IAAsB;QAC3B,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YAC/D,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,iCAAiC,IA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AAsB;QAChD,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAE5C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,2BAA2B,IAAI,EAAE;aACpE,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;QAC/B,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAQ;YACpC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;SAC3B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,wBAAwB,IAAI,EAAE;aACjE,CAAC,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-helpers/common';\nimport { BindingKeys, BindingScopes, type TBindingKey } from '@venizia/ignis-inversion';\nimport type { Container } from '@/helpers/inversion/container';\nimport type { TClass } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\n\n/** A registered item: its class and the container that resolves it. */\nexport type TRegistryDescriptor<TItem> = {\n container: Container;\n targetClass: TClass<TItem>;\n};\n\n/** Base of the auth registries. Registers classes under a name as singletons in a container and resolves them by name. Subclasses supply the binding key prefix. */\nexport abstract class AbstractAuthRegistry<TItem> extends BaseHelper {\n protected descriptors: Map<string, TRegistryDescriptor<TItem>>;\n\n constructor(opts: { scope: string }) {\n super(opts);\n this.descriptors = new Map();\n }\n\n protected abstract getBindingPrefix(): string;\n\n getKey(opts: { name: string }): TBindingKey {\n if (!opts?.name || ObjectUtility.isEmpty({ value: opts.name })) {\n throw getError({ message: `[getKey] Invalid name | name: ${opts.name}` });\n }\n\n return BindingKeys.build<unknown>({ namespace: this.getBindingPrefix(), key: opts.name });\n }\n\n /**\n * Whether a name resolves. The registry is the only source of truth for that: the strategy type is\n * open (`TAuthStrategy` accepts any string), so nothing upstream can tell a registered name from a\n * typo. `AuthenticateStrategy.isValid` knows the two built-ins only and must not be used here.\n */\n has(opts: { name: string }): boolean {\n return this.descriptors.has(opts.name);\n }\n\n /** Every registered name, for a caller building its own startup check or an error message. */\n getNames(): string[] {\n return [...this.descriptors.keys()];\n }\n\n getDefaultName(): string {\n const firstName = this.descriptors.keys().next().value;\n\n if (!firstName) {\n throw getError({\n message: `[${this.constructor.name}] No items registered`,\n });\n }\n\n return firstName;\n }\n\n protected registerDescriptor(opts: {\n container: Container;\n target: TClass<TItem>;\n name: string;\n }): void {\n const { container, target, name } = opts;\n\n this.descriptors.set(name, { container, targetClass: target });\n container\n .bind({ key: this.getKey({ name }) })\n .toClass(target)\n .setScope(BindingScopes.SINGLETON);\n }\n\n reset(): void {\n this.descriptors.clear();\n }\n\n protected resolveDescriptor(opts: { name: string }): TItem {\n const { name } = opts;\n const metadata = this.descriptors.get(name);\n\n if (!metadata) {\n throw getError({\n message: `[${this.constructor.name}] Descriptor not found: ${name}`,\n });\n }\n\n const { container } = metadata;\n const instance = container.get<TItem>({\n key: this.getKey({ name }),\n });\n\n if (!instance) {\n throw getError({\n message: `[${this.constructor.name}] Failed to resolve: ${name}`,\n });\n }\n\n return instance;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Binding, Container, TBindingKey } from '../../helpers/inversion/index.js';
1
+ import type { Binding, Container } from '../../helpers/inversion/index.js';
2
2
  import type { IConfigurable, ValueOrPromise } from '@venizia/ignis-helpers/common';
3
3
  import { BaseHelper } from '@venizia/ignis-helpers/core';
4
4
  type TInitDefault = {
@@ -9,7 +9,7 @@ type TInitDefault = {
9
9
  };
10
10
  /** Base of every component: `configure()` stores the options once, then runs `binding()` to register the component bindings. A second `configure()` call is a no-op. */
11
11
  export declare abstract class BaseComponent<ConfigurableOptions extends object = {}> extends BaseHelper implements IConfigurable<ConfigurableOptions> {
12
- protected bindings: Record<TBindingKey, Binding>;
12
+ protected bindings: Record<string, Binding>;
13
13
  protected initDefault: TInitDefault;
14
14
  protected isConfigured: boolean;
15
15
  /** What `application.component(Ctor, { options })` handed this instance, set before `binding()` runs. Optional, not defaulted to `{}`: a component registered through `configs.artifacts` gets no options and uses `??` to fall back to its binding, which an empty object would silently defeat. */
@@ -17,7 +17,7 @@ export declare abstract class BaseComponent<ConfigurableOptions extends object =
17
17
  constructor(opts: {
18
18
  scope: string;
19
19
  initDefault?: TInitDefault;
20
- bindings?: Record<TBindingKey, Binding>;
20
+ bindings?: Record<string, Binding>;
21
21
  });
22
22
  abstract binding(): ValueOrPromise<void>;
23
23
  /** Override this, not the field, to resolve options lazily. */
@@ -18,11 +18,11 @@ export class BaseComponent extends BaseHelper {
18
18
  message: '[initBindings] Invalid DI Container to init bindings!',
19
19
  });
20
20
  }
21
- for (const key in this.bindings) {
22
- if (container.isBound({ key })) {
21
+ for (const binding of Object.values(this.bindings)) {
22
+ if (container.isBound({ key: binding.key })) {
23
23
  continue;
24
24
  }
25
- container.set({ binding: this.bindings[key] });
25
+ container.set({ binding });
26
26
  }
27
27
  }
28
28
  async configure(opts) {
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/base/components/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAInE,wKAAwK;AACxK,MAAM,OAAgB,aACpB,SAAQ,UAAU;IAWlB,YAAY,IAIX;QACC,KAAK,CAAC,IAAI,CAAC,CAAC;QAVJ,iBAAY,GAAG,KAAK,CAAC;QAY7B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,EAAE,MAAM,EAAE,KAAK,EA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B,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;aACtB,IAAI,CAAC,0CAA0C,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7E,CAAC;CACF","sourcesContent":["import type { Binding, Container, TBindingKey } from '@/helpers/inversion';\nimport type { IConfigurable, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\n\ntype TInitDefault = { enable: false } | { enable: true; container: Container };\n\n/** Base of every component: `configure()` stores the options once, then runs `binding()` to register the component bindings. A second `configure()` call is a no-op. */\nexport abstract class BaseComponent<ConfigurableOptions extends object = {}>\n extends BaseHelper\n implements IConfigurable<ConfigurableOptions>\n{\n protected bindings: Record<TBindingKey, Binding>;\n\n protected initDefault: TInitDefault;\n protected isConfigured = false;\n\n /** What `application.component(Ctor, { options })` handed this instance, set before `binding()` runs. Optional, not defaulted to `{}`: a component registered through `configs.artifacts` gets no options and uses `??` to fall back to its binding, which an empty object would silently defeat. */\n options?: ConfigurableOptions;\n\n constructor(opts: {\n scope: string;\n initDefault?: TInitDefault;\n bindings?: Record<TBindingKey, Binding>;\n }) {\n super(opts);\n\n this.initDefault = opts.initDefault ?? { enable: false };\n this.bindings = opts.bindings ?? {};\n }\n\n abstract binding(): ValueOrPromise<void>;\n\n /** Override this, not the field, to resolve options lazily. */\n getOptions(): ConfigurableOptions | undefined {\n return this.options;\n }\n\n protected initDefaultBindings(opts: { container: Container }) {\n const { container } = opts;\n\n if (!container) {\n throw getError({\n message: '[initBindings] Invalid DI Container to init bindings!',\n });\n }\n\n for (const key in this.bindings) {\n if (container.isBound({ key })) {\n continue;\n }\n\n container.set({ binding: this.bindings[key] });\n }\n }\n\n async configure(opts?: ConfigurableOptions): Promise<void> {\n if (this.isConfigured) {\n return;\n }\n\n const t = performance.now();\n\n this.options = opts;\n\n this.logger.for(this.binding.name).info('START | Binding component | Options: %j', opts ?? {});\n\n if (this.initDefault?.enable) {\n this.initDefaultBindings({ container: this.initDefault.container });\n }\n\n await this.binding();\n\n this.isConfigured = true;\n this.logger\n .for(this.binding.name)\n .info('DONE | Binding component | Took: %s (ms)', performance.now() - t);\n }\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/base/components/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAInE,wKAAwK;AACxK,MAAM,OAAgB,aACpB,SAAQ,UAAU;IAWlB,YAAY,IAIX;QACC,KAAK,CAAC,IAAI,CAAC,CAAC;QAVJ,iBAAY,GAAG,KAAK,CAAC;QAY7B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QACzD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;IACtC,CAAC;IAID,+DAA+D;IAC/D,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAES,mBAAmB,CAAC,IAA8B;QAC1D,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAE3B,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,uDAAuD;aACjE,CAAC,CAAC;QACL,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACnD,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;gBAC5C,SAAS;YACX,CAAC;YAED,SAAS,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAA0B;QACxC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAE5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,yCAAyC,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QAE/F,IAAI,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC;YAC7B,IAAI,CAAC,mBAAmB,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC;QACtE,CAAC;QAED,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAErB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,MAAM;aACR,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;aACtB,IAAI,CAAC,0CAA0C,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7E,CAAC;CACF","sourcesContent":["import type { Binding, Container } from '@/helpers/inversion';\nimport type { IConfigurable, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\n\ntype TInitDefault = { enable: false } | { enable: true; container: Container };\n\n/** Base of every component: `configure()` stores the options once, then runs `binding()` to register the component bindings. A second `configure()` call is a no-op. */\nexport abstract class BaseComponent<ConfigurableOptions extends object = {}>\n extends BaseHelper\n implements IConfigurable<ConfigurableOptions>\n{\n protected bindings: Record<string, Binding>;\n\n protected initDefault: TInitDefault;\n protected isConfigured = false;\n\n /** What `application.component(Ctor, { options })` handed this instance, set before `binding()` runs. Optional, not defaulted to `{}`: a component registered through `configs.artifacts` gets no options and uses `??` to fall back to its binding, which an empty object would silently defeat. */\n options?: ConfigurableOptions;\n\n constructor(opts: {\n scope: string;\n initDefault?: TInitDefault;\n bindings?: Record<string, Binding>;\n }) {\n super(opts);\n\n this.initDefault = opts.initDefault ?? { enable: false };\n this.bindings = opts.bindings ?? {};\n }\n\n abstract binding(): ValueOrPromise<void>;\n\n /** Override this, not the field, to resolve options lazily. */\n getOptions(): ConfigurableOptions | undefined {\n return this.options;\n }\n\n protected initDefaultBindings(opts: { container: Container }) {\n const { container } = opts;\n\n if (!container) {\n throw getError({\n message: '[initBindings] Invalid DI Container to init bindings!',\n });\n }\n\n for (const binding of Object.values(this.bindings)) {\n if (container.isBound({ key: binding.key })) {\n continue;\n }\n\n container.set({ binding });\n }\n }\n\n async configure(opts?: ConfigurableOptions): Promise<void> {\n if (this.isConfigured) {\n return;\n }\n\n const t = performance.now();\n\n this.options = opts;\n\n this.logger.for(this.binding.name).info('START | Binding component | Options: %j', opts ?? {});\n\n if (this.initDefault?.enable) {\n this.initDefaultBindings({ container: this.initDefault.container });\n }\n\n await this.binding();\n\n this.isConfigured = true;\n this.logger\n .for(this.binding.name)\n .info('DONE | Binding component | Took: %s (ms)', performance.now() - t);\n }\n}\n"]}
@@ -3,6 +3,7 @@ export interface IRestComponentConfig {
3
3
  }
4
4
  /** Binding keys of the REST component. */
5
5
  export declare class RestBindingKeys {
6
- static readonly REST_COMPONENT_OPTIONS = "@app/rest/options";
6
+ /** Untyped on purpose: `IRestComponentConfig` has no fields, so a type would check nothing. */
7
+ static readonly REST_COMPONENT_OPTIONS: import("@venizia/ignis-inversion").TBindingKey<unknown>;
7
8
  }
8
9
  //# sourceMappingURL=types.d.ts.map
@@ -1,5 +1,7 @@
1
+ import { BindingKeys } from '../../../../../helpers/inversion/index.js';
1
2
  /** Binding keys of the REST component. */
2
3
  export class RestBindingKeys {
3
- static { this.REST_COMPONENT_OPTIONS = '@app/rest/options'; }
4
+ /** Untyped on purpose: `IRestComponentConfig` has no fields, so a type would check nothing. */
5
+ static { this.REST_COMPONENT_OPTIONS = BindingKeys.build({ key: '@app/rest/options' }); }
4
6
  }
5
7
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/base/components/controller/rest/common/types.ts"],"names":[],"mappings":"AAGA,0CAA0C;AAC1C,MAAM,OAAO,eAAe;aACV,2BAAsB,GAAG,mBAAmB,CAAC","sourcesContent":["/** Options of the REST component. Currently has no keys. */\nexport interface IRestComponentConfig {}\n\n/** Binding keys of the REST component. */\nexport class RestBindingKeys {\n static readonly REST_COMPONENT_OPTIONS = '@app/rest/options';\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/base/components/controller/rest/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKlD,0CAA0C;AAC1C,MAAM,OAAO,eAAe;IAC1B,+FAA+F;aAC/E,2BAAsB,GAAG,WAAW,CAAC,KAAK,CAAU,EAAE,GAAG,EAAE,mBAAmB,EAAE,CAAC,CAAC","sourcesContent":["import { BindingKeys } from '@/helpers/inversion';\n\n/** Options of the REST component. Currently has no keys. */\nexport interface IRestComponentConfig {}\n\n/** Binding keys of the REST component. */\nexport class RestBindingKeys {\n /** Untyped on purpose: `IRestComponentConfig` has no fields, so a type would check nothing. */\n static readonly REST_COMPONENT_OPTIONS = BindingKeys.build<unknown>({ key: '@app/rest/options' });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"rest.component.js","sourceRoot":"","sources":["../../../../../../src/base/components/controller/rest/rest.component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAA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AAM,EAAE,CAAC,CAAC;gBAElF,+DAA+D;gBAC/D,IAAI,QAAQ,EAAE,SAAS,KAAK,oBAAoB,CAAC,IAAI,EAAE,CAAC;oBACtD,OAAO;gBACT,CAAC;gBAED,IAAI,CAAC,QAAQ,EAAE,IAAI,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;oBACvE,MAAM,QAAQ,CAAC;wBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;wBACrD,OAAO,EAAE,+BAA+B,OAAO,CAAC,GAAG,6EAA6E;qBACjI,CAAC,CAAC;gBACL,CAAC;gBAED,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAyB;oBAC5D,GAAG,EAAE,OAAO,CAAC,GAAG;oBAChB,UAAU,EAAE,KAAK;iBAClB,CAAC,CAAC;gBAEH,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACd,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;oBAE3D,OAAO;gBACT,CAAC;gBAED,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAC;gBAC3B,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;gBAElD,MAAM,CAAC,IAAI,CAAC,iDAAiD,EAAE,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC7F,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { RestApplication } from '@/base/applications/rest';\nimport { ControllerTransports } from '@/base/controllers/common/constants';\nimport type { AbstractRestController } from '@/base/controllers/rest/abstract';\nimport { BindingNamespaces } from '@/common/bindings';\nimport { Binding, BindingValueTypes, MetadataRegistry } from '@/helpers/inversion';\nimport { BaseComponent } from '../../base';\nimport type { Env, Schema } from 'hono';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP, ObjectUtility } from '@venizia/ignis-helpers/common';\nimport type { IRestComponentConfig } from './common/types';\nimport { RestBindingKeys } from './common/types';\n\nconst DEFAULT_OPTIONS: IRestComponentConfig = {};\n\n/**\n * Generic over the same Hono env/schema/base-path `RestApplication` is: a bare `RestApplication`\n * parameter (defaulting to `RestApplication<Env, {}, '/'>`) fails to typecheck when passed `this`\n * from inside a differently-instantiated generic `RestApplication` subclass - `defaultHook`'s\n * contravariance makes the defaulted instantiation incompatible with an arbitrary one. Matching the\n * caller's own instantiation here removes the mismatch instead of widening to `any`.\n */\nexport class RestComponent<\n AppEnv extends Env = Env,\n AppSchema extends Schema = {},\n BasePath extends string = '/',\n> extends BaseComponent {\n constructor(private application: RestApplication<AppEnv, AppSchema, BasePath>) {\n super({\n scope: RestComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [RestBindingKeys.REST_COMPONENT_OPTIONS]: Binding.bind<IRestComponentConfig>({\n key: RestBindingKeys.REST_COMPONENT_OPTIONS,\n }).toValue(DEFAULT_OPTIONS),\n },\n });\n }\n\n override async binding(): Promise<void> {\n const logger = this.logger.for(this.binding.name);\n const router = this.application.getRootRouter();\n\n await this.application.drainByTag<AbstractRestController>({\n tag: BindingNamespaces.CONTROLLER,\n configured: new Set<string>(),\n onEach: async ({ binding }) => {\n const target = binding.getBindingMeta({ type: BindingValueTypes.CLASS });\n\n if (!target) {\n return;\n }\n\n const metadata = MetadataRegistry.getInstance().getControllerMetadata({ target });\n\n // Skip gRPC controllers - they are configured by GrpcComponent\n if (metadata?.transport === ControllerTransports.GRPC) {\n return;\n }\n\n if (!metadata?.path || ObjectUtility.isEmpty({ value: metadata.path })) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[registerControllers] key: '${binding.key}' | Invalid controller metadata, 'path' is required for controller metadata`,\n });\n }\n\n const instance = this.application.get<AbstractRestController>({\n key: binding.key,\n isOptional: false,\n });\n\n if (!instance) {\n logger.debug('No binding instance | key: %s', binding.key);\n\n return;\n }\n\n await instance.configure();\n router.route(metadata.path, instance.getRouter());\n\n logger.info('Configured REST controller | key: %s | path: %s', binding.key, metadata.path);\n },\n });\n }\n}\n"]}
1
+ {"version":3,"file":"rest.component.js","sourceRoot":"","sources":["../../../../../../src/base/components/controller/rest/rest.component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,eAAe,GAAyB,EAAE,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,OAAO,aAIX,SAAQ,aAAa;IACrB,YAAoB,WAAyD;QAC3E,KAAK,CAAC;YACJ,KAAK,EAAE,aAAa,CAAC,IAAI;YACzB,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE;YACrD,QAAQ,EAAE;gBACR,CAAC,eAAe,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC;oBACrD,GAAG,EAAE,eAAe,CAAC,sBAAsB;iBAC5C,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC;aAC5B;SACF,CAAC,CAAC;QATe,gBAAW,GAAX,WAAW,CAA8C;IAU7E,CAAC;IAEQ,KAAK,CAAC,OAAO;QACpB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,OAA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3D,OAAO;gBACT,CAAC;gBAED,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAC;gBAC3B,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;gBAElD,MAAM,CAAC,IAAI,CAAC,iDAAiD,EAAE,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC7F,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { RestApplication } from '@/base/applications/rest';\nimport { ControllerTransports } from '@/base/controllers/common/constants';\nimport type { AbstractRestController } from '@/base/controllers/rest/abstract';\nimport { BindingNamespaces } from '@/common/bindings';\nimport { Binding, BindingValueTypes, MetadataRegistry } from '@/helpers/inversion';\nimport { BaseComponent } from '../../base';\nimport type { Env, Schema } from 'hono';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { HTTP, ObjectUtility } from '@venizia/ignis-helpers/common';\nimport type { IRestComponentConfig } from './common/types';\nimport { RestBindingKeys } from './common/types';\n\nconst DEFAULT_OPTIONS: IRestComponentConfig = {};\n\n/**\n * Generic over the same Hono env/schema/base-path `RestApplication` is: a bare `RestApplication`\n * parameter (defaulting to `RestApplication<Env, {}, '/'>`) fails to typecheck when passed `this`\n * from inside a differently-instantiated generic `RestApplication` subclass - `defaultHook`'s\n * contravariance makes the defaulted instantiation incompatible with an arbitrary one. Matching the\n * caller's own instantiation here removes the mismatch instead of widening to `any`.\n */\nexport class RestComponent<\n AppEnv extends Env = Env,\n AppSchema extends Schema = {},\n BasePath extends string = '/',\n> extends BaseComponent {\n constructor(private application: RestApplication<AppEnv, AppSchema, BasePath>) {\n super({\n scope: RestComponent.name,\n initDefault: { enable: true, container: application },\n bindings: {\n [RestBindingKeys.REST_COMPONENT_OPTIONS]: Binding.bind({\n key: RestBindingKeys.REST_COMPONENT_OPTIONS,\n }).toValue(DEFAULT_OPTIONS),\n },\n });\n }\n\n override async binding(): Promise<void> {\n const logger = this.logger.for(this.binding.name);\n const router = this.application.getRootRouter();\n\n await this.application.drainByTag<AbstractRestController>({\n tag: BindingNamespaces.CONTROLLER,\n configured: new Set<string>(),\n onEach: async ({ binding }) => {\n const target = binding.getBindingMeta({ type: BindingValueTypes.CLASS });\n\n if (!target) {\n return;\n }\n\n const metadata = MetadataRegistry.getInstance().getControllerMetadata({ target });\n\n // Skip gRPC controllers - they are configured by GrpcComponent\n if (metadata?.transport === ControllerTransports.GRPC) {\n return;\n }\n\n if (!metadata?.path || ObjectUtility.isEmpty({ value: metadata.path })) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[registerControllers] key: '${binding.key}' | Invalid controller metadata, 'path' is required for controller metadata`,\n });\n }\n\n const instance = this.application.get<AbstractRestController>({\n key: binding.key,\n isOptional: false,\n });\n\n if (!instance) {\n logger.debug('No binding instance | key: %s', binding.key);\n\n return;\n }\n\n await instance.configure();\n router.route(metadata.path, instance.getRouter());\n\n logger.info('Configured REST controller | key: %s | path: %s', binding.key, metadata.path);\n },\n });\n }\n}\n"]}
@@ -38,7 +38,10 @@ export class CrudControllerFactory extends BaseHelper {
38
38
  target,
39
39
  index: 0,
40
40
  metadata: {
41
- key: BindingKeys.build({ namespace: BindingNamespaces.REPOSITORY, key: repositoryName }),
41
+ key: BindingKeys.build({
42
+ namespace: BindingNamespaces.REPOSITORY,
43
+ key: repositoryName,
44
+ }),
42
45
  index: 0,
43
46
  isOptional: false,
44
47
  },
@@ -1 +1 @@
1
- {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../src/base/controllers/factory/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAG9E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,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I,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC;QAC1F,CAAC,CAAC,CAAC;QAEH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/F,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,cAAc,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9E,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE;gBACP,gGAAgG,cAAc,cAAc,KAAK,iBAAiB,SAAS,EAAE;gBAC7J,sEAAsE;gBACtE,0HAA0H;aAC3H,CAAC,IAAI,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC","sourcesContent":["import type { AbstractRepository } from '@/base/repositories';\nimport { AuthorizationActions } from '@/base/auth/authorize/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type { AbstractEntity } from '@/base/models';\nimport { AuditFields, SchemaTypes } from '@/base/models/common/constants';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport { BindingNamespaces } from '@/common/bindings';\nimport { BindingKeys, MetadataRegistry } from '@/helpers/inversion';\nimport type { TClass, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { isClass } from '@venizia/ignis-inversion';\nimport type { Env, Schema } from 'hono';\nimport type {\n ICrudControllerOptions,\n TCrudRepositoryClass,\n TCrudRoutes,\n TRepositoryDataObject,\n TRepositoryPersistObject,\n} from '../common';\nimport { PersistableCrudController } from './crud';\nimport { RouteConfigResolver } from './definition';\n\n/** Factory for generating typed CRUD controllers from entity definitions. */\nexport class CrudControllerFactory extends BaseHelper {\n /** The generated routes that change data: the ones that must never be answered by a `read` permission. */\n private static readonly WRITE_VERBS = [\n 'create',\n 'updateById',\n 'updateBy',\n 'deleteById',\n 'deleteBy',\n 'restoreById',\n 'restoreBy',\n ] as const;\n\n constructor() {\n super({ scope: CrudControllerFactory.name });\n }\n\n /**\n * Injects `repositories.<repositoryName>` into constructor parameter 0 of a factory-generated\n * controller, so a subclass needs no constructor. Recorded as metadata rather than a parameter\n * decorator, which Bun drops in some configurations. A subclass that declares its own `@inject` at\n * index 0 wins, and a sibling subclass keeps the factory's key.\n */\n static registerRepositoryInjection(opts: {\n target: TClass<unknown>;\n factoryName: string;\n repositoryName: string;\n }): void {\n const { target, factoryName, repositoryName } = opts;\n\n if (!repositoryName) {\n throw getError({\n message: `[${factoryName}] Invalid repository name | repository.name must name the repository binding`,\n });\n }\n\n MetadataRegistry.getInstance().setInjectMetadata({\n target,\n index: 0,\n metadata: {\n key: BindingKeys.build({ namespace: BindingNamespaces.REPOSITORY, key: repositoryName }),\n index: 0,\n isOptional: false,\n },\n });\n }\n\n static build<\n Repository extends TCrudRepositoryClass,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TRepositoryDataObject<InstanceType<Repository>>,\n TPersistObject extends object = TRepositoryPersistObject<InstanceType<Repository>>,\n >(opts: ICrudControllerOptions<Repository>) {\n const { repository, authenticate, authorize, routes, isStrict = {} } = opts;\n\n CrudControllerFactory.assertWriteVerbsDeclareAuthorize({\n repositoryName: repository.name,\n authorize,\n routes,\n });\n CrudControllerFactory.assertRestoreRoutesSupported({ repository, routes });\n\n const model = MetadataRegistry.getInstance().getRepositoryBinding({\n target: repository,\n })?.model;\n\n if (!model) {\n throw getError({\n message: `[CrudControllerFactory.build] Cannot resolve the entity | repository: ${repository.name} | declare it with @repository({ model })`,\n });\n }\n\n const entityClass = isClass(model) ? model : model();\n const entityInstance = new entityClass();\n const settings = MetadataRegistry.getInstance().getModelMetadata({\n target: entityClass,\n })?.settings;\n\n const routeDefinitions = RouteConfigResolver.defineControllerRouteConfigs({\n isStrict: isStrict.requestSchema ?? true,\n idType: entityInstance.getIdType(),\n authenticate,\n authorize,\n routes,\n schema: {\n select: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.SELECT }),\n create: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.CREATE }),\n update: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.UPDATE }),\n },\n serverStampedKeys: [...(settings?.properties?.stamped ?? AuditFields.SCHEME_SET)],\n });\n\n const controllerClass = class extends PersistableCrudController<\n AbstractEntity<TAnyObjectSchema>,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject,\n TPersistObject\n > {\n constructor(repositoryInstance: AbstractRepository<TDataObject, TPersistObject>) {\n super({\n scope: new.target.name,\n isStrict: isStrict.path ?? true,\n repository: repositoryInstance,\n definitions: routeDefinitions,\n });\n }\n\n /** The routes of a generated controller come from `routes`; a subclass adds its own here. */\n override binding(): ValueOrPromise<void> {}\n\n /** Registers each listed CRUD route, after `binding()`: a custom static path is never taken by `/{id}`. */\n override bindDefaultRoutes(): ValueOrPromise<void> {\n if (routeDefinitions.COUNT) {\n this.defineRoute({\n configs: routeDefinitions.COUNT,\n handler: async (context) => this.count({ context }),\n });\n }\n\n if (routeDefinitions.FIND) {\n this.defineRoute({\n configs: routeDefinitions.FIND,\n handler: async (context) => this.find({ context }),\n });\n }\n\n if (routeDefinitions.FIND_ONE) {\n this.defineRoute({\n configs: routeDefinitions.FIND_ONE,\n handler: async (context) => this.findOne({ context }),\n });\n }\n\n if (routeDefinitions.FIND_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.FIND_BY_ID,\n handler: async (context) => this.findById({ context }),\n });\n }\n\n if (routeDefinitions.CREATE) {\n this.defineRoute({\n configs: routeDefinitions.CREATE,\n handler: async (context) => this.create({ context }),\n });\n }\n\n if (routeDefinitions.UPDATE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.UPDATE_BY_ID,\n handler: async (context) => this.updateById({ context }),\n });\n }\n\n if (routeDefinitions.UPDATE_BY) {\n this.defineRoute({\n configs: routeDefinitions.UPDATE_BY,\n handler: async (context) => this.updateBy({ context }),\n });\n }\n\n if (routeDefinitions.DELETE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.DELETE_BY_ID,\n handler: async (context) => this.deleteById({ context }),\n });\n }\n\n if (routeDefinitions.DELETE_BY) {\n this.defineRoute({\n configs: routeDefinitions.DELETE_BY,\n handler: async (context) => this.deleteBy({ context }),\n });\n }\n\n if (routeDefinitions.RESTORE_BY) {\n this.defineRoute({\n configs: routeDefinitions.RESTORE_BY,\n handler: async (context) => this.restoreBy({ context }),\n });\n }\n\n if (routeDefinitions.RESTORE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.RESTORE_BY_ID,\n handler: async (context) => this.restoreById({ context }),\n });\n }\n }\n };\n\n CrudControllerFactory.registerRepositoryInjection({\n target: controllerClass,\n factoryName: 'CrudControllerFactory.build',\n repositoryName: repository.name,\n });\n\n return controllerClass;\n }\n\n /** A restore route needs a repository that has the restore methods; the types already refuse one, this is the backstop for an untyped caller. */\n private static assertRestoreRoutesSupported(opts: {\n repository: TCrudRepositoryClass;\n routes: TCrudRoutes | undefined;\n }): void {\n const { repository, routes } = opts;\n\n const isRestoreListed = routes?.restoreById !== undefined || routes?.restoreBy !== undefined;\n const isRestorable =\n typeof repository.prototype.restoreById === 'function' &&\n typeof repository.prototype.restoreBy === 'function';\n\n if (isRestoreListed && !isRestorable) {\n throw getError({\n message: `[CrudControllerFactory.build] a restore route needs a repository with both restoreById and restoreBy | repository: ${repository.name}`,\n });\n }\n }\n\n private static describeSpec(opts: { spec: IAuthorizationSpec }): string {\n const { spec } = opts;\n\n return `{ action: ${String(spec.action)}, resource: ${String(spec.resource)} }`;\n }\n\n /**\n * Refuses a CRUD controller that lists a write verb which would inherit a controller-level `authorize`\n * that is only a `read` permission: the verb would then answer to anyone who may read.\n *\n * A listed write verb is fine when it declares its own `authorize` (a spec, an array, or `{ skip: true }`) or\n * skips authentication. Only the literal action `read` is detected; a custom action name is the application's own\n * vocabulary. An array counts when every spec in it is `read`, since the specs of one route must all pass.\n */\n static assertWriteVerbsDeclareAuthorize(opts: {\n repositoryName: string;\n authorize: IAuthorizationSpec | IAuthorizationSpec[] | undefined;\n routes: TCrudRoutes | undefined;\n }): void {\n const { repositoryName, authorize, routes } = opts;\n\n if (authorize == null) {\n return;\n }\n\n const specs = Array.isArray(authorize) ? authorize : [authorize];\n const isReadOnlyPermission =\n specs.length > 0 && specs.every((spec) => spec.action === AuthorizationActions.READ);\n\n if (!isReadOnlyPermission) {\n return;\n }\n\n const offending = CrudControllerFactory.WRITE_VERBS.filter((verb) => {\n const route = routes?.[verb];\n\n if (route === undefined) {\n return false;\n }\n\n return route === true || (route.authenticate?.skip !== true && route.authorize == null);\n });\n\n if (offending.length === 0) {\n return;\n }\n\n const inherited = specs.map((spec) => CrudControllerFactory.describeSpec({ spec })).join(', ');\n const verbs = offending.map((verb) => `${repositoryName}.${verb}`).join(', ');\n\n throw getError({\n message: [\n `[CrudControllerFactory.build] Write routes would inherit a read-only authorize | repository: ${repositoryName} | routes: ${verbs} | inherited: ${inherited}`,\n 'Anyone allowed to read could then create, update, delete or restore.',\n 'Fix: declare routes.<verb>.authorize for each of them (a spec, an array or { skip: true }), or leave them out of routes.',\n ].join(' | '),\n });\n }\n}\n"]}
1
+ {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../src/base/controllers/factory/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAG9E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MA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I,CAAC,CAAC;YAE7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC;QAC1F,CAAC,CAAC,CAAC;QAEH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/F,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,cAAc,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9E,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE;gBACP,gGAAgG,cAAc,cAAc,KAAK,iBAAiB,SAAS,EAAE;gBAC7J,sEAAsE;gBACtE,0HAA0H;aAC3H,CAAC,IAAI,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC","sourcesContent":["import type { AbstractRepository } from '@/base/repositories';\nimport { AuthorizationActions } from '@/base/auth/authorize/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type { AbstractEntity } from '@/base/models';\nimport { AuditFields, SchemaTypes } from '@/base/models/common/constants';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport { BindingNamespaces } from '@/common/bindings';\nimport { BindingKeys, MetadataRegistry } from '@/helpers/inversion';\nimport type { TClass, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { isClass } from '@venizia/ignis-inversion';\nimport type { Env, Schema } from 'hono';\nimport type {\n ICrudControllerOptions,\n TCrudRepositoryClass,\n TCrudRoutes,\n TRepositoryDataObject,\n TRepositoryPersistObject,\n} from '../common';\nimport { PersistableCrudController } from './crud';\nimport { RouteConfigResolver } from './definition';\n\n/** Factory for generating typed CRUD controllers from entity definitions. */\nexport class CrudControllerFactory extends BaseHelper {\n /** The generated routes that change data: the ones that must never be answered by a `read` permission. */\n private static readonly WRITE_VERBS = [\n 'create',\n 'updateById',\n 'updateBy',\n 'deleteById',\n 'deleteBy',\n 'restoreById',\n 'restoreBy',\n ] as const;\n\n constructor() {\n super({ scope: CrudControllerFactory.name });\n }\n\n /**\n * Injects `repositories.<repositoryName>` into constructor parameter 0 of a factory-generated\n * controller, so a subclass needs no constructor. Recorded as metadata rather than a parameter\n * decorator, which Bun drops in some configurations. A subclass that declares its own `@inject` at\n * index 0 wins, and a sibling subclass keeps the factory's key.\n */\n static registerRepositoryInjection(opts: {\n target: TClass<unknown>;\n factoryName: string;\n repositoryName: string;\n }): void {\n const { target, factoryName, repositoryName } = opts;\n\n if (!repositoryName) {\n throw getError({\n message: `[${factoryName}] Invalid repository name | repository.name must name the repository binding`,\n });\n }\n\n MetadataRegistry.getInstance().setInjectMetadata({\n target,\n index: 0,\n metadata: {\n key: BindingKeys.build<unknown>({\n namespace: BindingNamespaces.REPOSITORY,\n key: repositoryName,\n }),\n index: 0,\n isOptional: false,\n },\n });\n }\n\n static build<\n Repository extends TCrudRepositoryClass,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TRepositoryDataObject<InstanceType<Repository>>,\n TPersistObject extends object = TRepositoryPersistObject<InstanceType<Repository>>,\n >(opts: ICrudControllerOptions<Repository>) {\n const { repository, authenticate, authorize, routes, isStrict = {} } = opts;\n\n CrudControllerFactory.assertWriteVerbsDeclareAuthorize({\n repositoryName: repository.name,\n authorize,\n routes,\n });\n CrudControllerFactory.assertRestoreRoutesSupported({ repository, routes });\n\n const model = MetadataRegistry.getInstance().getRepositoryBinding({\n target: repository,\n })?.model;\n\n if (!model) {\n throw getError({\n message: `[CrudControllerFactory.build] Cannot resolve the entity | repository: ${repository.name} | declare it with @repository({ model })`,\n });\n }\n\n const entityClass = isClass(model) ? model : model();\n const entityInstance = new entityClass();\n const settings = MetadataRegistry.getInstance().getModelMetadata({\n target: entityClass,\n })?.settings;\n\n const routeDefinitions = RouteConfigResolver.defineControllerRouteConfigs({\n isStrict: isStrict.requestSchema ?? true,\n idType: entityInstance.getIdType(),\n authenticate,\n authorize,\n routes,\n schema: {\n select: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.SELECT }),\n create: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.CREATE }),\n update: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.UPDATE }),\n },\n serverStampedKeys: [...(settings?.properties?.stamped ?? AuditFields.SCHEME_SET)],\n });\n\n const controllerClass = class extends PersistableCrudController<\n AbstractEntity<TAnyObjectSchema>,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject,\n TPersistObject\n > {\n constructor(repositoryInstance: AbstractRepository<TDataObject, TPersistObject>) {\n super({\n scope: new.target.name,\n isStrict: isStrict.path ?? true,\n repository: repositoryInstance,\n definitions: routeDefinitions,\n });\n }\n\n /** The routes of a generated controller come from `routes`; a subclass adds its own here. */\n override binding(): ValueOrPromise<void> {}\n\n /** Registers each listed CRUD route, after `binding()`: a custom static path is never taken by `/{id}`. */\n override bindDefaultRoutes(): ValueOrPromise<void> {\n if (routeDefinitions.COUNT) {\n this.defineRoute({\n configs: routeDefinitions.COUNT,\n handler: async (context) => this.count({ context }),\n });\n }\n\n if (routeDefinitions.FIND) {\n this.defineRoute({\n configs: routeDefinitions.FIND,\n handler: async (context) => this.find({ context }),\n });\n }\n\n if (routeDefinitions.FIND_ONE) {\n this.defineRoute({\n configs: routeDefinitions.FIND_ONE,\n handler: async (context) => this.findOne({ context }),\n });\n }\n\n if (routeDefinitions.FIND_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.FIND_BY_ID,\n handler: async (context) => this.findById({ context }),\n });\n }\n\n if (routeDefinitions.CREATE) {\n this.defineRoute({\n configs: routeDefinitions.CREATE,\n handler: async (context) => this.create({ context }),\n });\n }\n\n if (routeDefinitions.UPDATE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.UPDATE_BY_ID,\n handler: async (context) => this.updateById({ context }),\n });\n }\n\n if (routeDefinitions.UPDATE_BY) {\n this.defineRoute({\n configs: routeDefinitions.UPDATE_BY,\n handler: async (context) => this.updateBy({ context }),\n });\n }\n\n if (routeDefinitions.DELETE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.DELETE_BY_ID,\n handler: async (context) => this.deleteById({ context }),\n });\n }\n\n if (routeDefinitions.DELETE_BY) {\n this.defineRoute({\n configs: routeDefinitions.DELETE_BY,\n handler: async (context) => this.deleteBy({ context }),\n });\n }\n\n if (routeDefinitions.RESTORE_BY) {\n this.defineRoute({\n configs: routeDefinitions.RESTORE_BY,\n handler: async (context) => this.restoreBy({ context }),\n });\n }\n\n if (routeDefinitions.RESTORE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.RESTORE_BY_ID,\n handler: async (context) => this.restoreById({ context }),\n });\n }\n }\n };\n\n CrudControllerFactory.registerRepositoryInjection({\n target: controllerClass,\n factoryName: 'CrudControllerFactory.build',\n repositoryName: repository.name,\n });\n\n return controllerClass;\n }\n\n /** A restore route needs a repository that has the restore methods; the types already refuse one, this is the backstop for an untyped caller. */\n private static assertRestoreRoutesSupported(opts: {\n repository: TCrudRepositoryClass;\n routes: TCrudRoutes | undefined;\n }): void {\n const { repository, routes } = opts;\n\n const isRestoreListed = routes?.restoreById !== undefined || routes?.restoreBy !== undefined;\n const isRestorable =\n typeof repository.prototype.restoreById === 'function' &&\n typeof repository.prototype.restoreBy === 'function';\n\n if (isRestoreListed && !isRestorable) {\n throw getError({\n message: `[CrudControllerFactory.build] a restore route needs a repository with both restoreById and restoreBy | repository: ${repository.name}`,\n });\n }\n }\n\n private static describeSpec(opts: { spec: IAuthorizationSpec }): string {\n const { spec } = opts;\n\n return `{ action: ${String(spec.action)}, resource: ${String(spec.resource)} }`;\n }\n\n /**\n * Refuses a CRUD controller that lists a write verb which would inherit a controller-level `authorize`\n * that is only a `read` permission: the verb would then answer to anyone who may read.\n *\n * A listed write verb is fine when it declares its own `authorize` (a spec, an array, or `{ skip: true }`) or\n * skips authentication. Only the literal action `read` is detected; a custom action name is the application's own\n * vocabulary. An array counts when every spec in it is `read`, since the specs of one route must all pass.\n */\n static assertWriteVerbsDeclareAuthorize(opts: {\n repositoryName: string;\n authorize: IAuthorizationSpec | IAuthorizationSpec[] | undefined;\n routes: TCrudRoutes | undefined;\n }): void {\n const { repositoryName, authorize, routes } = opts;\n\n if (authorize == null) {\n return;\n }\n\n const specs = Array.isArray(authorize) ? authorize : [authorize];\n const isReadOnlyPermission =\n specs.length > 0 && specs.every((spec) => spec.action === AuthorizationActions.READ);\n\n if (!isReadOnlyPermission) {\n return;\n }\n\n const offending = CrudControllerFactory.WRITE_VERBS.filter((verb) => {\n const route = routes?.[verb];\n\n if (route === undefined) {\n return false;\n }\n\n return route === true || (route.authenticate?.skip !== true && route.authorize == null);\n });\n\n if (offending.length === 0) {\n return;\n }\n\n const inherited = specs.map((spec) => CrudControllerFactory.describeSpec({ spec })).join(', ');\n const verbs = offending.map((verb) => `${repositoryName}.${verb}`).join(', ');\n\n throw getError({\n message: [\n `[CrudControllerFactory.build] Write routes would inherit a read-only authorize | repository: ${repositoryName} | routes: ${verbs} | inherited: ${inherited}`,\n 'Anyone allowed to read could then create, update, delete or restore.',\n 'Fix: declare routes.<verb>.authorize for each of them (a spec, an array or { skip: true }), or leave them out of routes.',\n ].join(' | '),\n });\n }\n}\n"]}