@notionhq/custom-blocks-dev-shell 0.1.73 → 0.1.74
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/README.md +27 -33
- package/docs/bindings.md +31 -36
- package/docs/data-sources.md +37 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# Custom blocks dev shell
|
|
2
2
|
|
|
3
|
-
The dev shell runs custom blocks in a local mock Notion host. It provides sample
|
|
4
|
-
|
|
5
|
-
`ntn workers deploy`.
|
|
3
|
+
The dev shell runs custom blocks in a local mock Notion host. It provides sample data that blocks
|
|
4
|
+
can use. It builds the worker and previews its custom blocks. Use it before `ntn workers deploy`.
|
|
6
5
|
|
|
7
6
|
## Usage
|
|
8
7
|
|
|
@@ -12,11 +11,10 @@ Run this command from your worker project:
|
|
|
12
11
|
ntn workers customblocks dev
|
|
13
12
|
```
|
|
14
13
|
|
|
15
|
-
Open the shell URL printed by the command. Blocks hot reload when their source
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
run leaves the others active.
|
|
14
|
+
Open the shell URL printed by the command. Blocks hot reload when their source files change. Each
|
|
15
|
+
run uses one port for the shell and all blocks. The default is `9873`. If that port is occupied, the
|
|
16
|
+
launcher selects the next available port. You can start multiple runs without choosing a port for
|
|
17
|
+
each run. Stopping one run leaves the others active.
|
|
20
18
|
|
|
21
19
|
The shell and blocks keep separate browser origins through localhost subdomains:
|
|
22
20
|
|
|
@@ -24,42 +22,38 @@ The shell and blocks keep separate browser origins through localhost subdomains:
|
|
|
24
22
|
- `http://chart.localhost:9873`: chart block
|
|
25
23
|
- `http://table.localhost:9873`: table block
|
|
26
24
|
|
|
27
|
-
Block capability keys, such as `"chart"` in `worker.customBlock("chart")`, become
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
Block capability keys, such as `"chart"` in `worker.customBlock("chart")`, become lowercase hostname
|
|
26
|
+
labels. Unsupported characters become hyphens. The launcher shortens long labels and adds numeric
|
|
27
|
+
suffixes when keys conflict.
|
|
30
28
|
|
|
31
|
-
Chrome and Firefox resolve these localhost subdomains without setup. Older macOS
|
|
32
|
-
|
|
33
|
-
([WebKit issue](https://bugs.webkit.org/show_bug.cgi?id=160504)). The launcher does
|
|
34
|
-
|
|
29
|
+
Chrome and Firefox resolve these localhost subdomains without setup. Older macOS Safari versions may
|
|
30
|
+
need hostname setup. macOS 26 Tahoe fixed this resolution
|
|
31
|
+
([WebKit issue](https://bugs.webkit.org/show_bug.cgi?id=160504)). The launcher does not change
|
|
32
|
+
hostnames on your system or install certificates.
|
|
35
33
|
|
|
36
|
-
Install `@notionhq/custom-blocks-dev-shell` in the worker's `devDependencies`
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
each time.
|
|
34
|
+
Install `@notionhq/custom-blocks-dev-shell` in the worker's `devDependencies` to pin its version.
|
|
35
|
+
This also makes the reference docs available in `node_modules`. If you do not install it, the CLI
|
|
36
|
+
fetches the latest version each time.
|
|
40
37
|
|
|
41
38
|
### Error surface
|
|
42
39
|
|
|
43
|
-
The preview shows an error surface when a block cannot initialize or an
|
|
44
|
-
|
|
45
|
-
error details or `Retry` to restart the preview.
|
|
40
|
+
The preview shows an error surface when a block cannot initialize or an uncaught runtime error
|
|
41
|
+
prevents it from rendering. Use `Copy` to copy the error details or `Retry` to restart the preview.
|
|
46
42
|
|
|
47
43
|
### Options
|
|
48
44
|
|
|
49
45
|
- `[path]`: Select a worker directory instead of using the current directory.
|
|
50
|
-
- `--port <port>`: Require this port for the whole run. If occupied, the command
|
|
51
|
-
|
|
52
|
-
- `-- --bind <capabilityKey>.<dataSourceKey>=<sampleDataFileName>`: Choose sample data.
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
- `--port <port>`: Require this port for the whole run. If occupied, the command fails with an
|
|
47
|
+
explanation. Omit this option to enable automatic fallback.
|
|
48
|
+
- `-- --bind <capabilityKey>.<dataSourceKey>=<sampleDataFileName>`: Choose sample data. Repeat for
|
|
49
|
+
multiple slots. The `--` is required for forwarding through `ntn`. See
|
|
50
|
+
[bindings](./docs/bindings.md) for an example.
|
|
55
51
|
|
|
56
52
|
## Documentation
|
|
57
53
|
|
|
58
54
|
These docs ship with the package and are available from `node_modules`:
|
|
59
55
|
|
|
60
|
-
- [`docs/bindings.md`](./docs/bindings.md): Connect blocks to data sources.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
in `data/*.json`. The page covers value shapes, validation, and files
|
|
65
|
-
generated from worker schemas.
|
|
56
|
+
- [`docs/bindings.md`](./docs/bindings.md): Connect blocks to data sources. The page covers
|
|
57
|
+
automatic mapping, compatibility, initialization, and live rebinding.
|
|
58
|
+
- [`docs/data-sources.md`](./docs/data-sources.md): Define local data sources in `data/*.json`. The
|
|
59
|
+
page covers value shapes, validation, and files generated from worker schemas.
|
package/docs/bindings.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# Dev shell bindings
|
|
2
2
|
|
|
3
|
-
The dev shell previews your worker's custom blocks with local data from
|
|
4
|
-
|
|
3
|
+
The dev shell previews your worker's custom blocks with local data from `data/*.json`. Each data
|
|
4
|
+
source selects its file in this order:
|
|
5
5
|
|
|
6
6
|
1. The explicit `--bind` selection.
|
|
7
7
|
2. `data/worker_<dataSourceKey>.json`, if it exists.
|
|
8
8
|
3. `data/<dataSourceKey>.json`, if it exists.
|
|
9
|
-
4. Otherwise, it stays unbound. The shell starts, but the block cannot initialize
|
|
10
|
-
|
|
9
|
+
4. Otherwise, it stays unbound. The shell starts, but the block cannot initialize until you connect
|
|
10
|
+
the source in **Data**.
|
|
11
11
|
|
|
12
|
-
An invalid explicit selection stops startup instead of falling back to another
|
|
13
|
-
|
|
12
|
+
An invalid explicit selection stops startup instead of falling back to another file. An empty file
|
|
13
|
+
still takes precedence over later choices.
|
|
14
14
|
|
|
15
15
|
## Choose sample data
|
|
16
16
|
|
|
@@ -20,48 +20,43 @@ Use `--bind <capabilityKey>.<dataSourceKey>=<sampleDataFileName>` to choose a so
|
|
|
20
20
|
ntn workers customblocks dev -- --bind task-board.tasks=sample_tasks.json
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
This connects the `tasks` data source on `task-board` to `data/sample_tasks.json`.
|
|
24
|
-
|
|
23
|
+
This connects the `tasks` data source on `task-board` to `data/sample_tasks.json`. Use a filename
|
|
24
|
+
from `data/`, including `.json`.
|
|
25
25
|
|
|
26
|
-
Repeat `--bind` for additional data sources. Sources without an override keep
|
|
27
|
-
|
|
28
|
-
separator.
|
|
26
|
+
Repeat `--bind` for additional data sources. Sources without an override keep their defaults. When
|
|
27
|
+
running `custom-blocks-dev-shell` directly, omit the `--` separator.
|
|
29
28
|
|
|
30
|
-
An unknown target, duplicate target, or missing file stops startup.
|
|
31
|
-
|
|
29
|
+
An unknown target, duplicate target, or missing file stops startup. Invalid JSON or an invalid
|
|
30
|
+
source file also stops startup.
|
|
32
31
|
|
|
33
|
-
The browser maps compatible properties automatically. Incomplete mappings do
|
|
34
|
-
|
|
35
|
-
Empty rows are valid.
|
|
32
|
+
The browser maps compatible properties automatically. Incomplete mappings do not stop the shell.
|
|
33
|
+
Open **Data** to finish connecting the block. Empty rows are valid.
|
|
36
34
|
|
|
37
35
|
## Connecting data
|
|
38
36
|
|
|
39
|
-
**Data** in the toolbar opens the bindings modal: one section
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(format: [`data-sources.md`](./data-sources.md)). The modal shows each slot
|
|
44
|
-
and its property mappings.
|
|
37
|
+
**Data** in the toolbar opens the bindings modal: one section per slot from the block's
|
|
38
|
+
`worker.customBlock({ dataSources })` declaration, each with a source picker and a per-property
|
|
39
|
+
mapping. The sources on offer are the ones in your worker's `data/*.json` (format:
|
|
40
|
+
[`data-sources.md`](./data-sources.md)). The modal shows each slot and its property mappings.
|
|
45
41
|
|
|
46
|
-
Properties map automatically when there is a unique source property with a
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
Properties map automatically when there is a unique source property with a matching key or name and
|
|
43
|
+
the same type. Use the property pickers to adjust mappings. Selecting a different source resets its
|
|
44
|
+
property mappings.
|
|
49
45
|
|
|
50
46
|
## Initialization & binding edits
|
|
51
47
|
|
|
52
|
-
Once every slot is bound and every property mapped, the block initializes and
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
Once every slot is bound and every property mapped, the block initializes and renders. Saving
|
|
49
|
+
binding changes restarts the block with the updated data. If initialization fails, fix the bindings
|
|
50
|
+
and save.
|
|
55
51
|
|
|
56
|
-
Bindings last for the page load, per block: refresh the shell and every block
|
|
57
|
-
|
|
52
|
+
Bindings last for the page load, per block: refresh the shell and every block returns to its CLI
|
|
53
|
+
selection or filename default.
|
|
58
54
|
|
|
59
|
-
The shell reads `data/*.json` once at spin-up. To pick up file edits,
|
|
60
|
-
|
|
55
|
+
The shell reads `data/*.json` once at spin-up. To pick up file edits, restart the dev-shell command;
|
|
56
|
+
a browser refresh is not enough.
|
|
61
57
|
|
|
62
58
|
## Data view
|
|
63
59
|
|
|
64
|
-
Click a data source in the sidebar to inspect its schema and rows, read-only.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
the block selection, so switching blocks updates it.
|
|
60
|
+
Click a data source in the sidebar to inspect its schema and rows, read-only. The shell shows
|
|
61
|
+
exactly the sources in `data/`, nothing else. Sources bound to the selected block carry a green
|
|
62
|
+
**Bound** pill; the pill follows the block selection, so switching blocks updates it.
|
package/docs/data-sources.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# Dev-shell data sources
|
|
2
2
|
|
|
3
|
-
Data sources come in kinds, marked by their `type`, and all live in the
|
|
4
|
-
|
|
5
|
-
supports the following types today:
|
|
3
|
+
Data sources come in kinds, marked by their `type`, and all live in the worker's `data/*.json` — one
|
|
4
|
+
source per file, read at spin-up. The shell supports the following types today:
|
|
6
5
|
|
|
7
|
-
- `worker` — hand-authored JSON files. This is how you give your blocks data,
|
|
8
|
-
|
|
6
|
+
- `worker` — hand-authored JSON files. This is how you give your blocks data, and what this document
|
|
7
|
+
describes.
|
|
9
8
|
- `manual` — sources a user creates themselves in the shell.
|
|
10
9
|
- `built-in` — sources we provide.
|
|
11
10
|
|
|
@@ -36,18 +35,17 @@ For example, `data/tasks.json`:
|
|
|
36
35
|
}
|
|
37
36
|
```
|
|
38
37
|
|
|
39
|
-
- `type` — the source's kind. Hand-authored files declare `"worker"` (the
|
|
40
|
-
|
|
41
|
-
- `name` — the label shown in the shell sidebar. If omitted, it defaults to
|
|
42
|
-
|
|
38
|
+
- `type` — the source's kind. Hand-authored files declare `"worker"` (the default); the pre-built
|
|
39
|
+
sources the shell adds carry `"built-in"`.
|
|
40
|
+
- `name` — the label shown in the shell sidebar. If omitted, it defaults to the filename without
|
|
41
|
+
`.json`.
|
|
43
42
|
- `icon` — optional emoji shown alongside the name.
|
|
44
|
-
- `schema` — maps each property key to `{ name, type }`. If omitted, it defaults
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
`
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
a unique string `id`. Store property values under their schema keys.
|
|
43
|
+
- `schema` — maps each property key to `{ name, type }`. If omitted, it defaults to `{}`. Use the
|
|
44
|
+
same property keys and types the block declares. Types: `title`, `rich_text`, `number`, `select`,
|
|
45
|
+
`multi_select`, `status`, `date`, `checkbox`, `url`, `email`, `phone_number`, `people`, `files`,
|
|
46
|
+
`relation`.
|
|
47
|
+
- `rows` — the source records. If omitted, it defaults to `[]`. Each row needs a unique string `id`.
|
|
48
|
+
Store property values under their schema keys.
|
|
51
49
|
|
|
52
50
|
Value shapes by property type:
|
|
53
51
|
|
|
@@ -64,34 +62,32 @@ Value shapes by property type:
|
|
|
64
62
|
|
|
65
63
|
## Validation
|
|
66
64
|
|
|
67
|
-
Files are validated at spin-up, before they reach the shell UI. A malformed
|
|
68
|
-
|
|
69
|
-
`data/tasks.json: rows.0.id: Invalid key: Expected "id" but received undefined`.
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
Files are validated at spin-up, before they reach the shell UI. A malformed file fails the run with
|
|
66
|
+
the file and problem named, e.g.
|
|
67
|
+
`data/tasks.json: rows.0.id: Invalid key: Expected "id" but received undefined`. The filename
|
|
68
|
+
without `.json` is the source identity used by bindings and source pickers. Renaming a file changes
|
|
69
|
+
its identity.
|
|
72
70
|
|
|
73
71
|
## Querying
|
|
74
72
|
|
|
75
|
-
The shell applies filters, then ordered sorts, then the query limit. The SDK
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
`time_zone` use that named zone, and an explicit offset in `start_time` wins.
|
|
73
|
+
The shell applies filters, then ordered sorts, then the query limit. The SDK resolves semantic
|
|
74
|
+
property keys to property IDs before it sends the query. Empty values stay last in both directions.
|
|
75
|
+
Date-only and zone-less datetime values sort using UTC. Datetime values with a `time_zone` use that
|
|
76
|
+
named zone, and an explicit offset in `start_time` wins.
|
|
80
77
|
|
|
81
78
|
## Materialization
|
|
82
79
|
|
|
83
|
-
You don't have to write these files from scratch. At spin-up the shell
|
|
84
|
-
|
|
85
|
-
`worker.
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
You don't have to write these files from scratch. At spin-up the shell materializes a file for every
|
|
81
|
+
data source the worker declares — both `worker.database(...)` entries and inline
|
|
82
|
+
`worker.customBlock({ dataSources })` schemas — that doesn't already have one:
|
|
83
|
+
`data/worker_<key>.json`, the declared schema with empty `rows`, mirroring a managed database before
|
|
84
|
+
any sync.
|
|
88
85
|
|
|
89
|
-
- The `worker_` prefix on the filename namespaces generated files
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
- Files are only ever written when absent: fill in `rows` freely and your
|
|
93
|
-
|
|
94
|
-
schema.
|
|
86
|
+
- The `worker_` prefix on the filename namespaces generated files away from ones you author
|
|
87
|
+
yourself, so both coexist; the display `name` stays as declared, so the sidebar shows the clean
|
|
88
|
+
name.
|
|
89
|
+
- Files are only ever written when absent: fill in `rows` freely and your edits survive restarts.
|
|
90
|
+
Delete a generated file to regenerate it from the schema.
|
|
95
91
|
|
|
96
92
|
The shell shows exactly the sources in `data/`, nothing else.
|
|
97
93
|
|
|
@@ -104,11 +100,10 @@ ntn workers customblocks sample <url-or-data-source-id> \
|
|
|
104
100
|
--out data/worker_tasks.json --row-only
|
|
105
101
|
```
|
|
106
102
|
|
|
107
|
-
Run the dev shell once to create the generated file, then stop it before sampling.
|
|
108
|
-
|
|
109
|
-
to replace existing rows.
|
|
103
|
+
Run the dev shell once to create the generated file, then stop it before sampling. `--row-only`
|
|
104
|
+
preserves the schema and appends rows with new IDs. Add `--overwrite` to replace existing rows.
|
|
110
105
|
|
|
111
|
-
Sampled property keys must match the generated schema. If they differ, sample
|
|
112
|
-
|
|
106
|
+
Sampled property keys must match the generated schema. If they differ, sample into a separate file
|
|
107
|
+
and select it with [`--bind`](./bindings.md#choose-sample-data).
|
|
113
108
|
|
|
114
109
|
Restart the dev shell after sampling to load the updated data.
|