vona-module-a-orm 5.0.51 → 5.0.53

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.
@@ -168,6 +168,29 @@ declare module 'vona-module-a-event' {
168
168
  }
169
169
  }
170
170
  /** event: end */
171
+ /** queue: begin */
172
+ export * from '../bean/queue.doubleDelete.ts';
173
+ import { type IDecoratorQueueOptions } from 'vona-module-a-queue';
174
+ declare module 'vona-module-a-queue' {
175
+ interface IQueueRecord {
176
+ 'a-orm:doubleDelete': IDecoratorQueueOptions;
177
+ }
178
+ }
179
+ declare module 'vona-module-a-orm' {
180
+ interface QueueDoubleDelete {
181
+ }
182
+ interface QueueDoubleDelete {
183
+ get $beanFullName(): 'a-orm.queue.doubleDelete';
184
+ get $onionName(): 'a-orm:doubleDelete';
185
+ }
186
+ }
187
+ /** queue: end */
188
+ /** queue: begin */
189
+ import type { QueueDoubleDelete } from '../bean/queue.doubleDelete.ts';
190
+ export interface IModuleQueue {
191
+ 'doubleDelete': QueueDoubleDelete;
192
+ }
193
+ /** queue: end */
171
194
  /** schedule: begin */
172
195
  export * from '../bean/schedule.softDeletionPrune.ts';
173
196
  import { type IDecoratorScheduleOptions } from 'vona-module-a-schedule';
@@ -226,6 +249,7 @@ export interface ScopeModuleAOrm {
226
249
  service: IModuleService;
227
250
  broadcast: IModuleBroadcast;
228
251
  event: IModuleEvent;
252
+ queue: IModuleQueue;
229
253
  }
230
254
  import 'vona';
