hostdb 0.10.0

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/LICENSE ADDED
@@ -0,0 +1,131 @@
1
+ # PolyForm Noncommercial License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree
8
+ to them as both strict obligations and conditions to all
9
+ your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the
14
+ software to do everything you might do with the software
15
+ that would otherwise infringe the licensor's copyright
16
+ in it for any permitted purpose. However, you may
17
+ only distribute the software according to [Distribution
18
+ License](#distribution-license) and make changes or new works
19
+ based on the software according to [Changes and New Works
20
+ License](#changes-and-new-works-license).
21
+
22
+ ## Distribution License
23
+
24
+ The licensor grants you an additional copyright license
25
+ to distribute copies of the software. Your license
26
+ to distribute covers distributing the software with
27
+ changes and new works permitted by [Changes and New Works
28
+ License](#changes-and-new-works-license).
29
+
30
+ ## Notices
31
+
32
+ You must ensure that anyone who gets a copy of any part of
33
+ the software from you also gets a copy of these terms or the
34
+ URL for them above, as well as copies of any plain-text lines
35
+ beginning with `Required Notice:` that the licensor provided
36
+ with the software. For example:
37
+
38
+ > Required Notice: Copyright Bob Bass (https://github.com/robertjbass)
39
+
40
+ ## Changes and New Works License
41
+
42
+ The licensor grants you an additional copyright license to
43
+ make changes and new works based on the software for any
44
+ permitted purpose.
45
+
46
+ ## Patent License
47
+
48
+ The licensor grants you a patent license for the software that
49
+ covers patent claims the licensor can license, or becomes able
50
+ to license, that you would infringe by using the software.
51
+
52
+ ## Noncommercial Purposes
53
+
54
+ Any noncommercial purpose is a permitted purpose.
55
+
56
+ ## Personal Uses
57
+
58
+ Personal use for research, experiment, and testing for
59
+ the benefit of public knowledge, personal study, private
60
+ entertainment, hobby projects, amateur pursuits, or religious
61
+ observance, without any anticipated commercial application,
62
+ is use for a permitted purpose.
63
+
64
+ ## Noncommercial Organizations
65
+
66
+ Use by any charitable organization, educational institution,
67
+ public research organization, public safety or health
68
+ organization, environmental protection organization,
69
+ or government institution is use for a permitted purpose
70
+ regardless of the source of funding or obligations resulting
71
+ from the funding.
72
+
73
+ ## Fair Use
74
+
75
+ You may have "fair use" rights for the software under the
76
+ law. These terms do not limit them.
77
+
78
+ ## No Other Rights
79
+
80
+ These terms do not allow you to sublicense or transfer any of
81
+ your licenses to anyone else, or prevent the licensor from
82
+ granting licenses to anyone else. These terms do not imply
83
+ any other licenses.
84
+
85
+ ## Patent Defense
86
+
87
+ If you make any written claim that the software infringes or
88
+ contributes to infringement of any patent, your patent license
89
+ for the software granted under these terms ends immediately. If
90
+ your company makes such a claim, your patent license ends
91
+ immediately for work on behalf of your company.
92
+
93
+ ## Violations
94
+
95
+ The first time you are notified in writing that you have
96
+ violated any of these terms, or done anything with the software
97
+ not covered by your licenses, your licenses can nonetheless
98
+ continue if you come into full compliance with these terms,
99
+ and take practical steps to correct past violations, within
100
+ 32 days of receiving notice. Otherwise, all your licenses
101
+ end immediately.
102
+
103
+ ## No Liability
104
+
105
+ ***As far as the law allows, the software comes as is, without
106
+ any warranty or condition, and the licensor will not be liable
107
+ to you for any damages arising out of these terms or the use
108
+ or nature of the software, under any kind of legal claim.***
109
+
110
+ ## Definitions
111
+
112
+ The **licensor** is the individual or entity offering these
113
+ terms, and the **software** is the software the licensor makes
114
+ available under these terms.
115
+
116
+ **You** refers to the individual or entity agreeing to these
117
+ terms.
118
+
119
+ **Your company** is any legal entity, sole proprietorship,
120
+ or other kind of organization that you work for, plus all
121
+ organizations that have control over, are under the control of,
122
+ or are under common control with that organization. **Control**
123
+ means ownership of substantially all the assets of an entity,
124
+ or the power to direct its management and policies by vote,
125
+ contract, or otherwise. Control can be direct or indirect.
126
+
127
+ **Your licenses** are all the licenses granted to you for the
128
+ software under these terms.
129
+
130
+ **Use** means anything you do with the software requiring one
131
+ of your licenses.
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # hostdb
2
+
3
+ Pre-built database binaries for all major platforms, distributed via GitHub Releases.
4
+
5
+ **Primary consumer:** [SpinDB](https://github.com/robertjbass/spindb) - a CLI tool for spinning up local database instances
6
+
7
+ ## Philosophy
8
+
9
+ This repository exists to solve one problem: **database binaries should be available for download on every major platform, for every supported version, without relying on third-party sources that may disappear.**
10
+
11
+ ### Binary Sourcing Priority
12
+
13
+ When adding a database, we source binaries in this order:
14
+
15
+ 1. **Official binaries** - Direct from vendor CDNs (Oracle for MySQL, MariaDB Foundation, EnterpriseDB for PostgreSQL Windows, etc.)
16
+ 2. **Third-party repositories** - Trusted sources like [MariaDB4j](https://github.com/MariaDB4j/MariaDB4j) Maven JARs
17
+ 3. **Build from source** - Docker builds for Linux, native GitHub Actions builds for macOS
18
+
19
+ ### What This Means
20
+
21
+ - Every database version we support has binaries for all 5 platforms
22
+ - Binaries are built once and hosted forever on GitHub Releases
23
+ - `releases.json` provides a queryable manifest of all available downloads
24
+ - CLI tools (like SpinDB) query this manifest to find and download binaries
25
+
26
+ ## Supported Platforms
27
+
28
+ | Platform | Description |
29
+ |----------|-------------|
30
+ | `linux-x64` | Linux x86_64 (glibc 2.28+) |
31
+ | `linux-arm64` | Linux ARM64 (glibc 2.28+) |
32
+ | `darwin-x64` | macOS Intel |
33
+ | `darwin-arm64` | macOS Apple Silicon |
34
+ | `win32-x64` | Windows x64 |
35
+
36
+ ## Quick Start
37
+
38
+ ```bash
39
+ # Download MySQL 8.4.3 for current platform
40
+ pnpm download:mysql
41
+
42
+ # Download for all platforms
43
+ pnpm download:mysql -- --all-platforms
44
+
45
+ # Build from source if no binary available
46
+ pnpm download:mariadb -- --version 11.8.5 --platform linux-arm64 --build-fallback
47
+
48
+ # List supported databases
49
+ pnpm dbs
50
+ ```
51
+
52
+ ## Querying Available Binaries
53
+
54
+ SpinDB (or any consumer) can fetch `releases.json` for available binaries:
55
+
56
+ ```bash
57
+ curl https://raw.githubusercontent.com/robertjbass/hostdb/main/releases.json
58
+ ```
59
+
60
+ **Download URL pattern:**
61
+ ```
62
+ https://github.com/robertjbass/hostdb/releases/download/{tag}/{filename}
63
+
64
+ # Example:
65
+ https://github.com/robertjbass/hostdb/releases/download/mysql-8.4.3/mysql-8.4.3-darwin-arm64.tar.gz
66
+ ```
67
+
68
+ ## Configuration Files
69
+
70
+ | File | Purpose |
71
+ |------|---------|
72
+ | `databases.json` | **Single source of truth** for all databases, versions, and platforms |
73
+ | `releases.json` | Queryable manifest of all GitHub Releases (auto-updated) |
74
+ | `builds/*/sources.json` | URL mappings for each database's binaries |
75
+
76
+ ### databases.json
77
+
78
+ The central configuration that **drives all automation**. GitHub Actions workflows validate against this file before building.
79
+
80
+ ```json
81
+ {
82
+ "mysql": {
83
+ "displayName": "MySQL",
84
+ "status": "in-progress",
85
+ "versions": { "8.4.7": true, "8.0.40": true },
86
+ "platforms": { "linux-x64": true, "darwin-arm64": true, ... }
87
+ }
88
+ }
89
+ ```
90
+
91
+ **To enable a new version:**
92
+ 1. Add it to `databases.json` with `true`
93
+ 2. Add URLs to `builds/<database>/sources.json`
94
+ 3. Run the workflow - it validates against databases.json automatically
95
+
96
+ **Status values:**
97
+ - `completed` - Fully built and released
98
+ - `in-progress` - Currently being implemented
99
+ - `pending` - Planned, not yet started
100
+ - `unsupported` - Not planned (licensing, niche use case, etc.)
101
+
102
+ ### releases.json
103
+
104
+ Auto-generated manifest updated after each GitHub Release. Structure:
105
+
106
+ ```json
107
+ {
108
+ "repository": "robertjbass/hostdb",
109
+ "lastUpdated": "2024-01-15T10:30:00Z",
110
+ "databases": {
111
+ "mysql": {
112
+ "8.4.3": {
113
+ "releaseTag": "mysql-8.4.3",
114
+ "platforms": {
115
+ "darwin-arm64": {
116
+ "url": "https://github.com/.../mysql-8.4.3-darwin-arm64.tar.gz",
117
+ "sha256": "abc123...",
118
+ "size": 165000000
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ ## Current Status
128
+
129
+ | Database | Status | Versions | Notes |
130
+ |----------|--------|----------|-------|
131
+ | MySQL | Completed | 8.4.7, 8.0.40 | Official binaries for all platforms |
132
+ | PostgreSQL | In Progress | 18.1.0, 17.7.0, 16.11.0, 15.15.0 | Source builds + EDB (Windows) |
133
+ | MariaDB | Completed | 11.8.5, 11.4.5, 10.11.15 | Official + source builds |
134
+ | Redis | Completed | 8.4.0, 7.4.7 | Source builds |
135
+ | SQLite | In Progress | 3.51.1 | Official amalgamation |
136
+ | Valkey | Completed | 9.0.1, 8.0.6 | Redis-compatible, permissive license (includes bespoke Windows builds via Cygwin) |
137
+ | MongoDB | Completed | 8.0.17, 8.2.3, 7.0.28 | Official binaries (SSPL license) |
138
+
139
+ See `pnpm dbs` for the full list.
140
+
141
+ ### Licensing Notes
142
+
143
+ Some databases have restrictive licenses that limit commercial and closed-source use:
144
+
145
+ | Database | License | Commercial Use | Open-Source Alternative |
146
+ |----------|---------|----------------|------------------------|
147
+ | MongoDB | SSPL | ❌ Restricted | [FerretDB](https://www.ferretdb.com/) (Apache 2.0) |
148
+ | Redis | RSALv2 + SSPLv1 | ❌ Restricted | [Valkey](https://valkey.io/) (BSD-3-Clause) |
149
+
150
+ **FerretDB** is a MongoDB-compatible database built on PostgreSQL. **Valkey** is a Redis fork maintained by the Linux Foundation after Redis changed to a non-open-source license.
151
+
152
+ If you need MongoDB or Redis compatibility for commercial/closed-source projects, use FerretDB or Valkey instead.
153
+
154
+ ## GitHub Actions
155
+
156
+ Each database has a release workflow triggered via `workflow_dispatch`:
157
+
158
+ 1. Go to Actions → "Release [Database]" → Run workflow
159
+ 2. **Select the version** from dropdown (synced from `databases.json`)
160
+ 3. Select platforms (default: all)
161
+ 4. Workflow **validates against databases.json** before building
162
+ 5. Downloads/builds binaries for all platforms in parallel
163
+ 6. Creates GitHub Release with artifacts
164
+ 7. Updates `releases.json` manifest
165
+
166
+ **Validation:** The workflow validates the selected version exists in `databases.json` and `sources.json` before building.
167
+
168
+ **Sync dropdowns:** Run `pnpm sync:versions` after adding new versions to databases.json.
169
+
170
+ ## Project Structure
171
+
172
+ ```
173
+ hostdb/
174
+ ├── databases.json # Source of truth for all databases
175
+ ├── releases.json # Queryable manifest of GitHub Releases
176
+ ├── schemas/ # JSON schemas for validation
177
+ ├── builds/
178
+ │ ├── mysql/
179
+ │ │ ├── download.ts # Download script
180
+ │ │ ├── sources.json # Version → URL mappings
181
+ │ │ ├── Dockerfile # Source build fallback
182
+ │ │ └── README.md
183
+ │ ├── postgresql/
184
+ │ ├── mariadb/
185
+ │ └── ...
186
+ ├── scripts/
187
+ │ ├── add-engine.ts # pnpm add:engine - scaffold new database
188
+ │ ├── fetch-edb-fileids.ts # pnpm edb:fileids - fetch PostgreSQL Windows file IDs
189
+ │ ├── list-databases.ts # pnpm dbs
190
+ │ ├── sync-versions.ts # pnpm sync:versions - sync workflow dropdowns
191
+ │ └── update-releases.ts # Updates releases.json after release
192
+ └── .github/workflows/
193
+ ├── release-mysql.yml
194
+ ├── release-postgresql.yml
195
+ └── ...
196
+ ```
197
+
198
+ ## Adding a New Database
199
+
200
+ Use the scaffolding script:
201
+
202
+ ```bash
203
+ pnpm add:engine redis # Creates builds/redis/, workflow, and package.json script
204
+ pnpm add:engine sqlite # Then follow printed instructions
205
+ ```
206
+
207
+ ## Documentation
208
+
209
+ - [ARCHITECTURE.md](./ARCHITECTURE.md) - Visual representation of how this repo works
210
+ - [CHECKLIST.md](./CHECKLIST.md) - Checklist for adding a new database
211
+
212
+ ## TODO
213
+
214
+ - [ ] Add Windows filesystem support to download scripts:
215
+ - [ ] Check `process.platform === 'win32'` for platform-specific logic
216
+ - [ ] Use Node's `path` utilities (`path.sep`, `path.join`, `path.normalize`) instead of manual string concatenation
217
+ - [ ] Use `os.tmpdir()` for temp file locations
218
+ - [ ] Use `fs.mkdtemp()` for safe cross-platform temp directory creation
219
+ - [ ] Normalize/escape backslashes when constructing download paths or invoking shell commands
220
+
221
+ ## Inspiration
222
+
223
+ - [MariaDB4j](https://github.com/MariaDB4j/MariaDB4j) - Embedded MariaDB for Java
224
+ - [embedded-postgres-binaries](https://github.com/zonkyio/embedded-postgres-binaries) - PostgreSQL binaries (we previously used this, now build from source)
225
+
226
+ ## License
227
+
228
+ [PolyForm Noncommercial 1.0.0](./LICENSE)
package/bin/cli.js ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { fileURLToPath, pathToFileURL } from 'node:url'
4
+ import { dirname, join } from 'node:path'
5
+ import { spawn } from 'node:child_process'
6
+ import { existsSync } from 'node:fs'
7
+ import { createRequire } from 'node:module'
8
+
9
+ const __filename = fileURLToPath(import.meta.url)
10
+ const __dirname = dirname(__filename)
11
+
12
+ const packageRoot = join(__dirname, '..')
13
+ const mainScript = join(packageRoot, 'cli', 'bin.ts')
14
+
15
+ // Find tsx ESM loader using Node's module resolution
16
+ let tsxLoader = null
17
+
18
+ try {
19
+ const require = createRequire(import.meta.url)
20
+ const tsxDir = dirname(require.resolve('tsx/package.json'))
21
+ const loaderPaths = [
22
+ join(tsxDir, 'dist', 'esm', 'index.mjs'),
23
+ join(tsxDir, 'dist', 'loader.mjs'),
24
+ ]
25
+ tsxLoader = loaderPaths.find((p) => existsSync(p))
26
+ } catch {
27
+ // tsx not found via module resolution
28
+ }
29
+
30
+ if (!tsxLoader) {
31
+ console.error('Error: tsx loader not found.')
32
+ console.error('\nTry running: pnpm install')
33
+ process.exit(1)
34
+ }
35
+
36
+ const tsxLoaderUrl = pathToFileURL(tsxLoader).href
37
+
38
+ const child = spawn(
39
+ process.execPath,
40
+ ['--import', tsxLoaderUrl, mainScript, ...process.argv.slice(2)],
41
+ {
42
+ stdio: 'inherit',
43
+ shell: false,
44
+ cwd: packageRoot,
45
+ },
46
+ )
47
+
48
+ // Forward termination signals to child process
49
+ const forwardSignal = (signal) => {
50
+ if (child.pid && !child.killed) {
51
+ child.kill(signal)
52
+ }
53
+ }
54
+
55
+ process.on('SIGINT', () => forwardSignal('SIGINT'))
56
+ process.on('SIGTERM', () => forwardSignal('SIGTERM'))
57
+ process.on('SIGHUP', () => forwardSignal('SIGHUP'))
58
+
59
+ child.on('exit', (code, signal) => {
60
+ // Clean up signal handlers
61
+ process.removeAllListeners('SIGINT')
62
+ process.removeAllListeners('SIGTERM')
63
+ process.removeAllListeners('SIGHUP')
64
+
65
+ // Exit with same code or signal-based exit code
66
+ if (signal) {
67
+ process.exit(128 + (signal === 'SIGINT' ? 2 : signal === 'SIGTERM' ? 15 : 1))
68
+ }
69
+ process.exit(code ?? 0)
70
+ })
71
+
72
+ child.on('error', (err) => {
73
+ console.error('Failed to start hostdb:', err.message)
74
+ process.exit(1)
75
+ })