@fozy-labs/rx-toolkit 0.5.3-rc.1 → 0.5.3-rc.2

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 (61) hide show
  1. package/README.md +3 -3
  2. package/dist/common/options/DefaultOptions.d.ts +1 -1
  3. package/dist/common/options/SharedOptions.d.ts +2 -2
  4. package/dist/query/api/createCommand.d.ts +21 -0
  5. package/dist/query/api/createCommand.js +20 -0
  6. package/dist/query/api/createOperation.d.ts +5 -3
  7. package/dist/query/api/createOperation.js +6 -2
  8. package/dist/query/api/createResource.d.ts +2 -2
  9. package/dist/query/api/createResourceDuplicator.d.ts +2 -2
  10. package/dist/query/core/Command/Command.d.ts +35 -0
  11. package/dist/query/core/Command/Command.js +210 -0
  12. package/dist/query/core/Command/CommandAgent.d.ts +19 -0
  13. package/dist/query/core/Command/CommandAgent.js +54 -0
  14. package/dist/query/core/Command/index.d.ts +2 -0
  15. package/dist/query/core/Command/index.js +2 -0
  16. package/dist/query/core/Opertation/Operation.d.ts +8 -35
  17. package/dist/query/core/Opertation/Operation.js +4 -211
  18. package/dist/query/core/Opertation/OperationAgent.d.ts +4 -19
  19. package/dist/query/core/Opertation/OperationAgent.js +4 -54
  20. package/dist/query/core/QueriesCache.d.ts +1 -1
  21. package/dist/query/core/QueriesLifetimeHooks.d.ts +1 -1
  22. package/dist/query/core/Resource/Resource.d.ts +2 -2
  23. package/dist/query/core/Resource/ResourceAgent.d.ts +1 -1
  24. package/dist/query/core/Resource/ResourceAgent.js +1 -1
  25. package/dist/query/core/Resource/ResourceDuplicator.d.ts +3 -3
  26. package/dist/query/core/Resource/ResourceDuplicator.js +1 -1
  27. package/dist/query/core/Resource/ResourceDuplicatorAgent.d.ts +2 -2
  28. package/dist/query/core/Resource/ResourceDuplicatorAgent.js +1 -1
  29. package/dist/query/core/Resource/ResourceRef.d.ts +1 -1
  30. package/dist/query/index.d.ts +4 -2
  31. package/dist/query/index.js +7 -2
  32. package/dist/query/lib/ReactiveCache.d.ts +1 -1
  33. package/dist/query/react/useCommandAgent.d.ts +24 -0
  34. package/dist/query/react/useCommandAgent.js +39 -0
  35. package/dist/query/react/useOperationAgent.d.ts +6 -8
  36. package/dist/query/react/useOperationAgent.js +6 -23
  37. package/dist/query/react/useResourceAgent.d.ts +3 -3
  38. package/dist/query/types/Command.types.d.ts +154 -0
  39. package/dist/query/types/Command.types.js +1 -0
  40. package/dist/query/types/Operation.types.d.ts +13 -154
  41. package/dist/query/types/index.d.ts +2 -1
  42. package/dist/query/types/index.js +3 -1
  43. package/dist/signals/base/Devtools.d.ts +1 -1
  44. package/dist/signals/operators/signalize.d.ts +1 -1
  45. package/dist/signals/signals/Computed.d.ts +2 -2
  46. package/dist/signals/signals/LocalState.d.ts +45 -0
  47. package/dist/signals/signals/{LocalSignal.js → LocalState.js} +59 -25
  48. package/dist/signals/signals/Signal.d.ts +4 -4
  49. package/dist/signals/signals/Signal.js +1 -1
  50. package/dist/signals/signals/State.d.ts +2 -2
  51. package/dist/signals/signals/index.d.ts +1 -1
  52. package/dist/signals/signals/index.js +1 -1
  53. package/dist/signals/types/signals.types.d.ts +5 -0
  54. package/docs/CHANGELOG.md +76 -18
  55. package/docs/devtools/README.md +4 -4
  56. package/docs/options/README.md +4 -2
  57. package/docs/query/README.md +34 -32
  58. package/docs/signals/README.md +10 -5
  59. package/docs/usage/react/README.md +17 -15
  60. package/package.json +1 -1
  61. package/dist/signals/signals/LocalSignal.d.ts +0 -32
