@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.
Files changed (196) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +143 -137
  3. package/dist/common/devtools/combineDevtools.js +3 -3
  4. package/dist/common/devtools/index.d.ts +3 -3
  5. package/dist/common/devtools/index.js +3 -3
  6. package/dist/common/devtools/reduxDevtools.d.ts +1 -1
  7. package/dist/common/devtools/reduxDevtools.js +17 -17
  8. package/dist/common/devtools/types.d.ts +0 -6
  9. package/dist/common/options/SharedOptions.d.ts +1 -0
  10. package/dist/common/options/SharedOptions.js +6 -0
  11. package/dist/common/options/index.d.ts +1 -1
  12. package/dist/common/options/index.js +1 -1
  13. package/dist/common/react/index.d.ts +2 -2
  14. package/dist/common/react/index.js +2 -2
  15. package/dist/common/react/useConstant.js +1 -1
  16. package/dist/common/utils/deepEqual.js +1 -1
  17. package/dist/common/utils/index.d.ts +3 -3
  18. package/dist/common/utils/index.js +3 -3
  19. package/dist/common/utils/shallowEqual.js +1 -1
  20. package/dist/index.d.ts +8 -7
  21. package/dist/index.js +8 -7
  22. package/dist/query/SKIP_TOKEN.js +1 -1
  23. package/dist/query/api/createCommand.d.ts +1 -1
  24. package/dist/query/api/createOperation.d.ts +1 -1
  25. package/dist/query/api/createOperation.js +1 -1
  26. package/dist/query/api/createResource.d.ts +1 -1
  27. package/dist/query/api/createResourceDuplicator.d.ts +1 -1
  28. package/dist/query/core/Command/Command.d.ts +7 -7
  29. package/dist/query/core/Command/Command.js +2 -2
  30. package/dist/query/core/Command/CommandAgent.d.ts +1 -1
  31. package/dist/query/core/Command/index.d.ts +2 -2
  32. package/dist/query/core/Command/index.js +2 -2
  33. package/dist/query/core/{Opertation → Operation}/Operation.d.ts +2 -2
  34. package/dist/query/core/{Opertation → Operation}/Operation.js +1 -1
  35. package/dist/query/core/{Opertation → Operation}/OperationAgent.d.ts +1 -1
  36. package/dist/query/core/{Opertation → Operation}/OperationAgent.js +1 -1
  37. package/dist/query/core/QueriesCache.d.ts +1 -1
  38. package/dist/query/core/QueriesCache.js +1 -1
  39. package/dist/query/core/QueriesLifetimeHooks.js +7 -7
  40. package/dist/query/core/Resource/Resource.d.ts +15 -15
  41. package/dist/query/core/Resource/Resource.js +7 -7
  42. package/dist/query/core/Resource/ResourceAgent.d.ts +1 -1
  43. package/dist/query/core/Resource/ResourceAgent.js +2 -2
  44. package/dist/query/core/Resource/ResourceDuplicator.d.ts +16 -16
  45. package/dist/query/core/Resource/ResourceDuplicator.js +18 -20
  46. package/dist/query/core/Resource/ResourceDuplicatorAgent.d.ts +5 -5
  47. package/dist/query/core/Resource/ResourceDuplicatorAgent.js +2 -2
  48. package/dist/query/core/Resource/ResourceRef.d.ts +2 -2
  49. package/dist/query/core/Resource/ResourceRef.js +12 -12
  50. package/dist/query/index.d.ts +11 -10
  51. package/dist/query/index.js +11 -10
  52. package/dist/query/lib/IndirectMap.js +4 -4
  53. package/dist/query/react/useCommandAgent.d.ts +2 -2
  54. package/dist/query/react/useOperationAgent.d.ts +1 -1
  55. package/dist/query/react/useOperationAgent.js +1 -1
  56. package/dist/query/react/useResourceAgent.d.ts +3 -3
  57. package/dist/query/react/useResourceAgent.js +1 -1
  58. package/dist/query/react/useResourceRef.d.ts +3 -3
  59. package/dist/query/react/useResourceRef.js +7 -2
  60. package/dist/query/types/Command.types.d.ts +1 -1
  61. package/dist/query/types/Operation.types.d.ts +1 -1
  62. package/dist/query/types/Resource.types.d.ts +7 -5
  63. package/dist/query/types/index.d.ts +4 -4
  64. package/dist/query/types/index.js +4 -4
  65. package/dist/query-v2/api/createApi.d.ts +10 -0
  66. package/dist/query-v2/api/createApi.js +83 -0
  67. package/dist/query-v2/core/common/CacheEntry.d.ts +29 -0
  68. package/dist/query-v2/core/common/CacheEntry.js +71 -0
  69. package/dist/query-v2/core/common/CacheMap.d.ts +38 -0
  70. package/dist/query-v2/core/common/CacheMap.js +127 -0
  71. package/dist/query-v2/core/common/LifecycleHooks.d.ts +22 -0
  72. package/dist/query-v2/core/common/LifecycleHooks.js +104 -0
  73. package/dist/query-v2/core/common/index.d.ts +3 -0
  74. package/dist/query-v2/core/common/index.js +3 -0
  75. package/dist/query-v2/core/index.d.ts +3 -0
  76. package/dist/query-v2/core/index.js +3 -0
  77. package/dist/query-v2/core/machines/Machine.d.ts +14 -0
  78. package/dist/query-v2/core/machines/Machine.js +33 -0
  79. package/dist/query-v2/core/machines/MachineError.d.ts +11 -0
  80. package/dist/query-v2/core/machines/MachineError.js +26 -0
  81. package/dist/query-v2/core/machines/MachineIdle.d.ts +8 -0
  82. package/dist/query-v2/core/machines/MachineIdle.js +19 -0
  83. package/dist/query-v2/core/machines/MachinePending.d.ts +12 -0
  84. package/dist/query-v2/core/machines/MachinePending.js +29 -0
  85. package/dist/query-v2/core/machines/MachineRefreshing.d.ts +14 -0
  86. package/dist/query-v2/core/machines/MachineRefreshing.js +46 -0
  87. package/dist/query-v2/core/machines/MachineSuccess.d.ts +16 -0
  88. package/dist/query-v2/core/machines/MachineSuccess.js +42 -0
  89. package/dist/query-v2/core/machines/MachineWithData.d.ts +18 -0
  90. package/dist/query-v2/core/machines/MachineWithData.js +40 -0
  91. package/dist/query-v2/core/machines/Patcher.d.ts +20 -0
  92. package/dist/query-v2/core/machines/Patcher.js +104 -0
  93. package/dist/query-v2/core/machines/index.d.ts +8 -0
  94. package/dist/query-v2/core/machines/index.js +8 -0
  95. package/dist/query-v2/core/resource/ResourceV2.d.ts +120 -0
  96. package/dist/query-v2/core/resource/ResourceV2.js +464 -0
  97. package/dist/query-v2/core/resource/ResourceV2Agent.d.ts +26 -0
  98. package/dist/query-v2/core/resource/ResourceV2Agent.js +132 -0
  99. package/dist/query-v2/core/resource/index.d.ts +2 -0
  100. package/dist/query-v2/core/resource/index.js +2 -0
  101. package/dist/query-v2/index.d.ts +11 -0
  102. package/dist/query-v2/index.js +17 -0
  103. package/dist/query-v2/lib/NO_VALUE.d.ts +2 -0
  104. package/dist/query-v2/lib/NO_VALUE.js +1 -0
  105. package/dist/query-v2/lib/SKIP_TOKEN.d.ts +2 -0
  106. package/dist/query-v2/lib/SKIP_TOKEN.js +1 -0
  107. package/dist/query-v2/lib/index.d.ts +4 -0
  108. package/dist/query-v2/lib/index.js +3 -0
  109. package/dist/query-v2/lib/stableStringify.d.ts +8 -0
  110. package/dist/query-v2/lib/stableStringify.js +23 -0
  111. package/dist/query-v2/plugins/ReactHooksPlugin.d.ts +25 -0
  112. package/dist/query-v2/plugins/ReactHooksPlugin.js +19 -0
  113. package/dist/query-v2/plugins/types.d.ts +1 -0
  114. package/dist/query-v2/plugins/types.js +1 -0
  115. package/dist/query-v2/react/__tests__/helpers.d.ts +12 -0
  116. package/dist/query-v2/react/__tests__/helpers.js +33 -0
  117. package/dist/query-v2/react/index.d.ts +2 -0
  118. package/dist/query-v2/react/index.js +2 -0
  119. package/dist/query-v2/react/useResourceV2Agent.d.ts +12 -0
  120. package/dist/query-v2/react/useResourceV2Agent.js +36 -0
  121. package/dist/query-v2/react/useResourceV2Ref.d.ts +12 -0
  122. package/dist/query-v2/react/useResourceV2Ref.js +57 -0
  123. package/dist/query-v2/snapshot/Snapshot.d.ts +13 -0
  124. package/dist/query-v2/snapshot/Snapshot.js +76 -0
  125. package/dist/query-v2/types/agent.types.d.ts +54 -0
  126. package/dist/query-v2/types/agent.types.js +1 -0
  127. package/dist/query-v2/types/api.types.d.ts +22 -0
  128. package/dist/query-v2/types/api.types.js +1 -0
  129. package/dist/query-v2/types/cache.types.d.ts +37 -0
  130. package/dist/query-v2/types/cache.types.js +1 -0
  131. package/dist/query-v2/types/index.d.ts +9 -0
  132. package/dist/query-v2/types/index.js +9 -0
  133. package/dist/query-v2/types/lifecycle.types.d.ts +25 -0
  134. package/dist/query-v2/types/lifecycle.types.js +1 -0
  135. package/dist/query-v2/types/machine.types.d.ts +67 -0
  136. package/dist/query-v2/types/machine.types.js +1 -0
  137. package/dist/query-v2/types/plugin.types.d.ts +38 -0
  138. package/dist/query-v2/types/plugin.types.js +1 -0
  139. package/dist/query-v2/types/resource.types.d.ts +35 -0
  140. package/dist/query-v2/types/resource.types.js +1 -0
  141. package/dist/query-v2/types/shared.types.d.ts +20 -0
  142. package/dist/query-v2/types/shared.types.js +1 -0
  143. package/dist/query-v2/types/snapshot.types.d.ts +21 -0
  144. package/dist/query-v2/types/snapshot.types.js +1 -0
  145. package/dist/signals/base/Batcher.js +9 -5
  146. package/dist/signals/base/ComputeCache.js +3 -3
  147. package/dist/signals/base/DependencyTracker.js +1 -1
  148. package/dist/signals/base/Devtools.d.ts +3 -2
  149. package/dist/signals/base/Devtools.js +54 -27
  150. package/dist/signals/base/Indexer.js +1 -1
  151. package/dist/signals/base/ReadonlySignal.js +1 -1
  152. package/dist/signals/base/SyncObservable.d.ts +1 -2
  153. package/dist/signals/base/SyncObservable.js +2 -5
  154. package/dist/signals/base/index.d.ts +6 -6
  155. package/dist/signals/base/index.js +6 -6
  156. package/dist/signals/index.d.ts +5 -4
  157. package/dist/signals/index.js +5 -4
  158. package/dist/signals/operators/index.d.ts +1 -1
  159. package/dist/signals/operators/index.js +1 -1
  160. package/dist/signals/react/index.d.ts +1 -1
  161. package/dist/signals/react/index.js +1 -1
  162. package/dist/signals/signals/Computed.d.ts +3 -4
  163. package/dist/signals/signals/Computed.js +18 -10
  164. package/dist/signals/signals/Effect.js +2 -1
  165. package/dist/signals/signals/LocalState.d.ts +3 -4
  166. package/dist/signals/signals/LocalState.js +8 -8
  167. package/dist/signals/signals/Signal.d.ts +7 -6
  168. package/dist/signals/signals/Signal.js +4 -1
  169. package/dist/signals/signals/State.d.ts +4 -5
  170. package/dist/signals/signals/State.js +23 -9
  171. package/dist/signals/signals/index.d.ts +5 -5
  172. package/dist/signals/signals/index.js +5 -6
  173. package/dist/signals/types/SignalOptions.d.ts +16 -0
  174. package/dist/signals/types/SignalOptions.js +1 -0
  175. package/dist/signals/types/index.d.ts +3 -1
  176. package/dist/signals/types/index.js +3 -1
  177. package/dist/signals/types/normalizeSignalOptions.d.ts +2 -0
  178. package/dist/signals/types/normalizeSignalOptions.js +10 -0
  179. package/dist/signals/types/signals.types.d.ts +2 -3
  180. package/docs/CHANGELOG.md +95 -90
  181. package/docs/CONTRIBUTING.md +230 -0
  182. package/docs/contributing/ai-assisted-development.md +47 -0
  183. package/docs/contributing/query-v2/README.md +379 -0
  184. package/docs/{release → contributing/release}/README.md +59 -59
  185. package/docs/devtools/README.md +228 -228
  186. package/docs/migrations/0.5.0.md +58 -58
  187. package/docs/migrations/query-v2.md +171 -0
  188. package/docs/options/README.md +92 -92
  189. package/docs/query/README.md +575 -573
  190. package/docs/query-v2/README.md +280 -0
  191. package/docs/query-v2/api-reference.md +235 -0
  192. package/docs/query-v2/optimistic-updates.md +148 -0
  193. package/docs/query-v2/ssr.md +130 -0
  194. package/docs/signals/README.md +300 -300
  195. package/docs/usage/react/README.md +309 -309
  196. package/package.json +85 -63
