@semics-tech/mongolite 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +91 -20
  2. package/dist/bin/mongolite-debug.d.ts +6 -1
  3. package/dist/bin/mongolite-debug.js +6 -113
  4. package/dist/bin/mongolite-debug.js.map +1 -1
  5. package/dist/bin/mongolite.d.ts +13 -0
  6. package/dist/bin/mongolite.js +172 -0
  7. package/dist/bin/mongolite.js.map +1 -0
  8. package/dist/cjs/bin/mongolite-debug.js +6 -149
  9. package/dist/cjs/bin/mongolite.js +207 -0
  10. package/dist/cjs/cli/discover.js +156 -0
  11. package/dist/cjs/cli/explorer.js +929 -0
  12. package/dist/cjs/cli/filter-builder.js +276 -0
  13. package/dist/cjs/cli/format.js +161 -0
  14. package/dist/cjs/cli/schema.js +211 -0
  15. package/dist/cjs/cli/ui.js +431 -0
  16. package/dist/cjs/collection.js +8 -1
  17. package/dist/cjs/cursors/findCursor.js +20 -8
  18. package/dist/cjs/index.js +108 -1
  19. package/dist/cjs/mongo-client.js +18 -1
  20. package/dist/cjs/server.js +164 -0
  21. package/dist/cjs/sync/commands.js +126 -0
  22. package/dist/cjs/sync/diff.js +174 -0
  23. package/dist/cjs/sync/httpSink.js +159 -0
  24. package/dist/cjs/sync/index.js +40 -0
  25. package/dist/cjs/sync/mongoExecutor.js +306 -0
  26. package/dist/cjs/sync/mongoSink.js +161 -0
  27. package/dist/cjs/sync/outbox.js +358 -0
  28. package/dist/cjs/sync/protocol.js +177 -0
  29. package/dist/cjs/sync/replicator.js +747 -0
  30. package/dist/cjs/sync/shadow.js +178 -0
  31. package/dist/cjs/sync/types.js +2 -0
  32. package/dist/cli/discover.d.ts +40 -0
  33. package/dist/cli/discover.js +146 -0
  34. package/dist/cli/discover.js.map +1 -0
  35. package/dist/cli/explorer.d.ts +59 -0
  36. package/dist/cli/explorer.js +923 -0
  37. package/dist/cli/explorer.js.map +1 -0
  38. package/dist/cli/filter-builder.d.ts +52 -0
  39. package/dist/cli/filter-builder.js +268 -0
  40. package/dist/cli/filter-builder.js.map +1 -0
  41. package/dist/cli/format.d.ts +29 -0
  42. package/dist/cli/format.js +153 -0
  43. package/dist/cli/format.js.map +1 -0
  44. package/dist/cli/schema.d.ts +58 -0
  45. package/dist/cli/schema.js +205 -0
  46. package/dist/cli/schema.js.map +1 -0
  47. package/dist/cli/ui.d.ts +71 -0
  48. package/dist/cli/ui.js +379 -0
  49. package/dist/cli/ui.js.map +1 -0
  50. package/dist/cloudflare.d.ts +1 -1
  51. package/dist/cloudflare.js.map +1 -1
  52. package/dist/collection.js +8 -1
  53. package/dist/collection.js.map +1 -1
  54. package/dist/cursors/findCursor.d.ts +12 -0
  55. package/dist/cursors/findCursor.js +20 -8
  56. package/dist/cursors/findCursor.js.map +1 -1
  57. package/dist/index.d.ts +68 -2
  58. package/dist/index.js +96 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/mongo-client.d.ts +13 -0
  61. package/dist/mongo-client.js +18 -1
  62. package/dist/mongo-client.js.map +1 -1
  63. package/dist/server.d.ts +97 -0
  64. package/dist/server.js +158 -0
  65. package/dist/server.js.map +1 -0
  66. package/dist/sync/commands.d.ts +49 -0
  67. package/dist/sync/commands.js +118 -0
  68. package/dist/sync/commands.js.map +1 -0
  69. package/dist/sync/diff.d.ts +55 -0
  70. package/dist/sync/diff.js +169 -0
  71. package/dist/sync/diff.js.map +1 -0
  72. package/dist/sync/httpSink.d.ts +93 -0
  73. package/dist/sync/httpSink.js +155 -0
  74. package/dist/sync/httpSink.js.map +1 -0
  75. package/dist/sync/index.d.ts +17 -0
  76. package/dist/sync/index.js +10 -0
  77. package/dist/sync/index.js.map +1 -0
  78. package/dist/sync/mongoExecutor.d.ts +37 -0
  79. package/dist/sync/mongoExecutor.js +302 -0
  80. package/dist/sync/mongoExecutor.js.map +1 -0
  81. package/dist/sync/mongoSink.d.ts +109 -0
  82. package/dist/sync/mongoSink.js +123 -0
  83. package/dist/sync/mongoSink.js.map +1 -0
  84. package/dist/sync/outbox.d.ts +120 -0
  85. package/dist/sync/outbox.js +355 -0
  86. package/dist/sync/outbox.js.map +1 -0
  87. package/dist/sync/protocol.d.ts +93 -0
  88. package/dist/sync/protocol.js +168 -0
  89. package/dist/sync/protocol.js.map +1 -0
  90. package/dist/sync/replicator.d.ts +177 -0
  91. package/dist/sync/replicator.js +744 -0
  92. package/dist/sync/replicator.js.map +1 -0
  93. package/dist/sync/shadow.d.ts +54 -0
  94. package/dist/sync/shadow.js +173 -0
  95. package/dist/sync/shadow.js.map +1 -0
  96. package/dist/sync/types.d.ts +388 -0
  97. package/dist/sync/types.js +2 -0
  98. package/dist/sync/types.js.map +1 -0
  99. package/package.json +16 -1
