@spoosh/react 0.5.0 → 0.6.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 +26 -5
- package/dist/index.d.mts +107 -62
- package/dist/index.d.ts +107 -62
- package/dist/index.js +187 -43
- package/dist/index.mjs +196 -42
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @spoosh/react
|
|
2
2
|
|
|
3
|
-
React hooks for Spoosh - `useRead`, `useWrite`, and `useInfiniteRead`.
|
|
3
|
+
React hooks for Spoosh - `useRead`, `useLazyRead`, `useWrite`, and `useInfiniteRead`.
|
|
4
4
|
|
|
5
5
|
**[Documentation](https://spoosh.dev/docs/integrations/react)** · **Requirements:** TypeScript >= 5.0, React >= 18.0
|
|
6
6
|
|
|
@@ -23,7 +23,8 @@ const spoosh = new Spoosh<ApiSchema, Error>("/api").use([
|
|
|
23
23
|
cachePlugin({ staleTime: 5000 }),
|
|
24
24
|
]);
|
|
25
25
|
|
|
26
|
-
export const { useRead, useWrite, useInfiniteRead } =
|
|
26
|
+
export const { useRead, useLazyRead, useWrite, useInfiniteRead } =
|
|
27
|
+
createReactSpoosh(spoosh);
|
|
27
28
|
```
|
|
28
29
|
|
|
29
30
|
### useRead
|
|
@@ -32,7 +33,7 @@ Fetch data with automatic caching and refetching.
|
|
|
32
33
|
|
|
33
34
|
```typescript
|
|
34
35
|
function UserList() {
|
|
35
|
-
const { data, loading, error,
|
|
36
|
+
const { data, loading, error, trigger } = useRead(
|
|
36
37
|
(api) => api("users").GET()
|
|
37
38
|
);
|
|
38
39
|
|
|
@@ -62,6 +63,27 @@ const { data: user } = useRead(
|
|
|
62
63
|
);
|
|
63
64
|
```
|
|
64
65
|
|
|
66
|
+
### useLazyRead
|
|
67
|
+
|
|
68
|
+
Lazy data fetching for print/download/export scenarios. Does not auto-fetch on mount.
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
function PrintOrder() {
|
|
72
|
+
const { trigger, loading } = useLazyRead((api) => api("orders/:id").GET);
|
|
73
|
+
|
|
74
|
+
const handlePrint = async (orderId: string) => {
|
|
75
|
+
const { data } = await trigger({ params: { id: orderId } });
|
|
76
|
+
if (data) printReceipt(data);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<button onClick={() => handlePrint("123")} disabled={loading}>
|
|
81
|
+
{loading ? "Loading..." : "Print"}
|
|
82
|
+
</button>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
65
87
|
### useWrite
|
|
66
88
|
|
|
67
89
|
Trigger mutations with loading and error states.
|
|
@@ -177,7 +199,7 @@ function PostList() {
|
|
|
177
199
|
| `error` | `TError \| undefined` | Error if request failed |
|
|
178
200
|
| `loading` | `boolean` | True during initial load |
|
|
179
201
|
| `fetching` | `boolean` | True during any fetch |
|
|
180
|
-
| `
|
|
202
|
+
| `trigger` | `() => Promise` | Manually trigger fetch |
|
|
181
203
|
| `abort` | `() => void` | Abort current request |
|
|
182
204
|
|
|
183
205
|
### useWrite(writeFn)
|
|
@@ -190,7 +212,6 @@ function PostList() {
|
|
|
190
212
|
| `data` | `TData \| undefined` | Response data |
|
|
191
213
|
| `error` | `TError \| undefined` | Error if request failed |
|
|
192
214
|
| `loading` | `boolean` | True while mutation is in progress |
|
|
193
|
-
| `reset` | `() => void` | Reset state |
|
|
194
215
|
| `abort` | `() => void` | Abort current request |
|
|
195
216
|
|
|
196
217
|
### useInfiniteRead(readFn, options)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ReadClient, TagMode, SpooshResponse, WriteClient, SpooshPlugin, PluginTypeConfig, SpooshOptions, MergePluginResults, StateManager, EventEmitter, PluginExecutor, PluginArray, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
|
|
1
|
+
import { ReadClient, TagMode, SpooshResponse, WriteClient, SpooshPlugin, PluginTypeConfig, SpooshOptions, MergePluginResults, StateManager, EventEmitter, PluginExecutor, PluginArray, ResolveTypes, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
|
|
3
2
|
|
|
4
3
|
type PluginHooksConfig<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
|
|
5
4
|
baseUrl: string;
|
|
@@ -22,15 +21,14 @@ type BaseReadOptions = {
|
|
|
22
21
|
*/
|
|
23
22
|
tags?: TagMode | (TagModeInArray | (string & {}))[];
|
|
24
23
|
};
|
|
25
|
-
|
|
26
24
|
/**
|
|
27
25
|
* Result returned by `useRead` hook.
|
|
28
26
|
*
|
|
29
27
|
* @template TData - The response data type
|
|
30
28
|
* @template TError - The error type
|
|
31
|
-
* @template
|
|
29
|
+
* @template TMeta - Plugin-provided metadata fields
|
|
32
30
|
*/
|
|
33
|
-
type BaseReadResult<TData, TError,
|
|
31
|
+
type BaseReadResult<TData, TError, TMeta = Record<string, unknown>> = {
|
|
34
32
|
/** True during the initial load (no data yet) */
|
|
35
33
|
loading: boolean;
|
|
36
34
|
/** True during any fetch operation */
|
|
@@ -40,11 +38,11 @@ type BaseReadResult<TData, TError, TPluginResult = Record<string, unknown>> = {
|
|
|
40
38
|
/** Error from the last failed request */
|
|
41
39
|
error: TError | undefined;
|
|
42
40
|
/** Plugin-provided metadata */
|
|
43
|
-
meta:
|
|
41
|
+
meta: TMeta;
|
|
44
42
|
/** Abort the current fetch operation */
|
|
45
43
|
abort: () => void;
|
|
46
|
-
/** Manually trigger a
|
|
47
|
-
|
|
44
|
+
/** Manually trigger a fetch */
|
|
45
|
+
trigger: () => Promise<SpooshResponse<TData, TError>>;
|
|
48
46
|
};
|
|
49
47
|
/**
|
|
50
48
|
* Result returned by `useWrite` hook.
|
|
@@ -52,9 +50,9 @@ type BaseReadResult<TData, TError, TPluginResult = Record<string, unknown>> = {
|
|
|
52
50
|
* @template TData - The response data type
|
|
53
51
|
* @template TError - The error type
|
|
54
52
|
* @template TOptions - The trigger options type
|
|
55
|
-
* @template
|
|
53
|
+
* @template TMeta - Plugin-provided metadata fields
|
|
56
54
|
*/
|
|
57
|
-
type BaseWriteResult<TData, TError, TOptions,
|
|
55
|
+
type BaseWriteResult<TData, TError, TOptions, TMeta = Record<string, unknown>> = {
|
|
58
56
|
/** Execute the mutation with optional options */
|
|
59
57
|
trigger: (options?: TOptions) => Promise<SpooshResponse<TData, TError>>;
|
|
60
58
|
/** True while the mutation is in progress */
|
|
@@ -64,12 +62,29 @@ type BaseWriteResult<TData, TError, TOptions, TPluginResult = Record<string, unk
|
|
|
64
62
|
/** Error from the last failed request */
|
|
65
63
|
error: TError | undefined;
|
|
66
64
|
/** Plugin-provided metadata */
|
|
67
|
-
meta:
|
|
68
|
-
/** Reset the state to initial values */
|
|
69
|
-
reset: () => void;
|
|
65
|
+
meta: TMeta;
|
|
70
66
|
/** Abort the current mutation */
|
|
71
67
|
abort: () => void;
|
|
72
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Result returned by `useLazyRead` hook.
|
|
71
|
+
*
|
|
72
|
+
* @template TData - The response data type
|
|
73
|
+
* @template TError - The error type
|
|
74
|
+
* @template TOptions - The trigger options type
|
|
75
|
+
*/
|
|
76
|
+
type BaseLazyReadResult<TData, TError, TOptions> = {
|
|
77
|
+
/** Execute the fetch with optional options */
|
|
78
|
+
trigger: (options?: TOptions) => Promise<SpooshResponse<TData, TError>>;
|
|
79
|
+
/** True while the fetch is in progress */
|
|
80
|
+
loading: boolean;
|
|
81
|
+
/** Response data from the API */
|
|
82
|
+
data: TData | undefined;
|
|
83
|
+
/** Error from the last failed request */
|
|
84
|
+
error: TError | undefined;
|
|
85
|
+
/** Abort the current fetch */
|
|
86
|
+
abort: () => void;
|
|
87
|
+
};
|
|
73
88
|
type OptionalQueryField<TQuery> = [TQuery] extends [never] ? object : undefined extends TQuery ? {
|
|
74
89
|
query?: Exclude<TQuery, undefined>;
|
|
75
90
|
} : {
|
|
@@ -89,8 +104,8 @@ type InputFields<TQuery, TBody, TParamNames extends string> = OptionalQueryField
|
|
|
89
104
|
type WriteResponseInputFields<TQuery, TBody, TParamNames extends string> = [TQuery, TBody, TParamNames] extends [never, never, never] ? object : {
|
|
90
105
|
input: InputFields<TQuery, TBody, TParamNames> | undefined;
|
|
91
106
|
};
|
|
92
|
-
type UseReadResult<TData, TError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = BaseReadResult<TData, TError> & MergePluginResults<TPlugins>["read"];
|
|
93
|
-
type UseWriteResult<TData, TError, TOptions, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = BaseWriteResult<TData, TError, TOptions> & MergePluginResults<TPlugins>["write"];
|
|
107
|
+
type UseReadResult<TData, TError, TMeta, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = BaseReadResult<TData, TError, TMeta> & MergePluginResults<TPlugins>["read"];
|
|
108
|
+
type UseWriteResult<TData, TError, TOptions, TMeta, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = BaseWriteResult<TData, TError, TOptions, TMeta> & MergePluginResults<TPlugins>["write"];
|
|
94
109
|
type ReadApiClient<TSchema, TDefaultError> = ReadClient<TSchema, TDefaultError>;
|
|
95
110
|
type WriteApiClient<TSchema, TDefaultError> = WriteClient<TSchema, TDefaultError>;
|
|
96
111
|
type SuccessResponse<T> = Extract<T, {
|
|
@@ -108,6 +123,7 @@ type ExtractMethodError<T> = T extends (...args: never[]) => infer R ? ErrorResp
|
|
|
108
123
|
error: infer E;
|
|
109
124
|
} ? E : unknown : unknown;
|
|
110
125
|
type ExtractMethodOptions<T> = T extends (...args: infer A) => unknown ? A[0] : never;
|
|
126
|
+
type ExtractCoreMethodOptions<T> = T extends (...args: infer A) => unknown ? A[0] extends object ? Pick<A[0], Extract<keyof A[0], "query" | "params" | "body">> : object : object;
|
|
111
127
|
type ExtractMethodQuery<T> = ExtractMethodOptions<T> extends {
|
|
112
128
|
query: infer Q;
|
|
113
129
|
} ? Q : never;
|
|
@@ -239,8 +255,8 @@ type BaseInfiniteReadResult<TData, TError, TItem, TPluginResult = Record<string,
|
|
|
239
255
|
fetchNext: () => Promise<void>;
|
|
240
256
|
/** Fetch the previous page */
|
|
241
257
|
fetchPrev: () => Promise<void>;
|
|
242
|
-
/**
|
|
243
|
-
|
|
258
|
+
/** Trigger refetch of all pages from the beginning */
|
|
259
|
+
trigger: () => Promise<void>;
|
|
244
260
|
/** Abort the current fetch operation */
|
|
245
261
|
abort: () => void;
|
|
246
262
|
/** Error from the last failed request */
|
|
@@ -250,16 +266,24 @@ type UseInfiniteReadResult<TData, TError, TItem, TPlugins extends readonly Spoos
|
|
|
250
266
|
type InfiniteReadApiClient<TSchema, TDefaultError> = ReadClient<TSchema, TDefaultError>;
|
|
251
267
|
|
|
252
268
|
type InferError<T, TDefaultError> = [T] extends [unknown] ? TDefaultError : T;
|
|
253
|
-
type ExtractParamsRecord<T> = ExtractResponseParamNames<T> extends never ? never : Record<ExtractResponseParamNames<T>, string | number>;
|
|
254
|
-
type ReadResolverContext<TSchema, TReadFn, TDefaultError> = ResolverContext<TSchema, ExtractMethodData<TReadFn>, InferError<ExtractMethodError<TReadFn>, TDefaultError>, ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractParamsRecord<TReadFn>>;
|
|
255
|
-
type ResolvedReadOptions<TSchema, TPlugins extends PluginArray, TReadFn, TDefaultError> = _spoosh_core.ResolveTypes<MergePluginOptions<TPlugins>["read"], ReadResolverContext<TSchema, TReadFn, TDefaultError>>;
|
|
256
269
|
type WriteResolverContext<TSchema, TMethod, TDefaultError> = ResolverContext<TSchema, ExtractMethodData<TMethod>, InferError<ExtractMethodError<TMethod>, TDefaultError>, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>>;
|
|
257
|
-
type ResolvedWriteOptions<TSchema, TPlugins extends PluginArray, TMethod, TDefaultError> =
|
|
258
|
-
type UseReadFn<TDefaultError, TSchema, TPlugins extends PluginArray> =
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
270
|
+
type ResolvedWriteOptions<TSchema, TPlugins extends PluginArray, TMethod, TDefaultError> = ResolveTypes<MergePluginOptions<TPlugins>["write"], WriteResolverContext<TSchema, TMethod, TDefaultError>>;
|
|
271
|
+
type UseReadFn<TDefaultError, TSchema, TPlugins extends PluginArray> = {
|
|
272
|
+
<TReadFn extends (api: ReadApiClient<TSchema, TDefaultError>) => Promise<{
|
|
273
|
+
data?: unknown;
|
|
274
|
+
error?: unknown;
|
|
275
|
+
}>, TReadOpts>(readFn: TReadFn, readOptions: TReadOpts & BaseReadOptions & ResolveTypes<MergePluginOptions<TPlugins>["read"], ResolverContext<TSchema, ExtractMethodData<TReadFn>, InferError<ExtractMethodError<TReadFn>, TDefaultError>, ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseParamNames<TReadFn> extends never ? never : Record<ExtractResponseParamNames<TReadFn>, string | number>>>): BaseReadResult<ExtractMethodData<TReadFn>, InferError<ExtractMethodError<TReadFn>, TDefaultError>, ResolveResultTypes<MergePluginResults<TPlugins>["read"], TReadOpts>> & ResponseInputFields<ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseParamNames<TReadFn>>;
|
|
276
|
+
<TReadFn extends (api: ReadApiClient<TSchema, TDefaultError>) => Promise<{
|
|
277
|
+
data?: unknown;
|
|
278
|
+
error?: unknown;
|
|
279
|
+
}>>(readFn: TReadFn): BaseReadResult<ExtractMethodData<TReadFn>, InferError<ExtractMethodError<TReadFn>, TDefaultError>, MergePluginResults<TPlugins>["read"]> & ResponseInputFields<ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseParamNames<TReadFn>>;
|
|
280
|
+
};
|
|
281
|
+
type UseWriteFn<TDefaultError, TSchema, TPlugins extends PluginArray> = {
|
|
282
|
+
<TMethod extends (...args: never) => Promise<SpooshResponse<unknown, unknown>>>(writeFn: (api: WriteApiClient<TSchema, TDefaultError>) => TMethod): BaseWriteResult<ExtractMethodData<TMethod>, InferError<ExtractMethodError<TMethod>, TDefaultError>, Parameters<TMethod>[0] & ResolvedWriteOptions<TSchema, TPlugins, TMethod, TDefaultError>, MergePluginResults<TPlugins>["write"]> & WriteResponseInputFields<ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod>>;
|
|
283
|
+
};
|
|
284
|
+
type UseLazyReadFn<TDefaultError, TSchema> = {
|
|
285
|
+
<TMethod extends (...args: never) => Promise<SpooshResponse<unknown, unknown>>>(readFn: (api: ReadApiClient<TSchema, TDefaultError>) => TMethod): BaseLazyReadResult<ExtractMethodData<TMethod>, InferError<ExtractMethodError<TMethod>, TDefaultError>, ExtractCoreMethodOptions<TMethod>> & WriteResponseInputFields<ExtractResponseQuery<TMethod>, ExtractResponseBody<TMethod>, ExtractResponseParamNames<TMethod>>;
|
|
286
|
+
};
|
|
263
287
|
type InfiniteReadResolverContext<TSchema, TData, TError, TRequest> = ResolverContext<TSchema, TData, TError, TRequest extends {
|
|
264
288
|
query: infer Q;
|
|
265
289
|
} ? Q : never, TRequest extends {
|
|
@@ -267,7 +291,7 @@ type InfiniteReadResolverContext<TSchema, TData, TError, TRequest> = ResolverCon
|
|
|
267
291
|
} ? B : never, TRequest extends {
|
|
268
292
|
params: infer P;
|
|
269
293
|
} ? P : never>;
|
|
270
|
-
type ResolvedInfiniteReadOptions<TSchema, TPlugins extends PluginArray, TData, TError, TRequest> =
|
|
294
|
+
type ResolvedInfiniteReadOptions<TSchema, TPlugins extends PluginArray, TData, TError, TRequest> = ResolveTypes<MergePluginOptions<TPlugins>["infiniteRead"], InfiniteReadResolverContext<TSchema, TData, TError, TRequest>>;
|
|
271
295
|
type UseInfiniteReadFn<TDefaultError, TSchema, TPlugins extends PluginArray> = <TData, TItem, TError = TDefaultError, TRequest extends AnyInfiniteRequestOptions = AnyInfiniteRequestOptions>(readFn: (api: InfiniteReadApiClient<TSchema, TDefaultError>) => Promise<SpooshResponse<TData, TError>>, readOptions: BaseInfiniteReadOptions<TData, TItem, TRequest> & ResolvedInfiniteReadOptions<TSchema, TPlugins, TData, TError, TRequest>) => BaseInfiniteReadResult<TData, TError, TItem, MergePluginResults<TPlugins>["read"]>;
|
|
272
296
|
/**
|
|
273
297
|
* Spoosh React hooks interface containing useRead, useWrite, and useInfiniteRead.
|
|
@@ -282,7 +306,7 @@ type SpooshReactHooks<TDefaultError, TSchema, TPlugins extends PluginArray> = {
|
|
|
282
306
|
*
|
|
283
307
|
* @param readFn - Function that selects the API endpoint to call (e.g., `(api) => api("posts").GET()`)
|
|
284
308
|
* @param readOptions - Optional configuration including `enabled`, `tags`, and plugin-specific options
|
|
285
|
-
* @returns Object containing `data`, `error`, `loading`, `fetching`, `
|
|
309
|
+
* @returns Object containing `data`, `error`, `loading`, `fetching`, `trigger`, and `abort`
|
|
286
310
|
*
|
|
287
311
|
* @example
|
|
288
312
|
* ```tsx
|
|
@@ -299,7 +323,7 @@ type SpooshReactHooks<TDefaultError, TSchema, TPlugins extends PluginArray> = {
|
|
|
299
323
|
* React hook for mutations (POST, PUT, PATCH, DELETE) with manual triggering.
|
|
300
324
|
*
|
|
301
325
|
* @param writeFn - Function that selects the API endpoint (e.g., `(api) => api("posts").POST`)
|
|
302
|
-
* @returns Object containing `trigger`, `data`, `error`, `loading`,
|
|
326
|
+
* @returns Object containing `trigger`, `data`, `error`, `loading`, and `abort`
|
|
303
327
|
*
|
|
304
328
|
* @example
|
|
305
329
|
* ```tsx
|
|
@@ -312,6 +336,23 @@ type SpooshReactHooks<TDefaultError, TSchema, TPlugins extends PluginArray> = {
|
|
|
312
336
|
* ```
|
|
313
337
|
*/
|
|
314
338
|
useWrite: UseWriteFn<TDefaultError, TSchema, TPlugins>;
|
|
339
|
+
/**
|
|
340
|
+
* React hook for lazy GET requests with manual triggering (does not auto-fetch on mount).
|
|
341
|
+
*
|
|
342
|
+
* @param readFn - Function that selects the API endpoint (e.g., `(api) => api("posts").GET`)
|
|
343
|
+
* @returns Object containing `trigger`, `data`, `error`, `loading`, and `abort`
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```tsx
|
|
347
|
+
* const { trigger, loading, data } = useLazyRead((api) => api("posts/:id").GET);
|
|
348
|
+
*
|
|
349
|
+
* const handleClick = async (id) => {
|
|
350
|
+
* const { data, error } = await trigger({ params: { id } });
|
|
351
|
+
* if (data) console.log('Fetched:', data);
|
|
352
|
+
* };
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
useLazyRead: UseLazyReadFn<TDefaultError, TSchema>;
|
|
315
356
|
/**
|
|
316
357
|
* React hook for infinite/paginated data fetching with automatic pagination control.
|
|
317
358
|
*
|
|
@@ -375,42 +416,46 @@ type SpooshInstanceShape<TApi, TSchema, TDefaultError, TPlugins> = {
|
|
|
375
416
|
*/
|
|
376
417
|
declare function createReactSpoosh<TSchema, TDefaultError, TPlugins extends PluginArray, TApi>(instance: SpooshInstanceShape<TApi, TSchema, TDefaultError, TPlugins>): SpooshReactHooks<TDefaultError, TSchema, TPlugins>;
|
|
377
418
|
|
|
378
|
-
declare function createUseRead<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">):
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
readOptions: infer
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
419
|
+
declare function createUseRead<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">): {
|
|
420
|
+
<TReadFn extends (api: ReadApiClient<TSchema, TDefaultError>) => Promise<{
|
|
421
|
+
data?: unknown;
|
|
422
|
+
error?: unknown;
|
|
423
|
+
}>, TReadOpts>(readFn: TReadFn, readOptions: TReadOpts & BaseReadOptions & ResolveTypes<((TPlugins[number] extends infer T ? T extends TPlugins[number] ? T extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
|
|
424
|
+
readOptions: infer R;
|
|
425
|
+
} ? R : object : object : never : never) extends infer T_1 ? T_1 extends (TPlugins[number] extends infer T_2 ? T_2 extends TPlugins[number] ? T_2 extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
|
|
426
|
+
readOptions: infer R;
|
|
427
|
+
} ? R : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, ResolverContext<TSchema, TReadFn extends (...args: unknown[]) => Promise<{
|
|
428
|
+
data: infer D;
|
|
429
|
+
}> ? D : unknown, [TReadFn extends (...args: unknown[]) => Promise<{
|
|
430
|
+
error: infer E;
|
|
431
|
+
}> ? E : unknown] extends [unknown] ? TDefaultError : TReadFn extends (...args: unknown[]) => Promise<{
|
|
432
|
+
error: infer E;
|
|
433
|
+
}> ? E : unknown, ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseParamNames<TReadFn> extends never ? never : Record<ExtractResponseParamNames<TReadFn>, string | number>>>): BaseReadResult<TReadFn extends (...args: unknown[]) => Promise<{
|
|
434
|
+
data: infer D;
|
|
435
|
+
}> ? D : unknown, [TReadFn extends (...args: unknown[]) => Promise<{
|
|
436
|
+
error: infer E;
|
|
437
|
+
}> ? E : unknown] extends [unknown] ? TDefaultError : TReadFn extends (...args: unknown[]) => Promise<{
|
|
438
|
+
error: infer E;
|
|
439
|
+
}> ? E : unknown, ResolveResultTypes<MergePluginResults<TPlugins>["read"], TReadOpts>> & ResponseInputFields<ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseParamNames<TReadFn>>;
|
|
440
|
+
<TReadFn extends (api: ReadApiClient<TSchema, TDefaultError>) => Promise<{
|
|
441
|
+
data?: unknown;
|
|
442
|
+
error?: unknown;
|
|
443
|
+
}>>(readFn: TReadFn): BaseReadResult<TReadFn extends (...args: unknown[]) => Promise<{
|
|
444
|
+
data: infer D;
|
|
445
|
+
}> ? D : unknown, [TReadFn extends (...args: unknown[]) => Promise<{
|
|
446
|
+
error: infer E;
|
|
447
|
+
}> ? E : unknown] extends [unknown] ? TDefaultError : TReadFn extends (...args: unknown[]) => Promise<{
|
|
448
|
+
error: infer E;
|
|
449
|
+
}> ? E : unknown, MergePluginResults<TPlugins>["read"]> & ResponseInputFields<ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseParamNames<TReadFn>>;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
declare function createUseLazyRead<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">): <TMethod extends (...args: never[]) => Promise<SpooshResponse<unknown, unknown>>>(readFn: (api: ReadApiClient<TSchema, TDefaultError>) => TMethod) => BaseLazyReadResult<ExtractMethodData<TMethod>, [ExtractMethodError<TMethod>] extends [unknown] ? TDefaultError : ExtractMethodError<TMethod>, ExtractCoreMethodOptions<TMethod>> & WriteResponseInputFields<ExtractResponseQuery<TMethod>, ExtractResponseBody<TMethod>, ExtractResponseParamNames<TMethod>>;
|
|
400
453
|
|
|
401
|
-
declare function createUseWrite<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">): <TMethod extends (...args: never[]) => Promise<SpooshResponse<unknown, unknown>>>(writeFn: (api: WriteApiClient<TSchema, TDefaultError>) => TMethod) => BaseWriteResult<ExtractMethodData<TMethod>, [ExtractMethodError<TMethod>] extends [unknown] ? TDefaultError : ExtractMethodError<TMethod>, ExtractMethodOptions<TMethod> &
|
|
454
|
+
declare function createUseWrite<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">): <TMethod extends (...args: never[]) => Promise<SpooshResponse<unknown, unknown>>>(writeFn: (api: WriteApiClient<TSchema, TDefaultError>) => TMethod) => BaseWriteResult<ExtractMethodData<TMethod>, [ExtractMethodError<TMethod>] extends [unknown] ? TDefaultError : ExtractMethodError<TMethod>, ExtractMethodOptions<TMethod> & ResolveTypes<((TPlugins[number] extends infer T ? T extends TPlugins[number] ? T extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
|
|
402
455
|
writeOptions: infer W;
|
|
403
456
|
} ? W : object : object : never : never) extends infer T_1 ? T_1 extends (TPlugins[number] extends infer T_2 ? T_2 extends TPlugins[number] ? T_2 extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
|
|
404
457
|
writeOptions: infer W;
|
|
405
|
-
} ? W : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, ResolverContext<TSchema, ExtractMethodData<TMethod>, [ExtractMethodError<TMethod>] extends [unknown] ? TDefaultError : ExtractMethodError<TMethod>, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>>>,
|
|
406
|
-
writeResult: infer W_1;
|
|
407
|
-
} ? W_1 : object : object : never : never) extends infer T_4 ? T_4 extends (TPlugins[number] extends infer T_5 ? T_5 extends TPlugins[number] ? T_5 extends SpooshPlugin<infer Types_1 extends PluginTypeConfig> ? Types_1 extends {
|
|
408
|
-
writeResult: infer W_1;
|
|
409
|
-
} ? W_1 : object : object : never : never) ? T_4 extends unknown ? (x: T_4) => void : never : never : never) extends (x: infer I) => void ? I : never, ExtractMethodOptions<TMethod> & _spoosh_core.ResolveTypes<((TPlugins[number] extends infer T_6 ? T_6 extends TPlugins[number] ? T_6 extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
|
|
410
|
-
writeOptions: infer W;
|
|
411
|
-
} ? W : object : object : never : never) extends infer T_7 ? T_7 extends (TPlugins[number] extends infer T_8 ? T_8 extends TPlugins[number] ? T_8 extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
|
|
412
|
-
writeOptions: infer W;
|
|
413
|
-
} ? W : object : object : never : never) ? T_7 extends unknown ? (x: T_7) => void : never : never : never) extends (x: infer I) => void ? I : never, ResolverContext<TSchema, ExtractMethodData<TMethod>, [ExtractMethodError<TMethod>] extends [unknown] ? TDefaultError : ExtractMethodError<TMethod>, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>>>>> & WriteResponseInputFields<ExtractResponseQuery<TMethod>, ExtractResponseBody<TMethod>, ExtractResponseParamNames<TMethod>>;
|
|
458
|
+
} ? W : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, ResolverContext<TSchema, ExtractMethodData<TMethod>, [ExtractMethodError<TMethod>] extends [unknown] ? TDefaultError : ExtractMethodError<TMethod>, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>>>, MergePluginResults<TPlugins>["write"]> & WriteResponseInputFields<ExtractResponseQuery<TMethod>, ExtractResponseBody<TMethod>, ExtractResponseParamNames<TMethod>>;
|
|
414
459
|
|
|
415
460
|
declare function createUseInfiniteRead<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">): <TData, TItem, TError = TDefaultError, TRequest extends AnyInfiniteRequestOptions = AnyInfiniteRequestOptions>(readFn: (api: InfiniteReadApiClient<TSchema, TDefaultError>) => Promise<SpooshResponse<TData, TError>>, readOptions: BaseInfiniteReadOptions<TData, TItem, TRequest> & (((TPlugins[number] extends infer T_3 ? T_3 extends TPlugins[number] ? T_3 extends SpooshPlugin<infer Types_1 extends PluginTypeConfig> ? Types_1 extends {
|
|
416
461
|
infiniteReadOptions: infer I_1;
|
|
@@ -422,4 +467,4 @@ declare function createUseInfiniteRead<TSchema, TDefaultError, TPlugins extends
|
|
|
422
467
|
readResult: infer R;
|
|
423
468
|
} ? R : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never>;
|
|
424
469
|
|
|
425
|
-
export { type BaseInfiniteReadOptions, type BaseInfiniteReadResult, type BaseReadOptions, type BaseReadResult, type BaseWriteResult, type PluginHooksConfig, type SpooshReactHooks, type UseInfiniteReadResult, type UseReadResult, type UseWriteResult, createReactSpoosh, createUseInfiniteRead, createUseRead, createUseWrite };
|
|
470
|
+
export { type BaseInfiniteReadOptions, type BaseInfiniteReadResult, type BaseLazyReadResult, type BaseReadOptions, type BaseReadResult, type BaseWriteResult, type PluginHooksConfig, type SpooshReactHooks, type UseInfiniteReadResult, type UseReadResult, type UseWriteResult, createReactSpoosh, createUseInfiniteRead, createUseLazyRead, createUseRead, createUseWrite };
|