@decaf-ts/for-nest 0.1.5 → 0.1.7
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/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 +4 -1
- package/lib/constants.d.ts +3 -0
- package/lib/constants.js.map +1 -1
- package/lib/decaf-model/DecafModelModule.cjs +8 -0
- package/lib/decaf-model/DecafModelModule.d.ts +1 -0
- package/lib/decaf-model/DecafModelModule.js.map +1 -1
- package/lib/decaf-model/FromModelController.cjs +42 -30
- package/lib/decaf-model/FromModelController.d.ts +2 -10
- package/lib/decaf-model/FromModelController.js.map +1 -1
- package/lib/decaf-model/decorators/ApiParamsFromModel.d.ts +2 -2
- package/lib/decaf-model/decorators/ApiParamsFromModel.js.map +1 -1
- package/lib/decaf-model/decorators/DecafParams.d.ts +2 -2
- package/lib/decaf-model/decorators/DecafParams.js.map +1 -1
- package/lib/decaf-model/decorators/decorators.cjs +60 -0
- package/lib/decaf-model/decorators/decorators.d.ts +46 -0
- package/lib/decaf-model/decorators/decorators.js.map +1 -0
- package/lib/decaf-model/decorators/types.d.ts +7 -1
- package/lib/esm/constants.d.ts +3 -0
- package/lib/esm/constants.js +3 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/decaf-model/DecafModelModule.d.ts +1 -0
- package/lib/esm/decaf-model/DecafModelModule.js +9 -1
- package/lib/esm/decaf-model/DecafModelModule.js.map +1 -1
- package/lib/esm/decaf-model/FromModelController.d.ts +2 -10
- package/lib/esm/decaf-model/FromModelController.js +43 -31
- package/lib/esm/decaf-model/FromModelController.js.map +1 -1
- package/lib/esm/decaf-model/decorators/ApiParamsFromModel.d.ts +2 -2
- package/lib/esm/decaf-model/decorators/ApiParamsFromModel.js.map +1 -1
- package/lib/esm/decaf-model/decorators/DecafParams.d.ts +2 -2
- package/lib/esm/decaf-model/decorators/DecafParams.js.map +1 -1
- package/lib/esm/decaf-model/decorators/decorators.d.ts +46 -0
- package/lib/esm/decaf-model/decorators/decorators.js +55 -0
- package/lib/esm/decaf-model/decorators/decorators.js.map +1 -0
- package/lib/esm/decaf-model/decorators/types.d.ts +7 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/interceptors/AuthInterceptor.d.ts +10 -0
- package/lib/esm/interceptors/AuthInterceptor.js +37 -0
- package/lib/esm/interceptors/AuthInterceptor.js.map +1 -0
- package/lib/esm/interceptors/DecafRequestHandlerInterceptor.js +2 -1
- package/lib/esm/interceptors/DecafRequestHandlerInterceptor.js.map +1 -1
- package/lib/esm/request/DecafHandlerExecutor.d.ts +1 -1
- package/lib/esm/request/DecafHandlerExecutor.js +2 -2
- package/lib/esm/request/DecafHandlerExecutor.js.map +1 -1
- package/lib/esm/types.d.ts +46 -2
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/interceptors/AuthInterceptor.cjs +40 -0
- package/lib/interceptors/AuthInterceptor.d.ts +10 -0
- package/lib/interceptors/AuthInterceptor.js.map +1 -0
- package/lib/interceptors/DecafRequestHandlerInterceptor.cjs +2 -1
- package/lib/interceptors/DecafRequestHandlerInterceptor.js.map +1 -1
- package/lib/request/DecafHandlerExecutor.cjs +2 -2
- package/lib/request/DecafHandlerExecutor.d.ts +1 -1
- package/lib/request/DecafHandlerExecutor.js.map +1 -1
- package/lib/types.d.ts +46 -2
- package/package.json +5 -2
|
@@ -23,6 +23,7 @@ const decoration_1 = require("@decaf-ts/decoration");
|
|
|
23
23
|
const decorators_1 = require("./decorators/index.cjs");
|
|
24
24
|
const request_1 = require("./../request/index.cjs");
|
|
25
25
|
const constants_1 = require("./../constants.cjs");
|
|
26
|
+
const decorators_2 = require("./decorators/decorators.cjs");
|
|
26
27
|
/**
|
|
27
28
|
* @description
|
|
28
29
|
* Factory and utilities for generating dynamic NestJS controllers from Decaf {@link Model} definitions.
|
|
@@ -80,7 +81,7 @@ class FromModelController {
|
|
|
80
81
|
const routePath = (0, logging_1.toKebabCase)(tableName);
|
|
81
82
|
const modelClazzName = ModelClazz.name;
|
|
82
83
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
-
const { description, apiProperties, path } = FromModelController.getRouteParametersFromModel(ModelClazz);
|
|
84
|
+
const { description, getPK, apiProperties, path } = FromModelController.getRouteParametersFromModel(ModelClazz);
|
|
84
85
|
log.debug(`Creating controller for model: ${modelClazzName}`);
|
|
85
86
|
let DynamicModelController = class DynamicModelController extends logging_1.LoggedClass {
|
|
86
87
|
constructor(clientContext) {
|
|
@@ -89,20 +90,22 @@ class FromModelController {
|
|
|
89
90
|
this.pk = decorator_validation_1.Model.pk(ModelClazz);
|
|
90
91
|
log.info(`Registering dynamic controller for model: ${modelClazzName} route: /${routePath}`);
|
|
91
92
|
}
|
|
92
|
-
get
|
|
93
|
-
if (!this.
|
|
94
|
-
this.
|
|
93
|
+
get persistence() {
|
|
94
|
+
if (!this._persistence)
|
|
95
|
+
this._persistence =
|
|
96
|
+
core_1.ModelService.getService(ModelClazz) ||
|
|
97
|
+
core_1.Repository.forModel(ModelClazz);
|
|
95
98
|
const adapterOptions = this.clientContext.get(constants_1.DECAF_ADAPTER_OPTIONS);
|
|
96
99
|
if (adapterOptions)
|
|
97
|
-
return this.
|
|
98
|
-
return this.
|
|
100
|
+
return this._persistence.for(adapterOptions);
|
|
101
|
+
return this._persistence;
|
|
99
102
|
}
|
|
100
103
|
async create(data) {
|
|
101
104
|
const log = this.log.for(this.create);
|
|
102
105
|
log.verbose(`creating new ${modelClazzName}`);
|
|
103
106
|
let created;
|
|
104
107
|
try {
|
|
105
|
-
created = await this.
|
|
108
|
+
created = await this.persistence.create(data);
|
|
106
109
|
}
|
|
107
110
|
catch (e) {
|
|
108
111
|
log.error(`Failed to create new ${modelClazzName}`, e);
|
|
@@ -111,15 +114,15 @@ class FromModelController {
|
|
|
111
114
|
log.info(`created new ${modelClazzName} with id ${created[this.pk]}`);
|
|
112
115
|
return created;
|
|
113
116
|
}
|
|
114
|
-
async read(
|
|
115
|
-
const id =
|
|
117
|
+
async read(routeParams) {
|
|
118
|
+
const id = getPK(...routeParams.ordered);
|
|
116
119
|
if (typeof id === "undefined")
|
|
117
120
|
throw new db_decorators_1.ValidationError(`No ${this.pk} provided`);
|
|
118
121
|
const log = this.log.for(this.read);
|
|
119
122
|
let read;
|
|
120
123
|
try {
|
|
121
124
|
log.debug(`reading ${modelClazzName} with ${this.pk} ${id}`);
|
|
122
|
-
read = await this.
|
|
125
|
+
read = await this.persistence.read(id);
|
|
123
126
|
}
|
|
124
127
|
catch (e) {
|
|
125
128
|
log.error(`Failed to read ${modelClazzName} with id ${id}`, e);
|
|
@@ -133,7 +136,8 @@ class FromModelController {
|
|
|
133
136
|
let results;
|
|
134
137
|
try {
|
|
135
138
|
log.debug(`Querying ${modelClazzName} using method "${method}"`);
|
|
136
|
-
|
|
139
|
+
const args = [method];
|
|
140
|
+
results = await this.persistence.query(...args);
|
|
137
141
|
}
|
|
138
142
|
catch (e) {
|
|
139
143
|
log.error(`Failed to query ${modelClazzName} using method "${method}"`, e);
|
|
@@ -144,10 +148,16 @@ class FromModelController {
|
|
|
144
148
|
}
|
|
145
149
|
async update(routeParams, body) {
|
|
146
150
|
const log = this.log.for(this.update);
|
|
151
|
+
const id = getPK(...routeParams.ordered);
|
|
152
|
+
if (typeof id === "undefined")
|
|
153
|
+
throw new db_decorators_1.ValidationError(`No ${this.pk} provided`);
|
|
147
154
|
let updated;
|
|
148
155
|
try {
|
|
149
|
-
log.info(`updating ${modelClazzName} with ${this.pk} ${
|
|
150
|
-
updated = await this.
|
|
156
|
+
log.info(`updating ${modelClazzName} with ${this.pk} ${id}`);
|
|
157
|
+
updated = await this.persistence.update(new ModelClazz({
|
|
158
|
+
...body,
|
|
159
|
+
[this.pk]: id,
|
|
160
|
+
}));
|
|
151
161
|
}
|
|
152
162
|
catch (e) {
|
|
153
163
|
log.error(e);
|
|
@@ -155,24 +165,22 @@ class FromModelController {
|
|
|
155
165
|
}
|
|
156
166
|
return updated;
|
|
157
167
|
}
|
|
158
|
-
async delete(
|
|
159
|
-
const id = pathParams[this.pk];
|
|
160
|
-
if (typeof id === "undefined")
|
|
161
|
-
throw new db_decorators_1.ValidationError(`No ${this.pk} provided`);
|
|
168
|
+
async delete(routeParams) {
|
|
162
169
|
const log = this.log.for(this.delete);
|
|
170
|
+
const id = getPK(...routeParams.ordered);
|
|
163
171
|
if (typeof id === "undefined")
|
|
164
172
|
throw new db_decorators_1.ValidationError(`No ${this.pk} provided`);
|
|
165
|
-
let
|
|
173
|
+
let del;
|
|
166
174
|
try {
|
|
167
|
-
log.debug(`deleting ${modelClazzName} with ${this.pk} ${
|
|
168
|
-
|
|
175
|
+
log.debug(`deleting ${modelClazzName} with ${this.pk} ${id}`);
|
|
176
|
+
del = await this.persistence.delete(id);
|
|
169
177
|
}
|
|
170
178
|
catch (e) {
|
|
171
|
-
log.error(`Failed to delete ${modelClazzName} with id ${
|
|
179
|
+
log.error(`Failed to delete ${modelClazzName} with id ${id}`, e);
|
|
172
180
|
throw e;
|
|
173
181
|
}
|
|
174
|
-
log.info(`deleted ${modelClazzName} with id ${
|
|
175
|
-
return
|
|
182
|
+
log.info(`deleted ${modelClazzName} with id ${id}`);
|
|
183
|
+
return del;
|
|
176
184
|
}
|
|
177
185
|
};
|
|
178
186
|
__decorate([
|
|
@@ -204,7 +212,7 @@ class FromModelController {
|
|
|
204
212
|
(0, swagger_1.ApiNotFoundResponse)({
|
|
205
213
|
description: `No ${modelClazzName} record matches the provided identifier.`,
|
|
206
214
|
}),
|
|
207
|
-
__param(0, (0,
|
|
215
|
+
__param(0, (0, decorators_1.DecafParams)(apiProperties)),
|
|
208
216
|
__metadata("design:type", Function),
|
|
209
217
|
__metadata("design:paramtypes", [Object]),
|
|
210
218
|
__metadata("design:returntype", Promise)
|
|
@@ -257,7 +265,7 @@ class FromModelController {
|
|
|
257
265
|
(0, swagger_1.ApiNotFoundResponse)({
|
|
258
266
|
description: `No ${modelClazzName} record matches the provided identifier.`,
|
|
259
267
|
}),
|
|
260
|
-
__param(0, (0,
|
|
268
|
+
__param(0, (0, decorators_1.DecafParams)(apiProperties)),
|
|
261
269
|
__metadata("design:type", Function),
|
|
262
270
|
__metadata("design:paramtypes", [Object]),
|
|
263
271
|
__metadata("design:returntype", Promise)
|
|
@@ -266,16 +274,15 @@ class FromModelController {
|
|
|
266
274
|
(0, common_1.Controller)(routePath),
|
|
267
275
|
(0, swagger_1.ApiTags)(modelClazzName),
|
|
268
276
|
(0, swagger_1.ApiExtraModels)(ModelClazz),
|
|
277
|
+
(0, decorators_2.Auth)(ModelClazz),
|
|
269
278
|
__metadata("design:paramtypes", [request_1.DecafRequestContext])
|
|
270
279
|
], DynamicModelController);
|
|
271
280
|
return DynamicModelController;
|
|
272
281
|
}
|
|
273
282
|
static getRouteParametersFromModel(ModelClazz) {
|
|
274
|
-
const instance = new ModelClazz({});
|
|
275
283
|
const pk = decorator_validation_1.Model.pk(ModelClazz);
|
|
276
|
-
const
|
|
277
|
-
const composedKeys =
|
|
278
|
-
[];
|
|
284
|
+
const composed = decoration_1.Metadata.get(ModelClazz, decoration_1.Metadata.key(db_decorators_1.DBKeys.COMPOSED, pk));
|
|
285
|
+
const composedKeys = composed?.args ?? [];
|
|
279
286
|
const keysToReturn = Array.isArray(composedKeys) && composedKeys.length > 0
|
|
280
287
|
? [...composedKeys]
|
|
281
288
|
: [pk];
|
|
@@ -291,7 +298,12 @@ class FromModelController {
|
|
|
291
298
|
type: String,
|
|
292
299
|
};
|
|
293
300
|
});
|
|
294
|
-
return {
|
|
301
|
+
return {
|
|
302
|
+
path,
|
|
303
|
+
description,
|
|
304
|
+
apiProperties,
|
|
305
|
+
getPK: (...params) => composed?.separator ? params.join(composed.separator) : params.join(""),
|
|
306
|
+
};
|
|
295
307
|
}
|
|
296
308
|
}
|
|
297
309
|
exports.FromModelController = FromModelController;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import type { DecafModelRoute } from "./decorators";
|
|
2
3
|
/**
|
|
3
4
|
* @description
|
|
4
5
|
* Factory and utilities for generating dynamic NestJS controllers from Decaf {@link Model} definitions.
|
|
@@ -51,14 +52,5 @@ import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
|
51
52
|
export declare class FromModelController {
|
|
52
53
|
private static readonly log;
|
|
53
54
|
static create<T extends Model<any>>(ModelClazz: ModelConstructor<T>): any;
|
|
54
|
-
static getRouteParametersFromModel<T extends Model<any>>(ModelClazz: ModelConstructor<T>):
|
|
55
|
-
description: string | undefined;
|
|
56
|
-
apiProperties: {
|
|
57
|
-
name: any;
|
|
58
|
-
description: string | undefined;
|
|
59
|
-
required: boolean;
|
|
60
|
-
type: StringConstructor;
|
|
61
|
-
}[];
|
|
62
|
-
path: string;
|
|
63
|
-
};
|
|
55
|
+
static getRouteParametersFromModel<T extends Model<any>>(ModelClazz: ModelConstructor<T>): DecafModelRoute;
|
|
64
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FromModelController.js","sourceRoot":"","sources":["../../src/decaf-model/FromModelController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyD;AACzD,6CAYyB;AACzB,
|
|
1
|
+
{"version":3,"file":"FromModelController.js","sourceRoot":"","sources":["../../src/decaf-model/FromModelController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyD;AACzD,6CAYyB;AACzB,yCAAgE;AAChE,yEAAyE;AACzE,+CAAsE;AACtE,2DAAkE;AAClE,qDAAgD;AAMhD,uDAIsB;AACtB,oDAAiD;AACjD,kDAAqD;AACrD,4DAA+C;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAa,mBAAmB;aACN,QAAG,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EAAE,EAAE;YACjE,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;QAEH,OAAO;YACL,IAAI;YACJ,WAAW;YACX,aAAa;YACb,KAAK,EAAE,CAAC,GAAG,MAA8B,EAAE,EAAE,CAC3C,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;SAC1E,CAAC;IACJ,CAAC;;AAtPH,kDAuPC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DecafApiProperties } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* @description Applies a set of Swagger `@ApiParam` decorators generated from a typed specification array.
|
|
4
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.
|
|
@@ -10,4 +10,4 @@ import { ApiParam } from "./types";
|
|
|
10
10
|
* @return {any} A composed decorator applying all generated `@ApiParam` decorators to the target method or controller.
|
|
11
11
|
* @function ApiParamsFromModel
|
|
12
12
|
*/
|
|
13
|
-
export declare function ApiParamsFromModel(props?:
|
|
13
|
+
export declare function ApiParamsFromModel(props?: DecafApiProperties[]): MethodDecorator & ClassDecorator;
|
|
@@ -1 +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,
|
|
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,QAA8B,EAAE;IAEhC,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"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DecafApiProperties } from "./types";
|
|
2
2
|
/**
|
|
3
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
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
5
|
* @param {ApiParam[]} [props=[]] Array of `ApiParam` definitions whose `name` fields determine the parameter extraction order.
|
|
6
6
|
* @return {ParameterDecorator} A NestJS parameter decorator that injects an ordered list of parameters and metadata into the controller method argument.
|
|
7
7
|
*/
|
|
8
|
-
export declare function DecafParams(props?:
|
|
8
|
+
export declare function DecafParams(props?: DecafApiProperties[]): ParameterDecorator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecafParams.js","sourceRoot":"","sources":["../../../src/decaf-model/decorators/DecafParams.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"DecafParams.js","sourceRoot":"","sources":["../../../src/decaf-model/decorators/DecafParams.ts"],"names":[],"mappings":";;AA8BA,kCAKC;AAnCD,2CAAwE;AAExE;;;;;;;;;;;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,CACzB,QAA8B,EAAE;IAEhC,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,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Roles = void 0;
|
|
4
|
+
exports.Auth = Auth;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const constants_1 = require("./../../constants.cjs");
|
|
7
|
+
const AuthInterceptor_1 = require("./../../interceptors/AuthInterceptor.cjs");
|
|
8
|
+
const decoration_1 = require("@decaf-ts/decoration");
|
|
9
|
+
/**
|
|
10
|
+
* A decorator function that applies authentication and authorization metadata to a NestJS controller or method.
|
|
11
|
+
*
|
|
12
|
+
* @param model - The model name or constructor function for the resource being accessed.
|
|
13
|
+
* If a string is provided, it is used as the resource name.
|
|
14
|
+
* If a constructor function is provided, its name is used as the resource name.
|
|
15
|
+
*
|
|
16
|
+
* @returns - A function that applies the authentication and authorization decorators to the target.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* @Controller('users')
|
|
21
|
+
* @Auth('User')
|
|
22
|
+
* export class UsersController {
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* @Controller('users')
|
|
30
|
+
* @Auth(User)
|
|
31
|
+
* export class UsersController {
|
|
32
|
+
* // ...
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function Auth(model) {
|
|
37
|
+
const resource = typeof model === "string" ? model : model.name;
|
|
38
|
+
return (0, common_1.applyDecorators)((0, common_1.SetMetadata)(constants_1.AUTH_META_KEY, resource), (0, common_1.UseInterceptors)(AuthInterceptor_1.AuthInterceptor));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A decorator function that sets the roles required for authentication and authorization to the model in NestJS.
|
|
42
|
+
*
|
|
43
|
+
* @param roles - An array of role names required for access.
|
|
44
|
+
*
|
|
45
|
+
* @returns - A function that applies the role decorators to the target.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* @model('users')
|
|
50
|
+
* @Roles(['admin'])
|
|
51
|
+
* export class UserModel {
|
|
52
|
+
* //...
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
const Roles = (roles) => {
|
|
57
|
+
return (0, decoration_1.metadata)(constants_1.AuthRole, roles);
|
|
58
|
+
};
|
|
59
|
+
exports.Roles = Roles;
|
|
60
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
/**
|
|
3
|
+
* A decorator function that applies authentication and authorization metadata to a NestJS controller or method.
|
|
4
|
+
*
|
|
5
|
+
* @param model - The model name or constructor function for the resource being accessed.
|
|
6
|
+
* If a string is provided, it is used as the resource name.
|
|
7
|
+
* If a constructor function is provided, its name is used as the resource name.
|
|
8
|
+
*
|
|
9
|
+
* @returns - A function that applies the authentication and authorization decorators to the target.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @Controller('users')
|
|
14
|
+
* @Auth('User')
|
|
15
|
+
* export class UsersController {
|
|
16
|
+
* // ...
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* @Controller('users')
|
|
23
|
+
* @Auth(User)
|
|
24
|
+
* export class UsersController {
|
|
25
|
+
* // ...
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function Auth(model: string | Constructor): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
30
|
+
/**
|
|
31
|
+
* A decorator function that sets the roles required for authentication and authorization to the model in NestJS.
|
|
32
|
+
*
|
|
33
|
+
* @param roles - An array of role names required for access.
|
|
34
|
+
*
|
|
35
|
+
* @returns - A function that applies the role decorators to the target.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* @model('users')
|
|
40
|
+
* @Roles(['admin'])
|
|
41
|
+
* export class UserModel {
|
|
42
|
+
* //...
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
export declare const Roles: (roles: string[]) => (model: any, prop?: any, descriptor?: PropertyDescriptor | number) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/decaf-model/decorators/decorators.ts"],"names":[],"mappings":";;;AAiCA,oBAOC;AAxCD,2CAA+E;AAE/E,qDAA0D;AAC1D,8EAAqE;AACrE,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,IAAI,CAAC,KAA2B;IAC9C,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;IAEhE,OAAO,IAAA,wBAAe,EACpB,IAAA,oBAAW,EAAC,yBAAa,EAAE,QAAQ,CAAC,EACpC,IAAA,wBAAe,EAAC,iCAAe,CAAC,CACjC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACI,MAAM,KAAK,GAAG,CAAC,KAAe,EAAE,EAAE;IACvC,OAAO,IAAA,qBAAQ,EAAC,oBAAQ,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
export type HttpVerbs = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
2
|
-
export type
|
|
2
|
+
export type DecafApiProperties = {
|
|
3
3
|
name: string;
|
|
4
4
|
description?: string;
|
|
5
5
|
required?: boolean;
|
|
6
6
|
type?: any;
|
|
7
7
|
};
|
|
8
|
+
export type DecafModelRoute = {
|
|
9
|
+
path: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
apiProperties: DecafApiProperties[];
|
|
12
|
+
getPK: (...args: Array<string | number>) => string;
|
|
13
|
+
};
|
|
8
14
|
export type DecafParamProps = {
|
|
9
15
|
original: Record<string, any>;
|
|
10
16
|
ordered: any[];
|
package/lib/esm/constants.d.ts
CHANGED
|
@@ -2,3 +2,6 @@ export declare const DECAF_MODULE_OPTIONS = "DecafModuleOptions";
|
|
|
2
2
|
export declare const DECAF_ADAPTER_ID = "DecafAdapter";
|
|
3
3
|
export declare const DECAF_HANDLERS: unique symbol;
|
|
4
4
|
export declare const DECAF_ADAPTER_OPTIONS: unique symbol;
|
|
5
|
+
export declare const AUTH_HANDLER: unique symbol;
|
|
6
|
+
export declare const AUTH_META_KEY = "auth:meta";
|
|
7
|
+
export declare const AuthRole = "AuthRole";
|
package/lib/esm/constants.js
CHANGED
|
@@ -2,4 +2,7 @@ export const DECAF_MODULE_OPTIONS = "DecafModuleOptions";
|
|
|
2
2
|
export const DECAF_ADAPTER_ID = "DecafAdapter";
|
|
3
3
|
export const DECAF_HANDLERS = Symbol("DecafHandlers");
|
|
4
4
|
export const DECAF_ADAPTER_OPTIONS = Symbol("DecafAdapterForOptions");
|
|
5
|
+
export const AUTH_HANDLER = Symbol("AUTH_HANDLER");
|
|
6
|
+
export const AUTH_META_KEY = "auth:meta";
|
|
7
|
+
export const AuthRole = "AuthRole";
|
|
5
8
|
//# 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;AAE/C,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,wBAAwB,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;AAEtE,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AAEzC,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC"}
|
|
@@ -2,5 +2,6 @@ import { DynamicModule, Type } from "@nestjs/common";
|
|
|
2
2
|
import { type DecafRequestHandler } from "../types";
|
|
3
3
|
export declare class DecafModelModule {
|
|
4
4
|
private static readonly log;
|
|
5
|
+
private static createModelServices;
|
|
5
6
|
static forRoot(flavour: string, handlers?: Type<DecafRequestHandler>[]): DynamicModule;
|
|
6
7
|
}
|
|
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
var DecafModelModule_1;
|
|
8
8
|
import { Module } from "@nestjs/common";
|
|
9
|
-
import { Adapter } from "@decaf-ts/core";
|
|
9
|
+
import { Adapter, ModelService } from "@decaf-ts/core";
|
|
10
10
|
import { Logging } from "@decaf-ts/logging";
|
|
11
11
|
import { FromModelController } from "./FromModelController.js";
|
|
12
12
|
import { DecafRequestHandlerInterceptor } from "./../interceptors/index.js";
|
|
@@ -16,10 +16,17 @@ import { DECAF_HANDLERS } from "./../constants.js";
|
|
|
16
16
|
let DecafModelModule = class DecafModelModule {
|
|
17
17
|
static { DecafModelModule_1 = this; }
|
|
18
18
|
static { this.log = Logging.for(DecafModelModule_1.name); }
|
|
19
|
+
static createModelServices(models) {
|
|
20
|
+
return models.map((model) => ({
|
|
21
|
+
provide: `${model.name}Service`,
|
|
22
|
+
useFactory: () => ModelService.forModel(model),
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
19
25
|
static forRoot(flavour, handlers = []) {
|
|
20
26
|
const log = this.log.for(this.forRoot);
|
|
21
27
|
log.info(`Generating controllers for flavour...`);
|
|
22
28
|
const trackedModels = Adapter.models(flavour);
|
|
29
|
+
const modelServices = this.createModelServices(trackedModels);
|
|
23
30
|
const controllers = trackedModels.map(FromModelController.create);
|
|
24
31
|
log.info(`Generated ${controllers.length} controllers`);
|
|
25
32
|
return {
|
|
@@ -41,6 +48,7 @@ let DecafModelModule = class DecafModelModule {
|
|
|
41
48
|
provide: APP_INTERCEPTOR,
|
|
42
49
|
useClass: DecafRequestHandlerInterceptor,
|
|
43
50
|
},
|
|
51
|
+
...modelServices,
|
|
44
52
|
],
|
|
45
53
|
};
|
|
46
54
|
}
|
|
@@ -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,EAAkB,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAW,MAAM,gBAAgB,CAAC;AAChE,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;IAEzD,MAAM,CAAC,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7CU,gBAAgB;IAD5B,MAAM,CAAC,EAAE,CAAC;GACE,gBAAgB,CA8C5B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import type { DecafModelRoute } from "./decorators";
|
|
2
3
|
/**
|
|
3
4
|
* @description
|
|
4
5
|
* Factory and utilities for generating dynamic NestJS controllers from Decaf {@link Model} definitions.
|
|
@@ -51,14 +52,5 @@ import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
|
51
52
|
export declare class FromModelController {
|
|
52
53
|
private static readonly log;
|
|
53
54
|
static create<T extends Model<any>>(ModelClazz: ModelConstructor<T>): any;
|
|
54
|
-
static getRouteParametersFromModel<T extends Model<any>>(ModelClazz: ModelConstructor<T>):
|
|
55
|
-
description: string | undefined;
|
|
56
|
-
apiProperties: {
|
|
57
|
-
name: any;
|
|
58
|
-
description: string | undefined;
|
|
59
|
-
required: boolean;
|
|
60
|
-
type: StringConstructor;
|
|
61
|
-
}[];
|
|
62
|
-
path: string;
|
|
63
|
-
};
|
|
55
|
+
static getRouteParametersFromModel<T extends Model<any>>(ModelClazz: ModelConstructor<T>): DecafModelRoute;
|
|
64
56
|
}
|