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.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);
@@ -2007,12 +2009,12 @@ var CrudBase = class {
2007
2009
  where: { id, ...bindingEnt, ...cond }
2008
2010
  });
2009
2011
  }
2010
- async operation(id, cb, extraOptions = {}) {
2012
+ async operation(id, cb, options = {}) {
2011
2013
  const bindingEnt = await this.getBindingPartialEntity();
2012
2014
  const where = {
2013
2015
  id,
2014
2016
  ...bindingEnt,
2015
- ...extraOptions.where || {}
2017
+ ...options.find?.where || {}
2016
2018
  };
2017
2019
  const throw404 = () => {
2018
2020
  throw new BlankReturnMessageDto2(
@@ -2023,11 +2025,10 @@ var CrudBase = class {
2023
2025
  if (!await this.repo.exists({ where })) {
2024
2026
  throw404();
2025
2027
  }
2026
- const res = await this.repo.manager.transaction(async (tdb) => {
2027
- const repo = tdb.getRepository(this.entityClass);
2028
+ const op = async (repo) => {
2028
2029
  const ent = await repo.findOne({
2029
- lock: { mode: "pessimistic_write" },
2030
- ...extraOptions,
2030
+ lock: { mode: "pessimistic_write", tables: [repo.metadata.tableName] },
2031
+ ...options.find || {},
2031
2032
  where
2032
2033
  });
2033
2034
  if (!ent) {
@@ -2061,7 +2062,10 @@ var CrudBase = class {
2061
2062
  const result = await cb(entProxy, { repo, flush });
2062
2063
  await flush();
2063
2064
  return result;
2064
- });
2065
+ };
2066
+ const res = await (options.repo ? op(options.repo) : this.repo.manager.transaction(
2067
+ (tdb) => op(tdb.getRepository(this.entityClass))
2068
+ ));
2065
2069
  if (res == null) {
2066
2070
  return new BlankReturnMessageDto2(200, "success");
2067
2071
  } else {
@@ -2267,20 +2271,6 @@ var PatchColumnsInGet = (cl, originalCl = cl, fieldsToOmit = []) => {
2267
2271
  return cl;
2268
2272
  };
2269
2273
 
2270
- // src/utility/memorize.ts
2271
- var Memorize = () => {
2272
- const cache = /* @__PURE__ */ new WeakMap();
2273
- return function(_target, propertyKey, descriptor) {
2274
- const getter = descriptor.get;
2275
- descriptor.get = function() {
2276
- if (cache.has(this)) return cache.get(this);
2277
- const value = getter.call(this);
2278
- cache.set(this, value);
2279
- return value;
2280
- };
2281
- };
2282
- };
2283
-
2284
2274
  // src/utility/mutate-pipe.ts
2285
2275
  var MutatorPipe = class {
2286
2276
  constructor(entityClass) {
@@ -2305,6 +2295,7 @@ var MutatorPipe = class {
2305
2295
  };
2306
2296
 
2307
2297
  // src/restful.ts
2298
+ import { Memorize } from "nfkit";
2308
2299
  var getCurrentLevelRelations = (relations) => relations.filter((r) => !r.includes("."));
2309
2300
  var getNextLevelRelations = (relations, enteringField) => relations.filter((r) => r.includes(".") && r.startsWith(`${enteringField}.`)).map((r) => r.split(".").slice(1).join("."));
2310
2301
  var _RestfulFactory = class _RestfulFactory {
@@ -2648,28 +2639,23 @@ var _RestfulFactory = class _RestfulFactory {
2648
2639
  get idType() {
2649
2640
  return Reflect.getMetadata("design:type", this.entityClass.prototype, "id");
2650
2641
  }
2651
- usePrefix(methodDec, path) {
2652
- if (path) {
2653
- if (this.options.prefix) {
2654
- return methodDec(`${this.options.prefix}/${path}`);
2655
- } else {
2656
- return methodDec(path);
2657
- }
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("/"));
2658
2648
  } else {
2659
- if (this.options.prefix) {
2660
- return methodDec(this.options.prefix);
2661
- } else {
2662
- return methodDec();
2663
- }
2649
+ return methodDec();
2664
2650
  }
2665
2651
  }
2666
2652
  create(extras = {}) {
2667
2653
  return MergeMethodDecorators([
2668
- this.usePrefix(Post),
2654
+ this.usePrefix(Post, extras.prefix),
2669
2655
  HttpCode(200),
2670
2656
  ApiOperation({
2671
2657
  summary: `Create a new ${this.entityClassName}`,
2672
- ...extras
2658
+ ..._5.omit(extras, "prefix")
2673
2659
  }),
2674
2660
  ApiBody({ type: this.createDto }),
2675
2661
  ApiOkResponse({ type: this.entityCreateReturnMessageDto }),
@@ -2681,10 +2667,10 @@ var _RestfulFactory = class _RestfulFactory {
2681
2667
  }
2682
2668
  findOne(extras = {}) {
2683
2669
  return MergeMethodDecorators([
2684
- this.usePrefix(Get, ":id"),
2670
+ this.usePrefix(Get, extras.prefix, ":id"),
2685
2671
  ApiOperation({
2686
2672
  summary: `Find a ${this.entityClassName} by id`,
2687
- ...extras
2673
+ ..._5.omit(extras, "prefix")
2688
2674
  }),
2689
2675
  ApiParam({ name: "id", type: this.idType, required: true }),
2690
2676
  ApiOkResponse({ type: this.entityReturnMessageDto }),
@@ -2703,20 +2689,20 @@ var _RestfulFactory = class _RestfulFactory {
2703
2689
  }
2704
2690
  findAll(extras = {}) {
2705
2691
  return MergeMethodDecorators([
2706
- this.usePrefix(Get),
2692
+ this.usePrefix(Get, extras.prefix),
2707
2693
  ApiOperation({
2708
2694
  summary: `Find all ${this.entityClassName}`,
2709
- ...extras
2695
+ ..._5.omit(extras, "prefix")
2710
2696
  }),
2711
2697
  ApiOkResponse({ type: this.entityArrayReturnMessageDto })
2712
2698
  ]);
2713
2699
  }
2714
2700
  findAllCursorPaginated(extras = {}) {
2715
2701
  return MergeMethodDecorators([
2716
- this.usePrefix(Get),
2702
+ this.usePrefix(Get, extras.prefix),
2717
2703
  ApiOperation({
2718
2704
  summary: `Find all ${this.entityClassName}`,
2719
- ...extras
2705
+ ..._5.omit(extras, "prefix")
2720
2706
  }),
2721
2707
  ApiOkResponse({ type: this.entityCursorPaginationReturnMessageDto })
2722
2708
  ]);
@@ -2739,11 +2725,11 @@ var _RestfulFactory = class _RestfulFactory {
2739
2725
  }
2740
2726
  update(extras = {}) {
2741
2727
  return MergeMethodDecorators([
2742
- this.usePrefix(Patch, ":id"),
2728
+ this.usePrefix(Patch, extras.prefix, ":id"),
2743
2729
  HttpCode(200),
2744
2730
  ApiOperation({
2745
2731
  summary: `Update a ${this.entityClassName} by id`,
2746
- ...extras
2732
+ ..._5.omit(extras, "prefix")
2747
2733
  }),
2748
2734
  ApiParam({ name: "id", type: this.idType, required: true }),
2749
2735
  ApiBody({ type: this.updateDto }),
@@ -2761,11 +2747,11 @@ var _RestfulFactory = class _RestfulFactory {
2761
2747
  }
2762
2748
  delete(extras = {}) {
2763
2749
  return MergeMethodDecorators([
2764
- this.usePrefix(Delete, ":id"),
2750
+ this.usePrefix(Delete, extras.prefix, ":id"),
2765
2751
  HttpCode(200),
2766
2752
  ApiOperation({
2767
2753
  summary: `Delete a ${this.entityClassName} by id`,
2768
- ...extras
2754
+ ..._5.omit(extras, "prefix")
2769
2755
  }),
2770
2756
  ApiParam({ name: "id", type: this.idType, required: true }),
2771
2757
  ApiBlankResponse(),
@@ -2778,11 +2764,11 @@ var _RestfulFactory = class _RestfulFactory {
2778
2764
  }
2779
2765
  import(extras = {}) {
2780
2766
  return MergeMethodDecorators([
2781
- this.usePrefix(Post, "import"),
2767
+ this.usePrefix(Post, extras.prefix, "import"),
2782
2768
  HttpCode(200),
2783
2769
  ApiOperation({
2784
2770
  summary: `Import ${this.entityClassName}`,
2785
- ...extras
2771
+ ..._5.omit(extras, "prefix")
2786
2772
  }),
2787
2773
  ApiBody({ type: this.importDto }),
2788
2774
  ApiOkResponse({ type: this.importReturnMessageDto }),
@@ -2791,11 +2777,11 @@ var _RestfulFactory = class _RestfulFactory {
2791
2777
  }
2792
2778
  operation(operationName, options = {}) {
2793
2779
  return MergeMethodDecorators([
2794
- this.usePrefix(Post, `:id/${operationName}`),
2780
+ this.usePrefix(Post, options.prefix, ":id", operationName),
2795
2781
  HttpCode(200),
2796
2782
  ApiOperation({
2797
2783
  summary: `${upperFirst(operationName)} a ${this.entityClassName} by id`,
2798
- ...options.operationExtras || {}
2784
+ ..._5.omit(options, "prefix", "returnType")
2799
2785
  }),
2800
2786
  options.returnType ? ApiTypeResponse(options.returnType) : ApiBlankResponse(),
2801
2787
  ApiError(
@@ -3050,6 +3036,7 @@ export {
3050
3036
  BindingValue,
3051
3037
  BlankCursorPaginationReturnMessageDto,
3052
3038
  BoolColumn,
3039
+ CreateOnlyColumn,
3053
3040
  CrudBase,
3054
3041
  CrudService,
3055
3042
  CursorPaginationDto,
@@ -3074,6 +3061,7 @@ export {
3074
3061
  ImportEntryDto,
3075
3062
  Inner,
3076
3063
  IntColumn,
3064
+ InternalColumn,
3077
3065
  JsonColumn,
3078
3066
  NotChangeable,
3079
3067
  NotColumn,