dzkcc-mflow 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/Api.d.ts +19 -6
- package/dist/core/Core.d.ts +21 -5
- package/dist/core/Decorators.d.ts +17 -8
- package/dist/core/Decorators.js +0 -3
- package/dist/mflow-tools.zip +0 -0
- package/package.json +1 -1
package/dist/core/Api.d.ts
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 核心接口 - 管理 Model 和 Manager 的生命周期
|
|
3
|
+
*
|
|
4
|
+
* 注意:返回类型由具体实现类(AbstractCore)决定,
|
|
5
|
+
* 实现类会使用类型推断将 symbol 映射到具体的 Model/Manager 类型
|
|
3
6
|
*/
|
|
4
7
|
export interface ICore {
|
|
5
8
|
/** 注册 Model - 通过 Symbol 自动实例化 */
|
|
6
9
|
regModel(modelSymbol: symbol): void;
|
|
7
10
|
/**
|
|
8
11
|
* 获取 Model(支持类型自动推断)
|
|
9
|
-
* @param modelSymbol Model 的 Symbol
|
|
10
|
-
* @returns Model 实例,类型会根据
|
|
12
|
+
* @param modelSymbol Model 的 Symbol。返回 any,由实现类提供具体类型
|
|
13
|
+
* @returns Model 实例,类型会根据 symbol 自动推断为具体的 Model 类型
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // 自动推断为 UserModel 类型
|
|
17
|
+
* const userModel = core.getModel(ModelNames.User);
|
|
18
|
+
* ```
|
|
11
19
|
*/
|
|
12
|
-
getModel<S extends symbol
|
|
20
|
+
getModel<S extends symbol>(modelSymbol: S): any;
|
|
13
21
|
/** 注册 Manager - 通过 Symbol 自动实例化 */
|
|
14
22
|
regManager(managerSymbol: symbol): void;
|
|
15
23
|
/**
|
|
16
24
|
* 获取 Manager(支持类型自动推断)
|
|
17
|
-
* @param managerSymbol Manager 的 Symbol
|
|
18
|
-
* @returns Manager 实例,类型会根据
|
|
25
|
+
* @param managerSymbol Manager 的 Symbol。返回 any,由实现类提供具体类型
|
|
26
|
+
* @returns Manager 实例,类型会根据 symbol 自动推断为具体的 Manager 类型
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // 自动推断为 GameManager 类型
|
|
30
|
+
* const gameManager = core.getManager(ManagerNames.Game);
|
|
31
|
+
* ```
|
|
19
32
|
*/
|
|
20
|
-
getManager<S extends symbol
|
|
33
|
+
getManager<S extends symbol>(managerSymbol: S): any;
|
|
21
34
|
}
|
|
22
35
|
/**
|
|
23
36
|
* Model 基接口 - 数据模型
|
package/dist/core/Core.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { ICore, IManager, IModel } from "./Api";
|
|
2
|
-
import { ModelTypeMap, ManagerTypeMap } from "./Decorators";
|
|
2
|
+
import { ModelTypeMap, ManagerTypeMap, ModelNames, ManagerNames } from "./Decorators";
|
|
3
|
+
/**
|
|
4
|
+
* 从 symbol 推断对应的字符串 key
|
|
5
|
+
* @example ModelNames.User -> 'User'
|
|
6
|
+
*/
|
|
7
|
+
type GetKeyFromSymbol<S extends symbol, Names extends Record<string, symbol>> = {
|
|
8
|
+
[K in keyof Names]: Names[K] extends S ? K : never;
|
|
9
|
+
}[keyof Names];
|
|
10
|
+
/**
|
|
11
|
+
* 从 Model Symbol 推断类型
|
|
12
|
+
*/
|
|
13
|
+
type InferModelType<S extends symbol> = GetKeyFromSymbol<S, typeof ModelNames> extends keyof ModelTypeMap ? ModelTypeMap[GetKeyFromSymbol<S, typeof ModelNames>] : IModel;
|
|
14
|
+
/**
|
|
15
|
+
* 从 Manager Symbol 推断类型
|
|
16
|
+
*/
|
|
17
|
+
type InferManagerType<S extends symbol> = GetKeyFromSymbol<S, typeof ManagerNames> extends keyof ManagerTypeMap ? ManagerTypeMap[GetKeyFromSymbol<S, typeof ManagerNames>] : IManager;
|
|
3
18
|
export declare abstract class AbstractCore<T extends AbstractCore<T>> implements ICore {
|
|
4
19
|
private readonly container;
|
|
5
20
|
constructor();
|
|
@@ -15,7 +30,7 @@ export declare abstract class AbstractCore<T extends AbstractCore<T>> implements
|
|
|
15
30
|
* const userModel = core.getModel(ModelNames.User);
|
|
16
31
|
* ```
|
|
17
32
|
*/
|
|
18
|
-
getModel<S extends symbol>(modelSymbol: S): S
|
|
33
|
+
getModel<S extends symbol>(modelSymbol: S): InferModelType<S>;
|
|
19
34
|
regManager(managerSymbol: symbol): void;
|
|
20
35
|
/**
|
|
21
36
|
* 获取 Manager 实例(支持类型自动推断)
|
|
@@ -27,7 +42,7 @@ export declare abstract class AbstractCore<T extends AbstractCore<T>> implements
|
|
|
27
42
|
* const gameManager = core.getManager(ManagerNames.Game);
|
|
28
43
|
* ```
|
|
29
44
|
*/
|
|
30
|
-
getManager<S extends symbol>(managerSymbol: S): S
|
|
45
|
+
getManager<S extends symbol>(managerSymbol: S): InferManagerType<S>;
|
|
31
46
|
}
|
|
32
47
|
export declare abstract class AbstractManager implements IManager {
|
|
33
48
|
abstract initialize(): void;
|
|
@@ -37,11 +52,12 @@ export declare abstract class AbstractManager implements IManager {
|
|
|
37
52
|
* @param modelSymbol Model 的 Symbol,使用 ModelNames.XXX
|
|
38
53
|
* @returns Model 实例,类型会根据 symbol 自动推断
|
|
39
54
|
*/
|
|
40
|
-
protected getModel<S extends symbol>(modelSymbol: S): S
|
|
55
|
+
protected getModel<S extends symbol>(modelSymbol: S): InferModelType<S>;
|
|
41
56
|
/**
|
|
42
57
|
* 获取 Manager 实例(支持类型自动推断)
|
|
43
58
|
* @param managerSymbol Manager 的 Symbol,使用 ManagerNames.XXX
|
|
44
59
|
* @returns Manager 实例,类型会根据 symbol 自动推断
|
|
45
60
|
*/
|
|
46
|
-
protected getManager<S extends symbol>(managerSymbol: S): S
|
|
61
|
+
protected getManager<S extends symbol>(managerSymbol: S): InferManagerType<S>;
|
|
47
62
|
}
|
|
63
|
+
export {};
|
|
@@ -1,36 +1,45 @@
|
|
|
1
1
|
import { ICore } from "./Api";
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
+
/** Model 名称接口(用于类型推断,通过生成的 d.ts 文件扩展) */
|
|
4
|
+
export interface ModelNamesType extends Record<string, symbol> {
|
|
5
|
+
}
|
|
6
|
+
/** Manager 名称接口(用于类型推断,通过生成的 d.ts 文件扩展) */
|
|
7
|
+
export interface ManagerNamesType extends Record<string, symbol> {
|
|
8
|
+
}
|
|
9
|
+
/** View 名称接口(用于类型推断,通过生成的 d.ts 文件扩展) */
|
|
10
|
+
export interface ViewNamesType extends Record<string, symbol> {
|
|
11
|
+
}
|
|
3
12
|
/** Model 名称到 Symbol 的映射,用于代码补全和类型推断 */
|
|
4
|
-
export declare const ModelNames:
|
|
13
|
+
export declare const ModelNames: ModelNamesType;
|
|
5
14
|
/** Manager 名称到 Symbol 的映射,用于代码补全和类型推断 */
|
|
6
|
-
export declare const ManagerNames:
|
|
15
|
+
export declare const ManagerNames: ManagerNamesType;
|
|
7
16
|
/** View 名称到 Symbol 的映射,用于代码补全和类型推断 */
|
|
8
|
-
export declare const ViewNames:
|
|
17
|
+
export declare const ViewNames: ViewNamesType;
|
|
9
18
|
/**
|
|
10
19
|
* Symbol 到类型的映射接口,用于类型推断
|
|
11
20
|
* 业务层通过 declare module 扩展此接口来注册类型
|
|
12
21
|
* @example
|
|
13
22
|
* ```typescript
|
|
14
|
-
* declare module '
|
|
23
|
+
* declare module 'dzkcc-mflow/core' {
|
|
15
24
|
* interface ModelTypeMap {
|
|
16
|
-
*
|
|
25
|
+
* 'User': UserModel; // 使用字符串字面量作为 key
|
|
17
26
|
* }
|
|
18
27
|
* }
|
|
19
28
|
* ```
|
|
20
29
|
*/
|
|
21
|
-
export interface ModelTypeMap {
|
|
30
|
+
export interface ModelTypeMap extends Record<string, any> {
|
|
22
31
|
}
|
|
23
32
|
/**
|
|
24
33
|
* Symbol 到类型的映射接口,用于类型推断
|
|
25
34
|
* 业务层通过 declare module 扩展此接口来注册类型
|
|
26
35
|
*/
|
|
27
|
-
export interface ManagerTypeMap {
|
|
36
|
+
export interface ManagerTypeMap extends Record<string, any> {
|
|
28
37
|
}
|
|
29
38
|
/**
|
|
30
39
|
* Symbol 到类型的映射接口,用于类型推断
|
|
31
40
|
* 业务层通过 declare module 扩展此接口来注册类型
|
|
32
41
|
*/
|
|
33
|
-
export interface ViewTypeMap {
|
|
42
|
+
export interface ViewTypeMap extends Record<string, any> {
|
|
34
43
|
}
|
|
35
44
|
/**
|
|
36
45
|
* Model 装饰器,用于注册 Model 到全局注册表
|
package/dist/core/Decorators.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
|
|
3
|
-
// ============================================================================
|
|
4
|
-
// Symbol 注册系统 - Names 对象(提供代码补全和类型推断)
|
|
5
|
-
// ============================================================================
|
|
6
3
|
/** Model 名称到 Symbol 的映射,用于代码补全和类型推断 */
|
|
7
4
|
const ModelNames = {};
|
|
8
5
|
/** Manager 名称到 Symbol 的映射,用于代码补全和类型推断 */
|
package/dist/mflow-tools.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED