@kubohiroya/turbowarp-http-server 0.2.0 → 0.2.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.
- package/README.ja.md +29 -13
- package/README.md +101 -42
- package/dist/cli.js +131 -17
- package/dist/cli.js.map +1 -1
- package/dist/compiler/adapters/cloudflare.d.ts +2 -0
- package/dist/compiler/adapters/cloudflare.js +477 -0
- package/dist/compiler/adapters/cloudflare.js.map +1 -0
- package/dist/compiler/adapters/firebase.d.ts +2 -0
- package/dist/compiler/adapters/firebase.js +489 -0
- package/dist/compiler/adapters/firebase.js.map +1 -0
- package/dist/compiler/adapters/index.d.ts +2 -0
- package/dist/compiler/adapters/index.js +3 -0
- package/dist/compiler/adapters/index.js.map +1 -0
- package/dist/compiler/binary/codec.d.ts +4 -0
- package/dist/compiler/binary/codec.js +45 -0
- package/dist/compiler/binary/codec.js.map +1 -0
- package/dist/compiler/binary/error.d.ts +3 -0
- package/dist/compiler/binary/error.js +21 -0
- package/dist/compiler/binary/error.js.map +1 -0
- package/dist/compiler/binary/index.d.ts +4 -0
- package/dist/compiler/binary/index.js +5 -0
- package/dist/compiler/binary/index.js.map +1 -0
- package/dist/compiler/binary/runtime.d.ts +18 -0
- package/dist/compiler/binary/runtime.js +123 -0
- package/dist/compiler/binary/runtime.js.map +1 -0
- package/dist/compiler/binary/types.d.ts +17 -0
- package/dist/compiler/binary/types.js +2 -0
- package/dist/compiler/binary/types.js.map +1 -0
- package/dist/compiler/feature-flags.d.ts +4 -0
- package/dist/compiler/feature-flags.js +4 -0
- package/dist/compiler/feature-flags.js.map +1 -0
- package/dist/compiler/index.d.ts +35 -0
- package/dist/compiler/index.js +84 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/ir-v2/canonical.d.ts +3 -0
- package/dist/compiler/ir-v2/canonical.js +50 -0
- package/dist/compiler/ir-v2/canonical.js.map +1 -0
- package/dist/compiler/ir-v2/index.d.ts +4 -0
- package/dist/compiler/ir-v2/index.js +5 -0
- package/dist/compiler/ir-v2/index.js.map +1 -0
- package/dist/compiler/ir-v2/parse.d.ts +10 -0
- package/dist/compiler/ir-v2/parse.js +753 -0
- package/dist/compiler/ir-v2/parse.js.map +1 -0
- package/dist/compiler/ir-v2/strict-json.d.ts +4 -0
- package/dist/compiler/ir-v2/strict-json.js +133 -0
- package/dist/compiler/ir-v2/strict-json.js.map +1 -0
- package/dist/compiler/ir-v2/types.d.ts +412 -0
- package/dist/compiler/ir-v2/types.js +84 -0
- package/dist/compiler/ir-v2/types.js.map +1 -0
- package/dist/compiler/kvs/lowering.d.ts +13 -0
- package/dist/compiler/kvs/lowering.js +77 -0
- package/dist/compiler/kvs/lowering.js.map +1 -0
- package/dist/compiler/manifest/error.d.ts +7 -0
- package/dist/compiler/manifest/error.js +9 -0
- package/dist/compiler/manifest/error.js.map +1 -0
- package/dist/compiler/manifest/index.d.ts +6 -0
- package/dist/compiler/manifest/index.js +7 -0
- package/dist/compiler/manifest/index.js.map +1 -0
- package/dist/compiler/manifest/operations.d.ts +12 -0
- package/dist/compiler/manifest/operations.js +60 -0
- package/dist/compiler/manifest/operations.js.map +1 -0
- package/dist/compiler/manifest/parse.d.ts +9 -0
- package/dist/compiler/manifest/parse.js +280 -0
- package/dist/compiler/manifest/parse.js.map +1 -0
- package/dist/compiler/manifest/registry.d.ts +3 -0
- package/dist/compiler/manifest/registry.js +48 -0
- package/dist/compiler/manifest/registry.js.map +1 -0
- package/dist/compiler/manifest/resolve.d.ts +14 -0
- package/dist/compiler/manifest/resolve.js +116 -0
- package/dist/compiler/manifest/resolve.js.map +1 -0
- package/dist/compiler/manifest/types.d.ts +95 -0
- package/dist/compiler/manifest/types.js +3 -0
- package/dist/compiler/manifest/types.js.map +1 -0
- package/dist/compiler/named-body/index.d.ts +1 -0
- package/dist/compiler/named-body/index.js +2 -0
- package/dist/compiler/named-body/index.js.map +1 -0
- package/dist/compiler/named-body/lowering.d.ts +18 -0
- package/dist/compiler/named-body/lowering.js +83 -0
- package/dist/compiler/named-body/lowering.js.map +1 -0
- package/dist/compiler/pipeline/compiler.d.ts +18 -0
- package/dist/compiler/pipeline/compiler.js +105 -0
- package/dist/compiler/pipeline/compiler.js.map +1 -0
- package/dist/compiler/pipeline/core-generator.d.ts +3 -0
- package/dist/compiler/pipeline/core-generator.js +483 -0
- package/dist/compiler/pipeline/core-generator.js.map +1 -0
- package/dist/compiler/pipeline/index.d.ts +5 -0
- package/dist/compiler/pipeline/index.js +6 -0
- package/dist/compiler/pipeline/index.js.map +1 -0
- package/dist/compiler/pipeline/registry.d.ts +7 -0
- package/dist/compiler/pipeline/registry.js +17 -0
- package/dist/compiler/pipeline/registry.js.map +1 -0
- package/dist/compiler/pipeline/requirements.d.ts +9 -0
- package/dist/compiler/pipeline/requirements.js +135 -0
- package/dist/compiler/pipeline/requirements.js.map +1 -0
- package/dist/compiler/pipeline/types.d.ts +65 -0
- package/dist/compiler/pipeline/types.js +2 -0
- package/dist/compiler/pipeline/types.js.map +1 -0
- package/dist/compiler/runtime/error.d.ts +6 -0
- package/dist/compiler/runtime/error.js +9 -0
- package/dist/compiler/runtime/error.js.map +1 -0
- package/dist/compiler/runtime/index.d.ts +1 -0
- package/dist/compiler/runtime/index.js +2 -0
- package/dist/compiler/runtime/index.js.map +1 -0
- package/dist/compiler/structured-data/index.d.ts +3 -0
- package/dist/compiler/structured-data/index.js +4 -0
- package/dist/compiler/structured-data/index.js.map +1 -0
- package/dist/compiler/structured-data/lowering.d.ts +30 -0
- package/dist/compiler/structured-data/lowering.js +202 -0
- package/dist/compiler/structured-data/lowering.js.map +1 -0
- package/dist/compiler/structured-data/path.d.ts +2 -0
- package/dist/compiler/structured-data/path.js +60 -0
- package/dist/compiler/structured-data/path.js.map +1 -0
- package/dist/compiler/structured-data/runtime.d.ts +20 -0
- package/dist/compiler/structured-data/runtime.js +210 -0
- package/dist/compiler/structured-data/runtime.js.map +1 -0
- package/dist/compiler/turbowarp-v2.d.ts +8 -0
- package/dist/compiler/turbowarp-v2.js +479 -0
- package/dist/compiler/turbowarp-v2.js.map +1 -0
- package/dist/compiler/validator/index.d.ts +4 -0
- package/dist/compiler/validator/index.js +5 -0
- package/dist/compiler/validator/index.js.map +1 -0
- package/dist/compiler/validator/ir-validator.d.ts +10 -0
- package/dist/compiler/validator/ir-validator.js +463 -0
- package/dist/compiler/validator/ir-validator.js.map +1 -0
- package/dist/compiler/validator/resource-lifetime.d.ts +18 -0
- package/dist/compiler/validator/resource-lifetime.js +106 -0
- package/dist/compiler/validator/resource-lifetime.js.map +1 -0
- package/dist/compiler/validator/turbowarp-subset.d.ts +3 -0
- package/dist/compiler/validator/turbowarp-subset.js +241 -0
- package/dist/compiler/validator/turbowarp-subset.js.map +1 -0
- package/dist/compiler/validator/types.d.ts +30 -0
- package/dist/compiler/validator/types.js +7 -0
- package/dist/compiler/validator/types.js.map +1 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -0
- package/dist/digest-cli.js +0 -0
- package/dist/extension-manifest.json +102 -0
- package/dist/named-body.d.ts +57 -0
- package/dist/named-body.js +396 -0
- package/dist/named-body.js.map +1 -0
- package/dist/named-data-namespace.d.ts +3 -0
- package/dist/named-data-namespace.js +6 -0
- package/dist/named-data-namespace.js.map +1 -0
- package/dist/protocol.d.ts +13 -1
- package/dist/protocol.js +34 -0
- package/dist/protocol.js.map +1 -1
- package/dist/resource-named-body-provider.d.ts +8 -0
- package/dist/resource-named-body-provider.js +88 -0
- package/dist/resource-named-body-provider.js.map +1 -0
- package/dist/server.d.ts +10 -1
- package/dist/server.js +37 -7
- package/dist/server.js.map +1 -1
- package/dist/turbowarp-http-server.js +516 -1
- package/docs/binary-resource-semantics.ja.md +84 -0
- package/docs/cloudflare-worker-compiler.ja.md +90 -0
- package/docs/compiler-manifest-registry.ja.md +79 -0
- package/docs/compiler-platform-pipeline.ja.md +94 -0
- package/docs/deploy-ir-v2.ja.md +123 -0
- package/docs/fixed-input-editors.ja.md +23 -0
- package/docs/index.html +80 -0
- package/docs/ir-v2-conformance.ja.md +65 -0
- package/docs/named-response-body.ja.md +120 -0
- package/docs/platform-storage-adapters.ja.md +99 -0
- package/docs/server-executable-subset.ja.md +88 -0
- package/docs/structured-data-lowering.ja.md +63 -0
- package/examples/compiler/message-app.v2.ir.json +41 -0
- package/package.json +44 -20
- package/schemas/block-editor-fixed-inputs.schema.json +85 -0
- package/schemas/compiler-extension-manifest.schema.json +126 -0
- package/schemas/compiler-manifest-lock-v1.schema.json +48 -0
- package/schemas/deploy-ir-v2.schema.json +835 -0
- package/schemas/ir-v2-conformance-fixture.schema.json +44 -0
- package/src/block-definitions.json +76 -0
- package/src/cli.ts +136 -23
- package/src/compiler/adapters/cloudflare.ts +510 -0
- package/src/compiler/adapters/firebase.ts +538 -0
- package/src/compiler/adapters/index.ts +2 -0
- package/src/compiler/binary/codec.ts +61 -0
- package/src/compiler/binary/error.ts +25 -0
- package/src/compiler/binary/index.ts +4 -0
- package/src/compiler/binary/runtime.ts +133 -0
- package/src/compiler/binary/types.ts +26 -0
- package/src/compiler/feature-flags.ts +7 -0
- package/src/compiler/index.ts +114 -0
- package/src/compiler/ir-v2/canonical.ts +46 -0
- package/src/compiler/ir-v2/index.ts +9 -0
- package/src/compiler/ir-v2/parse.ts +921 -0
- package/src/compiler/ir-v2/strict-json.ts +129 -0
- package/src/compiler/ir-v2/types.ts +462 -0
- package/src/compiler/kvs/lowering.ts +88 -0
- package/src/compiler/manifest/error.ts +29 -0
- package/src/compiler/manifest/index.ts +17 -0
- package/src/compiler/manifest/operations.ts +175 -0
- package/src/compiler/manifest/parse.ts +390 -0
- package/src/compiler/manifest/registry.ts +74 -0
- package/src/compiler/manifest/resolve.ts +159 -0
- package/src/compiler/manifest/types.ts +112 -0
- package/src/compiler/named-body/index.ts +1 -0
- package/src/compiler/named-body/lowering.ts +186 -0
- package/src/compiler/pipeline/compiler.ts +138 -0
- package/src/compiler/pipeline/core-generator.ts +486 -0
- package/src/compiler/pipeline/index.ts +5 -0
- package/src/compiler/pipeline/registry.ts +18 -0
- package/src/compiler/pipeline/requirements.ts +139 -0
- package/src/compiler/pipeline/types.ts +59 -0
- package/src/compiler/runtime/error.ts +11 -0
- package/src/compiler/runtime/index.ts +1 -0
- package/src/compiler/structured-data/index.ts +3 -0
- package/src/compiler/structured-data/lowering.ts +314 -0
- package/src/compiler/structured-data/path.ts +53 -0
- package/src/compiler/structured-data/runtime.ts +221 -0
- package/src/compiler/turbowarp-v2.ts +610 -0
- package/src/compiler/validator/index.ts +4 -0
- package/src/compiler/validator/ir-validator.ts +812 -0
- package/src/compiler/validator/resource-lifetime.ts +153 -0
- package/src/compiler/validator/turbowarp-subset.ts +387 -0
- package/src/compiler/validator/types.ts +68 -0
- package/src/extension.ts +87 -1
- package/src/fixed-input-editors.ts +181 -0
- package/src/fixed-input-schema.ts +15 -0
- package/src/named-body.ts +495 -0
- package/src/named-data-namespace.ts +6 -0
- package/src/protocol.ts +50 -1
- package/src/resource-named-body-provider.ts +106 -0
- package/src/server.ts +88 -8
- package/docs/turbowarp-http-server.architecture.visual-check.1440x900.dark.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.1440x900.light.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.dark.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.light.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.html +0 -32
- package/docs/turbowarp-http-server.architecture.visual-check.json +0 -547
- package/schemas/extension-manifest.schema.json +0 -49
- package/src/extension-manifest.ts +0 -149
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/kubohiroya/turbowarp-http-server/schemas/ir-v2-conformance-fixture.schema.json",
|
|
4
|
+
"title": "TurboWarp HTTP Server IR v2 conformance fixture",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["fixtureVersion", "id", "layer"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"fixtureVersion": {"const": 1},
|
|
9
|
+
"id": {"type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$"},
|
|
10
|
+
"layer": {"enum": ["frontend", "frontend-diagnostic", "core", "target"]},
|
|
11
|
+
"projectFile": {"type": "string"},
|
|
12
|
+
"manifestLockFile": {"type": "string"},
|
|
13
|
+
"expectedIrFile": {"type": "string"},
|
|
14
|
+
"externalVectors": {
|
|
15
|
+
"type": "array",
|
|
16
|
+
"items": {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"required": ["packageName", "packageVersion", "integrity"],
|
|
19
|
+
"properties": {
|
|
20
|
+
"packageName": {"type": "string"},
|
|
21
|
+
"packageVersion": {"type": "string"},
|
|
22
|
+
"integrity": {"type": "string", "pattern": "^sha256-"}
|
|
23
|
+
},
|
|
24
|
+
"additionalProperties": false
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"ir": {"type": "object"},
|
|
28
|
+
"request": {
|
|
29
|
+
"type": "object",
|
|
30
|
+
"required": ["method", "url"],
|
|
31
|
+
"properties": {
|
|
32
|
+
"method": {"type": "string"},
|
|
33
|
+
"url": {"type": "string", "format": "uri"},
|
|
34
|
+
"headers": {"type": "object", "additionalProperties": {"type": "string"}},
|
|
35
|
+
"bodyText": {"type": "string"},
|
|
36
|
+
"bodyFile": {"type": "string"}
|
|
37
|
+
},
|
|
38
|
+
"additionalProperties": false
|
|
39
|
+
},
|
|
40
|
+
"expected": {"type": "object"},
|
|
41
|
+
"expectedDiagnosticCodes": {"type": "array", "items": {"type": "string"}}
|
|
42
|
+
},
|
|
43
|
+
"additionalProperties": true
|
|
44
|
+
}
|
|
@@ -139,6 +139,67 @@
|
|
|
139
139
|
"description": "Returns the current request client address when available.",
|
|
140
140
|
"arguments": {}
|
|
141
141
|
},
|
|
142
|
+
{
|
|
143
|
+
"opcode": "setHandlerVariable",
|
|
144
|
+
"blockType": "COMMAND",
|
|
145
|
+
"text": "set handler variable [NAME] to [VALUE]",
|
|
146
|
+
"description": "Sets a request-local variable that is discarded when the current HTTP response completes.",
|
|
147
|
+
"arguments": {
|
|
148
|
+
"NAME": {"type": "STRING", "defaultValue": "value"},
|
|
149
|
+
"VALUE": {"type": "STRING", "defaultValue": "0"}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"opcode": "changeHandlerVariable",
|
|
154
|
+
"blockType": "COMMAND",
|
|
155
|
+
"text": "change handler variable [NAME] by [AMOUNT]",
|
|
156
|
+
"description": "Changes a request-local numeric variable using Scratch number conversion rules.",
|
|
157
|
+
"arguments": {
|
|
158
|
+
"NAME": {"type": "STRING", "defaultValue": "value"},
|
|
159
|
+
"AMOUNT": {"type": "NUMBER", "defaultValue": 1}
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"opcode": "handlerVariable",
|
|
164
|
+
"blockType": "REPORTER",
|
|
165
|
+
"text": "handler variable [NAME]",
|
|
166
|
+
"description": "Returns a request-local handler variable, or an empty string when it does not exist.",
|
|
167
|
+
"arguments": {
|
|
168
|
+
"NAME": {"type": "STRING", "defaultValue": "value"}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"opcode": "handlerVariableExists",
|
|
173
|
+
"blockType": "BOOLEAN",
|
|
174
|
+
"text": "handler variable [NAME] exists?",
|
|
175
|
+
"description": "Reports whether a request-local handler variable exists.",
|
|
176
|
+
"arguments": {
|
|
177
|
+
"NAME": {"type": "STRING", "defaultValue": "value"}
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"opcode": "deleteHandlerVariable",
|
|
182
|
+
"blockType": "COMMAND",
|
|
183
|
+
"text": "delete handler variable [NAME]",
|
|
184
|
+
"description": "Deletes a request-local handler variable.",
|
|
185
|
+
"arguments": {
|
|
186
|
+
"NAME": {"type": "STRING", "defaultValue": "value"}
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"opcode": "clearHandlerVariables",
|
|
191
|
+
"blockType": "COMMAND",
|
|
192
|
+
"text": "delete all handler variables",
|
|
193
|
+
"description": "Deletes all request-local handler variables for the current HTTP handler.",
|
|
194
|
+
"arguments": {}
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"opcode": "listHandlerVariables",
|
|
198
|
+
"blockType": "REPORTER",
|
|
199
|
+
"text": "active handler variables",
|
|
200
|
+
"description": "Returns comma-separated names of request-local handler variables.",
|
|
201
|
+
"arguments": {}
|
|
202
|
+
},
|
|
142
203
|
{
|
|
143
204
|
"opcode": "currentAuthType",
|
|
144
205
|
"blockType": "REPORTER",
|
|
@@ -265,6 +326,21 @@
|
|
|
265
326
|
"BODY": {"type": "STRING", "defaultValue": "{\"ok\":true}"}
|
|
266
327
|
}
|
|
267
328
|
},
|
|
329
|
+
{
|
|
330
|
+
"opcode": "respondWithNamedBody",
|
|
331
|
+
"blockType": "COMMAND",
|
|
332
|
+
"text": "respond with named [NAMESPACE] [NAME] kind [KIND] scope [SCOPE] target [TARGET_ID] as [REPRESENTATION] max bytes [MAX_BYTES]",
|
|
333
|
+
"description": "Completes the response with a named structured, document, binary, or asset snapshot resolved by the server.",
|
|
334
|
+
"arguments": {
|
|
335
|
+
"NAMESPACE": {"type": "STRING", "defaultValue": "asset"},
|
|
336
|
+
"NAME": {"type": "STRING", "defaultValue": "avatar"},
|
|
337
|
+
"KIND": {"type": "STRING", "defaultValue": "asset"},
|
|
338
|
+
"SCOPE": {"type": "STRING", "defaultValue": "project"},
|
|
339
|
+
"TARGET_ID": {"type": "STRING", "defaultValue": "Stage:1"},
|
|
340
|
+
"REPRESENTATION": {"type": "STRING", "defaultValue": "raw"},
|
|
341
|
+
"MAX_BYTES": {"type": "NUMBER", "defaultValue": 10485760}
|
|
342
|
+
}
|
|
343
|
+
},
|
|
268
344
|
{
|
|
269
345
|
"opcode": "recordHttpLog",
|
|
270
346
|
"blockType": "COMMAND",
|
package/src/cli.ts
CHANGED
|
@@ -1,41 +1,59 @@
|
|
|
1
1
|
import {readFileSync} from 'node:fs';
|
|
2
2
|
import {HtdigestFile} from './auth/digest-file.js';
|
|
3
|
+
import type {DigestAuthOptions} from './auth/digest.js';
|
|
3
4
|
import {startServer} from './server.js';
|
|
4
5
|
import type {CommunityServerOptions} from './community.js';
|
|
5
|
-
import type
|
|
6
|
+
import {compileToDirectory, type CompilerInputFormat} from './compiler/index.js';
|
|
6
7
|
|
|
7
8
|
interface CliOptions {
|
|
8
9
|
hostname: string;
|
|
9
10
|
port: number;
|
|
10
11
|
community?: false | CommunityServerOptions;
|
|
12
|
+
namedResponseBody?: boolean;
|
|
11
13
|
authDigestFile?: string;
|
|
12
14
|
authRealm?: string;
|
|
13
15
|
tlsCert?: string;
|
|
14
16
|
tlsKey?: string;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
void main(process.argv.slice(2)).catch((error: unknown) => {
|
|
20
|
+
console.error(error instanceof Error ? error.message : error);
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
async function main(args: readonly string[]): Promise<void> {
|
|
25
|
+
if (args[0] === 'compile') {
|
|
26
|
+
const options = parseCompileArgs(args.slice(1));
|
|
27
|
+
const result = await compileToDirectory(options);
|
|
28
|
+
for (const diagnostic of result.diagnostics) {
|
|
29
|
+
console.warn(`[${diagnostic.code}] ${diagnostic.message}`);
|
|
30
|
+
}
|
|
31
|
+
console.log(`Generated ${result.files.length} files in ${options.output}.`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const options = parseArgs(args);
|
|
36
|
+
const server = startServer(toServerOptions(options));
|
|
37
|
+
console.log(
|
|
38
|
+
`turbowarp-http-server listening on ${options.tlsCert ? 'https' : 'http'}://${server.hostname}:${server.port}`
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
function shutdown(signal: string): void {
|
|
42
|
+
console.log(`Received ${signal}; shutting down.`);
|
|
43
|
+
server
|
|
44
|
+
.close()
|
|
45
|
+
.catch((error: unknown) => {
|
|
46
|
+
console.error(error);
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
})
|
|
49
|
+
.finally(() => {
|
|
50
|
+
process.exit();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
36
53
|
|
|
37
|
-
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
38
|
-
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
54
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
55
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
56
|
+
}
|
|
39
57
|
|
|
40
58
|
function parseArgs(args: readonly string[]): CliOptions {
|
|
41
59
|
const options: CliOptions = {
|
|
@@ -66,6 +84,8 @@ function parseArgs(args: readonly string[]): CliOptions {
|
|
|
66
84
|
index += 1;
|
|
67
85
|
} else if (arg === '--community') {
|
|
68
86
|
options.community = {};
|
|
87
|
+
} else if (arg === '--enable-named-response-body') {
|
|
88
|
+
options.namedResponseBody = true;
|
|
69
89
|
} else if (arg === '--auth-digest') {
|
|
70
90
|
options.authDigestFile = requireValue(args, index, '--auth-digest');
|
|
71
91
|
index += 1;
|
|
@@ -99,12 +119,84 @@ function parseArgs(args: readonly string[]): CliOptions {
|
|
|
99
119
|
return options;
|
|
100
120
|
}
|
|
101
121
|
|
|
122
|
+
function parseCompileArgs(args: readonly string[]): {
|
|
123
|
+
input: string;
|
|
124
|
+
output: string;
|
|
125
|
+
format: CompilerInputFormat;
|
|
126
|
+
force: boolean;
|
|
127
|
+
target: string;
|
|
128
|
+
targetConfig?: string;
|
|
129
|
+
manifestLock?: string;
|
|
130
|
+
namedResponseBody: boolean;
|
|
131
|
+
} {
|
|
132
|
+
let input = '';
|
|
133
|
+
let output = '';
|
|
134
|
+
let format: CompilerInputFormat = 'turbowarp-json';
|
|
135
|
+
let force = false;
|
|
136
|
+
let target: string | undefined;
|
|
137
|
+
let targetConfig: string | undefined;
|
|
138
|
+
let manifestLock: string | undefined;
|
|
139
|
+
let namedResponseBody = false;
|
|
140
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
141
|
+
const arg = args[index];
|
|
142
|
+
if (arg === '--input') {
|
|
143
|
+
input = requireValue(args, index, '--input');
|
|
144
|
+
index += 1;
|
|
145
|
+
} else if (arg === '--output') {
|
|
146
|
+
output = requireValue(args, index, '--output');
|
|
147
|
+
index += 1;
|
|
148
|
+
} else if (arg === '--format') {
|
|
149
|
+
const value = requireValue(args, index, '--format');
|
|
150
|
+
if (value !== 'turbowarp-json' && value !== 'ir') throw new Error(`Invalid format: ${value}`);
|
|
151
|
+
format = value;
|
|
152
|
+
index += 1;
|
|
153
|
+
} else if (arg === '--force') {
|
|
154
|
+
force = true;
|
|
155
|
+
} else if (arg === '--target') {
|
|
156
|
+
target = requireValue(args, index, '--target');
|
|
157
|
+
index += 1;
|
|
158
|
+
} else if (arg === '--target-config') {
|
|
159
|
+
targetConfig = requireValue(args, index, '--target-config');
|
|
160
|
+
index += 1;
|
|
161
|
+
} else if (arg === '--manifest-lock') {
|
|
162
|
+
manifestLock = requireValue(args, index, '--manifest-lock');
|
|
163
|
+
index += 1;
|
|
164
|
+
} else if (arg === '--enable-named-response-body') {
|
|
165
|
+
namedResponseBody = true;
|
|
166
|
+
} else if (arg === '--help' || arg === '-h') {
|
|
167
|
+
printCompileHelp();
|
|
168
|
+
process.exit(0);
|
|
169
|
+
} else {
|
|
170
|
+
throw new Error(`Unknown compile argument: ${arg}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (!input) throw new Error('compile requires --input <file>.');
|
|
174
|
+
if (!output) throw new Error('compile requires --output <directory>.');
|
|
175
|
+
if (target === undefined) throw new Error('compile requires --target <id>.');
|
|
176
|
+
if (manifestLock !== undefined && format !== 'turbowarp-json') {
|
|
177
|
+
throw new Error('--manifest-lock requires --format turbowarp-json.');
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
input,
|
|
181
|
+
output,
|
|
182
|
+
format,
|
|
183
|
+
force,
|
|
184
|
+
target,
|
|
185
|
+
namedResponseBody,
|
|
186
|
+
...(targetConfig === undefined ? {} : {targetConfig}),
|
|
187
|
+
...(manifestLock === undefined ? {} : {manifestLock})
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
102
191
|
function toServerOptions(options: CliOptions): Parameters<typeof startServer>[0] {
|
|
103
192
|
const serverOptions: Parameters<typeof startServer>[0] = {
|
|
104
193
|
hostname: options.hostname,
|
|
105
194
|
port: options.port
|
|
106
195
|
};
|
|
107
196
|
if (options.community !== undefined) serverOptions.community = options.community;
|
|
197
|
+
if (options.namedResponseBody !== undefined) {
|
|
198
|
+
serverOptions.namedResponseBody = options.namedResponseBody;
|
|
199
|
+
}
|
|
108
200
|
const digestAuth = toDigestAuthOptions(options);
|
|
109
201
|
if (digestAuth) serverOptions.digestAuth = digestAuth;
|
|
110
202
|
if (options.tlsCert && options.tlsKey) {
|
|
@@ -145,7 +237,9 @@ function isTruthy(value: string | undefined): boolean {
|
|
|
145
237
|
}
|
|
146
238
|
|
|
147
239
|
function printHelp(): void {
|
|
148
|
-
console.log(`Usage:
|
|
240
|
+
console.log(`Usage:
|
|
241
|
+
turbowarp-http-server [--host <host>] [--port <port>]
|
|
242
|
+
turbowarp-http-server compile --input <file> --output <directory> [options]
|
|
149
243
|
|
|
150
244
|
Starts the companion HTTP/WebSocket bridge for the TurboWarp extension.
|
|
151
245
|
|
|
@@ -153,6 +247,7 @@ Options:
|
|
|
153
247
|
--host <host> Hostname or address to bind. Defaults to HOST or 127.0.0.1.
|
|
154
248
|
--port <port> TCP port to bind. Defaults to PORT or 8787.
|
|
155
249
|
--community Enable the learning-only Scratch-like community routes.
|
|
250
|
+
--enable-named-response-body Enable experimental named response blocks (default OFF).
|
|
156
251
|
--auth-digest <file>
|
|
157
252
|
Enable HTTP Digest authentication using an htdigest file.
|
|
158
253
|
--auth-realm <realm>
|
|
@@ -170,3 +265,21 @@ Environment:
|
|
|
170
265
|
TURBOWARP_HTTP_TLS_KEY
|
|
171
266
|
`);
|
|
172
267
|
}
|
|
268
|
+
|
|
269
|
+
function printCompileHelp(): void {
|
|
270
|
+
console.log(`Usage: turbowarp-http-server compile --input <file> --output <directory> [options]
|
|
271
|
+
|
|
272
|
+
Compiles an accepted TurboWarp project.json subset or deploy IR to Hono deployment artifacts.
|
|
273
|
+
|
|
274
|
+
Options:
|
|
275
|
+
--input <file> TurboWarp project.json or deploy IR JSON.
|
|
276
|
+
--output <directory> Generated project directory.
|
|
277
|
+
--format <format> turbowarp-json (default) or ir.
|
|
278
|
+
--target <id> Required deployment target; for example cloudflare-workers.
|
|
279
|
+
--target-config <file> Adapter config containing binding names, never secrets.
|
|
280
|
+
--manifest-lock <file> Locked extension manifests for TurboWarp project input.
|
|
281
|
+
--enable-named-response-body Enable the experimental named body IR operation (default OFF).
|
|
282
|
+
--force Replace generated files in a non-empty output directory.
|
|
283
|
+
-h, --help Show this help.
|
|
284
|
+
`);
|
|
285
|
+
}
|