@h3ravel/arquebus 0.5.0 → 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 +196 -144
  3. package/bin/index.js +177 -94
  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 +7 -7
  10. package/dist/browser/index.d.ts +7 -7
  11. package/dist/browser/index.js +9 -9
  12. package/dist/index.cjs +252 -121
  13. package/dist/index.d.cts +40 -8
  14. package/dist/index.d.ts +40 -8
  15. package/dist/index.js +245 -119
  16. package/dist/inspector/index.cjs +105 -33
  17. package/dist/inspector/index.js +102 -33
  18. package/dist/migrations/index.cjs +144 -126
  19. package/dist/migrations/index.d.cts +10 -10
  20. package/dist/migrations/index.d.ts +10 -10
  21. package/dist/migrations/index.js +148 -130
  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 +14 -3
  39. package/types/builder.ts +153 -80
  40. package/types/container.ts +79 -66
  41. package/types/generics.ts +75 -37
  42. package/types/modeling.ts +213 -158
  43. package/types/query-builder.ts +221 -191
  44. package/types/query-methods.ts +145 -109
  45. package/types/utils.ts +64 -56
@@ -8,77 +8,90 @@ import type Relation from 'src/relations/relation'
8
8
  import type { arquebus } from 'src'
9
9
 
10
10
  export interface TBaseConfig {
11
- client: 'mysql' | 'mysql2' | 'sqlite3' | 'oracle' | 'mariadb' | 'pg'
12
- connection: {
13
- typeCast?(field: TField, next: TFunction): any
14
- dateStrings?: boolean
15
- }
16
- pool?: {
17
- afterCreate: (connection: TConfig, callback: (val: any, con: any) => void) => Promise<any>
18
- } | undefined
19
- connections?: arquebus['connections']
20
- migrations?: {
21
- table: string
22
- path: string
23
- },
24
- factories?: {
25
- path: string
26
- },
27
- seeders?: {
28
- path: string
29
- },
30
- models?: {
31
- path: string
32
- }
11
+ client: 'mysql' | 'mysql2' | 'sqlite3' | 'oracle' | 'mariadb' | 'pg'
12
+ connection: {
13
+ typeCast?(field: TField, next: TFunction): any
14
+ dateStrings?: boolean
15
+ }
16
+ pool?:
17
+ | {
18
+ afterCreate: (
19
+ connection: TConfig,
20
+ callback: (val: any, con: any) => void,
21
+ ) => Promise<any>
22
+ }
23
+ | undefined
24
+ connections?: arquebus['connections']
25
+ migrations?: {
26
+ table: string
27
+ path: string
28
+ }
29
+ factories?: {
30
+ path: string
31
+ }
32
+ seeders?: {
33
+ path: string
34
+ }
35
+ models?: {
36
+ path: string
37
+ }
33
38
  }
34
39
 
35
- export type TConfig = TBaseConfig & ({
36
- client: 'pg'
37
- connection: Knex.PgConnectionConfig
38
- } | {
39
- client: 'oracle'
40
- connection: Knex.OracleDbConnectionConfig
41
- } | {
42
- client: 'mysql2'
43
- connection: Knex.MySql2ConnectionConfig
44
- } | {
45
- client: 'mysql'
46
- connection: Knex.MySqlConnectionConfig
47
- } | {
48
- client: 'sqlite3'
49
- connection: Knex.Sqlite3ConnectionConfig
50
- useNullAsDefault?: boolean
51
- } | {
52
- client: 'mariadb'
53
- connection: Knex.MariaSqlConnectionConfig
54
- useNullAsDefault?: boolean
55
- })
40
+ export type TConfig = TBaseConfig &
41
+ (
42
+ | {
43
+ client: 'pg'
44
+ connection: Knex.PgConnectionConfig
45
+ }
46
+ | {
47
+ client: 'oracle'
48
+ connection: Knex.OracleDbConnectionConfig
49
+ }
50
+ | {
51
+ client: 'mysql2'
52
+ connection: Knex.MySql2ConnectionConfig
53
+ }
54
+ | {
55
+ client: 'mysql'
56
+ connection: Knex.MySqlConnectionConfig
57
+ }
58
+ | {
59
+ client: 'sqlite3'
60
+ connection: Knex.Sqlite3ConnectionConfig
61
+ useNullAsDefault?: boolean
62
+ }
63
+ | {
64
+ client: 'mariadb'
65
+ connection: Knex.MariaSqlConnectionConfig
66
+ useNullAsDefault?: boolean
67
+ }
68
+ )
56
69
 
