@omegup/msync 0.0.32 → 0.0.34
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.esm.js +24 -13
- package/index.js +24 -13
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -1168,7 +1168,7 @@ const addTeardown = (it, tr) => {
|
|
|
1168
1168
|
next: n.then(({ cont, ...res }) => ({ cont: addTeardown(cont, tr), ...res })),
|
|
1169
1169
|
stop: () => (tr(), stop()),
|
|
1170
1170
|
clear: async () => {
|
|
1171
|
-
tr();
|
|
1171
|
+
await tr();
|
|
1172
1172
|
await clear();
|
|
1173
1173
|
},
|
|
1174
1174
|
};
|
|
@@ -1184,7 +1184,12 @@ const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startA
|
|
|
1184
1184
|
const q = $or(...changeKeys.map((k) => subQ(m, root().of(k))));
|
|
1185
1185
|
if (q)
|
|
1186
1186
|
pipeline.push({
|
|
1187
|
-
$match: {
|
|
1187
|
+
$match: {
|
|
1188
|
+
$or: [
|
|
1189
|
+
q.raw(root()),
|
|
1190
|
+
Object.fromEntries(changeKeys.map(k => [k, null])),
|
|
1191
|
+
],
|
|
1192
|
+
},
|
|
1188
1193
|
});
|
|
1189
1194
|
}
|
|
1190
1195
|
pipeline.push({
|
|
@@ -1219,7 +1224,10 @@ const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startA
|
|
|
1219
1224
|
};
|
|
1220
1225
|
|
|
1221
1226
|
const actions = {
|
|
1222
|
-
updateMany: (c, args) => [
|
|
1227
|
+
updateMany: (c, args) => [
|
|
1228
|
+
c.updateMany(...args),
|
|
1229
|
+
[`db['${c.collectionName}'].updateMany(...`, args, ')'],
|
|
1230
|
+
],
|
|
1223
1231
|
};
|
|
1224
1232
|
const streamNames = {};
|
|
1225
1233
|
const executes$1 = (view, input, streamName) => {
|
|
@@ -1263,11 +1271,12 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1263
1271
|
const withStop = (next, tr) => {
|
|
1264
1272
|
return addTeardown(() => ({ stop, next: next(), clear }), tr);
|
|
1265
1273
|
};
|
|
1266
|
-
const
|
|
1274
|
+
const nextData = (data) => (next, debug, tr) => ({
|
|
1267
1275
|
cont: withStop(next, tr),
|
|
1268
|
-
data
|
|
1276
|
+
data,
|
|
1269
1277
|
info: { job, debug: `${streamName} on ${collection.collectionName}: ${debug}` },
|
|
1270
1278
|
});
|
|
1279
|
+
const next = nextData([]);
|
|
1271
1280
|
const data = {
|
|
1272
1281
|
input: input.delta,
|
|
1273
1282
|
finalInputFirst: finalInput.raw(true),
|
|
@@ -1287,7 +1296,11 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1287
1296
|
const step2 = () => Promise.all([
|
|
1288
1297
|
last.findOne({ _id: streamName, data }),
|
|
1289
1298
|
last.findOne({ _id: streamName }),
|
|
1290
|
-
]).then(ts => next(step2_5(ts), ts[0]
|
|
1299
|
+
]).then(ts => next(step2_5(ts), ts[0]
|
|
1300
|
+
? `no teardown to handle, starting at ${ts[0].ts}`
|
|
1301
|
+
: ts[1]
|
|
1302
|
+
? 'handle teardown'
|
|
1303
|
+
: 'start fresh'));
|
|
1291
1304
|
const step2_5 = ([same, exists]) => async () => {
|
|
1292
1305
|
const handleTeardown = async (last) => {
|
|
1293
1306
|
if (!last.data)
|
|
@@ -1308,11 +1321,13 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1308
1321
|
return next(step3(same), 'clone into new collection');
|
|
1309
1322
|
};
|
|
1310
1323
|
const step3 = (lastTS) => async () => {
|
|
1311
|
-
const hardQuery = $and(lastTS
|
|
1324
|
+
const hardQuery = $and(lastTS
|
|
1325
|
+
? root().of('touchedAt').has($gteTs(lastTS.ts))
|
|
1326
|
+
: root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), hardMatch);
|
|
1312
1327
|
const notDeleted = eq($ifNull(root().of('deletedAt').expr(), nil))(nil);
|
|
1313
1328
|
const query = match ? and(notDeleted, match) : notDeleted;
|
|
1314
1329
|
const replaceRaw = $replaceWith_(field({
|
|
1315
|
-
after: ['after', ite(query, root().expr(), nil)],
|
|
1330
|
+
after: ['after', lastTS ? ite(query, root().expr(), nil) : root().expr()],
|
|
1316
1331
|
updated: ['updated', val(true)],
|
|
1317
1332
|
_id: ['_id', root().of('_id').expr()],
|
|
1318
1333
|
}));
|
|
@@ -1375,11 +1390,7 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1375
1390
|
return step8(l);
|
|
1376
1391
|
};
|
|
1377
1392
|
const step8 = (l) => {
|
|
1378
|
-
return
|
|
1379
|
-
data: l.aggResult.cursor.firstBatch,
|
|
1380
|
-
info: { job: undefined, debug: 'wait for change' },
|
|
1381
|
-
cont: withStop(() => l.stream.tryNext().then(doc => (doc ? next(step2, 'restart') : step8(l)))),
|
|
1382
|
-
};
|
|
1393
|
+
return nextData(l.aggResult.cursor.firstBatch)(() => l.stream.tryNext().then(doc => (doc ? next(step2, 'restart') : step8(l))), 'wait for change');
|
|
1383
1394
|
};
|
|
1384
1395
|
return stop;
|
|
1385
1396
|
};
|
package/index.js
CHANGED
|
@@ -1170,7 +1170,7 @@ const addTeardown = (it, tr) => {
|
|
|
1170
1170
|
next: n.then(({ cont, ...res }) => ({ cont: addTeardown(cont, tr), ...res })),
|
|
1171
1171
|
stop: () => (tr(), stop()),
|
|
1172
1172
|
clear: async () => {
|
|
1173
|
-
tr();
|
|
1173
|
+
await tr();
|
|
1174
1174
|
await clear();
|
|
1175
1175
|
},
|
|
1176
1176
|
};
|
|
@@ -1186,7 +1186,12 @@ const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startA
|
|
|
1186
1186
|
const q = $or(...changeKeys.map((k) => subQ(m, root().of(k))));
|
|
1187
1187
|
if (q)
|
|
1188
1188
|
pipeline.push({
|
|
1189
|
-
$match: {
|
|
1189
|
+
$match: {
|
|
1190
|
+
$or: [
|
|
1191
|
+
q.raw(root()),
|
|
1192
|
+
Object.fromEntries(changeKeys.map(k => [k, null])),
|
|
1193
|
+
],
|
|
1194
|
+
},
|
|
1190
1195
|
});
|
|
1191
1196
|
}
|
|
1192
1197
|
pipeline.push({
|
|
@@ -1221,7 +1226,10 @@ const makeWatchStream = (db, { collection, projection: p, hardMatch: m }, startA
|
|
|
1221
1226
|
};
|
|
1222
1227
|
|
|
1223
1228
|
const actions = {
|
|
1224
|
-
updateMany: (c, args) => [
|
|
1229
|
+
updateMany: (c, args) => [
|
|
1230
|
+
c.updateMany(...args),
|
|
1231
|
+
[`db['${c.collectionName}'].updateMany(...`, args, ')'],
|
|
1232
|
+
],
|
|
1225
1233
|
};
|
|
1226
1234
|
const streamNames = {};
|
|
1227
1235
|
const executes$1 = (view, input, streamName) => {
|
|
@@ -1265,11 +1273,12 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1265
1273
|
const withStop = (next, tr) => {
|
|
1266
1274
|
return addTeardown(() => ({ stop, next: next(), clear }), tr);
|
|
1267
1275
|
};
|
|
1268
|
-
const
|
|
1276
|
+
const nextData = (data) => (next, debug, tr) => ({
|
|
1269
1277
|
cont: withStop(next, tr),
|
|
1270
|
-
data
|
|
1278
|
+
data,
|
|
1271
1279
|
info: { job, debug: `${streamName} on ${collection.collectionName}: ${debug}` },
|
|
1272
1280
|
});
|
|
1281
|
+
const next = nextData([]);
|
|
1273
1282
|
const data = {
|
|
1274
1283
|
input: input.delta,
|
|
1275
1284
|
finalInputFirst: finalInput.raw(true),
|
|
@@ -1289,7 +1298,11 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1289
1298
|
const step2 = () => Promise.all([
|
|
1290
1299
|
last.findOne({ _id: streamName, data }),
|
|
1291
1300
|
last.findOne({ _id: streamName }),
|
|
1292
|
-
]).then(ts => next(step2_5(ts), ts[0]
|
|
1301
|
+
]).then(ts => next(step2_5(ts), ts[0]
|
|
1302
|
+
? `no teardown to handle, starting at ${ts[0].ts}`
|
|
1303
|
+
: ts[1]
|
|
1304
|
+
? 'handle teardown'
|
|
1305
|
+
: 'start fresh'));
|
|
1293
1306
|
const step2_5 = ([same, exists]) => async () => {
|
|
1294
1307
|
const handleTeardown = async (last) => {
|
|
1295
1308
|
if (!last.data)
|
|
@@ -1310,11 +1323,13 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1310
1323
|
return next(step3(same), 'clone into new collection');
|
|
1311
1324
|
};
|
|
1312
1325
|
const step3 = (lastTS) => async () => {
|
|
1313
|
-
const hardQuery = $and(lastTS
|
|
1326
|
+
const hardQuery = $and(lastTS
|
|
1327
|
+
? root().of('touchedAt').has($gteTs(lastTS.ts))
|
|
1328
|
+
: root().of('deletedAt').has($eq(null)), lastTS ? null : match && $expr(match), hardMatch);
|
|
1314
1329
|
const notDeleted = eq($ifNull(root().of('deletedAt').expr(), nil))(nil);
|
|
1315
1330
|
const query = match ? and(notDeleted, match) : notDeleted;
|
|
1316
1331
|
const replaceRaw = $replaceWith_(field({
|
|
1317
|
-
after: ['after', ite(query, root().expr(), nil)],
|
|
1332
|
+
after: ['after', lastTS ? ite(query, root().expr(), nil) : root().expr()],
|
|
1318
1333
|
updated: ['updated', val(true)],
|
|
1319
1334
|
_id: ['_id', root().of('_id').expr()],
|
|
1320
1335
|
}));
|
|
@@ -1377,11 +1392,7 @@ const executes$1 = (view, input, streamName) => {
|
|
|
1377
1392
|
return step8(l);
|
|
1378
1393
|
};
|
|
1379
1394
|
const step8 = (l) => {
|
|
1380
|
-
return
|
|
1381
|
-
data: l.aggResult.cursor.firstBatch,
|
|
1382
|
-
info: { job: undefined, debug: 'wait for change' },
|
|
1383
|
-
cont: withStop(() => l.stream.tryNext().then(doc => (doc ? next(step2, 'restart') : step8(l)))),
|
|
1384
|
-
};
|
|
1395
|
+
return nextData(l.aggResult.cursor.firstBatch)(() => l.stream.tryNext().then(doc => (doc ? next(step2, 'restart') : step8(l))), 'wait for change');
|
|
1385
1396
|
};
|
|
1386
1397
|
return stop;
|
|
1387
1398
|
};
|