nicot 1.1.29 → 1.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +48 -15
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +50 -17
- package/dist/index.mjs.map +3 -3
- package/dist/src/decorators/property.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -86,6 +86,7 @@ __export(index_exports, {
|
|
|
86
86
|
StringIdBase: () => StringIdBase,
|
|
87
87
|
TimeBase: () => TimeBase,
|
|
88
88
|
UpdatePipe: () => UpdatePipe,
|
|
89
|
+
UuidColumn: () => UuidColumn,
|
|
89
90
|
applyQueryMatchBoolean: () => applyQueryMatchBoolean,
|
|
90
91
|
applyQueryProperty: () => applyQueryProperty,
|
|
91
92
|
applyQueryPropertyLike: () => applyQueryPropertyLike,
|
|
@@ -202,6 +203,16 @@ var BigintTransformer = class {
|
|
|
202
203
|
var import_nesties4 = require("nesties");
|
|
203
204
|
|
|
204
205
|
// src/utility/type-transformer.ts
|
|
206
|
+
var nonTransformableTypes = /* @__PURE__ */ new Set([String, Number, Boolean]);
|
|
207
|
+
var toValue = (cl, value) => {
|
|
208
|
+
if (nonTransformableTypes.has(cl)) {
|
|
209
|
+
return value;
|
|
210
|
+
}
|
|
211
|
+
if (cl === Date) {
|
|
212
|
+
return new Date(value);
|
|
213
|
+
}
|
|
214
|
+
return Object.assign(new cl(), value);
|
|
215
|
+
};
|
|
205
216
|
var TypeTransformer = class {
|
|
206
217
|
constructor(definition) {
|
|
207
218
|
this.definition = definition;
|
|
@@ -211,11 +222,9 @@ var TypeTransformer = class {
|
|
|
211
222
|
return dbValue;
|
|
212
223
|
}
|
|
213
224
|
if (Array.isArray(this.definition)) {
|
|
214
|
-
return dbValue.map(
|
|
215
|
-
(value) => Object.assign(new this.definition[0](), value)
|
|
216
|
-
);
|
|
225
|
+
return dbValue.map((value) => toValue(this.definition[0], value));
|
|
217
226
|
}
|
|
218
|
-
return
|
|
227
|
+
return toValue(this.definition, dbValue);
|
|
219
228
|
}
|
|
220
229
|
to(entValue) {
|
|
221
230
|
return entValue;
|
|
@@ -257,6 +266,24 @@ var StringColumn = (length, options = {}) => {
|
|
|
257
266
|
swaggerDecorator(options, { type: String, maxLength: length })
|
|
258
267
|
]);
|
|
259
268
|
};
|
|
269
|
+
var UuidColumn = (options = {}) => {
|
|
270
|
+
return (0, import_nesties3.MergePropertyDecorators)([
|
|
271
|
+
(0, import_typeorm.Column)("uuid", {
|
|
272
|
+
...columnDecoratorOptions(options),
|
|
273
|
+
...options.generated ? {
|
|
274
|
+
nullable: false,
|
|
275
|
+
generated: "uuid"
|
|
276
|
+
} : {}
|
|
277
|
+
}),
|
|
278
|
+
(0, import_class_validator3.IsUUID)(),
|
|
279
|
+
validatorDecorator(options),
|
|
280
|
+
swaggerDecorator(options, {
|
|
281
|
+
type: String,
|
|
282
|
+
format: "uuid",
|
|
283
|
+
example: "550e8400-e29b-41d4-a716-446655440000"
|
|
284
|
+
})
|
|
285
|
+
]);
|
|
286
|
+
};
|
|
260
287
|
var IntColumn = (type, options = {}) => {
|
|
261
288
|
const decs = [
|
|
262
289
|
(0, import_typeorm.Column)(type, {
|
|
@@ -743,7 +770,6 @@ function IdBase(idOptions = {}) {
|
|
|
743
770
|
if (!idOptions.noOrderById) {
|
|
744
771
|
qb.orderBy(`${entityName}.id`, "DESC");
|
|
745
772
|
}
|
|
746
|
-
applyQueryProperty(this, qb, entityName, "id");
|
|
747
773
|
}
|
|
748
774
|
};
|
|
749
775
|
const dec = (0, import_nesties7.MergePropertyDecorators)([
|
|
@@ -754,7 +780,8 @@ function IdBase(idOptions = {}) {
|
|
|
754
780
|
columnExtras: { nullable: false, primary: true }
|
|
755
781
|
}),
|
|
756
782
|
Reflect.metadata("design:type", Number),
|
|
757
|
-
(0, import_typeorm3.Generated)("increment")
|
|
783
|
+
(0, import_typeorm3.Generated)("increment"),
|
|
784
|
+
QueryEqual()
|
|
758
785
|
]);
|
|
759
786
|
dec(cl.prototype, "id");
|
|
760
787
|
return cl;
|
|
@@ -763,19 +790,24 @@ function StringIdBase(idOptions) {
|
|
|
763
790
|
const cl = class StringIdBase extends TimeBase {
|
|
764
791
|
applyQuery(qb, entityName) {
|
|
765
792
|
super.applyQuery(qb, entityName);
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
793
|
+
if (!idOptions.noOrderById) {
|
|
794
|
+
qb.orderBy(`${entityName}.id`, "ASC");
|
|
795
|
+
}
|
|
769
796
|
}
|
|
770
797
|
};
|
|
798
|
+
const columnOptions = {
|
|
799
|
+
required: !idOptions.uuid,
|
|
800
|
+
description: idOptions.description,
|
|
801
|
+
columnExtras: { primary: true, nullable: false }
|
|
802
|
+
};
|
|
771
803
|
const decs = [
|
|
772
|
-
StringColumn(idOptions.length || (idOptions.uuid ? void 0 : 255), {
|
|
773
|
-
required: !idOptions.uuid,
|
|
774
|
-
description: idOptions.description,
|
|
775
|
-
columnExtras: { primary: true, nullable: false }
|
|
776
|
-
}),
|
|
777
804
|
Reflect.metadata("design:type", String),
|
|
778
|
-
|
|
805
|
+
QueryEqual(),
|
|
806
|
+
...idOptions.uuid ? [UuidColumn({ ...columnOptions, generated: true }), NotWritable()] : [
|
|
807
|
+
StringColumn(idOptions.length || 255, columnOptions),
|
|
808
|
+
(0, import_class_validator6.IsNotEmpty)(),
|
|
809
|
+
NotChangeable()
|
|
810
|
+
]
|
|
779
811
|
];
|
|
780
812
|
const dec = (0, import_nesties7.MergePropertyDecorators)(decs);
|
|
781
813
|
dec(cl.prototype, "id");
|
|
@@ -2201,6 +2233,7 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
2201
2233
|
StringIdBase,
|
|
2202
2234
|
TimeBase,
|
|
2203
2235
|
UpdatePipe,
|
|
2236
|
+
UuidColumn,
|
|
2204
2237
|
applyQueryMatchBoolean,
|
|
2205
2238
|
applyQueryProperty,
|
|
2206
2239
|
applyQueryPropertyLike,
|