@h3ravel/arquebus 0.6.7 → 0.6.9

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 (44) hide show
  1. package/bin/index.cjs +5772 -0
  2. package/bin/index.d.cts +1 -0
  3. package/bin/index.d.mts +1 -0
  4. package/bin/index.mjs +5746 -0
  5. package/bin/seeders-C0schOjT.mjs +3 -0
  6. package/bin/seeders-D-v59HCz.cjs +3 -0
  7. package/dist/browser/index.cjs +1263 -0
  8. package/dist/browser/index.d.cts +4932 -0
  9. package/dist/browser/index.d.mts +4932 -0
  10. package/dist/browser/index.mjs +1211 -0
  11. package/dist/index.cjs +5675 -0
  12. package/dist/index.d.cts +5129 -0
  13. package/dist/index.d.mts +5129 -0
  14. package/dist/index.mjs +5611 -0
  15. package/dist/inspector/index.cjs +4877 -0
  16. package/dist/inspector/index.d.cts +83 -0
  17. package/dist/inspector/index.d.mts +83 -0
  18. package/dist/inspector/index.mjs +4853 -0
  19. package/dist/migrations/chunk-BD38OWEx.mjs +15 -0
  20. package/dist/migrations/index.cjs +5433 -0
  21. package/dist/migrations/index.d.cts +4965 -0
  22. package/dist/migrations/index.d.mts +4962 -0
  23. package/dist/migrations/index.mjs +5387 -0
  24. package/dist/migrations/stubs/migration-js.stub +21 -0
  25. package/dist/migrations/stubs/migration-ts.stub +18 -0
  26. package/dist/migrations/stubs/migration.create-js.stub +24 -0
  27. package/dist/migrations/stubs/migration.create-ts.stub +21 -0
  28. package/dist/migrations/stubs/migration.update-js.stub +25 -0
  29. package/dist/migrations/stubs/migration.update-ts.stub +22 -0
  30. package/dist/seeders/index.cjs +137 -0
  31. package/dist/seeders/index.d.cts +4766 -0
  32. package/dist/seeders/index.d.mts +4766 -0
  33. package/dist/seeders/index.mjs +117 -0
  34. package/dist/seeders/index.ts +3 -0
  35. package/dist/seeders/runner.ts +101 -0
  36. package/dist/seeders/seeder-creator.ts +42 -0
  37. package/dist/seeders/seeder.ts +10 -0
  38. package/dist/stubs/arquebus.config-js.stub +25 -0
  39. package/dist/stubs/arquebus.config-ts.stub +24 -0
  40. package/dist/stubs/model-js.stub +5 -0
  41. package/dist/stubs/model-ts.stub +5 -0
  42. package/dist/stubs/seeder-js.stub +13 -0
  43. package/dist/stubs/seeder-ts.stub +14 -0
  44. package/package.json +2 -2
@@ -0,0 +1,117 @@
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.16.0_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
+ let stub = await readFile(this.getStubPath(type), "utf-8");
98
+ stub = stub.replace(/{{ name }}/g, name);
99
+ const filePath = path.join(dir, `${name}.${type}`);
100
+ await writeFile(filePath, stub);
101
+ return filePath;
102
+ }
103
+ getStubPath(type) {
104
+ if (this.customStubPath) return path.join(this.customStubPath, `seeder-${type}.stub`);
105
+ const __dirname$1 = this.getDirname(import.meta);
106
+ return path.join(__dirname$1, "stubs", `seeder-${type}.stub`);
107
+ }
108
+ getDirname(meta) {
109
+ if (typeof __dirname !== "undefined") return __dirname;
110
+ if (meta && meta.url) return dirname(fileURLToPath(meta.url));
111
+ throw new Error("Unable to determine dirname");
112
+ }
113
+ };
114
+ var seeder_creator_default = SeederCreator;
115
+
116
+ //#endregion
117
+ export { seeder_default as Seeder, seeder_creator_default as SeederCreator, runner_default as SeederRunner };
@@ -0,0 +1,3 @@
1
+ export { default as Seeder } from './seeder'
2
+ export { default as SeederRunner } from './runner'
3
+ export { default as SeederCreator } from './seeder-creator'
@@ -0,0 +1,101 @@
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
@@ -0,0 +1,42 @@
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
@@ -0,0 +1,10 @@
1
+ import type QueryBuilder from 'src/query-builder'
2
+
3
+ export abstract class Seeder {
4
+ /**
5
+ * Run the database seeds
6
+ */
7
+ abstract run(connection: QueryBuilder): Promise<void>
8
+ }
9
+
10
+ export default Seeder
@@ -0,0 +1,25 @@
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
+
@@ -0,0 +1,24 @@
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
+ })
@@ -0,0 +1,5 @@
1
+ import { Model } from '@h3ravel/arquebus'
2
+
3
+ export default class {{ name }} extends Model {
4
+ //
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Model } from '@h3ravel/arquebus'
2
+
3
+ export default class {{ name }} extends Model {
4
+ //
5
+ }
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,14 @@
1
+ import type { QueryBuilder } from '@h3ravel/arquebus'
2
+ import { Seeder } from '@h3ravel/arquebus'
3
+
4
+ export default class {{ name }} extends Seeder {
5
+ /**
6
+ * Run the database seeds.
7
+ *
8
+ * @param conn The current database connection
9
+ */
10
+ async run(connection: QueryBuilder) {
11
+ // Example: insert sample data
12
+ await connection.table('users').insert({ name: 'John Doe' })
13
+ }
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/arquebus",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "description": "Arquebus ORM is a Beautiful, expressive ORM inspired by Laravel's Eloquent, designed for TypeScript applications and for the H3ravel Framework.",
5
5
  "homepage": "https://h3ravel.toneflix.net/arquebus",
6
6
  "bin": {
@@ -168,7 +168,7 @@
168
168
  "sqlite3": "5.1.7",
169
169
  "terser": "^5.44.0",
170
170
  "ts-node": "^10.9.2",
171
- "tsdown": "^0.15.4",
171
+ "tsdown": "^0.16.0",
172
172
  "tsx": "^4.20.5",
173
173
  "typescript": "^5.9.2",
174
174
  "typescript-eslint": "^8.44.0",