@notionhq/custom-blocks-dev-shell 0.1.115 → 0.1.116
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/LICENSE +21 -0
- package/README.md +86 -13
- package/THIRD_PARTY_LICENSES.md +133 -0
- package/dist/assets/index-DSaseWP_.js +11 -0
- package/dist/assets/index-Do-x8yIt.css +2 -0
- package/dist/index.html +2 -2
- package/dist-cli/cli/published-cli.js +8467 -51
- package/docs/bindings.md +17 -12
- package/docs/bridge/changelog.md +67 -0
- package/docs/bridge/protocol.md +204 -0
- package/docs/bridge/versioning.md +38 -0
- package/docs/data-sources.md +49 -36
- package/docs/host/README.md +177 -0
- package/docs/host/docs/compatibility.md +68 -0
- package/docs/host/docs/handlers.md +199 -0
- package/docs/host/docs/lifecycle.md +117 -0
- package/package.json +5 -3
- package/dist/assets/index-DXzPwq_J.js +0 -11
- package/dist/assets/index-E1j3FxAu.css +0 -2
- package/dist-cli/cli/binding-cli-flags.js +0 -33
- package/dist-cli/cli/binding-errors.js +0 -15
- package/dist-cli/cli/block-csp.js +0 -84
- package/dist-cli/cli/build-block-registry.js +0 -30
- package/dist-cli/cli/convert-values.js +0 -222
- package/dist-cli/cli/convert.js +0 -210
- package/dist-cli/cli/data-source-files.js +0 -6
- package/dist-cli/cli/data-sources.js +0 -114
- package/dist-cli/cli/dev-shell-launcher.js +0 -239
- package/dist-cli/cli/dev-shell-run.js +0 -72
- package/dist-cli/cli/errors.js +0 -12
- package/dist-cli/cli/launcher-bindings.js +0 -144
- package/dist-cli/cli/materialize.js +0 -105
- package/dist-cli/cli/ports.js +0 -20
- package/dist-cli/cli/prebuilt.js +0 -23
- package/dist-cli/cli/runtime-error-client.js +0 -52
- package/dist-cli/cli/serve-ui.js +0 -110
- package/dist-cli/cli/shared-server.js +0 -70
- package/dist-cli/cli/utils.js +0 -52
- package/dist-cli/cli/vite-block-server.js +0 -125
- package/dist-cli/cli/vite-middleware.js +0 -111
- package/dist-cli/cli/worker-manifest.js +0 -158
- package/dist-cli/protocol/contrast.d.ts +0 -4
- package/dist-cli/protocol/contrast.js +0 -3
- package/dist-cli/protocol/dataSources/dataSource.d.ts +0 -786
- package/dist-cli/protocol/dataSources/dataSource.js +0 -66
- package/dist-cli/protocol/dataSources/dataSourcePage.d.ts +0 -74
- package/dist-cli/protocol/dataSources/dataSourcePage.js +0 -15
- package/dist-cli/protocol/dataSources/dataSourceValue.d.ts +0 -66
- package/dist-cli/protocol/dataSources/dataSourceValue.js +0 -14
- package/dist-cli/protocol/dataSources/dateValue.d.ts +0 -157
- package/dist-cli/protocol/dataSources/dateValue.js +0 -61
- package/dist-cli/protocol/dataSources/errors.d.ts +0 -8
- package/dist-cli/protocol/dataSources/errors.js +0 -7
- package/dist-cli/protocol/dataSources/propertySchema.d.ts +0 -200
- package/dist-cli/protocol/dataSources/propertySchema.js +0 -174
- package/dist-cli/protocol/dataSources/recordPointer.d.ts +0 -9
- package/dist-cli/protocol/dataSources/recordPointer.js +0 -8
- package/dist-cli/protocol/dataSources/sortDirection.d.ts +0 -3
- package/dist-cli/protocol/dataSources/sortDirection.js +0 -2
- package/dist-cli/protocol/errors.d.ts +0 -12
- package/dist-cli/protocol/errors.js +0 -6
- package/dist-cli/protocol/ids.d.ts +0 -31
- package/dist-cli/protocol/ids.js +0 -26
- package/dist-cli/protocol/index.d.ts +0 -53
- package/dist-cli/protocol/index.js +0 -53
- package/dist-cli/protocol/manifest.d.ts +0 -67
- package/dist-cli/protocol/manifest.js +0 -36
- package/dist-cli/protocol/messages/connect.d.ts +0 -54
- package/dist-cli/protocol/messages/connect.js +0 -39
- package/dist-cli/protocol/messages/contrastModeChanged.d.ts +0 -7
- package/dist-cli/protocol/messages/contrastModeChanged.js +0 -7
- package/dist-cli/protocol/messages/createPage.d.ts +0 -290
- package/dist-cli/protocol/messages/createPage.js +0 -51
- package/dist-cli/protocol/messages/createPageResult.d.ts +0 -897
- package/dist-cli/protocol/messages/createPageResult.js +0 -43
- package/dist-cli/protocol/messages/currentUserChanged.d.ts +0 -18
- package/dist-cli/protocol/messages/currentUserChanged.js +0 -9
- package/dist-cli/protocol/messages/dataSourcesChanged.d.ts +0 -157
- package/dist-cli/protocol/messages/dataSourcesChanged.js +0 -13
- package/dist-cli/protocol/messages/getPage.d.ts +0 -902
- package/dist-cli/protocol/messages/getPage.js +0 -48
- package/dist-cli/protocol/messages/getUser.d.ts +0 -44
- package/dist-cli/protocol/messages/getUser.js +0 -32
- package/dist-cli/protocol/messages/hostToSandbox.d.ts +0 -4385
- package/dist-cli/protocol/messages/hostToSandbox.js +0 -48
- package/dist-cli/protocol/messages/incomingType.d.ts +0 -9
- package/dist-cli/protocol/messages/incomingType.js +0 -17
- package/dist-cli/protocol/messages/init.d.ts +0 -273
- package/dist-cli/protocol/messages/init.js +0 -57
- package/dist-cli/protocol/messages/initResult.d.ts +0 -37
- package/dist-cli/protocol/messages/initResult.js +0 -29
- package/dist-cli/protocol/messages/invalidHostMessage.d.ts +0 -14
- package/dist-cli/protocol/messages/invalidHostMessage.js +0 -13
- package/dist-cli/protocol/messages/invalidSandboxMessage.d.ts +0 -14
- package/dist-cli/protocol/messages/invalidSandboxMessage.js +0 -13
- package/dist-cli/protocol/messages/isInitHandshakeMessage.d.ts +0 -4
- package/dist-cli/protocol/messages/isInitHandshakeMessage.js +0 -11
- package/dist-cli/protocol/messages/listUsers.d.ts +0 -52
- package/dist-cli/protocol/messages/listUsers.js +0 -33
- package/dist-cli/protocol/messages/messagePayload.d.ts +0 -19
- package/dist-cli/protocol/messages/messagePayload.js +0 -1
- package/dist-cli/protocol/messages/openExternalUrl.d.ts +0 -32
- package/dist-cli/protocol/messages/openExternalUrl.js +0 -26
- package/dist-cli/protocol/messages/openPage.d.ts +0 -38
- package/dist-cli/protocol/messages/openPage.js +0 -34
- package/dist-cli/protocol/messages/pageChanged.d.ts +0 -32
- package/dist-cli/protocol/messages/pageChanged.js +0 -9
- package/dist-cli/protocol/messages/parentChanged.d.ts +0 -26
- package/dist-cli/protocol/messages/parentChanged.js +0 -9
- package/dist-cli/protocol/messages/queryDataSource.d.ts +0 -1446
- package/dist-cli/protocol/messages/queryDataSource.js +0 -252
- package/dist-cli/protocol/messages/queryDataSourceResult.d.ts +0 -686
- package/dist-cli/protocol/messages/queryDataSourceResult.js +0 -44
- package/dist-cli/protocol/messages/resize.d.ts +0 -11
- package/dist-cli/protocol/messages/resize.js +0 -10
- package/dist-cli/protocol/messages/sandboxToHost.d.ts +0 -1091
- package/dist-cli/protocol/messages/sandboxToHost.js +0 -33
- package/dist-cli/protocol/messages/themeChanged.d.ts +0 -10
- package/dist-cli/protocol/messages/themeChanged.js +0 -10
- package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.d.ts +0 -10
- package/dist-cli/protocol/messages/unsubscribeDataSourceQuery.js +0 -9
- package/dist-cli/protocol/messages/updatePage.d.ts +0 -271
- package/dist-cli/protocol/messages/updatePage.js +0 -23
- package/dist-cli/protocol/messages/updatePageResult.d.ts +0 -895
- package/dist-cli/protocol/messages/updatePageResult.js +0 -41
- package/dist-cli/protocol/pages/page.d.ts +0 -1422
- package/dist-cli/protocol/pages/page.js +0 -318
- package/dist-cli/protocol/parent.d.ts +0 -32
- package/dist-cli/protocol/parent.js +0 -13
- package/dist-cli/protocol/protocolVersion.d.ts +0 -8
- package/dist-cli/protocol/protocolVersion.js +0 -11
- package/dist-cli/protocol/theme.d.ts +0 -3
- package/dist-cli/protocol/theme.js +0 -2
- package/dist-cli/protocol/users/user.d.ts +0 -32
- package/dist-cli/protocol/users/user.js +0 -20
- package/dist-cli/shared/block-registry.js +0 -28
- package/dist-cli/shared/data-source.js +0 -22
- package/dist-cli/shared/runtime-config.js +0 -10
- package/dist-cli/shared/sample-data-source.js +0 -12
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Load a worker's dev shell data sources from `<dataDir>/*.json` — one source
|
|
3
|
-
* per file, hand-authored. Every file is validated here, before it reaches
|
|
4
|
-
* the shell, so a malformed source fails spin-up naming the file and the
|
|
5
|
-
* problem instead of breaking the UI.
|
|
6
|
-
*/
|
|
7
|
-
import { readFileSync } from "node:fs";
|
|
8
|
-
import { basename, resolve } from "node:path";
|
|
9
|
-
import { notionPropertySchemaSchema, notionPropertyTypeSchema, } from "../protocol/index.js";
|
|
10
|
-
import * as v from "valibot";
|
|
11
|
-
import { dataSourceTypeSchema, } from "../shared/data-source.js";
|
|
12
|
-
import { listDataSourceFiles } from "./data-source-files.js";
|
|
13
|
-
import { formatUnknownError } from "./errors.js";
|
|
14
|
-
const DEV_SHELL_STATUS_GROUP_NAMES = [
|
|
15
|
-
"To-do",
|
|
16
|
-
"In progress",
|
|
17
|
-
"Complete",
|
|
18
|
-
"Current",
|
|
19
|
-
"Future",
|
|
20
|
-
];
|
|
21
|
-
const _allStatusGroupNamesListed = true;
|
|
22
|
-
void _allStatusGroupNamesListed;
|
|
23
|
-
export function readDataSources(dataDir) {
|
|
24
|
-
return listDataSourceFiles(dataDir)
|
|
25
|
-
.map(name => readSource(resolve(dataDir, name)))
|
|
26
|
-
.sort((left, right) => left.name.localeCompare(right.name));
|
|
27
|
-
}
|
|
28
|
-
const nonEmptyString = v.pipe(v.string(), v.nonEmpty());
|
|
29
|
-
const statusOptionsSchema = v.array(v.object({
|
|
30
|
-
id: nonEmptyString,
|
|
31
|
-
name: nonEmptyString,
|
|
32
|
-
}));
|
|
33
|
-
const statusGroupsSchema = v.array(v.object({
|
|
34
|
-
id: nonEmptyString,
|
|
35
|
-
name: v.picklist(DEV_SHELL_STATUS_GROUP_NAMES),
|
|
36
|
-
option_ids: v.array(nonEmptyString),
|
|
37
|
-
}));
|
|
38
|
-
const sourcePropertySchema = v.object({
|
|
39
|
-
name: v.optional(v.string()),
|
|
40
|
-
description: v.optional(v.string()),
|
|
41
|
-
type: notionPropertyTypeSchema,
|
|
42
|
-
options: v.optional(statusOptionsSchema),
|
|
43
|
-
groups: v.optional(statusGroupsSchema),
|
|
44
|
-
});
|
|
45
|
-
export const sourceFileSchema = v.object({
|
|
46
|
-
type: v.optional(dataSourceTypeSchema, "worker"),
|
|
47
|
-
name: v.optional(nonEmptyString),
|
|
48
|
-
icon: v.optional(v.string()),
|
|
49
|
-
schema: v.optional(v.record(v.string(), sourcePropertySchema), {}),
|
|
50
|
-
rows: v.optional(v.array(v.looseObject({ id: nonEmptyString })), []),
|
|
51
|
-
});
|
|
52
|
-
/**
|
|
53
|
-
* Parse and validate one source file. Structural mistakes throw with the file
|
|
54
|
-
* and problem named; the filename defines identity and the default `name`, and
|
|
55
|
-
* omitted `schema`/`rows` to empty — so the minimal valid file is `{}`.
|
|
56
|
-
*/
|
|
57
|
-
function readSource(file) {
|
|
58
|
-
let parsed;
|
|
59
|
-
try {
|
|
60
|
-
parsed = JSON.parse(readFileSync(file, "utf-8"));
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
throw new Error(`${file}: not valid JSON — ${formatUnknownError(error)}`);
|
|
64
|
-
}
|
|
65
|
-
if (Array.isArray(parsed)) {
|
|
66
|
-
throw new Error(`${file}: must be a JSON object`);
|
|
67
|
-
}
|
|
68
|
-
const result = v.safeParse(sourceFileSchema, parsed);
|
|
69
|
-
if (!result.success) {
|
|
70
|
-
const issue = result.issues[0];
|
|
71
|
-
const path = v.getDotPath(issue);
|
|
72
|
-
throw new Error(`${file}: ${path ? `${path}: ` : ""}${issue.message}`);
|
|
73
|
-
}
|
|
74
|
-
for (const [propertyKey, property] of Object.entries(result.output.schema)) {
|
|
75
|
-
if (property.options !== undefined &&
|
|
76
|
-
property.type !== "select" &&
|
|
77
|
-
property.type !== "multi_select" &&
|
|
78
|
-
property.type !== "status") {
|
|
79
|
-
throw new Error(`${file}: schema.${propertyKey}: options require a Select, Multi-select, or Status property`);
|
|
80
|
-
}
|
|
81
|
-
if (property.groups !== undefined && property.type !== "status") {
|
|
82
|
-
throw new Error(`${file}: schema.${propertyKey}: groups require a Status property`);
|
|
83
|
-
}
|
|
84
|
-
const optionIds = new Set((property.options ?? []).map(option => option.id));
|
|
85
|
-
const missingOptionId = (property.groups ?? [])
|
|
86
|
-
.flatMap(group => group.option_ids)
|
|
87
|
-
.find(optionId => !optionIds.has(optionId));
|
|
88
|
-
if (missingOptionId !== undefined) {
|
|
89
|
-
throw new Error(`${file}: schema.${propertyKey}: group references unknown option ID "${missingOptionId}"`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const { type, icon, schema, rows } = result.output;
|
|
93
|
-
const filename = basename(file, ".json");
|
|
94
|
-
return {
|
|
95
|
-
type,
|
|
96
|
-
key: filename,
|
|
97
|
-
filename,
|
|
98
|
-
name: result.output.name ?? filename,
|
|
99
|
-
...(icon !== undefined ? { icon } : {}),
|
|
100
|
-
schema: Object.fromEntries(Object.entries(schema).map(([propertyKey, property]) => [
|
|
101
|
-
propertyKey,
|
|
102
|
-
toNotionPropertySchema(propertyKey, property),
|
|
103
|
-
])),
|
|
104
|
-
rows,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function toNotionPropertySchema(propertyKey, property) {
|
|
108
|
-
return v.parse(notionPropertySchemaSchema, {
|
|
109
|
-
...property,
|
|
110
|
-
name: property.name ?? propertyKey,
|
|
111
|
-
options: property.options ?? [],
|
|
112
|
-
groups: property.groups ?? [],
|
|
113
|
-
});
|
|
114
|
-
}
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared orchestration for the repository and published dev shell launchers.
|
|
3
|
-
*
|
|
4
|
-
* It builds the worker and reads its manifest, creates one Vite middleware instance per
|
|
5
|
-
* custom block, and owns resource cleanup. Each launcher entry point
|
|
6
|
-
* supplies a small shell adapter, but otherwise delegates to this module.
|
|
7
|
-
*/
|
|
8
|
-
import { existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
9
|
-
import { basename, join, resolve } from "node:path";
|
|
10
|
-
import { parseDataSourceBindingOverride, parsePropertyBindingOverride, } from "./binding-cli-flags.js";
|
|
11
|
-
import { buildBlockRegistry } from "./build-block-registry.js";
|
|
12
|
-
import { readDataSources } from "./data-sources.js";
|
|
13
|
-
import { DevShellRun, installProcessSignalHandlers, } from "./dev-shell-run.js";
|
|
14
|
-
import { formatUnknownErrorWithStack } from "./errors.js";
|
|
15
|
-
import { resolveDevShellLauncherBindings } from "./launcher-bindings.js";
|
|
16
|
-
import { materializeWorkerSchemaDataSources } from "./materialize.js";
|
|
17
|
-
import { DEFAULT_DEV_SHELL_PORT, parsePort } from "./ports.js";
|
|
18
|
-
import { SharedServer } from "./shared-server.js";
|
|
19
|
-
import { parseCliArgs } from "./utils.js";
|
|
20
|
-
import { writeBlockViteConfig } from "./vite-block-server.js";
|
|
21
|
-
import { mountVite } from "./vite-middleware.js";
|
|
22
|
-
import { blockCapabilities, findWorkerDir, generateWorkerManifest, } from "./worker-manifest.js";
|
|
23
|
-
const dim = "\x1b[2m";
|
|
24
|
-
const bold = "\x1b[1m";
|
|
25
|
-
const cyan = "\x1b[36m";
|
|
26
|
-
const reset = "\x1b[0m";
|
|
27
|
-
const label = (name) => `${cyan}[${name}]${reset}`;
|
|
28
|
-
export async function prepareWorkerLaunchPlan(workerDir, options = {}) {
|
|
29
|
-
const root = resolve(workerDir);
|
|
30
|
-
if (!existsSync(resolve(root, "node_modules"))) {
|
|
31
|
-
throw new Error(`No node_modules in ${root}. Install the worker's dependencies first ` +
|
|
32
|
-
`(e.g. \`npm install\`), then rerun.`);
|
|
33
|
-
}
|
|
34
|
-
const { manifest, manifestPath } = await generateWorkerManifest(root, {
|
|
35
|
-
build: options.build,
|
|
36
|
-
});
|
|
37
|
-
const capabilities = blockCapabilities(manifest);
|
|
38
|
-
const registry = buildBlockRegistry(capabilities, options.shellPort ?? DEFAULT_DEV_SHELL_PORT);
|
|
39
|
-
const configDir = options.configDir ?? join(root, ".dev-shell");
|
|
40
|
-
const blocks = capabilities.map((capability, index) => {
|
|
41
|
-
const blockDir = resolve(root, capability.config.source.path);
|
|
42
|
-
const hostname = new URL(registry[index].url).hostname;
|
|
43
|
-
return {
|
|
44
|
-
capability,
|
|
45
|
-
blockDir,
|
|
46
|
-
hostname,
|
|
47
|
-
configFile: writeBlockViteConfig(blockDir, capability, configDir, hostname),
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
const dataDir = resolve(root, "data");
|
|
51
|
-
materializeWorkerSchemaDataSources(manifest, dataDir);
|
|
52
|
-
return {
|
|
53
|
-
workerDir: root,
|
|
54
|
-
configDir,
|
|
55
|
-
dataDir,
|
|
56
|
-
manifestPath,
|
|
57
|
-
blocks,
|
|
58
|
-
registry,
|
|
59
|
-
dataSources: readDataSources(dataDir),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
export function parseWorkerLaunchArgs(argv) {
|
|
63
|
-
const args = {
|
|
64
|
-
worker: undefined,
|
|
65
|
-
shellPort: DEFAULT_DEV_SHELL_PORT,
|
|
66
|
-
strictPort: false,
|
|
67
|
-
bindings: [],
|
|
68
|
-
propertyBindings: [],
|
|
69
|
-
};
|
|
70
|
-
let hasPositionalWorker = false;
|
|
71
|
-
parseCliArgs({
|
|
72
|
-
argv,
|
|
73
|
-
handlers: {
|
|
74
|
-
"--bind": value => {
|
|
75
|
-
args.bindings.push(parseDataSourceBindingOverride({ value }));
|
|
76
|
-
},
|
|
77
|
-
"--bind-property": value => {
|
|
78
|
-
args.propertyBindings.push(parsePropertyBindingOverride({ value }));
|
|
79
|
-
},
|
|
80
|
-
"--worker": value => {
|
|
81
|
-
if (value.length === 0) {
|
|
82
|
-
throw new Error("--worker requires a path to a worker directory.");
|
|
83
|
-
}
|
|
84
|
-
// Reject --worker after a positional worker path.
|
|
85
|
-
if (hasPositionalWorker) {
|
|
86
|
-
throw new Error("Cannot combine --worker with a positional worker path.");
|
|
87
|
-
}
|
|
88
|
-
args.worker = value;
|
|
89
|
-
},
|
|
90
|
-
"--port": value => {
|
|
91
|
-
args.shellPort = parsePort("--port", value);
|
|
92
|
-
args.strictPort = true;
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
onUnknown: arg => {
|
|
96
|
-
throw new Error(`Unknown dev shell option "${arg}". Supported: --worker <dir>, ` +
|
|
97
|
-
`--port <port>, --bind <capabilityKey>.<dataSourceKey>=<sampleDataFileName>, ` +
|
|
98
|
-
`--bind-property <capabilityKey>.<dataSourceKey>.<propertyKey>=<sourcePropertyKey>.`);
|
|
99
|
-
},
|
|
100
|
-
onPositional: arg => {
|
|
101
|
-
// The published launcher passes its optional worker path positionally.
|
|
102
|
-
// Reject a second positional path.
|
|
103
|
-
if (hasPositionalWorker) {
|
|
104
|
-
throw new Error("Only one positional worker path may be provided.");
|
|
105
|
-
}
|
|
106
|
-
// Reject a positional path after --worker.
|
|
107
|
-
if (args.worker !== undefined) {
|
|
108
|
-
throw new Error("Cannot combine --worker with a positional worker path.");
|
|
109
|
-
}
|
|
110
|
-
hasPositionalWorker = true;
|
|
111
|
-
args.worker = arg;
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
return args;
|
|
115
|
-
}
|
|
116
|
-
function logNamed(name, message) {
|
|
117
|
-
console.log(`${label(name)} ${message}`);
|
|
118
|
-
}
|
|
119
|
-
function printSummary(args, registry) {
|
|
120
|
-
console.log("");
|
|
121
|
-
console.log(`${bold}Dev shell${reset}`);
|
|
122
|
-
console.log(` ${label("dev-shell")} ${dim}http://localhost:${args.shellPort}${reset}`);
|
|
123
|
-
if (registry.length > 0) {
|
|
124
|
-
console.log("");
|
|
125
|
-
console.log(`${bold}Blocks${reset}`);
|
|
126
|
-
for (const entry of registry) {
|
|
127
|
-
console.log(` ${label(entry.key)} ${dim}${entry.url}${reset}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
console.log("");
|
|
131
|
-
}
|
|
132
|
-
function resolveWorkerLaunch(options) {
|
|
133
|
-
const args = parseWorkerLaunchArgs(options.argv);
|
|
134
|
-
const workerDir = args.worker === undefined
|
|
135
|
-
? findWorkerDir(options.detectFromDir)
|
|
136
|
-
: resolve(options.workerBaseDir, args.worker);
|
|
137
|
-
if (workerDir === undefined) {
|
|
138
|
-
throw new Error("No worker found: run from inside a worker directory, or pass --worker <dir>.");
|
|
139
|
-
}
|
|
140
|
-
if (args.worker === undefined) {
|
|
141
|
-
console.log(`Detected a worker at ${workerDir}.`);
|
|
142
|
-
}
|
|
143
|
-
return { args, workerDir };
|
|
144
|
-
}
|
|
145
|
-
function logWorkerPlan(workerName, plan) {
|
|
146
|
-
logNamed(workerName, `Wrote ${plan.manifestPath}`);
|
|
147
|
-
if (plan.blocks.length === 0) {
|
|
148
|
-
logNamed(workerName, "Worker declares no custom blocks.");
|
|
149
|
-
}
|
|
150
|
-
logNamed(workerName, plan.dataSources.length > 0
|
|
151
|
-
? `Data sources from data: ${plan.dataSources
|
|
152
|
-
.map(source => source.name)
|
|
153
|
-
.join(", ")}`
|
|
154
|
-
: "No data sources — create data/<key>.json files " +
|
|
155
|
-
"(format: node_modules/@notionhq/custom-blocks-dev-shell/docs/data-sources.md).");
|
|
156
|
-
}
|
|
157
|
-
function applyBindingsAndLog(args, plan, workerDir) {
|
|
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;
|
|
168
|
-
for (const entry of plan.registry) {
|
|
169
|
-
entry.propertyIdsByDataSource =
|
|
170
|
-
registryPropertyBindings.get(entry.key) ?? {};
|
|
171
|
-
entry.sampleFilesByDataSource = registryBindings.get(entry.key) ?? {};
|
|
172
|
-
}
|
|
173
|
-
logWorkerPlan(basename(workerDir), plan);
|
|
174
|
-
}
|
|
175
|
-
export async function launchDevShell(options) {
|
|
176
|
-
const { installSignalHandlers = true } = options;
|
|
177
|
-
const shared = new SharedServer();
|
|
178
|
-
const beforeCleanup = () => shared.close();
|
|
179
|
-
const run = options.createRun?.(beforeCleanup) ?? new DevShellRun(beforeCleanup);
|
|
180
|
-
if (installSignalHandlers) {
|
|
181
|
-
installProcessSignalHandlers(run);
|
|
182
|
-
}
|
|
183
|
-
try {
|
|
184
|
-
const { args, workerDir } = resolveWorkerLaunch(options);
|
|
185
|
-
const originalCwd = process.cwd();
|
|
186
|
-
// One worker owns the process for the run, including Vite config reloads
|
|
187
|
-
// and plugin callbacks. Resolve CLI paths before changing directories.
|
|
188
|
-
process.chdir(workerDir);
|
|
189
|
-
run.addResource(() => process.chdir(originalCwd));
|
|
190
|
-
args.shellPort = await shared.listen(args.shellPort, args.strictPort);
|
|
191
|
-
const tempRoot = join(workerDir, ".dev-shell");
|
|
192
|
-
mkdirSync(tempRoot, { recursive: true });
|
|
193
|
-
const configDir = mkdtempSync(join(tempRoot, "run-"));
|
|
194
|
-
run.addResource(() => rmSync(configDir, { recursive: true, force: true }));
|
|
195
|
-
logNamed(basename(workerDir), "Extracting worker manifest...");
|
|
196
|
-
const plan = await prepareWorkerLaunchPlan(workerDir, {
|
|
197
|
-
shellPort: args.shellPort,
|
|
198
|
-
configDir,
|
|
199
|
-
});
|
|
200
|
-
if (run.closing) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
applyBindingsAndLog(args, plan, workerDir);
|
|
204
|
-
const closeShell = await options.createShellLaunch({
|
|
205
|
-
plan,
|
|
206
|
-
shared,
|
|
207
|
-
log: logNamed,
|
|
208
|
-
});
|
|
209
|
-
if (closeShell) {
|
|
210
|
-
run.addResource(closeShell);
|
|
211
|
-
}
|
|
212
|
-
for (const block of plan.blocks) {
|
|
213
|
-
if (run.closing) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const close = await mountVite({
|
|
217
|
-
projectDir: workerDir,
|
|
218
|
-
hostname: block.hostname,
|
|
219
|
-
// TODO(custom-blocks): Let users limit network origins and embedding hosts.
|
|
220
|
-
blockPolicy: {
|
|
221
|
-
allowedNetworkOrigins: ["*"],
|
|
222
|
-
allowedFrameAncestors: ["*"],
|
|
223
|
-
},
|
|
224
|
-
shared,
|
|
225
|
-
config: { configFile: block.configFile, root: block.blockDir },
|
|
226
|
-
});
|
|
227
|
-
run.addResource(close);
|
|
228
|
-
}
|
|
229
|
-
if (run.closing) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
printSummary(args, plan.registry);
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
console.error(`Failed to start dev shell:\n${formatUnknownErrorWithStack(error)}`);
|
|
236
|
-
process.exitCode = 1;
|
|
237
|
-
run.shutdown("SIGTERM");
|
|
238
|
-
}
|
|
239
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/** Own the listener and Vite resources for one dev shell run. */
|
|
2
|
-
const SHUTDOWN_GRACE_MS = 1500;
|
|
3
|
-
export class DevShellRun {
|
|
4
|
-
beforeCleanup;
|
|
5
|
-
resources = [];
|
|
6
|
-
shuttingDown = false;
|
|
7
|
-
constructor(beforeCleanup) {
|
|
8
|
-
this.beforeCleanup = beforeCleanup;
|
|
9
|
-
}
|
|
10
|
-
get closing() {
|
|
11
|
-
return this.shuttingDown;
|
|
12
|
-
}
|
|
13
|
-
addResource(resource) {
|
|
14
|
-
if (this.closing) {
|
|
15
|
-
void closeResource(resource);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
this.resources.push(resource);
|
|
19
|
-
}
|
|
20
|
-
shutdown(signal) {
|
|
21
|
-
if (signal === "exit") {
|
|
22
|
-
const alreadyClosing = this.closing;
|
|
23
|
-
this.shuttingDown = true;
|
|
24
|
-
if (!alreadyClosing) {
|
|
25
|
-
void closeResource(this.beforeCleanup);
|
|
26
|
-
}
|
|
27
|
-
// Exit handlers cannot await promises. Start all remaining cleanup,
|
|
28
|
-
// including file removal when an earlier async cleanup timed out.
|
|
29
|
-
for (let resource = this.resources.pop(); resource; resource = this.resources.pop()) {
|
|
30
|
-
void closeResource(resource);
|
|
31
|
-
}
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (this.closing) {
|
|
35
|
-
process.exit(process.exitCode ?? 130);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
this.shuttingDown = true;
|
|
39
|
-
console.log("\n\x1b[2mShutting down...\x1b[0m");
|
|
40
|
-
void this.finishShutdown();
|
|
41
|
-
}
|
|
42
|
-
async finishShutdown() {
|
|
43
|
-
const timeout = setTimeout(() => {
|
|
44
|
-
process.exit(process.exitCode ?? 130);
|
|
45
|
-
}, SHUTDOWN_GRACE_MS);
|
|
46
|
-
await closeResource(this.beforeCleanup);
|
|
47
|
-
for (let resource = this.resources.pop(); resource; resource = this.resources.pop()) {
|
|
48
|
-
await closeResource(resource);
|
|
49
|
-
}
|
|
50
|
-
clearTimeout(timeout);
|
|
51
|
-
process.exit(process.exitCode ?? 0);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async function closeResource(resource) {
|
|
55
|
-
try {
|
|
56
|
-
await resource();
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
console.error("Dev shell cleanup failed:", error);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export function installProcessSignalHandlers(run) {
|
|
63
|
-
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
64
|
-
process.on(signal, () => run.shutdown(signal));
|
|
65
|
-
}
|
|
66
|
-
process.on("exit", () => run.shutdown("exit"));
|
|
67
|
-
process.on("uncaughtException", error => {
|
|
68
|
-
console.error(error);
|
|
69
|
-
process.exitCode = 1;
|
|
70
|
-
run.shutdown("SIGTERM");
|
|
71
|
-
});
|
|
72
|
-
}
|
package/dist-cli/cli/errors.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DevShellLauncherBindingError } from "./binding-errors.js";
|
|
2
|
-
/** Format an unknown error as a message without a stack trace. */
|
|
3
|
-
export function formatUnknownError(error) {
|
|
4
|
-
return error instanceof Error ? error.message : String(error);
|
|
5
|
-
}
|
|
6
|
-
/** Include stacks for unexpected errors. Binding failures show only their message. */
|
|
7
|
-
export function formatUnknownErrorWithStack(error) {
|
|
8
|
-
if (error instanceof DevShellLauncherBindingError) {
|
|
9
|
-
return error.message;
|
|
10
|
-
}
|
|
11
|
-
return error instanceof Error ? (error.stack ?? error.message) : String(error);
|
|
12
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Materialize a worker's declared data sources as `data/worker_<key>.json`
|
|
3
|
-
* files: the schema with no rows, mirroring a managed database before any
|
|
4
|
-
* sync. Rows are added by editing the file; `data-sources.ts` reads and
|
|
5
|
-
* validates whatever ends up in the directory.
|
|
6
|
-
*
|
|
7
|
-
* A block's data source can come from a `worker.database` or from an inline
|
|
8
|
-
* schema declared on the block (`worker.customBlock({ dataSources })`); both
|
|
9
|
-
* are materialized so all sources are treated equivalently — just files in
|
|
10
|
-
* `data/`. The `worker_` prefix keeps generated sources from ever colliding
|
|
11
|
-
* with hand-authored files, so both can coexist.
|
|
12
|
-
*
|
|
13
|
-
* Files are written only when absent, so hand-edited or hand-authored sources
|
|
14
|
-
* survive across restarts; delete a file to regenerate it from the schema.
|
|
15
|
-
*/
|
|
16
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
17
|
-
import { resolve } from "node:path";
|
|
18
|
-
import { blockCapabilities } from "./worker-manifest.js";
|
|
19
|
-
// Worker authoring type names → public data source (NotionPropertyType) names.
|
|
20
|
-
const TYPE_ALIASES = {
|
|
21
|
-
text: "rich_text",
|
|
22
|
-
file: "files",
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Generated files are namespaced so they never shadow authored files. The
|
|
26
|
-
* filename carries the prefix, while the display name stays as declared, so the sidebar
|
|
27
|
-
* shows the clean name.
|
|
28
|
-
*/
|
|
29
|
-
const WORKER_PREFIX = "worker_";
|
|
30
|
-
export function materializeWorkerSchemaDataSources(manifest, dataDir) {
|
|
31
|
-
// One descriptor per data source key: databases first (source of truth for
|
|
32
|
-
// anything they back), then inline block schemas for keys no database
|
|
33
|
-
// provides.
|
|
34
|
-
const descriptors = new Map();
|
|
35
|
-
for (const database of manifest.databases) {
|
|
36
|
-
descriptors.set(database.key, {
|
|
37
|
-
name: database.config.initialTitle ?? database.key,
|
|
38
|
-
properties: (database.config.schema?.properties ?? {}),
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
for (const block of blockCapabilities(manifest)) {
|
|
42
|
-
for (const [key, slot] of Object.entries(block.config.manifest.dataSources)) {
|
|
43
|
-
const properties = (slot.properties ?? {});
|
|
44
|
-
const existing = descriptors.get(key);
|
|
45
|
-
if (existing !== undefined) {
|
|
46
|
-
// Same key from two blocks with different shapes: slot keys are only
|
|
47
|
-
// unique per block, so one file can't serve both. First block wins;
|
|
48
|
-
// say so instead of leaving the loser silently unbindable.
|
|
49
|
-
if (existing.blockKey !== undefined &&
|
|
50
|
-
!samePropertySchemas(existing.properties, properties)) {
|
|
51
|
-
console.warn(`Blocks "${existing.blockKey}" and "${block.key}" both declare data source ` +
|
|
52
|
-
`"${key}" with different schemas; ${WORKER_PREFIX}${key}.json uses the ` +
|
|
53
|
-
`schema from "${existing.blockKey}". Author a data/ file for "${block.key}" by hand.`);
|
|
54
|
-
}
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
descriptors.set(key, {
|
|
58
|
-
name: slot.name ?? key,
|
|
59
|
-
properties,
|
|
60
|
-
blockKey: block.key,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// A worker with no data sources gets no data/ at all — the folder would
|
|
65
|
-
// only suggest the shell expects files there.
|
|
66
|
-
if (descriptors.size === 0) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
mkdirSync(dataDir, { recursive: true });
|
|
70
|
-
for (const [key, descriptor] of descriptors) {
|
|
71
|
-
// Replace path-hostile characters so the filename stays inside `dataDir`.
|
|
72
|
-
const file = resolve(dataDir, `${WORKER_PREFIX}${fileSafe(key)}.json`);
|
|
73
|
-
if (existsSync(file)) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
writeFileSync(file, `${JSON.stringify(buildSource(descriptor), null, 2)}\n`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function fileSafe(key) {
|
|
80
|
-
return key.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
81
|
-
}
|
|
82
|
-
function samePropertySchemas(left, right) {
|
|
83
|
-
const leftKeys = Object.keys(left).sort();
|
|
84
|
-
const rightKeys = Object.keys(right).sort();
|
|
85
|
-
return (leftKeys.length === rightKeys.length &&
|
|
86
|
-
leftKeys.every((key, index) => key === rightKeys[index] &&
|
|
87
|
-
left[key].type === right[key].type &&
|
|
88
|
-
(left[key].name ?? key) === (right[key].name ?? key)));
|
|
89
|
-
}
|
|
90
|
-
function buildSource(descriptor) {
|
|
91
|
-
const { name, properties } = descriptor;
|
|
92
|
-
const schema = {};
|
|
93
|
-
for (const [propertyKey, property] of Object.entries(properties)) {
|
|
94
|
-
schema[propertyKey] = {
|
|
95
|
-
name: property.name ?? propertyKey,
|
|
96
|
-
type: TYPE_ALIASES[property.type] ?? property.type,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
type: "worker",
|
|
101
|
-
name,
|
|
102
|
-
schema,
|
|
103
|
-
rows: [],
|
|
104
|
-
};
|
|
105
|
-
}
|