@notionhq/custom-blocks-dev-shell 0.1.113 → 0.1.115

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.
Files changed (131) hide show
  1. package/README.md +27 -14
  2. package/bin/cli.js +3 -1
  3. package/dist/assets/index-DXzPwq_J.js +11 -0
  4. package/dist/index.html +1 -1
  5. package/dist-cli/cli/binding-cli-flags.js +33 -0
  6. package/dist-cli/cli/binding-errors.js +15 -0
  7. package/dist-cli/{build-block-registry.js → cli/build-block-registry.js} +2 -0
  8. package/dist-cli/{convert-values.js → cli/convert-values.js} +5 -5
  9. package/dist-cli/{convert.js → cli/convert.js} +3 -3
  10. package/dist-cli/cli/data-source-files.js +6 -0
  11. package/dist-cli/{data-sources.js → cli/data-sources.js} +12 -65
  12. package/dist-cli/{dev-shell-launcher.js → cli/dev-shell-launcher.js} +23 -10
  13. package/dist-cli/{errors.js → cli/errors.js} +5 -1
  14. package/dist-cli/cli/launcher-bindings.js +144 -0
  15. package/dist-cli/{published-cli.js → cli/published-cli.js} +2 -2
  16. package/dist-cli/{worker-manifest.js → cli/worker-manifest.js} +18 -1
  17. package/dist-cli/protocol/contrast.d.ts +4 -0
  18. package/dist-cli/protocol/contrast.js +3 -0
  19. package/dist-cli/protocol/dataSources/dataSource.d.ts +786 -0
  20. package/dist-cli/protocol/dataSources/dataSource.js +66 -0
  21. package/dist-cli/protocol/dataSources/dataSourcePage.d.ts +74 -0
  22. package/dist-cli/protocol/dataSources/dataSourcePage.js +15 -0
  23. package/dist-cli/protocol/dataSources/dataSourceValue.d.ts +66 -0
  24. package/dist-cli/protocol/dataSources/dataSourceValue.js +14 -0
  25. package/dist-cli/protocol/dataSources/dateValue.d.ts +157 -0
  26. package/dist-cli/protocol/dataSources/dateValue.js +61 -0
  27. package/dist-cli/protocol/dataSources/errors.d.ts +8 -0
  28. package/dist-cli/protocol/dataSources/errors.js +7 -0
  29. package/dist-cli/protocol/dataSources/propertySchema.d.ts +200 -0
  30. package/dist-cli/protocol/dataSources/propertySchema.js +174 -0
  31. package/dist-cli/protocol/dataSources/recordPointer.d.ts +9 -0
  32. package/dist-cli/protocol/dataSources/recordPointer.js +8 -0
  33. package/dist-cli/protocol/dataSources/sortDirection.d.ts +3 -0
  34. package/dist-cli/protocol/dataSources/sortDirection.js +2 -0
  35. package/dist-cli/protocol/errors.d.ts +12 -0
  36. package/dist-cli/protocol/errors.js +6 -0
  37. package/dist-cli/protocol/ids.d.ts +31 -0
  38. package/dist-cli/protocol/ids.js +26 -0
  39. package/dist-cli/protocol/index.d.ts +53 -0
  40. package/dist-cli/protocol/index.js +53 -0
  41. package/dist-cli/protocol/manifest.d.ts +67 -0
  42. package/dist-cli/protocol/manifest.js +36 -0
  43. package/dist-cli/protocol/messages/connect.d.ts +54 -0
  44. package/dist-cli/protocol/messages/connect.js +39 -0
  45. package/dist-cli/protocol/messages/contrastModeChanged.d.ts +7 -0
  46. package/dist-cli/protocol/messages/contrastModeChanged.js +7 -0
  47. package/dist-cli/protocol/messages/createPage.d.ts +290 -0
  48. package/dist-cli/protocol/messages/createPage.js +51 -0
  49. package/dist-cli/protocol/messages/createPageResult.d.ts +897 -0
  50. package/dist-cli/protocol/messages/createPageResult.js +43 -0
  51. package/dist-cli/protocol/messages/currentUserChanged.d.ts +18 -0
  52. package/dist-cli/protocol/messages/currentUserChanged.js +9 -0
  53. package/dist-cli/protocol/messages/dataSourcesChanged.d.ts +157 -0
  54. package/dist-cli/protocol/messages/dataSourcesChanged.js +13 -0
  55. package/dist-cli/protocol/messages/getPage.d.ts +902 -0
  56. package/dist-cli/protocol/messages/getPage.js +48 -0
  57. package/dist-cli/protocol/messages/getUser.d.ts +44 -0
  58. package/dist-cli/protocol/messages/getUser.js +32 -0
  59. package/dist-cli/protocol/messages/hostToSandbox.d.ts +4385 -0
  60. package/dist-cli/protocol/messages/hostToSandbox.js +48 -0
  61. package/dist-cli/protocol/messages/incomingType.d.ts +9 -0
  62. package/dist-cli/protocol/messages/incomingType.js +17 -0
  63. package/dist-cli/protocol/messages/init.d.ts +273 -0
  64. package/dist-cli/protocol/messages/init.js +57 -0
  65. package/dist-cli/protocol/messages/initResult.d.ts +37 -0
  66. package/dist-cli/protocol/messages/initResult.js +29 -0
  67. package/dist-cli/protocol/messages/invalidHostMessage.d.ts +14 -0
  68. package/dist-cli/protocol/messages/invalidHostMessage.js +13 -0
  69. package/dist-cli/protocol/messages/invalidSandboxMessage.d.ts +14 -0
  70. package/dist-cli/protocol/messages/invalidSandboxMessage.js +13 -0
  71. package/dist-cli/protocol/messages/isInitHandshakeMessage.d.ts +4 -0
  72. package/dist-cli/protocol/messages/isInitHandshakeMessage.js +11 -0
  73. package/dist-cli/protocol/messages/listUsers.d.ts +52 -0
  74. package/dist-cli/protocol/messages/listUsers.js +33 -0
  75. package/dist-cli/protocol/messages/messagePayload.d.ts +19 -0
  76. package/dist-cli/protocol/messages/messagePayload.js +1 -0
  77. package/dist-cli/protocol/messages/openExternalUrl.d.ts +32 -0
  78. package/dist-cli/protocol/messages/openExternalUrl.js +26 -0
  79. package/dist-cli/protocol/messages/openPage.d.ts +38 -0
  80. package/dist-cli/protocol/messages/openPage.js +34 -0
  81. package/dist-cli/protocol/messages/pageChanged.d.ts +32 -0
  82. package/dist-cli/protocol/messages/pageChanged.js +9 -0
  83. package/dist-cli/protocol/messages/parentChanged.d.ts +26 -0
  84. package/dist-cli/protocol/messages/parentChanged.js +9 -0
  85. package/dist-cli/protocol/messages/queryDataSource.d.ts +1446 -0
  86. package/dist-cli/protocol/messages/queryDataSource.js +252 -0
  87. package/dist-cli/protocol/messages/queryDataSourceResult.d.ts +686 -0
  88. package/dist-cli/protocol/messages/queryDataSourceResult.js +44 -0
  89. package/dist-cli/protocol/messages/resize.d.ts +11 -0
  90. package/dist-cli/protocol/messages/resize.js +10 -0
  91. package/dist-cli/protocol/messages/sandboxToHost.d.ts +1091 -0
  92. package/dist-cli/protocol/messages/sandboxToHost.js +33 -0
  93. package/dist-cli/protocol/messages/themeChanged.d.ts +10 -0
  94. package/dist-cli/protocol/messages/themeChanged.js +10 -0
  95. package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.d.ts +10 -0
  96. package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.js +9 -0
  97. package/dist-cli/protocol/messages/updatePage.d.ts +271 -0
  98. package/dist-cli/protocol/messages/updatePage.js +23 -0
  99. package/dist-cli/protocol/messages/updatePageResult.d.ts +895 -0
  100. package/dist-cli/protocol/messages/updatePageResult.js +41 -0
  101. package/dist-cli/protocol/pages/page.d.ts +1422 -0
  102. package/dist-cli/protocol/pages/page.js +318 -0
  103. package/dist-cli/protocol/parent.d.ts +32 -0
  104. package/dist-cli/protocol/parent.js +13 -0
  105. package/dist-cli/protocol/protocolVersion.d.ts +8 -0
  106. package/dist-cli/protocol/protocolVersion.js +11 -0
  107. package/dist-cli/protocol/theme.d.ts +3 -0
  108. package/dist-cli/protocol/theme.js +2 -0
  109. package/dist-cli/protocol/users/user.d.ts +32 -0
  110. package/dist-cli/protocol/users/user.js +20 -0
  111. package/dist-cli/shared/block-registry.js +28 -0
  112. package/dist-cli/shared/data-source.js +22 -0
  113. package/dist-cli/shared/runtime-config.js +10 -0
  114. package/dist-cli/shared/sample-data-source.js +12 -0
  115. package/docs/bindings.md +79 -27
  116. package/package.json +5 -26
  117. package/dist/assets/index-DgQZ0zg6.js +0 -11
  118. package/dist-cli/date-value.js +0 -46
  119. package/dist-cli/resolve-bindings.js +0 -39
  120. package/dist-cli/source-bindings.js +0 -17
  121. /package/dist-cli/{block-csp.js → cli/block-csp.js} +0 -0
  122. /package/dist-cli/{dev-shell-run.js → cli/dev-shell-run.js} +0 -0
  123. /package/dist-cli/{materialize.js → cli/materialize.js} +0 -0
  124. /package/dist-cli/{ports.js → cli/ports.js} +0 -0
  125. /package/dist-cli/{prebuilt.js → cli/prebuilt.js} +0 -0
  126. /package/dist-cli/{runtime-error-client.js → cli/runtime-error-client.js} +0 -0
  127. /package/dist-cli/{serve-ui.js → cli/serve-ui.js} +0 -0
  128. /package/dist-cli/{shared-server.js → cli/shared-server.js} +0 -0
  129. /package/dist-cli/{utils.js → cli/utils.js} +0 -0
  130. /package/dist-cli/{vite-block-server.js → cli/vite-block-server.js} +0 -0
  131. /package/dist-cli/{vite-middleware.js → cli/vite-middleware.js} +0 -0
