sedentary 0.0.15 → 0.0.19
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 +65 -57
- package/index.js +206 -84
- package/lib/db.d.ts +16 -2
- package/lib/db.js +5 -5
- package/lib/minidb.js +75 -52
- package/package.json +13 -7
- package/requirements.txt +2 -0
- package/sedentary-pg/LICENSE +0 -21
- package/sedentary-pg/README.md +0 -34
- package/sedentary-pg/lib/pgdb.ts +0 -340
- package/sedentary-pg/package-lock.json +0 -6768
- package/sedentary-pg/package.json +0 -66
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 { DB, EntryBase, ForeignKeyOptions, Meta, 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,12 +12,12 @@ 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<
|
|
20
|
-
[key: string]: (this:
|
|
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];
|
|
19
|
+
declare type Methods<E> = {
|
|
20
|
+
[key: string]: (this: E) => unknown;
|
|
21
21
|
};
|
|
22
22
|
declare type Native__<T> = T extends Type<infer N, unknown> ? N : never;
|
|
23
23
|
declare type Native_<T> = T extends () => Type<infer N, infer E> ? Native__<Type<N, E>> : Native__<T>;
|
|
@@ -33,34 +33,51 @@ export declare type IndexDefinition = IndexAttributes | IndexOptions;
|
|
|
33
33
|
export declare type IndexesDefinition = {
|
|
34
34
|
[key: string]: IndexDefinition;
|
|
35
35
|
};
|
|
36
|
-
declare type BaseModelOptions<T> = {
|
|
36
|
+
declare type BaseModelOptions<B extends boolean, T> = {
|
|
37
37
|
indexes?: IndexesDefinition;
|
|
38
38
|
init?: (this: T) => void;
|
|
39
|
+
int8id?: B;
|
|
39
40
|
sync?: boolean;
|
|
40
41
|
tableName?: string;
|
|
41
42
|
};
|
|
42
|
-
export declare type ModelOptions<K extends string, M extends Methods<T>, P extends Meta<Natural,
|
|
43
|
-
int8id?: boolean;
|
|
43
|
+
export declare type ModelOptions<B extends boolean, K extends string, M extends Methods<T>, P extends Meta<Natural, EntryBase>, T extends EntryBase> = BaseModelOptions<B, T> & {
|
|
44
44
|
methods?: M;
|
|
45
45
|
parent?: P;
|
|
46
46
|
primaryKey?: K;
|
|
47
47
|
};
|
|
48
|
-
declare type
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
declare type ModelBaseOptions = {
|
|
49
|
+
indexes?: IndexesDefinition;
|
|
50
|
+
sync?: boolean;
|
|
51
|
+
tableName?: string;
|
|
52
|
+
};
|
|
53
|
+
export declare type ModelOptions2 = ModelBaseOptions & {
|
|
54
|
+
int8id?: boolean;
|
|
55
|
+
parent?: Type<Natural, EntryBase>;
|
|
56
|
+
primaryKey?: string;
|
|
57
|
+
};
|
|
58
|
+
declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
59
|
+
declare type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
60
|
+
declare type EntryIdNatural<B extends boolean> = IsUnion<B> extends true ? number : B extends true ? string : number;
|
|
61
|
+
export declare type EntryId<B extends boolean> = {
|
|
62
|
+
id?: EntryIdNatural<B>;
|
|
63
|
+
};
|
|
64
|
+
declare type ForeignKey<A> = A extends AttributeDefinition<Natural, infer E> ? () => Promise<E> : never;
|
|
65
|
+
declare type ModelFKAttributes<A extends AttributesDefinition> = {
|
|
66
|
+
[a in ForeignKeys<A> & string as `${a}Load`]?: ForeignKey<A[a]>;
|
|
67
|
+
};
|
|
68
|
+
declare type ModelBaseAttributes<A extends AttributesDefinition> = {
|
|
55
69
|
[a in keyof A]?: Native<A[a]>;
|
|
56
|
-
} & {
|
|
57
|
-
[a in Keys<A> & string as `${a}Load`]?: ForeignKey<A[a]>;
|
|
58
70
|
};
|
|
59
|
-
declare type
|
|
71
|
+
declare type ModelAttributes<A extends AttributesDefinition> = keyof ModelFKAttributes<A> extends never ? ModelBaseAttributes<A> : ModelBaseAttributes<A> & ModelFKAttributes<A>;
|
|
72
|
+
declare type Ancestor<A, N extends Natural, T extends EntryBase> = (new () => T) & {
|
|
60
73
|
[a in keyof A]?: Meta<Native<A[a]>, T>;
|
|
61
74
|
} & {
|
|
62
75
|
load: (boh: boolean) => Promise<T[]>;
|
|
63
|
-
} & Meta<N, T
|
|
76
|
+
} & Meta<N, T> & {
|
|
77
|
+
tmp: number;
|
|
78
|
+
};
|
|
79
|
+
declare type ModelBase<E extends EntryBase> = new () => E;
|
|
80
|
+
export declare type Entry<M> = M extends new () => infer E ? E : never;
|
|
64
81
|
export interface SedentaryOptions {
|
|
65
82
|
log?: ((message: string) => void) | null;
|
|
66
83
|
serverless?: boolean;
|
|
@@ -73,45 +90,36 @@ export declare class Sedentary {
|
|
|
73
90
|
private models;
|
|
74
91
|
constructor(filename: string, options?: SedentaryOptions);
|
|
75
92
|
DATETIME(): Type<Date, unknown>;
|
|
76
|
-
FKEY<N extends Natural, E extends
|
|
93
|
+
FKEY<N extends Natural, E extends EntryBase>(attribute: Type<N, E>, options?: ForeignKeyOptions): Type<N, E>;
|
|
77
94
|
INT(size?: number): Type<number, unknown>;
|
|
78
95
|
INT8(): Type<string, unknown>;
|
|
79
96
|
VARCHAR(size?: number): Type<string, unknown>;
|
|
97
|
+
checkSize(size: number, message: string): number;
|
|
80
98
|
connect(): Promise<void>;
|
|
81
99
|
end(): Promise<void>;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}):
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} &
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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;
|
|
100
|
+
model2<E extends EntryBase>(modelName: string): ModelBase<E>;
|
|
101
|
+
model2<E extends EntryBase, M extends Record<string, <S extends M>(this: E & S) => unknown>>(modelName: string, methods: M & Record<string, (this: E & M) => void>): ModelBase<E & M>;
|
|
102
|
+
model<A extends AttributesDefinition, B extends boolean, E extends EntryBase & EntryId<B> & ModelAttributes<A>>(modelName: string, attributes: A, options?: BaseModelOptions<B, E>): Ancestor<A, string, E>;
|
|
103
|
+
model<A extends AttributesDefinition, B extends boolean, K extends keyof A, P extends Meta<Natural, EntryBase>, N extends P extends {
|
|
104
|
+
tmp: number;
|
|
105
|
+
} ? (P extends Meta<infer N, EntryBase> ? N : never) : Native<A[K]>, E extends (P extends {
|
|
106
|
+
tmp: number;
|
|
107
|
+
} ? Parent<P> : EntryBase) & ModelAttributes<A>>(modelName: string, attributes: A, options?: BaseModelOptions<B, E> & {
|
|
108
|
+
parent?: P;
|
|
109
|
+
primaryKey?: K;
|
|
110
|
+
}): Ancestor<A, N, E>;
|
|
111
|
+
model<A extends AttributesDefinition, B extends boolean, E extends EntryBase & EntryId<B> & ModelAttributes<A>, M extends Record<string, <S extends M>(this: E & S) => unknown>>(modelName: string, attributes: A, options: BaseModelOptions<B, E>, methods: M & Record<string, (this: E & M) => unknown>): Ancestor<A, string, E & M>;
|
|
112
|
+
model<A extends AttributesDefinition, B extends boolean, K extends keyof A, P extends Meta<Natural, EntryBase>, N extends P extends {
|
|
113
|
+
tmp: number;
|
|
114
|
+
} ? (P extends Meta<infer N, EntryBase> ? N : never) : Native<A[K]>, E extends (P extends {
|
|
115
|
+
tmp: number;
|
|
116
|
+
} ? Parent<P> : EntryBase) & ModelAttributes<A>, M extends Record<string, <S extends M>(this: E & S) => unknown>>(modelName: string, attributes: A, options: BaseModelOptions<B, E> & {
|
|
117
|
+
parent?: P;
|
|
118
|
+
primaryKey?: K;
|
|
119
|
+
}, methods: M & Record<string, (this: E & M) => unknown>): Ancestor<A, N, E & M>;
|
|
116
120
|
}
|
|
117
121
|
export declare const Package: typeof Sedentary;
|
|
122
|
+
export declare class Sedentary2 {
|
|
123
|
+
model<E extends EntryBase>(modelName: string): ModelBase<E>;
|
|
124
|
+
model<E extends EntryBase, M extends Record<string, <S extends M>(this: E & S) => unknown>>(modelName: string, methods: M & Record<string, (this: E & M) => void>): ModelBase<E & M>;
|
|
125
|
+
}
|