@@ -1,9 +1,9 @@
1
1
  import type { ReactiveCache } from "../../../query/lib/ReactiveCache";
2
- import type { FallbackOnNever, CommandCreateOptions, CommandDefinition, CommandInstance } from "../../../query/types";
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['Args'] | null;
6
- data: FallbackOnNever<D['Selected'], D['Result']> | null;
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['Args']): ReactiveCache<CoreCommandQueryState<D>> | undefined;
25
- createQueryCache(args: D['Args'], state?: CoreCommandQueryState<D>): ReactiveCache<CoreCommandQueryState<D>>;
26
- initiate(args: D['Args'], options?: {
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['Args']): Promise<D['Data']>;
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/types").ComputeFn<{
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 './Command';
2
- export { CommandAgent } from './CommandAgent';
1
+ export { Command } from "./Command";
2
+ export { CommandAgent } from "./CommandAgent";
@@ -1,2 +1,2 @@
1
- export { Command } from './Command';
2
- export { CommandAgent } from './CommandAgent';
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 '../Command/Command';
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 '../Command/Command';
8
+ export type { CoreCommandQueryState as CoreOperationQueryState } from "../Command/Command";
@@ -1,4 +1,4 @@
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 '../Command/Command';
4
+ export { Command as Operation } from "../Command/Command";
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * @deprecated Use `CommandAgent` from '../Command/CommandAgent' instead. Will be removed in v0.6.0.
3
3
  */
4
- export { CommandAgent as OperationAgent } from '../Command/CommandAgent';
4
+ export { CommandAgent as OperationAgent } from "../Command/CommandAgent";
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * @deprecated Use `CommandAgent` from '../Command/CommandAgent' instead. Will be removed in v0.6.0.
3
3
  */
4
- export { CommandAgent as OperationAgent } from '../Command/CommandAgent';
4
+ export { CommandAgent as OperationAgent } from "../Command/CommandAgent";
@@ -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?: ((a: KEY, b: KEY) => boolean));
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: 'Queries',
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('$CLEANED');
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, ResourceRefInstanse, ResourceTransaction } from "../../../query/types";
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['Args'];
8
- savedData: D['Data'] | null;
9
- data: D['Data'] | null;
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"]) => ResourceRefInstanse<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?: {
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['Args'], options?: {
34
+ decrementLock(args: D["Args"], options?: {
35
35
  cache?: CoreResourceQueryCache<D>;
36
36
  }): CoreResourceQueryCache<D> | null;
37
- update(args: D['Args'], updateFn: (data: D['Data'], savedData: D['Data'] | null, transactions: ResourceTransaction[] | null) => {
38
- data: D['Data'];
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['Data'] | null;
40
+ savedData: D["Data"] | null;
41
41
  }, options?: {
42
42
  cache?: CoreResourceQueryCache<D>;
43
43
  }): CoreResourceQueryCache<D> | null;
44
- createWithData(args: D['Args'], data: D['Data'], options?: {
44
+ createWithData(args: D["Args"], data: D["Data"], options?: {
45
45
  cache?: CoreResourceQueryCache<D>;
46
46
  }): CoreResourceQueryCache<D>;
47
- initiate(args: D['Args'], options?: {
47
+ initiate(args: D["Args"], options?: {
48
48
  cache?: CoreResourceQueryCache<D>;
49
49
  }): CoreResourceQueryCache<D>;
50
- compareArgs(args1: D['Args'], args2: D['Args']): boolean;
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
- let cache = options?.cache ?? this.getQueryCache(args);
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
- let cache = options?.cache ?? this.getQueryCache(args);
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/types").ComputeFn<{
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 { Observable, Subject } from "rxjs";
4
+ import { CoreResourceQueryState, Resource } from "./Resource";
5
5
  import { ResourceDuplicatorAgent } from "./ResourceDuplicatorAgent";
6
6
  export type DuplicatorOptions<D extends DuplicatorDefinition> = {
7
- resource: Resource<D['RESOURCE_DEFINITION']>;
8
- getArgKey: (item: D['ARGS_ITEM']) => string | number;
9
- getDataKey: (item: D['DATA_ITEM']) => string | number;
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['Args'] extends Array<any> ? D['Args'][number] : never;
14
- DATA_ITEM: D['Data'] extends Array<any> ? D['Data'][number] : never;
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['RESOURCE_DEFINITION']> & {
18
- unreleasedArgs?: D['ARGS_ITEM'][];
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['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;
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['ARGS_ITEM'][]): {
36
- value$: import("../../../signals/types").ComputeFn<State<D>>;
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
- let fi = this._fis.get(argKey);
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
- let fi = this._fis.get(argKey);
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
- ? this._resource.createQueryCache(unreleasedArgs)
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
- import { ResourceDuplicator, DuplicatorDefinition } from "../../../query/core/Resource/ResourceDuplicator";
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/types").ComputeFn<{
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['ARGS_ITEM'][], force?: boolean): void;
33
- compareArgs(args: D['ARGS_ITEM'][], otherArgs: D['ARGS_ITEM'][]): boolean;
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, ResourceRefInstanse, ResourceTransaction } from "../../../query/types";
1
+ import { ResourceDefinition, ResourceRefInstance, ResourceTransaction } from "../../../query/types";
2
2
  import { Resource } from "./Resource";
3
- export declare class ResourceRef<D extends ResourceDefinition> implements ResourceRefInstanse<D> {
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 === 'pending');
49
+ const lastPendingIndex = transactions.findLastIndex((t) => t.status === "pending");
50
50
  transactions.forEach((transaction, index) => {
51
- if (transaction.status === 'pending') {
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 === 'committed') {
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 === 'aborted') {
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 === 'committed') {
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: 'pending',
97
+ status: "pending",
98
98
  abort() {
99
- if (this.status !== 'pending')
99
+ if (this.status !== "pending")
100
100
  return;
101
- this.status = 'aborted';
101
+ this.status = "aborted";
102
102
  reapplyTransactions();
103
103
  },
104
104
  commit() {
105
- if (this.status !== 'pending')
105
+ if (this.status !== "pending")
106
106
  return;
107
- this.status = 'committed';
107
+ this.status = "committed";
108
108
  reapplyTransactions();
109
- }
109
+ },
110
110
  };
111
111
  const updateFn = (data, savedData, transactions) => {
112
112
  isSkipped = false;
@@ -1,10 +1,11 @@
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 './react/useResourceAgent';
8
- export * from './react/useResourceRef';
9
- export * from './api/createOperation';
10
- export * from './react/useOperationAgent';
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";