@medusajs/query 2.17.2
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/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/joiner/helpers.d.ts +3 -0
- package/dist/joiner/helpers.d.ts.map +1 -0
- package/dist/joiner/helpers.js +69 -0
- package/dist/joiner/helpers.js.map +1 -0
- package/dist/joiner/index.d.ts +3 -0
- package/dist/joiner/index.d.ts.map +1 -0
- package/dist/joiner/index.js +19 -0
- package/dist/joiner/index.js.map +1 -0
- package/dist/joiner/remote-joiner.d.ts +43 -0
- package/dist/joiner/remote-joiner.d.ts.map +1 -0
- package/dist/joiner/remote-joiner.js +1279 -0
- package/dist/joiner/remote-joiner.js.map +1 -0
- package/dist/medusa-module.d.ts +13 -0
- package/dist/medusa-module.d.ts.map +1 -0
- package/dist/medusa-module.js +17 -0
- package/dist/medusa-module.js.map +1 -0
- package/dist/remote-query/index.d.ts +3 -0
- package/dist/remote-query/index.d.ts.map +1 -0
- package/dist/remote-query/index.js +19 -0
- package/dist/remote-query/index.js.map +1 -0
- package/dist/remote-query/parse-filters.d.ts +15 -0
- package/dist/remote-query/parse-filters.d.ts.map +1 -0
- package/dist/remote-query/parse-filters.js +178 -0
- package/dist/remote-query/parse-filters.js.map +1 -0
- package/dist/remote-query/query.d.ts +58 -0
- package/dist/remote-query/query.d.ts.map +1 -0
- package/dist/remote-query/query.js +254 -0
- package/dist/remote-query/query.js.map +1 -0
- package/dist/remote-query/remote-query.d.ts +43 -0
- package/dist/remote-query/remote-query.d.ts.map +1 -0
- package/dist/remote-query/remote-query.js +297 -0
- package/dist/remote-query/remote-query.js.map +1 -0
- package/dist/remote-query/to-remote-query.d.ts +29 -0
- package/dist/remote-query/to-remote-query.d.ts.map +1 -0
- package/dist/remote-query/to-remote-query.js +110 -0
- package/dist/remote-query/to-remote-query.js.map +1 -0
- package/dist/testing/medusa-module-mock.d.ts +2 -0
- package/dist/testing/medusa-module-mock.d.ts.map +1 -0
- package/dist/testing/medusa-module-mock.js +16 -0
- package/dist/testing/medusa-module-mock.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var _Query_instances, _Query_remoteQuery, _Query_indexModule, _Query_unwrapQueryConfig, _Query_unwrapRemoteQueryResponse;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.Query = void 0;
|
|
25
|
+
exports.createQuery = createQuery;
|
|
26
|
+
const utils_1 = require("@medusajs/utils");
|
|
27
|
+
const remote_query_1 = require("./remote-query");
|
|
28
|
+
const to_remote_query_1 = require("./to-remote-query");
|
|
29
|
+
function extractCacheOptions(option) {
|
|
30
|
+
return function extractKey(args) {
|
|
31
|
+
return args[1]?.cache?.[option];
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function isCacheEnabled(args) {
|
|
35
|
+
const isEnabled = extractCacheOptions("enable")(args);
|
|
36
|
+
if (isEnabled === false) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return (isEnabled === true ||
|
|
40
|
+
extractCacheOptions("key")(args) ||
|
|
41
|
+
extractCacheOptions("ttl")(args) ||
|
|
42
|
+
extractCacheOptions("tags")(args) ||
|
|
43
|
+
extractCacheOptions("autoInvalidate")(args) ||
|
|
44
|
+
extractCacheOptions("providers")(args));
|
|
45
|
+
}
|
|
46
|
+
const cacheDecoratorOptions = {
|
|
47
|
+
enable: isCacheEnabled,
|
|
48
|
+
key: async (args, cachingModule) => {
|
|
49
|
+
const key = extractCacheOptions("key")(args);
|
|
50
|
+
if (key) {
|
|
51
|
+
return key;
|
|
52
|
+
}
|
|
53
|
+
const queryOptions = args[0];
|
|
54
|
+
const remoteJoinerOptions = args[1] ?? {};
|
|
55
|
+
const { initialData, cache, ...restOptions } = remoteJoinerOptions;
|
|
56
|
+
const keyInput = {
|
|
57
|
+
queryOptions,
|
|
58
|
+
options: restOptions,
|
|
59
|
+
};
|
|
60
|
+
return await cachingModule.computeKey(keyInput);
|
|
61
|
+
},
|
|
62
|
+
ttl: extractCacheOptions("ttl"),
|
|
63
|
+
tags: extractCacheOptions("tags"),
|
|
64
|
+
autoInvalidate: extractCacheOptions("autoInvalidate"),
|
|
65
|
+
providers: extractCacheOptions("providers"),
|
|
66
|
+
container: function () {
|
|
67
|
+
return this.container;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* API wrapper around the remoteQuery
|
|
72
|
+
*/
|
|
73
|
+
class Query {
|
|
74
|
+
constructor({ remoteQuery, indexModule, container, }) {
|
|
75
|
+
_Query_instances.add(this);
|
|
76
|
+
_Query_remoteQuery.set(this, void 0);
|
|
77
|
+
_Query_indexModule.set(this, void 0);
|
|
78
|
+
__classPrivateFieldSet(this, _Query_remoteQuery, remoteQuery, "f");
|
|
79
|
+
__classPrivateFieldSet(this, _Query_indexModule, indexModule, "f");
|
|
80
|
+
this.container = container;
|
|
81
|
+
}
|
|
82
|
+
async query(queryOptions, options) {
|
|
83
|
+
if (!(0, utils_1.isObject)(queryOptions)) {
|
|
84
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Invalid query, expected object and received something else.");
|
|
85
|
+
}
|
|
86
|
+
const config = __classPrivateFieldGet(this, _Query_instances, "m", _Query_unwrapQueryConfig).call(this, queryOptions);
|
|
87
|
+
if (Query.traceRemoteQuery) {
|
|
88
|
+
return await Query.traceRemoteQuery(async () => await __classPrivateFieldGet(this, _Query_remoteQuery, "f").query(config, undefined, options), queryOptions);
|
|
89
|
+
}
|
|
90
|
+
return await __classPrivateFieldGet(this, _Query_remoteQuery, "f").query(config, undefined, options);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Query wrapper to provide specific GraphQL like API around remoteQuery.query
|
|
94
|
+
* @param query
|
|
95
|
+
* @param variables
|
|
96
|
+
* @param options
|
|
97
|
+
*/
|
|
98
|
+
async gql(query, variables, options) {
|
|
99
|
+
return await __classPrivateFieldGet(this, _Query_remoteQuery, "f").query(query, variables, options);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Graph function uses the remoteQuery under the hood and
|
|
103
|
+
* returns a result set
|
|
104
|
+
*/
|
|
105
|
+
async graph(queryOptions, options) {
|
|
106
|
+
const normalizedQuery = (0, to_remote_query_1.toRemoteQuery)(queryOptions, __classPrivateFieldGet(this, _Query_remoteQuery, "f").getEntitiesMap());
|
|
107
|
+
let response;
|
|
108
|
+
/**
|
|
109
|
+
* When traceGraphQuery method is defined, we will wrap the implementation
|
|
110
|
+
* inside a callback and provide the method to the traceGraphQuery
|
|
111
|
+
*/
|
|
112
|
+
if (Query.traceGraphQuery) {
|
|
113
|
+
response = await Query.traceGraphQuery(async () => await __classPrivateFieldGet(this, _Query_remoteQuery, "f").query(normalizedQuery, undefined, options), queryOptions);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
response = await __classPrivateFieldGet(this, _Query_remoteQuery, "f").query(normalizedQuery, undefined, options);
|
|
117
|
+
}
|
|
118
|
+
const result = __classPrivateFieldGet(this, _Query_instances, "m", _Query_unwrapRemoteQueryResponse).call(this, response);
|
|
119
|
+
if (options?.locale) {
|
|
120
|
+
await (0, utils_1.applyTranslations)({
|
|
121
|
+
localeCode: options.locale,
|
|
122
|
+
objects: result.data,
|
|
123
|
+
container: this.container,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Index function uses the Index module to query and hydrates the data with query.graph
|
|
130
|
+
* returns a result set
|
|
131
|
+
*/
|
|
132
|
+
async index(queryOptions, options) {
|
|
133
|
+
if (!__classPrivateFieldGet(this, _Query_indexModule, "f")) {
|
|
134
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Index module is not loaded.");
|
|
135
|
+
}
|
|
136
|
+
const mainEntity = queryOptions.entity;
|
|
137
|
+
const fields = [mainEntity + ".id"];
|
|
138
|
+
const filters = queryOptions.filters
|
|
139
|
+
? { [mainEntity]: queryOptions.filters }
|
|
140
|
+
: {};
|
|
141
|
+
const joinFilters = queryOptions.joinFilters
|
|
142
|
+
? { [mainEntity]: queryOptions.joinFilters }
|
|
143
|
+
: {};
|
|
144
|
+
const pagination = queryOptions.pagination;
|
|
145
|
+
if (pagination?.order) {
|
|
146
|
+
pagination.order = {
|
|
147
|
+
[mainEntity]: (0, utils_1.unflattenObjectKeys)(pagination?.order),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const indexResponse = (await __classPrivateFieldGet(this, _Query_indexModule, "f").query({
|
|
151
|
+
fields,
|
|
152
|
+
filters,
|
|
153
|
+
joinFilters,
|
|
154
|
+
pagination,
|
|
155
|
+
idsOnly: true,
|
|
156
|
+
}));
|
|
157
|
+
delete queryOptions.filters;
|
|
158
|
+
const idFilters = {
|
|
159
|
+
id: indexResponse.data.map((item) => item.id),
|
|
160
|
+
};
|
|
161
|
+
queryOptions.filters = idFilters;
|
|
162
|
+
const graphOptions = {
|
|
163
|
+
...queryOptions,
|
|
164
|
+
pagination: {
|
|
165
|
+
// We pass through `take` to force the `select-in` query strategy
|
|
166
|
+
// There might be a better way to do this, but for now this should do
|
|
167
|
+
take: queryOptions.pagination?.take ?? indexResponse.data.length,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
let finalResultset = indexResponse;
|
|
171
|
+
if (indexResponse.data.length) {
|
|
172
|
+
finalResultset = await this.graph(graphOptions, {
|
|
173
|
+
...options,
|
|
174
|
+
initialData: indexResponse.data,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (options?.locale) {
|
|
178
|
+
await (0, utils_1.applyTranslations)({
|
|
179
|
+
localeCode: options.locale,
|
|
180
|
+
objects: finalResultset.data,
|
|
181
|
+
container: this.container,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
data: finalResultset.data,
|
|
186
|
+
metadata: indexResponse.metadata,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.Query = Query;
|
|
191
|
+
_Query_remoteQuery = new WeakMap(), _Query_indexModule = new WeakMap(), _Query_instances = new WeakSet(), _Query_unwrapQueryConfig = function _Query_unwrapQueryConfig(config) {
|
|
192
|
+
let normalizedQuery = config;
|
|
193
|
+
if ("__value" in config) {
|
|
194
|
+
normalizedQuery = config.__value;
|
|
195
|
+
}
|
|
196
|
+
else if ("entity" in normalizedQuery) {
|
|
197
|
+
normalizedQuery = (0, to_remote_query_1.toRemoteQuery)(normalizedQuery, __classPrivateFieldGet(this, _Query_remoteQuery, "f").getEntitiesMap());
|
|
198
|
+
}
|
|
199
|
+
else if ("entryPoint" in normalizedQuery ||
|
|
200
|
+
"service" in normalizedQuery) {
|
|
201
|
+
normalizedQuery = (0, utils_1.remoteQueryObjectFromString)(normalizedQuery).__value;
|
|
202
|
+
}
|
|
203
|
+
return normalizedQuery;
|
|
204
|
+
}, _Query_unwrapRemoteQueryResponse = function _Query_unwrapRemoteQueryResponse(response) {
|
|
205
|
+
if (Array.isArray(response)) {
|
|
206
|
+
return { data: response, metadata: undefined };
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
data: response.rows,
|
|
210
|
+
metadata: response.metadata,
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
Query.instrument = {
|
|
214
|
+
graphQuery(tracer) {
|
|
215
|
+
Query.traceGraphQuery = tracer;
|
|
216
|
+
},
|
|
217
|
+
remoteQuery(tracer) {
|
|
218
|
+
Query.traceRemoteQuery = tracer;
|
|
219
|
+
},
|
|
220
|
+
remoteDataFetch(tracer) {
|
|
221
|
+
remote_query_1.RemoteQuery.traceFetchRemoteData = tracer;
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
__decorate([
|
|
225
|
+
(0, utils_1.Cached)(cacheDecoratorOptions),
|
|
226
|
+
__metadata("design:type", Function),
|
|
227
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
228
|
+
__metadata("design:returntype", Promise)
|
|
229
|
+
], Query.prototype, "graph", null);
|
|
230
|
+
__decorate([
|
|
231
|
+
(0, utils_1.Cached)(cacheDecoratorOptions),
|
|
232
|
+
__metadata("design:type", Function),
|
|
233
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
234
|
+
__metadata("design:returntype", Promise)
|
|
235
|
+
], Query.prototype, "index", null);
|
|
236
|
+
/**
|
|
237
|
+
* API wrapper around the remoteQuery with backward compatibility support
|
|
238
|
+
* @param remoteQuery
|
|
239
|
+
*/
|
|
240
|
+
function createQuery({ remoteQuery, indexModule, container, }) {
|
|
241
|
+
const query = new Query({
|
|
242
|
+
remoteQuery,
|
|
243
|
+
indexModule,
|
|
244
|
+
container,
|
|
245
|
+
});
|
|
246
|
+
function backwardCompatibleQuery(...args) {
|
|
247
|
+
return query.query.apply(query, args);
|
|
248
|
+
}
|
|
249
|
+
backwardCompatibleQuery.graph = query.graph.bind(query);
|
|
250
|
+
backwardCompatibleQuery.gql = query.gql.bind(query);
|
|
251
|
+
backwardCompatibleQuery.index = query.index.bind(query);
|
|
252
|
+
return backwardCompatibleQuery;
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/remote-query/query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqVA,kCAwBC;AAhWD,2CAOwB;AACxB,iDAA4C;AAC5C,uDAAiD;AAEjD,SAAS,mBAAmB,CAAC,MAAc;IACzC,OAAO,SAAS,UAAU,CAAC,IAAW;QACpC,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,CAAA;IACjC,CAAC,CAAA;AACH,CAAC;AAED,SAAS,cAAc,CAAC,IAAW;IACjC,MAAM,SAAS,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAA;IACrD,IAAI,SAA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jC,CAAC;IACD,eAAe,CAAC,MAAoD;QAClE,0BAAW,CAAC,oBAAoB,GAAG,MAAM,CAAA;IAC3C,CAAC;CACF,AAVgB,CAUhB;AAmGK;IADL,IAAA,cAAM,EAAC,qBAAqB,CAAC;;;;kCA2C7B;AAOK;IADL,IAAA,cAAM,EAAC,qBAAqB,CAAC;;;;kCA4E7B;AAGH;;;GAGG;AACH,SAAgB,WAAW,CAAC,EAC1B,WAAW,EACX,WAAW,EACX,SAAS,GAKV;IACC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC;QACtB,WAAW;QACX,WAAW;QACX,SAAS;KACV,CAAC,CAAA;IAEF,SAAS,uBAAuB,CAAC,GAAG,IAAW;QAC7C,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IACvC,CAAC;IAED,uBAAuB,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACvD,uBAAuB,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACnD,uBAAuB,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAEvD,OAAO,uBAA4D,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { JoinerArgument, JoinerRelationship, LoadedModule, ModuleJoinerConfig, RemoteExpandProperty, RemoteJoinerOptions, RemoteJoinerQuery, RemoteNestedExpands } from "@medusajs/types";
|
|
2
|
+
import { RemoteFetchDataCallback } from "../joiner";
|
|
3
|
+
export declare class RemoteQuery {
|
|
4
|
+
private remoteJoiner;
|
|
5
|
+
private modulesMap;
|
|
6
|
+
private customRemoteFetchData?;
|
|
7
|
+
private entitiesMap;
|
|
8
|
+
static traceFetchRemoteData?: (fetcher: () => Promise<any>, serviceName: string, method: string, options: {
|
|
9
|
+
select?: string[];
|
|
10
|
+
relations: string[];
|
|
11
|
+
}) => Promise<any>;
|
|
12
|
+
constructor({ modulesLoaded, customRemoteFetchData, servicesConfig, entitiesMap, }: {
|
|
13
|
+
modulesLoaded?: LoadedModule[];
|
|
14
|
+
customRemoteFetchData?: RemoteFetchDataCallback;
|
|
15
|
+
servicesConfig?: ModuleJoinerConfig[];
|
|
16
|
+
entitiesMap: Map<string, any>;
|
|
17
|
+
});
|
|
18
|
+
getEntitiesMap(): Map<string, any>;
|
|
19
|
+
setFetchDataCallback(remoteFetchData: (expand: RemoteExpandProperty, keyField: string, ids?: (unknown | unknown[])[], relationship?: any) => Promise<{
|
|
20
|
+
data: unknown[] | {
|
|
21
|
+
[path: string]: unknown[];
|
|
22
|
+
};
|
|
23
|
+
path?: string;
|
|
24
|
+
}>): void;
|
|
25
|
+
static getAllFieldsAndRelations(expand: RemoteExpandProperty | RemoteNestedExpands[number], prefix?: string, args?: JoinerArgument): {
|
|
26
|
+
select?: string[];
|
|
27
|
+
relations: string[];
|
|
28
|
+
args: JoinerArgument;
|
|
29
|
+
take?: number | null;
|
|
30
|
+
};
|
|
31
|
+
private hasPagination;
|
|
32
|
+
private buildPagination;
|
|
33
|
+
private fetchRemoteDataBatched;
|
|
34
|
+
remoteFetchData(expand: RemoteExpandProperty, keyField: string, ids?: (unknown | unknown[])[], relationship?: JoinerRelationship): Promise<{
|
|
35
|
+
data: unknown[] | {
|
|
36
|
+
[path: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
path?: string;
|
|
39
|
+
}>;
|
|
40
|
+
private executeFetchRequest;
|
|
41
|
+
query(query: string | RemoteJoinerQuery | object, variables?: Record<string, unknown>, options?: RemoteJoinerOptions): Promise<any>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=remote-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-query.d.ts","sourceRoot":"","sources":["../../src/remote-query/remote-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAC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AC,GACD,IAAI;WAIO,wBAAwB,CACpC,MAAM,EAAE,oBAAoB,GAAG,mBAAmB,CAAC,MAAM,CAAC,EAC1D,MAAM,SAAc,EACpB,IAAI,GAAE,cAAqC,GAC1C;QACD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;QACjB,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,IAAI,EAAE,cAAc,CAAA;QACpB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACrB;IAwDD,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,eAAe;YAUT,sBAAsB;IAgGvB,eAAe,CAC1B,MAAM,EAAE,oBAAoB,EAC5B,QAAQ,EAAE,MAAM,EAChB,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,OAAO,EAAE,CAAC,EAAE,EAC7B,YAAY,CAAC,EAAE,kBAAkB,GAChC,OAAO,CAAC;QACT,IAAI,EAAE,OAAO,EAAE,GAAG;YAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAA;QAC7C,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAC;YAgBY,mBAAmB;IA2IpB,KAAK,CAChB,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,MAAM,EAC1C,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,GAAG,CAAC;CAWhB"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteQuery = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/utils");
|
|
5
|
+
const joiner_1 = require("../joiner");
|
|
6
|
+
const medusa_module_1 = require("../medusa-module");
|
|
7
|
+
const BASE_PREFIX = "";
|
|
8
|
+
const MAX_BATCH_SIZE = 4000;
|
|
9
|
+
const MAX_CONCURRENT_REQUESTS = 10;
|
|
10
|
+
class RemoteQuery {
|
|
11
|
+
constructor({ modulesLoaded, customRemoteFetchData, servicesConfig = [], entitiesMap, }) {
|
|
12
|
+
this.modulesMap = new Map();
|
|
13
|
+
this.entitiesMap = new Map();
|
|
14
|
+
const servicesConfig_ = [...servicesConfig];
|
|
15
|
+
this.entitiesMap = entitiesMap;
|
|
16
|
+
if (!modulesLoaded?.length) {
|
|
17
|
+
modulesLoaded = medusa_module_1.MedusaModule.getLoadedModules().map((mod) => Object.values(mod)[0]);
|
|
18
|
+
}
|
|
19
|
+
for (const mod of modulesLoaded || []) {
|
|
20
|
+
if (!mod.__definition.isQueryable) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const serviceName = mod.__definition.key;
|
|
24
|
+
if (this.modulesMap.has(serviceName)) {
|
|
25
|
+
throw new Error(`Duplicated instance of module ${serviceName} is not allowed.`);
|
|
26
|
+
}
|
|
27
|
+
this.modulesMap.set(serviceName, mod);
|
|
28
|
+
servicesConfig_.push(mod.__joinerConfig);
|
|
29
|
+
}
|
|
30
|
+
this.customRemoteFetchData = customRemoteFetchData;
|
|
31
|
+
this.remoteJoiner = new joiner_1.RemoteJoiner(servicesConfig_, this.remoteFetchData.bind(this), {
|
|
32
|
+
autoCreateServiceNameAlias: false,
|
|
33
|
+
entitiesMap,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getEntitiesMap() {
|
|
37
|
+
return this.entitiesMap;
|
|
38
|
+
}
|
|
39
|
+
setFetchDataCallback(remoteFetchData) {
|
|
40
|
+
this.remoteJoiner.setFetchDataCallback(remoteFetchData);
|
|
41
|
+
}
|
|
42
|
+
static getAllFieldsAndRelations(expand, prefix = BASE_PREFIX, args = {}) {
|
|
43
|
+
expand = JSON.parse(JSON.stringify(expand));
|
|
44
|
+
let fields = new Set();
|
|
45
|
+
let relations = [];
|
|
46
|
+
let shouldSelectAll = false;
|
|
47
|
+
for (const field of expand.fields ?? []) {
|
|
48
|
+
if (field === "*") {
|
|
49
|
+
shouldSelectAll = true;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
fields.add(prefix ? `${prefix}.${field}` : field);
|
|
53
|
+
}
|
|
54
|
+
const filters = expand.args?.find((arg) => arg.name === "filters")?.value ?? {};
|
|
55
|
+
if ((0, utils_1.isPresent)(filters)) {
|
|
56
|
+
args[prefix] = filters;
|
|
57
|
+
}
|
|
58
|
+
else if ((0, utils_1.isPresent)(expand.args)) {
|
|
59
|
+
args[prefix] = expand.args;
|
|
60
|
+
}
|
|
61
|
+
for (const property in expand.expands ?? {}) {
|
|
62
|
+
const newPrefix = prefix ? `${prefix}.${property}` : property;
|
|
63
|
+
relations.push(newPrefix);
|
|
64
|
+
fields.delete(newPrefix);
|
|
65
|
+
const result = RemoteQuery.getAllFieldsAndRelations(expand.expands[property], newPrefix, args);
|
|
66
|
+
result.select?.forEach(fields.add, fields);
|
|
67
|
+
relations = relations.concat(result.relations);
|
|
68
|
+
}
|
|
69
|
+
const allFields = Array.from(fields);
|
|
70
|
+
const select = allFields.length && !shouldSelectAll
|
|
71
|
+
? allFields
|
|
72
|
+
: shouldSelectAll
|
|
73
|
+
? undefined
|
|
74
|
+
: [];
|
|
75
|
+
return {
|
|
76
|
+
select,
|
|
77
|
+
relations,
|
|
78
|
+
args,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
hasPagination(options) {
|
|
82
|
+
if (!options) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const attrs = ["skip", "cursor"];
|
|
86
|
+
return Object.keys(options).some((key) => attrs.includes(key));
|
|
87
|
+
}
|
|
88
|
+
buildPagination(options, count) {
|
|
89
|
+
return {
|
|
90
|
+
skip: options.skip,
|
|
91
|
+
take: options.take,
|
|
92
|
+
// cursor: options.cursor, not yet supported
|
|
93
|
+
// TODO: next cursor
|
|
94
|
+
count,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async fetchRemoteDataBatched(args) {
|
|
98
|
+
const { serviceName, keyField, service, methodName, filters, options, ids, } = args;
|
|
99
|
+
const getBatch = function* (idArray, batchSize) {
|
|
100
|
+
for (let i = 0; i < idArray.length; i += batchSize) {
|
|
101
|
+
yield idArray.slice(i, i + batchSize);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const idsToFetch = getBatch(ids, MAX_BATCH_SIZE);
|
|
105
|
+
const results = [];
|
|
106
|
+
let running = 0;
|
|
107
|
+
const fetchPromises = [];
|
|
108
|
+
const processBatch = async (batch) => {
|
|
109
|
+
running++;
|
|
110
|
+
const batchFilters = { ...filters, [keyField]: batch };
|
|
111
|
+
let result;
|
|
112
|
+
try {
|
|
113
|
+
if (RemoteQuery.traceFetchRemoteData) {
|
|
114
|
+
result = await RemoteQuery.traceFetchRemoteData(async () => service[methodName](batchFilters, options), serviceName, methodName, options);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
result = await service[methodName](batchFilters, options);
|
|
118
|
+
}
|
|
119
|
+
results.push(result);
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
running--;
|
|
123
|
+
processAllBatches();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
let batchesDone = () => { };
|
|
127
|
+
const awaitBatches = new Promise((ok) => {
|
|
128
|
+
batchesDone = ok;
|
|
129
|
+
});
|
|
130
|
+
const processAllBatches = async () => {
|
|
131
|
+
let isDone = false;
|
|
132
|
+
while (running < MAX_CONCURRENT_REQUESTS) {
|
|
133
|
+
const nextBatch = idsToFetch.next();
|
|
134
|
+
if (nextBatch.done) {
|
|
135
|
+
isDone = true;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
const batch = nextBatch.value;
|
|
139
|
+
fetchPromises.push(processBatch(batch));
|
|
140
|
+
}
|
|
141
|
+
if (isDone) {
|
|
142
|
+
await Promise.all(fetchPromises);
|
|
143
|
+
batchesDone();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
processAllBatches();
|
|
147
|
+
await awaitBatches;
|
|
148
|
+
const flattenedResults = results.reduce((acc, result) => {
|
|
149
|
+
if (Array.isArray(result) &&
|
|
150
|
+
result.length === 2 &&
|
|
151
|
+
Array.isArray(result[0])) {
|
|
152
|
+
return acc.concat(result[0]);
|
|
153
|
+
}
|
|
154
|
+
return acc.concat(result);
|
|
155
|
+
}, []);
|
|
156
|
+
return flattenedResults;
|
|
157
|
+
}
|
|
158
|
+
async remoteFetchData(expand, keyField, ids, relationship) {
|
|
159
|
+
if (this.customRemoteFetchData) {
|
|
160
|
+
const resp = await this.customRemoteFetchData(expand, keyField, ids);
|
|
161
|
+
if (resp !== undefined) {
|
|
162
|
+
return resp;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return this.executeFetchRequest({
|
|
166
|
+
expand,
|
|
167
|
+
keyField,
|
|
168
|
+
ids,
|
|
169
|
+
relationship,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async executeFetchRequest(params) {
|
|
173
|
+
const { expand, keyField, ids, relationship } = params;
|
|
174
|
+
const serviceConfig = expand.serviceConfig;
|
|
175
|
+
const service = this.modulesMap.get(serviceConfig.serviceName);
|
|
176
|
+
let filters = {};
|
|
177
|
+
const options = {
|
|
178
|
+
...RemoteQuery.getAllFieldsAndRelations(expand),
|
|
179
|
+
};
|
|
180
|
+
const availableOptions = [
|
|
181
|
+
"skip",
|
|
182
|
+
"take",
|
|
183
|
+
"limit",
|
|
184
|
+
"offset",
|
|
185
|
+
"cursor",
|
|
186
|
+
"sort",
|
|
187
|
+
"order",
|
|
188
|
+
"withDeleted",
|
|
189
|
+
"options",
|
|
190
|
+
];
|
|
191
|
+
const availableOptionsAlias = new Map([
|
|
192
|
+
["limit", "take"],
|
|
193
|
+
["offset", "skip"],
|
|
194
|
+
]);
|
|
195
|
+
for (const arg of expand.args || []) {
|
|
196
|
+
if (arg.name === "filters" && arg.value) {
|
|
197
|
+
filters = { ...filters, ...arg.value };
|
|
198
|
+
}
|
|
199
|
+
else if (arg.name === "context" && arg.value) {
|
|
200
|
+
filters["context"] = arg.value;
|
|
201
|
+
}
|
|
202
|
+
else if (availableOptions.includes(arg.name)) {
|
|
203
|
+
const argName = availableOptionsAlias.has(arg.name)
|
|
204
|
+
? availableOptionsAlias.get(arg.name)
|
|
205
|
+
: arg.name;
|
|
206
|
+
options[argName] = arg.value;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
delete options.args?.[BASE_PREFIX];
|
|
210
|
+
if (Object.keys(options.args ?? {}).length) {
|
|
211
|
+
filters = {
|
|
212
|
+
...filters,
|
|
213
|
+
...options?.args,
|
|
214
|
+
};
|
|
215
|
+
options.args = {};
|
|
216
|
+
}
|
|
217
|
+
const hasPagination = this.hasPagination(options);
|
|
218
|
+
const isIdsArray = Array.isArray(ids);
|
|
219
|
+
const idsLength = isIdsArray ? ids.length : 1;
|
|
220
|
+
if (ids) {
|
|
221
|
+
if (isIdsArray && !idsLength) {
|
|
222
|
+
if (hasPagination) {
|
|
223
|
+
return {
|
|
224
|
+
data: {
|
|
225
|
+
rows: [],
|
|
226
|
+
metadata: this.buildPagination(options, 0),
|
|
227
|
+
},
|
|
228
|
+
path: "rows",
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
return {
|
|
233
|
+
data: [],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
filters[keyField] = ids;
|
|
238
|
+
}
|
|
239
|
+
let methodName = hasPagination ? "listAndCount" : "list";
|
|
240
|
+
if (relationship?.args?.methodSuffix) {
|
|
241
|
+
methodName += (0, utils_1.toPascalCase)(relationship.args.methodSuffix);
|
|
242
|
+
}
|
|
243
|
+
else if (serviceConfig?.args?.methodSuffix) {
|
|
244
|
+
methodName += (0, utils_1.toPascalCase)(serviceConfig.args.methodSuffix);
|
|
245
|
+
}
|
|
246
|
+
if (typeof service[methodName] !== "function") {
|
|
247
|
+
throw new Error(`Method "${methodName}" does not exist on "${serviceConfig.serviceName}"`);
|
|
248
|
+
}
|
|
249
|
+
if (isIdsArray && idsLength && !hasPagination) {
|
|
250
|
+
options.take = null;
|
|
251
|
+
}
|
|
252
|
+
if (isIdsArray && idsLength >= MAX_BATCH_SIZE && !hasPagination) {
|
|
253
|
+
const data = await this.fetchRemoteDataBatched({
|
|
254
|
+
serviceName: serviceConfig.serviceName,
|
|
255
|
+
keyField,
|
|
256
|
+
service,
|
|
257
|
+
methodName,
|
|
258
|
+
filters,
|
|
259
|
+
options,
|
|
260
|
+
ids,
|
|
261
|
+
});
|
|
262
|
+
return { data };
|
|
263
|
+
}
|
|
264
|
+
let result;
|
|
265
|
+
if (RemoteQuery.traceFetchRemoteData) {
|
|
266
|
+
result = await RemoteQuery.traceFetchRemoteData(async () => service[methodName](filters, options), serviceConfig.serviceName, methodName, options);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
result = await service[methodName](filters, options);
|
|
270
|
+
}
|
|
271
|
+
if (hasPagination) {
|
|
272
|
+
const [data, count] = result;
|
|
273
|
+
return {
|
|
274
|
+
data: {
|
|
275
|
+
rows: data,
|
|
276
|
+
metadata: this.buildPagination(options, count),
|
|
277
|
+
},
|
|
278
|
+
path: "rows",
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
data: result,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
async query(query, variables, options) {
|
|
286
|
+
let finalQuery = query;
|
|
287
|
+
if ((0, utils_1.isString)(query)) {
|
|
288
|
+
finalQuery = joiner_1.RemoteJoiner.parseQuery(query, variables);
|
|
289
|
+
}
|
|
290
|
+
else if (!(0, utils_1.isString)(finalQuery?.service) && !(0, utils_1.isString)(finalQuery?.alias)) {
|
|
291
|
+
finalQuery = (0, joiner_1.toRemoteJoinerQuery)(query, variables);
|
|
292
|
+
}
|
|
293
|
+
return await this.remoteJoiner.query(finalQuery, options);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.RemoteQuery = RemoteQuery;
|
|
297
|
+
//# sourceMappingURL=remote-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-query.js","sourceRoot":"","sources":["../../src/remote-query/remote-query.ts"],"names":[],"mappings":";;;AAWA,2CAAmE;AACnE,sCAIkB;AAClB,oDAA+C;AAE/C,MAAM,WAAW,GAAG,EAAE,CAAA;AACtB,MAAM,cAAc,GAAG,IAAI,CAAA;AAC3B,MAAM,uBAAuB,GAAG,EAAE,CAAA;AAClC,MAAa,WAAW;IAatB,YAAY,EACV,aAAa,EACb,qBAAqB,EACrB,cAAc,GAAG,EAAE,EACnB,WAAW,GAMZ;QArBO,eAAU,GAA8B,IAAI,GAAG,EAAE,CAAA;QAEjD,gBAAW,GAAqB,IAAI,GAAG,EAAE,CAAA;QAoB/C,MAAM,eAAe,GAAG,CAAC,GAAG,cAAc,CAAC,CAAA;QAC3C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAE9B,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC;YAC3B,aAAa,GAAG,4BAAY,CAAC,gBAAgB,EAAE,CAAC,GAAG,CACjD,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAC/B,CAAA;QACH,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,aAAa,IAAI,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;gBAClC,SAAQ;YACV,CAAC;YAED,MAAM,WAAW,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAA;YAExC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBACrC,MAAM,IAAI,KAAK,CACb,iCAAiC,WAAW,kBAAkB,CAC/D,CAAA;YACH,CAAC;YAED,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,C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KAAK,CAChB,KAA0C,EAC1C,SAAmC,EACnC,OAA6B;QAE7B,IAAI,UAAU,GAAsB,KAA0B,CAAA;QAE9D,IAAI,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;YACpB,UAAU,GAAG,qBAAY,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QACxD,CAAC;aAAM,IAAI,CAAC,IAAA,gBAAQ,EAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,IAAA,gBAAQ,EAAC,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;YAC1E,UAAU,GAAG,IAAA,4BAAmB,EAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QACpD,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IAC3D,CAAC;CACF;AAtbD,kCAsbC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RemoteQueryFilters, RemoteQueryGraph, RemoteQueryInput } from "@medusajs/types";
|
|
2
|
+
/**
|
|
3
|
+
* convert a specific API configuration to a remote query object
|
|
4
|
+
*
|
|
5
|
+
* @param config
|
|
6
|
+
* @param entitiesMap
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const remoteQueryObject = toRemoteQuery({
|
|
10
|
+
* entity: "product",
|
|
11
|
+
* fields,
|
|
12
|
+
* filters: { variants: QueryFilter({ sku: "abc" }) },
|
|
13
|
+
* context: {
|
|
14
|
+
* variants: { calculated_price: QueryContext({ region_id: "reg_123" }) }
|
|
15
|
+
* }
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* console.log(remoteQueryObject);
|
|
19
|
+
*/
|
|
20
|
+
export declare function toRemoteQuery<const TEntity extends string>(config: {
|
|
21
|
+
entity: TEntity;
|
|
22
|
+
fields: RemoteQueryInput<TEntity>["fields"];
|
|
23
|
+
filters?: RemoteQueryFilters<TEntity>;
|
|
24
|
+
pagination?: Partial<RemoteQueryInput<TEntity>["pagination"]>;
|
|
25
|
+
context?: Record<string, any>;
|
|
26
|
+
withDeleted?: boolean;
|
|
27
|
+
strategy?: "joined" | "select-in" | "balanced";
|
|
28
|
+
}, entitiesMap: Map<string, any>): RemoteQueryGraph<TEntity>;
|
|
29
|
+
//# sourceMappingURL=to-remote-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-remote-query.d.ts","sourceRoot":"","sources":["../../src/remote-query/to-remote-query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,iBAAiB,CAAA;AAOxB;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,aAAa,CAAC,KAAK,CAAC,OAAO,SAAS,MAAM,EACxD,MAAM,EAAE;IACN,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAA;IAC3C,OAAO,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAA;IACrC,UAAU,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAA;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAA;CAC/C,EACD,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,gBAAgB,CAAC,OAAO,CAAC,CAgH3B"}
|