@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.
Files changed (300) hide show
  1. package/CHANGELOG.md +64 -3
  2. package/README.md +196 -172
  3. package/dist/index.js +1331 -1115
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +578 -417
  6. package/dist/index.min.js.map +1 -1
  7. package/es/.dts-output-manifest.json +1 -0
  8. package/es/.dts.tsbuildinfo +1 -0
  9. package/es/core/async-action.d.ts +1 -71
  10. package/es/core/async-action.js +83 -35
  11. package/es/core/async-action.js.map +1 -1
  12. package/es/core/base-store.d.ts +27 -62
  13. package/es/core/base-store.js +174 -74
  14. package/es/core/base-store.js.map +1 -1
  15. package/es/core/batch-manager.d.ts +0 -1
  16. package/es/core/batch-manager.js +15 -2
  17. package/es/core/batch-manager.js.map +1 -1
  18. package/es/core/create-store.d.ts +3 -3
  19. package/es/core/create-store.js +3 -3
  20. package/es/core/create-store.js.map +1 -1
  21. package/es/core/event-bus.d.ts +0 -1
  22. package/es/core/event-bus.js +1 -1
  23. package/es/core/event-bus.js.map +1 -1
  24. package/es/core/index.d.ts +1 -2
  25. package/es/core/index.js +2 -2
  26. package/es/core/pub-sub.d.ts +0 -1
  27. package/es/core/pub-sub.js +1 -1
  28. package/es/core/pub-sub.js.map +1 -1
  29. package/es/engine/index.d.ts +0 -1
  30. package/es/engine/index.js +1 -1
  31. package/es/engine/plugin.d.ts +0 -1
  32. package/es/engine/plugin.js +11 -2
  33. package/es/engine/plugin.js.map +1 -1
  34. package/es/engine/types.d.ts +0 -1
  35. package/es/engine/types.js +1 -1
  36. package/es/errors/index.d.ts +0 -1
  37. package/es/errors/index.js +17 -1
  38. package/es/errors/index.js.map +1 -1
  39. package/es/index.d.ts +3 -4
  40. package/es/index.js +8 -8
  41. package/es/index.js.map +1 -1
  42. package/es/middleware/index.d.ts +3 -4
  43. package/es/middleware/index.js +2 -2
  44. package/es/middleware/logger.d.ts +0 -1
  45. package/es/middleware/logger.js +2 -2
  46. package/es/middleware/logger.js.map +1 -1
  47. package/es/middleware/middleware-manager.d.ts +0 -1
  48. package/es/middleware/middleware-manager.js +5 -2
  49. package/es/middleware/middleware-manager.js.map +1 -1
  50. package/es/middleware/persist.d.ts +0 -1
  51. package/es/middleware/persist.js +3 -3
  52. package/es/middleware/persist.js.map +1 -1
  53. package/es/middleware/time-travel.d.ts +0 -1
  54. package/es/middleware/time-travel.js +1 -1
  55. package/es/middleware/time-travel.js.map +1 -1
  56. package/es/middleware/validation.d.ts +0 -1
  57. package/es/middleware/validation.js +2 -2
  58. package/es/middleware/validation.js.map +1 -1
  59. package/es/plugins/define-plugin.d.ts +1 -2
  60. package/es/plugins/define-plugin.js +2 -2
  61. package/es/plugins/define-plugin.js.map +1 -1
  62. package/es/plugins/index.d.ts +0 -1
  63. package/es/plugins/index.js +2 -2
  64. package/es/plugins/plugin-manager.d.ts +1 -31
  65. package/es/plugins/plugin-manager.js +58 -27
  66. package/es/plugins/plugin-manager.js.map +1 -1
  67. package/es/types/action.d.ts +2 -0
  68. package/es/types/action.js +10 -0
  69. package/es/types/batch.d.ts +2 -0
  70. package/es/types/batch.js +10 -0
  71. package/es/types/event.d.ts +2 -0
  72. package/es/types/event.js +10 -0
  73. package/es/types/index.d.ts +2 -3
  74. package/es/types/index.js +1 -1
  75. package/es/types/middleware.d.ts +10 -2
  76. package/es/types/middleware.js +1 -1
  77. package/es/types/mutation.d.ts +2 -0
  78. package/es/types/mutation.js +10 -0
  79. package/es/types/plugin.d.ts +4 -1
  80. package/es/types/plugin.js +1 -1
  81. package/es/types/state.d.ts +2 -0
  82. package/es/types/state.js +10 -0
  83. package/es/types/store.d.ts +19 -1
  84. package/es/types/store.js +1 -1
  85. package/es/types/subscription.d.ts +7 -2
  86. package/es/types/subscription.js +1 -1
  87. package/es/types/time-travel.d.ts +2 -0
  88. package/es/types/time-travel.js +10 -0
  89. package/es/types/utility.d.ts +3 -4
  90. package/es/types/utility.js +1 -1
  91. package/es/utils/debounce-throttle.d.ts +0 -1
  92. package/es/utils/debounce-throttle.js +1 -1
  93. package/es/utils/debounce-throttle.js.map +1 -1
  94. package/es/utils/deep-clone.d.ts +0 -1
  95. package/es/utils/deep-clone.js +1 -1
  96. package/es/utils/deep-clone.js.map +1 -1
  97. package/es/utils/index.d.ts +4 -5
  98. package/es/utils/index.js +1 -1
  99. package/es/utils/selector.d.ts +0 -1
  100. package/es/utils/selector.js +1 -1
  101. package/es/utils/selector.js.map +1 -1
  102. package/esm/core/async-action.js +83 -35
  103. package/esm/core/async-action.js.map +1 -1
  104. package/esm/core/base-store.js +174 -74
  105. package/esm/core/base-store.js.map +1 -1
  106. package/esm/core/batch-manager.js +15 -2
  107. package/esm/core/batch-manager.js.map +1 -1
  108. package/esm/core/create-store.js +3 -3
  109. package/esm/core/create-store.js.map +1 -1
  110. package/esm/core/event-bus.js +1 -1
  111. package/esm/core/event-bus.js.map +1 -1
  112. package/esm/core/index.js +2 -2
  113. package/esm/core/pub-sub.js +1 -1
  114. package/esm/core/pub-sub.js.map +1 -1
  115. package/esm/engine/index.js +1 -1
  116. package/esm/engine/plugin.js +11 -2
  117. package/esm/engine/plugin.js.map +1 -1
  118. package/esm/errors/index.js +17 -1
  119. package/esm/errors/index.js.map +1 -1
  120. package/esm/index.js +8 -8
  121. package/esm/index.js.map +1 -1
  122. package/esm/middleware/logger.js +2 -2
  123. package/esm/middleware/logger.js.map +1 -1
  124. package/esm/middleware/middleware-manager.js +5 -2
  125. package/esm/middleware/middleware-manager.js.map +1 -1
  126. package/esm/middleware/persist.js +3 -3
  127. package/esm/middleware/persist.js.map +1 -1
  128. package/esm/middleware/time-travel.js +1 -1
  129. package/esm/middleware/time-travel.js.map +1 -1
  130. package/esm/middleware/validation.js +2 -2
  131. package/esm/middleware/validation.js.map +1 -1
  132. package/esm/plugins/define-plugin.js +2 -2
  133. package/esm/plugins/define-plugin.js.map +1 -1
  134. package/esm/plugins/plugin-manager.js +58 -27
  135. package/esm/plugins/plugin-manager.js.map +1 -1
  136. package/esm/utils/debounce-throttle.js +1 -1
  137. package/esm/utils/debounce-throttle.js.map +1 -1
  138. package/esm/utils/deep-clone.js +1 -1
  139. package/esm/utils/deep-clone.js.map +1 -1
  140. package/esm/utils/selector.js +1 -1
  141. package/esm/utils/selector.js.map +1 -1
  142. package/lib/core/async-action.cjs +83 -35
  143. package/lib/core/async-action.cjs.map +1 -1
  144. package/lib/core/async-action.d.cts +25 -0
  145. package/lib/core/base-store.cjs +174 -74
  146. package/lib/core/base-store.cjs.map +1 -1
  147. package/lib/core/base-store.d.cts +50 -0
  148. package/lib/core/batch-manager.cjs +15 -2
  149. package/lib/core/batch-manager.cjs.map +1 -1
  150. package/{esm/core/batch-manager.d.ts → lib/core/batch-manager.d.cts} +0 -1
  151. package/lib/core/create-store.cjs +3 -3
  152. package/lib/core/create-store.cjs.map +1 -1
  153. package/lib/core/{create-store.d.ts → create-store.d.cts} +3 -3
  154. package/lib/core/event-bus.cjs +1 -1
  155. package/lib/core/event-bus.cjs.map +1 -1
  156. package/lib/core/{event-bus.d.ts → event-bus.d.cts} +0 -1
  157. package/lib/core/index.cjs +2 -2
  158. package/{esm/core/index.d.ts → lib/core/index.d.cts} +1 -2
  159. package/lib/core/pub-sub.cjs +1 -1
  160. package/lib/core/pub-sub.cjs.map +1 -1
  161. package/lib/core/{pub-sub.d.ts → pub-sub.d.cts} +0 -1
  162. package/lib/engine/index.cjs +1 -1
  163. package/{esm/engine/index.d.ts → lib/engine/index.d.cts} +0 -1
  164. package/lib/engine/plugin.cjs +11 -2
  165. package/lib/engine/plugin.cjs.map +1 -1
  166. package/{esm/engine/plugin.d.ts → lib/engine/plugin.d.cts} +0 -1
  167. package/lib/engine/types.cjs +1 -1
  168. package/lib/engine/{types.d.ts → types.d.cts} +0 -1
  169. package/lib/errors/index.cjs +17 -1
  170. package/lib/errors/index.cjs.map +1 -1
  171. package/lib/errors/{index.d.ts → index.d.cts} +0 -1
  172. package/lib/index.cjs +8 -8
  173. package/lib/index.cjs.map +1 -1
  174. package/lib/{index.d.ts → index.d.cts} +3 -4
  175. package/lib/middleware/index.cjs +2 -2
  176. package/lib/middleware/{index.d.ts → index.d.cts} +3 -4
  177. package/lib/middleware/logger.cjs +2 -2
  178. package/lib/middleware/logger.cjs.map +1 -1
  179. package/lib/middleware/{logger.d.ts → logger.d.cts} +0 -1
  180. package/lib/middleware/middleware-manager.cjs +5 -2
  181. package/lib/middleware/middleware-manager.cjs.map +1 -1
  182. package/lib/middleware/{middleware-manager.d.ts → middleware-manager.d.cts} +0 -1
  183. package/lib/middleware/persist.cjs +3 -3
  184. package/lib/middleware/persist.cjs.map +1 -1
  185. package/{esm/middleware/persist.d.ts → lib/middleware/persist.d.cts} +0 -1
  186. package/lib/middleware/time-travel.cjs +1 -1
  187. package/lib/middleware/time-travel.cjs.map +1 -1
  188. package/{esm/middleware/time-travel.d.ts → lib/middleware/time-travel.d.cts} +0 -1
  189. package/lib/middleware/validation.cjs +2 -2
  190. package/lib/middleware/validation.cjs.map +1 -1
  191. package/{esm/middleware/validation.d.ts → lib/middleware/validation.d.cts} +0 -1
  192. package/lib/plugins/define-plugin.cjs +2 -2
  193. package/lib/plugins/define-plugin.cjs.map +1 -1
  194. package/{esm/plugins/define-plugin.d.ts → lib/plugins/define-plugin.d.cts} +1 -2
  195. package/lib/plugins/index.cjs +2 -2
  196. package/{esm/plugins/index.d.ts → lib/plugins/index.d.cts} +0 -1
  197. package/lib/plugins/plugin-manager.cjs +58 -27
  198. package/lib/plugins/plugin-manager.cjs.map +1 -1
  199. package/lib/plugins/plugin-manager.d.cts +5 -0
  200. package/lib/types/action.cjs +12 -0
  201. package/lib/types/action.d.cts +2 -0
  202. package/lib/types/batch.cjs +12 -0
  203. package/lib/types/batch.d.cts +2 -0
  204. package/lib/types/event.cjs +12 -0
  205. package/lib/types/event.d.cts +2 -0
  206. package/lib/types/index.cjs +1 -1
  207. package/{esm/types/index.d.ts → lib/types/index.d.cts} +2 -3
  208. package/lib/types/middleware.cjs +1 -1
  209. package/lib/types/{middleware.d.ts → middleware.d.cts} +10 -2
  210. package/lib/types/mutation.cjs +12 -0
  211. package/lib/types/mutation.d.cts +2 -0
  212. package/lib/types/plugin.cjs +1 -1
  213. package/lib/types/{plugin.d.ts → plugin.d.cts} +4 -1
  214. package/lib/types/state.cjs +12 -0
  215. package/lib/types/state.d.cts +2 -0
  216. package/lib/types/store.cjs +1 -1
  217. package/lib/types/{store.d.ts → store.d.cts} +19 -1
  218. package/lib/types/subscription.cjs +1 -1
  219. package/lib/types/{subscription.d.ts → subscription.d.cts} +7 -2
  220. package/lib/types/time-travel.cjs +12 -0
  221. package/lib/types/time-travel.d.cts +2 -0
  222. package/lib/types/utility.cjs +1 -1
  223. package/lib/types/{utility.d.ts → utility.d.cts} +3 -4
  224. package/lib/utils/debounce-throttle.cjs +1 -1
  225. package/lib/utils/debounce-throttle.cjs.map +1 -1
  226. package/{esm/utils/debounce-throttle.d.ts → lib/utils/debounce-throttle.d.cts} +0 -1
  227. package/lib/utils/deep-clone.cjs +1 -1
  228. package/lib/utils/deep-clone.cjs.map +1 -1
  229. package/lib/utils/{deep-clone.d.ts → deep-clone.d.cts} +0 -1
  230. package/lib/utils/index.cjs +1 -1
  231. package/lib/utils/{index.d.ts → index.d.cts} +4 -5
  232. package/lib/utils/selector.cjs +1 -1
  233. package/lib/utils/selector.cjs.map +1 -1
  234. package/lib/utils/{selector.d.ts → selector.d.cts} +0 -1
  235. package/package.json +14 -11
  236. package/es/core/async-action.d.ts.map +0 -1
  237. package/es/core/base-store.d.ts.map +0 -1
  238. package/es/core/batch-manager.d.ts.map +0 -1
  239. package/es/core/create-store.d.ts.map +0 -1
  240. package/es/core/event-bus.d.ts.map +0 -1
  241. package/es/core/index.d.ts.map +0 -1
  242. package/es/core/pub-sub.d.ts.map +0 -1
  243. package/es/engine/index.d.ts.map +0 -1
  244. package/es/engine/plugin.d.ts.map +0 -1
  245. package/es/engine/types.d.ts.map +0 -1
  246. package/es/errors/index.d.ts.map +0 -1
  247. package/es/index.d.ts.map +0 -1
  248. package/es/middleware/index.d.ts.map +0 -1
  249. package/es/middleware/logger.d.ts.map +0 -1
  250. package/es/middleware/middleware-manager.d.ts.map +0 -1
  251. package/es/middleware/persist.d.ts.map +0 -1
  252. package/es/middleware/time-travel.d.ts.map +0 -1
  253. package/es/middleware/validation.d.ts.map +0 -1
  254. package/es/plugins/define-plugin.d.ts.map +0 -1
  255. package/es/plugins/index.d.ts.map +0 -1
  256. package/es/plugins/plugin-manager.d.ts.map +0 -1
  257. package/es/types/index.d.ts.map +0 -1
  258. package/es/types/middleware.d.ts.map +0 -1
  259. package/es/types/plugin.d.ts.map +0 -1
  260. package/es/types/store.d.ts.map +0 -1
  261. package/es/types/subscription.d.ts.map +0 -1
  262. package/es/types/utility.d.ts.map +0 -1
  263. package/es/utils/debounce-throttle.d.ts.map +0 -1
  264. package/es/utils/deep-clone.d.ts.map +0 -1
  265. package/es/utils/index.d.ts.map +0 -1
  266. package/es/utils/selector.d.ts.map +0 -1
  267. package/esm/core/async-action.d.ts +0 -95
  268. package/esm/core/base-store.d.ts +0 -85
  269. package/esm/core/create-store.d.ts +0 -66
  270. package/esm/core/event-bus.d.ts +0 -34
  271. package/esm/core/pub-sub.d.ts +0 -41
  272. package/esm/engine/types.d.ts +0 -81
  273. package/esm/errors/index.d.ts +0 -208
  274. package/esm/index.d.ts +0 -27
  275. package/esm/middleware/index.d.ts +0 -13
  276. package/esm/middleware/logger.d.ts +0 -67
  277. package/esm/middleware/middleware-manager.d.ts +0 -40
  278. package/esm/plugins/plugin-manager.d.ts +0 -35
  279. package/esm/types/middleware.d.ts +0 -172
  280. package/esm/types/plugin.d.ts +0 -136
  281. package/esm/types/store.d.ts +0 -198
  282. package/esm/types/subscription.d.ts +0 -158
  283. package/esm/types/utility.d.ts +0 -312
  284. package/esm/utils/deep-clone.d.ts +0 -143
  285. package/esm/utils/index.d.ts +0 -13
  286. package/esm/utils/selector.d.ts +0 -213
  287. package/lib/core/async-action.d.ts +0 -95
  288. package/lib/core/base-store.d.ts +0 -85
  289. package/lib/core/batch-manager.d.ts +0 -46
  290. package/lib/core/index.d.ts +0 -14
  291. package/lib/engine/index.d.ts +0 -10
  292. package/lib/engine/plugin.d.ts +0 -20
  293. package/lib/middleware/persist.d.ts +0 -34
  294. package/lib/middleware/time-travel.d.ts +0 -30
  295. package/lib/middleware/validation.d.ts +0 -100
  296. package/lib/plugins/define-plugin.d.ts +0 -74
  297. package/lib/plugins/index.d.ts +0 -8
  298. package/lib/plugins/plugin-manager.d.ts +0 -35
  299. package/lib/types/index.d.ts +0 -12
  300. package/lib/utils/debounce-throttle.d.ts +0 -86
