@omegup/msync 0.1.62 → 0.1.63

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 (42) hide show
  1. package/adapters/mongodb.d.ts +22 -0
  2. package/adapters/mongodb.esm.js +12 -0
  3. package/adapters/mongodb.esm.js.map +1 -0
  4. package/adapters/mongodb.js +14 -0
  5. package/adapters/mongodb.js.map +1 -0
  6. package/driver-BUCc3b89.js +31 -0
  7. package/driver-BUCc3b89.js.map +1 -0
  8. package/driver-sc6MCG57.esm.js +14 -0
  9. package/driver-sc6MCG57.esm.js.map +1 -0
  10. package/index.d.ts +1 -1
  11. package/index.esm.js +28 -102
  12. package/index.esm.js.map +1 -1
  13. package/index.js +28 -86
  14. package/index.js.map +1 -1
  15. package/lib/accumulators/index.d.ts +1 -1
  16. package/lib/aggregate/$merge.d.ts +5 -5
  17. package/lib/aggregate/group/utils/sub-merge.d.ts +2 -2
  18. package/lib/aggregate/prefix.d.ts +2 -2
  19. package/lib/boot/boot-utils.d.ts +2 -3
  20. package/lib/boot/boot.d.ts +2 -2
  21. package/lib/boot/first-stages.d.ts +1 -2
  22. package/lib/driver.d.ts +5 -0
  23. package/lib/expression/val.d.ts +1 -1
  24. package/lib/predicate/$eq.d.ts +1 -2
  25. package/lib/types/accumulator.d.ts +2 -2
  26. package/lib/types/aggregate.d.ts +4 -2
  27. package/lib/types/query.d.ts +1 -5
  28. package/lib/types/stream.d.ts +3 -4
  29. package/lib/utils/db-indexes.d.ts +1 -1
  30. package/lib/utils/map-object.d.ts +0 -4
  31. package/lib/utils/merge/merge.d.ts +5 -4
  32. package/lib/utils/merge/next-winner.d.ts +2 -1
  33. package/lib/utils/merge/types.d.ts +9 -5
  34. package/lib/utils/merge/utils.d.ts +4 -2
  35. package/lib/watch.d.ts +2 -3
  36. package/package.json +41 -22
  37. package/types/global-aug.d.ts +1 -1
  38. package/types/json.d.ts +12 -4
  39. package/types/mongo.d.ts +83 -23
  40. package/types/view.d.ts +1 -2
  41. package/test/mongodb.d.ts +0 -9
  42. package/test/uri.d.ts +0 -1
@@ -18,7 +18,7 @@ export declare const $pushDict: <D extends O, V, C = unknown>(key: Expr<string,
18
18
  [x: string]: O<{
19
19
  0: import("../..").Arr<AddO<V>>;
20
20
  1: import("../..").Arr<AddO<V>>;
21
- }> | undefined;
21
+ }>;
22
22
  }>, C>;
23
23
  export 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>;
