@h3ravel/arquebus 0.1.5 → 0.2.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.
Files changed (37) hide show
  1. package/bin/.gitkeep +0 -0
  2. package/{dist/index.cjs → bin/cli.cjs} +1161 -803
  3. package/bin/cli.d.cts +18 -0
  4. package/bin/cli.d.ts +18 -0
  5. package/bin/cli.js +4887 -183
  6. package/bin/index.cjs +4948 -0
  7. package/bin/index.d.cts +2 -0
  8. package/bin/index.d.ts +2 -0
  9. package/bin/index.js +4923 -0
  10. package/bin/migrations/stubs/migration-js.stub +21 -0
  11. package/bin/migrations/stubs/migration-ts.stub +18 -0
  12. package/bin/migrations/stubs/migration.create-js.stub +24 -0
  13. package/bin/migrations/stubs/migration.create-ts.stub +21 -0
  14. package/bin/migrations/stubs/migration.update-js.stub +25 -0
  15. package/bin/migrations/stubs/migration.update-ts.stub +22 -0
  16. package/bin/stubs/arquebus.config-js.stub +25 -0
  17. package/bin/stubs/arquebus.config-ts.stub +24 -0
  18. package/bin/stubs/model-js.stub +5 -0
  19. package/bin/stubs/model-ts.stub +5 -0
  20. package/dist/browser/index.cjs +117 -97
  21. package/dist/browser/index.d.cts +1205 -165
  22. package/dist/browser/index.d.ts +1205 -165
  23. package/dist/browser/index.js +115 -96
  24. package/dist/index.d.ts +1279 -347
  25. package/dist/index.js +3758 -3547
  26. package/package.json +24 -9
  27. package/src/migrations/stubs/migration-js.stub +21 -0
  28. package/src/migrations/stubs/migration-ts.stub +18 -0
  29. package/src/migrations/stubs/migration.create-js.stub +24 -0
  30. package/src/migrations/stubs/migration.create-ts.stub +21 -0
  31. package/src/migrations/stubs/migration.update-js.stub +25 -0
  32. package/src/migrations/stubs/migration.update-ts.stub +22 -0
  33. package/src/stubs/arquebus.config-js.stub +25 -0
  34. package/src/stubs/arquebus.config-ts.stub +24 -0
  35. package/src/stubs/model-js.stub +5 -0
  36. package/src/stubs/model-ts.stub +5 -0
  37. package/dist/index.d.cts +0 -457
package/dist/index.d.ts CHANGED
@@ -1,334 +1,966 @@
1
- import Knex from 'knex';
2
- import { Collection as Collection$1 } from 'collect.js';
1
+ import { Collection as Collection$2 } from 'collect.js';
2
+ import Knex$1, { Knex } from 'knex';
3
3
 
