@decaf-ts/for-nest 0.0.6 → 0.0.8

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 (73) hide show
  1. package/dist/for-nest.cjs +1 -1
  2. package/dist/for-nest.cjs.map +1 -1
  3. package/dist/for-nest.js +1 -1
  4. package/dist/for-nest.js.map +1 -1
  5. package/lib/decaf-model/DecafModelModule.cjs +36 -0
  6. package/lib/decaf-model/DecafModelModule.d.ts +5 -0
  7. package/lib/decaf-model/DecafModelModule.js.map +1 -0
  8. package/lib/{model-module.cjs → decaf-model/FromModelController.cjs} +57 -52
  9. package/lib/decaf-model/FromModelController.d.ts +15 -0
  10. package/lib/decaf-model/FromModelController.js.map +1 -0
  11. package/lib/decaf-model/decorators/ApiOperationFromModel.cjs +44 -0
  12. package/lib/decaf-model/decorators/ApiOperationFromModel.d.ts +21 -0
  13. package/lib/decaf-model/decorators/ApiOperationFromModel.js.map +1 -0
  14. package/lib/decaf-model/decorators/ApiParamsFromModel.cjs +27 -0
  15. package/lib/decaf-model/decorators/ApiParamsFromModel.d.ts +13 -0
  16. package/lib/decaf-model/decorators/ApiParamsFromModel.js.map +1 -0
  17. package/lib/decaf-model/decorators/DecafParams.cjs +34 -0
  18. package/lib/decaf-model/decorators/DecafParams.d.ts +8 -0
  19. package/lib/decaf-model/decorators/DecafParams.js.map +1 -0
  20. package/lib/decaf-model/decorators/index.cjs +21 -0
  21. package/lib/decaf-model/decorators/index.d.ts +4 -0
  22. package/lib/decaf-model/decorators/index.js.map +1 -0
  23. package/lib/decaf-model/decorators/types.cjs +3 -0
  24. package/lib/decaf-model/decorators/types.d.ts +12 -0
  25. package/lib/decaf-model/decorators/types.js.map +1 -0
  26. package/lib/decaf-model/index.cjs +20 -0
  27. package/lib/decaf-model/index.d.ts +3 -0
  28. package/lib/decaf-model/index.js.map +1 -0
  29. package/lib/esm/decaf-model/DecafModelModule.d.ts +5 -0
  30. package/lib/esm/decaf-model/DecafModelModule.js +33 -0
  31. package/lib/esm/decaf-model/DecafModelModule.js.map +1 -0
  32. package/lib/esm/decaf-model/FromModelController.d.ts +15 -0
  33. package/lib/esm/{model-module.js → decaf-model/FromModelController.js} +57 -53
  34. package/lib/esm/decaf-model/FromModelController.js.map +1 -0
  35. package/lib/esm/decaf-model/decorators/ApiOperationFromModel.d.ts +21 -0
  36. package/lib/esm/decaf-model/decorators/ApiOperationFromModel.js +40 -0
  37. package/lib/esm/decaf-model/decorators/ApiOperationFromModel.js.map +1 -0
  38. package/lib/esm/decaf-model/decorators/ApiParamsFromModel.d.ts +13 -0
  39. package/lib/esm/decaf-model/decorators/ApiParamsFromModel.js +24 -0
  40. package/lib/esm/decaf-model/decorators/ApiParamsFromModel.js.map +1 -0
  41. package/lib/esm/decaf-model/decorators/DecafParams.d.ts +8 -0
  42. package/lib/esm/decaf-model/decorators/DecafParams.js +31 -0
  43. package/lib/esm/decaf-model/decorators/DecafParams.js.map +1 -0
  44. package/lib/esm/decaf-model/decorators/index.d.ts +4 -0
  45. package/lib/esm/decaf-model/decorators/index.js +5 -0
  46. package/lib/esm/decaf-model/decorators/index.js.map +1 -0
  47. package/lib/esm/decaf-model/decorators/types.d.ts +12 -0
  48. package/lib/esm/decaf-model/decorators/types.js +2 -0
  49. package/lib/esm/decaf-model/decorators/types.js.map +1 -0
  50. package/lib/esm/decaf-model/index.d.ts +3 -0
  51. package/lib/esm/decaf-model/index.js +4 -0
  52. package/lib/esm/decaf-model/index.js.map +1 -0
  53. package/lib/esm/index.d.ts +2 -2
  54. package/lib/esm/index.js +2 -2
  55. package/lib/esm/index.js.map +1 -1
  56. package/lib/esm/module.js +1 -1
  57. package/lib/esm/module.js.map +1 -1
  58. package/lib/index.cjs +2 -2
  59. package/lib/index.d.ts +2 -2
  60. package/lib/index.js.map +1 -1
  61. package/lib/module.cjs +2 -2
  62. package/lib/module.js.map +1 -1
  63. package/package.json +1 -1
  64. package/lib/decorators.cjs +0 -32
  65. package/lib/decorators.d.ts +0 -8
  66. package/lib/decorators.js.map +0 -1
  67. package/lib/esm/decorators.d.ts +0 -8
  68. package/lib/esm/decorators.js +0 -29
  69. package/lib/esm/decorators.js.map +0 -1
  70. package/lib/esm/model-module.d.ts +0 -8
  71. package/lib/esm/model-module.js.map +0 -1
  72. package/lib/model-module.d.ts +0 -8
  73. package/lib/model-module.js.map +0 -1
