@omegup/msync 0.0.85 → 0.0.87

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
@@ -497,9 +497,9 @@ type ND = {
497
497
  };
498
498
  type SafeE<E> = Omit<E, `$${string}` | keyof ID>;
499
499
  type Merge<T extends doc, E> = Omit<SafeE<E>, keyof (ND & TS)> & ((T & ND & TS) | Del);
500
- 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>) => StreamRunnerParam<D, "out">;
500
+ 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">;
501
501
  declare const $simpleInsert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<T, "out">;
502
- declare const $insertPart: <T extends doc, EEE extends RORec<string, rawItem>>(out: RWCollection<Merge<T, EEE>>, ext: ExprsExact<Omit<SafeE<EEE>, keyof (ND & TS)>, unknown>) => StreamRunnerParam<Delta<T>, "out">;
502
+ 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">;
503
503
  declare const $insert: <T extends doc>(out: RWCollection<Merge<T, {}>>) => StreamRunnerParam<Delta<T>, "out">;
504
504
 
505
505
  declare const $group_: <V extends O>() => <ID, T extends O, C = unknown>(id: Expr<ID, T, C>, args: Accumulators<T, V, C>) => RawStages<O, T, Rec<"_id", ID> & V, C, 1>;
package/index.esm.js CHANGED
@@ -1,5 +1,6 @@
1
- import { SynchronousPromise } from 'synchronous-promise';
2
1
  import crypto$1 from 'crypto';
2
+ import { canonicalize } from 'json-canonicalize';
3
+ import { SynchronousPromise } from 'synchronous-promise';
3
4
  import { UUID, MongoClient } from 'mongodb';
4
5
  import { writeFile } from 'fs/promises';
5
6
 
@@ -1093,14 +1094,17 @@ const $unwind = (k, dict, middle) => {
1093
1094
 
1094
1095
  const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull1, includeNull2) => {
1095
1096
  const omit = omitRORec();
1097
+ const hash = crypto$1.createHash('md5').update(canonicalize(input)).digest('base64url');
1098
+ const ss = (f) => to($ifNull(root().of(f).of(k1).with(field1).expr(), val(hash)));
1096
1099
  return link()
1097
1100
  .with($replaceWithDelta(field(map1(k1, root().expr()))))
1101
+ .with($set_(set()({ bId: ['bId', ss('before')], aId: ['aId', ss('after')] })))
1098
1102
  .with($simpleLookup_({
1099
1103
  coll,
1100
1104
  k: 'a',
1101
1105
  fields: {
1102
1106
  foreign: root().of('before').with(field2),
1103
- local: root().of('after').of(k1).with(field1),
1107
+ local: root().of('aId'),
1104
1108
  },
1105
1109
  vars: {},
1106
1110
  pipeline: link().with(input).with(exec).stages,
@@ -1110,7 +1114,7 @@ const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, incl
1110
1114
  k: 'b',
1111
1115
  fields: {
1112
1116
  foreign: root().of('before').with(field2),
1113
- local: root().of('before').of(k1).with(field1),
1117
+ local: root().of('bId'),
1114
1118
  },
1115
1119
  vars: {},
1116
1120
  pipeline: link().with(input).with(exec).stages,
@@ -1403,8 +1407,7 @@ const $simpleMerge = () => (out, keys) => $mergeX(out, keys, root(), id$1);
1403
1407
  const $merge = () => (out, keys) => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()));
1404
1408
  const assertNotNull$1 = (expr) => expr;
1405
1409
 
1406
- const $insertX = (out, expr, map, ext) => {
1407
- const extExpr = mapExact(ext, (v) => val(v));
1410
+ const $insertX = (out, expr, map, ext, extExpr) => {
1408
1411
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
1409
1412
  return {
1410
1413
  teardown: c => c({
@@ -1431,12 +1434,15 @@ const $insertX = (out, expr, map, ext) => {
1431
1434
  },
1432
1435
  };
1433
1436
  };
1434
- const $simpleInsert = (out) => $insertX(out, root().expr(), id$1, {});
1435
- const $insertPart = (out, ext) => $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(ext), {
1436
- deletedAt: ['deletedAt', current],
1437
- _id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
1438
- touchedAt: ['touchedAt', current],
1439
- })), x), ext);
1437
+ const $simpleInsert = (out) => $insertX(out, root().expr(), id$1, {}, {});
1438
+ const $insertPart = (out, ext) => {
1439
+ const extExpr = mapExact(ext, (v) => val(v));
1440
+ return $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(extExpr), {
1441
+ deletedAt: ['deletedAt', current],
1442
+ _id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
1443
+ touchedAt: ['touchedAt', current],
1444
+ })), x), ext, extExpr);
1445
+ };
1440
1446
  const $insert = (out) => $insertPart(out, {});
