sedentary 0.0.40 → 0.0.43

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.
@@ -1,141 +0,0 @@
1
- import { Attribute, DB, EntryBase, ForeignKeyOptions, Natural, Transaction, Type } from "./db";
2
- export { Attribute, DB, EntryBase, ForeignKeyActions, ForeignKeyOptions, Index, Natural, Table, Transaction, Type } from "./db";
3
- export declare type TypeDefinition<N extends Natural, E> = (() => Type<N, E>) | Type<N, E>;
4
- export interface AttributeOptions<N extends Natural, E> {
5
- defaultValue?: N;
6
- fieldName?: string;
7
- notNull?: boolean;
8
- type: TypeDefinition<N, E>;
9
- unique?: boolean;
10
- }
11
- export declare type AttributeDefinition<N extends Natural, E> = TypeDefinition<N, E> | AttributeOptions<N, E>;
12
- export declare type AttributesDefinition = {
13
- [key: string]: AttributeDefinition<Natural, unknown>;
14
- };
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 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 extends Natural, 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<Natural, EntryBase>;
43
- primaryKey?: string;
44
- }
45
- declare type ConditionAttribute<N extends Natural> = N | ["=" | ">" | "<" | ">=" | "<=" | "<>", N] | ["IN", N[]] | ["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<Natural, 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<N extends Natural, A extends AttributesDefinition, EA extends Record<string, Natural>, EM extends EntryBase, E extends EntryBase> = (new (from?: Partial<EA>, tx?: Transaction) => E) & Attribute<N, 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<N extends Natural, A extends AttributesDefinition, EM extends EntryBase> = ModelBase<N, A, EntryBaseAttributes<A>, EM, EntryBaseAttributes<A> & EM>;
88
- declare type ModelStd = Attribute<Natural, 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<N extends Natural, E extends EntryBase>(attribute: Attribute<N, E>, options?: ForeignKeyOptions): Type<N, E>;
118
- INT(size?: number): Type<number, unknown>;
119
- INT8(): Type<BigInt, unknown>;
120
- NUMBER(): Type<number, unknown>;
121
- VARCHAR(size?: number): Type<string, unknown>;
122
- private checkDB;
123
- private checkOrderBy;
124
- private checkSize;
125
- private createWhere;
126
- connect(sync?: boolean): Promise<void>;
127
- sync(): Promise<void>;
128
- end(): Promise<void>;
129
- begin(): Promise<T>;
130
- escape(value: Natural): string;
131
- model<A extends AttributesDefinition, B extends boolean, K extends string, P extends ModelStd, EM extends EntryMethods<A, P>>(modelName: string, attributes: A, options?: BaseModelOptions & {
132
- int8id?: B;
133
- parent?: P;
134
- primaryKey?: K | keyof A;
135
- }): Model<K extends keyof A ? Native<A[K]> : KeyType<B, P>, ModelAttributes<A, B, K, P>, EM>;
136
- 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 & {
137
- int8id?: B;
138
- parent?: P;
139
- primaryKey?: K | keyof A;
140
- }, 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>;
141
- }
package/jest.config.js DELETED
@@ -1,8 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- module.exports = {
3
- collectCoverageFrom: ["db.ts", "index.ts"],
4
- preset: "ts-jest",
5
- testEnvironment: "jest-environment-node-single-context",
6
- testPathIgnorePatterns: ["/node_modules/", "/sedentary-pg/"],
7
- testSequencer: "./testSequencer.js"
8
- };
package/testSequencer.js DELETED
@@ -1,20 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2
- const Sequencer = require("@jest/test-sequencer").default;
3
-
4
- class CustomSequencer extends Sequencer {
5
- shard(tests, { shardIndex, shardCount }) {
6
- const shardSize = Math.ceil(tests.length / shardCount);
7
- const shardStart = shardSize * (shardIndex - 1);
8
- const shardEnd = shardSize * shardIndex;
9
-
10
- return [...tests].sort((a, b) => (a.path > b.path ? 1 : -1)).slice(shardStart, shardEnd);
11
- }
12
-
13
- sort(tests) {
14
- const copyTests = Array.from(tests);
15
-
16
- return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1));
17
- }
18
- }
19
-
20
- module.exports = CustomSequencer;