oak-backend-base 4.1.25 → 4.1.26

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.
@@ -1,6 +1,5 @@
1
1
  import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
2
2
  import { AppLoader as GeneralAppLoader, Trigger, EntityDict, Watcher, OpRecord, FreeTimer, OperationResult } from "oak-domain/lib/types";
3
- import { DbStore } from "./DbStore";
4
3
  import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
5
4
  import { IncomingHttpHeaders, IncomingMessage } from 'http';
6
5
  import { Namespace } from 'socket.io';
@@ -8,13 +7,14 @@ import DataSubscriber from './cluster/DataSubscriber';
8
7
  import Synchronizer from './Synchronizer';
9
8
  import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
10
9
  import { InternalErrorHandler } from './types';
10
+ import { AppDbStore } from './DbStore';
11
11
  export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>> extends GeneralAppLoader<ED, Cxt> {
12
- protected dbStore: DbStore<ED, Cxt>;
12
+ protected dbStore: AppDbStore<ED, Cxt>;
13
13
  private aspectDict;
14
14
  private externalDependencies;
15
15
  protected dataSubscriber?: DataSubscriber<ED, Cxt>;
16
16
  protected synchronizer?: Synchronizer<ED, Cxt>;
17
- protected contextBuilder: (store: DbStore<ED, Cxt>) => Cxt;
17
+ protected contextBuilder: (store: AppDbStore<ED, Cxt>) => Cxt;
18
18
  private nsSocket?;
19
19
  private watcherTimerId?;
20
20
  private scheduledJobs;
@@ -47,7 +47,7 @@ export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt exten
47
47
  message?: string;
48
48
  }>;
49
49
  initialize(ifExists?: 'drop' | 'omit' | 'dropIfNotStatic'): Promise<void>;
