lines-db 0.15.0 → 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 +31 -0
- package/README.ja.md +72 -6
- package/README.md +69 -4
- package/bin/cli.mjs +277 -51
- package/dist/index.d.mts +10 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +66 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal.mjs +1 -2
- package/package.json +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @toiroakr/lines-db
|
|
2
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
|
+
|
|
3
34
|
## 0.15.0
|
|
4
35
|
|
|
5
36
|
### Minor Changes
|
package/README.ja.md
CHANGED
|
@@ -10,7 +10,7 @@ CLIには検証、マイグレーション、値の補完、型生成のコマ
|
|
|
10
10
|
|
|
11
11
|
## インストール
|
|
12
12
|
|
|
13
|
-
Node.js 22.
|
|
13
|
+
Node.js 22.18.0以降が必要です。
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npm install lines-db
|
|
@@ -71,6 +71,61 @@ npx lines-db validate ./data --verbose
|
|
|
71
71
|
|
|
72
72
|
対応するスキーマファイルを読み込み、各行を検証します。検証エラーにはファイル名と詳細を表示します。
|
|
73
73
|
|
|
74
|
+
#### 名前付きデータセットの検証
|
|
75
|
+
|
|
76
|
+
共通データとシナリオ別のデータを `lines-db.config.json` に定義できます:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"schemaDir": "./data",
|
|
81
|
+
"base": ["./data"],
|
|
82
|
+
"datasets": {
|
|
83
|
+
"cogs": ["./data/cogs"],
|
|
84
|
+
"sales": ["./data/sales"]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
パスを省略すると、カレントディレクトリの `lines-db.config.json` を読み、`base` だけを検証します。
|
|
90
|
+
`--dataset <name>` は `base` に指定したデータセットを追加します。複数回指定すると、その順に各セットを結合します。`--all-datasets` は `base` と全データセットを
|
|
91
|
+
一度に結合して検証します。シナリオ間で同じIDを使っている場合、全セットの結合では重複エラーになります。
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npx lines-db validate
|
|
95
|
+
npx lines-db validate --dataset cogs
|
|
96
|
+
npx lines-db validate --dataset cogs --dataset sales
|
|
97
|
+
npx lines-db validate --all-datasets
|
|
98
|
+
npx lines-db validate --config ./seed/lines-db.config.json --dataset cogs
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`--config <path>` で別の設定ファイルを指定できます。`schemaDir`・`base`・`datasets` は必須で、
|
|
102
|
+
`base` と各データセットは1つ以上のディレクトリを指定します(追加セットが無ければ `datasets: {}`)。
|
|
103
|
+
設定内の相対パスは設定ファイルの場所が基準です。ディレクトリは `base`、選択したセットの順に読み込み、
|
|
104
|
+
同じディレクトリは1回だけ読み込みます。サブディレクトリを自動で探索することはありません。
|
|
105
|
+
スキーマ・ユニーク制約・外部キーは結合したデータ全体に対して検証され、エラーは元のファイルを指します。
|
|
106
|
+
|
|
107
|
+
`--dataset` と `--all-datasets` の併用、または設定用オプションと位置引数のパスの併用はエラーです。
|
|
108
|
+
不明なセット名や不正な設定もエラーになります。既存の `validate <path>` は設定ファイルを使わず、従来どおり動作します。
|
|
109
|
+
設定ファイルを使うCLIコマンドは `validate` のみです。
|
|
110
|
+
|
|
111
|
+
プログラムからは同じ設定を `loadDatasetConfig()` で読み込めます:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { LinesDB, loadDatasetConfig } from 'lines-db';
|
|
115
|
+
|
|
116
|
+
const config = await loadDatasetConfig('./lines-db.config.json', {
|
|
117
|
+
datasets: ['cogs', 'sales'],
|
|
118
|
+
});
|
|
119
|
+
const db = LinesDB.create(config);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`datasets` の省略または `[]` はbaseのみ、配列はbase+指定セットを配列順に結合し、`'all'` はbase+全セットを
|
|
123
|
+
設定ファイルの定義順に結合します。同じディレクトリは、シンボリックリンク経由の指定も含めて1回だけ読み込みます。
|
|
124
|
+
引数を省略した `loadDatasetConfig()` は、カレントディレクトリの `lines-db.config.json` を読みます。
|
|
125
|
+
戻り値は `Promise<DatabaseConfig>` です。設定ファイルを読み込めない場合、不正な設定や未知のセット名がある場合、
|
|
126
|
+
または選択したデータディレクトリが存在しない場合はPromiseをrejectします。データの読み込み・検証は
|
|
127
|
+
`db.initialize()` で実行します。`schemaDir` が存在しない、またはファイルを指す場合もエラーになります。
|
|
128
|
+
|
|
74
129
|
### データのマイグレーション
|
|
75
130
|
|
|
76
131
|
JSONLファイルの各行に変換関数を適用し、結果をスキーマで検証して保存します。
|
|
@@ -113,10 +168,10 @@ npx lines-db migrate ./data/users.jsonl "(row) => row" --fields id
|
|
|
113
168
|
### 足りない値を埋める
|
|
114
169
|
|
|
115
170
|
```bash
|
|
116
|
-
npx lines-db fill <path
|
|
171
|
+
npx lines-db fill <path...> [--schema-dir ./schemas] [--fields id,createdAt]
|
|
117
172
|
```
|
|
118
173
|
|
|
119
|
-
`path
|
|
174
|
+
`path`にはデータディレクトリやJSONLファイルを1つ以上指定します。共通スキーマを使う場合は`--schema-dir`で指定してください。省略すると各JSONLファイルと同じディレクトリでスキーマを探します。指定したフィールドに値がない行へ、検証スキーマが補った値を書き込みます。`--fields`を省略すると、各テーブルの主キーが対象です。
|
|
120
175
|
|
|
121
176
|
既存の値は置き換えません。値を補わなかった行は改行コードも含めて変更せず、補った行のキーはスキーマの順に並べます。検証に失敗する行には書き込みません。全行の値を計算してからファイルへ書き込みます。読み込み後に他のツールがファイルを変更していた場合は、どのファイルにも書き込まず、ファイル名を含む`JsonlConflictError`で終了します。
|
|
122
177
|
|
|
@@ -141,6 +196,17 @@ const { filled } = unwrap(
|
|
|
141
196
|
|
|
142
197
|
結果の`tablesWithoutSchema`にはスキーマがないテーブル、`unreadableLines`にはJSONオブジェクトとして読めない行、`unproducedFields`にはどのテーブルでも値を生成できなかったフィールドが入ります。
|
|
143
198
|
|
|
199
|
+
`fillFields()`の`path`には文字列か、空でない文字列配列を渡せます。複数パスでも全ファイルの値を計算し、外部変更を確認してから書き込みます。書き込み中に失敗した場合は、先に書き込んだファイルを復元します。重複して指定したファイルは1回だけ処理します。JSONオブジェクトとして読めない行は、従来どおり変更せずに報告します。
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
unwrap(
|
|
203
|
+
await fillFields({
|
|
204
|
+
path: ['./data/dataset-a', './data/dataset-b'],
|
|
205
|
+
schemaDir: './data',
|
|
206
|
+
}),
|
|
207
|
+
);
|
|
208
|
+
```
|
|
209
|
+
|
|
144
210
|
### ブラウザで閲覧・編集する
|
|
145
211
|
|
|
146
212
|
Studioをプロジェクトに追加して起動します。
|
|
@@ -506,11 +572,11 @@ const db = LinesDB.create({ dataDir: './data' });
|
|
|
506
572
|
|
|
507
573
|
```
|
|
508
574
|
data/
|
|
509
|
-
Item.schema.ts Item.jsonl #
|
|
575
|
+
Item.schema.ts Item.jsonl # スキーマと基本データ
|
|
510
576
|
ItemValuation.schema.ts
|
|
511
577
|
cogs/
|
|
512
|
-
Item.jsonl #
|
|
513
|
-
ItemValuation.jsonl #
|
|
578
|
+
Item.jsonl # 追加のItem行
|
|
579
|
+
ItemValuation.jsonl # 両方のデータセットのItem行を参照
|
|
514
580
|
```
|
|
515
581
|
|
|
516
582
|
```typescript
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ The CLI validates, migrates, fills missing values, and generates types. Install
|
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
|
-
Requires Node.js 22.
|
|
13
|
+
Requires Node.js 22.18.0 or later.
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npm install lines-db
|
|
@@ -71,6 +71,60 @@ npx lines-db validate ./data --verbose
|
|
|
71
71
|
|
|
72
72
|
The command loads the corresponding schema files and checks each row. Validation errors include the file and details of the failure.
|
|
73
73
|
|
|
74
|
+
#### Validate named datasets
|
|
75
|
+
|
|
76
|
+
Define shared data and scenario data in `lines-db.config.json`:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"schemaDir": "./data",
|
|
81
|
+
"base": ["./data"],
|
|
82
|
+
"datasets": {
|
|
83
|
+
"cogs": ["./data/cogs"],
|
|
84
|
+
"sales": ["./data/sales"]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Omit the positional path to read `lines-db.config.json` in the current working directory and validate only `base`.
|
|
90
|
+
`--dataset <name>` adds the named dataset to `base`; repeat the flag to combine several sets in the specified order. `--all-datasets` combines `base` and every dataset in one
|
|
91
|
+
validation run; IDs shared by different scenarios will cause duplicate errors.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npx lines-db validate
|
|
95
|
+
npx lines-db validate --dataset cogs
|
|
96
|
+
npx lines-db validate --dataset cogs --dataset sales
|
|
97
|
+
npx lines-db validate --all-datasets
|
|
98
|
+
npx lines-db validate --config ./seed/lines-db.config.json --dataset cogs
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Use `--config <path>` to select another configuration file. `schemaDir`, `base` and `datasets` are required.
|
|
102
|
+
`base` and each dataset must contain at least one directory; use `datasets: {}` when there are no additional sets.
|
|
103
|
+
Relative paths are resolved from the configuration file's directory. Directories are loaded in base-then-dataset
|
|
104
|
+
order, with each directory loaded only once. Subdirectories are not discovered automatically. Schemas, unique
|
|
105
|
+
constraints and foreign keys are checked across the combined data, and errors identify the original file.
|
|
106
|
+
|
|
107
|
+
Combining `--dataset` with `--all-datasets`, or using configuration options with a positional path, is an error.
|
|
108
|
+
Unknown dataset names and invalid configurations also fail. Existing `validate <path>` commands keep working
|
|
109
|
+
without reading a configuration file. Only the `validate` CLI command uses this configuration.
|
|
110
|
+
|
|
111
|
+
Programs can load the same configuration with `loadDatasetConfig()`:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { LinesDB, loadDatasetConfig } from 'lines-db';
|
|
115
|
+
|
|
116
|
+
const config = await loadDatasetConfig('./lines-db.config.json', {
|
|
117
|
+
datasets: ['cogs', 'sales'],
|
|
118
|
+
});
|
|
119
|
+
const db = LinesDB.create(config);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Omit `datasets` or pass `[]` for base only. An array combines base and the selected sets in array order;
|
|
123
|
+
`'all'` combines base and every set in configuration order. Each directory is loaded once, including symlink aliases.
|
|
124
|
+
Calling `loadDatasetConfig()` without arguments reads `lines-db.config.json` in the current working directory.
|
|
125
|
+
It returns `Promise<DatabaseConfig>` and rejects unreadable or invalid configuration, unknown set names and missing
|
|
126
|
+
selected data directories. A missing `schemaDir` or one pointing to a file is also rejected. Call `db.initialize()` to load and validate the data.
|
|
127
|
+
|
|
74
128
|
### Migrate data
|
|
75
129
|
|
|
76
130
|
Apply a function to each row, validate the result, and save it to the JSONL file.
|
|
@@ -113,10 +167,10 @@ Rows are matched by primary key, or by position when the file has no primary key
|
|
|
113
167
|
### Fill missing values
|
|
114
168
|
|
|
115
169
|
```bash
|
|
116
|
-
npx lines-db fill <path
|
|
170
|
+
npx lines-db fill <path...> [--schema-dir ./schemas] [--fields id,createdAt]
|
|
117
171
|
```
|
|
118
172
|
|
|
119
|
-
|
|
173
|
+
Pass one or more data directories or JSONL files. Use `--schema-dir` for shared schemas; otherwise schemas are loaded next to each JSONL file. The command fills missing fields with values supplied by the validation schema. Without `--fields`, it fills each table's primary key.
|
|
120
174
|
|
|
121
175
|
Existing values are never replaced. Lines that gain no values remain unchanged, including line endings. Updated lines use the schema's key order. Rows that fail validation are not written. All values are computed before writing any files. If another tool changed a file after it was read, the command writes nothing and stops with a `JsonlConflictError` naming that file.
|
|
122
176
|
|
|
@@ -141,6 +195,17 @@ const { filled } = unwrap(
|
|
|
141
195
|
|
|
142
196
|
The result's `tablesWithoutSchema` lists tables without schemas, `unreadableLines` lists lines that are not JSON objects, and `unproducedFields` lists fields for which no table produced a value.
|
|
143
197
|
|
|
198
|
+
`fillFields()` accepts a string or a non-empty readonly array of strings for `path`. Across all paths, every value is computed and every pending write is checked for outside changes before writing. If a write fails, files already written are restored. Overlapping paths process each file only once. Unreadable lines are still reported and left unchanged.
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
unwrap(
|
|
202
|
+
await fillFields({
|
|
203
|
+
path: ['./data/dataset-a', './data/dataset-b'],
|
|
204
|
+
schemaDir: './data',
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
```
|
|
208
|
+
|
|
144
209
|
### Browse and Edit in the Browser
|
|
145
210
|
|
|
146
211
|
Install Studio in the project and start it with the CLI.
|
|
@@ -397,7 +462,7 @@ The database records each JSONL file's contents when reading or writing it. If a
|
|
|
397
462
|
const result = await db.transaction((tx) => unwrap(tx.update('users', { age: 31 }, { id: 1 })));
|
|
398
463
|
|
|
399
464
|
if (!result.ok && result.error.name === 'JsonlConflictError') {
|
|
400
|
-
console.log(`${(result.error as JsonlConflictError).file}
|
|
465
|
+
console.log(`${(result.error as JsonlConflictError).file} has changed on disk`);
|
|
401
466
|
}
|
|
402
467
|
```
|
|
403
468
|
|