@reifydb/react 0.9.1 → 0.9.3

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 CHANGED
@@ -1,231 +1,40 @@
1
- import { Column, ShapeNode, InferShape } from '@reifydb/core';
1
+ import { ShapeNode, InferShape, FrameResults } from '@reifydb/core';
2
2
  export * from '@reifydb/core';
3
- import { WsClientOptions, WsClient, HttpClient, JsonHttpClient, JsonWsClient, SubscriptionConfig } from '@reifydb/client';
3
+ import { SubscriptionConfig } from '@reifydb/client';
4
4
  export * from '@reifydb/client';
5
- import React, { ReactNode } from 'react';
5
+ import { Store, Entry } from '@reifydb/store';
6
+ export * from '@reifydb/store';
7
+ import * as react_jsx_runtime from 'react/jsx-runtime';
8
+ import { ReactNode } from 'react';
6
9
 
7
- interface ConnectionState {
8
- client: WsClient | HttpClient | JsonHttpClient | JsonWsClient | null;
9
- isConnected: boolean;
10
- isConnecting: boolean;
11
- connectionError: string | null;
12
- listeners: Set<(state: ConnectionState) => void>;
10
+ interface StoreProviderProps {
11
+ store: Store;
12
+ children?: ReactNode;
13
13
  }
14
- interface ConnectionConfig {
15
- url?: string;
16
- token?: string;
17
- format?: 'json';
18
- options?: Omit<WsClientOptions, 'url' | 'token'>;
19
- }
20
- declare const DEFAULT_CONFIG: ConnectionConfig;
21
- declare const DEFAULT_URL = "ws://127.0.0.1:8090";
22
- declare class Connection {
23
- private state;
24
- private config;
25
- private connectPromise;
26
- constructor(config?: ConnectionConfig);
27
- setConfig(config: ConnectionConfig): void;
28
- getConfig(): ConnectionConfig;
29
- connect(url?: string, options?: Omit<WsClientOptions, 'url'>): Promise<void>;
30
- disconnect(): Promise<void>;
31
- reconnect(url?: string, options?: Omit<WsClientOptions, 'url'>): Promise<void>;
32
- getClient(): WsClient | HttpClient | JsonHttpClient | JsonWsClient | null;
33
- isConnected(): boolean;
34
- isConnecting(): boolean;
35
- getConnectionError(): string | null;
36
- getState(): Omit<ConnectionState, 'listeners'>;
37
- subscribe(listener: (state: ConnectionState) => void): () => void;
38
- private updateState;
39
- }
40
-
41
- /**
42
- * Get the singleton connection instance.
43
- * If a config is provided, the connection's config will be updated via setConfig().
44
- * @param config - Optional connection configuration
45
- * @returns The singleton Connection instance
46
- */
47
- declare function getConnection(config?: ConnectionConfig): Connection;
48
- /**
49
- * Clear the singleton connection
50
- */
51
- declare function clearConnection(): Promise<void>;
52
-
53
- declare const ConnectionContext: React.Context<Connection | null>;
54
- interface ConnectionProviderProps {
55
- config?: ConnectionConfig;
56
- children: ReactNode;
57
- }
58
- declare function ConnectionProvider({ config, children }: ConnectionProviderProps): React.JSX.Element;
59
-
60
- declare function useConnection(overrideConfig?: ConnectionConfig): {
61
- connect: () => Promise<void>;
62
- disconnect: () => Promise<void>;
63
- reconnect: () => Promise<void>;
64
- client: WsClient | HttpClient | JsonHttpClient | JsonWsClient | null;
65
- isConnected: boolean;
66
- isConnecting: boolean;
67
- connectionError: string | null;
68
- };
69
-
70
- interface QueryResult<T = any> {
71
- columns: Column[];
72
- rows: T[];
73
- executionTimeMs: number;
74
- rowsAffected?: number;
75
- }
76
- interface QueryState<T = any> {
77
- isExecuting: boolean;
78
- results: QueryResult<T>[] | undefined;
79
- error: string | undefined;
80
- executionTime: number | undefined;
81
- }
82
- interface QueryExecutorOptions {
83
- connectionConfig?: ConnectionConfig;
84
- }
85
- declare function useQueryExecutor<T = any>(options?: QueryExecutorOptions): {
86
- isExecuting: boolean;
87
- results: QueryResult<T>[] | undefined;
88
- error: string | undefined;
89
- executionTime: number | undefined;
90
- query: (rql: string, params?: any, shapes?: readonly ShapeNode[]) => Promise<void>;
91
- cancelQuery: () => void;
92
- };
93
-
94
- interface QueryOptions extends QueryExecutorOptions {
95
- connectionConfig?: ConnectionConfig;
96
- }
97
- declare function useQueryOne<S extends ShapeNode = any>(rql: string, params?: any, shape?: S, options?: QueryOptions): {
98
- isExecuting: boolean;
99
- result: QueryResult<S extends ShapeNode ? InferShape<S> : any> | undefined;
100
- error: string | undefined;
101
- };
102
- declare function useQueryMany<S extends readonly ShapeNode[] = readonly ShapeNode[]>(rql: string, params?: any, shapes?: S, options?: QueryOptions): {
103
- isExecuting: boolean;
104
- results: QueryResult<S extends readonly ShapeNode[] ? InferShape<S[number]> : any>[] | undefined;
105
- error: string | undefined;
106
- };
107
-
108
- interface CommandResult<T = any> {
109
- columns: Column[];
110
- rows: T[];
111
- executionTimeMs: number;
112
- rowsAffected?: number;
113
- }
114
- interface CommandState<T = any> {
115
- isExecuting: boolean;
116
- results: CommandResult<T>[] | undefined;
117
- error: string | undefined;
118
- executionTime: number | undefined;
119
- }
120
- interface CommandExecutorOptions {
121
- connectionConfig?: ConnectionConfig;
122
- }
123
- declare function useCommandExecutor<T = any>(options?: CommandExecutorOptions): {
124
- isExecuting: boolean;
125
- results: CommandResult<T>[] | undefined;
126
- error: string | undefined;
127
- executionTime: number | undefined;
128
- command: (rql: string, params?: any, shapes?: readonly ShapeNode[]) => Promise<void>;
129
- cancelCommand: () => void;
130
- };
14
+ declare function StoreProvider({ store, children }: StoreProviderProps): react_jsx_runtime.JSX.Element;
15
+ declare function useStore(): Store;
131
16
 
132
- interface CommandOptions extends CommandExecutorOptions {
133
- connectionConfig?: ConnectionConfig;
17
+ interface UseSubscriptionOptions {
18
+ config?: SubscriptionConfig;
19
+ enabled?: boolean;
134
20
  }
135
- declare function useCommandOne<S extends ShapeNode = any>(rql: string, params?: any, shape?: S, options?: CommandOptions): {
136
- isExecuting: boolean;
137
- result: CommandResult<S extends ShapeNode ? InferShape<S> : any> | undefined;
138
- error: string | undefined;
139
- };
140
- declare function useCommandMany<S extends readonly ShapeNode[] = readonly ShapeNode[]>(rql: string, params?: any, shapes?: S, options?: CommandOptions): {
141
- isExecuting: boolean;
142
- results: CommandResult<S extends readonly ShapeNode[] ? InferShape<S[number]> : any>[] | undefined;
143
- error: string | undefined;
144
- };
21
+ declare function useSubscription<S extends ShapeNode>(rql: string, params: any, shape: S, options?: UseSubscriptionOptions): Entry<InferShape<S>>;
145
22
 
146
- interface AdminResult<T = any> {
147
- columns: Column[];
148
- rows: T[];
149
- executionTimeMs: number;
150
- rowsAffected?: number;
151
- }
152
- interface AdminState<T = any> {
153
- isExecuting: boolean;
154
- results: AdminResult<T>[] | undefined;
155
- error: string | undefined;
156
- executionTime: number | undefined;
157
- }
158
- interface AdminExecutorOptions {
159
- connectionConfig?: ConnectionConfig;
23
+ interface UseQueryOptions {
24
+ enabled?: boolean;
160
25
  }
161
- declare function useAdminExecutor<T = any>(options?: AdminExecutorOptions): {
162
- isExecuting: boolean;
163
- results: AdminResult<T>[] | undefined;
164
- error: string | undefined;
165
- executionTime: number | undefined;
166
- admin: (rql: string, params?: any, shapes?: readonly ShapeNode[]) => Promise<void>;
167
- cancelAdmin: () => void;
168
- };
26
+ declare function useQuery<S extends ShapeNode>(rql: string, params: any, shape: S, options?: UseQueryOptions): Entry<InferShape<S>>;
169
27
 
170
- interface AdminOptions extends AdminExecutorOptions {
171
- connectionConfig?: ConnectionConfig;
28
+ interface Runner<S extends readonly ShapeNode[]> {
29
+ run: (rql: string, params?: any) => Promise<FrameResults<S>>;
30
+ isPending: boolean;
31
+ error: Error | undefined;
172
32
  }
173
- declare function useAdminOne<S extends ShapeNode = any>(rql: string, params?: any, shape?: S, options?: AdminOptions): {
174
- isExecuting: boolean;
175
- result: AdminResult<S extends ShapeNode ? InferShape<S> : any> | undefined;
176
- error: string | undefined;
177
- };
178
- declare function useAdminMany<S extends readonly ShapeNode[] = readonly ShapeNode[]>(rql: string, params?: any, shapes?: S, options?: AdminOptions): {
179
- isExecuting: boolean;
180
- results: AdminResult<S extends readonly ShapeNode[] ? InferShape<S[number]> : any>[] | undefined;
181
- error: string | undefined;
182
- };
183
33
 
184
- interface SubscriptionExecutorOptions {
185
- connectionConfig?: ConnectionConfig;
186
- }
187
- interface ChangeEvent<T> {
188
- operation: 'INSERT' | 'UPDATE' | 'REMOVE';
189
- rows: T[];
190
- timestamp: number;
191
- }
192
- interface SubscriptionState<T> {
193
- data: T[];
194
- changes: ChangeEvent<T>[];
195
- isSubscribed: boolean;
196
- isSubscribing: boolean;
197
- error: string | undefined;
198
- subscriptionId: string | undefined;
199
- }
200
- declare function useSubscriptionExecutor<T = any>(options?: SubscriptionExecutorOptions): {
201
- state: SubscriptionState<T>;
202
- subscribe: (rql: string, params?: any, shape?: ShapeNode, config?: SubscriptionConfig) => Promise<void>;
203
- unsubscribe: () => Promise<void>;
204
- clearChanges: () => void;
205
- clearData: () => void;
206
- };
34
+ type UseCommandResult<S extends readonly ShapeNode[]> = Runner<S>;
35
+ declare function useCommand<const S extends readonly ShapeNode[]>(shapes: S): UseCommandResult<S>;
207
36
 
208
- interface SubscriptionOptions extends SubscriptionExecutorOptions {
209
- enabled?: boolean;
210
- config?: SubscriptionConfig;
211
- }
212
- declare function useSubscription<S extends ShapeNode = any>(rql: string, params?: any, shape?: S, options?: SubscriptionOptions): {
213
- data: InferShape<S>[];
214
- changes: ChangeEvent<InferShape<S>>[];
215
- isSubscribed: boolean;
216
- isSubscribing: boolean;
217
- error: string | undefined;
218
- subscriptionId: string | undefined;
219
- };
220
-
221
- interface ColumnInfo {
222
- name: string;
223
- dataType: string;
224
- }
225
- interface TableInfo {
226
- name: string;
227
- columns: ColumnInfo[];
228
- }
229
- declare function useCatalog(): [boolean, TableInfo[], string | undefined];
37
+ type UseAdminResult<S extends readonly ShapeNode[]> = Runner<S>;
38
+ declare function useAdmin<const S extends readonly ShapeNode[]>(shapes: S): UseAdminResult<S>;
230
39
 
231
- export { type AdminExecutorOptions, type AdminOptions, type AdminResult, type AdminState, type ChangeEvent, type ColumnInfo, type CommandExecutorOptions, type CommandOptions, type CommandResult, type CommandState, Connection, type ConnectionConfig, ConnectionContext, ConnectionProvider, type ConnectionProviderProps, DEFAULT_CONFIG, DEFAULT_URL, type QueryExecutorOptions, type QueryOptions, type QueryResult, type QueryState, type SubscriptionExecutorOptions, type SubscriptionOptions, type SubscriptionState, type TableInfo, clearConnection, getConnection, useAdminExecutor, useAdminMany, useAdminOne, useCatalog, useCommandExecutor, useCommandMany, useCommandOne, useConnection, useQueryExecutor, useQueryMany, useQueryOne, useSubscription, useSubscriptionExecutor };
40
+ export { StoreProvider, type StoreProviderProps, type UseAdminResult, type UseCommandResult, type UseQueryOptions, type UseSubscriptionOptions, useAdmin, useCommand, useQuery, useStore, useSubscription };