@omegup/msync 0.1.28 → 0.1.29
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/index.d.ts +2 -1
- package/index.esm.js +21 -9
- package/index.js +21 -8
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -327,6 +327,7 @@ type View<V extends Model, K extends StrKey<V>> = {
|
|
|
327
327
|
};
|
|
328
328
|
|
|
329
329
|
declare const val: <T extends rawItem>(val: T) => Expr<T, unknown>;
|
|
330
|
+
declare const afterWriteTime: Expr<Timestamp, unknown>;
|
|
330
331
|
declare const current: Expr<Timestamp, unknown>;
|
|
331
332
|
declare const $let: <T, D, C, V extends RORec<string, jsonItem>>(vars: ExprsExact<V, D, C>, inExpr: Expr<T, D, C & V>) => Expr<T, D, C>;
|
|
332
333
|
declare const nil: Expr<null, unknown>;
|
|
@@ -680,5 +681,5 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
|
|
|
680
681
|
declare const prepare: (testName?: string) => Promise<MongoClient$1>;
|
|
681
682
|
declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
|
|
682
683
|
|
|
683
|
-
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Expr, Field, Machine, Type, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
|
|
684
|
+
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Expr, Field, Machine, Type, add, afterWriteTime, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
|
|
684
685
|
export type { Accumulators, Arr, AsLiteral, Delta, DeltaAccumulator, DeltaAccumulators, ExactKeys, ExprHKT, Exprs, ExprsExact, ExprsExactHKT, ExprsPart, ID, Loose, Merge, MergeArgs, MergeInto, MergeMapOArgs, Model, MongoTypeNames, N, NoRaw, NullToOBJ, O, OPick, OPickD, Patch, RONoRaw, RORec, RawStages, Rec, Replace, SnapshotStreamExecutionResult, StrKey, Strict, TS, WriteonlyCollection, doc, jsonPrim, notArr };
|
package/index.esm.js
CHANGED
|
@@ -81,9 +81,12 @@ const val = (val) => asExpr({
|
|
|
81
81
|
? { $literal: val }
|
|
82
82
|
: val),
|
|
83
83
|
});
|
|
84
|
-
const
|
|
84
|
+
const afterWriteTime = asExpr({
|
|
85
85
|
raw: () => asExprRaw(new Timestamp(0xffffffffffffffffn)),
|
|
86
86
|
});
|
|
87
|
+
const current = asExpr({
|
|
88
|
+
raw: () => asExprRaw('$$CLUSTER_TIME'),
|
|
89
|
+
});
|
|
87
90
|
const $let = (vars, inExpr) => asExpr({
|
|
88
91
|
raw: f => asExprRaw({
|
|
89
92
|
$let: {
|
|
@@ -842,7 +845,7 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
842
845
|
const setDeleted = out.whenNotMatched === 'discard';
|
|
843
846
|
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
844
847
|
_id: ['_id', f.of('_id').expr()],
|
|
845
|
-
touchedAt: ['touchedAt',
|
|
848
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
846
849
|
}))));
|
|
847
850
|
const sss = setDeleted
|
|
848
851
|
? link()
|
|
@@ -886,7 +889,7 @@ const $mergeId = () => (out, keys, id, ext) => {
|
|
|
886
889
|
return $mergeX(out, keys, root().of('after'), or => {
|
|
887
890
|
return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
|
|
888
891
|
_id: ['_id', id],
|
|
889
|
-
touchedAt: ['touchedAt',
|
|
892
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
890
893
|
}))), or);
|
|
891
894
|
}, ext);
|
|
892
895
|
};
|
|
@@ -908,7 +911,7 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
908
911
|
const mapId = (k, v) => map1(k, v);
|
|
909
912
|
const F1 = {
|
|
910
913
|
_id: ['_id', to(idPrefix ? concat$1(val(idPrefix), $rand) : $rand)],
|
|
911
|
-
touchedAt: ['touchedAt', to(
|
|
914
|
+
touchedAt: ['touchedAt', to(afterWriteTime)],
|
|
912
915
|
};
|
|
913
916
|
const F2 = mapId(gid, to(gidPath));
|
|
914
917
|
const addExtraAndMerge = {
|
|
@@ -918,7 +921,8 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
918
921
|
};
|
|
919
922
|
const addTSAndExtra = {
|
|
920
923
|
...mapExact0(e, to),
|
|
921
|
-
|
|
924
|
+
...(out.whenNotMatched === 'insert' ? { deletedAt: ['deletedAt', to(nil)] } : {}),
|
|
925
|
+
touchedAt: ['touchedAt', to(afterWriteTime)],
|
|
922
926
|
};
|
|
923
927
|
const updater = set()(addTSAndExtra);
|
|
924
928
|
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
@@ -1280,7 +1284,8 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1280
1284
|
}
|
|
1281
1285
|
catch (e) {
|
|
1282
1286
|
if ([85, 276].includes(e.code)) {
|
|
1283
|
-
log('Index created with different name', e.code, {
|
|
1287
|
+
log('Index created with different name', e.code, {
|
|
1288
|
+
collection: collection.collectionName});
|
|
1284
1289
|
break;
|
|
1285
1290
|
}
|
|
1286
1291
|
if (e.code == 12587) {
|
|
@@ -1295,6 +1300,11 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1295
1300
|
break;
|
|
1296
1301
|
}
|
|
1297
1302
|
};
|
|
1303
|
+
const ensureCollection = async (db, collectionName) => {
|
|
1304
|
+
if (!(await db.listCollections({ name: collectionName }, { nameOnly: true }).next())) {
|
|
1305
|
+
await db.createCollection(collectionName);
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1298
1308
|
|
|
1299
1309
|
const patch = ({ ...x }, k, v) => {
|
|
1300
1310
|
delete x[k];
|
|
@@ -1530,7 +1540,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1530
1540
|
raw: () => {
|
|
1531
1541
|
const replacer = map(mergeObjects(expr, field(mergeExpr(extExpr, {
|
|
1532
1542
|
deletedAt: ['deletedAt', nil],
|
|
1533
|
-
touchedAt: ['touchedAt',
|
|
1543
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
1534
1544
|
}))));
|
|
1535
1545
|
return link()
|
|
1536
1546
|
.with($replaceWith_(replacer))
|
|
@@ -1550,7 +1560,7 @@ const $insertPart = (out, ext) => {
|
|
|
1550
1560
|
return $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(extExpr), {
|
|
1551
1561
|
deletedAt: ['deletedAt', current],
|
|
1552
1562
|
_id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
|
|
1553
|
-
touchedAt: ['touchedAt',
|
|
1563
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
1554
1564
|
})), x), ext, extExpr);
|
|
1555
1565
|
};
|
|
1556
1566
|
const $insert = (out) => $insertPart(out, {});
|
|
@@ -1967,6 +1977,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1967
1977
|
partialFilterExpression: { updated: true, after: null, before: null },
|
|
1968
1978
|
name: 'updated_nulls_' + new UUID().toString('base64'),
|
|
1969
1979
|
});
|
|
1980
|
+
await ensureCollection(db, coll);
|
|
1970
1981
|
await db.command({
|
|
1971
1982
|
collMod: coll,
|
|
1972
1983
|
changeStreamPreAndPostImages: { enabled: true },
|
|
@@ -2148,6 +2159,7 @@ const executes$1 = (view, input, streamName, needs) => {
|
|
|
2148
2159
|
const stop = withStop(step0);
|
|
2149
2160
|
const step1 = async () => {
|
|
2150
2161
|
log('creating indexes');
|
|
2162
|
+
await ensureCollection(db, coll);
|
|
2151
2163
|
await db.command({
|
|
2152
2164
|
collMod: coll,
|
|
2153
2165
|
changeStreamPreAndPostImages: { enabled: true },
|
|
@@ -2238,4 +2250,4 @@ const executes = (view, input, needs) => {
|
|
|
2238
2250
|
};
|
|
2239
2251
|
const single = (view, needs = {}) => pipe(input => executes(view, input, needs), emptyDelta(), concatDelta, emptyDelta);
|
|
2240
2252
|
|
|
2241
|
-
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
|
|
2253
|
+
export { $accumulator, $and, $countDict, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, afterWriteTime, and, anyElementTrue, array, ceil, comp, concat$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
|
package/index.js
CHANGED
|
@@ -83,9 +83,12 @@ const val = (val) => asExpr({
|
|
|
83
83
|
? { $literal: val }
|
|
84
84
|
: val),
|
|
85
85
|
});
|
|
86
|
-
const
|
|
86
|
+
const afterWriteTime = asExpr({
|
|
87
87
|
raw: () => asExprRaw(new mongodb.Timestamp(0xffffffffffffffffn)),
|
|
88
88
|
});
|
|
89
|
+
const current = asExpr({
|
|
90
|
+
raw: () => asExprRaw('$$CLUSTER_TIME'),
|
|
91
|
+
});
|
|
89
92
|
const $let = (vars, inExpr) => asExpr({
|
|
90
93
|
raw: f => asExprRaw({
|
|
91
94
|
$let: {
|
|
@@ -844,7 +847,7 @@ const $mergeX = (out, keys, f, map, ext) => {
|
|
|
844
847
|
const setDeleted = out.whenNotMatched === 'discard';
|
|
845
848
|
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
846
849
|
_id: ['_id', f.of('_id').expr()],
|
|
847
|
-
touchedAt: ['touchedAt',
|
|
850
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
848
851
|
}))));
|
|
849
852
|
const sss = setDeleted
|
|
850
853
|
? link()
|
|
@@ -888,7 +891,7 @@ const $mergeId = () => (out, keys, id, ext) => {
|
|
|
888
891
|
return $mergeX(out, keys, root().of('after'), or => {
|
|
889
892
|
return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
|
|
890
893
|
_id: ['_id', id],
|
|
891
|
-
touchedAt: ['touchedAt',
|
|
894
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
892
895
|
}))), or);
|
|
893
896
|
}, ext);
|
|
894
897
|
};
|
|
@@ -910,7 +913,7 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
910
913
|
const mapId = (k, v) => map1(k, v);
|
|
911
914
|
const F1 = {
|
|
912
915
|
_id: ['_id', to(idPrefix ? concat$1(val(idPrefix), $rand) : $rand)],
|
|
913
|
-
touchedAt: ['touchedAt', to(
|
|
916
|
+
touchedAt: ['touchedAt', to(afterWriteTime)],
|
|
914
917
|
};
|
|
915
918
|
const F2 = mapId(gid, to(gidPath));
|
|
916
919
|
const addExtraAndMerge = {
|
|
@@ -920,7 +923,8 @@ const subMerge = (args, out, gid, extra, idPrefix, first) => {
|
|
|
920
923
|
};
|
|
921
924
|
const addTSAndExtra = {
|
|
922
925
|
...mapExact0(e, to),
|
|
923
|
-
|
|
926
|
+
...(out.whenNotMatched === 'insert' ? { deletedAt: ['deletedAt', to(nil)] } : {}),
|
|
927
|
+
touchedAt: ['touchedAt', to(afterWriteTime)],
|
|
924
928
|
};
|
|
925
929
|
const updater = set()(addTSAndExtra);
|
|
926
930
|
const whenMatched = getWhenMatched(out.whenNotMatched);
|
|
@@ -1282,7 +1286,8 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1282
1286
|
}
|
|
1283
1287
|
catch (e) {
|
|
1284
1288
|
if ([85, 276].includes(e.code)) {
|
|
1285
|
-
log('Index created with different name', e.code, {
|
|
1289
|
+
log('Index created with different name', e.code, {
|
|
1290
|
+
collection: collection.collectionName});
|
|
1286
1291
|
break;
|
|
1287
1292
|
}
|
|
1288
1293
|
if (e.code == 12587) {
|
|
@@ -1297,6 +1302,11 @@ const createIndexWithRetry = async (collection, indexSpec, options) => {
|
|
|
1297
1302
|
break;
|
|
1298
1303
|
}
|
|
1299
1304
|
};
|
|
1305
|
+
const ensureCollection = async (db, collectionName) => {
|
|
1306
|
+
if (!(await db.listCollections({ name: collectionName }, { nameOnly: true }).next())) {
|
|
1307
|
+
await db.createCollection(collectionName);
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1300
1310
|
|
|
1301
1311
|
const patch = ({ ...x }, k, v) => {
|
|
1302
1312
|
delete x[k];
|
|
@@ -1532,7 +1542,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
|
|
|
1532
1542
|
raw: () => {
|
|
1533
1543
|
const replacer = map(mergeObjects(expr, field(mergeExpr(extExpr, {
|
|
1534
1544
|
deletedAt: ['deletedAt', nil],
|
|
1535
|
-
touchedAt: ['touchedAt',
|
|
1545
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
1536
1546
|
}))));
|
|
1537
1547
|
return link()
|
|
1538
1548
|
.with($replaceWith_(replacer))
|
|
@@ -1552,7 +1562,7 @@ const $insertPart = (out, ext) => {
|
|
|
1552
1562
|
return $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(extExpr), {
|
|
1553
1563
|
deletedAt: ['deletedAt', current],
|
|
1554
1564
|
_id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
|
|
1555
|
-
touchedAt: ['touchedAt',
|
|
1565
|
+
touchedAt: ['touchedAt', afterWriteTime],
|
|
1556
1566
|
})), x), ext, extExpr);
|
|
1557
1567
|
};
|
|
1558
1568
|
const $insert = (out) => $insertPart(out, {});
|
|
@@ -1969,6 +1979,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
|
|
|
1969
1979
|
partialFilterExpression: { updated: true, after: null, before: null },
|
|
1970
1980
|
name: 'updated_nulls_' + new mongodb.UUID().toString('base64'),
|
|
1971
1981
|
});
|
|
1982
|
+
await ensureCollection(db, coll);
|
|
1972
1983
|
await db.command({
|
|
1973
1984
|
collMod: coll,
|
|
1974
1985
|
changeStreamPreAndPostImages: { enabled: true },
|
|
@@ -2150,6 +2161,7 @@ const executes$1 = (view, input, streamName, needs) => {
|
|
|
2150
2161
|
const stop = withStop(step0);
|
|
2151
2162
|
const step1 = async () => {
|
|
2152
2163
|
log('creating indexes');
|
|
2164
|
+
await ensureCollection(db, coll);
|
|
2153
2165
|
await db.command({
|
|
2154
2166
|
collMod: coll,
|
|
2155
2167
|
changeStreamPreAndPostImages: { enabled: true },
|
|
@@ -2296,6 +2308,7 @@ exports.$unwindDelta = $unwindDelta;
|
|
|
2296
2308
|
exports.Field = Field;
|
|
2297
2309
|
exports.Machine = Machine;
|
|
2298
2310
|
exports.add = add;
|
|
2311
|
+
exports.afterWriteTime = afterWriteTime;
|
|
2299
2312
|
exports.and = and;
|
|
2300
2313
|
exports.anyElementTrue = anyElementTrue;
|
|
2301
2314
|
exports.array = array;
|