57
70
  export interface ModelOptions<M extends Model = Model> {
58
- table?: string
59
- scopes?: TGeneric<(...args: any[]) => Builder<M>>
60
- plugins?: (<X extends MixinConstructor<M>>(Model: X) => MixinConstructor<M>)[]
61
- relations?: TGeneric<(...args: any[]) => Relation>
62
- attributes?: TGeneric<Attribute>
63
- CREATED_AT?: string
64
- UPDATED_AT?: string
65
- DELETED_AT?: string
66
- connection?: TBaseConfig['client']
67
- timestamps?: boolean
68
- primaryKey?: string
69
- incrementing?: boolean
70
- keyType?: 'int' | 'string'
71
- with?: Model['with']
72
- casts?: Model['casts']
71
+ table?: string
72
+ scopes?: TGeneric<(...args: any[]) => Builder<M>>
73
+ plugins?: (<X extends MixinConstructor<M>>(Model: X) => MixinConstructor<M>)[]
74
+ relations?: TGeneric<(...args: any[]) => Relation>
75
+ attributes?: TGeneric<Attribute>
76
+ CREATED_AT?: string
77
+ UPDATED_AT?: string
78
+ DELETED_AT?: string
79
+ connection?: TBaseConfig['client']
80
+ timestamps?: boolean
81
+ primaryKey?: string
82
+ incrementing?: boolean
83
+ keyType?: 'int' | 'string'
84
+ with?: Model['with']
85
+ casts?: Model['casts']
73
86
  }
74
87
 
75
88
  export interface TField {
76
- type: 'VAR_STRING' | 'BLOB' | 'DATETIME' | 'TIMESTAMP' | 'LONG' | 'JSON'
77
- length: number
78
- db: string
79
- table: string
80
- name: string
81
- string: TFunction,
82
- buffer: TFunction
83
- geometry: TFunction
89
+ type: 'VAR_STRING' | 'BLOB' | 'DATETIME' | 'TIMESTAMP' | 'LONG' | 'JSON'
90
+ length: number
91
+ db: string
92
+ table: string
93
+ name: string
94
+ string: TFunction
95
+ buffer: TFunction
96
+ geometry: TFunction
84
97
  }
package/types/generics.ts CHANGED
@@ -2,71 +2,109 @@ import type Model from 'src/model'
2
2
 
3
3
  export type TGeneric<V = any, K extends string = string> = Record<K, V>
4
4
  export type XGeneric<V = TGeneric, T = any> = {
5
- [key: string]: T
5
+ [key: string]: T
6
6
  } & V
7
7
 
8
8
  export interface Plugin {
9
- (model: Model, config: TGeneric): void
9
+ (model: Model, config: TGeneric): void
10
10
  }
11
11
 
12
12
  export type Hook =
13
- | 'creating' | 'created' | 'updating' | 'updated' | 'saving' | 'saved' | 'deleting' | 'deleted'
14
- | 'restoring' | 'restored' | 'trashed' | 'forceDeleted';
13
+ | 'creating'
14
+ | 'created'
15
+ | 'updating'
16
+ | 'updated'
17
+ | 'saving'
18
+ | 'saved'
19
+ | 'deleting'
20
+ | 'deleted'
21
+ | 'restoring'
22
+ | 'restored'
23
+ | 'trashed'
24
+ | 'forceDeleted'
15
25
 
16
- export type TFunction<TArgs extends any[] = any[], TReturn = any> = (...args: TArgs) => TReturn;
26
+ export type TFunction<TArgs extends any[] = any[], TReturn = any> = (
27
+ ...args: TArgs
28
+ ) => TReturn
17
29
 
18
30
  export type PrimitiveValue =
