sedentary 0.0.16 → 0.0.20
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 +0 -4
- package/index.d.ts +63 -65
- package/index.js +149 -172
- package/lib/db.d.ts +22 -18
- package/lib/db.js +11 -14
- package/lib/minidb.js +77 -53
- package/lib/transaction.d.ts +2 -0
- package/lib/transaction.js +6 -0
- package/package.json +25 -7
- package/utils.d.ts +1 -0
- package/utils.js +130 -0
- package/lib/log.d.ts +0 -4
- package/lib/log.js +0 -20
- package/lib/log.ts +0 -22
package/README.md
CHANGED
|
@@ -118,10 +118,6 @@ To work with the package under Windows, be sure to configure `bash.exe` as your
|
|
|
118
118
|
|
|
119
119
|
Do not hesitate to report any bug or inconsistency [@github](https://github.com/iccicci/sedentary/issues).
|
|
120
120
|
|
|
121
|
-
# ChangeLog
|
|
122
|
-
|
|
123
|
-
[ChangeLog](https://github.com/iccicci/sedentary/blob/master/CHANGELOG.md)
|
|
124
|
-
|
|
125
121
|
# Donating
|
|
126
122
|
|
|
127
123
|
If you find useful this package, please consider the opportunity to donate some satoshis to this bitcoin address:
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DB,
|
|
2
|
-
export {
|
|
1
|
+
import { Attribute, DB, EntryBase, ForeignKeyOptions, Natural, Type } from "./lib/db";
|
|
2
|
+
export { EntryBase, ForeignKeyActions, ForeignKeyOptions, Natural, Type } from "./lib/db";
|
|
3
3
|
export declare type TypeDefinition<N extends Natural, E> = (() => Type<N, E>) | Type<N, E>;
|
|
4
4
|
export interface AttributeOptions<N extends Natural, E> {
|
|
5
5
|
defaultValue?: N;
|
|
@@ -12,17 +12,13 @@ export declare type AttributeDefinition<N extends Natural, E> = TypeDefinition<N
|
|
|
12
12
|
export declare type AttributesDefinition = {
|
|
13
13
|
[key: string]: AttributeDefinition<Natural, unknown>;
|
|
14
14
|
};
|
|
15
|
-
declare type
|
|
16
|
-
declare type
|
|
17
|
-
[
|
|
18
|
-
}[keyof
|
|
19
|
-
declare type Methods<T> = {
|
|
20
|
-
[key: string]: (this: T) => unknown;
|
|
21
|
-
};
|
|
15
|
+
declare type ForeignKeysAttributes<T, k> = T extends AttributeDefinition<Natural, infer E> ? (E extends EntryBase ? k : never) : never;
|
|
16
|
+
declare type ForeignKeys<A extends AttributesDefinition> = {
|
|
17
|
+
[a in keyof A]?: ForeignKeysAttributes<A[a], a>;
|
|
18
|
+
}[keyof A];
|
|
22
19
|
declare type Native__<T> = T extends Type<infer N, unknown> ? N : never;
|
|
23
20
|
declare type Native_<T> = T extends () => Type<infer N, infer E> ? Native__<Type<N, E>> : Native__<T>;
|
|
24
21
|
declare type Native<T> = T extends AttributeOptions<infer N, infer E> ? Native__<Type<N, E>> : Native_<T>;
|
|
25
|
-
declare type Parent<T> = T extends Meta<Natural, infer E> ? E : never;
|
|
26
22
|
export declare type IndexAttributes = string[] | string;
|
|
27
23
|
export interface IndexOptions {
|
|
28
24
|
attributes: IndexAttributes;
|
|
@@ -33,34 +29,59 @@ export declare type IndexDefinition = IndexAttributes | IndexOptions;
|
|
|
33
29
|
export declare type IndexesDefinition = {
|
|
34
30
|
[key: string]: IndexDefinition;
|
|
35
31
|
};
|
|
36
|
-
|
|
32
|
+
interface BaseModelOptions {
|
|
37
33
|
indexes?: IndexesDefinition;
|
|
38
|
-
init?: (this: T) => void;
|
|
39
34
|
sync?: boolean;
|
|
40
35
|
tableName?: string;
|
|
41
|
-
}
|
|
42
|
-
export
|
|
36
|
+
}
|
|
37
|
+
export interface ModelOptions extends BaseModelOptions {
|
|
43
38
|
int8id?: boolean;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
parent?: Type<Natural, EntryBase>;
|
|
40
|
+
primaryKey?: string;
|
|
41
|
+
}
|
|
42
|
+
declare type ConditionAttribute<N extends Natural> = N | [">" | "<" | ">=" | "<=" | "<>", N] | ["LIKE", string] | ["IN", ...N[]];
|
|
43
|
+
declare type ConditionBase<A extends AttributesDefinition> = string | {
|
|
44
|
+
[a in keyof A]?: ConditionAttribute<Native<A[a]>>;
|
|
47
45
|
};
|
|
48
|
-
declare type
|
|
49
|
-
declare type
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
declare type
|
|
46
|
+
declare type Condition<A extends AttributesDefinition> = ConditionBase<A> | ["NOT", Condition<A>] | ["AND", ...Condition<A>[]] | ["OR", ...Condition<A>[]];
|
|
47
|
+
declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
48
|
+
declare type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
49
|
+
declare type BaseKeyType<B extends boolean> = IsUnion<B> extends true ? number : B extends true ? string : number;
|
|
50
|
+
declare type KeyType<B extends boolean, P extends ModelStd> = P extends new () => EntryBase ? (P extends Attribute<infer T, EntryBase> ? T : never) : BaseKeyType<B>;
|
|
51
|
+
declare type ForeignKey<A> = A extends AttributeDefinition<Natural, infer E> ? () => Promise<E> : never;
|
|
52
|
+
declare type EntryBaseAttributes<A extends AttributesDefinition> = {
|
|
55
53
|
[a in keyof A]?: Native<A[a]>;
|
|
56
|
-
} & {
|
|
57
|
-
[a in Keys<A> & string as `${a}Load`]?: ForeignKey<A[a]>;
|
|
58
54
|
};
|
|
59
|
-
declare type
|
|
60
|
-
|
|
55
|
+
declare type EntryMethodsBase<P extends ModelStd> = P extends new () => EntryBase ? P["methods"] : EntryBase;
|
|
56
|
+
declare type EntryMethodsFK<A extends AttributesDefinition> = {
|
|
57
|
+
[a in ForeignKeys<A> & string as `${a}Load`]: ForeignKey<A[a]>;
|
|
58
|
+
};
|
|
59
|
+
declare type EntryMethods<A extends AttributesDefinition, P extends ModelStd> = keyof EntryMethodsFK<A> extends never ? EntryMethodsBase<P> : EntryMethodsBase<P> & EntryMethodsFK<A>;
|
|
60
|
+
declare type ModelAttributesIf<A extends AttributesDefinition, T> = keyof A extends never ? T : T & A;
|
|
61
|
+
declare type ModelAttributes<A extends AttributesDefinition, B extends boolean, K extends string, P extends ModelStd> = K extends keyof A ? A : ModelAttributesIf<A, P extends new () => EntryBase ? P["attributes"] : {
|
|
62
|
+
id: Type<BaseKeyType<B>, unknown>;
|
|
63
|
+
}>;
|
|
64
|
+
declare type ModelBase<N extends Natural, A extends AttributesDefinition, EA extends Record<string, Natural | undefined>, EM extends EntryBase, E extends EntryBase> = (new (from?: EA) => E) & Attribute<N, E> & {
|
|
65
|
+
attributes: A;
|
|
66
|
+
foreignKeys: Record<string, boolean>;
|
|
67
|
+
methods: EM;
|
|
68
|
+
parent?: ModelStd;
|
|
69
|
+
tableName: string;
|
|
70
|
+
load: (where?: Condition<A>) => Promise<E[]>;
|
|
61
71
|
} & {
|
|
62
|
-
|
|
63
|
-
}
|
|
72
|
+
[a in keyof A]: Attribute<Native<A[a]>, E>;
|
|
73
|
+
};
|
|
74
|
+
declare type Model<N extends Natural, A extends AttributesDefinition, EM extends EntryBase> = ModelBase<N, A, EntryBaseAttributes<A>, EM, EntryBaseAttributes<A> & EM>;
|
|
75
|
+
declare type ModelStd = Attribute<Natural, EntryBase> & {
|
|
76
|
+
attributes: AttributesDefinition;
|
|
77
|
+
foreignKeys: Record<string, boolean>;
|
|
78
|
+
methods: EntryBase;
|
|
79
|
+
parent?: ModelStd;
|
|
80
|
+
};
|
|
81
|
+
export declare type Entry<M> = M extends new () => infer E ? E : never;
|
|
82
|
+
export declare type Where<M> = M extends {
|
|
83
|
+
load: (where: infer T) => void;
|
|
84
|
+
} ? Exclude<T, undefined> : never;
|
|
64
85
|
export interface SedentaryOptions {
|
|
65
86
|
log?: ((message: string) => void) | null;
|
|
66
87
|
serverless?: boolean;
|
|
@@ -73,45 +94,22 @@ export declare class Sedentary {
|
|
|
73
94
|
private models;
|
|
74
95
|
constructor(filename: string, options?: SedentaryOptions);
|
|
75
96
|
DATETIME(): Type<Date, unknown>;
|
|
76
|
-
FKEY<N extends Natural, E extends
|
|
97
|
+
FKEY<N extends Natural, E extends EntryBase>(attribute: Attribute<N, E>, options?: ForeignKeyOptions): Type<N, E>;
|
|
77
98
|
INT(size?: number): Type<number, unknown>;
|
|
78
99
|
INT8(): Type<string, unknown>;
|
|
79
100
|
VARCHAR(size?: number): Type<string, unknown>;
|
|
101
|
+
checkSize(size: number, message: string): number;
|
|
80
102
|
connect(): Promise<void>;
|
|
81
103
|
end(): Promise<void>;
|
|
82
|
-
model<A extends AttributesDefinition,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
primaryKey
|
|
91
|
-
}):
|
|
92
|
-
model<A extends AttributesDefinition, M extends Methods<T>, P extends Meta<Natural, Entry>, N extends P extends Meta<infer N, Entry> ? N : never, T extends Parent<P> & ModelWithMetods<A, M>>(name: string, attributes: A, options?: BaseModelOptions<T> & {
|
|
93
|
-
methods: M;
|
|
94
|
-
parent: P;
|
|
95
|
-
}): Ancestor<A, N, T>;
|
|
96
|
-
model<A extends AttributesDefinition, M extends Methods<T>, T extends Entry & {
|
|
97
|
-
id?: number;
|
|
98
|
-
} & ModelWithMetods<A, M>>(name: string, attributes: A, options?: BaseModelOptions<T> & {
|
|
99
|
-
methods: M;
|
|
100
|
-
}): Ancestor<A, number, T>;
|
|
101
|
-
model<A extends AttributesDefinition, T extends Entry & {
|
|
102
|
-
id?: string;
|
|
103
|
-
} & Model<A>>(name: string, attributes: A, options?: BaseModelOptions<T> & {
|
|
104
|
-
int8id: true;
|
|
105
|
-
}): Ancestor<A, string, T>;
|
|
106
|
-
model<A extends AttributesDefinition, K extends keyof A, N extends K extends keyof A ? Native<A[K]> : never, T extends Entry & Model<A>>(name: string, attributes: A, options?: BaseModelOptions<T> & {
|
|
107
|
-
primaryKey: K;
|
|
108
|
-
}): Ancestor<A, N, T>;
|
|
109
|
-
model<A extends AttributesDefinition, P extends Meta<Natural, Entry>, N extends P extends Meta<infer N, Entry> ? N : never, T extends Parent<P> & Model<A>>(name: string, attributes: A, options?: BaseModelOptions<T> & {
|
|
110
|
-
parent: P;
|
|
111
|
-
}): Ancestor<A, N, T>;
|
|
112
|
-
model<A extends AttributesDefinition, T extends Entry & {
|
|
113
|
-
id?: number;
|
|
114
|
-
} & Model<A>>(name: string, attributes: A, options?: BaseModelOptions<T>): Ancestor<A, number, T>;
|
|
115
|
-
checkSize(size: number, message: string): number;
|
|
104
|
+
model<A extends AttributesDefinition, B extends boolean, K extends string, P extends ModelStd, EM extends EntryMethods<A, P>>(modelName: string, attributes: A, options?: BaseModelOptions & {
|
|
105
|
+
int8id?: B;
|
|
106
|
+
parent?: P;
|
|
107
|
+
primaryKey?: K | keyof A;
|
|
108
|
+
}): Model<K extends keyof A ? Native<A[K]> : KeyType<B, P>, ModelAttributes<A, B, K, P>, EM>;
|
|
109
|
+
model<A extends AttributesDefinition, B extends boolean, K extends string, P extends ModelStd, EA extends EntryBaseAttributes<ModelAttributes<A, B, K, P>>, EM extends EntryMethods<A, P>, M extends Record<string, <S extends M>(this: EA & EM & S, ...args: any[]) => void>>(modelName: string, attributes: A, options: BaseModelOptions & {
|
|
110
|
+
int8id?: B;
|
|
111
|
+
parent?: P;
|
|
112
|
+
primaryKey?: K | keyof A;
|
|
113
|
+
}, methods: M & Record<keyof M, (this: EA & EM & M, ...args: any[]) => void>): Model<K extends keyof A ? Native<A[K]> : KeyType<B, P>, ModelAttributes<A, B, K, P>, EM & M>;
|
|
116
114
|
}
|
|
117
115
|
export declare const Package: typeof Sedentary;
|