@buka/nestjs-kit 3.0.1
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/.czrc +3 -0
- package/.vscode/tasks.json +21 -0
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/coverage/cobertura-coverage.xml +1173 -0
- package/dist/index.d.mts +311 -0
- package/dist/index.d.ts +311 -0
- package/dist/index.js +2553 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2478 -0
- package/dist/index.mjs.map +1 -0
- package/eslint.config.mjs +18 -0
- package/jest.config.cts +23 -0
- package/package.json +100 -0
- package/pnpm-workspace.yaml +4 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2478 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/mikro-orm/models/base-entity.ts
|
|
5
|
+
import { BigIntType as BigIntType2, PrimaryKey, PrimaryKeyProp } from "@mikro-orm/core";
|
|
6
|
+
import { ApiProperty as ApiProperty3 } from "@nestjs/swagger";
|
|
7
|
+
import { IsNumberString } from "class-validator";
|
|
8
|
+
|
|
9
|
+
// src/mikro-orm/models/timestamped-entity.ts
|
|
10
|
+
import { Config, OptionalProps } from "@mikro-orm/core";
|
|
11
|
+
|
|
12
|
+
// src/mikro-orm/decorators/entity-property.decorator.ts
|
|
13
|
+
import { Property as OrmProperty } from "@mikro-orm/core";
|
|
14
|
+
|
|
15
|
+
// src/mikro-orm/decorators/api-entity-property.decorator.ts
|
|
16
|
+
import { ApiHideProperty, getSchemaPath } from "@nestjs/swagger";
|
|
17
|
+
import { MetadataStorage as MetadataStorage2, ReferenceKind } from "@mikro-orm/core";
|
|
18
|
+
|
|
19
|
+
// src/mikro-orm/decorators/api-scalar-entity-property.decorator.ts
|
|
20
|
+
import { BigIntType } from "@mikro-orm/core";
|
|
21
|
+
import { applyDecorators as applyDecorators3 } from "@nestjs/common";
|
|
22
|
+
import { IsBoolean, IsCurrency, IsInt, IsISO8601, IsNumber, IsString, MaxLength, MinLength } from "class-validator";
|
|
23
|
+
|
|
24
|
+
// src/decorators/nested-property.decorator.ts
|
|
25
|
+
import * as R2 from "ramda";
|
|
26
|
+
import { applyDecorators } from "@nestjs/common";
|
|
27
|
+
import { Type as ClassType } from "class-transformer";
|
|
28
|
+
import { IsNotEmpty, ValidateNested } from "class-validator";
|
|
29
|
+
|
|
30
|
+
// src/decorators/model/model.register.ts
|
|
31
|
+
import * as R from "ramda";
|
|
32
|
+
var MODEL_METADATA_KEY = "buka:model";
|
|
33
|
+
var PROPERTY_METADATA_KEY = "buka:property";
|
|
34
|
+
var ModelRegister = class {
|
|
35
|
+
static {
|
|
36
|
+
__name(this, "ModelRegister");
|
|
37
|
+
}
|
|
38
|
+
static setModel(target, metadata) {
|
|
39
|
+
Reflect.defineMetadata(MODEL_METADATA_KEY, metadata, target);
|
|
40
|
+
}
|
|
41
|
+
static getModel(target) {
|
|
42
|
+
return Reflect.getMetadata(MODEL_METADATA_KEY, target);
|
|
43
|
+
}
|
|
44
|
+
static setProperty(target, propertyName, metadata) {
|
|
45
|
+
Reflect.defineMetadata(PROPERTY_METADATA_KEY, metadata, target.prototype, propertyName);
|
|
46
|
+
}
|
|
47
|
+
static getProperty(target, propertyName) {
|
|
48
|
+
return Reflect.getMetadata(PROPERTY_METADATA_KEY, target.prototype, propertyName);
|
|
49
|
+
}
|
|
50
|
+
static copyProperty(source, target, propertyName) {
|
|
51
|
+
const metadata = this.getProperty(source, propertyName);
|
|
52
|
+
if (metadata) {
|
|
53
|
+
const modelMetadata = this.addModel(target);
|
|
54
|
+
if (!modelMetadata.propertyKeys.includes(propertyName)) {
|
|
55
|
+
modelMetadata.propertyKeys.push(propertyName);
|
|
56
|
+
}
|
|
57
|
+
this.setProperty(target, propertyName, metadata);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
static addModel(target, kind = "model") {
|
|
61
|
+
const metadata = this.getModel(target);
|
|
62
|
+
if (!metadata) {
|
|
63
|
+
const metadata2 = {
|
|
64
|
+
kind,
|
|
65
|
+
propertyKeys: []
|
|
66
|
+
};
|
|
67
|
+
this.setModel(target, metadata2);
|
|
68
|
+
return metadata2;
|
|
69
|
+
}
|
|
70
|
+
return metadata;
|
|
71
|
+
}
|
|
72
|
+
static addProperty(target, propertyName, metadata = {}) {
|
|
73
|
+
const modelMetadata = this.addModel(target);
|
|
74
|
+
if (!modelMetadata.propertyKeys.includes(propertyName)) {
|
|
75
|
+
modelMetadata.propertyKeys.push(propertyName);
|
|
76
|
+
}
|
|
77
|
+
const propertyMetadata = {
|
|
78
|
+
type() {
|
|
79
|
+
return Reflect.getMetadata("design:type", target.prototype, propertyName);
|
|
80
|
+
},
|
|
81
|
+
...this.getProperty(target, propertyName) || {},
|
|
82
|
+
...R.omit([
|
|
83
|
+
"schema"
|
|
84
|
+
], metadata)
|
|
85
|
+
};
|
|
86
|
+
this.setProperty(target, propertyName, propertyMetadata);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 判断是否为已注册的 Model
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const isModel = ModelRegister.isModel(Class.prototype)
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
static isModel(target) {
|
|
97
|
+
return !!this.getModel(target);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 获取 Model 的所有属性
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const properties = ModelRegister.getProperties(Class.prototype)
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
static getModelPropertyKeys(target) {
|
|
108
|
+
const metadata = this.getModel(target);
|
|
109
|
+
return metadata ? metadata.propertyKeys : [];
|
|
110
|
+
}
|
|
111
|
+
static getProperties(target) {
|
|
112
|
+
const propertyKeys = this.getModelPropertyKeys(target);
|
|
113
|
+
return propertyKeys.map((propertyKey) => this.getProperty(target, propertyKey)).filter((property) => !!property);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/decorators/model/model.decorator.ts
|
|
118
|
+
function Model() {
|
|
119
|
+
return (target) => {
|
|
120
|
+
ModelRegister.addModel(target);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
__name(Model, "Model");
|
|
124
|
+
|
|
125
|
+
// src/exceptions/exceptions.ts
|
|
126
|
+
import { CustomError } from "ts-custom-error";
|
|
127
|
+
var Exception = class extends CustomError {
|
|
128
|
+
static {
|
|
129
|
+
__name(this, "Exception");
|
|
130
|
+
}
|
|
131
|
+
constructor(message) {
|
|
132
|
+
super(`[@buka/nestjs] ${message}`);
|
|
133
|
+
Object.defineProperty(this, "name", {
|
|
134
|
+
value: "Exception"
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// src/exceptions/type-exception.ts
|
|
140
|
+
var TypeException = class extends Exception {
|
|
141
|
+
static {
|
|
142
|
+
__name(this, "TypeException");
|
|
143
|
+
}
|
|
144
|
+
constructor(message) {
|
|
145
|
+
super(message);
|
|
146
|
+
Object.defineProperty(this, "name", {
|
|
147
|
+
value: "TypeException"
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/decorators/model/property.decorator.ts
|
|
153
|
+
import { IsOptional } from "class-validator";
|
|
154
|
+
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
|
155
|
+
function Property(options) {
|
|
156
|
+
return (target, propertyKey) => {
|
|
157
|
+
if (!("constructor" in target)) {
|
|
158
|
+
throw new TypeException("@Property decorator can only be applied to class properties.");
|
|
159
|
+
}
|
|
160
|
+
if (options?.optional) {
|
|
161
|
+
IsOptional()(target, propertyKey);
|
|
162
|
+
}
|
|
163
|
+
if (options?.schema) {
|
|
164
|
+
if (options?.optional) {
|
|
165
|
+
ApiPropertyOptional(options.schema)(target, propertyKey);
|
|
166
|
+
} else {
|
|
167
|
+
ApiProperty(options.schema)(target, propertyKey);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
ModelRegister.addProperty(target.constructor, propertyKey, options);
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
__name(Property, "Property");
|
|
174
|
+
|
|
175
|
+
// src/decorators/model/relation.decorator.ts
|
|
176
|
+
var RELATION_METADATA_KEY = "buka:relation";
|
|
177
|
+
function Relation(metadata) {
|
|
178
|
+
return (target, propertyKey) => {
|
|
179
|
+
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
180
|
+
relation: metadata
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
__name(Relation, "Relation");
|
|
185
|
+
|
|
186
|
+
// src/decorators/model/nested.decorator.ts
|
|
187
|
+
function Nested(options) {
|
|
188
|
+
return (target, propertyKey) => {
|
|
189
|
+
Property({
|
|
190
|
+
kind: "nested",
|
|
191
|
+
...options
|
|
192
|
+
})(target, propertyKey);
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
__name(Nested, "Nested");
|
|
196
|
+
|
|
197
|
+
// src/decorators/model/list.decorator.ts
|
|
198
|
+
function List(options) {
|
|
199
|
+
return (target, propertyKey) => {
|
|
200
|
+
Property({
|
|
201
|
+
kind: "list",
|
|
202
|
+
...options
|
|
203
|
+
})(target, propertyKey);
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
__name(List, "List");
|
|
207
|
+
|
|
208
|
+
// src/decorators/nested-property.decorator.ts
|
|
209
|
+
function NestedProperty(type, options = {}) {
|
|
210
|
+
const decorators = [
|
|
211
|
+
ValidateNested({
|
|
212
|
+
each: !!options.each
|
|
213
|
+
}),
|
|
214
|
+
ClassType(type)
|
|
215
|
+
];
|
|
216
|
+
const schema = options.schema || {
|
|
217
|
+
type: /* @__PURE__ */ __name(() => type(), "type")
|
|
218
|
+
};
|
|
219
|
+
const propertyMetadata = R2.pick([
|
|
220
|
+
"relation",
|
|
221
|
+
"optional"
|
|
222
|
+
], options);
|
|
223
|
+
if (options.each) {
|
|
224
|
+
decorators.push(List({
|
|
225
|
+
type,
|
|
226
|
+
schema,
|
|
227
|
+
...propertyMetadata
|
|
228
|
+
}));
|
|
229
|
+
} else {
|
|
230
|
+
decorators.push(Nested({
|
|
231
|
+
type,
|
|
232
|
+
schema,
|
|
233
|
+
...propertyMetadata
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
if (!options.optional) {
|
|
237
|
+
decorators.push(...[
|
|
238
|
+
// 如果不添加 IsNotEmpty,ValidateNested 在没有 IsOptional 的情况下也会允许 undefined 值通过验证
|
|
239
|
+
// https://github.com/typestack/class-validator/issues/717
|
|
240
|
+
IsNotEmpty({
|
|
241
|
+
each: options.each,
|
|
242
|
+
message: "$property is required"
|
|
243
|
+
})
|
|
244
|
+
]);
|
|
245
|
+
}
|
|
246
|
+
return applyDecorators(...decorators);
|
|
247
|
+
}
|
|
248
|
+
__name(NestedProperty, "NestedProperty");
|
|
249
|
+
|
|
250
|
+
// src/decorators/reference-property.decorator.ts
|
|
251
|
+
import { applyDecorators as applyDecorators2 } from "@nestjs/common";
|
|
252
|
+
import { Allow } from "class-validator";
|
|
253
|
+
var ReferencePropertiesMetadataKey = "buka:reference-properties";
|
|
254
|
+
function ReferenceProperty(entity) {
|
|
255
|
+
return applyDecorators2(Allow(), NestedProperty(() => EntityRefType(entity()), {
|
|
256
|
+
relation: {
|
|
257
|
+
kind: "1:1",
|
|
258
|
+
type: /* @__PURE__ */ __name(() => entity(), "type")
|
|
259
|
+
}
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
__name(ReferenceProperty, "ReferenceProperty");
|
|
263
|
+
|
|
264
|
+
// src/decorators/class-validator/has-any-key.ts
|
|
265
|
+
import { registerDecorator } from "class-validator";
|
|
266
|
+
var HAS_ANY_KEY = "hasAnyKey";
|
|
267
|
+
function HasAnyKey(keys, validationOptions) {
|
|
268
|
+
return function(object, propertyName) {
|
|
269
|
+
registerDecorator({
|
|
270
|
+
name: HAS_ANY_KEY,
|
|
271
|
+
target: object.constructor,
|
|
272
|
+
propertyName,
|
|
273
|
+
constraints: [
|
|
274
|
+
keys
|
|
275
|
+
],
|
|
276
|
+
options: validationOptions,
|
|
277
|
+
validator: {
|
|
278
|
+
validate(value) {
|
|
279
|
+
if (typeof value !== "object" || value === null) return false;
|
|
280
|
+
for (const key of keys) {
|
|
281
|
+
if (key in value) return true;
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
},
|
|
285
|
+
defaultMessage() {
|
|
286
|
+
return `$property must have at least one of the keys: ${keys.join(", ")}`;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
__name(HasAnyKey, "HasAnyKey");
|
|
293
|
+
|
|
294
|
+
// src/decorators/class-validator/match-json-schema.ts
|
|
295
|
+
import { registerDecorator as registerDecorator2 } from "class-validator";
|
|
296
|
+
import { validate } from "jsonschema";
|
|
297
|
+
var MATCH_JSON_SCHEMA = "matchJsonSchema";
|
|
298
|
+
function MatchJsonSchema(schema, validationOptions) {
|
|
299
|
+
return function(object, propertyName) {
|
|
300
|
+
registerDecorator2({
|
|
301
|
+
name: MATCH_JSON_SCHEMA,
|
|
302
|
+
target: object.constructor,
|
|
303
|
+
propertyName,
|
|
304
|
+
constraints: [
|
|
305
|
+
schema
|
|
306
|
+
],
|
|
307
|
+
options: validationOptions,
|
|
308
|
+
validator: {
|
|
309
|
+
validate(value, args) {
|
|
310
|
+
const [schema2] = args.constraints;
|
|
311
|
+
const results = validate(value, schema2);
|
|
312
|
+
return results.valid;
|
|
313
|
+
},
|
|
314
|
+
defaultMessage({ value, constraints }) {
|
|
315
|
+
return `${propertyName} must match the JSON schema`;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
__name(MatchJsonSchema, "MatchJsonSchema");
|
|
322
|
+
|
|
323
|
+
// src/decorators/page-query.ts
|
|
324
|
+
import { Query } from "@nestjs/common";
|
|
325
|
+
import { ApiQuery } from "@nestjs/swagger";
|
|
326
|
+
|
|
327
|
+
// src/pipes/page-query-validation.pipe.ts
|
|
328
|
+
import { BadRequestException, Injectable, InternalServerErrorException } from "@nestjs/common";
|
|
329
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
330
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
331
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
332
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
333
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
334
|
+
}
|
|
335
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
336
|
+
function _ts_metadata(k, v) {
|
|
337
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
338
|
+
}
|
|
339
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
340
|
+
var mixedOffsetAndCursorError = "Invalid page query: cannot mix offset-based and cursor-based pagination parameters.";
|
|
341
|
+
var mixedNextAndLastCursorError = "Invalid page query: cannot mix next and last cursor pagination parameters.";
|
|
342
|
+
var BukaPageQueryValidationPipe = class {
|
|
343
|
+
static {
|
|
344
|
+
__name(this, "BukaPageQueryValidationPipe");
|
|
345
|
+
}
|
|
346
|
+
options;
|
|
347
|
+
constructor(options = {
|
|
348
|
+
optional: false
|
|
349
|
+
}) {
|
|
350
|
+
this.options = options;
|
|
351
|
+
}
|
|
352
|
+
transform(value, metadata) {
|
|
353
|
+
if (metadata.type !== "query") {
|
|
354
|
+
throw new InternalServerErrorException("BukaPageQueryValidationPipe can only be used to validate query parameters.");
|
|
355
|
+
}
|
|
356
|
+
if (!value.page) {
|
|
357
|
+
if (this.options.optional) {
|
|
358
|
+
return value;
|
|
359
|
+
} else {
|
|
360
|
+
throw new BadRequestException("Missing required query parameter: page");
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const mode = this.options.mode;
|
|
364
|
+
if ((!mode || mode === "offset") && ("limit" in value.page || "offset" in value.page)) {
|
|
365
|
+
if ("after" in value.page || "first" in value.page || "before" in value.page || "last" in value.page) {
|
|
366
|
+
throw new BadRequestException(mixedOffsetAndCursorError);
|
|
367
|
+
}
|
|
368
|
+
const limit = parseInt(value.page.limit, 10);
|
|
369
|
+
const offset = parseInt(value.page.offset, 10);
|
|
370
|
+
if (isNaN(limit) || limit <= 0) {
|
|
371
|
+
throw new BadRequestException("Invalid page query: limit must be a positive integer.");
|
|
372
|
+
}
|
|
373
|
+
if (isNaN(offset) || offset < 0) {
|
|
374
|
+
throw new BadRequestException("Invalid page query: offset must be a non-negative integer.");
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
page: {
|
|
378
|
+
limit,
|
|
379
|
+
offset
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
if (!mode || mode === "cursor") {
|
|
384
|
+
if ("after" in value.page || "first" in value.page) {
|
|
385
|
+
if ("limit" in value.page || "offset" in value.page) {
|
|
386
|
+
throw new BadRequestException(mixedOffsetAndCursorError);
|
|
387
|
+
}
|
|
388
|
+
if ("before" in value.page || "last" in value.page) {
|
|
389
|
+
throw new BadRequestException(mixedNextAndLastCursorError);
|
|
390
|
+
}
|
|
391
|
+
const after = value.page.after;
|
|
392
|
+
const first = parseInt(value.page.first, 10);
|
|
393
|
+
if (typeof after !== "string") {
|
|
394
|
+
throw new BadRequestException("Invalid page query: after must be a string.");
|
|
395
|
+
}
|
|
396
|
+
if (isNaN(first) || first <= 0) {
|
|
397
|
+
throw new BadRequestException("Invalid page query: first must be a positive integer.");
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
page: {
|
|
401
|
+
after,
|
|
402
|
+
first
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
if ("before" in value.page || "last" in value.page) {
|
|
407
|
+
if ("limit" in value.page || "offset" in value.page) {
|
|
408
|
+
throw new BadRequestException(mixedOffsetAndCursorError);
|
|
409
|
+
}
|
|
410
|
+
if ("after" in value.page || "first" in value.page) {
|
|
411
|
+
throw new BadRequestException(mixedNextAndLastCursorError);
|
|
412
|
+
}
|
|
413
|
+
const before = value.page.before;
|
|
414
|
+
const last = parseInt(value.page.last, 10);
|
|
415
|
+
if (typeof before !== "string") {
|
|
416
|
+
throw new BadRequestException("Invalid page query: before must be a string.");
|
|
417
|
+
}
|
|
418
|
+
if (isNaN(last) || last <= 0) {
|
|
419
|
+
throw new BadRequestException("Invalid page query: last must be a positive integer.");
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
page: {
|
|
423
|
+
before,
|
|
424
|
+
last
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
throw new BadRequestException("Invalid page query: missing pagination parameters.");
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
BukaPageQueryValidationPipe = _ts_decorate([
|
|
433
|
+
Injectable(),
|
|
434
|
+
_ts_metadata("design:type", Function),
|
|
435
|
+
_ts_metadata("design:paramtypes", [
|
|
436
|
+
typeof BukaPageQueryValidationPipeOptions === "undefined" ? Object : BukaPageQueryValidationPipeOptions
|
|
437
|
+
])
|
|
438
|
+
], BukaPageQueryValidationPipe);
|
|
439
|
+
|
|
440
|
+
// src/decorators/page-query.ts
|
|
441
|
+
var OffsetPageSchema = {
|
|
442
|
+
type: "object",
|
|
443
|
+
properties: {
|
|
444
|
+
limit: {
|
|
445
|
+
type: "number"
|
|
446
|
+
},
|
|
447
|
+
offset: {
|
|
448
|
+
type: "number"
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
required: [
|
|
452
|
+
"limit",
|
|
453
|
+
"offset"
|
|
454
|
+
]
|
|
455
|
+
};
|
|
456
|
+
var NextCursorPageSchema = {
|
|
457
|
+
type: "object",
|
|
458
|
+
properties: {
|
|
459
|
+
after: {
|
|
460
|
+
type: "string"
|
|
461
|
+
},
|
|
462
|
+
first: {
|
|
463
|
+
type: "number"
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
required: [
|
|
467
|
+
"after",
|
|
468
|
+
"first"
|
|
469
|
+
]
|
|
470
|
+
};
|
|
471
|
+
var PreviousCursorPageSchema = {
|
|
472
|
+
type: "object",
|
|
473
|
+
properties: {
|
|
474
|
+
before: {
|
|
475
|
+
type: "string"
|
|
476
|
+
},
|
|
477
|
+
last: {
|
|
478
|
+
type: "number"
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
required: [
|
|
482
|
+
"before",
|
|
483
|
+
"last"
|
|
484
|
+
]
|
|
485
|
+
};
|
|
486
|
+
function PageQuery(mode) {
|
|
487
|
+
return (target, propertyKey, parameterIndex) => {
|
|
488
|
+
if (!propertyKey) {
|
|
489
|
+
throw new Error("@PageQuery decorator can only be used on method parameters.");
|
|
490
|
+
}
|
|
491
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, propertyKey);
|
|
492
|
+
if (mode === "offset") {
|
|
493
|
+
ApiQuery({
|
|
494
|
+
name: "page",
|
|
495
|
+
required: true,
|
|
496
|
+
schema: OffsetPageSchema
|
|
497
|
+
})(target, propertyKey, descriptor);
|
|
498
|
+
} else if (mode === "cursor") {
|
|
499
|
+
ApiQuery({
|
|
500
|
+
name: "page",
|
|
501
|
+
required: true,
|
|
502
|
+
schema: {
|
|
503
|
+
oneOf: [
|
|
504
|
+
NextCursorPageSchema,
|
|
505
|
+
PreviousCursorPageSchema
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
})(target, propertyKey, descriptor);
|
|
509
|
+
} else {
|
|
510
|
+
ApiQuery({
|
|
511
|
+
name: "page",
|
|
512
|
+
required: true,
|
|
513
|
+
schema: {
|
|
514
|
+
oneOf: [
|
|
515
|
+
OffsetPageSchema,
|
|
516
|
+
NextCursorPageSchema,
|
|
517
|
+
PreviousCursorPageSchema
|
|
518
|
+
]
|
|
519
|
+
}
|
|
520
|
+
})(target, propertyKey, descriptor);
|
|
521
|
+
}
|
|
522
|
+
Query(new BukaPageQueryValidationPipe({
|
|
523
|
+
mode
|
|
524
|
+
}))(target, propertyKey, parameterIndex);
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
__name(PageQuery, "PageQuery");
|
|
528
|
+
function OptionalPageQuery(mode) {
|
|
529
|
+
return (target, propertyKey, parameterIndex) => {
|
|
530
|
+
if (!propertyKey) {
|
|
531
|
+
throw new Error("@PageQuery decorator can only be used on method parameters.");
|
|
532
|
+
}
|
|
533
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, propertyKey);
|
|
534
|
+
if (mode === "offset") {
|
|
535
|
+
ApiQuery({
|
|
536
|
+
name: "page",
|
|
537
|
+
required: false,
|
|
538
|
+
schema: OffsetPageSchema
|
|
539
|
+
});
|
|
540
|
+
} else if (mode === "cursor") {
|
|
541
|
+
ApiQuery({
|
|
542
|
+
name: "page",
|
|
543
|
+
required: false,
|
|
544
|
+
schema: {
|
|
545
|
+
oneOf: [
|
|
546
|
+
NextCursorPageSchema,
|
|
547
|
+
PreviousCursorPageSchema
|
|
548
|
+
]
|
|
549
|
+
}
|
|
550
|
+
})(target, propertyKey, descriptor);
|
|
551
|
+
} else {
|
|
552
|
+
ApiQuery({
|
|
553
|
+
name: "page",
|
|
554
|
+
required: false,
|
|
555
|
+
schema: {
|
|
556
|
+
oneOf: [
|
|
557
|
+
OffsetPageSchema,
|
|
558
|
+
NextCursorPageSchema,
|
|
559
|
+
PreviousCursorPageSchema
|
|
560
|
+
]
|
|
561
|
+
}
|
|
562
|
+
})(target, propertyKey, descriptor);
|
|
563
|
+
}
|
|
564
|
+
Query(new BukaPageQueryValidationPipe({
|
|
565
|
+
mode,
|
|
566
|
+
optional: true
|
|
567
|
+
}))(target, propertyKey, parameterIndex);
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
__name(OptionalPageQuery, "OptionalPageQuery");
|
|
571
|
+
|
|
572
|
+
// src/utils/logger.ts
|
|
573
|
+
import { Logger } from "@nestjs/common";
|
|
574
|
+
var logger = new Logger("@buka/nestjs-kits");
|
|
575
|
+
|
|
576
|
+
// src/mikro-orm/decorators/api-scalar-entity-property.decorator.ts
|
|
577
|
+
function ApiScalarEntityProperty(options) {
|
|
578
|
+
const { meta } = options;
|
|
579
|
+
if (typeof meta["columnType"] === "string") {
|
|
580
|
+
const columnType = meta["columnType"].toLowerCase();
|
|
581
|
+
if (columnType.startsWith("varchar")) {
|
|
582
|
+
const length = Number(meta["columnType"].match(/\d+/)?.[0]);
|
|
583
|
+
return VarcharProperty(length, options);
|
|
584
|
+
}
|
|
585
|
+
if (columnType.startsWith("char")) {
|
|
586
|
+
const length = Number(meta["columnType"].match(/\d+/)?.[0]);
|
|
587
|
+
return CharProperty(length, options);
|
|
588
|
+
}
|
|
589
|
+
if (columnType === "text") return TextProperty(options);
|
|
590
|
+
if (columnType === "money") return MoneyProperty(options);
|
|
591
|
+
if (columnType.startsWith("int")) return IntProperty(options);
|
|
592
|
+
if (columnType.startsWith("smallint")) return IntProperty(options);
|
|
593
|
+
if (columnType.startsWith("tinyint")) return TinyintProperty(options);
|
|
594
|
+
if (columnType.startsWith("double")) return DoubleProperty(options);
|
|
595
|
+
if (columnType.startsWith("decimal") || columnType.startsWith("numeric")) return DecimalProperty(options);
|
|
596
|
+
if (columnType === "datetime") return DatetimeProperty(options);
|
|
597
|
+
}
|
|
598
|
+
if (meta.type === "varchar") return VarcharProperty(meta.length, options);
|
|
599
|
+
if (meta.type === "char") return CharProperty(meta.length, options);
|
|
600
|
+
if (meta.type === "text") return TextProperty(options);
|
|
601
|
+
if (meta.type === "money") return MoneyProperty(options);
|
|
602
|
+
if (meta.type === "int") return IntProperty(options);
|
|
603
|
+
if (meta.type === "smallint") return IntProperty(options);
|
|
604
|
+
if (meta.type === "tinyint") return TinyintProperty(options);
|
|
605
|
+
if (meta.type === "double") return DoubleProperty(options);
|
|
606
|
+
if (meta.type === "decimal" || meta.type === "numeric") return DecimalProperty(options);
|
|
607
|
+
if (meta.type === "datetime") return DatetimeProperty(options);
|
|
608
|
+
if (meta.type === "boolean" || meta.type === "bool") return BooleanProperty(options);
|
|
609
|
+
if (meta.type === "bigint") return BigIntProperty(options);
|
|
610
|
+
if (meta.type instanceof BigIntType) return BigIntProperty(options);
|
|
611
|
+
logger.warn(`No decorator founded for type ${meta.type} for property ${meta.name}.`);
|
|
612
|
+
return () => {
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
__name(ApiScalarEntityProperty, "ApiScalarEntityProperty");
|
|
616
|
+
function getEnumOptions(options) {
|
|
617
|
+
if (options.meta.enum !== true) return {};
|
|
618
|
+
const items = options.meta.items;
|
|
619
|
+
const values2 = typeof items === "function" ? items() : items;
|
|
620
|
+
const enumName = options.schema?.enumName;
|
|
621
|
+
return {
|
|
622
|
+
enum: values2,
|
|
623
|
+
enumName
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
__name(getEnumOptions, "getEnumOptions");
|
|
627
|
+
function VarcharProperty(length, options) {
|
|
628
|
+
const decorators = [];
|
|
629
|
+
if (!options.unverified) {
|
|
630
|
+
decorators.push(IsString());
|
|
631
|
+
if (length) decorators.push(MaxLength(length));
|
|
632
|
+
}
|
|
633
|
+
decorators.push(Property({
|
|
634
|
+
type: /* @__PURE__ */ __name(() => String, "type"),
|
|
635
|
+
optional: options.meta.nullable,
|
|
636
|
+
schema: {
|
|
637
|
+
type: "string",
|
|
638
|
+
maxLength: length,
|
|
639
|
+
...options.schema || {},
|
|
640
|
+
...getEnumOptions(options),
|
|
641
|
+
required: !options.meta.nullable,
|
|
642
|
+
description: options.meta.comment
|
|
643
|
+
}
|
|
644
|
+
}));
|
|
645
|
+
return applyDecorators3(...decorators);
|
|
646
|
+
}
|
|
647
|
+
__name(VarcharProperty, "VarcharProperty");
|
|
648
|
+
function CharProperty(length, options) {
|
|
649
|
+
const decorators = [];
|
|
650
|
+
if (!options.unverified) {
|
|
651
|
+
decorators.push(IsString());
|
|
652
|
+
if (length) decorators.push(MaxLength(length), MinLength(length));
|
|
653
|
+
}
|
|
654
|
+
decorators.push(Property({
|
|
655
|
+
type: /* @__PURE__ */ __name(() => String, "type"),
|
|
656
|
+
optional: options.meta.nullable,
|
|
657
|
+
schema: {
|
|
658
|
+
type: "string",
|
|
659
|
+
maxLength: length,
|
|
660
|
+
minimum: length,
|
|
661
|
+
...options.schema || {},
|
|
662
|
+
...getEnumOptions(options),
|
|
663
|
+
required: !options.meta.nullable,
|
|
664
|
+
description: options.meta.comment
|
|
665
|
+
}
|
|
666
|
+
}));
|
|
667
|
+
return applyDecorators3(...decorators);
|
|
668
|
+
}
|
|
669
|
+
__name(CharProperty, "CharProperty");
|
|
670
|
+
function TextProperty(options) {
|
|
671
|
+
const decorators = [];
|
|
672
|
+
if (!options.unverified) {
|
|
673
|
+
decorators.push(IsString());
|
|
674
|
+
}
|
|
675
|
+
decorators.push(Property({
|
|
676
|
+
type: /* @__PURE__ */ __name(() => String, "type"),
|
|
677
|
+
optional: options.meta.nullable,
|
|
678
|
+
schema: {
|
|
679
|
+
type: "string",
|
|
680
|
+
...options.schema || {},
|
|
681
|
+
...getEnumOptions(options),
|
|
682
|
+
required: !options.meta.nullable,
|
|
683
|
+
description: options.meta.comment
|
|
684
|
+
}
|
|
685
|
+
}));
|
|
686
|
+
return applyDecorators3(...decorators);
|
|
687
|
+
}
|
|
688
|
+
__name(TextProperty, "TextProperty");
|
|
689
|
+
function MoneyProperty(options) {
|
|
690
|
+
const decorators = [];
|
|
691
|
+
if (!options.unverified) {
|
|
692
|
+
decorators.push(IsCurrency({
|
|
693
|
+
symbol: ""
|
|
694
|
+
}));
|
|
695
|
+
}
|
|
696
|
+
decorators.push(Property({
|
|
697
|
+
type: /* @__PURE__ */ __name(() => String, "type"),
|
|
698
|
+
optional: options.meta.nullable,
|
|
699
|
+
schema: {
|
|
700
|
+
type: "string",
|
|
701
|
+
format: "money",
|
|
702
|
+
...options.schema || {},
|
|
703
|
+
required: !options.meta.nullable,
|
|
704
|
+
description: options.meta.comment
|
|
705
|
+
}
|
|
706
|
+
}));
|
|
707
|
+
return applyDecorators3(...decorators);
|
|
708
|
+
}
|
|
709
|
+
__name(MoneyProperty, "MoneyProperty");
|
|
710
|
+
function BigIntProperty(options) {
|
|
711
|
+
const { meta } = options;
|
|
712
|
+
let mode;
|
|
713
|
+
if (meta.type === "bigint") {
|
|
714
|
+
mode = "string";
|
|
715
|
+
} else if (meta.type instanceof BigIntType) {
|
|
716
|
+
const metaType = meta.type;
|
|
717
|
+
mode = metaType.mode === "string" ? "string" : "number";
|
|
718
|
+
} else {
|
|
719
|
+
throw new Error(`Unsupported type for BigIntProperty: ${meta.type}`);
|
|
720
|
+
}
|
|
721
|
+
const decorators = [];
|
|
722
|
+
if (mode === "string") {
|
|
723
|
+
if (!options.unverified) {
|
|
724
|
+
decorators.push(IsString());
|
|
725
|
+
}
|
|
726
|
+
decorators.push(Property({
|
|
727
|
+
type: /* @__PURE__ */ __name(() => String, "type"),
|
|
728
|
+
optional: options.meta.nullable,
|
|
729
|
+
schema: {
|
|
730
|
+
type: "string",
|
|
731
|
+
...options.schema || {},
|
|
732
|
+
...getEnumOptions(options),
|
|
733
|
+
required: !options.meta.nullable,
|
|
734
|
+
description: options.meta.comment
|
|
735
|
+
}
|
|
736
|
+
}));
|
|
737
|
+
} else {
|
|
738
|
+
if (!options.unverified) {
|
|
739
|
+
decorators.push(IsInt());
|
|
740
|
+
}
|
|
741
|
+
decorators.push(Property({
|
|
742
|
+
type: /* @__PURE__ */ __name(() => Number, "type"),
|
|
743
|
+
optional: options.meta.nullable,
|
|
744
|
+
schema: {
|
|
745
|
+
type: "integer",
|
|
746
|
+
format: "int64",
|
|
747
|
+
...options.schema || {},
|
|
748
|
+
...getEnumOptions(options),
|
|
749
|
+
required: !options.meta.nullable,
|
|
750
|
+
description: options.meta.comment
|
|
751
|
+
}
|
|
752
|
+
}));
|
|
753
|
+
}
|
|
754
|
+
return applyDecorators3(...decorators);
|
|
755
|
+
}
|
|
756
|
+
__name(BigIntProperty, "BigIntProperty");
|
|
757
|
+
function IntProperty(options) {
|
|
758
|
+
const decorators = [];
|
|
759
|
+
if (!options.unverified) {
|
|
760
|
+
decorators.push(IsInt());
|
|
761
|
+
}
|
|
762
|
+
decorators.push(Property({
|
|
763
|
+
type: /* @__PURE__ */ __name(() => Number, "type"),
|
|
764
|
+
optional: options.meta.nullable,
|
|
765
|
+
schema: {
|
|
766
|
+
type: "integer",
|
|
767
|
+
minimum: options.meta.unsigned ? 0 : -2147483647,
|
|
768
|
+
maximum: options.meta.unsigned ? 4294967295 : 2147483647,
|
|
769
|
+
...options.schema || {},
|
|
770
|
+
...getEnumOptions(options),
|
|
771
|
+
required: !options.meta.nullable,
|
|
772
|
+
description: options.meta.comment
|
|
773
|
+
}
|
|
774
|
+
}));
|
|
775
|
+
return applyDecorators3(...decorators);
|
|
776
|
+
}
|
|
777
|
+
__name(IntProperty, "IntProperty");
|
|
778
|
+
function TinyintProperty(options) {
|
|
779
|
+
const decorators = [];
|
|
780
|
+
if (!options.unverified) {
|
|
781
|
+
decorators.push(IsInt());
|
|
782
|
+
}
|
|
783
|
+
decorators.push(Property({
|
|
784
|
+
type: /* @__PURE__ */ __name(() => Number, "type"),
|
|
785
|
+
optional: options.meta.nullable,
|
|
786
|
+
schema: {
|
|
787
|
+
type: "integer",
|
|
788
|
+
minimum: options.meta.unsigned ? 0 : -128,
|
|
789
|
+
maximum: options.meta.unsigned ? 255 : 127,
|
|
790
|
+
...options.schema || {},
|
|
791
|
+
...getEnumOptions(options),
|
|
792
|
+
required: !options.meta.nullable,
|
|
793
|
+
description: options.meta.comment
|
|
794
|
+
}
|
|
795
|
+
}));
|
|
796
|
+
return applyDecorators3(...decorators);
|
|
797
|
+
}
|
|
798
|
+
__name(TinyintProperty, "TinyintProperty");
|
|
799
|
+
function DoubleProperty(options) {
|
|
800
|
+
const decorators = [];
|
|
801
|
+
if (!options.unverified) {
|
|
802
|
+
decorators.push(IsNumber());
|
|
803
|
+
}
|
|
804
|
+
decorators.push(Property({
|
|
805
|
+
type: /* @__PURE__ */ __name(() => Number, "type"),
|
|
806
|
+
optional: options.meta.nullable,
|
|
807
|
+
schema: {
|
|
808
|
+
type: "number",
|
|
809
|
+
format: "double",
|
|
810
|
+
minimum: options.meta.unsigned ? 0 : void 0,
|
|
811
|
+
...options.schema || {},
|
|
812
|
+
...getEnumOptions(options),
|
|
813
|
+
required: !options.meta.nullable,
|
|
814
|
+
description: options.meta.comment
|
|
815
|
+
}
|
|
816
|
+
}));
|
|
817
|
+
return applyDecorators3(...decorators);
|
|
818
|
+
}
|
|
819
|
+
__name(DoubleProperty, "DoubleProperty");
|
|
820
|
+
function DecimalProperty(options) {
|
|
821
|
+
const decorators = [];
|
|
822
|
+
if (!options.unverified) {
|
|
823
|
+
if (options.meta.scale) decorators.push(IsNumber({
|
|
824
|
+
maxDecimalPlaces: options.meta.scale
|
|
825
|
+
}));
|
|
826
|
+
else decorators.push(IsNumber());
|
|
827
|
+
}
|
|
828
|
+
decorators.push(Property({
|
|
829
|
+
type: /* @__PURE__ */ __name(() => Number, "type"),
|
|
830
|
+
optional: options.meta.nullable,
|
|
831
|
+
schema: {
|
|
832
|
+
type: "number",
|
|
833
|
+
format: "double",
|
|
834
|
+
minimum: options.meta.unsigned ? 0 : void 0,
|
|
835
|
+
...options.schema || {},
|
|
836
|
+
...getEnumOptions(options),
|
|
837
|
+
required: !options.meta.nullable,
|
|
838
|
+
description: options.meta.comment
|
|
839
|
+
}
|
|
840
|
+
}));
|
|
841
|
+
return applyDecorators3(...decorators);
|
|
842
|
+
}
|
|
843
|
+
__name(DecimalProperty, "DecimalProperty");
|
|
844
|
+
function DatetimeProperty(options) {
|
|
845
|
+
const decorators = [];
|
|
846
|
+
if (!options.unverified) {
|
|
847
|
+
decorators.push(IsISO8601());
|
|
848
|
+
}
|
|
849
|
+
decorators.push(Property({
|
|
850
|
+
type: /* @__PURE__ */ __name(() => Date, "type"),
|
|
851
|
+
optional: options.meta.nullable,
|
|
852
|
+
schema: {
|
|
853
|
+
type: "string",
|
|
854
|
+
format: "date-time",
|
|
855
|
+
...options.schema || {},
|
|
856
|
+
required: !options.meta.nullable,
|
|
857
|
+
description: options.meta.comment
|
|
858
|
+
}
|
|
859
|
+
}));
|
|
860
|
+
return applyDecorators3(...decorators);
|
|
861
|
+
}
|
|
862
|
+
__name(DatetimeProperty, "DatetimeProperty");
|
|
863
|
+
function BooleanProperty(options) {
|
|
864
|
+
const decorators = [];
|
|
865
|
+
if (!options.unverified) {
|
|
866
|
+
decorators.push(IsBoolean());
|
|
867
|
+
}
|
|
868
|
+
decorators.push(Property({
|
|
869
|
+
type: /* @__PURE__ */ __name(() => Boolean, "type"),
|
|
870
|
+
optional: options.meta.nullable,
|
|
871
|
+
schema: {
|
|
872
|
+
type: "boolean",
|
|
873
|
+
...options.schema || {},
|
|
874
|
+
required: !options.meta.nullable,
|
|
875
|
+
description: options.meta.comment
|
|
876
|
+
}
|
|
877
|
+
}));
|
|
878
|
+
return applyDecorators3(...decorators);
|
|
879
|
+
}
|
|
880
|
+
__name(BooleanProperty, "BooleanProperty");
|
|
881
|
+
|
|
882
|
+
// src/utils/nestjs-swagger-utils.ts
|
|
883
|
+
import * as R3 from "ramda";
|
|
884
|
+
import { ModelPropertiesAccessor } from "@nestjs/swagger/dist/services/model-properties-accessor";
|
|
885
|
+
import { DECORATORS } from "@nestjs/swagger/dist/constants";
|
|
886
|
+
import { METADATA_FACTORY_NAME } from "@nestjs/swagger/dist/plugin/plugin-constants";
|
|
887
|
+
import { clonePluginMetadataFactory } from "@nestjs/swagger/dist/type-helpers/mapped-types.utils";
|
|
888
|
+
import { ApiProperty as ApiProperty2 } from "@nestjs/swagger";
|
|
889
|
+
import { isFunction } from "@nestjs/common/utils/shared.utils";
|
|
890
|
+
import { isBuiltInType } from "@nestjs/swagger/dist/utils/is-built-in-type.util";
|
|
891
|
+
import { SchemaObjectMetadata } from "@nestjs/swagger/dist/interfaces/schema-object-metadata.interface";
|
|
892
|
+
var modelPropertiesAccessor = new ModelPropertiesAccessor();
|
|
893
|
+
function cloneMetadata(target, source, keys) {
|
|
894
|
+
clonePluginMetadataFactory(target, source.prototype, (metadata) => R3.pick(keys, metadata));
|
|
895
|
+
for (const propertyKey of keys) {
|
|
896
|
+
const metadata = getMetadataOfDecorator(source, propertyKey);
|
|
897
|
+
if (metadata) {
|
|
898
|
+
ApiProperty2(metadata)(target.prototype, propertyKey);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
__name(cloneMetadata, "cloneMetadata");
|
|
903
|
+
function getMetadataOfDecorator(classRef, propertyKey) {
|
|
904
|
+
if (propertyKey) {
|
|
905
|
+
return Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, propertyKey);
|
|
906
|
+
}
|
|
907
|
+
const props = modelPropertiesAccessor.getModelProperties(classRef.prototype);
|
|
908
|
+
return R3.fromPairs(props.map((prop) => [
|
|
909
|
+
prop,
|
|
910
|
+
Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, prop)
|
|
911
|
+
]));
|
|
912
|
+
}
|
|
913
|
+
__name(getMetadataOfDecorator, "getMetadataOfDecorator");
|
|
914
|
+
function getMetadataOfPlugin(classRef, propertyKey) {
|
|
915
|
+
const propsInPlugin = typeof classRef[METADATA_FACTORY_NAME] === "function" ? classRef[METADATA_FACTORY_NAME]() : {};
|
|
916
|
+
if (propertyKey) return propsInPlugin[propertyKey];
|
|
917
|
+
return propsInPlugin;
|
|
918
|
+
}
|
|
919
|
+
__name(getMetadataOfPlugin, "getMetadataOfPlugin");
|
|
920
|
+
function getMetadata(classRef, propertyKey) {
|
|
921
|
+
const propsInDecorator = getMetadataOfDecorator(classRef);
|
|
922
|
+
const propsInPlugin = getMetadataOfPlugin(classRef);
|
|
923
|
+
const metadataMap = R3.mergeRight(propsInPlugin, propsInDecorator);
|
|
924
|
+
if (propertyKey) return metadataMap[propertyKey];
|
|
925
|
+
return metadataMap;
|
|
926
|
+
}
|
|
927
|
+
__name(getMetadata, "getMetadata");
|
|
928
|
+
function isLazyTypeFunc(type) {
|
|
929
|
+
return isFunction(type) && type.name == "type";
|
|
930
|
+
}
|
|
931
|
+
__name(isLazyTypeFunc, "isLazyTypeFunc");
|
|
932
|
+
|
|
933
|
+
// src/utils/mikro-orm-utils.ts
|
|
934
|
+
import * as R4 from "ramda";
|
|
935
|
+
import { EntityMetadata, MetadataStorage } from "@mikro-orm/core";
|
|
936
|
+
function getMetadata2(classRef) {
|
|
937
|
+
const metadatas = [];
|
|
938
|
+
let parent = classRef;
|
|
939
|
+
do {
|
|
940
|
+
const meta = MetadataStorage.getMetadataFromDecorator(parent);
|
|
941
|
+
if (meta instanceof EntityMetadata) metadatas.push(meta);
|
|
942
|
+
parent = Object.getPrototypeOf(parent);
|
|
943
|
+
} while (parent && parent !== Object.prototype);
|
|
944
|
+
return R4.unnest(metadatas.map((meta) => R4.values(meta.properties)));
|
|
945
|
+
}
|
|
946
|
+
__name(getMetadata2, "getMetadata");
|
|
947
|
+
|
|
948
|
+
// src/mikro-orm/converters/entity-ref-type/entity-ref-type.ts
|
|
949
|
+
import { inheritTransformationMetadata, inheritValidationMetadata } from "@nestjs/mapped-types";
|
|
950
|
+
var EntityRefTypeClassMetadataPropertyKey = /* @__PURE__ */ Symbol("EntityRefTypeClassMetadataPropertyKey");
|
|
951
|
+
var storage = /* @__PURE__ */ new WeakMap();
|
|
952
|
+
function EntityRefType(classRef) {
|
|
953
|
+
if (storage.has(classRef)) {
|
|
954
|
+
return storage.get(classRef);
|
|
955
|
+
}
|
|
956
|
+
const properties = getMetadata2(classRef);
|
|
957
|
+
const primaryProperties = properties.filter((prop) => prop.primary).map((prop) => prop.name);
|
|
958
|
+
if (!primaryProperties.length) {
|
|
959
|
+
throw new Error(`Cannot create EntityRefType for ${classRef.name} because it has no primary properties.`);
|
|
960
|
+
}
|
|
961
|
+
let EntityRefTypeClass = class EntityRefTypeClass {
|
|
962
|
+
static {
|
|
963
|
+
__name(this, "EntityRefTypeClass");
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
EntityRefTypeClass[EntityRefTypeClassMetadataPropertyKey] = {};
|
|
967
|
+
cloneMetadata(EntityRefTypeClass, classRef, primaryProperties);
|
|
968
|
+
inheritValidationMetadata(classRef, EntityRefTypeClass, (key) => primaryProperties.includes(key));
|
|
969
|
+
inheritTransformationMetadata(classRef, EntityRefTypeClass, (key) => primaryProperties.includes(key));
|
|
970
|
+
storage.set(classRef, EntityRefTypeClass);
|
|
971
|
+
return EntityRefTypeClass;
|
|
972
|
+
}
|
|
973
|
+
__name(EntityRefType, "EntityRefType");
|
|
974
|
+
|
|
975
|
+
// src/mikro-orm/decorators/api-entity-property.decorator.ts
|
|
976
|
+
function ApiEntityProperty(options) {
|
|
977
|
+
return (target, propertyKey) => {
|
|
978
|
+
const meta = MetadataStorage2.getMetadataFromDecorator(target.constructor);
|
|
979
|
+
const prop = meta.properties[propertyKey];
|
|
980
|
+
if (!prop) return;
|
|
981
|
+
if (prop.hidden === true) {
|
|
982
|
+
ApiHideProperty()(target, propertyKey);
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
if (prop.kind === ReferenceKind.SCALAR) {
|
|
989
|
+
ApiScalarEntityProperty({
|
|
990
|
+
meta: prop,
|
|
991
|
+
schema: options
|
|
992
|
+
})(target, propertyKey);
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
const getType = /* @__PURE__ */ __name(() => {
|
|
996
|
+
const ent = prop.entity();
|
|
997
|
+
if (prop.eager === true) return ent;
|
|
998
|
+
if (typeof ent === "function") {
|
|
999
|
+
return EntityRefType(ent);
|
|
1000
|
+
}
|
|
1001
|
+
return Object;
|
|
1002
|
+
}, "getType");
|
|
1003
|
+
if (prop.kind === ReferenceKind.ONE_TO_ONE || prop.kind === ReferenceKind.MANY_TO_ONE) {
|
|
1004
|
+
Property({
|
|
1005
|
+
type: /* @__PURE__ */ __name(() => getType(), "type"),
|
|
1006
|
+
relation: {
|
|
1007
|
+
kind: prop.kind,
|
|
1008
|
+
type: /* @__PURE__ */ __name(() => getType(), "type")
|
|
1009
|
+
},
|
|
1010
|
+
schema: {
|
|
1011
|
+
description: prop.comment,
|
|
1012
|
+
required: !prop.nullable
|
|
1013
|
+
}
|
|
1014
|
+
})(target, propertyKey);
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
if (prop.kind === ReferenceKind.ONE_TO_MANY || prop.kind === ReferenceKind.MANY_TO_MANY) {
|
|
1018
|
+
NestedProperty(() => getType(), {
|
|
1019
|
+
each: true,
|
|
1020
|
+
optional: prop.nullable,
|
|
1021
|
+
schema: {
|
|
1022
|
+
description: prop.comment,
|
|
1023
|
+
type: "array",
|
|
1024
|
+
items: {
|
|
1025
|
+
type: getSchemaPath(() => getType())
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
})(target, propertyKey);
|
|
1029
|
+
Relation({
|
|
1030
|
+
kind: prop.kind,
|
|
1031
|
+
type: /* @__PURE__ */ __name(() => getType(), "type")
|
|
1032
|
+
})(target, propertyKey);
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
__name(ApiEntityProperty, "ApiEntityProperty");
|
|
1038
|
+
|
|
1039
|
+
// src/mikro-orm/decorators/entity-property.decorator.ts
|
|
1040
|
+
function EntityProperty(options) {
|
|
1041
|
+
return (target, propertyKey) => {
|
|
1042
|
+
if (typeof propertyKey !== "string") throw new TypeError("@EntityProperty() can only be used on string property");
|
|
1043
|
+
OrmProperty(options)(target, propertyKey);
|
|
1044
|
+
ApiEntityProperty({
|
|
1045
|
+
example: options?.example
|
|
1046
|
+
})(target, propertyKey);
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
__name(EntityProperty, "EntityProperty");
|
|
1050
|
+
|
|
1051
|
+
// src/mikro-orm/models/timestamped-entity.ts
|
|
1052
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1053
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1054
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1055
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1056
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1057
|
+
}
|
|
1058
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
1059
|
+
function _ts_metadata2(k, v) {
|
|
1060
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1061
|
+
}
|
|
1062
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
1063
|
+
var TimestampedEntity = class {
|
|
1064
|
+
static {
|
|
1065
|
+
__name(this, "TimestampedEntity");
|
|
1066
|
+
}
|
|
1067
|
+
[Config];
|
|
1068
|
+
[OptionalProps];
|
|
1069
|
+
createdAt = /* @__PURE__ */ new Date();
|
|
1070
|
+
updatedAt = /* @__PURE__ */ new Date();
|
|
1071
|
+
};
|
|
1072
|
+
_ts_decorate2([
|
|
1073
|
+
EntityProperty({
|
|
1074
|
+
type: "datetime",
|
|
1075
|
+
onCreate: /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "onCreate"),
|
|
1076
|
+
defaultRaw: "CURRENT_TIMESTAMP",
|
|
1077
|
+
comment: "\u521B\u5EFA\u65F6\u95F4"
|
|
1078
|
+
}),
|
|
1079
|
+
_ts_metadata2("design:type", typeof Date === "undefined" ? Object : Date)
|
|
1080
|
+
], TimestampedEntity.prototype, "createdAt", void 0);
|
|
1081
|
+
_ts_decorate2([
|
|
1082
|
+
EntityProperty({
|
|
1083
|
+
type: "datetime",
|
|
1084
|
+
onUpdate: /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "onUpdate"),
|
|
1085
|
+
defaultRaw: "CURRENT_TIMESTAMP",
|
|
1086
|
+
comment: "\u66F4\u65B0\u65F6\u95F4"
|
|
1087
|
+
}),
|
|
1088
|
+
_ts_metadata2("design:type", typeof Date === "undefined" ? Object : Date)
|
|
1089
|
+
], TimestampedEntity.prototype, "updatedAt", void 0);
|
|
1090
|
+
|
|
1091
|
+
// src/mikro-orm/models/base-entity.ts
|
|
1092
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
1093
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1094
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1095
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1096
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1097
|
+
}
|
|
1098
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
1099
|
+
function _ts_metadata3(k, v) {
|
|
1100
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1101
|
+
}
|
|
1102
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
1103
|
+
var BaseEntity = class extends TimestampedEntity {
|
|
1104
|
+
static {
|
|
1105
|
+
__name(this, "BaseEntity");
|
|
1106
|
+
}
|
|
1107
|
+
// [Config]?: DefineConfig<{ forceObject: true }>;
|
|
1108
|
+
[PrimaryKeyProp];
|
|
1109
|
+
id;
|
|
1110
|
+
};
|
|
1111
|
+
_ts_decorate3([
|
|
1112
|
+
ApiProperty3({
|
|
1113
|
+
type: "string",
|
|
1114
|
+
description: "PK",
|
|
1115
|
+
example: "1",
|
|
1116
|
+
required: true
|
|
1117
|
+
}),
|
|
1118
|
+
PrimaryKey({
|
|
1119
|
+
type: new BigIntType2("string"),
|
|
1120
|
+
comment: "\u4E3B\u952E"
|
|
1121
|
+
}),
|
|
1122
|
+
IsNumberString(),
|
|
1123
|
+
_ts_metadata3("design:type", String)
|
|
1124
|
+
], BaseEntity.prototype, "id", void 0);
|
|
1125
|
+
|
|
1126
|
+
// src/mikro-orm/converters/entity-dto-type/entity-dto-type.ts
|
|
1127
|
+
import { inheritTransformationMetadata as inheritTransformationMetadata2, inheritValidationMetadata as inheritValidationMetadata2 } from "@nestjs/mapped-types";
|
|
1128
|
+
import { wrap } from "@mikro-orm/core";
|
|
1129
|
+
function EntityDtoType(entity) {
|
|
1130
|
+
const properties = getMetadata2(entity);
|
|
1131
|
+
if (!properties.length) {
|
|
1132
|
+
throw new Error(`Cannot create EntityDtoType for ${entity.name} because it isn't an MikroORM Entity.`);
|
|
1133
|
+
}
|
|
1134
|
+
const keys = properties.filter((prop) => {
|
|
1135
|
+
if (prop.hidden) return false;
|
|
1136
|
+
if (prop.kind === "scalar" && prop.ref) return false;
|
|
1137
|
+
return true;
|
|
1138
|
+
}).map((prop) => prop.name);
|
|
1139
|
+
let EntityDtoTypeClass = class EntityDtoTypeClass2 {
|
|
1140
|
+
static {
|
|
1141
|
+
__name(this, "EntityDtoTypeClass");
|
|
1142
|
+
}
|
|
1143
|
+
static from(entity2) {
|
|
1144
|
+
const dto = new EntityDtoTypeClass2();
|
|
1145
|
+
const json = wrap(entity2).toPOJO();
|
|
1146
|
+
for (const property of properties) {
|
|
1147
|
+
if (property.hidden) continue;
|
|
1148
|
+
if (property.kind === "scalar" && !property.ref) {
|
|
1149
|
+
dto[property.name] = json[property.name];
|
|
1150
|
+
}
|
|
1151
|
+
if (property.kind === "m:n" || property.kind === "1:m") {
|
|
1152
|
+
dto[property.name] = json[property.name];
|
|
1153
|
+
}
|
|
1154
|
+
if (property.kind === "1:1" || property.kind === "m:1") {
|
|
1155
|
+
dto[property.name] = json[property.name];
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return dto;
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
inheritValidationMetadata2(entity, EntityDtoTypeClass, (key) => keys.includes(key));
|
|
1162
|
+
inheritTransformationMetadata2(entity, EntityDtoTypeClass, (key) => keys.includes(key));
|
|
1163
|
+
cloneMetadata(EntityDtoTypeClass, entity, keys);
|
|
1164
|
+
for (const property of keys) {
|
|
1165
|
+
ModelRegister.copyProperty(entity, EntityDtoTypeClass, property);
|
|
1166
|
+
}
|
|
1167
|
+
return EntityDtoTypeClass;
|
|
1168
|
+
}
|
|
1169
|
+
__name(EntityDtoType, "EntityDtoType");
|
|
1170
|
+
|
|
1171
|
+
// src/mikro-orm/decorators/entity-enum.decorator.ts
|
|
1172
|
+
import { Enum } from "@mikro-orm/core";
|
|
1173
|
+
function EntityEnum(options) {
|
|
1174
|
+
return (target, propertyKey) => {
|
|
1175
|
+
if (typeof propertyKey !== "string") throw new TypeError("@EntityEnum() can only be used on string property");
|
|
1176
|
+
Enum(options)(target, propertyKey);
|
|
1177
|
+
ApiEntityProperty({
|
|
1178
|
+
example: options.example,
|
|
1179
|
+
enumName: options.enumName
|
|
1180
|
+
})(target, propertyKey);
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
__name(EntityEnum, "EntityEnum");
|
|
1184
|
+
|
|
1185
|
+
// src/mikro-orm/decorators/entity-transient.decorator.ts
|
|
1186
|
+
import { Property as Property2 } from "@mikro-orm/core";
|
|
1187
|
+
function EntityTransient() {
|
|
1188
|
+
return Property2({
|
|
1189
|
+
persist: false
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
__name(EntityTransient, "EntityTransient");
|
|
1193
|
+
|
|
1194
|
+
// src/mikro-orm/decorators/entity-one-to-one.decorator.ts
|
|
1195
|
+
import { OneToOne as OrmOneToOne } from "@mikro-orm/core";
|
|
1196
|
+
function EntityOneToOne(entity, mappedByOrOptions, options) {
|
|
1197
|
+
return (target, propertyKey) => {
|
|
1198
|
+
if (typeof propertyKey !== "string") throw new TypeError("@EntityOneToOne() can only be used on string property");
|
|
1199
|
+
OrmOneToOne(entity, mappedByOrOptions, options)(target, propertyKey);
|
|
1200
|
+
ApiEntityProperty()(target, propertyKey);
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
__name(EntityOneToOne, "EntityOneToOne");
|
|
1204
|
+
|
|
1205
|
+
// src/mikro-orm/decorators/entity-one-to-many.decorator.ts
|
|
1206
|
+
import { OneToMany as OrmOneToMany } from "@mikro-orm/core";
|
|
1207
|
+
function EntityOneToMany(options) {
|
|
1208
|
+
return (target, propertyKey) => {
|
|
1209
|
+
if (typeof propertyKey !== "string") throw new TypeError("@EntityOneToMany() can only be used on string property");
|
|
1210
|
+
OrmOneToMany(options)(target, propertyKey);
|
|
1211
|
+
ApiEntityProperty()(target, propertyKey);
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
__name(EntityOneToMany, "EntityOneToMany");
|
|
1215
|
+
|
|
1216
|
+
// src/mikro-orm/decorators/entity-many-to-one.decorator.ts
|
|
1217
|
+
import { ManyToOne as OrmManyToOne } from "@mikro-orm/core";
|
|
1218
|
+
function EntityManyToOne(entity, options) {
|
|
1219
|
+
return (target, propertyKey) => {
|
|
1220
|
+
if (typeof propertyKey !== "string") throw new TypeError("@EntityManyToOne() can only be used on string property");
|
|
1221
|
+
OrmManyToOne(entity, options)(target, propertyKey);
|
|
1222
|
+
ApiEntityProperty()(target, propertyKey);
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
__name(EntityManyToOne, "EntityManyToOne");
|
|
1226
|
+
|
|
1227
|
+
// src/mikro-orm/decorators/entity-many-to-many.decorator.ts
|
|
1228
|
+
import { ManyToMany } from "@mikro-orm/core";
|
|
1229
|
+
function EntityManyToMany(entity, mappedBy, options) {
|
|
1230
|
+
return (target, propertyKey) => {
|
|
1231
|
+
if (typeof propertyKey !== "string") throw new TypeError("@EntityManyToMany() can only be used on string property");
|
|
1232
|
+
ManyToMany(entity, mappedBy, options)(target, propertyKey);
|
|
1233
|
+
ApiEntityProperty()(target, propertyKey);
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
__name(EntityManyToMany, "EntityManyToMany");
|
|
1237
|
+
|
|
1238
|
+
// src/mikro-orm/database.config.ts
|
|
1239
|
+
import { ToNumber } from "@buka/class-transformer-extra";
|
|
1240
|
+
import { IsBoolean as IsBoolean2, IsNumber as IsNumber2, IsString as IsString2 } from "class-validator";
|
|
1241
|
+
import * as R5 from "ramda";
|
|
1242
|
+
import * as util from "util";
|
|
1243
|
+
import { Migrator } from "@mikro-orm/migrations";
|
|
1244
|
+
import { FlushMode } from "@mikro-orm/core";
|
|
1245
|
+
import { BadRequestException as BadRequestException2 } from "@nestjs/common";
|
|
1246
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
1247
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1248
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1249
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1250
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1251
|
+
}
|
|
1252
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
1253
|
+
function _ts_metadata4(k, v) {
|
|
1254
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1255
|
+
}
|
|
1256
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
1257
|
+
var DatabaseConfig = class {
|
|
1258
|
+
static {
|
|
1259
|
+
__name(this, "DatabaseConfig");
|
|
1260
|
+
}
|
|
1261
|
+
debug = false;
|
|
1262
|
+
migration = false;
|
|
1263
|
+
dbName;
|
|
1264
|
+
host;
|
|
1265
|
+
port;
|
|
1266
|
+
user;
|
|
1267
|
+
password;
|
|
1268
|
+
timezone = "+08:00";
|
|
1269
|
+
toMikroOrmOptions(config) {
|
|
1270
|
+
let options = {
|
|
1271
|
+
host: this.host,
|
|
1272
|
+
port: this.port,
|
|
1273
|
+
user: this.user,
|
|
1274
|
+
password: this.password,
|
|
1275
|
+
dbName: this.dbName,
|
|
1276
|
+
debug: this.debug,
|
|
1277
|
+
timezone: this.timezone,
|
|
1278
|
+
forceUndefined: true,
|
|
1279
|
+
flushMode: FlushMode.COMMIT,
|
|
1280
|
+
serialization: {
|
|
1281
|
+
forceObject: true
|
|
1282
|
+
},
|
|
1283
|
+
findOneOrFailHandler: /* @__PURE__ */ __name((entityName, where) => new BadRequestException2(`Cannot find ${entityName} where ${util.inspect(where)}`), "findOneOrFailHandler")
|
|
1284
|
+
};
|
|
1285
|
+
if (this.migration) {
|
|
1286
|
+
options = R5.mergeDeepRight(options, {
|
|
1287
|
+
extensions: [
|
|
1288
|
+
Migrator
|
|
1289
|
+
],
|
|
1290
|
+
migrations: {
|
|
1291
|
+
snapshotName: "snapshot",
|
|
1292
|
+
path: "migrations",
|
|
1293
|
+
fileName: /* @__PURE__ */ __name((timestamp) => `migration-${timestamp}`, "fileName")
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
return R5.mergeDeepRight(options, config || {});
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
_ts_decorate4([
|
|
1301
|
+
IsBoolean2()
|
|
1302
|
+
], DatabaseConfig.prototype, "debug", void 0);
|
|
1303
|
+
_ts_decorate4([
|
|
1304
|
+
IsBoolean2(),
|
|
1305
|
+
_ts_metadata4("design:type", Boolean)
|
|
1306
|
+
], DatabaseConfig.prototype, "migration", void 0);
|
|
1307
|
+
_ts_decorate4([
|
|
1308
|
+
IsString2(),
|
|
1309
|
+
_ts_metadata4("design:type", String)
|
|
1310
|
+
], DatabaseConfig.prototype, "dbName", void 0);
|
|
1311
|
+
_ts_decorate4([
|
|
1312
|
+
IsString2(),
|
|
1313
|
+
_ts_metadata4("design:type", String)
|
|
1314
|
+
], DatabaseConfig.prototype, "host", void 0);
|
|
1315
|
+
_ts_decorate4([
|
|
1316
|
+
ToNumber(),
|
|
1317
|
+
IsNumber2({
|
|
1318
|
+
allowNaN: false
|
|
1319
|
+
}),
|
|
1320
|
+
_ts_metadata4("design:type", Number)
|
|
1321
|
+
], DatabaseConfig.prototype, "port", void 0);
|
|
1322
|
+
_ts_decorate4([
|
|
1323
|
+
IsString2(),
|
|
1324
|
+
_ts_metadata4("design:type", String)
|
|
1325
|
+
], DatabaseConfig.prototype, "user", void 0);
|
|
1326
|
+
_ts_decorate4([
|
|
1327
|
+
IsString2(),
|
|
1328
|
+
_ts_metadata4("design:type", String)
|
|
1329
|
+
], DatabaseConfig.prototype, "password", void 0);
|
|
1330
|
+
_ts_decorate4([
|
|
1331
|
+
IsString2()
|
|
1332
|
+
], DatabaseConfig.prototype, "timezone", void 0);
|
|
1333
|
+
|
|
1334
|
+
// src/swagger/is-reference-object.ts
|
|
1335
|
+
function isReferenceObject(obj) {
|
|
1336
|
+
return !!obj && typeof obj === "object" && typeof obj.$ref === "string";
|
|
1337
|
+
}
|
|
1338
|
+
__name(isReferenceObject, "isReferenceObject");
|
|
1339
|
+
|
|
1340
|
+
// src/swagger/deep-dereference.ts
|
|
1341
|
+
function deepDereference(openapi, reference) {
|
|
1342
|
+
let current = reference;
|
|
1343
|
+
const stack = [];
|
|
1344
|
+
while (isReferenceObject(current)) {
|
|
1345
|
+
const refPath = current.$ref;
|
|
1346
|
+
if (stack.includes(refPath)) return void 0;
|
|
1347
|
+
stack.push(refPath);
|
|
1348
|
+
const parts = refPath.replace(/^#\//, "").split("/");
|
|
1349
|
+
let next = openapi;
|
|
1350
|
+
for (const part of parts) {
|
|
1351
|
+
next = next[part];
|
|
1352
|
+
}
|
|
1353
|
+
if (!next) return void 0;
|
|
1354
|
+
current = next;
|
|
1355
|
+
}
|
|
1356
|
+
return current;
|
|
1357
|
+
}
|
|
1358
|
+
__name(deepDereference, "deepDereference");
|
|
1359
|
+
|
|
1360
|
+
// src/swagger/for-each-parameter.ts
|
|
1361
|
+
function forEachParameter(openapi, callback) {
|
|
1362
|
+
for (const pathItem of Object.values(openapi.paths)) {
|
|
1363
|
+
for (const operation of Object.values(pathItem)) {
|
|
1364
|
+
if (operation && operation.parameters) {
|
|
1365
|
+
for (const parameter of operation.parameters) {
|
|
1366
|
+
if (!("$ref" in parameter)) {
|
|
1367
|
+
callback(parameter);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
for (const parameter of Object.values(openapi.components?.parameters || {})) {
|
|
1374
|
+
if (!("$ref" in parameter)) {
|
|
1375
|
+
callback(parameter);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
__name(forEachParameter, "forEachParameter");
|
|
1380
|
+
|
|
1381
|
+
// src/swagger/deep-objectify-queries.ts
|
|
1382
|
+
function deepObjectifyQueries(openapi) {
|
|
1383
|
+
forEachParameter(openapi, (parameter) => {
|
|
1384
|
+
if (parameter.in === "query" && parameter.schema && parameter.style === void 0 && (parameter.explode === void 0 || parameter.explode === true)) {
|
|
1385
|
+
const schema = isReferenceObject(parameter.schema) ? deepDereference(openapi, parameter.schema) : parameter.schema;
|
|
1386
|
+
if (schema && (schema.type === "object" || schema.type === "array")) {
|
|
1387
|
+
parameter.style = "deepObject";
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
__name(deepObjectifyQueries, "deepObjectifyQueries");
|
|
1393
|
+
|
|
1394
|
+
// src/pipes/validation.pipe.ts
|
|
1395
|
+
import { MikroORM, EntityManager } from "@mikro-orm/core";
|
|
1396
|
+
import { ValidationPipe } from "@nestjs/common";
|
|
1397
|
+
import { Injectable as Injectable2, Logger as Logger2 } from "@nestjs/common";
|
|
1398
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
1399
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1400
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1401
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1402
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1403
|
+
}
|
|
1404
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
1405
|
+
function _ts_metadata5(k, v) {
|
|
1406
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1407
|
+
}
|
|
1408
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
1409
|
+
function deepMap(obj, fn) {
|
|
1410
|
+
if (Array.isArray(obj)) {
|
|
1411
|
+
return obj.map((item) => deepMap(item, fn));
|
|
1412
|
+
} else {
|
|
1413
|
+
return fn(obj);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
__name(deepMap, "deepMap");
|
|
1417
|
+
function transformReference(em, value, metatype) {
|
|
1418
|
+
if (typeof value !== "object" || value === null) return value;
|
|
1419
|
+
const entityProperties = getMetadata2(metatype);
|
|
1420
|
+
const primaryProperties = entityProperties.filter((p) => p.primary);
|
|
1421
|
+
if (primaryProperties.length === 1) {
|
|
1422
|
+
const propertyKey = primaryProperties[0].name;
|
|
1423
|
+
const ref = em.getReference(metatype, value[propertyKey], {
|
|
1424
|
+
wrapped: true
|
|
1425
|
+
});
|
|
1426
|
+
return ref;
|
|
1427
|
+
} else if (primaryProperties.length > 1) {
|
|
1428
|
+
const propertyKeys = primaryProperties.map((p) => p.name);
|
|
1429
|
+
const ref = em.getReference(metatype, propertyKeys.map((key) => value[key]), {
|
|
1430
|
+
wrapped: true
|
|
1431
|
+
});
|
|
1432
|
+
return ref;
|
|
1433
|
+
}
|
|
1434
|
+
return value;
|
|
1435
|
+
}
|
|
1436
|
+
__name(transformReference, "transformReference");
|
|
1437
|
+
function deepTransform(em, value, metatype) {
|
|
1438
|
+
if (typeof value !== "object" || value === null) {
|
|
1439
|
+
return value;
|
|
1440
|
+
}
|
|
1441
|
+
const propertyKeys = ModelRegister.getModelPropertyKeys(metatype);
|
|
1442
|
+
const result = {
|
|
1443
|
+
...value
|
|
1444
|
+
};
|
|
1445
|
+
for (const propertyKey of propertyKeys) {
|
|
1446
|
+
const propertyMetadata = ModelRegister.getProperty(metatype, propertyKey);
|
|
1447
|
+
if (!propertyMetadata) continue;
|
|
1448
|
+
if (!(propertyKey in value)) continue;
|
|
1449
|
+
const propertyValue = value[propertyKey];
|
|
1450
|
+
if (propertyMetadata.kind === "nested") {
|
|
1451
|
+
const ctor = propertyMetadata.type();
|
|
1452
|
+
if (EntityRefTypeClassMetadataPropertyKey in ctor) {
|
|
1453
|
+
result[propertyKey] = transformReference(em, propertyValue, ctor);
|
|
1454
|
+
} else {
|
|
1455
|
+
const v = deepTransform(em, propertyValue, ctor);
|
|
1456
|
+
result[propertyKey] = v;
|
|
1457
|
+
}
|
|
1458
|
+
} else if (propertyMetadata.kind === "list") {
|
|
1459
|
+
result[propertyKey] = deepMap(propertyValue, (item) => deepTransform(em, item, propertyMetadata.type()));
|
|
1460
|
+
} else if (propertyMetadata.kind === "dictionary") {
|
|
1461
|
+
result[propertyKey] = Object.fromEntries(Object.entries(propertyValue).map(([k, v]) => [
|
|
1462
|
+
k,
|
|
1463
|
+
deepTransform(em, v, propertyMetadata.type())
|
|
1464
|
+
]));
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return result;
|
|
1468
|
+
}
|
|
1469
|
+
__name(deepTransform, "deepTransform");
|
|
1470
|
+
var BukaValidationPipe = class _BukaValidationPipe extends ValidationPipe {
|
|
1471
|
+
static {
|
|
1472
|
+
__name(this, "BukaValidationPipe");
|
|
1473
|
+
}
|
|
1474
|
+
orm;
|
|
1475
|
+
em;
|
|
1476
|
+
logger = new Logger2(_BukaValidationPipe.name);
|
|
1477
|
+
constructor(orm, em) {
|
|
1478
|
+
super(), this.orm = orm, this.em = em;
|
|
1479
|
+
}
|
|
1480
|
+
async transform(value, metadata) {
|
|
1481
|
+
value = await super.transform(value, metadata);
|
|
1482
|
+
if (!metadata.metatype || typeof metadata.metatype !== "function") {
|
|
1483
|
+
return value;
|
|
1484
|
+
}
|
|
1485
|
+
const metatype = metadata.metatype;
|
|
1486
|
+
const result = await deepTransform(this.em, value, metatype);
|
|
1487
|
+
return result;
|
|
1488
|
+
}
|
|
1489
|
+
static withParams(options) {
|
|
1490
|
+
let BukaParametrizedValidationPipe = class BukaParametrizedValidationPipe2 extends ValidationPipe {
|
|
1491
|
+
static {
|
|
1492
|
+
__name(this, "BukaParametrizedValidationPipe");
|
|
1493
|
+
}
|
|
1494
|
+
orm;
|
|
1495
|
+
em;
|
|
1496
|
+
logger = new Logger2(BukaParametrizedValidationPipe2.name);
|
|
1497
|
+
constructor(orm, em) {
|
|
1498
|
+
super(options), this.orm = orm, this.em = em;
|
|
1499
|
+
}
|
|
1500
|
+
async transform(value, metadata) {
|
|
1501
|
+
value = await super.transform(value, metadata);
|
|
1502
|
+
if (!options.transform) return value;
|
|
1503
|
+
if (!metadata.metatype || typeof metadata.metatype !== "function") {
|
|
1504
|
+
return value;
|
|
1505
|
+
}
|
|
1506
|
+
const metatype = metadata.metatype;
|
|
1507
|
+
const result = await deepTransform(this.em, value, metatype);
|
|
1508
|
+
return result;
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
BukaParametrizedValidationPipe = _ts_decorate5([
|
|
1512
|
+
Injectable2(),
|
|
1513
|
+
_ts_metadata5("design:type", Function),
|
|
1514
|
+
_ts_metadata5("design:paramtypes", [
|
|
1515
|
+
typeof MikroORM === "undefined" ? Object : MikroORM,
|
|
1516
|
+
typeof EntityManager === "undefined" ? Object : EntityManager
|
|
1517
|
+
])
|
|
1518
|
+
], BukaParametrizedValidationPipe);
|
|
1519
|
+
return BukaParametrizedValidationPipe;
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
BukaValidationPipe = _ts_decorate5([
|
|
1523
|
+
Injectable2(),
|
|
1524
|
+
_ts_metadata5("design:type", Function),
|
|
1525
|
+
_ts_metadata5("design:paramtypes", [
|
|
1526
|
+
typeof MikroORM === "undefined" ? Object : MikroORM,
|
|
1527
|
+
typeof EntityManager === "undefined" ? Object : EntityManager
|
|
1528
|
+
])
|
|
1529
|
+
], BukaValidationPipe);
|
|
1530
|
+
|
|
1531
|
+
// src/converters/filter-query-type/filter-query-type.ts
|
|
1532
|
+
import * as R8 from "ramda";
|
|
1533
|
+
|
|
1534
|
+
// src/utils/class-validator-utils.ts
|
|
1535
|
+
import * as R6 from "ramda";
|
|
1536
|
+
import { getMetadataStorage } from "class-validator";
|
|
1537
|
+
function getMetadata3(source, propertyKey) {
|
|
1538
|
+
const metadataStorage = getMetadataStorage();
|
|
1539
|
+
const arr = metadataStorage.getTargetValidationMetadatas(source, null, false, false);
|
|
1540
|
+
if (!propertyKey) {
|
|
1541
|
+
const grouped = R6.groupBy((m) => m.propertyName, arr);
|
|
1542
|
+
const result = /* @__PURE__ */ new Map();
|
|
1543
|
+
for (const key in grouped) {
|
|
1544
|
+
result.set(key, grouped[key] || []);
|
|
1545
|
+
}
|
|
1546
|
+
return result;
|
|
1547
|
+
}
|
|
1548
|
+
return arr.filter((item) => item.propertyName === propertyKey);
|
|
1549
|
+
}
|
|
1550
|
+
__name(getMetadata3, "getMetadata");
|
|
1551
|
+
function setMetadata(target, propertyKey, metadata) {
|
|
1552
|
+
const metadataStorage = getMetadataStorage();
|
|
1553
|
+
metadataStorage.addValidationMetadata({
|
|
1554
|
+
...metadata,
|
|
1555
|
+
target,
|
|
1556
|
+
propertyName: propertyKey
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
__name(setMetadata, "setMetadata");
|
|
1560
|
+
|
|
1561
|
+
// src/utils/class-transformer-utils.ts
|
|
1562
|
+
import * as classTransformer from "class-transformer/cjs/storage";
|
|
1563
|
+
function getTransformMetadata(classRef, prop) {
|
|
1564
|
+
const metadataStorage = classTransformer.defaultMetadataStorage;
|
|
1565
|
+
const metadataMap = metadataStorage["_transformMetadatas"];
|
|
1566
|
+
const classMetadata = metadataMap.get(classRef);
|
|
1567
|
+
if (!classMetadata) return;
|
|
1568
|
+
if (!prop) return classMetadata;
|
|
1569
|
+
const propertyMetadata = classMetadata.get(prop);
|
|
1570
|
+
if (!propertyMetadata) return void 0;
|
|
1571
|
+
return Array.isArray(propertyMetadata) ? propertyMetadata : [
|
|
1572
|
+
propertyMetadata
|
|
1573
|
+
];
|
|
1574
|
+
}
|
|
1575
|
+
__name(getTransformMetadata, "getTransformMetadata");
|
|
1576
|
+
function setTransformMetadata(classRef, prop, metadata) {
|
|
1577
|
+
const meta = {
|
|
1578
|
+
...metadata,
|
|
1579
|
+
target: classRef,
|
|
1580
|
+
propertyName: prop
|
|
1581
|
+
};
|
|
1582
|
+
const metadataStorage = classTransformer.defaultMetadataStorage;
|
|
1583
|
+
const metadataMap = metadataStorage["_transformMetadatas"];
|
|
1584
|
+
if (metadataMap.has(classRef)) {
|
|
1585
|
+
const classMetadata = metadataMap.get(classRef);
|
|
1586
|
+
const propertyMetadata = classMetadata.get(prop);
|
|
1587
|
+
if (propertyMetadata) {
|
|
1588
|
+
classMetadata.set(prop, propertyMetadata.concat(meta));
|
|
1589
|
+
} else {
|
|
1590
|
+
classMetadata.set(prop, [
|
|
1591
|
+
meta
|
|
1592
|
+
]);
|
|
1593
|
+
}
|
|
1594
|
+
} else {
|
|
1595
|
+
metadataMap.set(classRef, /* @__PURE__ */ new Map([
|
|
1596
|
+
[
|
|
1597
|
+
prop,
|
|
1598
|
+
[
|
|
1599
|
+
meta
|
|
1600
|
+
]
|
|
1601
|
+
]
|
|
1602
|
+
]));
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
__name(setTransformMetadata, "setTransformMetadata");
|
|
1606
|
+
|
|
1607
|
+
// src/converters/filter-query-type/decorators/filter-query-operators.decorator.ts
|
|
1608
|
+
var FilterQueryOperatorsMetadataKey = "buka:filter-query-operators";
|
|
1609
|
+
function FilterQueryOperators(operators) {
|
|
1610
|
+
if (!operators || operators.length === 0) {
|
|
1611
|
+
throw new TypeError("FilterQueryOperators: operators array must not be empty");
|
|
1612
|
+
}
|
|
1613
|
+
return /* @__PURE__ */ __name(function FilterQueryOperatorsDecorator(target, propertyKey) {
|
|
1614
|
+
Reflect.defineMetadata(FilterQueryOperatorsMetadataKey, operators, target, propertyKey);
|
|
1615
|
+
}, "FilterQueryOperatorsDecorator");
|
|
1616
|
+
}
|
|
1617
|
+
__name(FilterQueryOperators, "FilterQueryOperators");
|
|
1618
|
+
function getFilterQueryOperators(target, propertyKey) {
|
|
1619
|
+
return Reflect.getMetadata(FilterQueryOperatorsMetadataKey, target, propertyKey);
|
|
1620
|
+
}
|
|
1621
|
+
__name(getFilterQueryOperators, "getFilterQueryOperators");
|
|
1622
|
+
|
|
1623
|
+
// src/converters/filter-query-type/filter-query-type.ts
|
|
1624
|
+
import { ArrayMinSize, IS_OPTIONAL, IsArray, IsOptional as IsOptional2 } from "class-validator";
|
|
1625
|
+
|
|
1626
|
+
// src/converters/filter-query-type/utils/get-collection-operators.ts
|
|
1627
|
+
var FilterQueryCollectionOperators = [
|
|
1628
|
+
"$some",
|
|
1629
|
+
"$every",
|
|
1630
|
+
"$none"
|
|
1631
|
+
];
|
|
1632
|
+
function getCollectionOperators(target, propertyKey) {
|
|
1633
|
+
const operators = getFilterQueryOperators(target.prototype, propertyKey);
|
|
1634
|
+
if (!operators) return FilterQueryCollectionOperators;
|
|
1635
|
+
return operators.filter((op) => FilterQueryCollectionOperators.includes(op));
|
|
1636
|
+
}
|
|
1637
|
+
__name(getCollectionOperators, "getCollectionOperators");
|
|
1638
|
+
|
|
1639
|
+
// src/converters/filter-query-type/utils/get-property-operators.ts
|
|
1640
|
+
var FilterQueryPropertyOperators = [
|
|
1641
|
+
"$eq",
|
|
1642
|
+
"$ne",
|
|
1643
|
+
"$lt",
|
|
1644
|
+
"$gt",
|
|
1645
|
+
"$lte",
|
|
1646
|
+
"$gte",
|
|
1647
|
+
"$in",
|
|
1648
|
+
"$nin"
|
|
1649
|
+
];
|
|
1650
|
+
function getPropertyOperators(target, propertyKey) {
|
|
1651
|
+
const operators = getFilterQueryOperators(target.prototype, propertyKey);
|
|
1652
|
+
if (!operators) return FilterQueryPropertyOperators;
|
|
1653
|
+
return operators.filter((op) => FilterQueryPropertyOperators.includes(op));
|
|
1654
|
+
}
|
|
1655
|
+
__name(getPropertyOperators, "getPropertyOperators");
|
|
1656
|
+
|
|
1657
|
+
// src/converters/filter-query-type/utils/swagger-metadata-to-json-schema.ts
|
|
1658
|
+
import * as R7 from "ramda";
|
|
1659
|
+
import { getSchemaPath as getSchemaPath2 } from "@nestjs/swagger";
|
|
1660
|
+
function scalarType(type) {
|
|
1661
|
+
if (typeof type === "string") return {
|
|
1662
|
+
type
|
|
1663
|
+
};
|
|
1664
|
+
if (type === String) return {
|
|
1665
|
+
type: "string"
|
|
1666
|
+
};
|
|
1667
|
+
if (type === Number) return {
|
|
1668
|
+
type: "number"
|
|
1669
|
+
};
|
|
1670
|
+
if (type === Boolean) return {
|
|
1671
|
+
type: "boolean"
|
|
1672
|
+
};
|
|
1673
|
+
return {
|
|
1674
|
+
$ref: getSchemaPath2(type)
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
__name(scalarType, "scalarType");
|
|
1678
|
+
function swaggerMetadataToJsonSchema(metadata) {
|
|
1679
|
+
const base = R7.omit([
|
|
1680
|
+
"type",
|
|
1681
|
+
"required"
|
|
1682
|
+
], metadata);
|
|
1683
|
+
if (isLazyTypeFunc(metadata.type)) {
|
|
1684
|
+
return {
|
|
1685
|
+
...base,
|
|
1686
|
+
...scalarType(metadata.type())
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
return {
|
|
1690
|
+
...base,
|
|
1691
|
+
...scalarType(metadata.type)
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
__name(swaggerMetadataToJsonSchema, "swaggerMetadataToJsonSchema");
|
|
1695
|
+
|
|
1696
|
+
// src/converters/filter-query-type/get-filter-query-schema.ts
|
|
1697
|
+
function getObjectSchema(classRef) {
|
|
1698
|
+
const properties = {};
|
|
1699
|
+
const schema = {
|
|
1700
|
+
type: "object",
|
|
1701
|
+
properties
|
|
1702
|
+
};
|
|
1703
|
+
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
1704
|
+
if (typeof propertyKey !== "string") continue;
|
|
1705
|
+
const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
|
|
1706
|
+
const isCollection = propertyMetadata?.relation?.kind === "1:m" || propertyMetadata?.relation?.kind === "m:n";
|
|
1707
|
+
const isRelation = !!propertyMetadata?.relation;
|
|
1708
|
+
const isOptional = !!propertyMetadata?.optional;
|
|
1709
|
+
if (isRelation) {
|
|
1710
|
+
if (isCollection) {
|
|
1711
|
+
const sub = getObjectSchema(propertyMetadata.relation.type());
|
|
1712
|
+
const operators = getCollectionOperators(classRef, propertyKey);
|
|
1713
|
+
for (const operator of operators) {
|
|
1714
|
+
properties[operator] = sub;
|
|
1715
|
+
}
|
|
1716
|
+
} else {
|
|
1717
|
+
const sub = getObjectSchema(propertyMetadata.relation.type());
|
|
1718
|
+
properties[propertyKey] = sub;
|
|
1719
|
+
}
|
|
1720
|
+
} else {
|
|
1721
|
+
const propertySchema = {
|
|
1722
|
+
type: "object",
|
|
1723
|
+
properties: {}
|
|
1724
|
+
};
|
|
1725
|
+
const originalSchema = getMetadata(classRef, propertyKey);
|
|
1726
|
+
const operators = getPropertyOperators(classRef, propertyKey);
|
|
1727
|
+
for (const operator of operators) {
|
|
1728
|
+
if ([
|
|
1729
|
+
"$in",
|
|
1730
|
+
"$nin"
|
|
1731
|
+
].includes(operator)) {
|
|
1732
|
+
propertySchema.properties[operator] = {
|
|
1733
|
+
type: "array",
|
|
1734
|
+
items: originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : {
|
|
1735
|
+
type: "string"
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
} else {
|
|
1739
|
+
propertySchema.properties[operator] = originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : {
|
|
1740
|
+
type: "string"
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
properties[propertyKey] = propertySchema;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
return schema;
|
|
1748
|
+
}
|
|
1749
|
+
__name(getObjectSchema, "getObjectSchema");
|
|
1750
|
+
function getFilterQuerySchema(classRef) {
|
|
1751
|
+
return {
|
|
1752
|
+
...getObjectSchema(classRef),
|
|
1753
|
+
description: `Filter query for ${classRef.name}`,
|
|
1754
|
+
required: false
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
__name(getFilterQuerySchema, "getFilterQuerySchema");
|
|
1758
|
+
|
|
1759
|
+
// src/converters/filter-query-type/filter-query-type.ts
|
|
1760
|
+
function createFilterQueryPropertyClassRef(classRef, propertyKey) {
|
|
1761
|
+
const propertyClass = class FilterQueryPropertyClass {
|
|
1762
|
+
static {
|
|
1763
|
+
__name(this, "FilterQueryPropertyClass");
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
ModelRegister.addModel(propertyClass);
|
|
1767
|
+
const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
|
|
1768
|
+
const validationMetadataList = getMetadata3(classRef, propertyKey).filter((metadata) => metadata.name !== IS_OPTIONAL);
|
|
1769
|
+
const transformerMetadataList = getTransformMetadata(classRef, propertyKey) || [];
|
|
1770
|
+
const operators = getPropertyOperators(classRef, propertyKey);
|
|
1771
|
+
for (const operator of operators) {
|
|
1772
|
+
if ([
|
|
1773
|
+
"$in",
|
|
1774
|
+
"$nin"
|
|
1775
|
+
].includes(operator)) {
|
|
1776
|
+
ModelRegister.addProperty(propertyClass, operator, {
|
|
1777
|
+
...propertyMetadata,
|
|
1778
|
+
kind: "list",
|
|
1779
|
+
optional: true
|
|
1780
|
+
});
|
|
1781
|
+
IsArray()(propertyClass.prototype, operator);
|
|
1782
|
+
ArrayMinSize(1)(propertyClass.prototype, operator);
|
|
1783
|
+
for (const metadata of validationMetadataList) {
|
|
1784
|
+
setMetadata(propertyClass, operator, {
|
|
1785
|
+
...metadata,
|
|
1786
|
+
each: true
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
for (const metadata of transformerMetadataList) {
|
|
1790
|
+
const transformFn = metadata.transformFn;
|
|
1791
|
+
setTransformMetadata(propertyClass, operator, {
|
|
1792
|
+
...metadata,
|
|
1793
|
+
transformFn: /* @__PURE__ */ __name(function FilterQueryPropertyTransformer(params) {
|
|
1794
|
+
if (Array.isArray(params.value)) {
|
|
1795
|
+
return params.value.map((v, i, arr) => transformFn({
|
|
1796
|
+
...params,
|
|
1797
|
+
value: v,
|
|
1798
|
+
key: i,
|
|
1799
|
+
obj: arr
|
|
1800
|
+
}));
|
|
1801
|
+
}
|
|
1802
|
+
return params.value;
|
|
1803
|
+
}, "FilterQueryPropertyTransformer")
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
} else {
|
|
1807
|
+
ModelRegister.addProperty(propertyClass, operator, {
|
|
1808
|
+
...propertyMetadata,
|
|
1809
|
+
optional: true
|
|
1810
|
+
});
|
|
1811
|
+
for (const metadata of validationMetadataList) {
|
|
1812
|
+
setMetadata(propertyClass, operator, metadata);
|
|
1813
|
+
}
|
|
1814
|
+
for (const metadata of transformerMetadataList) {
|
|
1815
|
+
setTransformMetadata(propertyClass, operator, metadata);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
IsOptional2()(propertyClass.prototype, operator);
|
|
1819
|
+
}
|
|
1820
|
+
return propertyClass;
|
|
1821
|
+
}
|
|
1822
|
+
__name(createFilterQueryPropertyClassRef, "createFilterQueryPropertyClassRef");
|
|
1823
|
+
function createFilterQueryObjectClassRef(classRef) {
|
|
1824
|
+
let FilterQueryObjectClass = class FilterQueryObjectClass {
|
|
1825
|
+
static {
|
|
1826
|
+
__name(this, "FilterQueryObjectClass");
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
1829
|
+
ModelRegister.addModel(FilterQueryObjectClass);
|
|
1830
|
+
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
1831
|
+
if (typeof propertyKey !== "string") continue;
|
|
1832
|
+
const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
|
|
1833
|
+
const isCollection = propertyMetadata?.relation?.kind === "1:m" || propertyMetadata?.relation?.kind === "m:n";
|
|
1834
|
+
const isRelation = !!propertyMetadata?.relation;
|
|
1835
|
+
const isOptional = !!propertyMetadata?.optional;
|
|
1836
|
+
if (isRelation) {
|
|
1837
|
+
if (isCollection) {
|
|
1838
|
+
let FilterQueryCollectionClass = class FilterQueryCollectionClass {
|
|
1839
|
+
static {
|
|
1840
|
+
__name(this, "FilterQueryCollectionClass");
|
|
1841
|
+
}
|
|
1842
|
+
};
|
|
1843
|
+
ModelRegister.addModel(FilterQueryCollectionClass);
|
|
1844
|
+
const sub = createFilterQueryObjectClassRef(propertyMetadata.relation.type());
|
|
1845
|
+
const operators = getCollectionOperators(classRef, propertyKey);
|
|
1846
|
+
for (const operator of operators) {
|
|
1847
|
+
NestedProperty(() => sub, {
|
|
1848
|
+
optional: true
|
|
1849
|
+
})(FilterQueryCollectionClass.prototype, operator);
|
|
1850
|
+
if (!isOptional) {
|
|
1851
|
+
HasAnyKey(getFilterQueryOperators(classRef, propertyKey))(FilterQueryCollectionClass.prototype, operator);
|
|
1852
|
+
}
|
|
1853
|
+
IsOptional2()(FilterQueryCollectionClass.prototype, operator);
|
|
1854
|
+
}
|
|
1855
|
+
NestedProperty(() => FilterQueryCollectionClass, {
|
|
1856
|
+
optional: isOptional
|
|
1857
|
+
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1858
|
+
if (!isOptional) HasAnyKey(operators)(FilterQueryObjectClass.prototype, propertyKey);
|
|
1859
|
+
} else {
|
|
1860
|
+
const sub = createFilterQueryObjectClassRef(propertyMetadata.relation.type());
|
|
1861
|
+
NestedProperty(() => sub, {
|
|
1862
|
+
optional: isOptional
|
|
1863
|
+
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1864
|
+
}
|
|
1865
|
+
} else {
|
|
1866
|
+
const propertyClass = createFilterQueryPropertyClassRef(classRef, propertyKey);
|
|
1867
|
+
NestedProperty(() => propertyClass, {
|
|
1868
|
+
optional: isOptional
|
|
1869
|
+
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1870
|
+
if (!isOptional) {
|
|
1871
|
+
const operators = getPropertyOperators(classRef, propertyKey);
|
|
1872
|
+
HasAnyKey(operators)(FilterQueryObjectClass.prototype, propertyKey);
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
return FilterQueryObjectClass;
|
|
1877
|
+
}
|
|
1878
|
+
__name(createFilterQueryObjectClassRef, "createFilterQueryObjectClassRef");
|
|
1879
|
+
function FilterQueryType(classRef) {
|
|
1880
|
+
if (!ModelRegister.isModel(classRef)) {
|
|
1881
|
+
throw new TypeException("FilterQueryType only accepts a class annotated with @Model().");
|
|
1882
|
+
}
|
|
1883
|
+
const FilterQueryObjectClass = createFilterQueryObjectClassRef(classRef);
|
|
1884
|
+
const properties = ModelRegister.getProperties(FilterQueryObjectClass);
|
|
1885
|
+
const isRequired = R8.any((p) => !p.optional, properties);
|
|
1886
|
+
let FilterQueryClass = class FilterQueryClass {
|
|
1887
|
+
static {
|
|
1888
|
+
__name(this, "FilterQueryClass");
|
|
1889
|
+
}
|
|
1890
|
+
filter;
|
|
1891
|
+
};
|
|
1892
|
+
ModelRegister.addModel(FilterQueryObjectClass);
|
|
1893
|
+
NestedProperty(() => FilterQueryObjectClass, {
|
|
1894
|
+
optional: !isRequired,
|
|
1895
|
+
schema: getFilterQuerySchema(classRef)
|
|
1896
|
+
})(FilterQueryClass.prototype, "filter");
|
|
1897
|
+
return FilterQueryClass;
|
|
1898
|
+
}
|
|
1899
|
+
__name(FilterQueryType, "FilterQueryType");
|
|
1900
|
+
|
|
1901
|
+
// src/converters/pick-type/pick-type.ts
|
|
1902
|
+
import { PickType as SwaggerPickType } from "@nestjs/swagger";
|
|
1903
|
+
function PickType(classRef, keys) {
|
|
1904
|
+
if (!ModelRegister.isModel(classRef)) {
|
|
1905
|
+
throw new TypeException("PickType only accepts a class annotated with @Model().");
|
|
1906
|
+
}
|
|
1907
|
+
const PickTypeClass = SwaggerPickType(classRef, keys);
|
|
1908
|
+
for (const key of keys) {
|
|
1909
|
+
ModelRegister.copyProperty(classRef, PickTypeClass, key);
|
|
1910
|
+
const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
|
|
1911
|
+
for (const metadataKey of metadataKeys) {
|
|
1912
|
+
const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
|
|
1913
|
+
if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
|
|
1914
|
+
Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
return PickTypeClass;
|
|
1918
|
+
}
|
|
1919
|
+
__name(PickType, "PickType");
|
|
1920
|
+
|
|
1921
|
+
// src/converters/omit-type/omit-type.ts
|
|
1922
|
+
import { OmitType as SwaggerOmitType } from "@nestjs/swagger";
|
|
1923
|
+
function OmitType(classRef, keys) {
|
|
1924
|
+
if (!ModelRegister.isModel(classRef)) {
|
|
1925
|
+
throw new TypeException("OmitType only accepts a class annotated with @Model().");
|
|
1926
|
+
}
|
|
1927
|
+
const OmitTypeClass = SwaggerOmitType(classRef, keys);
|
|
1928
|
+
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
1929
|
+
if (keys.includes(propertyKey)) continue;
|
|
1930
|
+
ModelRegister.copyProperty(classRef, OmitTypeClass, propertyKey);
|
|
1931
|
+
const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
|
|
1932
|
+
for (const metadataKey of metadataKeys) {
|
|
1933
|
+
const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
|
|
1934
|
+
if (Reflect.hasMetadata(metadataKey, OmitTypeClass.prototype, propertyKey)) continue;
|
|
1935
|
+
Reflect.defineMetadata(metadataKey, metadata, OmitTypeClass.prototype, propertyKey);
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
return OmitTypeClass;
|
|
1939
|
+
}
|
|
1940
|
+
__name(OmitType, "OmitType");
|
|
1941
|
+
|
|
1942
|
+
// src/converters/partial-type/partial-type.ts
|
|
1943
|
+
import { PartialType as SwaggerPartialType } from "@nestjs/swagger";
|
|
1944
|
+
function PartialType(classRef) {
|
|
1945
|
+
const PartialTypeClass = SwaggerPartialType(classRef);
|
|
1946
|
+
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
1947
|
+
ModelRegister.copyProperty(classRef, PartialTypeClass, propertyKey);
|
|
1948
|
+
const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
|
|
1949
|
+
for (const metadataKey of metadataKeys) {
|
|
1950
|
+
const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
|
|
1951
|
+
if (Reflect.hasMetadata(metadataKey, PartialTypeClass.prototype, propertyKey)) continue;
|
|
1952
|
+
Reflect.defineMetadata(metadataKey, metadata, PartialTypeClass.prototype, propertyKey);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
return PartialTypeClass;
|
|
1956
|
+
}
|
|
1957
|
+
__name(PartialType, "PartialType");
|
|
1958
|
+
|
|
1959
|
+
// src/converters/order-query-type/get-order-query-schema.ts
|
|
1960
|
+
function getOrderQueryEnum() {
|
|
1961
|
+
return {
|
|
1962
|
+
type: "string",
|
|
1963
|
+
enum: [
|
|
1964
|
+
"asc",
|
|
1965
|
+
"asc nulls last",
|
|
1966
|
+
"asc nulls first",
|
|
1967
|
+
"desc",
|
|
1968
|
+
"desc nulls last",
|
|
1969
|
+
"desc nulls first"
|
|
1970
|
+
]
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
__name(getOrderQueryEnum, "getOrderQueryEnum");
|
|
1974
|
+
function getOrderQueryMapSchema(classRef) {
|
|
1975
|
+
const properties = {};
|
|
1976
|
+
const schema = {
|
|
1977
|
+
type: "object",
|
|
1978
|
+
properties,
|
|
1979
|
+
required: []
|
|
1980
|
+
};
|
|
1981
|
+
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
1982
|
+
const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
|
|
1983
|
+
const isRelation = !!propertyMetadata?.relation;
|
|
1984
|
+
if (isRelation) {
|
|
1985
|
+
properties[propertyKey] = getOrderQueryMapSchema(propertyMetadata.relation.type());
|
|
1986
|
+
} else {
|
|
1987
|
+
properties[propertyKey] = getOrderQueryEnum();
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
return schema;
|
|
1991
|
+
}
|
|
1992
|
+
__name(getOrderQueryMapSchema, "getOrderQueryMapSchema");
|
|
1993
|
+
function getOrderQuerySchema(classRef) {
|
|
1994
|
+
const orderQueryMapSchema = getOrderQueryMapSchema(classRef);
|
|
1995
|
+
return {
|
|
1996
|
+
description: `Order query for ${classRef.name}`,
|
|
1997
|
+
oneOf: [
|
|
1998
|
+
{
|
|
1999
|
+
type: "array",
|
|
2000
|
+
items: orderQueryMapSchema
|
|
2001
|
+
},
|
|
2002
|
+
orderQueryMapSchema
|
|
2003
|
+
],
|
|
2004
|
+
required: false
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
__name(getOrderQuerySchema, "getOrderQuerySchema");
|
|
2008
|
+
|
|
2009
|
+
// src/converters/order-query-type/order-query-type.ts
|
|
2010
|
+
function OrderQueryType(classRef) {
|
|
2011
|
+
const schema = getOrderQuerySchema(classRef);
|
|
2012
|
+
let OrderQueryClass = class OrderQueryClass {
|
|
2013
|
+
static {
|
|
2014
|
+
__name(this, "OrderQueryClass");
|
|
2015
|
+
}
|
|
2016
|
+
orderBy;
|
|
2017
|
+
};
|
|
2018
|
+
Property({
|
|
2019
|
+
optional: true,
|
|
2020
|
+
schema
|
|
2021
|
+
})(OrderQueryClass.prototype, "orderBy");
|
|
2022
|
+
MatchJsonSchema(schema, {
|
|
2023
|
+
message: "Invalid order query"
|
|
2024
|
+
})(OrderQueryClass.prototype, "orderBy");
|
|
2025
|
+
return OrderQueryClass;
|
|
2026
|
+
}
|
|
2027
|
+
__name(OrderQueryType, "OrderQueryType");
|
|
2028
|
+
|
|
2029
|
+
// src/ro/offset-pagination.ro.ts
|
|
2030
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
2031
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2032
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2033
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2034
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2035
|
+
}
|
|
2036
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
2037
|
+
function _ts_metadata6(k, v) {
|
|
2038
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2039
|
+
}
|
|
2040
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
2041
|
+
var OffsetPaginationRo = class {
|
|
2042
|
+
static {
|
|
2043
|
+
__name(this, "OffsetPaginationRo");
|
|
2044
|
+
}
|
|
2045
|
+
total;
|
|
2046
|
+
limit;
|
|
2047
|
+
offset;
|
|
2048
|
+
};
|
|
2049
|
+
_ts_decorate6([
|
|
2050
|
+
Property({
|
|
2051
|
+
schema: {
|
|
2052
|
+
type: "number",
|
|
2053
|
+
description: "\u603B\u6570"
|
|
2054
|
+
}
|
|
2055
|
+
}),
|
|
2056
|
+
_ts_metadata6("design:type", Number)
|
|
2057
|
+
], OffsetPaginationRo.prototype, "total", void 0);
|
|
2058
|
+
_ts_decorate6([
|
|
2059
|
+
Property({
|
|
2060
|
+
schema: {
|
|
2061
|
+
type: "number",
|
|
2062
|
+
description: "\u6BCF\u9875\u6570\u91CF"
|
|
2063
|
+
}
|
|
2064
|
+
}),
|
|
2065
|
+
_ts_metadata6("design:type", Number)
|
|
2066
|
+
], OffsetPaginationRo.prototype, "limit", void 0);
|
|
2067
|
+
_ts_decorate6([
|
|
2068
|
+
Property({
|
|
2069
|
+
schema: {
|
|
2070
|
+
type: "number",
|
|
2071
|
+
description: "\u504F\u79FB\u91CF"
|
|
2072
|
+
}
|
|
2073
|
+
}),
|
|
2074
|
+
_ts_metadata6("design:type", Number)
|
|
2075
|
+
], OffsetPaginationRo.prototype, "offset", void 0);
|
|
2076
|
+
OffsetPaginationRo = _ts_decorate6([
|
|
2077
|
+
Model()
|
|
2078
|
+
], OffsetPaginationRo);
|
|
2079
|
+
|
|
2080
|
+
// src/ro/cursor-pagination.ro.ts
|
|
2081
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
2082
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2083
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2084
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2085
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2086
|
+
}
|
|
2087
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
2088
|
+
function _ts_metadata7(k, v) {
|
|
2089
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2090
|
+
}
|
|
2091
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
2092
|
+
var CursorPaginationRo = class {
|
|
2093
|
+
static {
|
|
2094
|
+
__name(this, "CursorPaginationRo");
|
|
2095
|
+
}
|
|
2096
|
+
total;
|
|
2097
|
+
limit;
|
|
2098
|
+
startCursor;
|
|
2099
|
+
endCursor;
|
|
2100
|
+
hasNextPage;
|
|
2101
|
+
hasPrevPage;
|
|
2102
|
+
};
|
|
2103
|
+
_ts_decorate7([
|
|
2104
|
+
Property({
|
|
2105
|
+
schema: {
|
|
2106
|
+
type: "number",
|
|
2107
|
+
description: "\u603B\u6570"
|
|
2108
|
+
}
|
|
2109
|
+
}),
|
|
2110
|
+
_ts_metadata7("design:type", Number)
|
|
2111
|
+
], CursorPaginationRo.prototype, "total", void 0);
|
|
2112
|
+
_ts_decorate7([
|
|
2113
|
+
Property({
|
|
2114
|
+
schema: {
|
|
2115
|
+
type: "number",
|
|
2116
|
+
description: "\u6BCF\u9875\u6570\u91CF"
|
|
2117
|
+
}
|
|
2118
|
+
}),
|
|
2119
|
+
_ts_metadata7("design:type", Number)
|
|
2120
|
+
], CursorPaginationRo.prototype, "limit", void 0);
|
|
2121
|
+
_ts_decorate7([
|
|
2122
|
+
Property({
|
|
2123
|
+
schema: {
|
|
2124
|
+
type: "string",
|
|
2125
|
+
description: "\u5F00\u59CB\u6E38\u6807"
|
|
2126
|
+
}
|
|
2127
|
+
}),
|
|
2128
|
+
_ts_metadata7("design:type", String)
|
|
2129
|
+
], CursorPaginationRo.prototype, "startCursor", void 0);
|
|
2130
|
+
_ts_decorate7([
|
|
2131
|
+
Property({
|
|
2132
|
+
schema: {
|
|
2133
|
+
type: "string",
|
|
2134
|
+
description: "\u7ED3\u675F\u6E38\u6807"
|
|
2135
|
+
}
|
|
2136
|
+
}),
|
|
2137
|
+
_ts_metadata7("design:type", String)
|
|
2138
|
+
], CursorPaginationRo.prototype, "endCursor", void 0);
|
|
2139
|
+
_ts_decorate7([
|
|
2140
|
+
Property({
|
|
2141
|
+
schema: {
|
|
2142
|
+
type: "boolean",
|
|
2143
|
+
description: "\u662F\u5426\u6709\u4E0B\u4E00\u9875"
|
|
2144
|
+
}
|
|
2145
|
+
}),
|
|
2146
|
+
_ts_metadata7("design:type", Boolean)
|
|
2147
|
+
], CursorPaginationRo.prototype, "hasNextPage", void 0);
|
|
2148
|
+
_ts_decorate7([
|
|
2149
|
+
Property({
|
|
2150
|
+
schema: {
|
|
2151
|
+
type: "boolean",
|
|
2152
|
+
description: "\u662F\u5426\u6709\u4E0A\u4E00\u9875"
|
|
2153
|
+
}
|
|
2154
|
+
}),
|
|
2155
|
+
_ts_metadata7("design:type", Boolean)
|
|
2156
|
+
], CursorPaginationRo.prototype, "hasPrevPage", void 0);
|
|
2157
|
+
CursorPaginationRo = _ts_decorate7([
|
|
2158
|
+
Model()
|
|
2159
|
+
], CursorPaginationRo);
|
|
2160
|
+
|
|
2161
|
+
// src/converters/list-response-body-type/list-response-body-type.ts
|
|
2162
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
2163
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2164
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2165
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2166
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2167
|
+
}
|
|
2168
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
2169
|
+
function _ts_metadata8(k, v) {
|
|
2170
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2171
|
+
}
|
|
2172
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2173
|
+
function ListResponseBodyType(classRef, mode) {
|
|
2174
|
+
let ResponseBodyMeta = class ResponseBodyMeta {
|
|
2175
|
+
static {
|
|
2176
|
+
__name(this, "ResponseBodyMeta");
|
|
2177
|
+
}
|
|
2178
|
+
pagination;
|
|
2179
|
+
};
|
|
2180
|
+
if (mode === "cursor") {
|
|
2181
|
+
NestedProperty(() => CursorPaginationRo)(ResponseBodyMeta.prototype, "pagination");
|
|
2182
|
+
} else if (mode === "offset") {
|
|
2183
|
+
NestedProperty(() => OffsetPaginationRo)(ResponseBodyMeta.prototype, "pagination");
|
|
2184
|
+
}
|
|
2185
|
+
let ListResponseBody = class ListResponseBody2 {
|
|
2186
|
+
static {
|
|
2187
|
+
__name(this, "ListResponseBody");
|
|
2188
|
+
}
|
|
2189
|
+
data;
|
|
2190
|
+
meta;
|
|
2191
|
+
constructor(data, meta) {
|
|
2192
|
+
this.data = data;
|
|
2193
|
+
this.meta = meta;
|
|
2194
|
+
}
|
|
2195
|
+
static fromSlice(slice) {
|
|
2196
|
+
const data = slice.data;
|
|
2197
|
+
const meta = {
|
|
2198
|
+
pagination: slice.pagination
|
|
2199
|
+
};
|
|
2200
|
+
const res = new ListResponseBody2(data, meta);
|
|
2201
|
+
return res;
|
|
2202
|
+
}
|
|
2203
|
+
};
|
|
2204
|
+
_ts_decorate8([
|
|
2205
|
+
NestedProperty(() => classRef, {
|
|
2206
|
+
each: true
|
|
2207
|
+
}),
|
|
2208
|
+
_ts_metadata8("design:type", Array)
|
|
2209
|
+
], ListResponseBody.prototype, "data", void 0);
|
|
2210
|
+
_ts_decorate8([
|
|
2211
|
+
NestedProperty(() => ResponseBodyMeta),
|
|
2212
|
+
_ts_metadata8("design:type", typeof ResponseBodyMeta === "undefined" ? Object : ResponseBodyMeta)
|
|
2213
|
+
], ListResponseBody.prototype, "meta", void 0);
|
|
2214
|
+
return ListResponseBody;
|
|
2215
|
+
}
|
|
2216
|
+
__name(ListResponseBodyType, "ListResponseBodyType");
|
|
2217
|
+
|
|
2218
|
+
// src/converters/response-body-type/response-body-type.ts
|
|
2219
|
+
function ResponseBodyType(classRef) {
|
|
2220
|
+
let ResponseBodyClass = class ResponseBodyClass2 {
|
|
2221
|
+
static {
|
|
2222
|
+
__name(this, "ResponseBodyClass");
|
|
2223
|
+
}
|
|
2224
|
+
data;
|
|
2225
|
+
constructor(data) {
|
|
2226
|
+
this.data = data;
|
|
2227
|
+
}
|
|
2228
|
+
static from(data, meta) {
|
|
2229
|
+
const instance = new ResponseBodyClass2(data);
|
|
2230
|
+
return instance;
|
|
2231
|
+
}
|
|
2232
|
+
};
|
|
2233
|
+
Property({
|
|
2234
|
+
type: /* @__PURE__ */ __name(() => classRef, "type"),
|
|
2235
|
+
schema: {
|
|
2236
|
+
type: /* @__PURE__ */ __name(() => classRef, "type")
|
|
2237
|
+
}
|
|
2238
|
+
})(ResponseBodyClass.prototype, "data");
|
|
2239
|
+
Property({
|
|
2240
|
+
type: /* @__PURE__ */ __name(() => Object, "type"),
|
|
2241
|
+
schema: {
|
|
2242
|
+
additionalProperties: true
|
|
2243
|
+
}
|
|
2244
|
+
});
|
|
2245
|
+
return ResponseBodyClass;
|
|
2246
|
+
}
|
|
2247
|
+
__name(ResponseBodyType, "ResponseBodyType");
|
|
2248
|
+
|
|
2249
|
+
// src/models/offset-pagination.ts
|
|
2250
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
2251
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2252
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2253
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2254
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2255
|
+
}
|
|
2256
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
2257
|
+
function _ts_metadata9(k, v) {
|
|
2258
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2259
|
+
}
|
|
2260
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2261
|
+
var OffsetPagination = class {
|
|
2262
|
+
static {
|
|
2263
|
+
__name(this, "OffsetPagination");
|
|
2264
|
+
}
|
|
2265
|
+
total;
|
|
2266
|
+
limit;
|
|
2267
|
+
offset;
|
|
2268
|
+
constructor(total, parameters) {
|
|
2269
|
+
this.total = total;
|
|
2270
|
+
this.limit = parameters.limit;
|
|
2271
|
+
this.offset = parameters.offset;
|
|
2272
|
+
}
|
|
2273
|
+
};
|
|
2274
|
+
_ts_decorate9([
|
|
2275
|
+
Property({
|
|
2276
|
+
schema: {
|
|
2277
|
+
type: "number",
|
|
2278
|
+
description: "\u603B\u6570"
|
|
2279
|
+
}
|
|
2280
|
+
}),
|
|
2281
|
+
_ts_metadata9("design:type", Number)
|
|
2282
|
+
], OffsetPagination.prototype, "total", void 0);
|
|
2283
|
+
_ts_decorate9([
|
|
2284
|
+
Property({
|
|
2285
|
+
schema: {
|
|
2286
|
+
type: "number",
|
|
2287
|
+
description: "\u6BCF\u9875\u6570\u91CF"
|
|
2288
|
+
}
|
|
2289
|
+
}),
|
|
2290
|
+
_ts_metadata9("design:type", Number)
|
|
2291
|
+
], OffsetPagination.prototype, "limit", void 0);
|
|
2292
|
+
_ts_decorate9([
|
|
2293
|
+
Property({
|
|
2294
|
+
schema: {
|
|
2295
|
+
type: "number",
|
|
2296
|
+
description: "\u504F\u79FB\u91CF"
|
|
2297
|
+
}
|
|
2298
|
+
}),
|
|
2299
|
+
_ts_metadata9("design:type", Number)
|
|
2300
|
+
], OffsetPagination.prototype, "offset", void 0);
|
|
2301
|
+
OffsetPagination = _ts_decorate9([
|
|
2302
|
+
Model(),
|
|
2303
|
+
_ts_metadata9("design:type", Function),
|
|
2304
|
+
_ts_metadata9("design:paramtypes", [
|
|
2305
|
+
Number,
|
|
2306
|
+
Object
|
|
2307
|
+
])
|
|
2308
|
+
], OffsetPagination);
|
|
2309
|
+
|
|
2310
|
+
// src/models/cursor-pagination.ts
|
|
2311
|
+
import { Cursor } from "@mikro-orm/core";
|
|
2312
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
2313
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2314
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2315
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2316
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2317
|
+
}
|
|
2318
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
2319
|
+
function _ts_metadata10(k, v) {
|
|
2320
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2321
|
+
}
|
|
2322
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
2323
|
+
var CursorPagination = class {
|
|
2324
|
+
static {
|
|
2325
|
+
__name(this, "CursorPagination");
|
|
2326
|
+
}
|
|
2327
|
+
total;
|
|
2328
|
+
limit;
|
|
2329
|
+
startCursor;
|
|
2330
|
+
endCursor;
|
|
2331
|
+
hasNextPage;
|
|
2332
|
+
hasPrevPage;
|
|
2333
|
+
constructor(cursor) {
|
|
2334
|
+
this.total = cursor.totalCount;
|
|
2335
|
+
this.limit = cursor.length;
|
|
2336
|
+
this.startCursor = cursor.startCursor;
|
|
2337
|
+
this.endCursor = cursor.endCursor;
|
|
2338
|
+
this.hasNextPage = cursor.hasNextPage;
|
|
2339
|
+
this.hasPrevPage = cursor.hasPrevPage;
|
|
2340
|
+
}
|
|
2341
|
+
};
|
|
2342
|
+
_ts_decorate10([
|
|
2343
|
+
Property({
|
|
2344
|
+
schema: {
|
|
2345
|
+
type: "number",
|
|
2346
|
+
description: "\u603B\u6570"
|
|
2347
|
+
}
|
|
2348
|
+
}),
|
|
2349
|
+
_ts_metadata10("design:type", Number)
|
|
2350
|
+
], CursorPagination.prototype, "total", void 0);
|
|
2351
|
+
_ts_decorate10([
|
|
2352
|
+
Property({
|
|
2353
|
+
schema: {
|
|
2354
|
+
type: "number",
|
|
2355
|
+
description: "\u6BCF\u9875\u6570\u91CF"
|
|
2356
|
+
}
|
|
2357
|
+
}),
|
|
2358
|
+
_ts_metadata10("design:type", Number)
|
|
2359
|
+
], CursorPagination.prototype, "limit", void 0);
|
|
2360
|
+
_ts_decorate10([
|
|
2361
|
+
Property({
|
|
2362
|
+
schema: {
|
|
2363
|
+
type: "string",
|
|
2364
|
+
description: "\u5F00\u59CB\u6E38\u6807",
|
|
2365
|
+
nullable: true
|
|
2366
|
+
}
|
|
2367
|
+
}),
|
|
2368
|
+
_ts_metadata10("design:type", Object)
|
|
2369
|
+
], CursorPagination.prototype, "startCursor", void 0);
|
|
2370
|
+
_ts_decorate10([
|
|
2371
|
+
Property({
|
|
2372
|
+
schema: {
|
|
2373
|
+
type: "string",
|
|
2374
|
+
description: "\u7ED3\u675F\u6E38\u6807",
|
|
2375
|
+
nullable: true
|
|
2376
|
+
}
|
|
2377
|
+
}),
|
|
2378
|
+
_ts_metadata10("design:type", Object)
|
|
2379
|
+
], CursorPagination.prototype, "endCursor", void 0);
|
|
2380
|
+
_ts_decorate10([
|
|
2381
|
+
Property({
|
|
2382
|
+
schema: {
|
|
2383
|
+
type: "boolean",
|
|
2384
|
+
description: "\u662F\u5426\u6709\u4E0B\u4E00\u9875"
|
|
2385
|
+
}
|
|
2386
|
+
}),
|
|
2387
|
+
_ts_metadata10("design:type", Boolean)
|
|
2388
|
+
], CursorPagination.prototype, "hasNextPage", void 0);
|
|
2389
|
+
_ts_decorate10([
|
|
2390
|
+
Property({
|
|
2391
|
+
schema: {
|
|
2392
|
+
type: "boolean",
|
|
2393
|
+
description: "\u662F\u5426\u6709\u4E0A\u4E00\u9875"
|
|
2394
|
+
}
|
|
2395
|
+
}),
|
|
2396
|
+
_ts_metadata10("design:type", Boolean)
|
|
2397
|
+
], CursorPagination.prototype, "hasPrevPage", void 0);
|
|
2398
|
+
CursorPagination = _ts_decorate10([
|
|
2399
|
+
Model(),
|
|
2400
|
+
_ts_metadata10("design:type", Function),
|
|
2401
|
+
_ts_metadata10("design:paramtypes", [
|
|
2402
|
+
typeof Cursor === "undefined" ? Object : Cursor
|
|
2403
|
+
])
|
|
2404
|
+
], CursorPagination);
|
|
2405
|
+
|
|
2406
|
+
// src/models/slice.ts
|
|
2407
|
+
var Slice = class _Slice {
|
|
2408
|
+
static {
|
|
2409
|
+
__name(this, "Slice");
|
|
2410
|
+
}
|
|
2411
|
+
data;
|
|
2412
|
+
pagination;
|
|
2413
|
+
constructor(data, pagination) {
|
|
2414
|
+
this.data = data;
|
|
2415
|
+
this.pagination = pagination;
|
|
2416
|
+
}
|
|
2417
|
+
*[Symbol.iterator]() {
|
|
2418
|
+
for (const item of this.data) {
|
|
2419
|
+
yield item;
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
static fromOffset(data, total, parameters) {
|
|
2423
|
+
const pagination = new OffsetPagination(total, parameters);
|
|
2424
|
+
return new _Slice(data, pagination);
|
|
2425
|
+
}
|
|
2426
|
+
static fromCursor(cursor) {
|
|
2427
|
+
const pagination = new CursorPagination(cursor);
|
|
2428
|
+
return new _Slice(cursor.items, pagination);
|
|
2429
|
+
}
|
|
2430
|
+
map(fn) {
|
|
2431
|
+
const mappedData = this.data.map(fn);
|
|
2432
|
+
return new _Slice(mappedData, this.pagination);
|
|
2433
|
+
}
|
|
2434
|
+
};
|
|
2435
|
+
export {
|
|
2436
|
+
BaseEntity,
|
|
2437
|
+
BukaValidationPipe,
|
|
2438
|
+
DatabaseConfig,
|
|
2439
|
+
EntityDtoType,
|
|
2440
|
+
EntityEnum,
|
|
2441
|
+
EntityManyToMany,
|
|
2442
|
+
EntityManyToOne,
|
|
2443
|
+
EntityOneToMany,
|
|
2444
|
+
EntityOneToOne,
|
|
2445
|
+
EntityProperty,
|
|
2446
|
+
EntityRefType,
|
|
2447
|
+
EntityRefTypeClassMetadataPropertyKey,
|
|
2448
|
+
EntityTransient,
|
|
2449
|
+
FilterQueryOperators,
|
|
2450
|
+
FilterQueryOperatorsMetadataKey,
|
|
2451
|
+
FilterQueryType,
|
|
2452
|
+
HAS_ANY_KEY,
|
|
2453
|
+
HasAnyKey,
|
|
2454
|
+
ListResponseBodyType,
|
|
2455
|
+
MATCH_JSON_SCHEMA,
|
|
2456
|
+
MatchJsonSchema,
|
|
2457
|
+
Model,
|
|
2458
|
+
ModelRegister,
|
|
2459
|
+
Nested,
|
|
2460
|
+
NestedProperty,
|
|
2461
|
+
OmitType,
|
|
2462
|
+
OptionalPageQuery,
|
|
2463
|
+
OrderQueryType,
|
|
2464
|
+
PageQuery,
|
|
2465
|
+
PartialType,
|
|
2466
|
+
PickType,
|
|
2467
|
+
Property,
|
|
2468
|
+
RELATION_METADATA_KEY,
|
|
2469
|
+
ReferencePropertiesMetadataKey,
|
|
2470
|
+
ReferenceProperty,
|
|
2471
|
+
Relation,
|
|
2472
|
+
ResponseBodyType,
|
|
2473
|
+
Slice,
|
|
2474
|
+
TimestampedEntity,
|
|
2475
|
+
deepObjectifyQueries,
|
|
2476
|
+
getFilterQueryOperators
|
|
2477
|
+
};
|
|
2478
|
+
//# sourceMappingURL=index.mjs.map
|