sedentary 0.0.54 → 0.1.1
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 +47 -28
- package/dist/cjs/db.js +19 -14
- package/dist/cjs/index.js +141 -89
- package/dist/cjs/package.json +1 -0
- package/dist/es/db.js +16 -11
- package/dist/es/index.js +140 -89
- package/dist/types/db.d.ts +27 -23
- package/dist/types/index.d.ts +55 -37
- package/package.json +8 -31
package/dist/types/index.d.ts
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import { Attribute, DB, EntryBase, ForeignKeyOptions, Transaction, Type } from "./db";
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export interface AttributeOptions<T, E> {
|
|
2
|
+
export { Attribute, base, DB, deepCopy, deepDiff, EntryBase, ForeignKeyActions, ForeignKeyOptions, Index, loaded, size, Table, Transaction, transaction, TxAction, Type } from "./db";
|
|
3
|
+
export interface AttributeOptions<T, N extends boolean> {
|
|
5
4
|
defaultValue?: T;
|
|
6
5
|
fieldName?: string;
|
|
7
|
-
notNull?:
|
|
8
|
-
type: TypeDefinition<T, E>;
|
|
6
|
+
notNull?: N;
|
|
9
7
|
unique?: boolean;
|
|
10
8
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
export interface AttributeOptionsSize<T, N extends boolean> extends AttributeOptions<T, N> {
|
|
10
|
+
size?: number;
|
|
11
|
+
}
|
|
12
|
+
type NotNull<O> = O extends {
|
|
13
|
+
notNull: true;
|
|
14
|
+
} ? true : false;
|
|
15
|
+
type AttributesDefinitionBase = {
|
|
16
|
+
[key: string]: [unknown, boolean, unknown];
|
|
17
|
+
};
|
|
18
|
+
export type AttributesDefinition<N extends AttributesDefinitionBase = AttributesDefinitionBase> = keyof N extends never ? {
|
|
19
|
+
[s: string]: Type<unknown, boolean, unknown>;
|
|
20
|
+
} : {
|
|
21
|
+
[key in keyof N]: Type<N[key][0], N[key][1], N[key][2]>;
|
|
14
22
|
};
|
|
15
23
|
declare const attributes: unique symbol;
|
|
16
24
|
declare const methods: unique symbol;
|
|
17
|
-
type ForeignKeysAttributes<T, k> = T extends
|
|
18
|
-
type ForeignKeys<A extends AttributesDefinition> = {
|
|
25
|
+
type ForeignKeysAttributes<T, k> = T extends Type<unknown, boolean, infer E> ? (E extends EntryBase ? k : never) : never;
|
|
26
|
+
type ForeignKeys<A extends AttributesDefinition> = Exclude<{
|
|
19
27
|
[a in keyof A]?: ForeignKeysAttributes<A[a], a>;
|
|
20
|
-
}[keyof A]
|
|
21
|
-
type
|
|
22
|
-
type Native__<T> = T extends () => Type<infer N, infer E> ? Native___<Type<N, E>> : Native___<T>;
|
|
23
|
-
type Native_<T, N, E> = T extends {
|
|
24
|
-
notNull: true;
|
|
25
|
-
} ? Native___<Type<N, E>> : Native___<Type<N, E>> | null;
|
|
26
|
-
type Native<T> = T extends AttributeOptions<infer N, infer E> ? Native_<T, N, E> : Native__<T> | null;
|
|
28
|
+
}[keyof A], undefined>;
|
|
29
|
+
type Native<T> = T extends Type<infer N, infer NN, unknown> ? (NN extends true ? N : N | null) : never;
|
|
27
30
|
export type IndexAttributes = string[] | string;
|
|
28
31
|
export interface IndexOptions {
|
|
29
32
|
attributes: IndexAttributes;
|
|
@@ -41,7 +44,7 @@ interface BaseModelOptions {
|
|
|
41
44
|
}
|
|
42
45
|
export interface ModelOptions extends BaseModelOptions {
|
|
43
46
|
int8id?: boolean;
|
|
44
|
-
parent?: Attribute<unknown, EntryBase>;
|
|
47
|
+
parent?: Attribute<unknown, boolean, EntryBase>;
|
|
45
48
|
primaryKey?: string;
|
|
46
49
|
}
|
|
47
50
|
type ConditionAttribute<T> = T | ["=" | ">" | "<" | ">=" | "<=" | "<>", T] | ["IN", T[]] | ["IS NULL"] | ["LIKE", string] | ["NOT"];
|
|
@@ -54,8 +57,8 @@ type Order<A extends AttributesDefinition> = Order_<A> | Order_<A>[];
|
|
|
54
57
|
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
55
58
|
type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
56
59
|
type BaseKeyType<B extends boolean> = IsUnion<B> extends true ? number : B extends true ? string : number;
|
|
57
|
-
type KeyType<B extends boolean, P extends ModelStd> = P extends new () => EntryBase ? (P extends Attribute<infer T, EntryBase> ? T : never) : BaseKeyType<B>;
|
|
58
|
-
type ForeignKey<A> = A extends
|
|
60
|
+
type KeyType<B extends boolean, P extends ModelStd> = P extends new () => EntryBase ? (P extends Attribute<infer T, boolean, EntryBase> ? T : never) : BaseKeyType<B>;
|
|
61
|
+
type ForeignKey<A> = A extends Type<unknown, boolean, infer E> ? () => Promise<E> : never;
|
|
59
62
|
type EntryBaseAttributes<A extends AttributesDefinition> = {
|
|
60
63
|
[a in keyof A]: Native<A[a]>;
|
|
61
64
|
};
|
|
@@ -66,10 +69,7 @@ type EntryMethodsFK<A extends AttributesDefinition> = {
|
|
|
66
69
|
type EntryMethods<A extends AttributesDefinition, P extends ModelStd> = keyof EntryMethodsFK<A> extends never ? EntryMethodsBase<P> : EntryMethodsBase<P> & EntryMethodsFK<A>;
|
|
67
70
|
type ModelAttributesIf<A extends AttributesDefinition, T> = keyof A extends never ? T : T & A;
|
|
68
71
|
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[typeof attributes] : {
|
|
69
|
-
id:
|
|
70
|
-
notNull: true;
|
|
71
|
-
type: Type<BaseKeyType<B>, unknown>;
|
|
72
|
-
};
|
|
72
|
+
id: Type<BaseKeyType<B>, true, unknown>;
|
|
73
73
|
}>;
|
|
74
74
|
export interface ModelLoad<A extends AttributesDefinition, E extends EntryBase> {
|
|
75
75
|
load(where: Condition<A>, order?: Order<A>, limit?: number, tx?: Transaction, lock?: boolean): Promise<E[]>;
|
|
@@ -78,17 +78,17 @@ export interface ModelLoad<A extends AttributesDefinition, E extends EntryBase>
|
|
|
78
78
|
load(where: Condition<A>, tx: Transaction, lock?: boolean): Promise<E[]>;
|
|
79
79
|
cancel(where: Condition<A>, tx?: Transaction): Promise<number>;
|
|
80
80
|
}
|
|
81
|
-
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> & {
|
|
81
|
+
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, true, E> & {
|
|
82
82
|
[attributes]: A;
|
|
83
83
|
foreignKeys: Record<string, boolean>;
|
|
84
84
|
[methods]: EM;
|
|
85
85
|
parent?: ModelStd;
|
|
86
86
|
tableName: string;
|
|
87
87
|
} & {
|
|
88
|
-
[a in keyof A]: Attribute<Native<A[a]>, E>;
|
|
88
|
+
[a in keyof A]: Attribute<Native<A[a]>, boolean, E>;
|
|
89
89
|
} & ModelLoad<A, E>;
|
|
90
90
|
type Model<T, A extends AttributesDefinition, EM extends EntryBase> = ModelBase<T, A, EntryBaseAttributes<A>, EM, EntryBaseAttributes<A> & EM>;
|
|
91
|
-
type ModelStd = Attribute<unknown, EntryBase> & {
|
|
91
|
+
type ModelStd = Attribute<unknown, true, EntryBase> & {
|
|
92
92
|
[attributes]: AttributesDefinition;
|
|
93
93
|
foreignKeys: Record<string, boolean>;
|
|
94
94
|
[methods]: EntryBase;
|
|
@@ -108,6 +108,12 @@ export interface SedentaryOptions {
|
|
|
108
108
|
log?: ((message: string) => void) | null;
|
|
109
109
|
sync?: boolean;
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Converts a JavaScript name to the default SQL name (snake_case).
|
|
113
|
+
* Uppercase letters become lowercase preceded by underscore, except the first character
|
|
114
|
+
* which is only lowercased without underscore.
|
|
115
|
+
*/
|
|
116
|
+
export declare function toSqlName(name: string): string;
|
|
111
117
|
export declare class Sedentary<D extends DB<T>, T extends Transaction> {
|
|
112
118
|
protected autoSync: boolean;
|
|
113
119
|
protected db: D;
|
|
@@ -115,16 +121,28 @@ export declare class Sedentary<D extends DB<T>, T extends Transaction> {
|
|
|
115
121
|
protected log: (message: string) => void;
|
|
116
122
|
private models;
|
|
117
123
|
constructor(options?: SedentaryOptions);
|
|
118
|
-
Boolean(): Type<boolean, unknown>;
|
|
119
|
-
DateTime(): Type<Date, unknown>;
|
|
120
|
-
FKey<T, E extends EntryBase>(attribute: Attribute<T, E>, options?: ForeignKeyOptions): Type<T, E>;
|
|
121
|
-
Float(
|
|
122
|
-
Int(
|
|
123
|
-
Int8(): Type<bigint, unknown>;
|
|
124
|
-
JSON<T>(): Type<T, unknown>;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
Boolean<O extends AttributeOptions<boolean, boolean> | undefined = undefined>(options?: O): Type<boolean, NotNull<O>, unknown>;
|
|
125
|
+
DateTime<O extends AttributeOptions<Date, boolean> | undefined = undefined>(options?: O): Type<Date, NotNull<O>, unknown>;
|
|
126
|
+
FKey<T, E extends EntryBase>(attribute: Attribute<T, boolean, E>, options?: ForeignKeyOptions): Type<T, boolean, E>;
|
|
127
|
+
Float<O extends AttributeOptionsSize<number, boolean> | undefined = undefined>(options?: O): Type<number, NotNull<O>, unknown>;
|
|
128
|
+
Int<O extends AttributeOptionsSize<number, boolean> | undefined = undefined>(options?: O): Type<number, NotNull<O>, unknown>;
|
|
129
|
+
Int8<O extends AttributeOptions<bigint, boolean> | undefined = undefined>(options?: O): Type<bigint, NotNull<O>, unknown>;
|
|
130
|
+
JSON<T = unknown>(): Type<T, false, unknown>;
|
|
131
|
+
JSON<T = unknown>(options: {
|
|
132
|
+
notNull: true;
|
|
133
|
+
} & AttributeOptions<T, boolean>): Type<T, true, unknown>;
|
|
134
|
+
JSON<T = unknown>(options: AttributeOptions<T, boolean>): Type<T, boolean, unknown>;
|
|
135
|
+
Number<O extends AttributeOptions<number, boolean> | undefined = undefined>(options?: O): Type<number, NotNull<O>, unknown>;
|
|
136
|
+
None<T = unknown>(): Type<T, false, unknown>;
|
|
137
|
+
None<T = unknown>(options: {
|
|
138
|
+
notNull: true;
|
|
139
|
+
} & AttributeOptions<unknown, boolean>): Type<T, true, unknown>;
|
|
140
|
+
None<T = unknown>(options: AttributeOptions<unknown, boolean>): Type<T, boolean, unknown>;
|
|
141
|
+
VarChar<S extends string = string>(): Type<S, false, unknown>;
|
|
142
|
+
VarChar<S extends string = string>(options: {
|
|
143
|
+
notNull: true;
|
|
144
|
+
} & AttributeOptionsSize<S, boolean>): Type<S, true, unknown>;
|
|
145
|
+
VarChar<S extends string = string>(options: AttributeOptionsSize<S, boolean>): Type<S, boolean, unknown>;
|
|
128
146
|
private checkDB;
|
|
129
147
|
private checkOrderBy;
|
|
130
148
|
private checkSize;
|
package/package.json
CHANGED
|
@@ -7,28 +7,26 @@
|
|
|
7
7
|
],
|
|
8
8
|
"description": "The ORM which never needs to migrate",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
10
|
+
"node": ">=20.19"
|
|
11
11
|
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
12
15
|
"funding": {
|
|
13
16
|
"url": "https://blockchain.info/address/1Md9WFAHrXTb3yPBwQWmUfv2RmzrtbHioB"
|
|
14
17
|
},
|
|
15
|
-
"homepage": "https://github.com/iccicci/sedentary/packages/sedentary#readme",
|
|
18
|
+
"homepage": "https://github.com/iccicci/sedentary/tree/master/packages/sedentary#readme",
|
|
16
19
|
"keywords": [
|
|
17
20
|
"DB",
|
|
18
21
|
"ORM",
|
|
19
22
|
"database",
|
|
20
23
|
"migration",
|
|
21
|
-
"
|
|
22
|
-
"postgresql",
|
|
23
|
-
"sqlite"
|
|
24
|
+
"postgresql"
|
|
24
25
|
],
|
|
25
26
|
"license": "MIT",
|
|
26
27
|
"main": "./dist/cjs/index.js",
|
|
27
28
|
"module": "./dist/es/index.js",
|
|
28
29
|
"name": "sedentary",
|
|
29
|
-
"optionalDependencies": {
|
|
30
|
-
"fsevents": "^2.3.3"
|
|
31
|
-
},
|
|
32
30
|
"readmeFilename": "README.md",
|
|
33
31
|
"repository": {
|
|
34
32
|
"type": "git",
|
|
@@ -36,30 +34,9 @@
|
|
|
36
34
|
},
|
|
37
35
|
"scripts": {
|
|
38
36
|
"build": "make build",
|
|
39
|
-
"coverage": "jest --coverage --no-cache --runInBand",
|
|
40
37
|
"deploy": "make deploy",
|
|
41
|
-
"
|
|
42
|
-
"preinstall": "if [ -f Makefile ] ; then make ; fi",
|
|
43
|
-
"pretest": "make pretest",
|
|
44
|
-
"test": "jest --no-cache --runInBand"
|
|
45
|
-
},
|
|
46
|
-
"tsd": {
|
|
47
|
-
"compilerOptions": {
|
|
48
|
-
"alwaysStrict": true,
|
|
49
|
-
"composite": false,
|
|
50
|
-
"esModuleInterop": true,
|
|
51
|
-
"moduleResolution": "Node",
|
|
52
|
-
"noImplicitAny": true,
|
|
53
|
-
"noImplicitReturns": true,
|
|
54
|
-
"noImplicitThis": true,
|
|
55
|
-
"strict": true,
|
|
56
|
-
"strictBindCallApply": true,
|
|
57
|
-
"strictFunctionTypes": true,
|
|
58
|
-
"strictNullChecks": true,
|
|
59
|
-
"strictPropertyInitialization": true,
|
|
60
|
-
"target": "ESNext"
|
|
61
|
-
}
|
|
38
|
+
"preinstall": "if [ -f Makefile ] ; then make ; fi"
|
|
62
39
|
},
|
|
63
40
|
"types": "./dist/types/index.d.ts",
|
|
64
|
-
"version": "0.
|
|
41
|
+
"version": "0.1.1"
|
|
65
42
|
}
|