@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,143 +0,0 @@
1
- /**
2
- * 深拷贝工具
3
- *
4
- * 提供高性能的深拷贝、浅拷贝和深度合并功能
5
- * @module utils/deep-clone
6
- */
7
- /**
8
- * 判断是否为对象
9
- *
10
- * @param value - 待检查的值
11
- * @returns 是否为对象
12
- */
13
- export declare function isObject(value: unknown): value is Record<string, unknown>;
14
- /**
15
- * 判断是否为普通对象(非数组、非内置对象)
16
- *
17
- * @param value - 待检查的值
18
- * @returns 是否为普通对象
19
- */
20
- export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
21
- /**
22
- * 深拷贝配置选项
23
- */
24
- export interface DeepCloneOptions {
25
- /** 是否优先使用 structuredClone(默认 true) */
26
- useStructuredClone?: boolean;
27
- /** 是否克隆函数(默认 false,函数保持引用) */
28
- cloneFunctions?: boolean;
29
- /** 是否克隆 Symbol 属性(默认 false) */
30
- cloneSymbols?: boolean;
31
- /** 最大深度(默认无限制) */
32
- maxDepth?: number;
33
- /** 自定义克隆器 */
34
- customCloner?: <T>(value: T, clone: <U>(v: U) => U) => T | undefined;
35
- }
36
- /**
37
- * 深拷贝
38
- *
39
- * 高性能深拷贝实现,优先使用原生 structuredClone(如果可用)
40
- *
41
- * @template T - 值类型
42
- * @param value - 要拷贝的值
43
- * @param options - 配置选项
44
- * @returns 拷贝后的值
45
- *
46
- * @example
47
- * ```typescript
48
- * const obj = { a: 1, b: { c: 2 } }
49
- * const cloned = deepClone(obj)
50
- * cloned.b.c = 3
51
- * console.log(obj.b.c) // 2
52
- * ```
53
- *
54
- * @example
55
- * ```typescript
56
- * // 带配置的深拷贝
57
- * const cloned = deepClone(obj, {
58
- * maxDepth: 5,
59
- * cloneSymbols: true
60
- * })
61
- * ```
62
- */
63
- export declare function deepClone<T>(value: T, options?: DeepCloneOptions): T;
64
- /**
65
- * 浅拷贝
66
- *
67
- * @template T - 值类型
68
- * @param value - 要拷贝的值
69
- * @returns 拷贝后的值
70
- *
71
- * @example
72
- * ```typescript
73
- * const arr = [1, 2, { a: 3 }]
74
- * const cloned = shallowClone(arr)
75
- * cloned[2].a = 4
76
- * console.log(arr[2].a) // 4 (浅拷贝,嵌套对象共享引用)
77
- * ```
78
- */
79
- export declare function shallowClone<T>(value: T): T;
80
- /**
81
- * 深度合并配置选项
82
- */
83
- export interface DeepMergeOptions {
84
- /** 数组合并策略:'replace' 替换 | 'concat' 连接 | 'merge' 按索引合并 */
85
- arrayStrategy?: 'replace' | 'concat' | 'merge';
86
- /** 是否克隆源对象(默认 true) */
87
- clone?: boolean;
88
- /** 最大深度 */
89
- maxDepth?: number;
90
- }
91
- /**
92
- * 深度合并对象
93
- *
94
- * 将多个源对象深度合并到目标对象
95
- *
96
- * @template T - 目标对象类型
97
- * @param target - 目标对象
98
- * @param sources - 源对象列表
99
- * @returns 合并后的对象
100
- *
101
- * @example
102
- * ```typescript
103
- * const target = { a: 1, b: { c: 2 } }
104
- * const source = { b: { d: 3 }, e: 4 }
105
- * const result = deepMerge(target, source)
106
- * // { a: 1, b: { c: 2, d: 3 }, e: 4 }
107
- * ```
108
- */
109
- export declare function deepMerge<T extends Record<string, unknown>>(target: T, ...sources: Array<Partial<T>>): T;
110
- /**
111
- * 带配置的深度合并
112
- *
113
- * @template T - 目标对象类型
114
- * @param target - 目标对象
115
- * @param options - 合并配置
116
- * @param sources - 源对象列表
117
- * @returns 合并后的对象
118
- */
119
- export declare function deepMergeWithOptions<T extends Record<string, unknown>>(target: T, options: DeepMergeOptions, ...sources: Array<Partial<T>>): T;
120
- /**
121
- * 比较两个值是否深度相等
122
- *
123
- * @param a - 第一个值
124
- * @param b - 第二个值
125
- * @returns 是否相等
126
- *
127
- * @example
128
- * ```typescript
129
- * deepEqual({ a: 1 }, { a: 1 }) // true
130
- * deepEqual([1, 2], [1, 2]) // true
131
- * deepEqual({ a: { b: 1 } }, { a: { b: 2 } }) // false
132
- * ```
133
- */
134
- export declare function deepEqual(a: unknown, b: unknown): boolean;
135
- /**
136
- * 冻结对象(深度)
137
- *
138
- * @template T - 对象类型
139
- * @param obj - 要冻结的对象
140
- * @returns 冻结后的对象
141
- */
142
- export declare function deepFreeze<T extends object>(obj: T): Readonly<T>;
143
- //# sourceMappingURL=deep-clone.d.ts.map
@@ -1,13 +0,0 @@
1
- /**
2
- * 工具函数模块
3
- *
4
- * 提供深拷贝、选择器、路径操作等工具函数
5
- * @module utils
6
- */
7
- export { debounce, throttle, } from './debounce-throttle';
8
- export type { DebouncedFunction, ThrottledFunction, } from './debounce-throttle';
9
- export { deepClone, deepEqual, deepFreeze, deepMerge, deepMergeWithOptions, isObject, isPlainObject, shallowClone, } from './deep-clone';
10
- export type { DeepCloneOptions, DeepMergeOptions, } from './deep-clone';
11
- export { combineSelectors, createCachedSelector, createMemoizedSelector, createSelector, createSelectorWithDeps, deleteByPath, getByPath, hasPath, setByPath, } from './selector';
12
- export type { MemoizedSelectorOptions, SelectorEqualityFn, } from './selector';
13
- //# sourceMappingURL=index.d.ts.map
@@ -1,213 +0,0 @@
1
- /**
2
- * 状态选择器工具
3
- *
4
- * 提供高性能的状态选择器和路径操作工具
5
- * @module utils/selector
6
- */
7
- import type { Selector, StateTree } from '../types';
8
- /**
9
- * 选择器相等性比较函数类型
10
- */
11
- export type SelectorEqualityFn<R> = (a: R, b: R) => boolean;
12
- /**
13
- * 记忆化选择器配置选项
14
- */
15
- export interface MemoizedSelectorOptions<R> {
16
- /** 相等性比较函数 */
17
- equalityFn?: SelectorEqualityFn<R>;
18
- /** 最大缓存大小(默认 1) */
19
- maxSize?: number;
20
- /** 是否在开发模式下记录缓存命中率 */
21
- trackHitRate?: boolean;
22
- }
23
- /**
24
- * 创建记忆化选择器
25
- *
26
- * 基本的记忆化选择器,只缓存最后一次结果
27
- *
28
- * @template S - 状态类型
29
- * @template R - 返回值类型
30
- * @param selector - 选择器函数
31
- * @param equalityFn - 相等性比较函数(默认使用 Object.is)
32
- * @returns 记忆化的选择器
33
- *
34
- * @example
35
- * ```typescript
36
- * const selectTodos = createSelector(
37
- * (state: AppState) => state.todos,
38
- * )
39
- *
40
- * const selectCompletedTodos = createSelector(
41
- * (state: AppState) => state.todos.filter(t => t.completed),
42
- * (a, b) => a.length === b.length && a.every((v, i) => v === b[i])
43
- * )
44
- * ```
45
- */
46
- export declare function createSelector<S extends StateTree, R>(selector: Selector<S, R>, equalityFn?: SelectorEqualityFn<R>): Selector<S, R>;
47
- /**
48
- * 创建带依赖的选择器
49
- *
50
- * 类似 reselect 的实现,支持多个输入选择器
51
- *
52
- * @template S - 状态类型
53
- * @template Deps - 依赖结果类型
54
- * @template R - 返回值类型
55
- * @param dependencies - 依赖选择器数组
56
- * @param combiner - 组合函数
57
- * @param options - 配置选项
58
- * @returns 记忆化的选择器
59
- *
60
- * @example
61
- * ```typescript
62
- * const selectVisibleTodos = createSelectorWithDeps(
63
- * [
64
- * (state) => state.todos,
65
- * (state) => state.visibilityFilter,
66
- * ],
67
- * (todos, filter) => {
68
- * switch (filter) {
69
- * case 'SHOW_COMPLETED': return todos.filter(t => t.completed)
70
- * case 'SHOW_ACTIVE': return todos.filter(t => !t.completed)
71
- * default: return todos
72
- * }
73
- * }
74
- * )
75
- * ```
76
- */
77
- export declare function createSelectorWithDeps<S extends StateTree, Deps extends unknown[], R>(dependencies: {
78
- [K in keyof Deps]: Selector<S, Deps[K]>;
79
- }, combiner: (...args: Deps) => R, options?: MemoizedSelectorOptions<R>): Selector<S, R>;
80
- /**
81
- * 组合多个选择器
82
- *
83
- * 简单的选择器组合,不带记忆化
84
- *
85
- * @template S - 状态类型
86
- * @template R - 结果类型数组
87
- * @template C - 组合结果类型
88
- * @param selectors - 选择器数组
89
- * @param combiner - 组合函数
90
- * @returns 组合后的选择器
91
- *
92
- * @example
93
- * ```typescript
94
- * const selectUserAndTodos = combineSelectors(
95
- * [
96
- * (state) => state.user,
97
- * (state) => state.todos,
98
- * ],
99
- * (user, todos) => ({ user, todos })
100
- * )
101
- * ```
102
- */
103
- export declare function combineSelectors<S extends StateTree, R extends unknown[], C>(selectors: {
104
- [K in keyof R]: Selector<S, R[K]>;
105
- }, combiner: (...results: R) => C): Selector<S, C>;
106
- /**
107
- * 创建带高级缓存的选择器
108
- *
109
- * 支持多个缓存条目,使用 LRU 策略
110
- *
111
- * @template S - 状态类型
112
- * @template R - 返回值类型
113
- * @param selector - 选择器函数
114
- * @param options - 配置选项
115
- * @returns 带缓存的选择器
116
- *
117
- * @example
118
- * ```typescript
119
- * const selectFilteredItems = createCachedSelector(
120
- * (state, filter) => state.items.filter(item => item.type === filter),
121
- * { maxSize: 5 }
122
- * )
123
- * ```
124
- */
125
- export declare function createCachedSelector<S extends StateTree, R>(selector: Selector<S, R>, options?: MemoizedSelectorOptions<R>): Selector<S, R> & {
126
- clearCache: () => void;
127
- getCacheSize: () => number;
128
- };
129
- /**
130
- * 创建记忆化选择器(别名,同 createSelector)
131
- *
132
- * @template S - 状态类型
133
- * @template R - 返回值类型
134
- * @param selector - 选择器函数
135
- * @param options - 配置选项
136
- * @returns 记忆化的选择器
137
- */
138
- export declare function createMemoizedSelector<S extends StateTree, R>(selector: Selector<S, R>, options?: MemoizedSelectorOptions<R>): Selector<S, R>;
139
- /**
140
- * 获取嵌套对象的值
141
- *
142
- * 支持点表示法和数组索引
143
- *
144
- * @template T - 返回值类型
145
- * @param obj - 对象
146
- * @param path - 路径(支持 'a.b.c' 或 'a[0].b')
147
- * @param defaultValue - 默认值(当路径不存在时返回)
148
- * @returns 值
149
- *
150
- * @example
151
- * ```typescript
152
- * const value = getByPath({ a: { b: { c: 1 } } }, 'a.b.c')
153
- * // value: 1
154
- *
155
- * const arr = getByPath({ items: [{ name: 'test' }] }, 'items[0].name')
156
- * // arr: 'test'
157
- *
158
- * const missing = getByPath({ a: 1 }, 'b.c', 'default')
159
- * // missing: 'default'
160
- * ```
161
- */
162
- export declare function getByPath<T = unknown>(obj: unknown, path: string, defaultValue?: T): T | undefined;
163
- /**
164
- * 设置嵌套对象的值
165
- *
166
- * 支持自动创建中间路径
167
- *
168
- * @param obj - 对象
169
- * @param path - 路径
170
- * @param value - 值
171
- * @returns 是否成功
172
- *
173
- * @example
174
- * ```typescript
175
- * const obj = {}
176
- * setByPath(obj, 'a.b.c', 1)
177
- * // obj: { a: { b: { c: 1 } } }
178
- *
179
- * setByPath(obj, 'items[0].name', 'test')
180
- * // obj: { a: { b: { c: 1 } }, items: [{ name: 'test' }] }
181
- * ```
182
- */
183
- export declare function setByPath(obj: Record<string, unknown>, path: string, value: unknown): boolean;
184
- /**
185
- * 删除嵌套对象的值
186
- *
187
- * @param obj - 对象
188
- * @param path - 路径
189
- * @returns 是否成功删除
190
- *
191
- * @example
192
- * ```typescript
193
- * const obj = { a: { b: { c: 1 } } }
194
- * deleteByPath(obj, 'a.b.c')
195
- * // obj: { a: { b: {} } }
196
- * ```
197
- */
198
- export declare function deleteByPath(obj: Record<string, unknown>, path: string): boolean;
199
- /**
200
- * 检查嵌套对象中是否存在指定路径
201
- *
202
- * @param obj - 对象
203
- * @param path - 路径
204
- * @returns 是否存在
205
- *
206
- * @example
207
- * ```typescript
208
- * hasPath({ a: { b: 1 } }, 'a.b') // true
209
- * hasPath({ a: { b: 1 } }, 'a.c') // false
210
- * ```
211
- */
212
- export declare function hasPath(obj: unknown, path: string): boolean;
213
- //# sourceMappingURL=selector.d.ts.map
@@ -1,95 +0,0 @@
1
- /**
2
- * 异步 Action 工具
3
- *
4
- * 提供框架无关的异步操作状态管理
5
- * @module core/async-action
6
- */
7
- import type { Unsubscribe } from '../types';
8
- /**
9
- * 异步 Action 配置
10
- */
11
- export interface AsyncActionOptions {
12
- /** 重试次数 (默认 0) */
13
- retryCount?: number;
14
- /** 重试间隔 (毫秒, 默认 1000) */
15
- retryDelay?: number;
16
- /** 超时时间 (毫秒, 0=不限) */
17
- timeout?: number;
18
- /** 执行前是否自动清除上次错误 */
19
- resetOnExecute?: boolean;
20
- }
21
- /**
22
- * 异步 Action 状态
23
- */
24
- export interface AsyncActionState<T> {
25
- /** 返回数据 */
26
- data: T | null;
27
- /** 错误信息 */
28
- error: Error | null;
29
- /** 是否加载中 */
30
- loading: boolean;
31
- /** 执行次数 */
32
- executionCount: number;
33
- /** 最后执行时间 */
34
- lastExecutedAt: number | null;
35
- }
36
- /**
37
- * 异步 Action 实例
38
- */
39
- export interface AsyncAction<T, Args extends unknown[]> {
40
- /** 当前状态 */
41
- readonly state: AsyncActionState<T>;
42
- /** 执行异步操作 */
43
- execute: (...args: Args) => Promise<T>;
44
- /** 重置状态 */
45
- reset: () => void;
46
- /** 取消当前执行 */
47
- abort: () => void;
48
- /** 订阅状态变化 */
49
- subscribe: (callback: (state: AsyncActionState<T>) => void) => Unsubscribe;
50
- /** 设置成功回调 */
51
- onSuccess: (callback: (data: T) => void) => Unsubscribe;
52
- /** 设置错误回调 */
53
- onError: (callback: (error: Error) => void) => Unsubscribe;
54
- }
55
- /**
56
- * 创建异步 Action
57
- *
58
- * 将异步函数包装为带状态追踪的 Action,自动管理 loading/data/error 状态
59
- *
60
- * @template T - 返回数据类型
61
- * @template Args - 参数类型
62
- * @param fn - 异步函数
63
- * @param options - 配置选项
64
- * @returns AsyncAction 实例
65
- *
66
- * @example
67
- * ```typescript
68
- * // 基本用法
69
- * const fetchUsers = createAsyncAction(async (page: number) => {
70
- * const res = await fetch(`/api/users?page=${page}`)
71
- * return res.json()
72
- * })
73
- *
74
- * await fetchUsers.execute(1)
75
- * console.log(fetchUsers.state.data) // 用户列表
76
- * console.log(fetchUsers.state.loading) // false
77
- *
78
- * // 带重试
79
- * const fetchWithRetry = createAsyncAction(
80
- * async () => fetch('/api/unstable').then(r => r.json()),
81
- * { retryCount: 3, retryDelay: 1000 }
82
- * )
83
- *
84
- * // 订阅状态变化
85
- * fetchUsers.subscribe((state) => {
86
- * console.log('loading:', state.loading, 'data:', state.data)
87
- * })
88
- *
89
- * // 成功/错误回调
90
- * fetchUsers.onSuccess((data) => console.log('Got:', data))
91
- * fetchUsers.onError((err) => console.error('Failed:', err))
92
- * ```
93
- */
94
- export declare function createAsyncAction<T, Args extends unknown[] = []>(fn: (...args: Args) => Promise<T>, options?: AsyncActionOptions): AsyncAction<T, Args>;
95
- //# sourceMappingURL=async-action.d.ts.map
@@ -1,85 +0,0 @@
1
- /**
2
- * 基础 Store 抽象类
3
- *
4
- * 提供框架无关的 Store 基础实现
5
- * @module core/base-store
6
- */
7
- import type { ActionContext, ActionSubscriber, StateMutation, StateSubscriber, StateTree, StoreActions, StoreDefinition, StoreGetters, StoreId, StoreInstance, StoreOptions, SubscribeOptions, Unsubscribe } from '../types';
8
- /**
9
- * 基础 Store 类
10
- *
11
- * @template Id - Store ID 类型
12
- * @template S - 状态类型
13
- * @template G - Getters 类型
14
- * @template A - Actions 类型
15
- */
16
- export declare class BaseStore<Id extends StoreId = StoreId, S extends StateTree = StateTree, G extends StoreGetters<S> = StoreGetters<S>, A extends StoreActions = StoreActions> implements StoreInstance<Id, S, G, A> {
17
- /** Store ID */
18
- readonly $id: Id;
19
- /** Getter 计算结果 */
20
- readonly getters: {
21
- [K in keyof G]: ReturnType<G[K]>;
22
- };
23
- /** Action 方法集合 */
24
- readonly actions: A;
25
- /** 状态订阅管理器 */
26
- private stateSubscribers;
27
- /** Action 订阅管理器 */
28
- private actionSubscribers;
29
- /** 初始状态工厂 */
30
- private initialStateFactory;
31
- /** 当前状态 */
32
- private _state;
33
- /** 是否已销毁 */
34
- private disposed;
35
- /**
36
- * 构造函数
37
- *
38
- * @param definition - Store 定义
39
- * @param _options - Store 配置选项
40
- */
41
- constructor(definition: StoreDefinition<Id, S, G, A>, _options?: StoreOptions);
42
- /**
43
- * 获取当前状态
44
- */
45
- get $state(): S;
46
- /**
47
- * 设置状态
48
- */
49
- set $state(newState: S);
50
- /**
51
- * 重置状态到初始值
52
- */
53
- $reset(): void;
54
- /**
55
- * 批量更新状态
56
- */
57
- $patch(partialState: Partial<S> | ((state: S) => void)): void;
58
- /**
59
- * 订阅状态变化
60
- */
61
- $subscribe(callback: StateSubscriber<S>, options?: SubscribeOptions): Unsubscribe;
62
- /**
63
- * 订阅 Action 调用
64
- */
65
- $onAction(callback: ActionSubscriber<A>): Unsubscribe;
66
- /**
67
- * 销毁 Store
68
- */
69
- $dispose(): void;
70
- /**
71
- * 通知状态变化
72
- */
73
- protected notifyStateChange(mutation: StateMutation<S>): void;
74
- /**
75
- * 通知 Action 调用
76
- */
77
- protected notifyAction(context: ActionContext<A>): void;
78
- /**
79
- * 检查是否已销毁
80
- */
81
- private checkDisposed;
82
- private createGetters;
83
- private createActions;
84
- }
85
- //# sourceMappingURL=base-store.d.ts.map
@@ -1,46 +0,0 @@
1
- /**
2
- * 批量更新管理器
3
- *
4
- * 用于优化多个状态更新的性能
5
- * @module core/batch-manager
6
- */
7
- import type { BatchManager, StoreId } from '../types';
8
- /**
9
- * 创建批量更新管理器
10
- *
11
- * @param onFlush - 刷新回调,接收所有待更新的 Store ID
12
- * @returns 批量更新管理器实例
13
- *
14
- * @example
15
- * ```typescript
16
- * const batchManager = createBatchManager((storeIds) => {
17
- * storeIds.forEach(id => {
18
- * // 通知订阅者更新
19
- * notifySubscribers(id)
20
- * })
21
- * })
22
- *
23
- * // 批量更新
24
- * batchManager.batch(() => {
25
- * store1.count++
26
- * store2.name = 'new name'
27
- * })
28
- * ```
29
- */
30
- export declare function createBatchManager(onFlush?: (storeIds: Set<StoreId>) => void): BatchManager;
31
- /**
32
- * 获取全局批量更新管理器
33
- */
34
- export declare function getGlobalBatchManager(): BatchManager;
35
- /**
36
- * 设置全局批量更新管理器
37
- */
38
- export declare function setGlobalBatchManager(manager: BatchManager): void;
39
- /**
40
- * 批量更新辅助函数
41
- *
42
- * @param fn - 执行函数
43
- * @returns 执行结果
44
- */
45
- export declare function batch<T>(fn: () => T): T;
46
- //# sourceMappingURL=batch-manager.d.ts.map
@@ -1,14 +0,0 @@
1
- /**
2
- * 核心模块导出
3
- *
4
- * @module core
5
- */
6
- export { createAsyncAction } from './async-action';
7
- export type { AsyncAction, AsyncActionOptions, AsyncActionState } from './async-action';
8
- export { BaseStore } from './base-store';
9
- export { batch, createBatchManager, getGlobalBatchManager, setGlobalBatchManager, } from './batch-manager';
10
- export { createStore } from './create-store';
11
- export type { CreateStoreDefinition, StoreAPI } from './create-store';
12
- export { createEventBus, globalEventBus } from './event-bus';
13
- export { createPubSub, createPubSubWithValue } from './pub-sub';
14
- //# sourceMappingURL=index.d.ts.map
@@ -1,10 +0,0 @@
1
- /**
2
- * @module store/engine
3
- *
4
- * Store 引擎桥接层的统一导出,提供将 Store 能力集成到 LDesign Engine 的工厂函数、
5
- * 事件键和状态键。包含引擎 API、容器、事件总线等兼容接口类型,
6
- * 供 Vue/React 等适配层复用。
7
- */
8
- export { createStoreEngineBridge, storeEventKeys, storeStateKeys, } from './plugin';
9
- export type { StoreEngineApi, StoreEngineApiLike, StoreEngineBridge, StoreEngineBridgeOptions, StoreEngineContainerLike, StoreEngineEventsLike, StoreEngineLike, StoreEngineLoggerLike, StoreEnginePluginContextLike, StoreEnginePluginOptions, StoreEngineRegisteredApi, StoreEngineStateLike, StoreRuntimeLike, } from './types';
10
- //# sourceMappingURL=index.d.ts.map
@@ -1,20 +0,0 @@
1
- /**
2
- * @composy/store-core Engine 桥接能力
3
- *
4
- * Core 负责 engine 生命周期、state/API 同步和事件派发;框架适配层只提供 runtime 创建与 App 挂载。
5
- * @module engine/plugin
6
- */
7
- import type { StoreEngineBridge, StoreEngineBridgeOptions, StoreRuntimeLike } from './types';
8
- export declare const storeStateKeys: {
9
- readonly BUS: "store:bus";
10
- readonly PINIA: "store:pinia";
11
- readonly API: "store:api";
12
- readonly REGISTRY: "store:registry";
13
- readonly RUNTIME: "store:runtime";
14
- };
15
- export declare const storeEventKeys: {
16
- readonly INSTALLED: "store:installed";
17
- readonly UNINSTALLED: "store:uninstalled";
18
- };
19
- export declare function createStoreEngineBridge<Runtime extends StoreRuntimeLike>(options: StoreEngineBridgeOptions<Runtime>): StoreEngineBridge;
20
- //# sourceMappingURL=plugin.d.ts.map
@@ -1,34 +0,0 @@
1
- /**
2
- * 持久化中间件
3
- *
4
- * 提供状态持久化功能
5
- * @module middleware/persist
6
- */
7
- import type { Middleware, PersistMiddlewareOptions, StateTree, StoreId } from '../types';
8
- /**
9
- * 创建持久化中间件
10
- *
11
- * @param options - 持久化选项
12
- * @returns 持久化中间件
13
- *
14
- * @example
15
- * ```typescript
16
- * const persist = createPersistMiddleware({
17
- * storage: 'localStorage',
18
- * stores: ['user', 'settings'],
19
- * debounce: 200,
20
- * })
21
- *
22
- * middlewareManager.use(persist)
23
- * ```
24
- */
25
- export declare function createPersistMiddleware(options?: PersistMiddlewareOptions): Middleware;
26
- /**
27
- * 从存储恢复状态
28
- *
29
- * @param storeId - Store ID
30
- * @param options - 持久化选项
31
- * @returns 恢复的状态或 null
32
- */
33
- export declare function restoreState<S extends StateTree>(storeId: StoreId, options?: PersistMiddlewareOptions): S | null;
34
- //# sourceMappingURL=persist.d.ts.map