@usearete/react 0.1.4 → 0.2.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 +119 -65
- package/dist/index.d.ts +93 -32
- package/dist/index.esm.js +2210 -280
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2214 -280
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,108 +1,162 @@
|
|
|
1
1
|
# Arete React SDK
|
|
2
2
|
|
|
3
|
-
React
|
|
3
|
+
React hooks and provider for consuming Arete stacks in React applications.
|
|
4
4
|
|
|
5
|
-
Built on top of [`@usearete/sdk`](https://www.npmjs.com/package/@usearete/sdk), the
|
|
5
|
+
Built on top of [`@usearete/sdk`](https://www.npmjs.com/package/@usearete/sdk), the framework-agnostic TypeScript core SDK.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @usearete/react
|
|
10
|
+
npm install @usearete/react react zustand
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
>
|
|
13
|
+
> Not using React? Use [`@usearete/sdk`](../core/README.md) directly.
|
|
14
14
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
### Basic Setup
|
|
15
|
+
## Quick Start
|
|
18
16
|
|
|
19
17
|
```tsx
|
|
20
|
-
import { AreteProvider, useArete
|
|
18
|
+
import { AreteProvider, useArete } from '@usearete/react';
|
|
19
|
+
import { ORE_STREAM_STACK } from './generated/ore-stack';
|
|
20
|
+
|
|
21
|
+
function Dashboard() {
|
|
22
|
+
const { views, isLoading, error } = useArete(ORE_STREAM_STACK, {
|
|
23
|
+
url: 'ws://localhost:8877',
|
|
24
|
+
httpUrl: 'http://localhost:8877',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const { data: latestRound } = views.OreRound.latest.useOne();
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
29
|
+
if (isLoading) {
|
|
30
|
+
return <div>Connecting...</div>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (error) {
|
|
34
|
+
return <div>{error.message}</div>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return <pre>{JSON.stringify(latestRound, null, 2)}</pre>;
|
|
38
|
+
}
|
|
25
39
|
|
|
26
|
-
function App() {
|
|
40
|
+
export default function App() {
|
|
27
41
|
return (
|
|
28
|
-
<AreteProvider
|
|
29
|
-
|
|
42
|
+
<AreteProvider
|
|
43
|
+
autoConnect={true}
|
|
44
|
+
auth={{
|
|
45
|
+
// publishableKey: 'hspk_...',
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
<Dashboard />
|
|
30
49
|
</AreteProvider>
|
|
31
50
|
);
|
|
32
51
|
}
|
|
33
|
-
|
|
34
|
-
function MyComponent() {
|
|
35
|
-
const stack = useArete(myStack);
|
|
36
|
-
// Use your stack
|
|
37
|
-
}
|
|
38
52
|
```
|
|
39
53
|
|
|
40
|
-
|
|
54
|
+
## Provider
|
|
41
55
|
|
|
42
|
-
|
|
43
|
-
- **React Integration**: Hooks-based API for easy integration with React applications
|
|
44
|
-
- **State Management**: Built-in state management with Zustand
|
|
45
|
-
- **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
46
|
-
- **View Definitions**: Create state and list views for your data
|
|
47
|
-
- **Transaction Handling**: Define and execute transactions with hooks
|
|
48
|
-
- **Single Item Queries**: Type-safe single item fetching with `take: 1` or `useOne()`
|
|
56
|
+
`AreteProvider` manages connected clients for descendant hooks.
|
|
49
57
|
|
|
50
|
-
|
|
58
|
+
Supported props:
|
|
51
59
|
|
|
52
|
-
|
|
60
|
+
- `autoConnect`
|
|
61
|
+
- `wallet`
|
|
62
|
+
- `auth`
|
|
63
|
+
- `fetch`
|
|
64
|
+
- `validateFrames`
|
|
65
|
+
- `reconnectIntervals`
|
|
66
|
+
- `maxReconnectAttempts`
|
|
67
|
+
- `maxEntriesPerView`
|
|
68
|
+
- `flushIntervalMs`
|
|
53
69
|
|
|
54
|
-
|
|
70
|
+
These are provider-wide defaults. Endpoint overrides stay on the hook call.
|
|
55
71
|
|
|
56
|
-
|
|
72
|
+
## `useArete(stack, options?)`
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
- `useAreteContext` - Access the runtime context directly
|
|
74
|
+
`useArete` returns the connected React surface for a stack:
|
|
60
75
|
|
|
61
|
-
|
|
76
|
+
- `views`
|
|
77
|
+
- `programs`
|
|
78
|
+
- `queries`
|
|
79
|
+
- `chain`
|
|
80
|
+
- `client`
|
|
81
|
+
- `connectionState`
|
|
82
|
+
- `isConnected`
|
|
83
|
+
- `isLoading`
|
|
84
|
+
- `error`
|
|
62
85
|
|
|
63
|
-
|
|
64
|
-
- `.use({ take: 1 })` - Subscribe to single item with type narrowing (returns `T | undefined`)
|
|
65
|
-
- `.useOne()` - Convenience method for single item queries (returns `T | undefined`)
|
|
86
|
+
Supported hook options:
|
|
66
87
|
|
|
67
|
-
|
|
88
|
+
- `url`
|
|
89
|
+
- `httpUrl`
|
|
90
|
+
- `transport`
|
|
91
|
+
- `programs`
|
|
68
92
|
|
|
69
|
-
|
|
70
|
-
- `createStateView` - Create a state view
|
|
71
|
-
- `createListView` - Create a list view
|
|
72
|
-
- `createRuntime` - Create a runtime instance
|
|
93
|
+
Notes:
|
|
73
94
|
|
|
74
|
-
|
|
95
|
+
- `transport: 'http'` disables streaming view subscriptions, but HTTP-backed surfaces like `queries`, `chain`, and program reads still work.
|
|
96
|
+
- If you pass attached `programs`, keep that object stable with a module constant or `useMemo` so React does not create a fresh client on every render.
|
|
75
97
|
|
|
76
|
-
|
|
98
|
+
## Views
|
|
77
99
|
|
|
78
|
-
|
|
100
|
+
View hooks return a `ViewHookResult<T>` object:
|
|
79
101
|
|
|
80
|
-
|
|
102
|
+
```ts
|
|
103
|
+
type ViewHookResult<T> = {
|
|
104
|
+
data: T | undefined;
|
|
105
|
+
isLoading: boolean;
|
|
106
|
+
error?: Error;
|
|
107
|
+
refresh: () => void;
|
|
108
|
+
};
|
|
109
|
+
```
|
|
81
110
|
|
|
82
|
-
|
|
83
|
-
- `ConnectionManager` - WebSocket connection handling
|
|
84
|
-
- `EntityStore` - State management
|
|
85
|
-
- AsyncIterable-based streaming APIs
|
|
111
|
+
List views support:
|
|
86
112
|
|
|
87
|
-
|
|
113
|
+
- `.use()`
|
|
114
|
+
- `.use({ take: 1 })`
|
|
115
|
+
- `.useOne()`
|
|
88
116
|
|
|
89
|
-
|
|
90
|
-
- `useArete` - Main hook for accessing stacks
|
|
91
|
-
- `useConnectionState` - Connection monitoring hook
|
|
92
|
-
- `defineStack`, `createStateView`, `createListView` - React-friendly factories
|
|
117
|
+
State views support:
|
|
93
118
|
|
|
94
|
-
|
|
119
|
+
- `.use(key)`
|
|
95
120
|
|
|
96
|
-
|
|
97
|
-
import { Arete, ConnectionManager } from '@usearete/react';
|
|
98
|
-
// or
|
|
99
|
-
import { Arete, ConnectionManager } from '@usearete/sdk';
|
|
100
|
-
```
|
|
121
|
+
## Programs, Queries, and Chain
|
|
101
122
|
|
|
102
|
-
|
|
123
|
+
`useArete` mirrors the connected core client surface:
|
|
103
124
|
|
|
104
|
-
|
|
125
|
+
- `programs.<program>.raw.<instruction>` for raw typed instructions
|
|
126
|
+
- `programs.<program>.plan` / `programs.<program>.instructions` for semantic instructions
|
|
127
|
+
- `programs.<program>.accounts` and `programs.<program>.queries` for HTTP reads
|
|
128
|
+
- `queries` for stack-level HTTP queries
|
|
129
|
+
- `chain` for chain helpers
|
|
105
130
|
|
|
106
|
-
|
|
131
|
+
Raw instruction hooks preserve `.execute`, `.build`, and `.useMutation()`.
|
|
107
132
|
|
|
108
|
-
|
|
133
|
+
Semantic instruction hooks preserve:
|
|
134
|
+
|
|
135
|
+
- `.execute`
|
|
136
|
+
- `.send`
|
|
137
|
+
- `.resolve`
|
|
138
|
+
- `.plan`
|
|
139
|
+
- `.build`
|
|
140
|
+
- `.stage`
|
|
141
|
+
- `.useMutation()`
|
|
142
|
+
|
|
143
|
+
## Low-Level Hooks
|
|
144
|
+
|
|
145
|
+
The React SDK also exports:
|
|
146
|
+
|
|
147
|
+
- `useConnectionState`
|
|
148
|
+
- `useView`
|
|
149
|
+
- `useEntity`
|
|
150
|
+
- `useAreteContext`
|
|
151
|
+
|
|
152
|
+
These accept the same client lookup overrides when you need to target a non-default client.
|
|
153
|
+
|
|
154
|
+
## Relationship with `@usearete/sdk`
|
|
155
|
+
|
|
156
|
+
`@usearete/react` re-exports selected core APIs and types for convenience, but it is not a complete mirror of the core package.
|
|
157
|
+
|
|
158
|
+
If you need the full low-level surface, import directly from `@usearete/sdk`.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT
|
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 { WalletAdapter, ConnectOptions, AuthConfig, Schema, ProgramSdkDefinition, StackDefinition, ConnectionState, ConnectedArete, StackWithAttachedPrograms, ProgramInterface, TypedInstruction, PreparedOperation, OperationReceiptFor, StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ViewSortConfig, QueriesInterface, ChainClient, StackQueryDefinition, ViewGroup, ViewDef } from '@usearete/sdk';
|
|
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';
|
|
5
4
|
import { UseBoundStore, StoreApi } from 'zustand';
|
|
6
5
|
|
|
7
6
|
type ViewMode = 'state' | 'list';
|
|
@@ -15,12 +14,13 @@ interface TransactionDefinition<TParams = unknown> {
|
|
|
15
14
|
key?: string | ((params: TParams) => string);
|
|
16
15
|
}>;
|
|
17
16
|
}
|
|
17
|
+
type ProgramMap$2 = Record<string, ProgramSdkDefinition>;
|
|
18
18
|
/**
|
|
19
19
|
* Global configuration for AreteProvider.
|
|
20
20
|
*
|
|
21
21
|
* Note: WebSocket URL is no longer configured here. The URL is:
|
|
22
|
-
* 1. Embedded in the stack definition (stack.
|
|
23
|
-
* 2. Optionally overridden per-hook via useArete(stack, { url
|
|
22
|
+
* 1. Embedded in the stack definition (`stack.endpoints.ws` / `stack.endpoints.http`)
|
|
23
|
+
* 2. Optionally overridden per-hook via `useArete(stack, { url, httpUrl })`
|
|
24
24
|
*/
|
|
25
25
|
interface AreteConfig {
|
|
26
26
|
autoConnect?: boolean;
|
|
@@ -29,16 +29,25 @@ interface AreteConfig {
|
|
|
29
29
|
maxReconnectAttempts?: number;
|
|
30
30
|
maxEntriesPerView?: number | null;
|
|
31
31
|
flushIntervalMs?: number;
|
|
32
|
+
fetch?: ConnectOptions['fetch'];
|
|
33
|
+
validateFrames?: boolean;
|
|
32
34
|
/** Authentication configuration */
|
|
33
|
-
auth?:
|
|
35
|
+
auth?: AuthConfig;
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
|
-
*
|
|
38
|
+
* Client lookup/connect options for React hooks.
|
|
37
39
|
*/
|
|
38
|
-
interface
|
|
39
|
-
/** Override the stack's embedded URL (useful for local development) */
|
|
40
|
+
interface ClientLookupOptions<TPrograms extends ProgramMap$2 | undefined = undefined> {
|
|
41
|
+
/** Override the stack's embedded WebSocket URL (useful for local development) */
|
|
40
42
|
url?: string;
|
|
43
|
+
/** Override the stack's embedded HTTP read URL (useful for local development) */
|
|
44
|
+
httpUrl?: string;
|
|
45
|
+
/** Override the stack transport. HTTP mode disables streaming view subscriptions. */
|
|
46
|
+
transport?: ConnectOptions<TPrograms>['transport'];
|
|
47
|
+
/** Attach additional program SDKs to the connected client. */
|
|
48
|
+
programs?: TPrograms;
|
|
41
49
|
}
|
|
50
|
+
type UseAreteOptions<TPrograms extends ProgramMap$2 | undefined = undefined> = ClientLookupOptions<TPrograms>;
|
|
42
51
|
interface ViewHookOptions<TSchema = unknown> {
|
|
43
52
|
enabled?: boolean;
|
|
44
53
|
initialData?: unknown;
|
|
@@ -98,9 +107,11 @@ interface ListViewHook<T> {
|
|
|
98
107
|
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?: ViewHookOptions) => ViewHookResult<TSchema | undefined>;
|
|
99
108
|
}
|
|
100
109
|
|
|
110
|
+
type ProgramMap$1 = Record<string, ProgramSdkDefinition>;
|
|
111
|
+
type ResolvedStack$1<TStack extends StackDefinition, TPrograms extends ProgramMap$1 | undefined> = StackWithAttachedPrograms<TStack, TPrograms>;
|
|
101
112
|
interface AreteContextValue {
|
|
102
|
-
getOrCreateClient: <TStack extends StackDefinition>(stack: TStack,
|
|
103
|
-
getClient: <TStack extends StackDefinition>(stack: TStack | undefined) =>
|
|
113
|
+
getOrCreateClient: <TStack extends StackDefinition, TPrograms extends ProgramMap$1 | undefined = undefined>(stack: TStack, options?: ClientLookupOptions<TPrograms>) => Promise<ConnectedArete<ResolvedStack$1<TStack, TPrograms>>>;
|
|
114
|
+
getClient: <TStack extends StackDefinition, TPrograms extends ProgramMap$1 | undefined = undefined>(stack: TStack | undefined, options?: ClientLookupOptions<TPrograms>) => ConnectedArete<ResolvedStack$1<TStack, TPrograms>> | null;
|
|
104
115
|
subscribeToClientChanges: (callback: () => void) => () => void;
|
|
105
116
|
config: AreteConfig;
|
|
106
117
|
}
|
|
@@ -109,24 +120,71 @@ declare function AreteProvider({ children, fallback, ...config }: AreteConfig &
|
|
|
109
120
|
fallback?: ReactNode;
|
|
110
121
|
}): React.JSX.Element;
|
|
111
122
|
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;
|
|
123
|
+
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;
|
|
115
126
|
|
|
116
127
|
type MutationStatus = 'idle' | 'pending' | 'success' | 'error';
|
|
117
|
-
|
|
118
|
-
onSuccess?: (result:
|
|
128
|
+
type UseMutationOptions<TOptions extends object = Record<string, never>, TResult = unknown> = TOptions & {
|
|
129
|
+
onSuccess?: (result: TResult) => void;
|
|
119
130
|
onError?: (error: Error) => void;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Result of {@link useInstructionMutation}.
|
|
134
|
+
*
|
|
135
|
+
* `TParams` is the merged params object accepted by the instruction (IDL args
|
|
136
|
+
* plus any user-provided account addresses), inferred from the generated
|
|
137
|
+
* handler. `TError` is the handler's typed program-error union.
|
|
138
|
+
*/
|
|
139
|
+
interface UseMutationResult<TParams = Record<string, unknown>, TResult = unknown, TOptions extends object = Record<string, never>> {
|
|
140
|
+
submit: (args: TParams, options?: Partial<UseMutationOptions<TOptions, TResult>>) => Promise<TResult>;
|
|
123
141
|
status: MutationStatus;
|
|
124
142
|
error: string | null;
|
|
143
|
+
signatures: string[];
|
|
125
144
|
signature: string | null;
|
|
126
145
|
isLoading: boolean;
|
|
127
146
|
reset: () => void;
|
|
128
147
|
}
|
|
129
|
-
|
|
148
|
+
type MutationExecutor<TParams = Record<string, unknown>, TResult = unknown, TOptions extends object = Record<string, never>> = {
|
|
149
|
+
(args: TParams, options?: TOptions): Promise<TResult>;
|
|
150
|
+
};
|
|
151
|
+
declare function useInstructionMutation<TParams = Record<string, unknown>, TResult = unknown, TOptions extends object = Record<string, never>>(execute: MutationExecutor<TParams, TResult, TOptions>): UseMutationResult<TParams, TResult, TOptions>;
|
|
152
|
+
|
|
153
|
+
type OperationOptionsArg<TClient> = TClient extends {
|
|
154
|
+
execute(prepared: PreparedOperation, options?: infer TOptions): Promise<unknown>;
|
|
155
|
+
} ? NonNullable<TOptions> : Record<string, never>;
|
|
156
|
+
type RawOptionsArg<TClient> = TClient extends {
|
|
157
|
+
transaction(instructions: readonly unknown[], options?: infer TOptions): Promise<unknown>;
|
|
158
|
+
} ? NonNullable<TOptions> : Record<string, never>;
|
|
159
|
+
type ConnectedOperationLike = {
|
|
160
|
+
prepare(input: unknown): Promise<PreparedOperation>;
|
|
161
|
+
};
|
|
162
|
+
type RawInstructionHookFor<THandler, TClient> = THandler extends TypedInstruction<infer P, infer E> ? {
|
|
163
|
+
useMutation: () => UseMutationResult<P, E, RawOptionsArg<TClient>>;
|
|
164
|
+
execute: (input: P, options?: RawOptionsArg<TClient>) => Promise<E>;
|
|
165
|
+
build: THandler['build'];
|
|
166
|
+
} : never;
|
|
167
|
+
type OperationHookFor<TOperation, TClient> = TOperation extends {
|
|
168
|
+
prepare(input: infer P): Promise<infer TPrepared extends PreparedOperation>;
|
|
169
|
+
} ? {
|
|
170
|
+
useMutation: () => UseMutationResult<P, OperationReceiptFor<TPrepared>, OperationOptionsArg<TClient>>;
|
|
171
|
+
execute: (input: P, options?: OperationOptionsArg<TClient>) => Promise<OperationReceiptFor<TPrepared>>;
|
|
172
|
+
prepare: TOperation['prepare'];
|
|
173
|
+
} : never;
|
|
174
|
+
type OperationHookNamespace<TNamespace, TClient> = {
|
|
175
|
+
[K in keyof TNamespace]: TNamespace[K] extends ConnectedOperationLike ? OperationHookFor<TNamespace[K], TClient> : TNamespace[K] extends Record<string, unknown> ? OperationHookNamespace<TNamespace[K], TClient> : never;
|
|
176
|
+
};
|
|
177
|
+
type ProgramHookInterface<TProgram extends ProgramSdkDefinition, TClient> = Omit<ProgramInterface<TProgram>, 'raw' | 'instructions' | 'transactions' | 'flows'> & {
|
|
178
|
+
raw: {
|
|
179
|
+
[K in keyof ProgramInterface<TProgram>['raw']]: RawInstructionHookFor<ProgramInterface<TProgram>['raw'][K], TClient>;
|
|
180
|
+
};
|
|
181
|
+
instructions: OperationHookNamespace<ProgramInterface<TProgram>['instructions'], TClient>;
|
|
182
|
+
transactions: OperationHookNamespace<ProgramInterface<TProgram>['transactions'], TClient>;
|
|
183
|
+
flows: OperationHookNamespace<ProgramInterface<TProgram>['flows'], TClient>;
|
|
184
|
+
};
|
|
185
|
+
type BuildProgramInterface<TPrograms extends Record<string, ProgramSdkDefinition> | undefined, TClient> = TPrograms extends Record<string, ProgramSdkDefinition> ? {
|
|
186
|
+
[K in keyof TPrograms]: ProgramHookInterface<TPrograms[K], TClient>;
|
|
187
|
+
} : Record<string, never>;
|
|
130
188
|
|
|
131
189
|
interface ZustandState {
|
|
132
190
|
entities: Map<string, Map<string, unknown>>;
|
|
@@ -168,6 +226,14 @@ declare class ZustandAdapter implements StorageAdapter {
|
|
|
168
226
|
getViewConfig(viewPath: string): ViewSortConfig | undefined;
|
|
169
227
|
}
|
|
170
228
|
|
|
229
|
+
type ProgramMap = Record<string, ProgramSdkDefinition>;
|
|
230
|
+
type ResolvedStack<TStack extends StackDefinition, TPrograms extends ProgramMap | undefined> = StackWithAttachedPrograms<TStack, TPrograms>;
|
|
231
|
+
type StackQueries<TStack> = TStack extends {
|
|
232
|
+
queries?: infer TQueries extends Record<string, StackQueryDefinition<unknown, unknown>> | undefined;
|
|
233
|
+
} ? TQueries : undefined;
|
|
234
|
+
type StackPrograms<TStack> = TStack extends {
|
|
235
|
+
programs?: infer TPrograms extends Record<string, ProgramSdkDefinition> | undefined;
|
|
236
|
+
} ? TPrograms : undefined;
|
|
171
237
|
type ViewHookForDef<TDef> = TDef extends ViewDef<infer T, 'state'> ? {
|
|
172
238
|
use: <TSchema = T>(key?: Record<string, string>, options?: ViewHookOptions<TSchema>) => ViewHookResult<TSchema>;
|
|
173
239
|
} : TDef extends ViewDef<infer T, 'list'> ? {
|
|
@@ -188,24 +254,19 @@ type BuildViewInterface<TViews extends Record<string, ViewGroup>> = {
|
|
|
188
254
|
[SubK in keyof TViews[K] as TViews[K][SubK] extends ViewDef<unknown, ViewMode> ? SubK : never]: ViewHookForDef<TViews[K][SubK]>;
|
|
189
255
|
};
|
|
190
256
|
};
|
|
191
|
-
type
|
|
192
|
-
useMutation: () => UseMutationResult;
|
|
193
|
-
execute: InstructionExecutor;
|
|
194
|
-
};
|
|
195
|
-
type BuildInstructionInterface<TInstructions extends Record<string, InstructionHandler> | undefined> = TInstructions extends Record<string, InstructionHandler> ? {
|
|
196
|
-
[K in keyof TInstructions]: InstructionHook;
|
|
197
|
-
} : {};
|
|
198
|
-
type StackClient<TStack extends StackDefinition> = {
|
|
257
|
+
type StackClient<TStack extends StackDefinition, TPrograms extends ProgramMap | undefined> = {
|
|
199
258
|
views: BuildViewInterface<TStack['views']>;
|
|
200
|
-
|
|
259
|
+
queries: QueriesInterface<StackQueries<ResolvedStack<TStack, TPrograms>>>;
|
|
260
|
+
programs: BuildProgramInterface<StackPrograms<ResolvedStack<TStack, TPrograms>>, ConnectedArete<ResolvedStack<TStack, TPrograms>>>;
|
|
261
|
+
chain: ChainClient;
|
|
201
262
|
zustandStore: UseBoundStore<StoreApi<AreteStore>>;
|
|
202
|
-
client:
|
|
263
|
+
client: ConnectedArete<ResolvedStack<TStack, TPrograms>>;
|
|
203
264
|
connectionState: ConnectionState;
|
|
204
265
|
isConnected: boolean;
|
|
205
266
|
isLoading: boolean;
|
|
206
267
|
error: Error | null;
|
|
207
268
|
};
|
|
208
|
-
declare function useArete<TStack extends StackDefinition>(stack: TStack, options?: UseAreteOptions): StackClient<TStack>;
|
|
269
|
+
declare function useArete<TStack extends StackDefinition, TPrograms extends ProgramMap | undefined = undefined>(stack: TStack, options?: UseAreteOptions<TPrograms>): StackClient<TStack, TPrograms>;
|
|
209
270
|
|
|
210
271
|
export { AreteProvider, ZustandAdapter, useArete, useAreteContext, useConnectionState, useEntity, useInstructionMutation, useView };
|
|
211
|
-
export type { AreteConfig, AreteStore, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, MutationStatus, StateViewHook, TransactionDefinition, UseAreteOptions, UseMutationOptions, UseMutationResult, UseMutationReturn, ViewHookOptions, ViewHookResult, ViewMode };
|
|
272
|
+
export type { AreteConfig, AreteStore, ClientLookupOptions, ListParams, ListParamsBase, ListParamsMultiple, ListParamsSingle, ListViewHook, MutationStatus, StateViewHook, TransactionDefinition, UseAreteOptions, UseMutationOptions, UseMutationResult, UseMutationReturn, ViewHookOptions, ViewHookResult, ViewMode };
|