@seamapi/react 4.10.0 → 4.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.
@@ -12,6 +12,7 @@ export * from './devices/use-device-providers.js';
12
12
  export * from './devices/use-devices.js';
13
13
  export * from './SeamProvider.js';
14
14
  export * from './use-seam-client.js';
15
+ export * from './use-seam-infinite-query.js';
15
16
  export * from './use-seam-mutation.js';
16
17
  export * from './use-seam-mutation-without-workspace.js';
17
18
  export * from './use-seam-query.js';
package/lib/seam/index.js CHANGED
@@ -12,6 +12,7 @@ export * from './devices/use-device-providers.js';
12
12
  export * from './devices/use-devices.js';
13
13
  export * from './SeamProvider.js';
14
14
  export * from './use-seam-client.js';
15
+ export * from './use-seam-infinite-query.js';
15
16
  export * from './use-seam-mutation.js';
16
17
  export * from './use-seam-mutation-without-workspace.js';
17
18
  export * from './use-seam-query.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/seam/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA;AACjD,cAAc,oCAAoC,CAAA;AAClD,cAAc,0CAA0C,CAAA;AACxD,cAAc,0CAA0C,CAAA;AACxD,cAAc,iDAAiD,CAAA;AAC/D,cAAc,0CAA0C,CAAA;AACxD,cAAc,yCAAyC,CAAA;AACvD,cAAc,kDAAkD,CAAA;AAChE,cAAc,+CAA+C,CAAA;AAC7D,cAAc,yBAAyB,CAAA;AACvC,cAAc,mCAAmC,CAAA;AACjD,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0CAA0C,CAAA;AACxD,cAAc,qBAAqB,CAAA;AACnC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,uCAAuC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/seam/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA;AACjD,cAAc,oCAAoC,CAAA;AAClD,cAAc,0CAA0C,CAAA;AACxD,cAAc,0CAA0C,CAAA;AACxD,cAAc,iDAAiD,CAAA;AAC/D,cAAc,0CAA0C,CAAA;AACxD,cAAc,yCAAyC,CAAA;AACvD,cAAc,kDAAkD,CAAA;AAChE,cAAc,+CAA+C,CAAA;AAC7D,cAAc,yBAAyB,CAAA;AACvC,cAAc,mCAAmC,CAAA;AACjD,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,0CAA0C,CAAA;AACxD,cAAc,qBAAqB,CAAA;AACnC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,uCAAuC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { SeamHttpApiError, SeamHttpEndpointPaginatedQueryPaths, SeamHttpEndpoints, SeamPageCursor } from '@seamapi/http/connect';
2
+ import { type UseInfiniteQueryOptions, type UseInfiniteQueryResult } from '@tanstack/react-query';
3
+ export type UseSeamInfiniteQueryParameters<T extends SeamHttpEndpointPaginatedQueryPaths> = Parameters<SeamHttpEndpoints[T]>[0];
4
+ export type UseSeamInfiniteQueryResult<T extends SeamHttpEndpointPaginatedQueryPaths> = UseInfiniteQueryResult<QueryData<T>, SeamHttpApiError>;
5
+ export declare function useSeamInfiniteQuery<T extends SeamHttpEndpointPaginatedQueryPaths>(endpointPath: T, parameters?: UseSeamInfiniteQueryParameters<T>, options?: Parameters<SeamHttpEndpoints[T]>[1] & QueryOptions<QueryData<T>, SeamHttpApiError>): UseSeamInfiniteQueryResult<T>;
6
+ interface QueryData<T extends SeamHttpEndpointPaginatedQueryPaths> {
7
+ data: Awaited<ReturnType<SeamHttpEndpoints[T]>>;
8
+ nextPageCursor: SeamPageCursor | null;
9
+ }
10
+ type QueryOptions<X, Y> = Omit<UseInfiniteQueryOptions<X, Y>, 'queryKey' | 'queryFn' | 'initialPageParam' | 'getNextPageParam'>;
11
+ export {};
@@ -0,0 +1,42 @@
1
+ import { useInfiniteQuery, } from '@tanstack/react-query';
2
+ import { useSeamClient } from '../../lib/seam/use-seam-client.js';
3
+ export function useSeamInfiniteQuery(endpointPath, parameters, options = {}) {
4
+ const { endpointClient: client, queryKeyPrefixes } = useSeamClient();
5
+ return useInfiniteQuery({
6
+ enabled: client != null,
7
+ ...options,
8
+ queryKey: [
9
+ ...queryKeyPrefixes,
10
+ ...endpointPath.split('/').filter((v) => v !== ''),
11
+ parameters,
12
+ ],
13
+ initialPageParam: null,
14
+ getNextPageParam: (lastPage) => lastPage.nextPageCursor,
15
+ queryFn: async ({ pageParam }) => {
16
+ if (client == null)
17
+ return {
18
+ data: [],
19
+ nextPageCursor: null,
20
+ };
21
+ // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
22
+ // Type assertion is needed here for performance reasons. The types are correct at runtime.
23
+ const endpoint = client[endpointPath];
24
+ const request = endpoint(parameters, options);
25
+ const pages = client.createPaginator(request);
26
+ if (pageParam == null) {
27
+ const [data, { nextPageCursor }] = await pages.firstPage();
28
+ return {
29
+ data: data,
30
+ nextPageCursor,
31
+ };
32
+ }
33
+ // Type assertion is needed for pageParam since the Seam API expects a branded PageCursor type.
34
+ const [data, { nextPageCursor }] = await pages.nextPage(pageParam);
35
+ return {
36
+ data: data,
37
+ nextPageCursor,
38
+ };
39
+ },
40
+ });
41
+ }
42
+ //# sourceMappingURL=use-seam-infinite-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-seam-infinite-query.js","sourceRoot":"","sources":["../../src/lib/seam/use-seam-infinite-query.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,gBAAgB,GAGjB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAU3D,MAAM,UAAU,oBAAoB,CAGlC,YAAe,EACf,UAA8C,EAC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aACf,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -2,7 +2,7 @@ import type { SeamHttpApiError, SeamHttpEndpointsWithoutWorkspace, SeamHttpEndpo
2
2
  import { type UseMutationOptions, type UseMutationResult } from '@tanstack/react-query';
