yuustate 3.10.2 → 3.11.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.
@@ -72,7 +72,11 @@ type Internal<TData, TError> = {
72
72
  garbageCollectionTimeoutId?: number;
73
73
  rollbackData?: TData | undefined;
74
74
  };
75
- type AdditionalStoreApi<TData, TError> = {
75
+ type AdditionalStoreApi<TData, TError, TVariable extends StoreKey = never> = {
76
+ /**
77
+ * The original query variable used to create this store.
78
+ */
79
+ variable: TVariable;
76
80
  /**
77
81
  * A deterministic hash string derived from the query variable.
78
82
  *
@@ -205,7 +209,7 @@ type AdditionalStoreApi<TData, TError> = {
205
209
  * @remarks
206
210
  * Controls caching, retry behavior, lifecycle, and side effects of an async operation.
207
211
  */
208
- export type QueryOptions<TData, TVariable extends StoreKey, TError = Error> = InitStoreOptions<QueryState<TData, TError>, AdditionalStoreApi<TData, TError>> & {
212
+ export type QueryOptions<TData, TVariable extends StoreKey, TError = Error> = InitStoreOptions<QueryState<TData, TError>, AdditionalStoreApi<TData, TError, TVariable>> & {
209
213
  /**
210
214
  * Time (in milliseconds) that data is considered fresh.
211
215
  *
@@ -357,6 +361,10 @@ export declare const createQuery: <TData, TVariable extends StoreKey = never, TE
357
361
  getState: () => QueryState<TData, TError>;
358
362
  subscribe: (subscriber: import("../vanilla.d.mts").Subscriber<QueryState<TData, TError>>) => () => void;
359
363
  getSubscriberCount: () => number;
364
+ /**
365
+ * The original query variable used to create this store.
366
+ */
367
+ variable: TVariable;
360
368
  /**
361
369
  * A deterministic hash string derived from the query variable.
362
370
  *
@@ -490,6 +498,15 @@ export declare const createQuery: <TData, TVariable extends StoreKey = never, TE
490
498
  * - Useful for bulk refetching.
491
499
  */
492
500
  executeAll: (options?: {
501
+ /**
502
+ * Optional predicate to select which query to execute.
503
+ */
504
+ filter?: (variable: TVariable) => boolean;
505
+ /**
506
+ * Whether to start a new execution instead of reusing an ongoing one.
507
+ *
508
+ * @default true
509
+ */
493
510
  overwriteOngoingExecution?: boolean;
494
511
  }) => void;
495
512
  /**
@@ -499,6 +516,15 @@ export declare const createQuery: <TData, TVariable extends StoreKey = never, TE
499
516
  * - Only re-fetches stale queries.
500
517
  */
501
518
  revalidateAll: (options?: {
519
+ /**
520
+ * Optional predicate to select which query to revalidate.
521
+ */
522
+ filter?: (variable: TVariable) => boolean;
523
+ /**
524
+ * Whether to start a new execution instead of reusing an ongoing one.
525
+ *
526
+ * @default true
527
+ */
502
528
  overwriteOngoingExecution?: boolean;
503
529
  }) => void;
504
530
  /**
@@ -509,11 +535,25 @@ export declare const createQuery: <TData, TVariable extends StoreKey = never, TE
509
535
  * - Invalidated queries bypass `staleTime` until successfully executed again.
510
536
  */
511
537
  invalidateAll: (options?: {
538
+ /**
539
+ * Optional predicate to select which query to invalidate.
540
+ */
541
+ filter?: (variable: TVariable) => boolean;
542
+ /**
543
+ * Whether to start a new execution instead of reusing an ongoing one.
544
+ *
545
+ * @default true
546
+ */
512
547
  overwriteOngoingExecution?: boolean;
513
548
  }) => void;
514
549
  /**
515
550
  * Resets all query instances.
516
551
  */
517
- resetAll: () => void;
552
+ resetAll: (options?: {
553
+ /**
554
+ * Optional predicate to select which query to reset.
555
+ */
556
+ filter?: (variable: TVariable) => boolean;
557
+ }) => void;
518
558
  };
519
559
  export {};
package/esm/react.mjs CHANGED
@@ -118,6 +118,7 @@ const createStores = (initialState, options) => {
118
118
  let store;
119
119
  if (stores.has(keyHash)) {
120
120
  store = stores.get(keyHash);
121
+ store.key = key;
121
122
  } else {
122
123
  store = initStore(
123
124
  initialState,
@@ -417,12 +418,14 @@ const createQuery = (queryFn, options = {}) => {
417
418
  let store;
418
419
  if (stores.has(variableHash)) {
419
420
  store = stores.get(variableHash);
421
+ store.variable = variable;
420
422
  } else {
421
423
  store = initStore(
422
424
  initialState,
423
425
  configureStoreEvents(variableHash)
424
426
  // Intentionally using as any: don't want to add generic on `initStore`
425
427
  );
428
+ store.variable = variable;
426
429
  store.variableHash = variableHash;
427
430
  stores.set(variableHash, store);
428
431
  const apis = getApis(store, variable);
@@ -522,6 +525,7 @@ const createQuery = (queryFn, options = {}) => {
522
525
  }
523
526
  });
524
527
  };
528
+ const shouldApplyToStore = (store, filter) => filter ? filter(store.variable) : true;
525
529
  return Object.assign(getStore, {
526
530
  /**
527
531
  * Executes all query instances.
@@ -529,8 +533,12 @@ const createQuery = (queryFn, options = {}) => {
529
533
  * @remarks
530
534
  * - Useful for bulk refetching.
531
535
  */
532
- executeAll: (options2) => {
533
- stores.forEach((store) => store.execute(options2));
536
+ executeAll: (options2 = {}) => {
537
+ const { filter, ...restOptions } = options2;
538
+ stores.forEach((store) => {
539
+ if (!shouldApplyToStore(store, filter)) return;
540
+ store.execute(restOptions);
541
+ });
534
542
  },
535
543
  /**
536
544
  * Revalidates all query instances.
@@ -538,8 +546,12 @@ const createQuery = (queryFn, options = {}) => {
538
546
  * @remarks
539
547
  * - Only re-fetches stale queries.
540
548
  */
541
- revalidateAll: (options2) => {
542
- stores.forEach((store) => store.revalidate(options2));
549
+ revalidateAll: (options2 = {}) => {
550
+ const { filter, ...restOptions } = options2;
551
+ stores.forEach((store) => {
552
+ if (!shouldApplyToStore(store, filter)) return;
553
+ store.revalidate(restOptions);
554
+ });
543
555
  },
544
556
  /**
545
557
  * Invalidates all query instances.
@@ -548,14 +560,22 @@ const createQuery = (queryFn, options = {}) => {
548
560
  * - Marks all queries as invalidated and triggers revalidation if active.
549
561
  * - Invalidated queries bypass `staleTime` until successfully executed again.
550
562
  */
551
- invalidateAll: (options2) => {
552
- stores.forEach((store) => store.invalidate(options2));
563
+ invalidateAll: (options2 = {}) => {
564
+ const { filter, ...restOptions } = options2;
565
+ stores.forEach((store) => {
566
+ if (!shouldApplyToStore(store, filter)) return;
567
+ store.invalidate(restOptions);
568
+ });
553
569
  },
554
570
  /**
555
571
  * Resets all query instances.
556
572
  */
557
- resetAll: () => {
558
- stores.forEach((store) => store.reset());
573
+ resetAll: (options2 = {}) => {
574
+ const { filter } = options2;
575
+ stores.forEach((store) => {
576
+ if (!shouldApplyToStore(store, filter)) return;
577
+ store.reset();
578
+ });
559
579
  }
560
580
  });
561
581
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "yuustate",
3
3
  "description": "Lightweight unified state management for sync and async data.",
4
4
  "private": false,
5
- "version": "3.10.2",
5
+ "version": "3.11.0",
6
6
  "keywords": [
7
7
  "utilities",
8
8
  "store",
@@ -72,7 +72,11 @@ type Internal<TData, TError> = {
72
72
  garbageCollectionTimeoutId?: number;
73
73
  rollbackData?: TData | undefined;
74
74
  };
75
- type AdditionalStoreApi<TData, TError> = {
75
+ type AdditionalStoreApi<TData, TError, TVariable extends StoreKey = never> = {
76
+ /**
77
+ * The original query variable used to create this store.
78
+ */
79
+ variable: TVariable;
76
80
  /**
77
81
  * A deterministic hash string derived from the query variable.
78
82
  *
@@ -205,7 +209,7 @@ type AdditionalStoreApi<TData, TError> = {
205
209
  * @remarks
206
210
  * Controls caching, retry behavior, lifecycle, and side effects of an async operation.
207
211
  */
208
- export type QueryOptions<TData, TVariable extends StoreKey, TError = Error> = InitStoreOptions<QueryState<TData, TError>, AdditionalStoreApi<TData, TError>> & {
212
+ export type QueryOptions<TData, TVariable extends StoreKey, TError = Error> = InitStoreOptions<QueryState<TData, TError>, AdditionalStoreApi<TData, TError, TVariable>> & {
209
213
  /**
210
214
  * Time (in milliseconds) that data is considered fresh.
211
215
  *
@@ -357,6 +361,10 @@ export declare const createQuery: <TData, TVariable extends StoreKey = never, TE
357
361
  getState: () => QueryState<TData, TError>;
358
362
  subscribe: (subscriber: import("../vanilla.ts").Subscriber<QueryState<TData, TError>>) => () => void;
359
363
  getSubscriberCount: () => number;
364
+ /**
365
+ * The original query variable used to create this store.
366
+ */
367
+ variable: TVariable;
360
368
  /**
361
369
  * A deterministic hash string derived from the query variable.
362
370
  *
@@ -490,6 +498,15 @@ export declare const createQuery: <TData, TVariable extends StoreKey = never, TE
490
498
  * - Useful for bulk refetching.
491
499
  */
492
500
  executeAll: (options?: {
501
+ /**
502
+ * Optional predicate to select which query to execute.
503
+ */
504
+ filter?: (variable: TVariable) => boolean;
505
+ /**
506
+ * Whether to start a new execution instead of reusing an ongoing one.
507
+ *
508
+ * @default true
509
+ */
493
510
  overwriteOngoingExecution?: boolean;
494
511
  }) => void;
495
512
  /**
@@ -499,6 +516,15 @@ export declare const createQuery: <TData, TVariable extends StoreKey = never, TE
499
516
  * - Only re-fetches stale queries.
500
517
  */
501
518
  revalidateAll: (options?: {
519
+ /**
520
+ * Optional predicate to select which query to revalidate.
521
+ */
522
+ filter?: (variable: TVariable) => boolean;
523
+ /**
524
+ * Whether to start a new execution instead of reusing an ongoing one.
525
+ *
526
+ * @default true
527
+ */
502
528
  overwriteOngoingExecution?: boolean;
503
529
  }) => void;
504
530
  /**
@@ -509,11 +535,25 @@ export declare const createQuery: <TData, TVariable extends StoreKey = never, TE
509
535
  * - Invalidated queries bypass `staleTime` until successfully executed again.
510
536
  */
511
537
  invalidateAll: (options?: {
538
+ /**
539
+ * Optional predicate to select which query to invalidate.
540
+ */
541
+ filter?: (variable: TVariable) => boolean;
542
+ /**
543
+ * Whether to start a new execution instead of reusing an ongoing one.
544
+ *
545
+ * @default true
546
+ */
512
547
  overwriteOngoingExecution?: boolean;
513
548
  }) => void;
514
549
  /**
515
550
  * Resets all query instances.
516
551
  */
517
- resetAll: () => void;
552
+ resetAll: (options?: {
553
+ /**
554
+ * Optional predicate to select which query to reset.
555
+ */
556
+ filter?: (variable: TVariable) => boolean;
557
+ }) => void;
518
558
  };
519
559
  export {};
package/react.js CHANGED
@@ -120,6 +120,7 @@ const createStores = (initialState, options) => {
120
120
  let store;
121
121
  if (stores.has(keyHash)) {
122
122
  store = stores.get(keyHash);
123
+ store.key = key;
123
124
  } else {
124
125
  store = vanilla.initStore(
125
126
  initialState,
@@ -419,12 +420,14 @@ const createQuery = (queryFn, options = {}) => {
419
420
  let store;
420
421
  if (stores.has(variableHash)) {
421
422
  store = stores.get(variableHash);
423
+ store.variable = variable;
422
424
  } else {
423
425
  store = vanilla.initStore(
424
426
  initialState,
425
427
  configureStoreEvents(variableHash)
426
428
  // Intentionally using as any: don't want to add generic on `initStore`
427
429
  );
430
+ store.variable = variable;
428
431
  store.variableHash = variableHash;
429
432
  stores.set(variableHash, store);
430
433
  const apis = getApis(store, variable);
@@ -524,6 +527,7 @@ const createQuery = (queryFn, options = {}) => {
524
527
  }
525
528
  });
526
529
  };
530
+ const shouldApplyToStore = (store, filter) => filter ? filter(store.variable) : true;
527
531
  return Object.assign(getStore, {
528
532
  /**
529
533
  * Executes all query instances.
@@ -531,8 +535,12 @@ const createQuery = (queryFn, options = {}) => {
531
535
  * @remarks
532
536
  * - Useful for bulk refetching.
533
537
  */
534
- executeAll: (options2) => {
535
- stores.forEach((store) => store.execute(options2));
538
+ executeAll: (options2 = {}) => {
539
+ const { filter, ...restOptions } = options2;
540
+ stores.forEach((store) => {
541
+ if (!shouldApplyToStore(store, filter)) return;
542
+ store.execute(restOptions);
543
+ });
536
544
  },
537
545
  /**
538
546
  * Revalidates all query instances.
@@ -540,8 +548,12 @@ const createQuery = (queryFn, options = {}) => {
540
548
  * @remarks
541
549
  * - Only re-fetches stale queries.
542
550
  */
543
- revalidateAll: (options2) => {
544
- stores.forEach((store) => store.revalidate(options2));
551
+ revalidateAll: (options2 = {}) => {
552
+ const { filter, ...restOptions } = options2;
553
+ stores.forEach((store) => {
554
+ if (!shouldApplyToStore(store, filter)) return;
555
+ store.revalidate(restOptions);
556
+ });
545
557
  },
546
558
  /**
547
559
  * Invalidates all query instances.
@@ -550,14 +562,22 @@ const createQuery = (queryFn, options = {}) => {
550
562
  * - Marks all queries as invalidated and triggers revalidation if active.
551
563
  * - Invalidated queries bypass `staleTime` until successfully executed again.
552
564
  */
553
- invalidateAll: (options2) => {
554
- stores.forEach((store) => store.invalidate(options2));
565
+ invalidateAll: (options2 = {}) => {
566
+ const { filter, ...restOptions } = options2;
567
+ stores.forEach((store) => {
568
+ if (!shouldApplyToStore(store, filter)) return;
569
+ store.invalidate(restOptions);
570
+ });
555
571
  },
556
572
  /**
557
573
  * Resets all query instances.
558
574
  */
559
- resetAll: () => {
560
- stores.forEach((store) => store.reset());
575
+ resetAll: (options2 = {}) => {
576
+ const { filter } = options2;
577
+ stores.forEach((store) => {
578
+ if (!shouldApplyToStore(store, filter)) return;
579
+ store.reset();
580
+ });
561
581
  }
562
582
  });
563
583
  };