@kubohiroya/turbowarp-cloudflare-worker 0.2.0 → 0.3.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/turbowarp-cloudflare-worker.js +8530 -127
- package/docs/index.html +28 -1
- package/docs/source-forms.ja.md +20 -0
- package/docs/stage2-release-verification.ja.md +31 -0
- package/package.json +5 -3
- package/schemas/auth-ir.schema.json +98 -0
- package/schemas/handler-ir.schema.json +53 -0
- package/schemas/protected-routes.schema.json +93 -0
- package/schemas/worker-ir.schema.json +167 -0
- package/src/editor-schema.ts +41 -0
- package/src/extension.ts +6 -0
- package/src/source-editor.ts +57 -0
|
@@ -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
|
+
}
|