@omegup/msync 0.1.36 → 0.1.38

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 CHANGED
@@ -236,6 +236,7 @@ declare const concat: {
236
236
  <D, C>(...expr: Expr<string, D, C>[]): Expr<string, D, C>;
237
237
  <D, C>(...expr: Expr<string | N, D, C>[]): Expr<string | N, D, C>;
238
238
  };
239
+ declare const $substr: <D, C>(expr: Expr<string, D, C>, start: Expr<number, D, C>, length: Expr<number, D, C>) => Expr<string, D, C>;
239
240
  declare const padLeft: <D, C>(expr: Expr<string, D, C>, pad: string) => Expr<string, D, C>;
240
241
  declare const regex: <D, C>(expr: Expr<string, D, C>, regex: Expr<string, D, C>, options?: Expr<string, D, C>) => Expr<boolean, D, C>;
241
242
  declare const str: <D, C>(expr: Expr<unknown, D, C>) => Expr<string, D, C>;
@@ -453,7 +454,15 @@ type ND$1 = {
453
454
  readonly deletedAt?: null;
454
455
  };
455
456
  type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
456
- declare const getWhenMatchedForMerge: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert") => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
457
+ type Args<P, Out> = [added: Expr<P, unknown, {
458
+ new: P;
459
+ }>, old: Expr<Out, Out>];
460
+ type Result<P> = Expr<P, unknown, {
461
+ new: P;
462
+ }>;
463
+ type Update$1<P, Out> = (...args: Args<P, Out>) => Result<P>;
464
+ type UpdateF<P, Out> = <K extends keyof IsDeleted>(...args: Args<Replace<P, RORec<K, Timestamp>>, Out>) => Result<Replace<P, RORec<K, Timestamp>>>;
465
+ declare const getWhenMatchedForMerge: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert", update: Update$1<Replace<P, RORec<K, Timestamp>>, Out>) => RawStages<O, Out, Out | Replace<Out, P>, RORec<"new", Replace<P, RORec<K, Timestamp>>>>;
457
466
  declare const getWhenMatched: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: "discard" | "fail" | "insert") => RawStages<O, Rec<"old" | "merged", Out | Replace<Out, P>>, Out | Replace<Out, P>>;
