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

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.11",
4
+ "version": "0.2.12",
5
5
  "type": "module",
6
6
  "description": "Flexible data viewer component for Tailor Platform",
7
7
  "files": [
@@ -11,7 +11,7 @@ import type {
11
11
  ExtractQueryVariables,
12
12
  ValidateCollectionQuery,
13
13
  } from "../types";
14
- import type { FieldName } from "../types";
14
+ import type { FieldName, OrderableFieldName } from "../types";
15
15
 
16
16
  /**
17
17
  * Resolves query variables type: uses `ExtractQueryVariables<TQuery>` when
@@ -58,7 +58,11 @@ export function useCollection<
58
58
  > & {
59
59
  metadata: TMetadata;
60
60
  tableName: TTableName;
61
- query: ValidateCollectionQuery<TQuery, FieldName<TMetadata, TTableName>>;
61
+ query: ValidateCollectionQuery<
62
+ TQuery,
63
+ FieldName<TMetadata, TTableName>,
64
+ OrderableFieldName<TMetadata, TTableName>
65
+ >;
62
66
  },
63
67
  ): UseCollectionReturn<
64
68
  FieldName<TMetadata, TTableName>,
@@ -28,6 +28,7 @@ export type {
28
28
  DataTableRowProps,
29
29
  DataTableCellProps,
30
30
  FieldName,
31
+ OrderableFieldName,
31
32
  ExtractOrderField,
32
33
  ExtractQueryVariables,
33
34
  ExtractQueryInputKeys,
@@ -582,6 +582,41 @@ export type FieldName<
582
582
  : never
583
583
  : never;
584
584
 
585
+ /**
586
+ * Field types that support ordering.
587
+ * Mirrors the runtime `fieldTypeToSortConfig` logic — types that return
588
+ * a `SortConfig` (not `undefined`) are considered orderable.
589
+ */
590
+ type OrderableFieldType =
591
+ | "string"
592
+ | "number"
593
+ | "boolean"
594
+ | "datetime"
595
+ | "date"
596
+ | "time"
597
+ | "enum";
598
+
599
+ /**
600
+ * Extract only orderable field names from table metadata.
601
+ *
602
+ * Fields whose `type` is not in `OrderableFieldType` (e.g. `uuid`, `array`,
603
+ * `nested`, `file`) are excluded. This allows `CheckOrderField` to compare
604
+ * only the fields that Tailor Platform actually exposes in the
605
+ * `OrderFieldEnum`, avoiding false positives for fields like `id`.
606
+ */
607
+ export type OrderableFieldName<
608
+ TMetadata extends TableMetadataMap,
609
+ TTableName extends keyof TMetadata,
610
+ > =
611
+ Extract<
612
+ TMetadata[TTableName]["fields"][number],
613
+ { readonly type: OrderableFieldType }
614
+ > extends { readonly name: infer N }
615
+ ? N extends string
616
+ ? N
617
+ : never
618
+ : never;
619
+
585
620
  /**
586
621
  * Extract the `order[].field` union type from a GraphQL variables type.
587
622
  *
@@ -726,6 +761,7 @@ type CheckQueryInput<
726
761
  export type ValidateCollectionQuery<
727
762
  TQuery,
728
763
  TFieldName extends string = string,
764
+ TOrderableFieldName extends string = TFieldName,
729
765
  > =
730
766
  ExtractQueryVariables<TQuery> extends never
731
767
  ? TQuery // No gql-tada type info → skip validation
@@ -733,7 +769,7 @@ export type ValidateCollectionQuery<
733
769
  ? TQuery & CheckFirstVariable<TQuery> // No metadata → only check $first
734
770
  : TQuery &
735
771
  CheckFirstVariable<TQuery> &
736
- CheckOrderField<TQuery, TFieldName> &
772
+ CheckOrderField<TQuery, TOrderableFieldName> &
737
773
  CheckQueryInput<TQuery, TFieldName>;
738
774
 
739
775
  /**