nicot 1.2.4 → 1.2.6

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 CHANGED
@@ -38,6 +38,8 @@ var __decorateClass = (decorators, target, key, kind) => {
38
38
  // index.ts
39
39
  var index_exports = {};
40
40
  __export(index_exports, {
41
+ BindingColumn: () => BindingColumn,
42
+ BindingValue: () => BindingValue,
41
43
  BlankCursorPaginationReturnMessageDto: () => BlankCursorPaginationReturnMessageDto,
42
44
  BoolColumn: () => BoolColumn,
43
45
  CrudBase: () => CrudBase,
@@ -45,6 +47,7 @@ __export(index_exports, {
45
47
  CursorPaginationDto: () => CursorPaginationDto,
46
48
  CursorPaginationReturnMessageDto: () => CursorPaginationReturnMessageDto,
47
49
  DateColumn: () => DateColumn,
50
+ DefaultBindingKey: () => DefaultBindingKey,
48
51
  EnumColumn: () => EnumColumn,
49
52
  FloatColumn: () => FloatColumn,
50
53
  GenericCursorPaginationReturnMessageDto: () => GenericCursorPaginationReturnMessageDto,
@@ -870,6 +873,18 @@ var QueryOr = (...decs) => {
870
873
  });
871
874
  };
872
875
 
876
+ // src/decorators/binding.ts
877
+ var DefaultBindingKey = "default";
878
+ var BindingColumn = (bindingKey = DefaultBindingKey) => Metadata.set("bindingColumn", bindingKey, "bindingColumnFields");
879
+ var BindingValue = (bindingKey = DefaultBindingKey) => (obj, key, des) => {
880
+ const isMethod = !!des && typeof des.value === "function";
881
+ Metadata.set(
882
+ "bindingValue",
883
+ { bindingKey, isMethod },
884
+ "bindingValueFields"
885
+ )(obj, key);
886
+ };
887
+
873
888
  // src/dto/cursor-pagination.ts
874
889
  var CursorPaginationDto = class {
875
890
  };
@@ -1458,6 +1473,30 @@ async function getPaginatedResult(qb, entityClass, entityAliasName, take, cursor
1458
1473
 
1459
1474
  // src/crud-base.ts
1460
1475
  var import_p_queue = __toESM(require("p-queue"));
1476
+
1477
+ // src/utility/observe-diff.ts
1478
+ var observeDiff = (obj, cb) => {
1479
+ return new Proxy(obj, {
1480
+ set(target, key, value) {
1481
+ const oldValue = target[key];
1482
+ const type = Object.prototype.hasOwnProperty.call(target, key) ? "update" : "add";
1483
+ target[key] = value;
1484
+ cb({ type, key, oldValue, newValue: value });
1485
+ return true;
1486
+ },
1487
+ deleteProperty(target, key) {
1488
+ if (Object.prototype.hasOwnProperty.call(target, key)) {
1489
+ const oldValue = target[key];
1490
+ delete target[key];
1491
+ cb({ type: "delete", key, oldValue, newValue: void 0 });
1492
+ return true;
1493
+ }
1494
+ return false;
1495
+ }
1496
+ });
1497
+ };
1498
+
1499
+ // src/crud-base.ts
1461
1500
  var Relation = (name, options = {}) => {
1462
1501
  return { name, inner: false, ...options };
1463
1502
  };
@@ -1491,7 +1530,11 @@ var CrudBase = class {
1491
1530
  });
1492
1531
  this.log = new import_common2.ConsoleLogger(`${this.entityClass.name}Service`);
1493
1532
  this._typeormRelations = getTypeormRelations(this.entityClass);
1533
+ // binding things
1534
+ this._tmpBindingMap = /* @__PURE__ */ new Map();
1535
+ this._bindingCache = /* @__PURE__ */ new Map();
1494
1536
  }
1537
+ // cleaning entities
1495
1538
  _cleanEntityNotInResultFields(ent) {
1496
1539
  const visited = /* @__PURE__ */ new Set();
1497
1540
  const runSingleObject = (o, cl) => {
@@ -1535,6 +1578,105 @@ var CrudBase = class {
1535
1578
  return this._cleanEntityNotInResultFields(ents);
1536
1579
  }
1537
1580
  }
1581
+ _lookForBindingValueField(bindingKey) {
1582
+ if (this._bindingCache.has(bindingKey)) {
1583
+ return this._bindingCache.get(bindingKey);
1584
+ }
1585
+ const bindingServiceFields = getSpecificFields(this, "bindingValue");
1586
+ const useField = bindingServiceFields.find((f) => {
1587
+ const meta = reflector.get("bindingValue", this, f);
1588
+ return meta?.bindingKey === bindingKey;
1589
+ });
1590
+ if (useField) {
1591
+ const meta = reflector.get("bindingValue", this, useField);
1592
+ const res = {
1593
+ ...meta,
1594
+ field: useField
1595
+ };
1596
+ this._bindingCache.set(bindingKey, res);
1597
+ return res;
1598
+ }
1599
+ return void 0;
1600
+ }
1601
+ _resolveBindingValue(entityField) {
1602
+ const bindingKey = reflector.get(
1603
+ "bindingColumn",
1604
+ this.entityClass,
1605
+ entityField
1606
+ );
1607
+ if (!bindingKey) {
1608
+ return void 0;
1609
+ }
1610
+ if (this._tmpBindingMap.has(bindingKey)) {
1611
+ return this._tmpBindingMap.get(bindingKey);
1612
+ }
1613
+ const bindingValueField = this._lookForBindingValueField(bindingKey);
1614
+ if (!bindingValueField) {
1615
+ return void 0;
1616
+ }
1617
+ if (bindingValueField.isMethod) {
1618
+ return this[bindingValueField.field]();
1619
+ } else {
1620
+ return this[bindingValueField.field];
1621
+ }
1622
+ }
1623
+ // MUST be called 1st on every CRUD operation
1624
+ async getBindingPartialEntity() {
1625
+ const bindingFields = getSpecificFields(this.entityClass, "bindingColumn");
1626
+ if (!bindingFields.length) {
1627
+ return {};
1628
+ }
1629
+ const values = bindingFields.map((field, i) => {
1630
+ return {
1631
+ field,
1632
+ value: this._resolveBindingValue(field),
1633
+ i
1634
+ };
1635
+ });
1636
+ this._tmpBindingMap.clear();
1637
+ const containingPromiseValues = values.filter(
1638
+ (v) => v.value instanceof Promise
1639
+ );
1640
+ if (containingPromiseValues.length) {
1641
+ await Promise.all(
1642
+ containingPromiseValues.map(async (v) => {
1643
+ v.value = await v.value;
1644
+ })
1645
+ );
1646
+ }
1647
+ const res = {};
1648
+ for (const v of values) {
1649
+ if (v.value != null) {
1650
+ res[v.field] = v.value;
1651
+ }
1652
+ }
1653
+ return res;
1654
+ }
1655
+ useBinding(value, bindngKey = DefaultBindingKey) {
1656
+ this._tmpBindingMap.set(bindngKey, value);
1657
+ return this;
1658
+ }
1659
+ _freezeBindings() {
1660
+ const res = {};
1661
+ for (const [key, value] of this._tmpBindingMap.entries()) {
1662
+ res[key] = value;
1663
+ }
1664
+ this._tmpBindingMap.clear();
1665
+ return res;
1666
+ }
1667
+ _restoreBindings(frozen) {
1668
+ this._tmpBindingMap.clear();
1669
+ for (const key of Object.keys(frozen)) {
1670
+ this._tmpBindingMap.set(key, frozen[key]);
1671
+ }
1672
+ return this;
1673
+ }
1674
+ async beforeSuper(fn) {
1675
+ const snap = this._freezeBindings();
1676
+ const res = await fn();
1677
+ this._restoreBindings(snap);
1678
+ return res;
1679
+ }
1538
1680
  async _batchCreate(ents, beforeCreate, skipErrors = false) {
1539
1681
  const entsWithId = ents.filter((ent) => ent.id != null);
1540
1682
  return this.repo.manager.transaction(async (mdb) => {
@@ -1640,6 +1782,7 @@ var CrudBase = class {
1640
1782
  });
1641
1783
  }
1642
1784
  async create(_ent, beforeCreate) {
1785
+ const bindingEnt = await this.getBindingPartialEntity();
1643
1786
  if (!_ent) {
1644
1787
  throw new import_nesties8.BlankReturnMessageDto(400, "Invalid entity").toException();
1645
1788
  }
@@ -1674,6 +1817,7 @@ var CrudBase = class {
1674
1817
  }
1675
1818
  }
1676
1819
  }
1820
+ Object.assign(ent, bindingEnt);
1677
1821
  if (beforeCreate) {
1678
1822
  await beforeCreate(repo);
1679
1823
  }
@@ -1739,10 +1883,20 @@ var CrudBase = class {
1739
1883
  queryBuilder() {
1740
1884
  return this.repo.createQueryBuilder(this.entityAliasName);
1741
1885
  }
1886
+ _applyQueryFromBinding(bindingEnt, qb) {
1887
+ for (const [key, value] of Object.entries(bindingEnt)) {
1888
+ const typeormKey = `_binding_${key}`;
1889
+ qb.andWhere(`${this.entityAliasName}.${key} = :${typeormKey}`, {
1890
+ [typeormKey]: value
1891
+ });
1892
+ }
1893
+ }
1742
1894
  async findOne(id, extraQuery = () => {
1743
1895
  }) {
1896
+ const bindingEnt = await this.getBindingPartialEntity();
1744
1897
  const query = this.queryBuilder().where(`${this.entityAliasName}.id = :id`, { id }).take(1);
1745
1898
  this._applyQueryRelations(query);
1899
+ this._applyQueryFromBinding(bindingEnt, query);
1746
1900
  this.extraGetQuery(query);
1747
1901
  extraQuery(query);
1748
1902
  query.take(1);
@@ -1773,6 +1927,7 @@ var CrudBase = class {
1773
1927
  }
1774
1928
  async _preFindAll(ent, extraQuery = () => {
1775
1929
  }) {
1930
+ const bindingEnt = await this.getBindingPartialEntity();
1776
1931
  const query = this.queryBuilder().where("1 = 1");
1777
1932
  const newEnt = new this.entityClass();
1778
1933
  if (ent) {
@@ -1782,6 +1937,7 @@ var CrudBase = class {
1782
1937
  }
1783
1938
  this._applyQueryRelations(query);
1784
1939
  this._applyQueryFilters(query, newEnt);
1940
+ this._applyQueryFromBinding(bindingEnt, query);
1785
1941
  const pageSettings = newEnt instanceof PageSettingsDto ? newEnt : Object.assign(new PageSettingsDto(), newEnt);
1786
1942
  this.extraGetQuery(query);
1787
1943
  extraQuery(query);
@@ -1840,6 +1996,7 @@ var CrudBase = class {
1840
1996
  }
1841
1997
  }
1842
1998
  async update(id, entPart, cond = {}) {
1999
+ const bindingEnt = await this.getBindingPartialEntity();
1843
2000
  let result;
1844
2001
  const ent = new this.entityClass();
1845
2002
  Object.assign(ent, entPart);
@@ -1852,6 +2009,7 @@ var CrudBase = class {
1852
2009
  result = await this.repo.update(
1853
2010
  {
1854
2011
  id,
2012
+ ...bindingEnt,
1855
2013
  ...cond
1856
2014
  },
1857
2015
  ent
@@ -1873,9 +2031,11 @@ var CrudBase = class {
1873
2031
  return new import_nesties8.BlankReturnMessageDto(200, "success");
1874
2032
  }
1875
2033
  async delete(id, cond = {}) {
2034
+ const bindingEnt = await this.getBindingPartialEntity();
1876
2035
  let result;
1877
2036
  const searchCond = {
1878
2037
  id,
2038
+ ...bindingEnt,
1879
2039
  ...cond
1880
2040
  };
1881
2041
  try {
@@ -1893,6 +2053,7 @@ var CrudBase = class {
1893
2053
  return new import_nesties8.BlankReturnMessageDto(200, "success");
1894
2054
  }
1895
2055
  async importEntities(_ents, extraChecking) {
2056
+ const bindingEnt = await this.getBindingPartialEntity();
1896
2057
  const ents = _ents.map((ent) => {
1897
2058
  const newEnt = new this.entityClass();
1898
2059
  Object.assign(
@@ -1920,6 +2081,9 @@ var CrudBase = class {
1920
2081
  const remainingEnts = ents.filter(
1921
2082
  (ent) => !invalidResults.find((result) => result.entry === ent)
1922
2083
  );
2084
+ for (const ent of remainingEnts) {
2085
+ Object.assign(ent, bindingEnt);
2086
+ }
1923
2087
  await Promise.all(remainingEnts.map((ent) => ent.beforeCreate?.()));
1924
2088
  const data = await this._batchCreate(remainingEnts, void 0, true);
1925
2089
  await Promise.all(data.results.map((e) => e.afterCreate?.()));
@@ -1939,9 +2103,72 @@ var CrudBase = class {
1939
2103
  })
1940
2104
  );
1941
2105
  }
1942
- async exists(id) {
1943
- const ent = await this.repo.findOne({ where: { id }, select: ["id"] });
1944
- return !!ent;
2106
+ async exists(id, cond = {}) {
2107
+ const bindingEnt = await this.getBindingPartialEntity();
2108
+ return this.repo.exists({
2109
+ where: { id, ...bindingEnt, ...cond }
2110
+ });
2111
+ }
2112
+ async operation(id, cb, extraOptions = {}) {
2113
+ const bindingEnt = await this.getBindingPartialEntity();
2114
+ const where = {
2115
+ id,
2116
+ ...bindingEnt,
2117
+ ...extraOptions.where || {}
2118
+ };
2119
+ const throw404 = () => {
2120
+ throw new import_nesties8.BlankReturnMessageDto(
2121
+ 404,
2122
+ `${this.entityName} ID ${id} not found.`
2123
+ ).toException();
2124
+ };
2125
+ if (!await this.repo.exists({ where })) {
2126
+ throw404();
2127
+ }
2128
+ const res = await this.repo.manager.transaction(async (tdb) => {
2129
+ const repo = tdb.getRepository(this.entityClass);
2130
+ const ent = await repo.findOne({
2131
+ lock: { mode: "pessimistic_write" },
2132
+ ...extraOptions,
2133
+ where
2134
+ });
2135
+ if (!ent) {
2136
+ throw404();
2137
+ }
2138
+ const initial = { ...ent };
2139
+ let changes = {};
2140
+ const entProxy = observeDiff(ent, (change) => {
2141
+ if (change.type === "delete") {
2142
+ if (initial[change.key] === null) {
2143
+ delete changes[change.key];
2144
+ } else {
2145
+ changes[change.key] = null;
2146
+ }
2147
+ } else {
2148
+ if (change.newValue !== initial[change.key]) {
2149
+ changes[change.key] = change.newValue;
2150
+ } else {
2151
+ delete changes[change.key];
2152
+ }
2153
+ }
2154
+ });
2155
+ const flush = async () => {
2156
+ if (Object.keys(changes).length) {
2157
+ const currentChanges = { ...changes };
2158
+ Object.assign(initial, changes);
2159
+ changes = {};
2160
+ await repo.update({ id }, currentChanges);
2161
+ }
2162
+ };
2163
+ const result = await cb(entProxy, { repo, flush });
2164
+ await flush();
2165
+ return result;
2166
+ });
2167
+ if (res == null) {
2168
+ return new import_nesties8.BlankReturnMessageDto(200, "success");
2169
+ } else {
2170
+ return new import_nesties8.GenericReturnMessageDto(200, "success", res);
2171
+ }
1945
2172
  }
1946
2173
  async _loadFullTextIndex() {
1947
2174
  const fields = reflector.getArray(
@@ -2163,7 +2390,132 @@ var _RestfulFactory = class _RestfulFactory {
2163
2390
  filterRelations(entityClass, options.relations);
2164
2391
  }
2165
2392
  }
2166
- getEntityClassName() {
2393
+ omitInput(...fields) {
2394
+ return new _RestfulFactory(
2395
+ this.entityClass,
2396
+ {
2397
+ ...this.options,
2398
+ fieldsToOmit: import_lodash5.default.uniq([...this.options.fieldsToOmit || [], ...fields])
2399
+ },
2400
+ this.__resolveVisited
2401
+ );
2402
+ }
2403
+ omitWrite(...fields) {
2404
+ return new _RestfulFactory(
2405
+ this.entityClass,
2406
+ {
2407
+ ...this.options,
2408
+ writeFieldsToOmit: import_lodash5.default.uniq([
2409
+ ...this.options.writeFieldsToOmit || [],
2410
+ ...fields
2411
+ ])
2412
+ },
2413
+ this.__resolveVisited
2414
+ );
2415
+ }
2416
+ omitCreate(...fields) {
2417
+ return new _RestfulFactory(
2418
+ this.entityClass,
2419
+ {
2420
+ ...this.options,
2421
+ createFieldsToOmit: import_lodash5.default.uniq([
2422
+ ...this.options.createFieldsToOmit || [],
2423
+ ...fields
2424
+ ])
2425
+ },
2426
+ this.__resolveVisited
2427
+ );
2428
+ }
2429
+ omitUpdate(...fields) {
2430
+ return new _RestfulFactory(
2431
+ this.entityClass,
2432
+ {
2433
+ ...this.options,
2434
+ updateFieldsToOmit: import_lodash5.default.uniq([
2435
+ ...this.options.updateFieldsToOmit || [],
2436
+ ...fields
2437
+ ])
2438
+ },
2439
+ this.__resolveVisited
2440
+ );
2441
+ }
2442
+ omitFindAll(...fields) {
2443
+ return new _RestfulFactory(
2444
+ this.entityClass,
2445
+ {
2446
+ ...this.options,
2447
+ findAllFieldsToOmit: import_lodash5.default.uniq([
2448
+ ...this.options.findAllFieldsToOmit || [],
2449
+ ...fields
2450
+ ])
2451
+ },
2452
+ this.__resolveVisited
2453
+ );
2454
+ }
2455
+ omitOutput(...fields) {
2456
+ return new _RestfulFactory(
2457
+ this.entityClass,
2458
+ {
2459
+ ...this.options,
2460
+ outputFieldsToOmit: import_lodash5.default.uniq([
2461
+ ...this.options.outputFieldsToOmit || [],
2462
+ ...fields
2463
+ ])
2464
+ },
2465
+ this.__resolveVisited
2466
+ );
2467
+ }
2468
+ pathPrefix(prefix) {
2469
+ return new _RestfulFactory(
2470
+ this.entityClass,
2471
+ {
2472
+ ...this.options,
2473
+ prefix
2474
+ },
2475
+ this.__resolveVisited
2476
+ );
2477
+ }
2478
+ keepEntityVersioningDates(enable = true) {
2479
+ return new _RestfulFactory(
2480
+ this.entityClass,
2481
+ {
2482
+ ...this.options,
2483
+ keepEntityVersioningDates: enable
2484
+ },
2485
+ this.__resolveVisited
2486
+ );
2487
+ }
2488
+ skipNonQueryableFields(enable = true) {
2489
+ return new _RestfulFactory(
2490
+ this.entityClass,
2491
+ {
2492
+ ...this.options,
2493
+ skipNonQueryableFields: enable
2494
+ },
2495
+ this.__resolveVisited
2496
+ );
2497
+ }
2498
+ renameEntityClass(name) {
2499
+ return new _RestfulFactory(
2500
+ this.entityClass,
2501
+ {
2502
+ ...this.options,
2503
+ entityClassName: name
2504
+ },
2505
+ this.__resolveVisited
2506
+ );
2507
+ }
2508
+ useRelations(...relations) {
2509
+ return new _RestfulFactory(
2510
+ this.entityClass,
2511
+ {
2512
+ ...this.options,
2513
+ relations: [...this.options.relations || [], ...relations]
2514
+ },
2515
+ this.__resolveVisited
2516
+ );
2517
+ }
2518
+ get entityClassName() {
2167
2519
  return this.options.entityClassName || this.entityClass.name;
2168
2520
  }
2169
2521
  get fieldsToOmit() {
@@ -2187,7 +2539,7 @@ var _RestfulFactory = class _RestfulFactory {
2187
2539
  get createDto() {
2188
2540
  return (0, import_nesties11.RenameClass)(
2189
2541
  OmitTypeExclude(this.entityClass, this.fieldsInCreateToOmit),
2190
- `Create${this.entityClass.name}Dto`
2542
+ `Create${this.entityClassName}Dto`
2191
2543
  );
2192
2544
  }
2193
2545
  get fieldsInUpdateToOmit() {
@@ -2202,7 +2554,7 @@ var _RestfulFactory = class _RestfulFactory {
2202
2554
  get updateDto() {
2203
2555
  return (0, import_nesties11.RenameClass)(
2204
2556
  (0, import_swagger6.PartialType)(OmitTypeExclude(this.entityClass, this.fieldsInUpdateToOmit)),
2205
- `Update${this.entityClass.name}Dto`
2557
+ `Update${this.entityClassName}Dto`
2206
2558
  );
2207
2559
  }
2208
2560
  get importDto() {
@@ -2246,7 +2598,7 @@ var _RestfulFactory = class _RestfulFactory {
2246
2598
  if (this.options.skipNonQueryableFields) {
2247
2599
  cl = PickTypeExpose(cl, this.queryableFields);
2248
2600
  }
2249
- return (0, import_nesties11.RenameClass)(cl, `Find${this.entityClass.name}Dto`);
2601
+ return (0, import_nesties11.RenameClass)(cl, `Find${this.entityClassName}Dto`);
2250
2602
  }
2251
2603
  get findAllCursorPaginatedDto() {
2252
2604
  return (0, import_nesties11.RenameClass)(
@@ -2254,7 +2606,7 @@ var _RestfulFactory = class _RestfulFactory {
2254
2606
  OmitTypeExclude(this.findAllDto, ["pageCount"]),
2255
2607
  CursorPaginationDto
2256
2608
  ),
2257
- `Find${this.entityClass.name}CursorPaginatedDto`
2609
+ `Find${this.entityClassName}CursorPaginatedDto`
2258
2610
  );
2259
2611
  }
2260
2612
  get entityResultDto() {
@@ -2297,7 +2649,7 @@ var _RestfulFactory = class _RestfulFactory {
2297
2649
  const relationFactory = new _RestfulFactory(
2298
2650
  relation.propertyClass,
2299
2651
  {
2300
- entityClassName: `${this.getEntityClassName()}${this.options.relations ? (0, import_lodash5.upperFirst)(relation.propertyName) : relation.propertyClass.name}`,
2652
+ entityClassName: `${this.entityClassName}${this.options.relations ? (0, import_lodash5.upperFirst)(relation.propertyName) : relation.propertyClass.name}`,
2301
2653
  relations: this.options.relations && getNextLevelRelations(
2302
2654
  this.options.relations.map(extractRelationName),
2303
2655
  relation.propertyName
@@ -2328,7 +2680,7 @@ var _RestfulFactory = class _RestfulFactory {
2328
2680
  }
2329
2681
  const res = (0, import_nesties11.RenameClass)(
2330
2682
  resultDto,
2331
- `${this.getEntityClassName()}ResultDto`
2683
+ `${this.entityClassName}ResultDto`
2332
2684
  );
2333
2685
  const currentContainer = this.__resolveVisited.get(this.entityClass);
2334
2686
  if (currentContainer) {
@@ -2348,7 +2700,7 @@ var _RestfulFactory = class _RestfulFactory {
2348
2700
  (m) => !m.keepInCreate
2349
2701
  )
2350
2702
  ]),
2351
- `${this.getEntityClassName()}CreateResultDto`
2703
+ `${this.entityClassName}CreateResultDto`
2352
2704
  );
2353
2705
  }
2354
2706
  get entityReturnMessageDto() {
@@ -2390,15 +2742,12 @@ var _RestfulFactory = class _RestfulFactory {
2390
2742
  this.usePrefix(import_common3.Post),
2391
2743
  (0, import_common3.HttpCode)(200),
2392
2744
  (0, import_swagger6.ApiOperation)({
2393
- summary: `Create a new ${this.getEntityClassName()}`,
2745
+ summary: `Create a new ${this.entityClassName}`,
2394
2746
  ...extras
2395
2747
  }),
2396
2748
  (0, import_swagger6.ApiBody)({ type: this.createDto }),
2397
2749
  (0, import_swagger6.ApiOkResponse)({ type: this.entityCreateReturnMessageDto }),
2398
- (0, import_swagger6.ApiBadRequestResponse)({
2399
- type: import_nesties10.BlankReturnMessageDto,
2400
- description: `The ${this.getEntityClassName()} is not valid`
2401
- })
2750
+ (0, import_nesties10.ApiError)(400, `The ${this.entityClassName} is not valid`)
2402
2751
  ]);
2403
2752
  }
2404
2753
  createParam() {
@@ -2408,15 +2757,15 @@ var _RestfulFactory = class _RestfulFactory {
2408
2757
  return (0, import_nesties10.MergeMethodDecorators)([
2409
2758
  this.usePrefix(import_common3.Get, ":id"),
2410
2759
  (0, import_swagger6.ApiOperation)({
2411
- summary: `Find a ${this.getEntityClassName()} by id`,
2760
+ summary: `Find a ${this.entityClassName} by id`,
2412
2761
  ...extras
2413
2762
  }),
2414
2763
  (0, import_swagger6.ApiParam)({ name: "id", type: this.idType, required: true }),
2415
2764
  (0, import_swagger6.ApiOkResponse)({ type: this.entityReturnMessageDto }),
2416
- (0, import_swagger6.ApiNotFoundResponse)({
2417
- type: import_nesties10.BlankReturnMessageDto,
2418
- description: `The ${this.getEntityClassName()} with the given id was not found`
2419
- })
2765
+ (0, import_nesties10.ApiError)(
2766
+ 400,
2767
+ `The ${this.entityClassName} with the given id was not found`
2768
+ )
2420
2769
  ]);
2421
2770
  }
2422
2771
  idParam() {
@@ -2430,7 +2779,7 @@ var _RestfulFactory = class _RestfulFactory {
2430
2779
  return (0, import_nesties10.MergeMethodDecorators)([
2431
2780
  this.usePrefix(import_common3.Get),
2432
2781
  (0, import_swagger6.ApiOperation)({
2433
- summary: `Find all ${this.getEntityClassName()}`,
2782
+ summary: `Find all ${this.entityClassName}`,
2434
2783
  ...extras
2435
2784
  }),
2436
2785
  (0, import_swagger6.ApiOkResponse)({ type: this.entityArrayReturnMessageDto })
@@ -2440,7 +2789,7 @@ var _RestfulFactory = class _RestfulFactory {
2440
2789
  return (0, import_nesties10.MergeMethodDecorators)([
2441
2790
  this.usePrefix(import_common3.Get),
2442
2791
  (0, import_swagger6.ApiOperation)({
2443
- summary: `Find all ${this.getEntityClassName()}`,
2792
+ summary: `Find all ${this.entityClassName}`,
2444
2793
  ...extras
2445
2794
  }),
2446
2795
  (0, import_swagger6.ApiOkResponse)({ type: this.entityCursorPaginationReturnMessageDto })
@@ -2467,24 +2816,18 @@ var _RestfulFactory = class _RestfulFactory {
2467
2816
  this.usePrefix(import_common3.Patch, ":id"),
2468
2817
  (0, import_common3.HttpCode)(200),
2469
2818
  (0, import_swagger6.ApiOperation)({
2470
- summary: `Update a ${this.getEntityClassName()} by id`,
2819
+ summary: `Update a ${this.entityClassName} by id`,
2471
2820
  ...extras
2472
2821
  }),
2473
2822
  (0, import_swagger6.ApiParam)({ name: "id", type: this.idType, required: true }),
2474
2823
  (0, import_swagger6.ApiBody)({ type: this.updateDto }),
2475
- (0, import_swagger6.ApiOkResponse)({ type: import_nesties10.BlankReturnMessageDto }),
2476
- (0, import_swagger6.ApiNotFoundResponse)({
2477
- type: import_nesties10.BlankReturnMessageDto,
2478
- description: `The ${this.getEntityClassName()} with the given id was not found`
2479
- }),
2480
- (0, import_swagger6.ApiBadRequestResponse)({
2481
- type: import_nesties10.BlankReturnMessageDto,
2482
- description: `The ${this.getEntityClassName()} is not valid`
2483
- }),
2484
- (0, import_swagger6.ApiInternalServerErrorResponse)({
2485
- type: import_nesties10.BlankReturnMessageDto,
2486
- description: "Internal error"
2487
- })
2824
+ (0, import_nesties10.ApiBlankResponse)(),
2825
+ (0, import_nesties10.ApiError)(
2826
+ 404,
2827
+ `The ${this.entityClassName} with the given id was not found`
2828
+ ),
2829
+ (0, import_nesties10.ApiError)(400, `The ${this.entityClassName} is not valid`),
2830
+ (0, import_nesties10.ApiError)(500, "Internal error")
2488
2831
  ]);
2489
2832
  }
2490
2833
  updateParam() {
@@ -2495,35 +2838,44 @@ var _RestfulFactory = class _RestfulFactory {
2495
2838
  this.usePrefix(import_common3.Delete, ":id"),
2496
2839
  (0, import_common3.HttpCode)(200),
2497
2840
  (0, import_swagger6.ApiOperation)({
2498
- summary: `Delete a ${this.getEntityClassName()} by id`,
2841
+ summary: `Delete a ${this.entityClassName} by id`,
2499
2842
  ...extras
2500
2843
  }),
2501
2844
  (0, import_swagger6.ApiParam)({ name: "id", type: this.idType, required: true }),
2502
- (0, import_swagger6.ApiOkResponse)({ type: import_nesties10.BlankReturnMessageDto }),
2503
- (0, import_swagger6.ApiNotFoundResponse)({
2504
- type: import_nesties10.BlankReturnMessageDto,
2505
- description: `The ${this.getEntityClassName()} with the given id was not found`
2506
- }),
2507
- (0, import_swagger6.ApiInternalServerErrorResponse)({
2508
- type: import_nesties10.BlankReturnMessageDto,
2509
- description: "Internal error"
2510
- })
2845
+ (0, import_nesties10.ApiBlankResponse)(),
2846
+ (0, import_nesties10.ApiError)(
2847
+ 404,
2848
+ `The ${this.entityClassName} with the given id was not found`
2849
+ ),
2850
+ (0, import_nesties10.ApiError)(500, "Internal error")
2511
2851
  ]);
2512
2852
  }
2513
2853
  import(extras = {}) {
2514
2854
  return (0, import_nesties10.MergeMethodDecorators)([
2515
- (0, import_common3.Post)("import"),
2855
+ this.usePrefix(import_common3.Post, "import"),
2516
2856
  (0, import_common3.HttpCode)(200),
2517
2857
  (0, import_swagger6.ApiOperation)({
2518
- summary: `Import ${this.getEntityClassName()}`,
2858
+ summary: `Import ${this.entityClassName}`,
2519
2859
  ...extras
2520
2860
  }),
2521
2861
  (0, import_swagger6.ApiBody)({ type: this.importDto }),
2522
2862
  (0, import_swagger6.ApiOkResponse)({ type: this.importReturnMessageDto }),
2523
- (0, import_swagger6.ApiInternalServerErrorResponse)({
2524
- type: import_nesties10.BlankReturnMessageDto,
2525
- description: "Internal error"
2526
- })
2863
+ (0, import_nesties10.ApiError)(500, "Internal error")
2864
+ ]);
2865
+ }
2866
+ operation(operationName, options = {}) {
2867
+ return (0, import_nesties10.MergeMethodDecorators)([
2868
+ this.usePrefix(import_common3.Post, `:id/${operationName}`),
2869
+ (0, import_common3.HttpCode)(200),
2870
+ (0, import_swagger6.ApiOperation)({
2871
+ summary: `${(0, import_lodash5.upperFirst)(operationName)} a ${this.entityClassName} by id`,
2872
+ ...options.operationExtras || {}
2873
+ }),
2874
+ options.returnType ? (0, import_nesties10.ApiTypeResponse)(options.returnType) : (0, import_nesties10.ApiBlankResponse)(),
2875
+ (0, import_nesties10.ApiError)(
2876
+ 404,
2877
+ `The ${this.entityClassName} with the given id was not found`
2878
+ )
2527
2879
  ]);
2528
2880
  }
2529
2881
  baseController(routeOptions = {}) {
@@ -2637,7 +2989,7 @@ var _RestfulFactory = class _RestfulFactory {
2637
2989
  Object.defineProperty(cl.prototype, method, descriptor);
2638
2990
  });
2639
2991
  }
2640
- return (0, import_nesties11.RenameClass)(cl, `${this.getEntityClassName()}Controller`);
2992
+ return (0, import_nesties11.RenameClass)(cl, `${this.entityClassName}Controller`);
2641
2993
  }
2642
2994
  crudService(options = {}) {
2643
2995
  return CrudService(this.entityClass, {
@@ -2769,6 +3121,8 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
2769
3121
  );
2770
3122
  // Annotate the CommonJS export names for ESM import in node:
2771
3123
  0 && (module.exports = {
3124
+ BindingColumn,
3125
+ BindingValue,
2772
3126
  BlankCursorPaginationReturnMessageDto,
2773
3127
  BoolColumn,
2774
3128
  CrudBase,
@@ -2776,6 +3130,7 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
2776
3130
  CursorPaginationDto,
2777
3131
  CursorPaginationReturnMessageDto,
2778
3132
  DateColumn,
3133
+ DefaultBindingKey,
2779
3134
  EnumColumn,
2780
3135
  FloatColumn,
2781
3136
  GenericCursorPaginationReturnMessageDto,