sedentary 0.0.51 → 0.0.53
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/dist/cjs/db.js +3 -0
- package/dist/es/db.js +3 -0
- package/dist/types/db.d.ts +2 -1
- package/dist/types/index.d.ts +34 -34
- package/package.json +1 -1
package/dist/cjs/db.js
CHANGED
|
@@ -57,6 +57,9 @@ function autoImplement() {
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
class Table extends autoImplement() {
|
|
60
|
+
findAttribute(name) {
|
|
61
|
+
return this.attributes.filter(_ => _.attributeName === name)[0];
|
|
62
|
+
}
|
|
60
63
|
findField(name) {
|
|
61
64
|
return this.attributes.filter(_ => _.fieldName === name)[0];
|
|
62
65
|
}
|
package/dist/es/db.js
CHANGED
|
@@ -53,6 +53,9 @@ function autoImplement() {
|
|
|
53
53
|
export class Table extends autoImplement() {
|
|
54
54
|
autoIncrementOwn;
|
|
55
55
|
oid;
|
|
56
|
+
findAttribute(name) {
|
|
57
|
+
return this.attributes.filter(_ => _.attributeName === name)[0];
|
|
58
|
+
}
|
|
56
59
|
findField(name) {
|
|
57
60
|
return this.attributes.filter(_ => _.fieldName === name)[0];
|
|
58
61
|
}
|
package/dist/types/db.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class EntryBase {
|
|
|
21
21
|
remove(): Promise<boolean>;
|
|
22
22
|
save(): Promise<boolean>;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
24
|
+
export type ForeignKeyActions = "cascade" | "no action" | "restrict" | "set default" | "set null";
|
|
25
25
|
export interface ForeignKeyOptions {
|
|
26
26
|
onDelete?: ForeignKeyActions;
|
|
27
27
|
onUpdate?: ForeignKeyActions;
|
|
@@ -82,6 +82,7 @@ declare const Table_base: new (defaults?: ITable | undefined) => ITable;
|
|
|
82
82
|
export declare class Table extends Table_base {
|
|
83
83
|
autoIncrementOwn?: boolean;
|
|
84
84
|
oid?: number;
|
|
85
|
+
findAttribute(name: string): Attribute<unknown, unknown>;
|
|
85
86
|
findField(name: string): Attribute<unknown, unknown>;
|
|
86
87
|
}
|
|
87
88
|
export declare abstract class DB<T extends Transaction> {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Attribute, DB, EntryBase, ForeignKeyOptions, Transaction, Type } from "./db";
|
|
2
2
|
export { Action, Attribute, base, DB, deepCopy, deepDiff, EntryBase, ForeignKeyActions, ForeignKeyOptions, Index, loaded, size, Table, Transaction, transaction, Type } from "./db";
|
|
3
|
-
export
|
|
3
|
+
export type TypeDefinition<T, E> = (() => Type<T, E>) | Type<T, E>;
|
|
4
4
|
export interface AttributeOptions<T, E> {
|
|
5
5
|
defaultValue?: T;
|
|
6
6
|
fieldName?: string;
|
|
@@ -8,30 +8,30 @@ export interface AttributeOptions<T, E> {
|
|
|
8
8
|
type: TypeDefinition<T, E>;
|
|
9
9
|
unique?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
12
|
-
export
|
|
11
|
+
export type AttributeDefinition<T, E> = TypeDefinition<T, E> | AttributeOptions<T, E>;
|
|
12
|
+
export type AttributesDefinition = {
|
|
13
13
|
[key: string]: AttributeDefinition<unknown, unknown>;
|
|
14
14
|
};
|
|
15
15
|
declare const attributes: unique symbol;
|
|
16
16
|
declare const methods: unique symbol;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
type ForeignKeysAttributes<T, k> = T extends AttributeDefinition<unknown, infer E> ? (E extends EntryBase ? k : never) : never;
|
|
18
|
+
type ForeignKeys<A extends AttributesDefinition> = {
|
|
19
19
|
[a in keyof A]?: ForeignKeysAttributes<A[a], a>;
|
|
20
20
|
}[keyof A];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
type Native___<T> = T extends Type<infer N, unknown> ? N : never;
|
|
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
24
|
notNull: true;
|
|
25
25
|
} ? Native___<Type<N, E>> : Native___<Type<N, E>> | null;
|
|
26
|
-
|
|
27
|
-
export
|
|
26
|
+
type Native<T> = T extends AttributeOptions<infer N, infer E> ? Native_<T, N, E> : Native__<T> | null;
|
|
27
|
+
export type IndexAttributes = string[] | string;
|
|
28
28
|
export interface IndexOptions {
|
|
29
29
|
attributes: IndexAttributes;
|
|
30
30
|
type?: "btree" | "hash";
|
|
31
31
|
unique?: boolean;
|
|
32
32
|
}
|
|
33
|
-
export
|
|
34
|
-
export
|
|
33
|
+
export type IndexDefinition = IndexAttributes | IndexOptions;
|
|
34
|
+
export type IndexesDefinition = {
|
|
35
35
|
[key: string]: IndexDefinition;
|
|
36
36
|
};
|
|
37
37
|
interface BaseModelOptions {
|
|
@@ -44,28 +44,28 @@ export interface ModelOptions extends BaseModelOptions {
|
|
|
44
44
|
parent?: Attribute<unknown, EntryBase>;
|
|
45
45
|
primaryKey?: string;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
type ConditionAttribute<T> = T | ["=" | ">" | "<" | ">=" | "<=" | "<>", T] | ["IN", T[]] | ["IS NULL"] | ["LIKE", string] | ["NOT"];
|
|
48
|
+
type ConditionBase<A extends AttributesDefinition> = string | {
|
|
49
49
|
[a in keyof A]?: ConditionAttribute<Native<A[a]>>;
|
|
50
50
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
type Condition<A extends AttributesDefinition> = ConditionBase<A> | ["NOT", Condition<A>] | ["AND", ...Condition<A>[]] | ["OR", ...Condition<A>[]];
|
|
52
|
+
type Order_<A extends AttributesDefinition> = keyof A | `-${string & keyof A}`;
|
|
53
|
+
type Order<A extends AttributesDefinition> = Order_<A> | Order_<A>[];
|
|
54
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
55
|
+
type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
56
|
+
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 AttributeDefinition<unknown, infer E> ? () => Promise<E> : never;
|
|
59
|
+
type EntryBaseAttributes<A extends AttributesDefinition> = {
|
|
60
60
|
[a in keyof A]: Native<A[a]>;
|
|
61
61
|
};
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
type EntryMethodsBase<P extends ModelStd> = P extends new () => EntryBase ? P[typeof methods] : EntryBase;
|
|
63
|
+
type EntryMethodsFK<A extends AttributesDefinition> = {
|
|
64
64
|
[a in ForeignKeys<A> & string as `${a}Load`]: ForeignKey<A[a]>;
|
|
65
65
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
type EntryMethods<A extends AttributesDefinition, P extends ModelStd> = keyof EntryMethodsFK<A> extends never ? EntryMethodsBase<P> : EntryMethodsBase<P> & EntryMethodsFK<A>;
|
|
67
|
+
type ModelAttributesIf<A extends AttributesDefinition, T> = keyof A extends never ? T : T & A;
|
|
68
|
+
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
69
|
id: {
|
|
70
70
|
notNull: true;
|
|
71
71
|
type: Type<BaseKeyType<B>, unknown>;
|
|
@@ -78,7 +78,7 @@ 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
|
-
|
|
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> & {
|
|
82
82
|
[attributes]: A;
|
|
83
83
|
foreignKeys: Record<string, boolean>;
|
|
84
84
|
[methods]: EM;
|
|
@@ -87,20 +87,20 @@ declare type ModelBase<T, A extends AttributesDefinition, EA extends Record<stri
|
|
|
87
87
|
} & {
|
|
88
88
|
[a in keyof A]: Attribute<Native<A[a]>, E>;
|
|
89
89
|
} & ModelLoad<A, E>;
|
|
90
|
-
|
|
91
|
-
|
|
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> & {
|
|
92
92
|
[attributes]: AttributesDefinition;
|
|
93
93
|
foreignKeys: Record<string, boolean>;
|
|
94
94
|
[methods]: EntryBase;
|
|
95
95
|
parent?: ModelStd;
|
|
96
96
|
};
|
|
97
|
-
export
|
|
98
|
-
export
|
|
97
|
+
export type Entry<M> = M extends new () => infer E ? E : never;
|
|
98
|
+
export type OrderBy<M> = M extends {
|
|
99
99
|
load(where: unknown, order?: infer T): void;
|
|
100
100
|
load(where: unknown, limit?: number): void;
|
|
101
101
|
load(where: unknown, tx?: Transaction): void;
|
|
102
102
|
} ? Exclude<T, undefined> : never;
|
|
103
|
-
export
|
|
103
|
+
export type Where<M> = M extends {
|
|
104
104
|
load(where: infer T): void;
|
|
105
105
|
} ? T : never;
|
|
106
106
|
export interface SedentaryOptions {
|
package/package.json
CHANGED