@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,123 @@
|
|
|
1
|
+
import { IrRuntimeError } from '../runtime/error.js';
|
|
2
|
+
import { DEFAULT_MAX_BINARY_BYTES } from './types.js';
|
|
3
|
+
import { validateBinaryLocator, validateBinaryMetadata } from './codec.js';
|
|
4
|
+
import { binaryError } from './error.js';
|
|
5
|
+
export class BinaryBodyHandle {
|
|
6
|
+
constructor(source) {
|
|
7
|
+
this.source = source;
|
|
8
|
+
this.consumed = false;
|
|
9
|
+
}
|
|
10
|
+
take() {
|
|
11
|
+
if (this.consumed)
|
|
12
|
+
binaryError('BINARY_BODY_CONSUMED', 'Binary body has already been consumed.');
|
|
13
|
+
this.consumed = true;
|
|
14
|
+
return this.source;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function effectiveBinaryLimit(operationLimit, compilerLimit = DEFAULT_MAX_BINARY_BYTES, targetLimit = Number.MAX_SAFE_INTEGER) {
|
|
18
|
+
for (const limit of [operationLimit, compilerLimit, targetLimit]) {
|
|
19
|
+
if (!Number.isSafeInteger(limit) || limit < 1)
|
|
20
|
+
binaryError('BINARY_INVALID_REF', 'Binary limit is invalid.');
|
|
21
|
+
}
|
|
22
|
+
return Math.min(operationLimit, compilerLimit, targetLimit);
|
|
23
|
+
}
|
|
24
|
+
export async function collectBinaryBody(source, maxBytes) {
|
|
25
|
+
if (source.size !== undefined && (!Number.isSafeInteger(source.size) || source.size < 0)) {
|
|
26
|
+
binaryError('BINARY_INVALID_REF', 'Binary body size is invalid.');
|
|
27
|
+
}
|
|
28
|
+
if (source.size !== undefined && source.size > maxBytes) {
|
|
29
|
+
binaryError('BINARY_TOO_LARGE', 'Binary body exceeds the configured limit.');
|
|
30
|
+
}
|
|
31
|
+
const chunks = [];
|
|
32
|
+
let total = 0;
|
|
33
|
+
const iterator = source.chunks[Symbol.asyncIterator]();
|
|
34
|
+
try {
|
|
35
|
+
while (true) {
|
|
36
|
+
const item = await iterator.next();
|
|
37
|
+
if (item.done)
|
|
38
|
+
break;
|
|
39
|
+
total += item.value.byteLength;
|
|
40
|
+
if (total > maxBytes) {
|
|
41
|
+
await iterator.return?.();
|
|
42
|
+
binaryError('BINARY_TOO_LARGE', 'Binary body exceeds the configured limit.');
|
|
43
|
+
}
|
|
44
|
+
chunks.push(item.value.slice());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof IrRuntimeError)
|
|
49
|
+
throw error;
|
|
50
|
+
binaryError('BINARY_STORAGE_FAILURE', 'Binary stream failed.');
|
|
51
|
+
}
|
|
52
|
+
const result = new Uint8Array(total);
|
|
53
|
+
let offset = 0;
|
|
54
|
+
for (const chunk of chunks) {
|
|
55
|
+
result.set(chunk, offset);
|
|
56
|
+
offset += chunk.byteLength;
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
export class InMemoryBinaryObjectStore {
|
|
61
|
+
constructor() {
|
|
62
|
+
this.objects = new Map();
|
|
63
|
+
this.revision = 0;
|
|
64
|
+
}
|
|
65
|
+
async resolve(locator) {
|
|
66
|
+
return this.objects.get(locatorKey(validateBinaryLocator(locator)))?.ref ?? null;
|
|
67
|
+
}
|
|
68
|
+
async get(ref) {
|
|
69
|
+
validateBinaryLocator(ref);
|
|
70
|
+
validateBinaryMetadata(ref);
|
|
71
|
+
const object = this.objects.get(locatorKey(ref));
|
|
72
|
+
if (object === undefined || (ref.revision !== undefined && object.ref.revision !== ref.revision))
|
|
73
|
+
return null;
|
|
74
|
+
const bytes = object.bytes.slice();
|
|
75
|
+
const source = { chunks: chunksOf(bytes), size: bytes.byteLength };
|
|
76
|
+
return object.ref.contentType === undefined ? source : { ...source, contentType: object.ref.contentType };
|
|
77
|
+
}
|
|
78
|
+
async put(locator, source, metadata, maxBytes) {
|
|
79
|
+
validateBinaryLocator(locator);
|
|
80
|
+
validateBinaryMetadata(metadata);
|
|
81
|
+
const bytes = await collectBinaryBody(source, maxBytes);
|
|
82
|
+
if (metadata.size !== undefined && metadata.size !== bytes.byteLength) {
|
|
83
|
+
binaryError('BINARY_INTEGRITY_MISMATCH', 'Binary size does not match.');
|
|
84
|
+
}
|
|
85
|
+
const integrity = await sha256Integrity(bytes);
|
|
86
|
+
if (metadata.integrity !== undefined && metadata.integrity !== integrity) {
|
|
87
|
+
binaryError('BINARY_INTEGRITY_MISMATCH', 'Binary integrity does not match.');
|
|
88
|
+
}
|
|
89
|
+
this.revision += 1;
|
|
90
|
+
const ref = {
|
|
91
|
+
...locator,
|
|
92
|
+
size: bytes.byteLength,
|
|
93
|
+
integrity,
|
|
94
|
+
revision: String(this.revision),
|
|
95
|
+
...(metadata.contentType === undefined ? {} : { contentType: metadata.contentType })
|
|
96
|
+
};
|
|
97
|
+
this.objects.set(locatorKey(locator), { bytes: bytes.slice(), ref });
|
|
98
|
+
return ref;
|
|
99
|
+
}
|
|
100
|
+
async delete(target) {
|
|
101
|
+
validateBinaryLocator(target);
|
|
102
|
+
const key = locatorKey(target);
|
|
103
|
+
const current = this.objects.get(key);
|
|
104
|
+
if (current === undefined)
|
|
105
|
+
return false;
|
|
106
|
+
if ('revision' in target && target.revision !== undefined && target.revision !== current.ref.revision)
|
|
107
|
+
return false;
|
|
108
|
+
return this.objects.delete(key);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function sha256Integrity(bytes) {
|
|
112
|
+
const copy = new Uint8Array(bytes.byteLength);
|
|
113
|
+
copy.set(bytes);
|
|
114
|
+
const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', copy.buffer));
|
|
115
|
+
return `sha256:${Array.from(digest, (byte) => byte.toString(16).padStart(2, '0')).join('')}`;
|
|
116
|
+
}
|
|
117
|
+
function locatorKey(locator) {
|
|
118
|
+
return `${locator.namespace}\u0000${locator.key}`;
|
|
119
|
+
}
|
|
120
|
+
async function* chunksOf(bytes) {
|
|
121
|
+
yield bytes;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/compiler/binary/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,wBAAwB,EAAgD,MAAM,YAAY,CAAC;AACnG,OAAO,EAAC,qBAAqB,EAAE,sBAAsB,EAAC,MAAM,YAAY,CA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pH,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;CACF;AAED,KAAK,UAAU,eAAe,CAAC,KAAiB;IAC9C,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChB,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClF,OAAO,UAAU,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/F,CAAC;AAED,SAAS,UAAU,CAAC,OAAwB;IAC1C,OAAO,GAAG,OAAO,CAAC,SAAS,SAAS,OAAO,CAAC,GAAG,EAAE,CAAC;AACpD,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,QAAQ,CAAC,KAAiB;IACxC,MAAM,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BinaryLocatorV2, BinaryMetadataV2, BinaryRefDescriptorV2 } from '../ir-v2/types.js';
|
|
2
|
+
export declare const DEFAULT_MAX_BINARY_BYTES: number;
|
|
3
|
+
export interface BinaryBodySource {
|
|
4
|
+
readonly chunks: AsyncIterable<Uint8Array>;
|
|
5
|
+
readonly contentType?: string;
|
|
6
|
+
readonly size?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface BinaryObjectStore {
|
|
9
|
+
resolve(locator: BinaryLocatorV2): Promise<BinaryRefDescriptorV2 | null>;
|
|
10
|
+
get(ref: BinaryRefDescriptorV2): Promise<BinaryBodySource | null>;
|
|
11
|
+
put(locator: BinaryLocatorV2, source: BinaryBodySource, metadata: BinaryMetadataV2, maxBytes: number): Promise<BinaryRefDescriptorV2>;
|
|
12
|
+
delete(target: BinaryLocatorV2 | BinaryRefDescriptorV2): Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
export interface BinaryTargetLimits {
|
|
15
|
+
maxBinaryBytes: number;
|
|
16
|
+
supportsStreaming: boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/compiler/binary/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-flags.js","sourceRoot":"","sources":["../../src/compiler/feature-flags.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,8BAA8B,GAAmC,MAAM,CAAC,MAAM,CAAC;IAC1F,iBAAiB,EAAE,KAAK;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type CompilerDiagnosticV2, type DeployIrV2 } from './ir-v2/index.js';
|
|
2
|
+
import { type PipelineDiagnostic } from './pipeline/index.js';
|
|
3
|
+
export * from './feature-flags.js';
|
|
4
|
+
export * from './adapters/index.js';
|
|
5
|
+
export * from './binary/index.js';
|
|
6
|
+
export * from './ir-v2/index.js';
|
|
7
|
+
export * from './manifest/index.js';
|
|
8
|
+
export * from './named-body/index.js';
|
|
9
|
+
export * from './pipeline/index.js';
|
|
10
|
+
export * from './runtime/index.js';
|
|
11
|
+
export * from './structured-data/index.js';
|
|
12
|
+
export * from './turbowarp-v2.js';
|
|
13
|
+
export * from './validator/index.js';
|
|
14
|
+
export type CompilerInputFormat = 'turbowarp-json' | 'ir';
|
|
15
|
+
export interface CompileOptions {
|
|
16
|
+
input: string;
|
|
17
|
+
output: string;
|
|
18
|
+
format: CompilerInputFormat;
|
|
19
|
+
force?: boolean;
|
|
20
|
+
target: string;
|
|
21
|
+
targetConfig?: string;
|
|
22
|
+
manifestLock?: string;
|
|
23
|
+
namedResponseBody?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface CompilerOutput {
|
|
26
|
+
ir: DeployIrV2;
|
|
27
|
+
diagnostics: Array<CompilerDiagnosticV2 | PipelineDiagnostic>;
|
|
28
|
+
files: string[];
|
|
29
|
+
}
|
|
30
|
+
export declare function compileToDirectory(options: CompileOptions): Promise<CompilerOutput>;
|
|
31
|
+
type AnyCompilerDiagnostic = CompilerDiagnosticV2 | PipelineDiagnostic;
|
|
32
|
+
export declare class CompilerDiagnosticsError extends Error {
|
|
33
|
+
readonly diagnostics: AnyCompilerDiagnostic[];
|
|
34
|
+
constructor(diagnostics: AnyCompilerDiagnostic[]);
|
|
35
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, extname, join, resolve } from 'node:path';
|
|
3
|
+
import { compileTurboWarpProjectV2 } from './turbowarp-v2.js';
|
|
4
|
+
import { resolveCompilerManifestLock } from './manifest/resolve.js';
|
|
5
|
+
import { parseDeployIrV2Json } from './ir-v2/index.js';
|
|
6
|
+
import { compileDeployIrV2 } from './pipeline/index.js';
|
|
7
|
+
export * from './feature-flags.js';
|
|
8
|
+
export * from './adapters/index.js';
|
|
9
|
+
export * from './binary/index.js';
|
|
10
|
+
export * from './ir-v2/index.js';
|
|
11
|
+
export * from './manifest/index.js';
|
|
12
|
+
export * from './named-body/index.js';
|
|
13
|
+
export * from './pipeline/index.js';
|
|
14
|
+
export * from './runtime/index.js';
|
|
15
|
+
export * from './structured-data/index.js';
|
|
16
|
+
export * from './turbowarp-v2.js';
|
|
17
|
+
export * from './validator/index.js';
|
|
18
|
+
export async function compileToDirectory(options) {
|
|
19
|
+
if (extname(options.input).toLowerCase() === '.sb3') {
|
|
20
|
+
throw new Error('Direct .sb3 input is not supported yet. Export or extract project.json first.');
|
|
21
|
+
}
|
|
22
|
+
if (options.manifestLock !== undefined && options.format !== 'turbowarp-json') {
|
|
23
|
+
throw new Error('manifestLock requires TurboWarp JSON input.');
|
|
24
|
+
}
|
|
25
|
+
const inputPath = resolve(options.input);
|
|
26
|
+
const outputPath = resolve(options.output);
|
|
27
|
+
const source = await readFile(inputPath, 'utf8');
|
|
28
|
+
const registry = options.format === 'turbowarp-json' && options.manifestLock !== undefined
|
|
29
|
+
? (await resolveCompilerManifestLock(options.manifestLock)).registry
|
|
30
|
+
: undefined;
|
|
31
|
+
const frontend = options.format === 'ir'
|
|
32
|
+
? { ir: parseDeployIrV2Json(source), diagnostics: [] }
|
|
33
|
+
: compileTurboWarpProjectV2(JSON.parse(source), registry);
|
|
34
|
+
const frontendErrors = frontend.diagnostics.filter(({ severity }) => severity === 'error');
|
|
35
|
+
if (frontendErrors.length > 0)
|
|
36
|
+
throw new CompilerDiagnosticsError(frontendErrors);
|
|
37
|
+
const ir = frontend.ir;
|
|
38
|
+
const targetConfig = options.targetConfig === undefined
|
|
39
|
+
? undefined
|
|
40
|
+
: JSON.parse(await readFile(resolve(options.targetConfig), 'utf8'));
|
|
41
|
+
const result = compileDeployIrV2(ir, {
|
|
42
|
+
target: options.target,
|
|
43
|
+
targetConfig,
|
|
44
|
+
featureFlags: { namedResponseBody: options.namedResponseBody === true }
|
|
45
|
+
});
|
|
46
|
+
if (!result.ok)
|
|
47
|
+
throw new CompilerDiagnosticsError(result.diagnostics);
|
|
48
|
+
await writeGeneratedFiles(outputPath, result.files, options.force === true);
|
|
49
|
+
return { ir, diagnostics: frontend.diagnostics, files: Object.keys(result.files).sort() };
|
|
50
|
+
}
|
|
51
|
+
async function writeGeneratedFiles(output, files, force) {
|
|
52
|
+
await mkdir(output, { recursive: true });
|
|
53
|
+
const existing = await readdir(output);
|
|
54
|
+
if (existing.length > 0 && !force) {
|
|
55
|
+
throw new Error(`Output directory is not empty: ${output}. Use --force to replace generated files.`);
|
|
56
|
+
}
|
|
57
|
+
for (const [relativePath, contents] of Object.entries(files)) {
|
|
58
|
+
const destination = join(output, relativePath);
|
|
59
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
60
|
+
await writeFile(destination, contents, 'utf8');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export class CompilerDiagnosticsError extends Error {
|
|
64
|
+
constructor(diagnostics) {
|
|
65
|
+
super(diagnostics.map(formatDiagnostic).join('\n'));
|
|
66
|
+
this.diagnostics = diagnostics;
|
|
67
|
+
this.name = 'CompilerDiagnosticsError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function formatDiagnostic(diagnostic) {
|
|
71
|
+
const location = diagnosticLocation(diagnostic);
|
|
72
|
+
return `[${diagnostic.code}]${location ? ` ${location}` : ''} ${diagnostic.message}`;
|
|
73
|
+
}
|
|
74
|
+
function diagnosticLocation(diagnostic) {
|
|
75
|
+
if ('reason' in diagnostic) {
|
|
76
|
+
return [diagnostic.targetId, diagnostic.routeId, diagnostic.sourceRef?.blockId].filter(Boolean).join(':');
|
|
77
|
+
}
|
|
78
|
+
if (diagnostic.code.startsWith('TW2_')) {
|
|
79
|
+
const sourceRef = diagnostic.sourceRef;
|
|
80
|
+
return [sourceRef?.targetName, sourceRef?.blockId].filter(Boolean).join(':');
|
|
81
|
+
}
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAC,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAC,yBAAyB,EAAC,MAAM,mBAAmB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,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;AACvF,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAiC;IAC3D,IAAI,QAAQ,IAAI,UAAU,EAAE,CAAC;QAC3B,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5G,CAAC;IACD,IAAI,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACvC,MAAM,SAAS,GAAI,UAAmC,CAAC,SAAS,CAAC;QACjE,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export function canonicalizeDeployIrV2(ir) {
|
|
2
|
+
return canonicalizeJson(ir);
|
|
3
|
+
}
|
|
4
|
+
export function canonicalizeJson(value) {
|
|
5
|
+
if (value === null)
|
|
6
|
+
return 'null';
|
|
7
|
+
if (typeof value === 'boolean')
|
|
8
|
+
return JSON.stringify(value);
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
assertWellFormedUnicode(value);
|
|
11
|
+
return JSON.stringify(value);
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === 'number') {
|
|
14
|
+
if (!Number.isFinite(value))
|
|
15
|
+
throw new Error('JCS numbers must be finite.');
|
|
16
|
+
return JSON.stringify(Object.is(value, -0) ? 0 : value);
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value))
|
|
19
|
+
return `[${value.map(canonicalizeJson).join(',')}]`;
|
|
20
|
+
const keys = Object.keys(value);
|
|
21
|
+
for (const key of keys)
|
|
22
|
+
assertWellFormedUnicode(key);
|
|
23
|
+
return `{${keys
|
|
24
|
+
.sort(compareUtf16)
|
|
25
|
+
.map((key) => `${JSON.stringify(key)}:${canonicalizeJson(value[key])}`)
|
|
26
|
+
.join(',')}}`;
|
|
27
|
+
}
|
|
28
|
+
function assertWellFormedUnicode(value) {
|
|
29
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
30
|
+
const code = value.charCodeAt(index);
|
|
31
|
+
if (code >= 0xd800 && code <= 0xdbff) {
|
|
32
|
+
const next = value.charCodeAt(index + 1);
|
|
33
|
+
if (!(next >= 0xdc00 && next <= 0xdfff)) {
|
|
34
|
+
throw new Error('JCS strings must not contain lone surrogates.');
|
|
35
|
+
}
|
|
36
|
+
index += 1;
|
|
37
|
+
}
|
|
38
|
+
else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
39
|
+
throw new Error('JCS strings must not contain lone surrogates.');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function compareUtf16(left, right) {
|
|
44
|
+
if (left < right)
|
|
45
|
+
return -1;
|
|
46
|
+
if (left > right)
|
|
47
|
+
return 1;
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=canonical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../../src/compiler/ir-v2/canonical.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,sBAAsB,CAAC,EAAc;IACnD,OAAO,gBAAgB,CAAC,EAA0B,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAgB;IAC/C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,uBAAuB,CAAC,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C,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YACzC,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC,EAAE,CAAC;gBACxC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;YACnE,CAAC;YACD,KAAK,IAAI,CAAC,CAAC;QACb,CAAC;aAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,KAAa;IAC/C,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,CAAC,CAAC,CAAC;IAC5B,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,CAAC,CAAC;IAC3B,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { canonicalizeDeployIrV2, canonicalizeJson } from './canonical.js';
|
|
2
|
+
export { DeployIrV2ParseError, parseDeployIrV2, parseDeployIrV2Json, type DeployIrV2ParseErrorCode } from './parse.js';
|
|
3
|
+
export { parseJsonWithoutDuplicateKeys } from './strict-json.js';
|
|
4
|
+
export * from './types.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { canonicalizeDeployIrV2, canonicalizeJson } from './canonical.js';
|
|
2
|
+
export { DeployIrV2ParseError, parseDeployIrV2, parseDeployIrV2Json } from './parse.js';
|
|
3
|
+
export { parseJsonWithoutDuplicateKeys } from './strict-json.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/compiler/ir-v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAE,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AACxE,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,6BAA6B,EAAC,MAAM,kBAAkB,CAAC;AAC/D,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DeployIrV2 } from './types.js';
|
|
2
|
+
export type DeployIrV2ParseErrorCode = 'TW2_IR_JSON_SYNTAX' | 'TW2_IR_DUPLICATE_KEY' | 'TW2_IR_VERSION' | 'TW2_IR_UNKNOWN_FIELD' | 'TW2_IR_UNKNOWN_NODE' | 'TW2_IR_INVALID_VALUE';
|
|
3
|
+
export declare class DeployIrV2ParseError extends Error {
|
|
4
|
+
readonly code: DeployIrV2ParseErrorCode;
|
|
5
|
+
readonly cause?: unknown | undefined;
|
|
6
|
+
readonly name = "DeployIrV2ParseError";
|
|
7
|
+
constructor(code: DeployIrV2ParseErrorCode, message: string, cause?: unknown | undefined);
|
|
8
|
+
}
|
|
9
|
+
export declare function parseDeployIrV2Json(text: string): DeployIrV2;
|
|
10
|
+
export declare function parseDeployIrV2(value: unknown): DeployIrV2;
|