@fozy-labs/rx-toolkit 0.5.4 → 0.6.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 (303) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +22 -13
  3. package/dist/common/devtools/reduxDevtools.js +17 -2
  4. package/dist/common/react/index.d.ts +1 -0
  5. package/dist/common/react/index.js +1 -0
  6. package/dist/common/react/useIsomorphicLayoutEffect.d.ts +17 -0
  7. package/dist/common/react/useIsomorphicLayoutEffect.js +17 -0
  8. package/dist/index.d.ts +1 -2
  9. package/dist/index.js +1 -2
  10. package/dist/query/api/createApi.d.ts +4 -0
  11. package/dist/query/api/createApi.js +9 -0
  12. package/dist/query/api/index.d.ts +1 -0
  13. package/dist/query/api/index.js +1 -0
  14. package/dist/query/constants.d.ts +12 -0
  15. package/dist/query/constants.js +15 -0
  16. package/dist/query/core/api/Api.d.ts +20 -0
  17. package/dist/query/core/api/Api.js +129 -0
  18. package/dist/query/core/api/constants.d.ts +2 -0
  19. package/dist/query/core/api/constants.js +3 -0
  20. package/dist/query/core/api/index.d.ts +3 -0
  21. package/dist/query/core/api/index.js +3 -0
  22. package/dist/query/core/api/mergeHooks.d.ts +2 -0
  23. package/dist/query/core/api/mergeHooks.js +26 -0
  24. package/dist/query/core/api/normalizeLinks.d.ts +2 -0
  25. package/dist/query/core/api/normalizeLinks.js +11 -0
  26. package/dist/query/core/cache/CacheEntry.d.ts +21 -0
  27. package/dist/query/core/cache/CacheEntry.js +54 -0
  28. package/dist/query/core/cache/CacheMap.d.ts +19 -0
  29. package/dist/query/core/cache/CacheMap.js +32 -0
  30. package/dist/query/core/cache/QueryCacheEntry.d.ts +21 -0
  31. package/dist/query/core/cache/QueryCacheEntry.js +136 -0
  32. package/dist/query/core/cache/index.d.ts +3 -0
  33. package/dist/query/core/cache/index.js +3 -0
  34. package/dist/query/core/command/Command.d.ts +67 -0
  35. package/dist/query/core/command/Command.js +253 -0
  36. package/dist/query/core/command/CommandAgent.d.ts +17 -0
  37. package/dist/query/core/command/CommandAgent.js +67 -0
  38. package/dist/query/core/command/LinkManager.d.ts +24 -0
  39. package/dist/query/core/command/LinkManager.js +71 -0
  40. package/dist/query/core/command/index.d.ts +2 -0
  41. package/dist/query/core/command/index.js +2 -0
  42. package/dist/query/core/errors/CacheEntryRemovedError.d.ts +7 -0
  43. package/dist/query/core/errors/CacheEntryRemovedError.js +9 -0
  44. package/dist/query/core/errors/MachineStateError.d.ts +8 -0
  45. package/dist/query/core/errors/MachineStateError.js +10 -0
  46. package/dist/query/core/errors/MachineTransitionError.d.ts +7 -0
  47. package/dist/query/core/errors/MachineTransitionError.js +9 -0
  48. package/dist/query/core/errors/index.d.ts +3 -0
  49. package/dist/query/core/errors/index.js +3 -0
  50. package/dist/query/core/index.d.ts +8 -0
  51. package/dist/query/core/index.js +8 -0
  52. package/dist/query/core/machine/Machine.d.ts +21 -0
  53. package/dist/query/core/machine/Machine.js +42 -0
  54. package/dist/query/core/machine/MachineBase.d.ts +31 -0
  55. package/dist/query/core/machine/MachineBase.js +176 -0
  56. package/dist/query/core/machine/MachineError.d.ts +10 -0
  57. package/dist/query/core/machine/MachineError.js +19 -0
  58. package/dist/query/core/machine/MachinePending.d.ts +13 -0
  59. package/dist/query/core/machine/MachinePending.js +32 -0
  60. package/dist/query/core/machine/MachineRefreshError.d.ts +12 -0
  61. package/dist/query/core/machine/MachineRefreshError.js +23 -0
  62. package/dist/query/core/machine/MachineRefreshing.d.ts +15 -0
  63. package/dist/query/core/machine/MachineRefreshing.js +43 -0
  64. package/dist/query/core/machine/MachineSuccess.d.ts +12 -0
  65. package/dist/query/core/machine/MachineSuccess.js +23 -0
  66. package/dist/query/core/machine/MachineWithData.d.ts +25 -0
  67. package/dist/query/core/machine/MachineWithData.js +73 -0
  68. package/dist/query/core/machine/index.d.ts +9 -0
  69. package/dist/query/core/machine/index.js +9 -0
  70. package/dist/query/core/machine/machine-helpers.d.ts +9 -0
  71. package/dist/query/core/machine/machine-helpers.js +80 -0
  72. package/dist/query/core/patcher/Patcher.d.ts +30 -0
  73. package/dist/query/core/patcher/Patcher.js +122 -0
  74. package/dist/query/core/patcher/index.d.ts +1 -0
  75. package/dist/query/core/patcher/index.js +1 -0
  76. package/dist/query/core/resource/Resource.d.ts +105 -0
  77. package/dist/query/core/resource/Resource.js +340 -0
  78. package/dist/query/core/resource/ResourceAgent.d.ts +37 -0
  79. package/dist/query/core/resource/ResourceAgent.js +179 -0
  80. package/dist/query/core/resource/index.d.ts +2 -0
  81. package/dist/query/core/resource/index.js +2 -0
  82. package/dist/query/core/snapshoter/Snapshoter.d.ts +22 -0
  83. package/dist/query/core/snapshoter/Snapshoter.js +78 -0
  84. package/dist/query/core/snapshoter/index.d.ts +2 -0
  85. package/dist/query/core/snapshoter/index.js +1 -0
  86. package/dist/query/core/syncer/Syncer.d.ts +32 -0
  87. package/dist/query/core/syncer/Syncer.js +85 -0
  88. package/dist/query/core/syncer/index.d.ts +2 -0
  89. package/dist/query/core/syncer/index.js +1 -0
  90. package/dist/query/index.d.ts +5 -10
  91. package/dist/query/index.js +5 -13
  92. package/dist/query/lib/broadcastSyncDriver.d.ts +5 -0
  93. package/dist/query/lib/broadcastSyncDriver.js +46 -0
  94. package/dist/query/lib/index.d.ts +3 -0
  95. package/dist/query/lib/index.js +3 -0
  96. package/dist/{query-v2 → query}/lib/stableStringify.js +5 -3
  97. package/dist/query/lib/toKeyed.d.ts +11 -0
  98. package/dist/query/lib/toKeyed.js +18 -0
  99. package/dist/query/react/ReactHooksPlugin.d.ts +31 -0
  100. package/dist/query/react/ReactHooksPlugin.js +21 -0
  101. package/dist/query/react/index.d.ts +3 -0
  102. package/dist/query/react/index.js +3 -0
  103. package/dist/query/react/useCommand.d.ts +2 -0
  104. package/dist/query/react/useCommand.js +14 -0
  105. package/dist/query/react/useResource.d.ts +2 -0
  106. package/dist/query/react/useResource.js +16 -0
  107. package/dist/query/types/api.d.ts +39 -0
  108. package/dist/query/types/cache.d.ts +51 -0
  109. package/dist/query/types/command.d.ts +52 -0
  110. package/dist/query/types/common.d.ts +65 -0
  111. package/dist/query/types/index.d.ts +8 -4
  112. package/dist/query/types/index.js +8 -5
  113. package/dist/query/types/plugin-hkt.d.ts +64 -0
  114. package/dist/query/types/resource.d.ts +49 -0
  115. package/dist/query/types/snapshot.d.ts +27 -0
  116. package/dist/query/types/snapshot.js +2 -0
  117. package/dist/query/types/state.d.ts +24 -0
  118. package/dist/signals/base/ComputeCache.js +1 -1
  119. package/dist/signals/base/Devtools.js +2 -6
  120. package/dist/signals/signals/Computed.d.ts +1 -0
  121. package/dist/signals/signals/Computed.js +5 -1
  122. package/dist/signals/signals/Effect.d.ts +0 -4
  123. package/dist/signals/signals/Effect.js +0 -6
  124. package/dist/signals/signals/LocalState.d.ts +1 -10
  125. package/dist/signals/signals/LocalState.js +0 -12
  126. package/dist/signals/signals/Signal.d.ts +2 -8
  127. package/dist/signals/signals/Signal.js +1 -10
  128. package/dist/signals/signals/State.d.ts +2 -1
  129. package/dist/signals/signals/State.js +9 -0
  130. package/dist/signals/types/SignalOptions.d.ts +0 -2
  131. package/dist/signals/types/normalizeSignalOptions.js +0 -3
  132. package/dist/signals/types/signals.types.d.ts +3 -1
  133. package/docs/CHANGELOG.md +54 -2
  134. package/docs/contributing/release/README.md +2 -8
  135. package/docs/migrations/0.6.0.md +224 -0
  136. package/docs/query/README.md +52 -562
  137. package/docs/query/api/README.md +59 -0
  138. package/docs/query/api/_CacheEntry.md +39 -0
  139. package/docs/query/api/_CacheMap.md +30 -0
  140. package/docs/query/api/_QueryCacheEntry.md +81 -0
  141. package/docs/query/api/command-agent.md +60 -0
  142. package/docs/query/api/command.md +76 -0
  143. package/docs/query/api/resource-agent.md +68 -0
  144. package/docs/query/api/resource.md +77 -0
  145. package/docs/query/concepts/agent.md +70 -0
  146. package/docs/query/concepts/architecture.md +139 -0
  147. package/docs/query/concepts/cache.md +81 -0
  148. package/docs/query/concepts/dataflows.md +473 -0
  149. package/docs/query/concepts/keyed.md +42 -0
  150. package/docs/query/concepts/machine.md +106 -0
  151. package/docs/query/concepts/patching.md +85 -0
  152. package/docs/query/usage/broadcast.md +188 -0
  153. package/docs/query/usage/command.md +203 -0
  154. package/docs/query/usage/lifecycle.md +114 -0
  155. package/docs/query/usage/links.md +125 -0
  156. package/docs/query/usage/plugins.md +96 -0
  157. package/docs/query/usage/resource.md +206 -0
  158. package/docs/query/usage/snapshot.md +80 -0
  159. package/docs/usage/react/README.md +45 -91
  160. package/package.json +5 -7
  161. package/dist/query/SKIP_TOKEN.d.ts +0 -1
  162. package/dist/query/SKIP_TOKEN.js +0 -1
  163. package/dist/query/api/createCommand.d.ts +0 -21
  164. package/dist/query/api/createCommand.js +0 -20
  165. package/dist/query/api/createOperation.d.ts +0 -5
  166. package/dist/query/api/createOperation.js +0 -6
  167. package/dist/query/api/createResource.d.ts +0 -3
  168. package/dist/query/api/createResource.js +0 -2
  169. package/dist/query/api/createResourceDuplicator.d.ts +0 -4
  170. package/dist/query/api/createResourceDuplicator.js +0 -2
  171. package/dist/query/api/resetAllQueriesCache.d.ts +0 -1
  172. package/dist/query/api/resetAllQueriesCache.js +0 -4
  173. package/dist/query/core/Command/Command.d.ts +0 -35
  174. package/dist/query/core/Command/Command.js +0 -210
  175. package/dist/query/core/Command/CommandAgent.d.ts +0 -19
  176. package/dist/query/core/Command/CommandAgent.js +0 -54
  177. package/dist/query/core/Command/index.d.ts +0 -2
  178. package/dist/query/core/Command/index.js +0 -2
  179. package/dist/query/core/Operation/Operation.d.ts +0 -8
  180. package/dist/query/core/Operation/Operation.js +0 -4
  181. package/dist/query/core/Operation/OperationAgent.d.ts +0 -4
  182. package/dist/query/core/Operation/OperationAgent.js +0 -4
  183. package/dist/query/core/QueriesCache.d.ts +0 -9
  184. package/dist/query/core/QueriesCache.js +0 -28
  185. package/dist/query/core/QueriesLifetimeHooks.d.ts +0 -22
  186. package/dist/query/core/QueriesLifetimeHooks.js +0 -86
  187. package/dist/query/core/ResetAllQueriesSignal.d.ts +0 -6
  188. package/dist/query/core/ResetAllQueriesSignal.js +0 -11
  189. package/dist/query/core/Resource/Resource.d.ts +0 -51
  190. package/dist/query/core/Resource/Resource.js +0 -232
  191. package/dist/query/core/Resource/ResourceAgent.d.ts +0 -35
  192. package/dist/query/core/Resource/ResourceAgent.js +0 -110
  193. package/dist/query/core/Resource/ResourceDuplicator.d.ts +0 -73
  194. package/dist/query/core/Resource/ResourceDuplicator.js +0 -227
  195. package/dist/query/core/Resource/ResourceDuplicatorAgent.d.ts +0 -35
  196. package/dist/query/core/Resource/ResourceDuplicatorAgent.js +0 -110
  197. package/dist/query/core/Resource/ResourceRef.d.ts +0 -16
  198. package/dist/query/core/Resource/ResourceRef.js +0 -136
  199. package/dist/query/lib/IndirectMap.d.ts +0 -19
  200. package/dist/query/lib/IndirectMap.js +0 -88
  201. package/dist/query/lib/ReactiveCache.d.ts +0 -62
  202. package/dist/query/lib/ReactiveCache.js +0 -80
  203. package/dist/query/react/useCommandAgent.d.ts +0 -24
  204. package/dist/query/react/useCommandAgent.js +0 -39
  205. package/dist/query/react/useOperationAgent.d.ts +0 -6
  206. package/dist/query/react/useOperationAgent.js +0 -6
  207. package/dist/query/react/useResourceAgent.d.ts +0 -6
  208. package/dist/query/react/useResourceAgent.js +0 -31
  209. package/dist/query/react/useResourceRef.d.ts +0 -5
  210. package/dist/query/react/useResourceRef.js +0 -13
  211. package/dist/query/types/Command.types.d.ts +0 -154
  212. package/dist/query/types/Command.types.js +0 -1
  213. package/dist/query/types/Operation.types.d.ts +0 -13
  214. package/dist/query/types/Operation.types.js +0 -1
  215. package/dist/query/types/Resource.types.d.ts +0 -129
  216. package/dist/query/types/Resource.types.js +0 -1
  217. package/dist/query/types/shared.types.d.ts +0 -26
  218. package/dist/query/types/shared.types.js +0 -1
  219. package/dist/query-v2/api/createApi.d.ts +0 -10
  220. package/dist/query-v2/api/createApi.js +0 -83
  221. package/dist/query-v2/core/common/CacheEntry.d.ts +0 -29
  222. package/dist/query-v2/core/common/CacheEntry.js +0 -71
  223. package/dist/query-v2/core/common/CacheMap.d.ts +0 -38
  224. package/dist/query-v2/core/common/CacheMap.js +0 -127
  225. package/dist/query-v2/core/common/LifecycleHooks.d.ts +0 -22
  226. package/dist/query-v2/core/common/LifecycleHooks.js +0 -104
  227. package/dist/query-v2/core/common/index.d.ts +0 -3
  228. package/dist/query-v2/core/common/index.js +0 -3
  229. package/dist/query-v2/core/index.d.ts +0 -3
  230. package/dist/query-v2/core/index.js +0 -3
  231. package/dist/query-v2/core/machines/Machine.d.ts +0 -14
  232. package/dist/query-v2/core/machines/Machine.js +0 -33
  233. package/dist/query-v2/core/machines/MachineError.d.ts +0 -11
  234. package/dist/query-v2/core/machines/MachineError.js +0 -26
  235. package/dist/query-v2/core/machines/MachineIdle.d.ts +0 -8
  236. package/dist/query-v2/core/machines/MachineIdle.js +0 -19
  237. package/dist/query-v2/core/machines/MachinePending.d.ts +0 -12
  238. package/dist/query-v2/core/machines/MachinePending.js +0 -29
  239. package/dist/query-v2/core/machines/MachineRefreshing.d.ts +0 -14
  240. package/dist/query-v2/core/machines/MachineRefreshing.js +0 -46
  241. package/dist/query-v2/core/machines/MachineSuccess.d.ts +0 -16
  242. package/dist/query-v2/core/machines/MachineSuccess.js +0 -42
  243. package/dist/query-v2/core/machines/MachineWithData.d.ts +0 -18
  244. package/dist/query-v2/core/machines/MachineWithData.js +0 -40
  245. package/dist/query-v2/core/machines/Patcher.d.ts +0 -20
  246. package/dist/query-v2/core/machines/Patcher.js +0 -104
  247. package/dist/query-v2/core/machines/index.d.ts +0 -8
  248. package/dist/query-v2/core/machines/index.js +0 -8
  249. package/dist/query-v2/core/resource/ResourceV2.d.ts +0 -120
  250. package/dist/query-v2/core/resource/ResourceV2.js +0 -464
  251. package/dist/query-v2/core/resource/ResourceV2Agent.d.ts +0 -26
  252. package/dist/query-v2/core/resource/ResourceV2Agent.js +0 -132
  253. package/dist/query-v2/core/resource/index.d.ts +0 -2
  254. package/dist/query-v2/core/resource/index.js +0 -2
  255. package/dist/query-v2/index.d.ts +0 -11
  256. package/dist/query-v2/index.js +0 -17
  257. package/dist/query-v2/lib/NO_VALUE.d.ts +0 -2
  258. package/dist/query-v2/lib/NO_VALUE.js +0 -1
  259. package/dist/query-v2/lib/SKIP_TOKEN.d.ts +0 -2
  260. package/dist/query-v2/lib/SKIP_TOKEN.js +0 -1
  261. package/dist/query-v2/lib/index.d.ts +0 -4
  262. package/dist/query-v2/lib/index.js +0 -3
  263. package/dist/query-v2/plugins/ReactHooksPlugin.d.ts +0 -25
  264. package/dist/query-v2/plugins/ReactHooksPlugin.js +0 -19
  265. package/dist/query-v2/plugins/types.d.ts +0 -1
  266. package/dist/query-v2/react/__tests__/helpers.d.ts +0 -12
  267. package/dist/query-v2/react/__tests__/helpers.js +0 -33
  268. package/dist/query-v2/react/index.d.ts +0 -2
  269. package/dist/query-v2/react/index.js +0 -2
  270. package/dist/query-v2/react/useResourceV2Agent.d.ts +0 -12
  271. package/dist/query-v2/react/useResourceV2Agent.js +0 -36
  272. package/dist/query-v2/react/useResourceV2Ref.d.ts +0 -12
  273. package/dist/query-v2/react/useResourceV2Ref.js +0 -57
  274. package/dist/query-v2/snapshot/Snapshot.d.ts +0 -13
  275. package/dist/query-v2/snapshot/Snapshot.js +0 -76
  276. package/dist/query-v2/types/agent.types.d.ts +0 -54
  277. package/dist/query-v2/types/api.types.d.ts +0 -22
  278. package/dist/query-v2/types/cache.types.d.ts +0 -37
  279. package/dist/query-v2/types/index.d.ts +0 -9
  280. package/dist/query-v2/types/index.js +0 -9
  281. package/dist/query-v2/types/lifecycle.types.d.ts +0 -25
  282. package/dist/query-v2/types/machine.types.d.ts +0 -67
  283. package/dist/query-v2/types/plugin.types.d.ts +0 -38
  284. package/dist/query-v2/types/resource.types.d.ts +0 -35
  285. package/dist/query-v2/types/resource.types.js +0 -1
  286. package/dist/query-v2/types/shared.types.d.ts +0 -20
  287. package/dist/query-v2/types/shared.types.js +0 -1
  288. package/dist/query-v2/types/snapshot.types.d.ts +0 -21
  289. package/dist/query-v2/types/snapshot.types.js +0 -1
  290. package/docs/contributing/query-v2/README.md +0 -379
  291. package/docs/migrations/query-v2.md +0 -171
  292. package/docs/query-v2/README.md +0 -280
  293. package/docs/query-v2/api-reference.md +0 -235
  294. package/docs/query-v2/optimistic-updates.md +0 -148
  295. package/docs/query-v2/ssr.md +0 -130
  296. /package/dist/{query-v2 → query}/lib/stableStringify.d.ts +0 -0
  297. /package/dist/{query-v2/plugins/types.js → query/types/api.js} +0 -0
  298. /package/dist/{query-v2/types/agent.types.js → query/types/cache.js} +0 -0
  299. /package/dist/{query-v2/types/api.types.js → query/types/command.js} +0 -0
  300. /package/dist/{query-v2/types/cache.types.js → query/types/common.js} +0 -0
  301. /package/dist/{query-v2/types/lifecycle.types.js → query/types/plugin-hkt.js} +0 -0
  302. /package/dist/{query-v2/types/machine.types.js → query/types/resource.js} +0 -0
  303. /package/dist/{query-v2/types/plugin.types.js → query/types/state.js} +0 -0
