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.mjs
CHANGED
|
@@ -117,6 +117,7 @@ import {
|
|
|
117
117
|
IsNumber,
|
|
118
118
|
IsOptional as IsOptional2,
|
|
119
119
|
IsString,
|
|
120
|
+
IsUUID,
|
|
120
121
|
MaxLength,
|
|
121
122
|
Min,
|
|
122
123
|
ValidateNested as ValidateNested2
|
|
@@ -140,6 +141,16 @@ var BigintTransformer = class {
|
|
|
140
141
|
import { getClassFromClassOrArray as getClassFromClassOrArray2 } from "nesties";
|
|
141
142
|
|
|
142
143
|
// src/utility/type-transformer.ts
|
|
144
|
+
var nonTransformableTypes = /* @__PURE__ */ new Set([String, Number, Boolean]);
|
|
145
|
+
var toValue = (cl, value) => {
|
|
146
|
+
if (nonTransformableTypes.has(cl)) {
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
if (cl === Date) {
|
|
150
|
+
return new Date(value);
|
|
151
|
+
}
|
|
152
|
+
return Object.assign(new cl(), value);
|
|
153
|
+
};
|
|
143
154
|
var TypeTransformer = class {
|
|
144
155
|
constructor(definition) {
|
|
145
156
|
this.definition = definition;
|
|
@@ -149,11 +160,9 @@ var TypeTransformer = class {
|
|
|
149
160
|
return dbValue;
|
|
150
161
|
}
|
|
151
162
|
if (Array.isArray(this.definition)) {
|
|
152
|
-
return dbValue.map(
|
|
153
|
-
(value) => Object.assign(new this.definition[0](), value)
|
|
154
|
-
);
|
|
163
|
+
return dbValue.map((value) => toValue(this.definition[0], value));
|
|
155
164
|
}
|
|
156
|
-
return
|
|
165
|
+
return toValue(this.definition, dbValue);
|
|
157
166
|
}
|
|
158
167
|
to(entValue) {
|
|
159
168
|
return entValue;
|
|
@@ -195,6 +204,24 @@ var StringColumn = (length, options = {}) => {
|
|
|
195
204
|
swaggerDecorator(options, { type: String, maxLength: length })
|
|
196
205
|
]);
|
|
197
206
|
};
|
|
207
|
+
var UuidColumn = (options = {}) => {
|
|
208
|
+
return MergePropertyDecorators2([
|
|
209
|
+
Column("uuid", {
|
|
210
|
+
...columnDecoratorOptions(options),
|
|
211
|
+
...options.generated ? {
|
|
212
|
+
nullable: false,
|
|
213
|
+
generated: "uuid"
|
|
214
|
+
} : {}
|
|
215
|
+
}),
|
|
216
|
+
IsUUID(),
|
|
217
|
+
validatorDecorator(options),
|
|
218
|
+
swaggerDecorator(options, {
|
|
219
|
+
type: String,
|
|
220
|
+
format: "uuid",
|
|
221
|
+
example: "550e8400-e29b-41d4-a716-446655440000"
|
|
222
|
+
})
|
|
223
|
+
]);
|
|
224
|
+
};
|
|
198
225
|
var IntColumn = (type, options = {}) => {
|
|
199
226
|
const decs = [
|
|
200
227
|
Column(type, {
|
|
@@ -677,8 +704,8 @@ __decorateClass([
|
|
|
677
704
|
], TimeBase.prototype, "deleteTime", 2);
|
|
678
705
|
|
|
679
706
|
// src/bases/id-base.ts
|
|
680
|
-
import { Generated } from "typeorm";
|
|
681
|
-
import { IsNotEmpty as IsNotEmpty2
|
|
707
|
+
import { Generated as Generated2 } from "typeorm";
|
|
708
|
+
import { IsNotEmpty as IsNotEmpty2 } from "class-validator";
|
|
682
709
|
import { MergePropertyDecorators as MergePropertyDecorators4 } from "nesties";
|
|
683
710
|
function IdBase(idOptions = {}) {
|
|
684
711
|
const cl = class IdBase extends TimeBase {
|
|
@@ -687,7 +714,6 @@ function IdBase(idOptions = {}) {
|
|
|
687
714
|
if (!idOptions.noOrderById) {
|
|
688
715
|
qb.orderBy(`${entityName}.id`, "DESC");
|
|
689
716
|
}
|
|
690
|
-
applyQueryProperty(this, qb, entityName, "id");
|
|
691
717
|
}
|
|
692
718
|
};
|
|
693
719
|
const dec = MergePropertyDecorators4([
|
|
@@ -698,7 +724,8 @@ function IdBase(idOptions = {}) {
|
|
|
698
724
|
columnExtras: { nullable: false, primary: true }
|
|
699
725
|
}),
|
|
700
726
|
Reflect.metadata("design:type", Number),
|
|
701
|
-
|
|
727
|
+
Generated2("increment"),
|
|
728
|
+
QueryEqual()
|
|
702
729
|
]);
|
|
703
730
|
dec(cl.prototype, "id");
|
|
704
731
|
return cl;
|
|
@@ -707,19 +734,24 @@ function StringIdBase(idOptions) {
|
|
|
707
734
|
const cl = class StringIdBase extends TimeBase {
|
|
708
735
|
applyQuery(qb, entityName) {
|
|
709
736
|
super.applyQuery(qb, entityName);
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
737
|
+
if (!idOptions.noOrderById) {
|
|
738
|
+
qb.orderBy(`${entityName}.id`, "ASC");
|
|
739
|
+
}
|
|
713
740
|
}
|
|
714
741
|
};
|
|
742
|
+
const columnOptions = {
|
|
743
|
+
required: !idOptions.uuid,
|
|
744
|
+
description: idOptions.description,
|
|
745
|
+
columnExtras: { primary: true, nullable: false }
|
|
746
|
+
};
|
|
715
747
|
const decs = [
|
|
716
|
-
StringColumn(idOptions.length || (idOptions.uuid ? void 0 : 255), {
|
|
717
|
-
required: !idOptions.uuid,
|
|
718
|
-
description: idOptions.description,
|
|
719
|
-
columnExtras: { primary: true, nullable: false }
|
|
720
|
-
}),
|
|
721
748
|
Reflect.metadata("design:type", String),
|
|
722
|
-
|
|
749
|
+
QueryEqual(),
|
|
750
|
+
...idOptions.uuid ? [UuidColumn({ ...columnOptions, generated: true }), NotWritable()] : [
|
|
751
|
+
StringColumn(idOptions.length || 255, columnOptions),
|
|
752
|
+
IsNotEmpty2(),
|
|
753
|
+
NotChangeable()
|
|
754
|
+
]
|
|
723
755
|
];
|
|
724
756
|
const dec = MergePropertyDecorators4(decs);
|
|
725
757
|
dec(cl.prototype, "id");
|
|
@@ -2175,6 +2207,7 @@ export {
|
|
|
2175
2207
|
StringIdBase,
|
|
2176
2208
|
TimeBase,
|
|
2177
2209
|
UpdatePipe,
|
|
2210
|
+
UuidColumn,
|
|
2178
2211
|
applyQueryMatchBoolean,
|
|
2179
2212
|
applyQueryProperty,
|
|
2180
2213
|
applyQueryPropertyLike,
|