@omegup/msync 0.1.23 → 0.1.25

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.
Files changed (3) hide show
  1. package/index.esm.js +8 -10
  2. package/index.js +8 -10
  3. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -2002,20 +2002,20 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
2002
2002
  whenMatched: link().with($replaceWith_(ite(eq(root().of('before').expr())(ctx()('new').of('after').expr()), root().expr(), mergeObjects(root().expr(), ctx()('new').expr())))).stages,
2003
2003
  whenNotMatched: 'insert',
2004
2004
  })).stages;
2005
+ const stream = await makeStream();
2005
2006
  const r = await aggregate(pdb, streamName, c => c({ coll: collection, input: cloneIntoNew }));
2006
2007
  const start = Date.now();
2007
2008
  const res = await snapshotCollection.deleteMany({ updated: true, after: null, before: null });
2008
2009
  log('deleting from cloned into new collection', Date.now() - start, res, `db['${snapshotCollection.collectionName}'].deleteMany({ updated: true, after: null, before: null })`);
2009
- return next(step4({ result: r, ts: lastTS?.ts }), 'run the aggregation');
2010
+ return next(step4({ result: r, ts: lastTS?.ts, stream }), 'run the aggregation');
2010
2011
  };
2011
2012
  const makeStream = () => makeWatchStream(view, streamName);
2012
- const step4 = ({ result, ts }) => async () => {
2013
+ const step4 = ({ result, ts, stream }) => async () => {
2013
2014
  const start = Date.now();
2014
2015
  log('snapshot', streamName, 'ensure before null', Date.now() - start);
2015
2016
  const first = ts === undefined;
2016
2017
  const stages = finalInput.raw(first);
2017
2018
  await last.updateOne({ _id: streamName }, { $set: { job: 1 } }, { upsert: true });
2018
- const stream = await makeStream();
2019
2019
  const nextRes = stream.tryNext();
2020
2020
  const aggResult = await aggregate(pdb, streamName, c => c({
2021
2021
  coll: snapshotCollection,
@@ -2154,13 +2154,11 @@ const executes$1 = (view, input, streamName, needs) => {
2154
2154
  partialFilterExpression: { deletedAt: { $eq: null } },
2155
2155
  name: 'touchedAt_' + new UUID().toString('base64'),
2156
2156
  });
2157
- log('start stream', { streamName, data });
2158
- await last.findOne();
2159
- console.log('got last update');
2160
- const p = last.findOne({ _id: streamName, data });
2161
- await p;
2162
2157
  log('stream started', { streamName, data });
2163
- const ts = await Promise.all([p, last.findOne({ _id: streamName })]);
2158
+ const ts = await Promise.all([
2159
+ last.findOne({ _id: streamName, data }),
2160
+ last.findOne({ _id: streamName }),
2161
+ ]);
2164
2162
  log('got last update', { streamName, ts });
2165
2163
  return next(step2_5(ts), 'handle teardown');
2166
2164
  };
@@ -2194,11 +2192,11 @@ const executes$1 = (view, input, streamName, needs) => {
2194
2192
  const step4 = (lastTS) => async () => {
2195
2193
  const raw = stages(lastTS).with(finalInput.raw(lastTS === null)).stages;
2196
2194
  const stream = await makeStream();
2195
+ const nextRes = stream.tryNext();
2197
2196
  const aggResult = await aggregate(pdb, streamName, c => c({
2198
2197
  coll: collection,
2199
2198
  input: raw,
2200
2199
  }));
2201
- const nextRes = stream.tryNext();
2202
2200
  return next(step7({ aggResult, ts: aggResult.cursor.atClusterTime, stream, nextRes }), 'update __last', () => stream.close());
2203
2201
  };
2204
2202
  const step7 = (l) => async () => {
package/index.js CHANGED
@@ -2004,20 +2004,20 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
2004
2004
  whenMatched: link().with($replaceWith_(ite(eq(root().of('before').expr())(ctx()('new').of('after').expr()), root().expr(), mergeObjects(root().expr(), ctx()('new').expr())))).stages,
2005
2005
  whenNotMatched: 'insert',
2006
2006
  })).stages;
2007
+ const stream = await makeStream();
2007
2008
  const r = await aggregate(pdb, streamName, c => c({ coll: collection, input: cloneIntoNew }));
2008
2009
  const start = Date.now();
2009
2010
  const res = await snapshotCollection.deleteMany({ updated: true, after: null, before: null });
2010
2011
  log('deleting from cloned into new collection', Date.now() - start, res, `db['${snapshotCollection.collectionName}'].deleteMany({ updated: true, after: null, before: null })`);
2011
- return next(step4({ result: r, ts: lastTS?.ts }), 'run the aggregation');
2012
+ return next(step4({ result: r, ts: lastTS?.ts, stream }), 'run the aggregation');
2012
2013
  };
2013
2014
  const makeStream = () => makeWatchStream(view, streamName);
2014
- const step4 = ({ result, ts }) => async () => {
2015
+ const step4 = ({ result, ts, stream }) => async () => {
2015
2016
  const start = Date.now();
2016
2017
  log('snapshot', streamName, 'ensure before null', Date.now() - start);
2017
2018
  const first = ts === undefined;
2018
2019
  const stages = finalInput.raw(first);
2019
2020
  await last.updateOne({ _id: streamName }, { $set: { job: 1 } }, { upsert: true });
2020
- const stream = await makeStream();
2021
2021
  const nextRes = stream.tryNext();
2022
2022
  const aggResult = await aggregate(pdb, streamName, c => c({
2023
2023
  coll: snapshotCollection,
@@ -2156,13 +2156,11 @@ const executes$1 = (view, input, streamName, needs) => {
2156
2156
  partialFilterExpression: { deletedAt: { $eq: null } },
2157
2157
  name: 'touchedAt_' + new mongodb.UUID().toString('base64'),
2158
2158
  });
2159
- log('start stream', { streamName, data });
2160
- await last.findOne();
2161
- console.log('got last update');
2162
- const p = last.findOne({ _id: streamName, data });
2163
- await p;
2164
2159
  log('stream started', { streamName, data });
2165
- const ts = await Promise.all([p, last.findOne({ _id: streamName })]);
2160
+ const ts = await Promise.all([
2161
+ last.findOne({ _id: streamName, data }),
2162
+ last.findOne({ _id: streamName }),
2163
+ ]);
2166
2164
  log('got last update', { streamName, ts });
2167
2165
  return next(step2_5(ts), 'handle teardown');
2168
2166
  };
@@ -2196,11 +2194,11 @@ const executes$1 = (view, input, streamName, needs) => {
2196
2194
  const step4 = (lastTS) => async () => {
2197
2195
  const raw = stages(lastTS).with(finalInput.raw(lastTS === null)).stages;
2198
2196
  const stream = await makeStream();
2197
+ const nextRes = stream.tryNext();
2199
2198
  const aggResult = await aggregate(pdb, streamName, c => c({
2200
2199
  coll: collection,
2201
2200
  input: raw,
2202
2201
  }));
2203
- const nextRes = stream.tryNext();
2204
2202
  return next(step7({ aggResult, ts: aggResult.cursor.atClusterTime, stream, nextRes }), 'update __last', () => stream.close());
2205
2203
  };
2206
2204
  const step7 = (l) => async () => {
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.23",
6
+ "version": "0.1.25",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",