@spoosh/core 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -210,11 +210,11 @@ type EventEmitter = {
210
210
  declare function createEventEmitter(): EventEmitter;
211
211
 
212
212
  type Subscriber = () => void;
213
+ type DataChangeCallback = (key: string, oldData: unknown, newData: unknown) => void;
213
214
  type CacheEntryWithKey<TData = unknown, TError = unknown> = {
214
215
  key: string;
215
216
  entry: CacheEntry<TData, TError>;
216
217
  };
217
- declare function createInitialState<TData, TError>(): OperationState<TData, TError>;
218
218
  type StateManager = {
219
219
  createQueryKey: (params: {
220
220
  path: string;
@@ -241,10 +241,18 @@ type StateManager = {
241
241
  setPendingPromise: (key: string, promise: Promise<unknown> | undefined) => void;
242
242
  /** Get a pending promise for a query key */
243
243
  getPendingPromise: (key: string) => Promise<unknown> | undefined;
244
+ /**
245
+ * Register a callback to be invoked when cache data changes.
246
+ * @returns Unsubscribe function
247
+ */
248
+ onDataChange: (callback: DataChangeCallback) => () => void;
244
249
  clear: () => void;
245
250
  };
251
+
246
252
  declare function createStateManager(): StateManager;
247
253
 
254
+ declare function createInitialState<TData, TError>(): OperationState<TData, TError>;
255
+
248
256
  /**
249
257
  * Devtool-related types for tracing and debugging.
250
258
  * These types are used by the devtool plugin and plugins that emit trace events.
@@ -429,7 +437,7 @@ interface EventTracer {
429
437
  emit(msg: string, options?: EventOptions): void;
430
438
  }
431
439
 
432
- type OperationType = "read" | "write" | "infiniteRead" | "queue";
440
+ type OperationType = "read" | "write" | "pages" | "queue";
433
441
  type LifecyclePhase = "onMount" | "onUnmount" | "onUpdate";
434
442
  type OperationState<TData = unknown, TError = unknown> = {
435
443
  data: TData | undefined;
@@ -486,7 +494,7 @@ type PluginContextBase = {
486
494
  eventEmitter: EventEmitter;
487
495
  /** Access other plugins' exported APIs */
488
496
  plugins: PluginAccessor;
489
- /** Plugin-specific options passed from hooks (useRead/useWrite/useInfiniteRead) */
497
+ /** Plugin-specific options passed from hooks (useRead/useWrite/usePages) */
490
498
  pluginOptions?: unknown;
491
499
  /** Force a network request even if cached data exists. Used by plugins to communicate intent. */
492
500
  forceRefetch?: boolean;
@@ -592,7 +600,7 @@ type PluginLifecycle = {
592
600
  type PluginTypeConfig = {
593
601
  readOptions?: object;
594
602
  writeOptions?: object;
595
- infiniteReadOptions?: object;
603
+ pagesOptions?: object;
596
604
  writeTriggerOptions?: object;
597
605
  queueOptions?: object;
598
606
  queueTriggerOptions?: object;
@@ -1021,8 +1029,8 @@ type ExtractReadOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends
1021
1029
  type ExtractWriteOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1022
1030
  writeOptions: infer W;
1023
1031
  } ? W : object : object;
1024
- type ExtractInfiniteReadOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1025
- infiniteReadOptions: infer I;
1032
+ type ExtractPagesOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1033
+ pagesOptions: infer I;
1026
1034
  } ? I : object : object;
1027
1035
  type ExtractWriteTriggerOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1028
1036
  writeTriggerOptions: infer W;
@@ -1049,7 +1057,7 @@ type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) exten
1049
1057
  type MergePluginOptions<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
1050
1058
  read: UnionToIntersection<ExtractReadOptions<TPlugins[number]>>;
1051
1059
  write: UnionToIntersection<ExtractWriteOptions<TPlugins[number]>>;
1052
- infiniteRead: UnionToIntersection<ExtractInfiniteReadOptions<TPlugins[number]>>;
1060
+ pages: UnionToIntersection<ExtractPagesOptions<TPlugins[number]>>;
1053
1061
  writeTrigger: UnionToIntersection<ExtractWriteTriggerOptions<TPlugins[number]>>;
1054
1062
  queue: UnionToIntersection<ExtractQueueOptions<TPlugins[number]>>;
1055
1063
  queueTrigger: UnionToIntersection<ExtractQueueTriggerOptions<TPlugins[number]>>;
@@ -1484,6 +1492,22 @@ type SpooshInstance<TSchema = unknown, TDefaultError = unknown, TPlugins extends
1484
1492
  };
1485
1493
  };
1486
1494
 
1495
+ type ExtractTriggerQuery<I> = I extends {
1496
+ query: infer Q;
1497
+ } ? {
1498
+ query?: Q;
1499
+ } : unknown;
1500
+ type ExtractTriggerBody<I> = I extends {
1501
+ body: infer B;
1502
+ } ? {
1503
+ body?: B;
1504
+ } : unknown;
1505
+ type ExtractTriggerParams<I> = I extends {
1506
+ params: infer P;
1507
+ } ? {
1508
+ params?: P;
1509
+ } : unknown;
1510
+
1487
1511
  /**
1488
1512
  * Class-based builder for creating Spoosh instances with type-safe plugin inference.
1489
1513
  *
@@ -1995,6 +2019,7 @@ type CreateOperationOptions<TData, TError> = {
1995
2019
  /** Unique identifier for the hook instance. Persists across queryKey changes. */
1996
2020
  instanceId?: string;
1997
2021
  };
