arcanajs 3.0.1 → 4.0.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/dist/arcanajs.js +2 -1
- package/dist/arcanajs.js.LICENSE.txt +14 -0
- package/dist/arcanajs.js.map +1 -1
- package/dist/arcanox.js +2 -0
- package/dist/arcanox.js.map +1 -0
- package/dist/cli/commands/db.d.ts +1 -0
- package/dist/cli/commands/make.d.ts +1 -0
- package/dist/cli/commands/migrate.d.ts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/arcanox/Model.d.ts +203 -0
- package/dist/lib/arcanox/QueryBuilder.d.ts +141 -0
- package/dist/lib/arcanox/adapters/MongoAdapter.d.ts +22 -0
- package/dist/lib/arcanox/adapters/MySQLAdapter.d.ts +27 -0
- package/dist/lib/arcanox/adapters/PostgresAdapter.d.ts +27 -0
- package/dist/lib/arcanox/extensions/MongoExtensions.d.ts +33 -0
- package/dist/lib/arcanox/factory/Factory.d.ts +26 -0
- package/dist/lib/arcanox/factory/index.d.ts +1 -0
- package/dist/lib/arcanox/index.d.ts +13 -0
- package/dist/lib/arcanox/providers/DatabaseProvider.d.ts +5 -0
- package/dist/lib/arcanox/relations/BelongsTo.d.ts +11 -0
- package/dist/lib/arcanox/relations/BelongsToMany.d.ts +15 -0
- package/dist/lib/arcanox/relations/HasMany.d.ts +11 -0
- package/dist/lib/arcanox/relations/HasOne.d.ts +11 -0
- package/dist/lib/arcanox/relations/Relation.d.ts +14 -0
- package/dist/lib/arcanox/schema/Blueprint.d.ts +183 -0
- package/dist/lib/arcanox/schema/Migration.d.ts +76 -0
- package/dist/lib/arcanox/schema/Schema.d.ts +49 -0
- package/dist/lib/arcanox/schema/index.d.ts +4 -0
- package/dist/lib/arcanox/seeder/Seeder.d.ts +13 -0
- package/dist/lib/arcanox/seeder/index.d.ts +1 -0
- package/dist/lib/arcanox/support/Macroable.d.ts +19 -0
- package/dist/lib/arcanox/types.d.ts +76 -0
- package/dist/lib/index.arcanox.d.ts +6 -0
- package/dist/lib/{index.d.ts → index.server.d.ts} +7 -11
- package/dist/lib/server/ArcanaJSServer.d.ts +35 -9
- package/dist/lib/server/Container.d.ts +31 -0
- package/dist/lib/server/MiddlewareBinder.d.ts +4 -0
- package/dist/lib/server/ResponseHandlerMiddleware.d.ts +0 -25
- package/dist/lib/server/Router.d.ts +12 -3
- package/dist/lib/server/http/FormRequest.d.ts +10 -0
- package/dist/lib/server/http/JsonResource.d.ts +13 -0
- package/dist/lib/server/http/Middleware.d.ts +4 -0
- package/dist/lib/server/support/ServiceProvider.d.ts +13 -0
- package/dist/lib/server/utils/dynamicRequire.d.ts +6 -0
- package/dist/lib/server/validation/ValidationException.d.ts +5 -0
- package/dist/lib/server/validation/Validator.d.ts +12 -0
- package/package.json +26 -14
- package/dist/lib/global.d.ts +0 -61
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { QueryBuilder } from "./QueryBuilder";
|
|
2
|
+
import { BelongsTo } from "./relations/BelongsTo";
|
|
3
|
+
import { BelongsToMany } from "./relations/BelongsToMany";
|
|
4
|
+
import { HasMany } from "./relations/HasMany";
|
|
5
|
+
import { HasOne } from "./relations/HasOne";
|
|
6
|
+
import type { DatabaseAdapter } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Relation types for arcanox relationships
|
|
9
|
+
*/
|
|
10
|
+
export type RelationType = "hasOne" | "hasMany" | "belongsTo" | "belongsToMany";
|
|
11
|
+
export interface RelationConfig {
|
|
12
|
+
type: RelationType;
|
|
13
|
+
related: typeof Model;
|
|
14
|
+
foreignKey?: string;
|
|
15
|
+
localKey?: string;
|
|
16
|
+
pivotTable?: string;
|
|
17
|
+
}
|
|
18
|
+
import { Macroable } from "./support/Macroable";
|
|
19
|
+
/**
|
|
20
|
+
* Base Model class - Arcanox ORM
|
|
21
|
+
*/
|
|
22
|
+
export declare class Model<T = any> extends Macroable {
|
|
23
|
+
protected static adapter: DatabaseAdapter;
|
|
24
|
+
protected static tableName: string;
|
|
25
|
+
protected static primaryKey: string;
|
|
26
|
+
protected static connection: string;
|
|
27
|
+
protected attributes: Record<string, any>;
|
|
28
|
+
protected original: Record<string, any>;
|
|
29
|
+
protected relations: Record<string, any>;
|
|
30
|
+
protected exists: boolean;
|
|
31
|
+
protected fillable: string[];
|
|
32
|
+
protected guarded: string[];
|
|
33
|
+
protected hidden: string[];
|
|
34
|
+
protected visible: string[];
|
|
35
|
+
protected casts: Record<string, string>;
|
|
36
|
+
protected dates: string[];
|
|
37
|
+
protected timestamps: boolean;
|
|
38
|
+
protected createdAt: string;
|
|
39
|
+
protected updatedAt: string;
|
|
40
|
+
protected softDeletes: boolean;
|
|
41
|
+
protected deletedAt: string;
|
|
42
|
+
/**
|
|
43
|
+
* Set the database adapter
|
|
44
|
+
*/
|
|
45
|
+
static setAdapter(adapter: DatabaseAdapter): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get the table name
|
|
48
|
+
*/
|
|
49
|
+
static getTable(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Create a new query builder instance
|
|
52
|
+
*/
|
|
53
|
+
static query<T>(): QueryBuilder<T>;
|
|
54
|
+
/**
|
|
55
|
+
* Get all records
|
|
56
|
+
*/
|
|
57
|
+
static all<T>(): Promise<T[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Find a record by ID
|
|
60
|
+
*/
|
|
61
|
+
static find<T>(id: any): Promise<T | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Find a record by ID or throw exception
|
|
64
|
+
*/
|
|
65
|
+
static findOrFail<T>(id: any): Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Create a WHERE query
|
|
68
|
+
*/
|
|
69
|
+
static where<T>(column: string, operator: any, value?: any): QueryBuilder<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Create a new record
|
|
72
|
+
*/
|
|
73
|
+
static create<T>(data: Partial<T>): Promise<T>;
|
|
74
|
+
/**
|
|
75
|
+
* Update a record
|
|
76
|
+
*/
|
|
77
|
+
static update<T>(id: any, data: Partial<T>): Promise<T>;
|
|
78
|
+
/**
|
|
79
|
+
* Delete a record
|
|
80
|
+
*/
|
|
81
|
+
static destroy(id: any): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* First or create
|
|
84
|
+
*/
|
|
85
|
+
static firstOrCreate<T>(attributes: Partial<T>, values?: Partial<T>): Promise<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Update or create
|
|
88
|
+
*/
|
|
89
|
+
static updateOrCreate<T>(attributes: Partial<T>, values?: Partial<T>): Promise<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Hydrate a model instance from data
|
|
92
|
+
*/
|
|
93
|
+
protected static hydrate<T>(data: any): T;
|
|
94
|
+
/**
|
|
95
|
+
* Fill model attributes
|
|
96
|
+
*/
|
|
97
|
+
fill(attributes: Partial<T>): this;
|
|
98
|
+
/**
|
|
99
|
+
* Check if attribute is fillable
|
|
100
|
+
*/
|
|
101
|
+
protected isFillable(key: string): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Set an attribute
|
|
104
|
+
*/
|
|
105
|
+
setAttribute(key: string, value: any): void;
|
|
106
|
+
/**
|
|
107
|
+
* Get an attribute
|
|
108
|
+
*/
|
|
109
|
+
getAttribute(key: string): any;
|
|
110
|
+
/**
|
|
111
|
+
* Cast attribute to specified type
|
|
112
|
+
*/
|
|
113
|
+
protected castAttribute(key: string, value: any, isGetting?: boolean): any;
|
|
114
|
+
/**
|
|
115
|
+
* Save the model
|
|
116
|
+
*/
|
|
117
|
+
save(): Promise<this>;
|
|
118
|
+
/**
|
|
119
|
+
* Update the model
|
|
120
|
+
*/
|
|
121
|
+
update(attributes: Partial<T>): Promise<this>;
|
|
122
|
+
/**
|
|
123
|
+
* Delete the model
|
|
124
|
+
*/
|
|
125
|
+
delete(): Promise<boolean>;
|
|
126
|
+
/**
|
|
127
|
+
* Force delete (ignore soft deletes)
|
|
128
|
+
*/
|
|
129
|
+
forceDelete(): Promise<boolean>;
|
|
130
|
+
/**
|
|
131
|
+
* Restore soft deleted model
|
|
132
|
+
*/
|
|
133
|
+
restore(): Promise<this>;
|
|
134
|
+
/**
|
|
135
|
+
* Sync original attributes
|
|
136
|
+
*/
|
|
137
|
+
protected syncOriginal(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Get dirty attributes (changed since last sync)
|
|
140
|
+
*/
|
|
141
|
+
getDirty(): Record<string, any>;
|
|
142
|
+
/**
|
|
143
|
+
* Check if model is dirty
|
|
144
|
+
*/
|
|
145
|
+
isDirty(): boolean;
|
|
146
|
+
constructor(attributes?: Partial<T>);
|
|
147
|
+
/**
|
|
148
|
+
* Convert model to JSON
|
|
149
|
+
*/
|
|
150
|
+
toJSON(): Record<string, any>;
|
|
151
|
+
/**
|
|
152
|
+
* Define a one-to-one relationship
|
|
153
|
+
*/
|
|
154
|
+
hasOne<R extends Model>(related: new () => R, foreignKey?: string, localKey?: string): HasOne<R>;
|
|
155
|
+
/**
|
|
156
|
+
* Define a one-to-many relationship
|
|
157
|
+
*/
|
|
158
|
+
hasMany<R extends Model>(related: new () => R, foreignKey?: string, localKey?: string): HasMany<R>;
|
|
159
|
+
/**
|
|
160
|
+
* Define an inverse one-to-one or many relationship
|
|
161
|
+
*/
|
|
162
|
+
belongsTo<R extends Model>(related: new () => R, foreignKey?: string, ownerKey?: string): BelongsTo<R>;
|
|
163
|
+
/**
|
|
164
|
+
* Define a many-to-many relationship
|
|
165
|
+
*/
|
|
166
|
+
belongsToMany<R extends Model>(related: new () => R, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string): BelongsToMany<R>;
|
|
167
|
+
/**
|
|
168
|
+
* Guess the pivot table name (alphabetical order of model names)
|
|
169
|
+
*/
|
|
170
|
+
protected guessPivotTable(related: Model): string;
|
|
171
|
+
/**
|
|
172
|
+
* Eager load relationships
|
|
173
|
+
*/
|
|
174
|
+
static with<T>(relations: string | string[]): QueryBuilder<T>;
|
|
175
|
+
/**
|
|
176
|
+
* Set a loaded relationship
|
|
177
|
+
*/
|
|
178
|
+
setRelation(relation: string, value: any): this;
|
|
179
|
+
/**
|
|
180
|
+
* Get a loaded relationship
|
|
181
|
+
*/
|
|
182
|
+
getRelation(relation: string): any;
|
|
183
|
+
/**
|
|
184
|
+
* Check if a relationship is loaded
|
|
185
|
+
*/
|
|
186
|
+
relationLoaded(relation: string): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Create a new query builder for the model
|
|
189
|
+
*/
|
|
190
|
+
newQuery(): QueryBuilder<T>;
|
|
191
|
+
/**
|
|
192
|
+
* Helper: Convert string to snake_case
|
|
193
|
+
*/
|
|
194
|
+
protected static snakeCase(str: string): string;
|
|
195
|
+
/**
|
|
196
|
+
* Helper: Pluralize string (simple implementation)
|
|
197
|
+
*/
|
|
198
|
+
protected static pluralize(str: string): string;
|
|
199
|
+
/**
|
|
200
|
+
* Helper: Convert to StudlyCase
|
|
201
|
+
*/
|
|
202
|
+
protected studly(str: string): string;
|
|
203
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { JoinClause, OrderByClause, WhereClause } from "./types";
|
|
2
|
+
import { Macroable } from "./support/Macroable";
|
|
3
|
+
/**
|
|
4
|
+
* Query Builder - Fluent interface for building database queries
|
|
5
|
+
* Arcanox Query Builder
|
|
6
|
+
*/
|
|
7
|
+
export declare class QueryBuilder<T = any> extends Macroable {
|
|
8
|
+
protected tableName: string;
|
|
9
|
+
protected selectColumns: string[];
|
|
10
|
+
protected whereClauses: WhereClause[];
|
|
11
|
+
protected orderByClauses: OrderByClause[];
|
|
12
|
+
protected joinClauses: JoinClause[];
|
|
13
|
+
protected limitValue?: number;
|
|
14
|
+
protected offsetValue?: number;
|
|
15
|
+
protected adapter: any;
|
|
16
|
+
constructor(table: string, adapter: any);
|
|
17
|
+
/**
|
|
18
|
+
* Select specific columns
|
|
19
|
+
*/
|
|
20
|
+
select(...columns: string[]): this;
|
|
21
|
+
/**
|
|
22
|
+
* Add a WHERE clause
|
|
23
|
+
*/
|
|
24
|
+
where(column: string, operator: any, value?: any): this;
|
|
25
|
+
/**
|
|
26
|
+
* Add an OR WHERE clause
|
|
27
|
+
*/
|
|
28
|
+
orWhere(column: string, operator: any, value?: any): this;
|
|
29
|
+
/**
|
|
30
|
+
* WHERE IN clause
|
|
31
|
+
*/
|
|
32
|
+
whereIn(column: string, values: any[]): this;
|
|
33
|
+
/**
|
|
34
|
+
* WHERE NOT IN clause
|
|
35
|
+
*/
|
|
36
|
+
whereNotIn(column: string, values: any[]): this;
|
|
37
|
+
/**
|
|
38
|
+
* WHERE BETWEEN clause
|
|
39
|
+
*/
|
|
40
|
+
whereBetween(column: string, range: [any, any]): this;
|
|
41
|
+
/**
|
|
42
|
+
* WHERE NULL clause
|
|
43
|
+
*/
|
|
44
|
+
whereNull(column: string): this;
|
|
45
|
+
/**
|
|
46
|
+
* WHERE NOT NULL clause
|
|
47
|
+
*/
|
|
48
|
+
whereNotNull(column: string): this;
|
|
49
|
+
/**
|
|
50
|
+
* Add ORDER BY clause
|
|
51
|
+
*/
|
|
52
|
+
orderBy(column: string, direction?: "ASC" | "DESC" | "asc" | "desc"): this;
|
|
53
|
+
/**
|
|
54
|
+
* Add LIMIT clause
|
|
55
|
+
*/
|
|
56
|
+
limit(count: number): this;
|
|
57
|
+
/**
|
|
58
|
+
* Add OFFSET clause
|
|
59
|
+
*/
|
|
60
|
+
offset(count: number): this;
|
|
61
|
+
/**
|
|
62
|
+
* Add JOIN clause
|
|
63
|
+
*/
|
|
64
|
+
join(table: string, first: string, operator: string, second: string, type?: "INNER" | "LEFT" | "RIGHT"): this;
|
|
65
|
+
/**
|
|
66
|
+
* Add LEFT JOIN clause
|
|
67
|
+
*/
|
|
68
|
+
leftJoin(table: string, first: string, operator: string, second: string): this;
|
|
69
|
+
/**
|
|
70
|
+
* Add RIGHT JOIN clause
|
|
71
|
+
*/
|
|
72
|
+
rightJoin(table: string, first: string, operator: string, second: string): this;
|
|
73
|
+
protected eagerLoads: string[];
|
|
74
|
+
protected model: any;
|
|
75
|
+
/**
|
|
76
|
+
* Set the model class
|
|
77
|
+
*/
|
|
78
|
+
setModel(model: any): this;
|
|
79
|
+
/**
|
|
80
|
+
* Eager load relationships
|
|
81
|
+
*/
|
|
82
|
+
with(relations: string | string[]): this;
|
|
83
|
+
/**
|
|
84
|
+
* Execute query and get all results
|
|
85
|
+
*/
|
|
86
|
+
get(): Promise<T[]>;
|
|
87
|
+
/**
|
|
88
|
+
* Eager load relations
|
|
89
|
+
*/
|
|
90
|
+
protected eagerLoadRelations(results: any[]): Promise<any[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Get first result
|
|
93
|
+
*/
|
|
94
|
+
first(): Promise<T | null>;
|
|
95
|
+
/**
|
|
96
|
+
* Find by ID
|
|
97
|
+
*/
|
|
98
|
+
find(id: any): Promise<T | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Count results
|
|
101
|
+
*/
|
|
102
|
+
count(): Promise<number>;
|
|
103
|
+
/**
|
|
104
|
+
* Get specific column values
|
|
105
|
+
*/
|
|
106
|
+
pluck(column: string): Promise<any[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Sum of column
|
|
109
|
+
*/
|
|
110
|
+
sum(column: string): Promise<number>;
|
|
111
|
+
/**
|
|
112
|
+
* Average of column
|
|
113
|
+
*/
|
|
114
|
+
avg(column: string): Promise<number>;
|
|
115
|
+
/**
|
|
116
|
+
* Minimum value of column
|
|
117
|
+
*/
|
|
118
|
+
min(column: string): Promise<any>;
|
|
119
|
+
/**
|
|
120
|
+
* Maximum value of column
|
|
121
|
+
*/
|
|
122
|
+
max(column: string): Promise<any>;
|
|
123
|
+
/**
|
|
124
|
+
* Check if any records exist
|
|
125
|
+
*/
|
|
126
|
+
exists(): Promise<boolean>;
|
|
127
|
+
/**
|
|
128
|
+
* Paginate results
|
|
129
|
+
*/
|
|
130
|
+
paginate(page?: number, perPage?: number): Promise<{
|
|
131
|
+
data: T[];
|
|
132
|
+
total: number;
|
|
133
|
+
perPage: number;
|
|
134
|
+
currentPage: number;
|
|
135
|
+
lastPage: number;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Clone the query builder
|
|
139
|
+
*/
|
|
140
|
+
clone(): QueryBuilder<T>;
|
|
141
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ColumnDefinition, Connection, DatabaseAdapter, DatabaseConfig, SelectOptions } from "../types";
|
|
2
|
+
export declare class MongoAdapter implements DatabaseAdapter {
|
|
3
|
+
private client;
|
|
4
|
+
private db;
|
|
5
|
+
connect(config: DatabaseConfig): Promise<Connection>;
|
|
6
|
+
disconnect(): Promise<void>;
|
|
7
|
+
createTable(tableName: string, columns: ColumnDefinition[]): Promise<void>;
|
|
8
|
+
dropTable(tableName: string): Promise<void>;
|
|
9
|
+
hasTable(tableName: string): Promise<boolean>;
|
|
10
|
+
hasColumn(tableName: string, columnName: string): Promise<boolean>;
|
|
11
|
+
select(table: string, options: SelectOptions): Promise<any[]>;
|
|
12
|
+
insert(table: string, data: Record<string, any>): Promise<any>;
|
|
13
|
+
update(table: string, id: any, data: Record<string, any>): Promise<any>;
|
|
14
|
+
delete(table: string, id: any): Promise<boolean>;
|
|
15
|
+
beginTransaction(): Promise<void>;
|
|
16
|
+
raw(query: string, params?: any[]): Promise<any>;
|
|
17
|
+
commit(): Promise<void>;
|
|
18
|
+
rollback(): Promise<void>;
|
|
19
|
+
private buildFilter;
|
|
20
|
+
private buildProjection;
|
|
21
|
+
private normalizeId;
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ColumnDefinition, Connection, DatabaseAdapter, DatabaseConfig, SelectOptions } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* MySQL Database Adapter
|
|
4
|
+
*/
|
|
5
|
+
export declare class MySQLAdapter implements DatabaseAdapter {
|
|
6
|
+
private pool;
|
|
7
|
+
private connection;
|
|
8
|
+
connect(config: DatabaseConfig): Promise<Connection>;
|
|
9
|
+
disconnect(): Promise<void>;
|
|
10
|
+
query(sql: string, params?: any[]): Promise<any>;
|
|
11
|
+
execute(sql: string, params?: any[]): Promise<any>;
|
|
12
|
+
createTable(tableName: string, columns: ColumnDefinition[]): Promise<void>;
|
|
13
|
+
dropTable(tableName: string): Promise<void>;
|
|
14
|
+
hasTable(tableName: string): Promise<boolean>;
|
|
15
|
+
hasColumn(tableName: string, columnName: string): Promise<boolean>;
|
|
16
|
+
select(table: string, options: SelectOptions): Promise<any[]>;
|
|
17
|
+
insert(table: string, data: Record<string, any>): Promise<any>;
|
|
18
|
+
update(table: string, id: any, data: Record<string, any>): Promise<any>;
|
|
19
|
+
delete(table: string, id: any): Promise<boolean>;
|
|
20
|
+
beginTransaction(): Promise<void>;
|
|
21
|
+
commit(): Promise<void>;
|
|
22
|
+
rollback(): Promise<void>;
|
|
23
|
+
raw(query: string, params?: any[]): Promise<any>;
|
|
24
|
+
private buildWhereCondition;
|
|
25
|
+
private mapType;
|
|
26
|
+
private formatValue;
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ColumnDefinition, Connection, DatabaseAdapter, DatabaseConfig, SelectOptions } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* PostgreSQL Database Adapter
|
|
4
|
+
*/
|
|
5
|
+
export declare class PostgresAdapter implements DatabaseAdapter {
|
|
6
|
+
private pool;
|
|
7
|
+
private client;
|
|
8
|
+
connect(config: DatabaseConfig): Promise<Connection>;
|
|
9
|
+
disconnect(): Promise<void>;
|
|
10
|
+
query(sql: string, params?: any[]): Promise<any>;
|
|
11
|
+
execute(sql: string, params?: any[]): Promise<any>;
|
|
12
|
+
createTable(tableName: string, columns: ColumnDefinition[]): Promise<void>;
|
|
13
|
+
dropTable(tableName: string): Promise<void>;
|
|
14
|
+
hasTable(tableName: string): Promise<boolean>;
|
|
15
|
+
hasColumn(tableName: string, columnName: string): Promise<boolean>;
|
|
16
|
+
select(table: string, options: SelectOptions): Promise<any[]>;
|
|
17
|
+
insert(table: string, data: Record<string, any>): Promise<any>;
|
|
18
|
+
update(table: string, id: any, data: Record<string, any>): Promise<any>;
|
|
19
|
+
delete(table: string, id: any): Promise<boolean>;
|
|
20
|
+
beginTransaction(): Promise<void>;
|
|
21
|
+
commit(): Promise<void>;
|
|
22
|
+
rollback(): Promise<void>;
|
|
23
|
+
raw(query: string, params?: any[]): Promise<any>;
|
|
24
|
+
private buildWhereCondition;
|
|
25
|
+
private mapType;
|
|
26
|
+
private formatValue;
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MongoDB-specific extensions for QueryBuilder
|
|
3
|
+
* These extensions provide Mongoose-style functionality for MongoDB
|
|
4
|
+
*/
|
|
5
|
+
export interface PopulateOptions {
|
|
6
|
+
from?: string;
|
|
7
|
+
localField?: string;
|
|
8
|
+
foreignField?: string;
|
|
9
|
+
as?: string;
|
|
10
|
+
select?: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* TypeScript type augmentation for better IDE support
|
|
14
|
+
*/
|
|
15
|
+
declare module "../QueryBuilder" {
|
|
16
|
+
interface QueryBuilder<T> {
|
|
17
|
+
/**
|
|
18
|
+
* Populate a relationship using MongoDB's $lookup
|
|
19
|
+
* @param field - The field name to populate
|
|
20
|
+
* @param options - Population options
|
|
21
|
+
*/
|
|
22
|
+
populate(field: string, options?: PopulateOptions): Promise<T[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Execute the query (alias for get())
|
|
25
|
+
*/
|
|
26
|
+
exec(): Promise<T[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Execute a MongoDB aggregation pipeline
|
|
29
|
+
* @param pipeline - MongoDB aggregation pipeline stages
|
|
30
|
+
*/
|
|
31
|
+
aggregate(pipeline: any[]): Promise<any[]>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Faker } from "@faker-js/faker";
|
|
2
|
+
import { Model } from "../Model";
|
|
3
|
+
/**
|
|
4
|
+
* Base Factory class
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class Factory<T extends Model> {
|
|
7
|
+
protected abstract model: new () => T;
|
|
8
|
+
protected faker: Faker;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Define the model's default state.
|
|
12
|
+
*/
|
|
13
|
+
abstract definition(): Record<string, any>;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new model instance with attributes.
|
|
16
|
+
*/
|
|
17
|
+
make(attributes?: Partial<T>): T;
|
|
18
|
+
/**
|
|
19
|
+
* Create and save a new model instance.
|
|
20
|
+
*/
|
|
21
|
+
create(attributes?: Partial<T>): Promise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Create multiple instances
|
|
24
|
+
*/
|
|
25
|
+
createMany(count: number, attributes?: Partial<T>): Promise<T[]>;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Factory } from "./Factory";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { MongoAdapter } from "./adapters/MongoAdapter";
|
|
2
|
+
export { MySQLAdapter } from "./adapters/MySQLAdapter";
|
|
3
|
+
export { PostgresAdapter } from "./adapters/PostgresAdapter";
|
|
4
|
+
export { Model } from "./Model";
|
|
5
|
+
export { QueryBuilder } from "./QueryBuilder";
|
|
6
|
+
export { BelongsTo } from "./relations/BelongsTo";
|
|
7
|
+
export { BelongsToMany } from "./relations/BelongsToMany";
|
|
8
|
+
export { HasMany } from "./relations/HasMany";
|
|
9
|
+
export { HasOne } from "./relations/HasOne";
|
|
10
|
+
export { Relation } from "./relations/Relation";
|
|
11
|
+
export { Macroable } from "./support/Macroable";
|
|
12
|
+
export type { ColumnDefinition, Connection, DatabaseAdapter, DatabaseConfig, JoinClause, OrderByClause, SelectOptions, WhereClause, } from "./types";
|
|
13
|
+
export * from "./extensions/MongoExtensions";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Model } from "../Model";
|
|
2
|
+
import { QueryBuilder } from "../QueryBuilder";
|
|
3
|
+
import { Relation } from "./Relation";
|
|
4
|
+
export declare class BelongsTo<R extends Model = any> extends Relation<R> {
|
|
5
|
+
protected foreignKey: string;
|
|
6
|
+
protected ownerKey: string;
|
|
7
|
+
constructor(query: QueryBuilder<R>, parent: Model, foreignKey: string, ownerKey: string);
|
|
8
|
+
addConstraints(): void;
|
|
9
|
+
addEagerConstraints(models: Model[]): void;
|
|
10
|
+
match(models: Model[], results: R[], relation: string): Model[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Model } from "../Model";
|
|
2
|
+
import { QueryBuilder } from "../QueryBuilder";
|
|
3
|
+
import { Relation } from "./Relation";
|
|
4
|
+
export declare class BelongsToMany<R extends Model = any> extends Relation<R> {
|
|
5
|
+
protected table: string;
|
|
6
|
+
protected foreignPivotKey: string;
|
|
7
|
+
protected relatedPivotKey: string;
|
|
8
|
+
protected parentKey: string;
|
|
9
|
+
protected relatedKey: string;
|
|
10
|
+
constructor(query: QueryBuilder<R>, parent: Model, table: string, foreignPivotKey: string, relatedPivotKey: string, parentKey: string, relatedKey: string);
|
|
11
|
+
addConstraints(): void;
|
|
12
|
+
protected performJoin(query?: QueryBuilder<R>): this;
|
|
13
|
+
addEagerConstraints(models: Model[]): void;
|
|
14
|
+
match(models: Model[], results: R[], relation: string): Model[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Model } from "../Model";
|
|
2
|
+
import { QueryBuilder } from "../QueryBuilder";
|
|
3
|
+
import { Relation } from "./Relation";
|
|
4
|
+
export declare class HasMany<R extends Model = any> extends Relation<R> {
|
|
5
|
+
protected foreignKey: string;
|
|
6
|
+
protected localKey: string;
|
|
7
|
+
constructor(query: QueryBuilder<R>, parent: Model, foreignKey: string, localKey: string);
|
|
8
|
+
addConstraints(): void;
|
|
9
|
+
addEagerConstraints(models: Model[]): void;
|
|
10
|
+
match(models: Model[], results: R[], relation: string): Model[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Model } from "../Model";
|
|
2
|
+
import { QueryBuilder } from "../QueryBuilder";
|
|
3
|
+
import { Relation } from "./Relation";
|
|
4
|
+
export declare class HasOne<R extends Model = any> extends Relation<R> {
|
|
5
|
+
protected foreignKey: string;
|
|
6
|
+
protected localKey: string;
|
|
7
|
+
constructor(query: QueryBuilder<R>, parent: Model, foreignKey: string, localKey: string);
|
|
8
|
+
addConstraints(): void;
|
|
9
|
+
addEagerConstraints(models: Model[]): void;
|
|
10
|
+
match(models: Model[], results: R[], relation: string): Model[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Model } from "../Model";
|
|
2
|
+
import { QueryBuilder } from "../QueryBuilder";
|
|
3
|
+
export declare abstract class Relation<R extends Model = any> {
|
|
4
|
+
protected query: QueryBuilder<R>;
|
|
5
|
+
protected parent: Model;
|
|
6
|
+
protected related: new () => R;
|
|
7
|
+
constructor(query: QueryBuilder<R>, parent: Model);
|
|
8
|
+
abstract addConstraints(): void;
|
|
9
|
+
abstract addEagerConstraints(models: Model[]): void;
|
|
10
|
+
abstract match(models: Model[], results: R[], relation: string): Model[];
|
|
11
|
+
getQuery(): QueryBuilder<R>;
|
|
12
|
+
get(): Promise<R[]>;
|
|
13
|
+
first(): Promise<R | null>;
|
|
14
|
+
}
|