@omegup/msync 0.1.45 → 0.1.47

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 (4) hide show
  1. package/index.d.ts +41 -14
  2. package/index.esm.js +348 -191
  3. package/index.js +349 -190
  4. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -39,10 +39,10 @@ interface RawObj {
39
39
  type raw = readonly rawItem[] | RawObj;
40
40
  type StrKey<T> = string & keyof T;
41
41
  type Replace<R, V> = Omit<R, StrKey<V>> & V & O;
42
- type AsLiteral<T extends keyof any | boolean, V = NoUnion<T>> = T extends keyof any ? {} extends {
42
+ type AsLiteral<T extends keyof any | boolean | N, V = NoUnion<T>> = T extends keyof any ? {} extends {
43
43
  [K in T]: 1;
44
44
  } ? never : V : V;
45
- type NoUnion<T, V = T> = T extends unknown ? ([V] extends [T] ? T : never) : never;
45
+ type NoUnion<T, V = T> = T extends T ? ([V] extends [T] ? T : never) : never;
46
46
 
47
47
  type HasJob = {
48
48
  job: object | undefined;
@@ -161,9 +161,22 @@ type D = O<DeletedAt & ID>;
161
161
  type Model = D & TS;
162
162
  type BA = 'before' | 'after';
163
163
  type PreDelta<T, K extends BA = BA, E = unknown> = Rec<K, T> & E;
164
- type Delta<T, K extends BA = BA, E = ID> = PreDelta<T | null, K, E>;
164
+ type DeletedFlags = O<{
165
+ readonly before?: true;
166
+ readonly after?: true;
167
+ }>;
168
+ type Deleted = {
169
+ readonly deleted?: DeletedFlags;
170
+ };
171
+ type Delta<T, K extends BA = BA, E = ID & Deleted> = PreDelta<T | null, K, E> & ({
172
+ after: T;
173
+ } | {
174
+ before: T;
175
+ });
165
176
  type Before<T> = PreDelta<T, 'before'>;
166
- type UBefore<T> = O & Partial<Delta<T | null, 'before'>>;
177
+ type UBefore<T> = O & {
178
+ readonly before?: T | null;
179
+ };
167
180
  type SnapshotStream<out Q extends O, in out T extends Q> = <Q2 extends O, Result extends Q2>(input: DeltaStages<Q2 | T, T, Result>) => SnapshotStreamExecutionResult<Q | Q2, Result>;
168
181
 
169
182
  declare const ExprRaw: unique symbol;
@@ -226,7 +239,9 @@ type Accumulator<in Doc, out T, in Ctx = unknown> = {
226
239
  <DeltaD extends O, I extends U>(f: Field<DeltaD, Doc | Undef<I>>): AccumulatorRaw<T | I, DeltaD, Ctx>;
227
240
  };
228
241
  };
229
- type Part<Doc> = Rec<'v', Doc> & RORec<'old', boolean>;
242
+ type Part<Doc> = Rec<'v', Doc> & RORec<'old', boolean> & {
243
+ readonly deleted?: true | N;
244
+ };
230
245
  type DeltaAccumulator<in out Doc, in out T, in out Ctx = unknown> = {
231
246
  group: Accumulator<Part<Doc>, T, Ctx>;
232
247
  merge: <D, C = Ctx>(a: Expr<T | N, D, C>, b: Expr<T, D, C>) => Expr<T, D, C>;
@@ -423,18 +438,28 @@ declare const $groupId: <T extends O, V extends O, EE = {}, Out extends Loose<st
423
438
  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">;
424
439
 
425
440
  type Params<As extends string, LQ extends O, RQ extends O, RE extends RQ, S extends notArr> = {
426
- localField: Field<LQ, S | Arr<S>>;
427
- foreignField: Field<RQ, S | Arr<S>>;
428
441
  from: SnapshotStreamExecutionResult<RQ, RE>;
429
442
  as: AsLiteral<As>;
430
- };
431
- declare const $lookup: <As extends string, LQ extends doc, RQ extends O, RE extends RQ & doc, S extends notArr>(p: Params<As, LQ, RQ, RE, S>) => <LE extends LQ>(l: SnapshotStream<LQ, LE>) => SnapshotStream<LQ, LE & RORec<As, RE>>;
432
- declare const $outerLookup: <As extends string, LQ extends doc, RQ extends O, RE extends RQ & doc, S extends notArr>(p: Params<As, LQ, RQ, RE, S>) => <LE extends LQ>(l: SnapshotStream<LQ, LE>) => SnapshotStream<LQ, LE & RORec<As, RE | null>>;
443
+ } & ({
444
+ to: 'one';
445
+ localField: Field<LQ, string>;
446
+ foreignField?: never;
447
+ middle?: never;
448
+ } | {
449
+ to: 'many';
450
+ middle: string;
451
+ localField: Field<LQ, S | Arr<S>>;
452
+ foreignField: Field<RQ, S | Arr<S>>;
453
+ });
454
+ declare const $lookup: <As extends string, LQ extends doc, RQ extends doc, RE extends RQ & doc, S extends notArr>(p: Params<As, LQ, RQ, RE, S>) => <LE extends LQ>(l: SnapshotStream<LQ, LE>) => SnapshotStream<LQ, LE & RORec<As, RE>>;
455
+ declare const $outerLookup: <As extends string, LQ extends doc, RQ extends doc, RE extends RQ & doc, S extends notArr>(p: Params<As, LQ, RQ, RE, S>) => <LE extends LQ>(l: SnapshotStream<LQ, LE>) => SnapshotStream<LQ, LE & RORec<As, RE | null>>;
433
456
 
434
457
  declare const $matchDelta: <T extends doc>(query: Expr<boolean, T>) => RawStages<unknown, Delta<T>, Delta<T>, unknown, number>;
458
+ declare const matchDelta: <D>() => RawStages<unknown, Delta<D | null>, Delta<D>>;
435
459
 
436
460
  declare const $match: <T extends doc>(query: Expr<boolean, T>) => DeltaStages<T, T, T>;
437
461
 
462
+ type Omit$1<T, K extends keyof any> = T extends T ? Pick<T, Exclude<keyof T, K>> : never;
438
463
  declare const Updater: unique symbol;
439
464
  type Updater<in R, in T, out V, in C = unknown> = {
440
465
  [Type]?(x: typeof Updater, r: R, t: T, c: C): V;
@@ -444,14 +469,16 @@ interface UpdaterHKT<R, Old, V, C, K extends keyof Old = keyof Old, V2 extends V
444
469
  readonly out: Updater<R, Get<Old, I<StrKey<V>, this>, K>, V2[I<StrKey<V>, this>], C>;
445
470
  }
446
471
  type Get<T, P extends string, K extends keyof T = never> = P extends K ? T[P] : P extends keyof T ? T[P] : undefined;
447
- 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<Old, StrKey<V>> & V, C> & Updater<R, Arr<Old>, Arr<Omit<Old, StrKey<V>> & V>, C>;
472
+ 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>;
448
473
  declare const to: <R, V, C = unknown, T = unknown>(expr: Expr<V, R, C>) => Updater<R, T, V, C>;
449
474
 
450
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>;
451
476
  declare const $replaceWith: <T extends O, V extends O>(expr: Expr<V, T>) => DeltaStages<O, T, V> & LinStages<O, T, V>;
452
477
 
453
478
  type s$1 = string;
454
- declare const $unwindDelta: <K1 extends s$1, T extends doc, K2 extends s$1, U extends doc, N1 extends null = never, N2 extends null = never>(k1: AsLiteral<K1>, k2: AsLiteral<K2>, k: K1 | K2 | false, middle?: string, includeNull1?: N1, includeNull2?: N2) => RawStages<Delta<Rec<K1, T | N1>>, Delta<Rec<K1, T | N1> & Rec<K2, Arr<U>>>, Delta<Rec<K1, T | N1> & Rec<K2, U | N2> & ID>>;
479
+ type JoinId<K1 extends s$1, K2 extends s$1> = K1 | K2 | readonly [K1, middle: s$1, K2] | readonly [K2, middle: s$1, K1];
480
+ declare const joinIdOf: <K1 extends s$1, K2 extends s$1, D, C = unknown>(k: JoinId<K1, K2>, k1: K1, k1Id: Expr<s$1, D, C>, k2Id: Expr<s$1, D, C>) => Expr<s$1, D, C>;
481
+ declare const $unwindDelta: <K1 extends s$1, T extends doc, K2 extends s$1, U extends doc, N1 extends null = never, N2 extends null = never>(k1: AsLiteral<K1>, k2: AsLiteral<K2>, k: JoinId<K1, K2>, includeNull1?: N1, includeNull2?: N2) => RawStages<unknown, Delta<Rec<K1, T | N1> & Rec<K2, Arr<U>>>, Delta<Rec<K1, T | N1> & Rec<K2, U | N2> & ID>>;
455
482
 
456
483
  type s = string;
457
484
  type TOf<TT, K extends string> = doc & Omit<TT, K>;
@@ -705,5 +732,5 @@ declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Pr
705
732
  declare const prepare: (testName?: string) => Promise<MongoClient$1>;
706
733
  declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
707
734
 
708
- 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, 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 };
709
- export type { Accumulators, Arr, AsLiteral, Delta, DeltaAccumulator, DeltaAccumulators, DeltaStages, 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 };
735
+ 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 };