@@ -0,0 +1,302 @@
1
+ /**
2
+ * Applies prepared write commands to MongoDB and classifies the outcome.
3
+ *
4
+ * Shared by the direct sink and by the HTTP receiver, so the subtle part has exactly
5
+ * one implementation: **a lost compare-and-swap raises no error.** It is a silent
6
+ * zero-match in an aggregate count, which means detecting it takes deliberate work —
7
+ * comparing what the batch expected to change against what the server says changed, and
8
+ * then re-reading the candidates to find out which document actually lost.
9
+ */
10
+ import { isConditional, isReservedPath, readVersion, stripReservedFields, toUpstreamId, } from './commands.js';
11
+ import { deepEqual } from './diff.js';
12
+ /**
13
+ * MongoDB server error codes that mean "this write will never succeed" — retrying them
14
+ * would stall the stream behind one bad document forever, so they are dead-lettered.
15
+ */
16
+ const PERMANENT_ERROR_CODES = new Set([
17
+ 2, // BadValue
18
+ 9, // FailedToParse
19
+ 10334, // BSONObjectTooLarge
20
+ 14, // TypeMismatch
21
+ 52, // DollarPrefixedFieldName
22
+ 56, // EmptyFieldName
23
+ 121, // DocumentValidationFailure
24
+ 17280, // KeyTooLong
25
+ ]);
26
+ /** MongoDB's duplicate-key code. On an insert-if-absent it means we lost a create race. */
27
+ const DUPLICATE_KEY = 11000;
28
+ /**
29
+ * Runs prepared writes against a database, one `bulkWrite` per collection.
30
+ *
31
+ * Throws on transient failure (network, election, timeout) so the caller retries the
32
+ * whole batch without checkpointing. Returns per-operation failures and conflicts for
33
+ * everything it could classify.
34
+ */
35
+ export async function executeWrites(db, writes, options = {}) {
36
+ const { writeConcern = { w: 'majority' }, versioning = true, idMapping, ObjectId } = options;
37
+ const byCollection = new Map();
38
+ for (const write of writes) {
39
+ const bucket = byCollection.get(write.op.collection);
40
+ if (bucket)
41
+ bucket.push(write);
42
+ else
43
+ byCollection.set(write.op.collection, [write]);
44
+ }
45
+ const failures = [];
46
+ const conflicts = [];
47
+ let applied = 0;
48
+ for (const [collectionName, entries] of byCollection) {
49
+ let result = null;
50
+ let rejected = 0;
51
+ try {
52
+ result = await db.collection(collectionName).bulkWrite(entries.map((entry) => entry.command), {
53
+ // Operations within a batch touch distinct documents, so ordering buys
54
+ // nothing and unordered lets the server parallelise.
55
+ ordered: false,
56
+ writeConcern,
57
+ });
58
+ }
59
+ catch (err) {
60
+ const bulkFailures = classifyBulkError(err, entries.length);
61
+ // A transient failure means the whole batch's fate is unknown — throw so the
62
+ // caller retries it rather than checkpointing work that may not have landed.
63
+ if (bulkFailures === null)
64
+ throw err;
65
+ for (const failure of bulkFailures) {
66
+ const entry = entries[failure.index];
67
+ if (!entry)
68
+ continue;
69
+ // A duplicate `_id` on an insert-if-absent means someone created the document
70
+ // first — a conflict to reconcile, not a poison document. A duplicate on any
71
+ // *other* unique index is a real constraint violation and must be dead-lettered,
72
+ // or it would be retried forever as a phantom conflict.
73
+ if (failure.code === DUPLICATE_KEY && isIdIndexViolation(failure)) {
74
+ conflicts.push({ index: entry.index, reason: 'already-exists' });
75
+ }
76
+ else {
77
+ failures.push({ index: entry.index, message: failure.message, code: failure.code });
78
+ }
79
+ }
80
+ rejected = bulkFailures.length;
81
+ result = err.result ?? null;
82
+ }
83
+ const landed = entries.length - rejected;
84
+ const suspects = findMisses(entries, result, rejected, versioning);
85
+ // `suspects` are candidates to investigate, not confirmed misses: the counts are
86
+ // aggregate, so one short count implicates every conditional write in the batch.
87
+ // Only the re-read says which of them actually lost, and `applied` must be reduced
88
+ // by that number rather than by the number investigated.
89
+ const confirmed = suspects.length
90
+ ? await describeConflicts(db, collectionName, suspects, conflicts, idMapping, ObjectId)
91
+ : 0;
92
+ applied += landed - confirmed;
93
+ }
94
+ return {
95
+ applied,
96
+ failures: failures.length > 0 ? failures : undefined,
97
+ conflicts: conflicts.length > 0 ? conflicts : undefined,
98
+ };
99
+ }
100
+ /**
101
+ * Identifies operations whose conditional write may not have matched.
102
+ *
103
+ * `bulkWrite` reports only aggregate counts, so this compares what the batch expected
104
+ * to change against what the server says changed. When the numbers agree, nothing was
105
+ * missed and no per-document work is needed.
106
+ */
107
+ function findMisses(entries, result, rejected, versioning) {
108
+ if (!versioning || result === null || rejected === entries.length)
109
+ return [];
110
+ const candidates = entries.filter((entry) => isConditional(entry.op));
111
+ if (candidates.length === 0)
112
+ return [];
113
+ const writes = candidates.filter((entry) => entry.op.type !== 'delete');
114
+ const deletes = candidates.filter((entry) => entry.op.type === 'delete');
115
+ const acknowledgedWrites = (result.matchedCount ?? 0) + (result.upsertedCount ?? 0);
116
+ const acknowledgedDeletes = result.deletedCount ?? 0;
117
+ const missed = [];
118
+ // The counts are aggregate, so which specific documents missed is unknown; the
119
+ // caller re-reads the candidates and decides per document.
120
+ if (acknowledgedWrites < writes.length)
121
+ missed.push(...writes);
122
+ if (acknowledgedDeletes < deletes.length)
123
+ missed.push(...deletes);
124
+ return missed;
125
+ }
126
+ /**
127
+ * Re-reads the upstream state of operations that may have missed, and records a
128
+ * conflict for each one whose version really has moved on.
129
+ *
130
+ * The re-read turns an aggregate "something didn't match" into a precise, per-document
131
+ * answer, and supplies the current server document the caller needs to reconcile.
132
+ *
133
+ * @returns How many candidates genuinely lost.
134
+ */
135
+ async function describeConflicts(db, collectionName, candidates, conflicts, idMapping, ObjectId) {
136
+ const ids = candidates.map((entry) => toUpstreamId(entry.op.documentId, idMapping, ObjectId));
137
+ const current = await db
138
+ .collection(collectionName)
139
+ .find({ _id: { $in: ids } })
140
+ .toArray();
141
+ const byId = new Map(current.map((doc) => [String(doc._id), doc]));
142
+ let confirmed = 0;
143
+ for (const { index, op } of candidates) {
144
+ const serverDocument = byId.get(op.documentId);
145
+ const serverVersion = readVersion(serverDocument);
146
+ if (op.type === 'delete') {
147
+ // Already gone upstream is the outcome we wanted, however it happened.
148
+ if (!serverDocument)
149
+ continue;
150
+ conflicts.push({ index, reason: 'version-mismatch', serverDocument, serverVersion });
151
+ confirmed += 1;
152
+ continue;
153
+ }
154
+ if (!serverDocument) {
155
+ conflicts.push({ index, reason: 'missing' });
156
+ confirmed += 1;
157
+ continue;
158
+ }
159
+ // The write may have landed after all, with a different operation in the batch
160
+ // being the one that missed.
161
+ //
162
+ // A version one ahead is necessary evidence but nowhere near sufficient: another
163
+ // writer following the same protocol also bumps `_v` by exactly one, so the two
164
+ // cases look identical from the version alone. Confirming that the document
165
+ // actually carries our change is what tells them apart — and getting this wrong
166
+ // silently swallows the very conflicts this machinery exists to catch.
167
+ if (isConditional(op) &&
168
+ serverVersion === op.baseVersion + 1 &&
169
+ reflectsWrite(serverDocument, op)) {
170
+ continue;
171
+ }
172
+ conflicts.push({ index, reason: 'version-mismatch', serverDocument, serverVersion });
173
+ confirmed += 1;
174
+ }
175
+ return confirmed;
176
+ }
177
+ /**
178
+ * Splits a driver error into per-operation permanent failures.
179
+ *
180
+ * @returns The failures to dead-letter, or `null` when the error is transient and the
181
+ * whole batch should be retried.
182
+ */
183
+ export function classifyBulkError(err, operationCount) {
184
+ const error = err;
185
+ // The driver retried and still could not reach a writable primary.
186
+ if (error.hasErrorLabel?.('RetryableWriteError'))
187
+ return null;
188
+ const writeErrors = error.writeErrors ?? error.result?.writeErrors;
189
+ if (Array.isArray(writeErrors) && writeErrors.length > 0) {
190
+ const failures = [];
191
+ for (const writeError of writeErrors) {
192
+ const code = writeError.code;
193
+ // An unrecognised write error might be transient (a duplicate key during a
194
+ // failover, say), so the batch is worth retrying whole. A duplicate key is
195
+ // handled separately by the caller, as a create race rather than a defect.
196
+ if (code === undefined || (code !== DUPLICATE_KEY && !PERMANENT_ERROR_CODES.has(code))) {
197
+ return null;
198
+ }
199
+ const index = writeError.index ?? 0;
200
+ if (index >= operationCount)
201
+ return null;
202
+ failures.push({
203
+ index,
204
+ message: writeError.errmsg ?? writeError.message ?? `write error ${code}`,
205
+ code,
206
+ keyPattern: writeError.keyPattern,
207
+ });
208
+ }
209
+ return failures;
210
+ }
211
+ // No per-write detail: a connection, timeout or auth error. Retry it.
212
+ return null;
213
+ }
214
+ /**
215
+ * True when the upstream document carries the change this operation was making.
216
+ *
217
+ * Only the paths the operation itself wrote are checked. That is deliberate: those are
218
+ * the values we would have written in local JSON form, so comparing them against the
219
+ * server is meaningful, whereas fields we never touched may hold BSON types the local
220
+ * store cannot represent and would not compare equal.
221
+ *
222
+ * A false positive is possible if another writer happened to set the identical value —
223
+ * and is harmless, since the upstream then holds what we wanted anyway.
224
+ */
225
+ function reflectsWrite(serverDocument, op) {
226
+ if (op.diff) {
227
+ for (const [path, value] of Object.entries(op.diff.set)) {
228
+ if (isReservedPath(path))
229
+ continue;
230
+ if (!valueAtPathEquals(serverDocument, path, value))
231
+ return false;
232
+ }
233
+ for (const path of op.diff.unset) {
234
+ if (isReservedPath(path))
235
+ continue;
236
+ if (readPath(serverDocument, path) !== undefined)
237
+ return false;
238
+ }
239
+ return true;
240
+ }
241
+ // Whole-document write: every field we sent should be present upstream.
242
+ for (const [key, value] of Object.entries(stripReservedFields(op.document ?? {}))) {
243
+ if (!valueAtPathEquals(serverDocument, key, value))
244
+ return false;
245
+ }
246
+ return true;
247
+ }
248
+ /**
249
+ * Compares a value at a dotted path against what we wrote.
250
+ *
251
+ * The server side is flattened to local JSON shape first, so a `Date` upstream compares
252
+ * equal to the ISO string a local write would have carried.
253
+ */
254
+ function valueAtPathEquals(document, path, expected) {
255
+ const actual = readPath(document, path);
256
+ if (actual === undefined)
257
+ return false;
258
+ try {
259
+ return deepEqual(JSON.parse(JSON.stringify(actual)), expected);
260
+ }
261
+ catch {
262
+ return false;
263
+ }
264
+ }
265
+ /** Reads a dotted path, returning `undefined` if any segment is missing. */
266
+ function readPath(document, path) {
267
+ let current = document;
268
+ for (const segment of path.split('.')) {
269
+ if (typeof current !== 'object' || current === null)
270
+ return undefined;
271
+ current = current[segment];
272
+ if (current === undefined)
273
+ return undefined;
274
+ }
275
+ return current;
276
+ }
277
+ /**
278
+ * True when a duplicate-key error is about the `_id` index specifically.
279
+ *
280
+ * MongoDB reports the offending index in `keyPattern` (and names it in `errmsg`), which
281
+ * is the only way to tell "someone else created this document" apart from "this document
282
+ * violates a unique constraint on some other field".
283
+ */
284
+ function isIdIndexViolation(failure) {
285
+ if (failure.keyPattern) {
286
+ const keys = Object.keys(failure.keyPattern);
287
+ return keys.length === 1 && keys[0] === '_id';
288
+ }
289
+ // Older servers and some drivers only give the message; the index name appears in it.
290
+ return /index:\s*_id_/.test(failure.message);
291
+ }
292
+ /** Reads documents back by `_id`, for refreshing a shadow after a conflict. */
293
+ export async function fetchDocuments(db, collection, documentIds, idMapping, ObjectId) {
294
+ if (documentIds.length === 0)
295
+ return [];
296
+ const ids = documentIds.map((id) => toUpstreamId(id, idMapping, ObjectId));
297
+ return db
298
+ .collection(collection)
299
+ .find({ _id: { $in: ids } })
300
+ .toArray();
301
+ }
302
+ //# sourceMappingURL=mongoExecutor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoExecutor.js","sourceRoot":"","sources":["../../src/sync/mongoExecutor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,aAAa,EACb,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAYtC;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,CAAC,EAAE,W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AO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,SAAS,CAAC;QACtE,OAAO,GAAI,OAAmC,CAAC,OAAO,CAAC,CAAC;QACxD,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;IAC9C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,OAG3B;IACC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC;IAChD,CAAC;IACD,sFAAsF;IACtF,OAAO,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,EAAe,EACf,UAAkB,EAClB,WAAqB,EACrB,SAAyB,EACzB,QAA0B;IAE1B,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACxC,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3E,OAAO,EAAE;SACN,UAAU,CAAC,UAAU,CAAC;SACtB,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC;SAC3B,OAAO,EAAE,CAAC;AACf,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * A {@link SyncSink} that writes to a MongoDB deployment using the official
3
+ * `mongodb` driver.
4
+ *
5
+ * The driver is an **optional peer dependency**, imported dynamically the first
6
+ * time a connection is opened. Projects that never replicate upstream do not
7
+ * need it installed, and bundlers that never reach this module do not pull it in.
8
+ */
9
+ import type { MongoDriverLike, SyncApplyResult, SyncIdMapping, SyncOperation, SyncSink } from './types.js';
10
+ export { VERSION_FIELD, UPDATED_AT_FIELD } from './commands.js';
11
+ /**
12
+ * Authentication and transport settings for the upstream connection.
13
+ *
14
+ * Most deployments need nothing beyond the connection string — it already
15
+ * carries username, password, `authSource`, `replicaSet` and `tls`. These
16
+ * options cover the cases a URI cannot express, chiefly the certificate-file
17
+ * based mechanisms (X.509, mTLS, a private CA).
18
+ */
19
+ export interface MongoUpstreamAuth {
20
+ /** Database to authenticate against, when it differs from the target database. */
21
+ authSource?: string;
22
+ /**
23
+ * SASL/auth mechanism, e.g. `'SCRAM-SHA-256'`, `'MONGODB-X509'`,
24
+ * `'MONGODB-AWS'`, `'MONGODB-OIDC'`, `'GSSAPI'`, `'PLAIN'`.
25
+ * Omit to let the driver negotiate.
26
+ */
27
+ authMechanism?: string;
28
+ /** Mechanism-specific properties, e.g. `{ AWS_SESSION_TOKEN: '…' }`. */
29
+ authMechanismProperties?: Record<string, unknown>;
30
+ /** Username, when not embedded in the connection string. */
31
+ username?: string;
32
+ /** Password, when not embedded in the connection string. */
33
+ password?: string;
34
+ /** Force TLS on or off. Usually inferred from the connection string. */
35
+ tls?: boolean;
36
+ /** Path to a PEM file with the certificate authority chain, for a private CA. */
37
+ tlsCAFile?: string;
38
+ /**
39
+ * Path to a PEM file holding the client certificate **and** its private key —
40
+ * required for mutual TLS and for `MONGODB-X509` authentication.
41
+ */
42
+ tlsCertificateKeyFile?: string;
43
+ /** Passphrase for an encrypted `tlsCertificateKeyFile`. */
44
+ tlsCertificateKeyFilePassword?: string;
45
+ /** Path to a PEM file listing revoked certificates. */
46
+ tlsCRLFile?: string;
47
+ /**
48
+ * Skip hostname verification. Never enable this against a production
49
+ * deployment — it removes the protection TLS is there to provide.
50
+ */
51
+ tlsAllowInvalidHostnames?: boolean;
52
+ /**
53
+ * Accept certificates that fail validation. Never enable this against a
54
+ * production deployment.
55
+ */
56
+ tlsAllowInvalidCertificates?: boolean;
57
+ }
58
+ export interface MongoSinkOptions extends MongoUpstreamAuth {
59
+ /** Upstream connection string, e.g. `mongodb+srv://host/db`. */
60
+ connectionString: string;
61
+ /** Target database. Defaults to the one in the connection string's path. */
62
+ database?: string;
63
+ /** See {@link SyncIdMapping}. Defaults to `'auto'`. */
64
+ idMapping?: SyncIdMapping;
65
+ /**
66
+ * Guard writes with a conditional update against each document's last-known `_v`.
67
+ * Defaults to `true`. See {@link SyncOptions.versioning}.
68
+ */
69
+ versioning?: boolean;
70
+ /**
71
+ * Write concern for replicated batches. Defaults to `{ w: 'majority' }` so an
72
+ * acknowledged batch has actually survived upstream before it is checkpointed
73
+ * locally.
74
+ */
75
+ writeConcern?: Record<string, unknown>;
76
+ /**
77
+ * Extra options passed straight through to `new MongoClient(...)`. Anything
78
+ * the driver supports — `serverApi`, `proxyHost`, `compressors`,
79
+ * `autoEncryption`, connection-pool tuning — belongs here.
80
+ */
81
+ driverOptions?: Record<string, unknown>;
82
+ /**
83
+ * Supply the `mongodb` module yourself instead of having it imported
84
+ * dynamically. Useful for bundlers that cannot resolve dynamic imports, and
85
+ * for tests.
86
+ */
87
+ driver?: MongoDriverLike;
88
+ }
89
+ export declare class MongoUpstreamSink implements SyncSink {
90
+ private readonly options;
91
+ readonly name = "mongodb";
92
+ private client;
93
+ private db;
94
+ private driver;
95
+ private readonly idMapping;
96
+ private readonly versioning;
97
+ constructor(options: MongoSinkOptions);
98
+ connect(): Promise<void>;
99
+ apply(operations: SyncOperation[]): Promise<SyncApplyResult>;
100
+ /**
101
+ * Command-building settings. The driver's own `ObjectId` is used when available so
102
+ * BSON instances match the connection that will serialise them.
103
+ */
104
+ private commandOptions;
105
+ fetch(collection: string, documentIds: string[]): Promise<Record<string, unknown>[]>;
106
+ close(): Promise<void>;
107
+ private loadDriver;
108
+ private clientOptions;
109
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * A {@link SyncSink} that writes to a MongoDB deployment using the official
3
+ * `mongodb` driver.
4
+ *
5
+ * The driver is an **optional peer dependency**, imported dynamically the first
6
+ * time a connection is opened. Projects that never replicate upstream do not
7
+ * need it installed, and bundlers that never reach this module do not pull it in.
8
+ */
9
+ import { buildWriteCommand } from './commands.js';
10
+ import { executeWrites, fetchDocuments } from './mongoExecutor.js';
11
+ export { VERSION_FIELD, UPDATED_AT_FIELD } from './commands.js';
12
+ export class MongoUpstreamSink {
13
+ constructor(options) {
14
+ this.options = options;
15
+ this.name = 'mongodb';
16
+ this.client = null;
17
+ this.db = null;
18
+ this.driver = null;
19
+ if (!options.connectionString) {
20
+ throw new Error('MongoUpstreamSink requires a `connectionString`.');
21
+ }
22
+ this.idMapping = options.idMapping ?? 'auto';
23
+ this.versioning = options.versioning ?? true;
24
+ this.driver = options.driver ?? null;
25
+ }
26
+ async connect() {
27
+ if (this.client && this.db)
28
+ return;
29
+ const driver = await this.loadDriver();
30
+ const client = new driver.MongoClient(this.options.connectionString, this.clientOptions());
31
+ await client.connect();
32
+ this.client = client;
33
+ this.db = client.db(this.options.database);
34
+ }
35
+ async apply(operations) {
36
+ if (!this.db)
37
+ await this.connect();
38
+ const db = this.db;
39
+ if (!db)
40
+ throw new Error('MongoUpstreamSink is not connected.');
41
+ const writes = operations.map((op, index) => ({
42
+ index,
43
+ op,
44
+ command: buildWriteCommand(op, this.commandOptions()),
45
+ }));
46
+ return executeWrites(db, writes, {
47
+ writeConcern: this.options.writeConcern ?? { w: 'majority' },
48
+ versioning: this.versioning,
49
+ idMapping: this.idMapping,
50
+ ObjectId: this.driver?.ObjectId,
51
+ });
52
+ }
53
+ /**
54
+ * Command-building settings. The driver's own `ObjectId` is used when available so
55
+ * BSON instances match the connection that will serialise them.
56
+ */
57
+ commandOptions() {
58
+ return {
59
+ idMapping: this.idMapping,
60
+ versioning: this.versioning,
61
+ ObjectId: this.driver?.ObjectId,
62
+ };
63
+ }
64
+ async fetch(collection, documentIds) {
65
+ if (documentIds.length === 0)
66
+ return [];
67
+ if (!this.db)
68
+ await this.connect();
69
+ const db = this.db;
70
+ if (!db)
71
+ throw new Error('MongoUpstreamSink is not connected.');
72
+ return fetchDocuments(db, collection, documentIds, this.idMapping, this.driver?.ObjectId);
73
+ }
74
+ async close() {
75
+ const client = this.client;
76
+ this.client = null;
77
+ this.db = null;
78
+ if (client)
79
+ await client.close();
80
+ }
81
+ // ---------------------------------------------------------------- internals
82
+ async loadDriver() {
83
+ if (this.driver)
84
+ return this.driver;
85
+ try {
86
+ // Indirect specifier: `mongodb` is optional, and a literal import would
87
+ // make it a hard build-time dependency for everyone compiling this package.
88
+ const specifier = 'mongodb';
89
+ const mod = (await import(specifier));
90
+ this.driver = mod;
91
+ return mod;
92
+ }
93
+ catch (err) {
94
+ throw new Error('MongoDB sync requires the `mongodb` driver. Install it with `npm install mongodb`, ' +
95
+ `or pass a \`driver\` explicitly. Original error: ${err instanceof Error ? err.message : String(err)}`);
96
+ }
97
+ }
98
+ clientOptions() {
99
+ const { authSource, authMechanism, authMechanismProperties, username, password, tls, tlsCAFile, tlsCertificateKeyFile, tlsCertificateKeyFilePassword, tlsCRLFile, tlsAllowInvalidHostnames, tlsAllowInvalidCertificates, driverOptions, } = this.options;
100
+ const auth = username !== undefined || password !== undefined ? { username, password } : undefined;
101
+ // Undefined keys are stripped so they never override a setting that the
102
+ // connection string already specified.
103
+ return stripUndefined({
104
+ authSource,
105
+ authMechanism,
106
+ authMechanismProperties,
107
+ auth,
108
+ tls,
109
+ tlsCAFile,
110
+ tlsCertificateKeyFile,
111
+ tlsCertificateKeyFilePassword,
112
+ tlsCRLFile,
113
+ tlsAllowInvalidHostnames,
114
+ tlsAllowInvalidCertificates,
115
+ ...driverOptions,
116
+ });
117
+ }
118
+ }
119
+ /** Drops unset keys so they never override what the connection string specified. */
120
+ function stripUndefined(value) {
121
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
122
+ }
123
+ //# sourceMappingURL=mongoSink.js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