vona-module-a-orm 5.0.57 → 5.0.58

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.
@@ -86,11 +86,13 @@ declare module 'vona' {
86
86
  /** service: end */
87
87
  /** broadcast: begin */
88
88
  export * from '../bean/broadcast.columnsClear.ts';
89
+ export * from '../bean/broadcast.databaseClientDispose.ts';
89
90
  export * from '../bean/broadcast.databaseClientReload.ts';
90
91
  import { type IDecoratorBroadcastOptions } from 'vona-module-a-broadcast';
91
92
  declare module 'vona-module-a-broadcast' {
92
93
  interface IBroadcastRecord {
93
94
  'a-orm:columnsClear': IDecoratorBroadcastOptions;
95
+ 'a-orm:databaseClientDispose': IDecoratorBroadcastOptions;
94
96
  'a-orm:databaseClientReload': IDecoratorBroadcastOptions;
95
97
  }
96
98
  }
@@ -101,6 +103,12 @@ declare module 'vona-module-a-orm' {
101
103
  get $beanFullName(): 'a-orm.broadcast.columnsClear';
102
104
  get $onionName(): 'a-orm:columnsClear';
103
105
  }
106
+ interface BroadcastDatabaseClientDispose {
107
+ }
108
+ interface BroadcastDatabaseClientDispose {
109
+ get $beanFullName(): 'a-orm.broadcast.databaseClientDispose';
110
+ get $onionName(): 'a-orm:databaseClientDispose';
111
+ }
104
112
  interface BroadcastDatabaseClientReload {
105
113
  }
106
114
  interface BroadcastDatabaseClientReload {
@@ -111,15 +119,18 @@ declare module 'vona-module-a-orm' {
111
119
  /** broadcast: end */
112
120
  /** broadcast: begin */
113
121
  import type { BroadcastColumnsClear } from '../bean/broadcast.columnsClear.ts';
122
+ import type { BroadcastDatabaseClientDispose } from '../bean/broadcast.databaseClientDispose.ts';
114
123
  import type { BroadcastDatabaseClientReload } from '../bean/broadcast.databaseClientReload.ts';
115
124
  export interface IModuleBroadcast {
116
125
  'columnsClear': BroadcastColumnsClear;
126
+ 'databaseClientDispose': BroadcastDatabaseClientDispose;
117
127
  'databaseClientReload': BroadcastDatabaseClientReload;
118
128
  }
119
129
  /** broadcast: end */
120
130
  /** event: begin */
121
131
  export * from '../bean/event.clientNameReal.ts';
122
132
  export * from '../bean/event.columnsClear.ts';
133
+ export * from '../bean/event.databaseClientDispose.ts';
123
134
  export * from '../bean/event.databaseClientReload.ts';
124
135
  import 'vona';
125
136
  declare module 'vona' {
@@ -137,6 +148,12 @@ declare module 'vona-module-a-orm' {
137
148
  get $beanFullName(): 'a-orm.event.columnsClear';
138
149
  get $onionName(): 'a-orm:columnsClear';
139
150
  }
151
+ interface EventDatabaseClientDispose {
152
+ }
153
+ interface EventDatabaseClientDispose {
154
+ get $beanFullName(): 'a-orm.event.databaseClientDispose';
155
+ get $onionName(): 'a-orm:databaseClientDispose';
156
+ }
140
157
  interface EventDatabaseClientReload {
141
158
  }
142
159
  interface EventDatabaseClientReload {
@@ -148,22 +165,26 @@ declare module 'vona-module-a-orm' {
148
165
  /** event: begin */
149
166
  import type { EventClientNameReal } from '../bean/event.clientNameReal.ts';
150
167
  import type { EventColumnsClear } from '../bean/event.columnsClear.ts';
168
+ import type { EventDatabaseClientDispose } from '../bean/event.databaseClientDispose.ts';
151
169
  import type { EventDatabaseClientReload } from '../bean/event.databaseClientReload.ts';
152
170
  export interface IModuleEvent {
153
171
  'clientNameReal': EventClientNameReal;
154
172
  'columnsClear': EventColumnsClear;
173
+ 'databaseClientDispose': EventDatabaseClientDispose;
155
174
  'databaseClientReload': EventDatabaseClientReload;
156
175
  }
157
176
  /** event: end */
158
177
  /** event: begin */
159
178
  import type { TypeEventClientNameRealData, TypeEventClientNameRealResult } from '../bean/event.clientNameReal.ts';
160
179
  import type { TypeEventColumnsClearData, TypeEventColumnsClearResult } from '../bean/event.columnsClear.ts';
180
+ import type { TypeEventDatabaseClientDisposeData, TypeEventDatabaseClientDisposeResult } from '../bean/event.databaseClientDispose.ts';
161
181
  import type { TypeEventDatabaseClientReloadData, TypeEventDatabaseClientReloadResult } from '../bean/event.databaseClientReload.ts';
162
182
  import type { EventOn } from 'vona-module-a-event';
163
183
  declare module 'vona-module-a-event' {
164
184
  interface IEventRecord {
165
185
  'a-orm:clientNameReal': EventOn<TypeEventClientNameRealData, TypeEventClientNameRealResult>;
166
186
  'a-orm:columnsClear': EventOn<TypeEventColumnsClearData, TypeEventColumnsClearResult>;
187
+ 'a-orm:databaseClientDispose': EventOn<TypeEventDatabaseClientDisposeData, TypeEventDatabaseClientDisposeResult>;
167
188
  'a-orm:databaseClientReload': EventOn<TypeEventDatabaseClientReloadData, TypeEventDatabaseClientReloadResult>;
168
189
  }
169
190
  }
@@ -0,0 +1,9 @@
1
+ import type { IBroadcastExecute } from 'vona-module-a-broadcast';
2
+ import type { IDatabaseClientRecord } from '../types/database.ts';
3
+ import { BeanBroadcastBase } from 'vona-module-a-broadcast';
4
+ export interface TypeBroadcastDatabaseClientDisposeJobData {
5
+ clientName?: keyof IDatabaseClientRecord;
6
+ }
7
+ export declare class BroadcastDatabaseClientDispose extends BeanBroadcastBase<TypeBroadcastDatabaseClientDisposeJobData> implements IBroadcastExecute<TypeBroadcastDatabaseClientDisposeJobData> {
8
+ execute(data: TypeBroadcastDatabaseClientDisposeJobData, isEmitter?: boolean): Promise<void>;
9
+ }
@@ -0,0 +1,8 @@
1
+ import type { IDatabaseClientRecord } from '../types/database.ts';
2
+ import { BeanEventBase } from 'vona-module-a-event';
3
+ export interface TypeEventDatabaseClientDisposeData {
4
+ clientName: keyof IDatabaseClientRecord;
5
+ }
6
+ export type TypeEventDatabaseClientDisposeResult = void;
7
+ export declare class EventDatabaseClientDispose extends BeanEventBase<TypeEventDatabaseClientDisposeData, TypeEventDatabaseClientDisposeResult> {
8
+ }
package/dist/index.js CHANGED
@@ -17,21 +17,21 @@ import { configAllWithIgnoreNull, configAll, configRedisWithIgnoreNull, configRe
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$x, _dec2$x, _class$x;
21
- let AopMethodTransaction = (_dec$x = AopMethod(), _dec2$x = BeanInfo({
20
+ var _dec$z, _dec2$z, _class$z;
21
+ let AopMethodTransaction = (_dec$z = AopMethod(), _dec2$z = BeanInfo({
22
22
  module: "a-orm"
23
- }), _dec$x(_class$x = _dec2$x(_class$x = class AopMethodTransaction extends BeanAopMethodBase {
23
+ }), _dec$z(_class$z = _dec2$z(_class$z = 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$x) || _class$x);
29
+ }) || _class$z) || _class$z);
30
30
 
31
- var _dec$w, _dec2$w, _class$w;
32
- let ServiceDatabaseAsyncLocalStorage = (_dec$w = Service(), _dec2$w = BeanInfo({
31
+ var _dec$y, _dec2$y, _class$y;
32
+ let ServiceDatabaseAsyncLocalStorage = (_dec$y = Service(), _dec2$y = BeanInfo({
33
33
  module: "a-orm"
34
- }), _dec$w(_class$w = _dec2$w(_class$w = class ServiceDatabaseAsyncLocalStorage extends BeanBase {
34
+ }), _dec$y(_class$y = _dec2$y(_class$y = 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$w = Service(), _dec2$w = BeanInfo({
50
50
  return fn();
51
51
  });
52
52
  }
53
- }) || _class$w) || _class$w);
53
+ }) || _class$y) || _class$y);
54
54
 
55
- var _dec$v, _dec2$v, _class$v;
55
+ var _dec$x, _dec2$x, _class$x;
56
56
  const SymbolColumnsCache = Symbol('SymbolColumnsCache');
57
57
  const SymbolColumnsDefaultCache = Symbol('SymbolColumnsDefaultCache');
58
- let ServiceColumnsCache = (_dec$v = Service(), _dec2$v = BeanInfo({
58
+ let ServiceColumnsCache = (_dec$x = Service(), _dec2$x = BeanInfo({
59
59
  module: "a-orm"
60
- }), _dec$v(_class$v = _dec2$v(_class$v = class ServiceColumnsCache extends BeanBase {
60
+ }), _dec$x(_class$x = _dec2$x(_class$x = 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$v = Service(), _dec2$v = BeanInfo({
112
112
  return exists;
113
113
  }
114
114
  }
115
- }) || _class$v) || _class$v);
115
+ }) || _class$x) || _class$x);
116
116
 
117
- var _dec$u, _dec2$u, _class$u;
118
- let ServiceColumns = (_dec$u = Service(), _dec2$u = BeanInfo({
117
+ var _dec$w, _dec2$w, _class$w;
118
+ let ServiceColumns = (_dec$w = Service(), _dec2$w = BeanInfo({
119
119
  module: "a-orm"
120
- }), _dec$u(_class$u = _dec2$u(_class$u = class ServiceColumns extends BeanBase {
120
+ }), _dec$w(_class$w = _dec2$w(_class$w = 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$u = Service(), _dec2$u = BeanInfo({
168
168
  columnsClear(tableName) {
169
169
  return this.scope.service.database.columnsClear(this.db.clientName, tableName);
170
170
  }
171
- }) || _class$u) || _class$u);
171
+ }) || _class$w) || _class$w);
172
172
 
173
173
  const TransactionIsolationLevelsMap = {
174
174
  DEFAULT: undefined,
@@ -181,10 +181,13 @@ const TransactionIsolationLevelsMap = {
181
181
 
182
182
  // export type TransactionPropagation=''
183
183
 
184
- var _dec$t, _dec2$t, _class$t;
185
- let ServiceDatabase = (_dec$t = Service(), _dec2$t = BeanInfo({
184
+ var _dec$v, _dec2$v, _class$v;
185
+ let ServiceDatabase = (_dec$v = Service(), _dec2$v = BeanInfo({
186
186
  module: "a-orm"
187
- }), _dec$t(_class$t = _dec2$t(_class$t = class ServiceDatabase extends BeanBase {
187
+ }), _dec$v(_class$v = _dec2$v(_class$v = class ServiceDatabase extends BeanBase {
188
+ get configDatabase() {
189
+ return this.app.config.database;
190
+ }
188
191
  getDialect(client) {
189
192
  if (!client) throw new Error('database dialect not specified');
190
193
  const beanFullName = this.scope.config.dialects[client];
@@ -192,6 +195,23 @@ let ServiceDatabase = (_dec$t = Service(), _dec2$t = BeanInfo({
192
195
  if (!dialect) throw new Error(`database dialect not found: ${client}`);
193
196
  return dialect;
194
197
  }
198
+ getClientConfig(clientName, original = false) {
199
+ // clientConfig
200
+ let clientConfig = this.configDatabase.clients[clientName];
201
+ if (original) return clientConfig;
202
+ // check
203
+ if (!clientConfig) {
204
+ throw new Error(`database config not found: ${clientName}`);
205
+ }
206
+ // configBaseClient
207
+ const dialect = this.scope.service.database.getDialect(clientConfig.client);
208
+ const configBaseClient = dialect.getConfigBase();
209
+ // combine
210
+ const configBase = this.configDatabase.base;
211
+ clientConfig = deepExtend({}, configBase, configBaseClient, clientConfig);
212
+ // ready
213
+ return clientConfig;
214
+ }
195
215
  prepareDbInfo(dbInfoOrClientName) {
196
216
  let level;
197
217
  let clientName;
@@ -262,14 +282,14 @@ let ServiceDatabase = (_dec$t = Service(), _dec2$t = BeanInfo({
262
282
  });
263
283
  }
264
284
  async reloadClients(clientName, clientConfig, extraData) {
265
- await this.__reloadAllClientsRaw(clientName, clientConfig, extraData);
285
+ await this.reloadClientsRaw(clientName, clientConfig, extraData);
266
286
  this.scope.broadcast.databaseClientReload.emit({
267
287
  clientName,
268
288
  clientConfig,
269
289
  extraData
270
290
  });
271
291
  }
272
- async __reloadAllClientsRaw(clientName, clientConfig, extraData) {
292
+ async reloadClientsRaw(clientName, clientConfig, extraData) {
273
293
  await this.scope.event.databaseClientReload.emit({
274
294
  clientName: this.prepareClientName(clientName),
275
295
  clientConfig,
@@ -277,12 +297,24 @@ let ServiceDatabase = (_dec$t = Service(), _dec2$t = BeanInfo({
277
297
  });
278
298
  this.__columnsClearRaw(clientName);
279
299
  }
280
- }) || _class$t) || _class$t);
300
+ async disposeClients(clientName) {
301
+ await this.disposeClientsRaw(clientName);
302
+ this.scope.broadcast.databaseClientDispose.emit({
303
+ clientName
304
+ });
305
+ }
306
+ async disposeClientsRaw(clientName) {
307
+ await this.scope.event.databaseClientDispose.emit({
308
+ clientName: this.prepareClientName(clientName)
309
+ });
310
+ this.__columnsClearRaw(clientName);
311
+ }
312
+ }) || _class$v) || _class$v);
281
313
 
282
- var _dec$s, _dec2$s, _class$s;
283
- let ServiceTransactionConsistency‌ = (_dec$s = Service(), _dec2$s = BeanInfo({
314
+ var _dec$u, _dec2$u, _class$u;
315
+ let ServiceTransactionConsistency‌ = (_dec$u = Service(), _dec2$u = BeanInfo({
284
316
  module: "a-orm"
285
- }), _dec$s(_class$s = _dec2$s(_class$s = class ServiceTransactionConsistency‌ extends BeanBase {
317
+ }), _dec$u(_class$u = _dec2$u(_class$u = class ServiceTransactionConsistency‌ extends BeanBase {
286
318
  constructor(...args) {
287
319
  super(...args);
288
320
  this._commitCallbacks = [];
@@ -310,12 +342,12 @@ let ServiceTransactionConsistency‌ = (_dec$s = Service(), _dec2$s = BeanInfo({
310
342
  }
311
343
  this._commitCallbacks = [];
312
344
  }
313
- }) || _class$s) || _class$s);
345
+ }) || _class$u) || _class$u);
314
346
 
315
- var _dec$r, _dec2$r, _class$r;
316
- let ServiceTransactionFiber = (_dec$r = Service(), _dec2$r = BeanInfo({
347
+ var _dec$t, _dec2$t, _class$t;
348
+ let ServiceTransactionFiber = (_dec$t = Service(), _dec2$t = BeanInfo({
317
349
  module: "a-orm"
318
- }), _dec$r(_class$r = _dec2$r(_class$r = class ServiceTransactionFiber extends BeanBase {
350
+ }), _dec$t(_class$t = _dec2$t(_class$t = class ServiceTransactionFiber extends BeanBase {
319
351
  constructor(...args) {
320
352
  super(...args);
321
353
  this._connection = void 0;
@@ -344,12 +376,12 @@ let ServiceTransactionFiber = (_dec$r = Service(), _dec2$r = BeanInfo({
344
376
  await this._transactionConsistency.compensatesDone();
345
377
  this._connection = undefined;
346
378
  }
347
- }) || _class$r) || _class$r);
379
+ }) || _class$t) || _class$t);
348
380
 
349
- var _dec$q, _dec2$q, _class$q;
350
- let ServiceTransactionState = (_dec$q = Service(), _dec2$q = BeanInfo({
381
+ var _dec$s, _dec2$s, _class$s;
382
+ let ServiceTransactionState = (_dec$s = Service(), _dec2$s = BeanInfo({
351
383
  module: "a-orm"
352
- }), _dec$q(_class$q = _dec2$q(_class$q = class ServiceTransactionState extends BeanBase {
384
+ }), _dec$s(_class$s = _dec2$s(_class$s = class ServiceTransactionState extends BeanBase {
353
385
  constructor(...args) {
354
386
  super(...args);
355
387
  this._fibers = {};
@@ -371,12 +403,12 @@ let ServiceTransactionState = (_dec$q = Service(), _dec2$q = BeanInfo({
371
403
  const selector = this.serviceDatabase.prepareClientNameSelector(dbInfo);
372
404
  delete this._fibers[selector];
373
405
  }
374
- }) || _class$q) || _class$q);
406
+ }) || _class$s) || _class$s);
375
407
 
376
- var _dec$p, _dec2$p, _class$p;
377
- let ServiceTransactionAsyncLocalStorage = (_dec$p = Service(), _dec2$p = BeanInfo({
408
+ var _dec$r, _dec2$r, _class$r;
409
+ let ServiceTransactionAsyncLocalStorage = (_dec$r = Service(), _dec2$r = BeanInfo({
378
410
  module: "a-orm"
379
- }), _dec$p(_class$p = _dec2$p(_class$p = class ServiceTransactionAsyncLocalStorage extends BeanBase {
411
+ }), _dec$r(_class$r = _dec2$r(_class$r = class ServiceTransactionAsyncLocalStorage extends BeanBase {
380
412
  constructor(...args) {
381
413
  super(...args);
382
414
  this.transactionStorage = void 0;
@@ -397,12 +429,12 @@ let ServiceTransactionAsyncLocalStorage = (_dec$p = Service(), _dec2$p = BeanInf
397
429
  return fn();
398
430
  });
399
431
  }
400
- }) || _class$p) || _class$p);
432
+ }) || _class$r) || _class$r);
401
433
 
402
- var _dec$o, _dec2$o, _class$o;
403
- let ServiceTransaction = (_dec$o = Service(), _dec2$o = BeanInfo({
434
+ var _dec$q, _dec2$q, _class$q;
435
+ let ServiceTransaction = (_dec$q = Service(), _dec2$q = BeanInfo({
404
436
  module: "a-orm"
405
- }), _dec$o(_class$o = _dec2$o(_class$o = class ServiceTransaction extends BeanBase {
437
+ }), _dec$q(_class$q = _dec2$q(_class$q = class ServiceTransaction extends BeanBase {
406
438
  constructor(...args) {
407
439
  super(...args);
408
440
  this._db = void 0;
@@ -521,7 +553,7 @@ let ServiceTransaction = (_dec$o = Service(), _dec2$o = BeanInfo({
521
553
  }
522
554
  return res;
523
555
  }
524
- }) || _class$o) || _class$o);
556
+ }) || _class$q) || _class$q);
525
557
  function _translateTransactionOptions(options) {
526
558
  if (!options) return undefined;
527
559
  return {
@@ -530,10 +562,10 @@ function _translateTransactionOptions(options) {
530
562
  };
531
563
  }
532
564
 
533
- var _dec$n, _dec2$n, _class$n;
534
- let ServiceDb = (_dec$n = Service(), _dec2$n = BeanInfo({
565
+ var _dec$p, _dec2$p, _class$p;
566
+ let ServiceDb = (_dec$p = Service(), _dec2$p = BeanInfo({
535
567
  module: "a-orm"
536
- }), _dec$n(_class$n = _dec2$n(_class$n = class ServiceDb extends BeanBase {
568
+ }), _dec$p(_class$p = _dec2$p(_class$p = class ServiceDb extends BeanBase {
537
569
  constructor(...args) {
538
570
  super(...args);
539
571
  this._client = void 0;
@@ -588,12 +620,12 @@ let ServiceDb = (_dec$n = Service(), _dec2$n = BeanInfo({
588
620
  compensate(cb) {
589
621
  return this.transaction.compensate(cb);
590
622
  }
591
- }) || _class$n) || _class$n);
623
+ }) || _class$p) || _class$p);
592
624
 
593
- var _dec$m, _dec2$m, _class$m;
594
- let ServiceDatabaseClient = (_dec$m = Service(), _dec2$m = BeanInfo({
625
+ var _dec$o, _dec2$o, _class$o;
626
+ let ServiceDatabaseClient = (_dec$o = Service(), _dec2$o = BeanInfo({
595
627
  module: "a-orm"
596
- }), _dec$m(_class$m = _dec2$m(_class$m = class ServiceDatabaseClient extends BeanBase {
628
+ }), _dec$o(_class$o = _dec2$o(_class$o = class ServiceDatabaseClient extends BeanBase {
597
629
  constructor(...args) {
598
630
  super(...args);
599
631
  this.level = void 0;
@@ -603,6 +635,7 @@ let ServiceDatabaseClient = (_dec$m = Service(), _dec2$m = BeanInfo({
603
635
  this._knex = void 0;
604
636
  this._db = void 0;
605
637
  this._onDatabaseClientReloadCancel = void 0;
638
+ this._onDatabaseClientDisposeCancel = void 0;
606
639
  }
607
640
  get configDatabase() {
608
641
  return this.app.config.database;
@@ -618,7 +651,7 @@ let ServiceDatabaseClient = (_dec$m = Service(), _dec2$m = BeanInfo({
618
651
  this._db = this.bean._newBean(ServiceDb, this);
619
652
  // load
620
653
  this.__load(clientNameSelector, clientConfig);
621
- // event
654
+ // event: databaseClientReload
622
655
  this._onDatabaseClientReloadCancel = this.scope.event.databaseClientReload.on(async ({
623
656
  clientName,
624
657
  clientConfig
@@ -628,11 +661,23 @@ let ServiceDatabaseClient = (_dec$m = Service(), _dec2$m = BeanInfo({
628
661
  }
629
662
  await next();
630
663
  });
664
+ // event: databaseClientDispose
665
+ this._onDatabaseClientDisposeCancel = this.scope.event.databaseClientDispose.on(async ({
666
+ clientName
667
+ }, next) => {
668
+ if (clientName === this.clientName) {
669
+ await this.bean.disposeInstance(this.$beanInstanceKey);
670
+ }
671
+ await next();
672
+ });
631
673
  }
632
674
  async __dispose__() {
633
675
  this._db = undefined;
634
676
  await this.__close();
635
677
  this._onDatabaseClientReloadCancel?.();
678
+ this._onDatabaseClientDisposeCancel?.();
679
+ this._onDatabaseClientReloadCancel = undefined;
680
+ this._onDatabaseClientDisposeCancel = undefined;
636
681
  }
637
682
  __load(clientNameSelector, clientConfig) {
638
683
  // name
@@ -641,7 +686,7 @@ let ServiceDatabaseClient = (_dec$m = Service(), _dec2$m = BeanInfo({
641
686
  this.level = dbInfo.level;
642
687
  this.clientName = dbInfo.clientName;
643
688
  // config
644
- this.clientConfig = clientConfig ? deepExtend({}, clientConfig) : this.getClientConfig(this.clientName);
689
+ this.clientConfig = clientConfig ? deepExtend({}, clientConfig) : this.scope.service.database.getClientConfig(this.clientName);
645
690
  this.$loggerChild('database').debug('clientName: %s, clientConfig: %j', this.clientName, this.clientConfig);
646
691
  // knex
647
692
  this._knex = knex(this.clientConfig);
@@ -656,23 +701,6 @@ let ServiceDatabaseClient = (_dec$m = Service(), _dec2$m = BeanInfo({
656
701
  await this.__close();
657
702
  this.__load(this.clientNameSelector, clientConfig);
658
703
  }
659
- getClientConfig(clientName, original = false) {
660
- // clientConfig
661
- let clientConfig = this.configDatabase.clients[clientName];
662
- if (original) return clientConfig;
663
- // check
664
- if (!clientConfig) {
665
- throw new Error(`database config not found: ${clientName}`);
666
- }
667
- // configBaseClient
668
- const dialect = this.scope.service.database.getDialect(clientConfig.client);
669
- const configBaseClient = dialect.getConfigBase();
670
- // combine
671
- const configBase = this.configDatabase.base;
672
- clientConfig = deepExtend({}, configBase, configBaseClient, clientConfig);
673
- // ready
674
- return clientConfig;
675
- }
676
704
  getDatabaseName() {
677
705
  const connection = this.clientConfig.connection;
678
706
  return connection.database || connection.filename;
@@ -687,24 +715,27 @@ let ServiceDatabaseClient = (_dec$m = Service(), _dec2$m = BeanInfo({
687
715
  }
688
716
  return result;
689
717
  }
690
- async changeConfigAndReload(databaseName) {
718
+
719
+ // only used by startup, so no consider that workers broadcast
720
+ async changeConfigConnectionAndReload(databaseName) {
691
721
  // set databaseName
692
722
  const connDatabaseName = this._prepareDatabaseName(databaseName);
693
723
  // set config
694
724
  // * should not use this.clientConfig.connection, because password is hidden
695
- const config = this.getClientConfig(this.clientName, true);
725
+ const config = this.scope.service.database.getClientConfig(this.clientName, true);
696
726
  config.connection = Object.assign({}, config.connection, connDatabaseName);
697
727
  // only used by startup, so no consider that workers broadcast
698
728
  this.configDatabase.clients[this.clientName] = config;
699
729
  // reload
700
- await this.scope.service.database.reloadClients(this.clientName, config);
730
+ await this.scope.service.database.reloadClientsRaw(this.clientName, config);
731
+ // await this.scope.service.database.reloadClients(this.clientName, config);
701
732
  }
702
- }) || _class$m) || _class$m);
733
+ }) || _class$o) || _class$o);
703
734
 
704
- var _dec$l, _dec2$l, _class$l;
705
- let BeanDatabase = (_dec$l = Bean(), _dec2$l = BeanInfo({
735
+ var _dec$n, _dec2$n, _class$n;
736
+ let BeanDatabase = (_dec$n = Bean(), _dec2$n = BeanInfo({
706
737
  module: "a-orm"
707
- }), _dec$l(_class$l = _dec2$l(_class$l = class BeanDatabase extends BeanBase {
738
+ }), _dec$n(_class$n = _dec2$n(_class$n = class BeanDatabase extends BeanBase {
708
739
  get current() {
709
740
  return this.bean._getBean(ServiceDatabaseAsyncLocalStorage).current;
710
741
  }
@@ -734,12 +765,12 @@ let BeanDatabase = (_dec$l = Bean(), _dec2$l = BeanInfo({
734
765
  return this.bean._getBean(ServiceTransactionAsyncLocalStorage).run(fn);
735
766
  });
736
767
  }
737
- }) || _class$l) || _class$l);
768
+ }) || _class$n) || _class$n);
738
769
 
739
- var _dec$k, _dec2$k, _dec3$7, _class$k;
740
- let BeanDatabaseDialectBase = (_dec$k = Bean(), _dec2$k = Virtual(), _dec3$7 = BeanInfo({
770
+ var _dec$m, _dec2$m, _dec3$7, _class$m;
771
+ let BeanDatabaseDialectBase = (_dec$m = Bean(), _dec2$m = Virtual(), _dec3$7 = BeanInfo({
741
772
  module: "a-orm"
742
- }), _dec$k(_class$k = _dec2$k(_class$k = _dec3$7(_class$k = class BeanDatabaseDialectBase extends BeanBase {
773
+ }), _dec$m(_class$m = _dec2$m(_class$m = _dec3$7(_class$m = class BeanDatabaseDialectBase extends BeanBase {
743
774
  getConfigBase() {
744
775
  return undefined;
745
776
  }
@@ -799,7 +830,7 @@ let BeanDatabaseDialectBase = (_dec$k = Bean(), _dec2$k = Virtual(), _dec3$7 = B
799
830
  _columnTypePrefixes(type, prefixes) {
800
831
  return prefixes.some(prefix => type.includes(prefix));
801
832
  }
802
- }) || _class$k) || _class$k) || _class$k);
833
+ }) || _class$m) || _class$m) || _class$m);
803
834
 
804
835
  const OpAggrs = ['count', 'sum', 'avg', 'max', 'min'];
805
836
  const OpJoint = {
@@ -1205,69 +1236,69 @@ function _initializerDefineProperty(e, i, r, l) {
1205
1236
  });
1206
1237
  }
1207
1238
 
1208
- var _dec$j, _dec2$j, _dec3$6, _dec4$4, _dec5$1, _dec6$1, _dec7$1, _class$j, _descriptor$4, _descriptor2$2, _descriptor3$1;
1239
+ var _dec$l, _dec2$l, _dec3$6, _dec4$4, _dec5$1, _dec6$1, _dec7$1, _class$l, _descriptor$4, _descriptor2$2, _descriptor3$1;
1209
1240
  const app$1 = useApp();
1210
1241
  const ormConfig$1 = app$1.util.getModuleConfigRaw('a-orm');
1211
1242
  const ordersDefault = ormConfig$1?.rest?.query?.orders?.default ?? 'createdAt,desc';
1212
- let DtoQueryBase = (_dec$j = Api.field(v.optional(), v.array(String, {
1243
+ let DtoQueryBase = (_dec$l = Api.field(v.optional(), v.array(String, {
1213
1244
  separator: ','
1214
- })), _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 {
1245
+ })), _dec2$l = 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$l = class DtoQueryBase {
1215
1246
  constructor() {
1216
1247
  _initializerDefineProperty(this, "columns", _descriptor$4, this);
1217
1248
  _initializerDefineProperty(this, "where", _descriptor2$2, this);
1218
1249
  _initializerDefineProperty(this, "orders", _descriptor3$1, this);
1219
1250
  }
1220
- }, _descriptor$4 = _applyDecoratedDescriptor(_class$j.prototype, "columns", [_dec$j, _dec2$j], {
1251
+ }, _descriptor$4 = _applyDecoratedDescriptor(_class$l.prototype, "columns", [_dec$l, _dec2$l], {
1221
1252
  configurable: true,
1222
1253
  enumerable: true,
1223
1254
  writable: true,
1224
1255
  initializer: null
1225
- }), _descriptor2$2 = _applyDecoratedDescriptor(_class$j.prototype, "where", [_dec3$6, _dec4$4], {
1256
+ }), _descriptor2$2 = _applyDecoratedDescriptor(_class$l.prototype, "where", [_dec3$6, _dec4$4], {
1226
1257
  configurable: true,
1227
1258
  enumerable: true,
1228
1259
  writable: true,
1229
1260
  initializer: null
1230
- }), _descriptor3$1 = _applyDecoratedDescriptor(_class$j.prototype, "orders", [_dec5$1, _dec6$1, _dec7$1], {
1261
+ }), _descriptor3$1 = _applyDecoratedDescriptor(_class$l.prototype, "orders", [_dec5$1, _dec6$1, _dec7$1], {
1231
1262
  configurable: true,
1232
1263
  enumerable: true,
1233
1264
  writable: true,
1234
1265
  initializer: null
1235
- }), _class$j);
1266
+ }), _class$l);
1236
1267
 
1237
- var _dec$i, _dec2$i, _dec3$5, _dec4$3, _class$i, _descriptor$3, _descriptor2$1;
1268
+ var _dec$k, _dec2$k, _dec3$5, _dec4$3, _class$k, _descriptor$3, _descriptor2$1;
1238
1269
  const app = useApp();
1239
1270
  const ormConfig = app.util.getModuleConfigRaw('a-orm');
1240
1271
  const pageSizeDefault = ormConfig?.rest?.query?.pageSize?.default ?? 20;
1241
1272
  const pageSizeMax = ormConfig?.rest?.query?.pageSize?.max ?? 100;
1242
- 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 {
1273
+ let DtoQueryPageBase = (_dec$k = Api.field(z.number().min(1).default(1)), _dec2$k = 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$k = class DtoQueryPageBase extends DtoQueryBase {
1243
1274
  constructor(...args) {
1244
1275
  super(...args);
1245
1276
  _initializerDefineProperty(this, "pageNo", _descriptor$3, this);
1246
1277
  _initializerDefineProperty(this, "pageSize", _descriptor2$1, this);
1247
1278
  }
1248
- }, _descriptor$3 = _applyDecoratedDescriptor(_class$i.prototype, "pageNo", [_dec$i, _dec2$i], {
1279
+ }, _descriptor$3 = _applyDecoratedDescriptor(_class$k.prototype, "pageNo", [_dec$k, _dec2$k], {
1249
1280
  configurable: true,
1250
1281
  enumerable: true,
1251
1282
  writable: true,
1252
1283
  initializer: null
1253
- }), _descriptor2$1 = _applyDecoratedDescriptor(_class$i.prototype, "pageSize", [_dec3$5, _dec4$3], {
1284
+ }), _descriptor2$1 = _applyDecoratedDescriptor(_class$k.prototype, "pageSize", [_dec3$5, _dec4$3], {
1254
1285
  configurable: true,
1255
1286
  enumerable: true,
1256
1287
  writable: true,
1257
1288
  initializer: null
1258
- }), _class$i);
1289
+ }), _class$k);
1259
1290
 
1260
1291
  const SymbolKeyFieldsMore = Symbol('$fieldsMore');
1261
1292
 
1262
1293
  class EntityBaseEmpty {}
1263
1294
 
1264
- var _dec$h, _dec2$h, _dec3$4, _dec4$2, _dec5, _dec6, _dec7, _dec8, _class$h, _descriptor$2, _descriptor2, _descriptor3, _descriptor4;
1265
- let EntityBaseInner = (_dec$h = Api.field(v.openapi({
1295
+ var _dec$j, _dec2$j, _dec3$4, _dec4$2, _dec5, _dec6, _dec7, _dec8, _class$j, _descriptor$2, _descriptor2, _descriptor3, _descriptor4;
1296
+ let EntityBaseInner = (_dec$j = Api.field(v.openapi({
1266
1297
  title: $locale('CreatedAt'),
1267
1298
  rest: {
1268
1299
  order: OrderMaxBase - 2
1269
1300
  }
1270
- })), _dec2$h = Reflect.metadata("design:type", typeof Date === "undefined" ? Object : Date), _dec3$4 = Api.field(v.openapi({
1301
+ })), _dec2$j = Reflect.metadata("design:type", typeof Date === "undefined" ? Object : Date), _dec3$4 = Api.field(v.openapi({
1271
1302
  title: $locale('UpdatedAt'),
1272
1303
  rest: {
1273
1304
  order: OrderMaxBase - 1
@@ -1282,7 +1313,7 @@ let EntityBaseInner = (_dec$h = Api.field(v.openapi({
1282
1313
  rest: {
1283
1314
  visible: false
1284
1315
  }
1285
- }), v.default(0)), _dec8 = Reflect.metadata("design:type", Number), _class$h = class EntityBaseInner extends EntityBaseEmpty {
1316
+ }), v.default(0)), _dec8 = Reflect.metadata("design:type", Number), _class$j = class EntityBaseInner extends EntityBaseEmpty {
1286
1317
  constructor(...args) {
1287
1318
  super(...args);
1288
1319
  _initializerDefineProperty(this, "createdAt", _descriptor$2, this);
@@ -1290,63 +1321,63 @@ let EntityBaseInner = (_dec$h = Api.field(v.openapi({
1290
1321
  _initializerDefineProperty(this, "deleted", _descriptor3, this);
1291
1322
  _initializerDefineProperty(this, "iid", _descriptor4, this);
1292
1323
  }
1293
- }, _descriptor$2 = _applyDecoratedDescriptor(_class$h.prototype, "createdAt", [_dec$h, _dec2$h], {
1324
+ }, _descriptor$2 = _applyDecoratedDescriptor(_class$j.prototype, "createdAt", [_dec$j, _dec2$j], {
1294
1325
  configurable: true,
1295
1326
  enumerable: true,
1296
1327
  writable: true,
1297
1328
  initializer: null
1298
- }), _descriptor2 = _applyDecoratedDescriptor(_class$h.prototype, "updatedAt", [_dec3$4, _dec4$2], {
1329
+ }), _descriptor2 = _applyDecoratedDescriptor(_class$j.prototype, "updatedAt", [_dec3$4, _dec4$2], {
1299
1330
  configurable: true,
1300
1331
  enumerable: true,
1301
1332
  writable: true,
1302
1333
  initializer: null
1303
- }), _descriptor3 = _applyDecoratedDescriptor(_class$h.prototype, "deleted", [_dec5, _dec6], {
1334
+ }), _descriptor3 = _applyDecoratedDescriptor(_class$j.prototype, "deleted", [_dec5, _dec6], {
1304
1335
  configurable: true,
1305
1336
  enumerable: true,
1306
1337
  writable: true,
1307
1338
  initializer: null
1308
- }), _descriptor4 = _applyDecoratedDescriptor(_class$h.prototype, "iid", [_dec7, _dec8], {
1339
+ }), _descriptor4 = _applyDecoratedDescriptor(_class$j.prototype, "iid", [_dec7, _dec8], {
1309
1340
  configurable: true,
1310
1341
  enumerable: true,
1311
1342
  writable: true,
1312
1343
  initializer: null
1313
- }), _class$h);
1344
+ }), _class$j);
1314
1345
 
1315
- var _dec$g, _dec2$g, _class$g, _descriptor$1;
1316
- let EntityBase = (_dec$g = Api.field(v.openapi({
1346
+ var _dec$i, _dec2$i, _class$i, _descriptor$1;
1347
+ let EntityBase = (_dec$i = Api.field(v.openapi({
1317
1348
  title: $locale('TableIdentity'),
1318
1349
  rest: {
1319
1350
  order: OrderCoreBase + 1
1320
1351
  }
1321
- }), v.tableIdentity()), _dec2$g = Reflect.metadata("design:type", typeof TableIdentity === "undefined" ? Object : TableIdentity), _class$g = class EntityBase extends EntityBaseInner {
1352
+ }), v.tableIdentity()), _dec2$i = Reflect.metadata("design:type", typeof TableIdentity === "undefined" ? Object : TableIdentity), _class$i = class EntityBase extends EntityBaseInner {
1322
1353
  constructor(...args) {
1323
1354
  super(...args);
1324
1355
  _initializerDefineProperty(this, "id", _descriptor$1, this);
1325
1356
  }
1326
- }, _descriptor$1 = _applyDecoratedDescriptor(_class$g.prototype, "id", [_dec$g, _dec2$g], {
1357
+ }, _descriptor$1 = _applyDecoratedDescriptor(_class$i.prototype, "id", [_dec$i, _dec2$i], {
1327
1358
  configurable: true,
1328
1359
  enumerable: true,
1329
1360
  writable: true,
1330
1361
  initializer: null
1331
- }), _class$g);
1362
+ }), _class$i);
1332
1363
 
1333
- var _dec$f, _dec2$f, _class$f, _descriptor;
1334
- let EntityBaseSimple = (_dec$f = Api.field(v.openapi({
1364
+ var _dec$h, _dec2$h, _class$h, _descriptor;
1365
+ let EntityBaseSimple = (_dec$h = Api.field(v.openapi({
1335
1366
  title: $locale('TableIdentity'),
1336
1367
  rest: {
1337
1368
  order: OrderCoreBase + 1
1338
1369
  }
1339
- })), _dec2$f = Reflect.metadata("design:type", Number), _class$f = class EntityBaseSimple extends EntityBaseInner {
1370
+ })), _dec2$h = Reflect.metadata("design:type", Number), _class$h = class EntityBaseSimple extends EntityBaseInner {
1340
1371
  constructor(...args) {
1341
1372
  super(...args);
1342
1373
  _initializerDefineProperty(this, "id", _descriptor, this);
1343
1374
  }
1344
- }, _descriptor = _applyDecoratedDescriptor(_class$f.prototype, "id", [_dec$f, _dec2$f], {
1375
+ }, _descriptor = _applyDecoratedDescriptor(_class$h.prototype, "id", [_dec$h, _dec2$h], {
1345
1376
  configurable: true,
1346
1377
  enumerable: true,
1347
1378
  writable: true,
1348
1379
  initializer: null
1349
- }), _class$f);
1380
+ }), _class$h);
1350
1381
 
1351
1382
  const SymbolKeyEntity = Symbol('$entity');
1352
1383
  const SymbolKeyEntityMeta = Symbol('$entityMeta');
@@ -2139,10 +2170,10 @@ class BeanModelCrudTable extends BeanModelCrudInner {
2139
2170
  }
2140
2171
  }
2141
2172
 
2142
- var _dec$e, _dec2$e, _dec3$3, _class$e;
2143
- let BeanModel = (_dec$e = Bean(), _dec2$e = Virtual(), _dec3$3 = BeanInfo({
2173
+ var _dec$g, _dec2$g, _dec3$3, _class$g;
2174
+ let BeanModel = (_dec$g = Bean(), _dec2$g = Virtual(), _dec3$3 = BeanInfo({
2144
2175
  module: "a-orm"
2145
- }), _dec$e(_class$e = _dec2$e(_class$e = _dec3$3(_class$e = class BeanModel extends BeanModelCrudTable {}) || _class$e) || _class$e) || _class$e);
2176
+ }), _dec$g(_class$g = _dec2$g(_class$g = _dec3$3(_class$g = class BeanModel extends BeanModelCrudTable {}) || _class$g) || _class$g) || _class$g);
2146
2177
 
2147
2178
  const SymbolCacheOptions = Symbol('SymbolCacheOptions');
2148
2179
  const SymbolCacheEnabled = Symbol('SymbolCacheEnabled');
@@ -2217,10 +2248,10 @@ class ModelCacheBase extends BeanBase {
2217
2248
  }
2218
2249
  }
2219
2250
 
2220
- var _dec$d, _dec2$d, _class$d;
2221
- let ServiceCacheEntity = (_dec$d = Service(), _dec2$d = BeanInfo({
2251
+ var _dec$f, _dec2$f, _class$f;
2252
+ let ServiceCacheEntity = (_dec$f = Service(), _dec2$f = BeanInfo({
2222
2253
  module: "a-orm"
2223
- }), _dec$d(_class$d = _dec2$d(_class$d = class ServiceCacheEntity extends ModelCacheBase {
2254
+ }), _dec$f(_class$f = _dec2$f(_class$f = class ServiceCacheEntity extends ModelCacheBase {
2224
2255
  __init__(model) {
2225
2256
  super.__init__(model, 'entity');
2226
2257
  }
@@ -2243,12 +2274,12 @@ let ServiceCacheEntity = (_dec$d = Service(), _dec2$d = BeanInfo({
2243
2274
  get keysAux() {
2244
2275
  return this._model.options.cache?.keysAux;
2245
2276
  }
2246
- }) || _class$d) || _class$d);
2277
+ }) || _class$f) || _class$f);
2247
2278
 
2248
- var _dec$c, _dec2$c, _class$c;
2249
- let ServiceCacheQuery = (_dec$c = Service(), _dec2$c = BeanInfo({
2279
+ var _dec$e, _dec2$e, _class$e;
2280
+ let ServiceCacheQuery = (_dec$e = Service(), _dec2$e = BeanInfo({
2250
2281
  module: "a-orm"
2251
- }), _dec$c(_class$c = _dec2$c(_class$c = class ServiceCacheQuery extends ModelCacheBase {
2282
+ }), _dec$e(_class$e = _dec2$e(_class$e = class ServiceCacheQuery extends ModelCacheBase {
2252
2283
  __init__(model) {
2253
2284
  super.__init__(model, 'query');
2254
2285
  }
@@ -2258,7 +2289,7 @@ let ServiceCacheQuery = (_dec$c = Service(), _dec2$c = BeanInfo({
2258
2289
  const cache = this.getInstance(table);
2259
2290
  await cache.clear();
2260
2291
  }
2261
- }) || _class$c) || _class$c);
2292
+ }) || _class$e) || _class$e);
2262
2293
 
2263
2294
  function handleRelationsCollection(relationsStatic, includeWrapper) {
2264
2295
  // collect
@@ -2303,10 +2334,10 @@ function handleRelationsCollection(relationsStatic, includeWrapper) {
2303
2334
  return relations;
2304
2335
  }
2305
2336
 
2306
- var _dec$b, _dec2$b, _class$b;
2307
- let ServiceRelations = (_dec$b = Service(), _dec2$b = BeanInfo({
2337
+ var _dec$d, _dec2$d, _class$d;
2338
+ let ServiceRelations = (_dec$d = Service(), _dec2$d = BeanInfo({
2308
2339
  module: "a-orm"
2309
- }), _dec$b(_class$b = _dec2$b(_class$b = class ServiceRelations extends BeanBase {
2340
+ }), _dec$d(_class$d = _dec2$d(_class$d = class ServiceRelations extends BeanBase {
2310
2341
  constructor(...args) {
2311
2342
  super(...args);
2312
2343
  this._model = void 0;
@@ -2838,7 +2869,7 @@ let ServiceRelations = (_dec$b = Service(), _dec2$b = BeanInfo({
2838
2869
  handleRelationsCollection(includeWrapper) {
2839
2870
  return handleRelationsCollection(this._model.options.relations, includeWrapper);
2840
2871
  }
2841
- }) || _class$b) || _class$b);
2872
+ }) || _class$d) || _class$d);
2842
2873
 
2843
2874
  class BeanModelCrud extends BeanModelCrudInner {
2844
2875
  async mget(ids, options) {
@@ -3499,16 +3530,16 @@ class BeanModelCache extends BeanModelCrud {
3499
3530
  }
3500
3531
  }
3501
3532
 
3502
- var _dec$a, _dec2$a, _dec3$2, _class$a;
3503
- let BeanModelBase = (_dec$a = Bean(), _dec2$a = Virtual(), _dec3$2 = BeanInfo({
3533
+ var _dec$c, _dec2$c, _dec3$2, _class$c;
3534
+ let BeanModelBase = (_dec$c = Bean(), _dec2$c = Virtual(), _dec3$2 = BeanInfo({
3504
3535
  module: "a-orm"
3505
- }), _dec$a(_class$a = _dec2$a(_class$a = _dec3$2(_class$a = class BeanModelBase extends BeanModelCache {}) || _class$a) || _class$a) || _class$a);
3536
+ }), _dec$c(_class$c = _dec2$c(_class$c = _dec3$2(_class$c = class BeanModelBase extends BeanModelCache {}) || _class$c) || _class$c) || _class$c);
3506
3537
 
3507
- var _dec$9, _dec2$9, _dec3$1, _dec4$1, _class$9;
3538
+ var _dec$b, _dec2$b, _dec3$1, _dec4$1, _class$b;
3508
3539
  const SymbolModuleScope$1 = Symbol('SymbolModuleScope');
3509
- let ServiceEntityResolver = (_dec$9 = Service(), _dec2$9 = BeanInfo({
3540
+ let ServiceEntityResolver = (_dec$b = Service(), _dec2$b = BeanInfo({
3510
3541
  module: "a-orm"
3511
- }), _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 {
3542
+ }), _dec3$1 = Reflect.metadata("design:type", Function), _dec4$1 = Reflect.metadata("design:paramtypes", [String]), _dec$b(_class$b = _dec2$b(_class$b = _dec3$1(_class$b = _dec4$1(_class$b = class ServiceEntityResolver extends BeanBase {
3512
3543
  constructor(moduleScope) {
3513
3544
  super();
3514
3545
  this[SymbolModuleScope$1] = void 0;
@@ -3523,13 +3554,13 @@ let ServiceEntityResolver = (_dec$9 = Service(), _dec2$9 = BeanInfo({
3523
3554
  }
3524
3555
  return this.__instances[prop];
3525
3556
  }
3526
- }) || _class$9) || _class$9) || _class$9) || _class$9);
3557
+ }) || _class$b) || _class$b) || _class$b) || _class$b);
3527
3558
 
3528
- var _dec$8, _dec2$8, _dec3, _dec4, _class$8;
3559
+ var _dec$a, _dec2$a, _dec3, _dec4, _class$a;
3529
3560
  const SymbolModuleScope = Symbol('SymbolModuleScope');
3530
- let ServiceModelResolver = (_dec$8 = Service(), _dec2$8 = BeanInfo({
3561
+ let ServiceModelResolver = (_dec$a = Service(), _dec2$a = BeanInfo({
3531
3562
  module: "a-orm"
3532
- }), _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 {
3563
+ }), _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [String]), _dec$a(_class$a = _dec2$a(_class$a = _dec3(_class$a = _dec4(_class$a = class ServiceModelResolver extends BeanBase {
3533
3564
  constructor(moduleScope) {
3534
3565
  super();
3535
3566
  this[SymbolModuleScope] = void 0;
@@ -3539,12 +3570,12 @@ let ServiceModelResolver = (_dec$8 = Service(), _dec2$8 = BeanInfo({
3539
3570
  const beanFullName = `${this[SymbolModuleScope]}.model.${prop}`;
3540
3571
  return this.bean._getBean(beanFullName);
3541
3572
  }
3542
- }) || _class$8) || _class$8) || _class$8) || _class$8);
3573
+ }) || _class$a) || _class$a) || _class$a) || _class$a);
3543
3574
 
3544
- var _dec$7, _dec2$7, _class$7;
3545
- let BroadcastColumnsClear = (_dec$7 = Broadcast(), _dec2$7 = BeanInfo({
3575
+ var _dec$9, _dec2$9, _class$9;
3576
+ let BroadcastColumnsClear = (_dec$9 = Broadcast(), _dec2$9 = BeanInfo({
3546
3577
  module: "a-orm"
3547
- }), _dec$7(_class$7 = _dec2$7(_class$7 = class BroadcastColumnsClear extends BeanBroadcastBase {
3578
+ }), _dec$9(_class$9 = _dec2$9(_class$9 = class BroadcastColumnsClear extends BeanBroadcastBase {
3548
3579
  async execute(data, isEmitter) {
3549
3580
  const {
3550
3581
  clientName,
@@ -3554,12 +3585,26 @@ let BroadcastColumnsClear = (_dec$7 = Broadcast(), _dec2$7 = BeanInfo({
3554
3585
  await cast(this.scope.service.database).__columnsClearRaw(clientName, tableName);
3555
3586
  }
3556
3587
  }
3557
- }) || _class$7) || _class$7);
3588
+ }) || _class$9) || _class$9);
3558
3589
 
3559
- var _dec$6, _dec2$6, _class$6;
3560
- let BroadcastDatabaseClientReload = (_dec$6 = Broadcast(), _dec2$6 = BeanInfo({
3590
+ var _dec$8, _dec2$8, _class$8;
3591
+ let BroadcastDatabaseClientDispose = (_dec$8 = Broadcast(), _dec2$8 = BeanInfo({
3561
3592
  module: "a-orm"
3562
- }), _dec$6(_class$6 = _dec2$6(_class$6 = class BroadcastDatabaseClientReload extends BeanBroadcastBase {
3593
+ }), _dec$8(_class$8 = _dec2$8(_class$8 = class BroadcastDatabaseClientDispose extends BeanBroadcastBase {
3594
+ async execute(data, isEmitter) {
3595
+ const {
3596
+ clientName
3597
+ } = data;
3598
+ if (!isEmitter) {
3599
+ await cast(this.scope.service.database).disposeClientsRaw(clientName);
3600
+ }
3601
+ }
3602
+ }) || _class$8) || _class$8);
3603
+
3604
+ var _dec$7, _dec2$7, _class$7;
3605
+ let BroadcastDatabaseClientReload = (_dec$7 = Broadcast(), _dec2$7 = BeanInfo({
3606
+ module: "a-orm"
3607
+ }), _dec$7(_class$7 = _dec2$7(_class$7 = class BroadcastDatabaseClientReload extends BeanBroadcastBase {
3563
3608
  async execute(data, isEmitter) {
3564
3609
  const {
3565
3610
  clientName,
@@ -3567,20 +3612,25 @@ let BroadcastDatabaseClientReload = (_dec$6 = Broadcast(), _dec2$6 = BeanInfo({
3567
3612
  extraData
3568
3613
  } = data;
3569
3614
  if (!isEmitter) {
3570
- await cast(this.scope.service.database).__reloadAllClientsRaw(clientName, clientConfig, extraData);
3615
+ await cast(this.scope.service.database).reloadClientsRaw(clientName, clientConfig, extraData);
3571
3616
  }
3572
3617
  }
3573
- }) || _class$6) || _class$6);
3618
+ }) || _class$7) || _class$7);
3619
+
3620
+ var _dec$6, _dec2$6, _class$6;
3621
+ let EventClientNameReal = (_dec$6 = Event(), _dec2$6 = BeanInfo({
3622
+ module: "a-orm"
3623
+ }), _dec$6(_class$6 = _dec2$6(_class$6 = class EventClientNameReal extends BeanEventBase {}) || _class$6) || _class$6);
3574
3624
 
3575
3625
  var _dec$5, _dec2$5, _class$5;
3576
- let EventClientNameReal = (_dec$5 = Event(), _dec2$5 = BeanInfo({
3626
+ let EventColumnsClear = (_dec$5 = Event(), _dec2$5 = BeanInfo({
3577
3627
  module: "a-orm"
3578
- }), _dec$5(_class$5 = _dec2$5(_class$5 = class EventClientNameReal extends BeanEventBase {}) || _class$5) || _class$5);
3628
+ }), _dec$5(_class$5 = _dec2$5(_class$5 = class EventColumnsClear extends BeanEventBase {}) || _class$5) || _class$5);
3579
3629
 
3580
3630
  var _dec$4, _dec2$4, _class$4;
3581
- let EventColumnsClear = (_dec$4 = Event(), _dec2$4 = BeanInfo({
3631
+ let EventDatabaseClientDispose = (_dec$4 = Event(), _dec2$4 = BeanInfo({
3582
3632
  module: "a-orm"
3583
- }), _dec$4(_class$4 = _dec2$4(_class$4 = class EventColumnsClear extends BeanEventBase {}) || _class$4) || _class$4);
3633
+ }), _dec$4(_class$4 = _dec2$4(_class$4 = class EventDatabaseClientDispose extends BeanEventBase {}) || _class$4) || _class$4);
3584
3634
 
3585
3635
  var _dec$3, _dec2$3, _class$3;
3586
3636
  let EventDatabaseClientReload = (_dec$3 = Event(), _dec2$3 = BeanInfo({
@@ -4344,4 +4394,4 @@ const $relationMutate = {
4344
4394
  belongsToMany
4345
4395
  };
4346
4396
 
4347
- 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 };
4397
+ export { $Dto, $column, $columns, $columnsAll, $locale, $relation, $relationDynamic, $relationMutate, $tableColumns, $tableComments, $tableDefaults, $tableName, AopMethodTransaction, BeanDatabase, BeanDatabaseDialectBase, BeanModel, BeanModelBase, BeanModelMeta, BroadcastColumnsClear, BroadcastDatabaseClientDispose, BroadcastDatabaseClientReload, Database, DatabaseDialect, DtoQueryBase, DtoQueryPageBase, Entity, EntityBase, EntityBaseEmpty, EntityBaseInner, EntityBaseSimple, Errors, EventClientNameReal, EventColumnsClear, EventDatabaseClientDispose, 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 };
@@ -3,7 +3,9 @@ import type { ConfigDatabaseClient } from '../types/config.ts';
3
3
  import type { IDatabaseClientDialectRecord, IDatabaseClientRecord, IDbInfo } from '../types/database.ts';
4
4
  import { BeanBase } from 'vona';
5
5
  export declare class ServiceDatabase extends BeanBase {
6
+ get configDatabase(): import("../types/config.ts").ConfigDatabase;
6
7
  getDialect(client: keyof IDatabaseClientDialectRecord): BeanDatabaseDialectBase;
8
+ getClientConfig(clientName: keyof IDatabaseClientRecord, original?: boolean): ConfigDatabaseClient;
7
9
  prepareDbInfo(dbInfoOrClientName?: Partial<IDbInfo> | keyof IDatabaseClientRecord): IDbInfo;
8
10
  prepareClientNameSelector(dbInfo: IDbInfo): string;
9
11
  parseClientNameSelector(clientNameSelector: string): IDbInfo;
@@ -13,5 +15,7 @@ export declare class ServiceDatabase extends BeanBase {
13
15
  columnsClear(clientName?: keyof IDatabaseClientRecord, tableName?: string): void;
14
16
  private __columnsClearRaw;
15
17
  reloadClients(clientName?: keyof IDatabaseClientRecord, clientConfig?: ConfigDatabaseClient, extraData?: any): Promise<void>;
16
- private __reloadAllClientsRaw;
18
+ reloadClientsRaw(clientName?: keyof IDatabaseClientRecord, clientConfig?: ConfigDatabaseClient, extraData?: any): Promise<void>;
19
+ disposeClients(clientName?: keyof IDatabaseClientRecord): Promise<void>;
20
+ disposeClientsRaw(clientName?: keyof IDatabaseClientRecord): Promise<void>;
17
21
  }
@@ -15,6 +15,7 @@ export declare class ServiceDatabaseClient extends BeanBase {
15
15
  private _knex;
16
16
  private _db;
17
17
  private _onDatabaseClientReloadCancel?;
18
+ private _onDatabaseClientDisposeCancel?;
18
19
  get configDatabase(): import("../types/config.ts").ConfigDatabase;
19
20
  get connection(): Knex;
20
21
  get db(): ServiceDb;
@@ -23,8 +24,7 @@ export declare class ServiceDatabaseClient extends BeanBase {
23
24
  private __load;
24
25
  private __close;
25
26
  reload(clientConfig?: ConfigDatabaseClient): Promise<void>;
26
- getClientConfig(clientName: keyof IDatabaseClientRecord, original?: boolean): ConfigDatabaseClient;
27
27
  getDatabaseName(): string;
28
28
  private _prepareDatabaseName;
29
- changeConfigAndReload(databaseName: string): Promise<void>;
29
+ changeConfigConnectionAndReload(databaseName: string): Promise<void>;
30
30
  }
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.57",
4
+ "version": "5.0.58",
5
5
  "title": "a-orm",
6
6
  "vonaModule": {
7
7
  "capabilities": {