@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,104 @@
1
+ "use strict";
2
+ /**
3
+ * What a review may contain. Pure, so the module and every consumer agree on
4
+ * one answer, and the rule is tested once.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.REVIEW_LIMITS = void 0;
8
+ exports.isStars = isStars;
9
+ exports.reviewContentProblems = reviewContentProblems;
10
+ exports.cleanReviewText = cleanReviewText;
11
+ exports.reviewTextConcerns = reviewTextConcerns;
12
+ exports.REVIEW_LIMITS = {
13
+ title: 120,
14
+ body: 5000,
15
+ response: 2000,
16
+ tags: 10,
17
+ tag: 40,
18
+ dimensions: 8,
19
+ dimension_key: 40,
20
+ media: 10,
21
+ display: 80,
22
+ };
23
+ /** A tag or dimension key: lowercase words joined by underscores. */
24
+ const KEY = /^[a-z][a-z0-9_]*$/;
25
+ function isStars(n) {
26
+ return typeof n === "number" && Number.isInteger(n) && n >= 1 && n <= 5;
27
+ }
28
+ /**
29
+ * Problems with a review's content, in plain words, or [] when it is fine.
30
+ * `partial` checks only the fields present (an edit).
31
+ */
32
+ function reviewContentProblems(content, options = {}) {
33
+ const problems = [];
34
+ if (!options.partial || content.rating !== undefined) {
35
+ if (!isStars(content.rating)) {
36
+ problems.push("rating must be a whole number of stars from 1 to 5");
37
+ }
38
+ }
39
+ const dims = content.dimensions;
40
+ if (dims) {
41
+ const keys = Object.keys(dims);
42
+ if (keys.length > exports.REVIEW_LIMITS.dimensions) {
43
+ problems.push(`at most ${exports.REVIEW_LIMITS.dimensions} dimensions`);
44
+ }
45
+ for (const key of keys) {
46
+ if (!KEY.test(key) || key.length > exports.REVIEW_LIMITS.dimension_key) {
47
+ problems.push(`dimension "${key}" must be lowercase_with_underscores`);
48
+ }
49
+ else if (!isStars(dims[key])) {
50
+ problems.push(`dimension "${key}" must be 1 to 5 stars`);
51
+ }
52
+ }
53
+ }
54
+ const tags = content.tags;
55
+ if (tags) {
56
+ if (tags.length > exports.REVIEW_LIMITS.tags) {
57
+ problems.push(`at most ${exports.REVIEW_LIMITS.tags} tags`);
58
+ }
59
+ if (new Set(tags).size !== tags.length) {
60
+ problems.push("tags must not repeat");
61
+ }
62
+ for (const tag of tags) {
63
+ if (typeof tag !== "string" || !KEY.test(tag) || tag.length > exports.REVIEW_LIMITS.tag) {
64
+ problems.push(`tag "${tag}" must be lowercase_with_underscores`);
65
+ }
66
+ }
67
+ }
68
+ if (content.title && content.title.length > exports.REVIEW_LIMITS.title) {
69
+ problems.push(`title is longer than ${exports.REVIEW_LIMITS.title} characters`);
70
+ }
71
+ if (content.body && content.body.length > exports.REVIEW_LIMITS.body) {
72
+ problems.push(`review is longer than ${exports.REVIEW_LIMITS.body} characters`);
73
+ }
74
+ if (content.media && content.media.length > exports.REVIEW_LIMITS.media) {
75
+ problems.push(`at most ${exports.REVIEW_LIMITS.media} attachments`);
76
+ }
77
+ return problems;
78
+ }
79
+ /** Trim, and turn blank into null. */
80
+ function cleanReviewText(text) {
81
+ const t = typeof text === "string" ? text.trim() : "";
82
+ return t ? t : null;
83
+ }
84
+ const PHONE = /(?:\+?\d[\d\s().-]{8,}\d)/;
85
+ const EMAIL = /[^\s@]+@[^\s@]+\.[a-z]{2,}/i;
86
+ const LINK = /\b(?:https?:\/\/|www\.)\S+|\b[a-z0-9-]+\.(?:com|ng|net|org|io|co|me|app|link|ly)\b/i;
87
+ /**
88
+ * Things in a review's text that usually mean it should wait for a moderator:
89
+ * contact details (people post phone numbers to take business off-platform,
90
+ * or to expose someone) and links. Not a judgement of tone — that is a
91
+ * moderator's call.
92
+ */
93
+ function reviewTextConcerns(...texts) {
94
+ const all = texts.filter(Boolean).join("\n");
95
+ const found = [];
96
+ if (PHONE.test(all))
97
+ found.push("phone_number");
98
+ if (EMAIL.test(all))
99
+ found.push("email");
100
+ if (LINK.test(all))
101
+ found.push("link");
102
+ return found;
103
+ }
104
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/review/rules.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAiBH,0BAEC;AAeD,sDAgDC;AAGD,0CAGC;AAcD,gDAOC;AA3GY,QAAA,aAAa,GAAG;IAC3B,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,EAAE;IACP,UAAU,EAAE,CAAC;IACb,aAAa,EAAE,EAAE;IACjB,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,EAAE;CACH,CAAA;AAEV,qEAAqE;AACrE,MAAM,GAAG,GAAG,mBAAmB,CAAA;AAE/B,SAAgB,OAAO,CAAC,CAAU;IAChC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzE,CAAC;AAWD;;;GAGG;AACH,SAAgB,qBAAqB,CACnC,OAA0B,EAC1B,UAAiC,EAAE;IAEnC,MAAM,QAAQ,GAAa,EAAE,CAAA;IAC7B,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACrD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7B,QAAQ,CA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,CAAC,GAAG,KAAoC;IACxE,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5C,MAAM,KAAK,GAAwB,EAAE,CAAA;IACrC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IAC/C,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACxC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACtC,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { SchemaPropertyMetadata, SchemaPropertyType } from "@etohq/types";
2
+ /**
3
+ * Shared parse/type plumbing for schema properties used by DML, the search
4
+ * DSL, and any future domain language that describes typed fields. Fluent
5
+ * modifiers (`default()`, `nullable()`, ...) belong to the domains that give
6
+ * them meaning — a search field has no default value, so the base must not
7
+ * offer one.
8
+ */
9
+ export declare abstract class BaseSchemaProperty<T> implements SchemaPropertyType<T> {
10
+ /**
11
+ * The runtime dataType for the schema. It is not the same as
12
+ * the "$dataType".
13
+ */
14
+ protected abstract dataType: SchemaPropertyMetadata<T>["dataType"];
15
+ /**
16
+ * A type-only property to infer the JavaScript data-type
17
+ * of the schema property
18
+ */
19
+ $dataType: T;
20
+ /**
21
+ * Returns the serialized metadata
22
+ */
23
+ parse(fieldName: string): SchemaPropertyMetadata<T>;
24
+ }
25
+ //# sourceMappingURL=base-property.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-property.d.ts","sourceRoot":"","sources":["../../src/schema/base-property.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEzE;;;;;;GAMG;AACH,8BAAsB,kBAAkB,CAAC,CAAC,CAAE,YAAW,kBAAkB,CAAC,CAAC,CAAC;IAC1E;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA;IAElE;;;OAGG;IACK,SAAS,EAAE,CAAC,CAAA;IAEpB;;OAEG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,sBAAsB,CAAC,CAAC,CAAC;CAQpD"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseSchemaProperty = void 0;
4
+ /**
5
+ * Shared parse/type plumbing for schema properties used by DML, the search
6
+ * DSL, and any future domain language that describes typed fields. Fluent
7
+ * modifiers (`default()`, `nullable()`, ...) belong to the domains that give
8
+ * them meaning — a search field has no default value, so the base must not
9
+ * offer one.
10
+ */
11
+ class BaseSchemaProperty {
12
+ /**
13
+ * Returns the serialized metadata
14
+ */
15
+ parse(fieldName) {
16
+ return {
17
+ fieldName,
18
+ dataType: this.dataType,
19
+ nullable: false,
20
+ computed: false,
21
+ };
22
+ }
23
+ }
24
+ exports.BaseSchemaProperty = BaseSchemaProperty;
25
+ //# sourceMappingURL=base-property.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-property.js","sourceRoot":"","sources":["../../src/schema/base-property.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACH,MAAsB,kBAAkB;IAatC;;OAEG;IACH,KAAK,CAAC,SAAiB;QACrB,OAAO;YACL,SAAS;YACT,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,KAAK;SAChB,CAAA;IACH,CAAC;CACF;AAxBD,gDAwBC"}
@@ -0,0 +1,2 @@
1
+ export * from "./base-property";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,18 @@
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("./base-property"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B"}
@@ -0,0 +1,345 @@
1
+ import { SearchTypes } from "@etohq/types";
2
+ /**
3
+ * An abstract class for search providers. Extend this class to create a search
4
+ * provider.
5
+ *
6
+ * A search provider translates the Search Module's provider-agnostic input into
7
+ * the calls of a search engine, such as Meilisearch or Typesense: it creates and
8
+ * migrates the physical indexes, writes and deletes documents, and runs queries.
9
+ * The Search Module owns everything around it, including index definitions,
10
+ * batching, task tracking, and reindexing.
11
+ *
12
+ * ### constructor
13
+ *
14
+ * The constructor allows you to access resources from the module's container using the first parameter,
15
+ * and the provider's options using the second parameter.
16
+ *
17
+ * If you're creating a client with a search engine, do it in the constructor.
18
+ * Establishing a connection with the search engine should happen in `onApplicationStart`.
19
+ *
20
+ * #### Example
21
+ *
22
+ * ```ts
23
+ * import { Logger } from "@etohq/framework/types"
24
+ * import { AbstractSearchProviderService } from "@etohq/framework/utils"
25
+ *
26
+ * type InjectedDependencies = {
27
+ * logger: Logger
28
+ * }
29
+ *
30
+ * type Options = {
31
+ * host: string
32
+ * apiKey: string
33
+ * }
34
+ *
35
+ * class MySearchProviderService extends AbstractSearchProviderService {
36
+ * static identifier = "my-search"
37
+ *
38
+ * protected logger_: Logger
39
+ * protected options_: Options
40
+ * // assuming you're initializing a client
41
+ * protected client
42
+ *
43
+ * constructor (
44
+ * { logger }: InjectedDependencies,
45
+ * options: Options
46
+ * ) {
47
+ * super()
48
+ *
49
+ * this.logger_ = logger
50
+ * this.options_ = options
51
+ *
52
+ * // assuming you're initializing a client
53
+ * this.client = new Client(options)
54
+ * }
55
+ * }
56
+ *
57
+ * export default MySearchProviderService
58
+ * ```
59
+ *
60
+ * ### Handling unsupported features
61
+ *
62
+ * There's no list of features to declare. If a query asks for something your engine can't
63
+ * express, throw; if an index definition asks for something it can't hold, throw from
64
+ * `upsertIndex` so the error surfaces at startup. Returning a slightly different result is
65
+ * the one outcome to avoid, since callers can't tell it apart from a correct one.
66
+ *
67
+ * @privateRemarks
68
+ *
69
+ * `waitForTask` is optional and left out of this class on purpose: the Search
70
+ * Module treats its presence as support, so only define it if your engine
71
+ * applies writes asynchronously. `searchMany` has a default that runs `search`
72
+ * concurrently; override it to pack the queries into one engine round-trip.
73
+ * Refer to the `ISearchProvider` interface for their expected parameters and
74
+ * return values.
75
+ */
76
+ export declare class AbstractSearchProviderService implements SearchTypes.ISearchProvider {
77
+ /**
78
+ * Each search provider has a unique identifier used to register it and to bind
79
+ * an index definition to it. An index definition selects a provider by setting
80
+ * its `provider` property to this identifier. You can also use this identifier
81
+ * in `medusa-config.ts` to configure the default provider for the Search Module.
82
+ *
83
+ * @example
84
+ * class MySearchProviderService extends AbstractSearchProviderService {
85
+ * static identifier = "my-search"
86
+ * // ...
87
+ * }
88
+ */
89
+ static identifier: string;
90
+ /**
91
+ * @ignore
92
+ */
93
+ get identifier(): string;
94
+ /**
95
+ * @ignore
96
+ */
97
+ getIdentifier(): string;
98
+ /**
99
+ * This method runs a search against an index. The Search Module will use this method in
100
+ * its `search` and `searchMany` methods.
101
+ *
102
+ * The free-text query arrives as `q`, already lifted out of `filters`, and
103
+ * `attributes_to_retrieve` is already narrowed to the fields the index can return.
104
+ *
105
+ * Compile `input.filters` to your engine's filter syntax, and reject the
106
+ * operators it can't express rather than approximating them. Also, use
107
+ * `input.index.physical_name` as the index to query, not `input.index.name`,
108
+ * since the two differ under an index prefix or between versions.
109
+ *
110
+ * @param {SearchTypes.ProviderSearchQuery} _input - The query, the resolved index
111
+ * definition, and the attributes to return.
112
+ * @returns {Promise<SearchTypes.SearchResult>} The hits, any facets, and the metadata.
113
+ *
114
+ * @example
115
+ * class MySearchProviderService extends AbstractSearchProviderService {
116
+ * // ...
117
+ * async search(
118
+ * input: SearchTypes.ProviderSearchQuery
119
+ * ): Promise<SearchTypes.SearchResult> {
120
+ * const response = await this.client.search(input.index.physical_name, {
121
+ * query: input.q,
122
+ * limit: input.pagination?.take,
123
+ * })
124
+ *
125
+ * return {
126
+ * hits: response.hits.map((hit) => ({ id: hit.id, document: hit })),
127
+ * metadata: {
128
+ * skip: input.pagination?.skip ?? 0,
129
+ * take: input.pagination?.take ?? 20,
130
+ * count: response.total,
131
+ * },
132
+ * }
133
+ * }
134
+ * }
135
+ */
136
+ search(_input: SearchTypes.ProviderSearchQuery): Promise<SearchTypes.SearchResult>;
137
+ /**
138
+ * This method runs multiple queries in a single request to the search engine.
139
+ * The Search Module uses it for its `searchMany` method, including the extra
140
+ * queries produced by disjunctive faceting.
141
+ *
142
+ * The default runs `search` concurrently. Override it to pack the queries into
143
+ * one engine round-trip.
144
+ *
145
+ * @param {SearchTypes.ProviderSearchQuery[]} inputs - The queries to run.
146
+ * @returns {Promise<SearchTypes.SearchResult[]>} A result for each query, in
147
+ * the same order as the queries.
148
+ *
149
+ * @example
150
+ * class MySearchProviderService extends AbstractSearchProviderService {
151
+ * // ...
152
+ * async searchMany(
153
+ * inputs: SearchTypes.ProviderSearchQuery[]
154
+ * ): Promise<SearchTypes.SearchResult[]> {
155
+ * const { results } = await this.client.multiSearch(
156
+ * inputs.map((input) => ({
157
+ * indexUid: input.index.physical_name,
158
+ * query: input.q,
159
+ * }))
160
+ * )
161
+ *
162
+ * return results.map((result, i) => this.buildResult(result, inputs[i]))
163
+ * }
164
+ * }
165
+ */
166
+ searchMany(inputs: SearchTypes.ProviderSearchQuery[]): Promise<SearchTypes.SearchResult[]>;
167
+ /**
168
+ * This method brings an index in line with its definition, creating it if it doesn't
169
+ * exist. The Search Module calls it for every definition when migrations run.
170
+ *
171
+ * You may recreate the index if your engine can't alter a schema in place. That's safe:
172
+ * the module only points this at an index it's about to seed, never at one that has to
173
+ * keep serving reads, and never during a partial rebuild.
174
+ *
175
+ * Throw if the definition asks for something your engine can't hold, such as a
176
+ * facet type it doesn't support. Since migrations run before the application
177
+ * serves requests, the error surfaces at startup rather than as wrong results
178
+ * later.
179
+ *
180
+ * @param {object} _input - The index to create or update.
181
+ * @param {SearchTypes.ResolvedSearchIndexDefinition} _input.index - The definition,
182
+ * including the `physical_name` to create it under, the `primary_key` its
183
+ * documents are keyed by, the `fields` it holds, and its `settings`.
184
+ * @returns {Promise<SearchTypes.SearchTask>} The write's task.
185
+ *
186
+ * @example
187
+ * class MySearchProviderService extends AbstractSearchProviderService {
188
+ * // ...
189
+ * async upsertIndex({
190
+ * index,
191
+ * }: {
192
+ * index: SearchTypes.ResolvedSearchIndexDefinition
193
+ * }): Promise<SearchTypes.SearchTask> {
194
+ * await this.client.createIndex(index.physical_name, {
195
+ * primaryKey: index.primary_key,
196
+ * })
197
+ *
198
+ * return { index: index.physical_name, status: "succeeded" }
199
+ * }
200
+ * }
201
+ */
202
+ upsertIndex(_input: {
203
+ index: SearchTypes.ResolvedSearchIndexDefinition;
204
+ }): Promise<SearchTypes.SearchTask>;
205
+ /**
206
+ * This method deletes an index and everything in it. The Search Module calls it
207
+ * to clean up an old version of an index once a newer one has taken over.
208
+ *
209
+ * @param {object} _input - The index to delete.
210
+ * @param {string} _input.index - The index's physical name.
211
+ * @returns {Promise<SearchTypes.SearchTask>} The write's task.
212
+ *
213
+ * @example
214
+ * class MySearchProviderService extends AbstractSearchProviderService {
215
+ * // ...
216
+ * async deleteIndex({
217
+ * index,
218
+ * }: {
219
+ * index: string
220
+ * }): Promise<SearchTypes.SearchTask> {
221
+ * await this.client.deleteIndex(index)
222
+ * return { index, status: "succeeded" }
223
+ * }
224
+ * }
225
+ */
226
+ deleteIndex(_input: {
227
+ index: string;
228
+ }): Promise<SearchTypes.SearchTask>;
229
+ /**
230
+ * This method lists the indexes you hold. The Search Module reads the document counts to
231
+ * spot an index that lost its data and needs reseeding.
232
+ *
233
+ * @returns {Promise<SearchTypes.SearchIndexInfo[]>} The indexes and their document counts.
234
+ *
235
+ * @example
236
+ * class MySearchProviderService extends AbstractSearchProviderService {
237
+ * // ...
238
+ * async listIndexes(): Promise<SearchTypes.SearchIndexInfo[]> {
239
+ * const indexes = await this.client.listIndexes()
240
+ *
241
+ * return indexes.map((index) => ({
242
+ * name: index.uid,
243
+ * provider: MySearchProviderService.identifier,
244
+ * document_count: index.numberOfDocuments,
245
+ * }))
246
+ * }
247
+ * }
248
+ */
249
+ listIndexes(): Promise<SearchTypes.SearchIndexInfo[]>;
250
+ /**
251
+ * This method adds documents to an index, replacing any that already exist under the same
252
+ * ID. The Search Module uses it both for direct writes and for seeding, where it's called
253
+ * once per batch.
254
+ *
255
+ * If your engine applies writes later rather than inline, return a task with an `id` and
256
+ * implement `waitForTask`, so the module can wait before making a new version active.
257
+ *
258
+ * Write to `input.index` but read schema information from `input.definition`:
259
+ * while a new version is being seeded, `input.index` is that version's
260
+ * physical index, whereas the definition is that of the logical index.
261
+ *
262
+ * @param {object} _input - The documents to write.
263
+ * @param {string} _input.index - The index's physical name. This is the index to
264
+ * write to.
265
+ * @param {SearchTypes.ResolvedSearchIndexDefinition} _input.definition - The
266
+ * definition of the logical index the documents belong to. Use it for schema
267
+ * information, such as the index's `fields` or `primary_key`.
268
+ * @param {SearchTypes.SearchDocument[]} _input.documents - The documents, each with an `id`.
269
+ * @returns {Promise<SearchTypes.SearchTask>} The write's task.
270
+ *
271
+ * @example
272
+ * class MySearchProviderService extends AbstractSearchProviderService {
273
+ * // ...
274
+ * async upsertDocuments({
275
+ * index,
276
+ * definition,
277
+ * documents,
278
+ * }: {
279
+ * index: string
280
+ * definition: SearchTypes.ResolvedSearchIndexDefinition
281
+ * documents: SearchTypes.SearchDocument[]
282
+ * }): Promise<SearchTypes.SearchTask> {
283
+ * const task = await this.client.addDocuments(index, documents, {
284
+ * schema: definition.fields,
285
+ * })
286
+ * return { id: `${task.uid}`, index, status: "enqueued" }
287
+ * }
288
+ * }
289
+ */
290
+ upsertDocuments(_input: {
291
+ index: string;
292
+ definition: SearchTypes.ResolvedSearchIndexDefinition;
293
+ documents: SearchTypes.SearchDocument[];
294
+ }): Promise<SearchTypes.SearchTask>;
295
+ /**
296
+ * This method removes every document matching the given filters.
297
+ *
298
+ * Deleting by ID isn't a special case — it arrives as a filter on the primary key, such
299
+ * as `{ id: ["prod_1", "prod_2"] }`. Recognize that shape and use your engine's
300
+ * delete-by-ID path, which is usually much faster. If your engine can't delete by
301
+ * arbitrary filters, either search first and delete the matching IDs, or throw.
302
+ *
303
+ * @param {SearchTypes.SearchDeleteDocumentsInput} _input - The index and the filters
304
+ * selecting the documents to remove.
305
+ * @returns {Promise<SearchTypes.SearchTask>} The write's task.
306
+ *
307
+ * @example
308
+ * class MySearchProviderService extends AbstractSearchProviderService {
309
+ * // ...
310
+ * async deleteDocuments({
311
+ * index,
312
+ * filters,
313
+ * }: SearchTypes.SearchDeleteDocumentsInput): Promise<SearchTypes.SearchTask> {
314
+ * await this.client.deleteDocumentsByFilter(index, filters)
315
+ * return { index, status: "succeeded" }
316
+ * }
317
+ * }
318
+ */
319
+ deleteDocuments(_input: SearchTypes.SearchDeleteDocumentsInput): Promise<SearchTypes.SearchTask>;
320
+ /**
321
+ * This method removes every document from an index without deleting the index itself.
322
+ * The Search Module uses it to empty an index before reseeding it in place.
323
+ *
324
+ * @param {object} _input - The index to empty.
325
+ * @param {string} _input.index - The index's physical name.
326
+ * @returns {Promise<SearchTypes.SearchTask>} The write's task.
327
+ *
328
+ * @example
329
+ * class MySearchProviderService extends AbstractSearchProviderService {
330
+ * // ...
331
+ * async clearIndex({
332
+ * index,
333
+ * }: {
334
+ * index: string
335
+ * }): Promise<SearchTypes.SearchTask> {
336
+ * await this.client.deleteAllDocuments(index)
337
+ * return { index, status: "succeeded" }
338
+ * }
339
+ * }
340
+ */
341
+ clearIndex(_input: {
342
+ index: string;
343
+ }): Promise<SearchTypes.SearchTask>;
344
+ }
345
+ //# sourceMappingURL=abstract-search-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-search-provider.d.ts","sourceRoot":"","sources":["../../src/search/abstract-search-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,qBAAa,6BACX,YAAW,WAAW,CAAC,eAAe;IAEtC;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,CAAA;IAEzB;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACG,MAAM,CACV,MAAM,EAAE,WAAW,CAAC,mBAAmB,GACtC,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC;IAIpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,UAAU,CACd,MAAM,EAAE,WAAW,CAAC,mBAAmB,EAAE,GACxC,OAAO,CAAC,WAAW,CAAC,YAAY,E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