@omegup/msync 0.0.43 → 0.0.44

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 (88) hide show
  1. package/index.esm.js +4 -4
  2. package/index.js +4 -4
  3. package/lib/accumulators/index.d.ts +10 -0
  4. package/lib/aggregate/$merge.d.ts +10 -0
  5. package/lib/aggregate/$upsert.d.ts +11 -0
  6. package/lib/aggregate/group/$group-merge.d.ts +12 -0
  7. package/lib/aggregate/group/index.d.ts +2 -0
  8. package/lib/aggregate/group/utils/sub-group.d.ts +6 -0
  9. package/lib/aggregate/group/utils/sub-merge.d.ts +15 -0
  10. package/lib/aggregate/index.d.ts +8 -0
  11. package/lib/aggregate/lookup/$lookup-delta.d.ts +10 -0
  12. package/lib/aggregate/lookup/$lookup-raw.d.ts +9 -0
  13. package/lib/aggregate/lookup/index.d.ts +16 -0
  14. package/lib/aggregate/match/$match-delta.d.ts +3 -0
  15. package/lib/aggregate/match/$match.d.ts +3 -0
  16. package/lib/aggregate/match/index.d.ts +2 -0
  17. package/lib/aggregate/mongo-stages.d.ts +13 -0
  18. package/lib/aggregate/out.d.ts +34 -0
  19. package/lib/aggregate/prefix.d.ts +33 -0
  20. package/lib/aggregate/raws.d.ts +17 -0
  21. package/lib/aggregate/set/$replace-with-each.d.ts +12 -0
  22. package/lib/aggregate/set/$set-delta.d.ts +5 -0
  23. package/lib/aggregate/set/$set.d.ts +6 -0
  24. package/lib/aggregate/set/index.d.ts +1 -0
  25. package/lib/aggregate/unwind/$unwind-delta.d.ts +5 -0
  26. package/lib/aggregate/unwind/index.d.ts +5 -0
  27. package/lib/boot/boot-simpl.d.ts +14 -0
  28. package/lib/boot/boot.d.ts +36 -0
  29. package/lib/boot/index.d.ts +2 -0
  30. package/lib/expression/arith.d.ts +26 -0
  31. package/lib/expression/array.d.ts +26 -0
  32. package/lib/expression/concat.d.ts +30 -0
  33. package/lib/expression/date.d.ts +17 -0
  34. package/lib/expression/expr-base.d.ts +5 -0
  35. package/lib/expression/index.d.ts +7 -0
  36. package/lib/expression/logic.d.ts +22 -0
  37. package/lib/expression/range.d.ts +6 -0
  38. package/lib/expression/val.d.ts +25 -0
  39. package/lib/field/field.d.ts +25 -0
  40. package/lib/field/index.d.ts +1 -0
  41. package/lib/machine.d.ts +9 -0
  42. package/lib/predicate/$eq.d.ts +13 -0
  43. package/lib/predicate/$expr.d.ts +3 -0
  44. package/lib/predicate/$in.d.ts +2 -0
  45. package/lib/predicate/index.d.ts +3 -0
  46. package/lib/predicate/utils.d.ts +5 -0
  47. package/lib/query/index.d.ts +1 -0
  48. package/lib/query/logic.d.ts +11 -0
  49. package/lib/stream/aggregate.d.ts +7 -0
  50. package/lib/types/accumulator.d.ts +30 -0
  51. package/lib/types/aggregate.d.ts +9 -0
  52. package/lib/types/expr.d.ts +27 -0
  53. package/lib/types/extern.d.ts +3 -0
  54. package/lib/types/index.d.ts +8 -0
  55. package/lib/types/lookup.d.ts +19 -0
  56. package/lib/types/machine.d.ts +17 -0
  57. package/lib/types/predicate.d.ts +14 -0
  58. package/lib/types/query.d.ts +12 -0
  59. package/lib/types/stream.d.ts +67 -0
  60. package/lib/update/index.d.ts +1 -0
  61. package/lib/update/updater.d.ts +19 -0
  62. package/lib/utils/before.d.ts +3 -0
  63. package/lib/utils/coll.d.ts +5 -0
  64. package/lib/utils/db-indexes.d.ts +4 -0
  65. package/lib/utils/guard.d.ts +18 -0
  66. package/lib/utils/index.d.ts +3 -0
  67. package/lib/utils/json.d.ts +9 -0
  68. package/lib/utils/log.d.ts +1 -0
  69. package/lib/utils/map-object.d.ts +41 -0
  70. package/lib/utils/merge/combiners.d.ts +6 -0
  71. package/lib/utils/merge/index.d.ts +2 -0
  72. package/lib/utils/merge/merge.d.ts +7 -0
  73. package/lib/utils/merge/next-winner.d.ts +3 -0
  74. package/lib/utils/merge/types.d.ts +19 -0
  75. package/lib/utils/merge/utils.d.ts +4 -0
  76. package/lib/utils/tear-down.d.ts +2 -0
  77. package/lib/watch.d.ts +15 -0
  78. package/package.json +1 -1
  79. package/test/mongodb.d.ts +9 -0
  80. package/test/uri.d.ts +1 -0
  81. package/types/class.d.ts +1 -0
  82. package/types/extern.d.ts +3 -0
  83. package/types/global.d.ts +50 -0
  84. package/types/hkt.d.ts +56 -0
  85. package/types/index.d.ts +6 -0
  86. package/types/json.d.ts +54 -0
  87. package/types/mongo.d.ts +24 -0
  88. package/types/view.d.ts +35 -0