@@ -1,211 +1,4 @@
1
- import { PromiseResolver } from "../../../common/utils";
2
- import { Batcher } from "../../../signals";
3
- import { QueriesCache } from "../QueriesCache";
4
- import { QueriesLifetimeHooks } from "../QueriesLifetimeHooks";
5
- import { OperationAgent } from "./OperationAgent";
6
- import { ResetAllQueriesSignal } from "../../../query/core/ResetAllQueriesSignal";
7
- class OperationQueryState {
8
- static create() {
9
- return {
10
- arg: null,
11
- data: null,
12
- error: null,
13
- isError: false,
14
- isRepeating: false,
15
- isDone: false,
16
- isSuccess: false,
17
- isLoading: false,
18
- isInitiated: false,
19
- };
20
- }
21
- static load(state = OperationQueryState.create(), args) {
22
- return {
23
- ...state,
24
- arg: args,
25
- isLoading: true,
26
- isRepeating: state.isDone,
27
- isInitiated: true,
28
- };
29
- }
30
- static success(state, data) {
31
- return {
32
- ...state,
33
- data,
34
- isLoading: false,
35
- isRepeating: false,
36
- isDone: true,
37
- isSuccess: true,
38
- isError: false,
39
- error: null,
40
- };
41
- }
42
- static error(state, error) {
43
- return {
44
- ...state,
45
- isLoading: false,
46
- isRepeating: false,
47
- isDone: true,
48
- isSuccess: false,
49
- isError: true,
50
- error,
51
- };
52
- }
53
- }
54
- export class Operation {
55
- _options;
56
- _queriesCache;
57
- _hooks;
58
- _links = [];
59
- _DEFAULT_CACHE_LIFETIME = 1_000;
60
- constructor(_options) {
61
- this._options = _options;
62
- this._queriesCache = new QueriesCache(this._options.cacheLifetime ?? this._DEFAULT_CACHE_LIFETIME);
63
- this._hooks = new QueriesLifetimeHooks({
64
- onCacheEntryAdded: _options.onCacheEntryAdded,
65
- onQueryStarted: _options.onQueryStarted,
66
- devtoolsName: _options.devtoolsName,
67
- });
68
- this._createLinks();
69
- ResetAllQueriesSignal.clean$.subscribe(() => {
70
- const caches = Array.from(this._queriesCache.values());
71
- caches.forEach((cache) => {
72
- cache.next(OperationQueryState.create());
73
- });
74
- });
75
- }
76
- _createLinks() {
77
- this._options.link?.((linkOptions) => {
78
- this._links.push(linkOptions);
79
- });
80
- }
81
- createAgent() {
82
- return new OperationAgent(this);
83
- }
84
- getQueryCache(args) {
85
- return this._queriesCache.getQueryCache(args);
86
- }
87
- createQueryCache(args, state = OperationQueryState.create()) {
88
- const cache = this._queriesCache.createQueryCache(args, state);
89
- const hookResolvers = this._hooks.onCacheEntryAdded(args);
90
- const spySub = cache.spy$.subscribe((state) => {
91
- if (!state.isDone)
92
- return;
93
- hookResolvers.cacheDataLoaded();
94
- spySub.unsubscribe();
95
- });
96
- cache.spy$.subscribe((state) => {
97
- hookResolvers.dataChanged$.next(state);
98
- });
99
- cache.onClean$.subscribe(() => {
100
- hookResolvers.cacheEntryRemoved();
101
- });
102
- return cache;
103
- }
104
- initiate(args, options) {
105
- return Batcher.run(() => this._initiate(args, options));
106
- }
107
- _initiate(args, options) {
108
- let cache = options?.cache ?? this.getQueryCache(args);
109
- const state = OperationQueryState.load(cache?.value, args);
110
- if (!cache) {
111
- cache = this.createQueryCache(args, state);
112
- }
113
- else {
114
- cache.next(state);
115
- }
116
- const linksMeta = this._links.map(link => {
117
- const forwardedArgs = link.forwardArgs(args);
118
- const ref = link.resource.createRef(forwardedArgs);
119
- return { link, ref, state: {} };
120
- });
121
- const query = this._options.queryFn(args);
122
- const hookResolvers = this._hooks.onQueryStarted(args);
123
- linksMeta.forEach(({ link, ref, state }) => {
124
- if (link.lock) {
125
- state.unlocker = ref.lock();
126
- }
127
- if (link.optimisticUpdate && ref.has) {
128
- state.patch = ref.patch((draft) => {
129
- return link.optimisticUpdate({ draft, args });
130
- });
131
- }
132
- });
133
- query
134
- .then((result) => {
135
- Batcher.run(() => {
136
- const data = this._options.select ? this._options.select(result) : result;
137
- cache.next(OperationQueryState.success(state, data));
138
- /**
139
- * Обновляем связанные ресурсы
140
- */
141
- linksMeta.forEach(({ link, ref, state }) => {
142
- if (link.update && ref.has) {
143
- // TODO подумать, нужно ли добавлять обработку, если patch() -> null (и в принце про работу patch)
144
- ref.patch((draft) => {
145
- return link.update({ draft, args, data });
146
- })?.commit();
147
- }
148
- if (link.create && !ref.has) {
149
- ref.create(link.create({ args, data }));
150
- }
151
- if (link.invalidate) {
152
- ref.invalidate();
153
- }
154
- state.patch?.commit();
155
- });
156
- hookResolvers.fulfilledSuccess(data);
157
- /**
158
- * Обновляем связанные ресурсы
159
- */
160
- linksMeta.forEach(({ state }) => {
161
- state.unlocker?.unlock();
162
- });
163
- });
164
- })
165
- .catch((error) => {
166
- Batcher.run(() => {
167
- cache.next(OperationQueryState.error(state, error));
168
- /**
169
- * Обновляем связанные ресурсы
170
- */
171
- linksMeta.forEach(({ state }) => {
172
- state.patch?.abort();
173
- });
174
- hookResolvers.fulfilledError(error);
175
- /**
176
- * Обновляем связанные ресурсы
177
- */
178
- linksMeta.forEach(({ state }) => {
179
- state.unlocker?.unlock();
180
- });
181
- });
182
- });
183
- return cache;
184
- }
185
- /**
186
- * Используеются для обртной совместимости, а надо ли менять что-то - хз
187
- * @deprecated
188
- */
189
- mutate(args) {
190
- const cache = this.initiate(args);
191
- const resolver = new PromiseResolver();
192
- const subscription = cache.value$.obs.subscribe((state) => {
193
- if (!state.isInitiated || state.isLoading || state.isRepeating)
194
- return;
195
- if (state.isError) {
196
- resolver.reject(state.error);
197
- return;
198
- }
199
- if (!state.isSuccess) {
200
- console.error("Unexpected state in mutation:", state);
201
- resolver.reject(new Error("Unexpected state in mutation"));
202
- return;
203
- }
204
- resolver.resolve(state.data);
205
- });
206
- resolver.promise.finally(() => {
207
- subscription.unsubscribe();
208
- });
209
- return resolver.promise;
210
- }
211
- }
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';
@@ -1,19 +1,4 @@
1
- import { OperationAgentInstanse, OperationDefinition } from "@/query/types";
2
- import type { Operation } from "./Operation";
3
- export declare class OperationAgent<D extends OperationDefinition> implements OperationAgentInstanse<D> {
4
- private _operation;
5
- private _operations$;
6
- state$: import("../../../signals/types").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(_operation: Operation<D>);
16
- private _next;
17
- initiate(args: D["Args"]): void;
18
- createAgent(): OperationAgentInstanse<D>;
19
- }
1
+ /**
2
+ * @deprecated Use `CommandAgent` from '../Command/CommandAgent' instead. Will be removed in v0.6.0.
3
+ */
4
+ export { CommandAgent as OperationAgent } from '../Command/CommandAgent';
@@ -1,54 +1,4 @@
1
- import { Computed, Signal } from "../../../signals";
2
- export class OperationAgent {
3
- _operation;
4
- _operations$ = Signal.create({
5
- current$: null,
6
- }, { isDisabled: true });
7
- state$ = Computed.create(() => {
8
- const operations = this._operations$.get();
9
- const currState = operations.current$?.value$.get();
10
- // Нет текущего состояния — дефолт
11
- if (!currState) {
12
- return {
13
- isLoading: false,
14
- isDone: false,
15
- isSuccess: false,
16
- isError: false,
17
- error: undefined,
18
- data: undefined,
19
- args: undefined,
20
- };
21
- }
22
- return {
23
- isLoading: currState.isLoading,
24
- isDone: currState.isDone,
25
- isSuccess: currState.isSuccess,
26
- isError: currState.isError,
27
- error: currState.error ?? undefined,
28
- data: currState.data ?? undefined,
29
- args: currState.arg,
30
- };
31
- }, { isDisabled: true });
32
- constructor(_operation) {
33
- this._operation = _operation;
34
- }
35
- _next(newCache) {
36
- this._operations$.set({
37
- current$: newCache,
38
- });
39
- }
40
- initiate(args) {
41
- const cache = this._operation.getQueryCache(args);
42
- if (!cache) {
43
- const newCache = this._operation.initiate(args);
44
- this._next(newCache);
45
- return;
46
- }
47
- // Всегда запускаем операцию заново, так как операции обычно не кэшируются как ресурсы
48
- const newCache = this._operation.initiate(args, { cache });
49
- this._next(newCache);
50
- }
51
- createAgent() {
52
- return new OperationAgent(this._operation);
53
- }
54
- }
1
+ /**
2
+ * @deprecated Use `CommandAgent` from '../Command/CommandAgent' instead. Will be removed in v0.6.0.
3
+ */
4
+ export { CommandAgent as OperationAgent } from '../Command/CommandAgent';
@@ -1,4 +1,4 @@
1
- import { ReactiveCache } from "@/query/lib/ReactiveCache";
1
+ import { ReactiveCache } from "../../query/lib/ReactiveCache";
2
2
  export declare class QueriesCache<KEY, VALUE> {
3
3
  private _cacheLifeTime;
4
4
  private readonly _cache;
@@ -1,5 +1,5 @@
1
1
  import { Subject } from "rxjs";
2
- import { OnCacheEntryAdded, OnQueryStarted } from "@/query/types";
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>;
@@ -1,5 +1,5 @@
1
- import { ReactiveCache } from "@/query/lib/ReactiveCache";
2
- import type { ResourceCreateOptions, ResourceDefinition, ResourceInstance, ResourceRefInstanse, ResourceTransaction } from "@/query/types";
1
+ import { ReactiveCache } from "../../../query/lib/ReactiveCache";
2
+ import type { ResourceCreateOptions, ResourceDefinition, ResourceInstance, ResourceRefInstanse, ResourceTransaction } from "../../../query/types";
3
3
  import { ResourceAgent } from "./ResourceAgent";
4
4
  export type CoreResourceQueryState<D extends ResourceDefinition> = {
5
5
  transactions: ResourceTransaction[] | null;
@@ -1,4 +1,4 @@
1
- import { ResourceAgentInstance, ResourceDefinition } from "@/query/types";
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;
@@ -1,7 +1,7 @@
1
1
  import { Computed, Signal } from "../../../signals";
2
2
  export class ResourceAgent {
3
3
  _resource;
4
- _resources$ = Signal.create({
4
+ _resources$ = Signal.state({
5
5
  previous$: null,
6
6
  current$: null,
7
7
  }, { isDisabled: true });
@@ -1,6 +1,6 @@
1
- import { ResourceDefinition } from "@/query/types";
1
+ import { ResourceDefinition } from "../../../query/types";
2
2
  import { CoreResourceQueryState, Resource } from "./Resource";
3
- import { ReadableSignalLike } from "@/signals/types";
3
+ import { ReadableSignalLike } from "../../../signals/types";
4
4
  import { Observable, Subject } from "rxjs";
5
5
  import { ResourceDuplicatorAgent } from "./ResourceDuplicatorAgent";
6
6
  export type DuplicatorOptions<D extends DuplicatorDefinition> = {
@@ -33,7 +33,7 @@ export declare class ResourceDuplicator<D extends DuplicatorDefinition> {
33
33
  createAgent: () => ResourceDuplicatorAgent<D>;
34
34
  /** @deprecated */
35
35
  d_init(args: D['ARGS_ITEM'][]): {
36
- value$: import("@/signals/types").ComputeFn<State<D>>;
36
+ value$: import("../../../signals/types").ComputeFn<State<D>>;
37
37
  };
38
38
  }
39
39
  export declare class ComputedReactiveCache<T> {
@@ -1,4 +1,4 @@
1
- import { Signal, signalize } from "@/signals";
1
+ import { Signal, signalize } from "../../../signals";
2
2
  import { finalize, ReplaySubject, share, Subject, takeUntil, timer } from "rxjs";
3
3
  import { ResourceDuplicatorAgent } from "./ResourceDuplicatorAgent";
4
4
  export class ResourceDuplicator {
@@ -1,5 +1,5 @@
1
- import { ResourceAgentInstance } from "@/query/types";
2
- import { ResourceDuplicator, DuplicatorDefinition } from "@/query/core/Resource/ResourceDuplicator";
1
+ import { ResourceAgentInstance } from "../../../query/types";
2
+ import { ResourceDuplicator, DuplicatorDefinition } from "../../../query/core/Resource/ResourceDuplicator";
3
3
  export declare class ResourceDuplicatorAgent<D extends DuplicatorDefinition> implements ResourceAgentInstance<D['RESOURCE_DEFINITION']> {
4
4
  private _resource;
5
5
  private _resources$;
@@ -1,7 +1,7 @@
1
1
  import { Computed, Signal } from "../../../signals";
2
2
  export class ResourceDuplicatorAgent {
3
3
  _resource;
4
- _resources$ = Signal.create({
4
+ _resources$ = Signal.state({
5
5
  previous$: null,
6
6
  current$: null,
7
7
  }, { isDisabled: true });
@@ -1,4 +1,4 @@
1
- import { ResourceDefinition, ResourceRefInstanse, ResourceTransaction } from "@/query/types";
1
+ import { ResourceDefinition, ResourceRefInstanse, ResourceTransaction } from "../../../query/types";
2
2
  import { Resource } from "./Resource";
3
3
  export declare class ResourceRef<D extends ResourceDefinition> implements ResourceRefInstanse<D> {
4
4
  private readonly _resource;
@@ -1,8 +1,10 @@
1
+ export * from './api/createCommand';
2
+ export * from './react/useCommandAgent';
1
3
  export * from './api/createResource';
2
- export * from './api/createOperation';
3
- export * from './api/resetAllQueriesCache';
4
4
  export * from './api/createResourceDuplicator';
5
+ export * from './api/resetAllQueriesCache';
5
6
  export * from './SKIP_TOKEN';
6
7
  export * from './react/useResourceAgent';
7
8
  export * from './react/useResourceRef';
9
+ export * from './api/createOperation';
8
10
  export * from './react/useOperationAgent';
@@ -1,8 +1,13 @@
1
+ // Command API
2
+ export * from './api/createCommand';
3
+ export * from './react/useCommandAgent';
4
+ // Resource API
1
5
  export * from './api/createResource';
2
- export * from './api/createOperation';
3
- export * from './api/resetAllQueriesCache';
4
6
  export * from './api/createResourceDuplicator';
7
+ export * from './api/resetAllQueriesCache';
5
8
  export * from './SKIP_TOKEN';
6
9
  export * from './react/useResourceAgent';
7
10
  export * from './react/useResourceRef';
11
+ // Deprecated Operation API (backward compatibility)
12
+ export * from './api/createOperation';
8
13
  export * from './react/useOperationAgent';
@@ -1,5 +1,5 @@
1
1
  import { Observable, Subject } from "rxjs";
2
- import { ReadableSignalLike } from "@/signals/types";
2
+ import { ReadableSignalLike } from "../../signals/types";
3
3
  type Options<VALUE> = {
4
4
  /**
5
5
  * Начальное состояние кэша
@@ -0,0 +1,24 @@
1
+ import type { Prettify, CommandAgentInstance, CommandDefinition, CommandQueryState } from "../../query/types";
2
+ type WithAgent<D extends CommandDefinition> = {
3
+ createAgent: () => CommandAgentInstance<D>;
4
+ };
5
+ type TriggerFn<D extends CommandDefinition> = (args: D['Args']) => Promise<D['Data']>;
6
+ type Result<D extends CommandDefinition> = [TriggerFn<D>, Prettify<CommandQueryState<D>>];
7
+ /**
8
+ * React hook для работы с командой (Command).
9
+ *
10
+ * Возвращает кортеж `[trigger, state]`:
11
+ * - `trigger(args)` — инициирует выполнение команды и возвращает Promise с результатом.
12
+ * - `state` — реактивное состояние выполнения команды.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * const [updateUser, state] = useCommandAgent(api.updateUser);
17
+ *
18
+ * const handleSubmit = async () => {
19
+ * const result = await updateUser({ id: 1, name: 'New Name' });
20
+ * };
21
+ * ```
22
+ */
23
+ export declare function useCommandAgent<D extends CommandDefinition>(op: WithAgent<D>): Result<D>;
24
+ export {};
@@ -0,0 +1,39 @@
1
+ import { useConstant, useEventHandler } from "../../common/react";
2
+ import { useSignal } from "../../signals/react";
3
+ /**
4
+ * React hook для работы с командой (Command).
5
+ *
6
+ * Возвращает кортеж `[trigger, state]`:
7
+ * - `trigger(args)` — инициирует выполнение команды и возвращает Promise с результатом.
8
+ * - `state` — реактивное состояние выполнения команды.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const [updateUser, state] = useCommandAgent(api.updateUser);
13
+ *
14
+ * const handleSubmit = async () => {
15
+ * const result = await updateUser({ id: 1, name: 'New Name' });
16
+ * };
17
+ * ```
18
+ */
19
+ export function useCommandAgent(op) {
20
+ const agent = useConstant(() => op.createAgent());
21
+ const state = useSignal(agent.state$);
22
+ const trigger = useEventHandler((args) => {
23
+ agent.initiate(args);
24
+ return new Promise((resolve, reject) => {
25
+ const sub = agent.state$.obs.subscribe((s) => {
26
+ if (s.isDone && !s.isLoading) {
27
+ sub.unsubscribe();
28
+ if (s.isSuccess) {
29
+ resolve(s.data);
30
+ }
31
+ else {
32
+ reject(s.error);
33
+ }
34
+ }
35
+ });
36
+ });
37
+ });
38
+ return [trigger, state];
39
+ }
@@ -1,8 +1,6 @@
1
- import type { Prettify, OperationAgentInstanse, OperationDefinition, OperationQueryState } from "../../query/types";
2
- type WithAgent<D extends OperationDefinition> = {
3
- createAgent: () => OperationAgentInstanse<D>;
4
- };
5
- type TriggerFn<D extends OperationDefinition> = (args: D['Args']) => Promise<D['Data']>;
6
- type Result<D extends OperationDefinition> = [TriggerFn<D>, Prettify<OperationQueryState<D>>];
7
- export declare function useOperationAgent<D extends OperationDefinition>(op: WithAgent<D>): Result<D>;
8
- export {};
1
+ import { useCommandAgent } from './useCommandAgent';
2
+ /**
3
+ * @deprecated Use `useCommandAgent` instead. Will be removed in v0.6.0.
4
+ * @see useCommandAgent
5
+ */
6
+ export declare const useOperationAgent: typeof useCommandAgent;
@@ -1,23 +1,6 @@
1
- import { useConstant, useEventHandler } from "../../common/react";
2
- import { useSignal } from "../../signals/react";
3
- export function useOperationAgent(op) {
4
- const agent = useConstant(() => op.createAgent());
5
- const state = useSignal(agent.state$);
6
- const trigger = useEventHandler((args) => {
7
- agent.initiate(args);
8
- return new Promise((resolve, reject) => {
9
- const sub = agent.state$.obs.subscribe((s) => {
10
- if (s.isDone && !s.isLoading) {
11
- sub.unsubscribe();
12
- if (s.isSuccess) {
13
- resolve(s.data);
14
- }
15
- else {
16
- reject(s.error);
17
- }
18
- }
19
- });
20
- });
21
- });
22
- return [trigger, state];
23
- }
1
+ import { useCommandAgent } from './useCommandAgent';
2
+ /**
3
+ * @deprecated Use `useCommandAgent` instead. Will be removed in v0.6.0.
4
+ * @see useCommandAgent
5
+ */
6
+ export const useOperationAgent = useCommandAgent;
@@ -1,6 +1,6 @@
1
- import { Prettify, ResourceDefinition, ResourceInstance, ResourceQueryState } from "@/query/types";
2
- import { SKIP } from "@/query/SKIP_TOKEN";
3
- import { DuplicatorDefinition, ResourceDuplicator } from "@/query/core/Resource/ResourceDuplicator";
1
+ import { Prettify, ResourceDefinition, ResourceInstance, ResourceQueryState } from "../../query/types";
2
+ import { SKIP } from "../../query/SKIP_TOKEN";
3
+ import { DuplicatorDefinition, ResourceDuplicator } from "../../query/core/Resource/ResourceDuplicator";
4
4
  type Result<D extends ResourceDefinition> = Prettify<ResourceQueryState<D>>;
5
5
  export declare function useResourceAgent<D extends ResourceDefinition>(res: ResourceInstance<D> | ResourceDuplicator<DuplicatorDefinition<D>>, ...argss: D['Args'] extends void ? [] | [typeof SKIP] : [D['Args'] | typeof SKIP]): Result<D>;
6
6
  export {};