@omegup/msync 0.0.10 → 0.0.12

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
@@ -102,7 +102,6 @@ type D = O<{
102
102
  readonly deletedAt?: Timestamp | null | undefined;
103
103
  } & ID>;
104
104
  type Model = D & TS;
105
- type OutInput<T, A = T | null> = ID & Rec<'after', A>;
106
105
  type BA = 'before' | 'after';
107
106
  type PreDelta<T, K extends BA = BA, E = unknown> = Rec<K, T> & E;
108
107
  type Delta<T, K extends BA = BA, E = ID> = PreDelta<T | null, K, E>;
@@ -476,7 +475,7 @@ type ND = {
476
475
  readonly deletedAt?: null;
477
476
  };
478
477
  type Merge<T extends ID> = (T & ND & TS) | Del;
479
- declare const $upsert: <T extends doc>(out: RWCollection<Merge<T>>) => RawStages<unknown, OutInput<T>, "out">;
478
+ declare const $upsert: <T extends doc>(out: RWCollection<Merge<T>>) => RawStages<unknown, Delta<T>, "out">;
480
479
 
481
480
  type DeltaPipe<Q extends O, T extends Q, F extends HKT<O2>, G extends HKT<O3>> = {
482
481
  with: <Q2 extends O, V extends Q2>(map: (a: Stream<Q, T, F, G>) => Stream<Q | Q2, V, F, G>) => DeltaPipe<Q | Q2, V, F, G>;
@@ -557,6 +556,7 @@ declare const dayAndMonthPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D,
557
556
  declare const now: <D, C>() => Expr<Date, D, C>;
558
557
  declare const monthPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
559
558
  declare const weekPart: <D, C>(date: Expr<Date, D, C>) => Expr<string, D, C>;
559
+ declare const year: <D, C>(date: Expr<Date, D, C>) => Expr<number, D, C>;
560
560
  declare const dateAdd: <D, C>(date: Expr<Date, D, C>, amount: Expr<number, D, C>, unit: Expr<"year" | "week" | "month" | "day" | "hour" | "minute" | "second", D, C>) => Expr<Date, D, C>;
561
561
  declare const maxDate: <D, C>(expr: Expr<Arr<Date>, D, C>) => Expr<Date, D, C>;
562
562
  declare const minDate: <D, C>(expr: Expr<Arr<Date>, D, C>) => Expr<Date, D, C>;
@@ -642,4 +642,4 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
642
642
  declare const prepare: (testName?: string) => Promise<MongoClient$1>;
643
643
  declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
644
644
 
645
- export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $simpleMerge, $sum, $unwind, $unwindDelta, $upsert, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type N, type NoRaw, type O, type OPick, type OPickD, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, type notArr, notNull, now, or, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap };
645
+ export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $simpleMerge, $sum, $unwind, $unwindDelta, $upsert, type Accumulators, type Arr, type AsLiteral, type Delta, type DeltaAccumulator, type DeltaAccumulators, Expr, type ExprHKT, type Exprs, type ExprsExact, type ExprsExactHKT, type ExprsPart, Field, type ID, type Loose, Machine, type Merge, type MergeArgs, type MergeInto, type MergeMapOArgs, type Model, type N, type NoRaw, type O, type OPick, type OPickD, type RONoRaw, type RORec, type RawStages, type Rec, type Replace, type SnapshotStreamExecutionResult, type StrKey, type Strict, type TS, Type, type WriteonlyCollection, add, and, array, ceil, comp, concat, concatArray, createIndex, ctx, current, dateAdd, dateDiff, dateLt, datePart, dayAndMonthPart, divide, type doc, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, type notArr, notNull, now, or, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
package/index.esm.js CHANGED
@@ -1030,18 +1030,18 @@ const $mergeId = () => (out, keys, id) => {
1030
1030
  })).stages;
1031
1031
  };
1032
1032
  const $simpleMerge = () => (out, keys) => $mergeId()(out, keys, root().of('_id').expr());
