@spoosh/react 0.4.0 → 0.5.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,17 +1,26 @@
1
1
  import * as _spoosh_core from '@spoosh/core';
2
- import { ReadClient, TagOptions, SpooshResponse, WriteClient, SpooshPlugin, PluginTypeConfig, SpooshOptions, MergePluginResults, StateManager, EventEmitter, PluginExecutor, PluginArray, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
2
+ import { ReadClient, TagMode, SpooshResponse, WriteClient, SpooshPlugin, PluginTypeConfig, SpooshOptions, MergePluginResults, StateManager, EventEmitter, PluginExecutor, PluginArray, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
3
3
 
4
4
  type PluginHooksConfig<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
5
5
  baseUrl: string;
6
6
  defaultOptions?: SpooshOptions;
7
7
  plugins: TPlugins;
8
8
  };
9
+ type TagModeInArray = "all" | "self";
9
10
  /**
10
11
  * Base options for `useRead` hook.
11
12
  */
12
- type BaseReadOptions = TagOptions & {
13
+ type BaseReadOptions = {
13
14
  /** Whether to fetch automatically on mount. Default: true */
14
15
  enabled?: boolean;
16
+ /**
17
+ * Unified tag option
18
+ * - String: mode only ('all' | 'self' | 'none')
19
+ * - Array: custom tags only OR [mode keyword mixed with custom tags]
20
+ * - 'all' or 'self' can be used in arrays
21
+ * - 'none' should only be used as string (use `tags: 'none'` not in array)
22
+ */
23
+ tags?: TagMode | (TagModeInArray | (string & {}))[];
15
24
  };
16
25
 
17
26
  /**
@@ -177,9 +186,17 @@ type InfinitePrevContext<TData, TRequest> = {
177
186
  * @template TItem - The item type after merging all responses
178
187
  * @template TRequest - The request options type (query, params, body)
179
188
  */
180
- type BaseInfiniteReadOptions<TData, TItem, TRequest = AnyInfiniteRequestOptions> = TagOptions & {
189
+ type BaseInfiniteReadOptions<TData, TItem, TRequest = AnyInfiniteRequestOptions> = {
181
190
  /** Whether to fetch automatically on mount. Default: true */
182
191
  enabled?: boolean;
192
+ /**
193
+ * Unified tag option
194
+ * - String: mode only ('all' | 'self' | 'none')
195
+ * - Array: custom tags only OR [mode keyword mixed with custom tags]
196
+ * - 'all' or 'self' can be used in arrays
197
+ * - 'none' should only be used as string (use `tags: 'none'` not in array)
198
+ */
199
+ tags?: TagMode | (TagModeInArray | (string & {}))[];
183
200
  /** Callback to determine if there's a next page to fetch */
184
201
  canFetchNext: (ctx: InfiniteNextContext<TData, TRequest>) => boolean;
185
202
  /** Callback to build the request options for the next page */
@@ -351,7 +368,7 @@ type SpooshInstanceShape<TApi, TSchema, TDefaultError, TPlugins> = {
351
368
  * const { useRead, useWrite, useInfiniteRead } = createReactSpoosh(spooshInstance);
352
369
  *
353
370
  * function MyComponent() {
354
- * const { data, loading } = useRead((api) => api.posts.$get());
371
+ * const { data, loading } = useRead((api) => api("posts").GET());
355
372
  * return <div>{loading ? 'Loading...' : data?.title}</div>;
356
373
  * }
357
374
  * ```
package/dist/index.d.ts CHANGED
@@ -1,17 +1,26 @@
1
1
  import * as _spoosh_core from '@spoosh/core';
2
- import { ReadClient, TagOptions, SpooshResponse, WriteClient, SpooshPlugin, PluginTypeConfig, SpooshOptions, MergePluginResults, StateManager, EventEmitter, PluginExecutor, PluginArray, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
2
+ import { ReadClient, TagMode, SpooshResponse, WriteClient, SpooshPlugin, PluginTypeConfig, SpooshOptions, MergePluginResults, StateManager, EventEmitter, PluginExecutor, PluginArray, MergePluginOptions, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
3
3
 
4
4
  type PluginHooksConfig<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
5
5
  baseUrl: string;
6
6
  defaultOptions?: SpooshOptions;
7
7
  plugins: TPlugins;
8
8
  };
9
+ type TagModeInArray = "all" | "self";
9
10
  /**
10
11
  * Base options for `useRead` hook.
11
12
  */
12
- type BaseReadOptions = TagOptions & {
13
+ type BaseReadOptions = {
13
14
  /** Whether to fetch automatically on mount. Default: true */
14
15
  enabled?: boolean;
16
+ /**
17
+ * Unified tag option
18
+ * - String: mode only ('all' | 'self' | 'none')
19
+ * - Array: custom tags only OR [mode keyword mixed with custom tags]
20
+ * - 'all' or 'self' can be used in arrays
21
+ * - 'none' should only be used as string (use `tags: 'none'` not in array)
22
+ */
23
+ tags?: TagMode | (TagModeInArray | (string & {}))[];
15
24
  };
16
25
 
17
26
  /**
@@ -177,9 +186,17 @@ type InfinitePrevContext<TData, TRequest> = {
177
186
  * @template TItem - The item type after merging all responses
178
187
  * @template TRequest - The request options type (query, params, body)
179
188
  */
180
- type BaseInfiniteReadOptions<TData, TItem, TRequest = AnyInfiniteRequestOptions> = TagOptions & {
189
+ type BaseInfiniteReadOptions<TData, TItem, TRequest = AnyInfiniteRequestOptions> = {
181
190
  /** Whether to fetch automatically on mount. Default: true */
182
191
  enabled?: boolean;
192
+ /**
193
+ * Unified tag option
194
+ * - String: mode only ('all' | 'self' | 'none')
195
+ * - Array: custom tags only OR [mode keyword mixed with custom tags]
196
+ * - 'all' or 'self' can be used in arrays
197
+ * - 'none' should only be used as string (use `tags: 'none'` not in array)
198
+ */
199
+ tags?: TagMode | (TagModeInArray | (string & {}))[];
183
200
  /** Callback to determine if there's a next page to fetch */
184
201
  canFetchNext: (ctx: InfiniteNextContext<TData, TRequest>) => boolean;
185
202
  /** Callback to build the request options for the next page */
@@ -351,7 +368,7 @@ type SpooshInstanceShape<TApi, TSchema, TDefaultError, TPlugins> = {
351
368
  * const { useRead, useWrite, useInfiniteRead } = createReactSpoosh(spooshInstance);
352
369
  *
353
370
  * function MyComponent() {
354
- * const { data, loading } = useRead((api) => api.posts.$get());
371
+ * const { data, loading } = useRead((api) => api("posts").GET());
355
372
  * return <div>{loading ? 'Loading...' : data?.title}</div>;
356
373
  * }
357
374
  * ```
package/dist/index.js CHANGED
@@ -35,12 +35,7 @@ var import_core = require("@spoosh/core");
35
35
  function createUseRead(options) {
36
36
  const { api, stateManager, eventEmitter, pluginExecutor } = options;
37
37
  return function useRead(readFn, readOptions) {
38
- const {
39
- enabled = true,
40
- tags,
41
- additionalTags,
42
- ...pluginOpts
43
- } = readOptions ?? {};
38
+ const { enabled = true, tags, ...pluginOpts } = readOptions ?? {};
44
39
  const hookId = (0, import_react.useId)();
45
40
  const selectorResultRef = (0, import_react.useRef)({
46
41
  call: null,
@@ -59,7 +54,7 @@ function createUseRead(options) {
59
54
  const requestOptions = capturedCall.options;
60
55
  const pathSegments = capturedCall.path.split("/").filter(Boolean);
61
56
  const resolvedPath = (0, import_core.resolvePath)(pathSegments, requestOptions?.params);
62
- const resolvedTags = (0, import_core.resolveTags)({ tags, additionalTags }, resolvedPath);
57
+ const resolvedTags = (0, import_core.resolveTags)({ tags }, resolvedPath);
63
58
  const queryKey = stateManager.createQueryKey({
64
59
  path: pathSegments,
65
60
  method: capturedCall.method,
@@ -331,7 +326,6 @@ function createUseInfiniteRead(options) {
331
326
  const {
332
327
  enabled = true,
333
328
  tags,
334
- additionalTags,
335
329
  canFetchNext,
336
330
  nextPageRequest,
337
331
  merger,
@@ -368,7 +362,7 @@ function createUseInfiniteRead(options) {
368
362
  body: void 0
369
363
  };
370
364
  const resolvedPath = (0, import_core3.resolvePath)(pathSegments, requestOptions?.params);
371
- const resolvedTags = (0, import_core3.resolveTags)({ tags, additionalTags }, resolvedPath);
365
+ const resolvedTags = (0, import_core3.resolveTags)({ tags }, resolvedPath);
372
366
  const canFetchNextRef = (0, import_react3.useRef)(canFetchNext);
373
367
  const canFetchPrevRef = (0, import_react3.useRef)(canFetchPrev);
374
368
  const nextPageRequestRef = (0, import_react3.useRef)(nextPageRequest);
package/dist/index.mjs CHANGED
@@ -19,12 +19,7 @@ import {
19
19
  function createUseRead(options) {
20
20
  const { api, stateManager, eventEmitter, pluginExecutor } = options;
21
21
  return function useRead(readFn, readOptions) {
22
- const {
23
- enabled = true,
24
- tags,
25
- additionalTags,
26
- ...pluginOpts
27
- } = readOptions ?? {};
22
+ const { enabled = true, tags, ...pluginOpts } = readOptions ?? {};
28
23
  const hookId = useId();
29
24
  const selectorResultRef = useRef({
30
25
  call: null,
@@ -43,7 +38,7 @@ function createUseRead(options) {
43
38
  const requestOptions = capturedCall.options;
44
39
  const pathSegments = capturedCall.path.split("/").filter(Boolean);
45
40
  const resolvedPath = resolvePath(pathSegments, requestOptions?.params);
46
- const resolvedTags = resolveTags({ tags, additionalTags }, resolvedPath);
41
+ const resolvedTags = resolveTags({ tags }, resolvedPath);
47
42
  const queryKey = stateManager.createQueryKey({
48
43
  path: pathSegments,
49
44
  method: capturedCall.method,
@@ -337,7 +332,6 @@ function createUseInfiniteRead(options) {
337
332
  const {
338
333
  enabled = true,
339
334
  tags,
340
- additionalTags,
341
335
  canFetchNext,
342
336
  nextPageRequest,
343
337
  merger,
@@ -374,7 +368,7 @@ function createUseInfiniteRead(options) {
374
368
  body: void 0
375
369
  };
376
370
  const resolvedPath = resolvePath3(pathSegments, requestOptions?.params);
377
- const resolvedTags = resolveTags3({ tags, additionalTags }, resolvedPath);
371
+ const resolvedTags = resolveTags3({ tags }, resolvedPath);
378
372
  const canFetchNextRef = useRef3(canFetchNext);
379
373
  const canFetchPrevRef = useRef3(canFetchPrev);
380
374
  const nextPageRequestRef = useRef3(nextPageRequest);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/react",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "description": "React hooks for Spoosh API client",
6
6
  "keywords": [
@@ -34,11 +34,11 @@
34
34
  }
35
35
  },
36
36
  "peerDependencies": {
37
- "@spoosh/core": ">=0.6.0",
37
+ "@spoosh/core": ">=0.7.0",
38
38
  "react": "^18 || ^19"
39
39
  },
40
40
  "devDependencies": {
41
- "@spoosh/core": "0.6.0"
41
+ "@spoosh/core": "0.7.0"
42
42
  },
43
43
  "scripts": {
44
44
  "dev": "tsup --watch",