458
467
  type MergeCollection<V extends O, Out extends Model> = {
459
468
  coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
@@ -462,18 +471,23 @@ type MergeCollection<V extends O, Out extends Model> = {
462
471
  coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
463
472
  whenNotMatched: 'fail';
464
473
  };
465
- declare const $mergeId: <V extends O>() => <SourcePart extends doc, Out extends Model, E = unknown, EEE extends RORec<string, rawItem> = {}>(out: MergeCollection<V, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, id: Expr<string, OutInputE<TakeDoc<V>, E, null>>, ext: Exact<Omit<SafeE$1<EEE>, keyof (ND$1 & TS)>, IdHKT>) => StreamRunnerParam<OutInputE<SourcePart, E>, "out">;
466
- declare const $simpleMergePart: <V extends O>() => <Source extends doc, Out extends Model, EEE extends RORec<string, rawItem>>(out: MergeCollection<V, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, ext: Exact<Omit<SafeE$1<EEE>, keyof (ND$1 & TS)>, IdHKT>) => StreamRunnerParam<Source, "out">;
467
- declare const $simpleMerge: <V extends O>() => <Source extends doc, Out extends Model>(out: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched?: "fail" | "discard") => StreamRunnerParam<Source, "out">;
468
- declare const $mergePart: <V extends O>() => <Out extends Model, SourcePart extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, ext: Exact<Omit<SafeE$1<EEE>, keyof (ND$1 & TS)>, IdHKT>) => StreamRunnerParam<Delta<SourcePart>, "out">;
469
- declare const $merge: <V extends O>() => <Out extends Model, SourcePart extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>) => StreamRunnerParam<Delta<SourcePart>, "out">;
474
+ type MergeUpdate<V, Out> = UpdateF<((OPick<V, Allowed$2<StrKey<V>>> & ID) | (Rec<Allowed$2<StrKey<V>>, N> & ID)) & TS, Out>;
475
+ declare const $mergeId: <V extends O>() => <SourcePart extends doc, Out extends Model, E = unknown, EEE extends RORec<string, rawItem> = {}>(out: MergeCollection<V, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, id: Expr<string, OutInputE<TakeDoc<V>, E, null>>, ext: Exact<Omit<SafeE$1<EEE>, keyof (ND$1 & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<OutInputE<SourcePart, E>, "out">;
476
+ declare const $simpleMergePart: <V extends O>() => <Source extends doc, Out extends Model, EEE extends RORec<string, rawItem>>(out: MergeCollection<V, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, ext: Exact<Omit<SafeE$1<EEE>, keyof (ND$1 & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Source, "out">;
477
+ declare const $simpleMerge: <V extends O>() => <Source extends doc, Out extends Model>(out: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched?: "fail" | "discard", update?: MergeUpdate<V, Out>) => StreamRunnerParam<Source, "out">;
478
+ declare const $mergePart: <V extends O>() => <Out extends Model, SourcePart extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, ext: Exact<Omit<SafeE$1<EEE>, keyof (ND$1 & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Delta<SourcePart>, "out">;
479
+ declare const $merge: <V extends O>() => <Out extends Model, SourcePart extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Delta<SourcePart>, "out">;
470
480
 
471
481
  type ND = {
472
482
  readonly deletedAt?: null;
473
483
  };
474
484
  type SafeE<E> = Omit<E, `$${string}` | keyof ID>;
475
485
  type Merge<T extends doc, E> = Omit<SafeE<E>, keyof (ND & TS)> & ((T & ND & TS) | Del);
476
- declare const $insertX: <T extends doc, D extends O, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, expr: Expr<T, D>, map: (x: Expr<T & ND & TS & Omit<SafeE<EEE>, keyof (ND & TS)>, D>) => Expr<Merge<T, EEE>, D>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, extExpr: ExprsExact<Omit<SafeE<EEE>, keyof (ND & TS)>, unknown>) => StreamRunnerParam<D, "out">;
486
+ type ExprP<P> = Expr<P, unknown, {
487
+ new: P;
488
+ }>;
489
+ type Update<P, Out> = (added: ExprP<P>, old: Expr<Out, Out>) => ExprP<P>;
490
+ declare const $insertX: <T extends doc, D extends O, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, expr: Expr<T, D>, map: (x: Expr<T & ND & TS & Omit<SafeE<EEE>, keyof (ND & TS)>, D>) => Expr<Merge<T, EEE>, D>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, extExpr: ExprsExact<Omit<SafeE<EEE>, keyof (ND & TS)>, unknown>, update?: Update<Replace<Merge<T, EEE>, {}>, Merge<T, EEE>>) => StreamRunnerParam<D, "out">;
477
491
  declare const $simpleInsert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<T, "out">;
478
492
  declare const $insertPart: <T extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>) => StreamRunnerParam<Delta<T>, "out">;
479
493
  declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
@@ -686,5 +700,5 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
686
700
  declare const prepare: (testName?: string) => Promise<MongoClient$1>;
687
701
  declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
688
702
 
689
- 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, mapFromPlainDateTime, mapToPlainDateTime, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, padLeft, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
703
+ 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, $substr, $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, mapFromPlainDateTime, mapToPlainDateTime, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, padLeft, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
690
704
  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
@@ -299,6 +299,11 @@ const $entries = (expr) => func(function (obj) {
299
299
  const concat$1 = (...expr) => asExpr({
300
300
  raw: f => asExprRaw({ $concat: expr.map(e => e.raw(f).get()) }),
301
301
  });
302
+ const $substr = (expr, start, length) => asExpr({
303
+ raw: f => asExprRaw({
304
+ $substrCP: [expr.raw(f).get(), start.raw(f).get(), length.raw(f).get()],
305
+ }),
306
+ });
302
307
  const padLeft = (expr, pad) => asExpr({
303
308
  raw: f => asExprRaw({
304
309
  $let: {
@@ -839,13 +844,13 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
839
844
  ]);
840
845
  const $merge2 = (args) => $merge_(args);
841
846
 
842
- const getWhenMatchedForMerge = (whenNotMatched) => {
847
+ const getWhenMatchedForMerge = (whenNotMatched, update) => {
843
848
  const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
844
849
  const newOrOld = whenNotMatched ===
845
850
  'insert'
846
851
  ? ctx()('new')
847
852
  : root();
848
- const merged = mergeObjects(root().expr(), ctx()('new').expr(), field({
853
+ const merged = mergeObjects(root().expr(), update(ctx()('new').expr(), root().expr()), field({
849
854
  deletedAt: ['deletedAt', orNull(newOrOld.of('deletedAt').expr())],
850
855
  }));
851
856
  return link()
@@ -864,7 +869,7 @@ const getWhenMatched = (whenNotMatched) => {
864
869
  const same = eq(preMergeOld)(root().of('merged').expr());
865
870
  return link().with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
866
871
  };
867
- const $mergeX = (out, keys, f, map, ext) => {
872
+ const $mergeX = (out, keys, f, map, ext, update) => {
868
873
  const patch = mapExact(keys, v => sub(v, f));
869
874
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
870
875
  const setDeleted = out.whenNotMatched === 'discard';
@@ -882,14 +887,14 @@ const $mergeX = (out, keys, f, map, ext) => {
882
887
  on: root().of('_id'),
883
888
  whenNotMatched: 'insert',
884
889
  stages: true,
885
- whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
890
+ whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
886
891
  })).stages
887
892
  : link().with($merge_({
888
893
  into: out.coll,
889
894
  on: root().of('_id'),
890
895
  whenNotMatched: 'fail',
891
896
  stages: true,
892
- whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
897
+ whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
893
898
  })).stages;
894
899
  const teardown = (coll) => ({
895
900
  collection: coll,
@@ -906,22 +911,22 @@ const $mergeX = (out, keys, f, map, ext) => {
906
911
  return {
907
912
  raw: (first) => link().with($replaceWith_(replacer)).with(sss)
908
913
  .stages,
909
- teardown: c => (setDeleted ? c(teardown(out.coll)) : c(teardown(out.coll))),
914
+ teardown: c => c(teardown(out.coll)),
910
915
  };
911
916
  };
912
- const $mergeId = () => (out, keys, id, ext) => {
917
+ const $mergeId = () => (out, keys, id, ext, update = x => x) => {
913
918
  const omRORec = omitRORec();
914
919
  return $mergeX(out, keys, root().of('after'), or => {
915
920
  return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
916
921
  _id: ['_id', id],
917
922
  touchedAt: ['touchedAt', current],
918
923
  }))), or);
919
- }, ext);
924
+ }, ext, update);
920
925
  };
921
- const $simpleMergePart = () => (out, keys, ext) => $mergeX(out, keys, root(), id$1, ext);
922
- const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {});
923
- const $mergePart = () => (out, keys, ext) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext);
924
- const $merge = () => (out, keys) => $mergePart()(out, keys, {});
926
+ const $simpleMergePart = () => (out, keys, ext, update = x => x) => $mergeX(out, keys, root(), id$1, ext, update);
927
+ const $simpleMerge = () => (out, keys, whenNotMatched = 'fail', update = x => x) => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {}, update);
928
+ const $mergePart = () => (out, keys, ext, update = x => x) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext, update);
929
+ const $merge = () => (out, keys, update = x => x) => $mergePart()(out, keys, {}, update);
925
930
  const assertNotNull$1 = (expr) => expr;
926
931
 
927
932
  const subMerge = (args, out, gid, extra, idPrefix, first) => {
@@ -1557,7 +1562,7 @@ const $replaceWith = (expr) => ({
1557
1562
  lin: $replaceWith_(expr),
1558
1563
  });
1559
1564
 
1560
- const $insertX = (out, expr, map, ext, extExpr) => {
1565
+ const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
1561
1566
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
1562
1567
  return {
1563
1568
  teardown: c => c({
@@ -1576,7 +1581,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
1576
1581
  into: out,
1577
1582
  on: root().of('_id'),
1578
1583
  stages: true,
1579
- whenMatched: getWhenMatchedForMerge('insert'),
1584
+ whenMatched: getWhenMatchedForMerge('insert', update),
1580
1585
  whenNotMatched: 'insert',
1581
1586
  })).stages;
1582
1587
  },
@@ -2274,4 +2279,4 @@ const executes = (view, input, needs) => {
2274
2279
  };
2275
2280
  const single = (view, needs = {}) => pipe(input => executes(view, input, needs), emptyDelta(), concatDelta, emptyDelta);
2276
2281
 
2277
- 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, mapFromPlainDateTime, mapToPlainDateTime, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, padLeft, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
2282
+ 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, $substr, $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, mapFromPlainDateTime, mapToPlainDateTime, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, padLeft, 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
@@ -301,6 +301,11 @@ const $entries = (expr) => func(function (obj) {
301
301
  const concat$1 = (...expr) => asExpr({
302
302
  raw: f => asExprRaw({ $concat: expr.map(e => e.raw(f).get()) }),
303
303
  });
304
+ const $substr = (expr, start, length) => asExpr({
305
+ raw: f => asExprRaw({
306
+ $substrCP: [expr.raw(f).get(), start.raw(f).get(), length.raw(f).get()],
307
+ }),
308
+ });
304
309
  const padLeft = (expr, pad) => asExpr({
305
310
  raw: f => asExprRaw({
306
311
  $let: {
@@ -841,13 +846,13 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
841
846
  ]);
842
847
  const $merge2 = (args) => $merge_(args);
843
848
 
844
- const getWhenMatchedForMerge = (whenNotMatched) => {
849
+ const getWhenMatchedForMerge = (whenNotMatched, update) => {
845
850
  const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
846
851
  const newOrOld = whenNotMatched ===
847
852
  'insert'
848
853
  ? ctx()('new')
849
854
  : root();
850
- const merged = mergeObjects(root().expr(), ctx()('new').expr(), field({
855
+ const merged = mergeObjects(root().expr(), update(ctx()('new').expr(), root().expr()), field({
851
856
  deletedAt: ['deletedAt', orNull(newOrOld.of('deletedAt').expr())],
852
857
  }));
853
858
  return link()
@@ -866,7 +871,7 @@ const getWhenMatched = (whenNotMatched) => {
866
871
  const same = eq(preMergeOld)(root().of('merged').expr());
867
872
  return link().with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
868
873
  };
869
- const $mergeX = (out, keys, f, map, ext) => {
874
+ const $mergeX = (out, keys, f, map, ext, update) => {
870
875
  const patch = mapExact(keys, v => sub(v, f));
871
876
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
872
877
  const setDeleted = out.whenNotMatched === 'discard';
@@ -884,14 +889,14 @@ const $mergeX = (out, keys, f, map, ext) => {
884
889
  on: root().of('_id'),
885
890
  whenNotMatched: 'insert',
886
891
  stages: true,
887
- whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
892
+ whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
888
893
  })).stages
889
894
  : link().with($merge_({
890
895
  into: out.coll,
891
896
  on: root().of('_id'),
892
897
  whenNotMatched: 'fail',
893
898
  stages: true,
894
- whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
899
+ whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
895
900
  })).stages;
896
901
  const teardown = (coll) => ({
897
902
  collection: coll,
@@ -908,22 +913,22 @@ const $mergeX = (out, keys, f, map, ext) => {
908
913
  return {
909
914
  raw: (first) => link().with($replaceWith_(replacer)).with(sss)
910
915
  .stages,
911
- teardown: c => (setDeleted ? c(teardown(out.coll)) : c(teardown(out.coll))),
916
+ teardown: c => c(teardown(out.coll)),
912
917
  };
913
918
  };
914
- const $mergeId = () => (out, keys, id, ext) => {
919
+ const $mergeId = () => (out, keys, id, ext, update = x => x) => {
915
920
  const omRORec = omitRORec();
916
921
  return $mergeX(out, keys, root().of('after'), or => {
917
922
  return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
918
923
  _id: ['_id', id],
919
924
  touchedAt: ['touchedAt', current],
920
925
  }))), or);
921
- }, ext);
926
+ }, ext, update);
922
927
  };
923
- const $simpleMergePart = () => (out, keys, ext) => $mergeX(out, keys, root(), id$1, ext);
924
- const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {});
925
- const $mergePart = () => (out, keys, ext) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext);
926
- const $merge = () => (out, keys) => $mergePart()(out, keys, {});
928
+ const $simpleMergePart = () => (out, keys, ext, update = x => x) => $mergeX(out, keys, root(), id$1, ext, update);
929
+ const $simpleMerge = () => (out, keys, whenNotMatched = 'fail', update = x => x) => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {}, update);
930
+ const $mergePart = () => (out, keys, ext, update = x => x) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext, update);
931
+ const $merge = () => (out, keys, update = x => x) => $mergePart()(out, keys, {}, update);
927
932
  const assertNotNull$1 = (expr) => expr;
928
933
 
929
934
  const subMerge = (args, out, gid, extra, idPrefix, first) => {
@@ -1559,7 +1564,7 @@ const $replaceWith = (expr) => ({
1559
1564
  lin: $replaceWith_(expr),
1560
1565
  });
1561
1566
 
1562
- const $insertX = (out, expr, map, ext, extExpr) => {
1567
+ const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
1563
1568
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
1564
1569
  return {
1565
1570
  teardown: c => c({
@@ -1578,7 +1583,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
1578
1583
  into: out,
1579
1584
  on: root().of('_id'),
1580
1585
  stages: true,
1581
- whenMatched: getWhenMatchedForMerge('insert'),
1586
+ whenMatched: getWhenMatchedForMerge('insert', update),
1582
1587
  whenNotMatched: 'insert',
1583
1588
  })).stages;
1584
1589
  },
@@ -2325,6 +2330,7 @@ exports.$set = $set;
2325
2330
  exports.$simpleInsert = $simpleInsert;
2326
2331
  exports.$simpleMerge = $simpleMerge;
2327
2332
  exports.$simpleMergePart = $simpleMergePart;
2333
+ exports.$substr = $substr;
2328
2334
  exports.$sum = $sum;
2329
2335
  exports.$type = $type;
2330
2336
  exports.$unwind = $unwind;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.esm.js",
4
4
  "typings": "index.d.ts",
5
5
  "name": "@omegup/msync",
6
- "version": "0.1.36",
6
+ "version": "0.1.38",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",