@omegup/msync 0.0.98 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +6 -1
- package/index.esm.js +50 -31
- package/index.js +50 -30
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -491,6 +491,11 @@ declare const $unwind: <TT extends O, K extends s, U extends doc>(k: AsLiteral<K
|
|
|
491
491
|
type Allowed$2<K extends string> = Exclude<K, keyof (TS & ID)>;
|
|
492
492
|
type Patch<V, KK extends StrKey<V> = StrKey<V>> = ((OPick<V, Allowed$2<KK>> & ID) | (Rec<Allowed$2<KK>, N> & ID)) & TS;
|
|
493
493
|
type TakeDoc<V, E = ID, KK extends StrKey<V> = StrKey<V>> = OPick<V, Allowed$2<KK>> & E;
|
|
494
|
+
type ND$1 = {
|
|
495
|
+
readonly deletedAt?: null;
|
|
496
|
+
};
|
|
497
|
+
type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
|
|
498
|
+
declare const $simpleMergePart: <V extends O>() => <Source extends doc, Out extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched: "fail" | "discard", ext: Exact<Omit<SafeE$1<EEE>, keyof (ND$1 & TS)>, IdHKT>) => StreamRunnerParam<Source, "out">;
|
|
494
499
|
declare const $simpleMerge: <V extends O>() => <Source extends doc, Out extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched?: "fail" | "discard") => StreamRunnerParam<Source, "out">;
|
|
495
500
|
declare const $merge: <V extends O>() => <Out extends doc, SourcePart extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, whenNotMatched?: "fail" | "discard") => StreamRunnerParam<Delta<SourcePart>, "out">;
|
|
496
501
|
|
|
@@ -698,4 +703,4 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
|
|
|
698
703
|
declare const prepare: (testName?: string) => Promise<MongoClient$1>;
|
|
699
704
|
declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
|
|
700
705
|
|
|
701
|
-
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, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $sum, $type, $unwind, $unwindDelta, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type MongoTypeNames, type N, type NoRaw, type NullToOBJ, type O, type OPick, type OPickD, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, 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, type notArr, 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 };
|
|
706
|
+
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, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $sum, $type, $unwind, $unwindDelta, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type MongoTypeNames, type N, type NoRaw, type NullToOBJ, type O, type OPick, type OPickD, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, 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, type notArr, 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.esm.js
CHANGED
|
@@ -1364,28 +1364,46 @@ const $replaceWith = (expr) => ({
|
|
|
1364
1364
|
lin: $replaceWith_(expr),
|
|
1365
1365
|
});
|
|
1366
1366
|
|
|
1367
|
-
const $mergeX = (out, keys, f, map, whenNotMatched = 'fail') =>
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1367
|
+
const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
|
|
1368
|
+
const patch = mapExact(keys, v => sub(v, f));
|
|
1369
|
+
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
1370
|
+
const setDeleted = whenNotMatched === 'discard';
|
|
1371
|
+
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
1372
|
+
_id: ['_id', f.of('_id').expr()],
|
|
1373
|
+
touchedAt: ['touchedAt', current],
|
|
1374
|
+
deletedAt: [setDeleted ? 'deletedAt' : 'touchedAt', current],
|
|
1375
|
+
}))));
|
|
1376
|
+
return {
|
|
1377
|
+
raw: (first) => link()
|
|
1376
1378
|
.with($replaceWith_(replacer))
|
|
1377
1379
|
.with($merge_({
|
|
1378
1380
|
into: out,
|
|
1379
1381
|
on: root().of('_id'),
|
|
1380
|
-
whenNotMatched,
|
|
1382
|
+
whenNotMatched: whenNotMatched === 'fail' ? 'fail' : 'insert',
|
|
1381
1383
|
stages: true,
|
|
1382
1384
|
whenMatched: asStages([
|
|
1383
|
-
{
|
|
1385
|
+
{
|
|
1386
|
+
$replaceWith: {
|
|
1387
|
+
old: setDeleted
|
|
1388
|
+
? { $mergeObjects: ['$$ROOT', { deletedAt: '$deletedAt' }] }
|
|
1389
|
+
: '$$ROOT',
|
|
1390
|
+
merged: {
|
|
1391
|
+
$mergeObjects: [
|
|
1392
|
+
'$$ROOT',
|
|
1393
|
+
'$$new',
|
|
1394
|
+
...(setDeleted ? [{ deletedAt: '$deletedAt' }] : []),
|
|
1395
|
+
],
|
|
1396
|
+
},
|
|
1397
|
+
},
|
|
1398
|
+
},
|
|
1384
1399
|
{
|
|
1385
1400
|
$replaceWith: {
|
|
1386
1401
|
$cond: {
|
|
1387
1402
|
if: {
|
|
1388
|
-
$eq: [
|
|
1403
|
+
$eq: [
|
|
1404
|
+
'$old',
|
|
1405
|
+
{ $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
|
|
1406
|
+
],
|
|
1389
1407
|
},
|
|
1390
1408
|
then: '$old',
|
|
1391
1409
|
else: '$merged',
|
|
@@ -1393,32 +1411,33 @@ const $mergeX = (out, keys, f, map, whenNotMatched = 'fail') => ({
|
|
|
1393
1411
|
},
|
|
1394
1412
|
},
|
|
1395
1413
|
]),
|
|
1396
|
-
})).stages
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1414
|
+
})).stages,
|
|
1415
|
+
teardown: c => c({
|
|
1416
|
+
collection: out,
|
|
1417
|
+
method: 'updateMany',
|
|
1418
|
+
params: [
|
|
1419
|
+
filter,
|
|
1420
|
+
[
|
|
1421
|
+
{
|
|
1422
|
+
$unset: Object.keys(mapExactToObject(keys, () => 1)),
|
|
1423
|
+
},
|
|
1424
|
+
],
|
|
1407
1425
|
],
|
|
1408
|
-
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
const $mergeId = () => (out, keys, id, whenNotMatched
|
|
1426
|
+
}),
|
|
1427
|
+
};
|
|
1428
|
+
};
|
|
1429
|
+
const $mergeId = () => (out, keys, id, ext, whenNotMatched) => {
|
|
1412
1430
|
const omRORec = omitRORec();
|
|
1413
1431
|
return $mergeX(out, keys, root().of('after'), or => {
|
|
1414
1432
|
return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
|
|
1415
1433
|
_id: ['_id', id],
|
|
1416
1434
|
touchedAt: ['touchedAt', current],
|
|
1417
1435
|
}))), or);
|
|
1418
|
-
}, whenNotMatched);
|
|
1436
|
+
}, whenNotMatched, ext);
|
|
1419
1437
|
};
|
|
1420
|
-
const $
|
|
1421
|
-
const $
|
|
1438
|
+
const $simpleMergePart = () => (out, keys, whenNotMatched, ext) => $mergeX(out, keys, root(), id$1, whenNotMatched, ext);
|
|
1439
|
+
const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX(out, keys, root(), id$1, whenNotMatched, {});
|
|
1440
|
+
const $merge = () => (out, keys, whenNotMatched = 'fail') => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()), {}, whenNotMatched);
|
|
1422
1441
|
const assertNotNull$1 = (expr) => expr;
|
|
1423
1442
|
|
|
1424
1443
|
const $insertX = (out, expr, map, ext, extExpr) => {
|
|
@@ -1983,4 +2002,4 @@ const makeCol = async (docs, database, name) => {
|
|
|
1983
2002
|
}
|
|
1984
2003
|
};
|
|
1985
2004
|
|
|
1986
|
-
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, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $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, 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 };
|
|
2005
|
+
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, $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, 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
|
@@ -1366,28 +1366,46 @@ const $replaceWith = (expr) => ({
|
|
|
1366
1366
|
lin: $replaceWith_(expr),
|
|
1367
1367
|
});
|
|
1368
1368
|
|
|
1369
|
-
const $mergeX = (out, keys, f, map, whenNotMatched = 'fail') =>
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1369
|
+
const $mergeX = (out, keys, f, map, whenNotMatched = 'fail', ext) => {
|
|
1370
|
+
const patch = mapExact(keys, v => sub(v, f));
|
|
1371
|
+
const filter = mapExactToObject(ext, v => ({ $eq: v }));
|
|
1372
|
+
const setDeleted = whenNotMatched === 'discard';
|
|
1373
|
+
const replacer = map(field(omitPick().backward(spread(patch, {
|
|
1374
|
+
_id: ['_id', f.of('_id').expr()],
|
|
1375
|
+
touchedAt: ['touchedAt', current],
|
|
1376
|
+
deletedAt: [setDeleted ? 'deletedAt' : 'touchedAt', current],
|
|
1377
|
+
}))));
|
|
1378
|
+
return {
|
|
1379
|
+
raw: (first) => link()
|
|
1378
1380
|
.with($replaceWith_(replacer))
|
|
1379
1381
|
.with($merge_({
|
|
1380
1382
|
into: out,
|
|
1381
1383
|
on: root().of('_id'),
|
|
1382
|
-
whenNotMatched,
|
|
1384
|
+
whenNotMatched: whenNotMatched === 'fail' ? 'fail' : 'insert',
|
|
1383
1385
|
stages: true,
|
|
1384
1386
|
whenMatched: asStages([
|
|
1385
|
-
{
|
|
1387
|
+
{
|
|
1388
|
+
$replaceWith: {
|
|
1389
|
+
old: setDeleted
|
|
1390
|
+
? { $mergeObjects: ['$$ROOT', { deletedAt: '$deletedAt' }] }
|
|
1391
|
+
: '$$ROOT',
|
|
1392
|
+
merged: {
|
|
1393
|
+
$mergeObjects: [
|
|
1394
|
+
'$$ROOT',
|
|
1395
|
+
'$$new',
|
|
1396
|
+
...(setDeleted ? [{ deletedAt: '$deletedAt' }] : []),
|
|
1397
|
+
],
|
|
1398
|
+
},
|
|
1399
|
+
},
|
|
1400
|
+
},
|
|
1386
1401
|
{
|
|
1387
1402
|
$replaceWith: {
|
|
1388
1403
|
$cond: {
|
|
1389
1404
|
if: {
|
|
1390
|
-
$eq: [
|
|
1405
|
+
$eq: [
|
|
1406
|
+
'$old',
|
|
1407
|
+
{ $mergeObjects: ['$merged', { touchedAt: '$old.touchedAt' }] },
|
|
1408
|
+
],
|
|
1391
1409
|
},
|
|
1392
1410
|
then: '$old',
|
|
1393
1411
|
else: '$merged',
|
|
@@ -1395,32 +1413,33 @@ const $mergeX = (out, keys, f, map, whenNotMatched = 'fail') => ({
|
|
|
1395
1413
|
},
|
|
1396
1414
|
},
|
|
1397
1415
|
]),
|
|
1398
|
-
})).stages
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1416
|
+
})).stages,
|
|
1417
|
+
teardown: c => c({
|
|
1418
|
+
collection: out,
|
|
1419
|
+
method: 'updateMany',
|
|
1420
|
+
params: [
|
|
1421
|
+
filter,
|
|
1422
|
+
[
|
|
1423
|
+
{
|
|
1424
|
+
$unset: Object.keys(mapExactToObject(keys, () => 1)),
|
|
1425
|
+
},
|
|
1426
|
+
],
|
|
1409
1427
|
],
|
|
1410
|
-
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
const $mergeId = () => (out, keys, id, whenNotMatched
|
|
1428
|
+
}),
|
|
1429
|
+
};
|
|
1430
|
+
};
|
|
1431
|
+
const $mergeId = () => (out, keys, id, ext, whenNotMatched) => {
|
|
1414
1432
|
const omRORec = omitRORec();
|
|
1415
1433
|
return $mergeX(out, keys, root().of('after'), or => {
|
|
1416
1434
|
return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
|
|
1417
1435
|
_id: ['_id', id],
|
|
1418
1436
|
touchedAt: ['touchedAt', current],
|
|
1419
1437
|
}))), or);
|
|
1420
|
-
}, whenNotMatched);
|
|
1438
|
+
}, whenNotMatched, ext);
|
|
1421
1439
|
};
|
|
1422
|
-
const $
|
|
1423
|
-
const $
|
|
1440
|
+
const $simpleMergePart = () => (out, keys, whenNotMatched, ext) => $mergeX(out, keys, root(), id$1, whenNotMatched, ext);
|
|
1441
|
+
const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX(out, keys, root(), id$1, whenNotMatched, {});
|
|
1442
|
+
const $merge = () => (out, keys, whenNotMatched = 'fail') => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()), {}, whenNotMatched);
|
|
1424
1443
|
const assertNotNull$1 = (expr) => expr;
|
|
1425
1444
|
|
|
1426
1445
|
const $insertX = (out, expr, map, ext, extExpr) => {
|
|
@@ -2030,6 +2049,7 @@ exports.$replaceWith = $replaceWith;
|
|
|
2030
2049
|
exports.$set = $set;
|
|
2031
2050
|
exports.$simpleInsert = $simpleInsert;
|
|
2032
2051
|
exports.$simpleMerge = $simpleMerge;
|
|
2052
|
+
exports.$simpleMergePart = $simpleMergePart;
|
|
2033
2053
|
exports.$sum = $sum;
|
|
2034
2054
|
exports.$type = $type;
|
|
2035
2055
|
exports.$unwind = $unwind;
|