sedentary 0.0.41 → 0.0.44
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 +3 -3
- package/dist/cjs/db.d.ts +110 -0
- package/dist/cjs/index.d.ts +142 -0
- package/dist/cjs/index.js +32 -29
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/es/db.d.ts +110 -0
- package/dist/es/index.d.ts +142 -0
- package/dist/es/index.js +32 -29
- package/dist/es/tsconfig.es.tsbuildinfo +1 -0
- package/dist/types/db.d.ts +17 -18
- package/dist/types/index.d.ts +25 -24
- package/dist/types/tsconfig.types.tsbuildinfo +1 -0
- package/package.json +11 -36
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ const db = new Sedentary("file.db");
|
|
|
52
52
|
|
|
53
53
|
class Items extends db.model("Item", {
|
|
54
54
|
num: db.INT,
|
|
55
|
-
str: db.
|
|
55
|
+
str: db.VarChar(30)
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
(async function () {
|
|
@@ -109,9 +109,9 @@ To work with the package under Windows, be sure to configure `bash.exe` as your
|
|
|
109
109
|
> npm config set script-shell bash.exe
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
#
|
|
112
|
+
# License
|
|
113
113
|
|
|
114
|
-
[MIT
|
|
114
|
+
[MIT License](https://github.com/iccicci/sedentary/blob/master/LICENSE)
|
|
115
115
|
|
|
116
116
|
# Bugs
|
|
117
117
|
|
package/dist/cjs/db.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export declare class EntryBase {
|
|
2
|
+
constructor(from?: Partial<EntryBase>);
|
|
3
|
+
construct(): void;
|
|
4
|
+
postLoad(): void;
|
|
5
|
+
postRemove(): void;
|
|
6
|
+
postSave(): void;
|
|
7
|
+
preLoad(): void;
|
|
8
|
+
preRemove(): void;
|
|
9
|
+
preSave(): void;
|
|
10
|
+
remove(): Promise<boolean>;
|
|
11
|
+
save(): Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export declare type ForeignKeyActions = "cascade" | "no action" | "restrict" | "set default" | "set null";
|
|
14
|
+
export interface ForeignKeyOptions {
|
|
15
|
+
onDelete?: ForeignKeyActions;
|
|
16
|
+
onUpdate?: ForeignKeyActions;
|
|
17
|
+
}
|
|
18
|
+
export interface Type<T, E> {
|
|
19
|
+
base: unknown;
|
|
20
|
+
entry?: E;
|
|
21
|
+
native?: T;
|
|
22
|
+
size?: number;
|
|
23
|
+
type: string;
|
|
24
|
+
foreignKey?: {
|
|
25
|
+
attributeName: string;
|
|
26
|
+
fieldName: string;
|
|
27
|
+
options?: ForeignKeyOptions;
|
|
28
|
+
tableName: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export declare class Type<T, E> {
|
|
32
|
+
constructor(from: Type<T, E>);
|
|
33
|
+
}
|
|
34
|
+
export interface Attribute<T, E> extends Type<T, E> {
|
|
35
|
+
attributeName: string;
|
|
36
|
+
defaultValue?: unknown;
|
|
37
|
+
fieldName: string;
|
|
38
|
+
modelName: string;
|
|
39
|
+
notNull: boolean;
|
|
40
|
+
tableName: string;
|
|
41
|
+
unique?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare class Attribute<T, E> extends Type<T, E> {
|
|
44
|
+
constructor(from: Attribute<T, E>);
|
|
45
|
+
}
|
|
46
|
+
export interface Constraint {
|
|
47
|
+
attribute: Attribute<unknown, unknown>;
|
|
48
|
+
constraintName: string;
|
|
49
|
+
type: "f" | "u";
|
|
50
|
+
}
|
|
51
|
+
export interface Index {
|
|
52
|
+
fields: string[];
|
|
53
|
+
indexName: string;
|
|
54
|
+
type: "btree" | "hash";
|
|
55
|
+
unique: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface ITable {
|
|
58
|
+
attributes: Attribute<unknown, unknown>[];
|
|
59
|
+
autoIncrement: boolean;
|
|
60
|
+
constraints: Constraint[];
|
|
61
|
+
indexes: Index[];
|
|
62
|
+
model: {
|
|
63
|
+
load: (where: any, order?: string[], tx?: Transaction) => Promise<EntryBase[]>;
|
|
64
|
+
};
|
|
65
|
+
parent?: Attribute<unknown, unknown>;
|
|
66
|
+
pk: Attribute<unknown, unknown>;
|
|
67
|
+
sync: boolean;
|
|
68
|
+
tableName: string;
|
|
69
|
+
}
|
|
70
|
+
declare const Table_base: new (defaults?: ITable | undefined) => ITable;
|
|
71
|
+
export declare class Table extends Table_base {
|
|
72
|
+
autoIncrementOwn?: boolean;
|
|
73
|
+
oid?: number;
|
|
74
|
+
findField(name: string): Attribute<unknown, unknown>;
|
|
75
|
+
}
|
|
76
|
+
export declare abstract class DB<T extends Transaction> {
|
|
77
|
+
tables: Table[];
|
|
78
|
+
protected log: (message: string) => void;
|
|
79
|
+
protected sync: boolean;
|
|
80
|
+
abstract connect(): Promise<void>;
|
|
81
|
+
abstract end(): Promise<void>;
|
|
82
|
+
constructor(log: (message: string) => void);
|
|
83
|
+
findTable(name: string): Table;
|
|
84
|
+
protected indexesEq(a: Index, b: Index): boolean;
|
|
85
|
+
syncDataBase(): Promise<void>;
|
|
86
|
+
protected syncLog(message: string): void;
|
|
87
|
+
abstract begin(): Promise<T>;
|
|
88
|
+
abstract escape(value: unknown): string;
|
|
89
|
+
abstract load(tableName: string, attributes: Record<string, string>, pk: Attribute<unknown, unknown>, model: new () => EntryBase, table: Table): (where: string, order?: string | string[], limit?: number, tx?: Transaction, lock?: boolean) => Promise<EntryBase[]>;
|
|
90
|
+
abstract remove(tableName: string, pk: Attribute<unknown, unknown>): (this: EntryBase & Record<string, unknown>) => Promise<boolean>;
|
|
91
|
+
abstract save(tableName: string, attributes: Record<string, string>, pk: Attribute<unknown, unknown>): (this: EntryBase & Record<string, unknown>) => Promise<boolean>;
|
|
92
|
+
abstract dropConstraints(table: Table): Promise<number[]>;
|
|
93
|
+
abstract dropFields(table: Table): Promise<void>;
|
|
94
|
+
abstract dropIndexes(table: Table, constraintIndexes: number[]): Promise<void>;
|
|
95
|
+
abstract syncConstraints(table: Table): Promise<void>;
|
|
96
|
+
abstract syncFields(table: Table): Promise<void>;
|
|
97
|
+
abstract syncIndexes(table: Table): Promise<void>;
|
|
98
|
+
abstract syncSequence(table: Table): Promise<void>;
|
|
99
|
+
abstract syncTable(table: Table): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
export declare class Transaction {
|
|
102
|
+
private entries;
|
|
103
|
+
protected log: (message: string) => void;
|
|
104
|
+
constructor(log: (message: string) => void);
|
|
105
|
+
addEntry(entry: EntryBase): void;
|
|
106
|
+
clean(): void;
|
|
107
|
+
commit(): Promise<void>;
|
|
108
|
+
rollback(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Attribute, DB, EntryBase, ForeignKeyOptions, Transaction, Type } from "./db";
|
|
2
|
+
export { Attribute, DB, EntryBase, ForeignKeyActions, ForeignKeyOptions, Index, Table, Transaction, Type } from "./db";
|
|
3
|
+
export declare type TypeDefinition<T, E> = (() => Type<T, E>) | Type<T, E>;
|
|
4
|
+
export interface AttributeOptions<T, E> {
|
|
5
|
+
defaultValue?: T;
|
|
6
|
+
fieldName?: string;
|
|
7
|
+
notNull?: boolean;
|
|
8
|
+
type: TypeDefinition<T, E>;
|
|
9
|
+
unique?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare type AttributeDefinition<T, E> = TypeDefinition<T, E> | AttributeOptions<T, E>;
|
|
12
|
+
export declare type AttributesDefinition = {
|
|
13
|
+
[key: string]: AttributeDefinition<unknown, unknown>;
|
|
14
|
+
};
|
|
15
|
+
declare type ForeignKeysAttributes<T, k> = T extends AttributeDefinition<unknown, 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 Native___<T> = T extends Type<infer N, unknown> ? N : never;
|
|
20
|
+
declare type Native__<T> = T extends () => Type<infer N, infer E> ? Native___<Type<N, E>> : Native___<T>;
|
|
21
|
+
declare type Native_<T, N, E> = T extends {
|
|
22
|
+
notNull: true;
|
|
23
|
+
} ? Native___<Type<N, E>> : Native___<Type<N, E>> | null;
|
|
24
|
+
declare type Native<T> = T extends AttributeOptions<infer N, infer E> ? Native_<T, N, E> : Native__<T> | null;
|
|
25
|
+
export declare type IndexAttributes = string[] | string;
|
|
26
|
+
export interface IndexOptions {
|
|
27
|
+
attributes: IndexAttributes;
|
|
28
|
+
type?: "btree" | "hash";
|
|
29
|
+
unique?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare type IndexDefinition = IndexAttributes | IndexOptions;
|
|
32
|
+
export declare type IndexesDefinition = {
|
|
33
|
+
[key: string]: IndexDefinition;
|
|
34
|
+
};
|
|
35
|
+
interface BaseModelOptions {
|
|
36
|
+
indexes?: IndexesDefinition;
|
|
37
|
+
sync?: boolean;
|
|
38
|
+
tableName?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ModelOptions extends BaseModelOptions {
|
|
41
|
+
int8id?: boolean;
|
|
42
|
+
parent?: Attribute<unknown, EntryBase>;
|
|
43
|
+
primaryKey?: string;
|
|
44
|
+
}
|
|
45
|
+
declare type ConditionAttribute<T> = T | ["=" | ">" | "<" | ">=" | "<=" | "<>", T] | ["IN", T[]] | ["IS NULL"] | ["LIKE", string] | ["NOT"];
|
|
46
|
+
declare type ConditionBase<A extends AttributesDefinition> = string | {
|
|
47
|
+
[a in keyof A]?: ConditionAttribute<Native<A[a]>>;
|
|
48
|
+
};
|
|
49
|
+
declare type Condition<A extends AttributesDefinition> = ConditionBase<A> | ["NOT", Condition<A>] | ["AND", ...Condition<A>[]] | ["OR", ...Condition<A>[]];
|
|
50
|
+
declare type Order_<A extends AttributesDefinition> = keyof A | `-${string & keyof A}`;
|
|
51
|
+
declare type Order<A extends AttributesDefinition> = Order_<A> | Order_<A>[];
|
|
52
|
+
declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
53
|
+
declare type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
54
|
+
declare type BaseKeyType<B extends boolean> = IsUnion<B> extends true ? number : B extends true ? string : number;
|
|
55
|
+
declare type KeyType<B extends boolean, P extends ModelStd> = P extends new () => EntryBase ? (P extends Attribute<infer T, EntryBase> ? T : never) : BaseKeyType<B>;
|
|
56
|
+
declare type ForeignKey<A> = A extends AttributeDefinition<unknown, infer E> ? () => Promise<E> : never;
|
|
57
|
+
declare type EntryBaseAttributes<A extends AttributesDefinition> = {
|
|
58
|
+
[a in keyof A]: Native<A[a]>;
|
|
59
|
+
};
|
|
60
|
+
declare type EntryMethodsBase<P extends ModelStd> = P extends new () => EntryBase ? P["methods"] : EntryBase;
|
|
61
|
+
declare type EntryMethodsFK<A extends AttributesDefinition> = {
|
|
62
|
+
[a in ForeignKeys<A> & string as `${a}Load`]: ForeignKey<A[a]>;
|
|
63
|
+
};
|
|
64
|
+
declare type EntryMethods<A extends AttributesDefinition, P extends ModelStd> = keyof EntryMethodsFK<A> extends never ? EntryMethodsBase<P> : EntryMethodsBase<P> & EntryMethodsFK<A>;
|
|
65
|
+
declare type ModelAttributesIf<A extends AttributesDefinition, T> = keyof A extends never ? T : T & A;
|
|
66
|
+
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"] : {
|
|
67
|
+
id: {
|
|
68
|
+
notNull: true;
|
|
69
|
+
type: Type<BaseKeyType<B>, unknown>;
|
|
70
|
+
};
|
|
71
|
+
}>;
|
|
72
|
+
export interface ModelLoad<A extends AttributesDefinition, E extends EntryBase> {
|
|
73
|
+
load(where: Condition<A>, order?: Order<A>, limit?: number, tx?: Transaction, lock?: boolean): Promise<E[]>;
|
|
74
|
+
load(where: Condition<A>, order?: Order<A>, tx?: Transaction, lock?: boolean): Promise<E[]>;
|
|
75
|
+
load(where: Condition<A>, limit?: number, tx?: Transaction, lock?: boolean): Promise<E[]>;
|
|
76
|
+
load(where: Condition<A>, tx: Transaction, lock?: boolean): Promise<E[]>;
|
|
77
|
+
}
|
|
78
|
+
declare type ModelBase<T, A extends AttributesDefinition, EA extends Record<string, unknown>, EM extends EntryBase, E extends EntryBase> = (new (from?: Partial<EA>, tx?: Transaction) => E) & Attribute<T, E> & {
|
|
79
|
+
attributes: A;
|
|
80
|
+
foreignKeys: Record<string, boolean>;
|
|
81
|
+
methods: EM;
|
|
82
|
+
parent?: ModelStd;
|
|
83
|
+
tableName: string;
|
|
84
|
+
} & {
|
|
85
|
+
[a in keyof A]: Attribute<Native<A[a]>, E>;
|
|
86
|
+
} & ModelLoad<A, E>;
|
|
87
|
+
declare type Model<T, A extends AttributesDefinition, EM extends EntryBase> = ModelBase<T, A, EntryBaseAttributes<A>, EM, EntryBaseAttributes<A> & EM>;
|
|
88
|
+
declare type ModelStd = Attribute<unknown, EntryBase> & {
|
|
89
|
+
attributes: AttributesDefinition;
|
|
90
|
+
foreignKeys: Record<string, boolean>;
|
|
91
|
+
methods: EntryBase;
|
|
92
|
+
parent?: ModelStd;
|
|
93
|
+
};
|
|
94
|
+
export declare type Entry<M> = M extends new () => infer E ? E : never;
|
|
95
|
+
export declare type OrderBy<M> = M extends {
|
|
96
|
+
load(where: unknown, order?: infer T): void;
|
|
97
|
+
load(where: unknown, limit?: number): void;
|
|
98
|
+
load(where: unknown, tx?: Transaction): void;
|
|
99
|
+
} ? Exclude<T, undefined> : never;
|
|
100
|
+
export declare type Where<M> = M extends {
|
|
101
|
+
load(where: infer T): void;
|
|
102
|
+
} ? T : never;
|
|
103
|
+
export interface SedentaryOptions {
|
|
104
|
+
autoSync?: boolean;
|
|
105
|
+
log?: ((message: string) => void) | null;
|
|
106
|
+
sync?: boolean;
|
|
107
|
+
}
|
|
108
|
+
export declare class Sedentary<D extends DB<T>, T extends Transaction> {
|
|
109
|
+
protected autoSync: boolean;
|
|
110
|
+
protected db: D;
|
|
111
|
+
protected doSync: boolean;
|
|
112
|
+
protected log: (message: string) => void;
|
|
113
|
+
private models;
|
|
114
|
+
constructor(options?: SedentaryOptions);
|
|
115
|
+
Boolean(): Type<boolean, unknown>;
|
|
116
|
+
DateTime(): Type<Date, unknown>;
|
|
117
|
+
FKey<T, E extends EntryBase>(attribute: Attribute<T, E>, options?: ForeignKeyOptions): Type<T, E>;
|
|
118
|
+
Int(size?: number): Type<number, unknown>;
|
|
119
|
+
Int8(): Type<bigint, unknown>;
|
|
120
|
+
JSON<T>(): Type<T, unknown>;
|
|
121
|
+
Number(): Type<number, unknown>;
|
|
122
|
+
VarChar(size?: number): Type<string, unknown>;
|
|
123
|
+
private checkDB;
|
|
124
|
+
private checkOrderBy;
|
|
125
|
+
private checkSize;
|
|
126
|
+
private createWhere;
|
|
127
|
+
connect(sync?: boolean): Promise<void>;
|
|
128
|
+
sync(): Promise<void>;
|
|
129
|
+
end(): Promise<void>;
|
|
130
|
+
begin(): Promise<T>;
|
|
131
|
+
escape(value: unknown): string;
|
|
132
|
+
model<A extends AttributesDefinition, B extends boolean, K extends string, P extends ModelStd, EM extends EntryMethods<A, P>>(modelName: string, attributes: A, options?: BaseModelOptions & {
|
|
133
|
+
int8id?: B;
|
|
134
|
+
parent?: P;
|
|
135
|
+
primaryKey?: K | keyof A;
|
|
136
|
+
}): Model<K extends keyof A ? Native<A[K]> : KeyType<B, P>, ModelAttributes<A, B, K, P>, EM>;
|
|
137
|
+
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 & {
|
|
138
|
+
int8id?: B;
|
|
139
|
+
parent?: P;
|
|
140
|
+
primaryKey?: K | keyof A;
|
|
141
|
+
}, 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>;
|
|
142
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -39,30 +39,33 @@ class Sedentary {
|
|
|
39
39
|
this.log = log ? log : log === null ? () => { } : console.log;
|
|
40
40
|
this.doSync = sync;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
Boolean() {
|
|
43
43
|
return new db_1.Type({ base: Boolean, type: "BOOLEAN" });
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
DateTime() {
|
|
46
46
|
return new db_1.Type({ base: Date, type: "DATETIME" });
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
FKey(attribute, options) {
|
|
49
49
|
const { attributeName, base, fieldName, size, tableName, type } = attribute;
|
|
50
50
|
return new db_1.Type({ base, foreignKey: { attributeName, fieldName, options, tableName }, size, type });
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
Int(size) {
|
|
53
53
|
const message = "Sedentary.INT: 'size' argument: Wrong value, expected 2 or 4";
|
|
54
54
|
size = size ? this.checkSize(size, message) : 4;
|
|
55
55
|
if (size !== 2 && size !== 4)
|
|
56
56
|
throw new Error(message);
|
|
57
57
|
return new db_1.Type({ base: Number, size, type: "INT" });
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
Int8() {
|
|
60
60
|
return new db_1.Type({ base: BigInt, size: 8, type: "INT8" });
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
JSON() {
|
|
63
|
+
return new db_1.Type({ base: Object, type: "JSON" });
|
|
64
|
+
}
|
|
65
|
+
Number() {
|
|
63
66
|
return new db_1.Type({ base: Number, type: "NUMBER" });
|
|
64
67
|
}
|
|
65
|
-
|
|
68
|
+
VarChar(size) {
|
|
66
69
|
const message = "Sedentary.VARCHAR: 'size' argument: Wrong value, expected positive integer";
|
|
67
70
|
size = size ? this.checkSize(size, message) : undefined;
|
|
68
71
|
return new db_1.Type({ base: String, size, type: "VARCHAR" });
|
|
@@ -195,7 +198,7 @@ class Sedentary {
|
|
|
195
198
|
await this.db.end();
|
|
196
199
|
this.log("Connection closed");
|
|
197
200
|
}
|
|
198
|
-
|
|
201
|
+
begin() {
|
|
199
202
|
return this.db.begin();
|
|
200
203
|
}
|
|
201
204
|
escape(value) {
|
|
@@ -227,12 +230,12 @@ class Sedentary {
|
|
|
227
230
|
throw new Error(`Sedentary.model: '${modelName}' model: 'parent' and 'primaryKey' options conflict each other`);
|
|
228
231
|
let autoIncrement = true;
|
|
229
232
|
const { indexes, int8id, parent, primaryKey, sync, tableName } = { sync: this.doSync, tableName: modelName, ...options };
|
|
230
|
-
let
|
|
231
|
-
? [new db_1.Attribute({ ...this.
|
|
232
|
-
: [new db_1.Attribute({ ...this.
|
|
233
|
-
let constraints = [{ attribute:
|
|
234
|
-
const
|
|
235
|
-
let pk =
|
|
233
|
+
let aArray = int8id
|
|
234
|
+
? [new db_1.Attribute({ ...this.Int8(), attributeName: "id", fieldName: "id", modelName, notNull: true, tableName, unique: true })]
|
|
235
|
+
: [new db_1.Attribute({ ...this.Int(4), attributeName: "id", fieldName: "id", modelName, notNull: true, tableName, unique: true })];
|
|
236
|
+
let constraints = [{ attribute: aArray[0], constraintName: `${tableName}_id_unique`, type: "u" }];
|
|
237
|
+
const iArray = [];
|
|
238
|
+
let pk = aArray[0];
|
|
236
239
|
let attr2field = { id: "id" };
|
|
237
240
|
if (!methods)
|
|
238
241
|
methods = {};
|
|
@@ -249,16 +252,16 @@ class Sedentary {
|
|
|
249
252
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
250
253
|
attr2field = parent ? { ...parent.attr2field } : {};
|
|
251
254
|
autoIncrement = false;
|
|
252
|
-
|
|
255
|
+
aArray = [];
|
|
253
256
|
constraints = [];
|
|
254
257
|
}
|
|
255
258
|
for (const attributeName of Object.keys(attributes).sort()) {
|
|
256
259
|
if (reservedNames.includes(attributeName))
|
|
257
260
|
throw new Error(`Sedentary.model: '${modelName}' model: '${attributeName}' attribute: Reserved name`);
|
|
258
261
|
const call = (defaultValue, fieldName, notNull, unique, func, message1, message2) => {
|
|
259
|
-
if (func === this.
|
|
260
|
-
throw new Error(`${message1} 'this.
|
|
261
|
-
if (![this.
|
|
262
|
+
if (func === this.FKey)
|
|
263
|
+
throw new Error(`${message1} 'this.FKey' can't be used directly`);
|
|
264
|
+
if (![this.Boolean, this.DateTime, this.Int, this.JSON, this.Int8, this.Number, this.VarChar].includes(func))
|
|
262
265
|
throw new Error(`${message1} ${message2}`);
|
|
263
266
|
return new db_1.Attribute({ attributeName, defaultValue, fieldName, modelName, notNull, tableName, unique, ...func() });
|
|
264
267
|
};
|
|
@@ -305,17 +308,17 @@ class Sedentary {
|
|
|
305
308
|
if (foreignKey) {
|
|
306
309
|
const options = foreignKey.options || {};
|
|
307
310
|
if (foreignKey.options !== undefined && !(foreignKey.options instanceof Object))
|
|
308
|
-
throw new Error(`Sedentary.
|
|
311
|
+
throw new Error(`Sedentary.FKey: '${modelName}' model: '${attributeName}' attribute: Wrong options type, expected 'Object'`);
|
|
309
312
|
for (const k in options)
|
|
310
313
|
if (!["onDelete", "onUpdate"].includes(k))
|
|
311
|
-
throw new Error(`Sedentary.
|
|
314
|
+
throw new Error(`Sedentary.FKey: '${modelName}' model: '${attributeName}' attribute: Unknown option '${k}'`);
|
|
312
315
|
for (const onChange of ["onDelete", "onUpdate"]) {
|
|
313
316
|
const actions = ["cascade", "no action", "restrict", "set default", "set null"];
|
|
314
317
|
let action = options[onChange];
|
|
315
318
|
if (!action)
|
|
316
319
|
action = options[onChange] = "no action";
|
|
317
320
|
if (action && !actions.includes(action))
|
|
318
|
-
throw new Error(`Sedentary.
|
|
321
|
+
throw new Error(`Sedentary.FKey: '${modelName}' model: '${attributeName}' attribute: '${onChange}' option: Wrong value, expected ${actions.map(_ => `'${_}'`).join(" | ")}`);
|
|
319
322
|
}
|
|
320
323
|
foreignKey.options = options;
|
|
321
324
|
}
|
|
@@ -328,7 +331,7 @@ class Sedentary {
|
|
|
328
331
|
const attribute = new db_1.Attribute({ attributeName, base, defaultValue, fieldName, foreignKey, modelName, notNull, size, tableName, type, unique });
|
|
329
332
|
if (primaryKey === attributeName)
|
|
330
333
|
pk = attribute;
|
|
331
|
-
|
|
334
|
+
aArray.push(attribute);
|
|
332
335
|
attr2field[attributeName] = fieldName;
|
|
333
336
|
if (foreignKey)
|
|
334
337
|
constraints.push({ attribute, constraintName: `fkey_${fieldName}_${foreignKey.tableName}_${foreignKey.fieldName}`, type: "f" });
|
|
@@ -336,17 +339,17 @@ class Sedentary {
|
|
|
336
339
|
constraints.push({ attribute, constraintName: `${tableName}_${fieldName}_unique`, type: "u" });
|
|
337
340
|
}
|
|
338
341
|
if (indexes) {
|
|
339
|
-
const
|
|
342
|
+
const originalAttributes = attributes;
|
|
340
343
|
if (!(indexes instanceof Object))
|
|
341
344
|
throw new Error(`Sedentary.model: '${modelName}' model: 'indexes' option: Wrong type, expected 'Object'`);
|
|
342
345
|
for (const indexName in indexes) {
|
|
343
|
-
if (
|
|
346
|
+
if (aArray.some(({ fieldName, unique }) => unique && `${tableName}_${fieldName}_unique` === indexName))
|
|
344
347
|
throw new Error(`Sedentary.model: '${modelName}' model: '${indexName}' index: index name already inferred by the unique constraint on an attribute`);
|
|
345
348
|
const idx = indexes[indexName];
|
|
346
349
|
const checkAttribute = (attribute, l) => {
|
|
347
350
|
if (typeof attribute !== "string")
|
|
348
351
|
throw new Error(`Sedentary.model: '${modelName}' model: '${indexName}' index: #${l + 1} attribute: Wrong type, expected 'string'`);
|
|
349
|
-
if (!(attribute in
|
|
352
|
+
if (!(attribute in originalAttributes))
|
|
350
353
|
throw new Error(`Sedentary.model: '${modelName}' model: '${indexName}' index: #${l + 1} attribute: Unknown attribute '${attribute}'`);
|
|
351
354
|
};
|
|
352
355
|
let attributes;
|
|
@@ -384,11 +387,11 @@ class Sedentary {
|
|
|
384
387
|
}
|
|
385
388
|
else
|
|
386
389
|
throw new Error(`Sedentary.model: '${modelName}' model: '${indexName}' index: Wrong type, expected 'Object'`);
|
|
387
|
-
|
|
390
|
+
iArray.push({ fields: attributes, indexName, type, unique });
|
|
388
391
|
}
|
|
389
392
|
}
|
|
390
393
|
this.models[modelName] = true;
|
|
391
|
-
const foreignKeys =
|
|
394
|
+
const foreignKeys = aArray
|
|
392
395
|
.filter(_ => _.foreignKey)
|
|
393
396
|
.reduce((ret, curr) => {
|
|
394
397
|
ret[curr.attributeName] = true;
|
|
@@ -438,7 +441,7 @@ class Sedentary {
|
|
|
438
441
|
tx.addEntry(this);
|
|
439
442
|
}
|
|
440
443
|
};
|
|
441
|
-
const table = new db_1.Table({ autoIncrement, constraints,
|
|
444
|
+
const table = new db_1.Table({ attributes: aArray, autoIncrement, constraints, indexes: iArray, model: ret, parent, pk, sync, tableName });
|
|
442
445
|
this.db.tables.push(table);
|
|
443
446
|
const load_ = this.db.load(tableName, attr2field, pk, ret, table);
|
|
444
447
|
const load = async (where, ...args) => {
|
|
@@ -506,7 +509,7 @@ class Sedentary {
|
|
|
506
509
|
return ret;
|
|
507
510
|
};
|
|
508
511
|
Object.defineProperty(ret.prototype.save, "name", { value: modelName + ".save" });
|
|
509
|
-
for (const attribute of
|
|
512
|
+
for (const attribute of aArray)
|
|
510
513
|
Object.defineProperty(ret, attribute.attributeName, { value: attribute });
|
|
511
514
|
for (const key of ["attributeName", "base", "fieldName", "modelName", "size", "tableName", "type", "unique"])
|
|
512
515
|
Object.defineProperty(ret, key, { value: pk[key] });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../../../../node_modules/typescript/lib/lib.es5.d.ts","../../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../../node_modules/typescript/lib/lib.dom.d.ts","../../../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../../../node_modules/typescript/lib/lib.scripthost.d.ts","../../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2020.full.d.ts","../../db.ts","../../index.ts","../../../../node_modules/@babel/types/lib/index.d.ts","../../../../node_modules/@types/babel__generator/index.d.ts","../../../../node_modules/@babel/parser/typings/babel-parser.d.ts","../../../../node_modules/@types/babel__template/index.d.ts","../../../../node_modules/@types/babel__traverse/index.d.ts","../../../../node_modules/@types/babel__core/index.d.ts","../../../../node_modules/@types/eslint/helpers.d.ts","../../../../node_modules/@types/eslint/lib/rules/index.d.ts","../../../../node_modules/@types/json-schema/index.d.ts","../../../../node_modules/@types/estree/index.d.ts","../../../../node_modules/@types/eslint/index.d.ts","../../../../node_modules/@types/node/assert.d.ts","../../../../node_modules/@types/node/assert/strict.d.ts","../../../../node_modules/@types/node/globals.d.ts","../../../../node_modules/@types/node/async_hooks.d.ts","../../../../node_modules/@types/node/buffer.d.ts","../../../../node_modules/@types/node/child_process.d.ts","../../../../node_modules/@types/node/cluster.d.ts","../../../../node_modules/@types/node/console.d.ts","../../../../node_modules/@types/node/constants.d.ts","../../../../node_modules/@types/node/crypto.d.ts","../../../../node_modules/@types/node/dgram.d.ts","../../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../../node_modules/@types/node/dns.d.ts","../../../../node_modules/@types/node/dns/promises.d.ts","../../../../node_modules/@types/node/domain.d.ts","../../../../node_modules/@types/node/events.d.ts","../../../../node_modules/@types/node/fs.d.ts","../../../../node_modules/@types/node/fs/promises.d.ts","../../../../node_modules/@types/node/http.d.ts","../../../../node_modules/@types/node/http2.d.ts","../../../../node_modules/@types/node/https.d.ts","../../../../node_modules/@types/node/inspector.d.ts","../../../../node_modules/@types/node/module.d.ts","../../../../node_modules/@types/node/net.d.ts","../../../../node_modules/@types/node/os.d.ts","../../../../node_modules/@types/node/path.d.ts","../../../../node_modules/@types/node/perf_hooks.d.ts","../../../../node_modules/@types/node/process.d.ts","../../../../node_modules/@types/node/punycode.d.ts","../../../../node_modules/@types/node/querystring.d.ts","../../../../node_modules/@types/node/readline.d.ts","../../../../node_modules/@types/node/repl.d.ts","../../../../node_modules/@types/node/stream.d.ts","../../../../node_modules/@types/node/stream/promises.d.ts","../../../../node_modules/@types/node/stream/consumers.d.ts","../../../../node_modules/@types/node/stream/web.d.ts","../../../../node_modules/@types/node/string_decoder.d.ts","../../../../node_modules/@types/node/test.d.ts","../../../../node_modules/@types/node/timers.d.ts","../../../../node_modules/@types/node/timers/promises.d.ts","../../../../node_modules/@types/node/tls.d.ts","../../../../node_modules/@types/node/trace_events.d.ts","../../../../node_modules/@types/node/tty.d.ts","../../../../node_modules/@types/node/url.d.ts","../../../../node_modules/@types/node/util.d.ts","../../../../node_modules/@types/node/v8.d.ts","../../../../node_modules/@types/node/vm.d.ts","../../../../node_modules/@types/node/wasi.d.ts","../../../../node_modules/@types/node/worker_threads.d.ts","../../../../node_modules/@types/node/zlib.d.ts","../../../../node_modules/@types/node/globals.global.d.ts","../../../../node_modules/@types/node/index.d.ts","../../../../node_modules/@types/graceful-fs/index.d.ts","../../../../node_modules/@types/istanbul-lib-coverage/index.d.ts","../../../../node_modules/@types/istanbul-lib-report/index.d.ts","../../../../node_modules/@types/istanbul-reports/index.d.ts","../../../../node_modules/chalk/index.d.ts","../../../../node_modules/@sinclair/typebox/typebox.d.ts","../../../../node_modules/@jest/schemas/build/index.d.ts","../../../../node_modules/pretty-format/build/index.d.ts","../../../../node_modules/jest-diff/build/index.d.ts","../../../../node_modules/jest-matcher-utils/build/index.d.ts","../../../../node_modules/@types/jest/index.d.ts","../../../../node_modules/@types/minimist/index.d.ts","../../../../node_modules/@types/normalize-package-data/index.d.ts","../../../../node_modules/pg-types/index.d.ts","../../../../node_modules/pg-protocol/dist/messages.d.ts","../../../../node_modules/pg-protocol/dist/serializer.d.ts","../../../../node_modules/pg-protocol/dist/parser.d.ts","../../../../node_modules/pg-protocol/dist/index.d.ts","../../../../node_modules/@types/pg/index.d.ts","../../../../node_modules/@types/pg-format/index.d.ts","../../../../node_modules/@types/prettier/index.d.ts","../../../../node_modules/@types/stack-utils/index.d.ts","../../../../node_modules/@types/yargs-parser/index.d.ts","../../../../node_modules/@types/yargs/index.d.ts"],"fileInfos":[{"version":"f5c28122bee592cfaf5c72ed7bcc47f453b79778ffa6e301f45d21a0970719d4","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9",{"version":"3f149f903dd20dfeb7c80e228b659f0e436532de772469980dbd00702cc05cc1","affectsGlobalScope":true},{"version":"1272277fe7daa738e555eb6cc45ded42cc2d0f76c07294142283145d49e96186","affectsGlobalScope":true},{"version":"7fac8cb5fc820bc2a59ae11ef1c5b38d3832c6d0dfaec5acdb5569137d09a481","affectsGlobalScope":true},{"version":"097a57355ded99c68e6df1b738990448e0bf170e606707df5a7c0481ff2427cd","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"181f1784c6c10b751631b24ce60c7f78b20665db4550b335be179217bacc0d5f","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"cd483c056da900716879771893a3c9772b66c3c88f8943b4205aec738a94b1d0","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"c37f8a49593a0030eecb51bbfa270e709bec9d79a6cc3bb851ef348d4e6b26f8","affectsGlobalScope":true},"f58c6d0669d1ee04b2fcb0e87fb949b6828602f3f29c7bf6c76a214f16fd50d5",{"version":"646aeb4fd36cec9c56dbe354720c8b555b6698ab688fd56784a52bea50631204","signature":"f9c304ad2d70238bd5859e6d74588f1411b7b615c9bcf4de29c0cfa0cd885a80"},{"version":"0072ed52c9d0b60303ddbc7cf8ff0a6cbb50e06e892adda62fe11ba9f983e6e3","signature":"c9c29a8ffd4cb138c52b0a9961aa8b8206c48e063374054677f4745a94a39f04"},"9b6d2a9f610aac2dc6c3fcc45a90dbbde0411dd677bdc956d76f484f397640f1","cc957354aa3c94c9961ebf46282cfde1e81d107fc5785a61f62c67f1dd3ac2eb","a46a2e69d12afe63876ec1e58d70e5dbee6d3e74132f4468f570c3d69f809f1c","93de1c6dab503f053efe8d304cb522bb3a89feab8c98f307a674a4fae04773e9","c7597e9b1b1eac80e5bca7d136321ab80804ff37f026bc84a8a8553904db9847","5426e62886b7be7806312d31a00e8f7dccd6fe63ba9bbefe99ee2eab29cc48a3",{"version":"64d4b35c5456adf258d2cf56c341e203a073253f229ef3208fc0d5020253b241","affectsGlobalScope":true},"0133ebdd17a823ae56861948870cde4dac18dd8818ab641039c85bbb720429e0","f3e604694b624fa3f83f6684185452992088f5efb2cf136b62474aa106d6f1b6","946bd1737d9412395a8f24414c70f18660b84a75a12b0b448e6eb1a2161d06dd","874d84ca5699231d5af2868fef01fc63f948bd83be928881479db48508f92ca0","9122ed7070e054b73ebab37c2373a196def2d90e7d1a9a7fcd9d46b0e51fae78","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"77f0b5c6a193a699c9f7d7fb0578e64e562d271afa740783665d2a827104a873","affectsGlobalScope":true},"21a167fec8f933752fb8157f06d28fab6817af3ad9b0bdb1908a10762391eab9",{"version":"002d6d5f044365b3fbfba0ba9be3bb57cac09b81547c8df4b0795755d2081d90","affectsGlobalScope":true},"0c0cee62cb619aed81133b904f644515ba3064487002a7da83fd8aa07b1b4abd","5a94487653355b56018122d92392beb2e5f4a6c63ba5cef83bbe1c99775ef713",{"version":"d5135ad93b33adcce80b18f8065087934cdc1730d63db58562edcf017e1aad9b","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","34ec1daf3566f26c43dbab380af0de1aac29166e57e4f9ef379a2f154e0cb290","bb9c4ffa5e6290c6980b63c815cdd1625876dadb2efaf77edbe82984be93e55e","75ecef44f126e2ae018b4abbd85b6e8a2e2ba1638ebec56cc64274643ce3567b","f30bb836526d930a74593f7b0f5c1c46d10856415a8f69e5e2fc3db80371e362","14b5aa23c5d0ae1907bc696ac7b6915d88f7d85799cc0dc2dcf98fbce2c5a67c","5c439dafdc09abe4d6c260a96b822fa0ba5be7203c71a63ab1f1423cd9e838ea",{"version":"bae4ea23beb8397755b935cb84d3cdc6cdb0b1b4a329b90de9fc6c8774d71994","affectsGlobalScope":true},"cec36af22f514322f870e81d30675c78df82ae8bf4863f5fd4e4424c040c678d","c57870f6664fd657ec2cf096bbb043b9556b0228ec0c12dd54193361ca563ea1","aeee0090b38de0dd47ca9a79ad5c2d156e3e09d92306719b0b45a3e96098e564","acfbb5aaef964e1d441f961a1846197f03241dba3c63b1e4d1903684888ef465","09416dd69576b03a3f485adf329a02f043e4a481e060ef5b208194e488d31fd9","8acf99b1c8682276a63ea5bb68433782715892726b97e4604a415e4e56bce41c",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"9499ba4dcd1ee0596d8c98d01341bc874840c5291156513bda667fecad54d5be","a907bf91df26df2400858ef75f749498fb5cf00062bf90a737ac3949cc07978d","cb92bc2e42b261e4299025756f1beb826b3d9666a3f0d46f8a7254ca512f57e4","e795a96de48dd2fbf83b1e29ecfae8e1dd428b99aa3508962c98679862e129a0",{"version":"59104b2e80c588b813d03d3a45f57117ca4601ae3fc216c5ffbcbafc4effc1c5","affectsGlobalScope":true},"5153a2fd150e46ce57bb3f8db1318d33f6ad3261ed70ceeff92281c0608c74a3","d1a78a3c5708807e8de3e399f91df4797c62e44b02195eefc2209b2e713e54ee","8c4c1a64db28930732033c31418f817dcb9d09d706766707ae6d38f23faf0c53","25846d43937c672bab7e8195f3d881f93495df712ee901860effc109918938cc","556bf5c36deb62cffa1bf697c1789fe008ec82db0273025001db66732714e9d9","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","23b89798789dffbd437c0c423f5d02d11f9736aea73d6abf16db4f812ff36eda","653968fc1b35c5eb3d273d36fac1c1dc66f9537edf28f33485b8776bd956e23d",{"version":"970a90f76d4d219ad60819d61f5994514087ba94c985647a3474a5a3d12714ed","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","a381f079c4804442f179d742fdb2e495fe28d67a47cac673485f75ae2e77aeca","3c13ef48634e7b5012fcf7e8fce7496352c2d779a7201389ca96a2a81ee4314d","5d0a25ec910fa36595f85a67ac992d7a53dd4064a1ba6aea1c9f14ab73a023f2",{"version":"bfe39beb986d2a2e512c091cbe924f1c415bc65de54de0e2f6a0dc6f84c183d9","affectsGlobalScope":true},"2d526e6f21d8cc66ac11ada32874e95ae88d870c6c9d3d9d4e03b1d1f9ad7b8e","06d7c42d256f0ce6afe1b2b6cfbc97ab391f29dadb00dd0ae8e8f23f5bc916c3","ec4bd1b200670fb567920db572d6701ed42a9641d09c4ff6869768c8f81b404c","e59a892d87e72733e2a9ca21611b9beb52977be2696c7ba4b216cbbb9a48f5aa","d2ec52f565f0570e90b659811347bd689f8c6039b11eaaccd0f243759d46da6e","8a300fa9b698845a1f9c41ecbe2c5966634582a8e2020d51abcace9b55aa959e",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"9c3df5971dc261aa29f25fdfcf7e8cfa248ff95a3d09ae4a6b81b1b09473f80f","3ebae8c00411116a66fca65b08228ea0cf0b72724701f9b854442100aab55aba","8b06ac3faeacb8484d84ddb44571d8f410697f98d7bfa86c0fda60373a9f5215","7eb06594824ada538b1d8b48c3925a83e7db792f47a081a62cf3e5c4e23cf0ee","f5638f7c2f12a9a1a57b5c41b3c1ea7db3876c003bab68e6a57afd6bcc169af0","0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","d982cdd2610155b3cbcbfa62ccabcf2d2b739f821518ef113348d160ef0010d9","ffcc5500e77223169833fc6eb59b3a507944a1f89574e0a1276b0ea7fc22c4a4","22f13de9e2fe5f0f4724797abd3d34a1cdd6e47ef81fc4933fea3b8bf4ad524b","e3ba509d3dce019b3190ceb2f3fc88e2610ab717122dabd91a9efaa37804040d","cda0cb09b995489b7f4c57f168cd31b83dcbaa7aad49612734fb3c9c73f6e4f2",{"version":"1de1ad6a1929317171d8cfcd55bb2732257680c1bf89bcd53e1d46a4d8dbda22","affectsGlobalScope":true},"209e814e8e71aec74f69686a9506dd7610b97ab59dcee9446266446f72a76d05","6fa0008bf91a4cc9c8963bace4bba0bd6865cbfa29c3e3ccc461155660fb113a","f60e3e3060207ac982da13363181fd7ee4beecc19a7c569f0d6bb034331066c2","17230b34bb564a3a2e36f9d3985372ccab4ad1722df2c43f7c5c2b553f68e5db","87ed0f84f0691d5c724b23159db96342e6b04ac69201b02c65936f4281ce1fbe","13868c5792808236b17dfe2803eafce911ea4d09d3b2fda95391891a494f988f","0dfe35191a04e8f9dc7caeb9f52f2ee07402736563d12cbccd15fb5f31ac877f","fa5c2d3fcd8e227e180815df0a0903ed4b116400452af8a75ac5b68e5e1de9da","e0fa568e94e16b6ee842d293e387f1b9620686a7f975371322429ce3d2ce0313","93c4fc5b5237c09bc9ed65cb8f0dc1d89034406ab40500b89701341994897142","b0d10e46cfe3f6c476b69af02eaa38e4ccc7430221ce3109ae84bb9fb8282298","70e9a18da08294f75bf23e46c7d69e67634c0765d355887b9b41f0d959e1426e","5e19d765e36e4b673d8eeeec8d8fb65dafb17ba6202cc21e9172bac2bce0fd04"],"options":{"composite":true,"esModuleInterop":true,"module":1,"noImplicitAny":true,"noImplicitReturns":true,"noImplicitThis":true,"outDir":"./","strict":true,"strictNullChecks":true,"strictPropertyInitialization":true,"target":7},"fileIdsList":[[48,103],[103],[103,116],[48,49,50,51,52,103],[48,50,103],[54,55,56,57,103],[58,103],[75,103,110],[103,112],[103,113],[103,118,120],[59,103],[62,103],[63,68,103],[64,74,75,82,91,102,103],[64,65,74,82,103],[66,103],[67,68,75,83,103],[68,91,99,103],[69,71,74,82,103],[70,103],[71,72,103],[73,74,103],[74,103],[74,75,76,91,102,103],[74,75,76,91,94,103],[103,107],[77,82,91,102,103],[74,75,77,78,82,91,99,102,103],[77,79,91,99,102,103],[59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109],[74,80,103],[81,102,103],[71,74,82,91,103],[83,103],[84,103],[62,85,103],[86,101,103,107],[87,103],[88,103],[74,89,103],[89,90,103,105],[74,91,92,93,94,103],[91,93,103],[91,92,103],[94,103],[95,103],[74,97,98,103],[97,98,103],[68,82,91,99,103],[100,103],[82,101,103],[63,77,88,102,103],[68,103],[91,103,104],[103,105],[103,106],[63,68,74,76,85,91,102,103,105,107],[91,103,108],[74,91,99,103,110,124,125,128,129],[103,133],[103,118],[103,115,119],[103,110,125,126,127],[103,110],[91,103,110,125],[103,117],[46,103],[46]],"referencedMap":[[50,1],[48,2],[117,3],[116,2],[53,4],[49,1],[51,5],[52,1],[54,2],[58,6],[55,7],[57,2],[111,8],[112,2],[113,9],[114,10],[121,11],[56,2],[122,2],[59,12],[60,12],[62,13],[63,14],[64,15],[65,16],[66,17],[67,18],[68,19],[69,20],[70,21],[71,22],[72,22],[73,23],[74,24],[75,25],[76,26],[61,27],[109,2],[77,28],[78,29],[79,30],[110,31],[80,32],[81,33],[82,34],[83,35],[84,36],[85,37],[86,38],[87,39],[88,40],[89,41],[90,42],[91,43],[93,44],[92,45],[94,46],[95,47],[96,2],[97,48],[98,49],[99,50],[100,51],[101,52],[102,53],[103,54],[104,55],[105,56],[106,57],[107,58],[108,59],[123,2],[130,2],[129,60],[131,2],[132,2],[133,2],[134,61],[115,2],[119,62],[120,63],[128,64],[125,65],[127,66],[126,65],[124,2],[118,67],[8,2],[9,2],[13,2],[12,2],[2,2],[14,2],[15,2],[16,2],[17,2],[18,2],[19,2],[20,2],[21,2],[3,2],[4,2],[25,2],[22,2],[23,2],[24,2],[26,2],[27,2],[28,2],[5,2],[29,2],[30,2],[31,2],[32,2],[6,2],[33,2],[34,2],[35,2],[36,2],[7,2],[37,2],[45,2],[42,2],[43,2],[38,2],[39,2],[40,2],[41,2],[1,2],[44,2],[11,2],[10,2],[46,2],[47,68]],"exportedModulesMap":[[50,1],[48,2],[117,3],[116,2],[53,4],[49,1],[51,5],[52,1],[54,2],[58,6],[55,7],[57,2],[111,8],[112,2],[113,9],[114,10],[121,11],[56,2],[122,2],[59,12],[60,12],[62,13],[63,14],[64,15],[65,16],[66,17],[67,18],[68,19],[69,20],[70,21],[71,22],[72,22],[73,23],[74,24],[75,25],[76,26],[61,27],[109,2],[77,28],[78,29],[79,30],[110,31],[80,32],[81,33],[82,34],[83,35],[84,36],[85,37],[86,38],[87,39],[88,40],[89,41],[90,42],[91,43],[93,44],[92,45],[94,46],[95,47],[96,2],[97,48],[98,49],[99,50],[100,51],[101,52],[102,53],[103,54],[104,55],[105,56],[106,57],[107,58],[108,59],[123,2],[130,2],[129,60],[131,2],[132,2],[133,2],[134,61],[115,2],[119,62],[120,63],[128,64],[125,65],[127,66],[126,65],[124,2],[118,67],[8,2],[9,2],[13,2],[12,2],[2,2],[14,2],[15,2],[16,2],[17,2],[18,2],[19,2],[20,2],[21,2],[3,2],[4,2],[25,2],[22,2],[23,2],[24,2],[26,2],[27,2],[28,2],[5,2],[29,2],[30,2],[31,2],[32,2],[6,2],[33,2],[34,2],[35,2],[36,2],[7,2],[37,2],[45,2],[42,2],[43,2],[38,2],[39,2],[40,2],[41,2],[1,2],[44,2],[11,2],[10,2],[47,69]],"semanticDiagnosticsPerFile":[50,48,117,116,53,49,51,52,54,58,55,57,111,112,113,114,121,56,122,59,60,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,61,109,77,78,79,110,80,81,82,83,84,85,86,87,88,89,90,91,93,92,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,123,130,129,131,132,133,134,115,119,120,128,125,127,126,124,118,8,9,13,12,2,14,15,16,17,18,19,20,21,3,4,25,22,23,24,26,27,28,5,29,30,31,32,6,33,34,35,36,7,37,45,42,43,38,39,40,41,1,44,11,10,46,47]},"version":"4.7.4"}
|
package/dist/es/db.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export declare class EntryBase {
|
|
2
|
+
constructor(from?: Partial<EntryBase>);
|
|
3
|
+
construct(): void;
|
|
4
|
+
postLoad(): void;
|
|
5
|
+
postRemove(): void;
|
|
6
|
+
postSave(): void;
|
|
7
|
+
preLoad(): void;
|
|
8
|
+
preRemove(): void;
|
|
9
|
+
preSave(): void;
|
|
10
|
+
remove(): Promise<boolean>;
|
|
11
|
+
save(): Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export declare type ForeignKeyActions = "cascade" | "no action" | "restrict" | "set default" | "set null";
|
|
14
|
+
export interface ForeignKeyOptions {
|
|
15
|
+
onDelete?: ForeignKeyActions;
|
|
16
|
+
onUpdate?: ForeignKeyActions;
|
|
17
|
+
}
|
|
18
|
+
export interface Type<T, E> {
|
|
19
|
+
base: unknown;
|
|
20
|
+
entry?: E;
|
|
21
|
+
native?: T;
|
|
22
|
+
size?: number;
|
|
23
|
+
type: string;
|
|
24
|
+
foreignKey?: {
|
|
25
|
+
attributeName: string;
|
|
26
|
+
fieldName: string;
|
|
27
|
+
options?: ForeignKeyOptions;
|
|
28
|
+
tableName: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export declare class Type<T, E> {
|
|
32
|
+
constructor(from: Type<T, E>);
|
|
33
|
+
}
|
|
34
|
+
export interface Attribute<T, E> extends Type<T, E> {
|
|
35
|
+
attributeName: string;
|
|
36
|
+
defaultValue?: unknown;
|
|
37
|
+
fieldName: string;
|
|
38
|
+
modelName: string;
|
|
39
|
+
notNull: boolean;
|
|
40
|
+
tableName: string;
|
|
41
|
+
unique?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare class Attribute<T, E> extends Type<T, E> {
|
|
44
|
+
constructor(from: Attribute<T, E>);
|
|
45
|
+
}
|
|
46
|
+
export interface Constraint {
|
|
47
|
+
attribute: Attribute<unknown, unknown>;
|
|
48
|
+
constraintName: string;
|
|
49
|
+
type: "f" | "u";
|
|
50
|
+
}
|
|
51
|
+
export interface Index {
|
|
52
|
+
fields: string[];
|
|
53
|
+
indexName: string;
|
|
54
|
+
type: "btree" | "hash";
|
|
55
|
+
unique: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface ITable {
|
|
58
|
+
attributes: Attribute<unknown, unknown>[];
|
|
59
|
+
autoIncrement: boolean;
|
|
60
|
+
constraints: Constraint[];
|
|
61
|
+
indexes: Index[];
|
|
62
|
+
model: {
|
|
63
|
+
load: (where: any, order?: string[], tx?: Transaction) => Promise<EntryBase[]>;
|
|
64
|
+
};
|
|
65
|
+
parent?: Attribute<unknown, unknown>;
|
|
66
|
+
pk: Attribute<unknown, unknown>;
|
|
67
|
+
sync: boolean;
|
|
68
|
+
tableName: string;
|
|
69
|
+
}
|
|
70
|
+
declare const Table_base: new (defaults?: ITable | undefined) => ITable;
|
|
71
|
+
export declare class Table extends Table_base {
|
|
72
|
+
autoIncrementOwn?: boolean;
|
|
73
|
+
oid?: number;
|
|
74
|
+
findField(name: string): Attribute<unknown, unknown>;
|
|
75
|
+
}
|
|
76
|
+
export declare abstract class DB<T extends Transaction> {
|
|
77
|
+
tables: Table[];
|
|
78
|
+
protected log: (message: string) => void;
|
|
79
|
+
protected sync: boolean;
|
|
80
|
+
abstract connect(): Promise<void>;
|
|
81
|
+
abstract end(): Promise<void>;
|
|
82
|
+
constructor(log: (message: string) => void);
|
|
83
|
+
findTable(name: string): Table;
|
|
84
|
+
protected indexesEq(a: Index, b: Index): boolean;
|
|
85
|
+
syncDataBase(): Promise<void>;
|
|
86
|
+
protected syncLog(message: string): void;
|
|
87
|
+
abstract begin(): Promise<T>;
|
|
88
|
+
abstract escape(value: unknown): string;
|
|
89
|
+
abstract load(tableName: string, attributes: Record<string, string>, pk: Attribute<unknown, unknown>, model: new () => EntryBase, table: Table): (where: string, order?: string | string[], limit?: number, tx?: Transaction, lock?: boolean) => Promise<EntryBase[]>;
|
|
90
|
+
abstract remove(tableName: string, pk: Attribute<unknown, unknown>): (this: EntryBase & Record<string, unknown>) => Promise<boolean>;
|
|
91
|
+
abstract save(tableName: string, attributes: Record<string, string>, pk: Attribute<unknown, unknown>): (this: EntryBase & Record<string, unknown>) => Promise<boolean>;
|
|
92
|
+
abstract dropConstraints(table: Table): Promise<number[]>;
|
|
93
|
+
abstract dropFields(table: Table): Promise<void>;
|
|
94
|
+
abstract dropIndexes(table: Table, constraintIndexes: number[]): Promise<void>;
|
|
95
|
+
abstract syncConstraints(table: Table): Promise<void>;
|
|
96
|
+
abstract syncFields(table: Table): Promise<void>;
|
|
97
|
+
abstract syncIndexes(table: Table): Promise<void>;
|
|
98
|
+
abstract syncSequence(table: Table): Promise<void>;
|
|
99
|
+
abstract syncTable(table: Table): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
export declare class Transaction {
|
|
102
|
+
private entries;
|
|
103
|
+
protected log: (message: string) => void;
|
|
104
|
+
constructor(log: (message: string) => void);
|
|
105
|
+
addEntry(entry: EntryBase): void;
|
|
106
|
+
clean(): void;
|
|
107
|
+
commit(): Promise<void>;
|
|
108
|
+
rollback(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
export {};
|