nicot 1.1.33 → 1.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/index.cjs +174 -31
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +172 -33
- package/dist/index.mjs.map +4 -4
- package/dist/src/decorators/property.d.ts +27 -4
- package/dist/src/decorators/query.d.ts +1 -0
- package/dist/src/restful.d.ts +1 -0
- package/dist/src/utility/metadata.d.ts +1 -0
- package/dist/src/utility/parse-bool.d.ts +8 -0
- package/dist/src/utility/query.d.ts +1 -0
- package/dist/src/utility/type-transformer.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -118,6 +118,7 @@ import {
|
|
|
118
118
|
IsOptional as IsOptional2,
|
|
119
119
|
IsString,
|
|
120
120
|
IsUUID,
|
|
121
|
+
Max,
|
|
121
122
|
MaxLength,
|
|
122
123
|
Min,
|
|
123
124
|
ValidateNested as ValidateNested2
|
|
@@ -212,10 +213,52 @@ var TypeTransformer = class {
|
|
|
212
213
|
return entValue;
|
|
213
214
|
}
|
|
214
215
|
};
|
|
216
|
+
var TypeTransformerString = class extends TypeTransformer {
|
|
217
|
+
from(dbValue) {
|
|
218
|
+
if (dbValue == null) {
|
|
219
|
+
return dbValue;
|
|
220
|
+
}
|
|
221
|
+
return super.from(JSON.parse(dbValue));
|
|
222
|
+
}
|
|
223
|
+
to(entValue) {
|
|
224
|
+
if (entValue == null) {
|
|
225
|
+
return entValue;
|
|
226
|
+
}
|
|
227
|
+
return JSON.stringify(super.to(entValue));
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// src/utility/parse-bool.ts
|
|
232
|
+
var parseBool = (value) => {
|
|
233
|
+
const trueValues = ["true", "1", "yes", "on", true, 1];
|
|
234
|
+
const falseValues = ["false", "0", "no", "off", false, 0];
|
|
235
|
+
if (trueValues.indexOf(value) !== -1) return true;
|
|
236
|
+
if (falseValues.indexOf(value) !== -1) return false;
|
|
237
|
+
if (!!value) {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
return void 0;
|
|
241
|
+
};
|
|
242
|
+
var parseBoolObject = (obj, boolFields) => {
|
|
243
|
+
const newObj = { ...obj };
|
|
244
|
+
for (const field of boolFields) {
|
|
245
|
+
newObj[field] = parseBool(newObj[field]);
|
|
246
|
+
}
|
|
247
|
+
return newObj;
|
|
248
|
+
};
|
|
249
|
+
var ParseBoolObjectPipe = class {
|
|
250
|
+
constructor(boolFields) {
|
|
251
|
+
this.boolFields = boolFields;
|
|
252
|
+
}
|
|
253
|
+
transform(obj) {
|
|
254
|
+
return parseBoolObject(obj, this.boolFields);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
215
257
|
|
|
216
258
|
// src/decorators/property.ts
|
|
217
259
|
function swaggerDecorator(options, injected = {}) {
|
|
218
|
-
|
|
260
|
+
const notRequiredButHasDefault = options.required == null && options.default != null;
|
|
261
|
+
const apiPropertyDec = ApiProperty2({
|
|
219
262
|
default: options.default,
|
|
220
263
|
required: !!(options.required && options.default == null),
|
|
221
264
|
example: options.default,
|
|
@@ -223,6 +266,18 @@ function swaggerDecorator(options, injected = {}) {
|
|
|
223
266
|
...injected,
|
|
224
267
|
...options.propertyExtras || {}
|
|
225
268
|
});
|
|
269
|
+
if (notRequiredButHasDefault) {
|
|
270
|
+
return MergePropertyDecorators2([
|
|
271
|
+
apiPropertyDec,
|
|
272
|
+
Metadata.set(
|
|
273
|
+
"notRequiredButHasDefault",
|
|
274
|
+
true,
|
|
275
|
+
"notRequiredButHasDefaultFields"
|
|
276
|
+
)
|
|
277
|
+
]);
|
|
278
|
+
} else {
|
|
279
|
+
return apiPropertyDec;
|
|
280
|
+
}
|
|
226
281
|
}
|
|
227
282
|
function validatorDecorator(options) {
|
|
228
283
|
const decs = [];
|
|
@@ -241,13 +296,24 @@ function columnDecoratorOptions(options) {
|
|
|
241
296
|
}
|
|
242
297
|
var StringColumn = (length, options = {}) => {
|
|
243
298
|
return MergePropertyDecorators2([
|
|
244
|
-
Column("varchar", {
|
|
299
|
+
Column(options.columnType || "varchar", {
|
|
300
|
+
length,
|
|
301
|
+
...columnDecoratorOptions(options)
|
|
302
|
+
}),
|
|
245
303
|
IsString(),
|
|
246
304
|
MaxLength(length),
|
|
247
305
|
validatorDecorator(options),
|
|
248
306
|
swaggerDecorator(options, { type: String, maxLength: length })
|
|
249
307
|
]);
|
|
250
308
|
};
|
|
309
|
+
var TextColumn = (options = {}) => {
|
|
310
|
+
return MergePropertyDecorators2([
|
|
311
|
+
Column(options.columnType || "text", columnDecoratorOptions(options)),
|
|
312
|
+
IsString(),
|
|
313
|
+
validatorDecorator(options),
|
|
314
|
+
swaggerDecorator(options, { type: String })
|
|
315
|
+
]);
|
|
316
|
+
};
|
|
251
317
|
var UuidColumn = (options = {}) => {
|
|
252
318
|
return MergePropertyDecorators2([
|
|
253
319
|
Column("uuid", {
|
|
@@ -266,8 +332,28 @@ var UuidColumn = (options = {}) => {
|
|
|
266
332
|
})
|
|
267
333
|
]);
|
|
268
334
|
};
|
|
335
|
+
var intMaxList = {
|
|
336
|
+
tinyint: 127,
|
|
337
|
+
smallint: 32767,
|
|
338
|
+
mediumint: 8388607,
|
|
339
|
+
int: 2147483647,
|
|
340
|
+
bigint: Number.MAX_SAFE_INTEGER
|
|
341
|
+
};
|
|
269
342
|
var IntColumn = (type, options = {}) => {
|
|
270
|
-
|
|
343
|
+
let max = intMaxList[type] || Number.MAX_SAFE_INTEGER;
|
|
344
|
+
if (max !== Number.MAX_SAFE_INTEGER && options.unsigned) {
|
|
345
|
+
max = max * 2 + 1;
|
|
346
|
+
}
|
|
347
|
+
let min = options.unsigned ? 0 : -max - 1;
|
|
348
|
+
if (options.range) {
|
|
349
|
+
if (typeof options.range.min === "number" && options.range.min > min) {
|
|
350
|
+
min = options.range.min;
|
|
351
|
+
}
|
|
352
|
+
if (typeof options.range.max === "number" && options.range.max < max) {
|
|
353
|
+
max = options.range.max;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return MergePropertyDecorators2([
|
|
271
357
|
Column(type, {
|
|
272
358
|
default: options.default,
|
|
273
359
|
unsigned: options.unsigned,
|
|
@@ -275,39 +361,53 @@ var IntColumn = (type, options = {}) => {
|
|
|
275
361
|
...columnDecoratorOptions(options)
|
|
276
362
|
}),
|
|
277
363
|
IsInt(),
|
|
364
|
+
...min > Number.MIN_SAFE_INTEGER ? [Min(min)] : [],
|
|
365
|
+
...max < Number.MAX_SAFE_INTEGER ? [Max(max)] : [],
|
|
278
366
|
validatorDecorator(options),
|
|
279
367
|
swaggerDecorator(options, {
|
|
280
368
|
type: Number,
|
|
281
|
-
minimum:
|
|
369
|
+
minimum: min > Number.MIN_SAFE_INTEGER ? min : void 0,
|
|
370
|
+
maximum: max < Number.MAX_SAFE_INTEGER ? max : void 0
|
|
282
371
|
})
|
|
283
|
-
];
|
|
284
|
-
if (options.unsigned) {
|
|
285
|
-
decs.push(Min(0));
|
|
286
|
-
}
|
|
287
|
-
return MergePropertyDecorators2(decs);
|
|
372
|
+
]);
|
|
288
373
|
};
|
|
289
374
|
var FloatColumn = (type, options = {}) => {
|
|
290
|
-
|
|
375
|
+
let min = options.unsigned ? 0 : Number.MIN_SAFE_INTEGER;
|
|
376
|
+
let max = Number.MAX_SAFE_INTEGER;
|
|
377
|
+
if (options.columnExtras?.precision != null && options.columnExtras?.scale != null) {
|
|
378
|
+
const precision = options.columnExtras.precision;
|
|
379
|
+
const scale = options.columnExtras.scale;
|
|
380
|
+
const intDigits = precision - scale;
|
|
381
|
+
if (intDigits > 0) {
|
|
382
|
+
const maxIntPart = Math.pow(10, intDigits) - 1;
|
|
383
|
+
const maxDecimalPart = scale > 0 ? (Math.pow(10, scale) - 1) / Math.pow(10, scale) : 0;
|
|
384
|
+
max = maxIntPart + maxDecimalPart;
|
|
385
|
+
min = options.unsigned ? 0 : -max;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return MergePropertyDecorators2([
|
|
291
389
|
Column(type, {
|
|
292
390
|
default: options.default,
|
|
293
391
|
unsigned: options.unsigned,
|
|
294
392
|
...columnDecoratorOptions(options)
|
|
295
393
|
}),
|
|
296
394
|
IsNumber(),
|
|
395
|
+
...min > Number.MIN_SAFE_INTEGER ? [Min(min)] : [],
|
|
396
|
+
...max < Number.MAX_SAFE_INTEGER ? [Max(max)] : [],
|
|
297
397
|
validatorDecorator(options),
|
|
298
398
|
swaggerDecorator(options, {
|
|
299
399
|
type: Number,
|
|
300
|
-
minimum:
|
|
400
|
+
minimum: min > Number.MIN_SAFE_INTEGER ? min : void 0,
|
|
401
|
+
maximum: max < Number.MAX_SAFE_INTEGER ? max : void 0
|
|
301
402
|
})
|
|
302
|
-
];
|
|
303
|
-
if (options.unsigned) {
|
|
304
|
-
decs.push(Min(0));
|
|
305
|
-
}
|
|
306
|
-
return MergePropertyDecorators2(decs);
|
|
403
|
+
]);
|
|
307
404
|
};
|
|
308
405
|
var DateColumn = (options = {}) => {
|
|
309
406
|
return MergePropertyDecorators2([
|
|
310
|
-
Column(
|
|
407
|
+
Column(
|
|
408
|
+
options.columnType || "timestamp",
|
|
409
|
+
columnDecoratorOptions(options)
|
|
410
|
+
),
|
|
311
411
|
IsDate(),
|
|
312
412
|
Transform(
|
|
313
413
|
(v) => {
|
|
@@ -347,31 +447,33 @@ var EnumColumn = (targetEnum, options = {}) => {
|
|
|
347
447
|
var BoolColumn = (options = {}) => MergePropertyDecorators2([
|
|
348
448
|
Index(),
|
|
349
449
|
Transform((v) => {
|
|
350
|
-
|
|
351
|
-
const falseValues = ["false", "0", "no", "off", false, 0];
|
|
352
|
-
if (trueValues.indexOf(v.value) !== -1) return true;
|
|
353
|
-
if (falseValues.indexOf(v.value) !== -1) return false;
|
|
354
|
-
return void 0;
|
|
450
|
+
return parseBool(v.value);
|
|
355
451
|
}),
|
|
356
452
|
Column("boolean", columnDecoratorOptions(options)),
|
|
357
453
|
validatorDecorator(options),
|
|
358
454
|
swaggerDecorator(options, { type: Boolean }),
|
|
359
455
|
Metadata.set("boolColumn", true, "boolColumnFields")
|
|
360
456
|
]);
|
|
361
|
-
var
|
|
457
|
+
var createJsonColumnDef = (columnType = "jsonb", typeTransformerClass = TypeTransformer) => (definition, options = {}) => {
|
|
362
458
|
const cl = getClassFromClassOrArray2(definition);
|
|
363
459
|
return MergePropertyDecorators2([
|
|
364
460
|
NotQueryable(),
|
|
365
461
|
Type2(() => cl),
|
|
366
462
|
ValidateNested2(),
|
|
367
|
-
Column(
|
|
463
|
+
Column(options.columnType || columnType, {
|
|
368
464
|
...columnDecoratorOptions(options),
|
|
369
|
-
transformer: new
|
|
465
|
+
transformer: new typeTransformerClass(definition)
|
|
370
466
|
}),
|
|
371
467
|
validatorDecorator(options),
|
|
372
468
|
swaggerDecorator(options, { type: definition })
|
|
373
469
|
]);
|
|
374
470
|
};
|
|
471
|
+
var JsonColumn = createJsonColumnDef();
|
|
472
|
+
var SimpleJsonColumn = createJsonColumnDef("json");
|
|
473
|
+
var StringJsonColumn = createJsonColumnDef(
|
|
474
|
+
"text",
|
|
475
|
+
TypeTransformerString
|
|
476
|
+
);
|
|
375
477
|
var NotColumn = (options = {}, specials = {}) => MergePropertyDecorators2([
|
|
376
478
|
Exclude(),
|
|
377
479
|
swaggerDecorator({
|
|
@@ -466,15 +568,26 @@ var applyQueryPropertyZeroNullable = createQueryCondition(
|
|
|
466
568
|
);
|
|
467
569
|
var applyQueryMatchBoolean = createQueryCondition(
|
|
468
570
|
(obj, qb, entityName, field) => {
|
|
469
|
-
const value = obj[field];
|
|
470
|
-
if (value === true
|
|
571
|
+
const value = parseBool(obj[field]);
|
|
572
|
+
if (value === true) {
|
|
471
573
|
qb.andWhere(`${entityName}.${field} = TRUE`);
|
|
472
574
|
}
|
|
473
|
-
if (value === false
|
|
575
|
+
if (value === false) {
|
|
474
576
|
qb.andWhere(`${entityName}.${field} = FALSE`);
|
|
475
577
|
}
|
|
476
578
|
}
|
|
477
579
|
);
|
|
580
|
+
var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
581
|
+
(obj, qb, entityName, field) => {
|
|
582
|
+
const value = parseBool(obj[field]);
|
|
583
|
+
if (value === true) {
|
|
584
|
+
qb.andWhere(`${entityName}.${field} = 1`);
|
|
585
|
+
}
|
|
586
|
+
if (value === false) {
|
|
587
|
+
qb.andWhere(`${entityName}.${field} = 0`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
);
|
|
478
591
|
|
|
479
592
|
// src/decorators/query.ts
|
|
480
593
|
import { MergePropertyDecorators as MergePropertyDecorators3 } from "nesties";
|
|
@@ -519,6 +632,7 @@ var QueryLike = () => QueryCondition(applyQueryPropertyLike);
|
|
|
519
632
|
var QuerySearch = () => QueryCondition(applyQueryPropertySearch);
|
|
520
633
|
var QueryEqualZeroNullable = () => QueryCondition(applyQueryPropertyZeroNullable);
|
|
521
634
|
var QueryMatchBoolean = () => QueryCondition(applyQueryMatchBoolean);
|
|
635
|
+
var QueryMatchBooleanMySQL = () => QueryCondition(applyQueryMatchBooleanMySQL);
|
|
522
636
|
var QueryOperator = (operator, field) => QueryCondition((obj, qb, entityName, key) => {
|
|
523
637
|
if (obj[key] == null) return;
|
|
524
638
|
const fieldName = field || key;
|
|
@@ -743,7 +857,7 @@ __decorateClass([
|
|
|
743
857
|
], TimeBase.prototype, "deleteTime", 2);
|
|
744
858
|
|
|
745
859
|
// src/bases/id-base.ts
|
|
746
|
-
import { Generated
|
|
860
|
+
import { Generated } from "typeorm";
|
|
747
861
|
import { IsNotEmpty as IsNotEmpty2 } from "class-validator";
|
|
748
862
|
import { MergePropertyDecorators as MergePropertyDecorators4 } from "nesties";
|
|
749
863
|
function IdBase(idOptions = {}) {
|
|
@@ -763,7 +877,7 @@ function IdBase(idOptions = {}) {
|
|
|
763
877
|
columnExtras: { nullable: false, primary: true }
|
|
764
878
|
}),
|
|
765
879
|
Reflect.metadata("design:type", Number),
|
|
766
|
-
|
|
880
|
+
Generated("increment"),
|
|
767
881
|
QueryEqual()
|
|
768
882
|
]);
|
|
769
883
|
dec(cl.prototype, "id");
|
|
@@ -1788,8 +1902,8 @@ var PatchColumnsInGet = (cl, originalCl = cl, fieldsToOmit = []) => {
|
|
|
1788
1902
|
...originalApiProp,
|
|
1789
1903
|
type: String,
|
|
1790
1904
|
required: false,
|
|
1791
|
-
enum: ["", "1"],
|
|
1792
|
-
default: originalApiProp?.default === true ? "1" : originalApiProp?.default === false ? "" : void 0
|
|
1905
|
+
enum: ["0", "1"],
|
|
1906
|
+
default: originalApiProp?.default === true ? "1" : originalApiProp?.default === false ? "0" : void 0
|
|
1793
1907
|
})(cl.prototype, field);
|
|
1794
1908
|
}
|
|
1795
1909
|
return cl;
|
|
@@ -1954,6 +2068,17 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
1954
2068
|
}
|
|
1955
2069
|
}
|
|
1956
2070
|
}
|
|
2071
|
+
const notRequiredButHasDefaultFields = getSpecificFields(
|
|
2072
|
+
this.entityClass,
|
|
2073
|
+
"notRequiredButHasDefault"
|
|
2074
|
+
).filter((f) => !outputFieldsToOmit.has(f));
|
|
2075
|
+
for (const field of notRequiredButHasDefaultFields) {
|
|
2076
|
+
const oldApiProperty = getApiProperty2(resultDto, field);
|
|
2077
|
+
ApiProperty6({
|
|
2078
|
+
...oldApiProperty,
|
|
2079
|
+
required: true
|
|
2080
|
+
})(resultDto.prototype, field);
|
|
2081
|
+
}
|
|
1957
2082
|
const res = RenameClass(
|
|
1958
2083
|
resultDto,
|
|
1959
2084
|
`${this.getEntityClassName()}ResultDto`
|
|
@@ -2040,8 +2165,17 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
2040
2165
|
ApiOkResponse({ type: this.entityCursorPaginationReturnMessageDto })
|
|
2041
2166
|
]);
|
|
2042
2167
|
}
|
|
2168
|
+
getBoolColumns() {
|
|
2169
|
+
const boolColumns = getSpecificFields(this.entityClass, "boolColumn");
|
|
2170
|
+
return _4.difference(boolColumns, this.fieldsInGetToOmit);
|
|
2171
|
+
}
|
|
2043
2172
|
findAllParam() {
|
|
2044
|
-
|
|
2173
|
+
const boolColumns = this.getBoolColumns();
|
|
2174
|
+
if (boolColumns.length) {
|
|
2175
|
+
return Query(new ParseBoolObjectPipe(boolColumns), GetPipe());
|
|
2176
|
+
} else {
|
|
2177
|
+
return Query(GetPipe());
|
|
2178
|
+
}
|
|
2045
2179
|
}
|
|
2046
2180
|
update(extras = {}) {
|
|
2047
2181
|
return MergeMethodDecorators([
|
|
@@ -2265,18 +2399,23 @@ export {
|
|
|
2265
2399
|
QueryLessEqual,
|
|
2266
2400
|
QueryLike,
|
|
2267
2401
|
QueryMatchBoolean,
|
|
2402
|
+
QueryMatchBooleanMySQL,
|
|
2268
2403
|
QueryNotEqual,
|
|
2269
2404
|
QueryOperator,
|
|
2270
2405
|
QuerySearch,
|
|
2271
2406
|
Relation,
|
|
2272
2407
|
RelationComputed,
|
|
2273
2408
|
RestfulFactory,
|
|
2409
|
+
SimpleJsonColumn,
|
|
2274
2410
|
StringColumn,
|
|
2275
2411
|
StringIdBase,
|
|
2412
|
+
StringJsonColumn,
|
|
2413
|
+
TextColumn,
|
|
2276
2414
|
TimeBase,
|
|
2277
2415
|
UpdatePipe,
|
|
2278
2416
|
UuidColumn,
|
|
2279
2417
|
applyQueryMatchBoolean,
|
|
2418
|
+
applyQueryMatchBooleanMySQL,
|
|
2280
2419
|
applyQueryProperty,
|
|
2281
2420
|
applyQueryPropertyLike,
|
|
2282
2421
|
applyQueryPropertySearch,
|