package/dist/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Workers local shell</title>
7
- <script type="module" crossorigin src="/assets/index-DgQZ0zg6.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-DXzPwq_J.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-E1j3FxAu.css">
9
9
  </head>
10
10
  <body>
@@ -0,0 +1,33 @@
1
+ import { DevShellLauncherBindingError } from "./binding-errors.js";
2
+ export function parseDataSourceBindingOverride({ value, }) {
3
+ const separator = value.indexOf("=");
4
+ const target = value.slice(0, separator);
5
+ const filename = value.slice(separator + 1);
6
+ const dot = target.indexOf(".");
7
+ if (separator < 0 ||
8
+ dot <= 0 ||
9
+ dot === target.length - 1 ||
10
+ target !== target.trim() ||
11
+ filename !== filename.trim() ||
12
+ !filename.endsWith(".json") ||
13
+ filename === ".json" ||
14
+ /[\\/\0]/.test(filename)) {
15
+ throw new DevShellLauncherBindingError("invalid_binding_syntax", "--bind requires <capabilityKey>.<dataSourceKey>=<sampleDataFileName.json>. Use a filename in data/.");
16
+ }
17
+ return { target, filename };
18
+ }
19
+ export function parsePropertyBindingOverride({ value, }) {
20
+ const separator = value.indexOf("=");
21
+ const target = value.slice(0, separator);
22
+ const sourcePropertyKey = value.slice(separator + 1);
23
+ const parts = target.split(".");
24
+ if (separator < 0 ||
25
+ parts.length < 3 ||
26
+ parts.some(part => part.length === 0) ||
27
+ target !== target.trim() ||
28
+ sourcePropertyKey.length === 0 ||
29
+ sourcePropertyKey !== sourcePropertyKey.trim()) {
30
+ throw new DevShellLauncherBindingError("invalid_property_binding_syntax", "--bind-property requires <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>.");
31
+ }
32
+ return { target, sourcePropertyKey };
33
+ }
@@ -0,0 +1,15 @@
1
+ /** A binding failure with a stable code for callers and a message for CLI output. */
2
+ export class DevShellLauncherBindingError extends Error {
3
+ code;
4
+ constructor(code, message) {
5
+ super(`${message} (error code: ${code})`);
6
+ this.name = "DevShellLauncherBindingError";
7
+ this.code = code;
8
+ }
9
+ }
10
+ export function bindingFailure(code, message) {
11
+ return {
12
+ status: "error",
13
+ error: new DevShellLauncherBindingError(code, message),
14
+ };
15
+ }
@@ -23,6 +23,8 @@ export function buildBlockRegistry(blocks, port = DEFAULT_DEV_SHELL_PORT) {
23
23
  manifest: capability.config.manifest,
24
24
  name: capability.key,
25
25
  url: `http://${hostname}.localhost:${port}/`,
26
+ sampleFilesByDataSource: {},
27
+ propertyIdsByDataSource: {},
26
28
  };