4
- declare class ModelNotFoundError extends BaseError {
5
- model: any;
6
- ids: any;
7
- setModel(model: any, ids?: any[]): this;
8
- getModel(): any;
9
- getIds(): any;
4
+ declare class Collection$1<I extends Model$2 | Model$1> extends Collection$2<I> implements ICollection<I> {
5
+ private newConstructor;
6
+ getConstructor<T extends typeof Collection$1<I>>(this: InstanceType<T>): T;
7
+ load(...relations: I[]): Promise<Collection$1<I>>;
8
+ loadAggregate<I>(relations: I, column: string, action?: string | null | TFunction): Promise<this>;
9
+ loadCount(relations: I): Promise<this>;
10
+ loadMax(relation: I, column: string): Promise<this>;
11
+ loadMin(relation: I, column: string): Promise<this>;
12
+ loadSum(relation: I, column: string): Promise<this>;
13
+ loadAvg(relation: I, column: string): Promise<this>;
14
+ mapThen(callback: () => void): Promise<void[]>;
15
+ modelKeys(): any[];
16
+ contains<K, V>(key: keyof I | K | TFunction, value?: V): boolean;
17
+ diff(items: ICollection<any> | any[]): any;
18
+ except(keys: any[]): any;
19
+ intersect(items: I[]): any;
20
+ unique(key?: TFunction | keyof I, _strict?: boolean): any;
21
+ find(key: any, defaultValue?: null): any;
22
+ fresh(...args: any[]): Promise<any>;
23
+ makeVisible(attributes: any): this;
24
+ makeHidden(attributes: any): this;
25
+ append(attributes: any): this;
26
+ only(keys: any[]): any;
27
+ getDictionary(items?: ICollection<any> | any[]): TGeneric;
28
+ toQuery(): any;
29
+ toData(): (I | {
30
+ [x: string]: any;
31
+ [x: number]: any;
32
+ [x: symbol]: any;
33
+ })[];
34
+ toJSON(): (I | {
35
+ [x: string]: any;
36
+ [x: number]: any;
37
+ [x: symbol]: any;
38
+ })[];
39
+ toJson(...args: any[]): string;
40
+ [Symbol.iterator]: () => Iterator<I>;
10
41
  }
11
- declare class RelationNotFoundError extends BaseError {
42
+
43
+ interface SchemaBuilder extends Knex.SchemaBuilder {
44
+ [k: string]: any;
12
45
  }
13
- declare class InvalidArgumentError extends BaseError {
46
+ interface AsMethod<QB extends AnyQueryBuilder> {
47
+ (alias: string): QB;
14
48
  }
15
- declare class BaseError extends Error {
16
- constructor(message: any, entity: any);
17
- message: any;
49
+ interface IStatement {
50
+ grouping: string;
51
+ direction: string;
52
+ type: string;
53
+ value: () => any;
54
+ not: boolean;
55
+ nulls: boolean;
56
+ bool: 'and' | 'or' | 'not';
57
+ }
58
+ interface IQueryBuilder<M extends Model$2 | Model$1 = Model$2, R = M[] | M> {
59
+ schema: SchemaBuilder;
60
+ _statements: IStatement[];
61
+ table(name: string): IQueryBuilder<M, R>;
62
+ select: SelectMethod<this>;
63
+ columns: SelectMethod<this>;
64
+ column: SelectMethod<this>;
65
+ distinct: SelectMethod<this>;
66
+ distinctOn: SelectMethod<this>;
67
+ as: AsMethod<this>;
68
+ asProxy(): IQueryBuilder<M, R>;
69
+ where: WhereMethod<this>;
70
+ andWhere: WhereMethod<this>;
71
+ orWhere(...args: any[]): this;
72
+ whereNot: WhereMethod<this>;
73
+ andWhereNot: WhereMethod<this>;
74
+ orWhereNot: WhereMethod<this>;
75
+ whereRaw: WhereRawMethod<this>;
76
+ orWhereRaw: WhereRawMethod<this>;
77
+ andWhereRaw: WhereRawMethod<this>;
78
+ whereWrapped: WhereWrappedMethod<this>;
79
+ havingWrapped: WhereWrappedMethod<this>;
80
+ whereExists: WhereExistsMethod<this>;
81
+ orWhereExists: WhereExistsMethod<this>;
82
+ whereNotExists: WhereExistsMethod<this>;
83
+ orWhereNotExists: WhereExistsMethod<this>;
84
+ whereIn: WhereInMethod<this>;
85
+ orWhereIn: WhereInMethod<this>;
86
+ whereNotIn: WhereInMethod<this>;
87
+ orWhereNotIn: WhereInMethod<this>;
88
+ whereBetween: WhereBetweenMethod<this>;
89
+ orWhereBetween: WhereBetweenMethod<this>;
90
+ andWhereBetween: WhereBetweenMethod<this>;
91
+ whereNotBetween: WhereBetweenMethod<this>;
92
+ orWhereNotBetween: WhereBetweenMethod<this>;
93
+ andWhereNotBetween: WhereBetweenMethod<this>;
94
+ whereNull: WhereNullMethod<this>;
95
+ orWhereNull: WhereNullMethod<this>;
96
+ whereNotNull: WhereNullMethod<this>;
97
+ orWhereNotNull: WhereNullMethod<this>;
98
+ whereColumn: WhereColumnMethod<this>;
99
+ orWhereColumn: WhereColumnMethod<this>;
100
+ andWhereColumn: WhereColumnMethod<this>;
101
+ whereNotColumn: WhereColumnMethod<this>;
102
+ orWhereNotColumn: WhereColumnMethod<this>;
103
+ andWhereNotColumn: WhereColumnMethod<this>;
104
+ whereJsonIsArray: WhereFieldExpressionMethod<this>;
105
+ orWhereJsonIsArray: WhereFieldExpressionMethod<this>;
106
+ whereJsonNotArray: WhereFieldExpressionMethod<this>;
107
+ orWhereJsonNotArray: WhereFieldExpressionMethod<this>;
108
+ whereJsonIsObject: WhereFieldExpressionMethod<this>;
109
+ orWhereJsonIsObject: WhereFieldExpressionMethod<this>;
110
+ whereJsonNotObject: WhereFieldExpressionMethod<this>;
111
+ orWhereJsonNotObject: WhereFieldExpressionMethod<this>;
112
+ whereJsonHasAny: WhereJsonExpressionMethod<this>;
113
+ orWhereJsonHasAny: WhereJsonExpressionMethod<this>;
114
+ whereJsonHasAll: WhereJsonExpressionMethod<this>;
115
+ orWhereJsonHasAll: WhereJsonExpressionMethod<this>;
116
+ having: WhereMethod<this>;
117
+ andHaving: WhereMethod<this>;
118
+ orHaving: WhereMethod<this>;
119
+ havingRaw: WhereRawMethod<this>;
120
+ orHavingRaw: WhereRawMethod<this>;
121
+ havingIn: WhereInMethod<this>;
122
+ orHavingIn: WhereInMethod<this>;
123
+ havingNotIn: WhereInMethod<this>;
124
+ orHavingNotIn: WhereInMethod<this>;
125
+ havingNull: WhereNullMethod<this>;
126
+ orHavingNull: WhereNullMethod<this>;
127
+ havingNotNull: WhereNullMethod<this>;
128
+ orHavingNotNull: WhereNullMethod<this>;
129
+ havingExists: WhereExistsMethod<this>;
130
+ orHavingExists: WhereExistsMethod<this>;
131
+ havingNotExists: WhereExistsMethod<this>;
132
+ orHavingNotExists: WhereExistsMethod<this>;
133
+ havingBetween: WhereBetweenMethod<this>;
134
+ orHavingBetween: WhereBetweenMethod<this>;
135
+ havingNotBetween: WhereBetweenMethod<this>;
136
+ orHavingNotBetween: WhereBetweenMethod<this>;
137
+ union: UnionMethod<this>;
138
+ unionAll: UnionMethod<this>;
139
+ intersect: SetOperationsMethod<this>;
140
+ join: JoinMethod<this>;
141
+ joinRaw: JoinRawMethod<this>;
142
+ innerJoin: JoinMethod<this>;
143
+ leftJoin: JoinMethod<this>;
144
+ leftOuterJoin: JoinMethod<this>;
145
+ rightJoin: JoinMethod<this>;
146
+ rightOuterJoin: JoinMethod<this>;
147
+ outerJoin: JoinMethod<this>;
148
+ fullOuterJoin: JoinMethod<this>;
149
+ crossJoin: JoinMethod<this>;
150
+ orderBy: OrderByMethod<this>;
151
+ orderByRaw: OrderByRawMethod<this>;
152
+ groupBy: GroupByMethod<this>;
153
+ groupByRaw: RawInterface<this>;
154
+ transaction(callback?: TFunction): Promise<Knex.Transaction> | undefined;
155
+ destroy(callback: TFunction): Promise<number>;
156
+ destroy(): Promise<number>;
157
+ clone(): IQueryBuilder<M, R>;
158
+ raw: Knex.RawQueryBuilder<TGeneric, M>;
159
+ get(columns?: string[]): Promise<any>;
160
+ first(columns?: string[]): Promise<M | null | undefined>;
161
+ find(key: string | number, columns?: string[]): Promise<M | null | undefined>;
162
+ insert(attributes: any): Promise<unknown>;
163
+ update(...attributes: any[]): Promise<number>;
164
+ delete(): Promise<boolean | number>;
165
+ exists(): Promise<boolean>;
166
+ count(column?: string): Promise<number>;
167
+ min(column: string): Promise<number>;
168
+ max(column: string): Promise<number>;
169
+ sum(column: string): Promise<number>;
170
+ avg(column: string): Promise<number>;
171
+ skip(count: number): this;
172
+ take(count: number): this;
173
+ limit(count: number): this;
174
+ offset(count: number): this;
175
+ pluck<X extends Model$2 = any>(column: string): Promise<ICollection<X>>;
176
+ chunk(count: number, callback: (rows: M[]) => any): Promise<boolean>;
177
+ forPage(page: number, perPage?: number): this;
178
+ paginate<F extends IPaginatorParams>(page?: number, perPage?: number): Promise<IPaginator<M, F>>;
18
179
  }
19
180
 
20
- /**
21
- * Compose functional mixins
22
- *
23
- * @param Base
24
- * @param mixins
25
- * @returns
26
- */
27
- declare function compose(Base: any, ...mixins: any[]): any;
28
- declare function now(format?: string): string;
29
- declare function getRelationName(relationMethod: any): string;
30
- declare function getScopeName(scopeMethod: any): string;
31
- declare function getRelationMethod(relation: any): string;
32
- declare function getScopeMethod(scope: any): string;
33
- declare function getAttrMethod(attr: any): string;
34
- declare function getGetterMethod(attr: any): string;
35
- declare function getSetterMethod(attr: any): string;
36
- declare function getAttrName(attrMethod: any): any;
37
- declare function tap(instance: any, callback: any): any;
38
- declare function flattenDeep(arr: any): any;
39
- declare function kebabCase(str: any): string;
40
- declare function snakeCase(str: any): string;
181
+ type Operator = string;
182
+ type ColumnRef = string | Raw;
183
+ type FieldExpression = string;
184
+ type TableRef<QB extends AnyQueryBuilder> = ColumnRef | AnyQueryBuilder | CallbackVoid<QB>;
185
+ type Selection<QB extends AnyQueryBuilder> = ColumnRef | AnyQueryBuilder | CallbackVoid<QB>;
186
+ type QBOrCallback<QB extends AnyQueryBuilder> = AnyQueryBuilder | CallbackVoid<QB>;
187
+ interface CallbackVoid<T> {
188
+ (this: T, arg: T): void;
189
+ }
190
+ type Raw = Knex.Raw;
191
+ type OrderByDirection = 'asc' | 'desc' | 'ASC' | 'DESC';
192
+ interface OrderByDescriptor {
193
+ column: ColumnRef;
194
+ order?: OrderByDirection;
195
+ }
196
+ type AnyQueryBuilder<M extends Model$2 = any, R = any> = IQueryBuilder<M, R> | IBuilder<M, R>;
197
+ type Expression<T> = T | Raw | AnyQueryBuilder;
198
+ type ColumnRefOrOrderByDescriptor = ColumnRef | OrderByDescriptor;
199
+ interface RawInterface<R> {
200
+ (sql: string, ...bindings: any[]): R;
201
+ }
202
+ interface BaseSetOperations<QB extends AnyQueryBuilder> {
203
+ (callbackOrBuilder: QBOrCallback<QB>, wrap?: boolean): QB;
204
+ (callbacksOrBuilders: QBOrCallback<QB>[], wrap?: boolean): QB;
205
+ }
206
+ type JoinRawMethod<QB extends AnyQueryBuilder> = RawInterface<QB> & {};
207
+ type OrderByRawMethod<QB extends AnyQueryBuilder> = RawInterface<QB> & {};
208
+ type WhereRawMethod<QB extends AnyQueryBuilder> = RawInterface<QB> & {};
209
+ interface GroupByMethod<QB extends AnyQueryBuilder> {
210
+ (...columns: ColumnRef[]): QB;
211
+ (columns: ColumnRef[]): QB;
212
+ }
213
+ type WithRelationType = {
214
+ [key: string]: <T extends IBuilder<any>>(builder: T) => T | void;
215
+ } | string | string[];
216
+ interface SetOperationsMethod<QB extends AnyQueryBuilder> extends BaseSetOperations<QB> {
217
+ (...callbacksOrBuilders: QBOrCallback<QB>[]): QB;
218
+ }
219
+ interface SelectMethod<QB extends AnyQueryBuilder> {
220
+ <QBP extends QB>(...columns: Selection<QBP>[]): QB;
221
+ <QBP extends QB>(columns: Selection<QBP>[]): QB;
222
+ }
223
+ interface WhereMethod<QB extends AnyQueryBuilder> {
224
+ (col: ColumnRef, op: Operator, expr: Expression<PrimitiveValue>): QB;
225
+ (col: ColumnRef, expr: Expression<PrimitiveValue>): QB;
226
+ (condition: boolean): QB;
227
+ (cb: CallbackVoid<QB>): QB;
228
+ (raw: Raw): QB;
229
+ <QBA extends AnyQueryBuilder>(qb: QBA): QB;
230
+ (obj: object): QB;
231
+ }
232
+ interface WhereWrappedMethod<QB extends AnyQueryBuilder> {
233
+ (cb: CallbackVoid<QB>): QB;
234
+ }
235
+ interface WhereFieldExpressionMethod<QB extends AnyQueryBuilder> {
236
+ (fieldExpression: FieldExpression): QB;
237
+ }
238
+ interface WhereExistsMethod<QB extends AnyQueryBuilder> {
239
+ (cb: CallbackVoid<QB>): QB;
240
+ (raw: Raw): QB;
241
+ <QBA extends AnyQueryBuilder>(qb: QBA): QB;
242
+ }
243
+ interface WhereInMethod<QB extends AnyQueryBuilder> {
244
+ (col: ColumnRef | ColumnRef[], expr: Expression<PrimitiveValue>[]): QB;
245
+ (col: ColumnRef | ColumnRef[], cb: CallbackVoid<QB>): QB;
246
+ (col: ColumnRef | ColumnRef[], qb: AnyQueryBuilder): QB;
247
+ }
248
+ interface WhereBetweenMethod<QB extends AnyQueryBuilder> {
249
+ (column: ColumnRef, range: [Expression<PrimitiveValue>, Expression<PrimitiveValue>]): QB;
250
+ }
251
+ interface WhereNullMethod<QB extends AnyQueryBuilder> {
252
+ (column: ColumnRef): QB;
253
+ }
254
+ interface OrderByMethod<QB extends AnyQueryBuilder> {
255
+ (column: ColumnRef, order?: OrderByDirection): QB;
256
+ (columns: ColumnRefOrOrderByDescriptor[]): QB;
257
+ }
258
+ interface WhereJsonExpressionMethod<QB extends AnyQueryBuilder> {
259
+ (fieldExpression: FieldExpression, keys: string | string[]): QB;
260
+ }
261
+ interface WhereColumnMethod<QB extends AnyQueryBuilder> {
262
+ (col1: ColumnRef, op: Operator, col2: ColumnRef): QB;
263
+ (col1: ColumnRef, col2: ColumnRef): QB;
264
+ }
265
+ interface UnionMethod<QB extends AnyQueryBuilder> extends BaseSetOperations<QB> {
266
+ (arg1: QBOrCallback<QB>, wrap?: boolean): QB;
267
+ (arg1: QBOrCallback<QB>, arg2: QBOrCallback<QB>, wrap?: boolean): QB;
268
+ (arg1: QBOrCallback<QB>, arg2: QBOrCallback<QB>, arg3: QBOrCallback<QB>, wrap?: boolean): QB;
269
+ (arg1: QBOrCallback<QB>, arg2: QBOrCallback<QB>, arg3: QBOrCallback<QB>, arg4: QBOrCallback<QB>, wrap?: boolean): QB;
270
+ (arg1: QBOrCallback<QB>, arg2: QBOrCallback<QB>, arg3: QBOrCallback<QB>, arg4: QBOrCallback<QB>, arg5: QBOrCallback<QB>, wrap?: boolean): QB;
271
+ (arg1: QBOrCallback<QB>, arg2: QBOrCallback<QB>, arg3: QBOrCallback<QB>, arg4: QBOrCallback<QB>, arg5: QBOrCallback<QB>, arg6: QBOrCallback<QB>, wrap?: boolean): QB;
272
+ (arg1: QBOrCallback<QB>, arg2: QBOrCallback<QB>, arg3: QBOrCallback<QB>, arg4: QBOrCallback<QB>, arg5: QBOrCallback<QB>, arg6: QBOrCallback<QB>, arg7: QBOrCallback<QB>, wrap?: boolean): QB;
273
+ }
274
+ interface JoinMethod<QB extends AnyQueryBuilder> {
275
+ (table: TableRef<QB>, leftCol: ColumnRef, op: Operator, rightCol: ColumnRef): QB;
276
+ (table: TableRef<QB>, leftCol: ColumnRef, rightCol: ColumnRef): QB;
277
+ (table: TableRef<QB>, cb: CallbackVoid<Knex.JoinClause>): QB;
278
+ (table: TableRef<QB>, raw: Raw): QB;
279
+ (raw: Raw): QB;
280
+ }
281
+ interface JoinMethod<QB extends AnyQueryBuilder> {
282
+ (table: TableRef<QB>, leftCol: ColumnRef, op: Operator, rightCol: ColumnRef): QB;
283
+ (table: TableRef<QB>, leftCol: ColumnRef, rightCol: ColumnRef): QB;
284
+ (table: TableRef<QB>, cb: CallbackVoid<Knex.JoinClause>): QB;
285
+ (table: TableRef<QB>, raw: Raw): QB;
286
+ (raw: Raw): QB;
287
+ }
41
288
 
42
- declare class arquebus {
43
- static connectorFactory: null;
44
- static instance: null;
45
- static getInstance(): null;
46
- static connection(connection?: null): any;
47
- static setConnectorFactory(connectorFactory: any): void;
48
- static getConnectorFactory(): typeof Knex;
49
- static addConnection(config: any, name?: string): any;
50
- static beginTransaction(connection?: null): any;
51
- static transaction(callback: any, connection?: null): any;
52
- static table(name: any, connection?: null): any;
53
- static schema(connection?: null): any;
54
- static destroyAll(): Promise<void>;
55
- static createModel(name: any, options: any): any;
56
- manager: {};
57
- connections: {};
58
- models: {};
59
- connection(connection?: null): any;
60
- getConnection(name?: null): any;
61
- addConnection(config: any, name?: string): void;
62
- beginTransaction(connection?: null): any;
63
- transaction(callback: any, connection?: null): any;
64
- table(name: any, connection?: null): any;
65
- schema(connection?: null): any;
66
- destroyAll(): Promise<void>;
67
- createModel(name: any, options?: {}): any;
289
+ declare const Inference$2: {
290
+ new <M extends Model$2 = Model$2, R = M[] | M>(): IQueryBuilder<M, R>;
291
+ };
292
+ declare class QueryBuilder<M extends Model$2 = Model$2, R = M[] | M> extends Inference$2<M, R> {
293
+ model: M;
294
+ schema: SchemaBuilder;
295
+ private connector;
296
+ constructor(config: TConfig | null, connector: TFunction);
297
+ asProxy(): any;
298
+ beginTransaction(): Promise<Knex.Transaction<any, any[]> | undefined>;
299
+ table<X extends M>(table: string): IQueryBuilder<X, R>;
300
+ transaction(callback?: TFunction): Promise<Knex.Transaction> | undefined;
301
+ find(id: string | number, columns?: string[]): Promise<any>;
302
+ get(_columns?: string[]): Promise<any>;
303
+ exists(): Promise<boolean>;
304
+ skip(this: any, ...args: any[]): any;
305
+ take(this: any, ...args: any[]): any;
306
+ chunk(count: number, callback: TFunction): Promise<boolean>;
307
+ paginate<F extends IPaginatorParams>(this: any, page?: number, perPage?: number): Promise<IPaginator<M, F>>;
308
+ forPage(this: any, page?: number, perPage?: number): any;
309
+ toSQL(...args: Parameters<typeof this$1.connector.toSQL>): Knex.Sql;
310
+ count(column: string): Promise<number>;
311
+ min(column: string): Promise<number>;
312
+ max(column: string): Promise<number>;
313
+ sum(column: string): Promise<number>;
314
+ avg(column: string): Promise<number>;
315
+ clone(): IQueryBuilder<M, R>;
316
+ delete(): Promise<number | boolean>;
317
+ insert(...args: Parameters<typeof this$1.connector.insert>): Promise<unknown>;
318
+ update(...args: Parameters<typeof this$1.connector.update>): Promise<number>;
319
+ destroy(...args: Parameters<typeof this$1.connector.destroy>): Promise<number>;
320
+ get _statements(): IStatement[] & any[];
321
+ get _single(): any;
322
+ get from(): Knex.Table<any, any>;
323
+ }
324
+
325
+ declare class Relation$1 {
326
+ query: QueryBuilder;
327
+ parent: any;
328
+ related: any;
329
+ eagerKeysWereEmpty: boolean;
330
+ static constraints: boolean;
331
+ static selfJoinCount: number;
332
+ constructor(query: any, parent: any);
333
+ static extend(trait: Record<string, any>): void;
334
+ static noConstraints(callback: () => any): any;
335
+ asProxy(): any;
336
+ getRelated(): any;
337
+ getKeys(models: any[], key?: string | null): any[];
338
+ getRelationQuery(): any;
339
+ whereInEager(whereIn: string, key: string, modelKeys: any[], query?: any): void;
340
+ whereInMethod(model: any, key: string): string;
341
+ getEager(): any;
342
+ get(columns?: string | string[]): Promise<any>;
343
+ first(columns?: string[]): Promise<any>;
344
+ paginate(...args: any[]): Promise<any>;
345
+ count(...args: any[]): Promise<any>;
346
+ toSql(): string;
347
+ addConstraints(): void;
348
+ getRelationCountHash(incrementJoinCount?: boolean): string;
349
+ getRelationExistenceQuery(query: any, parentQuery: any, columns?: string[]): any;
350
+ getRelationExistenceCountQuery(query: any, parentQuery: any): any;
351
+ getQualifiedParentKeyName(): string;
352
+ getExistenceCompareKey(this: any): string;
68
353
  }
69
354
 
70
- declare class Paginator {
71
- static formatter: null;
72
- static setFormatter(formatter: any): void;
73
- constructor(items: any, total: any, perPage: any, currentPage?: null, options?: {});
74
- _items: any;
75
- _total: any;
355
+ interface TBaseConfig {
356
+ client: 'mysql' | 'mysql2' | 'sqlite3' | 'oracle' | 'mariadb' | 'pg';
357
+ connection: {
358
+ typeCast?(field: TField, next: TFunction): any;
359
+ dateStrings?: boolean;
360
+ };
361
+ pool?: {
362
+ afterCreate: (connection: TConfig, callback: (val: any, con: any) => void) => Promise<any>;
363
+ } | undefined;
364
+ connections?: arquebus['connections'];
365
+ migrations?: {
366
+ table: string;
367
+ path: string;
368
+ };
369
+ factories?: {
370
+ path: string;
371
+ };
372
+ seeders?: {
373
+ path: string;
374
+ };
375
+ models?: {
376
+ path: string;
377
+ };
378
+ }
379
+ type TConfig = TBaseConfig & ({
380
+ client: 'pg';
381
+ connection: Knex.PgConnectionConfig;
382
+ } | {
383
+ client: 'oracle';
384
+ connection: Knex.OracleDbConnectionConfig;
385
+ } | {
386
+ client: 'mysql2';
387
+ connection: Knex.MySql2ConnectionConfig;
388
+ } | {
389
+ client: 'mysql';
390
+ connection: Knex.MySqlConnectionConfig;
391
+ } | {
392
+ client: 'sqlite3';
393
+ connection: Knex.Sqlite3ConnectionConfig;
394
+ useNullAsDefault?: boolean;
395
+ } | {
396
+ client: 'mariadb';
397
+ connection: Knex.MariaSqlConnectionConfig;
398
+ useNullAsDefault?: boolean;
399
+ });
400
+ interface ModelOptions<M extends Model$2 = Model$2> {
401
+ table?: string;
402
+ scopes?: TGeneric<(...args: any[]) => Builder<M>>;
403
+ plugins?: (<X extends MixinConstructor<M>>(Model: X) => MixinConstructor<M>)[];
404
+ relations?: TGeneric<(...args: any[]) => Relation$1>;
405
+ attributes?: TGeneric<Attribute$1>;
406
+ CREATED_AT?: string;
407
+ UPDATED_AT?: string;
408
+ DELETED_AT?: string;
409
+ connection?: TBaseConfig['client'];
410
+ timestamps?: boolean;
411
+ primaryKey?: string;
412
+ incrementing?: boolean;
413
+ keyType?: 'int' | 'string';
414
+ with?: Model$2['with'];
415
+ casts?: Model$2['casts'];
416
+ }
417
+ interface TField {
418
+ type: 'VAR_STRING' | 'BLOB' | 'DATETIME' | 'TIMESTAMP' | 'LONG' | 'JSON';
419
+ length: number;
420
+ db: string;
421
+ table: string;
422
+ name: string;
423
+ string: TFunction;
424
+ buffer: TFunction;
425
+ geometry: TFunction;
426
+ }
427
+
428
+ interface Attribute$1 {
429
+ make(config: {
430
+ get?: TFunction | null;
431
+ set?: TFunction | null;
432
+ }): Attribute$1;
433
+ get: TFunction | null;
434
+ set: TFunction | null;
435
+ withCaching?: boolean;
436
+ withObjectCaching?: boolean;
437
+ }
438
+ type Relation<M extends Model$2> = IBuilder<M, any> & {};
439
+ interface HasOneOrMany<M extends Model$2> extends Relation<M> {
440
+ save(model: M): Promise<M>;
441
+ saveMany(models: M[] | ICollection<M>): Promise<ICollection<M>>;
442
+ create(attributes?: any): Promise<M>;
443
+ createMany(records: any[]): Promise<ICollection<M>>;
444
+ }
445
+ interface HasOne<M extends Model$2> extends HasOneOrMany<M> {
446
+ getResults(): Promise<M | null>;
447
+ withDefault(callback?: TFunction | object): this;
448
+ }
449
+ interface HasMany<M extends Model$2> extends HasOneOrMany<M> {
450
+ getResults(): Promise<ICollection<M>>;
451
+ }
452
+ interface BelongsTo<M extends Model$2> extends Relation<M> {
453
+ getResults(): Promise<M | null>;
454
+ withDefault(callback?: TFunction | object): this;
455
+ }
456
+ interface BelongsToMany<M extends Model$2> extends Relation<M> {
457
+ getResults(): Promise<ICollection<M>>;
458
+ withTimestamps(): this;
459
+ wherePivot(column: any, operator?: any, value?: any, boolean?: string, ...args: any[]): this;
460
+ wherePivotBetween(column: any, values: any, boolean?: string, not?: boolean): this;
461
+ orWherePivotBetween(column: any, values: any): this;
462
+ wherePivotNotBetween(column: any, values: any, boolean?: string): this;
463
+ orWherePivotNotBetween(column: any, values: any): this;
464
+ wherePivotIn(column: any, values: any, boolean?: string, not?: boolean): this;
465
+ orWherePivot(column: any, operator?: any, value?: any): this;
466
+ orWherePivotIn(column: any, values: any): this;
467
+ wherePivotNotIn(column: any, values: any, boolean?: string): this;
468
+ orWherePivotNotIn(column: any, values: any): this;
469
+ wherePivotNull(column: any, boolean?: string, not?: boolean): this;
470
+ wherePivotNotNull(column: any, boolean?: string): this;
471
+ orWherePivotNull(column: any, not?: boolean): this;
472
+ orWherePivotNotNull(column: any): this;
473
+ orderByPivot(column: any, direction?: string): this;
474
+ }
475
+ interface IModel {
476
+ [value: string]: any;
477
+ attributes: any;
478
+ relations: any;
479
+ exists: boolean;
480
+ primaryKey: string;
481
+ builder?: IBuilder<any, any> | null;
482
+ table: string | null;
483
+ connection?: TBaseConfig['client'] | null;
484
+ keyType: string;
485
+ incrementing: boolean;
486
+ perPage: number;
487
+ with: string | string[] | TGeneric<(...args: any[]) => IBuilder<Model$2>>;
488
+ withCount: string[];
489
+ trx: AnyQueryBuilder | null;
490
+ timestamps: boolean;
491
+ dateFormat: string;
492
+ visible: string[];
493
+ hidden: string[];
494
+ query<T extends {
495
+ prototype: unknown;
496
+ }>(this: T, client?: AnyQueryBuilder | null): IBuilder<Model$2>;
497
+ on<T extends {
498
+ prototype: unknown;
499
+ }>(this: T, connection: string | null): IBuilder<Model$2>;
500
+ boot(): void;
501
+ make<T extends IModel>(this: new () => T, attributes?: TGeneric): T;
502
+ addHook(hook: Hook, callback: TFunction): void;
503
+ creating(callback: TFunction): void;
504
+ created(callback: TFunction): void;
505
+ updating(callback: TFunction): void;
506
+ updated(callback: TFunction): void;
507
+ deleting(callback: TFunction): void;
508
+ deleted(callback: TFunction): void;
509
+ saving(callback: TFunction): void;
510
+ saved(callback: TFunction): void;
511
+ restoring(callback: TFunction): void;
512
+ restored(callback: TFunction): void;
513
+ trashed(callback: TFunction): void;
514
+ forceDeleted(callback: TFunction): void;
515
+ bootIfNotBooted(): void;
516
+ initialize(): void;
517
+ initializePlugins(): void;
518
+ addPluginInitializer(method: any): void;
519
+ newInstance(attributes?: TGeneric, exists?: boolean): any;
520
+ getKey(): string | number | null | undefined;
521
+ getKeyName(): string;
522
+ getConnectionName(): string;
523
+ getConnection(): any;
524
+ setConnection(connection: TBaseConfig['client'] | null): this;
525
+ usesUniqueIds(): boolean;
526
+ uniqueIds(): string[];
527
+ newUniqueId(): string;
528
+ setUniqueIds(): void;
529
+ getKeyType(): string;
530
+ getIncrementing(): boolean;
531
+ setIncrementing(value: boolean): this;
532
+ getTable(): string;
533
+ setTable(table: string): this;
534
+ getDates(): string[];
535
+ getDateFormat(): string;
536
+ getAttributes(): object;
537
+ getAttribute(key: string): any;
538
+ setAttribute(key: string, value: any): this;
539
+ fill(attributes: any): this;
540
+ setAppends(appends: string[]): this;
541
+ append(key: string | string[]): this;
542
+ getRelation<T extends Model$2>(relation: string): T | ICollection<T> | null | undefined;
543
+ setRelation<T extends Model$2>(relation: string, value: T | ICollection<T> | null): this;
544
+ unsetRelation(relation: string): this;
545
+ relationLoaded(relation: string): boolean;
546
+ makeVisible(attributes: string | string[]): this;
547
+ makeHidden(attributes: string | string[]): this;
548
+ newCollection(models?: any[]): ICollection<Model$2>;
549
+ load(relations: WithRelationType): Promise<this>;
550
+ load(...relations: WithRelationType[]): Promise<this>;
551
+ loadAggregate(relations: WithRelationType, column: any, callback?: any): Promise<this>;
552
+ loadCount(...relations: WithRelationType[]): Promise<this>;
553
+ loadMax(relations: WithRelationType, column: string): Promise<this>;
554
+ loadMin(relations: WithRelationType, column: string): Promise<this>;
555
+ loadSum(relations: WithRelationType, column: string): Promise<this>;
556
+ usesTimestamps(): boolean;
557
+ updateTimestamps(): this;
558
+ getCreatedAtColumn(): string;
559
+ getUpdatedAtColumn(): string;
560
+ getDeletedAtColumn(): string;
561
+ setCreatedAt(value: string): this;
562
+ setUpdatedAt(value: string): this;
563
+ freshTimestamp(): Date;
564
+ freshTimestampString(): string;
565
+ fromDateTime(value: Date | number | null): string;
566
+ useSoftDeletes(): boolean;
567
+ toData(): any;
568
+ attributesToData(): any;
569
+ relationsToData(): any;
570
+ toJSON(): any;
571
+ toJson(): string;
572
+ toString(): string;
573
+ isDirty(attributes?: string | string[]): boolean;
574
+ getDirty(): string[];
575
+ save(options?: any): Promise<boolean>;
576
+ update(attributes?: any, options?: any): Promise<boolean>;
577
+ increment(column: string, amount?: number, extra?: any): Promise<boolean>;
578
+ decrement(column: string, amount?: number, extra?: any): Promise<boolean>;
579
+ serializeDate(date: any): string;
580
+ delete(options?: any): Promise<boolean>;
581
+ softDelete(options?: any): Promise<boolean>;
582
+ forceDelete(options?: any): Promise<boolean>;
583
+ restore(options?: any): Promise<boolean>;
584
+ trashed(): boolean;
585
+ fresh(): Promise<this>;
586
+ refresh(): Promise<this | undefined>;
587
+ push(): Promise<boolean>;
588
+ is(model: this): boolean;
589
+ isNot(model: this): boolean;
590
+ related<T extends RelationNames<this>>(relation: T): ReturnTypeOfMethod<this, `relation${Capitalize<SnakeToCamelCase<T>>}`>;
591
+ getRelated<T extends RelationNames<this>>(relation: T): ReturnTypeOfMethod<ReturnTypeOfMethod<this, `relation${Capitalize<SnakeToCamelCase<T>>}`>, any>;
592
+ hasOne<T extends Model$2>(model: new () => T, foreignKey?: string, localKey?: string): HasOne<T>;
593
+ hasMany<T extends Model$2>(model: new () => T, foreignKey?: string, localKey?: string): HasMany<T>;
594
+ belongsTo<T extends Model$2>(model: new () => T, foreignKey?: string, ownerKey?: string, relation?: string): BelongsTo<T>;
595
+ belongsToMany<T extends Model$2>(model: new () => T, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string): BelongsToMany<T>;
596
+ }
597
+
598
+ declare class Paginator<T extends Model$2, K extends IPaginatorParams = IPaginatorParams> implements IPaginator<T, K> {
599
+ static formatter: (paginator: IPaginator<any>) => any | null;
600
+ _items: Collection$1<T>;
601
+ _total: number;
76
602
  _perPage: number;
77
603
  _lastPage: number;
78
- _currentPage: any;
79
- options: {};
80
- setItems(items: any): void;
81
- hasMore: boolean | undefined;
604
+ _currentPage: number;
605
+ hasMore: boolean;
606
+ options: TGeneric;
607
+ static setFormatter(formatter: (paginator: IPaginator<any>) => any | null): void;
608
+ constructor(items: T[], total: number, perPage: number, currentPage?: number, options?: TGeneric);
609
+ setItems(items: T[]): void;
82
610
  firstItem(): number | null;
83
611
  lastItem(): number | null;
84
612
  hasMorePages(): boolean;
85
- get(index: any): any;
86
- count(): any;
87
- items(): any;
88
- map(callback: any): any;
89
- currentPage(): any;
613
+ get(index: number): T | null;
614
+ count(): number;
615
+ items(): Collection$1<T>;
616
+ map(callback: (value: T, index: number) => T): Collection$1<T>;
617
+ currentPage(): number;
90
618
  onFirstPage(): boolean;
91
619
  perPage(): number;
92
620
  lastPage(): number;
93
- total(): any;
621
+ total(): number;
94
622
  toData(): any;
95
623
  toJSON(): any;
96
624
  toJson(...args: any[]): string;
97
625
  }
98
626
 
99
- declare class Collection extends Collection$1<any> {
100
- constructor(collection?: Object | any[] | undefined);
101
- load(...relations: any[]): Promise<any>;
102
- loadAggregate(relations: any, column: any, action?: null): Promise<this>;
103
- loadCount(relations: any): Promise<this>;
104
- loadMax(relation: any, column: any): Promise<this>;
105
- loadMin(relation: any, column: any): Promise<this>;
106
- loadSum(relation: any, column: any): Promise<this>;
107
- loadAvg(relation: any, column: any): Promise<this>;
108
- mapThen(callback: any): Promise<any[]>;
109
- modelKeys(): any[];
110
- contains(key: any, operator?: null, value?: null, ...args: any[]): boolean;
111
- diff(items: any): any;
112
- except(keys: any): any;
113
- intersect(items: any): any;
114
- unique(key?: null, strict?: boolean): any;
115
- find(key: any, defaultValue?: null): any;
116
- fresh(...args: any[]): Promise<any>;
117
- makeVisible(attributes: any): this;
118
- makeHidden(attributes: any): this;
119
- append(attributes: any): this;
120
- only(keys: any): any;
121
- getDictionary(items?: null): {};
122
- toQuery(): any;
123
- toData(): any[];
124
- toJSON(): any[];
125
- toJson(...args: any[]): string;
126
- [Symbol.iterator](): {
127
- next(): {
128
- value: any;
129
- done: boolean;
130
- } | {
131
- done: boolean;
132
- value?: undefined;
133
- };
134
- };
135
- }
136
-
137
- declare class QueryBuilder {
138
- constructor(config: any, connector: any);
139
- connector: null;
140
- asProxy(): any;
141
- beginTransaction(): Promise<QueryBuilder>;
142
- table(table: any): QueryBuilder;
143
- transaction(callback: any): any;
144
- find(id: any, columns?: string[]): Promise<any>;
145
- get(columns?: string[]): Promise<null>;
146
- exists(): Promise<boolean>;
147
- skip(...args: any[]): any;
148
- take(...args: any[]): any;
149
- chunk(count: any, callback: any): Promise<boolean>;
150
- paginate(page?: number, perPage?: number): Promise<Paginator>;
151
- forPage(page?: number, perPage?: number): any;
152
- toSQL(...args: any[]): any;
153
- count(column: any): Promise<number>;
154
- min(column: any): Promise<number>;
155
- max(column: any): Promise<number>;
156
- sum(column: any): Promise<number>;
157
- avg(column: any): Promise<number>;
158
- clone(): QueryBuilder;
159
- delete(): Promise<any>;
160
- insert(...args: any[]): Promise<any>;
161
- update(...args: any[]): Promise<any>;
162
- destroy(...args: any[]): any;
163
- get _statements(): any;
164
- get _single(): any;
165
- get from(): any;
627
+ declare class Scope<M extends Model$2 = Model$2> implements IScope {
628
+ constructor();
629
+ apply(_builder: Builder<M>, _model: M): void;
166
630
  }
167
631
 
168
- declare class Builder {
169
- constructor(query: any);
170
- query: any;
632
+ declare const Inference$1: {
633
+ new <M extends Model$2 = Model$2, R = IModel | ICollection<M>>(): IBuilder<M, R>;
634
+ };
635
+ declare class Builder<M extends Model$2 = Model$2, R = IModel | ICollection<M>> extends Inference$1 {
636
+ query: IBuilder<M, R>;
171
637
  connection: any;
172
- model: any;
173
- actions: any;
174
- localMacros: {};
175
- eagerLoad: {};
176
- globalScopes: {};
177
- asProxy(): any;
638
+ model: M;
639
+ actions: any[];
640
+ localMacros: TGeneric<(...args: any[]) => any, keyof Omit<IBuilder<M, R>, number>>;
641
+ eagerLoad: TGeneric<(...args: any[]) => any>;
642
+ globalScopes: TGeneric<Scope<M> | ((arg: Builder<M, R>) => Builder<M, R>)>;
643
+ onDeleteCallback?: (builder: Builder<M, R>) => Promise<boolean | number>;
644
+ constructor(query: IBuilder<M, R>);
645
+ asProxy(): Builder<M, R>;
178
646
  orWhere(...args: any[]): this;
179
- chunk(count: any, callback: any): Promise<boolean>;
180
- enforceOrderBy(): void;
181
- clone(): any;
182
- forPage(page: any, perPage?: number): any;
183
- insert(...args: any[]): any;
184
- update(values: any): any;
185
- increment(column: any, amount?: number, extra?: {}): any;
186
- decrement(column: any, amount?: number, extra?: {}): any;
187
- addUpdatedAtColumn(values: any): any;
188
- delete(): any;
189
- onDelete(callback: any): void;
190
- onDeleteCallback: any;
191
- forceDelete(): any;
647
+ chunk<C extends TFunction>(count: number, callback: C): Promise<boolean>;
648
+ enforceOrderBy(this: any): void;
649
+ clone(this: any): any;
650
+ forPage(this: any, page: number, perPage?: number): any;
651
+ insert(...args: Parameters<typeof this$1.query.insert>): Promise<any>;
652
+ update<T extends TGeneric>(values: T): Promise<any>;
653
+ increment(column: string, amount?: number, extra?: {}): Promise<any>;
654
+ decrement(column: string, amount?: number, extra?: {}): Promise<any>;
655
+ addUpdatedAtColumn(values: TGeneric<string>): TGeneric<string>;
656
+ delete(): Promise<number | boolean>;
657
+ onDelete<C extends TFunction<any, Promise<number | boolean>>>(callback: C): void;
658
+ forceDelete(): Promise<number | boolean>;
192
659
  create(attributes?: {}): Promise<any>;
193
660
  newModelInstance(attributes?: {}): any;
194
- getQuery(): any;
195
- getModel(): any;
196
- setModel(model: any): this;
197
- qualifyColumn(column: any): any;
198
- setTable(table: any): this;
661
+ getQuery(): IBuilder<M, R>;
662
+ getModel(): M;
663
+ setModel<MO extends Model$2>(model: MO): this;
664
+ qualifyColumn(column: string): string;
665
+ setTable(table: string): this;
199
666
  applyScopes(): this;
200
- hasNamedScope(name: any): any;
201
- callNamedScope(scope: any, parameters: any): any;
202
- callScope(scope: any, parameters?: any[]): any;
203
- scopes(scopes: any): this;
204
- withGlobalScope(identifier: any, scope: any): this;
205
- withoutGlobalScope(scope: any): this;
206
- macro(name: any, callback: any): void;
207
- hasMacro(name: any): boolean;
208
- getMacro(name: any): any;
667
+ hasNamedScope(name: string): boolean;
668
+ callNamedScope(scope: string, parameters: any[]): any;
669
+ callScope(scope: (builder: this, ...args: any[]) => this, parameters?: never[]): this;
670
+ scopes(scopes: string[]): this;
671
+ withGlobalScope(identifier: string, scope: any): this;
672
+ withoutGlobalScope(scope: Scope | string): this;
673
+ macro<N extends string>(name: N, callback: (builder: TGeneric & IBuilder<M>, attrs: any, vals: any) => any): this;
674
+ hasMacro(name: string): boolean;
675
+ getMacro(name: string): (...args: any[]) => any;
209
676
  with(...args: any[]): this;
210
- has(relation: any, operator?: string, count?: number, boolean?: string, callback?: null): any;
677
+ has(relation: any, operator?: string, count?: number, boolean?: string, callback?: TFunction | null): any;
211
678
  orHas(relation: any, operator?: string, count?: number): any;
212
- doesntHave(relation: any, boolean?: string, callback?: null): any;
679
+ doesntHave(relation: any, boolean?: string, callback?: TFunction | null): any;
213
680
  orDoesntHave(relation: any): any;
214
- whereHas(relation: any, callback?: null, operator?: string, count?: number): any;
215
- orWhereHas(relation: any, callback?: null, operator?: string, count?: number): any;
681
+ whereHas(relation: any, callback?: TFunction | null, operator?: string, count?: number): any;
682
+ orWhereHas(relation: any, callback?: TFunction | null, operator?: string, count?: number): any;
216
683
  whereRelation(relation: any, ...args: any[]): any;
217
684
  orWhereRelation(relation: any, ...args: any[]): any;
218
- hasNested(relations: any, operator?: string, count?: number, boolean?: string, callback?: null): any;
219
- canUseExistsForExistenceCheck(operator: any, count: any): boolean;
220
- addHasWhere(hasQuery: any, relation: any, operator: any, count: any, boolean: any): any;
221
- addWhereExistsQuery(query: any, boolean?: string, not?: boolean): this;
222
- addWhereCountQuery(query: any, operator?: string, count?: number, boolean?: string): any;
223
- withAggregate(relations: any, column: any, action?: null): this;
685
+ hasNested(relations: any, operator?: string, count?: number, boolean?: string, callback?: TFunction | null): any;
686
+ canUseExistsForExistenceCheck(operator: string, count: number): boolean;
687
+ addHasWhere(hasQuery: any, relation: any, operator: string, count: number, boolean: string): any;
688
+ addWhereExistsQuery(this: any, query: any, boolean?: string, not?: boolean): any;
689
+ addWhereCountQuery(this: any, query: any, operator?: string, count?: number, boolean?: string): any;
690
+ withAggregate(relations: any, column: string, action?: string | null): this;
224
691
  toSql(): any;
225
- mergeConstraintsFrom(from: any): any;
226
- selectSub(query: any, as: any): any;
692
+ mergeConstraintsFrom(_from: any): this;
693
+ selectSub(query: Builder<M>, as: string): any;
227
694
  createSub(query: any): any[];
228
695
  parseSub(query: any): any[];
229
696
  prependDatabaseNameIfCrossDatabaseQuery(query: any): any;
230
- getRelationWithoutConstraints(relation: any): any;
697
+ getRelationWithoutConstraints(relation: string): any;
231
698
  withCount(...args: any[]): this;
232
- withMax(relation: any, column: any): this;
233
- withMin(relation: any, column: any): this;
234
- withAvg(relation: any, column: any): this;
235
- withSum(relation: any, column: any): this;
699
+ withMax(relation: any, column: string): this;
700
+ withMin(relation: any, column: string): this;
701
+ withAvg(relation: any, column: string): this;
702
+ withSum(relation: any, column: string): this;
236
703
  withExists(relation: any): this;
237
- parseWithRelations(relations: any): {};
238
- addNestedWiths(name: any, results: any): any;
239
- prepareNestedWithRelationships(relations: any, prefix?: string): {};
240
- combineConstraints(constraints: any): (builder: any) => any;
241
- parseNameAndAttributeSelectionConstraint(name: any, value: any): any[];
242
- createSelectWithConstraint(name: any): any[];
243
- related(relation: any): any;
244
- take(...args: any[]): any;
245
- skip(...args: any[]): any;
246
- first(...columns: any[]): Promise<any>;
247
- firstOrFail(...columns: any[]): Promise<any>;
248
- findOrFail(ids: any, columns?: string): Promise<any>;
249
- findOrNew(id: any, columns?: string[]): Promise<any>;
250
- firstOrNew(attributes?: {}, values?: {}): Promise<any>;
251
- firstOrCreate(attributes?: {}, values?: {}): Promise<any>;
252
- updateOrCreate(attributes: any, values?: {}): Promise<any>;
253
- latest(column?: null): this;
254
- oldest(column?: null): this;
255
- find(id: any, columns?: string): Promise<any>;
256
- findMany(ids: any, columns?: string): Promise<any>;
257
- pluck(column: any): Promise<Collection>;
258
- destroy(ids: any, ...args: any[]): Promise<number>;
259
- get(columns?: string): Promise<Collection>;
260
- all(columns?: string): Promise<any>;
261
- paginate(page: any, perPage: any): Promise<Paginator>;
704
+ parseWithRelations(relations: TGeneric): TGeneric | never[];
705
+ addNestedWiths(name: string, results: TGeneric): TGeneric;
706
+ prepareNestedWithRelationships(relations: TGeneric, prefix?: string): TGeneric;
707
+ combineConstraints(constraints: TFunction[]): (builder: Builder<M>) => Builder<M, IModel | ICollection<M>>;
708
+ parseNameAndAttributeSelectionConstraint(name: string, value: string): (string | ((query: any) => void))[];
709
+ createSelectWithConstraint(name: string): (string | ((query: any) => void))[];
710
+ related(relation: string): any;
711
+ take(this: any, ...args: any[]): any;
712
+ skip(this: any, ...args: any[]): any;
713
+ first(this: any, ...columns: any[]): Promise<M | null>;
714
+ firstOrFail(...columns: any[]): Promise<M>;
715
+ findOrFail(this: any, ...args: any[]): Promise<M>;
716
+ findOrNew(id: string, columns?: string[]): Promise<any>;
717
+ firstOrNew(this: any, attributes?: {}, values?: {}): Promise<any>;
718
+ firstOrCreate(this: any, attributes?: TGeneric, values?: {}): Promise<any>;
719
+ updateOrCreate(attributes: TGeneric, values?: {}): Promise<any>;
720
+ latest(column?: string): this;
721
+ oldest(column?: string): this;
722
+ find(this: any, id: string | number | Collection$1<M>, columns?: string[]): Promise<any>;
723
+ findMany(this: any, ids: string[] | number[] | ICollection<any>, columns?: string[]): Promise<any>;
724
+ pluck(column: string): Promise<any>;
725
+ destroy(this: any, ids?: (string | number)[] | TFunction | Collection$1<M>): Promise<number>;
726
+ get<M extends Model$2>(columns?: string | string[]): Promise<Collection$1<M>>;
727
+ all(columns?: string[]): Promise<any>;
728
+ paginate(this: any, page?: number, perPage?: number): Promise<Paginator<any, IPaginatorParams>>;
262
729
  getModels(...columns: any[]): Promise<any[]>;
263
- getRelation(name: any): any;
264
- relationsNestedUnder(relation: any): {};
265
- isNestedUnder(relation: any, name: any): any;
266
- eagerLoadRelation(models: any, name: any, constraints: any): Promise<any>;
267
- eagerLoadRelations(models: any): Promise<any>;
268
- hydrate(items: any): Collection;
730
+ getRelation(name: string): any;
731
+ relationsNestedUnder(relation: string): TGeneric;
732
+ isNestedUnder(relation: string, name: string): boolean;
733
+ eagerLoadRelation<M extends Model$2>(models: M[], name: string, constraints: any): Promise<any>;
734
+ eagerLoadRelations<M extends Model$2>(models: M[]): Promise<M[]>;
735
+ hydrate(items: any[]): Collection$1<any>;
736
+ }
737
+
738
+ interface IScope {
739
+ apply(builder: Builder<any>, model: Model$2): void;
740
+ }
741
+ interface IBuilder<M extends Model$2 | Model$1, R = ICollection<M> | IModel> extends IQueryBuilder<M, R> {
742
+ asProxy(): IQueryBuilder<M, R>;
743
+ enforceOrderBy(): void;
744
+ insert(attributes: any): Promise<any>;
745
+ update(attributes: any): Promise<any>;
746
+ increment(column: string, amount?: number, extra?: any): Promise<any>;
747
+ decrement(column: string, amount?: number, extra?: any): Promise<any>;
748
+ addUpdatedAtColumn(values: any): any;
749
+ delete(): Promise<boolean | number>;
750
+ softDelete(): boolean | Promise<any>;
751
+ forceDelete(): boolean | Promise<any>;
752
+ restore(): boolean | Promise<any>;
753
+ withTrashed(): this;
754
+ withoutTrashed(): this;
755
+ onlyTrashed(): this;
756
+ getDeletedAtColumn(): string;
757
+ create(attributes?: any): Promise<M>;
758
+ newModelInstance(attributes?: any): M;
759
+ count(columns?: string): Promise<number>;
760
+ getQuery(): AnyQueryBuilder;
761
+ getModel(): M;
762
+ setModel(model: M): this;
763
+ setTable(table: string): this;
764
+ applyScopes(): this;
765
+ scopes(scopes: string[]): this;
766
+ withGlobalScope(identifier: string | number, scope: string | (() => void)): this;
767
+ withoutGlobalScope(scope: IScope | string): this;
768
+ with(relation: WithRelationType): this;
769
+ with(...relations: WithRelationType[]): this;
770
+ has(relation: string, operator?: any, count?: number, boolean?: any, callback?: (builder: IBuilder<any>) => void | null): this;
771
+ orHas(relation: string, operator?: any, count?: number): this;
772
+ doesntHave(relation: string, boolean?: any, callback?: (builder: IBuilder<any>) => void | null): this;
773
+ orDoesntHave(relation: string): this;
774
+ whereHas(relation: string, callback?: (builder: IBuilder<any>) => void | IBuilder<any> | null, operator?: any, count?: number): this;
775
+ orWhereHas(relation: string, callback?: (builder: IBuilder<any>) => void | IBuilder<any> | null, operator?: any, count?: number): this;
776
+ whereRelation(relation: string, column: string, operator?: any, value?: any): this;
777
+ hasNested(relation: string, operator?: any, count?: number, boolean?: any, callback?: (builder: IBuilder<any>) => void | null): this;
778
+ canUseExistsForExistenceCheck(operator: string, count: number): boolean;
779
+ addHasWhere(hasQuery: IBuilder<any>, relation: string, operator?: string, count?: number, boolean?: string): this;
780
+ withAggregate(relations: string | string[] | object, column: string, action?: string | null): this;
781
+ toSql(): object;
782
+ withCount(...relations: WithRelationType[]): this;
783
+ withMax(relation: WithRelationType, column: string): this;
784
+ withMin(relation: WithRelationType, column: string): this;
785
+ withAvg(relation: WithRelationType, column: string): this;
786
+ withSum(relation: WithRelationType, column: string): this;
787
+ withExists(relation: WithRelationType): this;
788
+ related(relation: string): this;
789
+ first(column?: string | string[]): Promise<M | null | undefined>;
790
+ firstOrFail(column?: string | string[]): Promise<M>;
791
+ findOrFail(key: string | number, columns?: string[]): Promise<M>;
792
+ findOrFail(key: string[] | number[] | ICollection<any>, columns?: string[]): Promise<M>;
793
+ findOrFail(key: string | number | string[] | number[] | ICollection<any>, columns?: string[]): Promise<M>;
794
+ findOrNew(id: string | number, columns?: string[]): Promise<M>;
795
+ firstOrNew(attributes?: object, values?: object): Promise<M>;
796
+ firstOrCreate(attributes?: object, values?: object): Promise<M>;
797
+ updateOrCreate(attributes: object, values?: object): Promise<M>;
798
+ latest(column?: string): this;
799
+ oldest(column?: string): this;
800
+ find(key: string | number, columns?: string[]): Promise<M | null | undefined>;
801
+ findMany(keys: string[] | number[] | ICollection<any>, columns?: string[]): Promise<ICollection<M>>;
802
+ pluck<X extends Model$2 = any | M>(column: string): Promise<ICollection<X>>;
803
+ all(columns?: string[]): Promise<ICollection<M>>;
804
+ paginate<F extends IPaginatorParams>(page?: number, perPage?: number): Promise<IPaginator<M, F>>;
805
+ [value: string]: any;
806
+ }
807
+
808
+ interface ICollection<T extends Model$2 | Model$1> extends Collection$2<T> {
809
+ items?: T[];
810
+ load(...relations: T[]): Promise<ICollection<T>>;
811
+ loadAggregate(relations: T | T[], column: string, action?: string | null): Promise<this>;
812
+ loadCount(relation: T, column: string): Promise<this>;
813
+ loadMax(relation: T, column: string): Promise<this>;
814
+ loadMin(relation: T, column: string): Promise<this>;
815
+ loadSum(relation: T, column: string): Promise<this>;
816
+ loadAvg(relation: T, column: string): Promise<this>;
817
+ mapThen(callback: () => void): Promise<any>;
818
+ modelKeys(): string[] | number[];
819
+ contains(key: IModel | any, operator?: any, value?: any): boolean;
820
+ diff(items: ICollection<T> | any[]): ICollection<T>;
821
+ except(keys: any[]): ICollection<T>;
822
+ intersect(items: T[]): ICollection<T>;
823
+ unique(key?: any, strict?: boolean): ICollection<T>;
824
+ find(key: any, defaultValue?: any): any;
825
+ fresh(withs?: any[]): Promise<ICollection<T>>;
826
+ makeVisible(attributes: string | string[]): this;
827
+ makeHidden(attributes: string | string[]): this;
828
+ append(attributes: string[]): this;
829
+ only(keys: null | any[]): this;
830
+ getDictionary(items?: any[]): TGeneric;
831
+ toQuery(): IBuilder<T, any>;
832
+ toData(): any;
833
+ toJSON(): any;
834
+ toJson(): string;
835
+ toString(): string;
836
+ [key: string]: any;
837
+ [Symbol.iterator]: () => Iterator<T>;
838
+ }
839
+ interface IPaginatorParams {
840
+ current_page: number;
841
+ data: any[];
842
+ per_page: number;
843
+ total: number;
844
+ last_page: number;
845
+ count: number;
846
+ }
847
+ interface IPaginator<T extends Model$2 | Model$1, K extends IPaginatorParams = IPaginatorParams> {
848
+ formatter?(paginator: IPaginator<any>): any | null;
849
+ setFormatter?(formatter: (paginator: IPaginator<any>) => any | null): void;
850
+ setItems(items: T[] | Collection$1<T>): void;
851
+ hasMorePages(): boolean;
852
+ get(index: number): T | null;
853
+ count(): number;
854
+ items(): Collection$1<T>;
855
+ map(callback: (value: T, index: number) => T): Collection$1<T>;
856
+ currentPage(): number;
857
+ perPage(): number;
858
+ lastPage(): number;
859
+ firstItem(): number | null;
860
+ lastItem(): number | null;
861
+ total(): number;
862
+ toData<U = K>(): U;
863
+ toJSON<U = K>(): U;
864
+ toJson(): string;
865
+ [Symbol.iterator]?(): {
866
+ next: () => {
867
+ value: T;
868
+ done: boolean;
869
+ };
870
+ };
269
871
  }
270
872
 
271
- declare const Model_base: any;
272
- declare class Model extends Model_base {
273
- [x: string]: any;
873
+ declare class arquebus<M extends Model$2 = Model$2> {
874
+ static connectorFactory: typeof Knex$1 | null;
875
+ static instance: arquebus | null;
876
+ manager: Record<string, QueryBuilder<M>>;
877
+ connections: Record<string, TConfig>;
878
+ models: Record<string, typeof Model$2>;
879
+ constructor();
880
+ getConstructor<T extends typeof arquebus>(this: InstanceType<T>): T;
881
+ static getInstance(): arquebus<Model$2>;
882
+ static connection(connection?: TBaseConfig['client'] | null): QueryBuilder<Model$2, Model$2 | Model$2[]>;
883
+ static setConnectorFactory(connectorFactory: typeof Knex$1): void;
884
+ static getConnectorFactory(): typeof Knex$1;
885
+ static addConnection(config: TConfig | TBaseConfig, name?: string): void;
886
+ static beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]> | undefined>;
887
+ static transaction(callback: TFunction, connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>> | undefined;
888
+ static table(name: string, connection?: null): IQueryBuilder<Model$2, Model$2 | Model$2[]>;
889
+ static schema(connection?: null): SchemaBuilder;
890
+ static destroyAll(): Promise<void>;
891
+ static createModel<X extends TGeneric>(name: string, options: X): typeof Model$2;
892
+ connection(connection?: string | null): QueryBuilder<M, M | M[]>;
893
+ getConnection(name?: string | null): QueryBuilder<M, M | M[]>;
894
+ addConnection(config: TConfig | TBaseConfig, name?: string): void;
895
+ beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]> | undefined>;
896
+ transaction(callback: TFunction, connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>> | undefined;
897
+ table(name: string, connection?: null): IQueryBuilder<M, M | M[]>;
898
+ schema(connection?: null): SchemaBuilder;
899
+ destroyAll(): Promise<void>;
900
+ createModel(name: string, options?: ModelOptions): typeof Model$2;
901
+ }
902
+
903
+ declare const BaseModel$1: new (...args: any[]) => any;
904
+ declare class Model$2 extends BaseModel$1 {
905
+ protected primaryKey: string;
906
+ protected builder: IBuilder<any, any> | null;
907
+ protected table: string | null;
908
+ protected keyType: string;
909
+ protected incrementing: boolean;
910
+ protected withCount: never[];
911
+ perPage: number;
274
912
  static globalScopes: {};
275
913
  static pluginInitializers: {};
276
914
  static _booted: {};
277
- static resolver: null;
278
- static query(trx?: null): any;
279
- static on(connection?: null): any;
280
- static init(attributes?: {}): Model;
281
- static extend(plugin: any, options: any): void;
282
- static make(attributes?: {}): Model;
915
+ static resolver: arquebus;
916
+ connection: TBaseConfig['client'] | null;
917
+ eagerLoad: {};
918
+ exists: boolean;
919
+ with: string | string[] | TGeneric<(...args: any[]) => IBuilder<Model$2>>;
920
+ trx: null;
921
+ constructor(attributes?: {});
922
+ static query(trx?: null): Builder<Model$2, IModel | ICollection<Model$2>>;
923
+ static on(connection?: TBaseConfig['client'] | null): Builder<Model$2, IModel | ICollection<Model$2>>;
924
+ static init(attributes?: {}): Model$2;
925
+ static extend(plugin: TFunction, options: TGeneric): void;
926
+ static make(attributes?: TGeneric): Model$2;
927
+ getConstructor<T extends typeof Model$2>(this: InstanceType<T>): T;
928
+ bootIfNotBooted(this: any): void;
283
929
  static booting(): void;
284
930
  static boot(): void;
285
931
  static booted(): void;
286
- static setConnectionResolver(resolver: any): void;
287
- constructor(attributes?: {});
288
- primaryKey: string;
289
- builder: null;
290
- table: null;
291
- connection: null;
292
- keyType: string;
293
- incrementing: boolean;
294
- perPage: number;
295
- exists: boolean;
296
- eagerLoad: {};
297
- with: any[];
298
- withCount: any[];
299
- trx: null;
300
- bootIfNotBooted(): void;
932
+ static setConnectionResolver(resolver: arquebus): void;
301
933
  initialize(): void;
302
- initializePlugins(): void;
303
- addPluginInitializer(method: any): void;
304
- newInstance(attributes?: {}, exists?: boolean): any;
305
- newFromBuilder(attributes?: {}, connection?: null): any;
306
- asProxy(): any;
934
+ initializePlugins(this: any): void;
935
+ addPluginInitializer(this: any, method: any): void;
936
+ newInstance(this: any, attributes?: TGeneric, exists?: boolean): any;
937
+ newFromBuilder(attributes?: TGeneric, connection?: null): any;
938
+ asProxy(): this;
307
939
  getKey(): any;
308
940
  getKeyName(): string;
309
941
  getForeignKey(): string;
310
- getConnectionName(): null;
942
+ getConnectionName(): "mysql" | "mysql2" | "sqlite3" | "oracle" | "mariadb" | "pg";
311
943
  getTable(): string;
312
- getConnection(): any;
313
- setConnection(connection: any): this;
944
+ getConnection(this: any): any;
945
+ setConnection(connection: TBaseConfig['client'] | null): this;
314
946
  getKeyType(): string;
315
- newQuery(trx?: null): any;
316
- newQueryWithoutScopes(trx?: null): Builder;
317
- newModelQuery(trx?: null): Builder;
318
- addGlobalScopes(builder: any): any;
319
- hasNamedScope(name: any): boolean;
320
- callNamedScope(scope: any, parameters: any): any;
321
- setTable(table: any): this;
322
- newCollection(models?: any[]): Collection;
323
- load(...relations: any[]): Promise<this>;
324
- loadAggregate(relations: any, column: any, callback?: null): Promise<this>;
325
- loadCount(...relations: any[]): Promise<this>;
326
- loadMax(relations: any, column: any): Promise<this>;
327
- loadMin(relations: any, column: any): Promise<this>;
328
- loadSum(relations: any, column: any): Promise<this>;
329
- increment(column: any, amount?: number, extra?: {}, options?: {}): Promise<any>;
330
- decrement(column: any, amount?: number, extra?: {}, options?: {}): Promise<any>;
331
- incrementOrDecrement(column: any, amount: any, extra: any, method: any, options: any): Promise<any>;
947
+ newQuery(trx?: null): Builder<Model$2, IModel | ICollection<Model$2>>;
948
+ newQueryWithoutScopes(trx?: null): Builder<Model$2, IModel | ICollection<Model$2>>;
949
+ newModelQuery(trx?: null): Builder<Model$2, IModel | ICollection<Model$2>>;
950
+ addGlobalScopes(this: any, builder: Builder<Model$2>): Builder<Model$2, IModel | ICollection<Model$2>>;
951
+ hasNamedScope(name: string): boolean;
952
+ callNamedScope(scope: string, parameters: any[]): any;
953
+ setTable(table: string): this;
954
+ newCollection(this: any, models?: never[]): Collection$1<Model$2>;
955
+ load<R extends WithRelationType>(this: any, ...relations: R[]): Promise<any>;
956
+ loadAggregate<R extends WithRelationType>(relations: R[], column: string, callback?: TFunction | string | null): Promise<this>;
957
+ loadCount<R extends WithRelationType>(...relations: R[]): Promise<this>;
958
+ loadMax<R extends WithRelationType>(relations: R[], column: string): Promise<this>;
959
+ loadMin<R extends WithRelationType>(relations: R[], column: string): Promise<this>;
960
+ loadSum<R extends WithRelationType>(relations: R[], column: string): Promise<this>;
961
+ increment(column: string, amount?: number, extra?: TGeneric, options?: TGeneric): Promise<any>;
962
+ decrement(column: string, amount?: number, extra?: TGeneric, options?: TGeneric): Promise<any>;
963
+ incrementOrDecrement(column: string, amount: number, extra: TGeneric, method: string, options: TGeneric): Promise<any>;
332
964
  toData(): {
333
965
  [x: string]: any;
334
966
  [x: number]: any;
@@ -341,117 +973,417 @@ declare class Model extends Model_base {
341
973
  };
342
974
  toJson(...args: any[]): string;
343
975
  toString(): string;
344
- fill(attributes: any): this;
976
+ fill(attributes: TGeneric): this;
345
977
  transacting(trx: any): this;
346
978
  trashed(): boolean;
347
979
  getIncrementing(): boolean;
348
- setIncrementing(value: any): this;
349
- save(options?: {}): Promise<boolean>;
350
- update(attributes?: {}, options?: {}): Promise<boolean>;
980
+ setIncrementing(value: boolean): this;
981
+ save(options?: TGeneric): Promise<boolean>;
982
+ update(attributes?: TGeneric, options?: TGeneric): Promise<boolean>;
351
983
  delete(options?: {}): Promise<boolean>;
352
- performDeleteOnModel(options?: {}): Promise<void>;
984
+ performDeleteOnModel(options?: TGeneric): Promise<void>;
353
985
  setKeysForSaveQuery(query: any): any;
354
986
  forceDelete(options?: {}): Promise<boolean>;
355
- fresh(): any;
356
- refresh(): Promise<this | undefined>;
357
- attributes: any;
358
- newPivot(parent: any, attributes: any, table: any, exists: any, using?: null): any;
359
- qualifyColumn(column: any): any;
360
- getQualifiedKeyName(): any;
987
+ fresh(this: any): any;
988
+ refresh(this: any): Promise<any>;
989
+ newPivot<E extends Model$2>(parent: E, attributes: TGeneric, table: string, exists: boolean, using?: typeof Pivot$1 | null): Pivot$1;
990
+ qualifyColumn(column: string): string;
991
+ getQualifiedKeyName(): string;
361
992
  push(options?: {}): Promise<boolean>;
362
993
  is(model: any): any;
363
994
  isNot(model: any): boolean;
364
995
  }
365
- declare class Pivot extends Model {
366
- static fromRawAttributes(parent: any, attributes: any, table: any, exists?: boolean): Pivot;
367
- static fromAttributes(parent: any, attributes: any, table: any, exists?: boolean): Pivot;
368
- guarded: any[];
369
- pivotParent: null;
370
- foreignKey: null;
371
- relatedKey: null;
372
- setPivotKeys(foreignKey: any, relatedKey: any): this;
373
- hasTimestampAttributes(attributes?: null): boolean;
996
+ declare class Pivot$1 extends Model$2 {
997
+ incrementing: boolean;
998
+ guarded: never[];
999
+ pivotParent: Model$2 | null;
1000
+ foreignKey: string | null;
1001
+ relatedKey: string | null;
1002
+ setPivotKeys(foreignKey: string, relatedKey: string): this;
1003
+ static fromRawAttributes<E extends Model$2>(parent: E, attributes: TGeneric, table: string, exists?: boolean): Pivot$1;
1004
+ static fromAttributes<E extends Model$2>(parent: E, attributes: TGeneric, table: string, exists?: boolean): Pivot$1;
1005
+ hasTimestampAttributes(this: any, attributes?: TGeneric | null): boolean;
1006
+ }
1007
+
1008
+ type TGeneric<V = any, K extends string = string> = Record<K, V>;
1009
+ type XGeneric<V = TGeneric, T = any> = {
1010
+ [key: string]: T;
1011
+ } & V;
1012
+ type Hook = 'creating' | 'created' | 'updating' | 'updated' | 'saving' | 'saved' | 'deleting' | 'deleted' | 'restoring' | 'restored' | 'trashed' | 'forceDeleted';
1013
+ type TFunction<TArgs extends any[] = any[], TReturn = any> = (...args: TArgs) => TReturn;
1014
+ type PrimitiveValue = string | number | boolean | Date | string[] | number[] | boolean[] | Date[] | null | Buffer;
1015
+ type ReturnTypeOfMethod<T, K extends keyof T> = T[K] extends (...args: any[]) => infer R ? R : never;
1016
+ type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
1017
+ type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? U extends Uncapitalize<U> ? `${Uncapitalize<T>}${CamelToSnakeCase<U>}` : `${Uncapitalize<T>}_${CamelToSnakeCase<U>}` : S;
1018
+ type FunctionPropertyNames<T> = {
1019
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
1020
+ }[keyof T];
1021
+ type RelationNames<T> = FunctionPropertyNames<T> extends infer R ? R extends `relation${infer P}` ? P extends ('sToData' | 'loaded') ? never : CamelToSnakeCase<P> : never : never;
1022
+ type MixinConstructor<T = TGeneric> = new (...args: any[]) => T;
1023
+
1024
+ declare class Collection<I extends Model$1> extends Collection$2<I> {
1025
+ mapThen(callback: TFunction): Promise<any[]>;
1026
+ modelKeys(): any[];
1027
+ contains<K, V>(key: keyof I | K | TFunction, value?: V): boolean;
1028
+ diff(items: ICollection<any> | any[]): any;
1029
+ except(keys: any[]): any;
1030
+ intersect(items: I[]): any;
1031
+ unique(key?: TFunction | keyof I, _strict?: boolean): any;
1032
+ find(key: any, defaultValue?: null): any;
1033
+ makeVisible(attributes: any): this;
1034
+ makeHidden(attributes: any): this;
1035
+ append(attributes: any): this;
1036
+ only(keys: any[]): any;
1037
+ getDictionary(items?: ICollection<any> | any[]): TGeneric;
1038
+ toData(): (I | {
1039
+ [x: string]: any;
1040
+ [x: number]: any;
1041
+ [x: symbol]: any;
1042
+ })[];
1043
+ toJSON(): (I | {
1044
+ [x: string]: any;
1045
+ [x: number]: any;
1046
+ [x: symbol]: any;
1047
+ })[];
1048
+ toJson(...args: any[]): string;
1049
+ [Symbol.iterator]: () => Iterator<I>;
374
1050
  }
375
1051
 
1052
+ declare const BaseModel: new (...args: any[]) => any;
1053
+ declare class Model$1 extends BaseModel {
1054
+ protected primaryKey: string;
1055
+ protected perPage: number;
1056
+ static globalScopes: {};
1057
+ static pluginInitializers: {};
1058
+ static _booted: {};
1059
+ static resolver: arquebus;
1060
+ static browser: boolean;
1061
+ connection: TBaseConfig['client'] | null;
1062
+ constructor(attributes?: {});
1063
+ static init(attributes?: {}): Model$1;
1064
+ static extend(plugin: TFunction, options: TGeneric): void;
1065
+ static make(attributes?: TGeneric): Model$1;
1066
+ bootIfNotBooted(this: any): void;
1067
+ static booting(): void;
1068
+ static boot(): void;
1069
+ static booted(): void;
1070
+ static setConnectionResolver(resolver: arquebus): void;
1071
+ initialize(): void;
1072
+ initializePlugins(this: any): void;
1073
+ addPluginInitializer(this: any, method: any): void;
1074
+ newInstance(this: any, attributes?: TGeneric, exists?: boolean): any;
1075
+ asProxy(): this;
1076
+ getKey(): any;
1077
+ getKeyName(): string;
1078
+ getForeignKey(): string;
1079
+ getConnectionName(): "mysql" | "mysql2" | "sqlite3" | "oracle" | "mariadb" | "pg" | null;
1080
+ getTable(): any;
1081
+ setConnection(connection: TBaseConfig['client']): this;
1082
+ getKeyType(): any;
1083
+ hasNamedScope(name: string): boolean;
1084
+ callNamedScope(scope: string, parameters: any): any;
1085
+ setTable(table: string): this;
1086
+ newCollection(models?: never[]): Collection<never>;
1087
+ getIncrementing(): any;
1088
+ setIncrementing(value: boolean): this;
1089
+ toData(): {
1090
+ [x: string]: any;
1091
+ [x: number]: any;
1092
+ [x: symbol]: any;
1093
+ };
1094
+ toJSON(): {
1095
+ [x: string]: any;
1096
+ [x: number]: any;
1097
+ [x: symbol]: any;
1098
+ };
1099
+ toJson(...args: any[]): string;
1100
+ toString(): string;
1101
+ fill(attributes: TGeneric): this;
1102
+ transacting(trx: any): this;
1103
+ trashed(): boolean;
1104
+ newPivot<E extends Model$1>(parent: E, attributes: TGeneric, table: string, exists: boolean, using?: typeof Pivot | null): Pivot;
1105
+ qualifyColumn(column: string): string;
1106
+ getQualifiedKeyName(): string;
1107
+ is(model: any): any;
1108
+ isNot(model: any): boolean;
1109
+ }
1110
+ declare class Pivot extends Model$1 {
1111
+ incrementing: boolean;
1112
+ guarded: never[];
1113
+ pivotParent: Model$1 | null;
1114
+ foreignKey: string | null;
1115
+ relatedKey: string | null;
1116
+ setPivotKeys(foreignKey: string, relatedKey: string): this;
1117
+ static fromRawAttributes<E extends Model$1>(parent: E, attributes: TGeneric, table: string, exists?: boolean): Pivot;
1118
+ static fromAttributes<E extends Model$1>(parent: E, attributes: TGeneric, table: string, exists?: boolean): Pivot;
1119
+ hasTimestampAttributes(this: any, attributes?: TGeneric | null): boolean;
1120
+ }
1121
+
1122
+ interface IAttribute {
1123
+ get?: null | (<A extends TGeneric>(value: string, attr: A) => string);
1124
+ set?: null | (<A extends TGeneric>(value: string, attr: A) => string | TGeneric);
1125
+ }
376
1126
  declare class Attribute {
377
- static make(get?: null, set?: null): Attribute;
378
- static get(get: any): Attribute;
379
- static set(set: any): Attribute;
380
- constructor({ get, set }: {
381
- get?: null | undefined;
382
- set?: null | undefined;
383
- });
384
- get: any;
385
- set: any;
1127
+ get: IAttribute['get'];
1128
+ set: IAttribute['set'];
386
1129
  withCaching: boolean;
387
1130
  withObjectCaching: boolean;
1131
+ constructor({ get, set }: IAttribute);
1132
+ static make({ get, set }: IAttribute): Attribute;
1133
+ static get(get: IAttribute['get']): Attribute;
1134
+ static set(set: IAttribute['set']): Attribute;
388
1135
  withoutObjectCaching(): this;
389
1136
  shouldCache(): this;
390
1137
  }
391
1138
 
392
- declare class CastsAttributes {
393
- static get(): void;
394
- static set(): void;
1139
+ interface ICastsAttributes {
1140
+ get?(model: Model$2, key: string, value: string, attributes: TGeneric): string | null | undefined;
1141
+ set?(model: Model$2, key: string, value: string, attributes: TGeneric): string | null | undefined;
1142
+ }
1143
+ declare class CastsAttributes implements ICastsAttributes {
1144
+ constructor();
1145
+ static get(_model: Model$2, _key: string, _value: string, _attributes: TGeneric): string | null | undefined;
1146
+ static set(_model: Model$2, _key: string, _value: string, _attributes: TGeneric): string | null | undefined;
395
1147
  }
396
1148
 
397
- declare class Migration {
398
- connection: any;
1149
+ declare const HasUniqueIds: <TBase extends MixinConstructor>(Model: TBase) => {
1150
+ new (...args: any[]): {
1151
+ [x: string]: any;
1152
+ useUniqueIds: boolean;
1153
+ uniqueIds(): any[];
1154
+ getKeyType(): any;
1155
+ getIncrementing(): any;
1156
+ };
1157
+ } & TBase;
1158
+
1159
+ interface IMigration {
1160
+ withinTransaction?: boolean;
1161
+ up(schema: SchemaBuilder, connection?: QueryBuilder): Promise<any>;
1162
+ down(schema: SchemaBuilder, connection?: QueryBuilder): Promise<any>;
1163
+ getConnection(): TBaseConfig['client'];
1164
+ }
1165
+ declare const Inference: {
1166
+ new (): IMigration;
1167
+ };
1168
+ declare class Migration extends Inference {
1169
+ protected connection: TBaseConfig['client'];
399
1170
  withinTransaction: boolean;
400
- getConnection(): any;
1171
+ getConnection(): TBaseConfig['client'];
1172
+ }
1173
+
1174
+ declare class MigrationRepository {
1175
+ resolver: typeof arquebus;
1176
+ table: string;
1177
+ connection: TBaseConfig['client'] | null;
1178
+ constructor(resolver: typeof arquebus, table: string);
1179
+ getRan(): Promise<ICollection<any>>;
1180
+ getMigrations(steps: number): Promise<any>;
1181
+ getMigrationsByBatch(batch: number): Promise<any>;
1182
+ getLast(): Promise<any>;
1183
+ getMigrationBatches(): Promise<TGeneric>;
1184
+ log(file: string, batch: number): Promise<void>;
1185
+ delete(migration: TGeneric): Promise<void>;
1186
+ getNextBatchNumber(): Promise<number>;
1187
+ getLastBatchNumber(): Promise<number>;
1188
+ createRepository(): Promise<void>;
1189
+ repositoryExists(): Promise<boolean>;
1190
+ deleteRepository(): Promise<void>;
1191
+ getTable(): IQueryBuilder<Model$2, Model$2 | Model$2[]>;
1192
+ getConnection(): QueryBuilder<Model$2, Model$2 | Model$2[]>;
1193
+ setSource(name: TBaseConfig['client']): void;
401
1194
  }
402
1195
 
403
- declare class Scope {
404
- apply(builder: any, model: any): void;
1196
+ interface MigrationOptions {
1197
+ pretend?: boolean;
1198
+ step?: number;
1199
+ batch?: number;
1200
+ }
1201
+ declare class Migrator {
1202
+ events: any;
1203
+ repository: MigrationRepository;
1204
+ files: any;
1205
+ resolver: typeof arquebus;
1206
+ connection: TBaseConfig['client'];
1207
+ paths: string[];
1208
+ output: boolean | null;
1209
+ constructor(repository: MigrationRepository, resolver?: typeof arquebus | null, files?: any, dispatcher?: any);
1210
+ run(paths?: string[], options?: MigrationOptions): Promise<string[]>;
1211
+ pendingMigrations(files: Record<string, string>, ran: string[]): string[];
1212
+ runPending(migrations: string[], options?: MigrationOptions): Promise<void>;
1213
+ runUp(file: string, batch: number, _pretend: boolean): Promise<void>;
1214
+ runDown(file: string, migration: {
1215
+ migration: string;
1216
+ }, _pretend: boolean): Promise<void>;
1217
+ rollback(paths?: string[], options?: MigrationOptions): Promise<string[]>;
1218
+ getMigrationsForRollback(options: MigrationOptions): Promise<{
1219
+ migration: string;
1220
+ }[]>;
1221
+ rollbackMigrations(migrations: {
1222
+ migration: string;
1223
+ }[], paths: string[], options: MigrationOptions): Promise<string[]>;
1224
+ reset(_paths?: string[], _pretend?: boolean): Promise<string[]> | string[];
1225
+ resetMigrations(migrations: {
1226
+ migration: string;
1227
+ }[], paths: string[], pretend?: boolean): Promise<string[]>;
1228
+ runMigration(migration: IMigration, method: 'up' | 'down'): Promise<void>;
1229
+ runMethod(connection: QueryBuilder, migration: IMigration, method: 'up' | 'down'): Promise<void>;
1230
+ resolvePath(filePath: string): Promise<IMigration>;
1231
+ getMigrationClass(migrationName: string): string;
1232
+ getMigrationFiles(paths: string[]): Promise<Record<string, string>>;
1233
+ getMigrationName(filePath: string): string;
1234
+ path(p: string): void;
1235
+ getPaths(): string[];
1236
+ getConnection(): TBaseConfig['client'];
1237
+ resolveConnection(connection?: TBaseConfig['client']): any;
1238
+ getRepository(): MigrationRepository;
1239
+ repositoryExists(): Promise<boolean>;
1240
+ hasRunAnyMigrations(): Promise<boolean>;
1241
+ deleteRepository(): void;
1242
+ setOutput(output: boolean): this;
1243
+ write(...args: any[]): void;
1244
+ writeTwoColumns(name: string, ...args: string[]): void;
1245
+ writeTask(description: string, task: () => Promise<any> | any): Promise<void>;
405
1246
  }
406
1247
 
407
- declare function softDeletes(Model: any): {
408
- new (): {
1248
+ interface MigrationStatus {
1249
+ name: string;
1250
+ ran: boolean;
1251
+ batch: number | null;
1252
+ }
1253
+ interface MigrateOptions {
1254
+ path?: string;
1255
+ step?: number;
1256
+ pretend?: boolean;
1257
+ batch?: number;
1258
+ }
1259
+ interface TCallback {
1260
+ (message: string, status?: 'success' | 'error' | 'info' | 'quiet'): void;
1261
+ }
1262
+ declare class Migrate {
1263
+ private basePath?;
1264
+ private customStubPath?;
1265
+ private callback;
1266
+ constructor(basePath?: string | undefined, customStubPath?: string | undefined, callback?: TCallback);
1267
+ /**
1268
+ * Runs all pending migrations
1269
+ *
1270
+ * @param config
1271
+ * @param options
1272
+ * @param destroyAll
1273
+ */
1274
+ run(config: TBaseConfig, options?: MigrateOptions, destroyAll?: boolean): Promise<void>;
1275
+ /**
1276
+ * Rollback the last migration
1277
+ *
1278
+ * @param config
1279
+ * @param options
1280
+ * @param destroyAll
1281
+ */
1282
+ rollback(config: TBaseConfig, options?: MigrateOptions, destroyAll?: boolean): Promise<void>;
1283
+ /**
1284
+ * Prepares the database for migration
1285
+ *
1286
+ * @param migrator
1287
+ */
1288
+ prepareDatabase(migrator: Migrator): Promise<void>;
1289
+ /**
1290
+ * Check the status of available migrations
1291
+ *
1292
+ * @param config
1293
+ * @param options
1294
+ * @param destroyAll
1295
+ * @returns
1296
+ */
1297
+ status(config: TBaseConfig, options?: MigrateOptions, destroyAll?: boolean): Promise<MigrationStatus[]>;
1298
+ /**
1299
+ * Setup the database connection
1300
+ *
1301
+ * @param config
1302
+ * @returns
1303
+ */
1304
+ setupConnection(config: TBaseConfig): Promise<{
1305
+ arquebus: typeof arquebus;
1306
+ migrator: Migrator;
1307
+ }>;
1308
+ }
1309
+
1310
+ declare const softDeletes: <TBase extends MixinConstructor>(Model: TBase) => {
1311
+ new (...args: any[]): {
409
1312
  [x: string]: any;
410
1313
  forceDeleting: boolean;
411
- initialize(): void;
1314
+ initialize(this: typeof Model.prototype): void;
412
1315
  initializeSoftDeletes(): void;
413
1316
  forceDelete(): Promise<any>;
414
1317
  forceDeleteQuietly(): any;
415
1318
  performDeleteOnModel(options?: {}): Promise<any>;
416
- exists: boolean | undefined;
417
1319
  runSoftDelete(options?: {}): Promise<void>;
418
1320
  restore(options?: {}): Promise<any>;
419
1321
  restoreQuietly(): any;
420
1322
  trashed(): boolean;
421
1323
  isForceDeleting(): boolean;
422
- getDeletedAtColumn(): any;
1324
+ getDeletedAtColumn(this: typeof Model.prototype): any;
423
1325
  getQualifiedDeletedAtColumn(): any;
424
1326
  };
425
- [x: string]: any;
426
- bootSoftDeletes(): void;
427
- softDeleted(callback: any): void;
428
- restoring(callback: any): void;
429
- restored(callback: any): void;
430
- forceDeleting(callback: any): void;
431
- forceDeleted(callback: any): void;
432
- };
1327
+ bootSoftDeletes(this: typeof Model.prototype): void;
1328
+ softDeleted(this: typeof Model.prototype, callback: TFunction): void;
1329
+ restoring(this: typeof Model.prototype, callback: TFunction): void;
1330
+ restored(this: typeof Model.prototype, callback: TFunction): void;
1331
+ forceDeleting(this: typeof Model.prototype, callback: TFunction): void;
1332
+ forceDeleted(this: typeof Model.prototype, callback: TFunction): void;
1333
+ } & TBase;
433
1334
 
434
- declare function HasUniqueIds(Model: any): {
435
- new (): {
436
- [x: string]: any;
437
- useUniqueIds: boolean;
438
- uniqueIds(): any[];
439
- getKeyType(): any;
440
- getIncrementing(): any;
441
- };
442
- [x: string]: any;
443
- };
1335
+ declare class BaseError extends Error {
1336
+ constructor(message: string, _entity?: any);
1337
+ }
1338
+ declare class ModelNotFoundError extends BaseError {
1339
+ model?: IModel;
1340
+ ids: (string | number)[] | string | number;
1341
+ constructor();
1342
+ setModel(model: IModel, ids?: never[]): this;
1343
+ getModel(): IModel | undefined;
1344
+ getIds(): string | number | (string | number)[];
1345
+ }
1346
+ declare class RelationNotFoundError extends BaseError {
1347
+ }
1348
+ declare class InvalidArgumentError extends BaseError {
1349
+ }
444
1350
 
445
- declare function migrateRun(config: any, options?: {}, destroyAll?: boolean): Promise<void>;
446
- declare function migrateRollback(config: any, options?: {}, destroyAll?: boolean): Promise<void>;
447
- declare function migrateStatus(config: any, options?: {}, destroyAll?: boolean): Promise<{
448
- name: string;
449
- ran: any;
450
- batch: any;
451
- }[]>;
1351
+ declare const now: (format?: string) => string;
1352
+ declare const getRelationName: (relationMethod: string) => string;
1353
+ declare const getScopeName: (scopeMethod: string) => string;
1354
+ declare const getRelationMethod: (relation: string) => string;
1355
+ declare const getScopeMethod: (scope: string) => string;
1356
+ declare const getAttrMethod: (attr: string) => string;
1357
+ declare const getGetterMethod: (attr: string) => string;
1358
+ declare const getSetterMethod: (attr: string) => string;
1359
+ declare const getAttrName: (attrMethod: string) => string;
1360
+ /**
1361
+ * Tap into a model a collection instance
1362
+ *
1363
+ * @param instance
1364
+ * @param callback
1365
+ * @returns
1366
+ */
1367
+ declare const tap: <I>(instance: I, callback: (ins: I) => Promise<I> | I) => Promise<I> | I;
1368
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
1369
+ type Mixin<TBase extends MixinConstructor, TReturn extends MixinConstructor> = (base: TBase) => TReturn;
1370
+ /**
1371
+ * Compose functional mixins
1372
+ *
1373
+ * @param Base
1374
+ * @param mixins
1375
+ * @returns
1376
+ */
1377
+ declare function compose<MC extends MixinConstructor, P extends Mixin<MC, MixinConstructor>[]>(Base: MC, ...mixins: P): new (...args: any[]) => InstanceType<MC> & UnionToIntersection<InstanceType<ReturnType<P[number]>>>;
1378
+ declare const flattenDeep: (arr: any) => any;
1379
+ declare const kebabCase: (str: string) => string;
1380
+ declare const snakeCase: (str: string) => string;
1381
+ declare const defineConfig: (config: TConfig) => XGeneric<TConfig>;
452
1382
 
453
- declare function make(model: any, data: any, options?: {}): any;
454
- declare function makeCollection(model: any, data: any): Collection;
455
- declare function makePaginator(model: any, data: any): Paginator;
1383
+ declare const make: (model: Model$2, data: TGeneric, options?: {
1384
+ paginated: IPaginatorParams;
1385
+ }) => any;
1386
+ declare const makeCollection: (model: Model$2, data: TGeneric) => Collection$1<Model$2 | Model$1>;
1387
+ declare const makePaginator: (model: Model$2, data: TGeneric) => Paginator<Model$2, IPaginatorParams>;
456
1388
 
457
- export { Attribute, Builder, CastsAttributes, Collection, HasUniqueIds, InvalidArgumentError, Migration, Model, ModelNotFoundError, Paginator, Pivot, QueryBuilder, RelationNotFoundError, Scope, softDeletes as SoftDeletes, arquebus, compose, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, kebabCase, make, makeCollection, makePaginator, migrateRollback, migrateRun, migrateStatus, now, snakeCase, tap };
1389
+ export { Attribute, Builder, CastsAttributes, Collection$1 as Collection, HasUniqueIds, InvalidArgumentError, Migrate, Migration, Model$2 as Model, ModelNotFoundError, Paginator, Pivot$1 as Pivot, QueryBuilder, RelationNotFoundError, Scope, softDeletes as SoftDeletes, arquebus, compose, defineConfig, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, kebabCase, make, makeCollection, makePaginator, now, snakeCase, tap };