19
- | string
20
- | number
21
- | boolean
22
- | Date
23
- | string[]
24
- | number[]
25
- | boolean[]
26
- | Date[]
27
- | null
28
- | Buffer;
31
+ | string
32
+ | number
33
+ | boolean
34
+ | Date
35
+ | string[]
36
+ | number[]
37
+ | boolean[]
38
+ | Date[]
39
+ | null
40
+ | Buffer
29
41
 
30
- export type ReturnTypeOfMethod<T, K extends keyof T> = T[K] extends (...args: any[]) => infer R ? R : never;
42
+ export type ReturnTypeOfMethod<T, K extends keyof T> = T[K] extends (
43
+ ...args: any[]
44
+ ) => infer R
45
+ ? R
46
+ : never
31
47
 
32
48
  export type SnakeToCamelCase<S extends string> =
33
- S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
49
+ S extends `${infer T}_${infer U}`
50
+ ? `${T}${Capitalize<SnakeToCamelCase<U>>}`
51
+ : S
34
52
 
35
53
  // declare const model: ModelDecorator;
36
54
  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;
55
+ S extends `${infer T}${infer U}`
56
+ ? U extends Uncapitalize<U>
57
+ ? `${Uncapitalize<T>}${CamelToSnakeCase<U>}`
58
+ : `${Uncapitalize<T>}_${CamelToSnakeCase<U>}`
59
+ : S
40
60
 
41
61
  export type FunctionPropertyNames<T> = {
42
- [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
43
- }[keyof T];
62
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never
63
+ }[keyof T]
44
64
 
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;
65
+ export type RelationNames<T> =
66
+ FunctionPropertyNames<T> extends infer R
67
+ ? R extends `relation${infer P}`
68
+ ? P extends 'sToData' | 'loaded'
69
+ ? never
70
+ : CamelToSnakeCase<P>
71
+ : never
72
+ : never
48
73
 
49
74
  export type MixinConstructor<T = TGeneric> = new (...args: any[]) => T
50
- export type AbstractConstructor<T = TGeneric> = abstract new (...args: any[]) => T;
75
+ export type AbstractConstructor<T = TGeneric> = abstract new (
76
+ ...args: any[]
77
+ ) => T
51
78
 
52
79
  // Helper type: combine all mixin instance types into a single intersection
53
- export type MixinReturn<Base extends MixinConstructor, Mixins extends ((base: any) => any)[]> =
54
- Base extends MixinConstructor<infer B>
80
+ export type MixinReturn<
81
+ Base extends MixinConstructor,
82
+ Mixins extends ((base: any) => any)[],
83
+ > =
84
+ Base extends MixinConstructor<infer B>
55
85
  ? IntersectionOfInstances<InstanceTypeOfMixins<Mixins>> & B
56
86
  : never
57
87
 
58
- export type InstanceTypeOfMixins<T extends ((base: any) => any)[]> =
59
- T extends [infer Head, ...infer Tail]
60
- ? Head extends (base: any) => infer R
88
+ export type InstanceTypeOfMixins<T extends ((base: any) => any)[]> = T extends [
89
+ infer Head,
90
+ ...infer Tail,
91
+ ]
92
+ ? Head extends (base: any) => infer R
61
93
  ? Tail extends ((base: any) => any)[]
62
- ? R | InstanceTypeOfMixins<Tail>
63
- : R
64
- : never
94
+ ? R | InstanceTypeOfMixins<Tail>
95
+ : R
65
96
  : never
97
+ : never
66
98
 
67
- export type IntersectionOfInstances<U> =
68
- (U extends any ? (x: U) => any : never) extends (x: infer I) => any ? I : never
99
+ export type IntersectionOfInstances<U> = (
100
+ U extends any ? (x: U) => any : never
101
+ ) extends (x: infer I) => any
102
+ ? I
103
+ : never
69
104
 
70
105
  export interface DeepMixinFunction {
71
- <MC extends MixinConstructor, P extends ((base: any) => any)[]> (Base: MC, ...mixins: P): MixinReturn<MC, P>
106
+ <MC extends MixinConstructor, P extends ((base: any) => any)[]>(
107
+ Base: MC,
108
+ ...mixins: P
109
+ ): MixinReturn<MC, P>
72
110
  }