@omegup/msync 0.1.38 → 0.1.40

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
@@ -120,7 +120,7 @@ type LinStages<out Q, in S extends Q, out R extends Q, in C = unknown> = {
120
120
  };
121
121
  type TStages<in out S, out Q, in out B extends Q, out R extends Q, M extends number = number> = {
122
122
  coll: ReadonlyCollection<S>;
123
- input: RawStages<unknown, S, B, unknown, M>;
123
+ input: RawStages<unknown, S, S & B, unknown, M>;
124
124
  exec: RawStages<Q, B, R, unknown, M>;
125
125
  };
126
126
  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;
@@ -353,6 +353,7 @@ declare const $rand: Expr<string, unknown, unknown>;
353
353
  declare const $sum: <D extends O, C = unknown>(expr: Expr<number | N, D, C>) => DeltaAccumulator<D, number, C>;
354
354
  declare const $accumulator: <D, T, Ctx, A extends readonly unknown[]>(init: () => NoRaw<T>, accumulateArgs: AppMap<ExprHKT<Part<D>, Ctx>, A>, accumulate: (a: NoRaw<T>, ...args: NoRaw<A>) => NoRaw<T>, merge: (...args: NoRaw<[T | N, T]>) => NoRaw<T>) => DeltaAccumulator<D, T, Ctx>;
355
355
  declare const $countDict: <D extends O, C = unknown>(expr: Expr<string, D, C>) => DeltaAccumulator<D, Rec<string, number>, C>;
356
+ declare const $countDictArray: <D extends O, C = unknown>(expr: Expr<Arr<string>, D, C>) => DeltaAccumulator<D, Rec<string, number>, C>;
356
357
  declare const $pushDict: <D extends O, V, C = unknown>(key: Expr<string, D, C>, value: Expr<V, D, C>) => DeltaAccumulator<D, Rec<string, Rec<"0" | "1", Arr<V>>>, C>;
357
358
  declare const $keys: <D extends O, C = unknown>(expr: Expr<Rec<string, number>, D, C>) => Expr<Arr<string>, D, C>;
358
359
  declare const $entries: <D extends O, V, C = unknown>(expr: Expr<Rec<string, Rec<"1" | "0", Arr<V>>>, D, C>) => Expr<Arr<Rec<"k", string> & Rec<"v", V>>, D, C>;
@@ -412,8 +413,8 @@ declare const $groupId: <T extends O, V extends O, EE = {}, Out extends Loose<st
412
413
  declare const $group: <T extends O, Grp extends notArr, V extends O, EE = {}, Out extends Loose<Grp, V, "_grp"> = Loose<Grp, V, "_grp">>(id: Expr<Grp, T>, args: DeltaAccumulators<T, O & Omit<V, Denied<"_grp">>>, out: RWCollection<MergedInput<Out, V, Grp, "_grp", EE> | Strict<Grp, V, "_grp", EE>, Out>, extra: ExprsExact<Omit<EE, IdAndTsKeys | "_grp" | Exclude<keyof V, IdAndTsKeys | "_grp">>, Rec<"_grp", Grp> & Omit<V, IdAndTsKeys | "_grp">>, idPrefix?: string) => StreamRunnerParam<Delta<T>, "out">;
413
414
 
414
415
  type Params<As extends string, LQ extends O, RQ extends O, RE extends RQ, S extends notArr> = {
415
- localField: Field<LQ, S>;
416
- foreignField: Field<RQ, S>;
416
+ localField: Field<LQ, S | Arr<S>>;
417
+ foreignField: Field<RQ, S | Arr<S>>;
417
418
  from: SnapshotStreamExecutionResult<RQ, RE>;
418
419
  as: AsLiteral<As>;
419
420
  };
@@ -700,5 +701,5 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
700
701
  declare const prepare: (testName?: string) => Promise<MongoClient$1>;
701
702
  declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
702
703
 
703
- export { $accumulator, $and, $countDict, $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, Expr, Field, Machine, Type, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, 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 };
704
+ 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, Expr, Field, Machine, Type, add, and, anyElementTrue, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, 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 };
704
705
  export type { Accumulators, Arr, AsLiteral, Delta, DeltaAccumulator, DeltaAccumulators, ExactKeys, ExprHKT, Exprs, ExprsExact, ExprsExactHKT, ExprsPart, ID, Loose, Merge, MergeArgs, MergeInto, MergeMapOArgs, Model, MongoTypeNames, N, NoRaw, NullToOBJ, O, OPick, OPickD, Patch, RONoRaw, RORec, RawStages, Rec, Replace, SnapshotStreamExecutionResult, StrKey, Strict, TS, WriteonlyCollection, doc, jsonPrim, notArr };
package/index.esm.js CHANGED
@@ -249,6 +249,23 @@ const $countDict = (expr) => $accumulator(function () {
249
249
  return y ? (a[k] = y) : delete a[k], a;
250
250
  }, a || {});
251
251
  });
