@eggjs/tegg-dal-plugin 4.0.0-beta.7 → 4.0.0-beta.8

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.
Files changed (43) hide show
  1. package/dist/DalModuleLoadUnitHook-BQjJ9Sf6.d.ts +13 -0
  2. package/dist/DalModuleLoadUnitHook-CrJVDTM5.js +40 -0
  3. package/dist/DalTableEggPrototypeHook-CW3ojxJE.d.ts +11 -0
  4. package/dist/DalTableEggPrototypeHook-DcDNlKdt.js +25 -0
  5. package/dist/DataSource-IPtIsuKR.d.ts +12 -0
  6. package/dist/DataSource-oPmPly4i.js +79 -0
  7. package/dist/MysqlDataSourceManager-Bl5dlpX7.js +58 -0
  8. package/dist/MysqlDataSourceManager-lrONMsdL.d.ts +15 -0
  9. package/dist/SqlMapManager-Dee8HrBh.js +27 -0
  10. package/dist/SqlMapManager-fyfTcuvE.d.ts +13 -0
  11. package/dist/TableModelManager-C9FVu5zw.js +27 -0
  12. package/dist/TableModelManager-D9HmMlTB.d.ts +13 -0
  13. package/dist/TransactionPrototypeHook-Cz3trnvZ.d.ts +12 -0
  14. package/dist/TransactionPrototypeHook-_PXHgwHf.js +50 -0
  15. package/dist/TransactionalAOP-Bm-mjuDZ.js +30 -0
  16. package/dist/TransactionalAOP-CRvc1-Sf.d.ts +15 -0
  17. package/dist/app.js +7 -6
  18. package/dist/index.d.ts +9 -8
  19. package/dist/index.js +9 -9
  20. package/dist/lib/DalModuleLoadUnitHook.d.ts +1 -12
  21. package/dist/lib/DalModuleLoadUnitHook.js +2 -38
  22. package/dist/lib/DalTableEggPrototypeHook.d.ts +1 -10
  23. package/dist/lib/DalTableEggPrototypeHook.js +3 -23
  24. package/dist/lib/DataSource.d.ts +2 -11
  25. package/dist/lib/DataSource.js +5 -66
  26. package/dist/lib/MysqlDataSourceManager.d.ts +1 -14
  27. package/dist/lib/MysqlDataSourceManager.js +1 -56
  28. package/dist/lib/SqlMapManager.d.ts +1 -12
  29. package/dist/lib/SqlMapManager.js +1 -25
  30. package/dist/lib/TableModelManager.d.ts +1 -12
  31. package/dist/lib/TableModelManager.js +1 -25
  32. package/dist/lib/TransactionPrototypeHook.d.ts +1 -11
  33. package/dist/lib/TransactionPrototypeHook.js +3 -48
  34. package/dist/lib/TransactionalAOP.d.ts +1 -14
  35. package/dist/lib/TransactionalAOP.js +1 -20
  36. package/dist/types-CSwhn03Z.d.ts +1 -0
  37. package/dist/types-Ct3xXZX7.js +3 -0
  38. package/dist/types.d.ts +1 -1
  39. package/dist/types.js +1 -1
  40. package/package.json +9 -9
  41. package/dist/_virtual/_@oxc-project_runtime@0.93.0/helpers/decorate.js +0 -10
  42. package/dist/_virtual/_@oxc-project_runtime@0.93.0/helpers/decorateMetadata.js +0 -7
  43. package/dist/_virtual/_@oxc-project_runtime@0.93.0/helpers/decorateParam.js +0 -9
