@omegup/msync 0.1.62 → 0.1.63
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/adapters/mongodb.d.ts +22 -0
- package/adapters/mongodb.esm.js +12 -0
- package/adapters/mongodb.esm.js.map +1 -0
- package/adapters/mongodb.js +14 -0
- package/adapters/mongodb.js.map +1 -0
- package/driver-BUCc3b89.js +31 -0
- package/driver-BUCc3b89.js.map +1 -0
- package/driver-sc6MCG57.esm.js +14 -0
- package/driver-sc6MCG57.esm.js.map +1 -0
- package/index.d.ts +1 -1
- package/index.esm.js +28 -102
- package/index.esm.js.map +1 -1
- package/index.js +28 -86
- package/index.js.map +1 -1
- package/lib/accumulators/index.d.ts +1 -1
- package/lib/aggregate/$merge.d.ts +5 -5
- package/lib/aggregate/group/utils/sub-merge.d.ts +2 -2
- package/lib/aggregate/prefix.d.ts +2 -2
- package/lib/boot/boot-utils.d.ts +2 -3
- package/lib/boot/boot.d.ts +2 -2
- package/lib/boot/first-stages.d.ts +1 -2
- package/lib/driver.d.ts +5 -0
- package/lib/expression/val.d.ts +1 -1
- package/lib/predicate/$eq.d.ts +1 -2
- package/lib/types/accumulator.d.ts +2 -2
- package/lib/types/aggregate.d.ts +4 -2
- package/lib/types/query.d.ts +1 -5
- package/lib/types/stream.d.ts +3 -4
- package/lib/utils/db-indexes.d.ts +1 -1
- package/lib/utils/map-object.d.ts +0 -4
- package/lib/utils/merge/merge.d.ts +5 -4
- package/lib/utils/merge/next-winner.d.ts +2 -1
- package/lib/utils/merge/types.d.ts +9 -5
- package/lib/utils/merge/utils.d.ts +4 -2
- package/lib/watch.d.ts +2 -3
- package/package.json +41 -22
- package/types/global-aug.d.ts +1 -1
- package/types/json.d.ts +12 -4
- package/types/mongo.d.ts +83 -23
- package/types/view.d.ts +1 -2
- package/test/mongodb.d.ts +0 -9
- package/test/uri.d.ts +0 -1
package/index.js
CHANGED
|
@@ -6,15 +6,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __exportAll = (all, no_symbols) => {
|
|
10
|
-
let target = {};
|
|
11
|
-
for (var name in all) __defProp(target, name, {
|
|
12
|
-
get: all[name],
|
|
13
|
-
enumerable: true
|
|
14
|
-
});
|
|
15
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
-
return target;
|
|
17
|
-
};
|
|
18
9
|
var __copyProps = (to, from, except, desc) => {
|
|
19
10
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
11
|
key = keys[i];
|
|
@@ -25,17 +16,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
16
|
}
|
|
26
17
|
return to;
|
|
27
18
|
};
|
|
28
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
29
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
30
20
|
value: mod,
|
|
31
21
|
enumerable: true
|
|
32
22
|
}) : target, mod));
|
|
33
23
|
//#endregion
|
|
34
|
-
|
|
24
|
+
const require_driver = require("./driver-BUCc3b89.js");
|
|
35
25
|
let crypto$1 = require("crypto");
|
|
36
26
|
crypto$1 = __toESM(crypto$1, 1);
|
|
37
27
|
let json_canonicalize = require("json-canonicalize");
|
|
38
|
-
let fs_promises = require("fs/promises");
|
|
39
28
|
//#region .build/lib/expression/expr-base.js
|
|
40
29
|
const asExprRaw = (raw) => ({ get: () => raw });
|
|
41
30
|
const asExpr = (r) => r;
|
|
@@ -80,7 +69,6 @@ const map1 = (k, to) => {
|
|
|
80
69
|
};
|
|
81
70
|
//#endregion
|
|
82
71
|
//#region .build/lib/utils/map-object.js
|
|
83
|
-
const map = (x, f) => Object.fromEntries(Object.entries(x).map(([k, v]) => [k, f(v, k)]));
|
|
84
72
|
const mapExactToObject0 = (x, f) => {
|
|
85
73
|
const filter = (x) => x.filter((x) => x[0] === x[1][0]);
|
|
86
74
|
const matched = filter(Object.entries(x));
|
|
@@ -666,8 +654,8 @@ const getSubsetMatchForExt = (ext) => {
|
|
|
666
654
|
};
|
|
667
655
|
const getWhenMatchedForMerge = (whenNotMatched, update, canWrite) => {
|
|
668
656
|
const orNull = (e) => whenNotMatched === "discard" ? $ifNull(e, nil) : e;
|
|
669
|
-
const
|
|
670
|
-
const merged = mergeObjects(root().expr(), update(ctx()("new").expr(), root().expr()), field({ deletedAt: ["deletedAt",
|
|
657
|
+
const deletedAt = orNull((whenNotMatched === "insert" ? ctx()("new") : root()).of("deletedAt").expr());
|
|
658
|
+
const merged = mergeObjects(root().expr(), update(ctx()("new").expr(), root().expr()), field({ deletedAt: ["deletedAt", deletedAt] }));
|
|
671
659
|
return link().with($replaceWith_(field({
|
|
672
660
|
old: ["old", root().expr()],
|
|
673
661
|
merged: ["merged", merged]
|
|
@@ -825,14 +813,6 @@ const $group = (id, args, out, extra, idPrefix = "") => $groupMerge(id, args, {
|
|
|
825
813
|
whenNotMatched: "insert"
|
|
826
814
|
}, "_grp", extra, idPrefix);
|
|
827
815
|
//#endregion
|
|
828
|
-
//#region .build/types/mongo.js
|
|
829
|
-
var mongo_exports = /* @__PURE__ */ __exportAll({});
|
|
830
|
-
__reExport(mongo_exports, require("mongodb"));
|
|
831
|
-
//#endregion
|
|
832
|
-
//#region .build/types/index.js
|
|
833
|
-
var types_exports = /* @__PURE__ */ __exportAll({});
|
|
834
|
-
__reExport(types_exports, mongo_exports);
|
|
835
|
-
//#endregion
|
|
836
816
|
//#region .build/lib/aggregate/set/$replace-with-each.js
|
|
837
817
|
const deltaExpr = (expr) => (field) => {
|
|
838
818
|
return ite(eqTyped($ifNull(root().of(field).expr(), nil), nil), nil, expr(field));
|
|
@@ -1182,6 +1162,7 @@ const ensureCollection = async (db, collectionName) => {
|
|
|
1182
1162
|
};
|
|
1183
1163
|
//#endregion
|
|
1184
1164
|
//#region .build/lib/utils/merge/utils.js
|
|
1165
|
+
const map = (x, f) => Object.fromEntries(Object.entries(x).map(([k, v]) => [k, f(v, k)]));
|
|
1185
1166
|
const patch = ({ ...x }, k, v) => {
|
|
1186
1167
|
delete x[k];
|
|
1187
1168
|
return {
|
|
@@ -1193,10 +1174,12 @@ const restart = (sources) => {
|
|
|
1193
1174
|
return map(sources, (x) => x.stop());
|
|
1194
1175
|
};
|
|
1195
1176
|
const race = (sources) => {
|
|
1196
|
-
const promises = Object.values(map(sources, (
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1177
|
+
const promises = Object.values(map(sources, (p, key) => {
|
|
1178
|
+
return p.next.then((frame) => ({
|
|
1179
|
+
key,
|
|
1180
|
+
frame
|
|
1181
|
+
}), (error) => new Error(error));
|
|
1182
|
+
}));
|
|
1200
1183
|
return Promise.any(promises).then((result) => {
|
|
1201
1184
|
if (result instanceof Error) throw result;
|
|
1202
1185
|
else return result;
|
|
@@ -1252,7 +1235,7 @@ const mergeIterators = (params) => {
|
|
|
1252
1235
|
}),
|
|
1253
1236
|
next: select(sources).then(makeReiterate(sources, interrupt, hooks)),
|
|
1254
1237
|
clear: async () => {
|
|
1255
|
-
for (const key in sources) await sources[key]
|
|
1238
|
+
for (const key in sources) await sources[key]?.clear();
|
|
1256
1239
|
}
|
|
1257
1240
|
};
|
|
1258
1241
|
};
|
|
@@ -1375,9 +1358,9 @@ const join = (params, leftSnapshot, rightSnapshot, stagesUntilNextLookup, outerL
|
|
|
1375
1358
|
teardown: final.teardown
|
|
1376
1359
|
}, async () => {
|
|
1377
1360
|
log("Creating indexes for lookup left", leftSnapshot.coll.collectionName, { [`before.${lField.str()}`]: 1 });
|
|
1378
|
-
await createIndex(leftSnapshot.coll, { [`before.${lField.str()}`]: 1 }, { name: "left_" + new
|
|
1361
|
+
await createIndex(leftSnapshot.coll, { [`before.${lField.str()}`]: 1 }, { name: "left_" + new (require_driver.driver()).UUID().toString("base64") });
|
|
1379
1362
|
log("Creating indexes for lookup right", rightSnapshot.coll.collectionName, { [`before.${rField.str()}`]: 1 });
|
|
1380
|
-
await createIndex(rightSnapshot.coll, { [`before.${rField.str()}`]: 1 }, { name: "right_" + new
|
|
1363
|
+
await createIndex(rightSnapshot.coll, { [`before.${rField.str()}`]: 1 }, { name: "right_" + new (require_driver.driver()).UUID().toString("base64") });
|
|
1381
1364
|
});
|
|
1382
1365
|
const lRunner = getRunner(left, lRunnerInput, finalInput);
|
|
1383
1366
|
const rRunner = getRunner(right, rRunnerInput, finalInput);
|
|
@@ -1523,12 +1506,12 @@ const addTeardown = (it, tr) => {
|
|
|
1523
1506
|
//#endregion
|
|
1524
1507
|
//#region .build/lib/watch.js
|
|
1525
1508
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1526
|
-
const maxTimestamp = new
|
|
1509
|
+
const maxTimestamp = () => new (require_driver.driver()).Timestamp(18446744073709551615n);
|
|
1527
1510
|
const getCurrentTimestamp = async (db) => {
|
|
1528
|
-
return (await db.admin().command({ serverStatus: 1 }))
|
|
1511
|
+
return (await db.admin().command({ serverStatus: 1 })).operationTime;
|
|
1529
1512
|
};
|
|
1530
1513
|
async function getLastCommittedTs(adminDb) {
|
|
1531
|
-
return (await adminDb.command({ replSetGetStatus: 1 }))
|
|
1514
|
+
return (await adminDb.command({ replSetGetStatus: 1 })).optimes?.lastCommittedOpTime?.ts ?? null;
|
|
1532
1515
|
}
|
|
1533
1516
|
async function waitUntilStablePast(db, oplogTs, { pollMs = 0, timeoutMs = 1e4 } = {}) {
|
|
1534
1517
|
const adminDb = db.client.db("admin");
|
|
@@ -1671,7 +1654,7 @@ const register = (coll, keys, match, cb) => {
|
|
|
1671
1654
|
let maxKeysRemoved = null;
|
|
1672
1655
|
const makeWatchStream = async ({ collection, projection: p, hardMatch: m }, streamName) => {
|
|
1673
1656
|
const { db } = collection.s;
|
|
1674
|
-
await (maxKeysRemoved ??= Promise.all((await db.listCollections({}, { nameOnly: true }).toArray()).map((x) => void db.collection(x.name).updateMany({ touchedAt: maxTimestamp }, [{ $set: { touchedAt: "$$CLUSTER_TIME" } }]))).then(() => {}));
|
|
1657
|
+
await (maxKeysRemoved ??= Promise.all((await db.listCollections({}, { nameOnly: true }).toArray()).map((x) => void db.collection(x.name).updateMany({ touchedAt: maxTimestamp() }, [{ $set: { touchedAt: "$$CLUSTER_TIME" } }]))).then(() => {}));
|
|
1675
1658
|
const projection = {
|
|
1676
1659
|
...p ? mapExactToObject(p, (v) => v) : {},
|
|
1677
1660
|
deletedAt: 1
|
|
@@ -1722,7 +1705,7 @@ const $nor = combine("$nor", filterUndefined(all));
|
|
|
1722
1705
|
const $or = combine("$or", filterUndefined(first$1));
|
|
1723
1706
|
//#endregion
|
|
1724
1707
|
//#region .build/lib/boot/first-stages.js
|
|
1725
|
-
const previous = (ts) => new
|
|
1708
|
+
const previous = (ts) => new (require_driver.driver()).Timestamp({
|
|
1726
1709
|
t: ts.high - 60,
|
|
1727
1710
|
i: 0
|
|
1728
1711
|
});
|
|
@@ -1830,11 +1813,11 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1830
1813
|
log("creating indexes");
|
|
1831
1814
|
await createIndex(snapshotCollection, { before: 1 }, {
|
|
1832
1815
|
partialFilterExpression: { before: null },
|
|
1833
|
-
name: "before_" +
|
|
1816
|
+
name: "before_" + require_driver.uuid()
|
|
1834
1817
|
});
|
|
1835
1818
|
await createIndex(snapshotCollection, { updated: 1 }, {
|
|
1836
1819
|
partialFilterExpression: { updated: true },
|
|
1837
|
-
name: "updated_" +
|
|
1820
|
+
name: "updated_" + require_driver.uuid()
|
|
1838
1821
|
});
|
|
1839
1822
|
await createIndex(snapshotCollection, {
|
|
1840
1823
|
updated: 1,
|
|
@@ -1846,7 +1829,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1846
1829
|
after: null,
|
|
1847
1830
|
before: null
|
|
1848
1831
|
},
|
|
1849
|
-
name: "updated_nulls_" +
|
|
1832
|
+
name: "updated_nulls_" + require_driver.uuid()
|
|
1850
1833
|
});
|
|
1851
1834
|
await createIndex(snapshotCollection, {
|
|
1852
1835
|
updated: 1,
|
|
@@ -1856,7 +1839,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1856
1839
|
updated: true,
|
|
1857
1840
|
after: null
|
|
1858
1841
|
},
|
|
1859
|
-
name: "updated_no_after_" +
|
|
1842
|
+
name: "updated_no_after_" + require_driver.uuid()
|
|
1860
1843
|
});
|
|
1861
1844
|
await createIndex(snapshotCollection, { updated: 1 }, {
|
|
1862
1845
|
partialFilterExpression: {
|
|
@@ -1864,7 +1847,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1864
1847
|
after: null,
|
|
1865
1848
|
before: null
|
|
1866
1849
|
},
|
|
1867
|
-
name: "updated_nulls_" +
|
|
1850
|
+
name: "updated_nulls_" + require_driver.uuid()
|
|
1868
1851
|
});
|
|
1869
1852
|
await ensureCollection(db, coll);
|
|
1870
1853
|
await db.command({
|
|
@@ -1873,7 +1856,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1873
1856
|
});
|
|
1874
1857
|
await createIndex(collection, { touchedAt: 1 }, hardMatch ? {
|
|
1875
1858
|
partialFilterExpression: hardMatch.raw(root()),
|
|
1876
|
-
name: "touchedAt_hard_" +
|
|
1859
|
+
name: "touchedAt_hard_" + require_driver.uuid()
|
|
1877
1860
|
} : {});
|
|
1878
1861
|
await setup?.();
|
|
1879
1862
|
await after?.();
|
|
@@ -1917,7 +1900,8 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1917
1900
|
}), "run the aggregation", () => stream.close());
|
|
1918
1901
|
};
|
|
1919
1902
|
const makeStream = () => makeWatchStream(view, streamName);
|
|
1920
|
-
const step4 = (
|
|
1903
|
+
const step4 = (args) => async () => {
|
|
1904
|
+
const { result, ts, stream } = args;
|
|
1921
1905
|
const start = Date.now();
|
|
1922
1906
|
log("snapshot", streamName, "ensure before null", Date.now() - start);
|
|
1923
1907
|
const first = ts === void 0;
|
|
@@ -2054,7 +2038,7 @@ const executes$1 = (view, input, streamName, needs) => {
|
|
|
2054
2038
|
});
|
|
2055
2039
|
await createIndex(collection, { touchedAt: 1 }, {
|
|
2056
2040
|
partialFilterExpression: { deletedAt: { $eq: null } },
|
|
2057
|
-
name: "touchedAt_" + new
|
|
2041
|
+
name: "touchedAt_" + new (require_driver.driver()).UUID().toString("base64")
|
|
2058
2042
|
});
|
|
2059
2043
|
log("stream started", {
|
|
2060
2044
|
streamName,
|
|
@@ -2159,45 +2143,6 @@ const executes = (view, input, needs) => {
|
|
|
2159
2143
|
};
|
|
2160
2144
|
const single = (view, needs = {}) => pipe((input) => executes(view, input, needs), emptyDelta(), concatDelta, emptyDelta);
|
|
2161
2145
|
//#endregion
|
|
2162
|
-
//#region .build/test/uri.js
|
|
2163
|
-
require("dotenv").config();
|
|
2164
|
-
const uri = process.env["MONGO_URL"];
|
|
2165
|
-
//#endregion
|
|
2166
|
-
//#region .build/test/mongodb.js
|
|
2167
|
-
const enablePreAndPostImages = (coll) => coll.s.db.command({
|
|
2168
|
-
collMod: coll.collectionName,
|
|
2169
|
-
changeStreamPreAndPostImages: { enabled: true }
|
|
2170
|
-
});
|
|
2171
|
-
const prepare = async (testName) => {
|
|
2172
|
-
const client = new mongodb.MongoClient(uri, testName ? { monitorCommands: true } : {});
|
|
2173
|
-
if (testName) {
|
|
2174
|
-
const handler = (c) => {
|
|
2175
|
-
(0, fs_promises.writeFile)(`./out/${testName}.log`, JSON.stringify(c.command) + ",\n", { flag: "w" });
|
|
2176
|
-
};
|
|
2177
|
-
client.on("commandStarted", handler);
|
|
2178
|
-
client.on("commandSucceeded", handler);
|
|
2179
|
-
}
|
|
2180
|
-
await client.connect();
|
|
2181
|
-
await client.db("admin").command({ setClusterParameter: { changeStreamOptions: { preAndPostImages: { expireAfterSeconds: 60 } } } });
|
|
2182
|
-
return client;
|
|
2183
|
-
};
|
|
2184
|
-
const clears = [];
|
|
2185
|
-
const makeCol = async (docs, database, name) => {
|
|
2186
|
-
if (!name) {
|
|
2187
|
-
const n = name = crypto.randomUUID();
|
|
2188
|
-
clears.push(async () => {
|
|
2189
|
-
await database.collection(n).drop({ ignoreUndefined: true });
|
|
2190
|
-
});
|
|
2191
|
-
}
|
|
2192
|
-
try {
|
|
2193
|
-
const col = await database.createCollection(name, { changeStreamPreAndPostImages: { enabled: true } });
|
|
2194
|
-
if (docs.length) await col.insertMany([...docs]);
|
|
2195
|
-
return col;
|
|
2196
|
-
} catch {
|
|
2197
|
-
return database.collection(name);
|
|
2198
|
-
}
|
|
2199
|
-
};
|
|
2200
|
-
//#endregion
|
|
2201
2146
|
exports.$accumulator = $accumulator;
|
|
2202
2147
|
exports.$and = $and;
|
|
2203
2148
|
exports.$countDict = $countDict;
|
|
@@ -2273,7 +2218,6 @@ exports.datePart = datePart;
|
|
|
2273
2218
|
exports.dayAndMonthPart = dayAndMonthPart;
|
|
2274
2219
|
exports.divide = divide;
|
|
2275
2220
|
exports.emptyDelta = emptyDelta;
|
|
2276
|
-
exports.enablePreAndPostImages = enablePreAndPostImages;
|
|
2277
2221
|
exports.eq = eq;
|
|
2278
2222
|
exports.eqTyped = eqTyped;
|
|
2279
2223
|
exports.except = except;
|
|
@@ -2303,8 +2247,6 @@ exports.literalsEqaul = literalsEqaul;
|
|
|
2303
2247
|
exports.log = log;
|
|
2304
2248
|
exports.lt = lt;
|
|
2305
2249
|
exports.lte = lte;
|
|
2306
|
-
exports.makeCol = makeCol;
|
|
2307
|
-
exports.map = map;
|
|
2308
2250
|
exports.map1 = map1;
|
|
2309
2251
|
exports.mapExact = mapExact;
|
|
2310
2252
|
exports.mapExact0 = mapExact0;
|
|
@@ -2334,7 +2276,6 @@ exports.notNull = notNull;
|
|
|
2334
2276
|
exports.now = now;
|
|
2335
2277
|
exports.or = or;
|
|
2336
2278
|
exports.padLeft = padLeft;
|
|
2337
|
-
exports.prepare = prepare;
|
|
2338
2279
|
exports.rand = rand;
|
|
2339
2280
|
exports.range = range;
|
|
2340
2281
|
exports.reflex = reflex;
|
|
@@ -2356,6 +2297,7 @@ exports.subtract = subtract;
|
|
|
2356
2297
|
exports.sym = sym;
|
|
2357
2298
|
exports.to = to;
|
|
2358
2299
|
exports.toInt = toInt;
|
|
2300
|
+
exports.useDriver = require_driver.useDriver;
|
|
2359
2301
|
exports.val = val;
|
|
2360
2302
|
exports.weekPart = weekPart;
|
|
2361
2303
|
exports.wrap = wrap;
|