@h3ravel/arquebus 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +20 -1
  2. package/bin/index.cjs +225 -171
  3. package/bin/index.js +208 -122
  4. package/bin/seeders-8GJzfIIN.js +3 -0
  5. package/bin/seeders-ByeSoCAQ.cjs +131 -0
  6. package/bin/seeders-CltigymO.js +79 -0
  7. package/bin/seeders-_xJ6VGVS.cjs +3 -0
  8. package/dist/browser/index.cjs +9 -9
  9. package/dist/browser/index.d.cts +3655 -183
  10. package/dist/browser/index.d.ts +3655 -183
  11. package/dist/browser/index.js +9 -9
  12. package/dist/index.cjs +270 -135
  13. package/dist/index.d.cts +3797 -294
  14. package/dist/index.d.ts +3797 -294
  15. package/dist/index.js +263 -133
  16. package/dist/inspector/index.cjs +122 -46
  17. package/dist/inspector/index.js +119 -46
  18. package/dist/migrations/index.cjs +171 -151
  19. package/dist/migrations/index.d.cts +3510 -27
  20. package/dist/migrations/index.d.ts +3510 -27
  21. package/dist/migrations/index.js +177 -150
  22. package/dist/migrations/stubs/migration-js.stub +1 -1
  23. package/dist/migrations/stubs/migration-ts.stub +1 -1
  24. package/dist/migrations/stubs/migration.create-js.stub +5 -5
  25. package/dist/migrations/stubs/migration.create-ts.stub +5 -5
  26. package/dist/migrations/stubs/migration.update-js.stub +2 -2
  27. package/dist/migrations/stubs/migration.update-ts.stub +3 -3
  28. package/dist/seeders/index.cjs +141 -0
  29. package/dist/seeders/index.d.cts +4766 -0
  30. package/dist/seeders/index.d.ts +4766 -0
  31. package/dist/seeders/index.js +118 -0
  32. package/dist/seeders/index.ts +3 -0
  33. package/dist/seeders/runner.ts +102 -0
  34. package/dist/seeders/seeder-creator.ts +42 -0
  35. package/dist/seeders/seeder.ts +10 -0
  36. package/dist/stubs/seeder-js.stub +13 -0
  37. package/dist/stubs/seeder-ts.stub +9 -0
  38. package/package.json +15 -4
  39. package/types/builder.ts +158 -80
  40. package/types/container.ts +79 -66
  41. package/types/generics.ts +75 -36
  42. package/types/modeling.ts +213 -158
  43. package/types/query-builder.ts +223 -186
  44. package/types/query-methods.ts +160 -104
  45. package/types/utils.ts +64 -55
package/types/modeling.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import type { AnyQueryBuilder, WithRelationType } from './query-methods'
2
- import type { Hook, RelationNames, ReturnTypeOfMethod, SnakeToCamelCase, TFunction, TGeneric } from './generics'
2
+ import type {
3
+ Hook,
4
+ RelationNames,
5
+ ReturnTypeOfMethod,
6
+ SnakeToCamelCase,
7
+ TFunction,
8
+ TGeneric,
9
+ } from './generics'
3
10
 
4
11
  import type { IBuilder } from './builder'
5
12
  import type { ICollection } from './utils'
@@ -7,184 +14,232 @@ import type Model from 'src/model'
7
14
  import type { TBaseConfig } from './container'
8
15
 
9
16
  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
17
+ make(config: { get?: TFunction | null; set?: TFunction | null }): Attribute
18
+ get: TFunction | null
19
+ set: TFunction | null
20
+ withCaching?: boolean
21
+ withObjectCaching?: boolean
15
22
  }
16
23
 
17
24
  export interface CastsAttributes {
18
- get (): any;
19
- set (): void;
25
+ get(): any
26
+ set(): void
20
27
  }
21
28
 
22
- export type Relation<M extends Model> = IBuilder<M, any> & {
23
- }
29
+ export type Relation<M extends Model> = IBuilder<M, any> & {}
24
30
 
25
31
  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>>;
32
+ save(model: M): Promise<M>
33
+ saveMany(models: M[] | ICollection<M>): Promise<ICollection<M>>
34
+ create(attributes?: any): Promise<M>
35
+ createMany(records: any[]): Promise<ICollection<M>>
30
36
  }
31
37
 
32
38
  export interface HasOne<M extends Model> extends HasOneOrMany<M> {
33
- getResults (): Promise<M | null>;
34
- withDefault (callback?: TFunction | object): this;
39
+ getResults(): Promise<M | null>
40
+ withDefault(callback?: TFunction | object): this
35
41
  }
