@jskit-ai/database-runtime-postgres 0.1.4

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.
@@ -0,0 +1,160 @@
1
+ export default Object.freeze({
2
+ packageVersion: 1,
3
+ packageId: "@jskit-ai/database-runtime-postgres",
4
+ version: "0.1.4",
5
+ options: {
6
+ "db-host": {
7
+ required: false,
8
+ values: [],
9
+ defaultValue: "localhost",
10
+ promptLabel: "Database host",
11
+ promptHint: "Postgres host (for example 127.0.0.1)"
12
+ },
13
+ "db-port": {
14
+ required: false,
15
+ values: [],
16
+ defaultValue: "5432",
17
+ promptLabel: "Database port",
18
+ promptHint: "Postgres port (usually 5432)"
19
+ },
20
+ "db-name": {
21
+ required: true,
22
+ values: [],
23
+ promptLabel: "Database name",
24
+ promptHint: "Database name to connect to"
25
+ },
26
+ "db-user": {
27
+ required: true,
28
+ values: [],
29
+ promptLabel: "Database user",
30
+ promptHint: "Database username"
31
+ },
32
+ "db-password": {
33
+ required: true,
34
+ values: [],
35
+ inputType: "password",
36
+ promptLabel: "Database password",
37
+ promptHint: "Database password"
38
+ }
39
+ },
40
+ dependsOn: [
41
+ "@jskit-ai/database-runtime"
42
+ ],
43
+ capabilities: {
44
+ provides: [
45
+ "runtime.database.driver",
46
+ "runtime.database.driver.postgres"
47
+ ],
48
+ requires: [
49
+ "runtime.database"
50
+ ]
51
+ },
52
+ runtime: {
53
+ server: {
54
+ providerEntrypoint: "src/server/providers/DatabaseRuntimePostgresServiceProvider.js",
55
+ providers: [
56
+ {
57
+ entrypoint: "src/server/providers/DatabaseRuntimePostgresServiceProvider.js",
58
+ export: "DatabaseRuntimePostgresServiceProvider"
59
+ }
60
+ ]
61
+ },
62
+ client: {
63
+ providers: []
64
+ }
65
+ },
66
+ metadata: {
67
+ apiSummary: {
68
+ surfaces: [
69
+ {
70
+ subpath: "./server",
71
+ summary: "Exports Postgres database runtime provider."
72
+ },
73
+ {
74
+ subpath: "./shared",
75
+ summary: "Exports Postgres dialect metadata helpers."
76
+ },
77
+ {
78
+ subpath: "./client",
79
+ summary: "Exports no runtime API today (reserved client entrypoint)."
80
+ }
81
+ ],
82
+ containerTokens: {
83
+ server: [
84
+ "runtime.database.driver.postgres"
85
+ ],
86
+ client: []
87
+ }
88
+ }
89
+ },
90
+ mutations: {
91
+ dependencies: {
92
+ runtime: {
93
+ "@jskit-ai/database-runtime": "0.1.4",
94
+ "pg": "^8.13.1"
95
+ },
96
+ dev: {}
97
+ },
98
+ packageJson: {
99
+ scripts: {}
100
+ },
101
+ procfile: {},
102
+ files: [],
103
+ text: [
104
+ {
105
+ file: ".env",
106
+ op: "upsert-env",
107
+ key: "DB_CLIENT",
108
+ value: "pg",
109
+ reason: "Configure database client driver for runtime wiring.",
110
+ category: "runtime-config",
111
+ id: "database-client-postgres"
112
+ },
113
+ {
114
+ file: ".env",
115
+ op: "upsert-env",
116
+ key: "DB_HOST",
117
+ value: "${option:db-host}",
118
+ reason: "Configure database host.",
119
+ category: "runtime-config",
120
+ id: "database-host"
121
+ },
122
+ {
123
+ file: ".env",
124
+ op: "upsert-env",
125
+ key: "DB_PORT",
126
+ value: "${option:db-port}",
127
+ reason: "Configure database port.",
128
+ category: "runtime-config",
129
+ id: "database-port"
130
+ },
131
+ {
132
+ file: ".env",
133
+ op: "upsert-env",
134
+ key: "DB_NAME",
135
+ value: "${option:db-name}",
136
+ reason: "Configure database name.",
137
+ category: "runtime-config",
138
+ id: "database-name"
139
+ },
140
+ {
141
+ file: ".env",
142
+ op: "upsert-env",
143
+ key: "DB_USER",
144
+ value: "${option:db-user}",
145
+ reason: "Configure database user.",
146
+ category: "runtime-config",
147
+ id: "database-user"
148
+ },
149
+ {
150
+ file: ".env",
151
+ op: "upsert-env",
152
+ key: "DB_PASSWORD",
153
+ value: "${option:db-password}",
154
+ reason: "Configure database password.",
155
+ category: "runtime-config",
156
+ id: "database-password"
157
+ }
158
+ ]
159
+ }
160
+ });
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@jskit-ai/database-runtime-postgres",
3
+ "version": "0.1.4",
4
+ "type": "module",
5
+ "scripts": {
6
+ "test": "node --test"
7
+ },
8
+ "exports": {
9
+ "./client": "./src/client/index.js",
10
+ "./server/providers/DatabaseRuntimePostgresServiceProvider": "./src/server/providers/DatabaseRuntimePostgresServiceProvider.js",
11
+ "./shared": "./src/shared/index.js",
12
+ "./shared/dialect": "./src/shared/dialect.js"
13
+ },
14
+ "dependencies": {
15
+ "@jskit-ai/database-runtime": "0.1.4"
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import * as postgresDialect from "../../shared/index.js";
2
+
3
+ const DATABASE_DRIVER_POSTGRES_TOKEN = "runtime.database.driver.postgres";
4
+
5
+ const POSTGRES_DATABASE_DRIVER_API = Object.freeze({
6
+ ...postgresDialect
7
+ });
8
+
9
+ class DatabaseRuntimePostgresServiceProvider {
10
+ static id = DATABASE_DRIVER_POSTGRES_TOKEN;
11
+
12
+ register(app) {
13
+ if (!app || typeof app.singleton !== "function") {
14
+ throw new Error("DatabaseRuntimePostgresServiceProvider requires application singleton().");
15
+ }
16
+
17
+ app.singleton(DATABASE_DRIVER_POSTGRES_TOKEN, () => POSTGRES_DATABASE_DRIVER_API);
18
+ }
19
+
20
+ boot() {}
21
+ }
22
+
23
+ export { DatabaseRuntimePostgresServiceProvider };
@@ -0,0 +1,7 @@
1
+ const DIALECT_ID = "pg";
2
+
3
+ function getDialectId() {
4
+ return DIALECT_ID;
5
+ }
6
+
7
+ export { DIALECT_ID, getDialectId };
@@ -0,0 +1 @@
1
+ export { DIALECT_ID, getDialectId } from "./dialect.js";
@@ -0,0 +1,32 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+ import test from "node:test";
4
+
5
+ import * as clientApi from "../src/client/index.js";
6
+ import * as sharedApi from "../src/shared/index.js";
7
+ import { DatabaseRuntimePostgresServiceProvider } from "../src/server/providers/DatabaseRuntimePostgresServiceProvider.js";
8
+
9
+ test("package exports include explicit shared and provider entrypoints", async () => {
10
+ const packageJson = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
11
+ const exportsMap = packageJson && typeof packageJson === "object" ? packageJson.exports : {};
12
+ assert.equal(exportsMap["./server"], undefined);
13
+ assert.equal(
14
+ exportsMap["./server/providers/DatabaseRuntimePostgresServiceProvider"],
15
+ "./src/server/providers/DatabaseRuntimePostgresServiceProvider.js"
16
+ );
17
+ assert.equal(exportsMap["./shared"], "./src/shared/index.js");
18
+ });
19
+
20
+ test("client entrypoint exports no postgres runtime api", () => {
21
+ assert.deepEqual(Object.keys(clientApi), []);
22
+ });
23
+
24
+ test("server provider module exports postgres service provider only", () => {
25
+ assert.equal(typeof DatabaseRuntimePostgresServiceProvider, "function");
26
+ });
27
+
28
+ test("shared entrypoint exports postgres dialect helpers", () => {
29
+ assert.equal(sharedApi.DIALECT_ID, "pg");
30
+ assert.equal(sharedApi.getDialectId(), "pg");
31
+ assert.equal(typeof sharedApi.DatabaseRuntimePostgresServiceProvider, "undefined");
32
+ });
@@ -0,0 +1,33 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { DatabaseRuntimePostgresServiceProvider } from "../src/server/providers/DatabaseRuntimePostgresServiceProvider.js";
4
+
5
+ function createSingletonApp() {
6
+ const singletons = new Map();
7
+
8
+ return {
9
+ has(token) {
10
+ return singletons.has(token);
11
+ },
12
+ singleton(token, factory) {
13
+ singletons.set(token, factory(this));
14
+ },
15
+ make(token) {
16
+ if (!singletons.has(token)) {
17
+ throw new Error(`Token ${String(token)} is not registered.`);
18
+ }
19
+ return singletons.get(token);
20
+ }
21
+ };
22
+ }
23
+
24
+ test("DatabaseRuntimePostgresServiceProvider registers postgres driver api", () => {
25
+ const app = createSingletonApp();
26
+ const provider = new DatabaseRuntimePostgresServiceProvider();
27
+ provider.register(app);
28
+
29
+ assert.equal(app.has("runtime.database.driver.postgres"), true);
30
+ const api = app.make("runtime.database.driver.postgres");
31
+ assert.equal(api.DIALECT_ID, "pg");
32
+ assert.equal(api.getDialectId(), "pg");
33
+ });