pulse-js-framework 1.7.11 → 1.7.12
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 +2 -1
- package/package.json +15 -2
- package/runtime/context.js +374 -0
- package/runtime/graphql.js +1356 -0
- package/runtime/index.js +6 -0
- package/runtime/logger.js +2 -1
- package/runtime/websocket.js +874 -0
- package/types/context.d.ts +171 -0
- package/types/graphql.d.ts +490 -0
- package/types/index.d.ts +15 -0
- package/types/websocket.d.ts +347 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pulse Framework - Context API Type Definitions
|
|
3
|
+
* @module pulse-js-framework/runtime/context
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Pulse } from './pulse';
|
|
7
|
+
|
|
8
|
+
/** Context options */
|
|
9
|
+
export interface ContextOptions {
|
|
10
|
+
/** Display name for debugging */
|
|
11
|
+
displayName?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Context object created by createContext
|
|
16
|
+
*/
|
|
17
|
+
export interface Context<T> {
|
|
18
|
+
/** Unique identifier (internal) */
|
|
19
|
+
readonly _id: symbol;
|
|
20
|
+
/** Display name for debugging */
|
|
21
|
+
readonly displayName: string;
|
|
22
|
+
/** Default value when no Provider is found */
|
|
23
|
+
readonly defaultValue: T;
|
|
24
|
+
/** Provider shorthand method */
|
|
25
|
+
Provider: (value: T | Pulse<T>, children: (() => any) | any) => any;
|
|
26
|
+
/** Consumer shorthand method */
|
|
27
|
+
Consumer: (render: (value: Pulse<T>) => any) => any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a new context with a default value
|
|
32
|
+
*
|
|
33
|
+
* @template T The type of the context value
|
|
34
|
+
* @param defaultValue Value used when no Provider is found in the tree
|
|
35
|
+
* @param options Context options
|
|
36
|
+
* @returns Context object to pass to Provider and useContext
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const ThemeContext = createContext<'light' | 'dark'>('light');
|
|
40
|
+
* const UserContext = createContext<User | null>(null, { displayName: 'UserContext' });
|
|
41
|
+
*/
|
|
42
|
+
export declare function createContext<T>(
|
|
43
|
+
defaultValue: T,
|
|
44
|
+
options?: ContextOptions
|
|
45
|
+
): Context<T>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Provide a value to a context for all descendants
|
|
49
|
+
*
|
|
50
|
+
* @template T The type of the context value
|
|
51
|
+
* @param context Context object from createContext
|
|
52
|
+
* @param value Value to provide (can be reactive pulse)
|
|
53
|
+
* @param children Child elements or render function
|
|
54
|
+
* @returns The rendered children
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* Provider(ThemeContext, 'dark', () => [Header(), Content()]);
|
|
58
|
+
* Provider(ThemeContext, themePulse, () => App());
|
|
59
|
+
*/
|
|
60
|
+
export declare function Provider<T>(
|
|
61
|
+
context: Context<T>,
|
|
62
|
+
value: T | Pulse<T>,
|
|
63
|
+
children: (() => any) | any
|
|
64
|
+
): any;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get the current value from a context
|
|
68
|
+
*
|
|
69
|
+
* Returns a reactive pulse that updates when the provided value changes.
|
|
70
|
+
* If no Provider is found, returns the context's default value.
|
|
71
|
+
*
|
|
72
|
+
* @template T The type of the context value
|
|
73
|
+
* @param context Context object from createContext
|
|
74
|
+
* @returns Reactive pulse containing the context value
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* const theme = useContext(ThemeContext);
|
|
78
|
+
* console.log(theme.get()); // 'dark'
|
|
79
|
+
*/
|
|
80
|
+
export declare function useContext<T>(context: Context<T>): Pulse<T>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Consumer component pattern for context consumption
|
|
84
|
+
*
|
|
85
|
+
* @template T The type of the context value
|
|
86
|
+
* @param context Context object from createContext
|
|
87
|
+
* @param render Render function receiving the context value
|
|
88
|
+
* @returns Result of the render function
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* Consumer(ThemeContext, (theme) => el(`button.btn-${theme.get()}`));
|
|
92
|
+
*/
|
|
93
|
+
export declare function Consumer<T>(
|
|
94
|
+
context: Context<T>,
|
|
95
|
+
render: (value: Pulse<T>) => any
|
|
96
|
+
): any;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Check if a value is a valid context object
|
|
100
|
+
*
|
|
101
|
+
* @param value Value to check
|
|
102
|
+
* @returns True if value is a valid context
|
|
103
|
+
*/
|
|
104
|
+
export declare function isContext(value: unknown): value is Context<unknown>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get the current provider depth for a context (useful for debugging)
|
|
108
|
+
*
|
|
109
|
+
* @param context Context to check
|
|
110
|
+
* @returns Current nesting depth of providers
|
|
111
|
+
*/
|
|
112
|
+
export declare function getContextDepth(context: Context<unknown>): number;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Dispose a context and clean up its resources
|
|
116
|
+
* Should be called when a context is no longer needed (e.g., in tests)
|
|
117
|
+
*
|
|
118
|
+
* @param context Context to dispose
|
|
119
|
+
*/
|
|
120
|
+
export declare function disposeContext(context: Context<unknown>): void;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Create a derived context value from one or more contexts
|
|
124
|
+
*
|
|
125
|
+
* @template T The type of the derived value
|
|
126
|
+
* @param selector Function that receives context values and returns derived value
|
|
127
|
+
* @param contexts Contexts to derive from
|
|
128
|
+
* @returns Computed pulse with derived value
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* const effectiveTheme = useContextSelector(
|
|
132
|
+
* (settings, user) => settings.get().theme || user.get().preferredTheme,
|
|
133
|
+
* SettingsContext,
|
|
134
|
+
* UserContext
|
|
135
|
+
* );
|
|
136
|
+
*/
|
|
137
|
+
export declare function useContextSelector<T, Contexts extends Context<any>[]>(
|
|
138
|
+
selector: (...values: { [K in keyof Contexts]: Contexts[K] extends Context<infer U> ? Pulse<U> : never }) => T,
|
|
139
|
+
...contexts: Contexts
|
|
140
|
+
): Pulse<T>;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Provide multiple contexts at once
|
|
144
|
+
*
|
|
145
|
+
* @param providers Array of [context, value] pairs
|
|
146
|
+
* @param children Render function for children
|
|
147
|
+
* @returns Rendered children
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* provideMany([
|
|
151
|
+
* [ThemeContext, 'dark'],
|
|
152
|
+
* [UserContext, currentUser],
|
|
153
|
+
* [LocaleContext, 'fr']
|
|
154
|
+
* ], () => App());
|
|
155
|
+
*/
|
|
156
|
+
export declare function provideMany<T extends [Context<any>, any][]>(
|
|
157
|
+
providers: T,
|
|
158
|
+
children: (() => any) | any
|
|
159
|
+
): any;
|
|
160
|
+
|
|
161
|
+
export default {
|
|
162
|
+
createContext,
|
|
163
|
+
useContext,
|
|
164
|
+
Provider,
|
|
165
|
+
Consumer,
|
|
166
|
+
isContext,
|
|
167
|
+
getContextDepth,
|
|
168
|
+
disposeContext,
|
|
169
|
+
useContextSelector,
|
|
170
|
+
provideMany
|
|
171
|
+
};
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pulse GraphQL Client TypeScript Definitions
|
|
3
|
+
* @module pulse-js-framework/runtime/graphql
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Pulse } from './pulse';
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Error Types
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* GraphQL error codes
|
|
14
|
+
*/
|
|
15
|
+
export type GraphQLErrorCode =
|
|
16
|
+
| 'GRAPHQL_ERROR'
|
|
17
|
+
| 'NETWORK_ERROR'
|
|
18
|
+
| 'PARSE_ERROR'
|
|
19
|
+
| 'TIMEOUT'
|
|
20
|
+
| 'AUTHENTICATION_ERROR'
|
|
21
|
+
| 'AUTHORIZATION_ERROR'
|
|
22
|
+
| 'VALIDATION_ERROR'
|
|
23
|
+
| 'SUBSCRIPTION_ERROR';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* GraphQL Error with operation context
|
|
27
|
+
*/
|
|
28
|
+
export declare class GraphQLError extends Error {
|
|
29
|
+
readonly name: 'GraphQLError';
|
|
30
|
+
readonly code: GraphQLErrorCode;
|
|
31
|
+
readonly errors: GraphQLResponseError[];
|
|
32
|
+
readonly data: unknown;
|
|
33
|
+
readonly extensions: Record<string, unknown>;
|
|
34
|
+
readonly response: unknown;
|
|
35
|
+
readonly request: unknown;
|
|
36
|
+
|
|
37
|
+
constructor(message: string, options?: {
|
|
38
|
+
code?: GraphQLErrorCode;
|
|
39
|
+
errors?: GraphQLResponseError[];
|
|
40
|
+
data?: unknown;
|
|
41
|
+
extensions?: Record<string, unknown>;
|
|
42
|
+
response?: unknown;
|
|
43
|
+
request?: unknown;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
static isGraphQLError(error: unknown): error is GraphQLError;
|
|
47
|
+
|
|
48
|
+
hasPartialData(): boolean;
|
|
49
|
+
isAuthenticationError(): boolean;
|
|
50
|
+
isAuthorizationError(): boolean;
|
|
51
|
+
isValidationError(): boolean;
|
|
52
|
+
isNetworkError(): boolean;
|
|
53
|
+
isTimeout(): boolean;
|
|
54
|
+
getFirstError(): string | null;
|
|
55
|
+
getAllErrors(): string[];
|
|
56
|
+
toJSON(): Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* GraphQL response error structure
|
|
61
|
+
*/
|
|
62
|
+
export interface GraphQLResponseError {
|
|
63
|
+
message: string;
|
|
64
|
+
locations?: { line: number; column: number }[];
|
|
65
|
+
path?: (string | number)[];
|
|
66
|
+
extensions?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// Interceptor Types
|
|
71
|
+
// ============================================================================
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Interceptor handler
|
|
75
|
+
*/
|
|
76
|
+
export interface InterceptorHandler<T = unknown> {
|
|
77
|
+
fulfilled?: (value: T) => T | Promise<T>;
|
|
78
|
+
rejected?: (error: Error) => T | Promise<T>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Interceptor manager
|
|
83
|
+
*/
|
|
84
|
+
export declare class InterceptorManager<T = unknown> {
|
|
85
|
+
use(fulfilled?: (value: T) => T | Promise<T>, rejected?: (error: Error) => T | Promise<T>): number;
|
|
86
|
+
eject(id: number): void;
|
|
87
|
+
clear(): void;
|
|
88
|
+
readonly size: number;
|
|
89
|
+
[Symbol.iterator](): IterableIterator<InterceptorHandler<T>>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ============================================================================
|
|
93
|
+
// Configuration Types
|
|
94
|
+
// ============================================================================
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* GraphQL client configuration options
|
|
98
|
+
*/
|
|
99
|
+
export interface GraphQLClientOptions {
|
|
100
|
+
/** GraphQL endpoint URL (required) */
|
|
101
|
+
url: string;
|
|
102
|
+
/** WebSocket URL for subscriptions (default: derived from url) */
|
|
103
|
+
wsUrl?: string;
|
|
104
|
+
/** Default request headers */
|
|
105
|
+
headers?: Record<string, string>;
|
|
106
|
+
/** Request timeout in ms (default: 30000) */
|
|
107
|
+
timeout?: number;
|
|
108
|
+
/** Fetch credentials mode (default: 'same-origin') */
|
|
109
|
+
credentials?: 'include' | 'omit' | 'same-origin';
|
|
110
|
+
/** Retry attempts on failure (default: 0) */
|
|
111
|
+
retries?: number;
|
|
112
|
+
/** Delay between retries in ms (default: 1000) */
|
|
113
|
+
retryDelay?: number;
|
|
114
|
+
/** WebSocket connection parameters */
|
|
115
|
+
wsConnectionParams?: Record<string, unknown> | (() => Record<string, unknown> | Promise<Record<string, unknown>>);
|
|
116
|
+
/** Enable WebSocket auto-reconnect (default: true) */
|
|
117
|
+
wsReconnect?: boolean;
|
|
118
|
+
/** Max WebSocket reconnection attempts (default: 5) */
|
|
119
|
+
wsMaxRetries?: number;
|
|
120
|
+
/** Enable query caching (default: true) */
|
|
121
|
+
cache?: boolean;
|
|
122
|
+
/** Cache TTL in ms (default: 300000) */
|
|
123
|
+
cacheTime?: number;
|
|
124
|
+
/** Time before data is considered stale in ms (default: 0) */
|
|
125
|
+
staleTime?: number;
|
|
126
|
+
/** Deduplicate identical in-flight queries (default: true) */
|
|
127
|
+
dedupe?: boolean;
|
|
128
|
+
/** Throw on GraphQL errors (default: true) */
|
|
129
|
+
throwOnError?: boolean;
|
|
130
|
+
/** Global error handler */
|
|
131
|
+
onError?: (error: GraphQLError) => void;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Query/Mutation request options
|
|
136
|
+
*/
|
|
137
|
+
export interface GraphQLRequestOptions {
|
|
138
|
+
/** Custom cache key */
|
|
139
|
+
cacheKey?: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ============================================================================
|
|
143
|
+
// Client Types
|
|
144
|
+
// ============================================================================
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* GraphQL client instance
|
|
148
|
+
*/
|
|
149
|
+
export interface GraphQLClient {
|
|
150
|
+
/** Execute a GraphQL query */
|
|
151
|
+
query<T = unknown>(query: string, variables?: Record<string, unknown>, options?: GraphQLRequestOptions): Promise<T>;
|
|
152
|
+
/** Execute a GraphQL mutation */
|
|
153
|
+
mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>, options?: GraphQLRequestOptions): Promise<T>;
|
|
154
|
+
/** Subscribe to a GraphQL subscription */
|
|
155
|
+
subscribe(subscription: string, variables?: Record<string, unknown>, handlers: SubscriptionHandlers): () => void;
|
|
156
|
+
/** Invalidate a cache entry */
|
|
157
|
+
invalidate(cacheKey: string): void;
|
|
158
|
+
/** Invalidate all cache entries */
|
|
159
|
+
invalidateAll(): void;
|
|
160
|
+
/** Get cache statistics */
|
|
161
|
+
getCacheStats(): { size: number; keys: string[] };
|
|
162
|
+
/** Get active subscriptions count */
|
|
163
|
+
getActiveSubscriptions(): number;
|
|
164
|
+
/** Close all subscriptions */
|
|
165
|
+
closeAllSubscriptions(): void;
|
|
166
|
+
/** WebSocket connection state */
|
|
167
|
+
readonly wsState: Pulse<'connecting' | 'open' | 'closing' | 'closed'>;
|
|
168
|
+
/** WebSocket connected state */
|
|
169
|
+
readonly wsConnected: Pulse<boolean>;
|
|
170
|
+
/** Request interceptors */
|
|
171
|
+
readonly interceptors: {
|
|
172
|
+
request: InterceptorManager<GraphQLRequestConfig>;
|
|
173
|
+
response: InterceptorManager<unknown>;
|
|
174
|
+
};
|
|
175
|
+
/** Create a child client with merged config */
|
|
176
|
+
create(options?: Partial<GraphQLClientOptions>): GraphQLClient;
|
|
177
|
+
/** Dispose the client */
|
|
178
|
+
dispose(): void;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* GraphQL request configuration (for interceptors)
|
|
183
|
+
*/
|
|
184
|
+
export interface GraphQLRequestConfig {
|
|
185
|
+
query: string;
|
|
186
|
+
variables?: Record<string, unknown>;
|
|
187
|
+
operationName?: string | null;
|
|
188
|
+
[key: string]: unknown;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Subscription event handlers
|
|
193
|
+
*/
|
|
194
|
+
export interface SubscriptionHandlers {
|
|
195
|
+
onData?: (data: unknown) => void;
|
|
196
|
+
onError?: (error: GraphQLError) => void;
|
|
197
|
+
onComplete?: () => void;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ============================================================================
|
|
201
|
+
// useQuery Types
|
|
202
|
+
// ============================================================================
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Query status
|
|
206
|
+
*/
|
|
207
|
+
export type QueryStatus = 'idle' | 'loading' | 'success' | 'error';
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* useQuery hook options
|
|
211
|
+
*/
|
|
212
|
+
export interface UseQueryOptions<TData = unknown, TSelect = TData> {
|
|
213
|
+
/** GraphQL client instance */
|
|
214
|
+
client?: GraphQLClient;
|
|
215
|
+
/** Enable/disable query (default: true) */
|
|
216
|
+
enabled?: boolean | Pulse<boolean>;
|
|
217
|
+
/** Execute immediately (default: true) */
|
|
218
|
+
immediate?: boolean;
|
|
219
|
+
/** Custom cache key */
|
|
220
|
+
cacheKey?: string | (() => string);
|
|
221
|
+
/** Cache TTL in ms */
|
|
222
|
+
cacheTime?: number;
|
|
223
|
+
/** Stale time in ms */
|
|
224
|
+
staleTime?: number;
|
|
225
|
+
/** Refetch when window gains focus */
|
|
226
|
+
refetchOnFocus?: boolean;
|
|
227
|
+
/** Refetch when network reconnects */
|
|
228
|
+
refetchOnReconnect?: boolean;
|
|
229
|
+
/** Polling interval in ms */
|
|
230
|
+
refetchInterval?: number;
|
|
231
|
+
/** Retry attempts */
|
|
232
|
+
retry?: number;
|
|
233
|
+
/** Retry delay in ms */
|
|
234
|
+
retryDelay?: number;
|
|
235
|
+
/** Success callback */
|
|
236
|
+
onSuccess?: (data: TSelect) => void;
|
|
237
|
+
/** Error callback */
|
|
238
|
+
onError?: (error: GraphQLError) => void;
|
|
239
|
+
/** Transform/select data */
|
|
240
|
+
select?: (data: TData) => TSelect;
|
|
241
|
+
/** Placeholder data while loading */
|
|
242
|
+
placeholderData?: TSelect;
|
|
243
|
+
/** Keep previous data during refetch */
|
|
244
|
+
keepPreviousData?: boolean;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* useQuery hook return type
|
|
249
|
+
*/
|
|
250
|
+
export interface UseQueryReturn<TData = unknown> {
|
|
251
|
+
/** Query result data */
|
|
252
|
+
data: Pulse<TData | null>;
|
|
253
|
+
/** Query error */
|
|
254
|
+
error: Pulse<GraphQLError | null>;
|
|
255
|
+
/** True during initial load */
|
|
256
|
+
loading: Pulse<boolean>;
|
|
257
|
+
/** True during any fetch (including refetch) */
|
|
258
|
+
fetching: Pulse<boolean>;
|
|
259
|
+
/** Query status */
|
|
260
|
+
status: Pulse<QueryStatus>;
|
|
261
|
+
/** True if data is stale */
|
|
262
|
+
isStale: Pulse<boolean>;
|
|
263
|
+
/** Force refetch */
|
|
264
|
+
refetch: () => Promise<TData>;
|
|
265
|
+
/** Invalidate cache */
|
|
266
|
+
invalidate: () => void;
|
|
267
|
+
/** Reset to initial state */
|
|
268
|
+
reset: () => void;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ============================================================================
|
|
272
|
+
// useMutation Types
|
|
273
|
+
// ============================================================================
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Mutation status
|
|
277
|
+
*/
|
|
278
|
+
export type MutationStatus = 'idle' | 'loading' | 'success' | 'error';
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* useMutation hook options
|
|
282
|
+
*/
|
|
283
|
+
export interface UseMutationOptions<TData = unknown, TVariables = Record<string, unknown>, TContext = unknown> {
|
|
284
|
+
/** GraphQL client instance */
|
|
285
|
+
client?: GraphQLClient;
|
|
286
|
+
/** Success callback */
|
|
287
|
+
onSuccess?: (data: TData, variables: TVariables) => void;
|
|
288
|
+
/** Error callback */
|
|
289
|
+
onError?: (error: GraphQLError, variables: TVariables, context?: TContext) => void;
|
|
290
|
+
/** Called after success or error */
|
|
291
|
+
onSettled?: (data: TData | null, error: GraphQLError | null, variables: TVariables) => void;
|
|
292
|
+
/** Retry attempts */
|
|
293
|
+
retry?: number;
|
|
294
|
+
/** Retry delay in ms */
|
|
295
|
+
retryDelay?: number;
|
|
296
|
+
/** Called before mutation (for optimistic updates), return value passed to onError/onSettled */
|
|
297
|
+
onMutate?: (variables: TVariables) => TContext | Promise<TContext>;
|
|
298
|
+
/** Cache keys to invalidate on success */
|
|
299
|
+
invalidateQueries?: string[];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* useMutation hook return type
|
|
304
|
+
*/
|
|
305
|
+
export interface UseMutationReturn<TData = unknown, TVariables = Record<string, unknown>> {
|
|
306
|
+
/** Mutation result data */
|
|
307
|
+
data: Pulse<TData | null>;
|
|
308
|
+
/** Mutation error */
|
|
309
|
+
error: Pulse<GraphQLError | null>;
|
|
310
|
+
/** True while mutation is in progress */
|
|
311
|
+
loading: Pulse<boolean>;
|
|
312
|
+
/** Mutation status */
|
|
313
|
+
status: Pulse<MutationStatus>;
|
|
314
|
+
/** Execute mutation */
|
|
315
|
+
mutate: (variables?: TVariables) => Promise<TData>;
|
|
316
|
+
/** Execute mutation (alias for mutate) */
|
|
317
|
+
mutateAsync: (variables?: TVariables) => Promise<TData>;
|
|
318
|
+
/** Reset to initial state */
|
|
319
|
+
reset: () => void;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ============================================================================
|
|
323
|
+
// useSubscription Types
|
|
324
|
+
// ============================================================================
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Subscription status
|
|
328
|
+
*/
|
|
329
|
+
export type SubscriptionStatus = 'connecting' | 'connected' | 'error' | 'closed';
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* useSubscription hook options
|
|
333
|
+
*/
|
|
334
|
+
export interface UseSubscriptionOptions<TData = unknown> {
|
|
335
|
+
/** GraphQL client instance */
|
|
336
|
+
client?: GraphQLClient;
|
|
337
|
+
/** Enable/disable subscription (default: true) */
|
|
338
|
+
enabled?: boolean | Pulse<boolean>;
|
|
339
|
+
/** Called on each message */
|
|
340
|
+
onData?: (data: TData) => void;
|
|
341
|
+
/** Error callback */
|
|
342
|
+
onError?: (error: GraphQLError) => void;
|
|
343
|
+
/** Called when subscription ends */
|
|
344
|
+
onComplete?: () => void;
|
|
345
|
+
/** Resubscribe on error (default: true) */
|
|
346
|
+
shouldResubscribe?: boolean | (() => boolean);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* useSubscription hook return type
|
|
351
|
+
*/
|
|
352
|
+
export interface UseSubscriptionReturn<TData = unknown> {
|
|
353
|
+
/** Latest subscription data */
|
|
354
|
+
data: Pulse<TData | null>;
|
|
355
|
+
/** Subscription error */
|
|
356
|
+
error: Pulse<GraphQLError | null>;
|
|
357
|
+
/** Subscription status */
|
|
358
|
+
status: Pulse<SubscriptionStatus>;
|
|
359
|
+
/** Manually unsubscribe */
|
|
360
|
+
unsubscribe: () => void;
|
|
361
|
+
/** Restart subscription */
|
|
362
|
+
resubscribe: () => void;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// ============================================================================
|
|
366
|
+
// Factory Functions
|
|
367
|
+
// ============================================================================
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Create a GraphQL client instance.
|
|
371
|
+
*
|
|
372
|
+
* @param options Client configuration options
|
|
373
|
+
* @returns GraphQL client instance
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* const client = createGraphQLClient({
|
|
377
|
+
* url: '/graphql',
|
|
378
|
+
* headers: { 'Authorization': 'Bearer token' }
|
|
379
|
+
* });
|
|
380
|
+
*
|
|
381
|
+
* const users = await client.query(`
|
|
382
|
+
* query GetUsers { users { id name } }
|
|
383
|
+
* `);
|
|
384
|
+
*/
|
|
385
|
+
export declare function createGraphQLClient(options: GraphQLClientOptions): GraphQLClient;
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Set the default GraphQL client for hooks.
|
|
389
|
+
*/
|
|
390
|
+
export declare function setDefaultClient(client: GraphQLClient | null): void;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Get the default GraphQL client.
|
|
394
|
+
*/
|
|
395
|
+
export declare function getDefaultClient(): GraphQLClient | null;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Execute a GraphQL query with caching and reactivity.
|
|
399
|
+
*
|
|
400
|
+
* @param query GraphQL query string
|
|
401
|
+
* @param variables Query variables (can be a function for reactive variables)
|
|
402
|
+
* @param options Query options
|
|
403
|
+
* @returns Reactive query state and controls
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* const { data, loading, error, refetch } = useQuery(
|
|
407
|
+
* `query GetUser($id: ID!) { user(id: $id) { id name } }`,
|
|
408
|
+
* { id: '123' },
|
|
409
|
+
* { staleTime: 30000 }
|
|
410
|
+
* );
|
|
411
|
+
*/
|
|
412
|
+
export declare function useQuery<TData = unknown, TSelect = TData>(
|
|
413
|
+
query: string,
|
|
414
|
+
variables?: Record<string, unknown> | (() => Record<string, unknown>),
|
|
415
|
+
options?: UseQueryOptions<TData, TSelect>
|
|
416
|
+
): UseQueryReturn<TSelect>;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Execute GraphQL mutations.
|
|
420
|
+
*
|
|
421
|
+
* @param mutation GraphQL mutation string
|
|
422
|
+
* @param options Mutation options
|
|
423
|
+
* @returns Mutation state and execute function
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* const { mutate, loading } = useMutation(
|
|
427
|
+
* `mutation CreateUser($input: CreateUserInput!) {
|
|
428
|
+
* createUser(input: $input) { id name }
|
|
429
|
+
* }`,
|
|
430
|
+
* { onSuccess: (data) => console.log('Created:', data) }
|
|
431
|
+
* );
|
|
432
|
+
*
|
|
433
|
+
* await mutate({ input: { name: 'John' } });
|
|
434
|
+
*/
|
|
435
|
+
export declare function useMutation<TData = unknown, TVariables = Record<string, unknown>>(
|
|
436
|
+
mutation: string,
|
|
437
|
+
options?: UseMutationOptions<TData, TVariables>
|
|
438
|
+
): UseMutationReturn<TData, TVariables>;
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Subscribe to GraphQL subscriptions over WebSocket.
|
|
442
|
+
*
|
|
443
|
+
* @param subscription GraphQL subscription string
|
|
444
|
+
* @param variables Subscription variables (can be a function for reactive variables)
|
|
445
|
+
* @param options Subscription options
|
|
446
|
+
* @returns Reactive subscription state
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* const { data, status } = useSubscription(
|
|
450
|
+
* `subscription OnMessage($channelId: ID!) {
|
|
451
|
+
* messageAdded(channelId: $channelId) { id content }
|
|
452
|
+
* }`,
|
|
453
|
+
* { channelId: '123' },
|
|
454
|
+
* { onData: (msg) => console.log('New message:', msg) }
|
|
455
|
+
* );
|
|
456
|
+
*/
|
|
457
|
+
export declare function useSubscription<TData = unknown>(
|
|
458
|
+
subscription: string,
|
|
459
|
+
variables?: Record<string, unknown> | (() => Record<string, unknown>),
|
|
460
|
+
options?: UseSubscriptionOptions<TData>
|
|
461
|
+
): UseSubscriptionReturn<TData>;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Generate a cache key for a GraphQL operation.
|
|
465
|
+
*/
|
|
466
|
+
export declare function generateCacheKey(query: string, variables?: Record<string, unknown>): string;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Extract operation name from a GraphQL query string.
|
|
470
|
+
*/
|
|
471
|
+
export declare function extractOperationName(query: string): string | null;
|
|
472
|
+
|
|
473
|
+
// ============================================================================
|
|
474
|
+
// Default Export
|
|
475
|
+
// ============================================================================
|
|
476
|
+
|
|
477
|
+
declare const _default: {
|
|
478
|
+
createGraphQLClient: typeof createGraphQLClient;
|
|
479
|
+
GraphQLClient: GraphQLClient;
|
|
480
|
+
GraphQLError: typeof GraphQLError;
|
|
481
|
+
useQuery: typeof useQuery;
|
|
482
|
+
useMutation: typeof useMutation;
|
|
483
|
+
useSubscription: typeof useSubscription;
|
|
484
|
+
setDefaultClient: typeof setDefaultClient;
|
|
485
|
+
getDefaultClient: typeof getDefaultClient;
|
|
486
|
+
generateCacheKey: typeof generateCacheKey;
|
|
487
|
+
extractOperationName: typeof extractOperationName;
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
export default _default;
|
package/types/index.d.ts
CHANGED
|
@@ -224,3 +224,18 @@ export {
|
|
|
224
224
|
useField,
|
|
225
225
|
useFieldArray
|
|
226
226
|
} from './form';
|
|
227
|
+
|
|
228
|
+
// Context API
|
|
229
|
+
export {
|
|
230
|
+
Context,
|
|
231
|
+
ContextOptions,
|
|
232
|
+
createContext,
|
|
233
|
+
useContext,
|
|
234
|
+
Provider,
|
|
235
|
+
Consumer,
|
|
236
|
+
isContext,
|
|
237
|
+
getContextDepth,
|
|
238
|
+
disposeContext,
|
|
239
|
+
useContextSelector,
|
|
240
|
+
provideMany
|
|
241
|
+
} from './context';
|