@omegup/msync 0.0.63 → 0.0.64

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
@@ -84,6 +84,7 @@ type TStages<in out S, out Q, in out B extends Q, out R extends Q, M extends num
84
84
  type Stages<out Q, out R extends Q, out SDom> = <E>(consume: <S extends SDom, B extends Q>(value: TStages<S, Q, B, R>) => E) => E;
85
85
  type Actions<W> = {
86
86
  updateMany: [Filter<W>, UpdateFilter<W> | BSON.Document[]];
87
+ deleteMany: [Filter<W>];
87
88
  };
88
89
  type TeardownRecord<W, M extends keyof Actions<W>> = {
89
90
  collection: WriteonlyCollection<W>;
package/index.esm.js CHANGED
@@ -613,21 +613,27 @@ const $groupMerge = (id, args, out, gid, extra, idPrefix = '') => ({
613
613
  raw: (first) => link()
614
614
  .with(subGroup(id, args, addGrp(gid)))
615
615
  .with(subMerge(args, out, gid, extra, idPrefix, first)).stages,
616
- teardown: c => c({
617
- collection: out.into,
618
- method: 'updateMany',
619
- params: [
620
- {},
621
- [
622
- {
623
- $unset: Object.keys({
624
- ...mapExactToObject(extra, () => 1),
625
- ...mapExactToObject(args, () => 1),
626
- }),
627
- },
616
+ teardown: c => c(out.whenNotMatched === 'insert'
617
+ ? {
618
+ collection: out.into,
619
+ method: 'deleteMany',
620
+ params: [{}],
621
+ }
622
+ : {
623
+ collection: out.into,
624
+ method: 'updateMany',
625
+ params: [
626
+ {},
627
+ [
628
+ {
629
+ $unset: Object.keys({
630
+ ...mapExactToObject(extra, () => 1),
631
+ ...mapExactToObject(args, () => 1),
632
+ }),
633
+ },
634
+ ],
628
635
  ],
629
- ],
630
- }),
636
+ }),
631
637
  });
632
638
  const $groupId = (id, args, out, extra) => $groupMerge(id, args, { into: out, whenNotMatched: 'fail' }, '_id', extra);
633
639
  const $group = (id, args, out, extra, idPrefix = '') => $groupMerge(id, args, { into: out, whenNotMatched: 'insert' }, '_grp', extra, idPrefix);
@@ -1495,9 +1501,13 @@ const actions = {
1495
1501
  c.updateMany(...args),
1496
1502
  [`db['${c.collectionName}'].updateMany(...`, args, ')'],
1497
1503
  ],
1504
+ deleteMany: (c, args) => [
1505
+ c.deleteMany(...args),
1506
+ [`db['${c.collectionName}'].deleteMany(...`, args, ')'],
1507
+ ],
1498
1508
  };
1499
1509
  const streamNames = {};
1500
- const executes$1 = (view, input, streamName, skip = false) => {
1510
+ const executes$1 = (view, input, streamName, skip = false, after) => {
1501
1511
  const hash = crypto$1
1502
1512
  .createHash('md5')
1503
1513
  .update(new Error().stack + '')
@@ -1590,6 +1600,7 @@ const executes$1 = (view, input, streamName, skip = false) => {
1590
1600
  if (exists && !same) {
1591
1601
  await handleTeardown(exists);
1592
1602
  }
1603
+ await after?.();
1593
1604
  return nextData([])(async () => {
1594
1605
  await new Promise(resolve => setTimeout(resolve, 1000));
1595
1606
  return step3(same)();
package/index.js CHANGED
@@ -615,21 +615,27 @@ const $groupMerge = (id, args, out, gid, extra, idPrefix = '') => ({
615
615
  raw: (first) => link()
616
616
  .with(subGroup(id, args, addGrp(gid)))
617
617
  .with(subMerge(args, out, gid, extra, idPrefix, first)).stages,
618
- teardown: c => c({
619
- collection: out.into,
620
- method: 'updateMany',
621
- params: [
622
- {},
623
- [
624
- {
625
- $unset: Object.keys({
626
- ...mapExactToObject(extra, () => 1),
627
- ...mapExactToObject(args, () => 1),
628
- }),
629
- },
618
+ teardown: c => c(out.whenNotMatched === 'insert'
619
+ ? {
620
+ collection: out.into,
621
+ method: 'deleteMany',
622
+ params: [{}],
623
+ }
624
+ : {
625
+ collection: out.into,
626
+ method: 'updateMany',
627
+ params: [
628
+ {},
629
+ [
630
+ {
631
+ $unset: Object.keys({
632
+ ...mapExactToObject(extra, () => 1),
633
+ ...mapExactToObject(args, () => 1),
634
+ }),
635
+ },
636
+ ],
630
637
  ],
631
- ],
632
- }),
638
+ }),
633
639
  });
634
640
  const $groupId = (id, args, out, extra) => $groupMerge(id, args, { into: out, whenNotMatched: 'fail' }, '_id', extra);
635
641
  const $group = (id, args, out, extra, idPrefix = '') => $groupMerge(id, args, { into: out, whenNotMatched: 'insert' }, '_grp', extra, idPrefix);
@@ -1497,9 +1503,13 @@ const actions = {
1497
1503
  c.updateMany(...args),
1498
1504
  [`db['${c.collectionName}'].updateMany(...`, args, ')'],
1499
1505
  ],
1506
+ deleteMany: (c, args) => [
1507
+ c.deleteMany(...args),
1508
+ [`db['${c.collectionName}'].deleteMany(...`, args, ')'],
1509
+ ],
1500
1510
  };
1501
1511
  const streamNames = {};
1502
- const executes$1 = (view, input, streamName, skip = false) => {
1512
+ const executes$1 = (view, input, streamName, skip = false, after) => {
1503
1513
  const hash = crypto$1
1504
1514
  .createHash('md5')
1505
1515
  .update(new Error().stack + '')
@@ -1592,6 +1602,7 @@ const executes$1 = (view, input, streamName, skip = false) => {
1592
1602
  if (exists && !same) {
1593
1603
  await handleTeardown(exists);
1594
1604
  }
1605
+ await after?.();
1595
1606
  return nextData([])(async () => {
1596
1607
  await new Promise(resolve => setTimeout(resolve, 1000));
1597
1608
  return step3(same)();
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.63",
6
+ "version": "0.0.64",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",