From 334e13d7ebb0a9d6af6987e8e91f5053a3b52dfa Mon Sep 17 00:00:00 2001 From: Gxkl Date: Wed, 17 Apr 2024 16:54:34 +0800 Subject: [PATCH] refactor: add types package (#205) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ##### Checklist - [ ] `npm test` passes - [ ] tests and/or benchmarks are included - [ ] documentation is changed or added - [ ] commit message follows commit guidelines ##### Affected core subsystem(s) ##### Description of change --- core/aop-decorator/index.ts | 1 + core/aop-decorator/package.json | 3 +- core/aop-decorator/src/AspectMetaBuilder.ts | 2 +- .../src/CrosscutAdviceFactory.ts | 6 +- core/aop-decorator/src/decorator/Advice.ts | 55 +--- core/aop-decorator/src/decorator/Crosscut.ts | 41 +-- core/aop-decorator/src/decorator/Pointcut.ts | 9 +- core/aop-decorator/src/model/Aspect.ts | 15 +- core/aop-decorator/src/model/PointcutInfo.ts | 26 +- core/aop-decorator/src/util/AdviceInfoUtil.ts | 4 +- core/aop-decorator/src/util/AspectInfoUtil.ts | 7 +- .../src/util/CrosscutInfoUtil.ts | 15 +- .../src/util/PointcutAdviceInfoUtil.ts | 9 +- .../test/AspectMetaBuilder.test.ts | 7 +- .../test/fixtures/CrosscutExample.ts | 6 +- .../test/fixtures/InheritExample.ts | 5 +- .../test/fixtures/PointcutExample.ts | 3 +- core/aop-runtime/package.json | 1 + core/aop-runtime/src/AspectExecutor.ts | 2 +- core/aop-runtime/src/EggObjectAopHook.ts | 6 +- .../src/EggPrototypeCrossCutHook.ts | 3 +- core/aop-runtime/src/LoadUnitAopHook.ts | 18 +- core/aop-runtime/test/aop-runtime.test.ts | 10 +- .../fixtures/modules/hello_succeed/Hello.ts | 7 +- .../fixtures/modules/should_throw/Hello.ts | 3 +- core/background-task/package.json | 3 +- .../src/BackgroundTaskHelper.ts | 7 +- .../test/BackgroundTaskHelper.test.ts | 4 +- core/common-util/index.ts | 2 +- core/common-util/package.json | 1 + core/common-util/src/Graph.ts | 6 +- core/common-util/src/ModuleConfig.ts | 47 +--- core/common-util/src/ModuleConfigs.ts | 8 +- core/common-util/test/MapUtil.test.ts | 2 +- core/common-util/test/ModuleConfig.test.ts | 4 +- core/common-util/test/NameUtil.test.ts | 2 +- core/common-util/test/ObjectUtil.test.ts | 2 +- core/common-util/test/ProtoGraph.test.ts | 5 +- core/common-util/test/TimerUtil.test.ts | 2 +- core/controller-decorator/index.ts | 2 +- core/controller-decorator/package.json | 1 + .../src/builder/ControllerMetaBuilder.ts | 5 - .../builder/ControllerMetaBuilderFactory.ts | 11 +- .../controller-decorator/src/decorator/Acl.ts | 4 +- .../src/decorator/Context.ts | 4 +- .../src/decorator/Middleware.ts | 5 +- .../src/decorator/http/HTTPController.ts | 13 +- .../src/decorator/http/HTTPMethod.ts | 12 +- .../src/decorator/http/HTTPParam.ts | 18 +- .../src/decorator/http/Host.ts | 5 +- .../impl/http/HTTPControllerMetaBuilder.ts | 16 +- .../http/HTTPControllerMethodMetaBuilder.ts | 6 +- .../src/model/HTTPControllerMeta.ts | 7 +- .../src/model/HTTPMethodMeta.ts | 6 +- core/controller-decorator/src/model/index.ts | 4 - .../src/util/ControllerInfoUtil.ts | 17 +- .../src/util/ControllerMetadataUtil.ts | 7 +- .../src/util/HTTPInfoUtil.ts | 19 +- .../src/util/MethodInfoUtil.ts | 17 +- .../src/util/validator/ControllerValidator.ts | 4 +- .../src/util/validator/MethodValidator.ts | 4 +- core/controller-decorator/test/Acl.test.ts | 5 +- .../controller-decorator/test/Context.test.ts | 2 +- .../test/Middleware.test.ts | 2 +- .../test/fixtures/AclController.ts | 2 +- .../test/fixtures/HTTPFooController.ts | 7 +- .../test/fixtures/HTTPPriorityController.ts | 3 +- .../test/fixtures/MiddlewareController.ts | 2 +- .../test/http/HTTPMeta.test.ts | 5 +- .../test/http/Host.test.ts | 2 +- .../test/util/ControllerMetadataUtil.test.ts | 7 +- .../test/util/HTTPPriority.test.ts | 2 +- core/core-decorator/index.ts | 10 +- core/core-decorator/package.json | 1 + .../src/decorator/ConfigSource.ts | 5 +- .../src/decorator/ContextProto.ts | 10 +- .../src/decorator/EggQualifier.ts | 6 +- .../src/decorator/InitTypeQualifier.ts | 6 +- core/core-decorator/src/decorator/Inject.ts | 8 +- .../src/decorator/ModuleQualifier.ts | 5 +- .../src/decorator/MultiInstanceProto.ts | 43 +-- .../core-decorator/src/decorator/Prototype.ts | 17 +- .../src/decorator/SingletonProto.ts | 10 +- core/core-decorator/src/util/MetadataUtil.ts | 3 +- core/core-decorator/src/util/PrototypeUtil.ts | 15 +- core/core-decorator/src/util/QualifierUtil.ts | 9 +- core/core-decorator/test/decorators.test.ts | 21 +- .../test/fixtures/decators/ContextCache.ts | 3 +- .../test/fixtures/decators/FooLogger.ts | 3 +- .../decators/QualifierCacheService.ts | 3 +- .../test/fixtures/decators/SingletonCache.ts | 3 +- .../test/util/MetadataUtil.test.ts | 2 +- core/dal-decorator/index.ts | 10 +- core/dal-decorator/package.json | 1 + core/dal-decorator/src/decorator/Column.ts | 261 +----------------- .../src/decorator/DataSourceQualifier.ts | 7 +- core/dal-decorator/src/decorator/Index.ts | 15 +- core/dal-decorator/src/decorator/Table.ts | 32 +-- core/dal-decorator/src/model/ColumnModel.ts | 3 +- core/dal-decorator/src/model/IndexModel.ts | 5 +- core/dal-decorator/src/model/TableModel.ts | 11 +- core/dal-decorator/src/type/Spatial.ts | 17 +- core/dal-decorator/src/util/ColumnInfoUtil.ts | 7 +- core/dal-decorator/src/util/IndexInfoUtil.ts | 7 +- core/dal-decorator/src/util/TableInfoUtil.ts | 8 +- .../test/fixtures/modules/dal/Foo.ts | 3 +- core/dal-decorator/test/index.test.ts | 3 +- core/dal-runtime/package.json | 1 + core/dal-runtime/src/BaseSqlMap.ts | 11 +- core/dal-runtime/src/CodeGenerator.ts | 23 +- core/dal-runtime/src/DataSource.ts | 3 +- core/dal-runtime/src/DatabaseForker.ts | 4 +- core/dal-runtime/src/SqlGenerator.ts | 7 +- core/dal-runtime/src/SqlMapLoader.ts | 4 +- core/dal-runtime/src/TableSqlMap.ts | 3 +- core/dal-runtime/src/TemplateUtil.ts | 13 +- core/dal-runtime/test/DAO.test.ts | 4 +- core/dal-runtime/test/DataSource.test.ts | 6 +- core/dal-runtime/test/SqlGenerator.test.ts | 2 +- .../test/fixtures/modules/dal/Foo.ts | 9 +- .../fixtures/modules/generate_codes/Foo.ts | 9 +- core/dynamic-inject-runtime/package.json | 3 +- .../src/EggObjectFactory.ts | 12 +- .../src/EggObjectFactoryObject.ts | 12 +- .../src/EggObjectFactoryPrototype.ts | 28 +- core/dynamic-inject/index.ts | 3 +- core/dynamic-inject/package.json | 3 +- core/dynamic-inject/src/EggObjectFactory.ts | 8 - .../src/QualifierImplDecoratorUtil.ts | 10 +- core/dynamic-inject/src/QualifierImplUtil.ts | 8 +- core/dynamic-inject/src/typing.ts | 1 - core/eventbus-decorator/package.json | 1 + core/eventbus-decorator/src/EventContext.ts | 6 +- core/eventbus-decorator/src/EventInfoUtil.ts | 3 +- core/eventbus-runtime/package.json | 1 + .../src/EventContextFactory.ts | 9 +- .../src/EventHandlerFactory.ts | 5 +- .../eventbus-runtime/src/SingletonEventBus.ts | 14 +- core/lifecycle/index.ts | 3 +- core/lifecycle/package.json | 3 +- core/lifecycle/src/IdenticalObject.ts | 6 +- core/lifecycle/src/LifycycleUtil.ts | 15 +- core/lifecycle/src/decorator/index.ts | 4 +- core/loader/package.json | 1 + core/loader/src/LoaderFactory.ts | 2 +- core/loader/src/LoaderUtil.ts | 3 +- core/loader/src/impl/ModuleLoader.ts | 7 +- core/metadata/index.ts | 3 +- core/metadata/package.json | 1 + core/metadata/src/enum/EggLoadUnitType.ts | 7 - core/metadata/src/errors.ts | 9 +- .../src/factory/EggPrototypeCreatorFactory.ts | 15 +- .../src/factory/EggPrototypeFactory.ts | 10 +- core/metadata/src/factory/LoadUnitFactory.ts | 21 +- core/metadata/src/impl/EggPrototypeBuilder.ts | 42 ++- core/metadata/src/impl/EggPrototypeImpl.ts | 17 +- .../impl/LoadUnitMultiInstanceProtoHook.ts | 11 +- core/metadata/src/impl/ModuleLoadUnit.ts | 28 +- core/metadata/src/model/AppGraph.ts | 16 +- core/metadata/src/model/EggPrototype.ts | 75 +---- core/metadata/src/model/LoadUnit.ts | 25 +- core/metadata/src/util/ClassUtil.ts | 3 +- core/orm-decorator/index.ts | 2 +- core/orm-decorator/package.json | 1 + .../src/builder/AttributeMetaBuilder.ts | 4 +- .../src/builder/IndexMetaBuilder.ts | 4 +- .../src/builder/ModelMetaBuilder.ts | 2 +- core/orm-decorator/src/decorator/Attribute.ts | 17 +- .../orm-decorator/src/decorator/DataSource.ts | 2 +- core/orm-decorator/src/decorator/Index.ts | 8 +- core/orm-decorator/src/decorator/Model.ts | 11 +- core/orm-decorator/src/util/ModelInfoUtil.ts | 34 +-- .../src/util/ModelMetadataUtil.ts | 3 +- core/runtime/index.ts | 3 +- core/runtime/package.json | 3 +- .../src/factory/EggContainerFactory.ts | 20 +- core/runtime/src/factory/EggObjectFactory.ts | 15 +- .../src/factory/LoadUnitInstanceFactory.ts | 12 +- core/runtime/src/impl/ContextInitiator.ts | 9 +- core/runtime/src/impl/ContextObjectGraph.ts | 4 +- .../src/impl/EggAlwaysNewObjectContainer.ts | 7 +- core/runtime/src/impl/EggObjectImpl.ts | 9 +- core/runtime/src/impl/EggObjectUtil.ts | 3 +- .../src/impl/ModuleLoadUnitInstance.ts | 20 +- core/runtime/src/model/AbstractEggContext.ts | 11 +- core/runtime/src/model/ContextHandler.ts | 12 +- core/runtime/src/model/EggContext.ts | 13 +- core/runtime/src/model/EggObject.ts | 30 +- core/runtime/src/model/LoadUnitInstance.ts | 12 +- core/runtime/test/EggObject.test.ts | 4 +- core/runtime/test/EggObjectUtil.test.ts | 4 +- core/runtime/test/LoadUnitInstance.test.ts | 7 +- .../test/QualifierLoadUnitInstance.test.ts | 6 +- .../test/fixtures/EggContextStorage.ts | 8 +- .../CacheService.ts | 3 +- .../inject-context-to-singleton/object.ts | 3 +- .../fixtures/modules/lifecycle-hook/object.ts | 4 +- .../CountController.ts | 3 +- .../module-for-load-unit-instance/TempObj.ts | 3 +- .../multi-instance-module/MultiInstance.ts | 5 +- .../multi-module/multi-module-repo/AppRepo.ts | 3 +- .../multi-module-repo/PersistenceService.ts | 3 +- core/runtime/test/util.ts | 7 +- core/schedule-decorator/index.ts | 1 + core/schedule-decorator/package.json | 1 + .../src/builder/ScheduleMetaBuilder.ts | 3 +- .../src/decorator/Schedule.ts | 35 +-- .../src/model/ScheduleMetadata.ts | 7 +- .../src/util/ScheduleInfoUtil.ts | 9 +- .../src/util/ScheduleMetadataUtil.ts | 6 +- core/standalone-decorator/src/typing.ts | 1 - .../src/util/StandaloneUtil.ts | 1 - core/tegg/index.ts | 9 +- core/tegg/package.json | 3 +- core/transaction-decorator/index.ts | 3 +- core/transaction-decorator/package.json | 3 +- .../src/builder/TransactionMetaBuilder.ts | 3 +- .../src/decorator/Transactional.ts | 4 +- .../src/model/TransactionMetadata.ts | 7 - .../src/util/TransactionMetadataUtil.ts | 9 +- .../builder/TransactionMetaBuilder.test.ts | 4 +- .../test/fixtures/transaction.ts | 2 +- core/types/README.md | 15 + core/types/aop/Advice.ts | 42 +++ core/types/aop/Aspect.ts | 16 ++ core/types/aop/Crosscut.ts | 38 +++ core/types/aop/Pointcut.ts | 32 +++ core/types/aop/index.ts | 4 + core/types/common/Graph.ts | 3 + core/types/common/Logger.ts | 7 + core/types/common/ModuleConfig.ts | 34 +++ .../src => types/common}/RuntimeConfig.ts | 0 core/types/common/index.ts | 4 + .../controller-decorator/HTTPController.ts | 5 + core/types/controller-decorator/HTTPMethod.ts | 7 + core/types/controller-decorator/HTTPParam.ts | 11 + .../types/controller-decorator/MetadataKey.ts | 20 ++ core/types/controller-decorator/builder.ts | 8 + core/types/controller-decorator/index.ts | 8 + .../model/ControllerMetadata.ts | 2 +- .../controller-decorator}/model/MethodMeta.ts | 0 .../controller-decorator}/model/types.ts | 1 + core/types/core-decorator/ContextProto.ts | 7 + core/types/core-decorator/Inject.ts | 4 + core/types/core-decorator/Metadata.ts | 1 + .../core-decorator/MultiInstanceProto.ts | 31 +++ core/types/core-decorator/Prototype.ts | 11 + core/types/core-decorator/SingletonProto.ts | 7 + .../core-decorator}/enum/AccessLevel.ts | 0 .../core-decorator}/enum/EggType.ts | 0 .../core-decorator}/enum/ObjectInitType.ts | 0 core/types/core-decorator/enum/Qualifier.ts | 11 + core/types/core-decorator/index.ts | 16 ++ .../model/EggMultiInstancePrototypeInfo.ts | 0 .../core-decorator}/model/EggPrototypeInfo.ts | 0 .../core-decorator}/model/InjectObjectInfo.ts | 0 .../core-decorator}/model/QualifierInfo.ts | 0 core/types/dal/Qualifier.ts | 5 + core/types/dal/decorator/Column.ts | 259 +++++++++++++++++ .../dal/decorator/DataSourceQualifier.ts | 2 + core/types/dal/decorator/Index.ts | 13 + core/types/dal/decorator/Table.ts | 25 ++ .../src => types/dal}/enum/ColumnFormat.ts | 0 .../src => types/dal}/enum/ColumnType.ts | 0 .../src => types/dal}/enum/CompressionType.ts | 0 .../src => types/dal}/enum/IndexStoreType.ts | 0 .../src => types/dal}/enum/IndexType.ts | 0 .../src => types/dal}/enum/InsertMethod.ts | 0 .../src => types/dal}/enum/RowFormat.ts | 0 core/types/dal/enum/SqlType.ts | 7 + core/types/dal/enum/Templates.ts | 5 + core/types/dal/index.ts | 21 ++ core/types/dal/type/CodeGenerator.ts | 6 + .../src => types/dal}/type/ColumnTsType.ts | 0 .../src => types/dal}/type/DateSource.ts | 1 - core/types/dal/type/Spatial.ts | 13 + .../src => types/dal}/type/SqlMap.ts | 14 +- core/types/dynamic-inject.ts | 15 + core/types/index.ts | 12 + .../lifecycle}/EggObjectLifecycle.ts | 2 + core/types/lifecycle/IdenticalObject.ts | 5 + .../src => types/lifecycle}/LifecycleHook.ts | 0 core/types/lifecycle/index.ts | 4 + core/types/metadata/errors.ts | 5 + core/types/metadata/index.ts | 4 + core/types/metadata/model/EggPrototype.ts | 98 +++++++ core/types/metadata/model/LoadUnit.ts | 36 +++ .../src => types/metadata}/model/Loader.ts | 2 +- core/types/orm.ts | 41 +++ core/types/package.json | 48 ++++ core/types/runtime/Factory.ts | 9 + core/types/runtime/index.ts | 5 + .../runtime}/model/EggContainer.ts | 6 +- core/types/runtime/model/EggContext.ts | 10 + core/types/runtime/model/EggObject.ts | 28 ++ core/types/runtime/model/LoadUnitInstance.ts | 11 + core/types/schedule.ts | 41 +++ .../src/Common.ts => types/transaction.ts} | 9 + core/types/tsconfig.json | 12 + core/types/tsconfig.pub.json | 12 + .../app/controller/AppController.ts | 3 +- .../fixtures/apps/dal-app/modules/dal/Foo.ts | 9 +- .../test/fixtures/dal-module/Foo.ts | 9 +- 303 files changed, 1808 insertions(+), 1500 deletions(-) delete mode 100644 core/controller-decorator/src/builder/ControllerMetaBuilder.ts delete mode 100644 core/dynamic-inject/src/EggObjectFactory.ts delete mode 100644 core/dynamic-inject/src/typing.ts delete mode 100644 core/metadata/src/enum/EggLoadUnitType.ts delete mode 100644 core/transaction-decorator/src/model/TransactionMetadata.ts create mode 100644 core/types/README.md create mode 100644 core/types/aop/Advice.ts create mode 100644 core/types/aop/Aspect.ts create mode 100644 core/types/aop/Crosscut.ts create mode 100644 core/types/aop/Pointcut.ts create mode 100644 core/types/aop/index.ts create mode 100644 core/types/common/Graph.ts create mode 100644 core/types/common/Logger.ts create mode 100644 core/types/common/ModuleConfig.ts rename core/{common-util/src => types/common}/RuntimeConfig.ts (100%) create mode 100644 core/types/common/index.ts create mode 100644 core/types/controller-decorator/HTTPController.ts create mode 100644 core/types/controller-decorator/HTTPMethod.ts create mode 100644 core/types/controller-decorator/HTTPParam.ts create mode 100644 core/types/controller-decorator/MetadataKey.ts create mode 100644 core/types/controller-decorator/builder.ts create mode 100644 core/types/controller-decorator/index.ts rename core/{controller-decorator/src => types/controller-decorator}/model/ControllerMetadata.ts (86%) rename core/{controller-decorator/src => types/controller-decorator}/model/MethodMeta.ts (100%) rename core/{controller-decorator/src => types/controller-decorator}/model/types.ts (97%) create mode 100644 core/types/core-decorator/ContextProto.ts create mode 100644 core/types/core-decorator/Inject.ts create mode 100644 core/types/core-decorator/Metadata.ts create mode 100644 core/types/core-decorator/MultiInstanceProto.ts create mode 100644 core/types/core-decorator/Prototype.ts create mode 100644 core/types/core-decorator/SingletonProto.ts rename core/{core-decorator/src => types/core-decorator}/enum/AccessLevel.ts (100%) rename core/{core-decorator/src => types/core-decorator}/enum/EggType.ts (100%) rename core/{core-decorator/src => types/core-decorator}/enum/ObjectInitType.ts (100%) create mode 100644 core/types/core-decorator/enum/Qualifier.ts create mode 100644 core/types/core-decorator/index.ts rename core/{core-decorator/src => types/core-decorator}/model/EggMultiInstancePrototypeInfo.ts (100%) rename core/{core-decorator/src => types/core-decorator}/model/EggPrototypeInfo.ts (100%) rename core/{core-decorator/src => types/core-decorator}/model/InjectObjectInfo.ts (100%) rename core/{core-decorator/src => types/core-decorator}/model/QualifierInfo.ts (100%) create mode 100644 core/types/dal/Qualifier.ts create mode 100644 core/types/dal/decorator/Column.ts create mode 100644 core/types/dal/decorator/DataSourceQualifier.ts create mode 100644 core/types/dal/decorator/Index.ts create mode 100644 core/types/dal/decorator/Table.ts rename core/{dal-decorator/src => types/dal}/enum/ColumnFormat.ts (100%) rename core/{dal-decorator/src => types/dal}/enum/ColumnType.ts (100%) rename core/{dal-decorator/src => types/dal}/enum/CompressionType.ts (100%) rename core/{dal-decorator/src => types/dal}/enum/IndexStoreType.ts (100%) rename core/{dal-decorator/src => types/dal}/enum/IndexType.ts (100%) rename core/{dal-decorator/src => types/dal}/enum/InsertMethod.ts (100%) rename core/{dal-decorator/src => types/dal}/enum/RowFormat.ts (100%) create mode 100644 core/types/dal/enum/SqlType.ts create mode 100644 core/types/dal/enum/Templates.ts create mode 100644 core/types/dal/index.ts create mode 100644 core/types/dal/type/CodeGenerator.ts rename core/{dal-decorator/src => types/dal}/type/ColumnTsType.ts (100%) rename core/{dal-decorator/src => types/dal}/type/DateSource.ts (99%) create mode 100644 core/types/dal/type/Spatial.ts rename core/{dal-decorator/src => types/dal}/type/SqlMap.ts (64%) create mode 100644 core/types/dynamic-inject.ts create mode 100644 core/types/index.ts rename core/{lifecycle/src => types/lifecycle}/EggObjectLifecycle.ts (93%) create mode 100644 core/types/lifecycle/IdenticalObject.ts rename core/{lifecycle/src => types/lifecycle}/LifecycleHook.ts (100%) create mode 100644 core/types/lifecycle/index.ts create mode 100644 core/types/metadata/errors.ts create mode 100644 core/types/metadata/index.ts create mode 100644 core/types/metadata/model/EggPrototype.ts create mode 100644 core/types/metadata/model/LoadUnit.ts rename core/{metadata/src => types/metadata}/model/Loader.ts (64%) create mode 100644 core/types/orm.ts create mode 100644 core/types/package.json create mode 100644 core/types/runtime/Factory.ts create mode 100644 core/types/runtime/index.ts rename core/{runtime/src => types/runtime}/model/EggContainer.ts (78%) create mode 100644 core/types/runtime/model/EggContext.ts create mode 100644 core/types/runtime/model/EggObject.ts create mode 100644 core/types/runtime/model/LoadUnitInstance.ts create mode 100644 core/types/schedule.ts rename core/{transaction-decorator/src/Common.ts => types/transaction.ts} (70%) create mode 100644 core/types/tsconfig.json create mode 100644 core/types/tsconfig.pub.json diff --git a/core/aop-decorator/index.ts b/core/aop-decorator/index.ts index 5a6bfb22..20c5c043 100644 --- a/core/aop-decorator/index.ts +++ b/core/aop-decorator/index.ts @@ -1,3 +1,4 @@ +export * from '@eggjs/tegg-types/aop'; export * from './src/decorator/Advice'; export * from './src/decorator/Pointcut'; export * from './src/decorator/Crosscut'; diff --git a/core/aop-decorator/package.json b/core/aop-decorator/package.json index 6f5bd4cd..0124a066 100644 --- a/core/aop-decorator/package.json +++ b/core/aop-decorator/package.json @@ -18,7 +18,8 @@ "dependencies": { "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", - "@eggjs/tegg-metadata": "^3.37.1" + "@eggjs/tegg-metadata": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1" }, "scripts": { "test": "cross-env NODE_ENV=test NODE_OPTIONS='--no-deprecation' mocha", diff --git a/core/aop-decorator/src/AspectMetaBuilder.ts b/core/aop-decorator/src/AspectMetaBuilder.ts index 2cca9634..16776442 100644 --- a/core/aop-decorator/src/AspectMetaBuilder.ts +++ b/core/aop-decorator/src/AspectMetaBuilder.ts @@ -1,5 +1,5 @@ +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { CrosscutAdviceFactory } from './CrosscutAdviceFactory'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; import { Aspect, AspectBuilder } from './model/Aspect'; import { PointcutAdviceInfoUtil } from './util/PointcutAdviceInfoUtil'; diff --git a/core/aop-decorator/src/CrosscutAdviceFactory.ts b/core/aop-decorator/src/CrosscutAdviceFactory.ts index a008ccb6..e9f79dc0 100644 --- a/core/aop-decorator/src/CrosscutAdviceFactory.ts +++ b/core/aop-decorator/src/CrosscutAdviceFactory.ts @@ -1,8 +1,6 @@ -import assert from 'assert'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; -import { IAdvice } from './decorator/Advice'; +import assert from 'node:assert'; +import type { EggProtoImplClass, IAdvice, AdviceInfo } from '@eggjs/tegg-types'; import { CrosscutInfoUtil } from './util/CrosscutInfoUtil'; -import { AdviceInfo } from './model/Aspect'; export class CrosscutAdviceFactory { private readonly crosscutAdviceClazzList: Array> = []; diff --git a/core/aop-decorator/src/decorator/Advice.ts b/core/aop-decorator/src/decorator/Advice.ts index 3c79d5dd..e3c30340 100644 --- a/core/aop-decorator/src/decorator/Advice.ts +++ b/core/aop-decorator/src/decorator/Advice.ts @@ -1,55 +1,8 @@ -import { - AccessLevel, - EggProtoImplClass, - ObjectInitType, - Prototype, - PrototypeParams, PrototypeUtil, -} from '@eggjs/core-decorator'; -import { AdviceInfoUtil } from '../util/AdviceInfoUtil'; +import { Prototype, PrototypeUtil } from '@eggjs/core-decorator'; import { StackUtil } from '@eggjs/tegg-common-util'; - -export interface AdviceContext { - that: T; - method: PropertyKey; - args: any[]; - adviceParams?: K; -} - -/** - * execute order: - * 1. beforeCall - * 1. around - * 1. afterReturn/afterThrow - * 1. afterFinally - */ -export interface IAdvice { - /** - * call before function - * @param ctx - */ - beforeCall?(ctx: AdviceContext): Promise; - - /** - * call after function succeed - */ - afterReturn?(ctx: AdviceContext, result: any): Promise; - - /** - * call after function throw error - */ - afterThrow?(ctx: AdviceContext, error: Error): Promise; - - /** - * always call after function done - */ - afterFinally?(ctx: AdviceContext): Promise; - - /** - * execute the function - * the only one can modify the function return value - */ - around?(ctx: AdviceContext, next: () => Promise): Promise; -} +import { AccessLevel, ObjectInitType } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, IAdvice, PrototypeParams } from '@eggjs/tegg-types'; +import { AdviceInfoUtil } from '../util/AdviceInfoUtil'; const defaultAdviceParam = { accessLevel: AccessLevel.PUBLIC, diff --git a/core/aop-decorator/src/decorator/Crosscut.ts b/core/aop-decorator/src/decorator/Crosscut.ts index ca2f339c..cac31922 100644 --- a/core/aop-decorator/src/decorator/Crosscut.ts +++ b/core/aop-decorator/src/decorator/Crosscut.ts @@ -1,45 +1,12 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; -import { IAdvice } from './Advice'; -import { CrosscutInfo, CrosscutInfoUtil } from '../util/CrosscutInfoUtil'; -import { - ClassPointInfo, - CustomPointcutCallback, - CustomPointInfo, - NamePointInfo, - PointcutType, -} from '../model/PointcutInfo'; - -export interface CrosscutOptions { - // 默认值 100 - order?: number; - adviceParams?: any; -} +import { PointcutType } from '@eggjs/tegg-types'; +import type { CrosscutInfo, EggProtoImplClass, IAdvice, CrosscutParam, CrosscutOptions } from '@eggjs/tegg-types'; +import { CrosscutInfoUtil } from '../util/CrosscutInfoUtil'; +import { ClassPointInfo, CustomPointInfo, NamePointInfo } from '../model/PointcutInfo'; const defaultCrossOptions = { order: 100, }; -// TODO type check for methodName -export interface ClassCrosscutParam { - type: PointcutType.CLASS; - clazz: EggProtoImplClass; - methodName: PropertyKey; -} - -export interface NameCrosscutParam { - type: PointcutType.NAME; - className: RegExp; - methodName: RegExp; -} - - -export interface CustomCrosscutParam { - type: PointcutType.CUSTOM; - callback: CustomPointcutCallback; -} - -export type CrosscutParam = ClassCrosscutParam | NameCrosscutParam | CustomCrosscutParam; - export function Crosscut(param: CrosscutParam, options?: CrosscutOptions) { return function(constructor: EggProtoImplClass) { let crosscutInfo: CrosscutInfo; diff --git a/core/aop-decorator/src/decorator/Pointcut.ts b/core/aop-decorator/src/decorator/Pointcut.ts index 2ffbee8e..f0940ce4 100644 --- a/core/aop-decorator/src/decorator/Pointcut.ts +++ b/core/aop-decorator/src/decorator/Pointcut.ts @@ -1,15 +1,8 @@ -import { IAdvice } from './Advice'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass, IAdvice, PointcutOptions } from '@eggjs/tegg-types'; import { PointcutAdviceInfoUtil } from '../util/PointcutAdviceInfoUtil'; import assert from 'assert'; import { AdviceInfoUtil } from '../util/AdviceInfoUtil'; -export interface PointcutOptions { - // default is 1000 - order?: number; - adviceParams?: K; -} - const defaultPointcutOptions = { order: 1000, }; diff --git a/core/aop-decorator/src/model/Aspect.ts b/core/aop-decorator/src/model/Aspect.ts index e7bb2c0f..263c706e 100644 --- a/core/aop-decorator/src/model/Aspect.ts +++ b/core/aop-decorator/src/model/Aspect.ts @@ -1,17 +1,4 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; -import { IAdvice } from '../decorator/Advice'; - -export interface AdviceInfo { - clazz: EggProtoImplClass; - order: number; - adviceParams: any; -} - -export interface AspectAdvice { - name: string; - clazz: EggProtoImplClass; - adviceParams: any; -} +import type { AdviceInfo, AspectAdvice, EggProtoImplClass, IAdvice } from '@eggjs/tegg-types'; export class Aspect { readonly clazz: EggProtoImplClass; diff --git a/core/aop-decorator/src/model/PointcutInfo.ts b/core/aop-decorator/src/model/PointcutInfo.ts index 6444f606..9528b812 100644 --- a/core/aop-decorator/src/model/PointcutInfo.ts +++ b/core/aop-decorator/src/model/PointcutInfo.ts @@ -1,25 +1,5 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; - -export enum PointcutType { - /** - * use class type to match - */ - CLASS = 'CLASS', - /** - * use regexp to match className and methodName - */ - NAME = 'NAME', - /** - * use custom function to match - */ - CUSTOM = 'CUSTOM', -} - -export interface PointcutInfo { - type: PointcutType; - - match(clazz: EggProtoImplClass, method: PropertyKey): boolean; -} +import { PointcutType } from '@eggjs/tegg-types'; +import type { CustomPointcutCallback, EggProtoImplClass, PointcutInfo } from '@eggjs/tegg-types'; export class ClassPointInfo implements PointcutInfo { readonly type = PointcutType.CLASS; @@ -56,8 +36,6 @@ export class NamePointInfo implements PointcutInfo { } } -export type CustomPointcutCallback = (clazz: EggProtoImplClass, method: PropertyKey) => boolean; - export class CustomPointInfo implements PointcutInfo { readonly type = PointcutType.CUSTOM; readonly cb: CustomPointcutCallback; diff --git a/core/aop-decorator/src/util/AdviceInfoUtil.ts b/core/aop-decorator/src/util/AdviceInfoUtil.ts index 04793690..6ca74ecf 100644 --- a/core/aop-decorator/src/util/AdviceInfoUtil.ts +++ b/core/aop-decorator/src/util/AdviceInfoUtil.ts @@ -1,5 +1,5 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; -import { IAdvice } from '../decorator/Advice'; +import { MetadataUtil } from '@eggjs/core-decorator'; +import type { EggProtoImplClass, IAdvice } from '@eggjs/tegg-types'; export const IS_ADVICE = Symbol.for('EggPrototype#isAdvice'); diff --git a/core/aop-decorator/src/util/AspectInfoUtil.ts b/core/aop-decorator/src/util/AspectInfoUtil.ts index bba6f1e0..391ae5f6 100644 --- a/core/aop-decorator/src/util/AspectInfoUtil.ts +++ b/core/aop-decorator/src/util/AspectInfoUtil.ts @@ -1,9 +1,8 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; -import { IAdvice } from '../decorator/Advice'; +import { MetadataUtil } from '@eggjs/core-decorator'; +import { ASPECT_LIST } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, IAdvice } from '@eggjs/tegg-types'; import { Aspect } from '../model/Aspect'; -export const ASPECT_LIST = Symbol.for('EggPrototype#aspectList'); - export class AspectInfoUtil { static setAspectList(aspectList: Array, clazz: EggProtoImplClass) { MetadataUtil.defineMetaData(ASPECT_LIST, aspectList, clazz); diff --git a/core/aop-decorator/src/util/CrosscutInfoUtil.ts b/core/aop-decorator/src/util/CrosscutInfoUtil.ts index fdd189fe..b99a9b80 100644 --- a/core/aop-decorator/src/util/CrosscutInfoUtil.ts +++ b/core/aop-decorator/src/util/CrosscutInfoUtil.ts @@ -1,15 +1,6 @@ -import { AdviceInfo } from '../model/Aspect'; -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; -import { IAdvice } from '../decorator/Advice'; -import { PointcutInfo } from '../model/PointcutInfo'; - -export const CROSSCUT_INFO_LIST = Symbol.for('EggPrototype#crosscutInfoList'); -export const IS_CROSSCUT_ADVICE = Symbol.for('EggPrototype#isCrosscutAdvice'); - -export interface CrosscutInfo { - pointcutInfo: PointcutInfo; - adviceInfo: AdviceInfo; -} +import { MetadataUtil } from '@eggjs/core-decorator'; +import { IS_CROSSCUT_ADVICE, CROSSCUT_INFO_LIST } from '@eggjs/tegg-types'; +import type { CrosscutInfo, EggProtoImplClass, IAdvice } from '@eggjs/tegg-types'; export class CrosscutInfoUtil { static setIsCrosscutAdvice(isCrosscutAdvice: boolean, clazz: EggProtoImplClass) { diff --git a/core/aop-decorator/src/util/PointcutAdviceInfoUtil.ts b/core/aop-decorator/src/util/PointcutAdviceInfoUtil.ts index 277a47ce..39c678e7 100644 --- a/core/aop-decorator/src/util/PointcutAdviceInfoUtil.ts +++ b/core/aop-decorator/src/util/PointcutAdviceInfoUtil.ts @@ -1,9 +1,6 @@ -import { - EggProtoImplClass, MetadataUtil, -} from '@eggjs/core-decorator'; -import { AdviceInfo } from '../model/Aspect'; - -export const POINTCUT_ADVICE_INFO_LIAR = Symbol.for('EggPrototype#pointcutAdviceInfoList'); +import { MetadataUtil } from '@eggjs/core-decorator'; +import { POINTCUT_ADVICE_INFO_LIAR } from '@eggjs/tegg-types'; +import type { AdviceInfo, EggProtoImplClass } from '@eggjs/tegg-types'; interface PointcutAdviceInfo { method: PropertyKey; diff --git a/core/aop-decorator/test/AspectMetaBuilder.test.ts b/core/aop-decorator/test/AspectMetaBuilder.test.ts index 556051a3..9f12a05c 100644 --- a/core/aop-decorator/test/AspectMetaBuilder.test.ts +++ b/core/aop-decorator/test/AspectMetaBuilder.test.ts @@ -1,7 +1,10 @@ +import assert from 'node:assert'; +import { PrototypeUtil } from '@eggjs/core-decorator'; import { CrosscutAdviceFactory } from '../src/CrosscutAdviceFactory'; import { CrosscutClassAdviceExample, - CrosscutCustomAdviceExample, CrosscutExample, + CrosscutCustomAdviceExample, + CrosscutExample, CrosscutNameAdviceExample, } from './fixtures/CrosscutExample'; import { @@ -11,7 +14,6 @@ import { PointcutExample, } from './fixtures/PointcutExample'; import { AspectMetaBuilder } from '../src/AspectMetaBuilder'; -import assert from 'assert'; import { ChildExample, CrosscutNoOverwriteParentExample, @@ -21,7 +23,6 @@ import { PointcutAdviceOverwriteChildExample, PointcutAdviceOverwriteParentExample, } from './fixtures/InheritExample'; -import { PrototypeUtil } from '@eggjs/core-decorator'; describe('test/AspectMetaBuild.test.ts', () => { const crosscutAdviceFactory = new CrosscutAdviceFactory(); diff --git a/core/aop-decorator/test/fixtures/CrosscutExample.ts b/core/aop-decorator/test/fixtures/CrosscutExample.ts index b9c1fa03..b7edae59 100644 --- a/core/aop-decorator/test/fixtures/CrosscutExample.ts +++ b/core/aop-decorator/test/fixtures/CrosscutExample.ts @@ -1,5 +1,7 @@ -import { ContextProto, EggProtoImplClass } from '@eggjs/core-decorator'; -import { Advice, Crosscut, IAdvice, PointcutType } from '../..'; +import { ContextProto } from '@eggjs/core-decorator'; +import { PointcutType } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, IAdvice } from '@eggjs/tegg-types'; +import { Advice, Crosscut } from '../..'; @ContextProto() export class CrosscutExample { diff --git a/core/aop-decorator/test/fixtures/InheritExample.ts b/core/aop-decorator/test/fixtures/InheritExample.ts index c77ce977..66b7a639 100644 --- a/core/aop-decorator/test/fixtures/InheritExample.ts +++ b/core/aop-decorator/test/fixtures/InheritExample.ts @@ -1,8 +1,9 @@ import { ContextProto } from '@eggjs/core-decorator'; -import { Advice, AdviceContext, IAdvice } from '../../src/decorator/Advice'; +import { PointcutType } from '@eggjs/tegg-types'; +import type { AdviceContext, IAdvice } from '@eggjs/tegg-types'; +import { Advice } from '../../src/decorator/Advice'; import { Pointcut } from '../../src/decorator/Pointcut'; import { Crosscut } from '../../src/decorator/Crosscut'; -import { PointcutType } from '../../src/model/PointcutInfo'; @Advice() export class PointcutAdviceNoOverwriteParentExample implements IAdvice { diff --git a/core/aop-decorator/test/fixtures/PointcutExample.ts b/core/aop-decorator/test/fixtures/PointcutExample.ts index e66d9d1f..0109fe91 100644 --- a/core/aop-decorator/test/fixtures/PointcutExample.ts +++ b/core/aop-decorator/test/fixtures/PointcutExample.ts @@ -1,5 +1,6 @@ import { ContextProto } from '@eggjs/core-decorator'; -import { Advice, AdviceContext, IAdvice, Pointcut } from '../..'; +import type { AdviceContext, IAdvice } from '@eggjs/tegg-types'; +import { Advice, Pointcut } from '../..'; @Advice() export class PointcutAdviceBeforeCallExample implements IAdvice { diff --git a/core/aop-runtime/package.json b/core/aop-runtime/package.json index d2f4c402..42e8bd86 100644 --- a/core/aop-runtime/package.json +++ b/core/aop-runtime/package.json @@ -49,6 +49,7 @@ "@eggjs/tegg-lifecycle": "^3.37.1", "@eggjs/tegg-metadata": "^3.37.1", "@eggjs/tegg-runtime": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "koa-compose": "^4.1.0" }, "devDependencies": { diff --git a/core/aop-runtime/src/AspectExecutor.ts b/core/aop-runtime/src/AspectExecutor.ts index a6a2c39b..a0cfaf86 100644 --- a/core/aop-runtime/src/AspectExecutor.ts +++ b/core/aop-runtime/src/AspectExecutor.ts @@ -1,4 +1,4 @@ -import { AdviceContext, AspectAdvice, IAdvice } from '@eggjs/aop-decorator'; +import type { AdviceContext, AspectAdvice, IAdvice } from '@eggjs/tegg-types'; import compose from 'koa-compose'; import type { Middleware } from 'koa-compose'; diff --git a/core/aop-runtime/src/EggObjectAopHook.ts b/core/aop-runtime/src/EggObjectAopHook.ts index d29a63eb..9f5a1243 100644 --- a/core/aop-runtime/src/EggObjectAopHook.ts +++ b/core/aop-runtime/src/EggObjectAopHook.ts @@ -1,6 +1,6 @@ -import { LifecycleHook } from '@eggjs/tegg-lifecycle'; -import { EggObject, EggObjectLifeCycleContext } from '@eggjs/tegg-runtime'; -import { Aspect, ASPECT_LIST } from '@eggjs/aop-decorator'; +import { ASPECT_LIST } from '@eggjs/tegg-types'; +import type { EggObject, EggObjectLifeCycleContext, LifecycleHook } from '@eggjs/tegg-types'; +import { Aspect } from '@eggjs/aop-decorator'; import { AspectExecutor } from './AspectExecutor'; export class EggObjectAopHook implements LifecycleHook { diff --git a/core/aop-runtime/src/EggPrototypeCrossCutHook.ts b/core/aop-runtime/src/EggPrototypeCrossCutHook.ts index be61aa68..321e60bd 100644 --- a/core/aop-runtime/src/EggPrototypeCrossCutHook.ts +++ b/core/aop-runtime/src/EggPrototypeCrossCutHook.ts @@ -1,6 +1,5 @@ -import { LifecycleHook } from '@eggjs/tegg-lifecycle'; +import type { EggPrototype, EggPrototypeLifecycleContext, LifecycleHook } from '@eggjs/tegg-types'; import { CrosscutAdviceFactory, CrosscutInfoUtil } from '@eggjs/aop-decorator'; -import { EggPrototype, EggPrototypeLifecycleContext } from '@eggjs/tegg-metadata'; export class EggPrototypeCrossCutHook implements LifecycleHook { private readonly crosscutAdviceFactory: CrosscutAdviceFactory; diff --git a/core/aop-runtime/src/LoadUnitAopHook.ts b/core/aop-runtime/src/LoadUnitAopHook.ts index 2e68ab7a..7971da27 100644 --- a/core/aop-runtime/src/LoadUnitAopHook.ts +++ b/core/aop-runtime/src/LoadUnitAopHook.ts @@ -1,11 +1,13 @@ -import { LifecycleHook } from '@eggjs/tegg-lifecycle'; -import { CrosscutAdviceFactory, AspectMetaBuilder, AspectInfoUtil } from '@eggjs/aop-decorator'; -import { EggProtoImplClass, PrototypeUtil } from '@eggjs/core-decorator'; -import { EggPrototype, LoadUnit, LoadUnitLifecycleContext, TeggError } from '@eggjs/tegg-metadata'; - -export interface EggPrototypeWithClazz extends EggPrototype { - clazz?: EggProtoImplClass; -} +import { AspectInfoUtil, AspectMetaBuilder, CrosscutAdviceFactory } from '@eggjs/aop-decorator'; +import { PrototypeUtil } from '@eggjs/core-decorator'; +import { TeggError } from '@eggjs/tegg-metadata'; +import type { + EggPrototype, + EggPrototypeWithClazz, + LifecycleHook, + LoadUnit, + LoadUnitLifecycleContext, +} from '@eggjs/tegg-types'; export class LoadUnitAopHook implements LifecycleHook { private readonly crosscutAdviceFactory: CrosscutAdviceFactory; diff --git a/core/aop-runtime/test/aop-runtime.test.ts b/core/aop-runtime/test/aop-runtime.test.ts index 022fad28..03a966e1 100644 --- a/core/aop-runtime/test/aop-runtime.test.ts +++ b/core/aop-runtime/test/aop-runtime.test.ts @@ -1,12 +1,12 @@ -import path from 'path'; +import assert from 'node:assert'; +import path from 'node:path'; import mm from 'mm'; -import assert from 'assert'; -import { EggObjectLifecycleUtil, LoadUnitInstance, LoadUnitInstanceFactory } from '@eggjs/tegg-runtime'; +import { EggObjectLifecycleUtil, LoadUnitInstanceFactory } from '@eggjs/tegg-runtime'; import { EggPrototypeLifecycleUtil, LoadUnitFactory, LoadUnitLifecycleUtil } from '@eggjs/tegg-metadata'; +import type { LoadUnitInstance } from '@eggjs/tegg-types'; import { CrosscutAdviceFactory } from '@eggjs/aop-decorator'; -import { EggTestContext } from '../../test-util'; +import { CoreTestHelper, EggTestContext } from '../../test-util'; import { CallTrace, Hello, crosscutAdviceParams, pointcutAdviceParams } from './fixtures/modules/hello_succeed/Hello'; -import { CoreTestHelper } from '../../test-util/CoreTestHelper'; import { EggObjectAopHook } from '../src/EggObjectAopHook'; import { LoadUnitAopHook } from '../src/LoadUnitAopHook'; import { EggPrototypeCrossCutHook } from '../src/EggPrototypeCrossCutHook'; diff --git a/core/aop-runtime/test/fixtures/modules/hello_succeed/Hello.ts b/core/aop-runtime/test/fixtures/modules/hello_succeed/Hello.ts index 1cf92c11..ef49d93f 100644 --- a/core/aop-runtime/test/fixtures/modules/hello_succeed/Hello.ts +++ b/core/aop-runtime/test/fixtures/modules/hello_succeed/Hello.ts @@ -1,6 +1,7 @@ +import assert from 'node:assert'; import { ContextProto, Inject, SingletonProto } from '@eggjs/core-decorator'; -import { Advice, AdviceContext, Crosscut, IAdvice, Pointcut, PointcutType } from '@eggjs/aop-decorator'; -import assert from 'assert'; +import { Advice, Crosscut, Pointcut } from '@eggjs/aop-decorator'; +import { AdviceContext, IAdvice, PointcutType } from '@eggjs/tegg-types'; export interface CallTraceMsg { className: string; @@ -70,7 +71,7 @@ export class PointcutAdvice implements IAdvice { name: ctx.args[0], result: error.message, adviceParams: ctx.adviceParams, - }); + }); } async afterFinally(ctx: AdviceContext): Promise { diff --git a/core/aop-runtime/test/fixtures/modules/should_throw/Hello.ts b/core/aop-runtime/test/fixtures/modules/should_throw/Hello.ts index f6e9f6ca..adac5897 100644 --- a/core/aop-runtime/test/fixtures/modules/should_throw/Hello.ts +++ b/core/aop-runtime/test/fixtures/modules/should_throw/Hello.ts @@ -1,5 +1,6 @@ import { ContextProto } from '@eggjs/core-decorator'; -import { Advice, AdviceContext, IAdvice, Pointcut } from '@eggjs/aop-decorator'; +import { Advice, Pointcut } from '@eggjs/aop-decorator'; +import type { AdviceContext, IAdvice } from '@eggjs/tegg-types'; @Advice() class PointcutAdvice implements IAdvice { diff --git a/core/background-task/package.json b/core/background-task/package.json index ecbdf25b..bf437722 100644 --- a/core/background-task/package.json +++ b/core/background-task/package.json @@ -39,7 +39,8 @@ "dependencies": { "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-lifecycle": "^3.37.1", - "@eggjs/tegg-runtime": "^3.37.1" + "@eggjs/tegg-runtime": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1" }, "devDependencies": { "@eggjs/tegg-common-util": "^3.37.1", diff --git a/core/background-task/src/BackgroundTaskHelper.ts b/core/background-task/src/BackgroundTaskHelper.ts index aa52d7e6..ff2b0d9a 100644 --- a/core/background-task/src/BackgroundTaskHelper.ts +++ b/core/background-task/src/BackgroundTaskHelper.ts @@ -1,7 +1,8 @@ -import assert from 'assert'; -import { AccessLevel, ContextProto, Inject } from '@eggjs/core-decorator'; +import assert from 'node:assert'; import type { EggLogger, EggAppConfig } from 'egg'; -import { EggObjectLifecycle } from '@eggjs/tegg-lifecycle'; +import { ContextProto, Inject } from '@eggjs/core-decorator'; +import { AccessLevel } from '@eggjs/tegg-types'; +import type { EggObjectLifecycle } from '@eggjs/tegg-types'; import { ContextHandler, EggContextLifecycleUtil } from '@eggjs/tegg-runtime'; @ContextProto({ diff --git a/core/background-task/test/BackgroundTaskHelper.test.ts b/core/background-task/test/BackgroundTaskHelper.test.ts index 906f748c..ab1b37fc 100644 --- a/core/background-task/test/BackgroundTaskHelper.test.ts +++ b/core/background-task/test/BackgroundTaskHelper.test.ts @@ -1,6 +1,6 @@ -import { BackgroundTaskHelper } from '../src/BackgroundTaskHelper'; +import assert from 'node:assert'; import { TimerUtil } from '@eggjs/tegg-common-util'; -import assert from 'assert'; +import { BackgroundTaskHelper } from '../src/BackgroundTaskHelper'; describe('test/BackgroundTaskHelper.test.ts', () => { let helper: BackgroundTaskHelper; diff --git a/core/common-util/index.ts b/core/common-util/index.ts index ec3530bc..d75acb7b 100644 --- a/core/common-util/index.ts +++ b/core/common-util/index.ts @@ -1,3 +1,4 @@ +export * from '@eggjs/tegg-types/common'; export * from './src/MapUtil'; export * from './src/NameUtil'; export * from './src/Graph'; @@ -8,4 +9,3 @@ export * from './src/ProxyUtil'; export * from './src/ModuleConfig'; export * from './src/ModuleConfigs'; export * from './src/TimerUtil'; -export * from './src/RuntimeConfig'; diff --git a/core/common-util/package.json b/core/common-util/package.json index d9940dbe..0806ac84 100644 --- a/core/common-util/package.json +++ b/core/common-util/package.json @@ -36,6 +36,7 @@ "node": ">=14.0.0" }, "dependencies": { + "@eggjs/tegg-types": "^3.36.2", "extend2": "^1.0.0", "globby": "^11.1.0", "js-yaml": "^3.14.0" diff --git a/core/common-util/src/Graph.ts b/core/common-util/src/Graph.ts index 3eede879..9a0d9687 100644 --- a/core/common-util/src/Graph.ts +++ b/core/common-util/src/Graph.ts @@ -1,8 +1,6 @@ -const inspect = Symbol.for('nodejs.util.inspect.custom'); +import type { GraphNodeObj } from '@eggjs/tegg-types'; -export interface GraphNodeObj { - readonly id: string; -} +const inspect = Symbol.for('nodejs.util.inspect.custom'); export class GraphNode { val: T; diff --git a/core/common-util/src/ModuleConfig.ts b/core/common-util/src/ModuleConfig.ts index 039e4d48..cc51e17b 100644 --- a/core/common-util/src/ModuleConfig.ts +++ b/core/common-util/src/ModuleConfig.ts @@ -1,28 +1,18 @@ -import assert from 'assert'; -import yaml from 'js-yaml'; -import fs, { promises as fsPromise } from 'fs'; -import path from 'path'; +import assert from 'node:assert'; +import fs, { promises as fsPromise } from 'node:fs'; +import path from 'node:path'; +import extend from 'extend2'; import globby from 'globby'; +import yaml from 'js-yaml'; +import type { + InlineModuleReferenceConfig, + ModuleConfig, + ModuleReference, + ModuleReferenceConfig, + NpmModuleReferenceConfig, + ReadModuleReferenceOptions, +} from '@eggjs/tegg-types'; import { FSUtil } from './FSUtil'; -import extend from 'extend2'; - -export interface ModuleReference { - name: string; - path: string; - optional?: boolean; -} - -export interface InlineModuleReferenceConfig { - path: string; - optional?: boolean; -} - -export interface NpmModuleReferenceConfig { - package: string; - optional?: boolean; -} - -export type ModuleReferenceConfig = InlineModuleReferenceConfig | NpmModuleReferenceConfig; export class ModuleReferenceConfigHelp { static isInlineModuleReference(moduleReference: ModuleReferenceConfig): moduleReference is InlineModuleReferenceConfig { @@ -34,17 +24,6 @@ export class ModuleReferenceConfigHelp { } } -export interface ModuleConfig { -} - -export interface ReadModuleReferenceOptions { - // module dir deep for globby when use auto scan module - // default is 10 - deep?: number; - cwd?: string; - extraFilePattern?: string[]; -} - const DEFAULT_READ_MODULE_REF_OPTS = { deep: 10, }; diff --git a/core/common-util/src/ModuleConfigs.ts b/core/common-util/src/ModuleConfigs.ts index 2817a9eb..b3f06789 100644 --- a/core/common-util/src/ModuleConfigs.ts +++ b/core/common-util/src/ModuleConfigs.ts @@ -1,10 +1,4 @@ -import { ModuleConfig, ModuleReference } from './ModuleConfig'; - -export interface ModuleConfigHolder { - name: string; - config: ModuleConfig; - reference: ModuleReference; -} +import type { ModuleConfig, ModuleConfigHolder } from '@eggjs/tegg-types'; export class ModuleConfigs { constructor(readonly inner: Record) { diff --git a/core/common-util/test/MapUtil.test.ts b/core/common-util/test/MapUtil.test.ts index 806077df..6c930aab 100644 --- a/core/common-util/test/MapUtil.test.ts +++ b/core/common-util/test/MapUtil.test.ts @@ -1,5 +1,5 @@ +import assert from 'node:assert'; import { MapUtil } from '..'; -import assert from 'assert'; describe('test/MapUtil.test.ts', () => { it('should set value if key not exists', () => { diff --git a/core/common-util/test/ModuleConfig.test.ts b/core/common-util/test/ModuleConfig.test.ts index e407bf08..7e60c0ba 100644 --- a/core/common-util/test/ModuleConfig.test.ts +++ b/core/common-util/test/ModuleConfig.test.ts @@ -1,5 +1,5 @@ -import assert from 'assert'; -import path from 'path'; +import assert from 'node:assert'; +import path from 'node:path'; import { ModuleConfigUtil } from '../src/ModuleConfig'; describe('test/ModuleConfig.test.ts', () => { diff --git a/core/common-util/test/NameUtil.test.ts b/core/common-util/test/NameUtil.test.ts index 9cc8379b..e2cb4ca8 100644 --- a/core/common-util/test/NameUtil.test.ts +++ b/core/common-util/test/NameUtil.test.ts @@ -1,5 +1,5 @@ +import assert from 'node:assert'; import { NameUtil } from '..'; -import assert from 'assert'; describe('test/NameUtil.test.ts', () => { it('should work', () => { diff --git a/core/common-util/test/ObjectUtil.test.ts b/core/common-util/test/ObjectUtil.test.ts index eff370ec..d76d1a59 100644 --- a/core/common-util/test/ObjectUtil.test.ts +++ b/core/common-util/test/ObjectUtil.test.ts @@ -1,4 +1,4 @@ -import assert from 'assert'; +import assert from 'node:assert'; import { ObjectUtils } from '..'; describe('test/ObjectUtil.test.ts', () => { diff --git a/core/common-util/test/ProtoGraph.test.ts b/core/common-util/test/ProtoGraph.test.ts index 652031a8..f033e95b 100644 --- a/core/common-util/test/ProtoGraph.test.ts +++ b/core/common-util/test/ProtoGraph.test.ts @@ -1,5 +1,6 @@ -import assert from 'assert'; -import { GraphNode, Graph, GraphNodeObj } from '../src/Graph'; +import assert from 'node:assert'; +import type { GraphNodeObj } from '@eggjs/tegg-types'; +import { GraphNode, Graph } from '../src/Graph'; describe('test/LoadUnit/Graph.test.ts', () => { class GraphNodeVal implements GraphNodeObj { diff --git a/core/common-util/test/TimerUtil.test.ts b/core/common-util/test/TimerUtil.test.ts index f512657d..397c1e95 100644 --- a/core/common-util/test/TimerUtil.test.ts +++ b/core/common-util/test/TimerUtil.test.ts @@ -1,4 +1,4 @@ -import assert from 'assert'; +import assert from 'node:assert'; import { TimerUtil } from '..'; describe('test/TimerUtil.test.ts', () => { diff --git a/core/controller-decorator/index.ts b/core/controller-decorator/index.ts index 8492949c..7e8ac427 100644 --- a/core/controller-decorator/index.ts +++ b/core/controller-decorator/index.ts @@ -1,5 +1,6 @@ import './src/impl/http/HTTPControllerMetaBuilder'; +export * from '@eggjs/tegg-types/controller-decorator'; export * from './src/model'; export * from './src/decorator/Context'; export * from './src/decorator/Middleware'; @@ -9,6 +10,5 @@ export * from './src/decorator/http/HTTPMethod'; export * from './src/decorator/http/HTTPParam'; export * from './src/decorator/http/Host'; export * from './src/builder/ControllerMetaBuilderFactory'; -export * from './src/builder/ControllerMetaBuilder'; export * from './src/util/ControllerMetadataUtil'; export * from './src/util/HTTPPriorityUtil'; diff --git a/core/controller-decorator/package.json b/core/controller-decorator/package.json index 5af1a22e..15ce5c76 100644 --- a/core/controller-decorator/package.json +++ b/core/controller-decorator/package.json @@ -40,6 +40,7 @@ "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", "@eggjs/tegg-metadata": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "path-to-regexp": "^1.8.0", "reflect-metadata": "^0.1.13", "undici": "^5.26.5" diff --git a/core/controller-decorator/src/builder/ControllerMetaBuilder.ts b/core/controller-decorator/src/builder/ControllerMetaBuilder.ts deleted file mode 100644 index 914b8b99..00000000 --- a/core/controller-decorator/src/builder/ControllerMetaBuilder.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ControllerMetadata } from '../model/ControllerMetadata'; - -export interface ControllerMetaBuilder { - build(): ControllerMetadata | undefined; -} diff --git a/core/controller-decorator/src/builder/ControllerMetaBuilderFactory.ts b/core/controller-decorator/src/builder/ControllerMetaBuilderFactory.ts index 81dfc9ab..6009afd2 100644 --- a/core/controller-decorator/src/builder/ControllerMetaBuilderFactory.ts +++ b/core/controller-decorator/src/builder/ControllerMetaBuilderFactory.ts @@ -1,10 +1,11 @@ -import { ControllerTypeLike } from '../model'; -import { ControllerMetaBuilder } from './ControllerMetaBuilder'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { + ControllerMetaBuilder, + ControllerMetaBuilderCreator, + ControllerTypeLike, + EggProtoImplClass, +} from '@eggjs/tegg-types'; import ControllerInfoUtil from '../util/ControllerInfoUtil'; -export type ControllerMetaBuilderCreator = (clazz: EggProtoImplClass) => ControllerMetaBuilder; - export class ControllerMetaBuilderFactory { private static builderCreatorMap: Map = new Map(); diff --git a/core/controller-decorator/src/decorator/Acl.ts b/core/controller-decorator/src/decorator/Acl.ts index 0dec32cd..be8b7fcb 100644 --- a/core/controller-decorator/src/decorator/Acl.ts +++ b/core/controller-decorator/src/decorator/Acl.ts @@ -1,5 +1,5 @@ -import assert from 'assert'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import assert from 'node:assert'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import ControllerInfoUtil from '../util/ControllerInfoUtil'; import MethodInfoUtil from '../util/MethodInfoUtil'; diff --git a/core/controller-decorator/src/decorator/Context.ts b/core/controller-decorator/src/decorator/Context.ts index 950010dc..d9389224 100644 --- a/core/controller-decorator/src/decorator/Context.ts +++ b/core/controller-decorator/src/decorator/Context.ts @@ -1,5 +1,5 @@ -import assert from 'assert'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import assert from 'node:assert'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import MethodInfoUtil from '../util/MethodInfoUtil'; export function Context() { diff --git a/core/controller-decorator/src/decorator/Middleware.ts b/core/controller-decorator/src/decorator/Middleware.ts index adcaa8cc..1d1b6245 100644 --- a/core/controller-decorator/src/decorator/Middleware.ts +++ b/core/controller-decorator/src/decorator/Middleware.ts @@ -1,6 +1,5 @@ -import { MiddlewareFunc } from '../model'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; -import assert from 'assert'; +import assert from 'node:assert'; +import type { EggProtoImplClass, MiddlewareFunc } from '@eggjs/tegg-types'; import ControllerInfoUtil from '../util/ControllerInfoUtil'; import MethodInfoUtil from '../util/MethodInfoUtil'; diff --git a/core/controller-decorator/src/decorator/http/HTTPController.ts b/core/controller-decorator/src/decorator/http/HTTPController.ts index 6a70815a..460bf969 100644 --- a/core/controller-decorator/src/decorator/http/HTTPController.ts +++ b/core/controller-decorator/src/decorator/http/HTTPController.ts @@ -1,14 +1,9 @@ -import { AccessLevel, EggProtoImplClass, PrototypeUtil, SingletonProto } from '@eggjs/core-decorator'; +import { PrototypeUtil, SingletonProto } from '@eggjs/core-decorator'; import { StackUtil } from '@eggjs/tegg-common-util'; -import HTTPInfoUtil from '../../util/HTTPInfoUtil'; +import type { EggProtoImplClass, HTTPControllerParams } from '@eggjs/tegg-types'; +import { AccessLevel, ControllerType } from '@eggjs/tegg-types'; import ControllerInfoUtil from '../../util/ControllerInfoUtil'; -import { ControllerType } from '../../model'; - -export interface HTTPControllerParams { - protoName?: string; - controllerName?: string; - path?: string; -} +import HTTPInfoUtil from '../../util/HTTPInfoUtil'; export function HTTPController(param?: HTTPControllerParams) { return function(constructor: EggProtoImplClass) { diff --git a/core/controller-decorator/src/decorator/http/HTTPMethod.ts b/core/controller-decorator/src/decorator/http/HTTPMethod.ts index 956e32fe..fa3b47fd 100644 --- a/core/controller-decorator/src/decorator/http/HTTPMethod.ts +++ b/core/controller-decorator/src/decorator/http/HTTPMethod.ts @@ -1,15 +1,9 @@ -import assert from 'assert'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import assert from 'node:assert'; +import { ControllerType } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, HTTPMethodParams } from '@eggjs/tegg-types'; import HTTPInfoUtil from '../../util/HTTPInfoUtil'; -import { ControllerType, HTTPMethodEnum } from '../../model'; import MethodInfoUtil from '../../util/MethodInfoUtil'; -export interface HTTPMethodParams { - method: HTTPMethodEnum; - path: string; - priority?: number; -} - export function HTTPMethod(param: HTTPMethodParams) { return function(target: any, propertyKey: PropertyKey) { assert(typeof propertyKey === 'string', diff --git a/core/controller-decorator/src/decorator/http/HTTPParam.ts b/core/controller-decorator/src/decorator/http/HTTPParam.ts index f602f174..f3c14d50 100644 --- a/core/controller-decorator/src/decorator/http/HTTPParam.ts +++ b/core/controller-decorator/src/decorator/http/HTTPParam.ts @@ -1,8 +1,8 @@ import assert from 'node:assert'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; -import { ObjectUtils } from '@eggjs/tegg-common-util'; -import { HTTPParamType } from '../../model'; +import { HTTPParamType } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, HTTPParamParams, HTTPQueriesParams, HTTPQueryParams } from '@eggjs/tegg-types'; import HTTPInfoUtil from '../../util/HTTPInfoUtil'; +import { ObjectUtils } from '@eggjs/tegg-common-util'; // TODO url params // /foo/:id @@ -28,14 +28,6 @@ export function HTTPHeaders() { }; } -export interface HTTPQueryParams { - name?: string; -} - -export interface HTTPQueriesParams { - name?: string; -} - export function HTTPQuery(param?: HTTPQueryParams) { return function(target: any, propertyKey: PropertyKey, parameterIndex: number) { assert(typeof propertyKey === 'string', @@ -62,10 +54,6 @@ export function HTTPQueries(param?: HTTPQueriesParams) { }; } -export interface HTTPParamParams { - name?: string; -} - export function HTTPParam(param?: HTTPParamParams) { return function(target: any, propertyKey: PropertyKey, parameterIndex: number) { assert(typeof propertyKey === 'string', diff --git a/core/controller-decorator/src/decorator/http/Host.ts b/core/controller-decorator/src/decorator/http/Host.ts index 033e330c..2cd9e884 100644 --- a/core/controller-decorator/src/decorator/http/Host.ts +++ b/core/controller-decorator/src/decorator/http/Host.ts @@ -1,8 +1,7 @@ +import assert from 'node:assert'; +import type { EggProtoImplClass, HostType } from '@eggjs/tegg-types'; import ControllerInfoUtil from '../../util/ControllerInfoUtil'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; import MethodInfoUtil from '../../util/MethodInfoUtil'; -import assert from 'assert'; -import { HostType } from '../../model'; export function Host(host: HostType) { diff --git a/core/controller-decorator/src/impl/http/HTTPControllerMetaBuilder.ts b/core/controller-decorator/src/impl/http/HTTPControllerMetaBuilder.ts index 0494586c..ff40e6d6 100644 --- a/core/controller-decorator/src/impl/http/HTTPControllerMetaBuilder.ts +++ b/core/controller-decorator/src/impl/http/HTTPControllerMetaBuilder.ts @@ -1,14 +1,16 @@ -import { EggProtoImplClass, PrototypeUtil } from '@eggjs/core-decorator'; -import assert from 'assert'; -import HTTPInfoUtil from '../../util/HTTPInfoUtil'; -import ControllerInfoUtil from '../../util/ControllerInfoUtil'; -import { ControllerType, HTTPControllerMeta, HTTPMethodMeta } from '../../model'; -import { ControllerValidator } from '../../util/validator/ControllerValidator'; +import assert from 'node:assert'; +import { PrototypeUtil } from '@eggjs/core-decorator'; import { ObjectUtils } from '@eggjs/tegg-common-util'; -import { HTTPControllerMethodMetaBuilder } from './HTTPControllerMethodMetaBuilder'; import { ClassUtil } from '@eggjs/tegg-metadata'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; +import { ControllerType } from '@eggjs/tegg-types'; import { ControllerMetaBuilderFactory } from '../../builder/ControllerMetaBuilderFactory'; +import { HTTPControllerMeta, HTTPMethodMeta } from '../../model'; +import ControllerInfoUtil from '../../util/ControllerInfoUtil'; import { ControllerMetadataUtil } from '../../util/ControllerMetadataUtil'; +import HTTPInfoUtil from '../../util/HTTPInfoUtil'; +import { ControllerValidator } from '../../util/validator/ControllerValidator'; +import { HTTPControllerMethodMetaBuilder } from './HTTPControllerMethodMetaBuilder'; export class HTTPControllerMetaBuilder { private readonly clazz: EggProtoImplClass; diff --git a/core/controller-decorator/src/impl/http/HTTPControllerMethodMetaBuilder.ts b/core/controller-decorator/src/impl/http/HTTPControllerMethodMetaBuilder.ts index 06ec0a6c..26689e57 100644 --- a/core/controller-decorator/src/impl/http/HTTPControllerMethodMetaBuilder.ts +++ b/core/controller-decorator/src/impl/http/HTTPControllerMethodMetaBuilder.ts @@ -1,10 +1,10 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import path from 'node:path'; +import { ClassUtil } from '@eggjs/tegg-metadata'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { HTTPMethodMeta, ParamMeta, ParamMetaUtil } from '../../model'; import { MethodValidator } from '../../util/validator/MethodValidator'; import HTTPInfoUtil from '../../util/HTTPInfoUtil'; import MethodInfoUtil from '../../util/MethodInfoUtil'; -import { ClassUtil } from '@eggjs/tegg-metadata'; -import path from 'path'; import { HTTPPriorityUtil } from '../../util/HTTPPriorityUtil'; export class HTTPControllerMethodMetaBuilder { diff --git a/core/controller-decorator/src/model/HTTPControllerMeta.ts b/core/controller-decorator/src/model/HTTPControllerMeta.ts index bea96ff2..584a0597 100644 --- a/core/controller-decorator/src/model/HTTPControllerMeta.ts +++ b/core/controller-decorator/src/model/HTTPControllerMeta.ts @@ -1,8 +1,7 @@ -import path from 'path'; -import { ControllerMetadata } from './ControllerMetadata'; -import { ControllerType, MiddlewareFunc } from './types'; +import path from 'node:path'; +import type { ControllerMetadata, EggPrototypeName, MiddlewareFunc } from '@eggjs/tegg-types'; +import { ControllerType } from '@eggjs/tegg-types'; import { HTTPMethodMeta } from './HTTPMethodMeta'; -import { EggPrototypeName } from '@eggjs/core-decorator'; export class HTTPControllerMeta implements ControllerMetadata { readonly protoName: EggPrototypeName; diff --git a/core/controller-decorator/src/model/HTTPMethodMeta.ts b/core/controller-decorator/src/model/HTTPMethodMeta.ts index a9b9b7d6..9b6703a4 100644 --- a/core/controller-decorator/src/model/HTTPMethodMeta.ts +++ b/core/controller-decorator/src/model/HTTPMethodMeta.ts @@ -1,7 +1,7 @@ -import assert from 'assert'; +import assert from 'node:assert'; import pathToRegexp from 'path-to-regexp'; -import { MethodMeta } from './MethodMeta'; -import { HTTPMethodEnum, HTTPParamType, MiddlewareFunc } from './types'; +import { HTTPParamType } from '@eggjs/tegg-types'; +import type { HTTPMethodEnum, MethodMeta, MiddlewareFunc } from '@eggjs/tegg-types'; export abstract class ParamMeta { type: HTTPParamType; diff --git a/core/controller-decorator/src/model/index.ts b/core/controller-decorator/src/model/index.ts index ce5e1577..b035fa43 100644 --- a/core/controller-decorator/src/model/index.ts +++ b/core/controller-decorator/src/model/index.ts @@ -1,7 +1,3 @@ -export * from './types'; - -export * from './MethodMeta'; -export * from './ControllerMetadata'; export * from './HTTPMethodMeta'; export * from './HTTPControllerMeta'; export * from './HTTPRequest'; diff --git a/core/controller-decorator/src/util/ControllerInfoUtil.ts b/core/controller-decorator/src/util/ControllerInfoUtil.ts index 7ff80747..df2f7815 100644 --- a/core/controller-decorator/src/util/ControllerInfoUtil.ts +++ b/core/controller-decorator/src/util/ControllerInfoUtil.ts @@ -1,11 +1,12 @@ -import { ControllerTypeLike, MiddlewareFunc } from '../model'; -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; - -export const CONTROLLER_TYPE = Symbol.for('EggPrototype#controllerType'); -export const CONTROLLER_NAME = Symbol.for('EggPrototype#controllerName'); -export const CONTROLLER_HOST = Symbol.for('EggPrototype#controllerHost'); -export const CONTROLLER_MIDDLEWARES = Symbol.for('EggPrototype#controller#middlewares'); -export const CONTROLLER_ACL = Symbol.for('EggPrototype#controller#acl'); +import { + CONTROLLER_ACL, + CONTROLLER_HOST, + CONTROLLER_MIDDLEWARES, + CONTROLLER_NAME, + CONTROLLER_TYPE, +} from '@eggjs/tegg-types'; +import type { ControllerTypeLike, EggProtoImplClass, MiddlewareFunc } from '@eggjs/tegg-types'; +import { MetadataUtil } from '@eggjs/core-decorator'; export default class ControllerInfoUtil { static addControllerMiddleware(middleware: MiddlewareFunc, clazz: EggProtoImplClass) { diff --git a/core/controller-decorator/src/util/ControllerMetadataUtil.ts b/core/controller-decorator/src/util/ControllerMetadataUtil.ts index 0ee7b03a..749485dd 100644 --- a/core/controller-decorator/src/util/ControllerMetadataUtil.ts +++ b/core/controller-decorator/src/util/ControllerMetadataUtil.ts @@ -1,9 +1,8 @@ -import { ControllerMetadata } from '../model/ControllerMetadata'; -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; +import { CONTROLLER_META_DATA } from '@eggjs/tegg-types'; +import type { ControllerMetadata, EggProtoImplClass } from '@eggjs/tegg-types'; +import { MetadataUtil } from '@eggjs/core-decorator'; import { ControllerMetaBuilderFactory } from '../builder/ControllerMetaBuilderFactory'; -export const CONTROLLER_META_DATA = Symbol.for('EggPrototype#controller#metaData'); - export class ControllerMetadataUtil { static setControllerMetadata(clazz: EggProtoImplClass, metaData: ControllerMetadata) { MetadataUtil.defineMetaData(CONTROLLER_META_DATA, metaData, clazz); diff --git a/core/controller-decorator/src/util/HTTPInfoUtil.ts b/core/controller-decorator/src/util/HTTPInfoUtil.ts index ccd80c58..787a2524 100644 --- a/core/controller-decorator/src/util/HTTPInfoUtil.ts +++ b/core/controller-decorator/src/util/HTTPInfoUtil.ts @@ -1,13 +1,14 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; +import { MetadataUtil } from '@eggjs/core-decorator'; +import { + CONTROLLER_HTTP_PATH, + CONTROLLER_METHOD_METHOD_MAP, + CONTROLLER_METHOD_PARAM_NAME_MAP, + CONTROLLER_METHOD_PARAM_TYPE_MAP, + CONTROLLER_METHOD_PATH_MAP, + CONTROLLER_METHOD_PRIORITY, +} from '@eggjs/tegg-types'; +import type { EggProtoImplClass, HTTPMethodEnum, HTTPParamType } from '@eggjs/tegg-types'; import { MapUtil } from '@eggjs/tegg-common-util'; -import { HTTPMethodEnum, HTTPParamType } from '../model'; - -const CONTROLLER_HTTP_PATH = Symbol.for('EggPrototype#controller#http#path'); -const CONTROLLER_METHOD_METHOD_MAP = Symbol.for('EggPrototype#controller#method#http#method'); -const CONTROLLER_METHOD_PATH_MAP = Symbol.for('EggPrototype#controller#method#http#path'); -const CONTROLLER_METHOD_PARAM_TYPE_MAP = Symbol.for('EggPrototype#controller#method#http#params#type'); -const CONTROLLER_METHOD_PARAM_NAME_MAP = Symbol.for('EggPrototype#controller#method#http#params#name'); -const CONTROLLER_METHOD_PRIORITY = Symbol.for('EggPrototype#controller#method#http#priority'); type HTTPMethodPathMap = Map; type HTTPMethodMethodMap = Map; diff --git a/core/controller-decorator/src/util/MethodInfoUtil.ts b/core/controller-decorator/src/util/MethodInfoUtil.ts index 9fd67e55..d2a080da 100644 --- a/core/controller-decorator/src/util/MethodInfoUtil.ts +++ b/core/controller-decorator/src/util/MethodInfoUtil.ts @@ -1,12 +1,13 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; +import { MetadataUtil } from '@eggjs/core-decorator'; import { MapUtil } from '@eggjs/tegg-common-util'; -import { ControllerTypeLike, MiddlewareFunc } from '../model'; - -const METHOD_CONTROLLER_TYPE_MAP = Symbol.for('EggPrototype#controller#mthods'); -const METHOD_CONTROLLER_HOST = Symbol.for('EggPrototype#controller#mthods#host'); -const METHOD_CONTEXT_INDEX = Symbol.for('EggPrototype#controller#method#context'); -const METHOD_MIDDLEWARES = Symbol.for('EggPrototype#method#middlewares'); -const METHOD_ACL = Symbol.for('EggPrototype#method#acl'); +import { + METHOD_ACL, + METHOD_CONTEXT_INDEX, + METHOD_CONTROLLER_HOST, + METHOD_CONTROLLER_TYPE_MAP, + METHOD_MIDDLEWARES, +} from '@eggjs/tegg-types'; +import type { ControllerTypeLike, EggProtoImplClass, MiddlewareFunc } from '@eggjs/tegg-types'; type METHOD_MAP = Map; type MethodContextIndexMap = Map; diff --git a/core/controller-decorator/src/util/validator/ControllerValidator.ts b/core/controller-decorator/src/util/validator/ControllerValidator.ts index 6df88ef5..cbc9c7a4 100644 --- a/core/controller-decorator/src/util/validator/ControllerValidator.ts +++ b/core/controller-decorator/src/util/validator/ControllerValidator.ts @@ -1,6 +1,6 @@ -import ControllerInfoUtil from '../ControllerInfoUtil'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { ClassUtil } from '@eggjs/tegg-metadata'; +import ControllerInfoUtil from '../ControllerInfoUtil'; export class ControllerValidator { // should throw error diff --git a/core/controller-decorator/src/util/validator/MethodValidator.ts b/core/controller-decorator/src/util/validator/MethodValidator.ts index 5e984a98..a5634aa4 100644 --- a/core/controller-decorator/src/util/validator/MethodValidator.ts +++ b/core/controller-decorator/src/util/validator/MethodValidator.ts @@ -1,6 +1,6 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; -import MethodInfoUtil from '../MethodInfoUtil'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { ClassUtil } from '@eggjs/tegg-metadata'; +import MethodInfoUtil from '../MethodInfoUtil'; import ControllerInfoUtil from '../ControllerInfoUtil'; export class MethodValidator { diff --git a/core/controller-decorator/test/Acl.test.ts b/core/controller-decorator/test/Acl.test.ts index 2d7babf8..01a21629 100644 --- a/core/controller-decorator/test/Acl.test.ts +++ b/core/controller-decorator/test/Acl.test.ts @@ -1,7 +1,8 @@ -import assert from 'assert'; +import assert from 'node:assert'; +import { ControllerType } from '@eggjs/tegg-types'; import { AclController } from './fixtures/AclController'; import { ControllerMetaBuilderFactory } from '../src/builder/ControllerMetaBuilderFactory'; -import { ControllerType, HTTPControllerMeta } from '../src/model'; +import { HTTPControllerMeta } from '../src/model'; describe('test/Context.test.ts', () => { it('should work', () => { diff --git a/core/controller-decorator/test/Context.test.ts b/core/controller-decorator/test/Context.test.ts index d358de1d..1d059388 100644 --- a/core/controller-decorator/test/Context.test.ts +++ b/core/controller-decorator/test/Context.test.ts @@ -1,5 +1,5 @@ +import assert from 'node:assert'; import { ContextController } from './fixtures/ContextController'; -import assert from 'assert'; import MethodInfoUtil from '../src/util/MethodInfoUtil'; describe('test/Context.test.ts', () => { diff --git a/core/controller-decorator/test/Middleware.test.ts b/core/controller-decorator/test/Middleware.test.ts index edc13ec4..cafbc90e 100644 --- a/core/controller-decorator/test/Middleware.test.ts +++ b/core/controller-decorator/test/Middleware.test.ts @@ -1,4 +1,4 @@ -import assert from 'assert'; +import assert from 'node:assert'; import { MiddlewareController, MiddlewaresController } from './fixtures/MiddlewareController'; import ControllerInfoUtil from '../src/util/ControllerInfoUtil'; import MethodInfoUtil from '../src/util/MethodInfoUtil'; diff --git a/core/controller-decorator/test/fixtures/AclController.ts b/core/controller-decorator/test/fixtures/AclController.ts index 98846117..b27efb19 100644 --- a/core/controller-decorator/test/fixtures/AclController.ts +++ b/core/controller-decorator/test/fixtures/AclController.ts @@ -1,7 +1,7 @@ +import { HTTPMethodEnum } from '@eggjs/tegg-types'; import { Acl } from '../../src/decorator/Acl'; import { HTTPController } from '../../src/decorator/http/HTTPController'; import { HTTPMethod } from '../../src/decorator/http/HTTPMethod'; -import { HTTPMethodEnum } from '../../src/model'; @Acl('mock1') @HTTPController() diff --git a/core/controller-decorator/test/fixtures/HTTPFooController.ts b/core/controller-decorator/test/fixtures/HTTPFooController.ts index 05ba8bd4..6930853d 100644 --- a/core/controller-decorator/test/fixtures/HTTPFooController.ts +++ b/core/controller-decorator/test/fixtures/HTTPFooController.ts @@ -1,10 +1,9 @@ +import { HTTPMethodEnum } from '@eggjs/tegg-types' +import type { EggContext, Next, IncomingHttpHeaders } from '@eggjs/tegg-types'; import { HTTPController } from '../../src/decorator/http/HTTPController'; import { Context } from '../../src/decorator/Context'; import { Middleware } from '../../src/decorator/Middleware'; -import { EggContext, HTTPMethodEnum, Next, IncomingHttpHeaders } from '../../src/model'; -import { - HTTPBody, HTTPParam, HTTPQueries, HTTPQuery, HTTPHeaders, -} from '../../src/decorator/http/HTTPParam'; +import { HTTPBody, HTTPParam, HTTPQueries, HTTPQuery, HTTPHeaders } from '../../src/decorator/http/HTTPParam'; import { HTTPMethod } from '../../src/decorator/http/HTTPMethod'; async function middleware1(ctx: EggContext, next: Next) { diff --git a/core/controller-decorator/test/fixtures/HTTPPriorityController.ts b/core/controller-decorator/test/fixtures/HTTPPriorityController.ts index e96bceb2..da5c9958 100644 --- a/core/controller-decorator/test/fixtures/HTTPPriorityController.ts +++ b/core/controller-decorator/test/fixtures/HTTPPriorityController.ts @@ -1,5 +1,6 @@ +import { HTTPMethodEnum } from '@eggjs/tegg-types'; import { HTTPController } from '../../src/decorator/http/HTTPController'; -import { HTTPMethod, HTTPMethodEnum } from '../..'; +import { HTTPMethod } from '../..'; @HTTPController({ path: '/foo', diff --git a/core/controller-decorator/test/fixtures/MiddlewareController.ts b/core/controller-decorator/test/fixtures/MiddlewareController.ts index c950fe58..1c8f2842 100644 --- a/core/controller-decorator/test/fixtures/MiddlewareController.ts +++ b/core/controller-decorator/test/fixtures/MiddlewareController.ts @@ -1,4 +1,4 @@ -import { EggContext, Next } from '../../src/model'; +import type { EggContext, Next } from '@eggjs/tegg-types'; import { Middleware } from '../../src/decorator/Middleware'; async function middleware1(ctx: EggContext, next: Next) { diff --git a/core/controller-decorator/test/http/HTTPMeta.test.ts b/core/controller-decorator/test/http/HTTPMeta.test.ts index d7711cce..ffe4ee29 100644 --- a/core/controller-decorator/test/http/HTTPMeta.test.ts +++ b/core/controller-decorator/test/http/HTTPMeta.test.ts @@ -1,3 +1,5 @@ +import assert from 'node:assert'; +import { ControllerType, HTTPMethodEnum } from '@eggjs/tegg-types'; import { ControllerWithParam, DefaultValueController, @@ -7,7 +9,6 @@ import { FoxController, FxxController, } from '../fixtures/HTTPFooController'; -import assert from 'assert'; import { BodyParamMeta, ControllerMetaBuilderFactory, @@ -17,7 +18,7 @@ import { QueriesParamMeta, QueryParamMeta, } from '../..'; -import { ControllerType, HTTPControllerMeta, HTTPMethodEnum } from '../../src/model'; +import { HTTPControllerMeta } from '../../src/model'; import { PriorityController, TooLongController } from '../fixtures/HTTPPriorityController'; describe('core/controller-decorator/test/http/HTTPMeta.test.ts', () => { diff --git a/core/controller-decorator/test/http/Host.test.ts b/core/controller-decorator/test/http/Host.test.ts index e7871504..88e7f780 100644 --- a/core/controller-decorator/test/http/Host.test.ts +++ b/core/controller-decorator/test/http/Host.test.ts @@ -1,4 +1,4 @@ -import assert from 'assert'; +import assert from 'node:assert'; import { HostController } from '../fixtures/HostController'; import ControllerInfoUtil from '../../src/util/ControllerInfoUtil'; import MethodInfoUtil from '../../src/util/MethodInfoUtil'; diff --git a/core/controller-decorator/test/util/ControllerMetadataUtil.test.ts b/core/controller-decorator/test/util/ControllerMetadataUtil.test.ts index 5a186ee5..c2700830 100644 --- a/core/controller-decorator/test/util/ControllerMetadataUtil.test.ts +++ b/core/controller-decorator/test/util/ControllerMetadataUtil.test.ts @@ -1,7 +1,8 @@ -import { FooController, ParentController, ChildController } from '../fixtures/HTTPFooController'; -import { CONTROLLER_META_DATA, ControllerMetadataUtil } from '../../src/util/ControllerMetadataUtil'; +import assert from 'node:assert'; import { MetadataUtil } from '@eggjs/core-decorator'; -import assert from 'assert'; +import { CONTROLLER_META_DATA } from '@eggjs/tegg-types'; +import { FooController, ParentController, ChildController } from '../fixtures/HTTPFooController'; +import { ControllerMetadataUtil } from '../../src/util/ControllerMetadataUtil'; import '../../src/impl/http/HTTPControllerMetaBuilder'; describe('test/util/ControllerMetadataUtil.test.ts', () => { diff --git a/core/controller-decorator/test/util/HTTPPriority.test.ts b/core/controller-decorator/test/util/HTTPPriority.test.ts index 1d823105..767451ac 100644 --- a/core/controller-decorator/test/util/HTTPPriority.test.ts +++ b/core/controller-decorator/test/util/HTTPPriority.test.ts @@ -1,5 +1,5 @@ +import assert from 'node:assert'; import { HTTPPriorityUtil } from '../../src/util/HTTPPriorityUtil'; -import assert from 'assert'; describe('test/util/HTTPPriority.test.ts', () => { describe('path has no regexp', () => { diff --git a/core/core-decorator/index.ts b/core/core-decorator/index.ts index f6c76ea0..6ea6eee7 100644 --- a/core/core-decorator/index.ts +++ b/core/core-decorator/index.ts @@ -1,3 +1,4 @@ +export * from '@eggjs/tegg-types/core-decorator'; export * from './src/decorator/Inject'; export * from './src/decorator/Prototype'; export * from './src/decorator/InitTypeQualifier'; @@ -8,15 +9,6 @@ export * from './src/decorator/EggQualifier'; export * from './src/decorator/MultiInstanceProto'; export * from './src/decorator/ConfigSource'; -export * from './src/enum/AccessLevel'; -export * from './src/enum/ObjectInitType'; -export * from './src/enum/EggType'; - -export * from './src/model/EggPrototypeInfo'; -export * from './src/model/InjectObjectInfo'; -export * from './src/model/QualifierInfo'; -export * from './src/model/EggMultiInstancePrototypeInfo'; - export * from './src/util/MetadataUtil'; export * from './src/util/PrototypeUtil'; export * from './src/util/QualifierUtil'; diff --git a/core/core-decorator/package.json b/core/core-decorator/package.json index d3559996..010fdc94 100644 --- a/core/core-decorator/package.json +++ b/core/core-decorator/package.json @@ -37,6 +37,7 @@ }, "dependencies": { "@eggjs/tegg-common-util": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "reflect-metadata": "^0.1.13" }, "publishConfig": { diff --git a/core/core-decorator/src/decorator/ConfigSource.ts b/core/core-decorator/src/decorator/ConfigSource.ts index 015b9bd8..f8e1508f 100644 --- a/core/core-decorator/src/decorator/ConfigSource.ts +++ b/core/core-decorator/src/decorator/ConfigSource.ts @@ -1,7 +1,6 @@ import { QualifierUtil } from '../util/QualifierUtil'; -import { EggProtoImplClass } from '../model/EggPrototypeInfo'; - -export const ConfigSourceQualifierAttribute = Symbol.for('Qualifier.ConfigSource'); +import { ConfigSourceQualifierAttribute } from '@eggjs/tegg-types'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; export function ConfigSourceQualifier(moduleName: string) { return function(target: any, propertyKey: PropertyKey) { diff --git a/core/core-decorator/src/decorator/ContextProto.ts b/core/core-decorator/src/decorator/ContextProto.ts index fbca5893..00b54cb1 100644 --- a/core/core-decorator/src/decorator/ContextProto.ts +++ b/core/core-decorator/src/decorator/ContextProto.ts @@ -1,12 +1,6 @@ import { Prototype } from './Prototype'; -import { ObjectInitType } from '../enum/ObjectInitType'; -import { AccessLevel } from '../enum/AccessLevel'; - -export interface ContextProtoParams { - name?: string; - accessLevel?: AccessLevel; - protoImplType?: string; -} +import { AccessLevel, ObjectInitType } from '@eggjs/tegg-types'; +import type { ContextProtoParams } from '@eggjs/tegg-types'; export function ContextProto(params?: ContextProtoParams) { return Prototype({ diff --git a/core/core-decorator/src/decorator/EggQualifier.ts b/core/core-decorator/src/decorator/EggQualifier.ts index 6814cd53..af291945 100644 --- a/core/core-decorator/src/decorator/EggQualifier.ts +++ b/core/core-decorator/src/decorator/EggQualifier.ts @@ -1,8 +1,6 @@ +import { EggQualifierAttribute } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, EggType } from '@eggjs/tegg-types'; import { QualifierUtil } from '../util/QualifierUtil'; -import { EggProtoImplClass } from '../model/EggPrototypeInfo'; -import { EggType } from '../enum/EggType'; - -export const EggQualifierAttribute = Symbol.for('Qualifier.Egg'); export function EggQualifier(eggType: EggType) { return function(target: any, propertyKey: PropertyKey) { diff --git a/core/core-decorator/src/decorator/InitTypeQualifier.ts b/core/core-decorator/src/decorator/InitTypeQualifier.ts index 68db50a1..3da0826a 100644 --- a/core/core-decorator/src/decorator/InitTypeQualifier.ts +++ b/core/core-decorator/src/decorator/InitTypeQualifier.ts @@ -1,8 +1,6 @@ +import { InitTypeQualifierAttribute } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, ObjectInitTypeLike } from '@eggjs/tegg-types'; import { QualifierUtil } from '../util/QualifierUtil'; -import { EggProtoImplClass } from '../model/EggPrototypeInfo'; -import { ObjectInitTypeLike } from '../enum/ObjectInitType'; - -export const InitTypeQualifierAttribute = Symbol.for('Qualifier.InitType'); export function InitTypeQualifier(initType: ObjectInitTypeLike) { return function(target: any, propertyKey: PropertyKey) { diff --git a/core/core-decorator/src/decorator/Inject.ts b/core/core-decorator/src/decorator/Inject.ts index e463523e..f5b758a9 100644 --- a/core/core-decorator/src/decorator/Inject.ts +++ b/core/core-decorator/src/decorator/Inject.ts @@ -1,11 +1,5 @@ -import { InjectObjectInfo } from '../model/InjectObjectInfo'; +import type { EggProtoImplClass, InjectObjectInfo, InjectParams } from '@eggjs/tegg-types'; import { PrototypeUtil } from '../util/PrototypeUtil'; -import { EggProtoImplClass } from '../model/EggPrototypeInfo'; - -export interface InjectParams { - // obj instance name, default is property name - name?: string; -} export function Inject(param?: InjectParams | string) { return function(target: any, propertyKey: PropertyKey) { diff --git a/core/core-decorator/src/decorator/ModuleQualifier.ts b/core/core-decorator/src/decorator/ModuleQualifier.ts index 30680011..c69e9265 100644 --- a/core/core-decorator/src/decorator/ModuleQualifier.ts +++ b/core/core-decorator/src/decorator/ModuleQualifier.ts @@ -1,7 +1,6 @@ +import { LoadUnitNameQualifierAttribute } from '@eggjs/tegg-types'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { QualifierUtil } from '../util/QualifierUtil'; -import { EggProtoImplClass } from '../model/EggPrototypeInfo'; - -export const LoadUnitNameQualifierAttribute = Symbol.for('Qualifier.LoadUnitName'); export function ModuleQualifier(moduleName: string) { return function(target: any, propertyKey: PropertyKey) { diff --git a/core/core-decorator/src/decorator/MultiInstanceProto.ts b/core/core-decorator/src/decorator/MultiInstanceProto.ts index fc638af0..446edecd 100644 --- a/core/core-decorator/src/decorator/MultiInstanceProto.ts +++ b/core/core-decorator/src/decorator/MultiInstanceProto.ts @@ -1,13 +1,12 @@ -import { ObjectInitType, ObjectInitTypeLike } from '../enum/ObjectInitType'; -import { AccessLevel } from '../enum/AccessLevel'; -import { DEFAULT_PROTO_IMPL_TYPE } from './Prototype'; -import { +import { ObjectInitType, AccessLevel, DEFAULT_PROTO_IMPL_TYPE } from '@eggjs/tegg-types'; +import type { EggMultiInstanceCallbackPrototypeInfo, EggMultiInstancePrototypeInfo, - MultiInstancePrototypeGetObjectsContext, - ObjectInfo, -} from '../model/EggMultiInstancePrototypeInfo'; -import { EggProtoImplClass } from '../model/EggPrototypeInfo'; + EggProtoImplClass, + MultiInstancePrototypeParams, + MultiInstancePrototypeStaticParams, + MultiInstancePrototypeCallbackParams, +} from '@eggjs/tegg-types'; import { PrototypeUtil } from '../util/PrototypeUtil'; import { StackUtil } from '@eggjs/tegg-common-util'; @@ -17,34 +16,6 @@ const DEFAULT_PARAMS = { protoImplType: DEFAULT_PROTO_IMPL_TYPE, }; -export interface BaseMultiInstancePrototypeCallbackParams { - /** - * obj init type - */ - initType?: ObjectInitTypeLike; - /** - * access level - */ - accessLevel?: AccessLevel; - /** - * EggPrototype implement type - */ - protoImplType?: string; -} - -export interface MultiInstancePrototypeCallbackParams extends BaseMultiInstancePrototypeCallbackParams { - getObjects(ctx: MultiInstancePrototypeGetObjectsContext): ObjectInfo[]; -} - -export interface MultiInstancePrototypeStaticParams extends BaseMultiInstancePrototypeCallbackParams { - /** - * object info list - */ - objects: ObjectInfo[]; -} - -export type MultiInstancePrototypeParams = MultiInstancePrototypeCallbackParams | MultiInstancePrototypeStaticParams; - export function MultiInstanceProto(param: MultiInstancePrototypeParams) { return function(clazz: EggProtoImplClass) { PrototypeUtil.setIsEggMultiInstancePrototype(clazz); diff --git a/core/core-decorator/src/decorator/Prototype.ts b/core/core-decorator/src/decorator/Prototype.ts index 54c52d0d..a8eaa68d 100644 --- a/core/core-decorator/src/decorator/Prototype.ts +++ b/core/core-decorator/src/decorator/Prototype.ts @@ -1,18 +1,7 @@ -import { ObjectInitType, ObjectInitTypeLike } from '../enum/ObjectInitType'; -import { AccessLevel } from '../enum/AccessLevel'; -import { EggProtoImplClass, EggPrototypeInfo } from '../model/EggPrototypeInfo'; -import { PrototypeUtil } from '../util/PrototypeUtil'; import { NameUtil, StackUtil } from '@eggjs/tegg-common-util'; - - -export interface PrototypeParams { - name?: string; - initType?: ObjectInitTypeLike; - accessLevel?: AccessLevel; - protoImplType?: string; -} - -export const DEFAULT_PROTO_IMPL_TYPE = 'DEFAULT'; +import { AccessLevel, DEFAULT_PROTO_IMPL_TYPE, ObjectInitType } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, EggPrototypeInfo, PrototypeParams } from '@eggjs/tegg-types'; +import { PrototypeUtil } from '../util/PrototypeUtil'; const DEFAULT_PARAMS = { initType: ObjectInitType.SINGLETON, diff --git a/core/core-decorator/src/decorator/SingletonProto.ts b/core/core-decorator/src/decorator/SingletonProto.ts index 1e4d33b4..f28d0130 100644 --- a/core/core-decorator/src/decorator/SingletonProto.ts +++ b/core/core-decorator/src/decorator/SingletonProto.ts @@ -1,12 +1,6 @@ +import { AccessLevel, ObjectInitType } from '@eggjs/tegg-types'; +import type { SingletonProtoParams } from '@eggjs/tegg-types'; import { Prototype } from './Prototype'; -import { ObjectInitType } from '../enum/ObjectInitType'; -import { AccessLevel } from '../enum/AccessLevel'; - -interface SingletonProtoParams { - name?: string; - accessLevel?: AccessLevel; - protoImplType?: string; -} export function SingletonProto(params?: SingletonProtoParams) { return Prototype({ diff --git a/core/core-decorator/src/util/MetadataUtil.ts b/core/core-decorator/src/util/MetadataUtil.ts index 72f69ea0..5f57991f 100644 --- a/core/core-decorator/src/util/MetadataUtil.ts +++ b/core/core-decorator/src/util/MetadataUtil.ts @@ -1,7 +1,6 @@ import 'reflect-metadata'; -import { EggProtoImplClass } from '../model/EggPrototypeInfo'; +import type { EggProtoImplClass, MetaDataKey } from '@eggjs/tegg-types'; -export type MetaDataKey = symbol | string; export class MetadataUtil { static deleteMetaData(metadataKey: MetaDataKey, clazz: EggProtoImplClass) { diff --git a/core/core-decorator/src/util/PrototypeUtil.ts b/core/core-decorator/src/util/PrototypeUtil.ts index 79519e36..650c2a37 100644 --- a/core/core-decorator/src/util/PrototypeUtil.ts +++ b/core/core-decorator/src/util/PrototypeUtil.ts @@ -1,10 +1,13 @@ -import { MetadataUtil } from './MetadataUtil'; -import { EggProtoImplClass, EggPrototypeInfo, EggPrototypeName } from '../model/EggPrototypeInfo'; -import { InjectObjectInfo } from '../model/InjectObjectInfo'; -import { +import type { EggMultiInstanceCallbackPrototypeInfo, - EggMultiInstancePrototypeInfo, MultiInstancePrototypeGetObjectsContext, -} from '../model/EggMultiInstancePrototypeInfo'; + EggMultiInstancePrototypeInfo, + EggProtoImplClass, + EggPrototypeInfo, + EggPrototypeName, + InjectObjectInfo, + MultiInstancePrototypeGetObjectsContext, +} from '@eggjs/tegg-types'; +import { MetadataUtil } from './MetadataUtil'; export class PrototypeUtil { static readonly IS_EGG_OBJECT_PROTOTYPE = Symbol.for('EggPrototype#isEggPrototype'); diff --git a/core/core-decorator/src/util/QualifierUtil.ts b/core/core-decorator/src/util/QualifierUtil.ts index 4fd415bb..17ff6081 100644 --- a/core/core-decorator/src/util/QualifierUtil.ts +++ b/core/core-decorator/src/util/QualifierUtil.ts @@ -1,10 +1,7 @@ -import { MetadataUtil } from './MetadataUtil'; import { MapUtil } from '@eggjs/tegg-common-util'; -import { EggProtoImplClass } from '../model/EggPrototypeInfo'; -import { QualifierAttribute, QualifierInfo, QualifierValue } from '../model/QualifierInfo'; - -const QUALIFIER_META_DATA = Symbol.for('EggPrototype#qualifier'); -const PROPERTY_QUALIFIER_META_DATA = Symbol.for('EggPrototype#propertyQualifier'); +import { PROPERTY_QUALIFIER_META_DATA, QUALIFIER_META_DATA } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, QualifierAttribute, QualifierInfo, QualifierValue } from '@eggjs/tegg-types'; +import { MetadataUtil } from './MetadataUtil'; export class QualifierUtil { static addProtoQualifier(clazz: EggProtoImplClass, attribute: QualifierAttribute, value: QualifierValue) { diff --git a/core/core-decorator/test/decorators.test.ts b/core/core-decorator/test/decorators.test.ts index d9589c3f..9bbcfb7e 100644 --- a/core/core-decorator/test/decorators.test.ts +++ b/core/core-decorator/test/decorators.test.ts @@ -1,23 +1,20 @@ -import assert from 'assert'; - -import CacheService from './fixtures/decators/CacheService'; -import ContextCache from './fixtures/decators/ContextCache'; -import SingletonCache from './fixtures/decators/SingletonCache'; - +import assert from 'node:assert'; import { - PrototypeUtil, AccessLevel, ObjectInitType, - EggPrototypeInfo, - InjectObjectInfo, - QualifierUtil, LoadUnitNameQualifierAttribute, InitTypeQualifierAttribute, DEFAULT_PROTO_IMPL_TYPE, -} from '..'; +} from '@eggjs/tegg-types'; +import type { EggPrototypeInfo, EggMultiInstancePrototypeInfo, InjectObjectInfo } from '@eggjs/tegg-types'; + +import CacheService from './fixtures/decators/CacheService'; +import ContextCache from './fixtures/decators/ContextCache'; +import SingletonCache from './fixtures/decators/SingletonCache'; + +import { PrototypeUtil, QualifierUtil } from '..'; import QualifierCacheService from './fixtures/decators/QualifierCacheService'; import { FOO_ATTRIBUTE, FooLogger } from './fixtures/decators/FooLogger'; -import { EggMultiInstancePrototypeInfo } from '../src/model/EggMultiInstancePrototypeInfo'; describe('test/decorator.test.ts', () => { describe('ContextProto', () => { diff --git a/core/core-decorator/test/fixtures/decators/ContextCache.ts b/core/core-decorator/test/fixtures/decators/ContextCache.ts index f1fcc6dc..b34c2123 100644 --- a/core/core-decorator/test/fixtures/decators/ContextCache.ts +++ b/core/core-decorator/test/fixtures/decators/ContextCache.ts @@ -1,4 +1,5 @@ -import { AccessLevel, ContextProto } from '../../..'; +import { AccessLevel } from '@eggjs/tegg-types'; +import { ContextProto } from '../../..'; import { ICache } from './ICache'; @ContextProto({ diff --git a/core/core-decorator/test/fixtures/decators/FooLogger.ts b/core/core-decorator/test/fixtures/decators/FooLogger.ts index ba5b8aa2..41742af6 100644 --- a/core/core-decorator/test/fixtures/decators/FooLogger.ts +++ b/core/core-decorator/test/fixtures/decators/FooLogger.ts @@ -1,6 +1,5 @@ +import { AccessLevel, ObjectInitType } from '@eggjs/tegg-types'; import { MultiInstanceProto } from '../../../src/decorator/MultiInstanceProto'; -import { AccessLevel } from '../../../src/enum/AccessLevel'; -import { ObjectInitType } from '../../../src/enum/ObjectInitType'; export const FOO_ATTRIBUTE = Symbol.for('FOO_ATTRIBUTE'); diff --git a/core/core-decorator/test/fixtures/decators/QualifierCacheService.ts b/core/core-decorator/test/fixtures/decators/QualifierCacheService.ts index 0da37845..94a1df38 100644 --- a/core/core-decorator/test/fixtures/decators/QualifierCacheService.ts +++ b/core/core-decorator/test/fixtures/decators/QualifierCacheService.ts @@ -1,4 +1,5 @@ -import { ContextProto, InitTypeQualifier, Inject, ModuleQualifier, ObjectInitType } from '../../..'; +import { ObjectInitType } from '@eggjs/tegg-types'; +import { ContextProto, InitTypeQualifier, Inject, ModuleQualifier } from '../../..'; import { ICache } from './ICache'; @ContextProto() diff --git a/core/core-decorator/test/fixtures/decators/SingletonCache.ts b/core/core-decorator/test/fixtures/decators/SingletonCache.ts index becf2c40..b85365c1 100644 --- a/core/core-decorator/test/fixtures/decators/SingletonCache.ts +++ b/core/core-decorator/test/fixtures/decators/SingletonCache.ts @@ -1,4 +1,5 @@ -import { AccessLevel, SingletonProto } from '../../..'; +import { AccessLevel } from '@eggjs/tegg-types'; +import { SingletonProto } from '../../..'; import { ICache } from './ICache'; @SingletonProto({ diff --git a/core/core-decorator/test/util/MetadataUtil.test.ts b/core/core-decorator/test/util/MetadataUtil.test.ts index 21dbfbb8..2e747051 100644 --- a/core/core-decorator/test/util/MetadataUtil.test.ts +++ b/core/core-decorator/test/util/MetadataUtil.test.ts @@ -1,4 +1,4 @@ -import assert from 'assert'; +import assert from 'node:assert'; import { MetadataUtil } from '../..'; class Parent { diff --git a/core/dal-decorator/index.ts b/core/dal-decorator/index.ts index 542f5a20..5546ad4f 100644 --- a/core/dal-decorator/index.ts +++ b/core/dal-decorator/index.ts @@ -1,9 +1,4 @@ -export * from './src/enum/CompressionType'; -export * from './src/enum/InsertMethod'; -export * from './src/enum/RowFormat'; -export * from './src/enum/IndexType'; -export * from './src/enum/ColumnType'; - +export * from '@eggjs/tegg-types/dal'; export * from './src/decorator/Index'; export * from './src/decorator/Table'; export * from './src/decorator/Column'; @@ -17,8 +12,5 @@ export * from './src/model/ColumnModel'; export * from './src/model/IndexModel'; export * from './src/model/TableModel'; -export * from './src/type/DateSource'; export * from './src/type/Spatial'; -export * from './src/type/SqlMap'; -export * from './src/type/ColumnTsType'; export * from './src/type/MySql'; diff --git a/core/dal-decorator/package.json b/core/dal-decorator/package.json index 16e05f52..df7e8669 100644 --- a/core/dal-decorator/package.json +++ b/core/dal-decorator/package.json @@ -39,6 +39,7 @@ "dependencies": { "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "lodash.snakecase": "^4.1.1", "pluralize": "^7.0.0" }, diff --git a/core/dal-decorator/src/decorator/Column.ts b/core/dal-decorator/src/decorator/Column.ts index 8790fb15..a1a491e3 100644 --- a/core/dal-decorator/src/decorator/Column.ts +++ b/core/dal-decorator/src/decorator/Column.ts @@ -1,265 +1,6 @@ import assert from 'node:assert'; -import { ColumnType } from '../enum/ColumnType'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { ColumnParams, ColumnTypeParams, EggProtoImplClass } from '@eggjs/tegg-types'; import { ColumnInfoUtil } from '../util/ColumnInfoUtil'; -import { ColumnFormat } from '../enum/ColumnFormat'; - -export interface ColumnParams { - name?: string; - default?: string; - canNull?: boolean; - comment?: string; - visible?: boolean; - autoIncrement?: boolean; - uniqueKey?: boolean; - primaryKey?: boolean; - collate?: string; - columnFormat?: ColumnFormat; - engineAttribute?: string; - secondaryEngineAttribute?: string; -} - -export interface IColumnTypeParams { - type: ColumnType; -} - -export interface BitParams extends IColumnTypeParams { - type: ColumnType.BIT, - length?: number; -} - -export interface BoolParams extends IColumnTypeParams { - type: ColumnType.BOOL, -} - -interface BaseNumericParams extends IColumnTypeParams { - length?: number; - unsigned?: boolean; - zeroFill?: boolean; -} - -interface BaseFloatNumericParams extends IColumnTypeParams { - length?: number; - fractionalLength?: number; - unsigned?: boolean; - zeroFill?: boolean; -} - -export interface TinyIntParams extends BaseNumericParams { - type: ColumnType.TINYINT; -} - -export interface SmallIntParams extends BaseNumericParams { - type: ColumnType.SMALLINT; -} - -export interface MediumIntParams extends BaseNumericParams { - type: ColumnType.MEDIUMINT; -} - -export interface IntParams extends BaseNumericParams { - type: ColumnType.INT; -} - -export interface BigIntParams extends BaseNumericParams { - type: ColumnType.BIGINT; -} - -export interface DecimalParams extends BaseFloatNumericParams { - type: ColumnType.DECIMAL; -} - -export interface FloatParams extends BaseFloatNumericParams { - type: ColumnType.FLOAT; -} - -export interface DoubleParams extends BaseFloatNumericParams { - type: ColumnType.DOUBLE; -} - -export interface DateParams extends IColumnTypeParams { - type: ColumnType.DATE; -} - -export interface DateTimeParams extends IColumnTypeParams { - type: ColumnType.DATETIME; - precision?: number; - autoUpdate?: boolean; -} - -export interface TimestampParams extends IColumnTypeParams { - type: ColumnType.TIMESTAMP; - precision?: number; - autoUpdate?: boolean; -} - -export interface TimeParams extends IColumnTypeParams { - type: ColumnType.TIME; - precision?: number; -} - -export interface YearParams extends IColumnTypeParams { - type: ColumnType.YEAR; -} - -export interface CharParams extends IColumnTypeParams { - type: ColumnType.CHAR; - length?: number; - characterSet?: string; - collate?: string; -} - -export interface VarCharParams extends IColumnTypeParams { - type: ColumnType.VARCHAR; - length: number; - characterSet?: string; - collate?: string; -} - -export interface BinaryParams extends IColumnTypeParams { - type: ColumnType.BINARY; - length?: number; -} - -export interface VarBinaryParams extends IColumnTypeParams { - type: ColumnType.VARBINARY; - length: number; -} - -export interface TinyBlobParams extends IColumnTypeParams { - type: ColumnType.TINYBLOB; -} - -export interface TinyTextParams extends IColumnTypeParams { - type: ColumnType.TINYTEXT; - characterSet?: string; - collate?: string; -} - -export interface BlobParams extends IColumnTypeParams { - type: ColumnType.BLOB; - length?: number; -} - -export interface TextParams extends IColumnTypeParams { - type: ColumnType.TEXT; - length?: number; - characterSet?: string; - collate?: string; -} - -export interface MediumBlobParams extends IColumnTypeParams { - type: ColumnType.MEDIUMBLOB; -} - -export interface LongBlobParams extends IColumnTypeParams { - type: ColumnType.LONGBLOB; -} - -export interface MediumTextParams extends IColumnTypeParams { - type: ColumnType.MEDIUMTEXT; - characterSet?: string; - collate?: string; -} - -export interface LongTextParams extends IColumnTypeParams { - type: ColumnType.LONGTEXT; - characterSet?: string; - collate?: string; -} - -export interface EnumParams extends IColumnTypeParams { - type: ColumnType.ENUM; - enums: string[]; - characterSet?: string; - collate?: string; -} - -export interface SetParams extends IColumnTypeParams { - type: ColumnType.SET; - enums: string[]; - characterSet?: string; - collate?: string; -} - -export interface JsonParams extends IColumnTypeParams { - type: ColumnType.JSON; -} - -export interface BaseSpatialParams extends IColumnTypeParams { - SRID?: number; -} - -export interface GeometryParams extends BaseSpatialParams { - type: ColumnType.GEOMETRY; -} - -export interface PointParams extends BaseSpatialParams { - type: ColumnType.POINT; -} - -export interface LinestringParams extends BaseSpatialParams { - type: ColumnType.LINESTRING; -} - -export interface PolygonParams extends BaseSpatialParams { - type: ColumnType.POLYGON; -} - -export interface MultiPointParams extends BaseSpatialParams { - type: ColumnType.MULTIPOINT; -} - -export interface MultiLinestringParams extends BaseSpatialParams { - type: ColumnType.MULTILINESTRING; -} - -export interface MultiPolygonParams extends BaseSpatialParams { - type: ColumnType.MULTIPOLYGON; -} - -export interface GeometryCollectionParams extends BaseSpatialParams { - type: ColumnType.GEOMETRYCOLLECTION; -} - -export type ColumnTypeParams = BitParams -| BoolParams -| TinyIntParams -| SmallIntParams -| MediumIntParams -| IntParams -| BigIntParams -| DecimalParams -| FloatParams -| DoubleParams -| DateParams -| DateTimeParams -| TimestampParams -| TimeParams -| YearParams -| CharParams -| VarCharParams -| BinaryParams -| VarBinaryParams -| TinyBlobParams -| TinyTextParams -| BlobParams -| TextParams -| MediumBlobParams -| MediumTextParams -| LongBlobParams -| LongTextParams -| EnumParams -| SetParams -| JsonParams -| GeometryParams -| PointParams -| LinestringParams -| PolygonParams -| MultiPointParams -| MultiLinestringParams -| MultiPolygonParams -| GeometryCollectionParams; export function Column(type: ColumnTypeParams, params?: ColumnParams) { return function(target: any, propertyKey: PropertyKey) { diff --git a/core/dal-decorator/src/decorator/DataSourceQualifier.ts b/core/dal-decorator/src/decorator/DataSourceQualifier.ts index 35213e72..ab755b6d 100644 --- a/core/dal-decorator/src/decorator/DataSourceQualifier.ts +++ b/core/dal-decorator/src/decorator/DataSourceQualifier.ts @@ -1,7 +1,6 @@ -import { QualifierUtil, EggProtoImplClass } from '@eggjs/tegg'; - -export const DataSourceQualifierAttribute = Symbol('Qualifier.DataSource'); -export const DataSourceInjectName = 'dataSource'; +import { DataSourceQualifierAttribute } from '@eggjs/tegg-types'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; +import { QualifierUtil } from '@eggjs/core-decorator'; export function DataSourceQualifier(dataSourceName: string) { return function(target: any, propertyKey: PropertyKey) { diff --git a/core/dal-decorator/src/decorator/Index.ts b/core/dal-decorator/src/decorator/Index.ts index 7df13ca5..65cf8be1 100644 --- a/core/dal-decorator/src/decorator/Index.ts +++ b/core/dal-decorator/src/decorator/Index.ts @@ -1,19 +1,6 @@ -import { IndexType } from '../enum/IndexType'; -import { IndexStoreType } from '../enum/IndexStoreType'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass, IndexParams } from '@eggjs/tegg-types'; import { IndexInfoUtil } from '../util/IndexInfoUtil'; -export interface IndexParams { - keys: string[]; - name?: string; - type?: IndexType, - storeType?: IndexStoreType; - comment?: string; - engineAttribute?: string; - secondaryEngineAttribute?: string; - parser?: string; -} - export function Index(params: IndexParams) { return function(constructor: EggProtoImplClass) { IndexInfoUtil.addIndex(constructor, params); diff --git a/core/dal-decorator/src/decorator/Table.ts b/core/dal-decorator/src/decorator/Table.ts index ddd583ea..899d63de 100644 --- a/core/dal-decorator/src/decorator/Table.ts +++ b/core/dal-decorator/src/decorator/Table.ts @@ -1,32 +1,8 @@ -// Create Table https://dev.mysql.com/doc/refman/8.0/en/create-table.html - -import { AccessLevel, EggProtoImplClass, ObjectInitType, Prototype, PrototypeUtil } from '@eggjs/core-decorator'; -import { TableInfoUtil } from '../util/TableInfoUtil'; -import { InsertMethod } from '../enum/InsertMethod'; +import { Prototype, PrototypeUtil } from '@eggjs/core-decorator'; import { StackUtil } from '@eggjs/tegg-common-util'; -import { CompressionType } from '../enum/CompressionType'; -import { RowFormat } from '../enum/RowFormat'; - -export interface TableParams { - name?: string; - dataSourceName?: string; - comment?: string; - autoExtendSize?: number; - autoIncrement?: number; - avgRowLength?: number; - characterSet?: string; - collate?: string; - compression?: CompressionType; - encryption?: boolean; - engine?: string; - engineAttribute?: string; - insertMethod?: InsertMethod; - keyBlockSize?: number; - maxRows?: number; - minRows?: number; - rowFormat?: RowFormat; - secondaryEngineAttribute?: string; -} +import { AccessLevel, ObjectInitType } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, TableParams } from '@eggjs/tegg-types'; +import { TableInfoUtil } from '../util/TableInfoUtil'; export function Table(params?: TableParams) { return function(constructor: EggProtoImplClass) { diff --git a/core/dal-decorator/src/model/ColumnModel.ts b/core/dal-decorator/src/model/ColumnModel.ts index b3215410..d6a36c1b 100644 --- a/core/dal-decorator/src/model/ColumnModel.ts +++ b/core/dal-decorator/src/model/ColumnModel.ts @@ -1,6 +1,5 @@ -import { ColumnFormat } from '../enum/ColumnFormat'; -import { ColumnParams, ColumnTypeParams } from '../decorator/Column'; import snakecase from 'lodash.snakecase'; +import type { ColumnFormat, ColumnParams, ColumnTypeParams } from '@eggjs/tegg-types'; export class ColumnModel { columnName: string; diff --git a/core/dal-decorator/src/model/IndexModel.ts b/core/dal-decorator/src/model/IndexModel.ts index d72ac126..924b160f 100644 --- a/core/dal-decorator/src/model/IndexModel.ts +++ b/core/dal-decorator/src/model/IndexModel.ts @@ -1,6 +1,5 @@ -import { IndexType } from '../enum/IndexType'; -import { IndexStoreType } from '../enum/IndexStoreType'; -import { IndexParams } from '../decorator/Index'; +import { IndexType } from '@eggjs/tegg-types'; +import type { IndexParams, IndexStoreType } from '@eggjs/tegg-types'; import { ColumnModel } from './ColumnModel'; export interface IndexKey { diff --git a/core/dal-decorator/src/model/TableModel.ts b/core/dal-decorator/src/model/TableModel.ts index a5fa73dc..89ded854 100644 --- a/core/dal-decorator/src/model/TableModel.ts +++ b/core/dal-decorator/src/model/TableModel.ts @@ -1,16 +1,13 @@ import assert from 'node:assert'; -import { CompressionType } from '../enum/CompressionType'; -import { InsertMethod } from '../enum/InsertMethod'; -import { RowFormat } from '../enum/RowFormat'; +import pluralize from 'pluralize'; +import snakecase from 'lodash.snakecase'; +import { IndexType } from '@eggjs/tegg-types'; +import type { CompressionType, EggProtoImplClass, InsertMethod, RowFormat } from '@eggjs/tegg-types'; import { ColumnModel } from './ColumnModel'; import { IndexModel } from './IndexModel'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; import { TableInfoUtil } from '../util/TableInfoUtil'; -import pluralize from 'pluralize'; -import snakecase from 'lodash.snakecase'; import { ColumnInfoUtil } from '../util/ColumnInfoUtil'; import { IndexInfoUtil } from '../util/IndexInfoUtil'; -import { IndexType } from '../enum/IndexType'; export class TableModel { clazz: EggProtoImplClass; diff --git a/core/dal-decorator/src/type/Spatial.ts b/core/dal-decorator/src/type/Spatial.ts index 405fbc26..d588491a 100644 --- a/core/dal-decorator/src/type/Spatial.ts +++ b/core/dal-decorator/src/type/Spatial.ts @@ -1,18 +1,5 @@ -import { ColumnType } from '../enum/ColumnType'; - -export interface Point { - x: number; - y: number; -} - -export type Line = Array; -export type Polygon = Array; -export type Geometry = Point | Line | Polygon; - -export type MultiPoint = Array; -export type MultiLine = Array; -export type MultiPolygon = Array; -export type GeometryCollection = Array; +import { ColumnType } from '@eggjs/tegg-types'; +import type { Geometry, GeometryCollection } from '@eggjs/tegg-types'; export class SpatialHelper { static isPoint(t: Geometry) { diff --git a/core/dal-decorator/src/util/ColumnInfoUtil.ts b/core/dal-decorator/src/util/ColumnInfoUtil.ts index 616b64bb..96e3ba8a 100644 --- a/core/dal-decorator/src/util/ColumnInfoUtil.ts +++ b/core/dal-decorator/src/util/ColumnInfoUtil.ts @@ -1,8 +1,7 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; -import { ColumnParams, ColumnTypeParams } from '../decorator/Column'; +import { DAL_COLUMN_INFO_MAP, DAL_COLUMN_TYPE_MAP } from '@eggjs/tegg-types'; +import type { ColumnParams, ColumnTypeParams, EggProtoImplClass } from '@eggjs/tegg-types'; +import { MetadataUtil } from '@eggjs/core-decorator'; -export const DAL_COLUMN_INFO_MAP = Symbol('EggPrototype#dalColumnInfoMap'); -export const DAL_COLUMN_TYPE_MAP = Symbol('EggPrototype#dalColumnTypeMap'); export type ColumnInfoMap = Map; export type ColumnTypeMap = Map; diff --git a/core/dal-decorator/src/util/IndexInfoUtil.ts b/core/dal-decorator/src/util/IndexInfoUtil.ts index 736cd845..e2aa34ca 100644 --- a/core/dal-decorator/src/util/IndexInfoUtil.ts +++ b/core/dal-decorator/src/util/IndexInfoUtil.ts @@ -1,7 +1,6 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; -import { IndexParams } from '../decorator/Index'; - -export const DAL_INDEX_LIST = Symbol('EggPrototype#dalIndexList'); +import { DAL_INDEX_LIST } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, IndexParams } from '@eggjs/tegg-types'; +import { MetadataUtil } from '@eggjs/core-decorator'; export class IndexInfoUtil { static addIndex(clazz: EggProtoImplClass, index: IndexParams) { diff --git a/core/dal-decorator/src/util/TableInfoUtil.ts b/core/dal-decorator/src/util/TableInfoUtil.ts index 36c29aaa..e6a46ea2 100644 --- a/core/dal-decorator/src/util/TableInfoUtil.ts +++ b/core/dal-decorator/src/util/TableInfoUtil.ts @@ -1,8 +1,6 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; -import { TableParams } from '../decorator/Table'; - -export const DAL_IS_TABLE = Symbol('EggPrototype#dalIsTable'); -export const DAL_TABLE_PARAMS = Symbol('EggPrototype#dalTableParams'); +import { DAL_IS_TABLE, DAL_TABLE_PARAMS } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, TableParams } from '@eggjs/tegg-types'; +import { MetadataUtil } from '@eggjs/core-decorator'; export const TABLE_CLAZZ_LIST: Array = []; diff --git a/core/dal-decorator/test/fixtures/modules/dal/Foo.ts b/core/dal-decorator/test/fixtures/modules/dal/Foo.ts index 0db87f50..3389bea0 100644 --- a/core/dal-decorator/test/fixtures/modules/dal/Foo.ts +++ b/core/dal-decorator/test/fixtures/modules/dal/Foo.ts @@ -1,4 +1,5 @@ -import { Table, Index, Column, ColumnType, IndexType } from '../../../..'; +import { ColumnType, IndexType } from '@eggjs/tegg-types'; +import { Table, Index, Column } from '../../../..'; @Table({ comment: 'foo table', diff --git a/core/dal-decorator/test/index.test.ts b/core/dal-decorator/test/index.test.ts index 58feb335..1fbaa407 100644 --- a/core/dal-decorator/test/index.test.ts +++ b/core/dal-decorator/test/index.test.ts @@ -1,6 +1,7 @@ import assert from 'node:assert'; import { Foo } from './fixtures/modules/dal/Foo'; -import { ColumnInfoUtil, ColumnType, IndexInfoUtil, IndexType, TableInfoUtil } from '..'; +import { ColumnType, IndexType } from '@eggjs/tegg-types'; +import { ColumnInfoUtil, IndexInfoUtil, TableInfoUtil } from '..'; import { TableModel } from '../src/model/TableModel'; describe('test/dal/index.test.ts', () => { diff --git a/core/dal-runtime/package.json b/core/dal-runtime/package.json index ef47bcb6..e71b6c89 100644 --- a/core/dal-runtime/package.json +++ b/core/dal-runtime/package.json @@ -41,6 +41,7 @@ "dependencies": { "@eggjs/rds": "^1.0.0", "@eggjs/tegg": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "js-beautify": "^1.15.1", "lodash": "^4.17.21", "nunjucks": "^3.2.4", diff --git a/core/dal-runtime/src/BaseSqlMap.ts b/core/dal-runtime/src/BaseSqlMap.ts index 78f7129f..83e54447 100644 --- a/core/dal-runtime/src/BaseSqlMap.ts +++ b/core/dal-runtime/src/BaseSqlMap.ts @@ -1,14 +1,9 @@ import _ from 'lodash'; -import { ColumnType, IndexType, SqlType, SqlMap, TableModel } from '@eggjs/tegg/dal'; -import { Logger } from '@eggjs/tegg'; +import { TableModel } from '@eggjs/tegg/dal'; +import { ColumnType, IndexType, SqlType, SqlMap } from '@eggjs/tegg-types'; +import type { Logger, GenerateSqlMap } from '@eggjs/tegg-types'; import { TemplateUtil } from './TemplateUtil'; -export interface GenerateSqlMap { - name: string; - type: SqlType.DELETE | SqlType.UPDATE | SqlType.INSERT | SqlType.SELECT; - sql: string; -} - export class BaseSqlMapGenerator { private readonly tableModel: TableModel; private readonly logger: Logger; diff --git a/core/dal-runtime/src/CodeGenerator.ts b/core/dal-runtime/src/CodeGenerator.ts index 4e30811d..7140bd3b 100644 --- a/core/dal-runtime/src/CodeGenerator.ts +++ b/core/dal-runtime/src/CodeGenerator.ts @@ -1,25 +1,14 @@ -import nunjucks, { type Environment } from 'nunjucks'; +import fs from 'node:fs/promises'; import path from 'node:path'; +import { js_beautify } from 'js-beautify'; import _ from 'lodash'; -import { TemplateUtil } from './TemplateUtil'; +import nunjucks, { type Environment } from 'nunjucks'; +import { Templates } from '@eggjs/tegg-types'; +import type { CodeGeneratorOptions } from '@eggjs/tegg-types'; import { ColumnModel, TableModel } from '@eggjs/tegg/dal'; import { PrototypeUtil } from '@eggjs/tegg'; -import fs from 'node:fs/promises'; -import { js_beautify } from 'js-beautify'; import { SqlGenerator } from './SqlGenerator'; - -export interface CodeGeneratorOptions { - moduleDir: string; - moduleName: string; - teggPkg?: string; - dalPkg?: string; -} - -export enum Templates { - BASE_DAO = 'base_dao', - DAO = 'dao', - EXTENSION = 'extension', -} +import { TemplateUtil } from './TemplateUtil'; export class CodeGenerator { private readonly moduleDir: string; diff --git a/core/dal-runtime/src/DataSource.ts b/core/dal-runtime/src/DataSource.ts index 0750f9ac..403f0b63 100644 --- a/core/dal-runtime/src/DataSource.ts +++ b/core/dal-runtime/src/DataSource.ts @@ -1,4 +1,5 @@ -import { DataSource as IDataSource, PaginateData, SqlType, TableModel } from '@eggjs/tegg/dal'; +import { TableModel } from '@eggjs/tegg/dal'; +import type { DataSource as IDataSource, PaginateData, SqlType } from '@eggjs/tegg-types'; import { MysqlDataSource } from './MySqlDataSource'; import { TableSqlMap } from './TableSqlMap'; import { TableModelInstanceBuilder } from './TableModelInstanceBuilder'; diff --git a/core/dal-runtime/src/DatabaseForker.ts b/core/dal-runtime/src/DatabaseForker.ts index ede373ce..b567585a 100644 --- a/core/dal-runtime/src/DatabaseForker.ts +++ b/core/dal-runtime/src/DatabaseForker.ts @@ -1,8 +1,8 @@ -import { DataSourceOptions } from './MySqlDataSource'; -import { RDSClient } from '@eggjs/rds'; import path from 'node:path'; import fs from 'node:fs/promises'; import assert from 'node:assert'; +import { RDSClient } from '@eggjs/rds'; +import { DataSourceOptions } from './MySqlDataSource'; export class DatabaseForker { private readonly env: string; diff --git a/core/dal-runtime/src/SqlGenerator.ts b/core/dal-runtime/src/SqlGenerator.ts index 35e5522b..8ccff903 100644 --- a/core/dal-runtime/src/SqlGenerator.ts +++ b/core/dal-runtime/src/SqlGenerator.ts @@ -1,11 +1,10 @@ import { - BaseSpatialParams, ColumnModel, - ColumnType, - ColumnTypeParams, - IndexModel, IndexType, + IndexModel, TableModel, } from '@eggjs/tegg/dal'; +import { ColumnType, IndexType } from '@eggjs/tegg-types'; +import type { BaseSpatialParams, ColumnTypeParams } from '@eggjs/tegg-types'; // TODO diff 实现 export class SqlGenerator { diff --git a/core/dal-runtime/src/SqlMapLoader.ts b/core/dal-runtime/src/SqlMapLoader.ts index 5877936c..ead1770b 100644 --- a/core/dal-runtime/src/SqlMapLoader.ts +++ b/core/dal-runtime/src/SqlMapLoader.ts @@ -1,6 +1,6 @@ import path from 'node:path'; -import { TableModel, SqlMap } from '@eggjs/tegg/dal'; -import { Logger } from '@eggjs/tegg'; +import { TableModel } from '@eggjs/tegg/dal'; +import type { Logger, SqlMap } from '@eggjs/tegg-types'; import { BaseSqlMapGenerator } from './BaseSqlMap'; import { TableSqlMap } from './TableSqlMap'; import { LoaderUtil } from '@eggjs/tegg/helper'; diff --git a/core/dal-runtime/src/TableSqlMap.ts b/core/dal-runtime/src/TableSqlMap.ts index 8f98a217..da918f25 100644 --- a/core/dal-runtime/src/TableSqlMap.ts +++ b/core/dal-runtime/src/TableSqlMap.ts @@ -2,7 +2,8 @@ import { Template } from 'nunjucks'; import { NunjucksUtils } from './NunjucksUtil'; import { TemplateUtil } from './TemplateUtil'; -import { SqlMap, SqlType } from '@eggjs/tegg/dal'; +import { SqlType } from '@eggjs/tegg-types'; +import type { SqlMap } from '@eggjs/tegg-types'; export interface SqlGenerator { type: SqlType; diff --git a/core/dal-runtime/src/TemplateUtil.ts b/core/dal-runtime/src/TemplateUtil.ts index cc23832d..1fbc6358 100644 --- a/core/dal-runtime/src/TemplateUtil.ts +++ b/core/dal-runtime/src/TemplateUtil.ts @@ -1,15 +1,16 @@ import path from 'node:path'; -import { - ColumnModel, - ColumnType, - Geometry, GeometryCollection, +import { ColumnModel, SpatialHelper } from '@eggjs/tegg/dal'; +import { ColumnType } from '@eggjs/tegg-types'; +import type { + Geometry, + GeometryCollection, Line, MultiLine, MultiPoint, MultiPolygon, Point, - Polygon, SpatialHelper, -} from '@eggjs/tegg/dal'; + Polygon, +} from '@eggjs/tegg-types'; export class TemplateUtil { static isSpatialType(columnModel: ColumnModel): boolean { diff --git a/core/dal-runtime/test/DAO.test.ts b/core/dal-runtime/test/DAO.test.ts index eff290ba..dec52ba2 100644 --- a/core/dal-runtime/test/DAO.test.ts +++ b/core/dal-runtime/test/DAO.test.ts @@ -1,9 +1,9 @@ import assert from 'node:assert'; +import path from 'node:path'; +import { TableModel } from '@eggjs/dal-decorator'; import { MysqlDataSource } from '../src/MySqlDataSource'; import { SqlMapLoader } from '../src/SqlMapLoader'; import { Foo } from './fixtures/modules/dal/Foo'; -import { TableModel } from '@eggjs/dal-decorator'; -import path from 'node:path'; import { DataSource } from '../src/DataSource'; import FooDAO from './fixtures/modules/dal/dal/dao/FooDAO'; import { DatabaseForker } from '../src/DatabaseForker'; diff --git a/core/dal-runtime/test/DataSource.test.ts b/core/dal-runtime/test/DataSource.test.ts index e4e2fda6..a7a5f3b6 100644 --- a/core/dal-runtime/test/DataSource.test.ts +++ b/core/dal-runtime/test/DataSource.test.ts @@ -1,12 +1,12 @@ import assert from 'node:assert'; +import path from 'node:path'; +import { DeleteResult, InsertResult, UpdateResult } from '@eggjs/rds/lib/types'; +import { TableModel } from '@eggjs/dal-decorator'; import { MysqlDataSource } from '../src/MySqlDataSource'; import { SqlMapLoader } from '../src/SqlMapLoader'; import { Foo } from './fixtures/modules/dal/Foo'; -import { TableModel } from '@eggjs/dal-decorator'; -import path from 'node:path'; import { DataSource } from '../src/DataSource'; import { TableModelInstanceBuilder } from '../src/TableModelInstanceBuilder'; -import { DeleteResult, InsertResult, UpdateResult } from '@eggjs/rds/lib/types'; import { DatabaseForker } from '../src/DatabaseForker'; describe('test/Datasource.test.ts', () => { diff --git a/core/dal-runtime/test/SqlGenerator.test.ts b/core/dal-runtime/test/SqlGenerator.test.ts index 8f1ba217..3e1d525c 100644 --- a/core/dal-runtime/test/SqlGenerator.test.ts +++ b/core/dal-runtime/test/SqlGenerator.test.ts @@ -1,7 +1,7 @@ import assert from 'node:assert'; +import { TableModel } from '@eggjs/dal-decorator'; import { Foo } from './fixtures/modules/dal/Foo'; import { SqlGenerator } from '../src/SqlGenerator'; -import { TableModel } from '@eggjs/dal-decorator'; import { AutoUpdateTime } from './fixtures/modules/dal/AutoUpdateTime'; describe('test/SqlGenerator.test.ts', () => { diff --git a/core/dal-runtime/test/fixtures/modules/dal/Foo.ts b/core/dal-runtime/test/fixtures/modules/dal/Foo.ts index 2afdaab7..33eff159 100644 --- a/core/dal-runtime/test/fixtures/modules/dal/Foo.ts +++ b/core/dal-runtime/test/fixtures/modules/dal/Foo.ts @@ -4,11 +4,16 @@ import { Geometry, GeometryCollection, Index, + IndexStoreType, IndexType, - Line, MultiLine, MultiPoint, MultiPolygon, Point, Polygon, + Line, + MultiLine, + MultiPoint, + MultiPolygon, + Point, + Polygon, Table, } from '@eggjs/dal-decorator'; -import { IndexStoreType } from '@eggjs/dal-decorator/src/enum/IndexStoreType'; @Table({ name: 'egg_foo', diff --git a/core/dal-runtime/test/fixtures/modules/generate_codes/Foo.ts b/core/dal-runtime/test/fixtures/modules/generate_codes/Foo.ts index cbf4cad8..5e1a3493 100644 --- a/core/dal-runtime/test/fixtures/modules/generate_codes/Foo.ts +++ b/core/dal-runtime/test/fixtures/modules/generate_codes/Foo.ts @@ -5,10 +5,15 @@ import { GeometryCollection, Index, IndexType, - Line, MultiLine, MultiPoint, MultiPolygon, Point, Polygon, + Line, + IndexStoreType, + MultiLine, + MultiPoint, + MultiPolygon, + Point, + Polygon, Table, } from '@eggjs/dal-decorator'; -import { IndexStoreType } from '@eggjs/dal-decorator/src/enum/IndexStoreType'; @Table({ name: 'egg_foo', diff --git a/core/dynamic-inject-runtime/package.json b/core/dynamic-inject-runtime/package.json index e404d73e..fb1cb052 100644 --- a/core/dynamic-inject-runtime/package.json +++ b/core/dynamic-inject-runtime/package.json @@ -47,7 +47,8 @@ "@eggjs/tegg-dynamic-inject": "^3.37.1", "@eggjs/tegg-lifecycle": "^3.37.1", "@eggjs/tegg-metadata": "^3.37.1", - "@eggjs/tegg-runtime": "^3.37.1" + "@eggjs/tegg-runtime": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1" }, "devDependencies": { "@eggjs/module-test-util": "^3.37.1", diff --git a/core/dynamic-inject-runtime/src/EggObjectFactory.ts b/core/dynamic-inject-runtime/src/EggObjectFactory.ts index c01f2034..b070b3f6 100644 --- a/core/dynamic-inject-runtime/src/EggObjectFactory.ts +++ b/core/dynamic-inject-runtime/src/EggObjectFactory.ts @@ -1,10 +1,12 @@ -import type { EggContainerFactory } from '@eggjs/tegg-runtime'; -import { AccessLevel, PrototypeUtil, QualifierValue, SingletonProto } from '@eggjs/core-decorator'; -import { +import { AccessLevel } from '@eggjs/tegg-types'; +import type { + QualifierValue, EggAbstractClazz, EggObjectFactory as IEggObjectFactory, - QualifierImplUtil, -} from '@eggjs/tegg-dynamic-inject'; +} from '@eggjs/tegg-types'; +import type { EggContainerFactory } from '@eggjs/tegg-runtime'; +import { PrototypeUtil, SingletonProto } from '@eggjs/core-decorator'; +import { QualifierImplUtil } from '@eggjs/tegg-dynamic-inject'; import { EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE } from './EggObjectFactoryPrototype'; diff --git a/core/dynamic-inject-runtime/src/EggObjectFactoryObject.ts b/core/dynamic-inject-runtime/src/EggObjectFactoryObject.ts index 53535046..dcb9a0e0 100644 --- a/core/dynamic-inject-runtime/src/EggObjectFactoryObject.ts +++ b/core/dynamic-inject-runtime/src/EggObjectFactoryObject.ts @@ -1,13 +1,15 @@ import { EggContainerFactory, - EggContext, - EggObject, EggObjectFactory as TEggObjectFactory, } from '@eggjs/tegg-runtime'; import { EggObjectFactoryPrototype } from './EggObjectFactoryPrototype'; -import { EggObjectName } from '@eggjs/core-decorator'; import { IdenticalUtil } from '@eggjs/tegg-lifecycle'; -import { EggPrototype } from '@eggjs/tegg-metadata'; +import type { + EggRuntimeContext, + EggObject, + EggObjectName, + EggPrototype, +} from '@eggjs/tegg-types'; import { EggObjectFactory } from './EggObjectFactory'; const OBJ = Symbol('EggObjectFactoryObject#obj'); @@ -15,7 +17,7 @@ const OBJ = Symbol('EggObjectFactoryObject#obj'); export class EggObjectFactoryObject implements EggObject { readonly proto: EggObjectFactoryPrototype; readonly name: EggObjectName; - readonly ctx?: EggContext; + readonly ctx?: EggRuntimeContext; readonly id: string; private [OBJ]: EggObjectFactory; diff --git a/core/dynamic-inject-runtime/src/EggObjectFactoryPrototype.ts b/core/dynamic-inject-runtime/src/EggObjectFactoryPrototype.ts index 8bf4efbc..d80ccee4 100644 --- a/core/dynamic-inject-runtime/src/EggObjectFactoryPrototype.ts +++ b/core/dynamic-inject-runtime/src/EggObjectFactoryPrototype.ts @@ -1,20 +1,26 @@ +import { EggPrototypeCreatorFactory } from '@eggjs/tegg-metadata'; import { + MetadataUtil, + QualifierUtil, +} from '@eggjs/core-decorator'; +import { NameUtil } from '@eggjs/tegg-common-util'; +import { IdenticalUtil } from '@eggjs/tegg-lifecycle'; +import type { + AccessLevel, + EggObjectFactory, EggPrototype, - EggPrototypeCreatorFactory, + EggProtoImplClass, + EggPrototypeInfo, EggPrototypeLifecycleContext, - InjectObjectProto, LoadUnit, -} from '@eggjs/tegg-metadata'; -import { - AccessLevel, EggProtoImplClass, EggPrototypeInfo, EggPrototypeName, + EggPrototypeName, + InjectObjectProto, + LoadUnit, MetaDataKey, - MetadataUtil, ObjectInitTypeLike, QualifierInfo, - QualifierUtil, QualifierValue, -} from '@eggjs/core-decorator'; -import { NameUtil } from '@eggjs/tegg-common-util'; -import { Id, IdenticalUtil } from '@eggjs/tegg-lifecycle'; -import { EggObjectFactory } from '@eggjs/tegg-dynamic-inject'; + QualifierValue, + Id, +} from '@eggjs/tegg-types'; export const EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE = 'EGG_OBJECT_FACTORY_PROTOTYPE'; diff --git a/core/dynamic-inject/index.ts b/core/dynamic-inject/index.ts index 074a4ac7..50a9b78e 100644 --- a/core/dynamic-inject/index.ts +++ b/core/dynamic-inject/index.ts @@ -1,4 +1,3 @@ -export * from './src/EggObjectFactory'; +export * from '@eggjs/tegg-types/dynamic-inject'; export * from './src/QualifierImplUtil'; -export * from './src/typing'; export * from './src/QualifierImplDecoratorUtil'; diff --git a/core/dynamic-inject/package.json b/core/dynamic-inject/package.json index 521cc958..d928776f 100644 --- a/core/dynamic-inject/package.json +++ b/core/dynamic-inject/package.json @@ -39,7 +39,8 @@ "access": "public" }, "dependencies": { - "@eggjs/core-decorator": "^3.37.1" + "@eggjs/core-decorator": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1" }, "devDependencies": { "@types/mocha": "^10.0.1", diff --git a/core/dynamic-inject/src/EggObjectFactory.ts b/core/dynamic-inject/src/EggObjectFactory.ts deleted file mode 100644 index db0052b0..00000000 --- a/core/dynamic-inject/src/EggObjectFactory.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { QualifierValue } from '@eggjs/core-decorator'; - -import { EggAbstractClazz } from './typing'; - -export interface EggObjectFactory { - getEggObject(abstractClazz: EggAbstractClazz, qualifierValue: QualifierValue): Promise; - getEggObjects(abstractClazz: EggAbstractClazz): Promise>; -} diff --git a/core/dynamic-inject/src/QualifierImplDecoratorUtil.ts b/core/dynamic-inject/src/QualifierImplDecoratorUtil.ts index 136a2d98..66349cd6 100644 --- a/core/dynamic-inject/src/QualifierImplDecoratorUtil.ts +++ b/core/dynamic-inject/src/QualifierImplDecoratorUtil.ts @@ -1,12 +1,6 @@ -import { EggAbstractClazz } from './typing'; +import type { EggAbstractClazz, EggProtoImplClass, ImplDecorator, ImplTypeEnum, QualifierAttribute } from '@eggjs/tegg-types'; +import { QualifierUtil } from '@eggjs/core-decorator'; import { QualifierImplUtil } from './QualifierImplUtil'; -import { EggProtoImplClass, QualifierAttribute, QualifierUtil, QualifierValue } from '@eggjs/core-decorator'; - -export type ImplTypeEnum = { - [id: string]: QualifierValue; -}; - -export type ImplDecorator = (type: Enum[keyof Enum]) => ((clazz: EggProtoImplClass) => void); export class QualifierImplDecoratorUtil { static generatorDecorator(abstractClazz: EggAbstractClazz, attribute: QualifierAttribute): ImplDecorator { diff --git a/core/dynamic-inject/src/QualifierImplUtil.ts b/core/dynamic-inject/src/QualifierImplUtil.ts index 9d473dc8..d4d666e7 100644 --- a/core/dynamic-inject/src/QualifierImplUtil.ts +++ b/core/dynamic-inject/src/QualifierImplUtil.ts @@ -1,8 +1,6 @@ -import { EggProtoImplClass, MetadataUtil, QualifierValue } from '@eggjs/core-decorator'; - -import { EggAbstractClazz } from './typing'; - -export const QUALIFIER_IMPL_MAP = Symbol.for('EggPrototype#qualifierImplMap'); +import { MetadataUtil } from '@eggjs/core-decorator'; +import { QUALIFIER_IMPL_MAP } from '@eggjs/tegg-types'; +import type { EggAbstractClazz, EggProtoImplClass, QualifierValue } from '@eggjs/tegg-types'; export class QualifierImplUtil { static addQualifierImpl(abstractClazz: EggAbstractClazz, qualifierValue: QualifierValue, implClazz: EggProtoImplClass) { diff --git a/core/dynamic-inject/src/typing.ts b/core/dynamic-inject/src/typing.ts deleted file mode 100644 index ec823e1b..00000000 --- a/core/dynamic-inject/src/typing.ts +++ /dev/null @@ -1 +0,0 @@ -export type EggAbstractClazz = Function & {prototype: T}; diff --git a/core/eventbus-decorator/package.json b/core/eventbus-decorator/package.json index a89714ab..ebe2b5fa 100644 --- a/core/eventbus-decorator/package.json +++ b/core/eventbus-decorator/package.json @@ -36,6 +36,7 @@ "dependencies": { "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "typed-emitter": "^1.3.1" }, "engines": { diff --git a/core/eventbus-decorator/src/EventContext.ts b/core/eventbus-decorator/src/EventContext.ts index 23d0111a..7a7181c6 100644 --- a/core/eventbus-decorator/src/EventContext.ts +++ b/core/eventbus-decorator/src/EventContext.ts @@ -1,11 +1,11 @@ // use @eggjs/tegg as namespace // eslint-disable-next-line import/no-unresolved import type { Events } from '@eggjs/tegg'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; -import assert from 'assert'; +import assert from 'node:assert'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { EventInfoUtil } from './EventInfoUtil'; -export interface IEventContext{ +export interface IEventContext { eventName: keyof Events } diff --git a/core/eventbus-decorator/src/EventInfoUtil.ts b/core/eventbus-decorator/src/EventInfoUtil.ts index f0350572..d5a75ea9 100644 --- a/core/eventbus-decorator/src/EventInfoUtil.ts +++ b/core/eventbus-decorator/src/EventInfoUtil.ts @@ -1,4 +1,5 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; +import { MetadataUtil } from '@eggjs/core-decorator'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { EventName } from './EventBus'; export const EVENT_NAME = Symbol.for('EggPrototype#eventName'); diff --git a/core/eventbus-runtime/package.json b/core/eventbus-runtime/package.json index c3e2ae9f..ef8b8051 100644 --- a/core/eventbus-runtime/package.json +++ b/core/eventbus-runtime/package.json @@ -41,6 +41,7 @@ "@eggjs/eventbus-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", "@eggjs/tegg-runtime": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "await-event": "^2.1.0", "await-first": "^1.0.0" }, diff --git a/core/eventbus-runtime/src/EventContextFactory.ts b/core/eventbus-runtime/src/EventContextFactory.ts index f3f56837..5e4aa5dc 100644 --- a/core/eventbus-runtime/src/EventContextFactory.ts +++ b/core/eventbus-runtime/src/EventContextFactory.ts @@ -1,7 +1,8 @@ -import { AccessLevel, SingletonProto } from '@eggjs/core-decorator'; -import { EggContext } from '@eggjs/tegg-runtime'; +import { SingletonProto } from '@eggjs/core-decorator'; +import { AccessLevel } from '@eggjs/tegg-types'; +import type { EggRuntimeContext } from '@eggjs/tegg-types'; -export type ContextCreator = (parentContext?: EggContext) => EggContext; +export type ContextCreator = (parentContext?: EggRuntimeContext) => EggRuntimeContext; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, @@ -9,7 +10,7 @@ export type ContextCreator = (parentContext?: EggContext) => EggContext; export class EventContextFactory { private creator: ContextCreator; - createContext(parentContext?: EggContext): EggContext { + createContext(parentContext?: EggRuntimeContext): EggRuntimeContext { return this.creator(parentContext); } diff --git a/core/eventbus-runtime/src/EventHandlerFactory.ts b/core/eventbus-runtime/src/EventHandlerFactory.ts index c571eefe..b10dd8de 100644 --- a/core/eventbus-runtime/src/EventHandlerFactory.ts +++ b/core/eventbus-runtime/src/EventHandlerFactory.ts @@ -1,8 +1,9 @@ import { EventHandler, EventName, Events, Arguments, EVENT_CONTEXT_INJECT } from '@eggjs/eventbus-decorator'; import { EggContainerFactory } from '@eggjs/tegg-runtime'; -import { EggPrototype } from '@eggjs/tegg-metadata'; +import { AccessLevel } from '@eggjs/tegg-types'; +import type { EggPrototype } from '@eggjs/tegg-types'; import { MapUtil } from '@eggjs/tegg-common-util'; -import { AccessLevel, SingletonProto } from '@eggjs/core-decorator'; +import { SingletonProto } from '@eggjs/core-decorator'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/core/eventbus-runtime/src/SingletonEventBus.ts b/core/eventbus-runtime/src/SingletonEventBus.ts index 57e0509e..0344c7b2 100644 --- a/core/eventbus-runtime/src/SingletonEventBus.ts +++ b/core/eventbus-runtime/src/SingletonEventBus.ts @@ -1,8 +1,10 @@ -import { AccessLevel, Inject, SingletonProto } from '@eggjs/core-decorator'; +import { Inject, SingletonProto } from '@eggjs/core-decorator'; import { EventBus, Events, EventWaiter, EventName, CORK_ID } from '@eggjs/eventbus-decorator'; import type { Arguments } from '@eggjs/eventbus-decorator'; -import { ContextHandler, EggContext } from '@eggjs/tegg-runtime'; +import { ContextHandler } from '@eggjs/tegg-runtime'; import type { EggLogger } from 'egg'; +import { AccessLevel } from '@eggjs/tegg-types'; +import type { EggRuntimeContext } from '@eggjs/tegg-types'; import { EventContextFactory } from './EventContextFactory'; import { EventHandlerFactory } from './EventHandlerFactory'; import { EventEmitter } from 'events'; @@ -12,7 +14,7 @@ import awaitFirst from 'await-first'; export interface Event { name: EventName; args: Array; - context?: EggContext; + context?: EggRuntimeContext; } export interface CorkEvents { @@ -108,7 +110,7 @@ export class SingletonEventBus implements EventBus, EventWaiter { corkdEvents.events.push(event); } - emitWithContext(parentContext: EggContext, event: E, args: Arguments): boolean { + emitWithContext(parentContext: EggRuntimeContext, event: E, args: Arguments): boolean { const corkId = parentContext.get(CORK_ID); const hasListener = this.eventHandlerFactory.hasListeners(event); if (corkId) { @@ -118,7 +120,7 @@ export class SingletonEventBus implements EventBus, EventWaiter { return this.doEmitWithContext(parentContext, event, args); } - private doEmitWithContext(parentContext: EggContext, event: EventName, args: Array): boolean { + private doEmitWithContext(parentContext: EggRuntimeContext, event: EventName, args: Array): boolean { const hasListener = this.eventHandlerFactory.hasListeners(event); const ctx = this.eventContextFactory.createContext(parentContext); this.doEmit(ctx, event, args); @@ -134,7 +136,7 @@ export class SingletonEventBus implements EventBus, EventWaiter { } } - private async doEmit(ctx: EggContext, event: EventName, args: Array) { + private async doEmit(ctx: EggRuntimeContext, event: EventName, args: Array) { await ContextHandler.run(ctx, async () => { const lifecycle = {}; if (ctx.init) { diff --git a/core/lifecycle/index.ts b/core/lifecycle/index.ts index 5ac490bf..517fb877 100644 --- a/core/lifecycle/index.ts +++ b/core/lifecycle/index.ts @@ -1,5 +1,4 @@ -export * from './src/LifecycleHook'; -export * from './src/EggObjectLifecycle'; +export * from '@eggjs/tegg-types/lifecycle'; export * from './src/LifycycleUtil'; export * from './src/IdenticalObject'; export * from './src/decorator'; diff --git a/core/lifecycle/package.json b/core/lifecycle/package.json index b6e4ce99..be190a04 100644 --- a/core/lifecycle/package.json +++ b/core/lifecycle/package.json @@ -39,7 +39,8 @@ "access": "public" }, "dependencies": { - "@eggjs/core-decorator": "^3.37.1" + "@eggjs/core-decorator": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1" }, "devDependencies": { "@eggjs/tegg-metadata": "^3.37.1", diff --git a/core/lifecycle/src/IdenticalObject.ts b/core/lifecycle/src/IdenticalObject.ts index 35d6d30f..7d4801ea 100644 --- a/core/lifecycle/src/IdenticalObject.ts +++ b/core/lifecycle/src/IdenticalObject.ts @@ -1,8 +1,4 @@ -export type Id = string; - -export class IdenticalObject { - id: Id; -} +import type { Id } from '@eggjs/tegg-types'; export class IdenticalUtil { private static objIndex = 0; diff --git a/core/lifecycle/src/LifycycleUtil.ts b/core/lifecycle/src/LifycycleUtil.ts index 34fdd9e7..ee859a0a 100644 --- a/core/lifecycle/src/LifycycleUtil.ts +++ b/core/lifecycle/src/LifycycleUtil.ts @@ -1,9 +1,12 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; -import type { EggPrototype } from '@eggjs/tegg-metadata'; -import { LifecycleContext, LifecycleHook, LifecycleObject } from './LifecycleHook'; -import { EggObjectLifecycle } from './EggObjectLifecycle'; - -export type LifecycleHookName = keyof EggObjectLifecycle; +import { MetadataUtil } from '@eggjs/core-decorator'; +import type { + EggPrototype, + EggProtoImplClass, + LifecycleContext, + LifecycleHook, + LifecycleHookName, + LifecycleObject, +} from '@eggjs/tegg-types'; export class LifecycleUtil> { diff --git a/core/lifecycle/src/decorator/index.ts b/core/lifecycle/src/decorator/index.ts index 0923c63b..3529287c 100644 --- a/core/lifecycle/src/decorator/index.ts +++ b/core/lifecycle/src/decorator/index.ts @@ -1,5 +1,5 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; -import { LifecycleUtil, LifecycleHookName } from '../LifycycleUtil'; +import type { EggProtoImplClass, LifecycleHookName } from '@eggjs/tegg-types'; +import { LifecycleUtil } from '../LifycycleUtil'; function createLifecycle(hookName: LifecycleHookName) { return () => { diff --git a/core/loader/package.json b/core/loader/package.json index f2851260..9b4ba19a 100644 --- a/core/loader/package.json +++ b/core/loader/package.json @@ -38,6 +38,7 @@ "dependencies": { "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "globby": "^11.1.0", "is-type-of": "^1.2.1" }, diff --git a/core/loader/src/LoaderFactory.ts b/core/loader/src/LoaderFactory.ts index f4e4d3be..48b8fde8 100644 --- a/core/loader/src/LoaderFactory.ts +++ b/core/loader/src/LoaderFactory.ts @@ -1,4 +1,4 @@ -import type { EggLoadUnitTypeLike, Loader } from '@eggjs/tegg-metadata'; +import type { EggLoadUnitTypeLike, Loader } from '@eggjs/tegg-types'; export type LoaderCreator = (unitPath: string) => Loader; diff --git a/core/loader/src/LoaderUtil.ts b/core/loader/src/LoaderUtil.ts index c266f7a4..6f281a45 100644 --- a/core/loader/src/LoaderUtil.ts +++ b/core/loader/src/LoaderUtil.ts @@ -1,4 +1,5 @@ -import { EggProtoImplClass, PrototypeUtil } from '@eggjs/core-decorator'; +import { PrototypeUtil } from '@eggjs/core-decorator'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import BuiltinModule from 'module'; import is from 'is-type-of'; diff --git a/core/loader/src/impl/ModuleLoader.ts b/core/loader/src/impl/ModuleLoader.ts index 219aa1bf..af18b250 100644 --- a/core/loader/src/impl/ModuleLoader.ts +++ b/core/loader/src/impl/ModuleLoader.ts @@ -1,11 +1,8 @@ import globby from 'globby'; -import path from 'path'; - +import path from 'node:path'; import { LoaderUtil } from '../LoaderUtil'; - -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass, Loader } from '@eggjs/tegg-types'; import { LoaderFactory } from '../LoaderFactory'; -import type { Loader } from '@eggjs/tegg-metadata'; export class ModuleLoader implements Loader { private readonly moduleDir: string; diff --git a/core/metadata/index.ts b/core/metadata/index.ts index da61c6b0..90cfafe9 100644 --- a/core/metadata/index.ts +++ b/core/metadata/index.ts @@ -1,10 +1,9 @@ -export * from './src/enum/EggLoadUnitType'; +export * from '@eggjs/tegg-types/metadata'; export * from './src/factory/EggPrototypeFactory'; export * from './src/factory/EggPrototypeCreatorFactory'; export * from './src/factory/LoadUnitFactory'; export * from './src/model/EggPrototype'; export * from './src/model/LoadUnit'; -export * from './src/model/Loader'; export * from './src/errors'; export * from './src/util/ClassUtil'; export * from './src/impl/LoadUnitMultiInstanceProtoHook'; diff --git a/core/metadata/package.json b/core/metadata/package.json index 277be8ab..baf094a7 100644 --- a/core/metadata/package.json +++ b/core/metadata/package.json @@ -38,6 +38,7 @@ "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", "@eggjs/tegg-lifecycle": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "egg-errors": "^2.2.3" }, "devDependencies": { diff --git a/core/metadata/src/enum/EggLoadUnitType.ts b/core/metadata/src/enum/EggLoadUnitType.ts deleted file mode 100644 index c53fcacd..00000000 --- a/core/metadata/src/enum/EggLoadUnitType.ts +++ /dev/null @@ -1,7 +0,0 @@ -export enum EggLoadUnitType { - MODULE = 'MODULE', - PLUGIN = 'PLUGIN', - APP = 'APP', -} - -export type EggLoadUnitTypeLike = EggLoadUnitType | string; diff --git a/core/metadata/src/errors.ts b/core/metadata/src/errors.ts index e7613392..9242bb31 100644 --- a/core/metadata/src/errors.ts +++ b/core/metadata/src/errors.ts @@ -1,11 +1,6 @@ import { FrameworkBaseError } from 'egg-errors'; -import { EggPrototypeName, QualifierInfo } from '@eggjs/core-decorator'; - -export enum ErrorCodes { - EGG_PROTO_NOT_FOUND = 'EGG_PROTO_NOT_FOUND', - MULTI_PROTO_FOUND = 'MULTI_PROTO_FOUND', - INCOMPATIBLE_PROTO_INJECT = 'INCOMPATIBLE_PROTO_INJECT', -} +import { ErrorCodes } from '@eggjs/tegg-types'; +import type { EggPrototypeName, QualifierInfo } from '@eggjs/tegg-types'; export class TeggError extends FrameworkBaseError { get module() { diff --git a/core/metadata/src/factory/EggPrototypeCreatorFactory.ts b/core/metadata/src/factory/EggPrototypeCreatorFactory.ts index add7e751..5ec9f752 100644 --- a/core/metadata/src/factory/EggPrototypeCreatorFactory.ts +++ b/core/metadata/src/factory/EggPrototypeCreatorFactory.ts @@ -1,8 +1,13 @@ -import { EggProtoImplClass, EggPrototypeInfo, PrototypeUtil } from '@eggjs/core-decorator'; -import { LoadUnit } from '../model/LoadUnit'; -import { EggPrototype, EggPrototypeLifecycleContext, EggPrototypeLifecycleUtil } from '../model/EggPrototype'; - -export type EggPrototypeCreator = (ctx: EggPrototypeLifecycleContext) => EggPrototype; +import { PrototypeUtil } from '@eggjs/core-decorator'; +import type { + EggProtoImplClass, + EggPrototypeInfo, + EggPrototypeCreator, + LoadUnit, + EggPrototype, + EggPrototypeLifecycleContext, +} from '@eggjs/tegg-types'; +import { EggPrototypeLifecycleUtil } from '../model/EggPrototype'; export class EggPrototypeCreatorFactory { private static creatorMap = new Map(); diff --git a/core/metadata/src/factory/EggPrototypeFactory.ts b/core/metadata/src/factory/EggPrototypeFactory.ts index 71086e37..18a9c3ab 100644 --- a/core/metadata/src/factory/EggPrototypeFactory.ts +++ b/core/metadata/src/factory/EggPrototypeFactory.ts @@ -1,15 +1,9 @@ -import { - AccessLevel, - EggPrototypeName, - QualifierInfo, -} from '@eggjs/core-decorator'; import { MapUtil } from '@eggjs/tegg-common-util'; -import { EggPrototype } from '../model/EggPrototype'; -import { LoadUnit } from '../model/LoadUnit'; +import { AccessLevel } from '@eggjs/tegg-types'; +import type { EggPrototypeName, EggPrototype, LoadUnit, QualifierInfo } from '@eggjs/tegg-types'; import { FrameworkErrorFormater } from 'egg-errors'; import { EggPrototypeNotFound, MultiPrototypeFound } from '../errors'; - export class EggPrototypeFactory { public static instance = new EggPrototypeFactory(); diff --git a/core/metadata/src/factory/LoadUnitFactory.ts b/core/metadata/src/factory/LoadUnitFactory.ts index 124747e1..4e89c720 100644 --- a/core/metadata/src/factory/LoadUnitFactory.ts +++ b/core/metadata/src/factory/LoadUnitFactory.ts @@ -1,14 +1,13 @@ -import { LoadUnit, LoadUnitLifecycleContext, LoadUnitLifecycleUtil } from '../model/LoadUnit'; -import { EggLoadUnitTypeLike } from '../enum/EggLoadUnitType'; -import { Id } from '@eggjs/tegg-lifecycle'; -import { Loader } from '../model/Loader'; - -export type LoadUnitCreator = (ctx: LoadUnitLifecycleContext) => LoadUnit; - -interface LoadUnitPair { - loadUnit: LoadUnit; - ctx: LoadUnitLifecycleContext; -} +import type { + EggLoadUnitTypeLike, + Id, + LoadUnit, + LoadUnitLifecycleContext, + Loader, + LoadUnitCreator, + LoadUnitPair, +} from '@eggjs/tegg-types'; +import { LoadUnitLifecycleUtil } from '../model/LoadUnit'; export class LoadUnitFactory { private static loadUnitCreatorMap: Map = new Map(); diff --git a/core/metadata/src/impl/EggPrototypeBuilder.ts b/core/metadata/src/impl/EggPrototypeBuilder.ts index d10798bd..222e4705 100644 --- a/core/metadata/src/impl/EggPrototypeBuilder.ts +++ b/core/metadata/src/impl/EggPrototypeBuilder.ts @@ -1,36 +1,28 @@ -import assert from 'assert'; +import assert from 'node:assert'; +import { PrototypeUtil, QualifierUtil } from '@eggjs/core-decorator'; import { + ObjectInitType, + InitTypeQualifierAttribute, + DEFAULT_PROTO_IMPL_TYPE, +} from '@eggjs/tegg-types'; +import type { AccessLevel, EggProtoImplClass, - EggPrototypeName, InitTypeQualifierAttribute, - ObjectInitTypeLike, PrototypeUtil, - QualifierInfo, QualifierUtil, - DEFAULT_PROTO_IMPL_TYPE, ObjectInitType, -} from '@eggjs/core-decorator'; -import { LoadUnit } from '../model/LoadUnit'; -import { EggPrototype, EggPrototypeLifecycleContext, InjectObjectProto } from '../model/EggPrototype'; + EggPrototype, + EggPrototypeLifecycleContext, + EggPrototypeName, + InjectObject, + InjectObjectProto, + LoadUnit, + ObjectInitTypeLike, + QualifierInfo, +} from '@eggjs/tegg-types'; import { EggPrototypeFactory } from '../factory/EggPrototypeFactory'; import { IdenticalUtil } from '@eggjs/tegg-lifecycle'; -import { EggPrototypeImpl } from '../impl/EggPrototypeImpl'; +import { EggPrototypeImpl } from './EggPrototypeImpl'; import { EggPrototypeCreatorFactory } from '../factory/EggPrototypeCreatorFactory'; import { EggPrototypeNotFound, MultiPrototypeFound } from '../errors'; -export interface InjectObject { - /** - * property name obj inject to - */ - refName: PropertyKey; - /** - * obj's name will be injected - */ - objName: PropertyKey; - /** - * obj's initType will be injected - * if null same as current obj - */ - initType?: ObjectInitTypeLike; -} - export class EggPrototypeBuilder { private clazz: EggProtoImplClass; private name: EggPrototypeName; diff --git a/core/metadata/src/impl/EggPrototypeImpl.ts b/core/metadata/src/impl/EggPrototypeImpl.ts index 5548c045..020144f6 100644 --- a/core/metadata/src/impl/EggPrototypeImpl.ts +++ b/core/metadata/src/impl/EggPrototypeImpl.ts @@ -1,13 +1,16 @@ -import { EggPrototype, InjectObjectProto } from '../model/EggPrototype'; -import { +import { MetadataUtil } from '@eggjs/core-decorator'; +import type { AccessLevel, + EggPrototype, EggProtoImplClass, - EggPrototypeName, MetaDataKey, MetadataUtil, + EggPrototypeName, + MetaDataKey, ObjectInitTypeLike, - QualifierInfo, QualifierValue, -} from '@eggjs/core-decorator'; -import { Id } from '@eggjs/tegg-lifecycle'; - + QualifierInfo, + QualifierValue, + Id, + InjectObjectProto, +} from '@eggjs/tegg-types'; export class EggPrototypeImpl implements EggPrototype { private readonly clazz: EggProtoImplClass; diff --git a/core/metadata/src/impl/LoadUnitMultiInstanceProtoHook.ts b/core/metadata/src/impl/LoadUnitMultiInstanceProtoHook.ts index ba3c7a3a..da1783c1 100644 --- a/core/metadata/src/impl/LoadUnitMultiInstanceProtoHook.ts +++ b/core/metadata/src/impl/LoadUnitMultiInstanceProtoHook.ts @@ -1,10 +1,7 @@ -import { LifecycleHook } from '@eggjs/tegg-lifecycle'; -import { EggProtoImplClass, PrototypeUtil } from '@eggjs/core-decorator'; -import { - EggPrototypeCreatorFactory, EggPrototypeFactory, - LoadUnit, - LoadUnitLifecycleContext, -} from '@eggjs/tegg-metadata'; +import { PrototypeUtil } from '@eggjs/core-decorator'; +import type { EggProtoImplClass, LifecycleHook, LoadUnit, LoadUnitLifecycleContext } from '@eggjs/tegg-types'; +import { EggPrototypeCreatorFactory } from '../factory/EggPrototypeCreatorFactory'; +import { EggPrototypeFactory } from '../factory/EggPrototypeFactory'; export class LoadUnitMultiInstanceProtoHook implements LifecycleHook { multiInstanceClazzSet: Set = new Set(); diff --git a/core/metadata/src/impl/ModuleLoadUnit.ts b/core/metadata/src/impl/ModuleLoadUnit.ts index 371522f6..b9816e3d 100644 --- a/core/metadata/src/impl/ModuleLoadUnit.ts +++ b/core/metadata/src/impl/ModuleLoadUnit.ts @@ -1,23 +1,25 @@ -import assert from 'assert'; -import path from 'path'; - -import { Graph, GraphNode, GraphNodeObj, MapUtil } from '@eggjs/tegg-common-util'; +import assert from 'node:assert'; +import path from 'node:path'; import { - EggProtoImplClass, - EggPrototypeName, + EggLoadUnitType, InitTypeQualifierAttribute, LoadUnitNameQualifierAttribute, +} from '@eggjs/tegg-types'; +import type { + EggProtoImplClass, + GraphNodeObj, + EggPrototype, + EggPrototypeName, + Loader, + LoadUnit, + LoadUnitLifecycleContext, ObjectInitTypeLike, - PrototypeUtil, QualifierInfo, - QualifierUtil, -} from '@eggjs/core-decorator'; +} from '@eggjs/tegg-types'; +import { Graph, GraphNode, MapUtil } from '@eggjs/tegg-common-util'; +import { PrototypeUtil, QualifierUtil } from '@eggjs/core-decorator'; import { FrameworkErrorFormater } from 'egg-errors'; import { IdenticalUtil } from '@eggjs/tegg-lifecycle'; -import { LoadUnit, LoadUnitLifecycleContext } from '../model/LoadUnit'; -import { Loader } from '../model/Loader'; -import { EggPrototype } from '../model/EggPrototype'; -import { EggLoadUnitType } from '../enum/EggLoadUnitType'; import { EggPrototypeFactory } from '../factory/EggPrototypeFactory'; import { LoadUnitFactory } from '../factory/LoadUnitFactory'; import { EggPrototypeCreatorFactory } from '../factory/EggPrototypeCreatorFactory'; diff --git a/core/metadata/src/model/AppGraph.ts b/core/metadata/src/model/AppGraph.ts index ad1f5f05..720bde01 100644 --- a/core/metadata/src/model/AppGraph.ts +++ b/core/metadata/src/model/AppGraph.ts @@ -1,17 +1,9 @@ import assert from 'node:assert'; import util from 'node:util'; -import { Graph, GraphNode, GraphNodeObj, ModuleConfigUtil, ModuleReference } from '@eggjs/tegg-common-util'; -import { - AccessLevel, - EggProtoImplClass, - EggPrototypeName, - INIT_TYPE_TRY_ORDER, - InitTypeQualifierAttribute, - LoadUnitNameQualifierAttribute, - PrototypeUtil, - QualifierInfo, - QualifierUtil, -} from '@eggjs/core-decorator'; +import { Graph, GraphNode, ModuleConfigUtil } from '@eggjs/tegg-common-util'; +import { PrototypeUtil, QualifierUtil } from '@eggjs/core-decorator'; +import { AccessLevel, INIT_TYPE_TRY_ORDER, InitTypeQualifierAttribute, LoadUnitNameQualifierAttribute } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, EggPrototypeName, GraphNodeObj, ModuleReference, QualifierInfo } from '@eggjs/tegg-types'; export interface InstanceClazzMeta { name: PropertyKey; diff --git a/core/metadata/src/model/EggPrototype.ts b/core/metadata/src/model/EggPrototype.ts index 83a38ec0..b0c6370a 100644 --- a/core/metadata/src/model/EggPrototype.ts +++ b/core/metadata/src/model/EggPrototype.ts @@ -1,75 +1,4 @@ -import { - QualifierInfo, - EggPrototypeName, - AccessLevel, - ObjectInitTypeLike, - MetaDataKey, - EggProtoImplClass, EggPrototypeInfo, QualifierValue, QualifierAttribute, -} from '@eggjs/core-decorator'; -import { LifecycleObject, LifecycleContext, LifecycleUtil } from '@eggjs/tegg-lifecycle'; -import { LoadUnit } from './LoadUnit'; - -export interface InjectObjectProto { - /** - * property name obj inject to - */ - refName: PropertyKey; - /** - * obj's name will be injected - */ - objName: PropertyKey; - /** - * inject qualifiers - */ - qualifiers: QualifierInfo[]; - /** - * inject prototype - */ - proto: EggPrototype; -} - -export type EggPrototypeClass = new (...args: any[]) => EggPrototype; - -export interface EggPrototypeLifecycleContext extends LifecycleContext { - clazz: EggProtoImplClass; - prototypeInfo: EggPrototypeInfo; - loadUnit: LoadUnit; -} - -export interface EggPrototype extends LifecycleObject { - // TODO - // 1. proto name - // 1. default obj name - readonly name: EggPrototypeName; - readonly initType: ObjectInitTypeLike; - readonly accessLevel: AccessLevel; - readonly loadUnitId: string; - readonly injectObjects: InjectObjectProto[]; - readonly className?: string; - - /** - * get metedata for key - * @param {MetaDataKey} metadataKey - */ - getMetaData(metadataKey: MetaDataKey): T | undefined; - - /** - * verify proto is satisfied with qualifier - * - * default qualifier: - * - load unit name - * - init type - * - * @param qualifier - */ - verifyQualifier(qualifier: QualifierInfo): boolean; - verifyQualifiers(qualifiers: QualifierInfo[]): boolean; - getQualifier(attribute: QualifierAttribute): QualifierValue | undefined - - /** - * construct egg object, not trigger lifecycle method/hook - */ - constructEggObject(): object; -} +import { LifecycleUtil } from '@eggjs/tegg-lifecycle'; +import type { EggPrototype, EggPrototypeLifecycleContext } from '@eggjs/tegg-types'; export const EggPrototypeLifecycleUtil = new LifecycleUtil(); diff --git a/core/metadata/src/model/LoadUnit.ts b/core/metadata/src/model/LoadUnit.ts index 0c6e385b..2c2da451 100644 --- a/core/metadata/src/model/LoadUnit.ts +++ b/core/metadata/src/model/LoadUnit.ts @@ -1,25 +1,4 @@ -import { LifecycleContext, LifecycleObject, LifecycleUtil } from '@eggjs/tegg-lifecycle'; -import { EggPrototypeName, QualifierInfo } from '@eggjs/core-decorator'; - -import { EggLoadUnitTypeLike } from '../enum/EggLoadUnitType'; -import { EggPrototype } from './EggPrototype'; -import { Loader } from './Loader'; - -export interface LoadUnitLifecycleContext extends LifecycleContext { - unitPath: string; - loader: Loader; -} - -export interface LoadUnit extends LifecycleObject { - readonly name: string; - readonly unitPath: string; - readonly type: EggLoadUnitTypeLike; - - iterateEggPrototype(): IterableIterator; - registerEggPrototype(proto: EggPrototype): void; - deletePrototype(proto: EggPrototype); - getEggPrototype(name: EggPrototypeName, qualifiers: QualifierInfo[]): EggPrototype[]; - containPrototype(proto: EggPrototype): boolean; -} +import { LifecycleUtil } from '@eggjs/tegg-lifecycle'; +import type { LoadUnit, LoadUnitLifecycleContext } from '@eggjs/tegg-types'; export const LoadUnitLifecycleUtil = new LifecycleUtil(); diff --git a/core/metadata/src/util/ClassUtil.ts b/core/metadata/src/util/ClassUtil.ts index 9fc74f9d..14207dc4 100644 --- a/core/metadata/src/util/ClassUtil.ts +++ b/core/metadata/src/util/ClassUtil.ts @@ -1,4 +1,5 @@ -import { EggProtoImplClass, PrototypeUtil } from '@eggjs/core-decorator'; +import { PrototypeUtil } from '@eggjs/core-decorator'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; export class ClassUtil { static classDescription(clazz: EggProtoImplClass): string { diff --git a/core/orm-decorator/index.ts b/core/orm-decorator/index.ts index 66c0b001..8b7c3e3b 100644 --- a/core/orm-decorator/index.ts +++ b/core/orm-decorator/index.ts @@ -1,3 +1,4 @@ +export * from '@eggjs/tegg-types/orm'; export * from './src/model/ModelMetadata'; export * from './src/model/AttributeMeta'; export * from './src/model/IndexMeta'; @@ -10,4 +11,3 @@ export * from './src/decorator/Attribute'; export * from './src/decorator/DataSource'; export * from './src/util/ModelInfoUtil'; export * from './src/util/ModelMetadataUtil'; - diff --git a/core/orm-decorator/package.json b/core/orm-decorator/package.json index ee0c0b4e..e7db99ec 100644 --- a/core/orm-decorator/package.json +++ b/core/orm-decorator/package.json @@ -39,6 +39,7 @@ "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", "@eggjs/tegg-metadata": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "lodash": "^4.17.21", "pluralize": "^8.0.0" }, diff --git a/core/orm-decorator/src/builder/AttributeMetaBuilder.ts b/core/orm-decorator/src/builder/AttributeMetaBuilder.ts index 03f7fca0..f82eedef 100644 --- a/core/orm-decorator/src/builder/AttributeMetaBuilder.ts +++ b/core/orm-decorator/src/builder/AttributeMetaBuilder.ts @@ -1,6 +1,6 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass, ModelAttributeInfo } from '@eggjs/tegg-types'; import { AttributeMeta } from '../model/AttributeMeta'; -import { ModelAttributeInfo, ModelInfoUtil } from '../util/ModelInfoUtil'; +import { ModelInfoUtil } from '../util/ModelInfoUtil'; import { NameUtil } from '../util/NameUtil'; export class AttributeMetaBuilder { diff --git a/core/orm-decorator/src/builder/IndexMetaBuilder.ts b/core/orm-decorator/src/builder/IndexMetaBuilder.ts index 7264eae5..b95fbaa4 100644 --- a/core/orm-decorator/src/builder/IndexMetaBuilder.ts +++ b/core/orm-decorator/src/builder/IndexMetaBuilder.ts @@ -1,6 +1,6 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass, ModelIndexInfo } from '@eggjs/tegg-types'; import { IndexMeta } from '../model/IndexMeta'; -import { ModelIndexInfo, ModelInfoUtil } from '../util/ModelInfoUtil'; +import { ModelInfoUtil } from '../util/ModelInfoUtil'; import { NameUtil } from '../util/NameUtil'; import { AttributeMeta } from '../model/AttributeMeta'; diff --git a/core/orm-decorator/src/builder/ModelMetaBuilder.ts b/core/orm-decorator/src/builder/ModelMetaBuilder.ts index e008585e..577ddffa 100644 --- a/core/orm-decorator/src/builder/ModelMetaBuilder.ts +++ b/core/orm-decorator/src/builder/ModelMetaBuilder.ts @@ -1,4 +1,4 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { ModelMetadata } from '../model/ModelMetadata'; import { ModelInfoUtil } from '../util/ModelInfoUtil'; import { NameUtil } from '../util/NameUtil'; diff --git a/core/orm-decorator/src/decorator/Attribute.ts b/core/orm-decorator/src/decorator/Attribute.ts index b040fc8e..168fb2a0 100644 --- a/core/orm-decorator/src/decorator/Attribute.ts +++ b/core/orm-decorator/src/decorator/Attribute.ts @@ -1,19 +1,6 @@ -import assert from 'assert'; +import assert from 'node:assert'; +import type { AttributeOptions, EggProtoImplClass } from '@eggjs/tegg-types'; import { ModelInfoUtil } from '../util/ModelInfoUtil'; -import { EggProtoImplClass } from '@eggjs/core-decorator'; - -export interface AttributeOptions { - // field name, default is property name - name?: string; - // allow null, default is true - allowNull?: boolean; - // auto increment, default is false - autoIncrement?: boolean; - // primary field, default is false - primary?: boolean; - // unique field, default is false - unique?: boolean; -} export function Attribute(dataType: string, options?: AttributeOptions) { return function(target: any, propertyKey: PropertyKey) { diff --git a/core/orm-decorator/src/decorator/DataSource.ts b/core/orm-decorator/src/decorator/DataSource.ts index 6eed1e0b..62d1904e 100644 --- a/core/orm-decorator/src/decorator/DataSource.ts +++ b/core/orm-decorator/src/decorator/DataSource.ts @@ -1,4 +1,4 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { ModelInfoUtil } from '../util/ModelInfoUtil'; export function DataSource(dataSource: string) { diff --git a/core/orm-decorator/src/decorator/Index.ts b/core/orm-decorator/src/decorator/Index.ts index c8fad3ca..dd91a3b6 100644 --- a/core/orm-decorator/src/decorator/Index.ts +++ b/core/orm-decorator/src/decorator/Index.ts @@ -1,12 +1,6 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass, IndexOptions } from '@eggjs/tegg-types'; import { ModelInfoUtil } from '../util/ModelInfoUtil'; -export interface IndexOptions { - unique?: boolean; - primary?: boolean; - name?: string; -} - export function Index(fields: string[], params?: IndexOptions) { return function(clazz: EggProtoImplClass) { ModelInfoUtil.addModelIndex(fields, params, clazz); diff --git a/core/orm-decorator/src/decorator/Model.ts b/core/orm-decorator/src/decorator/Model.ts index a0bfb22a..38781f81 100644 --- a/core/orm-decorator/src/decorator/Model.ts +++ b/core/orm-decorator/src/decorator/Model.ts @@ -1,13 +1,8 @@ -import { AccessLevel, EggProtoImplClass, SingletonProto } from '@eggjs/core-decorator'; +import { SingletonProto } from '@eggjs/core-decorator'; +import { AccessLevel, MODEL_PROTO_IMPL_TYPE } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, ModelParams } from '@eggjs/tegg-types'; import { ModelInfoUtil } from '../util/ModelInfoUtil'; -export interface ModelParams { - tableName?: string; - dataSource?: string; -} - -export const MODEL_PROTO_IMPL_TYPE = 'MODEL_PROTO'; - export function Model(param?: ModelParams) { return function(clazz: EggProtoImplClass) { ModelInfoUtil.setIsModel(true, clazz); diff --git a/core/orm-decorator/src/util/ModelInfoUtil.ts b/core/orm-decorator/src/util/ModelInfoUtil.ts index fee3d8cd..726aa501 100644 --- a/core/orm-decorator/src/util/ModelInfoUtil.ts +++ b/core/orm-decorator/src/util/ModelInfoUtil.ts @@ -1,22 +1,18 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; -import { AttributeOptions } from '../decorator/Attribute'; -import { IndexOptions } from '../decorator/Index'; - -export const IS_MODEL = Symbol.for('EggPrototype#model#isModel'); -export const MODEL_DATA_SOURCE = Symbol.for('EggPrototype#model#dataSource'); -export const MODEL_DATA_TABLE_NAME = Symbol.for('EggPrototype#model#tableName'); -export const MODEL_DATA_INDICES = Symbol.for('EggPrototype#model#indices'); -export const MODEL_DATA_ATTRIBUTES = Symbol.for('EggPrototype#model#attributes'); - -export interface ModelIndexInfo { - fields: string[]; - options?: IndexOptions; -} - -export interface ModelAttributeInfo { - dataType: string; - options?: AttributeOptions; -} +import { MetadataUtil } from '@eggjs/core-decorator'; +import type { + AttributeOptions, + EggProtoImplClass, + IndexOptions, + ModelAttributeInfo, + ModelIndexInfo, +} from '@eggjs/tegg-types'; +import { + IS_MODEL, + MODEL_DATA_ATTRIBUTES, + MODEL_DATA_INDICES, + MODEL_DATA_SOURCE, + MODEL_DATA_TABLE_NAME, +} from '@eggjs/tegg-types'; type ModelAttributeMap = Map; diff --git a/core/orm-decorator/src/util/ModelMetadataUtil.ts b/core/orm-decorator/src/util/ModelMetadataUtil.ts index 4cc4bd63..d3ece26e 100644 --- a/core/orm-decorator/src/util/ModelMetadataUtil.ts +++ b/core/orm-decorator/src/util/ModelMetadataUtil.ts @@ -1,4 +1,5 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; +import { MetadataUtil } from '@eggjs/core-decorator'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { ModelMetadata } from '../model/ModelMetadata'; export const MODEL_METADATA = Symbol.for('EggPrototype#model#metadata'); diff --git a/core/runtime/index.ts b/core/runtime/index.ts index 10aeb3fa..4c941f91 100644 --- a/core/runtime/index.ts +++ b/core/runtime/index.ts @@ -1,4 +1,5 @@ -export * from './src/model/EggContainer'; +export * from '@eggjs/tegg-types/runtime'; +export { EggRuntimeContext as EggContext } from '@eggjs/tegg-types/runtime'; export * from './src/model/EggContext'; export * from './src/model/AbstractEggContext'; export * from './src/model/LoadUnitInstance'; diff --git a/core/runtime/package.json b/core/runtime/package.json index 8b9941e0..9f1981f4 100644 --- a/core/runtime/package.json +++ b/core/runtime/package.json @@ -39,7 +39,8 @@ "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", "@eggjs/tegg-lifecycle": "^3.37.1", - "@eggjs/tegg-metadata": "^3.37.1" + "@eggjs/tegg-metadata": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1" }, "devDependencies": { "@eggjs/tegg-loader": "^3.37.1", diff --git a/core/runtime/src/factory/EggContainerFactory.ts b/core/runtime/src/factory/EggContainerFactory.ts index 86e9e1fc..cab11569 100644 --- a/core/runtime/src/factory/EggContainerFactory.ts +++ b/core/runtime/src/factory/EggContainerFactory.ts @@ -1,20 +1,20 @@ -import { EggPrototype, EggPrototypeFactory } from '@eggjs/tegg-metadata'; -import { EggContainer } from '../model/EggContainer'; -import { LifecycleContext } from '@eggjs/tegg-lifecycle'; -import { +import { EggPrototypeFactory } from '@eggjs/tegg-metadata'; +import type { + ContainerGetMethod, + EggContainer, + EggObject, EggObjectName, - ObjectInitTypeLike, - PrototypeUtil, EggProtoImplClass, + EggPrototype, + LifecycleContext, + ObjectInitTypeLike, QualifierInfo, -} from '@eggjs/core-decorator'; -import { EggObject } from '../model/EggObject'; +} from '@eggjs/tegg-types'; +import { PrototypeUtil } from '@eggjs/core-decorator'; import { ContextHandler } from '../model/ContextHandler'; import { ContextInitiator } from '../impl/ContextInitiator'; import { NameUtil } from '@eggjs/tegg-common-util'; -export type ContainerGetMethod = (proto: EggPrototype) => EggContainer; - export class EggContainerFactory { private static containerGetMethodMap: Map = new Map(); diff --git a/core/runtime/src/factory/EggObjectFactory.ts b/core/runtime/src/factory/EggObjectFactory.ts index 088c83bf..b443894a 100644 --- a/core/runtime/src/factory/EggObjectFactory.ts +++ b/core/runtime/src/factory/EggObjectFactory.ts @@ -1,7 +1,14 @@ -import { EggObject, EggObjectLifeCycleContext, EggObjectLifecycleUtil } from '../model/EggObject'; -import { EggObjectName } from '@eggjs/core-decorator'; -import { EggPrototype, EggPrototypeClass, LoadUnitFactory } from '@eggjs/tegg-metadata'; +import type { + CreateObjectMethod, + EggObject, + EggObjectLifeCycleContext, + EggObjectName, + EggPrototype, + EggPrototypeClass, +} from '@eggjs/tegg-types'; +import { LoadUnitFactory } from '@eggjs/tegg-metadata'; import EggObjectImpl from '../impl/EggObjectImpl'; +import { EggObjectLifecycleUtil } from '../model/EggObject'; import { LoadUnitInstanceFactory } from './LoadUnitInstanceFactory'; interface EggObjectPair { @@ -9,8 +16,6 @@ interface EggObjectPair { ctx: EggObjectLifeCycleContext; } -export type CreateObjectMethod = (name: EggObjectName, proto: EggPrototype, lifecycleContext: EggObjectLifeCycleContext) => Promise; - export class EggObjectFactory { static eggObjectMap: Map = new Map(); static eggObjectCreateMap: Map = new Map(); diff --git a/core/runtime/src/factory/LoadUnitInstanceFactory.ts b/core/runtime/src/factory/LoadUnitInstanceFactory.ts index 42bddebe..221ab6be 100644 --- a/core/runtime/src/factory/LoadUnitInstanceFactory.ts +++ b/core/runtime/src/factory/LoadUnitInstanceFactory.ts @@ -1,12 +1,14 @@ -import { +import { LoadUnitInstanceLifecycleUtil } from '../model/LoadUnitInstance'; +import { ObjectInitType } from '@eggjs/tegg-types'; +import type { + EggLoadUnitTypeLike, + EggPrototype, + LoadUnit, LoadUnitInstance, LoadUnitInstanceLifecycleContext, - LoadUnitInstanceLifecycleUtil, -} from '../model/LoadUnitInstance'; -import { EggLoadUnitTypeLike, EggPrototype, LoadUnit } from '@eggjs/tegg-metadata'; +} from '@eggjs/tegg-types'; import { IdenticalUtil } from '@eggjs/tegg-lifecycle'; import { EggContainerFactory } from './EggContainerFactory'; -import { ObjectInitType } from '@eggjs/core-decorator'; type LoadUnitInstanceCreator = (ctx: LoadUnitInstanceLifecycleContext) => LoadUnitInstance; interface LoadUnitInstancePair { diff --git a/core/runtime/src/impl/ContextInitiator.ts b/core/runtime/src/impl/ContextInitiator.ts index 9f59305a..f6fa1e53 100644 --- a/core/runtime/src/impl/ContextInitiator.ts +++ b/core/runtime/src/impl/ContextInitiator.ts @@ -1,16 +1,15 @@ import { LoadUnitFactory } from '@eggjs/tegg-metadata'; -import { EggContext } from '../model/EggContext'; -import { EggObject } from '../model/EggObject'; +import type { EggRuntimeContext, EggObject } from '@eggjs/tegg-types'; import { ContextObjectGraph } from './ContextObjectGraph'; import { EggContainerFactory } from '../factory/EggContainerFactory'; const CONTEXT_INITIATOR = Symbol('EggContext#ContextInitiator'); export class ContextInitiator { - private readonly eggContext: EggContext; + private readonly eggContext: EggRuntimeContext; private readonly eggObjectInitRecorder: WeakMap; - constructor(eggContext: EggContext) { + constructor(eggContext: EggRuntimeContext) { this.eggContext = eggContext; this.eggObjectInitRecorder = new WeakMap(); this.eggContext.set(CONTEXT_INITIATOR, this); @@ -32,7 +31,7 @@ export class ContextInitiator { })); } - static createContextInitiator(context: EggContext): ContextInitiator { + static createContextInitiator(context: EggRuntimeContext): ContextInitiator { let initiator = context.get(CONTEXT_INITIATOR); if (!initiator) { initiator = new ContextInitiator(context); diff --git a/core/runtime/src/impl/ContextObjectGraph.ts b/core/runtime/src/impl/ContextObjectGraph.ts index 621c431c..deb21108 100644 --- a/core/runtime/src/impl/ContextObjectGraph.ts +++ b/core/runtime/src/impl/ContextObjectGraph.ts @@ -1,5 +1,5 @@ -import { EggPrototype, InjectObjectProto } from '@eggjs/tegg-metadata'; -import { ObjectInitType } from '@eggjs/core-decorator'; +import { ObjectInitType } from '@eggjs/tegg-types'; +import type { EggPrototype, InjectObjectProto } from '@eggjs/tegg-types'; class InjectProtoHolder { private idSet: Set = new Set(); diff --git a/core/runtime/src/impl/EggAlwaysNewObjectContainer.ts b/core/runtime/src/impl/EggAlwaysNewObjectContainer.ts index ccd7fd8d..f612016e 100644 --- a/core/runtime/src/impl/EggAlwaysNewObjectContainer.ts +++ b/core/runtime/src/impl/EggAlwaysNewObjectContainer.ts @@ -1,8 +1,5 @@ -import { EggContainer } from '../model/EggContainer'; -import { Id, LifecycleContext } from '@eggjs/tegg-lifecycle'; -import { EggPrototype } from '@eggjs/tegg-metadata'; -import { EggObjectName, ObjectInitType } from '@eggjs/core-decorator'; -import { EggObject } from '../model/EggObject'; +import { ObjectInitType } from '@eggjs/tegg-types'; +import type { EggContainer, EggObject, EggObjectName, EggPrototype, Id, LifecycleContext } from '@eggjs/tegg-types'; import { EggObjectFactory } from '../factory/EggObjectFactory'; import { EggContainerFactory } from '../factory/EggContainerFactory'; diff --git a/core/runtime/src/impl/EggObjectImpl.ts b/core/runtime/src/impl/EggObjectImpl.ts index b037f22f..d706ec48 100644 --- a/core/runtime/src/impl/EggObjectImpl.ts +++ b/core/runtime/src/impl/EggObjectImpl.ts @@ -1,7 +1,8 @@ -import { EggObject, EggObjectLifeCycleContext, EggObjectLifecycleUtil, EggObjectStatus } from '../model/EggObject'; -import { EggPrototype, LoadUnitFactory } from '@eggjs/tegg-metadata'; -import { EggObjectName, ObjectInitType } from '@eggjs/core-decorator'; -import { IdenticalUtil, EggObjectLifecycle } from '@eggjs/tegg-lifecycle'; +import { LoadUnitFactory } from '@eggjs/tegg-metadata'; +import { ObjectInitType, EggObjectStatus } from '@eggjs/tegg-types'; +import type { EggObject, EggObjectName, EggObjectLifecycle, EggObjectLifeCycleContext, EggPrototype } from '@eggjs/tegg-types'; +import { IdenticalUtil } from '@eggjs/tegg-lifecycle'; +import { EggObjectLifecycleUtil } from '../model/EggObject'; import { EggContainerFactory } from '../factory/EggContainerFactory'; import { EggObjectUtil } from './EggObjectUtil'; import { ContextHandler } from '../model/ContextHandler'; diff --git a/core/runtime/src/impl/EggObjectUtil.ts b/core/runtime/src/impl/EggObjectUtil.ts index 7fe87297..b9261d32 100644 --- a/core/runtime/src/impl/EggObjectUtil.ts +++ b/core/runtime/src/impl/EggObjectUtil.ts @@ -1,6 +1,5 @@ -import { EggObject } from '../model/EggObject'; +import type { EggObject, EggPrototype } from '@eggjs/tegg-types'; import { EggContainerFactory } from '../factory/EggContainerFactory'; -import { EggPrototype } from '@eggjs/tegg-metadata'; export class EggObjectUtil { static eggObjectGetProperty(eggObject: EggObject): PropertyDescriptor { diff --git a/core/runtime/src/impl/ModuleLoadUnitInstance.ts b/core/runtime/src/impl/ModuleLoadUnitInstance.ts index d8e071a6..1e95733a 100644 --- a/core/runtime/src/impl/ModuleLoadUnitInstance.ts +++ b/core/runtime/src/impl/ModuleLoadUnitInstance.ts @@ -1,15 +1,19 @@ -import { +import { MapUtil } from '@eggjs/tegg-common-util'; +import { IdenticalUtil } from '@eggjs/tegg-lifecycle'; +import { EggLoadUnitType, ObjectInitType } from '@eggjs/tegg-types'; +import type { + EggObject, + EggObjectName, + EggPrototype, + EggPrototypeName, + Id, + LoadUnit, LoadUnitInstance, LoadUnitInstanceLifecycleContext, - LoadUnitInstanceLifecycleUtil, -} from '../model/LoadUnitInstance'; -import { EggLoadUnitType, EggPrototype, LoadUnit } from '@eggjs/tegg-metadata'; -import { EggObjectName, EggPrototypeName, ObjectInitType } from '@eggjs/core-decorator'; -import { EggObject } from '../model/EggObject'; -import { Id, IdenticalUtil } from '@eggjs/tegg-lifecycle'; +} from '@eggjs/tegg-types'; import { EggObjectFactory } from '../factory/EggObjectFactory'; -import { MapUtil } from '@eggjs/tegg-common-util'; import { LoadUnitInstanceFactory } from '../factory/LoadUnitInstanceFactory'; +import { LoadUnitInstanceLifecycleUtil } from '../model/LoadUnitInstance'; export class ModuleLoadUnitInstance implements LoadUnitInstance { readonly loadUnit: LoadUnit; diff --git a/core/runtime/src/model/AbstractEggContext.ts b/core/runtime/src/model/AbstractEggContext.ts index 58c3517d..cb59709f 100644 --- a/core/runtime/src/model/AbstractEggContext.ts +++ b/core/runtime/src/model/AbstractEggContext.ts @@ -1,14 +1,13 @@ -import { EggContext, EggContextLifecycleContext, EggContextLifecycleUtil } from './EggContext'; -import { EggObjectName, EggPrototypeName, ObjectInitType } from '@eggjs/core-decorator'; -import { EggPrototype, TeggError } from '@eggjs/tegg-metadata'; -import { EggObject } from './EggObject'; -import { Id } from '@eggjs/tegg-lifecycle'; +import { ObjectInitType } from '@eggjs/tegg-types'; +import type { EggRuntimeContext, EggContextLifecycleContext, EggObject, EggObjectName, EggPrototype, EggPrototypeName, Id } from '@eggjs/tegg-types'; +import { TeggError } from '@eggjs/tegg-metadata'; +import { EggContextLifecycleUtil } from './EggContext'; import { MapUtil } from '@eggjs/tegg-common-util'; import { EggContainerFactory } from '../factory/EggContainerFactory'; import { EggObjectFactory } from '../factory/EggObjectFactory'; import { ContextHandler } from './ContextHandler'; -export abstract class AbstractEggContext implements EggContext { +export abstract class AbstractEggContext implements EggRuntimeContext { private contextData: Map = new Map(); private protoToCreate: Map = new Map(); private eggObjectMap: Map> = new Map(); diff --git a/core/runtime/src/model/ContextHandler.ts b/core/runtime/src/model/ContextHandler.ts index 9e6cb1c0..4b4ef990 100644 --- a/core/runtime/src/model/ContextHandler.ts +++ b/core/runtime/src/model/ContextHandler.ts @@ -1,18 +1,18 @@ -import assert from 'assert'; -import { EggContext } from './EggContext'; +import assert from 'node:assert'; +import type { EggRuntimeContext } from '@eggjs/tegg-types'; -type runInContextCallback = (context: EggContext, fn: () => Promise) => Promise; +type runInContextCallback = (context: EggRuntimeContext, fn: () => Promise) => Promise; export class ContextHandler { - static getContextCallback: () => EggContext | undefined; + static getContextCallback: () => EggRuntimeContext | undefined; static runInContextCallback: runInContextCallback; - static getContext(): EggContext | undefined { + static getContext(): EggRuntimeContext | undefined { assert(this.getContextCallback, 'getContextCallback not set'); return this.getContextCallback ? this.getContextCallback() : undefined; } - static run(context: EggContext, fn: () => Promise): Promise { + static run(context: EggRuntimeContext, fn: () => Promise): Promise { assert(this.runInContextCallback, 'runInContextCallback not set'); return this.runInContextCallback(context, fn); } diff --git a/core/runtime/src/model/EggContext.ts b/core/runtime/src/model/EggContext.ts index 69a15a3d..8a0f1139 100644 --- a/core/runtime/src/model/EggContext.ts +++ b/core/runtime/src/model/EggContext.ts @@ -1,13 +1,4 @@ -import { EggContainer } from './EggContainer'; +import type { EggRuntimeContext, EggContextLifecycleContext } from '@eggjs/tegg-types'; import { LifecycleUtil } from '@eggjs/tegg-lifecycle'; -export interface EggContextLifecycleContext { -} - -export interface EggContext extends EggContainer { - // ctx get/set method - get(key: string | symbol): any | undefined; - set(key: string | symbol, val: any); -} - -export const EggContextLifecycleUtil = new LifecycleUtil(); +export const EggContextLifecycleUtil = new LifecycleUtil(); diff --git a/core/runtime/src/model/EggObject.ts b/core/runtime/src/model/EggObject.ts index a5a04a76..edc0a322 100644 --- a/core/runtime/src/model/EggObject.ts +++ b/core/runtime/src/model/EggObject.ts @@ -1,30 +1,4 @@ -import { LifecycleContext, LifecycleObject, LifecycleUtil } from '@eggjs/tegg-lifecycle'; -import { EggPrototype, LoadUnit } from '@eggjs/tegg-metadata'; -import { EggPrototypeName } from '@eggjs/core-decorator'; -import { EggContext } from './EggContext'; -import { LoadUnitInstance } from './LoadUnitInstance'; - -export enum EggObjectStatus { - PENDING = 'PENDING', - READY = 'READY', - ERROR = 'ERROR', - DESTROYING = 'DESTROYING', - DESTROYED = 'DESTROYED', -} - -export interface EggObjectLifeCycleContext extends LifecycleContext { - readonly loadUnit: LoadUnit; - readonly loadUnitInstance: LoadUnitInstance; -} - -export interface EggObject extends LifecycleObject { - readonly isReady: boolean; - readonly obj: object; - readonly proto: EggPrototype; - readonly name: EggPrototypeName; - readonly ctx?: EggContext; - - injectProperty(name: string, descriptor: PropertyDescriptor); -} +import { LifecycleUtil } from '@eggjs/tegg-lifecycle'; +import type { EggObject, EggObjectLifeCycleContext } from '@eggjs/tegg-types'; export const EggObjectLifecycleUtil = new LifecycleUtil(); diff --git a/core/runtime/src/model/LoadUnitInstance.ts b/core/runtime/src/model/LoadUnitInstance.ts index 59dd720b..a38b6507 100644 --- a/core/runtime/src/model/LoadUnitInstance.ts +++ b/core/runtime/src/model/LoadUnitInstance.ts @@ -1,14 +1,4 @@ -import { EggContainer } from './EggContainer'; -import { LoadUnit } from '@eggjs/tegg-metadata'; +import type { LoadUnitInstance, LoadUnitInstanceLifecycleContext } from '@eggjs/tegg-types'; import { LifecycleUtil } from '@eggjs/tegg-lifecycle'; -export interface LoadUnitInstanceLifecycleContext { - loadUnit: LoadUnit; -} - -export interface LoadUnitInstance extends EggContainer { - readonly name: string; - readonly loadUnit: LoadUnit; -} - export const LoadUnitInstanceLifecycleUtil = new LifecycleUtil(); diff --git a/core/runtime/test/EggObject.test.ts b/core/runtime/test/EggObject.test.ts index 465e44f3..339af024 100644 --- a/core/runtime/test/EggObject.test.ts +++ b/core/runtime/test/EggObject.test.ts @@ -1,11 +1,11 @@ -import assert from 'assert'; +import assert from 'node:assert'; +import mm from 'mm'; import { EggPrototypeFactory } from '@eggjs/tegg-metadata'; import { EggTestContext } from './fixtures/EggTestContext'; import TestUtil from './util'; import { EggContainerFactory } from '..'; import { Foo, Bar } from './fixtures/modules/lifecycle-hook/object'; import { Bar as ExtendsBar } from './fixtures/modules/extends-module/Base'; -import mm from 'mm'; import { ContextHandler } from '../src/model/ContextHandler'; import { SingletonBar } from './fixtures/modules/inject-context-to-singleton/object'; diff --git a/core/runtime/test/EggObjectUtil.test.ts b/core/runtime/test/EggObjectUtil.test.ts index a51df59e..2729f3a5 100644 --- a/core/runtime/test/EggObjectUtil.test.ts +++ b/core/runtime/test/EggObjectUtil.test.ts @@ -1,10 +1,10 @@ -import TestUtil from './util'; -import assert from 'assert'; +import assert from 'node:assert'; import mm from 'mm'; import { EggPrototypeFactory } from '@eggjs/tegg-metadata'; import { EggObjectUtil } from '../src/impl/EggObjectUtil'; import { ContextHandler } from '../src/model/ContextHandler'; import { EggTestContext } from './fixtures/EggTestContext'; +import TestUtil from './util'; describe('test/EggObjectUtil.test.ts', () => { let ctx: EggTestContext; diff --git a/core/runtime/test/LoadUnitInstance.test.ts b/core/runtime/test/LoadUnitInstance.test.ts index d8bc659d..e71fb7f5 100644 --- a/core/runtime/test/LoadUnitInstance.test.ts +++ b/core/runtime/test/LoadUnitInstance.test.ts @@ -1,12 +1,13 @@ -import assert from 'assert'; +import assert from 'node:assert'; +import mm from 'mm'; import { EggPrototypeFactory } from '@eggjs/tegg-metadata'; +import { LoadUnitInstance } from '@eggjs/tegg-types'; import { EggTestContext } from './fixtures/EggTestContext'; import TestUtil from './util'; -import { EggContainerFactory, LoadUnitInstance } from '..'; +import { EggContainerFactory } from '..'; import CountController from './fixtures/modules/module-for-load-unit-instance/CountController'; import AppService from './fixtures/modules/multi-module/multi-module-service/AppService'; import { Bar, Foo } from './fixtures/modules/extends-module/Base'; -import mm from 'mm'; import { ContextHandler } from '../src/model/ContextHandler'; import { EggContextStorage } from './fixtures/EggContextStorage'; import { FOO_ATTRIBUTE, FooLogger } from './fixtures/modules/multi-instance-module/MultiInstance'; diff --git a/core/runtime/test/QualifierLoadUnitInstance.test.ts b/core/runtime/test/QualifierLoadUnitInstance.test.ts index 0534d890..17aeb94d 100644 --- a/core/runtime/test/QualifierLoadUnitInstance.test.ts +++ b/core/runtime/test/QualifierLoadUnitInstance.test.ts @@ -1,10 +1,10 @@ -import assert from 'assert'; +import assert from 'node:assert'; +import mm from 'mm'; +import { EggPrototypeFactory } from '@eggjs/tegg-metadata'; import TestUtil from './util'; import { EggTestContext } from './fixtures/EggTestContext'; import CacheService from './fixtures/modules/init-type-qualifier-module/CacheService'; -import { EggPrototypeFactory } from '@eggjs/tegg-metadata'; import { EggContainerFactory } from '..'; -import mm from 'mm'; import { ContextHandler } from '../src/model/ContextHandler'; describe('test/LoadUnit/QualifierLoadUnitInstance.test.ts', () => { diff --git a/core/runtime/test/fixtures/EggContextStorage.ts b/core/runtime/test/fixtures/EggContextStorage.ts index 4a6c707e..4050c91c 100644 --- a/core/runtime/test/fixtures/EggContextStorage.ts +++ b/core/runtime/test/fixtures/EggContextStorage.ts @@ -1,15 +1,15 @@ -import { AsyncLocalStorage } from 'async_hooks'; -import { EggContext } from '../../src/model/EggContext'; +import { AsyncLocalStorage } from 'node:async_hooks'; +import { EggRuntimeContext } from '@eggjs/tegg-types'; import { ContextHandler } from '../../src/model/ContextHandler'; export class EggContextStorage { - static storage = new AsyncLocalStorage(); + static storage = new AsyncLocalStorage(); static register() { ContextHandler.getContextCallback = () => { return EggContextStorage.storage.getStore(); }; - ContextHandler.runInContextCallback = (context: EggContext, fn: () => Promise) => { + ContextHandler.runInContextCallback = (context: EggRuntimeContext, fn: () => Promise) => { return EggContextStorage.storage.run(context, fn); }; } diff --git a/core/runtime/test/fixtures/modules/init-type-qualifier-module/CacheService.ts b/core/runtime/test/fixtures/modules/init-type-qualifier-module/CacheService.ts index 1a92690a..d3ec4d19 100644 --- a/core/runtime/test/fixtures/modules/init-type-qualifier-module/CacheService.ts +++ b/core/runtime/test/fixtures/modules/init-type-qualifier-module/CacheService.ts @@ -1,5 +1,6 @@ import { ICache, CacheValue } from './Cache'; -import { ObjectInitType, ContextProto, InitTypeQualifier, Inject } from '@eggjs/core-decorator'; +import { ObjectInitType } from '@eggjs/tegg-types'; +import { ContextProto, InitTypeQualifier, Inject } from '@eggjs/core-decorator'; @ContextProto() export default class CacheService { diff --git a/core/runtime/test/fixtures/modules/inject-context-to-singleton/object.ts b/core/runtime/test/fixtures/modules/inject-context-to-singleton/object.ts index 2b9776b0..8119c594 100644 --- a/core/runtime/test/fixtures/modules/inject-context-to-singleton/object.ts +++ b/core/runtime/test/fixtures/modules/inject-context-to-singleton/object.ts @@ -1,4 +1,5 @@ -import { AccessLevel, ContextProto, Inject, SingletonProto } from '@eggjs/core-decorator'; +import { AccessLevel } from '@eggjs/tegg-types'; +import { ContextProto, Inject, SingletonProto } from '@eggjs/core-decorator'; @ContextProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/core/runtime/test/fixtures/modules/lifecycle-hook/object.ts b/core/runtime/test/fixtures/modules/lifecycle-hook/object.ts index 4dde9f2b..a7cd9d7b 100644 --- a/core/runtime/test/fixtures/modules/lifecycle-hook/object.ts +++ b/core/runtime/test/fixtures/modules/lifecycle-hook/object.ts @@ -1,6 +1,6 @@ -import { AccessLevel, ContextProto, SingletonProto } from '@eggjs/core-decorator'; +import { AccessLevel, EggObjectLifecycle } from '@eggjs/tegg-types'; +import { ContextProto, SingletonProto } from '@eggjs/core-decorator'; import { - EggObjectLifecycle, LifecyclePostConstruct, LifecyclePreInject, LifecyclePostInject, diff --git a/core/runtime/test/fixtures/modules/module-for-load-unit-instance/CountController.ts b/core/runtime/test/fixtures/modules/module-for-load-unit-instance/CountController.ts index 8ae6d92f..9a7187a9 100644 --- a/core/runtime/test/fixtures/modules/module-for-load-unit-instance/CountController.ts +++ b/core/runtime/test/fixtures/modules/module-for-load-unit-instance/CountController.ts @@ -1,4 +1,5 @@ -import { AccessLevel, ContextProto, Inject } from '@eggjs/core-decorator'; +import { AccessLevel } from '@eggjs/tegg-types'; +import { ContextProto, Inject } from '@eggjs/core-decorator'; import CountService from './CountService'; import TempObj from './TempObj'; diff --git a/core/runtime/test/fixtures/modules/module-for-load-unit-instance/TempObj.ts b/core/runtime/test/fixtures/modules/module-for-load-unit-instance/TempObj.ts index 7a05e402..0e2603f2 100644 --- a/core/runtime/test/fixtures/modules/module-for-load-unit-instance/TempObj.ts +++ b/core/runtime/test/fixtures/modules/module-for-load-unit-instance/TempObj.ts @@ -1,4 +1,5 @@ -import { Prototype, ObjectInitType } from '@eggjs/core-decorator'; +import { ObjectInitType } from '@eggjs/tegg-types'; +import { Prototype } from '@eggjs/core-decorator'; @Prototype({ initType: ObjectInitType.ALWAYS_NEW, diff --git a/core/runtime/test/fixtures/modules/multi-instance-module/MultiInstance.ts b/core/runtime/test/fixtures/modules/multi-instance-module/MultiInstance.ts index e579019d..f6c4a507 100644 --- a/core/runtime/test/fixtures/modules/multi-instance-module/MultiInstance.ts +++ b/core/runtime/test/fixtures/modules/multi-instance-module/MultiInstance.ts @@ -1,7 +1,6 @@ -import { AccessLevel, ObjectInitType, MultiInstanceProto, QualifierValue } from '@eggjs/core-decorator'; +import { AccessLevel, ObjectInitType, QualifierValue, EggObject, EggObjectLifeCycleContext } from '@eggjs/tegg-types'; +import { MultiInstanceProto } from '@eggjs/core-decorator'; import { LifecycleInit } from '@eggjs/tegg-lifecycle'; -import { EggObject, EggObjectLifeCycleContext } from '../../../../src/model/EggObject'; - export const FOO_ATTRIBUTE = Symbol.for('FOO_ATTRIBUTE'); diff --git a/core/runtime/test/fixtures/modules/multi-module/multi-module-repo/AppRepo.ts b/core/runtime/test/fixtures/modules/multi-module/multi-module-repo/AppRepo.ts index c163b9a9..67f6284f 100644 --- a/core/runtime/test/fixtures/modules/multi-module/multi-module-repo/AppRepo.ts +++ b/core/runtime/test/fixtures/modules/multi-module/multi-module-repo/AppRepo.ts @@ -1,6 +1,7 @@ +import { AccessLevel } from '@eggjs/tegg-types'; +import { ContextProto, Inject } from '@eggjs/core-decorator'; import App from '../multi-module-common/model/App'; import PersistenceService from './PersistenceService'; -import { AccessLevel, ContextProto, Inject } from '@eggjs/core-decorator'; @ContextProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/core/runtime/test/fixtures/modules/multi-module/multi-module-repo/PersistenceService.ts b/core/runtime/test/fixtures/modules/multi-module/multi-module-repo/PersistenceService.ts index 835fedbb..82cd63e5 100644 --- a/core/runtime/test/fixtures/modules/multi-module/multi-module-repo/PersistenceService.ts +++ b/core/runtime/test/fixtures/modules/multi-module/multi-module-repo/PersistenceService.ts @@ -1,4 +1,5 @@ -import { AccessLevel, ObjectInitType, Prototype } from '@eggjs/core-decorator'; +import { AccessLevel, ObjectInitType } from '@eggjs/tegg-types'; +import { Prototype } from '@eggjs/core-decorator'; @Prototype({ initType: ObjectInitType.SINGLETON, diff --git a/core/runtime/test/util.ts b/core/runtime/test/util.ts index 7322d58c..7f69e993 100644 --- a/core/runtime/test/util.ts +++ b/core/runtime/test/util.ts @@ -1,6 +1,7 @@ -import path from 'path'; -import { EggLoadUnitType, LoadUnitFactory } from '@eggjs/tegg-metadata'; -import { LoadUnitInstance, LoadUnitInstanceFactory } from '..'; +import path from 'node:path'; +import { EggLoadUnitType, LoadUnitInstance } from '@eggjs/tegg-types'; +import { LoadUnitFactory } from '@eggjs/tegg-metadata'; +import { LoadUnitInstanceFactory } from '..'; import { LoaderFactory } from '@eggjs/tegg-loader'; export default class TestUtil { diff --git a/core/schedule-decorator/index.ts b/core/schedule-decorator/index.ts index c840eb77..cbb36624 100644 --- a/core/schedule-decorator/index.ts +++ b/core/schedule-decorator/index.ts @@ -1,3 +1,4 @@ +export * from '@eggjs/tegg-types/schedule'; export * from './src/model/ScheduleMetadata'; export * from './src/util/ScheduleInfoUtil'; export * from './src/util/ScheduleMetadataUtil'; diff --git a/core/schedule-decorator/package.json b/core/schedule-decorator/package.json index 298b07fd..6e3c4e9f 100644 --- a/core/schedule-decorator/package.json +++ b/core/schedule-decorator/package.json @@ -38,6 +38,7 @@ "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", "@eggjs/tegg-metadata": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1", "cron-parser": "^2.18.0" }, "devDependencies": { diff --git a/core/schedule-decorator/src/builder/ScheduleMetaBuilder.ts b/core/schedule-decorator/src/builder/ScheduleMetaBuilder.ts index 996b880d..b0fecbcc 100644 --- a/core/schedule-decorator/src/builder/ScheduleMetaBuilder.ts +++ b/core/schedule-decorator/src/builder/ScheduleMetaBuilder.ts @@ -1,7 +1,6 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import type { EggProtoImplClass, ScheduleOptions } from '@eggjs/tegg-types'; import { ScheduleMetadata } from '../model/ScheduleMetadata'; import { ScheduleInfoUtil } from '../util/ScheduleInfoUtil'; -import { ScheduleOptions } from '../decorator/Schedule'; const DEFAULT_SCHEDULE_OPTIONS: ScheduleOptions = { immediate: false, diff --git a/core/schedule-decorator/src/decorator/Schedule.ts b/core/schedule-decorator/src/decorator/Schedule.ts index 7f32a41c..f700c244 100644 --- a/core/schedule-decorator/src/decorator/Schedule.ts +++ b/core/schedule-decorator/src/decorator/Schedule.ts @@ -1,38 +1,9 @@ -import { ScheduleTypeLike } from '../model/ScheduleMetadata'; -import { AccessLevel, EggProtoImplClass, PrototypeUtil, SingletonProto } from '@eggjs/core-decorator'; +import { PrototypeUtil, SingletonProto } from '@eggjs/core-decorator'; +import { AccessLevel } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, ScheduleOptions, ScheduleParams, ScheduleSubscriber } from '@eggjs/tegg-types'; import { ScheduleInfoUtil } from '../util/ScheduleInfoUtil'; import { StackUtil } from '@eggjs/tegg-common-util'; -export interface ScheduleParams { - type: ScheduleTypeLike; - scheduleData: T; -} - -export interface CronParams { - cron: string; - cronOptions?: any; -} - -export interface IntervalParams { - interval: string | number; -} - -export type CronScheduleParams = ScheduleParams; -export type IntervalScheduleParams = ScheduleParams; - -export interface ScheduleOptions { - // default is false - immediate?: boolean; - // default is false - disable?: boolean; - // if env has value, only run in this envs - env?: Array; -} - -export interface ScheduleSubscriber { - subscribe(data?: any): Promise; -} - export function Schedule(param: ScheduleParams, options?: ScheduleOptions) { return function(clazz: EggProtoImplClass) { ScheduleInfoUtil.setIsSchedule(true, clazz); diff --git a/core/schedule-decorator/src/model/ScheduleMetadata.ts b/core/schedule-decorator/src/model/ScheduleMetadata.ts index e2b68ac8..d5d8a8be 100644 --- a/core/schedule-decorator/src/model/ScheduleMetadata.ts +++ b/core/schedule-decorator/src/model/ScheduleMetadata.ts @@ -1,9 +1,4 @@ -export enum ScheduleType { - WORKER = 'worker', - ALL = 'all', -} - -export type ScheduleTypeLike = ScheduleType | string; +import type { ScheduleTypeLike } from '@eggjs/tegg-types'; export class ScheduleMetadata { type: ScheduleTypeLike; diff --git a/core/schedule-decorator/src/util/ScheduleInfoUtil.ts b/core/schedule-decorator/src/util/ScheduleInfoUtil.ts index 0ff68622..f7af04b9 100644 --- a/core/schedule-decorator/src/util/ScheduleInfoUtil.ts +++ b/core/schedule-decorator/src/util/ScheduleInfoUtil.ts @@ -1,9 +1,6 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; -import { ScheduleOptions, ScheduleParams } from '../decorator/Schedule'; - -export const IS_SCHEDULE = Symbol.for('EggPrototype#isSchedule'); -export const SCHEDULE_PARAMS = Symbol.for('EggPrototype#schedule#params'); -export const SCHEDULE_OPTIONS = Symbol.for('EggPrototype#schedule#options'); +import { MetadataUtil } from '@eggjs/core-decorator'; +import { IS_SCHEDULE, SCHEDULE_PARAMS, SCHEDULE_OPTIONS } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, ScheduleOptions, ScheduleParams } from '@eggjs/tegg-types'; export class ScheduleInfoUtil { static isSchedule(clazz: EggProtoImplClass): boolean { diff --git a/core/schedule-decorator/src/util/ScheduleMetadataUtil.ts b/core/schedule-decorator/src/util/ScheduleMetadataUtil.ts index e3aaee7c..f638a8a1 100644 --- a/core/schedule-decorator/src/util/ScheduleMetadataUtil.ts +++ b/core/schedule-decorator/src/util/ScheduleMetadataUtil.ts @@ -1,8 +1,8 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/core-decorator'; +import { MetadataUtil } from '@eggjs/core-decorator'; +import { SCHEDULE_METADATA } from '@eggjs/tegg-types'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; import { ScheduleMetadata } from '../model/ScheduleMetadata'; -export const SCHEDULE_METADATA = Symbol.for('EggPrototype#schedule#metadata'); - export class ScheduleMetadataUtil { static setScheduleMetadata(clazz: EggProtoImplClass, metaData: ScheduleMetadata) { MetadataUtil.defineMetaData(SCHEDULE_METADATA, metaData, clazz); diff --git a/core/standalone-decorator/src/typing.ts b/core/standalone-decorator/src/typing.ts index a8393f0e..bf8d5b58 100644 --- a/core/standalone-decorator/src/typing.ts +++ b/core/standalone-decorator/src/typing.ts @@ -2,5 +2,4 @@ export interface MainRunner { main(): Promise; } - export type MainRunnerClass = new() => MainRunner; diff --git a/core/standalone-decorator/src/util/StandaloneUtil.ts b/core/standalone-decorator/src/util/StandaloneUtil.ts index 61789773..e40a9dbe 100644 --- a/core/standalone-decorator/src/util/StandaloneUtil.ts +++ b/core/standalone-decorator/src/util/StandaloneUtil.ts @@ -1,6 +1,5 @@ import { MainRunnerClass } from '../typing'; - export class StandaloneUtil { private static runnerClass: MainRunnerClass | undefined; diff --git a/core/tegg/index.ts b/core/tegg/index.ts index cd21f003..0db9e612 100644 --- a/core/tegg/index.ts +++ b/core/tegg/index.ts @@ -8,11 +8,4 @@ export * as aop from '@eggjs/aop-decorator'; export * as orm from '@eggjs/tegg-orm-decorator'; export * as schedule from '@eggjs/tegg-schedule-decorator'; export { RuntimeConfig, ModuleConfigs, ModuleConfigHolder } from '@eggjs/tegg-common-util'; - -export interface Logger { - debug(message?: any, ...optionalParams: any[]): void; - log(message?: any, ...optionalParams: any[]): void; - info(message?: any, ...optionalParams: any[]): void; - warn(message?: any, ...optionalParams: any[]): void; - error(message?: any, ...optionalParams: any[]): void; -} +export { Logger } from '@eggjs/tegg-types'; diff --git a/core/tegg/package.json b/core/tegg/package.json index ce214c3b..c661fe67 100644 --- a/core/tegg/package.json +++ b/core/tegg/package.json @@ -51,7 +51,8 @@ "@eggjs/tegg-orm-decorator": "^3.37.1", "@eggjs/tegg-runtime": "^3.37.1", "@eggjs/tegg-schedule-decorator": "^3.37.1", - "@eggjs/tegg-transaction-decorator": "^3.37.1" + "@eggjs/tegg-transaction-decorator": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1" }, "publishConfig": { "access": "public" diff --git a/core/transaction-decorator/index.ts b/core/transaction-decorator/index.ts index e9a0e223..b3e32951 100644 --- a/core/transaction-decorator/index.ts +++ b/core/transaction-decorator/index.ts @@ -1,5 +1,4 @@ +export * from '@eggjs/tegg-types/transaction'; export * from './src/decorator/Transactional'; -export * from './src/Common'; -export * from './src/model/TransactionMetadata'; export * from './src/builder/TransactionMetaBuilder'; export * from './src/util/TransactionMetadataUtil'; diff --git a/core/transaction-decorator/package.json b/core/transaction-decorator/package.json index 9a95934a..a887c93c 100644 --- a/core/transaction-decorator/package.json +++ b/core/transaction-decorator/package.json @@ -19,7 +19,8 @@ "dependencies": { "@eggjs/core-decorator": "^3.37.1", "@eggjs/tegg-common-util": "^3.37.1", - "@eggjs/tegg-metadata": "^3.37.1" + "@eggjs/tegg-metadata": "^3.37.1", + "@eggjs/tegg-types": "^3.37.1" }, "scripts": { "test": "cross-env NODE_ENV=test NODE_OPTIONS='--no-deprecation' mocha", diff --git a/core/transaction-decorator/src/builder/TransactionMetaBuilder.ts b/core/transaction-decorator/src/builder/TransactionMetaBuilder.ts index 5cf7965a..ccff3bb3 100644 --- a/core/transaction-decorator/src/builder/TransactionMetaBuilder.ts +++ b/core/transaction-decorator/src/builder/TransactionMetaBuilder.ts @@ -1,5 +1,4 @@ -import { EggProtoImplClass } from '@eggjs/tegg'; -import { TransactionMetadata } from '../model/TransactionMetadata'; +import type { EggProtoImplClass, TransactionMetadata } from '@eggjs/tegg-types'; import { TransactionMetadataUtil } from '../util/TransactionMetadataUtil'; export class TransactionMetaBuilder { diff --git a/core/transaction-decorator/src/decorator/Transactional.ts b/core/transaction-decorator/src/decorator/Transactional.ts index cf87403c..0aee7f9e 100644 --- a/core/transaction-decorator/src/decorator/Transactional.ts +++ b/core/transaction-decorator/src/decorator/Transactional.ts @@ -1,5 +1,5 @@ -import { EggProtoImplClass } from '@eggjs/tegg'; -import { TransactionalParams, PropagationType } from '../Common'; +import { PropagationType } from '@eggjs/tegg-types'; +import type { EggProtoImplClass, TransactionalParams } from '@eggjs/tegg-types'; import { TransactionMetadataUtil } from '../util/TransactionMetadataUtil'; export function Transactional(params?: TransactionalParams) { diff --git a/core/transaction-decorator/src/model/TransactionMetadata.ts b/core/transaction-decorator/src/model/TransactionMetadata.ts deleted file mode 100644 index efb851c9..00000000 --- a/core/transaction-decorator/src/model/TransactionMetadata.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { PropagationType } from '../Common'; - -export interface TransactionMetadata { - propagation: PropagationType; - method: PropertyKey; - datasourceName?: string; -} diff --git a/core/transaction-decorator/src/util/TransactionMetadataUtil.ts b/core/transaction-decorator/src/util/TransactionMetadataUtil.ts index 2c91d164..a6f12975 100644 --- a/core/transaction-decorator/src/util/TransactionMetadataUtil.ts +++ b/core/transaction-decorator/src/util/TransactionMetadataUtil.ts @@ -1,8 +1,6 @@ -import { EggProtoImplClass, MetadataUtil } from '@eggjs/tegg'; -import { TransactionMetadata } from '../model/TransactionMetadata'; - -export const TRANSACTION_META_DATA = Symbol.for('EggPrototype#transaction#metaData'); -export const IS_TRANSACTION_CLAZZ = Symbol.for('EggPrototype#IS_TRANSACTION_CLAZZ'); +import { MetadataUtil } from '@eggjs/tegg'; +import { IS_TRANSACTION_CLAZZ, TRANSACTION_META_DATA, TransactionMetadata } from '@eggjs/tegg-types'; +import type { EggProtoImplClass } from '@eggjs/tegg-types'; export class TransactionMetadataUtil { @@ -22,5 +20,4 @@ export class TransactionMetadataUtil { static getTransactionMetadataList(clazz: EggProtoImplClass): TransactionMetadata[] { return MetadataUtil.getArrayMetaData(TRANSACTION_META_DATA, clazz); } - } diff --git a/core/transaction-decorator/test/builder/TransactionMetaBuilder.test.ts b/core/transaction-decorator/test/builder/TransactionMetaBuilder.test.ts index bfb4e264..b9e73892 100644 --- a/core/transaction-decorator/test/builder/TransactionMetaBuilder.test.ts +++ b/core/transaction-decorator/test/builder/TransactionMetaBuilder.test.ts @@ -1,7 +1,7 @@ -import assert from 'assert'; +import assert from 'node:assert'; +import { PropagationType } from '@eggjs/tegg-types'; import { TransactionMetadataUtil } from '../../src/util/TransactionMetadataUtil'; import { TransactionMetaBuilder } from '../../src/builder/TransactionMetaBuilder'; -import { PropagationType } from '../../src/Common'; import { Foo, Bar, FooBar, BarFoo } from '../fixtures/transaction'; import { Transactional } from '../../src/decorator/Transactional'; diff --git a/core/transaction-decorator/test/fixtures/transaction.ts b/core/transaction-decorator/test/fixtures/transaction.ts index b07aa2fa..6471c168 100644 --- a/core/transaction-decorator/test/fixtures/transaction.ts +++ b/core/transaction-decorator/test/fixtures/transaction.ts @@ -1,5 +1,5 @@ +import { PropagationType } from '@eggjs/tegg-types'; import { Transactional } from '../../src/decorator/Transactional'; -import { PropagationType } from '../../src/Common'; export class Foo { diff --git a/core/types/README.md b/core/types/README.md new file mode 100644 index 00000000..2e666917 --- /dev/null +++ b/core/types/README.md @@ -0,0 +1,15 @@ +# `@eggjs/tegg-types` + +## why + +Not all types and enums are suitable to be exported by tegg, but some types and enums are useful for tegg plugin and application development. + +So we need this package to provide shared types and enums for tegg. + +## content + +shared types (type and interface) and enums for tegg, including: + +- shared types and enums among multiple tegg core packages + +- shared types and enums provided for tegg plugin and application development diff --git a/core/types/aop/Advice.ts b/core/types/aop/Advice.ts new file mode 100644 index 00000000..dd7bcf45 --- /dev/null +++ b/core/types/aop/Advice.ts @@ -0,0 +1,42 @@ +export interface AdviceContext { + that: T; + method: PropertyKey; + args: any[]; + adviceParams?: K; +} + +/** + * execute order: + * 1. beforeCall + * 1. around + * 1. afterReturn/afterThrow + * 1. afterFinally + */ +export interface IAdvice { + /** + * call before function + * @param ctx + */ + beforeCall?(ctx: AdviceContext): Promise; + + /** + * call after function succeed + */ + afterReturn?(ctx: AdviceContext, result: any): Promise; + + /** + * call after function throw error + */ + afterThrow?(ctx: AdviceContext, error: Error): Promise; + + /** + * always call after function done + */ + afterFinally?(ctx: AdviceContext): Promise; + + /** + * execute the function + * the only one can modify the function return value + */ + around?(ctx: AdviceContext, next: () => Promise): Promise; +} diff --git a/core/types/aop/Aspect.ts b/core/types/aop/Aspect.ts new file mode 100644 index 00000000..dec7b459 --- /dev/null +++ b/core/types/aop/Aspect.ts @@ -0,0 +1,16 @@ +import type { EggProtoImplClass } from '../core-decorator'; +import type { IAdvice } from './Advice'; + +export interface AdviceInfo { + clazz: EggProtoImplClass; + order: number; + adviceParams: any; +} + +export interface AspectAdvice { + name: string; + clazz: EggProtoImplClass; + adviceParams: any; +} + +export const ASPECT_LIST = Symbol.for('EggPrototype#aspectList'); diff --git a/core/types/aop/Crosscut.ts b/core/types/aop/Crosscut.ts new file mode 100644 index 00000000..e4236db8 --- /dev/null +++ b/core/types/aop/Crosscut.ts @@ -0,0 +1,38 @@ +import type { EggProtoImplClass } from '../core-decorator'; +import type { AdviceInfo } from './Aspect'; +import type { CustomPointcutCallback, PointcutInfo, PointcutType } from './Pointcut'; + +export interface CrosscutOptions { + // 默认值 100 + order?: number; + adviceParams?: any; +} + +// TODO type check for methodName +export interface ClassCrosscutParam { + type: PointcutType.CLASS; + clazz: EggProtoImplClass; + methodName: PropertyKey; +} + +export interface NameCrosscutParam { + type: PointcutType.NAME; + className: RegExp; + methodName: RegExp; +} + + +export interface CustomCrosscutParam { + type: PointcutType.CUSTOM; + callback: CustomPointcutCallback; +} + +export type CrosscutParam = ClassCrosscutParam | NameCrosscutParam | CustomCrosscutParam; + +export const CROSSCUT_INFO_LIST = Symbol.for('EggPrototype#crosscutInfoList'); +export const IS_CROSSCUT_ADVICE = Symbol.for('EggPrototype#isCrosscutAdvice'); + +export interface CrosscutInfo { + pointcutInfo: PointcutInfo; + adviceInfo: AdviceInfo; +} diff --git a/core/types/aop/Pointcut.ts b/core/types/aop/Pointcut.ts new file mode 100644 index 00000000..50d5adae --- /dev/null +++ b/core/types/aop/Pointcut.ts @@ -0,0 +1,32 @@ +import { EggProtoImplClass } from '../core-decorator'; + +export interface PointcutOptions { + // default is 1000 + order?: number; + adviceParams?: K; +} + +export enum PointcutType { + /** + * use class type to match + */ + CLASS = 'CLASS', + /** + * use regexp to match className and methodName + */ + NAME = 'NAME', + /** + * use custom function to match + */ + CUSTOM = 'CUSTOM', +} + +export interface PointcutInfo { + type: PointcutType; + + match(clazz: EggProtoImplClass, method: PropertyKey): boolean; +} + +export type CustomPointcutCallback = (clazz: EggProtoImplClass, method: PropertyKey) => boolean; + +export const POINTCUT_ADVICE_INFO_LIAR = Symbol.for('EggPrototype#pointcutAdviceInfoList'); diff --git a/core/types/aop/index.ts b/core/types/aop/index.ts new file mode 100644 index 00000000..ed3559a3 --- /dev/null +++ b/core/types/aop/index.ts @@ -0,0 +1,4 @@ +export * from './Advice'; +export * from './Aspect'; +export * from './Crosscut'; +export * from './Pointcut'; diff --git a/core/types/common/Graph.ts b/core/types/common/Graph.ts new file mode 100644 index 00000000..705704d4 --- /dev/null +++ b/core/types/common/Graph.ts @@ -0,0 +1,3 @@ +export interface GraphNodeObj { + readonly id: string; +} diff --git a/core/types/common/Logger.ts b/core/types/common/Logger.ts new file mode 100644 index 00000000..0707d7d9 --- /dev/null +++ b/core/types/common/Logger.ts @@ -0,0 +1,7 @@ +export interface Logger { + debug(message?: any, ...optionalParams: any[]): void; + log(message?: any, ...optionalParams: any[]): void; + info(message?: any, ...optionalParams: any[]): void; + warn(message?: any, ...optionalParams: any[]): void; + error(message?: any, ...optionalParams: any[]): void; +} diff --git a/core/types/common/ModuleConfig.ts b/core/types/common/ModuleConfig.ts new file mode 100644 index 00000000..0afff5a1 --- /dev/null +++ b/core/types/common/ModuleConfig.ts @@ -0,0 +1,34 @@ +export interface ModuleReference { + name: string; + path: string; + optional?: boolean; +} + +export interface InlineModuleReferenceConfig { + path: string; + optional?: boolean; +} + +export interface NpmModuleReferenceConfig { + package: string; + optional?: boolean; +} + +export type ModuleReferenceConfig = InlineModuleReferenceConfig | NpmModuleReferenceConfig; + +export interface ModuleConfig { +} + +export interface ReadModuleReferenceOptions { + // module dir deep for globby when use auto scan module + // default is 10 + deep?: number; + cwd?: string; + extraFilePattern?: string[]; +} + +export interface ModuleConfigHolder { + name: string; + config: ModuleConfig; + reference: ModuleReference; +} diff --git a/core/common-util/src/RuntimeConfig.ts b/core/types/common/RuntimeConfig.ts similarity index 100% rename from core/common-util/src/RuntimeConfig.ts rename to core/types/common/RuntimeConfig.ts diff --git a/core/types/common/index.ts b/core/types/common/index.ts new file mode 100644 index 00000000..1d73d595 --- /dev/null +++ b/core/types/common/index.ts @@ -0,0 +1,4 @@ +export * from './Graph'; +export * from './ModuleConfig'; +export * from './RuntimeConfig'; +export * from './Logger'; diff --git a/core/types/controller-decorator/HTTPController.ts b/core/types/controller-decorator/HTTPController.ts new file mode 100644 index 00000000..e331b447 --- /dev/null +++ b/core/types/controller-decorator/HTTPController.ts @@ -0,0 +1,5 @@ +export interface HTTPControllerParams { + protoName?: string; + controllerName?: string; + path?: string; +} diff --git a/core/types/controller-decorator/HTTPMethod.ts b/core/types/controller-decorator/HTTPMethod.ts new file mode 100644 index 00000000..4dbaf129 --- /dev/null +++ b/core/types/controller-decorator/HTTPMethod.ts @@ -0,0 +1,7 @@ +import { HTTPMethodEnum } from './model/types'; + +export interface HTTPMethodParams { + method: HTTPMethodEnum; + path: string; + priority?: number; +} diff --git a/core/types/controller-decorator/HTTPParam.ts b/core/types/controller-decorator/HTTPParam.ts new file mode 100644 index 00000000..853ad548 --- /dev/null +++ b/core/types/controller-decorator/HTTPParam.ts @@ -0,0 +1,11 @@ +export interface HTTPQueryParams { + name?: string; +} + +export interface HTTPQueriesParams { + name?: string; +} + +export interface HTTPParamParams { + name?: string; +} diff --git a/core/types/controller-decorator/MetadataKey.ts b/core/types/controller-decorator/MetadataKey.ts new file mode 100644 index 00000000..f21c69b3 --- /dev/null +++ b/core/types/controller-decorator/MetadataKey.ts @@ -0,0 +1,20 @@ +export const CONTROLLER_TYPE = Symbol.for('EggPrototype#controllerType'); +export const CONTROLLER_NAME = Symbol.for('EggPrototype#controllerName'); +export const CONTROLLER_HOST = Symbol.for('EggPrototype#controllerHost'); +export const CONTROLLER_MIDDLEWARES = Symbol.for('EggPrototype#controller#middlewares'); +export const CONTROLLER_ACL = Symbol.for('EggPrototype#controller#acl'); + +export const CONTROLLER_META_DATA = Symbol.for('EggPrototype#controller#metaData'); + +export const CONTROLLER_HTTP_PATH = Symbol.for('EggPrototype#controller#http#path'); +export const CONTROLLER_METHOD_METHOD_MAP = Symbol.for('EggPrototype#controller#method#http#method'); +export const CONTROLLER_METHOD_PATH_MAP = Symbol.for('EggPrototype#controller#method#http#path'); +export const CONTROLLER_METHOD_PARAM_TYPE_MAP = Symbol.for('EggPrototype#controller#method#http#params#type'); +export const CONTROLLER_METHOD_PARAM_NAME_MAP = Symbol.for('EggPrototype#controller#method#http#params#name'); +export const CONTROLLER_METHOD_PRIORITY = Symbol.for('EggPrototype#controller#method#http#priority'); + +export const METHOD_CONTROLLER_TYPE_MAP = Symbol.for('EggPrototype#controller#mthods'); +export const METHOD_CONTROLLER_HOST = Symbol.for('EggPrototype#controller#mthods#host'); +export const METHOD_CONTEXT_INDEX = Symbol.for('EggPrototype#controller#method#context'); +export const METHOD_MIDDLEWARES = Symbol.for('EggPrototype#method#middlewares'); +export const METHOD_ACL = Symbol.for('EggPrototype#method#acl'); diff --git a/core/types/controller-decorator/builder.ts b/core/types/controller-decorator/builder.ts new file mode 100644 index 00000000..fbe6847c --- /dev/null +++ b/core/types/controller-decorator/builder.ts @@ -0,0 +1,8 @@ +import { EggProtoImplClass } from '../core-decorator'; +import { ControllerMetadata } from './model/ControllerMetadata'; + +export interface ControllerMetaBuilder { + build(): ControllerMetadata | undefined; +} + +export type ControllerMetaBuilderCreator = (clazz: EggProtoImplClass) => ControllerMetaBuilder; diff --git a/core/types/controller-decorator/index.ts b/core/types/controller-decorator/index.ts new file mode 100644 index 00000000..cec782cd --- /dev/null +++ b/core/types/controller-decorator/index.ts @@ -0,0 +1,8 @@ +export * from './model/ControllerMetadata'; +export * from './model/MethodMeta'; +export * from './model/types'; +export * from './builder'; +export * from './HTTPController'; +export * from './HTTPMethod'; +export * from './HTTPParam'; +export * from './MetadataKey'; diff --git a/core/controller-decorator/src/model/ControllerMetadata.ts b/core/types/controller-decorator/model/ControllerMetadata.ts similarity index 86% rename from core/controller-decorator/src/model/ControllerMetadata.ts rename to core/types/controller-decorator/model/ControllerMetadata.ts index 812cde17..dcd21375 100644 --- a/core/controller-decorator/src/model/ControllerMetadata.ts +++ b/core/types/controller-decorator/model/ControllerMetadata.ts @@ -1,6 +1,6 @@ +import type { EggPrototypeName } from '@eggjs/tegg-types'; import { ControllerTypeLike, MiddlewareFunc } from './types'; import { MethodMeta } from './MethodMeta'; -import { EggPrototypeName } from '@eggjs/core-decorator'; export interface ControllerMetadata { readonly protoName: EggPrototypeName; diff --git a/core/controller-decorator/src/model/MethodMeta.ts b/core/types/controller-decorator/model/MethodMeta.ts similarity index 100% rename from core/controller-decorator/src/model/MethodMeta.ts rename to core/types/controller-decorator/model/MethodMeta.ts diff --git a/core/controller-decorator/src/model/types.ts b/core/types/controller-decorator/model/types.ts similarity index 97% rename from core/controller-decorator/src/model/types.ts rename to core/types/controller-decorator/model/types.ts index ae44eb06..3e173649 100644 --- a/core/controller-decorator/src/model/types.ts +++ b/core/types/controller-decorator/model/types.ts @@ -11,6 +11,7 @@ export enum ControllerType { MGW_RPC = 'MGW_RPC', MESSAGE = 'MESSAGE', SCHEDULE = 'SCHEDULE', + HEADERS = 'HEADERS', } export type HostType = string | string []; diff --git a/core/types/core-decorator/ContextProto.ts b/core/types/core-decorator/ContextProto.ts new file mode 100644 index 00000000..20f1aff4 --- /dev/null +++ b/core/types/core-decorator/ContextProto.ts @@ -0,0 +1,7 @@ +import { AccessLevel } from './enum/AccessLevel'; + +export interface ContextProtoParams { + name?: string; + accessLevel?: AccessLevel; + protoImplType?: string; +} diff --git a/core/types/core-decorator/Inject.ts b/core/types/core-decorator/Inject.ts new file mode 100644 index 00000000..85513bb5 --- /dev/null +++ b/core/types/core-decorator/Inject.ts @@ -0,0 +1,4 @@ +export interface InjectParams { + // obj instance name, default is property name + name?: string; +} diff --git a/core/types/core-decorator/Metadata.ts b/core/types/core-decorator/Metadata.ts new file mode 100644 index 00000000..8e895d90 --- /dev/null +++ b/core/types/core-decorator/Metadata.ts @@ -0,0 +1 @@ +export type MetaDataKey = symbol | string; diff --git a/core/types/core-decorator/MultiInstanceProto.ts b/core/types/core-decorator/MultiInstanceProto.ts new file mode 100644 index 00000000..214ee905 --- /dev/null +++ b/core/types/core-decorator/MultiInstanceProto.ts @@ -0,0 +1,31 @@ +import type { AccessLevel } from './enum/AccessLevel'; +import type { ObjectInitTypeLike } from './enum/ObjectInitType'; +import type { MultiInstancePrototypeGetObjectsContext, ObjectInfo } from './model/EggMultiInstancePrototypeInfo'; + +export interface BaseMultiInstancePrototypeCallbackParams { + /** + * obj init type + */ + initType?: ObjectInitTypeLike; + /** + * access level + */ + accessLevel?: AccessLevel; + /** + * EggPrototype implement type + */ + protoImplType?: string; +} + +export interface MultiInstancePrototypeCallbackParams extends BaseMultiInstancePrototypeCallbackParams { + getObjects(ctx: MultiInstancePrototypeGetObjectsContext): ObjectInfo[]; +} + +export interface MultiInstancePrototypeStaticParams extends BaseMultiInstancePrototypeCallbackParams { + /** + * object info list + */ + objects: ObjectInfo[]; +} + +export type MultiInstancePrototypeParams = MultiInstancePrototypeCallbackParams | MultiInstancePrototypeStaticParams; diff --git a/core/types/core-decorator/Prototype.ts b/core/types/core-decorator/Prototype.ts new file mode 100644 index 00000000..1250098b --- /dev/null +++ b/core/types/core-decorator/Prototype.ts @@ -0,0 +1,11 @@ +import { AccessLevel } from './enum/AccessLevel'; +import { ObjectInitTypeLike } from './enum/ObjectInitType'; + +export interface PrototypeParams { + name?: string; + initType?: ObjectInitTypeLike; + accessLevel?: AccessLevel; + protoImplType?: string; +} + +export const DEFAULT_PROTO_IMPL_TYPE = 'DEFAULT'; diff --git a/core/types/core-decorator/SingletonProto.ts b/core/types/core-decorator/SingletonProto.ts new file mode 100644 index 00000000..f8a203e6 --- /dev/null +++ b/core/types/core-decorator/SingletonProto.ts @@ -0,0 +1,7 @@ +import type { AccessLevel } from './enum/AccessLevel'; + +export interface SingletonProtoParams { + name?: string; + accessLevel?: AccessLevel; + protoImplType?: string; +} diff --git a/core/core-decorator/src/enum/AccessLevel.ts b/core/types/core-decorator/enum/AccessLevel.ts similarity index 100% rename from core/core-decorator/src/enum/AccessLevel.ts rename to core/types/core-decorator/enum/AccessLevel.ts diff --git a/core/core-decorator/src/enum/EggType.ts b/core/types/core-decorator/enum/EggType.ts similarity index 100% rename from core/core-decorator/src/enum/EggType.ts rename to core/types/core-decorator/enum/EggType.ts diff --git a/core/core-decorator/src/enum/ObjectInitType.ts b/core/types/core-decorator/enum/ObjectInitType.ts similarity index 100% rename from core/core-decorator/src/enum/ObjectInitType.ts rename to core/types/core-decorator/enum/ObjectInitType.ts diff --git a/core/types/core-decorator/enum/Qualifier.ts b/core/types/core-decorator/enum/Qualifier.ts new file mode 100644 index 00000000..93ae00a4 --- /dev/null +++ b/core/types/core-decorator/enum/Qualifier.ts @@ -0,0 +1,11 @@ +export const ConfigSourceQualifierAttribute = Symbol.for('Qualifier.ConfigSource'); + +export const EggQualifierAttribute = Symbol.for('Qualifier.Egg'); + +export const InitTypeQualifierAttribute = Symbol.for('Qualifier.InitType'); + +export const LoadUnitNameQualifierAttribute = Symbol.for('Qualifier.LoadUnitName'); + +export const QUALIFIER_META_DATA = Symbol.for('EggPrototype#qualifier'); + +export const PROPERTY_QUALIFIER_META_DATA = Symbol.for('EggPrototype#propertyQualifier'); diff --git a/core/types/core-decorator/index.ts b/core/types/core-decorator/index.ts new file mode 100644 index 00000000..9b74827e --- /dev/null +++ b/core/types/core-decorator/index.ts @@ -0,0 +1,16 @@ +export * from './enum/AccessLevel'; +export * from './enum/EggType'; +export * from './enum/ObjectInitType'; +export * from './enum/Qualifier'; + +export * from './model/EggPrototypeInfo'; +export * from './model/InjectObjectInfo'; +export * from './model/QualifierInfo'; +export * from './model/EggMultiInstancePrototypeInfo'; + +export * from './ContextProto'; +export * from './Inject'; +export * from './Metadata'; +export * from './MultiInstanceProto'; +export * from './Prototype'; +export * from './SingletonProto'; diff --git a/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts b/core/types/core-decorator/model/EggMultiInstancePrototypeInfo.ts similarity index 100% rename from core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts rename to core/types/core-decorator/model/EggMultiInstancePrototypeInfo.ts diff --git a/core/core-decorator/src/model/EggPrototypeInfo.ts b/core/types/core-decorator/model/EggPrototypeInfo.ts similarity index 100% rename from core/core-decorator/src/model/EggPrototypeInfo.ts rename to core/types/core-decorator/model/EggPrototypeInfo.ts diff --git a/core/core-decorator/src/model/InjectObjectInfo.ts b/core/types/core-decorator/model/InjectObjectInfo.ts similarity index 100% rename from core/core-decorator/src/model/InjectObjectInfo.ts rename to core/types/core-decorator/model/InjectObjectInfo.ts diff --git a/core/core-decorator/src/model/QualifierInfo.ts b/core/types/core-decorator/model/QualifierInfo.ts similarity index 100% rename from core/core-decorator/src/model/QualifierInfo.ts rename to core/types/core-decorator/model/QualifierInfo.ts diff --git a/core/types/dal/Qualifier.ts b/core/types/dal/Qualifier.ts new file mode 100644 index 00000000..41606d37 --- /dev/null +++ b/core/types/dal/Qualifier.ts @@ -0,0 +1,5 @@ +export const DAL_COLUMN_INFO_MAP = Symbol('EggPrototype#dalColumnInfoMap'); +export const DAL_COLUMN_TYPE_MAP = Symbol('EggPrototype#dalColumnTypeMap'); +export const DAL_INDEX_LIST = Symbol('EggPrototype#dalIndexList'); +export const DAL_IS_TABLE = Symbol('EggPrototype#dalIsTable'); +export const DAL_TABLE_PARAMS = Symbol('EggPrototype#dalTableParams'); diff --git a/core/types/dal/decorator/Column.ts b/core/types/dal/decorator/Column.ts new file mode 100644 index 00000000..e85d7f4e --- /dev/null +++ b/core/types/dal/decorator/Column.ts @@ -0,0 +1,259 @@ +import { ColumnType } from '../enum/ColumnType'; +import { ColumnFormat } from '../enum/ColumnFormat'; + +export interface ColumnParams { + name?: string; + default?: string; + canNull?: boolean; + comment?: string; + visible?: boolean; + autoIncrement?: boolean; + uniqueKey?: boolean; + primaryKey?: boolean; + collate?: string; + columnFormat?: ColumnFormat; + engineAttribute?: string; + secondaryEngineAttribute?: string; +} + +export interface IColumnTypeParams { + type: ColumnType; +} + +export interface BitParams extends IColumnTypeParams { + type: ColumnType.BIT, + length?: number; +} + +export interface BoolParams extends IColumnTypeParams { + type: ColumnType.BOOL, +} + +interface BaseNumericParams extends IColumnTypeParams { + length?: number; + unsigned?: boolean; + zeroFill?: boolean; +} + +interface BaseFloatNumericParams extends IColumnTypeParams { + length?: number; + fractionalLength?: number; + unsigned?: boolean; + zeroFill?: boolean; +} + +export interface TinyIntParams extends BaseNumericParams { + type: ColumnType.TINYINT; +} + +export interface SmallIntParams extends BaseNumericParams { + type: ColumnType.SMALLINT; +} + +export interface MediumIntParams extends BaseNumericParams { + type: ColumnType.MEDIUMINT; +} + +export interface IntParams extends BaseNumericParams { + type: ColumnType.INT; +} + +export interface BigIntParams extends BaseNumericParams { + type: ColumnType.BIGINT; +} + +export interface DecimalParams extends BaseFloatNumericParams { + type: ColumnType.DECIMAL; +} + +export interface FloatParams extends BaseFloatNumericParams { + type: ColumnType.FLOAT; +} + +export interface DoubleParams extends BaseFloatNumericParams { + type: ColumnType.DOUBLE; +} + +export interface DateParams extends IColumnTypeParams { + type: ColumnType.DATE; +} + +export interface DateTimeParams extends IColumnTypeParams { + type: ColumnType.DATETIME; + precision?: number; + autoUpdate?: boolean; +} + +export interface TimestampParams extends IColumnTypeParams { + type: ColumnType.TIMESTAMP; + precision?: number; + autoUpdate?: boolean; +} + +export interface TimeParams extends IColumnTypeParams { + type: ColumnType.TIME; + precision?: number; +} + +export interface YearParams extends IColumnTypeParams { + type: ColumnType.YEAR; +} + +export interface CharParams extends IColumnTypeParams { + type: ColumnType.CHAR; + length?: number; + characterSet?: string; + collate?: string; +} + +export interface VarCharParams extends IColumnTypeParams { + type: ColumnType.VARCHAR; + length: number; + characterSet?: string; + collate?: string; +} + +export interface BinaryParams extends IColumnTypeParams { + type: ColumnType.BINARY; + length?: number; +} + +export interface VarBinaryParams extends IColumnTypeParams { + type: ColumnType.VARBINARY; + length: number; +} + +export interface TinyBlobParams extends IColumnTypeParams { + type: ColumnType.TINYBLOB; +} + +export interface TinyTextParams extends IColumnTypeParams { + type: ColumnType.TINYTEXT; + characterSet?: string; + collate?: string; +} + +export interface BlobParams extends IColumnTypeParams { + type: ColumnType.BLOB; + length?: number; +} + +export interface TextParams extends IColumnTypeParams { + type: ColumnType.TEXT; + length?: number; + characterSet?: string; + collate?: string; +} + +export interface MediumBlobParams extends IColumnTypeParams { + type: ColumnType.MEDIUMBLOB; +} + +export interface LongBlobParams extends IColumnTypeParams { + type: ColumnType.LONGBLOB; +} + +export interface MediumTextParams extends IColumnTypeParams { + type: ColumnType.MEDIUMTEXT; + characterSet?: string; + collate?: string; +} + +export interface LongTextParams extends IColumnTypeParams { + type: ColumnType.LONGTEXT; + characterSet?: string; + collate?: string; +} + +export interface EnumParams extends IColumnTypeParams { + type: ColumnType.ENUM; + enums: string[]; + characterSet?: string; + collate?: string; +} + +export interface SetParams extends IColumnTypeParams { + type: ColumnType.SET; + enums: string[]; + characterSet?: string; + collate?: string; +} + +export interface JsonParams extends IColumnTypeParams { + type: ColumnType.JSON; +} + +export interface BaseSpatialParams extends IColumnTypeParams { + SRID?: number; +} + +export interface GeometryParams extends BaseSpatialParams { + type: ColumnType.GEOMETRY; +} + +export interface PointParams extends BaseSpatialParams { + type: ColumnType.POINT; +} + +export interface LinestringParams extends BaseSpatialParams { + type: ColumnType.LINESTRING; +} + +export interface PolygonParams extends BaseSpatialParams { + type: ColumnType.POLYGON; +} + +export interface MultiPointParams extends BaseSpatialParams { + type: ColumnType.MULTIPOINT; +} + +export interface MultiLinestringParams extends BaseSpatialParams { + type: ColumnType.MULTILINESTRING; +} + +export interface MultiPolygonParams extends BaseSpatialParams { + type: ColumnType.MULTIPOLYGON; +} + +export interface GeometryCollectionParams extends BaseSpatialParams { + type: ColumnType.GEOMETRYCOLLECTION; +} + +export type ColumnTypeParams = BitParams +| BoolParams +| TinyIntParams +| SmallIntParams +| MediumIntParams +| IntParams +| BigIntParams +| DecimalParams +| FloatParams +| DoubleParams +| DateParams +| DateTimeParams +| TimestampParams +| TimeParams +| YearParams +| CharParams +| VarCharParams +| BinaryParams +| VarBinaryParams +| TinyBlobParams +| TinyTextParams +| BlobParams +| TextParams +| MediumBlobParams +| MediumTextParams +| LongBlobParams +| LongTextParams +| EnumParams +| SetParams +| JsonParams +| GeometryParams +| PointParams +| LinestringParams +| PolygonParams +| MultiPointParams +| MultiLinestringParams +| MultiPolygonParams +| GeometryCollectionParams; diff --git a/core/types/dal/decorator/DataSourceQualifier.ts b/core/types/dal/decorator/DataSourceQualifier.ts new file mode 100644 index 00000000..898b0ecb --- /dev/null +++ b/core/types/dal/decorator/DataSourceQualifier.ts @@ -0,0 +1,2 @@ +export const DataSourceQualifierAttribute = Symbol('Qualifier.DataSource'); +export const DataSourceInjectName = 'dataSource'; diff --git a/core/types/dal/decorator/Index.ts b/core/types/dal/decorator/Index.ts new file mode 100644 index 00000000..3b4950a9 --- /dev/null +++ b/core/types/dal/decorator/Index.ts @@ -0,0 +1,13 @@ +import type { IndexStoreType } from '../enum/IndexStoreType'; +import type { IndexType } from '../enum/IndexType'; + +export interface IndexParams { + keys: string[]; + name?: string; + type?: IndexType, + storeType?: IndexStoreType; + comment?: string; + engineAttribute?: string; + secondaryEngineAttribute?: string; + parser?: string; +} diff --git a/core/types/dal/decorator/Table.ts b/core/types/dal/decorator/Table.ts new file mode 100644 index 00000000..89d13430 --- /dev/null +++ b/core/types/dal/decorator/Table.ts @@ -0,0 +1,25 @@ +// Create Table https://dev.mysql.com/doc/refman/8.0/en/create-table.html +import type { InsertMethod } from '../enum/InsertMethod'; +import type { CompressionType } from '../enum/CompressionType'; +import type { RowFormat } from '../enum/RowFormat'; + +export interface TableParams { + name?: string; + dataSourceName?: string; + comment?: string; + autoExtendSize?: number; + autoIncrement?: number; + avgRowLength?: number; + characterSet?: string; + collate?: string; + compression?: CompressionType; + encryption?: boolean; + engine?: string; + engineAttribute?: string; + insertMethod?: InsertMethod; + keyBlockSize?: number; + maxRows?: number; + minRows?: number; + rowFormat?: RowFormat; + secondaryEngineAttribute?: string; +} diff --git a/core/dal-decorator/src/enum/ColumnFormat.ts b/core/types/dal/enum/ColumnFormat.ts similarity index 100% rename from core/dal-decorator/src/enum/ColumnFormat.ts rename to core/types/dal/enum/ColumnFormat.ts diff --git a/core/dal-decorator/src/enum/ColumnType.ts b/core/types/dal/enum/ColumnType.ts similarity index 100% rename from core/dal-decorator/src/enum/ColumnType.ts rename to core/types/dal/enum/ColumnType.ts diff --git a/core/dal-decorator/src/enum/CompressionType.ts b/core/types/dal/enum/CompressionType.ts similarity index 100% rename from core/dal-decorator/src/enum/CompressionType.ts rename to core/types/dal/enum/CompressionType.ts diff --git a/core/dal-decorator/src/enum/IndexStoreType.ts b/core/types/dal/enum/IndexStoreType.ts similarity index 100% rename from core/dal-decorator/src/enum/IndexStoreType.ts rename to core/types/dal/enum/IndexStoreType.ts diff --git a/core/dal-decorator/src/enum/IndexType.ts b/core/types/dal/enum/IndexType.ts similarity index 100% rename from core/dal-decorator/src/enum/IndexType.ts rename to core/types/dal/enum/IndexType.ts diff --git a/core/dal-decorator/src/enum/InsertMethod.ts b/core/types/dal/enum/InsertMethod.ts similarity index 100% rename from core/dal-decorator/src/enum/InsertMethod.ts rename to core/types/dal/enum/InsertMethod.ts diff --git a/core/dal-decorator/src/enum/RowFormat.ts b/core/types/dal/enum/RowFormat.ts similarity index 100% rename from core/dal-decorator/src/enum/RowFormat.ts rename to core/types/dal/enum/RowFormat.ts diff --git a/core/types/dal/enum/SqlType.ts b/core/types/dal/enum/SqlType.ts new file mode 100644 index 00000000..81ead7a4 --- /dev/null +++ b/core/types/dal/enum/SqlType.ts @@ -0,0 +1,7 @@ +export enum SqlType { + BLOCK = 'BLOCK', + INSERT = 'INSERT', + SELECT = 'SELECT', + UPDATE = 'UPDATE', + DELETE = 'DELETE', +} diff --git a/core/types/dal/enum/Templates.ts b/core/types/dal/enum/Templates.ts new file mode 100644 index 00000000..a92dbc9a --- /dev/null +++ b/core/types/dal/enum/Templates.ts @@ -0,0 +1,5 @@ +export enum Templates { + BASE_DAO = 'base_dao', + DAO = 'dao', + EXTENSION = 'extension', +} diff --git a/core/types/dal/index.ts b/core/types/dal/index.ts new file mode 100644 index 00000000..9e72ce50 --- /dev/null +++ b/core/types/dal/index.ts @@ -0,0 +1,21 @@ +export * from './enum/ColumnFormat'; +export * from './enum/ColumnType'; +export * from './enum/CompressionType'; +export * from './enum/IndexStoreType'; +export * from './enum/IndexType'; +export * from './enum/InsertMethod'; +export * from './enum/RowFormat'; +export * from './enum/SqlType'; +export * from './enum/Templates'; + +export * from './type/CodeGenerator'; +export * from './type/ColumnTsType'; +export * from './type/DateSource'; +export * from './type/Spatial'; +export * from './type/SqlMap'; + +export * from './decorator/Column'; +export * from './decorator/DataSourceQualifier'; +export * from './decorator/Index'; +export * from './decorator/Table'; +export * from './Qualifier'; diff --git a/core/types/dal/type/CodeGenerator.ts b/core/types/dal/type/CodeGenerator.ts new file mode 100644 index 00000000..13796e28 --- /dev/null +++ b/core/types/dal/type/CodeGenerator.ts @@ -0,0 +1,6 @@ +export interface CodeGeneratorOptions { + moduleDir: string; + moduleName: string; + teggPkg?: string; + dalPkg?: string; +} diff --git a/core/dal-decorator/src/type/ColumnTsType.ts b/core/types/dal/type/ColumnTsType.ts similarity index 100% rename from core/dal-decorator/src/type/ColumnTsType.ts rename to core/types/dal/type/ColumnTsType.ts diff --git a/core/dal-decorator/src/type/DateSource.ts b/core/types/dal/type/DateSource.ts similarity index 99% rename from core/dal-decorator/src/type/DateSource.ts rename to core/types/dal/type/DateSource.ts index 8a41a60f..5e0aa4c1 100644 --- a/core/dal-decorator/src/type/DateSource.ts +++ b/core/types/dal/type/DateSource.ts @@ -4,7 +4,6 @@ export interface PaginateData { rows: Array; } - export interface DataSource { execute(sqlName: string, data?: any): Promise>; executeScalar(sqlName: string, data?: any): Promise; diff --git a/core/types/dal/type/Spatial.ts b/core/types/dal/type/Spatial.ts new file mode 100644 index 00000000..29a30b8b --- /dev/null +++ b/core/types/dal/type/Spatial.ts @@ -0,0 +1,13 @@ +export interface Point { + x: number; + y: number; +} + +export type Line = Array; +export type Polygon = Array; +export type Geometry = Point | Line | Polygon; + +export type MultiPoint = Array; +export type MultiLine = Array; +export type MultiPolygon = Array; +export type GeometryCollection = Array; diff --git a/core/dal-decorator/src/type/SqlMap.ts b/core/types/dal/type/SqlMap.ts similarity index 64% rename from core/dal-decorator/src/type/SqlMap.ts rename to core/types/dal/type/SqlMap.ts index e9ffd12f..8aebb5e5 100644 --- a/core/dal-decorator/src/type/SqlMap.ts +++ b/core/types/dal/type/SqlMap.ts @@ -1,10 +1,4 @@ -export enum SqlType { - BLOCK = 'BLOCK', - INSERT = 'INSERT', - SELECT = 'SELECT', - UPDATE = 'UPDATE', - DELETE = 'DELETE', -} +import type { SqlType } from '../enum/SqlType'; export interface BaseSqlMap { type?: SqlType; @@ -21,3 +15,9 @@ export interface BlockSqlMap extends BaseSqlMap { } export type SqlMap = FullSqlMap | BlockSqlMap; + +export interface GenerateSqlMap { + name: string; + type: SqlType.DELETE | SqlType.UPDATE | SqlType.INSERT | SqlType.SELECT; + sql: string; +} diff --git a/core/types/dynamic-inject.ts b/core/types/dynamic-inject.ts new file mode 100644 index 00000000..31dda31c --- /dev/null +++ b/core/types/dynamic-inject.ts @@ -0,0 +1,15 @@ +import { EggProtoImplClass, QualifierValue } from './core-decorator'; + +export type EggAbstractClazz = Function & {prototype: T}; +export type ImplTypeEnum = { + [id: string]: QualifierValue; +}; + +export type ImplDecorator = (type: Enum[keyof Enum]) => ((clazz: EggProtoImplClass) => void); + +export interface EggObjectFactory { + getEggObject(abstractClazz: EggAbstractClazz, qualifierValue: QualifierValue): Promise; + getEggObjects(abstractClazz: EggAbstractClazz): Promise>; +} + +export const QUALIFIER_IMPL_MAP = Symbol.for('EggPrototype#qualifierImplMap'); diff --git a/core/types/index.ts b/core/types/index.ts new file mode 100644 index 00000000..bc2a0a73 --- /dev/null +++ b/core/types/index.ts @@ -0,0 +1,12 @@ +export * from './aop'; +export * from './common'; +export * from './controller-decorator'; +export * from './core-decorator'; +export * from './dal'; +export * from './dynamic-inject'; +export * from './lifecycle'; +export * from './metadata'; +export * from './orm'; +export * from './runtime'; +export * from './schedule'; +export * from './transaction'; diff --git a/core/lifecycle/src/EggObjectLifecycle.ts b/core/types/lifecycle/EggObjectLifecycle.ts similarity index 93% rename from core/lifecycle/src/EggObjectLifecycle.ts rename to core/types/lifecycle/EggObjectLifecycle.ts index 42260e9c..7db36e47 100644 --- a/core/lifecycle/src/EggObjectLifecycle.ts +++ b/core/types/lifecycle/EggObjectLifecycle.ts @@ -34,3 +34,5 @@ export interface EggObjectLifecycle { */ destroy?(ctx: EggObjectLifeCycleContext, eggObj: EggObject): Promise; } + +export type LifecycleHookName = keyof EggObjectLifecycle; diff --git a/core/types/lifecycle/IdenticalObject.ts b/core/types/lifecycle/IdenticalObject.ts new file mode 100644 index 00000000..ad5f77e0 --- /dev/null +++ b/core/types/lifecycle/IdenticalObject.ts @@ -0,0 +1,5 @@ +export type Id = string; + +export interface IdenticalObject { + id: Id; +} diff --git a/core/lifecycle/src/LifecycleHook.ts b/core/types/lifecycle/LifecycleHook.ts similarity index 100% rename from core/lifecycle/src/LifecycleHook.ts rename to core/types/lifecycle/LifecycleHook.ts diff --git a/core/types/lifecycle/index.ts b/core/types/lifecycle/index.ts new file mode 100644 index 00000000..305b6ffe --- /dev/null +++ b/core/types/lifecycle/index.ts @@ -0,0 +1,4 @@ +export * from './EggObjectLifecycle'; +export * from './IdenticalObject'; +export * from './LifecycleHook'; + diff --git a/core/types/metadata/errors.ts b/core/types/metadata/errors.ts new file mode 100644 index 00000000..97642a16 --- /dev/null +++ b/core/types/metadata/errors.ts @@ -0,0 +1,5 @@ +export enum ErrorCodes { + EGG_PROTO_NOT_FOUND = 'EGG_PROTO_NOT_FOUND', + MULTI_PROTO_FOUND = 'MULTI_PROTO_FOUND', + INCOMPATIBLE_PROTO_INJECT = 'INCOMPATIBLE_PROTO_INJECT', +} diff --git a/core/types/metadata/index.ts b/core/types/metadata/index.ts new file mode 100644 index 00000000..aaed8ef7 --- /dev/null +++ b/core/types/metadata/index.ts @@ -0,0 +1,4 @@ +export * from './model/EggPrototype'; +export * from './model/Loader'; +export * from './model/LoadUnit'; +export * from './errors'; diff --git a/core/types/metadata/model/EggPrototype.ts b/core/types/metadata/model/EggPrototype.ts new file mode 100644 index 00000000..5074ed5e --- /dev/null +++ b/core/types/metadata/model/EggPrototype.ts @@ -0,0 +1,98 @@ +import { + AccessLevel, + EggProtoImplClass, + EggPrototypeInfo, + EggPrototypeName, + MetaDataKey, + ObjectInitTypeLike, + QualifierAttribute, + QualifierInfo, + QualifierValue, +} from '../../core-decorator'; +import { LifecycleContext, LifecycleObject } from '../../lifecycle'; +import { LoadUnit } from './LoadUnit'; + +export interface InjectObjectProto { + /** + * property name obj inject to + */ + refName: PropertyKey; + /** + * obj's name will be injected + */ + objName: PropertyKey; + /** + * inject qualifiers + */ + qualifiers: QualifierInfo[]; + /** + * inject prototype + */ + proto: EggPrototype; +} + +export interface InjectObject { + /** + * property name obj inject to + */ + refName: PropertyKey; + /** + * obj's name will be injected + */ + objName: PropertyKey; + /** + * obj's initType will be injected + * if null same as current obj + */ + initType?: ObjectInitTypeLike; +} + +export type EggPrototypeClass = new (...args: any[]) => EggPrototype; + +export interface EggPrototypeLifecycleContext extends LifecycleContext { + clazz: EggProtoImplClass; + prototypeInfo: EggPrototypeInfo; + loadUnit: LoadUnit; +} + +export interface EggPrototype extends LifecycleObject { + // TODO + // 1. proto name + // 1. default obj name + readonly name: EggPrototypeName; + readonly initType: ObjectInitTypeLike; + readonly accessLevel: AccessLevel; + readonly loadUnitId: string; + readonly injectObjects: InjectObjectProto[]; + readonly className?: string; + + /** + * get metedata for key + * @param {MetaDataKey} metadataKey + */ + getMetaData(metadataKey: MetaDataKey): T | undefined; + + /** + * verify proto is satisfied with qualifier + * + * default qualifier: + * - load unit name + * - init type + * + * @param qualifier + */ + verifyQualifier(qualifier: QualifierInfo): boolean; + verifyQualifiers(qualifiers: QualifierInfo[]): boolean; + getQualifier(attribute: QualifierAttribute): QualifierValue | undefined + + /** + * construct egg object, not trigger lifecycle method/hook + */ + constructEggObject(): object; +} + +export interface EggPrototypeWithClazz extends EggPrototype { + clazz?: EggProtoImplClass; +} + +export type EggPrototypeCreator = (ctx: EggPrototypeLifecycleContext) => EggPrototype; diff --git a/core/types/metadata/model/LoadUnit.ts b/core/types/metadata/model/LoadUnit.ts new file mode 100644 index 00000000..e1d3a819 --- /dev/null +++ b/core/types/metadata/model/LoadUnit.ts @@ -0,0 +1,36 @@ +import { EggPrototypeName, QualifierInfo } from '../../core-decorator'; +import { LifecycleContext, LifecycleObject } from '../../lifecycle'; +import { EggPrototype } from './EggPrototype'; +import { Loader } from './Loader'; + +export enum EggLoadUnitType { + MODULE = 'MODULE', + PLUGIN = 'PLUGIN', + APP = 'APP', +} + +export type EggLoadUnitTypeLike = EggLoadUnitType | string; + +export interface LoadUnitLifecycleContext extends LifecycleContext { + unitPath: string; + loader: Loader; +} + +export interface LoadUnit extends LifecycleObject { + readonly name: string; + readonly unitPath: string; + readonly type: EggLoadUnitTypeLike; + + iterateEggPrototype(): IterableIterator; + registerEggPrototype(proto: EggPrototype): void; + deletePrototype(proto: EggPrototype); + getEggPrototype(name: EggPrototypeName, qualifiers: QualifierInfo[]): EggPrototype[]; + containPrototype(proto: EggPrototype): boolean; +} + +export interface LoadUnitPair { + loadUnit: LoadUnit; + ctx: LoadUnitLifecycleContext; +} + +export type LoadUnitCreator = (ctx: LoadUnitLifecycleContext) => LoadUnit; diff --git a/core/metadata/src/model/Loader.ts b/core/types/metadata/model/Loader.ts similarity index 64% rename from core/metadata/src/model/Loader.ts rename to core/types/metadata/model/Loader.ts index f1c453ce..7a3b1224 100644 --- a/core/metadata/src/model/Loader.ts +++ b/core/types/metadata/model/Loader.ts @@ -1,4 +1,4 @@ -import { EggProtoImplClass } from '@eggjs/core-decorator'; +import { EggProtoImplClass } from '../../core-decorator'; /** * Loader to load class list in module diff --git a/core/types/orm.ts b/core/types/orm.ts new file mode 100644 index 00000000..d2db4bc8 --- /dev/null +++ b/core/types/orm.ts @@ -0,0 +1,41 @@ +export interface AttributeOptions { + // field name, default is property name + name?: string; + // allow null, default is true + allowNull?: boolean; + // auto increment, default is false + autoIncrement?: boolean; + // primary field, default is false + primary?: boolean; + // unique field, default is false + unique?: boolean; +} + +export interface IndexOptions { + unique?: boolean; + primary?: boolean; + name?: string; +} + +export interface ModelParams { + tableName?: string; + dataSource?: string; +} + +export interface ModelIndexInfo { + fields: string[]; + options?: IndexOptions; +} + +export interface ModelAttributeInfo { + dataType: string; + options?: AttributeOptions; +} + +export const MODEL_PROTO_IMPL_TYPE = 'MODEL_PROTO'; + +export const IS_MODEL = Symbol.for('EggPrototype#model#isModel'); +export const MODEL_DATA_SOURCE = Symbol.for('EggPrototype#model#dataSource'); +export const MODEL_DATA_TABLE_NAME = Symbol.for('EggPrototype#model#tableName'); +export const MODEL_DATA_INDICES = Symbol.for('EggPrototype#model#indices'); +export const MODEL_DATA_ATTRIBUTES = Symbol.for('EggPrototype#model#attributes'); diff --git a/core/types/package.json b/core/types/package.json new file mode 100644 index 00000000..c3adbfa5 --- /dev/null +++ b/core/types/package.json @@ -0,0 +1,48 @@ +{ + "name": "@eggjs/tegg-types", + "version": "3.37.1", + "description": "tegg types", + "keywords": [ + "egg", + "typescript", + "tegg", + "types" + ], + "main": "./index.js", + "files": [ + "*.js", + "*.d.ts" + ], + "typings": "index.d.ts", + "scripts": { + "clean": "tsc -b --clean", + "tsc:pub": "npm run clean && tsc -p ./tsconfig.pub.json", + "prepublishOnly": "npm run tsc:pub" + }, + "author": "gxkl ", + "license": "MIT", + "homepage": "https://github.com/eggjs/tegg", + "bugs": { + "url": "https://github.com/eggjs/tegg/issues" + }, + "repository": { + "type": "git", + "url": "git@github.com:eggjs/tegg.git", + "directory": "core/types" + }, + "engines": { + "node": ">=14.0.0" + }, + "dependencies": {}, + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@types/mocha": "^10.0.1", + "@types/node": "^20.2.4", + "cross-env": "^7.0.3", + "mocha": "^10.2.0", + "ts-node": "^10.9.1", + "typescript": "^5.0.4" + } +} diff --git a/core/types/runtime/Factory.ts b/core/types/runtime/Factory.ts new file mode 100644 index 00000000..c33c8dbd --- /dev/null +++ b/core/types/runtime/Factory.ts @@ -0,0 +1,9 @@ +import type { EggObjectName } from '../core-decorator'; +import type { LifecycleContext } from '../lifecycle'; +import type { EggPrototype } from '../metadata'; +import type { EggContainer } from './model/EggContainer'; +import type { EggObject, EggObjectLifeCycleContext } from './model/EggObject'; + +export type ContainerGetMethod = (proto: EggPrototype) => EggContainer; + +export type CreateObjectMethod = (name: EggObjectName, proto: EggPrototype, lifecycleContext: EggObjectLifeCycleContext) => Promise; diff --git a/core/types/runtime/index.ts b/core/types/runtime/index.ts new file mode 100644 index 00000000..034c5f5c --- /dev/null +++ b/core/types/runtime/index.ts @@ -0,0 +1,5 @@ +export * from './model/EggContainer'; +export * from './model/EggContext'; +export * from './model/EggObject'; +export * from './model/LoadUnitInstance'; +export * from './Factory'; diff --git a/core/runtime/src/model/EggContainer.ts b/core/types/runtime/model/EggContainer.ts similarity index 78% rename from core/runtime/src/model/EggContainer.ts rename to core/types/runtime/model/EggContainer.ts index e1679510..7658217d 100644 --- a/core/runtime/src/model/EggContainer.ts +++ b/core/types/runtime/model/EggContainer.ts @@ -1,6 +1,6 @@ -import { LifecycleContext, LifecycleObject } from '@eggjs/tegg-lifecycle'; -import { EggObjectName, EggPrototypeName } from '@eggjs/core-decorator'; -import { EggPrototype } from '@eggjs/tegg-metadata'; +import { EggObjectName, EggPrototypeName } from '../../core-decorator'; +import { LifecycleContext, LifecycleObject } from '../../lifecycle'; +import { EggPrototype } from '../../metadata'; import { EggObject } from './EggObject'; export interface EggContainer extends LifecycleObject { diff --git a/core/types/runtime/model/EggContext.ts b/core/types/runtime/model/EggContext.ts new file mode 100644 index 00000000..8500d474 --- /dev/null +++ b/core/types/runtime/model/EggContext.ts @@ -0,0 +1,10 @@ +import { EggContainer } from './EggContainer'; + +export interface EggContextLifecycleContext { +} + +export interface EggRuntimeContext extends EggContainer { + // ctx get/set method + get(key: string | symbol): any | undefined; + set(key: string | symbol, val: any); +} diff --git a/core/types/runtime/model/EggObject.ts b/core/types/runtime/model/EggObject.ts new file mode 100644 index 00000000..73c84496 --- /dev/null +++ b/core/types/runtime/model/EggObject.ts @@ -0,0 +1,28 @@ +import { EggPrototypeName } from '../../core-decorator'; +import { LifecycleContext, LifecycleObject } from '../../lifecycle'; +import { EggPrototype, LoadUnit } from '../../metadata'; +import { EggRuntimeContext } from './EggContext'; +import { LoadUnitInstance } from './LoadUnitInstance'; + +export enum EggObjectStatus { + PENDING = 'PENDING', + READY = 'READY', + ERROR = 'ERROR', + DESTROYING = 'DESTROYING', + DESTROYED = 'DESTROYED', +} + +export interface EggObjectLifeCycleContext extends LifecycleContext { + readonly loadUnit: LoadUnit; + readonly loadUnitInstance: LoadUnitInstance; +} + +export interface EggObject extends LifecycleObject { + readonly isReady: boolean; + readonly obj: object; + readonly proto: EggPrototype; + readonly name: EggPrototypeName; + readonly ctx?: EggRuntimeContext; + + injectProperty(name: string, descriptor: PropertyDescriptor); +} diff --git a/core/types/runtime/model/LoadUnitInstance.ts b/core/types/runtime/model/LoadUnitInstance.ts new file mode 100644 index 00000000..3b5f692e --- /dev/null +++ b/core/types/runtime/model/LoadUnitInstance.ts @@ -0,0 +1,11 @@ +import { LoadUnit } from '../../metadata'; +import { EggContainer } from './EggContainer'; + +export interface LoadUnitInstanceLifecycleContext { + loadUnit: LoadUnit; +} + +export interface LoadUnitInstance extends EggContainer { + readonly name: string; + readonly loadUnit: LoadUnit; +} diff --git a/core/types/schedule.ts b/core/types/schedule.ts new file mode 100644 index 00000000..9fef0ede --- /dev/null +++ b/core/types/schedule.ts @@ -0,0 +1,41 @@ +export enum ScheduleType { + WORKER = 'worker', + ALL = 'all', +} + +export const IS_SCHEDULE = Symbol.for('EggPrototype#isSchedule'); +export const SCHEDULE_PARAMS = Symbol.for('EggPrototype#schedule#params'); +export const SCHEDULE_OPTIONS = Symbol.for('EggPrototype#schedule#options'); +export const SCHEDULE_METADATA = Symbol.for('EggPrototype#schedule#metadata'); + +export type ScheduleTypeLike = ScheduleType | string; + +export interface ScheduleParams { + type: ScheduleTypeLike; + scheduleData: T; +} + +export interface CronParams { + cron: string; + cronOptions?: any; +} + +export interface IntervalParams { + interval: string | number; +} + +export type CronScheduleParams = ScheduleParams; +export type IntervalScheduleParams = ScheduleParams; + +export interface ScheduleOptions { + // default is false + immediate?: boolean; + // default is false + disable?: boolean; + // if env has value, only run in this envs + env?: Array; +} + +export interface ScheduleSubscriber { + subscribe(data?: any): Promise; +} diff --git a/core/transaction-decorator/src/Common.ts b/core/types/transaction.ts similarity index 70% rename from core/transaction-decorator/src/Common.ts rename to core/types/transaction.ts index a8adda3f..418d614c 100644 --- a/core/transaction-decorator/src/Common.ts +++ b/core/types/transaction.ts @@ -15,3 +15,12 @@ export interface TransactionalParams { * */ datasourceName?: string; } + +export interface TransactionMetadata { + propagation: PropagationType; + method: PropertyKey; + datasourceName?: string; +} + +export const TRANSACTION_META_DATA = Symbol.for('EggPrototype#transaction#metaData'); +export const IS_TRANSACTION_CLAZZ = Symbol.for('EggPrototype#IS_TRANSACTION_CLAZZ'); diff --git a/core/types/tsconfig.json b/core/types/tsconfig.json new file mode 100644 index 00000000..cc4f3f73 --- /dev/null +++ b/core/types/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "baseUrl": "./", + "outDir": "lib" + }, + "exclude": [ + "dist", + "node_modules", + "test" + ] +} diff --git a/core/types/tsconfig.pub.json b/core/types/tsconfig.pub.json new file mode 100644 index 00000000..cc4f3f73 --- /dev/null +++ b/core/types/tsconfig.pub.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "baseUrl": "./", + "outDir": "lib" + }, + "exclude": [ + "dist", + "node_modules", + "test" + ] +} diff --git a/plugin/controller/test/fixtures/apps/controller-app/app/controller/AppController.ts b/plugin/controller/test/fixtures/apps/controller-app/app/controller/AppController.ts index bba49b00..e55736d3 100644 --- a/plugin/controller/test/fixtures/apps/controller-app/app/controller/AppController.ts +++ b/plugin/controller/test/fixtures/apps/controller-app/app/controller/AppController.ts @@ -7,7 +7,8 @@ import { HTTPMethodEnum, HTTPParam, HTTPQuery, - HTTPHeaders, IncomingHttpHeaders, + HTTPHeaders, + IncomingHttpHeaders, Middleware, Inject, } from '@eggjs/tegg'; diff --git a/plugin/dal/test/fixtures/apps/dal-app/modules/dal/Foo.ts b/plugin/dal/test/fixtures/apps/dal-app/modules/dal/Foo.ts index 44f02610..0a0d7346 100644 --- a/plugin/dal/test/fixtures/apps/dal-app/modules/dal/Foo.ts +++ b/plugin/dal/test/fixtures/apps/dal-app/modules/dal/Foo.ts @@ -5,10 +5,15 @@ import { GeometryCollection, Index, IndexType, - Line, MultiLine, MultiPoint, MultiPolygon, Point, Polygon, + IndexStoreType, + Line, + MultiLine, + MultiPoint, + MultiPolygon, + Point, + Polygon, Table, } from '@eggjs/dal-decorator'; -import { IndexStoreType } from '@eggjs/dal-decorator/src/enum/IndexStoreType'; @Table({ name: 'egg_foo', diff --git a/standalone/standalone/test/fixtures/dal-module/Foo.ts b/standalone/standalone/test/fixtures/dal-module/Foo.ts index 44f02610..0a0d7346 100644 --- a/standalone/standalone/test/fixtures/dal-module/Foo.ts +++ b/standalone/standalone/test/fixtures/dal-module/Foo.ts @@ -5,10 +5,15 @@ import { GeometryCollection, Index, IndexType, - Line, MultiLine, MultiPoint, MultiPolygon, Point, Polygon, + IndexStoreType, + Line, + MultiLine, + MultiPoint, + MultiPolygon, + Point, + Polygon, Table, } from '@eggjs/dal-decorator'; -import { IndexStoreType } from '@eggjs/dal-decorator/src/enum/IndexStoreType'; @Table({ name: 'egg_foo',