@izumisy-tailor/tailor-data-viewer 0.2.12 → 0.2.13
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/package.json
CHANGED
|
@@ -3,7 +3,6 @@ import type { UseCollectionReturn } from "../types";
|
|
|
3
3
|
|
|
4
4
|
const CollectionContext = createContext<UseCollectionReturn<
|
|
5
5
|
string,
|
|
6
|
-
unknown,
|
|
7
6
|
unknown
|
|
8
7
|
> | null>(null);
|
|
9
8
|
|
|
@@ -25,7 +24,7 @@ export function CollectionProvider({
|
|
|
25
24
|
value,
|
|
26
25
|
children,
|
|
27
26
|
}: {
|
|
28
|
-
value: UseCollectionReturn<string, unknown
|
|
27
|
+
value: UseCollectionReturn<string, unknown>;
|
|
29
28
|
children: ReactNode;
|
|
30
29
|
}) {
|
|
31
30
|
return (
|
|
@@ -35,8 +34,6 @@ export function CollectionProvider({
|
|
|
35
34
|
);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
37
|
/**
|
|
41
38
|
* Hook to access collection state from the nearest `Collection.Provider`.
|
|
42
39
|
*
|
|
@@ -71,8 +68,6 @@ export function useCollectionContext<
|
|
|
71
68
|
return ctx as UseCollectionReturn<TFieldName>;
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
|
|
76
71
|
/**
|
|
77
72
|
* `Collection` namespace object providing the Provider component.
|
|
78
73
|
*
|
|
@@ -86,5 +81,3 @@ export function useCollectionContext<
|
|
|
86
81
|
export const Collection = {
|
|
87
82
|
Provider: CollectionProvider,
|
|
88
83
|
} as const;
|
|
89
|
-
|
|
90
|
-
|
|
@@ -8,21 +8,10 @@ import type {
|
|
|
8
8
|
SortState,
|
|
9
9
|
UseCollectionOptions,
|
|
10
10
|
UseCollectionReturn,
|
|
11
|
-
ExtractQueryVariables,
|
|
12
11
|
ValidateCollectionQuery,
|
|
13
12
|
} from "../types";
|
|
14
13
|
import type { FieldName, OrderableFieldName } from "../types";
|
|
15
14
|
|
|
16
|
-
/**
|
|
17
|
-
* Resolves query variables type: uses `ExtractQueryVariables<TQuery>` when
|
|
18
|
-
* the query document carries a `__variablesType` brand (e.g. gql-tada),
|
|
19
|
-
* otherwise falls back to `QueryVariables<TFieldName>`.
|
|
20
|
-
*/
|
|
21
|
-
type ResolveVariables<TQuery, TFieldName extends string = string> =
|
|
22
|
-
ExtractQueryVariables<TQuery> extends never
|
|
23
|
-
? QueryVariables<TFieldName>
|
|
24
|
-
: ExtractQueryVariables<TQuery>;
|
|
25
|
-
|
|
26
15
|
// -----------------------------------------------------------------------------
|
|
27
16
|
// Overload signatures
|
|
28
17
|
// -----------------------------------------------------------------------------
|
|
@@ -66,10 +55,9 @@ export function useCollection<
|
|
|
66
55
|
},
|
|
67
56
|
): UseCollectionReturn<
|
|
68
57
|
FieldName<TMetadata, TTableName>,
|
|
69
|
-
ResolveVariables<TQuery, FieldName<TMetadata, TTableName>>,
|
|
70
58
|
{
|
|
71
59
|
query: TQuery;
|
|
72
|
-
variables:
|
|
60
|
+
variables: QueryVariables;
|
|
73
61
|
},
|
|
74
62
|
MetadataFilter<TMetadata, TTableName>
|
|
75
63
|
>;
|
|
@@ -95,11 +83,7 @@ export function useCollection<TQuery>(
|
|
|
95
83
|
metadata?: never;
|
|
96
84
|
tableName?: never;
|
|
97
85
|
},
|
|
98
|
-
): UseCollectionReturn<
|
|
99
|
-
string,
|
|
100
|
-
ResolveVariables<TQuery>,
|
|
101
|
-
{ query: TQuery; variables: ResolveVariables<TQuery> }
|
|
102
|
-
>;
|
|
86
|
+
): UseCollectionReturn<string, { query: TQuery; variables: QueryVariables }>;
|
|
103
87
|
|
|
104
88
|
// -----------------------------------------------------------------------------
|
|
105
89
|
// Implementation
|
|
@@ -110,11 +94,7 @@ export function useCollection(
|
|
|
110
94
|
tableName?: string;
|
|
111
95
|
query: unknown;
|
|
112
96
|
},
|
|
113
|
-
): UseCollectionReturn<
|
|
114
|
-
string,
|
|
115
|
-
QueryVariables,
|
|
116
|
-
{ query: unknown; variables: QueryVariables }
|
|
117
|
-
> {
|
|
97
|
+
): UseCollectionReturn<string, { query: unknown; variables: QueryVariables }> {
|
|
118
98
|
const { params = {}, query: queryDocument } = options;
|
|
119
99
|
const {
|
|
120
100
|
initialFilters = [],
|
package/src/component/types.ts
CHANGED
|
@@ -186,15 +186,31 @@ export interface PageInfo {
|
|
|
186
186
|
/**
|
|
187
187
|
* GraphQL query variables in Tailor Platform format.
|
|
188
188
|
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* `VariablesOf<>` types.
|
|
189
|
+
* Field-level type safety for `query` and `order` is not enforced here.
|
|
190
|
+
* Instead, `ValidateCollectionQuery` performs compile-time checks
|
|
191
|
+
* (e.g. `CheckQueryInput` for filter field names, `CheckOrderField`
|
|
192
|
+
* for orderable fields) when `useCollection` is called with metadata.
|
|
194
193
|
*/
|
|
195
|
-
export interface QueryVariables
|
|
194
|
+
export interface QueryVariables {
|
|
195
|
+
/**
|
|
196
|
+
* Filter object built at runtime by `useCollection`.
|
|
197
|
+
*
|
|
198
|
+
* Typed as `Record<string, unknown>` because the concrete shape depends on
|
|
199
|
+
* which filters the user applies at runtime (e.g. `{ name: { eq: "foo" } }`).
|
|
200
|
+
*
|
|
201
|
+
* Compile-time safety for field names is enforced separately by
|
|
202
|
+
* `ValidateCollectionQuery` (specifically `CheckQueryInput`), which verifies
|
|
203
|
+
* that metadata field names are a subset of the GraphQL `QueryInput` type's keys.
|
|
204
|
+
*/
|
|
196
205
|
query?: Record<string, unknown>;
|
|
197
|
-
|
|
206
|
+
/**
|
|
207
|
+
* Sort order built at runtime by `useCollection`.
|
|
208
|
+
*
|
|
209
|
+
* `field` is typed as `string` here. Compile-time validation that
|
|
210
|
+
* field names are assignable to the GraphQL `OrderInput` enum is
|
|
211
|
+
* performed by `ValidateCollectionQuery` (specifically `CheckOrderField`).
|
|
212
|
+
*/
|
|
213
|
+
order?: { field: string; direction: "Asc" | "Desc" }[];
|
|
198
214
|
first: number;
|
|
199
215
|
after?: string | null;
|
|
200
216
|
}
|
|
@@ -369,16 +385,12 @@ export interface UseCollectionOptions<
|
|
|
369
385
|
* `UseCollectionReturn<string>` (bivariant method check).
|
|
370
386
|
*
|
|
371
387
|
* @typeParam TFieldName - Union of allowed field name strings (default: `string`).
|
|
372
|
-
* @typeParam TVariables - Type of the `variables` output (default: `QueryVariables<TFieldName>`).
|
|
373
|
-
* Pass `VariablesOf<typeof YOUR_QUERY>` (gql-tada) to get
|
|
374
|
-
* exact type compatibility with your GraphQL client.
|
|
375
388
|
* @typeParam TQueryArgs - Type returned by `toQueryArgs()`. Contains both
|
|
376
389
|
* `query` and `variables`.
|
|
377
390
|
*/
|
|
378
391
|
export interface UseCollectionReturn<
|
|
379
392
|
TFieldName extends string = string,
|
|
380
|
-
|
|
381
|
-
TQueryArgs = { query: unknown; variables: TVariables },
|
|
393
|
+
TQueryArgs = { query: unknown; variables: QueryVariables },
|
|
382
394
|
TFilter = Filter<TFieldName>,
|
|
383
395
|
> {
|
|
384
396
|
/**
|
|
@@ -453,7 +465,7 @@ export interface UseDataTableOptions<TRow extends Record<string, unknown>> {
|
|
|
453
465
|
/** Error */
|
|
454
466
|
error?: Error | null;
|
|
455
467
|
/** Collection state for sort/pagination integration */
|
|
456
|
-
collection?: UseCollectionReturn<string, unknown
|
|
468
|
+
collection?: UseCollectionReturn<string, unknown>;
|
|
457
469
|
}
|
|
458
470
|
|
|
459
471
|
/**
|