@izumisy-tailor/tailor-data-viewer 0.2.12 → 0.2.14

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@izumisy-tailor/tailor-data-viewer",
3
3
  "private": false,
4
- "version": "0.2.12",
4
+ "version": "0.2.14",
5
5
  "type": "module",
6
6
  "description": "Flexible data viewer component for Tailor Platform",
7
7
  "files": [
@@ -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, 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
-
@@ -14,13 +14,20 @@ import type {
14
14
  import type { FieldName, OrderableFieldName } from "../types";
15
15
 
16
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>`.
17
+ * Resolves the variables type for `toQueryArgs()` return value.
18
+ *
19
+ * When the query document carries gql-tada type information
20
+ * (`ExtractQueryVariables` resolves to a concrete type), uses that type
21
+ * so the result is directly compatible with `useQuery()` from urql.
22
+ * Otherwise falls back to `QueryVariables`.
23
+ *
24
+ * Note: The runtime value is always `QueryVariables`, but the gql-tada
25
+ * variables type is structurally compatible (a supertype), so the cast
26
+ * is safe.
20
27
  */
21
- type ResolveVariables<TQuery, TFieldName extends string = string> =
28
+ type ResolveVariables<TQuery> =
22
29
  ExtractQueryVariables<TQuery> extends never
23
- ? QueryVariables<TFieldName>
30
+ ? QueryVariables
24
31
  : ExtractQueryVariables<TQuery>;
25
32
 
26
33
  // -----------------------------------------------------------------------------
@@ -66,10 +73,9 @@ export function useCollection<
66
73
  },
67
74
  ): UseCollectionReturn<
68
75
  FieldName<TMetadata, TTableName>,
69
- ResolveVariables<TQuery, FieldName<TMetadata, TTableName>>,
70
76
  {
71
77
  query: TQuery;
72
- variables: ResolveVariables<TQuery, FieldName<TMetadata, TTableName>>;
78
+ variables: ResolveVariables<TQuery>;
73
79
  },
74
80
  MetadataFilter<TMetadata, TTableName>
75
81
  >;
@@ -97,7 +103,6 @@ export function useCollection<TQuery>(
97
103
  },
98
104
  ): UseCollectionReturn<
99
105
  string,
100
- ResolveVariables<TQuery>,
101
106
  { query: TQuery; variables: ResolveVariables<TQuery> }
102
107
  >;
103
108
 
@@ -110,11 +115,7 @@ export function useCollection(
110
115
  tableName?: string;
111
116
  query: unknown;
112
117
  },
113
- ): UseCollectionReturn<
114
- string,
115
- QueryVariables,
116
- { query: unknown; variables: QueryVariables }
117
- > {
118
+ ): UseCollectionReturn<string, { query: unknown; variables: QueryVariables }> {
118
119
  const { params = {}, query: queryDocument } = options;
119
120
  const {
120
121
  initialFilters = [],
@@ -186,15 +186,31 @@ export interface PageInfo {
186
186
  /**
187
187
  * GraphQL query variables in Tailor Platform format.
188
188
  *
189
- * @typeParam TFieldName - Union of allowed field name strings (default: `string`).
190
- * When metadata is provided to `useCollection`, this
191
- * narrows `order[].field` to match the table's field names,
192
- * making the output directly compatible with gql-tada's
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<TFieldName extends string = string> {
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
- order?: { field: TFieldName; direction: "Asc" | "Desc" }[];
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
- TVariables = QueryVariables<TFieldName>,
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, unknown>;
468
+ collection?: UseCollectionReturn<string, unknown>;
457
469
  }
458
470
 
459
471
  /**