@h3ravel/arquebus 0.6.5 → 0.6.7
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 +5 -4
- package/package.json +4 -3
- package/bin/index.cjs +0 -5964
- package/bin/index.d.cts +0 -1
- package/bin/index.d.ts +0 -1
- package/bin/index.js +0 -5960
- package/bin/seeders-8GJzfIIN.js +0 -3
- package/bin/seeders-ByeSoCAQ.cjs +0 -131
- package/bin/seeders-CltigymO.js +0 -79
- package/bin/seeders-_xJ6VGVS.cjs +0 -3
- package/dist/browser/index.cjs +0 -1271
- package/dist/browser/index.d.cts +0 -4932
- package/dist/browser/index.d.ts +0 -4932
- package/dist/browser/index.js +0 -1218
- package/dist/index.cjs +0 -5750
- package/dist/index.d.cts +0 -5129
- package/dist/index.d.ts +0 -5129
- package/dist/index.js +0 -5679
- package/dist/inspector/index.cjs +0 -4961
- package/dist/inspector/index.d.cts +0 -83
- package/dist/inspector/index.d.ts +0 -83
- package/dist/inspector/index.js +0 -4932
- package/dist/migrations/chunk-PECeCxCb.js +0 -15
- package/dist/migrations/index.cjs +0 -5507
- package/dist/migrations/index.d.cts +0 -4965
- package/dist/migrations/index.d.ts +0 -4962
- package/dist/migrations/index.js +0 -5454
- package/dist/migrations/stubs/migration-js.stub +0 -21
- package/dist/migrations/stubs/migration-ts.stub +0 -18
- package/dist/migrations/stubs/migration.create-js.stub +0 -24
- package/dist/migrations/stubs/migration.create-ts.stub +0 -21
- package/dist/migrations/stubs/migration.update-js.stub +0 -25
- package/dist/migrations/stubs/migration.update-ts.stub +0 -22
- package/dist/seeders/index.cjs +0 -141
- package/dist/seeders/index.d.cts +0 -4766
- package/dist/seeders/index.d.ts +0 -4766
- package/dist/seeders/index.js +0 -118
- 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/dist/stubs/arquebus.config-js.stub +0 -25
- package/dist/stubs/arquebus.config-ts.stub +0 -24
- package/dist/stubs/model-js.stub +0 -5
- package/dist/stubs/model-ts.stub +0 -5
- package/dist/stubs/seeder-js.stub +0 -13
- package/dist/stubs/seeder-ts.stub +0 -9
package/dist/seeders/index.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import path$1, { dirname } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
|
|
6
|
-
//#region src/seeders/seeder.ts
|
|
7
|
-
var Seeder = class {};
|
|
8
|
-
var seeder_default = Seeder;
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region src/seeders/runner.ts
|
|
12
|
-
async function glob(folderPath) {
|
|
13
|
-
const { default: escalade } = await import("escalade");
|
|
14
|
-
const entries = [];
|
|
15
|
-
await escalade(folderPath, async (dir, names) => {
|
|
16
|
-
await Promise.all(names.map(async (name) => {
|
|
17
|
-
const p = path.join(dir, name);
|
|
18
|
-
try {
|
|
19
|
-
await access(p);
|
|
20
|
-
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
21
|
-
} catch {}
|
|
22
|
-
}));
|
|
23
|
-
return "";
|
|
24
|
-
});
|
|
25
|
-
return entries;
|
|
26
|
-
}
|
|
27
|
-
var SeederRunner = class {
|
|
28
|
-
resolver;
|
|
29
|
-
connection;
|
|
30
|
-
paths = [];
|
|
31
|
-
constructor(resolver) {
|
|
32
|
-
this.resolver = resolver;
|
|
33
|
-
}
|
|
34
|
-
path(p) {
|
|
35
|
-
this.paths = Array.from(new Set([...this.paths, p]));
|
|
36
|
-
}
|
|
37
|
-
getPaths() {
|
|
38
|
-
return this.paths;
|
|
39
|
-
}
|
|
40
|
-
resolveConnection(connection) {
|
|
41
|
-
var _getInstance, _ref, _instance$connections;
|
|
42
|
-
const name = connection || this.connection || "default";
|
|
43
|
-
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
44
|
-
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
45
|
-
/** noop */
|
|
46
|
-
});
|
|
47
|
-
return this.resolver.fire(name);
|
|
48
|
-
}
|
|
49
|
-
setConnection(connection) {
|
|
50
|
-
this.connection = connection;
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
async getSeederFiles(paths) {
|
|
54
|
-
const files = [];
|
|
55
|
-
for (const p of paths) {
|
|
56
|
-
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
57
|
-
files.push(p);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
files.push(...await glob(p));
|
|
61
|
-
}
|
|
62
|
-
return files;
|
|
63
|
-
}
|
|
64
|
-
async resolvePath(filePath) {
|
|
65
|
-
try {
|
|
66
|
-
const mod = await import(filePath);
|
|
67
|
-
return new (mod.default ?? mod.Seeder)();
|
|
68
|
-
} catch {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async run(paths, connection) {
|
|
73
|
-
const files = await this.getSeederFiles(paths);
|
|
74
|
-
const conn = this.resolveConnection(connection);
|
|
75
|
-
for (const file of files) {
|
|
76
|
-
const seeder = await this.resolvePath(file);
|
|
77
|
-
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
var runner_default = SeederRunner;
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region node_modules/.pnpm/tsdown@0.15.6_typescript@5.9.3/node_modules/tsdown/esm-shims.js
|
|
85
|
-
const getFilename = () => fileURLToPath(import.meta.url);
|
|
86
|
-
const getDirname = () => path$1.dirname(getFilename());
|
|
87
|
-
const __dirname = /* @__PURE__ */ getDirname();
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/seeders/seeder-creator.ts
|
|
91
|
-
var SeederCreator = class {
|
|
92
|
-
constructor(customStubPath) {
|
|
93
|
-
this.customStubPath = customStubPath;
|
|
94
|
-
}
|
|
95
|
-
async create(dir, name, type = "js") {
|
|
96
|
-
await mkdir(dir, { recursive: true });
|
|
97
|
-
const stubPath = this.getStubPath(type);
|
|
98
|
-
let stub = await readFile(stubPath, "utf-8");
|
|
99
|
-
stub = stub.replace(/{{ name }}/g, name);
|
|
100
|
-
const filePath = path.join(dir, `${name}.${type}`);
|
|
101
|
-
await writeFile(filePath, stub);
|
|
102
|
-
return filePath;
|
|
103
|
-
}
|
|
104
|
-
getStubPath(type) {
|
|
105
|
-
if (this.customStubPath) return path.join(this.customStubPath, `seeder-${type}.stub`);
|
|
106
|
-
const __dirname$1 = this.getDirname(import.meta);
|
|
107
|
-
return path.join(__dirname$1, "stubs", `seeder-${type}.stub`);
|
|
108
|
-
}
|
|
109
|
-
getDirname(meta) {
|
|
110
|
-
if (typeof __dirname !== "undefined") return __dirname;
|
|
111
|
-
if (meta && meta.url) return dirname(fileURLToPath(meta.url));
|
|
112
|
-
throw new Error("Unable to determine dirname");
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
var seeder_creator_default = SeederCreator;
|
|
116
|
-
|
|
117
|
-
//#endregion
|
|
118
|
-
export { seeder_default as Seeder, seeder_creator_default as SeederCreator, runner_default as SeederRunner };
|
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
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from '@h3ravel/arquebus'
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
client: 'mysql2',
|
|
5
|
-
connection: {
|
|
6
|
-
host: 'localhost',
|
|
7
|
-
database: 'database',
|
|
8
|
-
user: 'user',
|
|
9
|
-
password: 'password'
|
|
10
|
-
},
|
|
11
|
-
migrations: {
|
|
12
|
-
table: 'migrations',
|
|
13
|
-
path: './migrations',
|
|
14
|
-
},
|
|
15
|
-
factories: {
|
|
16
|
-
path: './factories',
|
|
17
|
-
},
|
|
18
|
-
seeders: {
|
|
19
|
-
path: './seeders',
|
|
20
|
-
},
|
|
21
|
-
models: {
|
|
22
|
-
path: './models'
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from '@h3ravel/arquebus'
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
client: 'mysql2',
|
|
5
|
-
connection: {
|
|
6
|
-
host: 'localhost',
|
|
7
|
-
database: 'database',
|
|
8
|
-
user: 'user',
|
|
9
|
-
password: 'password'
|
|
10
|
-
},
|
|
11
|
-
migrations: {
|
|
12
|
-
table: 'migrations',
|
|
13
|
-
path: './migrations',
|
|
14
|
-
},
|
|
15
|
-
factories: {
|
|
16
|
-
path: './factories',
|
|
17
|
-
},
|
|
18
|
-
seeders: {
|
|
19
|
-
path: './seeders',
|
|
20
|
-
},
|
|
21
|
-
models: {
|
|
22
|
-
path: './models'
|
|
23
|
-
}
|
|
24
|
-
})
|
package/dist/stubs/model-js.stub
DELETED
package/dist/stubs/model-ts.stub
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Seeder } from '@h3ravel/arquebus'
|
|
2
|
-
|
|
3
|
-
export default class {{ name }} extends Seeder {
|
|
4
|
-
/**
|
|
5
|
-
* Run the seeder.
|
|
6
|
-
*
|
|
7
|
-
* @param {(import('@h3ravel/arquebus').QueryBuilder)} connection
|
|
8
|
-
*/
|
|
9
|
-
async run(connection) {
|
|
10
|
-
// Example: insert sample data
|
|
11
|
-
await connection.table('users').insert({ name: 'John Doe' })
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { QueryBuilder } from '@h3ravel/arquebus'
|
|
2
|
-
import { Seeder } from '@h3ravel/arquebus'
|
|
3
|
-
|
|
4
|
-
export default class {{ name }} extends Seeder {
|
|
5
|
-
async run(connection: QueryBuilder) {
|
|
6
|
-
// Example: insert sample data
|
|
7
|
-
await connection.table('users').insert({ name: 'John Doe' })
|
|
8
|
-
}
|
|
9
|
-
}
|