@h3ravel/arquebus 0.2.2 → 0.2.4

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.
@@ -0,0 +1,71 @@
1
+ import type Model from 'src/model'
2
+
3
+ export type TGeneric<V = any, K extends string = string> = Record<K, V>
4
+ export type XGeneric<V = TGeneric, T = any> = {
5
+ [key: string]: T
6
+ } & V
7
+
8
+ export interface Plugin {
9
+ (model: Model, config: TGeneric): void
10
+ }
11
+
12
+ export type Hook =
13
+ | 'creating' | 'created' | 'updating' | 'updated' | 'saving' | 'saved' | 'deleting' | 'deleted'
14
+ | 'restoring' | 'restored' | 'trashed' | 'forceDeleted';
15
+
16
+ export type TFunction<TArgs extends any[] = any[], TReturn = any> = (...args: TArgs) => TReturn;
17
+
18
+ export type PrimitiveValue =
19
+ | string
20
+ | number
21
+ | boolean
22
+ | Date
23
+ | string[]
24
+ | number[]
25
+ | boolean[]
26
+ | Date[]
27
+ | null
28
+ | Buffer;
29
+
30
+ export type ReturnTypeOfMethod<T, K extends keyof T> = T[K] extends (...args: any[]) => infer R ? R : never;
31
+
32
+ export type SnakeToCamelCase<S extends string> =
33
+ S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
34
+
35
+ // declare const model: ModelDecorator;
36
+ export type CamelToSnakeCase<S extends string> =
37
+ S extends `${infer T}${infer U}` ?
38
+ U extends Uncapitalize<U> ? `${Uncapitalize<T>}${CamelToSnakeCase<U>}` : `${Uncapitalize<T>}_${CamelToSnakeCase<U>}` :
39
+ S;
40
+
41
+ export type FunctionPropertyNames<T> = {
42
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
43
+ }[keyof T];
44
+
45
+ export type RelationNames<T> = FunctionPropertyNames<T> extends infer R
46
+ ? R extends `relation${infer P}` ? P extends ('sToData' | 'loaded') ? never : CamelToSnakeCase<P> : never
47
+ : never;
48
+
49
+ export type MixinConstructor<T = TGeneric> = new (...args: any[]) => T
50
+
51
+ // Helper type: combine all mixin instance types into a single intersection
52
+ export type MixinReturn<Base extends MixinConstructor, Mixins extends ((base: any) => any)[]> =
53
+ Base extends MixinConstructor<infer B>
54
+ ? IntersectionOfInstances<InstanceTypeOfMixins<Mixins>> & B
55
+ : never
56
+
57
+ export type InstanceTypeOfMixins<T extends ((base: any) => any)[]> =
58
+ T extends [infer Head, ...infer Tail]
59
+ ? Head extends (base: any) => infer R
60
+ ? Tail extends ((base: any) => any)[]
61
+ ? R | InstanceTypeOfMixins<Tail>
62
+ : R
63
+ : never
64
+ : never
65
+
66
+ export type IntersectionOfInstances<U> =
67
+ (U extends any ? (x: U) => any : never) extends (x: infer I) => any ? I : never
68
+
69
+ export interface DeepMixinFunction {
70
+ <MC extends MixinConstructor, P extends ((base: any) => any)[]> (Base: MC, ...mixins: P): MixinReturn<MC, P>
71
+ }
@@ -0,0 +1,190 @@
1
+ import type { AnyQueryBuilder, WithRelationType } from './query-methods'
2
+ import type { Hook, RelationNames, ReturnTypeOfMethod, SnakeToCamelCase, TFunction, TGeneric } from './generics'
3
+
4
+ import type { IBuilder } from './builder'
5
+ import type { ICollection } from './utils'
6
+ import type Model from 'src/model'
7
+ import type { TBaseConfig } from './container'
8
+
9
+ export interface Attribute {
10
+ make (config: { get?: TFunction | null, set?: TFunction | null }): Attribute;
11
+ get: TFunction | null
12
+ set: TFunction | null
13
+ withCaching?: boolean
14
+ withObjectCaching?: boolean
15
+ }
16
+
17
+ export interface CastsAttributes {
18
+ get (): any;
19
+ set (): void;
20
+ }
21
+
22
+ export type Relation<M extends Model> = IBuilder<M, any> & {
23
+ }
24
+
25
+ export interface HasOneOrMany<M extends Model> extends Relation<M> {
26
+ save (model: M): Promise<M>;
27
+ saveMany (models: M[] | ICollection<M>): Promise<ICollection<M>>;
28
+ create (attributes?: any): Promise<M>;
29
+ createMany (records: any[]): Promise<ICollection<M>>;
30
+ }
31
+
32
+ export interface HasOne<M extends Model> extends HasOneOrMany<M> {
33
+ getResults (): Promise<M | null>;
34
+ withDefault (callback?: TFunction | object): this;
35
+ }
36
+
37
+ export interface HasMany<M extends Model> extends HasOneOrMany<M> {
38
+ getResults (): Promise<ICollection<M>>;
39
+ }
40
+
41
+ export interface BelongsTo<M extends Model> extends Relation<M> {
42
+ getResults (): Promise<M | null>;
43
+ withDefault (callback?: TFunction | object): this;
44
+ }
45
+
46
+ export interface BelongsToMany<M extends Model> extends Relation<M> {
47
+ getResults (): Promise<ICollection<M>>;
48
+ withTimestamps (): this;
49
+ wherePivot (column: any, operator?: any, value?: any, boolean?: string, ...args: any[]): this;
50
+ wherePivotBetween (column: any, values: any, boolean?: string, not?: boolean): this;
51
+ orWherePivotBetween (column: any, values: any): this;
52
+ wherePivotNotBetween (column: any, values: any, boolean?: string): this;
53
+ orWherePivotNotBetween (column: any, values: any): this;
54
+ wherePivotIn (column: any, values: any, boolean?: string, not?: boolean): this;
55
+ orWherePivot (column: any, operator?: any, value?: any): this;
56
+ orWherePivotIn (column: any, values: any): this;
57
+ wherePivotNotIn (column: any, values: any, boolean?: string): this;
58
+ orWherePivotNotIn (column: any, values: any): this;
59
+ wherePivotNull (column: any, boolean?: string, not?: boolean): this;
60
+ wherePivotNotNull (column: any, boolean?: string): this;
61
+ orWherePivotNull (column: any, not?: boolean): this;
62
+ orWherePivotNotNull (column: any): this;
63
+ orderByPivot (column: any, direction?: string): this;
64
+ }
65
+
66
+ export interface IModel {
67
+ [value: string]: any;
68
+ attributes: any
69
+ relations: any
70
+ exists: boolean
71
+ primaryKey: string
72
+ builder?: IBuilder<any, any> | null
73
+ table: string | null
74
+ connection?: TBaseConfig['client'] | null
75
+ keyType: string
76
+ incrementing: boolean
77
+ perPage: number
78
+ with: string | string[] | TGeneric<(...args: any[]) => IBuilder<Model>>
79
+ withCount: string[]
80
+ trx: AnyQueryBuilder | null
81
+ timestamps: boolean
82
+ dateFormat: string
83
+ visible: string[]
84
+ hidden: string[]
85
+ query<T extends { prototype: unknown }> (this: T, client?: AnyQueryBuilder | null): IBuilder<Model>;
86
+ on<T extends { prototype: unknown }> (this: T, connection: string | null): IBuilder<Model>;
87
+ boot (): void;
88
+ make<T extends IModel> (this: new () => T, attributes?: TGeneric): T;
89
+ addHook (hook: Hook, callback: TFunction): void;
90
+ creating (callback: TFunction): void;
91
+ created (callback: TFunction): void;
92
+ updating (callback: TFunction): void;
93
+ updated (callback: TFunction): void;
94
+ deleting (callback: TFunction): void;
95
+ deleted (callback: TFunction): void;
96
+ saving (callback: TFunction): void;
97
+ saved (callback: TFunction): void;
98
+ restoring (callback: TFunction): void;
99
+ restored (callback: TFunction): void;
100
+ trashed (callback: TFunction): void;
101
+ forceDeleted (callback: TFunction): void;
102
+ bootIfNotBooted (): void;
103
+ initialize (): void;
104
+ initializePlugins (): void;
105
+ addPluginInitializer (method: any): void;
106
+ newInstance (attributes?: TGeneric, exists?: boolean): any;
107
+ getKey (): string | number | null | undefined;
108
+ getKeyName (): string;
109
+ getConnectionName (): string;
110
+ getConnection (): any;
111
+ setConnection (connection: TBaseConfig['client'] | null): this;
112
+ usesUniqueIds (): boolean;
113
+ uniqueIds (): string[];
114
+ newUniqueId (): string;
115
+ setUniqueIds (): void;
116
+ getKeyType (): string;
117
+ getIncrementing (): boolean;
118
+ setIncrementing (value: boolean): this;
119
+ getTable (): string;
120
+ setTable (table: string): this;
121
+ getDates (): string[];
122
+ getDateFormat (): string;
123
+ getAttributes (): object;
124
+ getAttribute (key: string): any;
125
+ setAttribute (key: string, value: any): this;
126
+ fill (attributes: any): this;
127
+ setAppends (appends: string[]): this;
128
+ append (key: string | string[]): this;
129
+ getRelation<T extends Model> (relation: string): T | ICollection<T> | null | undefined;
130
+ setRelation<T extends Model> (relation: string, value: T | ICollection<T> | null): this;
131
+ unsetRelation (relation: string): this;
132
+ relationLoaded (relation: string): boolean;
133
+ makeVisible (attributes: string | string[]): this;
134
+ makeHidden (attributes: string | string[]): this;
135
+ newCollection (models?: any[]): ICollection<Model>;
136
+ load (relations: WithRelationType): Promise<this>;
137
+ load (...relations: WithRelationType[]): Promise<this>;
138
+ loadAggregate (relations: WithRelationType, column: any, callback?: any): Promise<this>;
139
+ loadCount (...relations: WithRelationType[]): Promise<this>;
140
+ loadMax (relations: WithRelationType, column: string): Promise<this>;
141
+ loadMin (relations: WithRelationType, column: string): Promise<this>;
142
+ loadSum (relations: WithRelationType, column: string): Promise<this>;
143
+ usesTimestamps (): boolean;
144
+ updateTimestamps (): this;
145
+ getCreatedAtColumn (): string;
146
+ getUpdatedAtColumn (): string;
147
+ getDeletedAtColumn (): string;
148
+ setCreatedAt (value: string): this;
149
+ setUpdatedAt (value: string): this;
150
+ freshTimestamp (): Date;
151
+ freshTimestampString (): string;
152
+ fromDateTime (value: Date | number | null): string;
153
+ useSoftDeletes (): boolean;
154
+ toData (): any;
155
+ attributesToData (): any;
156
+ relationsToData (): any;
157
+ toJSON (): any;
158
+ toJson (): string;
159
+ toString (): string;
160
+ isDirty (attributes?: string | string[]): boolean;
161
+ getDirty (): string[];
162
+ save (options?: any): Promise<boolean>;
163
+ update (attributes?: any, options?: any): Promise<boolean>;
164
+ increment (column: string, amount?: number, extra?: any): Promise<boolean>;
165
+ decrement (column: string, amount?: number, extra?: any): Promise<boolean>;
166
+ serializeDate (date: any): string;
167
+ delete (options?: any): Promise<boolean>;
168
+ softDelete (options?: any): Promise<boolean>;
169
+ forceDelete (options?: any): Promise<boolean>;
170
+ restore (options?: any): Promise<boolean>;
171
+ trashed (): boolean;
172
+ fresh (): Promise<this>;
173
+ refresh (): Promise<this | undefined>;
174
+ push (): Promise<boolean>;
175
+ is (model: this): boolean;
176
+ isNot (model: this): boolean;
177
+ // related(relation: string): Builder<any>;
178
+ // getRelated<T extends IModel>(relation: string): Promise<this | Collection<T> | null>;
179
+ related<T extends RelationNames<this>> (relation: T): ReturnTypeOfMethod<
180
+ this,
181
+ `relation${Capitalize<SnakeToCamelCase<T>>}`
182
+ >;
183
+ getRelated<T extends RelationNames<this>> (relation: T): ReturnTypeOfMethod<
184
+ ReturnTypeOfMethod<this, `relation${Capitalize<SnakeToCamelCase<T>>}`>, any>//'getResults'>;
185
+ hasOne<T extends Model> (model: new () => T, foreignKey?: string, localKey?: string): HasOne<T>;
186
+ hasMany<T extends Model> (model: new () => T, foreignKey?: string, localKey?: string): HasMany<T>;
187
+ belongsTo<T extends Model> (model: new () => T, foreignKey?: string, ownerKey?: string, relation?: string): BelongsTo<T>;
188
+ belongsToMany<T extends Model> (model: new () => T, table?: string, foreignPivotKey?: string, relatedPivotKey?: string, parentKey?: string, relatedKey?: string): BelongsToMany<T>;
189
+ }
190
+ export type IPivot = IModel & {}
@@ -0,0 +1,170 @@
1
+ import type { AnyQueryBuilder, GroupByMethod, JoinMethod, JoinRawMethod, OrderByMethod, OrderByRawMethod, RawInterface, SelectMethod, SetOperationsMethod, UnionMethod, WhereBetweenMethod, WhereColumnMethod, WhereExistsMethod, WhereFieldExpressionMethod, WhereInMethod, WhereJsonExpressionMethod, WhereMethod, WhereNullMethod, WhereRawMethod, WhereWrappedMethod } from './query-methods'
2
+ import type { ICollection, IPaginator, IPaginatorParams } from './utils'
3
+ import type { TFunction, TGeneric } from './generics'
4
+
5
+ import type BModel from 'src/browser/model'
6
+ import type { Knex } from 'knex'
7
+ import type Model from 'src/model'
8
+
9
+ export interface SchemaBuilder extends Knex.SchemaBuilder {
10
+ [k: string]: any
11
+ };
12
+
13
+ interface AsMethod<QB extends AnyQueryBuilder> {
14
+ (alias: string): QB;
15
+ }
16
+
17
+ export interface IStatement {
18
+ grouping: string
19
+ direction: string
20
+ type: string
21
+ value: () => any,
22
+ not: boolean
23
+ nulls: boolean
24
+ bool: 'and' | 'or' | 'not'
25
+ }
26
+
27
+ export type IConnector<M extends TGeneric = any, R = any> = Knex & Knex.QueryBuilder<M, R>
28
+
29
+ export interface IQueryBuilder<M extends Model | BModel = Model, R = M[] | M> {
30
+ // connector: IQueryBuilder<M, R>
31
+ schema: SchemaBuilder
32
+ _statements: IStatement[],
33
+ table (name: string): IQueryBuilder<M, R>
34
+ select: SelectMethod<this>
35
+ columns: SelectMethod<this>
36
+ column: SelectMethod<this>
37
+ distinct: SelectMethod<this>
38
+ distinctOn: SelectMethod<this>
39
+ as: AsMethod<this>
40
+ asProxy (): IQueryBuilder<M, R>
41
+ where: WhereMethod<this>
42
+ andWhere: WhereMethod<this>
43
+ // orWhere: WhereMethod<this>
44
+ orWhere (...args: any[]): this
45
+ whereNot: WhereMethod<this>
46
+ andWhereNot: WhereMethod<this>
47
+ orWhereNot: WhereMethod<this>
48
+
49
+ whereRaw: WhereRawMethod<this>
50
+ orWhereRaw: WhereRawMethod<this>
51
+ andWhereRaw: WhereRawMethod<this>
52
+
53
+ whereWrapped: WhereWrappedMethod<this>
54
+ havingWrapped: WhereWrappedMethod<this>
55
+
56
+ whereExists: WhereExistsMethod<this>
57
+ orWhereExists: WhereExistsMethod<this>
58
+ whereNotExists: WhereExistsMethod<this>
59
+ orWhereNotExists: WhereExistsMethod<this>
60
+
61
+ whereIn: WhereInMethod<this>
62
+ orWhereIn: WhereInMethod<this>
63
+ whereNotIn: WhereInMethod<this>
64
+ orWhereNotIn: WhereInMethod<this>
65
+
66
+ whereBetween: WhereBetweenMethod<this>
67
+ orWhereBetween: WhereBetweenMethod<this>
68
+ andWhereBetween: WhereBetweenMethod<this>
69
+ whereNotBetween: WhereBetweenMethod<this>
70
+ orWhereNotBetween: WhereBetweenMethod<this>
71
+ andWhereNotBetween: WhereBetweenMethod<this>
72
+
73
+ whereNull: WhereNullMethod<this>
74
+ orWhereNull: WhereNullMethod<this>
75
+ whereNotNull: WhereNullMethod<this>
76
+ orWhereNotNull: WhereNullMethod<this>
77
+
78
+ whereColumn: WhereColumnMethod<this>
79
+ orWhereColumn: WhereColumnMethod<this>
80
+ andWhereColumn: WhereColumnMethod<this>
81
+ whereNotColumn: WhereColumnMethod<this>
82
+ orWhereNotColumn: WhereColumnMethod<this>
83
+ andWhereNotColumn: WhereColumnMethod<this>
84
+
85
+ whereJsonIsArray: WhereFieldExpressionMethod<this>
86
+ orWhereJsonIsArray: WhereFieldExpressionMethod<this>
87
+ whereJsonNotArray: WhereFieldExpressionMethod<this>
88
+ orWhereJsonNotArray: WhereFieldExpressionMethod<this>
89
+ whereJsonIsObject: WhereFieldExpressionMethod<this>
90
+ orWhereJsonIsObject: WhereFieldExpressionMethod<this>
91
+ whereJsonNotObject: WhereFieldExpressionMethod<this>
92
+ orWhereJsonNotObject: WhereFieldExpressionMethod<this>
93
+ whereJsonHasAny: WhereJsonExpressionMethod<this>
94
+ orWhereJsonHasAny: WhereJsonExpressionMethod<this>
95
+ whereJsonHasAll: WhereJsonExpressionMethod<this>
96
+ orWhereJsonHasAll: WhereJsonExpressionMethod<this>
97
+
98
+ having: WhereMethod<this>
99
+ andHaving: WhereMethod<this>
100
+ orHaving: WhereMethod<this>
101
+
102
+ havingRaw: WhereRawMethod<this>
103
+ orHavingRaw: WhereRawMethod<this>
104
+
105
+ havingIn: WhereInMethod<this>
106
+ orHavingIn: WhereInMethod<this>
107
+ havingNotIn: WhereInMethod<this>
108
+ orHavingNotIn: WhereInMethod<this>
109
+
110
+ havingNull: WhereNullMethod<this>
111
+ orHavingNull: WhereNullMethod<this>
112
+ havingNotNull: WhereNullMethod<this>
113
+ orHavingNotNull: WhereNullMethod<this>
114
+
115
+ havingExists: WhereExistsMethod<this>
116
+ orHavingExists: WhereExistsMethod<this>
117
+ havingNotExists: WhereExistsMethod<this>
118
+ orHavingNotExists: WhereExistsMethod<this>
119
+
120
+ havingBetween: WhereBetweenMethod<this>
121
+ orHavingBetween: WhereBetweenMethod<this>
122
+ havingNotBetween: WhereBetweenMethod<this>
123
+ orHavingNotBetween: WhereBetweenMethod<this>
124
+
125
+ union: UnionMethod<this>
126
+ unionAll: UnionMethod<this>
127
+ intersect: SetOperationsMethod<this>
128
+
129
+ join: JoinMethod<this>
130
+ joinRaw: JoinRawMethod<this>
131
+ innerJoin: JoinMethod<this>
132
+ leftJoin: JoinMethod<this>
133
+ leftOuterJoin: JoinMethod<this>
134
+ rightJoin: JoinMethod<this>
135
+ rightOuterJoin: JoinMethod<this>
136
+ outerJoin: JoinMethod<this>
137
+ fullOuterJoin: JoinMethod<this>
138
+ crossJoin: JoinMethod<this>
139
+
140
+ orderBy: OrderByMethod<this>
141
+ orderByRaw: OrderByRawMethod<this>
142
+
143
+ groupBy: GroupByMethod<this>
144
+ groupByRaw: RawInterface<this>
145
+ transaction (callback?: TFunction): Promise<Knex.Transaction> | undefined;
146
+ destroy (callback: TFunction): Promise<number>;
147
+ destroy (): Promise<number>;
148
+ clone (): IQueryBuilder<M, R>;
149
+ raw: Knex.RawQueryBuilder<TGeneric, M>;
150
+ get (columns?: string[]): Promise<any>;
151
+ first (columns?: string[]): Promise<M | null | undefined>;
152
+ find (key: string | number, columns?: string[]): Promise<M | null | undefined>;
153
+ insert (attributes: any): Promise<unknown>;
154
+ update (...attributes: any[]): Promise<number>;
155
+ delete (): Promise<boolean | number>;
156
+ exists (): Promise<boolean>;
157
+ count (column?: string): Promise<number>;
158
+ min (column: string): Promise<number>;
159
+ max (column: string): Promise<number>;
160
+ sum (column: string): Promise<number>;
161
+ avg (column: string): Promise<number>;
162
+ skip (count: number): this;
163
+ take (count: number): this;
164
+ limit (count: number): this;
165
+ offset (count: number): this;
166
+ pluck<X extends Model = any> (column: string): Promise<ICollection<X>>;
167
+ chunk (count: number, callback: (rows: M[]) => any): Promise<boolean>;
168
+ forPage (page: number, perPage?: number): this;
169
+ paginate<F extends IPaginatorParams> (page?: number, perPage?: number): Promise<IPaginator<M, F>>;
170
+ }
@@ -0,0 +1,183 @@
1
+ import type { IBuilder } from './builder'
2
+ import type { IQueryBuilder } from './query-builder'
3
+ import type { Knex } from 'knex'
4
+ import type { Model } from 'src/model'
5
+ import type { PrimitiveValue } from './generics'
6
+
7
+ type Operator = string;
8
+ type ColumnRef = string | Raw;
9
+ type FieldExpression = string;
10
+ type JsonObjectOrFieldExpression = object | object[] | FieldExpression;
11
+
12
+ type TableRef<QB extends AnyQueryBuilder> = ColumnRef | AnyQueryBuilder | CallbackVoid<QB>;
13
+ type Selection<QB extends AnyQueryBuilder> = ColumnRef | AnyQueryBuilder | CallbackVoid<QB>;
14
+ type QBOrCallback<QB extends AnyQueryBuilder> = AnyQueryBuilder | CallbackVoid<QB>;
15
+
16
+ interface CallbackVoid<T> {
17
+ (this: T, arg: T): void;
18
+ }
19
+
20
+ export type Raw = Knex.Raw;
21
+
22
+ export type OrderByDirection = 'asc' | 'desc' | 'ASC' | 'DESC';
23
+
24
+ export interface OrderByDescriptor {
25
+ column: ColumnRef;
26
+ order?: OrderByDirection;
27
+ }
28
+
29
+ export type AnyQueryBuilder<M extends Model = any, R = any> = IQueryBuilder<M, R> | IBuilder<M, R>;
30
+
31
+ export type Expression<T> = T | Raw | AnyQueryBuilder;
32
+
33
+ export type ColumnRefOrOrderByDescriptor = ColumnRef | OrderByDescriptor;
34
+
35
+ export interface RawInterface<R> {
36
+ (sql: string, ...bindings: any[]): R;
37
+ }
38
+
39
+ export interface BaseSetOperations<QB extends AnyQueryBuilder> {
40
+ (callbackOrBuilder: QBOrCallback<QB>, wrap?: boolean): QB;
41
+ (callbacksOrBuilders: QBOrCallback<QB>[], wrap?: boolean): QB;
42
+ }
43
+
44
+ export type JoinRawMethod<QB extends AnyQueryBuilder> = RawInterface<QB> & {}
45
+
46
+ export type OrderByRawMethod<QB extends AnyQueryBuilder> = RawInterface<QB> & {}
47
+
48
+ export type WhereRawMethod<QB extends AnyQueryBuilder> = RawInterface<QB> & {}
49
+
50
+ export interface GroupByMethod<QB extends AnyQueryBuilder> {
51
+ (...columns: ColumnRef[]): QB;
52
+ (columns: ColumnRef[]): QB;
53
+ }
54
+
55
+ export type WithRelationType = {
56
+ [key: string]: <T extends IBuilder<any>>(builder: T) => T | void;
57
+ } | string | string[];
58
+
59
+ export interface SetOperationsMethod<QB extends AnyQueryBuilder> extends BaseSetOperations<QB> {
60
+ (...callbacksOrBuilders: QBOrCallback<QB>[]): QB;
61
+ }
62
+
63
+ export interface SelectMethod<QB extends AnyQueryBuilder> {
64
+ <QBP extends QB> (...columns: Selection<QBP>[]): QB;
65
+ <QBP extends QB> (columns: Selection<QBP>[]): QB;
66
+ }
67
+
68
+ export interface WhereMethod<QB extends AnyQueryBuilder> {
69
+ (col: ColumnRef, op: Operator, expr: Expression<PrimitiveValue>): QB;
70
+ (col: ColumnRef, expr: Expression<PrimitiveValue>): QB;
71
+
72
+ (condition: boolean): QB;
73
+ (cb: CallbackVoid<QB>): QB;
74
+ (raw: Raw): QB;
75
+ <QBA extends AnyQueryBuilder> (qb: QBA): QB;
76
+
77
+ (obj: object): QB;
78
+ }
79
+
80
+ export interface WhereWrappedMethod<QB extends AnyQueryBuilder> {
81
+ (cb: CallbackVoid<QB>): QB;
82
+ }
83
+
84
+ export interface WhereFieldExpressionMethod<QB extends AnyQueryBuilder> {
85
+ (fieldExpression: FieldExpression): QB;
86
+ }
87
+
88
+ export interface WhereExistsMethod<QB extends AnyQueryBuilder> {
89
+ (cb: CallbackVoid<QB>): QB;
90
+ (raw: Raw): QB;
91
+ <QBA extends AnyQueryBuilder> (qb: QBA): QB;
92
+ }
93
+
94
+ export interface WhereInMethod<QB extends AnyQueryBuilder> {
95
+ (col: ColumnRef | ColumnRef[], expr: Expression<PrimitiveValue>[]): QB;
96
+ (col: ColumnRef | ColumnRef[], cb: CallbackVoid<QB>): QB;
97
+ (col: ColumnRef | ColumnRef[], qb: AnyQueryBuilder): QB;
98
+ }
99
+
100
+ export interface WhereBetweenMethod<QB extends AnyQueryBuilder> {
101
+ (column: ColumnRef, range: [Expression<PrimitiveValue>, Expression<PrimitiveValue>]): QB;
102
+ }
103
+
104
+ export interface WhereNullMethod<QB extends AnyQueryBuilder> {
105
+ (column: ColumnRef): QB;
106
+ }
107
+
108
+ export interface OrderByMethod<QB extends AnyQueryBuilder> {
109
+ (column: ColumnRef, order?: OrderByDirection): QB;
110
+ (columns: ColumnRefOrOrderByDescriptor[]): QB;
111
+ }
112
+
113
+ export interface WhereJsonExpressionMethod<QB extends AnyQueryBuilder> {
114
+ (fieldExpression: FieldExpression, keys: string | string[]): QB;
115
+ }
116
+
117
+ export interface WhereColumnMethod<QB extends AnyQueryBuilder> {
118
+ (col1: ColumnRef, op: Operator, col2: ColumnRef): QB;
119
+ (col1: ColumnRef, col2: ColumnRef): QB;
120
+ }
121
+
122
+ export interface JoinMethod<QB extends AnyQueryBuilder> {
123
+ (table: TableRef<QB>, leftCol: ColumnRef, op: Operator, rightCol: ColumnRef): QB;
124
+ (table: TableRef<QB>, leftCol: ColumnRef, rightCol: ColumnRef): QB;
125
+ (table: TableRef<QB>, cb: CallbackVoid<Knex.JoinClause>): QB;
126
+ (table: TableRef<QB>, raw: Raw): QB;
127
+ (raw: Raw): QB;
128
+ }
129
+
130
+ export interface WhereJsonMethod<QB extends AnyQueryBuilder> {
131
+ (
132
+ fieldExpression: FieldExpression,
133
+ jsonObjectOrFieldExpression: JsonObjectOrFieldExpression
134
+ ): QB;
135
+ }
136
+
137
+ export interface UnionMethod<QB extends AnyQueryBuilder> extends BaseSetOperations<QB> {
138
+ (arg1: QBOrCallback<QB>, wrap?: boolean): QB;
139
+ (arg1: QBOrCallback<QB>, arg2: QBOrCallback<QB>, wrap?: boolean): QB;
140
+ (arg1: QBOrCallback<QB>, arg2: QBOrCallback<QB>, arg3: QBOrCallback<QB>, wrap?: boolean): QB;
141
+ (
142
+ arg1: QBOrCallback<QB>,
143
+ arg2: QBOrCallback<QB>,
144
+ arg3: QBOrCallback<QB>,
145
+ arg4: QBOrCallback<QB>,
146
+ wrap?: boolean
147
+ ): QB;
148
+ (
149
+ arg1: QBOrCallback<QB>,
150
+ arg2: QBOrCallback<QB>,
151
+ arg3: QBOrCallback<QB>,
152
+ arg4: QBOrCallback<QB>,
153
+ arg5: QBOrCallback<QB>,
154
+ wrap?: boolean
155
+ ): QB;
156
+ (
157
+ arg1: QBOrCallback<QB>,
158
+ arg2: QBOrCallback<QB>,
159
+ arg3: QBOrCallback<QB>,
160
+ arg4: QBOrCallback<QB>,
161
+ arg5: QBOrCallback<QB>,
162
+ arg6: QBOrCallback<QB>,
163
+ wrap?: boolean
164
+ ): QB;
165
+ (
166
+ arg1: QBOrCallback<QB>,
167
+ arg2: QBOrCallback<QB>,
168
+ arg3: QBOrCallback<QB>,
169
+ arg4: QBOrCallback<QB>,
170
+ arg5: QBOrCallback<QB>,
171
+ arg6: QBOrCallback<QB>,
172
+ arg7: QBOrCallback<QB>,
173
+ wrap?: boolean
174
+ ): QB;
175
+ }
176
+
177
+ export interface JoinMethod<QB extends AnyQueryBuilder> {
178
+ (table: TableRef<QB>, leftCol: ColumnRef, op: Operator, rightCol: ColumnRef): QB;
179
+ (table: TableRef<QB>, leftCol: ColumnRef, rightCol: ColumnRef): QB;
180
+ (table: TableRef<QB>, cb: CallbackVoid<Knex.JoinClause>): QB;
181
+ (table: TableRef<QB>, raw: Raw): QB;
182
+ (raw: Raw): QB;
183
+ }
package/types/utils.ts ADDED
@@ -0,0 +1,69 @@
1
+ import type BModel from 'src/browser/model'
2
+ import type { Collection as BaseCollection } from 'collect.js'
3
+ import type Collection from 'src/collection'
4
+ import type { IBuilder } from './builder'
5
+ import type { IModel } from './modeling'
6
+ import type Model from 'src/model'
7
+ import type { TGeneric } from './generics'
8
+
9
+ export interface ICollection<T extends Model | BModel> extends BaseCollection<T> {
10
+ items?: T[];
11
+ load (...relations: T[]): Promise<ICollection<T>>;
12
+ loadAggregate (relations: T | T[], column: string, action?: string | null): Promise<this>;
13
+ loadCount (relation: T, column: string): Promise<this>;
14
+ loadMax (relation: T, column: string): Promise<this>;
15
+ loadMin (relation: T, column: string): Promise<this>;
16
+ loadSum (relation: T, column: string): Promise<this>;
17
+ loadAvg (relation: T, column: string): Promise<this>;
18
+ mapThen (callback: () => void): Promise<any>;
19
+ modelKeys (): string[] | number[];
20
+ contains (key: IModel | any, operator?: any, value?: any): boolean;
21
+ diff (items: ICollection<T> | any[]): ICollection<T>;
22
+ except (keys: any[]): ICollection<T>;
23
+ intersect (items: T[]): ICollection<T>;
24
+ unique (key?: any, strict?: boolean): ICollection<T>;
25
+ find (key: any, defaultValue?: any): any;
26
+ fresh (withs?: any[]): Promise<ICollection<T>>;
27
+ makeVisible (attributes: string | string[]): this;
28
+ makeHidden (attributes: string | string[]): this;
29
+ append (attributes: string[]): this;
30
+ only (keys: null | any[]): this;
31
+ getDictionary (items?: any[]): TGeneric;
32
+ toQuery (): IBuilder<T, any>;
33
+ toData (): any;
34
+ toJSON (): any;
35
+ toJson (): string;
36
+ toString (): string;
37
+ [key: string]: any;
38
+ [Symbol.iterator]: () => Iterator<T>;
39
+ }
40
+
41
+ export interface IPaginatorParams {
42
+ current_page: number,
43
+ data: any[],
44
+ per_page: number,
45
+ total: number,
46
+ last_page: number,
47
+ count: number,
48
+ }
49
+
50
+ export interface IPaginator<T extends Model | BModel, K extends IPaginatorParams = IPaginatorParams> {
51
+ formatter?(paginator: IPaginator<any>): any | null
52
+ setFormatter?(formatter: (paginator: IPaginator<any>) => any | null): void;
53
+ setItems (items: T[] | Collection<T>): void;
54
+ hasMorePages (): boolean;
55
+ get (index: number): T | null;
56
+ count (): number;
57
+ items (): Collection<T>;
58
+ map (callback: (value: T, index: number) => T): Collection<T>;
59
+ currentPage (): number;
60
+ perPage (): number;
61
+ lastPage (): number;
62
+ firstItem (): number | null;
63
+ lastItem (): number | null;
64
+ total (): number;
65
+ toData<U = K> (): U;
66
+ toJSON<U = K> (): U;
67
+ toJson (): string;
68
+ [Symbol.iterator]?(): { next: () => { value: T; done: boolean } };
69
+ }