vona-module-a-orm 5.0.57 → 5.0.59

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