@venizia/ignis-kernel 0.4.8-9 → 0.5.0-0

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 (171) hide show
  1. package/dist/esm/base/applications/artifact-index.d.ts +3 -3
  2. package/dist/esm/base/applications/artifact-index.js.map +1 -1
  3. package/dist/esm/base/applications/body-limit.js +1 -1
  4. package/dist/esm/base/applications/body-limit.js.map +1 -1
  5. package/dist/esm/base/applications/common/types/application.d.ts +2 -2
  6. package/dist/esm/base/applications/common/types/application.js.map +1 -1
  7. package/dist/esm/base/applications/common/types/middlewares.d.ts +2 -2
  8. package/dist/esm/base/applications/common/types/middlewares.js.map +1 -1
  9. package/dist/esm/base/applications/rest.d.ts +2 -2
  10. package/dist/esm/base/applications/rest.js +6 -1
  11. package/dist/esm/base/applications/rest.js.map +1 -1
  12. package/dist/esm/base/auth/authenticate/common/keys.d.ts +21 -7
  13. package/dist/esm/base/auth/authenticate/common/keys.js +34 -7
  14. package/dist/esm/base/auth/authenticate/common/keys.js.map +1 -1
  15. package/dist/esm/base/auth/authenticate/common/types/jwt.d.ts +9 -18
  16. package/dist/esm/base/auth/authenticate/common/types/jwt.js.map +1 -1
  17. package/dist/esm/base/auth/authenticate/common/types/rest.d.ts +3 -1
  18. package/dist/esm/base/auth/authenticate/common/types/rest.js.map +1 -1
  19. package/dist/esm/base/auth/authenticate/common/types/service.d.ts +3 -3
  20. package/dist/esm/base/auth/authenticate/common/types/service.js.map +1 -1
  21. package/dist/esm/base/auth/authenticate/common/types/strategy.d.ts +2 -3
  22. package/dist/esm/base/auth/authenticate/common/types/strategy.js.map +1 -1
  23. package/dist/esm/base/auth/authenticate/strategies/strategy-registry.d.ts +1 -1
  24. package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js +1 -1
  25. package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js.map +1 -1
  26. package/dist/esm/base/auth/authorize/common/constants/binding-keys.d.ts +6 -3
  27. package/dist/esm/base/auth/authorize/common/constants/binding-keys.js +8 -3
  28. package/dist/esm/base/auth/authorize/common/constants/binding-keys.js.map +1 -1
  29. package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.js.map +1 -1
  30. package/dist/esm/base/auth/authorize/providers/request-domain.js +2 -1
  31. package/dist/esm/base/auth/authorize/providers/request-domain.js.map +1 -1
  32. package/dist/esm/base/auth/base/abstract-auth-registry.d.ts +2 -1
  33. package/dist/esm/base/auth/base/abstract-auth-registry.js +2 -2
  34. package/dist/esm/base/auth/base/abstract-auth-registry.js.map +1 -1
  35. package/dist/esm/base/components/base.d.ts +3 -3
  36. package/dist/esm/base/components/base.js +3 -3
  37. package/dist/esm/base/components/base.js.map +1 -1
  38. package/dist/esm/base/components/controller/rest/common/types.d.ts +2 -1
  39. package/dist/esm/base/components/controller/rest/common/types.js +3 -1
  40. package/dist/esm/base/components/controller/rest/common/types.js.map +1 -1
  41. package/dist/esm/base/components/controller/rest/rest.component.js.map +1 -1
  42. package/dist/esm/base/controllers/common/types/route.d.ts +13 -4
  43. package/dist/esm/base/controllers/common/types/route.js.map +1 -1
  44. package/dist/esm/base/controllers/factory/controller.d.ts +3 -4
  45. package/dist/esm/base/controllers/factory/controller.js +4 -2
  46. package/dist/esm/base/controllers/factory/controller.js.map +1 -1
  47. package/dist/esm/base/controllers/factory/crud/abstract.d.ts +3 -4
  48. package/dist/esm/base/controllers/factory/crud/abstract.js.map +1 -1
  49. package/dist/esm/base/controllers/factory/definition.d.ts +69 -49
  50. package/dist/esm/base/controllers/factory/definition.js +45 -31
  51. package/dist/esm/base/controllers/factory/definition.js.map +1 -1
  52. package/dist/esm/base/controllers/factory/index.d.ts +1 -0
  53. package/dist/esm/base/controllers/factory/index.js +1 -0
  54. package/dist/esm/base/controllers/factory/index.js.map +1 -1
  55. package/dist/esm/base/controllers/factory/injection.d.ts +38 -0
  56. package/dist/esm/base/controllers/factory/injection.js +54 -0
  57. package/dist/esm/base/controllers/factory/injection.js.map +1 -0
  58. package/dist/esm/base/controllers/rest/abstract.js +1 -1
  59. package/dist/esm/base/controllers/rest/abstract.js.map +1 -1
  60. package/dist/esm/base/controllers/rest/base.d.ts +3 -3
  61. package/dist/esm/base/controllers/rest/base.js.map +1 -1
  62. package/dist/esm/base/datasources/abstract.d.ts +4 -92
  63. package/dist/esm/base/datasources/abstract.js +3 -217
  64. package/dist/esm/base/datasources/abstract.js.map +1 -1
  65. package/dist/esm/base/datasources/common/types.d.ts +2 -2
  66. package/dist/esm/base/datasources/common/types.js.map +1 -1
  67. package/dist/esm/base/datasources/index.d.ts +1 -0
  68. package/dist/esm/base/datasources/index.js +1 -0
  69. package/dist/esm/base/datasources/index.js.map +1 -1
  70. package/dist/esm/base/datasources/root.d.ts +107 -0
  71. package/dist/esm/base/datasources/root.js +237 -0
  72. package/dist/esm/base/datasources/root.js.map +1 -0
  73. package/dist/esm/base/events/common/types.d.ts +2 -1
  74. package/dist/esm/base/events/common/types.js.map +1 -1
  75. package/dist/esm/base/events/event-bus.js.map +1 -1
  76. package/dist/esm/base/metadata/artifact-keys.d.ts +2 -1
  77. package/dist/esm/base/metadata/artifact-keys.js.map +1 -1
  78. package/dist/esm/base/metadata/index.d.ts +1 -1
  79. package/dist/esm/base/metadata/index.js +1 -1
  80. package/dist/esm/base/metadata/injectable.d.ts +2 -1
  81. package/dist/esm/base/metadata/injectable.js.map +1 -1
  82. package/dist/esm/base/metadata/injectors.d.ts +1 -1
  83. package/dist/esm/base/metadata/persistents/datasource.d.ts +21 -0
  84. package/dist/esm/base/metadata/persistents/datasource.js +46 -0
  85. package/dist/esm/base/metadata/persistents/datasource.js.map +1 -0
  86. package/dist/esm/base/metadata/persistents/index.d.ts +5 -0
  87. package/dist/esm/base/metadata/persistents/index.js +5 -0
  88. package/dist/esm/base/metadata/persistents/index.js.map +1 -0
  89. package/dist/esm/base/metadata/persistents/model.d.ts +18 -0
  90. package/dist/esm/base/metadata/persistents/model.js +64 -0
  91. package/dist/esm/base/metadata/persistents/model.js.map +1 -0
  92. package/dist/esm/base/metadata/persistents/repository/index.d.ts +19 -0
  93. package/dist/esm/base/metadata/persistents/repository/index.js +32 -0
  94. package/dist/esm/base/metadata/persistents/repository/index.js.map +1 -0
  95. package/dist/esm/base/metadata/persistents/repository/injection.d.ts +15 -0
  96. package/dist/esm/base/metadata/persistents/repository/injection.js +64 -0
  97. package/dist/esm/base/metadata/persistents/repository/injection.js.map +1 -0
  98. package/dist/esm/base/metadata/persistents/repository/resolve.d.ts +15 -0
  99. package/dist/esm/base/metadata/persistents/repository/resolve.js +76 -0
  100. package/dist/esm/base/metadata/persistents/repository/resolve.js.map +1 -0
  101. package/dist/esm/base/metadata/persistents/repository/validate.d.ts +15 -0
  102. package/dist/esm/base/metadata/persistents/repository/validate.js +50 -0
  103. package/dist/esm/base/metadata/persistents/repository/validate.js.map +1 -0
  104. package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.js +2 -1
  105. package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.js.map +1 -1
  106. package/dist/esm/base/models/common/schemas.d.ts +9 -9
  107. package/dist/esm/base/models/common/schemas.js +1 -1
  108. package/dist/esm/base/models/common/schemas.js.map +1 -1
  109. package/dist/esm/base/models/common/utilities.d.ts +1 -1
  110. package/dist/esm/base/repositories/common/response-reader.d.ts +40 -1
  111. package/dist/esm/base/repositories/common/response-reader.js +68 -1
  112. package/dist/esm/base/repositories/common/response-reader.js.map +1 -1
  113. package/dist/esm/base/repositories/common/types/contracts.d.ts +2 -2
  114. package/dist/esm/base/repositories/common/types/contracts.js.map +1 -1
  115. package/dist/esm/base/repositories/common/types/options.d.ts +2 -2
  116. package/dist/esm/base/repositories/common/types/options.js.map +1 -1
  117. package/dist/esm/base/repositories/common/types/query.d.ts +6 -15
  118. package/dist/esm/base/repositories/common/types/query.js.map +1 -1
  119. package/dist/esm/base/repositories/core/abstract.d.ts +6 -6
  120. package/dist/esm/base/repositories/core/abstract.js.map +1 -1
  121. package/dist/esm/base/repositories/query-schemas/index.js +7 -0
  122. package/dist/esm/base/repositories/query-schemas/index.js.map +1 -1
  123. package/dist/esm/common/bindings.d.ts +7 -7
  124. package/dist/esm/common/bindings.js +21 -7
  125. package/dist/esm/common/bindings.js.map +1 -1
  126. package/dist/esm/helpers/inversion/common/types/artifact.d.ts +2 -2
  127. package/dist/esm/helpers/inversion/common/types/artifact.js.map +1 -1
  128. package/dist/esm/helpers/inversion/common/types/model.d.ts +1 -1
  129. package/dist/esm/helpers/inversion/common/types/model.js.map +1 -1
  130. package/dist/esm/helpers/inversion/index.d.ts +1 -1
  131. package/dist/esm/helpers/inversion/index.js.map +1 -1
  132. package/dist/esm/helpers/inversion/mixins/artifact.mixin.d.ts +9 -8
  133. package/dist/esm/helpers/inversion/mixins/artifact.mixin.js +1 -0
  134. package/dist/esm/helpers/inversion/mixins/artifact.mixin.js.map +1 -1
  135. package/dist/esm/helpers/inversion/mixins/controllers/controller.d.ts +9 -8
  136. package/dist/esm/helpers/inversion/mixins/controllers/controller.js +1 -0
  137. package/dist/esm/helpers/inversion/mixins/controllers/controller.js.map +1 -1
  138. package/dist/esm/helpers/inversion/mixins/controllers/grpc.d.ts +9 -8
  139. package/dist/esm/helpers/inversion/mixins/controllers/grpc.js +1 -0
  140. package/dist/esm/helpers/inversion/mixins/controllers/grpc.js.map +1 -1
  141. package/dist/esm/helpers/inversion/mixins/controllers/rest.d.ts +9 -8
  142. package/dist/esm/helpers/inversion/mixins/controllers/rest.js +1 -0
  143. package/dist/esm/helpers/inversion/mixins/controllers/rest.js.map +1 -1
  144. package/dist/esm/helpers/inversion/mixins/datasource.mixin.d.ts +9 -8
  145. package/dist/esm/helpers/inversion/mixins/datasource.mixin.js +1 -0
  146. package/dist/esm/helpers/inversion/mixins/datasource.mixin.js.map +1 -1
  147. package/dist/esm/helpers/inversion/mixins/model.mixin.d.ts +9 -8
  148. package/dist/esm/helpers/inversion/mixins/model.mixin.js +1 -0
  149. package/dist/esm/helpers/inversion/mixins/model.mixin.js.map +1 -1
  150. package/dist/esm/helpers/inversion/mixins/repository.mixin.d.ts +14 -13
  151. package/dist/esm/helpers/inversion/mixins/repository.mixin.js +6 -6
  152. package/dist/esm/helpers/inversion/mixins/repository.mixin.js.map +1 -1
  153. package/dist/esm/helpers/inversion/registry.d.ts +61 -61
  154. package/dist/esm/helpers/inversion/registry.js.map +1 -1
  155. package/dist/esm/helpers/singleton-realm.js +5 -4
  156. package/dist/esm/helpers/singleton-realm.js.map +1 -1
  157. package/dist/esm/metadata.d.ts +1 -1
  158. package/dist/esm/metadata.js +1 -1
  159. package/dist/esm/repository.d.ts +1 -0
  160. package/dist/esm/repository.js +1 -0
  161. package/dist/esm/repository.js.map +1 -1
  162. package/dist/esm/utilities/index.d.ts +1 -0
  163. package/dist/esm/utilities/index.js +1 -0
  164. package/dist/esm/utilities/index.js.map +1 -1
  165. package/dist/esm/utilities/toggle.utility.d.ts +22 -0
  166. package/dist/esm/utilities/toggle.utility.js +16 -0
  167. package/dist/esm/utilities/toggle.utility.js.map +1 -0
  168. package/package.json +5 -5
  169. package/dist/esm/base/metadata/persistents.d.ts +0 -54
  170. package/dist/esm/base/metadata/persistents.js +0 -302
  171. package/dist/esm/base/metadata/persistents.js.map +0 -1
