@fozy-labs/rx-toolkit 0.5.3-rc.1 → 0.5.3
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 +21 -21
- package/README.md +143 -137
- package/dist/common/devtools/combineDevtools.js +3 -3
- package/dist/common/devtools/index.d.ts +3 -3
- package/dist/common/devtools/index.js +3 -3
- package/dist/common/devtools/reduxDevtools.d.ts +1 -1
- package/dist/common/devtools/reduxDevtools.js +17 -17
- package/dist/common/devtools/types.d.ts +0 -6
- package/dist/common/options/DefaultOptions.d.ts +1 -1
- package/dist/common/options/SharedOptions.d.ts +3 -2
- package/dist/common/options/SharedOptions.js +6 -0
- package/dist/common/options/index.d.ts +1 -1
- package/dist/common/options/index.js +1 -1
- package/dist/common/react/index.d.ts +2 -2
- package/dist/common/react/index.js +2 -2
- package/dist/common/react/useConstant.js +1 -1
- package/dist/common/utils/deepEqual.js +1 -1
- package/dist/common/utils/index.d.ts +3 -3
- package/dist/common/utils/index.js +3 -3
- package/dist/common/utils/shallowEqual.js +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +8 -7
- package/dist/query/SKIP_TOKEN.js +1 -1
- package/dist/query/api/createCommand.d.ts +21 -0
- package/dist/query/api/createCommand.js +20 -0
- package/dist/query/api/createOperation.d.ts +5 -3
- package/dist/query/api/createOperation.js +6 -2
- package/dist/query/api/createResource.d.ts +2 -2
- package/dist/query/api/createResourceDuplicator.d.ts +2 -2
- package/dist/query/core/Command/Command.d.ts +35 -0
- package/dist/query/core/{Opertation/Operation.js → Command/Command.js} +13 -14
- package/dist/query/core/Command/CommandAgent.d.ts +19 -0
- package/dist/query/core/{Opertation/OperationAgent.js → Command/CommandAgent.js} +13 -13
- package/dist/query/core/Command/index.d.ts +2 -0
- package/dist/query/core/Command/index.js +2 -0
- package/dist/query/core/Operation/Operation.d.ts +8 -0
- package/dist/query/core/Operation/Operation.js +4 -0
- package/dist/query/core/Operation/OperationAgent.d.ts +4 -0
- package/dist/query/core/Operation/OperationAgent.js +4 -0
- package/dist/query/core/QueriesCache.d.ts +2 -2
- package/dist/query/core/QueriesCache.js +1 -1
- package/dist/query/core/QueriesLifetimeHooks.d.ts +1 -1
- package/dist/query/core/QueriesLifetimeHooks.js +7 -7
- package/dist/query/core/Resource/Resource.d.ts +16 -16
- package/dist/query/core/Resource/Resource.js +7 -7
- package/dist/query/core/Resource/ResourceAgent.d.ts +2 -2
- package/dist/query/core/Resource/ResourceAgent.js +3 -3
- package/dist/query/core/Resource/ResourceDuplicator.d.ts +17 -17
- package/dist/query/core/Resource/ResourceDuplicator.js +18 -20
- package/dist/query/core/Resource/ResourceDuplicatorAgent.d.ts +6 -6
- package/dist/query/core/Resource/ResourceDuplicatorAgent.js +3 -3
- package/dist/query/core/Resource/ResourceRef.d.ts +2 -2
- package/dist/query/core/Resource/ResourceRef.js +12 -12
- package/dist/query/index.d.ts +11 -8
- package/dist/query/index.js +14 -8
- package/dist/query/lib/IndirectMap.js +4 -4
- package/dist/query/lib/ReactiveCache.d.ts +1 -1
- package/dist/query/react/useCommandAgent.d.ts +24 -0
- package/dist/query/react/useCommandAgent.js +39 -0
- package/dist/query/react/useOperationAgent.d.ts +6 -8
- package/dist/query/react/useOperationAgent.js +6 -23
- package/dist/query/react/useResourceAgent.d.ts +4 -4
- package/dist/query/react/useResourceAgent.js +1 -1
- package/dist/query/react/useResourceRef.d.ts +3 -3
- package/dist/query/react/useResourceRef.js +7 -2
- package/dist/query/types/Command.types.d.ts +154 -0
- package/dist/query/types/Command.types.js +1 -0
- package/dist/query/types/Operation.types.d.ts +13 -154
- package/dist/query/types/Resource.types.d.ts +7 -5
- package/dist/query/types/index.d.ts +4 -3
- package/dist/query/types/index.js +5 -3
- package/dist/query-v2/api/createApi.d.ts +10 -0
- package/dist/query-v2/api/createApi.js +83 -0
- package/dist/query-v2/core/common/CacheEntry.d.ts +29 -0
- package/dist/query-v2/core/common/CacheEntry.js +71 -0
- package/dist/query-v2/core/common/CacheMap.d.ts +38 -0
- package/dist/query-v2/core/common/CacheMap.js +127 -0
- package/dist/query-v2/core/common/LifecycleHooks.d.ts +22 -0
- package/dist/query-v2/core/common/LifecycleHooks.js +104 -0
- package/dist/query-v2/core/common/index.d.ts +3 -0
- package/dist/query-v2/core/common/index.js +3 -0
- package/dist/query-v2/core/index.d.ts +3 -0
- package/dist/query-v2/core/index.js +3 -0
- package/dist/query-v2/core/machines/Machine.d.ts +14 -0
- package/dist/query-v2/core/machines/Machine.js +33 -0
- package/dist/query-v2/core/machines/MachineError.d.ts +11 -0
- package/dist/query-v2/core/machines/MachineError.js +26 -0
- package/dist/query-v2/core/machines/MachineIdle.d.ts +8 -0
- package/dist/query-v2/core/machines/MachineIdle.js +19 -0
- package/dist/query-v2/core/machines/MachinePending.d.ts +12 -0
- package/dist/query-v2/core/machines/MachinePending.js +29 -0
- package/dist/query-v2/core/machines/MachineRefreshing.d.ts +14 -0
- package/dist/query-v2/core/machines/MachineRefreshing.js +46 -0
- package/dist/query-v2/core/machines/MachineSuccess.d.ts +16 -0
- package/dist/query-v2/core/machines/MachineSuccess.js +42 -0
- package/dist/query-v2/core/machines/MachineWithData.d.ts +18 -0
- package/dist/query-v2/core/machines/MachineWithData.js +40 -0
- package/dist/query-v2/core/machines/Patcher.d.ts +20 -0
- package/dist/query-v2/core/machines/Patcher.js +104 -0
- package/dist/query-v2/core/machines/index.d.ts +8 -0
- package/dist/query-v2/core/machines/index.js +8 -0
- package/dist/query-v2/core/resource/ResourceV2.d.ts +120 -0
- package/dist/query-v2/core/resource/ResourceV2.js +464 -0
- package/dist/query-v2/core/resource/ResourceV2Agent.d.ts +26 -0
- package/dist/query-v2/core/resource/ResourceV2Agent.js +132 -0
- package/dist/query-v2/core/resource/index.d.ts +2 -0
- package/dist/query-v2/core/resource/index.js +2 -0
- package/dist/query-v2/index.d.ts +11 -0
- package/dist/query-v2/index.js +17 -0
- package/dist/query-v2/lib/NO_VALUE.d.ts +2 -0
- package/dist/query-v2/lib/NO_VALUE.js +1 -0
- package/dist/query-v2/lib/SKIP_TOKEN.d.ts +2 -0
- package/dist/query-v2/lib/SKIP_TOKEN.js +1 -0
- package/dist/query-v2/lib/index.d.ts +4 -0
- package/dist/query-v2/lib/index.js +3 -0
- package/dist/query-v2/lib/stableStringify.d.ts +8 -0
- package/dist/query-v2/lib/stableStringify.js +23 -0
- package/dist/query-v2/plugins/ReactHooksPlugin.d.ts +25 -0
- package/dist/query-v2/plugins/ReactHooksPlugin.js +19 -0
- package/dist/query-v2/plugins/types.d.ts +1 -0
- package/dist/query-v2/plugins/types.js +1 -0
- package/dist/query-v2/react/__tests__/helpers.d.ts +12 -0
- package/dist/query-v2/react/__tests__/helpers.js +33 -0
- package/dist/query-v2/react/index.d.ts +2 -0
- package/dist/query-v2/react/index.js +2 -0
- package/dist/query-v2/react/useResourceV2Agent.d.ts +12 -0
- package/dist/query-v2/react/useResourceV2Agent.js +36 -0
- package/dist/query-v2/react/useResourceV2Ref.d.ts +12 -0
- package/dist/query-v2/react/useResourceV2Ref.js +57 -0
- package/dist/query-v2/snapshot/Snapshot.d.ts +13 -0
- package/dist/query-v2/snapshot/Snapshot.js +76 -0
- package/dist/query-v2/types/agent.types.d.ts +54 -0
- package/dist/query-v2/types/agent.types.js +1 -0
- package/dist/query-v2/types/api.types.d.ts +22 -0
- package/dist/query-v2/types/api.types.js +1 -0
- package/dist/query-v2/types/cache.types.d.ts +37 -0
- package/dist/query-v2/types/cache.types.js +1 -0
- package/dist/query-v2/types/index.d.ts +9 -0
- package/dist/query-v2/types/index.js +9 -0
- package/dist/query-v2/types/lifecycle.types.d.ts +25 -0
- package/dist/query-v2/types/lifecycle.types.js +1 -0
- package/dist/query-v2/types/machine.types.d.ts +67 -0
- package/dist/query-v2/types/machine.types.js +1 -0
- package/dist/query-v2/types/plugin.types.d.ts +38 -0
- package/dist/query-v2/types/plugin.types.js +1 -0
- package/dist/query-v2/types/resource.types.d.ts +35 -0
- package/dist/query-v2/types/resource.types.js +1 -0
- package/dist/query-v2/types/shared.types.d.ts +20 -0
- package/dist/query-v2/types/shared.types.js +1 -0
- package/dist/query-v2/types/snapshot.types.d.ts +21 -0
- package/dist/query-v2/types/snapshot.types.js +1 -0
- package/dist/signals/base/Batcher.js +9 -5
- package/dist/signals/base/ComputeCache.js +3 -3
- package/dist/signals/base/DependencyTracker.js +1 -1
- package/dist/signals/base/Devtools.d.ts +3 -2
- package/dist/signals/base/Devtools.js +54 -27
- package/dist/signals/base/Indexer.js +1 -1
- package/dist/signals/base/ReadonlySignal.js +1 -1
- package/dist/signals/base/SyncObservable.d.ts +1 -2
- package/dist/signals/base/SyncObservable.js +2 -5
- package/dist/signals/base/index.d.ts +6 -6
- package/dist/signals/base/index.js +6 -6
- package/dist/signals/index.d.ts +5 -4
- package/dist/signals/index.js +5 -4
- package/dist/signals/operators/index.d.ts +1 -1
- package/dist/signals/operators/index.js +1 -1
- package/dist/signals/operators/signalize.d.ts +1 -1
- package/dist/signals/react/index.d.ts +1 -1
- package/dist/signals/react/index.js +1 -1
- package/dist/signals/signals/Computed.d.ts +3 -4
- package/dist/signals/signals/Computed.js +18 -10
- package/dist/signals/signals/Effect.js +2 -1
- package/dist/signals/signals/LocalState.d.ts +44 -0
- package/dist/signals/signals/{LocalSignal.js → LocalState.js} +62 -28
- package/dist/signals/signals/Signal.d.ts +8 -7
- package/dist/signals/signals/Signal.js +4 -1
- package/dist/signals/signals/State.d.ts +4 -5
- package/dist/signals/signals/State.js +23 -9
- package/dist/signals/signals/index.d.ts +5 -5
- package/dist/signals/signals/index.js +5 -6
- package/dist/signals/types/SignalOptions.d.ts +16 -0
- package/dist/signals/types/SignalOptions.js +1 -0
- package/dist/signals/types/index.d.ts +3 -1
- package/dist/signals/types/index.js +3 -1
- package/dist/signals/types/normalizeSignalOptions.d.ts +2 -0
- package/dist/signals/types/normalizeSignalOptions.js +10 -0
- package/dist/signals/types/signals.types.d.ts +6 -2
- package/docs/CHANGELOG.md +111 -32
- package/docs/CONTRIBUTING.md +230 -0
- package/docs/contributing/ai-assisted-development.md +47 -0
- package/docs/contributing/query-v2/README.md +379 -0
- package/docs/{release → contributing/release}/README.md +59 -59
- package/docs/devtools/README.md +228 -228
- package/docs/migrations/0.5.0.md +58 -58
- package/docs/migrations/query-v2.md +171 -0
- package/docs/options/README.md +92 -90
- package/docs/query/README.md +575 -571
- package/docs/query-v2/README.md +280 -0
- package/docs/query-v2/api-reference.md +235 -0
- package/docs/query-v2/optimistic-updates.md +148 -0
- package/docs/query-v2/ssr.md +130 -0
- package/docs/signals/README.md +300 -295
- package/docs/usage/react/README.md +309 -307
- package/package.json +86 -63
- package/dist/query/core/Opertation/Operation.d.ts +0 -35
- package/dist/query/core/Opertation/OperationAgent.d.ts +0 -19
- package/dist/signals/signals/LocalSignal.d.ts +0 -32
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Command } from "../../query/core/Command/Command";
|
|
2
|
+
/**
|
|
3
|
+
* Создаёт команду (command) — единицу мутирующего запроса.
|
|
4
|
+
*
|
|
5
|
+
* Команда инкапсулирует асинхронную операцию с поддержкой кеширования,
|
|
6
|
+
* связывания с ресурсами (link) и оптимистичных обновлений.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const updateUser = createCommand({
|
|
11
|
+
* queryFn: (args: { id: string; name: string }) => api.updateUser(args),
|
|
12
|
+
* link: (link) => link({
|
|
13
|
+
* resource: userResource,
|
|
14
|
+
* forwardArgs: (args) => ({ id: args.id }),
|
|
15
|
+
* invalidate: true,
|
|
16
|
+
* }),
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const createCommand = ((options) => new Command(options));
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Use `createCommand` instead. Will be removed in v0.6.0.
|
|
3
|
+
* @see createCommand
|
|
4
|
+
*/
|
|
5
|
+
export declare const createOperation: <ARGS, RESULT, SELECTED = never>(options: import("..").CommandCreateOptions<import("..").CommandDefinition<ARGS, RESULT, SELECTED>>) => import("../core/Command").Command<import("..").CommandDefinition<ARGS, RESULT, SELECTED>>;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { createCommand } from "./createCommand";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use `createCommand` instead. Will be removed in v0.6.0.
|
|
4
|
+
* @see createCommand
|
|
5
|
+
*/
|
|
6
|
+
export const createOperation = createCommand;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { Resource } from "../../query/core/Resource/Resource";
|
|
2
|
+
import type { ResourceCreateOptions, ResourceDefinition } from "../../query/types";
|
|
3
3
|
export declare const createResource: <ARGS, RESULT, SELECTED = never>(options: ResourceCreateOptions<ResourceDefinition<ARGS, RESULT, SELECTED>>) => Resource<ResourceDefinition<ARGS, RESULT, SELECTED>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DuplicatorOptions, ResourceDuplicator
|
|
2
|
-
import { ResourceDefinition } from "
|
|
1
|
+
import { DuplicatorDefinition, DuplicatorOptions, ResourceDuplicator } from "../../query/core/Resource/ResourceDuplicator";
|
|
2
|
+
import { ResourceDefinition } from "../../query/types";
|
|
3
3
|
export declare const createResourceDuplicator: <ARGS, RESULT, SELECTED = never>(options: DuplicatorOptions<DuplicatorDefinition<ResourceDefinition<ARGS, RESULT, SELECTED>>>) => ResourceDuplicator<DuplicatorDefinition<ResourceDefinition<ARGS, RESULT, SELECTED>>>;
|
|
4
4
|
export type ResourceDuplicatorCreateFn<ARGS, RESULT, SELECTED = never> = (options: DuplicatorOptions<DuplicatorDefinition<ResourceDefinition<ARGS, RESULT, SELECTED>>>) => ResourceDuplicator<DuplicatorDefinition<ResourceDefinition<ARGS, RESULT, SELECTED>>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReactiveCache } from "../../../query/lib/ReactiveCache";
|
|
2
|
+
import type { CommandCreateOptions, CommandDefinition, CommandInstance, FallbackOnNever } from "../../../query/types";
|
|
3
|
+
import { CommandAgent } from "./CommandAgent";
|
|
4
|
+
export type CoreCommandQueryState<D extends CommandDefinition> = {
|
|
5
|
+
arg: D["Args"] | null;
|
|
6
|
+
data: FallbackOnNever<D["Selected"], D["Result"]> | null;
|
|
7
|
+
error: unknown | null;
|
|
8
|
+
isError: boolean;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
isRepeating: boolean;
|
|
11
|
+
isDone: boolean;
|
|
12
|
+
isSuccess: boolean;
|
|
13
|
+
isInitiated: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare class Command<D extends CommandDefinition> implements CommandInstance<D> {
|
|
16
|
+
private readonly _options;
|
|
17
|
+
private _queriesCache;
|
|
18
|
+
private _hooks;
|
|
19
|
+
private _links;
|
|
20
|
+
private _DEFAULT_CACHE_LIFETIME;
|
|
21
|
+
constructor(_options: CommandCreateOptions<D>);
|
|
22
|
+
private _createLinks;
|
|
23
|
+
createAgent(): CommandAgent<D>;
|
|
24
|
+
getQueryCache(args: D["Args"]): ReactiveCache<CoreCommandQueryState<D>> | undefined;
|
|
25
|
+
createQueryCache(args: D["Args"], state?: CoreCommandQueryState<D>): ReactiveCache<CoreCommandQueryState<D>>;
|
|
26
|
+
initiate(args: D["Args"], options?: {
|
|
27
|
+
cache?: ReactiveCache<CoreCommandQueryState<D>>;
|
|
28
|
+
}): ReactiveCache<CoreCommandQueryState<D>>;
|
|
29
|
+
private _initiate;
|
|
30
|
+
/**
|
|
31
|
+
* Используется для обратной совместимости
|
|
32
|
+
* @deprecated
|
|
33
|
+
*/
|
|
34
|
+
mutate(args: D["Args"]): Promise<D["Data"]>;
|
|
35
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { PromiseResolver } from "../../../common/utils";
|
|
2
|
+
import { ResetAllQueriesSignal } from "../../../query/core/ResetAllQueriesSignal";
|
|
2
3
|
import { Batcher } from "../../../signals";
|
|
3
4
|
import { QueriesCache } from "../QueriesCache";
|
|
4
5
|
import { QueriesLifetimeHooks } from "../QueriesLifetimeHooks";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
class OperationQueryState {
|
|
6
|
+
import { CommandAgent } from "./CommandAgent";
|
|
7
|
+
class CommandQueryState {
|
|
8
8
|
static create() {
|
|
9
9
|
return {
|
|
10
10
|
arg: null,
|
|
@@ -18,7 +18,7 @@ class OperationQueryState {
|
|
|
18
18
|
isInitiated: false,
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
static load(state =
|
|
21
|
+
static load(state = CommandQueryState.create(), args) {
|
|
22
22
|
return {
|
|
23
23
|
...state,
|
|
24
24
|
arg: args,
|
|
@@ -51,7 +51,7 @@ class OperationQueryState {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
export class
|
|
54
|
+
export class Command {
|
|
55
55
|
_options;
|
|
56
56
|
_queriesCache;
|
|
57
57
|
_hooks;
|
|
@@ -69,7 +69,7 @@ export class Operation {
|
|
|
69
69
|
ResetAllQueriesSignal.clean$.subscribe(() => {
|
|
70
70
|
const caches = Array.from(this._queriesCache.values());
|
|
71
71
|
caches.forEach((cache) => {
|
|
72
|
-
cache.next(
|
|
72
|
+
cache.next(CommandQueryState.create());
|
|
73
73
|
});
|
|
74
74
|
});
|
|
75
75
|
}
|
|
@@ -79,12 +79,12 @@ export class Operation {
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
createAgent() {
|
|
82
|
-
return new
|
|
82
|
+
return new CommandAgent(this);
|
|
83
83
|
}
|
|
84
84
|
getQueryCache(args) {
|
|
85
85
|
return this._queriesCache.getQueryCache(args);
|
|
86
86
|
}
|
|
87
|
-
createQueryCache(args, state =
|
|
87
|
+
createQueryCache(args, state = CommandQueryState.create()) {
|
|
88
88
|
const cache = this._queriesCache.createQueryCache(args, state);
|
|
89
89
|
const hookResolvers = this._hooks.onCacheEntryAdded(args);
|
|
90
90
|
const spySub = cache.spy$.subscribe((state) => {
|
|
@@ -106,14 +106,14 @@ export class Operation {
|
|
|
106
106
|
}
|
|
107
107
|
_initiate(args, options) {
|
|
108
108
|
let cache = options?.cache ?? this.getQueryCache(args);
|
|
109
|
-
const state =
|
|
109
|
+
const state = CommandQueryState.load(cache?.value, args);
|
|
110
110
|
if (!cache) {
|
|
111
111
|
cache = this.createQueryCache(args, state);
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
114
114
|
cache.next(state);
|
|
115
115
|
}
|
|
116
|
-
const linksMeta = this._links.map(link => {
|
|
116
|
+
const linksMeta = this._links.map((link) => {
|
|
117
117
|
const forwardedArgs = link.forwardArgs(args);
|
|
118
118
|
const ref = link.resource.createRef(forwardedArgs);
|
|
119
119
|
return { link, ref, state: {} };
|
|
@@ -134,13 +134,12 @@ export class Operation {
|
|
|
134
134
|
.then((result) => {
|
|
135
135
|
Batcher.run(() => {
|
|
136
136
|
const data = this._options.select ? this._options.select(result) : result;
|
|
137
|
-
cache.next(
|
|
137
|
+
cache.next(CommandQueryState.success(state, data));
|
|
138
138
|
/**
|
|
139
139
|
* Обновляем связанные ресурсы
|
|
140
140
|
*/
|
|
141
141
|
linksMeta.forEach(({ link, ref, state }) => {
|
|
142
142
|
if (link.update && ref.has) {
|
|
143
|
-
// TODO подумать, нужно ли добавлять обработку, если patch() -> null (и в принце про работу patch)
|
|
144
143
|
ref.patch((draft) => {
|
|
145
144
|
return link.update({ draft, args, data });
|
|
146
145
|
})?.commit();
|
|
@@ -164,7 +163,7 @@ export class Operation {
|
|
|
164
163
|
})
|
|
165
164
|
.catch((error) => {
|
|
166
165
|
Batcher.run(() => {
|
|
167
|
-
cache.next(
|
|
166
|
+
cache.next(CommandQueryState.error(state, error));
|
|
168
167
|
/**
|
|
169
168
|
* Обновляем связанные ресурсы
|
|
170
169
|
*/
|
|
@@ -183,7 +182,7 @@ export class Operation {
|
|
|
183
182
|
return cache;
|
|
184
183
|
}
|
|
185
184
|
/**
|
|
186
|
-
*
|
|
185
|
+
* Используется для обратной совместимости
|
|
187
186
|
* @deprecated
|
|
188
187
|
*/
|
|
189
188
|
mutate(args) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CommandAgentInstance, CommandDefinition } from "../../../query/types";
|
|
2
|
+
import type { Command } from "./Command";
|
|
3
|
+
export declare class CommandAgent<D extends CommandDefinition> implements CommandAgentInstance<D> {
|
|
4
|
+
private _command;
|
|
5
|
+
private _commands$;
|
|
6
|
+
state$: import("../../../signals").ComputeFn<{
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
isDone: boolean;
|
|
9
|
+
isSuccess: boolean;
|
|
10
|
+
isError: boolean;
|
|
11
|
+
error: {} | undefined;
|
|
12
|
+
data: NonNullable<import("../../../query/types").FallbackOnNever<D["Selected"], D["Result"]>> | undefined;
|
|
13
|
+
args: D["Args"];
|
|
14
|
+
}>;
|
|
15
|
+
constructor(_command: Command<D>);
|
|
16
|
+
private _next;
|
|
17
|
+
initiate(args: D["Args"]): void;
|
|
18
|
+
createAgent(): CommandAgentInstance<D>;
|
|
19
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Computed, Signal } from "../../../signals";
|
|
2
|
-
export class
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export class CommandAgent {
|
|
3
|
+
_command;
|
|
4
|
+
_commands$ = Signal.state({
|
|
5
5
|
current$: null,
|
|
6
6
|
}, { isDisabled: true });
|
|
7
7
|
state$ = Computed.create(() => {
|
|
8
|
-
const
|
|
9
|
-
const currState =
|
|
8
|
+
const commands = this._commands$.get();
|
|
9
|
+
const currState = commands.current$?.value$.get();
|
|
10
10
|
// Нет текущего состояния — дефолт
|
|
11
11
|
if (!currState) {
|
|
12
12
|
return {
|
|
@@ -29,26 +29,26 @@ export class OperationAgent {
|
|
|
29
29
|
args: currState.arg,
|
|
30
30
|
};
|
|
31
31
|
}, { isDisabled: true });
|
|
32
|
-
constructor(
|
|
33
|
-
this.
|
|
32
|
+
constructor(_command) {
|
|
33
|
+
this._command = _command;
|
|
34
34
|
}
|
|
35
35
|
_next(newCache) {
|
|
36
|
-
this.
|
|
36
|
+
this._commands$.set({
|
|
37
37
|
current$: newCache,
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
initiate(args) {
|
|
41
|
-
const cache = this.
|
|
41
|
+
const cache = this._command.getQueryCache(args);
|
|
42
42
|
if (!cache) {
|
|
43
|
-
const newCache = this.
|
|
43
|
+
const newCache = this._command.initiate(args);
|
|
44
44
|
this._next(newCache);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
// Всегда запускаем
|
|
48
|
-
const newCache = this.
|
|
47
|
+
// Всегда запускаем команду заново, так как команды обычно не кэшируются как ресурсы
|
|
48
|
+
const newCache = this._command.initiate(args, { cache });
|
|
49
49
|
this._next(newCache);
|
|
50
50
|
}
|
|
51
51
|
createAgent() {
|
|
52
|
-
return new
|
|
52
|
+
return new CommandAgent(this._command);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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,8 +1,8 @@
|
|
|
1
|
-
import { ReactiveCache } from "
|
|
1
|
+
import { ReactiveCache } from "../../query/lib/ReactiveCache";
|
|
2
2
|
export declare class QueriesCache<KEY, VALUE> {
|
|
3
3
|
private _cacheLifeTime;
|
|
4
4
|
private readonly _cache;
|
|
5
|
-
constructor(_cacheLifeTime?: number | false, compareArgsFn?: (
|
|
5
|
+
constructor(_cacheLifeTime?: number | false, compareArgsFn?: (a: KEY, b: KEY) => boolean);
|
|
6
6
|
getQueryCache(args: KEY): ReactiveCache<VALUE> | undefined;
|
|
7
7
|
createQueryCache(args: KEY, initialState: VALUE): ReactiveCache<VALUE>;
|
|
8
8
|
values(): MapIterator<ReactiveCache<VALUE>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { shallowEqual } from "../../common/utils";
|
|
1
2
|
import { IndirectMap } from "../../query/lib/IndirectMap";
|
|
2
3
|
import { ReactiveCache } from "../../query/lib/ReactiveCache";
|
|
3
|
-
import { shallowEqual } from "../../common/utils";
|
|
4
4
|
export class QueriesCache {
|
|
5
5
|
_cacheLifeTime;
|
|
6
6
|
_cache;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Subject } from "rxjs";
|
|
2
|
-
import { OnCacheEntryAdded, OnQueryStarted } from "
|
|
2
|
+
import { OnCacheEntryAdded, OnQueryStarted } from "../../query/types";
|
|
3
3
|
type Options<ARGS, DATA> = {
|
|
4
4
|
onCacheEntryAdded?: OnCacheEntryAdded<ARGS, DATA>;
|
|
5
5
|
onQueryStarted?: OnQueryStarted<ARGS, DATA>;
|
|
@@ -19,15 +19,15 @@ export class QueriesLifetimeHooks {
|
|
|
19
19
|
dataChanged$.subscribe((state) => {
|
|
20
20
|
if (!stateDevtools) {
|
|
21
21
|
stateDevtools = Devtools.createState(state, {
|
|
22
|
-
base:
|
|
23
|
-
name: devtoolsName ||
|
|
22
|
+
base: "Queries",
|
|
23
|
+
name: devtoolsName || "",
|
|
24
24
|
});
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
stateDevtools(state);
|
|
28
28
|
});
|
|
29
29
|
$cacheEntryRemoved.then(() => {
|
|
30
|
-
stateDevtools(
|
|
30
|
+
stateDevtools("$CLEANED");
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
}
|
|
@@ -63,7 +63,7 @@ export class QueriesLifetimeHooks {
|
|
|
63
63
|
const queryFulfilledResolver = new PromiseResolver();
|
|
64
64
|
this.onQueryStartedListeners.forEach((listener) => {
|
|
65
65
|
listener(args, {
|
|
66
|
-
$queryFulfilled: queryFulfilledResolver.promise
|
|
66
|
+
$queryFulfilled: queryFulfilledResolver.promise,
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
69
|
return {
|
|
@@ -71,16 +71,16 @@ export class QueriesLifetimeHooks {
|
|
|
71
71
|
queryFulfilledResolver.resolve({
|
|
72
72
|
data,
|
|
73
73
|
error: undefined,
|
|
74
|
-
isError: false
|
|
74
|
+
isError: false,
|
|
75
75
|
});
|
|
76
76
|
},
|
|
77
77
|
fulfilledError: (error) => {
|
|
78
78
|
queryFulfilledResolver.resolve({
|
|
79
79
|
data: undefined,
|
|
80
80
|
error,
|
|
81
|
-
isError: true
|
|
81
|
+
isError: true,
|
|
82
82
|
});
|
|
83
|
-
}
|
|
83
|
+
},
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
86
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ReactiveCache } from "
|
|
2
|
-
import type { ResourceCreateOptions, ResourceDefinition, ResourceInstance,
|
|
1
|
+
import { ReactiveCache } from "../../../query/lib/ReactiveCache";
|
|
2
|
+
import type { ResourceCreateOptions, ResourceDefinition, ResourceInstance, ResourceRefInstance, ResourceTransaction } from "../../../query/types";
|
|
3
3
|
import { ResourceAgent } from "./ResourceAgent";
|
|
4
4
|
export type CoreResourceQueryState<D extends ResourceDefinition> = {
|
|
5
5
|
transactions: ResourceTransaction[] | null;
|
|
6
6
|
abortController: AbortController | null;
|
|
7
|
-
args: D[
|
|
8
|
-
savedData: D[
|
|
9
|
-
data: D[
|
|
7
|
+
args: D["Args"];
|
|
8
|
+
savedData: D["Data"] | null;
|
|
9
|
+
data: D["Data"] | null;
|
|
10
10
|
error: unknown | null;
|
|
11
11
|
isError: boolean;
|
|
12
12
|
isLoading: boolean;
|
|
@@ -25,27 +25,27 @@ export declare class Resource<D extends ResourceDefinition> implements ResourceI
|
|
|
25
25
|
private _DEFAULT_CACHE_LIFETIME;
|
|
26
26
|
constructor(_options: ResourceCreateOptions<D>);
|
|
27
27
|
createAgent: () => ResourceAgent<D>;
|
|
28
|
-
createRef: (args: D["Args"]) =>
|
|
29
|
-
getQueryCache(args: D[
|
|
30
|
-
createQueryCache(args: D[
|
|
31
|
-
incrementLock(args: 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
32
|
cache?: CoreResourceQueryCache<D>;
|
|
33
33
|
}): CoreResourceQueryCache<D>;
|
|
34
|
-
decrementLock(args: D[
|
|
34
|
+
decrementLock(args: D["Args"], options?: {
|
|
35
35
|
cache?: CoreResourceQueryCache<D>;
|
|
36
36
|
}): CoreResourceQueryCache<D> | null;
|
|
37
|
-
update(args: D[
|
|
38
|
-
data: D[
|
|
37
|
+
update(args: D["Args"], updateFn: (data: D["Data"], savedData: D["Data"] | null, transactions: ResourceTransaction[] | null) => {
|
|
38
|
+
data: D["Data"];
|
|
39
39
|
transactions: ResourceTransaction[] | null;
|
|
40
|
-
savedData: D[
|
|
40
|
+
savedData: D["Data"] | null;
|
|
41
41
|
}, options?: {
|
|
42
42
|
cache?: CoreResourceQueryCache<D>;
|
|
43
43
|
}): CoreResourceQueryCache<D> | null;
|
|
44
|
-
createWithData(args: D[
|
|
44
|
+
createWithData(args: D["Args"], data: D["Data"], options?: {
|
|
45
45
|
cache?: CoreResourceQueryCache<D>;
|
|
46
46
|
}): CoreResourceQueryCache<D>;
|
|
47
|
-
initiate(args: D[
|
|
47
|
+
initiate(args: D["Args"], options?: {
|
|
48
48
|
cache?: CoreResourceQueryCache<D>;
|
|
49
49
|
}): CoreResourceQueryCache<D>;
|
|
50
|
-
compareArgs(args1: D[
|
|
50
|
+
compareArgs(args1: D["Args"], args2: D["Args"]): boolean;
|
|
51
51
|
}
|
|
@@ -20,7 +20,7 @@ class ResourceQueryState {
|
|
|
20
20
|
isLocked: false,
|
|
21
21
|
isLoading: false,
|
|
22
22
|
isInitiated: false,
|
|
23
|
-
lockCount: 0
|
|
23
|
+
lockCount: 0,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
static load(state, args) {
|
|
@@ -66,7 +66,7 @@ class ResourceQueryState {
|
|
|
66
66
|
return {
|
|
67
67
|
...state,
|
|
68
68
|
isLocked: lockCount > 0,
|
|
69
|
-
lockCount
|
|
69
|
+
lockCount,
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
static decrementLock(state) {
|
|
@@ -74,7 +74,7 @@ class ResourceQueryState {
|
|
|
74
74
|
return {
|
|
75
75
|
...state,
|
|
76
76
|
isLocked: lockCount > 0,
|
|
77
|
-
lockCount
|
|
77
|
+
lockCount,
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
static update(state, data, savedData, transactions) {
|
|
@@ -82,7 +82,7 @@ class ResourceQueryState {
|
|
|
82
82
|
...state,
|
|
83
83
|
transactions,
|
|
84
84
|
savedData,
|
|
85
|
-
data
|
|
85
|
+
data,
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
static createWithData(data, args) {
|
|
@@ -100,7 +100,7 @@ class ResourceQueryState {
|
|
|
100
100
|
args,
|
|
101
101
|
isInitiated: false,
|
|
102
102
|
isLocked: false,
|
|
103
|
-
lockCount: 0
|
|
103
|
+
lockCount: 0,
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -160,7 +160,7 @@ export class Resource {
|
|
|
160
160
|
return cache;
|
|
161
161
|
}
|
|
162
162
|
decrementLock(args, options) {
|
|
163
|
-
|
|
163
|
+
const cache = options?.cache ?? this.getQueryCache(args);
|
|
164
164
|
if (!cache) {
|
|
165
165
|
return null;
|
|
166
166
|
}
|
|
@@ -168,7 +168,7 @@ export class Resource {
|
|
|
168
168
|
return cache;
|
|
169
169
|
}
|
|
170
170
|
update(args, updateFn, options) {
|
|
171
|
-
|
|
171
|
+
const cache = options?.cache ?? this.getQueryCache(args);
|
|
172
172
|
if (!cache) {
|
|
173
173
|
return null;
|
|
174
174
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ResourceAgentInstance, ResourceDefinition } from "
|
|
1
|
+
import { ResourceAgentInstance, ResourceDefinition } from "../../../query/types";
|
|
2
2
|
import type { Resource } from "./Resource";
|
|
3
3
|
export declare class ResourceAgent<D extends ResourceDefinition> implements ResourceAgentInstance<D> {
|
|
4
4
|
private _resource;
|
|
5
5
|
private _resources$;
|
|
6
|
-
state$: import("../../../signals
|
|
6
|
+
state$: import("../../../signals").ComputeFn<{
|
|
7
7
|
isInitiated: boolean;
|
|
8
8
|
isLoading: boolean;
|
|
9
9
|
isInitialLoading: boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Computed, Signal } from "../../../signals";
|
|
2
2
|
export class ResourceAgent {
|
|
3
3
|
_resource;
|
|
4
|
-
_resources$ = Signal.
|
|
4
|
+
_resources$ = Signal.state({
|
|
5
5
|
previous$: null,
|
|
6
6
|
current$: null,
|
|
7
7
|
}, { isDisabled: true });
|
|
@@ -60,8 +60,8 @@ export class ResourceAgent {
|
|
|
60
60
|
isError: currState.isError,
|
|
61
61
|
isLocked: currState.isLocked,
|
|
62
62
|
isReloading: currState.isReloading,
|
|
63
|
-
error: isShowPrev ? prevState.error ?? undefined : currState.error ?? undefined,
|
|
64
|
-
data: isShowPrev ? prevState.data ?? undefined : currState.data ?? undefined,
|
|
63
|
+
error: isShowPrev ? (prevState.error ?? undefined) : (currState.error ?? undefined),
|
|
64
|
+
data: isShowPrev ? (prevState.data ?? undefined) : (currState.data ?? undefined),
|
|
65
65
|
args: currState.args ?? undefined,
|
|
66
66
|
};
|
|
67
67
|
}, { isDisabled: true });
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { ResourceDefinition } from "@/query/types";
|
|
2
|
-
import { CoreResourceQueryState, Resource } from "./Resource";
|
|
3
|
-
import { ReadableSignalLike } from "@/signals/types";
|
|
4
1
|
import { Observable, Subject } from "rxjs";
|
|
2
|
+
import { ResourceDefinition } from "../../../query/types";
|
|
3
|
+
import { ReadableSignalLike } from "../../../signals/types";
|
|
4
|
+
import { CoreResourceQueryState, Resource } from "./Resource";
|
|
5
5
|
import { ResourceDuplicatorAgent } from "./ResourceDuplicatorAgent";
|
|
6
6
|
export type DuplicatorOptions<D extends DuplicatorDefinition> = {
|
|
7
|
-
resource: Resource<D[
|
|
8
|
-
getArgKey: (item: D[
|
|
9
|
-
getDataKey: (item: D[
|
|
7
|
+
resource: Resource<D["RESOURCE_DEFINITION"]>;
|
|
8
|
+
getArgKey: (item: D["ARGS_ITEM"]) => string | number;
|
|
9
|
+
getDataKey: (item: D["DATA_ITEM"]) => string | number;
|
|
10
10
|
cacheLifetime?: number | false;
|
|
11
11
|
};
|
|
12
12
|
export type DuplicatorDefinition<D extends ResourceDefinition = ResourceDefinition> = {
|
|
13
|
-
ARGS_ITEM: D[
|
|
14
|
-
DATA_ITEM: D[
|
|
13
|
+
ARGS_ITEM: D["Args"] extends Array<any> ? D["Args"][number] : never;
|
|
14
|
+
DATA_ITEM: D["Data"] extends Array<any> ? D["Data"][number] : never;
|
|
15
15
|
RESOURCE_DEFINITION: D;
|
|
16
16
|
};
|
|
17
|
-
type State<D extends DuplicatorDefinition> = CoreResourceQueryState<D[
|
|
18
|
-
unreleasedArgs?: D[
|
|
17
|
+
type State<D extends DuplicatorDefinition> = CoreResourceQueryState<D["RESOURCE_DEFINITION"]> & {
|
|
18
|
+
unreleasedArgs?: D["ARGS_ITEM"][];
|
|
19
19
|
};
|
|
20
20
|
type Cache<D extends DuplicatorDefinition> = ComputedReactiveCache<State<D>>;
|
|
21
21
|
export type CoreResourceDuplicatorCache<D extends DuplicatorDefinition> = Cache<D>;
|
|
@@ -25,15 +25,15 @@ export declare class ResourceDuplicator<D extends DuplicatorDefinition> {
|
|
|
25
25
|
private _caches;
|
|
26
26
|
private get _resource();
|
|
27
27
|
constructor(_options: DuplicatorOptions<D>);
|
|
28
|
-
getQueryCache(args: D[
|
|
29
|
-
createCache(args: D[
|
|
30
|
-
initiate(args: D[
|
|
31
|
-
serialize(args: D[
|
|
32
|
-
compareArgs(a: D[
|
|
28
|
+
getQueryCache(args: D["ARGS_ITEM"][]): Cache<D> | undefined;
|
|
29
|
+
createCache(args: D["ARGS_ITEM"][]): Cache<D>;
|
|
30
|
+
initiate(args: D["ARGS_ITEM"][], cache?: Cache<D>): Cache<D>;
|
|
31
|
+
serialize(args: D["ARGS_ITEM"][]): string;
|
|
32
|
+
compareArgs(a: D["ARGS_ITEM"][], b: D["ARGS_ITEM"][]): boolean;
|
|
33
33
|
createAgent: () => ResourceDuplicatorAgent<D>;
|
|
34
34
|
/** @deprecated */
|
|
35
|
-
d_init(args: D[
|
|
36
|
-
value$: import("
|
|
35
|
+
d_init(args: D["ARGS_ITEM"][]): {
|
|
36
|
+
value$: import("../../../signals").ComputeFn<State<D>>;
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
export declare class ComputedReactiveCache<T> {
|