@arkstack/database 0.16.5 → 0.16.6
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/dist/commands/DbCommand.js +15 -0
- package/dist/commands/MakeFactoryCommand.js +1 -1
- package/dist/commands/MakeMigrationCommand.js +1 -1
- package/dist/commands/MakeModelCommand.js +1 -1
- package/dist/commands/MakeSeederCommand.js +1 -1
- package/dist/commands/MigrateCommand.js +4 -0
- package/dist/commands/MigrateFreshCommand.js +4 -0
- package/dist/commands/MigrateRollbackCommand.js +4 -0
- package/dist/commands/MigrationHistoryCommand.js +4 -0
- package/dist/commands/SeedCommand.js +4 -0
- package/dist/commands/chunks/arkorm-DbtS6UA3.js +137 -0
- package/package.json +5 -4
- package/dist/commands/chunks/{Rebuilder-BeqOrRy3.js → Rebuilder-CL-V8vgc.js} +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as bootArkorm } from "./chunks/arkorm-DbtS6UA3.js";
|
|
2
|
+
import { CliApp, DbCommand as DbCommand$1 } from "arkormx";
|
|
3
|
+
//#region src/commands/DbCommand.ts
|
|
4
|
+
var DbCommand = class extends DbCommand$1 {
|
|
5
|
+
async handle() {
|
|
6
|
+
try {
|
|
7
|
+
bootArkorm();
|
|
8
|
+
} catch {}
|
|
9
|
+
this.app.command = this;
|
|
10
|
+
this.app = new CliApp();
|
|
11
|
+
return super.handle();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { DbCommand };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Rebuilder } from "./chunks/Rebuilder-
|
|
1
|
+
import { t as Rebuilder } from "./chunks/Rebuilder-CL-V8vgc.js";
|
|
2
2
|
import { CliApp, MakeFactoryCommand as MakeFactoryCommand$1 } from "arkormx";
|
|
3
3
|
//#region src/commands/MakeFactoryCommand.ts
|
|
4
4
|
var MakeFactoryCommand = class extends MakeFactoryCommand$1 {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Rebuilder } from "./chunks/Rebuilder-
|
|
1
|
+
import { t as Rebuilder } from "./chunks/Rebuilder-CL-V8vgc.js";
|
|
2
2
|
import { CliApp, MakeMigrationCommand as MakeMigrationCommand$1 } from "arkormx";
|
|
3
3
|
//#region src/commands/MakeMigrationCommand.ts
|
|
4
4
|
var MakeMigrationCommand = class extends MakeMigrationCommand$1 {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Rebuilder } from "./chunks/Rebuilder-
|
|
1
|
+
import { t as Rebuilder } from "./chunks/Rebuilder-CL-V8vgc.js";
|
|
2
2
|
import { CliApp, MakeModelCommand as MakeModelCommand$1 } from "arkormx";
|
|
3
3
|
//#region src/commands/MakeModelCommand.ts
|
|
4
4
|
var MakeModelCommand = class extends MakeModelCommand$1 {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Rebuilder } from "./chunks/Rebuilder-
|
|
1
|
+
import { t as Rebuilder } from "./chunks/Rebuilder-CL-V8vgc.js";
|
|
2
2
|
import { CliApp, MakeSeederCommand as MakeSeederCommand$1 } from "arkormx";
|
|
3
3
|
//#region src/commands/MakeSeederCommand.ts
|
|
4
4
|
var MakeSeederCommand = class extends MakeSeederCommand$1 {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { t as bootArkorm } from "./chunks/arkorm-DbtS6UA3.js";
|
|
1
2
|
import { CliApp, MigrateCommand as MigrateCommand$1 } from "arkormx";
|
|
2
3
|
//#region src/commands/MigrateCommand.ts
|
|
3
4
|
var MigrateCommand = class extends MigrateCommand$1 {
|
|
4
5
|
async handle() {
|
|
6
|
+
try {
|
|
7
|
+
bootArkorm();
|
|
8
|
+
} catch {}
|
|
5
9
|
this.app.command = this;
|
|
6
10
|
this.app = new CliApp();
|
|
7
11
|
return super.handle();
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { t as bootArkorm } from "./chunks/arkorm-DbtS6UA3.js";
|
|
1
2
|
import { CliApp, MigrateFreshCommand as MigrateFreshCommand$1 } from "arkormx";
|
|
2
3
|
//#region src/commands/MigrateFreshCommand.ts
|
|
3
4
|
var MigrateFreshCommand = class extends MigrateFreshCommand$1 {
|
|
4
5
|
async handle() {
|
|
6
|
+
try {
|
|
7
|
+
bootArkorm();
|
|
8
|
+
} catch {}
|
|
5
9
|
this.app.command = this;
|
|
6
10
|
this.app = new CliApp();
|
|
7
11
|
return super.handle();
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { t as bootArkorm } from "./chunks/arkorm-DbtS6UA3.js";
|
|
1
2
|
import { CliApp, MigrateRollbackCommand as MigrateRollbackCommand$1 } from "arkormx";
|
|
2
3
|
//#region src/commands/MigrateRollbackCommand.ts
|
|
3
4
|
var MigrateRollbackCommand = class extends MigrateRollbackCommand$1 {
|
|
4
5
|
async handle() {
|
|
6
|
+
try {
|
|
7
|
+
bootArkorm();
|
|
8
|
+
} catch {}
|
|
5
9
|
this.app.command = this;
|
|
6
10
|
this.app = new CliApp();
|
|
7
11
|
return super.handle();
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { t as bootArkorm } from "./chunks/arkorm-DbtS6UA3.js";
|
|
1
2
|
import { CliApp, MigrationHistoryCommand as MigrationHistoryCommand$1 } from "arkormx";
|
|
2
3
|
//#region src/commands/MigrationHistoryCommand.ts
|
|
3
4
|
var MigrationHistoryCommand = class extends MigrationHistoryCommand$1 {
|
|
4
5
|
async handle() {
|
|
6
|
+
try {
|
|
7
|
+
bootArkorm();
|
|
8
|
+
} catch {}
|
|
5
9
|
this.app.command = this;
|
|
6
10
|
this.app = new CliApp();
|
|
7
11
|
return super.handle();
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { t as bootArkorm } from "./chunks/arkorm-DbtS6UA3.js";
|
|
1
2
|
import { CliApp, SeedCommand as SeedCommand$1 } from "arkormx";
|
|
2
3
|
//#region src/commands/SeedCommand.ts
|
|
3
4
|
var SeedCommand = class extends SeedCommand$1 {
|
|
4
5
|
async handle() {
|
|
6
|
+
try {
|
|
7
|
+
bootArkorm();
|
|
8
|
+
} catch {}
|
|
5
9
|
this.app.command = this;
|
|
6
10
|
this.app = new CliApp();
|
|
7
11
|
return super.handle();
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Arkorm, DB, Model, createKyselyAdapter } from "arkormx";
|
|
2
|
+
import { Arkstack } from "@arkstack/contract";
|
|
3
|
+
import { Pool } from "pg";
|
|
4
|
+
import { Kysely, PostgresDialect } from "kysely";
|
|
5
|
+
import { createArkormCurrentPageResolver } from "resora";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { config, outputDir } from "@arkstack/common";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
//#region src/kysely.ts
|
|
10
|
+
/**
|
|
11
|
+
* Build a pg {@link Pool} from a {@link ConnectionConfig}. A `url` (or
|
|
12
|
+
* `DATABASE_URL`) wins over the discrete `host`/`port`/`user`/... fields.
|
|
13
|
+
*
|
|
14
|
+
* @param connection
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
const createPool = (connection) => {
|
|
18
|
+
const poolConfig = connection.url ? { connectionString: connection.url } : {
|
|
19
|
+
host: connection.host,
|
|
20
|
+
port: connection.port,
|
|
21
|
+
user: connection.user,
|
|
22
|
+
database: connection.database,
|
|
23
|
+
password: connection.password
|
|
24
|
+
};
|
|
25
|
+
if (connection.ssl !== void 0) poolConfig.ssl = connection.ssl;
|
|
26
|
+
if (connection.pool?.max !== void 0) poolConfig.max = connection.pool.max;
|
|
27
|
+
if (connection.pool?.idleTimeoutMillis !== void 0) poolConfig.idleTimeoutMillis = connection.pool.idleTimeoutMillis;
|
|
28
|
+
if (connection.pool?.connectionTimeoutMillis !== void 0) poolConfig.connectionTimeoutMillis = connection.pool.connectionTimeoutMillis;
|
|
29
|
+
return new Pool(poolConfig);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Build a Kysely instance for the given connection using the Postgres dialect.
|
|
33
|
+
*
|
|
34
|
+
* @param connection
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
const createKysely = (connection) => {
|
|
38
|
+
return new Kysely({ dialect: new PostgresDialect({ pool: createPool(connection) }) });
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Build an ArkORM Kysely adapter for the given connection. This is what binds
|
|
42
|
+
* models to the database.
|
|
43
|
+
*
|
|
44
|
+
* @param connection
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
const createAdapter = (connection) => {
|
|
48
|
+
return createKyselyAdapter(createKysely(connection));
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/config.ts
|
|
52
|
+
/**
|
|
53
|
+
* Read a value from the `database` configuration namespace with a fallback.
|
|
54
|
+
*
|
|
55
|
+
* Never throws when the config file is missing; returns the default instead.
|
|
56
|
+
*
|
|
57
|
+
* @param key Dot path within the database config.
|
|
58
|
+
* @param defaultValue Value returned when the key is not set.
|
|
59
|
+
*/
|
|
60
|
+
const configure = (key, defaultValue) => {
|
|
61
|
+
try {
|
|
62
|
+
return config(`database.${key}`, defaultValue);
|
|
63
|
+
} catch {
|
|
64
|
+
return defaultValue;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Resolve a configured {@link ConnectionConfig} by name, or the default
|
|
69
|
+
* connection when none is given.
|
|
70
|
+
*
|
|
71
|
+
* @param name The connection name. Defaults to `database.default`.
|
|
72
|
+
* @throws when the named connection is not configured.
|
|
73
|
+
*/
|
|
74
|
+
const resolveConnection = (name) => {
|
|
75
|
+
const connection = name ?? configure("default", "pgsql");
|
|
76
|
+
const resolved = configure("connections", {})[connection];
|
|
77
|
+
if (!resolved) throw new Error(`Database connection "${connection}" is not configured.`);
|
|
78
|
+
return resolved;
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/arkorm.ts
|
|
82
|
+
/**
|
|
83
|
+
* Default ArkORM paths matching the scaffolded application structure. Apps with
|
|
84
|
+
* a different layout can override them by adding an `arkormx.config.ts`.
|
|
85
|
+
*/
|
|
86
|
+
const defaultPaths = () => {
|
|
87
|
+
return {
|
|
88
|
+
models: "./src/app/models",
|
|
89
|
+
factories: "./src/database/factories",
|
|
90
|
+
seeders: "./src/database/seeders",
|
|
91
|
+
migrations: "./src/database/migrations",
|
|
92
|
+
buildOutput: path.relative(Arkstack.rootDir(), outputDir())
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Whether the application provides its own `arkormx.config.{ts,js}`. When it
|
|
97
|
+
* does, ArkORM loads it and it takes precedence over the framework defaults.
|
|
98
|
+
*/
|
|
99
|
+
const hasUserArkormConfig = () => {
|
|
100
|
+
const root = Arkstack.rootDir();
|
|
101
|
+
return existsSync(path.join(root, "arkormx.config.ts")) || existsSync(path.join(root, "arkormx.config.js"));
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Configure ArkORM natively from `src/config/database.ts`, so applications work
|
|
105
|
+
* without an `arkormx.config.ts`.
|
|
106
|
+
*
|
|
107
|
+
* Builds the adapter from the default (or named) connection, registers the
|
|
108
|
+
* conventional paths and the resora pagination resolver, and binds models. A
|
|
109
|
+
* user-provided `arkormx.config.{ts,js}` always wins — in that case this is a
|
|
110
|
+
* no-op and ArkORM loads the file instead.
|
|
111
|
+
*
|
|
112
|
+
* @param options Optional overrides merged over the derived config.
|
|
113
|
+
* @returns Whether the framework applied its configuration.
|
|
114
|
+
*/
|
|
115
|
+
const bootArkorm = (options = {}) => {
|
|
116
|
+
if (hasUserArkormConfig()) return false;
|
|
117
|
+
const { connection, adapter, paths, pagination, ...rest } = options;
|
|
118
|
+
const resolvedAdapter = adapter ?? createAdapter(resolveConnection(connection));
|
|
119
|
+
Arkorm.configure({
|
|
120
|
+
adapter: resolvedAdapter,
|
|
121
|
+
paths: {
|
|
122
|
+
...defaultPaths(),
|
|
123
|
+
...paths ?? {}
|
|
124
|
+
},
|
|
125
|
+
pagination: {
|
|
126
|
+
resolveCurrentPage: createArkormCurrentPageResolver(),
|
|
127
|
+
...pagination ?? {}
|
|
128
|
+
},
|
|
129
|
+
outputExt: "ts",
|
|
130
|
+
...rest
|
|
131
|
+
});
|
|
132
|
+
Model.setAdapter(resolvedAdapter);
|
|
133
|
+
DB.setAdapter(resolvedAdapter);
|
|
134
|
+
return true;
|
|
135
|
+
};
|
|
136
|
+
//#endregion
|
|
137
|
+
export { bootArkorm as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/database",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Database module for Arkstack, providing core database integration and data layer features.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"exports": {
|
|
33
33
|
".": "./dist/index.js",
|
|
34
|
+
"./DbCommand": "./dist/commands/DbCommand.js",
|
|
34
35
|
"./MakeFactoryCommand": "./dist/commands/MakeFactoryCommand.js",
|
|
35
36
|
"./MakeMigrationCommand": "./dist/commands/MakeMigrationCommand.js",
|
|
36
37
|
"./MakeModelCommand": "./dist/commands/MakeModelCommand.js",
|
|
@@ -51,12 +52,12 @@
|
|
|
51
52
|
"dependencies": {
|
|
52
53
|
"@arkormx/plugin-clear-router": "^0.1.49",
|
|
53
54
|
"dotenv": "^17.4.2",
|
|
54
|
-
"arkormx": "^2.
|
|
55
|
+
"arkormx": "^2.11.2",
|
|
55
56
|
"kysely": "^0.29.2",
|
|
56
57
|
"pg": "^8.22.0",
|
|
57
58
|
"resora": "^1.3.27",
|
|
58
|
-
"@arkstack/common": "^0.16.
|
|
59
|
-
"@arkstack/contract": "^0.16.
|
|
59
|
+
"@arkstack/common": "^0.16.6",
|
|
60
|
+
"@arkstack/contract": "^0.16.6"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@types/pg": "^8.16.0"
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
3
2
|
import { Arkstack } from "@arkstack/contract";
|
|
4
|
-
import { Logger } from "@arkstack/common";
|
|
5
3
|
import { globSync } from "node:fs";
|
|
4
|
+
import { Logger } from "@arkstack/common";
|
|
6
5
|
import { join } from "node:path";
|
|
6
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
7
7
|
//#region src/extensions/Rebuilder.ts
|
|
8
8
|
var Rebuilder = class Rebuilder {
|
|
9
9
|
app;
|