@wix/sdk-types 1.14.0 → 1.16.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.
@@ -432,44 +432,6 @@ type OperatorsWithBooleanValues = '$isEmpty' | '$exists';
432
432
  type OperatorsWithArrayValues = '$in' | '$nin' | '$hasAll' | '$hasSome';
433
433
  type OperatorForArrayFiltering = '$matchItems';
434
434
 
435
- /**
436
- * Cursor-based paging configuration
437
- */
438
- interface CursorPaging {
439
- /** Maximum number of items to return in the results. */
440
- limit?: number | null;
441
- /**
442
- * Pointer to the next or previous page in the list of results.
443
- *
444
- * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
445
- * Not relevant for the first request.
446
- */
447
- cursor?: string | null;
448
- }
449
- /**
450
- * Offset-based paging configuration
451
- */
452
- interface OffsetPaging {
453
- /** Number of items to load */
454
- limit?: number | null;
455
- /** Number of items to skip in the current sort order */
456
- offset?: number | null;
457
- }
458
- /**
459
- * Supported paging types for search APIs
460
- */
461
- type PagingType = 'cursor' | 'offset';
462
- /**
463
- * Paging type based on the SearchSpec's paging type
464
- */
465
- type Paging<Spec extends {
466
- paging?: PagingType;
467
- }> = Spec['paging'] extends 'cursor' ? {
468
- cursorPaging: CursorPaging;
469
- } : Spec['paging'] extends 'offset' ? {
470
- paging: OffsetPaging;
471
- } : {};
472
-
473
435
  /**
474
436
  * Sort direction type for requests
475
437
  */
@@ -502,10 +464,10 @@ type WQLFields<WQLGroup> = WQLGroup extends {
502
464
  fields: readonly string[];
503
465
  } ? WQLGroup['fields'][number] : never;
504
466
  /**
505
- * Sorting configuration for search results
506
- * @template Spec The search specification type
467
+ * Sorting configuration for search/query results
468
+ * @template Spec The WQL specification type
507
469
  */
