@bunnykit/orm 0.1.0
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/LICENSE +21 -0
- package/README.md +904 -0
- package/dist/bin/bunny.d.ts +2 -0
- package/dist/bin/bunny.js +108 -0
- package/dist/src/connection/Connection.d.ts +13 -0
- package/dist/src/connection/Connection.js +49 -0
- package/dist/src/index.d.ts +20 -0
- package/dist/src/index.js +18 -0
- package/dist/src/migration/Migration.d.ts +4 -0
- package/dist/src/migration/Migration.js +2 -0
- package/dist/src/migration/MigrationCreator.d.ts +5 -0
- package/dist/src/migration/MigrationCreator.js +39 -0
- package/dist/src/migration/Migrator.d.ts +21 -0
- package/dist/src/migration/Migrator.js +137 -0
- package/dist/src/model/BelongsToMany.d.ts +27 -0
- package/dist/src/model/BelongsToMany.js +118 -0
- package/dist/src/model/Model.d.ts +166 -0
- package/dist/src/model/Model.js +763 -0
- package/dist/src/model/MorphMap.d.ts +7 -0
- package/dist/src/model/MorphMap.js +12 -0
- package/dist/src/model/MorphRelations.d.ts +81 -0
- package/dist/src/model/MorphRelations.js +296 -0
- package/dist/src/model/Observer.d.ts +19 -0
- package/dist/src/model/Observer.js +21 -0
- package/dist/src/query/Builder.d.ts +106 -0
- package/dist/src/query/Builder.js +466 -0
- package/dist/src/schema/Blueprint.d.ts +66 -0
- package/dist/src/schema/Blueprint.js +200 -0
- package/dist/src/schema/Schema.d.ts +16 -0
- package/dist/src/schema/Schema.js +135 -0
- package/dist/src/schema/grammars/Grammar.d.ts +26 -0
- package/dist/src/schema/grammars/Grammar.js +95 -0
- package/dist/src/schema/grammars/MySqlGrammar.d.ts +18 -0
- package/dist/src/schema/grammars/MySqlGrammar.js +96 -0
- package/dist/src/schema/grammars/PostgresGrammar.d.ts +16 -0
- package/dist/src/schema/grammars/PostgresGrammar.js +88 -0
- package/dist/src/schema/grammars/SQLiteGrammar.d.ts +16 -0
- package/dist/src/schema/grammars/SQLiteGrammar.js +108 -0
- package/dist/src/typegen/TypeGenerator.d.ts +29 -0
- package/dist/src/typegen/TypeGenerator.js +171 -0
- package/dist/src/typegen/TypeMapper.d.ts +4 -0
- package/dist/src/typegen/TypeMapper.js +27 -0
- package/dist/src/types/index.d.ts +53 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.js +6 -0
- package/package.json +62 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Connection } from "../connection/Connection.js";
|
|
2
|
+
import { Builder } from "../query/Builder.js";
|
|
3
|
+
import { MorphTo, MorphOne, MorphMany, MorphToMany } from "./MorphRelations.js";
|
|
4
|
+
import { BelongsToMany } from "./BelongsToMany.js";
|
|
5
|
+
export type ModelConstructor<T extends Model = Model> = typeof Model & (new (...args: any[]) => T);
|
|
6
|
+
export type GlobalScope = (builder: Builder<any>, model: typeof Model) => void;
|
|
7
|
+
export type CastDefinition = string | CastsAttributes | (new (...args: any[]) => CastsAttributes);
|
|
8
|
+
export interface CastsAttributes {
|
|
9
|
+
get(model: Model, key: string, value: any, attributes: Record<string, any>): any;
|
|
10
|
+
set(model: Model, key: string, value: any, attributes: Record<string, any>): any;
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class Relation<T extends Model = Model> {
|
|
13
|
+
protected builder: Builder<T>;
|
|
14
|
+
protected parent: Model;
|
|
15
|
+
protected related: typeof Model;
|
|
16
|
+
protected foreignKey: string;
|
|
17
|
+
protected localKey: string;
|
|
18
|
+
constructor(parent: Model, related: typeof Model, foreignKey?: string, localKey?: string);
|
|
19
|
+
abstract addConstraints(): void;
|
|
20
|
+
abstract getResults(): Promise<T | T[] | null>;
|
|
21
|
+
abstract addEagerConstraints(models: Model[]): void;
|
|
22
|
+
abstract getEager(): Promise<any[]>;
|
|
23
|
+
abstract match(models: Model[], results: any[], relationName: string): void;
|
|
24
|
+
protected defaultForeignKey(): string;
|
|
25
|
+
getQuery(): Builder<T>;
|
|
26
|
+
qualifyRelatedColumn(column: string): string;
|
|
27
|
+
protected newExistenceQuery(parentQuery: Builder<any>, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): Builder<any>;
|
|
28
|
+
getRelationExistenceSql(parentQuery: Builder<any>, callback?: (query: Builder<any>) => void | Builder<any>): string;
|
|
29
|
+
getRelationCountSql(parentQuery: Builder<any>, callback?: (query: Builder<any>) => void | Builder<any>): string;
|
|
30
|
+
getRelationAggregateSql(parentQuery: Builder<any>, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): string;
|
|
31
|
+
}
|
|
32
|
+
export declare class HasMany<T extends Model = Model> extends Relation<T> {
|
|
33
|
+
constructor(parent: Model, related: typeof Model, foreignKey?: string, localKey?: string);
|
|
34
|
+
addConstraints(): void;
|
|
35
|
+
addEagerConstraints(models: Model[]): void;
|
|
36
|
+
getEager(): Promise<any[]>;
|
|
37
|
+
match(models: Model[], results: any[], relationName: string): void;
|
|
38
|
+
getResults(): Promise<T[]>;
|
|
39
|
+
latestOfMany(column?: string): HasOne<T>;
|
|
40
|
+
oldestOfMany(column?: string): HasOne<T>;
|
|
41
|
+
ofMany(column: string, aggregate?: "max" | "min"): HasOne<T>;
|
|
42
|
+
}
|
|
43
|
+
export declare class BelongsTo<T extends Model = Model> extends Relation<T> {
|
|
44
|
+
constructor(parent: Model, related: typeof Model, foreignKey?: string, ownerKey?: string);
|
|
45
|
+
addConstraints(): void;
|
|
46
|
+
addEagerConstraints(models: Model[]): void;
|
|
47
|
+
getEager(): Promise<any[]>;
|
|
48
|
+
match(models: Model[], results: any[], relationName: string): void;
|
|
49
|
+
getResults(): Promise<T | null>;
|
|
50
|
+
associate(model: Model | any): Model;
|
|
51
|
+
dissociate(): Model;
|
|
52
|
+
protected newExistenceQuery(parentQuery: Builder<any>, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): Builder<any>;
|
|
53
|
+
}
|
|
54
|
+
export declare class HasManyThrough<T extends Model = Model> extends Relation<T> {
|
|
55
|
+
protected through: typeof Model;
|
|
56
|
+
protected firstKey: string;
|
|
57
|
+
protected secondKey: string;
|
|
58
|
+
protected secondLocalKey: string;
|
|
59
|
+
constructor(parent: Model, related: typeof Model, through: typeof Model, firstKey?: string, secondKey?: string, localKey?: string, secondLocalKey?: string);
|
|
60
|
+
addConstraints(): void;
|
|
61
|
+
addEagerConstraints(models: Model[]): void;
|
|
62
|
+
getEager(): Promise<any[]>;
|
|
63
|
+
match(models: Model[], results: any[], relationName: string): void;
|
|
64
|
+
getResults(): Promise<T[] | T | null>;
|
|
65
|
+
protected newExistenceQuery(parentQuery: Builder<any>, aggregate: string, callback?: (query: Builder<any>) => void | Builder<any>): Builder<any>;
|
|
66
|
+
}
|
|
67
|
+
export declare class HasOneThrough<T extends Model = Model> extends HasManyThrough<T> {
|
|
68
|
+
getResults(): Promise<T | null>;
|
|
69
|
+
match(models: Model[], results: any[], relationName: string): void;
|
|
70
|
+
}
|
|
71
|
+
export declare class HasOne<T extends Model = Model> extends Relation<T> {
|
|
72
|
+
constructor(parent: Model, related: typeof Model, foreignKey?: string, localKey?: string);
|
|
73
|
+
addConstraints(): void;
|
|
74
|
+
addEagerConstraints(models: Model[]): void;
|
|
75
|
+
getEager(): Promise<any[]>;
|
|
76
|
+
match(models: Model[], results: any[], relationName: string): void;
|
|
77
|
+
getResults(): Promise<T | null>;
|
|
78
|
+
}
|
|
79
|
+
export declare class Model<T extends Record<string, any> = Record<string, any>> {
|
|
80
|
+
static table: string;
|
|
81
|
+
static primaryKey: string;
|
|
82
|
+
static timestamps: boolean;
|
|
83
|
+
static connection?: Connection;
|
|
84
|
+
static dateFormat: string;
|
|
85
|
+
static morphName?: string;
|
|
86
|
+
static casts: Record<string, CastDefinition>;
|
|
87
|
+
static fillable: string[];
|
|
88
|
+
static guarded: string[];
|
|
89
|
+
static attributes: Record<string, any>;
|
|
90
|
+
static softDeletes: boolean;
|
|
91
|
+
static deletedAtColumn: string;
|
|
92
|
+
$attributes: T;
|
|
93
|
+
$original: Partial<T>;
|
|
94
|
+
$exists: boolean;
|
|
95
|
+
$relations: Record<string, any>;
|
|
96
|
+
$casts: Record<string, CastDefinition>;
|
|
97
|
+
constructor(attributes?: Partial<T>);
|
|
98
|
+
static getTable(): string;
|
|
99
|
+
static getConnection(): Connection;
|
|
100
|
+
static setConnection(connection: Connection): void;
|
|
101
|
+
static query<M extends typeof Model>(this: M): Builder<InstanceType<M>>;
|
|
102
|
+
static addGlobalScope(name: string, scope: GlobalScope): void;
|
|
103
|
+
static removeGlobalScope(name: string): void;
|
|
104
|
+
static applyGlobalScopes(builder: Builder<any>): void;
|
|
105
|
+
static getQualifiedDeletedAtColumn(): string;
|
|
106
|
+
static create<M extends typeof Model>(this: M, attributes: Partial<InstanceType<M> extends Model<infer U> ? U : Record<string, any>>): Promise<InstanceType<M>>;
|
|
107
|
+
static find<M extends typeof Model>(this: M, id: any): Promise<InstanceType<M> | null>;
|
|
108
|
+
static first<M extends typeof Model>(this: M): Promise<InstanceType<M> | null>;
|
|
109
|
+
static where<M extends typeof Model>(this: M, column: string | Record<string, any>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
|
|
110
|
+
static whereIn<M extends typeof Model>(this: M, column: string, values: any[]): Builder<InstanceType<M>>;
|
|
111
|
+
static whereNull<M extends typeof Model>(this: M, column: string): Builder<InstanceType<M>>;
|
|
112
|
+
static whereNotNull<M extends typeof Model>(this: M, column: string): Builder<InstanceType<M>>;
|
|
113
|
+
static orWhere<M extends typeof Model>(this: M, column: string | Record<string, any>, operator?: string | any, value?: any): Builder<InstanceType<M>>;
|
|
114
|
+
static with<M extends typeof Model>(this: M, ...relations: string[]): Builder<InstanceType<M>>;
|
|
115
|
+
static withTrashed<M extends typeof Model>(this: M): Builder<InstanceType<M>>;
|
|
116
|
+
static onlyTrashed<M extends typeof Model>(this: M): Builder<InstanceType<M>>;
|
|
117
|
+
static withoutGlobalScope<M extends typeof Model>(this: M, scope: string): Builder<InstanceType<M>>;
|
|
118
|
+
static withoutGlobalScopes<M extends typeof Model>(this: M): Builder<InstanceType<M>>;
|
|
119
|
+
static scope<M extends typeof Model>(this: M, name: string, ...args: any[]): Builder<InstanceType<M>>;
|
|
120
|
+
static has<M extends typeof Model>(this: M, relationName: string, operator?: string, count?: number): Builder<InstanceType<M>>;
|
|
121
|
+
static whereHas<M extends typeof Model>(this: M, relationName: string, callback?: (query: Builder<any>) => void | Builder<any>, operator?: string, count?: number): Builder<InstanceType<M>>;
|
|
122
|
+
static doesntHave<M extends typeof Model>(this: M, relationName: string): Builder<InstanceType<M>>;
|
|
123
|
+
static withCount<M extends typeof Model>(this: M, relationName: string, alias?: string): Builder<InstanceType<M>>;
|
|
124
|
+
static withSum<M extends typeof Model>(this: M, relationName: string, column: string, alias?: string): Builder<InstanceType<M>>;
|
|
125
|
+
static withAvg<M extends typeof Model>(this: M, relationName: string, column: string, alias?: string): Builder<InstanceType<M>>;
|
|
126
|
+
static withMin<M extends typeof Model>(this: M, relationName: string, column: string, alias?: string): Builder<InstanceType<M>>;
|
|
127
|
+
static withMax<M extends typeof Model>(this: M, relationName: string, column: string, alias?: string): Builder<InstanceType<M>>;
|
|
128
|
+
static all<M extends typeof Model>(this: M): Promise<InstanceType<M>[]>;
|
|
129
|
+
static paginate<M extends typeof Model>(this: M, perPage?: number, page?: number): Promise<import("../query/Builder.js").Paginator<InstanceType<M>>>;
|
|
130
|
+
static eagerLoadRelations(models: Model[], relations: string[]): Promise<void>;
|
|
131
|
+
static eagerLoadRelation(models: Model[], relationName: string): Promise<void>;
|
|
132
|
+
fill(attributes: Partial<T>): this;
|
|
133
|
+
isFillable(key: string): boolean;
|
|
134
|
+
getAttribute<K extends keyof T>(key: K): T[K];
|
|
135
|
+
getAttribute(key: string): any;
|
|
136
|
+
setAttribute<K extends keyof T>(key: K, value: T[K]): void;
|
|
137
|
+
setAttribute(key: string, value: any): void;
|
|
138
|
+
castAttribute(key: string, value: any): any;
|
|
139
|
+
serializeCastAttribute(key: string, value: any): any;
|
|
140
|
+
mergeCasts(casts: Record<string, CastDefinition>): this;
|
|
141
|
+
protected getCastDefinition(key: string): CastDefinition | undefined;
|
|
142
|
+
protected resolveCustomCast(cast: CastDefinition): CastsAttributes | null;
|
|
143
|
+
getDirty(): Partial<T>;
|
|
144
|
+
isDirty(): boolean;
|
|
145
|
+
save(): Promise<this>;
|
|
146
|
+
delete(): Promise<boolean>;
|
|
147
|
+
restore(): Promise<boolean>;
|
|
148
|
+
forceDelete(): Promise<boolean>;
|
|
149
|
+
refresh(): Promise<this>;
|
|
150
|
+
toJSON(): Record<string, any>;
|
|
151
|
+
toString(): string;
|
|
152
|
+
freshTimestamp(): string;
|
|
153
|
+
setRelation(name: string, value: any): void;
|
|
154
|
+
getRelation(name: string): any;
|
|
155
|
+
hasMany<R extends Model>(related: ModelConstructor<R>, foreignKey?: string, localKey?: string): HasMany<R>;
|
|
156
|
+
belongsTo<R extends Model>(related: ModelConstructor<R>, foreignKey?: string, ownerKey?: string): BelongsTo<R>;
|
|
157
|
+
hasOne<R extends Model>(related: ModelConstructor<R>, foreignKey?: string, localKey?: string): HasOne<R>;
|
|
158
|
+
hasManyThrough<R extends Model>(related: ModelConstructor<R>, through: ModelConstructor, firstKey?: string, secondKey?: string, localKey?: string, secondLocalKey?: string): HasManyThrough<R>;
|
|
159
|
+
hasOneThrough<R extends Model>(related: ModelConstructor<R>, through: ModelConstructor, firstKey?: string, secondKey?: string, localKey?: string, secondLocalKey?: string): HasOneThrough<R>;
|
|
160
|
+
belongsToMany<R extends Model>(related: ModelConstructor<R>, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string): BelongsToMany<R>;
|
|
161
|
+
morphTo(name: string, typeMap?: Record<string, ModelConstructor>): MorphTo;
|
|
162
|
+
morphOne<R extends Model>(related: ModelConstructor<R>, name: string, typeColumn?: string, idColumn?: string, localKey?: string): MorphOne<R>;
|
|
163
|
+
morphMany<R extends Model>(related: ModelConstructor<R>, name: string, typeColumn?: string, idColumn?: string, localKey?: string): MorphMany<R>;
|
|
164
|
+
morphToMany<R extends Model>(related: ModelConstructor<R>, name: string, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string): MorphToMany<R>;
|
|
165
|
+
morphedByMany<R extends Model>(related: ModelConstructor<R>, name: string, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string): MorphToMany<R>;
|
|
166
|
+
}
|