@astrale-os/adapter-cloudflare 0.5.0-beta.22 → 0.5.0-beta.221
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.md +246 -0
- package/dist/adapter.d.ts +9 -15
- package/dist/adapter.js +43 -129
- package/dist/build/bundle/admit.d.ts +3 -0
- package/dist/build/bundle/admit.js +47 -0
- package/dist/build/bundle/compiled-wasm-loader.d.ts +8 -0
- package/dist/build/bundle/compiled-wasm-loader.js +21 -0
- package/dist/build/bundler.d.ts +21 -0
- package/dist/build/bundler.js +96 -0
- package/dist/build/closure.d.ts +4 -1
- package/dist/build/closure.js +7 -1
- package/dist/build/codegen/execution.d.ts +3 -13
- package/dist/build/codegen/execution.js +2 -44
- package/dist/build/codegen/wrangler.d.ts +28 -10
- package/dist/build/codegen/wrangler.js +71 -21
- package/dist/build/configuration/invocation-timeout.d.ts +2 -0
- package/dist/build/configuration/invocation-timeout.js +9 -0
- package/dist/build/configuration/request-limit.d.ts +2 -0
- package/dist/build/configuration/request-limit.js +9 -0
- package/dist/build/configuration/router.d.ts +7 -0
- package/dist/build/configuration/router.js +17 -0
- package/dist/build/configuration/settings.d.ts +6 -0
- package/dist/build/configuration/settings.js +40 -0
- package/dist/build/configuration.d.ts +4 -9
- package/dist/build/configuration.js +4 -40
- package/dist/build/frontend/files.d.ts +19 -0
- package/dist/build/frontend/files.js +99 -0
- package/dist/build/frontend/readiness.d.ts +16 -0
- package/dist/build/frontend/readiness.js +21 -0
- package/dist/build/frontend/revision.d.ts +5 -0
- package/dist/build/frontend/revision.js +14 -0
- package/dist/build/frontend/vite.d.ts +14 -0
- package/dist/build/frontend/vite.js +42 -0
- package/dist/build/frontend/vite.process.d.ts +7 -0
- package/dist/build/frontend/vite.process.js +65 -0
- package/dist/build/frontend/vite.runner.d.ts +1 -0
- package/dist/build/frontend/vite.runner.js +155 -0
- package/dist/build/index.d.ts +10 -6
- package/dist/build/index.js +10 -6
- package/dist/build/material.d.ts +10 -0
- package/dist/build/material.js +25 -0
- package/dist/build/worker/codegen/entry.d.ts +9 -0
- package/dist/build/worker/codegen/entry.js +65 -0
- package/dist/build/worker/codegen/literal.d.ts +28 -0
- package/dist/build/worker/codegen/literal.js +136 -0
- package/dist/build/worker/codegen/service.d.ts +14 -0
- package/dist/build/worker/codegen/service.js +57 -0
- package/dist/build/worker/execution.prepare.d.ts +20 -0
- package/dist/build/worker/execution.prepare.js +129 -0
- package/dist/build/worker/media-type.d.ts +1 -0
- package/dist/build/worker/media-type.js +20 -0
- package/dist/build/worker/modules.d.ts +20 -0
- package/dist/build/worker/modules.js +32 -0
- package/dist/build/worker/specifier.d.ts +5 -0
- package/dist/build/worker/specifier.js +15 -0
- package/dist/build/worker/upload.d.ts +23 -0
- package/dist/build/worker/upload.js +42 -0
- package/dist/hosting/activation.d.ts +46 -0
- package/dist/hosting/activation.js +127 -0
- package/dist/hosting/assets.d.ts +14 -0
- package/dist/hosting/assets.js +53 -0
- package/dist/hosting/bounded.d.ts +10 -0
- package/dist/hosting/bounded.js +32 -0
- package/dist/hosting/bytes.d.ts +6 -0
- package/dist/hosting/bytes.js +25 -0
- package/dist/hosting/client.d.ts +144 -0
- package/dist/hosting/client.js +491 -0
- package/dist/hosting/dispatcher/cron.d.mts +10 -0
- package/dist/hosting/dispatcher/cron.mjs +135 -0
- package/dist/hosting/dispatcher/deployments.d.mts +26 -0
- package/dist/hosting/dispatcher/deployments.mjs +158 -0
- package/dist/hosting/dispatcher/dispatcher.d.mts +17 -0
- package/dist/hosting/dispatcher/dispatcher.mjs +76 -0
- package/dist/hosting/dispatcher/env.d.mts +51 -0
- package/dist/hosting/dispatcher/failure.d.mts +4 -0
- package/dist/hosting/dispatcher/failure.mjs +15 -0
- package/dist/hosting/dispatcher/index.d.mts +4 -0
- package/dist/hosting/dispatcher/index.mjs +8 -0
- package/dist/hosting/dispatcher/modules.d.ts +24 -0
- package/dist/hosting/dispatcher/modules.js +55 -0
- package/dist/hosting/dispatcher/services.d.mts +23 -0
- package/dist/hosting/dispatcher/services.mjs +202 -0
- package/dist/hosting/identity.d.ts +15 -0
- package/dist/hosting/identity.js +36 -0
- package/dist/hosting/index.d.ts +34 -0
- package/dist/hosting/index.js +32 -0
- package/dist/hosting/kv.d.ts +90 -0
- package/dist/hosting/kv.js +207 -0
- package/dist/hosting/listing.d.ts +34 -0
- package/dist/hosting/listing.js +49 -0
- package/dist/hosting/names.d.ts +16 -0
- package/dist/hosting/names.js +28 -0
- package/dist/hosting/provision/account.d.ts +11 -0
- package/dist/hosting/provision/account.js +86 -0
- package/dist/hosting/provision/dispatcher.d.ts +42 -0
- package/dist/hosting/provision/dispatcher.js +99 -0
- package/dist/hosting/provision/ingress.d.ts +12 -0
- package/dist/hosting/provision/ingress.js +31 -0
- package/dist/hosting/provision/plan.d.ts +143 -0
- package/dist/hosting/provision/plan.js +246 -0
- package/dist/hosting/provision/routing.d.ts +82 -0
- package/dist/hosting/provision/routing.js +226 -0
- package/dist/hosting/readiness.d.ts +53 -0
- package/dist/hosting/readiness.js +82 -0
- package/dist/hosting/refusal.d.ts +28 -0
- package/dist/hosting/refusal.js +13 -0
- package/dist/hosting/retirement.d.ts +68 -0
- package/dist/hosting/retirement.js +99 -0
- package/dist/hosting/retry-after.d.ts +6 -0
- package/dist/hosting/retry-after.js +55 -0
- package/dist/hosting/script.d.ts +186 -0
- package/dist/hosting/script.js +324 -0
- package/dist/hosting/testing/fake-cloudflare.d.ts +212 -0
- package/dist/hosting/testing/fake-cloudflare.js +757 -0
- package/dist/hosting/testing/index.d.ts +6 -0
- package/dist/hosting/testing/index.js +6 -0
- package/dist/hosting/time.d.ts +4 -0
- package/dist/hosting/time.js +20 -0
- package/dist/identity/binding.d.ts +1 -1
- package/dist/identity/binding.js +1 -1
- package/dist/identity/material.d.ts +1 -2
- package/dist/identity/material.js +5 -18
- package/dist/index.d.ts +14 -12
- package/dist/index.js +13 -11
- package/dist/namespace/configure.d.ts +22 -0
- package/dist/namespace/configure.js +199 -0
- package/dist/namespace/coordinates.d.ts +15 -0
- package/dist/namespace/coordinates.js +49 -0
- package/dist/namespace/deploy-release.d.ts +53 -0
- package/dist/namespace/deploy-release.js +386 -0
- package/dist/namespace/hosting.d.ts +29 -0
- package/dist/namespace/hosting.js +120 -0
- package/dist/namespace/index.d.ts +12 -0
- package/dist/namespace/index.js +12 -0
- package/dist/namespace/list.d.ts +18 -0
- package/dist/namespace/list.js +63 -0
- package/dist/namespace/readiness.d.ts +30 -0
- package/dist/namespace/readiness.js +31 -0
- package/dist/namespace/record.d.ts +21 -0
- package/dist/namespace/record.js +53 -0
- package/dist/params.d.ts +60 -76
- package/dist/release/build.d.ts +35 -0
- package/dist/release/build.js +44 -0
- package/dist/release/deployment.d.ts +44 -0
- package/dist/release/deployment.js +141 -0
- package/dist/release/index.d.ts +2 -2
- package/dist/release/index.js +2 -2
- package/dist/worker/binary.d.ts +21 -0
- package/dist/worker/binary.js +31 -0
- package/dist/worker/build-digest.d.ts +10 -0
- package/dist/worker/build-digest.js +22 -0
- package/dist/worker/cache.d.ts +28 -0
- package/dist/worker/cache.js +70 -0
- package/dist/worker/durable.d.ts +3 -0
- package/dist/worker/durable.js +5 -0
- package/dist/worker/entry.d.ts +38 -25
- package/dist/worker/entry.js +87 -109
- package/dist/worker/front.d.ts +56 -0
- package/dist/worker/front.js +59 -0
- package/dist/worker/frontend.d.ts +4 -0
- package/dist/worker/frontend.js +83 -0
- package/dist/worker/index.d.ts +4 -1
- package/dist/worker/index.js +4 -1
- package/dist/worker/restate.d.ts +6 -0
- package/dist/worker/restate.js +6 -0
- package/dist/worker/settings.d.ts +47 -0
- package/dist/worker/settings.js +163 -0
- package/dist/wrangler/bundle.d.ts +10 -0
- package/dist/wrangler/bundle.js +27 -0
- package/dist/wrangler/index.d.ts +3 -0
- package/dist/wrangler/index.js +3 -0
- package/dist/wrangler/process.d.ts +15 -0
- package/dist/wrangler/process.js +113 -0
- package/dist/wrangler/type-generation.d.ts +6 -0
- package/dist/wrangler/type-generation.js +19 -0
- package/package.json +36 -14
- package/template/astrale.config.ts +42 -36
- package/dist/build/artifact.d.ts +0 -8
- package/dist/build/artifact.js +0 -179
- package/dist/build/codegen/gateway.d.ts +0 -1
- package/dist/build/codegen/gateway.js +0 -7
- package/dist/build/frontend-v1.d.ts +0 -16
- package/dist/build/frontend-v1.js +0 -133
- package/dist/build/parse-output.d.ts +0 -26
- package/dist/build/parse-output.js +0 -57
- package/dist/build/wrangler-cli.d.ts +0 -105
- package/dist/build/wrangler-cli.js +0 -448
- package/dist/deploy/deploy.d.ts +0 -17
- package/dist/deploy/deploy.js +0 -207
- package/dist/deploy/index.d.ts +0 -1
- package/dist/deploy/index.js +0 -1
- package/dist/identity/secret.d.ts +0 -3
- package/dist/identity/secret.js +0 -7
- package/dist/identity/source.d.ts +0 -26
- package/dist/identity/source.js +0 -98
- package/dist/release/namespace.d.ts +0 -2
- package/dist/release/namespace.js +0 -6
- package/dist/release/target.d.ts +0 -2
- package/dist/release/target.js +0 -9
- package/dist/worker/gateway.d.ts +0 -15
- package/dist/worker/gateway.js +0 -26
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
|
|
2
|
+
import { readFile, readdir, rm } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { buildViteFrontend } from './vite.js';
|
|
5
|
+
/**
|
|
6
|
+
* Root names that Cloudflare Workers Static Assets reads as configuration rather than serving.
|
|
7
|
+
*
|
|
8
|
+
* Wrangler withholds them from a direct upload and applies them, while the managed upload through
|
|
9
|
+
* Services serves them as ordinary public files, so the same output would behave differently per
|
|
10
|
+
* adapter. The Worker runs first on every request and owns frontend response headers and routing for
|
|
11
|
+
* both, which leaves these files nothing to configure.
|
|
12
|
+
*/
|
|
13
|
+
const RESERVED_ROOT_NAMES = new Set([
|
|
14
|
+
'_headers',
|
|
15
|
+
'_redirects',
|
|
16
|
+
'.assetsignore',
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* Name of a Cloudflare Pages worker script, the server-side code of a Pages project.
|
|
20
|
+
*
|
|
21
|
+
* Wrangler refuses to upload a root asset under this name, since that would publish the code, unless
|
|
22
|
+
* an `.assetsignore` exists, and the reserved names above already exclude one. A direct deployment
|
|
23
|
+
* would therefore fail at upload, while the managed upload through Services would publish the code.
|
|
24
|
+
* Neither adapter runs a Pages worker: the Worker is the only server-side code for both.
|
|
25
|
+
*/
|
|
26
|
+
const PAGES_WORKER_NAME = '_worker.js';
|
|
27
|
+
export async function frontendFiles(input) {
|
|
28
|
+
const frontend = input.frontend;
|
|
29
|
+
if (frontend === undefined)
|
|
30
|
+
return { files: [], addressed: [] };
|
|
31
|
+
if (frontend.source.kind === 'external') {
|
|
32
|
+
return { files: frontendBuild.files(frontend, []), addressed: [] };
|
|
33
|
+
}
|
|
34
|
+
await rm(input.output, { recursive: true, force: true });
|
|
35
|
+
const built = await buildViteFrontend({
|
|
36
|
+
projectDir: input.projectDir,
|
|
37
|
+
output: input.output,
|
|
38
|
+
...(frontend.source.config === undefined ? {} : { config: frontend.source.config }),
|
|
39
|
+
recordSource: input.recordSource,
|
|
40
|
+
signal: input.signal,
|
|
41
|
+
});
|
|
42
|
+
const files = frontendBuild.files(frontend, await readFiles(input.output));
|
|
43
|
+
refuseReservedNames(files);
|
|
44
|
+
refusePagesWorker(files);
|
|
45
|
+
// A name the bundler reported but that never reached disk is not a served path; keeping only the
|
|
46
|
+
// intersection means the evidence describes exactly what this deployment will answer with.
|
|
47
|
+
const served = new Set(files.map((file) => file.path));
|
|
48
|
+
return { files, addressed: built.addressed.filter((path) => served.has(path)) };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Refuse output that Cloudflare would read as asset configuration instead of serving it.
|
|
52
|
+
*
|
|
53
|
+
* Only the root is reserved: a nested `docs/_headers` stays an ordinary file. The match ignores case
|
|
54
|
+
* and covers directories, because Wrangler's upload filter withholds any root entry under these names
|
|
55
|
+
* regardless of case, and a case-insensitive filesystem hands it `_Headers` when it reads `_headers`.
|
|
56
|
+
*/
|
|
57
|
+
function refuseReservedNames(files) {
|
|
58
|
+
const reserved = new Set(files
|
|
59
|
+
.map((file) => file.path.split('/')[0])
|
|
60
|
+
.filter((name) => RESERVED_ROOT_NAMES.has(name.toLowerCase())));
|
|
61
|
+
if (reserved.size === 0)
|
|
62
|
+
return;
|
|
63
|
+
const names = [...reserved].join(', ');
|
|
64
|
+
throw new TypeError(`Frontend output contains reserved Cloudflare asset configuration name(s) at its root: ${names}. ` +
|
|
65
|
+
'A direct cloudflare() deployment would apply them as Workers Static Assets configuration, while a managed astrale() deployment would serve them as public files. ' +
|
|
66
|
+
'The Worker owns frontend response headers and routing for both adapters: remove them from the Vite public directory, or stop the build from emitting them.');
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Refuse output that Wrangler would decline to upload as a Cloudflare Pages worker script.
|
|
70
|
+
*
|
|
71
|
+
* Wrangler tests the relative path with a plain `startsWith`, not through its case-insensitive upload
|
|
72
|
+
* filter, so the match here is a case-sensitive prefix of the root name too. It covers a `_worker.js`
|
|
73
|
+
* file or directory and siblings such as `_worker.js.map`, which Wrangler refuses alike, while both
|
|
74
|
+
* adapters serve `_Worker.js` or a nested `docs/_worker.js` as an ordinary file.
|
|
75
|
+
*/
|
|
76
|
+
function refusePagesWorker(files) {
|
|
77
|
+
const workers = new Set(files
|
|
78
|
+
.map((file) => file.path.split('/')[0])
|
|
79
|
+
.filter((name) => name.startsWith(PAGES_WORKER_NAME)));
|
|
80
|
+
if (workers.size === 0)
|
|
81
|
+
return;
|
|
82
|
+
const names = [...workers].join(', ');
|
|
83
|
+
throw new TypeError(`Frontend output contains Cloudflare Pages worker name(s) at its root: ${names}. ` +
|
|
84
|
+
`A direct cloudflare() deployment would fail because Wrangler refuses to upload a root name starting with ${PAGES_WORKER_NAME} as possible server-side code, while a managed astrale() deployment would serve them as public files. ` +
|
|
85
|
+
'The Worker is the only server-side code for both adapters: remove or rename them in the Vite public directory, or stop the build from emitting them.');
|
|
86
|
+
}
|
|
87
|
+
async function readFiles(root, current = '') {
|
|
88
|
+
const entries = await readdir(join(root, current), { withFileTypes: true });
|
|
89
|
+
const files = [];
|
|
90
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
91
|
+
const path = current === '' ? entry.name : `${current}/${entry.name}`;
|
|
92
|
+
if (entry.isDirectory())
|
|
93
|
+
files.push(...(await readFiles(root, path)));
|
|
94
|
+
else if (entry.isFile()) {
|
|
95
|
+
files.push({ path, content: new Uint8Array(await readFile(join(root, path))) });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return files;
|
|
99
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Release } from '@astrale-os/sdk/deployment/release';
|
|
2
|
+
import type { verifyReadiness } from '@astrale-os/sdk/deployment/verify';
|
|
3
|
+
type ReadinessFetch = NonNullable<NonNullable<Parameters<typeof verifyReadiness>[1]>['fetch']>;
|
|
4
|
+
/** Release equality alone cannot prove a frontend-only deployment has propagated. */
|
|
5
|
+
export declare function verifyWorkerFrontend(release: Release, worker: {
|
|
6
|
+
readonly assets?: {
|
|
7
|
+
readonly files: readonly {
|
|
8
|
+
readonly path: string;
|
|
9
|
+
bytes(): Uint8Array;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
}, options?: {
|
|
13
|
+
readonly fetch?: ReadinessFetch;
|
|
14
|
+
readonly signal?: AbortSignal;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { frontendRevision } from './revision.js';
|
|
2
|
+
/** Release equality alone cannot prove a frontend-only deployment has propagated. */
|
|
3
|
+
export async function verifyWorkerFrontend(release, worker, options = {}) {
|
|
4
|
+
const frontend = release.build.frontend;
|
|
5
|
+
if (frontend === undefined || frontend.source.kind === 'external')
|
|
6
|
+
return;
|
|
7
|
+
if (worker.assets === undefined)
|
|
8
|
+
throw new Error('Prepared Worker frontend assets are missing.');
|
|
9
|
+
const expected = frontendRevision(worker.assets.files);
|
|
10
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
11
|
+
for (const route of frontend.routes) {
|
|
12
|
+
const response = await fetcher(new URL(route.path, release.url).href, {
|
|
13
|
+
redirect: 'error',
|
|
14
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
15
|
+
});
|
|
16
|
+
const matches = response.status === 200 && response.headers.get('X-Astrale-Frontend') === expected;
|
|
17
|
+
await response.body?.cancel();
|
|
18
|
+
if (!matches)
|
|
19
|
+
throw new Error(`Frontend ${route.path} is not serving the prepared browser build yet.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
/** Bind the generated Worker to its exact browser files, independently of Schema revision. */
|
|
3
|
+
export function frontendRevision(files) {
|
|
4
|
+
const hash = createHash('sha256');
|
|
5
|
+
const ordered = files
|
|
6
|
+
.map((file) => ({ path: file.path.replace(/^\//u, ''), bytes: file.bytes }))
|
|
7
|
+
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
8
|
+
for (const file of ordered) {
|
|
9
|
+
const bytes = file.bytes();
|
|
10
|
+
hash.update(JSON.stringify([file.path, bytes.byteLength]));
|
|
11
|
+
hash.update(bytes);
|
|
12
|
+
}
|
|
13
|
+
return `sha256:${hash.digest('hex')}`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a Vite frontend in an isolated process and report its authored inputs, along with the
|
|
3
|
+
* outputs the bundler content-addressed. Those are the files a browser may keep forever, and only
|
|
4
|
+
* the build that named them can say which they are.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildViteFrontend(input: {
|
|
7
|
+
readonly projectDir: string;
|
|
8
|
+
readonly output: string;
|
|
9
|
+
readonly config?: string;
|
|
10
|
+
readonly recordSource?: (path: string) => void;
|
|
11
|
+
readonly signal: AbortSignal;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
readonly addressed: readonly string[];
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { runViteProcess } from './vite.process.js';
|
|
6
|
+
/**
|
|
7
|
+
* Build a Vite frontend in an isolated process and report its authored inputs, along with the
|
|
8
|
+
* outputs the bundler content-addressed. Those are the files a browser may keep forever, and only
|
|
9
|
+
* the build that named them can say which they are.
|
|
10
|
+
*/
|
|
11
|
+
export async function buildViteFrontend(input) {
|
|
12
|
+
const parent = dirname(input.output);
|
|
13
|
+
await mkdir(parent, { recursive: true });
|
|
14
|
+
const scratch = await mkdtemp(join(parent, 'vite-run-'));
|
|
15
|
+
const evidence = join(scratch, 'sources.json');
|
|
16
|
+
const addressed = join(scratch, 'addressed.json');
|
|
17
|
+
try {
|
|
18
|
+
await runViteProcess({
|
|
19
|
+
cwd: input.projectDir,
|
|
20
|
+
arguments: [runnerPath(), input.output, evidence, input.config ?? '', addressed],
|
|
21
|
+
signal: input.signal,
|
|
22
|
+
});
|
|
23
|
+
const sources = JSON.parse(await readFile(evidence, 'utf8'));
|
|
24
|
+
if (!Array.isArray(sources) || sources.some((path) => typeof path !== 'string')) {
|
|
25
|
+
throw new TypeError('Vite preparation source evidence is invalid.');
|
|
26
|
+
}
|
|
27
|
+
for (const path of sources)
|
|
28
|
+
input.recordSource?.(path);
|
|
29
|
+
const named = JSON.parse(await readFile(addressed, 'utf8'));
|
|
30
|
+
if (!Array.isArray(named) || named.some((path) => typeof path !== 'string')) {
|
|
31
|
+
throw new TypeError('Vite preparation output evidence is invalid.');
|
|
32
|
+
}
|
|
33
|
+
return { addressed: Object.freeze([...named]) };
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await rm(scratch, { recursive: true, force: true });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function runnerPath() {
|
|
40
|
+
const built = fileURLToPath(new URL('./vite.runner.js', import.meta.url));
|
|
41
|
+
return existsSync(built) ? built : fileURLToPath(new URL('./vite.runner.ts', import.meta.url));
|
|
42
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
const MAXIMUM_OUTPUT_BYTES = 1024 * 1024;
|
|
3
|
+
const TERMINATION_GRACE_MS = 1_000;
|
|
4
|
+
const VITE_TIMEOUT_MS = 300_000;
|
|
5
|
+
/** Run one bounded, cancellable Vite subprocess. */
|
|
6
|
+
export function runViteProcess(input) {
|
|
7
|
+
if (input.signal.aborted)
|
|
8
|
+
return Promise.reject(abortReason(input.signal));
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const child = spawn(process.execPath, input.arguments, {
|
|
11
|
+
cwd: input.cwd,
|
|
12
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
13
|
+
windowsHide: true,
|
|
14
|
+
});
|
|
15
|
+
let output = '';
|
|
16
|
+
let outputBytes = 0;
|
|
17
|
+
let terminating;
|
|
18
|
+
let escalation;
|
|
19
|
+
const timeout = setTimeout(() => terminate(new Error('Vite process timed out.')), input.timeoutMs ?? VITE_TIMEOUT_MS);
|
|
20
|
+
const abort = () => terminate(abortReason(input.signal));
|
|
21
|
+
input.signal.addEventListener('abort', abort, { once: true });
|
|
22
|
+
const cleanup = () => {
|
|
23
|
+
clearTimeout(timeout);
|
|
24
|
+
if (escalation !== undefined)
|
|
25
|
+
clearTimeout(escalation);
|
|
26
|
+
input.signal.removeEventListener('abort', abort);
|
|
27
|
+
};
|
|
28
|
+
function terminate(cause) {
|
|
29
|
+
if (terminating !== undefined)
|
|
30
|
+
return;
|
|
31
|
+
terminating = cause;
|
|
32
|
+
child.kill('SIGTERM');
|
|
33
|
+
escalation = setTimeout(() => {
|
|
34
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
35
|
+
child.kill('SIGKILL');
|
|
36
|
+
}, TERMINATION_GRACE_MS);
|
|
37
|
+
}
|
|
38
|
+
const collect = (buffer) => {
|
|
39
|
+
outputBytes += buffer.byteLength;
|
|
40
|
+
if (outputBytes > MAXIMUM_OUTPUT_BYTES) {
|
|
41
|
+
terminate(new Error('Vite process exceeded its output limit.'));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
output += buffer.toString();
|
|
45
|
+
};
|
|
46
|
+
child.stdout.on('data', collect);
|
|
47
|
+
child.stderr.on('data', collect);
|
|
48
|
+
child.once('error', (cause) => {
|
|
49
|
+
cleanup();
|
|
50
|
+
reject(terminating ?? cause);
|
|
51
|
+
});
|
|
52
|
+
child.once('close', (code) => {
|
|
53
|
+
cleanup();
|
|
54
|
+
if (terminating !== undefined)
|
|
55
|
+
reject(terminating);
|
|
56
|
+
else if (code === 0)
|
|
57
|
+
resolve();
|
|
58
|
+
else
|
|
59
|
+
reject(new Error(`Vite failed (code ${code ?? 1}):\n${output.slice(-1500)}`));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function abortReason(signal) {
|
|
64
|
+
return signal.reason instanceof Error ? signal.reason : new Error('Vite process cancelled.');
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { readdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
|
+
const CONFIG_FILES = Object.freeze([
|
|
6
|
+
'vite.config.js',
|
|
7
|
+
'vite.config.mjs',
|
|
8
|
+
'vite.config.ts',
|
|
9
|
+
'vite.config.cjs',
|
|
10
|
+
'vite.config.mts',
|
|
11
|
+
'vite.config.cts',
|
|
12
|
+
]);
|
|
13
|
+
await main();
|
|
14
|
+
async function main() {
|
|
15
|
+
const [output, evidence, configured, addressed] = process.argv.slice(2);
|
|
16
|
+
if (output === undefined || evidence === undefined) {
|
|
17
|
+
throw new TypeError('Vite preparation runner arguments are invalid.');
|
|
18
|
+
}
|
|
19
|
+
const projectDir = process.cwd();
|
|
20
|
+
const vite = await projectVite(projectDir);
|
|
21
|
+
const sources = new Set();
|
|
22
|
+
const named = new Set();
|
|
23
|
+
let publicDir = false;
|
|
24
|
+
let environment = {
|
|
25
|
+
directory: false,
|
|
26
|
+
mode: 'production',
|
|
27
|
+
};
|
|
28
|
+
const config = configured === '' || configured === undefined ? undefined : configured;
|
|
29
|
+
await vite.build({
|
|
30
|
+
logLevel: 'silent',
|
|
31
|
+
...(config === undefined
|
|
32
|
+
? {}
|
|
33
|
+
: { configFile: isAbsolute(config) ? config : resolve(projectDir, config) }),
|
|
34
|
+
build: { outDir: output, emptyOutDir: true },
|
|
35
|
+
plugins: [
|
|
36
|
+
{
|
|
37
|
+
name: 'astrale:preparation-sources',
|
|
38
|
+
configResolved(value) {
|
|
39
|
+
publicDir = value.publicDir;
|
|
40
|
+
environment = { directory: value.envDir, mode: value.mode };
|
|
41
|
+
for (const path of value.configFileDependencies)
|
|
42
|
+
sources.add(path);
|
|
43
|
+
},
|
|
44
|
+
transform(_source, id) {
|
|
45
|
+
const path = physicalModulePath(id);
|
|
46
|
+
if (path !== undefined)
|
|
47
|
+
sources.add(path);
|
|
48
|
+
},
|
|
49
|
+
// The bundler is the only party that knows which outputs it content-addressed: a served path
|
|
50
|
+
// is safe to retain exactly when its name changes with its bytes. Reading that here, from
|
|
51
|
+
// the build that produced them, is what keeps the answer a fact rather than a guess about
|
|
52
|
+
// directory layout or file naming.
|
|
53
|
+
generateBundle(options, bundle) {
|
|
54
|
+
for (const [fileName, entry] of Object.entries(bundle)) {
|
|
55
|
+
if (addressedName(options, entry))
|
|
56
|
+
named.add(fileName);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
for (const path of configCandidates(projectDir, config))
|
|
63
|
+
sources.add(path);
|
|
64
|
+
for (const path of environmentCandidates(environment))
|
|
65
|
+
sources.add(path);
|
|
66
|
+
if (publicDir !== false)
|
|
67
|
+
await collectTree(publicDir, sources);
|
|
68
|
+
await writeFile(evidence, JSON.stringify([...sources]));
|
|
69
|
+
if (addressed !== undefined)
|
|
70
|
+
await writeFile(addressed, JSON.stringify([...named].sort()));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Whether this output's name carries a content hash.
|
|
74
|
+
*
|
|
75
|
+
* Two facts are required, and each is necessary. The output must carry a `name`, which the bundler
|
|
76
|
+
* sets only for the outputs it named itself: a plugin emitting an explicit `fileName` bypasses the
|
|
77
|
+
* template entirely, and such a file can sit anywhere, including beside the bundle's own output. And
|
|
78
|
+
* the template that was applied must embed `[hash]`, since a project is free to strip it.
|
|
79
|
+
*
|
|
80
|
+
* Anything else leaves the answer unknown, and unknown must read as "not content-addressed": losing
|
|
81
|
+
* the optimization costs a revalidation, while claiming it wrongly serves a stale file for as long
|
|
82
|
+
* as the header says, with no way to recall it.
|
|
83
|
+
*/
|
|
84
|
+
function addressedName(options, entry) {
|
|
85
|
+
if (typeof entry.name !== 'string')
|
|
86
|
+
return false;
|
|
87
|
+
const template = entry.type === 'asset'
|
|
88
|
+
? options.assetFileNames
|
|
89
|
+
: entry.isEntry === true
|
|
90
|
+
? options.entryFileNames
|
|
91
|
+
: options.chunkFileNames;
|
|
92
|
+
return typeof template === 'string' && template.includes('[hash]');
|
|
93
|
+
}
|
|
94
|
+
function environmentCandidates(input) {
|
|
95
|
+
const directory = input.directory;
|
|
96
|
+
if (directory === false)
|
|
97
|
+
return [];
|
|
98
|
+
return ['.env', '.env.local', `.env.${input.mode}`, `.env.${input.mode}.local`].map((name) => join(directory, name));
|
|
99
|
+
}
|
|
100
|
+
function physicalModulePath(id) {
|
|
101
|
+
if (id.startsWith('\0'))
|
|
102
|
+
return undefined;
|
|
103
|
+
const path = id.replace(/[?#].*$/u, '');
|
|
104
|
+
if (path.length === 0)
|
|
105
|
+
return undefined;
|
|
106
|
+
if (path.startsWith('file:')) {
|
|
107
|
+
try {
|
|
108
|
+
return fileURLToPath(path);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return isAbsolute(path) ? path : undefined;
|
|
115
|
+
}
|
|
116
|
+
async function projectVite(projectDir) {
|
|
117
|
+
try {
|
|
118
|
+
const manifest = createRequire(join(projectDir, 'package.json')).resolve('vite/package.json');
|
|
119
|
+
const entry = createRequire(manifest).resolve('vite');
|
|
120
|
+
return (await import(pathToFileURL(entry).href));
|
|
121
|
+
}
|
|
122
|
+
catch (cause) {
|
|
123
|
+
throw new TypeError('Vite frontend requires a project-local Vite package.', { cause });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function configCandidates(projectDir, configured) {
|
|
127
|
+
if (configured !== undefined) {
|
|
128
|
+
return [isAbsolute(configured) ? configured : resolve(projectDir, configured)];
|
|
129
|
+
}
|
|
130
|
+
return CONFIG_FILES.map((name) => join(projectDir, name));
|
|
131
|
+
}
|
|
132
|
+
async function collectTree(path, output) {
|
|
133
|
+
output.add(path);
|
|
134
|
+
let entries;
|
|
135
|
+
try {
|
|
136
|
+
entries = await readdir(path, { withFileTypes: true });
|
|
137
|
+
}
|
|
138
|
+
catch (cause) {
|
|
139
|
+
if (errorCode(cause) === 'ENOENT')
|
|
140
|
+
return;
|
|
141
|
+
throw cause;
|
|
142
|
+
}
|
|
143
|
+
for (const entry of entries) {
|
|
144
|
+
const child = join(path, entry.name);
|
|
145
|
+
if (entry.isDirectory())
|
|
146
|
+
await collectTree(child, output);
|
|
147
|
+
else if (entry.isFile())
|
|
148
|
+
output.add(child);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function errorCode(input) {
|
|
152
|
+
return input !== null && typeof input === 'object' && 'code' in input
|
|
153
|
+
? String(Reflect.get(input, 'code'))
|
|
154
|
+
: undefined;
|
|
155
|
+
}
|
package/dist/build/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { generateBuildMaterialModule } from './material.js';
|
|
2
|
+
export { cloudflareWorkerBundler } from './bundler.js';
|
|
3
|
+
export { bundleUpload, type BundleUpload } from './worker/upload.js';
|
|
4
|
+
export { workerBuildManifest, type WorkerUpload } from '../release/build.js';
|
|
5
|
+
export { isAdapterVar, resolveRouter, workerSettings } from './configuration.js';
|
|
6
|
+
export { encodeWorkerSettings, SETTINGS_BINDING } from '../worker/settings.js';
|
|
7
|
+
export { GENERATED_WORKER_RUNTIME } from './codegen/wrangler.js';
|
|
8
|
+
export { frontendFiles } from './frontend/files.js';
|
|
9
|
+
export { verifyWorkerFrontend } from './frontend/readiness.js';
|
|
4
10
|
export { qualifyWorkerBundle } from './qualification.js';
|
|
5
11
|
export { assertSingletonRuntimeRoots } from './roots.js';
|
|
6
|
-
export {
|
|
7
|
-
export { signingIdentitySecrets } from '../identity/secret.js';
|
|
8
|
-
export { runWranglerBundle, runWranglerDeploy, runWranglerDeploymentStatus, runWranglerDev, runWranglerTypes, } from './wrangler-cli.js';
|
|
12
|
+
export { runWranglerBundle, runWranglerTypes } from '../wrangler/index.js';
|
package/dist/build/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { generateBuildMaterialModule } from './material.js';
|
|
2
|
+
export { cloudflareWorkerBundler } from './bundler.js';
|
|
3
|
+
export { bundleUpload } from './worker/upload.js';
|
|
4
|
+
export { workerBuildManifest } from '../release/build.js';
|
|
5
|
+
export { isAdapterVar, resolveRouter, workerSettings } from './configuration.js';
|
|
6
|
+
export { encodeWorkerSettings, SETTINGS_BINDING } from '../worker/settings.js';
|
|
7
|
+
export { GENERATED_WORKER_RUNTIME } from './codegen/wrangler.js';
|
|
8
|
+
export { frontendFiles } from './frontend/files.js';
|
|
9
|
+
export { verifyWorkerFrontend } from './frontend/readiness.js';
|
|
4
10
|
export { qualifyWorkerBundle } from './qualification.js';
|
|
5
11
|
export { assertSingletonRuntimeRoots } from './roots.js';
|
|
6
|
-
export {
|
|
7
|
-
export { signingIdentitySecrets } from '../identity/secret.js';
|
|
8
|
-
export { runWranglerBundle, runWranglerDeploy, runWranglerDeploymentStatus, runWranglerDev, runWranglerTypes, } from './wrangler-cli.js';
|
|
12
|
+
export { runWranglerBundle, runWranglerTypes } from '../wrangler/index.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Build } from '@astrale-os/sdk/deployment/build';
|
|
2
|
+
/**
|
|
3
|
+
* Generate a TypeScript module exporting `loadBuildMaterial()` for a custom Worker entrypoint.
|
|
4
|
+
*
|
|
5
|
+
* The module uses the same verified shared literal as the adapter's generated Service. Its
|
|
6
|
+
* factory allocates the material on demand; `generatedCloudflareWorkerEntry` seals it before use.
|
|
7
|
+
* Write the source at build time and import its factory from the Worker. No authoring or
|
|
8
|
+
* compression dependency is needed by the generated module at runtime.
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateBuildMaterialModule(build: Build): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { generatedMaterial } from '@astrale-os/sdk/deployment/build';
|
|
2
|
+
import { sharedLiteral, verifySharedLiteral } from './worker/codegen/literal.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generate a TypeScript module exporting `loadBuildMaterial()` for a custom Worker entrypoint.
|
|
5
|
+
*
|
|
6
|
+
* The module uses the same verified shared literal as the adapter's generated Service. Its
|
|
7
|
+
* factory allocates the material on demand; `generatedCloudflareWorkerEntry` seals it before use.
|
|
8
|
+
* Write the source at build time and import its factory from the Worker. No authoring or
|
|
9
|
+
* compression dependency is needed by the generated module at runtime.
|
|
10
|
+
*/
|
|
11
|
+
export function generateBuildMaterialModule(build) {
|
|
12
|
+
const generated = generatedMaterial(build);
|
|
13
|
+
const literal = sharedLiteral(generated);
|
|
14
|
+
verifySharedLiteral(literal, generated);
|
|
15
|
+
// An empty shared array otherwise has an implicit any[] type in strict TypeScript consumers.
|
|
16
|
+
const declarations = literal.declarations.map((line) => ` ${line.replace(/ = \[\]$/, ': readonly [] = []')}`);
|
|
17
|
+
return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
|
|
18
|
+
import type { GeneratedBuildMaterial } from '@astrale-os/sdk/deployment/build'
|
|
19
|
+
|
|
20
|
+
export function loadBuildMaterial(): GeneratedBuildMaterial {
|
|
21
|
+
${declarations.join('\n')}
|
|
22
|
+
return ${literal.expression} as unknown as GeneratedBuildMaterial
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BuildMaterial } from '@astrale-os/sdk/deployment/build';
|
|
2
|
+
export interface ExecutionEntryOptions {
|
|
3
|
+
readonly frontSpecifier?: string;
|
|
4
|
+
readonly frontend?: BuildMaterial['frontend'];
|
|
5
|
+
readonly frontendRevision?: string;
|
|
6
|
+
readonly frontendAddressed?: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
/** Generate the isolate-startup entry that realizes the heavy Service on first request. */
|
|
9
|
+
export declare function generateExecutionEntry(serviceSpecifier: string, options?: ExecutionEntryOptions): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Generate the isolate-startup entry that realizes the heavy Service on first request. */
|
|
2
|
+
export function generateExecutionEntry(serviceSpecifier, options = {}) {
|
|
3
|
+
const frontSpecifier = options.frontSpecifier ?? '@astrale-os/adapter-cloudflare/worker/front';
|
|
4
|
+
const configuration = [
|
|
5
|
+
options.frontend === undefined
|
|
6
|
+
? ''
|
|
7
|
+
: ` frontend: ${JSON.stringify(options.frontend)} as const satisfies NonNullable<BuildMaterial['frontend']>,\n`,
|
|
8
|
+
options.frontendRevision === undefined
|
|
9
|
+
? ''
|
|
10
|
+
: ` frontendRevision: ${JSON.stringify(options.frontendRevision)},\n`,
|
|
11
|
+
options.frontendAddressed === undefined
|
|
12
|
+
? ''
|
|
13
|
+
: ` frontendAddressed: ${JSON.stringify(options.frontendAddressed)},\n`,
|
|
14
|
+
].join('');
|
|
15
|
+
// Keep adapter types on the resolved value import: consumers may only depend on adapter-astrale.
|
|
16
|
+
// esbuild subtracts value-import paths from its minifier histogram, but not standalone type
|
|
17
|
+
// imports, so an absolute type-only path would make bundle bytes depend on the checkout.
|
|
18
|
+
return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
|
|
19
|
+
import type { BuildMaterial } from '@astrale-os/sdk/deployment/build'
|
|
20
|
+
|
|
21
|
+
import { cloudflareFrontDoor, type CloudflareAdapterBindings, type CloudflareWorker } from ${JSON.stringify(frontSpecifier)}
|
|
22
|
+
|
|
23
|
+
type WorkerEnv = CloudflareEnv & CloudflareAdapterBindings
|
|
24
|
+
|
|
25
|
+
const SERVICE_SPECIFIER = ${JSON.stringify(serviceSpecifier)}
|
|
26
|
+
let servicePromise: Promise<CloudflareWorker<CloudflareEnv>> | undefined
|
|
27
|
+
|
|
28
|
+
// Admission and public frontend files answer from startup, so a View's document never waits for
|
|
29
|
+
// the execution Service to load. Each such file starts that load for the calls the View makes next.
|
|
30
|
+
const frontDoor = cloudflareFrontDoor<WorkerEnv>({
|
|
31
|
+
${configuration}})
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
async fetch(request: Request, environment: WorkerEnv, context: ExecutionContext) {
|
|
35
|
+
const admission = await frontDoor.admit(request, environment)
|
|
36
|
+
if (admission.kind === 'refused') return admission.response
|
|
37
|
+
if (admission.kind === 'frontend') {
|
|
38
|
+
context.waitUntil(prepare())
|
|
39
|
+
return admission.response
|
|
40
|
+
}
|
|
41
|
+
return (await service()).fetch(request, environment, context)
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function service(): Promise<CloudflareWorker<CloudflareEnv>> {
|
|
46
|
+
return (servicePromise ??= import(SERVICE_SPECIFIER).then((loaded: unknown) => {
|
|
47
|
+
if (loaded === null || typeof loaded !== 'object') invalid()
|
|
48
|
+
const worker = Reflect.get(loaded, 'default') as unknown
|
|
49
|
+
if (worker === null || typeof worker !== 'object' || typeof Reflect.get(worker, 'fetch') !== 'function') invalid()
|
|
50
|
+
return worker as CloudflareWorker<CloudflareEnv>
|
|
51
|
+
}))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function prepare(): Promise<void> {
|
|
55
|
+
// A failure stays memoized by the Service and resurfaces on the request that needs it.
|
|
56
|
+
return service().then((worker) => worker.prepare?.()).then(ignore, ignore)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function ignore(): void {}
|
|
60
|
+
|
|
61
|
+
function invalid(): never {
|
|
62
|
+
throw new TypeError('Cloudflare execution Service module is invalid.')
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emit one JavaScript literal that shares every structurally identical subtree.
|
|
3
|
+
*
|
|
4
|
+
* Build material reaches a Worker as an inline literal, and JSON has no references, so a flat
|
|
5
|
+
* literal repeats every repeated subtree. A compiled Domain is dominated by pattern automata, and
|
|
6
|
+
* a handful of distinct expressions account for dozens of identical copies of one automaton, so
|
|
7
|
+
* the flat form allocates an order of magnitude more objects than the value actually contains.
|
|
8
|
+
*
|
|
9
|
+
* Sharing changes nothing an observer can see. The literal evaluates to a value that serialises
|
|
10
|
+
* identically, so the material digest taken over it is unchanged, and the material is deeply
|
|
11
|
+
* frozen before anything reads it, so no holder can observe the aliasing.
|
|
12
|
+
*/
|
|
13
|
+
export interface SharedLiteral {
|
|
14
|
+
/** `const` declarations for each subtree used more than once, each one after its children. */
|
|
15
|
+
readonly declarations: readonly string[];
|
|
16
|
+
/** The expression for the value itself, referencing those declarations. */
|
|
17
|
+
readonly expression: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function sharedLiteral(value: unknown, prefix?: string): SharedLiteral;
|
|
20
|
+
/**
|
|
21
|
+
* Refuse a literal that does not evaluate back to the value it was built from.
|
|
22
|
+
*
|
|
23
|
+
* Emitting source is the one part of sharing that a type cannot check, so the generator proves its
|
|
24
|
+
* own output instead: a defect becomes a failed build rather than a Worker that boots with the
|
|
25
|
+
* wrong material. The comparison is the serialised form, which is also what the material digest
|
|
26
|
+
* is taken over.
|
|
27
|
+
*/
|
|
28
|
+
export declare function verifySharedLiteral(literal: SharedLiteral, expected: unknown): void;
|