@omegup/msync 0.1.37 → 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
@@ -454,7 +454,15 @@ type ND$1 = {
454
454
  readonly deletedAt?: null;
455
455
  };
456
456
  type SafeE$1<E> = Omit<E, `$${string}` | keyof ID>;
457
- 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>>>>;
458
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>>;
459
467
  type MergeCollection<V extends O, Out extends Model> = {
460
468
  coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
@@ -463,18 +471,23 @@ type MergeCollection<V extends O, Out extends Model> = {
463
471
  coll: RWCollection<Out | Replace<Out, Patch<V>>, Out>;
464
472
  whenNotMatched: 'fail';
465
473
  };
466
- 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">;
467
- 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">;
468
- 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">;
469
- 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">;
470
- 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">;
471
480
 
472
481
  type ND = {
473
482
  readonly deletedAt?: null;
474
483
  };
475
484
  type SafeE<E> = Omit<E, `$${string}` | keyof ID>;
476
485
  type Merge<T extends doc, E> = Omit<SafeE<E>, keyof (ND & TS)> & ((T & ND & TS) | Del);
477
- 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">;
478
491
  declare const $simpleInsert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<T, "out">;
479
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">;
480
493
  declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
package/index.esm.js CHANGED
@@ -844,13 +844,13 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
844
844
  ]);
845
845
  const $merge2 = (args) => $merge_(args);
846
846
 
847
- const getWhenMatchedForMerge = (whenNotMatched) => {
847
+ const getWhenMatchedForMerge = (whenNotMatched, update) => {
848
848
  const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
849
849
  const newOrOld = whenNotMatched ===
850
850
  'insert'
851
851
  ? ctx()('new')
852
852
  : root();
853
- const merged = mergeObjects(root().expr(), ctx()('new').expr(), field({
853
+ const merged = mergeObjects(root().expr(), update(ctx()('new').expr(), root().expr()), field({
854
854
  deletedAt: ['deletedAt', orNull(newOrOld.of('deletedAt').expr())],
855
855
  }));
856
856
  return link()
@@ -869,7 +869,7 @@ const getWhenMatched = (whenNotMatched) => {
869
869
  const same = eq(preMergeOld)(root().of('merged').expr());
870
870
  return link().with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
871
871
  };
872
- const $mergeX = (out, keys, f, map, ext) => {
872
+ const $mergeX = (out, keys, f, map, ext, update) => {
873
873
  const patch = mapExact(keys, v => sub(v, f));
874
874
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
875
875
  const setDeleted = out.whenNotMatched === 'discard';
@@ -887,14 +887,14 @@ const $mergeX = (out, keys, f, map, ext) => {
887
887
  on: root().of('_id'),
888
888
  whenNotMatched: 'insert',
889
889
  stages: true,
890
- whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
890
+ whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
891
891
  })).stages
892
892
  : link().with($merge_({
893
893
  into: out.coll,
894
894
  on: root().of('_id'),
895
895
  whenNotMatched: 'fail',
896
896
  stages: true,
897
- whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
897
+ whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
898
898
  })).stages;
899
899
  const teardown = (coll) => ({
900
900
  collection: coll,
@@ -911,22 +911,22 @@ const $mergeX = (out, keys, f, map, ext) => {
911
911
  return {
912
912
  raw: (first) => link().with($replaceWith_(replacer)).with(sss)
913
913
  .stages,
914
- teardown: c => (setDeleted ? c(teardown(out.coll)) : c(teardown(out.coll))),
914
+ teardown: c => c(teardown(out.coll)),
915
915
  };
916
916
  };
917
- const $mergeId = () => (out, keys, id, ext) => {
917
+ const $mergeId = () => (out, keys, id, ext, update = x => x) => {
918
918
  const omRORec = omitRORec();
919
919
  return $mergeX(out, keys, root().of('after'), or => {
920
920
  return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
921
921
  _id: ['_id', id],
922
922
  touchedAt: ['touchedAt', current],
923
923
  }))), or);
924
- }, ext);
924
+ }, ext, update);
925
925
  };
926
- const $simpleMergePart = () => (out, keys, ext) => $mergeX(out, keys, root(), id$1, ext);
927
- const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {});
928
- const $mergePart = () => (out, keys, ext) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext);
929
- 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);
930
930
  const assertNotNull$1 = (expr) => expr;
931
931
 
