@notionhq/workers 0.6.0 → 0.7.0
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/dist/block.d.ts +321 -0
- package/dist/block.d.ts.map +1 -0
- package/dist/block.js +0 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/worker.d.ts +1 -41
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +0 -50
- package/package.json +1 -1
- package/src/block.ts +525 -0
- package/src/index.ts +0 -7
- package/src/worker.test.ts +0 -147
- package/src/worker.ts +1 -59
- package/dist/capabilities/custom-block.d.ts +0 -124
- package/dist/capabilities/custom-block.d.ts.map +0 -1
- package/dist/capabilities/custom-block.js +0 -22
- package/src/capabilities/custom-block.ts +0 -181
package/src/worker.ts
CHANGED
|
@@ -11,11 +11,6 @@ import type {
|
|
|
11
11
|
} from "./capabilities/automation.js";
|
|
12
12
|
import { createAutomationCapability } from "./capabilities/automation.js";
|
|
13
13
|
import type { CapabilityContext } from "./capabilities/context.js";
|
|
14
|
-
import type {
|
|
15
|
-
CustomBlockCapability,
|
|
16
|
-
CustomBlockConfiguration,
|
|
17
|
-
} from "./capabilities/custom-block.js";
|
|
18
|
-
import { createCustomBlockCapability } from "./capabilities/custom-block.js";
|
|
19
14
|
import type {
|
|
20
15
|
NotionManagedOAuthConfiguration,
|
|
21
16
|
OAuthCapability,
|
|
@@ -74,8 +69,7 @@ type Capability =
|
|
|
74
69
|
| AutomationCapability
|
|
75
70
|
| WorkflowCapability
|
|
76
71
|
| OAuthCapability
|
|
77
|
-
| WebhookCapability
|
|
78
|
-
| CustomBlockCapability;
|
|
72
|
+
| WebhookCapability;
|
|
79
73
|
|
|
80
74
|
export type CapabilityType = Capability["_tag"];
|
|
81
75
|
|
|
@@ -111,7 +105,6 @@ type StoredCapability =
|
|
|
111
105
|
| AutomationCapability
|
|
112
106
|
| StoredWorkflowCapability
|
|
113
107
|
| OAuthCapability
|
|
114
|
-
| CustomBlockCapability
|
|
115
108
|
| WebhookCapability;
|
|
116
109
|
|
|
117
110
|
/**
|
|
@@ -616,51 +609,6 @@ export class Worker {
|
|
|
616
609
|
return capability;
|
|
617
610
|
}
|
|
618
611
|
|
|
619
|
-
/**
|
|
620
|
-
* Register a custom block capability.
|
|
621
|
-
*
|
|
622
|
-
* A custom block is a front-end view that the deploy pipeline builds from
|
|
623
|
-
* the source entry into a deployable bundle. It can optionally declare a
|
|
624
|
-
* data-source *schema* (`name`, and optional `description`, `icon`, and
|
|
625
|
-
* `properties`) that the block reads.
|
|
626
|
-
*
|
|
627
|
-
* Example:
|
|
628
|
-
*
|
|
629
|
-
* ```ts
|
|
630
|
-
* const worker = new Worker();
|
|
631
|
-
* export default worker;
|
|
632
|
-
*
|
|
633
|
-
* worker.customBlock("issueBoard", {
|
|
634
|
-
* version: 1,
|
|
635
|
-
* path: "./views/issueBoard",
|
|
636
|
-
* dataSources: {
|
|
637
|
-
* issues: {
|
|
638
|
-
* name: "Issues",
|
|
639
|
-
* properties: {
|
|
640
|
-
* title: { name: "Title", type: "title" },
|
|
641
|
-
* status: { name: "Status", type: "status" },
|
|
642
|
-
* },
|
|
643
|
-
* },
|
|
644
|
-
* },
|
|
645
|
-
* });
|
|
646
|
-
* ```
|
|
647
|
-
*
|
|
648
|
-
* The manifest keys (`version`, `dataSources`) are top-level on the config;
|
|
649
|
-
* the SDK assembles the deploy-wire `CustomBlockManifest` from them. Binding
|
|
650
|
-
* each declared data source to a concrete managed database is instance-level
|
|
651
|
-
* and handled at deploy time — the worker does not emit bindings.
|
|
652
|
-
*
|
|
653
|
-
* @param key - The unique key for this block (the block declaration key).
|
|
654
|
-
* @param config - The custom block configuration (a `project`/`static` source folder + optional `version`/`dataSources` schema).
|
|
655
|
-
* @returns The custom block capability.
|
|
656
|
-
*/
|
|
657
|
-
customBlock(key: string, config: CustomBlockConfiguration): CustomBlockCapability {
|
|
658
|
-
this.#validateUniqueKey(key);
|
|
659
|
-
const capability = createCustomBlockCapability(key, config);
|
|
660
|
-
this.#capabilities.set(key, capability);
|
|
661
|
-
return capability;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
612
|
/**
|
|
665
613
|
* Get all registered capabilities (for discovery) without their handlers.
|
|
666
614
|
*/
|
|
@@ -702,12 +650,6 @@ export class Worker {
|
|
|
702
650
|
);
|
|
703
651
|
}
|
|
704
652
|
|
|
705
|
-
if (capability._tag === "custom_block") {
|
|
706
|
-
throw new Error(
|
|
707
|
-
`Cannot run custom block capability "${key}" - custom blocks only provide configuration`,
|
|
708
|
-
);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
653
|
if (!capability.handler) {
|
|
712
654
|
throw new Error(`Capability "${key}" cannot be executed`);
|
|
713
655
|
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Icon for a custom block data source. Mirrors the server/client
|
|
3
|
-
* `CustomBlockManifestIcon` (`@notionhq/shared/customViews/customBlockManifestTypes`).
|
|
4
|
-
*/
|
|
5
|
-
export type CustomBlockManifestIcon = {
|
|
6
|
-
type: "emoji";
|
|
7
|
-
emoji: string;
|
|
8
|
-
} | {
|
|
9
|
-
type: "external";
|
|
10
|
-
url: string;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Public-API-shaped property type names usable in a custom block manifest.
|
|
14
|
-
*/
|
|
15
|
-
export type CustomBlockManifestPropertyType = "title" | "rich_text" | "number" | "select" | "multi_select" | "status" | "date" | "people" | "files" | "checkbox" | "url" | "email" | "phone_number" | "formula" | "relation" | "rollup" | "created_time" | "created_by" | "last_edited_time" | "last_edited_by" | "last_visited_time" | "button" | "unique_id" | "location" | "verification" | "place";
|
|
16
|
-
/**
|
|
17
|
-
* Describes a single property exposed by a custom block data source.
|
|
18
|
-
*/
|
|
19
|
-
export type CustomBlockManifestProperty = {
|
|
20
|
-
name: string;
|
|
21
|
-
description?: string;
|
|
22
|
-
type: CustomBlockManifestPropertyType;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Rich schema describing one of a custom block's data sources.
|
|
26
|
-
*/
|
|
27
|
-
export type CustomBlockManifestDataSource = {
|
|
28
|
-
/** Display name for the data source. */
|
|
29
|
-
name: string;
|
|
30
|
-
/** Optional human-readable description of the data source. */
|
|
31
|
-
description?: string;
|
|
32
|
-
/** Optional icon for the data source. */
|
|
33
|
-
icon?: CustomBlockManifestIcon;
|
|
34
|
-
/** Optional property schema keyed by property key. */
|
|
35
|
-
properties?: Record<string, CustomBlockManifestProperty>;
|
|
36
|
-
};
|
|
37
|
-
export type CustomBlockManifest = {
|
|
38
|
-
version: 1;
|
|
39
|
-
/**
|
|
40
|
-
* The block's datasources schema, mapping keys you name to {@link CustomBlockManifestDataSource}
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
*
|
|
44
|
-
* {
|
|
45
|
-
* "myDataSource": {
|
|
46
|
-
* "name": "My Data Source",
|
|
47
|
-
* "description": "A description of my data source",
|
|
48
|
-
* "icon": "icon.png",
|
|
49
|
-
* "properties": {
|
|
50
|
-
* "property1": {
|
|
51
|
-
* "name": "Property 1",
|
|
52
|
-
* "type": "string"
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* }
|
|
56
|
-
* }
|
|
57
|
-
*/
|
|
58
|
-
dataSources: Record<string, CustomBlockManifestDataSource>;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* A custom block is a front-end web app served in an iframe in the client with live data access.
|
|
62
|
-
*
|
|
63
|
-
* Available `type`s are `project` (a buildable project dir) and `static` (an already-built dir served as-is).
|
|
64
|
-
*/
|
|
65
|
-
export type CustomBlockConfiguration = ({
|
|
66
|
-
/** Buildable project dir (the default). */
|
|
67
|
-
type?: "project";
|
|
68
|
-
/** Path to the project dir, relative to the worker root (e.g. `"./blocks/foo"`). */
|
|
69
|
-
path: string;
|
|
70
|
-
/** Build command run in `path`. Defaults to `npm run build`. */
|
|
71
|
-
command?: string;
|
|
72
|
-
/** Built-output dir relative to `path`. Defaults to `dist`. */
|
|
73
|
-
output?: string;
|
|
74
|
-
} | {
|
|
75
|
-
/** An already-built browser-bundle dir; served as-is, no build step. */
|
|
76
|
-
type: "static";
|
|
77
|
-
/** Path to the prebuilt dir, relative to the worker root. */
|
|
78
|
-
path: string;
|
|
79
|
-
command?: never;
|
|
80
|
-
output?: never;
|
|
81
|
-
}) & Partial<CustomBlockManifest>;
|
|
82
|
-
/**
|
|
83
|
-
* The build source of a custom block, mirroring the server's
|
|
84
|
-
* `BlockSourceDeclaration`. `project` is a buildable dir (`command` defaults to
|
|
85
|
-
* `npm run build`, `output` to `dist`); `static` is an already-built dir served
|
|
86
|
-
* as-is.
|
|
87
|
-
*/
|
|
88
|
-
export type BlockSourceDeclaration = {
|
|
89
|
-
type: "project";
|
|
90
|
-
path: string;
|
|
91
|
-
command?: string;
|
|
92
|
-
output?: string;
|
|
93
|
-
} | {
|
|
94
|
-
type: "static";
|
|
95
|
-
path: string;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Config payload carried in the runtime manifest for a `_tag: "custom_block"`
|
|
99
|
-
* capability entry. The server parses this (see `RawBlockCapabilityConfig` in
|
|
100
|
-
* `capabilities-service.ts`): `source` is the build entry and `manifest` is the
|
|
101
|
-
* author-declared {@link CustomBlockManifest} describing the block's data-source
|
|
102
|
-
* schema. Data-source *bindings* are instance-level and are not carried here.
|
|
103
|
-
*/
|
|
104
|
-
export type CustomBlockCapabilityConfig = {
|
|
105
|
-
source: BlockSourceDeclaration;
|
|
106
|
-
manifest: CustomBlockManifest;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* A custom-block capability entry. Unlike other capabilities it has no runtime
|
|
110
|
-
* handler — it is a build-time/deploy-time declaration only, carried through
|
|
111
|
-
* the manifest so the server can build and bind the block on deploy.
|
|
112
|
-
*/
|
|
113
|
-
export type CustomBlockCapability = {
|
|
114
|
-
readonly _tag: "custom_block";
|
|
115
|
-
readonly key: string;
|
|
116
|
-
readonly config: CustomBlockCapabilityConfig;
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* Builds a custom-block capability entry from its authoring configuration. The
|
|
120
|
-
* author-declared `dataSources` schema is carried verbatim into the block
|
|
121
|
-
* {@link CustomBlockManifest}; no bindings are emitted.
|
|
122
|
-
*/
|
|
123
|
-
export declare function createCustomBlockCapability(key: string, config: CustomBlockConfiguration): CustomBlockCapability;
|
|
124
|
-
//# sourceMappingURL=custom-block.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-block.d.ts","sourceRoot":"","sources":["../../src/capabilities/custom-block.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAChC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACxC,OAAO,GACP,WAAW,GACX,QAAQ,GACR,QAAQ,GACR,cAAc,GACd,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,OAAO,GACP,UAAU,GACV,KAAK,GACL,OAAO,GACP,cAAc,GACd,SAAS,GACT,UAAU,GACV,QAAQ,GACR,cAAc,GACd,YAAY,GACZ,kBAAkB,GAClB,gBAAgB,GAChB,mBAAmB,GACnB,QAAQ,GACR,WAAW,GACX,UAAU,GACV,cAAc,GACd,OAAO,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,+BAA+B,CAAC;CACtC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC3C,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,IAAI,CAAC,EAAE,uBAAuB,CAAC;IAC/B,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC,OAAO,EAAE,CAAC,CAAC;IACX;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG,CACpC;IACA,2CAA2C;IAC3C,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;CACf,GACD;IACA,wEAAwE;IACxE,IAAI,EAAE,QAAQ,CAAC;IACf,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,CAAC;CACd,CACH,GACA,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAC/B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACzC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,QAAQ,EAAE,mBAAmB,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG;IACnC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,2BAA2B,CAC1C,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,wBAAwB,GAC9B,qBAAqB,CAsBvB"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
function createCustomBlockCapability(key, config) {
|
|
2
|
-
const source = config.type === "static" ? { type: "static", path: config.path } : {
|
|
3
|
-
type: "project",
|
|
4
|
-
path: config.path,
|
|
5
|
-
...config.command !== void 0 ? { command: config.command } : {},
|
|
6
|
-
...config.output !== void 0 ? { output: config.output } : {}
|
|
7
|
-
};
|
|
8
|
-
return {
|
|
9
|
-
_tag: "custom_block",
|
|
10
|
-
key,
|
|
11
|
-
config: {
|
|
12
|
-
source,
|
|
13
|
-
manifest: {
|
|
14
|
-
version: config.version ?? 1,
|
|
15
|
-
dataSources: config.dataSources ?? {}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
createCustomBlockCapability
|
|
22
|
-
};
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// Custom Block Authoring API
|
|
3
|
-
// ============================================================================
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Icon for a custom block data source. Mirrors the server/client
|
|
7
|
-
* `CustomBlockManifestIcon` (`@notionhq/shared/customViews/customBlockManifestTypes`).
|
|
8
|
-
*/
|
|
9
|
-
export type CustomBlockManifestIcon =
|
|
10
|
-
| { type: "emoji"; emoji: string }
|
|
11
|
-
| { type: "external"; url: string };
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Public-API-shaped property type names usable in a custom block manifest.
|
|
15
|
-
*/
|
|
16
|
-
export type CustomBlockManifestPropertyType =
|
|
17
|
-
| "title"
|
|
18
|
-
| "rich_text"
|
|
19
|
-
| "number"
|
|
20
|
-
| "select"
|
|
21
|
-
| "multi_select"
|
|
22
|
-
| "status"
|
|
23
|
-
| "date"
|
|
24
|
-
| "people"
|
|
25
|
-
| "files"
|
|
26
|
-
| "checkbox"
|
|
27
|
-
| "url"
|
|
28
|
-
| "email"
|
|
29
|
-
| "phone_number"
|
|
30
|
-
| "formula"
|
|
31
|
-
| "relation"
|
|
32
|
-
| "rollup"
|
|
33
|
-
| "created_time"
|
|
34
|
-
| "created_by"
|
|
35
|
-
| "last_edited_time"
|
|
36
|
-
| "last_edited_by"
|
|
37
|
-
| "last_visited_time"
|
|
38
|
-
| "button"
|
|
39
|
-
| "unique_id"
|
|
40
|
-
| "location"
|
|
41
|
-
| "verification"
|
|
42
|
-
| "place";
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Describes a single property exposed by a custom block data source.
|
|
46
|
-
*/
|
|
47
|
-
export type CustomBlockManifestProperty = {
|
|
48
|
-
name: string;
|
|
49
|
-
description?: string;
|
|
50
|
-
type: CustomBlockManifestPropertyType;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Rich schema describing one of a custom block's data sources.
|
|
55
|
-
*/
|
|
56
|
-
export type CustomBlockManifestDataSource = {
|
|
57
|
-
/** Display name for the data source. */
|
|
58
|
-
name: string;
|
|
59
|
-
/** Optional human-readable description of the data source. */
|
|
60
|
-
description?: string;
|
|
61
|
-
/** Optional icon for the data source. */
|
|
62
|
-
icon?: CustomBlockManifestIcon;
|
|
63
|
-
/** Optional property schema keyed by property key. */
|
|
64
|
-
properties?: Record<string, CustomBlockManifestProperty>;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export type CustomBlockManifest = {
|
|
68
|
-
version: 1;
|
|
69
|
-
/**
|
|
70
|
-
* The block's datasources schema, mapping keys you name to {@link CustomBlockManifestDataSource}
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
*
|
|
74
|
-
* {
|
|
75
|
-
* "myDataSource": {
|
|
76
|
-
* "name": "My Data Source",
|
|
77
|
-
* "description": "A description of my data source",
|
|
78
|
-
* "icon": "icon.png",
|
|
79
|
-
* "properties": {
|
|
80
|
-
* "property1": {
|
|
81
|
-
* "name": "Property 1",
|
|
82
|
-
* "type": "string"
|
|
83
|
-
* }
|
|
84
|
-
* }
|
|
85
|
-
* }
|
|
86
|
-
* }
|
|
87
|
-
*/
|
|
88
|
-
dataSources: Record<string, CustomBlockManifestDataSource>;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* A custom block is a front-end web app served in an iframe in the client with live data access.
|
|
93
|
-
*
|
|
94
|
-
* Available `type`s are `project` (a buildable project dir) and `static` (an already-built dir served as-is).
|
|
95
|
-
*/
|
|
96
|
-
export type CustomBlockConfiguration = (
|
|
97
|
-
| {
|
|
98
|
-
/** Buildable project dir (the default). */
|
|
99
|
-
type?: "project";
|
|
100
|
-
/** Path to the project dir, relative to the worker root (e.g. `"./blocks/foo"`). */
|
|
101
|
-
path: string;
|
|
102
|
-
/** Build command run in `path`. Defaults to `npm run build`. */
|
|
103
|
-
command?: string;
|
|
104
|
-
/** Built-output dir relative to `path`. Defaults to `dist`. */
|
|
105
|
-
output?: string;
|
|
106
|
-
}
|
|
107
|
-
| {
|
|
108
|
-
/** An already-built browser-bundle dir; served as-is, no build step. */
|
|
109
|
-
type: "static";
|
|
110
|
-
/** Path to the prebuilt dir, relative to the worker root. */
|
|
111
|
-
path: string;
|
|
112
|
-
command?: never;
|
|
113
|
-
output?: never;
|
|
114
|
-
}
|
|
115
|
-
) &
|
|
116
|
-
Partial<CustomBlockManifest>;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* The build source of a custom block, mirroring the server's
|
|
120
|
-
* `BlockSourceDeclaration`. `project` is a buildable dir (`command` defaults to
|
|
121
|
-
* `npm run build`, `output` to `dist`); `static` is an already-built dir served
|
|
122
|
-
* as-is.
|
|
123
|
-
*/
|
|
124
|
-
export type BlockSourceDeclaration =
|
|
125
|
-
| { type: "project"; path: string; command?: string; output?: string }
|
|
126
|
-
| { type: "static"; path: string };
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Config payload carried in the runtime manifest for a `_tag: "custom_block"`
|
|
130
|
-
* capability entry. The server parses this (see `RawBlockCapabilityConfig` in
|
|
131
|
-
* `capabilities-service.ts`): `source` is the build entry and `manifest` is the
|
|
132
|
-
* author-declared {@link CustomBlockManifest} describing the block's data-source
|
|
133
|
-
* schema. Data-source *bindings* are instance-level and are not carried here.
|
|
134
|
-
*/
|
|
135
|
-
export type CustomBlockCapabilityConfig = {
|
|
136
|
-
source: BlockSourceDeclaration;
|
|
137
|
-
manifest: CustomBlockManifest;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* A custom-block capability entry. Unlike other capabilities it has no runtime
|
|
142
|
-
* handler — it is a build-time/deploy-time declaration only, carried through
|
|
143
|
-
* the manifest so the server can build and bind the block on deploy.
|
|
144
|
-
*/
|
|
145
|
-
export type CustomBlockCapability = {
|
|
146
|
-
readonly _tag: "custom_block";
|
|
147
|
-
readonly key: string;
|
|
148
|
-
readonly config: CustomBlockCapabilityConfig;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Builds a custom-block capability entry from its authoring configuration. The
|
|
153
|
-
* author-declared `dataSources` schema is carried verbatim into the block
|
|
154
|
-
* {@link CustomBlockManifest}; no bindings are emitted.
|
|
155
|
-
*/
|
|
156
|
-
export function createCustomBlockCapability(
|
|
157
|
-
key: string,
|
|
158
|
-
config: CustomBlockConfiguration,
|
|
159
|
-
): CustomBlockCapability {
|
|
160
|
-
const source: BlockSourceDeclaration =
|
|
161
|
-
config.type === "static"
|
|
162
|
-
? { type: "static", path: config.path }
|
|
163
|
-
: {
|
|
164
|
-
type: "project",
|
|
165
|
-
path: config.path,
|
|
166
|
-
...(config.command !== undefined ? { command: config.command } : {}),
|
|
167
|
-
...(config.output !== undefined ? { output: config.output } : {}),
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
_tag: "custom_block",
|
|
172
|
-
key,
|
|
173
|
-
config: {
|
|
174
|
-
source,
|
|
175
|
-
manifest: {
|
|
176
|
-
version: config.version ?? 1,
|
|
177
|
-
dataSources: config.dataSources ?? {},
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
}
|