36
42
 
37
43
  export interface HasMany<M extends Model> extends HasOneOrMany<M> {
38
- getResults (): Promise<ICollection<M>>;
44
+ getResults(): Promise<ICollection<M>>
39
45
  }
40
46
 
41
47
  export interface BelongsTo<M extends Model> extends Relation<M> {
42
- getResults (): Promise<M | null>;
43
- withDefault (callback?: TFunction | object): this;
48
+ getResults(): Promise<M | null>
49
+ withDefault(callback?: TFunction | object): this
44
50
  }
45
51
 
46
52
  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;
53
+ getResults(): Promise<ICollection<M>>
54
+ withTimestamps(): this
55
+ wherePivot(
56
+ column: any,
57
+ operator?: any,
58
+ value?: any,
59
+ boolean?: string,
60
+ ...args: any[]
61
+ ): this
62
+ wherePivotBetween(
63
+ column: any,
64
+ values: any,
65
+ boolean?: string,
66
+ not?: boolean,
67
+ ): this
68
+ orWherePivotBetween(column: any, values: any): this
69
+ wherePivotNotBetween(column: any, values: any, boolean?: string): this
70
+ orWherePivotNotBetween(column: any, values: any): this
71
+ wherePivotIn(column: any, values: any, boolean?: string, not?: boolean): this
72
+ orWherePivot(column: any, operator?: any, value?: any): this
73
+ orWherePivotIn(column: any, values: any): this
74
+ wherePivotNotIn(column: any, values: any, boolean?: string): this
75
+ orWherePivotNotIn(column: any, values: any): this
76
+ wherePivotNull(column: any, boolean?: string, not?: boolean): this
77
+ wherePivotNotNull(column: any, boolean?: string): this
78
+ orWherePivotNull(column: any, not?: boolean): this
79
+ orWherePivotNotNull(column: any): this
80
+ orderByPivot(column: any, direction?: string): this
64
81
  }
65
82
 
66
83
  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>;
