@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,54 +0,0 @@
1
- import { Computed, Signal } from "../../../signals";
2
- export class CommandAgent {
3
- _command;
4
- _commands$ = Signal.state({
5
- current$: null,
6
- }, { isDisabled: true });
7
- state$ = Computed.create(() => {
8
- const commands = this._commands$.get();
9
- const currState = commands.current$?.value$.get();
10
- // Нет текущего состояния — дефолт
11
- if (!currState) {
12
- return {
13
- isLoading: false,
14
- isDone: false,
15
- isSuccess: false,
16
- isError: false,
17
- error: undefined,
18
- data: undefined,
19
- args: undefined,
20
- };
21
- }
22
- return {
23
- isLoading: currState.isLoading,
24
- isDone: currState.isDone,
25
- isSuccess: currState.isSuccess,
26
- isError: currState.isError,
27
- error: currState.error ?? undefined,
28
- data: currState.data ?? undefined,
29
- args: currState.arg,
30
- };
31
- }, { isDisabled: true });
32
- constructor(_command) {
33
- this._command = _command;
34
- }
35
- _next(newCache) {
36
- this._commands$.set({
37
- current$: newCache,
38
- });
39
- }
40
- initiate(args) {
41
- const cache = this._command.getQueryCache(args);
42
- if (!cache) {
43
- const newCache = this._command.initiate(args);
44
- this._next(newCache);
45
- return;
46
- }
47
- // Всегда запускаем команду заново, так как команды обычно не кэшируются как ресурсы
48
- const newCache = this._command.initiate(args, { cache });
49
- this._next(newCache);
50
- }
51
- createAgent() {
52
- return new CommandAgent(this._command);
53
- }
54
- }
@@ -1,2 +0,0 @@
1
- export { Command } from "./Command";
2
- export { CommandAgent } from "./CommandAgent";
@@ -1,2 +0,0 @@
1
- export { Command } from "./Command";
2
- export { CommandAgent } from "./CommandAgent";
@@ -1,8 +0,0 @@
1
- /**
2
- * @deprecated Use `Command` from '../Command/Command' instead. Will be removed in v0.6.0.
3
- */
4
- export { Command as Operation } from "../Command/Command";
5
- /**
6
- * @deprecated Use `CoreCommandQueryState` from '../Command/Command' instead. Will be removed in v0.6.0.
7
- */
8
- export type { CoreCommandQueryState as CoreOperationQueryState } from "../Command/Command";
@@ -1,4 +0,0 @@
1
- /**
2
- * @deprecated Use `Command` from '../Command/Command' instead. Will be removed in v0.6.0.
3
- */
4
- export { Command as Operation } from "../Command/Command";
@@ -1,4 +0,0 @@
1
- /**
2
- * @deprecated Use `CommandAgent` from '../Command/CommandAgent' instead. Will be removed in v0.6.0.
3
- */
4
- export { CommandAgent as OperationAgent } from "../Command/CommandAgent";
@@ -1,4 +0,0 @@
1
- /**
2
- * @deprecated Use `CommandAgent` from '../Command/CommandAgent' instead. Will be removed in v0.6.0.
3
- */
4
- export { CommandAgent as OperationAgent } from "../Command/CommandAgent";
@@ -1,9 +0,0 @@
1
- import { ReactiveCache } from "../../query/lib/ReactiveCache";
2
- export declare class QueriesCache<KEY, VALUE> {
3
- private _cacheLifeTime;
4
- private readonly _cache;
5
- constructor(_cacheLifeTime?: number | false, compareArgsFn?: (a: KEY, b: KEY) => boolean);
6
- getQueryCache(args: KEY): ReactiveCache<VALUE> | undefined;
7
- createQueryCache(args: KEY, initialState: VALUE): ReactiveCache<VALUE>;
8
- values(): MapIterator<ReactiveCache<VALUE>>;
9
- }
@@ -1,28 +0,0 @@
1
- import { shallowEqual } from "../../common/utils";
2
- import { IndirectMap } from "../../query/lib/IndirectMap";
3
- import { ReactiveCache } from "../../query/lib/ReactiveCache";
4
- export class QueriesCache {
5
- _cacheLifeTime;
6
- _cache;
7
- constructor(_cacheLifeTime = 60_000, compareArgsFn = shallowEqual) {
8
- this._cacheLifeTime = _cacheLifeTime;
9
- this._cache = new IndirectMap(compareArgsFn);
10
- }
11
- getQueryCache(args) {
12
- return this._cache.get(args);
13
- }
14
- createQueryCache(args, initialState) {
15
- const cache = new ReactiveCache({
16
- initialState,
17
- cacheLifeTime: this._cacheLifeTime,
18
- });
19
- cache.onClean$.subscribe(() => {
20
- this._cache.delete(args);
21
- });
22
- this._cache.set(args, cache);
23
- return cache;
24
- }
25
- values() {
26
- return this._cache.values();
27
- }
28
- }
@@ -1,22 +0,0 @@
1
- import { Subject } from "rxjs";
2
- import { OnCacheEntryAdded, OnQueryStarted } from "../../query/types";
3
- type Options<ARGS, DATA> = {
4
- onCacheEntryAdded?: OnCacheEntryAdded<ARGS, DATA>;
5
- onQueryStarted?: OnQueryStarted<ARGS, DATA>;
6
- devtoolsName?: string | false;
7
- };
8
- export declare class QueriesLifetimeHooks<ARGS, DATA> {
9
- private onCacheEntryAddedListeners;
10
- private onQueryStartedListeners;
11
- constructor(options: Options<ARGS, DATA> | undefined);
12
- onCacheEntryAdded: (args: ARGS) => {
13
- cacheDataLoaded: () => void;
14
- cacheEntryRemoved: () => void;
15
- dataChanged$: Subject<DATA>;
16
- };
17
- onQueryStarted: (args: ARGS) => {
18
- fulfilledSuccess: (data: DATA) => void;
19
- fulfilledError: (error: unknown) => void;
20
- };
21
- }
22
- export {};
@@ -1,86 +0,0 @@
1
- import { Subject } from "rxjs";
2
- import { SharedOptions } from "../../common/options/SharedOptions";
3
- import { PromiseResolver } from "../../common/utils";
4
- import { Devtools } from "../../signals";
5
- export class QueriesLifetimeHooks {
6
- onCacheEntryAddedListeners = [];
7
- onQueryStartedListeners = [];
8
- constructor(options) {
9
- if (options?.onCacheEntryAdded) {
10
- this.onCacheEntryAddedListeners.push(options.onCacheEntryAdded);
11
- }
12
- if (options?.onQueryStarted) {
13
- this.onQueryStartedListeners.push(options.onQueryStarted);
14
- }
15
- const devtoolsName = options?.devtoolsName;
16
- if (devtoolsName !== false && Devtools.hasDevtools) {
17
- this.onCacheEntryAddedListeners.push(async (_, { $cacheEntryRemoved, dataChanged$ }) => {
18
- let stateDevtools = null;
19
- dataChanged$.subscribe((state) => {
20
- if (!stateDevtools) {
21
- stateDevtools = Devtools.createState(state, {
22
- base: "Queries",
23
- name: devtoolsName || "",
24
- });
25
- return;
26
- }
27
- stateDevtools(state);
28
- });
29
- $cacheEntryRemoved.then(() => {
30
- stateDevtools("$CLEANED");
31
- });
32
- });
33
- }
34
- if (SharedOptions.onQueryError) {
35
- this.onQueryStartedListeners.push(async (_, { $queryFulfilled }) => {
36
- const result = await $queryFulfilled;
37
- if (result.isError)
38
- SharedOptions.onQueryError(result.error);
39
- });
40
- }
41
- }
42
- onCacheEntryAdded = (args) => {
43
- const cacheDataLoadedResolver = new PromiseResolver();
44
- const cacheEntryRemovedResolver = new PromiseResolver();
45
- const dataChanged$ = new Subject(); // TODO не нравится мне это, мб передавать $spy в аргументы?
46
- cacheEntryRemovedResolver.promise.finally(() => {
47
- dataChanged$.complete();
48
- });
49
- this.onCacheEntryAddedListeners.forEach((listener) => {
50
- listener(args, {
51
- $cacheDataLoaded: cacheDataLoadedResolver.promise,
52
- $cacheEntryRemoved: cacheEntryRemovedResolver.promise,
53
- dataChanged$,
54
- });
55
- });
56
- return {
57
- cacheDataLoaded: () => cacheDataLoadedResolver.resolve(),
58
- cacheEntryRemoved: () => cacheEntryRemovedResolver.resolve(),
59
- dataChanged$,
60
- };
61
- };
62
- onQueryStarted = (args) => {
63
- const queryFulfilledResolver = new PromiseResolver();
64
- this.onQueryStartedListeners.forEach((listener) => {
65
- listener(args, {
66
- $queryFulfilled: queryFulfilledResolver.promise,
67
- });
68
- });
69
- return {
70
- fulfilledSuccess: (data) => {
71
- queryFulfilledResolver.resolve({
72
- data,
73
- error: undefined,
74
- isError: false,
75
- });
76
- },
77
- fulfilledError: (error) => {
78
- queryFulfilledResolver.resolve({
79
- data: undefined,
80
- error,
81
- isError: true,
82
- });
83
- },
84
- };
85
- };
86
- }
@@ -1,6 +0,0 @@
1
- import { Subject } from "rxjs";
2
- export declare class ResetAllQueriesSignal {
3
- private static subject$;
4
- static clean$: Subject<void>;
5
- static clean(): void;
6
- }
@@ -1,11 +0,0 @@
1
- import { Subject } from "rxjs";
2
- import { Batcher } from "../../signals";
3
- export class ResetAllQueriesSignal {
4
- static subject$ = new Subject();
5
- static clean$ = ResetAllQueriesSignal.subject$;
6
- static clean() {
7
- Batcher.run(() => {
8
- ResetAllQueriesSignal.subject$.next();
9
- });
10
- }
11
- }
@@ -1,51 +0,0 @@
1
- import { ReactiveCache } from "../../../query/lib/ReactiveCache";
2
- import type { ResourceCreateOptions, ResourceDefinition, ResourceInstance, ResourceRefInstance, ResourceTransaction } from "../../../query/types";
3
- import { ResourceAgent } from "./ResourceAgent";
4
- export type CoreResourceQueryState<D extends ResourceDefinition> = {
5
- transactions: ResourceTransaction[] | null;
6
- abortController: AbortController | null;
7
- args: D["Args"];
8
- savedData: D["Data"] | null;
9
- data: D["Data"] | null;
10
- error: unknown | null;
11
- isError: boolean;
12
- isLoading: boolean;
13
- isReloading: boolean;
14
- isDone: boolean;
15
- isSuccess: boolean;
16
- isLocked: boolean;
17
- isInitiated: boolean;
18
- lockCount: number;
19
- };
20
- export type CoreResourceQueryCache<D extends ResourceDefinition> = ReactiveCache<CoreResourceQueryState<D>>;
21
- export declare class Resource<D extends ResourceDefinition> implements ResourceInstance<D> {
22
- private readonly _options;
23
- private readonly _queriesCache;
24
- private readonly _hooks;
25
- private _DEFAULT_CACHE_LIFETIME;
26
- constructor(_options: ResourceCreateOptions<D>);
27
- createAgent: () => ResourceAgent<D>;
28
- createRef: (args: D["Args"]) => ResourceRefInstance<D>;
29
- getQueryCache(args: D["Args"]): CoreResourceQueryCache<D> | undefined;
30
- createQueryCache(args: D["Args"], state?: CoreResourceQueryState<D>): CoreResourceQueryCache<D>;
31
- incrementLock(args: D["Args"], options?: {
32
- cache?: CoreResourceQueryCache<D>;
33
- }): CoreResourceQueryCache<D>;
34
- decrementLock(args: D["Args"], options?: {
35
- cache?: CoreResourceQueryCache<D>;
36
- }): CoreResourceQueryCache<D> | null;
37
- update(args: D["Args"], updateFn: (data: D["Data"], savedData: D["Data"] | null, transactions: ResourceTransaction[] | null) => {
38
- data: D["Data"];
39
- transactions: ResourceTransaction[] | null;
40
- savedData: D["Data"] | null;
41
- }, options?: {
42
- cache?: CoreResourceQueryCache<D>;
43
- }): CoreResourceQueryCache<D> | null;
44
- createWithData(args: D["Args"], data: D["Data"], options?: {
45
- cache?: CoreResourceQueryCache<D>;
46
- }): CoreResourceQueryCache<D>;
47
- initiate(args: D["Args"], options?: {
48
- cache?: CoreResourceQueryCache<D>;
49
- }): CoreResourceQueryCache<D>;
50
- compareArgs(args1: D["Args"], args2: D["Args"]): boolean;
51
- }
@@ -1,232 +0,0 @@
1
- import { SharedOptions } from "../../../common/options/SharedOptions";
2
- import { QueriesCache } from "../QueriesCache";
3
- import { QueriesLifetimeHooks } from "../QueriesLifetimeHooks";
4
- import { ResetAllQueriesSignal } from "../ResetAllQueriesSignal";
5
- import { ResourceAgent } from "./ResourceAgent";
6
- import { ResourceRef } from "./ResourceRef";
7
- class ResourceQueryState {
8
- static create(args) {
9
- return {
10
- transactions: null,
11
- savedData: null,
12
- abortController: null,
13
- args,
14
- data: null,
15
- error: null,
16
- isError: false,
17
- isReloading: false,
18
- isDone: false,
19
- isSuccess: false,
20
- isLocked: false,
21
- isLoading: false,
22
- isInitiated: false,
23
- lockCount: 0,
24
- };
25
- }
26
- static load(state, args) {
27
- state = state ?? ResourceQueryState.create(args);
28
- return {
29
- ...state,
30
- abortController: new AbortController(),
31
- args: args,
32
- isLoading: !state.isDone,
33
- isReloading: state.isDone,
34
- isInitiated: true,
35
- };
36
- }
37
- static success(state, data) {
38
- return {
39
- ...state,
40
- abortController: null,
41
- savedData: null,
42
- transactions: null,
43
- data,
44
- isLoading: false,
45
- isReloading: false,
46
- isDone: true,
47
- isSuccess: true,
48
- isError: false,
49
- error: null,
50
- };
51
- }
52
- static error(state, error) {
53
- return {
54
- ...state,
55
- abortController: null,
56
- isLoading: false,
57
- isReloading: false,
58
- isDone: true,
59
- isSuccess: false,
60
- isError: true,
61
- error,
62
- };
63
- }
64
- static incrementLock(state) {
65
- const lockCount = state.lockCount + 1;
66
- return {
67
- ...state,
68
- isLocked: lockCount > 0,
69
- lockCount,
70
- };
71
- }
72
- static decrementLock(state) {
73
- const lockCount = Math.max(0, state.lockCount - 1);
74
- return {
75
- ...state,
76
- isLocked: lockCount > 0,
77
- lockCount,
78
- };
79
- }
80
- static update(state, data, savedData, transactions) {
81
- return {
82
- ...state,
83
- transactions,
84
- savedData,
85
- data,
86
- };
87
- }
88
- static createWithData(data, args) {
89
- return {
90
- savedData: null,
91
- transactions: null,
92
- data,
93
- isLoading: false,
94
- isReloading: false,
95
- isDone: true,
96
- isSuccess: true,
97
- isError: false,
98
- error: null,
99
- abortController: null,
100
- args,
101
- isInitiated: false,
102
- isLocked: false,
103
- lockCount: 0,
104
- };
105
- }
106
- }
107
- export class Resource {
108
- _options;
109
- _queriesCache;
110
- _hooks;
111
- _DEFAULT_CACHE_LIFETIME = 60_000;
112
- constructor(_options) {
113
- this._options = _options;
114
- this._hooks = new QueriesLifetimeHooks({
115
- onCacheEntryAdded: _options.onCacheEntryAdded,
116
- onQueryStarted: _options.onQueryStarted,
117
- devtoolsName: _options.devtoolsName,
118
- });
119
- this._queriesCache = new QueriesCache(_options.cacheLifetime ?? this._DEFAULT_CACHE_LIFETIME);
120
- ResetAllQueriesSignal.clean$.subscribe(() => {
121
- const caches = Array.from(this._queriesCache.values());
122
- caches.forEach((cache) => {
123
- cache.value.abortController?.abort();
124
- cache.next(ResourceQueryState.create(cache.value.args));
125
- });
126
- });
127
- }
128
- createAgent = () => {
129
- return new ResourceAgent(this);
130
- };
131
- createRef = (args) => {
132
- return new ResourceRef(this, args);
133
- };
134
- getQueryCache(args) {
135
- return this._queriesCache.getQueryCache(args);
136
- }
137
- createQueryCache(args, state = ResourceQueryState.create(args)) {
138
- const cache = this._queriesCache.createQueryCache(args, state);
139
- const hookResolvers = this._hooks.onCacheEntryAdded(args);
140
- const spySub = cache.spy$.subscribe((state) => {
141
- if (!state.isDone)
142
- return;
143
- hookResolvers.cacheDataLoaded();
144
- spySub.unsubscribe();
145
- });
146
- cache.spy$.subscribe((data) => {
147
- hookResolvers.dataChanged$.next(data);
148
- });
149
- cache.onClean$.subscribe(() => {
150
- hookResolvers.cacheEntryRemoved();
151
- });
152
- return cache;
153
- }
154
- incrementLock(args, options) {
155
- let cache = options?.cache ?? this.getQueryCache(args);
156
- if (!cache) {
157
- cache = this.createQueryCache(args);
158
- }
159
- cache.next(ResourceQueryState.incrementLock(cache.value));
160
- return cache;
161
- }
162
- decrementLock(args, options) {
163
- const cache = options?.cache ?? this.getQueryCache(args);
164
- if (!cache) {
165
- return null;
166
- }
167
- cache.next(ResourceQueryState.decrementLock(cache.value));
168
- return cache;
169
- }
170
- update(args, updateFn, options) {
171
- const cache = options?.cache ?? this.getQueryCache(args);
172
- if (!cache) {
173
- return null;
174
- }
175
- const cacheValue = cache.value;
176
- if (!cacheValue.isDone) {
177
- return cache;
178
- }
179
- const { data, transactions, savedData } = updateFn(cacheValue.data, cacheValue.savedData, cacheValue.transactions);
180
- cache.next(ResourceQueryState.update(cache.value, data, savedData, transactions));
181
- return cache;
182
- }
183
- createWithData(args, data, options) {
184
- let cache = options?.cache ?? this.getQueryCache(args);
185
- const state = ResourceQueryState.createWithData(data, args);
186
- if (!cache) {
187
- cache = this.createQueryCache(args, state);
188
- // Только обновляем кэш новыми данными, если он еще не был инициализирован.
189
- // Это предотвращает перезапись уже инициализированного кэша.
190
- }
191
- else if (!cache.value.isInitiated) {
192
- cache.next(state);
193
- }
194
- return cache;
195
- }
196
- initiate(args, options) {
197
- let cache = options?.cache ?? this.getQueryCache(args);
198
- const prevAbortController = cache?.value.abortController ?? null;
199
- const state = ResourceQueryState.load(cache?.value, args);
200
- if (!cache) {
201
- cache = this.createQueryCache(args, state);
202
- }
203
- else {
204
- cache.next(state);
205
- }
206
- prevAbortController?.abort();
207
- const abortController = state.abortController;
208
- const query = this._options.queryFn(args, { abortSignal: abortController.signal });
209
- const hookResolvers = this._hooks.onQueryStarted(args);
210
- query
211
- .then((result) => {
212
- if (abortController.signal.aborted) {
213
- return;
214
- }
215
- const data = this._options.select ? this._options.select(result) : result;
216
- cache.next(ResourceQueryState.success(state, data));
217
- hookResolvers.fulfilledSuccess(data);
218
- })
219
- .catch((error) => {
220
- if (abortController.signal.aborted) {
221
- return;
222
- }
223
- cache.next(ResourceQueryState.error(state, error));
224
- hookResolvers.fulfilledError(error);
225
- });
226
- return cache;
227
- }
228
- compareArgs(args1, args2) {
229
- const compareFn = this._options.compareArgsFn ?? SharedOptions.defaultCompareArgs;
230
- return compareFn(args1, args2);
231
- }
232
- }
@@ -1,35 +0,0 @@
1
- import { ResourceAgentInstance, ResourceDefinition } from "../../../query/types";
2
- import type { Resource } from "./Resource";
3
- export declare class ResourceAgent<D extends ResourceDefinition> implements ResourceAgentInstance<D> {
4
- private _resource;
5
- private _resources$;
6
- state$: import("../../../signals").ComputeFn<{
7
- isInitiated: boolean;
8
- isLoading: boolean;
9
- isInitialLoading: boolean;
10
- isDone: boolean;
11
- isSuccess: boolean;
12
- isError: boolean;
13
- isLocked: boolean;
14
- isReloading: boolean;
15
- error: undefined;
16
- data: undefined;
17
- args: D["Args"];
18
- } | {
19
- isInitiated: boolean;
20
- isLoading: boolean;
21
- isInitialLoading: boolean;
22
- isDone: boolean;
23
- isSuccess: boolean;
24
- isError: boolean;
25
- isLocked: boolean;
26
- isReloading: boolean;
27
- error: {} | undefined;
28
- data: NonNullable<D["Data"]> | undefined;
29
- args: NonNullable<D["Args"]> | undefined;
30
- }>;
31
- constructor(_resource: Resource<D>);
32
- initiate(args: D["Args"], force?: boolean): void;
33
- compareArgs(args: D["Args"], otherArgs: D["Args"]): boolean;
34
- private _next;
35
- }