@@ -0,0 +1,13 @@
1
+ import { LifecycleHook, Logger, ModuleConfigHolder } from "@eggjs/tegg";
2
+ import { LoadUnit, LoadUnitLifecycleContext } from "@eggjs/tegg/helper";
3
+
4
+ //#region src/lib/DalModuleLoadUnitHook.d.ts
5
+ declare class DalModuleLoadUnitHook implements LifecycleHook<LoadUnitLifecycleContext, LoadUnit> {
6
+ private readonly moduleConfigs;
7
+ private readonly env;
8
+ private readonly logger?;
9
+ constructor(env: string, moduleConfigs: Record<string, ModuleConfigHolder>, logger?: Logger);
10
+ preCreate(_: LoadUnitLifecycleContext, loadUnit: LoadUnit): Promise<void>;
11
+ }
12
+ //#endregion
13
+ export { DalModuleLoadUnitHook };
@@ -0,0 +1,40 @@
1
+ import { MysqlDataSourceManager } from "./MysqlDataSourceManager-Bl5dlpX7.js";
2
+ import "@eggjs/tegg";
3
+ import "@eggjs/tegg/helper";
4
+ import { DatabaseForker } from "@eggjs/dal-runtime";
5
+
6
+ //#region src/lib/DalModuleLoadUnitHook.ts
7
+ var DalModuleLoadUnitHook = class {
8
+ moduleConfigs;
9
+ env;
10
+ logger;
11
+ constructor(env, moduleConfigs, logger) {
12
+ this.env = env;
13
+ this.moduleConfigs = moduleConfigs;
14
+ this.logger = logger;
15
+ }
16
+ async preCreate(_, loadUnit) {
17
+ const moduleConfigHolder = this.moduleConfigs[loadUnit.name];
18
+ if (!moduleConfigHolder) return;
19
+ const dataSourceConfig = moduleConfigHolder.config.dataSource;
20
+ if (!dataSourceConfig) return;
21
+ await Promise.all(Object.entries(dataSourceConfig).map(async ([name, config]) => {
22
+ const dataSourceOptions = {
23
+ ...config,
24
+ name,
25
+ logger: this.logger
26
+ };
27
+ const forker = new DatabaseForker(this.env, dataSourceOptions);
28
+ if (forker.shouldFork()) await forker.forkDb(loadUnit.unitPath);
29
+ try {
30
+ await MysqlDataSourceManager.instance.createDataSource(loadUnit.name, name, dataSourceOptions);
31
+ } catch (e) {
32
+ if (e instanceof Error) e.message = `create module ${loadUnit.name} datasource ${name} failed: ${e.message}`;
33
+ throw e;
34
+ }
35
+ }));
36
+ }
37
+ };
38
+
39
+ //#endregion
40
+ export { DalModuleLoadUnitHook };
@@ -0,0 +1,11 @@
1
+ import { LifecycleHook, Logger } from "@eggjs/tegg";
2
+ import { EggPrototype, EggPrototypeLifecycleContext } from "@eggjs/tegg/helper";
3
+
4
+ //#region src/lib/DalTableEggPrototypeHook.d.ts
5
+ declare class DalTableEggPrototypeHook implements LifecycleHook<EggPrototypeLifecycleContext, EggPrototype> {
6
+ private readonly logger;
7
+ constructor(logger: Logger);
8
+ preCreate(ctx: EggPrototypeLifecycleContext): Promise<void>;
9
+ }
10
+ //#endregion
11
+ export { DalTableEggPrototypeHook };
@@ -0,0 +1,25 @@
1
+ import { TableModelManager } from "./TableModelManager-C9FVu5zw.js";
2
+ import { SqlMapManager } from "./SqlMapManager-Dee8HrBh.js";
3
+ import "@eggjs/tegg";
4
+ import "@eggjs/tegg/helper";
5
+ import { DaoInfoUtil, TableModel } from "@eggjs/dal-decorator";
6
+ import { SqlMapLoader } from "@eggjs/dal-runtime";
7
+
8
+ //#region src/lib/DalTableEggPrototypeHook.ts
9
+ var DalTableEggPrototypeHook = class {
10
+ logger;
11
+ constructor(logger) {
12
+ this.logger = logger;
13
+ }
14
+ async preCreate(ctx) {
15
+ if (!DaoInfoUtil.getIsDao(ctx.clazz)) return;
16
+ const tableClazz = ctx.clazz.clazzModel;
17
+ const tableModel = TableModel.build(tableClazz);
18
+ TableModelManager.instance.set(ctx.loadUnit.name, tableModel);
19
+ const sqlMap = new SqlMapLoader(tableModel, ctx.clazz, this.logger).load();
20
+ SqlMapManager.instance.set(ctx.loadUnit.name, sqlMap);
21
+ }
22
+ };
23
+
24
+ //#endregion
25
+ export { DalTableEggPrototypeHook };
@@ -0,0 +1,12 @@
1
+ import { TransactionalAOP } from "./TransactionalAOP-CRvc1-Sf.js";
2
+ import { ObjectInfo } from "@eggjs/tegg";
3
+ import { DataSource } from "@eggjs/dal-runtime";
4
+
5
+ //#region src/lib/DataSource.d.ts
6
+ declare class DataSourceDelegate<T> extends DataSource<T> {
7
+ private transactionalAOP;
8
+ objInfo: ObjectInfo;
9
+ constructor(transactionalAOP: TransactionalAOP, objInfo: ObjectInfo);
10
+ }
11
+ //#endregion
12
+ export { DataSourceDelegate };
@@ -0,0 +1,79 @@
1
+ import { TableModelManager } from "./TableModelManager-C9FVu5zw.js";
2
+ import { SqlMapManager } from "./SqlMapManager-Dee8HrBh.js";
3
+ import { MysqlDataSourceManager } from "./MysqlDataSourceManager-Bl5dlpX7.js";
4
+ import { TransactionalAOP, __decorate } from "./TransactionalAOP-Bm-mjuDZ.js";
5
+ import { AccessLevel, Inject, LoadUnitNameQualifierAttribute, MultiInstanceInfo, MultiInstanceProto, ObjectInitType } from "@eggjs/tegg";
6
+ import { EggLoadUnitType, LoaderFactory, ModuleConfigUtil } from "@eggjs/tegg/helper";
7
+ import { DataSource } from "@eggjs/dal-runtime";
8
+ import assert from "node:assert";
9
+ import { DataSourceInjectName, DataSourceQualifierAttribute, TableInfoUtil } from "@eggjs/tegg/dal";
10
+
11
+ //#region \0@oxc-project+runtime@0.93.0/helpers/decorateMetadata.js
12
+ function __decorateMetadata(k, v) {
13
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
14
+ }
15
+
16
+ //#endregion
17
+ //#region \0@oxc-project+runtime@0.93.0/helpers/decorateParam.js
18
+ function __decorateParam(paramIndex, decorator) {
19
+ return function(target, key) {
20
+ decorator(target, key, paramIndex);
21
+ };
22
+ }
23
+
24
+ //#endregion
25
+ //#region src/lib/DataSource.ts
26
+ var _ref;
27
+ let DataSourceDelegate = class DataSourceDelegate$1 extends DataSource {
28
+ transactionalAOP;
29
+ objInfo;
30
+ constructor(transactionalAOP, objInfo) {
31
+ const dataSourceQualifierValue = objInfo.qualifiers.find((t) => t.attribute === DataSourceQualifierAttribute)?.value;
32
+ assert(dataSourceQualifierValue);
33
+ const [moduleName, dataSource, clazzName] = dataSourceQualifierValue.split(".");
34
+ const tableModel = TableModelManager.instance.get(moduleName, clazzName);
35
+ assert(tableModel, `not found table ${dataSourceQualifierValue}`);
36
+ const mysqlDataSource = MysqlDataSourceManager.instance.get(moduleName, dataSource);
37
+ assert(mysqlDataSource, `not found dataSource ${dataSource} in module ${moduleName}`);
38
+ const sqlMap = SqlMapManager.instance.get(moduleName, clazzName);
39
+ assert(sqlMap, `not found SqlMap ${clazzName} in module ${moduleName}`);
40
+ super(tableModel, mysqlDataSource, sqlMap);
41
+ this.transactionalAOP = transactionalAOP;
42
+ this.objInfo = objInfo;
43
+ }
44
+ };
45
+ DataSourceDelegate = __decorate([
46
+ MultiInstanceProto({
47
+ accessLevel: AccessLevel.PUBLIC,
48
+ initType: ObjectInitType.SINGLETON,
49
+ async getObjects(ctx) {
50
+ const config = ModuleConfigUtil.loadModuleConfigSync(ctx.unitPath);
51
+ const dataSources = Object.keys(config?.dataSource || {});
52
+ const result = [];
53
+ const tableClazzList = (await LoaderFactory.createLoader(ctx.unitPath, EggLoadUnitType.MODULE).load()).filter((t) => {
54
+ return TableInfoUtil.getIsTable(t);
55
+ });
56
+ const dataSourceLength = dataSources.length;
57
+ for (const dataSource of dataSources) {
58
+ const moduleClazzList = tableClazzList.filter((clazz) => {
59
+ const dataSourceName = TableInfoUtil.getTableParams(clazz)?.dataSourceName ?? "default";
60
+ return dataSourceLength === 1 || dataSourceName === dataSource;
61
+ });
62
+ for (const clazz of moduleClazzList) result.push({
63
+ name: DataSourceInjectName,
64
+ qualifiers: [{
65
+ attribute: DataSourceQualifierAttribute,
66
+ value: `${ctx.moduleName}.${dataSource}.${clazz.name}`
67
+ }]
68
+ });
69
+ }
70
+ return result;
71
+ }
72
+ }),
73
+ __decorateParam(0, Inject({ name: "transactionalAOP" })),
74
+ __decorateParam(1, MultiInstanceInfo([DataSourceQualifierAttribute, LoadUnitNameQualifierAttribute])),
75
+ __decorateMetadata("design:paramtypes", [typeof (_ref = typeof TransactionalAOP !== "undefined" && TransactionalAOP) === "function" ? _ref : Object, Object])
76
+ ], DataSourceDelegate);
77
+
78
+ //#endregion
79
+ export { DataSourceDelegate };
@@ -0,0 +1,58 @@
1
+ import { MysqlDataSource } from "@eggjs/dal-runtime";
2
+ import crypto from "node:crypto";
3
+
4
+ //#region src/lib/MysqlDataSourceManager.ts
5
+ var MysqlDataSourceManager = class MysqlDataSourceManager {
6
+ static instance = new MysqlDataSourceManager();
7
+ dataSourceIndices;
8
+ dataSources;
9
+ constructor() {
10
+ this.dataSourceIndices = /* @__PURE__ */ new Map();
11
+ this.dataSources = /* @__PURE__ */ new Map();
12
+ }
13
+ get(moduleName, dataSourceName) {
14
+ const dataSourceIndex = this.dataSourceIndices.get(moduleName)?.get(dataSourceName);
15
+ if (dataSourceIndex) return this.dataSources.get(dataSourceIndex);
16
+ }
17
+ async createDataSource(moduleName, dataSourceName, config) {
18
+ const { logger,...dsConfig } = config || {};
19
+ const dataSourceConfig = {
20
+ ...dsConfig,
21
+ name: dataSourceName
22
+ };
23
+ const index = MysqlDataSourceManager.createDataSourceKey(dataSourceConfig);
24
+ let dataSource = this.dataSources.get(index);
25
+ if (!dataSource) {
26
+ dataSource = new MysqlDataSource({
27
+ ...dataSourceConfig,
28
+ logger
29
+ });
30
+ this.dataSources.set(index, dataSource);
31
+ }
32
+ let moduleDataSourceIndices = this.dataSourceIndices.get(moduleName);
33
+ if (!moduleDataSourceIndices) {
34
+ moduleDataSourceIndices = /* @__PURE__ */ new Map();
35
+ this.dataSourceIndices.set(moduleName, moduleDataSourceIndices);
36
+ }
37
+ moduleDataSourceIndices.set(dataSourceName, index);
38
+ await dataSource.ready();
39
+ }
40
+ clear() {
41
+ this.dataSourceIndices.clear();
42
+ }
43
+ static createDataSourceKey(dataSourceOptions) {
44
+ const hash = crypto.createHash("md5");
45
+ const keys = Object.keys(dataSourceOptions).sort();
46
+ for (const key of keys) {
47
+ const value = dataSourceOptions[key];
48
+ if (value) {
49
+ hash.update(key);
50
+ hash.update(String(value));
51
+ }
52
+ }
53
+ return hash.digest("hex");
54
+ }
55
+ };
56
+
57
+ //#endregion
58
+ export { MysqlDataSourceManager };
@@ -0,0 +1,15 @@
1
+ import { DataSourceOptions, MysqlDataSource } from "@eggjs/dal-runtime";
2
+
3
+ //#region src/lib/MysqlDataSourceManager.d.ts
4
+ declare class MysqlDataSourceManager {
5
+ static instance: MysqlDataSourceManager;
6
+ private readonly dataSourceIndices;
7
+ private readonly dataSources;
8
+ constructor();
9
+ get(moduleName: string, dataSourceName: string): MysqlDataSource | undefined;
10
+ createDataSource(moduleName: string, dataSourceName: string, config: DataSourceOptions): Promise<void>;
11
+ clear(): void;
12
+ static createDataSourceKey(dataSourceOptions: DataSourceOptions): string;
13
+ }
14
+ //#endregion
15
+ export { MysqlDataSourceManager };
@@ -0,0 +1,27 @@
1
+ import { TableSqlMap } from "@eggjs/dal-runtime";
2
+
3
+ //#region src/lib/SqlMapManager.ts
4
+ var SqlMapManager = class SqlMapManager {
5
+ static instance = new SqlMapManager();
6
+ sqlMaps;
7
+ constructor() {
8
+ this.sqlMaps = /* @__PURE__ */ new Map();
9
+ }
10
+ get(moduleName, clazzName) {
11
+ return this.sqlMaps.get(moduleName)?.get(clazzName);
12
+ }
13
+ set(moduleName, sqlMap) {
14
+ let tables = this.sqlMaps.get(moduleName);
15
+ if (!tables) {
16
+ tables = /* @__PURE__ */ new Map();
17
+ this.sqlMaps.set(moduleName, tables);
18
+ }
19
+ tables.set(sqlMap.name, sqlMap);
20
+ }
21
+ clear() {
22
+ this.sqlMaps.clear();
23
+ }
24
+ };
25
+
26
+ //#endregion
27
+ export { SqlMapManager };
@@ -0,0 +1,13 @@
1
+ import { TableSqlMap } from "@eggjs/dal-runtime";
2
+
3
+ //#region src/lib/SqlMapManager.d.ts
4
+ declare class SqlMapManager {
5
+ static instance: SqlMapManager;
6
+ private sqlMaps;
7
+ constructor();
8
+ get(moduleName: string, clazzName: string): TableSqlMap | undefined;
9
+ set(moduleName: string, sqlMap: TableSqlMap): void;
10
+ clear(): void;
11
+ }
12
+ //#endregion
13
+ export { SqlMapManager };
@@ -0,0 +1,27 @@
1
+ import { TableModel } from "@eggjs/dal-decorator";
2
+
3
+ //#region src/lib/TableModelManager.ts
4
+ var TableModelManager = class TableModelManager {
5
+ static instance = new TableModelManager();
6
+ tableModels;
7
+ constructor() {
8
+ this.tableModels = /* @__PURE__ */ new Map();
9
+ }
10
+ get(moduleName, clazzName) {
11
+ return this.tableModels.get(moduleName)?.get(clazzName);
12
+ }
13
+ set(moduleName, tableModel) {
14
+ let tables = this.tableModels.get(moduleName);
15
+ if (!tables) {
16
+ tables = /* @__PURE__ */ new Map();
17
+ this.tableModels.set(moduleName, tables);
18
+ }
19
+ tables.set(tableModel.clazz.name, tableModel);
20
+ }
21
+ clear() {
22
+ this.tableModels.clear();
23
+ }
24
+ };
25
+
26
+ //#endregion
27
+ export { TableModelManager };
@@ -0,0 +1,13 @@
1
+ import { TableModel } from "@eggjs/dal-decorator";
2
+
3
+ //#region src/lib/TableModelManager.d.ts
4
+ declare class TableModelManager {
5
+ static instance: TableModelManager;
6
+ private tableModels;
7
+ constructor();
8
+ get(moduleName: string, clazzName: string): TableModel | undefined;
9
+ set(moduleName: string, tableModel: TableModel): void;
10
+ clear(): void;
11
+ }
12
+ //#endregion
13
+ export { TableModelManager };
@@ -0,0 +1,12 @@
1
+ import { LifecycleHook, Logger, ModuleConfigHolder } from "@eggjs/tegg";
2
+ import { EggPrototype, EggPrototypeLifecycleContext } from "@eggjs/tegg-metadata";
3
+
4
+ //#region src/lib/TransactionPrototypeHook.d.ts
5
+ declare class TransactionPrototypeHook implements LifecycleHook<EggPrototypeLifecycleContext, EggPrototype> {
6
+ private readonly moduleConfigs;
7
+ private readonly logger;
8
+ constructor(moduleConfigs: Record<string, ModuleConfigHolder>, logger: Logger);
9
+ preCreate(ctx: EggPrototypeLifecycleContext): Promise<void>;
10
+ }
11
+ //#endregion
12
+ export { TransactionPrototypeHook };
@@ -0,0 +1,50 @@
1
+ import { MysqlDataSourceManager } from "./MysqlDataSourceManager-Bl5dlpX7.js";
2
+ import { TransactionalAOP } from "./TransactionalAOP-Bm-mjuDZ.js";
3
+ import "@eggjs/tegg";
4
+ import assert from "node:assert";
5
+ import "@eggjs/tegg-metadata";
6
+ import { PropagationType, TransactionMetaBuilder } from "@eggjs/tegg/transaction";
7
+ import { Pointcut } from "@eggjs/tegg/aop";
8
+
9
+ //#region src/lib/TransactionPrototypeHook.ts
10
+ var TransactionPrototypeHook = class {
11
+ moduleConfigs;
12
+ logger;
13
+ constructor(moduleConfigs, logger) {
14
+ this.moduleConfigs = moduleConfigs;
15
+ this.logger = logger;
16
+ }
17
+ async preCreate(ctx) {
18
+ const transactionMetadataList = new TransactionMetaBuilder(ctx.clazz).build();
19
+ if (transactionMetadataList.length < 1) return;
20
+ const moduleName = ctx.loadUnit.name;
21
+ for (const transactionMetadata of transactionMetadataList) {
22
+ const clazzName = `${moduleName}.${ctx.clazz.name}.${String(transactionMetadata.method)}`;
23
+ const datasourceConfigs = (this.moduleConfigs[moduleName]?.config)?.dataSource || {};
24
+ let datasourceName;
25
+ if (transactionMetadata.datasourceName) {
26
+ assert(datasourceConfigs[transactionMetadata.datasourceName], `method ${clazzName} specified datasource ${transactionMetadata.datasourceName} not exists`);
27
+ datasourceName = transactionMetadata.datasourceName;
28
+ this.logger.info(`use datasource [${transactionMetadata.datasourceName}] for class ${clazzName}`);
29
+ } else {
30
+ const dataSources = Object.keys(datasourceConfigs);
31
+ if (dataSources.length === 1) datasourceName = dataSources[0];
32
+ else throw new Error(`method ${clazzName} not specified datasource, module ${moduleName} has multi datasource, should specify datasource name`);
33
+ this.logger.info(`use default datasource ${dataSources[0]} for class ${clazzName}`);
34
+ }
35
+ const adviceParams = {
36
+ propagation: transactionMetadata.propagation,
37
+ dataSourceGetter: () => {
38
+ const mysqlDataSource = MysqlDataSourceManager.instance.get(moduleName, datasourceName);
39
+ if (!mysqlDataSource) throw new Error(`method ${clazzName} not found datasource ${datasourceName}`);
40
+ return mysqlDataSource;
41
+ }
42
+ };
43
+ assert(adviceParams.propagation === PropagationType.REQUIRED, "Transactional propagation only support required for now");
44
+ Pointcut(TransactionalAOP, { adviceParams })(ctx.clazz.prototype, transactionMetadata.method);
45
+ }
46
+ }
47
+ };
48
+
49
+ //#endregion
50
+ export { TransactionPrototypeHook };
@@ -0,0 +1,30 @@
1
+ import { AccessLevel, ObjectInitType } from "@eggjs/tegg";
2
+ import { MysqlDataSource } from "@eggjs/dal-runtime";
3
+ import { PropagationType } from "@eggjs/tegg/transaction";
4
+ import { Advice } from "@eggjs/tegg/aop";
5
+
6
+ //#region \0@oxc-project+runtime@0.93.0/helpers/decorate.js
7
+ function __decorate(decorators, target, key, desc) {
8
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
12
+ }
13
+
14
+ //#endregion
15
+ //#region src/lib/TransactionalAOP.ts
16
+ let TransactionalAOP = class TransactionalAOP$1 {
17
+ async around(ctx, next) {
18
+ const { propagation, dataSourceGetter } = ctx.adviceParams;
19
+ const dataSource = dataSourceGetter();
20
+ if (propagation === PropagationType.ALWAYS_NEW) return await dataSource.beginTransactionScope(next);
21
+ return await dataSource.beginTransactionScope(next);
22
+ }
23
+ };
24
+ TransactionalAOP = __decorate([Advice({
25
+ accessLevel: AccessLevel.PUBLIC,
26
+ initType: ObjectInitType.SINGLETON
27
+ })], TransactionalAOP);
28
+
29
+ //#endregion
30
+ export { TransactionalAOP, __decorate };
@@ -0,0 +1,15 @@
1
+ import { EggProtoImplClass } from "@eggjs/tegg";
2
+ import { MysqlDataSource } from "@eggjs/dal-runtime";
3
+ import { PropagationType } from "@eggjs/tegg/transaction";
4
+ import { AdviceContext, IAdvice } from "@eggjs/tegg/aop";
5
+
6
+ //#region src/lib/TransactionalAOP.d.ts
7
+ interface TransactionalParams {
8
+ propagation: PropagationType;
9
+ dataSourceGetter: () => MysqlDataSource;
10
+ }
11
+ declare class TransactionalAOP implements IAdvice<EggProtoImplClass, TransactionalParams> {
12
+ around(ctx: AdviceContext<EggProtoImplClass, TransactionalParams>, next: () => Promise<any>): Promise<void>;
13
+ }
14
+ //#endregion
15
+ export { TransactionalAOP, TransactionalParams };
package/dist/app.js CHANGED
@@ -1,9 +1,10 @@
1
- import { TableModelManager } from "./lib/TableModelManager.js";
2
- import { SqlMapManager } from "./lib/SqlMapManager.js";
3
- import { DalTableEggPrototypeHook } from "./lib/DalTableEggPrototypeHook.js";
4
- import { MysqlDataSourceManager } from "./lib/MysqlDataSourceManager.js";
5
- import { DalModuleLoadUnitHook } from "./lib/DalModuleLoadUnitHook.js";
6
- import { TransactionPrototypeHook } from "./lib/TransactionPrototypeHook.js";
1
+ import { TableModelManager } from "./TableModelManager-C9FVu5zw.js";
2
+ import { SqlMapManager } from "./SqlMapManager-Dee8HrBh.js";
3
+ import { DalTableEggPrototypeHook } from "./DalTableEggPrototypeHook-DcDNlKdt.js";
4
+ import { MysqlDataSourceManager } from "./MysqlDataSourceManager-Bl5dlpX7.js";
5
+ import { DalModuleLoadUnitHook } from "./DalModuleLoadUnitHook-CrJVDTM5.js";
6
+ import "./TransactionalAOP-Bm-mjuDZ.js";
7
+ import { TransactionPrototypeHook } from "./TransactionPrototypeHook-_PXHgwHf.js";
7
8
 
