@omegup/msync 0.1.47 → 0.1.49

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
@@ -26,6 +26,9 @@ type O<T = unknown> = Obj & T;
26
26
  type RORec<K extends keyof never, T = unknown> = {
27
27
  readonly [P in K]: T;
28
28
  };
29
+ type PRRec<K extends keyof never, T = unknown> = {
30
+ [P in K]?: T;
31
+ };
29
32
  type Rec<K extends string, T = unknown> = O<RORec<K, T>>;
30
33
  type O2 = readonly [O, O];
31
34
  type O3 = readonly [O, O, O];
@@ -39,6 +42,7 @@ interface RawObj {
39
42
  type raw = readonly rawItem[] | RawObj;
40
43
  type StrKey<T> = string & keyof T;
41
44
  type Replace<R, V> = Omit<R, StrKey<V>> & V & O;
45
+ type ReplaceQ<R extends Q, VV, Q extends O> = Omit<R, StrKey<VV>> & Omit<VV, StrKey<Q>> & Q;
42
46
  type AsLiteral<T extends keyof any | boolean | N, V = NoUnion<T>> = T extends keyof any ? {} extends {
43
47
  [K in T]: 1;
44
48
  } ? never : V : V;
@@ -206,10 +210,10 @@ type BoolExpr<in D1, in D2, in Ctx = unknown> = {
206
210
 
207
211
  type ExactPart<T, F extends HKT<T[StrKey<T>]>> = MapOPart<T, MappedHKT<T, F>>;
208
212
  type ExactKeys<K extends string> = Exact<RORec<K, 1>, IdHKT>;
209
- type MapO<T, F extends HKT<StrKey<T>>> = MapOPart<T, F> & {
210
- readonly [P: string]: readonly [StrKey<T>, unknown];
213
+ type MapO<T, F extends HKT<K>, K extends StrKey<T> = StrKey<T>> = MapOPart<T, F, K> & {
214
+ readonly [P: string]: readonly [K, unknown];
211
215
  };
212
- type MapOPart<T, F extends HKT<StrKey<T>>, K extends keyof T = StrKey<T>> = {
216
+ type MapOPart<T, F extends HKT<K>, K extends keyof T = StrKey<T>> = {
213
217
  readonly [P in K]: readonly [P, App<F, P & string>];
214
218
  };
215
219
  type Exact<T, F extends HKT<T[StrKey<T>]>> = MapO<T, MappedHKT<T, F>>;
@@ -351,27 +355,29 @@ declare const $getField: {
351
355
  <T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T, D, C>, field: K): Expr<T[K], D, C>;
352
356
  <T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T | N, D, C>, field: K): Expr<T[K] | null, D, C>;
353
357
  };
354
- type NoRaw<T> = T extends Arr<infer U> ? NoRaw<U>[] : T extends readonly unknown[] ? {
355
- [K in keyof T]: NoRaw<T[K]>;
356
- } : T extends O ? {
357
- [K in StrKey<T>]: NoRaw<T[K]>;
358
- } : T;
359
- type RONoRaw<T> = T extends Arr<infer U> ? readonly RONoRaw<U>[] : T extends readonly unknown[] ? {
360
- readonly [K in keyof T]: RONoRaw<T[K]>;
361
- } : T extends O ? {
362
- readonly [K in StrKey<T>]: RONoRaw<T[K]>;
363
- } : T;
364
- declare const func: <T extends jsonItem, A extends readonly jsonItem[], D, C = unknown>(f: (...args: NoRaw<A>) => RONoRaw<T>, ...args: { [X in keyof A]: Expr<A[X], D, C>; }) => Expr<T, D, C>;
358
+ type AddO<T> = T extends notObj ? T : T extends Array<infer U> ? Arr<AddO<U>> : O<T>;
359
+ declare const func: <T extends jsonItem, A extends readonly jsonItem[], D, C = unknown>(f: (...args: A) => T, ...args: { [X in keyof A]: Expr<AddO<A[X]>, D, C>; }) => Expr<AddO<T>, D, C>;
365
360
  declare const rand: () => string;
366
361
  declare const $rand: Expr<string, unknown, unknown>;
367
362
 
363
+ type AddOs<A extends readonly unknown[]> = {
364
+ [K in keyof A]: AddO<A[K]>;
365
+ };
366
+ type PushSides<V> = {
367
+ 0: V[];
368
+ 1: V[];
369
+ };
370
+ type PushDict<V> = PRRec<string, PushSides<V>>;
368
371
  declare const $sum: <D extends O, C = unknown>(expr: Expr<number | N, D, C>) => DeltaAccumulator<D, number, C>;
369
- 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>;
370
- declare const $countDict: <D extends O, C = unknown>(expr: Expr<string, D, C>) => DeltaAccumulator<D, Rec<string, number>, C>;
371
- declare const $countDictArray: <D extends O, C = unknown>(expr: Expr<Arr<string>, D, C>) => DeltaAccumulator<D, Rec<string, number>, C>;
372
- 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>;
373
- declare const $keys: <D extends O, C = unknown>(expr: Expr<Rec<string, number>, D, C>) => Expr<Arr<string>, D, C>;
374
- 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>;
372
+ declare const $accumulator: <D, T, Ctx, A extends readonly unknown[]>(init: () => T, accumulateArgs: AppMap<ExprHKT<Part<D>, Ctx>, AddOs<A>>, accumulate: (a: T, ...args: A) => T, merge: (...args: [T | N, T]) => T) => DeltaAccumulator<D, AddO<T>, Ctx>;
373
+ declare const $countDict: <D extends O, K extends string = string, C = unknown>(expr: Expr<AddO<K>, D, C>) => DeltaAccumulator<D, AddO<PRRec<K, number>>, C>;
374
+ declare const $countDictArray: <D extends O, K extends string = string, C = unknown>(expr: Expr<AddO<K[]>, D, C>) => DeltaAccumulator<D, AddO<PRRec<K, number>>, C>;
375
+ declare const $pushDict: <D extends O, V, C = unknown>(key: Expr<string, D, C>, value: Expr<AddO<V>, D, C>) => DeltaAccumulator<D, O<PushDict<V>>, C>;
376
+ declare const $keys: <D extends O, K extends string = string, C = unknown>(expr: Expr<AddO<PRRec<K, number>>, D, C>) => Expr<AddO<K[]>, D, C>;
377
+ declare const $entries: <D extends O, V, C = unknown>(expr: Expr<AddO<PushDict<V>>, D, C>) => Expr<AddO<{
378
+ k: string;
379
+ v: V;
380
+ }[]>, D, C>;
375
381
 
376
382
  type DeltaPipe<Q extends O, T extends Q, F extends HKT<O2>, G extends HKT<O3>> = {
377
383
  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>;
@@ -419,17 +425,17 @@ declare const $merge2: <T extends O, Out extends O = T, Ctx = unknown, In extend
419
425
 
420
426
  type GI$1<GG> = Exclude<GG, keyof TS>;
421
427
  type IdAndTsKeys = keyof (TS & ID);
422
- type V<VV, GG extends string> = Omit<VV, IdAndTsKeys | GI$1<GG>>;
428
+ type V$1<VV, GG extends string> = Omit<VV, IdAndTsKeys | GI$1<GG>>;
423
429
  type Prepare<Grp, GG extends string> = TS & ID & Rec<GI$1<GG>, Grp>;
424
430
  type Par<T> = {
425
431
  [P in keyof T]?: T[P] | null;
426
432
  };
427
- type Loose<Grp, VV, GG extends string> = Prepare<Grp, GG> & Par<V<VV, GG>>;
428
- type Strict<Grp, VV, GG extends string, EE> = Prepare<Grp, GG> & V<VV, GG> & Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V<VV, GG>>;
429
- type V_Grp<VV, GG extends string, Grp> = Rec<GI$1<GG>, Grp> & V<VV, GG>;
430
- type Extra<EE, VV, GG extends string> = Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V<VV, GG>>;
433
+ type Loose<Grp, VV, GG extends string> = Prepare<Grp, GG> & Par<V$1<VV, GG>>;
434
+ type Strict<Grp, VV, GG extends string, EE> = Prepare<Grp, GG> & V$1<VV, GG> & Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V$1<VV, GG>>;
435
+ type V_Grp<VV, GG extends string, Grp> = Rec<GI$1<GG>, Grp> & V$1<VV, GG>;
436
+ type Extra<EE, VV, GG extends string> = Omit<EE, IdAndTsKeys | GI$1<GG> | keyof V$1<VV, GG>>;
431
437
  type OrReplace<T, V> = T | Replace<T, V>;
432
- type MergedInput<Out, VV, Grp, GG extends string, EE> = OrReplace<Replace<Replace<Out, V<VV, GG>>, Extra<EE, VV, GG>> & Model, TS & ID & V_Grp<VV, GG, Grp> & Extra<EE, VV, GG>>;
438
+ type MergedInput<Out, VV, Grp, GG extends string, EE> = OrReplace<Replace<Replace<Out, V$1<VV, GG>>, Extra<EE, VV, GG>> & Model, TS & ID & V_Grp<VV, GG, Grp> & Extra<EE, VV, GG>>;
433
439
 
434
440
  type Denied<GID = never> = keyof (TS & ID) | GID;
435
441
  type GI<GG> = Exclude<GG, keyof TS>;
@@ -465,14 +471,18 @@ type Updater<in R, in T, out V, in C = unknown> = {
465
471
  [Type]?(x: typeof Updater, r: R, t: T, c: C): V;
466
472
  readonly raw: <D extends O>(f: Field<D, R | N>) => readonly (readonly [string, rawItem])[];
467
473
  };
468
- interface UpdaterHKT<R, Old, V, C, K extends keyof Old = keyof Old, V2 extends V = V> extends HKT<StrKey<V>> {
469
- readonly out: Updater<R, Get<Old, I<StrKey<V>, this>, K>, V2[I<StrKey<V>, this>], C>;
474
+ interface UpdaterHKT<R, Old, V, C, K extends keyof Old = keyof Old, V2 extends V = V> extends UpdaterQHKT<R, Old, V2, StrKey<V>, C, K> {
475
+ }
476
+ interface UpdaterQHKT<R, Old, V, KV extends StrKey<V>, C, K extends keyof Old = keyof Old> extends HKT<KV> {
477
+ readonly out: Updater<R, Get<Old, I<KV, this>, K>, V[I<KV, this>], C>;
470
478
  }
471
479
  type Get<T, P extends string, K extends keyof T = never> = P extends K ? T[P] : P extends keyof T ? T[P] : undefined;
472
480
  declare const set: <V>() => <R, Old extends notArr, C = unknown, K extends keyof Old = never>(fields: MapO<V, UpdaterHKT<R, Old, V, C, K>>) => Updater<R, Old, O & Omit$1<Old, StrKey<V>> & V, C> & Updater<R, Arr<Old>, Arr<Omit$1<Old, StrKey<V>> & V>, C>;
473
481
  declare const to: <R, V, C = unknown, T = unknown>(expr: Expr<V, R, C>) => Updater<R, T, V, C>;
474
482
 
475
- declare const $set: <V extends O>() => <R extends O, C = unknown>(fields: MapO<V, UpdaterHKT<R, R, V, C>>) => DeltaStages<O, R, Replace<R, V>, C> & LinStages<O, R, Replace<R, V>, C>;
483
+ type V<VV, Q> = Exclude<StrKey<VV>, StrKey<Q>>;
484
+ type $Set<VV extends O, Q extends O> = <R extends Q, C = unknown>(fields: MapO<Omit<VV, StrKey<Q>>, UpdaterQHKT<R, R, VV, V<VV, Q>, C>, V<VV, Q>>) => DeltaStages<Q, R, Q & ReplaceQ<R, VV, Q>, C> & LinStages<Q, R, Q & ReplaceQ<R, VV, Q>, C>;
485
+ declare const $set: <VV extends O, Q extends O = O>() => $Set<VV, Q>;
476
486
  declare const $replaceWith: <T extends O, V extends O>(expr: Expr<V, T>) => DeltaStages<O, T, V> & LinStages<O, T, V>;
477
487
 
478
488
  type s$1 = string;
@@ -733,4 +743,4 @@ declare const prepare: (testName?: string) => Promise<MongoClient$1>;
733
743
  declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
734
744
 
735
745
  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, emptyDelta, enablePreAndPostImages, eq, eqTyped, except, exprMapVal, field, fieldF, fieldM, filter, filterDefined, first, firstSure, floor, from, func, getWhenMatched, getWhenMatchedForMerge, gt, gte, inArray, isArray, ite, joinIdOf, last, log, lt, lte, makeCol, map1, mapFromPlainDateTime, mapToPlainDateTime, mapVal, matchDelta, 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 };
736
- export type { Accumulators, Arr, AsLiteral, Delta, DeltaAccumulator, DeltaAccumulators, DeltaStages, ExactKeys, ExprHKT, Exprs, ExprsExact, ExprsExactHKT, ExprsPart, ID, JoinId, 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 };
746
+ export type { Accumulators, AddO, Arr, AsLiteral, Delta, DeltaAccumulator, DeltaAccumulators, DeltaStages, ExactKeys, ExprHKT, Exprs, ExprsExact, ExprsExactHKT, ExprsPart, ID, JoinId, Loose, Merge, MergeArgs, MergeInto, MergeMapOArgs, Model, MongoTypeNames, N, NullToOBJ, O, OPick, OPickD, Patch, RORec, RawStages, Rec, Replace, SnapshotStreamExecutionResult, StrKey, Strict, TS, WriteonlyCollection, doc, jsonPrim, notArr };
package/index.esm.js CHANGED
@@ -76,7 +76,8 @@ const spread = (a, b) => ({ ...a, ...mapExact(b, id$1) });
76
76
  const spread0 = (a, b) => ({ ...a, ...mapExact0(b, id$1) });
77
77
 
78
78
  const val = (val) => asExpr({
79
- raw: () => asExprRaw((val && typeof val === 'object' && !(val instanceof Date)) || (typeof val === 'string' && val[0] === '$')
79
+ raw: () => asExprRaw((val && typeof val === 'object' && !(val instanceof Date)) ||
80
+ (typeof val === 'string' && val[0] === '$')
80
81
  ? { $literal: val }
81
82
  : val),
82
83
  });
@@ -864,11 +865,17 @@ const $map1 = (ex, map) => $map0({ input: ex, as: 'item', expr: map(ctx()('item'
864
865
  const $map = (ex, map) => $map1(ex, i => map(i.expr()));
865
866
 
866
867
  const subUpdater = (a, f) => ({ raw: (g) => a.raw(g.with(f)) });
868
+ const rawSet = (fields) => (f) => {
869
+ return Object.entries(mapExactToObject0(fields, v => v)).flatMap(([k, v]) => v.raw(f).map(([l, v]) => [`.${k}${l}`, v]));
870
+ };
867
871
  const set = () => (fields) => ({
868
- raw: f => {
869
- return Object.entries(mapExactToObject0(fields, v => v)).flatMap(([k, v]) => v.raw(f).map(([l, v]) => [`.${k}${l}`, v]));
870
- },
872
+ raw: rawSet(fields),
871
873
  });
874
+ const setQ = () => {
875
+ return (fields) => ({
876
+ raw: rawSet(fields),
877
+ });
878
+ };
872
879
  const weaken = (updater) => ({ raw: f => updater.raw(f) });
873
880
  const to = (expr) => ({
874
881
  raw: f => [['', expr.raw(f).get()]],
@@ -1711,9 +1718,7 @@ const $setCore = (updater) => ({
1711
1718
  raw: $set1(updater),
1712
1719
  lin: $set_(updater),
1713
1720
  });
1714
- const $set = () => (fields) => {
1715
- return $setCore(set()(fields));
1716
- };
1721
+ const $set = () => (fields) => $setCore(setQ()(fields));
1717
1722
  const $replaceWith = (expr) => ({
1718
1723
  delta: $replaceWithDelta(expr),
1719
1724
  raw: $replaceWith1(expr),
package/index.js CHANGED
@@ -78,7 +78,8 @@ const spread = (a, b) => ({ ...a, ...mapExact(b, id$1) });
78
78
  const spread0 = (a, b) => ({ ...a, ...mapExact0(b, id$1) });
79
79
 
80
80
  const val = (val) => asExpr({
81
- raw: () => asExprRaw((val && typeof val === 'object' && !(val instanceof Date)) || (typeof val === 'string' && val[0] === '$')
81
+ raw: () => asExprRaw((val && typeof val === 'object' && !(val instanceof Date)) ||
82
+ (typeof val === 'string' && val[0] === '$')
82
83
  ? { $literal: val }
83
84
  : val),
84
85
  });
@@ -866,11 +867,17 @@ const $map1 = (ex, map) => $map0({ input: ex, as: 'item', expr: map(ctx()('item'
866
867
  const $map = (ex, map) => $map1(ex, i => map(i.expr()));
867
868
 
868
869
  const subUpdater = (a, f) => ({ raw: (g) => a.raw(g.with(f)) });
870
+ const rawSet = (fields) => (f) => {
871
+ return Object.entries(mapExactToObject0(fields, v => v)).flatMap(([k, v]) => v.raw(f).map(([l, v]) => [`.${k}${l}`, v]));
872
+ };
869
873
  const set = () => (fields) => ({
870
- raw: f => {
871
- return Object.entries(mapExactToObject0(fields, v => v)).flatMap(([k, v]) => v.raw(f).map(([l, v]) => [`.${k}${l}`, v]));
872
- },
874
+ raw: rawSet(fields),
873
875
  });
876
+ const setQ = () => {
877
+ return (fields) => ({
878
+ raw: rawSet(fields),
879
+ });
880
+ };
874
881
  const weaken = (updater) => ({ raw: f => updater.raw(f) });
875
882
  const to = (expr) => ({
876
883
  raw: f => [['', expr.raw(f).get()]],
@@ -1713,9 +1720,7 @@ const $setCore = (updater) => ({
1713
1720
  raw: $set1(updater),
1714
1721
  lin: $set_(updater),
1715
1722
  });
1716
- const $set = () => (fields) => {
1717
- return $setCore(set()(fields));
1718
- };
1723
+ const $set = () => (fields) => $setCore(setQ()(fields));
1719
1724
  const $replaceWith = (expr) => ({
1720
1725
  delta: $replaceWithDelta(expr),
1721
1726
  raw: $replaceWith1(expr),
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.47",
6
+ "version": "0.1.49",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",