@spoosh/react 0.14.1 → 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
@@ -1,4 +1,4 @@
1
- import { ReadClient, TagMode, SpooshResponse, ExtractTriggerQuery as ExtractTriggerQuery$3, ExtractTriggerBody as ExtractTriggerBody$3, ExtractTriggerParams as ExtractTriggerParams$3, SpooshPlugin, PluginTypeConfig, MergePluginResults, WriteSelectorClient, SpooshBody, QueueSelectorClient, QueueItem, QueueStats, InfiniteRequestOptions, InfiniteNextContext, InfinitePage, InfinitePrevContext, SubscriptionClient, SubscriptionAdapter, OperationType, StateManager, EventEmitter, PluginExecutor, SpooshTransport, PluginArray, ResolveTypes, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginApi, MethodOptionsMap, CoreRequestOptionsBase, SpooshClient, SpooshOptions } from '@spoosh/core';
1
+ import { ReadClient, SpooshResponse, ExtractTriggerQuery as ExtractTriggerQuery$3, ExtractTriggerBody as ExtractTriggerBody$3, ExtractTriggerParams as ExtractTriggerParams$3, SpooshPlugin, PluginTypeConfig, MergePluginResults, WriteSelectorClient, SpooshBody, QueueSelectorClient, QueueItem, QueueStats, InfiniteRequestOptions, InfiniteNextContext, InfinitePage, InfinitePrevContext, SubscriptionClient, SubscriptionAdapter, OperationType, StateManager, EventEmitter, PluginExecutor, SpooshTransport, PluginArray, ResolveTypes, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginApi, MethodOptionsMap, CoreRequestOptionsBase, SpooshClient, SpooshOptions } from '@spoosh/core';
2
2
 
