@componentonce/compiler-esbuild 0.1.0-beta.0 → 0.1.0-beta.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/dist/index.js CHANGED
@@ -1,290 +1,3 @@
1
- import { createHash } from "node:crypto";
2
- import { build, } from "esbuild";
3
- /** Stable identifier for the trusted CommonJS bundle contract emitted by this package. */
4
- export const COMPONENTONCE_TRUSTED_BUNDLE_FORMAT = "componentonce.trusted-cjs.v1";
5
- const DEFAULT_SOURCE_FILE_NAME = "componentonce-module.ts";
6
- const DEFAULT_REACT_SOURCE_FILE_NAME = "componentonce-module.tsx";
7
- const DEFAULT_EVALUATED_SOURCE_NAME = "componentonce-trusted-bundle.js";
8
- const REACT_EXTERNALS = ["react", "react/jsx-runtime", "react/jsx-dev-runtime"];
9
- /** Compilation failure with stable, normalized esbuild diagnostics. */
10
- export class ComponentOnceCompileError extends Error {
11
- /** Compiler errors that caused the build to fail. */
12
- diagnostics;
13
- constructor(diagnostics) {
14
- super(formatCompileErrorMessage(diagnostics));
15
- this.name = "ComponentOnceCompileError";
16
- this.diagnostics = Object.freeze([...diagnostics]);
17
- }
18
- }
19
- /** Deterministic error raised when a bundle requests an external the host did not inject. */
20
- export class ComponentOnceMissingExternalError extends Error {
21
- /** Exact module specifier requested by the bundle. */
22
- specifier;
23
- /** Sorted external specifiers supplied by the host. */
24
- availableExternals;
25
- constructor(specifier, availableExternals) {
26
- const sortedExternals = Object.freeze([...availableExternals].sort());
27
- const available = sortedExternals.length === 0 ? "(none)" : sortedExternals.join(", ");
28
- super(`Missing trusted bundle external "${specifier}". Available externals: ${available}.`);
29
- this.name = "ComponentOnceMissingExternalError";
30
- this.specifier = specifier;
31
- this.availableExternals = sortedExternals;
32
- }
33
- }
34
- /** Error raised when loaded bundle content does not match its expected SHA-256 integrity. */
35
- export class ComponentOnceIntegrityError extends Error {
36
- /** Expected subresource-integrity-style SHA-256 value. */
37
- expectedIntegrity;
38
- /** Actual subresource-integrity-style SHA-256 value. */
39
- actualIntegrity;
40
- constructor(expectedIntegrity, actualIntegrity) {
41
- super(`Trusted bundle integrity mismatch. Expected "${expectedIntegrity}" but received "${actualIntegrity}".`);
42
- this.name = "ComponentOnceIntegrityError";
43
- this.expectedIntegrity = expectedIntegrity;
44
- this.actualIntegrity = actualIntegrity;
45
- }
46
- }
47
- /**
48
- * Compile one trusted module into a deterministic CommonJS artifact.
49
- *
50
- * Only caller-declared imports remain external. This generic path does not add React or any other
51
- * runtime implicitly; every external must be injected explicitly by the host at instantiation.
52
- */
53
- export async function compileTrustedModule(input) {
54
- const sourceFileName = input.sourceFileName ?? DEFAULT_SOURCE_FILE_NAME;
55
- const loader = input.loader ?? inferLoader(sourceFileName);
56
- const allowedExternals = normalizeAllowedExternals(input.externalModules ?? []);
57
- try {
58
- const result = await build({
59
- bundle: true,
60
- charset: "utf8",
61
- format: "cjs",
62
- jsx: input.jsx ?? "transform",
63
- legalComments: "none",
64
- logLevel: "silent",
65
- metafile: true,
66
- minify: false,
67
- platform: "neutral",
68
- plugins: [createHostExternalPlugin(allowedExternals)],
69
- sourcemap: "inline",
70
- sourcesContent: true,
71
- stdin: {
72
- contents: input.source,
73
- loader: loader,
74
- sourcefile: sourceFileName,
75
- },
76
- target: "es2022",
77
- treeShaking: true,
78
- write: false,
79
- });
80
- const output = result.outputFiles?.[0];
81
- if (output === undefined || result.metafile === undefined) {
82
- throw new ComponentOnceCompileError([
83
- createInternalDiagnostic("esbuild did not return an in-memory bundle and metafile."),
84
- ]);
85
- }
86
- const code = output.text;
87
- const hashes = hashBundleSource(code);
88
- const metafile = deepFreeze(result.metafile);
89
- const diagnostics = Object.freeze(result.warnings.map((warning) => normalizeMessage("warning", warning)));
90
- const externalModules = Object.freeze(collectExternalModules(metafile));
91
- return Object.freeze({
92
- format: COMPONENTONCE_TRUSTED_BUNDLE_FORMAT,
93
- code,
94
- byteLength: hashes.byteLength,
95
- sha256: hashes.sha256,
96
- integrity: hashes.integrity,
97
- externalModules,
98
- diagnostics,
99
- metafile,
100
- });
101
- }
102
- catch (error) {
103
- if (error instanceof ComponentOnceCompileError)
104
- throw error;
105
- if (isBuildFailure(error)) {
106
- throw new ComponentOnceCompileError(error.errors.map((message) => normalizeMessage("error", message)));
107
- }
108
- throw error;
109
- }
110
- }
111
- /** Compile a trusted React module while keeping the host React singleton external. */
112
- export function compileTrustedReactModule(input) {
113
- return compileTrustedModule({
114
- source: input.source,
115
- sourceFileName: input.sourceFileName ?? DEFAULT_REACT_SOURCE_FILE_NAME,
116
- ...(input.loader === undefined ? {} : { loader: input.loader }),
117
- externalModules: [
118
- ...REACT_EXTERNALS,
119
- ...(input.additionalExternalModules ?? []),
120
- ],
121
- jsx: "automatic",
122
- });
123
- }
124
- /** Calculate a subresource-integrity-style SHA-256 value for bundle text or UTF-8 bytes. */
125
- export function calculateTrustedBundleIntegrity(source) {
126
- return hashBundleSource(source).integrity;
127
- }
128
- /** Throw when bundle text or bytes do not match an expected SHA-256 integrity value. */
129
- export function assertTrustedBundleIntegrity(source, expectedIntegrity) {
130
- const actualIntegrity = calculateTrustedBundleIntegrity(source);
131
- if (actualIntegrity !== expectedIntegrity) {
132
- throw new ComponentOnceIntegrityError(expectedIntegrity, actualIntegrity);
133
- }
134
- }
135
- /**
136
- * Execute a trusted bundle with a deliberately narrow CommonJS environment.
137
- *
138
- * This API uses `new Function` and is only for trusted internal code. It is not a sandbox: evaluated
139
- * code retains access to JavaScript globals. The only available `require` values are provided by
140
- * `options.externals`, so React is always the exact instance selected by the host.
141
- */
142
- export function instantiateTrustedBundle(source, options) {
143
- const artifact = isBundleArtifact(source) ? source : undefined;
144
- if (artifact !== undefined && artifact.format !== COMPONENTONCE_TRUSTED_BUNDLE_FORMAT) {
145
- throw new TypeError(`Unsupported trusted bundle format: "${String(artifact.format)}".`);
146
- }
147
- const bundleSource = artifact === undefined ? source : artifact.code;
148
- const expectedIntegrity = options.expectedIntegrity ?? artifact?.integrity;
149
- if (expectedIntegrity !== undefined) {
150
- assertTrustedBundleIntegrity(bundleSource, expectedIntegrity);
151
- }
152
- const code = typeof bundleSource === "string" ? bundleSource : decodeUtf8(bundleSource);
153
- const availableExternals = Object.keys(options.externals).sort();
154
- const trustedRequire = (specifier) => {
155
- if (!Object.prototype.hasOwnProperty.call(options.externals, specifier)) {
156
- throw new ComponentOnceMissingExternalError(specifier, availableExternals);
157
- }
158
- return options.externals[specifier];
159
- };
160
- const commonJsModule = { exports: {} };
161
- const sourceName = sanitizeSourceName(options.sourceName ?? DEFAULT_EVALUATED_SOURCE_NAME);
162
- const evaluate = new Function("module", "exports", "require", `"use strict";\n${code}\n//# sourceURL=${sourceName}`);
163
- evaluate(commonJsModule, commonJsModule.exports, trustedRequire);
164
- return commonJsModule.exports;
165
- }
166
- function createHostExternalPlugin(allowedExternals) {
167
- return {
168
- name: "componentonce-host-externals",
169
- setup(buildApi) {
170
- buildApi.onResolve({ filter: /.*/ }, (args) => {
171
- if (allowedExternals.has(args.path)) {
172
- return { external: true, path: args.path };
173
- }
174
- return {
175
- errors: [
176
- {
177
- text: `Import "${args.path}" is not an allowed host external. ` +
178
- "Add its exact specifier to externalModules (or additionalExternalModules for the React helper).",
179
- },
180
- ],
181
- };
182
- });
183
- },
184
- };
185
- }
186
- function normalizeAllowedExternals(additionalExternals) {
187
- const externals = new Set();
188
- for (const specifier of additionalExternals) {
189
- if (specifier.length === 0 ||
190
- specifier !== specifier.trim() ||
191
- specifier.includes("\0") ||
192
- specifier.includes("\n") ||
193
- specifier.includes("\r")) {
194
- throw new ComponentOnceCompileError([
195
- createInternalDiagnostic(`Invalid additional external module specifier: ${JSON.stringify(specifier)}.`),
196
- ]);
197
- }
198
- externals.add(specifier);
199
- }
200
- return externals;
201
- }
202
- function inferLoader(sourceFileName) {
203
- const lowerName = sourceFileName.toLowerCase();
204
- if (lowerName.endsWith(".jsx"))
205
- return "jsx";
206
- if (lowerName.endsWith(".js") || lowerName.endsWith(".mjs") || lowerName.endsWith(".cjs")) {
207
- return "js";
208
- }
209
- if (lowerName.endsWith(".ts") || lowerName.endsWith(".mts") || lowerName.endsWith(".cts")) {
210
- return "ts";
211
- }
212
- return "tsx";
213
- }
214
- function normalizeMessage(kind, message) {
215
- return Object.freeze({
216
- kind,
217
- text: message.text,
218
- ...(message.location === null ? {} : { location: normalizeLocation(message.location) }),
219
- notes: Object.freeze(message.notes.map((note) => Object.freeze({
220
- text: note.text,
221
- ...(note.location === null ? {} : { location: normalizeLocation(note.location) }),
222
- }))),
223
- });
224
- }
225
- function normalizeLocation(location) {
226
- return Object.freeze({
227
- file: location.file,
228
- line: location.line,
229
- column: location.column,
230
- length: location.length,
231
- lineText: location.lineText,
232
- });
233
- }
234
- function createInternalDiagnostic(text) {
235
- return Object.freeze({ kind: "error", text, notes: Object.freeze([]) });
236
- }
237
- function formatCompileErrorMessage(diagnostics) {
238
- const details = diagnostics.map((diagnostic) => {
239
- const location = diagnostic.location;
240
- const prefix = location === undefined
241
- ? diagnostic.kind
242
- : `${location.file}:${location.line}:${location.column + 1}`;
243
- return `${prefix}: ${diagnostic.text}`;
244
- });
245
- return `ComponentOnce compilation failed${details.length === 0 ? "." : `:\n${details.join("\n")}`}`;
246
- }
247
- function isBuildFailure(error) {
248
- return (typeof error === "object" &&
249
- error !== null &&
250
- "errors" in error &&
251
- Array.isArray(error.errors));
252
- }
253
- function collectExternalModules(metafile) {
254
- const modules = new Set();
255
- for (const output of Object.values(metafile.outputs)) {
256
- for (const imported of output.imports) {
257
- if (imported.external)
258
- modules.add(imported.path);
259
- }
260
- }
261
- return [...modules].sort();
262
- }
263
- function hashBundleSource(source) {
264
- const bytes = typeof source === "string" ? Buffer.from(source, "utf8") : source;
265
- const digest = createHash("sha256").update(bytes).digest();
266
- return {
267
- byteLength: bytes.byteLength,
268
- sha256: digest.toString("hex"),
269
- integrity: `sha256-${digest.toString("base64")}`,
270
- };
271
- }
272
- function isBundleArtifact(source) {
273
- return typeof source === "object" && !(source instanceof Uint8Array);
274
- }
275
- function decodeUtf8(source) {
276
- return new TextDecoder("utf-8", { fatal: true }).decode(source);
277
- }
278
- function sanitizeSourceName(sourceName) {
279
- return sourceName.replace(/[\r\n\u2028\u2029]/g, "_");
280
- }
281
- function deepFreeze(value) {
282
- if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
283
- for (const child of Object.values(value)) {
284
- deepFreeze(child);
285
- }
286
- Object.freeze(value);
287
- }
288
- return value;
289
- }
1
+ export * from "./compiler.js";
2
+ export * from "./package.js";
290
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,KAAK,GAMN,MAAM,SAAS,CAAC;AAEjB,0FAA0F;AAC1F,MAAM,CAAC,MAAM,mCAAmC,GAAG,8BAAuC,CAAC;AAE3F,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAC3D,MAAM,8BAA8B,GAAG,0BAA0B,CAAC;AAClE,MAAM,6BAA6B,GAAG,iCAAiC,CAAC;AACxE,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,CAAU,CAAC;AAwFzF,uEAAuE;AACvE,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,qDAAqD;IAC5C,WAAW,CAAqC;IAEzD,YAAY,WAA+C;QACzD,KAAK,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;IACrD,CAAC;CACF;AAqBD,6FAA6F;AAC7F,MAAM,OAAO,iCAAkC,SAAQ,KAAK;IAC1D,sDAAsD;IAC7C,SAAS,CAAS;IAC3B,uDAAuD;IA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CAAC,MAAM,EAAE,CAAC;IAC3D,OAAO;QACL,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC9B,SAAS,EAAE,UAAU,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;KACjD,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CACvB,MAAwC;IAExC,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,YAAY,UAAU,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,UAAU,CAAC,MAAkB;IACpC,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,OAAO,UAAU,CAAC,OAAO,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,UAAU,CAAI,KAAQ;IAC7B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3E,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAgC,CAAC,EAAE,CAAC;YACpE,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,88 @@
1
+ import type { AnyComponentOnceDefinition, ComponentOnceManifest } from "@componentonce/core";
2
+ import { type ComponentOnceCompileInput, type ComponentOnceHostExternals, type ComponentOnceReactCompileInput, type ComponentOnceTrustedBundleArtifact, type InstantiateTrustedBundleOptions } from "./compiler.js";
3
+ /** Stable identifier for a self-describing ComponentOnce package envelope. */
4
+ export declare const COMPONENTONCE_TRUSTED_PACKAGE_FORMAT: "componentonce.trusted-package.v1";
5
+ /** Conventional named export containing a packaged ComponentOnce definition. */
6
+ export declare const COMPONENTONCE_DEFAULT_DEFINITION_EXPORT: "definition";
7
+ /** Persistable package containing inspectable metadata plus one trusted executable bundle. */
8
+ export interface ComponentOnceTrustedPackage {
9
+ /** Package-envelope contract version. */
10
+ readonly format: typeof COMPONENTONCE_TRUSTED_PACKAGE_FORMAT;
11
+ /** Renderer/adapter id such as react or dom; custom adapters may use their own stable id. */
12
+ readonly renderer: string;
13
+ /** Component identity and compatibility metadata readable without executing the bundle. */
14
+ readonly manifest: ComponentOnceManifest;
15
+ /** Named module export containing the ComponentOnce definition. */
16
+ readonly definitionExport: string;
17
+ /** Integrity-protected executable bundle produced by this compiler. */
18
+ readonly bundle: ComponentOnceTrustedBundleArtifact;
19
+ }
20
+ /** Explicit inputs for wrapping an existing trusted bundle in a self-describing package. */
21
+ export interface CreateTrustedComponentPackageInput {
22
+ readonly renderer: string;
23
+ readonly manifest: ComponentOnceManifest;
24
+ readonly bundle: ComponentOnceTrustedBundleArtifact;
25
+ readonly definitionExport?: string;
26
+ }
27
+ /** Generic trusted-definition build that discovers the manifest once at build time. */
28
+ export interface ComponentOnceDefinitionPackageBuildInput extends ComponentOnceCompileInput {
29
+ /** Stable renderer/adapter id recorded in package metadata. */
30
+ readonly renderer: string;
31
+ /** Build-time module values used to evaluate the trusted definition once. */
32
+ readonly externals?: ComponentOnceHostExternals;
33
+ /** Named definition export; defaults to definition. */
34
+ readonly definitionExport?: string;
35
+ }
36
+ /** React package build that keeps React external and discovers metadata once at build time. */
37
+ export interface ComponentOnceReactPackageBuildInput extends ComponentOnceReactCompileInput {
38
+ /** Build-time values including the exact React/JSX runtime used by this build. */
39
+ readonly externals: ComponentOnceHostExternals;
40
+ /** Named definition export; defaults to definition. */
41
+ readonly definitionExport?: string;
42
+ }
43
+ /** Error raised when a high-level package builder cannot find a valid definition export. */
44
+ export declare class ComponentOncePackageDefinitionError extends Error {
45
+ /** Export name that was missing or invalid. */
46
+ readonly definitionExport: string;
47
+ constructor(definitionExport: string);
48
+ }
49
+ /** Error raised when package metadata disagrees with the definition in its executable bundle. */
50
+ export declare class ComponentOncePackageManifestMismatchError extends Error {
51
+ /** Manifest persisted in the package envelope. */
52
+ readonly packaged: ComponentOnceManifest;
53
+ /** Manifest produced by the executable definition. */
54
+ readonly loaded: ComponentOnceManifest;
55
+ constructor(packaged: ComponentOnceManifest, loaded: ComponentOnceManifest);
56
+ }
57
+ /**
58
+ * Wrap an already compiled trusted bundle with metadata catalogs can inspect without executing code.
59
+ *
60
+ * This low-level helper does not evaluate the bundle. High-level builders evaluate trusted source
61
+ * once during build time to discover the exported definition and then persist its manifest here.
62
+ */
63
+ export declare function createTrustedComponentPackage(input: CreateTrustedComponentPackageInput): ComponentOnceTrustedPackage;
64
+ /**
65
+ * Compile a generic trusted definition and emit a self-describing package.
66
+ *
67
+ * The module executes exactly once during trusted build time so its manifest can be captured. Later
68
+ * catalogs can inspect the package metadata without evaluating the executable component.
69
+ */
70
+ export declare function buildTrustedDefinitionPackage(input: ComponentOnceDefinitionPackageBuildInput): Promise<ComponentOnceTrustedPackage>;
71
+ /**
72
+ * Compile a trusted React definition and emit a self-describing package.
73
+ *
74
+ * React and its JSX runtimes remain external in the executable artifact. The supplied build-time
75
+ * externals are only used for the one-time trusted metadata discovery.
76
+ */
77
+ export declare function buildTrustedReactPackage(input: ComponentOnceReactPackageBuildInput): Promise<ComponentOnceTrustedPackage>;
78
+ /** Serialize a trusted package to portable JSON for any host-owned storage adapter. */
79
+ export declare function serializeTrustedComponentPackage(componentPackage: ComponentOnceTrustedPackage, space?: number): string;
80
+ /** Parse a persisted trusted package and verify the executable bundle integrity metadata. */
81
+ export declare function parseTrustedComponentPackage(source: string | Uint8Array): ComponentOnceTrustedPackage;
82
+ /**
83
+ * Instantiate a self-describing package and verify its executable definition still matches metadata.
84
+ *
85
+ * Hosts should use this at the trusted-code boundary after loading a package from storage.
86
+ */
87
+ export declare function instantiateTrustedComponentPackage<TDefinition extends AnyComponentOnceDefinition = AnyComponentOnceDefinition>(componentPackage: ComponentOnceTrustedPackage, options: InstantiateTrustedBundleOptions): TDefinition;
88
+ //# sourceMappingURL=package.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../src/package.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,0BAA0B,EAC1B,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAML,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,8BAA8B,EACnC,KAAK,kCAAkC,EACvC,KAAK,+BAA+B,EACrC,MAAM,eAAe,CAAC;AAEvB,8EAA8E;AAC9E,eAAO,MAAM,oCAAoC,EAAG,kCAA2C,CAAC;AAEhG,gFAAgF;AAChF,eAAO,MAAM,uCAAuC,EAAG,YAAqB,CAAC;AAI7E,8FAA8F;AAC9F,MAAM,WAAW,2BAA2B;IAC1C,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,OAAO,oCAAoC,CAAC;IAC7D,6FAA6F;IAC7F,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2FAA2F;IAC3F,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC,mEAAmE;IACnE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,kCAAkC,CAAC;CACrD;AAED,4FAA4F;AAC5F,MAAM,WAAW,kCAAkC;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC,QAAQ,CAAC,MAA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B,gCAAgC,CAC9C,gBAAgB,EAAE,2BAA2B,EAC7C,KAAK,SAAI,GACR,MAAM,CAER;AAED,6FAA6F;AAC7F,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,MAAM,GAAG,UAAU,GAC1B,2BAA2B,CAwC7B;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAChD,WAAW,SAAS,0BAA0B,GAAG,0BAA0B,EAE3E,gBAAgB,EAAE,2BAA2B,EAC7C,OAAO,EAAE,+BAA+B,GACvC,WAAW,CAab"}
@@ -0,0 +1,229 @@
1
+ import { createHash } from "node:crypto";
2
+ import { COMPONENTONCE_TRUSTED_BUNDLE_FORMAT, assertTrustedBundleIntegrity, compileTrustedModule, compileTrustedReactModule, instantiateTrustedBundle, } from "./compiler.js";
3
+ /** Stable identifier for a self-describing ComponentOnce package envelope. */
4
+ export const COMPONENTONCE_TRUSTED_PACKAGE_FORMAT = "componentonce.trusted-package.v1";
5
+ /** Conventional named export containing a packaged ComponentOnce definition. */
6
+ export const COMPONENTONCE_DEFAULT_DEFINITION_EXPORT = "definition";
7
+ const REACT_EXTERNALS = ["react", "react/jsx-runtime", "react/jsx-dev-runtime"];
8
+ /** Error raised when a high-level package builder cannot find a valid definition export. */
9
+ export class ComponentOncePackageDefinitionError extends Error {
10
+ /** Export name that was missing or invalid. */
11
+ definitionExport;
12
+ constructor(definitionExport) {
13
+ super("Trusted module export \"" +
14
+ definitionExport +
15
+ "\" is not a ComponentOnce definition with a manifest and implementation.");
16
+ this.name = "ComponentOncePackageDefinitionError";
17
+ this.definitionExport = definitionExport;
18
+ }
19
+ }
20
+ /** Error raised when package metadata disagrees with the definition in its executable bundle. */
21
+ export class ComponentOncePackageManifestMismatchError extends Error {
22
+ /** Manifest persisted in the package envelope. */
23
+ packaged;
24
+ /** Manifest produced by the executable definition. */
25
+ loaded;
26
+ constructor(packaged, loaded) {
27
+ super("Packaged manifest \"" +
28
+ packaged.id +
29
+ "\" version \"" +
30
+ packaged.version +
31
+ "\" does not match the loaded definition \"" +
32
+ loaded.id +
33
+ "\" version \"" +
34
+ loaded.version +
35
+ "\".");
36
+ this.name = "ComponentOncePackageManifestMismatchError";
37
+ this.packaged = packaged;
38
+ this.loaded = loaded;
39
+ }
40
+ }
41
+ /**
42
+ * Wrap an already compiled trusted bundle with metadata catalogs can inspect without executing code.
43
+ *
44
+ * This low-level helper does not evaluate the bundle. High-level builders evaluate trusted source
45
+ * once during build time to discover the exported definition and then persist its manifest here.
46
+ */
47
+ export function createTrustedComponentPackage(input) {
48
+ const renderer = requireNonEmptyString(input.renderer, "renderer");
49
+ const definitionExport = requireNonEmptyString(input.definitionExport ?? COMPONENTONCE_DEFAULT_DEFINITION_EXPORT, "definitionExport");
50
+ return deepFreeze({
51
+ format: COMPONENTONCE_TRUSTED_PACKAGE_FORMAT,
52
+ renderer,
53
+ manifest: copyManifest(input.manifest),
54
+ definitionExport,
55
+ bundle: input.bundle,
56
+ });
57
+ }
58
+ /**
59
+ * Compile a generic trusted definition and emit a self-describing package.
60
+ *
61
+ * The module executes exactly once during trusted build time so its manifest can be captured. Later
62
+ * catalogs can inspect the package metadata without evaluating the executable component.
63
+ */
64
+ export async function buildTrustedDefinitionPackage(input) {
65
+ const externals = input.externals ?? {};
66
+ const artifact = await compileTrustedModule({
67
+ source: input.source,
68
+ ...(input.sourceFileName === undefined ? {} : { sourceFileName: input.sourceFileName }),
69
+ ...(input.loader === undefined ? {} : { loader: input.loader }),
70
+ ...(input.resolveDir === undefined ? {} : { resolveDir: input.resolveDir }),
71
+ externalModules: uniqueStrings([
72
+ ...(input.externalModules ?? []),
73
+ ...Object.keys(externals),
74
+ ]),
75
+ ...(input.jsx === undefined ? {} : { jsx: input.jsx }),
76
+ });
77
+ return packageTrustedDefinitionArtifact(artifact, input.renderer, externals, input.definitionExport);
78
+ }
79
+ /**
80
+ * Compile a trusted React definition and emit a self-describing package.
81
+ *
82
+ * React and its JSX runtimes remain external in the executable artifact. The supplied build-time
83
+ * externals are only used for the one-time trusted metadata discovery.
84
+ */
85
+ export async function buildTrustedReactPackage(input) {
86
+ const additionalExternals = Object.keys(input.externals).filter((specifier) => !REACT_EXTERNALS.includes(specifier));
87
+ const artifact = await compileTrustedReactModule({
88
+ source: input.source,
89
+ ...(input.sourceFileName === undefined ? {} : { sourceFileName: input.sourceFileName }),
90
+ ...(input.loader === undefined ? {} : { loader: input.loader }),
91
+ ...(input.resolveDir === undefined ? {} : { resolveDir: input.resolveDir }),
92
+ additionalExternalModules: uniqueStrings([
93
+ ...(input.additionalExternalModules ?? []),
94
+ ...additionalExternals,
95
+ ]),
96
+ });
97
+ return packageTrustedDefinitionArtifact(artifact, "react", input.externals, input.definitionExport);
98
+ }
99
+ /** Serialize a trusted package to portable JSON for any host-owned storage adapter. */
100
+ export function serializeTrustedComponentPackage(componentPackage, space = 2) {
101
+ return JSON.stringify(componentPackage, null, space);
102
+ }
103
+ /** Parse a persisted trusted package and verify the executable bundle integrity metadata. */
104
+ export function parseTrustedComponentPackage(source) {
105
+ const text = typeof source === "string" ? source : decodeUtf8(source);
106
+ const parsed = JSON.parse(text);
107
+ if (!isRecord(parsed) || parsed.format !== COMPONENTONCE_TRUSTED_PACKAGE_FORMAT) {
108
+ throw new TypeError("Unsupported or invalid ComponentOnce package format.");
109
+ }
110
+ if (!isRecord(parsed.bundle) || parsed.bundle.format !== COMPONENTONCE_TRUSTED_BUNDLE_FORMAT) {
111
+ throw new TypeError("ComponentOnce package does not contain a supported trusted bundle.");
112
+ }
113
+ const bundle = parsed.bundle;
114
+ if (typeof bundle.code !== "string" ||
115
+ typeof bundle.integrity !== "string" ||
116
+ typeof bundle.sha256 !== "string" ||
117
+ typeof bundle.byteLength !== "number" ||
118
+ !Array.isArray(bundle.externalModules) ||
119
+ !bundle.externalModules.every((specifier) => typeof specifier === "string")) {
120
+ throw new TypeError("ComponentOnce package bundle metadata is incomplete.");
121
+ }
122
+ assertTrustedBundleIntegrity(bundle.code, bundle.integrity);
123
+ const hashes = hashBundleSource(bundle.code);
124
+ if (hashes.sha256 !== bundle.sha256 || hashes.byteLength !== bundle.byteLength) {
125
+ throw new TypeError("ComponentOnce package bundle hash metadata does not match its code.");
126
+ }
127
+ if (typeof parsed.renderer !== "string" || !isRecord(parsed.manifest)) {
128
+ throw new TypeError("ComponentOnce package renderer or manifest is invalid.");
129
+ }
130
+ return createTrustedComponentPackage({
131
+ renderer: parsed.renderer,
132
+ manifest: parsed.manifest,
133
+ bundle,
134
+ definitionExport: typeof parsed.definitionExport === "string"
135
+ ? parsed.definitionExport
136
+ : COMPONENTONCE_DEFAULT_DEFINITION_EXPORT,
137
+ });
138
+ }
139
+ /**
140
+ * Instantiate a self-describing package and verify its executable definition still matches metadata.
141
+ *
142
+ * Hosts should use this at the trusted-code boundary after loading a package from storage.
143
+ */
144
+ export function instantiateTrustedComponentPackage(componentPackage, options) {
145
+ const moduleExports = instantiateTrustedBundle(componentPackage.bundle, options);
146
+ const definition = readDefinitionExport(moduleExports, componentPackage.definitionExport);
147
+ if (!sameManifest(componentPackage.manifest, definition.manifest)) {
148
+ throw new ComponentOncePackageManifestMismatchError(componentPackage.manifest, definition.manifest);
149
+ }
150
+ return definition;
151
+ }
152
+ function packageTrustedDefinitionArtifact(artifact, renderer, externals, definitionExport = COMPONENTONCE_DEFAULT_DEFINITION_EXPORT) {
153
+ const moduleExports = instantiateTrustedBundle(artifact, { externals });
154
+ const definition = readDefinitionExport(moduleExports, definitionExport);
155
+ return createTrustedComponentPackage({
156
+ renderer,
157
+ manifest: definition.manifest,
158
+ bundle: artifact,
159
+ definitionExport,
160
+ });
161
+ }
162
+ function readDefinitionExport(moduleExports, definitionExport) {
163
+ const value = moduleExports[definitionExport];
164
+ if (!isRecord(value) || !isRecord(value.manifest) || !("implementation" in value)) {
165
+ throw new ComponentOncePackageDefinitionError(definitionExport);
166
+ }
167
+ copyManifest(value.manifest);
168
+ return value;
169
+ }
170
+ function copyManifest(manifest) {
171
+ if (!isRecord(manifest)) {
172
+ throw new TypeError("ComponentOnce manifest must be an object.");
173
+ }
174
+ const id = requireNonEmptyString(manifest.id, "manifest.id");
175
+ const version = requireNonEmptyString(manifest.version, "manifest.version");
176
+ if (manifest.displayName !== undefined && typeof manifest.displayName !== "string") {
177
+ throw new TypeError("manifest.displayName must be a string when supplied.");
178
+ }
179
+ const requirements = manifest.requirements?.map((requirement, index) => {
180
+ if (!isRecord(requirement)) {
181
+ throw new TypeError("manifest.requirements[" + index + "] must be an object.");
182
+ }
183
+ return {
184
+ name: requireNonEmptyString(requirement.name, "manifest.requirements[" + index + "].name"),
185
+ version: requireNonEmptyString(requirement.version, "manifest.requirements[" + index + "].version"),
186
+ };
187
+ });
188
+ return {
189
+ id,
190
+ version,
191
+ ...(manifest.displayName === undefined ? {} : { displayName: manifest.displayName }),
192
+ ...(requirements === undefined ? {} : { requirements }),
193
+ };
194
+ }
195
+ function sameManifest(left, right) {
196
+ return JSON.stringify(copyManifest(left)) === JSON.stringify(copyManifest(right));
197
+ }
198
+ function requireNonEmptyString(value, field) {
199
+ if (typeof value !== "string" || value.trim() === "") {
200
+ throw new TypeError(field + " must be a non-empty string.");
201
+ }
202
+ return value;
203
+ }
204
+ function uniqueStrings(values) {
205
+ return [...new Set(values)];
206
+ }
207
+ function isRecord(value) {
208
+ return typeof value === "object" && value !== null && !Array.isArray(value);
209
+ }
210
+ function decodeUtf8(source) {
211
+ return new TextDecoder("utf-8", { fatal: true }).decode(source);
212
+ }
213
+ function hashBundleSource(source) {
214
+ const bytes = Buffer.from(source, "utf8");
215
+ return {
216
+ byteLength: bytes.byteLength,
217
+ sha256: createHash("sha256").update(bytes).digest("hex"),
218
+ };
219
+ }
220
+ function deepFreeze(value) {
221
+ if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
222
+ for (const child of Object.values(value)) {
223
+ deepFreeze(child);
224
+ }
225
+ Object.freeze(value);
226
+ }
227
+ return value;
228
+ }
229
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package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