@@ -11,28 +11,25 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var DecafModelModule_1;
15
14
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.DecafModelModule = void 0;
15
+ exports.FromModelController = void 0;
17
16
  const common_1 = require("@nestjs/common");
18
17
  const swagger_1 = require("@nestjs/swagger");
19
18
  const core_1 = require("@decaf-ts/core");
20
19
  const decorator_validation_1 = require("@decaf-ts/decorator-validation");
21
20
  const logging_1 = require("@decaf-ts/logging");
22
- const RepoFactory_1 = require("./RepoFactory.cjs");
23
- const decorators_1 = require("./decorators.cjs");
24
- let DecafModelModule = class DecafModelModule {
25
- static { DecafModelModule_1 = this; }
26
- static get log() {
27
- if (!this._logger)
28
- this._logger = logging_1.Logging.for(DecafModelModule_1);
29
- return this._logger;
30
- }
31
- static toModelController(ModelClazz) {
32
- const log = this.log.for(this.toModelController);
21
+ const db_decorators_1 = require("@decaf-ts/db-decorators");
22
+ const decoration_1 = require("@decaf-ts/decoration");
23
+ const decorators_1 = require("./decorators/index.cjs");
24
+ const RepoFactory_1 = require("./../RepoFactory.cjs");
25
+ class FromModelController {
26
+ static { this.log = logging_1.Logging.for(FromModelController.name); }
27
+ static create(ModelClazz) {
28
+ const log = FromModelController.log.for(FromModelController.create);
33
29
  const tableName = core_1.Repository.table(ModelClazz);
34
30
  const routePath = (0, logging_1.toKebabCase)(tableName);
35
31
  const modelClazzName = ModelClazz.name;
32
+ const { description, apiProperties, path } = FromModelController.getRouteParametersFromModel(ModelClazz);
36
33
  log.debug(`Creating controller for model: ${modelClazzName}`);
37
34
  let DynamicModelController = class DynamicModelController extends logging_1.LoggedClass {
38
35
  constructor(repoFactory) {
@@ -61,7 +58,8 @@ let DecafModelModule = class DecafModelModule {
61
58
  log.info(`created new ${modelClazzName} with id ${created[this.pk]}`);
62
59
  return created;
63
60
  }
64
- async read(id) {
61
+ async read(pathParams) {
62
+ const { id } = pathParams;
65
63
  const log = this.log.for(this.read);
66
64
  let read;
67
65
  try {
@@ -89,12 +87,12 @@ let DecafModelModule = class DecafModelModule {
89
87
  log.info(`Successfully queried ${modelClazzName} using method "${method}"`);
90
88
  return results;
91
89
  }
92
- async update(data) {
90
+ async update(routeParams, body) {
93
91
  const log = this.log.for(this.update);
94
92
  let updated;
95
93
  try {
96
- log.info(`updating ${modelClazzName} with ${this.pk} ${data[this.pk]}`);
97
- updated = await this.repo.create(data);
94
+ log.info(`updating ${modelClazzName} with ${this.pk} ${body[this.pk]}`);
95
+ updated = await this.repo.create(body);
98
96
  }
99
97
  catch (e) {
100
98
  log.error(e);
@@ -102,15 +100,15 @@ let DecafModelModule = class DecafModelModule {
102
100
  }
103
101
  return updated;
104
102
  }
105
- async delete(id) {
103
+ async delete(routeParams) {
106
104
  const log = this.log.for(this.delete);
107
105
  let read;
108
106
  try {
109
- log.debug(`deleting ${modelClazzName} with ${this.pk} ${id}`);
110
- read = await this.repo.read(id);
107
+ log.debug(`deleting ${modelClazzName} with ${this.pk} ${routeParams}`);
108
+ read = await this.repo.read("id");
111
109
  }
112
110
  catch (e) {
113
- log.error(`Failed to delete ${modelClazzName} with id ${id}`, e);
111
+ log.error(`Failed to delete ${modelClazzName} with id ${"id"}`, e);
114
112
  throw e;
115
113
  }
116
114
  log.info(`deleted ${modelClazzName} with id ${read[this.pk]}`);
@@ -137,18 +135,18 @@ let DecafModelModule = class DecafModelModule {
137
135
  __metadata("design:returntype", Promise)
138
136
  ], DynamicModelController.prototype, "create", null);
139
137
  __decorate([
140
- (0, decorators_1.ApiOperationFromModel)(ModelClazz, "GET", ":id"),
138
+ (0, decorators_1.ApiOperationFromModel)(ModelClazz, "GET", path),
139
+ (0, decorators_1.ApiParamsFromModel)(apiProperties),
141
140
  (0, swagger_1.ApiOperation)({ summary: `Retrieve a ${modelClazzName} record by id.` }),
142
- (0, swagger_1.ApiParam)({ name: "id", description: "Primary key" }),
143
141
  (0, swagger_1.ApiOkResponse)({
144
142
  description: `${modelClazzName} retrieved successfully.`,
145
143
  }),
146
144
  (0, swagger_1.ApiNotFoundResponse)({
147
145
  description: `No ${modelClazzName} record matches the provided identifier.`,
148
146
  }),
149
- __param(0, (0, common_1.Param)("id")),
147
+ __param(0, (0, common_1.Param)()),
150
148
  __metadata("design:type", Function),
151
- __metadata("design:paramtypes", [String]),
149
+ __metadata("design:paramtypes", [Object]),
152
150
  __metadata("design:returntype", Promise)
153
151
  ], DynamicModelController.prototype, "read", null);
154
152
  __decorate([
@@ -167,7 +165,8 @@ let DecafModelModule = class DecafModelModule {
167
165
  __metadata("design:returntype", Promise)
168
166
  ], DynamicModelController.prototype, "query", null);
169
167
  __decorate([
170
- (0, decorators_1.ApiOperationFromModel)(ModelClazz, "PUT", ":id"),
168
+ (0, decorators_1.ApiOperationFromModel)(ModelClazz, "PUT", path),
169
+ (0, decorators_1.ApiParamsFromModel)(apiProperties),
171
170
  (0, swagger_1.ApiOperation)({
172
171
  summary: `Replace an existing ${modelClazzName} record with a new payload.`,
173
172
  }),
@@ -182,27 +181,25 @@ let DecafModelModule = class DecafModelModule {
182
181
  description: `No ${modelClazzName} record matches the provided identifier.`,
183
182
  }),
184
183
  (0, swagger_1.ApiBadRequestResponse)({ description: "Payload validation failed." }),
185
- __param(0, (0, common_1.Body)()),
184
+ __param(0, (0, decorators_1.DecafParams)(apiProperties)),
185
+ __param(1, (0, common_1.Body)()),
186
186
  __metadata("design:type", Function),
187
- __metadata("design:paramtypes", [decorator_validation_1.Model]),
187
+ __metadata("design:paramtypes", [Object, decorator_validation_1.Model]),
188
188
  __metadata("design:returntype", Promise)
189
189
  ], DynamicModelController.prototype, "update", null);
190
190
  __decorate([
191
- (0, decorators_1.ApiOperationFromModel)(ModelClazz, "DELETE", ":id"),
191
+ (0, decorators_1.ApiOperationFromModel)(ModelClazz, "DELETE", path),
192
+ (0, decorators_1.ApiParamsFromModel)(apiProperties),
192
193
  (0, swagger_1.ApiOperation)({ summary: `Delete a ${modelClazzName} record by id.` }),
193
- (0, swagger_1.ApiParam)({
194
- name: "id",
195
- description: `Primary key value of the ${modelClazzName} record to delete.`,
196
- }),
197
194
  (0, swagger_1.ApiOkResponse)({
198
195
  description: `${modelClazzName} record deleted successfully.`,
199
196
  }),
200
197
  (0, swagger_1.ApiNotFoundResponse)({
201
198
  description: `No ${modelClazzName} record matches the provided identifier.`,
202
199
  }),
203
- __param(0, (0, common_1.Param)("id")),
200
+ __param(0, (0, decorators_1.DecafParams)(apiProperties)),
204
201
  __metadata("design:type", Function),
205
- __metadata("design:paramtypes", [String]),
202
+ __metadata("design:paramtypes", [Object]),
206
203
  __metadata("design:returntype", Promise)
207
204
  ], DynamicModelController.prototype, "delete", null);
208
205
  DynamicModelController = __decorate([
@@ -213,21 +210,29 @@ let DecafModelModule = class DecafModelModule {
213
210
  ], DynamicModelController);
214
211
  return DynamicModelController;
215
212
  }
216
- static forRoot(flavour) {
217
- const log = this.log.for(this.forRoot);
218
- log.info(`Generating controllers for flavour...`);
219
- const trackedModels = core_1.Adapter.models(flavour);
220
- const controllers = trackedModels.map(this.toModelController.bind(this));
221
- log.info(`Generated ${controllers.length} controllers`);
222
- return {
223
- module: DecafModelModule_1,
224
- controllers,
225
- providers: [RepoFactory_1.RepoFactory],
226
- };
213
+ static getRouteParametersFromModel(ModelClazz) {
214
+ const instance = new ModelClazz({});
215
+ const pk = ((0, db_decorators_1.findPrimaryKey)(instance)?.id || "id");
216
+ const composedKeyMetaKey = core_1.Repository.key(db_decorators_1.DBKeys.COMPOSED);
217
+ const composedKeys = Reflect.getMetadata(composedKeyMetaKey, instance, pk)?.args ??
218
+ [];
219
+ const keysToReturn = Array.isArray(composedKeys) && composedKeys.length > 0
220
+ ? [...composedKeys]
221
+ : [pk];
222
+ const description = decoration_1.Metadata.description(ModelClazz);
223
+ // remove duplicates while preserving order
224
+ const uniqueKeys = Array.from(new Set(keysToReturn));
225
+ const path = uniqueKeys.map((key) => `:${key}`).join("/");
226
+ const apiProperties = uniqueKeys.map((key) => {
227
+ return {
228
+ name: key,
229
+ description: decoration_1.Metadata.description(ModelClazz, key),
230
+ required: true,
231
+ type: String,
232
+ };
233
+ });
234
+ return { description, apiProperties, path };
227
235
  }
228
- };
229
- exports.DecafModelModule = DecafModelModule;
230
- exports.DecafModelModule = DecafModelModule = DecafModelModule_1 = __decorate([
231
- (0, common_1.Module)({})
232
- ], DecafModelModule);
233
- //# sourceMappingURL=model-module.js.map
236
+ }
237
+ exports.FromModelController = FromModelController;
238
+ //# sourceMappingURL=FromModelController.js.map
@@ -0,0 +1,15 @@
1
+ import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
2
+ export declare class FromModelController {
3
+ private static readonly log;
4
+ static create<T extends Model<any>>(ModelClazz: ModelConstructor<T>): any;
5
+ static getRouteParametersFromModel<T extends Model<any>>(ModelClazz: ModelConstructor<T>): {
6
+ description: string | undefined;
7
+ apiProperties: {
8
+ name: any;
9
+ description: string | undefined;
10
+ required: boolean;
11
+ type: StringConstructor;
12
+ }[];
13
+ path: string;
14
+ };
15
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FromModelController.js","sourceRoot":"","sources":["../../src/decaf-model/FromModelController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyD;AACzD,6CAYyB;AACzB,yCAAkD;AAClD,yEAAyE;AACzE,+CAAsE;AACtE,2DAAiE;AACjE,qDAAgD;AAChD,uDAKsB;AACtB,sDAA6C;AAE7C,MAAa,mBAAmB;aACN,QAAG,GAAG,iBAAO,CAAC,GAAG,CAAC,mB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,GAAG,CAAC;YACpD,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;YACnB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAEX,MAAM,WAAW,GAAG,qBAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAErD,2CAA2C;QAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;QAErD,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1D,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAC3C,OAAO;gBACL,IAAI,EAAE,GAAG;gBACT,WAAW,EAAE,qBAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,GAAG,CAAC;gBAClD,QAAQ,EAAE,IAAI;gBACd,IAAI,EAAE,MAAM;aACb,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IAC9C,CAAC;;AA7NH,kDA8NC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOperationBlocked = isOperationBlocked;
4
+ exports.ApiOperationFromModel = ApiOperationFromModel;
5
+ const decoration_1 = require("@decaf-ts/decoration");
6
+ const common_1 = require("@nestjs/common");
7
+ const swagger_1 = require("@nestjs/swagger");
8
+ const reflection_1 = require("@decaf-ts/reflection");
9
+ const db_decorators_1 = require("@decaf-ts/db-decorators");
10
+ /**
11
+ * @description Determines if a given CRUD operation is blocked for a specific model constructor.
12
+ * @summary Retrieves the operation-blocking handler metadata stored on the provided model constructor (under `OperationKeys.REFLECT + OperationKeys.BLOCK`), executes it (if present) with its persisted arguments plus the requested operation, and returns whether the operation is blocked. If no handler exists, the operation is considered allowed (returns `false`).
13
+ * @param {ModelConstructor<any>} ModelConstructor - The target model constructor whose metadata may include a blocking handler.
14
+ * @param {CrudOperations} op - The CRUD operation to evaluate (e.g., `OperationKeys.CREATE`, `OperationKeys.READ`, `OperationKeys.UPDATE`, `OperationKeys.DELETE`).
15
+ * @return {boolean} `true` when the operation is explicitly blocked by the model's handler; otherwise `false`.
16
+ * @function isOperationBlocked
17
+ */
18
+ function isOperationBlocked(ModelConstructor, op) {
19
+ const { handler, args } = (decoration_1.Metadata.get(ModelConstructor, db_decorators_1.OperationKeys.REFLECT + db_decorators_1.OperationKeys.BLOCK) || {});
20
+ // @ts-ignore
21
+ return !handler ? false : (handler(...args, op) ?? false);
22
+ }
23
+ /**
24
+ * @description Conditionally applies an HTTP method decorator for a given model and verb, hiding the endpoint in Swagger (and not registering the route) when the model blocks that CRUD operation.
25
+ * @summary Maps an HTTP verb to its corresponding `CrudOperations` key and Nest HTTP decorator (`@Get`, `@Post`, etc.). It checks `isOperationBlocked(ModelConstructor, crudOp)` and, if blocked, applies only `@ApiExcludeEndpoint()` (Swagger-hidden, no Nest route). If permitted, it applies the appropriate HTTP decorator with the optional `path`.
26
+ * @param {ModelConstructor<any>} ModelConstructor - The model constructor used to resolve operation-blocking rules.
27
+ * @param {HttpVerbs} verb - The HTTP verb to map (e.g., `"GET" | "POST" | "PUT" | "PATCH" | "DELETE"`).
28
+ * @param {string} [path] - Optional route path passed through to the corresponding Nest HTTP method decorator.
29
+ * @return {MethodDecorator} A method decorator that either excludes the endpoint from Swagger (and route registration) or applies the correct HTTP decorator.
30
+ */
31
+ function ApiOperationFromModel(ModelConstructor, verb, path) {
32
+ const httpToCrud = {
33
+ GET: [db_decorators_1.OperationKeys.READ, common_1.Get],
34
+ POST: [db_decorators_1.OperationKeys.CREATE, common_1.Post],
35
+ PUT: [db_decorators_1.OperationKeys.UPDATE, common_1.Put],
36
+ PATCH: [db_decorators_1.OperationKeys.UPDATE, common_1.Patch],
37
+ DELETE: [db_decorators_1.OperationKeys.DELETE, common_1.Delete],
38
+ };
39
+ const [crudOp, HttpMethodDecorator] = httpToCrud[verb];
40
+ return isOperationBlocked(ModelConstructor, crudOp)
41
+ ? (0, reflection_1.apply)((0, swagger_1.ApiExcludeEndpoint)())
42
+ : (0, reflection_1.apply)(HttpMethodDecorator(path));
43
+ }
44
+ //# sourceMappingURL=ApiOperationFromModel.js.map
@@ -0,0 +1,21 @@
1
+ import { CrudOperations } from "@decaf-ts/db-decorators";
2
+ import { ModelConstructor } from "@decaf-ts/decorator-validation";
3
+ import { HttpVerbs } from "./types";
4
+ /**
5
+ * @description Determines if a given CRUD operation is blocked for a specific model constructor.
6
+ * @summary Retrieves the operation-blocking handler metadata stored on the provided model constructor (under `OperationKeys.REFLECT + OperationKeys.BLOCK`), executes it (if present) with its persisted arguments plus the requested operation, and returns whether the operation is blocked. If no handler exists, the operation is considered allowed (returns `false`).
7
+ * @param {ModelConstructor<any>} ModelConstructor - The target model constructor whose metadata may include a blocking handler.
8
+ * @param {CrudOperations} op - The CRUD operation to evaluate (e.g., `OperationKeys.CREATE`, `OperationKeys.READ`, `OperationKeys.UPDATE`, `OperationKeys.DELETE`).
9
+ * @return {boolean} `true` when the operation is explicitly blocked by the model's handler; otherwise `false`.
10
+ * @function isOperationBlocked
11
+ */
12
+ export declare function isOperationBlocked(ModelConstructor: ModelConstructor<any>, op: CrudOperations): boolean;
13
+ /**
14
+ * @description Conditionally applies an HTTP method decorator for a given model and verb, hiding the endpoint in Swagger (and not registering the route) when the model blocks that CRUD operation.
15
+ * @summary Maps an HTTP verb to its corresponding `CrudOperations` key and Nest HTTP decorator (`@Get`, `@Post`, etc.). It checks `isOperationBlocked(ModelConstructor, crudOp)` and, if blocked, applies only `@ApiExcludeEndpoint()` (Swagger-hidden, no Nest route). If permitted, it applies the appropriate HTTP decorator with the optional `path`.
16
+ * @param {ModelConstructor<any>} ModelConstructor - The model constructor used to resolve operation-blocking rules.
17
+ * @param {HttpVerbs} verb - The HTTP verb to map (e.g., `"GET" | "POST" | "PUT" | "PATCH" | "DELETE"`).
18
+ * @param {string} [path] - Optional route path passed through to the corresponding Nest HTTP method decorator.
19
+ * @return {MethodDecorator} A method decorator that either excludes the endpoint from Swagger (and route registration) or applies the correct HTTP decorator.
20
+ */
21
+ export declare function ApiOperationFromModel(ModelConstructor: ModelConstructor<any>, verb: HttpVerbs, path?: string): MethodDecorator;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiOperationFromModel.js","sourceRoot":"","sources":["../../../src/decaf-model/decorators/ApiOperationFromModel.ts"],"names":[],"mappings":";;AAgBA,gDAiBC;AAUD,sDAoBC;AA/DD,qDAAgD;AAChD,2CAA+D;AAC/D,6CAAqD;AACrD,qDAA6C;AAC7C,2DAAwE;AAIxE;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,gBAAuC,EACvC,EAAkB;IAElB,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,qBAAQ,CAAC,GAAG,CACrC,gBAAuB,EACvB,6BAAa,CAAC,OAAO,GAAG,6BAAa,CAAC,KAAK,CAC5C,IAAI,EAAE,CAMN,CAAC;IAEF,aAAa;IACb,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACnC,gBAAuC,EACvC,IAAe,EACf,IAAa;IAEb,MAAM,UAAU,GAGZ;QACF,GAAG,EAAE,CAAC,6BAAa,CAAC,IAAI,EAAE,YAAG,CAAC;QAC9B,IAAI,EAAE,CAAC,6BAAa,CAAC,MAAM,EAAE,aAAI,CAAC;QAClC,GAAG,EAAE,CAAC,6BAAa,CAAC,MAAM,EAAE,YAAG,CAAC;QAChC,KAAK,EAAE,CAAC,6BAAa,CAAC,MAAM,EAAE,cAAK,CAAC;QACpC,MAAM,EAAE,CAAC,6BAAa,CAAC,MAAM,EAAE,eAAM,CAAC;KACvC,CAAC;IAEF,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACvD,OAAO,kBAAkB,CAAC,gBAAgB,EAAE,MAAM,CAAC;QACjD,CAAC,CAAC,IAAA,kBAAK,EAAC,IAAA,4BAAkB,GAAE,CAAC;QAC7B,CAAC,CAAC,IAAA,kBAAK,EAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiParamsFromModel = ApiParamsFromModel;
4
+ const common_1 = require("@nestjs/common");
5
+ const swagger_1 = require("@nestjs/swagger");
6
+ /**
7
+ * @description Applies a set of Swagger `@ApiParam` decorators generated from a typed specification array.
8
+ * @summary Transforms each entry of the provided `ApiParam[]` into a corresponding `@ApiParam()` decorator (defaulting `description`, `required`, and `type` when omitted) and composes them into a single decorator via Nest's `applyDecorators`. Useful for synchronizing runtime route params with OpenAPI documentation in a concise, declarative way.
9
+ * @param {ApiParam[]} [props=[]] Array describing path parameters to be documented.
10
+ * @param {string} props[].name The parameter's name as it appears in the route template (e.g., `:id`).
11
+ * @param {string} [props[].description] Human-readable explanation of the parameter; defaults to `"Path parameter: <name>"`.
12
+ * @param {boolean} [props[].required=true] Whether the parameter is required; defaults to `true`.
13
+ * @param {new (...args:any[]) => any} [props[].type=String] Constructor/type used by Swagger to infer schema (e.g., `String`, `Number`, `UUID`, custom class).
14
+ * @return {MethodDecorator & ClassDecorator} A composed decorator applying all generated `@ApiParam` decorators to the target method or controller.
15
+ * @function ApiParamsFromModel
16
+ */
17
+ function ApiParamsFromModel(props = []) {
18
+ const decorators = props.map((p) => (0, swagger_1.ApiParam)({
19
+ name: p.name,
20
+ description: p.description ?? `Path parameter: ${p.name}`,
21
+ required: p.required ?? true,
22
+ // schema: { type: 'string' },
23
+ type: p.type ?? String,
24
+ }));
25
+ return (0, common_1.applyDecorators)(...decorators);
26
+ }
27
+ //# sourceMappingURL=ApiParamsFromModel.js.map
@@ -0,0 +1,13 @@
1
+ import { ApiParam } from "./types";
2
+ /**
3
+ * @description Applies a set of Swagger `@ApiParam` decorators generated from a typed specification array.
4
+ * @summary Transforms each entry of the provided `ApiParam[]` into a corresponding `@ApiParam()` decorator (defaulting `description`, `required`, and `type` when omitted) and composes them into a single decorator via Nest's `applyDecorators`. Useful for synchronizing runtime route params with OpenAPI documentation in a concise, declarative way.
5
+ * @param {ApiParam[]} [props=[]] Array describing path parameters to be documented.
6
+ * @param {string} props[].name The parameter's name as it appears in the route template (e.g., `:id`).
7
+ * @param {string} [props[].description] Human-readable explanation of the parameter; defaults to `"Path parameter: <name>"`.
8
+ * @param {boolean} [props[].required=true] Whether the parameter is required; defaults to `true`.
9
+ * @param {new (...args:any[]) => any} [props[].type=String] Constructor/type used by Swagger to infer schema (e.g., `String`, `Number`, `UUID`, custom class).
10
+ * @return {MethodDecorator & ClassDecorator} A composed decorator applying all generated `@ApiParam` decorators to the target method or controller.
11
+ * @function ApiParamsFromModel
12
+ */
13
+ export declare function ApiParamsFromModel(props?: ApiParam[]): MethodDecorator & ClassDecorator;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiParamsFromModel.js","sourceRoot":"","sources":["../../../src/decaf-model/decorators/ApiParamsFromModel.ts"],"names":[],"mappings":";;AAeA,gDAaC;AA5BD,2CAAiD;AACjD,6CAA0D;AAG1D;;;;;;;;;;GAUG;AACH,SAAgB,kBAAkB,CAChC,QAAoB,EAAE;IAEtB,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACjC,IAAA,kBAAW,EAAC;QACV,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,WAAW,EAAE,CAAC,CAAC,WAAW,IAAI,mBAAmB,CAAC,CAAC,IAAI,EAAE;QACzD,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,IAAI;QAC5B,8BAA8B;QAC9B,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,MAAM;KACvB,CAAC,CACH,CAAC;IACF,OAAO,IAAA,wBAAe,EAAC,GAAG,UAAU,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DecafParams = DecafParams;
4
+ const common_1 = require("@nestjs/common");
5
+ /**
6
+ * @description Creates a custom NestJS parameter decorator that extracts and returns route parameters ordered by a specific key sequence.
7
+ * @summary The `OrderedParams` decorator reads the incoming HTTP request's `params` object, optionally orders it according to a provided list of parameter names, and returns an object containing the original params, the ordered values, and the applied order list. This ensures deterministic parameter access for routes with multiple path parameters.
8
+ * @template {string[]} TOrder - Represents the expected sequence of parameter names.
9
+ * @param {TOrder | undefined} order An optional array specifying the parameter names' desired order. If not provided, the decorator will preserve the order of the keys as they appear in the original `req.params` object.
10
+ * @param {ExecutionContext} ctx The NestJS execution context, used to retrieve the current HTTP request object.
11
+ * @return {DecafParamProps} An object containing:
12
+ * - `original`: the raw parameter map from `req.params`;
13
+ * - `ordered`: an array of parameter values in the requested order;
14
+ * - `order`: the effective order list used.
15
+ * @function OrderedParams
16
+ */
17
+ const OrderedParams = (0, common_1.createParamDecorator)((order, ctx) => {
18
+ const req = ctx.switchToHttp().getRequest();
19
+ const original = (req?.params ?? {});
20
+ const orderList = order ?? Object.keys(original);
21
+ const ordered = orderList.map((k) => original[k]);
22
+ return { original, ordered, order: orderList };
23
+ });
24
+ /**
25
+ * @description A higher-level decorator factory that leverages `OrderedParams` to extract route parameters in a specific order derived from a list of `ApiParam` definitions.
26
+ * @summary `DecafParams` computes the order of route parameters based on the provided `ApiParam[]` specification (using each element’s `name`), then applies `OrderedParams(order)` as a parameter decorator. This enables parameter-level binding that remains consistent with the documented API parameter metadata.
27
+ * @param {ApiParam[]} [props=[]] Array of `ApiParam` definitions whose `name` fields determine the parameter extraction order.
28
+ * @return {ParameterDecorator} A NestJS parameter decorator that injects an ordered list of parameters and metadata into the controller method argument.
29
+ */
30
+ function DecafParams(props = []) {
31
+ const order = props.map((p) => p.name);
32
+ return OrderedParams(order);
33
+ }
34
+ //# sourceMappingURL=DecafParams.js.map
@@ -0,0 +1,8 @@
1
+ import { ApiParam } from "./types";
2
+ /**
3
+ * @description A higher-level decorator factory that leverages `OrderedParams` to extract route parameters in a specific order derived from a list of `ApiParam` definitions.
4
+ * @summary `DecafParams` computes the order of route parameters based on the provided `ApiParam[]` specification (using each element’s `name`), then applies `OrderedParams(order)` as a parameter decorator. This enables parameter-level binding that remains consistent with the documented API parameter metadata.
5
+ * @param {ApiParam[]} [props=[]] Array of `ApiParam` definitions whose `name` fields determine the parameter extraction order.
6
+ * @return {ParameterDecorator} A NestJS parameter decorator that injects an ordered list of parameters and metadata into the controller method argument.
7
+ */
8
+ export declare function DecafParams(props?: ApiParam[]): ParameterDecorator;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecafParams.js","sourceRoot":"","sources":["../../../src/decaf-model/decorators/DecafParams.ts"],"names":[],"mappings":";;AA+BA,kCAGC;AAlCD,2CAAwE;AAGxE;;;;;;;;;;;GAWG;AACH,MAAM,aAAa,GAAG,IAAA,6BAAoB,EACxC,CAAC,KAA2B,EAAE,GAAqB,EAAmB,EAAE;IACtE,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAC5C,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,MAAM,IAAI,EAAE,CAAwB,CAAC;IAC5D,MAAM,SAAS,GAAG,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACjD,CAAC,CACF,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,QAAoB,EAAE;IAChD,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types.cjs"), exports);
18
+ __exportStar(require("./ApiOperationFromModel.cjs"), exports);
19
+ __exportStar(require("./ApiParamsFromModel.cjs"), exports);
20
+ __exportStar(require("./DecafParams.cjs"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ export * from "./types";
2
+ export * from "./ApiOperationFromModel";
3
+ export * from "./ApiParamsFromModel";
4
+ export * from "./DecafParams";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decaf-model/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,8DAAwC;AACxC,2DAAqC;AACrC,oDAA8B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,12 @@
1
+ export type HttpVerbs = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
2
+ export type ApiParam = {
3
+ name: string;
4
+ description?: string;
5
+ required?: boolean;
6
+ type?: any;
7
+ };
8
+ export type DecafParamProps = {
9
+ original: Record<string, any>;
10
+ ordered: any[];
11
+ order: string[];
12
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/decaf-model/decorators/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./decorators/index.cjs"), exports);
18
+ __exportStar(require("./DecafModelModule.cjs"), exports);
19
+ __exportStar(require("./FromModelController.cjs"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ export * from "./decorators";
2
+ export * from "./DecafModelModule";
3
+ export * from "./FromModelController";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decaf-model/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAA6B;AAC7B,yDAAmC;AACnC,4DAAsC"}
@@ -0,0 +1,5 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ export declare class DecafModelModule {
3
+ private static readonly log;
4
+ static forRoot(flavour: string): DynamicModule;
5
+ }
@@ -0,0 +1,33 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var DecafModelModule_1;
8
+ import { Module } from "@nestjs/common";
9
+ import { Adapter } from "@decaf-ts/core";
10
+ import { Logging } from "@decaf-ts/logging";
11
+ import { RepoFactory } from "./../RepoFactory.js";
12
+ import { FromModelController } from "./FromModelController.js";
13
+ let DecafModelModule = class DecafModelModule {
14
+ static { DecafModelModule_1 = this; }
15
+ static { this.log = Logging.for(DecafModelModule_1.name); }
16
+ static forRoot(flavour) {
17
+ const log = this.log.for(this.forRoot);
18
+ log.info(`Generating controllers for flavour...`);
19
+ const trackedModels = Adapter.models(flavour);
20
+ const controllers = trackedModels.map(FromModelController.create);
21
+ log.info(`Generated ${controllers.length} controllers`);
22
+ return {
23
+ module: DecafModelModule_1,
24
+ controllers,
25
+ providers: [RepoFactory],
26
+ };
27
+ }
28
+ };
29
+ DecafModelModule = DecafModelModule_1 = __decorate([
30
+ Module({})
31
+ ], DecafModelModule);
32
+ export { DecafModelModule };
33
+ //# sourceMappingURL=DecafModelModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecafModelModule.js","sourceRoot":"","sources":["../../../src/decaf-model/DecafModelModule.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,4BAAuB;AAC7C,OAAO,EAAE,mBAAmB,EAAE,iCAA8B;AAGrD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;;aACH,QAAG,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAgB,CAAC,IAAI,CAAC,AAArC,CAAsC;IAEjE,MAAM,CAAC,OAAO,CAAC,OAAe;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,GAAG,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;QAElD,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,WAAW,GAAG,aAAa,CAAC,GAAG,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAElE,GAAG,CAAC,IAAI,CAAC,aAAa,WAAW,CAAC,MAAM,cAAc,CAAC,CAAC;QAExD,OAAO;YACL,MAAM,EAAE,kBAAgB;YACxB,WAAW;YACX,SAAS,EAAE,CAAC,WAAW,CAAC;SACzB,CAAC;IACJ,CAAC;;AAjBU,gBAAgB;IAD5B,MAAM,CAAC,EAAE,CAAC;GACE,gBAAgB,CAkB5B"}
@@ -0,0 +1,15 @@
1
+ import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
2
+ export declare class FromModelController {
3
+ private static readonly log;
4
+ static create<T extends Model<any>>(ModelClazz: ModelConstructor<T>): any;
5
+ static getRouteParametersFromModel<T extends Model<any>>(ModelClazz: ModelConstructor<T>): {
6
+ description: string | undefined;
7
+ apiProperties: {
8
+ name: any;
9
+ description: string | undefined;
10
+ required: boolean;
11
+ type: StringConstructor;
12
+ }[];
13
+ path: string;
14
+ };
15
+ }