@etohq/utils 2.0.4 → 2.1.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.
Files changed (165) hide show
  1. package/dist/bundles.d.ts +1 -0
  2. package/dist/bundles.d.ts.map +1 -1
  3. package/dist/bundles.js +2 -1
  4. package/dist/bundles.js.map +1 -1
  5. package/dist/dal/mikro-orm/mikro-orm-create-connection.d.ts.map +1 -1
  6. package/dist/dal/mikro-orm/mikro-orm-create-connection.js +7 -0
  7. package/dist/dal/mikro-orm/mikro-orm-create-connection.js.map +1 -1
  8. package/dist/dml/errors.d.ts +12 -0
  9. package/dist/dml/errors.d.ts.map +1 -1
  10. package/dist/dml/errors.js +21 -1
  11. package/dist/dml/errors.js.map +1 -1
  12. package/dist/dml/helpers/create-mikro-orm-entity.d.ts.map +1 -1
  13. package/dist/dml/helpers/create-mikro-orm-entity.js +25 -5
  14. package/dist/dml/helpers/create-mikro-orm-entity.js.map +1 -1
  15. package/dist/index.d.ts +3 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/migrations/index.d.ts.map +1 -1
  20. package/dist/migrations/index.js +5 -2
  21. package/dist/migrations/index.js.map +1 -1
  22. package/dist/modules-sdk/definition.d.ts +8 -0
  23. package/dist/modules-sdk/definition.d.ts.map +1 -1
  24. package/dist/modules-sdk/definition.js +5 -0
  25. package/dist/modules-sdk/definition.js.map +1 -1
  26. package/dist/review/events.d.ts +14 -0
  27. package/dist/review/events.d.ts.map +1 -0
  28. package/dist/review/events.js +18 -0
  29. package/dist/review/events.js.map +1 -0
  30. package/dist/review/index.d.ts +4 -0
  31. package/dist/review/index.d.ts.map +1 -0
  32. package/dist/review/index.js +20 -0
  33. package/dist/review/index.js.map +1 -0
  34. package/dist/review/rank.d.ts +21 -0
  35. package/dist/review/rank.d.ts.map +1 -0
  36. package/dist/review/rank.js +29 -0
  37. package/dist/review/rank.js.map +1 -0
  38. package/dist/review/rules.d.ts +42 -0
  39. package/dist/review/rules.d.ts.map +1 -0
  40. package/dist/review/rules.js +104 -0
  41. package/dist/review/rules.js.map +1 -0
  42. package/dist/schema/base-property.d.ts +25 -0
  43. package/dist/schema/base-property.d.ts.map +1 -0
  44. package/dist/schema/base-property.js +25 -0
  45. package/dist/schema/base-property.js.map +1 -0
  46. package/dist/schema/index.d.ts +2 -0
  47. package/dist/schema/index.d.ts.map +1 -0
  48. package/dist/schema/index.js +18 -0
  49. package/dist/schema/index.js.map +1 -0
  50. package/dist/search/abstract-search-provider.d.ts +345 -0
  51. package/dist/search/abstract-search-provider.d.ts.map +1 -0
  52. package/dist/search/abstract-search-provider.js +345 -0
  53. package/dist/search/abstract-search-provider.js.map +1 -0
  54. package/dist/search/define-search-index.d.ts +12 -0
  55. package/dist/search/define-search-index.d.ts.map +1 -0
  56. package/dist/search/define-search-index.js +47 -0
  57. package/dist/search/define-search-index.js.map +1 -0
  58. package/dist/search/definition-helpers.d.ts +112 -0
  59. package/dist/search/definition-helpers.d.ts.map +1 -0
  60. package/dist/search/definition-helpers.js +196 -0
  61. package/dist/search/definition-helpers.js.map +1 -0
  62. package/dist/search/document-utils.d.ts +29 -0
  63. package/dist/search/document-utils.d.ts.map +1 -0
  64. package/dist/search/document-utils.js +134 -0
  65. package/dist/search/document-utils.js.map +1 -0
  66. package/dist/search/index.d.ts +6 -5
  67. package/dist/search/index.d.ts.map +1 -1
  68. package/dist/search/index.js +6 -5
  69. package/dist/search/index.js.map +1 -1
  70. package/dist/search/model/index-builder.d.ts +61 -0
  71. package/dist/search/model/index-builder.d.ts.map +1 -0
  72. package/dist/search/model/index-builder.js +84 -0
  73. package/dist/search/model/index-builder.js.map +1 -0
  74. package/dist/search/model/index.d.ts +3 -0
  75. package/dist/search/model/index.d.ts.map +1 -0
  76. package/dist/search/model/index.js +9 -0
  77. package/dist/search/model/index.js.map +1 -0
  78. package/dist/search/model/properties/base.d.ts +52 -0
  79. package/dist/search/model/properties/base.d.ts.map +1 -0
  80. package/dist/search/model/properties/base.js +139 -0
  81. package/dist/search/model/properties/base.js.map +1 -0
  82. package/dist/search/model/properties/boolean.d.ts +8 -0
  83. package/dist/search/model/properties/boolean.d.ts.map +1 -0
  84. package/dist/search/model/properties/boolean.js +14 -0
  85. package/dist/search/model/properties/boolean.js.map +1 -0
  86. package/dist/search/model/properties/date.d.ts +8 -0
  87. package/dist/search/model/properties/date.d.ts.map +1 -0
  88. package/dist/search/model/properties/date.js +16 -0
  89. package/dist/search/model/properties/date.js.map +1 -0
  90. package/dist/search/model/properties/float.d.ts +8 -0
  91. package/dist/search/model/properties/float.d.ts.map +1 -0
  92. package/dist/search/model/properties/float.js +14 -0
  93. package/dist/search/model/properties/float.js.map +1 -0
  94. package/dist/search/model/properties/geo.d.ts +11 -0
  95. package/dist/search/model/properties/geo.d.ts.map +1 -0
  96. package/dist/search/model/properties/geo.js +14 -0
  97. package/dist/search/model/properties/geo.js.map +1 -0
  98. package/dist/search/model/properties/index.d.ts +11 -0
  99. package/dist/search/model/properties/index.d.ts.map +1 -0
  100. package/dist/search/model/properties/index.js +27 -0
  101. package/dist/search/model/properties/index.js.map +1 -0
  102. package/dist/search/model/properties/integer.d.ts +8 -0
  103. package/dist/search/model/properties/integer.d.ts.map +1 -0
  104. package/dist/search/model/properties/integer.js +14 -0
  105. package/dist/search/model/properties/integer.js.map +1 -0
  106. package/dist/search/model/properties/keyword.d.ts +8 -0
  107. package/dist/search/model/properties/keyword.d.ts.map +1 -0
  108. package/dist/search/model/properties/keyword.js +14 -0
  109. package/dist/search/model/properties/keyword.js.map +1 -0
  110. package/dist/search/model/properties/object.d.ts +12 -0
  111. package/dist/search/model/properties/object.d.ts.map +1 -0
  112. package/dist/search/model/properties/object.js +38 -0
  113. package/dist/search/model/properties/object.js.map +1 -0
  114. package/dist/search/model/properties/text.d.ts +8 -0
  115. package/dist/search/model/properties/text.d.ts.map +1 -0
  116. package/dist/search/model/properties/text.js +14 -0
  117. package/dist/search/model/properties/text.js.map +1 -0
  118. package/dist/search/model/properties/vector.d.ts +18 -0
  119. package/dist/search/model/properties/vector.d.ts.map +1 -0
  120. package/dist/search/model/properties/vector.js +51 -0
  121. package/dist/search/model/properties/vector.js.map +1 -0
  122. package/dist/search/model/search-fields-schema.d.ts +22 -0
  123. package/dist/search/model/search-fields-schema.d.ts.map +1 -0
  124. package/dist/search/model/search-fields-schema.js +70 -0
  125. package/dist/search/model/search-fields-schema.js.map +1 -0
  126. package/dist/search/search-scope.d.ts +44 -0
  127. package/dist/search/search-scope.d.ts.map +1 -0
  128. package/dist/search/search-scope.js +111 -0
  129. package/dist/search/search-scope.js.map +1 -0
  130. package/dist/{search → search-legacy}/abstract-service.d.ts +19 -19
  131. package/dist/search-legacy/abstract-service.d.ts.map +1 -0
  132. package/dist/{search → search-legacy}/abstract-service.js +8 -8
  133. package/dist/search-legacy/abstract-service.js.map +1 -0
  134. package/dist/search-legacy/index-types.d.ts.map +1 -0
  135. package/dist/search-legacy/index-types.js.map +1 -0
  136. package/dist/search-legacy/index.d.ts +6 -0
  137. package/dist/search-legacy/index.d.ts.map +1 -0
  138. package/dist/search-legacy/index.js +22 -0
  139. package/dist/search-legacy/index.js.map +1 -0
  140. package/dist/search-legacy/search-relations.d.ts.map +1 -0
  141. package/dist/search-legacy/search-relations.js.map +1 -0
  142. package/dist/{search → search-legacy}/types.d.ts +29 -29
  143. package/dist/search-legacy/types.d.ts.map +1 -0
  144. package/dist/{search → search-legacy}/types.js +1 -1
  145. package/dist/search-legacy/types.js.map +1 -0
  146. package/dist/search-legacy/variant-keys.d.ts.map +1 -0
  147. package/dist/search-legacy/variant-keys.js.map +1 -0
  148. package/dist/tsconfig.tsbuildinfo +1 -1
  149. package/package.json +7 -2
  150. package/dist/search/abstract-service.d.ts.map +0 -1
  151. package/dist/search/abstract-service.js.map +0 -1
  152. package/dist/search/index-types.d.ts.map +0 -1
  153. package/dist/search/index-types.js.map +0 -1
  154. package/dist/search/search-relations.d.ts.map +0 -1
  155. package/dist/search/search-relations.js.map +0 -1
  156. package/dist/search/types.d.ts.map +0 -1
  157. package/dist/search/types.js.map +0 -1
  158. package/dist/search/variant-keys.d.ts.map +0 -1
  159. package/dist/search/variant-keys.js.map +0 -1
  160. /package/dist/{search → search-legacy}/index-types.d.ts +0 -0
  161. /package/dist/{search → search-legacy}/index-types.js +0 -0
  162. /package/dist/{search → search-legacy}/search-relations.d.ts +0 -0
  163. /package/dist/{search → search-legacy}/search-relations.js +0 -0
  164. /package/dist/{search → search-legacy}/variant-keys.d.ts +0 -0
  165. /package/dist/{search → search-legacy}/variant-keys.js +0 -0
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SearchFieldsSchema = void 0;
5
+ const IsSearchFieldsSchema = Symbol.for("isSearchFieldsSchema");
6
+ /**
7
+ * A fields schema produced by `search.define(...)`. Compiles to plain
8
+ * SearchFieldDefinition records for the Search Module.
9
+ */
10
+ class SearchFieldsSchema {
11
+ constructor(schema) {
12
+ this[_a] = true;
13
+ this.schema = schema;
14
+ }
15
+ static isSearchFieldsSchema(value) {
16
+ return !!value?.[IsSearchFieldsSchema];
17
+ }
18
+ /**
19
+ * Compile the DSL schema into plain SearchFieldDefinition records.
20
+ */
21
+ toFields() {
22
+ const fields = {};
23
+ for (const [fieldName, property] of Object.entries(this.schema)) {
24
+ fields[fieldName] = metadataToFieldDefinition(property.parse(fieldName));
25
+ }
26
+ return fields;
27
+ }
28
+ }
29
+ exports.SearchFieldsSchema = SearchFieldsSchema;
30
+ _a = IsSearchFieldsSchema;
31
+ function metadataToFieldDefinition(metadata) {
32
+ const field = {
33
+ type: metadata.dataType.name,
34
+ };
35
+ if (metadata.array !== undefined) {
36
+ field.array = metadata.array;
37
+ }
38
+ if (metadata.searchable !== undefined) {
39
+ field.searchable = metadata.searchable;
40
+ }
41
+ if (metadata.filterable !== undefined) {
42
+ field.filterable = metadata.filterable;
43
+ }
44
+ if (metadata.sortable !== undefined) {
45
+ field.sortable = metadata.sortable;
46
+ }
47
+ if (metadata.facetable !== undefined) {
48
+ field.facetable = metadata.facetable;
49
+ }
50
+ if (metadata.retrievable !== undefined) {
51
+ field.retrievable = metadata.retrievable;
52
+ }
53
+ if (metadata.dimensions !== undefined) {
54
+ field.dimensions = metadata.dimensions;
55
+ }
56
+ if (metadata.embed !== undefined) {
57
+ field.embed = metadata.embed;
58
+ }
59
+ if (metadata.provider_options !== undefined) {
60
+ field.provider_options = metadata.provider_options;
61
+ }
62
+ if (metadata.fields) {
63
+ field.fields = {};
64
+ for (const [name, nested] of Object.entries(metadata.fields)) {
65
+ field.fields[name] = metadataToFieldDefinition(nested);
66
+ }
67
+ }
68
+ return field;
69
+ }
70
+ //# sourceMappingURL=search-fields-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-fields-schema.js","sourceRoot":"","sources":["../../../src/search/model/search-fields-schema.ts"],"names":[],"mappings":";;;;AAOA,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;AAE/D;;;GAGG;AACH,MAAa,kBAAkB;IAW7B,YAAY,MAAc;QAR1B,QAAsB,GAAG,IAAI,CAAA;QAS3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,MAAM,CAAC,oBAAoB,CACzB,KAAc;QAEd,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,oBAAoB,CAAC,CAAA;IACxC,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,MAAM,MAAM,GAA0C,EAAE,CAAA;QAExD,KAAK,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAChE,MAAM,CAAC,SAAS,CAAC,GAAG,yBAAyB,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAA;QAC1E,CAAC;QA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C5C,KAAK,CAAC,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAA;IACpD,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,MAAM,GAAG,EAAE,CAAA;QACjB,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7D,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAA;QACxD,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { SearchTypes } from "@etohq/types";
2
+ /**
3
+ * What one search request may see, as resolved per request by the index's
4
+ * `scope` resolver in `configureScopedSearch`: the audiences it reads from
5
+ * (a publishable key's sales channels, a member's networks) and the root(s)
6
+ * of their trees.
7
+ */
8
+ export type SearchRequestScope = {
9
+ /** The audiences the request may see. Must not be empty. */
10
+ audience_ids: string[];
11
+ /** The root(s) of the request's audience trees. Must not be empty. */
12
+ root_id: string | string[];
13
+ };
14
+ /**
15
+ * The root of a node in a tree stored as a materialized path, such as a sales
16
+ * channel's or a network's `mpath` (`root.child.grandchild`). A root's path is
17
+ * its own id.
18
+ */
19
+ export declare function treeRootOf(path: string, separator?: string): string;
20
+ /**
21
+ * The distinct roots of several nodes' materialized paths. What an index
22
+ * writes into its `scope.root` field next to the audiences, and what a request
23
+ * resolves for its own audiences.
24
+ */
25
+ export declare function treeRootsOf(paths: string[], separator?: string): string[];
26
+ /**
27
+ * Refuses a `scope` that names a missing field, a field that can't be
28
+ * filtered on, or a field that can be faceted. A facet on a scoping field
29
+ * would count documents outside the request's scope, because disjunctive
30
+ * faceting drops that field's own filter to compute it.
31
+ *
32
+ * Does nothing for an index that declares no `scope`.
33
+ */
34
+ export declare function validateSearchScope(definition: Pick<SearchTypes.SearchIndexDefinition, "name" | "fields" | "scope">): void;
35
+ /**
36
+ * The filters that confine a search to the request's scope: visible, sharing
37
+ * an audience with the request, and under one of its roots. ANDed onto every
38
+ * query, so a client can narrow its results but never widen past them.
39
+ *
40
+ * Throws rather than returning an unscoped filter when the index declares no
41
+ * `scope` or the request resolved no audiences or no root.
42
+ */
43
+ export declare function buildSearchScopeFilters(definition: Pick<SearchTypes.SearchIndexDefinition, "name" | "fields" | "scope">, scope: SearchRequestScope): SearchTypes.SearchFilters;
44
+ //# sourceMappingURL=search-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-scope.d.ts","sourceRoot":"","sources":["../../src/search/search-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAG1C;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,4DAA4D;IAC5D,YAAY,EAAE,MAAM,EAAE,CAAA;IAEtB,sEAAsE;IACtE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC3B,CAAA;AAMD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAM,GAAG,MAAM,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,SAAM,GAAG,MAAM,EAAE,CAMtE;AAkBD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,GAC/E,IAAI,CAwCN;AAsBD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,IAAI,CACd,WAAW,CAAC,qBAAqB,EACjC,MAAM,GAAG,QAAQ,GAAG,OAAO,CAC5B,EACD,KAAK,EAAE,kBAAkB,GACxB,WAAW,CAAC,aAAa,CAuC3B"}
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.treeRootOf = treeRootOf;
4
+ exports.treeRootsOf = treeRootsOf;
5
+ exports.validateSearchScope = validateSearchScope;
6
+ exports.buildSearchScopeFilters = buildSearchScopeFilters;
7
+ const common_1 = require("../common");
8
+ const SCOPE_ROLES = ["visible", "audiences", "root"];
9
+ /**
10
+ * The root of a node in a tree stored as a materialized path, such as a sales
11
+ * channel's or a network's `mpath` (`root.child.grandchild`). A root's path is
12
+ * its own id.
13
+ */
14
+ function treeRootOf(path, separator = ".") {
15
+ return path.split(separator)[0];
16
+ }
17
+ /**
18
+ * The distinct roots of several nodes' materialized paths. What an index
19
+ * writes into its `scope.root` field next to the audiences, and what a request
20
+ * resolves for its own audiences.
21
+ */
22
+ function treeRootsOf(paths, separator = ".") {
23
+ return [
24
+ ...new Set(paths.filter(Boolean).map((path) => treeRootOf(path, separator))),
25
+ ];
26
+ }
27
+ function findField(fields, path) {
28
+ const [head, ...rest] = path.split(".");
29
+ const field = fields[head];
30
+ if (!field || !rest.length) {
31
+ return field;
32
+ }
33
+ return field.type === "object" && field.fields
34
+ ? findField(field.fields, rest.join("."))
35
+ : undefined;
36
+ }
37
+ /**
38
+ * Refuses a `scope` that names a missing field, a field that can't be
39
+ * filtered on, or a field that can be faceted. A facet on a scoping field
40
+ * would count documents outside the request's scope, because disjunctive
41
+ * faceting drops that field's own filter to compute it.
42
+ *
43
+ * Does nothing for an index that declares no `scope`.
44
+ */
45
+ function validateSearchScope(definition) {
46
+ const scope = definition.scope;
47
+ if (!scope) {
48
+ return;
49
+ }
50
+ for (const role of SCOPE_ROLES) {
51
+ const path = scope[role]?.field;
52
+ if (!path) {
53
+ throw new common_1.EtoError(common_1.EtoError.Types.INVALID_DATA, `Search index "${definition.name}" scope must name its ${role} field`);
54
+ }
55
+ const field = findField(definition.fields, path);
56
+ if (!field) {
57
+ throw new common_1.EtoError(common_1.EtoError.Types.INVALID_DATA, `Search index "${definition.name}" scope ${role} field "${path}" is not a field of the index`);
58
+ }
59
+ if (field.filterable !== true) {
60
+ throw new common_1.EtoError(common_1.EtoError.Types.INVALID_DATA, `Search index "${definition.name}" scope ${role} field "${path}" must be filterable`);
61
+ }
62
+ if (field.facetable) {
63
+ throw new common_1.EtoError(common_1.EtoError.Types.INVALID_DATA, `Search index "${definition.name}" scope ${role} field "${path}" must not be facetable: a facet on it counts documents outside the reader's scope`);
64
+ }
65
+ }
66
+ }
67
+ const toList = (value) => (Array.isArray(value) ? value : [value]).filter((item) => !!item);
68
+ // An array field matches when it shares a value with the request; a scalar
69
+ // one when its value is among the request's. Either way the request's list is
70
+ // never widened.
71
+ function anyOf(definition, path, values) {
72
+ const field = findField(definition.fields ?? {}, path);
73
+ return {
74
+ [path]: field?.array ? { $overlaps: values } : { $in: values },
75
+ };
76
+ }
77
+ /**
78
+ * The filters that confine a search to the request's scope: visible, sharing
79
+ * an audience with the request, and under one of its roots. ANDed onto every
80
+ * query, so a client can narrow its results but never widen past them.
81
+ *
82
+ * Throws rather than returning an unscoped filter when the index declares no
83
+ * `scope` or the request resolved no audiences or no root.
84
+ */
85
+ function buildSearchScopeFilters(definition, scope) {
86
+ const declared = definition.scope;
87
+ if (!declared) {
88
+ throw new common_1.EtoError(common_1.EtoError.Types.INVALID_DATA, `Search index "${definition.name}" declares no scope, so it can't be served outside the back office`);
89
+ }
90
+ const audiences = toList(scope?.audience_ids);
91
+ if (!audiences.length) {
92
+ throw new common_1.EtoError(common_1.EtoError.Types.INVALID_DATA, `Search on "${definition.name}" resolved no audiences (sales channels, networks) for this request`);
93
+ }
94
+ const roots = toList(scope?.root_id);
95
+ if (!roots.length) {
96
+ throw new common_1.EtoError(common_1.EtoError.Types.INVALID_DATA, `Search on "${definition.name}" resolved no root for this request`);
97
+ }
98
+ const visible = declared.visible.value;
99
+ return {
100
+ $and: [
101
+ {
102
+ [declared.visible.field]: Array.isArray(visible)
103
+ ? { $in: visible }
104
+ : { $eq: visible },
105
+ },
106
+ anyOf(definition, declared.audiences.field, audiences),
107
+ anyOf(definition, declared.root.field, roots),
108
+ ],
109
+ };
110
+ }
111
+ //# sourceMappingURL=search-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-scope.js","sourceRoot":"","sources":["../../src/search/search-scope.ts"],"names":[],"mappings":";;AA0BA,gCAEC;AAOD,kCAMC;AA0BD,kDA0CC;AA8BD,0DA6CC;AAvLD,sCAAoC;AAkBpC,MAAM,WAAW,GAAgB,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,CAAC,CAAA;AAEjE;;;;GAIG;AACH,SAAgB,UAAU,CAAC,IAAY,EAAE,SAAS,GAAG,GAAG;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;AACjC,CAAC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CAAC,KAAe,EAAE,SAAS,GAAG,GAAG;IAC1D,OAAO;QACL,GAAG,IAAI,GAAG,CACR,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CACjE;KACF,CAAA;AACH,CAAC;AAED,SAAS,SAAS,CAChB,MAAyD,EACzD,IAAY;IAEZ,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAE1B,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM;QAC5C,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC,CAAC,S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CAAC,KAAK,CAAC,YAAY,EAC3B,cAAc,UAAU,CAAC,IAAI,qCAAqC,CACnE,CAAA;IACH,CAAC;IAED,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAA;IAEtC,OAAO;QACL,IAAI,EAAE;YACJ;gBACE,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;oBAC9C,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE;oBAClB,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE;aACrB;YACD,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;YACtD,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC;SAC9C;KACF,CAAA;AACH,CAAC"}
@@ -1,9 +1,9 @@
1
- import { SearchTypes } from "@etohq/types";
2
- import type { SearchIndexDocument, SearchIndexGroup, SearchQuery, SearchResult } from "./types";
1
+ import { SearchLegacyTypes } from "@etohq/types";
2
+ import type { LegacySearchIndexDocument, LegacySearchIndexGroup, LegacySearchQuery, LegacySearchResult } from "./types";
3
3
  /**
4
4
  * ## Overview
5
5
  *
6
- * A search service class is in a TypeScript or JavaScript file created in the `src/services` directory. The class must extend the `AbstractSearchService` class imported
6
+ * A search service class is in a TypeScript or JavaScript file created in the `src/services` directory. The class must extend the `AbstractLegacySearchService` class imported
7
7
  * from the `@etohq/utils` package.
8
8
  *
9
9
  * Based on services’ naming conventions, the file’s name should be the slug version of the search service’s name without `service`, and the class’s name should be the
@@ -12,9 +12,9 @@ import type { SearchIndexDocument, SearchIndexGroup, SearchQuery, SearchResult }
12
12
  * For example, create the `MySearchService` class in the file `src/services/my-search.ts`:
13
13
  *
14
14
  * ```ts title="src/services/my-search.ts"
15
- * import { AbstractSearchService } from "@etohq/utils"
15
+ * import { AbstractLegacySearchService } from "@etohq/utils"
16
16
  *
17
- * class MySearchService extends AbstractSearchService {
17
+ * class MySearchService extends AbstractLegacySearchService {
18
18
  * isDefault = false
19
19
  *
20
20
  * createIndex(indexName: string, options: Record<string, any>) {
@@ -76,7 +76,7 @@ import type { SearchIndexDocument, SearchIndexGroup, SearchQuery, SearchResult }
76
76
  *
77
77
  * ---
78
78
  */
