@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.
- package/README.md +20 -1
- package/bin/index.cjs +196 -144
- package/bin/index.js +177 -94
- package/bin/seeders-8GJzfIIN.js +3 -0
- package/bin/seeders-ByeSoCAQ.cjs +131 -0
- package/bin/seeders-CltigymO.js +79 -0
- package/bin/seeders-_xJ6VGVS.cjs +3 -0
- package/dist/browser/index.cjs +9 -9
- package/dist/browser/index.d.cts +7 -7
- package/dist/browser/index.d.ts +7 -7
- package/dist/browser/index.js +9 -9
- package/dist/index.cjs +252 -121
- package/dist/index.d.cts +40 -8
- package/dist/index.d.ts +40 -8
- package/dist/index.js +245 -119
- package/dist/inspector/index.cjs +105 -33
- package/dist/inspector/index.js +102 -33
- package/dist/migrations/index.cjs +144 -126
- package/dist/migrations/index.d.cts +10 -10
- package/dist/migrations/index.d.ts +10 -10
- package/dist/migrations/index.js +148 -130
- package/dist/migrations/stubs/migration-js.stub +1 -1
- package/dist/migrations/stubs/migration-ts.stub +1 -1
- package/dist/migrations/stubs/migration.create-js.stub +5 -5
- package/dist/migrations/stubs/migration.create-ts.stub +5 -5
- package/dist/migrations/stubs/migration.update-js.stub +2 -2
- package/dist/migrations/stubs/migration.update-ts.stub +3 -3
- package/dist/seeders/index.cjs +141 -0
- package/dist/seeders/index.d.cts +4766 -0
- package/dist/seeders/index.d.ts +4766 -0
- package/dist/seeders/index.js +118 -0
- package/dist/seeders/index.ts +3 -0
- package/dist/seeders/runner.ts +102 -0
- package/dist/seeders/seeder-creator.ts +42 -0
- package/dist/seeders/seeder.ts +10 -0
- package/dist/stubs/seeder-js.stub +13 -0
- package/dist/stubs/seeder-ts.stub +9 -0
- package/package.json +14 -3
- package/types/builder.ts +153 -80
- package/types/container.ts +79 -66
- package/types/generics.ts +75 -37
- package/types/modeling.ts +213 -158
- package/types/query-builder.ts +221 -191
- package/types/query-methods.ts +145 -109
- package/types/utils.ts +64 -56
package/types/container.ts
CHANGED
|
@@ -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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
5
|
+
[key: string]: T
|
|
6
6
|
} & V
|
|
7
7
|
|
|
8
8
|
export interface Plugin {
|
|
9
|
-
|
|
9
|
+
(model: Model, config: TGeneric): void
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export type Hook =
|
|
13
|
-
|
|
14
|
-
|
|
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> = (
|
|
26
|
+
export type TFunction<TArgs extends any[] = any[], TReturn = any> = (
|
|
27
|
+
...args: TArgs
|
|
28
|
+
) => TReturn
|
|
17
29
|
|
|
18
30
|
export type PrimitiveValue =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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> =
|
|
46
|
-
|
|
47
|
-
|
|
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 (
|
|
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<
|
|
54
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
: never
|
|
94
|
+
? R | InstanceTypeOfMixins<Tail>
|
|
95
|
+
: R
|
|
65
96
|
: never
|
|
97
|
+
: never
|
|
66
98
|
|
|
67
|
-
export type IntersectionOfInstances<U> =
|
|
68
|
-
|
|
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
|
-
|
|
106
|
+
<MC extends MixinConstructor, P extends ((base: any) => any)[]>(
|
|
107
|
+
Base: MC,
|
|
108
|
+
...mixins: P
|
|
109
|
+
): MixinReturn<MC, P>
|
|
72
110
|
}
|