1033
- const $merge = () => (out, keys) => $mergeId()(out, keys, assertNotNull(root()
1033
+ const $merge = () => (out, keys) => $mergeId()(out, keys, assertNotNull$1(root()
1034
1034
  .of('before')
1035
1035
  .of('_id')
1036
1036
  .expr()));
1037
- const assertNotNull = (expr) => expr;
1037
+ const assertNotNull$1 = (expr) => expr;
1038
1038
 
1039
1039
  const $upsert = (out) => {
1040
- const replacer = ite(eqTyped(root().of('after').expr(), nil), field({
1040
+ const replacer = ite(eq(root().of('after').expr())(nil), field({
1041
1041
  deletedAt: ['deletedAt', current],
1042
- _id: ['_id', root().of('_id').expr()],
1042
+ _id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
1043
1043
  touchedAt: ['touchedAt', current],
1044
- }), mergeObjects(root().of('after').expr(), field({ deletedAt: ['deletedAt', nil], touchedAt: ['touchedAt', current] })));
1044
+ }), mergeObjects(assertNotNull(root().of('after').expr()), field({ deletedAt: ['deletedAt', nil], touchedAt: ['touchedAt', current] })));
1045
1045
  return link()
1046
1046
  .with($replaceWith_(replacer))
1047
1047
  .with($merge_({
@@ -1051,6 +1051,7 @@ const $upsert = (out) => {
1051
1051
  whenNotMatched: 'insert',
1052
1052
  })).stages;
1053
1053
  };
1054
+ const assertNotNull = (expr) => expr;
1054
1055
 
1055
1056
  const T = (s) => `Timestamp(${parseInt(`${BigInt(s) / 2n ** 32n}`)}, ${parseInt(`${BigInt(s) % 2n ** 32n}`)})`;
1056
1057
  const replace = (s) => s.replace(/\{"\$timestamp":"(\d+)"\}/g, (_, d) => T(d));
@@ -1358,6 +1359,9 @@ const monthPart = (date) => asExpr({
1358
1359
  const weekPart = (date) => asExpr({
1359
1360
  raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%Y-%U' } }),
1360
1361
  });
1362
+ const year = (date) => asExpr({
1363
+ raw: f => asExprRaw({ $year: date.raw(f).get() }),
1364
+ });
1361
1365
  const dateAdd = (date, amount, unit) => asExpr({
1362
1366
  raw: f => asExprRaw({
1363
1367
  $dateAdd: {
@@ -1621,4 +1625,4 @@ const makeCol = async (docs, database, name) => {
1621
1625
  }
1622
1626
  };
1623
1627
 
1624
- export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $simpleMerge, $sum, $unwind, $unwindDelta, $upsert, Field, Machine, add, and, 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, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, notNull, now, or, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap };
1628
+ export { $accumulator, $and, $countDict, $entries, $eq, $expr, $getField, $group, $groupId, $groupMerge, $gt, $gtTs, $gte, $gteTs, $ifNull, $in, $keys, $let, $lookup, $lt, $lte, $map, $map1, $match, $matchDelta, $merge, $merge_, $ne, $nin, $nor, $or, $pushDict, $rand, $replaceWith, $set, $simpleMerge, $sum, $unwind, $unwindDelta, $upsert, Field, Machine, add, and, 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, gt, gte, inArray, isArray, ite, last, log, lt, lte, makeCol, map1, mapVal, max, maxDate, mergeExact, mergeExact0, mergeExpr, mergeObjects, minDate, monthPart, multiply, ne, nil, noop, notNull, now, or, pair, prepare, rand, range, root, set, setField, size, slice, sortArray, staging, startOf, str, sub, subtract, to, toInt, val, weekPart, wrap, year };
package/index.js CHANGED
@@ -1032,18 +1032,18 @@ const $mergeId = () => (out, keys, id) => {
1032
1032
  })).stages;
1033
1033
  };
1034
1034
  const $simpleMerge = () => (out, keys) => $mergeId()(out, keys, root().of('_id').expr());
1035
- const $merge = () => (out, keys) => $mergeId()(out, keys, assertNotNull(root()
1035
+ const $merge = () => (out, keys) => $mergeId()(out, keys, assertNotNull$1(root()
1036
1036
  .of('before')
1037
1037
  .of('_id')
1038
1038
  .expr()));
1039
- const assertNotNull = (expr) => expr;
1039
+ const assertNotNull$1 = (expr) => expr;
1040
1040
 
1041
1041
  const $upsert = (out) => {
1042
- const replacer = ite(eqTyped(root().of('after').expr(), nil), field({
1042
+ const replacer = ite(eq(root().of('after').expr())(nil), field({
1043
1043
  deletedAt: ['deletedAt', current],
1044
- _id: ['_id', root().of('_id').expr()],
1044
+ _id: ['_id', assertNotNull(root().of('before').of('_id').expr())],
1045
1045
  touchedAt: ['touchedAt', current],
1046
- }), mergeObjects(root().of('after').expr(), field({ deletedAt: ['deletedAt', nil], touchedAt: ['touchedAt', current] })));
1046
+ }), mergeObjects(assertNotNull(root().of('after').expr()), field({ deletedAt: ['deletedAt', nil], touchedAt: ['touchedAt', current] })));
1047
1047
  return link()
1048
1048
  .with($replaceWith_(replacer))
1049
1049
  .with($merge_({
@@ -1053,6 +1053,7 @@ const $upsert = (out) => {
1053
1053
  whenNotMatched: 'insert',
1054
1054
  })).stages;
1055
1055
  };
1056
+ const assertNotNull = (expr) => expr;
1056
1057
 
1057
1058
  const T = (s) => `Timestamp(${parseInt(`${BigInt(s) / 2n ** 32n}`)}, ${parseInt(`${BigInt(s) % 2n ** 32n}`)})`;
1058
1059
  const replace = (s) => s.replace(/\{"\$timestamp":"(\d+)"\}/g, (_, d) => T(d));
@@ -1360,6 +1361,9 @@ const monthPart = (date) => asExpr({
1360
1361
  const weekPart = (date) => asExpr({
1361
1362
  raw: f => asExprRaw({ $dateToString: { date: date.raw(f).get(), format: '%Y-%U' } }),
1362
1363
  });
1364
+ const year = (date) => asExpr({
1365
+ raw: f => asExprRaw({ $year: date.raw(f).get() }),
1366
+ });
1363
1367
  const dateAdd = (date, amount, unit) => asExpr({
1364
1368
  raw: f => asExprRaw({
1365
1369
  $dateAdd: {
@@ -1743,3 +1747,4 @@ exports.toInt = toInt;
1743
1747
  exports.val = val;
1744
1748
  exports.weekPart = weekPart;
1745
1749
  exports.wrap = wrap;
1750
+ exports.year = year;
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.0.10",
6
+ "version": "0.0.12",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",