932
932
  const subMerge = (args, out, gid, extra, idPrefix, first) => {
@@ -1562,7 +1562,7 @@ const $replaceWith = (expr) => ({
1562
1562
  lin: $replaceWith_(expr),
1563
1563
  });
1564
1564
 
1565
- const $insertX = (out, expr, map, ext, extExpr) => {
1565
+ const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
1566
1566
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
1567
1567
  return {
1568
1568
  teardown: c => c({
@@ -1581,7 +1581,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
1581
1581
  into: out,
1582
1582
  on: root().of('_id'),
1583
1583
  stages: true,
1584
- whenMatched: getWhenMatchedForMerge('insert'),
1584
+ whenMatched: getWhenMatchedForMerge('insert', update),
1585
1585
  whenNotMatched: 'insert',
1586
1586
  })).stages;
1587
1587
  },
package/index.js CHANGED
@@ -846,13 +846,13 @@ const $merge_ = ({ into, on, whenNotMatched, ...notMatched }) => asStages([
846
846
  ]);
847
847
  const $merge2 = (args) => $merge_(args);
848
848
 
849
- const getWhenMatchedForMerge = (whenNotMatched) => {
849
+ const getWhenMatchedForMerge = (whenNotMatched, update) => {
850
850
  const orNull = (e) => whenNotMatched === 'discard' ? $ifNull(e, nil) : e;
851
851
  const newOrOld = whenNotMatched ===
852
852
  'insert'
853
853
  ? ctx()('new')
854
854
  : root();
855
- const merged = mergeObjects(root().expr(), ctx()('new').expr(), field({
855
+ const merged = mergeObjects(root().expr(), update(ctx()('new').expr(), root().expr()), field({
856
856
  deletedAt: ['deletedAt', orNull(newOrOld.of('deletedAt').expr())],
857
857
  }));
858
858
  return link()
@@ -871,7 +871,7 @@ const getWhenMatched = (whenNotMatched) => {
871
871
  const same = eq(preMergeOld)(root().of('merged').expr());
872
872
  return link().with($replaceWith_(ite(same, root().of('old').expr(), root().of('merged').expr()))).stages;
873
873
  };
874
- const $mergeX = (out, keys, f, map, ext) => {
874
+ const $mergeX = (out, keys, f, map, ext, update) => {
875
875
  const patch = mapExact(keys, v => sub(v, f));
876
876
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
877
877
  const setDeleted = out.whenNotMatched === 'discard';
@@ -889,14 +889,14 @@ const $mergeX = (out, keys, f, map, ext) => {
889
889
  on: root().of('_id'),
890
890
  whenNotMatched: 'insert',
891
891
  stages: true,
892
- whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
892
+ whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
893
893
  })).stages
894
894
  : link().with($merge_({
895
895
  into: out.coll,
896
896
  on: root().of('_id'),
897
897
  whenNotMatched: 'fail',
898
898
  stages: true,
899
- whenMatched: getWhenMatchedForMerge(out.whenNotMatched),
899
+ whenMatched: getWhenMatchedForMerge(out.whenNotMatched, update),
900
900
  })).stages;
901
901
  const teardown = (coll) => ({
902
902
  collection: coll,
@@ -913,22 +913,22 @@ const $mergeX = (out, keys, f, map, ext) => {
913
913
  return {
914
914
  raw: (first) => link().with($replaceWith_(replacer)).with(sss)
915
915
  .stages,
916
- teardown: c => (setDeleted ? c(teardown(out.coll)) : c(teardown(out.coll))),
916
+ teardown: c => c(teardown(out.coll)),
917
917
  };
918
918
  };
919
- const $mergeId = () => (out, keys, id, ext) => {
919
+ const $mergeId = () => (out, keys, id, ext, update = x => x) => {
920
920
  const omRORec = omitRORec();
921
921
  return $mergeX(out, keys, root().of('after'), or => {
922
922
  return ite(eqTyped(root().of('after').expr(), nil), field(omRORec.backward(spread(mapExact(keys, () => nil), {
923
923
  _id: ['_id', id],
924
924
  touchedAt: ['touchedAt', current],
925
925
  }))), or);
926
- }, ext);
926
+ }, ext, update);
927
927
  };
928
- const $simpleMergePart = () => (out, keys, ext) => $mergeX(out, keys, root(), id$1, ext);
929
- const $simpleMerge = () => (out, keys, whenNotMatched = 'fail') => $mergeX({ coll: out, whenNotMatched }, keys, root(), id$1, {});
930
- const $mergePart = () => (out, keys, ext) => $mergeId()({ coll: out, whenNotMatched: 'fail' }, keys, assertNotNull$1(root().of('before').of('_id').expr()), ext);
931
- 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);
932
932
  const assertNotNull$1 = (expr) => expr;
933
933
 
934
934
  const subMerge = (args, out, gid, extra, idPrefix, first) => {
@@ -1564,7 +1564,7 @@ const $replaceWith = (expr) => ({
1564
1564
  lin: $replaceWith_(expr),
1565
1565
  });
1566
1566
 
1567
- const $insertX = (out, expr, map, ext, extExpr) => {
1567
+ const $insertX = (out, expr, map, ext, extExpr, update = x => x) => {
1568
1568
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
1569
1569
  return {
1570
1570
  teardown: c => c({
@@ -1583,7 +1583,7 @@ const $insertX = (out, expr, map, ext, extExpr) => {
1583
1583
  into: out,
1584
1584
  on: root().of('_id'),
1585
1585
  stages: true,
1586
- whenMatched: getWhenMatchedForMerge('insert'),
1586
+ whenMatched: getWhenMatchedForMerge('insert', update),
1587
1587
  whenNotMatched: 'insert',
1588
1588
  })).stages;
1589
1589
  },
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.37",
6
+ "version": "0.1.38",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",