@h3ravel/arquebus 0.1.6 → 0.2.1

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