2022
+
1998
2023
  declare function createOperationController<TData, TError>(options: CreateOperationOptions<TData, TError>): OperationController<TData, TError>;
1999
2024
 
2000
2025
  type InfiniteRequestOptions = {
@@ -2002,27 +2027,43 @@ type InfiniteRequestOptions = {
2002
2027
  params?: Record<string, string | number>;
2003
2028
  body?: unknown;
2004
2029
  };
2005
- type PageContext<TData, TRequest = InfiniteRequestOptions> = {
2006
- response: TData | undefined;
2007
- allResponses: TData[];
2030
+ type InfinitePageStatus = "pending" | "loading" | "success" | "error" | "stale";
2031
+ interface InfinitePage<TData, TError, TMeta> {
2032
+ status: InfinitePageStatus;
2033
+ data?: TData;
2034
+ error?: TError;
2035
+ meta?: TMeta;
2036
+ input?: InfiniteRequestOptions;
2037
+ }
2038
+ type InfiniteNextContext<TData, TError, TRequest, TMeta> = {
2039
+ lastPage: InfinitePage<TData, TError, TMeta> | undefined;
2040
+ pages: InfinitePage<TData, TError, TMeta>[];
2041
+ request: TRequest;
2042
+ };
2043
+ type InfinitePrevContext<TData, TError, TRequest, TMeta> = {
2044
+ firstPage: InfinitePage<TData, TError, TMeta> | undefined;
2045
+ pages: InfinitePage<TData, TError, TMeta>[];
2008
2046
  request: TRequest;
2009
2047
  };
2010
2048
  type FetchDirection = "next" | "prev";
2011
- type InfiniteReadState<TData, TItem, TError> = {
2049
+ type InfiniteTriggerOptions = Partial<InfiniteRequestOptions> & {
2050
+ /** Bypass cache and force refetch. Default: true */
2051
+ force?: boolean;
2052
+ };
2053
+ type InfiniteReadState<TData, TItem, TError, TMeta = Record<string, unknown>> = {
2012
2054
  data: TItem[] | undefined;
2013
- allResponses: TData[] | undefined;
2014
- allRequests: InfiniteRequestOptions[] | undefined;
2055
+ pages: InfinitePage<TData, TError, TMeta>[];
2015
2056
  canFetchNext: boolean;
2016
2057
  canFetchPrev: boolean;
2017
2058
  error: TError | undefined;
2018
2059
  };
2019
- type InfiniteReadController<TData, TItem, TError> = {
2020
- getState: () => InfiniteReadState<TData, TItem, TError>;
2060
+ type InfiniteReadController<TData, TItem, TError, TMeta = Record<string, unknown>> = {
2061
+ getState: () => InfiniteReadState<TData, TItem, TError, TMeta>;
2021
2062
  getFetchingDirection: () => FetchDirection | null;
2022
2063
  subscribe: (callback: () => void) => () => void;
2023
2064
  fetchNext: () => Promise<void>;
2024
2065
  fetchPrev: () => Promise<void>;
2025
- refetch: () => Promise<void>;
2066
+ trigger: (options?: InfiniteTriggerOptions) => Promise<void>;
2026
2067
  abort: () => void;
2027
2068
  mount: () => void;
2028
2069
  unmount: () => void;
@@ -2030,17 +2071,16 @@ type InfiniteReadController<TData, TItem, TError> = {
2030
2071
  getContext: () => PluginContext;
2031
2072
  setPluginOptions: (options: unknown) => void;
2032
2073
  };
2033
- type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
2074
+ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest, TMeta = Record<string, unknown>> = {
2034
2075
  path: string;
2035
2076
  method: HttpMethod;
2036
2077
  tags: string[];
2037
2078
  initialRequest: InfiniteRequestOptions;
2038
- baseOptionsForKey: object;
2039
- canFetchNext: (ctx: PageContext<TData, TRequest>) => boolean;
2040
- canFetchPrev?: (ctx: PageContext<TData, TRequest>) => boolean;
2041
- nextPageRequest: (ctx: PageContext<TData, TRequest>) => Partial<TRequest>;
2042
- prevPageRequest?: (ctx: PageContext<TData, TRequest>) => Partial<TRequest>;
2043
- merger: (responses: TData[]) => TItem[];
2079
+ canFetchNext?: (ctx: InfiniteNextContext<TData, TError, TRequest, TMeta>) => boolean;
2080
+ canFetchPrev?: (ctx: InfinitePrevContext<TData, TError, TRequest, TMeta>) => boolean;
2081
+ nextPageRequest?: (ctx: InfiniteNextContext<TData, TError, TRequest, TMeta>) => Partial<TRequest>;
2082
+ prevPageRequest?: (ctx: InfinitePrevContext<TData, TError, TRequest, TMeta>) => Partial<TRequest>;
2083
+ merger: (pages: InfinitePage<TData, TError, TMeta>[]) => TItem[];
2044
2084
  stateManager: StateManager;
2045
2085
  eventEmitter: EventEmitter;
2046
2086
  pluginExecutor: PluginExecutor;
@@ -2048,7 +2088,8 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
2048
2088
  /** Unique identifier for the hook instance. Persists across queryKey changes. */
2049
2089
  instanceId?: string;
2050
2090
  };
2051
- declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest>): InfiniteReadController<TData, TItem, TError>;
2091
+
2092
+ 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>;
2052
2093
 
2053
2094
  /**
2054
2095
  * Status of an item in the queue.
@@ -2171,4 +2212,4 @@ declare class Semaphore {
2171
2212
  getWaitingCount(): number;
2172
2213
  }
2173
2214
 
2174
- 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 PageContext, 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 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 WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, 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 };
2215
+ 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 WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, 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
@@ -210,11 +210,11 @@ type EventEmitter = {
210
210
  declare function createEventEmitter(): EventEmitter;
211
211
 
212
212
  type Subscriber = () => void;
213
+ type DataChangeCallback = (key: string, oldData: unknown, newData: unknown) => void;
213
214
  type CacheEntryWithKey<TData = unknown, TError = unknown> = {
214
215
  key: string;
215
216
  entry: CacheEntry<TData, TError>;
216
217
  };
217
- declare function createInitialState<TData, TError>(): OperationState<TData, TError>;
218
218
  type StateManager = {
219
219
  createQueryKey: (params: {
220
220
  path: string;
@@ -241,10 +241,18 @@ type StateManager = {
241
241
  setPendingPromise: (key: string, promise: Promise<unknown> | undefined) => void;
242
242
  /** Get a pending promise for a query key */
243
243
  getPendingPromise: (key: string) => Promise<unknown> | undefined;
244
+ /**
245
+ * Register a callback to be invoked when cache data changes.
246
+ * @returns Unsubscribe function
247
+ */
248
+ onDataChange: (callback: DataChangeCallback) => () => void;
244
249
  clear: () => void;
245
250
  };
251
+
246
252
  declare function createStateManager(): StateManager;
247
253
 
254
+ declare function createInitialState<TData, TError>(): OperationState<TData, TError>;
255
+
248
256
  /**
249
257
  * Devtool-related types for tracing and debugging.
250
258
  * These types are used by the devtool plugin and plugins that emit trace events.
@@ -429,7 +437,7 @@ interface EventTracer {
429
437
  emit(msg: string, options?: EventOptions): void;
430
438
  }
431
439
 
432
- type OperationType = "read" | "write" | "infiniteRead" | "queue";
440
+ type OperationType = "read" | "write" | "pages" | "queue";
433
441
  type LifecyclePhase = "onMount" | "onUnmount" | "onUpdate";
434
442
  type OperationState<TData = unknown, TError = unknown> = {
435
443
  data: TData | undefined;
@@ -486,7 +494,7 @@ type PluginContextBase = {
486
494
  eventEmitter: EventEmitter;
487
495
  /** Access other plugins' exported APIs */
488
496
  plugins: PluginAccessor;
489
- /** Plugin-specific options passed from hooks (useRead/useWrite/useInfiniteRead) */
497
+ /** Plugin-specific options passed from hooks (useRead/useWrite/usePages) */
490
498
  pluginOptions?: unknown;
491
499
  /** Force a network request even if cached data exists. Used by plugins to communicate intent. */
492
500
  forceRefetch?: boolean;
@@ -592,7 +600,7 @@ type PluginLifecycle = {
592
600
  type PluginTypeConfig = {
593
601
  readOptions?: object;
594
602
  writeOptions?: object;
595
- infiniteReadOptions?: object;
603
+ pagesOptions?: object;
596
604
  writeTriggerOptions?: object;
597
605
  queueOptions?: object;
598
606
  queueTriggerOptions?: object;
@@ -1021,8 +1029,8 @@ type ExtractReadOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends
1021
1029
  type ExtractWriteOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1022
1030
  writeOptions: infer W;
1023
1031
  } ? W : object : object;
1024
- type ExtractInfiniteReadOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1025
- infiniteReadOptions: infer I;
1032
+ type ExtractPagesOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1033
+ pagesOptions: infer I;
1026
1034
  } ? I : object : object;
1027
1035
  type ExtractWriteTriggerOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1028
1036
  writeTriggerOptions: infer W;
@@ -1049,7 +1057,7 @@ type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) exten
1049
1057
  type MergePluginOptions<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
1050
1058
  read: UnionToIntersection<ExtractReadOptions<TPlugins[number]>>;
1051
1059
  write: UnionToIntersection<ExtractWriteOptions<TPlugins[number]>>;
1052
- infiniteRead: UnionToIntersection<ExtractInfiniteReadOptions<TPlugins[number]>>;
1060
+ pages: UnionToIntersection<ExtractPagesOptions<TPlugins[number]>>;
1053
1061
  writeTrigger: UnionToIntersection<ExtractWriteTriggerOptions<TPlugins[number]>>;
1054
1062
  queue: UnionToIntersection<ExtractQueueOptions<TPlugins[number]>>;
1055
1063
  queueTrigger: UnionToIntersection<ExtractQueueTriggerOptions<TPlugins[number]>>;
@@ -1484,6 +1492,22 @@ type SpooshInstance<TSchema = unknown, TDefaultError = unknown, TPlugins extends
1484
1492
  };
1485
1493
  };