8
9
  //#region src/app.ts
9
10
  var DalAppBootHook = class {
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { DalModuleLoadUnitHook } from "./lib/DalModuleLoadUnitHook.js";
2
- import { DalTableEggPrototypeHook } from "./lib/DalTableEggPrototypeHook.js";
3
- import { TransactionalAOP, TransactionalParams } from "./lib/TransactionalAOP.js";
4
- import { DataSourceDelegate } from "./lib/DataSource.js";
5
- import { MysqlDataSourceManager } from "./lib/MysqlDataSourceManager.js";
6
- import { SqlMapManager } from "./lib/SqlMapManager.js";
7
- import { TableModelManager } from "./lib/TableModelManager.js";
8
- import { TransactionPrototypeHook } from "./lib/TransactionPrototypeHook.js";
1
+ import "./types-CSwhn03Z.js";
2
+ import { DalModuleLoadUnitHook } from "./DalModuleLoadUnitHook-BQjJ9Sf6.js";
3
+ import { DalTableEggPrototypeHook } from "./DalTableEggPrototypeHook-CW3ojxJE.js";
4
+ import { TransactionalAOP, TransactionalParams } from "./TransactionalAOP-CRvc1-Sf.js";
5
+ import { DataSourceDelegate } from "./DataSource-IPtIsuKR.js";
6
+ import { MysqlDataSourceManager } from "./MysqlDataSourceManager-lrONMsdL.js";
7
+ import { SqlMapManager } from "./SqlMapManager-fyfTcuvE.js";
8
+ import { TableModelManager } from "./TableModelManager-D9HmMlTB.js";
9
+ import { TransactionPrototypeHook } from "./TransactionPrototypeHook-Cz3trnvZ.js";
9
10
  export { DalModuleLoadUnitHook, DalTableEggPrototypeHook, DataSourceDelegate, MysqlDataSourceManager, SqlMapManager, TableModelManager, TransactionPrototypeHook, TransactionalAOP, TransactionalParams };
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { TableModelManager } from "./lib/TableModelManager.js";
2
- import { SqlMapManager } from "./lib/SqlMapManager.js";
3
- import { DalTableEggPrototypeHook } from "./lib/DalTableEggPrototypeHook.js";
4
- import { MysqlDataSourceManager } from "./lib/MysqlDataSourceManager.js";
5
- import { DalModuleLoadUnitHook } from "./lib/DalModuleLoadUnitHook.js";
6
- import { TransactionalAOP } from "./lib/TransactionalAOP.js";
7
- import { TransactionPrototypeHook } from "./lib/TransactionPrototypeHook.js";
8
- import "./types.js";
9
- import { DataSourceDelegate } from "./lib/DataSource.js";
1
+ import { TableModelManager } from "./TableModelManager-C9FVu5zw.js";
2
+ import { SqlMapManager } from "./SqlMapManager-Dee8HrBh.js";
3
+ import { DalTableEggPrototypeHook } from "./DalTableEggPrototypeHook-DcDNlKdt.js";
4
+ import { MysqlDataSourceManager } from "./MysqlDataSourceManager-Bl5dlpX7.js";
5
+ import { DalModuleLoadUnitHook } from "./DalModuleLoadUnitHook-CrJVDTM5.js";
6
+ import { TransactionalAOP } from "./TransactionalAOP-Bm-mjuDZ.js";
7
+ import { TransactionPrototypeHook } from "./TransactionPrototypeHook-_PXHgwHf.js";
8
+ import "./types-Ct3xXZX7.js";
9
+ import { DataSourceDelegate } from "./DataSource-oPmPly4i.js";
10
10
 
11
11
  export { DalModuleLoadUnitHook, DalTableEggPrototypeHook, DataSourceDelegate, MysqlDataSourceManager, SqlMapManager, TableModelManager, TransactionPrototypeHook, TransactionalAOP };
@@ -1,13 +1,2 @@
1
- import { LifecycleHook, Logger, ModuleConfigHolder } from "@eggjs/tegg";
2
- import { LoadUnit, LoadUnitLifecycleContext } from "@eggjs/tegg/helper";
3
-
4
- //#region src/lib/DalModuleLoadUnitHook.d.ts
5
- declare class DalModuleLoadUnitHook implements LifecycleHook<LoadUnitLifecycleContext, LoadUnit> {
6
- private readonly moduleConfigs;
7
- private readonly env;
8
- private readonly logger?;
9
- constructor(env: string, moduleConfigs: Record<string, ModuleConfigHolder>, logger?: Logger);
10
- preCreate(_: LoadUnitLifecycleContext, loadUnit: LoadUnit): Promise<void>;
11
- }
12
- //#endregion
1
+ import { DalModuleLoadUnitHook } from "../DalModuleLoadUnitHook-BQjJ9Sf6.js";
13
2
  export { DalModuleLoadUnitHook };
@@ -1,40 +1,4 @@
1
- import { MysqlDataSourceManager } from "./MysqlDataSourceManager.js";
2
- import "@eggjs/tegg";
3
- import "@eggjs/tegg/helper";
4
- import { DatabaseForker } from "@eggjs/dal-runtime";
1
+ import "../MysqlDataSourceManager-Bl5dlpX7.js";
2
+ import { DalModuleLoadUnitHook } from "../DalModuleLoadUnitHook-CrJVDTM5.js";
5
3
 
6
- //#region src/lib/DalModuleLoadUnitHook.ts
7
- var DalModuleLoadUnitHook = class {
8
- moduleConfigs;
9
- env;
10
- logger;
11
- constructor(env, moduleConfigs, logger) {
12
- this.env = env;
13
- this.moduleConfigs = moduleConfigs;
14
- this.logger = logger;
15
- }
16
- async preCreate(_, loadUnit) {
17
- const moduleConfigHolder = this.moduleConfigs[loadUnit.name];
18
- if (!moduleConfigHolder) return;
19
- const dataSourceConfig = moduleConfigHolder.config.dataSource;
20
- if (!dataSourceConfig) return;
21
- await Promise.all(Object.entries(dataSourceConfig).map(async ([name, config]) => {
22
- const dataSourceOptions = {
23
- ...config,
24
- name,
25
- logger: this.logger
26
- };
27
- const forker = new DatabaseForker(this.env, dataSourceOptions);
28
- if (forker.shouldFork()) await forker.forkDb(loadUnit.unitPath);
29
- try {
30
- await MysqlDataSourceManager.instance.createDataSource(loadUnit.name, name, dataSourceOptions);
31
- } catch (e) {
32
- if (e instanceof Error) e.message = `create module ${loadUnit.name} datasource ${name} failed: ${e.message}`;
33
- throw e;
34
- }
35
- }));
36
- }
37
- };
38
-
39
- //#endregion
40
4
  export { DalModuleLoadUnitHook };
@@ -1,11 +1,2 @@
1
- import { LifecycleHook, Logger } from "@eggjs/tegg";
2
- import { EggPrototype, EggPrototypeLifecycleContext } from "@eggjs/tegg/helper";
3
-
4
- //#region src/lib/DalTableEggPrototypeHook.d.ts
5
- declare class DalTableEggPrototypeHook implements LifecycleHook<EggPrototypeLifecycleContext, EggPrototype> {
6
- private readonly logger;
7
- constructor(logger: Logger);
8
- preCreate(ctx: EggPrototypeLifecycleContext): Promise<void>;
9
- }
10
- //#endregion
1
+ import { DalTableEggPrototypeHook } from "../DalTableEggPrototypeHook-CW3ojxJE.js";
11
2
  export { DalTableEggPrototypeHook };
@@ -1,25 +1,5 @@
1
- import { TableModelManager } from "./TableModelManager.js";
2
- import { SqlMapManager } from "./SqlMapManager.js";
3
- import "@eggjs/tegg";
4
- import "@eggjs/tegg/helper";
5
- import { DaoInfoUtil, TableModel } from "@eggjs/dal-decorator";
6
- import { SqlMapLoader } from "@eggjs/dal-runtime";
1
+ import "../TableModelManager-C9FVu5zw.js";
2
+ import "../SqlMapManager-Dee8HrBh.js";
3
+ import { DalTableEggPrototypeHook } from "../DalTableEggPrototypeHook-DcDNlKdt.js";
7
4
 
8
- //#region src/lib/DalTableEggPrototypeHook.ts
9
- var DalTableEggPrototypeHook = class {
10
- logger;
11
- constructor(logger) {
12
- this.logger = logger;
13
- }
14
- async preCreate(ctx) {
15
- if (!DaoInfoUtil.getIsDao(ctx.clazz)) return;
16
- const tableClazz = ctx.clazz.clazzModel;
17
- const tableModel = TableModel.build(tableClazz);
18
- TableModelManager.instance.set(ctx.loadUnit.name, tableModel);
19
- const sqlMap = new SqlMapLoader(tableModel, ctx.clazz, this.logger).load();
20
- SqlMapManager.instance.set(ctx.loadUnit.name, sqlMap);
21
- }
22
- };
23
-
24
- //#endregion
25
5
  export { DalTableEggPrototypeHook };
@@ -1,12 +1,3 @@
1
- import { TransactionalAOP } from "./TransactionalAOP.js";
2
- import { ObjectInfo } from "@eggjs/tegg";
3
- import { DataSource } from "@eggjs/dal-runtime";
4
-
5
- //#region src/lib/DataSource.d.ts
6
- declare class DataSourceDelegate<T> extends DataSource<T> {
7
- private transactionalAOP;
8
- objInfo: ObjectInfo;
9
- constructor(transactionalAOP: TransactionalAOP, objInfo: ObjectInfo);
10
- }
11
- //#endregion
1
+ import "../TransactionalAOP-CRvc1-Sf.js";
2
+ import { DataSourceDelegate } from "../DataSource-IPtIsuKR.js";
12
3
  export { DataSourceDelegate };
@@ -1,68 +1,7 @@
1
- import { TableModelManager } from "./TableModelManager.js";
2
- import { SqlMapManager } from "./SqlMapManager.js";
3
- import { MysqlDataSourceManager } from "./MysqlDataSourceManager.js";
4
- import { __decorate } from "../_virtual/_@oxc-project_runtime@0.93.0/helpers/decorate.js";
5
- import { TransactionalAOP } from "./TransactionalAOP.js";
6
- import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.93.0/helpers/decorateMetadata.js";
7
- import { __decorateParam } from "../_virtual/_@oxc-project_runtime@0.93.0/helpers/decorateParam.js";
8
- import { AccessLevel, Inject, LoadUnitNameQualifierAttribute, MultiInstanceInfo, MultiInstanceProto, ObjectInitType } from "@eggjs/tegg";
9
- import { EggLoadUnitType, LoaderFactory, ModuleConfigUtil } from "@eggjs/tegg/helper";
10
- import { DataSource } from "@eggjs/dal-runtime";
11
- import assert from "node:assert";
12
- import { DataSourceInjectName, DataSourceQualifierAttribute, TableInfoUtil } from "@eggjs/tegg/dal";
1
+ import "../TableModelManager-C9FVu5zw.js";
2
+ import "../SqlMapManager-Dee8HrBh.js";
3
+ import "../MysqlDataSourceManager-Bl5dlpX7.js";
4
+ import "../TransactionalAOP-Bm-mjuDZ.js";
5
+ import { DataSourceDelegate } from "../DataSource-oPmPly4i.js";
13
6
 
14
- //#region src/lib/DataSource.ts
15
- var _ref;
16
- let DataSourceDelegate = class DataSourceDelegate$1 extends DataSource {
17
- transactionalAOP;
18
- objInfo;
19
- constructor(transactionalAOP, objInfo) {
20
- const dataSourceQualifierValue = objInfo.qualifiers.find((t) => t.attribute === DataSourceQualifierAttribute)?.value;
21
- assert(dataSourceQualifierValue);
22
- const [moduleName, dataSource, clazzName] = dataSourceQualifierValue.split(".");
23
- const tableModel = TableModelManager.instance.get(moduleName, clazzName);
24
- assert(tableModel, `not found table ${dataSourceQualifierValue}`);
25
- const mysqlDataSource = MysqlDataSourceManager.instance.get(moduleName, dataSource);
26
- assert(mysqlDataSource, `not found dataSource ${dataSource} in module ${moduleName}`);
27
- const sqlMap = SqlMapManager.instance.get(moduleName, clazzName);
28
- assert(sqlMap, `not found SqlMap ${clazzName} in module ${moduleName}`);
29
- super(tableModel, mysqlDataSource, sqlMap);
30
- this.transactionalAOP = transactionalAOP;
31
- this.objInfo = objInfo;
32
- }
33
- };
34
- DataSourceDelegate = __decorate([
35
- MultiInstanceProto({
36
- accessLevel: AccessLevel.PUBLIC,
37
- initType: ObjectInitType.SINGLETON,
38
- async getObjects(ctx) {
39
- const config = ModuleConfigUtil.loadModuleConfigSync(ctx.unitPath);
40
- const dataSources = Object.keys(config?.dataSource || {});
41
- const result = [];
42
- const tableClazzList = (await LoaderFactory.createLoader(ctx.unitPath, EggLoadUnitType.MODULE).load()).filter((t) => {
43
- return TableInfoUtil.getIsTable(t);
44
- });
45
- const dataSourceLength = dataSources.length;
46
- for (const dataSource of dataSources) {
47
- const moduleClazzList = tableClazzList.filter((clazz) => {
48
- const dataSourceName = TableInfoUtil.getTableParams(clazz)?.dataSourceName ?? "default";
49
- return dataSourceLength === 1 || dataSourceName === dataSource;
50
- });
51
- for (const clazz of moduleClazzList) result.push({
52
- name: DataSourceInjectName,
53
- qualifiers: [{
54
- attribute: DataSourceQualifierAttribute,
55
- value: `${ctx.moduleName}.${dataSource}.${clazz.name}`
56
- }]
57
- });
58
- }
59
- return result;
60
- }
61
- }),
62
- __decorateParam(0, Inject({ name: "transactionalAOP" })),
63
- __decorateParam(1, MultiInstanceInfo([DataSourceQualifierAttribute, LoadUnitNameQualifierAttribute])),
64
- __decorateMetadata("design:paramtypes", [typeof (_ref = typeof TransactionalAOP !== "undefined" && TransactionalAOP) === "function" ? _ref : Object, Object])
65
- ], DataSourceDelegate);
66
-
67
- //#endregion
68
7
  export { DataSourceDelegate };
@@ -1,15 +1,2 @@
1
- import { DataSourceOptions, MysqlDataSource } from "@eggjs/dal-runtime";
2
-
3
- //#region src/lib/MysqlDataSourceManager.d.ts
4
- declare class MysqlDataSourceManager {
5
- static instance: MysqlDataSourceManager;
6
- private readonly dataSourceIndices;
7
- private readonly dataSources;
8
- constructor();
9
- get(moduleName: string, dataSourceName: string): MysqlDataSource | undefined;
10
- createDataSource(moduleName: string, dataSourceName: string, config: DataSourceOptions): Promise<void>;
11
- clear(): void;
12
- static createDataSourceKey(dataSourceOptions: DataSourceOptions): string;
13
- }
14
- //#endregion
1
+ import { MysqlDataSourceManager } from "../MysqlDataSourceManager-lrONMsdL.js";
15
2
  export { MysqlDataSourceManager };
@@ -1,58 +1,3 @@
1
- import { MysqlDataSource } from "@eggjs/dal-runtime";
2
- import crypto from "node:crypto";
1
+ import { MysqlDataSourceManager } from "../MysqlDataSourceManager-Bl5dlpX7.js";
3
2
 
4
- //#region src/lib/MysqlDataSourceManager.ts
5
- var MysqlDataSourceManager = class MysqlDataSourceManager {
6
- static instance = new MysqlDataSourceManager();
7
- dataSourceIndices;
8
- dataSources;
9
- constructor() {
10
- this.dataSourceIndices = /* @__PURE__ */ new Map();
11
- this.dataSources = /* @__PURE__ */ new Map();
12
- }
13
- get(moduleName, dataSourceName) {
14
- const dataSourceIndex = this.dataSourceIndices.get(moduleName)?.get(dataSourceName);
15
- if (dataSourceIndex) return this.dataSources.get(dataSourceIndex);
16
- }
17
- async createDataSource(moduleName, dataSourceName, config) {
18
- const { logger,...dsConfig } = config || {};
19
- const dataSourceConfig = {
20
- ...dsConfig,
21
- name: dataSourceName
22
- };
23
- const index = MysqlDataSourceManager.createDataSourceKey(dataSourceConfig);
24
- let dataSource = this.dataSources.get(index);
25
- if (!dataSource) {
26
- dataSource = new MysqlDataSource({
27
- ...dataSourceConfig,
28
- logger
29
- });
30
- this.dataSources.set(index, dataSource);
31
- }
32
- let moduleDataSourceIndices = this.dataSourceIndices.get(moduleName);
33
- if (!moduleDataSourceIndices) {
34
- moduleDataSourceIndices = /* @__PURE__ */ new Map();
35
- this.dataSourceIndices.set(moduleName, moduleDataSourceIndices);
36
- }
37
- moduleDataSourceIndices.set(dataSourceName, index);
38
- await dataSource.ready();
39
- }
40
- clear() {
41
- this.dataSourceIndices.clear();
42
- }
43
- static createDataSourceKey(dataSourceOptions) {
44
- const hash = crypto.createHash("md5");
45
- const keys = Object.keys(dataSourceOptions).sort();
46
- for (const key of keys) {
47
- const value = dataSourceOptions[key];
48
- if (value) {
49
- hash.update(key);
50
- hash.update(String(value));
51
- }
52
- }
53
- return hash.digest("hex");
54
- }
55
- };
56
-
57
- //#endregion
58
3
  export { MysqlDataSourceManager };
@@ -1,13 +1,2 @@
1
- import { TableSqlMap } from "@eggjs/dal-runtime";
2
-
3
- //#region src/lib/SqlMapManager.d.ts
4
- declare class SqlMapManager {
5
- static instance: SqlMapManager;
6
- private sqlMaps;
7
- constructor();
8
- get(moduleName: string, clazzName: string): TableSqlMap | undefined;
9
- set(moduleName: string, sqlMap: TableSqlMap): void;
10
- clear(): void;
11
- }
12
- //#endregion
1
+ import { SqlMapManager } from "../SqlMapManager-fyfTcuvE.js";
13
2
  export { SqlMapManager };
@@ -1,27 +1,3 @@
1
- import { TableSqlMap } from "@eggjs/dal-runtime";
1
+ import { SqlMapManager } from "../SqlMapManager-Dee8HrBh.js";
2
2
 
3
- //#region src/lib/SqlMapManager.ts
4
- var SqlMapManager = class SqlMapManager {
5
- static instance = new SqlMapManager();
6
- sqlMaps;
7
- constructor() {
8
- this.sqlMaps = /* @__PURE__ */ new Map();
9
- }
10
- get(moduleName, clazzName) {
11
- return this.sqlMaps.get(moduleName)?.get(clazzName);
12
- }
13
- set(moduleName, sqlMap) {
14
- let tables = this.sqlMaps.get(moduleName);
15
- if (!tables) {
16
- tables = /* @__PURE__ */ new Map();
17
- this.sqlMaps.set(moduleName, tables);
18
- }
19
- tables.set(sqlMap.name, sqlMap);
20
- }
21
- clear() {
22
- this.sqlMaps.clear();
23
- }
24
- };
25
-
26
- //#endregion
27
3
  export { SqlMapManager };
@@ -1,13 +1,2 @@
1
- import { TableModel } from "@eggjs/dal-decorator";
2
-
3
- //#region src/lib/TableModelManager.d.ts
4
- declare class TableModelManager {
5
- static instance: TableModelManager;
6
- private tableModels;
7
- constructor();
8
- get(moduleName: string, clazzName: string): TableModel | undefined;
9
- set(moduleName: string, tableModel: TableModel): void;
10
- clear(): void;
11
- }
12
- //#endregion
1
+ import { TableModelManager } from "../TableModelManager-D9HmMlTB.js";
13
2
  export { TableModelManager };
@@ -1,27 +1,3 @@
1
- import { TableModel } from "@eggjs/dal-decorator";
1
+ import { TableModelManager } from "../TableModelManager-C9FVu5zw.js";
2
2
 
3
- //#region src/lib/TableModelManager.ts
4
- var TableModelManager = class TableModelManager {
5
- static instance = new TableModelManager();
6
- tableModels;
7
- constructor() {
8
- this.tableModels = /* @__PURE__ */ new Map();
9
- }
10
- get(moduleName, clazzName) {
11
- return this.tableModels.get(moduleName)?.get(clazzName);
12
- }
13
- set(moduleName, tableModel) {
14
- let tables = this.tableModels.get(moduleName);
15
- if (!tables) {
16
- tables = /* @__PURE__ */ new Map();
17
- this.tableModels.set(moduleName, tables);
18
- }
19
- tables.set(tableModel.clazz.name, tableModel);
20
- }
21
- clear() {
22
- this.tableModels.clear();
23
- }
24
- };
25
-
26
- //#endregion
27
3
  export { TableModelManager };
@@ -1,12 +1,2 @@
1
- import { LifecycleHook, Logger, ModuleConfigHolder } from "@eggjs/tegg";
2
- import { EggPrototype, EggPrototypeLifecycleContext } from "@eggjs/tegg-metadata";
3
-
4
- //#region src/lib/TransactionPrototypeHook.d.ts
5
- declare class TransactionPrototypeHook implements LifecycleHook<EggPrototypeLifecycleContext, EggPrototype> {
6
- private readonly moduleConfigs;
7
- private readonly logger;
8
- constructor(moduleConfigs: Record<string, ModuleConfigHolder>, logger: Logger);
9
- preCreate(ctx: EggPrototypeLifecycleContext): Promise<void>;
10
- }
11
- //#endregion
1
+ import { TransactionPrototypeHook } from "../TransactionPrototypeHook-Cz3trnvZ.js";
12
2
  export { TransactionPrototypeHook };
@@ -1,50 +1,5 @@
1
- import { MysqlDataSourceManager } from "./MysqlDataSourceManager.js";
2
- import { TransactionalAOP } from "./TransactionalAOP.js";
3
- import "@eggjs/tegg";
4
- import assert from "node:assert";
5
- import "@eggjs/tegg-metadata";
6
- import { PropagationType, TransactionMetaBuilder } from "@eggjs/tegg/transaction";
7
- import { Pointcut } from "@eggjs/tegg/aop";
1
+ import "../MysqlDataSourceManager-Bl5dlpX7.js";
2
+ import "../TransactionalAOP-Bm-mjuDZ.js";
3
+ import { TransactionPrototypeHook } from "../TransactionPrototypeHook-_PXHgwHf.js";
8
4
 
9
- //#region src/lib/TransactionPrototypeHook.ts
10
- var TransactionPrototypeHook = class {
11
- moduleConfigs;
12
- logger;
13
- constructor(moduleConfigs, logger) {
14
- this.moduleConfigs = moduleConfigs;
15
- this.logger = logger;
16
- }
17
- async preCreate(ctx) {
18
- const transactionMetadataList = new TransactionMetaBuilder(ctx.clazz).build();
19
- if (transactionMetadataList.length < 1) return;
20
- const moduleName = ctx.loadUnit.name;
21
- for (const transactionMetadata of transactionMetadataList) {
22
- const clazzName = `${moduleName}.${ctx.clazz.name}.${String(transactionMetadata.method)}`;
23
- const datasourceConfigs = (this.moduleConfigs[moduleName]?.config)?.dataSource || {};
24
- let datasourceName;
25
- if (transactionMetadata.datasourceName) {
26
- assert(datasourceConfigs[transactionMetadata.datasourceName], `method ${clazzName} specified datasource ${transactionMetadata.datasourceName} not exists`);
27
- datasourceName = transactionMetadata.datasourceName;
28
- this.logger.info(`use datasource [${transactionMetadata.datasourceName}] for class ${clazzName}`);
29
- } else {
30
- const dataSources = Object.keys(datasourceConfigs);
31
- if (dataSources.length === 1) datasourceName = dataSources[0];
32
- else throw new Error(`method ${clazzName} not specified datasource, module ${moduleName} has multi datasource, should specify datasource name`);
33
- this.logger.info(`use default datasource ${dataSources[0]} for class ${clazzName}`);
34
- }
35
- const adviceParams = {
36
- propagation: transactionMetadata.propagation,
37
- dataSourceGetter: () => {
38
- const mysqlDataSource = MysqlDataSourceManager.instance.get(moduleName, datasourceName);
39
- if (!mysqlDataSource) throw new Error(`method ${clazzName} not found datasource ${datasourceName}`);
40
- return mysqlDataSource;
41
- }
42
- };
43
- assert(adviceParams.propagation === PropagationType.REQUIRED, "Transactional propagation only support required for now");
44
- Pointcut(TransactionalAOP, { adviceParams })(ctx.clazz.prototype, transactionMetadata.method);
45
- }
46
- }
47
- };
48
-
49
- //#endregion
50
5
  export { TransactionPrototypeHook };
@@ -1,15 +1,2 @@
1
- import { EggProtoImplClass } from "@eggjs/tegg";
2
- import { MysqlDataSource } from "@eggjs/dal-runtime";
3
- import { PropagationType } from "@eggjs/tegg/transaction";
4
- import { AdviceContext, IAdvice } from "@eggjs/tegg/aop";
5
-
6
- //#region src/lib/TransactionalAOP.d.ts
7
- interface TransactionalParams {
8
- propagation: PropagationType;
9
- dataSourceGetter: () => MysqlDataSource;
10
- }
11
- declare class TransactionalAOP implements IAdvice<EggProtoImplClass, TransactionalParams> {
12
- around(ctx: AdviceContext<EggProtoImplClass, TransactionalParams>, next: () => Promise<any>): Promise<void>;
13
- }
14
- //#endregion
1
+ import { TransactionalAOP, TransactionalParams } from "../TransactionalAOP-CRvc1-Sf.js";
15
2
  export { TransactionalAOP, TransactionalParams };
@@ -1,22 +1,3 @@
1
- import { __decorate } from "../_virtual/_@oxc-project_runtime@0.93.0/helpers/decorate.js";
2
- import { AccessLevel, ObjectInitType } from "@eggjs/tegg";
3
- import { MysqlDataSource } from "@eggjs/dal-runtime";
4
- import { PropagationType } from "@eggjs/tegg/transaction";
5
- import { Advice } from "@eggjs/tegg/aop";
1
+ import { TransactionalAOP } from "../TransactionalAOP-Bm-mjuDZ.js";
6
2
 
7
- //#region src/lib/TransactionalAOP.ts
8
- let TransactionalAOP = class TransactionalAOP$1 {
9
- async around(ctx, next) {
10
- const { propagation, dataSourceGetter } = ctx.adviceParams;
11
- const dataSource = dataSourceGetter();
12
- if (propagation === PropagationType.ALWAYS_NEW) return await dataSource.beginTransactionScope(next);
13
- return await dataSource.beginTransactionScope(next);
14
- }
15
- };
16
- TransactionalAOP = __decorate([Advice({
17
- accessLevel: AccessLevel.PUBLIC,
18
- initType: ObjectInitType.SINGLETON
19
- })], TransactionalAOP);
20
-
21
- //#endregion
22
3
  export { TransactionalAOP };
@@ -0,0 +1 @@
1
+ import "@eggjs/tegg-plugin/types";
@@ -0,0 +1,3 @@
1
+ import "@eggjs/tegg-plugin/types";
2
+
3
+ export { };
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- import "@eggjs/tegg-plugin/types";
1
+ import "./types-CSwhn03Z.js";
package/dist/types.js CHANGED
@@ -1,3 +1,3 @@
1
- import "@eggjs/tegg-plugin/types";
1
+ import "./types-Ct3xXZX7.js";
2
2
 
3
3
  export { };
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "eggModule": {
11
11
  "name": "teggDal"
12
12
  },
13
- "version": "4.0.0-beta.7",
13
+ "version": "4.0.0-beta.8",
14
14
  "description": "dal plugin for egg",
15
15
  "keywords": [
16
16
  "egg",
@@ -51,14 +51,14 @@
51
51
  "node": ">=22.18.0"
52
52
  },
53
53
  "dependencies": {
54
- "@eggjs/dal-runtime": "4.0.0-beta.7",
55
- "@eggjs/tegg": "4.0.0-beta.7",
56
- "@eggjs/tegg-metadata": "4.0.0-beta.7",
57
- "@eggjs/dal-decorator": "4.0.0-beta.7"
54
+ "@eggjs/tegg": "4.0.0-beta.8",
55
+ "@eggjs/dal-runtime": "4.0.0-beta.8",
56
+ "@eggjs/tegg-metadata": "4.0.0-beta.8",
57
+ "@eggjs/dal-decorator": "4.0.0-beta.8"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "egg": "beta",
61
- "@eggjs/tegg-plugin": "4.0.0-beta.7"
61
+ "@eggjs/tegg-plugin": "4.0.0-beta.8"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@eggjs/bin": "beta",
@@ -72,9 +72,9 @@
72
72
  "typescript": "^5.9.3",
73
73
  "tsdown": "^0.15.6",
74
74
  "unplugin-unused": "^0.5.3",
75
- "@eggjs/tegg-aop-plugin": "4.0.0-beta.7",
76
- "@eggjs/tegg-plugin": "4.0.0-beta.7",
77
- "@eggjs/tegg-config": "4.0.0-beta.7"
75
+ "@eggjs/tegg-aop-plugin": "4.0.0-beta.8",
76
+ "@eggjs/tegg-config": "4.0.0-beta.8",
77
+ "@eggjs/tegg-plugin": "4.0.0-beta.8"
78
78
  },
79
79
  "publishConfig": {
80
80
  "access": "public"
@@ -1,10 +0,0 @@
1
- //#region \0@oxc-project+runtime@0.93.0/helpers/decorate.js
2
- function __decorate(decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- }
8
-
9
- //#endregion
10
- export { __decorate };
@@ -1,7 +0,0 @@
1
- //#region \0@oxc-project+runtime@0.93.0/helpers/decorateMetadata.js
2
- function __decorateMetadata(k, v) {
3
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4
- }
5
-
6
- //#endregion
7
- export { __decorateMetadata };
@@ -1,9 +0,0 @@
1
- //#region \0@oxc-project+runtime@0.93.0/helpers/decorateParam.js
2
- function __decorateParam(paramIndex, decorator) {
3
- return function(target, key) {
4
- decorator(target, key, paramIndex);
5
- };
6
- }
7
-
8
- //#endregion
9
- export { __decorateParam };