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