@composy/store-core 0.0.1 → 0.0.2
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/CHANGELOG.md +64 -3
- package/README.md +196 -172
- package/dist/index.js +1331 -1115
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +578 -417
- package/dist/index.min.js.map +1 -1
- package/es/.dts-output-manifest.json +1 -0
- package/es/.dts.tsbuildinfo +1 -0
- package/es/core/async-action.d.ts +1 -71
- package/es/core/async-action.js +83 -35
- package/es/core/async-action.js.map +1 -1
- package/es/core/base-store.d.ts +27 -62
- package/es/core/base-store.js +174 -74
- package/es/core/base-store.js.map +1 -1
- package/es/core/batch-manager.d.ts +0 -1
- package/es/core/batch-manager.js +15 -2
- package/es/core/batch-manager.js.map +1 -1
- package/es/core/create-store.d.ts +3 -3
- package/es/core/create-store.js +3 -3
- package/es/core/create-store.js.map +1 -1
- package/es/core/event-bus.d.ts +0 -1
- package/es/core/event-bus.js +1 -1
- package/es/core/event-bus.js.map +1 -1
- package/es/core/index.d.ts +1 -2
- package/es/core/index.js +2 -2
- package/es/core/pub-sub.d.ts +0 -1
- package/es/core/pub-sub.js +1 -1
- package/es/core/pub-sub.js.map +1 -1
- package/es/engine/index.d.ts +0 -1
- package/es/engine/index.js +1 -1
- package/es/engine/plugin.d.ts +0 -1
- package/es/engine/plugin.js +11 -2
- package/es/engine/plugin.js.map +1 -1
- package/es/engine/types.d.ts +0 -1
- package/es/engine/types.js +1 -1
- package/es/errors/index.d.ts +0 -1
- package/es/errors/index.js +17 -1
- package/es/errors/index.js.map +1 -1
- package/es/index.d.ts +3 -4
- package/es/index.js +8 -8
- package/es/index.js.map +1 -1
- package/es/middleware/index.d.ts +3 -4
- package/es/middleware/index.js +2 -2
- package/es/middleware/logger.d.ts +0 -1
- package/es/middleware/logger.js +2 -2
- package/es/middleware/logger.js.map +1 -1
- package/es/middleware/middleware-manager.d.ts +0 -1
- package/es/middleware/middleware-manager.js +5 -2
- package/es/middleware/middleware-manager.js.map +1 -1
- package/es/middleware/persist.d.ts +0 -1
- package/es/middleware/persist.js +3 -3
- package/es/middleware/persist.js.map +1 -1
- package/es/middleware/time-travel.d.ts +0 -1
- package/es/middleware/time-travel.js +1 -1
- package/es/middleware/time-travel.js.map +1 -1
- package/es/middleware/validation.d.ts +0 -1
- package/es/middleware/validation.js +2 -2
- package/es/middleware/validation.js.map +1 -1
- package/es/plugins/define-plugin.d.ts +1 -2
- package/es/plugins/define-plugin.js +2 -2
- package/es/plugins/define-plugin.js.map +1 -1
- package/es/plugins/index.d.ts +0 -1
- package/es/plugins/index.js +2 -2
- package/es/plugins/plugin-manager.d.ts +1 -31
- package/es/plugins/plugin-manager.js +58 -27
- package/es/plugins/plugin-manager.js.map +1 -1
- package/es/types/action.d.ts +2 -0
- package/es/types/action.js +10 -0
- package/es/types/batch.d.ts +2 -0
- package/es/types/batch.js +10 -0
- package/es/types/event.d.ts +2 -0
- package/es/types/event.js +10 -0
- package/es/types/index.d.ts +2 -3
- package/es/types/index.js +1 -1
- package/es/types/middleware.d.ts +10 -2
- package/es/types/middleware.js +1 -1
- package/es/types/mutation.d.ts +2 -0
- package/es/types/mutation.js +10 -0
- package/es/types/plugin.d.ts +4 -1
- package/es/types/plugin.js +1 -1
- package/es/types/state.d.ts +2 -0
- package/es/types/state.js +10 -0
- package/es/types/store.d.ts +19 -1
- package/es/types/store.js +1 -1
- package/es/types/subscription.d.ts +7 -2
- package/es/types/subscription.js +1 -1
- package/es/types/time-travel.d.ts +2 -0
- package/es/types/time-travel.js +10 -0
- package/es/types/utility.d.ts +3 -4
- package/es/types/utility.js +1 -1
- package/es/utils/debounce-throttle.d.ts +0 -1
- package/es/utils/debounce-throttle.js +1 -1
- package/es/utils/debounce-throttle.js.map +1 -1
- package/es/utils/deep-clone.d.ts +0 -1
- package/es/utils/deep-clone.js +1 -1
- package/es/utils/deep-clone.js.map +1 -1
- package/es/utils/index.d.ts +4 -5
- package/es/utils/index.js +1 -1
- package/es/utils/selector.d.ts +0 -1
- package/es/utils/selector.js +1 -1
- package/es/utils/selector.js.map +1 -1
- package/esm/core/async-action.js +83 -35
- package/esm/core/async-action.js.map +1 -1
- package/esm/core/base-store.js +174 -74
- package/esm/core/base-store.js.map +1 -1
- package/esm/core/batch-manager.js +15 -2
- package/esm/core/batch-manager.js.map +1 -1
- package/esm/core/create-store.js +3 -3
- package/esm/core/create-store.js.map +1 -1
- package/esm/core/event-bus.js +1 -1
- package/esm/core/event-bus.js.map +1 -1
- package/esm/core/index.js +2 -2
- package/esm/core/pub-sub.js +1 -1
- package/esm/core/pub-sub.js.map +1 -1
- package/esm/engine/index.js +1 -1
- package/esm/engine/plugin.js +11 -2
- package/esm/engine/plugin.js.map +1 -1
- package/esm/errors/index.js +17 -1
- package/esm/errors/index.js.map +1 -1
- package/esm/index.js +8 -8
- package/esm/index.js.map +1 -1
- package/esm/middleware/logger.js +2 -2
- package/esm/middleware/logger.js.map +1 -1
- package/esm/middleware/middleware-manager.js +5 -2
- package/esm/middleware/middleware-manager.js.map +1 -1
- package/esm/middleware/persist.js +3 -3
- package/esm/middleware/persist.js.map +1 -1
- package/esm/middleware/time-travel.js +1 -1
- package/esm/middleware/time-travel.js.map +1 -1
- package/esm/middleware/validation.js +2 -2
- package/esm/middleware/validation.js.map +1 -1
- package/esm/plugins/define-plugin.js +2 -2
- package/esm/plugins/define-plugin.js.map +1 -1
- package/esm/plugins/plugin-manager.js +58 -27
- package/esm/plugins/plugin-manager.js.map +1 -1
- package/esm/utils/debounce-throttle.js +1 -1
- package/esm/utils/debounce-throttle.js.map +1 -1
- package/esm/utils/deep-clone.js +1 -1
- package/esm/utils/deep-clone.js.map +1 -1
- package/esm/utils/selector.js +1 -1
- package/esm/utils/selector.js.map +1 -1
- package/lib/core/async-action.cjs +83 -35
- package/lib/core/async-action.cjs.map +1 -1
- package/lib/core/async-action.d.cts +25 -0
- package/lib/core/base-store.cjs +174 -74
- package/lib/core/base-store.cjs.map +1 -1
- package/lib/core/base-store.d.cts +50 -0
- package/lib/core/batch-manager.cjs +15 -2
- package/lib/core/batch-manager.cjs.map +1 -1
- package/{esm/core/batch-manager.d.ts → lib/core/batch-manager.d.cts} +0 -1
- package/lib/core/create-store.cjs +3 -3
- package/lib/core/create-store.cjs.map +1 -1
- package/lib/core/{create-store.d.ts → create-store.d.cts} +3 -3
- package/lib/core/event-bus.cjs +1 -1
- package/lib/core/event-bus.cjs.map +1 -1
- package/lib/core/{event-bus.d.ts → event-bus.d.cts} +0 -1
- package/lib/core/index.cjs +2 -2
- package/{esm/core/index.d.ts → lib/core/index.d.cts} +1 -2
- package/lib/core/pub-sub.cjs +1 -1
- package/lib/core/pub-sub.cjs.map +1 -1
- package/lib/core/{pub-sub.d.ts → pub-sub.d.cts} +0 -1
- package/lib/engine/index.cjs +1 -1
- package/{esm/engine/index.d.ts → lib/engine/index.d.cts} +0 -1
- package/lib/engine/plugin.cjs +11 -2
- package/lib/engine/plugin.cjs.map +1 -1
- package/{esm/engine/plugin.d.ts → lib/engine/plugin.d.cts} +0 -1
- package/lib/engine/types.cjs +1 -1
- package/lib/engine/{types.d.ts → types.d.cts} +0 -1
- package/lib/errors/index.cjs +17 -1
- package/lib/errors/index.cjs.map +1 -1
- package/lib/errors/{index.d.ts → index.d.cts} +0 -1
- package/lib/index.cjs +8 -8
- package/lib/index.cjs.map +1 -1
- package/lib/{index.d.ts → index.d.cts} +3 -4
- package/lib/middleware/index.cjs +2 -2
- package/lib/middleware/{index.d.ts → index.d.cts} +3 -4
- package/lib/middleware/logger.cjs +2 -2
- package/lib/middleware/logger.cjs.map +1 -1
- package/lib/middleware/{logger.d.ts → logger.d.cts} +0 -1
- package/lib/middleware/middleware-manager.cjs +5 -2
- package/lib/middleware/middleware-manager.cjs.map +1 -1
- package/lib/middleware/{middleware-manager.d.ts → middleware-manager.d.cts} +0 -1
- package/lib/middleware/persist.cjs +3 -3
- package/lib/middleware/persist.cjs.map +1 -1
- package/{esm/middleware/persist.d.ts → lib/middleware/persist.d.cts} +0 -1
- package/lib/middleware/time-travel.cjs +1 -1
- package/lib/middleware/time-travel.cjs.map +1 -1
- package/{esm/middleware/time-travel.d.ts → lib/middleware/time-travel.d.cts} +0 -1
- package/lib/middleware/validation.cjs +2 -2
- package/lib/middleware/validation.cjs.map +1 -1
- package/{esm/middleware/validation.d.ts → lib/middleware/validation.d.cts} +0 -1
- package/lib/plugins/define-plugin.cjs +2 -2
- package/lib/plugins/define-plugin.cjs.map +1 -1
- package/{esm/plugins/define-plugin.d.ts → lib/plugins/define-plugin.d.cts} +1 -2
- package/lib/plugins/index.cjs +2 -2
- package/{esm/plugins/index.d.ts → lib/plugins/index.d.cts} +0 -1
- package/lib/plugins/plugin-manager.cjs +58 -27
- package/lib/plugins/plugin-manager.cjs.map +1 -1
- package/lib/plugins/plugin-manager.d.cts +5 -0
- package/lib/types/action.cjs +12 -0
- package/lib/types/action.d.cts +2 -0
- package/lib/types/batch.cjs +12 -0
- package/lib/types/batch.d.cts +2 -0
- package/lib/types/event.cjs +12 -0
- package/lib/types/event.d.cts +2 -0
- package/lib/types/index.cjs +1 -1
- package/{esm/types/index.d.ts → lib/types/index.d.cts} +2 -3
- package/lib/types/middleware.cjs +1 -1
- package/lib/types/{middleware.d.ts → middleware.d.cts} +10 -2
- package/lib/types/mutation.cjs +12 -0
- package/lib/types/mutation.d.cts +2 -0
- package/lib/types/plugin.cjs +1 -1
- package/lib/types/{plugin.d.ts → plugin.d.cts} +4 -1
- package/lib/types/state.cjs +12 -0
- package/lib/types/state.d.cts +2 -0
- package/lib/types/store.cjs +1 -1
- package/lib/types/{store.d.ts → store.d.cts} +19 -1
- package/lib/types/subscription.cjs +1 -1
- package/lib/types/{subscription.d.ts → subscription.d.cts} +7 -2
- package/lib/types/time-travel.cjs +12 -0
- package/lib/types/time-travel.d.cts +2 -0
- package/lib/types/utility.cjs +1 -1
- package/lib/types/{utility.d.ts → utility.d.cts} +3 -4
- package/lib/utils/debounce-throttle.cjs +1 -1
- package/lib/utils/debounce-throttle.cjs.map +1 -1
- package/{esm/utils/debounce-throttle.d.ts → lib/utils/debounce-throttle.d.cts} +0 -1
- package/lib/utils/deep-clone.cjs +1 -1
- package/lib/utils/deep-clone.cjs.map +1 -1
- package/lib/utils/{deep-clone.d.ts → deep-clone.d.cts} +0 -1
- package/lib/utils/index.cjs +1 -1
- package/lib/utils/{index.d.ts → index.d.cts} +4 -5
- package/lib/utils/selector.cjs +1 -1
- package/lib/utils/selector.cjs.map +1 -1
- package/lib/utils/{selector.d.ts → selector.d.cts} +0 -1
- package/package.json +14 -11
- package/es/core/async-action.d.ts.map +0 -1
- package/es/core/base-store.d.ts.map +0 -1
- package/es/core/batch-manager.d.ts.map +0 -1
- package/es/core/create-store.d.ts.map +0 -1
- package/es/core/event-bus.d.ts.map +0 -1
- package/es/core/index.d.ts.map +0 -1
- package/es/core/pub-sub.d.ts.map +0 -1
- package/es/engine/index.d.ts.map +0 -1
- package/es/engine/plugin.d.ts.map +0 -1
- package/es/engine/types.d.ts.map +0 -1
- package/es/errors/index.d.ts.map +0 -1
- package/es/index.d.ts.map +0 -1
- package/es/middleware/index.d.ts.map +0 -1
- package/es/middleware/logger.d.ts.map +0 -1
- package/es/middleware/middleware-manager.d.ts.map +0 -1
- package/es/middleware/persist.d.ts.map +0 -1
- package/es/middleware/time-travel.d.ts.map +0 -1
- package/es/middleware/validation.d.ts.map +0 -1
- package/es/plugins/define-plugin.d.ts.map +0 -1
- package/es/plugins/index.d.ts.map +0 -1
- package/es/plugins/plugin-manager.d.ts.map +0 -1
- package/es/types/index.d.ts.map +0 -1
- package/es/types/middleware.d.ts.map +0 -1
- package/es/types/plugin.d.ts.map +0 -1
- package/es/types/store.d.ts.map +0 -1
- package/es/types/subscription.d.ts.map +0 -1
- package/es/types/utility.d.ts.map +0 -1
- package/es/utils/debounce-throttle.d.ts.map +0 -1
- package/es/utils/deep-clone.d.ts.map +0 -1
- package/es/utils/index.d.ts.map +0 -1
- package/es/utils/selector.d.ts.map +0 -1
- package/esm/core/async-action.d.ts +0 -95
- package/esm/core/base-store.d.ts +0 -85
- package/esm/core/create-store.d.ts +0 -66
- package/esm/core/event-bus.d.ts +0 -34
- package/esm/core/pub-sub.d.ts +0 -41
- package/esm/engine/types.d.ts +0 -81
- package/esm/errors/index.d.ts +0 -208
- package/esm/index.d.ts +0 -27
- package/esm/middleware/index.d.ts +0 -13
- package/esm/middleware/logger.d.ts +0 -67
- package/esm/middleware/middleware-manager.d.ts +0 -40
- package/esm/plugins/plugin-manager.d.ts +0 -35
- package/esm/types/middleware.d.ts +0 -172
- package/esm/types/plugin.d.ts +0 -136
- package/esm/types/store.d.ts +0 -198
- package/esm/types/subscription.d.ts +0 -158
- package/esm/types/utility.d.ts +0 -312
- package/esm/utils/deep-clone.d.ts +0 -143
- package/esm/utils/index.d.ts +0 -13
- package/esm/utils/selector.d.ts +0 -213
- package/lib/core/async-action.d.ts +0 -95
- package/lib/core/base-store.d.ts +0 -85
- package/lib/core/batch-manager.d.ts +0 -46
- package/lib/core/index.d.ts +0 -14
- package/lib/engine/index.d.ts +0 -10
- package/lib/engine/plugin.d.ts +0 -20
- package/lib/middleware/persist.d.ts +0 -34
- package/lib/middleware/time-travel.d.ts +0 -30
- package/lib/middleware/validation.d.ts +0 -100
- package/lib/plugins/define-plugin.d.ts +0 -74
- package/lib/plugins/index.d.ts +0 -8
- package/lib/plugins/plugin-manager.d.ts +0 -35
- package/lib/types/index.d.ts +0 -12
- package/lib/utils/debounce-throttle.d.ts +0 -86
package/esm/types/store.d.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Store 核心类型定义
|
|
3
|
-
*
|
|
4
|
-
* @module types/store
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* 状态对象类型
|
|
8
|
-
*/
|
|
9
|
-
export type StateTree = Record<string | number | symbol, unknown>;
|
|
10
|
-
/**
|
|
11
|
-
* Store ID 类型
|
|
12
|
-
*/
|
|
13
|
-
export type StoreId = string;
|
|
14
|
-
/**
|
|
15
|
-
* Getter 函数类型
|
|
16
|
-
* @template S - 状态类型
|
|
17
|
-
* @template R - 返回值类型
|
|
18
|
-
*/
|
|
19
|
-
export type StoreGetter<S extends StateTree, R> = (state: S) => R;
|
|
20
|
-
/**
|
|
21
|
-
* Getter 集合类型
|
|
22
|
-
* @template S - 状态类型
|
|
23
|
-
*/
|
|
24
|
-
export type StoreGetters<S extends StateTree> = Record<string, StoreGetter<S, unknown>>;
|
|
25
|
-
/**
|
|
26
|
-
* Action 函数类型
|
|
27
|
-
*
|
|
28
|
-
* 允许 action 通过 `this` 访问当前 Store 实例;未使用 `this` 的普通函数依旧兼容。
|
|
29
|
-
*/
|
|
30
|
-
export type StoreAction = (...args: unknown[]) => unknown;
|
|
31
|
-
/**
|
|
32
|
-
* Action 集合类型
|
|
33
|
-
*/
|
|
34
|
-
export type StoreActions = Record<string, StoreAction>;
|
|
35
|
-
/**
|
|
36
|
-
* Store 定义选项
|
|
37
|
-
* @template Id - Store ID 类型
|
|
38
|
-
* @template S - 状态类型
|
|
39
|
-
* @template G - Getters 类型
|
|
40
|
-
* @template A - Actions 类型
|
|
41
|
-
*/
|
|
42
|
-
export interface StoreDefinition<Id extends StoreId = StoreId, S extends StateTree = StateTree, G extends StoreGetters<S> = StoreGetters<S>, A extends StoreActions = StoreActions> {
|
|
43
|
-
/** Store 唯一标识 */
|
|
44
|
-
id: Id;
|
|
45
|
-
/** 初始状态工厂函数 */
|
|
46
|
-
state: () => S;
|
|
47
|
-
/** Getters 定义 */
|
|
48
|
-
getters?: G;
|
|
49
|
-
/** Actions 定义 */
|
|
50
|
-
actions?: A;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Store 实例接口
|
|
54
|
-
* @template Id - Store ID 类型
|
|
55
|
-
* @template S - 状态类型
|
|
56
|
-
* @template G - Getters 类型
|
|
57
|
-
* @template A - Actions 类型
|
|
58
|
-
*/
|
|
59
|
-
export interface StoreInstance<Id extends StoreId = StoreId, S extends StateTree = StateTree, G extends StoreGetters<S> = StoreGetters<S>, A extends StoreActions = StoreActions> {
|
|
60
|
-
/** Store 唯一标识 */
|
|
61
|
-
$id: Id;
|
|
62
|
-
/** 当前状态 */
|
|
63
|
-
$state: S;
|
|
64
|
-
/** Getter 计算结果 */
|
|
65
|
-
getters: {
|
|
66
|
-
[K in keyof G]: ReturnType<G[K]>;
|
|
67
|
-
};
|
|
68
|
-
/** Action 方法集合 */
|
|
69
|
-
actions: A;
|
|
70
|
-
/**
|
|
71
|
-
* 重置状态到初始值
|
|
72
|
-
*/
|
|
73
|
-
$reset: () => void;
|
|
74
|
-
/**
|
|
75
|
-
* 批量更新状态
|
|
76
|
-
* @param partialState - 部分状态或更新函数
|
|
77
|
-
*/
|
|
78
|
-
$patch: (partialState: Partial<S> | ((state: S) => void)) => void;
|
|
79
|
-
/**
|
|
80
|
-
* 订阅状态变化
|
|
81
|
-
* @param callback - 回调函数
|
|
82
|
-
* @param options - 订阅选项
|
|
83
|
-
* @returns 取消订阅函数
|
|
84
|
-
*/
|
|
85
|
-
$subscribe: (callback: StateSubscriber<S>, options?: SubscribeOptions) => () => void;
|
|
86
|
-
/**
|
|
87
|
-
* 订阅 action 调用
|
|
88
|
-
* @param callback - 回调函数
|
|
89
|
-
* @returns 取消订阅函数
|
|
90
|
-
*/
|
|
91
|
-
$onAction: (callback: ActionSubscriber<A>) => () => void;
|
|
92
|
-
/**
|
|
93
|
-
* 销毁 store
|
|
94
|
-
*/
|
|
95
|
-
$dispose: () => void;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 状态变化订阅器
|
|
99
|
-
* @template S - 状态类型
|
|
100
|
-
*/
|
|
101
|
-
export type StateSubscriber<S extends StateTree> = (mutation: StateMutation<S>, state: S) => void;
|
|
102
|
-
/**
|
|
103
|
-
* 状态变化信息
|
|
104
|
-
* @template S - 状态类型
|
|
105
|
-
*/
|
|
106
|
-
export interface StateMutation<S extends StateTree> {
|
|
107
|
-
/** 变化类型 */
|
|
108
|
-
type: 'direct' | 'patch object' | 'patch function';
|
|
109
|
-
/** Store ID */
|
|
110
|
-
storeId: StoreId;
|
|
111
|
-
/** 变化的键路径 */
|
|
112
|
-
events?: string[];
|
|
113
|
-
/** 变化前的状态快照 */
|
|
114
|
-
oldState?: Partial<S>;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* 订阅选项
|
|
118
|
-
*/
|
|
119
|
-
export interface SubscribeOptions {
|
|
120
|
-
/** 是否立即执行一次 */
|
|
121
|
-
immediate?: boolean;
|
|
122
|
-
/** 是否深度监听 */
|
|
123
|
-
deep?: boolean;
|
|
124
|
-
/** 是否在组件卸载后继续监听 */
|
|
125
|
-
detached?: boolean;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Action 订阅器
|
|
129
|
-
* @template A - Actions 类型
|
|
130
|
-
*/
|
|
131
|
-
export type ActionSubscriber<A extends StoreActions> = (context: ActionContext<A>) => void;
|
|
132
|
-
/**
|
|
133
|
-
* Action 上下文
|
|
134
|
-
* @template A - Actions 类型
|
|
135
|
-
*/
|
|
136
|
-
export interface ActionContext<A extends StoreActions> {
|
|
137
|
-
/** Action 名称 */
|
|
138
|
-
name: keyof A;
|
|
139
|
-
/** Store ID */
|
|
140
|
-
storeId: StoreId;
|
|
141
|
-
/** 调用参数 */
|
|
142
|
-
args: unknown[];
|
|
143
|
-
/** 执行后回调,异步 action 会在 Promise resolve 后触发 */
|
|
144
|
-
after: (callback: (result: unknown) => void | Promise<void>) => void;
|
|
145
|
-
/** 错误回调,异步 action 会在 Promise reject 后触发 */
|
|
146
|
-
onError: (callback: (error: unknown) => void | Promise<void>) => void;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Store 配置选项
|
|
150
|
-
*/
|
|
151
|
-
export interface StoreOptions {
|
|
152
|
-
/** 是否启用严格模式(只能通过 action 修改状态) */
|
|
153
|
-
strict?: boolean;
|
|
154
|
-
/** 是否启用开发工具 */
|
|
155
|
-
devtools?: boolean;
|
|
156
|
-
/** 是否启用持久化 */
|
|
157
|
-
persist?: boolean;
|
|
158
|
-
/** 持久化配置 */
|
|
159
|
-
persistOptions?: PersistOptions;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* 持久化选项
|
|
163
|
-
*/
|
|
164
|
-
export interface PersistOptions {
|
|
165
|
-
/** 存储键名 */
|
|
166
|
-
key?: string;
|
|
167
|
-
/** 存储类型 */
|
|
168
|
-
storage?: 'localStorage' | 'sessionStorage' | 'custom';
|
|
169
|
-
/** 自定义存储适配器 */
|
|
170
|
-
customStorage?: StorageAdapter;
|
|
171
|
-
/** 要持久化的路径 */
|
|
172
|
-
paths?: string[];
|
|
173
|
-
/** 序列化函数 */
|
|
174
|
-
serializer?: {
|
|
175
|
-
serialize: (value: unknown) => string;
|
|
176
|
-
deserialize: (value: string) => unknown;
|
|
177
|
-
};
|
|
178
|
-
/** 恢复前回调 */
|
|
179
|
-
beforeRestore?: (context: {
|
|
180
|
-
store: unknown;
|
|
181
|
-
}) => void;
|
|
182
|
-
/** 恢复后回调 */
|
|
183
|
-
afterRestore?: (context: {
|
|
184
|
-
store: unknown;
|
|
185
|
-
}) => void;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* 存储适配器接口
|
|
189
|
-
*/
|
|
190
|
-
export interface StorageAdapter {
|
|
191
|
-
/** 获取数据 */
|
|
192
|
-
getItem: (key: string) => string | null | Promise<string | null>;
|
|
193
|
-
/** 设置数据 */
|
|
194
|
-
setItem: (key: string, value: string) => void | Promise<void>;
|
|
195
|
-
/** 删除数据 */
|
|
196
|
-
removeItem: (key: string) => void | Promise<void>;
|
|
197
|
-
}
|
|
198
|
-
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 订阅系统类型定义
|
|
3
|
-
*
|
|
4
|
-
* @module types/subscription
|
|
5
|
-
*/
|
|
6
|
-
import type { StateTree, StoreId } from './store';
|
|
7
|
-
/**
|
|
8
|
-
* 订阅回调类型
|
|
9
|
-
* @template T - 数据类型
|
|
10
|
-
*/
|
|
11
|
-
export type Subscriber<T = unknown> = (value: T, oldValue?: T) => void;
|
|
12
|
-
/**
|
|
13
|
-
* 取消订阅函数类型
|
|
14
|
-
*/
|
|
15
|
-
export type Unsubscribe = () => void;
|
|
16
|
-
/**
|
|
17
|
-
* 订阅选项
|
|
18
|
-
*/
|
|
19
|
-
export interface SubscriptionOptions {
|
|
20
|
-
/** 是否立即执行 */
|
|
21
|
-
immediate?: boolean;
|
|
22
|
-
/** 是否在 store 销毁后保持订阅 */
|
|
23
|
-
detached?: boolean;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* 发布订阅管理器接口
|
|
27
|
-
*/
|
|
28
|
-
export interface PubSub<T = unknown> {
|
|
29
|
-
/**
|
|
30
|
-
* 订阅
|
|
31
|
-
* @param callback - 回调函数
|
|
32
|
-
* @param options - 订阅选项
|
|
33
|
-
* @returns 取消订阅函数
|
|
34
|
-
*/
|
|
35
|
-
subscribe: (callback: Subscriber<T>, options?: SubscriptionOptions) => Unsubscribe;
|
|
36
|
-
/**
|
|
37
|
-
* 发布
|
|
38
|
-
* @param value - 新值
|
|
39
|
-
* @param oldValue - 旧值
|
|
40
|
-
*/
|
|
41
|
-
publish: (value: T, oldValue?: T) => void;
|
|
42
|
-
/**
|
|
43
|
-
* 清空所有订阅
|
|
44
|
-
*/
|
|
45
|
-
clear: () => void;
|
|
46
|
-
/**
|
|
47
|
-
* 获取订阅者数量
|
|
48
|
-
*/
|
|
49
|
-
size: () => number;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 事件类型
|
|
53
|
-
*/
|
|
54
|
-
export type EventType = 'store:created' | 'store:disposed' | 'state:changed' | 'action:called' | 'action:completed' | 'action:error' | 'plugin:installed' | 'plugin:uninstalled';
|
|
55
|
-
/**
|
|
56
|
-
* 事件数据
|
|
57
|
-
*/
|
|
58
|
-
export interface EventData {
|
|
59
|
-
/** 事件类型 */
|
|
60
|
-
type: EventType;
|
|
61
|
-
/** Store ID */
|
|
62
|
-
storeId?: StoreId;
|
|
63
|
-
/** 事件数据 */
|
|
64
|
-
payload?: unknown;
|
|
65
|
-
/** 时间戳 */
|
|
66
|
-
timestamp: number;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* 事件监听器类型
|
|
70
|
-
*/
|
|
71
|
-
export type EventListener = (data: EventData) => void;
|
|
72
|
-
/**
|
|
73
|
-
* 事件总线接口
|
|
74
|
-
*/
|
|
75
|
-
export interface EventBus {
|
|
76
|
-
/**
|
|
77
|
-
* 监听事件
|
|
78
|
-
* @param type - 事件类型
|
|
79
|
-
* @param listener - 监听器
|
|
80
|
-
* @returns 取消监听函数
|
|
81
|
-
*/
|
|
82
|
-
on: (type: EventType | '*', listener: EventListener) => Unsubscribe;
|
|
83
|
-
/**
|
|
84
|
-
* 监听一次
|
|
85
|
-
* @param type - 事件类型
|
|
86
|
-
* @param listener - 监听器
|
|
87
|
-
* @returns 取消监听函数
|
|
88
|
-
*/
|
|
89
|
-
once: (type: EventType, listener: EventListener) => Unsubscribe;
|
|
90
|
-
/**
|
|
91
|
-
* 取消监听
|
|
92
|
-
* @param type - 事件类型
|
|
93
|
-
* @param listener - 监听器
|
|
94
|
-
*/
|
|
95
|
-
off: (type: EventType | '*', listener?: EventListener) => void;
|
|
96
|
-
/**
|
|
97
|
-
* 发送事件
|
|
98
|
-
* @param type - 事件类型
|
|
99
|
-
* @param payload - 事件数据
|
|
100
|
-
*/
|
|
101
|
-
emit: (type: EventType, payload?: unknown) => void;
|
|
102
|
-
/**
|
|
103
|
-
* 清空所有监听器
|
|
104
|
-
*/
|
|
105
|
-
clear: () => void;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* 选择器函数类型
|
|
109
|
-
* @template S - 状态类型
|
|
110
|
-
* @template R - 返回值类型
|
|
111
|
-
*/
|
|
112
|
-
export type Selector<S extends StateTree, R> = (state: S) => R;
|
|
113
|
-
/**
|
|
114
|
-
* 选择器订阅选项
|
|
115
|
-
*/
|
|
116
|
-
export interface SelectorOptions<R> {
|
|
117
|
-
/** 是否立即执行 */
|
|
118
|
-
immediate?: boolean;
|
|
119
|
-
/** 相等性比较函数 */
|
|
120
|
-
equalityFn?: (a: R, b: R) => boolean;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* 批量更新上下文
|
|
124
|
-
*/
|
|
125
|
-
export interface BatchContext {
|
|
126
|
-
/** 是否正在批量更新 */
|
|
127
|
-
isBatching: boolean;
|
|
128
|
-
/** 待更新的 Store ID 列表 */
|
|
129
|
-
pendingStores: Set<StoreId>;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* 批量更新管理器接口
|
|
133
|
-
*/
|
|
134
|
-
export interface BatchManager {
|
|
135
|
-
/**
|
|
136
|
-
* 开始批量更新
|
|
137
|
-
*/
|
|
138
|
-
start: () => void;
|
|
139
|
-
/**
|
|
140
|
-
* 结束批量更新并通知所有订阅者
|
|
141
|
-
*/
|
|
142
|
-
end: () => void;
|
|
143
|
-
/**
|
|
144
|
-
* 标记 Store 需要更新
|
|
145
|
-
* @param storeId - Store ID
|
|
146
|
-
*/
|
|
147
|
-
markDirty: (storeId: StoreId) => void;
|
|
148
|
-
/**
|
|
149
|
-
* 在批量上下文中执行
|
|
150
|
-
* @param fn - 执行函数
|
|
151
|
-
*/
|
|
152
|
-
batch: <T>(fn: () => T) => T;
|
|
153
|
-
/**
|
|
154
|
-
* 是否正在批量更新
|
|
155
|
-
*/
|
|
156
|
-
isBatching: () => boolean;
|
|
157
|
-
}
|
|
158
|
-
//# sourceMappingURL=subscription.d.ts.map
|
package/esm/types/utility.d.ts
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 工具类型定义
|
|
3
|
-
*
|
|
4
|
-
* 提供常用的类型工具,用于增强类型安全
|
|
5
|
-
* @module types/utility
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* 深度部分类型
|
|
9
|
-
*
|
|
10
|
-
* 将对象的所有属性(包括嵌套属性)设为可选
|
|
11
|
-
*
|
|
12
|
-
* @template T - 原始类型
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* interface User {
|
|
17
|
-
* name: string
|
|
18
|
-
* address: { city: string; zip: string }
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* type PartialUser = DeepPartial<User>
|
|
22
|
-
* // { name?: string; address?: { city?: string; zip?: string } }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export type DeepPartial<T> = T extends object ? T extends Array<infer U> ? Array<DeepPartial<U>> : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer U> ? Set<DeepPartial<U>> : T extends Function ? T : {
|
|
26
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
27
|
-
} : T;
|
|
28
|
-
/**
|
|
29
|
-
* 深度只读类型
|
|
30
|
-
*
|
|
31
|
-
* 将对象的所有属性(包括嵌套属性)设为只读
|
|
32
|
-
*
|
|
33
|
-
* @template T - 原始类型
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* interface Config {
|
|
38
|
-
* api: { url: string; timeout: number }
|
|
39
|
-
* }
|
|
40
|
-
*
|
|
41
|
-
* type ReadonlyConfig = DeepReadonly<Config>
|
|
42
|
-
* // { readonly api: { readonly url: string; readonly timeout: number } }
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export type DeepReadonly<T> = T extends object ? T extends Array<infer U> ? ReadonlyArray<DeepReadonly<U>> : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends Function ? T : {
|
|
46
|
-
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
|
47
|
-
} : T;
|
|
48
|
-
/**
|
|
49
|
-
* 只读 Map 类型
|
|
50
|
-
*/
|
|
51
|
-
type ReadonlyMap<K, V> = Omit<Map<K, V>, 'set' | 'delete' | 'clear'>;
|
|
52
|
-
/**
|
|
53
|
-
* 只读 Set 类型
|
|
54
|
-
*/
|
|
55
|
-
type ReadonlySet<T> = Omit<Set<T>, 'add' | 'delete' | 'clear'>;
|
|
56
|
-
/**
|
|
57
|
-
* 获取对象的所有路径
|
|
58
|
-
*
|
|
59
|
-
* @template T - 对象类型
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* interface State {
|
|
64
|
-
* user: { name: string; age: number }
|
|
65
|
-
* settings: { theme: string }
|
|
66
|
-
* }
|
|
67
|
-
*
|
|
68
|
-
* type Paths = PathsOf<State>
|
|
69
|
-
* // 'user' | 'user.name' | 'user.age' | 'settings' | 'settings.theme'
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export type PathsOf<T, Prefix extends string = ''> = T extends object ? T extends Array<unknown> ? Prefix : {
|
|
73
|
-
[K in keyof T & string]: K extends string ? Prefix extends '' ? K | PathsOf<T[K], K> : `${Prefix}.${K}` | PathsOf<T[K], `${Prefix}.${K}`> : never;
|
|
74
|
-
}[keyof T & string] : Prefix;
|
|
75
|
-
/**
|
|
76
|
-
* 根据路径获取类型
|
|
77
|
-
*
|
|
78
|
-
* @template T - 对象类型
|
|
79
|
-
* @template P - 路径字符串
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* interface State {
|
|
84
|
-
* user: { name: string; age: number }
|
|
85
|
-
* }
|
|
86
|
-
*
|
|
87
|
-
* type UserName = PathValue<State, 'user.name'> // string
|
|
88
|
-
* type User = PathValue<State, 'user'> // { name: string; age: number }
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export type PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? PathValue<T[K], Rest> : never : P extends keyof T ? T[P] : never;
|
|
92
|
-
/**
|
|
93
|
-
* 提取函数的参数类型
|
|
94
|
-
*
|
|
95
|
-
* @template T - 函数类型
|
|
96
|
-
*/
|
|
97
|
-
export type ArgumentsOf<T extends (...args: unknown[]) => unknown> = T extends (...args: infer P) => unknown ? P : never;
|
|
98
|
-
/**
|
|
99
|
-
* 提取函数的返回类型(异步函数自动解包 Promise)
|
|
100
|
-
*
|
|
101
|
-
* @template T - 函数类型
|
|
102
|
-
*/
|
|
103
|
-
export type AsyncReturnType<T extends (...args: unknown[]) => unknown> = T extends (...args: unknown[]) => Promise<infer R> ? R : T extends (...args: unknown[]) => infer R ? R : never;
|
|
104
|
-
/**
|
|
105
|
-
* 非空类型
|
|
106
|
-
*
|
|
107
|
-
* 从类型中排除 null 和 undefined
|
|
108
|
-
*
|
|
109
|
-
* @template T - 原始类型
|
|
110
|
-
*/
|
|
111
|
-
export type NonNullable<T> = T extends null | undefined ? never : T;
|
|
112
|
-
/**
|
|
113
|
-
* 可为 null 的类型
|
|
114
|
-
*
|
|
115
|
-
* @template T - 原始类型
|
|
116
|
-
*/
|
|
117
|
-
export type Nullable<T> = T | null;
|
|
118
|
-
/**
|
|
119
|
-
* 可选的类型
|
|
120
|
-
*
|
|
121
|
-
* @template T - 原始类型
|
|
122
|
-
*/
|
|
123
|
-
export type Optional<T> = T | undefined;
|
|
124
|
-
/**
|
|
125
|
-
* 品牌类型
|
|
126
|
-
*
|
|
127
|
-
* 用于创建名义类型系统
|
|
128
|
-
*
|
|
129
|
-
* @template T - 基础类型
|
|
130
|
-
* @template Brand - 品牌标识
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```typescript
|
|
134
|
-
* type UserId = Brand<string, 'UserId'>
|
|
135
|
-
* type PostId = Brand<string, 'PostId'>
|
|
136
|
-
*
|
|
137
|
-
* // UserId 和 PostId 不能互相赋值,即使底层都是 string
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
export type Brand<T, Brand extends string> = T & {
|
|
141
|
-
__brand: Brand;
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* 严格对象类型
|
|
145
|
-
*
|
|
146
|
-
* 确保对象不包含多余的属性
|
|
147
|
-
*
|
|
148
|
-
* @template T - 期望类型
|
|
149
|
-
* @template Actual - 实际类型
|
|
150
|
-
*/
|
|
151
|
-
export type Exact<T, Actual extends T> = T & {
|
|
152
|
-
[K in keyof Actual]: K extends keyof T ? T[K] : never;
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* 获取对象的必需键
|
|
156
|
-
*
|
|
157
|
-
* @template T - 对象类型
|
|
158
|
-
*/
|
|
159
|
-
export type RequiredKeys<T> = {
|
|
160
|
-
[K in keyof T]-?: undefined extends T[K] ? never : K;
|
|
161
|
-
}[keyof T];
|
|
162
|
-
/**
|
|
163
|
-
* 获取对象的可选键
|
|
164
|
-
*
|
|
165
|
-
* @template T - 对象类型
|
|
166
|
-
*/
|
|
167
|
-
export type OptionalKeys<T> = {
|
|
168
|
-
[K in keyof T]-?: undefined extends T[K] ? K : never;
|
|
169
|
-
}[keyof T];
|
|
170
|
-
/**
|
|
171
|
-
* 选择对象的部分属性设为必需
|
|
172
|
-
*
|
|
173
|
-
* @template T - 对象类型
|
|
174
|
-
* @template K - 需要设为必需的键
|
|
175
|
-
*/
|
|
176
|
-
export type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
177
|
-
/**
|
|
178
|
-
* 选择对象的部分属性设为可选
|
|
179
|
-
*
|
|
180
|
-
* @template T - 对象类型
|
|
181
|
-
* @template K - 需要设为可选的键
|
|
182
|
-
*/
|
|
183
|
-
export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
184
|
-
/**
|
|
185
|
-
* 合并两个类型
|
|
186
|
-
*
|
|
187
|
-
* 第二个类型的属性会覆盖第一个类型
|
|
188
|
-
*
|
|
189
|
-
* @template T - 第一个类型
|
|
190
|
-
* @template U - 第二个类型
|
|
191
|
-
*/
|
|
192
|
-
export type Merge<T, U> = Omit<T, keyof U> & U;
|
|
193
|
-
/**
|
|
194
|
-
* 获取两个类型的公共键
|
|
195
|
-
*
|
|
196
|
-
* @template T - 第一个类型
|
|
197
|
-
* @template U - 第二个类型
|
|
198
|
-
*/
|
|
199
|
-
export type CommonKeys<T, U> = keyof T & keyof U;
|
|
200
|
-
/**
|
|
201
|
-
* 函数类型
|
|
202
|
-
*/
|
|
203
|
-
export type AnyFunction = (...args: unknown[]) => unknown;
|
|
204
|
-
/**
|
|
205
|
-
* 异步函数类型
|
|
206
|
-
*/
|
|
207
|
-
export type AsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
208
|
-
/**
|
|
209
|
-
* 类类型
|
|
210
|
-
*
|
|
211
|
-
* @template T - 实例类型
|
|
212
|
-
*/
|
|
213
|
-
export type Constructor<T = unknown> = new (...args: unknown[]) => T;
|
|
214
|
-
/**
|
|
215
|
-
* 抽象类类型
|
|
216
|
-
*
|
|
217
|
-
* @template T - 实例类型
|
|
218
|
-
*/
|
|
219
|
-
export type AbstractConstructor<T = unknown> = abstract new (...args: unknown[]) => T;
|
|
220
|
-
/**
|
|
221
|
-
* 确保类型不为 never
|
|
222
|
-
*
|
|
223
|
-
* @template T - 待检查类型
|
|
224
|
-
*/
|
|
225
|
-
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
226
|
-
/**
|
|
227
|
-
* 确保类型是数组
|
|
228
|
-
*
|
|
229
|
-
* @template T - 待检查类型
|
|
230
|
-
*/
|
|
231
|
-
export type IsArray<T> = T extends unknown[] ? true : false;
|
|
232
|
-
/**
|
|
233
|
-
* 确保类型是对象(非数组、非函数)
|
|
234
|
-
*
|
|
235
|
-
* @template T - 待检查类型
|
|
236
|
-
*/
|
|
237
|
-
export type IsPlainObject<T> = T extends object ? T extends Function ? false : T extends unknown[] ? false : true : false;
|
|
238
|
-
/**
|
|
239
|
-
* 值类型为指定类型的键
|
|
240
|
-
*
|
|
241
|
-
* @template T - 对象类型
|
|
242
|
-
* @template V - 值类型
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```typescript
|
|
246
|
-
* interface User {
|
|
247
|
-
* id: number
|
|
248
|
-
* name: string
|
|
249
|
-
* age: number
|
|
250
|
-
* }
|
|
251
|
-
*
|
|
252
|
-
* type NumberKeys = KeysOfType<User, number> // 'id' | 'age'
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
export type KeysOfType<T, V> = {
|
|
256
|
-
[K in keyof T]: T[K] extends V ? K : never;
|
|
257
|
-
}[keyof T];
|
|
258
|
-
/**
|
|
259
|
-
* 排除值类型为指定类型的键
|
|
260
|
-
*
|
|
261
|
-
* @template T - 对象类型
|
|
262
|
-
* @template V - 要排除的值类型
|
|
263
|
-
*/
|
|
264
|
-
export type KeysExcludeType<T, V> = {
|
|
265
|
-
[K in keyof T]: T[K] extends V ? never : K;
|
|
266
|
-
}[keyof T];
|
|
267
|
-
/**
|
|
268
|
-
* 仅保留值类型为指定类型的属性
|
|
269
|
-
*
|
|
270
|
-
* @template T - 对象类型
|
|
271
|
-
* @template V - 值类型
|
|
272
|
-
*/
|
|
273
|
-
export type PickByType<T, V> = Pick<T, KeysOfType<T, V>>;
|
|
274
|
-
/**
|
|
275
|
-
* 排除值类型为指定类型的属性
|
|
276
|
-
*
|
|
277
|
-
* @template T - 对象类型
|
|
278
|
-
* @template V - 要排除的值类型
|
|
279
|
-
*/
|
|
280
|
-
export type OmitByType<T, V> = Pick<T, KeysExcludeType<T, V>>;
|
|
281
|
-
/**
|
|
282
|
-
* 提取 Promise 的值类型
|
|
283
|
-
*
|
|
284
|
-
* @template T - Promise 类型
|
|
285
|
-
*/
|
|
286
|
-
export type Awaited<T> = T extends Promise<infer U> ? Awaited<U> : T;
|
|
287
|
-
/**
|
|
288
|
-
* 联合类型转交叉类型
|
|
289
|
-
*
|
|
290
|
-
* @template U - 联合类型
|
|
291
|
-
*/
|
|
292
|
-
export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
293
|
-
/**
|
|
294
|
-
* 元组类型转联合类型
|
|
295
|
-
*
|
|
296
|
-
* @template T - 元组类型
|
|
297
|
-
*/
|
|
298
|
-
export type TupleToUnion<T extends unknown[]> = T[number];
|
|
299
|
-
/**
|
|
300
|
-
* 字符串字面量首字母大写
|
|
301
|
-
*
|
|
302
|
-
* @template S - 字符串类型
|
|
303
|
-
*/
|
|
304
|
-
export type Capitalize<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
305
|
-
/**
|
|
306
|
-
* 字符串字面量首字母小写
|
|
307
|
-
*
|
|
308
|
-
* @template S - 字符串类型
|
|
309
|
-
*/
|
|
310
|
-
export type Uncapitalize<S extends string> = S extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : S;
|
|
311
|
-
export {};
|
|
312
|
-
//# sourceMappingURL=utility.d.ts.map
|