@kubohiroya/turbowarp-cloudflare-worker 0.2.0 → 0.3.1

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.
@@ -0,0 +1,167 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://kubohiroya.github.io/turbowarp-http-server-cloudflare/schemas/worker-ir.schema.json",
4
+ "type": "object",
5
+ "required": [
6
+ "name"
7
+ ],
8
+ "properties": {
9
+ "name": {
10
+ "type": "string",
11
+ "minLength": 1
12
+ },
13
+ "handlers": {
14
+ "items": {
15
+ "type": "object",
16
+ "required": [
17
+ "method",
18
+ "path",
19
+ "responseText"
20
+ ],
21
+ "properties": {
22
+ "method": {
23
+ "type": "string",
24
+ "minLength": 1
25
+ },
26
+ "path": {
27
+ "type": "string",
28
+ "minLength": 1
29
+ },
30
+ "responseText": {
31
+ "type": "string",
32
+ "minLength": 1
33
+ }
34
+ }
35
+ }
36
+ },
37
+ "compatibilityDate": {
38
+ "type": "string",
39
+ "minLength": 1
40
+ },
41
+ "auth": {
42
+ "type": "object",
43
+ "required": [
44
+ "mode"
45
+ ],
46
+ "properties": {
47
+ "mode": {
48
+ "const": "external-oauth-oidc"
49
+ },
50
+ "providers": {
51
+ "items": {
52
+ "enum": [
53
+ "google",
54
+ "microsoft",
55
+ "github"
56
+ ]
57
+ }
58
+ },
59
+ "session": {
60
+ "enum": [
61
+ "signed-cookie",
62
+ "bearer-jwt",
63
+ "cloudflare-access"
64
+ ]
65
+ },
66
+ "protectedRoutes": {
67
+ "type": "array",
68
+ "items": {
69
+ "type": "object",
70
+ "required": [
71
+ "method",
72
+ "path",
73
+ "onUnauthenticated"
74
+ ],
75
+ "properties": {
76
+ "method": {
77
+ "type": "string",
78
+ "minLength": 1
79
+ },
80
+ "path": {
81
+ "type": "string",
82
+ "minLength": 1
83
+ },
84
+ "onUnauthenticated": {
85
+ "enum": [
86
+ "redirect-login",
87
+ "json-401",
88
+ "forbid-403"
89
+ ]
90
+ },
91
+ "auth": {
92
+ "enum": [
93
+ "session",
94
+ "bearer-jwt"
95
+ ]
96
+ },
97
+ "requiredRole": {
98
+ "type": "string",
99
+ "minLength": 1
100
+ },
101
+ "requiredScopes": {
102
+ "type": "array",
103
+ "items": {
104
+ "type": "string",
105
+ "minLength": 1
106
+ }
107
+ }
108
+ }
109
+ }
110
+ },
111
+ "loginPath": {
112
+ "type": "string",
113
+ "minLength": 1
114
+ },
115
+ "callbackPath": {
116
+ "type": "string",
117
+ "minLength": 1
118
+ },
119
+ "logoutPath": {
120
+ "type": "string",
121
+ "minLength": 1
122
+ },
123
+ "mePath": {
124
+ "type": "string",
125
+ "minLength": 1
126
+ },
127
+ "jwtIssuerEnv": {
128
+ "type": "string",
129
+ "minLength": 1
130
+ },
131
+ "jwtAudienceEnv": {
132
+ "type": "string",
133
+ "minLength": 1
134
+ }
135
+ }
136
+ },
137
+ "storage": {
138
+ "type": "array",
139
+ "items": {
140
+ "type": "object",
141
+ "required": [
142
+ "kind",
143
+ "binding",
144
+ "name"
145
+ ],
146
+ "properties": {
147
+ "kind": {
148
+ "enum": [
149
+ "d1",
150
+ "kv",
151
+ "r2",
152
+ "durable-object"
153
+ ]
154
+ },
155
+ "binding": {
156
+ "type": "string",
157
+ "minLength": 1
158
+ },
159
+ "name": {
160
+ "type": "string",
161
+ "minLength": 1
162
+ }
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
@@ -0,0 +1,41 @@
1
+ import type {SourceEditorOptions} from '@kubohiroya/turbowarp-extension-data-editor/schema';
2
+ import {extensionConfig} from './config.js';
3
+ import {canonicalBundle, sourceBinding} from './source-editor.js';
4
+ import handler from '../schemas/handler-ir.schema.json' with {type: 'json'};
5
+ import worker from '../schemas/worker-ir.schema.json' with {type: 'json'};
6
+ import routes from '../schemas/protected-routes.schema.json' with {type: 'json'};
7
+ import auth from '../schemas/auth-ir.schema.json' with {type: 'json'};
8
+ import {parseWorkerIr} from './ir.js';
9
+ export const cloudflareSchemaBundles = {
10
+ handler: canonicalBundle('turbowarp-http-server-cloudflare', 'handler-ir', handler, {path: 'src/ir.ts', symbol: 'parseWorkerIr'}),
11
+ worker: canonicalBundle('turbowarp-http-server-cloudflare', 'worker-ir', worker, {path: 'src/ir.ts', symbol: 'parseWorkerIr'}),
12
+ routes: canonicalBundle('turbowarp-http-server-cloudflare', 'protected-routes', routes, {path: 'src/ir.ts', symbol: 'parseWorkerIr'}),
13
+ auth: canonicalBundle('turbowarp-http-server-cloudflare', 'auth-ir', auth, {path: 'src/ir.ts', symbol: 'parseWorkerIr'})
14
+ };
15
+ function handlersSource(source: string): void {
16
+ const data: unknown = JSON.parse(source);
17
+ parseWorkerIr({name: 'editor-validation', handlers: Array.isArray(data) ? data : [data]});
18
+ }
19
+ function routesSource(source: string): void {
20
+ const data: unknown = JSON.parse(source);
21
+ parseWorkerIr({name: 'editor-validation', auth: {mode: 'external-oauth-oidc', providers: [], protectedRoutes: Array.isArray(data) ? data : [data]}});
22
+ }
23
+ const methodHints = {'ui:enum': ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD']};
24
+ const routeHints = {method: {'ui:enum': ['*', ...methodHints['ui:enum']]}};
25
+ const authHints = {protectedRoutes: {items: routeHints}};
26
+ const handlerHints = {method: methodHints, items: {method: methodHints}};
27
+ const handlerBinding = () => sourceBinding('HANDLERS', cloudflareSchemaBundles.handler, JSON.parse, handlersSource,
28
+ 'json', handlerHints);
29
+ const authBinding = () => sourceBinding('AUTH', cloudflareSchemaBundles.auth, JSON.parse,
30
+ source => parseWorkerIr({name: 'editor-validation', auth: JSON.parse(source)}), 'json', authHints);
31
+ const definitions = [
32
+ {editorId: 'worker-handlers-source', opcodes: ['createWorkerIr'], bindings: [handlerBinding()]},
33
+ {editorId: 'worker-ir-source', opcodes: ['generateFilesJson'], bindings: [sourceBinding('IR', cloudflareSchemaBundles.worker, JSON.parse, source => parseWorkerIr(JSON.parse(source)), 'json', {handlers: {items: {method: methodHints}}, auth: authHints})]},
34
+ {editorId: 'protected-routes-source', opcodes: ['createAuthIr'], bindings: [sourceBinding('PROTECTED_ROUTES', cloudflareSchemaBundles.routes, JSON.parse, routesSource, 'json', {...routeHints, items: routeHints})]},
35
+ {editorId: 'worker-with-auth-source', opcodes: ['createWorkerIrWithAuth'], bindings: [handlerBinding(), authBinding()]}
36
+ ];
37
+
38
+ export const sourceEditorDefinitions: readonly SourceEditorOptions[] = definitions.map(({editorId, opcodes, bindings}) => ({
39
+ apiVersion: 1, extensionId: extensionConfig.id, editorId, opcodes: opcodes.map(opcode => `${extensionConfig.id}_${opcode}`), bindings,
40
+ validationContext: () => ({consumerId: extensionConfig.id, nowMs: Date.now(), settings: null})
41
+ }));
package/src/extension.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import {fixedInputRegistration} from './fixed-input-editors.js';
2
+ import {sourceEditorDefinitions} from './editor-schema.js';
3
+ import {registerSourceEditors} from './source-editor.js';
1
4
  import {extensionConfig} from './config';
2
5
  import definitions from './block-definitions.json';
3
6
  import {generateCloudflareWorkerFiles} from './generator.js';
@@ -35,7 +38,14 @@ const authBlockIconUri =
35
38
  'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCI+PHJlY3QgeD0iNiIgeT0iMTgiIHdpZHRoPSIzNiIgaGVpZ2h0PSIyNCIgcng9IjQiIGZpbGw9IiNGNzk1MjEiLz48cGF0aCBkPSJNMTUgMTh2LTZjMC01IDQtOSA5LTlzOSA0IDkgOXY2IiBmaWxsPSJub25lIiBzdHJva2U9IiMxRjI5MzciIHN0cm9rZS13aWR0aD0iNCIvPjxjaXJjbGUgY3g9IjI0IiBjeT0iMzAiIHI9IjMiIGZpbGw9IiMxRjI5MzciLz48L3N2Zz4=';
36
39
 
37
40
  export class CloudflareExtension implements TurboWarpExtension {
41
+ private readonly fixedInputs = fixedInputRegistration(typeof Scratch === 'undefined' ? undefined : Scratch);
42
+
43
+ private readonly unregisterSourceEditors: () => void;
44
+ public constructor() {this.unregisterSourceEditors = registerSourceEditors(Scratch, sourceEditorDefinitions);}
45
+ public dispose(): void {this.fixedInputs.dispose(); this.unregisterSourceEditors();}
46
+
38
47
  public getInfo(): Record<string, unknown> {
48
+ this.fixedInputs.ensure(paletteDefinitions.flatMap(block => 'opcode' in block ? [`${extensionConfig.id}_${block.opcode}`] : []));
39
49
  return {
40
50
  id: extensionConfig.id,
41
51
  name: Scratch.translate(definitions.extensionName),
@@ -0,0 +1,206 @@
1
+ import {parseFixedNumberInput} from '@kubohiroya/turbowarp-extension-data-editor/schema';
2
+ import type {FixedInputBinding, FixedInputEditorOptions, JsonValue, LiteralValue} from '@kubohiroya/turbowarp-extension-data-editor';
3
+ import {fixedInputBundle} from './fixed-input-schema.js';
4
+ const extensionId = "kubohiroyacloudflareworker";
5
+ const repository = "turbowarp-cloudflare-worker";
6
+ interface Field {opcode: string; argument: string; control: 'number' | 'enum'; choices: readonly string[];
7
+ normalization: string; shape: string; maxBytes: boolean}
8
+ const fields: readonly Field[] = [
9
+ {
10
+ "opcode": "createHandlerIr",
11
+ "argument": "METHOD",
12
+ "control": "enum",
13
+ "choices": [
14
+ "GET",
15
+ "POST",
16
+ "PUT",
17
+ "PATCH",
18
+ "DELETE",
19
+ "OPTIONS",
20
+ "HEAD"
21
+ ],
22
+ "normalization": "method",
23
+ "shape": "text.TEXT",
24
+ "maxBytes": false
25
+ },
26
+ {
27
+ "opcode": "createProtectedRouteIr",
28
+ "argument": "METHOD",
29
+ "control": "enum",
30
+ "choices": [
31
+ "GET",
32
+ "POST",
33
+ "PUT",
34
+ "PATCH",
35
+ "DELETE",
36
+ "OPTIONS",
37
+ "HEAD",
38
+ "*"
39
+ ],
40
+ "normalization": "method",
41
+ "shape": "text.TEXT",
42
+ "maxBytes": false
43
+ },
44
+ {
45
+ "opcode": "createProtectedRouteIr",
46
+ "argument": "ON_UNAUTHENTICATED",
47
+ "control": "enum",
48
+ "choices": [
49
+ "redirect-login",
50
+ "json-401",
51
+ "forbid-403"
52
+ ],
53
+ "normalization": "trim",
54
+ "shape": "text.TEXT",
55
+ "maxBytes": false
56
+ },
57
+ {
58
+ "opcode": "createBearerRouteIr",
59
+ "argument": "METHOD",
60
+ "control": "enum",
61
+ "choices": [
62
+ "GET",
63
+ "POST",
64
+ "PUT",
65
+ "PATCH",
66
+ "DELETE",
67
+ "OPTIONS",
68
+ "HEAD",
69
+ "*"
70
+ ],
71
+ "normalization": "method",
72
+ "shape": "text.TEXT",
73
+ "maxBytes": false
74
+ },
75
+ {
76
+ "opcode": "createBearerRoleRouteIr",
77
+ "argument": "METHOD",
78
+ "control": "enum",
79
+ "choices": [
80
+ "GET",
81
+ "POST",
82
+ "PUT",
83
+ "PATCH",
84
+ "DELETE",
85
+ "OPTIONS",
86
+ "HEAD",
87
+ "*"
88
+ ],
89
+ "normalization": "method",
90
+ "shape": "text.TEXT",
91
+ "maxBytes": false
92
+ },
93
+ {
94
+ "opcode": "createBearerScopeRouteIr",
95
+ "argument": "METHOD",
96
+ "control": "enum",
97
+ "choices": [
98
+ "GET",
99
+ "POST",
100
+ "PUT",
101
+ "PATCH",
102
+ "DELETE",
103
+ "OPTIONS",
104
+ "HEAD",
105
+ "*"
106
+ ],
107
+ "normalization": "method",
108
+ "shape": "text.TEXT",
109
+ "maxBytes": false
110
+ }
111
+ ];
112
+ function literalString(value: JsonValue | LiteralValue): string {
113
+ if (typeof value !== 'string') throw new TypeError('Expected a string literal.');
114
+ return value;
115
+ }
116
+ /** Legacy nonempty finite aliases are projections; opening never creates a write. */
117
+ export function existingFixedNumber(value: JsonValue | LiteralValue): number {
118
+ if ((typeof value !== 'string' && typeof value !== 'number') ||
119
+ (typeof value === 'string' && value.trim() === '')) throw new TypeError('Unavailable numeric projection.');
120
+ const number = Number(value);
121
+ if (!Number.isFinite(number)) throw new TypeError('Unavailable numeric projection.');
122
+ return number;
123
+ }
124
+ function normalizeChoice(field: Field, raw: string): string {
125
+ if (field.normalization === 'lowercase') return raw.toLowerCase();
126
+ if (field.normalization === 'method') return raw.trim().toUpperCase();
127
+ if (field.normalization === 'trim') return raw.trim();
128
+ if (field.normalization === 'parse-format') {
129
+ const lower = raw.trim().toLowerCase();
130
+ return lower === 'json' ? 'JSON' : lower === 'yaml' ? 'YAML' : lower === 'auto' ? 'auto' : raw;
131
+ }
132
+ return raw;
133
+ }
134
+ function binding(field: Field): FixedInputBinding {
135
+ return {argument: field.argument, schemaBundle: fixedInputBundle(field.opcode, field.argument),
136
+ control: {kind: field.control, ...(field.control === 'enum' ? {choices: field.choices.map(value => ({value}))} : {})},
137
+ read(value) {return field.control === 'number' ? existingFixedNumber(value) : normalizeChoice(field, literalString(value));},
138
+ encode(value) {
139
+ if (field.control === 'number') {
140
+ const parsed = parseFixedNumberInput(value);
141
+ if (parsed.kind !== 'valid') throw new TypeError('Invalid new numeric input.');
142
+ return parsed.token;
143
+ }
144
+ const raw = literalString(value), normalized = normalizeChoice(field, raw);
145
+ if (!field.choices.includes(normalized)) throw new TypeError('Unsupported fixed choice.');
146
+ return field.shape === 'menu-shadow' || field.shape === 'direct-field-dropdown' ? normalized : raw;
147
+ },
148
+ validateCandidate(value) {
149
+ try {
150
+ if (field.control === 'number') {
151
+ const number = existingFixedNumber(value);
152
+ if (field.maxBytes && (!Number.isSafeInteger(Math.trunc(number)) || Math.trunc(number) < 1)) return [{message: 'Invalid named body size.'}];
153
+ return [];
154
+ }
155
+ return field.choices.includes(normalizeChoice(field, literalString(value))) ? [] : [{message: 'Unsupported fixed choice.'}];
156
+ } catch {return [{message: 'Invalid fixed input.'}];}
157
+ }
158
+ };
159
+ }
160
+ export const fixedInputEditors: readonly FixedInputEditorOptions[] = [...new Set(fields.map(f => f.opcode))].map(opcode => ({
161
+ apiVersion: 1, extensionId, editorId: `${opcode}-fixed-inputs`, opcodes: [`${extensionId}_${opcode}`],
162
+ contractId: `${repository}/${opcode}`, contractRevision: 'fixed-inputs-v1',
163
+ bindings: fields.filter(field => field.opcode === opcode).map(binding),
164
+ validationContext: () => ({consumerId: repository, nowMs: 0, settings: null})
165
+ }));
166
+
167
+ interface OptionalFixedHost {
168
+ gui?: {blockEditors?: {apiVersion?: number; registerFixedInputEditor?: (definition: FixedInputEditorOptions) => () => void}};
169
+ vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}};
170
+ }
171
+ /** Registration follows the advertised opcode membership and the optional host capability. */
172
+ export function fixedInputRegistration(scratch: unknown) {
173
+ const host = (scratch ?? {}) as OptionalFixedHost;
174
+ let active: unknown;
175
+ let membership = '';
176
+ const removers: (() => void)[] = [];
177
+ let stopped = false;
178
+ const clear = () => {
179
+ host.vm?.runtime?.off?.('RUNTIME_DISPOSED', shutdown);
180
+ for (const remove of removers.splice(0).reverse()) remove();
181
+ active = undefined;
182
+ membership = '';
183
+ };
184
+ const shutdown = () => {stopped = true; clear();};
185
+ return {
186
+ ensure(visibleOpcodes: readonly string[]) {
187
+ const api = host.gui?.blockEditors;
188
+ const definitions = fixedInputEditors.filter(definition => definition.opcodes.every(opcode => visibleOpcodes.includes(opcode)));
189
+ const key = definitions.map(definition => definition.editorId).join(',');
190
+ if (stopped || (api === active && membership === key)) return;
191
+ clear();
192
+ if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== 'function' || !definitions.length) return;
193
+ try {
194
+ for (const definition of definitions) {
195
+ const remove = api.registerFixedInputEditor.call(api, definition);
196
+ if (typeof remove !== 'function') throw new TypeError('Invalid fixed input cleanup.');
197
+ removers.push(remove);
198
+ }
199
+ active = api;
200
+ membership = key;
201
+ host.vm?.runtime?.on?.('RUNTIME_DISPOSED', shutdown);
202
+ } catch (error) {clear(); throw error;}
203
+ },
204
+ dispose: shutdown
205
+ };
206
+ }
@@ -0,0 +1,17 @@
1
+ import type {SchemaBundle, SchemaDocument} from '@kubohiroya/turbowarp-extension-data-editor/schema';
2
+ import document from '../schemas/block-editor-fixed-inputs.schema.json' with {type: 'json'};
3
+ import protectedRoutes from '../schemas/protected-routes.schema.json' with {type: 'json'};
4
+ const repository = "turbowarp-cloudflare-worker";
5
+ /** The owner JSON document is canonical; this selects a primitive field fragment. */
6
+ export function fixedInputBundle(opcode: string, argument: string): SchemaBundle {
7
+ const pointer = `#/$defs/${opcode}/properties/${argument}`;
8
+ const source = {repository, path: 'schemas/block-editor-fixed-inputs.schema.json', symbol: pointer};
9
+ const blocks = document.$defs as Record<string, {properties: Record<string, SchemaDocument>}>;
10
+ return {identity: {ownerId: repository, contractId: opcode, revision: 'fixed-inputs-v1', variantId: argument},
11
+ dialect: '2020-12', root: {retrievalUri: document.$id, document: blocks[opcode]!.properties[argument]!,
12
+ artifact: {role: 'canonical-schema', source}},
13
+ resources: [{retrievalUri: protectedRoutes.$id, document: protectedRoutes as unknown as SchemaDocument,
14
+ artifact: {role: 'canonical-schema', source: {repository, path: 'schemas/protected-routes.schema.json'}}}],
15
+ provenance: {canonicalSources: [source, {repository, path: 'schemas/protected-routes.schema.json'}, {repository, path: 'src/extension.ts', symbol: opcode}],
16
+ generatedFiles: [], referenceSchemas: [], generationSources: []}};
17
+ }
@@ -0,0 +1,57 @@
1
+ import {compileSchemaBundle, validateSchemaInput} from '@kubohiroya/turbowarp-extension-data-editor/schema';
2
+ import type {SchemaBundle, SchemaDocument, SchemaJsonValue, SourceBinding, SourceEditorOptions} from '@kubohiroya/turbowarp-extension-data-editor/schema';
3
+
4
+ export function canonicalBundle(ownerId: string, contractId: string, document: SchemaDocument, ownerSource: {path: string; symbol: string}): SchemaBundle {
5
+ const path = `schemas/${contractId}.schema.json`;
6
+ const source = {repository: ownerId, path};
7
+ return {
8
+ identity: {ownerId, contractId, revision: 'source-forms-v1', variantId: 'default'},
9
+ dialect: '2020-12',
10
+ root: {retrievalUri: `https://kubohiroya.github.io/${ownerId}/schemas/${contractId}.schema.json`, document,
11
+ artifact: {role: 'canonical-schema', source}},
12
+ resources: [], provenance: {canonicalSources: [source, {repository: ownerId, ...ownerSource}], generatedFiles: [], referenceSchemas: [], generationSources: []}
13
+ };
14
+ }
15
+
16
+ export function sourceBinding(argument: string, bundle: SchemaBundle,
17
+ read: (source: string) => unknown, check: (source: string) => unknown = read,
18
+ format: 'json' | 'yaml' = 'json', uiSchema?: SourceBinding['variants'][number]['uiSchema']): SourceBinding {
19
+ const compiled = compileSchemaBundle(bundle);
20
+ return {
21
+ argument,
22
+ variants: [{variantId: 'default', format, schemaBundle: bundle, ...(uiSchema ? {uiSchema} : {})}],
23
+ decode(source) {return {source, format, variantId: 'default', data: read(source) as SchemaJsonValue};},
24
+ validateSource(source, context) {
25
+ if (compiled.kind !== 'compiled') return {source, result: {kind: 'schema-error', diagnostics: [{code: 'source-schema-invalid'}]}};
26
+ try {
27
+ const data = read(source) as SchemaJsonValue;
28
+ return {source, result: validateSchemaInput(compiled.validator, data, {context,
29
+ ownerValidate: () => {
30
+ try {check(source); return {kind: 'valid', issues: []};}
31
+ catch {return {kind: 'invalid', issues: [{dataPath: '', ruleId: 'source-owner-invalid'}]};}
32
+ }})};
33
+ } catch {return {source, result: {kind: 'invalid', diagnostics: [{code: 'source-decode-invalid'}]}};}
34
+ }
35
+ };
36
+ }
37
+
38
+ /** The optional capability keeps legacy hosts and the startup flag safely inactive. */
39
+ export function registerSourceEditors(scratch: unknown, definitions: readonly SourceEditorOptions[]): () => void {
40
+ const host = scratch as {gui?: {blockEditors?: {apiVersion?: number; registerSourceEditor?: (options: SourceEditorOptions) => () => void}};
41
+ vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}}};
42
+ const api = host.gui?.blockEditors;
43
+ if (api?.apiVersion !== 1 || typeof api.registerSourceEditor !== 'function') return () => {};
44
+ const removers: (() => void)[] = [];
45
+ let active = true;
46
+ const dispose = () => {
47
+ if (!active) return;
48
+ active = false;
49
+ host.vm?.runtime?.off?.('RUNTIME_DISPOSED', dispose);
50
+ for (const remove of removers.splice(0).reverse()) remove();
51
+ };
52
+ try {
53
+ for (const definition of definitions) removers.push(api.registerSourceEditor.call(api, definition));
54
+ host.vm?.runtime?.on?.('RUNTIME_DISPOSED', dispose);
55
+ } catch (error) {dispose(); throw error;}
56
+ return dispose;
57
+ }