@fozy-labs/rx-toolkit 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +22 -13
- package/dist/common/devtools/reduxDevtools.js +17 -2
- package/dist/common/react/index.d.ts +1 -0
- package/dist/common/react/index.js +1 -0
- package/dist/common/react/useIsomorphicLayoutEffect.d.ts +17 -0
- package/dist/common/react/useIsomorphicLayoutEffect.js +17 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/query/api/createApi.d.ts +4 -0
- package/dist/query/api/createApi.js +9 -0
- package/dist/query/api/index.d.ts +1 -0
- package/dist/query/api/index.js +1 -0
- package/dist/query/constants.d.ts +12 -0
- package/dist/query/constants.js +15 -0
- package/dist/query/core/api/Api.d.ts +20 -0
- package/dist/query/core/api/Api.js +129 -0
- package/dist/query/core/api/constants.d.ts +2 -0
- package/dist/query/core/api/constants.js +3 -0
- package/dist/query/core/api/index.d.ts +4 -0
- package/dist/query/core/api/index.js +4 -0
- package/dist/query/core/api/mergeHooks.d.ts +2 -0
- package/dist/query/core/api/mergeHooks.js +26 -0
- package/dist/query/core/api/normalizeLinks.d.ts +2 -0
- package/dist/query/core/api/normalizeLinks.js +11 -0
- package/dist/query/core/cache/CacheEntry.d.ts +21 -0
- package/dist/query/core/cache/CacheEntry.js +54 -0
- package/dist/query/core/cache/CacheMap.d.ts +19 -0
- package/dist/query/core/cache/CacheMap.js +32 -0
- package/dist/query/core/cache/QueryCacheEntry.d.ts +21 -0
- package/dist/query/core/cache/QueryCacheEntry.js +136 -0
- package/dist/query/core/cache/index.d.ts +3 -0
- package/dist/query/core/cache/index.js +3 -0
- package/dist/query/core/command/Command.d.ts +67 -0
- package/dist/query/core/command/Command.js +253 -0
- package/dist/query/core/command/CommandAgent.d.ts +17 -0
- package/dist/query/core/command/CommandAgent.js +67 -0
- package/dist/query/core/command/LinkManager.d.ts +24 -0
- package/dist/query/core/command/LinkManager.js +71 -0
- package/dist/query/core/command/index.d.ts +2 -0
- package/dist/query/core/command/index.js +2 -0
- package/dist/query/core/errors/CacheEntryRemovedError.d.ts +7 -0
- package/dist/query/core/errors/CacheEntryRemovedError.js +9 -0
- package/dist/query/core/errors/MachineStateError.d.ts +8 -0
- package/dist/query/core/errors/MachineStateError.js +10 -0
- package/dist/query/core/errors/MachineTransitionError.d.ts +7 -0
- package/dist/query/core/errors/MachineTransitionError.js +9 -0
- package/dist/query/core/errors/index.d.ts +3 -0
- package/dist/query/core/errors/index.js +3 -0
- package/dist/query/core/index.d.ts +8 -0
- package/dist/query/core/index.js +8 -0
- package/dist/query/core/machine/Machine.d.ts +21 -0
- package/dist/query/core/machine/Machine.js +42 -0
- package/dist/query/core/machine/MachineBase.d.ts +31 -0
- package/dist/query/core/machine/MachineBase.js +176 -0
- package/dist/query/core/machine/MachineError.d.ts +10 -0
- package/dist/query/core/machine/MachineError.js +19 -0
- package/dist/query/core/machine/MachinePending.d.ts +13 -0
- package/dist/query/core/machine/MachinePending.js +32 -0
- package/dist/query/core/machine/MachineRefreshError.d.ts +12 -0
- package/dist/query/core/machine/MachineRefreshError.js +23 -0
- package/dist/query/core/machine/MachineRefreshing.d.ts +15 -0
- package/dist/query/core/machine/MachineRefreshing.js +43 -0
- package/dist/query/core/machine/MachineSuccess.d.ts +12 -0
- package/dist/query/core/machine/MachineSuccess.js +23 -0
- package/dist/query/core/machine/MachineWithData.d.ts +25 -0
- package/dist/query/core/machine/MachineWithData.js +73 -0
- package/dist/query/core/machine/index.d.ts +9 -0
- package/dist/query/core/machine/index.js +9 -0
- package/dist/query/core/machine/machine-helpers.d.ts +9 -0
- package/dist/query/core/machine/machine-helpers.js +80 -0
- package/dist/query/core/patcher/Patcher.d.ts +30 -0
- package/dist/query/core/patcher/Patcher.js +122 -0
- package/dist/query/core/patcher/index.d.ts +1 -0
- package/dist/query/core/patcher/index.js +1 -0
- package/dist/query/core/resource/Resource.d.ts +105 -0
- package/dist/query/core/resource/Resource.js +340 -0
- package/dist/query/core/resource/ResourceAgent.d.ts +37 -0
- package/dist/query/core/resource/ResourceAgent.js +179 -0
- package/dist/query/core/resource/index.d.ts +2 -0
- package/dist/query/core/resource/index.js +2 -0
- package/dist/query/core/snapshoter/Snapshoter.d.ts +22 -0
- package/dist/query/core/snapshoter/Snapshoter.js +78 -0
- package/dist/query/core/snapshoter/index.d.ts +2 -0
- package/dist/query/core/snapshoter/index.js +1 -0
- package/dist/query/core/syncer/Syncer.d.ts +32 -0
- package/dist/query/core/syncer/Syncer.js +85 -0
- package/dist/query/core/syncer/index.d.ts +2 -0
- package/dist/query/core/syncer/index.js +1 -0
- package/dist/query/index.d.ts +5 -10
- package/dist/query/index.js +5 -13
- package/dist/query/lib/broadcastSyncDriver.d.ts +5 -0
- package/dist/query/lib/broadcastSyncDriver.js +46 -0
- package/dist/query/lib/index.d.ts +3 -0
- package/dist/query/lib/index.js +3 -0
- package/dist/{query-v2 → query}/lib/stableStringify.js +5 -3
- package/dist/query/lib/toKeyed.d.ts +11 -0
- package/dist/query/lib/toKeyed.js +18 -0
- package/dist/query/react/ReactHooksPlugin.d.ts +31 -0
- package/dist/query/react/ReactHooksPlugin.js +21 -0
- package/dist/query/react/index.d.ts +3 -0
- package/dist/query/react/index.js +3 -0
- package/dist/query/react/useCommand.d.ts +2 -0
- package/dist/query/react/useCommand.js +14 -0
- package/dist/query/react/useResource.d.ts +2 -0
- package/dist/query/react/useResource.js +16 -0
- package/dist/query/types/api.d.ts +39 -0
- package/dist/query/types/cache.d.ts +51 -0
- package/dist/query/types/command.d.ts +52 -0
- package/dist/query/types/common.d.ts +65 -0
- package/dist/query/types/index.d.ts +8 -4
- package/dist/query/types/index.js +8 -5
- package/dist/query/types/plugin-hkt.d.ts +64 -0
- package/dist/query/types/resource.d.ts +49 -0
- package/dist/query/types/snapshot.d.ts +27 -0
- package/dist/query/types/snapshot.js +2 -0
- package/dist/query/types/state.d.ts +24 -0
- package/dist/signals/base/ComputeCache.js +1 -1
- package/dist/signals/base/Devtools.js +2 -6
- package/dist/signals/signals/Computed.d.ts +1 -0
- package/dist/signals/signals/Computed.js +5 -1
- package/dist/signals/signals/Effect.d.ts +0 -4
- package/dist/signals/signals/Effect.js +0 -6
- package/dist/signals/signals/LocalState.d.ts +1 -10
- package/dist/signals/signals/LocalState.js +0 -12
- package/dist/signals/signals/Signal.d.ts +2 -8
- package/dist/signals/signals/Signal.js +1 -10
- package/dist/signals/signals/State.d.ts +2 -1
- package/dist/signals/signals/State.js +9 -0
- package/dist/signals/types/SignalOptions.d.ts +0 -2
- package/dist/signals/types/normalizeSignalOptions.js +0 -3
- package/dist/signals/types/signals.types.d.ts +3 -1
- package/docs/CHANGELOG.md +61 -31
- package/docs/migrations/0.6.0.md +224 -0
- package/docs/query/README.md +52 -562
- package/docs/query/api/README.md +59 -0
- package/docs/query/api/_CacheEntry.md +39 -0
- package/docs/query/api/_CacheMap.md +30 -0
- package/docs/query/api/_QueryCacheEntry.md +81 -0
- package/docs/query/api/command-agent.md +60 -0
- package/docs/query/api/command.md +76 -0
- package/docs/query/api/resource-agent.md +68 -0
- package/docs/query/api/resource.md +77 -0
- package/docs/query/concepts/agent.md +70 -0
- package/docs/query/concepts/architecture.md +139 -0
- package/docs/query/concepts/cache.md +81 -0
- package/docs/query/concepts/dataflows.md +473 -0
- package/docs/query/concepts/keyed.md +42 -0
- package/docs/query/concepts/machine.md +106 -0
- package/docs/query/concepts/patching.md +85 -0
- package/docs/query/usage/broadcast.md +188 -0
- package/docs/query/usage/command.md +203 -0
- package/docs/query/usage/lifecycle.md +114 -0
- package/docs/query/usage/links.md +125 -0
- package/docs/query/usage/plugins.md +96 -0
- package/docs/query/usage/resource.md +206 -0
- package/docs/query/usage/snapshot.md +80 -0
- package/docs/usage/react/README.md +45 -91
- package/package.json +6 -9
- package/dist/query/SKIP_TOKEN.d.ts +0 -1
- package/dist/query/SKIP_TOKEN.js +0 -1
- package/dist/query/api/createCommand.d.ts +0 -21
- package/dist/query/api/createCommand.js +0 -20
- package/dist/query/api/createOperation.d.ts +0 -5
- package/dist/query/api/createOperation.js +0 -6
- package/dist/query/api/createResource.d.ts +0 -3
- package/dist/query/api/createResource.js +0 -2
- package/dist/query/api/createResourceDuplicator.d.ts +0 -4
- package/dist/query/api/createResourceDuplicator.js +0 -2
- package/dist/query/api/resetAllQueriesCache.d.ts +0 -1
- package/dist/query/api/resetAllQueriesCache.js +0 -4
- package/dist/query/core/Command/Command.d.ts +0 -35
- package/dist/query/core/Command/Command.js +0 -210
- package/dist/query/core/Command/CommandAgent.d.ts +0 -19
- package/dist/query/core/Command/CommandAgent.js +0 -54
- package/dist/query/core/Command/index.d.ts +0 -2
- package/dist/query/core/Command/index.js +0 -2
- package/dist/query/core/Operation/Operation.d.ts +0 -8
- package/dist/query/core/Operation/Operation.js +0 -4
- package/dist/query/core/Operation/OperationAgent.d.ts +0 -4
- package/dist/query/core/Operation/OperationAgent.js +0 -4
- package/dist/query/core/QueriesCache.d.ts +0 -9
- package/dist/query/core/QueriesCache.js +0 -28
- package/dist/query/core/QueriesLifetimeHooks.d.ts +0 -22
- package/dist/query/core/QueriesLifetimeHooks.js +0 -86
- package/dist/query/core/ResetAllQueriesSignal.d.ts +0 -6
- package/dist/query/core/ResetAllQueriesSignal.js +0 -11
- package/dist/query/core/Resource/Resource.d.ts +0 -51
- package/dist/query/core/Resource/Resource.js +0 -232
- package/dist/query/core/Resource/ResourceAgent.d.ts +0 -35
- package/dist/query/core/Resource/ResourceAgent.js +0 -110
- package/dist/query/core/Resource/ResourceDuplicator.d.ts +0 -73
- package/dist/query/core/Resource/ResourceDuplicator.js +0 -227
- package/dist/query/core/Resource/ResourceDuplicatorAgent.d.ts +0 -35
- package/dist/query/core/Resource/ResourceDuplicatorAgent.js +0 -110
- package/dist/query/core/Resource/ResourceRef.d.ts +0 -16
- package/dist/query/core/Resource/ResourceRef.js +0 -136
- package/dist/query/lib/IndirectMap.d.ts +0 -19
- package/dist/query/lib/IndirectMap.js +0 -88
- package/dist/query/lib/ReactiveCache.d.ts +0 -62
- package/dist/query/lib/ReactiveCache.js +0 -80
- package/dist/query/react/useCommandAgent.d.ts +0 -24
- package/dist/query/react/useCommandAgent.js +0 -39
- package/dist/query/react/useOperationAgent.d.ts +0 -6
- package/dist/query/react/useOperationAgent.js +0 -6
- package/dist/query/react/useResourceAgent.d.ts +0 -6
- package/dist/query/react/useResourceAgent.js +0 -31
- package/dist/query/react/useResourceRef.d.ts +0 -5
- package/dist/query/react/useResourceRef.js +0 -13
- package/dist/query/types/Command.types.d.ts +0 -154
- package/dist/query/types/Command.types.js +0 -1
- package/dist/query/types/Operation.types.d.ts +0 -13
- package/dist/query/types/Operation.types.js +0 -1
- package/dist/query/types/Resource.types.d.ts +0 -129
- package/dist/query/types/Resource.types.js +0 -1
- package/dist/query/types/shared.types.d.ts +0 -26
- package/dist/query/types/shared.types.js +0 -1
- package/dist/query-v2/api/createApi.d.ts +0 -10
- package/dist/query-v2/api/createApi.js +0 -83
- package/dist/query-v2/core/common/CacheEntry.d.ts +0 -29
- package/dist/query-v2/core/common/CacheEntry.js +0 -71
- package/dist/query-v2/core/common/CacheMap.d.ts +0 -38
- package/dist/query-v2/core/common/CacheMap.js +0 -127
- package/dist/query-v2/core/common/LifecycleHooks.d.ts +0 -22
- package/dist/query-v2/core/common/LifecycleHooks.js +0 -104
- package/dist/query-v2/core/common/index.d.ts +0 -3
- package/dist/query-v2/core/common/index.js +0 -3
- package/dist/query-v2/core/index.d.ts +0 -3
- package/dist/query-v2/core/index.js +0 -3
- package/dist/query-v2/core/machines/Machine.d.ts +0 -14
- package/dist/query-v2/core/machines/Machine.js +0 -33
- package/dist/query-v2/core/machines/MachineError.d.ts +0 -11
- package/dist/query-v2/core/machines/MachineError.js +0 -26
- package/dist/query-v2/core/machines/MachineIdle.d.ts +0 -8
- package/dist/query-v2/core/machines/MachineIdle.js +0 -19
- package/dist/query-v2/core/machines/MachinePending.d.ts +0 -12
- package/dist/query-v2/core/machines/MachinePending.js +0 -29
- package/dist/query-v2/core/machines/MachineRefreshing.d.ts +0 -14
- package/dist/query-v2/core/machines/MachineRefreshing.js +0 -46
- package/dist/query-v2/core/machines/MachineSuccess.d.ts +0 -16
- package/dist/query-v2/core/machines/MachineSuccess.js +0 -42
- package/dist/query-v2/core/machines/MachineWithData.d.ts +0 -18
- package/dist/query-v2/core/machines/MachineWithData.js +0 -40
- package/dist/query-v2/core/machines/Patcher.d.ts +0 -20
- package/dist/query-v2/core/machines/Patcher.js +0 -104
- package/dist/query-v2/core/machines/index.d.ts +0 -8
- package/dist/query-v2/core/machines/index.js +0 -8
- package/dist/query-v2/core/resource/ResourceV2.d.ts +0 -120
- package/dist/query-v2/core/resource/ResourceV2.js +0 -464
- package/dist/query-v2/core/resource/ResourceV2Agent.d.ts +0 -26
- package/dist/query-v2/core/resource/ResourceV2Agent.js +0 -132
- package/dist/query-v2/core/resource/index.d.ts +0 -2
- package/dist/query-v2/core/resource/index.js +0 -2
- package/dist/query-v2/index.d.ts +0 -11
- package/dist/query-v2/index.js +0 -17
- package/dist/query-v2/lib/NO_VALUE.d.ts +0 -2
- package/dist/query-v2/lib/NO_VALUE.js +0 -1
- package/dist/query-v2/lib/SKIP_TOKEN.d.ts +0 -2
- package/dist/query-v2/lib/SKIP_TOKEN.js +0 -1
- package/dist/query-v2/lib/index.d.ts +0 -4
- package/dist/query-v2/lib/index.js +0 -3
- package/dist/query-v2/plugins/ReactHooksPlugin.d.ts +0 -25
- package/dist/query-v2/plugins/ReactHooksPlugin.js +0 -19
- package/dist/query-v2/plugins/types.d.ts +0 -1
- package/dist/query-v2/react/__tests__/helpers.d.ts +0 -12
- package/dist/query-v2/react/__tests__/helpers.js +0 -33
- package/dist/query-v2/react/index.d.ts +0 -2
- package/dist/query-v2/react/index.js +0 -2
- package/dist/query-v2/react/useResourceV2Agent.d.ts +0 -12
- package/dist/query-v2/react/useResourceV2Agent.js +0 -36
- package/dist/query-v2/react/useResourceV2Ref.d.ts +0 -12
- package/dist/query-v2/react/useResourceV2Ref.js +0 -57
- package/dist/query-v2/snapshot/Snapshot.d.ts +0 -13
- package/dist/query-v2/snapshot/Snapshot.js +0 -76
- package/dist/query-v2/types/agent.types.d.ts +0 -54
- package/dist/query-v2/types/api.types.d.ts +0 -22
- package/dist/query-v2/types/cache.types.d.ts +0 -37
- package/dist/query-v2/types/index.d.ts +0 -9
- package/dist/query-v2/types/index.js +0 -9
- package/dist/query-v2/types/lifecycle.types.d.ts +0 -25
- package/dist/query-v2/types/machine.types.d.ts +0 -67
- package/dist/query-v2/types/plugin.types.d.ts +0 -38
- package/dist/query-v2/types/resource.types.d.ts +0 -35
- package/dist/query-v2/types/resource.types.js +0 -1
- package/dist/query-v2/types/shared.types.d.ts +0 -20
- package/dist/query-v2/types/shared.types.js +0 -1
- package/dist/query-v2/types/snapshot.types.d.ts +0 -21
- package/dist/query-v2/types/snapshot.types.js +0 -1
- package/docs/contributing/query-v2/README.md +0 -379
- package/docs/migrations/query-v2.md +0 -171
- package/docs/query-v2/README.md +0 -280
- package/docs/query-v2/api-reference.md +0 -235
- package/docs/query-v2/optimistic-updates.md +0 -148
- package/docs/query-v2/ssr.md +0 -130
- /package/dist/{query-v2 → query}/lib/stableStringify.d.ts +0 -0
- /package/dist/{query-v2/plugins/types.js → query/types/api.js} +0 -0
- /package/dist/{query-v2/types/agent.types.js → query/types/cache.js} +0 -0
- /package/dist/{query-v2/types/api.types.js → query/types/command.js} +0 -0
- /package/dist/{query-v2/types/cache.types.js → query/types/common.js} +0 -0
- /package/dist/{query-v2/types/lifecycle.types.js → query/types/plugin-hkt.js} +0 -0
- /package/dist/{query-v2/types/machine.types.js → query/types/resource.js} +0 -0
- /package/dist/{query-v2/types/plugin.types.js → query/types/state.js} +0 -0
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { shallowEqual } from "../../../common/utils/shallowEqual";
|
|
2
|
-
import { stableStringify } from "../../../query-v2/lib/stableStringify";
|
|
3
|
-
class SerializedCacheMap {
|
|
4
|
-
_map = new Map();
|
|
5
|
-
_serializeArgs;
|
|
6
|
-
_argsMemo;
|
|
7
|
-
constructor(serializeArgs, doCacheArgs) {
|
|
8
|
-
this._serializeArgs = serializeArgs;
|
|
9
|
-
this._argsMemo = doCacheArgs ? new WeakMap() : null;
|
|
10
|
-
}
|
|
11
|
-
_serialize(args) {
|
|
12
|
-
if (this._argsMemo && typeof args === "object" && args !== null) {
|
|
13
|
-
let cached = this._argsMemo.get(args);
|
|
14
|
-
if (cached === undefined) {
|
|
15
|
-
cached = this._serializeArgs(args);
|
|
16
|
-
this._argsMemo.set(args, cached);
|
|
17
|
-
}
|
|
18
|
-
return cached;
|
|
19
|
-
}
|
|
20
|
-
return this._serializeArgs(args);
|
|
21
|
-
}
|
|
22
|
-
get(args) {
|
|
23
|
-
return this._map.get(this._serialize(args));
|
|
24
|
-
}
|
|
25
|
-
set(args, entry) {
|
|
26
|
-
this._map.set(this._serialize(args), entry);
|
|
27
|
-
}
|
|
28
|
-
getOrCreate(args, factory) {
|
|
29
|
-
const key = this._serialize(args);
|
|
30
|
-
let entry = this._map.get(key);
|
|
31
|
-
if (!entry) {
|
|
32
|
-
entry = factory();
|
|
33
|
-
this._map.set(key, entry);
|
|
34
|
-
}
|
|
35
|
-
return entry;
|
|
36
|
-
}
|
|
37
|
-
delete(args) {
|
|
38
|
-
return this._map.delete(this._serialize(args));
|
|
39
|
-
}
|
|
40
|
-
has(args) {
|
|
41
|
-
return this._map.has(this._serialize(args));
|
|
42
|
-
}
|
|
43
|
-
values() {
|
|
44
|
-
return this._map.values();
|
|
45
|
-
}
|
|
46
|
-
entries() {
|
|
47
|
-
return this._map.entries();
|
|
48
|
-
}
|
|
49
|
-
clear() {
|
|
50
|
-
this._map.clear();
|
|
51
|
-
}
|
|
52
|
-
get size() {
|
|
53
|
-
return this._map.size;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
class CompareCacheMap {
|
|
57
|
-
_items = [];
|
|
58
|
-
_compareArg;
|
|
59
|
-
constructor(compareArg) {
|
|
60
|
-
this._compareArg = compareArg;
|
|
61
|
-
}
|
|
62
|
-
_findIndex(args) {
|
|
63
|
-
for (let i = 0; i < this._items.length; i++) {
|
|
64
|
-
if (this._compareArg(this._items[i].args, args)) {
|
|
65
|
-
return i;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return -1;
|
|
69
|
-
}
|
|
70
|
-
get(args) {
|
|
71
|
-
const idx = this._findIndex(args);
|
|
72
|
-
return idx >= 0 ? this._items[idx].entry : undefined;
|
|
73
|
-
}
|
|
74
|
-
set(args, entry) {
|
|
75
|
-
const idx = this._findIndex(args);
|
|
76
|
-
if (idx >= 0) {
|
|
77
|
-
this._items[idx] = { args, entry };
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
this._items.push({ args, entry });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
getOrCreate(args, factory) {
|
|
84
|
-
const idx = this._findIndex(args);
|
|
85
|
-
if (idx >= 0) {
|
|
86
|
-
return this._items[idx].entry;
|
|
87
|
-
}
|
|
88
|
-
const entry = factory();
|
|
89
|
-
this._items.push({ args, entry });
|
|
90
|
-
return entry;
|
|
91
|
-
}
|
|
92
|
-
delete(args) {
|
|
93
|
-
const idx = this._findIndex(args);
|
|
94
|
-
if (idx >= 0) {
|
|
95
|
-
this._items.splice(idx, 1);
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
has(args) {
|
|
101
|
-
return this._findIndex(args) >= 0;
|
|
102
|
-
}
|
|
103
|
-
*values() {
|
|
104
|
-
for (const item of this._items) {
|
|
105
|
-
yield item.entry;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
*entries() {
|
|
109
|
-
for (const item of this._items) {
|
|
110
|
-
yield [item.args, item.entry];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
clear() {
|
|
114
|
-
this._items.length = 0;
|
|
115
|
-
}
|
|
116
|
-
get size() {
|
|
117
|
-
return this._items.length;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
export const CacheMap = {
|
|
121
|
-
create(options) {
|
|
122
|
-
if (options.keyStrategy === "compare") {
|
|
123
|
-
return new CompareCacheMap(options.compareArg ?? shallowEqual);
|
|
124
|
-
}
|
|
125
|
-
return new SerializedCacheMap(options.serializeArgs ?? stableStringify, options.doCacheArgs);
|
|
126
|
-
},
|
|
127
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { TOnCacheEntryAdded, TOnQueryStarted } from "../../../query-v2/types/lifecycle.types";
|
|
2
|
-
import type { TMachineInstance } from "../machines/Machine";
|
|
3
|
-
import type { CacheEntry } from "./CacheEntry";
|
|
4
|
-
export declare class LifecycleHooks<TArgs, TData, TError = Error> {
|
|
5
|
-
private readonly _onCacheEntryAdded?;
|
|
6
|
-
private readonly _onQueryStarted?;
|
|
7
|
-
private _cacheEntryState;
|
|
8
|
-
private _queryState;
|
|
9
|
-
private _serializeArgs;
|
|
10
|
-
constructor(options: {
|
|
11
|
-
onCacheEntryAdded?: TOnCacheEntryAdded<TArgs, TData>;
|
|
12
|
-
onQueryStarted?: TOnQueryStarted<TArgs, TData>;
|
|
13
|
-
serializeArgs: (args: unknown) => string;
|
|
14
|
-
});
|
|
15
|
-
fireCacheEntryAdded(args: TArgs, getCacheEntry: () => TMachineInstance<TData, TError>): void;
|
|
16
|
-
fireCacheEntryRemoved(args: TArgs): void;
|
|
17
|
-
resolveCacheDataLoaded(args: TArgs, data: TData): void;
|
|
18
|
-
fireQueryStarted(args: TArgs, getCacheEntry: () => CacheEntry<TData, TError>): void;
|
|
19
|
-
resolveQueryFulfilled(data: TData): void;
|
|
20
|
-
rejectQueryFulfilled(error: unknown): void;
|
|
21
|
-
clearAll(): void;
|
|
22
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { PromiseResolver } from "../../../common/utils/PromiseResolver";
|
|
2
|
-
export class LifecycleHooks {
|
|
3
|
-
_onCacheEntryAdded;
|
|
4
|
-
_onQueryStarted;
|
|
5
|
-
_cacheEntryState = new Map();
|
|
6
|
-
_queryState = null;
|
|
7
|
-
_serializeArgs;
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this._onCacheEntryAdded = options.onCacheEntryAdded;
|
|
10
|
-
this._onQueryStarted = options.onQueryStarted;
|
|
11
|
-
this._serializeArgs = options.serializeArgs;
|
|
12
|
-
}
|
|
13
|
-
fireCacheEntryAdded(args, getCacheEntry) {
|
|
14
|
-
if (!this._onCacheEntryAdded)
|
|
15
|
-
return;
|
|
16
|
-
const key = this._serializeArgs(args);
|
|
17
|
-
const $cacheDataLoaded = new PromiseResolver();
|
|
18
|
-
const $cacheEntryRemoved = new PromiseResolver();
|
|
19
|
-
// Prevent unhandled rejection if no consumer attaches .catch()
|
|
20
|
-
$cacheDataLoaded.promise.catch(() => { });
|
|
21
|
-
$cacheEntryRemoved.promise.catch(() => { });
|
|
22
|
-
const state = {
|
|
23
|
-
$cacheDataLoaded,
|
|
24
|
-
$cacheEntryRemoved,
|
|
25
|
-
dataLoaded: false,
|
|
26
|
-
};
|
|
27
|
-
this._cacheEntryState.set(key, state);
|
|
28
|
-
const tools = {
|
|
29
|
-
$cacheDataLoaded: $cacheDataLoaded.promise,
|
|
30
|
-
$cacheEntryRemoved: $cacheEntryRemoved.promise,
|
|
31
|
-
getCacheEntry: getCacheEntry,
|
|
32
|
-
};
|
|
33
|
-
this._onCacheEntryAdded(args, tools);
|
|
34
|
-
}
|
|
35
|
-
fireCacheEntryRemoved(args) {
|
|
36
|
-
const key = this._serializeArgs(args);
|
|
37
|
-
const state = this._cacheEntryState.get(key);
|
|
38
|
-
if (!state)
|
|
39
|
-
return;
|
|
40
|
-
if (!state.dataLoaded) {
|
|
41
|
-
state.$cacheDataLoaded.reject(new Error("Cache entry removed before data loaded"));
|
|
42
|
-
}
|
|
43
|
-
state.$cacheEntryRemoved.resolve();
|
|
44
|
-
this._cacheEntryState.delete(key);
|
|
45
|
-
}
|
|
46
|
-
resolveCacheDataLoaded(args, data) {
|
|
47
|
-
const key = this._serializeArgs(args);
|
|
48
|
-
const state = this._cacheEntryState.get(key);
|
|
49
|
-
if (!state || state.dataLoaded)
|
|
50
|
-
return;
|
|
51
|
-
state.dataLoaded = true;
|
|
52
|
-
state.$cacheDataLoaded.resolve(data);
|
|
53
|
-
}
|
|
54
|
-
fireQueryStarted(args, getCacheEntry) {
|
|
55
|
-
if (!this._onQueryStarted) {
|
|
56
|
-
// Still create state for resolving/rejecting even without callback
|
|
57
|
-
const resolver = new PromiseResolver();
|
|
58
|
-
resolver.promise.catch(() => { });
|
|
59
|
-
this._queryState = {
|
|
60
|
-
$queryFulfilled: resolver,
|
|
61
|
-
};
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const $queryFulfilled = new PromiseResolver();
|
|
65
|
-
// Prevent unhandled rejection if consumer doesn't attach .catch()
|
|
66
|
-
$queryFulfilled.promise.catch(() => { });
|
|
67
|
-
this._queryState = { $queryFulfilled };
|
|
68
|
-
const tools = {
|
|
69
|
-
$queryFulfilled: $queryFulfilled.promise,
|
|
70
|
-
getCacheEntry: () => getCacheEntry(),
|
|
71
|
-
};
|
|
72
|
-
this._onQueryStarted(args, tools);
|
|
73
|
-
}
|
|
74
|
-
resolveQueryFulfilled(data) {
|
|
75
|
-
if (!this._queryState)
|
|
76
|
-
return;
|
|
77
|
-
this._queryState.$queryFulfilled.resolve({ data, isError: false });
|
|
78
|
-
this._queryState = null;
|
|
79
|
-
}
|
|
80
|
-
rejectQueryFulfilled(error) {
|
|
81
|
-
if (!this._queryState)
|
|
82
|
-
return;
|
|
83
|
-
this._queryState.$queryFulfilled.reject(error);
|
|
84
|
-
this._queryState = null;
|
|
85
|
-
}
|
|
86
|
-
clearAll() {
|
|
87
|
-
for (const [, state] of this._cacheEntryState) {
|
|
88
|
-
if (!state.dataLoaded) {
|
|
89
|
-
state.$cacheDataLoaded.reject(new Error("Cache entry removed before data loaded"));
|
|
90
|
-
}
|
|
91
|
-
state.$cacheEntryRemoved.resolve();
|
|
92
|
-
}
|
|
93
|
-
this._cacheEntryState.clear();
|
|
94
|
-
if (this._queryState) {
|
|
95
|
-
try {
|
|
96
|
-
this._queryState.$queryFulfilled.reject(new Error("Resource reset"));
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
// Already settled
|
|
100
|
-
}
|
|
101
|
-
this._queryState = null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { TMachineStatus } from "../../../query-v2/types/machine.types";
|
|
2
|
-
import { MachineError } from "./MachineError";
|
|
3
|
-
import { MachineIdle } from "./MachineIdle";
|
|
4
|
-
import { MachinePending } from "./MachinePending";
|
|
5
|
-
import { MachineRefreshing } from "./MachineRefreshing";
|
|
6
|
-
import { MachineSuccess } from "./MachineSuccess";
|
|
7
|
-
export type TMachineInstance<TData = unknown, TError = Error> = MachineIdle | MachinePending<TData> | MachineSuccess<TData> | MachineError<TError> | MachineRefreshing<TData>;
|
|
8
|
-
export declare const Machine: {
|
|
9
|
-
readonly idle: () => MachineIdle;
|
|
10
|
-
readonly fromSnapshot: <TData>(state: {
|
|
11
|
-
status: TMachineStatus;
|
|
12
|
-
} & Record<string, unknown>) => TMachineInstance<TData>;
|
|
13
|
-
};
|
|
14
|
-
export { MachineIdle, MachinePending, MachineSuccess, MachineError, MachineRefreshing };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { NO_VALUE as NO_VALUE_VALUE } from "../../../query-v2/lib/NO_VALUE";
|
|
2
|
-
import { MachineError } from "./MachineError";
|
|
3
|
-
import { MachineIdle } from "./MachineIdle";
|
|
4
|
-
import { MachinePending } from "./MachinePending";
|
|
5
|
-
import { MachineRefreshing } from "./MachineRefreshing";
|
|
6
|
-
import { MachineSuccess } from "./MachineSuccess";
|
|
7
|
-
export const Machine = {
|
|
8
|
-
idle() {
|
|
9
|
-
return MachineIdle.create();
|
|
10
|
-
},
|
|
11
|
-
fromSnapshot(state) {
|
|
12
|
-
switch (state.status) {
|
|
13
|
-
case "idle":
|
|
14
|
-
return MachineIdle.create();
|
|
15
|
-
case "pending":
|
|
16
|
-
return MachinePending.create(state.args ?? null);
|
|
17
|
-
case "success":
|
|
18
|
-
return MachineSuccess.deploy({
|
|
19
|
-
status: "success",
|
|
20
|
-
args: state.args ?? null,
|
|
21
|
-
data: state.data,
|
|
22
|
-
updatedAt: state.updatedAt ?? Date.now(),
|
|
23
|
-
});
|
|
24
|
-
case "error":
|
|
25
|
-
return MachineError.create((state.error ?? new Error("Unknown error")), state.args ?? null);
|
|
26
|
-
case "refreshing":
|
|
27
|
-
return MachineRefreshing.create(state.data, state.args ?? null, state.updatedAt ?? Date.now(), NO_VALUE_VALUE, null);
|
|
28
|
-
default:
|
|
29
|
-
throw new Error(`Unknown machine status: ${state.status}`);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
export { MachineIdle, MachinePending, MachineSuccess, MachineError, MachineRefreshing };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { TResourceV2ErrorState } from "../../../query-v2/types/machine.types";
|
|
2
|
-
import { MachineIdle } from "./MachineIdle";
|
|
3
|
-
import { MachinePending } from "./MachinePending";
|
|
4
|
-
export declare class MachineError<TError = Error> {
|
|
5
|
-
readonly state: TResourceV2ErrorState<TError>;
|
|
6
|
-
private constructor();
|
|
7
|
-
retry(): MachinePending;
|
|
8
|
-
start(args: unknown): MachinePending;
|
|
9
|
-
reset(): MachineIdle;
|
|
10
|
-
static create<TError = Error>(error: TError, args: unknown): MachineError<TError>;
|
|
11
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { MachineIdle } from "./MachineIdle";
|
|
2
|
-
import { MachinePending } from "./MachinePending";
|
|
3
|
-
export class MachineError {
|
|
4
|
-
state;
|
|
5
|
-
constructor(error, args) {
|
|
6
|
-
this.state = {
|
|
7
|
-
status: "error",
|
|
8
|
-
args,
|
|
9
|
-
data: null,
|
|
10
|
-
error,
|
|
11
|
-
updatedAt: null,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
retry() {
|
|
15
|
-
return MachinePending.create(this.state.args);
|
|
16
|
-
}
|
|
17
|
-
start(args) {
|
|
18
|
-
return MachinePending.create(args);
|
|
19
|
-
}
|
|
20
|
-
reset() {
|
|
21
|
-
return MachineIdle.create();
|
|
22
|
-
}
|
|
23
|
-
static create(error, args) {
|
|
24
|
-
return new MachineError(error, args);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { TResourceV2IdleState } from "../../../query-v2/types/machine.types";
|
|
2
|
-
import { MachinePending } from "./MachinePending";
|
|
3
|
-
export declare class MachineIdle {
|
|
4
|
-
readonly state: TResourceV2IdleState;
|
|
5
|
-
start(args: unknown): MachinePending;
|
|
6
|
-
reset(): MachineIdle;
|
|
7
|
-
static create(): MachineIdle;
|
|
8
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { MachinePending } from "./MachinePending";
|
|
2
|
-
export class MachineIdle {
|
|
3
|
-
state = {
|
|
4
|
-
status: "idle",
|
|
5
|
-
args: null,
|
|
6
|
-
data: null,
|
|
7
|
-
error: null,
|
|
8
|
-
updatedAt: null,
|
|
9
|
-
};
|
|
10
|
-
start(args) {
|
|
11
|
-
return MachinePending.create(args);
|
|
12
|
-
}
|
|
13
|
-
reset() {
|
|
14
|
-
return this;
|
|
15
|
-
}
|
|
16
|
-
static create() {
|
|
17
|
-
return new MachineIdle();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { TResourceV2PendingState } from "../../../query-v2/types/machine.types";
|
|
2
|
-
import { MachineError } from "./MachineError";
|
|
3
|
-
import { MachineIdle } from "./MachineIdle";
|
|
4
|
-
import { MachineSuccess } from "./MachineSuccess";
|
|
5
|
-
export declare class MachinePending<TData = unknown> {
|
|
6
|
-
readonly state: TResourceV2PendingState<TData>;
|
|
7
|
-
private constructor();
|
|
8
|
-
successHappened(data: TData): MachineSuccess<TData>;
|
|
9
|
-
errorHappened<TError = Error>(error: TError): MachineError<TError>;
|
|
10
|
-
reset(): MachineIdle;
|
|
11
|
-
static create<TData = unknown>(args: unknown): MachinePending<TData>;
|
|
12
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { NO_VALUE as NO_VALUE_VALUE } from "../../../query-v2/lib/NO_VALUE";
|
|
2
|
-
import { MachineError } from "./MachineError";
|
|
3
|
-
import { MachineIdle } from "./MachineIdle";
|
|
4
|
-
import { MachineSuccess } from "./MachineSuccess";
|
|
5
|
-
export class MachinePending {
|
|
6
|
-
state;
|
|
7
|
-
constructor(args) {
|
|
8
|
-
this.state = {
|
|
9
|
-
status: "pending",
|
|
10
|
-
args,
|
|
11
|
-
data: null,
|
|
12
|
-
error: null,
|
|
13
|
-
updatedAt: null,
|
|
14
|
-
originalData: NO_VALUE_VALUE,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
successHappened(data) {
|
|
18
|
-
return MachineSuccess.create(data, this.state.args);
|
|
19
|
-
}
|
|
20
|
-
errorHappened(error) {
|
|
21
|
-
return MachineError.create(error, this.state.args);
|
|
22
|
-
}
|
|
23
|
-
reset() {
|
|
24
|
-
return MachineIdle.create();
|
|
25
|
-
}
|
|
26
|
-
static create(args) {
|
|
27
|
-
return new MachinePending(args);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { NO_VALUE } from "../../../query-v2/lib/NO_VALUE";
|
|
2
|
-
import type { TResourceV2Patch, TResourceV2RefreshingState } from "../../../query-v2/types/machine.types";
|
|
3
|
-
import { MachineIdle } from "./MachineIdle";
|
|
4
|
-
import { MachineSuccess } from "./MachineSuccess";
|
|
5
|
-
import { MachineWithData, type MachineWithDataState } from "./MachineWithData";
|
|
6
|
-
export declare class MachineRefreshing<TData = unknown> extends MachineWithData<TData> {
|
|
7
|
-
readonly state: TResourceV2RefreshingState<TData>;
|
|
8
|
-
private constructor();
|
|
9
|
-
protected cloneWith(updates: Partial<MachineWithDataState<TData>>): this;
|
|
10
|
-
successHappened(data: TData): MachineSuccess<TData>;
|
|
11
|
-
errorHappened(_error: unknown): MachineSuccess<TData>;
|
|
12
|
-
reset(): MachineIdle;
|
|
13
|
-
static create<TData>(data: TData, args: unknown, updatedAt: number, originalData?: TData | NO_VALUE, patches?: TResourceV2Patch[] | null): MachineRefreshing<TData>;
|
|
14
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { NO_VALUE as NO_VALUE_VALUE } from "../../../query-v2/lib/NO_VALUE";
|
|
2
|
-
import { MachineIdle } from "./MachineIdle";
|
|
3
|
-
import { MachineSuccess } from "./MachineSuccess";
|
|
4
|
-
import { MachineWithData } from "./MachineWithData";
|
|
5
|
-
export class MachineRefreshing extends MachineWithData {
|
|
6
|
-
state;
|
|
7
|
-
constructor(data, args, updatedAt, originalData = NO_VALUE_VALUE, patches = null) {
|
|
8
|
-
super();
|
|
9
|
-
this.state = {
|
|
10
|
-
status: "refreshing",
|
|
11
|
-
args,
|
|
12
|
-
data,
|
|
13
|
-
error: null,
|
|
14
|
-
updatedAt,
|
|
15
|
-
originalData,
|
|
16
|
-
patches,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
cloneWith(updates) {
|
|
20
|
-
return new MachineRefreshing(updates.data ?? this.state.data, this.state.args, this.state.updatedAt, updates.originalData !== undefined ? updates.originalData : this.state.originalData, updates.patches !== undefined ? updates.patches : this.state.patches);
|
|
21
|
-
}
|
|
22
|
-
successHappened(data) {
|
|
23
|
-
// Fresh data supersedes optimistic patches — abort all pending (per ADR-4, E11)
|
|
24
|
-
const cleaned = this.abortAllPendingPatches();
|
|
25
|
-
// Ignore cleaned data — fresh data from server replaces everything
|
|
26
|
-
void cleaned;
|
|
27
|
-
return MachineSuccess.create(data, this.state.args);
|
|
28
|
-
}
|
|
29
|
-
errorHappened(_error) {
|
|
30
|
-
// ADR-2: Preserve stale data on refresh error
|
|
31
|
-
// Return MachineSuccess with original stale data, same updatedAt, preserve patches
|
|
32
|
-
return MachineSuccess.deploy({
|
|
33
|
-
status: "success",
|
|
34
|
-
args: this.state.args,
|
|
35
|
-
data: this.state.data,
|
|
36
|
-
updatedAt: this.state.updatedAt,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
reset() {
|
|
40
|
-
this.abortAllPendingPatches();
|
|
41
|
-
return MachineIdle.create();
|
|
42
|
-
}
|
|
43
|
-
static create(data, args, updatedAt, originalData = NO_VALUE_VALUE, patches = null) {
|
|
44
|
-
return new MachineRefreshing(data, args, updatedAt, originalData, patches);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { TResourceV2SuccessState } from "../../../query-v2/types/machine.types";
|
|
2
|
-
import type { TResourceV2SnapshotSlice } from "../../../query-v2/types/snapshot.types";
|
|
3
|
-
import { MachineIdle } from "./MachineIdle";
|
|
4
|
-
import { MachinePending } from "./MachinePending";
|
|
5
|
-
import { MachineRefreshing } from "./MachineRefreshing";
|
|
6
|
-
import { MachineWithData, type MachineWithDataState } from "./MachineWithData";
|
|
7
|
-
export declare class MachineSuccess<TData = unknown> extends MachineWithData<TData> {
|
|
8
|
-
readonly state: TResourceV2SuccessState<TData>;
|
|
9
|
-
private constructor();
|
|
10
|
-
protected cloneWith(updates: Partial<MachineWithDataState<TData>>): this;
|
|
11
|
-
invalidate(): MachineRefreshing<TData>;
|
|
12
|
-
start(args: unknown): MachinePending<TData>;
|
|
13
|
-
reset(): MachineIdle;
|
|
14
|
-
static create<TData>(data: TData, args: unknown): MachineSuccess<TData>;
|
|
15
|
-
static deploy<TData = unknown>(snapshotSlice: TResourceV2SnapshotSlice<TData>): MachineSuccess<TData>;
|
|
16
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { NO_VALUE as NO_VALUE_VALUE } from "../../../query-v2/lib/NO_VALUE";
|
|
2
|
-
import { MachineIdle } from "./MachineIdle";
|
|
3
|
-
import { MachinePending } from "./MachinePending";
|
|
4
|
-
import { MachineRefreshing } from "./MachineRefreshing";
|
|
5
|
-
import { MachineWithData } from "./MachineWithData";
|
|
6
|
-
export class MachineSuccess extends MachineWithData {
|
|
7
|
-
state;
|
|
8
|
-
constructor(data, args, updatedAt, originalData = NO_VALUE_VALUE, patches = null) {
|
|
9
|
-
super();
|
|
10
|
-
this.state = {
|
|
11
|
-
status: "success",
|
|
12
|
-
args,
|
|
13
|
-
data,
|
|
14
|
-
error: null,
|
|
15
|
-
updatedAt,
|
|
16
|
-
originalData,
|
|
17
|
-
patches,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
cloneWith(updates) {
|
|
21
|
-
return new MachineSuccess(updates.data ?? this.state.data, this.state.args, this.state.updatedAt, updates.originalData !== undefined ? updates.originalData : this.state.originalData, updates.patches !== undefined ? updates.patches : this.state.patches);
|
|
22
|
-
}
|
|
23
|
-
invalidate() {
|
|
24
|
-
return MachineRefreshing.create(this.state.data, this.state.args, this.state.updatedAt, this.state.originalData, this.state.patches);
|
|
25
|
-
}
|
|
26
|
-
start(args) {
|
|
27
|
-
// Abort pending patches before transitioning (per ADR-4)
|
|
28
|
-
this.abortAllPendingPatches();
|
|
29
|
-
return MachinePending.create(args);
|
|
30
|
-
}
|
|
31
|
-
reset() {
|
|
32
|
-
// Abort pending patches before transitioning (per ADR-4)
|
|
33
|
-
this.abortAllPendingPatches();
|
|
34
|
-
return MachineIdle.create();
|
|
35
|
-
}
|
|
36
|
-
static create(data, args) {
|
|
37
|
-
return new MachineSuccess(data, args, Date.now());
|
|
38
|
-
}
|
|
39
|
-
static deploy(snapshotSlice) {
|
|
40
|
-
return new MachineSuccess(snapshotSlice.data, snapshotSlice.args, snapshotSlice.updatedAt);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { NO_VALUE } from "../../../query-v2/lib/NO_VALUE";
|
|
2
|
-
import type { TPatchFn, TResourceV2Patch } from "../../../query-v2/types/machine.types";
|
|
3
|
-
export interface MachineWithDataState<TData> {
|
|
4
|
-
data: TData;
|
|
5
|
-
originalData: TData | NO_VALUE;
|
|
6
|
-
patches: TResourceV2Patch[] | null;
|
|
7
|
-
}
|
|
8
|
-
export declare abstract class MachineWithData<TData = unknown> {
|
|
9
|
-
abstract readonly state: MachineWithDataState<TData>;
|
|
10
|
-
protected abstract cloneWith(updates: Partial<MachineWithDataState<TData>>): this;
|
|
11
|
-
addPatch(patch: TResourceV2Patch): this;
|
|
12
|
-
finishPatch(type: "commit" | "abort", patch: TResourceV2Patch): this;
|
|
13
|
-
createPatch<TSelf extends MachineWithData<TData>>(this: TSelf, patchFn: TPatchFn<TData>): {
|
|
14
|
-
machine: TSelf;
|
|
15
|
-
patch: TResourceV2Patch;
|
|
16
|
-
};
|
|
17
|
-
abortAllPendingPatches(): this;
|
|
18
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { NO_VALUE as NO_VALUE_VALUE } from "../../../query-v2/lib/NO_VALUE";
|
|
2
|
-
import { Patcher } from "./Patcher";
|
|
3
|
-
export class MachineWithData {
|
|
4
|
-
addPatch(patch) {
|
|
5
|
-
const { state } = this;
|
|
6
|
-
const originalData = (state.originalData === NO_VALUE_VALUE ? state.data : state.originalData);
|
|
7
|
-
const currentPatches = state.patches ? [...state.patches, patch] : [patch];
|
|
8
|
-
const resolved = Patcher.resolvePatches(originalData, currentPatches);
|
|
9
|
-
return this.cloneWith({
|
|
10
|
-
data: resolved.data,
|
|
11
|
-
originalData,
|
|
12
|
-
patches: resolved.patches.length > 0 ? resolved.patches : null,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
finishPatch(type, patch) {
|
|
16
|
-
const { state } = this;
|
|
17
|
-
const result = Patcher.finishPatch(state.originalData, state.patches, type, patch);
|
|
18
|
-
return this.cloneWith({
|
|
19
|
-
data: result.data ?? state.data,
|
|
20
|
-
originalData: result.originalData,
|
|
21
|
-
patches: result.patches,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
createPatch(patchFn) {
|
|
25
|
-
const { state } = this;
|
|
26
|
-
const dataForPatch = state.data;
|
|
27
|
-
const patch = Patcher.createPatch(patchFn, dataForPatch);
|
|
28
|
-
const machine = this.addPatch(patch);
|
|
29
|
-
return { machine, patch };
|
|
30
|
-
}
|
|
31
|
-
abortAllPendingPatches() {
|
|
32
|
-
const { state } = this;
|
|
33
|
-
const result = Patcher.abortAllPending(state.originalData, state.patches);
|
|
34
|
-
return this.cloneWith({
|
|
35
|
-
data: result.data ?? state.data,
|
|
36
|
-
originalData: result.originalData,
|
|
37
|
-
patches: result.patches,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { NO_VALUE } from "../../../query-v2/lib/NO_VALUE";
|
|
2
|
-
import type { TPatchFn, TResourceV2Patch } from "../../../query-v2/types/machine.types";
|
|
3
|
-
export declare class Patcher {
|
|
4
|
-
static createPatch<TData>(patchFn: TPatchFn<TData>, data: TData): TResourceV2Patch;
|
|
5
|
-
static resolvePatches<TData>(originalData: TData, patches: TResourceV2Patch[]): {
|
|
6
|
-
data: TData;
|
|
7
|
-
patches: TResourceV2Patch[];
|
|
8
|
-
baseData: TData;
|
|
9
|
-
};
|
|
10
|
-
static finishPatch<TData>(originalData: TData | typeof NO_VALUE, patches: TResourceV2Patch[] | null, type: "commit" | "abort", patch: TResourceV2Patch): {
|
|
11
|
-
originalData: TData | typeof NO_VALUE;
|
|
12
|
-
patches: TResourceV2Patch[] | null;
|
|
13
|
-
data: TData | null;
|
|
14
|
-
};
|
|
15
|
-
static abortAllPending<TData>(originalData: TData | typeof NO_VALUE, patches: TResourceV2Patch[] | null): {
|
|
16
|
-
originalData: TData | typeof NO_VALUE;
|
|
17
|
-
patches: TResourceV2Patch[] | null;
|
|
18
|
-
data: TData | null;
|
|
19
|
-
};
|
|
20
|
-
}
|