@medusajs/utils 2.18.0 → 2.19.0-preview-20260811102316
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/create-psql-index-helper.d.ts +1 -1
- package/dist/common/create-psql-index-helper.d.ts.map +1 -1
- package/dist/common/define-config.d.ts.map +1 -1
- package/dist/common/define-config.js +5 -2
- package/dist/common/define-config.js.map +1 -1
- package/dist/core-flows/events.d.ts +20 -15
- package/dist/core-flows/events.d.ts.map +1 -1
- package/dist/core-flows/events.js +20 -15
- package/dist/core-flows/events.js.map +1 -1
- package/dist/dml/entity-builder.d.ts +11 -2
- package/dist/dml/entity-builder.d.ts.map +1 -1
- package/dist/dml/entity-builder.js +10 -1
- package/dist/dml/entity-builder.js.map +1 -1
- package/dist/dml/helpers/entity-builder/build-indexes.d.ts +1 -1
- package/dist/dml/helpers/entity-builder/build-indexes.d.ts.map +1 -1
- package/dist/dml/helpers/entity-builder/build-indexes.js +8 -0
- package/dist/dml/helpers/entity-builder/build-indexes.js.map +1 -1
- package/dist/dml/properties/json.d.ts +5 -2
- package/dist/dml/properties/json.d.ts.map +1 -1
- package/dist/dml/properties/json.js +4 -1
- package/dist/dml/properties/json.js.map +1 -1
- package/dist/fulfillment/provider.d.ts +6 -2
- package/dist/fulfillment/provider.d.ts.map +1 -1
- package/dist/fulfillment/provider.js +6 -2
- package/dist/fulfillment/provider.js.map +1 -1
- package/dist/modules-sdk/definition.d.ts +3 -0
- package/dist/modules-sdk/definition.d.ts.map +1 -1
- package/dist/modules-sdk/definition.js +2 -0
- package/dist/modules-sdk/definition.js.map +1 -1
- package/dist/search/abstract-search-provider.d.ts +278 -0
- package/dist/search/abstract-search-provider.d.ts.map +1 -0
- package/dist/search/abstract-search-provider.js +282 -0
- package/dist/search/abstract-search-provider.js.map +1 -0
- package/dist/search/define-search-index.d.ts +9 -0
- package/dist/search/define-search-index.d.ts.map +1 -0
- package/dist/search/define-search-index.js +19 -0
- package/dist/search/define-search-index.js.map +1 -0
- package/dist/search/index.d.ts +2 -4
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +2 -4
- package/dist/search/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/search/abstract-service.d.ts +0 -345
- package/dist/search/abstract-service.d.ts.map +0 -1
- package/dist/search/abstract-service.js +0 -139
- package/dist/search/abstract-service.js.map +0 -1
- package/dist/search/index-types.d.ts +0 -4
- package/dist/search/index-types.d.ts.map +0 -1
- package/dist/search/index-types.js +0 -7
- package/dist/search/index-types.js.map +0 -1
- package/dist/search/search-relations.d.ts +0 -2
- package/dist/search/search-relations.d.ts.map +0 -1
- package/dist/search/search-relations.js +0 -14
- package/dist/search/search-relations.js.map +0 -1
- package/dist/search/variant-keys.d.ts +0 -2
- package/dist/search/variant-keys.d.ts.map +0 -1
- package/dist/search/variant-keys.js +0 -13
- package/dist/search/variant-keys.js.map +0 -1
|
@@ -250,6 +250,9 @@ class AbstractFulfillmentProviderService {
|
|
|
250
250
|
* @param items - The items in the fulfillment.
|
|
251
251
|
* @param order - The order this fulfillment is created for.
|
|
252
252
|
* @param fulfillment - The fulfillment's details.
|
|
253
|
+
* @param additionalData - Custom key-value pairs forwarded from the workflow that
|
|
254
|
+
* created the fulfillment (for example, the `additional_data` of the Create Order
|
|
255
|
+
* Fulfillment API route). It isn't persisted on the fulfillment.
|
|
253
256
|
* @returns An object whose `data` property is stored in the fulfillment's `data` property.
|
|
254
257
|
*
|
|
255
258
|
* @example
|
|
@@ -259,7 +262,8 @@ class AbstractFulfillmentProviderService {
|
|
|
259
262
|
* data: Record<string, unknown>,
|
|
260
263
|
* items: Partial<Omit<FulfillmentItemDTO, "fulfillment">>[],
|
|
261
264
|
* order: Partial<FulfillmentOrderDTO> | undefined,
|
|
262
|
-
* fulfillment: Partial<Omit<FulfillmentDTO, "provider_id" | "data" | "items"
|
|
265
|
+
* fulfillment: Partial<Omit<FulfillmentDTO, "provider_id" | "data" | "items">>,
|
|
266
|
+
* additionalData?: Record<string, unknown>
|
|
263
267
|
* ): Promise<CreateFulfillmentResult> {
|
|
264
268
|
* // assuming the client creates a fulfillment
|
|
265
269
|
* // in the third-party service
|
|
@@ -277,7 +281,7 @@ class AbstractFulfillmentProviderService {
|
|
|
277
281
|
* }
|
|
278
282
|
* }
|
|
279
283
|
*/
|
|
280
|
-
async createFulfillment(data, items, order, fulfillment) {
|
|
284
|
+
async createFulfillment(data, items, order, fulfillment, additionalData) {
|
|
281
285
|
throw Error("createFulfillment must be overridden by the child class");
|
|
282
286
|
}
|
|
283
287
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/fulfillment/provider.ts"],"names":[],"mappings":";;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAa,kCAAkC;IAsB7C;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,GAAG;QAC7B,OAAO,GAAG,EAAE,WAAW,EAAE,qBAAqB,CAAA;IAChD,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAQ,IAAI,CAAC,WAAmB,CAAC,UAAU,CAAA;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,KAAK,CAAC,qBAAqB;QACzB,MAAM,KAAK,CAAC,6DAA6D,CAAC,CAAA;IAC5E,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,KAAK,CAAC,uBAAuB,CAC3B,UAAmC,EACnC,IAA6B,EAC7B,OAAuC;QAEvC,MAAM,KAAK,CAAC,+DAA+D,CAAC,CAAA;IAC9E,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,cAAc,CAAC,IAA6B;QAChD,MAAM,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACrE,CAAC;IAED;;;;;;;;;;;;;;;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@ export declare const Modules: {
|
|
|
25
25
|
readonly FILE: "file";
|
|
26
26
|
readonly NOTIFICATION: "notification";
|
|
27
27
|
readonly INDEX: "index";
|
|
28
|
+
readonly SEARCH: "search";
|
|
28
29
|
readonly LOCKING: "locking";
|
|
29
30
|
readonly SETTINGS: "settings";
|
|
30
31
|
readonly CACHING: "caching";
|
|
@@ -58,6 +59,7 @@ export declare const MODULE_PACKAGE_NAMES: {
|
|
|
58
59
|
file: string;
|
|
59
60
|
notification: string;
|
|
60
61
|
index: string;
|
|
62
|
+
search: string;
|
|
61
63
|
locking: string;
|
|
62
64
|
settings: string;
|
|
63
65
|
caching: string;
|
|
@@ -102,6 +104,7 @@ export declare const ModuleRegistrationName: {
|
|
|
102
104
|
readonly FILE: "file";
|
|
103
105
|
readonly NOTIFICATION: "notification";
|
|
104
106
|
readonly INDEX: "index";
|
|
107
|
+
readonly SEARCH: "search";
|
|
105
108
|
readonly LOCKING: "locking";
|
|
106
109
|
readonly SETTINGS: "settings";
|
|
107
110
|
readonly CACHING: "caching";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/modules-sdk/definition.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/modules-sdk/definition.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCV,CAAA;AAEV,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiChC,CAAA;AAED,eAAO,MAAM,6BAA6B,IAKpC,CAAA;AAGN,eAAO,MAAM,oCAAoC;;;;;CAKhD,CAAA;AAeD;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAA;AAC5D,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAU,CAAA"}
|
|
@@ -28,6 +28,7 @@ exports.Modules = {
|
|
|
28
28
|
FILE: "file",
|
|
29
29
|
NOTIFICATION: "notification",
|
|
30
30
|
INDEX: "index",
|
|
31
|
+
SEARCH: "search",
|
|
31
32
|
LOCKING: "locking",
|
|
32
33
|
SETTINGS: "settings",
|
|
33
34
|
CACHING: "caching",
|
|
@@ -61,6 +62,7 @@ exports.MODULE_PACKAGE_NAMES = {
|
|
|
61
62
|
[exports.Modules.FILE]: "@medusajs/medusa/file",
|
|
62
63
|
[exports.Modules.NOTIFICATION]: "@medusajs/medusa/notification",
|
|
63
64
|
[exports.Modules.INDEX]: "@medusajs/medusa/index-module",
|
|
65
|
+
[exports.Modules.SEARCH]: "@medusajs/medusa/search",
|
|
64
66
|
[exports.Modules.LOCKING]: "@medusajs/medusa/locking",
|
|
65
67
|
[exports.Modules.SETTINGS]: "@medusajs/medusa/settings",
|
|
66
68
|
[exports.Modules.CACHING]: "@medusajs/medusa/caching",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../../src/modules-sdk/definition.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG;IACrB,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,aAAa,EAAE,eAAe;IAC9B,GAAG,EAAE,KAAK;IACV,WAAW,EAAE,aAAa;IAC1B,cAAc,EAAE,gBAAgB;IAChC,IAAI,EAAE,MAAM;IACZ,eAAe,EAAE,WAAW;IAC5B,MAAM,EAAE,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CAC3B,4CAAoC,CAAC,eAAO,CAAC,eAAe,CAAC,CAC9D,GAAG,eAAO,CAAC,eAAe,CAAA;AAC3B,qCAA6B,CAC3B,4CAAoC,CAAC,eAAO,CAAC,OAAO,CAAC,CACtD,GAAG,eAAO,CAAC,OAAO,CAAA;AAMN,QAAA,sBAAsB,GAAG,eAAO,CAAA"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { SearchTypes } from "@medusajs/types";
|
|
2
|
+
/**
|
|
3
|
+
* An abstract class for search providers. Extend this class to create a search
|
|
4
|
+
* provider.
|
|
5
|
+
*
|
|
6
|
+
* ### constructor
|
|
7
|
+
*
|
|
8
|
+
* The constructor allows you to access resources from the module's container using the first parameter,
|
|
9
|
+
* and the provider's options using the second parameter.
|
|
10
|
+
*
|
|
11
|
+
* If you're creating a client with a search engine, do it in the constructor.
|
|
12
|
+
* Establishing a connection with the search engine should happen in `onApplicationStart`.
|
|
13
|
+
*
|
|
14
|
+
* #### Example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { Logger } from "@medusajs/framework/types"
|
|
18
|
+
* import { AbstractSearchProviderService } from "@medusajs/framework/utils"
|
|
19
|
+
*
|
|
20
|
+
* type InjectedDependencies = {
|
|
21
|
+
* logger: Logger
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* type Options = {
|
|
25
|
+
* host: string
|
|
26
|
+
* apiKey: string
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
30
|
+
* static identifier = "my-search"
|
|
31
|
+
*
|
|
32
|
+
* protected logger_: Logger
|
|
33
|
+
* protected options_: Options
|
|
34
|
+
* // assuming you're initializing a client
|
|
35
|
+
* protected client
|
|
36
|
+
*
|
|
37
|
+
* constructor (
|
|
38
|
+
* { logger }: InjectedDependencies,
|
|
39
|
+
* options: Options
|
|
40
|
+
* ) {
|
|
41
|
+
* super()
|
|
42
|
+
*
|
|
43
|
+
* this.logger_ = logger
|
|
44
|
+
* this.options_ = options
|
|
45
|
+
*
|
|
46
|
+
* // assuming you're initializing a client
|
|
47
|
+
* this.client = new Client(options)
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* export default MySearchProviderService
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* ---
|
|
55
|
+
*
|
|
56
|
+
* ## Notes About Class Methods
|
|
57
|
+
*
|
|
58
|
+
* There's no list of features to declare. If a query asks for something your engine can't
|
|
59
|
+
* express, throw; if an index definition asks for something it can't hold, throw from
|
|
60
|
+
* `upsertIndex` so the error surfaces at startup. Returning a slightly different result is
|
|
61
|
+
* the one outcome to avoid, since callers can't tell it apart from a correct one.
|
|
62
|
+
*
|
|
63
|
+
* `swapIndex`, `searchMany` and `waitForTask` are optional and
|
|
64
|
+
* left out of this class on purpose: the Search Module treats their presence as support,
|
|
65
|
+
* so only define the ones your engine can back. Implementing `swapIndex`, for example,
|
|
66
|
+
* lets the module reindex without downtime instead of rebuilding in place.
|
|
67
|
+
*
|
|
68
|
+
* ---
|
|
69
|
+
*/
|
|
70
|
+
export declare class AbstractSearchProviderService implements SearchTypes.ISearchProvider {
|
|
71
|
+
/**
|
|
72
|
+
* @example
|
|
73
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
74
|
+
* static identifier = "my-search"
|
|
75
|
+
* // ...
|
|
76
|
+
* }
|
|
77
|
+
*/
|
|
78
|
+
static identifier: string;
|
|
79
|
+
/**
|
|
80
|
+
* @ignore
|
|
81
|
+
*/
|
|
82
|
+
get identifier(): string;
|
|
83
|
+
/**
|
|
84
|
+
* @ignore
|
|
85
|
+
*/
|
|
86
|
+
getIdentifier(): string;
|
|
87
|
+
/**
|
|
88
|
+
* This method runs a search against an index. The Search Module will use this method in
|
|
89
|
+
* its `search` and `searchMany` methods.
|
|
90
|
+
*
|
|
91
|
+
* The free-text query arrives as `q`, already lifted out of `filters`, and
|
|
92
|
+
* `attributes_to_retrieve` is already narrowed to the fields the index can return.
|
|
93
|
+
*
|
|
94
|
+
* @param {SearchTypes.ProviderSearchQuery} input - The query, the resolved index
|
|
95
|
+
* definition, and the attributes to return.
|
|
96
|
+
* @returns {Promise<SearchTypes.SearchResult>} The hits, any facets, and the metadata.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
100
|
+
* // ...
|
|
101
|
+
* async search(
|
|
102
|
+
* input: SearchTypes.ProviderSearchQuery
|
|
103
|
+
* ): Promise<SearchTypes.SearchResult> {
|
|
104
|
+
* const response = await this.client.search(input.index.physical_name, {
|
|
105
|
+
* query: input.q,
|
|
106
|
+
* limit: input.pagination?.take,
|
|
107
|
+
* })
|
|
108
|
+
*
|
|
109
|
+
* return {
|
|
110
|
+
* hits: response.hits.map((hit) => ({ id: hit.id, document: hit })),
|
|
111
|
+
* metadata: {
|
|
112
|
+
* skip: input.pagination?.skip ?? 0,
|
|
113
|
+
* take: input.pagination?.take ?? 20,
|
|
114
|
+
* count: response.total,
|
|
115
|
+
* },
|
|
116
|
+
* }
|
|
117
|
+
* }
|
|
118
|
+
* }
|
|
119
|
+
*/
|
|
120
|
+
search(_input: SearchTypes.ProviderSearchQuery): Promise<SearchTypes.SearchResult>;
|
|
121
|
+
/**
|
|
122
|
+
* This method brings an index in line with its definition, creating it if it doesn't
|
|
123
|
+
* exist. The Search Module calls it for every definition when migrations run.
|
|
124
|
+
*
|
|
125
|
+
* You may recreate the index if your engine can't alter a schema in place. That's safe:
|
|
126
|
+
* the module only points this at an index it's about to seed, never at one that has to
|
|
127
|
+
* keep serving reads, and never during a partial rebuild.
|
|
128
|
+
*
|
|
129
|
+
* @param {object} input - The index to create or update.
|
|
130
|
+
* @param {SearchTypes.ResolvedSearchIndexDefinition} input.index - The definition,
|
|
131
|
+
* including the `physical_name` to create it under.
|
|
132
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
136
|
+
* // ...
|
|
137
|
+
* async upsertIndex({
|
|
138
|
+
* index,
|
|
139
|
+
* }: {
|
|
140
|
+
* index: SearchTypes.ResolvedSearchIndexDefinition
|
|
141
|
+
* }): Promise<SearchTypes.SearchTask> {
|
|
142
|
+
* await this.client.createIndex(index.physical_name, {
|
|
143
|
+
* primaryKey: index.primary_key,
|
|
144
|
+
* })
|
|
145
|
+
*
|
|
146
|
+
* return { index: index.physical_name, status: "succeeded" }
|
|
147
|
+
* }
|
|
148
|
+
* }
|
|
149
|
+
*/
|
|
150
|
+
upsertIndex(_input: {
|
|
151
|
+
index: SearchTypes.ResolvedSearchIndexDefinition;
|
|
152
|
+
}): Promise<SearchTypes.SearchTask>;
|
|
153
|
+
/**
|
|
154
|
+
* This method deletes an index and everything in it.
|
|
155
|
+
*
|
|
156
|
+
* @param {object} input - The index to delete.
|
|
157
|
+
* @param {string} input.index - The index's physical name.
|
|
158
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
162
|
+
* // ...
|
|
163
|
+
* async deleteIndex({
|
|
164
|
+
* index,
|
|
165
|
+
* }: {
|
|
166
|
+
* index: string
|
|
167
|
+
* }): Promise<SearchTypes.SearchTask> {
|
|
168
|
+
* await this.client.deleteIndex(index)
|
|
169
|
+
* return { index, status: "succeeded" }
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
*/
|
|
173
|
+
deleteIndex(_input: {
|
|
174
|
+
index: string;
|
|
175
|
+
}): Promise<SearchTypes.SearchTask>;
|
|
176
|
+
/**
|
|
177
|
+
* This method lists the indexes you hold. The Search Module reads the document counts to
|
|
178
|
+
* spot an index that lost its data and needs reseeding.
|
|
179
|
+
*
|
|
180
|
+
* @returns {Promise<SearchTypes.SearchIndexInfo[]>} The indexes and their document counts.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
184
|
+
* // ...
|
|
185
|
+
* async listIndexes(): Promise<SearchTypes.SearchIndexInfo[]> {
|
|
186
|
+
* const indexes = await this.client.listIndexes()
|
|
187
|
+
*
|
|
188
|
+
* return indexes.map((index) => ({
|
|
189
|
+
* name: index.uid,
|
|
190
|
+
* provider: MySearchProviderService.identifier,
|
|
191
|
+
* document_count: index.numberOfDocuments,
|
|
192
|
+
* }))
|
|
193
|
+
* }
|
|
194
|
+
* }
|
|
195
|
+
*/
|
|
196
|
+
listIndexes(): Promise<SearchTypes.SearchIndexInfo[]>;
|
|
197
|
+
/**
|
|
198
|
+
* This method adds documents to an index, replacing any that already exist under the same
|
|
199
|
+
* ID. The Search Module uses it both for direct writes and for seeding, where it's called
|
|
200
|
+
* once per batch.
|
|
201
|
+
*
|
|
202
|
+
* If your engine applies writes later rather than inline, return a task with an `id` and
|
|
203
|
+
* implement `waitForTask`, so the module can wait before swapping a new index in.
|
|
204
|
+
*
|
|
205
|
+
* @param {object} input - The documents to write.
|
|
206
|
+
* @param {string} input.index - The index's physical name.
|
|
207
|
+
* @param {SearchTypes.SearchDocument[]} input.documents - The documents, each with an `id`.
|
|
208
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
212
|
+
* // ...
|
|
213
|
+
* async upsertDocuments({
|
|
214
|
+
* index,
|
|
215
|
+
* documents,
|
|
216
|
+
* }: {
|
|
217
|
+
* index: string
|
|
218
|
+
* documents: SearchTypes.SearchDocument[]
|
|
219
|
+
* }): Promise<SearchTypes.SearchTask> {
|
|
220
|
+
* const task = await this.client.addDocuments(index, documents)
|
|
221
|
+
* return { id: `${task.uid}`, index, status: "enqueued" }
|
|
222
|
+
* }
|
|
223
|
+
* }
|
|
224
|
+
*/
|
|
225
|
+
upsertDocuments(_input: {
|
|
226
|
+
index: string;
|
|
227
|
+
documents: SearchTypes.SearchDocument[];
|
|
228
|
+
}): Promise<SearchTypes.SearchTask>;
|
|
229
|
+
/**
|
|
230
|
+
* This method removes every document matching the given filters.
|
|
231
|
+
*
|
|
232
|
+
* Deleting by ID isn't a special case — it arrives as a filter on the primary key, such
|
|
233
|
+
* as `{ id: ["prod_1", "prod_2"] }`. Recognize that shape and use your engine's
|
|
234
|
+
* delete-by-ID path, which is usually much faster. If your engine can't delete by
|
|
235
|
+
* arbitrary filters, either search first and delete the matching IDs, or throw.
|
|
236
|
+
*
|
|
237
|
+
* @param {SearchTypes.SearchDeleteDocumentsInput} input - The index and the filters
|
|
238
|
+
* selecting the documents to remove.
|
|
239
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
243
|
+
* // ...
|
|
244
|
+
* async deleteDocuments({
|
|
245
|
+
* index,
|
|
246
|
+
* filters,
|
|
247
|
+
* }: SearchTypes.SearchDeleteDocumentsInput): Promise<SearchTypes.SearchTask> {
|
|
248
|
+
* await this.client.deleteDocumentsByFilter(index, filters)
|
|
249
|
+
* return { index, status: "succeeded" }
|
|
250
|
+
* }
|
|
251
|
+
* }
|
|
252
|
+
*/
|
|
253
|
+
deleteDocuments(_input: SearchTypes.SearchDeleteDocumentsInput): Promise<SearchTypes.SearchTask>;
|
|
254
|
+
/**
|
|
255
|
+
* This method removes every document from an index without deleting the index itself.
|
|
256
|
+
*
|
|
257
|
+
* @param {object} input - The index to empty.
|
|
258
|
+
* @param {string} input.index - The index's physical name.
|
|
259
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
263
|
+
* // ...
|
|
264
|
+
* async clearIndex({
|
|
265
|
+
* index,
|
|
266
|
+
* }: {
|
|
267
|
+
* index: string
|
|
268
|
+
* }): Promise<SearchTypes.SearchTask> {
|
|
269
|
+
* await this.client.deleteAllDocuments(index)
|
|
270
|
+
* return { index, status: "succeeded" }
|
|
271
|
+
* }
|
|
272
|
+
* }
|
|
273
|
+
*/
|
|
274
|
+
clearIndex(_input: {
|
|
275
|
+
index: string;
|
|
276
|
+
}): Promise<SearchTypes.SearchTask>;
|
|
277
|
+
}
|
|
278
|
+
//# 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,iBAAiB,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,qBAAa,6BACX,YAAW,WAAW,CAAC,eAAe;IAEtC;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,CAAA;IAEzB;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACG,MAAM,CACV,MAAM,EAAE,WAAW,CAAC,mBAAmB,GACtC,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC;IAIpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,WAAW,CAAC,MAAM,EAAE;QACxB,KAAK,EAAE,WAAW,CAAC,6BAA6B,CAAA;KACjD,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;IAInC;;;;;;;;;;;;;;;;;;;OAmBG;IACG,WAAW,CAAC,MAAM,EAAE;QACxB,KAAK,EAAE,MAAM,CAAA;KACd,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;IAInC;;;;;;;;;;;;;;;;;;;OAmBG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC;IAI3D;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,eAAe,CAAC,MAAM,EAAE;QAC5B,KAAK,EAAE,MAAM,CAAA;QACb,SAAS,EAAE,WAAW,CAAC,cAAc,EAAE,CAAA;KACxC,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;IAInC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,eAAe,CACnB,MAAM,EAAE,WAAW,CAAC,0BAA0B,GAC7C,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;IAIlC;;;;;;;;;;;;;;;;;;;OAmBG;IACG,UAAU,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;CAG7E"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractSearchProviderService = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* An abstract class for search providers. Extend this class to create a search
|
|
6
|
+
* provider.
|
|
7
|
+
*
|
|
8
|
+
* ### constructor
|
|
9
|
+
*
|
|
10
|
+
* The constructor allows you to access resources from the module's container using the first parameter,
|
|
11
|
+
* and the provider's options using the second parameter.
|
|
12
|
+
*
|
|
13
|
+
* If you're creating a client with a search engine, do it in the constructor.
|
|
14
|
+
* Establishing a connection with the search engine should happen in `onApplicationStart`.
|
|
15
|
+
*
|
|
16
|
+
* #### Example
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { Logger } from "@medusajs/framework/types"
|
|
20
|
+
* import { AbstractSearchProviderService } from "@medusajs/framework/utils"
|
|
21
|
+
*
|
|
22
|
+
* type InjectedDependencies = {
|
|
23
|
+
* logger: Logger
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* type Options = {
|
|
27
|
+
* host: string
|
|
28
|
+
* apiKey: string
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
32
|
+
* static identifier = "my-search"
|
|
33
|
+
*
|
|
34
|
+
* protected logger_: Logger
|
|
35
|
+
* protected options_: Options
|
|
36
|
+
* // assuming you're initializing a client
|
|
37
|
+
* protected client
|
|
38
|
+
*
|
|
39
|
+
* constructor (
|
|
40
|
+
* { logger }: InjectedDependencies,
|
|
41
|
+
* options: Options
|
|
42
|
+
* ) {
|
|
43
|
+
* super()
|
|
44
|
+
*
|
|
45
|
+
* this.logger_ = logger
|
|
46
|
+
* this.options_ = options
|
|
47
|
+
*
|
|
48
|
+
* // assuming you're initializing a client
|
|
49
|
+
* this.client = new Client(options)
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* export default MySearchProviderService
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* ---
|
|
57
|
+
*
|
|
58
|
+
* ## Notes About Class Methods
|
|
59
|
+
*
|
|
60
|
+
* There's no list of features to declare. If a query asks for something your engine can't
|
|
61
|
+
* express, throw; if an index definition asks for something it can't hold, throw from
|
|
62
|
+
* `upsertIndex` so the error surfaces at startup. Returning a slightly different result is
|
|
63
|
+
* the one outcome to avoid, since callers can't tell it apart from a correct one.
|
|
64
|
+
*
|
|
65
|
+
* `swapIndex`, `searchMany` and `waitForTask` are optional and
|
|
66
|
+
* left out of this class on purpose: the Search Module treats their presence as support,
|
|
67
|
+
* so only define the ones your engine can back. Implementing `swapIndex`, for example,
|
|
68
|
+
* lets the module reindex without downtime instead of rebuilding in place.
|
|
69
|
+
*
|
|
70
|
+
* ---
|
|
71
|
+
*/
|
|
72
|
+
class AbstractSearchProviderService {
|
|
73
|
+
/**
|
|
74
|
+
* @ignore
|
|
75
|
+
*/
|
|
76
|
+
get identifier() {
|
|
77
|
+
return this.constructor.identifier;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @ignore
|
|
81
|
+
*/
|
|
82
|
+
getIdentifier() {
|
|
83
|
+
return this.constructor.identifier;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* This method runs a search against an index. The Search Module will use this method in
|
|
87
|
+
* its `search` and `searchMany` methods.
|
|
88
|
+
*
|
|
89
|
+
* The free-text query arrives as `q`, already lifted out of `filters`, and
|
|
90
|
+
* `attributes_to_retrieve` is already narrowed to the fields the index can return.
|
|
91
|
+
*
|
|
92
|
+
* @param {SearchTypes.ProviderSearchQuery} input - The query, the resolved index
|
|
93
|
+
* definition, and the attributes to return.
|
|
94
|
+
* @returns {Promise<SearchTypes.SearchResult>} The hits, any facets, and the metadata.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
98
|
+
* // ...
|
|
99
|
+
* async search(
|
|
100
|
+
* input: SearchTypes.ProviderSearchQuery
|
|
101
|
+
* ): Promise<SearchTypes.SearchResult> {
|
|
102
|
+
* const response = await this.client.search(input.index.physical_name, {
|
|
103
|
+
* query: input.q,
|
|
104
|
+
* limit: input.pagination?.take,
|
|
105
|
+
* })
|
|
106
|
+
*
|
|
107
|
+
* return {
|
|
108
|
+
* hits: response.hits.map((hit) => ({ id: hit.id, document: hit })),
|
|
109
|
+
* metadata: {
|
|
110
|
+
* skip: input.pagination?.skip ?? 0,
|
|
111
|
+
* take: input.pagination?.take ?? 20,
|
|
112
|
+
* count: response.total,
|
|
113
|
+
* },
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
*/
|
|
118
|
+
async search(_input) {
|
|
119
|
+
throw Error("search must be overridden by the child class");
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* This method brings an index in line with its definition, creating it if it doesn't
|
|
123
|
+
* exist. The Search Module calls it for every definition when migrations run.
|
|
124
|
+
*
|
|
125
|
+
* You may recreate the index if your engine can't alter a schema in place. That's safe:
|
|
126
|
+
* the module only points this at an index it's about to seed, never at one that has to
|
|
127
|
+
* keep serving reads, and never during a partial rebuild.
|
|
128
|
+
*
|
|
129
|
+
* @param {object} input - The index to create or update.
|
|
130
|
+
* @param {SearchTypes.ResolvedSearchIndexDefinition} input.index - The definition,
|
|
131
|
+
* including the `physical_name` to create it under.
|
|
132
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
136
|
+
* // ...
|
|
137
|
+
* async upsertIndex({
|
|
138
|
+
* index,
|
|
139
|
+
* }: {
|
|
140
|
+
* index: SearchTypes.ResolvedSearchIndexDefinition
|
|
141
|
+
* }): Promise<SearchTypes.SearchTask> {
|
|
142
|
+
* await this.client.createIndex(index.physical_name, {
|
|
143
|
+
* primaryKey: index.primary_key,
|
|
144
|
+
* })
|
|
145
|
+
*
|
|
146
|
+
* return { index: index.physical_name, status: "succeeded" }
|
|
147
|
+
* }
|
|
148
|
+
* }
|
|
149
|
+
*/
|
|
150
|
+
async upsertIndex(_input) {
|
|
151
|
+
throw Error("upsertIndex must be overridden by the child class");
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* This method deletes an index and everything in it.
|
|
155
|
+
*
|
|
156
|
+
* @param {object} input - The index to delete.
|
|
157
|
+
* @param {string} input.index - The index's physical name.
|
|
158
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
162
|
+
* // ...
|
|
163
|
+
* async deleteIndex({
|
|
164
|
+
* index,
|
|
165
|
+
* }: {
|
|
166
|
+
* index: string
|
|
167
|
+
* }): Promise<SearchTypes.SearchTask> {
|
|
168
|
+
* await this.client.deleteIndex(index)
|
|
169
|
+
* return { index, status: "succeeded" }
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
*/
|
|
173
|
+
async deleteIndex(_input) {
|
|
174
|
+
throw Error("deleteIndex must be overridden by the child class");
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* This method lists the indexes you hold. The Search Module reads the document counts to
|
|
178
|
+
* spot an index that lost its data and needs reseeding.
|
|
179
|
+
*
|
|
180
|
+
* @returns {Promise<SearchTypes.SearchIndexInfo[]>} The indexes and their document counts.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
184
|
+
* // ...
|
|
185
|
+
* async listIndexes(): Promise<SearchTypes.SearchIndexInfo[]> {
|
|
186
|
+
* const indexes = await this.client.listIndexes()
|
|
187
|
+
*
|
|
188
|
+
* return indexes.map((index) => ({
|
|
189
|
+
* name: index.uid,
|
|
190
|
+
* provider: MySearchProviderService.identifier,
|
|
191
|
+
* document_count: index.numberOfDocuments,
|
|
192
|
+
* }))
|
|
193
|
+
* }
|
|
194
|
+
* }
|
|
195
|
+
*/
|
|
196
|
+
async listIndexes() {
|
|
197
|
+
throw Error("listIndexes must be overridden by the child class");
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* This method adds documents to an index, replacing any that already exist under the same
|
|
201
|
+
* ID. The Search Module uses it both for direct writes and for seeding, where it's called
|
|
202
|
+
* once per batch.
|
|
203
|
+
*
|
|
204
|
+
* If your engine applies writes later rather than inline, return a task with an `id` and
|
|
205
|
+
* implement `waitForTask`, so the module can wait before swapping a new index in.
|
|
206
|
+
*
|
|
207
|
+
* @param {object} input - The documents to write.
|
|
208
|
+
* @param {string} input.index - The index's physical name.
|
|
209
|
+
* @param {SearchTypes.SearchDocument[]} input.documents - The documents, each with an `id`.
|
|
210
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
214
|
+
* // ...
|
|
215
|
+
* async upsertDocuments({
|
|
216
|
+
* index,
|
|
217
|
+
* documents,
|
|
218
|
+
* }: {
|
|
219
|
+
* index: string
|
|
220
|
+
* documents: SearchTypes.SearchDocument[]
|
|
221
|
+
* }): Promise<SearchTypes.SearchTask> {
|
|
222
|
+
* const task = await this.client.addDocuments(index, documents)
|
|
223
|
+
* return { id: `${task.uid}`, index, status: "enqueued" }
|
|
224
|
+
* }
|
|
225
|
+
* }
|
|
226
|
+
*/
|
|
227
|
+
async upsertDocuments(_input) {
|
|
228
|
+
throw Error("upsertDocuments must be overridden by the child class");
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* This method removes every document matching the given filters.
|
|
232
|
+
*
|
|
233
|
+
* Deleting by ID isn't a special case — it arrives as a filter on the primary key, such
|
|
234
|
+
* as `{ id: ["prod_1", "prod_2"] }`. Recognize that shape and use your engine's
|
|
235
|
+
* delete-by-ID path, which is usually much faster. If your engine can't delete by
|
|
236
|
+
* arbitrary filters, either search first and delete the matching IDs, or throw.
|
|
237
|
+
*
|
|
238
|
+
* @param {SearchTypes.SearchDeleteDocumentsInput} input - The index and the filters
|
|
239
|
+
* selecting the documents to remove.
|
|
240
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
244
|
+
* // ...
|
|
245
|
+
* async deleteDocuments({
|
|
246
|
+
* index,
|
|
247
|
+
* filters,
|
|
248
|
+
* }: SearchTypes.SearchDeleteDocumentsInput): Promise<SearchTypes.SearchTask> {
|
|
249
|
+
* await this.client.deleteDocumentsByFilter(index, filters)
|
|
250
|
+
* return { index, status: "succeeded" }
|
|
251
|
+
* }
|
|
252
|
+
* }
|
|
253
|
+
*/
|
|
254
|
+
async deleteDocuments(_input) {
|
|
255
|
+
throw Error("deleteDocuments must be overridden by the child class");
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* This method removes every document from an index without deleting the index itself.
|
|
259
|
+
*
|
|
260
|
+
* @param {object} input - The index to empty.
|
|
261
|
+
* @param {string} input.index - The index's physical name.
|
|
262
|
+
* @returns {Promise<SearchTypes.SearchTask>} The write's task.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* class MySearchProviderService extends AbstractSearchProviderService {
|
|
266
|
+
* // ...
|
|
267
|
+
* async clearIndex({
|
|
268
|
+
* index,
|
|
269
|
+
* }: {
|
|
270
|
+
* index: string
|
|
271
|
+
* }): Promise<SearchTypes.SearchTask> {
|
|
272
|
+
* await this.client.deleteAllDocuments(index)
|
|
273
|
+
* return { index, status: "succeeded" }
|
|
274
|
+
* }
|
|
275
|
+
* }
|
|
276
|
+
*/
|
|
277
|
+
async clearIndex(_input) {
|
|
278
|
+
throw Error("clearIndex must be overridden by the child class");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.AbstractSearchProviderService = AbstractSearchProviderService;
|
|
282
|
+
//# sourceMappingURL=abstract-search-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-search-provider.js","sourceRoot":"","sources":["../../src/search/abstract-search-provider.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,MAAa,6BAA6B;IAYxC;;OAEG;IACH,IAAI,UAAU;QACZ,OAAQ,IAAI,CAAC,WAAmB,CAAC,UAAU,CAAA;IAC7C,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAQ,IAAI,CAAC,WAAmB,CAAC,UAAU,CAAA;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,KAAK,CAAC,MAAM,CACV,MAAuC;QAEvC,MAAM,KAAK,CAAC,8CAA8C,CAAC,CAAA;IAC7D,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;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