lines-db 0.18.1 → 0.19.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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @toiroakr/lines-db
2
2
 
3
+ ## 0.19.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 4bfd4b7: Read the files a schema file imports anew when one of them changed, so an edit to a project file the schema imports, such as a table definition, is validated against instead of the version first loaded. Once the first read has recorded the imports, a file is evaluated again only when it or a file it imports changed, except after a read that failed, so reading the tables again many times does not grow memory with the number of files. A package from `node_modules`, and a file of another package, such as one linked from a workspace, stay one module. A runtime without synchronous module hooks still reads only the schema file itself again, and CommonJS schemas (`.schema.cts`) keep their first evaluation, as before.
8
+
9
+ `hasExternalChanges()` and `findExternalChanges()` now report an edit to, or the removal of, a project file the schemas imported, so the studio reloads when only a table definition changed. `listSchemaDependencies()` lists the project files a database's schemas imported. With synchronous module hooks, a relative import of a file that was not there when the tables were read is tracked too, so creating the file is reported as a change. Calling `initialize()` again in the same process before an earlier call has finished can leave `hasExternalChanges()` reporting no change for a file edited while the earlier call was reading; the studio reads the tables one reload at a time and is not affected. The studio watches the imported files too, so an open page is told as soon as one of them is edited or created, even when it is outside the watched directories; a file that is not there yet is watched through the directory that would hold it, or the nearest one that exists.
10
+
11
+ ## 0.19.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 376a141: A JSON column now gives back a string, a boolean and a number as the value that was inserted. A string such as `"123"`, `"true"`, `"null"` or `'{"a":1}'` used to come back as a number, a boolean, null or an object, and `false` and `true` came back as `0` and `1`. Every value of a JSON column is now stored as JSON text with a string quoted, for `insert`, `batchInsert`, `update` (including `resetToDefault`) and the conditions of `find`, `update` and `delete` alike. Objects and arrays are stored as before, and the JSONL file still holds plain values.
16
+
17
+ Breaking for raw SQL: a string in a JSON column is now stored and read back through `query()` in its quoted form, so `WHERE data = 'abc'` becomes `WHERE data = '"abc"'`. `lines-db` also no longer warns "Failed to parse JSON column" for a plain string it wrote itself.
18
+
19
+ ### Patch Changes
20
+
21
+ - 8deddc8: A table with a validation schema (a schema file, or `validationSchema` passed in code) no longer refuses a row that leaves out a field every existing row holds, when the schema takes that row. Before, the field was inferred as NOT NULL from the rows on disk, so inserting `{"id":3,"name":"c"}` into a table whose rows all had `nick` failed with `NOT NULL constraint failed: users.nick`, in `insert()` and in the studio's save, although the schema accepted the row. A field the schema fills in, or whose omission the schema rejects, stays as it was.
22
+ - aa9725e: `lines-db studio` now lists a table whose JSONL file has no rows, and a table with a primary key can have its first row added in the studio. The studio reads the columns of such a table from the types of its schema file, so the table is listed when the schema declares its input type through `~standard.types` (zod and valibot do; a hand-written Standard Schema has to declare `types`). Without types, the table stays out of the list as before. `DatabaseConfig` has a new `schemaOfEmptyTable` option to give the columns of a table with no rows. `lines-db validate` no longer says a table has "validation errors" when it only skips the foreign keys that point at an empty table; it says the table has no rows to read its columns from.
23
+ - 8deddc8: A boolean, object or array written into a field that no row holds a value in yet is now written back to the JSONL file as it was given. Before, saving `true` into a field that was `null` in every row wrote `1`, and an object wrote JSON text such as `"{\"a\":1}"`, which a schema that takes a boolean or an object then refuses on the next load. A string written first settles the field as text, so a later object is stored as text too, and a write that failed, matched no row or was rolled back leaves the field untyped.
24
+ - 8deddc8: Saving one row no longer rewrites the other rows of the file when the write-back writes only the primary key (`writeFilledValues: 'primaryKey'`, the studio's default). Before, a row nothing was written to had every field its line holds replaced by the value the schema computes: with a schema that computes `full` from `a` and `b`, saving row 1 changed `"full":"edited by hand"` in row 3 to `"full":"m-n"`. Such a row is now written as the file holds it. A field named in `writeBackFields`, and a foreign-key column that an `ON DELETE` / `ON UPDATE` `CASCADE` or `SET NULL` action can change, is still written from the database for every row.
25
+
3
26
  ## 0.18.1
4
27
 
5
28
  ### Patch Changes
package/README.ja.md CHANGED
@@ -473,7 +473,7 @@ if (!result.ok && result.error.name === 'JsonlConflictError') {
473
473
 
474
474
  内容の確認と書き込みの間はファイルをロックしません。その間に別のプロセスが保存した変更は上書きされます。一人でローカルファイルを編集する用途を想定しており、同時に書き込むプロセス間の排他制御は行いません。
475
475
 
476
- `hasExternalChanges()`は、最後に読み書きした後のJSONLファイルやスキーマファイルの変更・追加・削除を確認します。`findExternalChanges()`は該当ファイルの一覧を返します。長時間動くプロセスで、他のツールによる変更を検知して読み直すときに使えます。
476
+ `hasExternalChanges()`は、最後に読み書きした後のJSONLファイルやスキーマファイルの変更・追加・削除と、読み込み時にスキーマがimportしていたプロジェクト内ファイル(テーブル定義など)の変更・削除を確認します。`findExternalChanges()`は該当ファイルの一覧を返し、`listSchemaDependencies()`はスキーマがimportしていたプロジェクト内ファイルの一覧を返します。長時間動くプロセスで、他のツールによる変更を検知して読み直すときに使えます。同期のモジュールフックがあるときは、読み込み時に存在しなかった相対importの先も追跡し、そのファイルが作られると変更として報告します。最初の読み込みでimportが記録されたあとは、読み込みに失敗した場合を除き、そのファイルか、そのファイルがimportしているファイルが変わったときだけ、次の読み込みで評価し直されます。同期のモジュールフックがない実行環境では、スキーマファイル自身だけを読み直します。
477
477
 
478
478
  ```typescript
479
479
  if (unwrap(await db.hasExternalChanges())) {
package/README.md CHANGED
@@ -386,6 +386,8 @@ const order = unwrap(db.findOne('orders', { id: 1 }));
386
386
  console.log(order.items[0].name); // "Laptop"
387
387
  ```
388
388
 
389
+ A JSON column keeps any value as it was inserted. Every value is stored as JSON text, a string quoted, so the string `"123"` is returned as `"123"`, and the number `123` as `123`. In SQL, a string is therefore compared in its quoted form: `WHERE data = '"abc"'`.
390
+
389
391
  ### Schema transformations
390
392
 
391
393
  If a schema converts date strings to `Date` objects on load, define a `backward` transformation to convert them to strings when saving. JSONL stores the strings; the application works with `Date` objects.
@@ -472,7 +474,7 @@ With `sync()` or automatic sync outside a transaction, database changes remain a
472
474
 
473
475
  Files are not locked between checking their contents and writing. Changes saved by another process during that interval are overwritten. This is intended for one person editing local files; it does not coordinate concurrent writers.
474
476
 
475
- `hasExternalChanges()` detects changes, additions, and deletions of JSONL and schema files since the last read or write. `findExternalChanges()` lists the affected files. Use them to detect edits made by other tools and reload data in a long-running process.
477
+ `hasExternalChanges()` detects changes, additions, and deletions of JSONL and schema files since the last read or write, and changes and deletions of the project files the schemas imported (such as a table definition) when they were read. `findExternalChanges()` lists the affected files, and `listSchemaDependencies()` lists the project files the schemas imported. Use them to detect edits made by other tools and reload data in a long-running process. With synchronous module hooks, a relative import of a file that was not there when the tables were read is tracked too, so creating the file is reported as a change. Once the first read has recorded the imports, a file is evaluated again on the next read only when it or a file it imports changed, except after a read that failed; a runtime without synchronous module hooks reads only the schema file itself again.
476
478
 
477
479
  ```typescript
478
480
  if (unwrap(await db.hasExternalChanges())) {