@@ -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,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,E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@/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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,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,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,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AAE,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":["../../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,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"]}
@@ -2,7 +2,6 @@ import type { TAuthMode, TAuthStrategy } from '../../../auth/authenticate/common
2
2
  import type { IAuthorizationSpec } from '../../../auth/authorize/common/types/index.js';
3
3
  import type { TAnyObjectSchema } from '../schema-builders.js';
4
4
  import type { createRoute, RouteConfig as HonoRouteConfig, OpenAPIHono, z } from '@hono/zod-openapi';
5
- import type { AnyType } from '@venizia/ignis-helpers/common';
6
5
  import type { Env, Schema } from 'hono';
7
6
  import type { TRouteHandler } from './context.js';
8
7
  /** Registered route with its configuration and router instance. */
@@ -53,10 +52,17 @@ export type TResponseHeaderObject = {
53
52
  /** OpenAPI response headers format */
54
53
  export type TResponseHeaders = Record<string, TResponseHeaderObject>;
55
54
  type TInferDistributive<S> = S extends z.ZodType ? z.infer<S> : never;
55
+ type TJsonSchemaOf<Response> = Response extends {
56
+ content: {
57
+ 'application/json': {
58
+ schema: infer JsonSchema;
59
+ };
60
+ };
61
+ } ? JsonSchema : never;
56
62
  /** The JSON response body type of a route config `R`: the union of the schemas under `application/json` across all its response codes. */
57
63
  export type TResponseBodyOf<R extends {
58
- responses: AnyType;
59
- }> = TInferDistributive<R['responses'][keyof R['responses']]['content']['application/json']['schema']>;
64
+ responses: object;
65
+ }> = TInferDistributive<TJsonSchemaOf<R['responses'][keyof R['responses']]>>;
60
66
  /** What a CRUD route lets a caller override: auth, the request schemas (params, query, body, headers) and the response schema and headers. */
