@omegup/msync 0.1.44 → 0.1.45

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 +47 -52
  2. package/index.js +47 -52
  3. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -1628,8 +1628,7 @@ const aggregate = (db, streamName, input, snapshot = true, start = Date.now()) =
1628
1628
  };
1629
1629
  log('exec', streamName, req);
1630
1630
  const start2 = Date.now();
1631
- return db
1632
- .then(d => d.command(req))
1631
+ return db.command(req)
1633
1632
  .then(result => {
1634
1633
  log('prepare', streamName, Date.now() - start);
1635
1634
  log('prepare2', streamName, start2 - start);
@@ -1880,54 +1879,9 @@ const getFirstStages = (view, needs) => {
1880
1879
  return { firstStages, hardMatch };
1881
1880
  };
1882
1881
 
1883
- require('dotenv').config();
1884
- const uri = process.env['MONGO_URL'];
1885
-
1886
- const enablePreAndPostImages = (coll) => coll.s.db.command({
1887
- collMod: coll.collectionName,
1888
- changeStreamPreAndPostImages: { enabled: true },
1889
- });
1890
- const prepare = async (testName) => {
1891
- const client = new MongoClient(uri, testName ? { monitorCommands: true } : {});
1892
- if (testName) {
1893
- const handler = (c) => {
1894
- writeFile(`./out/${testName}.log`, JSON.stringify(c.command) + ',\n', { flag: 'w' });
1895
- };
1896
- client.on('commandStarted', handler);
1897
- client.on('commandSucceeded', handler);
1898
- }
1899
- await client.connect();
1900
- await client.db('admin').command({
1901
- setClusterParameter: {
1902
- changeStreamOptions: {
1903
- preAndPostImages: { expireAfterSeconds: 60 },
1904
- },
1905
- },
1906
- });
1907
- return client;
1908
- };
1909
- const makeCol = async (docs, database, name) => {
1910
- if (!name) {
1911
- (name = crypto.randomUUID());
1912
- }
1913
- try {
1914
- const col = await database.createCollection(name, {
1915
- changeStreamPreAndPostImages: { enabled: true },
1916
- });
1917
- if (docs.length)
1918
- await col.insertMany([...docs]);
1919
- return col;
1920
- }
1921
- catch {
1922
- return database.collection(name);
1923
- }
1924
- };
1925
-
1926
1882
  const streamNames = {};
1927
1883
  const executes$2 = (view, input, streamName, skip = false, after, needs = {}) => {
1928
1884
  const { collection, projection, match } = view;
1929
- const client = prepare();
1930
- const pdb = client.then(cl => cl.db(collection.dbName));
1931
1885
  const { firstStages, hardMatch } = getFirstStages(view, needs);
1932
1886
  const db = collection.s.db, coll = collection.collectionName;
1933
1887
  const hash = crypto$1
@@ -2065,7 +2019,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
2065
2019
  whenNotMatched: 'insert',
2066
2020
  })).stages;
2067
2021
  const stream = await makeStream();
2068
- const r = await aggregate(pdb, streamName, c => c({ coll: collection, input: cloneIntoNew }));
2022
+ const r = await aggregate(db, streamName, c => c({ coll: collection, input: cloneIntoNew }));
2069
2023
  const start = Date.now();
2070
2024
  const res = await snapshotCollection.deleteMany({ updated: true, after: null, before: null });
2071
2025
  log('deleting from cloned into new collection', Date.now() - start, res, `db['${snapshotCollection.collectionName}'].deleteMany({ updated: true, after: null, before: null })`);
@@ -2079,7 +2033,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
2079
2033
  const stages = finalInput.raw(first);
2080
2034
  await last.updateOne({ _id: streamName }, { $set: { job: 1 } }, { upsert: true });
2081
2035
  const nextRes = stream.tryNext();