27
29
  });
28
30
  }
@@ -1,5 +1,5 @@
1
+ import { notionDateValueSchema, } from "../protocol/index.js";
1
2
  import * as v from "valibot";
2
- import { localDateValueSchema } from "./date-value.js";
3
3
  import { unreachable } from "./utils.js";
4
4
  /**
5
5
  * Convert one public API property value object to a local data source value.
@@ -175,7 +175,7 @@ const anyLocalValue = v.union([
175
175
  stringValue,
176
176
  numberValue,
177
177
  booleanValue,
178
- localDateValueSchema,
178
+ notionDateValueSchema,
179
179
  stringArrayValue,
180
180
  pointerArrayValue,
181
181
  ]);
@@ -198,9 +198,9 @@ const VALUE_SCHEMAS = {
198
198
  number: numberValue,
199
199
  checkbox: booleanValue,
200
200
  multi_select: stringArrayValue,
201
- date: localDateValueSchema,
202
- created_time: localDateValueSchema,
203
- last_edited_time: localDateValueSchema,
201
+ date: notionDateValueSchema,
202
+ created_time: notionDateValueSchema,
203
+ last_edited_time: notionDateValueSchema,
204
204
  people: pointerArrayValue,
205
205
  relation: pointerArrayValue,
206
206
  created_by: pointerArrayValue,
@@ -6,9 +6,10 @@
6
6
  * standalone: `npx @notionhq/custom-blocks-dev-shell convert --in sample.json`.
7
7
  */