3
3
  export type UseSeamMutationWithoutWorkspaceVariables<T extends SeamHttpEndpointWithoutWorkspaceMutationPaths> = Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[0];
4
4
  export type UseSeamMutationWithoutWorkspaceResult<T extends SeamHttpEndpointWithoutWorkspaceMutationPaths> = UseMutationResult<MutationData<T>, SeamHttpApiError, UseSeamMutationWithoutWorkspaceVariables<T>>;
5
- export declare function UseSeamMutationWithoutWorkspace<T extends SeamHttpEndpointWithoutWorkspaceMutationPaths>(endpointPath: T, options?: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] & MutationOptions<MutationData<T>, SeamHttpApiError, UseSeamMutationWithoutWorkspaceVariables<T>>): UseSeamMutationWithoutWorkspaceResult<T>;
5
+ export declare function useSeamMutationWithoutWorkspace<T extends SeamHttpEndpointWithoutWorkspaceMutationPaths>(endpointPath: T, options?: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] & MutationOptions<MutationData<T>, SeamHttpApiError, UseSeamMutationWithoutWorkspaceVariables<T>>): UseSeamMutationWithoutWorkspaceResult<T>;
6
6
  type MutationData<T extends SeamHttpEndpointWithoutWorkspaceMutationPaths> = Awaited<ReturnType<SeamHttpEndpointsWithoutWorkspace[T]>>;
7
7
  type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>;
8
8
  export {};
@@ -1,6 +1,6 @@
1
1
  import { useMutation, } from '@tanstack/react-query';
2
2
  import { NullSeamClientError, useSeamClient } from '../../lib/seam/use-seam-client.js';