84
+ [value: string]: any
85
+ attributes: any
86
+ relations: any
87
+ exists: boolean
88
+ // primaryKey: string
89
+ // builder?: IBuilder<any, any> | null
90
+ // table: string | null
91
+ connection?: TBaseConfig['client'] | null
92
+ // keyType: string
93
+ // incrementing: boolean
94
+ perPage: number
95
+ with: string | string[] | TGeneric<(...args: any[]) => IBuilder<Model>>
96
+ // withCount: string[]
97
+ trx: AnyQueryBuilder | null
98
+ timestamps: boolean
99
+ dateFormat: string
100
+ visible: string[]
101
+ hidden: string[]
102
+ query<T extends { prototype: unknown }>(
103
+ this: T,
104
+ client?: AnyQueryBuilder | null,
105
+ ): IBuilder<Model>
106
+ on<T extends { prototype: unknown }>(
107
+ this: T,
108
+ connection: string | null,
109
+ ): IBuilder<Model>
110
+ boot(): void
111
+ make<T extends IModel>(this: new () => T, attributes?: TGeneric): T
112
+ addHook(hook: Hook, callback: TFunction): void
113
+ creating(callback: TFunction): void
114
+ created(callback: TFunction): void
115
+ updating(callback: TFunction): void
116
+ updated(callback: TFunction): void
117
+ deleting(callback: TFunction): void
118
+ deleted(callback: TFunction): void
119
+ saving(callback: TFunction): void
120
+ saved(callback: TFunction): void
121
+ restoring(callback: TFunction): void
122
+ restored(callback: TFunction): void
123
+ trashed(callback: TFunction): void
124
+ forceDeleted(callback: TFunction): void
125
+ bootIfNotBooted(): void
126
+ initialize(): void
127
+ initializePlugins(): void
128
+ addPluginInitializer(method: any): void
129
+ newInstance(attributes?: TGeneric, exists?: boolean): any
130
+ getKey(): string | number | null | undefined
131
+ getKeyName(): string
132
+ getConnectionName(): string
133
+ getConnection(): any
134
+ setConnection(connection: TBaseConfig['client'] | null): this
135
+ usesUniqueIds(): boolean
136
+ uniqueIds(): string[]
137
+ // newUniqueId (): string;
138
+ setUniqueIds(): void
139
+ getKeyType(): string
140
+ getIncrementing(): boolean
141
+ setIncrementing(value: boolean): this
142
+ getTable(): string
143
+ setTable(table: string): this
144
+ getDates(): string[]
145
+ getDateFormat(): string
146
+ getAttributes(): object
147
+ getAttribute(key: string): any
148
+ setAttribute(key: string, value: any): this
149
+ fill(attributes: any): this
150
+ setAppends(appends: string[]): this
151
+ append(key: string | string[]): this
152
+ getRelation<T extends Model>(
153
+ relation: string,
154
+ ): T | ICollection<T> | null | undefined
155
+ setRelation<T extends Model>(
156
+ relation: string,
157
+ value: T | ICollection<T> | null,
158
+ ): this
159
+ unsetRelation(relation: string): this
160
+ relationLoaded(relation: string): boolean
161
+ makeVisible(attributes: string | string[]): this
162
+ makeHidden(attributes: string | string[]): this
163
+ newCollection(models?: any[]): ICollection<Model>
164
+ load(relations: WithRelationType): Promise<this>
165
+ load(...relations: WithRelationType[]): Promise<this>
166
+ loadAggregate(
167
+ relations: WithRelationType,
168
+ column: any,
169
+ callback?: any,
170
+ ): Promise<this>
171
+ loadCount(...relations: WithRelationType[]): Promise<this>
172
+ loadMax(relations: WithRelationType, column: string): Promise<this>
173
+ loadMin(relations: WithRelationType, column: string): Promise<this>
174
+ loadSum(relations: WithRelationType, column: string): Promise<this>
175
+ usesTimestamps(): boolean
176
+ updateTimestamps(): this
177
+ getCreatedAtColumn(): string
178
+ getUpdatedAtColumn(): string
179
+ getDeletedAtColumn(): string
180
+ setCreatedAt(value: string): this
181
+ setUpdatedAt(value: string): this
182
+ freshTimestamp(): Date
183
+ freshTimestampString(): string
184
+ fromDateTime(value: Date | number | null): string
185
+ useSoftDeletes(): boolean
186
+ toData(): any
187
+ attributesToData(): any
188
+ relationsToData(): any
189
+ toJSON(): any
190
+ toJson(): string
191
+ toString(): string
192
+ isDirty(attributes?: string | string[]): boolean
193
+ getDirty(): string[]
194
+ save(options?: any): Promise<boolean>
195
+ update(attributes?: any, options?: any): Promise<boolean>
196
+ increment(column: string, amount?: number, extra?: any): Promise<boolean>
197
+ decrement(column: string, amount?: number, extra?: any): Promise<boolean>
198
+ serializeDate(date: any): string
199
+ delete(options?: any): Promise<boolean>
200
+ softDelete(options?: any): Promise<boolean>
201
+ forceDelete(options?: any): Promise<boolean>
202
+ restore(options?: any): Promise<boolean>
203
+ trashed(): boolean
204
+ fresh(): Promise<this>
205
+ refresh(): Promise<this | undefined>
206
+ push(): Promise<boolean>
207
+ is(model: this): boolean
208
+ isNot(model: this): boolean
209
+ // related(relation: string): Builder<any>;
210
+ // getRelated<T extends IModel>(relation: string): Promise<this | Collection<T> | null>;
211
+ related<T extends RelationNames<this>>(
212
+ relation: T,
213
+ ): ReturnTypeOfMethod<this, `relation${Capitalize<SnakeToCamelCase<T>>}`>
214
+ getRelated<T extends RelationNames<this>>(
215
+ relation: T,
216
+ ): ReturnTypeOfMethod<
217
+ ReturnTypeOfMethod<this, `relation${Capitalize<SnakeToCamelCase<T>>}`>,
218
+ any
219
+ > //'getResults'>;
220
+ hasOne<T extends Model>(
221
+ model: new () => T,
222
+ foreignKey?: string,
223
+ localKey?: string,
224
+ ): HasOne<T>
225
+ hasMany<T extends Model>(
226
+ model: new () => T,
227
+ foreignKey?: string,
228
+ localKey?: string,
229
+ ): HasMany<T>
230
+ belongsTo<T extends Model>(
231
+ model: new () => T,
232
+ foreignKey?: string,
233
+ ownerKey?: string,
234
+ relation?: string,
235
+ ): BelongsTo<T>
236
+ belongsToMany<T extends Model>(
237
+ model: new () => T,
238
+ table?: string,
239
+ foreignPivotKey?: string,
240
+ relatedPivotKey?: string,
241
+ parentKey?: string,
242
+ relatedKey?: string,
243
+ ): BelongsToMany<T>
189
244
  }
190
245
  export type IPivot = IModel & {}