lines-db 0.0.0-stage → 0.18.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/CHANGELOG.md ADDED
@@ -0,0 +1,437 @@
1
+ # @toiroakr/lines-db
2
+
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8f9912e: Migrate CLI argument validation to @politty/loculus and generate validators with @loculus/rolldown during the build. Node.js 22.18.0 or newer is now required.
8
+
9
+ ## 0.17.0
10
+
11
+ ### Minor Changes
12
+
13
+ - d711b36: Allow `fillFields()` and `lines-db fill` to fill multiple directories or JSONL files in one operation, computing values and checking for outside changes across all paths before writing. Add `--schema-dir` to the fill command for shared schemas.
14
+
15
+ ## 0.16.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 19259c2: Move the Studio server and browser assets into @lines-db/studio. Install the new package to continue using lines-db studio. Other CLI commands and the database library no longer ship Studio.
20
+
21
+ Rename the core package from @toiroakr/lines-db to lines-db. Update imports and installation commands to use lines-db.
22
+
23
+ Update CLI imports, generated types, editor integration, and documentation for the new package names. Publish both packages from the release workflow.
24
+
25
+ Use the current TypeScript 7.1 synchronous API for Studio schema inspection and verify declared columns with TypeScript 5 and 7.1 in CI.
26
+
27
+ ## 0.15.1
28
+
29
+ ### Patch Changes
30
+
31
+ - c7d2668: Add named dataset configuration for CLI and programmatic use. Export `loadDatasetConfig(path?, { datasets?: string[] | "all" })` returning a database configuration; omit `datasets` or use `[]` for base only, pass an array to combine named sets in order, or use `"all"` to combine every set. `validate` without a positional path reads `lines-db.config.json` and validates only `base`; Repeated `--dataset <name>` flags add named sets in order and `--all-datasets` combines all sets. `--config <path>` selects another configuration, and data and schema paths resolve relative to that file. Existing positional file and directory validation remains unchanged. Reject nonexistent or non-directory schema paths to prevent skipped validation. Reject invalid configurations, unknown datasets and conflicting options; deduplicate overlapping data directories before validation.
32
+ - 19614fc: Support shared schema directories when editing Studio data sets, and edit composed data sets by routing updates and deletes to source files and selecting an insert destination, with conflict detection and rollback across files.
33
+
34
+ ## 0.15.0
35
+
36
+ ### Minor Changes
37
+
38
+ - 798196b: feat: add `lines-db fill` and `fillFields()` to fill the values a table computes into JSONL rows missing them
39
+
40
+ `fillFields({ path, fields })` fills the named fields - by default each table's primary key - into the rows that have no value for them, with the values each table computes for a row: its validation schema's value by default, or the function `loadFiller` builds from the schema module (such as a generated create-time `hook`). A value already in the file is never replaced, a line that gains nothing is left byte for byte (CRLF included), a line that gains a value is written with its keys in the order the computed row lists them, every value is computed before any file is written, and a file saved by another tool after it was read stops the fill with a `JsonlConflictError` before any file is written. The result lists the filled files, the tables without a schema file, the lines that are not JSON objects, and the named fields no table produced a value for. `lines-db fill <path> [--fields a,b]` runs it with the validation schemas. A file starting with a byte order mark is read past the mark, which the filled file keeps. The filled files are written to temporary files and replace the originals only once all are written, and the files already replaced are put back if a later one fails; the error names any file that could not be put back. A filled file keeps its permissions.
41
+ - 798196b: feat: add `LinesDB.hasExternalChanges()` to tell whether the files changed since the database read them
42
+
43
+ It resolves to `true` when a JSONL file the database read or wrote was edited or removed, a JSONL file was added to or removed from a data directory, or a table's schema file was edited, added or removed since `initialize()` or the database's last write. `findExternalChanges()` resolves to the files themselves, for telling which table an outside edit touched. A long-running process can call either to create the database again and load the current files before it serves or writes stale rows.
44
+ - 825b9d2: fix!: refuse to write a table back over a JSONL file changed after the database read it
45
+
46
+ A sync used to write the database's rows over the file, so a line added or a value edited in the file after `initialize()` was silently lost. The sync now leaves such a file alone and fails with a `JsonlConflictError` (exported as a type) naming the file; create the database again and call `initialize()` to load the current file before writing.
47
+ - 798196b: fix!: fail to initialize when a table's schema file cannot be loaded
48
+
49
+ A schema file that failed to import - a syntax error, a package it cannot resolve - or that exports no Standard Schema was ignored, and its table was loaded without validation, so rows were then written without the checks the file means to make. `initialize()` now fails with the file and the reason instead.
50
+ - 798196b: feat: add `lines-db studio` to browse and edit tables in the browser
51
+
52
+ - `lines-db studio <dataDir>` starts a local web UI (`http://127.0.0.1:4848`; `--port`, `--open`, `--write-filled-values`) that lists the tables of `dataDir` with their row counts and shows a table as a grid, built with React and shadcn/ui and shipped prebuilt (no new runtime dependency). Edits, new records and deletions stay pending, highlighted in the grid, until **Save N changes** writes them in one transaction through `update()` / `insert()` / `delete()` (`POST /api/tables/:name/changes`); a value the schema rejects writes nothing and is shown with the change it came from. A table without a primary key, or with a row whose primary key is null, is shown read-only. The table list can be collapsed, which the browser remembers, and opens as a drawer on a narrow screen.
53
+ - A cell's editor validates the value as you type through `POST /api/tables/:name/check`, which runs the change in a transaction that is rolled back, and lists the issues under the field. A JSON column opens in a dialog with a highlighting editor that marks syntax errors and accepts comments and trailing commas, which are dropped as the value is saved as plain JSON. A banner above the grid counts the unsaved changes and saves or discards them. **Schema** opens on the table's declared definition (columns, foreign keys, indexes), with a **Code** tab for the schema file as it is on disk, highlighted; a table with failing rows shows only the code (`GET /api/tables/:name/schema`). The columns are read from the types of the schema file (its Standard Schema `types`) with the TypeScript of the project, through the compiler API of TypeScript 5 and 6 or the Corsa API of TypeScript 7.1 and later (`typescript` is an optional peer dependency), and are marked as inferred from the rows when that is not possible.
54
+ - A table with rows that fail validation on load is shown as its JSONL file holds it, with the failing rows and cells marked and their issues listed; a fix is checked with `validateRow()` and written to that row's line only, and the table is loaded as usual once every row passes. Adding and deleting rows is off until then. A field the schema refuses as a key is marked **not in schema**, and its column header removes it from every row at once. The studio loads the tables row by row, so a foreign-key or NOT NULL violation marks its row instead of stopping the start, a save reports the edited rows that still fail such a check, and a fixed file keeps its permissions. The studio watches the data directory and pushes a `changed` event over Server-Sent Events (`/api/events`) when the files change on disk or a save succeeds, and the page reloads its rows unless a cell or a new row is being edited. A JSONL file changed by another tool is not overwritten: a save that would write over it (`JsonlConflictError`) answers 409 naming the file, and the tables are reloaded from the files.
55
+ - A save writes the fields the user wrote and leaves the values the schema fills in out of the file (`writeFilledValues: 'primaryKey'`; `--write-filled-values all` writes them too). A value the schema filled in is shown with a **default** mark, and **Remove field** takes a field out of the row, leaving its value to the schema.
56
+ - The token generated at start-up is handed to the page the server serves, kept in `sessionStorage` and sent with each request, and a request without it is refused with 401; another site cannot read the page, so it cannot get the token. It answers only requests whose `Host` is the local server, accepts writes only as `application/json` and not from another `Origin`, and serves its page with a Content-Security-Policy that allows scripts and styles from itself only.
57
+ - 085f7c4: fix!: refuse writes made through the database while a `transaction()` callback is running
58
+
59
+ `transaction(fn)` now passes `fn` an object of its own instead of the database itself, and a write made through the database (`db.insert()` / `db.update()` / `db.delete()`, their batch variants, `execute()`, a `query()` that changes rows, and SQL on `db.getDb()`) while the transaction is open returns a failed Result or throws, instead of joining the transaction. Before, such a write from unrelated code running while an async callback awaited was reported as done, then rolled back with the transaction if the callback threw, or committed with it otherwise. Writes are synchronous, so they are refused rather than queued until the transaction ends. Code inside the callback must write through the `tx` argument. While a transaction runs, SQL run through the database itself (`getDb()`, `execute()`, `query()`) may only read: a `SELECT`, `VALUES`, `WITH` or `EXPLAIN`, or a pragma that reads such as `PRAGMA table_info(...)`. Every other statement is refused, including transaction control, `SAVEPOINT`, and any `PRAGMA` that sets something, since each could change the transaction. Through the callback's `tx`, SQL runs as before. `getDb()` now returns a wrapper around the SQLite connection instead of the connection itself, also outside a transaction, so a handle or prepared statement kept from before a transaction is refused too when it writes while a callback runs; it runs SQL unchanged when no transaction is open.
60
+ - 798196b: fix!: write a transaction back before it commits, and only the tables it changed
61
+
62
+ - `transaction()` writes the tables back before `COMMIT`, and rolls the transaction back when the write-back fails, so a `JsonlConflictError` or an I/O error no longer leaves the database holding a change its files did not get.
63
+ - Every file a transaction writes back is checked before the first one is written, so a file changed on disk fails the transaction before any file is written. When writing a later file fails, the files already written are put back to what they held, as far as writing them again succeeds.
64
+ - A transaction writes back only the tables it changed through `insert()` / `update()` / `delete()` and their batch variants, together with the tables an `ON DELETE` / `ON UPDATE` `CASCADE` or `SET NULL` action can change in turn; a table it did not change keeps its file as it is, and a change made to that file on disk no longer fails the transaction. Raw SQL through `execute()` or `query()` that changes rows inside a transaction still writes back every table, since the tables it changed are unknown, and `sync()` inside a transaction now fails instead of writing rows the transaction could roll back. A write or sync made while a transaction is starting, or once its callback has returned and it writes its files back, is refused: the first could be written back with rows the transaction later rolls back, and the second would miss the files. This also holds for a statement prepared on `getDb()` inside the transaction and run later. `BEGIN`, `COMMIT`, `END` and `ROLLBACK` through `execute()` / `query()` inside a transaction are refused, as they would end it before its files are written back, and inside a transaction `getDb()` hands out a handle that refuses them too and has the tables written back whole once SQL run on it changes rows.
65
+ - 798196b: feat: add `validateRow(tableName, row)` to check a row against a table's schema
66
+
67
+ It resolves to the row as the schema validates it, or a `ValidationError` with the issues. It also works for a table left out on load because rows failed validation, so a tool can check a fix to such a row before writing it to the file.
68
+ - 798196b: feat: choose to write back only the fields a user wrote, leaving the values a schema fills in out of the file
69
+
70
+ - `writeFilledValues: 'primaryKey'` on the config, or on a single `sync()`, writes back the fields a row's line holds, the fields an `insert()` / `batchInsert()` was given, the fields an `update()` / `batchUpdate()` changed, and the fields named in `writeBackFields` / `fields`. A value the validation schema fills in - a default, or a field it computes - stays out of the line, except a primary key the schema generates, which is written so the row keeps it. The default, `'all'`, writes every value as before. A column an `ON DELETE` / `ON UPDATE` `CASCADE` or `SET NULL` action can change is always written, as the action changes it without a write through the database. A field a migration `transform` set on a row while loading counts as written on that row, and the rows of a table that raw SQL through `execute()` or `query()` may have changed are written back whole, as which fields it set is unknown.
71
+ - `insert()` and `batchInsert()` store the rows as the schema validated them, so a field the row omits holds the value the schema fills in instead of failing with `NOT NULL constraint failed`.
72
+ - `update(..., { resetToDefault: ['age'] })` hands a field back to the schema: the row holds the value the schema fills in, and with `writeFilledValues: 'primaryKey'` its line loses the field.
73
+ - `findWithDefaults(tableName)` resolves to every row with the fields the schema filled in on it.
74
+
75
+ ### Patch Changes
76
+
77
+ - 798196b: fix: read a JSONL line that holds JSON but not an object, such as `null` or an array, as a `JsonlParseError` naming its file and line, instead of loading it as a row
78
+ - 798196b: fix: keep a field the schema does not know in the lines a write-back rewrites
79
+
80
+ A validation schema that strips unknown keys, such as valibot's `v.object()`, lets a line hold a field the table has no column for. Writing the table back rewrote every line from the database, so changing any row dropped that field from every line, including lines that were not changed. A write-back now keeps such a field where its line holds it, also on a row whose primary key changed. A schema that refuses unknown keys, such as `v.strictObject()`, reports the line as failing validation instead.
81
+ - 798196b: fix: let an inferred column be null when some rows lack the field
82
+
83
+ A table without a schema infers its columns from its rows, and marked a column NOT NULL when no row held `null` for it, even when some rows did not hold the field at all. Those rows store `null` for it, so loading such a table failed with `NOT NULL constraint failed`. A column is now NOT NULL only when every row holds a value for it.
84
+ - a88fd28: studio: tell an open page that the files changed on disk when a value check is the first to notice and reloads the tables. Before, the page heard nothing, as the watcher then found nothing left to reload, so it kept showing the old rows.
85
+ - b66133d: feat(studio): edit a row in a form beside the grid, and JSON values as fields
86
+
87
+ - A row form beside the grid, shown or hidden from the header, edits every field of a row at once; its changes join the pending ones. While it is shown a click on a row shows that row in it and a double click edits the cell; while it is hidden a double click on a row shows it. A foreign key field opens the row it refers to (`GET /api/tables` now lists each table's `references`). The form can be widened by dragging its edge.
88
+ - A JSON value is edited as fields of its own, in the row form and in a cell's editor: a map as a field per key, a list as a field per item and a list of maps as a block per item, with issues shown under the key they are about. Each block switches to a JSON editor.
89
+ - **Remove field** and **Set null** are offered only where the schema takes them, and keys inside a JSON value are added and removed only where the schema takes them: the studio validates a sample row with the change to find out, and lists it on each column of `GET /api/tables` (`nullable`, `optional`, `nested`).
90
+ - **Add record** opens a dialog with a field for each column; the fields left empty are left out of the row, and the whole row is checked as it is filled in.
91
+ - A text field grows with its lines, and Shift+Enter breaks a line. The colors follow Prisma Studio, light and dark, with a toggle in the header; the head of each row and the column headers stay in view as the grid scrolls; and the panes no longer bounce at the ends of a scroll.
92
+
93
+ ## 0.14.0
94
+
95
+ ### Minor Changes
96
+
97
+ - 117c96e: feat: validate data sets composed from several data directories against a shared schema directory
98
+
99
+ - `DatabaseConfig.schemaDir` sets where `<Table>.schema.{ts,mts,cts}` files are looked up, for both validation and foreign key discovery, so `{ dataDir: 'seed/data/cogs', schemaDir: 'seed/data' }` no longer fails with `Schema file not found`. When unset, a schema is looked up next to the JSONL file as before; it is required when `dataDir` lists several directories, since a data set directory does not hold the schemas of its tables and they would otherwise be loaded unvalidated. `SchemaLoader.loadSchema()` and `SchemaLoader.hasSchema()` take the same directory as an optional second argument.
100
+ - `DatabaseConfig.dataDir` also takes a list of directories. A table found in more than one of them has the rows of each file, in the order the list gives, and validation, unique indexes and foreign keys run over those rows together: a data set can reference rows of a base set, and an id defined in two sets is reported as a violation. `ValidationErrorDetail.file` / `rowIndex` and the `file` / `line` of a `JsonlParseError` point at the file the row came from and its position in that file.
101
+ - A database whose `dataDir` lists several directories is read-only: `insert`, `update`, `delete`, their `batch*` forms, `sync()` and SQL that writes through `execute()` or `query()` return an error without changing the database or the files, since such rows have no single file to be written back to.
102
+
103
+ Breaking: `DatabaseConfig.dataDir` is now typed `string | readonly string[]`, so code that reads it back as a `string` no longer type-checks.
104
+
105
+ fix: a foreign key checked after a circular dependency is now reported at the index of the offending row. It was taken from the SQLite rowid, which for an integer primary key is the id itself, so a table whose ids did not run 1..N in file order reported `id - 1` instead.
106
+
107
+ ## 0.13.0
108
+
109
+ ### Minor Changes
110
+
111
+ - fbd290c: fix: expose structured file and line metadata for malformed JSONL errors
112
+
113
+ `JsonlReader.read()` previously threw a plain `Error` whose message contained only the offending text, so callers had no reliable way to determine which file and physical line caused a malformed-JSON failure. It now returns a failed `Result` (see the separate `Result`-type-migration changeset) whose `error` is a `JsonlParseError` (exported from the package entry point) carrying `file` (the path passed to `read()`, the same value `ValidationErrorDetail.file` already carries for schema errors) and `line` (the 1-based physical line, counting blank lines and matching what an editor shows for both LF and CRLF files), while keeping the existing human-readable message. This error propagates unchanged through `LinesDB.initialize()`, so callers such as `tailor seed validate` can link a parse failure back to its source location.
114
+ - fbd290c: feat!: migrate the JS programmatic API (`LinesDB`, `JsonlReader`) to a `Result` type instead of throwing
115
+
116
+ **Breaking change.** Every `LinesDB` method that could previously throw (`initialize`, `find`, `findOne`, `query`, `queryOne`, `execute`, `insert`, `batchInsert`, `update`, `batchUpdate`, `delete`, `batchDelete`, `sync`, `transaction`, `close`) now returns a `Result<T, Error>` — a plain `{ ok: true; value: T } | { ok: false; error: Error }` — instead of throwing or rejecting. `JsonlReader.read()` and `JsonlReader.inferSchema()` do the same. `getSchema`, `getTableNames`, and `getDb` are unaffected since they cannot fail.
117
+
118
+ A new `Result` type plus `ok`, `err`, and `unwrap` helpers are exported from the package entry point. `unwrap(result)` reads `result.value`, or throws `result.error` when `result.ok` is `false` — the quickest way to restore the previous throw-on-failure behavior at a call site:
119
+
120
+ ```ts
121
+ import { LinesDB, unwrap } from '@toiroakr/lines-db';
122
+
123
+ const db = LinesDB.create({ dataDir: './data' });
124
+ unwrap(await db.initialize());
125
+ const users = unwrap(db.find('users'));
126
+ ```
127
+
128
+ Inside `db.transaction(async (tx) => { ... })`, `tx` is the same Result-returning API, so a failed `tx.insert()`/`tx.update()`/etc. no longer throws on its own and therefore does not roll back the transaction by itself — check the Result (or call `unwrap`) and let the thrown error propagate out of the callback to trigger a rollback.
129
+
130
+ The CLI (`lines-db validate`/`migrate`/`generate`) is unaffected: it unwraps these Results internally and keeps its existing exit codes and error output.
131
+
132
+ Migration: wrap existing call sites with `unwrap(...)`, or switch to checking `.ok` where you want to handle a failure without a try/catch (e.g. an expected validation error from `insert`/`update`).
133
+
134
+ ## 0.12.7
135
+
136
+ ### Patch Changes
137
+
138
+ - df82465: chore(deps): update pnpm to v12
139
+ - 3e19767: fix(deps): update dependency @politty/zod to ^0.2.0
140
+
141
+ ## 0.12.6
142
+
143
+ ### Patch Changes
144
+
145
+ - 149dd11: fix(deps): update dependency zod to ^4.5.4
146
+
147
+ ## 0.12.5
148
+
149
+ ### Patch Changes
150
+
151
+ - b87c941: fix: revert engines.node requirement from Node 24 back to Node >=22.12.0
152
+
153
+ The `engines.node` requirement was unintentionally bumped from `>=22.12.0` to `>=24.19.0` as a side effect of a Renovate update that only intended to pin the CI workflow's Node version, not raise the package's minimum supported Node version. No runtime dependency actually requires Node 24. Consumers can now install and run this package on Node 22.12.0 or later again.
154
+
155
+ ## 0.12.4
156
+
157
+ ### Patch Changes
158
+
159
+ - 937c5a5: fix(deps): update dependency @politty/zod to ^0.1.2
160
+
161
+ ## 0.12.3
162
+
163
+ ### Patch Changes
164
+
165
+ - 1a16efa: chore(deps): migrate from politty to @politty/zod
166
+ - ef529f6: fix(deps): update dependency politty to ^0.11.7
167
+ - 66f2ed3: chore(deps): update dependency @changesets/cli to v3
168
+ - c0f6205: fix(deps): update dependency politty to ^0.11.8
169
+
170
+ ## 0.12.2
171
+
172
+ ### Patch Changes
173
+
174
+ - 7ff9a08: fix(deps): update dependency @standard-schema/spec to ^1.1.0
175
+ - 8e303a1: fix(deps): update dependency amaro to ^1.1.11
176
+
177
+ ## 0.12.1
178
+
179
+ ### Patch Changes
180
+
181
+ - 310bdaf: Stop bundling `zod` and `politty` into the CLI binary (`bin/cli.mjs`) and declare them as regular
182
+ `dependencies` instead of `devDependencies`. Both are implementation details of the CLI's argument
183
+ parsing (`src/cli.ts`) — the library's public API (`src/index.ts`) never touches them — but bundling
184
+ them baked in a copy that could drift from the `zod` version `politty` itself requires as a peer
185
+ dependency. Installing them as ordinary dependencies keeps a single, consistent `zod` instance.
186
+
187
+ No functional change for consumers: `npx lines-db` and installed CLI usage behave identically, just
188
+ with a smaller bundled binary and `politty`/`zod` resolved from `node_modules` instead.
189
+
190
+ ## 0.12.0
191
+
192
+ ### Minor Changes
193
+
194
+ - 18bf887: Put a field a line did not have where the schema declares it, instead of at the end of the line, and
195
+ export that merge as `mergeFields` for filling a JSONL file in without a database.
196
+
197
+ A write-back appended a key the line was missing, which left a backfilled `id` trailing at the end of
198
+ the row - somewhere no hand-written seed line puts it - and left callers re-reading the file afterwards
199
+ to reorder it themselves:
200
+
201
+ ```jsonl
202
+ {"name":"Alice","id":"018f…"} before
203
+ {"id":"018f…","name":"Alice"} now
204
+ ```
205
+
206
+ The order comes from the row the schema computes, so it is the order the schema declares its fields in.
207
+ A key the line already had never moves, and a key the schema does not declare stays behind the declared
208
+ ones.
209
+
210
+ `mergeFields` is that same merge on its own, for when the values come from somewhere other than a query
211
+ and loading the file into SQLite would only get in the way:
212
+
213
+ ```typescript
214
+ import { JsonlReader, JsonlWriter, mergeFields } from "@toiroakr/lines-db";
215
+
216
+ const rows = await JsonlReader.read("./data/users.jsonl");
217
+ const filled = rows.map((row) =>
218
+ mergeFields(row, fillIds(row), { fields: ["id"] })
219
+ );
220
+ await JsonlWriter.write("./data/users.jsonl", filled);
221
+ ```
222
+
223
+ Nothing else in the line is read or checked, so a field in a format a schema would reject cannot keep
224
+ the named ones from being written. A field the computed row has no value for is left alone rather than
225
+ nulled out, and `keyOrder` overrides where a new key lands when the computed row does not list its
226
+ fields in the order the schema declares them.
227
+
228
+ ## 0.11.0
229
+
230
+ ### Minor Changes
231
+
232
+ - 15cd137: Let a sync write back only the fields you name, instead of always rewriting the whole row.
233
+
234
+ Write-back materialized every column, so values a validation schema computed and fields the JSONL
235
+ file omitted were baked into the file - `lines-db migrate` rewrote far more than the transform
236
+ touched. Naming the fields keeps the rest of each line exactly as the file had it:
237
+
238
+ ```bash
239
+ # users.jsonl before: {"name":"John"}
240
+ npx lines-db migrate ./data/users.jsonl "(row) => row" --fields id
241
+ # users.jsonl after: {"name":"John","id":"..."}
242
+ ```
243
+
244
+ - `--fields <list>` on the `migrate` CLI
245
+ - `db.sync(table, { fields: ['id'] })` for a single sync
246
+ - `writeBackFields` on the database config, which also covers the automatic sync after insert,
247
+ update, and transaction
248
+
249
+ One list covers every table a run touches: a table without a named field has nothing written back to
250
+ it, so a directory of tables that do not all share an `id` works with a single `--fields id`. The CLI
251
+ still rejects a field no table has, and `sync(table, { fields })` rejects a field that one table does
252
+ not have.
253
+
254
+ Declaring nothing keeps the previous behaviour of writing every field.
255
+
256
+ ### Patch Changes
257
+
258
+ - 15cd137: Keep the order a JSONL file lists its rows in when syncing.
259
+
260
+ A sync wrote rows back in database order. An integer primary key is SQLite's rowid, so a file whose
261
+ lines were not already sorted by id came back reshuffled - a whole-file diff out of a one-field
262
+ change. Rows now keep the order the file has them in, and rows the file did not have are appended.
263
+ When rows cannot be matched to their lines (no usable primary key and a changed row count), a full
264
+ write-back falls back to database order as before.
265
+
266
+ - 15cd137: Fix `lines-db migrate <file>` on Windows.
267
+
268
+ The command split the given path on `/` and fell back to `.` when it found none, so a Windows path
269
+ turned into a table name and the data directory became the current directory:
270
+ `Table 'D:\...\User' not found in directory '.'`. Paths now go through `node:path`, which is
271
+ separator-aware.
272
+
273
+ ## 0.10.1
274
+
275
+ ### Patch Changes
276
+
277
+ - 4587fb2: Remove the `js-yaml: '>=4.2.0'` pnpm override. It forced `@manypkg/get-packages` (via `read-yaml-file@1.1.0`, a transitive dependency of `@changesets/cli`) onto js-yaml 4, whose `yaml.safeLoad` was removed, breaking `pnpm changeset version` and the release workflow. Both js-yaml security advisories the override addressed (quadratic-complexity DoS and prototype pollution in merge handling) are already patched in the 3.x line at 3.15.0, so removing the override lets pnpm resolve that dependency to a safe 3.x release without forcing an incompatible major on affected consumers.
278
+ - 5450665: Remove the optional `valibot` peerDependency. The library only relies on the `@standard-schema/spec` interface at runtime and in its public types, so no schema library needs to be declared as a peer dependency.
279
+
280
+ ## 0.10.0
281
+
282
+ ### Minor Changes
283
+
284
+ - 332b239: Drop CJS build and replace tsx with amaro
285
+
286
+ - ESM-only build. Node.js 22.12+ (VSCode 1.118+) required.
287
+ - Replace `tsx` runtime dependency with `amaro` for TypeScript schema file loading.
288
+
289
+ ### Patch Changes
290
+
291
+ - c42865e: Replace commander with politty for the CLI framework. Bundle zod and politty into the CLI binary so they are no longer installed as runtime dependencies for library users.
292
+
293
+ ## 0.9.2
294
+
295
+ ### Patch Changes
296
+
297
+ - 9982a21: Update runtime dependencies (`commander` to v14.0.3, `@standard-schema/spec` to v1.1.0, `tsx` to v4.21.0) and refresh devDependencies/tooling (migrate from ESLint/Prettier to Oxlint/Oxfmt, TypeScript v6).
298
+
299
+ ## 0.9.1
300
+
301
+ ### Patch Changes
302
+
303
+ - 4ca2664: fix: validate circular foreign key constraints via deferred validation
304
+
305
+ Previously, when two tables had bidirectional foreign keys (e.g., `_User` → `User` and `User` → `_User`), one direction's FK validation was always skipped due to circular dependency detection. Now, circular dependency FKs are validated in a second pass after all tables have been loaded, using SQL queries instead of SQLite FK constraints.
306
+
307
+ ## 0.9.0
308
+
309
+ ### Minor Changes
310
+
311
+ - 07b35ed: Export ErrorFormatter and related types (ErrorFormatterOptions, ValidationErrorInfo, ForeignKeyErrorInfo) from package entry point
312
+
313
+ ## 0.8.0
314
+
315
+ ### Minor Changes
316
+
317
+ - c408b92: feat: display per-table validation results for directory validation
318
+
319
+ The `validate` command now shows individual results per table when validating a directory, including record counts for successful tables (e.g., `✓ users (3 records)`).
320
+
321
+ - Added `TableValidationResult` type and `tableResults` field to `ValidationResult`
322
+ - Each table result includes `tableName`, `valid`, `rowCount`, `errors`, and `warnings`
323
+
324
+ ### Patch Changes
325
+
326
+ - e61a4ee: fix: gracefully handle foreign key validation when referenced table has errors
327
+
328
+ When validating a directory, if a table had validation errors, any table referencing it via foreign key would crash with a misleading `no such table` SQLite error. Now, foreign key constraints to failed tables are skipped with a clear warning (e.g., `⚠ Skipping foreign key validation for table 'child': referenced table 'parent' has validation errors`), and the child table's own schema validation still runs normally.
329
+
330
+ ## 0.7.0
331
+
332
+ ### Minor Changes
333
+
334
+ - 4597383: feat: support .mts and .cts schema file extensions
335
+
336
+ Schema files are now auto-detected with the following priority: `.schema.ts` > `.schema.mts` > `.schema.cts`. Mixed extensions within a single project are supported.
337
+
338
+ - Added `--output` option to `generate` command for specifying the output file path (e.g., `--output ./data/db.mts`)
339
+ - Import paths are correctly rewritten: `.ts`→`.js`, `.mts`→`.mjs`, `.cts`→`.cjs`
340
+ - New exported utilities: `findSchemaFile`, `isSchemaFile`, `extractTableNameFromSchemaFile`, `rewriteExtensionForImport`, `SCHEMA_EXTENSIONS`
341
+
342
+ ## 0.6.1
343
+
344
+ ### Patch Changes
345
+
346
+ - 9ae4075: fix: support foreign key constraints with unique indexes
347
+
348
+ ## 0.6.0
349
+
350
+ ### Minor Changes
351
+
352
+ - 042c14e: feat!: Refactor validation process and remove Validator class
353
+
354
+ fix: extension for latest lines-fb
355
+
356
+ - b22f4f0: feat: Refactor validation process and enhance database initialization
357
+ - Added detailedValidate option to initialize() for detailed constraint violation reporting
358
+ - Enhanced migrate command to apply transforms during initialization for better performance
359
+ - Implemented batch insert for improved performance with SQLite parameter limits
360
+ - Added support for self-referencing foreign keys (e.g., nullable parent_id columns)
361
+ - Improved error handling and reporting for validation failures
362
+ - Added transform option to initialize() method for data transformation during load
363
+ - Enhanced foreign key dependency resolution
364
+ - Added type-fest as dev dependency
365
+
366
+ ## 0.5.0
367
+
368
+ ### Minor Changes
369
+
370
+ - 1d60d66: feat: support directory for migration
371
+
372
+ ## 0.4.1
373
+
374
+ ### Patch Changes
375
+
376
+ - b281dc8: Fix constraint validation in validator to properly detect primary key and unique index violations
377
+
378
+ Previously, the validator was not creating indexes from schema metadata and was missing the default primaryKey behavior, causing constraint violations to go undetected. This fix ensures:
379
+
380
+ - Indexes (both unique and non-unique) are now properly created from schema metadata in the validation database
381
+ - Primary key defaults to 'id' column when not explicitly specified, matching database.ts behavior
382
+ - Constraint violations are properly detected by inserting rows into an in-memory database and catching SQLite exceptions
383
+ - Detailed error information is extracted from SQLite error messages for better diagnostics
384
+
385
+ Added comprehensive regression tests to prevent this issue from recurring.
386
+
387
+ ## 0.4.0
388
+
389
+ ### Minor Changes
390
+
391
+ - a662484: - Allow flexible schema export methods (support loading from `schema` or `default` exports)
392
+ - Enhance constraint validation by loading data into an actual database (catches unique, primary key, and foreign key violations)
393
+ - Add fallback logic to automatically use `id` column as primary key when it exists and no primary key is explicitly defined
394
+
395
+ ## 0.3.0
396
+
397
+ ### Minor Changes
398
+
399
+ - 50266c5: - Enhanced database initialization with dependency resolution and error handling
400
+ - Added support for undefined values in schema inference
401
+ - Implemented validation that automatically adds columns during data insertion
402
+
403
+ ## 0.2.1
404
+
405
+ ### Patch Changes
406
+
407
+ - 0881a89: fix: use tsx for load typescript
408
+
409
+ ## 0.2.0
410
+
411
+ ### Minor Changes
412
+
413
+ - b8e0afe: feat!: remove bun/deno
414
+
415
+ ### Patch Changes
416
+
417
+ - 49089e1: fix: skip validation with warning instead of error when schema file is not found
418
+
419
+ When validating a directory containing JSONL files, if a schema file is missing for some tables, the validator will now:
420
+
421
+ - Skip validation for those files with a warning message instead of throwing an error
422
+ - Display warnings in yellow in the CLI output
423
+ - Continue validation for other files that have schema files
424
+
425
+ This allows for more flexible validation workflows where not all tables require validation schemas.
426
+
427
+ ## 0.1.2
428
+
429
+ ### Patch Changes
430
+
431
+ - 00c623a: chore: update README
432
+
433
+ ## 0.1.1
434
+
435
+ ### Patch Changes
436
+
437
+ - fce2b5a: chore: update README
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Akira HIGUCHI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.