diff --git a/core/dal-decorator/src/type/MySql.ts b/core/dal-decorator/src/type/MySql.ts index f6bd1a96..674a978c 100644 --- a/core/dal-decorator/src/type/MySql.ts +++ b/core/dal-decorator/src/type/MySql.ts @@ -1 +1 @@ -export { InsertResult, UpdateResult, DeleteResult } from '@eggjs/rds/lib/types'; +export { InsertResult, UpdateResult, DeleteResult } from '@eggjs/rds'; diff --git a/core/dal-runtime/src/CodeGenerator.ts b/core/dal-runtime/src/CodeGenerator.ts index 58c5139a..329917b5 100644 --- a/core/dal-runtime/src/CodeGenerator.ts +++ b/core/dal-runtime/src/CodeGenerator.ts @@ -11,6 +11,8 @@ import { SqlGenerator } from './SqlGenerator'; export interface CodeGeneratorOptions { moduleDir: string; moduleName: string; + teggPkg?: string; + dalPkg?: string; } export enum Templates { @@ -22,10 +24,14 @@ export enum Templates { export class CodeGenerator { private readonly moduleDir: string; private readonly moduleName: string; + private readonly teggPkg: string; + private readonly dalPkg: string; constructor(options: CodeGeneratorOptions) { this.moduleDir = options.moduleDir; this.moduleName = options.moduleName; + this.teggPkg = options.teggPkg ?? '@eggjs/tegg'; + this.dalPkg = options.dalPkg ?? '@eggjs/tegg/dal'; this.createNunjucksEnv(); } @@ -49,6 +55,8 @@ export class CodeGenerator { fileName: path.basename(filePath), clazzName: tableModel.clazz.name, moduleName: this.moduleName, + teggPkg: this.teggPkg, + dalPkg: this.dalPkg, id: tableModel.columns.find(t => t.propertyName === 'id'), primaryIndex: tableModel.getPrimary(), tableModelPath: TemplateUtil.importPath(tableModelAbsolutePath, path.dirname(filePath)), diff --git a/core/dal-runtime/src/templates/base_dao.njk b/core/dal-runtime/src/templates/base_dao.njk index 7c261187..89e7d096 100644 --- a/core/dal-runtime/src/templates/base_dao.njk +++ b/core/dal-runtime/src/templates/base_dao.njk @@ -68,16 +68,16 @@ Optional<{{clazzName}}, > {% endmacro %} -import type { InsertResult, UpdateResult, DeleteResult } from '@eggjs/rds/lib/types'; -import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg'; -import { DataSource, DataSourceInjectName, DataSourceQualifier, ColumnTsType } from '@eggjs/tegg/dal'; +import type { InsertResult, UpdateResult, DeleteResult } from '{{dalPkg}}'; +import { SingletonProto, AccessLevel, Inject } from '{{teggPkg}}'; +import { DataSource, DataSourceInjectName, DataSourceQualifier, ColumnTsType } from '{{dalPkg}}'; import { {{ clazzName }} } from '{{ tableModelPath }}'; // empty-line type Optional = Omit & Partial; /** * 自动生成的 {{ clazzName }}DAO 基类 * @class Base{{ clazzName }}DAO - * @classdesc 该文件由 @eggjs/tegg 自动生成,请**不要**修改它! + * @classdesc 该文件由 {{teggPkg}} 自动生成,请**不要**修改它! */ /* istanbul ignore next */ @SingletonProto({ diff --git a/core/dal-runtime/src/templates/dao.njk b/core/dal-runtime/src/templates/dao.njk index c922fd5c..2e2c6882 100644 --- a/core/dal-runtime/src/templates/dao.njk +++ b/core/dal-runtime/src/templates/dao.njk @@ -1,4 +1,4 @@ -import { SingletonProto, AccessLevel } from '@eggjs/tegg'; +import { SingletonProto, AccessLevel } from '{{teggPkg}}'; import { Base{{ clazzName }}DAO } from './base/Base{{ clazzName }}DAO'; // empty-line /** diff --git a/core/dal-runtime/src/templates/extension.njk b/core/dal-runtime/src/templates/extension.njk index e1bf00a2..f2f5e3cc 100644 --- a/core/dal-runtime/src/templates/extension.njk +++ b/core/dal-runtime/src/templates/extension.njk @@ -1,9 +1,9 @@ -import { SqlMap } from '@eggjs/tegg/dal'; +import { SqlMap } from '{{dalPkg}}'; // empty-line /** * Define Custom SQLs * - * import { SqlMap, SqlType } from '@eggjs/tegg/dal'; + * import { SqlMap, SqlType } from '{{dalPkg}}'; * * export default { * findByName: { diff --git a/core/dal-runtime/test/CodeGenerator.test.ts b/core/dal-runtime/test/CodeGenerator.test.ts index 8358b782..39a16036 100644 --- a/core/dal-runtime/test/CodeGenerator.test.ts +++ b/core/dal-runtime/test/CodeGenerator.test.ts @@ -10,6 +10,7 @@ describe('test/CodeGenerator.test.ts', () => { const generator = new CodeGenerator({ moduleDir: path.join(__dirname, './fixtures/modules/generate_codes'), moduleName: 'dal', + dalPkg: '@eggjs/dal-decorator', }); const fooModel = TableModel.build(Foo); await generator.generate(fooModel); diff --git a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/dao/base/BaseFooDAO.ts b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/dao/base/BaseFooDAO.ts index 37e63098..a33326ee 100644 --- a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/dao/base/BaseFooDAO.ts +++ b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/dao/base/BaseFooDAO.ts @@ -1,6 +1,6 @@ -import type { InsertResult, UpdateResult, DeleteResult } from '@eggjs/rds/lib/types'; +import type { InsertResult, UpdateResult, DeleteResult } from '@eggjs/dal-decorator'; import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg'; -import { DataSource, DataSourceInjectName, DataSourceQualifier, ColumnTsType } from '@eggjs/tegg/dal'; +import { DataSource, DataSourceInjectName, DataSourceQualifier, ColumnTsType } from '@eggjs/dal-decorator'; import { Foo } from '../../../Foo'; type Optional = Omit < T, K > & Partial ; diff --git a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/dao/base/BaseMultiPrimaryKeyDAO.ts b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/dao/base/BaseMultiPrimaryKeyDAO.ts index 355c3bfe..58d5bee8 100644 --- a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/dao/base/BaseMultiPrimaryKeyDAO.ts +++ b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/dao/base/BaseMultiPrimaryKeyDAO.ts @@ -1,6 +1,6 @@ -import type { InsertResult, UpdateResult, DeleteResult } from '@eggjs/rds/lib/types'; +import type { InsertResult, UpdateResult, DeleteResult } from '@eggjs/dal-decorator'; import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg'; -import { DataSource, DataSourceInjectName, DataSourceQualifier, ColumnTsType } from '@eggjs/tegg/dal'; +import { DataSource, DataSourceInjectName, DataSourceQualifier, ColumnTsType } from '@eggjs/dal-decorator'; import { MultiPrimaryKey } from '../../../MultiPrimaryKey'; type Optional = Omit < T, K > & Partial ; diff --git a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/extension/FooExtension.ts b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/extension/FooExtension.ts index 24c2e288..f8ce78d3 100644 --- a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/extension/FooExtension.ts +++ b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/extension/FooExtension.ts @@ -1,9 +1,9 @@ -import { SqlMap } from '@eggjs/tegg/dal'; +import { SqlMap } from '@eggjs/dal-decorator'; /** * Define Custom SQLs * - * import { SqlMap, SqlType } from '@eggjs/tegg/dal'; + * import { SqlMap, SqlType } from '@eggjs/dal-decorator'; * * export default { * findByName: { diff --git a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/extension/MultiPrimaryKeyExtension.ts b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/extension/MultiPrimaryKeyExtension.ts index 24c2e288..f8ce78d3 100644 --- a/core/dal-runtime/test/fixtures/modules/generate_codes/dal/extension/MultiPrimaryKeyExtension.ts +++ b/core/dal-runtime/test/fixtures/modules/generate_codes/dal/extension/MultiPrimaryKeyExtension.ts @@ -1,9 +1,9 @@ -import { SqlMap } from '@eggjs/tegg/dal'; +import { SqlMap } from '@eggjs/dal-decorator'; /** * Define Custom SQLs * - * import { SqlMap, SqlType } from '@eggjs/tegg/dal'; + * import { SqlMap, SqlType } from '@eggjs/dal-decorator'; * * export default { * findByName: {