2082
- const aggResult = await aggregate(pdb, streamName, c => c({
2036
+ const aggResult = await aggregate(db, streamName, c => c({
2083
2037
  coll: snapshotCollection,
2084
2038
  input: link()
2085
2039
  .with($match_(root().of('updated').has($eq(true))))
@@ -2161,8 +2115,6 @@ const executes$1 = (view, input, streamName, needs) => {
2161
2115
  else if (streamNames[streamName] != hash)
2162
2116
  throw new Error('streamName already used');
2163
2117
  const { collection, projection, hardMatch: pre, match } = view;
2164
- const client = prepare();
2165
- const pdb = client.then(cl => cl.db(collection.dbName));
2166
2118
  const removeNotYetSynchronizedFields = projection &&
2167
2119
  Object.values(mapExactToObject(projection, (_, k) => (needs[k] ?? k.startsWith('_')) ? root().of(k).has($exists(true)) : null));
2168
2120
  const hardMatch = removeNotYetSynchronizedFields
@@ -2256,7 +2208,7 @@ const executes$1 = (view, input, streamName, needs) => {
2256
2208
  const raw = stages(lastTS).with(finalInput.raw(lastTS === null)).stages;
2257
2209
  const stream = await makeStream();
2258
2210
  const nextRes = stream.tryNext();
2259
- const aggResult = await aggregate(pdb, streamName, c => c({
2211
+ const aggResult = await aggregate(db, streamName, c => c({
2260
2212
  coll: collection,
2261
2213
  input: raw,
2262
2214
  }));
@@ -2299,4 +2251,47 @@ const executes = (view, input, needs) => {
2299
2251
  };
2300
2252
  const single = (view, needs = {}) => pipe(input => executes(view, input, needs), emptyDelta(), concatDelta, emptyDelta);
2301
2253
 
2254
+ require('dotenv').config();
2255
+ const uri = process.env['MONGO_URL'];
2256
+
2257
+ const enablePreAndPostImages = (coll) => coll.s.db.command({
2258
+ collMod: coll.collectionName,
2259
+ changeStreamPreAndPostImages: { enabled: true },
2260
+ });
2261
+ const prepare = async (testName) => {
2262
+ const client = new MongoClient(uri, testName ? { monitorCommands: true } : {});
2263
+ if (testName) {
2264
+ const handler = (c) => {
2265
+ writeFile(`./out/${testName}.log`, JSON.stringify(c.command) + ',\n', { flag: 'w' });
2266
+ };
2267
+ client.on('commandStarted', handler);
2268
+ client.on('commandSucceeded', handler);
2269
+ }
2270
+ await client.connect();
2271
+ await client.db('admin').command({
2272
+ setClusterParameter: {
2273
+ changeStreamOptions: {
2274
+ preAndPostImages: { expireAfterSeconds: 60 },
2275
+ },
2276
+ },
2277
+ });
2278
+ return client;
2279
+ };
2280
+ const makeCol = async (docs, database, name) => {
2281
+ if (!name) {
2282
+ (name = crypto.randomUUID());
2283
+ }
2284
+ try {
2285
+ const col = await database.createCollection(name, {
2286
+ changeStreamPreAndPostImages: { enabled: true },
2287
+ });
2288
+ if (docs.length)
2289
+ await col.insertMany([...docs]);
2290
+ return col;
2291
+ }
2292
+ catch {
2293
+ return database.collection(name);
2294
+ }
2295
+ };
2296
+
2302
2297
  export { $accumulator, $and, $countDict, $countDictArray, $entries, $eq, $exists, $expr, $getField, $group, $groupId, $groupMerge, $group_, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $insert, $insertPart, $insertX, $keys, $let, $lookup, $lt, $lte, $map, $map0, $map1, $match, $matchDelta, $merge, $merge2, $mergeId, $mergePart, $merge_, $ne, $nin, $nor, $or, $outerLookup, $pushDict, $rand, $reduce, $replaceWith, $set, $simpleInsert, $simpleMerge, $simpleMergePart, $substr, $sum, $type, $unwind, $unwindDelta, Field, Machine, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, emptyDelta, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first$1 as first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapFromPlainDateTime, mapToPlainDateTime, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, not, notNull, now, or, padLeft, pair, prepare, rand, range, regex, root, set, setField, single, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
package/index.js CHANGED
@@ -1630,8 +1630,7 @@ const aggregate = (db, streamName, input, snapshot = true, start = Date.now()) =
1630
1630
  };
1631
1631
  log('exec', streamName, req);
1632
1632
  const start2 = Date.now();
1633
- return db
1634
- .then(d => d.command(req))
1633
+ return db.command(req)
1635
1634
  .then(result => {
1636
1635
  log('prepare', streamName, Date.now() - start);
1637
1636
  log('prepare2', streamName, start2 - start);
@@ -1882,54 +1881,9 @@ const getFirstStages = (view, needs) => {
1882
1881
  return { firstStages, hardMatch };
1883
1882
  };
1884
1883
 
1885
- require('dotenv').config();
1886
- const uri = process.env['MONGO_URL'];
1887
-
1888
- const enablePreAndPostImages = (coll) => coll.s.db.command({
1889
- collMod: coll.collectionName,
1890
- changeStreamPreAndPostImages: { enabled: true },
1891
- });
1892
- const prepare = async (testName) => {
1893
- const client = new mongodb.MongoClient(uri, testName ? { monitorCommands: true } : {});
1894
- if (testName) {
1895
- const handler = (c) => {
1896
- promises.writeFile(`./out/${testName}.log`, JSON.stringify(c.command) + ',\n', { flag: 'w' });
1897
- };
1898
- client.on('commandStarted', handler);
1899
- client.on('commandSucceeded', handler);
1900
- }
1901
- await client.connect();
1902
- await client.db('admin').command({
1903
- setClusterParameter: {
1904
- changeStreamOptions: {
1905
- preAndPostImages: { expireAfterSeconds: 60 },
1906
- },
1907
- },
1908
- });
1909
- return client;
1910
- };
1911
- const makeCol = async (docs, database, name) => {
1912
- if (!name) {
1913
- (name = crypto.randomUUID());
1914
- }
1915
- try {
1916
- const col = await database.createCollection(name, {
1917
- changeStreamPreAndPostImages: { enabled: true },
1918
- });
1919
- if (docs.length)
1920
- await col.insertMany([...docs]);
1921
- return col;
1922
- }
1923
- catch {
1924
- return database.collection(name);
1925
- }
1926
- };
1927
-
1928
1884
  const streamNames = {};
1929
1885
  const executes$2 = (view, input, streamName, skip = false, after, needs = {}) => {
1930
1886
  const { collection, projection, match } = view;
1931
- const client = prepare();
1932
- const pdb = client.then(cl => cl.db(collection.dbName));
1933
1887
  const { firstStages, hardMatch } = getFirstStages(view, needs);
1934
1888
  const db = collection.s.db, coll = collection.collectionName;
1935
1889
  const hash = crypto$1
@@ -2067,7 +2021,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
2067
2021
  whenNotMatched: 'insert',
2068
2022
  })).stages;
2069
2023
  const stream = await makeStream();
2070
- const r = await aggregate(pdb, streamName, c => c({ coll: collection, input: cloneIntoNew }));
2024
+ const r = await aggregate(db, streamName, c => c({ coll: collection, input: cloneIntoNew }));
2071
2025
  const start = Date.now();
2072
2026
  const res = await snapshotCollection.deleteMany({ updated: true, after: null, before: null });
2073
2027
  log('deleting from cloned into new collection', Date.now() - start, res, `db['${snapshotCollection.collectionName}'].deleteMany({ updated: true, after: null, before: null })`);
@@ -2081,7 +2035,7 @@ const executes$2 = (view, input, streamName, skip = false, after, needs = {}) =>
2081
2035
  const stages = finalInput.raw(first);
2082
2036
  await last.updateOne({ _id: streamName }, { $set: { job: 1 } }, { upsert: true });
2083
2037
  const nextRes = stream.tryNext();
2084
- const aggResult = await aggregate(pdb, streamName, c => c({
2038
+ const aggResult = await aggregate(db, streamName, c => c({
2085
2039
  coll: snapshotCollection,
2086
2040
  input: link()
2087
2041
  .with($match_(root().of('updated').has($eq(true))))
@@ -2163,8 +2117,6 @@ const executes$1 = (view, input, streamName, needs) => {
2163
2117
  else if (streamNames[streamName] != hash)
2164
2118
  throw new Error('streamName already used');
2165
2119
  const { collection, projection, hardMatch: pre, match } = view;
2166
- const client = prepare();
2167
- const pdb = client.then(cl => cl.db(collection.dbName));
2168
2120
  const removeNotYetSynchronizedFields = projection &&
2169
2121
  Object.values(mapExactToObject(projection, (_, k) => (needs[k] ?? k.startsWith('_')) ? root().of(k).has($exists(true)) : null));
2170
2122
  const hardMatch = removeNotYetSynchronizedFields
@@ -2258,7 +2210,7 @@ const executes$1 = (view, input, streamName, needs) => {
2258
2210
  const raw = stages(lastTS).with(finalInput.raw(lastTS === null)).stages;
2259
2211
  const stream = await makeStream();
2260
2212
  const nextRes = stream.tryNext();
2261
- const aggResult = await aggregate(pdb, streamName, c => c({
2213
+ const aggResult = await aggregate(db, streamName, c => c({
2262
2214
  coll: collection,
2263
2215
  input: raw,
2264
2216
  }));
@@ -2301,6 +2253,49 @@ const executes = (view, input, needs) => {
2301
2253
  };
2302
2254
  const single = (view, needs = {}) => pipe(input => executes(view, input, needs), emptyDelta(), concatDelta, emptyDelta);
2303
2255
 
2256
+ require('dotenv').config();
2257
+ const uri = process.env['MONGO_URL'];
2258
+
2259
+ const enablePreAndPostImages = (coll) => coll.s.db.command({
2260
+ collMod: coll.collectionName,
2261
+ changeStreamPreAndPostImages: { enabled: true },
2262
+ });
2263
+ const prepare = async (testName) => {
2264
+ const client = new mongodb.MongoClient(uri, testName ? { monitorCommands: true } : {});
2265
+ if (testName) {
2266
+ const handler = (c) => {
2267
+ promises.writeFile(`./out/${testName}.log`, JSON.stringify(c.command) + ',\n', { flag: 'w' });
2268
+ };
2269
+ client.on('commandStarted', handler);
2270
+ client.on('commandSucceeded', handler);
2271
+ }
2272
+ await client.connect();
2273
+ await client.db('admin').command({
2274
+ setClusterParameter: {
2275
+ changeStreamOptions: {
2276
+ preAndPostImages: { expireAfterSeconds: 60 },
2277
+ },
2278
+ },
2279
+ });
2280
+ return client;
2281
+ };
2282
+ const makeCol = async (docs, database, name) => {
2283
+ if (!name) {
2284
+ (name = crypto.randomUUID());
2285
+ }
2286
+ try {
2287
+ const col = await database.createCollection(name, {
2288
+ changeStreamPreAndPostImages: { enabled: true },
2289
+ });
2290
+ if (docs.length)
2291
+ await col.insertMany([...docs]);
2292
+ return col;
2293
+ }
2294
+ catch {
2295
+ return database.collection(name);
2296
+ }
2297
+ };
2298
+
2304
2299
  exports.$accumulator = $accumulator;
2305
2300
  exports.$and = $and;
2306
2301
  exports.$countDict = $countDict;
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.44",
6
+ "version": "0.1.45",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",