24
24
  export declare const $entries: <D extends O, V, C = unknown>(expr: Expr<AddO<PushDict<V>>, D, C>) => Expr<AddO<{
@@ -19,9 +19,9 @@ type Result<P> = Expr<P, unknown, {
19
19
  }>;
20
20
  type Update<P, Out> = (...args: Args<P, Out>) => Result<P>;
21
21
  type UpdateF<P, Out> = <K extends keyof IsDeleted>(...args: Args<Replace<P, RORec<K, Timestamp>>, Out>) => Result<Replace<P, RORec<K, Timestamp>>>;
22
- export declare const getSubsetMatchForExt: <Out extends Model, P extends Model, E extends Record<keyof E, rawItem>>(ext: Exact<E, IdHKT>) => null | Expr<boolean, Rec<'old' | 'merged', Out | Replace<Out, P>>>;
23
- export declare const getWhenMatchedForMerge: <Out extends Model, P extends Model, K extends keyof IsDeleted>(whenNotMatched: 'discard' | 'fail' | 'insert', update: Update<Replace<P, RORec<K, Timestamp>>, Out>, canWrite: Expr<boolean, Rec<'old' | 'merged', Out | Replace<Out, P>>> | null) => RawStages<O, Out, Out | Replace<Out, P>, RORec<'new', Replace<P, RORec<K, Timestamp>>>>;
24
- export declare const getWhenMatched: <Out extends Model, P extends Model>(whenNotMatched: 'discard' | 'fail' | 'insert', canWrite: Expr<boolean, Rec<'old' | 'merged', Out | Replace<Out, P>>> | null) => RawStages<O, Rec<'old' | 'merged', Out | Replace<Out, P>>, Out | Replace<Out, P>>;
22
+ export declare const getSubsetMatchForExt: <Out extends Model, P extends O & ID & TS, E extends Record<keyof E, rawItem>>(ext: Exact<E, IdHKT>) => null | Expr<boolean, Rec<'old' | 'merged', Out | Replace<Out, P>>>;
23
+ export declare const getWhenMatchedForMerge: <Out extends Model, P extends O & ID & TS, K extends keyof IsDeleted>(whenNotMatched: 'discard' | 'fail' | 'insert', update: Update<Replace<P, RORec<K, Timestamp>>, Out>, canWrite: Expr<boolean, Rec<'old' | 'merged', Out | Replace<Out, P>>> | null) => RawStages<O, Out, Out | Replace<Out, P>, RORec<'new', Replace<P, RORec<K, Timestamp>>>>;
24
+ export declare const getWhenMatched: <Out extends Model, P extends O & ID & TS>(whenNotMatched: 'discard' | 'fail' | 'insert', canWrite: Expr<boolean, Rec<'old' | 'merged', Out | Replace<Out, P>>> | null) => RawStages<O, Rec<'old' | 'merged', Out | Replace<Out, P>>, Out | Replace<Out, P>>;
25
25
  type MergeCollection<V extends O, Out extends Model> = {
26
26
  coll: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>;
27
27
  whenNotMatched: 'discard';
@@ -30,9 +30,9 @@ type MergeCollection<V extends O, Out extends Model> = {
30
30
  whenNotMatched: 'fail';
31
31
  };
32
32
  type MergeUpdate<V, Out> = UpdateF<((OPick<V, Allowed<StrKey<V>>> & ID) | (Rec<Allowed<StrKey<V>>, N> & ID)) & TS, Out>;
33
- export declare const $mergeId: <V extends O>() => <SourcePart extends doc, Out extends Model, E = unknown, EEE extends { [K in StrKey<EEE>]: rawItem; } = {}>(out: MergeCollection<V, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, id: Expr<string, OutInputE<TakeDoc<V>, E, null>>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<OutInputE<SourcePart, E>, 'out'>;
33
+ export declare const $mergeId: <V extends O>() => <SourcePart extends doc, Out extends Model, E = unknown, EEE extends { [K in keyof EEE]: rawItem; } = {}>(out: MergeCollection<V, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, id: Expr<string, OutInputE<TakeDoc<V>, E, null>>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<OutInputE<SourcePart, E>, 'out'>;
34
34
  export declare const $simpleMergePart: <V extends O>() => <Source extends doc, Out extends Model, EEE extends { [K in StrKey<EEE>]: rawItem; }>(out: MergeCollection<V, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Source, 'out'>;
35
35
  export declare const $simpleMerge: <V extends O>() => <Source extends doc, Out extends Model>(out: RWCollection<Out | Replace<Out, Patch<V>> | Replace<Patch<V>, IsDeleted>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, Source>, whenNotMatched?: 'fail' | 'discard', update?: MergeUpdate<V, Out>) => StreamRunnerParam<Source, 'out'>;
36
- export declare const $mergePart: <V extends O>() => <Out extends Model, SourcePart extends doc, EEE extends { [K in StrKey<EEE>]: rawItem; }>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Delta<SourcePart>, 'out'>;
36
+ export declare const $mergePart: <V extends O>() => <Out extends Model, SourcePart extends doc, EEE extends { [K in keyof EEE]: rawItem; }>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, ext: Exact<Omit<SafeE<EEE>, keyof (ND & TS)>, IdHKT>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Delta<SourcePart>, 'out'>;
37
37
  export declare const $merge: <V extends O>() => <Out extends Model, SourcePart extends doc>(out: RWCollection<Out | Replace<Out, Patch<V>>, Out>, keys: ExprsExact<TakeDoc<V, unknown>, SourcePart>, update?: MergeUpdate<V, Out>) => StreamRunnerParam<Delta<SourcePart>, 'out'>;
38
38
  export {};
@@ -1,6 +1,6 @@
1
1
  import type { AsLiteral, ID, O, RWCollection, Rec, Replace, notArr, Omit, Exclude } from '../../../../types';
2
2
  import { type ExprsExact } from '../../../expression/concat';
3
- import type { IsDeleted, Model, RawStages, TS } from '../../../types';
3
+ import type { DeletedAt, IsDeleted, Model, RawStages, TS } from '../../../types';
4
4
  import type { DeltaAccumulators } from '../../../types/accumulator';
5
5
  type GI<GG> = Exclude<GG, keyof TS>;
6
6
  export type IdAndTsKeys = keyof (TS & ID);
@@ -9,7 +9,7 @@ export type Prepare<Grp, GG extends string> = TS & ID & Rec<GI<GG>, Grp>;
9
9
  type Par<T> = {
10
10
  [P in keyof T]?: T[P] | null;
11
11
  };
12
- export type Loose<Grp, VV, GG extends string> = Prepare<Grp, GG> & Par<V<VV, GG>>;
12
+ export type Loose<Grp, VV, GG extends string> = Prepare<Grp, GG> & Par<V<VV, GG>> & DeletedAt;
13
13
  export type Strict<Grp, VV, GG extends string, EE> = Prepare<Grp, GG> & V<VV, GG> & Omit<EE, IdAndTsKeys | GI<GG> | keyof V<VV, GG>>;
14
14
  export type V_Grp<VV, GG extends string, Grp> = Rec<GI<GG>, Grp> & V<VV, GG>;
15
15
  export type Extra<EE, VV, GG extends string> = Omit<EE, IdAndTsKeys | GI<GG> | keyof V<VV, GG>>;
@@ -1,8 +1,8 @@
1
- import type { App, HKT, O2, O3, O, RawObj } from '../../types';
1
+ import type { App, HKT, O2, O3, O } from '../../types';
2
2
  import type { Delta, DeltaStages, FRawStages, RawStages, Stream, TStages } from '../types';
3
3
  import type { Equal } from '../utils/guard';
4
4
  type n = number;
5
- export declare const asStages: <Q, T extends Q, V extends Q, C = unknown, M extends n = n>(x: readonly RawObj[]) => RawStages<Q, T, V, C, M>;
5
+ export declare const asStages: <Q, T extends Q, V extends Q, C = unknown, M extends n = n>(x: RawStages<Q, T, V, C, M>) => RawStages<Q, T, V, C, M>;
6
6
  export declare const same: <T extends Dom, V extends Dom, F extends HKT<Dom, Q>, Dom = unknown, Q = unknown, C = unknown, M extends n = n>(_: Equal<Dom, T, V>) => RawStages<Q, App<F, T>, App<F, V>, C, M>;
7
7
  export declare const concatStages: <Q, T extends Q, V extends Q, W extends Q, C, M extends n = n>(part1: RawStages<Q, T, V, C, M>, part2: RawStages<Q, V, W, C, M>) => RawStages<Q, T, W, C, M>;
8
8
  export declare const concatFStages: <Q, T extends Q & O, V extends Q & O, W extends Q & O, C, M extends n = n>(part1: FRawStages<Q, T, V, C, M>, part2: FRawStages<Q, V, W, C, M>) => FRawStages<Q, T, W, C, M>;
@@ -1,5 +1,4 @@
1
- import { Collection, type Timestamp } from 'mongodb';
2
- import type { BSON, Exclude, OPickD, rawItem, RawObj, StrKey } from '../../types';
1
+ import type { Collection, Document, Exclude, OPickD, rawItem, RawObj, StrKey, Timestamp } from '../../types';
3
2
  import type { Actions, Model } from '../types/stream';
4
3
  export type AllowedPick<V extends Model, K extends StrKey<V>> = OPickD<V, Allowed<K>>;
5
4
  export type Allowed<K> = Exclude<K, 'deletedAt' | '_id'>;
@@ -23,5 +22,5 @@ export type Last = {
23
22
  job?: 1 | null;
24
23
  };
25
24
  export declare const actions: {
26
- [K in keyof Actions<unknown>]: <W extends BSON.Document>(col: Collection<W>, x: Actions<W>[K]) => [Promise<unknown>, unknown[]];
25
+ [K in keyof Actions<unknown>]: <W extends Document>(col: Collection<W>, x: Actions<W>[K]) => [Promise<unknown>, unknown[]];
27
26
  };
@@ -1,10 +1,10 @@
1
- import type { O2, O3, StrKey, View } from '../../types';
1
+ import type { Dict, O2, O3, StrKey, View } from '../../types';
2
2
  import type { HKT, I } from '../../types/hkt';
3
3
  import { type DeltaPipe } from '../aggregate/prefix';
4
4
  import type { SnapshotStreamExecutionResult } from '../types';
5
5
  import type { DeltaStages, Model } from '../types/stream';
6
6
  import type { Allowed, AllowedPick } from './boot-utils';
7
- export declare const streamNames: Record<string, string>;
7
+ export declare const streamNames: Dict<string>;
8
8
  export interface SnapshotStreamHKT extends HKT<O2> {
9
9
  readonly out: SnapshotStreamExecutionResult<I<O2, this>[0], I<O2, this>[1]>;
10
10
  }
@@ -1,5 +1,4 @@
1
- import { Timestamp } from 'mongodb';
2
- import type { O, StrKey, View } from '../../types';
1
+ import type { O, StrKey, Timestamp, View } from '../../types';
3
2
  import { type Concat } from '../aggregate/prefix';
4
3
  import type { Query } from '../types';
5
4
  import type { Del, Model } from '../types/stream';
@@ -0,0 +1,5 @@
1
+ import type { Driver } from '../types';
2
+ export type { Driver } from '../types';
3
+ export declare const useDriver: (driver: Driver) => void;
4
+ export declare const driver: () => Driver;
5
+ export declare const uuid: () => string;
@@ -1,4 +1,4 @@
1
- import type { Timestamp } from 'mongodb';
1
+ import type { Timestamp } from '../../types';
2
2
  import type { Arr, N, O, StrKey, jsonItem, notObj, rawItem } from '../../types';
3
3
  import type { Expr } from '../types';
4
4
  import type { ExprsExact } from './concat';
@@ -1,5 +1,4 @@
1
- import type { Timestamp } from 'mongodb';
2
- import type { Arr, N, rawItem, RawObj } from '../../types';
1
+ import type { Arr, N, rawItem, RawObj, Timestamp } from '../../types';
3
2
  export declare const $eq: <T extends unknown>(operand: rawItem & T) => import("../types").Predicate<T>;
4
3
  export declare const $ne: <T extends unknown>(operand: rawItem & T) => import("../types").Predicate<T>;
5
4
  type Numeric = number | Timestamp | Date;
@@ -1,5 +1,5 @@
1
1
  import type { Expr } from './expr';
2
- import type { HKT, I, N, O, RORec, RawObj, Rec, Type, U, Undef, jsonItem } from '../../types';
2
+ import type { HKT, I, N, O, PRRec, RORec, RawObj, Rec, Type, U, Undef, jsonItem } from '../../types';
3
3
  import type { Field } from '../field';
4
4
  import type { Exact } from '../utils/map-object';
5
5
  declare const AccumulatorRaw: unique symbol;
@@ -15,7 +15,7 @@ export interface DeltaAccumulatorHKT<T, C = unknown> extends HKT<unknown> {
15
15
  readonly out: DeltaAccumulator<T, I<unknown, this>, C>;
16
16
  }
17
17
  export type DeltaAccumulators<T, V extends object, 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;
18
+ export type AccumulatorsRoot<Acc extends Accumulators<never, PRRec<string, jsonItem>, never>> = Acc extends Accumulators<infer T extends O, PRRec<string, jsonItem>, never> ? T : never;
19
19
  export type Accumulator<in Doc, out T, in Ctx = unknown> = {
20
20
  [Type]?(_: typeof Accumulator): typeof Accumulator;
21
21
  raw: {
@@ -1,7 +1,9 @@
1
- import type { Long, Timestamp } from 'mongodb';
1
+ import type { Timestamp } from '../../types';
2
2
  export type AggregateCommand<T> = {
3
3
  cursor: {
4
- id: Long | number;
4
+ id: number | {
5
+ toString(): string;
6
+ };
5
7
  firstBatch: T[];
6
8
  atClusterTime: Timestamp;
7
9
  ns: string;
@@ -1,12 +1,8 @@
1
1
  import type { O, RawObj, Type } from '../../types';
2
2
  import type { Field } from '../field';
3
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
4
  export type Query<in T extends O, in C = unknown> = {
9
5
  [Type]?(x: typeof Query, y: T, c: C): void;
10
- raw: <DeltaT extends O>(f: Field<DeltaT, T>) => QueryRaw<DeltaT, C>;
6
+ raw: <DeltaT extends O>(f: Field<DeltaT, T>) => RawObj;
11
7
  };
12
8
  export {};
@@ -1,5 +1,4 @@
1
- import type { BSON, Filter, Timestamp, UpdateFilter } from 'mongodb';
2
- import type { App, HKT, ID, N, O, RawObj, ReadonlyCollection, Rec, Type, WriteonlyCollection } from '../../types';
1
+ import type { App, Document, Timestamp, HKT, ID, N, O, RawObj, ReadonlyCollection, Rec, Type, WriteonlyCollection } from '../../types';
3
2
  import type { Field } from '../field';
4
3
  import type { HasJob, Runner } from './machine';
5
4
  declare const RawStage: unique symbol;
@@ -22,8 +21,8 @@ export type TStages<in out S, out Q, in out B extends Q, out R extends Q, M exte
22
21
  };
23
22
  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
23
  export type Actions<W> = {
25
- updateMany: [Filter<W>, UpdateFilter<W> | BSON.Document[]];
26
- deleteMany: [Filter<W>];
24
+ updateMany: [Document, Document | readonly Document[]];
25
+ deleteMany: [Document];
27
26
  };
28
27
  export type TeardownRecord<W, M extends keyof Actions<W>> = {
29
28
  collection: WriteonlyCollection<W>;
@@ -1,4 +1,4 @@
1
- import type { Collection, CreateIndexesOptions, Db, IndexSpecification } from 'mongodb';
1
+ import type { Collection, CreateIndexesOptions, Db, IndexSpecification } from '../../types';
2
2
  export declare const indexMap: Map<string, Map<string, Promise<void>>>;
3
3
  export declare const createIndex: (collection: {
4
4
  readonly createIndex: Collection['createIndex'];
@@ -1,13 +1,9 @@
1
1
  import type { App, HKT, I, IdHKT, Omit, 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
2
  export type ExactPart<T, F extends HKT<T[StrKey<T>]>> = MapOPart<T, MappedHKT<T, F>>;
4
3
  export type ExactPart1<T, F extends HKT<StrKey<T>>> = {
5
4
  readonly [K in StrKey<T>]: App<F, K>;
6
5
  };
7
6
  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
7
  export type ExactKeys<K extends string> = Exact<RORec<K, 1>, IdHKT>;
12
8
  export type MapO<T, F extends HKT<K>, K extends StrKey<T> = StrKey<T>> = MapOPart<T, F, K> & {
13
9
  readonly [P: string]: readonly [K, unknown];
@@ -1,10 +1,11 @@
1
+ import type { PRRec } from '../../../types';
1
2
  import type { Frame, IteratorResult, HasJob } from '../../types';
2
3
  import type { KEYS, Race, SourceIteratorResults, SourceResults } from './types';
3
- export declare const mergeIterators: <K extends KEYS, Result, Info extends Record<K, HasJob>>(params: {
4
+ export declare const mergeIterators: <K extends KEYS, Result, Info extends PRRec<K, HasJob>>(params: {
4
5
  sources: SourceIteratorResults<K, Result, Info>;
5
- interrupt?: (key: KEYS) => boolean;
6
- select?: Race<K, Result, Info>;
6
+ interrupt?: ((key: KEYS) => boolean) | undefined;
7
+ select?: Race<K, Result, Info> | undefined;
7
8
  hooks?: {
8
9
  start?: (frame: Frame<Result, Info[K]>, result: IteratorResult<Result, Info[K]>) => void;
9
- };
10
+ } | undefined;
10
11
  }) => IteratorResult<Result, SourceResults<K, Info>>;
@@ -1,3 +1,4 @@
1
+ import type { PRRec } from '../../../types';
1
2
  import type { NextFrame, HasJob } from '../../types';
2
3
  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>>;
4
+ export declare const nextWinner: <K extends KEYS, Result, Info extends PRRec<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>>;
@@ -1,19 +1,23 @@
1
+ import type { PRRec } from '../../../types';
1
2
  import type { Frame, IteratorResult, HasJob } from '../../types';
2
3
  export type KEYS = string;
3
- export type SourceIteratorResults<K extends KEYS, Result, Info extends Record<K, unknown>> = {
4
+ export type SourceIteratorResults<K extends KEYS, Result, Info extends PRRec<K, unknown>> = {
5
+ readonly [P in K]?: IteratorResult<Result, Info[P]>;
6
+ };
7
+ export type RSourceIteratorResults<K extends KEYS, Result, Info extends PRRec<K, unknown>> = {
4
8
  readonly [P in K]: IteratorResult<Result, Info[P]>;
5
9
  };
6
- export type SourceResults<K extends KEYS, Info extends Record<K, HasJob>> = {
10
+ export type SourceResults<K extends KEYS, Info extends PRRec<K, HasJob>> = {
7
11
  readonly [P in K]: {
8
12
  readonly key: P;
9
13
  readonly value: Info[P];
10
- readonly job: Info[P]['job'];
14
+ readonly job: (Info[P] & {})['job'];
11
15
  };
12
16
  }[K];
13
- export type RaceWinner<K extends KEYS, Result, Info extends Record<K, unknown>> = {
17
+ export type RaceWinner<K extends KEYS, Result, Info extends PRRec<K, unknown>> = {
14
18
  readonly [P in K]: {
15
19
  readonly key: P;
16
20
  readonly frame: Frame<Result, Info[P]>;
17
21
  };
18
22
  }[K];
19
- export type Race<K extends KEYS, Result, Info extends Record<K, HasJob>> = (arg: SourceIteratorResults<K, Result, Info>) => PromiseLike<RaceWinner<K, Result, Info>>;
23
+ export type Race<K extends KEYS, Result, Info extends PRRec<K, HasJob>> = (arg: SourceIteratorResults<K, Result, Info>) => PromiseLike<RaceWinner<K, Result, Info>>;
@@ -1,4 +1,6 @@
1
+ import type { PRRec } from '../../../types';
1
2
  import type { KEYS, RaceWinner, SourceIteratorResults } from './types';
3
+ export declare const map: <T, K extends string & keyof T & keyof V, V>(x: Pick<T, K>, f: <P extends K>(v: Required<T>[P], k: P) => V[P]) => V;
2
4
  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>>;
5
+ export declare const restart: <K extends KEYS, Result, Info extends PRRec<K, unknown>>(sources: SourceIteratorResults<K, Result, Info>) => SourceIteratorResults<K, Result, Info>;
6
+ export declare const race: <W, K extends KEYS, Result, Info extends PRRec<K, W>>(sources: SourceIteratorResults<K, Result, Info>) => Promise<RaceWinner<K, Result, Info>>;
package/lib/watch.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { type Db, Timestamp } from 'mongodb';
2
- import type { O, StrKey, View } from '../types';
1
+ import type { Db, Dict, Document, O, StrKey, Timestamp, View } from '../types';
3
2
  import type { Field } from './field';
4
3
  import type { Model, Query } from './types';
5
4
  export type OplogEntry = {
6
5
  ts: Timestamp;
7
6
  ns: string;
8
7
  op: 'i' | 'u' | 'd' | 'c' | 'n';
9
- o: Record<string, unknown>;
8
+ o: Dict<unknown>;
10
9
  o2?: {
11
10
  _id: string;
12
11
  };
package/package.json CHANGED
@@ -1,23 +1,42 @@
1
1
  {
2
- "name": "@omegup/msync",
3
- "version": "0.1.62",
4
- "description": "Keeps derived MongoDB data in sync with the documents it comes from.",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/Omegup/msync.git"
8
- },
9
- "homepage": "https://omegup.github.io/msync/",
10
- "license": "MIT",
11
- "bugs": {
12
- "url": "https://github.com/Omegup/msync/issues"
13
- },
14
- "main": "index.js",
15
- "module": "index.esm.js",
16
- "typings": "index.d.ts",
17
- "dependencies": {
18
- "dayjs": "^1.11.9",
19
- "dotenv": "^16.3.1",
20
- "json-canonicalize": "^2.0.0",
21
- "mongodb": "^6.8.0"
22
- }
23
- }
2
+ "name": "@omegup/msync",
3
+ "version": "0.1.63",
4
+ "description": "Keeps derived MongoDB data in sync with the documents it comes from.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Omegup/msync.git"
8
+ },
9
+ "homepage": "https://omegup.github.io/msync/",
10
+ "license": "MIT",
11
+ "bugs": {
12
+ "url": "https://github.com/Omegup/msync/issues"
13
+ },
14
+ "main": "index.js",
15
+ "module": "index.esm.js",
16
+ "typings": "index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./index.d.ts",
20
+ "import": "./index.esm.js",
21
+ "require": "./index.js"
22
+ },
23
+ "./adapters/mongodb": {
24
+ "types": "./adapters/mongodb.d.ts",
25
+ "import": "./adapters/mongodb.esm.js",
26
+ "require": "./adapters/mongodb.js"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "dayjs": "^1.11.9",
31
+ "dotenv": "^16.3.1",
32
+ "json-canonicalize": "^2.0.0"
33
+ },
34
+ "peerDependencies": {
35
+ "mongodb": "^6.8.0"
36
+ },
37
+ "peerDependenciesMeta": {
38
+ "mongodb": {
39
+ "optional": true
40
+ }
41
+ }
42
+ }
@@ -4,7 +4,7 @@ import type { AsNum, GetDom } from './global';
4
4
  export {};
5
5
  declare global {
6
6
  type Entry<T, K extends keyof T = keyof T> = readonly [string, T[string & K]] & {
7
- [k in K]: readonly [string & k, T[k]];
7
+ [k in K]?: readonly [string & k, T[k]];
8
8
  }[K];
9
9
  interface ObjectConstructor {
10
10
  entries<T, _ = 0>(object?: T): readonly Entry<T>[];
package/types/json.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Timestamp } from 'mongodb';
2
1
  import type { Type } from './class';
2
+ import type { Timestamp } from './mongo';
3
3
  import type { Omit } from './global';
4
4
  export type { Type } from './class';
5
5
  export type U = undefined;
@@ -19,8 +19,8 @@ export interface JsonArr {
19
19
  export type A = {
20
20
  [Type]: typeof array;
21
21
  };
22
- export type Arr<T, N extends number = number> = A & {
23
- readonly [_ in N]: T;
22
+ export type Arr<T> = A & {
23
+ readonly [_: number]: T;
24
24
  };
25
25
  type Obj = {
26
26
  [Type]: typeof object;
@@ -32,6 +32,9 @@ export type RORec<K extends keyof never, T = unknown> = {
32
32
  export type PRRec<K extends keyof never, T = unknown> = {
33
33
  [P in K]?: T;
34
34
  };
35
+ export type Dict<T> = {
36
+ [P: string]: T;
37
+ };
35
38
  export type Par<K extends string, V extends Rec<K, jsonItem>> = {
36
39
  readonly [k in K]?: V[k] | N;
37
40
  };
@@ -49,7 +52,12 @@ export type raw = readonly rawItem[] | RawObj;
49
52
  export type StrKey<T> = string & keyof T;
50
53
  export type Replace<R, V> = Omit<R, StrKey<V>> & V & O;
51
54
  export type ReplaceQ<R extends Q, VV, Q extends O> = Omit<R, StrKey<VV>> & Omit<VV, StrKey<Q>> & Q;
52
- export type AsLiteral<T extends keyof any | boolean | N, V = NoUnion<T>> = T extends keyof any ? {} extends {
55
+ type AnyKeyed = {
56
+ [x: string]: never;
57
+ [x: number]: never;
58
+ [x: symbol]: never;
59
+ };
60
+ export type AsLiteral<T extends keyof any | boolean | N, V = NoUnion<T>> = T extends keyof any ? [Record<string, 1>] extends [never] ? [Record<T, 1>] extends [never] ? never : V : AnyKeyed extends {
53
61
  [K in T]: 1;
54
62
  } ? never : V : V;
55
63
  type NoUnion<T, V = T> = T extends T ? ([V] extends [T] ? T : never) : never;
package/types/mongo.d.ts CHANGED
@@ -1,24 +1,84 @@
1
- import 'mongodb';
2
- import { BSON } from 'mongodb';
1
+ import type { PRRec } from './json';
3
2
  export declare const RawStage: unique symbol;
4
- declare module 'mongodb' {
5
- interface Collection<TSchema extends BSON.Document = BSON.Document> {
6
- [RawStage]: {
7
- (_: 2): TSchema;
8
- (_: 1, x: TSchema): TSchema;
9
- };
10
- s: {
11
- db: Db;
12
- };
13
- }
14
- interface Db {
15
- s: {
16
- client?: MongoClient;
17
- };
18
- client: MongoClient;
19
- }
20
- interface Timestamp {
21
- toExtendedJSON(): BSON.TimestampExtended;
22
- }
23
- }
24
- export * from 'mongodb';
3
+ export type Document = object;
4
+ export type Filter<T> = PRRec<keyof T & string, unknown> & Document;
5
+ export type UpdateFilter<T> = {
6
+ $set?: PRRec<keyof T & string, unknown>;
7
+ } & Document;
8
+ export interface Timestamp {
9
+ readonly _bsontype: 'Timestamp';
10
+ readonly high: number;
11
+ readonly low: number;
12
+ comp(other: unknown): number;
13
+ }
14
+ export interface UUID {
15
+ toString(encoding: 'base64'): string;
16
+ }
17
+ export interface Driver {
18
+ Timestamp: {
19
+ new (value: bigint): Timestamp;
20
+ new (value: {
21
+ t: number;
22
+ i: number;
23
+ }): Timestamp;
24
+ };
25
+ UUID: new () => UUID;
26
+ }
27
+ export interface Cursor<T> extends AsyncIterable<T> {
28
+ next(): Promise<T | null>;
29
+ toArray(): Promise<T[]>;
30
+ close(): Promise<void>;
31
+ }
32
+ export type IndexSpecification = Document;
33
+ export type CreateIndexesOptions = Document & {
34
+ name?: string;
35
+ partialFilterExpression?: Document;
36
+ };
37
+ export type UpdateOptions = {
38
+ upsert?: boolean;
39
+ };
40
+ export interface Commander {
41
+ command<T extends object = PRRec<string, unknown>>(command: Document): Promise<T>;
42
+ }
43
+ export interface Client {
44
+ db(name: string): Db;
45
+ }
46
+ export interface Db extends Commander {
47
+ readonly s: {
48
+ readonly client?: Client;
49
+ };
50
+ readonly client: Client;
51
+ readonly namespace: string;
52
+ admin(): Commander;
53
+ collection<T = Document>(name: string): Collection<T>;
54
+ createCollection(name: string): Promise<unknown>;
55
+ listCollections(filter: Document, options: {
56
+ nameOnly: true;
57
+ }): Cursor<{
58
+ name: string;
59
+ }>;
60
+ }
61
+ export interface Collection<TSchema = Document> {
62
+ readonly s: {
63
+ readonly db: Db;
64
+ };
65
+ readonly collectionName: string;
66
+ readonly namespace: string;
67
+ readonly dbName: string;
68
+ [RawStage]: {
69
+ (_: 2): TSchema;
70
+ (_: 1, x: TSchema): TSchema;
71
+ };
72
+ createIndex(spec: IndexSpecification, options?: CreateIndexesOptions): Promise<string>;
73
+ findOne(filter: Document): Promise<TSchema | null>;
74
+ find(filter: Document, options?: Document): Cursor<TSchema>;
75
+ updateOne(filter: Document, update: Document | readonly Document[], options?: UpdateOptions): Promise<unknown>;
76
+ updateMany(filter: Document, update: Document | readonly Document[]): Promise<unknown>;
77
+ deleteOne(filter: Document): Promise<unknown>;
78
+ deleteMany(filter: Document): Promise<unknown>;
79
+ drop(): Promise<unknown>;
80
+ }
81
+ export type WatchStream<T = {}> = {
82
+ close(): Promise<void>;
83
+ tryNext(): Promise<T | null>;
84
+ };
package/types/view.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import type { Collection, Db } from 'mongodb';
2
1
  import type { Del, Expr, Model, Query } from '../lib/types';
3
2
  import type { ExactKeys } from '../lib/utils/map-object';
4
3
  import type { O, StrKey } from './json';
5
- import type { RawStage } from './mongo';
4
+ import type { Collection, Db, RawStage } from './mongo';
6
5
  interface CommonCollection {
7
6
  readonly s: {
8
7
  readonly db: Db;
package/test/mongodb.d.ts DELETED
@@ -1,9 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
1
- export declare const uri: string;