@fozy-labs/rx-toolkit 0.5.3-rc.2 → 0.5.4
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/SharedOptions.d.ts +1 -0
- 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 +1 -1
- package/dist/query/api/createOperation.d.ts +1 -1
- package/dist/query/api/createOperation.js +1 -1
- package/dist/query/api/createResource.d.ts +1 -1
- package/dist/query/api/createResourceDuplicator.d.ts +1 -1
- package/dist/query/core/Command/Command.d.ts +7 -7
- package/dist/query/core/Command/Command.js +2 -2
- package/dist/query/core/Command/CommandAgent.d.ts +1 -1
- package/dist/query/core/Command/index.d.ts +2 -2
- package/dist/query/core/Command/index.js +2 -2
- package/dist/query/core/{Opertation → Operation}/Operation.d.ts +2 -2
- package/dist/query/core/{Opertation → Operation}/Operation.js +1 -1
- package/dist/query/core/{Opertation → Operation}/OperationAgent.d.ts +1 -1
- package/dist/query/core/{Opertation → Operation}/OperationAgent.js +1 -1
- package/dist/query/core/QueriesCache.d.ts +1 -1
- package/dist/query/core/QueriesCache.js +1 -1
- package/dist/query/core/QueriesLifetimeHooks.js +7 -7
- package/dist/query/core/Resource/Resource.d.ts +15 -15
- package/dist/query/core/Resource/Resource.js +7 -7
- package/dist/query/core/Resource/ResourceAgent.d.ts +1 -1
- package/dist/query/core/Resource/ResourceAgent.js +2 -2
- package/dist/query/core/Resource/ResourceDuplicator.d.ts +16 -16
- package/dist/query/core/Resource/ResourceDuplicator.js +18 -20
- package/dist/query/core/Resource/ResourceDuplicatorAgent.d.ts +5 -5
- package/dist/query/core/Resource/ResourceDuplicatorAgent.js +2 -2
- 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 -10
- package/dist/query/index.js +11 -10
- package/dist/query/lib/IndirectMap.js +4 -4
- package/dist/query/react/useCommandAgent.d.ts +2 -2
- package/dist/query/react/useOperationAgent.d.ts +1 -1
- package/dist/query/react/useOperationAgent.js +1 -1
- package/dist/query/react/useResourceAgent.d.ts +3 -3
- 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 +1 -1
- package/dist/query/types/Operation.types.d.ts +1 -1
- package/dist/query/types/Resource.types.d.ts +7 -5
- package/dist/query/types/index.d.ts +4 -4
- package/dist/query/types/index.js +4 -4
- 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/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 +3 -4
- package/dist/signals/signals/LocalState.js +8 -8
- package/dist/signals/signals/Signal.d.ts +7 -6
- 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 +2 -3
- package/docs/CHANGELOG.md +95 -90
- 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 -92
- package/docs/query/README.md +575 -573
- 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 -300
- package/docs/usage/react/README.md +309 -309
- package/package.json +85 -63
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ReactiveCache } from "../../../query/lib/ReactiveCache";
|
|
2
|
-
import type {
|
|
2
|
+
import type { CommandCreateOptions, CommandDefinition, CommandInstance, FallbackOnNever } from "../../../query/types";
|
|
3
3
|
import { CommandAgent } from "./CommandAgent";
|
|
4
4
|
export type CoreCommandQueryState<D extends CommandDefinition> = {
|
|
5
|
-
arg: D[
|
|
6
|
-
data: FallbackOnNever<D[
|
|
5
|
+
arg: D["Args"] | null;
|
|
6
|
+
data: FallbackOnNever<D["Selected"], D["Result"]> | null;
|
|
7
7
|
error: unknown | null;
|
|
8
8
|
isError: boolean;
|
|
9
9
|
isLoading: boolean;
|
|
@@ -21,9 +21,9 @@ export declare class Command<D extends CommandDefinition> implements CommandInst
|
|
|
21
21
|
constructor(_options: CommandCreateOptions<D>);
|
|
22
22
|
private _createLinks;
|
|
23
23
|
createAgent(): CommandAgent<D>;
|
|
24
|
-
getQueryCache(args: D[
|
|
25
|
-
createQueryCache(args: D[
|
|
26
|
-
initiate(args: 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
27
|
cache?: ReactiveCache<CoreCommandQueryState<D>>;
|
|
28
28
|
}): ReactiveCache<CoreCommandQueryState<D>>;
|
|
29
29
|
private _initiate;
|
|
@@ -31,5 +31,5 @@ export declare class Command<D extends CommandDefinition> implements CommandInst
|
|
|
31
31
|
* Используется для обратной совместимости
|
|
32
32
|
* @deprecated
|
|
33
33
|
*/
|
|
34
|
-
mutate(args: D[
|
|
34
|
+
mutate(args: D["Args"]): Promise<D["Data"]>;
|
|
35
35
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
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
6
|
import { CommandAgent } from "./CommandAgent";
|
|
6
|
-
import { ResetAllQueriesSignal } from "../../../query/core/ResetAllQueriesSignal";
|
|
7
7
|
class CommandQueryState {
|
|
8
8
|
static create() {
|
|
9
9
|
return {
|
|
@@ -113,7 +113,7 @@ export class Command {
|
|
|
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: {} };
|
|
@@ -3,7 +3,7 @@ import type { Command } from "./Command";
|
|
|
3
3
|
export declare class CommandAgent<D extends CommandDefinition> implements CommandAgentInstance<D> {
|
|
4
4
|
private _command;
|
|
5
5
|
private _commands$;
|
|
6
|
-
state$: import("../../../signals
|
|
6
|
+
state$: import("../../../signals").ComputeFn<{
|
|
7
7
|
isLoading: boolean;
|
|
8
8
|
isDone: boolean;
|
|
9
9
|
isSuccess: boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Command } from
|
|
2
|
-
export { CommandAgent } from
|
|
1
|
+
export { Command } from "./Command";
|
|
2
|
+
export { CommandAgent } from "./CommandAgent";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Command } from
|
|
2
|
-
export { CommandAgent } from
|
|
1
|
+
export { Command } from "./Command";
|
|
2
|
+
export { CommandAgent } from "./CommandAgent";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @deprecated Use `Command` from '../Command/Command' instead. Will be removed in v0.6.0.
|
|
3
3
|
*/
|
|
4
|
-
export { Command as Operation } from
|
|
4
|
+
export { Command as Operation } from "../Command/Command";
|
|
5
5
|
/**
|
|
6
6
|
* @deprecated Use `CoreCommandQueryState` from '../Command/Command' instead. Will be removed in v0.6.0.
|
|
7
7
|
*/
|
|
8
|
-
export type { CoreCommandQueryState as CoreOperationQueryState } from
|
|
8
|
+
export type { CoreCommandQueryState as CoreOperationQueryState } from "../Command/Command";
|
|
@@ -2,7 +2,7 @@ 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;
|
|
@@ -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
1
|
import { ReactiveCache } from "../../../query/lib/ReactiveCache";
|
|
2
|
-
import type { ResourceCreateOptions, ResourceDefinition, ResourceInstance,
|
|
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
|
}
|
|
@@ -3,7 +3,7 @@ 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;
|
|
@@ -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 { Observable, Subject } from "rxjs";
|
|
1
2
|
import { ResourceDefinition } from "../../../query/types";
|
|
2
|
-
import { CoreResourceQueryState, Resource } from "./Resource";
|
|
3
3
|
import { ReadableSignalLike } from "../../../signals/types";
|
|
4
|
-
import {
|
|
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("../../../signals
|
|
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> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Signal, signalize } from "../../../signals";
|
|
2
1
|
import { finalize, ReplaySubject, share, Subject, takeUntil, timer } from "rxjs";
|
|
2
|
+
import { Signal, signalize } from "../../../signals";
|
|
3
3
|
import { ResourceDuplicatorAgent } from "./ResourceDuplicatorAgent";
|
|
4
4
|
export class ResourceDuplicator {
|
|
5
5
|
_options;
|
|
@@ -25,7 +25,7 @@ export class ResourceDuplicator {
|
|
|
25
25
|
obs: value$.obs,
|
|
26
26
|
});
|
|
27
27
|
cache.onClean$.subscribe(() => {
|
|
28
|
-
args.forEach(arg => {
|
|
28
|
+
args.forEach((arg) => {
|
|
29
29
|
const argKey = this._options.getArgKey(arg);
|
|
30
30
|
const fi = this._fis.get(argKey);
|
|
31
31
|
if (!fi)
|
|
@@ -47,9 +47,9 @@ export class ResourceDuplicator {
|
|
|
47
47
|
this._resource.initiate(unreleasedArgs);
|
|
48
48
|
}
|
|
49
49
|
const uninitiatedCaches = new Set();
|
|
50
|
-
args.forEach(arg => {
|
|
50
|
+
args.forEach((arg) => {
|
|
51
51
|
const argKey = this._options.getArgKey(arg);
|
|
52
|
-
|
|
52
|
+
const fi = this._fis.get(argKey);
|
|
53
53
|
if (fi && !fi.cache.value.isInitiated) {
|
|
54
54
|
uninitiatedCaches.add(fi.cache);
|
|
55
55
|
}
|
|
@@ -61,9 +61,9 @@ export class ResourceDuplicator {
|
|
|
61
61
|
}
|
|
62
62
|
serialize(args) {
|
|
63
63
|
if (!args)
|
|
64
|
-
return
|
|
65
|
-
const argsKeys = args.map(a => this._options.getArgKey(a));
|
|
66
|
-
return argsKeys.join(
|
|
64
|
+
return "";
|
|
65
|
+
const argsKeys = args.map((a) => this._options.getArgKey(a));
|
|
66
|
+
return argsKeys.join("|");
|
|
67
67
|
}
|
|
68
68
|
compareArgs(a, b) {
|
|
69
69
|
return this.serialize(a) === this.serialize(b);
|
|
@@ -73,12 +73,12 @@ export class ResourceDuplicator {
|
|
|
73
73
|
};
|
|
74
74
|
/** @deprecated */
|
|
75
75
|
d_init(args) {
|
|
76
|
-
const argsKeys = args.map(a => this._options.getArgKey(a));
|
|
76
|
+
const argsKeys = args.map((a) => this._options.getArgKey(a));
|
|
77
77
|
const releasedCaches = new Set();
|
|
78
78
|
const unreleasedArgs = [];
|
|
79
|
-
args.forEach(arg => {
|
|
79
|
+
args.forEach((arg) => {
|
|
80
80
|
const argKey = this._options.getArgKey(arg);
|
|
81
|
-
|
|
81
|
+
const fi = this._fis.get(argKey);
|
|
82
82
|
if (!fi || !fi.cache.value.isInitiated) {
|
|
83
83
|
unreleasedArgs.push(arg);
|
|
84
84
|
return;
|
|
@@ -86,10 +86,8 @@ export class ResourceDuplicator {
|
|
|
86
86
|
fi.k++;
|
|
87
87
|
releasedCaches.add(fi.cache);
|
|
88
88
|
});
|
|
89
|
-
const queryCache = unreleasedArgs?.length > 0
|
|
90
|
-
|
|
91
|
-
: null;
|
|
92
|
-
unreleasedArgs.forEach(arg => {
|
|
89
|
+
const queryCache = unreleasedArgs?.length > 0 ? this._resource.createQueryCache(unreleasedArgs) : null;
|
|
90
|
+
unreleasedArgs.forEach((arg) => {
|
|
93
91
|
const argKey = this._options.getArgKey(arg);
|
|
94
92
|
let fi = this._fis.get(argKey);
|
|
95
93
|
if (!fi) {
|
|
@@ -109,7 +107,7 @@ export class ResourceDuplicator {
|
|
|
109
107
|
for (const rc of releasedCaches) {
|
|
110
108
|
itemsAcc.push(rc.value$.get());
|
|
111
109
|
}
|
|
112
|
-
const isNotInitiated = itemsAcc.some(i => !i.isInitiated);
|
|
110
|
+
const isNotInitiated = itemsAcc.some((i) => !i.isInitiated);
|
|
113
111
|
const baseReturn = {
|
|
114
112
|
transactions: null,
|
|
115
113
|
abortController: null,
|
|
@@ -132,9 +130,9 @@ export class ResourceDuplicator {
|
|
|
132
130
|
...baseReturn,
|
|
133
131
|
isInitiated: false,
|
|
134
132
|
};
|
|
135
|
-
const isError = itemsAcc.some(i => i.isError);
|
|
133
|
+
const isError = itemsAcc.some((i) => i.isError);
|
|
136
134
|
if (isError) {
|
|
137
|
-
const firstError = itemsAcc.find(i => i.isError);
|
|
135
|
+
const firstError = itemsAcc.find((i) => i.isError);
|
|
138
136
|
return {
|
|
139
137
|
...baseReturn,
|
|
140
138
|
isError: true,
|
|
@@ -142,17 +140,17 @@ export class ResourceDuplicator {
|
|
|
142
140
|
error: firstError.error,
|
|
143
141
|
};
|
|
144
142
|
}
|
|
145
|
-
const isLoading = itemsAcc.some(i => i.isLoading);
|
|
143
|
+
const isLoading = itemsAcc.some((i) => i.isLoading);
|
|
146
144
|
if (isLoading)
|
|
147
145
|
return {
|
|
148
146
|
...baseReturn,
|
|
149
147
|
isLoading: true,
|
|
150
148
|
};
|
|
151
149
|
const dataAcc = [];
|
|
152
|
-
itemsAcc.forEach(item => {
|
|
150
|
+
itemsAcc.forEach((item) => {
|
|
153
151
|
item.data?.forEach((d) => {
|
|
154
152
|
const dataKey = this._options.getDataKey(d);
|
|
155
|
-
const index = argsKeys.findIndex(ak => ak === dataKey);
|
|
153
|
+
const index = argsKeys.findIndex((ak) => ak === dataKey);
|
|
156
154
|
if (index === -1)
|
|
157
155
|
return;
|
|
158
156
|
dataAcc[index] = d;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { DuplicatorDefinition, ResourceDuplicator } from "../../../query/core/Resource/ResourceDuplicator";
|
|
1
2
|
import { ResourceAgentInstance } from "../../../query/types";
|
|
2
|
-
|
|
3
|
-
export declare class ResourceDuplicatorAgent<D extends DuplicatorDefinition> implements ResourceAgentInstance<D['RESOURCE_DEFINITION']> {
|
|
3
|
+
export declare class ResourceDuplicatorAgent<D extends DuplicatorDefinition> implements ResourceAgentInstance<D["RESOURCE_DEFINITION"]> {
|
|
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;
|
|
@@ -29,7 +29,7 @@ export declare class ResourceDuplicatorAgent<D extends DuplicatorDefinition> imp
|
|
|
29
29
|
args: NonNullable<D["RESOURCE_DEFINITION"]["Args"]> | undefined;
|
|
30
30
|
}>;
|
|
31
31
|
constructor(_resource: ResourceDuplicator<D>);
|
|
32
|
-
initiate(args: D[
|
|
33
|
-
compareArgs(args: D[
|
|
32
|
+
initiate(args: D["ARGS_ITEM"][], force?: boolean): void;
|
|
33
|
+
compareArgs(args: D["ARGS_ITEM"][], otherArgs: D["ARGS_ITEM"][]): boolean;
|
|
34
34
|
private _next;
|
|
35
35
|
}
|
|
@@ -60,8 +60,8 @@ export class ResourceDuplicatorAgent {
|
|
|
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,6 +1,6 @@
|
|
|
1
|
-
import { ResourceDefinition,
|
|
1
|
+
import { ResourceDefinition, ResourceRefInstance, ResourceTransaction } from "../../../query/types";
|
|
2
2
|
import { Resource } from "./Resource";
|
|
3
|
-
export declare class ResourceRef<D extends ResourceDefinition> implements
|
|
3
|
+
export declare class ResourceRef<D extends ResourceDefinition> implements ResourceRefInstance<D> {
|
|
4
4
|
private readonly _resource;
|
|
5
5
|
private readonly _args;
|
|
6
6
|
private _cacheItem;
|
|
@@ -23,7 +23,7 @@ export class ResourceRef {
|
|
|
23
23
|
return;
|
|
24
24
|
isLocked = false;
|
|
25
25
|
this._resource.decrementLock(this._args, { cache: this._cacheItem });
|
|
26
|
-
}
|
|
26
|
+
},
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
unlockOne() {
|
|
@@ -46,9 +46,9 @@ export class ResourceRef {
|
|
|
46
46
|
let currentData = savedData ?? data;
|
|
47
47
|
const remainingTransactions = [];
|
|
48
48
|
let foundPending = false;
|
|
49
|
-
const lastPendingIndex = transactions.findLastIndex(t => t.status ===
|
|
49
|
+
const lastPendingIndex = transactions.findLastIndex((t) => t.status === "pending");
|
|
50
50
|
transactions.forEach((transaction, index) => {
|
|
51
|
-
if (transaction.status ===
|
|
51
|
+
if (transaction.status === "pending") {
|
|
52
52
|
foundPending = true;
|
|
53
53
|
// Применяем pending транзакцию и оставляем в очереди
|
|
54
54
|
currentData = applyPatches(currentData, transaction.patches);
|
|
@@ -56,12 +56,12 @@ export class ResourceRef {
|
|
|
56
56
|
}
|
|
57
57
|
else if (foundPending) {
|
|
58
58
|
// После pending транзакции
|
|
59
|
-
if (transaction.status ===
|
|
59
|
+
if (transaction.status === "committed") {
|
|
60
60
|
// Применяем и оставляем в очереди
|
|
61
61
|
currentData = applyPatches(currentData, transaction.patches);
|
|
62
62
|
remainingTransactions.push(transaction);
|
|
63
63
|
}
|
|
64
|
-
else if (transaction.status ===
|
|
64
|
+
else if (transaction.status === "aborted") {
|
|
65
65
|
// Проверяем, есть ли pending после текущей aborted
|
|
66
66
|
const hasPendingAfter = index < lastPendingIndex;
|
|
67
67
|
if (hasPendingAfter) {
|
|
@@ -73,7 +73,7 @@ export class ResourceRef {
|
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
75
75
|
// До первой pending транзакции
|
|
76
|
-
if (transaction.status ===
|
|
76
|
+
if (transaction.status === "committed") {
|
|
77
77
|
// Применяем и убираем из очереди
|
|
78
78
|
const patches = transaction.patches;
|
|
79
79
|
currentData = applyPatches(currentData, patches);
|
|
@@ -94,19 +94,19 @@ export class ResourceRef {
|
|
|
94
94
|
const transaction = {
|
|
95
95
|
patches: [],
|
|
96
96
|
inversePatches: [],
|
|
97
|
-
status:
|
|
97
|
+
status: "pending",
|
|
98
98
|
abort() {
|
|
99
|
-
if (this.status !==
|
|
99
|
+
if (this.status !== "pending")
|
|
100
100
|
return;
|
|
101
|
-
this.status =
|
|
101
|
+
this.status = "aborted";
|
|
102
102
|
reapplyTransactions();
|
|
103
103
|
},
|
|
104
104
|
commit() {
|
|
105
|
-
if (this.status !==
|
|
105
|
+
if (this.status !== "pending")
|
|
106
106
|
return;
|
|
107
|
-
this.status =
|
|
107
|
+
this.status = "committed";
|
|
108
108
|
reapplyTransactions();
|
|
109
|
-
}
|
|
109
|
+
},
|
|
110
110
|
};
|
|
111
111
|
const updateFn = (data, savedData, transactions) => {
|
|
112
112
|
isSkipped = false;
|
package/dist/query/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
1
|
+
export * from "./api/createCommand";
|
|
2
|
+
export * from "./react/useCommandAgent";
|
|
3
|
+
export * from "./api/createResource";
|
|
4
|
+
export * from "./api/createResourceDuplicator";
|
|
5
|
+
export * from "./api/resetAllQueriesCache";
|
|
6
|
+
export * from "./SKIP_TOKEN";
|
|
7
|
+
export * from "./types";
|
|
8
|
+
export * from "./react/useResourceAgent";
|
|
9
|
+
export * from "./react/useResourceRef";
|
|
10
|
+
export * from "./api/createOperation";
|
|
11
|
+
export * from "./react/useOperationAgent";
|