61
67
  export type TCustomizableRouteConfig = TRouteAuthConfig & {
62
68
  request?: {
@@ -88,7 +94,10 @@ export interface ICustomizableRoutes<RouteConfig extends TCustomizableRouteConfi
88
94
  * The routes of a CRUD controller: only a listed route exists, as `true` (on, with its defaults) or a config
89
95
  * (on, with overrides). `restoreById` and `restoreBy` are listed only for a repository that has both methods.
90
96
  */
91
- export type TCrudRoutes<Repository extends object = AnyType> = {
97
+ export type TCrudRoutes<Repository extends object = {
98
+ restoreById: unknown;
99
+ restoreBy: unknown;
100
+ }> = {
92
101
  [Key in keyof ICustomizableRoutes]?: Key extends 'restoreById' | 'restoreBy' ? Repository extends {
93
102
  restoreById: unknown;
94
103
  restoreBy: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/common/types/route.ts"],"names":[],"mappings":"","sourcesContent":["import type { TAuthMode, TAuthStrategy } from '@/base/auth/authenticate/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport type {\n createRoute,\n RouteConfig as HonoRouteConfig,\n OpenAPIHono,\n z,\n} from '@hono/zod-openapi';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TRouteHandler } from './context';\n\n/** Registered route with its configuration and router instance. */\nexport interface IDefineRouteOptions<\n RouteConfig extends HonoRouteConfig,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n> {\n configs: ReturnType<typeof createRoute<string, RouteConfig>>;\n route: OpenAPIHono<RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Fluent binding for two-step route registration: bindRoute({ configs }).to({ handler }). */\nexport interface IBindRouteOptions<\n RouteConfig extends HonoRouteConfig,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n> {\n configs: RouteConfig;\n to: <ResponseType = unknown>(opts: {\n handler: TRouteHandler<ResponseType, RouteEnv>;\n }) => IDefineRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Route configuration extended with optional authenticate and authorize fields. */\nexport interface IAuthRouteConfig extends HonoRouteConfig {\n authenticate?: { strategies?: TAuthStrategy[]; mode?: TAuthMode };\n authorize?: IAuthorizationSpec | IAuthorizationSpec[];\n}\n\n/** Per-route authentication config: { skip: true } or { strategies, mode }. */\nexport type TRouteAuthenticateConfig =\n | { skip: true }\n | { skip?: false; strategies?: TAuthStrategy[]; mode?: TAuthMode };\n\n/** Per-route authorization config: { skip: true }, single spec, or array of specs. */\nexport type TRouteAuthorizeConfig = { skip: true } | IAuthorizationSpec | IAuthorizationSpec[];\n\n/** Per-route auth config. Endpoint config takes precedence over controller-level config. */\nexport type TRouteAuthConfig = {\n authenticate?: TRouteAuthenticateConfig;\n authorize?: TRouteAuthorizeConfig;\n};\n\n/** OpenAPI response header object */\nexport type TResponseHeaderObject = {\n description?: string;\n schema: { type: 'string'; examples?: string[] };\n};\n\n/** OpenAPI response headers format */\nexport type TResponseHeaders = Record<string, TResponseHeaderObject>;\n\n// Response body types derived from route definitions; a distributive conditional applies z.infer to each schema of the union separately.\ntype TInferDistributive<S> = S extends z.ZodType ? z.infer<S> : never;\n/** The JSON response body type of a route config `R`: the union of the schemas under `application/json` across all its response codes. */\nexport type TResponseBodyOf<R extends { responses: AnyType }> = TInferDistributive<\n R['responses'][keyof R['responses']]['content']['application/json']['schema']\n>;\n\n/** What a CRUD route lets a caller override: auth, the request schemas (params, query, body, headers) and the response schema and headers. */\nexport type TCustomizableRouteConfig = TRouteAuthConfig & {\n request?: {\n params?: TAnyObjectSchema;\n query?: TAnyObjectSchema;\n body?: TAnyObjectSchema;\n headers?: TAnyObjectSchema;\n };\n response?: {\n schema?: z.ZodType;\n headers?: TResponseHeaders;\n };\n};\n\n/** Per-route configuration for CRUD controller endpoints (auth, request, response). */\nexport interface ICustomizableRoutes<\n RouteConfig extends TCustomizableRouteConfig = TCustomizableRouteConfig,\n> {\n count?: RouteConfig;\n find?: RouteConfig;\n findById?: RouteConfig;\n findOne?: RouteConfig;\n create?: RouteConfig;\n updateById?: RouteConfig;\n updateBy?: RouteConfig;\n deleteById?: RouteConfig;\n deleteBy?: RouteConfig;\n restoreById?: RouteConfig;\n restoreBy?: RouteConfig;\n}\n\n/**\n * The routes of a CRUD controller: only a listed route exists, as `true` (on, with its defaults) or a config\n * (on, with overrides). `restoreById` and `restoreBy` are listed only for a repository that has both methods.\n */\nexport type TCrudRoutes<Repository extends object = AnyType> = {\n [Key in keyof ICustomizableRoutes]?: Key extends 'restoreById' | 'restoreBy'\n ? Repository extends { restoreById: unknown; restoreBy: unknown }\n ? true | TCustomizableRouteConfig\n : never\n : true | TCustomizableRouteConfig;\n};\n"]}
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/common/types/route.ts"],"names":[],"mappings":"","sourcesContent":["import type { TAuthMode, TAuthStrategy } from '@/base/auth/authenticate/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport type {\n createRoute,\n RouteConfig as HonoRouteConfig,\n OpenAPIHono,\n z,\n} from '@hono/zod-openapi';\nimport type { Env, Schema } from 'hono';\nimport type { TRouteHandler } from './context';\n\n/** Registered route with its configuration and router instance. */\nexport interface IDefineRouteOptions<\n RouteConfig extends HonoRouteConfig,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n> {\n configs: ReturnType<typeof createRoute<string, RouteConfig>>;\n route: OpenAPIHono<RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Fluent binding for two-step route registration: bindRoute({ configs }).to({ handler }). */\nexport interface IBindRouteOptions<\n RouteConfig extends HonoRouteConfig,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n> {\n configs: RouteConfig;\n to: <ResponseType = unknown>(opts: {\n handler: TRouteHandler<ResponseType, RouteEnv>;\n }) => IDefineRouteOptions<RouteConfig, RouteEnv, RouteSchema, BasePath>;\n}\n\n/** Route configuration extended with optional authenticate and authorize fields. */\nexport interface IAuthRouteConfig extends HonoRouteConfig {\n authenticate?: { strategies?: TAuthStrategy[]; mode?: TAuthMode };\n authorize?: IAuthorizationSpec | IAuthorizationSpec[];\n}\n\n/** Per-route authentication config: { skip: true } or { strategies, mode }. */\nexport type TRouteAuthenticateConfig =\n | { skip: true }\n | { skip?: false; strategies?: TAuthStrategy[]; mode?: TAuthMode };\n\n/** Per-route authorization config: { skip: true }, single spec, or array of specs. */\nexport type TRouteAuthorizeConfig = { skip: true } | IAuthorizationSpec | IAuthorizationSpec[];\n\n/** Per-route auth config. Endpoint config takes precedence over controller-level config. */\nexport type TRouteAuthConfig = {\n authenticate?: TRouteAuthenticateConfig;\n authorize?: TRouteAuthorizeConfig;\n};\n\n/** OpenAPI response header object */\nexport type TResponseHeaderObject = {\n description?: string;\n schema: { type: 'string'; examples?: string[] };\n};\n\n/** OpenAPI response headers format */\nexport type TResponseHeaders = Record<string, TResponseHeaderObject>;\n\n// Response body types derived from route definitions; a distributive conditional applies z.infer to each schema of the union separately.\ntype TInferDistributive<S> = S extends z.ZodType ? z.infer<S> : never;\ntype TJsonSchemaOf<Response> = Response extends {\n content: { 'application/json': { schema: infer JsonSchema } };\n}\n ? JsonSchema\n : never;\n/** The JSON response body type of a route config `R`: the union of the schemas under `application/json` across all its response codes. */\nexport type TResponseBodyOf<R extends { responses: object }> = TInferDistributive<\n TJsonSchemaOf<R['responses'][keyof R['responses']]>\n>;\n\n/** What a CRUD route lets a caller override: auth, the request schemas (params, query, body, headers) and the response schema and headers. */\nexport type TCustomizableRouteConfig = TRouteAuthConfig & {\n request?: {\n params?: TAnyObjectSchema;\n query?: TAnyObjectSchema;\n body?: TAnyObjectSchema;\n headers?: TAnyObjectSchema;\n };\n response?: {\n schema?: z.ZodType;\n headers?: TResponseHeaders;\n };\n};\n\n/** Per-route configuration for CRUD controller endpoints (auth, request, response). */\nexport interface ICustomizableRoutes<\n RouteConfig extends TCustomizableRouteConfig = TCustomizableRouteConfig,\n> {\n count?: RouteConfig;\n find?: RouteConfig;\n findById?: RouteConfig;\n findOne?: RouteConfig;\n create?: RouteConfig;\n updateById?: RouteConfig;\n updateBy?: RouteConfig;\n deleteById?: RouteConfig;\n deleteBy?: RouteConfig;\n restoreById?: RouteConfig;\n restoreBy?: RouteConfig;\n}\n\n/**\n * The routes of a CRUD controller: only a listed route exists, as `true` (on, with its defaults) or a config\n * (on, with overrides). `restoreById` and `restoreBy` are listed only for a repository that has both methods.\n */\nexport type TCrudRoutes<Repository extends object = { restoreById: unknown; restoreBy: unknown }> =\n {\n [Key in keyof ICustomizableRoutes]?: Key extends 'restoreById' | 'restoreBy'\n ? Repository extends { restoreById: unknown; restoreBy: unknown }\n ? true | TCustomizableRouteConfig\n : never\n : true | TCustomizableRouteConfig;\n };\n"]}
@@ -1,4 +1,3 @@
1
- import type { AnyType } from '@venizia/ignis-helpers/common';
2
1
  import type { AbstractRepository } from '../../repositories/index.js';
3
2
  import type { IAuthorizationSpec } from '../../auth/authorize/common/types/index.js';
4
3
  import type { TClass, ValueOrPromise } from '@venizia/ignis-helpers/common';
@@ -22,7 +21,7 @@ export declare class CrudControllerFactory extends BaseHelper {
22
21
  repositoryName: string;
23
22
  }): void;
24
23
  static build<Repository extends TCrudRepositoryClass, RouteEnv extends Env = Env, RouteSchema extends Schema = {}, BasePath extends string = '/', ConfigurableOptions extends object = {}, TDataObject extends object = TRepositoryDataObject<InstanceType<Repository>>, TPersistObject extends object = TRepositoryPersistObject<InstanceType<Repository>>>(opts: ICrudControllerOptions<Repository>): {
25
- new (repositoryInstance: AbstractRepository<TDataObject, TPersistObject, AnyType>): {
24
+ new (repositoryInstance: AbstractRepository<TDataObject, TPersistObject>): {
26
25
  /** The routes of a generated controller come from `routes`; a subclass adds its own here. */
27
26
  binding(): ValueOrPromise<void>;
28
27
  /** Registers each listed CRUD route, after `binding()`: a custom static path is never taken by `/{id}`. */
@@ -96,8 +95,8 @@ export declare class CrudControllerFactory extends BaseHelper {
96
95
  scope: string;
97
96
  args: unknown;
98
97
  task: () => Promise<R>;
99
- }): Promise<any>;
100
- normalizeCountData<ResponseSchema extends unknown, RequestContext extends import("../index.js").TRouteContext<RouteEnv> = import("../index.js").TRouteContext<RouteEnv>, ResponseData extends {
98
+ }): Promise<R>;
99
+ normalizeCountData<ResponseSchema, RequestContext extends import("../index.js").TRouteContext<RouteEnv> = import("../index.js").TRouteContext<RouteEnv>, ResponseData extends {
101
100
  count: number;
102
101
  data?: import("@venizia/ignis-helpers/common").TNullable<ResponseSchema>;
103
102
  } = {
@@ -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
  },
@@ -79,7 +82,6 @@ export class CrudControllerFactory extends BaseHelper {
79
82
  serverStampedKeys: [...(settings?.properties?.stamped ?? AuditFields.SCHEME_SET)],
80
83
  });
81
84
  const controllerClass = class extends PersistableCrudController {
82
- // Any extra options: a repository whose options narrow `IExtraOptions` (a typed transaction) must fit.
83
85
  constructor(repositoryInstance) {
84
86
  super({
85
87
  scope: new.target.name,
@@ -1 +1 @@
1
- {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../src/base/controllers/factory/controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAG9E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,g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,IAAI,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 { AnyType } from '@venizia/ignis-helpers/common';\nimport 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 // Any extra options: a repository whose options narrow `IExtraOptions` (a typed transaction) must fit.\n constructor(repositoryInstance: AbstractRepository<TDataObject, TPersistObject, AnyType>) {\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,MAAM,gCAAgC,CAAC;AAE1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AASnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,6EAA6E;AAC7E,MAAM,OAAO,qBAAsB,SAAQ,UAAU;IACnD,0GAA0G;aAClF,gBAAW,GAAG;QACpC,QAAQ;QACR,YAAY;QACZ,UAAU;QACV,YAAY;QACZ,UAAU;QACV,aAAa;QACb,WAAW;KACH,CAAC;IAEX;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,2BAA2B,CAAC,IAIlC;QACC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;QAErD,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,IAAI,WAAW,8EAA8E;aACvG,CAAC,CAAC;QACL,CAAC;QAED,gBAAgB,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAC;YAC/C,MAAM;YACN,KAAK,EAAE,CAAC;YACR,QAAQ,EAAE;gBACR,GAAG,EAAE,WAAW,CAAC,K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AAI,CAAC,CAAC;QAEvF,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,qBAAqB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YAClE,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,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"]}
@@ -1,9 +1,8 @@
1
1
  import type { AbstractEntity } from '../../../models/base.js';
2
2
  import type { AbstractRepository } from '../../../repositories/index.js';
3
3
  import type { TAnyObjectSchema } from '../../common/schema-builders.js';
4
- import type { AnyType } from '@venizia/ignis-helpers/common';
5
4
  import type { Env, Schema } from 'hono';
6
- import type { TEntityDataObject, TEntityPersistObject, TRouteContext } from '../../common/index.js';
5
+ import type { IAuthRouteConfig, TEntityDataObject, TEntityPersistObject, TRouteContext } from '../../common/index.js';
7
6
  import { BaseRestController } from '../../rest/base.js';
8
7
  type TBulkWhereResolution<WhereType> = {
9
8
  where: WhereType;
@@ -18,8 +17,8 @@ export declare abstract class AbstractCrudController<TEntity extends AbstractEnt
18
17
  constructor(opts: {
19
18
  scope: string;
20
19
  isStrict?: boolean;
21
- repository: AbstractRepository<TDataObject, TPersistObject, AnyType>;
22
- definitions: AnyType;
20
+ repository: AbstractRepository<TDataObject, TPersistObject>;
21
+ definitions: Record<string, IAuthRouteConfig>;
23
22
  });
24
23
  /**
25
24
  * Refuses (400) a filter the client sent when it names a field the model hides (`where`, `order`, an include scope).
@@ -1 +1 @@
1
- {"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/factory/crud/abstract.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAMrD,yRAAyR;AACzR,MAAM,OAAgB,sBAQpB,SAAQ,kBAAwE;IAGhF,YAAY,IAKX;QACC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAA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K,EAAE,OAAO,CAAC,IAAI,CACjB,EAAE,OAAO,EAAE,8CAA8C,EAAE,EAC3D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CACjC;aACF,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;CACF","sourcesContent":["import type { AbstractEntity } from '@/base/models/base';\nimport type { AbstractRepository } from '@/base/repositories';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type { TEntityDataObject, TEntityPersistObject, TRouteContext } from '../../common';\nimport { BaseRestController } from '../../rest/base';\n\ntype TBulkWhereResolution<WhereType> =\n | { where: WhereType; error?: undefined }\n | { where?: undefined; error: Response };\n\n/** Base tier of a generated CRUD controller - the repository handle; the response helpers (`respond`, `setListHeaders`) live on BaseRestController so hand-written controllers share them. Read and write verbs are layered on by ReadableCrudController / PersistableCrudController. */\nexport abstract class AbstractCrudController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n TPersistObject extends object = TEntityPersistObject<TEntity>,\n> extends BaseRestController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions> {\n repository: AbstractRepository<TDataObject, TPersistObject>;\n\n constructor(opts: {\n scope: string;\n isStrict?: boolean;\n repository: AbstractRepository<TDataObject, TPersistObject, AnyType>;\n definitions: AnyType;\n }) {\n super({ scope: opts.scope, isStrict: opts.isStrict });\n this.repository = opts.repository;\n this.definitions = opts.definitions;\n }\n\n /**\n * Refuses (400) a filter the client sent when it names a field the model hides (`where`, `order`, an include scope).\n * The repository answers it; a stand-in that does not extend `AbstractRepository` has no hidden fields to hold the filter to.\n */\n assertRequestFilter(opts: {\n filter?: { where?: unknown; order?: unknown; include?: unknown };\n }): void {\n (\n this.repository as Partial<Pick<AbstractRepository<object>, 'assertRequestFilter'>>\n ).assertRequestFilter?.(opts);\n }\n\n /** 400 when a bulk operation is missing its `where` filter; undefined when it is present. */\n bulkWhereError(opts: { context: TRouteContext<RouteEnv>; where?: object }) {\n const { context, where } = opts;\n\n if (!where || Object.keys(where).length === 0) {\n return context.json(\n { message: 'where filter is required for bulk operations' },\n HTTP.ResultCodes.RS_4.BadRequest,\n );\n }\n\n return undefined;\n }\n\n /** Bulk `where` from the query or the JSON body (long id lists outgrow a URL). Both, or none, is a 400. */\n resolveBulkWhere<WhereType extends object>(opts: {\n context: TRouteContext<RouteEnv>;\n where?: {\n fromQuery?: WhereType;\n fromBody?: WhereType;\n };\n }): TBulkWhereResolution<WhereType> {\n const { context, where: whereSources } = opts;\n const { fromQuery, fromBody } = whereSources ?? {};\n\n if (fromQuery !== undefined && fromBody !== undefined) {\n return {\n error: context.json(\n { message: 'where given in both the query and the body - send it in one' },\n HTTP.ResultCodes.RS_4.BadRequest,\n ),\n };\n }\n\n const where = fromQuery ?? fromBody;\n\n if (!where || Object.keys(where).length === 0) {\n return {\n error: context.json(\n { message: 'where filter is required for bulk operations' },\n HTTP.ResultCodes.RS_4.BadRequest,\n ),\n };\n }\n\n return { where };\n }\n}\n"]}
1
+ {"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../../../../src/base/controllers/factory/crud/abstract.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAQrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAMrD,yRAAyR;AACzR,MAAM,OAAgB,sBAQpB,SAAQ,kBAAwE;IAGhF,YAAY,IAKX;QACC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtD,IAA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I,CACjB,EAAE,OAAO,EAAE,8CAA8C,EAAE,EAC3D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CACjC;aACF,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;CACF","sourcesContent":["import type { AbstractEntity } from '@/base/models/base';\nimport type { AbstractRepository } from '@/base/repositories';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport type { Env, Schema } from 'hono';\nimport type {\n IAuthRouteConfig,\n TEntityDataObject,\n TEntityPersistObject,\n TRouteContext,\n} from '../../common';\nimport { BaseRestController } from '../../rest/base';\n\ntype TBulkWhereResolution<WhereType> =\n | { where: WhereType; error?: undefined }\n | { where?: undefined; error: Response };\n\n/** Base tier of a generated CRUD controller - the repository handle; the response helpers (`respond`, `setListHeaders`) live on BaseRestController so hand-written controllers share them. Read and write verbs are layered on by ReadableCrudController / PersistableCrudController. */\nexport abstract class AbstractCrudController<\n TEntity extends AbstractEntity<TAnyObjectSchema> = AbstractEntity<TAnyObjectSchema>,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TEntityDataObject<TEntity>,\n TPersistObject extends object = TEntityPersistObject<TEntity>,\n> extends BaseRestController<RouteEnv, RouteSchema, BasePath, ConfigurableOptions> {\n repository: AbstractRepository<TDataObject, TPersistObject>;\n\n constructor(opts: {\n scope: string;\n isStrict?: boolean;\n repository: AbstractRepository<TDataObject, TPersistObject>;\n definitions: Record<string, IAuthRouteConfig>;\n }) {\n super({ scope: opts.scope, isStrict: opts.isStrict });\n this.repository = opts.repository;\n this.definitions = opts.definitions;\n }\n\n /**\n * Refuses (400) a filter the client sent when it names a field the model hides (`where`, `order`, an include scope).\n * The repository answers it; a stand-in that does not extend `AbstractRepository` has no hidden fields to hold the filter to.\n */\n assertRequestFilter(opts: {\n filter?: { where?: unknown; order?: unknown; include?: unknown };\n }): void {\n (\n this.repository as Partial<Pick<AbstractRepository<object>, 'assertRequestFilter'>>\n ).assertRequestFilter?.(opts);\n }\n\n /** 400 when a bulk operation is missing its `where` filter; undefined when it is present. */\n bulkWhereError(opts: { context: TRouteContext<RouteEnv>; where?: object }) {\n const { context, where } = opts;\n\n if (!where || Object.keys(where).length === 0) {\n return context.json(\n { message: 'where filter is required for bulk operations' },\n HTTP.ResultCodes.RS_4.BadRequest,\n );\n }\n\n return undefined;\n }\n\n /** Bulk `where` from the query or the JSON body (long id lists outgrow a URL). Both, or none, is a 400. */\n resolveBulkWhere<WhereType extends object>(opts: {\n context: TRouteContext<RouteEnv>;\n where?: {\n fromQuery?: WhereType;\n fromBody?: WhereType;\n };\n }): TBulkWhereResolution<WhereType> {\n const { context, where: whereSources } = opts;\n const { fromQuery, fromBody } = whereSources ?? {};\n\n if (fromQuery !== undefined && fromBody !== undefined) {\n return {\n error: context.json(\n { message: 'where given in both the query and the body - send it in one' },\n HTTP.ResultCodes.RS_4.BadRequest,\n ),\n };\n }\n\n const where = fromQuery ?? fromBody;\n\n if (!where || Object.keys(where).length === 0) {\n return {\n error: context.json(\n { message: 'where filter is required for bulk operations' },\n HTTP.ResultCodes.RS_4.BadRequest,\n ),\n };\n }\n\n return { where };\n }\n}\n"]}