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