231
255
  declare module 'vona' {
@@ -10,7 +10,7 @@ export declare class BeanDatabaseDialectBase extends BeanBase {
10
10
  createDatabase(_schemaBuilder: Knex.SchemaBuilder, _databaseName: string): Promise<void>;
11
11
  dropDatabase(_schemaBuilder: Knex.SchemaBuilder, _databaseName: string): Promise<void>;
12
12
  fetchIndexes(_schemaBuilder: Knex.SchemaBuilder, _tableName: string): Promise<IFetchIndexesResultItem[]>;
13
- insert(_builder: Knex.QueryBuilder): Promise<TableIdentity[]>;
13
+ insert(_builder: Knex.QueryBuilder, _datas: any[]): Promise<TableIdentity[]>;
14
14
  query(_result: any): void;
15
15
  viewDependents(_builder: Knex.QueryBuilder, _viewName: string): Promise<string[]>;
16
16
  coerceColumn(column: Knex.ColumnInfo): ITableColumn;
@@ -44,8 +44,12 @@ export declare class BeanModelCache<TRecord extends {} = {}> extends BeanModelCr
44
44
  private __filterMGetColumns;
45
45
  private __filterGetColumns;
46
46
  cacheEntityDel(id: TableIdentity | TableIdentity[], table?: keyof ITableRecord): Promise<void>;
47
+ cacheEntityDelInner(id: TableIdentity | TableIdentity[], table?: keyof ITableRecord): Promise<void>;
47
48
  cacheEntityClear(table?: keyof ITableRecord): Promise<void>;
49
+ cacheEntityClearInner(table?: keyof ITableRecord): Promise<void>;
48
50
  cacheQueryClear(table?: keyof ITableRecord): Promise<void>;
51
+ cacheQueryClearInner(table?: keyof ITableRecord): Promise<void>;
52
+ private _shardingCacheDoubleDelete;
49
53
  private _cacheQueryClearModelsClear;
50
54
  private _getModelsClear;
51
55
  private _getModelsClearAll;
@@ -0,0 +1,15 @@
1
+ import type { IQueueExecute, IQueuePushOptions } from 'vona-module-a-queue';
2
+ import type { IDatabaseClientRecord } from '../types/database.ts';
3
+ import type { ITableRecord } from '../types/onion/table.ts';
4
+ import { BeanQueueBase } from 'vona-module-a-queue';
5
+ export interface TypeQueueDoubleDeleteJobData {
6
+ beanFullName: string;
7
+ clientName: keyof IDatabaseClientRecord;
8
+ table: keyof ITableRecord;
9
+ method: 'cacheEntityDelInner' | 'cacheEntityClearInner' | 'cacheQueryClearInner';
10
+ args: any[];
11
+ }
12
+ export type TypeQueueDoubleDeleteJobResult = void;
13
+ export declare class QueueDoubleDelete extends BeanQueueBase<TypeQueueDoubleDeleteJobData, TypeQueueDoubleDeleteJobResult> implements IQueueExecute<TypeQueueDoubleDeleteJobData, TypeQueueDoubleDeleteJobResult> {
14
+ execute(data: TypeQueueDoubleDeleteJobData, _options?: IQueuePushOptions): Promise<TypeQueueDoubleDeleteJobResult>;
15
+ }
@@ -5,12 +5,20 @@ import type { TSummerCachePreset } from 'vona-module-a-summer';
5
5
  import type { IDatabaseClientDialectRecord } from '../types/database.ts';
6
6
  export type TypeDataBaseConfigDialects = Record<keyof IDatabaseClientDialectRecord, TypeBeanRecordGeneralSelectorKeys<'databaseDialect'>>;
7
7
  export declare function config(_app: VonaApplication): {
8
+ sharding: {
9
+ cache: {
10
+ doubleDelete: boolean;
11
+ };
12
+ };
8
13
  rest: {
9
14
  query: {
10
15
  pageSize: {
11
16
  default: number;
12
17
  max: number;
13
18
  };
19
+ orders: {
20
+ default: string;
21
+ };
14
22
  };
15
23
  };
16
24
  table: {
package/dist/index.js CHANGED
@@ -1,37 +1,37 @@
1
1
  import BigNumber$1, { BigNumber } from 'bignumber.js';
2
- import { BeanInfo, BeanAopMethodBase, BeanBase, deepExtend, Virtual, appResource, beanFullNameFromOnionName, cast, appMetadata, useApp, BeanSimple, combineConfigDefault, BeanScopeBase, createBeanDecorator, PickClassInner, $Class } from 'vona';
2
+ import { BeanInfo, BeanAopMethodBase, BeanBase, deepExtend, Virtual, appResource, beanFullNameFromOnionName, cast, useApp, BeanSimple, combineConfigDefault, BeanScopeBase, createBeanDecorator, PickClassInner, $Class } from 'vona';
3
3
  import { AopMethod, Aspect } from 'vona-module-a-aspect';
4
4
  import { Service, Bean, Scope } from 'vona-module-a-bean';
5
5
  import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
6
6
  import knex from 'knex';
7
7
  import { isNil, safeBoolean, isClass, ensureArray, hashkey } from '@cabloy/utils';
8
8
  import { swapDeps } from '@cabloy/deps';
9
- import { prepareClassType, getTargetDecoratorRules, Api, v, OrderMaxBase, OrderCoreBase, getSchemaDynamic, SymbolSchemaDynamicRefId, addSchemaDynamic, mergeFieldsOpenapiMetadata } from 'vona-module-a-openapi';
10
- import { ZodMetadata } from '@cabloy/zod-query';
11
- import { SymbolDecoratorRuleColumn } from 'vona-module-a-openapiutils';
9
+ import { prepareClassType, getTargetDecoratorRules, getTargetDecoratorRuleColumnsMap, Api, v, OrderMaxBase, OrderCoreBase, getSchemaDynamic, SymbolSchemaDynamicRefId, addSchemaDynamic, mergeFieldsOpenapiMetadata } from 'vona-module-a-openapi';
10
+ import { ZodMetadata } from '@cabloy/zod-openapi';
12
11
  import z from 'zod';
13
12
  import { Broadcast, BeanBroadcastBase } from 'vona-module-a-broadcast';
14
13
  import { Event, BeanEventBase } from 'vona-module-a-event';
14
+ import { Queue, BeanQueueBase } from 'vona-module-a-queue';
15
15
  import { Schedule } from 'vona-module-a-schedule';
16
16
  import { configAllWithIgnoreNull, configAll, configRedisWithIgnoreNull, configRedis } from 'vona-module-a-summer';
17
17
  import { ServiceDatabaseAsyncLocalStorage as ServiceDatabaseAsyncLocalStorage$1, ServiceTransactionConsistency‌ as ServiceTransactionConsistency_ } from 'vona-module-a-orm';
18
18
  import { mutate } from 'mutate-on-copy';
19
19
 
20
- var _dec$w, _dec2$w, _class$w;
21
- let AopMethodTransaction = (_dec$w = AopMethod(), _dec2$w = BeanInfo({
20
+ var _dec$x, _dec2$x, _class$x;
21
+ let AopMethodTransaction = (_dec$x = AopMethod(), _dec2$x = BeanInfo({
22
22
  module: "a-orm"
23
- }), _dec$w(_class$w = _dec2$w(_class$w = class AopMethodTransaction extends BeanAopMethodBase {
23
+ }), _dec$x(_class$x = _dec2$x(_class$x = class AopMethodTransaction extends BeanAopMethodBase {
24
24
  execute(options, _args, next, _receiver, _prop) {
25
25
  return this.bean.database.current.transaction.begin(() => {
26
26
  return next();
27
27
  }, options);
28
28
  }
29
- }) || _class$w) || _class$w);
29
+ }) || _class$x) || _class$x);
30
30
 
31
- var _dec$v, _dec2$v, _class$v;
32
- let ServiceDatabaseAsyncLocalStorage = (_dec$v = Service(), _dec2$v = BeanInfo({
31
+ var _dec$w, _dec2$w, _class$w;
32
+ let ServiceDatabaseAsyncLocalStorage = (_dec$w = Service(), _dec2$w = BeanInfo({
33
33
  module: "a-orm"
34
- }), _dec$v(_class$v = _dec2$v(_class$v = class ServiceDatabaseAsyncLocalStorage extends BeanBase {
34
+ }), _dec$w(_class$w = _dec2$w(_class$w = class ServiceDatabaseAsyncLocalStorage extends BeanBase {
35
35
  constructor(...args) {
36
36
  super(...args);
37
37
  this.dbStorage = void 0;
@@ -50,14 +50,14 @@ let ServiceDatabaseAsyncLocalStorage = (_dec$v = Service(), _dec2$v = BeanInfo({
50
50
  return fn();
51
51
  });
52
52
  }
53
- }) || _class$v) || _class$v);
53
+ }) || _class$w) || _class$w);
54
54
 
55
- var _dec$u, _dec2$u, _class$u;
55
+ var _dec$v, _dec2$v, _class$v;
56
56
  const SymbolColumnsCache = Symbol('SymbolColumnsCache');
57
57
  const SymbolColumnsDefaultCache = Symbol('SymbolColumnsDefaultCache');
58
- let ServiceColumnsCache = (_dec$u = Service(), _dec2$u = BeanInfo({
58
+ let ServiceColumnsCache = (_dec$v = Service(), _dec2$v = BeanInfo({
59
59
  module: "a-orm"
60
- }), _dec$u(_class$u = _dec2$u(_class$u = class ServiceColumnsCache extends BeanBase {
60
+ }), _dec$v(_class$v = _dec2$v(_class$v = class ServiceColumnsCache extends BeanBase {
61
61
  constructor(...args) {
62
62
  super(...args);
63
63
  this.clientName = void 0;
@@ -112,12 +112,12 @@ let ServiceColumnsCache = (_dec$u = Service(), _dec2$u = BeanInfo({
112
112
  return exists;
113
113
  }
114
114
  }
115
- }) || _class$u) || _class$u);
115
+ }) || _class$v) || _class$v);
116
116
 
117
- var _dec$t, _dec2$t, _class$t;
118
- let ServiceColumns = (_dec$t = Service(), _dec2$t = BeanInfo({
117
+ var _dec$u, _dec2$u, _class$u;
118
+ let ServiceColumns = (_dec$u = Service(), _dec2$u = BeanInfo({
119
119
  module: "a-orm"
120
- }), _dec$t(_class$t = _dec2$t(_class$t = class ServiceColumns extends BeanBase {
120
+ }), _dec$u(_class$u = _dec2$u(_class$u = class ServiceColumns extends BeanBase {
121
121
  constructor(...args) {
122
122
  super(...args);
123
123
  this._db = void 0;
@@ -168,7 +168,7 @@ let ServiceColumns = (_dec$t = Service(), _dec2$t = BeanInfo({
168
168
  columnsClear(tableName) {
169
169
  return this.scope.service.database.columnsClear(this.db.clientName, tableName);
170
170
  }
171
- }) || _class$t) || _class$t);
171
+ }) || _class$u) || _class$u);
172
172
 
173
173
  const TransactionIsolationLevelsMap = {
174
174
  DEFAULT: undefined,
@@ -181,10 +181,10 @@ const TransactionIsolationLevelsMap = {
181
181
 
182
182
  // export type TransactionPropagation=''
183
183
 
184
- var _dec$s, _dec2$s, _class$s;
185
- let ServiceDatabase = (_dec$s = Service(), _dec2$s = BeanInfo({
184
+ var _dec$t, _dec2$t, _class$t;
185
+ let ServiceDatabase = (_dec$t = Service(), _dec2$t = BeanInfo({
186
186
  module: "a-orm"
187
- }), _dec$s(_class$s = _dec2$s(_class$s = class ServiceDatabase extends BeanBase {
187
+ }), _dec$t(_class$t = _dec2$t(_class$t = class ServiceDatabase extends BeanBase {
188
188
  getDialect(client) {
189
189
  if (!client) throw new Error('database dialect not specified');
190
190
  const beanFullName = this.scope.config.dialects[client];
@@ -270,12 +270,12 @@ let ServiceDatabase = (_dec$s = Service(), _dec2$s = BeanInfo({
270
270
  });
271
271
  this.__columnsClearRaw(clientName);
272
272
  }
273
- }) || _class$s) || _class$s);
273
+ }) || _class$t) || _class$t);
274
274
 
275
- var _dec$r, _dec2$r, _class$r;
276
- let ServiceTransactionConsistency‌ = (_dec$r = Service(), _dec2$r = BeanInfo({
275
+ var _dec$s, _dec2$s, _class$s;
276
+ let ServiceTransactionConsistency‌ = (_dec$s = Service(), _dec2$s = BeanInfo({
277
277
  module: "a-orm"
278
- }), _dec$r(_class$r = _dec2$r(_class$r = class ServiceTransactionConsistency‌ extends BeanBase {
278
+ }), _dec$s(_class$s = _dec2$s(_class$s = class ServiceTransactionConsistency‌ extends BeanBase {
279
279
  constructor(...args) {
280
280
  super(...args);
281
281
  this._commitCallbacks = [];
@@ -287,7 +287,7 @@ let ServiceTransactionConsistency‌ = (_dec$r = Service(), _dec2$r = BeanInfo({
287
287
  compensate(cb) {
288
288
  this._compensateCallbacks.unshift(AsyncResource.bind(cb));
289
289
  }
290
- async commitDone() {
290
+ async commitsDone() {
291
291
  while (true) {
292
292
  const cb = this._commitCallbacks.shift();
293
293
  if (!cb) break;
@@ -295,7 +295,7 @@ let ServiceTransactionConsistency‌ = (_dec$r = Service(), _dec2$r = BeanInfo({
295
295
  }
296
296
  this._compensateCallbacks = [];
297
297
  }
298
- async compensateDone() {
298
+ async compensatesDone() {
299
299
  while (true) {
300
300
  const cb = this._compensateCallbacks.shift();
301
301
  if (!cb) break;
@@ -303,12 +303,12 @@ let ServiceTransactionConsistency‌ = (_dec$r = Service(), _dec2$r = BeanInfo({
303
303
  }
304
304
  this._commitCallbacks = [];
305
305
  }
306
- }) || _class$r) || _class$r);
306
+ }) || _class$s) || _class$s);
307
307
 
308
- var _dec$q, _dec2$q, _class$q;
309
- let ServiceTransactionFiber = (_dec$q = Service(), _dec2$q = BeanInfo({
308
+ var _dec$r, _dec2$r, _class$r;
309
+ let ServiceTransactionFiber = (_dec$r = Service(), _dec2$r = BeanInfo({
310
310
  module: "a-orm"
311
- }), _dec$q(_class$q = _dec2$q(_class$q = class ServiceTransactionFiber extends BeanBase {
311
+ }), _dec$r(_class$r = _dec2$r(_class$r = class ServiceTransactionFiber extends BeanBase {
312
312
  constructor(...args) {
313
313
  super(...args);
314
314
  this._connection = void 0;
@@ -329,20 +329,20 @@ let ServiceTransactionFiber = (_dec$q = Service(), _dec2$q = BeanInfo({
329
329
  }
330
330
  async doCommit() {
331
331
  await this._connection.commit();
332
- await this._transactionConsistency.commitDone();
332
+ await this._transactionConsistency.commitsDone();
333
333
  this._connection = undefined;
334
334
  }
335
335
  async doRollback() {
336
336
  await this._connection.rollback();
337
- await this._transactionConsistency.compensateDone();
337
+ await this._transactionConsistency.compensatesDone();
338
338
  this._connection = undefined;
339
339
  }
340
- }) || _class$q) || _class$q);
340
+ }) || _class$r) || _class$r);
341
341
 
342
- var _dec$p, _dec2$p, _class$p;
343
- let ServiceTransactionState = (_dec$p = Service(), _dec2$p = BeanInfo({
342
+ var _dec$q, _dec2$q, _class$q;
343
+ let ServiceTransactionState = (_dec$q = Service(), _dec2$q = BeanInfo({
344
344
  module: "a-orm"
345
- }), _dec$p(_class$p = _dec2$p(_class$p = class ServiceTransactionState extends BeanBase {
345
+ }), _dec$q(_class$q = _dec2$q(_class$q = class ServiceTransactionState extends BeanBase {
346
346
  constructor(...args) {
347
347
  super(...args);
348
348
  this._fibers = {};
@@ -364,12 +364,12 @@ let ServiceTransactionState = (_dec$p = Service(), _dec2$p = BeanInfo({
364
364
  const selector = this.serviceDatabase.prepareClientNameSelector(dbInfo);
365
365
  delete this._fibers[selector];
366
366
  }
367
- }) || _class$p) || _class$p);
367
+ }) || _class$q) || _class$q);
368
368
 
369
- var _dec$o, _dec2$o, _class$o;
370
- let ServiceTransactionAsyncLocalStorage = (_dec$o = Service(), _dec2$o = BeanInfo({
369
+ var _dec$p, _dec2$p, _class$p;
370
+ let ServiceTransactionAsyncLocalStorage = (_dec$p = Service(), _dec2$p = BeanInfo({
371
371
  module: "a-orm"
372
- }), _dec$o(_class$o = _dec2$o(_class$o = class ServiceTransactionAsyncLocalStorage extends BeanBase {
372
+ }), _dec$p(_class$p = _dec2$p(_class$p = class ServiceTransactionAsyncLocalStorage extends BeanBase {
373
373
  constructor(...args) {
374
374
  super(...args);
375
375
  this.transactionStorage = void 0;
@@ -390,12 +390,12 @@ let ServiceTransactionAsyncLocalStorage = (_dec$o = Service(), _dec2$o = BeanInf
390
390
  return fn();
391
391
  });
392
392
  }
393
- }) || _class$o) || _class$o);
393
+ }) || _class$p) || _class$p);
394
394
 
395
- var _dec$n, _dec2$n, _class$n;
396
- let ServiceTransaction = (_dec$n = Service(), _dec2$n = BeanInfo({
395
+ var _dec$o, _dec2$o, _class$o;
396
+ let ServiceTransaction = (_dec$o = Service(), _dec2$o = BeanInfo({
397
397
  module: "a-orm"
398
- }), _dec$n(_class$n = _dec2$n(_class$n = class ServiceTransaction extends BeanBase {
398
+ }), _dec$o(_class$o = _dec2$o(_class$o = class ServiceTransaction extends BeanBase {
399
399
  constructor(...args) {
400
400
  super(...args);
401
401
  this._db = void 0;
@@ -516,7 +516,7 @@ let ServiceTransaction = (_dec$n = Service(), _dec2$n = BeanInfo({
516
516
  }
517
517
  return res;
518
518
  }
519
- }) || _class$n) || _class$n);
519
+ }) || _class$o) || _class$o);
520
520
  function _translateTransactionOptions(options) {
521
521
  if (!options) return undefined;
522
522
  return {
@@ -525,10 +525,10 @@ function _translateTransactionOptions(options) {
525
525
  };
526
526
  }
527
527
 
528
- var _dec$m, _dec2$m, _class$m;
529
- let ServiceDb = (_dec$m = Service(), _dec2$m = BeanInfo({
528
+ var _dec$n, _dec2$n, _class$n;
529
+ let ServiceDb = (_dec$n = Service(), _dec2$n = BeanInfo({
530
530
  module: "a-orm"
531
- }), _dec$m(_class$m = _dec2$m(_class$m = class ServiceDb extends BeanBase {
531
+ }), _dec$n(_class$n = _dec2$n(_class$n = class ServiceDb extends BeanBase {
532
532
  constructor(...args) {
533
533
  super(...args);
534
534
  this._client = void 0;
@@ -583,12 +583,12 @@ let ServiceDb = (_dec$m = Service(), _dec2$m = BeanInfo({
583
583
  compensate(cb) {
584
584
  return this.transaction.compensate(cb);
585
585
  }
586
- }) || _class$m) || _class$m);
586
+ }) || _class$n) || _class$n);
587
587
 
588
- var _dec$l, _dec2$l, _class$l;
589
- let ServiceDatabaseClient = (_dec$l = Service(), _dec2$l = BeanInfo({
588
+ var _dec$m, _dec2$m, _class$m;
589
+ let ServiceDatabaseClient = (_dec$m = Service(), _dec2$m = BeanInfo({
590
590
  module: "a-orm"
591
- }), _dec$l(_class$l = _dec2$l(_class$l = class ServiceDatabaseClient extends BeanBase {
591
+ }), _dec$m(_class$m = _dec2$m(_class$m = class ServiceDatabaseClient extends BeanBase {
592
592
  constructor(...args) {
593
593
  super(...args);
594
594
  this.level = void 0;
@@ -694,12 +694,12 @@ let ServiceDatabaseClient = (_dec$l = Service(), _dec2$l = BeanInfo({
694
694
  // reload
695
695
  await this.reload(config);
696
696
  }
697
- }) || _class$l) || _class$l);
697
+ }) || _class$m) || _class$m);
698
698
 
699
- var _dec$k, _dec2$k, _class$k;
700
- let BeanDatabase = (_dec$k = Bean(), _dec2$k = BeanInfo({
699
+ var _dec$l, _dec2$l, _class$l;
700
+ let BeanDatabase = (_dec$l = Bean(), _dec2$l = BeanInfo({
701
701
  module: "a-orm"
702
- }), _dec$k(_class$k = _dec2$k(_class$k = class BeanDatabase extends BeanBase {
702
+ }), _dec$l(_class$l = _dec2$l(_class$l = class BeanDatabase extends BeanBase {
703
703
  get current() {
704
704
  return this.bean._getBean(ServiceDatabaseAsyncLocalStorage).current;
705
705
  }
@@ -729,12 +729,12 @@ let BeanDatabase = (_dec$k = Bean(), _dec2$k = BeanInfo({
729
729
  return this.bean._getBean(ServiceTransactionAsyncLocalStorage).run(fn);
730
730
  });
731
731
  }
732
- }) || _class$k) || _class$k);
732
+ }) || _class$l) || _class$l);
733
733
 
734
- var _dec$j, _dec2$j, _dec3$7, _class$j;
735
- let BeanDatabaseDialectBase = (_dec$j = Bean(), _dec2$j = Virtual(), _dec3$7 = BeanInfo({
734
+ var _dec$k, _dec2$k, _dec3$7, _class$k;
735
+ let BeanDatabaseDialectBase = (_dec$k = Bean(), _dec2$k = Virtual(), _dec3$7 = BeanInfo({
736
736
  module: "a-orm"
737
- }), _dec$j(_class$j = _dec2$j(_class$j = _dec3$7(_class$j = class BeanDatabaseDialectBase extends BeanBase {
737
+ }), _dec$k(_class$k = _dec2$k(_class$k = _dec3$7(_class$k = class BeanDatabaseDialectBase extends BeanBase {
738
738
  getConfigBase() {
739
739
  return undefined;
740
740
  }
@@ -750,7 +750,7 @@ let BeanDatabaseDialectBase = (_dec$j = Bean(), _dec2$j = Virtual(), _dec3$7 = B
750
750
  async fetchIndexes(_schemaBuilder, _tableName) {
751
751
  throw new Error('Not Implemented');
752
752
  }
753
- async insert(_builder) {
753
+ async insert(_builder, _datas) {
754
754
  throw new Error('Not Implemented');
755
755
  }
756
756
  query(_result) {
@@ -794,7 +794,7 @@ let BeanDatabaseDialectBase = (_dec$j = Bean(), _dec2$j = Virtual(), _dec3$7 = B
794
794
  _columnTypePrefixes(type, prefixes) {
795
795
  return prefixes.some(prefix => type.includes(prefix));
796
796
  }
797
- }) || _class$j) || _class$j) || _class$j);
797
+ }) || _class$k) || _class$k) || _class$k);
798
798
 
799
799
  const OpAggrs = ['count', 'sum', 'avg', 'max', 'min'];
800
800
  const OpJoint = {
@@ -807,6 +807,8 @@ const OpJoint = {
807
807
  const OpNormal = {
808
808
  eq: '_eq_',
809
809
  notEq: '_notEq_',
810
+ eqI: '_eqI_',
811
+ notEqI: '_notEqI_',
810
812
  gt: '_gt_',
811
813
  gte: '_gte_',
812
814
  lt: '_lt_',
@@ -1018,10 +1020,23 @@ function _buildWhereColumn(having, knex, builder, column, value, op) {
1018
1020
  }
1019
1021
  function _buildWhereColumnOpNormal(having, knex, builder, column, value, op) {
1020
1022
  column = _checkHavingColumn(knex, column);
1023
+ if (_shouldPatchLike(knex)) {
1024
+ if (op === Op.startsWith) op = Op.startsWithI;
1025
+ if (op === Op.endsWith) op = Op.endsWithI;
1026
+ if (op === Op.includes) op = Op.includesI;
1027
+ if (op === Op.eqI) op = Op.eq;
1028
+ if (op === Op.notEqI) op = Op.notEq;
1029
+ }
1021
1030
  if (op === Op.eq) {
1022
1031
  builder[having ? 'having' : 'where'](column, '=', value);
1023
1032
  } else if (op === Op.notEq) {
1024
1033
  builder[having ? 'having' : 'where'](column, '<>', value);
1034
+ } else if (op === Op.eqI) {
1035
+ builder[having ? 'havingILike' : 'whereILike'](column, value);
1036
+ } else if (op === Op.notEqI) {
1037
+ builder[having ? 'havingNot' : 'whereNot'](builder => {
1038
+ builder[having ? 'havingILike' : 'whereILike'](column, value);
1039
+ });
1025
1040
  } else if (op === Op.gt) {
1026
1041
  builder[having ? 'having' : 'where'](column, '>', value);
1027
1042
  } else if (op === Op.gte) {
@@ -1058,6 +1073,13 @@ function _buildWhereColumnOpNormal(having, knex, builder, column, value, op) {
1058
1073
  builder[having ? 'having' : 'where'](column, '=', knex.ref(value));
1059
1074
  }
1060
1075
  }
1076
+ function _shouldPatchLike(knex) {
1077
+ const dialectName = _getDialectName(knex);
1078
+ return dialectName === 'mysql' || dialectName === 'mysql2';
1079
+ }
1080
+ function _getDialectName(knex) {
1081
+ return knex.client.config.client;
1082
+ }
1061
1083
  function _checkHavingColumn(knex, column) {
1062
1084
  let [aggr, name] = cast(column).split('_');
1063
1085
  if (!OpAggrs.includes(aggr) || !name) return column;
@@ -1092,7 +1114,7 @@ function $columns(key) {
1092
1114
  }
1093
1115
  function $columnsAll(classEntity, withTableName, withMeta) {
1094
1116
  const classEntity2 = _prepareClassEntity(classEntity);
1095
- let columns = appMetadata.getMetadata(SymbolDecoratorRuleColumn, classEntity2.prototype);
1117
+ let columns = getTargetDecoratorRuleColumnsMap(classEntity2.prototype);
1096
1118
  if (withTableName) {
1097
1119
  const tableName = $tableName(classEntity2);
1098
1120
  columns = {
@@ -1131,7 +1153,8 @@ function $tableComments(classEntity) {
1131
1153
  const comments = {};
1132
1154
  for (const key in rules) {
1133
1155
  const rule = rules[key];
1134
- const comment = rule._def.openapi?.metadata?.description || rule._def.openapi?.metadata?.title;
1156
+ const metadata = ZodMetadata.getOpenapiMetadata(rule);
1157
+ const comment = metadata?.description || metadata?.title;
1135
1158
  comments[key] = comment ? app.meta.text(comment) : '';
1136
1159
  }
1137
1160
  // table comment
@@ -1177,66 +1200,69 @@ function _initializerDefineProperty(e, i, r, l) {
1177
1200
  });
1178
1201
  }
1179
1202
 
1180
- var _dec$i, _dec2$i, _dec3$6, _dec4$4, _dec5$1, _dec6$1, _class$i, _descriptor$4, _descriptor2$2, _descriptor3$1;
1181
- let DtoQueryBase = (_dec$i = Api.field(v.optional(), v.array(String, {
1203
+ var _dec$j, _dec2$j, _dec3$6, _dec4$4, _dec5$1, _dec6$1, _dec7$1, _class$j, _descriptor$4, _descriptor2$2, _descriptor3$1;
1204
+ const app$1 = useApp();
1205
+ const ormConfig$1 = app$1.util.getModuleConfigRaw('a-orm');
1206
+ const ordersDefault = ormConfig$1?.rest?.query?.orders?.default ?? 'createdAt,desc';
1207
+ let DtoQueryBase = (_dec$j = Api.field(v.optional(), v.array(String, {
1182
1208
  separator: ','
1183
- })), _dec2$i = Reflect.metadata("design:type", Array), _dec3$6 = Api.field(v.optional(), z.object({}).passthrough()), _dec4$4 = Reflect.metadata("design:type", Object), _dec5$1 = Api.field(v.optional(), z.union([z.string(), z.array(z.array(z.string()))])), _dec6$1 = Reflect.metadata("design:type", Object), _class$i = class DtoQueryBase {
1209
+ })), _dec2$j = Reflect.metadata("design:type", Array), _dec3$6 = Api.field(v.optional(), z.looseObject({})), _dec4$4 = Reflect.metadata("design:type", Object), _dec5$1 = Api.field(v.default(ordersDefault), v.optional(), z.union([z.string(), z.array(z.array(z.string()))])), _dec6$1 = Api.field(v.optional(), z.union([z.string(), z.array(z.array(z.string()))])), _dec7$1 = Reflect.metadata("design:type", Object), _class$j = class DtoQueryBase {
1184
1210
  constructor() {
1185
1211
  _initializerDefineProperty(this, "columns", _descriptor$4, this);
1186
1212
  _initializerDefineProperty(this, "where", _descriptor2$2, this);
1187
1213
  _initializerDefineProperty(this, "orders", _descriptor3$1, this);
1188
1214
  }
1189
- }, _descriptor$4 = _applyDecoratedDescriptor(_class$i.prototype, "columns", [_dec$i, _dec2$i], {
1215
+ }, _descriptor$4 = _applyDecoratedDescriptor(_class$j.prototype, "columns", [_dec$j, _dec2$j], {
1190
1216
  configurable: true,
1191
1217
  enumerable: true,
1192
1218
  writable: true,
1193
1219
  initializer: null
1194
- }), _descriptor2$2 = _applyDecoratedDescriptor(_class$i.prototype, "where", [_dec3$6, _dec4$4], {
1220
+ }), _descriptor2$2 = _applyDecoratedDescriptor(_class$j.prototype, "where", [_dec3$6, _dec4$4], {
1195
1221
  configurable: true,
1196
1222
  enumerable: true,
1197
1223
  writable: true,
1198
1224
  initializer: null
1199
- }), _descriptor3$1 = _applyDecoratedDescriptor(_class$i.prototype, "orders", [_dec5$1, _dec6$1], {
1225
+ }), _descriptor3$1 = _applyDecoratedDescriptor(_class$j.prototype, "orders", [_dec5$1, _dec6$1, _dec7$1], {
1200
1226
  configurable: true,
1201
1227
  enumerable: true,
1202
1228
  writable: true,
1203
1229
  initializer: null
1204
- }), _class$i);
1230
+ }), _class$j);
1205
1231
 
1206
- var _dec$h, _dec2$h, _dec3$5, _dec4$3, _class$h, _descriptor$3, _descriptor2$1;
1232
+ var _dec$i, _dec2$i, _dec3$5, _dec4$3, _class$i, _descriptor$3, _descriptor2$1;
1207
1233
  const app = useApp();
1208
1234
  const ormConfig = app.util.getModuleConfigRaw('a-orm');
1209
1235
  const pageSizeDefault = ormConfig?.rest?.query?.pageSize?.default ?? 20;
1210
1236
  const pageSizeMax = ormConfig?.rest?.query?.pageSize?.max ?? 100;
1211
- let DtoQueryPageBase = (_dec$h = Api.field(z.number().min(1).default(1)), _dec2$h = Reflect.metadata("design:type", Number), _dec3$5 = Api.field(z.number().min(1).max(pageSizeMax).default(pageSizeDefault)), _dec4$3 = Reflect.metadata("design:type", Number), _class$h = class DtoQueryPageBase extends DtoQueryBase {
1237
+ let DtoQueryPageBase = (_dec$i = Api.field(z.number().min(1).default(1)), _dec2$i = Reflect.metadata("design:type", Number), _dec3$5 = Api.field(z.number().min(1).max(pageSizeMax).default(pageSizeDefault)), _dec4$3 = Reflect.metadata("design:type", Number), _class$i = class DtoQueryPageBase extends DtoQueryBase {
1212
1238
  constructor(...args) {
1213
1239
  super(...args);
1214
1240
  _initializerDefineProperty(this, "pageNo", _descriptor$3, this);
1215
1241
  _initializerDefineProperty(this, "pageSize", _descriptor2$1, this);
1216
1242
  }
1217
- }, _descriptor$3 = _applyDecoratedDescriptor(_class$h.prototype, "pageNo", [_dec$h, _dec2$h], {
1243
+ }, _descriptor$3 = _applyDecoratedDescriptor(_class$i.prototype, "pageNo", [_dec$i, _dec2$i], {
1218
1244
  configurable: true,
1219
1245
  enumerable: true,
1220
1246
  writable: true,
1221
1247
  initializer: null
1222
- }), _descriptor2$1 = _applyDecoratedDescriptor(_class$h.prototype, "pageSize", [_dec3$5, _dec4$3], {
1248
+ }), _descriptor2$1 = _applyDecoratedDescriptor(_class$i.prototype, "pageSize", [_dec3$5, _dec4$3], {
1223
1249
  configurable: true,
1224
1250
  enumerable: true,
1225
1251
  writable: true,
1226
1252
  initializer: null
1227
- }), _class$h);
1253
+ }), _class$i);
1228
1254
 
1229
1255
  const SymbolKeyFieldsMore = Symbol('$fieldsMore');
1230
1256
 
1231
1257
  class EntityBaseEmpty {}
1232
1258
 
1233
- var _dec$g, _dec2$g, _dec3$4, _dec4$2, _dec5, _dec6, _dec7, _dec8, _class$g, _descriptor$2, _descriptor2, _descriptor3, _descriptor4;
1234
- let EntityBaseInner = (_dec$g = Api.field(v.openapi({
1259
+ var _dec$h, _dec2$h, _dec3$4, _dec4$2, _dec5, _dec6, _dec7, _dec8, _class$h, _descriptor$2, _descriptor2, _descriptor3, _descriptor4;
1260
+ let EntityBaseInner = (_dec$h = Api.field(v.openapi({
1235
1261
  title: $locale('CreatedAt'),
1236
1262
  rest: {
1237
1263
  order: OrderMaxBase - 2
1238
1264
  }
1239
- })), _dec2$g = Reflect.metadata("design:type", typeof Date === "undefined" ? Object : Date), _dec3$4 = Api.field(v.openapi({
1265
+ })), _dec2$h = Reflect.metadata("design:type", typeof Date === "undefined" ? Object : Date), _dec3$4 = Api.field(v.openapi({
1240
1266
  title: $locale('UpdatedAt'),
1241
1267
  rest: {
1242
1268
  order: OrderMaxBase - 1
@@ -1251,7 +1277,7 @@ let EntityBaseInner = (_dec$g = Api.field(v.openapi({
1251
1277
  rest: {
1252
1278
  visible: false
1253
1279
  }
1254
- }), v.default(0)), _dec8 = Reflect.metadata("design:type", Number), _class$g = class EntityBaseInner extends EntityBaseEmpty {
1280
+ }), v.default(0)), _dec8 = Reflect.metadata("design:type", Number), _class$h = class EntityBaseInner extends EntityBaseEmpty {
1255
1281
  constructor(...args) {
1256
1282
  super(...args);
1257
1283
  _initializerDefineProperty(this, "createdAt", _descriptor$2, this);
@@ -1259,63 +1285,63 @@ let EntityBaseInner = (_dec$g = Api.field(v.openapi({
1259
1285
  _initializerDefineProperty(this, "deleted", _descriptor3, this);
1260
1286
  _initializerDefineProperty(this, "iid", _descriptor4, this);
1261
1287
  }
1262
- }, _descriptor$2 = _applyDecoratedDescriptor(_class$g.prototype, "createdAt", [_dec$g, _dec2$g], {
1288
+ }, _descriptor$2 = _applyDecoratedDescriptor(_class$h.prototype, "createdAt", [_dec$h, _dec2$h], {
1263
1289
  configurable: true,
1264
1290
  enumerable: true,
1265
1291
  writable: true,
1266
1292
  initializer: null
1267
- }), _descriptor2 = _applyDecoratedDescriptor(_class$g.prototype, "updatedAt", [_dec3$4, _dec4$2], {
1293
+ }), _descriptor2 = _applyDecoratedDescriptor(_class$h.prototype, "updatedAt", [_dec3$4, _dec4$2], {
1268
1294
  configurable: true,
1269
1295
  enumerable: true,
1270
1296
  writable: true,
1271
1297
  initializer: null
1272
- }), _descriptor3 = _applyDecoratedDescriptor(_class$g.prototype, "deleted", [_dec5, _dec6], {
1298
+ }), _descriptor3 = _applyDecoratedDescriptor(_class$h.prototype, "deleted", [_dec5, _dec6], {
1273
1299
  configurable: true,
1274
1300
  enumerable: true,
1275
1301
  writable: true,
1276
1302
  initializer: null
1277
- }), _descriptor4 = _applyDecoratedDescriptor(_class$g.prototype, "iid", [_dec7, _dec8], {
1303
+ }), _descriptor4 = _applyDecoratedDescriptor(_class$h.prototype, "iid", [_dec7, _dec8], {
1278
1304
  configurable: true,
1279
1305
  enumerable: true,
1280
1306
  writable: true,
1281
1307
  initializer: null
1282
- }), _class$g);
1308
+ }), _class$h);
1283
1309
 
1284
- var _dec$f, _dec2$f, _class$f, _descriptor$1;
1285
- let EntityBase = (_dec$f = Api.field(v.openapi({
1310
+ var _dec$g, _dec2$g, _class$g, _descriptor$1;
1311
+ let EntityBase = (_dec$g = Api.field(v.openapi({
1286
1312
  title: $locale('TableIdentity'),
1287
1313
  rest: {
1288
1314
  order: OrderCoreBase + 1
1289
1315
  }
1290
- }), v.tableIdentity()), _dec2$f = Reflect.metadata("design:type", typeof TableIdentity === "undefined" ? Object : TableIdentity), _class$f = class EntityBase extends EntityBaseInner {
1316
+ }), v.tableIdentity()), _dec2$g = Reflect.metadata("design:type", typeof TableIdentity === "undefined" ? Object : TableIdentity), _class$g = class EntityBase extends EntityBaseInner {
1291
1317
  constructor(...args) {
1292
1318
  super(...args);
1293
1319
  _initializerDefineProperty(this, "id", _descriptor$1, this);
1294
1320
  }
1295
- }, _descriptor$1 = _applyDecoratedDescriptor(_class$f.prototype, "id", [_dec$f, _dec2$f], {
1321
+ }, _descriptor$1 = _applyDecoratedDescriptor(_class$g.prototype, "id", [_dec$g, _dec2$g], {
1296
1322
  configurable: true,
1297
1323
  enumerable: true,
1298
1324
  writable: true,
1299
1325
  initializer: null
1300
- }), _class$f);
1326
+ }), _class$g);
1301
1327
 
1302
- var _dec$e, _dec2$e, _class$e, _descriptor;
1303
- let EntityBaseSimple = (_dec$e = Api.field(v.openapi({
1328
+ var _dec$f, _dec2$f, _class$f, _descriptor;
1329
+ let EntityBaseSimple = (_dec$f = Api.field(v.openapi({
1304
1330
  title: $locale('TableIdentity'),
1305
1331
  rest: {
1306
1332
  order: OrderCoreBase + 1
1307
1333
  }
1308
- })), _dec2$e = Reflect.metadata("design:type", Number), _class$e = class EntityBaseSimple extends EntityBaseInner {
1334
+ })), _dec2$f = Reflect.metadata("design:type", Number), _class$f = class EntityBaseSimple extends EntityBaseInner {
1309
1335
  constructor(...args) {
1310
1336
  super(...args);
1311
1337
  _initializerDefineProperty(this, "id", _descriptor, this);
1312
1338
  }
1313
- }, _descriptor = _applyDecoratedDescriptor(_class$e.prototype, "id", [_dec$e, _dec2$e], {
1339
+ }, _descriptor = _applyDecoratedDescriptor(_class$f.prototype, "id", [_dec$f, _dec2$f], {
1314
1340
  configurable: true,
1315
1341
  enumerable: true,
1316
1342
  writable: true,
1317
1343
  initializer: null
1318
- }), _class$e);
1344
+ }), _class$f);
1319
1345
 
1320
1346
  const SymbolKeyEntity = Symbol('$entity');
1321
1347
  const SymbolKeyEntityMeta = Symbol('$entityMeta');
@@ -2003,12 +2029,10 @@ class BeanModelCrudInner extends BeanModelView {
2003
2029
  }
2004
2030
  // builder
2005
2031
  const builder = this.builder(table);
2006
- // insert
2007
- builder.insert(datas);
2008
- // debug
2009
- this.$loggerChild('model').debug('model.insert: %s', builder.toQuery());
2032
+ // // debug
2033
+ // this.$loggerChild('model').debug('model.insert: %s', builder.toQuery());
2010
2034
  // dialect insert
2011
- const ids = await this.dialect.insert(builder);
2035
+ const ids = await this.dialect.insert(builder, datas);
2012
2036
  // combine
2013
2037
  const result = [];
2014
2038
  const dataDefault = await this.defaultData(table);
@@ -2109,10 +2133,10 @@ class BeanModelCrudTable extends BeanModelCrudInner {
2109
2133
  }
2110
2134
  }
2111
2135
 
2112
- var _dec$d, _dec2$d, _dec3$3, _class$d;
2113
- let BeanModel = (_dec$d = Bean(), _dec2$d = Virtual(), _dec3$3 = BeanInfo({
2136
+ var _dec$e, _dec2$e, _dec3$3, _class$e;
2137
+ let BeanModel = (_dec$e = Bean(), _dec2$e = Virtual(), _dec3$3 = BeanInfo({
2114
2138
  module: "a-orm"
2115
- }), _dec$d(_class$d = _dec2$d(_class$d = _dec3$3(_class$d = class BeanModel extends BeanModelCrudTable {}) || _class$d) || _class$d) || _class$d);
2139
+ }), _dec$e(_class$e = _dec2$e(_class$e = _dec3$3(_class$e = class BeanModel extends BeanModelCrudTable {}) || _class$e) || _class$e) || _class$e);
2116
2140
 
2117
2141
  const SymbolCacheOptions = Symbol('SymbolCacheOptions');
2118
2142
  const SymbolCacheEnabled = Symbol('SymbolCacheEnabled');
@@ -2187,10 +2211,10 @@ class ModelCacheBase extends BeanBase {
2187
2211
  }
2188
2212
  }
2189
2213
 
2190
- var _dec$c, _dec2$c, _class$c;
2191
- let ServiceCacheEntity = (_dec$c = Service(), _dec2$c = BeanInfo({
2214
+ var _dec$d, _dec2$d, _class$d;
2215
+ let ServiceCacheEntity = (_dec$d = Service(), _dec2$d = BeanInfo({
2192
2216
  module: "a-orm"
2193
- }), _dec$c(_class$c = _dec2$c(_class$c = class ServiceCacheEntity extends ModelCacheBase {
2217
+ }), _dec$d(_class$d = _dec2$d(_class$d = class ServiceCacheEntity extends ModelCacheBase {
2194
2218
  __init__(model) {
2195
2219
  super.__init__(model, 'entity');
2196
2220
  }
@@ -2213,12 +2237,12 @@ let ServiceCacheEntity = (_dec$c = Service(), _dec2$c = BeanInfo({
2213
2237
  get keysAux() {
2214
2238
  return this._model.options.cache?.keysAux;
2215
2239
  }
2216
- }) || _class$c) || _class$c);
2240
+ }) || _class$d) || _class$d);
2217
2241
 
2218
- var _dec$b, _dec2$b, _class$b;
2219
- let ServiceCacheQuery = (_dec$b = Service(), _dec2$b = BeanInfo({
2242
+ var _dec$c, _dec2$c, _class$c;
2243
+ let ServiceCacheQuery = (_dec$c = Service(), _dec2$c = BeanInfo({
2220
2244
  module: "a-orm"
2221
- }), _dec$b(_class$b = _dec2$b(_class$b = class ServiceCacheQuery extends ModelCacheBase {
2245
+ }), _dec$c(_class$c = _dec2$c(_class$c = class ServiceCacheQuery extends ModelCacheBase {
2222
2246
  __init__(model) {
2223
2247
  super.__init__(model, 'query');
2224
2248
  }
@@ -2228,12 +2252,12 @@ let ServiceCacheQuery = (_dec$b = Service(), _dec2$b = BeanInfo({
2228
2252
  const cache = this.getInstance(table);
2229
2253
  await cache.clear();
2230
2254
  }
2231
- }) || _class$b) || _class$b);
2255
+ }) || _class$c) || _class$c);
2232
2256
 
2233
- var _dec$a, _dec2$a, _class$a;
2234
- let ServiceRelations = (_dec$a = Service(), _dec2$a = BeanInfo({
2257
+ var _dec$b, _dec2$b, _class$b;
2258
+ let ServiceRelations = (_dec$b = Service(), _dec2$b = BeanInfo({
2235
2259
  module: "a-orm"
2236
- }), _dec$a(_class$a = _dec2$a(_class$a = class ServiceRelations extends BeanBase {
2260
+ }), _dec$b(_class$b = _dec2$b(_class$b = class ServiceRelations extends BeanBase {
2237
2261
  constructor(...args) {
2238
2262
  super(...args);
2239
2263
  this._model = void 0;
@@ -2729,7 +2753,7 @@ let ServiceRelations = (_dec$a = Service(), _dec2$a = BeanInfo({
2729
2753
  if (!columns) return [columns, true];
2730
2754
  columns = Array.isArray(columns) ? columns : [columns];
2731
2755
  if (columns.includes('*') || columns.includes(key)) return [columns, true];
2732
- columns.push(key);
2756
+ columns = columns.concat(key);
2733
2757
  return [columns, false];
2734
2758
  }
2735
2759
  __getModelTarget(modelClassTarget, meta) {
@@ -2774,7 +2798,7 @@ let ServiceRelations = (_dec$a = Service(), _dec2$a = BeanInfo({
2774
2798
  }
2775
2799
  return relations;
2776
2800
  }
2777
- }) || _class$a) || _class$a);
2801
+ }) || _class$b) || _class$b);
2778
2802
 
2779
2803
  class BeanModelCrud extends BeanModelCrudInner {
2780
2804
  async mget(ids, options) {
@@ -3244,17 +3268,73 @@ class BeanModelCache extends BeanModelCrud {
3244
3268
  return data2;
3245
3269
  }
3246
3270
  async cacheEntityDel(id, table) {
3271
+ await this.cacheEntityDelInner(id, table);
3272
+ if (this.db.inTransaction) {
3273
+ this.db.commit(async () => {
3274
+ await this.cacheEntityDelInner(id, table);
3275
+ });
3276
+ }
3277
+ this._shardingCacheDoubleDelete({
3278
+ beanFullName: this.$beanFullName,
3279
+ clientName: this.db.clientName,
3280
+ table: this.getTable(),
3281
+ method: 'cacheEntityDelInner',
3282
+ args: [id, table]
3283
+ });
3284
+ }
3285
+ async cacheEntityDelInner(id, table) {
3247
3286
  await this.cacheEntity.del(id, table);
3248
- await this.cacheQueryClear(table);
3287
+ await this.cacheQueryClearInner(table);
3249
3288
  }
3250
3289
  async cacheEntityClear(table) {
3290
+ await this.cacheEntityClearInner(table);
3291
+ if (this.db.inTransaction) {
3292
+ this.db.commit(async () => {
3293
+ await this.cacheEntityClearInner(table);
3294
+ });
3295
+ }
3296
+ this._shardingCacheDoubleDelete({
3297
+ beanFullName: this.$beanFullName,
3298
+ clientName: this.db.clientName,
3299
+ table: this.getTable(),
3300
+ method: 'cacheEntityClearInner',
3301
+ args: [table]
3302
+ });
3303
+ }
3304
+ async cacheEntityClearInner(table) {
3251
3305
  await this.cacheEntity.clear(table);
3252
- await this.cacheQueryClear(table);
3306
+ await this.cacheQueryClearInner(table);
3253
3307
  }
3254
3308
  async cacheQueryClear(table) {
3309
+ await this.cacheQueryClearInner(table);
3310
+ if (this.db.inTransaction) {
3311
+ this.db.commit(async () => {
3312
+ await this.cacheQueryClearInner(table);
3313
+ });
3314
+ }
3315
+ this._shardingCacheDoubleDelete({
3316
+ beanFullName: this.$beanFullName,
3317
+ clientName: this.db.clientName,
3318
+ table: this.getTable(),
3319
+ method: 'cacheQueryClearInner',
3320
+ args: [table]
3321
+ });
3322
+ }
3323
+ async cacheQueryClearInner(table) {
3255
3324
  await this.cacheQuery.clear(table);
3256
3325
  await this._cacheQueryClearModelsClear();
3257
3326
  }
3327
+ _shardingCacheDoubleDelete(jobData) {
3328
+ const doubleDelete = this.scopeOrm.config.sharding.cache.doubleDelete;
3329
+ if (!doubleDelete) return;
3330
+ if (this.db.inTransaction) {
3331
+ this.db.commit(() => {
3332
+ this.scopeOrm.queue.doubleDelete.push(jobData);
3333
+ });
3334
+ } else {
3335
+ this.scopeOrm.queue.doubleDelete.push(jobData);
3336
+ }
3337
+ }
3258
3338
  async _cacheQueryClearModelsClear() {
3259
3339
  const modelsClear = this._getModelsClear();
3260
3340
  if (!modelsClear || modelsClear.length === 0) return;
@@ -3264,7 +3344,7 @@ class BeanModelCache extends BeanModelCrud {
3264
3344
  if (modelsClearedByFn) {
3265
3345
  await modelsClearedByFn(this.ctx, modelTarget, this);
3266
3346
  } else {
3267
- await modelTarget.cacheQueryClear();
3347
+ await modelTarget.cacheQueryClearInner();
3268
3348
  }
3269
3349
  }
3270
3350
  }
@@ -3340,16 +3420,16 @@ class BeanModelCache extends BeanModelCrud {
3340
3420
  }
3341
3421
  }
3342
3422
 
3343
- var _dec$9, _dec2$9, _dec3$2, _class$9;
3344
- let BeanModelBase = (_dec$9 = Bean(), _dec2$9 = Virtual(), _dec3$2 = BeanInfo({
3423
+ var _dec$a, _dec2$a, _dec3$2, _class$a;
3424
+ let BeanModelBase = (_dec$a = Bean(), _dec2$a = Virtual(), _dec3$2 = BeanInfo({
3345
3425
  module: "a-orm"
3346
- }), _dec$9(_class$9 = _dec2$9(_class$9 = _dec3$2(_class$9 = class BeanModelBase extends BeanModelCache {}) || _class$9) || _class$9) || _class$9);
3426
+ }), _dec$a(_class$a = _dec2$a(_class$a = _dec3$2(_class$a = class BeanModelBase extends BeanModelCache {}) || _class$a) || _class$a) || _class$a);
3347
3427
 
3348
- var _dec$8, _dec2$8, _dec3$1, _dec4$1, _class$8;
3428
+ var _dec$9, _dec2$9, _dec3$1, _dec4$1, _class$9;
3349
3429
  const SymbolModuleScope$1 = Symbol('SymbolModuleScope');
3350
- let ServiceEntityResolver = (_dec$8 = Service(), _dec2$8 = BeanInfo({
3430
+ let ServiceEntityResolver = (_dec$9 = Service(), _dec2$9 = BeanInfo({
3351
3431
  module: "a-orm"
3352
- }), _dec3$1 = Reflect.metadata("design:type", Function), _dec4$1 = Reflect.metadata("design:paramtypes", [String]), _dec$8(_class$8 = _dec2$8(_class$8 = _dec3$1(_class$8 = _dec4$1(_class$8 = class ServiceEntityResolver extends BeanBase {
3432
+ }), _dec3$1 = Reflect.metadata("design:type", Function), _dec4$1 = Reflect.metadata("design:paramtypes", [String]), _dec$9(_class$9 = _dec2$9(_class$9 = _dec3$1(_class$9 = _dec4$1(_class$9 = class ServiceEntityResolver extends BeanBase {
3353
3433
  constructor(moduleScope) {
3354
3434
  super();
3355
3435
  this[SymbolModuleScope$1] = void 0;
@@ -3364,13 +3444,13 @@ let ServiceEntityResolver = (_dec$8 = Service(), _dec2$8 = BeanInfo({
3364
3444
  }
3365
3445
  return this.__instances[prop];
3366
3446
  }
3367
- }) || _class$8) || _class$8) || _class$8) || _class$8);
3447
+ }) || _class$9) || _class$9) || _class$9) || _class$9);
3368
3448
 
3369
- var _dec$7, _dec2$7, _dec3, _dec4, _class$7;
3449
+ var _dec$8, _dec2$8, _dec3, _dec4, _class$8;
3370
3450
  const SymbolModuleScope = Symbol('SymbolModuleScope');
3371
- let ServiceModelResolver = (_dec$7 = Service(), _dec2$7 = BeanInfo({
3451
+ let ServiceModelResolver = (_dec$8 = Service(), _dec2$8 = BeanInfo({
3372
3452
  module: "a-orm"
3373
- }), _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [String]), _dec$7(_class$7 = _dec2$7(_class$7 = _dec3(_class$7 = _dec4(_class$7 = class ServiceModelResolver extends BeanBase {
3453
+ }), _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [String]), _dec$8(_class$8 = _dec2$8(_class$8 = _dec3(_class$8 = _dec4(_class$8 = class ServiceModelResolver extends BeanBase {
3374
3454
  constructor(moduleScope) {
3375
3455
  super();
3376
3456
  this[SymbolModuleScope] = void 0;
@@ -3380,12 +3460,12 @@ let ServiceModelResolver = (_dec$7 = Service(), _dec2$7 = BeanInfo({
3380
3460
  const beanFullName = `${this[SymbolModuleScope]}.model.${prop}`;
3381
3461
  return this.bean._getBean(beanFullName);
3382
3462
  }
3383
- }) || _class$7) || _class$7) || _class$7) || _class$7);
3463
+ }) || _class$8) || _class$8) || _class$8) || _class$8);
3384
3464
 
3385
- var _dec$6, _dec2$6, _class$6;
3386
- let BroadcastColumnsClear = (_dec$6 = Broadcast(), _dec2$6 = BeanInfo({
3465
+ var _dec$7, _dec2$7, _class$7;
3466
+ let BroadcastColumnsClear = (_dec$7 = Broadcast(), _dec2$7 = BeanInfo({
3387
3467
  module: "a-orm"
3388
- }), _dec$6(_class$6 = _dec2$6(_class$6 = class BroadcastColumnsClear extends BeanBroadcastBase {
3468
+ }), _dec$7(_class$7 = _dec2$7(_class$7 = class BroadcastColumnsClear extends BeanBroadcastBase {
3389
3469
  async execute(data, isEmitter) {
3390
3470
  const {
3391
3471
  clientName,
@@ -3395,12 +3475,12 @@ let BroadcastColumnsClear = (_dec$6 = Broadcast(), _dec2$6 = BeanInfo({
3395
3475
  await cast(this.scope.service.database).__columnsClearRaw(clientName, tableName);
3396
3476
  }
3397
3477
  }
3398
- }) || _class$6) || _class$6);
3478
+ }) || _class$7) || _class$7);
3399
3479
 
3400
- var _dec$5, _dec2$5, _class$5;
3401
- let BroadcastDatabaseClientReload = (_dec$5 = Broadcast(), _dec2$5 = BeanInfo({
3480
+ var _dec$6, _dec2$6, _class$6;
3481
+ let BroadcastDatabaseClientReload = (_dec$6 = Broadcast(), _dec2$6 = BeanInfo({
3402
3482
  module: "a-orm"
3403
- }), _dec$5(_class$5 = _dec2$5(_class$5 = class BroadcastDatabaseClientReload extends BeanBroadcastBase {
3483
+ }), _dec$6(_class$6 = _dec2$6(_class$6 = class BroadcastDatabaseClientReload extends BeanBroadcastBase {
3404
3484
  async execute(data, isEmitter) {
3405
3485
  const {
3406
3486
  clientName,
@@ -3411,22 +3491,38 @@ let BroadcastDatabaseClientReload = (_dec$5 = Broadcast(), _dec2$5 = BeanInfo({
3411
3491
  await cast(this.scope.service.database).__reloadAllClientsRaw(clientName, clientConfig, extraData);
3412
3492
  }
3413
3493
  }
3414
- }) || _class$5) || _class$5);
3494
+ }) || _class$6) || _class$6);
3495
+
3496
+ var _dec$5, _dec2$5, _class$5;
3497
+ let EventClientNameReal = (_dec$5 = Event(), _dec2$5 = BeanInfo({
3498
+ module: "a-orm"
3499
+ }), _dec$5(_class$5 = _dec2$5(_class$5 = class EventClientNameReal extends BeanEventBase {}) || _class$5) || _class$5);
3415
3500
 
3416
3501
  var _dec$4, _dec2$4, _class$4;
3417
- let EventClientNameReal = (_dec$4 = Event(), _dec2$4 = BeanInfo({
3502
+ let EventColumnsClear = (_dec$4 = Event(), _dec2$4 = BeanInfo({
3418
3503
  module: "a-orm"
3419
- }), _dec$4(_class$4 = _dec2$4(_class$4 = class EventClientNameReal extends BeanEventBase {}) || _class$4) || _class$4);
3504
+ }), _dec$4(_class$4 = _dec2$4(_class$4 = class EventColumnsClear extends BeanEventBase {}) || _class$4) || _class$4);
3420
3505
 
3421
3506
  var _dec$3, _dec2$3, _class$3;
3422
- let EventColumnsClear = (_dec$3 = Event(), _dec2$3 = BeanInfo({
3507
+ let EventDatabaseClientReload = (_dec$3 = Event(), _dec2$3 = BeanInfo({
3423
3508
  module: "a-orm"
3424
- }), _dec$3(_class$3 = _dec2$3(_class$3 = class EventColumnsClear extends BeanEventBase {}) || _class$3) || _class$3);
3509
+ }), _dec$3(_class$3 = _dec2$3(_class$3 = class EventDatabaseClientReload extends BeanEventBase {}) || _class$3) || _class$3);
3425
3510
 
3426
3511
  var _dec$2, _dec2$2, _class$2;
3427
- let EventDatabaseClientReload = (_dec$2 = Event(), _dec2$2 = BeanInfo({
3512
+ let QueueDoubleDelete = (_dec$2 = Queue({
3513
+ options: {
3514
+ job: {
3515
+ delay: 3 * 1000
3516
+ }
3517
+ }
3518
+ }), _dec2$2 = BeanInfo({
3428
3519
  module: "a-orm"
3429
- }), _dec$2(_class$2 = _dec2$2(_class$2 = class EventDatabaseClientReload extends BeanEventBase {}) || _class$2) || _class$2);
3520
+ }), _dec$2(_class$2 = _dec2$2(_class$2 = class QueueDoubleDelete extends BeanQueueBase {
3521
+ async execute(data, _options) {
3522
+ const beanInstance = this.app.bean._newBean(data.beanFullName, data.clientName, data.table);
3523
+ await beanInstance[data.method](...data.args);
3524
+ }
3525
+ }) || _class$2) || _class$2);
3430
3526
 
3431
3527
  var _dec$1, _dec2$1, _class$1;
3432
3528
  let ScheduleSoftDeletionPrune = (_dec$1 = Schedule({
@@ -3470,11 +3566,19 @@ let ScheduleSoftDeletionPrune = (_dec$1 = Schedule({
3470
3566
 
3471
3567
  function config(_app) {
3472
3568
  return {
3569
+ sharding: {
3570
+ cache: {
3571
+ doubleDelete: false
3572
+ }
3573
+ },
3473
3574
  rest: {
3474
3575
  query: {
3475
3576
  pageSize: {
3476
3577
  default: 20,
3477
3578
  max: 100
3579
+ },
3580
+ orders: {
3581
+ default: 'createdAt,desc'
3478
3582
  }
3479
3583
  }
3480
3584
  },
@@ -3647,11 +3751,11 @@ class Main extends BeanSimple {
3647
3751
  };
3648
3752
  }
3649
3753
  });
3650
- Object.defineProperty(this.app.context, 'commitDone', {
3754
+ Object.defineProperty(this.app.context, 'commitsDone', {
3651
3755
  enumerable: false,
3652
3756
  get() {
3653
3757
  return function () {
3654
- cast(this).transactionConsistency.commitDone();
3758
+ return cast(this).transactionConsistency.commitsDone();
3655
3759
  };
3656
3760
  }
3657
3761
  });
@@ -4241,4 +4345,4 @@ const $relationMutate = {
4241
4345
  belongsToMany
4242
4346
  };
4243
4347
 
4244
- export { $Dto, $column, $columns, $columnsAll, $locale, $relation, $relationDynamic, $relationMutate, $tableColumns, $tableComments, $tableDefaults, $tableName, AopMethodTransaction, BeanDatabase, BeanDatabaseDialectBase, BeanModel, BeanModelBase, BeanModelMeta, BroadcastColumnsClear, BroadcastDatabaseClientReload, Database, DatabaseDialect, DtoQueryBase, DtoQueryPageBase, Entity, EntityBase, EntityBaseEmpty, EntityBaseInner, EntityBaseSimple, Errors, EventClientNameReal, EventColumnsClear, EventDatabaseClientReload, ExtendKnex, ExtendSchemaBuilder, ExtendTableBuilder, Main, Model, Op, OpAggrs, OpJoint, OpJointValues, OpNormal, OpNormalValues, OpValues, ScheduleSoftDeletionPrune, ScopeModuleAOrm, ServiceCacheEntity, ServiceCacheQuery, ServiceColumns, ServiceColumnsCache, ServiceDatabase, ServiceDatabaseAsyncLocalStorage, ServiceDatabaseClient, ServiceDb, ServiceEntityResolver, ServiceModelResolver, ServiceRelations, ServiceTransaction, ServiceTransactionAsyncLocalStorage, ServiceTransactionConsistency‌, ServiceTransactionFiber, ServiceTransactionState, SymbolKeyEntity, SymbolKeyEntityMeta, SymbolKeyFieldsMore, SymbolKeyModelOptions, TransactionIsolationLevelsMap, buildWhere, config, configDefault, getClassEntityFromClassModel, getTableOrTableAlias, getTargetColumnName, isAggrColumn, isRaw, isRef, locales, prepareClassModel, prepareColumns };
4348
+ export { $Dto, $column, $columns, $columnsAll, $locale, $relation, $relationDynamic, $relationMutate, $tableColumns, $tableComments, $tableDefaults, $tableName, AopMethodTransaction, BeanDatabase, BeanDatabaseDialectBase, BeanModel, BeanModelBase, BeanModelMeta, BroadcastColumnsClear, BroadcastDatabaseClientReload, Database, DatabaseDialect, DtoQueryBase, DtoQueryPageBase, Entity, EntityBase, EntityBaseEmpty, EntityBaseInner, EntityBaseSimple, Errors, EventClientNameReal, EventColumnsClear, EventDatabaseClientReload, ExtendKnex, ExtendSchemaBuilder, ExtendTableBuilder, Main, Model, Op, OpAggrs, OpJoint, OpJointValues, OpNormal, OpNormalValues, OpValues, QueueDoubleDelete, ScheduleSoftDeletionPrune, ScopeModuleAOrm, ServiceCacheEntity, ServiceCacheQuery, ServiceColumns, ServiceColumnsCache, ServiceDatabase, ServiceDatabaseAsyncLocalStorage, ServiceDatabaseClient, ServiceDb, ServiceEntityResolver, ServiceModelResolver, ServiceRelations, ServiceTransaction, ServiceTransactionAsyncLocalStorage, ServiceTransactionConsistency‌, ServiceTransactionFiber, ServiceTransactionState, SymbolKeyEntity, SymbolKeyEntityMeta, SymbolKeyFieldsMore, SymbolKeyModelOptions, TransactionIsolationLevelsMap, buildWhere, config, configDefault, getClassEntityFromClassModel, getTableOrTableAlias, getTargetColumnName, isAggrColumn, isRaw, isRef, locales, prepareClassModel, prepareColumns };
@@ -5,6 +5,6 @@ export declare class ServiceTransactionConsistency‌ extends BeanBase {
5
5
  private _compensateCallbacks;
6
6
  commit(cb: FunctionAny): void;
7
7
  compensate(cb: FunctionAny): void;
8
- commitDone(): Promise<void>;
9
- compensateDone(): Promise<void>;
8
+ commitsDone(): Promise<void>;
9
+ compensatesDone(): Promise<void>;
10
10
  }
@@ -29,7 +29,7 @@ declare module 'vona' {
29
29
  interface VonaContext {
30
30
  get db(): ServiceDb;
31
31
  commit(cb: FunctionAny): void;
32
- commitDone(): Promise<void>;
32
+ commitsDone(): Promise<void>;
33
33
  }
34
34
  interface VonaConfigEnv {
35
35
  DATABASE_DEFAULT_CLIENT: string | undefined;
@@ -10,6 +10,8 @@ export declare const OpJoint: {
10
10
  export declare const OpNormal: {
11
11
  readonly eq: "_eq_";
12
12
  readonly notEq: "_notEq_";
13
+ readonly eqI: "_eqI_";
14
+ readonly notEqI: "_notEqI_";
13
15
  readonly gt: "_gt_";
14
16
  readonly gte: "_gte_";
15
17
  readonly lt: "_lt_";
@@ -31,6 +33,8 @@ export declare const OpNormal: {
31
33
  export declare const Op: {
32
34
  readonly eq: "_eq_";
33
35
  readonly notEq: "_notEq_";
36
+ readonly eqI: "_eqI_";
37
+ readonly notEqI: "_notEqI_";
34
38
  readonly gt: "_gt_";
35
39
  readonly gte: "_gte_";
36
40
  readonly lt: "_lt_";
@@ -56,8 +60,8 @@ export declare const Op: {
56
60
  readonly skip: "_skip_";
57
61
  };
58
62
  export declare const OpJointValues: ("_and_" | "_or_" | "_not_" | "_exists_" | "_notExists_")[];
59
- export declare const OpNormalValues: ("_eq_" | "_notEq_" | "_gt_" | "_gte_" | "_lt_" | "_lte_" | "_in_" | "_notIn_" | "_is_" | "_isNot_" | "_between_" | "_notBetween_" | "_startsWith_" | "_endsWith_" | "_includes_" | "_startsWithI_" | "_endsWithI_" | "_includesI_" | "_ref_")[];
60
- export declare const OpValues: ("_eq_" | "_notEq_" | "_gt_" | "_gte_" | "_lt_" | "_lte_" | "_in_" | "_notIn_" | "_is_" | "_isNot_" | "_between_" | "_notBetween_" | "_startsWith_" | "_endsWith_" | "_includes_" | "_startsWithI_" | "_endsWithI_" | "_includesI_" | "_ref_" | "_and_" | "_or_" | "_not_" | "_exists_" | "_notExists_" | "_skip_")[];
63
+ export declare const OpNormalValues: ("_eq_" | "_notEq_" | "_eqI_" | "_notEqI_" | "_gt_" | "_gte_" | "_lt_" | "_lte_" | "_in_" | "_notIn_" | "_is_" | "_isNot_" | "_between_" | "_notBetween_" | "_startsWith_" | "_endsWith_" | "_includes_" | "_startsWithI_" | "_endsWithI_" | "_includesI_" | "_ref_")[];
64
+ export declare const OpValues: ("_and_" | "_or_" | "_not_" | "_exists_" | "_notExists_" | "_skip_" | "_eq_" | "_notEq_" | "_eqI_" | "_notEqI_" | "_gt_" | "_gte_" | "_lt_" | "_lte_" | "_in_" | "_notIn_" | "_is_" | "_isNot_" | "_between_" | "_notBetween_" | "_startsWith_" | "_endsWith_" | "_includes_" | "_startsWithI_" | "_endsWithI_" | "_includesI_" | "_ref_")[];
61
65
  export type TypeOpsJointPostfix<Op> = {
62
66
  [KEY in keyof Op]: Op[KEY] | (KEY extends string ? `_${KEY}_${number}` : never);
63
67
  };
@@ -5,7 +5,7 @@ export interface IDecoratorDatabaseDialectOptions {
5
5
  }
6
6
  declare module 'vona-module-a-onion' {
7
7
  interface BeanOnion {
8
- databaseDialect: ServiceOnion<IDecoratorDatabaseDialectOptions, keyof IDatabaseDialectRecord>;
8
+ databaseDialect: ServiceOnion<IDatabaseDialectRecord>;
9
9
  }
10
10
  }
11
11
  declare module 'vona' {
@@ -1,6 +1,7 @@
1
1
  import type { OmitNever } from 'vona';
2
2
  import type { ServiceOnion } from 'vona-module-a-onion';
3
3
  import type { TypeOpenapiMetadata } from 'vona-module-a-openapi';
4
+ import type { SchemaLike } from 'vona-module-a-openapiutils';
4
5
  import type { SymbolKeyFieldsMore } from '../entity.ts';
5
6
  import type { ITableRecord } from './table.ts';
6
7
  export interface IEntityRecord {
@@ -10,10 +11,11 @@ export interface IDecoratorEntityOptions<FieldsMore = never> {
10
11
  table?: keyof ITableRecord;
11
12
  independent?: boolean;
12
13
  openapi?: TypeOpenapiMetadata;
14
+ pipes?: SchemaLike | SchemaLike[];
13
15
  }
14
16
  declare module 'vona-module-a-onion' {
15
17
  interface BeanOnion {
16
- entity: ServiceOnion<IDecoratorEntityOptions, keyof IEntityRecord>;
18
+ entity: ServiceOnion<IEntityRecord>;
17
19
  }
18
20
  }
19
21
  declare module 'vona' {
@@ -42,7 +42,7 @@ export interface IDecoratorModelOptions<TRecord extends EntityBaseEmpty = any> {
42
42
  }
43
43
  declare module 'vona-module-a-onion' {
44
44
  interface BeanOnion {
45
- model: ServiceOnion<IDecoratorModelOptions, keyof IModelRecord>;
45
+ model: ServiceOnion<IModelRecord>;
46
46
  }
47
47
  }
48
48
  declare module 'vona' {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-orm",
3
3
  "type": "module",
4
- "version": "5.0.51",
4
+ "version": "5.0.53",
5
5
  "title": "a-orm",
6
6
  "vonaModule": {
7
7
  "capabilities": {