252
+ const $countDictArray = (expr) => $accumulator(function () {
253
+ return {};
254
+ }, [sub(expr, root().of('v')), root().of('old').expr()], function (a, keys, old) {
255
+ keys.forEach(k => {
256
+ const y = (a[k] || 0) + (old ? -1 : 1);
257
+ if (y)
258
+ a[k] = y;
259
+ else
260
+ delete a[k];
261
+ });
262
+ return a;
263
+ }, function (a, b) {
264
+ return Object.keys(b).reduce((a, k) => {
265
+ let y = (a[k] || 0) + b[k];
266
+ return y ? (a[k] = y) : delete a[k], a;
267
+ }, a || {});
268
+ });
252
269
  const $pushDict = (key, value) => $accumulator(function () {
253
270
  return {};
254
271
  }, [
@@ -514,6 +531,7 @@ const $group1 = (id, args) => (f) => asStages([
514
531
  const rawVars = (vars, f) => mapExactToObject(vars, v => v.raw(f).get());
515
532
  const $simpleLookup1 = (args) => f => {
516
533
  const { coll, k, vars, fields, ...etc } = args;
534
+ const letVars = rawVars(vars, f());
517
535
  return asStages([
518
536
  {
519
537
  $lookup: {
@@ -523,7 +541,7 @@ const $simpleLookup1 = (args) => f => {
523
541
  foreignField: root().with(fields.foreign).str(),
524
542
  }),
525
543
  as: f().of(k).str(),
526
- let: rawVars(vars, f()),
544
+ ...(Object.keys(letVars).length > 0 && { let: letVars }),
527
545
  ...etc,
528
546
  },
529
547
  },
@@ -1271,10 +1289,10 @@ const $lookupRaw = ({ field1, field2 }, { coll, exec, input }, k2, k, includeNul
1271
1289
  .with($simpleLookup1({
1272
1290
  coll,
1273
1291
  k: k2,
1274
- vars: map1('local', root().with(field1).expr()),
1292
+ fields: { local: field1, foreign: root().of('before').with(field2) },
1293
+ vars: {},
1275
1294
  pipeline: link()
1276
1295
  .with(input)
1277
- .with($match_($expr(eq(ctx()('local').expr())(root().of('before').with(field2).expr()))))
1278
1296
  .with(exec)
1279
1297
  .with($replaceWith_(root().of('before').expr())).stages,
1280
1298
  })(f))
@@ -2279,4 +2297,4 @@ const executes = (view, input, needs) => {
2279
2297
  };
2280
2298
  const single = (view, needs = {}) => pipe(input => executes(view, input, needs), emptyDelta(), concatDelta, emptyDelta);
2281
2299
 
2282
- export { $accumulator, $and, $countDict, $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$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, 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 };
2300
+ 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$1 as concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, 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
@@ -251,6 +251,23 @@ const $countDict = (expr) => $accumulator(function () {
251
251
  return y ? (a[k] = y) : delete a[k], a;
252
252
  }, a || {});
253
253
  });
254
+ const $countDictArray = (expr) => $accumulator(function () {
255
+ return {};
256
+ }, [sub(expr, root().of('v')), root().of('old').expr()], function (a, keys, old) {
257
+ keys.forEach(k => {
258
+ const y = (a[k] || 0) + (old ? -1 : 1);
259
+ if (y)
260
+ a[k] = y;
261
+ else
262
+ delete a[k];
263
+ });
264
+ return a;
265
+ }, function (a, b) {
266
+ return Object.keys(b).reduce((a, k) => {
267
+ let y = (a[k] || 0) + b[k];
268
+ return y ? (a[k] = y) : delete a[k], a;
269
+ }, a || {});
270
+ });
254
271
  const $pushDict = (key, value) => $accumulator(function () {
255
272
  return {};
256
273
  }, [
@@ -516,6 +533,7 @@ const $group1 = (id, args) => (f) => asStages([
516
533
  const rawVars = (vars, f) => mapExactToObject(vars, v => v.raw(f).get());
517
534
  const $simpleLookup1 = (args) => f => {
518
535
  const { coll, k, vars, fields, ...etc } = args;
536
+ const letVars = rawVars(vars, f());
519
537
  return asStages([
520
538
  {
521
539
  $lookup: {
@@ -525,7 +543,7 @@ const $simpleLookup1 = (args) => f => {
525
543
  foreignField: root().with(fields.foreign).str(),
526
544
  }),
527
545
  as: f().of(k).str(),
528
- let: rawVars(vars, f()),
546
+ ...(Object.keys(letVars).length > 0 && { let: letVars }),
529
547
  ...etc,
530
548
  },
531
549
  },
@@ -1273,10 +1291,10 @@ const $lookupRaw = ({ field1, field2 }, { coll, exec, input }, k2, k, includeNul
1273
1291
  .with($simpleLookup1({
1274
1292
  coll,
1275
1293
  k: k2,
1276
- vars: map1('local', root().with(field1).expr()),
1294
+ fields: { local: field1, foreign: root().of('before').with(field2) },
1295
+ vars: {},
1277
1296
  pipeline: link()
1278
1297
  .with(input)
1279
- .with($match_($expr(eq(ctx()('local').expr())(root().of('before').with(field2).expr()))))
1280
1298
  .with(exec)
1281
1299
  .with($replaceWith_(root().of('before').expr())).stages,
1282
1300
  })(f))
@@ -2284,6 +2302,7 @@ const single = (view, needs = {}) => pipe(input => executes(view, input, needs),
2284
2302
  exports.$accumulator = $accumulator;
2285
2303
  exports.$and = $and;
2286
2304
  exports.$countDict = $countDict;
2305
+ exports.$countDictArray = $countDictArray;
2287
2306
  exports.$entries = $entries;
2288
2307
  exports.$eq = $eq;
2289
2308
  exports.$exists = $exists;
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.38",
6
+ "version": "0.1.40",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",