@@ -0,0 +1,25 @@
1
+ import type { Timestamp } from 'mongodb';
2
+ import type { Arr, N, O, RORec, StrKey, jsonItem, rawItem } from '../../types';
3
+ import type { Expr } from '../types';
4
+ import type { ExprsExact } from './concat';
5
+ export declare const val: <T extends rawItem>(val: T) => Expr<T, unknown>;
6
+ export declare const current: Expr<Timestamp, unknown>;
7
+ export declare const $let: <T, D, C, V extends RORec<string, jsonItem>>(vars: ExprsExact<V, D, C>, inExpr: Expr<T, D, C & V>) => Expr<T, D, C>;
8
+ export declare const nil: Expr<null, unknown>;
9
+ export declare const $getField: {
10
+ <T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T, D, C>, field: K): Expr<T[K], D, C>;
11
+ <T, K extends StrKey<T>, D, C = unknown>(expr: Expr<T | N, D, C>, field: K): Expr<T[K] | null, D, C>;
12
+ };
13
+ export type NoRaw<T> = T extends Arr<infer U> ? NoRaw<U>[] : T extends readonly unknown[] ? {
14
+ [K in keyof T]: NoRaw<T[K]>;
15
+ } : T extends O ? {
16
+ [K in StrKey<T>]: NoRaw<T[K]>;
17
+ } : T;
18
+ export type RONoRaw<T> = T extends Arr<infer U> ? readonly RONoRaw<U>[] : T extends readonly unknown[] ? {
19
+ readonly [K in keyof T]: RONoRaw<T[K]>;
20
+ } : T extends O ? {
21
+ readonly [K in StrKey<T>]: RONoRaw<T[K]>;
22
+ } : T;
23
+ export 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>;
24
+ export declare const rand: () => string;
25
+ export declare const $rand: Expr<string, unknown, unknown>;
@@ -0,0 +1,25 @@
1
+ import type { Arr, AsLiteral, N, O, RORec, Undef } from '../../types';
2
+ import type { Expr, Query } from '../types';
3
+ import type { Predicate } from '../types/predicate';
4
+ export declare class Field<in R, out V, in C = unknown> {
5
+ private field;
6
+ private raw;
7
+ private concat;
8
+ has<R extends O>(this: Field<R, V>, p: Predicate<V>): Query<R, C>;
9
+ has<R extends O, V>(this: Field<R, Arr<V>>, p: Predicate<V>): Query<R, C>;
10
+ private constructor();
11
+ static root: <T extends O>() => Field<T, T, unknown>;
12
+ static ctx: <T>() => <K extends string>(k: K) => Field<unknown, T, RORec<K, T>>;
13
+ of<V, K extends keyof V, _ extends 0 = 0>(this: Field<R, Arr<V>, C>, k: AsLiteral<K>): Field<R, Arr<V[K]>, C>;
14
+ of<V, K extends keyof V, _ extends 1 = 1>(this: Field<R, O<V>, C>, k: K): Field<R, V[K], C>;
15
+ of<V, K extends keyof V, I extends N = never, _ extends 2 = 2>(this: Field<R, Arr<V> | Undef<I>, C>, k: K): Field<R, Arr<V[K]> | I, C>;
16
+ of<V, K extends keyof V, I extends N = never, _ extends 3 = 3>(this: Field<R, O<V> | Undef<I>, C>, k: K): Field<R, V[K] | I, C>;
17
+ with<V, W, C2 = unknown, _ extends 0 = 0>(this: Field<R, O<V>, C>, k: Field<O<V>, W, C2>): Field<R, W, C & C2>;
18
+ with<V, W, C2 = unknown, _ extends 1 = 1>(this: Field<R, Arr<V>, C>, k: Field<O<V>, Arr<W> | O<W>, C2>): Field<R, Arr<W>, C & C2>;
19
+ with<V, W, I extends N = never, C2 = unknown, _ extends 2 = 2>(this: Field<R, O<V> | Undef<I>, C>, k: Field<O<V>, W, C2>): Field<R, W | I, C & C2>;
20
+ with<V, W, I extends N = never, C2 = unknown, _ extends 3 = 3>(this: Field<R, Arr<V> | Undef<I>, C>, k: Field<O<V>, Arr<W> | O<W>, C2>): Field<R, Arr<W> | I, C & C2>;
21
+ str(this: Field<R, V>): string;
22
+ private exprRaw;
23
+ expr<R, V, C = unknown>(this: Field<R, V, C>): Expr<V, R, C>;
24
+ }
25
+ export declare const root: <T extends O>() => Field<T, T, unknown>, ctx: <T>() => <K extends string>(k: K) => Field<unknown, T, RORec<K, T>>;
@@ -0,0 +1 @@
1
+ export * from './field';
@@ -0,0 +1,9 @@
1
+ import type { Iterator, HasJob } from './types';
2
+ export declare class Machine<Result = unknown> {
3
+ private sources;
4
+ constructor(root?: Iterator<Result, HasJob>);
5
+ add(x: Iterator<Result, HasJob>): void;
6
+ runner(): Iterator<Result, HasJob>;
7
+ start(cb?: (info: HasJob) => void | boolean): Promise<never>;
8
+ }
9
+ export declare const wrap: <Result>(root: Machine<Result>) => Machine<Result>;
@@ -0,0 +1,13 @@
1
+ import { Timestamp } from 'mongodb';
2
+ export declare const $eq: <T extends unknown>(operand: import("../../types").rawItem & T) => import("../types").Predicate<T>;
3
+ export declare const $ne: <T extends unknown>(operand: import("../../types").rawItem & T) => import("../types").Predicate<T>;
4
+ type Numeric = number | Timestamp | Date;
5
+ export declare const comp: <D2 extends Numeric = number>(op: "$lte" | "$gte" | "$lt" | "$gt") => <T extends D2>(operand: import("../../types").rawItem & D2) => import("../types").Predicate<D2>;
6
+ export declare const $gt: <T extends number>(operand: import("../../types").rawItem & number) => import("../types").Predicate<number>;
7
+ export declare const $gtTs: <T extends Timestamp>(operand: import("../../types").rawItem & Timestamp) => import("../types").Predicate<Timestamp>;
8
+ export declare const $gteTs: <T extends Timestamp>(operand: import("../../types").rawItem & Timestamp) => import("../types").Predicate<Timestamp>;
9
+ export declare const $lt: <T extends number>(operand: import("../../types").rawItem & number) => import("../types").Predicate<number>;
10
+ export declare const dateLt: <T extends Date>(operand: import("../../types").rawItem & Date) => import("../types").Predicate<Date>;
11
+ export declare const $gte: <T extends number>(operand: import("../../types").rawItem & number) => import("../types").Predicate<number>;
12
+ export declare const $lte: <T extends number>(operand: import("../../types").rawItem & number) => import("../types").Predicate<number>;
13
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { O } from '../../types';
2
+ import type { Expr, Query } from '../types';
3
+ export declare const $expr: <D extends O, C>(expr: Expr<boolean, D, C>) => Query<D, C>;
@@ -0,0 +1,2 @@
1
+ export declare const $in: <T extends unknown>(operand: import("../../types").rawItem & readonly T[]) => import("../types").Predicate<T>;
2
+ export declare const $nin: <T extends unknown>(operand: import("../../types").rawItem & readonly T[]) => import("../types").Predicate<T>;
@@ -0,0 +1,3 @@
1
+ export * from './$eq';
2
+ export * from './$expr';
3
+ export * from './$in';
@@ -0,0 +1,5 @@
1
+ import type { App, HKT, rawItem } from '../../types';
2
+ import type { Predicate } from '../types';
3
+ type Operators = '$eq' | '$ne' | '$gt' | '$gte' | '$lt' | '$lte' | '$in' | '$nin';
4
+ export declare const operator: <K extends Operators, F extends HKT<Dom, HKT<Dom, Dom>>, Dom extends unknown, Default extends Dom = Dom, G extends HKT<Dom, HKT<Dom, Dom>> = F>() => <D2 extends Dom = Default>(op: K) => <T extends D2>(operand: rawItem & App<App<F, D2>, T>) => Predicate<App<App<G, D2>, T>>;
5
+ export {};
@@ -0,0 +1 @@
1
+ export { $and, $nor, $or } from './logic';
@@ -0,0 +1,11 @@
1
+ import type { N, O } from '../../types';
2
+ import type { Query } from '../types';
3
+ type Many<T> = readonly (T | N)[];
4
+ type Combiner = {
5
+ <T extends O, C = unknown>(first: Query<T, C>, ...args: Many<Query<T, C>>): Query<T, C>;
6
+ <T extends O, C = unknown>(...args: Many<Query<T, C>>): Query<T, C> | undefined;
7
+ };
8
+ export declare const $and: Combiner;
9
+ export declare const $nor: Combiner;
10
+ export declare const $or: Combiner;
11
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { AggregateCommand } from '../types/aggregate';
2
+ import type { ReadonlyCollection } from '../../types';
3
+ import type { RawStages } from '../types';
4
+ export declare const aggregate: <Result>(input: <E>(consume: <S, B>(value: {
5
+ coll: ReadonlyCollection<S>;
6
+ input: RawStages<unknown, B, Result>;
7
+ }) => E) => E, snapshot?: boolean, start?: number) => Promise<AggregateCommand<Result>>;
@@ -0,0 +1,30 @@
1
+ import type { Expr } from './expr';
2
+ import type { HKT, I, N, O, RORec, RawObj, Rec, Type, U, Undef, jsonItem } from '../../types';
3
+ import type { Field } from '../field';
4
+ import type { Exact } from '../utils/map-object';
5
+ declare const AccumulatorRaw: unique symbol;
6
+ declare const Accumulator: unique symbol;
7
+ export interface AccumulatorRaw<in Doc, out T, in C = unknown> extends RawObj {
8
+ [Type](_: typeof AccumulatorRaw, source: Doc, ctx: C): readonly [typeof AccumulatorRaw, T];
9
+ }
10
+ export interface AccumulatorHKT<T, C = unknown> extends HKT<unknown> {
11
+ readonly out: Accumulator<T, I<unknown, this>, C>;
12
+ }
13
+ export type Accumulators<T, V extends RORec<string, jsonItem>, C = unknown> = Exact<V, AccumulatorHKT<T, C>>;
14
+ export interface DeltaAccumulatorHKT<T, C = unknown> extends HKT<unknown> {
15
+ readonly out: DeltaAccumulator<T, I<unknown, this>, C>;
16
+ }
17
+ export type DeltaAccumulators<T, V extends RORec<string, jsonItem>, C = unknown> = Exact<V, DeltaAccumulatorHKT<T, C>>;
18
+ export type AccumulatorsRoot<Acc extends Accumulators<never, RORec<string, jsonItem>, never>> = Acc extends Accumulators<infer T extends O, RORec<string, jsonItem>, never> ? T : never;
19
+ export type Accumulator<in Doc, out T, in Ctx = unknown> = {
20
+ [Type]?(_: typeof Accumulator): typeof Accumulator;
21
+ raw: {
22
+ <DeltaD extends O, I extends U>(f: Field<DeltaD, Doc | Undef<I>>): AccumulatorRaw<T | I, DeltaD, Ctx>;
23
+ };
24
+ };
25
+ export type Part<Doc> = Rec<'v', Doc> & RORec<'old', boolean>;
26
+ export type DeltaAccumulator<in out Doc, in out T, in out Ctx = unknown> = {
27
+ group: Accumulator<Part<Doc>, T, Ctx>;
28
+ merge: <D, C = Ctx>(a: Expr<T | N, D, C>, b: Expr<T, D, C>) => Expr<T, D, C>;
29
+ };
30
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { Long, Timestamp } from 'mongodb';
2
+ export type AggregateCommand<T> = {
3
+ cursor: {
4
+ id: Long | number;
5
+ firstBatch: T[];
6
+ atClusterTime: Timestamp;
7
+ ns: string;
8
+ };
9
+ };
@@ -0,0 +1,27 @@
1
+ import type { O, Type, U, Undef, rawItem } from '../../types';
2
+ import type { Field } from '../field';
3
+ declare const Expr: unique symbol;
4
+ declare const ExprRaw: unique symbol;
5
+ export type ExprRaw<out T, in Doc, in Ctx = unknown> = {
6
+ [Type]?(x: typeof ExprRaw): void;
7
+ [ExprRaw]?(doc: Doc, ctx: Ctx): T;
8
+ get: () => rawItem;
9
+ };
10
+ export type Expr<out T, in Doc, in Ctx = unknown> = {
11
+ [Type]?(x: typeof Expr): void;
12
+ [Expr]?(doc: Doc, ctx: Ctx): T;
13
+ raw: {
14
+ <DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, Doc | Undef<I>, C>): ExprRaw<T | I, DeltaD, Ctx & C>;
15
+ };
16
+ };
17
+ export type BoolExpr<in D1, in D2, in Ctx = unknown> = {
18
+ [Type]?(x: typeof Expr): void;
19
+ [Expr](doc: D1, ctx: Ctx): true;
20
+ [Expr](doc: D2, ctx: Ctx): false;
21
+ raw: {
22
+ <DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, D1 | D2 | Undef<I>, C>): ExprRaw<boolean, DeltaD, Ctx & C>;
23
+ <DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, D1 | Undef<I>, C>): ExprRaw<true, DeltaD, Ctx & C>;
24
+ <DeltaD extends O, I extends U, C = unknown>(f: Field<DeltaD, D2 | Undef<I>, C>): ExprRaw<false, DeltaD, Ctx & C>;
25
+ };
26
+ };
27
+ export {};
@@ -0,0 +1,3 @@
1
+ export type { Accumulators, DeltaAccumulators, DeltaAccumulator } from './accumulator';
2
+ export type { Expr } from './expr';
3
+ export type { RawStages, SnapshotStreamExecutionResult, TS, Model, Delta } from './stream';
@@ -0,0 +1,8 @@
1
+ export * from './machine';
2
+ export * from './query';
3
+ export * from './stream';
4
+ export * from './expr';
5
+ export * from './predicate';
6
+ export * from './accumulator';
7
+ export * from './lookup';
8
+ export * from './aggregate';
@@ -0,0 +1,19 @@
1
+ import type { AsLiteral, O, ReadonlyCollection } from '../../types';
2
+ import type { ExprsExact } from '../expression/concat';
3
+ import type { Field } from '../field';
4
+ import type { RawStages } from '../types';
5
+ export type LookupArgs<T extends O, U extends O, R, K extends string, Ctx, C, s = string> = {
6
+ vars: ExprsExact<Ctx, T, C>;
7
+ k: AsLiteral<K>;
8
+ } & ({
9
+ coll: ReadonlyCollection<R>;
10
+ pipeline: RawStages<unknown, R, U, Ctx & C>;
11
+ fields?: {
12
+ foreign: Field<R, s>;
13
+ local: Field<T, s>;
14
+ };
15
+ } | {
16
+ coll?: never;
17
+ pipeline: RawStages<unknown, null, U, Ctx & C>;
18
+ fields?: never;
19
+ });
@@ -0,0 +1,17 @@
1
+ export type HasJob = {
2
+ job: object | undefined;
3
+ };
4
+ export type Runner<T, Info extends HasJob> = Iterator<T, Info>;
5
+ export type NextFrame<T, Info> = PromiseLike<Frame<T, Info>>;
6
+ export type Frame<T, Info> = {
7
+ data: T;
8
+ info: Info;
9
+ cont: Iterator<T, Info>;
10
+ };
11
+ export type IteratorResult<out T, out Info> = {
12
+ next: NextFrame<T, Info>;
13
+ stop: Iterator<T, Info>;
14
+ clear: () => Promise<unknown>;
15
+ };
16
+ export type Iterator<out T, out Info> = () => IteratorResult<T, Info>;
17
+ export type AsynIter<T> = readonly [T, () => PromiseLike<AsynIter<T>>];
@@ -0,0 +1,14 @@
1
+ import type { Expr } from '../types';
2
+ import type { Type, RawObj, O } from '../../types';
3
+ import type { Field } from '../field';
4
+ declare const Predicate: unique symbol;
5
+ declare const PredicateRaw: unique symbol;
6
+ export type PredicateRaw = RawObj & {
7
+ [Type]?(x: typeof PredicateRaw): void;
8
+ };
9
+ export interface Predicate<in V> {
10
+ [Type]?(x: typeof Predicate, _: V): void;
11
+ raw: PredicateRaw;
12
+ expr: <D extends O, C>(field: Field<D, V, C>) => Expr<boolean, D, C>;
13
+ }
14
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { O, RawObj, Type } from '../../types';
2
+ import type { Field } from '../field';
3
+ declare const Query: unique symbol;
4
+ declare const QueryRaw: unique symbol;
5
+ export type QueryRaw<T, C = unknown> = RawObj & {
6
+ [Type]?(x: typeof QueryRaw, y: T, c: C): void;
7
+ };
8
+ export type Query<in T extends O, in C = unknown> = {
9
+ [Type]?(x: typeof Query, y: T, c: C): void;
10
+ raw: <DeltaT extends O>(f: Field<DeltaT, T>) => QueryRaw<DeltaT, C>;
11
+ };
12
+ export {};
@@ -0,0 +1,67 @@
1
+ import type { BSON, Filter, Timestamp, UpdateFilter } from 'mongodb';
2
+ import type { App, HKT, ID, O, RawObj, ReadonlyCollection, Rec, Type, WriteonlyCollection } from '../../types';
3
+ import type { Field } from '../field';
4
+ import type { HasJob, Runner } from './machine';
5
+ declare const RawStage: unique symbol;
6
+ type RawArr = readonly RawObj[];
7
+ export interface RawStages<out Q, in S extends Q, out R extends Q, in C = unknown, out M = number> extends RawArr {
8
+ [Type]?(_: typeof RawStage, source: S, ctx: C, q: Q): readonly [typeof RawStage, R, M, Q];
9
+ }
10
+ export type FRawStages<out Q, in S extends Q & O, out R extends Q & O, in C = unknown, out M extends number = number> = <F extends HKT<O, O>>(f: <T extends O>() => Field<App<F, T>, T>) => RawStages<App<F, Q & O>, App<F, S>, App<F, R>, C, M>;
11
+ export type DeltaStages<out Q, in S extends Q & O, out R extends Q & O, in C = unknown> = {
12
+ delta: RawStages<unknown, Delta<S>, Delta<R>, C>;
13
+ raw: FRawStages<Q, S, R, C>;
14
+ };
15
+ export type LinStages<out Q, in S extends Q, out R extends Q, in C = unknown> = {
16
+ lin: RawStages<Q, S, R, C, 1>;
17
+ };
18
+ export type TStages<in out S, out Q, in out B extends Q, out R extends Q, M extends number = number> = {
19
+ coll: ReadonlyCollection<S>;
20
+ input: RawStages<unknown, S, B, unknown, M>;
21
+ exec: RawStages<Q, B, R, unknown, M>;
22
+ };
23
+ export 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;
24
+ export type Actions<W> = {
25
+ updateMany: [Filter<W>, UpdateFilter<W> | BSON.Document[]];
26
+ };
27
+ export type TeardownRecord<W, M extends keyof Actions<W>> = {
28
+ collection: WriteonlyCollection<W>;
29
+ method: M;
30
+ params: Actions<W>[M];
31
+ };
32
+ export type StreamRunnerParam<in V, out Result> = {
33
+ raw: (first: boolean) => RawStages<unknown, V, Result>;
34
+ teardown: <R>(consume: <W, M extends keyof Actions<W>>(x: TeardownRecord<W, M>) => R) => R;
35
+ };
36
+ export type StreamRunner<out V> = <Result>(input: StreamRunnerParam<V, Result>) => Runner<readonly Result[], HasJob>;
37
+ export type SimpleStreamExecutionResult<out Q, out V extends Q> = {
38
+ readonly out: StreamRunner<V>;
39
+ };
40
+ export type SnapshotStreamExecutionResult<out Q, out V extends Q> = {
41
+ readonly out: StreamRunner<Delta<V>>;
42
+ readonly stages: Stages<Before<Q>, Before<V>, UBefore<Q>>;
43
+ };
44
+ export type Stream<out Q extends O, in out T extends Q, in out F extends HKT<[O, O]>, in out G extends HKT<[O, O, O]>> = <Q2 extends O, Result extends Q2>(input: App<G, [Q2 | T, T, Result]>) => App<F, [Q | Q2, Result]>;
45
+ export type TS = {
46
+ readonly touchedAt: Timestamp;
47
+ };
48
+ export type Del = O<{
49
+ readonly deletedAt: Timestamp;
50
+ } & ID & TS>;
51
+ export type D = O<{
52
+ readonly deletedAt?: Timestamp | null | undefined;
53
+ } & ID>;
54
+ export type Model = D & TS;
55
+ export type OutInput<T, A = T | null> = ID & Rec<'after', A>;
56
+ export type SimpleStream<in out Q extends O, out T extends Q> = <Q2 extends O, Result extends Q2>(input: LinStages<Q2 | T, T, Result>) => SimpleStreamExecutionResult<Q | Q2, Result>;
57
+ export type BA = 'before' | 'after';
58
+ export type PreDelta<T, K extends BA = BA, E = unknown> = Rec<K, T> & E;
59
+ export type Delta<T, K extends BA = BA, E = ID> = PreDelta<T | null, K, E>;
60
+ export type Before<T> = PreDelta<T, 'before'>;
61
+ export type After<T> = Delta<T, 'after'>;
62
+ export type UBefore<T> = O & Partial<Delta<T | null, 'before'>>;
63
+ export type UDelta<T, E = {
64
+ readonly updated: boolean;
65
+ }> = Delta<T, 'after', ID> & UBefore<T> & E;
66
+ export 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>;
67
+ export {};
@@ -0,0 +1 @@
1
+ export { set, to } from './updater';
@@ -0,0 +1,19 @@
1
+ import type { Arr, HKT, I, N, O, StrKey, Type, notArr, rawItem } from '../../types';
2
+ import { Field } from '../field';
3
+ import type { Expr } from '../types';
4
+ import { type MapO } from '../utils/map-object';
5
+ declare const Updater: unique symbol;
6
+ export type Updater<in R, in T, out V, in C = unknown> = {
7
+ [Type]?(x: typeof Updater, r: R, t: T, c: C): V;
8
+ readonly raw: <D extends O>(f: Field<D, R | N>) => readonly (readonly [string, rawItem])[];
9
+ };
10
+ export declare const subUpdater: <P extends O, D, T, V, Ctx>(a: Updater<D, T, V, Ctx>, f: Field<P, D>) => Updater<P, T, V, Ctx>;
11
+ export interface UpdaterHKT<R, Old, V, C, K extends keyof Old = keyof Old, V2 extends V = V> extends HKT<StrKey<V>> {
12
+ readonly out: Updater<R, Get<Old, I<StrKey<V>, this>, K>, V2[I<StrKey<V>, this>], C>;
13
+ }
14
+ export type Get<T, P extends string, K extends keyof T = never> = P extends K ? T[P] : P extends keyof T ? T[P] : undefined;
15
+ export 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>;
16
+ export declare const weaken: <R, T, V, C = unknown>(updater: Updater<R, T, V, C>) => Updater<R | null, T | N, V | null, C>;
17
+ export declare const to: <R, V, C = unknown, T = unknown>(expr: Expr<V, R, C>) => Updater<R, T, V, C>;
18
+ export declare const items: <R, T, V, C = unknown>(x: Updater<R, T, V, C>) => Updater<R, Arr<T>, Arr<V>, C>;
19
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { O } from '../../types';
2
+ import type { Before, FRawStages, RawStages } from '../types';
3
+ export declare const asBefore: <Q extends O, S extends Q, R extends Q, C = unknown>(f: FRawStages<Q, S, R, C>) => RawStages<Before<Q>, Before<S>, Before<R>, C>;
@@ -0,0 +1,5 @@
1
+ import type { ReadonlyCollection, WriteonlyCollection } from '../../types';
2
+ export declare const dbcoll: (x: ReadonlyCollection<unknown> | WriteonlyCollection<never>) => {
3
+ db: string;
4
+ coll: string;
5
+ };
@@ -0,0 +1,4 @@
1
+ import type { Collection, CreateIndexesOptions, IndexSpecification } from 'mongodb';
2
+ export declare const createIndex: (collection: {
3
+ readonly createIndex: Collection["createIndex"];
4
+ }, indexSpec: IndexSpecification, options?: CreateIndexesOptions) => Promise<void>;
@@ -0,0 +1,18 @@
1
+ import type { App, HKT, jsonItem, Literal, Par, Rec, RORec } from '../../types';
2
+ export type Equal<Dom, T extends Dom, V extends Dom> = {
3
+ forward: <F extends HKT<Dom>>(x: App<F, T>) => App<F, V>;
4
+ forward1: (x: T) => V;
5
+ backward: <F extends HKT<Dom>>(x: App<F, V>) => App<F, T>;
6
+ backward1: (x: V) => T;
7
+ };
8
+ export declare const sym: <Dom, T extends Dom, V extends Dom>(eq: Equal<Dom, T, V>) => Equal<Dom, V, T>;
9
+ export declare const omitRORec: <K extends string, E extends string, R extends string, T extends unknown>() => Equal<unknown, RORec<Exclude<K, E | R>, T>, Omit<RORec<Exclude<K, E | R>, T>, R>>;
10
+ type s = keyof any;
11
+ export declare const omitPick: <K extends s, E extends s, R extends s, T extends RORec<Exclude<K, E | R>, unknown>>() => Equal<unknown, Pick<T, Exclude<K, E | R>>, Omit<Pick<T, Exclude<K, E | R>>, R>>;
12
+ export declare const omitExclude: <K extends s, E extends s, R extends s, T extends RORec<Exclude<K, E | R>, unknown>>() => Equal<unknown, Omit<T, E & Exclude<K, keyof T>>, Omit<Pick<T, Exclude<K, E | R>>, R>>;
13
+ export declare const renamedFields: <K extends s, F extends HKT<K, s>, G extends HKT<App<F, K>>>() => Equal<string | number | symbol, keyof { [P in K as App<F, P>]: App<G, P>; }, App<F, K>>;
14
+ export declare const doubleExclude: <K extends string, E extends s, R extends s>() => Equal<K, K, Exclude<K, E & Exclude<Literal<R>, K>>>;
15
+ export declare const excludeIdem: <K extends s, E extends s, S extends E = E>() => Equal<Exclude<K, E>, Exclude<K, E>, Exclude<Exclude<K, E>, S>>;
16
+ export declare const eqPar: <K extends string, T extends Rec<K, jsonItem>, K2 extends K>() => Equal<unknown, Par<K2, T>, Par<K, T>>;
17
+ export declare const notExtendExcluded: <Key extends keyof any, Others extends keyof any, Source extends keyof any, Denied extends keyof any, F extends HKT<Others | Exclude<Source, Denied | Key>, Dom>, Else extends Dom, Dom = unknown>() => Equal<Dom, Key extends Others | Exclude<Source, Key | Denied> ? App<F, Key> : Else, Key extends Others ? App<F, Key> : Else>;
18
+ export {};
@@ -0,0 +1,3 @@
1
+ export { log } from './log';
2
+ export { createIndex } from './db-indexes';
3
+ export { map1, noop } from './json';
@@ -0,0 +1,9 @@
1
+ import type { AsLiteral, Rec } from '../../types';
2
+ export declare const id: <T>(x: T) => T;
3
+ export declare const defined: <T>(x: T | undefined | null) => x is T;
4
+ export declare const noop: () => void;
5
+ export declare const anoop: () => Promise<void>;
6
+ export declare const asRec: <K extends string, T>(x: Record<K, T>) => Rec<K, T>;
7
+ export declare const map1: <K extends string, Im>(k: AsLiteral<K>, to: Im) => { readonly [P in K]: [P, Im]; } & {
8
+ readonly [_: string]: [K, Im];
9
+ };
@@ -0,0 +1 @@
1
+ export declare const log: (...args: unknown[]) => void;
@@ -0,0 +1,41 @@
1
+ import type { App, HKT, I, IdHKT, RORec, StrKey } from '../../types';
2
+ export declare const map: <T, K extends string & keyof T, V extends RORec<K, unknown>>(x: Pick<T, K>, f: <P extends K>(v: T[P], k: P) => V[P]) => V;
3
+ export type ExactPart<T, F extends HKT<T[StrKey<T>]>> = MapOPart<T, MappedHKT<T, F>>;
4
+ export type ExactPart1<T, F extends HKT<StrKey<T>>> = {
5
+ readonly [K in StrKey<T>]: App<F, K>;
6
+ };
7
+ type s = string;
8
+ export type MapKDom<RK extends MapKDom<RK, F>, F extends HKT<StrKey<RK>>> = MapO<RK, F> & {
9
+ readonly [P in s]?: readonly [keyof RK, unknown];
10
+ };
11
+ export type ExactKeys<K extends string> = Exact<RORec<K, 1>, IdHKT>;
12
+ export type MapO<T, F extends HKT<StrKey<T>>> = MapOPart<T, F> & {
13
+ readonly [P: string]: readonly [StrKey<T>, unknown];
14
+ };
15
+ export type MapK<K extends s, F extends HKT<K>> = MapO<RORec<K>, F>;
16
+ export type MapOPart<T, F extends HKT<StrKey<T>>, K extends keyof T = StrKey<T>> = {
17
+ readonly [P in K]: readonly [P, App<F, P & string>];
18
+ };
19
+ export type MapKPart1<T, F extends HKT<StrKey<T>>> = {
20
+ readonly [P in StrKey<T>]: App<F, P>;
21
+ };
22
+ export type Exact<T, F extends HKT<T[StrKey<T>]>> = MapO<T, MappedHKT<T, F>>;
23
+ export interface MappedHKT<T, F extends HKT<T[StrKey<T>]>> extends HKT<StrKey<T>> {
24
+ readonly out: App<F, T[I<StrKey<T>, this>]>;
25
+ }
26
+ export declare const mapExactToObject0: <T, F extends HKT<StrKey<T>>, G extends HKT<StrKey<T>>>(x: MapO<T, F>, f: <P extends StrKey<T>>(v: App<F, P>, k: P) => App<G, P>) => MapKPart1<T, G>;
27
+ export declare const mapExactToObject1: <K extends string, F extends HKT<K>, G extends HKT<K>>(x: MapK<K, F>, f: <P extends K>(v: App<F, P>, k: P) => App<G, P>) => MapKPart1<RORec<K>, G>;
28
+ export interface WithKey1<K extends string, G extends HKT<K>> extends HKT<K> {
29
+ readonly out: readonly [I<K, this>, App<G, I<K, this>>];
30
+ }
31
+ export declare const mapExact0: <T, F extends HKT<StrKey<T>>, G extends HKT<StrKey<T>>>(x: MapO<T, F>, f: <P extends StrKey<T>>(v: App<F, P>, k: P) => App<G, P>) => MapO<T, G>;
32
+ export declare const mapExact1: <K extends s, F extends HKT<K>, G extends HKT<K>>(x: MapK<K, F>, f: <P extends K>(v: App<F, P>, k: P) => App<G, P>) => MapK<K, G>;
33
+ export declare const mapExactToObject: <T, F extends HKT<T[StrKey<T>]>, G extends HKT<StrKey<T>>>(x: Exact<T, F>, f: <P extends StrKey<T>>(v: App<F, T[P]>, k: P) => App<G, P>) => ExactPart1<T, G>;
34
+ export declare const mapExact: <T, F extends HKT<T[StrKey<T>]>, G extends HKT<T[StrKey<T>]>>(x: Exact<T, F>, f: <P extends StrKey<T>>(v: App<F, T[P]>, k: P) => App<G, T[P]>) => Exact<T, G>;
35
+ type Dom<T, V> = HKT<T[StrKey<T>] | V[StrKey<V>]>;
36
+ export declare const spread: <T, V, F extends Dom<T, V>, E = unknown, No extends keyof V = never>(a: Exact<Omit<T, No>, F>, b: Exact<V, F>) => Exact<V & Omit<T, keyof V> & Pick<E, symbol & keyof E>, F>;
37
+ export interface MergeHKT<T, V, F1 extends HKT<StrKey<Omit<T, No>>>, F2 extends HKT<StrKey<V>>, No extends keyof V = never> extends HKT<StrKey<V & Omit<T, No>>> {
38
+ readonly out: I<StrKey<V & Omit<T, No>>, this> extends StrKey<V> ? App<F2, I<StrKey<V>, this>> : App<F1, I<StrKey<Omit<T, No>>, this>>;
39
+ }
40
+ export declare const spread0: <T, V, F1 extends HKT<StrKey<Omit<T, No>>>, F2 extends HKT<StrKey<V>>, E = unknown, No extends keyof V = never>(a: MapO<Omit<T, No>, F1>, b: MapO<V, F2>) => MapO<V & Omit<T, No> & Pick<E, symbol & keyof E>, MergeHKT<T, V, F1, F2, No>>;
41
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { Iterator, HasJob } from '../../types';
2
+ export { mergeIterators } from './merge';
3
+ export declare const firstWorksMerge: <Result, Info extends HasJob>(iters: Iterator<Result, Info>[]) => Iterator<Result, {
4
+ readonly key: string;
5
+ readonly value: Info;
6
+ } & HasJob>;
@@ -0,0 +1,2 @@
1
+ export { firstWorksMerge, mergeIterators } from './combiners';
2
+ export { Machine, wrap } from '../../machine';
@@ -0,0 +1,7 @@
1
+ import type { IteratorResult, HasJob } from '../../types';
2
+ import type { KEYS, Race, SourceIteratorResults, SourceResults } from './types';
3
+ export declare const mergeIterators: <K extends KEYS, Result, Info extends Record<K, HasJob>>(params: {
4
+ sources: SourceIteratorResults<K, Result, Info>;
5
+ interrupt?: (key: KEYS) => boolean;
6
+ select?: Race<K, Result, Info>;
7
+ }) => IteratorResult<Result, SourceResults<K, Info>>;
@@ -0,0 +1,3 @@
1
+ import type { NextFrame, HasJob } from '../../types';
2
+ import type { KEYS, RaceWinner, SourceIteratorResults } from './types';
3
+ export declare const nextWinner: <K extends KEYS, Result, Info extends Record<K, HasJob>>(previousWinner: RaceWinner<K, Result, Info>, previousWinnerNextFrame: NextFrame<Result, Info[K]>, sources: SourceIteratorResults<K, Result, Info>, interrupt?: (key: KEYS) => boolean) => PromiseLike<RaceWinner<K, Result, Info>>;
@@ -0,0 +1,19 @@
1
+ import type { Frame, IteratorResult, HasJob } from '../../types';
2
+ export type KEYS = string;
3
+ export type SourceIteratorResults<K extends KEYS, Result, Info extends Record<K, unknown>> = {
4
+ readonly [P in K]: IteratorResult<Result, Info[P]>;
5
+ };
6
+ export type SourceResults<K extends KEYS, Info extends Record<K, HasJob>> = {
7
+ readonly [P in K]: {
8
+ readonly key: P;
9
+ readonly value: Info[P];
10
+ readonly job: Info[P]['job'];
11
+ };
12
+ }[K];
13
+ export type RaceWinner<K extends KEYS, Result, Info extends Record<K, unknown>> = {
14
+ readonly [P in K]: {
15
+ readonly key: P;
16
+ readonly frame: Frame<Result, Info[P]>;
17
+ };
18
+ }[K];
19
+ export type Race<K extends KEYS, Result, Info extends Record<K, HasJob>> = (arg: SourceIteratorResults<K, Result, Info>) => PromiseLike<RaceWinner<K, Result, Info>>;
@@ -0,0 +1,4 @@
1
+ import type { KEYS, RaceWinner, SourceIteratorResults } from './types';
2
+ export declare const patch: <T, K extends keyof T>(x: T, k: K, v: T[K]) => T;
3
+ export declare const restart: <K extends KEYS, Result, Info extends Record<K, unknown>>(sources: SourceIteratorResults<K, Result, Info>) => SourceIteratorResults<K, Result, Info>;
4
+ export declare const race: <W, K extends KEYS, Result, Info extends Record<K, W>>(sources: SourceIteratorResults<K, Result, Info>) => Promise<RaceWinner<K, Result, Info>>;
@@ -0,0 +1,2 @@
1
+ import type { Iterator } from '../types';
2
+ export declare const addTeardown: <T, Info>(it: Iterator<T, Info>, tr?: () => Promise<void>) => Iterator<T, Info>;
package/lib/watch.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { BSON, Db, Timestamp } from 'mongodb';
2
+ import type { O, StrKey, View } from '../types';
3
+ import { type Field } from './field';
4
+ import type { Model, Query } from './types';
5
+ export declare const changeKeys: readonly ["fullDocument", "fullDocumentBeforeChange"];
6
+ export type ChangeKey = (typeof changeKeys)[number];
7
+ export type Change<T extends Model> = O<{
8
+ readonly fullDocument: T;
9
+ readonly fullDocumentBeforeChange: T;
10
+ }>;
11
+ export declare const subQ: <D extends O, C, DeltaD extends O>(a: Query<D, C>, f: Field<DeltaD, D>) => Query<DeltaD, C>;
12
+ export declare const makeWatchStream: <V extends Model, K extends StrKey<V>>(db: Db, { collection, projection: p, hardMatch: m }: View<V, K>, startAt: Timestamp, streamName: string) => {
13
+ tryNext: () => Promise<import("mongodb").ChangeStreamDocument<BSON.Document> | null>;
14
+ close: () => Promise<void>;
15
+ };
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.43",
6
+ "version": "0.0.44",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",
@@ -0,0 +1,9 @@
1
+ import { Collection, MongoClient } from 'mongodb';
2
+ import type { AsynIter, Iterator } from '../lib/types';
3
+ import type { ID, doc } from '../types';
4
+ import type { Db, OptionalUnlessRequiredId } from 'mongodb';
5
+ export declare const run: <T, Info>(cont: Iterator<T, Info>) => Promise<never>;
6
+ export declare const iterate: <T>([, next]: AsynIter<T>) => PromiseLike<never>;
7
+ export declare const enablePreAndPostImages: <T extends doc>(coll: Collection<T>) => Promise<import("mongodb").Document>;
8
+ export declare const prepare: (testName?: string) => Promise<MongoClient>;
9
+ export declare const makeCol: <T extends ID>(docs: readonly OptionalUnlessRequiredId<T>[], database: Db, name?: string) => Promise<Collection<T>>;
package/test/uri.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const uri: string;
@@ -0,0 +1 @@
1
+ export declare const Type: unique symbol;
@@ -0,0 +1,3 @@
1
+ export type { Type } from './class';
2
+ export type { Arr, ID, N, O, Rec, StrKey, doc, OPick, OPickD, RORec, Replace } from './index';
3
+ export type { AsLiteral, notArr, WriteonlyCollection, Collection, Timestamp } from './index';