nicot 1.2.7 → 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 +57 -67
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +37 -49
- 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 +2 -2
- package/dist/src/utility/memorize.d.ts +0 -1
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);
|
|
@@ -2086,12 +2090,12 @@ var CrudBase = class {
|
|
|
2086
2090
|
where: { id, ...bindingEnt, ...cond }
|
|
2087
2091
|
});
|
|
2088
2092
|
}
|
|
2089
|
-
async operation(id, cb,
|
|
2093
|
+
async operation(id, cb, options = {}) {
|
|
2090
2094
|
const bindingEnt = await this.getBindingPartialEntity();
|
|
2091
2095
|
const where = {
|
|
2092
2096
|
id,
|
|
2093
2097
|
...bindingEnt,
|
|
2094
|
-
...
|
|
2098
|
+
...options.find?.where || {}
|
|
2095
2099
|
};
|
|
2096
2100
|
const throw404 = () => {
|
|
2097
2101
|
throw new import_nesties8.BlankReturnMessageDto(
|
|
@@ -2102,11 +2106,10 @@ var CrudBase = class {
|
|
|
2102
2106
|
if (!await this.repo.exists({ where })) {
|
|
2103
2107
|
throw404();
|
|
2104
2108
|
}
|
|
2105
|
-
const
|
|
2106
|
-
const repo = tdb.getRepository(this.entityClass);
|
|
2109
|
+
const op = async (repo) => {
|
|
2107
2110
|
const ent = await repo.findOne({
|
|
2108
|
-
lock: { mode: "pessimistic_write" },
|
|
2109
|
-
...
|
|
2111
|
+
lock: { mode: "pessimistic_write", tables: [repo.metadata.tableName] },
|
|
2112
|
+
...options.find || {},
|
|
2110
2113
|
where
|
|
2111
2114
|
});
|
|
2112
2115
|
if (!ent) {
|
|
@@ -2140,7 +2143,10 @@ var CrudBase = class {
|
|
|
2140
2143
|
const result = await cb(entProxy, { repo, flush });
|
|
2141
2144
|
await flush();
|
|
2142
2145
|
return result;
|
|
2143
|
-
}
|
|
2146
|
+
};
|
|
2147
|
+
const res = await (options.repo ? op(options.repo) : this.repo.manager.transaction(
|
|
2148
|
+
(tdb) => op(tdb.getRepository(this.entityClass))
|
|
2149
|
+
));
|
|
2144
2150
|
if (res == null) {
|
|
2145
2151
|
return new import_nesties8.BlankReturnMessageDto(200, "success");
|
|
2146
2152
|
} else {
|
|
@@ -2318,20 +2324,6 @@ var PatchColumnsInGet = (cl, originalCl = cl, fieldsToOmit = []) => {
|
|
|
2318
2324
|
return cl;
|
|
2319
2325
|
};
|
|
2320
2326
|
|
|
2321
|
-
// src/utility/memorize.ts
|
|
2322
|
-
var Memorize = () => {
|
|
2323
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
2324
|
-
return function(_target, propertyKey, descriptor) {
|
|
2325
|
-
const getter = descriptor.get;
|
|
2326
|
-
descriptor.get = function() {
|
|
2327
|
-
if (cache.has(this)) return cache.get(this);
|
|
2328
|
-
const value = getter.call(this);
|
|
2329
|
-
cache.set(this, value);
|
|
2330
|
-
return value;
|
|
2331
|
-
};
|
|
2332
|
-
};
|
|
2333
|
-
};
|
|
2334
|
-
|
|
2335
2327
|
// src/utility/mutate-pipe.ts
|
|
2336
2328
|
var MutatorPipe = class {
|
|
2337
2329
|
constructor(entityClass) {
|
|
@@ -2356,6 +2348,7 @@ var MutatorPipe = class {
|
|
|
2356
2348
|
};
|
|
2357
2349
|
|
|
2358
2350
|
// src/restful.ts
|
|
2351
|
+
var import_nfkit2 = require("nfkit");
|
|
2359
2352
|
var getCurrentLevelRelations = (relations) => relations.filter((r) => !r.includes("."));
|
|
2360
2353
|
var getNextLevelRelations = (relations, enteringField) => relations.filter((r) => r.includes(".") && r.startsWith(`${enteringField}.`)).map((r) => r.split(".").slice(1).join("."));
|
|
2361
2354
|
var _RestfulFactory = class _RestfulFactory {
|
|
@@ -2699,28 +2692,23 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2699
2692
|
get idType() {
|
|
2700
2693
|
return Reflect.getMetadata("design:type", this.entityClass.prototype, "id");
|
|
2701
2694
|
}
|
|
2702
|
-
usePrefix(methodDec,
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
}
|
|
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("/"));
|
|
2709
2701
|
} else {
|
|
2710
|
-
|
|
2711
|
-
return methodDec(this.options.prefix);
|
|
2712
|
-
} else {
|
|
2713
|
-
return methodDec();
|
|
2714
|
-
}
|
|
2702
|
+
return methodDec();
|
|
2715
2703
|
}
|
|
2716
2704
|
}
|
|
2717
2705
|
create(extras = {}) {
|
|
2718
2706
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2719
|
-
this.usePrefix(import_common3.Post),
|
|
2707
|
+
this.usePrefix(import_common3.Post, extras.prefix),
|
|
2720
2708
|
(0, import_common3.HttpCode)(200),
|
|
2721
2709
|
(0, import_swagger6.ApiOperation)({
|
|
2722
2710
|
summary: `Create a new ${this.entityClassName}`,
|
|
2723
|
-
...extras
|
|
2711
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2724
2712
|
}),
|
|
2725
2713
|
(0, import_swagger6.ApiBody)({ type: this.createDto }),
|
|
2726
2714
|
(0, import_swagger6.ApiOkResponse)({ type: this.entityCreateReturnMessageDto }),
|
|
@@ -2732,10 +2720,10 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2732
2720
|
}
|
|
2733
2721
|
findOne(extras = {}) {
|
|
2734
2722
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2735
|
-
this.usePrefix(import_common3.Get, ":id"),
|
|
2723
|
+
this.usePrefix(import_common3.Get, extras.prefix, ":id"),
|
|
2736
2724
|
(0, import_swagger6.ApiOperation)({
|
|
2737
2725
|
summary: `Find a ${this.entityClassName} by id`,
|
|
2738
|
-
...extras
|
|
2726
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2739
2727
|
}),
|
|
2740
2728
|
(0, import_swagger6.ApiParam)({ name: "id", type: this.idType, required: true }),
|
|
2741
2729
|
(0, import_swagger6.ApiOkResponse)({ type: this.entityReturnMessageDto }),
|
|
@@ -2754,20 +2742,20 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2754
2742
|
}
|
|
2755
2743
|
findAll(extras = {}) {
|
|
2756
2744
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2757
|
-
this.usePrefix(import_common3.Get),
|
|
2745
|
+
this.usePrefix(import_common3.Get, extras.prefix),
|
|
2758
2746
|
(0, import_swagger6.ApiOperation)({
|
|
2759
2747
|
summary: `Find all ${this.entityClassName}`,
|
|
2760
|
-
...extras
|
|
2748
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2761
2749
|
}),
|
|
2762
2750
|
(0, import_swagger6.ApiOkResponse)({ type: this.entityArrayReturnMessageDto })
|
|
2763
2751
|
]);
|
|
2764
2752
|
}
|
|
2765
2753
|
findAllCursorPaginated(extras = {}) {
|
|
2766
2754
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2767
|
-
this.usePrefix(import_common3.Get),
|
|
2755
|
+
this.usePrefix(import_common3.Get, extras.prefix),
|
|
2768
2756
|
(0, import_swagger6.ApiOperation)({
|
|
2769
2757
|
summary: `Find all ${this.entityClassName}`,
|
|
2770
|
-
...extras
|
|
2758
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2771
2759
|
}),
|
|
2772
2760
|
(0, import_swagger6.ApiOkResponse)({ type: this.entityCursorPaginationReturnMessageDto })
|
|
2773
2761
|
]);
|
|
@@ -2790,11 +2778,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2790
2778
|
}
|
|
2791
2779
|
update(extras = {}) {
|
|
2792
2780
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2793
|
-
this.usePrefix(import_common3.Patch, ":id"),
|
|
2781
|
+
this.usePrefix(import_common3.Patch, extras.prefix, ":id"),
|
|
2794
2782
|
(0, import_common3.HttpCode)(200),
|
|
2795
2783
|
(0, import_swagger6.ApiOperation)({
|
|
2796
2784
|
summary: `Update a ${this.entityClassName} by id`,
|
|
2797
|
-
...extras
|
|
2785
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2798
2786
|
}),
|
|
2799
2787
|
(0, import_swagger6.ApiParam)({ name: "id", type: this.idType, required: true }),
|
|
2800
2788
|
(0, import_swagger6.ApiBody)({ type: this.updateDto }),
|
|
@@ -2812,11 +2800,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2812
2800
|
}
|
|
2813
2801
|
delete(extras = {}) {
|
|
2814
2802
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2815
|
-
this.usePrefix(import_common3.Delete, ":id"),
|
|
2803
|
+
this.usePrefix(import_common3.Delete, extras.prefix, ":id"),
|
|
2816
2804
|
(0, import_common3.HttpCode)(200),
|
|
2817
2805
|
(0, import_swagger6.ApiOperation)({
|
|
2818
2806
|
summary: `Delete a ${this.entityClassName} by id`,
|
|
2819
|
-
...extras
|
|
2807
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2820
2808
|
}),
|
|
2821
2809
|
(0, import_swagger6.ApiParam)({ name: "id", type: this.idType, required: true }),
|
|
2822
2810
|
(0, import_nesties10.ApiBlankResponse)(),
|
|
@@ -2829,11 +2817,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2829
2817
|
}
|
|
2830
2818
|
import(extras = {}) {
|
|
2831
2819
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2832
|
-
this.usePrefix(import_common3.Post, "import"),
|
|
2820
|
+
this.usePrefix(import_common3.Post, extras.prefix, "import"),
|
|
2833
2821
|
(0, import_common3.HttpCode)(200),
|
|
2834
2822
|
(0, import_swagger6.ApiOperation)({
|
|
2835
2823
|
summary: `Import ${this.entityClassName}`,
|
|
2836
|
-
...extras
|
|
2824
|
+
...import_lodash5.default.omit(extras, "prefix")
|
|
2837
2825
|
}),
|
|
2838
2826
|
(0, import_swagger6.ApiBody)({ type: this.importDto }),
|
|
2839
2827
|
(0, import_swagger6.ApiOkResponse)({ type: this.importReturnMessageDto }),
|
|
@@ -2842,11 +2830,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2842
2830
|
}
|
|
2843
2831
|
operation(operationName, options = {}) {
|
|
2844
2832
|
return (0, import_nesties10.MergeMethodDecorators)([
|
|
2845
|
-
this.usePrefix(import_common3.Post,
|
|
2833
|
+
this.usePrefix(import_common3.Post, options.prefix, ":id", operationName),
|
|
2846
2834
|
(0, import_common3.HttpCode)(200),
|
|
2847
2835
|
(0, import_swagger6.ApiOperation)({
|
|
2848
2836
|
summary: `${(0, import_lodash5.upperFirst)(operationName)} a ${this.entityClassName} by id`,
|
|
2849
|
-
...options
|
|
2837
|
+
...import_lodash5.default.omit(options, "prefix", "returnType")
|
|
2850
2838
|
}),
|
|
2851
2839
|
options.returnType ? (0, import_nesties10.ApiTypeResponse)(options.returnType) : (0, import_nesties10.ApiBlankResponse)(),
|
|
2852
2840
|
(0, import_nesties10.ApiError)(
|
|
@@ -2977,58 +2965,58 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2977
2965
|
}
|
|
2978
2966
|
};
|
|
2979
2967
|
__decorateClass([
|
|
2980
|
-
Memorize()
|
|
2968
|
+
(0, import_nfkit2.Memorize)()
|
|
2981
2969
|
], _RestfulFactory.prototype, "fieldsToOmit", 1);
|
|
2982
2970
|
__decorateClass([
|
|
2983
|
-
Memorize()
|
|
2971
|
+
(0, import_nfkit2.Memorize)()
|
|
2984
2972
|
], _RestfulFactory.prototype, "fieldsInCreateToOmit", 1);
|
|
2985
2973
|
__decorateClass([
|
|
2986
|
-
Memorize()
|
|
2974
|
+
(0, import_nfkit2.Memorize)()
|
|
2987
2975
|
], _RestfulFactory.prototype, "createDto", 1);
|
|
2988
2976
|
__decorateClass([
|
|
2989
|
-
Memorize()
|
|
2977
|
+
(0, import_nfkit2.Memorize)()
|
|
2990
2978
|
], _RestfulFactory.prototype, "fieldsInUpdateToOmit", 1);
|
|
2991
2979
|
__decorateClass([
|
|
2992
|
-
Memorize()
|
|
2980
|
+
(0, import_nfkit2.Memorize)()
|
|
2993
2981
|
], _RestfulFactory.prototype, "updateDto", 1);
|
|
2994
2982
|
__decorateClass([
|
|
2995
|
-
Memorize()
|
|
2983
|
+
(0, import_nfkit2.Memorize)()
|
|
2996
2984
|
], _RestfulFactory.prototype, "importDto", 1);
|
|
2997
2985
|
__decorateClass([
|
|
2998
|
-
Memorize()
|
|
2986
|
+
(0, import_nfkit2.Memorize)()
|
|
2999
2987
|
], _RestfulFactory.prototype, "fieldsInGetToOmit", 1);
|
|
3000
2988
|
__decorateClass([
|
|
3001
|
-
Memorize()
|
|
2989
|
+
(0, import_nfkit2.Memorize)()
|
|
3002
2990
|
], _RestfulFactory.prototype, "queryableFields", 1);
|
|
3003
2991
|
__decorateClass([
|
|
3004
|
-
Memorize()
|
|
2992
|
+
(0, import_nfkit2.Memorize)()
|
|
3005
2993
|
], _RestfulFactory.prototype, "findAllDto", 1);
|
|
3006
2994
|
__decorateClass([
|
|
3007
|
-
Memorize()
|
|
2995
|
+
(0, import_nfkit2.Memorize)()
|
|
3008
2996
|
], _RestfulFactory.prototype, "findAllCursorPaginatedDto", 1);
|
|
3009
2997
|
__decorateClass([
|
|
3010
|
-
Memorize()
|
|
2998
|
+
(0, import_nfkit2.Memorize)()
|
|
3011
2999
|
], _RestfulFactory.prototype, "entityResultDto", 1);
|
|
3012
3000
|
__decorateClass([
|
|
3013
|
-
Memorize()
|
|
3001
|
+
(0, import_nfkit2.Memorize)()
|
|
3014
3002
|
], _RestfulFactory.prototype, "entityCreateResultDto", 1);
|
|
3015
3003
|
__decorateClass([
|
|
3016
|
-
Memorize()
|
|
3004
|
+
(0, import_nfkit2.Memorize)()
|
|
3017
3005
|
], _RestfulFactory.prototype, "entityReturnMessageDto", 1);
|
|
3018
3006
|
__decorateClass([
|
|
3019
|
-
Memorize()
|
|
3007
|
+
(0, import_nfkit2.Memorize)()
|
|
3020
3008
|
], _RestfulFactory.prototype, "entityCreateReturnMessageDto", 1);
|
|
3021
3009
|
__decorateClass([
|
|
3022
|
-
Memorize()
|
|
3010
|
+
(0, import_nfkit2.Memorize)()
|
|
3023
3011
|
], _RestfulFactory.prototype, "entityArrayReturnMessageDto", 1);
|
|
3024
3012
|
__decorateClass([
|
|
3025
|
-
Memorize()
|
|
3013
|
+
(0, import_nfkit2.Memorize)()
|
|
3026
3014
|
], _RestfulFactory.prototype, "entityCursorPaginationReturnMessageDto", 1);
|
|
3027
3015
|
__decorateClass([
|
|
3028
|
-
Memorize()
|
|
3016
|
+
(0, import_nfkit2.Memorize)()
|
|
3029
3017
|
], _RestfulFactory.prototype, "importReturnMessageDto", 1);
|
|
3030
3018
|
__decorateClass([
|
|
3031
|
-
Memorize()
|
|
3019
|
+
(0, import_nfkit2.Memorize)()
|
|
3032
3020
|
], _RestfulFactory.prototype, "idType", 1);
|
|
3033
3021
|
var RestfulFactory = _RestfulFactory;
|
|
3034
3022
|
|
|
@@ -3102,6 +3090,7 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
|
3102
3090
|
BindingValue,
|
|
3103
3091
|
BlankCursorPaginationReturnMessageDto,
|
|
3104
3092
|
BoolColumn,
|
|
3093
|
+
CreateOnlyColumn,
|
|
3105
3094
|
CrudBase,
|
|
3106
3095
|
CrudService,
|
|
3107
3096
|
CursorPaginationDto,
|
|
@@ -3126,6 +3115,7 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
|
3126
3115
|
ImportEntryDto,
|
|
3127
3116
|
Inner,
|
|
3128
3117
|
IntColumn,
|
|
3118
|
+
InternalColumn,
|
|
3129
3119
|
JsonColumn,
|
|
3130
3120
|
NotChangeable,
|
|
3131
3121
|
NotColumn,
|