@x12i/reportic-adapter-mongo 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/index.d.ts +10 -0
- package/dist/index.js +303 -0
- package/dist/index.js.map +1 -0
- package/package.json +30 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Reportic contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @x12i/reportic-adapter-mongo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Scoped read-only MongoDB dataset adapter.
|
|
4
|
+
|
|
5
|
+
ESM package with TypeScript declarations. Requires Node.js 22 or later; Reportic format 0.2 and compatible Reportic 0.2.x workspace packages.
|
|
6
|
+
|
|
7
|
+
See the Reportic workspace README and docs/studio.md for setup, SDK examples, the editor, catalog, host identity integration, CLI, HTTP, MCP, and operational limits.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MongoClient } from 'mongodb';
|
|
2
|
+
import { AdapterContext, DatasetAdapter } from '@x12i/reportic-datasets';
|
|
3
|
+
|
|
4
|
+
interface MongoTransport {
|
|
5
|
+
openMongo(context: AdapterContext): Promise<MongoClient>;
|
|
6
|
+
}
|
|
7
|
+
declare function normalizeBson(value: unknown, depth?: number): unknown;
|
|
8
|
+
declare const mongoAdapter: DatasetAdapter;
|
|
9
|
+
|
|
10
|
+
export { type MongoTransport, mongoAdapter, normalizeBson };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// packages/reportic-adapter-mongo/src/index.ts
|
|
2
|
+
import { MongoClient, ObjectId, Long, Decimal128, Binary, Timestamp } from "mongodb";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { isObject } from "@x12i/reportic-catalog/schema";
|
|
5
|
+
import { datasetError, checkJson } from "@x12i/reportic-datasets";
|
|
6
|
+
import { approvedEndpoint, authorizedAddress, deadlineSignal } from "@x12i/reportic-adapter-api";
|
|
7
|
+
var fieldName = z.string().regex(/^[A-Za-z_][\w-]*(?:\.[A-Za-z_][\w-]*)*$/).max(200);
|
|
8
|
+
var settings = z.object({
|
|
9
|
+
database: z.string().regex(/^[A-Za-z_][\w-]{0,63}$/),
|
|
10
|
+
collection: z.string().regex(/^[A-Za-z_][\w-]{0,119}$/),
|
|
11
|
+
kind: z.enum(["find", "countDocuments", "estimatedDocumentCount", "aggregate"]),
|
|
12
|
+
filter: z.record(z.unknown()).optional(),
|
|
13
|
+
projection: z.record(fieldName, z.union([z.literal(0), z.literal(1)])).optional(),
|
|
14
|
+
sort: z.record(fieldName, z.union([z.literal(1), z.literal(-1)])).optional(),
|
|
15
|
+
pipeline: z.array(z.record(z.unknown())).min(1).max(30).optional(),
|
|
16
|
+
batchSize: z.number().int().min(1).max(1e3).default(100),
|
|
17
|
+
operandTypes: z.record(z.enum(["dateTime", "objectId", "int64", "decimal"])).optional(),
|
|
18
|
+
keyType: z.enum(["objectId", "int64"]).optional()
|
|
19
|
+
}).strict();
|
|
20
|
+
var filters = /* @__PURE__ */ new Set(["$and", "$or", "$nor", "$not", "$eq", "$ne", "$gt", "$gte", "$lt", "$lte", "$in", "$nin", "$exists", "$type", "$size", "$elemMatch", "$all"]);
|
|
21
|
+
var stages = /* @__PURE__ */ new Set(["$match", "$project", "$group", "$sort", "$limit", "$skip", "$unwind", "$count", "$facet", "$addFields", "$set", "$unset", "$bucket"]);
|
|
22
|
+
var expressions = /* @__PURE__ */ new Set([
|
|
23
|
+
"$sum",
|
|
24
|
+
"$avg",
|
|
25
|
+
"$min",
|
|
26
|
+
"$max",
|
|
27
|
+
"$count",
|
|
28
|
+
"$first",
|
|
29
|
+
"$last",
|
|
30
|
+
"$push",
|
|
31
|
+
"$addToSet",
|
|
32
|
+
"$literal",
|
|
33
|
+
"$ifNull",
|
|
34
|
+
"$cond",
|
|
35
|
+
"$eq",
|
|
36
|
+
"$ne",
|
|
37
|
+
"$gt",
|
|
38
|
+
"$gte",
|
|
39
|
+
"$lt",
|
|
40
|
+
"$lte",
|
|
41
|
+
"$and",
|
|
42
|
+
"$or",
|
|
43
|
+
"$not",
|
|
44
|
+
"$toString",
|
|
45
|
+
"$add",
|
|
46
|
+
"$subtract",
|
|
47
|
+
"$multiply",
|
|
48
|
+
"$divide",
|
|
49
|
+
"$round",
|
|
50
|
+
"$dateTrunc",
|
|
51
|
+
"$dateToString",
|
|
52
|
+
"$concat",
|
|
53
|
+
"$size"
|
|
54
|
+
]);
|
|
55
|
+
function inspectTemplate(value, allowed, operands, depth = 0) {
|
|
56
|
+
if (depth > 25) throw datasetError("INVALID_MONGO_OPERATION", "plan", "The MongoDB expression is nested too deeply.");
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
value.forEach((child) => inspectTemplate(child, allowed, operands, depth + 1));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!isObject(value)) return;
|
|
62
|
+
if (Object.hasOwn(value, "$operand")) {
|
|
63
|
+
if (allowed !== filters || Object.keys(value).length !== 1 || typeof value.$operand !== "string") {
|
|
64
|
+
throw datasetError("INVALID_MONGO_OPERAND", "plan", "Place parameters only in approved filter operand positions.");
|
|
65
|
+
}
|
|
66
|
+
operands.add(value.$operand);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const [key, child] of Object.entries(value)) {
|
|
70
|
+
if (key.startsWith("$") && !allowed.has(key)) throw datasetError("UNSAFE_MONGO_OPERATOR", "plan", "The MongoDB operation contains a restricted operator.");
|
|
71
|
+
inspectTemplate(child, allowed, operands, depth + 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function inspectPipeline(pipeline, operands, depth = 0) {
|
|
75
|
+
if (depth > 4 || pipeline.length > 30) throw datasetError("INVALID_MONGO_PIPELINE", "plan", "The MongoDB pipeline exceeds its stage or nesting limit.");
|
|
76
|
+
for (const stage of pipeline) {
|
|
77
|
+
if (!isObject(stage) || Object.keys(stage).length !== 1) throw datasetError("INVALID_MONGO_PIPELINE", "plan", "Every pipeline entry must have one approved stage.");
|
|
78
|
+
const [kind, input] = Object.entries(stage)[0];
|
|
79
|
+
if (!stages.has(kind)) throw datasetError("UNSAFE_MONGO_STAGE", "plan", "The pipeline uses a write, cross-collection or unsupported stage.");
|
|
80
|
+
if (kind === "$facet") {
|
|
81
|
+
if (!isObject(input) || Object.keys(input).length > 12) throw datasetError("INVALID_MONGO_PIPELINE", "plan", "A facet needs named, bounded branches.");
|
|
82
|
+
for (const branch of Object.values(input)) {
|
|
83
|
+
if (!Array.isArray(branch)) throw datasetError("INVALID_MONGO_PIPELINE", "plan", "Each facet branch must be a pipeline.");
|
|
84
|
+
inspectPipeline(branch, operands, depth + 1);
|
|
85
|
+
}
|
|
86
|
+
} else inspectTemplate(input, kind === "$match" ? filters : expressions, operands);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function operationConfig(operation) {
|
|
90
|
+
const parsed = settings.safeParse(operation.configuration);
|
|
91
|
+
if (!parsed.success) throw datasetError("INVALID_MONGO_OPERATION", "plan", "Select an approved database, collection and read operation.");
|
|
92
|
+
return parsed.data;
|
|
93
|
+
}
|
|
94
|
+
function bsonOperand(value, type) {
|
|
95
|
+
if (Array.isArray(value)) {
|
|
96
|
+
if (value.length > 200 || value.some(Array.isArray)) throw datasetError("INVALID_MONGO_OPERAND", "request", "A filter list is too large or nested.");
|
|
97
|
+
return value.map((item) => bsonOperand(item, type));
|
|
98
|
+
}
|
|
99
|
+
if (value === null && !type) return null;
|
|
100
|
+
if (typeof value !== "string" && typeof value !== "boolean" && (typeof value !== "number" || !Number.isFinite(value) || Number.isInteger(value) && !Number.isSafeInteger(value))) {
|
|
101
|
+
throw datasetError("INVALID_MONGO_OPERAND", "request", "A filter operand must be a scalar or a bounded scalar list.");
|
|
102
|
+
}
|
|
103
|
+
if (!type) return value;
|
|
104
|
+
try {
|
|
105
|
+
if (type === "dateTime" && typeof value === "string" && /^\d{4}-\d\d-\d\dT/.test(value) && Number.isFinite(Date.parse(value))) return new Date(value);
|
|
106
|
+
if (type === "objectId" && typeof value === "string" && /^[a-f\d]{24}$/i.test(value)) return new ObjectId(value);
|
|
107
|
+
if (type === "int64" && typeof value === "string" && /^-?\d{1,19}$/.test(value) && BigInt(value) >= -9223372036854775808n && BigInt(value) <= 9223372036854775807n) return Long.fromString(value);
|
|
108
|
+
if (type === "decimal" && typeof value === "string" && /^[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/.test(value) && value.length <= 128) return Decimal128.fromString(value);
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
throw datasetError("INVALID_MONGO_OPERAND", "request", "The filter value does not match the approved BSON type.");
|
|
112
|
+
}
|
|
113
|
+
function bindOperands(value, inputs, types) {
|
|
114
|
+
if (Array.isArray(value)) return value.map((item) => bindOperands(item, inputs, types));
|
|
115
|
+
if (!isObject(value)) return value;
|
|
116
|
+
if (Object.hasOwn(value, "$operand")) {
|
|
117
|
+
const name = String(value.$operand);
|
|
118
|
+
if (!Object.hasOwn(inputs, name)) throw datasetError("INVALID_MONGO_OPERAND", "request", "A required filter operand is missing.");
|
|
119
|
+
return bsonOperand(inputs[name], types[name]);
|
|
120
|
+
}
|
|
121
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, bindOperands(child, inputs, types)]));
|
|
122
|
+
}
|
|
123
|
+
function normalizeBson(value, depth = 0) {
|
|
124
|
+
if (depth > 32) throw datasetError("SOURCE_LIMIT_REACHED", "mapping", "The MongoDB document is nested too deeply.");
|
|
125
|
+
if (value instanceof ObjectId) return value.toHexString();
|
|
126
|
+
if (value instanceof Timestamp) return value.toString();
|
|
127
|
+
if (value instanceof Long || value instanceof Decimal128 || typeof value === "bigint") return value.toString();
|
|
128
|
+
if (value instanceof Date) return value.toISOString();
|
|
129
|
+
if (value instanceof Binary) return Buffer.from(value.value()).toString("base64");
|
|
130
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array) return Buffer.from(value).toString("base64");
|
|
131
|
+
if (Array.isArray(value)) return value.map((item) => normalizeBson(item, depth + 1));
|
|
132
|
+
if (isObject(value)) {
|
|
133
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
134
|
+
throw datasetError("BSON_TYPE_UNSUPPORTED", "mapping", "Use an approved projection for this BSON type.");
|
|
135
|
+
}
|
|
136
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, normalizeBson(child, depth + 1)]));
|
|
137
|
+
}
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
async function openMongo(context) {
|
|
141
|
+
const profile = context.profile;
|
|
142
|
+
const provider = profile.transport;
|
|
143
|
+
if (provider?.openMongo) return provider.openMongo(context);
|
|
144
|
+
const url = approvedEndpoint(profile, ["mongodb:"]);
|
|
145
|
+
if (url.pathname !== "" && url.pathname !== "/") throw datasetError("INVALID_CONNECTION", "connection", "Use a single approved MongoDB host and port.");
|
|
146
|
+
const signal = deadlineSignal(context);
|
|
147
|
+
const { address, family } = await authorizedAddress(url.hostname, profile, signal);
|
|
148
|
+
const auth = context.secret?.mongo;
|
|
149
|
+
const { ca, cert, key } = context.secret?.tls ?? {};
|
|
150
|
+
const client = new MongoClient("mongodb://" + (family === 6 ? "[" + address + "]" : address) + ":" + (url.port || 27017), {
|
|
151
|
+
directConnection: true,
|
|
152
|
+
tls: !profile.allowInsecure,
|
|
153
|
+
servername: url.hostname.replace(/^\[|\]$/g, ""),
|
|
154
|
+
ca,
|
|
155
|
+
cert,
|
|
156
|
+
key,
|
|
157
|
+
...auth ? { auth: { username: auth.username, password: auth.password }, authSource: auth.authSource } : {},
|
|
158
|
+
serverSelectionTimeoutMS: Math.max(1, context.deadline - Date.now()),
|
|
159
|
+
maxPoolSize: 2,
|
|
160
|
+
retryReads: false,
|
|
161
|
+
retryWrites: false,
|
|
162
|
+
promoteLongs: false
|
|
163
|
+
});
|
|
164
|
+
try {
|
|
165
|
+
await client.connect();
|
|
166
|
+
signal.throwIfAborted();
|
|
167
|
+
return client;
|
|
168
|
+
} catch {
|
|
169
|
+
await client.close().catch(() => {
|
|
170
|
+
});
|
|
171
|
+
throw datasetError("CONNECTION_FAILED", "connection", "The approved MongoDB identity could not connect.");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
var mongoAdapter = {
|
|
175
|
+
protocol: "mongo",
|
|
176
|
+
capabilities: ["find", "bounded cursor", "offset", "indexed _id keyset", "exact count", "whole-collection estimate", "read-only aggregation", "shared snapshot", "BSON precision"],
|
|
177
|
+
validateOperation(operation, profile) {
|
|
178
|
+
const config = operationConfig(operation);
|
|
179
|
+
if (profile && !profile.operationRules.includes(config.database + "." + config.collection + ":" + config.kind)) {
|
|
180
|
+
throw datasetError("UNAUTHORIZED_SOURCE_OPERATION", "connection", "The connection does not grant this exact MongoDB namespace and operation.");
|
|
181
|
+
}
|
|
182
|
+
if (config.kind === "aggregate" ? !config.pipeline : Boolean(config.pipeline)) {
|
|
183
|
+
throw datasetError("INVALID_MONGO_PIPELINE", "plan", "A pipeline is only available on an aggregate operation.");
|
|
184
|
+
}
|
|
185
|
+
if (config.kind === "estimatedDocumentCount" && (config.filter || config.pipeline)) {
|
|
186
|
+
throw datasetError("ESTIMATE_SCOPE_MISMATCH", "plan", "Estimated document count applies to the whole collection.");
|
|
187
|
+
}
|
|
188
|
+
const operands = /* @__PURE__ */ new Set();
|
|
189
|
+
inspectTemplate(config.filter, filters, operands);
|
|
190
|
+
if (config.pipeline) inspectPipeline(config.pipeline, operands);
|
|
191
|
+
if (operation.slots.some((slot) => slot.section !== "operands" || !operands.has(slot.name)) || [...operands].some((name) => !operation.slots.some((slot) => slot.name === name && slot.required))) {
|
|
192
|
+
throw datasetError("INVALID_MONGO_OPERAND", "plan", "Every dynamic filter operand needs a declared required slot.");
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
validatePagination(operation, mode) {
|
|
196
|
+
const config = operationConfig(operation);
|
|
197
|
+
const sort = Object.keys(config.sort ?? {});
|
|
198
|
+
if (mode === "stream" && ["find", "aggregate"].includes(config.kind)) return;
|
|
199
|
+
if (config.kind === "find" && mode === "offset" && sort.at(-1) === "_id") return;
|
|
200
|
+
if (config.kind === "find" && mode === "keyset" && sort.length === 1 && sort[0] === "_id") return;
|
|
201
|
+
throw datasetError("PAGINATION_UNAVAILABLE", "plan", "Use a bounded cursor, or page find results with an approved unique _id order.");
|
|
202
|
+
},
|
|
203
|
+
validateSnapshot(operation) {
|
|
204
|
+
if (operationConfig(operation).kind === "estimatedDocumentCount") {
|
|
205
|
+
throw datasetError("SNAPSHOT_UNAVAILABLE", "plan", "Collection estimates cannot participate in a shared snapshot.");
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
async testConnection(context) {
|
|
209
|
+
const client = await openMongo(context);
|
|
210
|
+
await client.close();
|
|
211
|
+
},
|
|
212
|
+
async openSnapshot(context) {
|
|
213
|
+
if (!context.profile?.snapshot) throw datasetError("SNAPSHOT_UNAVAILABLE", "connection", "This MongoDB connection has no approved snapshot capability.");
|
|
214
|
+
const client = await openMongo(context);
|
|
215
|
+
const session = client.startSession({ causalConsistency: false });
|
|
216
|
+
try {
|
|
217
|
+
session.startTransaction({ readConcern: { level: "snapshot" }, readPreference: "primary" });
|
|
218
|
+
return { value: { client, session }, close: async () => {
|
|
219
|
+
try {
|
|
220
|
+
if (session.inTransaction()) await session.abortTransaction();
|
|
221
|
+
} finally {
|
|
222
|
+
try {
|
|
223
|
+
await session.endSession();
|
|
224
|
+
} finally {
|
|
225
|
+
await client.close();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
} };
|
|
229
|
+
} catch {
|
|
230
|
+
try {
|
|
231
|
+
await session.endSession();
|
|
232
|
+
} finally {
|
|
233
|
+
await client.close();
|
|
234
|
+
}
|
|
235
|
+
throw datasetError("SNAPSHOT_UNAVAILABLE", "connection", "The approved snapshot could not start.");
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
async execute(operation, request, context) {
|
|
239
|
+
const config = operationConfig(operation);
|
|
240
|
+
const operands = isObject(request.operands) ? request.operands : {};
|
|
241
|
+
let filter = bindOperands(config.filter ?? {}, operands, config.operandTypes ?? {});
|
|
242
|
+
const page = context.page;
|
|
243
|
+
if (page.mode === "keyset" && page.key !== void 0) {
|
|
244
|
+
filter = { $and: [filter, { _id: { [config.sort?._id === -1 ? "$lt" : "$gt"]: bsonOperand(page.key, config.keyType) } }] };
|
|
245
|
+
}
|
|
246
|
+
const snapshot = context.snapshot;
|
|
247
|
+
if (snapshot && config.kind === "estimatedDocumentCount") throw datasetError("SNAPSHOT_UNAVAILABLE", "connection", "Collection estimates cannot participate in a shared snapshot.");
|
|
248
|
+
const client = snapshot?.client ?? await openMongo(context);
|
|
249
|
+
const signal = deadlineSignal(context);
|
|
250
|
+
const options = {
|
|
251
|
+
signal,
|
|
252
|
+
maxTimeMS: Math.max(1, context.deadline - Date.now()),
|
|
253
|
+
session: snapshot?.session
|
|
254
|
+
};
|
|
255
|
+
try {
|
|
256
|
+
signal.throwIfAborted();
|
|
257
|
+
const collection = client.db(config.database).collection(config.collection);
|
|
258
|
+
if (config.kind === "countDocuments" || config.kind === "estimatedDocumentCount") {
|
|
259
|
+
const estimated = config.kind === "estimatedDocumentCount";
|
|
260
|
+
const value = estimated ? await collection.estimatedDocumentCount({ maxTimeMS: options.maxTimeMS }) : await collection.countDocuments(filter, options);
|
|
261
|
+
signal.throwIfAborted();
|
|
262
|
+
if (!Number.isSafeInteger(value)) throw datasetError("COUNT_PRECISION_MISMATCH", "mapping", "The driver count exceeds safe numeric precision.");
|
|
263
|
+
return { body: { count: value }, count: { value, precision: estimated ? "estimated" : "exact", scope: estimated ? "wholeCollection" : "matchedQuery" }, exhausted: true };
|
|
264
|
+
}
|
|
265
|
+
const cursor = config.kind === "find" ? collection.find(filter, {
|
|
266
|
+
...options,
|
|
267
|
+
projection: config.projection,
|
|
268
|
+
sort: config.sort,
|
|
269
|
+
batchSize: config.batchSize,
|
|
270
|
+
...page.mode === "offset" ? { skip: page.offset, limit: page.limit } : page.mode === "keyset" ? { limit: page.limit } : context.businessLimit ? { limit: context.businessLimit + 1 } : {}
|
|
271
|
+
}) : collection.aggregate([
|
|
272
|
+
...config.filter ? [{ $match: filter }] : [],
|
|
273
|
+
...bindOperands(config.pipeline, operands, config.operandTypes ?? {})
|
|
274
|
+
], { ...options, batchSize: config.batchSize, allowDiskUse: false });
|
|
275
|
+
const body = [];
|
|
276
|
+
let bytes = 2;
|
|
277
|
+
try {
|
|
278
|
+
for await (const record of cursor) {
|
|
279
|
+
signal.throwIfAborted();
|
|
280
|
+
const normalized = normalizeBson(record);
|
|
281
|
+
checkJson(normalized, context.maxBytes);
|
|
282
|
+
bytes += Buffer.byteLength(JSON.stringify(normalized)) + 1;
|
|
283
|
+
if (bytes > context.maxBytes || body.length >= context.maxRows) {
|
|
284
|
+
throw datasetError("SOURCE_LIMIT_REACHED", "page", "The MongoDB cursor exceeded the remaining execution budget.");
|
|
285
|
+
}
|
|
286
|
+
body.push(normalized);
|
|
287
|
+
}
|
|
288
|
+
} finally {
|
|
289
|
+
await cursor.close().catch(() => {
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return { body, bytes, exhausted: true };
|
|
293
|
+
} finally {
|
|
294
|
+
if (!snapshot) await client.close().catch(() => {
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
export {
|
|
300
|
+
mongoAdapter,
|
|
301
|
+
normalizeBson
|
|
302
|
+
};
|
|
303
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { MongoClient, ObjectId, Long, Decimal128, Binary, Timestamp, type ClientSession, type Document } from 'mongodb';\nimport { z } from 'zod';\nimport type { ApprovedOperation, DatasetObject } from '@x12i/reportic-catalog';\nimport { isObject } from '@x12i/reportic-catalog/schema';\nimport { datasetError, checkJson, type AdapterContext, type DatasetAdapter } from '@x12i/reportic-datasets';\nimport { approvedEndpoint, authorizedAddress, deadlineSignal } from '@x12i/reportic-adapter-api';\n\nexport interface MongoTransport {\n openMongo(context: AdapterContext): Promise<MongoClient>;\n}\n\nconst fieldName = z.string().regex(/^[A-Za-z_][\\w-]*(?:\\.[A-Za-z_][\\w-]*)*$/).max(200);\nconst settings = z.object({\n database: z.string().regex(/^[A-Za-z_][\\w-]{0,63}$/),\n collection: z.string().regex(/^[A-Za-z_][\\w-]{0,119}$/),\n kind: z.enum(['find', 'countDocuments', 'estimatedDocumentCount', 'aggregate']),\n filter: z.record(z.unknown()).optional(),\n projection: z.record(fieldName, z.union([z.literal(0), z.literal(1)])).optional(),\n sort: z.record(fieldName, z.union([z.literal(1), z.literal(-1)])).optional(),\n pipeline: z.array(z.record(z.unknown())).min(1).max(30).optional(),\n batchSize: z.number().int().min(1).max(1_000).default(100),\n operandTypes: z.record(z.enum(['dateTime', 'objectId', 'int64', 'decimal'])).optional(),\n keyType: z.enum(['objectId', 'int64']).optional(),\n}).strict();\nconst filters = new Set(['$and', '$or', '$nor', '$not', '$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$in', '$nin', '$exists', '$type', '$size', '$elemMatch', '$all']);\nconst stages = new Set(['$match', '$project', '$group', '$sort', '$limit', '$skip', '$unwind', '$count', '$facet', '$addFields', '$set', '$unset', '$bucket']);\nconst expressions = new Set(['$sum', '$avg', '$min', '$max', '$count', '$first', '$last', '$push', '$addToSet',\n '$literal', '$ifNull', '$cond', '$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$and', '$or', '$not', '$toString',\n '$add', '$subtract', '$multiply', '$divide', '$round', '$dateTrunc', '$dateToString', '$concat', '$size']);\n\nfunction inspectTemplate(value: unknown, allowed: Set<string>, operands: Set<string>, depth = 0) {\n if (depth > 25) throw datasetError('INVALID_MONGO_OPERATION', 'plan', 'The MongoDB expression is nested too deeply.');\n if (Array.isArray(value)) {\n value.forEach(child => inspectTemplate(child, allowed, operands, depth + 1));\n return;\n }\n if (!isObject(value)) return;\n if (Object.hasOwn(value, '$operand')) {\n if (allowed !== filters || Object.keys(value).length !== 1 || typeof value.$operand !== 'string') {\n throw datasetError('INVALID_MONGO_OPERAND', 'plan', 'Place parameters only in approved filter operand positions.');\n }\n operands.add(value.$operand);\n return;\n }\n for (const [key, child] of Object.entries(value)) {\n if (key.startsWith('$') && !allowed.has(key)) throw datasetError('UNSAFE_MONGO_OPERATOR', 'plan', 'The MongoDB operation contains a restricted operator.');\n inspectTemplate(child, allowed, operands, depth + 1);\n }\n}\n\nfunction inspectPipeline(pipeline: DatasetObject[], operands: Set<string>, depth = 0) {\n if (depth > 4 || pipeline.length > 30) throw datasetError('INVALID_MONGO_PIPELINE', 'plan', 'The MongoDB pipeline exceeds its stage or nesting limit.');\n for (const stage of pipeline) {\n if (!isObject(stage) || Object.keys(stage).length !== 1) throw datasetError('INVALID_MONGO_PIPELINE', 'plan', 'Every pipeline entry must have one approved stage.');\n const [kind, input] = Object.entries(stage)[0];\n if (!stages.has(kind)) throw datasetError('UNSAFE_MONGO_STAGE', 'plan', 'The pipeline uses a write, cross-collection or unsupported stage.');\n if (kind === '$facet') {\n if (!isObject(input) || Object.keys(input).length > 12) throw datasetError('INVALID_MONGO_PIPELINE', 'plan', 'A facet needs named, bounded branches.');\n for (const branch of Object.values(input)) {\n if (!Array.isArray(branch)) throw datasetError('INVALID_MONGO_PIPELINE', 'plan', 'Each facet branch must be a pipeline.');\n inspectPipeline(branch, operands, depth + 1);\n }\n } else inspectTemplate(input, kind === '$match' ? filters : expressions, operands);\n }\n}\n\nfunction operationConfig(operation: ApprovedOperation) {\n const parsed = settings.safeParse(operation.configuration);\n if (!parsed.success) throw datasetError('INVALID_MONGO_OPERATION', 'plan', 'Select an approved database, collection and read operation.');\n return parsed.data;\n}\n\nfunction bsonOperand(value: unknown, type?: string): unknown {\n if (Array.isArray(value)) {\n if (value.length > 200 || value.some(Array.isArray)) throw datasetError('INVALID_MONGO_OPERAND', 'request', 'A filter list is too large or nested.');\n return value.map(item => bsonOperand(item, type));\n }\n if (value === null && !type) return null;\n if (typeof value !== 'string' && typeof value !== 'boolean' &&\n (typeof value !== 'number' || !Number.isFinite(value) || Number.isInteger(value) && !Number.isSafeInteger(value))) {\n throw datasetError('INVALID_MONGO_OPERAND', 'request', 'A filter operand must be a scalar or a bounded scalar list.');\n }\n if (!type) return value;\n try {\n if (type === 'dateTime' && typeof value === 'string' && /^\\d{4}-\\d\\d-\\d\\dT/.test(value) && Number.isFinite(Date.parse(value))) return new Date(value);\n if (type === 'objectId' && typeof value === 'string' && /^[a-f\\d]{24}$/i.test(value)) return new ObjectId(value);\n if (type === 'int64' && typeof value === 'string' && /^-?\\d{1,19}$/.test(value) &&\n BigInt(value) >= -9223372036854775808n && BigInt(value) <= 9223372036854775807n) return Long.fromString(value);\n if (type === 'decimal' && typeof value === 'string' && /^[+-]?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$/.test(value) && value.length <= 128) return Decimal128.fromString(value);\n } catch { /* Convert representation errors to a safe diagnostic. */ }\n throw datasetError('INVALID_MONGO_OPERAND', 'request', 'The filter value does not match the approved BSON type.');\n}\n\nfunction bindOperands(value: unknown, inputs: DatasetObject, types: Record<string, string>): unknown {\n if (Array.isArray(value)) return value.map(item => bindOperands(item, inputs, types));\n if (!isObject(value)) return value;\n if (Object.hasOwn(value, '$operand')) {\n const name = String(value.$operand);\n if (!Object.hasOwn(inputs, name)) throw datasetError('INVALID_MONGO_OPERAND', 'request', 'A required filter operand is missing.');\n return bsonOperand(inputs[name], types[name]);\n }\n return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, bindOperands(child, inputs, types)]));\n}\n\nexport function normalizeBson(value: unknown, depth = 0): unknown {\n if (depth > 32) throw datasetError('SOURCE_LIMIT_REACHED', 'mapping', 'The MongoDB document is nested too deeply.');\n if (value instanceof ObjectId) return value.toHexString();\n if (value instanceof Timestamp) return value.toString();\n if (value instanceof Long || value instanceof Decimal128 || typeof value === 'bigint') return value.toString();\n if (value instanceof Date) return value.toISOString();\n if (value instanceof Binary) return Buffer.from(value.value()).toString('base64');\n if (Buffer.isBuffer(value) || value instanceof Uint8Array) return Buffer.from(value).toString('base64');\n if (Array.isArray(value)) return value.map(item => normalizeBson(item, depth + 1));\n if (isObject(value)) {\n if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {\n throw datasetError('BSON_TYPE_UNSUPPORTED', 'mapping', 'Use an approved projection for this BSON type.');\n }\n return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, normalizeBson(child, depth + 1)]));\n }\n return value;\n}\n\nasync function openMongo(context: AdapterContext) {\n const profile = context.profile!;\n const provider = profile.transport as MongoTransport | undefined;\n if (provider?.openMongo) return provider.openMongo(context);\n const url = approvedEndpoint(profile, ['mongodb:']);\n if (url.pathname !== '' && url.pathname !== '/') throw datasetError('INVALID_CONNECTION', 'connection', 'Use a single approved MongoDB host and port.');\n const signal = deadlineSignal(context);\n const {address, family} = await authorizedAddress(url.hostname, profile, signal);\n const auth = context.secret?.mongo;\n const {ca, cert, key} = context.secret?.tls ?? {};\n const client = new MongoClient('mongodb://' + (family === 6 ? '[' + address + ']' : address) + ':' + (url.port || 27017), {\n directConnection: true, tls: !profile.allowInsecure, servername: url.hostname.replace(/^\\[|\\]$/g, ''),\n ca, cert, key, ...(auth ? {auth: {username: auth.username, password: auth.password}, authSource: auth.authSource} : {}),\n serverSelectionTimeoutMS: Math.max(1, context.deadline - Date.now()),\n maxPoolSize: 2, retryReads: false, retryWrites: false, promoteLongs: false,\n });\n try {\n await client.connect();\n signal.throwIfAborted();\n return client;\n } catch {\n await client.close().catch(() => {});\n throw datasetError('CONNECTION_FAILED', 'connection', 'The approved MongoDB identity could not connect.');\n }\n}\n\ntype Snapshot = {client: MongoClient; session: ClientSession};\n\nexport const mongoAdapter: DatasetAdapter = {\n protocol: 'mongo',\n capabilities: ['find', 'bounded cursor', 'offset', 'indexed _id keyset', 'exact count', 'whole-collection estimate', 'read-only aggregation', 'shared snapshot', 'BSON precision'],\n validateOperation(operation, profile) {\n const config = operationConfig(operation);\n if (profile && !profile.operationRules.includes(config.database + '.' + config.collection + ':' + config.kind)) {\n throw datasetError('UNAUTHORIZED_SOURCE_OPERATION', 'connection', 'The connection does not grant this exact MongoDB namespace and operation.');\n }\n if (config.kind === 'aggregate' ? !config.pipeline : Boolean(config.pipeline)) {\n throw datasetError('INVALID_MONGO_PIPELINE', 'plan', 'A pipeline is only available on an aggregate operation.');\n }\n if (config.kind === 'estimatedDocumentCount' && (config.filter || config.pipeline)) {\n throw datasetError('ESTIMATE_SCOPE_MISMATCH', 'plan', 'Estimated document count applies to the whole collection.');\n }\n const operands = new Set<string>();\n inspectTemplate(config.filter, filters, operands);\n if (config.pipeline) inspectPipeline(config.pipeline, operands);\n if (operation.slots.some(slot => slot.section !== 'operands' || !operands.has(slot.name)) ||\n [...operands].some(name => !operation.slots.some(slot => slot.name === name && slot.required))) {\n throw datasetError('INVALID_MONGO_OPERAND', 'plan', 'Every dynamic filter operand needs a declared required slot.');\n }\n },\n validatePagination(operation, mode) {\n const config = operationConfig(operation);\n const sort = Object.keys(config.sort ?? {});\n if (mode === 'stream' && ['find', 'aggregate'].includes(config.kind)) return;\n if (config.kind === 'find' && mode === 'offset' && sort.at(-1) === '_id') return;\n if (config.kind === 'find' && mode === 'keyset' && sort.length === 1 && sort[0] === '_id') return;\n throw datasetError('PAGINATION_UNAVAILABLE', 'plan', 'Use a bounded cursor, or page find results with an approved unique _id order.');\n },\n validateSnapshot(operation) {\n if (operationConfig(operation).kind === 'estimatedDocumentCount') {\n throw datasetError('SNAPSHOT_UNAVAILABLE', 'plan', 'Collection estimates cannot participate in a shared snapshot.');\n }\n },\n async testConnection(context) {\n const client = await openMongo(context);\n await client.close();\n },\n async openSnapshot(context) {\n if (!context.profile?.snapshot) throw datasetError('SNAPSHOT_UNAVAILABLE', 'connection', 'This MongoDB connection has no approved snapshot capability.');\n const client = await openMongo(context);\n const session = client.startSession({causalConsistency: false});\n try {\n session.startTransaction({readConcern: {level: 'snapshot'}, readPreference: 'primary'});\n return {value: {client, session}, close: async () => {\n try { if (session.inTransaction()) await session.abortTransaction(); }\n finally { try { await session.endSession(); } finally { await client.close(); } }\n }};\n } catch {\n try { await session.endSession(); } finally { await client.close(); }\n throw datasetError('SNAPSHOT_UNAVAILABLE', 'connection', 'The approved snapshot could not start.');\n }\n },\n async execute(operation, request, context) {\n const config = operationConfig(operation);\n const operands = isObject(request.operands) ? request.operands : {};\n let filter = bindOperands(config.filter ?? {}, operands, config.operandTypes ?? {}) as Document;\n const page = context.page;\n if (page.mode === 'keyset' && page.key !== undefined) {\n filter = {$and: [filter, {_id: {[config.sort?._id === -1 ? '$lt' : '$gt']: bsonOperand(page.key, config.keyType)}}]};\n }\n const snapshot = context.snapshot as Snapshot | undefined;\n if (snapshot && config.kind === 'estimatedDocumentCount') throw datasetError('SNAPSHOT_UNAVAILABLE', 'connection', 'Collection estimates cannot participate in a shared snapshot.');\n const client = snapshot?.client ?? await openMongo(context);\n const signal = deadlineSignal(context);\n const options = {\n signal, maxTimeMS: Math.max(1, context.deadline - Date.now()), session: snapshot?.session,\n };\n try {\n signal.throwIfAborted();\n const collection = client.db(config.database).collection(config.collection);\n if (config.kind === 'countDocuments' || config.kind === 'estimatedDocumentCount') {\n const estimated = config.kind === 'estimatedDocumentCount';\n const value = estimated ? await collection.estimatedDocumentCount({maxTimeMS: options.maxTimeMS}) : await collection.countDocuments(filter, options);\n signal.throwIfAborted();\n if (!Number.isSafeInteger(value)) throw datasetError('COUNT_PRECISION_MISMATCH', 'mapping', 'The driver count exceeds safe numeric precision.');\n return {body: {count: value}, count: {value, precision: estimated ? 'estimated' : 'exact', scope: estimated ? 'wholeCollection' : 'matchedQuery'}, exhausted: true};\n }\n const cursor = config.kind === 'find' ? collection.find(filter, {\n ...options, projection: config.projection, sort: config.sort, batchSize: config.batchSize,\n ...(page.mode === 'offset' ? {skip: page.offset, limit: page.limit} : page.mode === 'keyset' ? {limit: page.limit} :\n context.businessLimit ? {limit: context.businessLimit + 1} : {}),\n }) : collection.aggregate([\n ...(config.filter ? [{$match: filter}] : []),\n ...bindOperands(config.pipeline!, operands, config.operandTypes ?? {}) as Document[],\n ], {...options, batchSize: config.batchSize, allowDiskUse: false});\n const body: unknown[] = [];\n let bytes = 2;\n try {\n for await (const record of cursor) {\n signal.throwIfAborted();\n const normalized = normalizeBson(record);\n checkJson(normalized, context.maxBytes);\n bytes += Buffer.byteLength(JSON.stringify(normalized)) + 1;\n if (bytes > context.maxBytes || body.length >= context.maxRows) {\n throw datasetError('SOURCE_LIMIT_REACHED', 'page', 'The MongoDB cursor exceeded the remaining execution budget.');\n }\n body.push(normalized);\n }\n } finally { await cursor.close().catch(() => {}); }\n return {body, bytes, exhausted: true};\n } finally { if (!snapshot) await client.close().catch(() => {}); }\n },\n};\n"],"mappings":";AAAA,SAAS,aAAa,UAAU,MAAM,YAAY,QAAQ,iBAAoD;AAC9G,SAAS,SAAS;AAElB,SAAS,gBAAgB;AACzB,SAAS,cAAc,iBAA2D;AAClF,SAAS,kBAAkB,mBAAmB,sBAAsB;AAMpE,IAAM,YAAY,EAAE,OAAO,EAAE,MAAM,yCAAyC,EAAE,IAAI,GAAG;AACrF,IAAM,WAAW,EAAE,OAAO;AAAA,EACxB,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB;AAAA,EACnD,YAAY,EAAE,OAAO,EAAE,MAAM,yBAAyB;AAAA,EACtD,MAAM,EAAE,KAAK,CAAC,QAAQ,kBAAkB,0BAA0B,WAAW,CAAC;AAAA,EAC9E,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACvC,YAAY,EAAE,OAAO,WAAW,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS;AAAA,EAChF,MAAM,EAAE,OAAO,WAAW,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS;AAAA,EAC3E,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA,EACjE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,GAAK,EAAE,QAAQ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,OAAO,WAAW,KAAI;AAAA,IACtC,UAAE;AAAU,UAAI,CAAC,SAAU,OAAM,OAAO,MAAM,EAAE,MAAM,MAAM;AAAA,MAAC,CAAC;AAAA,IAAG;AAAA,EACnE;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x12i/reportic-adapter-mongo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Scoped read-only MongoDB dataset adapter",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@x12i/reportic-catalog": "0.2.2",
|
|
27
|
+
"@x12i/reportic-datasets": "0.2.2",
|
|
28
|
+
"@x12i/reportic-adapter-api": "0.2.2",
|
|
29
|
+
"mongodb": "^6.22.0",
|
|
30
|
+
"zod": "^3.25.0"
|
|
31
|
+
}
|
|
32
|
+
}
|