3
3
  type SuccessResponse<T> = Extract<T, {
4
4
  data: unknown;
@@ -72,7 +72,6 @@ type ExtractSubscriptionError<T> = SubscriptionReturnType<T> extends {
72
72
  error: infer E;
73
73
  } ? E : unknown;
74
74
 
75
- type TagModeInArray$1 = "all" | "self";
76
75
  /**
77
76
  * Base options for `useRead` hook.
78
77
  */
@@ -80,13 +79,11 @@ type BaseReadOptions = {
80
79
  /** Whether to fetch automatically on mount. Default: true */
81
80
  enabled?: boolean;
82
81
  /**
83
- * Unified tag option
84
- * - String: mode only ('all' | 'self' | 'none')
85
- * - Array: custom tags only OR [mode keyword mixed with custom tags]
86
- * - 'all' or 'self' can be used in arrays
87
- * - 'none' should only be used as string (use `tags: 'none'` not in array)
82
+ * Custom tags for cache entry.
83
+ * Can be a single tag string or an array of tags.
84
+ * Default: auto-generated from path (e.g., "users/1")
88
85
  */
89
- tags?: TagMode | (TagModeInArray$1 | (string & {}))[];
86
+ tags?: string | string[];
90
87
  };
91
88
  type QueryField<TQuery> = [TQuery] extends [never] ? object : undefined extends TQuery ? {
92
89
  query?: Exclude<TQuery, undefined>;
@@ -291,7 +288,6 @@ type UseQueueResult<TData, TError, TTriggerInput, TMeta = object> = {
291
288
  */
292
289
  type QueueApiClient<TSchema, TDefaultError> = QueueSelectorClient<TSchema, TDefaultError>;
293
290
 
294
- type TagModeInArray = "all" | "self";
295
291
  type TriggerAwaitedReturn<T> = T extends (...args: never[]) => infer R ? Awaited<R> : never;
296
292
  type ExtractInputFromResponse<T> = T extends {
297
293
  input: infer I;
@@ -314,13 +310,11 @@ type BasePagesOptions<TData, TItem, TError = unknown, TRequest = InfiniteRequest
314
310
  /** Whether to fetch automatically on mount. Default: true */
315
311
  enabled?: boolean;
316
312
  /**
317
- * Unified tag option
318
- * - String: mode only ('all' | 'self' | 'none')
319
- * - Array: custom tags only OR [mode keyword mixed with custom tags]
320
- * - 'all' or 'self' can be used in arrays
321
- * - 'none' should only be used as string (use `tags: 'none'` not in array)
313
+ * Custom tags for cache entry.
314
+ * Can be a single tag string or an array of tags.
315
+ * Default: auto-generated from path (e.g., "posts/1")
322
316
  */
323
- tags?: TagMode | (TagModeInArray | (string & {}))[];
317
+ tags?: string | string[];
324
318
  /**
325
319
  * Callback to determine if there's a next page to fetch.
326
320
  * Receives the last page to check for pagination indicators.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ReadClient, TagMode, SpooshResponse, ExtractTriggerQuery as ExtractTriggerQuery$3, ExtractTriggerBody as ExtractTriggerBody$3, ExtractTriggerParams as ExtractTriggerParams$3, SpooshPlugin, PluginTypeConfig, MergePluginResults, WriteSelectorClient, SpooshBody, QueueSelectorClient, QueueItem, QueueStats, InfiniteRequestOptions, InfiniteNextContext, InfinitePage, InfinitePrevContext, SubscriptionClient, SubscriptionAdapter, OperationType, StateManager, EventEmitter, PluginExecutor, SpooshTransport, PluginArray, ResolveTypes, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginApi, MethodOptionsMap, CoreRequestOptionsBase, SpooshClient, SpooshOptions } from '@spoosh/core';
1
+ import { ReadClient, SpooshResponse, ExtractTriggerQuery as ExtractTriggerQuery$3, ExtractTriggerBody as ExtractTriggerBody$3, ExtractTriggerParams as ExtractTriggerParams$3, SpooshPlugin, PluginTypeConfig, MergePluginResults, WriteSelectorClient, SpooshBody, QueueSelectorClient, QueueItem, QueueStats, InfiniteRequestOptions, InfiniteNextContext, InfinitePage, InfinitePrevContext, SubscriptionClient, SubscriptionAdapter, OperationType, StateManager, EventEmitter, PluginExecutor, SpooshTransport, PluginArray, ResolveTypes, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginApi, MethodOptionsMap, CoreRequestOptionsBase, SpooshClient, SpooshOptions } from '@spoosh/core';
2
2
 
3
3
  type SuccessResponse<T> = Extract<T, {
4
4
  data: unknown;
@@ -72,7 +72,6 @@ type ExtractSubscriptionError<T> = SubscriptionReturnType<T> extends {
72
72
  error: infer E;
73
73
  } ? E : unknown;
74
74
 
75
- type TagModeInArray$1 = "all" | "self";
76
75
  /**
77
76
  * Base options for `useRead` hook.
78
77
  */
@@ -80,13 +79,11 @@ type BaseReadOptions = {
80
79
  /** Whether to fetch automatically on mount. Default: true */
81
80
  enabled?: boolean;
82
81
  /**
83
- * Unified tag option
84
- * - String: mode only ('all' | 'self' | 'none')
85
- * - Array: custom tags only OR [mode keyword mixed with custom tags]
86
- * - 'all' or 'self' can be used in arrays
87
- * - 'none' should only be used as string (use `tags: 'none'` not in array)
82
+ * Custom tags for cache entry.
83
+ * Can be a single tag string or an array of tags.
84
+ * Default: auto-generated from path (e.g., "users/1")
88
85
  */
89
- tags?: TagMode | (TagModeInArray$1 | (string & {}))[];
86
+ tags?: string | string[];
90
87
  };
91
88
  type QueryField<TQuery> = [TQuery] extends [never] ? object : undefined extends TQuery ? {
92
89
  query?: Exclude<TQuery, undefined>;
@@ -291,7 +288,6 @@ type UseQueueResult<TData, TError, TTriggerInput, TMeta = object> = {
291
288
  */
292
289
  type QueueApiClient<TSchema, TDefaultError> = QueueSelectorClient<TSchema, TDefaultError>;
293
290
 
294
- type TagModeInArray = "all" | "self";
295
291
  type TriggerAwaitedReturn<T> = T extends (...args: never[]) => infer R ? Awaited<R> : never;
296
292
  type ExtractInputFromResponse<T> = T extends {
297
293
  input: infer I;
@@ -314,13 +310,11 @@ type BasePagesOptions<TData, TItem, TError = unknown, TRequest = InfiniteRequest
314
310
  /** Whether to fetch automatically on mount. Default: true */
315
311
  enabled?: boolean;
316
312
  /**
317
- * Unified tag option
318
- * - String: mode only ('all' | 'self' | 'none')
319
- * - Array: custom tags only OR [mode keyword mixed with custom tags]
320
- * - 'all' or 'self' can be used in arrays
321
- * - 'none' should only be used as string (use `tags: 'none'` not in array)
313
+ * Custom tags for cache entry.
314
+ * Can be a single tag string or an array of tags.
315
+ * Default: auto-generated from path (e.g., "posts/1")
322
316
  */
323
- tags?: TagMode | (TagModeInArray | (string & {}))[];
317
+ tags?: string | string[];
324
318
  /**
325
319
  * Callback to determine if there's a next page to fetch.
326
320
  * Receives the last page to check for pagination indicators.
package/dist/index.js CHANGED
@@ -153,9 +153,9 @@ function createUseRead(options) {
153
153
  });
154
154
  const unsubInvalidate = eventEmitter.on(
155
155
  "invalidate",
156
- (invalidatedTags) => {
157
- const hasMatch = invalidatedTags.some(
158
- (tag) => resolvedTags.includes(tag)
156
+ (invalidatePatterns) => {
157
+ const hasMatch = resolvedTags.some(
158
+ (tag) => (0, import_core.matchTags)(tag, invalidatePatterns)
159
159
  );
160
160
  if (hasMatch) {
161
161
  executeWithTracking(true);
@@ -548,9 +548,9 @@ function createUsePages(options) {
548
548
  }
549
549
  const unsubInvalidate = eventEmitter.on(
550
550
  "invalidate",
551
- (invalidatedTags) => {
552
- const hasMatch = invalidatedTags.some(
553
- (tag) => resolvedTags.includes(tag)
551
+ (invalidatePatterns) => {
552
+ const hasMatch = resolvedTags.some(
553
+ (tag) => (0, import_core3.matchTags)(tag, invalidatePatterns)
554
554
  );
555
555
  if (hasMatch) {
556
556
  setIsPending(true);
package/dist/index.mjs CHANGED
@@ -13,7 +13,8 @@ import {
13
13
  createOperationController,
14
14
  createSelectorProxy,
15
15
  resolvePath,
16
- resolveTags
16
+ resolveTags,
17
+ matchTags
17
18
  } from "@spoosh/core";
18
19
  function createUseRead(options) {
19
20
  const { api, stateManager, eventEmitter, pluginExecutor } = options;
@@ -140,9 +141,9 @@ function createUseRead(options) {
140
141
  });
141
142
  const unsubInvalidate = eventEmitter.on(
142
143
  "invalidate",
143
- (invalidatedTags) => {
144
- const hasMatch = invalidatedTags.some(
145
- (tag) => resolvedTags.includes(tag)
144
+ (invalidatePatterns) => {
145
+ const hasMatch = resolvedTags.some(
146
+ (tag) => matchTags(tag, invalidatePatterns)
146
147
  );
147
148
  if (hasMatch) {
148
149
  executeWithTracking(true);
@@ -415,7 +416,8 @@ import {
415
416
  createInfiniteReadController,
416
417
  createSelectorProxy as createSelectorProxy3,
417
418
  resolvePath as resolvePath3,
418
- resolveTags as resolveTags3
419
+ resolveTags as resolveTags3,
420
+ matchTags as matchTags2
419
421
  } from "@spoosh/core";
420
422
  function createUsePages(options) {
421
423
  const { api, stateManager, eventEmitter, pluginExecutor } = options;
@@ -558,9 +560,9 @@ function createUsePages(options) {
558
560
  }
559
561
  const unsubInvalidate = eventEmitter.on(
560
562
  "invalidate",
561
- (invalidatedTags) => {
562
- const hasMatch = invalidatedTags.some(
563
- (tag) => resolvedTags.includes(tag)
563
+ (invalidatePatterns) => {
564
+ const hasMatch = resolvedTags.some(
565
+ (tag) => matchTags2(tag, invalidatePatterns)
564
566
  );
565
567
  if (hasMatch) {
566
568
  setIsPending(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/react",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
4
  "license": "MIT",
5
5
  "description": "React hooks for Spoosh API toolkit",
6
6
  "keywords": [
@@ -34,7 +34,7 @@
34
34
  }
35
35
  },
36
36
  "peerDependencies": {
37
- "@spoosh/core": ">=0.17.1",
37
+ "@spoosh/core": ">=0.18.0",
38
38
  "@spoosh/transport-sse": ">=0.1.0",
39
39
  "react": "^18 || ^19"
40
40
  },
@@ -46,7 +46,7 @@
46
46
  "devDependencies": {
47
47
  "@testing-library/react": "^16.0.0",
48
48
  "jsdom": "^26.0.0",
49
- "@spoosh/core": "0.17.1",
49
+ "@spoosh/core": "0.18.0",
50
50
  "@spoosh/transport-sse": "0.1.1",
51
51
  "@spoosh/test-utils": "0.3.0"
52
52
  },