8
8
  import { readFileSync } from "node:fs";
9
+ import { NOTION_PROPERTY_TYPES, } from "../protocol/index.js";
9
10
  import * as v from "valibot";
10
11
  import { convertPublicApiPropertyValue, isDataSourceValue, matchesPropertyType, } from "./convert-values.js";
11
- import { NOTION_PROPERTY_TYPES, sourceFileSchema } from "./data-sources.js";
12
+ import { sourceFileSchema } from "./data-sources.js";
12
13
  import { formatUnknownError } from "./errors.js";
13
14
  import { claimUniqueKey, parseCliArgs, slugify } from "./utils.js";
14
15
  const SUPPORTED_TYPES = new Set(NOTION_PROPERTY_TYPES);
@@ -151,8 +152,7 @@ export function validateSource(source) {
151
152
  const path = v.getDotPath(issue);
152
153
  throw new Error(`Converted data source is invalid: ${path ? `${path}: ` : ""}${issue.message}`);
153
154
  }
154
- const schema = (source.schema ?? {});
155
- const rows = (source.rows ?? []);
155
+ const { schema, rows } = result.output;
156
156
  const issues = [];
157
157
  for (const row of rows) {
158
158
  for (const [key, value] of Object.entries(row)) {
@@ -0,0 +1,6 @@
1
+ import { existsSync, readdirSync } from "node:fs";
2
+ export function listDataSourceFiles(dataDir) {
3
+ return existsSync(dataDir)
4
+ ? readdirSync(dataDir).filter(name => name.endsWith(".json"))
5
+ : [];
6
+ }
@@ -4,16 +4,13 @@
4
4
  * the shell, so a malformed source fails spin-up naming the file and the
5
5
  * problem instead of breaking the UI.
6
6
  */
7
- import { existsSync, readdirSync, readFileSync } from "node:fs";
7
+ import { readFileSync } from "node:fs";
8
8
  import { basename, resolve } from "node:path";
9
+ import { notionPropertySchemaSchema, notionPropertyTypeSchema, } from "../protocol/index.js";
9
10
  import * as v from "valibot";
11
+ import { dataSourceTypeSchema, } from "../shared/data-source.js";
12
+ import { listDataSourceFiles } from "./data-source-files.js";
10
13
  import { formatUnknownError } from "./errors.js";
11
- const DEV_SHELL_DATA_SOURCE_TYPES = [
12
- "built-in",
13
- "worker",
14
- "manual",
15
- "syncedFromProd",
16
- ];
17
14
  const DEV_SHELL_STATUS_GROUP_NAMES = [
18
15
  "To-do",
19
16
  "In progress",
@@ -21,48 +18,10 @@ const DEV_SHELL_STATUS_GROUP_NAMES = [
21
18
  "Current",
22
19
  "Future",
23
20
  ];
24
- // Local copy of the SDK's NOTION_PROPERTY_TYPES: the compiled CLI runs under
25
- // plain node, which can't import the SDK's published TS source at runtime.
26
- // The `satisfies` below plus the type-only import keep the two lists locked
27
- // together — a drift on either side fails typecheck.
28
- export const NOTION_PROPERTY_TYPES = [
29
- "title",
30
- "rich_text",
31
- "number",
32
- "checkbox",
33
- "url",
34
- "email",
35
- "phone_number",
36
- "select",
37
- "multi_select",
38
- "status",
39
- "date",
40
- "people",
41
- "files",
42
- "unique_id",
43
- "relation",
44
- "place",
45
- "formula",
46
- "rollup",
47
- "button",
48
- "verification",
49
- "last_visited_time",
50
- "location",
51
- "created_time",
52
- "last_edited_time",
53
- "created_by",
54
- "last_edited_by",
55
- ];
56
- const _allPropertyTypesListed = true;
57
- void _allPropertyTypesListed;
58
21
  const _allStatusGroupNamesListed = true;
59
22
  void _allStatusGroupNamesListed;
60
23
  export function readDataSources(dataDir) {
61
- if (!existsSync(dataDir)) {
62
- return [];
63
- }
64
- return readdirSync(dataDir)
65
- .filter(name => name.endsWith(".json"))
24
+ return listDataSourceFiles(dataDir)
66
25
  .map(name => readSource(resolve(dataDir, name)))
67
26
  .sort((left, right) => left.name.localeCompare(right.name));
68
27
  }
@@ -79,12 +38,12 @@ const statusGroupsSchema = v.array(v.object({
79
38
  const sourcePropertySchema = v.object({
80
39
  name: v.optional(v.string()),
81
40
  description: v.optional(v.string()),
82
- type: v.picklist(NOTION_PROPERTY_TYPES),
41
+ type: notionPropertyTypeSchema,
83
42
  options: v.optional(statusOptionsSchema),
84
43
  groups: v.optional(statusGroupsSchema),
85
44
  });
86
45
  export const sourceFileSchema = v.object({
87
- type: v.optional(v.picklist(DEV_SHELL_DATA_SOURCE_TYPES), "worker"),
46
+ type: v.optional(dataSourceTypeSchema, "worker"),
88
47
  name: v.optional(nonEmptyString),
89
48
  icon: v.optional(v.string()),
90
49
  schema: v.optional(v.record(v.string(), sourcePropertySchema), {}),
@@ -146,22 +105,10 @@ function readSource(file) {
146
105
  };
147
106
  }
148
107
  function toNotionPropertySchema(propertyKey, property) {
149
- const base = {
108
+ return v.parse(notionPropertySchemaSchema, {
109
+ ...property,
150
110
  name: property.name ?? propertyKey,
151
- ...(property.description !== undefined
152
- ? { description: property.description }
153
- : {}),
154
- };
155
- if (property.type === "select" || property.type === "multi_select") {
156
- return { ...base, type: property.type, options: property.options ?? [] };
157
- }
158
- if (property.type === "status") {
159
- return {
160
- ...base,
161
- type: "status",
162
- options: property.options ?? [],
163
- groups: property.groups ?? [],
164
- };
165
- }
166
- return { ...base, type: property.type };
111
+ options: property.options ?? [],
112
+ groups: property.groups ?? [],
113
+ });
167
114
  }
@@ -7,15 +7,15 @@
7
7
  */
8
8
  import { existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
9
9
  import { basename, join, resolve } from "node:path";
10
- import { buildBlockRegistry, } from "./build-block-registry.js";
10
+ import { parseDataSourceBindingOverride, parsePropertyBindingOverride, } from "./binding-cli-flags.js";
11
+ import { buildBlockRegistry } from "./build-block-registry.js";
11
12
  import { readDataSources } from "./data-sources.js";
12
13
  import { DevShellRun, installProcessSignalHandlers, } from "./dev-shell-run.js";
13
14
  import { formatUnknownErrorWithStack } from "./errors.js";
15
+ import { resolveDevShellLauncherBindings } from "./launcher-bindings.js";
14
16
  import { materializeWorkerSchemaDataSources } from "./materialize.js";
15
17
  import { DEFAULT_DEV_SHELL_PORT, parsePort } from "./ports.js";
16
- import { resolveLaunchBindings } from "./resolve-bindings.js";
17
18
  import { SharedServer } from "./shared-server.js";
18
- import { parseBindingOverride, } from "./source-bindings.js";
19
19
  import { parseCliArgs } from "./utils.js";
20
20
  import { writeBlockViteConfig } from "./vite-block-server.js";
21
21
  import { mountVite } from "./vite-middleware.js";
@@ -65,13 +65,17 @@ export function parseWorkerLaunchArgs(argv) {
65
65
  shellPort: DEFAULT_DEV_SHELL_PORT,
66
66
  strictPort: false,
67
67
  bindings: [],
68
+ propertyBindings: [],
68
69
  };
69
70
  let hasPositionalWorker = false;
70
71
  parseCliArgs({
71
72
  argv,
72
73
  handlers: {
73
74
  "--bind": value => {
74
- args.bindings.push(parseBindingOverride(value));
75
+ args.bindings.push(parseDataSourceBindingOverride({ value }));
76
+ },
77
+ "--bind-property": value => {
78
+ args.propertyBindings.push(parsePropertyBindingOverride({ value }));
75
79
  },
76
80
  "--worker": value => {
77
81
  if (value.length === 0) {
@@ -90,7 +94,8 @@ export function parseWorkerLaunchArgs(argv) {
90
94
  },
91
95
  onUnknown: arg => {
92
96
  throw new Error(`Unknown dev shell option "${arg}". Supported: --worker <dir>, ` +
93
- `--port <port>, --bind <capabilityKey>.<dataSourceKey>=<sampleDataFileName>.`);
97
+ `--port <port>, --bind <capabilityKey>.<dataSourceKey>=<sampleDataFileName>, ` +
98
+ `--bind-property <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>.`);
94
99
  },
95
100
  onPositional: arg => {
96
101
  // The published launcher passes its optional worker path positionally.
@@ -150,12 +155,20 @@ function logWorkerPlan(workerName, plan) {
150
155
  "(format: node_modules/@notionhq/custom-blocks-dev-shell/docs/data-sources.md).");
151
156
  }
152
157
  function applyBindingsAndLog(args, plan, workerDir) {
153
- const { registryBindings } = resolveLaunchBindings(plan.blocks.map(block => block.capability), plan.dataSources, args.bindings);
158
+ const result = resolveDevShellLauncherBindings({
159
+ blocks: plan.blocks.map(block => block.capability),
160
+ sources: plan.dataSources,
161
+ sourceOverrides: args.bindings,
162
+ propertyOverrides: args.propertyBindings,
163
+ });
164
+ if (result.status === "error") {
165
+ throw result.error;
166
+ }
167
+ const { registryBindings, registryPropertyBindings } = result.value;
154
168
  for (const entry of plan.registry) {
155
- const bindings = registryBindings.get(entry.key);
156
- if (bindings !== undefined) {
157
- entry.sampleFilesByDataSource = bindings;
158
- }
169
+ entry.propertyIdsByDataSource =
170
+ registryPropertyBindings.get(entry.key) ?? {};
171
+ entry.sampleFilesByDataSource = registryBindings.get(entry.key) ?? {};
159
172
  }
160
173
  logWorkerPlan(basename(workerDir), plan);
161
174
  }
@@ -1,8 +1,12 @@
1
+ import { DevShellLauncherBindingError } from "./binding-errors.js";
1
2
  /** Format an unknown error as a message without a stack trace. */
2
3
  export function formatUnknownError(error) {
3
4
  return error instanceof Error ? error.message : String(error);
4
5
  }
5
- /** Format an unknown error with its stack when one is available. */
6
+ /** Include stacks for unexpected errors. Binding failures show only their message. */
6
7
  export function formatUnknownErrorWithStack(error) {
8
+ if (error instanceof DevShellLauncherBindingError) {
9
+ return error.message;
10
+ }
7
11
  return error instanceof Error ? (error.stack ?? error.message) : String(error);
8
12
  }
@@ -0,0 +1,144 @@
1
+ import { selectSampleDataSource } from "../shared/sample-data-source.js";
2
+ import { bindingFailure, } from "./binding-errors.js";
3
+ export function resolveDevShellLauncherBindings(args) {
4
+ const { blocks, sources, sourceOverrides, propertyOverrides } = args;
5
+ const dataSourceSlots = blocks.flatMap(block => Object.entries(block.config.manifest.dataSources).map(([slotKey, slot]) => ({
6
+ blockKey: block.key,
7
+ slotKey,
8
+ target: `${block.key}.${slotKey}`,
9
+ properties: slot.properties ?? {},
10
+ })));
11
+ const explicitSlots = new Map();
12
+ for (const binding of sourceOverrides) {
13
+ const result = resolveDataSourceBindingSlot({
14
+ binding,
15
+ dataSourceSlots,
16
+ sources,
17
+ explicitSlots,
18
+ });
19
+ if (result.status === "error") {
20
+ return result;
21
+ }
22
+ explicitSlots.set(binding.target, result.value);
23
+ }
24
+ const selectedDataSourceSlots = dataSourceSlots.map(slot => explicitSlots.get(slot.target) ?? {
25
+ ...slot,
26
+ source: selectSampleDataSource({
27
+ slotKey: slot.slotKey,
28
+ sources,
29
+ explicitFilename: undefined,
30
+ }),
31
+ explicitFilename: undefined,
32
+ });
33
+ const propertySlots = selectedDataSourceSlots.flatMap(slot => Object.entries(slot.properties).map(([propertyKey, property]) => ({
34
+ slot,
35
+ propertyKey,
36
+ property,
37
+ target: `${slot.target}.${propertyKey}`,
38
+ })));
39
+ const seenTargets = new Set();
40
+ const propertyMappings = [];
41
+ for (const binding of propertyOverrides) {
42
+ const result = resolvePropertyBindingSlot({
43
+ binding,
44
+ propertySlots,
45
+ seenTargets,
46
+ });
47
+ if (result.status === "error") {
48
+ return result;
49
+ }
50
+ seenTargets.add(binding.target);
51
+ propertyMappings.push(result.value);
52
+ }
53
+ return {
54
+ status: "success",
55
+ value: buildBindingRegistry({
56
+ dataSourceSlots: selectedDataSourceSlots,
57
+ propertyMappings,
58
+ }),
59
+ };
60
+ }
61
+ function resolveDataSourceBindingSlot({ binding, dataSourceSlots, sources, explicitSlots, }) {
62
+ const { target, filename } = binding;
63
+ const matches = dataSourceSlots.filter(slot => slot.target === target);
64
+ if (matches.length !== 1) {
65
+ return bindingFailure(matches.length === 0
66
+ ? "unknown_binding_target"
67
+ : "ambiguous_binding_target", `${matches.length === 0 ? "Unknown" : "Ambiguous"} binding target "${target}". Available targets: ${dataSourceSlots.map(slot => slot.target).join(", ") || "(none)"}.`);
68
+ }
69
+ if (explicitSlots.has(target)) {
70
+ return bindingFailure("duplicate_binding_target", `Duplicate --bind target "${target}". Specify each target once.`);
71
+ }
72
+ const slot = matches[0];
73
+ const source = selectSampleDataSource({
74
+ slotKey: slot.slotKey,
75
+ sources,
76
+ explicitFilename: filename,
77
+ });
78
+ if (source === undefined) {
79
+ return bindingFailure("sample_file_not_found", `Cannot bind ${target}: data/${filename} does not exist. Available files: ${sources.map(candidate => `${candidate.filename}.json`).join(", ") || "(none)"}.`);
80
+ }
81
+ return {
82
+ status: "success",
83
+ value: { ...slot, source, explicitFilename: filename },
84
+ };
85
+ }
86
+ function resolvePropertyBindingSlot({ binding, propertySlots, seenTargets, }) {
87
+ const { target, sourcePropertyKey } = binding;
88
+ const matches = propertySlots.filter(slot => slot.target === target);
89
+ if (matches.length !== 1) {
90
+ return bindingFailure(matches.length === 0
91
+ ? "unknown_property_binding_target"
92
+ : "ambiguous_property_binding_target", `${matches.length === 0 ? "Unknown" : "Ambiguous"} property binding target "${target}". Available targets: ${propertySlots.map(slot => slot.target).join(", ") || "(none)"}.`);
93
+ }
94
+ if (seenTargets.has(target)) {
95
+ return bindingFailure("duplicate_property_binding_target", `Duplicate --bind-property target "${target}". Specify each target once.`);
96
+ }
97
+ const { slot, propertyKey, property } = matches[0];
98
+ const { source } = slot;
99
+ if (source === undefined) {
100
+ return bindingFailure("binding_source_missing", `Cannot bind ${target}: no sample source selected. Use --bind ${slot.target}=<sampleDataFileName.json>.`);
101
+ }
102
+ const sourceProperty = Object.hasOwn(source.schema, sourcePropertyKey)
103
+ ? source.schema[sourcePropertyKey]
104
+ : undefined;
105
+ if (sourceProperty === undefined) {
106
+ return bindingFailure("source_property_not_found", `Cannot bind ${target}: source property "${sourcePropertyKey}" does not exist in data/${source.filename}.json.`);
107
+ }
108
+ if (sourceProperty.type !== property.type) {
109
+ return bindingFailure("property_type_mismatch", `Cannot bind ${target}: source property "${sourcePropertyKey}" has type "${sourceProperty.type}", expected "${property.type}".`);
110
+ }
111
+ return {
112
+ status: "success",
113
+ value: {
114
+ blockKey: slot.blockKey,
115
+ slotKey: slot.slotKey,
116
+ propertyKey,
117
+ sourcePropertyKey,
118
+ },
119
+ };
120
+ }
121
+ function buildBindingRegistry({ dataSourceSlots, propertyMappings, }) {
122
+ const registryBindings = new Map();
123
+ for (const { blockKey, slotKey, explicitFilename } of dataSourceSlots) {
124
+ if (explicitFilename === undefined) {
125
+ continue;
126
+ }
127
+ registryBindings.set(blockKey, {
128
+ ...registryBindings.get(blockKey),
129
+ [slotKey]: explicitFilename,
130
+ });
131
+ }
132
+ const registryPropertyBindings = new Map();
133
+ for (const { blockKey, slotKey, propertyKey, sourcePropertyKey, } of propertyMappings) {
134
+ const blockBindings = registryPropertyBindings.get(blockKey) ?? {};
135
+ const slotBindings = Object.hasOwn(blockBindings, slotKey)
136
+ ? blockBindings[slotKey]
137
+ : {};
138
+ registryPropertyBindings.set(blockKey, {
139
+ ...blockBindings,
140
+ [slotKey]: { ...slotBindings, [propertyKey]: sourcePropertyKey },
141
+ });
142
+ }
143
+ return { registryBindings, registryPropertyBindings };
144
+ }
@@ -20,12 +20,12 @@ import { copyPrebuiltDataSources } from "./prebuilt.js";
20
20
  import { createUiHandler } from "./serve-ui.js";
21
21
  const __dirname = dirname(fileURLToPath(import.meta.url));
22
22
  const createShellLaunch = async ({ plan, shared, log }) => {
23
- const distDir = resolve(__dirname, "..", "dist");
23
+ const distDir = resolve(__dirname, "../..", "dist");
24
24
  if (!existsSync(join(distDir, "index.html"))) {
25
25
  throw new Error(`No prebuilt UI found at ${distDir}. This package was not assembled ` +
26
26
  `correctly; reinstall it.`);
27
27
  }
28
- const prebuiltDir = resolve(__dirname, "..", "data");
28
+ const prebuiltDir = resolve(__dirname, "../..", "data");
29
29
  shared.routes.set("localhost", {
30
30
  handle: createUiHandler(distDir, {
31
31
  blocks: plan.registry,
@@ -13,6 +13,21 @@ import { execSync } from "node:child_process";
13
13
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
14
14
  import { dirname, resolve } from "node:path";
15
15
  import { pathToFileURL } from "node:url";
16
+ import { manifestSchema } from "../protocol/index.js";
17
+ import * as v from "valibot";
18
+ const workerBlockCapabilitySchema = v.object({
19
+ _tag: v.literal("custom_block"),
20
+ key: v.string(),
21
+ config: v.object({
22
+ source: v.object({
23
+ type: v.string(),
24
+ path: v.string(),
25
+ command: v.optional(v.string()),
26
+ output: v.optional(v.string()),
27
+ }),
28
+ manifest: manifestSchema,
29
+ }),
30
+ });
16
31
  const WORKER_MANIFEST_FILENAME = "worker_manifest.json";
17
32
  /**
18
33
  * Heuristic for the no-flag fallback: does `dir` look like a worker project?
@@ -64,7 +79,9 @@ export function findWorkerDir(startDir) {
64
79
  }
65
80
  /** The custom-block capabilities in a manifest, narrowed by `_tag`. */
66
81
  export function blockCapabilities(manifest) {
67
- return manifest.capabilities.filter((capability) => capability._tag === "custom_block");
82
+ return manifest.capabilities
83
+ .filter(capability => capability._tag === "custom_block")
84
+ .map(capability => v.parse(workerBlockCapabilitySchema, capability));
68
85
  }
69
86
  function isManifestShape(value) {
70
87
  return (typeof value === "object" &&
@@ -0,0 +1,4 @@
1
+ import * as v from "valibot";
2
+ export declare const notionContrastModeSchema: v.PicklistSchema<["standard", "high"], undefined>;
3
+ export type NotionContrastMode = v.InferOutput<typeof notionContrastModeSchema>;
4
+ export declare const DEFAULT_CONTRAST_MODE: NotionContrastMode;
@@ -0,0 +1,3 @@
1
+ import * as v from "valibot";
2
+ export const notionContrastModeSchema = v.picklist(["standard", "high"]);
3
+ export const DEFAULT_CONTRAST_MODE = "standard";