@idb-orm/core 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -22
- package/dist/client/compiled-query.d.ts +2 -2
- package/dist/client/dump.d.ts +27 -0
- package/dist/client/helpers.d.ts +2 -2
- package/dist/client/index.d.ts +4 -4
- package/dist/client/restore.d.ts +14 -0
- package/dist/client/types/find.d.ts +32 -16
- package/dist/client/types/index.d.ts +7 -7
- package/dist/client/types/mutation.d.ts +25 -24
- package/dist/core.d.ts +1 -5
- package/dist/error.d.ts +46 -1
- package/dist/field/field-types.d.ts +5 -5
- package/dist/field/index.d.ts +1 -1
- package/dist/field/primary-key.d.ts +8 -1
- package/dist/field/property.d.ts +12 -27
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +2 -2
- package/dist/model/model-types.d.ts +7 -4
- package/dist/model/model.d.ts +6 -5
- package/dist/object-store.d.ts +5 -2
- package/dist/typing/index.d.ts +3 -0
- package/dist/typing/tag.d.ts +104 -0
- package/dist/typing/type.d.ts +42 -0
- package/dist/typing/utils.d.ts +30 -0
- package/dist/util-types.d.ts +10 -0
- package/dist/utils.d.ts +5 -0
- package/package.json +1 -1
- package/dist/dump/class.d.ts +0 -22
- package/dist/dump/json.d.ts +0 -9
- package/dist/field/type-wrapper.d.ts +0 -108
- package/dist/field/validators.d.ts +0 -13
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { MaybeGenerator, Promisable } from '../util-types';
|
|
2
|
+
export declare const enum Tag {
|
|
3
|
+
string = 0,
|
|
4
|
+
number = 1,
|
|
5
|
+
date = 2,
|
|
6
|
+
boolean = 3,
|
|
7
|
+
symbol = 4,
|
|
8
|
+
bigint = 5,
|
|
9
|
+
file = 6,
|
|
10
|
+
void = 7,
|
|
11
|
+
float = 8,
|
|
12
|
+
int = 9,
|
|
13
|
+
unknown = 10,
|
|
14
|
+
literal = 11,
|
|
15
|
+
array = 12,
|
|
16
|
+
set = 13,
|
|
17
|
+
union = 14,
|
|
18
|
+
optional = 15,
|
|
19
|
+
default = 16,
|
|
20
|
+
object = 17,
|
|
21
|
+
tuple = 18,
|
|
22
|
+
custom = 19
|
|
23
|
+
}
|
|
24
|
+
export interface VoidTag {
|
|
25
|
+
tag: Tag.void;
|
|
26
|
+
}
|
|
27
|
+
export interface StringTag {
|
|
28
|
+
tag: Tag.string;
|
|
29
|
+
}
|
|
30
|
+
export interface NumberTag {
|
|
31
|
+
tag: Tag.number;
|
|
32
|
+
}
|
|
33
|
+
export interface IntTag {
|
|
34
|
+
tag: Tag.int;
|
|
35
|
+
}
|
|
36
|
+
export interface FloatTag {
|
|
37
|
+
tag: Tag.float;
|
|
38
|
+
}
|
|
39
|
+
export interface DateTag {
|
|
40
|
+
tag: Tag.date;
|
|
41
|
+
}
|
|
42
|
+
export interface BooleanTag {
|
|
43
|
+
tag: Tag.boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface SymbolTag {
|
|
46
|
+
tag: Tag.symbol;
|
|
47
|
+
}
|
|
48
|
+
export interface BigIntTag {
|
|
49
|
+
tag: Tag.bigint;
|
|
50
|
+
}
|
|
51
|
+
export interface UnknownTag {
|
|
52
|
+
tag: Tag.unknown;
|
|
53
|
+
}
|
|
54
|
+
export interface FileTag {
|
|
55
|
+
tag: Tag.file;
|
|
56
|
+
}
|
|
57
|
+
export interface LiteralTag<V = unknown> {
|
|
58
|
+
tag: Tag.literal;
|
|
59
|
+
value: V;
|
|
60
|
+
}
|
|
61
|
+
export interface ArrayTag<V extends TypeTag = TypeTag> {
|
|
62
|
+
tag: Tag.array;
|
|
63
|
+
of: V;
|
|
64
|
+
}
|
|
65
|
+
export interface SetTag<V extends TypeTag = TypeTag> {
|
|
66
|
+
tag: Tag.set;
|
|
67
|
+
of: V;
|
|
68
|
+
}
|
|
69
|
+
export interface OptionalTag<V extends TypeTag = TypeTag> {
|
|
70
|
+
tag: Tag.optional;
|
|
71
|
+
of: V;
|
|
72
|
+
}
|
|
73
|
+
export interface UnionTag<V extends TypeTag[] = TypeTag[]> {
|
|
74
|
+
tag: Tag.union;
|
|
75
|
+
options: V;
|
|
76
|
+
}
|
|
77
|
+
export interface TupleTag<V extends TypeTag[] = TypeTag[]> {
|
|
78
|
+
tag: Tag.tuple;
|
|
79
|
+
elements: V;
|
|
80
|
+
}
|
|
81
|
+
export interface ObjectTag<P extends Record<string, TypeTag> = Record<string, TypeTag>> {
|
|
82
|
+
tag: Tag.object;
|
|
83
|
+
props: P;
|
|
84
|
+
}
|
|
85
|
+
export interface DefaultTag<T extends TypeTag = TypeTag> {
|
|
86
|
+
tag: Tag.default;
|
|
87
|
+
of: T;
|
|
88
|
+
value: MaybeGenerator<unknown>;
|
|
89
|
+
}
|
|
90
|
+
export interface CustomTag<V = any, PR = any> {
|
|
91
|
+
tag: Tag.custom;
|
|
92
|
+
isType: (test: unknown) => boolean;
|
|
93
|
+
parse?: (test: unknown) => PR;
|
|
94
|
+
serialize?: (value: V) => Promisable<unknown>;
|
|
95
|
+
deserialize?: (value: unknown) => Promisable<V>;
|
|
96
|
+
}
|
|
97
|
+
type Dec = [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
98
|
+
export type TypeTag = VoidTag | LiteralTag | StringTag | IntTag | FloatTag | NumberTag | DateTag | BooleanTag | SymbolTag | UnknownTag | FileTag | BigIntTag | SetTag | OptionalTag | UnionTag | ArrayTag | ObjectTag | TupleTag | CustomTag | DefaultTag;
|
|
99
|
+
export type TagToType<T extends TypeTag, Depth extends number = 5> = Depth extends 0 ? any : T extends StringTag ? string : T extends NumberTag ? number : T extends BooleanTag ? boolean : T extends LiteralTag<infer V> ? V : T extends DateTag ? Date : T extends SymbolTag ? symbol : T extends UnknownTag ? unknown : T extends FileTag ? File : T extends BigIntTag ? bigint : T extends TupleTag<infer TEls> ? {
|
|
100
|
+
[K in keyof TEls]: TagToType<TEls[K], Dec[Depth]>;
|
|
101
|
+
} : T extends SetTag<infer T> ? Set<TagToType<T, Dec[Depth]>> : T extends UnionTag<infer TOpts> ? TagToType<TOpts[number], Dec[Depth]> : T extends ArrayTag<infer T> ? TagToType<T, Dec[Depth]>[] : T extends ObjectTag<infer P> ? {
|
|
102
|
+
[K in keyof P]: TagToType<P[K], Dec[Depth]>;
|
|
103
|
+
} : T extends DefaultTag<infer T> | OptionalTag<infer T> ? TagToType<T, Dec[Depth]> | undefined : T extends CustomTag<infer V> ? V : never;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Literable } from '../util-types';
|
|
2
|
+
import { ArrayTag, BigIntTag, BooleanTag, CustomTag, DateTag, DefaultTag, FileTag, FloatTag, IntTag, LiteralTag, NumberTag, ObjectTag, OptionalTag, SetTag, StringTag, SymbolTag, Tag, TagToType, TupleTag, TypeTag, UnionTag, UnknownTag, VoidTag } from './tag';
|
|
3
|
+
interface TypeCache {
|
|
4
|
+
[Tag.string]: StringTag;
|
|
5
|
+
[Tag.number]: NumberTag;
|
|
6
|
+
[Tag.boolean]: BooleanTag;
|
|
7
|
+
[Tag.bigint]: BigIntTag;
|
|
8
|
+
[Tag.symbol]: SymbolTag;
|
|
9
|
+
[Tag.void]: VoidTag;
|
|
10
|
+
[Tag.file]: FileTag;
|
|
11
|
+
[Tag.date]: DateTag;
|
|
12
|
+
[Tag.int]: IntTag;
|
|
13
|
+
[Tag.float]: FloatTag;
|
|
14
|
+
[Tag.unknown]: UnknownTag;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Gets a type from the primitive type cache, creating it if it doesn't exist
|
|
18
|
+
* @param tag Primitive tag to acquire a type for
|
|
19
|
+
* @returns Proper typetag
|
|
20
|
+
*/
|
|
21
|
+
export declare function getType<K extends keyof TypeCache>(tag: K): TypeCache[K];
|
|
22
|
+
export declare function String(): StringTag;
|
|
23
|
+
export declare function Number(): NumberTag;
|
|
24
|
+
export declare function Boolean(): BooleanTag;
|
|
25
|
+
export declare function BigInt(): BigIntTag;
|
|
26
|
+
export declare function Symbol(): SymbolTag;
|
|
27
|
+
export declare function Int(): IntTag;
|
|
28
|
+
export declare function Float(): FloatTag;
|
|
29
|
+
export declare function Void(): VoidTag;
|
|
30
|
+
export declare function File(): FileTag;
|
|
31
|
+
export declare function Date(): DateTag;
|
|
32
|
+
export declare function Unknown(): UnknownTag;
|
|
33
|
+
export declare function Literal<const V extends Literable>(value: V): LiteralTag<V>;
|
|
34
|
+
export declare function Array<V extends TypeTag>(element: V): ArrayTag<V>;
|
|
35
|
+
export declare function Default<V extends TypeTag>(of: V, value: TagToType<V>): DefaultTag<V>;
|
|
36
|
+
export declare function Set<V extends TypeTag>(element: V): SetTag<V>;
|
|
37
|
+
export declare function Union<const V extends TypeTag[]>(types: V): UnionTag<V>;
|
|
38
|
+
export declare function Optional<V extends TypeTag>(type: V): OptionalTag<V>;
|
|
39
|
+
export declare function Object<R extends Record<string, TypeTag>>(props: R): ObjectTag<R>;
|
|
40
|
+
export declare function Tuple<const V extends TypeTag[]>(types: V): TupleTag<V>;
|
|
41
|
+
export declare function Custom<V>(opts: Omit<CustomTag<V>, "tag">): CustomTag<V>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TagToType, TypeTag } from './tag';
|
|
2
|
+
import { ParseResult } from '../field';
|
|
3
|
+
export declare function typeToString(type: TypeTag): string;
|
|
4
|
+
/**
|
|
5
|
+
* Serialize's a type into JSON
|
|
6
|
+
* @param type Type
|
|
7
|
+
* @param value Value to serialize
|
|
8
|
+
*/
|
|
9
|
+
export declare function serializeType<T extends TypeTag>(type: T, value: TagToType<T>): Promise<unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Convert a value from it's JSON serialized version to it's Javascript representation
|
|
12
|
+
* @param type Type to parse the value as
|
|
13
|
+
* @param value JSON value to deserialize
|
|
14
|
+
* @returns Type denoted by the type parameter
|
|
15
|
+
*/
|
|
16
|
+
export declare function deserializeType<T extends TypeTag, R = TagToType<T>>(type: T, value: unknown): Promise<R>;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the given types are exactly equal
|
|
19
|
+
* @param t1 First type to check
|
|
20
|
+
* @param t2 Second type to check
|
|
21
|
+
*/
|
|
22
|
+
export declare function isExactType(t1: TypeTag, t2: TypeTag): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Checks to see if `test` is a valid subtype of `base`
|
|
25
|
+
* @param base Base type tag
|
|
26
|
+
* @param test Testing type tag
|
|
27
|
+
*/
|
|
28
|
+
export declare function isSubtype(base: TypeTag, test: TypeTag): boolean;
|
|
29
|
+
export declare function isType<T extends TypeTag>(type: T, value: unknown): value is TagToType<T>;
|
|
30
|
+
export declare function parseType<T extends TypeTag>(type: T, value: unknown): ParseResult<TagToType<T>>;
|
package/dist/util-types.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export type RemoveNeverValues<T extends object> = {
|
|
|
24
24
|
* A type representing a dictionary from string to some type
|
|
25
25
|
*/
|
|
26
26
|
export type Dict<T = unknown> = Record<string, T>;
|
|
27
|
+
export type PartialRecord<K extends symbol | number | string, V> = {
|
|
28
|
+
[Q in K]?: V;
|
|
29
|
+
};
|
|
30
|
+
export type MaybeGenerator<T> = T | (() => T);
|
|
27
31
|
type UndefinedKeys<T extends Dict> = {
|
|
28
32
|
[K in Keyof<T>]: undefined extends T[K] ? K : never;
|
|
29
33
|
}[Keyof<T>];
|
|
@@ -43,4 +47,10 @@ export type SinglularKey<T extends Record<string, any>> = {
|
|
|
43
47
|
};
|
|
44
48
|
}[keyof T];
|
|
45
49
|
export type Ctor<T> = new (...args: any[]) => T;
|
|
50
|
+
/**
|
|
51
|
+
* If you go over this limit, refactor you application buddy
|
|
52
|
+
*/
|
|
53
|
+
export type RecursionLimit = 10;
|
|
54
|
+
export type PrevDepth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
55
|
+
export type Dec<D extends number> = PrevDepth[D] extends number ? PrevDepth[D] : never;
|
|
46
56
|
export {};
|
package/dist/utils.d.ts
CHANGED
|
@@ -16,3 +16,8 @@ export declare function identity<T>(value: T): T;
|
|
|
16
16
|
* Performs a union over `set1` and `set2`, modifying `set1` to be union of the two sets
|
|
17
17
|
*/
|
|
18
18
|
export declare function unionSets<T>(set: Set<T>, other: Set<T>): Set<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Attempts to coerce a string into a number, if the number is NaN, returns the string instead
|
|
21
|
+
* @param str String to coerce
|
|
22
|
+
*/
|
|
23
|
+
export declare function tryNumberCoerce(str: string): string | number;
|
package/package.json
CHANGED
package/dist/dump/class.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Arrayable, Dict } from '../util-types';
|
|
2
|
-
declare abstract class Dump<T> {
|
|
3
|
-
protected readonly name: string;
|
|
4
|
-
protected readonly content: T;
|
|
5
|
-
protected readonly extension: string;
|
|
6
|
-
constructor(name: string, content: T, extension: string);
|
|
7
|
-
abstract getValue(): T;
|
|
8
|
-
abstract toFile(filename?: string, options?: FilePropertyBag): File;
|
|
9
|
-
download(filename?: string, options?: FilePropertyBag): void;
|
|
10
|
-
}
|
|
11
|
-
type JsonValue = Arrayable<Dict>;
|
|
12
|
-
export declare class JsonDump extends Dump<JsonValue> {
|
|
13
|
-
constructor(name: string, content: JsonValue);
|
|
14
|
-
getValue(): JsonValue;
|
|
15
|
-
toFile(filename?: string, options?: FilePropertyBag): File;
|
|
16
|
-
}
|
|
17
|
-
export declare class CsvDump extends Dump<string> {
|
|
18
|
-
constructor(name: string, content: string);
|
|
19
|
-
getValue(): string;
|
|
20
|
-
toFile(filename?: string, options?: FilePropertyBag): File;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
package/dist/dump/json.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { WhereObject } from '../client/types/find.js';
|
|
2
|
-
import { Dict } from '../util-types';
|
|
3
|
-
import { DbClient } from '../client';
|
|
4
|
-
import { ValidValue } from '../field';
|
|
5
|
-
import { CollectionObject } from '../model';
|
|
6
|
-
import { Transaction } from '../transaction.js';
|
|
7
|
-
import { JsonDump } from './class.js';
|
|
8
|
-
export declare function dumpStoreToJson<Current extends Names, Names extends string, Models extends CollectionObject<Names>>(db: DbClient<string, Names, CollectionObject<Names>>, store: Current, where?: WhereObject<Models[Current] extends Dict<ValidValue> ? Models[Current] : never>, tx?: Transaction<"readonly", Names>): Promise<JsonDump>;
|
|
9
|
-
export declare function dumpDatabaseToJSON<Names extends string>(db: DbClient<string, Names, any>, stores?: Names[]): Promise<JsonDump>;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { Literable, Promisable } from '../util-types.js';
|
|
2
|
-
declare const enum TypeLabel {
|
|
3
|
-
string = 0,
|
|
4
|
-
number = 1,
|
|
5
|
-
boolean = 2,
|
|
6
|
-
literal = 3,
|
|
7
|
-
date = 4,
|
|
8
|
-
symbol = 5,
|
|
9
|
-
bigint = 6,
|
|
10
|
-
array = 7,
|
|
11
|
-
set = 8,
|
|
12
|
-
union = 9,
|
|
13
|
-
optional = 10,
|
|
14
|
-
file = 11,
|
|
15
|
-
unknown = 12,
|
|
16
|
-
default = 13,
|
|
17
|
-
object = 14,
|
|
18
|
-
custom = 15
|
|
19
|
-
}
|
|
20
|
-
export interface StringTag {
|
|
21
|
-
tag: TypeLabel.string;
|
|
22
|
-
}
|
|
23
|
-
export interface NumberTag {
|
|
24
|
-
tag: TypeLabel.number;
|
|
25
|
-
}
|
|
26
|
-
export interface DateTag {
|
|
27
|
-
tag: TypeLabel.date;
|
|
28
|
-
}
|
|
29
|
-
interface BooleanTag {
|
|
30
|
-
tag: TypeLabel.boolean;
|
|
31
|
-
}
|
|
32
|
-
interface SymbolTag {
|
|
33
|
-
tag: TypeLabel.symbol;
|
|
34
|
-
}
|
|
35
|
-
interface BigIntTag {
|
|
36
|
-
tag: TypeLabel.bigint;
|
|
37
|
-
}
|
|
38
|
-
interface UnknownTag {
|
|
39
|
-
tag: TypeLabel.unknown;
|
|
40
|
-
}
|
|
41
|
-
interface FileTag {
|
|
42
|
-
tag: TypeLabel.file;
|
|
43
|
-
}
|
|
44
|
-
interface LiteralTag<V = unknown> {
|
|
45
|
-
tag: TypeLabel.literal;
|
|
46
|
-
value: V;
|
|
47
|
-
}
|
|
48
|
-
interface ArrayTag<V extends TypeTag = TypeTag> {
|
|
49
|
-
tag: TypeLabel.array;
|
|
50
|
-
of: V;
|
|
51
|
-
}
|
|
52
|
-
interface SetTag<V extends TypeTag = TypeTag> {
|
|
53
|
-
tag: TypeLabel.set;
|
|
54
|
-
of: V;
|
|
55
|
-
}
|
|
56
|
-
interface OptionalTag<V extends TypeTag = TypeTag> {
|
|
57
|
-
tag: TypeLabel.optional;
|
|
58
|
-
of: V;
|
|
59
|
-
}
|
|
60
|
-
interface UnionTag<V extends TypeTag[] = TypeTag[]> {
|
|
61
|
-
tag: TypeLabel.union;
|
|
62
|
-
options: V;
|
|
63
|
-
}
|
|
64
|
-
interface ObjectTag<P extends Record<string, TypeTag> = Record<string, TypeTag>> {
|
|
65
|
-
tag: TypeLabel.object;
|
|
66
|
-
props: P;
|
|
67
|
-
}
|
|
68
|
-
interface DefaultTag<V extends TypeTag = TypeTag> {
|
|
69
|
-
tag: TypeLabel.default;
|
|
70
|
-
of: V;
|
|
71
|
-
}
|
|
72
|
-
interface CustomTag<V = any> {
|
|
73
|
-
tag: TypeLabel.custom;
|
|
74
|
-
isType: (test: unknown) => boolean;
|
|
75
|
-
serialize?: (value: V) => Promisable<unknown>;
|
|
76
|
-
deserialize?: (value: unknown) => Promisable<V>;
|
|
77
|
-
}
|
|
78
|
-
export type TypeTag = LiteralTag | StringTag | NumberTag | DateTag | BooleanTag | SymbolTag | UnknownTag | FileTag | BigIntTag | SetTag | OptionalTag | UnionTag | ArrayTag | ObjectTag | DefaultTag | CustomTag;
|
|
79
|
-
export declare class Type {
|
|
80
|
-
static readonly String: StringTag;
|
|
81
|
-
static readonly Number: NumberTag;
|
|
82
|
-
static readonly Boolean: BooleanTag;
|
|
83
|
-
static readonly BigInt: BigIntTag;
|
|
84
|
-
static readonly Symbol: SymbolTag;
|
|
85
|
-
static readonly File: FileTag;
|
|
86
|
-
static readonly Date: DateTag;
|
|
87
|
-
static readonly Unknown: UnknownTag;
|
|
88
|
-
static Literal<const V extends Literable>(value: V): LiteralTag<V>;
|
|
89
|
-
static Array<V extends TypeTag>(element: V): ArrayTag<V>;
|
|
90
|
-
static Set<V extends TypeTag>(element: V): SetTag<V>;
|
|
91
|
-
static Union<const V extends TypeTag[]>(types: V): UnionTag<V>;
|
|
92
|
-
static Optional<V extends TypeTag>(type: V): OptionalTag<V>;
|
|
93
|
-
static Object<R extends Record<string, TypeTag>>(props: R): ObjectTag<R>;
|
|
94
|
-
static Custom<V>({ isType, serialize, deserialize, }: {
|
|
95
|
-
isType: (test: unknown) => boolean;
|
|
96
|
-
serialize?: (value: V) => unknown;
|
|
97
|
-
deserialize?: (value: unknown) => V;
|
|
98
|
-
}): CustomTag<V>;
|
|
99
|
-
/**
|
|
100
|
-
* Serialize's a type into JSON
|
|
101
|
-
* @param type Type
|
|
102
|
-
* @param value Value to serialize
|
|
103
|
-
*/
|
|
104
|
-
static serialize(type: TypeTag, value: unknown): Promise<unknown>;
|
|
105
|
-
static deserialize<T extends TypeTag>(type: T, value: unknown): Promise<unknown>;
|
|
106
|
-
static is<T extends TypeTag>(type: T, value: unknown): boolean;
|
|
107
|
-
}
|
|
108
|
-
export {};
|