79
- export declare abstract class AbstractSearchService implements SearchTypes.ISearchService {
79
+ export declare abstract class AbstractLegacySearchService implements SearchLegacyTypes.ILegacySearchService {
80
80
  /**
81
81
  * @ignore
82
82
  */
@@ -117,7 +117,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
117
117
  * productService: ProductService
118
118
  * }
119
119
  *
120
- * class MySearchService extends AbstractSearchService {
120
+ * class MySearchService extends AbstractLegacySearchService {
121
121
  * // ...
122
122
  * protected readonly productService_: ProductService
123
123
  *
@@ -147,7 +147,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
147
147
  * An example implementation, assuming `client` would interact with a third-party service:
148
148
  *
149
149
  * ```ts title="src/services/my-search.ts"
150
- * class MySearchService extends AbstractSearchService {
150
+ * class MySearchService extends AbstractLegacySearchService {
151
151
  * // ...
152
152
  * createIndex(indexName: string, options: Record<string, any>) {
153
153
  * return this.client_.initIndex(indexName)
@@ -160,7 +160,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
160
160
  * `options` parameter:
161
161
  *
162
162
  * ```ts
163
- * class MeiliSearchService extends AbstractSearchService {
163
+ * class MeiliSearchService extends AbstractLegacySearchService {
164
164
  * // ...
165
165
  * async createIndex(
166
166
  * indexName: string,
@@ -180,7 +180,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
180
180
  * @returns {unknown} No required format of returned data, as it depends on your custom implementation.
181
181
  *
182
182
  * @example
183
- * class MySearchService extends AbstractSearchService {
183
+ * class MySearchService extends AbstractLegacySearchService {
184
184
  * // ...
185
185
  *
186
186
  * getIndex(indexName: string) {
@@ -201,7 +201,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
201
201
  * @returns {unknown} The response of saving the documents in the search engine, but there’s no required format of the response.
202
202
  *
203
203
  * @example
204
- * class MySearchService extends AbstractSearchService {
204
+ * class MySearchService extends AbstractLegacySearchService {
205
205
  * // ...
206
206
  *
207
207
  * async addDocuments(
@@ -225,7 +225,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
225
225
  * @returns {unknown} The response of replacing the documents in the search engine, but there’s no required format of the response.
226
226
  *
227
227
  * @example
228
- * class MySearchService extends AbstractSearchService {
228
+ * class MySearchService extends AbstractLegacySearchService {
229
229
  * // ...
230
230
  *
231
231
  * async replaceDocuments(
@@ -252,7 +252,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
252
252
  * @returns {unknown} The response of deleting the document in the search engine, but there’s no required format of the response.
253
253
  *
254
254
  * @example
255
- * class MySearchService extends AbstractSearchService {
255
+ * class MySearchService extends AbstractLegacySearchService {
256
256
  * // ...
257
257
  *
258
258
  * async deleteDocument(
@@ -272,7 +272,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
272
272
  * @returns {unknown} The response of deleting the documents of that index in the search engine, but there’s no required format of the response.
273
273
  *
274
274
  * @example
275
- * class MySearchService extends AbstractSearchService {
275
+ * class MySearchService extends AbstractLegacySearchService {
276
276
  * // ...
277
277
  *
278
278
  * async deleteAllDocuments(indexName: string) {
@@ -301,7 +301,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
301
301
  * @returns {unknown} The list of results. For example, an array of products.
302
302
  *
303
303
  * @example
304
- * class MySearchService extends AbstractSearchService {
304
+ * class MySearchService extends AbstractLegacySearchService {
305
305
  * // ...
306
306
  *
307
307
  * async search(
@@ -329,7 +329,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
329
329
  * @returns {unknown} The response of updating the index in the search engine, but there’s no required format of the response.
330
330
  *
331
331
  * @example
332
- * class MySearchService extends AbstractSearchService {
332
+ * class MySearchService extends AbstractLegacySearchService {
333
333
  * // ...
334
334
  *
335
335
  * async updateSettings(
@@ -360,7 +360,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
360
360
  /**
361
361
  * Creates or replaces a group (a top-level bucket of documents).
362
362
  */
363
- upsertGroup(group: SearchIndexGroup): Promise<void>;
363
+ upsertGroup(group: LegacySearchIndexGroup): Promise<void>;
364
364
  /**
365
365
  * Removes a group by its tracking id.
366
366
  */
@@ -368,7 +368,7 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
368
368
  /**
369
369
  * Upserts documents (chunks). Implementations must be idempotent by tracking id.
370
370
  */
371
- upsertDocuments(documents: SearchIndexDocument[]): Promise<void>;
371
+ upsertDocuments(documents: LegacySearchIndexDocument[]): Promise<void>;
372
372
  /**
373
373
  * Removes documents by their tracking ids.
374
374
  */
@@ -377,6 +377,6 @@ export declare abstract class AbstractSearchService implements SearchTypes.ISear
377
377
  * Searches documents, returning ranked hits. The caller hydrates the ids
378
378
  * from the source of truth.
379
379
  */
380
- searchDocuments(query: SearchQuery): Promise<SearchResult>;
380
+ searchDocuments(query: LegacySearchQuery): Promise<LegacySearchResult>;
381
381
  }
382
382
  //# sourceMappingURL=abstract-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-service.d.ts","sourceRoot":"","sources":["../../src/search-legacy/abstract-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,OAAO,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAA;AAEhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,8BAAsB,2BACpB,YAAW,iBAAiB,CAAC,oBAAoB;IAEjD;;OAEG;IACH,MAAM,CAAC,gBAAgB,UAAO;IAE9B;;OAEG;IACH,MAAM,CAAC,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EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,EAAE,OAAO,GACf,OAAO;IAEV;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO;IAEtE;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAQ;IAExC;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAQ;IAE3C,SAAS,CAAC,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK;IAMrE;;OAEG;IACG,WAAW,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D;;OAEG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD;;OAEG;IACG,eAAe,CAAC,SAAS,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5E;;OAEG;IACG,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3D;;;OAGG;IACG,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAG7E"}
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractSearchService = void 0;
3
+ exports.AbstractLegacySearchService = void 0;
4
4
  /**
5
5
  * ## Overview
6
6
  *
7
- * A search service class is in a TypeScript or JavaScript file created in the `src/services` directory. The class must extend the `AbstractSearchService` class imported
7
+ * A search service class is in a TypeScript or JavaScript file created in the `src/services` directory. The class must extend the `AbstractLegacySearchService` class imported
8
8
  * from the `@etohq/utils` package.
9
9
  *
10
10
  * Based on services’ naming conventions, the file’s name should be the slug version of the search service’s name without `service`, and the class’s name should be the
@@ -13,9 +13,9 @@ exports.AbstractSearchService = void 0;
13
13
  * For example, create the `MySearchService` class in the file `src/services/my-search.ts`:
14
14
  *
15
15
  * ```ts title="src/services/my-search.ts"
16
- * import { AbstractSearchService } from "@etohq/utils"
16
+ * import { AbstractLegacySearchService } from "@etohq/utils"
17
17
  *
18
- * class MySearchService extends AbstractSearchService {
18
+ * class MySearchService extends AbstractLegacySearchService {
19
19
  * isDefault = false
20
20
  *
21
21
  * createIndex(indexName: string, options: Record<string, any>) {
@@ -77,7 +77,7 @@ exports.AbstractSearchService = void 0;
77
77
  *
78
78
  * ---
79
79
  */
80
- class AbstractSearchService {
80
+ class AbstractLegacySearchService {
81
81
  /**
82
82
  * @ignore
83
83
  */
@@ -110,7 +110,7 @@ class AbstractSearchService {
110
110
  * productService: ProductService
111
111
  * }
112
112
  *
113
- * class MySearchService extends AbstractSearchService {
113
+ * class MySearchService extends AbstractLegacySearchService {
114
114
  * // ...
115
115
  * protected readonly productService_: ProductService
116
116
  *
@@ -179,9 +179,9 @@ class AbstractSearchService {
179
179
  throw this.capabilityUnsupported_("searchDocuments", "supportsDocuments");
180
180
  }
181
181
  }
182
- exports.AbstractSearchService = AbstractSearchService;
182
+ exports.AbstractLegacySearchService = AbstractLegacySearchService;
183
183
  /**
184
184
  * @ignore
185
185
  */
186
- AbstractSearchService._isSearchService = true;
186
+ AbstractLegacySearchService._isSearchService = true;
187
187
  //# sourceMappingURL=abstract-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-service.js","sourceRoot":"","sources":["../../src/search-legacy/abstract-service.ts"],"names":[],"mappings":";;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,MAAsB,2BAA2B;IAQ/C;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,GAAG;QACxB,OAAO,GAAG,EAAE,WAAW,EAAE,gBAAgB,CAAA;IAC3C,CAAC;IAWD;;OAEG;IACH,IAAI,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-types.d.ts","sourceRoot":"","sources":["../../src/search-legacy/index-types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;CAEtB,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-types.js","sourceRoot":"","sources":["../../src/search-legacy/index-types.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACxB,QAAQ,EAAE,UAAU;CACrB,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from "./abstract-service";
2
+ export * from "./search-relations";
3
+ export * from "./index-types";
4
+ export * from "./variant-keys";
5
+ export * from "./types";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search-legacy/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./abstract-service"), exports);
18
+ __exportStar(require("./search-relations"), exports);
19
+ __exportStar(require("./index-types"), exports);
20
+ __exportStar(require("./variant-keys"), exports);
21
+ __exportStar(require("./types"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/search-legacy/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAkC;AAClC,qDAAkC;AAClC,gDAA6B;AAC7B,iDAA8B;AAC9B,0CAAuB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-relations.d.ts","sourceRoot":"","sources":["../../src/search-legacy/search-relations.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qCAAqC,UASjD,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-relations.js","sourceRoot":"","sources":["../../src/search-legacy/search-relations.ts"],"names":[],"mappings":";;;AAAa,QAAA,qCAAqC,GAAG;IACnD,UAAU;IACV,MAAM;IACN,MAAM;IACN,YAAY;IACZ,iBAAiB;IACjB,QAAQ;IACR,kBAAkB;IAClB,SAAS;CACV,CAAA"}
@@ -1,18 +1,18 @@
1
1
  /**
2
- * Types for the group/document capability of {@link AbstractSearchService}.
2
+ * Types for the group/document capability of {@link AbstractLegacySearchService}.
3
3
  *
4
4
  * Search engines that natively model a dataset as groups and documents (chunks)
5
5
  * — such as Trieve — implement this capability. Documents are addressed by a
6
6
  * tracking id and partitioned by `type:<entity>` tags.
7
7
  */
8
- export type SearchIndexGroup = {
8
+ export type LegacySearchIndexGroup = {
9
9
  tracking_id: string;
10
10
  name: string;
11
11
  description?: string | null;
12
12
  tag_set?: string[];
13
13
  metadata?: Record<string, unknown>;
14
14
  };
15
- export type SearchIndexDocument = {
15
+ export type LegacySearchIndexDocument = {
16
16
  tracking_id: string;
17
17
  /** Groups the document belongs to (e.g. `["source:src_1"]`). */
18
18
  group_tracking_ids?: string[];
@@ -22,20 +22,20 @@ export type SearchIndexDocument = {
22
22
  metadata?: Record<string, unknown>;
23
23
  };
24
24
  /** A scalar a filter can match. */
25
- export type SearchValue = string | number | boolean;
25
+ export type LegacySearchValue = string | number | boolean;
26
26
  /**
27
27
  * Per-field operators — a small, engine-neutral vocabulary. Providers map what
28
28
  * they support onto their engine and ignore the rest (`supportsOperators`).
29
29
  */
30
- export type SearchOperators = {
31
- $eq?: SearchValue | SearchValue[];
32
- $ne?: SearchValue;
33
- $in?: SearchValue[];
34
- $nin?: SearchValue[];
35
- $gt?: SearchValue;
36
- $gte?: SearchValue;
37
- $lt?: SearchValue;
38
- $lte?: SearchValue;
30
+ export type LegacySearchOperators = {
31
+ $eq?: LegacySearchValue | LegacySearchValue[];
32
+ $ne?: LegacySearchValue;
33
+ $in?: LegacySearchValue[];
34
+ $nin?: LegacySearchValue[];
35
+ $gt?: LegacySearchValue;
36
+ $gte?: LegacySearchValue;
37
+ $lt?: LegacySearchValue;
38
+ $lte?: LegacySearchValue;
39
39
  /** Substring / text match. */
40
40
  $like?: string;
41
41
  /** Prefix match. */
@@ -43,16 +43,16 @@ export type SearchOperators = {
43
43
  $exists?: boolean;
44
44
  };
45
45
  /** One condition group: `{ source_id: "src_1", upvotes: { $gte: 10 } }`. */
46
- export type SearchCondition = {
47
- [field: string]: SearchValue | SearchValue[] | SearchOperators;
46
+ export type LegacySearchCondition = {
47
+ [field: string]: LegacySearchValue | LegacySearchValue[] | LegacySearchOperators;
48
48
  };
49
49
  /** An ordered sort clause; `relevance` is the engine's default score. */
50
- export type SearchSort = {
50
+ export type LegacySearchSort = {
51
51
  field: string;
52
52
  direction?: "asc" | "desc";
53
53
  };
54
54
  /** Engine-neutral relevance shaping. */
55
- export type SearchRanking = {
55
+ export type LegacySearchRanking = {
56
56
  strategy?: "relevance" | "recent" | "similar" | "personalized" | "popular";
57
57
  /** Favour recent documents, optionally on a specific field. */
58
58
  recency?: {
@@ -66,7 +66,7 @@ export type SearchRanking = {
66
66
  weight: number;
67
67
  }[];
68
68
  };
69
- export type SearchQuery = {
69
+ export type LegacySearchQuery = {
70
70
  /** Free-text query; omit to browse by filters alone. */
71
71
  query?: string;
72
72
  /** Retrieval mode, when the engine supports several. */
@@ -78,14 +78,14 @@ export type SearchQuery = {
78
78
  /** Tags every document must carry. */
79
79
  tag_set?: string[];
80
80
  /** Exact-match conditions, combined with AND. */
81
- filters?: SearchCondition;
81
+ filters?: LegacySearchCondition;
82
82
  /** Any-of condition groups, OR-ed together and AND-ed with `filters`. */
83
- filters_any?: SearchCondition[];
83
+ filters_any?: LegacySearchCondition[];
84
84
  /** Conditions every match must NOT satisfy. */
85
- filters_not?: SearchCondition;
85
+ filters_not?: LegacySearchCondition;
86
86
  /** Ordered sort clauses (applied in order). */
87
- sort?: SearchSort[];
88
- ranking?: SearchRanking;
87
+ sort?: LegacySearchSort[];
88
+ ranking?: LegacySearchRanking;
89
89
  /** Recommend documents similar to these ids. */
90
90
  similar_to?: {
91
91
  positive?: string[];
@@ -93,7 +93,7 @@ export type SearchQuery = {
93
93
  exclude?: string[];
94
94
  };
95
95
  /** Extensible request context (user, locale, market, experiment, …). */
96
- context?: Record<string, SearchValue | undefined>;
96
+ context?: Record<string, LegacySearchValue | undefined>;
97
97
  /** Metadata keys to aggregate counts for. */
98
98
  facets?: string[];
99
99
  /** What to return per hit, when the engine can supply it. */
@@ -106,24 +106,24 @@ export type SearchQuery = {
106
106
  /** Opaque continuation token for cursor-based engines. */
107
107
  cursor?: string;
108
108
  };
109
- export type SearchHit = {
109
+ export type LegacySearchHit = {
110
110
  id: string;
111
111
  score?: number;
112
112
  /** Indexed document metadata, e.g. `{ post_id, source_id, tags }`. */
113
113
  metadata?: Record<string, unknown>;
114
114
  highlights?: Record<string, string[]>;
115
115
  };
116
- export type SearchFacet = {
116
+ export type LegacySearchFacet = {
117
117
  value: string;
118
118
  count: number;
119
119
  };
120
- export type SearchResult = {
121
- hits: SearchHit[];
120
+ export type LegacySearchResult = {
121
+ hits: LegacySearchHit[];
122
122
  /** Absent when the engine cannot count cheaply (cursor-based engines). */
123
123
  total?: number;
124
124
  /** Continuation token for the next page, when supported. */
125
125
  cursor?: string;
126
126
  /** Facet counts, keyed by the requested metadata field. */
127
- facets?: Record<string, SearchFacet[]>;
127
+ facets?: Record<string, LegacySearchFacet[]>;
128
128
  };
129
129
  //# sourceMappingURL=types.d.ts.map