@diagonal-hq/pages 0.3.3 → 0.3.4

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +33 -2
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -206,13 +206,18 @@ export type ResourceSortFieldDescriptor = {
206
206
 
207
207
  export type ResourceSortDirection = 1 | -1 | 'asc' | 'desc';
208
208
 
209
+ export type ResourceSortMap = Record<string, ResourceSortDirection>;
210
+
211
+ export type ResourceSortDescriptorList = (ResourceSortDescriptor | ResourceSortFieldDescriptor)[];
212
+
209
213
  export type ResourceSortInput =
210
214
  | string
211
215
  | string[]
212
216
  | ResourceSortDescriptor
213
217
  | ResourceSortFieldDescriptor
214
- | (ResourceSortDescriptor | ResourceSortFieldDescriptor)[]
215
- | Record<string, ResourceSortDirection | number | string>;
218
+ | ResourceSortDescriptorList
219
+ | ResourceSortMap
220
+ | Record<string, number | string>;
216
221
 
217
222
  export type ResourceListParams<TRelations extends readonly string[] = readonly string[]> = {
218
223
  page?: number;
@@ -4642,6 +4647,28 @@ export type SdkUtils = Omit<TaskUtils, 'workspace' | 'workflow' | 'tiptap'> & {
4642
4647
  * Sdk.utils.pluralize(2, 'item', 'items'); // '2 items'
4643
4648
  */
4644
4649
  pluralize: (count: number, one: string, other: string) => string;
4650
+ /**
4651
+ * Type a sort that is not written inline in the call that reads it: a variable, a
4652
+ * `useMemo` result, a `useState` initial value, or an entry of a lookup table.
4653
+ * TypeScript widens `'desc'` to `string` and `-1` to `number` in such a value, and
4654
+ * `Sdk.hooks.useRecords` and a resource `search` or `searchAll` then cannot check it. `Sdk.utils.resourceSortInput` checks each direction where the sort is
4655
+ * written and returns the same value with its sort type. A direction is `1`, `-1`,
4656
+ * `'asc'`, or `'desc'`. An invalid direction throws.
4657
+ *
4658
+ * @example
4659
+ * const newestFirst = Sdk.utils.resourceSortInput({ created_at: 'desc' });
4660
+ * const { data: records } = Sdk.hooks.useRecords(orders, { sort: newestFirst });
4661
+ *
4662
+ * @example
4663
+ * const [sort, setSort] = React.useState(Sdk.utils.resourceSortInput({ key: 'name', direction: 'asc' }));
4664
+ * const { data: records } = Sdk.hooks.useRecords(students, { sort });
4665
+ */
4666
+ resourceSortInput: {
4667
+ (sort: ResourceSortDescriptor): ResourceSortDescriptor;
4668
+ (sort: ResourceSortFieldDescriptor): ResourceSortFieldDescriptor;
4669
+ (sort: ResourceSortDescriptorList): ResourceSortDescriptorList;
4670
+ (sort: ResourceSortMap): ResourceSortMap;
4671
+ };
4645
4672
  /**
4646
4673
  * Build URLs for published workflows by stable slug or ID.
4647
4674
  *
@@ -14564,6 +14591,10 @@ export declare const workspace: SdkInternal.FilePageSdk["workspace"];
14564
14591
 
14565
14592
  export type ResourceSortDirection = SdkInternal.ResourceSortDirection;
14566
14593
 
14594
+ export type ResourceSortMap = SdkInternal.ResourceSortMap;
14595
+
14596
+ export type ResourceSortDescriptorList = SdkInternal.ResourceSortDescriptorList;
14597
+
14567
14598
  export type ResourceSortInput = SdkInternal.ResourceSortInput;
14568
14599
 
14569
14600
  export type ResourceListParams<TRelations extends readonly string[] = readonly string[]> = SdkInternal.ResourceListParams<TRelations>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/pages",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "The Page SDK for the pages of file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {