@fozy-labs/rx-toolkit 0.5.4 → 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 +48 -2
- 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 +5 -7
- 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,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,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,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,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
|
-
}
|