@medusajs/search 0.0.1 → 2.18.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 (102) hide show
  1. package/README.md +4 -1
  2. package/dist/index.d.ts +7 -8
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +11 -21
  5. package/dist/index.js.map +1 -0
  6. package/dist/joiner-config.d.ts +8 -2
  7. package/dist/joiner-config.d.ts.map +1 -0
  8. package/dist/joiner-config.js +9 -1
  9. package/dist/joiner-config.js.map +1 -0
  10. package/dist/loaders/{container.d.ts → providers.d.ts} +2 -1
  11. package/dist/loaders/providers.d.ts.map +1 -0
  12. package/dist/loaders/providers.js +23 -0
  13. package/dist/loaders/providers.js.map +1 -0
  14. package/dist/migrations/Migration20260805085626.d.ts +6 -0
  15. package/dist/migrations/Migration20260805085626.d.ts.map +1 -0
  16. package/dist/migrations/Migration20260805085626.js +23 -0
  17. package/dist/migrations/Migration20260805085626.js.map +1 -0
  18. package/dist/models/index.d.ts +3 -2
  19. package/dist/models/index.d.ts.map +1 -0
  20. package/dist/models/index.js +6 -16
  21. package/dist/models/index.js.map +1 -0
  22. package/dist/models/search-index-sync.d.ts +25 -0
  23. package/dist/models/search-index-sync.d.ts.map +1 -0
  24. package/dist/models/search-index-sync.js +42 -0
  25. package/dist/models/search-index-sync.js.map +1 -0
  26. package/dist/models/search-index.d.ts +21 -0
  27. package/dist/models/search-index.d.ts.map +1 -0
  28. package/dist/models/search-index.js +29 -0
  29. package/dist/models/search-index.js.map +1 -0
  30. package/dist/services/index.d.ts +2 -0
  31. package/dist/services/index.d.ts.map +1 -0
  32. package/dist/services/index.js +4 -1
  33. package/dist/services/index.js.map +1 -0
  34. package/dist/services/search-module-service.d.ts +45 -22
  35. package/dist/services/search-module-service.d.ts.map +1 -0
  36. package/dist/services/search-module-service.js +160 -45
  37. package/dist/services/search-module-service.js.map +1 -0
  38. package/dist/services/search-provider.d.ts +23 -0
  39. package/dist/services/search-provider.d.ts.map +1 -0
  40. package/dist/services/search-provider.js +64 -0
  41. package/dist/services/search-provider.js.map +1 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -0
  43. package/dist/types/index.d.ts +80 -110
  44. package/dist/types/index.d.ts.map +1 -0
  45. package/dist/types/index.js +5 -5
  46. package/dist/types/index.js.map +1 -0
  47. package/dist/utils/index.d.ts +63 -3
  48. package/dist/utils/index.d.ts.map +1 -0
  49. package/dist/utils/index.js +384 -17
  50. package/dist/utils/index.js.map +1 -0
  51. package/dist/utils/ingestion.d.ts +12 -0
  52. package/dist/utils/ingestion.d.ts.map +1 -0
  53. package/dist/utils/ingestion.js +69 -0
  54. package/dist/utils/ingestion.js.map +1 -0
  55. package/dist/utils/migrations.d.ts +11 -0
  56. package/dist/utils/migrations.d.ts.map +1 -0
  57. package/dist/utils/migrations.js +98 -0
  58. package/dist/utils/migrations.js.map +1 -0
  59. package/dist/utils/seeding.d.ts +14 -0
  60. package/dist/utils/seeding.d.ts.map +1 -0
  61. package/dist/utils/seeding.js +343 -0
  62. package/dist/utils/seeding.js.map +1 -0
  63. package/package.json +26 -45
  64. package/dist/initialize/index.d.ts +0 -8
  65. package/dist/initialize/index.js +0 -17
  66. package/dist/loaders/connection.d.ts +0 -4
  67. package/dist/loaders/connection.js +0 -41
  68. package/dist/loaders/container.js +0 -21
  69. package/dist/loaders/index.d.ts +0 -2
  70. package/dist/loaders/index.js +0 -10
  71. package/dist/migrations/Migration20231019174230.d.ts +0 -4
  72. package/dist/migrations/Migration20231019174230.js +0 -18
  73. package/dist/models/catalog-relation.d.ts +0 -15
  74. package/dist/models/catalog-relation.js +0 -72
  75. package/dist/models/catalog.d.ts +0 -11
  76. package/dist/models/catalog.js +0 -55
  77. package/dist/module-definition.d.ts +0 -2
  78. package/dist/module-definition.js +0 -15
  79. package/dist/scripts/bin/run-migration-down.d.ts +0 -3
  80. package/dist/scripts/bin/run-migration-down.js +0 -32
  81. package/dist/scripts/bin/run-migration-up.d.ts +0 -3
  82. package/dist/scripts/bin/run-migration-up.js +0 -32
  83. package/dist/scripts/bin/run-seed.d.ts +0 -3
  84. package/dist/scripts/bin/run-seed.js +0 -38
  85. package/dist/scripts/index.d.ts +0 -2
  86. package/dist/scripts/index.js +0 -18
  87. package/dist/scripts/migration-down.d.ts +0 -10
  88. package/dist/scripts/migration-down.js +0 -52
  89. package/dist/scripts/migration-up.d.ts +0 -10
  90. package/dist/scripts/migration-up.js +0 -56
  91. package/dist/scripts/seed-data/index.d.ts +0 -8
  92. package/dist/scripts/seed-data/index.js +0 -138
  93. package/dist/scripts/seed.d.ts +0 -5
  94. package/dist/scripts/seed.js +0 -65
  95. package/dist/services/postgres-provider.d.ts +0 -126
  96. package/dist/services/postgres-provider.js +0 -441
  97. package/dist/utils/build-config.d.ts +0 -21
  98. package/dist/utils/build-config.js +0 -437
  99. package/dist/utils/create-partitions.d.ts +0 -3
  100. package/dist/utils/create-partitions.js +0 -27
  101. package/dist/utils/query-builder.d.ts +0 -28
  102. package/dist/utils/query-builder.js +0 -375
