@omegup/msync 0.0.16 → 0.0.17

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 (89) hide show
  1. package/index.d.ts +21 -8
  2. package/index.esm.js +103 -3
  3. package/index.js +103 -2
  4. package/lib/accumulators/index.d.ts +10 -0
  5. package/lib/aggregate/$merge.d.ts +10 -0
  6. package/lib/aggregate/$upsert.d.ts +9 -0
  7. package/lib/aggregate/group/$group-merge.d.ts +12 -0
  8. package/lib/aggregate/group/index.d.ts +2 -0
  9. package/lib/aggregate/group/utils/sub-group.d.ts +6 -0
  10. package/lib/aggregate/group/utils/sub-merge.d.ts +15 -0
  11. package/lib/aggregate/index.d.ts +8 -0
  12. package/lib/aggregate/lookup/$lookup-delta.d.ts +10 -0
  13. package/lib/aggregate/lookup/$lookup-raw.d.ts +9 -0
  14. package/lib/aggregate/lookup/index.d.ts +11 -0
  15. package/lib/aggregate/match/$match-delta.d.ts +3 -0
  16. package/lib/aggregate/match/$match.d.ts +3 -0
  17. package/lib/aggregate/match/index.d.ts +2 -0
  18. package/lib/aggregate/mongo-stages.d.ts +13 -0
  19. package/lib/aggregate/out.d.ts +34 -0
  20. package/lib/aggregate/prefix.d.ts +33 -0
  21. package/lib/aggregate/raws.d.ts +17 -0
  22. package/lib/aggregate/set/$replace-with-each.d.ts +12 -0
  23. package/lib/aggregate/set/$set-delta.d.ts +5 -0
  24. package/lib/aggregate/set/$set.d.ts +6 -0
  25. package/lib/aggregate/set/index.d.ts +1 -0
  26. package/lib/aggregate/unwind/$unwind-delta.d.ts +5 -0
  27. package/lib/aggregate/unwind/index.d.ts +5 -0
  28. package/lib/boot/boot-simpl.d.ts +14 -0
  29. package/lib/boot/boot.d.ts +36 -0
  30. package/lib/boot/index.d.ts +2 -0
  31. package/lib/expression/arith.d.ts +26 -0
  32. package/lib/expression/array.d.ts +25 -0
  33. package/lib/expression/concat.d.ts +30 -0
  34. package/lib/expression/date.d.ts +17 -0
  35. package/lib/expression/expr-base.d.ts +5 -0
  36. package/lib/expression/index.d.ts +7 -0
  37. package/lib/expression/logic.d.ts +22 -0
  38. package/lib/expression/range.d.ts +6 -0
  39. package/lib/expression/val.d.ts +25 -0
  40. package/lib/field/field.d.ts +25 -0
  41. package/lib/field/index.d.ts +1 -0
  42. package/lib/machine.d.ts +9 -0
  43. package/lib/predicate/$eq.d.ts +13 -0
  44. package/lib/predicate/$expr.d.ts +3 -0
  45. package/lib/predicate/$in.d.ts +2 -0
  46. package/lib/predicate/index.d.ts +3 -0
  47. package/lib/predicate/utils.d.ts +5 -0
  48. package/lib/query/index.d.ts +1 -0
  49. package/lib/query/logic.d.ts +11 -0
  50. package/lib/stream/aggregate.d.ts +7 -0
  51. package/lib/types/accumulator.d.ts +30 -0
  52. package/lib/types/aggregate.d.ts +9 -0
  53. package/lib/types/expr.d.ts +27 -0
  54. package/lib/types/extern.d.ts +3 -0
  55. package/lib/types/index.d.ts +8 -0
  56. package/lib/types/lookup.d.ts +19 -0
  57. package/lib/types/machine.d.ts +17 -0
  58. package/lib/types/predicate.d.ts +14 -0
  59. package/lib/types/query.d.ts +12 -0
  60. package/lib/types/stream.d.ts +67 -0
  61. package/lib/update/index.d.ts +1 -0
  62. package/lib/update/updater.d.ts +19 -0
  63. package/lib/utils/before.d.ts +3 -0
  64. package/lib/utils/coll.d.ts +5 -0
  65. package/lib/utils/db-indexes.d.ts +4 -0
  66. package/lib/utils/guard.d.ts +18 -0
  67. package/lib/utils/index.d.ts +3 -0
  68. package/lib/utils/json.d.ts +9 -0
  69. package/lib/utils/log.d.ts +1 -0
  70. package/lib/utils/map-object.d.ts +41 -0
  71. package/lib/utils/merge/combiners.d.ts +6 -0
  72. package/lib/utils/merge/index.d.ts +2 -0
  73. package/lib/utils/merge/merge.d.ts +7 -0
  74. package/lib/utils/merge/next-winner.d.ts +3 -0
  75. package/lib/utils/merge/types.d.ts +19 -0
  76. package/lib/utils/merge/utils.d.ts +4 -0
  77. package/lib/utils/tear-down.d.ts +2 -0
  78. package/lib/watch.d.ts +15 -0
  79. package/package.json +1 -1
  80. package/test/mongodb.d.ts +9 -0
  81. package/test/uri.d.ts +1 -0
  82. package/types/class.d.ts +1 -0
  83. package/types/extern.d.ts +3 -0
  84. package/types/global.d.ts +44 -0
  85. package/types/hkt.d.ts +56 -0
  86. package/types/index.d.ts +6 -0
  87. package/types/json.d.ts +54 -0
  88. package/types/mongo.d.ts +24 -0
  89. package/types/view.d.ts +35 -0
