@omegup/msync 0.1.15 → 0.1.17
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 +38 -24
- package/index.js +38 -24
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -1331,13 +1331,50 @@ const mergeIterators = (params) => {
|
|
|
1331
1331
|
};
|
|
1332
1332
|
};
|
|
1333
1333
|
|
|
1334
|
+
const T = (s) => `Timestamp(${parseInt(`${BigInt(s) / 2n ** 32n}`)}, ${parseInt(`${BigInt(s) % 2n ** 32n}`)})`;
|
|
1335
|
+
const replace = (s) => s.replace(/\{"\$timestamp":"(\d+)"\}/g, (_, d) => T(d));
|
|
1336
|
+
const json = (a) => replace(JSON.stringify(a));
|
|
1337
|
+
const log = (...args) => console.log(new Date(), ...args.map(a => (typeof a === 'function' ? a(replace) : a && typeof a === 'object' ? json(a) : a)));
|
|
1338
|
+
|
|
1339
|
+
const state = { steady: false };
|
|
1340
|
+
let timeout = null;
|
|
1341
|
+
const aggregate = (streamName, input, snapshot = true, start = Date.now()) => input(({ coll, input }) => {
|
|
1342
|
+
const req = {
|
|
1343
|
+
aggregate: coll.collectionName,
|
|
1344
|
+
pipeline: input,
|
|
1345
|
+
cursor: {},
|
|
1346
|
+
...(snapshot && { readConcern: { level: 'snapshot' } }),
|
|
1347
|
+
};
|
|
1348
|
+
if (timeout !== null) {
|
|
1349
|
+
clearTimeout(timeout);
|
|
1350
|
+
timeout = null;
|
|
1351
|
+
}
|
|
1352
|
+
log('exec', streamName, req);
|
|
1353
|
+
return coll.s.db.command(req).then(result => {
|
|
1354
|
+
const r = result;
|
|
1355
|
+
log('execed', streamName, (replace) => replace(JSON.stringify(req).replaceAll('$$CLUSTER_TIME', JSON.stringify(r.cursor.atClusterTime))), result, 'took', Date.now() - start);
|
|
1356
|
+
if (!state.steady) {
|
|
1357
|
+
if (timeout !== null)
|
|
1358
|
+
throw new Error('timeout should be null');
|
|
1359
|
+
timeout = setTimeout(() => {
|
|
1360
|
+
state.steady = true;
|
|
1361
|
+
console.log('steady');
|
|
1362
|
+
}, 1000);
|
|
1363
|
+
}
|
|
1364
|
+
return r;
|
|
1365
|
+
}, err => {
|
|
1366
|
+
log('err', req, err);
|
|
1367
|
+
throw new Error(err);
|
|
1368
|
+
});
|
|
1369
|
+
});
|
|
1370
|
+
|
|
1334
1371
|
const firstWorksMerge = (iters) => {
|
|
1335
1372
|
const iterator = () => {
|
|
1336
1373
|
const results = iters.map(iter => iter());
|
|
1337
1374
|
const sources = { ...results };
|
|
1338
1375
|
return mergeIterators({
|
|
1339
1376
|
sources,
|
|
1340
|
-
interrupt: key =>
|
|
1377
|
+
interrupt: key => state.steady
|
|
1341
1378
|
});
|
|
1342
1379
|
};
|
|
1343
1380
|
return iterator;
|
|
@@ -1501,29 +1538,6 @@ const $insertPart = (out, ext) => {
|
|
|
1501
1538
|
const $insert = (out) => $insertPart(out, {});
|
|
1502
1539
|
const assertNotNull = (expr) => expr;
|
|
1503
1540
|
|
|
1504
|
-
const T = (s) => `Timestamp(${parseInt(`${BigInt(s) / 2n ** 32n}`)}, ${parseInt(`${BigInt(s) % 2n ** 32n}`)})`;
|
|
1505
|
-
const replace = (s) => s.replace(/\{"\$timestamp":"(\d+)"\}/g, (_, d) => T(d));
|
|
1506
|
-
const json = (a) => replace(JSON.stringify(a));
|
|
1507
|
-
const log = (...args) => console.log(new Date(), ...args.map(a => (typeof a === 'function' ? a(replace) : a && typeof a === 'object' ? json(a) : a)));
|
|
1508
|
-
|
|
1509
|
-
const aggregate = (streamName, input, snapshot = true, start = Date.now()) => input(({ coll, input }) => {
|
|
1510
|
-
const req = {
|
|
1511
|
-
aggregate: coll.collectionName,
|
|
1512
|
-
pipeline: input,
|
|
1513
|
-
cursor: {},
|
|
1514
|
-
...(snapshot && { readConcern: { level: 'snapshot' } }),
|
|
1515
|
-
};
|
|
1516
|
-
log('exec', streamName, req);
|
|
1517
|
-
return coll.s.db.command(req).then(result => {
|
|
1518
|
-
const r = result;
|
|
1519
|
-
log('execed', streamName, (replace) => replace(JSON.stringify(req).replaceAll('$$CLUSTER_TIME', JSON.stringify(r.cursor.atClusterTime))), result, 'took', Date.now() - start);
|
|
1520
|
-
return r;
|
|
1521
|
-
}, err => {
|
|
1522
|
-
log('err', req, err);
|
|
1523
|
-
throw new Error(err);
|
|
1524
|
-
});
|
|
1525
|
-
});
|
|
1526
|
-
|
|
1527
1541
|
const addTeardown = (it, tr) => {
|
|
1528
1542
|
if (!tr)
|
|
1529
1543
|
return it;
|
package/index.js
CHANGED
|
@@ -1333,13 +1333,50 @@ const mergeIterators = (params) => {
|
|
|
1333
1333
|
};
|
|
1334
1334
|
};
|
|
1335
1335
|
|
|
1336
|
+
const T = (s) => `Timestamp(${parseInt(`${BigInt(s) / 2n ** 32n}`)}, ${parseInt(`${BigInt(s) % 2n ** 32n}`)})`;
|
|
1337
|
+
const replace = (s) => s.replace(/\{"\$timestamp":"(\d+)"\}/g, (_, d) => T(d));
|
|
1338
|
+
const json = (a) => replace(JSON.stringify(a));
|
|
1339
|
+
const log = (...args) => console.log(new Date(), ...args.map(a => (typeof a === 'function' ? a(replace) : a && typeof a === 'object' ? json(a) : a)));
|
|
1340
|
+
|
|
1341
|
+
const state = { steady: false };
|
|
1342
|
+
let timeout = null;
|
|
1343
|
+
const aggregate = (streamName, input, snapshot = true, start = Date.now()) => input(({ coll, input }) => {
|
|
1344
|
+
const req = {
|
|
1345
|
+
aggregate: coll.collectionName,
|
|
1346
|
+
pipeline: input,
|
|
1347
|
+
cursor: {},
|
|
1348
|
+
...(snapshot && { readConcern: { level: 'snapshot' } }),
|
|
1349
|
+
};
|
|
1350
|
+
if (timeout !== null) {
|
|
1351
|
+
clearTimeout(timeout);
|
|
1352
|
+
timeout = null;
|
|
1353
|
+
}
|
|
1354
|
+
log('exec', streamName, req);
|
|
1355
|
+
return coll.s.db.command(req).then(result => {
|
|
1356
|
+
const r = result;
|
|
1357
|
+
log('execed', streamName, (replace) => replace(JSON.stringify(req).replaceAll('$$CLUSTER_TIME', JSON.stringify(r.cursor.atClusterTime))), result, 'took', Date.now() - start);
|
|
1358
|
+
if (!state.steady) {
|
|
1359
|
+
if (timeout !== null)
|
|
1360
|
+
throw new Error('timeout should be null');
|
|
1361
|
+
timeout = setTimeout(() => {
|
|
1362
|
+
state.steady = true;
|
|
1363
|
+
console.log('steady');
|
|
1364
|
+
}, 1000);
|
|
1365
|
+
}
|
|
1366
|
+
return r;
|
|
1367
|
+
}, err => {
|
|
1368
|
+
log('err', req, err);
|
|
1369
|
+
throw new Error(err);
|
|
1370
|
+
});
|
|
1371
|
+
});
|
|
1372
|
+
|
|
1336
1373
|
const firstWorksMerge = (iters) => {
|
|
1337
1374
|
const iterator = () => {
|
|
1338
1375
|
const results = iters.map(iter => iter());
|
|
1339
1376
|
const sources = { ...results };
|
|
1340
1377
|
return mergeIterators({
|
|
1341
1378
|
sources,
|
|
1342
|
-
interrupt: key =>
|
|
1379
|
+
interrupt: key => state.steady
|
|
1343
1380
|
});
|
|
1344
1381
|
};
|
|
1345
1382
|
return iterator;
|
|
@@ -1503,29 +1540,6 @@ const $insertPart = (out, ext) => {
|
|
|
1503
1540
|
const $insert = (out) => $insertPart(out, {});
|
|
1504
1541
|
const assertNotNull = (expr) => expr;
|
|
1505
1542
|
|
|
1506
|
-
const T = (s) => `Timestamp(${parseInt(`${BigInt(s) / 2n ** 32n}`)}, ${parseInt(`${BigInt(s) % 2n ** 32n}`)})`;
|
|
1507
|
-
const replace = (s) => s.replace(/\{"\$timestamp":"(\d+)"\}/g, (_, d) => T(d));
|
|
1508
|
-
const json = (a) => replace(JSON.stringify(a));
|
|
1509
|
-
const log = (...args) => console.log(new Date(), ...args.map(a => (typeof a === 'function' ? a(replace) : a && typeof a === 'object' ? json(a) : a)));
|
|
1510
|
-
|
|
1511
|
-
const aggregate = (streamName, input, snapshot = true, start = Date.now()) => input(({ coll, input }) => {
|
|
1512
|
-
const req = {
|
|
1513
|
-
aggregate: coll.collectionName,
|
|
1514
|
-
pipeline: input,
|
|
1515
|
-
cursor: {},
|
|
1516
|
-
...(snapshot && { readConcern: { level: 'snapshot' } }),
|
|
1517
|
-
};
|
|
1518
|
-
log('exec', streamName, req);
|
|
1519
|
-
return coll.s.db.command(req).then(result => {
|
|
1520
|
-
const r = result;
|
|
1521
|
-
log('execed', streamName, (replace) => replace(JSON.stringify(req).replaceAll('$$CLUSTER_TIME', JSON.stringify(r.cursor.atClusterTime))), result, 'took', Date.now() - start);
|
|
1522
|
-
return r;
|
|
1523
|
-
}, err => {
|
|
1524
|
-
log('err', req, err);
|
|
1525
|
-
throw new Error(err);
|
|
1526
|
-
});
|
|
1527
|
-
});
|
|
1528
|
-
|
|
1529
1543
|
const addTeardown = (it, tr) => {
|
|
1530
1544
|
if (!tr)
|
|
1531
1545
|
return it;
|