50
- getStore(): DbStore<ED, Cxt>;
50
+ getStore(): AppDbStore<ED, Cxt>;
51
51
  getEndpoints(prefix: string): [string, "post" | "get" | "put" | "delete", string, (params: Record<string, string>, headers: IncomingHttpHeaders, req: IncomingMessage, body?: any) => Promise<{
52
52
  headers?: Record<string, string | string[]>;
53
53
  data: any;
package/lib/AppLoader.js CHANGED
@@ -9,7 +9,6 @@ const IntrinsicLogics_1 = require("oak-domain/lib/store/IntrinsicLogics");
9
9
  const lodash_1 = require("oak-domain/lib/utils/lodash");
10
10
  const uuid_1 = require("oak-domain/lib/utils/uuid");
11
11
  const types_1 = require("oak-domain/lib/types");
12
- const DbStore_1 = require("./DbStore");
13
12
  const index_1 = tslib_1.__importStar(require("oak-common-aspect/lib/index"));
14
13
  const assert_1 = tslib_1.__importDefault(require("assert"));
15
14
  const dependencyBuilder_1 = require("oak-domain/lib/compiler/dependencyBuilder");
@@ -18,6 +17,8 @@ const env_1 = require("./cluster/env");
18
17
  const Synchronizer_1 = tslib_1.__importDefault(require("./Synchronizer"));
19
18
  const i18n_1 = tslib_1.__importDefault(require("oak-domain/lib/data/i18n"));
20
19
  const requirePrj_1 = tslib_1.__importDefault(require("./utils/requirePrj"));
20
+ const dbPriority_1 = require("./utils/dbPriority");
21
+ const DbStore_1 = require("./DbStore");
21
22
  class AppLoader extends types_1.AppLoader {
22
23
  dbStore;
23
24
  aspectDict;
@@ -95,8 +96,7 @@ class AppLoader extends types_1.AppLoader {
95
96
  * 后台启动的configuration,统一放在这里读取
96
97
  */
97
98
  getConfiguration() {
98
- const dbConfigFile = (0, path_1.join)(this.path, 'configuration', 'mysql.json');
99
- const dbConfig = require(dbConfigFile);
99
+ const dbConfig = (0, dbPriority_1.getDbConfig)(this.path);
100
100
  const syncConfigFile = (0, path_1.join)(this.path, 'lib', 'configuration', 'sync.js');
101
101
  const syncConfigs = (0, fs_1.existsSync)(syncConfigFile) && require(syncConfigFile).default;
102
102
  return {
@@ -112,7 +112,7 @@ class AppLoader extends types_1.AppLoader {
112
112
  this.externalDependencies = depGraph.ascOrder;
113
113
  const { authDeduceRelationMap, selectFreeEntities, updateFreeDict } = this.requireSth('lib/configuration/relation');
114
114
  this.aspectDict = Object.assign({}, index_1.default, this.requireSth('lib/aspects/index'));
115
- this.dbStore = new DbStore_1.DbStore(storageSchema, () => this.contextBuilder(this.dbStore), dbConfig, authDeduceRelationMap, selectFreeEntities, updateFreeDict);
115
+ this.dbStore = (0, DbStore_1.createDbStore)(storageSchema, () => this.contextBuilder(this.dbStore), dbConfig, authDeduceRelationMap, selectFreeEntities, updateFreeDict);
116
116
  if (nsSubscribe) {
117
117
  this.dataSubscriber = new DataSubscriber_1.default(nsSubscribe, nsServer);
118
118
  }
@@ -290,7 +290,7 @@ class AppLoader extends types_1.AppLoader {
290
290
  }
291
291
  }
292
292
  }
293
- await this.dbStore.disconnect();
293
+ // await this.dbStore.disconnect(); // 不需要马上断开连接,在initialize后可能还会有操作,unmount时会断开
294
294
  }
295
295
  getStore() {
296
296
  return this.dbStore;
@@ -484,7 +484,7 @@ class AppLoader extends types_1.AppLoader {
484
484
  try {
485
485
  const result = await this.execFreeTimer(timer, context);
486
486
  if (result) {
487
- console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`);
487
+ console.log(`定时器【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是`, result);
488
488
  }
489
489
  await context.commit();
490
490
  }
@@ -536,7 +536,7 @@ class AppLoader extends types_1.AppLoader {
536
536
  socket: this.nsSocket,
537
537
  contextBuilder: () => this.makeContext(),
538
538
  });
539
- console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`);
539
+ console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是`, result);
540
540
  await context.commit();
541
541
  }
542
542
  catch (err) {
@@ -571,7 +571,7 @@ class AppLoader extends types_1.AppLoader {
571
571
  socket: this.nsSocket,
572
572
  contextBuilder: () => this.makeContext(),
573
573
  });
574
- console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`);
574
+ console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是`, result);
575
575
  await context.commit();
576
576
  }
577
577
  catch (err) {
package/lib/DbStore.d.ts CHANGED
@@ -1,22 +1,16 @@
1
- import { MysqlStore, MySqlSelectOption, MysqlOperateOption } from 'oak-db';
2
- import { EntityDict, StorageSchema, Trigger, Checker, SelectOption, SelectFreeEntities, UpdateFreeDict, AuthDeduceRelationMap, VolatileTrigger, OperateOption } from 'oak-domain/lib/types';
1
+ import { DbConfiguration } from 'oak-db/src/types/configuration';
2
+ import { EntityDict, StorageSchema, Trigger, Checker, SelectFreeEntities, UpdateFreeDict, AuthDeduceRelationMap, VolatileTrigger, OperateOption } from 'oak-domain/lib/types';
3
3
  import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
4
- import { MySQLConfiguration } from 'oak-db/lib/MySQL/types/Configuration';
5
4
  import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
6
- import { AsyncRowStore, AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
7
- export declare class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>> extends MysqlStore<ED, Cxt> implements AsyncRowStore<ED, Cxt> {
8
- private executor;
9
- private relationAuth;
10
- constructor(storageSchema: StorageSchema<ED>, contextBuilder: () => Cxt, mysqlConfiguration: MySQLConfiguration, authDeduceRelationMap: AuthDeduceRelationMap<ED>, selectFreeEntities?: SelectFreeEntities<ED>, updateFreeDict?: UpdateFreeDict<ED>, onVolatileTrigger?: <T extends keyof ED>(entity: T, trigger: VolatileTrigger<ED, T, Cxt>, ids: string[], cxtStr: string, option: OperateOption) => Promise<void>);
11
- checkRelationAsync<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, operation: Omit<ED[T]["Operation"] | ED[T]["Selection"], "id">, context: Cxt): Promise<void>;
12
- protected cascadeUpdateAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: MysqlOperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
13
- operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: MysqlOperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
14
- select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: MySqlSelectOption): Promise<Partial<ED[T]["Schema"]>[]>;
15
- count<T extends keyof ED>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: SelectOption): Promise<number>;
5
+ import { CascadeStore } from 'oak-domain/lib/store/CascadeStore';
6
+ import { DbStore } from 'oak-db/lib/types/dbStore';
7
+ export type TriggerStore<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>> = {
16
8
  registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
17
9
  registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
18
10
  setOnVolatileTrigger(onVolatileTrigger: <T extends keyof ED>(entity: T, trigger: VolatileTrigger<ED, T, Cxt>, ids: string[], cxtStr: string, option: OperateOption) => Promise<void>): void;
19
11
  execVolatileTrigger<T extends keyof ED>(entity: T, name: string, ids: string[], context: Cxt, option: OperateOption): Promise<void>;
20
12
  checkpoint(ts: number): Promise<number>;
21
13
  independentCheckPoint(name: string, ts: number, instanceCount?: number, instanceId?: number): Promise<number>;
22
- }
14
+ };
15
+ export type AppDbStore<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>> = DbStore<ED, Cxt> & CascadeStore<ED> & TriggerStore<ED, Cxt>;
16
+ export declare const createDbStore: <ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>>(storageSchema: StorageSchema<ED>, contextBuilder: () => Cxt, dbConfiguration: DbConfiguration, authDeduceRelationMap: AuthDeduceRelationMap<ED>, selectFreeEntities?: SelectFreeEntities<ED>, updateFreeDict?: UpdateFreeDict<ED>, onVolatileTrigger?: <T extends keyof ED>(entity: T, trigger: VolatileTrigger<ED, T, Cxt>, ids: string[], cxtStr: string, option: OperateOption) => Promise<void>) => AppDbStore<ED, Cxt>;
package/lib/DbStore.js CHANGED
@@ -1,128 +1,133 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DbStore = void 0;
4
- const oak_db_1 = require("oak-db");
3
+ exports.createDbStore = void 0;
5
4
  const TriggerExecutor_1 = require("oak-domain/lib/store/TriggerExecutor");
6
5
  const RelationAuth_1 = require("oak-domain/lib/store/RelationAuth");
7
- class DbStore extends oak_db_1.MysqlStore {
8
- executor;
9
- relationAuth;
10
- constructor(storageSchema, contextBuilder, mysqlConfiguration, authDeduceRelationMap, selectFreeEntities = [], updateFreeDict = {}, onVolatileTrigger) {
11
- super(storageSchema, mysqlConfiguration);
12
- this.executor = new TriggerExecutor_1.TriggerExecutor(contextBuilder, undefined, onVolatileTrigger);
13
- this.relationAuth = new RelationAuth_1.RelationAuth(storageSchema, authDeduceRelationMap, selectFreeEntities, updateFreeDict);
14
- }
15
- checkRelationAsync(entity, operation, context) {
16
- return this.relationAuth.checkRelationAsync(entity, operation, context);
17
- }
18
- async cascadeUpdateAsync(entity, operation, context, option) {
19
- // 如果是在modi处理过程中,所有的trigger也可以延时到apply时再处理(这时候因为modi中的数据并不实际存在,处理会有问题)
20
- if (!option.blockTrigger) {
21
- await this.executor.preOperation(entity, operation, context, option);
22
- }
23
- const result = await super.cascadeUpdateAsync(entity, operation, context, option);
24
- if (!option.blockTrigger) {
25
- await this.executor.postOperation(entity, operation, context, option);
26
- }
27
- return result;
28
- }
29
- async operate(entity, operation, context, option) {
30
- const autoCommit = !context.getCurrentTxnId();
31
- let result;
32
- if (autoCommit) {
33
- await context.begin();
34
- }
35
- try {
36
- await this.relationAuth.checkRelationAsync(entity, operation, context);
37
- result = await super.operate(entity, operation, context, option);
38
- }
39
- catch (err) {
40
- await context.rollback();
41
- throw err;
42
- }
43
- if (autoCommit) {
44
- await context.commit();
45
- }
46
- return result;
47
- }
48
- async select(entity, selection, context, option) {
49
- const autoCommit = !context.getCurrentTxnId();
50
- if (autoCommit) {
51
- await context.begin();
52
- }
53
- let result;
54
- // select的trigger应加在根select之前,cascade的select不加处理
55
- Object.assign(selection, {
56
- action: 'select',
57
- });
58
- if (!option.blockTrigger) {
59
- await this.executor.preOperation(entity, selection, context, option);
6
+ const dbPriority_1 = require("./utils/dbPriority");
7
+ const createDbStore = (storageSchema, contextBuilder, dbConfiguration, authDeduceRelationMap, selectFreeEntities = [], updateFreeDict = {}, onVolatileTrigger) => {
8
+ const BaseStoreClass = (0, dbPriority_1.getDbStoreClass)();
9
+ // 动态创建继承类
10
+ class DynamicDbStore extends BaseStoreClass {
11
+ executor;
12
+ relationAuth;
13
+ constructor() {
14
+ super(storageSchema, dbConfiguration);
15
+ this.executor = new TriggerExecutor_1.TriggerExecutor(contextBuilder, undefined, onVolatileTrigger);
16
+ this.relationAuth = new RelationAuth_1.RelationAuth(storageSchema, authDeduceRelationMap, selectFreeEntities, updateFreeDict);
17
+ }
18
+ checkRelationAsync(entity, operation, context) {
19
+ return this.relationAuth.checkRelationAsync(entity, operation, context);
20
+ }
21
+ async cascadeUpdateAsync(entity, operation, context, option) {
22
+ // 如果是在modi处理过程中,所有的trigger也可以延时到apply时再处理(这时候因为modi中的数据并不实际存在,处理会有问题)
23
+ if (!option.blockTrigger) {
24
+ await this.executor.preOperation(entity, operation, context, option);
25
+ }
26
+ const result = await super.cascadeUpdateAsync(entity, operation, context, option);
27
+ if (!option.blockTrigger) {
28
+ await this.executor.postOperation(entity, operation, context, option);
29
+ }
30
+ return result;
60
31
  }
61
- if (!option.dontCollect) {
62
- await this.relationAuth.checkRelationAsync(entity, selection, context);
32
+ async operate(entity, operation, context, option) {
33
+ const autoCommit = !context.getCurrentTxnId();
34
+ let result;
35
+ if (autoCommit) {
36
+ await context.begin();
37
+ }
38
+ try {
39
+ await this.relationAuth.checkRelationAsync(entity, operation, context);
40
+ result = await super.operate(entity, operation, context, option);
41
+ }
42
+ catch (err) {
43
+ await context.rollback();
44
+ throw err;
45
+ }
46
+ if (autoCommit) {
47
+ await context.commit();
48
+ }
49
+ return result;
63
50
  }
64
- try {
65
- result = await super.select(entity, selection, context, option);
51
+ async select(entity, selection, context, option) {
52
+ const autoCommit = !context.getCurrentTxnId();
53
+ if (autoCommit) {
54
+ await context.begin();
55
+ }
56
+ let result;
57
+ // select的trigger应加在根select之前,cascade的select不加处理
58
+ Object.assign(selection, {
59
+ action: 'select',
60
+ });
66
61
  if (!option.blockTrigger) {
67
- await this.executor.postOperation(entity, selection, context, option, result);
62
+ await this.executor.preOperation(entity, selection, context, option);
63
+ }
64
+ if (!option.dontCollect) {
65
+ await this.relationAuth.checkRelationAsync(entity, selection, context);
66
+ }
67
+ try {
68
+ result = await super.select(entity, selection, context, option);
69
+ if (!option.blockTrigger) {
70
+ await this.executor.postOperation(entity, selection, context, option, result);
71
+ }
72
+ }
73
+ catch (err) {
74
+ await context.rollback();
75
+ throw err;
76
+ }
77
+ if (autoCommit) {
78
+ await context.commit();
79
+ }
80
+ return result;
81
+ }
82
+ async count(entity, selection, context, option) {
83
+ const autoCommit = !context.getCurrentTxnId();
84
+ let result;
85
+ if (autoCommit) {
86
+ await context.begin();
87
+ }
88
+ try {
89
+ // count不用检查权限,因为检查权限中本身要用到count
90
+ // const selection2 = Object.assign({
91
+ // action: 'select',
92
+ // }, selection) as ED[T]['Operation'];
93
+ // await this.relationAuth.checkRelationAsync(entity, selection2, context);
94
+ // if (!option.blockTrigger) {
95
+ // await this.executor.preOperation(entity, selection2, context, option);
96
+ // }
97
+ result = await super.count(entity, selection, context, option);
98
+ /* count应该不存在后trigger吧
99
+ if (!option.blockTrigger) {
100
+ await this.executor.postOperation(entity, selection2, context, option);
101
+ } */
102
+ }
103
+ catch (err) {
104
+ await context.rollback();
105
+ throw err;
68
106
  }
107
+ if (autoCommit) {
108
+ await context.commit();
109
+ }
110
+ return result;
69
111
  }
70
- catch (err) {
71
- await context.rollback();
72
- throw err;
112
+ registerTrigger(trigger) {
113
+ this.executor.registerTrigger(trigger);
73
114
  }
74
- if (autoCommit) {
75
- await context.commit();
115
+ registerChecker(checker) {
116
+ this.executor.registerChecker(checker, this.getSchema());
76
117
  }
77
- return result;
78
- }
79
- async count(entity, selection, context, option) {
80
- const autoCommit = !context.getCurrentTxnId();
81
- let result;
82
- if (autoCommit) {
83
- await context.begin();
118
+ setOnVolatileTrigger(onVolatileTrigger) {
119
+ this.executor.setOnVolatileTrigger(onVolatileTrigger);
84
120
  }
85
- try {
86
- // count不用检查权限,因为检查权限中本身要用到count
87
- // const selection2 = Object.assign({
88
- // action: 'select',
89
- // }, selection) as ED[T]['Operation'];
90
- // await this.relationAuth.checkRelationAsync(entity, selection2, context);
91
- // if (!option.blockTrigger) {
92
- // await this.executor.preOperation(entity, selection2, context, option);
93
- // }
94
- result = await super.count(entity, selection, context, option);
95
- /* count应该不存在后trigger吧
96
- if (!option.blockTrigger) {
97
- await this.executor.postOperation(entity, selection2, context, option);
98
- } */
121
+ async execVolatileTrigger(entity, name, ids, context, option) {
122
+ return this.executor.execVolatileTrigger(entity, name, ids, context, option);
99
123
  }
100
- catch (err) {
101
- await context.rollback();
102
- throw err;
124
+ checkpoint(ts) {
125
+ return this.executor.checkpoint(ts);
103
126
  }
104
- if (autoCommit) {
105
- await context.commit();
127
+ independentCheckPoint(name, ts, instanceCount, instanceId) {
128
+ return this.executor.independentCheckPoint(name, ts, instanceCount, instanceId);
106
129
  }
107
- return result;
108
- }
109
- registerTrigger(trigger) {
110
- this.executor.registerTrigger(trigger);
111
- }
112
- registerChecker(checker) {
113
- this.executor.registerChecker(checker, this.getSchema());
114
- }
115
- setOnVolatileTrigger(onVolatileTrigger) {
116
- this.executor.setOnVolatileTrigger(onVolatileTrigger);
117
- }
118
- async execVolatileTrigger(entity, name, ids, context, option) {
119
- return this.executor.execVolatileTrigger(entity, name, ids, context, option);
120
- }
121
- checkpoint(ts) {
122
- return this.executor.checkpoint(ts);
123
- }
124
- independentCheckPoint(name, ts, instanceCount, instanceId) {
125
- return this.executor.independentCheckPoint(name, ts, instanceCount, instanceId);
126
130
  }
127
- }
128
- exports.DbStore = DbStore;
131
+ return new DynamicDbStore();
132
+ };
133
+ exports.createDbStore = createDbStore;
@@ -0,0 +1,16 @@
1
+ import { MysqlStore, PostgreSQLStore } from "oak-db";
2
+ import { DbConfiguration } from "oak-db/src/types/configuration";
3
+ import { AsyncRowStore } from "oak-domain/lib/store/AsyncRowStore";
4
+ import { EntityDict, StorageSchema } from 'oak-domain/lib/types';
5
+ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
6
+ import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
7
+ import { CascadeStore } from "oak-domain/lib/store/CascadeStore";
8
+ /**
9
+ * 数据库优先级列表,按顺序尝试获取配置文件
10
+ */
11
+ export declare const dbList: {
12
+ mysql: typeof MysqlStore;
13
+ postgres: typeof PostgreSQLStore;
14
+ };
15
+ export declare const getDbConfig: (path: string) => DbConfiguration;
16
+ export declare const getDbStoreClass: <ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>>() => new (schema: StorageSchema<ED>, config: DbConfiguration) => AsyncRowStore<ED, Cxt> & CascadeStore<ED>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDbStoreClass = exports.getDbConfig = exports.dbList = void 0;
4
+ const oak_db_1 = require("oak-db");
5
+ const path_1 = require("path");
6
+ const fs_1 = require("fs");
7
+ /**
8
+ * 数据库优先级列表,按顺序尝试获取配置文件
9
+ */
10
+ exports.dbList = {
11
+ mysql: oak_db_1.MysqlStore,
12
+ postgres: oak_db_1.PostgreSQLStore
13
+ };
14
+ let usedDbType = null;
15
+ const getDbConfig = (path) => {
16
+ for (const db of Object.keys(exports.dbList)) {
17
+ try {
18
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
19
+ let dbConfigFile = (0, path_1.join)(path, 'configuration', `${db}.${process.env.NODE_ENV}.json`);
20
+ if ((0, fs_1.existsSync)(dbConfigFile) === false) {
21
+ dbConfigFile = (0, path_1.join)(path, 'configuration', `${db}.json`);
22
+ }
23
+ if ((0, fs_1.existsSync)(dbConfigFile) === false) {
24
+ continue;
25
+ }
26
+ const config = require(dbConfigFile);
27
+ console.log(`使用${db}作为数据库`);
28
+ usedDbType = db;
29
+ return Object.assign({}, config);
30
+ }
31
+ catch (err) {
32
+ // do nothing
33
+ }
34
+ }
35
+ throw new Error(`没有找到数据库配置文件,请在configuration目录下添加任一配置文件:${Object.keys(exports.dbList).map(ele => `${ele}.json`).join('、')}`);
36
+ };
37
+ exports.getDbConfig = getDbConfig;
38
+ const getDbStoreClass = () => {
39
+ const dbType = usedDbType || (() => {
40
+ throw new Error('无法确定数据库类型');
41
+ })();
42
+ const DbStoreClass = exports.dbList[dbType.toLowerCase()];
43
+ if (!DbStoreClass) {
44
+ throw new Error(`不支持的数据库类型:${dbType},请确认是否存在以下配置文件:${Object.keys(exports.dbList).map(ele => `${ele}.json`).join('、')}`);
45
+ }
46
+ return DbStoreClass;
47
+ };
48
+ exports.getDbStoreClass = getDbStoreClass;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-backend-base",
3
- "version": "4.1.25",
3
+ "version": "4.1.26",
4
4
  "description": "oak-backend-base",
5
5
  "main": "lib/index",
6
6
  "author": {
@@ -22,9 +22,9 @@
22
22
  "mysql2": "^2.3.3",
23
23
  "node-schedule": "^2.1.0",
24
24
  "oak-common-aspect": "^3.0.5",
25
- "oak-db": "^3.3.11",
26
- "oak-domain": "^5.1.31",
27
- "oak-frontend-base": "^5.3.43",
25
+ "oak-db": "^3.3.12",
26
+ "oak-domain": "^5.1.33",
27
+ "oak-frontend-base": "^5.3.45",
28
28
  "socket.io": "^4.8.1",
29
29
  "socket.io-client": "^4.7.2",
30
30
  "uuid": "^8.3.2"