@decaf-ts/for-nest 0.1.3 → 0.1.4
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.
- package/README.md +1 -1
- package/dist/for-nest.cjs +1 -1
- package/dist/for-nest.cjs.map +1 -1
- package/dist/for-nest.js +1 -1
- package/dist/for-nest.js.map +1 -1
- package/lib/constants.cjs +3 -1
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js.map +1 -1
- package/lib/decaf-model/DecafModelModule.cjs +22 -3
- package/lib/decaf-model/DecafModelModule.d.ts +3 -2
- package/lib/decaf-model/DecafModelModule.js.map +1 -1
- package/lib/decaf-model/FromModelController.cjs +69 -16
- package/lib/decaf-model/FromModelController.d.ts +49 -0
- package/lib/decaf-model/FromModelController.js.map +1 -1
- package/lib/esm/constants.d.ts +2 -0
- package/lib/esm/constants.js +2 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/decaf-model/DecafModelModule.d.ts +3 -2
- package/lib/esm/decaf-model/DecafModelModule.js +22 -3
- package/lib/esm/decaf-model/DecafModelModule.js.map +1 -1
- package/lib/esm/decaf-model/FromModelController.d.ts +49 -0
- package/lib/esm/decaf-model/FromModelController.js +69 -16
- package/lib/esm/decaf-model/FromModelController.js.map +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interceptors/DecafRequestHandlerInterceptor.d.ts +53 -0
- package/lib/esm/interceptors/DecafRequestHandlerInterceptor.js +73 -0
- package/lib/esm/interceptors/DecafRequestHandlerInterceptor.js.map +1 -0
- package/lib/esm/interceptors/index.d.ts +1 -0
- package/lib/esm/interceptors/index.js +2 -0
- package/lib/esm/interceptors/index.js.map +1 -0
- package/lib/esm/module.js +1 -1
- package/lib/esm/module.js.map +1 -1
- package/lib/esm/request/DecafHandlerExecutor.d.ts +52 -0
- package/lib/esm/request/DecafHandlerExecutor.js +77 -0
- package/lib/esm/request/DecafHandlerExecutor.js.map +1 -0
- package/lib/esm/request/DecafRequestContext.d.ts +26 -0
- package/lib/esm/request/DecafRequestContext.js +44 -0
- package/lib/esm/request/DecafRequestContext.js.map +1 -0
- package/lib/esm/request/index.d.ts +2 -0
- package/lib/esm/request/index.js +3 -0
- package/lib/esm/request/index.js.map +1 -0
- package/lib/esm/types.d.ts +9 -0
- package/lib/index.cjs +2 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js.map +1 -1
- package/lib/interceptors/DecafRequestHandlerInterceptor.cjs +76 -0
- package/lib/interceptors/DecafRequestHandlerInterceptor.d.ts +53 -0
- package/lib/interceptors/DecafRequestHandlerInterceptor.js.map +1 -0
- package/lib/interceptors/index.cjs +18 -0
- package/lib/interceptors/index.d.ts +1 -0
- package/lib/interceptors/index.js.map +1 -0
- package/lib/module.cjs +1 -1
- package/lib/module.js.map +1 -1
- package/lib/request/DecafHandlerExecutor.cjs +80 -0
- package/lib/request/DecafHandlerExecutor.d.ts +52 -0
- package/lib/request/DecafHandlerExecutor.js.map +1 -0
- package/lib/request/DecafRequestContext.cjs +47 -0
- package/lib/request/DecafRequestContext.d.ts +26 -0
- package/lib/request/DecafRequestContext.js.map +1 -0
- package/lib/request/index.cjs +19 -0
- package/lib/request/index.d.ts +2 -0
- package/lib/request/index.js.map +1 -0
- package/lib/types.d.ts +9 -0
- package/package.json +1 -1
- package/lib/RepoFactory.cjs +0 -27
- package/lib/RepoFactory.d.ts +0 -6
- package/lib/RepoFactory.js.map +0 -1
- package/lib/esm/RepoFactory.d.ts +0 -6
- package/lib/esm/RepoFactory.js +0 -24
- package/lib/esm/RepoFactory.js.map +0 -1
|
@@ -15,12 +15,63 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.FromModelController = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const swagger_1 = require("@nestjs/swagger");
|
|
18
|
+
const core_1 = require("@decaf-ts/core");
|
|
18
19
|
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
19
20
|
const logging_1 = require("@decaf-ts/logging");
|
|
20
21
|
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
21
22
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
22
23
|
const decorators_1 = require("./decorators/index.cjs");
|
|
23
|
-
const
|
|
24
|
+
const request_1 = require("./../request/index.cjs");
|
|
25
|
+
const constants_1 = require("./../constants.cjs");
|
|
26
|
+
/**
|
|
27
|
+
* @description
|
|
28
|
+
* Factory and utilities for generating dynamic NestJS controllers from Decaf {@link Model} definitions.
|
|
29
|
+
*
|
|
30
|
+
* @summary
|
|
31
|
+
* The `FromModelController` class provides the infrastructure necessary to automatically generate
|
|
32
|
+
* strongly-typed CRUD controllers based on a given {@link ModelConstructor}. It inspects metadata from
|
|
33
|
+
* the model, derives route paths, parameters, and generates a dynamic controller class at runtime with
|
|
34
|
+
* full support for querying, creation, update, and deletion of model entities through a {@link Repo}.
|
|
35
|
+
*
|
|
36
|
+
* @template T The {@link Model} type associated with the generated controller.
|
|
37
|
+
*
|
|
38
|
+
* @param ModelClazz The model class to generate the controller from.
|
|
39
|
+
*
|
|
40
|
+
* @class FromModelController
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* // Given a Decaf Model:
|
|
45
|
+
* class User extends Model<User> {
|
|
46
|
+
* id!: string;
|
|
47
|
+
* name!: string;
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* // Register controller:
|
|
51
|
+
* const UserController = FromModelController.create(User);
|
|
52
|
+
*
|
|
53
|
+
* // NestJS will expose:
|
|
54
|
+
* // POST /user
|
|
55
|
+
* // GET /user/:id
|
|
56
|
+
* // GET /user/query/:method
|
|
57
|
+
* // PUT /user/:id
|
|
58
|
+
* // DELETE /user/:id
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @mermaid
|
|
62
|
+
* sequenceDiagram
|
|
63
|
+
* participant Client
|
|
64
|
+
* participant Controller
|
|
65
|
+
* participant Repo
|
|
66
|
+
* participant DB
|
|
67
|
+
*
|
|
68
|
+
* Client->>Controller: HTTP Request
|
|
69
|
+
* Controller->>Repo: Resolve repository for Model
|
|
70
|
+
* Repo->>DB: Execute DB operation
|
|
71
|
+
* DB-->>Repo: DB Result
|
|
72
|
+
* Repo-->>Controller: Model Instance(s)
|
|
73
|
+
* Controller-->>Client: JSON Response
|
|
74
|
+
*/
|
|
24
75
|
class FromModelController {
|
|
25
76
|
static { this.log = logging_1.Logging.for(FromModelController.name); }
|
|
26
77
|
static create(ModelClazz) {
|
|
@@ -32,24 +83,26 @@ class FromModelController {
|
|
|
32
83
|
const { description, apiProperties, path } = FromModelController.getRouteParametersFromModel(ModelClazz);
|
|
33
84
|
log.debug(`Creating controller for model: ${modelClazzName}`);
|
|
34
85
|
let DynamicModelController = class DynamicModelController extends logging_1.LoggedClass {
|
|
35
|
-
constructor(
|
|
86
|
+
constructor(clientContext) {
|
|
36
87
|
super();
|
|
37
|
-
this.
|
|
88
|
+
this.clientContext = clientContext;
|
|
89
|
+
this.pk = decorator_validation_1.Model.pk(ModelClazz);
|
|
38
90
|
log.info(`Registering dynamic controller for model: ${modelClazzName} route: /${routePath}`);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
91
|
+
}
|
|
92
|
+
get repository() {
|
|
93
|
+
if (!this._repo)
|
|
94
|
+
this._repo = core_1.Repository.forModel(ModelClazz);
|
|
95
|
+
const adapterOptions = this.clientContext.get(constants_1.DECAF_ADAPTER_OPTIONS);
|
|
96
|
+
if (adapterOptions)
|
|
97
|
+
return this._repo.for(adapterOptions);
|
|
98
|
+
return this._repo;
|
|
46
99
|
}
|
|
47
100
|
async create(data) {
|
|
48
101
|
const log = this.log.for(this.create);
|
|
49
102
|
log.verbose(`creating new ${modelClazzName}`);
|
|
50
103
|
let created;
|
|
51
104
|
try {
|
|
52
|
-
created = await this.
|
|
105
|
+
created = await this.repository.create(data);
|
|
53
106
|
}
|
|
54
107
|
catch (e) {
|
|
55
108
|
log.error(`Failed to create new ${modelClazzName}`, e);
|
|
@@ -64,7 +117,7 @@ class FromModelController {
|
|
|
64
117
|
let read;
|
|
65
118
|
try {
|
|
66
119
|
log.debug(`reading ${modelClazzName} with ${this.pk} ${id}`);
|
|
67
|
-
read = await this.
|
|
120
|
+
read = await this.repository.read(id);
|
|
68
121
|
}
|
|
69
122
|
catch (e) {
|
|
70
123
|
log.error(`Failed to read ${modelClazzName} with id ${id}`, e);
|
|
@@ -78,7 +131,7 @@ class FromModelController {
|
|
|
78
131
|
let results;
|
|
79
132
|
try {
|
|
80
133
|
log.debug(`Querying ${modelClazzName} using method "${method}"`);
|
|
81
|
-
results = await this.
|
|
134
|
+
results = await this.repository[method]();
|
|
82
135
|
}
|
|
83
136
|
catch (e) {
|
|
84
137
|
log.error(`Failed to query ${modelClazzName} using method "${method}"`, e);
|
|
@@ -92,7 +145,7 @@ class FromModelController {
|
|
|
92
145
|
let updated;
|
|
93
146
|
try {
|
|
94
147
|
log.info(`updating ${modelClazzName} with ${this.pk} ${body[this.pk]}`);
|
|
95
|
-
updated = await this.
|
|
148
|
+
updated = await this.repository.create(body);
|
|
96
149
|
}
|
|
97
150
|
catch (e) {
|
|
98
151
|
log.error(e);
|
|
@@ -105,7 +158,7 @@ class FromModelController {
|
|
|
105
158
|
let read;
|
|
106
159
|
try {
|
|
107
160
|
log.debug(`deleting ${modelClazzName} with ${this.pk} ${routeParams}`);
|
|
108
|
-
read = await this.
|
|
161
|
+
read = await this.repository.read("id");
|
|
109
162
|
}
|
|
110
163
|
catch (e) {
|
|
111
164
|
log.error(`Failed to delete ${modelClazzName} with id ${"id"}`, e);
|
|
@@ -206,7 +259,7 @@ class FromModelController {
|
|
|
206
259
|
(0, common_1.Controller)(routePath),
|
|
207
260
|
(0, swagger_1.ApiTags)(modelClazzName),
|
|
208
261
|
(0, swagger_1.ApiExtraModels)(ModelClazz),
|
|
209
|
-
__metadata("design:paramtypes", [
|
|
262
|
+
__metadata("design:paramtypes", [request_1.DecafRequestContext])
|
|
210
263
|
], DynamicModelController);
|
|
211
264
|
return DynamicModelController;
|
|
212
265
|
}
|
|
@@ -1,4 +1,53 @@
|
|
|
1
1
|
import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* Factory and utilities for generating dynamic NestJS controllers from Decaf {@link Model} definitions.
|
|
5
|
+
*
|
|
6
|
+
* @summary
|
|
7
|
+
* The `FromModelController` class provides the infrastructure necessary to automatically generate
|
|
8
|
+
* strongly-typed CRUD controllers based on a given {@link ModelConstructor}. It inspects metadata from
|
|
9
|
+
* the model, derives route paths, parameters, and generates a dynamic controller class at runtime with
|
|
10
|
+
* full support for querying, creation, update, and deletion of model entities through a {@link Repo}.
|
|
11
|
+
*
|
|
12
|
+
* @template T The {@link Model} type associated with the generated controller.
|
|
13
|
+
*
|
|
14
|
+
* @param ModelClazz The model class to generate the controller from.
|
|
15
|
+
*
|
|
16
|
+
* @class FromModelController
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // Given a Decaf Model:
|
|
21
|
+
* class User extends Model<User> {
|
|
22
|
+
* id!: string;
|
|
23
|
+
* name!: string;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // Register controller:
|
|
27
|
+
* const UserController = FromModelController.create(User);
|
|
28
|
+
*
|
|
29
|
+
* // NestJS will expose:
|
|
30
|
+
* // POST /user
|
|
31
|
+
* // GET /user/:id
|
|
32
|
+
* // GET /user/query/:method
|
|
33
|
+
* // PUT /user/:id
|
|
34
|
+
* // DELETE /user/:id
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @mermaid
|
|
38
|
+
* sequenceDiagram
|
|
39
|
+
* participant Client
|
|
40
|
+
* participant Controller
|
|
41
|
+
* participant Repo
|
|
42
|
+
* participant DB
|
|
43
|
+
*
|
|
44
|
+
* Client->>Controller: HTTP Request
|
|
45
|
+
* Controller->>Repo: Resolve repository for Model
|
|
46
|
+
* Repo->>DB: Execute DB operation
|
|
47
|
+
* DB-->>Repo: DB Result
|
|
48
|
+
* Repo-->>Controller: Model Instance(s)
|
|
49
|
+
* Controller-->>Client: JSON Response
|
|
50
|
+
*/
|
|
2
51
|
export declare class FromModelController {
|
|
3
52
|
private static readonly log;
|
|
4
53
|
static create<T extends Model<any>>(ModelClazz: ModelConstructor<T>): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FromModelController.js","sourceRoot":"","sources":["../../src/decaf-model/FromModelController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyD;AACzD,6CAYyB;
|
|
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,2DAAiD;AACjD,qDAAgD;AAChD,uDAKsB;AACtB,oDAAiD;AACjD,kDAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAa,mBAAmB;aACN,QAAG,GAAG,iBAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAE7D,AAAP,MAAM,CAAC,MAAM,CAAuB,UAA+B;QACjE,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACpE,MAAM,SAAS,GAAG,4BAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAA,qBAAW,EAAC,SAAS,CAAC,CAAC;QACzC,MAAM,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC;QACvC,6D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C,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;;AA5NH,kDA6NC"}
|
package/lib/esm/constants.d.ts
CHANGED
package/lib/esm/constants.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export const DECAF_MODULE_OPTIONS = "DecafModuleOptions";
|
|
2
2
|
export const DECAF_ADAPTER_ID = "DecafAdapter";
|
|
3
|
+
export const DECAF_HANDLERS = Symbol("DecafHandlers");
|
|
4
|
+
export const DECAF_ADAPTER_OPTIONS = Symbol("DecafAdapterForOptions");
|
|
3
5
|
//# sourceMappingURL=constants.js.map
|
package/lib/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAE/C,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DynamicModule } from "@nestjs/common";
|
|
1
|
+
import { DynamicModule, Type } from "@nestjs/common";
|
|
2
|
+
import { type DecafRequestHandler } from "../types";
|
|
2
3
|
export declare class DecafModelModule {
|
|
3
4
|
private static readonly log;
|
|
4
|
-
static forRoot(flavour: string): DynamicModule;
|
|
5
|
+
static forRoot(flavour: string, handlers?: Type<DecafRequestHandler>[]): DynamicModule;
|
|
5
6
|
}
|
|
@@ -8,12 +8,15 @@ var DecafModelModule_1;
|
|
|
8
8
|
import { Module } from "@nestjs/common";
|
|
9
9
|
import { Adapter } from "@decaf-ts/core";
|
|
10
10
|
import { Logging } from "@decaf-ts/logging";
|
|
11
|
-
import { RepoFactory } from "./../RepoFactory.js";
|
|
12
11
|
import { FromModelController } from "./FromModelController.js";
|
|
12
|
+
import { DecafRequestHandlerInterceptor } from "./../interceptors/index.js";
|
|
13
|
+
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
14
|
+
import { DecafHandlerExecutor, DecafRequestContext } from "./../request/index.js";
|
|
15
|
+
import { DECAF_HANDLERS } from "./../constants.js";
|
|
13
16
|
let DecafModelModule = class DecafModelModule {
|
|
14
17
|
static { DecafModelModule_1 = this; }
|
|
15
18
|
static { this.log = Logging.for(DecafModelModule_1.name); }
|
|
16
|
-
static forRoot(flavour) {
|
|
19
|
+
static forRoot(flavour, handlers = []) {
|
|
17
20
|
const log = this.log.for(this.forRoot);
|
|
18
21
|
log.info(`Generating controllers for flavour...`);
|
|
19
22
|
const trackedModels = Adapter.models(flavour);
|
|
@@ -22,7 +25,23 @@ let DecafModelModule = class DecafModelModule {
|
|
|
22
25
|
return {
|
|
23
26
|
module: DecafModelModule_1,
|
|
24
27
|
controllers,
|
|
25
|
-
providers: [
|
|
28
|
+
providers: [
|
|
29
|
+
{
|
|
30
|
+
provide: DECAF_HANDLERS,
|
|
31
|
+
useFactory: () => {
|
|
32
|
+
return handlers.map((H) => {
|
|
33
|
+
log.info(`Registered request handler: ${H.name}`);
|
|
34
|
+
return new H();
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
DecafRequestContext,
|
|
39
|
+
DecafHandlerExecutor,
|
|
40
|
+
{
|
|
41
|
+
provide: APP_INTERCEPTOR,
|
|
42
|
+
useClass: DecafRequestHandlerInterceptor,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
26
45
|
};
|
|
27
46
|
}
|
|
28
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecafModelModule.js","sourceRoot":"","sources":["../../../src/decaf-model/DecafModelModule.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAiB,MAAM,
|
|
1
|
+
{"version":3,"file":"DecafModelModule.js","sourceRoot":"","sources":["../../../src/decaf-model/DecafModelModule.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAiB,MAAM,EAAQ,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,iCAA8B;AAC5D,OAAO,EAAE,8BAA8B,EAAE,mCAAwB;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,8BAAmB;AACvE,OAAO,EAAE,cAAc,EAAE,0BAAqB;AAGvC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;;aACH,QAAG,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAgB,CAAC,IAAI,CAAC,AAArC,CAAsC;IAEjE,MAAM,CAAC,OAAO,CACZ,OAAe,EACf,WAAwC,EAAE;QAE1C,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;gBACT;oBACE,OAAO,EAAE,cAAc;oBACvB,UAAU,EAAE,GAAG,EAAE;wBACf,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;4BACxB,GAAG,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;4BAClD,OAAO,IAAI,CAAC,EAAE,CAAC;wBACjB,CAAC,CAAC,CAAC;oBACL,CAAC;iBACF;gBACD,mBAAmB;gBACnB,oBAAoB;gBACpB;oBACE,OAAO,EAAE,eAAe;oBACxB,QAAQ,EAAE,8BAA8B;iBACzC;aACF;SACF,CAAC;IACJ,CAAC;;AApCU,gBAAgB;IAD5B,MAAM,CAAC,EAAE,CAAC;GACE,gBAAgB,CAqC5B"}
|
|
@@ -1,4 +1,53 @@
|
|
|
1
1
|
import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* Factory and utilities for generating dynamic NestJS controllers from Decaf {@link Model} definitions.
|
|
5
|
+
*
|
|
6
|
+
* @summary
|
|
7
|
+
* The `FromModelController` class provides the infrastructure necessary to automatically generate
|
|
8
|
+
* strongly-typed CRUD controllers based on a given {@link ModelConstructor}. It inspects metadata from
|
|
9
|
+
* the model, derives route paths, parameters, and generates a dynamic controller class at runtime with
|
|
10
|
+
* full support for querying, creation, update, and deletion of model entities through a {@link Repo}.
|
|
11
|
+
*
|
|
12
|
+
* @template T The {@link Model} type associated with the generated controller.
|
|
13
|
+
*
|
|
14
|
+
* @param ModelClazz The model class to generate the controller from.
|
|
15
|
+
*
|
|
16
|
+
* @class FromModelController
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // Given a Decaf Model:
|
|
21
|
+
* class User extends Model<User> {
|
|
22
|
+
* id!: string;
|
|
23
|
+
* name!: string;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // Register controller:
|
|
27
|
+
* const UserController = FromModelController.create(User);
|
|
28
|
+
*
|
|
29
|
+
* // NestJS will expose:
|
|
30
|
+
* // POST /user
|
|
31
|
+
* // GET /user/:id
|
|
32
|
+
* // GET /user/query/:method
|
|
33
|
+
* // PUT /user/:id
|
|
34
|
+
* // DELETE /user/:id
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @mermaid
|
|
38
|
+
* sequenceDiagram
|
|
39
|
+
* participant Client
|
|
40
|
+
* participant Controller
|
|
41
|
+
* participant Repo
|
|
42
|
+
* participant DB
|
|
43
|
+
*
|
|
44
|
+
* Client->>Controller: HTTP Request
|
|
45
|
+
* Controller->>Repo: Resolve repository for Model
|
|
46
|
+
* Repo->>DB: Execute DB operation
|
|
47
|
+
* DB-->>Repo: DB Result
|
|
48
|
+
* Repo-->>Controller: Model Instance(s)
|
|
49
|
+
* Controller-->>Client: JSON Response
|
|
50
|
+
*/
|
|
2
51
|
export declare class FromModelController {
|
|
3
52
|
private static readonly log;
|
|
4
53
|
static create<T extends Model<any>>(ModelClazz: ModelConstructor<T>): any;
|
|
@@ -12,12 +12,63 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
};
|
|
13
13
|
import { Body, Controller, Param } from "@nestjs/common";
|
|
14
14
|
import { ApiBadRequestResponse, ApiBody, ApiCreatedResponse, ApiExtraModels, ApiNotFoundResponse, ApiOkResponse, ApiOperation, ApiParam, ApiTags, ApiUnprocessableEntityResponse, getSchemaPath, } from "@nestjs/swagger";
|
|
15
|
+
import { Repository } from "@decaf-ts/core";
|
|
15
16
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
16
17
|
import { LoggedClass, Logging, toKebabCase } from "@decaf-ts/logging";
|
|
17
18
|
import { DBKeys } from "@decaf-ts/db-decorators";
|
|
18
19
|
import { Metadata } from "@decaf-ts/decoration";
|
|
19
20
|
import { ApiOperationFromModel, ApiParamsFromModel, DecafParams, } from "./decorators/index.js";
|
|
20
|
-
import {
|
|
21
|
+
import { DecafRequestContext } from "./../request/index.js";
|
|
22
|
+
import { DECAF_ADAPTER_OPTIONS } from "./../constants.js";
|
|
23
|
+
/**
|
|
24
|
+
* @description
|
|
25
|
+
* Factory and utilities for generating dynamic NestJS controllers from Decaf {@link Model} definitions.
|
|
26
|
+
*
|
|
27
|
+
* @summary
|
|
28
|
+
* The `FromModelController` class provides the infrastructure necessary to automatically generate
|
|
29
|
+
* strongly-typed CRUD controllers based on a given {@link ModelConstructor}. It inspects metadata from
|
|
30
|
+
* the model, derives route paths, parameters, and generates a dynamic controller class at runtime with
|
|
31
|
+
* full support for querying, creation, update, and deletion of model entities through a {@link Repo}.
|
|
32
|
+
*
|
|
33
|
+
* @template T The {@link Model} type associated with the generated controller.
|
|
34
|
+
*
|
|
35
|
+
* @param ModelClazz The model class to generate the controller from.
|
|
36
|
+
*
|
|
37
|
+
* @class FromModelController
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // Given a Decaf Model:
|
|
42
|
+
* class User extends Model<User> {
|
|
43
|
+
* id!: string;
|
|
44
|
+
* name!: string;
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* // Register controller:
|
|
48
|
+
* const UserController = FromModelController.create(User);
|
|
49
|
+
*
|
|
50
|
+
* // NestJS will expose:
|
|
51
|
+
* // POST /user
|
|
52
|
+
* // GET /user/:id
|
|
53
|
+
* // GET /user/query/:method
|
|
54
|
+
* // PUT /user/:id
|
|
55
|
+
* // DELETE /user/:id
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @mermaid
|
|
59
|
+
* sequenceDiagram
|
|
60
|
+
* participant Client
|
|
61
|
+
* participant Controller
|
|
62
|
+
* participant Repo
|
|
63
|
+
* participant DB
|
|
64
|
+
*
|
|
65
|
+
* Client->>Controller: HTTP Request
|
|
66
|
+
* Controller->>Repo: Resolve repository for Model
|
|
67
|
+
* Repo->>DB: Execute DB operation
|
|
68
|
+
* DB-->>Repo: DB Result
|
|
69
|
+
* Repo-->>Controller: Model Instance(s)
|
|
70
|
+
* Controller-->>Client: JSON Response
|
|
71
|
+
*/
|
|
21
72
|
export class FromModelController {
|
|
22
73
|
static { this.log = Logging.for(FromModelController.name); }
|
|
23
74
|
static create(ModelClazz) {
|
|
@@ -29,24 +80,26 @@ export class FromModelController {
|
|
|
29
80
|
const { description, apiProperties, path } = FromModelController.getRouteParametersFromModel(ModelClazz);
|
|
30
81
|
log.debug(`Creating controller for model: ${modelClazzName}`);
|
|
31
82
|
let DynamicModelController = class DynamicModelController extends LoggedClass {
|
|
32
|
-
constructor(
|
|
83
|
+
constructor(clientContext) {
|
|
33
84
|
super();
|
|
34
|
-
this.
|
|
85
|
+
this.clientContext = clientContext;
|
|
86
|
+
this.pk = Model.pk(ModelClazz);
|
|
35
87
|
log.info(`Registering dynamic controller for model: ${modelClazzName} route: /${routePath}`);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
88
|
+
}
|
|
89
|
+
get repository() {
|
|
90
|
+
if (!this._repo)
|
|
91
|
+
this._repo = Repository.forModel(ModelClazz);
|
|
92
|
+
const adapterOptions = this.clientContext.get(DECAF_ADAPTER_OPTIONS);
|
|
93
|
+
if (adapterOptions)
|
|
94
|
+
return this._repo.for(adapterOptions);
|
|
95
|
+
return this._repo;
|
|
43
96
|
}
|
|
44
97
|
async create(data) {
|
|
45
98
|
const log = this.log.for(this.create);
|
|
46
99
|
log.verbose(`creating new ${modelClazzName}`);
|
|
47
100
|
let created;
|
|
48
101
|
try {
|
|
49
|
-
created = await this.
|
|
102
|
+
created = await this.repository.create(data);
|
|
50
103
|
}
|
|
51
104
|
catch (e) {
|
|
52
105
|
log.error(`Failed to create new ${modelClazzName}`, e);
|
|
@@ -61,7 +114,7 @@ export class FromModelController {
|
|
|
61
114
|
let read;
|
|
62
115
|
try {
|
|
63
116
|
log.debug(`reading ${modelClazzName} with ${this.pk} ${id}`);
|
|
64
|
-
read = await this.
|
|
117
|
+
read = await this.repository.read(id);
|
|
65
118
|
}
|
|
66
119
|
catch (e) {
|
|
67
120
|
log.error(`Failed to read ${modelClazzName} with id ${id}`, e);
|
|
@@ -75,7 +128,7 @@ export class FromModelController {
|
|
|
75
128
|
let results;
|
|
76
129
|
try {
|
|
77
130
|
log.debug(`Querying ${modelClazzName} using method "${method}"`);
|
|
78
|
-
results = await this.
|
|
131
|
+
results = await this.repository[method]();
|
|
79
132
|
}
|
|
80
133
|
catch (e) {
|
|
81
134
|
log.error(`Failed to query ${modelClazzName} using method "${method}"`, e);
|
|
@@ -89,7 +142,7 @@ export class FromModelController {
|
|
|
89
142
|
let updated;
|
|
90
143
|
try {
|
|
91
144
|
log.info(`updating ${modelClazzName} with ${this.pk} ${body[this.pk]}`);
|
|
92
|
-
updated = await this.
|
|
145
|
+
updated = await this.repository.create(body);
|
|
93
146
|
}
|
|
94
147
|
catch (e) {
|
|
95
148
|
log.error(e);
|
|
@@ -102,7 +155,7 @@ export class FromModelController {
|
|
|
102
155
|
let read;
|
|
103
156
|
try {
|
|
104
157
|
log.debug(`deleting ${modelClazzName} with ${this.pk} ${routeParams}`);
|
|
105
|
-
read = await this.
|
|
158
|
+
read = await this.repository.read("id");
|
|
106
159
|
}
|
|
107
160
|
catch (e) {
|
|
108
161
|
log.error(`Failed to delete ${modelClazzName} with id ${"id"}`, e);
|
|
@@ -203,7 +256,7 @@ export class FromModelController {
|
|
|
203
256
|
Controller(routePath),
|
|
204
257
|
ApiTags(modelClazzName),
|
|
205
258
|
ApiExtraModels(ModelClazz),
|
|
206
|
-
__metadata("design:paramtypes", [
|
|
259
|
+
__metadata("design:paramtypes", [DecafRequestContext])
|
|
207
260
|
], DynamicModelController);
|
|
208
261
|
return DynamicModelController;
|
|
209
262
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FromModelController.js","sourceRoot":"","sources":["../../../src/decaf-model/FromModelController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,8BAA8B,EAC9B,aAAa,GACd,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"FromModelController.js","sourceRoot":"","sources":["../../../src/decaf-model/FromModelController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,8BAA8B,EAC9B,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAQ,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAoB,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,QAA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MAAM,YAAY,GAChB,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC;YACpD,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;YACnB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAEX,MAAM,WAAW,GAAG,QAAQ,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,QAAQ,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"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -23,11 +23,12 @@ import "./decoration";
|
|
|
23
23
|
export * from "./constants";
|
|
24
24
|
export * from "./decoration";
|
|
25
25
|
export * from "./module";
|
|
26
|
-
export * from "./RepoFactory";
|
|
27
26
|
export * from "./types";
|
|
28
27
|
export * from "./utils";
|
|
29
28
|
export * from "./factory";
|
|
30
29
|
export * from "./decaf-model";
|
|
30
|
+
export * from "./interceptors";
|
|
31
|
+
export * from "./request";
|
|
31
32
|
/**
|
|
32
33
|
* Represents the current version of the ts-workspace module.
|
|
33
34
|
* The actual version number is replaced during the build process.
|
package/lib/esm/index.js
CHANGED
|
@@ -24,11 +24,12 @@ import "./decoration.js";
|
|
|
24
24
|
export * from "./constants.js";
|
|
25
25
|
export * from "./decoration.js";
|
|
26
26
|
export * from "./module.js";
|
|
27
|
-
export * from "./RepoFactory.js";
|
|
28
27
|
export * from "./types.js";
|
|
29
28
|
export * from "./utils.js";
|
|
30
29
|
export * from "./factory/index.js";
|
|
31
30
|
export * from "./decaf-model/index.js";
|
|
31
|
+
export * from "./interceptors/index.js";
|
|
32
|
+
export * from "./request/index.js";
|
|
32
33
|
/**
|
|
33
34
|
* Represents the current version of the ts-workspace module.
|
|
34
35
|
* The actual version number is replaced during the build process.
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,yBAAsB;AAEtB,+BAA4B;AAC5B,gCAA6B;AAC7B,4BAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,yBAAsB;AAEtB,+BAA4B;AAC5B,gCAA6B;AAC7B,4BAAyB;AACzB,2BAAwB;AACxB,2BAAwB;AACxB,mCAA0B;AAC1B,uCAA8B;AAC9B,wCAA+B;AAC/B,mCAA0B;AAE1B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AACrC,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;AAE1C,QAAQ,CAAC,eAAe,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from "@nestjs/common";
|
|
2
|
+
import { DecafHandlerExecutor } from "../request";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* Interceptor responsible for executing all registered Decaf request handlers
|
|
6
|
+
* before the controller method is invoked.
|
|
7
|
+
*
|
|
8
|
+
* @summary
|
|
9
|
+
* The {@link DecafRequestHandlerInterceptor} integrates the Decaf request-handling pipeline
|
|
10
|
+
* into NestJS' interceptor mechanism. Before passing execution to the next handler in the
|
|
11
|
+
* NestJS chain, it delegates request processing to the {@link DecafHandlerExecutor}, which
|
|
12
|
+
* sequentially runs all registered {@link DecafRequestHandler} instances. This allows
|
|
13
|
+
* behaviors such as authentication, logging, tenant resolution, or metadata enrichment
|
|
14
|
+
* to occur prior to controller execution.
|
|
15
|
+
*
|
|
16
|
+
* @class DecafRequestHandlerInterceptor
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // Apply globally:
|
|
21
|
+
* app.useGlobalInterceptors(new DecafRequestHandlerInterceptor(executor));
|
|
22
|
+
*
|
|
23
|
+
* // Or in a module:
|
|
24
|
+
* @Module({
|
|
25
|
+
* providers: [
|
|
26
|
+
* DecafHandlerExecutor,
|
|
27
|
+
* {
|
|
28
|
+
* provide: APP_INTERCEPTOR,
|
|
29
|
+
* useClass: DecafRequestHandlerInterceptor,
|
|
30
|
+
* },
|
|
31
|
+
* ],
|
|
32
|
+
* })
|
|
33
|
+
* export class AppModule {}
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @mermaid
|
|
37
|
+
* sequenceDiagram
|
|
38
|
+
* participant Client
|
|
39
|
+
* participant Interceptor
|
|
40
|
+
* participant Executor
|
|
41
|
+
* participant Controller
|
|
42
|
+
*
|
|
43
|
+
* Client->>Interceptor: HTTP Request
|
|
44
|
+
* Interceptor->>Executor: exec(request)
|
|
45
|
+
* Executor-->>Interceptor: handlers completed
|
|
46
|
+
* Interceptor->>Controller: next.handle()
|
|
47
|
+
* Controller-->>Client: Response
|
|
48
|
+
*/
|
|
49
|
+
export declare class DecafRequestHandlerInterceptor implements NestInterceptor {
|
|
50
|
+
private readonly executor;
|
|
51
|
+
constructor(executor: DecafHandlerExecutor);
|
|
52
|
+
intercept(ctx: ExecutionContext, next: CallHandler): Promise<import("rxjs").Observable<any>>;
|
|
53
|
+
}
|