@kubohiroya/turbowarp-cloudflare-worker 0.3.0 → 0.4.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/README.ja.md +6 -0
- package/README.md +5 -1
- package/assets/block-icon.svg +1 -0
- package/dist/turbowarp-cloudflare-worker.js +11279 -9610
- package/docs/fixed-input-editors.ja.md +22 -0
- package/docs/index.html +16 -4
- package/package.json +10 -3
- package/schemas/block-editor-fixed-inputs.schema.json +119 -0
- package/src/config.ts +1 -1
- package/src/extension.ts +5 -1
- package/src/fixed-input-editors.ts +206 -0
- package/src/fixed-input-schema.ts +17 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# 固定入力の編集
|
|
2
|
+
|
|
3
|
+
S3-4のローカル実装です。対応GUIの固定入力機能は既定OFFです。旧GUI・API無し・固定入力機能OFFではブロックの従来動作を保ちます。`getInfo()` に存在する対象opcodeだけ登録し、再取得・APIの置換・拡張の`dispose()`・runtimeの破棄に対応します。既存SOURCEエディターとopcodeは分離しています。
|
|
4
|
+
|
|
5
|
+
|ブロックopcode|引数|UI|
|
|
6
|
+
|---|---|---|
|
|
7
|
+
|`createHandlerIr`|`METHOD`|既定値からの選択:`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`, `HEAD`|
|
|
8
|
+
|`createProtectedRouteIr`|`METHOD`|既定値からの選択:`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`, `HEAD`, `*`|
|
|
9
|
+
|`createProtectedRouteIr`|`ON_UNAUTHENTICATED`|既定値からの選択:`redirect-login`, `json-401`, `forbid-403`|
|
|
10
|
+
|`createBearerRouteIr`|`METHOD`|既定値からの選択:`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`, `HEAD`, `*`|
|
|
11
|
+
|`createBearerRoleRouteIr`|`METHOD`|既定値からの選択:`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`, `HEAD`, `*`|
|
|
12
|
+
|`createBearerScopeRouteIr`|`METHOD`|既定値からの選択:`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`, `HEAD`, `*`|
|
|
13
|
+
|
|
14
|
+
数値の新規入力は、空白を除いた完全な有限JSON数値トークンを受け付け、指数表記・負のゼロ・表記を保持します。空文字、16進表記、先頭の`+`、先頭ゼロや未完成トークンは新規保存しません。既存値は開いただけで書き換えません。既存の有限数値別表記は参照用に投影し、未編集の生値を保ちます。未知の旧enum値も無操作では保存し直しません。
|
|
15
|
+
|
|
16
|
+
`METHOD` は前後空白を除いて大文字化します。`createHandlerIr` に `*` はありません。認証失敗時の動作は既存の `schemas/protected-routes.schema.json` の enum を参照し、旧Schemaの `$id` と既存データを維持します。
|
|
17
|
+
|
|
18
|
+
reporter接続は読取専用で、実行・置換しません。新しい選択や数値を保存するときだけ純粋codecとSchemaで検証します。検証失敗時は全変更を拒否し、ブロックや接続を部分的に書き換えません。
|
|
19
|
+
|
|
20
|
+
正本は本ownerの `schemas/block-editor-fixed-inputs.schema.json`、TSモジュールは選択・参照用、`dist`は生成物です。外部候補取得や実行時Schema生成は行いません。
|
|
21
|
+
|
|
22
|
+
切戻しはGUIの固定入力機能OFFで行えます。既存のプロジェクト形式・opcode・メニュー・defaultValue・実行時の処理は維持します。
|
package/docs/index.html
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
6
|
<title>turbowarp-cloudflare-worker</title>
|
|
7
7
|
<style>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
:root{color-scheme:light dark;--fg:#222;--bg:#fff;--code-bg:#f3f3f3;--pre-bg:#f6f8fa}
|
|
9
|
+
@media (prefers-color-scheme:dark){:root{--fg:#e7eaf2;--bg:#12141a;--code-bg:#242833;--pre-bg:#1b1e26}}
|
|
10
|
+
body{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;max-width:900px;margin:0 auto;padding:2rem;line-height:1.6;color:var(--fg);background:var(--bg)}
|
|
11
|
+
code{background:var(--code-bg);padding:.1em .3em;border-radius:.25em}
|
|
12
|
+
pre{background:var(--pre-bg);padding:1rem;overflow:auto;border-radius:.5rem}
|
|
11
13
|
</style>
|
|
12
14
|
<style id="block-reference-style">
|
|
13
15
|
#extension-block-reference{max-width:72rem;margin:2rem auto;padding:1rem;line-height:1.6;overflow-wrap:anywhere}
|
|
@@ -50,9 +52,19 @@
|
|
|
50
52
|
<li><a href="#block-createBearerScopeRouteIr"><code>API route [METHOD] [PATH] requires bearer scope [SCOPE]</code></a></li>
|
|
51
53
|
<li><a href="#block-createWorkerIrWithAuth"><code>Cloudflare Worker [NAME] with handlers JSON [HANDLERS] and auth JSON [AUTH]</code></a></li>
|
|
52
54
|
</ul></nav>
|
|
53
|
-
<article id="block-createHandlerIr" class="block-reference-entry"><h3><code>Cloudflare handler [METHOD] [PATH] returns [BODY]</code></h3><p>Creates a minimal HTTP handler IR JSON entry for the Cloudflare generator.</p><p>Block type: REPORTER. Opcode: <code>createHandlerIr</code>. <a href="#block-createHandlerIr">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>METHOD</code></th><td>STRING</td><td><code>GET</code></td><td></td></tr><tr><th scope="row"><code>PATH</code></th><td>STRING</td><td><code>/hello</code></td><td></td></tr><tr><th scope="row"><code>BODY</code></th><td>STRING</td><td><code>Hello from TurboWarp</code></td><td></td></tr></tbody></table></div
|
|
55
|
+
<article id="block-createHandlerIr" class="block-reference-entry"><h3><code>Cloudflare handler [METHOD] [PATH] returns [BODY]</code></h3><p>Creates a minimal HTTP handler IR JSON entry for the Cloudflare generator.</p><p>Block type: REPORTER. Opcode: <code>createHandlerIr</code>. <a href="#block-createHandlerIr">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>METHOD</code></th><td>STRING</td><td><code>GET</code></td><td></td></tr><tr><th scope="row"><code>PATH</code></th><td>STRING</td><td><code>/hello</code></td><td></td></tr><tr><th scope="row"><code>BODY</code></th><td>STRING</td><td><code>Hello from TurboWarp</code></td><td></td></tr></tbody></table></div><p lang="ja" class="fixed-input-help"><a href="#fixed-input-editors">このブロックの固定入力編集と互換性</a></p>
|
|
56
|
+
</article><article id="block-createWorkerIr" class="block-reference-entry"><h3><code>Cloudflare Worker [NAME] with handlers JSON [HANDLERS]</code></h3><p>Creates a deployable Worker IR JSON document from handler entries.</p><p>Block type: REPORTER. Opcode: <code>createWorkerIr</code>. <a href="#block-createWorkerIr">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>NAME</code></th><td>STRING</td><td><code>tw-http-app</code></td><td></td></tr><tr><th scope="row"><code>HANDLERS</code></th><td>STRING</td><td><code>[]</code></td><td></td></tr></tbody></table></div></article><article id="block-generateFilesJson" class="block-reference-entry"><h3><code>generated Cloudflare files JSON from IR [IR]</code></h3><p>Runs the Cloudflare Workers/Hono generator and returns GeneratedFile[] as JSON.</p><p>Block type: REPORTER. Opcode: <code>generateFilesJson</code>. <a href="#block-generateFilesJson">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>IR</code></th><td>STRING</td><td><code>{"name":"tw-http-app","handlers":[]}</code></td><td></td></tr></tbody></table></div></article><article id="block-createProtectedRouteIr" class="block-reference-entry"><h3><code>protected route [METHOD] [PATH] when unauthenticated [ON_UNAUTHENTICATED]</code></h3><p>Creates an auth guard IR entry for a route protected by external OAuth/OIDC.</p><p>Block type: REPORTER. Opcode: <code>createProtectedRouteIr</code>. <a href="#block-createProtectedRouteIr">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>METHOD</code></th><td>STRING</td><td><code>GET</code></td><td></td></tr><tr><th scope="row"><code>PATH</code></th><td>STRING</td><td><code>/private</code></td><td></td></tr><tr><th scope="row"><code>ON_UNAUTHENTICATED</code></th><td>STRING</td><td><code>redirect-login</code></td><td></td></tr></tbody></table></div><p lang="ja" class="fixed-input-help"><a href="#fixed-input-editors">このブロックの固定入力編集と互換性</a></p>
|
|
57
|
+
</article><article id="block-createAuthIr" class="block-reference-entry"><h3><code>external OAuth/OIDC auth providers [PROVIDERS] protected routes JSON [PROTECTED_ROUTES]</code></h3><p>Creates auth IR for Google, Microsoft, and GitHub account sign-in.</p><p>Block type: REPORTER. Opcode: <code>createAuthIr</code>. <a href="#block-createAuthIr">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>PROVIDERS</code></th><td>STRING</td><td><code>google,github</code></td><td></td></tr><tr><th scope="row"><code>PROTECTED_ROUTES</code></th><td>STRING</td><td><code>[]</code></td><td></td></tr></tbody></table></div></article><article id="block-createBearerRouteIr" class="block-reference-entry"><h3><code>API route [METHOD] [PATH] requires bearer token</code></h3><p>Creates a protected route IR entry that requires a valid self-issued ES256 bearer JWT.</p><p>Block type: REPORTER. Opcode: <code>createBearerRouteIr</code>. <a href="#block-createBearerRouteIr">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>METHOD</code></th><td>STRING</td><td><code>GET</code></td><td></td></tr><tr><th scope="row"><code>PATH</code></th><td>STRING</td><td><code>/api/items</code></td><td></td></tr></tbody></table></div><p lang="ja" class="fixed-input-help"><a href="#fixed-input-editors">このブロックの固定入力編集と互換性</a></p>
|
|
58
|
+
</article><article id="block-createBearerRoleRouteIr" class="block-reference-entry"><h3><code>API route [METHOD] [PATH] requires bearer role [ROLE]</code></h3><p>Creates a bearer JWT protected route IR entry that also requires a role claim.</p><p>Block type: REPORTER. Opcode: <code>createBearerRoleRouteIr</code>. <a href="#block-createBearerRoleRouteIr">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>METHOD</code></th><td>STRING</td><td><code>POST</code></td><td></td></tr><tr><th scope="row"><code>PATH</code></th><td>STRING</td><td><code>/api/admin</code></td><td></td></tr><tr><th scope="row"><code>ROLE</code></th><td>STRING</td><td><code>admin</code></td><td></td></tr></tbody></table></div><p lang="ja" class="fixed-input-help"><a href="#fixed-input-editors">このブロックの固定入力編集と互換性</a></p>
|
|
59
|
+
</article><article id="block-createBearerScopeRouteIr" class="block-reference-entry"><h3><code>API route [METHOD] [PATH] requires bearer scope [SCOPE]</code></h3><p>Creates a bearer JWT protected route IR entry that also requires one or more scopes.</p><p>Block type: REPORTER. Opcode: <code>createBearerScopeRouteIr</code>. <a href="#block-createBearerScopeRouteIr">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>METHOD</code></th><td>STRING</td><td><code>POST</code></td><td></td></tr><tr><th scope="row"><code>PATH</code></th><td>STRING</td><td><code>/api/posts</code></td><td></td></tr><tr><th scope="row"><code>SCOPE</code></th><td>STRING</td><td><code>posts:write</code></td><td></td></tr></tbody></table></div><p lang="ja" class="fixed-input-help"><a href="#fixed-input-editors">このブロックの固定入力編集と互換性</a></p>
|
|
60
|
+
</article><article id="block-createWorkerIrWithAuth" class="block-reference-entry"><h3><code>Cloudflare Worker [NAME] with handlers JSON [HANDLERS] and auth JSON [AUTH]</code></h3><p>Creates Worker IR with an external OAuth/OIDC auth policy.</p><p>Block type: REPORTER. Opcode: <code>createWorkerIrWithAuth</code>. <a href="#block-createWorkerIrWithAuth">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>NAME</code></th><td>STRING</td><td><code>tw-http-app</code></td><td></td></tr><tr><th scope="row"><code>HANDLERS</code></th><td>STRING</td><td><code>[]</code></td><td></td></tr><tr><th scope="row"><code>AUTH</code></th><td>STRING</td><td><code>{"mode":"external-oauth-oidc","providers":["google"],"protectedRoutes":[]}</code></td><td></td></tr></tbody></table></div></article>
|
|
54
61
|
<p><a href="https://github.com/kubohiroya/turbowarp-cloudflare-worker/blob/main/README.md">Repository guide and examples</a></p>
|
|
55
62
|
</section>
|
|
56
63
|
<!-- END COMPLETE BLOCK REFERENCE -->
|
|
64
|
+
<section lang="ja" id="fixed-input-editors"><h2>固定入力の編集</h2><p>対応GUIの固定入力機能は既定OFFです。既存値は開いただけでは変更せず、reporter接続は評価・置換しません。新しい選択と有限JSON数値入力のみを検証して保存し、既存の補正・丸め処理を維持します。機能OFFで従来の編集へ戻せます。</p><p><a href="fixed-input-editors.ja.md">対象入力・Schemaの正本・互換性・切戻し</a></p></section>
|
|
65
|
+
<!-- The shared TurboWarp Plus header. It inserts itself at the top of the
|
|
66
|
+
page in a shadow root, so it cannot disturb the styles below. -->
|
|
67
|
+
<script type="module"
|
|
68
|
+
src="https://kubohiroya.github.io/turbowarp-plus-site-header/dist/auto.js"></script>
|
|
57
69
|
</body>
|
|
58
70
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-cloudflare-worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Cloudflare Workers TypeScript generator and TurboWarp extension bridge for turbowarp-http-server.",
|
|
5
5
|
"author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"type": "module",
|
|
25
25
|
"files": [
|
|
26
|
+
"assets/",
|
|
26
27
|
"dist/",
|
|
27
28
|
"docs/",
|
|
28
29
|
"schemas/",
|
|
@@ -65,12 +66,12 @@
|
|
|
65
66
|
},
|
|
66
67
|
"dependencies": {
|
|
67
68
|
"hono": "^4.10.7",
|
|
68
|
-
"@kubohiroya/turbowarp-extension-data-editor": "
|
|
69
|
+
"@kubohiroya/turbowarp-extension-data-editor": "^0.3.4"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
72
|
"@cloudflare/workers-types": "^5.20260826.1",
|
|
72
73
|
"@eslint/js": "^9.39.5",
|
|
73
|
-
"@kubohiroya/vite-plugin-turbowarp-extension": "0.
|
|
74
|
+
"@kubohiroya/vite-plugin-turbowarp-extension": "^0.8.0",
|
|
74
75
|
"@types/node": "^24.13.3",
|
|
75
76
|
"eslint": "^9.39.5",
|
|
76
77
|
"typescript": "^5.9.3",
|
|
@@ -78,5 +79,11 @@
|
|
|
78
79
|
"vite": "^8.2.2",
|
|
79
80
|
"vitest": "^4.1.10",
|
|
80
81
|
"react-dom": "18.3.1"
|
|
82
|
+
},
|
|
83
|
+
"gitHead": "dce435c39e37f647d0ab7052d3830fac9330f7ad",
|
|
84
|
+
"x-turbowarp-source": {
|
|
85
|
+
"revision": "dce435c39e37f647d0ab7052d3830fac9330f7ad",
|
|
86
|
+
"revisionRole": "base-commit",
|
|
87
|
+
"sourceState": "local-release-overlay"
|
|
81
88
|
}
|
|
82
89
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://kubohiroya.github.io/turbowarp-cloudflare-worker/schemas/block-editor-fixed-inputs.schema.json",
|
|
4
|
+
"$defs": {
|
|
5
|
+
"createHandlerIr": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"METHOD": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"enum": [
|
|
11
|
+
"GET",
|
|
12
|
+
"POST",
|
|
13
|
+
"PUT",
|
|
14
|
+
"PATCH",
|
|
15
|
+
"DELETE",
|
|
16
|
+
"OPTIONS",
|
|
17
|
+
"HEAD"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": [
|
|
22
|
+
"METHOD"
|
|
23
|
+
],
|
|
24
|
+
"additionalProperties": true
|
|
25
|
+
},
|
|
26
|
+
"createProtectedRouteIr": {
|
|
27
|
+
"type": "object",
|
|
28
|
+
"properties": {
|
|
29
|
+
"METHOD": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"enum": [
|
|
32
|
+
"GET",
|
|
33
|
+
"POST",
|
|
34
|
+
"PUT",
|
|
35
|
+
"PATCH",
|
|
36
|
+
"DELETE",
|
|
37
|
+
"OPTIONS",
|
|
38
|
+
"HEAD",
|
|
39
|
+
"*"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"ON_UNAUTHENTICATED": {
|
|
43
|
+
"$ref": "https://kubohiroya.github.io/turbowarp-http-server-cloudflare/schemas/protected-routes.schema.json#/anyOf/0/properties/onUnauthenticated"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"required": [
|
|
47
|
+
"METHOD",
|
|
48
|
+
"ON_UNAUTHENTICATED"
|
|
49
|
+
],
|
|
50
|
+
"additionalProperties": true
|
|
51
|
+
},
|
|
52
|
+
"createBearerRouteIr": {
|
|
53
|
+
"type": "object",
|
|
54
|
+
"properties": {
|
|
55
|
+
"METHOD": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"enum": [
|
|
58
|
+
"GET",
|
|
59
|
+
"POST",
|
|
60
|
+
"PUT",
|
|
61
|
+
"PATCH",
|
|
62
|
+
"DELETE",
|
|
63
|
+
"OPTIONS",
|
|
64
|
+
"HEAD",
|
|
65
|
+
"*"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"required": [
|
|
70
|
+
"METHOD"
|
|
71
|
+
],
|
|
72
|
+
"additionalProperties": true
|
|
73
|
+
},
|
|
74
|
+
"createBearerRoleRouteIr": {
|
|
75
|
+
"type": "object",
|
|
76
|
+
"properties": {
|
|
77
|
+
"METHOD": {
|
|
78
|
+
"type": "string",
|
|
79
|
+
"enum": [
|
|
80
|
+
"GET",
|
|
81
|
+
"POST",
|
|
82
|
+
"PUT",
|
|
83
|
+
"PATCH",
|
|
84
|
+
"DELETE",
|
|
85
|
+
"OPTIONS",
|
|
86
|
+
"HEAD",
|
|
87
|
+
"*"
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"required": [
|
|
92
|
+
"METHOD"
|
|
93
|
+
],
|
|
94
|
+
"additionalProperties": true
|
|
95
|
+
},
|
|
96
|
+
"createBearerScopeRouteIr": {
|
|
97
|
+
"type": "object",
|
|
98
|
+
"properties": {
|
|
99
|
+
"METHOD": {
|
|
100
|
+
"type": "string",
|
|
101
|
+
"enum": [
|
|
102
|
+
"GET",
|
|
103
|
+
"POST",
|
|
104
|
+
"PUT",
|
|
105
|
+
"PATCH",
|
|
106
|
+
"DELETE",
|
|
107
|
+
"OPTIONS",
|
|
108
|
+
"HEAD",
|
|
109
|
+
"*"
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"required": [
|
|
114
|
+
"METHOD"
|
|
115
|
+
],
|
|
116
|
+
"additionalProperties": true
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -8,5 +8,5 @@ export const extensionConfig = {
|
|
|
8
8
|
unsandboxed: false,
|
|
9
9
|
docsURI: 'https://kubohiroya.github.io/turbowarp-cloudflare-worker/',
|
|
10
10
|
blockIconURI:
|
|
11
|
-
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCI+
|
|
11
|
+
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCI+PHBhdGggZD0iTTI4LjAgMjcuMEwyOC4wIDUuME0yOC4wIDI3LjBMNDMuNiAxMS40TTI4LjAgMjcuMEw1MC4wIDI3LjBNMjguMCAyNy4wTDQzLjYgNDIuNk0yOC4wIDI3LjBMMjguMCA0OS4wTTI4LjAgMjcuMEwxMi40IDQyLjZNMjguMCAyNy4wTDYuMCAyNy4wTTI4LjAgMjcuMEwxMi40IDExLjQiIHN0cm9rZT0iIzI1NjNFQiIgc3Ryb2tlLXdpZHRoPSIxLjA0IiBzdHJva2UtbGluZWNhcD0icm91bmQiLz48cGF0aCBkPSJNMjguMCAxMC4wTDQwLjAgMTUuMEw0NS4wIDI3LjBMNDAuMCAzOS4wTDI4LjAgNDQuMEwxNi4wIDM5LjBMMTEuMCAyNy4wTDE2LjAgMTUuMFoiIGZpbGw9Im5vbmUiIHN0cm9rZT0iIzI1NjNFQiIgc3Ryb2tlLXdpZHRoPSIxLjMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48cGF0aCBkPSJNMjIuNSAyMWgxMS41bDcgN3YxNC41YTIgMiAwIDAgMS0yIDJIMjIuNWEyIDIgMCAwIDEtMi0yVjIzYTIgMiAwIDAgMSAyLTJ6IiBmaWxsPSIjZmZmIiBzdHJva2U9IiMxNjMwNUMiIHN0cm9rZS13aWR0aD0iMi40IiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PHBhdGggZD0iTTM0IDIxdjdoNyIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMTYzMDVDIiBzdHJva2Utd2lkdGg9IjIuNCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjxwYXRoIGQ9Ik0yOC41IDM5LjVhNC4yIDQuMiAwIDAgMSAuNi04LjMgNS42IDUuNiAwIDAgMSAxMC4zIDEuNiAzLjQgMy40IDAgMCAxLTEuMSA2Ljd6IiBmaWxsPSIjRjJBMzNBIi8+PHBhdGggZD0iTTE0IDBWOC4wIiBzdHJva2U9IiMxNjMwNUMiIHN0cm9rZS13aWR0aD0iMS41IiBzdHJva2UtbGluZWNhcD0icm91bmQiLz48cGF0aCBkPSJNMTIuMyA4LjVMNi4xIDYuOUwzLjEgMi45TTE1LjcgOC41TDIxLjkgNi45TDI0LjkgMi45TTEyLjMgMTAuMEw1LjQgOS45TDIuMSA2LjlNMTUuNyAxMC4wTDIyLjYgOS45TDI1LjkgNi45TTEyLjMgMTEuOEw1LjQgMTEuOUwyLjEgMTQuOU0xNS43IDExLjhMMjIuNiAxMS45TDI1LjkgMTQuOU0xMi4zIDEzLjNMNi4xIDE0LjlMMy4xIDE4LjlNMTUuNyAxMy4zTDIxLjkgMTQuOUwyNC45IDE4LjkiIGZpbGw9Im5vbmUiIHN0cm9rZT0iIzE2MzA1QyIgc3Ryb2tlLXdpZHRoPSIxLjA1IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48Y2lyY2xlIGN4PSIxNCIgY3k9IjEwLjkiIHI9IjMuNCIgZmlsbD0iIzE2MzA1QyIvPjxjaXJjbGUgY3g9IjE0IiBjeT0iMTUuMSIgcj0iMi4zIiBmaWxsPSIjMTYzMDVDIi8+PC9zdmc+'
|
|
12
12
|
} as const;
|
package/src/extension.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {fixedInputRegistration} from './fixed-input-editors.js';
|
|
1
2
|
import {sourceEditorDefinitions} from './editor-schema.js';
|
|
2
3
|
import {registerSourceEditors} from './source-editor.js';
|
|
3
4
|
import {extensionConfig} from './config';
|
|
@@ -37,11 +38,14 @@ const authBlockIconUri =
|
|
|
37
38
|
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCI+PHJlY3QgeD0iNiIgeT0iMTgiIHdpZHRoPSIzNiIgaGVpZ2h0PSIyNCIgcng9IjQiIGZpbGw9IiNGNzk1MjEiLz48cGF0aCBkPSJNMTUgMTh2LTZjMC01IDQtOSA5LTlzOSA0IDkgOXY2IiBmaWxsPSJub25lIiBzdHJva2U9IiMxRjI5MzciIHN0cm9rZS13aWR0aD0iNCIvPjxjaXJjbGUgY3g9IjI0IiBjeT0iMzAiIHI9IjMiIGZpbGw9IiMxRjI5MzciLz48L3N2Zz4=';
|
|
38
39
|
|
|
39
40
|
export class CloudflareExtension implements TurboWarpExtension {
|
|
41
|
+
private readonly fixedInputs = fixedInputRegistration(typeof Scratch === 'undefined' ? undefined : Scratch);
|
|
42
|
+
|
|
40
43
|
private readonly unregisterSourceEditors: () => void;
|
|
41
44
|
public constructor() {this.unregisterSourceEditors = registerSourceEditors(Scratch, sourceEditorDefinitions);}
|
|
42
|
-
public dispose(): void {this.unregisterSourceEditors();}
|
|
45
|
+
public dispose(): void {this.fixedInputs.dispose(); this.unregisterSourceEditors();}
|
|
43
46
|
|
|
44
47
|
public getInfo(): Record<string, unknown> {
|
|
48
|
+
this.fixedInputs.ensure(paletteDefinitions.flatMap(block => 'opcode' in block ? [`${extensionConfig.id}_${block.opcode}`] : []));
|
|
45
49
|
return {
|
|
46
50
|
id: extensionConfig.id,
|
|
47
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
|
+
}
|