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