Skip to content

build: generate types/ at build and pack time instead of committing it - #4

Merged
Shinrai merged 4 commits into
nextfrom
chore/generated-types
Nov 25, 2026
Merged

Shinrai merged 4 commits into
nextfrom
chore/generated-types

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

No bug fixes

📦 Dependencies

No dependency updates

🔧 Other Changes

👥 Contributors

@Shinrai
Shinrai merged commit b7566f0 into next Nov 25, 2026
24 checks passed
@cldmv-bot
cldmv-bot Bot deleted the chore/generated-types branch November 25, 2026 22:45
cldmv-bot Bot added a commit that referenced this pull request Nov 26, 2026
# `@cldmv/sqlite-wasm` v0.1.0 Changelog

**Release Date**: November 2026
**Release Type**: Minor (first release)
**Branch**: `release/0.1.0`

---

## Overview

First release of `@cldmv/sqlite-wasm`: SQLite 3.54.1 compiled to WebAssembly, with one build and one API for Node.js and browsers. Databases are real files in Node, OPFS in a browser worker, or memory anywhere, and the files are standard SQLite files that native SQLite and `node:sqlite` open as usual.

The wasm is built from SQLite's own source archive with wasi-sdk and binaryen. There is no Emscripten runtime and no fork of another wasm SQLite project. CI builds it from a pinned SQLite version and hash, and nothing binary is committed.

---

## ✨ Features

### Synchronous database API on one shared wasm instance ([#2](#2))

`sqlite.open(path, options)` returns a database with prepared statements, `run` / `get` / `all` / `iterate`, transactions (nested ones become savepoints), user-defined functions, aggregates, window functions and collations, plus `backup()`, `serialize()`, `attach()` and `checkpoint()`. Every connection in a process shares one module instance, which is what lets `ATTACH` and `backup()` work between them. Every SQLite failure is a `sqlite.error` carrying the result code name (`SQLITE_CONSTRAINT_PRIMARYKEY`) and the extended code number.

### Storage drivers: `fs`, `opfs` and `memory` ([#2](#2))

- **`fs`** (Node) writes real files through synchronous `fs` calls, with `fsync` on the file and on its folder after create and delete.
- **`opfs`** (dedicated browser workers) uses OPFS sync access handles, opened before SQLite needs them, so no COOP/COEP headers are needed.
- **`memory`** works anywhere. Each file name keeps its data for the life of the process.
- **`auto`** (the default) picks `fs` in Node and `opfs` in a dedicated worker.

WAL is the default journal mode, run in exclusive locking mode so the WAL index lives in heap memory. A clean `close()` checkpoints the WAL and removes the `-wal` file. `truncate` and `delete` rollback journals are available too.

### Locking between processes and tabs ([#2](#2))

In Node, opening a database takes an owner lock outside the file, and the `lock` option picks where it lives: `beside` (a `<db>.lock/` folder, the default), `temp` (a private per-user folder under `os.tmpdir()`), a folder you name, or `db` (a row inside the database). A lock whose process is gone is taken over. In browsers, the lock is a Web Lock per database.

### Browser main thread: worker host and client ([#2](#2))

`@cldmv/sqlite-wasm/host` runs the database in a worker with `host.listen(self)`, and `@cldmv/sqlite-wasm/worker` gives the main thread an async client with the same API, including nested transactions, `backup()` and `serialize()`. A `setup(db)` hook on the host runs on every open.

### Multi-tab sharing ([#2](#2))

With `share: true`, several tabs of one origin use one OPFS database. One tab's worker owns the database and the others send their requests to it over a `BroadcastChannel`. Ownership moves through a Web Lock when that tab closes or its worker ends, with reads retried against the new owner, and writes whose outcome is unknown failing with `SQLITE_BUSY` rather than running twice. `db.info.leader` and `db.info.watch()` show which tab owns it.

### Drizzle ORM driver ([#2](#2))

`@cldmv/sqlite-wasm/drizzle` exports `drizzle()` and `migrate()` for the synchronous database (Node or inside a worker) and for the async worker client on the main thread. `drizzle-orm` `^0.45.0` is an optional peer dependency.

### What is compiled in ([#2](#2))

FTS3/4/5, R\*Tree and Geopoly, JSON, `dbstat`, math and `percentile` functions, column metadata, STAT4, and `UPDATE`/`DELETE ... ORDER BY ... LIMIT` (generated into the parser from the source archive, so Drizzle's `.orderBy()` and `.limit()` work on updates and deletes). Foreign keys are on and double-quoted strings are identifiers only. The README's "What is compiled in" section has the full list, including what is left out.

---

## 🔧 CI & tooling

- **Package layout and v4 CI** ([#1](#1)): tsup build into `dist/` with a CommonJS entry that re-exports the ESM one, `@cldmv/vitest-runner` tests, eslint and prettier, and the CLDMV v4 workflow set.
- **The wasm build in CI** ([#2](#2)): pinned and hash-checked downloads of SQLite's source archive, wasi-sdk and binaryen, with retries and a cache. The browser tests run headless Chromium as their own CI job, and `npm run sqlite:bump` moves the SQLite pin.
- **Generated types** ([#4](#4)): `types/` is built when the package is built or packed instead of being committed, and each published declaration's header names its own file.

## 🔧 Dependencies

- `drizzle-orm` `^0.45.0`: optional peer dependency, needed only for `@cldmv/sqlite-wasm/drizzle`.
- No runtime dependencies.

---

## Upgrade notes

- First release, nothing to upgrade from.
- Node.js `>=20.19.0` at runtime. The CommonJS entry needs `require(esm)`, so `^20.19.0` or `>=22.13.0`.
- Browsers need a dedicated worker with OPFS sync access handles for persistent storage. Multi-tab sharing also needs Web Locks and `BroadcastChannel`.



<details>
<summary>👥 Contributors</summary>

- @Shinrai

</details>

---

<!-- coverage-start -->

![coverage](https://img.shields.io/badge/coverage-100.0%25-brightgreen?style=for-the-badge&logo=vitest&logoColor=white)

| Metric | Coverage |
|--------|----------|
| Statements | 100.0% |
| Branches   | 100.0% |
| Functions  | 100.0% |
| Lines      | 100.0% |

*Avg: **100.0%** · `c0f05b9` · Node lts/**

<!-- coverage-end -->

<!-- co-authors -->

Co-authored-by: Shinrai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant