nicot 1.2.6 → 1.2.9
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 +59 -92
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +38 -73
- package/dist/index.mjs.map +3 -3
- package/dist/src/crud-base.d.ts +8 -2
- package/dist/src/decorators/property.d.ts +2 -0
- package/dist/src/restful.d.ts +15 -10
- package/package.json +3 -2
- package/dist/src/utility/memorize.d.ts +0 -1
- package/dist/src/utility/observe-diff.d.ts +0 -6
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
BindingValue: () => BindingValue,
|
|
43
43
|
BlankCursorPaginationReturnMessageDto: () => BlankCursorPaginationReturnMessageDto,
|
|
44
44
|
BoolColumn: () => BoolColumn,
|
|
45
|
+
CreateOnlyColumn: () => CreateOnlyColumn,
|
|
45
46
|
CrudBase: () => CrudBase,
|
|
46
47
|
CrudService: () => CrudService,
|
|
47
48
|
CursorPaginationDto: () => CursorPaginationDto,
|
|
@@ -66,6 +67,7 @@ __export(index_exports, {
|
|
|
66
67
|
ImportEntryDto: () => ImportEntryDto,
|
|
67
68
|
Inner: () => Inner,
|
|
68
69
|
IntColumn: () => IntColumn,
|
|
70
|
+
InternalColumn: () => InternalColumn,
|
|
69
71
|
JsonColumn: () => JsonColumn,
|
|
70
72
|
NotChangeable: () => NotChangeable,
|
|
71
73
|
NotColumn: () => NotColumn,
|
|
@@ -606,6 +608,8 @@ var QueryColumn = (options = {}) => (0, import_nesties3.MergePropertyDecorators)
|
|
|
606
608
|
...options
|
|
607
609
|
})
|
|
608
610
|
]);
|
|
611
|
+
var InternalColumn = () => (0, import_nesties3.MergePropertyDecorators)([NotQueryable(), NotWritable(), NotInResult()]);
|
|
612
|
+
var CreateOnlyColumn = () => (0, import_nesties3.MergePropertyDecorators)([NotQueryable(), NotChangeable(), NotInResult()]);
|
|
609
613
|
var RelationComputed = (type) => (obj, propertyKey) => {
|
|
610
614
|
const fun = () => {
|
|
611
615
|
const designType = Reflect.getMetadata("design:type", obj, propertyKey);
|
|
@@ -1473,30 +1477,7 @@ async function getPaginatedResult(qb, entityClass, entityAliasName, take, cursor
|
|
|
1473
1477
|
|
|
1474
1478
|
// src/crud-base.ts
|
|
1475
1479
|
var import_p_queue = __toESM(require("p-queue"));
|
|
1476
|
-
|
|
1477
|
-
// src/utility/observe-diff.ts
|
|
1478
|
-
var observeDiff = (obj, cb) => {
|
|
1479
|
-
return new Proxy(obj, {
|
|
1480
|
-
set(target, key, value) {
|
|
1481
|
-
const oldValue = target[key];
|
|
1482
|
-
const type = Object.prototype.hasOwnProperty.call(target, key) ? "update" : "add";
|
|
1483
|
-
target[key] = value;
|
|
1484
|
-
cb({ type, key, oldValue, newValue: value });
|
|
1485
|
-
return true;
|
|
1486
|
-
},
|
|
1487
|
-
deleteProperty(target, key) {
|
|
1488
|
-
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
1489
|
-
const oldValue = target[key];
|
|
1490
|
-
delete target[key];
|
|
1491
|
-
cb({ type: "delete", key, oldValue, newValue: void 0 });
|
|
1492
|
-
return true;
|
|
1493
|
-
}
|
|
1494
|
-
return false;
|
|
1495
|
-
}
|
|
1496
|
-
});
|
|
1497
|
-
};
|
|
1498
|
-
|
|
1499
|
-
// src/crud-base.ts
|
|
1480
|
+
var import_nfkit = require("nfkit");
|
|
1500
1481
|
var Relation = (name, options = {}) => {
|
|
1501
1482
|
return { name, inner: false, ...options };
|
|
1502
1483
|
};
|
|
@@ -2109,12 +2090,12 @@ var CrudBase = class {
|
|
|
2109
2090
|
where: { id, ...bindingEnt, ...cond }
|
|
2110
2091
|
});
|
|
2111
2092
|
}
|
|
2112
|
-
async operation(id, cb,
|
|
2093
|
+
async operation(id, cb, options = {}) {
|
|
2113
2094
|
const bindingEnt = await this.getBindingPartialEntity();
|
|
2114
2095
|
const where = {
|
|
2115
2096
|
id,
|
|
2116
2097
|
...bindingEnt,
|
|
2117
|
-
...
|
|
2098
|
+
...options.find?.where || {}
|
|
2118
2099
|
};
|
|
2119
2100
|
const throw404 = () => {
|
|
2120
2101
|
throw new import_nesties8.BlankReturnMessageDto(
|
|
@@ -2125,11 +2106,10 @@ var CrudBase = class {
|
|
|
2125
2106
|
if (!await this.repo.exists({ where })) {
|
|
2126
2107
|
throw404();
|
|
2127
2108
|
}
|
|
2128
|
-
const
|
|
2129
|
-
const repo = tdb.getRepository(this.entityClass);
|
|
2109
|
+
const op = async (repo) => {
|
|
2130
2110
|
const ent = await repo.findOne({
|
|
2131
|
-
lock: { mode: "pessimistic_write" },
|
|
2132
|
-
...
|
|
2111
|
+
lock: { mode: "pessimistic_write", tables: [repo.metadata.tableName] },
|
|
2112
|
+
...options.find || {},
|
|
2133
2113
|
where
|
|
2134
2114
|
});
|
|
2135
2115
|
if (!ent) {
|
|
@@ -2137,7 +2117,7 @@ var CrudBase = class {
|
|
|
2137
2117
|
}
|
|
2138
2118
|
const initial = { ...ent };
|
|
2139
2119
|
let changes = {};
|
|
2140
|
-
const entProxy = observeDiff(ent, (change) => {
|
|
2120
|
+
const entProxy = (0, import_nfkit.observeDiff)(ent, (change) => {
|
|
2141
2121
|
if (change.type === "delete") {
|
|
2142
2122
|
if (initial[change.key] === null) {
|
|
2143
2123
|
delete changes[change.key];
|
|
@@ -2163,7 +2143,10 @@ var CrudBase = class {
|
|
|
2163
2143
|
const result = await cb(entProxy, { repo, flush });
|
|
2164
2144
|
await flush();
|
|
2165
2145
|
return result;
|
|
2166
|
-
}
|
|
2146
|
+
};
|
|
2147
|
+
const res = await (options.repo ? op(options.repo) : this.repo.manager.transaction(
|
|
2148
|
+
(tdb) => op(tdb.getRepository(this.entityClass))
|
|
2149
|
+
));
|
|
2167
2150
|
if (res == null) {
|
|
2168
2151
|
return new import_nesties8.BlankReturnMessageDto(200, "success");
|
|
2169
2152
|
} else {
|
|
@@ -2341,20 +2324,6 @@ var PatchColumnsInGet = (cl, originalCl = cl, fieldsToOmit = []) => {
|
|
|
2341
2324
|
return cl;
|
|
2342
2325
|
};
|
|
2343
2326
|
|
|
2344
|
-
// src/utility/memorize.ts
|
|
2345
|
-
var Memorize = () => {
|
|
2346
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
2347
|
-
return function(_target, propertyKey, descriptor) {
|
|
2348
|
-
const getter = descriptor.get;
|
|
2349
|
-
descriptor.get = function() {
|
|
2350
|
-
if (cache.has(this)) return cache.get(this);
|
|
2351
|
-
const value = getter.call(this);
|
|
2352
|
-
cache.set(this, value);
|
|
2353
|
-
return value;
|
|
2354
|
-
};
|
|
2355
|
-
};
|
|
2356
|
-
};
|
|
2357
|
-
|
|
2358
2327
|
// src/utility/mutate-pipe.ts
|
|
2359
2328
|
var MutatorPipe = class {
|
|
2360
2329
|
constructor(entityClass) {
|
|
@@ -2379,6 +2348,7 @@ var MutatorPipe = class {
|
|
|
2379
2348
|
};
|
|
2380
2349
|
|
|
2381
2350
|
// src/restful.ts
|
|
2351
|
+
var import_nfkit2 = require("nfkit");
|
|
2382
2352
|
var getCurrentLevelRelations = (relations) => relations.filter((r) => !r.includes("."));
|
|
2383
2353
|
var getNextLevelRelations = (relations, enteringField) => relations.filter((r) => r.includes(".") && r.startsWith(`${enteringField}.`)).map((r) => r.split(".").slice(1).join("."));
|
|
2384
2354
|
var _RestfulFactory = class _RestfulFactory {
|
|
@@ -2722,28 +2692,23 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2722
2692
|
get idType() {
|
|
2723
2693
|
return Reflect.getMetadata("design:type", this.entityClass.prototype, "id");
|
|
2724
2694
|
}
|
|
2725
|
-
usePrefix(methodDec,
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
}
|
|
2695
|
+
usePrefix(methodDec, ...paths) {
|
|
2696
|
+
const usePaths = [this.options.prefix, ...paths].filter(
|
|
2697
|
+
(s) => s && s.length > 0
|
|
2698
|
+
);
|
|
2699
|
+
if (usePaths.length > 0) {
|
|
2700
|
+
return methodDec(usePaths.join("/"));
|
|
2732
2701
|
} else {
|
|
2733
|
-
|
|
2734
|
-
return methodDec(this.options.prefix);
|
|
2735
|
-
} else {
|
|
2736
|
-
return methodDec();
|
|
2737
|
-
}
|
|
2702
|
+
return methodDec();
|
|
2738
2703
|
}
|
|
2739
2704
|
}
|
|
2740
2705
|
create(extras = {}) {
|
|
2741
2706
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2742
|
-
this.usePrefix(import_common3.Post),
|
|
2707
|
+
this.usePrefix(import_common3.Post, extras.prefix),
|
|
2743
2708
|
(0, import_common3.HttpCode)(200),
|
|
2744
2709
|
(0, import_swagger6.ApiOperation)({
|
|
2745
2710
|
summary: `Create a new ${this.entityClassName}`,
|
|
2746
|
-
...extras
|
|
2711
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2747
2712
|
}),
|
|
2748
2713
|
(0, import_swagger6.ApiBody)({ type: this.createDto }),
|
|
2749
2714
|
(0, import_swagger6.ApiOkResponse)({ type: this.entityCreateReturnMessageDto }),
|
|
@@ -2755,10 +2720,10 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2755
2720
|
}
|
|
2756
2721
|
findOne(extras = {}) {
|
|
2757
2722
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2758
|
-
this.usePrefix(import_common3.Get, ":id"),
|
|
2723
|
+
this.usePrefix(import_common3.Get, extras.prefix, ":id"),
|
|
2759
2724
|
(0, import_swagger6.ApiOperation)({
|
|
2760
2725
|
summary: `Find a ${this.entityClassName} by id`,
|
|
2761
|
-
...extras
|
|
2726
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2762
2727
|
}),
|
|
2763
2728
|
(0, import_swagger6.ApiParam)({ name: "id", type: this.idType, required: true }),
|
|
2764
2729
|
(0, import_swagger6.ApiOkResponse)({ type: this.entityReturnMessageDto }),
|
|
@@ -2777,20 +2742,20 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2777
2742
|
}
|
|
2778
2743
|
findAll(extras = {}) {
|
|
2779
2744
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2780
|
-
this.usePrefix(import_common3.Get),
|
|
2745
|
+
this.usePrefix(import_common3.Get, extras.prefix),
|
|
2781
2746
|
(0, import_swagger6.ApiOperation)({
|
|
2782
2747
|
summary: `Find all ${this.entityClassName}`,
|
|
2783
|
-
...extras
|
|
2748
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2784
2749
|
}),
|
|
2785
2750
|
(0, import_swagger6.ApiOkResponse)({ type: this.entityArrayReturnMessageDto })
|
|
2786
2751
|
]);
|
|
2787
2752
|
}
|
|
2788
2753
|
findAllCursorPaginated(extras = {}) {
|
|
2789
2754
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2790
|
-
this.usePrefix(import_common3.Get),
|
|
2755
|
+
this.usePrefix(import_common3.Get, extras.prefix),
|
|
2791
2756
|
(0, import_swagger6.ApiOperation)({
|
|
2792
2757
|
summary: `Find all ${this.entityClassName}`,
|
|
2793
|
-
...extras
|
|
2758
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2794
2759
|
}),
|
|
2795
2760
|
(0, import_swagger6.ApiOkResponse)({ type: this.entityCursorPaginationReturnMessageDto })
|
|
2796
2761
|
]);
|
|
@@ -2813,11 +2778,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2813
2778
|
}
|
|
2814
2779
|
update(extras = {}) {
|
|
2815
2780
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2816
|
-
this.usePrefix(import_common3.Patch, ":id"),
|
|
2781
|
+
this.usePrefix(import_common3.Patch, extras.prefix, ":id"),
|
|
2817
2782
|
(0, import_common3.HttpCode)(200),
|
|
2818
2783
|
(0, import_swagger6.ApiOperation)({
|
|
2819
2784
|
summary: `Update a ${this.entityClassName} by id`,
|
|
2820
|
-
...extras
|
|
2785
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2821
2786
|
}),
|
|
2822
2787
|
(0, import_swagger6.ApiParam)({ name: "id", type: this.idType, required: true }),
|
|
2823
2788
|
(0, import_swagger6.ApiBody)({ type: this.updateDto }),
|
|
@@ -2835,11 +2800,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2835
2800
|
}
|
|
2836
2801
|
delete(extras = {}) {
|
|
2837
2802
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2838
|
-
this.usePrefix(import_common3.Delete, ":id"),
|
|
2803
|
+
this.usePrefix(import_common3.Delete, extras.prefix, ":id"),
|
|
2839
2804
|
(0, import_common3.HttpCode)(200),
|
|
2840
2805
|
(0, import_swagger6.ApiOperation)({
|
|
2841
2806
|
summary: `Delete a ${this.entityClassName} by id`,
|
|
2842
|
-
...extras
|
|
2807
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2843
2808
|
}),
|
|
2844
2809
|
(0, import_swagger6.ApiParam)({ name: "id", type: this.idType, required: true }),
|
|
2845
2810
|
(0, import_nesties10.ApiBlankResponse)(),
|
|
@@ -2852,11 +2817,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2852
2817
|
}
|
|
2853
2818
|
import(extras = {}) {
|
|
2854
2819
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2855
|
-
this.usePrefix(import_common3.Post, "import"),
|
|
2820
|
+
this.usePrefix(import_common3.Post, extras.prefix, "import"),
|
|
2856
2821
|
(0, import_common3.HttpCode)(200),
|
|
2857
2822
|
(0, import_swagger6.ApiOperation)({
|
|
2858
2823
|
summary: `Import ${this.entityClassName}`,
|
|
2859
|
-
...extras
|
|
2824
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2860
2825
|
}),
|
|
2861
2826
|
(0, import_swagger6.ApiBody)({ type: this.importDto }),
|
|
2862
2827
|
(0, import_swagger6.ApiOkResponse)({ type: this.importReturnMessageDto }),
|
|
@@ -2865,11 +2830,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2865
2830
|
}
|
|
2866
2831
|
operation(operationName, options = {}) {
|
|
2867
2832
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2868
|
-
this.usePrefix(import_common3.Post,
|
|
2833
|
+
this.usePrefix(import_common3.Post, options.prefix, ":id", operationName),
|
|
2869
2834
|
(0, import_common3.HttpCode)(200),
|
|
2870
2835
|
(0, import_swagger6.ApiOperation)({
|
|
2871
2836
|
summary: `${(0, import_lodash5.upperFirst)(operationName)} a ${this.entityClassName} by id`,
|
|
2872
|
-
...options
|
|
2837
|
+
...import_lodash5.default.omit(options, "prefix", "returnType")
|
|
2873
2838
|
}),
|
|
2874
2839
|
options.returnType ? (0, import_nesties10.ApiTypeResponse)(options.returnType) : (0, import_nesties10.ApiBlankResponse)(),
|
|
2875
2840
|
(0, import_nesties10.ApiError)(
|
|
@@ -3000,58 +2965,58 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
3000
2965
|
}
|
|
3001
2966
|
};
|
|
3002
2967
|
__decorateClass([
|
|
3003
|
-
Memorize()
|
|
2968
|
+
(0, import_nfkit2.Memorize)()
|
|
3004
2969
|
], _RestfulFactory.prototype, "fieldsToOmit", 1);
|
|
3005
2970
|
__decorateClass([
|
|
3006
|
-
Memorize()
|
|
2971
|
+
(0, import_nfkit2.Memorize)()
|
|
3007
2972
|
], _RestfulFactory.prototype, "fieldsInCreateToOmit", 1);
|
|
3008
2973
|
__decorateClass([
|
|
3009
|
-
Memorize()
|
|
2974
|
+
(0, import_nfkit2.Memorize)()
|
|
3010
2975
|
], _RestfulFactory.prototype, "createDto", 1);
|
|
3011
2976
|
__decorateClass([
|
|
3012
|
-
Memorize()
|
|
2977
|
+
(0, import_nfkit2.Memorize)()
|
|
3013
2978
|
], _RestfulFactory.prototype, "fieldsInUpdateToOmit", 1);
|
|
3014
2979
|
__decorateClass([
|
|
3015
|
-
Memorize()
|
|
2980
|
+
(0, import_nfkit2.Memorize)()
|
|
3016
2981
|
], _RestfulFactory.prototype, "updateDto", 1);
|
|
3017
2982
|
__decorateClass([
|
|
3018
|
-
Memorize()
|
|
2983
|
+
(0, import_nfkit2.Memorize)()
|
|
3019
2984
|
], _RestfulFactory.prototype, "importDto", 1);
|
|
3020
2985
|
__decorateClass([
|
|
3021
|
-
Memorize()
|
|
2986
|
+
(0, import_nfkit2.Memorize)()
|
|
3022
2987
|
], _RestfulFactory.prototype, "fieldsInGetToOmit", 1);
|
|
3023
2988
|
__decorateClass([
|
|
3024
|
-
Memorize()
|
|
2989
|
+
(0, import_nfkit2.Memorize)()
|
|
3025
2990
|
], _RestfulFactory.prototype, "queryableFields", 1);
|
|
3026
2991
|
__decorateClass([
|
|
3027
|
-
Memorize()
|
|
2992
|
+
(0, import_nfkit2.Memorize)()
|
|
3028
2993
|
], _RestfulFactory.prototype, "findAllDto", 1);
|
|
3029
2994
|
__decorateClass([
|
|
3030
|
-
Memorize()
|
|
2995
|
+
(0, import_nfkit2.Memorize)()
|
|
3031
2996
|
], _RestfulFactory.prototype, "findAllCursorPaginatedDto", 1);
|
|
3032
2997
|
__decorateClass([
|
|
3033
|
-
Memorize()
|
|
2998
|
+
(0, import_nfkit2.Memorize)()
|
|
3034
2999
|
], _RestfulFactory.prototype, "entityResultDto", 1);
|
|
3035
3000
|
__decorateClass([
|
|
3036
|
-
Memorize()
|
|
3001
|
+
(0, import_nfkit2.Memorize)()
|
|
3037
3002
|
], _RestfulFactory.prototype, "entityCreateResultDto", 1);
|
|
3038
3003
|
__decorateClass([
|
|
3039
|
-
Memorize()
|
|
3004
|
+
(0, import_nfkit2.Memorize)()
|
|
3040
3005
|
], _RestfulFactory.prototype, "entityReturnMessageDto", 1);
|
|
3041
3006
|
__decorateClass([
|
|
3042
|
-
Memorize()
|
|
3007
|
+
(0, import_nfkit2.Memorize)()
|
|
3043
3008
|
], _RestfulFactory.prototype, "entityCreateReturnMessageDto", 1);
|
|
3044
3009
|
__decorateClass([
|
|
3045
|
-
Memorize()
|
|
3010
|
+
(0, import_nfkit2.Memorize)()
|
|
3046
3011
|
], _RestfulFactory.prototype, "entityArrayReturnMessageDto", 1);
|
|
3047
3012
|
__decorateClass([
|
|
3048
|
-
Memorize()
|
|
3013
|
+
(0, import_nfkit2.Memorize)()
|
|
3049
3014
|
], _RestfulFactory.prototype, "entityCursorPaginationReturnMessageDto", 1);
|
|
3050
3015
|
__decorateClass([
|
|
3051
|
-
Memorize()
|
|
3016
|
+
(0, import_nfkit2.Memorize)()
|
|
3052
3017
|
], _RestfulFactory.prototype, "importReturnMessageDto", 1);
|
|
3053
3018
|
__decorateClass([
|
|
3054
|
-
Memorize()
|
|
3019
|
+
(0, import_nfkit2.Memorize)()
|
|
3055
3020
|
], _RestfulFactory.prototype, "idType", 1);
|
|
3056
3021
|
var RestfulFactory = _RestfulFactory;
|
|
3057
3022
|
|
|
@@ -3125,6 +3090,7 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
|
3125
3090
|
BindingValue,
|
|
3126
3091
|
BlankCursorPaginationReturnMessageDto,
|
|
3127
3092
|
BoolColumn,
|
|
3093
|
+
CreateOnlyColumn,
|
|
3128
3094
|
CrudBase,
|
|
3129
3095
|
CrudService,
|
|
3130
3096
|
CursorPaginationDto,
|
|
@@ -3149,6 +3115,7 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
|
3149
3115
|
ImportEntryDto,
|
|
3150
3116
|
Inner,
|
|
3151
3117
|
IntColumn,
|
|
3118
|
+
InternalColumn,
|
|
3152
3119
|
JsonColumn,
|
|
3153
3120
|
NotChangeable,
|
|
3154
3121
|
NotColumn,
|