hyperstack-react 0.4.2 → 0.5.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/dist/index.d.ts +24 -17
- package/dist/index.esm.js +492 -117
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +492 -117
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { WalletAdapter, StackDefinition, ConnectionState, HyperStack, InstructionExecutorOptions, ExecutionResult, InstructionExecutor, StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ViewSortConfig, ViewGroup, ViewDef, InstructionHandler } from 'hyperstack-typescript';
|
|
3
|
-
export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, ArgSchema, ArgType, BuiltInstruction, ConfirmationLevel, ConnectionManager, ConnectionState, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, EntityFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, HyperStack, HyperStackConfig, HyperStackError, HyperStackOptions, HyperStackOptionsWithStorage, InstructionDefinition, InstructionExecutor, InstructionExecutorOptions, InstructionHandler, MemoryAdapter, PdaConfig, PdaSeed, ProgramError, ResolvedAccount, ResolvedAccounts, RichUpdate, RichUpdateCallback, 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 'hyperstack-typescript';
|
|
2
|
+
import { WalletAdapter, Schema, StackDefinition, ConnectionState, HyperStack, InstructionExecutorOptions, ExecutionResult, InstructionExecutor, StorageAdapter, StorageAdapterConfig, UpdateCallback, RichUpdateCallback, Update, RichUpdate, ViewSortConfig, ViewGroup, ViewDef, InstructionHandler } from 'hyperstack-typescript';
|
|
3
|
+
export { AccountCategory, AccountMeta, AccountResolutionOptions, AccountResolutionResult, ArgSchema, ArgType, BuiltInstruction, ConfirmationLevel, ConnectionManager, ConnectionState, DEFAULT_CONFIG, DEFAULT_MAX_ENTRIES_PER_VIEW, EntityFrame, ErrorMetadata, ExecuteOptions, ExecutionResult, Frame, FrameMode, FrameOp, FrameProcessor, FrameProcessorConfig, HyperStack, HyperStackConfig, HyperStackError, HyperStackOptions, HyperStackOptionsWithStorage, 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 'hyperstack-typescript';
|
|
4
4
|
import { UseBoundStore, StoreApi } from 'zustand';
|
|
5
5
|
|
|
6
6
|
type ViewMode = 'state' | 'list';
|
|
@@ -36,10 +36,12 @@ interface UseHyperstackOptions {
|
|
|
36
36
|
/** Override the stack's embedded URL (useful for local development) */
|
|
37
37
|
url?: string;
|
|
38
38
|
}
|
|
39
|
-
interface ViewHookOptions {
|
|
39
|
+
interface ViewHookOptions<TSchema = unknown> {
|
|
40
40
|
enabled?: boolean;
|
|
41
41
|
initialData?: unknown;
|
|
42
42
|
refreshOnReconnect?: boolean;
|
|
43
|
+
/** Schema to validate entities. Returns undefined if validation fails. */
|
|
44
|
+
schema?: Schema<TSchema>;
|
|
43
45
|
}
|
|
44
46
|
interface ViewHookResult<T> {
|
|
45
47
|
data: T | undefined;
|
|
@@ -47,20 +49,22 @@ interface ViewHookResult<T> {
|
|
|
47
49
|
error?: Error;
|
|
48
50
|
refresh: () => void;
|
|
49
51
|
}
|
|
50
|
-
interface ListParamsBase {
|
|
52
|
+
interface ListParamsBase<TSchema = unknown> {
|
|
51
53
|
key?: string;
|
|
52
54
|
where?: Record<string, unknown>;
|
|
53
55
|
limit?: number;
|
|
54
56
|
filters?: Record<string, string>;
|
|
55
57
|
skip?: number;
|
|
58
|
+
/** Schema to validate/filter entities. Only entities passing safeParse will be returned. */
|
|
59
|
+
schema?: Schema<TSchema>;
|
|
56
60
|
}
|
|
57
|
-
interface ListParamsSingle extends ListParamsBase {
|
|
61
|
+
interface ListParamsSingle<TSchema = unknown> extends ListParamsBase<TSchema> {
|
|
58
62
|
take: 1;
|
|
59
63
|
}
|
|
60
|
-
interface ListParamsMultiple extends ListParamsBase {
|
|
64
|
+
interface ListParamsMultiple<TSchema = unknown> extends ListParamsBase<TSchema> {
|
|
61
65
|
take?: number;
|
|
62
66
|
}
|
|
63
|
-
type ListParams = ListParamsSingle | ListParamsMultiple
|
|
67
|
+
type ListParams<TSchema = unknown> = ListParamsSingle<TSchema> | ListParamsMultiple<TSchema>;
|
|
64
68
|
interface UseMutationReturn {
|
|
65
69
|
submit: (instructionOrTx: unknown | unknown[]) => Promise<string>;
|
|
66
70
|
status: 'idle' | 'pending' | 'success' | 'error';
|
|
@@ -74,14 +78,15 @@ interface StateViewHook<T> {
|
|
|
74
78
|
}, options?: ViewHookOptions) => ViewHookResult<T>;
|
|
75
79
|
}
|
|
76
80
|
interface ListViewHook<T> {
|
|
77
|
-
use(params: ListParamsSingle
|
|
78
|
-
use(params?: ListParamsMultiple
|
|
79
|
-
useOne: (params?: Omit<ListParamsBase
|
|
81
|
+
use<TSchema = T>(params: ListParamsSingle<TSchema>, options?: ViewHookOptions): ViewHookResult<TSchema | undefined>;
|
|
82
|
+
use<TSchema = T>(params?: ListParamsMultiple<TSchema>, options?: ViewHookOptions): ViewHookResult<TSchema[]>;
|
|
83
|
+
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?: ViewHookOptions) => ViewHookResult<TSchema | undefined>;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
interface HyperstackContextValue {
|
|
83
87
|
getOrCreateClient: <TStack extends StackDefinition>(stack: TStack, urlOverride?: string) => Promise<HyperStack<TStack>>;
|
|
84
88
|
getClient: <TStack extends StackDefinition>(stack: TStack | undefined) => HyperStack<TStack> | null;
|
|
89
|
+
subscribeToClientChanges: (callback: () => void) => () => void;
|
|
85
90
|
config: HyperstackConfig;
|
|
86
91
|
}
|
|
87
92
|
declare function HyperstackProvider({ children, fallback, ...config }: HyperstackConfig & {
|
|
@@ -149,19 +154,19 @@ declare class ZustandAdapter implements StorageAdapter {
|
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
type ViewHookForDef<TDef> = TDef extends ViewDef<infer T, 'state'> ? {
|
|
152
|
-
use: (key?: Record<string, string>, options?: ViewHookOptions) => ViewHookResult<
|
|
157
|
+
use: <TSchema = T>(key?: Record<string, string>, options?: ViewHookOptions<TSchema>) => ViewHookResult<TSchema>;
|
|
153
158
|
} : TDef extends ViewDef<infer T, 'list'> ? {
|
|
154
159
|
use: {
|
|
155
|
-
(params: ListParamsSingle
|
|
156
|
-
(params?: ListParamsMultiple
|
|
160
|
+
<TSchema = T>(params: ListParamsSingle<TSchema>, options?: ViewHookOptions<TSchema>): ViewHookResult<TSchema | undefined>;
|
|
161
|
+
<TSchema = T>(params?: ListParamsMultiple<TSchema>, options?: ViewHookOptions<TSchema>): ViewHookResult<TSchema[]>;
|
|
157
162
|
};
|
|
158
|
-
useOne: (params?: Omit<ListParamsBase
|
|
163
|
+
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?: ViewHookOptions<TSchema>) => ViewHookResult<TSchema | undefined>;
|
|
159
164
|
} : TDef extends ViewDef<infer T, 'state' | 'list'> ? {
|
|
160
165
|
use: {
|
|
161
|
-
(params: ListParamsSingle
|
|
162
|
-
(params?: ListParamsMultiple | Record<string, string>, options?: ViewHookOptions): ViewHookResult<
|
|
166
|
+
<TSchema = T>(params: ListParamsSingle<TSchema>, options?: ViewHookOptions<TSchema>): ViewHookResult<TSchema | undefined>;
|
|
167
|
+
<TSchema = T>(params?: ListParamsMultiple<TSchema> | Record<string, string>, options?: ViewHookOptions<TSchema>): ViewHookResult<TSchema | TSchema[]>;
|
|
163
168
|
};
|
|
164
|
-
useOne: (params?: Omit<ListParamsBase
|
|
169
|
+
useOne: <TSchema = T>(params?: Omit<ListParamsBase<TSchema>, 'take'>, options?: ViewHookOptions<TSchema>) => ViewHookResult<TSchema | undefined>;
|
|
165
170
|
} : never;
|
|
166
171
|
type BuildViewInterface<TViews extends Record<string, ViewGroup>> = {
|
|
167
172
|
[K in keyof TViews]: {
|
|
@@ -180,6 +185,8 @@ type StackClient<TStack extends StackDefinition> = {
|
|
|
180
185
|
instructions: BuildInstructionInterface<TStack['instructions']>;
|
|
181
186
|
zustandStore: UseBoundStore<StoreApi<HyperStackStore>>;
|
|
182
187
|
client: HyperStack<TStack>;
|
|
188
|
+
connectionState: ConnectionState;
|
|
189
|
+
isConnected: boolean;
|
|
183
190
|
isLoading: boolean;
|
|
184
191
|
error: Error | null;
|
|
185
192
|
};
|