1441
1447
  const assertNotNull = (expr) => expr;
1442
1448
 
package/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var synchronousPromise = require('synchronous-promise');
4
3
  var crypto$1 = require('crypto');
4
+ var jsonCanonicalize = require('json-canonicalize');
5
+ var synchronousPromise = require('synchronous-promise');
5
6
  var mongodb = require('mongodb');
6
7
  var promises = require('fs/promises');
7
8
 
@@ -1095,14 +1096,17 @@ const $unwind = (k, dict, middle) => {
1095
1096
 
1096
1097
  const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, includeNull1, includeNull2) => {
1097
1098
  const omit = omitRORec();
1099
+ const hash = crypto$1.createHash('md5').update(jsonCanonicalize.canonicalize(input)).digest('base64url');
1100
+ const ss = (f) => to($ifNull(root().of(f).of(k1).with(field1).expr(), val(hash)));
1098
1101
  return link()
1099
1102
  .with($replaceWithDelta(field(map1(k1, root().expr()))))
1103
+ .with($set_(set()({ bId: ['bId', ss('before')], aId: ['aId', ss('after')] })))
1100
1104
  .with($simpleLookup_({
1101
1105
  coll,
1102
1106
  k: 'a',
1103
1107
  fields: {
1104
1108
  foreign: root().of('before').with(field2),
1105
- local: root().of('after').of(k1).with(field1),
1109
+ local: root().of('aId'),
1106
1110
  },
1107
1111
  vars: {},
1108
1112
  pipeline: link().with(input).with(exec).stages,
@@ -1112,7 +1116,7 @@ const $lookupDelta = ({ field1, field2 }, { coll, exec, input }, k1, k2, k, incl
1112
1116
  k: 'b',
1113
1117
  fields: {
1114
1118
  foreign: root().of('before').with(field2),
1115
- local: root().of('before').of(k1).with(field1),
1119
+ local: root().of('bId'),
1116
1120
  },
1117
1121
  vars: {},
1118
1122
  pipeline: link().with(input).with(exec).stages,
@@ -1405,8 +1409,7 @@ const $simpleMerge = () => (out, keys) => $mergeX(out, keys, root(), id$1);
1405
1409
  const $merge = () => (out, keys) => $mergeId()(out, keys, assertNotNull$1(root().of('before').of('_id').expr()));
1406
1410
  const assertNotNull$1 = (expr) => expr;
1407
1411
 
1408
- const $insertX = (out, expr, map, ext) => {
1409
- const extExpr = mapExact(ext, (v) => val(v));
1412
+ const $insertX = (out, expr, map, ext, extExpr) => {
1410
1413
  const filter = mapExactToObject(ext, v => ({ $eq: v }));
1411
1414
  return {
1412
1415
  teardown: c => c({
@@ -1433,12 +1436,15 @@ const $insertX = (out, expr, map, ext) => {
1433
1436
  },
1434
1437
  };
1435
1438
  };
1436
- const $simpleInsert = (out) => $insertX(out, root().expr(), id$1, {});
1437
- const $insertPart = (out, ext) => $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(ext), {
1438
- deletedAt: ['deletedAt', current],
1439
- _id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
1440
- touchedAt: ['touchedAt', current],
1441
- })), x), ext);
1439
+ const $simpleInsert = (out) => $insertX(out, root().expr(), id$1, {}, {});
1440
+ const $insertPart = (out, ext) => {
1441
+ const extExpr = mapExact(ext, (v) => val(v));
1442
+ return $insertX(out, assertNotNull(root().of('after').expr()), x => ite(eq(root().of('after').expr())(nil), field(mergeExpr(translateOmit().forward(extExpr), {
1443
+ deletedAt: ['deletedAt', current],
1444
+ _id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
1445
+ touchedAt: ['touchedAt', current],
1446
+ })), x), ext, extExpr);
1447
+ };
1442
1448
  const $insert = (out) => $insertPart(out, {});
1443
1449
  const assertNotNull = (expr) => expr;
1444
1450
 
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.0.85",
6
+ "version": "0.0.87",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",