@decaf-ts/for-nest 0.1.4 → 0.1.6
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/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 -25
- 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/types.d.ts +7 -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 +44 -27
- 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/types.d.ts +7 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- 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 +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- 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 +1 -1
- package/package.json +5 -2
|
@@ -80,7 +80,7 @@ class FromModelController {
|
|
|
80
80
|
const routePath = (0, logging_1.toKebabCase)(tableName);
|
|
81
81
|
const modelClazzName = ModelClazz.name;
|
|
82
82
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
-
const { description, apiProperties, path } = FromModelController.getRouteParametersFromModel(ModelClazz);
|
|
83
|
+
const { description, getPK, apiProperties, path } = FromModelController.getRouteParametersFromModel(ModelClazz);
|
|
84
84
|
log.debug(`Creating controller for model: ${modelClazzName}`);
|
|
85
85
|
let DynamicModelController = class DynamicModelController extends logging_1.LoggedClass {
|
|
86
86
|
constructor(clientContext) {
|
|
@@ -89,20 +89,22 @@ class FromModelController {
|
|
|
89
89
|
this.pk = decorator_validation_1.Model.pk(ModelClazz);
|
|
90
90
|
log.info(`Registering dynamic controller for model: ${modelClazzName} route: /${routePath}`);
|
|
91
91
|
}
|
|
92
|
-
get
|
|
93
|
-
if (!this.
|
|
94
|
-
this.
|
|
92
|
+
get persistence() {
|
|
93
|
+
if (!this._persistence)
|
|
94
|
+
this._persistence =
|
|
95
|
+
core_1.ModelService.getService(ModelClazz) ||
|
|
96
|
+
core_1.Repository.forModel(ModelClazz);
|
|
95
97
|
const adapterOptions = this.clientContext.get(constants_1.DECAF_ADAPTER_OPTIONS);
|
|
96
98
|
if (adapterOptions)
|
|
97
|
-
return this.
|
|
98
|
-
return this.
|
|
99
|
+
return this._persistence.for(adapterOptions);
|
|
100
|
+
return this._persistence;
|
|
99
101
|
}
|
|
100
102
|
async create(data) {
|
|
101
103
|
const log = this.log.for(this.create);
|
|
102
104
|
log.verbose(`creating new ${modelClazzName}`);
|
|
103
105
|
let created;
|
|
104
106
|
try {
|
|
105
|
-
created = await this.
|
|
107
|
+
created = await this.persistence.create(data);
|
|
106
108
|
}
|
|
107
109
|
catch (e) {
|
|
108
110
|
log.error(`Failed to create new ${modelClazzName}`, e);
|
|
@@ -111,13 +113,15 @@ class FromModelController {
|
|
|
111
113
|
log.info(`created new ${modelClazzName} with id ${created[this.pk]}`);
|
|
112
114
|
return created;
|
|
113
115
|
}
|
|
114
|
-
async read(
|
|
115
|
-
const
|
|
116
|
+
async read(routeParams) {
|
|
117
|
+
const id = getPK(...routeParams.ordered);
|
|
118
|
+
if (typeof id === "undefined")
|
|
119
|
+
throw new db_decorators_1.ValidationError(`No ${this.pk} provided`);
|
|
116
120
|
const log = this.log.for(this.read);
|
|
117
121
|
let read;
|
|
118
122
|
try {
|
|
119
123
|
log.debug(`reading ${modelClazzName} with ${this.pk} ${id}`);
|
|
120
|
-
read = await this.
|
|
124
|
+
read = await this.persistence.read(id);
|
|
121
125
|
}
|
|
122
126
|
catch (e) {
|
|
123
127
|
log.error(`Failed to read ${modelClazzName} with id ${id}`, e);
|
|
@@ -131,7 +135,8 @@ class FromModelController {
|
|
|
131
135
|
let results;
|
|
132
136
|
try {
|
|
133
137
|
log.debug(`Querying ${modelClazzName} using method "${method}"`);
|
|
134
|
-
|
|
138
|
+
const args = [method];
|
|
139
|
+
results = await this.persistence.query(...args);
|
|
135
140
|
}
|
|
136
141
|
catch (e) {
|
|
137
142
|
log.error(`Failed to query ${modelClazzName} using method "${method}"`, e);
|
|
@@ -142,10 +147,16 @@ class FromModelController {
|
|
|
142
147
|
}
|
|
143
148
|
async update(routeParams, body) {
|
|
144
149
|
const log = this.log.for(this.update);
|
|
150
|
+
const id = getPK(...routeParams.ordered);
|
|
151
|
+
if (typeof id === "undefined")
|
|
152
|
+
throw new db_decorators_1.ValidationError(`No ${this.pk} provided`);
|
|
145
153
|
let updated;
|
|
146
154
|
try {
|
|
147
|
-
log.info(`updating ${modelClazzName} with ${this.pk} ${
|
|
148
|
-
updated = await this.
|
|
155
|
+
log.info(`updating ${modelClazzName} with ${this.pk} ${id}`);
|
|
156
|
+
updated = await this.persistence.update(new ModelClazz({
|
|
157
|
+
...body,
|
|
158
|
+
[this.pk]: id,
|
|
159
|
+
}));
|
|
149
160
|
}
|
|
150
161
|
catch (e) {
|
|
151
162
|
log.error(e);
|
|
@@ -155,17 +166,20 @@ class FromModelController {
|
|
|
155
166
|
}
|
|
156
167
|
async delete(routeParams) {
|
|
157
168
|
const log = this.log.for(this.delete);
|
|
158
|
-
|
|
169
|
+
const id = getPK(...routeParams.ordered);
|
|
170
|
+
if (typeof id === "undefined")
|
|
171
|
+
throw new db_decorators_1.ValidationError(`No ${this.pk} provided`);
|
|
172
|
+
let del;
|
|
159
173
|
try {
|
|
160
|
-
log.debug(`deleting ${modelClazzName} with ${this.pk} ${
|
|
161
|
-
|
|
174
|
+
log.debug(`deleting ${modelClazzName} with ${this.pk} ${id}`);
|
|
175
|
+
del = await this.persistence.delete(id);
|
|
162
176
|
}
|
|
163
177
|
catch (e) {
|
|
164
|
-
log.error(`Failed to delete ${modelClazzName} with id ${
|
|
178
|
+
log.error(`Failed to delete ${modelClazzName} with id ${id}`, e);
|
|
165
179
|
throw e;
|
|
166
180
|
}
|
|
167
|
-
log.info(`deleted ${modelClazzName} with id ${
|
|
168
|
-
return
|
|
181
|
+
log.info(`deleted ${modelClazzName} with id ${id}`);
|
|
182
|
+
return del;
|
|
169
183
|
}
|
|
170
184
|
};
|
|
171
185
|
__decorate([
|
|
@@ -197,7 +211,7 @@ class FromModelController {
|
|
|
197
211
|
(0, swagger_1.ApiNotFoundResponse)({
|
|
198
212
|
description: `No ${modelClazzName} record matches the provided identifier.`,
|
|
199
213
|
}),
|
|
200
|
-
__param(0, (0,
|
|
214
|
+
__param(0, (0, decorators_1.DecafParams)(apiProperties)),
|
|
201
215
|
__metadata("design:type", Function),
|
|
202
216
|
__metadata("design:paramtypes", [Object]),
|
|
203
217
|
__metadata("design:returntype", Promise)
|
|
@@ -264,11 +278,9 @@ class FromModelController {
|
|
|
264
278
|
return DynamicModelController;
|
|
265
279
|
}
|
|
266
280
|
static getRouteParametersFromModel(ModelClazz) {
|
|
267
|
-
const instance = new ModelClazz({});
|
|
268
281
|
const pk = decorator_validation_1.Model.pk(ModelClazz);
|
|
269
|
-
const
|
|
270
|
-
const composedKeys =
|
|
271
|
-
[];
|
|
282
|
+
const composed = decoration_1.Metadata.get(ModelClazz, decoration_1.Metadata.key(db_decorators_1.DBKeys.COMPOSED, pk));
|
|
283
|
+
const composedKeys = composed?.args ?? [];
|
|
272
284
|
const keysToReturn = Array.isArray(composedKeys) && composedKeys.length > 0
|
|
273
285
|
? [...composedKeys]
|
|
274
286
|
: [pk];
|
|
@@ -284,7 +296,12 @@ class FromModelController {
|
|
|
284
296
|
type: String,
|
|
285
297
|
};
|
|
286
298
|
});
|
|
287
|
-
return {
|
|
299
|
+
return {
|
|
300
|
+
path,
|
|
301
|
+
description,
|
|
302
|
+
apiProperties,
|
|
303
|
+
getPK: (...params) => composed?.separator ? params.join(composed.separator) : params.join(""),
|
|
304
|
+
};
|
|
288
305
|
}
|
|
289
306
|
}
|
|
290
307
|
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;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,C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CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;SAC1E,CAAC;IACJ,CAAC;;AArPH,kDAsPC"}
|
|
@@ -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"}
|
|
@@ -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[];
|
|
@@ -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,mBAAmB,CAAC,MAAa;QAC9C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC5B,OAAO,EAAE,GAAG,KAAK,CAAC,IAAI,SAAS;YAC/B,UAAU,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC;SAC/C,CAAC,CAAC,CAAC;IACN,CAAC;IAED,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,aAAa,GAAG,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;QAC9D,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;gBACD,GAAG,aAAa;aACjB;SACF,CAAC;IACJ,CAAC;;AA7CU,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
|
}
|
|
@@ -12,10 +12,10 @@ 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
|
+
import { ModelService, Repository } from "@decaf-ts/core";
|
|
16
16
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
17
17
|
import { LoggedClass, Logging, toKebabCase } from "@decaf-ts/logging";
|
|
18
|
-
import { DBKeys } from "@decaf-ts/db-decorators";
|
|
18
|
+
import { DBKeys, ValidationError } from "@decaf-ts/db-decorators";
|
|
19
19
|
import { Metadata } from "@decaf-ts/decoration";
|
|
20
20
|
import { ApiOperationFromModel, ApiParamsFromModel, DecafParams, } from "./decorators/index.js";
|
|
21
21
|
import { DecafRequestContext } from "./../request/index.js";
|
|
@@ -77,7 +77,7 @@ export class FromModelController {
|
|
|
77
77
|
const routePath = toKebabCase(tableName);
|
|
78
78
|
const modelClazzName = ModelClazz.name;
|
|
79
79
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
-
const { description, apiProperties, path } = FromModelController.getRouteParametersFromModel(ModelClazz);
|
|
80
|
+
const { description, getPK, apiProperties, path } = FromModelController.getRouteParametersFromModel(ModelClazz);
|
|
81
81
|
log.debug(`Creating controller for model: ${modelClazzName}`);
|
|
82
82
|
let DynamicModelController = class DynamicModelController extends LoggedClass {
|
|
83
83
|
constructor(clientContext) {
|
|
@@ -86,20 +86,22 @@ export class FromModelController {
|
|
|
86
86
|
this.pk = Model.pk(ModelClazz);
|
|
87
87
|
log.info(`Registering dynamic controller for model: ${modelClazzName} route: /${routePath}`);
|
|
88
88
|
}
|
|
89
|
-
get
|
|
90
|
-
if (!this.
|
|
91
|
-
this.
|
|
89
|
+
get persistence() {
|
|
90
|
+
if (!this._persistence)
|
|
91
|
+
this._persistence =
|
|
92
|
+
ModelService.getService(ModelClazz) ||
|
|
93
|
+
Repository.forModel(ModelClazz);
|
|
92
94
|
const adapterOptions = this.clientContext.get(DECAF_ADAPTER_OPTIONS);
|
|
93
95
|
if (adapterOptions)
|
|
94
|
-
return this.
|
|
95
|
-
return this.
|
|
96
|
+
return this._persistence.for(adapterOptions);
|
|
97
|
+
return this._persistence;
|
|
96
98
|
}
|
|
97
99
|
async create(data) {
|
|
98
100
|
const log = this.log.for(this.create);
|
|
99
101
|
log.verbose(`creating new ${modelClazzName}`);
|
|
100
102
|
let created;
|
|
101
103
|
try {
|
|
102
|
-
created = await this.
|
|
104
|
+
created = await this.persistence.create(data);
|
|
103
105
|
}
|
|
104
106
|
catch (e) {
|
|
105
107
|
log.error(`Failed to create new ${modelClazzName}`, e);
|
|
@@ -108,13 +110,15 @@ export class FromModelController {
|
|
|
108
110
|
log.info(`created new ${modelClazzName} with id ${created[this.pk]}`);
|
|
109
111
|
return created;
|
|
110
112
|
}
|
|
111
|
-
async read(
|
|
112
|
-
const
|
|
113
|
+
async read(routeParams) {
|
|
114
|
+
const id = getPK(...routeParams.ordered);
|
|
115
|
+
if (typeof id === "undefined")
|
|
116
|
+
throw new ValidationError(`No ${this.pk} provided`);
|
|
113
117
|
const log = this.log.for(this.read);
|
|
114
118
|
let read;
|
|
115
119
|
try {
|
|
116
120
|
log.debug(`reading ${modelClazzName} with ${this.pk} ${id}`);
|
|
117
|
-
read = await this.
|
|
121
|
+
read = await this.persistence.read(id);
|
|
118
122
|
}
|
|
119
123
|
catch (e) {
|
|
120
124
|
log.error(`Failed to read ${modelClazzName} with id ${id}`, e);
|
|
@@ -128,7 +132,8 @@ export class FromModelController {
|
|
|
128
132
|
let results;
|
|
129
133
|
try {
|
|
130
134
|
log.debug(`Querying ${modelClazzName} using method "${method}"`);
|
|
131
|
-
|
|
135
|
+
const args = [method];
|
|
136
|
+
results = await this.persistence.query(...args);
|
|
132
137
|
}
|
|
133
138
|
catch (e) {
|
|
134
139
|
log.error(`Failed to query ${modelClazzName} using method "${method}"`, e);
|
|
@@ -139,10 +144,16 @@ export class FromModelController {
|
|
|
139
144
|
}
|
|
140
145
|
async update(routeParams, body) {
|
|
141
146
|
const log = this.log.for(this.update);
|
|
147
|
+
const id = getPK(...routeParams.ordered);
|
|
148
|
+
if (typeof id === "undefined")
|
|
149
|
+
throw new ValidationError(`No ${this.pk} provided`);
|
|
142
150
|
let updated;
|
|
143
151
|
try {
|
|
144
|
-
log.info(`updating ${modelClazzName} with ${this.pk} ${
|
|
145
|
-
updated = await this.
|
|
152
|
+
log.info(`updating ${modelClazzName} with ${this.pk} ${id}`);
|
|
153
|
+
updated = await this.persistence.update(new ModelClazz({
|
|
154
|
+
...body,
|
|
155
|
+
[this.pk]: id,
|
|
156
|
+
}));
|
|
146
157
|
}
|
|
147
158
|
catch (e) {
|
|
148
159
|
log.error(e);
|
|
@@ -152,17 +163,20 @@ export class FromModelController {
|
|
|
152
163
|
}
|
|
153
164
|
async delete(routeParams) {
|
|
154
165
|
const log = this.log.for(this.delete);
|
|
155
|
-
|
|
166
|
+
const id = getPK(...routeParams.ordered);
|
|
167
|
+
if (typeof id === "undefined")
|
|
168
|
+
throw new ValidationError(`No ${this.pk} provided`);
|
|
169
|
+
let del;
|
|
156
170
|
try {
|
|
157
|
-
log.debug(`deleting ${modelClazzName} with ${this.pk} ${
|
|
158
|
-
|
|
171
|
+
log.debug(`deleting ${modelClazzName} with ${this.pk} ${id}`);
|
|
172
|
+
del = await this.persistence.delete(id);
|
|
159
173
|
}
|
|
160
174
|
catch (e) {
|
|
161
|
-
log.error(`Failed to delete ${modelClazzName} with id ${
|
|
175
|
+
log.error(`Failed to delete ${modelClazzName} with id ${id}`, e);
|
|
162
176
|
throw e;
|
|
163
177
|
}
|
|
164
|
-
log.info(`deleted ${modelClazzName} with id ${
|
|
165
|
-
return
|
|
178
|
+
log.info(`deleted ${modelClazzName} with id ${id}`);
|
|
179
|
+
return del;
|
|
166
180
|
}
|
|
167
181
|
};
|
|
168
182
|
__decorate([
|
|
@@ -194,7 +208,7 @@ export class FromModelController {
|
|
|
194
208
|
ApiNotFoundResponse({
|
|
195
209
|
description: `No ${modelClazzName} record matches the provided identifier.`,
|
|
196
210
|
}),
|
|
197
|
-
__param(0,
|
|
211
|
+
__param(0, DecafParams(apiProperties)),
|
|
198
212
|
__metadata("design:type", Function),
|
|
199
213
|
__metadata("design:paramtypes", [Object]),
|
|
200
214
|
__metadata("design:returntype", Promise)
|
|
@@ -261,11 +275,9 @@ export class FromModelController {
|
|
|
261
275
|
return DynamicModelController;
|
|
262
276
|
}
|
|
263
277
|
static getRouteParametersFromModel(ModelClazz) {
|
|
264
|
-
const instance = new ModelClazz({});
|
|
265
278
|
const pk = Model.pk(ModelClazz);
|
|
266
|
-
const
|
|
267
|
-
const composedKeys =
|
|
268
|
-
[];
|
|
279
|
+
const composed = Metadata.get(ModelClazz, Metadata.key(DBKeys.COMPOSED, pk));
|
|
280
|
+
const composedKeys = composed?.args ?? [];
|
|
269
281
|
const keysToReturn = Array.isArray(composedKeys) && composedKeys.length > 0
|
|
270
282
|
? [...composedKeys]
|
|
271
283
|
: [pk];
|
|
@@ -281,7 +293,12 @@ export class FromModelController {
|
|
|
281
293
|
type: String,
|
|
282
294
|
};
|
|
283
295
|
});
|
|
284
|
-
return {
|
|
296
|
+
return {
|
|
297
|
+
path,
|
|
298
|
+
description,
|
|
299
|
+
apiProperties,
|
|
300
|
+
getPK: (...params) => composed?.separator ? params.join(composed.separator) : params.join(""),
|
|
301
|
+
};
|
|
285
302
|
}
|
|
286
303
|
}
|
|
287
304
|
//# sourceMappingURL=FromModelController.js.map
|
|
@@ -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;AACzB,OAAO,EAAQ,UAAU,EAAE,MAAM,gBAAgB,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,EAAE,YAAY,EAAQ,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAoB,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAMhD,OAAO,EACL,qBAAqB,EACrB,kBAAkB,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AC;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"}
|
|
@@ -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":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG1D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAChC,
|
|
1
|
+
{"version":3,"file":"ApiParamsFromModel.js","sourceRoot":"","sources":["../../../../src/decaf-model/decorators/ApiParamsFromModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG1D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA8B,EAAE;IAEhC,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACjC,WAAW,CAAC;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,eAAe,CAAC,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":"AAAA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"DecafParams.js","sourceRoot":"","sources":["../../../../src/decaf-model/decorators/DecafParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,gBAAgB,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,MAAM,aAAa,GAAG,oBAAoB,CACxC,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,MAAM,UAAU,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"}
|
|
@@ -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/index.d.ts
CHANGED