@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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ISyncDriver, TResourceOptions } from "../../../query/types";
|
|
2
|
+
import type { Resource } from "../resource/Resource";
|
|
3
|
+
export interface ISyncerConfig {
|
|
4
|
+
syncDriver: ISyncDriver;
|
|
5
|
+
keyPrefix: string | null;
|
|
6
|
+
defaultSync: "none" | "resources" | "all";
|
|
7
|
+
resourcesByKey: Map<string, Resource<any, any>>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Encapsulates cross-tab sync (REQ/RES) logic previously inlined in createApi.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Syncer {
|
|
13
|
+
private static readonly SYNC_TIMEOUT_MS;
|
|
14
|
+
private readonly pendingRequests;
|
|
15
|
+
private readonly syncDriver;
|
|
16
|
+
private readonly keyPrefix;
|
|
17
|
+
private readonly defaultSync;
|
|
18
|
+
private readonly resourcesByKey;
|
|
19
|
+
constructor(config: ISyncerConfig);
|
|
20
|
+
/** Connect the sync driver and start listening for messages. */
|
|
21
|
+
connect(): void;
|
|
22
|
+
/** Create a beforeQuery hook for resource config. */
|
|
23
|
+
get beforeQuery(): (resourceKey: string, entryKey: string) => Promise<{
|
|
24
|
+
data: unknown;
|
|
25
|
+
} | null>;
|
|
26
|
+
/** Check whether sync is enabled for a given resource options. */
|
|
27
|
+
isResourceSyncEnabled(opts: TResourceOptions<any, any>): boolean;
|
|
28
|
+
/** Clear pending requests and reconnect the sync driver (used by resetAll). */
|
|
29
|
+
cleanup(): void;
|
|
30
|
+
private handleIncomingSyncMessage;
|
|
31
|
+
private requestDataFromOtherTabs;
|
|
32
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encapsulates cross-tab sync (REQ/RES) logic previously inlined in createApi.
|
|
3
|
+
*/
|
|
4
|
+
export class Syncer {
|
|
5
|
+
static SYNC_TIMEOUT_MS = 150;
|
|
6
|
+
pendingRequests = new Map();
|
|
7
|
+
syncDriver;
|
|
8
|
+
keyPrefix;
|
|
9
|
+
defaultSync;
|
|
10
|
+
resourcesByKey;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.syncDriver = config.syncDriver;
|
|
13
|
+
this.keyPrefix = config.keyPrefix;
|
|
14
|
+
this.defaultSync = config.defaultSync;
|
|
15
|
+
this.resourcesByKey = config.resourcesByKey;
|
|
16
|
+
}
|
|
17
|
+
/** Connect the sync driver and start listening for messages. */
|
|
18
|
+
connect() {
|
|
19
|
+
this.syncDriver.connect(this.handleIncomingSyncMessage);
|
|
20
|
+
}
|
|
21
|
+
/** Create a beforeQuery hook for resource config. */
|
|
22
|
+
get beforeQuery() {
|
|
23
|
+
return (resourceKey, entryKey) => this.requestDataFromOtherTabs(resourceKey, entryKey);
|
|
24
|
+
}
|
|
25
|
+
/** Check whether sync is enabled for a given resource options. */
|
|
26
|
+
isResourceSyncEnabled(opts) {
|
|
27
|
+
if (opts.sync !== undefined)
|
|
28
|
+
return opts.sync;
|
|
29
|
+
return this.defaultSync === "resources" || this.defaultSync === "all";
|
|
30
|
+
}
|
|
31
|
+
/** Clear pending requests and reconnect the sync driver (used by resetAll). */
|
|
32
|
+
cleanup() {
|
|
33
|
+
for (const [, pending] of this.pendingRequests) {
|
|
34
|
+
clearTimeout(pending.timer);
|
|
35
|
+
pending.resolve(null);
|
|
36
|
+
}
|
|
37
|
+
this.pendingRequests.clear();
|
|
38
|
+
this.syncDriver.disconnect();
|
|
39
|
+
this.syncDriver.connect(this.handleIncomingSyncMessage);
|
|
40
|
+
}
|
|
41
|
+
// ── Private ──
|
|
42
|
+
handleIncomingSyncMessage = (msg) => {
|
|
43
|
+
if (msg.type === "REQ") {
|
|
44
|
+
if (msg.keys[0] !== (this.keyPrefix ?? ""))
|
|
45
|
+
return;
|
|
46
|
+
const resource = this.resourcesByKey.get(msg.keys[1]);
|
|
47
|
+
if (!resource)
|
|
48
|
+
return;
|
|
49
|
+
const entryKey = msg.keys[2];
|
|
50
|
+
const entry = resource.getEntry(entryKey);
|
|
51
|
+
if (!entry)
|
|
52
|
+
return;
|
|
53
|
+
const machine = entry.peek();
|
|
54
|
+
if (machine.state.status === "success") {
|
|
55
|
+
const data = machine.state.patchState ? machine.state.patchState.originalData : machine.state.data;
|
|
56
|
+
this.syncDriver.send({
|
|
57
|
+
type: "RES",
|
|
58
|
+
reqId: msg.reqId,
|
|
59
|
+
keys: msg.keys,
|
|
60
|
+
data,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (msg.type === "RES") {
|
|
65
|
+
const pending = this.pendingRequests.get(msg.reqId);
|
|
66
|
+
if (pending) {
|
|
67
|
+
clearTimeout(pending.timer);
|
|
68
|
+
this.pendingRequests.delete(msg.reqId);
|
|
69
|
+
pending.resolve(msg.data !== undefined ? { data: msg.data } : null);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
requestDataFromOtherTabs(resourceKey, entryKey) {
|
|
74
|
+
const reqId = crypto.randomUUID();
|
|
75
|
+
const keys = [this.keyPrefix ?? "", resourceKey, entryKey];
|
|
76
|
+
return new Promise((resolve) => {
|
|
77
|
+
const timer = setTimeout(() => {
|
|
78
|
+
this.pendingRequests.delete(reqId);
|
|
79
|
+
resolve(null);
|
|
80
|
+
}, Syncer.SYNC_TIMEOUT_MS);
|
|
81
|
+
this.pendingRequests.set(reqId, { resolve, timer });
|
|
82
|
+
this.syncDriver.send({ type: "REQ", reqId, keys });
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Syncer } from "./Syncer";
|
package/dist/query/index.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
export * from "./api
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./api/resetAllQueriesCache";
|
|
6
|
-
export * from "./SKIP_TOKEN";
|
|
1
|
+
export * from "./api";
|
|
2
|
+
export * from "./constants";
|
|
3
|
+
export * from "./lib";
|
|
4
|
+
export * from "./react";
|
|
7
5
|
export * from "./types";
|
|
8
|
-
export
|
|
9
|
-
export * from "./react/useResourceRef";
|
|
10
|
-
export * from "./api/createOperation";
|
|
11
|
-
export * from "./react/useOperationAgent";
|
|
6
|
+
export { Machine, MachineBase, MachineWithData, MachinePending, MachineSuccess, MachineError, MachineRefreshing, MachineRefreshError, } from "./core/machine";
|
package/dist/query/index.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
|
|
5
|
-
export * from "./api/createResource";
|
|
6
|
-
export * from "./api/createResourceDuplicator";
|
|
7
|
-
export * from "./api/resetAllQueriesCache";
|
|
8
|
-
export * from "./SKIP_TOKEN";
|
|
1
|
+
export * from "./api";
|
|
2
|
+
export * from "./constants";
|
|
3
|
+
export * from "./lib";
|
|
4
|
+
export * from "./react";
|
|
9
5
|
export * from "./types";
|
|
10
|
-
export
|
|
11
|
-
export * from "./react/useResourceRef";
|
|
12
|
-
// Deprecated Operation API (backward compatibility)
|
|
13
|
-
export * from "./api/createOperation";
|
|
14
|
-
export * from "./react/useOperationAgent";
|
|
6
|
+
export { Machine, MachineBase, MachineWithData, MachinePending, MachineSuccess, MachineError, MachineRefreshing, MachineRefreshError, } from "./core/machine";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
function isValidSyncMessage(msg) {
|
|
2
|
+
if (msg == null || typeof msg !== "object")
|
|
3
|
+
return false;
|
|
4
|
+
const m = msg;
|
|
5
|
+
return ((m.type === "REQ" || m.type === "RES") &&
|
|
6
|
+
typeof m.reqId === "string" &&
|
|
7
|
+
Array.isArray(m.keys) &&
|
|
8
|
+
m.keys.length === 3 &&
|
|
9
|
+
m.keys.every((k) => typeof k === "string"));
|
|
10
|
+
}
|
|
11
|
+
export function broadcastSyncDriver(options) {
|
|
12
|
+
const channelName = options?.channel ?? "rx-toolkit";
|
|
13
|
+
let bc = null;
|
|
14
|
+
return {
|
|
15
|
+
connect(onMessage) {
|
|
16
|
+
try {
|
|
17
|
+
bc = new BroadcastChannel(channelName);
|
|
18
|
+
bc.onmessage = (ev) => {
|
|
19
|
+
if (isValidSyncMessage(ev.data)) {
|
|
20
|
+
onMessage(ev.data);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
bc = null;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
disconnect() {
|
|
29
|
+
try {
|
|
30
|
+
bc?.close();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
/* noop */
|
|
34
|
+
}
|
|
35
|
+
bc = null;
|
|
36
|
+
},
|
|
37
|
+
send(message) {
|
|
38
|
+
try {
|
|
39
|
+
bc?.postMessage(message);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
/* noop — channel may be closed or unavailable */
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
function isPlainObject(value) {
|
|
2
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3
|
-
}
|
|
4
1
|
/**
|
|
5
2
|
* Deterministic JSON.stringify with sorted object keys.
|
|
6
3
|
* Used as the default serializeArgs for the 'serialize' key strategy.
|
|
@@ -9,6 +6,8 @@ function isPlainObject(value) {
|
|
|
9
6
|
* Does NOT handle: Date, Map, Set, RegExp (documented limitation).
|
|
10
7
|
*/
|
|
11
8
|
export function stableStringify(value) {
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
return "undefined";
|
|
12
11
|
return JSON.stringify(value, (_, val) => {
|
|
13
12
|
if (isPlainObject(val)) {
|
|
14
13
|
return Object.keys(val)
|
|
@@ -21,3 +20,6 @@ export function stableStringify(value) {
|
|
|
21
20
|
return val;
|
|
22
21
|
});
|
|
23
22
|
}
|
|
23
|
+
function isPlainObject(value) {
|
|
24
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Args, Keyed } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard: returns `true` if `args` is already wrapped in `Keyed<T>`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isKeyed<T>(args: Args<T>): args is Keyed<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Normalizes raw args into `Keyed<T>`.
|
|
8
|
+
* If `args` is already `Keyed`, it passes through unchanged.
|
|
9
|
+
* Otherwise wraps with `{ value: args, key: serializeFn(args) }`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function toKeyed<T>(args: Args<T>, serializeFn?: (value: T) => string): Keyed<T>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { KEYED_BRAND } from "../constants";
|
|
2
|
+
import { stableStringify } from "./stableStringify";
|
|
3
|
+
/**
|
|
4
|
+
* Type guard: returns `true` if `args` is already wrapped in `Keyed<T>`.
|
|
5
|
+
*/
|
|
6
|
+
export function isKeyed(args) {
|
|
7
|
+
return args !== null && typeof args === "object" && KEYED_BRAND in args;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes raw args into `Keyed<T>`.
|
|
11
|
+
* If `args` is already `Keyed`, it passes through unchanged.
|
|
12
|
+
* Otherwise wraps with `{ value: args, key: serializeFn(args) }`.
|
|
13
|
+
*/
|
|
14
|
+
export function toKeyed(args, serializeFn = stableStringify) {
|
|
15
|
+
if (isKeyed(args))
|
|
16
|
+
return args;
|
|
17
|
+
return { value: args, key: serializeFn(args), [KEYED_BRAND]: true };
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ArgsOrVoidOrSkip, ICommand, IPlugin, IPluginContext, IResource, PluginHKT, TCommandAgentState, TCommandOptions, TResourceAgentState, TResourceOptions } from "../../query/types";
|
|
2
|
+
/** Resource augmentation shape produced by ReactHooksPlugin. */
|
|
3
|
+
type ReactHooksResourceShape<TArgs, TData> = {
|
|
4
|
+
useResource: (args: ArgsOrVoidOrSkip<TArgs>) => TResourceAgentState<TArgs, TData>;
|
|
5
|
+
};
|
|
6
|
+
/** Command augmentation shape produced by ReactHooksPlugin. */
|
|
7
|
+
type ReactHooksCommandShape<TArgs, TData> = {
|
|
8
|
+
useCommand: (key?: string) => [trigger: (args: TArgs) => Promise<TData>, state: TCommandAgentState<TArgs, TData>];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* HKT declaration for ReactHooksPlugin.
|
|
12
|
+
* Uses `this['_TArgs']` and `this['_TData']` which become concrete when
|
|
13
|
+
* applied through `ApplyPluginResourceHKT` / `ApplyPluginCommandHKT`.
|
|
14
|
+
*/
|
|
15
|
+
export interface ReactHooksPluginHKT extends PluginHKT {
|
|
16
|
+
readonly resourceType: ReactHooksResourceShape<this["_TArgs"], this["_TData"]>;
|
|
17
|
+
readonly commandType: ReactHooksCommandShape<this["_TArgs"], this["_TData"]>;
|
|
18
|
+
}
|
|
19
|
+
export declare class ReactHooksPlugin implements IPlugin {
|
|
20
|
+
readonly name = "ReactHooksPlugin";
|
|
21
|
+
readonly _hkt: ReactHooksPluginHKT;
|
|
22
|
+
install(_context: IPluginContext): void;
|
|
23
|
+
augmentResource<TArgs, TData>(resource: IResource<TArgs, TData>, _options: TResourceOptions<TArgs, TData>): {
|
|
24
|
+
useResource: (args: ArgsOrVoidOrSkip<TArgs>) => TResourceAgentState<TArgs, TData>;
|
|
25
|
+
};
|
|
26
|
+
augmentCommand<TArgs, TData>(command: ICommand<TArgs, TData>, _options: TCommandOptions<TArgs, TData>): {
|
|
27
|
+
useCommand: (key?: string) => [trigger: (args: TArgs) => Promise<TData>, state: TCommandAgentState<TArgs, TData>];
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export declare function reactHooksPlugin(): ReactHooksPlugin;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCommand } from "./useCommand";
|
|
2
|
+
import { useResource } from "./useResource";
|
|
3
|
+
export class ReactHooksPlugin {
|
|
4
|
+
name = "ReactHooksPlugin";
|
|
5
|
+
install(_context) {
|
|
6
|
+
// no-op
|
|
7
|
+
}
|
|
8
|
+
augmentResource(resource, _options) {
|
|
9
|
+
return {
|
|
10
|
+
useResource: (args) => useResource(resource, args),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
augmentCommand(command, _options) {
|
|
14
|
+
return {
|
|
15
|
+
useCommand: (key) => useCommand(command, key),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function reactHooksPlugin() {
|
|
20
|
+
return new ReactHooksPlugin();
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useConstant, useEventHandler } from "../../common/react";
|
|
3
|
+
import { useSignal } from "../../signals/react";
|
|
4
|
+
export function useCommand(command, key) {
|
|
5
|
+
const agent = useConstant(() => command.createAgent(key), [command]);
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
if (key !== undefined) {
|
|
8
|
+
agent.setKey(key);
|
|
9
|
+
}
|
|
10
|
+
}, [agent, key]);
|
|
11
|
+
const state = useSignal(agent.state$);
|
|
12
|
+
const trigger = useEventHandler((args) => agent.trigger(args));
|
|
13
|
+
return [trigger, state];
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useConstant, useIsomorphicLayoutEffect } from "../../common/react";
|
|
2
|
+
import { useSignal } from "../../signals/react";
|
|
3
|
+
export function useResource(resource, args) {
|
|
4
|
+
const agent = useConstant(() => {
|
|
5
|
+
const r = resource.createAgent();
|
|
6
|
+
r.set(args, true);
|
|
7
|
+
return r;
|
|
8
|
+
}, [resource]);
|
|
9
|
+
if (agent.args !== args) {
|
|
10
|
+
agent.set(args, true);
|
|
11
|
+
}
|
|
12
|
+
useIsomorphicLayoutEffect(() => {
|
|
13
|
+
agent.start();
|
|
14
|
+
}, [agent]);
|
|
15
|
+
return useSignal(agent.state$);
|
|
16
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TCacheEntryAddedContext, TQueryStartedContext } from "./cache";
|
|
2
|
+
import type { ICommand, TCommandOptions } from "./command";
|
|
3
|
+
import type { CombinePluginCommandAugments, CombinePluginResourceAugments, PluginHKT } from "./plugin-hkt";
|
|
4
|
+
import type { IResource, TResourceOptions } from "./resource";
|
|
5
|
+
import type { ISyncDriver, TApiSnapshot } from "./snapshot";
|
|
6
|
+
export interface IPluginContext {
|
|
7
|
+
keyPrefix: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IPlugin {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
install(context: IPluginContext): void;
|
|
12
|
+
augmentResource?<TArgs, TData>(resource: IResource<TArgs, TData>, options: TResourceOptions<TArgs, TData>): Record<string, unknown>;
|
|
13
|
+
augmentCommand?<TArgs, TData>(command: ICommand<TArgs, TData>, options: TCommandOptions<TArgs, TData>): Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Phantom type member. Plugins that provide typed augmentations should
|
|
16
|
+
* `declare readonly _hkt: MyPluginHKT` where `MyPluginHKT extends PluginHKT`.
|
|
17
|
+
* Never set at runtime — purely a compile-time protocol.
|
|
18
|
+
*/
|
|
19
|
+
readonly _hkt?: PluginHKT;
|
|
20
|
+
}
|
|
21
|
+
export interface TCreateApiOptions<TPlugins extends readonly IPlugin[] = readonly IPlugin[]> {
|
|
22
|
+
keyPrefix?: string | null;
|
|
23
|
+
plugins?: TPlugins;
|
|
24
|
+
serializeArgs?: (args: unknown) => string;
|
|
25
|
+
resourceRetentionTime?: number | false;
|
|
26
|
+
commandRetentionTime?: number | false;
|
|
27
|
+
initialSnapshot?: TApiSnapshot | null;
|
|
28
|
+
snapshotValidTime?: number | false;
|
|
29
|
+
defaultSync?: "none" | "resources" | "all";
|
|
30
|
+
syncDriver?: ISyncDriver;
|
|
31
|
+
onCacheEntryAdded?: (args: unknown, ctx: TCacheEntryAddedContext<unknown, unknown>) => void;
|
|
32
|
+
onQueryStarted?: (args: unknown, ctx: TQueryStartedContext<unknown, unknown>) => void | Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export interface IApi<TPlugins extends readonly IPlugin[] = readonly IPlugin[]> {
|
|
35
|
+
createResource<TArgs = void, TData = unknown>(options: TResourceOptions<TArgs, TData>): IResource<TArgs, TData> & CombinePluginResourceAugments<TPlugins, TArgs, TData>;
|
|
36
|
+
createCommand<TArgs = void, TData = unknown>(options: TCommandOptions<TArgs, TData>): ICommand<TArgs, TData> & CombinePluginCommandAugments<TPlugins, TArgs, TData>;
|
|
37
|
+
getSnapshot(): TApiSnapshot;
|
|
38
|
+
resetAll(): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Subject } from "rxjs";
|
|
2
|
+
import type { Machine } from "../../query/core/machine";
|
|
3
|
+
import type { ReadableSignalFnLike } from "../../signals/types";
|
|
4
|
+
import type { IPatchHandle, Keyed } from "./common";
|
|
5
|
+
export interface ICacheEntryOptions<TState> {
|
|
6
|
+
retentionTime: number | false;
|
|
7
|
+
devtoolsKey: string;
|
|
8
|
+
beforeDevtoolsPush?: (state: TState) => TState;
|
|
9
|
+
}
|
|
10
|
+
export interface ICacheEntry<TState> {
|
|
11
|
+
readonly completed$: Subject<void>;
|
|
12
|
+
readonly state$: ReadableSignalFnLike<TState>;
|
|
13
|
+
peek(): TState;
|
|
14
|
+
set(state: TState): void;
|
|
15
|
+
complete(): void;
|
|
16
|
+
}
|
|
17
|
+
export interface ICacheMap<TValue> {
|
|
18
|
+
readonly size: number;
|
|
19
|
+
get(key: string): TValue | undefined;
|
|
20
|
+
set(key: string, value: TValue): void;
|
|
21
|
+
delete(key: string): boolean;
|
|
22
|
+
has(key: string): boolean;
|
|
23
|
+
clear(): void;
|
|
24
|
+
values(): IterableIterator<TValue>;
|
|
25
|
+
}
|
|
26
|
+
export interface IQueryCacheEntryOptions<TArgs, TData> {
|
|
27
|
+
queryFn: (keyedArgs: Keyed<TArgs>, signal: AbortSignal) => Promise<TData>;
|
|
28
|
+
retentionTime: number | false;
|
|
29
|
+
keyedArgs: Keyed<TArgs>;
|
|
30
|
+
resourceKey?: string;
|
|
31
|
+
initialMachine?: Machine<TArgs, TData>;
|
|
32
|
+
beforeDevtoolsPush?: (machine: Machine<TArgs, TData>) => any;
|
|
33
|
+
}
|
|
34
|
+
export interface IQueryCacheEntry<TArgs, TData> extends ICacheEntry<Machine<TArgs, TData>> {
|
|
35
|
+
readonly keyedArgs: Keyed<TArgs>;
|
|
36
|
+
readonly machine$: ReadableSignalFnLike<Machine<TArgs, TData>>;
|
|
37
|
+
refresh(): void;
|
|
38
|
+
retry(): void;
|
|
39
|
+
createPatch(patchFn: (data: TData) => void): IPatchHandle | null;
|
|
40
|
+
}
|
|
41
|
+
export interface TCacheEntryAddedContext<TArgs, TData> {
|
|
42
|
+
entry: IQueryCacheEntry<TArgs, TData>;
|
|
43
|
+
$cacheDataLoaded: Promise<TData>;
|
|
44
|
+
$cacheEntryRemoved: Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export interface TQueryStartedContext<TArgs, TData> {
|
|
47
|
+
entry: IQueryCacheEntry<TArgs, TData>;
|
|
48
|
+
$queryFulfilled: Promise<{
|
|
49
|
+
data: TData;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ReadableSignalFnLike } from "../../signals/types";
|
|
2
|
+
import type { IQueryCacheEntry, TCacheEntryAddedContext, TQueryStartedContext } from "./cache";
|
|
3
|
+
import type { Args } from "./common";
|
|
4
|
+
import type { IResource } from "./resource";
|
|
5
|
+
import type { TCommandAgentState } from "./state";
|
|
6
|
+
export interface TLinkConfig<TArgs, TData, TResArgs, TResData> {
|
|
7
|
+
resource: IResource<TResArgs, TResData>;
|
|
8
|
+
forwardArgs: (commandArgs: TArgs) => TResArgs | undefined;
|
|
9
|
+
invalidate?: boolean;
|
|
10
|
+
optimisticUpdate?: (draft: TResData, commandArgs: TArgs) => void;
|
|
11
|
+
update?: (draft: TResData, commandArgs: TArgs, result: TData) => void;
|
|
12
|
+
}
|
|
13
|
+
export type TLinksInput<TArgs, TData> = TLinkConfig<TArgs, TData, any, any>[] | ((link: (config: TLinkConfig<TArgs, TData, any, any>) => void) => void);
|
|
14
|
+
export interface ICommand<TArgs, TData> {
|
|
15
|
+
trigger(args: Args<TArgs>, key?: string): Promise<TData>;
|
|
16
|
+
getEntry(key: string): IQueryCacheEntry<TArgs, TData> | null;
|
|
17
|
+
getEntry$(key: string): IQueryCacheEntry<TArgs, TData> | null;
|
|
18
|
+
createAgent(key?: string): ICommandAgent<TArgs, TData>;
|
|
19
|
+
}
|
|
20
|
+
export interface ICommandAgent<TArgs, TData> {
|
|
21
|
+
state$: ReadableSignalFnLike<TCommandAgentState<TArgs, TData>>;
|
|
22
|
+
trigger(args: Args<TArgs>, key?: string): Promise<TData>;
|
|
23
|
+
setKey(key: string): void;
|
|
24
|
+
}
|
|
25
|
+
export interface TCommandOptions<TArgs, TData> {
|
|
26
|
+
queryFn: (args: TArgs) => Promise<TData>;
|
|
27
|
+
key?: string;
|
|
28
|
+
links?: TLinksInput<TArgs, TData>;
|
|
29
|
+
retentionTime?: number | false;
|
|
30
|
+
onCacheEntryAdded?: (args: TArgs, ctx: TCacheEntryAddedContext<TArgs, TData>) => void;
|
|
31
|
+
onQueryStarted?: (args: TArgs, ctx: TQueryStartedContext<TArgs, TData>) => void | Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Configuration object for creating a {@link Command}.
|
|
35
|
+
*
|
|
36
|
+
* @template TArgs - The argument type accepted by the mutation function.
|
|
37
|
+
* @template TData - The data type returned by the mutation function.
|
|
38
|
+
*/
|
|
39
|
+
export interface ICommandConfig<TArgs, TData> {
|
|
40
|
+
/** Function that executes the mutation. */
|
|
41
|
+
queryFn: (args: TArgs) => Promise<TData>;
|
|
42
|
+
/** Optional prefix for cache keys and devtools display. */
|
|
43
|
+
key?: string;
|
|
44
|
+
/** Link descriptors that bind this command to related resources. */
|
|
45
|
+
links: TLinkConfig<TArgs, TData, any, any>[];
|
|
46
|
+
/** Time (ms) to keep a cache entry after subscribers drop off. `false` disables auto-removal. */
|
|
47
|
+
retentionTime: number | false;
|
|
48
|
+
/** Called when a new cache entry is created. See lifecycle hooks documentation. */
|
|
49
|
+
onCacheEntryAdded?: (args: TArgs, ctx: TCacheEntryAddedContext<TArgs, TData>) => void;
|
|
50
|
+
/** Called every time `queryFn` starts. See lifecycle hooks documentation. */
|
|
51
|
+
onQueryStarted?: (args: TArgs, ctx: TQueryStartedContext<TArgs, TData>) => void | Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Patch } from "immer";
|
|
2
|
+
import type { KEYED_BRAND, SKIP } from "../constants";
|
|
3
|
+
export type Keyed<T> = {
|
|
4
|
+
value: T;
|
|
5
|
+
key: string;
|
|
6
|
+
readonly [KEYED_BRAND]: true;
|
|
7
|
+
};
|
|
8
|
+
export type Args<TArgs> = TArgs | Keyed<TArgs>;
|
|
9
|
+
export type ArgsOrVoid<TArgs> = TArgs extends void ? void : Args<TArgs>;
|
|
10
|
+
export type ArgsOrVoidOrSkip<TArgs> = TArgs extends void ? void | typeof SKIP : Args<TArgs> | typeof SKIP;
|
|
11
|
+
export type TMachineStatus = "pending" | "success" | "error" | "refreshing" | "refresh-error";
|
|
12
|
+
export interface TPendingState<TArgs> {
|
|
13
|
+
status: "pending";
|
|
14
|
+
args: TArgs;
|
|
15
|
+
data: null;
|
|
16
|
+
error: null;
|
|
17
|
+
updatedAt: null;
|
|
18
|
+
}
|
|
19
|
+
export interface TSuccessState<TArgs, TData> {
|
|
20
|
+
status: "success";
|
|
21
|
+
args: TArgs;
|
|
22
|
+
data: TData;
|
|
23
|
+
error: null;
|
|
24
|
+
updatedAt: number;
|
|
25
|
+
patchState: TPatchState<TData> | null;
|
|
26
|
+
}
|
|
27
|
+
export interface TErrorState<TArgs> {
|
|
28
|
+
status: "error";
|
|
29
|
+
args: TArgs;
|
|
30
|
+
data: null;
|
|
31
|
+
error: unknown;
|
|
32
|
+
updatedAt: null;
|
|
33
|
+
}
|
|
34
|
+
export interface TRefreshingState<TArgs, TData> {
|
|
35
|
+
status: "refreshing";
|
|
36
|
+
args: TArgs;
|
|
37
|
+
data: TData;
|
|
38
|
+
error: null;
|
|
39
|
+
updatedAt: number;
|
|
40
|
+
patchState: TPatchState<TData> | null;
|
|
41
|
+
}
|
|
42
|
+
export interface TRefreshErrorState<TArgs, TData> {
|
|
43
|
+
status: "refresh-error";
|
|
44
|
+
args: TArgs;
|
|
45
|
+
data: TData;
|
|
46
|
+
error: unknown;
|
|
47
|
+
updatedAt: number;
|
|
48
|
+
patchState: TPatchState<TData> | null;
|
|
49
|
+
}
|
|
50
|
+
export type TMachineState<TArgs, TData> = TPendingState<TArgs> | TSuccessState<TArgs, TData> | TErrorState<TArgs> | TRefreshingState<TArgs, TData> | TRefreshErrorState<TArgs, TData>;
|
|
51
|
+
export interface TPatchEntry {
|
|
52
|
+
forward: Patch[];
|
|
53
|
+
inverse: Patch[];
|
|
54
|
+
status: "pending" | "committed" | "aborted";
|
|
55
|
+
}
|
|
56
|
+
export interface TPatchState<TData> {
|
|
57
|
+
originalData: TData;
|
|
58
|
+
patches: TPatchEntry[];
|
|
59
|
+
isConsistencyViolation: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface IPatchHandle {
|
|
62
|
+
commit(): void;
|
|
63
|
+
abort(): void;
|
|
64
|
+
}
|
|
65
|
+
export type TAgentStatus = TMachineStatus | "idle";
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
1
|
+
export * from "./common";
|
|
2
|
+
export * from "./cache";
|
|
3
|
+
export * from "./state";
|
|
4
|
+
export * from "./snapshot";
|
|
5
|
+
export * from "./resource";
|
|
6
|
+
export * from "./command";
|
|
7
|
+
export * from "./api";
|
|
8
|
+
export * from "./plugin-hkt";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
|
|
5
|
-
export * from "./
|
|
1
|
+
export * from "./common";
|
|
2
|
+
export * from "./cache";
|
|
3
|
+
export * from "./state";
|
|
4
|
+
export * from "./snapshot";
|
|
5
|
+
export * from "./resource";
|
|
6
|
+
export * from "./command";
|
|
7
|
+
export * from "./api";
|
|
8
|
+
export * from "./plugin-hkt";
|