nicot 1.1.37 → 1.2.0
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 +58 -20
- package/dist/index.cjs +651 -271
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +580 -221
- package/dist/index.mjs.map +4 -4
- package/dist/src/bases/base-restful-controller.d.ts +1 -1
- package/dist/src/crud-base.d.ts +1 -0
- package/dist/src/decorators/access.d.ts +1 -0
- package/dist/src/decorators/get-mutator.d.ts +17 -0
- package/dist/src/decorators/index.d.ts +1 -0
- package/dist/src/decorators/pipes.d.ts +6 -4
- package/dist/src/decorators/property.d.ts +3 -3
- package/dist/src/decorators/query.d.ts +26 -6
- package/dist/src/restful.d.ts +26 -20
- package/dist/src/utility/memorize.d.ts +1 -0
- package/dist/src/utility/metadata.d.ts +7 -5
- package/dist/src/utility/mutate-pipe.d.ts +8 -0
- package/dist/src/utility/omit-type-exclude.d.ts +1 -0
- package/dist/src/utility/parse-bool.d.ts +0 -7
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -67,7 +67,6 @@ import {
|
|
|
67
67
|
} from "nesties";
|
|
68
68
|
|
|
69
69
|
// src/decorators/access.ts
|
|
70
|
-
import { Expose } from "class-transformer";
|
|
71
70
|
import { IsOptional } from "class-validator";
|
|
72
71
|
|
|
73
72
|
// src/utility/metadata.ts
|
|
@@ -94,13 +93,14 @@ function getNotInResultFields(obj, keepEntityVersioningDates = false) {
|
|
|
94
93
|
// src/decorators/access.ts
|
|
95
94
|
import { MergePropertyDecorators } from "nesties";
|
|
96
95
|
var NotWritable = () => MergePropertyDecorators([
|
|
97
|
-
Expose({ groups: ["r"] }),
|
|
98
96
|
IsOptional(),
|
|
99
|
-
Metadata.set("notWritable", true, "notWritableFields")
|
|
100
|
-
|
|
97
|
+
Metadata.set("notWritable", true, "notWritableFields")
|
|
98
|
+
]);
|
|
99
|
+
var NotCreatable = () => MergePropertyDecorators([
|
|
100
|
+
IsOptional(),
|
|
101
|
+
Metadata.set("notCreatable", true, "notCreatableFields")
|
|
101
102
|
]);
|
|
102
103
|
var NotChangeable = () => MergePropertyDecorators([
|
|
103
|
-
Expose({ groups: ["r", "c"] }),
|
|
104
104
|
Metadata.set("notChangeable", true, "notChangeableFields")
|
|
105
105
|
]);
|
|
106
106
|
var NotQueryable = () => Metadata.set("notQueryable", true, "notQueryableFields");
|
|
@@ -239,21 +239,45 @@ var parseBool = (value) => {
|
|
|
239
239
|
}
|
|
240
240
|
return void 0;
|
|
241
241
|
};
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
|
|
243
|
+
// src/decorators/get-mutator.ts
|
|
244
|
+
var RequireGetMutator = () => Metadata.set("requireGetMutator", true, "requireGetMutatorFields");
|
|
245
|
+
var GetMutator = (mutator, options = {}) => Metadata.set("getMutator", { mutator, ...options }, "getMutatorFields");
|
|
246
|
+
var createGetMutator = (mutator, defaultOptions = {}) => (options = {}) => GetMutator(mutator, {
|
|
247
|
+
...defaultOptions,
|
|
248
|
+
...options,
|
|
249
|
+
apiPropertyExtras: {
|
|
250
|
+
...defaultOptions.apiPropertyExtras || {},
|
|
251
|
+
...options.apiPropertyExtras || {}
|
|
246
252
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
});
|
|
254
|
+
var GetMutatorBool = createGetMutator(parseBool, {
|
|
255
|
+
enum: ["0", "1"],
|
|
256
|
+
example: "1"
|
|
257
|
+
});
|
|
258
|
+
var GetMutatorInt = createGetMutator((s) => parseInt(s, 10));
|
|
259
|
+
var GetMutatorFloat = createGetMutator((s) => parseFloat(s));
|
|
260
|
+
var GetMutatorStringSeparated = (separator = ",", options = {}) => GetMutator((s) => s.split(separator), {
|
|
261
|
+
example: `value1${separator}value2${separator}value3`,
|
|
262
|
+
...options
|
|
263
|
+
});
|
|
264
|
+
var GetMutatorIntSeparated = (separator = ",", options = {}) => GetMutator(
|
|
265
|
+
(s) => s.split(separator).map((item) => parseInt(item.trim(), 10)),
|
|
266
|
+
{
|
|
267
|
+
example: `1${separator}2${separator}3`,
|
|
268
|
+
...options
|
|
252
269
|
}
|
|
253
|
-
|
|
254
|
-
|
|
270
|
+
);
|
|
271
|
+
var GetMutatorFloatSeparated = (separator = ",", options = {}) => GetMutator(
|
|
272
|
+
(s) => s.split(separator).map((item) => parseFloat(item.trim())),
|
|
273
|
+
{
|
|
274
|
+
example: `1.5${separator}2.5${separator}3.5`,
|
|
275
|
+
...options
|
|
255
276
|
}
|
|
256
|
-
|
|
277
|
+
);
|
|
278
|
+
var GetMutatorJson = createGetMutator((s) => JSON.parse(s), {
|
|
279
|
+
example: `{"key1":"value1","key2":2,"key3":[1,2,3]}`
|
|
280
|
+
});
|
|
257
281
|
|
|
258
282
|
// src/decorators/property.ts
|
|
259
283
|
var NotRequiredButHasDefaultDec = () => Metadata.set(
|
|
@@ -454,12 +478,12 @@ var BoolColumn = (options = {}) => MergePropertyDecorators2([
|
|
|
454
478
|
Column("boolean", columnDecoratorOptions(options)),
|
|
455
479
|
validatorDecorator(options),
|
|
456
480
|
swaggerDecorator(options, { type: Boolean }),
|
|
457
|
-
|
|
481
|
+
GetMutatorBool()
|
|
458
482
|
]);
|
|
459
483
|
var createJsonColumnDef = (columnType = "jsonb", typeTransformerClass = TypeTransformer) => (definition, options = {}) => {
|
|
460
484
|
const cl = getClassFromClassOrArray2(definition);
|
|
461
485
|
return MergePropertyDecorators2([
|
|
462
|
-
|
|
486
|
+
RequireGetMutator(),
|
|
463
487
|
Type2(() => cl),
|
|
464
488
|
ValidateNested2(),
|
|
465
489
|
Column(options.columnType || columnType, {
|
|
@@ -507,89 +531,48 @@ var RelationComputed = (type) => (obj, propertyKey) => {
|
|
|
507
531
|
|
|
508
532
|
// src/decorators/pipes.ts
|
|
509
533
|
import { ValidationPipe } from "@nestjs/common";
|
|
510
|
-
var
|
|
511
|
-
transform: true,
|
|
512
|
-
transformOptions: { groups: ["c"], enableImplicitConversion: true }
|
|
513
|
-
});
|
|
514
|
-
var GetPipe = () => new ValidationPipe({
|
|
534
|
+
var OptionalDataPipe = () => new ValidationPipe({
|
|
515
535
|
transform: true,
|
|
516
|
-
transformOptions: {
|
|
536
|
+
transformOptions: { enableImplicitConversion: true },
|
|
517
537
|
skipMissingProperties: true,
|
|
518
538
|
skipNullProperties: true,
|
|
519
539
|
skipUndefinedProperties: true
|
|
520
540
|
});
|
|
521
|
-
var
|
|
522
|
-
transform
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
skipNullProperties: true,
|
|
526
|
-
skipUndefinedProperties: true
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
// src/utility/query.ts
|
|
530
|
-
function createQueryCondition(cond) {
|
|
531
|
-
return (obj, qb, entityName, ...fields) => {
|
|
532
|
-
for (const field of fields) {
|
|
533
|
-
if (obj[field] == null) {
|
|
534
|
-
continue;
|
|
535
|
-
}
|
|
536
|
-
const ret = cond(obj, qb, entityName, field);
|
|
537
|
-
if (typeof ret === "string") {
|
|
538
|
-
qb.andWhere(ret);
|
|
539
|
-
} else if (typeof ret === "object" && typeof ret["query"] === "string") {
|
|
540
|
-
const _ret = ret;
|
|
541
|
-
qb.andWhere(_ret.query, _ret.params);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
return qb;
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
var applyQueryProperty = createQueryCondition(
|
|
548
|
-
(obj, qb, entityName, field) => qb.andWhere(`${entityName}.${field} = :${field}`, { [field]: obj[field] })
|
|
549
|
-
);
|
|
550
|
-
var applyQueryPropertyLike = createQueryCondition(
|
|
551
|
-
(obj, qb, entityName, field) => qb.andWhere(`${entityName}.${field} like (:${field} || '%')`, {
|
|
552
|
-
[field]: obj[field]
|
|
553
|
-
})
|
|
554
|
-
);
|
|
555
|
-
var applyQueryPropertySearch = createQueryCondition(
|
|
556
|
-
(obj, qb, entityName, field) => qb.andWhere(`${entityName}.${field} like ('%' || :${field} || '%')`, {
|
|
557
|
-
[field]: obj[field]
|
|
558
|
-
})
|
|
559
|
-
);
|
|
560
|
-
var applyQueryPropertyZeroNullable = createQueryCondition(
|
|
561
|
-
(obj, qb, entityName, field) => {
|
|
562
|
-
if ([0, "0"].indexOf(obj[field]) !== -1) {
|
|
563
|
-
qb.andWhere(`${entityName}.${field} IS NULL`);
|
|
564
|
-
} else {
|
|
565
|
-
qb.andWhere(`${entityName}.${field} = :${field}`, {
|
|
566
|
-
[field]: obj[field]
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
);
|
|
571
|
-
var applyQueryMatchBoolean = createQueryCondition(
|
|
572
|
-
(obj, qb, entityName, field) => {
|
|
573
|
-
const value = parseBool(obj[field]);
|
|
574
|
-
if (value === true) {
|
|
575
|
-
qb.andWhere(`${entityName}.${field} = TRUE`);
|
|
541
|
+
var PickPipe = (fields) => ({
|
|
542
|
+
transform(obj) {
|
|
543
|
+
if (obj === null || typeof obj !== "object") {
|
|
544
|
+
return obj;
|
|
576
545
|
}
|
|
577
|
-
|
|
578
|
-
|
|
546
|
+
const proto = Object.getPrototypeOf(obj);
|
|
547
|
+
const clone = Object.create(proto);
|
|
548
|
+
const fieldSet = new Set(fields);
|
|
549
|
+
for (const key of fieldSet) {
|
|
550
|
+
const desc = Object.getOwnPropertyDescriptor(obj, key);
|
|
551
|
+
if (desc) {
|
|
552
|
+
Object.defineProperty(clone, key, desc);
|
|
553
|
+
}
|
|
579
554
|
}
|
|
555
|
+
return clone;
|
|
580
556
|
}
|
|
581
|
-
);
|
|
582
|
-
var
|
|
583
|
-
(obj
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
qb.andWhere(`${entityName}.${field} = 1`);
|
|
557
|
+
});
|
|
558
|
+
var OmitPipe = (fields) => ({
|
|
559
|
+
transform(obj) {
|
|
560
|
+
if (obj === null || typeof obj !== "object") {
|
|
561
|
+
return obj;
|
|
587
562
|
}
|
|
588
|
-
|
|
589
|
-
|
|
563
|
+
const proto = Object.getPrototypeOf(obj);
|
|
564
|
+
const clone = Object.create(proto);
|
|
565
|
+
const omitSet = new Set(fields);
|
|
566
|
+
for (const key of Reflect.ownKeys(obj)) {
|
|
567
|
+
if (omitSet.has(key)) continue;
|
|
568
|
+
const desc = Object.getOwnPropertyDescriptor(obj, key);
|
|
569
|
+
if (desc) {
|
|
570
|
+
Object.defineProperty(clone, key, desc);
|
|
571
|
+
}
|
|
590
572
|
}
|
|
573
|
+
return clone;
|
|
591
574
|
}
|
|
592
|
-
);
|
|
575
|
+
});
|
|
593
576
|
|
|
594
577
|
// src/decorators/query.ts
|
|
595
578
|
import { MergePropertyDecorators as MergePropertyDecorators3 } from "nesties";
|
|
@@ -624,31 +607,118 @@ var getSubject = (qb, alias) => {
|
|
|
624
607
|
};
|
|
625
608
|
|
|
626
609
|
// src/decorators/query.ts
|
|
610
|
+
import { Brackets } from "typeorm";
|
|
627
611
|
var QueryCondition = (cond) => Metadata.set(
|
|
628
612
|
"queryCondition",
|
|
629
613
|
cond,
|
|
630
614
|
"queryConditionFields"
|
|
631
615
|
);
|
|
632
|
-
var
|
|
633
|
-
|
|
634
|
-
var
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
616
|
+
var QueryManual = () => QueryCondition((obj, qb, entityName, key) => {
|
|
617
|
+
});
|
|
618
|
+
var QueryWrapInfo = class {
|
|
619
|
+
constructor(obj, key, field) {
|
|
620
|
+
this.obj = obj;
|
|
621
|
+
this.key = key;
|
|
622
|
+
this.field = field;
|
|
623
|
+
this._value = obj[key];
|
|
624
|
+
}
|
|
625
|
+
get value() {
|
|
626
|
+
return this._value;
|
|
627
|
+
}
|
|
628
|
+
mutateValue(next) {
|
|
629
|
+
this._value = next;
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
var queryWrapCounters = /* @__PURE__ */ new WeakMap();
|
|
633
|
+
var getQueryVarName = (obj, key) => {
|
|
634
|
+
const queryCounters = queryWrapCounters.get(obj) || {};
|
|
635
|
+
let useField = `_qw_` + key;
|
|
636
|
+
if (queryCounters[key] == null) {
|
|
637
|
+
queryCounters[key] = 0;
|
|
638
|
+
} else {
|
|
639
|
+
useField += `__${queryCounters[key].toString(36)}`;
|
|
640
|
+
++queryCounters[key];
|
|
641
|
+
}
|
|
642
|
+
queryWrapCounters.set(obj, queryCounters);
|
|
643
|
+
return useField;
|
|
644
|
+
};
|
|
645
|
+
var QueryWrap = (wrapper, field) => QueryCondition((obj, qb, entityName, key) => {
|
|
639
646
|
if (obj[key] == null) return;
|
|
640
647
|
const fieldName = field || key;
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
648
|
+
const varField = getQueryVarName(obj, key);
|
|
649
|
+
const entityExpr = `${entityName}.${fieldName}`;
|
|
650
|
+
const varExpr = `:${varField}`;
|
|
651
|
+
const info = new QueryWrapInfo(obj, key, fieldName);
|
|
652
|
+
const expr = wrapper(entityExpr, varExpr, info);
|
|
653
|
+
if (expr) {
|
|
654
|
+
qb.andWhere(expr, {
|
|
655
|
+
[varField]: info.value
|
|
656
|
+
});
|
|
657
|
+
}
|
|
645
658
|
});
|
|
659
|
+
var createQueryWrap = (wrapper) => (field) => QueryWrap(wrapper, field);
|
|
660
|
+
var QueryLike = createQueryWrap(
|
|
661
|
+
(entityExpr, varExpr) => `${entityExpr} LIKE (${varExpr} || '%')`
|
|
662
|
+
);
|
|
663
|
+
var QuerySearch = createQueryWrap(
|
|
664
|
+
(entityExpr, varExpr) => `${entityExpr} LIKE ('%' || ${varExpr} || '%')`
|
|
665
|
+
);
|
|
666
|
+
var QueryEqualZeroNullable = createQueryWrap(
|
|
667
|
+
(entityExpr, varExpr, info) => [0, "0"].indexOf(info.value) !== -1 ? `${entityExpr} IS NULL` : `${entityExpr} = ${varExpr}`
|
|
668
|
+
);
|
|
669
|
+
var QueryMatchBoolean = createQueryWrap(
|
|
670
|
+
(entityExpr, varExpr, info) => {
|
|
671
|
+
const value = parseBool(info.value);
|
|
672
|
+
if (value === true) {
|
|
673
|
+
return `${entityExpr} = TRUE`;
|
|
674
|
+
}
|
|
675
|
+
if (value === false) {
|
|
676
|
+
return `${entityExpr} = FALSE`;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
);
|
|
680
|
+
var QueryMatchBooleanMySQL = createQueryWrap(
|
|
681
|
+
(entityExpr, varExpr, info) => {
|
|
682
|
+
const value = parseBool(info.value);
|
|
683
|
+
if (value === true) {
|
|
684
|
+
return `${entityExpr} = 1`;
|
|
685
|
+
}
|
|
686
|
+
if (value === false) {
|
|
687
|
+
return `${entityExpr} = 0`;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
);
|
|
691
|
+
var QueryOperator = (operator, field) => QueryWrap(
|
|
692
|
+
(entityExpr, varExpr) => `${entityExpr} ${operator} ${varExpr}`,
|
|
693
|
+
field
|
|
694
|
+
);
|
|
646
695
|
var createQueryOperator = (operator) => (field) => QueryOperator(operator, field);
|
|
696
|
+
var QueryEqual = createQueryOperator("=");
|
|
647
697
|
var QueryGreater = createQueryOperator(">");
|
|
648
698
|
var QueryGreaterEqual = createQueryOperator(">=");
|
|
649
699
|
var QueryLess = createQueryOperator("<");
|
|
650
700
|
var QueryLessEqual = createQueryOperator("<=");
|
|
651
701
|
var QueryNotEqual = createQueryOperator("!=");
|
|
702
|
+
var QueryJsonbHas = createQueryOperator("?");
|
|
703
|
+
var createQueryArrayify = (newWrapper, singleFallbackWrapper) => createQueryWrap((entityExpr, varExpr, info) => {
|
|
704
|
+
const value = info.value;
|
|
705
|
+
const items = Array.isArray(value) ? value : typeof value === "string" ? value.split(",") : [value];
|
|
706
|
+
if (items.length === 1 && singleFallbackWrapper) {
|
|
707
|
+
const singleRes = singleFallbackWrapper(entityExpr, varExpr, info);
|
|
708
|
+
if (singleRes) {
|
|
709
|
+
return singleRes;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
info.mutateValue(items);
|
|
713
|
+
const newVarExpr = `(:...${varExpr.slice(1)})`;
|
|
714
|
+
return newWrapper(entityExpr, newVarExpr, info);
|
|
715
|
+
});
|
|
716
|
+
var createQueryOperatorArrayify = (operator, singleFallback) => createQueryArrayify(
|
|
717
|
+
(entityExpr, varExpr) => `${entityExpr} ${operator} ${varExpr}`,
|
|
718
|
+
typeof singleFallback === "string" ? singleFallback.length ? (entityExpr, varExpr) => `${entityExpr} ${singleFallback} ${varExpr}` : void 0 : singleFallback
|
|
719
|
+
);
|
|
720
|
+
var QueryIn = createQueryOperatorArrayify("IN", "=");
|
|
721
|
+
var QueryNotIn = createQueryOperatorArrayify("NOT IN", "!=");
|
|
652
722
|
var QueryFullText = (options = {}) => {
|
|
653
723
|
const configurationName = options.parser ? `nicot_parser_${options.parser}` : options.configuration || "english";
|
|
654
724
|
const tsQueryFunction = options.tsQueryFunction || "websearch_to_tsquery";
|
|
@@ -656,7 +726,7 @@ var QueryFullText = (options = {}) => {
|
|
|
656
726
|
QueryCondition((obj, qb, entityName, key) => {
|
|
657
727
|
if (obj[key] == null) return;
|
|
658
728
|
const fieldName = key;
|
|
659
|
-
const typeormField = key;
|
|
729
|
+
const typeormField = getQueryVarName(obj, key);
|
|
660
730
|
const tsVectorStatement = `to_tsvector('${configurationName}', "${entityName}"."${fieldName}")`;
|
|
661
731
|
const tsQueryStatement = `${tsQueryFunction}('${configurationName}', :${typeormField})`;
|
|
662
732
|
qb.andWhere(`${tsVectorStatement} @@ ${tsQueryStatement}`, {
|
|
@@ -682,6 +752,36 @@ var QueryFullText = (options = {}) => {
|
|
|
682
752
|
)
|
|
683
753
|
]);
|
|
684
754
|
};
|
|
755
|
+
var QueryAnd = (...decs) => {
|
|
756
|
+
const conditions = decs.map(
|
|
757
|
+
(dec) => reflector.getMetadataFromDecorator(dec, "queryCondition")
|
|
758
|
+
);
|
|
759
|
+
return QueryCondition(
|
|
760
|
+
(obj, qb, entityName, key) => conditions.forEach((cond) => cond(obj, qb, entityName, key))
|
|
761
|
+
);
|
|
762
|
+
};
|
|
763
|
+
var QueryOr = (...decs) => {
|
|
764
|
+
const conditions = decs.map(
|
|
765
|
+
(dec) => reflector.getMetadataFromDecorator(dec, "queryCondition")
|
|
766
|
+
);
|
|
767
|
+
return QueryCondition((obj, qb, entityName, key) => {
|
|
768
|
+
if (!conditions.length) {
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
qb.andWhere(
|
|
772
|
+
new Brackets((orQb) => {
|
|
773
|
+
const innerBrackets = conditions.map(
|
|
774
|
+
(cond) => new Brackets((andQb) => {
|
|
775
|
+
cond(obj, andQb, entityName, key);
|
|
776
|
+
})
|
|
777
|
+
);
|
|
778
|
+
const [first, ...rest] = innerBrackets;
|
|
779
|
+
orQb.where(first);
|
|
780
|
+
rest.forEach((bracket) => orQb.orWhere(bracket));
|
|
781
|
+
})
|
|
782
|
+
);
|
|
783
|
+
});
|
|
784
|
+
};
|
|
685
785
|
|
|
686
786
|
// src/dto/cursor-pagination.ts
|
|
687
787
|
var CursorPaginationDto = class {
|
|
@@ -974,7 +1074,7 @@ function getTypeormRelations(cl) {
|
|
|
974
1074
|
}
|
|
975
1075
|
|
|
976
1076
|
// src/utility/cursor-pagination-utils.ts
|
|
977
|
-
import { Brackets } from "typeorm";
|
|
1077
|
+
import { Brackets as Brackets2 } from "typeorm";
|
|
978
1078
|
import _2 from "lodash";
|
|
979
1079
|
import SJSON from "superjson";
|
|
980
1080
|
|
|
@@ -1193,8 +1293,8 @@ async function getPaginatedResult(qb, entityClass, entityAliasName, take, cursor
|
|
|
1193
1293
|
).filter((s) => !s.includes("__never__"));
|
|
1194
1294
|
if (expressionMatrix.length) {
|
|
1195
1295
|
qb.andWhere(
|
|
1196
|
-
new
|
|
1197
|
-
const levelToBrackets = (level) => new
|
|
1296
|
+
new Brackets2((sqb) => {
|
|
1297
|
+
const levelToBrackets = (level) => new Brackets2((qb2) => {
|
|
1198
1298
|
level.forEach((expr, i) => {
|
|
1199
1299
|
if (i === 0) {
|
|
1200
1300
|
qb2.where(expr);
|
|
@@ -1311,11 +1411,14 @@ var CrudBase = class {
|
|
|
1311
1411
|
cl,
|
|
1312
1412
|
this.crudOptions.keepEntityVersioningDates
|
|
1313
1413
|
);
|
|
1414
|
+
if (cl === this.entityClass && this.crudOptions.outputFieldsToOmit) {
|
|
1415
|
+
fields.push(...this.crudOptions.outputFieldsToOmit);
|
|
1416
|
+
}
|
|
1314
1417
|
for (const field of fields) {
|
|
1315
1418
|
delete o[field];
|
|
1316
1419
|
}
|
|
1317
1420
|
visited.add(o);
|
|
1318
|
-
for (const relation of
|
|
1421
|
+
for (const relation of getTypeormRelations(cl)) {
|
|
1319
1422
|
const propertyName = relation.propertyName;
|
|
1320
1423
|
if (o[propertyName]) {
|
|
1321
1424
|
if (Array.isArray(o[propertyName])) {
|
|
@@ -1813,7 +1916,8 @@ import {
|
|
|
1813
1916
|
MergeMethodDecorators,
|
|
1814
1917
|
PaginatedReturnMessageDto as PaginatedReturnMessageDto2,
|
|
1815
1918
|
ReturnMessageDto as ReturnMessageDto2,
|
|
1816
|
-
getApiProperty as getApiProperty2
|
|
1919
|
+
getApiProperty as getApiProperty2,
|
|
1920
|
+
DataPipe
|
|
1817
1921
|
} from "nesties";
|
|
1818
1922
|
import {
|
|
1819
1923
|
ApiBadRequestResponse,
|
|
@@ -1823,12 +1927,12 @@ import {
|
|
|
1823
1927
|
ApiOkResponse,
|
|
1824
1928
|
ApiOperation,
|
|
1825
1929
|
ApiParam,
|
|
1826
|
-
ApiProperty as
|
|
1930
|
+
ApiProperty as ApiProperty5,
|
|
1827
1931
|
IntersectionType,
|
|
1828
1932
|
OmitType as OmitType2,
|
|
1829
1933
|
PartialType
|
|
1830
1934
|
} from "@nestjs/swagger";
|
|
1831
|
-
import
|
|
1935
|
+
import _5, { upperFirst } from "lodash";
|
|
1832
1936
|
import { RenameClass } from "nesties";
|
|
1833
1937
|
|
|
1834
1938
|
// src/bases/base-restful-controller.ts
|
|
@@ -1844,44 +1948,44 @@ var BaseRestfulController = class {
|
|
|
1844
1948
|
constructor(serviceOrRepo, _options = {}) {
|
|
1845
1949
|
this._options = _options;
|
|
1846
1950
|
if (serviceOrRepo instanceof CrudBase) {
|
|
1847
|
-
this.
|
|
1951
|
+
this._service = serviceOrRepo;
|
|
1848
1952
|
} else {
|
|
1849
1953
|
const crudServiceClass = CrudService(this._options.entityClass, {
|
|
1850
1954
|
relations: this._options.relations
|
|
1851
1955
|
});
|
|
1852
|
-
this.
|
|
1956
|
+
this._service = new crudServiceClass(serviceOrRepo);
|
|
1853
1957
|
}
|
|
1854
1958
|
}
|
|
1855
1959
|
findOne(id) {
|
|
1856
|
-
return this.
|
|
1960
|
+
return this._service.findOne(id);
|
|
1857
1961
|
}
|
|
1858
1962
|
findAll(dto) {
|
|
1859
1963
|
if (this._options.paginateType === "cursor") {
|
|
1860
|
-
return this.
|
|
1964
|
+
return this._service.findAllCursorPaginated(dto);
|
|
1861
1965
|
}
|
|
1862
1966
|
if (this._options.paginateType === "offset") {
|
|
1863
|
-
return this.
|
|
1967
|
+
return this._service.findAll(dto);
|
|
1864
1968
|
}
|
|
1865
1969
|
dto["recordsPerPage"] ??= 99999;
|
|
1866
|
-
return this.
|
|
1970
|
+
return this._service.findAll(dto);
|
|
1867
1971
|
}
|
|
1868
1972
|
create(dto) {
|
|
1869
|
-
return this.
|
|
1973
|
+
return this._service.create(dto);
|
|
1870
1974
|
}
|
|
1871
1975
|
update(id, dto) {
|
|
1872
|
-
return this.
|
|
1976
|
+
return this._service.update(id, dto);
|
|
1873
1977
|
}
|
|
1874
1978
|
delete(id) {
|
|
1875
|
-
return this.
|
|
1979
|
+
return this._service.delete(id);
|
|
1876
1980
|
}
|
|
1877
1981
|
import(data) {
|
|
1878
|
-
return this.
|
|
1982
|
+
return this._service.importEntities(data.data);
|
|
1879
1983
|
}
|
|
1880
1984
|
};
|
|
1881
1985
|
|
|
1882
1986
|
// src/utility/omit-type-exclude.ts
|
|
1883
1987
|
import { OmitType } from "@nestjs/swagger";
|
|
1884
|
-
import { Exclude as Exclude2 } from "class-transformer";
|
|
1988
|
+
import { Exclude as Exclude2, Expose } from "class-transformer";
|
|
1885
1989
|
var OmitTypeExclude = (cl, keys) => {
|
|
1886
1990
|
const omitted = OmitType(cl, keys);
|
|
1887
1991
|
for (const key of keys) {
|
|
@@ -1889,130 +1993,204 @@ var OmitTypeExclude = (cl, keys) => {
|
|
|
1889
1993
|
}
|
|
1890
1994
|
return omitted;
|
|
1891
1995
|
};
|
|
1996
|
+
var PickTypeExpose = (cl, keys) => {
|
|
1997
|
+
const picked = OmitType(
|
|
1998
|
+
cl,
|
|
1999
|
+
Object.keys(cl.prototype).filter((k) => !keys.includes(k))
|
|
2000
|
+
);
|
|
2001
|
+
for (const key of keys) {
|
|
2002
|
+
Expose()(picked.prototype, key);
|
|
2003
|
+
}
|
|
2004
|
+
return picked;
|
|
2005
|
+
};
|
|
1892
2006
|
|
|
1893
2007
|
// src/utility/patch-column-in-get.ts
|
|
1894
|
-
import { ApiProperty as ApiProperty5 } from "@nestjs/swagger";
|
|
1895
2008
|
import { getApiProperty } from "nesties";
|
|
2009
|
+
import _4 from "lodash";
|
|
2010
|
+
import { DECORATORS } from "@nestjs/swagger/dist/constants";
|
|
1896
2011
|
var PatchColumnsInGet = (cl, originalCl = cl, fieldsToOmit = []) => {
|
|
1897
2012
|
const omit2 = new Set(fieldsToOmit);
|
|
1898
|
-
const
|
|
2013
|
+
const useCl = originalCl || cl;
|
|
2014
|
+
const mutateFields = getSpecificFields(useCl, "getMutator").filter(
|
|
1899
2015
|
(f) => !omit2.has(f)
|
|
1900
2016
|
);
|
|
1901
|
-
for (const field of
|
|
2017
|
+
for (const field of mutateFields) {
|
|
1902
2018
|
const originalApiProp = getApiProperty(originalCl, field);
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
2019
|
+
const info = reflector.get("getMutator", useCl, field);
|
|
2020
|
+
Reflect.defineMetadata(
|
|
2021
|
+
DECORATORS.API_MODEL_PROPERTIES,
|
|
2022
|
+
{
|
|
2023
|
+
...originalApiProp,
|
|
2024
|
+
type: String,
|
|
2025
|
+
required: false,
|
|
2026
|
+
example: info.example ?? void 0,
|
|
2027
|
+
enum: info.enum ?? void 0,
|
|
2028
|
+
default: void 0,
|
|
2029
|
+
...info.apiPropertyExtras || {}
|
|
2030
|
+
},
|
|
2031
|
+
cl.prototype,
|
|
2032
|
+
field
|
|
2033
|
+
);
|
|
2034
|
+
}
|
|
2035
|
+
const queryableFieldsRemaining = _4.difference(
|
|
2036
|
+
getSpecificFields(useCl, "queryCondition"),
|
|
2037
|
+
mutateFields
|
|
2038
|
+
);
|
|
2039
|
+
for (const field of queryableFieldsRemaining) {
|
|
2040
|
+
const originalApiProp = getApiProperty(originalCl, field);
|
|
2041
|
+
Reflect.defineMetadata(
|
|
2042
|
+
DECORATORS.API_MODEL_PROPERTIES,
|
|
2043
|
+
{
|
|
2044
|
+
...originalApiProp,
|
|
2045
|
+
default: void 0
|
|
2046
|
+
// we remove every default value in get
|
|
2047
|
+
},
|
|
2048
|
+
cl.prototype,
|
|
2049
|
+
field
|
|
2050
|
+
);
|
|
1910
2051
|
}
|
|
1911
2052
|
return cl;
|
|
1912
2053
|
};
|
|
1913
2054
|
|
|
2055
|
+
// src/utility/memorize.ts
|
|
2056
|
+
var Memorize = () => {
|
|
2057
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
2058
|
+
return function(_target, propertyKey, descriptor) {
|
|
2059
|
+
const getter = descriptor.get;
|
|
2060
|
+
descriptor.get = function() {
|
|
2061
|
+
if (cache.has(this)) return cache.get(this);
|
|
2062
|
+
const value = getter.call(this);
|
|
2063
|
+
cache.set(this, value);
|
|
2064
|
+
return value;
|
|
2065
|
+
};
|
|
2066
|
+
};
|
|
2067
|
+
};
|
|
2068
|
+
|
|
2069
|
+
// src/utility/mutate-pipe.ts
|
|
2070
|
+
var MutatorPipe = class {
|
|
2071
|
+
constructor(entityClass) {
|
|
2072
|
+
this.entityClass = entityClass;
|
|
2073
|
+
this.mutatorFields = getSpecificFields(this.entityClass, "getMutator");
|
|
2074
|
+
}
|
|
2075
|
+
transform(obj) {
|
|
2076
|
+
if (obj === null || typeof obj !== "object") {
|
|
2077
|
+
return obj;
|
|
2078
|
+
}
|
|
2079
|
+
const newObj = { ...obj };
|
|
2080
|
+
for (const field of this.mutatorFields) {
|
|
2081
|
+
const v = newObj[field];
|
|
2082
|
+
if (v == null) {
|
|
2083
|
+
continue;
|
|
2084
|
+
}
|
|
2085
|
+
const mutator = reflector.get("getMutator", this.entityClass, field);
|
|
2086
|
+
newObj[field] = mutator.mutator(v);
|
|
2087
|
+
}
|
|
2088
|
+
return newObj;
|
|
2089
|
+
}
|
|
2090
|
+
};
|
|
2091
|
+
|
|
1914
2092
|
// src/restful.ts
|
|
1915
2093
|
var getCurrentLevelRelations = (relations) => relations.filter((r) => !r.includes("."));
|
|
1916
2094
|
var getNextLevelRelations = (relations, enteringField) => relations.filter((r) => r.includes(".") && r.startsWith(`${enteringField}.`)).map((r) => r.split(".").slice(1).join("."));
|
|
1917
|
-
var
|
|
2095
|
+
var _RestfulFactory = class _RestfulFactory {
|
|
1918
2096
|
constructor(entityClass, options = {}, __resolveVisited = /* @__PURE__ */ new Map()) {
|
|
1919
2097
|
this.entityClass = entityClass;
|
|
1920
2098
|
this.options = options;
|
|
1921
2099
|
this.__resolveVisited = __resolveVisited;
|
|
1922
|
-
|
|
2100
|
+
if (options.relations) {
|
|
2101
|
+
filterRelations(entityClass, options.relations);
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
getEntityClassName() {
|
|
2105
|
+
return this.options.entityClassName || this.entityClass.name;
|
|
2106
|
+
}
|
|
2107
|
+
get fieldsToOmit() {
|
|
2108
|
+
return _5.uniq([
|
|
1923
2109
|
...getSpecificFields(this.entityClass, "notColumn"),
|
|
1924
2110
|
...this.options.fieldsToOmit || [],
|
|
1925
2111
|
...getTypeormRelations(this.entityClass).map(
|
|
1926
2112
|
(r) => r.propertyName
|
|
1927
2113
|
)
|
|
1928
2114
|
]);
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
2115
|
+
}
|
|
2116
|
+
get fieldsInCreateToOmit() {
|
|
2117
|
+
return _5.uniq([
|
|
2118
|
+
...this.fieldsToOmit,
|
|
2119
|
+
...this.options.writeFieldsToOmit || [],
|
|
2120
|
+
...this.options.createFieldsToOmit || [],
|
|
2121
|
+
...getSpecificFields(this.entityClass, "notWritable"),
|
|
2122
|
+
...getSpecificFields(this.entityClass, "notCreatable")
|
|
2123
|
+
]);
|
|
2124
|
+
}
|
|
2125
|
+
get createDto() {
|
|
2126
|
+
return RenameClass(
|
|
2127
|
+
OmitTypeExclude(this.entityClass, this.fieldsInCreateToOmit),
|
|
1938
2128
|
`Create${this.entityClass.name}Dto`
|
|
1939
2129
|
);
|
|
1940
|
-
|
|
1941
|
-
|
|
2130
|
+
}
|
|
2131
|
+
get fieldsInUpdateToOmit() {
|
|
2132
|
+
return _5.uniq([
|
|
1942
2133
|
...this.fieldsToOmit,
|
|
1943
|
-
...
|
|
2134
|
+
...this.options.writeFieldsToOmit || [],
|
|
2135
|
+
...this.options.updateFieldsToOmit || [],
|
|
2136
|
+
...getSpecificFields(this.entityClass, "notWritable"),
|
|
2137
|
+
...getSpecificFields(this.entityClass, "notChangeable")
|
|
1944
2138
|
]);
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
2139
|
+
}
|
|
2140
|
+
get updateDto() {
|
|
2141
|
+
return RenameClass(
|
|
2142
|
+
PartialType(OmitTypeExclude(this.entityClass, this.fieldsInUpdateToOmit)),
|
|
2143
|
+
`Update${this.entityClass.name}Dto`
|
|
2144
|
+
);
|
|
2145
|
+
}
|
|
2146
|
+
get importDto() {
|
|
2147
|
+
return ImportDataDto(this.createDto);
|
|
2148
|
+
}
|
|
2149
|
+
get fieldsInGetToOmit() {
|
|
2150
|
+
return _5.uniq([
|
|
2151
|
+
...this.fieldsToOmit,
|
|
2152
|
+
...getSpecificFields(this.entityClass, "notQueryable"),
|
|
2153
|
+
..._5.difference(
|
|
2154
|
+
getSpecificFields(this.entityClass, "requireGetMutator"),
|
|
2155
|
+
getSpecificFields(this.entityClass, "getMutator")
|
|
2156
|
+
)
|
|
2157
|
+
]);
|
|
2158
|
+
}
|
|
2159
|
+
get queryableFields() {
|
|
2160
|
+
return _5.difference(
|
|
2161
|
+
getSpecificFields(this.entityClass, "queryCondition"),
|
|
2162
|
+
this.fieldsInGetToOmit
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
get findAllDto() {
|
|
2166
|
+
let cl = PartialType(
|
|
2167
|
+
PatchColumnsInGet(
|
|
2168
|
+
OmitTypeExclude(
|
|
2169
|
+
this.entityClass instanceof PageSettingsDto ? this.entityClass : IntersectionType(
|
|
2170
|
+
this.entityClass,
|
|
2171
|
+
PageSettingsDto
|
|
1954
2172
|
),
|
|
1955
|
-
this.entityClass,
|
|
1956
2173
|
this.fieldsInGetToOmit
|
|
1957
|
-
)
|
|
1958
|
-
|
|
1959
|
-
|
|
2174
|
+
),
|
|
2175
|
+
this.entityClass,
|
|
2176
|
+
this.fieldsInGetToOmit
|
|
2177
|
+
)
|
|
1960
2178
|
);
|
|
1961
|
-
this.
|
|
2179
|
+
if (this.options.skipNonQueryableFields) {
|
|
2180
|
+
cl = PickTypeExpose(cl, this.queryableFields);
|
|
2181
|
+
}
|
|
2182
|
+
return RenameClass(cl, `Find${this.entityClass.name}Dto`);
|
|
2183
|
+
}
|
|
2184
|
+
get findAllCursorPaginatedDto() {
|
|
2185
|
+
return RenameClass(
|
|
1962
2186
|
IntersectionType(
|
|
1963
2187
|
OmitTypeExclude(this.findAllDto, ["pageCount"]),
|
|
1964
2188
|
CursorPaginationDto
|
|
1965
2189
|
),
|
|
1966
2190
|
`Find${this.entityClass.name}CursorPaginatedDto`
|
|
1967
2191
|
);
|
|
1968
|
-
this.updateDto = RenameClass(
|
|
1969
|
-
PartialType(
|
|
1970
|
-
OmitTypeExclude(
|
|
1971
|
-
this.createDto,
|
|
1972
|
-
getSpecificFields(this.entityClass, "notChangeable")
|
|
1973
|
-
)
|
|
1974
|
-
),
|
|
1975
|
-
`Update${this.entityClass.name}Dto`
|
|
1976
|
-
);
|
|
1977
|
-
this.entityResultDto = this.resolveEntityResultDto();
|
|
1978
|
-
this.entityCreateResultDto = RenameClass(
|
|
1979
|
-
OmitType2(this.entityResultDto, [
|
|
1980
|
-
...getTypeormRelations(this.entityClass).map(
|
|
1981
|
-
(r) => r.propertyName
|
|
1982
|
-
),
|
|
1983
|
-
...getSpecificFields(
|
|
1984
|
-
this.entityClass,
|
|
1985
|
-
"notColumn",
|
|
1986
|
-
(m) => !m.keepInCreate
|
|
1987
|
-
)
|
|
1988
|
-
]),
|
|
1989
|
-
`${this.getEntityClassName()}CreateResultDto`
|
|
1990
|
-
);
|
|
1991
|
-
this.entityReturnMessageDto = ReturnMessageDto2(this.entityResultDto);
|
|
1992
|
-
this.entityCreateReturnMessageDto = ReturnMessageDto2(
|
|
1993
|
-
this.entityCreateResultDto
|
|
1994
|
-
);
|
|
1995
|
-
this.entityArrayReturnMessageDto = PaginatedReturnMessageDto2(
|
|
1996
|
-
this.entityResultDto
|
|
1997
|
-
);
|
|
1998
|
-
this.entityCursorPaginationReturnMessageDto = CursorPaginationReturnMessageDto(this.entityResultDto);
|
|
1999
|
-
this.importReturnMessageDto = ReturnMessageDto2([
|
|
2000
|
-
ImportEntryDto(this.entityCreateResultDto)
|
|
2001
|
-
]);
|
|
2002
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
2003
|
-
this.idType = Reflect.getMetadata(
|
|
2004
|
-
"design:type",
|
|
2005
|
-
this.entityClass.prototype,
|
|
2006
|
-
"id"
|
|
2007
|
-
);
|
|
2008
|
-
if (options.relations) {
|
|
2009
|
-
filterRelations(entityClass, options.relations);
|
|
2010
|
-
}
|
|
2011
2192
|
}
|
|
2012
|
-
|
|
2013
|
-
return this.options.entityClassName || this.entityClass.name;
|
|
2014
|
-
}
|
|
2015
|
-
resolveEntityResultDto() {
|
|
2193
|
+
get entityResultDto() {
|
|
2016
2194
|
const relations = getTypeormRelations(this.entityClass);
|
|
2017
2195
|
const currentLevelRelations = this.options.relations && new Set(
|
|
2018
2196
|
getCurrentLevelRelations(
|
|
@@ -2036,7 +2214,7 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
2036
2214
|
this.entityClass,
|
|
2037
2215
|
relation.propertyName
|
|
2038
2216
|
);
|
|
2039
|
-
|
|
2217
|
+
ApiProperty5({
|
|
2040
2218
|
...oldApiProperty,
|
|
2041
2219
|
required: false,
|
|
2042
2220
|
type: () => relation.isArray ? [useClass[0]] : useClass[0]
|
|
@@ -2076,7 +2254,7 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
2076
2254
|
).filter((f) => !outputFieldsToOmit.has(f));
|
|
2077
2255
|
for (const field of notRequiredButHasDefaultFields) {
|
|
2078
2256
|
const oldApiProperty = getApiProperty2(resultDto, field);
|
|
2079
|
-
|
|
2257
|
+
ApiProperty5({
|
|
2080
2258
|
...oldApiProperty,
|
|
2081
2259
|
required: true
|
|
2082
2260
|
})(resultDto.prototype, field);
|
|
@@ -2091,6 +2269,40 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
2091
2269
|
}
|
|
2092
2270
|
return res;
|
|
2093
2271
|
}
|
|
2272
|
+
get entityCreateResultDto() {
|
|
2273
|
+
return RenameClass(
|
|
2274
|
+
OmitType2(this.entityResultDto, [
|
|
2275
|
+
...getTypeormRelations(this.entityClass).map(
|
|
2276
|
+
(r) => r.propertyName
|
|
2277
|
+
),
|
|
2278
|
+
...getSpecificFields(
|
|
2279
|
+
this.entityClass,
|
|
2280
|
+
"notColumn",
|
|
2281
|
+
(m) => !m.keepInCreate
|
|
2282
|
+
)
|
|
2283
|
+
]),
|
|
2284
|
+
`${this.getEntityClassName()}CreateResultDto`
|
|
2285
|
+
);
|
|
2286
|
+
}
|
|
2287
|
+
get entityReturnMessageDto() {
|
|
2288
|
+
return ReturnMessageDto2(this.entityResultDto);
|
|
2289
|
+
}
|
|
2290
|
+
get entityCreateReturnMessageDto() {
|
|
2291
|
+
return ReturnMessageDto2(this.entityCreateResultDto);
|
|
2292
|
+
}
|
|
2293
|
+
get entityArrayReturnMessageDto() {
|
|
2294
|
+
return PaginatedReturnMessageDto2(this.entityResultDto);
|
|
2295
|
+
}
|
|
2296
|
+
get entityCursorPaginationReturnMessageDto() {
|
|
2297
|
+
return CursorPaginationReturnMessageDto(this.entityResultDto);
|
|
2298
|
+
}
|
|
2299
|
+
get importReturnMessageDto() {
|
|
2300
|
+
return ReturnMessageDto2([ImportEntryDto(this.entityCreateResultDto)]);
|
|
2301
|
+
}
|
|
2302
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
2303
|
+
get idType() {
|
|
2304
|
+
return Reflect.getMetadata("design:type", this.entityClass.prototype, "id");
|
|
2305
|
+
}
|
|
2094
2306
|
usePrefix(methodDec, path) {
|
|
2095
2307
|
if (path) {
|
|
2096
2308
|
if (this.options.prefix) {
|
|
@@ -2123,7 +2335,7 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
2123
2335
|
]);
|
|
2124
2336
|
}
|
|
2125
2337
|
createParam() {
|
|
2126
|
-
return Body(
|
|
2338
|
+
return Body(DataPipe(), OmitPipe(this.fieldsInCreateToOmit));
|
|
2127
2339
|
}
|
|
2128
2340
|
findOne(extras = {}) {
|
|
2129
2341
|
return MergeMethodDecorators([
|
|
@@ -2167,16 +2379,20 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
2167
2379
|
ApiOkResponse({ type: this.entityCursorPaginationReturnMessageDto })
|
|
2168
2380
|
]);
|
|
2169
2381
|
}
|
|
2170
|
-
|
|
2171
|
-
const
|
|
2172
|
-
return
|
|
2382
|
+
getMutatorColumns() {
|
|
2383
|
+
const mutatorColumns = getSpecificFields(this.entityClass, "getMutator");
|
|
2384
|
+
return _5.difference(mutatorColumns, this.fieldsInGetToOmit);
|
|
2173
2385
|
}
|
|
2174
2386
|
findAllParam() {
|
|
2175
|
-
const
|
|
2176
|
-
|
|
2177
|
-
|
|
2387
|
+
const mutatorColumns = this.getMutatorColumns();
|
|
2388
|
+
const restPipes = [OptionalDataPipe(), OmitPipe(this.fieldsInGetToOmit)];
|
|
2389
|
+
if (this.options.skipNonQueryableFields) {
|
|
2390
|
+
restPipes.push(PickPipe(this.queryableFields));
|
|
2391
|
+
}
|
|
2392
|
+
if (mutatorColumns.length) {
|
|
2393
|
+
return Query(new MutatorPipe(this.entityClass), ...restPipes);
|
|
2178
2394
|
} else {
|
|
2179
|
-
return Query(
|
|
2395
|
+
return Query(...restPipes);
|
|
2180
2396
|
}
|
|
2181
2397
|
}
|
|
2182
2398
|
update(extras = {}) {
|
|
@@ -2205,7 +2421,7 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
2205
2421
|
]);
|
|
2206
2422
|
}
|
|
2207
2423
|
updateParam() {
|
|
2208
|
-
return Body(
|
|
2424
|
+
return Body(OptionalDataPipe(), OmitPipe(this.fieldsInUpdateToOmit));
|
|
2209
2425
|
}
|
|
2210
2426
|
delete(extras = {}) {
|
|
2211
2427
|
return MergeMethodDecorators([
|
|
@@ -2359,14 +2575,134 @@ var RestfulFactory = class _RestfulFactory {
|
|
|
2359
2575
|
crudService(options = {}) {
|
|
2360
2576
|
return CrudService(this.entityClass, {
|
|
2361
2577
|
relations: this.options.relations,
|
|
2578
|
+
outputFieldsToOmit: this.options.outputFieldsToOmit,
|
|
2362
2579
|
...options
|
|
2363
2580
|
});
|
|
2364
2581
|
}
|
|
2365
2582
|
};
|
|
2583
|
+
__decorateClass([
|
|
2584
|
+
Memorize()
|
|
2585
|
+
], _RestfulFactory.prototype, "fieldsToOmit", 1);
|
|
2586
|
+
__decorateClass([
|
|
2587
|
+
Memorize()
|
|
2588
|
+
], _RestfulFactory.prototype, "fieldsInCreateToOmit", 1);
|
|
2589
|
+
__decorateClass([
|
|
2590
|
+
Memorize()
|
|
2591
|
+
], _RestfulFactory.prototype, "createDto", 1);
|
|
2592
|
+
__decorateClass([
|
|
2593
|
+
Memorize()
|
|
2594
|
+
], _RestfulFactory.prototype, "fieldsInUpdateToOmit", 1);
|
|
2595
|
+
__decorateClass([
|
|
2596
|
+
Memorize()
|
|
2597
|
+
], _RestfulFactory.prototype, "updateDto", 1);
|
|
2598
|
+
__decorateClass([
|
|
2599
|
+
Memorize()
|
|
2600
|
+
], _RestfulFactory.prototype, "importDto", 1);
|
|
2601
|
+
__decorateClass([
|
|
2602
|
+
Memorize()
|
|
2603
|
+
], _RestfulFactory.prototype, "fieldsInGetToOmit", 1);
|
|
2604
|
+
__decorateClass([
|
|
2605
|
+
Memorize()
|
|
2606
|
+
], _RestfulFactory.prototype, "queryableFields", 1);
|
|
2607
|
+
__decorateClass([
|
|
2608
|
+
Memorize()
|
|
2609
|
+
], _RestfulFactory.prototype, "findAllDto", 1);
|
|
2610
|
+
__decorateClass([
|
|
2611
|
+
Memorize()
|
|
2612
|
+
], _RestfulFactory.prototype, "findAllCursorPaginatedDto", 1);
|
|
2613
|
+
__decorateClass([
|
|
2614
|
+
Memorize()
|
|
2615
|
+
], _RestfulFactory.prototype, "entityResultDto", 1);
|
|
2616
|
+
__decorateClass([
|
|
2617
|
+
Memorize()
|
|
2618
|
+
], _RestfulFactory.prototype, "entityCreateResultDto", 1);
|
|
2619
|
+
__decorateClass([
|
|
2620
|
+
Memorize()
|
|
2621
|
+
], _RestfulFactory.prototype, "entityReturnMessageDto", 1);
|
|
2622
|
+
__decorateClass([
|
|
2623
|
+
Memorize()
|
|
2624
|
+
], _RestfulFactory.prototype, "entityCreateReturnMessageDto", 1);
|
|
2625
|
+
__decorateClass([
|
|
2626
|
+
Memorize()
|
|
2627
|
+
], _RestfulFactory.prototype, "entityArrayReturnMessageDto", 1);
|
|
2628
|
+
__decorateClass([
|
|
2629
|
+
Memorize()
|
|
2630
|
+
], _RestfulFactory.prototype, "entityCursorPaginationReturnMessageDto", 1);
|
|
2631
|
+
__decorateClass([
|
|
2632
|
+
Memorize()
|
|
2633
|
+
], _RestfulFactory.prototype, "importReturnMessageDto", 1);
|
|
2634
|
+
__decorateClass([
|
|
2635
|
+
Memorize()
|
|
2636
|
+
], _RestfulFactory.prototype, "idType", 1);
|
|
2637
|
+
var RestfulFactory = _RestfulFactory;
|
|
2638
|
+
|
|
2639
|
+
// src/utility/query.ts
|
|
2640
|
+
function createQueryCondition(cond) {
|
|
2641
|
+
return (obj, qb, entityName, ...fields) => {
|
|
2642
|
+
for (const field of fields) {
|
|
2643
|
+
if (obj[field] == null) {
|
|
2644
|
+
continue;
|
|
2645
|
+
}
|
|
2646
|
+
const ret = cond(obj, qb, entityName, field);
|
|
2647
|
+
if (typeof ret === "string") {
|
|
2648
|
+
qb.andWhere(ret);
|
|
2649
|
+
} else if (typeof ret === "object" && typeof ret["query"] === "string") {
|
|
2650
|
+
const _ret = ret;
|
|
2651
|
+
qb.andWhere(_ret.query, _ret.params);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
return qb;
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
var applyQueryProperty = createQueryCondition(
|
|
2658
|
+
(obj, qb, entityName, field) => qb.andWhere(`${entityName}.${field} = :${field}`, { [field]: obj[field] })
|
|
2659
|
+
);
|
|
2660
|
+
var applyQueryPropertyLike = createQueryCondition(
|
|
2661
|
+
(obj, qb, entityName, field) => qb.andWhere(`${entityName}.${field} like (:${field} || '%')`, {
|
|
2662
|
+
[field]: obj[field]
|
|
2663
|
+
})
|
|
2664
|
+
);
|
|
2665
|
+
var applyQueryPropertySearch = createQueryCondition(
|
|
2666
|
+
(obj, qb, entityName, field) => qb.andWhere(`${entityName}.${field} like ('%' || :${field} || '%')`, {
|
|
2667
|
+
[field]: obj[field]
|
|
2668
|
+
})
|
|
2669
|
+
);
|
|
2670
|
+
var applyQueryPropertyZeroNullable = createQueryCondition(
|
|
2671
|
+
(obj, qb, entityName, field) => {
|
|
2672
|
+
if ([0, "0"].indexOf(obj[field]) !== -1) {
|
|
2673
|
+
qb.andWhere(`${entityName}.${field} IS NULL`);
|
|
2674
|
+
} else {
|
|
2675
|
+
qb.andWhere(`${entityName}.${field} = :${field}`, {
|
|
2676
|
+
[field]: obj[field]
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
);
|
|
2681
|
+
var applyQueryMatchBoolean = createQueryCondition(
|
|
2682
|
+
(obj, qb, entityName, field) => {
|
|
2683
|
+
const value = parseBool(obj[field]);
|
|
2684
|
+
if (value === true) {
|
|
2685
|
+
qb.andWhere(`${entityName}.${field} = TRUE`);
|
|
2686
|
+
}
|
|
2687
|
+
if (value === false) {
|
|
2688
|
+
qb.andWhere(`${entityName}.${field} = FALSE`);
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
);
|
|
2692
|
+
var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
2693
|
+
(obj, qb, entityName, field) => {
|
|
2694
|
+
const value = parseBool(obj[field]);
|
|
2695
|
+
if (value === true) {
|
|
2696
|
+
qb.andWhere(`${entityName}.${field} = 1`);
|
|
2697
|
+
}
|
|
2698
|
+
if (value === false) {
|
|
2699
|
+
qb.andWhere(`${entityName}.${field} = 0`);
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
);
|
|
2366
2703
|
export {
|
|
2367
2704
|
BlankCursorPaginationReturnMessageDto,
|
|
2368
2705
|
BoolColumn,
|
|
2369
|
-
CreatePipe,
|
|
2370
2706
|
CrudBase,
|
|
2371
2707
|
CrudService,
|
|
2372
2708
|
CursorPaginationDto,
|
|
@@ -2375,7 +2711,14 @@ export {
|
|
|
2375
2711
|
EnumColumn,
|
|
2376
2712
|
FloatColumn,
|
|
2377
2713
|
GenericCursorPaginationReturnMessageDto,
|
|
2378
|
-
|
|
2714
|
+
GetMutator,
|
|
2715
|
+
GetMutatorBool,
|
|
2716
|
+
GetMutatorFloat,
|
|
2717
|
+
GetMutatorFloatSeparated,
|
|
2718
|
+
GetMutatorInt,
|
|
2719
|
+
GetMutatorIntSeparated,
|
|
2720
|
+
GetMutatorJson,
|
|
2721
|
+
GetMutatorStringSeparated,
|
|
2379
2722
|
IdBase,
|
|
2380
2723
|
ImportDataBaseDto,
|
|
2381
2724
|
ImportDataDto,
|
|
@@ -2386,10 +2729,15 @@ export {
|
|
|
2386
2729
|
JsonColumn,
|
|
2387
2730
|
NotChangeable,
|
|
2388
2731
|
NotColumn,
|
|
2732
|
+
NotCreatable,
|
|
2389
2733
|
NotInResult,
|
|
2390
2734
|
NotQueryable,
|
|
2391
2735
|
NotWritable,
|
|
2736
|
+
OmitPipe,
|
|
2737
|
+
OptionalDataPipe,
|
|
2392
2738
|
PageSettingsDto,
|
|
2739
|
+
PickPipe,
|
|
2740
|
+
QueryAnd,
|
|
2393
2741
|
QueryColumn,
|
|
2394
2742
|
QueryCondition,
|
|
2395
2743
|
QueryEqual,
|
|
@@ -2397,16 +2745,24 @@ export {
|
|
|
2397
2745
|
QueryFullText,
|
|
2398
2746
|
QueryGreater,
|
|
2399
2747
|
QueryGreaterEqual,
|
|
2748
|
+
QueryIn,
|
|
2749
|
+
QueryJsonbHas,
|
|
2400
2750
|
QueryLess,
|
|
2401
2751
|
QueryLessEqual,
|
|
2402
2752
|
QueryLike,
|
|
2753
|
+
QueryManual,
|
|
2403
2754
|
QueryMatchBoolean,
|
|
2404
2755
|
QueryMatchBooleanMySQL,
|
|
2405
2756
|
QueryNotEqual,
|
|
2757
|
+
QueryNotIn,
|
|
2406
2758
|
QueryOperator,
|
|
2759
|
+
QueryOr,
|
|
2407
2760
|
QuerySearch,
|
|
2761
|
+
QueryWrap,
|
|
2762
|
+
QueryWrapInfo,
|
|
2408
2763
|
Relation,
|
|
2409
2764
|
RelationComputed,
|
|
2765
|
+
RequireGetMutator,
|
|
2410
2766
|
RestfulFactory,
|
|
2411
2767
|
SimpleJsonColumn,
|
|
2412
2768
|
StringColumn,
|
|
@@ -2414,7 +2770,6 @@ export {
|
|
|
2414
2770
|
StringJsonColumn,
|
|
2415
2771
|
TextColumn,
|
|
2416
2772
|
TimeBase,
|
|
2417
|
-
UpdatePipe,
|
|
2418
2773
|
UuidColumn,
|
|
2419
2774
|
applyQueryMatchBoolean,
|
|
2420
2775
|
applyQueryMatchBooleanMySQL,
|
|
@@ -2422,7 +2777,11 @@ export {
|
|
|
2422
2777
|
applyQueryPropertyLike,
|
|
2423
2778
|
applyQueryPropertySearch,
|
|
2424
2779
|
applyQueryPropertyZeroNullable,
|
|
2780
|
+
createGetMutator,
|
|
2781
|
+
createQueryArrayify,
|
|
2425
2782
|
createQueryCondition,
|
|
2426
|
-
createQueryOperator
|
|
2783
|
+
createQueryOperator,
|
|
2784
|
+
createQueryOperatorArrayify,
|
|
2785
|
+
createQueryWrap
|
|
2427
2786
|
};
|
|
2428
2787
|
//# sourceMappingURL=index.mjs.map
|