@lines-db/studio 0.16.6 → 0.16.8
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 +28 -0
- package/README.ja.md +26 -0
- package/README.md +26 -0
- package/dist/index.d.mts +16 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +202 -167
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/ui/assets/index-BOXnVdiV.js +91 -0
- package/ui/assets/index-DqhpJkVr.css +2 -0
- package/ui/index.html +2 -2
- package/ui/assets/index-CM-ZFnfz.js +0 -91
- package/ui/assets/index-DB7uh2ec.css +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @lines-db/studio
|
|
2
2
|
|
|
3
|
+
## 0.16.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2e3c0ef: Add `createStudioHandler`, which resolves to `{ token, fetch(request), close() }`. Its `fetch` is a Web-standard `(request: Request) => Promise<Response>` handler, so the studio can be served from a server of your own and framed by a page of the same origin. `startStudioServer` is now a thin `node:http` wrapper around it and behaves as before.
|
|
8
|
+
|
|
9
|
+
The page asks for the API with addresses relative to its own, so it works below any path, as long as it is opened with a trailing slash. `frameAncestors: 'self'` lets a page of the same origin frame the studio (`'none'` by default), and `requestHeaders` has the page send the given headers with every API request except the event stream, which an `EventSource` cannot give headers, for a host that checks them before passing a request on. The values are written into the page, so they are not secrets from whoever can load it. A write is rejected when its `Origin` is present and not the origin of the request URL.
|
|
10
|
+
|
|
11
|
+
## 0.16.7
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 1a510a8: An inserted row's field the validation schema transforms is now written to the JSONL file as it was given, not as the schema made it. With a schema that turns the `code` `"1"` into `"ORD-1"` (a TailorDB `create` hook does this), `insert('orders', { id: 3, code: '1' })` used to write `"ORD-1"`, and the next load of the file turned it into `"ORD-ORD-1"`. It now writes `"1"`, as `update` already did, so the file holds the side a seed file holds and the schema applies its transformation once, on load. This applies to `insert` and `batchInsert` when `writeFilledValues` is `'primaryKey'` (the studio's default), except for fields named in `writeBackFields` and foreign-key columns a `CASCADE` or `SET NULL` action can change, and values a line cannot hold, such as a bigint, which are still written as the database has them; with `'all'` every value the schema gives is still written.
|
|
16
|
+
|
|
17
|
+
`findWithDefaults()` now also returns `input` for each row: the row as its line holds it, the values before the schema transformed them, without the fields the schema filled in. The studio's rows response carries it as `inputs`, and the studio can show each value as its input, its output (read-only), or both, the input marked `in` above the output marked `out`; the input is what a cell and the form edit.
|
|
18
|
+
|
|
19
|
+
Updating one field of a row no longer rewrites the other fields of its line with the values the schema made of them: with the line `{"id":1,"code":"a","note":"n"}`, changing only `note` used to write `"code":"ORD-a"`, which the schema turned into `"ORD-ORD-a"` on the next load. With `writeFilledValues: 'primaryKey'`, a field the line holds and nothing set now keeps the line's value; `'all'` still writes the value the schema gives.
|
|
20
|
+
|
|
21
|
+
A write-back finds the line of a row again by the primary key the schema makes of it, so a table whose schema transforms its primary key keeps the keys its lines hold, and a table without a primary key, and a row whose primary key was changed, find it by the position its line had when the file was read, kept up to date as rows are added and removed. The studio edits a column whose lines hold another type than the schema makes in its Input view, and every new row, as text when the lines hold strings and as JSON otherwise. A rowid change made by an ON UPDATE CASCADE, or by raw SQL, carries the row's recorded position with it, and a row with a recorded position keeps its line even when its key moves onto another row's old key.
|
|
22
|
+
|
|
23
|
+
A line's fields that the schema does not know, and the fields a migration `transform` set, now stay with their own row when a table's integer primary keys are not in order in the file: with the lines `{"id":3,"extra":"x3"}` and `{"id":1,"extra":"x1"}`, updating row 1 used to swap the two `extra` values.
|
|
24
|
+
|
|
25
|
+
A row whose key changes while a write-back of its table is in progress keeps its line, and the log of rowid changes works with the SQLite that Bun ships, which refuses a qualified table name in a trigger.
|
|
26
|
+
|
|
27
|
+
`update` now stores what the validation schema makes of each value it is given, as `insert` does: updating `code` to `"b"` used to leave `"b"` in the database, so the studio's Output view and `find()` showed `"b"` instead of `"ORD-b"` until the file was loaded again. The line still holds `"b"`.
|
|
28
|
+
- Updated dependencies [1a510a8]
|
|
29
|
+
- lines-db@0.19.2
|
|
30
|
+
|
|
3
31
|
## 0.16.6
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/README.ja.md
CHANGED
|
@@ -35,6 +35,8 @@ JSONオブジェクトはキーごと、配列は要素ごとに入力欄を表
|
|
|
35
35
|
|
|
36
36
|
保存するのは、明示的に指定したフィールドと生成された主キーです。それ以外のスキーマの既定値はファイルに書きません。既定値も含めて保存するには`--write-filled-values all`を使います。詳しくは[書き戻しの挙動](https://github.com/toiroakr/lines-db/blob/main/lib/README.ja.md#スキーマが補う値)を参照してください。
|
|
37
37
|
|
|
38
|
+
スキーマが値を変換する場合(`create`フックが`"1"`を`"ORD-1"`にするなど)、グリッドに**Input / Output / Both**の切り替えが出ます。既定のInputはファイルが持つ値で、セルで編集できます。Outputはスキーマが変換した値で、編集できません。ファイルの値が、スキーマが作る値と別の型の列(真偽値の列の`"yes"`など)は、Input表示では、ファイルの値が文字列ならテキストとして、数値やオブジェクトなど文字列以外を含むならJSONとして編集します。新しい行は、表示に関わらず、この入力側の型で入力します。スキーマが名前を変える(`backward`)か捨てるために、ファイルにだけある列は、Input表示に**file only**として、スキーマがほかの列から作る列は**made by the schema**として表示し、既存の行ではどちらも編集できません。新しい行には、file only の列を含めてファイルが持つ列を入力し、スキーマが作る列は入力しません。Bothは、編集できる入力に**in**、その下に出力を**out**の印を付けて縦に並べます。既定の`--write-filled-values primaryKey`では保存で入力を書きます。ただし`writeBackFields`で指定したフィールド、`CASCADE`や`SET NULL`で変わりうる外部キー列、bigintのように行に書けない値は、データベースの値を書きます。`all`では変換後の値を書きます。
|
|
39
|
+
|
|
38
40
|
### 検証エラーのある行を直す
|
|
39
41
|
|
|
40
42
|
検証エラーのあるテーブルは、元のファイルの内容を表示し、該当する行とセルに印を付けます。修正を保存すると、その行を検証して1行だけを書き換えます。他の行は変更しません。全行の検証が通ると、通常のテーブルとして読み込みます。
|
|
@@ -89,4 +91,28 @@ console.log(studio.url);
|
|
|
89
91
|
await studio.close();
|
|
90
92
|
```
|
|
91
93
|
|
|
94
|
+
## 別のサーバーから配信する
|
|
95
|
+
|
|
96
|
+
`createStudioHandler`は`{ token, fetch(request), close() }`を返します。`fetch`はWeb標準のハンドラー`(request: Request) => Promise<Response>`で、サーバーを起動する代わりに、自前のサーバーへ組み込めます。ハンドラーはHostも、組み込むパスも検査しません。好きなパスに組み込み、受け取るURLからそのパスを取り除き、Hostは呼び出し側で検査してください。
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
import { createStudioHandler } from '@lines-db/studio';
|
|
100
|
+
|
|
101
|
+
const studio = await createStudioHandler({
|
|
102
|
+
dataDir: './data',
|
|
103
|
+
frameAncestors: 'self',
|
|
104
|
+
requestHeaders: { 'x-studio-host': 'embedded' },
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ハンドラーは起動時に1回だけ作り、リクエストごとに`studio.fetch`へ渡します。
|
|
108
|
+
// `close()`はファイル監視とイベントストリームを終了させ、再開できません。終了時にだけ呼びます。
|
|
109
|
+
const response = await studio.fetch(request);
|
|
110
|
+
await studio.close();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- ページはAPIを自身からの相対アドレスで呼ぶため、末尾のスラッシュ付きで開けばどのパスでも動きます。
|
|
114
|
+
- `frameAncestors`の既定は`'none'`で、どのページもStudioをフレームに入れられません。`'self'`にすると同じオリジンのページがフレームに入れられます。
|
|
115
|
+
- `requestHeaders`は、リアルタイム更新のストリームを除くすべてのAPIリクエストに、ページが付けて送ります。リクエストを転送する前にヘッダーを検査する組み込み先のためのものです。ストリームはEventSourceが要求するためヘッダーを付けられず、組み込み先は`GET /api/events`をヘッダーなしで通す必要があります。値はページに書き込まれるため、ページを読み込める人には秘密になりません。
|
|
116
|
+
- 書き込みは、`Origin`ヘッダーがあり、リクエストURLのオリジンと一致しない場合に拒否します。`Origin`がないリクエストはこのチェックを通り、書き込みには引き続きトークンと`application/json`が必要です。
|
|
117
|
+
|
|
92
118
|
TypeScriptのスキーマファイルには`amaro/transform`などのローダーが必要です。CLIは自動で登録します。コードから起動する場合は、スキーマを読み込む前にローダーを登録してください。
|
package/README.md
CHANGED
|
@@ -35,6 +35,8 @@ Values supplied by the schema are dimmed and marked **default**. **Remove field*
|
|
|
35
35
|
|
|
36
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
37
|
|
|
38
|
+
When the schema transforms a value (a `create` hook turning `"1"` into `"ORD-1"`), the grid shows an **Input / Output / Both** switch. Input, the default, is what the file holds and what a cell edits; Output is what the schema makes of it and is read-only; a column whose lines hold values of another type than the schema makes (such as `"yes"` for a boolean) is edited in the Input view as text when the lines hold strings, and as JSON when they hold other values, such as numbers or objects; a new row is always filled in by these input types; a field only the lines hold, which the schema renames (a `backward` transformation) or removes, is shown in the Input view marked **file only**, and a field the schema makes from others is marked **made by the schema**, both read-only for a row of the file; a new row is given the fields the file holds, file only ones included, and not those the schema makes; Both shows the editable input marked **in** with the output marked **out** under it. With the default `--write-filled-values primaryKey`, a save writes the input, except for fields named in `writeBackFields`, foreign-key columns a `CASCADE` or `SET NULL` action can change, and values a line cannot hold, such as a bigint, which are written as the database has them; with `all` it writes the transformed value.
|
|
39
|
+
|
|
38
40
|
### Fix invalid rows
|
|
39
41
|
|
|
40
42
|
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.
|
|
@@ -89,4 +91,28 @@ console.log(studio.url);
|
|
|
89
91
|
await studio.close();
|
|
90
92
|
```
|
|
91
93
|
|
|
94
|
+
## Serve from another server
|
|
95
|
+
|
|
96
|
+
`createStudioHandler` resolves to `{ token, fetch(request), close() }`. Its `fetch` is a Web-standard handler, `(request: Request) => Promise<Response>`, to mount in a server of your own instead of starting one. It checks neither the Host nor which path it is mounted under, so mount it at a path of your choice, strip that path from the URL it receives, and check the Host yourself.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
import { createStudioHandler } from '@lines-db/studio';
|
|
100
|
+
|
|
101
|
+
const studio = await createStudioHandler({
|
|
102
|
+
dataDir: './data',
|
|
103
|
+
frameAncestors: 'self',
|
|
104
|
+
requestHeaders: { 'x-studio-host': 'embedded' },
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Create the handler once at startup and pass every request to `studio.fetch`.
|
|
108
|
+
// `close()` stops the file watchers and ends the event streams for good, so call it only at shutdown.
|
|
109
|
+
const response = await studio.fetch(request);
|
|
110
|
+
await studio.close();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- The page requests the API with addresses relative to its own, so it works at any path, as long as the page is opened with a trailing slash.
|
|
114
|
+
- `frameAncestors` is `'none'` by default, which keeps every page from framing the studio. `'self'` lets a page of the same origin frame it.
|
|
115
|
+
- `requestHeaders` are sent by the page with every API request except the live-reload stream, for a host that checks them before passing a request on. The stream is requested by an event source, which cannot send headers, so the host has to let `GET /api/events` through without them. The values are written into the page, so they are not secrets from anyone who can load it.
|
|
116
|
+
- A write is rejected when its `Origin` header is present and is not the origin of the request URL. A request without `Origin` passes this check, and a write still needs the token and `application/json`.
|
|
117
|
+
|
|
92
118
|
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.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
import { WriteFilledValues } from "lines-db";
|
|
2
|
-
interface
|
|
2
|
+
interface StudioHandlerOptions {
|
|
3
3
|
dataDir: string | string[];
|
|
4
4
|
schemaDir?: string;
|
|
5
5
|
/** Directory holding the built page. Defaults to the one shipped with the package */
|
|
6
6
|
uiDir?: string;
|
|
7
7
|
/** Which values the schema fills in a save writes into the file. Defaults to 'primaryKey' */
|
|
8
8
|
writeFilledValues?: WriteFilledValues;
|
|
9
|
+
/** Which pages may frame the studio: none, or those of its own origin. Defaults to 'none' */
|
|
10
|
+
frameAncestors?: 'none' | 'self';
|
|
11
|
+
/** Headers the page sends with every API request, for a host that checks them before passing the request on */
|
|
12
|
+
requestHeaders?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
interface StudioServerOptions extends StudioHandlerOptions {
|
|
9
15
|
host?: string;
|
|
10
16
|
port?: number;
|
|
11
17
|
}
|
|
18
|
+
interface StudioHandler {
|
|
19
|
+
/** The token every API request presents, generated at start-up and handed to the page */
|
|
20
|
+
token: string;
|
|
21
|
+
/** Answers a request whose path is relative to the studio's root; checking the Host is left to the caller */
|
|
22
|
+
fetch(request: Request): Promise<Response>;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
12
25
|
interface StudioServer {
|
|
13
26
|
url: string;
|
|
14
27
|
/** The token every API request presents, generated at start-up and handed to the page */
|
|
15
28
|
token: string;
|
|
16
29
|
close(): Promise<void>;
|
|
17
30
|
}
|
|
31
|
+
export declare function createStudioHandler(options: StudioHandlerOptions): Promise<StudioHandler>;
|
|
18
32
|
export declare function startStudioServer(options: StudioServerOptions): Promise<StudioServer>;
|
|
19
|
-
export type { StudioServer, StudioServerOptions };
|
|
33
|
+
export type { StudioHandler, StudioHandlerOptions, StudioServer, StudioServerOptions };
|
|
20
34
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/server.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/server.ts"],"mappings":";UAiCiB;EACf;EACA;;EAEA;;EAEA,oBAAoB;;EAEpB;;EAEA,iBAAiB;;UAGF,4BAA4B;EAC3C;EACA;;UAGe;;EAEf;;EAEA,MAAM,SAAS,UAAU,QAAQ;EACjC,SAAS;;UAGM;EACf;;EAEA;EACA,SAAS;;wBAwBW,oBAAoB,SAAS,uBAAuB,QAAQ;wBA4mB5D,kBAAkB,SAAS,sBAAsB,QAAQ"}
|