1486
1494
 
1495
+ type ExtractTriggerQuery<I> = I extends {
1496
+ query: infer Q;
1497
+ } ? {
1498
+ query?: Q;
1499
+ } : unknown;
1500
+ type ExtractTriggerBody<I> = I extends {
1501
+ body: infer B;
1502
+ } ? {
1503
+ body?: B;
1504
+ } : unknown;
1505
+ type ExtractTriggerParams<I> = I extends {
1506
+ params: infer P;
1507
+ } ? {
1508
+ params?: P;
1509
+ } : unknown;
1510
+
1487
1511
  /**
1488
1512
  * Class-based builder for creating Spoosh instances with type-safe plugin inference.
1489
1513
  *
@@ -1995,6 +2019,7 @@ type CreateOperationOptions<TData, TError> = {
1995
2019
  /** Unique identifier for the hook instance. Persists across queryKey changes. */
1996
2020
  instanceId?: string;
1997
2021
  };
2022
+
1998
2023
  declare function createOperationController<TData, TError>(options: CreateOperationOptions<TData, TError>): OperationController<TData, TError>;
1999
2024
 
2000
2025
  type InfiniteRequestOptions = {
@@ -2002,27 +2027,43 @@ type InfiniteRequestOptions = {
2002
2027
  params?: Record<string, string | number>;
2003
2028
  body?: unknown;
2004
2029
  };
2005
- type PageContext<TData, TRequest = InfiniteRequestOptions> = {
2006
- response: TData | undefined;
2007
- allResponses: TData[];
2030
+ type InfinitePageStatus = "pending" | "loading" | "success" | "error" | "stale";
2031
+ interface InfinitePage<TData, TError, TMeta> {
2032
+ status: InfinitePageStatus;
2033
+ data?: TData;
2034
+ error?: TError;
2035
+ meta?: TMeta;
2036
+ input?: InfiniteRequestOptions;
2037
+ }
2038
+ type InfiniteNextContext<TData, TError, TRequest, TMeta> = {
2039
+ lastPage: InfinitePage<TData, TError, TMeta> | undefined;
2040
+ pages: InfinitePage<TData, TError, TMeta>[];
2041
+ request: TRequest;
2042
+ };
2043
+ type InfinitePrevContext<TData, TError, TRequest, TMeta> = {
2044
+ firstPage: InfinitePage<TData, TError, TMeta> | undefined;
2045
+ pages: InfinitePage<TData, TError, TMeta>[];
2008
2046
  request: TRequest;
2009
2047
  };
2010
2048
  type FetchDirection = "next" | "prev";
2011
- type InfiniteReadState<TData, TItem, TError> = {
2049
+ type InfiniteTriggerOptions = Partial<InfiniteRequestOptions> & {
2050
+ /** Bypass cache and force refetch. Default: true */
2051
+ force?: boolean;
2052
+ };
2053
+ type InfiniteReadState<TData, TItem, TError, TMeta = Record<string, unknown>> = {
2012
2054
  data: TItem[] | undefined;
2013
- allResponses: TData[] | undefined;
2014
- allRequests: InfiniteRequestOptions[] | undefined;
2055
+ pages: InfinitePage<TData, TError, TMeta>[];
2015
2056
  canFetchNext: boolean;
2016
2057
  canFetchPrev: boolean;
2017
2058
  error: TError | undefined;
2018
2059
  };
2019
- type InfiniteReadController<TData, TItem, TError> = {
2020
- getState: () => InfiniteReadState<TData, TItem, TError>;
2060
+ type InfiniteReadController<TData, TItem, TError, TMeta = Record<string, unknown>> = {
2061
+ getState: () => InfiniteReadState<TData, TItem, TError, TMeta>;
2021
2062
  getFetchingDirection: () => FetchDirection | null;
2022
2063
  subscribe: (callback: () => void) => () => void;
2023
2064
  fetchNext: () => Promise<void>;
2024
2065
  fetchPrev: () => Promise<void>;
2025
- refetch: () => Promise<void>;
2066
+ trigger: (options?: InfiniteTriggerOptions) => Promise<void>;
2026
2067
  abort: () => void;
2027
2068
  mount: () => void;
2028
2069
  unmount: () => void;
@@ -2030,17 +2071,16 @@ type InfiniteReadController<TData, TItem, TError> = {
2030
2071
  getContext: () => PluginContext;
2031
2072
  setPluginOptions: (options: unknown) => void;
2032
2073
  };
2033
- type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
2074
+ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest, TMeta = Record<string, unknown>> = {
2034
2075
  path: string;
2035
2076
  method: HttpMethod;
2036
2077
  tags: string[];
2037
2078
  initialRequest: InfiniteRequestOptions;
2038
- baseOptionsForKey: object;
2039
- canFetchNext: (ctx: PageContext<TData, TRequest>) => boolean;
2040
- canFetchPrev?: (ctx: PageContext<TData, TRequest>) => boolean;
2041
- nextPageRequest: (ctx: PageContext<TData, TRequest>) => Partial<TRequest>;
2042
- prevPageRequest?: (ctx: PageContext<TData, TRequest>) => Partial<TRequest>;
2043
- merger: (responses: TData[]) => TItem[];
2079
+ canFetchNext?: (ctx: InfiniteNextContext<TData, TError, TRequest, TMeta>) => boolean;
2080
+ canFetchPrev?: (ctx: InfinitePrevContext<TData, TError, TRequest, TMeta>) => boolean;
2081
+ nextPageRequest?: (ctx: InfiniteNextContext<TData, TError, TRequest, TMeta>) => Partial<TRequest>;
2082
+ prevPageRequest?: (ctx: InfinitePrevContext<TData, TError, TRequest, TMeta>) => Partial<TRequest>;
2083
+ merger: (pages: InfinitePage<TData, TError, TMeta>[]) => TItem[];
2044
2084
  stateManager: StateManager;
2045
2085
  eventEmitter: EventEmitter;
2046
2086
  pluginExecutor: PluginExecutor;
@@ -2048,7 +2088,8 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
2048
2088
  /** Unique identifier for the hook instance. Persists across queryKey changes. */
2049
2089
  instanceId?: string;
2050
2090
  };
2051
- declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest>): InfiniteReadController<TData, TItem, TError>;
2091
+
2092
+ 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>;
2052
2093
 
2053
2094
  /**
2054
2095
  * Status of an item in the queue.
@@ -2171,4 +2212,4 @@ declare class Semaphore {
2171
2212
  getWaitingCount(): number;
2172
2213
  }
2173
2214
 
2174
- 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 PageContext, 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 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 WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, 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 };
2215
+ 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 WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createQueueController, createSelectorProxy, 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 };