@@ -1,66 +1,181 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const types_1 = require("../types");
4
- const build_config_1 = require("../utils/build-config");
5
- const joiner_config_1 = require("./../joiner-config");
6
- class SearchModuleService {
7
- constructor(container, moduleDeclaration) {
3
+ const utils_1 = require("@medusajs/framework/utils");
4
+ const _utils_1 = require("../utils");
5
+ const ingestion_1 = require("../utils/ingestion");
6
+ const migrations_1 = require("../utils/migrations");
7
+ const seeding_1 = require("../utils/seeding");
8
+ const joiner_config_1 = require("../joiner-config");
9
+ class SearchModuleService
10
+ // Deliberately no models: `SearchIndex` and `SearchIndexSync` are the module's
11
+ // own bookkeeping, so they get no generated CRUD and are not linkable. They are
12
+ // still discovered from `src/models` for migrations.
13
+ extends (0, utils_1.MedusaService)({}) {
14
+ constructor(container, moduleOptions, moduleDeclaration) {
15
+ // @ts-ignore
16
+ super(...arguments);
8
17
  this.moduleDeclaration = moduleDeclaration;
18
+ this.isWorkerMode = true;
9
19
  this.__hooks = {
10
20
  onApplicationStart() {
11
21
  return this.onApplicationStart_();
12
22
  },
13
23
  };
14
- this.container_ = container;
15
- this.moduleOptions_ = (moduleDeclaration.options ??
16
- moduleDeclaration);
17
- const { eventBusModuleService, storageProviderCtr, storageProviderCtrOptions, } = container;
18
- this.eventBusModuleService_ = eventBusModuleService;
19
- this.storageProviderCtr_ = storageProviderCtr;
20
- this.storageProviderCtrOptions_ = storageProviderCtrOptions;
21
- if (!this.eventBusModuleService_) {
22
- throw new Error("EventBusModuleService is required for the SearchModule to work");
23
- }
24
+ this.logger_ = container.logger ?? console;
25
+ this.searchProviderService_ = container.searchProviderService;
26
+ this.moduleOptions_ = (moduleOptions ??
27
+ moduleDeclaration.options ??
28
+ {});
29
+ // `worker_mode` is stamped onto every module's declaration by the
30
+ // modules-sdk from the application's own `projectConfig.workerMode`, so this
31
+ // reads the same value `configModule` would give — an HTTP-only process
32
+ // must not spend its boot seeding indexes.
33
+ this.isWorkerMode = moduleDeclaration.worker_mode !== "server";
34
+ // Resolved here rather than on application start, so anything that resolves the
35
+ // module — `db:migrate` included — sees the definitions without booting first.
36
+ this.indexes_ = this.moduleOptions_.indexes?.length
37
+ ? (0, _utils_1.resolveIndexDefinitions)({
38
+ definitions: this.moduleOptions_.indexes,
39
+ default_provider: container.searchProviderService.getDefaultIdentifier(this.moduleOptions_.default_provider),
40
+ index_prefix: this.moduleOptions_.index_prefix,
41
+ })
42
+ : new Map();
43
+ this.eventRoutes_ = (0, ingestion_1.buildEventRoutes)(this.indexes_);
44
+ this.context_ = {
45
+ container,
46
+ logger: this.logger_,
47
+ options: this.moduleOptions_,
48
+ indexes: this.indexes_,
49
+ providers: container.searchProviderService,
50
+ indexService: container.searchIndexService,
51
+ syncService: container.searchIndexSyncService,
52
+ locking: resolveLocking(container),
53
+ };
24
54
  }
55
+ // Declared so that `Module()` does not derive one by scanning `src/models`,
56
+ // which would make the module's bookkeeping linkable.
25
57
  __joinerConfig() {
26
58
  return joiner_config_1.joinerConfig;
27
59
  }
28
- async onApplicationStart_() {
29
- this.buildSchemaObjectRepresentation_();
30
- this.storageProvider_ = new this.storageProviderCtr_(this.container_, Object.assign(this.storageProviderCtrOptions_ ?? {}, {
31
- schemaObjectRepresentation: this.schemaObjectRepresentation_,
32
- entityMap: this.schemaEntitiesMap_,
33
- }), this.moduleOptions_);
34
- this.registerListeners();
35
- if (this.storageProvider_.onApplicationStart) {
36
- await this.storageProvider_.onApplicationStart();
37
- }
38
- }
39
- async query(...args) {
40
- return await this.storageProvider_.query.apply(this.storageProvider_, args);
41
- }
42
- async queryAndCount(...args) {
43
- return await this.storageProvider_.queryAndCount.apply(this.storageProvider_, args);
60
+ async search(query) {
61
+ const [result] = await this.searchMany([query]);
62
+ return result;
44
63
  }
45
- registerListeners() {
46
- const schemaObjectRepresentation = this.schemaObjectRepresentation_ ?? {};
47
- for (const [entityName, schemaEntityObjectRepresentation] of Object.entries(schemaObjectRepresentation)) {
48
- if (types_1.schemaObjectRepresentationPropertiesToOmit.includes(entityName)) {
49
- continue;
64
+ async searchMany(queries) {
65
+ if (!queries.length) {
66
+ return [];
67
+ }
68
+ const prepared = queries.map((query) => {
69
+ const index = (0, _utils_1.retrieveIndexDefinition)(this.indexes_, query.entity);
70
+ const normalized = (0, _utils_1.normalizeSearchQuery)({ query, index });
71
+ const provider = this.searchProviderService_.retrieve(index.provider);
72
+ // Whether the *provider* can serve the query is the provider's call, made
73
+ // while it translates. This only checks the query against the definition,
74
+ // which is provider-independent.
75
+ (0, _utils_1.validateFieldUsage)({ index, query: normalized });
76
+ return { normalized, provider };
77
+ });
78
+ return await (0, utils_1.promiseAll)(prepared.map(async ({ normalized, provider }) => {
79
+ if (!normalized.search_options?.disjunctive_facets) {
80
+ return await provider.search(normalized);
81
+ }
82
+ const { base, per_facet } = (0, _utils_1.buildDisjunctiveFacetQueries)(normalized);
83
+ if (!per_facet.size) {
84
+ return await provider.search(base);
50
85
  }
51
- schemaEntityObjectRepresentation.listeners.forEach((listener) => {
52
- this.eventBusModuleService_.subscribe(listener, this.storageProvider_.consumeEvent(schemaEntityObjectRepresentation));
86
+ // The base query carries the hits; the per-facet ones only recompute one
87
+ // facet each with that facet's own filter lifted.
88
+ const fields = [...per_facet.keys()];
89
+ const inputs = [base, ...fields.map((field) => per_facet.get(field))];
90
+ const [baseResult, ...facetResults] = provider.searchMany
91
+ ? await provider.searchMany(inputs)
92
+ : await (0, utils_1.promiseAll)(inputs.map((input) => provider.search(input)));
93
+ return (0, _utils_1.mergeDisjunctiveFacetResults)({
94
+ base: baseResult,
95
+ per_facet: new Map(fields.map((field, i) => [field, facetResults[i]])),
53
96
  });
97
+ }));
98
+ }
99
+ async upsertDocuments({ index, documents, }) {
100
+ if (!documents.length) {
101
+ return { index, status: "succeeded" };
54
102
  }
103
+ const definition = (0, _utils_1.retrieveIndexDefinition)(this.indexes_, index);
104
+ const provider = this.searchProviderService_.retrieve(definition.provider);
105
+ const task = await provider.upsertDocuments({
106
+ index: definition.physical_name,
107
+ documents,
108
+ });
109
+ return (0, _utils_1.assertTaskAccepted)(task, index);
110
+ }
111
+ async deleteDocuments({ index, filters, }) {
112
+ if (!filters || !Object.keys(filters).length) {
113
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Deleting from search index "${index}" requires filters; pass { id: [...] } to delete by id, or clear the index through a reindex`);
114
+ }
115
+ const definition = (0, _utils_1.retrieveIndexDefinition)(this.indexes_, index);
116
+ const provider = this.searchProviderService_.retrieve(definition.provider);
117
+ const task = await provider.deleteDocuments({
118
+ index: definition.physical_name,
119
+ filters,
120
+ });
121
+ return (0, _utils_1.assertTaskAccepted)(task, index);
122
+ }
123
+ // Waits for its writes, so awaiting this acknowledges the event.
124
+ async ingest(event) {
125
+ return await (0, ingestion_1.ingestEvent)(this.context_, {
126
+ event,
127
+ routes: this.eventRoutes_,
128
+ });
55
129
  }
56
- buildSchemaObjectRepresentation_() {
57
- if (this.schemaObjectRepresentation_) {
58
- return this.schemaObjectRepresentation_;
130
+ listIndexes() {
131
+ return [...this.indexes_.keys()];
132
+ }
133
+ listRetrievableFields(index) {
134
+ return (0, _utils_1.listRetrievablePaths)((0, _utils_1.retrieveIndexDefinition)(this.indexes_, index).fields);
135
+ }
136
+ async reindex(input = {}) {
137
+ return await (0, seeding_1.reindexIndexes)(this.context_, input);
138
+ }
139
+ /**
140
+ * Seeds whatever needs data. Indexes that are not migrated yet are skipped —
141
+ * creating and migrating physical indexes is the application's job
142
+ * (e.g. `db:migrate`), not something a booting worker invents.
143
+ */
144
+ async onApplicationStart_() {
145
+ if (!this.indexes_.size || !this.isWorkerMode) {
146
+ return;
147
+ }
148
+ const seeds = await this.createSeedPlan_();
149
+ if (!seeds.length) {
150
+ return;
59
151
  }
60
- const [objectRepresentation, entityMap] = (0, build_config_1.buildSchemaObjectRepresentation)(this.moduleOptions_.schema);
61
- this.schemaObjectRepresentation_ = objectRepresentation;
62
- this.schemaEntitiesMap_ = entityMap;
63
- return this.schemaObjectRepresentation_;
152
+ this.logger_.info(`[Search] Seeding ${seeds.length} index(es): ${seeds
153
+ .map((seed) => `${seed.index} (${seed.reason})`)
154
+ .join(", ")}`);
155
+ await this.executeSeedPlan_(seeds);
156
+ }
157
+ async createSeedPlan_() {
158
+ return await (0, seeding_1.createSeedPlan)(this.context_);
159
+ }
160
+ async executeSeedPlan_(actions) {
161
+ await (0, seeding_1.executeSeedPlan)(this.context_, actions);
162
+ }
163
+ async createIndexMigrationPlan() {
164
+ return await (0, migrations_1.createIndexMigrationPlan)(this.context_);
165
+ }
166
+ async executeIndexMigrationPlan(actions) {
167
+ await (0, migrations_1.executeIndexMigrationPlan)(this.context_, actions);
64
168
  }
65
169
  }
66
170
  exports.default = SearchModuleService;
171
+ // The Locking Module is optional, and reading a missing registration off the
172
+ // container throws rather than returning undefined.
173
+ function resolveLocking(container) {
174
+ try {
175
+ return container[utils_1.Modules.LOCKING];
176
+ }
177
+ catch {
178
+ return undefined;
179
+ }
180
+ }
181
+ //# sourceMappingURL=search-module-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-module-service.js","sourceRoot":"","sources":["../../src/services/search-module-service.ts"],"names":[],"mappings":";;AAUA,qDAMkC;AAQlC,mCASe;AACf,kDAAkE;AAClE,oDAG4B;AAC5B,8CAIyB;AACzB,oDAA+C;AAY/C,MAAqB,mBAAmB;AACtC,+EAA+E;AAC/E,gFAAgF;AAChF,qDAAqD;AACrD,SAAQ,IAAA,qBAAa,EAAC,EAAE,CAAC;IAqBzB,YACE,SAA+B,EAC/B,aAAkC,EACf,iBAA4C;QAE/D,aAAa;QACb,KAAK,CAAC,GAAG,SAAS,CAAC,CAAA;QAHA,sBAAiB,GAAjB,iBAAiB,CAA2B;QArBvD,iBAAY,GAAY,IAAI,CAAA;QAwEtC,YAAO,GAAG;YACR,kBAAkB;gBAChB,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAA;YACnC,CAAC;SACF,CAAA;QAlDC,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,IAAK,OAA6B,CAAA;QACjE,IAAI,CAAC,sBAAsB,GAAG,SAAS,CAAC,qBAAqB,CAAA;QAE7D,IAAI,CAAC,cAAc,GAAG,CAAC,aAAa;YAClC,iBAAiB,CAAC,OAAO;YACzB,EAAE,CAAwB,CAAA;QAE5B,kEAAkE;QAClE,6EAA6E;QAC7E,wEAAwE;QACxE,2CAA2C;QAC3C,IAAI,CAAC,YAAY,GAAG,iBAAiB,CAAC,WAAW,KAAK,QAAQ,CAAA;QAE9D,gFAAgF;QAChF,+EAA+E;QAC/E,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM;YACjD,CAAC,CAAC,IAAA,gCAAuB,EAAC;gBACtB,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,OAAO;gBACxC,gBAAgB,EACd,SAAS,CAAC,qBAAqB,CAAC,oBAAoB,CACl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aACjD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC;aAC/C,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAA;QAED,MAAM,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;IAES,KAAK,CAAC,eAAe;QAC7B,OAAO,MAAM,IAAA,wBAAc,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5C,CAAC;IAES,KAAK,CAAC,gBAAgB,CAC9B,OAAgC;QAEhC,MAAM,IAAA,yBAAe,EAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC/C,CAAC;IAED,KAAK,CAAC,wBAAwB;QAG5B,OAAO,MAAM,IAAA,qCAAwB,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACtD,CAAC;IAED,KAAK,CAAC,yBAAyB,CAC7B,OAAiD;QAEjD,MAAM,IAAA,sCAAyB,EAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACzD,CAAC;CACF;AApQD,sCAoQC;AAED,6EAA6E;AAC7E,oDAAoD;AACpD,SAAS,cAAc,CACrB,SAA+B;IAE/B,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,eAAO,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Constructor, SearchTypes } from "@medusajs/framework/types";
2
+ import { SearchProviderRegistrationPrefix } from "../types";
3
+ type InjectedDependencies = {
4
+ [key: `${typeof SearchProviderRegistrationPrefix}${string}`]: SearchTypes.ISearchProvider;
5
+ };
6
+ /**
7
+ * Registry over the registered providers. Multiple providers can be used, and
8
+ * each index can select which provider to use for itself.
9
+ */
10
+ export declare class SearchProviderService {
11
+ protected readonly providers_: Map<string, SearchTypes.ISearchProvider>;
12
+ constructor(container: InjectedDependencies);
13
+ static getRegistrationIdentifier(providerClass: Constructor<SearchTypes.ISearchProvider>, optionName?: string): string;
14
+ retrieve(identifier: string): SearchTypes.ISearchProvider;
15
+ list(): SearchTypes.ISearchProvider[];
16
+ /**
17
+ * Used by definitions that do not name a provider. Resolves to the sole
18
+ * registered provider, or to the module's `default_provider` option.
19
+ */
20
+ getDefaultIdentifier(configured?: string): string;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=search-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-provider.d.ts","sourceRoot":"","sources":["../../src/services/search-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEpE,OAAO,EAAE,gCAAgC,EAAE,MAAM,QAAQ,CAAA;AAEzD,KAAK,oBAAoB,GAAG;IAC1B,CACE,GAAG,EAAE,GAAG,OAAO,gCAAgC,GAAG,MAAM,EAAE,GACzD,WAAW,CAAC,eAAe,CAAA;CAC/B,CAAA;AAED;;;GAGG;AACH,qBAAa,qBAAqB;IAChC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,eAAe,CAAC,CAC5D;gBAEC,SAAS,EAAE,oBAAoB;IAyB3C,MAAM,CAAC,yBAAyB,CAC9B,aAAa,EAAE,WAAW,CAAC,WAAW,CAAC,eAAe,CAAC,EACvD,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM;IAIT,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW,CAAC,eAAe;IAezD,IAAI,IAAI,WAAW,CAAC,eAAe,EAAE;IAIrC;;;OAGG;IACH,oBAAoB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;CA2BlD"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchProviderService = void 0;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ const _types_1 = require("../types");
6
+ /**
7
+ * Registry over the registered providers. Multiple providers can be used, and
8
+ * each index can select which provider to use for itself.
9
+ */
10
+ class SearchProviderService {
11
+ constructor(container) {
12
+ this.providers_ = new Map();
13
+ for (const key of Object.keys(container)) {
14
+ if (!key.startsWith(_types_1.SearchProviderRegistrationPrefix)) {
15
+ continue;
16
+ }
17
+ const provider = container[key];
18
+ if (!provider?.identifier) {
19
+ continue;
20
+ }
21
+ // Definitions bind to a provider by identifier, so two registrations of
22
+ // the same provider class would be indistinguishable to them — the second
23
+ // would silently shadow the first.
24
+ if (this.providers_.has(provider.identifier)) {
25
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `The search provider "${provider.identifier}" is registered twice. Register each provider once; index definitions select it through their "provider" field.`);
26
+ }
27
+ this.providers_.set(provider.identifier, provider);
28
+ }
29
+ }
30
+ static getRegistrationIdentifier(providerClass, optionName) {
31
+ return `${providerClass.identifier}_${optionName}`;
32
+ }
33
+ retrieve(identifier) {
34
+ const provider = this.providers_.get(identifier);
35
+ if (!provider) {
36
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Search provider "${identifier}" is not registered. Registered providers: ${[...this.providers_.keys()].join(", ") || "(none)"}`);
37
+ }
38
+ return provider;
39
+ }
40
+ list() {
41
+ return [...this.providers_.values()];
42
+ }
43
+ /**
44
+ * Used by definitions that do not name a provider. Resolves to the sole
45
+ * registered provider, or to the module's `default_provider` option.
46
+ */
47
+ getDefaultIdentifier(configured) {
48
+ if (configured) {
49
+ // Surfaces a typo in `default_provider` at boot rather than on first query.
50
+ this.retrieve(configured);
51
+ return configured;
52
+ }
53
+ const identifiers = [...this.providers_.keys()];
54
+ if (identifiers.length === 1) {
55
+ return identifiers[0];
56
+ }
57
+ if (!identifiers.length) {
58
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "The Search Module requires at least one provider to be registered");
59
+ }
60
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Several search providers are registered (${identifiers.join(", ")}), so "default_provider" must be set, or every index definition must name its provider`);
61
+ }
62
+ }
63
+ exports.SearchProviderService = SearchProviderService;
64
+ //# sourceMappingURL=search-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-provider.js","sourceRoot":"","sources":["../../src/services/search-provider.ts"],"names":[],"mappings":";;;AACA,qDAAuD;AACvD,mCAAyD;AAQzD;;;GAGG;AACH,MAAa,qBAAqB;IAIhC,YAAY,SAA+B;QAHxB,eAAU,GAC3B,IAAI,GAAG,EAAE,CAAA;QAGT,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,yCAAgC,CAAC,EAAE,CAAC;gBACtD,SAAQ;YACV,CAAC;YAED,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;YAC/B,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;gBAC1B,SAAQ;YACV,CAAC;YAED,wEAAwE;YACxE,0EAA0E;YAC1E,mCAAmC;YACnC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC7C,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,wBAAwB,QAAQ,CAAC,UAAU,iHAAiH,CAC7J,CAAA;YACH,CAAC;YAED,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QACpD,CAAC;IACH,CAAC;IAED,MAAM,CAAC,yBAAyB,CAC9B,aAAuD,EACvD,UAAmB;QAEnB,OAAO,GAAI,aAAqB,CAAC,UAAU,IAAI,UAAU,EAAE,CAAA;IAC7D,CAAC;IAED,QAAQ,CAAC,UAAkB;QACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QAEhD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,SAAS,EAC3B,oBAAoB,UAAU,8CAC5B,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAC5C,EAAE,CACH,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,IAAI;QACF,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAA;IACtC,CAAC;IAED;;;OAGG;IACH,oBAAoB,CAAC,UAAmB;QACtC,IAAI,UAAU,EAAE,CAAC;YACf,4EAA4E;YAC5E,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;YACzB,OAAO,UAAU,CAAA;QACnB,CAAC;QAED,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAA;QAE/C,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,WAAW,CAAC,CAAC,CAAC,CAAA;QACvB,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YACxB,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,mEAAmE,CACpE,CAAA;QACH,CAAC;QAED,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,4CAA4C,WAAW,CAAC,IAAI,CAC1D,IAAI,CACL,wFAAwF,CAC1F,CAAA;IACH,CAAC;CACF;AAtFD,sDAsFC"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/joiner-config.ts","../src/loaders/providers.ts","../src/migrations/migration20260805085626.ts","../src/models/index.ts","../src/models/search-index-sync.ts","../src/models/search-index.ts","../src/services/index.ts","../src/services/search-module-service.ts","../src/services/search-provider.ts","../src/types/index.ts","../src/utils/index.ts","../src/utils/ingestion.ts","../src/utils/migrations.ts","../src/utils/seeding.ts"],"version":"5.9.3"}
@@ -1,122 +1,92 @@
1
- import { ModuleJoinerConfig, ModulesSdkTypes, Subscriber } from "@medusajs/types";
2
- /**
3
- * Represents the module options that can be provided
4
- */
5
- export interface SearchModuleOptions {
6
- customAdapter?: {
7
- constructor: new (...args: any[]) => any;
8
- options: any;
9
- };
10
- defaultAdapterOptions?: ModulesSdkTypes.ModuleServiceInitializeOptions;
11
- schema: string;
12
- }
13
- export type SchemaObjectEntityRepresentation = {
14
- /**
15
- * The name of the type/entity in the schema
16
- */
17
- entity: string;
1
+ import { Logger, ModuleProviderExports, ModuleServiceInitializeOptions, ModulesSdkTypes, SearchTypes } from "@medusajs/framework/types";
2
+ export declare const SearchProviderIdentifiersRegistrationName = "search_providers_identifier";
3
+ export declare const SearchProviderRegistrationPrefix = "srh_";
4
+ export type SearchModuleOptions = Partial<ModuleServiceInitializeOptions> & {
18
5
  /**
19
- * All parents a type/entity refers to in the schema
20
- * or through links
6
+ * More than one may be registered, unlike most provider-backed modules. A
7
+ * definition picks one by identifier through its `provider`, so products can
8
+ * live on a dedicated engine while quieter entities stay on Postgres.
21
9
  */
22
- parents: {
23
- /**
24
- * The reference to the schema object representation
25
- * of the parent
26
- */
27
- ref: SchemaObjectEntityRepresentation;
28
- /**
29
- * When a link is inferred between two types/entities
30
- * we are configuring the link tree, and therefore we are
31
- * storing the reference to the parent type/entity within the
32
- * schema which defer from the true parent from a pure entity
33
- * point of view
34
- */
35
- inSchemaRef?: SchemaObjectEntityRepresentation;
36
- /**
37
- * The property the data should be assigned to in the parent
38
- */
39
- targetProp: string;
40
- /**
41
- * Are the data expected to be a list or not
42
- */
43
- isList?: boolean;
10
+ providers?: {
11
+ resolve: string | ModuleProviderExports;
12
+ id: string;
13
+ options?: Record<string, unknown>;
44
14
  }[];
15
+ default_provider?: string;
16
+ index_prefix?: string;
45
17
  /**
46
- * The default fields to query for the type/entity
47
- */
48
- fields: string[];
49
- /**
50
- * @Listerners directive is required and all listeners found
51
- * for the type will be stored here
52
- */
53
- listeners: string[];
54
- /**
55
- * The alias for the type/entity retrieved in the corresponding
56
- * module
57
- */
58
- alias: string;
59
- /**
60
- * The module joiner config corresponding to the module the type/entity
61
- * refers to
18
+ * The definitions this module manages. It does not discover them itself — the
19
+ * application loads them off the file system and passes them in, so there is one
20
+ * input rather than two that can disagree.
62
21
  */
63
- moduleConfig: ModuleJoinerConfig;
64
- };
65
- export type SchemaPropertiesMap = {
66
- [key: string]: {
67
- shortCutOf?: string;
68
- ref: SchemaObjectEntityRepresentation;
22
+ indexes?: SearchTypes.SearchIndexDefinition[];
23
+ reindex?: {
24
+ batch_size?: number;
69
25
  };
70
26
  };
71
- export type EntityNameModuleConfigMap = {
72
- [key: string]: ModuleJoinerConfig;
73
- };
74
- /**
75
- * Represents the schema objects representation once the schema has been processed
76
- */
77
- export type SchemaObjectRepresentation = {
78
- [key: string]: SchemaObjectEntityRepresentation;
79
- } | {
80
- _schemaPropertiesMap: SchemaPropertiesMap;
81
- _serviceNameModuleConfigMap: EntityNameModuleConfigMap;
82
- };
83
- export declare const schemaObjectRepresentationPropertiesToOmit: string[];
27
+ declare module "@medusajs/types" {
28
+ interface ModuleOptions {
29
+ "@medusajs/search": SearchModuleOptions;
30
+ "@medusajs/medusa/search": SearchModuleOptions;
31
+ }
32
+ }
84
33
  /**
85
- * Represents the storage provider interface, TODO: move this to @medusajs/types once we are settled on the interface
34
+ * Handed to the migration and seeding helpers per call; they keep no state of
35
+ * their own. `indexes` is a live reference to the service's registry, not a copy,
36
+ * and `providers` is structural so `utils` need not depend on the service layer.
86
37
  */
87
- export interface StorageProvider {
88
- new (container: {
89
- [key: string]: any;
90
- }, storageProviderOptions: unknown & {
91
- schemaObjectRepresentation: SchemaObjectRepresentation;
92
- }, moduleOptions: SearchModuleOptions): StorageProvider;
93
- onApplicationStart?(): Promise<void>;
94
- query(...args: any[]): unknown;
95
- queryAndCount(...args: any[]): unknown;
96
- consumeEvent(schemaEntityObjectRepresentation: SchemaObjectEntityRepresentation): Subscriber;
97
- }
98
- export type Select = {
99
- [key: string]: boolean | Select | Select[];
100
- };
101
- export type Where = {
102
- [key: string]: any;
103
- };
104
- export type OrderBy = {
105
- [path: string]: OrderBy | "ASC" | "DESC" | 1 | -1 | true | false;
106
- };
107
- export type QueryFormat = {
108
- select: Select;
109
- where?: Where;
110
- joinWhere?: Where;
38
+ /** Resolved definitions, keyed by index name. */
39
+ export type SearchIndexes = Map<string, SearchTypes.ResolvedSearchIndexDefinition>;
40
+ export type SearchIndexContext = {
41
+ container: SearchTypes.SearchContainer;
42
+ logger: Logger;
43
+ options: SearchModuleOptions;
44
+ indexes: SearchIndexes;
45
+ providers: {
46
+ retrieve(identifier: string): SearchTypes.ISearchProvider;
47
+ };
48
+ indexService: ModulesSdkTypes.IMedusaInternalService<any>;
49
+ syncService: ModulesSdkTypes.IMedusaInternalService<any>;
50
+ locking?: {
51
+ execute<T>(keys: string | string[], job: () => Promise<T>, args?: {
52
+ timeout?: number;
53
+ }): Promise<T>;
54
+ };
111
55
  };
112
- export type QueryOptions = {
113
- skip?: number;
114
- take?: number;
115
- orderBy?: OrderBy | OrderBy[];
116
- keepFilteredEntities?: boolean;
56
+ export type SearchIndexRegistry = Pick<SearchIndexContext, "indexes" | "indexService" | "providers">;
57
+ export type SearchSeedRuntime = SearchIndexRegistry & Pick<SearchIndexContext, "syncService" | "container" | "options">;
58
+ export type SearchIngestionRuntime = SearchIndexRegistry & Pick<SearchIndexContext, "container">;
59
+ /** Event name to the indexes that declared it. */
60
+ export type SearchEventRoutes = Map<string, string[]>;
61
+ /** One seed run against one index. Append-only, so these are the history. */
62
+ export type SearchIndexSyncRecord = {
63
+ id: string;
64
+ search_index_id: string;
65
+ job_id: string | null;
66
+ status: string;
67
+ filters: Record<string, unknown> | null;
68
+ last_key: string | null;
69
+ documents_synced: number;
70
+ started_at: Date | null;
71
+ completed_at: Date | null;
72
+ error: string | null;
73
+ created_at: Date;
74
+ updated_at: Date;
75
+ deleted_at: Date | null;
117
76
  };
118
- type ResultSetLimit = [never | 0 | 1 | 2];
119
- export type Resultset<Select, Prev extends number = 3> = Prev extends never ? never : {
120
- [key in keyof Select]: Select[key] extends boolean ? string : Select[key] extends Select[] ? Resultset<Select[key][0], ResultSetLimit[Prev]>[] : Select[key] extends {} ? Resultset<Select[key], ResultSetLimit[Prev]> : unknown;
77
+ export type SearchIndexSeedReason =
78
+ /** Created but never filled. */
79
+ "index_created"
80
+ /** Exists and holds no documents — an engine wiped or restarted underneath us. */
81
+ | "index_empty"
82
+ /** A migration built a new index that has to be filled, then swapped in. */
83
+ | "schema_changed" | "last_run_failed";
84
+ export type SearchIndexSeedAction = {
85
+ index: string;
86
+ /** The index the seed writes into. */
87
+ target_physical_name: string;
88
+ /** Whether the target has to be aliased over the live index once filled. */
89
+ swap: boolean;
90
+ reason: SearchIndexSeedReason;
121
91
  };
122
- export {};
92
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,qBAAqB,EACrB,8BAA8B,EAC9B,eAAe,EACf,WAAW,EACZ,MAAM,2BAA2B,CAAA;AAElC,eAAO,MAAM,yCAAyC,gCACvB,CAAA;AAG/B,eAAO,MAAM,gCAAgC,SAAS,CAAA;AAEtD,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,8BAA8B,CAAC,GAAG;IAC1E;;;;OAIG;IACH,SAAS,CAAC,EAAE;QACV,OAAO,EAAE,MAAM,GAAG,qBAAqB,CAAA;QACvC,EAAE,EAAE,MAAM,CAAA;QACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAClC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7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.schemaObjectRepresentationPropertiesToOmit = void 0;
4
- exports.schemaObjectRepresentationPropertiesToOmit = [
5
- "_schemaPropertiesMap",
6
- "_serviceNameModuleConfigMap",
7
- ];
3
+ exports.SearchProviderRegistrationPrefix = exports.SearchProviderIdentifiersRegistrationName = void 0;
4
+ exports.SearchProviderIdentifiersRegistrationName = "search_providers_identifier";
5
+ // Providers are registered as `srh_{identifier}_{id}`.
6
+ exports.SearchProviderRegistrationPrefix = "srh_";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAQa,QAAA,yCAAyC,GACpD,6BAA6B,CAAA;AAE/B,uDAAuD;AAC1C,QAAA,gCAAgC,GAAG,MAAM,CAAA"}
@@ -1,3 +1,63 @@
1
- export * from "./query-builder";
2
- export * from "./create-partitions";
3
- export * from "./build-config";
1
+ import { SearchTypes } from "@medusajs/framework/types";
2
+ import { SearchIndexes } from "../types";
3
+ export declare enum SearchIndexState {
4
+ PENDING = "pending",
5
+ BUILDING = "building",
6
+ READY = "ready",
7
+ ERROR = "error"
8
+ }
9
+ export declare enum SearchSyncStatus {
10
+ PENDING = "pending",
11
+ PROCESSING = "processing",
12
+ DONE = "done",
13
+ FAILED = "failed",
14
+ CANCELED = "canceled"
15
+ }
16
+ export declare const DEFAULT_REINDEX_BATCH_SIZE = 100;
17
+ export type FlatSearchField = {
18
+ path: string;
19
+ field: SearchTypes.SearchFieldDefinition;
20
+ };
21
+ export declare function flattenFields(fields: Record<string, SearchTypes.SearchFieldDefinition>, prefix?: string): FlatSearchField[];
22
+ export declare function isSearchable(field: SearchTypes.SearchFieldDefinition): boolean;
23
+ export declare function isFacetable(field: SearchTypes.SearchFieldDefinition, kind: SearchTypes.SearchFacetKind): boolean;
24
+ /**
25
+ * The dotted paths an index can hand back on hits. Object containers are
26
+ * excluded — only their declared leaves are stored, so returning the container
27
+ * would silently hand back a partial object.
28
+ */
29
+ export declare function listRetrievablePaths(fields: Record<string, SearchTypes.SearchFieldDefinition>): string[];
30
+ export declare function normalizeSearchQuery({ query, index, }: {
31
+ query: SearchTypes.SearchQuery;
32
+ index: SearchTypes.ResolvedSearchIndexDefinition;
33
+ }): SearchTypes.ProviderSearchQuery;
34
+ /**
35
+ * The base query plus one per faceted field with that field's own filter dropped.
36
+ * Every engine reviewed needs a query per facet, so the fan-out lives here rather
37
+ * than in each provider. `disjunctive_facets` is stripped from what is handed on —
38
+ * a provider should never see an option it is not expected to act on.
39
+ */
40
+ export declare function buildDisjunctiveFacetQueries(query: SearchTypes.ProviderSearchQuery): {
41
+ base: SearchTypes.ProviderSearchQuery;
42
+ per_facet: Map<string, SearchTypes.ProviderSearchQuery>;
43
+ };
44
+ export declare function mergeDisjunctiveFacetResults({ base, per_facet, }: {
45
+ base: SearchTypes.SearchResult;
46
+ per_facet: Map<string, SearchTypes.SearchResult>;
47
+ }): SearchTypes.SearchResult;
48
+ export declare function validateFieldUsage({ index, query, }: {
49
+ index: SearchTypes.ResolvedSearchIndexDefinition;
50
+ query: Pick<SearchTypes.SearchQuery, "filters" | "pagination" | "search_options">;
51
+ }): void;
52
+ /**
53
+ * Resolves every definition once, at construction. Duplicates and incoherent
54
+ * definitions fail here, so everything downstream can treat the result as given.
55
+ */
56
+ export declare function resolveIndexDefinitions({ definitions, default_provider, index_prefix, }: {
57
+ definitions: SearchTypes.SearchIndexDefinition[];
58
+ default_provider: string;
59
+ index_prefix?: string;
60
+ }): SearchIndexes;
61
+ export declare function retrieveIndexDefinition(indexes: SearchIndexes, name: string): SearchTypes.ResolvedSearchIndexDefinition;
62
+ export declare function assertTaskAccepted(task: SearchTypes.SearchTask, index: string): SearchTypes.SearchTask;
63
+ //# sourceMappingURL=index.d.ts.map