3
- export function UseSeamMutationWithoutWorkspace(endpointPath, options = {}) {
3
+ export function useSeamMutationWithoutWorkspace(endpointPath, options = {}) {
4
4
  const { endpointClient: client } = useSeamClient();
5
5
  return useMutation({
6
6
  ...options,
package/lib/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const seamapiReactVersion = "4.10.0";
1
+ declare const seamapiReactVersion = "4.11.0";
2
2
  export default seamapiReactVersion;
package/lib/version.js CHANGED
@@ -1,3 +1,3 @@
1
- const seamapiReactVersion = '4.10.0';
1
+ const seamapiReactVersion = '4.11.0';
2
2
  export default seamapiReactVersion;
3
3
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamapi/react",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
4
4
  "description": "Seam Components.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -145,7 +145,7 @@
145
145
  "@rxfork/r2wc-react-to-web-component": "^2.4.0",
146
146
  "@seamapi/fake-devicedb": "^1.6.1",
147
147
  "@seamapi/fake-seam-connect": "^1.76.0",
148
- "@seamapi/http": "^1.40.0",
148
+ "@seamapi/http": "^1.40.1",
149
149
  "@seamapi/types": "^1.395.3",
150
150
  "@storybook/addon-designs": "^7.0.1",
151
151
  "@storybook/addon-essentials": "^7.0.2",
@@ -12,6 +12,7 @@ export * from './devices/use-device-providers.js'
12
12
  export * from './devices/use-devices.js'
13
13
  export * from './SeamProvider.js'
14
14
  export * from './use-seam-client.js'
15
+ export * from './use-seam-infinite-query.js'
15
16
  export * from './use-seam-mutation.js'
16
17
  export * from './use-seam-mutation-without-workspace.js'
17
18
  export * from './use-seam-query.js'
@@ -0,0 +1,81 @@
1
+ import type {
2
+ SeamHttpApiError,
3
+ SeamHttpEndpointPaginatedQueryPaths,
4
+ SeamHttpEndpoints,
5
+ SeamHttpRequest,
6
+ SeamPageCursor,
7
+ } from '@seamapi/http/connect'
8
+ import {
9
+ useInfiniteQuery,
10
+ type UseInfiniteQueryOptions,
11
+ type UseInfiniteQueryResult,
12
+ } from '@tanstack/react-query'
13
+
14
+ import { useSeamClient } from 'lib/seam/use-seam-client.js'
15
+
16
+ export type UseSeamInfiniteQueryParameters<
17
+ T extends SeamHttpEndpointPaginatedQueryPaths,
18
+ > = Parameters<SeamHttpEndpoints[T]>[0]
19
+
20
+ export type UseSeamInfiniteQueryResult<
21
+ T extends SeamHttpEndpointPaginatedQueryPaths,
22
+ > = UseInfiniteQueryResult<QueryData<T>, SeamHttpApiError>
23
+
24
+ export function useSeamInfiniteQuery<
25
+ T extends SeamHttpEndpointPaginatedQueryPaths,
26
+ >(
27
+ endpointPath: T,
28
+ parameters?: UseSeamInfiniteQueryParameters<T>,
29
+ options: Parameters<SeamHttpEndpoints[T]>[1] &
30
+ QueryOptions<QueryData<T>, SeamHttpApiError> = {}
31
+ ): UseSeamInfiniteQueryResult<T> {
32
+ const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
33
+ return useInfiniteQuery({
34
+ enabled: client != null,
35
+ ...options,
36
+ queryKey: [
37
+ ...queryKeyPrefixes,
38
+ ...endpointPath.split('/').filter((v) => v !== ''),
39
+ parameters,
40
+ ],
41
+ initialPageParam: null,
42
+ getNextPageParam: (lastPage) => lastPage.nextPageCursor,
43
+ queryFn: async ({ pageParam }) => {
44
+ if (client == null)
45
+ return {
46
+ data: [] as Awaited<ReturnType<SeamHttpEndpoints[T]>>,
47
+ nextPageCursor: null,
48
+ }
49
+ // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
50
+ // Type assertion is needed here for performance reasons. The types are correct at runtime.
51
+ const endpoint = client[endpointPath] as (...args: any) => any
52
+ const request = endpoint(parameters, options)
53
+ const pages = client.createPaginator(request as SeamHttpRequest<any, any>)
54
+ if (pageParam == null) {
55
+ const [data, { nextPageCursor }] = await pages.firstPage()
56
+ return {
57
+ data: data as Awaited<ReturnType<SeamHttpEndpoints[T]>>,
58
+ nextPageCursor,
59
+ }
60
+ }
61
+ // Type assertion is needed for pageParam since the Seam API expects a branded PageCursor type.
62
+ const [data, { nextPageCursor }] = await pages.nextPage(
63
+ pageParam as SeamPageCursor
64
+ )
65
+ return {
66
+ data: data as Awaited<ReturnType<SeamHttpEndpoints[T]>>,
67
+ nextPageCursor,
68
+ }
69
+ },
70
+ })
71
+ }
72
+
73
+ interface QueryData<T extends SeamHttpEndpointPaginatedQueryPaths> {
74
+ data: Awaited<ReturnType<SeamHttpEndpoints[T]>>
75
+ nextPageCursor: SeamPageCursor | null
76
+ }
77
+
78
+ type QueryOptions<X, Y> = Omit<
79
+ UseInfiniteQueryOptions<X, Y>,
80
+ 'queryKey' | 'queryFn' | 'initialPageParam' | 'getNextPageParam'
81
+ >
@@ -23,7 +23,7 @@ export type UseSeamMutationWithoutWorkspaceResult<
23
23
  UseSeamMutationWithoutWorkspaceVariables<T>
24
24
  >
25
25
 
26
- export function UseSeamMutationWithoutWorkspace<
26
+ export function useSeamMutationWithoutWorkspace<
27
27
  T extends SeamHttpEndpointWithoutWorkspaceMutationPaths,
28
28
  >(
29
29
  endpointPath: T,
@@ -1,3 +1,3 @@
1
- const seamapiReactVersion = '4.10.0'
1
+ const seamapiReactVersion = '4.11.0'
2
2
 
3
3
  export default seamapiReactVersion