@spoosh/core 0.18.2 → 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
  */
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
  */
package/dist/index.js CHANGED
@@ -2370,10 +2370,14 @@ function createSubscriptionController(options) {
2370
2370
  let handle = null;
2371
2371
  const subscribers = /* @__PURE__ */ new Set();
2372
2372
  let subscriptionVersion = 0;
2373
+ const messageQueue = [];
2374
+ let queueIndex = 0;
2373
2375
  let cachedState = {
2374
2376
  data: void 0,
2375
2377
  error: void 0,
2376
- isConnected: false
2378
+ isConnected: false,
2379
+ _messageQueue: messageQueue,
2380
+ _queueIndex: queueIndex
2377
2381
  };
2378
2382
  const updateStateFromHandle = () => {
2379
2383
  if (!handle) return;
@@ -2381,6 +2385,7 @@ function createSubscriptionController(options) {
2381
2385
  const newError = handle.getError();
2382
2386
  if (newData !== cachedState.data || newError !== cachedState.error) {
2383
2387
  cachedState = {
2388
+ ...cachedState,
2384
2389
  data: newData,
2385
2390
  error: newError,
2386
2391
  isConnected: true
@@ -2418,17 +2423,29 @@ function createSubscriptionController(options) {
2418
2423
  handle.unsubscribe();
2419
2424
  handle = null;
2420
2425
  }
2421
- 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
+ };
2422
2435
  notify();
2423
2436
  const ctx = createContext();
2424
2437
  ctx.onData = (data) => {
2425
2438
  if (thisVersion !== subscriptionVersion) {
2426
2439
  return;
2427
2440
  }
2441
+ messageQueue.push(data);
2442
+ queueIndex++;
2428
2443
  cachedState = {
2429
2444
  data,
2430
2445
  error: cachedState.error,
2431
- isConnected: true
2446
+ isConnected: true,
2447
+ _messageQueue: messageQueue,
2448
+ _queueIndex: queueIndex
2432
2449
  };
2433
2450
  notify();
2434
2451
  };
@@ -2437,9 +2454,8 @@ function createSubscriptionController(options) {
2437
2454
  return;
2438
2455
  }
2439
2456
  cachedState = {
2440
- data: cachedState.data,
2441
- error,
2442
- isConnected: cachedState.isConnected
2457
+ ...cachedState,
2458
+ error
2443
2459
  };
2444
2460
  notify();
2445
2461
  };
package/dist/index.mjs CHANGED
@@ -2293,10 +2293,14 @@ function createSubscriptionController(options) {
2293
2293
  let handle = null;
2294
2294
  const subscribers = /* @__PURE__ */ new Set();
2295
2295
  let subscriptionVersion = 0;
2296
+ const messageQueue = [];
2297
+ let queueIndex = 0;
2296
2298
  let cachedState = {
2297
2299
  data: void 0,
2298
2300
  error: void 0,
2299
- isConnected: false
2301
+ isConnected: false,
2302
+ _messageQueue: messageQueue,
2303
+ _queueIndex: queueIndex
2300
2304
  };
2301
2305
  const updateStateFromHandle = () => {
2302
2306
  if (!handle) return;
@@ -2304,6 +2308,7 @@ function createSubscriptionController(options) {
2304
2308
  const newError = handle.getError();
2305
2309
  if (newData !== cachedState.data || newError !== cachedState.error) {
2306
2310
  cachedState = {
2311
+ ...cachedState,
2307
2312
  data: newData,
2308
2313
  error: newError,
2309
2314
  isConnected: true
@@ -2341,17 +2346,29 @@ function createSubscriptionController(options) {
2341
2346
  handle.unsubscribe();
2342
2347
  handle = null;
2343
2348
  }
2344
- 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
+ };
2345
2358
  notify();
2346
2359
  const ctx = createContext();
2347
2360
  ctx.onData = (data) => {
2348
2361
  if (thisVersion !== subscriptionVersion) {
2349
2362
  return;
2350
2363
  }
2364
+ messageQueue.push(data);
2365
+ queueIndex++;
2351
2366
  cachedState = {
2352
2367
  data,
2353
2368
  error: cachedState.error,
2354
- isConnected: true
2369
+ isConnected: true,
2370
+ _messageQueue: messageQueue,
2371
+ _queueIndex: queueIndex
2355
2372
  };
2356
2373
  notify();
2357
2374
  };
@@ -2360,9 +2377,8 @@ function createSubscriptionController(options) {
2360
2377
  return;
2361
2378
  }
2362
2379
  cachedState = {
2363
- data: cachedState.data,
2364
- error,
2365
- isConnected: cachedState.isConnected
2380
+ ...cachedState,
2381
+ error
2366
2382
  };
2367
2383
  notify();
2368
2384
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/core",
3
- "version": "0.18.2",
3
+ "version": "0.18.3",
4
4
  "license": "MIT",
5
5
  "description": "Type-safe API toolkit with plugin middleware system",
6
6
  "keywords": [