@spoosh/core 0.14.1 → 0.15.1
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.mts +162 -36
- package/dist/index.d.ts +162 -36
- package/dist/index.js +199 -159
- package/dist/index.mjs +199 -159
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -215,7 +215,6 @@ type CacheEntryWithKey<TData = unknown, TError = unknown> = {
|
|
|
215
215
|
key: string;
|
|
216
216
|
entry: CacheEntry<TData, TError>;
|
|
217
217
|
};
|
|
218
|
-
declare function createInitialState<TData, TError>(): OperationState<TData, TError>;
|
|
219
218
|
type StateManager = {
|
|
220
219
|
createQueryKey: (params: {
|
|
221
220
|
path: string;
|
|
@@ -249,8 +248,11 @@ type StateManager = {
|
|
|
249
248
|
onDataChange: (callback: DataChangeCallback) => () => void;
|
|
250
249
|
clear: () => void;
|
|
251
250
|
};
|
|
251
|
+
|
|
252
252
|
declare function createStateManager(): StateManager;
|
|
253
253
|
|
|
254
|
+
declare function createInitialState<TData, TError>(): OperationState<TData, TError>;
|
|
255
|
+
|
|
254
256
|
/**
|
|
255
257
|
* Devtool-related types for tracing and debugging.
|
|
256
258
|
* These types are used by the devtool plugin and plugins that emit trace events.
|
|
@@ -435,7 +437,7 @@ interface EventTracer {
|
|
|
435
437
|
emit(msg: string, options?: EventOptions): void;
|
|
436
438
|
}
|
|
437
439
|
|
|
438
|
-
type OperationType = "read" | "write" | "
|
|
440
|
+
type OperationType = "read" | "write" | "pages" | "queue";
|
|
439
441
|
type LifecyclePhase = "onMount" | "onUnmount" | "onUpdate";
|
|
440
442
|
type OperationState<TData = unknown, TError = unknown> = {
|
|
441
443
|
data: TData | undefined;
|
|
@@ -492,7 +494,7 @@ type PluginContextBase = {
|
|
|
492
494
|
eventEmitter: EventEmitter;
|
|
493
495
|
/** Access other plugins' exported APIs */
|
|
494
496
|
plugins: PluginAccessor;
|
|
495
|
-
/** Plugin-specific options passed from hooks (useRead/useWrite/
|
|
497
|
+
/** Plugin-specific options passed from hooks (useRead/useWrite/usePages) */
|
|
496
498
|
pluginOptions?: unknown;
|
|
497
499
|
/** Force a network request even if cached data exists. Used by plugins to communicate intent. */
|
|
498
500
|
forceRefetch?: boolean;
|
|
@@ -598,7 +600,7 @@ type PluginLifecycle = {
|
|
|
598
600
|
type PluginTypeConfig = {
|
|
599
601
|
readOptions?: object;
|
|
600
602
|
writeOptions?: object;
|
|
601
|
-
|
|
603
|
+
pagesOptions?: object;
|
|
602
604
|
writeTriggerOptions?: object;
|
|
603
605
|
queueOptions?: object;
|
|
604
606
|
queueTriggerOptions?: object;
|
|
@@ -1027,8 +1029,8 @@ type ExtractReadOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends
|
|
|
1027
1029
|
type ExtractWriteOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
|
|
1028
1030
|
writeOptions: infer W;
|
|
1029
1031
|
} ? W : object : object;
|
|
1030
|
-
type
|
|
1031
|
-
|
|
1032
|
+
type ExtractPagesOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
|
|
1033
|
+
pagesOptions: infer I;
|
|
1032
1034
|
} ? I : object : object;
|
|
1033
1035
|
type ExtractWriteTriggerOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
|
|
1034
1036
|
writeTriggerOptions: infer W;
|
|
@@ -1051,21 +1053,21 @@ type ExtractWriteResult<T> = T extends SpooshPlugin<infer Types> ? Types extends
|
|
|
1051
1053
|
type ExtractInstanceApi<T> = T extends SpooshPlugin<infer Types> ? Types extends {
|
|
1052
1054
|
instanceApi: infer A;
|
|
1053
1055
|
} ? A : object : object;
|
|
1054
|
-
type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
1056
|
+
type UnionToIntersection$1<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
1055
1057
|
type MergePluginOptions<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
|
|
1056
|
-
read: UnionToIntersection<ExtractReadOptions<TPlugins[number]>>;
|
|
1057
|
-
write: UnionToIntersection<ExtractWriteOptions<TPlugins[number]>>;
|
|
1058
|
-
|
|
1059
|
-
writeTrigger: UnionToIntersection<ExtractWriteTriggerOptions<TPlugins[number]>>;
|
|
1060
|
-
queue: UnionToIntersection<ExtractQueueOptions<TPlugins[number]>>;
|
|
1061
|
-
queueTrigger: UnionToIntersection<ExtractQueueTriggerOptions<TPlugins[number]>>;
|
|
1058
|
+
read: UnionToIntersection$1<ExtractReadOptions<TPlugins[number]>>;
|
|
1059
|
+
write: UnionToIntersection$1<ExtractWriteOptions<TPlugins[number]>>;
|
|
1060
|
+
pages: UnionToIntersection$1<ExtractPagesOptions<TPlugins[number]>>;
|
|
1061
|
+
writeTrigger: UnionToIntersection$1<ExtractWriteTriggerOptions<TPlugins[number]>>;
|
|
1062
|
+
queue: UnionToIntersection$1<ExtractQueueOptions<TPlugins[number]>>;
|
|
1063
|
+
queueTrigger: UnionToIntersection$1<ExtractQueueTriggerOptions<TPlugins[number]>>;
|
|
1062
1064
|
};
|
|
1063
1065
|
type MergePluginResults<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
|
|
1064
|
-
read: UnionToIntersection<ExtractReadResult<TPlugins[number]>>;
|
|
1065
|
-
write: UnionToIntersection<ExtractWriteResult<TPlugins[number]>>;
|
|
1066
|
-
queue: UnionToIntersection<ExtractQueueResult<TPlugins[number]>>;
|
|
1066
|
+
read: UnionToIntersection$1<ExtractReadResult<TPlugins[number]>>;
|
|
1067
|
+
write: UnionToIntersection$1<ExtractWriteResult<TPlugins[number]>>;
|
|
1068
|
+
queue: UnionToIntersection$1<ExtractQueueResult<TPlugins[number]>>;
|
|
1067
1069
|
};
|
|
1068
|
-
type MergePluginInstanceApi<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[], TSchema = unknown> = ResolveInstanceApi<UnionToIntersection<ExtractInstanceApi<TPlugins[number]>>, TSchema, MergePluginOptions<TPlugins>["read"]>;
|
|
1070
|
+
type MergePluginInstanceApi<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[], TSchema = unknown> = ResolveInstanceApi<UnionToIntersection$1<ExtractInstanceApi<TPlugins[number]>>, TSchema, MergePluginOptions<TPlugins>["read"]>;
|
|
1069
1071
|
type PluginRegistry<TPlugins extends SpooshPlugin<PluginTypeConfig>[]> = {
|
|
1070
1072
|
plugins: TPlugins;
|
|
1071
1073
|
_options: MergePluginOptions<TPlugins>;
|
|
@@ -1309,12 +1311,103 @@ type WritePathMethods$1<TSchema, TPath extends string> = FindMatchingKey<TSchema
|
|
|
1309
1311
|
*/
|
|
1310
1312
|
type WriteSchemaHelper<TSchema> = <TPath extends WritePaths<TSchema> | (string & {})>(path: TPath) => HasWriteMethod<TSchema, TPath> extends true ? WritePathMethods$1<TSchema, TPath> : never;
|
|
1311
1313
|
|
|
1314
|
+
/**
|
|
1315
|
+
* Check for exact type equality using function type assignability.
|
|
1316
|
+
* Two types are equal if functions returning them are mutually assignable.
|
|
1317
|
+
*/
|
|
1318
|
+
type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
1319
|
+
/**
|
|
1320
|
+
* Convert bare `object` type to `never` to exclude it from the union.
|
|
1321
|
+
* Preserves all other types including interfaces and types with actual properties.
|
|
1322
|
+
*/
|
|
1323
|
+
type FilterObjectType<T> = Equals<T, object> extends true ? never : T;
|
|
1324
|
+
/**
|
|
1325
|
+
* Convert a union type to an intersection type.
|
|
1326
|
+
* This merges all properties from all types in the union.
|
|
1327
|
+
*/
|
|
1328
|
+
type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
1329
|
+
/**
|
|
1330
|
+
* Extract all option types from plugin configuration and create a union, then intersect.
|
|
1331
|
+
* This allows middleware to access all properties from all option types.
|
|
1332
|
+
* object types are converted to unknown which doesn't affect the intersection.
|
|
1333
|
+
*/
|
|
1334
|
+
type ExtractPluginOptionsUnion<T extends PluginTypeConfig> = UnionToIntersection<FilterObjectType<T extends {
|
|
1335
|
+
readOptions: infer R;
|
|
1336
|
+
} ? R : never> | FilterObjectType<T extends {
|
|
1337
|
+
writeOptions: infer W;
|
|
1338
|
+
} ? W : never> | FilterObjectType<T extends {
|
|
1339
|
+
writeTriggerOptions: infer WT;
|
|
1340
|
+
} ? WT : never> | FilterObjectType<T extends {
|
|
1341
|
+
queueTriggerOptions: infer QT;
|
|
1342
|
+
} ? QT : never> | FilterObjectType<T extends {
|
|
1343
|
+
pagesOptions: infer P;
|
|
1344
|
+
} ? P : never> | FilterObjectType<T extends {
|
|
1345
|
+
queueOptions: infer Q;
|
|
1346
|
+
} ? Q : never>>;
|
|
1347
|
+
/**
|
|
1348
|
+
* Plugin context with typed pluginOptions based on plugin configuration.
|
|
1349
|
+
*/
|
|
1350
|
+
type TypedPluginContext<T extends PluginTypeConfig> = Omit<PluginContext, "pluginOptions"> & {
|
|
1351
|
+
pluginOptions?: ExtractPluginOptionsUnion<T>;
|
|
1352
|
+
};
|
|
1353
|
+
/**
|
|
1354
|
+
* Plugin definition with typed context for middleware and handlers.
|
|
1355
|
+
*/
|
|
1356
|
+
type TypedPluginDefinition<T extends PluginTypeConfig> = Omit<SpooshPlugin<T>, "middleware" | "afterResponse" | "lifecycle"> & {
|
|
1357
|
+
middleware?: (context: TypedPluginContext<T>, next: () => Promise<any>) => Promise<any>;
|
|
1358
|
+
afterResponse?: (context: TypedPluginContext<T>, response: any) => any;
|
|
1359
|
+
lifecycle?: {
|
|
1360
|
+
onMount?: (context: TypedPluginContext<T>) => void | Promise<void>;
|
|
1361
|
+
onUpdate?: (context: TypedPluginContext<T>, previousContext: TypedPluginContext<T>) => void | Promise<void>;
|
|
1362
|
+
onUnmount?: (context: TypedPluginContext<T>) => void | Promise<void>;
|
|
1363
|
+
};
|
|
1364
|
+
};
|
|
1365
|
+
/**
|
|
1366
|
+
* Helper to create a Spoosh plugin with automatic type inference for plugin options.
|
|
1367
|
+
*
|
|
1368
|
+
* This eliminates the need for manual type assertions in middleware by automatically
|
|
1369
|
+
* intersecting all option types, making all properties accessible:
|
|
1370
|
+
*
|
|
1371
|
+
* ```ts
|
|
1372
|
+
* // Before:
|
|
1373
|
+
* const pluginOptions = context.pluginOptions as CacheReadOptions | undefined;
|
|
1374
|
+
* const staleTime = pluginOptions?.staleTime ?? defaultStaleTime;
|
|
1375
|
+
*
|
|
1376
|
+
* // After (with createSpooshPlugin):
|
|
1377
|
+
* const staleTime = context.pluginOptions?.staleTime ?? defaultStaleTime;
|
|
1378
|
+
* ```
|
|
1379
|
+
*
|
|
1380
|
+
* @typeParam T - Plugin type configuration (readOptions, writeOptions, etc.)
|
|
1381
|
+
* @param definition - Plugin definition with typed context
|
|
1382
|
+
* @returns Typed Spoosh plugin
|
|
1383
|
+
*
|
|
1384
|
+
* @example
|
|
1385
|
+
* ```ts
|
|
1386
|
+
* export const cachePlugin = (config: CachePluginConfig = {}) =>
|
|
1387
|
+
* createSpooshPlugin<{
|
|
1388
|
+
* readOptions: CacheReadOptions;
|
|
1389
|
+
* writeOptions: CacheWriteOptions;
|
|
1390
|
+
* pagesOptions: CachePagesOptions;
|
|
1391
|
+
* }>({
|
|
1392
|
+
* name: "spoosh:cache",
|
|
1393
|
+
* operations: ["read", "write", "pages"],
|
|
1394
|
+
* middleware: async (context, next) => {
|
|
1395
|
+
* // context.pluginOptions is automatically typed as an intersection:
|
|
1396
|
+
* // CacheReadOptions & CachePagesOptions (CacheWriteOptions filtered as it's just 'object')
|
|
1397
|
+
* // All properties from all option types are accessible:
|
|
1398
|
+
* const staleTime = context.pluginOptions?.staleTime ?? defaultStaleTime;
|
|
1399
|
+
* return next();
|
|
1400
|
+
* },
|
|
1401
|
+
* });
|
|
1402
|
+
* ```
|
|
1403
|
+
*/
|
|
1404
|
+
declare function createSpooshPlugin<T extends PluginTypeConfig>(definition: TypedPluginDefinition<T>): SpooshPlugin<T>;
|
|
1405
|
+
|
|
1312
1406
|
/**
|
|
1313
1407
|
* Base request options available on all methods.
|
|
1314
1408
|
*/
|
|
1315
1409
|
type BaseRequestOptions = {
|
|
1316
1410
|
headers?: HeadersInitOrGetter;
|
|
1317
|
-
cache?: RequestCache;
|
|
1318
1411
|
signal?: AbortSignal;
|
|
1319
1412
|
};
|
|
1320
1413
|
/**
|
|
@@ -1490,6 +1583,22 @@ type SpooshInstance<TSchema = unknown, TDefaultError = unknown, TPlugins extends
|
|
|
1490
1583
|
};
|
|
1491
1584
|
};
|
|
1492
1585
|
|
|
1586
|
+
type ExtractTriggerQuery<I> = I extends {
|
|
1587
|
+
query: infer Q;
|
|
1588
|
+
} ? {
|
|
1589
|
+
query?: Q;
|
|
1590
|
+
} : unknown;
|
|
1591
|
+
type ExtractTriggerBody<I> = I extends {
|
|
1592
|
+
body: infer B;
|
|
1593
|
+
} ? {
|
|
1594
|
+
body?: B;
|
|
1595
|
+
} : unknown;
|
|
1596
|
+
type ExtractTriggerParams<I> = I extends {
|
|
1597
|
+
params: infer P;
|
|
1598
|
+
} ? {
|
|
1599
|
+
params?: P;
|
|
1600
|
+
} : unknown;
|
|
1601
|
+
|
|
1493
1602
|
/**
|
|
1494
1603
|
* Class-based builder for creating Spoosh instances with type-safe plugin inference.
|
|
1495
1604
|
*
|
|
@@ -2001,6 +2110,7 @@ type CreateOperationOptions<TData, TError> = {
|
|
|
2001
2110
|
/** Unique identifier for the hook instance. Persists across queryKey changes. */
|
|
2002
2111
|
instanceId?: string;
|
|
2003
2112
|
};
|
|
2113
|
+
|
|
2004
2114
|
declare function createOperationController<TData, TError>(options: CreateOperationOptions<TData, TError>): OperationController<TData, TError>;
|
|
2005
2115
|
|
|
2006
2116
|
type InfiniteRequestOptions = {
|
|
@@ -2008,27 +2118,43 @@ type InfiniteRequestOptions = {
|
|
|
2008
2118
|
params?: Record<string, string | number>;
|
|
2009
2119
|
body?: unknown;
|
|
2010
2120
|
};
|
|
2011
|
-
type
|
|
2012
|
-
|
|
2013
|
-
|
|
2121
|
+
type InfinitePageStatus = "pending" | "loading" | "success" | "error" | "stale";
|
|
2122
|
+
interface InfinitePage<TData, TError, TMeta> {
|
|
2123
|
+
status: InfinitePageStatus;
|
|
2124
|
+
data?: TData;
|
|
2125
|
+
error?: TError;
|
|
2126
|
+
meta?: TMeta;
|
|
2127
|
+
input?: InfiniteRequestOptions;
|
|
2128
|
+
}
|
|
2129
|
+
type InfiniteNextContext<TData, TError, TRequest, TMeta> = {
|
|
2130
|
+
lastPage: InfinitePage<TData, TError, TMeta> | undefined;
|
|
2131
|
+
pages: InfinitePage<TData, TError, TMeta>[];
|
|
2132
|
+
request: TRequest;
|
|
2133
|
+
};
|
|
2134
|
+
type InfinitePrevContext<TData, TError, TRequest, TMeta> = {
|
|
2135
|
+
firstPage: InfinitePage<TData, TError, TMeta> | undefined;
|
|
2136
|
+
pages: InfinitePage<TData, TError, TMeta>[];
|
|
2014
2137
|
request: TRequest;
|
|
2015
2138
|
};
|
|
2016
2139
|
type FetchDirection = "next" | "prev";
|
|
2017
|
-
type
|
|
2140
|
+
type InfiniteTriggerOptions = Partial<InfiniteRequestOptions> & {
|
|
2141
|
+
/** Bypass cache and force refetch. Default: true */
|
|
2142
|
+
force?: boolean;
|
|
2143
|
+
};
|
|
2144
|
+
type InfiniteReadState<TData, TItem, TError, TMeta = Record<string, unknown>> = {
|
|
2018
2145
|
data: TItem[] | undefined;
|
|
2019
|
-
|
|
2020
|
-
allRequests: InfiniteRequestOptions[] | undefined;
|
|
2146
|
+
pages: InfinitePage<TData, TError, TMeta>[];
|
|
2021
2147
|
canFetchNext: boolean;
|
|
2022
2148
|
canFetchPrev: boolean;
|
|
2023
2149
|
error: TError | undefined;
|
|
2024
2150
|
};
|
|
2025
|
-
type InfiniteReadController<TData, TItem, TError
|
|
2026
|
-
getState: () => InfiniteReadState<TData, TItem, TError>;
|
|
2151
|
+
type InfiniteReadController<TData, TItem, TError, TMeta = Record<string, unknown>> = {
|
|
2152
|
+
getState: () => InfiniteReadState<TData, TItem, TError, TMeta>;
|
|
2027
2153
|
getFetchingDirection: () => FetchDirection | null;
|
|
2028
2154
|
subscribe: (callback: () => void) => () => void;
|
|
2029
2155
|
fetchNext: () => Promise<void>;
|
|
2030
2156
|
fetchPrev: () => Promise<void>;
|
|
2031
|
-
|
|
2157
|
+
trigger: (options?: InfiniteTriggerOptions) => Promise<void>;
|
|
2032
2158
|
abort: () => void;
|
|
2033
2159
|
mount: () => void;
|
|
2034
2160
|
unmount: () => void;
|
|
@@ -2036,17 +2162,16 @@ type InfiniteReadController<TData, TItem, TError> = {
|
|
|
2036
2162
|
getContext: () => PluginContext;
|
|
2037
2163
|
setPluginOptions: (options: unknown) => void;
|
|
2038
2164
|
};
|
|
2039
|
-
type CreateInfiniteReadOptions<TData, TItem, TError, TRequest
|
|
2165
|
+
type CreateInfiniteReadOptions<TData, TItem, TError, TRequest, TMeta = Record<string, unknown>> = {
|
|
2040
2166
|
path: string;
|
|
2041
2167
|
method: HttpMethod;
|
|
2042
2168
|
tags: string[];
|
|
2043
2169
|
initialRequest: InfiniteRequestOptions;
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
merger: (responses: TData[]) => TItem[];
|
|
2170
|
+
canFetchNext?: (ctx: InfiniteNextContext<TData, TError, TRequest, TMeta>) => boolean;
|
|
2171
|
+
canFetchPrev?: (ctx: InfinitePrevContext<TData, TError, TRequest, TMeta>) => boolean;
|
|
2172
|
+
nextPageRequest?: (ctx: InfiniteNextContext<TData, TError, TRequest, TMeta>) => Partial<TRequest>;
|
|
2173
|
+
prevPageRequest?: (ctx: InfinitePrevContext<TData, TError, TRequest, TMeta>) => Partial<TRequest>;
|
|
2174
|
+
merger: (pages: InfinitePage<TData, TError, TMeta>[]) => TItem[];
|
|
2050
2175
|
stateManager: StateManager;
|
|
2051
2176
|
eventEmitter: EventEmitter;
|
|
2052
2177
|
pluginExecutor: PluginExecutor;
|
|
@@ -2054,7 +2179,8 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
|
|
|
2054
2179
|
/** Unique identifier for the hook instance. Persists across queryKey changes. */
|
|
2055
2180
|
instanceId?: string;
|
|
2056
2181
|
};
|
|
2057
|
-
|
|
2182
|
+
|
|
2183
|
+
declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions, TMeta = Record<string, unknown>>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest, TMeta>): InfiniteReadController<TData, TItem, TError, TMeta>;
|
|
2058
2184
|
|
|
2059
2185
|
/**
|
|
2060
2186
|
* Status of an item in the queue.
|
|
@@ -2177,4 +2303,4 @@ declare class Semaphore {
|
|
|
2177
2303
|
getWaitingCount(): number;
|
|
2178
2304
|
}
|
|
2179
2305
|
|
|
2180
|
-
export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type
|
|
2306
|
+
export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DataChangeCallback, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExecuteOptions, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type ExtractTriggerBody, type ExtractTriggerParams, type ExtractTriggerQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteNextContext, type InfinitePage, type InfinitePageStatus, type InfinitePrevContext, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InfiniteTriggerOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueueController, type QueueControllerConfig, type QueueControllerContext, type QueueItem, type QueueItemStatus, type QueueSelectorClient, type QueueStats, type QueueTriggerInput, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Semaphore, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type Subscriber, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type TypedPluginContext, type TypedPluginDefinition, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, createSpooshPlugin, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, removeHeaderKeys, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
|
package/dist/index.d.ts
CHANGED
|
@@ -215,7 +215,6 @@ type CacheEntryWithKey<TData = unknown, TError = unknown> = {
|
|
|
215
215
|
key: string;
|
|
216
216
|
entry: CacheEntry<TData, TError>;
|
|
217
217
|
};
|
|
218
|
-
declare function createInitialState<TData, TError>(): OperationState<TData, TError>;
|
|
219
218
|
type StateManager = {
|
|
220
219
|
createQueryKey: (params: {
|
|
221
220
|
path: string;
|
|
@@ -249,8 +248,11 @@ type StateManager = {
|
|
|
249
248
|
onDataChange: (callback: DataChangeCallback) => () => void;
|
|
250
249
|
clear: () => void;
|
|
251
250
|
};
|
|
251
|
+
|
|
252
252
|
declare function createStateManager(): StateManager;
|
|
253
253
|
|
|
254
|
+
declare function createInitialState<TData, TError>(): OperationState<TData, TError>;
|
|
255
|
+
|
|
254
256
|
/**
|
|
255
257
|
* Devtool-related types for tracing and debugging.
|
|
256
258
|
* These types are used by the devtool plugin and plugins that emit trace events.
|
|
@@ -435,7 +437,7 @@ interface EventTracer {
|
|
|
435
437
|
emit(msg: string, options?: EventOptions): void;
|
|
436
438
|
}
|
|
437
439
|
|
|
438
|
-
type OperationType = "read" | "write" | "
|
|
440
|
+
type OperationType = "read" | "write" | "pages" | "queue";
|
|
439
441
|
type LifecyclePhase = "onMount" | "onUnmount" | "onUpdate";
|
|
440
442
|
type OperationState<TData = unknown, TError = unknown> = {
|
|
441
443
|
data: TData | undefined;
|
|
@@ -492,7 +494,7 @@ type PluginContextBase = {
|
|
|
492
494
|
eventEmitter: EventEmitter;
|
|
493
495
|
/** Access other plugins' exported APIs */
|
|
494
496
|
plugins: PluginAccessor;
|
|
495
|
-
/** Plugin-specific options passed from hooks (useRead/useWrite/
|
|
497
|
+
/** Plugin-specific options passed from hooks (useRead/useWrite/usePages) */
|
|
496
498
|
pluginOptions?: unknown;
|
|
497
499
|
/** Force a network request even if cached data exists. Used by plugins to communicate intent. */
|
|
498
500
|
forceRefetch?: boolean;
|
|
@@ -598,7 +600,7 @@ type PluginLifecycle = {
|
|
|
598
600
|
type PluginTypeConfig = {
|
|
599
601
|
readOptions?: object;
|
|
600
602
|
writeOptions?: object;
|
|
601
|
-
|
|
603
|
+
pagesOptions?: object;
|
|
602
604
|
writeTriggerOptions?: object;
|
|
603
605
|
queueOptions?: object;
|
|
604
606
|
queueTriggerOptions?: object;
|
|
@@ -1027,8 +1029,8 @@ type ExtractReadOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends
|
|
|
1027
1029
|
type ExtractWriteOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
|
|
1028
1030
|
writeOptions: infer W;
|
|
1029
1031
|
} ? W : object : object;
|
|
1030
|
-
type
|
|
1031
|
-
|
|
1032
|
+
type ExtractPagesOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
|
|
1033
|
+
pagesOptions: infer I;
|
|
1032
1034
|
} ? I : object : object;
|
|
1033
1035
|
type ExtractWriteTriggerOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
|
|
1034
1036
|
writeTriggerOptions: infer W;
|
|
@@ -1051,21 +1053,21 @@ type ExtractWriteResult<T> = T extends SpooshPlugin<infer Types> ? Types extends
|
|
|
1051
1053
|
type ExtractInstanceApi<T> = T extends SpooshPlugin<infer Types> ? Types extends {
|
|
1052
1054
|
instanceApi: infer A;
|
|
1053
1055
|
} ? A : object : object;
|
|
1054
|
-
type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
1056
|
+
type UnionToIntersection$1<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
1055
1057
|
type MergePluginOptions<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
|
|
1056
|
-
read: UnionToIntersection<ExtractReadOptions<TPlugins[number]>>;
|
|
1057
|
-
write: UnionToIntersection<ExtractWriteOptions<TPlugins[number]>>;
|
|
1058
|
-
|
|
1059
|
-
writeTrigger: UnionToIntersection<ExtractWriteTriggerOptions<TPlugins[number]>>;
|
|
1060
|
-
queue: UnionToIntersection<ExtractQueueOptions<TPlugins[number]>>;
|
|
1061
|
-
queueTrigger: UnionToIntersection<ExtractQueueTriggerOptions<TPlugins[number]>>;
|
|
1058
|
+
read: UnionToIntersection$1<ExtractReadOptions<TPlugins[number]>>;
|
|
1059
|
+
write: UnionToIntersection$1<ExtractWriteOptions<TPlugins[number]>>;
|
|
1060
|
+
pages: UnionToIntersection$1<ExtractPagesOptions<TPlugins[number]>>;
|
|
1061
|
+
writeTrigger: UnionToIntersection$1<ExtractWriteTriggerOptions<TPlugins[number]>>;
|
|
1062
|
+
queue: UnionToIntersection$1<ExtractQueueOptions<TPlugins[number]>>;
|
|
1063
|
+
queueTrigger: UnionToIntersection$1<ExtractQueueTriggerOptions<TPlugins[number]>>;
|
|
1062
1064
|
};
|
|
1063
1065
|
type MergePluginResults<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
|
|
1064
|
-
read: UnionToIntersection<ExtractReadResult<TPlugins[number]>>;
|
|
1065
|
-
write: UnionToIntersection<ExtractWriteResult<TPlugins[number]>>;
|
|
1066
|
-
queue: UnionToIntersection<ExtractQueueResult<TPlugins[number]>>;
|
|
1066
|
+
read: UnionToIntersection$1<ExtractReadResult<TPlugins[number]>>;
|
|
1067
|
+
write: UnionToIntersection$1<ExtractWriteResult<TPlugins[number]>>;
|
|
1068
|
+
queue: UnionToIntersection$1<ExtractQueueResult<TPlugins[number]>>;
|
|
1067
1069
|
};
|
|
1068
|
-
type MergePluginInstanceApi<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[], TSchema = unknown> = ResolveInstanceApi<UnionToIntersection<ExtractInstanceApi<TPlugins[number]>>, TSchema, MergePluginOptions<TPlugins>["read"]>;
|
|
1070
|
+
type MergePluginInstanceApi<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[], TSchema = unknown> = ResolveInstanceApi<UnionToIntersection$1<ExtractInstanceApi<TPlugins[number]>>, TSchema, MergePluginOptions<TPlugins>["read"]>;
|
|
1069
1071
|
type PluginRegistry<TPlugins extends SpooshPlugin<PluginTypeConfig>[]> = {
|
|
1070
1072
|
plugins: TPlugins;
|
|
1071
1073
|
_options: MergePluginOptions<TPlugins>;
|
|
@@ -1309,12 +1311,103 @@ type WritePathMethods$1<TSchema, TPath extends string> = FindMatchingKey<TSchema
|
|
|
1309
1311
|
*/
|
|
1310
1312
|
type WriteSchemaHelper<TSchema> = <TPath extends WritePaths<TSchema> | (string & {})>(path: TPath) => HasWriteMethod<TSchema, TPath> extends true ? WritePathMethods$1<TSchema, TPath> : never;
|
|
1311
1313
|
|
|
1314
|
+
/**
|
|
1315
|
+
* Check for exact type equality using function type assignability.
|
|
1316
|
+
* Two types are equal if functions returning them are mutually assignable.
|
|
1317
|
+
*/
|
|
1318
|
+
type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
1319
|
+
/**
|
|
1320
|
+
* Convert bare `object` type to `never` to exclude it from the union.
|
|
1321
|
+
* Preserves all other types including interfaces and types with actual properties.
|
|
1322
|
+
*/
|
|
1323
|
+
type FilterObjectType<T> = Equals<T, object> extends true ? never : T;
|
|
1324
|
+
/**
|
|
1325
|
+
* Convert a union type to an intersection type.
|
|
1326
|
+
* This merges all properties from all types in the union.
|
|
1327
|
+
*/
|
|
1328
|
+
type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
1329
|
+
/**
|
|
1330
|
+
* Extract all option types from plugin configuration and create a union, then intersect.
|
|
1331
|
+
* This allows middleware to access all properties from all option types.
|
|
1332
|
+
* object types are converted to unknown which doesn't affect the intersection.
|
|
1333
|
+
*/
|
|
1334
|
+
type ExtractPluginOptionsUnion<T extends PluginTypeConfig> = UnionToIntersection<FilterObjectType<T extends {
|
|
1335
|
+
readOptions: infer R;
|
|
1336
|
+
} ? R : never> | FilterObjectType<T extends {
|
|
1337
|
+
writeOptions: infer W;
|
|
1338
|
+
} ? W : never> | FilterObjectType<T extends {
|
|
1339
|
+
writeTriggerOptions: infer WT;
|
|
1340
|
+
} ? WT : never> | FilterObjectType<T extends {
|
|
1341
|
+
queueTriggerOptions: infer QT;
|
|
1342
|
+
} ? QT : never> | FilterObjectType<T extends {
|
|
1343
|
+
pagesOptions: infer P;
|
|
1344
|
+
} ? P : never> | FilterObjectType<T extends {
|
|
1345
|
+
queueOptions: infer Q;
|
|
1346
|
+
} ? Q : never>>;
|
|
1347
|
+
/**
|
|
1348
|
+
* Plugin context with typed pluginOptions based on plugin configuration.
|
|
1349
|
+
*/
|
|
1350
|
+
type TypedPluginContext<T extends PluginTypeConfig> = Omit<PluginContext, "pluginOptions"> & {
|
|
1351
|
+
pluginOptions?: ExtractPluginOptionsUnion<T>;
|
|
1352
|
+
};
|
|
1353
|
+
/**
|
|
1354
|
+
* Plugin definition with typed context for middleware and handlers.
|
|
1355
|
+
*/
|
|
1356
|
+
type TypedPluginDefinition<T extends PluginTypeConfig> = Omit<SpooshPlugin<T>, "middleware" | "afterResponse" | "lifecycle"> & {
|
|
1357
|
+
middleware?: (context: TypedPluginContext<T>, next: () => Promise<any>) => Promise<any>;
|
|
1358
|
+
afterResponse?: (context: TypedPluginContext<T>, response: any) => any;
|
|
1359
|
+
lifecycle?: {
|
|
1360
|
+
onMount?: (context: TypedPluginContext<T>) => void | Promise<void>;
|
|
1361
|
+
onUpdate?: (context: TypedPluginContext<T>, previousContext: TypedPluginContext<T>) => void | Promise<void>;
|
|
1362
|
+
onUnmount?: (context: TypedPluginContext<T>) => void | Promise<void>;
|
|
1363
|
+
};
|
|
1364
|
+
};
|
|
1365
|
+
/**
|
|
1366
|
+
* Helper to create a Spoosh plugin with automatic type inference for plugin options.
|
|
1367
|
+
*
|
|
1368
|
+
* This eliminates the need for manual type assertions in middleware by automatically
|
|
1369
|
+
* intersecting all option types, making all properties accessible:
|
|
1370
|
+
*
|
|
1371
|
+
* ```ts
|
|
1372
|
+
* // Before:
|
|
1373
|
+
* const pluginOptions = context.pluginOptions as CacheReadOptions | undefined;
|
|
1374
|
+
* const staleTime = pluginOptions?.staleTime ?? defaultStaleTime;
|
|
1375
|
+
*
|
|
1376
|
+
* // After (with createSpooshPlugin):
|
|
1377
|
+
* const staleTime = context.pluginOptions?.staleTime ?? defaultStaleTime;
|
|
1378
|
+
* ```
|
|
1379
|
+
*
|
|
1380
|
+
* @typeParam T - Plugin type configuration (readOptions, writeOptions, etc.)
|
|
1381
|
+
* @param definition - Plugin definition with typed context
|
|
1382
|
+
* @returns Typed Spoosh plugin
|
|
1383
|
+
*
|
|
1384
|
+
* @example
|
|
1385
|
+
* ```ts
|
|
1386
|
+
* export const cachePlugin = (config: CachePluginConfig = {}) =>
|
|
1387
|
+
* createSpooshPlugin<{
|
|
1388
|
+
* readOptions: CacheReadOptions;
|
|
1389
|
+
* writeOptions: CacheWriteOptions;
|
|
1390
|
+
* pagesOptions: CachePagesOptions;
|
|
1391
|
+
* }>({
|
|
1392
|
+
* name: "spoosh:cache",
|
|
1393
|
+
* operations: ["read", "write", "pages"],
|
|
1394
|
+
* middleware: async (context, next) => {
|
|
1395
|
+
* // context.pluginOptions is automatically typed as an intersection:
|
|
1396
|
+
* // CacheReadOptions & CachePagesOptions (CacheWriteOptions filtered as it's just 'object')
|
|
1397
|
+
* // All properties from all option types are accessible:
|
|
1398
|
+
* const staleTime = context.pluginOptions?.staleTime ?? defaultStaleTime;
|
|
1399
|
+
* return next();
|
|
1400
|
+
* },
|
|
1401
|
+
* });
|
|
1402
|
+
* ```
|
|
1403
|
+
*/
|
|
1404
|
+
declare function createSpooshPlugin<T extends PluginTypeConfig>(definition: TypedPluginDefinition<T>): SpooshPlugin<T>;
|
|
1405
|
+
|
|
1312
1406
|
/**
|
|
1313
1407
|
* Base request options available on all methods.
|
|
1314
1408
|
*/
|
|
1315
1409
|
type BaseRequestOptions = {
|
|
1316
1410
|
headers?: HeadersInitOrGetter;
|
|
1317
|
-
cache?: RequestCache;
|
|
1318
1411
|
signal?: AbortSignal;
|
|
1319
1412
|
};
|
|
1320
1413
|
/**
|
|
@@ -1490,6 +1583,22 @@ type SpooshInstance<TSchema = unknown, TDefaultError = unknown, TPlugins extends
|
|
|
1490
1583
|
};
|
|
1491
1584
|
};
|
|
1492
1585
|
|
|
1586
|
+
type ExtractTriggerQuery<I> = I extends {
|
|
1587
|
+
query: infer Q;
|
|
1588
|
+
} ? {
|
|
1589
|
+
query?: Q;
|
|
1590
|
+
} : unknown;
|
|
1591
|
+
type ExtractTriggerBody<I> = I extends {
|
|
1592
|
+
body: infer B;
|
|
1593
|
+
} ? {
|
|
1594
|
+
body?: B;
|
|
1595
|
+
} : unknown;
|
|
1596
|
+
type ExtractTriggerParams<I> = I extends {
|
|
1597
|
+
params: infer P;
|
|
1598
|
+
} ? {
|
|
1599
|
+
params?: P;
|
|
1600
|
+
} : unknown;
|
|
1601
|
+
|
|
1493
1602
|
/**
|
|
1494
1603
|
* Class-based builder for creating Spoosh instances with type-safe plugin inference.
|
|
1495
1604
|
*
|
|
@@ -2001,6 +2110,7 @@ type CreateOperationOptions<TData, TError> = {
|
|
|
2001
2110
|
/** Unique identifier for the hook instance. Persists across queryKey changes. */
|
|
2002
2111
|
instanceId?: string;
|
|
2003
2112
|
};
|
|
2113
|
+
|
|
2004
2114
|
declare function createOperationController<TData, TError>(options: CreateOperationOptions<TData, TError>): OperationController<TData, TError>;
|
|
2005
2115
|
|
|
2006
2116
|
type InfiniteRequestOptions = {
|
|
@@ -2008,27 +2118,43 @@ type InfiniteRequestOptions = {
|
|
|
2008
2118
|
params?: Record<string, string | number>;
|
|
2009
2119
|
body?: unknown;
|
|
2010
2120
|
};
|
|
2011
|
-
type
|
|
2012
|
-
|
|
2013
|
-
|
|
2121
|
+
type InfinitePageStatus = "pending" | "loading" | "success" | "error" | "stale";
|
|
2122
|
+
interface InfinitePage<TData, TError, TMeta> {
|
|
2123
|
+
status: InfinitePageStatus;
|
|
2124
|
+
data?: TData;
|
|
2125
|
+
error?: TError;
|
|
2126
|
+
meta?: TMeta;
|
|
2127
|
+
input?: InfiniteRequestOptions;
|
|
2128
|
+
}
|
|
2129
|
+
type InfiniteNextContext<TData, TError, TRequest, TMeta> = {
|
|
2130
|
+
lastPage: InfinitePage<TData, TError, TMeta> | undefined;
|
|
2131
|
+
pages: InfinitePage<TData, TError, TMeta>[];
|
|
2132
|
+
request: TRequest;
|
|
2133
|
+
};
|
|
2134
|
+
type InfinitePrevContext<TData, TError, TRequest, TMeta> = {
|
|
2135
|
+
firstPage: InfinitePage<TData, TError, TMeta> | undefined;
|
|
2136
|
+
pages: InfinitePage<TData, TError, TMeta>[];
|
|
2014
2137
|
request: TRequest;
|
|
2015
2138
|
};
|
|
2016
2139
|
type FetchDirection = "next" | "prev";
|
|
2017
|
-
type
|
|
2140
|
+
type InfiniteTriggerOptions = Partial<InfiniteRequestOptions> & {
|
|
2141
|
+
/** Bypass cache and force refetch. Default: true */
|
|
2142
|
+
force?: boolean;
|
|
2143
|
+
};
|
|
2144
|
+
type InfiniteReadState<TData, TItem, TError, TMeta = Record<string, unknown>> = {
|
|
2018
2145
|
data: TItem[] | undefined;
|
|
2019
|
-
|
|
2020
|
-
allRequests: InfiniteRequestOptions[] | undefined;
|
|
2146
|
+
pages: InfinitePage<TData, TError, TMeta>[];
|
|
2021
2147
|
canFetchNext: boolean;
|
|
2022
2148
|
canFetchPrev: boolean;
|
|
2023
2149
|
error: TError | undefined;
|
|
2024
2150
|
};
|
|
2025
|
-
type InfiniteReadController<TData, TItem, TError
|
|
2026
|
-
getState: () => InfiniteReadState<TData, TItem, TError>;
|
|
2151
|
+
type InfiniteReadController<TData, TItem, TError, TMeta = Record<string, unknown>> = {
|
|
2152
|
+
getState: () => InfiniteReadState<TData, TItem, TError, TMeta>;
|
|
2027
2153
|
getFetchingDirection: () => FetchDirection | null;
|
|
2028
2154
|
subscribe: (callback: () => void) => () => void;
|
|
2029
2155
|
fetchNext: () => Promise<void>;
|
|
2030
2156
|
fetchPrev: () => Promise<void>;
|
|
2031
|
-
|
|
2157
|
+
trigger: (options?: InfiniteTriggerOptions) => Promise<void>;
|
|
2032
2158
|
abort: () => void;
|
|
2033
2159
|
mount: () => void;
|
|
2034
2160
|
unmount: () => void;
|
|
@@ -2036,17 +2162,16 @@ type InfiniteReadController<TData, TItem, TError> = {
|
|
|
2036
2162
|
getContext: () => PluginContext;
|
|
2037
2163
|
setPluginOptions: (options: unknown) => void;
|
|
2038
2164
|
};
|
|
2039
|
-
type CreateInfiniteReadOptions<TData, TItem, TError, TRequest
|
|
2165
|
+
type CreateInfiniteReadOptions<TData, TItem, TError, TRequest, TMeta = Record<string, unknown>> = {
|
|
2040
2166
|
path: string;
|
|
2041
2167
|
method: HttpMethod;
|
|
2042
2168
|
tags: string[];
|
|
2043
2169
|
initialRequest: InfiniteRequestOptions;
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
merger: (responses: TData[]) => TItem[];
|
|
2170
|
+
canFetchNext?: (ctx: InfiniteNextContext<TData, TError, TRequest, TMeta>) => boolean;
|
|
2171
|
+
canFetchPrev?: (ctx: InfinitePrevContext<TData, TError, TRequest, TMeta>) => boolean;
|
|
2172
|
+
nextPageRequest?: (ctx: InfiniteNextContext<TData, TError, TRequest, TMeta>) => Partial<TRequest>;
|
|
2173
|
+
prevPageRequest?: (ctx: InfinitePrevContext<TData, TError, TRequest, TMeta>) => Partial<TRequest>;
|
|
2174
|
+
merger: (pages: InfinitePage<TData, TError, TMeta>[]) => TItem[];
|
|
2050
2175
|
stateManager: StateManager;
|
|
2051
2176
|
eventEmitter: EventEmitter;
|
|
2052
2177
|
pluginExecutor: PluginExecutor;
|
|
@@ -2054,7 +2179,8 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
|
|
|
2054
2179
|
/** Unique identifier for the hook instance. Persists across queryKey changes. */
|
|
2055
2180
|
instanceId?: string;
|
|
2056
2181
|
};
|
|
2057
|
-
|
|
2182
|
+
|
|
2183
|
+
declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions, TMeta = Record<string, unknown>>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest, TMeta>): InfiniteReadController<TData, TItem, TError, TMeta>;
|
|
2058
2184
|
|
|
2059
2185
|
/**
|
|
2060
2186
|
* Status of an item in the queue.
|
|
@@ -2177,4 +2303,4 @@ declare class Semaphore {
|
|
|
2177
2303
|
getWaitingCount(): number;
|
|
2178
2304
|
}
|
|
2179
2305
|
|
|
2180
|
-
export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type
|
|
2306
|
+
export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DataChangeCallback, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExecuteOptions, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type ExtractTriggerBody, type ExtractTriggerParams, type ExtractTriggerQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteNextContext, type InfinitePage, type InfinitePageStatus, type InfinitePrevContext, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InfiniteTriggerOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type QueueController, type QueueControllerConfig, type QueueControllerContext, type QueueItem, type QueueItemStatus, type QueueSelectorClient, type QueueStats, type QueueTriggerInput, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, Semaphore, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type Subscriber, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type TypedPluginContext, type TypedPluginDefinition, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, createSpooshPlugin, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, removeHeaderKeys, resolveHeadersToRecord, resolvePath, resolvePathString, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
|