@spoosh/core 0.18.1 → 0.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1763,12 +1763,13 @@ type IsStrictSubscriptionOptionsRequired<TMethodConfig, TUserPath extends string
1763
1763
  /**
1764
1764
  * Subscription response type that carries event types.
1765
1765
  */
1766
- type SubscriptionResponse<TMethodConfig, TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[] = readonly (keyof ExtractEvents<TMethodConfig>)[]> = {
1766
+ type SubscriptionResponse<TMethodConfig, TUserPath extends string, TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[] = readonly (keyof ExtractEvents<TMethodConfig>)[]> = {
1767
1767
  _subscription: true;
1768
1768
  events: ExtractEvents<TMethodConfig>;
1769
1769
  requestedEvents: TRequestedEvents;
1770
1770
  query: ExtractQuery<TMethodConfig>;
1771
1771
  body: ExtractBody<TMethodConfig>;
1772
+ params: HasParams<TUserPath> extends true ? Record<ExtractParamNames<TUserPath>, string | number> : never;
1772
1773
  error: ExtractError<TMethodConfig>;
1773
1774
  };
1774
1775
  type BaseSubscriptionResponse<TEvents extends Record<string, unknown> = Record<string, unknown>, TError = unknown> = {
@@ -1777,6 +1778,7 @@ type BaseSubscriptionResponse<TEvents extends Record<string, unknown> = Record<s
1777
1778
  requestedEvents: readonly string[];
1778
1779
  query: unknown;
1779
1780
  body: unknown;
1781
+ params: unknown;
1780
1782
  error: TError;
1781
1783
  };
1782
1784
  /**
@@ -1784,7 +1786,7 @@ type BaseSubscriptionResponse<TEvents extends Record<string, unknown> = Record<s
1784
1786
  * GET: Strict typing (body/query required if schema requires)
1785
1787
  * POST/PUT/etc: Loose typing (body/query always optional, passed to trigger)
1786
1788
  */
1787
- type SubscriptionMethodFn<TMethodConfig, TUserPath extends string, TMethod extends string> = TMethod extends "GET" ? IsStrictSubscriptionOptionsRequired<TMethodConfig, TUserPath> extends true ? <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options: StrictSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TRequestedEvents> : <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options?: StrictSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TRequestedEvents> : <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options?: LooseSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TRequestedEvents>;
1789
+ type SubscriptionMethodFn<TMethodConfig, TUserPath extends string, TMethod extends string> = TMethod extends "GET" ? IsStrictSubscriptionOptionsRequired<TMethodConfig, TUserPath> extends true ? <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options: StrictSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TUserPath, TRequestedEvents> : <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options?: StrictSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TUserPath, TRequestedEvents> : <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options?: LooseSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TUserPath, TRequestedEvents>;
1788
1790
  /**
1789
1791
  * Subscription path methods - only methods with events field.
1790
1792
  */
@@ -2460,6 +2462,7 @@ type InfiniteReadController<TData, TItem, TError, TMeta = Record<string, unknown
2460
2462
  fetchNext: () => Promise<void>;
2461
2463
  fetchPrev: () => Promise<void>;
2462
2464
  trigger: (options?: InfiniteTriggerOptions) => Promise<void>;
2465
+ refetch: () => Promise<void>;
2463
2466
  abort: () => void;
2464
2467
  mount: () => void;
2465
2468
  unmount: () => void;
package/dist/index.d.ts CHANGED
@@ -1763,12 +1763,13 @@ type IsStrictSubscriptionOptionsRequired<TMethodConfig, TUserPath extends string
1763
1763
  /**
1764
1764
  * Subscription response type that carries event types.
1765
1765
  */
1766
- type SubscriptionResponse<TMethodConfig, TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[] = readonly (keyof ExtractEvents<TMethodConfig>)[]> = {
1766
+ type SubscriptionResponse<TMethodConfig, TUserPath extends string, TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[] = readonly (keyof ExtractEvents<TMethodConfig>)[]> = {
1767
1767
  _subscription: true;
1768
1768
  events: ExtractEvents<TMethodConfig>;
1769
1769
  requestedEvents: TRequestedEvents;
1770
1770
  query: ExtractQuery<TMethodConfig>;
1771
1771
  body: ExtractBody<TMethodConfig>;
1772
+ params: HasParams<TUserPath> extends true ? Record<ExtractParamNames<TUserPath>, string | number> : never;
1772
1773
  error: ExtractError<TMethodConfig>;
1773
1774
  };
1774
1775
  type BaseSubscriptionResponse<TEvents extends Record<string, unknown> = Record<string, unknown>, TError = unknown> = {
@@ -1777,6 +1778,7 @@ type BaseSubscriptionResponse<TEvents extends Record<string, unknown> = Record<s
1777
1778
  requestedEvents: readonly string[];
1778
1779
  query: unknown;
1779
1780
  body: unknown;
1781
+ params: unknown;
1780
1782
  error: TError;
1781
1783
  };
1782
1784
  /**
@@ -1784,7 +1786,7 @@ type BaseSubscriptionResponse<TEvents extends Record<string, unknown> = Record<s
1784
1786
  * GET: Strict typing (body/query required if schema requires)
1785
1787
  * POST/PUT/etc: Loose typing (body/query always optional, passed to trigger)
1786
1788
  */
1787
- type SubscriptionMethodFn<TMethodConfig, TUserPath extends string, TMethod extends string> = TMethod extends "GET" ? IsStrictSubscriptionOptionsRequired<TMethodConfig, TUserPath> extends true ? <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options: StrictSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TRequestedEvents> : <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options?: StrictSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TRequestedEvents> : <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options?: LooseSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TRequestedEvents>;
1789
+ type SubscriptionMethodFn<TMethodConfig, TUserPath extends string, TMethod extends string> = TMethod extends "GET" ? IsStrictSubscriptionOptionsRequired<TMethodConfig, TUserPath> extends true ? <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options: StrictSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TUserPath, TRequestedEvents> : <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options?: StrictSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TUserPath, TRequestedEvents> : <TRequestedEvents extends readonly (keyof ExtractEvents<TMethodConfig>)[]>(options?: LooseSubscriptionRequestOptions<TMethodConfig, TUserPath, TRequestedEvents>) => SubscriptionResponse<TMethodConfig, TUserPath, TRequestedEvents>;
1788
1790
  /**
1789
1791
  * Subscription path methods - only methods with events field.
1790
1792
  */
@@ -2460,6 +2462,7 @@ type InfiniteReadController<TData, TItem, TError, TMeta = Record<string, unknown
2460
2462
  fetchNext: () => Promise<void>;
2461
2463
  fetchPrev: () => Promise<void>;
2462
2464
  trigger: (options?: InfiniteTriggerOptions) => Promise<void>;
2465
+ refetch: () => Promise<void>;
2463
2466
  abort: () => void;
2464
2467
  mount: () => void;
2465
2468
  unmount: () => void;
package/dist/index.js CHANGED
@@ -1920,6 +1920,20 @@ function createInfiniteReadController(options) {
1920
1920
  }
1921
1921
  notify();
1922
1922
  },
1923
+ async refetch() {
1924
+ const firstPageKey = pageKeys[0];
1925
+ if (!firstPageKey) {
1926
+ await doFetch("next", {});
1927
+ return;
1928
+ }
1929
+ const firstPageRequest = pageRequests.get(firstPageKey) ?? initialRequest;
1930
+ pageSubscriptions.slice(1).forEach((unsub) => unsub());
1931
+ pageSubscriptions = pageSubscriptions.slice(0, 1);
1932
+ pageKeys = [firstPageKey];
1933
+ pageRequests = /* @__PURE__ */ new Map([[firstPageKey, firstPageRequest]]);
1934
+ stateManager.setCache(firstPageKey, { stale: true });
1935
+ await doFetch("next", firstPageRequest);
1936
+ },
1923
1937
  abort() {
1924
1938
  abortController?.abort();
1925
1939
  abortController = null;
@@ -2356,10 +2370,14 @@ function createSubscriptionController(options) {
2356
2370
  let handle = null;
2357
2371
  const subscribers = /* @__PURE__ */ new Set();
2358
2372
  let subscriptionVersion = 0;
2373
+ const messageQueue = [];
2374
+ let queueIndex = 0;
2359
2375
  let cachedState = {
2360
2376
  data: void 0,
2361
2377
  error: void 0,
2362
- isConnected: false
2378
+ isConnected: false,
2379
+ _messageQueue: messageQueue,
2380
+ _queueIndex: queueIndex
2363
2381
  };
2364
2382
  const updateStateFromHandle = () => {
2365
2383
  if (!handle) return;
@@ -2367,6 +2385,7 @@ function createSubscriptionController(options) {
2367
2385
  const newError = handle.getError();
2368
2386
  if (newData !== cachedState.data || newError !== cachedState.error) {
2369
2387
  cachedState = {
2388
+ ...cachedState,
2370
2389
  data: newData,
2371
2390
  error: newError,
2372
2391
  isConnected: true
@@ -2404,17 +2423,29 @@ function createSubscriptionController(options) {
2404
2423
  handle.unsubscribe();
2405
2424
  handle = null;
2406
2425
  }
2407
- cachedState = { data: void 0, error: void 0, isConnected: false };
2426
+ messageQueue.length = 0;
2427
+ queueIndex = 0;
2428
+ cachedState = {
2429
+ data: void 0,
2430
+ error: void 0,
2431
+ isConnected: false,
2432
+ _messageQueue: messageQueue,
2433
+ _queueIndex: queueIndex
2434
+ };
2408
2435
  notify();
2409
2436
  const ctx = createContext();
2410
2437
  ctx.onData = (data) => {
2411
2438
  if (thisVersion !== subscriptionVersion) {
2412
2439
  return;
2413
2440
  }
2441
+ messageQueue.push(data);
2442
+ queueIndex++;
2414
2443
  cachedState = {
2415
2444
  data,
2416
2445
  error: cachedState.error,
2417
- isConnected: true
2446
+ isConnected: true,
2447
+ _messageQueue: messageQueue,
2448
+ _queueIndex: queueIndex
2418
2449
  };
2419
2450
  notify();
2420
2451
  };
@@ -2423,9 +2454,8 @@ function createSubscriptionController(options) {
2423
2454
  return;
2424
2455
  }
2425
2456
  cachedState = {
2426
- data: cachedState.data,
2427
- error,
2428
- isConnected: cachedState.isConnected
2457
+ ...cachedState,
2458
+ error
2429
2459
  };
2430
2460
  notify();
2431
2461
  };
package/dist/index.mjs CHANGED
@@ -1843,6 +1843,20 @@ function createInfiniteReadController(options) {
1843
1843
  }
1844
1844
  notify();
1845
1845
  },
1846
+ async refetch() {
1847
+ const firstPageKey = pageKeys[0];
1848
+ if (!firstPageKey) {
1849
+ await doFetch("next", {});
1850
+ return;
1851
+ }
1852
+ const firstPageRequest = pageRequests.get(firstPageKey) ?? initialRequest;
1853
+ pageSubscriptions.slice(1).forEach((unsub) => unsub());
1854
+ pageSubscriptions = pageSubscriptions.slice(0, 1);
1855
+ pageKeys = [firstPageKey];
1856
+ pageRequests = /* @__PURE__ */ new Map([[firstPageKey, firstPageRequest]]);
1857
+ stateManager.setCache(firstPageKey, { stale: true });
1858
+ await doFetch("next", firstPageRequest);
1859
+ },
1846
1860
  abort() {
1847
1861
  abortController?.abort();
1848
1862
  abortController = null;
@@ -2279,10 +2293,14 @@ function createSubscriptionController(options) {
2279
2293
  let handle = null;
2280
2294
  const subscribers = /* @__PURE__ */ new Set();
2281
2295
  let subscriptionVersion = 0;
2296
+ const messageQueue = [];
2297
+ let queueIndex = 0;
2282
2298
  let cachedState = {
2283
2299
  data: void 0,
2284
2300
  error: void 0,
2285
- isConnected: false
2301
+ isConnected: false,
2302
+ _messageQueue: messageQueue,
2303
+ _queueIndex: queueIndex
2286
2304
  };
2287
2305
  const updateStateFromHandle = () => {
2288
2306
  if (!handle) return;
@@ -2290,6 +2308,7 @@ function createSubscriptionController(options) {
2290
2308
  const newError = handle.getError();
2291
2309
  if (newData !== cachedState.data || newError !== cachedState.error) {
2292
2310
  cachedState = {
2311
+ ...cachedState,
2293
2312
  data: newData,
2294
2313
  error: newError,
2295
2314
  isConnected: true
@@ -2327,17 +2346,29 @@ function createSubscriptionController(options) {
2327
2346
  handle.unsubscribe();
2328
2347
  handle = null;
2329
2348
  }
2330
- cachedState = { data: void 0, error: void 0, isConnected: false };
2349
+ messageQueue.length = 0;
2350
+ queueIndex = 0;
2351
+ cachedState = {
2352
+ data: void 0,
2353
+ error: void 0,
2354
+ isConnected: false,
2355
+ _messageQueue: messageQueue,
2356
+ _queueIndex: queueIndex
2357
+ };
2331
2358
  notify();
2332
2359
  const ctx = createContext();
2333
2360
  ctx.onData = (data) => {
2334
2361
  if (thisVersion !== subscriptionVersion) {
2335
2362
  return;
2336
2363
  }
2364
+ messageQueue.push(data);
2365
+ queueIndex++;
2337
2366
  cachedState = {
2338
2367
  data,
2339
2368
  error: cachedState.error,
2340
- isConnected: true
2369
+ isConnected: true,
2370
+ _messageQueue: messageQueue,
2371
+ _queueIndex: queueIndex
2341
2372
  };
2342
2373
  notify();
2343
2374
  };
@@ -2346,9 +2377,8 @@ function createSubscriptionController(options) {
2346
2377
  return;
2347
2378
  }
2348
2379
  cachedState = {
2349
- data: cachedState.data,
2350
- error,
2351
- isConnected: cachedState.isConnected
2380
+ ...cachedState,
2381
+ error
2352
2382
  };
2353
2383
  notify();
2354
2384
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/core",
3
- "version": "0.18.1",
3
+ "version": "0.18.3",
4
4
  "license": "MIT",
5
5
  "description": "Type-safe API toolkit with plugin middleware system",
6
6
  "keywords": [