@graphql-mesh/transport-mongo 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMongoMapping = parseMongoMapping;
4
+ exports.resolveMappingValue = resolveMappingValue;
5
+ exports.columnMapFromSelection = columnMapFromSelection;
6
+ exports.projectionFromSelection = projectionFromSelection;
7
+ exports.mapDocumentToGraphql = mapDocumentToGraphql;
8
+ /**
9
+ * Parse `@mongo` `where` / `set` / `selection` block strings.
10
+ * Skips `# ...` comments to EOL. Supports nested `{ ... }` blocks and `$args` / `$this` / `$pseudo`.
11
+ */
12
+ function parseMongoMapping(source) {
13
+ if (source == null || !String(source).trim()) {
14
+ return { entries: [] };
15
+ }
16
+ const text = stripComments(String(source));
17
+ const { entries, next } = parseBlock(text, 0, false);
18
+ if (next < text.length && text.slice(next).trim()) {
19
+ throw new Error(`Unexpected trailing content in Mongo mapping: ${text.slice(next, next + 40)}`);
20
+ }
21
+ return { entries };
22
+ }
23
+ function resolveMappingValue(value, ctx) {
24
+ if (!value)
25
+ return undefined;
26
+ switch (value.kind) {
27
+ case 'literal':
28
+ return value.value;
29
+ case 'column':
30
+ return value.value;
31
+ case 'pseudo':
32
+ return ctx.literals?.[value.value];
33
+ case 'args': {
34
+ return getPath(ctx.args, value.path || [value.value]);
35
+ }
36
+ case 'this': {
37
+ return getPath(ctx.parent, value.path || [value.value]);
38
+ }
39
+ default:
40
+ return undefined;
41
+ }
42
+ }
43
+ function columnMapFromSelection(parsed) {
44
+ const map = new Map();
45
+ for (const entry of parsed.entries) {
46
+ if (entry.children || entry.spread)
47
+ continue;
48
+ if (entry.value?.kind === 'column') {
49
+ map.set(entry.key, entry.value.value);
50
+ }
51
+ }
52
+ return map;
53
+ }
54
+ /** Build a Mongo projection `{ path: 1 }` from selection column mappings. */
55
+ function projectionFromSelection(parsed) {
56
+ const projection = {};
57
+ collectProjection(parsed.entries, projection);
58
+ return projection;
59
+ }
60
+ function collectProjection(entries, out) {
61
+ for (const entry of entries) {
62
+ if (entry.spread)
63
+ continue;
64
+ if (entry.children) {
65
+ collectProjection(entry.children, out);
66
+ continue;
67
+ }
68
+ if (entry.value?.kind === 'column') {
69
+ out[entry.value.value] = 1;
70
+ }
71
+ }
72
+ }
73
+ /**
74
+ * Map a Mongo document to GraphQL fields via selection.
75
+ * Nested blocks become nested objects; lists of subdocs pass through for now.
76
+ */
77
+ function mapDocumentToGraphql(doc, selection) {
78
+ if (doc == null)
79
+ return null;
80
+ const out = {};
81
+ for (const entry of selection.entries) {
82
+ if (entry.spread)
83
+ continue;
84
+ if (entry.key === '$' || entry.value?.kind === 'pseudo')
85
+ continue;
86
+ if (entry.children) {
87
+ out[entry.key] = mapDocumentToGraphql(doc, { entries: entry.children });
88
+ continue;
89
+ }
90
+ if (entry.value?.kind === 'column') {
91
+ out[entry.key] = coerceGraphqlValue(getPath(doc, entry.value.value.split('.')));
92
+ }
93
+ }
94
+ return out;
95
+ }
96
+ /** graphql-scalars ObjectID serialize expects a 24-char hex string, not a driver ObjectId. */
97
+ function coerceGraphqlValue(value) {
98
+ if (value == null)
99
+ return value;
100
+ if (typeof value === 'object' && value !== null && 'toHexString' in value) {
101
+ try {
102
+ return value.toHexString();
103
+ }
104
+ catch {
105
+ return value;
106
+ }
107
+ }
108
+ return value;
109
+ }
110
+ function stripComments(source) {
111
+ return source
112
+ .split('\n')
113
+ .map(line => {
114
+ let inQuote = null;
115
+ for (let i = 0; i < line.length; i++) {
116
+ const c = line[i];
117
+ if (inQuote) {
118
+ if (c === '\\') {
119
+ i++;
120
+ continue;
121
+ }
122
+ if (c === inQuote)
123
+ inQuote = null;
124
+ continue;
125
+ }
126
+ if (c === '"' || c === "'") {
127
+ inQuote = c;
128
+ continue;
129
+ }
130
+ if (c === '#') {
131
+ return line.slice(0, i);
132
+ }
133
+ }
134
+ return line;
135
+ })
136
+ .join('\n');
137
+ }
138
+ function parseBlock(text, start, expectClosing) {
139
+ const entries = [];
140
+ let i = skipWs(text, start);
141
+ while (i < text.length) {
142
+ if (text[i] === '}') {
143
+ if (!expectClosing) {
144
+ throw new Error(`Unexpected "}" in Mongo mapping at ${i}`);
145
+ }
146
+ return { entries, next: i + 1 };
147
+ }
148
+ if (text.startsWith('...', i)) {
149
+ const afterDots = skipWs(text, i + 3);
150
+ if (afterDots >= text.length || text[afterDots] !== '$') {
151
+ throw new Error(`Expected "$" after "..." in Mongo mapping at ${i}`);
152
+ }
153
+ const rhs = readPseudoOrPath(text, afterDots);
154
+ if (rhs.value.kind !== 'args' && rhs.value.kind !== 'this') {
155
+ throw new Error(`Spread target must be $args / $this path, got ${rhs.raw}`);
156
+ }
157
+ entries.push({
158
+ key: `...${rhs.raw}`,
159
+ value: rhs.value,
160
+ spread: true,
161
+ });
162
+ i = skipWs(text, rhs.next);
163
+ continue;
164
+ }
165
+ if (text[i] === '$') {
166
+ const pseudo = readPseudoOrPath(text, i);
167
+ entries.push({
168
+ key: pseudo.raw,
169
+ value: pseudo.value,
170
+ });
171
+ i = skipWs(text, pseudo.next);
172
+ continue;
173
+ }
174
+ const key = readIdent(text, i);
175
+ i = skipWs(text, key.next);
176
+ if (i < text.length && text[i] === '{') {
177
+ const nested = parseBlock(text, i + 1, true);
178
+ entries.push({ key: key.value, children: nested.entries });
179
+ i = skipWs(text, nested.next);
180
+ continue;
181
+ }
182
+ if (i >= text.length || text[i] !== ':') {
183
+ entries.push({
184
+ key: key.value,
185
+ value: { kind: 'column', value: key.value },
186
+ });
187
+ continue;
188
+ }
189
+ i = skipWs(text, i + 1);
190
+ if (i < text.length && text[i] === '{') {
191
+ const nested = parseBlock(text, i + 1, true);
192
+ entries.push({ key: key.value, children: nested.entries });
193
+ i = skipWs(text, nested.next);
194
+ continue;
195
+ }
196
+ if (i < text.length && text[i] === '$') {
197
+ const rhs = readPseudoOrPath(text, i);
198
+ entries.push({ key: key.value, value: rhs.value });
199
+ i = skipWs(text, rhs.next);
200
+ continue;
201
+ }
202
+ if (i < text.length && (text[i] === '"' || text[i] === "'")) {
203
+ const lit = readQuoted(text, i);
204
+ entries.push({
205
+ key: key.value,
206
+ value: { kind: 'literal', value: lit.value },
207
+ });
208
+ i = skipWs(text, lit.next);
209
+ continue;
210
+ }
211
+ const col = readPathIdent(text, i);
212
+ entries.push({
213
+ key: key.value,
214
+ value: { kind: 'column', value: col.value },
215
+ });
216
+ i = skipWs(text, col.next);
217
+ }
218
+ if (expectClosing) {
219
+ throw new Error('Unclosed "{" in Mongo mapping');
220
+ }
221
+ return { entries, next: i };
222
+ }
223
+ function readPseudoOrPath(text, start) {
224
+ if (text[start] !== '$') {
225
+ throw new Error(`Expected "$" at ${start}`);
226
+ }
227
+ // bare `$`
228
+ if (start + 1 >= text.length || !isIdentStart(text[start + 1] ?? '')) {
229
+ return {
230
+ raw: '$',
231
+ value: { kind: 'pseudo', value: '$' },
232
+ next: start + 1,
233
+ };
234
+ }
235
+ const path = readDottedPath(text, start + 1);
236
+ const raw = `$${path.value}`;
237
+ const segments = path.value.split('.');
238
+ const head = segments[0];
239
+ if (head === 'args') {
240
+ return {
241
+ raw,
242
+ value: { kind: 'args', value: segments.slice(1).join('.') || 'args', path: segments.slice(1) },
243
+ next: path.next,
244
+ };
245
+ }
246
+ if (head === 'this') {
247
+ return {
248
+ raw,
249
+ value: { kind: 'this', value: segments.slice(1).join('.') || 'this', path: segments.slice(1) },
250
+ next: path.next,
251
+ };
252
+ }
253
+ return {
254
+ raw,
255
+ value: { kind: 'pseudo', value: path.value },
256
+ next: path.next,
257
+ };
258
+ }
259
+ function readIdent(text, start) {
260
+ if (!isIdentStart(text[start] ?? '')) {
261
+ throw new Error(`Expected identifier at ${start}`);
262
+ }
263
+ let i = start + 1;
264
+ while (i < text.length && isIdentPart(text[i]))
265
+ i++;
266
+ return { value: text.slice(start, i), next: i };
267
+ }
268
+ /** Ident or dotted mongo path (`address.street`). */
269
+ function readPathIdent(text, start) {
270
+ return readDottedPath(text, start);
271
+ }
272
+ function readDottedPath(text, start) {
273
+ const first = readIdent(text, start);
274
+ let value = first.value;
275
+ let i = first.next;
276
+ while (i < text.length && text[i] === '.') {
277
+ i++;
278
+ const next = readIdent(text, i);
279
+ value += `.${next.value}`;
280
+ i = next.next;
281
+ }
282
+ return { value, next: i };
283
+ }
284
+ function readQuoted(text, start) {
285
+ const quote = text[start];
286
+ let i = start + 1;
287
+ let out = '';
288
+ while (i < text.length) {
289
+ const c = text[i];
290
+ if (c === '\\') {
291
+ out += text[i + 1] ?? '';
292
+ i += 2;
293
+ continue;
294
+ }
295
+ if (c === quote) {
296
+ return { value: out, next: i + 1 };
297
+ }
298
+ out += c;
299
+ i++;
300
+ }
301
+ throw new Error('Unclosed string in Mongo mapping');
302
+ }
303
+ function skipWs(text, start) {
304
+ let i = start;
305
+ while (i < text.length && /\s/.test(text[i]))
306
+ i++;
307
+ return i;
308
+ }
309
+ function isIdentStart(c) {
310
+ const code = c.charCodeAt(0);
311
+ return ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code === 95 /* _ */);
312
+ }
313
+ function isIdentPart(c) {
314
+ const code = c.charCodeAt(0);
315
+ return ((code >= 65 && code <= 90) ||
316
+ (code >= 97 && code <= 122) ||
317
+ (code >= 48 && code <= 57) ||
318
+ code === 95);
319
+ }
320
+ function getPath(obj, path) {
321
+ let cur = obj;
322
+ for (const seg of path) {
323
+ if (cur == null || typeof cur !== 'object')
324
+ return undefined;
325
+ cur = cur[seg];
326
+ }
327
+ return cur;
328
+ }
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
File without changes
@@ -0,0 +1,85 @@
1
+ import { MongoClient } from 'mongodb';
2
+ export function createMongoClient(opts) {
3
+ const client = new MongoClient(opts.location, {
4
+ maxPoolSize: opts.maxPoolSize,
5
+ });
6
+ let dbPromise;
7
+ async function getDb() {
8
+ if (!dbPromise) {
9
+ dbPromise = client.connect().then(() => client.db());
10
+ }
11
+ return dbPromise;
12
+ }
13
+ return {
14
+ async findOne(collection, filter, options) {
15
+ const db = await getDb();
16
+ return db.collection(collection).findOne(filter, {
17
+ projection: options?.projection,
18
+ sort: options?.sort,
19
+ });
20
+ },
21
+ async findMany(collection, filter, options) {
22
+ const db = await getDb();
23
+ let cursor = db.collection(collection).find(filter, {
24
+ projection: options?.projection,
25
+ sort: options?.sort,
26
+ });
27
+ if (options?.skip != null)
28
+ cursor = cursor.skip(options.skip);
29
+ if (options?.limit != null)
30
+ cursor = cursor.limit(options.limit);
31
+ return cursor.toArray();
32
+ },
33
+ async count(collection, filter) {
34
+ const db = await getDb();
35
+ return db.collection(collection).countDocuments(filter);
36
+ },
37
+ async insertOne(collection, doc) {
38
+ const db = await getDb();
39
+ const result = await db.collection(collection).insertOne(doc);
40
+ return { insertedId: result.insertedId };
41
+ },
42
+ async insertMany(collection, docs) {
43
+ const db = await getDb();
44
+ const result = await db.collection(collection).insertMany(docs);
45
+ return {
46
+ insertedIds: Object.values(result.insertedIds),
47
+ insertedCount: result.insertedCount,
48
+ };
49
+ },
50
+ async updateOne(collection, filter, update) {
51
+ const db = await getDb();
52
+ const result = await db.collection(collection).updateOne(filter, update);
53
+ return {
54
+ matchedCount: result.matchedCount,
55
+ modifiedCount: result.modifiedCount,
56
+ upsertedId: result.upsertedId ?? undefined,
57
+ };
58
+ },
59
+ async updateMany(collection, filter, update) {
60
+ const db = await getDb();
61
+ const result = await db.collection(collection).updateMany(filter, update);
62
+ return {
63
+ matchedCount: result.matchedCount,
64
+ modifiedCount: result.modifiedCount,
65
+ };
66
+ },
67
+ async deleteOne(collection, filter) {
68
+ const db = await getDb();
69
+ const result = await db.collection(collection).deleteOne(filter);
70
+ return { deletedCount: result.deletedCount ?? 0 };
71
+ },
72
+ async deleteMany(collection, filter) {
73
+ const db = await getDb();
74
+ const result = await db.collection(collection).deleteMany(filter);
75
+ return { deletedCount: result.deletedCount ?? 0 };
76
+ },
77
+ async aggregate(collection, pipeline) {
78
+ const db = await getDb();
79
+ return db.collection(collection).aggregate(pipeline).toArray();
80
+ },
81
+ async dispose() {
82
+ await client.close();
83
+ },
84
+ };
85
+ }
@@ -0,0 +1,236 @@
1
+ import { createDefaultExecutor } from '@graphql-mesh/transport-common';
2
+ import { getDirective, MapperKind, mapSchema } from '@graphql-tools/utils';
3
+ import { DisposableSymbols } from '@whatwg-node/disposablestack';
4
+ import { createMongoClient } from './client.js';
5
+ import { buildMongoFilter, buildMongoSort, buildSetDocument, coerceFilterValue, } from './filter.js';
6
+ import { mapDocumentToGraphql, parseMongoMapping, projectionFromSelection, resolveMappingValue, } from './mapping.js';
7
+ export function getMongoExecutor({ subgraph, client }) {
8
+ const transportDirectives = getDirective(subgraph, subgraph, 'transport');
9
+ if (!transportDirectives?.length && !client) {
10
+ throw new Error('No @transport directive found on schema definition');
11
+ }
12
+ const transport = transportDirectives?.[0];
13
+ const mongoClient = client ||
14
+ createMongoClient({
15
+ location: transport.location,
16
+ ...(transport?.options || {}),
17
+ });
18
+ const executable = mapSchema(subgraph, {
19
+ [MapperKind.OBJECT_FIELD](fieldConfig) {
20
+ const mongoDirs = getDirective(subgraph, fieldConfig, 'mongo');
21
+ if (!mongoDirs?.length)
22
+ return fieldConfig;
23
+ return attachMongoResolver(fieldConfig, mongoDirs[0], mongoClient);
24
+ },
25
+ });
26
+ const defaultExecutor = createDefaultExecutor(executable);
27
+ const disposable = defaultExecutor;
28
+ disposable[DisposableSymbols.asyncDispose] = async () => {
29
+ await mongoClient.dispose();
30
+ };
31
+ return disposable;
32
+ }
33
+ function attachMongoResolver(fieldConfig, directive, client) {
34
+ const selection = parseMongoMapping(directive.selection);
35
+ const projection = projectionFromSelection(selection);
36
+ const filterSource = directive.filter ?? directive.where;
37
+ fieldConfig.resolve = async function mongoResolver(parent, graphqlArgs) {
38
+ const ctx = { args: graphqlArgs, parent };
39
+ const filter = buildMongoFilter(filterSource, ctx);
40
+ const sort = buildMongoSort(directive.sort, ctx);
41
+ const proj = Object.keys(projection).length ? projection : undefined;
42
+ switch (directive.kind) {
43
+ case 'FIND_ONE': {
44
+ const doc = await client.findOne(directive.collection, filter, {
45
+ projection: proj,
46
+ sort,
47
+ skip: resolveBinderNumber(directive.skip, ctx),
48
+ });
49
+ return mapDocumentToGraphql(doc, selection);
50
+ }
51
+ case 'FIND_MANY': {
52
+ const docs = await client.findMany(directive.collection, filter, {
53
+ projection: proj,
54
+ sort,
55
+ limit: resolveBinderNumber(directive.limit, ctx),
56
+ skip: resolveBinderNumber(directive.skip, ctx),
57
+ });
58
+ return docs.map(doc => mapDocumentToGraphql(doc, selection));
59
+ }
60
+ case 'COUNT':
61
+ return client.count(directive.collection, filter);
62
+ case 'CONNECTION':
63
+ return resolveConnection(client, directive, filter, sort, proj, ctx, selection);
64
+ case 'PAGINATION':
65
+ return resolvePagination(client, directive, filter, sort, proj, ctx, selection);
66
+ case 'INSERT_ONE': {
67
+ const doc = buildSetDocument(directive.set, ctx);
68
+ const { insertedId } = await client.insertOne(directive.collection, doc);
69
+ const created = await client.findOne(directive.collection, { _id: insertedId });
70
+ return mapPayload(created, insertedId, selection);
71
+ }
72
+ case 'INSERT_MANY': {
73
+ const records = (graphqlArgs.records || []);
74
+ const { insertedIds, insertedCount } = await client.insertMany(directive.collection, records);
75
+ const docs = await client.findMany(directive.collection, {
76
+ _id: { $in: insertedIds },
77
+ });
78
+ return {
79
+ records: docs.map(d => mapDocumentToGraphql(d, nestedSelection(selection, 'records'))),
80
+ recordIds: insertedIds.map(id => String(id)),
81
+ createdCount: insertedCount,
82
+ };
83
+ }
84
+ case 'UPDATE_ONE': {
85
+ const setDoc = buildSetDocument(directive.set, ctx);
86
+ await client.updateOne(directive.collection, filter, { $set: setDoc });
87
+ const updated = await client.findOne(directive.collection, filter);
88
+ return mapPayload(updated, updated?._id, selection);
89
+ }
90
+ case 'UPDATE_MANY': {
91
+ const setDoc = buildSetDocument(directive.set, ctx);
92
+ const result = await client.updateMany(directive.collection, filter, { $set: setDoc });
93
+ return {
94
+ matchedCount: result.matchedCount,
95
+ modifiedCount: result.modifiedCount,
96
+ };
97
+ }
98
+ case 'DELETE_ONE': {
99
+ const existing = await client.findOne(directive.collection, filter);
100
+ await client.deleteOne(directive.collection, filter);
101
+ return mapPayload(existing, existing?._id, selection);
102
+ }
103
+ case 'DELETE_MANY': {
104
+ const result = await client.deleteMany(directive.collection, filter);
105
+ return { deletedCount: result.deletedCount };
106
+ }
107
+ case 'AGGREGATE': {
108
+ const pipeline = resolvePipeline(directive.pipeline, ctx, filter);
109
+ const rows = await client.aggregate(directive.collection, pipeline);
110
+ return rows.map(doc => mapDocumentToGraphql(doc, selection));
111
+ }
112
+ default:
113
+ throw new Error(`@mongo kind ${directive.kind} is not implemented`);
114
+ }
115
+ };
116
+ return fieldConfig;
117
+ }
118
+ async function resolveConnection(client, directive, filter, sort, projection, ctx, selection) {
119
+ const first = resolveBinderNumber(directive.first, ctx) ?? 10;
120
+ const after = resolveBinderString(directive.after, ctx);
121
+ const connFilter = { ...filter };
122
+ if (after) {
123
+ connFilter._id = {
124
+ ...(typeof connFilter._id === 'object' && connFilter._id ? connFilter._id : {}),
125
+ $gt: coerceFilterValue(after),
126
+ };
127
+ }
128
+ const docs = await client.findMany(directive.collection, connFilter, {
129
+ projection,
130
+ sort: sort || { _id: 1 },
131
+ limit: first + 1,
132
+ });
133
+ const hasNextPage = docs.length > first;
134
+ const pageDocs = hasNextPage ? docs.slice(0, first) : docs;
135
+ const totalCount = await client.count(directive.collection, filter);
136
+ const nodesSel = nestedSelection(selection, 'nodes');
137
+ const nodes = pageDocs.map(d => mapDocumentToGraphql(d, nodesSel));
138
+ const edges = pageDocs.map(d => ({
139
+ cursor: String(d._id),
140
+ node: mapDocumentToGraphql(d, nestedSelection(nestedSelection(selection, 'edges'), 'node')),
141
+ }));
142
+ return {
143
+ nodes,
144
+ edges,
145
+ pageInfo: {
146
+ hasNextPage,
147
+ hasPreviousPage: Boolean(after),
148
+ startCursor: edges[0]?.cursor ?? null,
149
+ endCursor: edges[edges.length - 1]?.cursor ?? null,
150
+ },
151
+ totalCount,
152
+ };
153
+ }
154
+ async function resolvePagination(client, directive, filter, sort, projection, ctx, selection) {
155
+ const page = Math.max(1, resolveBinderNumber(directive.page, ctx) ?? 1);
156
+ const perPage = Math.max(1, resolveBinderNumber(directive.perPage, ctx) ?? 20);
157
+ const itemCount = await client.count(directive.collection, filter);
158
+ const pageCount = Math.ceil(itemCount / perPage) || 0;
159
+ const docs = await client.findMany(directive.collection, filter, {
160
+ projection,
161
+ sort,
162
+ skip: (page - 1) * perPage,
163
+ limit: perPage,
164
+ });
165
+ const itemsSel = nestedSelection(selection, 'items');
166
+ return {
167
+ count: docs.length,
168
+ items: docs.map(d => mapDocumentToGraphql(d, itemsSel)),
169
+ pageInfo: {
170
+ currentPage: page,
171
+ perPage,
172
+ pageCount,
173
+ itemCount,
174
+ hasNextPage: page < pageCount,
175
+ hasPreviousPage: page > 1,
176
+ },
177
+ };
178
+ }
179
+ function mapPayload(doc, id, selection) {
180
+ const recordSel = nestedSelection(selection, 'record');
181
+ return {
182
+ record: mapDocumentToGraphql(doc, recordSel.entries.length ? recordSel : selection),
183
+ recordId: id != null ? String(id) : null,
184
+ };
185
+ }
186
+ function nestedSelection(selection, key) {
187
+ const entry = selection.entries.find(e => e.key === key);
188
+ return { entries: entry?.children || [] };
189
+ }
190
+ function resolvePipeline(pipelineSource, ctx, filter) {
191
+ if (!pipelineSource || !pipelineSource.trim()) {
192
+ return Object.keys(filter).length ? [{ $match: filter }] : [];
193
+ }
194
+ const trimmed = pipelineSource.trim();
195
+ if (trimmed.startsWith('[')) {
196
+ try {
197
+ const parsed = JSON.parse(trimmed);
198
+ return parsed.map(stage => {
199
+ if (stage.$match === '$args.filter' || stage.$match === '$filter') {
200
+ return { $match: filter };
201
+ }
202
+ return stage;
203
+ });
204
+ }
205
+ catch {
206
+ // fall through
207
+ }
208
+ }
209
+ // Mapping-style: treat as match binder only
210
+ const fromMapping = buildMongoFilter(pipelineSource, ctx);
211
+ return Object.keys(fromMapping).length ? [{ $match: fromMapping }] : [{ $match: filter }];
212
+ }
213
+ function resolveBinderNumber(source, ctx) {
214
+ if (!source)
215
+ return undefined;
216
+ const parsed = parseMongoMapping(source);
217
+ if (parsed.entries.length === 1 && parsed.entries[0].value) {
218
+ const val = resolveMappingValue(parsed.entries[0].value, ctx);
219
+ if (typeof val === 'number')
220
+ return val;
221
+ if (typeof val === 'string' && val.trim() !== '')
222
+ return Number(val);
223
+ }
224
+ return undefined;
225
+ }
226
+ function resolveBinderString(source, ctx) {
227
+ if (!source)
228
+ return undefined;
229
+ const parsed = parseMongoMapping(source);
230
+ if (parsed.entries.length === 1 && parsed.entries[0].value) {
231
+ const val = resolveMappingValue(parsed.entries[0].value, ctx);
232
+ if (typeof val === 'string')
233
+ return val;
234
+ }
235
+ return undefined;
236
+ }