@@ -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) => Promise<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?: () => 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) => {
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.16",
6
+ "version": "0.0.17",
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';
@@ -0,0 +1,44 @@
1
+ import type { App, AppMap, AppMapRW, HKT, PromiseHKT } from './hkt';
2
+ import type { RORec, StrKey } from './json';
3
+ export type AsNum<R> = R extends `${infer A extends number}` ? A : never;
4
+ export type GetDom<Dom = unknown> = readonly [readonly Dom[], keyof any];
5
+ declare global {
6
+ type Entry<T, K extends keyof T = keyof T> = readonly [string, T[string & K]] & {
7
+ [k in K]: readonly [string & k, T[k]];
8
+ }[K];
9
+ interface ObjectConstructor {
10
+ entries<T, _ = 0>(object?: T): readonly Entry<T>[];
11
+ fromEntries<T, _ = 0>(entries: readonly Entry<T>[]): T;
12
+ keys<T, _ extends 1>(obj: T): readonly StrKey<T>[];
13
+ }
14
+ interface ReadonlyArray<T> {
15
+ includes<T, V extends T>(this: ReadonlyArray<V>, item: T, fromIndex?: number): item is V;
16
+ map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[];
17
+ map<K extends string, T extends RORec<K>, U extends RORec<K>, _ extends 2 = 2>(this: readonly Entry<T, K>[], callbackfn: <P extends K>(value: [P, T[P]], index: number, array: this) => readonly [P, U[P]], thisArg?: any): readonly Entry<U, K>[];
18
+ map<V extends ReadonlyArray<unknown>, F extends HKT<unknown>, G extends HKT<unknown>, _ extends 1 = 1>(this: AppMap<F, V>, callbackfn: <I extends keyof V>(value: App<F, V[I]>, index: AsNum<I>, array: V) => App<G, V[I]>, thisArg?: any): AppMapRW<G, V>;
19
+ reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
20
+ reduce<V extends ReadonlyArray<unknown>, F extends HKT, U>(this: AppMap<F, V>, callbackfn: <I extends keyof V>(previousValue: U, currentValue: App<F, V[I]>, currentIndex: AsNum<I>, array: V) => U, initialValue: U): U;
21
+ map<V extends ReadonlyArray<Dom>, F extends HKT<Dom>, G extends HKT<GetDom<Dom>>, Dom = unknown, _ extends 0 = 0>(this: AppMap<F, V, Dom>, callbackfn: <I extends keyof V>(value: App<F, V[I] & Dom>, index: AsNum<I>, array: V) => App<G, [V, I]>, thisArg?: any): AppMapRW<G, {
22
+ [I in keyof V]: [V, I];
23
+ }, GetDom<Dom>>;
24
+ }
25
+ interface Array<T> extends ReadonlyArray<T> {
26
+ includes<T, V extends T>(this: ReadonlyArray<V>, item: T, fromIndex?: number): item is V;
27
+ map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[];
28
+ map<K extends string, T extends RORec<K>, U extends RORec<K>, _ extends 2 = 2>(this: readonly Entry<T, K>[], callbackfn: <P extends K>(value: [P, T[P]], index: number, array: this) => readonly [P, U[P]], thisArg?: any): readonly Entry<U, K>[];
29
+ map<V extends ReadonlyArray<unknown>, F extends HKT<unknown>, G extends HKT<unknown>, _ extends 1 = 1>(this: AppMap<F, V>, callbackfn: <I extends keyof V>(value: App<F, V[I]>, index: AsNum<I>, array: V) => App<G, V[I]>, thisArg?: any): AppMapRW<G, V>;
30
+ reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
31
+ reduce<V extends ReadonlyArray<unknown>, F extends HKT, U>(this: AppMap<F, V>, callbackfn: <I extends keyof V>(previousValue: U, currentValue: App<F, V[I]>, currentIndex: AsNum<I>, array: V) => U, initialValue: U): U;
32
+ map<V extends ReadonlyArray<Dom>, F extends HKT<Dom>, G extends HKT<GetDom<Dom>>, Dom = unknown, _ extends 0 = 0>(this: AppMap<F, V, Dom>, callbackfn: <I extends keyof V>(value: App<F, V[I] & Dom>, index: AsNum<I>, array: V) => App<G, [V, I]>, thisArg?: any): AppMapRW<G, {
33
+ [I in keyof V]: [V, I];
34
+ }, GetDom<Dom>>;
35
+ }
36
+ interface PromiseConstructor {
37
+ all<T extends readonly unknown[] | []>(values: AppMap<PromiseHKT, T>): Promise<T>;
38
+ race<T extends readonly unknown[] | [], _ extends 0 = 0>(values: AppMap<PromiseHKT, T>): Promise<T[number]>;
39
+ all<T extends readonly unknown[] | []>(values: T): Promise<{
40
+ -readonly [P in keyof T]: Awaited<T[P]>;
41
+ }>;
42
+ race<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
43
+ }
44
+ }
package/types/hkt.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ import type { UBefore } from "../lib/types";
2
+ import type { Rec } from "./json";
3
+ export interface HKT<in Dom = unknown, out Im = unknown> {
4
+ readonly in: (x: Dom) => void;
5
+ readonly out: Im;
6
+ }
7
+ export type App<F extends HKT<X>, X> = (F & {
8
+ readonly in: (x: X) => void;
9
+ })['out'];
10
+ export type I<Dom, F extends HKT<Dom>> = F['in'] extends (x: infer X extends Dom) => void ? X : never;
11
+ export interface ArrHKT<Dom = unknown> extends HKT<Dom> {
12
+ readonly out: readonly I<Dom, this>[];
13
+ }
14
+ export interface IdHKT<Dom = unknown> extends HKT<Dom> {
15
+ readonly out: I<Dom, this>;
16
+ }
17
+ export interface RConstHKT<Im, Dom = Im> extends HKT<Im, HKT<Dom, Im>> {
18
+ readonly out: ConstHKT<I<Im, this>, Dom>;
19
+ }
20
+ export interface ConstHKT<Im, Dom = unknown> extends HKT<Dom, Im> {
21
+ readonly out: Im;
22
+ }
23
+ type ApplyF<Dom, Im, T extends [Dom, HKT<Dom, Im>]> = App<T[1], T[0]>;
24
+ export interface ApplyHKT<Dom, Im> extends HKT<[Dom, HKT<Dom, Im>], Im> {
25
+ readonly out: ApplyF<Dom, Im, I<[Dom, HKT<Dom, Im>], this>>;
26
+ }
27
+ export interface µ<X extends [HKT<A, B>, HKT<B, C>], A = unknown, B = unknown, C = unknown> extends HKT<A, C> {
28
+ readonly out: App<X[1], App<X[0], I<A, this>>>;
29
+ }
30
+ export type AppMap<F extends HKT<Dom>, X extends readonly Dom[], Dom = unknown> = readonly App<F, Dom>[] & {
31
+ [I in keyof X]: App<F, X[I]>;
32
+ };
33
+ export type AppMapRW<F extends HKT<Dom>, X extends readonly Dom[], Dom = unknown> = App<F, Dom>[] & {
34
+ [I in keyof X]: App<F, X[I]>;
35
+ };
36
+ export interface PromiseHKT<Dom = unknown> extends HKT<Dom> {
37
+ readonly out: PromiseLike<I<Dom, this>>;
38
+ }
39
+ export interface DeepFieldHKT<R, T, K extends keyof T, F extends HKT<R, T>> extends HKT<R, T[K]> {
40
+ readonly out: App<F, I<R, this>>[K];
41
+ }
42
+ export interface FieldHKT<K extends string> extends DeepFieldHKT<Record<K, unknown>, Record<K, unknown>, K, IdHKT<Record<K, unknown>>> {
43
+ }
44
+ export interface RecordHKT<K extends string, Dom = unknown> extends HKT<Dom, Record<K, Dom>> {
45
+ readonly out: Record<K, I<Dom, this>>;
46
+ }
47
+ export interface RecHKT<K extends string, Dom = unknown, E = unknown> extends HKT<Dom, Rec<K, Dom>> {
48
+ readonly out: Rec<K, I<Dom, this>> & E;
49
+ }
50
+ export interface UBeforeHKT<Dom = unknown> extends HKT<Dom, UBefore<Dom>> {
51
+ readonly out: UBefore<I<Dom, this>>;
52
+ }
53
+ export interface And<E> extends HKT {
54
+ readonly out: E & I<unknown, this>;
55
+ }
56
+ export {};
@@ -0,0 +1,6 @@
1
+ export * from './global';
2
+ export * from './json';
3
+ export * from './hkt';
4
+ export * from './class';
5
+ export * from './view';
6
+ export * from './mongo';
@@ -0,0 +1,54 @@
1
+ import type { Timestamp } from 'mongodb';
2
+ import { Type } from './class';
3
+ export { Type } from './class';
4
+ export type U = undefined;
5
+ export type N = null | U;
6
+ export type jsonPrim = number | null | string | boolean | Timestamp | Date;
7
+ export type notObj = jsonPrim | U;
8
+ export type notArr = notObj | O;
9
+ export type jsonItem = unknown;
10
+ export type rawItem = jsonPrim | raw | U;
11
+ export type Undef<I extends N> = I | (I extends never ? I : notObj);
12
+ export declare const object: unique symbol;
13
+ export declare const array: unique symbol;
14
+ export interface JsonArr {
15
+ [Type]: typeof array;
16
+ readonly [_: number]: jsonItem | U;
17
+ }
18
+ export type A = {
19
+ [Type]: typeof array;
20
+ };
21
+ export type Arr<T, N extends number = number> = A & {
22
+ readonly [_ in N]: T;
23
+ };
24
+ type Obj = {
25
+ [Type]: typeof object;
26
+ };
27
+ export type O<T = unknown> = Obj & T;
28
+ export type RORec<K extends keyof never, T = unknown> = {
29
+ readonly [P in K]: T;
30
+ };
31
+ export type Par<K extends string, V extends Rec<K, jsonItem>> = {
32
+ readonly [k in K]?: V[k] | N;
33
+ };
34
+ export type Rec<K extends string, T = unknown> = O<RORec<K, T>>;
35
+ export type O2 = readonly [O, O];
36
+ export type O3 = readonly [O, O, O];
37
+ export type ID = {
38
+ readonly _id: string;
39
+ };
40
+ export type doc = O & ID;
41
+ export interface RawObj {
42
+ readonly [_: string]: rawItem | U;
43
+ }
44
+ export type raw = readonly rawItem[] | RawObj;
45
+ export type StrKey<T> = string & keyof T;
46
+ export type Replace<R, V> = Omit<R, StrKey<V>> & V & O;
47
+ export type AsLiteral<T extends keyof any | boolean, V = NoUnion<T>> = T extends keyof any ? {} extends {
48
+ [K in T]: 1;
49
+ } ? never : V : V;
50
+ type NoUnion<T, V = T> = T extends unknown ? ([V] extends [T] ? T : never) : never;
51
+ export type Literal<K> = string extends K ? never : K;
52
+ export type RemoveSignature<T> = {
53
+ [K in keyof T as Literal<K>]: T[K];
54
+ };
@@ -0,0 +1,24 @@
1
+ import 'mongodb';
2
+ import { BSON } from 'mongodb';
3
+ 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';
@@ -0,0 +1,35 @@
1
+ import type { Collection, Db } from 'mongodb';
2
+ import type { Del, Expr, Model, Query } from '../lib/types';
3
+ import type { ExactKeys } from '../lib/utils/map-object';
4
+ import type { O, StrKey } from './json';
5
+ import type { RawStage } from './mongo';
6
+ interface CommonCollection {
7
+ readonly s: {
8
+ readonly db: Db;
9
+ };
10
+ collectionName: string;
11
+ namespace: string;
12
+ dbName: string;
13
+ createIndex: Collection['createIndex'];
14
+ }
15
+ export interface ReadonlyCollection<out Out> extends CommonCollection {
16
+ [RawStage](_: 2): Out;
17
+ }
18
+ export interface WriteonlyCollection<in R> extends CommonCollection {
19
+ [RawStage]: {
20
+ (_: 1, x: R): unknown;
21
+ };
22
+ }
23
+ export interface RWCollection<in R extends O, out Out extends O = R> extends CommonCollection {
24
+ [RawStage](_: 2): Out;
25
+ [RawStage](_: 1, x: R): unknown;
26
+ }
27
+ export type OPick<V, K extends StrKey<V>, E extends StrKey<V> = never> = O & Pick<V, K | E>;
28
+ export type OPickD<V extends Model, K extends StrKey<V>> = OPick<V, K, 'deletedAt' | '_id'>;
29
+ export type View<V extends Model, K extends StrKey<V>> = {
30
+ collection: ReadonlyCollection<V | Del>;
31
+ projection: ExactKeys<K>;
32
+ match?: Expr<boolean, OPickD<V, K>>;
33
+ hardMatch?: Query<V>;
34
+ };
35
+ export {};