@lines-db/studio 0.0.0-stage → 0.16.2

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,32 @@
1
+ # @lines-db/studio
2
+
3
+ ## 0.16.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [8f9912e]
8
+ - lines-db@0.18.0
9
+
10
+ ## 0.16.1
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [d711b36]
15
+ - lines-db@0.17.0
16
+
17
+ ## 0.16.0
18
+
19
+ ### Minor Changes
20
+
21
+ - 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.
22
+
23
+ Rename the core package from @toiroakr/lines-db to lines-db. Update imports and installation commands to use lines-db.
24
+
25
+ Update CLI imports, generated types, editor integration, and documentation for the new package names. Publish both packages from the release workflow.
26
+
27
+ Use the current TypeScript 7.1 synchronous API for Studio schema inspection and verify declared columns with TypeScript 5 and 7.1 in CI.
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [19259c2]
32
+ - lines-db@0.16.0
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.
package/README.ja.md ADDED
@@ -0,0 +1,92 @@
1
+ # @lines-db/studio
2
+
3
+ [English](./README.md)
4
+
5
+ Studioは[lines-db](https://github.com/toiroakr/lines-db)のブラウザ用エディタです。ローカルサーバーでJSONLのテーブルを読み込み、編集内容をスキーマで検証してから保存します。
6
+
7
+ ## 起動する
8
+
9
+ Node.js 22.12.0以降が必要です。プロジェクトに両方のパッケージをインストールします。
10
+
11
+ ```bash
12
+ npm install -D lines-db @lines-db/studio
13
+ npx lines-db studio ./data --open
14
+ ```
15
+
16
+ 既定のURLは`http://127.0.0.1:4848`です。`--port`でポートを変更し、`--port 0`で空いているポートを選べます。`--open`を指定するとブラウザが開きます。終了するにはCtrl+Cを押してください。
17
+
18
+ 編集するテーブルには主キーが必要です。`id`列、またはスキーマの`primaryKey`を使い、全行に値が入っている必要があります。主キーがないテーブルは読み取り専用です。
19
+
20
+ ## 編集と保存
21
+
22
+ テーブルを選ぶと、行と列を表形式で表示します。ヘッダー右端のボタンで行フォームを開くと、1件のレコードをまとめて編集できます。フォームの端をドラッグすると幅を変えられます。フォームの表示中は行をクリックして選択し、セルをダブルクリックして編集します。非表示のときは行をダブルクリックするとフォームが開きます。外部キーの入力欄から参照先の行を開けます。
23
+
24
+ 行を追加するには**Add record**を使います。主キーを含む各列の入力欄があり、入力中に行全体を検証します。空の欄は行に含めず、スキーマの既定値を使います。行を選択すると削除できます。
25
+
26
+ 編集・追加・削除は、**Save N changes**を押すまで未保存のままです。保存時に1つのトランザクションでまとめて書き込みます。**Discard**で未保存の変更を破棄できます。検証に失敗した場合はエラーを表示し、修正できるように変更内容を残します。通常の保存ではテーブルのJSONLファイル全体を書き直すため、編集していない行の書式も変わることがあります。
27
+
28
+ ### フィールドとJSONの編集
29
+
30
+ セルの入力値は入力中に検証し、該当フィールドの下にエラーを表示します。**Set**は値を未保存の変更に加える操作です。ファイルへの保存は行いません。Enter、JSONエディタではCmd/Ctrl+Enterで値を確定できます。テキスト欄は内容に合わせて高さが変わり、Shift+Enterで改行できます。
31
+
32
+ JSONオブジェクトはキーごと、配列は要素ごとに入力欄を表示します。オブジェクトの配列は要素ごとのブロックになります。ブロックをJSONエディタに切り替えると、テキストで編集できます。構文エラーは該当位置に表示します。コメントと末尾のカンマも入力できますが、値の確定時に取り除きます。
33
+
34
+ スキーマが補った値は薄い文字で表示し、**default**の印を付けます。**Remove field**でフィールドをファイルから省略し、スキーマの既定値に戻せます。**Set null**ではnullを設定します。これらの操作はスキーマが許す場合だけ表示します。フィールドの削除、nullの設定、JSON内のキーの追加・削除を許すかどうかは、サンプル行を検証して確認します。
35
+
36
+ 保存するのは、明示的に指定したフィールドと生成された主キーです。それ以外のスキーマの既定値はファイルに書きません。既定値も含めて保存するには`--write-filled-values all`を使います。詳しくは[書き戻しの挙動](https://github.com/toiroakr/lines-db/blob/main/lib/README.ja.md#スキーマが補う値)を参照してください。
37
+
38
+ ### 検証エラーのある行を直す
39
+
40
+ 検証エラーのあるテーブルは、元のファイルの内容を表示し、該当する行とセルに印を付けます。修正を保存すると、その行を検証して1行だけを書き換えます。他の行は変更しません。全行の検証が通ると、通常のテーブルとして読み込みます。
41
+
42
+ 検証エラーが残っている間は、行を追加・削除できません。スキーマが受け付けないフィールドには**not in schema**の印を付けます。列見出しから、そのフィールドを全行で削除できます。
43
+
44
+ ## スキーマを見る
45
+
46
+ **Schema**で列、外部キー、インデックスを表示します。列には型と、省略やnullの設定ができるかを示します。外部キーから参照先テーブルのスキーマを開けます。開いているスキーマは`#orders?schema=customers`のようにURLへ反映されます。
47
+
48
+ 列の宣言は、スキーマのStandard Schemaの`types`から読み取ります。プロジェクトにインストールされたTypeScriptを使い、5・6ではCompiler API、7.1以降ではCorsa APIに対応しています。TypeScriptがない場合や型の宣言がない場合は、行の値から列を推論し、その旨を表示します。
49
+
50
+ **Code**タブには、ディスク上のスキーマファイルを構文ハイライト付きで表示します。検証エラーのあるテーブルではコードだけを表示します。配色はヘッダーでOSの設定・ライト・ダークから選べます。
51
+
52
+ ## 共通スキーマとデータセット
53
+
54
+ スキーマとデータが別の場所にある場合は、`--schema-dir`を指定します。
55
+
56
+ ```bash
57
+ npx lines-db studio seed/data/cogs --schema-dir seed/data
58
+ ```
59
+
60
+ 複数のディレクトリをまとめて読み込むには、`--data-dir`を繰り返します。位置引数との併用も可能です。複数ディレクトリを指定する場合は`--schema-dir`が必要です。
61
+
62
+ ```bash
63
+ npx lines-db studio --data-dir seed/data --data-dir seed/data/cogs --schema-dir seed/data
64
+ ```
65
+
66
+ 検証、列の宣言、外部キー、Schema画面では共通スキーマを使います。一意制約と外部キーは、選んだデータセット全体で検証します。
67
+
68
+ 更新・削除は各行の元のファイルへ反映します。**Add record**で保存先のディレクトリを選べます。テーブルのファイルがなければ作成します。保存途中で失敗した場合は、書き込み済みのファイルを元に戻そうとします。
69
+
70
+ ## 他のツールでファイルを変更した場合
71
+
72
+ Studioはディスク上のファイルを監視します。未保存の編集がなければ変更後のデータを読み直し、編集が残っていれば通知を表示します。
73
+
74
+ 保存前にスキーマの変更を確認し、変更されていれば読み直して検証します。書き込み対象のファイルが変更されていた場合は、何も書き込まずに保存を中止します。ファイル名を表示し、テーブルを読み直します。`CASCADE`や`SET NULL`などの外部キーの操作で変更されるテーブルも対象です。無関係なテーブルのファイルの変更では保存を中止しません。
75
+
76
+ ## ローカルサーバー
77
+
78
+ サーバーは起動時にトークンを生成し、配信するページに渡します。ページはトークンを`sessionStorage`に保存し、APIリクエストに付けます。トークンのないリクエストには401を返します。他のサイトのページからStudioのページを読んでトークンを取得することはできません。
79
+
80
+ サーバーは自身のローカルホスト宛てのリクエストを受け付けます。書き込みはStudioのページから送られた、`application/json`のリクエストに限ります。
81
+
82
+ ## コードから起動する
83
+
84
+ ```js
85
+ import { startStudioServer } from '@lines-db/studio';
86
+
87
+ const studio = await startStudioServer({ dataDir: './data', port: 4848 });
88
+ console.log(studio.url);
89
+ await studio.close();
90
+ ```
91
+
92
+ TypeScriptのスキーマファイルには`amaro/transform`などのローダーが必要です。CLIは自動で登録します。コードから起動する場合は、スキーマを読み込む前にローダーを登録してください。
package/README.md CHANGED
@@ -1,3 +1,92 @@
1
- # Temporary Holding Version
1
+ # @lines-db/studio
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [日本語](./README.ja.md)
4
+
5
+ Studio is a browser editor for [lines-db](https://github.com/toiroakr/lines-db). It runs a local server, reads JSONL tables, and validates edits against their schemas before saving.
6
+
7
+ ## Start Studio
8
+
9
+ Requires Node.js 22.12.0 or later. Install both packages in the project.
10
+
11
+ ```bash
12
+ npm install -D lines-db @lines-db/studio
13
+ npx lines-db studio ./data --open
14
+ ```
15
+
16
+ The default URL is `http://127.0.0.1:4848`. Use `--port` to change the port, or `--port 0` to pick a free one. `--open` opens the browser. Press Ctrl+C to stop the server.
17
+
18
+ A table needs a primary key with a value on every row to be editable. Studio uses the `id` column or the schema's `primaryKey` definition. Tables without a primary key are read-only.
19
+
20
+ ## Edit and save
21
+
22
+ Select a table to see its rows and columns. The row form beside the grid edits all fields of a record. Open it from the button on the right of the header, and drag its edge to resize it. While the form is open, click a row to select it or double-click a cell to edit it. When the form is hidden, double-click a row to open it. Foreign key fields link to the referenced row.
23
+
24
+ Use **Add record** to create a row, or select rows to delete them. The dialog includes the primary key and checks the whole row as you enter values. Empty fields are omitted so the schema can fill them in.
25
+
26
+ Edits, additions, and deletions remain pending until **Save N changes** writes them in one transaction. **Discard** removes the pending changes. If validation fails, Studio shows the errors and keeps the edits for correction. A normal save rewrites the table's JSONL file, so formatting on unchanged lines can also change.
27
+
28
+ ### Fields and JSON values
29
+
30
+ The cell editor validates values as you type and shows errors below the affected field. **Set** adds the value to the pending changes; it does not save the file. Press Enter to set a value, or Cmd/Ctrl+Enter in the JSON editor. Text fields grow to fit their contents, and Shift+Enter inserts a line break.
31
+
32
+ JSON objects have an input for each key, arrays have one for each item, and arrays of objects have a block for each item. Switch a block to the JSON editor to edit the value as text. Syntax errors are marked in place. Comments and trailing commas are accepted while editing and removed when you set the value.
33
+
34
+ Values supplied by the schema are dimmed and marked **default**. **Remove field** omits a field from the file so the schema can supply its value again. **Set null** sets it to null. Studio offers these actions only when the schema accepts them. It checks a sample row to determine whether a field can be removed or set to null, or whether keys can be added or removed within a JSON value.
35
+
36
+ By default, saves write explicitly supplied fields and generated primary keys. Other schema defaults remain omitted. Use `--write-filled-values all` to write every value, including defaults. See [write-back behavior](https://github.com/toiroakr/lines-db/blob/main/lib/README.md#values-the-schema-fills-in) for details.
37
+
38
+ ### Fix invalid rows
39
+
40
+ When a table contains rows that fail validation, Studio displays the original file and marks the affected rows and cells. Saving a correction validates the row and rewrites only that line. Other lines remain unchanged. Once every row passes validation, Studio loads the table normally.
41
+
42
+ Adding and deleting rows is disabled while the table has validation errors. Unknown fields rejected by the schema are marked **not in schema**; the column header can remove that field from every row.
43
+
44
+ ## Inspect schemas
45
+
46
+ **Schema** shows columns, foreign keys, and indexes. Each column lists its type and whether it is optional or nullable. Foreign keys link to the referenced table's schema. The URL records the open schema, for example `#orders?schema=customers`.
47
+
48
+ Studio reads declared columns from the schema's Standard Schema `types` using the TypeScript installed in the project. It supports the compiler API in TypeScript 5 and 6 and the Corsa API in TypeScript 7.1 and later. If TypeScript is unavailable or the schema does not declare types, Studio infers columns from the rows and labels them accordingly.
49
+
50
+ The **Code** tab shows the schema file as stored on disk, with syntax highlighting. Tables with invalid rows show only the code. The header also lets you choose system, light, or dark colors.
51
+
52
+ ## Shared schemas and data sets
53
+
54
+ Use `--schema-dir` when the schema files live separately from the data.
55
+
56
+ ```bash
57
+ npx lines-db studio seed/data/cogs --schema-dir seed/data
58
+ ```
59
+
60
+ Repeat `--data-dir` to combine several data directories. A positional directory can also be combined with `--data-dir`. Multiple directories require `--schema-dir`.
61
+
62
+ ```bash
63
+ npx lines-db studio --data-dir seed/data --data-dir seed/data/cogs --schema-dir seed/data
64
+ ```
65
+
66
+ Validation, declared columns, foreign keys, and the Schema dialog use the shared schemas. Unique constraints and foreign keys are checked across all selected data sets.
67
+
68
+ Updates and deletions go back to each row's source file. In **Add record**, choose the destination directory; Studio creates the table file there if needed. If a save fails after writing a file, Studio attempts to restore the files it already wrote.
69
+
70
+ ## Changes made outside Studio
71
+
72
+ Studio watches the files on disk. With no pending edits, it reloads changed data automatically. With pending edits, it shows a notice.
73
+
74
+ Before saving, Studio reloads changed schemas and validates against them. If a file that the save would write has changed, the save stops, names the file, and reloads the tables without writing. This includes tables affected by foreign key actions such as `CASCADE` or `SET NULL`. Changes to unrelated table files do not stop the save.
75
+
76
+ ## Local server
77
+
78
+ The server creates a token at startup and includes it in the page. The page stores it in `sessionStorage` and sends it with API requests. Requests without the token receive a 401 response. Pages on other sites cannot read the Studio page to obtain the token.
79
+
80
+ The server accepts requests addressed to its local host. Writes must come from the Studio page with an `application/json` content type.
81
+
82
+ ## Start from code
83
+
84
+ ```js
85
+ import { startStudioServer } from '@lines-db/studio';
86
+
87
+ const studio = await startStudioServer({ dataDir: './data', port: 4848 });
88
+ console.log(studio.url);
89
+ await studio.close();
90
+ ```
91
+
92
+ TypeScript schema files require a loader such as `amaro/transform`. The lines-db CLI registers it automatically. When starting from code, register a loader before loading the schemas.
@@ -0,0 +1,22 @@
1
+ import { WriteFilledValues } from "lines-db";
2
+ //#region src/server.d.ts
3
+ interface StudioServerOptions {
4
+ dataDir: string | string[];
5
+ schemaDir?: string;
6
+ /** Directory holding the built page. Defaults to the one shipped with the package */
7
+ uiDir?: string;
8
+ /** Which values the schema fills in a save writes into the file. Defaults to 'primaryKey' */
9
+ writeFilledValues?: WriteFilledValues;
10
+ host?: string;
11
+ port?: number;
12
+ }
13
+ interface StudioServer {
14
+ url: string;
15
+ /** The token every API request presents, generated at start-up and handed to the page */
16
+ token: string;
17
+ close(): Promise<void>;
18
+ }
19
+ export declare function startStudioServer(options: StudioServerOptions): Promise<StudioServer>;
20
+ //#endregion
21
+ export type { StudioServer, StudioServerOptions };
22
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/server.ts"],"mappings":";;UA8BiB;EACf;EACA;;EAEA;;EAEA,oBAAoB;EACpB;EACA;;UAGe;EACf;;EAEA;EACA,SAAS;;wBAwBW,kBAAkB,SAAS,sBAAsB,QAAQ"}