@schemavaults/dbh 0.7.5 → 0.8.1
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/CLAUDE.md +41 -0
- package/README.md +23 -1
- package/dist/build-db-migrations.d.ts +3 -0
- package/dist/cli.d.ts +3 -0
- package/package.json +29 -6
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## What This Is
|
|
6
|
+
|
|
7
|
+
`@schemavaults/dbh` is an npm package that provides a Kysely-based adapter for connecting to Postgres databases through a Neon-compatible WebSocket proxy. It works with both Neon-hosted serverless Postgres and local Postgres instances (via a bundled WS proxy).
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
Ensure dependencies are installed with `bun install` before attempting to run any other commands.
|
|
12
|
+
|
|
13
|
+
- **Build:** `bun run build` (runs tsc + tsc-alias, then cleans test files from dist/)
|
|
14
|
+
- **Lint:** `bun run lint` (eslint on src/)
|
|
15
|
+
- **Unit tests:** `bun run test` or `bun run test:unit`
|
|
16
|
+
- **Single test:** `bun test --test-name-pattern '<pattern>'`
|
|
17
|
+
- **E2E tests:** `cd tests && /bin/bash ./run_e2e_tests.sh` (requires Docker Compose — spins up postgres, ws-proxy, and test-runner containers)
|
|
18
|
+
- **CLI:** `bun run cli --help` locally or `bunx @schemavaults/dbh --help` remotely.
|
|
19
|
+
|
|
20
|
+
## Architecture
|
|
21
|
+
|
|
22
|
+
The core adapter is `SchemaVaultsPostgresNeonProxyAdapter<T>` (generic over Kysely table types). It wraps Kysely with a `NeonDialect` and handles credential parsing, WS proxy URL resolution, and debug logging. Consumers extend or instantiate it, passing an environment (`development|test|staging|production`), optional credentials (defaults to env vars), and an optional `wsProxyUrl` (string or generator function).
|
|
23
|
+
|
|
24
|
+
Key modules:
|
|
25
|
+
- `src/schemavaults-postgres-neon-proxy-adapter.ts` — the main adapter class
|
|
26
|
+
- `src/migrate.ts` — Kysely migration helpers (`migrate`, `reverse`), exported as a separate entrypoint (`@schemavaults/dbh/migrate`)
|
|
27
|
+
- `src/sql.ts` — re-exports Kysely's `sql` tag
|
|
28
|
+
- `src/utils/parseDatabaseCredentials.ts` — parses/validates DB credentials from an object or `process.env`
|
|
29
|
+
|
|
30
|
+
The package has two export entrypoints: `.` (adapter + sql + types), `./sql` (Kysely template tag re-export), `./migrate` (migration utilities), and `./cli` (@schemavaults/dbh command-line utility).
|
|
31
|
+
|
|
32
|
+
## Local Dev Environment
|
|
33
|
+
|
|
34
|
+
- Runtime/package manager: **Bun** (v1.3.6)
|
|
35
|
+
- TypeScript with path alias `@/*` → `src/*` (resolved by tsc-alias at build time)
|
|
36
|
+
- E2E tests run inside Docker containers (postgres:17.7 + a Go-based WS proxy on port 5433)
|
|
37
|
+
|
|
38
|
+
## Environment Variables
|
|
39
|
+
|
|
40
|
+
The adapter reads these from `process.env` when credentials aren't passed directly:
|
|
41
|
+
`POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_URL`, `POSTGRES_URL_NON_POOLING` (optional), `POSTGRES_HOST`, `POSTGRES_PORT`, `POSTGRES_DATABASE`. Debug mode via `SCHEMAVAULTS_DBH_DEBUG=true`.
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Ensure that you have both `postgres` and a `postgres-ws-proxy` containers runnin
|
|
|
20
20
|
|
|
21
21
|
You'll likely want to replace the `build:` sections for the services in the e2e test example `.yml` file with `image:`. For example, use `image: postgres:17.7` for the `postgres` service. For the proxy, you can pull the docker image from `ghcr.io/schemavaults/dbh/postgres-ws-proxy`; use the version number equal to your `@schemavaults/dbh` npm package installation:
|
|
22
22
|
```md
|
|
23
|
-
# NPM Package: @schemavaults/dbh@0.
|
|
23
|
+
# NPM Package: @schemavaults/dbh@0.8.1 => ghcr.io/schemavaults/dbh/postgres-ws-proxy:0.8.1
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
### In your application server code
|
|
@@ -31,6 +31,28 @@ For an example, see the e2e test file: [./src/tests/e2e/ConnectToLocalDatabase.t
|
|
|
31
31
|
|
|
32
32
|
You may need to define a custom `WsProxyUrlGenerator` function to determine how the `postgres-ws-proxy` can be reached.
|
|
33
33
|
|
|
34
|
+
### From your command-line
|
|
35
|
+
|
|
36
|
+
#### CLI Help Command
|
|
37
|
+
```bash
|
|
38
|
+
# run migrations (and more) from the cli
|
|
39
|
+
bunx @schemavaults/dbh --help
|
|
40
|
+
# or `bun run cli --help` if you have the dbh source repository as your working directory
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Build example database migrations with the CLI
|
|
44
|
+
```bash
|
|
45
|
+
mkdir ./tests/tmp
|
|
46
|
+
|
|
47
|
+
# compile TypeScript Kysely migrations to JavaScript
|
|
48
|
+
bunx @schemavaults/dbh build-db-migrations ./src/tests/example-migrations \
|
|
49
|
+
--outdir ./tests/tmp/example-compiled-migrations \
|
|
50
|
+
--sql-module ./src/sql.ts \
|
|
51
|
+
--sql-outdir ./tests/tmp/
|
|
52
|
+
|
|
53
|
+
rm -rf ./tests/tmp
|
|
54
|
+
```
|
|
55
|
+
|
|
34
56
|
## Required Environment Variables
|
|
35
57
|
|
|
36
58
|
Ensure that the following environment variables are defined:
|
package/dist/cli.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/dbh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Easily connect to PostgresDB from serverless environment",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/schemavaults/dbh.git"
|
|
10
10
|
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"dbh": "dist-cli/cli.js"
|
|
13
|
+
},
|
|
11
14
|
"dependencies": {
|
|
12
15
|
"kysely": "0.28.10",
|
|
13
16
|
"kysely-neon": "1.3.0",
|
|
@@ -21,19 +24,25 @@
|
|
|
21
24
|
"@eslint/js": "9.39.1",
|
|
22
25
|
"globals": "16.5.0",
|
|
23
26
|
"@typescript-eslint/eslint-plugin": "8.48.1",
|
|
24
|
-
"@typescript-eslint/parser": "8.48.1"
|
|
27
|
+
"@typescript-eslint/parser": "8.48.1",
|
|
28
|
+
"commander": "14.0.3"
|
|
25
29
|
},
|
|
26
30
|
"scripts": {
|
|
27
31
|
"build": "tsc --project tsconfig.json && tsc-alias --project tsconfig.json",
|
|
32
|
+
"postbuild": "bun run cleanup",
|
|
33
|
+
"build:cli": "bun build ./src/cli.ts --outdir dist-cli --format esm --target node --minify",
|
|
34
|
+
"build:build-db-migrations": "bun build ./src/build-db-migrations.ts --outdir dist-cli --format esm --target bun --minify",
|
|
28
35
|
"test:unit": "bun test --test-name-pattern 'DBH Init'",
|
|
29
36
|
"test": "bun run test:unit",
|
|
30
|
-
"test:e2e": "bun test ./src/tests/e2e/
|
|
37
|
+
"test:e2e": "bun test ./src/tests/e2e/",
|
|
38
|
+
"test:build-db-migrations": "/bin/bash ./tests/run_build_example_migrations_test.sh",
|
|
31
39
|
"cleanup:compiled_tests_in_dist_directory": "find ./dist -type f \\( -name \"*.test.js\" -o -name \"*.test.js.map\" -o -name \"*.test.d.ts\" \\) -delete",
|
|
32
40
|
"cleanup:rm_tests_dir": "rm -rf ./dist/tests",
|
|
33
|
-
"cleanup": "
|
|
34
|
-
"
|
|
41
|
+
"cleanup:rm_cli_js_artifacts": "rm -rf ./dist/cli.js && rm -rf ./dist/cli.js.map",
|
|
42
|
+
"cleanup": "bun run cleanup:compiled_tests_in_dist_directory && bun run cleanup:rm_tests_dir && bun run cleanup:rm_cli_js_artifacts",
|
|
35
43
|
"version": "bun run ./scripts/package_version.ts",
|
|
36
|
-
"lint": "eslint src"
|
|
44
|
+
"lint": "eslint src",
|
|
45
|
+
"cli": "bun run ./src/cli.ts"
|
|
37
46
|
},
|
|
38
47
|
"main": "dist/index.js",
|
|
39
48
|
"module": "dist/index.js",
|
|
@@ -63,6 +72,20 @@
|
|
|
63
72
|
"types": "./dist/migrate.d.ts",
|
|
64
73
|
"import": "./dist/migrate.js",
|
|
65
74
|
"require": "./dist/migrate.js"
|
|
75
|
+
},
|
|
76
|
+
"./sql": {
|
|
77
|
+
"types": "./dist/sql.d.ts",
|
|
78
|
+
"import": "./dist/sql.js",
|
|
79
|
+
"require": "./dist/sql.js"
|
|
80
|
+
},
|
|
81
|
+
"./cli": {
|
|
82
|
+
"types": "./dist/cli.d.ts",
|
|
83
|
+
"import": "./dist-cli/cli.js",
|
|
84
|
+
"require": "./dist-cli/cli.js"
|
|
85
|
+
},
|
|
86
|
+
"./build-db-migrations": {
|
|
87
|
+
"import": "./dist-cli/build-db-migrations.js",
|
|
88
|
+
"require": "./dist-cli/build-db-migrations.js"
|
|
66
89
|
}
|
|
67
90
|
}
|
|
68
91
|
}
|