508
- type Sorting<Spec extends SearchSpec> = Spec['wql'] extends {
470
+ type Sorting<Spec extends WQLSpec> = Spec['wql'] extends {
509
471
  length: 0;
510
472
  } | [] ? {
511
473
  fieldName?: string;
@@ -563,42 +525,14 @@ interface WQL {
563
525
  }
564
526
 
565
527
  /**
566
- * Specification for a search API
567
- * Defines what fields can be filtered, sorted, searched, and aggregated
568
- * @example
569
- * interface MySearchSpec extends SearchSpec {
570
- * wql: [{
571
- * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
572
- * fields: ['id', 'title'],
573
- * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
574
- * }],
575
- * paging: 'offset', // or 'cursor' for cursor-based pagination
576
- * searchable: ['title', 'description'],
577
- * aggregatable: ['category', 'price']
578
- * };
528
+ * Base specification interface for APIs that support WQL (Wix Query Language)
579
529
  */
580
- interface SearchSpec {
530
+ interface WQLSpec {
581
531
  /**
582
532
  * Groups of fields with shared operator and sorting capabilities
583
533
  * Each group defines what operations can be performed on its fields
584
534
  */
585
535
  wql: readonly WQL[];
586
- /**
587
- * Supported paging type for this search API
588
- * - 'cursor': Uses cursor-based pagination
589
- * - 'offset': Uses offset-based pagination
590
- */
591
- paging: PagingType;
592
- /**
593
- * Fields that can be used for full-text search
594
- * If not specified, all fields are searchable
595
- */
596
- searchable?: readonly string[];
597
- /**
598
- * Fields that can be used for aggregations
599
- * These fields must be searchable and not contain PII
600
- */
601
- aggregatable?: readonly string[];
602
536
  }
603
537
 
604
538
  /**
@@ -606,19 +540,11 @@ interface SearchSpec {
606
540
  */
607
541
  type GetNestedType<Entity, Path extends string> = Path extends keyof Entity ? Entity[Path] extends (infer ArrayElement)[] | null | undefined ? ArrayElement : Exclude<Entity[Path], null | undefined> : Path extends `${infer FirstPathPart}.${infer RemainingPath}` ? FirstPathPart extends keyof Entity ? Entity[FirstPathPart] extends (infer ArrayElement)[] | null | undefined ? GetNestedType<NonNullable<ArrayElement>, RemainingPath> : Entity[FirstPathPart] extends object | null | undefined ? GetNestedType<NonNullable<Entity[FirstPathPart]>, RemainingPath> : never : never : never;
608
542
  /**
609
- * Extracts all filterable field paths from a search spec
610
- * @template Spec The search specification type
543
+ * Extracts all filterable field paths from a spec
544
+ * @template Spec The WQL specification type
611
545
  * // Results in a union type of all field paths that can be filtered
612
546
  */
613
- type FilterableFields<Spec extends SearchSpec> = Spec['wql'][number]['fields'][number];
614
- /**
615
- * Extracts all searchable field paths from a search spec
616
- * @template Spec The search specification type
617
- * // Results in a union type of all field paths that can be searched
618
- */
619
- type SearchableFields<Spec extends SearchSpec> = Spec extends {
620
- searchable: readonly string[];
621
- } ? Spec['searchable'][number] : string;
547
+ type FilterableFields<Spec extends WQLSpec> = Spec['wql'][number]['fields'][number];
622
548
 
623
549
  /**
624
550
  * Helper type to detect if a type is an enum-like union of string literals
@@ -633,25 +559,25 @@ type IsEnumLike<T> = T extends string | null | undefined ? string extends NonNul
633
559
  */
634
560
  type ApplicableOperators<Entity, Path extends string> = Path extends keyof Entity ? Entity[Path] extends string | null | undefined ? IsEnumLike<Entity[Path]> extends true ? EnumOperators : StringOperators : Entity[Path] extends number | null | undefined ? NumberOperators : Entity[Path] extends boolean | null | undefined ? BooleanOperators : Entity[Path] extends Date | null | undefined ? DateOperators : Entity[Path] extends (infer E)[] | null | undefined ? E extends object ? ArrayOfObjectsOperators : ArrayOfPrimitivesOperators : Entity[Path] extends object | null | undefined ? ObjectOperators : never : Path extends `${infer K}.${infer R}` ? K extends keyof Entity ? Entity[K] extends (infer U)[] | null | undefined ? ApplicableOperators<NonNullable<U>, R> : Entity[K] extends object | null | undefined ? ApplicableOperators<NonNullable<Entity[K]>, R> : never : never : never;
635
561
  /**
636
- * Determines allowed operators for a field based on the search spec
562
+ * Determines allowed operators for a field based on the spec
637
563
  * @template Entity The entity type
638
- * @template Spec The search specification type
564
+ * @template Spec The WQL specification type
639
565
  * @template Field The field to check
640
566
  */
641
- type AllowedOperators<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Spec['wql'][number] extends infer WQLGroup ? WQLGroup extends WQL ? Field extends WQLGroup['fields'][number] ? WQLGroup['operators'] extends typeof ALL_APPLICABLE_OPERATORS ? ApplicableOperators<Entity, Field & string> : WQLGroup['operators'] extends readonly string[] ? WQLGroup['operators'][number] : never : never : never : never;
567
+ type AllowedOperators<Entity, Spec extends WQLSpec, Field extends FilterableFields<Spec>> = Spec['wql'][number] extends infer WQLGroup ? WQLGroup extends WQL ? Field extends WQLGroup['fields'][number] ? WQLGroup['operators'] extends typeof ALL_APPLICABLE_OPERATORS ? ApplicableOperators<Entity, Field & string> : WQLGroup['operators'] extends readonly string[] ? WQLGroup['operators'][number] : never : never : never : never;
642
568
  /**
643
569
  * Filter operations type for individual field conditions
644
570
  * @template Entity The entity type
645
- * @template Spec The search specification type
571
+ * @template Spec The WQL specification type
646
572
  * @template Field The field to filter on
647
573
  */
648
- type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Simplify<{
574
+ type FilterOps<Entity, Spec extends WQLSpec, Field extends FilterableFields<Spec>> = Simplify<{
649
575
  [Op in AllowedOperators<Entity, Spec, Field>]?: Op extends OperatorsWithBooleanValues ? boolean : Op extends OperatorForArrayFiltering ? JsonObject[] : Op extends OperatorsWithArrayValues ? GetNestedType<Entity, Field & string>[] : GetNestedType<Entity, Field & string>;
650
576
  }>;
651
577
  /**
652
578
  * Filter type for building type-safe query filters
653
579
  * @template Entity The entity type
654
- * @template Spec The search specification type
580
+ * @template Spec The WQL specification type
655
581
  * @example
656
582
  * // Simple filter
657
583
  * const filter: Filter<Product, ProductSpec> = {
@@ -670,7 +596,7 @@ type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<S
670
596
  * ]
671
597
  * };
672
598
  */
673
- type Filter<Entity, Spec extends SearchSpec> = Simplify<{
599
+ type Filter<Entity, Spec extends WQLSpec> = Simplify<{
674
600
  [Field in FilterableFields<Spec>]?: AllowedOperators<Entity, Spec, Field> extends infer AllowedOps ? AllowedOps extends '$eq' ? GetNestedType<Entity, Field & string> | FilterOps<Entity, Spec, Field> : FilterOps<Entity, Spec, Field> : never;
675
601
  } | {
676
602
  $and?: Filter<Entity, Spec>[];
@@ -678,6 +604,78 @@ type Filter<Entity, Spec extends SearchSpec> = Simplify<{
678
604
  $not?: Filter<Entity, Spec>;
679
605
  }>;
680
606
 
607
+ /**
608
+ * Cursor-based paging configuration
609
+ */
610
+ interface CursorPaging {
611
+ /** Maximum number of items to return in the results. */
612
+ limit?: number | null;
613
+ /**
614
+ * Pointer to the next or previous page in the list of results.
615
+ *
616
+ * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
617
+ * Not relevant for the first request.
618
+ */
619
+ cursor?: string | null;
620
+ }
621
+ /**
622
+ * Offset-based paging configuration
623
+ */
624
+ interface OffsetPaging {
625
+ /** Number of items to load */
626
+ limit?: number | null;
627
+ /** Number of items to skip in the current sort order */
628
+ offset?: number | null;
629
+ }
630
+ /**
631
+ * Supported paging types for search APIs
632
+ */
633
+ type PagingType = 'cursor' | 'offset';
634
+ /**
635
+ * Paging type based on the SearchSpec's paging type
636
+ */
637
+ type Paging<Spec extends {
638
+ paging?: PagingType;
639
+ }> = Spec['paging'] extends 'cursor' ? {
640
+ cursorPaging: CursorPaging;
641
+ } : Spec['paging'] extends 'offset' ? {
642
+ paging: OffsetPaging;
643
+ } : {};
644
+
645
+ /**
646
+ * Specification for a search API
647
+ * Defines what fields can be filtered, sorted, searched, and aggregated
648
+ * @example
649
+ * interface MySearchSpec extends SearchSpec {
650
+ * wql: [{
651
+ * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
652
+ * fields: ['id', 'title'],
653
+ * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
654
+ * }],
655
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
656
+ * searchable: ['title', 'description'],
657
+ * aggregatable: ['category', 'price']
658
+ * };
659
+ */
660
+ interface SearchSpec extends WQLSpec {
661
+ /**
662
+ * Supported paging type for this search API
663
+ * - 'cursor': Uses cursor-based pagination
664
+ * - 'offset': Uses offset-based pagination
665
+ */
666
+ paging: PagingType;
667
+ /**
668
+ * Fields that can be used for full-text search
669
+ * If not specified, all fields are searchable
670
+ */
671
+ searchable?: readonly string[];
672
+ /**
673
+ * Fields that can be used for aggregations
674
+ * These fields must be searchable and not contain PII
675
+ */
676
+ aggregatable?: readonly string[];
677
+ }
678
+
681
679
  /**
682
680
  * Type of scalar aggregation to perform
683
681
  */
@@ -785,6 +783,15 @@ type Aggregation<Spec extends SearchSpec> = BaseAggregationWithoutType<Spec> & {
785
783
  nested?: NestedAggregation<Spec>;
786
784
  };
787
785
 
786
+ /**
787
+ * Extracts all searchable field paths from a search spec
788
+ * @template Spec The search specification type
789
+ * // Results in a union type of all field paths that can be searched
790
+ */
791
+ type SearchableFields<Spec extends SearchSpec> = Spec extends {
792
+ searchable: readonly string[];
793
+ } ? Spec['searchable'][number] : string;
794
+
788
795
  /**
789
796
  * Configuration for full-text search functionality
790
797
  * @template Spec The search specification type
@@ -875,4 +882,61 @@ type BaseSearch<Entity, Spec extends SearchSpec> = {
875
882
  */
876
883
  type Search<Entity, Spec extends SearchSpec> = BaseSearch<Entity, Spec> & Partial<Paging<Spec>>;
877
884
 
878
- export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type MigrationOptions, type NonNullablePaths, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, type Search, type SearchSpec, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
885
+ /**
886
+ * Specification for a query API
887
+ * Defines what fields can be filtered and sorted
888
+ * @example
889
+ * interface MyQuerySpec extends QuerySpec {
890
+ * wql: [{
891
+ * operators: ['$eq', '$ne'],
892
+ * fields: ['id', 'title'],
893
+ * sort: 'BOTH'
894
+ * }],
895
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
896
+ * };
897
+ */
898
+ interface QuerySpec extends WQLSpec {
899
+ /**
900
+ * Supported paging type for this query API
901
+ * - 'cursor': Uses cursor-based pagination
902
+ * - 'offset': Uses offset-based pagination
903
+ */
904
+ paging: PagingType;
905
+ }
906
+
907
+ /**
908
+ * Complete query request for an entity type
909
+ * @template Entity The entity type being queried
910
+ * @template Spec The query specification type
911
+ * @example
912
+ * // Define a query type for products
913
+ * type QueryProducts = Query<Product, ProductQuerySpec>;
914
+ *
915
+ * // Create a query request with offset paging
916
+ * const query: QueryProducts = {
917
+ * filter: { price: { $gte: 10 } },
918
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
919
+ * paging: { limit: 20, offset: 0 }
920
+ * };
921
+ *
922
+ * // Or with cursor paging (if spec.paging = 'cursor')
923
+ * const query: QueryProducts = {
924
+ * filter: { price: { $gte: 10 } },
925
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
926
+ * cursorPaging: { limit: 20, cursor: "..." }
927
+ * };
928
+ */
929
+ type Query<Entity, Spec extends QuerySpec> = {
930
+ /**
931
+ * Filter object.
932
+ * Learn more about the [filter section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-filter-section).
933
+ */
934
+ filter?: Filter<Entity, Spec>;
935
+ /**
936
+ * List of sort objects.
937
+ * Learn more about the [sort section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-sort-section).
938
+ */
939
+ sort?: Sorting<Spec>[];
940
+ } & Partial<Paging<Spec>>;
941
+
942
+ export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type Filter, type FilterableFields, type GetNestedType, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type MigrationOptions, type NonNullablePaths, type PublicMetadata, type Query, type QuerySpec, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, SORT_CAPABILITIES, SORT_DIRECTIONS, type Search, type SearchSpec, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata, type SortCapability, type SortOrder, type Sorting, type WQL, type WQLSpec };
@@ -17,8 +17,21 @@ function ServicePluginDefinition(componentType, methods) {
17
17
  };
18
18
  }
19
19
  var SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
20
+
21
+ // src/common/sort.ts
22
+ var SORT_DIRECTIONS = {
23
+ ASC: "ASC",
24
+ DESC: "DESC"
25
+ };
26
+ var SORT_CAPABILITIES = {
27
+ ...SORT_DIRECTIONS,
28
+ BOTH: "BOTH",
29
+ NONE: "NONE"
30
+ };
20
31
  export {
21
32
  EventDefinition,
22
33
  SERVICE_PLUGIN_ERROR_TYPE,
34
+ SORT_CAPABILITIES,
35
+ SORT_DIRECTIONS,
23
36
  ServicePluginDefinition
24
37
  };
@@ -432,44 +432,6 @@ type OperatorsWithBooleanValues = '$isEmpty' | '$exists';
432
432
  type OperatorsWithArrayValues = '$in' | '$nin' | '$hasAll' | '$hasSome';
433
433
  type OperatorForArrayFiltering = '$matchItems';
434
434
 
435
- /**
436
- * Cursor-based paging configuration
437
- */
438
- interface CursorPaging {
439
- /** Maximum number of items to return in the results. */
440
- limit?: number | null;
441
- /**
442
- * Pointer to the next or previous page in the list of results.
443
- *
444
- * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
445
- * Not relevant for the first request.
446
- */
447
- cursor?: string | null;
448
- }
449
- /**
450
- * Offset-based paging configuration
451
- */
452
- interface OffsetPaging {
453
- /** Number of items to load */
454
- limit?: number | null;
455
- /** Number of items to skip in the current sort order */
456
- offset?: number | null;
457
- }
458
- /**
459
- * Supported paging types for search APIs
460
- */
461
- type PagingType = 'cursor' | 'offset';
462
- /**
463
- * Paging type based on the SearchSpec's paging type
464
- */
465
- type Paging<Spec extends {
466
- paging?: PagingType;
467
- }> = Spec['paging'] extends 'cursor' ? {
468
- cursorPaging: CursorPaging;
469
- } : Spec['paging'] extends 'offset' ? {
470
- paging: OffsetPaging;
471
- } : {};
472
-
473
435
  /**
474
436
  * Sort direction type for requests
475
437
  */
@@ -502,10 +464,10 @@ type WQLFields<WQLGroup> = WQLGroup extends {
502
464
  fields: readonly string[];
503
465
  } ? WQLGroup['fields'][number] : never;
504
466
  /**
505
- * Sorting configuration for search results
506
- * @template Spec The search specification type
467
+ * Sorting configuration for search/query results
468
+ * @template Spec The WQL specification type
507
469
  */
508
- type Sorting<Spec extends SearchSpec> = Spec['wql'] extends {
470
+ type Sorting<Spec extends WQLSpec> = Spec['wql'] extends {
509
471
  length: 0;
510
472
  } | [] ? {
511
473
  fieldName?: string;
@@ -563,42 +525,14 @@ interface WQL {
563
525
  }
564
526
 
565
527
  /**
566
- * Specification for a search API
567
- * Defines what fields can be filtered, sorted, searched, and aggregated
568
- * @example
569
- * interface MySearchSpec extends SearchSpec {
570
- * wql: [{
571
- * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
572
- * fields: ['id', 'title'],
573
- * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
574
- * }],
575
- * paging: 'offset', // or 'cursor' for cursor-based pagination
576
- * searchable: ['title', 'description'],
577
- * aggregatable: ['category', 'price']
578
- * };
528
+ * Base specification interface for APIs that support WQL (Wix Query Language)
579
529
  */
580
- interface SearchSpec {
530
+ interface WQLSpec {
581
531
  /**
582
532
  * Groups of fields with shared operator and sorting capabilities
583
533
  * Each group defines what operations can be performed on its fields
584
534
  */
585
535
  wql: readonly WQL[];
586
- /**
587
- * Supported paging type for this search API
588
- * - 'cursor': Uses cursor-based pagination
589
- * - 'offset': Uses offset-based pagination
590
- */
591
- paging: PagingType;
592
- /**
593
- * Fields that can be used for full-text search
594
- * If not specified, all fields are searchable
595
- */
596
- searchable?: readonly string[];
597
- /**
598
- * Fields that can be used for aggregations
599
- * These fields must be searchable and not contain PII
600
- */
601
- aggregatable?: readonly string[];
602
536
  }
603
537
 
604
538
  /**
@@ -606,19 +540,11 @@ interface SearchSpec {
606
540
  */
607
541
  type GetNestedType<Entity, Path extends string> = Path extends keyof Entity ? Entity[Path] extends (infer ArrayElement)[] | null | undefined ? ArrayElement : Exclude<Entity[Path], null | undefined> : Path extends `${infer FirstPathPart}.${infer RemainingPath}` ? FirstPathPart extends keyof Entity ? Entity[FirstPathPart] extends (infer ArrayElement)[] | null | undefined ? GetNestedType<NonNullable<ArrayElement>, RemainingPath> : Entity[FirstPathPart] extends object | null | undefined ? GetNestedType<NonNullable<Entity[FirstPathPart]>, RemainingPath> : never : never : never;
608
542
  /**
609
- * Extracts all filterable field paths from a search spec
610
- * @template Spec The search specification type
543
+ * Extracts all filterable field paths from a spec
544
+ * @template Spec The WQL specification type
611
545
  * // Results in a union type of all field paths that can be filtered
612
546
  */
613
- type FilterableFields<Spec extends SearchSpec> = Spec['wql'][number]['fields'][number];
614
- /**
615
- * Extracts all searchable field paths from a search spec
616
- * @template Spec The search specification type
617
- * // Results in a union type of all field paths that can be searched
618
- */
619
- type SearchableFields<Spec extends SearchSpec> = Spec extends {
620
- searchable: readonly string[];
621
- } ? Spec['searchable'][number] : string;
547
+ type FilterableFields<Spec extends WQLSpec> = Spec['wql'][number]['fields'][number];
622
548
 
623
549
  /**
624
550
  * Helper type to detect if a type is an enum-like union of string literals
@@ -633,25 +559,25 @@ type IsEnumLike<T> = T extends string | null | undefined ? string extends NonNul
633
559
  */
634
560
  type ApplicableOperators<Entity, Path extends string> = Path extends keyof Entity ? Entity[Path] extends string | null | undefined ? IsEnumLike<Entity[Path]> extends true ? EnumOperators : StringOperators : Entity[Path] extends number | null | undefined ? NumberOperators : Entity[Path] extends boolean | null | undefined ? BooleanOperators : Entity[Path] extends Date | null | undefined ? DateOperators : Entity[Path] extends (infer E)[] | null | undefined ? E extends object ? ArrayOfObjectsOperators : ArrayOfPrimitivesOperators : Entity[Path] extends object | null | undefined ? ObjectOperators : never : Path extends `${infer K}.${infer R}` ? K extends keyof Entity ? Entity[K] extends (infer U)[] | null | undefined ? ApplicableOperators<NonNullable<U>, R> : Entity[K] extends object | null | undefined ? ApplicableOperators<NonNullable<Entity[K]>, R> : never : never : never;
635
561
  /**
636
- * Determines allowed operators for a field based on the search spec
562
+ * Determines allowed operators for a field based on the spec
637
563
  * @template Entity The entity type
638
- * @template Spec The search specification type
564
+ * @template Spec The WQL specification type
639
565
  * @template Field The field to check
640
566
  */
641
- type AllowedOperators<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Spec['wql'][number] extends infer WQLGroup ? WQLGroup extends WQL ? Field extends WQLGroup['fields'][number] ? WQLGroup['operators'] extends typeof ALL_APPLICABLE_OPERATORS ? ApplicableOperators<Entity, Field & string> : WQLGroup['operators'] extends readonly string[] ? WQLGroup['operators'][number] : never : never : never : never;
567
+ type AllowedOperators<Entity, Spec extends WQLSpec, Field extends FilterableFields<Spec>> = Spec['wql'][number] extends infer WQLGroup ? WQLGroup extends WQL ? Field extends WQLGroup['fields'][number] ? WQLGroup['operators'] extends typeof ALL_APPLICABLE_OPERATORS ? ApplicableOperators<Entity, Field & string> : WQLGroup['operators'] extends readonly string[] ? WQLGroup['operators'][number] : never : never : never : never;
642
568
  /**
643
569
  * Filter operations type for individual field conditions
644
570
  * @template Entity The entity type
645
- * @template Spec The search specification type
571
+ * @template Spec The WQL specification type
646
572
  * @template Field The field to filter on
647
573
  */
648
- type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<Spec>> = Simplify<{
574
+ type FilterOps<Entity, Spec extends WQLSpec, Field extends FilterableFields<Spec>> = Simplify<{
649
575
  [Op in AllowedOperators<Entity, Spec, Field>]?: Op extends OperatorsWithBooleanValues ? boolean : Op extends OperatorForArrayFiltering ? JsonObject[] : Op extends OperatorsWithArrayValues ? GetNestedType<Entity, Field & string>[] : GetNestedType<Entity, Field & string>;
650
576
  }>;
651
577
  /**
652
578
  * Filter type for building type-safe query filters
653
579
  * @template Entity The entity type
654
- * @template Spec The search specification type
580
+ * @template Spec The WQL specification type
655
581
  * @example
656
582
  * // Simple filter
657
583
  * const filter: Filter<Product, ProductSpec> = {
@@ -670,7 +596,7 @@ type FilterOps<Entity, Spec extends SearchSpec, Field extends FilterableFields<S
670
596
  * ]
671
597
  * };
672
598
  */
673
- type Filter<Entity, Spec extends SearchSpec> = Simplify<{
599
+ type Filter<Entity, Spec extends WQLSpec> = Simplify<{
674
600
  [Field in FilterableFields<Spec>]?: AllowedOperators<Entity, Spec, Field> extends infer AllowedOps ? AllowedOps extends '$eq' ? GetNestedType<Entity, Field & string> | FilterOps<Entity, Spec, Field> : FilterOps<Entity, Spec, Field> : never;
675
601
  } | {
676
602
  $and?: Filter<Entity, Spec>[];
@@ -678,6 +604,78 @@ type Filter<Entity, Spec extends SearchSpec> = Simplify<{
678
604
  $not?: Filter<Entity, Spec>;
679
605
  }>;
680
606
 
607
+ /**
608
+ * Cursor-based paging configuration
609
+ */
610
+ interface CursorPaging {
611
+ /** Maximum number of items to return in the results. */
612
+ limit?: number | null;
613
+ /**
614
+ * Pointer to the next or previous page in the list of results.
615
+ *
616
+ * Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response.
617
+ * Not relevant for the first request.
618
+ */
619
+ cursor?: string | null;
620
+ }
621
+ /**
622
+ * Offset-based paging configuration
623
+ */
624
+ interface OffsetPaging {
625
+ /** Number of items to load */
626
+ limit?: number | null;
627
+ /** Number of items to skip in the current sort order */
628
+ offset?: number | null;
629
+ }
630
+ /**
631
+ * Supported paging types for search APIs
632
+ */
633
+ type PagingType = 'cursor' | 'offset';
634
+ /**
635
+ * Paging type based on the SearchSpec's paging type
636
+ */
637
+ type Paging<Spec extends {
638
+ paging?: PagingType;
639
+ }> = Spec['paging'] extends 'cursor' ? {
640
+ cursorPaging: CursorPaging;
641
+ } : Spec['paging'] extends 'offset' ? {
642
+ paging: OffsetPaging;
643
+ } : {};
644
+
645
+ /**
646
+ * Specification for a search API
647
+ * Defines what fields can be filtered, sorted, searched, and aggregated
648
+ * @example
649
+ * interface MySearchSpec extends SearchSpec {
650
+ * wql: [{
651
+ * operators: ['$eq', '$ne'], // or 'typeof ALL_APPLICABLE_OPERATORS' for all operators that can be used based on the field type
652
+ * fields: ['id', 'title'],
653
+ * sort: 'BOTH' // or 'ASC' / 'DESC' for specific sorting
654
+ * }],
655
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
656
+ * searchable: ['title', 'description'],
657
+ * aggregatable: ['category', 'price']
658
+ * };
659
+ */
660
+ interface SearchSpec extends WQLSpec {
661
+ /**
662
+ * Supported paging type for this search API
663
+ * - 'cursor': Uses cursor-based pagination
664
+ * - 'offset': Uses offset-based pagination
665
+ */
666
+ paging: PagingType;
667
+ /**
668
+ * Fields that can be used for full-text search
669
+ * If not specified, all fields are searchable
670
+ */
671
+ searchable?: readonly string[];
672
+ /**
673
+ * Fields that can be used for aggregations
674
+ * These fields must be searchable and not contain PII
675
+ */
676
+ aggregatable?: readonly string[];
677
+ }
678
+
681
679
  /**
682
680
  * Type of scalar aggregation to perform
683
681
  */
@@ -785,6 +783,15 @@ type Aggregation<Spec extends SearchSpec> = BaseAggregationWithoutType<Spec> & {
785
783
  nested?: NestedAggregation<Spec>;
786
784
  };
787
785
 
786
+ /**
787
+ * Extracts all searchable field paths from a search spec
788
+ * @template Spec The search specification type
789
+ * // Results in a union type of all field paths that can be searched
790
+ */
791
+ type SearchableFields<Spec extends SearchSpec> = Spec extends {
792
+ searchable: readonly string[];
793
+ } ? Spec['searchable'][number] : string;
794
+
788
795
  /**
789
796
  * Configuration for full-text search functionality
790
797
  * @template Spec The search specification type
@@ -875,4 +882,61 @@ type BaseSearch<Entity, Spec extends SearchSpec> = {
875
882
  */
876
883
  type Search<Entity, Spec extends SearchSpec> = BaseSearch<Entity, Spec> & Partial<Paging<Spec>>;
877
884
 
878
- export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type MigrationOptions, type NonNullablePaths, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, type Search, type SearchSpec, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
885
+ /**
886
+ * Specification for a query API
887
+ * Defines what fields can be filtered and sorted
888
+ * @example
889
+ * interface MyQuerySpec extends QuerySpec {
890
+ * wql: [{
891
+ * operators: ['$eq', '$ne'],
892
+ * fields: ['id', 'title'],
893
+ * sort: 'BOTH'
894
+ * }],
895
+ * paging: 'offset', // or 'cursor' for cursor-based pagination
896
+ * };
897
+ */
898
+ interface QuerySpec extends WQLSpec {
899
+ /**
900
+ * Supported paging type for this query API
901
+ * - 'cursor': Uses cursor-based pagination
902
+ * - 'offset': Uses offset-based pagination
903
+ */
904
+ paging: PagingType;
905
+ }
906
+
907
+ /**
908
+ * Complete query request for an entity type
909
+ * @template Entity The entity type being queried
910
+ * @template Spec The query specification type
911
+ * @example
912
+ * // Define a query type for products
913
+ * type QueryProducts = Query<Product, ProductQuerySpec>;
914
+ *
915
+ * // Create a query request with offset paging
916
+ * const query: QueryProducts = {
917
+ * filter: { price: { $gte: 10 } },
918
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
919
+ * paging: { limit: 20, offset: 0 }
920
+ * };
921
+ *
922
+ * // Or with cursor paging (if spec.paging = 'cursor')
923
+ * const query: QueryProducts = {
924
+ * filter: { price: { $gte: 10 } },
925
+ * sort: [{ fieldName: 'price', order: 'ASC' }],
926
+ * cursorPaging: { limit: 20, cursor: "..." }
927
+ * };
928
+ */
929
+ type Query<Entity, Spec extends QuerySpec> = {
930
+ /**
931
+ * Filter object.
932
+ * Learn more about the [filter section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-filter-section).
933
+ */
934
+ filter?: Filter<Entity, Spec>;
935
+ /**
936
+ * List of sort objects.
937
+ * Learn more about the [sort section](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language#the-sort-section).
938
+ */
939
+ sort?: Sorting<Spec>[];
940
+ } & Partial<Paging<Spec>>;
941
+
942
+ export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type Filter, type FilterableFields, type GetNestedType, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type MigrationOptions, type NonNullablePaths, type PublicMetadata, type Query, type QuerySpec, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, SORT_CAPABILITIES, SORT_DIRECTIONS, type Search, type SearchSpec, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata, type SortCapability, type SortOrder, type Sorting, type WQL, type WQLSpec };