@usearete/react 0.1.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +350 -61
- package/dist/index.cjs +2344 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +516 -66
- package/dist/index.esm.js +1800 -9653
- package/dist/index.esm.js.map +1 -1
- package/eslint-plugin.cjs +5 -0
- package/eslint-rules/arete-hooks.js +171 -0
- package/eslint-rules/package.json +3 -0
- package/package.json +18 -9
- package/dist/index.js +0 -10033
- package/dist/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, Arete, AreteError, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, BuiltInstruction, ConfirmationLevel, ConnectionManager, ConnectionState, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, EntityFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, InstructionDefinition, InstructionExecutor, InstructionExecutorOptions, InstructionHandler, MemoryAdapter, PdaConfig, PdaSeed, ProgramError, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, Schema, SnapshotEntity, SnapshotFrame, StackDefinition, StorageAdapter, StorageAdapterConfig, Subscription, SubscriptionRegistry, Update, UpdateCallback, ViewDef, ViewGroup, WalletAdapter, WalletConnectOptions, WalletState, createInstructionExecutor, createPublicKeySeed, createSeed, derivePda, executeInstruction, formatProgramError, isSnapshotFrame, isValidFrame, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, serializeInstructionData, validateAccountResolution, waitForConfirmation } from '@usearete/sdk';
|
|
2
|
+
import { StackDefinition, WalletAdapter, ConnectOptions, AuthConfig, Schema, ProgramSdkDefinition, ConnectionState, ConnectedArete, StackWithAttachedPrograms, PreparedOperation, TransactionFailureOutcome, OperationExecutionEvent, OperationExecutionSuccessEvent, OperationTransactionReceipt, TransactionOutcome, ProgramInterface, TypedInstruction, OperationReceiptFor, StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ViewSortConfig, QueriesInterface, ChainClient, StackConnectedExtensions, SocketIssue, StackQueryDefinition, ViewGroup, ViewDef, ContextSlotOptions, NativeBalanceInfo, TokenBalanceInput, TokenBalanceInfo, WaitForProcessedSlotOptions } from '@usearete/sdk';
|
|
3
|
+
export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, Arete, AreteError, AreteOptions, AreteOptionsWithStorage, ArgSchema, ArgType, AuthConfig, BuildOptions, BuiltAccountMeta, BuiltInstruction, ConfirmationLevel, ConnectOptions, ConnectedArete, ConnectionManager, ConnectionState, ContextSlotOptions, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, DefaultViewKey, EntityFrame, ErrorFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, FrameValidationDiagnostic, InstructionError, InstructionExecutor, InstructionHandler, InstructionHandlerConfig, MemoryAdapter, MergeProgramMaps, NativeBalanceInfo, OperationCallbackError, OperationExecutionError, OperationExecutionOptions, OperationReceiptFor, OperationTransactionReceipt, PdaConfig, PdaSeed, PreparedFlow, PreparedInstruction, PreparedOperation, PreparedTransaction, PreparedTransactionInstruction, ProcessedSlotTimeoutError, ProgramError, QueryLease, QuerySnapshot, QueryStore, ReadRequestError, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, Schema, SendOptions, SendResult, SnapshotEntity, SnapshotFrame, SocketIssue, StackDefinition, StackWithAttachedPrograms, StorageAdapter, StorageAdapterConfig, StringifiedBigints, SubscribedFrame, Subscription, SubscriptionQuery, SubscriptionRegistry, SubscriptionRequest, SubscriptionSnapshotOptions, TokenBalanceInfo, TokenBalanceInput, TransactionExecutionError, TransactionFailureOutcome, TransactionOptions, TransactionOutcome, TypedInstruction, UnsubscribedFrame, Update, UpdateCallback, ViewDef, ViewGroup, ViewKeyValue, WaitForProcessedSlotOptions, WalletAdapter, WalletConnectOptions, WalletState, buildInstruction, canonicalQueryKey, createInstructionExecutor, createInstructionHandler, createPublicKeySeed, createSeed, derivePda, executeInstruction, formatProgramError, formatRawToUi, getTransactionFailureOutcome, isErrorFrame, isHostedAreteEndpoint, isSnapshotFrame, isSubscribedFrame, isUnsubscribedFrame, isValidFrame, normalizeSubscriptionQuery, parseFrame, parseFrameFromBlob, parseInstructionError, resolveAccounts, safeToRawAmount, serializeInstructionData, serializeViewKey, stringifyBigints, toRawAmount, unwrapOperationExecutionError, validateAccountResolution, withPrograms } from '@usearete/sdk';
|
|
5
4
|
import { UseBoundStore, StoreApi } from 'zustand';
|
|
6
5
|
|
|
7
6
|
type ViewMode = 'state' | 'list';
|
|
@@ -15,57 +14,162 @@ interface TransactionDefinition<TParams = unknown> {
|
|
|
15
14
|
key?: string | ((params: TParams) => string);
|
|
16
15
|
}>;
|
|
17
16
|
}
|
|
17
|
+
type ProgramMap$3 = Record<string, ProgramSdkDefinition>;
|
|
18
18
|
/**
|
|
19
19
|
* Global configuration for AreteProvider.
|
|
20
20
|
*
|
|
21
|
-
* Note: WebSocket URL is
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* Note: WebSocket URL is usually embedded in the stack definition
|
|
22
|
+
* (`stack.endpoints.ws` / `stack.endpoints.http`). Override it for the whole
|
|
23
|
+
* app via `stackOptions`, or per-hook via `useArete(stack, { url, httpUrl })`.
|
|
24
24
|
*/
|
|
25
25
|
interface AreteConfig {
|
|
26
|
+
/**
|
|
27
|
+
* Default stack for the app. When set, components can call `useArete()`
|
|
28
|
+
* with no arguments; passing a stack explicitly always wins. Register the
|
|
29
|
+
* stack's type once for full inference on argument-less calls:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* declare module '@usearete/react' {
|
|
33
|
+
* interface AreteDefaultStackRegistry { defaultStack: OreStreamStack }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
stack?: StackDefinition;
|
|
38
|
+
/**
|
|
39
|
+
* Default lookup options for the provider stack. They also apply when that
|
|
40
|
+
* same stack is passed explicitly to `useArete(stack)` without options.
|
|
41
|
+
*/
|
|
42
|
+
stackOptions?: ClientLookupOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Connect immediately when the client is created (defaults to true).
|
|
45
|
+
* Provider connection settings are applied when a shared client is created;
|
|
46
|
+
* changing them does not mutate an existing client. Call retry() to replace
|
|
47
|
+
* that client with the latest settings. Wallet is the reactive exception.
|
|
48
|
+
*/
|
|
26
49
|
autoConnect?: boolean;
|
|
50
|
+
/** Reconnect automatically after an established connection is lost (defaults to true). */
|
|
51
|
+
autoReconnect?: boolean;
|
|
27
52
|
wallet?: WalletAdapter;
|
|
28
53
|
reconnectIntervals?: number[];
|
|
29
54
|
maxReconnectAttempts?: number;
|
|
30
55
|
maxEntriesPerView?: number | null;
|
|
31
56
|
flushIntervalMs?: number;
|
|
57
|
+
fetch?: ConnectOptions['fetch'];
|
|
58
|
+
validateFrames?: boolean;
|
|
59
|
+
/** Receives structured details when a generated schema rejects a frame. */
|
|
60
|
+
onFrameValidationError?: ConnectOptions['onFrameValidationError'];
|
|
32
61
|
/** Authentication configuration */
|
|
33
|
-
auth?:
|
|
62
|
+
auth?: AuthConfig;
|
|
34
63
|
}
|
|
35
64
|
/**
|
|
36
|
-
*
|
|
65
|
+
* Client lookup/connect options for React hooks.
|
|
37
66
|
*/
|
|
38
|
-
interface
|
|
39
|
-
/** Override the stack's embedded URL (useful for local development) */
|
|
67
|
+
interface ClientLookupOptions<TPrograms extends ProgramMap$3 | undefined = undefined> {
|
|
68
|
+
/** Override the stack's embedded WebSocket URL (useful for local development) */
|
|
40
69
|
url?: string;
|
|
70
|
+
/** Override the stack's embedded HTTP read URL (useful for local development) */
|
|
71
|
+
httpUrl?: string;
|
|
72
|
+
/** Override the stack transport. HTTP mode disables streaming view subscriptions. */
|
|
73
|
+
transport?: ConnectOptions<TPrograms>['transport'];
|
|
74
|
+
/** Attach additional program SDKs to the connected client. */
|
|
75
|
+
programs?: TPrograms;
|
|
41
76
|
}
|
|
42
|
-
|
|
77
|
+
type UseAreteOptions<TPrograms extends ProgramMap$3 | undefined = undefined> = ClientLookupOptions<TPrograms>;
|
|
78
|
+
interface ViewSchemaValidationDiagnostic {
|
|
79
|
+
readonly view: string;
|
|
80
|
+
readonly key?: string;
|
|
81
|
+
readonly entity: unknown;
|
|
82
|
+
readonly error: unknown;
|
|
83
|
+
}
|
|
84
|
+
type ViewSchemaValidationErrorCallback = (diagnostic: ViewSchemaValidationDiagnostic) => void;
|
|
85
|
+
interface ViewHookSharedOptions<TSchema = unknown> {
|
|
43
86
|
enabled?: boolean;
|
|
44
|
-
|
|
45
|
-
refreshOnReconnect?: boolean;
|
|
46
|
-
/** Schema to validate entities. Returns undefined if validation fails. */
|
|
87
|
+
/** Schema used to validate and project cached entities. Rejected entities are excluded. */
|
|
47
88
|
schema?: Schema<TSchema>;
|
|
89
|
+
/** Observe entities rejected by the caller-supplied schema. */
|
|
90
|
+
onSchemaValidationError?: ViewSchemaValidationErrorCallback;
|
|
48
91
|
/** Whether to include initial snapshot (defaults to true) */
|
|
49
92
|
withSnapshot?: boolean;
|
|
50
93
|
/** Cursor for resuming from a specific point (_seq value) */
|
|
51
94
|
after?: string;
|
|
52
95
|
/** Maximum number of entities to include in snapshot */
|
|
53
96
|
snapshotLimit?: number;
|
|
97
|
+
partition?: string;
|
|
98
|
+
filters?: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
interface StateViewHookOptions<TSchema = unknown> extends ViewHookSharedOptions<TSchema> {
|
|
101
|
+
initialData?: TSchema;
|
|
102
|
+
}
|
|
103
|
+
interface ListViewHookOptions<TSchema = unknown> extends ViewHookSharedOptions<TSchema> {
|
|
104
|
+
initialData?: readonly TSchema[];
|
|
54
105
|
}
|
|
55
|
-
interface
|
|
106
|
+
interface ListOneViewHookOptions<TSchema = unknown> extends ViewHookSharedOptions<TSchema> {
|
|
107
|
+
initialData?: TSchema;
|
|
108
|
+
}
|
|
109
|
+
/** @deprecated Use StateViewHookOptions, ListViewHookOptions, or ListOneViewHookOptions. */
|
|
110
|
+
type ViewHookOptions<TSchema = unknown> = StateViewHookOptions<TSchema> | ListViewHookOptions<TSchema> | ListOneViewHookOptions<TSchema>;
|
|
111
|
+
/**
|
|
112
|
+
* Lifecycle status of a view hook:
|
|
113
|
+
* - `'disabled'` — no key/params or `enabled: false`; nothing is subscribed.
|
|
114
|
+
* - `'connecting'` — enabled, but the Arete client has not connected yet.
|
|
115
|
+
* - `'subscribing'` — subscribed, waiting for the first snapshot.
|
|
116
|
+
* - `'ready'` — data is usable, from a live snapshot or trusted `initialData`.
|
|
117
|
+
* - `'error'` — the subscription failed; see `error`.
|
|
118
|
+
*/
|
|
119
|
+
type ViewStatus = 'disabled' | 'connecting' | 'subscribing' | 'ready' | 'error';
|
|
120
|
+
interface ViewHookResultBase<T> {
|
|
56
121
|
data: T | undefined;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
refresh: () => void;
|
|
122
|
+
isRefreshing: boolean;
|
|
123
|
+
refresh: () => Promise<void>;
|
|
60
124
|
}
|
|
125
|
+
type EmptyViewData<T> = T extends readonly unknown[] ? T : undefined;
|
|
126
|
+
type ViewHookResult<T> = (ViewHookResultBase<T> & {
|
|
127
|
+
status: 'disabled';
|
|
128
|
+
isPending: false;
|
|
129
|
+
isReady: false;
|
|
130
|
+
isEmpty: false;
|
|
131
|
+
isLoading: false;
|
|
132
|
+
error: undefined;
|
|
133
|
+
}) | (ViewHookResultBase<T> & {
|
|
134
|
+
status: 'connecting' | 'subscribing';
|
|
135
|
+
isPending: true;
|
|
136
|
+
isReady: false;
|
|
137
|
+
isEmpty: false;
|
|
138
|
+
isLoading: boolean;
|
|
139
|
+
error: undefined;
|
|
140
|
+
}) | (ViewHookResultBase<T> & {
|
|
141
|
+
status: 'error';
|
|
142
|
+
isPending: false;
|
|
143
|
+
isReady: false;
|
|
144
|
+
isEmpty: false;
|
|
145
|
+
isLoading: false;
|
|
146
|
+
error: Error;
|
|
147
|
+
}) | (Omit<ViewHookResultBase<T>, 'data'> & {
|
|
148
|
+
data: T;
|
|
149
|
+
status: 'ready';
|
|
150
|
+
isPending: false;
|
|
151
|
+
isReady: true;
|
|
152
|
+
isEmpty: false;
|
|
153
|
+
isLoading: false;
|
|
154
|
+
error: undefined;
|
|
155
|
+
}) | (Omit<ViewHookResultBase<T>, 'data'> & {
|
|
156
|
+
data: EmptyViewData<T>;
|
|
157
|
+
status: 'ready';
|
|
158
|
+
isPending: false;
|
|
159
|
+
isReady: true;
|
|
160
|
+
isEmpty: true;
|
|
161
|
+
isLoading: false;
|
|
162
|
+
error: undefined;
|
|
163
|
+
});
|
|
61
164
|
interface ListParamsBase<TSchema = unknown> {
|
|
62
165
|
key?: string;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
filters?: Record<string, string>;
|
|
166
|
+
partition?: string;
|
|
167
|
+
filters?: Record<string, unknown>;
|
|
66
168
|
skip?: number;
|
|
67
169
|
/** Schema to validate/filter entities. Only entities passing safeParse will be returned. */
|
|
68
170
|
schema?: Schema<TSchema>;
|
|
171
|
+
/** Observe entities rejected by the caller-supplied schema. */
|
|
172
|
+
onSchemaValidationError?: ViewSchemaValidationErrorCallback;
|
|
69
173
|
/** Whether to include initial snapshot (defaults to true) */
|
|
70
174
|
withSnapshot?: boolean;
|
|
71
175
|
/** Cursor for resuming from a specific point (_seq value) */
|
|
@@ -87,46 +191,242 @@ interface UseMutationReturn {
|
|
|
87
191
|
signature?: string;
|
|
88
192
|
reset: () => void;
|
|
89
193
|
}
|
|
90
|
-
interface StateViewHook<T> {
|
|
91
|
-
use: (key:
|
|
92
|
-
|
|
93
|
-
|
|
194
|
+
interface StateViewHook<T, TKey = string> {
|
|
195
|
+
use: (key: TKey | null | undefined, options?: StateViewHookOptions<T>) => ViewHookResult<T>;
|
|
196
|
+
/**
|
|
197
|
+
* Refresh active subscriptions for this view without holding a hook result.
|
|
198
|
+
* Pass a key to refresh one keyed subscription; omit it to refresh every
|
|
199
|
+
* active subscription of the view. No-op when nothing is subscribed, which
|
|
200
|
+
* makes it safe to use in `reconcile: { refresh: [...] }` targets.
|
|
201
|
+
*/
|
|
202
|
+
refresh: (key?: TKey | null) => Promise<void>;
|
|
94
203
|
}
|
|
95
204
|
interface ListViewHook<T> {
|
|
96
|
-
use<TSchema = T>(params: ListParamsSingle<TSchema>, options?:
|
|
97
|
-
use<TSchema = T>(params?: ListParamsMultiple<TSchema>, options?:
|
|
98
|
-
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?:
|
|
205
|
+
use<TSchema = T>(params: ListParamsSingle<TSchema>, options?: ListOneViewHookOptions<TSchema>): ViewHookResult<TSchema>;
|
|
206
|
+
use<TSchema = T>(params?: ListParamsMultiple<TSchema>, options?: ListViewHookOptions<TSchema>): ViewHookResult<TSchema[]>;
|
|
207
|
+
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?: ListOneViewHookOptions<TSchema>) => ViewHookResult<TSchema>;
|
|
208
|
+
/** Refresh every active subscription of this list view. No-op when none. */
|
|
209
|
+
refresh: () => Promise<void>;
|
|
99
210
|
}
|
|
100
211
|
|
|
212
|
+
type ProgramMap$2 = Record<string, ProgramSdkDefinition>;
|
|
213
|
+
type ResolvedStack$1<TStack extends StackDefinition, TPrograms extends ProgramMap$2 | undefined> = StackWithAttachedPrograms<TStack, TPrograms>;
|
|
214
|
+
interface ClientChange {
|
|
215
|
+
cacheKey: string;
|
|
216
|
+
status: 'connecting' | 'connected' | 'error';
|
|
217
|
+
error?: Error;
|
|
218
|
+
}
|
|
101
219
|
interface AreteContextValue {
|
|
102
|
-
getOrCreateClient: <TStack extends StackDefinition>(stack: TStack,
|
|
103
|
-
getClient: <TStack extends StackDefinition>(stack: TStack | undefined) =>
|
|
104
|
-
|
|
220
|
+
getOrCreateClient: <TStack extends StackDefinition, TPrograms extends ProgramMap$2 | undefined = undefined>(stack: TStack, options?: ClientLookupOptions<TPrograms>) => Promise<ConnectedArete<ResolvedStack$1<TStack, TPrograms>>>;
|
|
221
|
+
getClient: <TStack extends StackDefinition, TPrograms extends ProgramMap$2 | undefined = undefined>(stack: TStack | undefined, options?: ClientLookupOptions<TPrograms>) => ConnectedArete<ResolvedStack$1<TStack, TPrograms>> | null;
|
|
222
|
+
retryClient: <TStack extends StackDefinition, TPrograms extends ProgramMap$2 | undefined = undefined>(stack: TStack, options?: ClientLookupOptions<TPrograms>) => Promise<ConnectedArete<ResolvedStack$1<TStack, TPrograms>>>;
|
|
223
|
+
subscribeToClientChanges: (callback: (change?: ClientChange) => void) => () => void;
|
|
105
224
|
config: AreteConfig;
|
|
106
225
|
}
|
|
107
|
-
declare function AreteProvider({ children,
|
|
226
|
+
declare function AreteProvider({ children, ...config }: AreteConfig & {
|
|
108
227
|
children: ReactNode;
|
|
109
|
-
fallback?: ReactNode;
|
|
110
228
|
}): React.JSX.Element;
|
|
111
229
|
declare function useAreteContext(): AreteContextValue;
|
|
112
|
-
declare function useConnectionState(stack?: StackDefinition): ConnectionState;
|
|
113
|
-
declare function useView<T>(stack: StackDefinition, viewPath: string): T[];
|
|
114
|
-
declare function useEntity<T>(stack: StackDefinition, viewPath: string, key: string): T | null;
|
|
230
|
+
declare function useConnectionState(stack?: StackDefinition, options?: ClientLookupOptions): ConnectionState;
|
|
115
231
|
|
|
116
232
|
type MutationStatus = 'idle' | 'pending' | 'success' | 'error';
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
233
|
+
type MutationPhase = 'idle' | 'preparing' | 'awaiting-wallet' | 'submitted' | 'confirmed' | 'reconciling' | 'reconciled' | 'confirmed-unreconciled' | 'not-submitted' | 'submitted-unknown' | 'chain-failed';
|
|
234
|
+
interface MutationLifecycleEvent<TResult = unknown, TPrepared extends PreparedOperation = PreparedOperation> {
|
|
235
|
+
readonly phase: MutationPhase;
|
|
236
|
+
readonly prepared: TPrepared | null;
|
|
237
|
+
readonly result?: TResult;
|
|
238
|
+
readonly failure?: TransactionFailureOutcome;
|
|
239
|
+
readonly error?: Error;
|
|
240
|
+
readonly transactionEvent?: OperationExecutionEvent<TPrepared> | OperationExecutionSuccessEvent<TPrepared>;
|
|
241
|
+
}
|
|
242
|
+
interface MutationReconciliationContext<TResult = unknown, TPrepared extends PreparedOperation = PreparedOperation> {
|
|
243
|
+
readonly result: TResult;
|
|
244
|
+
readonly prepared: TPrepared | null;
|
|
245
|
+
readonly signatures: readonly string[];
|
|
246
|
+
readonly completedReceipts: readonly OperationTransactionReceipt[];
|
|
247
|
+
readonly signal: AbortSignal;
|
|
248
|
+
}
|
|
249
|
+
interface MutationExecutionObserver<TPrepared extends PreparedOperation = PreparedOperation> {
|
|
250
|
+
onPrepared(prepared: TPrepared): void;
|
|
251
|
+
onAwaitingWallet(): void;
|
|
252
|
+
onTransactionStart(event: OperationExecutionEvent<TPrepared>): void;
|
|
253
|
+
onTransactionSuccess(event: OperationExecutionSuccessEvent<TPrepared>): void;
|
|
254
|
+
onCallbackError(error: unknown): void;
|
|
255
|
+
}
|
|
256
|
+
type MutationReconcileFn<TResult = unknown, TPrepared extends PreparedOperation = PreparedOperation> = (context: MutationReconciliationContext<TResult, TPrepared>) => unknown | Promise<unknown>;
|
|
257
|
+
/**
|
|
258
|
+
* Anything that can be refreshed after a mutation reconciles: a plain
|
|
259
|
+
* callback, or any hook result carrying a `refresh` method (view hooks from
|
|
260
|
+
* `arete.views.*` and read hooks from `arete.read.*`), so callers can write
|
|
261
|
+
* `reconcile: { refresh: [board, round, quoteRead] }` without extracting
|
|
262
|
+
* `.refresh` functions by hand.
|
|
263
|
+
*/
|
|
264
|
+
type ReconciliationRefreshTarget = (() => unknown | Promise<unknown>) | {
|
|
265
|
+
readonly refresh: () => unknown | Promise<unknown>;
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Shorthand overrides for the default reconciliation injected into generated
|
|
269
|
+
* program hooks. Only valid when the hook-level default is a marked default
|
|
270
|
+
* reconciliation (see `createProcessedSlotReconciliation`).
|
|
271
|
+
*/
|
|
272
|
+
interface MutationReconcileOverrides {
|
|
273
|
+
readonly refresh?: ReconciliationRefreshTarget | readonly ReconciliationRefreshTarget[];
|
|
274
|
+
readonly timeoutMs?: number;
|
|
120
275
|
}
|
|
121
|
-
|
|
122
|
-
|
|
276
|
+
type UseMutationOptions<TOptions extends object = Record<string, unknown>, TResult = unknown, TPrepared extends PreparedOperation = PreparedOperation> = TOptions & {
|
|
277
|
+
onConfirmed?: (result: TResult) => void | Promise<void>;
|
|
278
|
+
onSuccess?: (result: TResult) => void | Promise<void>;
|
|
279
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
280
|
+
reconcile?: false | MutationReconcileFn<TResult, TPrepared> | MutationReconcileOverrides;
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Result of {@link useInstructionMutation}.
|
|
284
|
+
*
|
|
285
|
+
* `phase` is the primary, discriminated status: it walks
|
|
286
|
+
* 'preparing' → 'awaiting-wallet' → 'submitted' → 'confirmed' →
|
|
287
|
+
* 'reconciling' → 'reconciled' on the happy path, and lands on
|
|
288
|
+
* 'confirmed-unreconciled', 'not-submitted', 'submitted-unknown', or
|
|
289
|
+
* 'chain-failed' otherwise. UIs should branch on `phase` for busy labels and
|
|
290
|
+
* on {@link UseMutationResult.displayError} /
|
|
291
|
+
* {@link UseMutationResult.reconciliationError} for messages.
|
|
292
|
+
*
|
|
293
|
+
* `failure` and `outcome` describe chain execution only; callback and
|
|
294
|
+
* reconciliation failures never replace a confirmed outcome.
|
|
295
|
+
*/
|
|
296
|
+
interface UseMutationResult<TParams = Record<string, unknown>, TResult = unknown, TOptions extends object = Record<string, unknown>, TPrepared extends PreparedOperation = PreparedOperation> {
|
|
297
|
+
/** Event-handler form. Errors are recorded in mutation state and do not escape. */
|
|
298
|
+
mutate: (args: TParams, options?: Partial<UseMutationOptions<TOptions, TResult, TPrepared>>) => void;
|
|
299
|
+
/** Rejecting form for imperative composition. Equivalent to submit(). */
|
|
300
|
+
mutateAsync: (args: TParams, options?: Partial<UseMutationOptions<TOptions, TResult, TPrepared>>) => Promise<TResult>;
|
|
301
|
+
submit: (args: TParams, options?: Partial<UseMutationOptions<TOptions, TResult, TPrepared>>) => Promise<TResult>;
|
|
123
302
|
status: MutationStatus;
|
|
303
|
+
phase: MutationPhase;
|
|
304
|
+
latestEvent: MutationLifecycleEvent<TResult, TPrepared> | null;
|
|
124
305
|
error: string | null;
|
|
306
|
+
displayError: string | null;
|
|
307
|
+
failure: TransactionFailureOutcome | null;
|
|
308
|
+
outcome: TransactionOutcome | null;
|
|
309
|
+
prepared: TPrepared | null;
|
|
310
|
+
data: TResult | undefined;
|
|
311
|
+
result: TResult | undefined;
|
|
312
|
+
signatures: string[];
|
|
125
313
|
signature: string | null;
|
|
314
|
+
completedReceipts: OperationTransactionReceipt[];
|
|
315
|
+
callbackError: Error | null;
|
|
316
|
+
callbackErrors: Error[];
|
|
317
|
+
reconciliationError: Error | null;
|
|
126
318
|
isLoading: boolean;
|
|
319
|
+
isConfirmed: boolean;
|
|
320
|
+
isSubmittedUnknown: boolean;
|
|
321
|
+
isPreparing: boolean;
|
|
322
|
+
isAwaitingWallet: boolean;
|
|
323
|
+
isReconciling: boolean;
|
|
324
|
+
canRetryReconciliation: boolean;
|
|
325
|
+
/** Retry only post-confirmation stream reconciliation; never resubmits. */
|
|
326
|
+
retryReconciliation: () => Promise<void>;
|
|
127
327
|
reset: () => void;
|
|
128
328
|
}
|
|
129
|
-
|
|
329
|
+
type MutationExecutor<TParams = Record<string, unknown>, TResult = unknown, TOptions extends object = Record<string, unknown>, TPrepared extends PreparedOperation = PreparedOperation> = {
|
|
330
|
+
(args: TParams, options?: TOptions, observer?: MutationExecutionObserver<TPrepared>): Promise<TResult>;
|
|
331
|
+
};
|
|
332
|
+
declare function useInstructionMutation<TParams = Record<string, unknown>, TResult = unknown, TOptions extends object = Record<string, unknown>, TPrepared extends PreparedOperation = PreparedOperation>(execute: MutationExecutor<TParams, TResult, TOptions, TPrepared>, defaults?: Partial<UseMutationOptions<TOptions, TResult, TPrepared>>): UseMutationResult<TParams, TResult, TOptions, TPrepared>;
|
|
333
|
+
|
|
334
|
+
type OperationOptionsArg<TClient> = TClient extends {
|
|
335
|
+
execute(prepared: PreparedOperation, options?: infer TOptions): Promise<unknown>;
|
|
336
|
+
} ? NonNullable<TOptions> : Record<string, unknown>;
|
|
337
|
+
type RawOptionsArg<TClient> = TClient extends {
|
|
338
|
+
transaction(instructions: readonly unknown[], options?: infer TOptions): Promise<unknown>;
|
|
339
|
+
} ? NonNullable<TOptions> : Record<string, unknown>;
|
|
340
|
+
type ConnectedOperationLike = {
|
|
341
|
+
prepare(input: unknown): Promise<PreparedOperation>;
|
|
342
|
+
};
|
|
343
|
+
type RawInstructionHookFor<THandler, TClient> = THandler extends TypedInstruction<infer P, infer E> ? {
|
|
344
|
+
useMutation: (options?: Partial<UseMutationOptions<RawOptionsArg<TClient>, E>>) => UseMutationResult<P, E, RawOptionsArg<TClient>>;
|
|
345
|
+
execute: (input: P, options?: RawOptionsArg<TClient>) => Promise<E>;
|
|
346
|
+
build: THandler['build'];
|
|
347
|
+
} : never;
|
|
348
|
+
type OperationHookFor<TOperation, TClient> = TOperation extends {
|
|
349
|
+
prepare(input: infer P): Promise<infer TPrepared extends PreparedOperation>;
|
|
350
|
+
} ? {
|
|
351
|
+
useMutation: (options?: Partial<UseMutationOptions<OperationOptionsArg<TClient>, OperationReceiptFor<TPrepared>, TPrepared>>) => UseMutationResult<P, OperationReceiptFor<TPrepared>, OperationOptionsArg<TClient>, TPrepared>;
|
|
352
|
+
execute: (input: P, options?: OperationOptionsArg<TClient>) => Promise<OperationReceiptFor<TPrepared>>;
|
|
353
|
+
prepare: TOperation['prepare'];
|
|
354
|
+
} : never;
|
|
355
|
+
type OperationHookNamespace<TNamespace, TClient> = {
|
|
356
|
+
[K in keyof TNamespace]: TNamespace[K] extends ConnectedOperationLike ? OperationHookFor<TNamespace[K], TClient> : TNamespace[K] extends Record<string, unknown> ? OperationHookNamespace<TNamespace[K], TClient> : never;
|
|
357
|
+
};
|
|
358
|
+
type ProgramHookInterface<TProgram extends ProgramSdkDefinition, TClient> = Omit<ProgramInterface<TProgram>, 'raw' | 'instructions' | 'transactions' | 'flows'> & {
|
|
359
|
+
raw: {
|
|
360
|
+
[K in keyof ProgramInterface<TProgram>['raw']]: RawInstructionHookFor<ProgramInterface<TProgram>['raw'][K], TClient>;
|
|
361
|
+
};
|
|
362
|
+
instructions: OperationHookNamespace<ProgramInterface<TProgram>['instructions'], TClient>;
|
|
363
|
+
transactions: OperationHookNamespace<ProgramInterface<TProgram>['transactions'], TClient>;
|
|
364
|
+
flows: OperationHookNamespace<ProgramInterface<TProgram>['flows'], TClient>;
|
|
365
|
+
};
|
|
366
|
+
type BuildProgramInterface<TPrograms extends Record<string, ProgramSdkDefinition> | undefined, TClient> = TPrograms extends Record<string, ProgramSdkDefinition> ? {
|
|
367
|
+
[K in keyof TPrograms]: ProgramHookInterface<TPrograms[K], TClient>;
|
|
368
|
+
} : Record<string, never>;
|
|
369
|
+
|
|
370
|
+
type AsyncReadKey = string | number | bigint | boolean | null | undefined | readonly AsyncReadKey[] | {
|
|
371
|
+
readonly [key: string]: AsyncReadKey;
|
|
372
|
+
};
|
|
373
|
+
interface AsyncReadContext {
|
|
374
|
+
readonly signal: AbortSignal;
|
|
375
|
+
readonly key: AsyncReadKey;
|
|
376
|
+
}
|
|
377
|
+
interface UseAsyncReadOptions<T> {
|
|
378
|
+
enabled?: boolean;
|
|
379
|
+
initialData?: T;
|
|
380
|
+
debounceMs?: number;
|
|
381
|
+
/** Status to expose when the read is disabled by an unavailable dependency. */
|
|
382
|
+
disabledStatus?: Extract<AsyncReadStatus, 'disabled' | 'connecting'>;
|
|
383
|
+
}
|
|
384
|
+
type AsyncReadStatus = 'disabled' | 'connecting' | 'loading' | 'ready' | 'refreshing' | 'error';
|
|
385
|
+
interface UseAsyncReadResult<T> {
|
|
386
|
+
data: T | undefined;
|
|
387
|
+
error: Error | null;
|
|
388
|
+
status: AsyncReadStatus;
|
|
389
|
+
/** True while the read is connecting or loading its first result. */
|
|
390
|
+
isPending: boolean;
|
|
391
|
+
/** True after the read has completed once, including during a refresh. */
|
|
392
|
+
isReady: boolean;
|
|
393
|
+
/** True when a ready read resolved to `null` or `undefined`. */
|
|
394
|
+
isEmpty: boolean;
|
|
395
|
+
isLoading: boolean;
|
|
396
|
+
isRefreshing: boolean;
|
|
397
|
+
refresh: () => Promise<T | undefined>;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Minimal keyed async state with no cache, retry, or request deduplication.
|
|
401
|
+
* A newer request aborts and supersedes the previous request for this hook.
|
|
402
|
+
*
|
|
403
|
+
* The returned state is tagged with the key that produced it: when the key
|
|
404
|
+
* changes, the hook immediately reports the fresh key's initial state instead
|
|
405
|
+
* of briefly exposing data fetched for the previous key. Callers never need
|
|
406
|
+
* to re-verify that `data` matches the arguments they passed.
|
|
407
|
+
*/
|
|
408
|
+
declare function useAsyncRead<T>(key: AsyncReadKey, read: (context: AsyncReadContext) => Promise<T>, options?: UseAsyncReadOptions<T>): UseAsyncReadResult<T>;
|
|
409
|
+
|
|
410
|
+
type NullableArgs<TArgs extends readonly unknown[]> = {
|
|
411
|
+
[I in keyof TArgs]: TArgs[I] | undefined | null;
|
|
412
|
+
};
|
|
413
|
+
type RequiredNullableArgs<TArgs extends readonly unknown[]> = {
|
|
414
|
+
[I in keyof TArgs]-?: TArgs[I] | undefined | null;
|
|
415
|
+
};
|
|
416
|
+
type ReactReadInterface<TRead> = [TRead] extends [never] ? Record<string, never> : {
|
|
417
|
+
[K in keyof TRead]: TRead[K] extends (...args: infer TArgs) => infer TReturn ? TArgs extends readonly unknown[] ? TRead[K] & {
|
|
418
|
+
use: {
|
|
419
|
+
(...args: NullableArgs<TArgs>): UseAsyncReadResult<Awaited<TReturn>>;
|
|
420
|
+
(...args: [
|
|
421
|
+
...RequiredNullableArgs<TArgs>,
|
|
422
|
+
ReadHookOptions<Awaited<TReturn>>
|
|
423
|
+
]): UseAsyncReadResult<Awaited<TReturn>>;
|
|
424
|
+
};
|
|
425
|
+
} : never : never;
|
|
426
|
+
};
|
|
427
|
+
/** @deprecated Use {@link ReactReadInterface}; `read` now includes both forms. */
|
|
428
|
+
type ReadHookInterface<TRead> = ReactReadInterface<TRead>;
|
|
429
|
+
type ReadHookOptions<T> = Pick<UseAsyncReadOptions<T>, 'initialData' | 'debounceMs'>;
|
|
130
430
|
|
|
131
431
|
interface ZustandState {
|
|
132
432
|
entities: Map<string, Map<string, unknown>>;
|
|
@@ -168,44 +468,194 @@ declare class ZustandAdapter implements StorageAdapter {
|
|
|
168
468
|
getViewConfig(viewPath: string): ViewSortConfig | undefined;
|
|
169
469
|
}
|
|
170
470
|
|
|
171
|
-
type
|
|
172
|
-
|
|
471
|
+
type ProgramMap$1 = Record<string, ProgramSdkDefinition>;
|
|
472
|
+
type ResolvedStack<TStack extends StackDefinition, TPrograms extends ProgramMap$1 | undefined> = StackWithAttachedPrograms<TStack, TPrograms>;
|
|
473
|
+
type StackQueries<TStack> = TStack extends {
|
|
474
|
+
queries?: infer TQueries extends Record<string, StackQueryDefinition<unknown, unknown>> | undefined;
|
|
475
|
+
} ? TQueries : undefined;
|
|
476
|
+
type StackPrograms<TStack> = TStack extends {
|
|
477
|
+
programs?: infer TPrograms extends Record<string, ProgramSdkDefinition> | undefined;
|
|
478
|
+
} ? TPrograms : undefined;
|
|
479
|
+
type ConnectedStack<TStack extends StackDefinition, TPrograms extends ProgramMap$1 | undefined> = ConnectedArete<ResolvedStack<TStack, TPrograms>>;
|
|
480
|
+
type ConnectedField<TClient, TKey extends PropertyKey> = TKey extends keyof TClient ? TClient[TKey] : undefined;
|
|
481
|
+
type ViewHookForDef<TDef> = TDef extends ViewDef<infer T, 'state', infer TKey> ? {
|
|
482
|
+
use: <TSchema = T>(key: TKey | null | undefined, options?: StateViewHookOptions<TSchema>) => ViewHookResult<TSchema>;
|
|
483
|
+
refresh: (key?: TKey | null) => Promise<void>;
|
|
173
484
|
} : TDef extends ViewDef<infer T, 'list'> ? {
|
|
174
485
|
use: {
|
|
175
|
-
<TSchema = T>(params: ListParamsSingle<TSchema>, options?:
|
|
176
|
-
<TSchema = T>(params?: ListParamsMultiple<TSchema>, options?:
|
|
486
|
+
<TSchema = T>(params: ListParamsSingle<TSchema>, options?: ListOneViewHookOptions<TSchema>): ViewHookResult<TSchema>;
|
|
487
|
+
<TSchema = T>(params?: ListParamsMultiple<TSchema>, options?: ListViewHookOptions<TSchema>): ViewHookResult<TSchema[]>;
|
|
177
488
|
};
|
|
178
|
-
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?:
|
|
179
|
-
|
|
489
|
+
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?: ListOneViewHookOptions<TSchema>) => ViewHookResult<TSchema>;
|
|
490
|
+
refresh: () => Promise<void>;
|
|
491
|
+
} : TDef extends ViewDef<infer T, 'state' | 'list', infer TKey> ? {
|
|
180
492
|
use: {
|
|
181
|
-
<TSchema = T>(params: ListParamsSingle<TSchema>, options?:
|
|
182
|
-
<TSchema = T>(params?: ListParamsMultiple<TSchema> |
|
|
493
|
+
<TSchema = T>(params: ListParamsSingle<TSchema>, options?: ListOneViewHookOptions<TSchema>): ViewHookResult<TSchema>;
|
|
494
|
+
<TSchema = T>(params?: ListParamsMultiple<TSchema> | TKey, options?: ListViewHookOptions<TSchema> | StateViewHookOptions<TSchema>): ViewHookResult<TSchema | TSchema[]>;
|
|
183
495
|
};
|
|
184
|
-
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?:
|
|
496
|
+
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?: ListOneViewHookOptions<TSchema>) => ViewHookResult<TSchema>;
|
|
497
|
+
refresh: (key?: TKey | null) => Promise<void>;
|
|
185
498
|
} : never;
|
|
186
499
|
type BuildViewInterface<TViews extends Record<string, ViewGroup>> = {
|
|
187
500
|
[K in keyof TViews]: {
|
|
188
|
-
[SubK in keyof TViews[K] as TViews[K][SubK] extends ViewDef<
|
|
501
|
+
[SubK in keyof TViews[K] as TViews[K][SubK] extends ViewDef<any, ViewMode, any> ? SubK : never]: ViewHookForDef<TViews[K][SubK]>;
|
|
189
502
|
};
|
|
190
503
|
};
|
|
191
|
-
type
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
type StackClient<TStack extends StackDefinition> = {
|
|
504
|
+
type UseAreteResult<TStack extends StackDefinition, TPrograms extends ProgramMap$1 | undefined = undefined> = {
|
|
505
|
+
/**
|
|
506
|
+
* Typed subscription hooks, one per stack view. Keyed hooks only ever
|
|
507
|
+
* expose data for the key you passed — when the key changes, `data` is
|
|
508
|
+
* `undefined` (and `isLoading` true) until the new key's snapshot arrives,
|
|
509
|
+
* so callers never need to re-verify data against their inputs.
|
|
510
|
+
*/
|
|
199
511
|
views: BuildViewInterface<TStack['views']>;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
512
|
+
queries: QueriesInterface<StackQueries<ResolvedStack<TStack, TPrograms>>>;
|
|
513
|
+
programs: BuildProgramInterface<StackPrograms<ResolvedStack<TStack, TPrograms>>, ConnectedStack<TStack, TPrograms>>;
|
|
514
|
+
chain: ChainClient | null;
|
|
515
|
+
zustandStore: UseBoundStore<StoreApi<AreteStore>> | null;
|
|
516
|
+
client: ConnectedStack<TStack, TPrograms> | null;
|
|
517
|
+
read: ReactReadInterface<NonNullable<ConnectedField<StackConnectedExtensions<ResolvedStack<TStack, TPrograms>>, 'read'>>>;
|
|
518
|
+
/** @deprecated Hooks and imperative reads now share the `read` namespace. */
|
|
519
|
+
reads: ReactReadInterface<NonNullable<ConnectedField<StackConnectedExtensions<ResolvedStack<TStack, TPrograms>>, 'read'>>>;
|
|
520
|
+
addresses: ConnectedField<StackConnectedExtensions<ResolvedStack<TStack, TPrograms>>, 'addresses'>;
|
|
521
|
+
constants: ConnectedField<StackConnectedExtensions<ResolvedStack<TStack, TPrograms>>, 'constants'>;
|
|
522
|
+
defaults: ConnectedField<StackConnectedExtensions<ResolvedStack<TStack, TPrograms>>, 'defaults'>;
|
|
523
|
+
math: ConnectedField<StackConnectedExtensions<ResolvedStack<TStack, TPrograms>>, 'math'>;
|
|
524
|
+
/**
|
|
525
|
+
* Raw connection state reported by the client. Prefer {@link status},
|
|
526
|
+
* which also covers the initial client-creation window.
|
|
527
|
+
*/
|
|
203
528
|
connectionState: ConnectionState;
|
|
529
|
+
/**
|
|
530
|
+
* The single connection field UIs should read: 'connecting' while the
|
|
531
|
+
* client is being created or connecting, then the client's own state.
|
|
532
|
+
*/
|
|
533
|
+
status: ConnectionState;
|
|
204
534
|
isConnected: boolean;
|
|
205
535
|
isLoading: boolean;
|
|
536
|
+
/** True when retry() can start a new shared connection attempt. */
|
|
537
|
+
canRetry: boolean;
|
|
206
538
|
error: Error | null;
|
|
539
|
+
socketIssue: SocketIssue | null;
|
|
540
|
+
retry: () => Promise<void>;
|
|
541
|
+
};
|
|
542
|
+
/**
|
|
543
|
+
* Module-augmentation point for the default stack's type. When the provider
|
|
544
|
+
* declares a default stack (`<AreteProvider stack={...}>`), register its type
|
|
545
|
+
* once so argument-less `useArete()` calls are fully typed:
|
|
546
|
+
*
|
|
547
|
+
* ```ts
|
|
548
|
+
* declare module '@usearete/react' {
|
|
549
|
+
* interface AreteDefaultStackRegistry { defaultStack: OreStreamStack }
|
|
550
|
+
* }
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
interface AreteDefaultStackRegistry {
|
|
554
|
+
}
|
|
555
|
+
type RegisteredDefaultStack = AreteDefaultStackRegistry extends {
|
|
556
|
+
defaultStack: infer TStack extends StackDefinition;
|
|
557
|
+
} ? TStack : StackDefinition;
|
|
558
|
+
declare function useArete(stack?: undefined, options?: UseAreteOptions): UseAreteResult<RegisteredDefaultStack, undefined>;
|
|
559
|
+
declare function useArete<TStack extends StackDefinition, TPrograms extends ProgramMap$1 | undefined = undefined>(stack: TStack, options?: UseAreteOptions<TPrograms>): UseAreteResult<TStack, TPrograms>;
|
|
560
|
+
|
|
561
|
+
type ProgramMap = Record<string, ProgramSdkDefinition>;
|
|
562
|
+
type BoundAreteProviderProps = Omit<AreteConfig, 'stack'> & {
|
|
563
|
+
children: ReactNode;
|
|
207
564
|
};
|
|
208
|
-
|
|
565
|
+
/**
|
|
566
|
+
* Bind the React SDK to one generated stack without ambient module
|
|
567
|
+
* augmentation. The returned hook remains explicit through an app-specific
|
|
568
|
+
* name such as `useOre`, while the generic provider and hook remain available
|
|
569
|
+
* for multi-stack applications.
|
|
570
|
+
*/
|
|
571
|
+
declare function createAreteReact<TStack extends StackDefinition>(stack: TStack): {
|
|
572
|
+
readonly Provider: ({ children, ...config }: BoundAreteProviderProps) => React.JSX.Element;
|
|
573
|
+
readonly useArete: <TPrograms extends ProgramMap | undefined = undefined>(options?: UseAreteOptions<TPrograms>) => UseAreteResult<TStack, TPrograms>;
|
|
574
|
+
readonly stack: TStack;
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Minimal shape of a named status source: any view hook result, read hook
|
|
579
|
+
* result, or compatible object. Use `false`/`null`/`undefined` to exclude a
|
|
580
|
+
* source conditionally, e.g. `Miner: authority && miner`.
|
|
581
|
+
*/
|
|
582
|
+
type ViewStatusSource = {
|
|
583
|
+
isLoading: boolean;
|
|
584
|
+
isRefreshing?: boolean;
|
|
585
|
+
error?: Error | null;
|
|
586
|
+
} | false | null | undefined;
|
|
587
|
+
interface SummarizedViewStatus {
|
|
588
|
+
/** True while any included source is still loading. */
|
|
589
|
+
isLoading: boolean;
|
|
590
|
+
/** True when any included source has an error. */
|
|
591
|
+
hasError: boolean;
|
|
592
|
+
/** True while any included source is refreshing committed data. */
|
|
593
|
+
isRefreshing: boolean;
|
|
594
|
+
/** Names of sources still loading, in declaration order. */
|
|
595
|
+
loading: string[];
|
|
596
|
+
/** `"Name: message"` for each source error, in declaration order. */
|
|
597
|
+
errors: string[];
|
|
598
|
+
/** Names of sources refreshing committed data, in declaration order. */
|
|
599
|
+
refreshing: string[];
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Aggregate the status of connection, view, and read hook results into loading,
|
|
603
|
+
* refreshing, and error lists. Pure function; call it during render.
|
|
604
|
+
*
|
|
605
|
+
* ```tsx
|
|
606
|
+
* const streams = summarizeStatuses({ Board: board, Round: round, Miner: authority && miner });
|
|
607
|
+
* {streams.loading.length > 0 && <p>Loading: {streams.loading.join(', ')}</p>}
|
|
608
|
+
* {streams.errors.length > 0 && <p role="alert">{streams.errors.join(' · ')}</p>}
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
declare function summarizeStatuses(sources: Record<string, ViewStatusSource>): SummarizedViewStatus;
|
|
612
|
+
/** @deprecated Use summarizeStatuses; it also accepts connection and read results. */
|
|
613
|
+
declare const summarizeViews: typeof summarizeStatuses;
|
|
614
|
+
type StatusSource = ViewStatusSource;
|
|
615
|
+
type SummarizedStatus = SummarizedViewStatus;
|
|
616
|
+
|
|
617
|
+
interface BalanceHookOptions<T> extends ContextSlotOptions, UseAsyncReadOptions<T> {
|
|
618
|
+
}
|
|
619
|
+
declare function useNativeBalance(chain: ChainClient | null | undefined, address: string | null | undefined, options?: BalanceHookOptions<NativeBalanceInfo>): UseAsyncReadResult<NativeBalanceInfo>;
|
|
620
|
+
declare function useTokenBalance(chain: ChainClient | null | undefined, input: TokenBalanceInput | null | undefined, options?: BalanceHookOptions<TokenBalanceInfo>): UseAsyncReadResult<TokenBalanceInfo>;
|
|
621
|
+
|
|
622
|
+
declare const DEFAULT_RECONCILIATION_TIMEOUT_MS = 30000;
|
|
623
|
+
interface ProcessedSlotClient {
|
|
624
|
+
waitForProcessedSlot(slot: number | bigint, options?: WaitForProcessedSlotOptions): Promise<bigint>;
|
|
625
|
+
}
|
|
626
|
+
type ReconciliationRefresh = ReconciliationRefreshTarget;
|
|
627
|
+
interface ProcessedSlotReconciliationOptions extends WaitForProcessedSlotOptions {
|
|
628
|
+
refresh?: ReconciliationRefresh | readonly ReconciliationRefresh[];
|
|
629
|
+
}
|
|
630
|
+
type ProcessedSlotReconciliationResult = {
|
|
631
|
+
readonly status: 'reconciled';
|
|
632
|
+
readonly confirmedSlot: bigint;
|
|
633
|
+
readonly processedSlot: bigint;
|
|
634
|
+
} | {
|
|
635
|
+
readonly status: 'confirmed-unreconciled';
|
|
636
|
+
readonly confirmedSlot: bigint;
|
|
637
|
+
readonly error: Error;
|
|
638
|
+
};
|
|
639
|
+
declare function reconcileProcessedSlot(client: ProcessedSlotClient | null | undefined, slot: number | bigint, options?: ProcessedSlotReconciliationOptions): Promise<ProcessedSlotReconciliationResult>;
|
|
640
|
+
declare function useReconcileProcessedSlot(client: ProcessedSlotClient | null | undefined): (slot: number | bigint, options?: ProcessedSlotReconciliationOptions) => Promise<ProcessedSlotReconciliationResult>;
|
|
641
|
+
/**
|
|
642
|
+
* The default reconciliation injected into generated program mutation hooks.
|
|
643
|
+
* Marked so `useInstructionMutation` can resolve `reconcile: { ... }` override
|
|
644
|
+
* objects against it via {@link DefaultReconciliationFn.withOverrides}.
|
|
645
|
+
*/
|
|
646
|
+
interface DefaultReconciliationFn {
|
|
647
|
+
(context: MutationReconciliationContext<unknown, PreparedOperation>): Promise<ProcessedSlotReconciliationResult | undefined>;
|
|
648
|
+
readonly areteDefaultReconciliation: true;
|
|
649
|
+
readonly shouldReconcile: (context: MutationReconciliationContext<unknown, PreparedOperation>) => boolean;
|
|
650
|
+
readonly withOverrides: (overrides: MutationReconcileOverrides) => DefaultReconciliationFn;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Build the default reconciliation for generated program hooks: wait until the
|
|
654
|
+
* stream has processed the highest slot among completed transactions, then run
|
|
655
|
+
* any requested refreshes. Mutations without a reported slot (e.g. raw
|
|
656
|
+
* instruction sends) skip reconciliation silently.
|
|
657
|
+
*/
|
|
658
|
+
declare function createProcessedSlotReconciliation(client: ProcessedSlotClient | null | undefined, baseOverrides?: MutationReconcileOverrides): DefaultReconciliationFn;
|
|
209
659
|
|
|
210
|
-
export { AreteProvider, ZustandAdapter, useArete, useAreteContext,
|
|
211
|
-
export type { AreteConfig, AreteStore, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, MutationStatus, StateViewHook, TransactionDefinition, UseAreteOptions, UseMutationOptions, UseMutationResult, UseMutationReturn, ViewHookOptions, ViewHookResult, ViewMode };
|
|
660
|
+
export { AreteProvider, DEFAULT_RECONCILIATION_TIMEOUT_MS, ZustandAdapter, createAreteReact, createProcessedSlotReconciliation, reconcileProcessedSlot, summarizeStatuses, summarizeViews, useArete, useAreteContext, useAsyncRead, useConnectionState, useInstructionMutation, useNativeBalance, useReconcileProcessedSlot, useTokenBalance };
|
|
661
|
+
export type { AreteConfig, AreteDefaultStackRegistry, AreteStore, AsyncReadContext, AsyncReadKey, AsyncReadStatus, BalanceHookOptions, BoundAreteProviderProps, ClientLookupOptions, DefaultReconciliationFn, ListOneViewHookOptions, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, ListViewHookOptions, MutationExecutionObserver, MutationExecutor, MutationLifecycleEvent, MutationPhase, MutationReconcileFn, MutationReconcileOverrides, MutationReconciliationContext, MutationStatus, ProcessedSlotClient, ProcessedSlotReconciliationOptions, ProcessedSlotReconciliationResult, ReactReadInterface, ReadHookInterface, ReadHookOptions, ReconciliationRefresh, ReconciliationRefreshTarget, StateViewHook, StateViewHookOptions, StatusSource, SummarizedStatus, SummarizedViewStatus, TransactionDefinition, UseAreteOptions, UseAreteResult, UseAsyncReadOptions, UseAsyncReadResult, UseMutationOptions, UseMutationResult, UseMutationReturn, ViewHookOptions, ViewHookResult, ViewMode, ViewSchemaValidationDiagnostic, ViewSchemaValidationErrorCallback, ViewStatus, ViewStatusSource };
|