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.mjs
CHANGED
|
@@ -516,6 +516,8 @@ var QueryColumn = (options = {}) => MergePropertyDecorators2([
|
|
|
516
516
|
...options
|
|
517
517
|
})
|
|
518
518
|
]);
|
|
519
|
+
var InternalColumn = () => MergePropertyDecorators2([NotQueryable(), NotWritable(), NotInResult()]);
|
|
520
|
+
var CreateOnlyColumn = () => MergePropertyDecorators2([NotQueryable(), NotChangeable(), NotInResult()]);
|
|
519
521
|
var RelationComputed = (type) => (obj, propertyKey) => {
|
|
520
522
|
const fun = () => {
|
|
521
523
|
const designType = Reflect.getMetadata("design:type", obj, propertyKey);
|
|
@@ -1394,30 +1396,7 @@ async function getPaginatedResult(qb, entityClass, entityAliasName, take, cursor
|
|
|
1394
1396
|
|
|
1395
1397
|
// src/crud-base.ts
|
|
1396
1398
|
import PQueue from "p-queue";
|
|
1397
|
-
|
|
1398
|
-
// src/utility/observe-diff.ts
|
|
1399
|
-
var observeDiff = (obj, cb) => {
|
|
1400
|
-
return new Proxy(obj, {
|
|
1401
|
-
set(target, key, value) {
|
|
1402
|
-
const oldValue = target[key];
|
|
1403
|
-
const type = Object.prototype.hasOwnProperty.call(target, key) ? "update" : "add";
|
|
1404
|
-
target[key] = value;
|
|
1405
|
-
cb({ type, key, oldValue, newValue: value });
|
|
1406
|
-
return true;
|
|
1407
|
-
},
|
|
1408
|
-
deleteProperty(target, key) {
|
|
1409
|
-
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
1410
|
-
const oldValue = target[key];
|
|
1411
|
-
delete target[key];
|
|
1412
|
-
cb({ type: "delete", key, oldValue, newValue: void 0 });
|
|
1413
|
-
return true;
|
|
1414
|
-
}
|
|
1415
|
-
return false;
|
|
1416
|
-
}
|
|
1417
|
-
});
|
|
1418
|
-
};
|
|
1419
|
-
|
|
1420
|
-
// src/crud-base.ts
|
|
1399
|
+
import { observeDiff } from "nfkit";
|
|
1421
1400
|
var Relation = (name, options = {}) => {
|
|
1422
1401
|
return { name, inner: false, ...options };
|
|
1423
1402
|
};
|
|
@@ -2030,12 +2009,12 @@ var CrudBase = class {
|
|
|
2030
2009
|
where: { id, ...bindingEnt, ...cond }
|
|
2031
2010
|
});
|
|
2032
2011
|
}
|
|
2033
|
-
async operation(id, cb,
|
|
2012
|
+
async operation(id, cb, options = {}) {
|
|
2034
2013
|
const bindingEnt = await this.getBindingPartialEntity();
|
|
2035
2014
|
const where = {
|
|
2036
2015
|
id,
|
|
2037
2016
|
...bindingEnt,
|
|
2038
|
-
...
|
|
2017
|
+
...options.find?.where || {}
|
|
2039
2018
|
};
|
|
2040
2019
|
const throw404 = () => {
|
|
2041
2020
|
throw new BlankReturnMessageDto2(
|
|
@@ -2046,11 +2025,10 @@ var CrudBase = class {
|
|
|
2046
2025
|
if (!await this.repo.exists({ where })) {
|
|
2047
2026
|
throw404();
|
|
2048
2027
|
}
|
|
2049
|
-
const
|
|
2050
|
-
const repo = tdb.getRepository(this.entityClass);
|
|
2028
|
+
const op = async (repo) => {
|
|
2051
2029
|
const ent = await repo.findOne({
|
|
2052
|
-
lock: { mode: "pessimistic_write" },
|
|
2053
|
-
...
|
|
2030
|
+
lock: { mode: "pessimistic_write", tables: [repo.metadata.tableName] },
|
|
2031
|
+
...options.find || {},
|
|
2054
2032
|
where
|
|
2055
2033
|
});
|
|
2056
2034
|
if (!ent) {
|
|
@@ -2084,7 +2062,10 @@ var CrudBase = class {
|
|
|
2084
2062
|
const result = await cb(entProxy, { repo, flush });
|
|
2085
2063
|
await flush();
|
|
2086
2064
|
return result;
|
|
2087
|
-
}
|
|
2065
|
+
};
|
|
2066
|
+
const res = await (options.repo ? op(options.repo) : this.repo.manager.transaction(
|
|
2067
|
+
(tdb) => op(tdb.getRepository(this.entityClass))
|
|
2068
|
+
));
|
|
2088
2069
|
if (res == null) {
|
|
2089
2070
|
return new BlankReturnMessageDto2(200, "success");
|
|
2090
2071
|
} else {
|
|
@@ -2290,20 +2271,6 @@ var PatchColumnsInGet = (cl, originalCl = cl, fieldsToOmit = []) => {
|
|
|
2290
2271
|
return cl;
|
|
2291
2272
|
};
|
|
2292
2273
|
|
|
2293
|
-
// src/utility/memorize.ts
|
|
2294
|
-
var Memorize = () => {
|
|
2295
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
2296
|
-
return function(_target, propertyKey, descriptor) {
|
|
2297
|
-
const getter = descriptor.get;
|
|
2298
|
-
descriptor.get = function() {
|
|
2299
|
-
if (cache.has(this)) return cache.get(this);
|
|
2300
|
-
const value = getter.call(this);
|
|
2301
|
-
cache.set(this, value);
|
|
2302
|
-
return value;
|
|
2303
|
-
};
|
|
2304
|
-
};
|
|
2305
|
-
};
|
|
2306
|
-
|
|
2307
2274
|
// src/utility/mutate-pipe.ts
|
|
2308
2275
|
var MutatorPipe = class {
|
|
2309
2276
|
constructor(entityClass) {
|
|
@@ -2328,6 +2295,7 @@ var MutatorPipe = class {
|
|
|
2328
2295
|
};
|
|
2329
2296
|
|
|
2330
2297
|
// src/restful.ts
|
|
2298
|
+
import { Memorize } from "nfkit";
|
|
2331
2299
|
var getCurrentLevelRelations = (relations) => relations.filter((r) => !r.includes("."));
|
|
2332
2300
|
var getNextLevelRelations = (relations, enteringField) => relations.filter((r) => r.includes(".") && r.startsWith(`${enteringField}.`)).map((r) => r.split(".").slice(1).join("."));
|
|
2333
2301
|
var _RestfulFactory = class _RestfulFactory {
|
|
@@ -2671,28 +2639,23 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2671
2639
|
get idType() {
|
|
2672
2640
|
return Reflect.getMetadata("design:type", this.entityClass.prototype, "id");
|
|
2673
2641
|
}
|
|
2674
|
-
usePrefix(methodDec,
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
}
|
|
2642
|
+
usePrefix(methodDec, ...paths) {
|
|
2643
|
+
const usePaths = [this.options.prefix, ...paths].filter(
|
|
2644
|
+
(s) => s && s.length > 0
|
|
2645
|
+
);
|
|
2646
|
+
if (usePaths.length > 0) {
|
|
2647
|
+
return methodDec(usePaths.join("/"));
|
|
2681
2648
|
} else {
|
|
2682
|
-
|
|
2683
|
-
return methodDec(this.options.prefix);
|
|
2684
|
-
} else {
|
|
2685
|
-
return methodDec();
|
|
2686
|
-
}
|
|
2649
|
+
return methodDec();
|
|
2687
2650
|
}
|
|
2688
2651
|
}
|
|
2689
2652
|
create(extras = {}) {
|
|
2690
2653
|
return MergeMethodDecorators([
|
|
2691
|
-
this.usePrefix(Post),
|
|
2654
|
+
this.usePrefix(Post, extras.prefix),
|
|
2692
2655
|
HttpCode(200),
|
|
2693
2656
|
ApiOperation({
|
|
2694
2657
|
summary: `Create a new ${this.entityClassName}`,
|
|
2695
|
-
...extras
|
|
2658
|
+
..._5.omit(extras, "prefix")
|
|
2696
2659
|
}),
|
|
2697
2660
|
ApiBody({ type: this.createDto }),
|
|
2698
2661
|
ApiOkResponse({ type: this.entityCreateReturnMessageDto }),
|
|
@@ -2704,10 +2667,10 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2704
2667
|
}
|
|
2705
2668
|
findOne(extras = {}) {
|
|
2706
2669
|
return MergeMethodDecorators([
|
|
2707
|
-
this.usePrefix(Get, ":id"),
|
|
2670
|
+
this.usePrefix(Get, extras.prefix, ":id"),
|
|
2708
2671
|
ApiOperation({
|
|
2709
2672
|
summary: `Find a ${this.entityClassName} by id`,
|
|
2710
|
-
...extras
|
|
2673
|
+
..._5.omit(extras, "prefix")
|
|
2711
2674
|
}),
|
|
2712
2675
|
ApiParam({ name: "id", type: this.idType, required: true }),
|
|
2713
2676
|
ApiOkResponse({ type: this.entityReturnMessageDto }),
|
|
@@ -2726,20 +2689,20 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2726
2689
|
}
|
|
2727
2690
|
findAll(extras = {}) {
|
|
2728
2691
|
return MergeMethodDecorators([
|
|
2729
|
-
this.usePrefix(Get),
|
|
2692
|
+
this.usePrefix(Get, extras.prefix),
|
|
2730
2693
|
ApiOperation({
|
|
2731
2694
|
summary: `Find all ${this.entityClassName}`,
|
|
2732
|
-
...extras
|
|
2695
|
+
..._5.omit(extras, "prefix")
|
|
2733
2696
|
}),
|
|
2734
2697
|
ApiOkResponse({ type: this.entityArrayReturnMessageDto })
|
|
2735
2698
|
]);
|
|
2736
2699
|
}
|
|
2737
2700
|
findAllCursorPaginated(extras = {}) {
|
|
2738
2701
|
return MergeMethodDecorators([
|
|
2739
|
-
this.usePrefix(Get),
|
|
2702
|
+
this.usePrefix(Get, extras.prefix),
|
|
2740
2703
|
ApiOperation({
|
|
2741
2704
|
summary: `Find all ${this.entityClassName}`,
|
|
2742
|
-
...extras
|
|
2705
|
+
..._5.omit(extras, "prefix")
|
|
2743
2706
|
}),
|
|
2744
2707
|
ApiOkResponse({ type: this.entityCursorPaginationReturnMessageDto })
|
|
2745
2708
|
]);
|
|
@@ -2762,11 +2725,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2762
2725
|
}
|
|
2763
2726
|
update(extras = {}) {
|
|
2764
2727
|
return MergeMethodDecorators([
|
|
2765
|
-
this.usePrefix(Patch, ":id"),
|
|
2728
|
+
this.usePrefix(Patch, extras.prefix, ":id"),
|
|
2766
2729
|
HttpCode(200),
|
|
2767
2730
|
ApiOperation({
|
|
2768
2731
|
summary: `Update a ${this.entityClassName} by id`,
|
|
2769
|
-
...extras
|
|
2732
|
+
..._5.omit(extras, "prefix")
|
|
2770
2733
|
}),
|
|
2771
2734
|
ApiParam({ name: "id", type: this.idType, required: true }),
|
|
2772
2735
|
ApiBody({ type: this.updateDto }),
|
|
@@ -2784,11 +2747,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2784
2747
|
}
|
|
2785
2748
|
delete(extras = {}) {
|
|
2786
2749
|
return MergeMethodDecorators([
|
|
2787
|
-
this.usePrefix(Delete, ":id"),
|
|
2750
|
+
this.usePrefix(Delete, extras.prefix, ":id"),
|
|
2788
2751
|
HttpCode(200),
|
|
2789
2752
|
ApiOperation({
|
|
2790
2753
|
summary: `Delete a ${this.entityClassName} by id`,
|
|
2791
|
-
...extras
|
|
2754
|
+
..._5.omit(extras, "prefix")
|
|
2792
2755
|
}),
|
|
2793
2756
|
ApiParam({ name: "id", type: this.idType, required: true }),
|
|
2794
2757
|
ApiBlankResponse(),
|
|
@@ -2801,11 +2764,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2801
2764
|
}
|
|
2802
2765
|
import(extras = {}) {
|
|
2803
2766
|
return MergeMethodDecorators([
|
|
2804
|
-
this.usePrefix(Post, "import"),
|
|
2767
|
+
this.usePrefix(Post, extras.prefix, "import"),
|
|
2805
2768
|
HttpCode(200),
|
|
2806
2769
|
ApiOperation({
|
|
2807
2770
|
summary: `Import ${this.entityClassName}`,
|
|
2808
|
-
...extras
|
|
2771
|
+
..._5.omit(extras, "prefix")
|
|
2809
2772
|
}),
|
|
2810
2773
|
ApiBody({ type: this.importDto }),
|
|
2811
2774
|
ApiOkResponse({ type: this.importReturnMessageDto }),
|
|
@@ -2814,11 +2777,11 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2814
2777
|
}
|
|
2815
2778
|
operation(operationName, options = {}) {
|
|
2816
2779
|
return MergeMethodDecorators([
|
|
2817
|
-
this.usePrefix(Post,
|
|
2780
|
+
this.usePrefix(Post, options.prefix, ":id", operationName),
|
|
2818
2781
|
HttpCode(200),
|
|
2819
2782
|
ApiOperation({
|
|
2820
2783
|
summary: `${upperFirst(operationName)} a ${this.entityClassName} by id`,
|
|
2821
|
-
...options
|
|
2784
|
+
..._5.omit(options, "prefix", "returnType")
|
|
2822
2785
|
}),
|
|
2823
2786
|
options.returnType ? ApiTypeResponse(options.returnType) : ApiBlankResponse(),
|
|
2824
2787
|
ApiError(
|
|
@@ -3073,6 +3036,7 @@ export {
|
|
|
3073
3036
|
BindingValue,
|
|
3074
3037
|
BlankCursorPaginationReturnMessageDto,
|
|
3075
3038
|
BoolColumn,
|
|
3039
|
+
CreateOnlyColumn,
|
|
3076
3040
|
CrudBase,
|
|
3077
3041
|
CrudService,
|
|
3078
3042
|
CursorPaginationDto,
|
|
@@ -3097,6 +3061,7 @@ export {
|
|
|
3097
3061
|
ImportEntryDto,
|
|
3098
3062
|
Inner,
|
|
3099
3063
|
IntColumn,
|
|
3064
|
+
InternalColumn,
|
|
3100
3065
|
JsonColumn,
|
|
3101
3066
|
NotChangeable,
|
|
3102
3067
|
NotColumn,
|