@@ -1,208 +0,0 @@
1
- /**
2
- * 自定义错误类
3
- *
4
- * 提供统一的错误处理模式
5
- * @module errors
6
- */
7
- /**
8
- * Store 错误代码
9
- */
10
- export declare enum StoreErrorCode {
11
- /** Store 已销毁 */
12
- STORE_DISPOSED = "STORE_DISPOSED",
13
- /** Store 不存在 */
14
- STORE_NOT_FOUND = "STORE_NOT_FOUND",
15
- /** Store 已存在 */
16
- STORE_ALREADY_EXISTS = "STORE_ALREADY_EXISTS",
17
- /** 无效的状态 */
18
- INVALID_STATE = "INVALID_STATE",
19
- /** 无效的 Action */
20
- INVALID_ACTION = "INVALID_ACTION",
21
- /** 序列化错误 */
22
- SERIALIZATION_ERROR = "SERIALIZATION_ERROR",
23
- /** 反序列化错误 */
24
- DESERIALIZATION_ERROR = "DESERIALIZATION_ERROR",
25
- /** 存储错误 */
26
- STORAGE_ERROR = "STORAGE_ERROR",
27
- /** 插件错误 */
28
- PLUGIN_ERROR = "PLUGIN_ERROR",
29
- /** 中间件错误 */
30
- MIDDLEWARE_ERROR = "MIDDLEWARE_ERROR",
31
- /** 订阅错误 */
32
- SUBSCRIPTION_ERROR = "SUBSCRIPTION_ERROR",
33
- /** 超时错误 */
34
- TIMEOUT_ERROR = "TIMEOUT_ERROR",
35
- /** 未知错误 */
36
- UNKNOWN_ERROR = "UNKNOWN_ERROR"
37
- }
38
- /**
39
- * 错误严重级别
40
- */
41
- export declare enum ErrorSeverity {
42
- /** 警告 - 不影响功能,但需要注意 */
43
- WARNING = "warning",
44
- /** 错误 - 影响部分功能 */
45
- ERROR = "error",
46
- /** 致命 - 导致系统无法正常运行 */
47
- FATAL = "fatal"
48
- }
49
- /**
50
- * Store 错误上下文
51
- */
52
- export interface StoreErrorContext {
53
- /** Store ID */
54
- storeId?: string;
55
- /** Action 名称 */
56
- action?: string;
57
- /** 插件名称 */
58
- plugin?: string;
59
- /** 中间件名称 */
60
- middleware?: string;
61
- /** 额外数据 */
62
- data?: unknown;
63
- /** 时间戳 */
64
- timestamp?: number;
65
- }
66
- /**
67
- * Store 基础错误类
68
- *
69
- * 所有 Store 相关错误的基类
70
- *
71
- * @example
72
- * ```typescript
73
- * try {
74
- * store.someAction()
75
- * } catch (error) {
76
- * if (error instanceof StoreError) {
77
- * console.log('Store error:', error.code, error.message)
78
- * console.log('Context:', error.context)
79
- * }
80
- * }
81
- * ```
82
- */
83
- export declare class StoreError extends Error {
84
- /** 错误代码 */
85
- readonly code: StoreErrorCode;
86
- /** 错误上下文 */
87
- readonly context: StoreErrorContext;
88
- /** 错误严重级别 */
89
- readonly severity: ErrorSeverity;
90
- /** 原始错误 */
91
- readonly cause?: Error;
92
- /**
93
- * 创建 Store 错误
94
- *
95
- * @param message - 错误消息
96
- * @param code - 错误代码
97
- * @param context - 错误上下文
98
- * @param severity - 错误严重级别
99
- * @param cause - 原始错误
100
- */
101
- constructor(message: string, code?: StoreErrorCode, context?: StoreErrorContext, severity?: ErrorSeverity, cause?: Error);
102
- /**
103
- * 转换为 JSON
104
- */
105
- toJSON(): Record<string, unknown>;
106
- /**
107
- * 格式化错误信息
108
- */
109
- format(): string;
110
- }
111
- /**
112
- * Store 销毁错误
113
- *
114
- * 当尝试操作已销毁的 Store 时抛出
115
- */
116
- export declare class StoreDisposedError extends StoreError {
117
- constructor(storeId: string, action?: string);
118
- }
119
- /**
120
- * Store 不存在错误
121
- */
122
- export declare class StoreNotFoundError extends StoreError {
123
- constructor(storeId: string);
124
- }
125
- /**
126
- * Store 已存在错误
127
- */
128
- export declare class StoreAlreadyExistsError extends StoreError {
129
- constructor(storeId: string);
130
- }
131
- /**
132
- * 无效状态错误
133
- */
134
- export declare class InvalidStateError extends StoreError {
135
- constructor(message: string, storeId?: string, data?: unknown);
136
- }
137
- /**
138
- * 序列化错误
139
- */
140
- export declare class SerializationError extends StoreError {
141
- constructor(message: string, cause?: Error, storeId?: string);
142
- }
143
- /**
144
- * 反序列化错误
145
- */
146
- export declare class DeserializationError extends StoreError {
147
- constructor(message: string, cause?: Error, storeId?: string);
148
- }
149
- /**
150
- * 存储错误
151
- */
152
- export declare class StorageError extends StoreError {
153
- constructor(message: string, cause?: Error, storeId?: string);
154
- }
155
- /**
156
- * 插件错误
157
- */
158
- export declare class PluginError extends StoreError {
159
- constructor(message: string, pluginName: string, cause?: Error);
160
- }
161
- /**
162
- * 中间件错误
163
- */
164
- export declare class MiddlewareError extends StoreError {
165
- constructor(message: string, middlewareName: string, cause?: Error);
166
- }
167
- /**
168
- * 订阅错误
169
- */
170
- export declare class SubscriptionError extends StoreError {
171
- constructor(message: string, cause?: Error, storeId?: string);
172
- }
173
- /**
174
- * 超时错误
175
- */
176
- export declare class TimeoutError extends StoreError {
177
- constructor(message: string, storeId?: string, action?: string);
178
- }
179
- /**
180
- * 错误处理工具
181
- */
182
- export declare const errorUtils: {
183
- /**
184
- * 判断是否为 Store 错误
185
- */
186
- isStoreError(error: unknown): error is StoreError;
187
- /**
188
- * 判断是否为特定类型的错误
189
- */
190
- isErrorCode(error: unknown, code: StoreErrorCode): boolean;
191
- /**
192
- * 包装错误为 Store 错误
193
- */
194
- wrap(error: unknown, code?: StoreErrorCode, context?: StoreErrorContext): StoreError;
195
- /**
196
- * 安全执行函数,捕获并包装错误
197
- */
198
- tryCatch<T>(fn: () => T | Promise<T>, code?: StoreErrorCode, context?: StoreErrorContext): Promise<T>;
199
- /**
200
- * 创建错误日志记录器
201
- */
202
- createLogger(prefix: string): {
203
- error(error: StoreError): void;
204
- warn(error: StoreError): void;
205
- log(error: StoreError): void;
206
- };
207
- };
208
- //# sourceMappingURL=index.d.ts.map
package/esm/index.d.ts DELETED
@@ -1,27 +0,0 @@
1
- /**
2
- * @composy/store-core - 框架无关的状态管理核心库
3
- *
4
- * 主要功能模块:
5
- * - 核心抽象:Store、State、Action、Getter 等核心概念
6
- * - 插件系统:可扩展的插件机制
7
- * - 中间件:日志、持久化、时间旅行等
8
- * - 订阅发布:状态变化订阅、事件总线
9
- * - 批量更新:性能优化的批量状态更新
10
- * - 工具函数:深拷贝、选择器等
11
- *
12
- * @module @composy/store-core
13
- */
14
- export { BaseStore, batch, createAsyncAction, createBatchManager, createEventBus, createPubSub, createPubSubWithValue, createStore, getGlobalBatchManager, globalEventBus, setGlobalBatchManager, } from './core';
15
- export type { AsyncAction, AsyncActionOptions, AsyncActionState, CreateStoreDefinition, StoreAPI, } from './core';
16
- export * from './engine';
17
- export { DeserializationError, ErrorSeverity, errorUtils, InvalidStateError, MiddlewareError, PluginError, SerializationError, StorageError, StoreAlreadyExistsError, StoreDisposedError, StoreError, StoreErrorCode, StoreNotFoundError, SubscriptionError, TimeoutError, } from './errors';
18
- export type { StoreErrorContext, } from './errors';
19
- export { createLoggerMiddleware, createMiddlewareManager, createPersistMiddleware, createSimpleLoggerMiddleware, createTimeTravelMiddleware, createValidationMiddleware, getGlobalMiddlewareManager, restoreState, setGlobalMiddlewareManager, setRestoreCallback, } from './middleware';
20
- export type { StoreValidationRules, ValidationError, ValidationMiddlewareOptions, ValidationResult, ValidationRule, } from './middleware';
21
- export { composePlugins, createPluginFactory, createPluginManager, defineStorePlugin, getGlobalPluginManager, setGlobalPluginManager, } from './plugins';
22
- export type { ActionContext, ActionSubscriber, BatchContext, BatchManager, DefinePluginOptions, EventBus, EventData, EventListener, EventType, LoggerMiddlewareOptions, Middleware, MiddlewareActionType, MiddlewareContext, MiddlewareFunction, MiddlewareManager, PersistMiddlewareOptions, PersistOptions, PluginContext, PluginFactory, PluginManager, PubSub, Selector, SelectorOptions, StateMutation, StateSnapshot, StateSubscriber, StateTree, StorageAdapter, StoreAction, StoreActions, StoreDefinition, StoreGetter, StoreGetters, StoreId, StoreInstance, StoreManagerLike, StoreOptions, StorePlugin, SubscribeOptions, Subscriber, SubscriptionOptions, TimeTravelController, TimeTravelMiddlewareOptions, Unsubscribe, } from './types';
23
- export { combineSelectors, createCachedSelector, createMemoizedSelector, createSelector, createSelectorWithDeps, debounce, deepClone, deepEqual, deepFreeze, deepMerge, deepMergeWithOptions, deleteByPath, getByPath, hasPath, isObject, isPlainObject, setByPath, shallowClone, throttle, } from './utils';
24
- export declare const version = "1.0.0";
25
- export declare const name = "@composy/store-core";
26
- export type { DebouncedFunction, DeepCloneOptions, DeepMergeOptions, MemoizedSelectorOptions, SelectorEqualityFn, ThrottledFunction, } from './utils';
27
- //# sourceMappingURL=index.d.ts.map
@@ -1,13 +0,0 @@
1
- /**
2
- * 中间件模块导出
3
- *
4
- * 提供日志、持久化、时间旅行等中间件
5
- * @module middleware
6
- */
7
- export { createLoggerMiddleware, createProductionLoggerMiddleware, createSimpleLoggerMiddleware, } from './logger';
8
- export { createMiddlewareManager, getGlobalMiddlewareManager, setGlobalMiddlewareManager, } from './middleware-manager';
9
- export { createPersistMiddleware, restoreState, } from './persist';
10
- export { createTimeTravelMiddleware, setRestoreCallback, } from './time-travel';
11
- export { createValidationMiddleware, } from './validation';
12
- export type { StoreValidationRules, ValidationError, ValidationMiddlewareOptions, ValidationResult, ValidationRule, } from './validation';
13
- //# sourceMappingURL=index.d.ts.map
@@ -1,67 +0,0 @@
1
- /**
2
- * 日志中间件
3
- *
4
- * 提供状态变化和 Action 调用的日志记录,支持多种日志级别和格式化选项
5
- * @module middleware/logger
6
- */
7
- import type { LoggerMiddlewareOptions, Middleware, MiddlewareContext } from '../types';
8
- /**
9
- * 创建日志中间件
10
- *
11
- * 提供完整的状态变化和 Action 调用日志记录,支持时间戳、分组和性能计时
12
- *
13
- * @param options - 日志选项
14
- * @returns 日志中间件
15
- *
16
- * @example
17
- * ```typescript
18
- * const logger = createLoggerMiddleware({
19
- * logState: true,
20
- * collapsed: true,
21
- * timestamp: true,
22
- * filter: (context) => context.storeId !== 'internal'
23
- * })
24
- *
25
- * middlewareManager.use(logger)
26
- * ```
27
- */
28
- export declare function createLoggerMiddleware(options?: LoggerMiddlewareOptions): Middleware;
29
- /**
30
- * 简单日志中间件(不使用分组,适合生产环境)
31
- *
32
- * @param options - 配置选项
33
- * @param options.includePayload - 是否输出 payload
34
- * @param options.format - 自定义日志格式化函数
35
- * @param options.filter - 日志过滤器
36
- * @returns 简单日志中间件
37
- *
38
- * @example
39
- * ```typescript
40
- * const logger = createSimpleLoggerMiddleware({
41
- * includePayload: true,
42
- * format: (ctx) => `${ctx.storeId}: ${ctx.type}`
43
- * })
44
- * ```
45
- */
46
- export declare function createSimpleLoggerMiddleware(options?: {
47
- /** 是否包含 payload */
48
- includePayload?: boolean;
49
- /** 自定义格式化函数 */
50
- format?: (context: MiddlewareContext) => string;
51
- /** 过滤器 */
52
- filter?: (context: MiddlewareContext) => boolean;
53
- }): Middleware;
54
- /**
55
- * 创建生产环境日志中间件
56
- *
57
- * 只记录错误和警告,不记录正常状态变化
58
- *
59
- * @param options - 配置选项
60
- * @param options.onError - 自定义错误处理器
61
- * @returns 生产环境日志中间件
62
- */
63
- export declare function createProductionLoggerMiddleware(options?: {
64
- /** 自定义错误处理器 */
65
- onError?: (error: Error, context: MiddlewareContext) => void;
66
- }): Middleware;
67
- //# sourceMappingURL=logger.d.ts.map
@@ -1,40 +0,0 @@
1
- /**
2
- * 中间件管理器
3
- *
4
- * @module middleware/middleware-manager
5
- */
6
- import type { MiddlewareManager } from '../types';
7
- /**
8
- * 创建中间件管理器
9
- *
10
- * @returns 中间件管理器实例
11
- *
12
- * @example
13
- * ```typescript
14
- * const manager = createMiddlewareManager()
15
- *
16
- * // 添加日志中间件
17
- * manager.use({
18
- * name: 'logger',
19
- * priority: 1,
20
- * handler: async (ctx, next) => {
21
- * console.log('Before:', ctx.type)
22
- * await next()
23
- * console.log('After:', ctx.type)
24
- * }
25
- * })
26
- *
27
- * // 执行中间件链
28
- * await manager.execute({ storeId: 'test', state: {}, type: 'state:patch' })
29
- * ```
30
- */
31
- export declare function createMiddlewareManager(): MiddlewareManager;
32
- /**
33
- * 获取全局中间件管理器
34
- */
35
- export declare function getGlobalMiddlewareManager(): MiddlewareManager;
36
- /**
37
- * 设置全局中间件管理器
38
- */
39
- export declare function setGlobalMiddlewareManager(manager: MiddlewareManager): void;
40
- //# sourceMappingURL=middleware-manager.d.ts.map
@@ -1,35 +0,0 @@
1
- /**
2
- * 插件管理器
3
- *
4
- * @module plugins/plugin-manager
5
- */
6
- import type { PluginManager } from '../types';
7
- /**
8
- * 创建插件管理器
9
- *
10
- * @returns 插件管理器实例
11
- *
12
- * @example
13
- * ```typescript
14
- * const manager = createPluginManager()
15
- *
16
- * // 注册插件
17
- * manager.use(myPlugin, { option: 'value' })
18
- *
19
- * // 获取插件
20
- * const plugin = manager.get('my-plugin')
21
- *
22
- * // 移除插件
23
- * manager.remove('my-plugin')
24
- * ```
25
- */
26
- export declare function createPluginManager(): PluginManager;
27
- /**
28
- * 获取全局插件管理器
29
- */
30
- export declare function getGlobalPluginManager(): PluginManager;
31
- /**
32
- * 设置全局插件管理器
33
- */
34
- export declare function setGlobalPluginManager(manager: PluginManager): void;
35
- //# sourceMappingURL=plugin-manager.d.ts.map
@@ -1,172 +0,0 @@
1
- /**
2
- * 中间件系统类型定义
3
- *
4
- * @module types/middleware
5
- */
6
- import type { StateTree, StoreId } from './store';
7
- /**
8
- * 中间件上下文
9
- * @template S - 状态类型
10
- */
11
- export interface MiddlewareContext<S extends StateTree = StateTree> {
12
- /** Store ID */
13
- storeId: StoreId;
14
- /** 当前状态 */
15
- state: S;
16
- /** 操作类型 */
17
- type: MiddlewareActionType;
18
- /** 操作数据 */
19
- payload?: unknown;
20
- /** 元数据 */
21
- meta?: Record<string, unknown>;
22
- }
23
- /**
24
- * 中间件操作类型
25
- */
26
- export type MiddlewareActionType = 'state:init' | 'state:patch' | 'state:reset' | 'action:before' | 'action:after' | 'action:error';
27
- /**
28
- * 中间件函数类型
29
- * @template S - 状态类型
30
- */
31
- export type MiddlewareFunction<S extends StateTree = StateTree> = (context: MiddlewareContext<S>, next: () => void | Promise<void>) => void | Promise<void>;
32
- /**
33
- * 中间件接口
34
- * @template S - 状态类型
35
- */
36
- export interface Middleware<S extends StateTree = StateTree> {
37
- /** 中间件名称 */
38
- readonly name: string;
39
- /** 中间件优先级(数字越小越先执行) */
40
- readonly priority?: number;
41
- /** 中间件处理函数 */
42
- handler: MiddlewareFunction<S>;
43
- }
44
- /**
45
- * 中间件管理器接口
46
- */
47
- export interface MiddlewareManager {
48
- /**
49
- * 添加中间件
50
- * @param middleware - 中间件实例
51
- */
52
- use: (middleware: Middleware) => void;
53
- /**
54
- * 移除中间件
55
- * @param name - 中间件名称
56
- */
57
- remove: (name: string) => void;
58
- /**
59
- * 获取中间件
60
- * @param name - 中间件名称
61
- */
62
- get: (name: string) => Middleware | undefined;
63
- /**
64
- * 是否存在中间件
65
- * @param name - 中间件名称
66
- */
67
- has: (name: string) => boolean;
68
- /**
69
- * 执行中间件链
70
- * @param context - 上下文
71
- */
72
- execute: (context: MiddlewareContext) => Promise<void>;
73
- /**
74
- * 获取所有中间件
75
- */
76
- getAll: () => Middleware[];
77
- /**
78
- * 清空所有中间件
79
- */
80
- clear: () => void;
81
- }
82
- /**
83
- * 日志中间件选项
84
- */
85
- export interface LoggerMiddlewareOptions {
86
- /** 是否记录状态变化 */
87
- logState?: boolean;
88
- /** 是否记录 action */
89
- logAction?: boolean;
90
- /** 是否折叠日志 */
91
- collapsed?: boolean;
92
- /** 是否显示时间戳 */
93
- timestamp?: boolean;
94
- /** 日志级别 */
95
- level?: 'log' | 'info' | 'warn' | 'debug';
96
- /** 自定义日志器 */
97
- logger?: {
98
- log: (...args: unknown[]) => void;
99
- info: (...args: unknown[]) => void;
100
- warn: (...args: unknown[]) => void;
101
- debug: (...args: unknown[]) => void;
102
- error?: (...args: unknown[]) => void;
103
- group?: (...args: unknown[]) => void;
104
- groupCollapsed?: (...args: unknown[]) => void;
105
- groupEnd?: () => void;
106
- };
107
- /** 自定义过滤器 */
108
- filter?: (context: MiddlewareContext) => boolean;
109
- }
110
- /**
111
- * 持久化中间件选项
112
- */
113
- export interface PersistMiddlewareOptions {
114
- /** 存储键名前缀 */
115
- keyPrefix?: string;
116
- /** 存储类型 */
117
- storage?: 'localStorage' | 'sessionStorage';
118
- /** 要持久化的 Store ID 列表(空则全部持久化) */
119
- stores?: StoreId[];
120
- /** 要持久化的状态路径 */
121
- paths?: Record<StoreId, string[]>;
122
- /** 序列化函数 */
123
- serialize?: (value: unknown) => string;
124
- /** 反序列化函数 */
125
- deserialize?: (value: string) => unknown;
126
- /** 防抖延迟(毫秒) */
127
- debounce?: number;
128
- }
129
- /**
130
- * 时间旅行中间件选项
131
- */
132
- export interface TimeTravelMiddlewareOptions {
133
- /** 最大历史记录数 */
134
- maxHistory?: number;
135
- /** 是否启用 */
136
- enabled?: boolean;
137
- }
138
- /**
139
- * 时间旅行控制器
140
- */
141
- export interface TimeTravelController {
142
- /** 撤销 */
143
- undo: () => void;
144
- /** 重做 */
145
- redo: () => void;
146
- /** 跳转到指定历史 */
147
- goto: (index: number) => void;
148
- /** 获取历史记录 */
149
- getHistory: () => StateSnapshot[];
150
- /** 当前历史索引 */
151
- getCurrentIndex: () => number;
152
- /** 是否可撤销 */
153
- canUndo: () => boolean;
154
- /** 是否可重做 */
155
- canRedo: () => boolean;
156
- /** 清空历史 */
157
- clear: () => void;
158
- }
159
- /**
160
- * 状态快照
161
- */
162
- export interface StateSnapshot {
163
- /** 快照时间 */
164
- timestamp: number;
165
- /** 状态数据 */
166
- state: StateTree;
167
- /** 操作类型 */
168
- type: MiddlewareActionType;
169
- /** Store ID */
170
- storeId: StoreId;
171
- }
172
- //# sourceMappingURL=middleware.d.ts.map
@@ -1,136 +0,0 @@
1
- /**
2
- * 插件系统类型定义
3
- *
4
- * @module types/plugin
5
- */
6
- import type { StateTree, StoreId } from './store';
7
- /**
8
- * 插件上下文
9
- */
10
- export interface PluginContext {
11
- /** Store 管理器实例 */
12
- storeManager: StoreManagerLike;
13
- /** 当前 Store ID */
14
- storeId: StoreId;
15
- /** 当前 Store 实例 */
16
- store: unknown;
17
- /** 插件配置选项 */
18
- options: Record<string, unknown>;
19
- }
20
- /**
21
- * Store 管理器接口(简化版)
22
- */
23
- export interface StoreManagerLike {
24
- /** 获取 Store */
25
- getStore: (id: StoreId) => unknown;
26
- /** 是否存在 Store */
27
- hasStore: (id: StoreId) => boolean;
28
- /** 获取所有 Store ID */
29
- getStoreIds: () => StoreId[];
30
- }
31
- /**
32
- * 插件接口
33
- * @template Options - 插件选项类型
34
- */
35
- export interface StorePlugin<Options = Record<string, unknown>> {
36
- /** 插件名称 */
37
- readonly name: string;
38
- /** 插件版本 */
39
- readonly version?: string;
40
- /** 插件描述 */
41
- readonly description?: string;
42
- /**
43
- * 安装插件
44
- * @param context - 插件上下文
45
- * @param options - 插件选项
46
- */
47
- install: (context: PluginContext, options?: Options) => void | Promise<void>;
48
- /**
49
- * 卸载插件
50
- * @param context - 插件上下文
51
- */
52
- uninstall?: (context: PluginContext) => void | Promise<void>;
53
- /**
54
- * Store 创建时的钩子
55
- * @param store - Store 实例
56
- */
57
- onStoreCreated?: (store: unknown) => void;
58
- /**
59
- * Store 销毁时的钩子
60
- * @param store - Store 实例
61
- */
62
- onStoreDisposed?: (store: unknown) => void;
63
- /**
64
- * 状态变化时的钩子
65
- * @param storeId - Store ID
66
- * @param state - 新状态
67
- * @param oldState - 旧状态
68
- */
69
- onStateChange?: <S extends StateTree>(storeId: StoreId, state: S, oldState: S) => void;
70
- }
71
- /**
72
- * 插件工厂函数类型
73
- * @template Options - 插件选项类型
74
- */
75
- export type PluginFactory<Options = Record<string, unknown>> = (options?: Options) => StorePlugin<Options>;
76
- /**
77
- * 定义插件选项
78
- * @template Options - 插件选项类型
79
- */
80
- export interface DefinePluginOptions<Options = Record<string, unknown>> {
81
- /** 插件名称 */
82
- name: string;
83
- /** 插件版本 */
84
- version?: string;
85
- /** 插件描述 */
86
- description?: string;
87
- /** 安装函数 */
88
- install: StorePlugin<Options>['install'];
89
- /** 卸载函数 */
90
- uninstall?: StorePlugin<Options>['uninstall'];
91
- /** Store 创建钩子 */
92
- onStoreCreated?: StorePlugin<Options>['onStoreCreated'];
93
- /** Store 销毁钩子 */
94
- onStoreDisposed?: StorePlugin<Options>['onStoreDisposed'];
95
- /** 状态变化钩子 */
96
- onStateChange?: StorePlugin<Options>['onStateChange'];
97
- }
98
- /**
99
- * 插件管理器接口
100
- */
101
- export interface PluginManager {
102
- /**
103
- * 注册插件
104
- * @param plugin - 插件实例
105
- * @param options - 插件选项
106
- */
107
- use: <Options>(plugin: StorePlugin<Options>, options?: Options) => void;
108
- /**
109
- * 移除插件
110
- * @param name - 插件名称
111
- */
112
- remove: (name: string) => void;
113
- /**
114
- * 获取插件
115
- * @param name - 插件名称
116
- */
117
- get: (name: string) => StorePlugin | undefined;
118
- /**
119
- * 是否已注册插件
120
- * @param name - 插件名称
121
- */
122
- has: (name: string) => boolean;
123
- /**
124
- * 获取所有插件
125
- */
126
- getAll: () => Map<string, StorePlugin>;
127
- /**
128
- * 获取插件数量
129
- */
130
- size: () => number;
131
- /**
132
- * 清空所有插件
133
- */
134
- clear: () => void;
135
- }
136
- //# sourceMappingURL=plugin.d.ts.map