@@ -1,104 +0,0 @@
1
- import { applyPatches, enablePatches, produceWithPatches } from "immer";
2
- import { NO_VALUE } from "../../../query-v2/lib/NO_VALUE";
3
- enablePatches();
4
- function applyImmerPatches(data, patches) {
5
- return applyPatches(data, patches);
6
- }
7
- export class Patcher {
8
- static createPatch(patchFn, data) {
9
- const [, patches, inversePatches] = produceWithPatches(data, patchFn);
10
- return {
11
- patches,
12
- inversePatches,
13
- status: "pending",
14
- };
15
- }
16
- static resolvePatches(originalData, patches) {
17
- let currentData = originalData;
18
- let baseData = originalData;
19
- const remainingPatches = [];
20
- let foundPending = false;
21
- const lastPendingIndex = patches.findLastIndex((p) => p.status === "pending");
22
- patches.forEach((patch, index) => {
23
- if (patch.status === "pending") {
24
- foundPending = true;
25
- currentData = applyImmerPatches(currentData, patch.patches);
26
- remainingPatches.push(patch);
27
- }
28
- else if (foundPending) {
29
- if (patch.status === "committed") {
30
- currentData = applyImmerPatches(currentData, patch.patches);
31
- remainingPatches.push(patch);
32
- }
33
- else if (patch.status === "aborted") {
34
- const hasPendingAfter = index < lastPendingIndex;
35
- if (hasPendingAfter) {
36
- currentData = applyImmerPatches(currentData, patch.inversePatches);
37
- remainingPatches.push(patch);
38
- }
39
- // No pending after → remove from queue
40
- }
41
- }
42
- else {
43
- // Before first pending
44
- if (patch.status === "committed") {
45
- currentData = applyImmerPatches(currentData, patch.patches);
46
- baseData = currentData;
47
- // committed before pending → remove from queue
48
- }
49
- else if (patch.status === "aborted") {
50
- // aborted before pending → remove from queue
51
- }
52
- }
53
- });
54
- return { data: currentData, patches: remainingPatches, baseData };
55
- }
56
- static finishPatch(originalData, patches, type, patch) {
57
- if (!patches) {
58
- return { originalData, patches: null, data: null };
59
- }
60
- // Mark the target patch
61
- patch.status = type === "commit" ? "committed" : "aborted";
62
- // If no originalData, nothing to resolve
63
- if (originalData === NO_VALUE) {
64
- return { originalData, patches, data: null };
65
- }
66
- // Resolve patches
67
- const resolved = Patcher.resolvePatches(originalData, patches);
68
- const hasPending = resolved.patches.some((p) => p.status === "pending");
69
- if (!hasPending) {
70
- // No pending patches remain → clear originalData and patches
71
- return {
72
- originalData: NO_VALUE,
73
- patches: resolved.patches.length > 0 ? resolved.patches : null,
74
- data: resolved.data,
75
- };
76
- }
77
- return {
78
- originalData: resolved.baseData,
79
- patches: resolved.patches.length > 0 ? resolved.patches : null,
80
- data: resolved.data,
81
- };
82
- }
83
- static abortAllPending(originalData, patches) {
84
- if (!patches) {
85
- return { originalData, patches: null, data: null };
86
- }
87
- // Mark all pending as aborted
88
- for (const patch of patches) {
89
- if (patch.status === "pending") {
90
- patch.status = "aborted";
91
- }
92
- }
93
- if (originalData === NO_VALUE) {
94
- return { originalData: NO_VALUE, patches: null, data: null };
95
- }
96
- // Resolve: all should be either committed or aborted now
97
- const resolved = Patcher.resolvePatches(originalData, patches);
98
- return {
99
- originalData: NO_VALUE,
100
- patches: null,
101
- data: resolved.data,
102
- };
103
- }
104
- }
@@ -1,8 +0,0 @@
1
- export { Machine, type TMachineInstance } from "./Machine";
2
- export { MachineIdle } from "./MachineIdle";
3
- export { MachinePending } from "./MachinePending";
4
- export { MachineSuccess } from "./MachineSuccess";
5
- export { MachineError } from "./MachineError";
6
- export { MachineRefreshing } from "./MachineRefreshing";
7
- export { MachineWithData } from "./MachineWithData";
8
- export { Patcher } from "./Patcher";
@@ -1,8 +0,0 @@
1
- export { Machine } from "./Machine";
2
- export { MachineIdle } from "./MachineIdle";
3
- export { MachinePending } from "./MachinePending";
4
- export { MachineSuccess } from "./MachineSuccess";
5
- export { MachineError } from "./MachineError";
6
- export { MachineRefreshing } from "./MachineRefreshing";
7
- export { MachineWithData } from "./MachineWithData";
8
- export { Patcher } from "./Patcher";
@@ -1,120 +0,0 @@
1
- import type { IResourceV2Agent } from "../../../query-v2/types/agent.types";
2
- import type { ICacheEntry } from "../../../query-v2/types/cache.types";
3
- import type { TOnCacheEntryAdded, TOnQueryStarted } from "../../../query-v2/types/lifecycle.types";
4
- import type { TMachine, TPatchFn } from "../../../query-v2/types/machine.types";
5
- import type { IResourceV2 } from "../../../query-v2/types/resource.types";
6
- import type { TBeforeDevtoolsPushFn, TCompareArgsFn, TQueryFn, TSerializeArgsFn } from "../../../query-v2/types/shared.types";
7
- import { CacheEntry } from "../common/CacheEntry";
8
- import type { TMachineInstance } from "../machines/Machine";
9
- export interface ResourceV2Config<TArgs, TData, TError = Error> {
10
- key?: string;
11
- keyPrefix?: string;
12
- keyStrategy?: "serialize" | "compare";
13
- queryFn: TQueryFn<TArgs, TData>;
14
- onCacheEntryAdded?: TOnCacheEntryAdded<TArgs, TData>;
15
- onQueryStarted?: TOnQueryStarted<TArgs, TData>;
16
- serializeArgs?: TSerializeArgsFn;
17
- compareArg?: TCompareArgsFn;
18
- cacheLifetime?: number;
19
- beforeDevtoolsPush?: TBeforeDevtoolsPushFn<TMachine<TData, TError>>;
20
- maxSnapshotDataAge?: number;
21
- doCacheArgs?: boolean;
22
- }
23
- /**
24
- * Cache-backed resource manager.
25
- * Orchestrates queries, caching, lifecycle hooks, GC, and optimistic patches for a single resource type.
26
- */
27
- export declare class ResourceV2<TArgs, TData, TError = Error> implements IResourceV2<TArgs, TData, TError> {
28
- private readonly _cache;
29
- private readonly _queryFn;
30
- private readonly _lifecycleHooks;
31
- private readonly _serializeArgs;
32
- private readonly _compareArg;
33
- private readonly _keyStrategy;
34
- private readonly _cacheLifetime;
35
- private readonly _beforeDevtoolsPush?;
36
- private readonly _key?;
37
- private readonly _keyPrefix?;
38
- /** In-flight queries keyed by serialized args — for dedup + abort */
39
- private readonly _inFlight;
40
- /** Cache lifetime timers keyed by serialized args */
41
- private readonly _gcTimers;
42
- /** Refresh error listeners (used by Agent for refreshError tracking) */
43
- private readonly _refreshErrorListeners;
44
- constructor(config: ResourceV2Config<TArgs, TData, TError>);
45
- /**
46
- * Create an agent that tracks a single cache entry with reactive state (SWR).
47
- *
48
- * @returns A new agent bound to this resource.
49
- */
50
- createAgent(): IResourceV2Agent<TArgs, TData, TError>;
51
- /**
52
- * Execute a query for the given args, returning the cache entry.
53
- * Deduplicates concurrent calls for the same args unless `doForce` is set.
54
- *
55
- * @param args - Query arguments (used as cache key).
56
- * @param doForce - If true, bypass dedup and re-execute the query.
57
- * @returns The cache entry after query initiation.
58
- */
59
- query(args: TArgs, doForce?: boolean): Promise<ICacheEntry<TData, TError>>;
60
- /**
61
- * Reactive query — read machine state as a signal dependency.
62
- * Initiates the query if not already cached.
63
- *
64
- * @param args - Query arguments.
65
- * @returns Current machine state (registers a reactive subscription).
66
- */
67
- query$(args: TArgs, doForce?: boolean): TMachine<TData, TError>;
68
- /**
69
- * Get the cache entry for the given args without initiating a query (unless `doInitiate` is set).
70
- *
71
- * @param args - Query arguments.
72
- * @returns The cache entry, or `null` if not cached.
73
- */
74
- entry(args: TArgs, doInitiate?: boolean): ICacheEntry<TData, TError> | null;
75
- entry$(args: TArgs, doInitiate?: boolean): TMachine<TData, TError>;
76
- invalidate(args: TArgs): void;
77
- compareArgs(a: TArgs, b: TArgs): boolean;
78
- /** Public key getter for API registry */
79
- get key(): string | undefined;
80
- /** Public keyStrategy getter for snapshot validation */
81
- get keyStrategy(): "serialize" | "compare";
82
- /** Serialize args to string key */
83
- getSerializedKey(args: TArgs): string;
84
- /** Iterate cache entries — for snapshot */
85
- cacheEntries(): Iterable<[TArgs | string, CacheEntry<TData, TError>]>;
86
- /** Hydrate a cache entry from snapshot data */
87
- hydrateEntry(args: TArgs, machine: TMachineInstance<TData, TError>): void;
88
- /** Check if cache entry exists for given args */
89
- hasEntry(args: TArgs): boolean;
90
- /** Pre-populate cache with data */
91
- populateEntry(args: TArgs, data: TData): void;
92
- /** Create an optimistic patch on a cache entry */
93
- createEntryPatch(args: TArgs, patchFn: TPatchFn<TData>): {
94
- commit: () => void;
95
- abort: () => void;
96
- } | null;
97
- /** Lock a cache entry — prevent GC eviction. Returns unlock function. */
98
- lockEntry(args: TArgs): {
99
- unlock: () => void;
100
- };
101
- /** Subscribe to refresh error events (used by Agent) */
102
- onRefreshError(listener: (args: TArgs, error: TError) => void): () => void;
103
- /** Reset the entire cache — aborts in-flight requests, clears GC timers, completes all entries. */
104
- resetCache(): void;
105
- /**
106
- * Schedule GC for a cache entry after cacheLifetime.
107
- * Called when subscriber count drops to 0.
108
- */
109
- scheduleGc(args: TArgs): void;
110
- /**
111
- * Cancel pending GC for a cache entry.
112
- * Called when a new subscriber appears.
113
- */
114
- cancelGc(args: TArgs): void;
115
- private _cancelGcTimer;
116
- private _evictEntry;
117
- private _executeQuery;
118
- private _executeRefresh;
119
- private _buildCacheEntryOptions;
120
- }