@h3ravel/arquebus 0.6.10 → 0.6.12
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/bin/index.cjs +1 -1
- package/bin/{index.mjs → index.js} +2 -2
- package/bin/seeders-DIkcRliK.js +3 -0
- package/dist/migrations/{index.mjs → index.js} +1 -1
- package/package.json +25 -25
- package/bin/index.d.mts +0 -1
- package/bin/seeders-C0schOjT.mjs +0 -3
- package/dist/browser/index.d.mts +0 -4932
- package/dist/index.d.mts +0 -5129
- package/dist/inspector/index.d.mts +0 -83
- package/dist/migrations/index.d.mts +0 -4962
- package/dist/seeders/index.d.mts +0 -4766
- package/dist/seeders/index.ts +0 -3
- package/dist/seeders/runner.ts +0 -101
- package/dist/seeders/seeder-creator.ts +0 -42
- package/dist/seeders/seeder.ts +0 -10
- /package/bin/{index.d.cts → index.d.ts} +0 -0
- /package/dist/browser/{index.d.cts → index.d.ts} +0 -0
- /package/dist/browser/{index.mjs → index.js} +0 -0
- /package/dist/{index.d.cts → index.d.ts} +0 -0
- /package/dist/{index.mjs → index.js} +0 -0
- /package/dist/inspector/{index.d.cts → index.d.ts} +0 -0
- /package/dist/inspector/{index.mjs → index.js} +0 -0
- /package/dist/migrations/{chunk-BD38OWEx.mjs → chunk-Bop6jNiL.js} +0 -0
- /package/dist/migrations/{index.d.cts → index.d.ts} +0 -0
- /package/dist/seeders/{index.d.cts → index.d.ts} +0 -0
- /package/dist/seeders/{index.mjs → index.js} +0 -0
package/dist/seeders/index.ts
DELETED
package/dist/seeders/runner.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type QueryBuilder from 'src/query-builder'
|
|
2
|
-
import type Seeder from './seeder'
|
|
3
|
-
import type { TBaseConfig } from 'types/container'
|
|
4
|
-
import { access } from 'node:fs/promises'
|
|
5
|
-
import type { arquebus } from 'src'
|
|
6
|
-
import path from 'path'
|
|
7
|
-
|
|
8
|
-
async function glob (folderPath: string): Promise<string[]> {
|
|
9
|
-
const { default: escalade } = await import('escalade')
|
|
10
|
-
const entries: string[] = []
|
|
11
|
-
const root = folderPath
|
|
12
|
-
await escalade(root, async (dir, names) => {
|
|
13
|
-
await Promise.all(
|
|
14
|
-
names.map(async (name) => {
|
|
15
|
-
const p = path.join(dir, name)
|
|
16
|
-
try {
|
|
17
|
-
await access(p)
|
|
18
|
-
if (p.endsWith('.js') || p.endsWith('.ts')) entries.push(p)
|
|
19
|
-
} catch {
|
|
20
|
-
/** */
|
|
21
|
-
}
|
|
22
|
-
}),
|
|
23
|
-
)
|
|
24
|
-
return ''
|
|
25
|
-
})
|
|
26
|
-
return entries
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class SeederRunner {
|
|
30
|
-
resolver: typeof arquebus
|
|
31
|
-
connection!: TBaseConfig['client']
|
|
32
|
-
paths: string[] = []
|
|
33
|
-
|
|
34
|
-
constructor(resolver: typeof arquebus) {
|
|
35
|
-
this.resolver = resolver
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
path (p: string): void {
|
|
39
|
-
this.paths = Array.from(new Set([...this.paths, p]))
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getPaths (): string[] {
|
|
43
|
-
return this.paths
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
resolveConnection (connection?: TBaseConfig['client']): QueryBuilder {
|
|
47
|
-
const name = connection || this.connection || 'default'
|
|
48
|
-
// If the resolver has no connection manager entry, attempt to autoload config
|
|
49
|
-
const instance: any = (this.resolver as any).getInstance?.() ?? null
|
|
50
|
-
const hasConn = !!instance?.connections?.[name]
|
|
51
|
-
if (!hasConn) {
|
|
52
|
-
// Attempt autoload; do not throw if empty
|
|
53
|
-
this.resolver
|
|
54
|
-
.autoLoad()
|
|
55
|
-
.catch(() => {
|
|
56
|
-
/** noop */
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
return this.resolver.fire(name)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
setConnection (connection: TBaseConfig['client']): this {
|
|
63
|
-
this.connection = connection
|
|
64
|
-
return this
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async getSeederFiles (paths: string[]): Promise<string[]> {
|
|
68
|
-
const files: string[] = []
|
|
69
|
-
for (const p of paths) {
|
|
70
|
-
if (p.endsWith('.js') || p.endsWith('.ts')) {
|
|
71
|
-
files.push(p)
|
|
72
|
-
continue
|
|
73
|
-
}
|
|
74
|
-
files.push(...(await glob(p)))
|
|
75
|
-
}
|
|
76
|
-
return files
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async resolvePath (filePath: string): Promise<Seeder | null> {
|
|
80
|
-
try {
|
|
81
|
-
const mod = await import(filePath)
|
|
82
|
-
const instance = new (mod.default ?? mod.Seeder)()
|
|
83
|
-
return instance as Seeder
|
|
84
|
-
} catch {
|
|
85
|
-
return null
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async run (paths: string[], connection?: TBaseConfig['client']): Promise<void> {
|
|
90
|
-
const files = await this.getSeederFiles(paths)
|
|
91
|
-
const conn = this.resolveConnection(connection)
|
|
92
|
-
for (const file of files) {
|
|
93
|
-
const seeder = await this.resolvePath(file)
|
|
94
|
-
if (seeder && typeof seeder.run === 'function') {
|
|
95
|
-
await seeder.run(conn)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export default SeederRunner
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
2
|
-
|
|
3
|
-
import { dirname } from 'node:path'
|
|
4
|
-
import { fileURLToPath } from 'node:url'
|
|
5
|
-
import path from 'path'
|
|
6
|
-
|
|
7
|
-
export class SeederCreator {
|
|
8
|
-
constructor(private customStubPath?: string) { }
|
|
9
|
-
|
|
10
|
-
async create (dir: string, name: string, type: 'js' | 'ts' = 'js') {
|
|
11
|
-
await mkdir(dir, { recursive: true })
|
|
12
|
-
|
|
13
|
-
const stubPath = this.getStubPath(type)
|
|
14
|
-
let stub = await readFile(stubPath, 'utf-8')
|
|
15
|
-
stub = stub.replace(/{{ name }}/g, name)
|
|
16
|
-
|
|
17
|
-
const filePath = path.join(dir, `${name}.${type}`)
|
|
18
|
-
await writeFile(filePath, stub)
|
|
19
|
-
|
|
20
|
-
return filePath
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getStubPath (type: 'js' | 'ts') {
|
|
24
|
-
if (this.customStubPath) return path.join(this.customStubPath, `seeder-${type}.stub`)
|
|
25
|
-
const __dirname = this.getDirname(import.meta as any)
|
|
26
|
-
return path.join(__dirname, 'stubs', `seeder-${type}.stub`)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getDirname (meta: ImportMeta | null) {
|
|
30
|
-
if (typeof __dirname !== 'undefined') {
|
|
31
|
-
// CJS build
|
|
32
|
-
return __dirname
|
|
33
|
-
}
|
|
34
|
-
if (meta && meta.url) {
|
|
35
|
-
// ESM build
|
|
36
|
-
return dirname(fileURLToPath(meta.url))
|
|
37
|
-
}
|
|
38
|
-
throw new Error('Unable to determine dirname')
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default SeederCreator
|
package/dist/seeders/seeder.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|