@ny4n/chord 0.0.0-stage → 1.0.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.
Files changed (124) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +261 -2
  3. package/dist/api.d.ts +20 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +77 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/bundler.d.ts +6 -0
  8. package/dist/bundler.d.ts.map +1 -0
  9. package/dist/bundler.js +3 -0
  10. package/dist/bundler.js.map +1 -0
  11. package/dist/context/index.d.ts +24 -0
  12. package/dist/context/index.d.ts.map +1 -0
  13. package/dist/context/index.js +97 -0
  14. package/dist/context/index.js.map +1 -0
  15. package/dist/delta/apply-immutable-trusted.d.ts +4 -0
  16. package/dist/delta/apply-immutable-trusted.d.ts.map +1 -0
  17. package/dist/delta/apply-immutable-trusted.js +127 -0
  18. package/dist/delta/apply-immutable-trusted.js.map +1 -0
  19. package/dist/delta/core.d.ts +108 -0
  20. package/dist/delta/core.d.ts.map +1 -0
  21. package/dist/delta/core.js +645 -0
  22. package/dist/delta/core.js.map +1 -0
  23. package/dist/delta/diff.d.ts +5 -0
  24. package/dist/delta/diff.d.ts.map +1 -0
  25. package/dist/delta/diff.js +433 -0
  26. package/dist/delta/diff.js.map +1 -0
  27. package/dist/delta/draft.d.ts +5 -0
  28. package/dist/delta/draft.d.ts.map +1 -0
  29. package/dist/delta/draft.js +2 -0
  30. package/dist/delta/draft.js.map +1 -0
  31. package/dist/delta/index.d.ts +5 -0
  32. package/dist/delta/index.d.ts.map +1 -0
  33. package/dist/delta/index.js +6 -0
  34. package/dist/delta/index.js.map +1 -0
  35. package/dist/delta/revision-validator.d.ts +7 -0
  36. package/dist/delta/revision-validator.d.ts.map +1 -0
  37. package/dist/delta/revision-validator.js +71 -0
  38. package/dist/delta/revision-validator.js.map +1 -0
  39. package/dist/delta/tracker.d.ts +26 -0
  40. package/dist/delta/tracker.d.ts.map +1 -0
  41. package/dist/delta/tracker.js +2069 -0
  42. package/dist/delta/tracker.js.map +1 -0
  43. package/dist/facets/host.d.ts +12 -0
  44. package/dist/facets/host.d.ts.map +1 -0
  45. package/dist/facets/host.js +763 -0
  46. package/dist/facets/host.js.map +1 -0
  47. package/dist/facets/loader.d.ts +3 -0
  48. package/dist/facets/loader.d.ts.map +1 -0
  49. package/dist/facets/loader.js +5 -0
  50. package/dist/facets/loader.js.map +1 -0
  51. package/dist/index.d.ts +12 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +10 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/json.d.ts +10 -0
  56. package/dist/json.d.ts.map +1 -0
  57. package/dist/json.js +124 -0
  58. package/dist/json.js.map +1 -0
  59. package/dist/node/bundle-loader.d.ts +30 -0
  60. package/dist/node/bundle-loader.d.ts.map +1 -0
  61. package/dist/node/bundle-loader.js +377 -0
  62. package/dist/node/bundle-loader.js.map +1 -0
  63. package/dist/node/bundle.d.ts +26 -0
  64. package/dist/node/bundle.d.ts.map +1 -0
  65. package/dist/node/bundle.js +183 -0
  66. package/dist/node/bundle.js.map +1 -0
  67. package/dist/node/manifest.d.ts +36 -0
  68. package/dist/node/manifest.d.ts.map +1 -0
  69. package/dist/node/manifest.js +6 -0
  70. package/dist/node/manifest.js.map +1 -0
  71. package/dist/node/package.d.ts +15 -0
  72. package/dist/node/package.d.ts.map +1 -0
  73. package/dist/node/package.js +199 -0
  74. package/dist/node/package.js.map +1 -0
  75. package/dist/node.d.ts +5 -0
  76. package/dist/node.d.ts.map +1 -0
  77. package/dist/node.js +3 -0
  78. package/dist/node.js.map +1 -0
  79. package/dist/services/consumer.d.ts +11 -0
  80. package/dist/services/consumer.d.ts.map +1 -0
  81. package/dist/services/consumer.js +585 -0
  82. package/dist/services/consumer.js.map +1 -0
  83. package/dist/services/errors.d.ts +8 -0
  84. package/dist/services/errors.d.ts.map +1 -0
  85. package/dist/services/errors.js +22 -0
  86. package/dist/services/errors.js.map +1 -0
  87. package/dist/services/handle.d.ts +15 -0
  88. package/dist/services/handle.d.ts.map +1 -0
  89. package/dist/services/handle.js +101 -0
  90. package/dist/services/handle.js.map +1 -0
  91. package/dist/services/instances.d.ts +26 -0
  92. package/dist/services/instances.d.ts.map +1 -0
  93. package/dist/services/instances.js +140 -0
  94. package/dist/services/instances.js.map +1 -0
  95. package/dist/services/loopback.d.ts +5 -0
  96. package/dist/services/loopback.d.ts.map +1 -0
  97. package/dist/services/loopback.js +15 -0
  98. package/dist/services/loopback.js.map +1 -0
  99. package/dist/services/provider.d.ts +37 -0
  100. package/dist/services/provider.d.ts.map +1 -0
  101. package/dist/services/provider.js +521 -0
  102. package/dist/services/provider.js.map +1 -0
  103. package/dist/services/state-codec.d.ts +15 -0
  104. package/dist/services/state-codec.d.ts.map +1 -0
  105. package/dist/services/state-codec.js +133 -0
  106. package/dist/services/state-codec.js.map +1 -0
  107. package/dist/services/state-internals.d.ts +13 -0
  108. package/dist/services/state-internals.d.ts.map +1 -0
  109. package/dist/services/state-internals.js +10 -0
  110. package/dist/services/state-internals.js.map +1 -0
  111. package/dist/services/state.d.ts +28 -0
  112. package/dist/services/state.d.ts.map +1 -0
  113. package/dist/services/state.js +397 -0
  114. package/dist/services/state.js.map +1 -0
  115. package/dist/services/wire.d.ts +63 -0
  116. package/dist/services/wire.d.ts.map +1 -0
  117. package/dist/services/wire.js +186 -0
  118. package/dist/services/wire.js.map +1 -0
  119. package/dist/types.d.ts +277 -0
  120. package/dist/types.d.ts.map +1 -0
  121. package/dist/types.js +2 -0
  122. package/dist/types.js.map +1 -0
  123. package/package.json +71 -5
  124. package/src/delta/README.md +191 -0
@@ -0,0 +1,377 @@
1
+ import { createHash } from "node:crypto";
2
+ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { createRequire, isBuiltin } from "node:module";
4
+ import { tmpdir } from "node:os";
5
+ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { compileFunction } from "node:vm";
8
+ import { FACET_BUNDLE_ARTIFACT_FORMAT, FACET_BUNDLE_ARTIFACT_FORMAT_VERSION, FACET_BUNDLE_FORMAT, FACET_BUNDLE_FORMAT_VERSION, FACET_BUNDLE_MANIFEST_FILE, } from "./manifest.js";
9
+ /** Read and validate a versioned facet bundle manifest. */
10
+ export async function readFacetBundleManifest(path) {
11
+ const manifestPath = toFilePath(path);
12
+ let parsed;
13
+ try {
14
+ parsed = JSON.parse(await readFile(manifestPath, "utf8"));
15
+ }
16
+ catch (error) {
17
+ throw new Error(`Could not read facet bundle manifest ${manifestPath}`, { cause: error });
18
+ }
19
+ return validateManifest(parsed, manifestPath);
20
+ }
21
+ /** Read and verify one transportable entry from a facet bundle on disk. */
22
+ export async function readFacetBundleArtifact(options) {
23
+ if (options.entry.length === 0)
24
+ throw new TypeError("Facet bundle entry name must not be empty");
25
+ const manifestPath = toFilePath(options.manifestPath);
26
+ const manifest = await readFacetBundleManifest(manifestPath);
27
+ const entry = manifest.entries[options.entry];
28
+ if (entry === undefined)
29
+ throw new Error(`Facet bundle ${manifest.plugin.id} has no entry named ${options.entry}`);
30
+ const modulePath = resolveBundleFile(manifestPath, entry.file, "entry");
31
+ const source = await readFile(modulePath, "utf8");
32
+ verifySource(source, entry);
33
+ const sourceMapContents = entry.sourceMap === undefined
34
+ ? undefined
35
+ : await readFile(resolveBundleFile(manifestPath, entry.sourceMap, "source map"), "utf8");
36
+ return Object.freeze({
37
+ format: FACET_BUNDLE_ARTIFACT_FORMAT,
38
+ formatVersion: FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,
39
+ plugin: manifest.plugin,
40
+ entryName: options.entry,
41
+ entry,
42
+ source,
43
+ ...(sourceMapContents === undefined ? {} : { sourceMapContents }),
44
+ });
45
+ }
46
+ /** Materialize a transported artifact and create a fresh VM-compiled CommonJS generation for each load. */
47
+ export function createFacetBundleArtifactLoader(options) {
48
+ const artifact = validateArtifact(options.artifact);
49
+ const temporaryParent = resolve(options.temporaryDirectory ?? tmpdir());
50
+ return {
51
+ async load() {
52
+ await mkdir(temporaryParent, { recursive: true });
53
+ const directory = await mkdtemp(join(temporaryParent, "chord-facet-"));
54
+ try {
55
+ await materializeArtifact(directory, artifact);
56
+ const loaded = await createFacetBundleLoader({
57
+ manifestPath: join(directory, FACET_BUNDLE_MANIFEST_FILE),
58
+ entry: artifact.entryName,
59
+ resolveExternal: options.resolveExternal,
60
+ }).load();
61
+ let disposed = false;
62
+ return {
63
+ get facets() {
64
+ return loaded.facets;
65
+ },
66
+ async dispose() {
67
+ if (disposed)
68
+ return;
69
+ disposed = true;
70
+ const errors = [];
71
+ try {
72
+ await loaded.dispose();
73
+ }
74
+ catch (error) {
75
+ errors.push(error);
76
+ }
77
+ try {
78
+ await rm(directory, { force: true, recursive: true });
79
+ }
80
+ catch (error) {
81
+ errors.push(error);
82
+ }
83
+ if (errors.length === 1)
84
+ throw errors[0];
85
+ if (errors.length > 1)
86
+ throw new AggregateError(errors, "Failed to dispose facet bundle artifact");
87
+ },
88
+ };
89
+ }
90
+ catch (error) {
91
+ try {
92
+ await rm(directory, { force: true, recursive: true });
93
+ }
94
+ catch (cleanupError) {
95
+ throw new AggregateError([error, cleanupError], "Facet bundle artifact loading and cleanup failed");
96
+ }
97
+ throw error;
98
+ }
99
+ },
100
+ };
101
+ }
102
+ /** Create a reusable loader for one opaque entry in a facet bundle manifest. */
103
+ export function createFacetBundleLoader(options) {
104
+ if (options.entry.length === 0)
105
+ throw new TypeError("Facet bundle entry name must not be empty");
106
+ const manifestPath = toFilePath(options.manifestPath);
107
+ return {
108
+ async load() {
109
+ const manifest = await readFacetBundleManifest(manifestPath);
110
+ const entry = manifest.entries[options.entry];
111
+ if (entry === undefined) {
112
+ throw new Error(`Facet bundle ${manifest.plugin.id} has no entry named ${options.entry}`);
113
+ }
114
+ const modulePath = resolveBundleFile(manifestPath, entry.file, "entry");
115
+ try {
116
+ const source = await readFile(modulePath, "utf8");
117
+ if (options.verifyIntegrity !== false)
118
+ verifySource(source, entry);
119
+ const exported = executeCommonJsModule(source, modulePath, entry.externalImports, options.resolveExternal);
120
+ let facets = facetsFromModule(exported, manifest.plugin.id, options.entry);
121
+ let disposed = false;
122
+ return {
123
+ get facets() {
124
+ return facets;
125
+ },
126
+ async dispose() {
127
+ if (disposed)
128
+ return;
129
+ disposed = true;
130
+ facets = Object.freeze([]);
131
+ },
132
+ };
133
+ }
134
+ catch (error) {
135
+ const detail = error instanceof Error ? `: ${error.message}` : "";
136
+ throw new Error(`Could not load facet bundle entry ${manifest.plugin.id}/${options.entry}${detail}`, {
137
+ cause: error,
138
+ });
139
+ }
140
+ },
141
+ };
142
+ }
143
+ function executeCommonJsModule(source, modulePath, externalImports, resolver) {
144
+ const requireFromModule = createRequire(modulePath);
145
+ const externalTargets = new Map();
146
+ for (const specifier of externalImports) {
147
+ if (!isBuiltin(specifier))
148
+ validatePackageSpecifier(specifier);
149
+ externalTargets.set(specifier, toRequireSpecifier(resolveExternalTarget(specifier, resolver)));
150
+ }
151
+ const targetFor = (specifier) => {
152
+ const target = externalTargets.get(specifier);
153
+ if (target === undefined)
154
+ throw new Error(`Facet bundle required undeclared external import: ${specifier}`);
155
+ return target;
156
+ };
157
+ const requireExternal = Object.assign((specifier) => requireFromModule(targetFor(specifier)), {
158
+ resolve: (specifier) => requireFromModule.resolve(targetFor(specifier)),
159
+ });
160
+ const commonJsModule = { exports: Object.create(null) };
161
+ const compiled = compileFunction(source, ["exports", "require", "module", "__filename", "__dirname"], {
162
+ filename: modulePath,
163
+ });
164
+ Reflect.apply(compiled, commonJsModule.exports, [
165
+ commonJsModule.exports,
166
+ requireExternal,
167
+ commonJsModule,
168
+ modulePath,
169
+ dirname(modulePath),
170
+ ]);
171
+ return commonJsModule.exports;
172
+ }
173
+ function toRequireSpecifier(target) {
174
+ if (isAbsolute(target) || isBuiltin(target))
175
+ return target;
176
+ let url;
177
+ try {
178
+ url = new URL(target);
179
+ }
180
+ catch {
181
+ return target;
182
+ }
183
+ if (url.protocol === "file:")
184
+ return fileURLToPath(url);
185
+ if (url.protocol === "node:")
186
+ return url.href;
187
+ throw new Error(`Facet bundle external target must be a file, package, or built-in module: ${target}`);
188
+ }
189
+ function toFilePath(path) {
190
+ if (typeof path === "string")
191
+ return resolve(path);
192
+ if (path.protocol !== "file:")
193
+ throw new TypeError(`Facet bundle manifest must be a file URL, not ${path.protocol}`);
194
+ return fileURLToPath(path);
195
+ }
196
+ function resolveBundleFile(manifestPath, file, label) {
197
+ if (file.length === 0 || isAbsolute(file) || basename(file) !== file || file === "." || file === "..") {
198
+ throw new Error(`Facet bundle ${label} must be a filename relative to its manifest`);
199
+ }
200
+ return resolve(dirname(manifestPath), file);
201
+ }
202
+ function verifySource(source, entry) {
203
+ const expected = parseIntegrity(entry.integrity);
204
+ const actual = createHash("sha256").update(source, "utf8").digest("base64");
205
+ if (actual !== expected)
206
+ throw new Error(`Facet bundle integrity check failed for ${entry.file}`);
207
+ }
208
+ function parseIntegrity(integrity) {
209
+ const prefix = "sha256-";
210
+ if (!integrity.startsWith(prefix) || integrity.length === prefix.length) {
211
+ throw new Error("Facet bundle entry has an invalid SHA-256 integrity value");
212
+ }
213
+ return integrity.slice(prefix.length);
214
+ }
215
+ function facetsFromModule(imported, pluginId, entryName) {
216
+ if (!isRecord(imported))
217
+ throw new Error(`Facet bundle entry ${pluginId}/${entryName} did not export a module`);
218
+ const exported = imported.default;
219
+ const candidates = Array.isArray(exported) ? exported : [exported];
220
+ if (candidates.length === 0) {
221
+ throw new Error(`Facet bundle entry ${pluginId}/${entryName} exported no facets`);
222
+ }
223
+ const facets = [];
224
+ for (const candidate of candidates) {
225
+ if (!isRecord(candidate) || typeof candidate.id !== "string" || candidate.id.length === 0) {
226
+ throw new Error(`Facet bundle entry ${pluginId}/${entryName} has a facet with an invalid ID`);
227
+ }
228
+ if (typeof candidate.setup !== "function") {
229
+ throw new Error(`Facet bundle entry ${pluginId}/${entryName} facet ${candidate.id} has no setup function`);
230
+ }
231
+ facets.push(candidate);
232
+ }
233
+ const ids = facets.map(({ id }) => id);
234
+ if (new Set(ids).size !== ids.length) {
235
+ throw new Error(`Facet bundle entry ${pluginId}/${entryName} exports duplicate facet IDs`);
236
+ }
237
+ return Object.freeze(facets);
238
+ }
239
+ function validateArtifact(value) {
240
+ if (!isRecord(value) ||
241
+ value.format !== FACET_BUNDLE_ARTIFACT_FORMAT ||
242
+ value.formatVersion !== FACET_BUNDLE_ARTIFACT_FORMAT_VERSION ||
243
+ typeof value.entryName !== "string" ||
244
+ value.entryName.length === 0 ||
245
+ typeof value.source !== "string") {
246
+ throw new Error("Invalid facet bundle artifact");
247
+ }
248
+ const manifest = validateManifest({
249
+ format: FACET_BUNDLE_FORMAT,
250
+ formatVersion: FACET_BUNDLE_FORMAT_VERSION,
251
+ plugin: value.plugin,
252
+ entries: { [value.entryName]: value.entry },
253
+ }, "facet bundle artifact");
254
+ const entry = manifest.entries[value.entryName];
255
+ if (entry.sourceMap === undefined) {
256
+ if (value.sourceMapContents !== undefined) {
257
+ throw new Error("Facet bundle artifact has source map contents without a source map");
258
+ }
259
+ }
260
+ else if (typeof value.sourceMapContents !== "string") {
261
+ throw new Error("Facet bundle artifact is missing its source map contents");
262
+ }
263
+ verifySource(value.source, entry);
264
+ return Object.freeze({
265
+ format: FACET_BUNDLE_ARTIFACT_FORMAT,
266
+ formatVersion: FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,
267
+ plugin: manifest.plugin,
268
+ entryName: value.entryName,
269
+ entry,
270
+ source: value.source,
271
+ ...(value.sourceMapContents === undefined ? {} : { sourceMapContents: value.sourceMapContents }),
272
+ });
273
+ }
274
+ async function materializeArtifact(directory, artifact) {
275
+ const manifest = {
276
+ format: FACET_BUNDLE_FORMAT,
277
+ formatVersion: FACET_BUNDLE_FORMAT_VERSION,
278
+ plugin: artifact.plugin,
279
+ entries: { [artifact.entryName]: artifact.entry },
280
+ };
281
+ await Promise.all([
282
+ writeFile(join(directory, artifact.entry.file), artifact.source, "utf8"),
283
+ writeFile(join(directory, FACET_BUNDLE_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`, "utf8"),
284
+ ...(artifact.entry.sourceMap === undefined
285
+ ? []
286
+ : [writeFile(join(directory, artifact.entry.sourceMap), artifact.sourceMapContents, "utf8")]),
287
+ ]);
288
+ }
289
+ function resolveExternalTarget(specifier, resolver) {
290
+ const resolved = resolver?.(specifier);
291
+ if (resolved !== undefined)
292
+ return typeof resolved === "string" ? resolved : resolved.href;
293
+ const extension = import.meta.url.endsWith(".ts") ? "ts" : "js";
294
+ if (specifier === "@ny4n/chord")
295
+ return new URL(`../index.${extension}`, import.meta.url).href;
296
+ if (specifier === "@ny4n/chord/context") {
297
+ return new URL(`../context/index.${extension}`, import.meta.url).href;
298
+ }
299
+ if (specifier === "@ny4n/chord/node")
300
+ return new URL(`../node.${extension}`, import.meta.url).href;
301
+ return import.meta.resolve(specifier);
302
+ }
303
+ function validatePackageSpecifier(specifier) {
304
+ const segments = specifier.split("/");
305
+ const packageParts = specifier.startsWith("@") ? 2 : 1;
306
+ if (specifier.startsWith(".") ||
307
+ specifier.startsWith("/") ||
308
+ specifier.startsWith("#") ||
309
+ specifier.includes(":") ||
310
+ specifier.includes("\\") ||
311
+ segments.length < packageParts ||
312
+ segments.some((part) => part.length === 0 || part === "." || part === "..")) {
313
+ throw new Error(`Facet bundle artifact has an unsupported external import: ${specifier}`);
314
+ }
315
+ }
316
+ function validateManifest(value, path) {
317
+ if (!isRecord(value) || value.format !== FACET_BUNDLE_FORMAT) {
318
+ throw new Error(`Invalid facet bundle manifest format in ${path}`);
319
+ }
320
+ if (value.formatVersion !== FACET_BUNDLE_FORMAT_VERSION) {
321
+ throw new Error(`Unsupported facet bundle manifest version in ${path}: ${String(value.formatVersion)}`);
322
+ }
323
+ if (!isRecord(value.plugin) || typeof value.plugin.id !== "string" || value.plugin.id.length === 0) {
324
+ throw new Error(`Facet bundle manifest has an invalid plugin identity in ${path}`);
325
+ }
326
+ if (value.plugin.version !== undefined &&
327
+ (typeof value.plugin.version !== "string" || value.plugin.version.length === 0)) {
328
+ throw new Error(`Facet bundle manifest has an invalid plugin version in ${path}`);
329
+ }
330
+ if (!isRecord(value.entries) || Object.keys(value.entries).length === 0) {
331
+ throw new Error(`Facet bundle manifest has no entries in ${path}`);
332
+ }
333
+ const entries = {};
334
+ for (const [name, candidate] of Object.entries(value.entries)) {
335
+ if (name.length === 0 || !isRecord(candidate)) {
336
+ throw new Error(`Facet bundle manifest has an invalid entry in ${path}`);
337
+ }
338
+ if (typeof candidate.file !== "string")
339
+ throw new Error(`Facet bundle entry ${name} has no file`);
340
+ resolveBundleFile(path, candidate.file, `entry ${name}`);
341
+ if (typeof candidate.integrity !== "string")
342
+ throw new Error(`Facet bundle entry ${name} has no integrity`);
343
+ parseIntegrity(candidate.integrity);
344
+ if (!Array.isArray(candidate.externalImports) ||
345
+ candidate.externalImports.some((item) => typeof item !== "string")) {
346
+ throw new Error(`Facet bundle entry ${name} has invalid external imports`);
347
+ }
348
+ const externalImports = Object.freeze([...candidate.externalImports]);
349
+ if (new Set(externalImports).size !== externalImports.length) {
350
+ throw new Error(`Facet bundle entry ${name} has duplicate external imports`);
351
+ }
352
+ if (candidate.sourceMap !== undefined) {
353
+ if (typeof candidate.sourceMap !== "string")
354
+ throw new Error(`Facet bundle entry ${name} has an invalid source map`);
355
+ resolveBundleFile(path, candidate.sourceMap, `entry ${name} source map`);
356
+ }
357
+ entries[name] = Object.freeze({
358
+ file: candidate.file,
359
+ integrity: candidate.integrity,
360
+ externalImports,
361
+ ...(candidate.sourceMap === undefined ? {} : { sourceMap: candidate.sourceMap }),
362
+ });
363
+ }
364
+ return Object.freeze({
365
+ format: FACET_BUNDLE_FORMAT,
366
+ formatVersion: FACET_BUNDLE_FORMAT_VERSION,
367
+ plugin: Object.freeze({
368
+ id: value.plugin.id,
369
+ ...(value.plugin.version === undefined ? {} : { version: value.plugin.version }),
370
+ }),
371
+ entries: Object.freeze(entries),
372
+ });
373
+ }
374
+ function isRecord(value) {
375
+ return typeof value === "object" && value !== null && !Array.isArray(value);
376
+ }
377
+ //# sourceMappingURL=bundle-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle-loader.js","sourceRoot":"","sources":["../../src/node/bundle-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,OAAO,EACN,4BAA4B,EAC5B,oCAAoC,EACpC,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,GAI1B,MAAM,eAAe,CAAC;AAyBvB,2DAA2D;AAC3D,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,IAAkB;IAC/D,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACJ,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wCAAwC,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO,gBAAgB,CAA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C,IAAI,OAAO,SAAS,CAAC,SAAS,KAAK,QAAQ;gBAC1C,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,4BAA4B,CAAC,CAAC;YACzE,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,IAAI,aAAa,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;YAC7B,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,eAAe;YACf,GAAG,CAAC,SAAS,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC;SAChF,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,mBAAmB;QAC3B,aAAa,EAAE,2BAA2B;QAC1C,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACrB,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE;YACnB,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAChF,CAAC;QACF,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;KAC/B,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdir, mkdtemp, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { createRequire, isBuiltin } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { basename, dirname, isAbsolute, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { compileFunction } from \"node:vm\";\nimport type { Facet, FacetLoader, LoadedFacets } from \"../types.ts\";\nimport {\n\tFACET_BUNDLE_ARTIFACT_FORMAT,\n\tFACET_BUNDLE_ARTIFACT_FORMAT_VERSION,\n\tFACET_BUNDLE_FORMAT,\n\tFACET_BUNDLE_FORMAT_VERSION,\n\tFACET_BUNDLE_MANIFEST_FILE,\n\ttype FacetBundleArtifact,\n\ttype FacetBundleEntry,\n\ttype FacetBundleManifest,\n} from \"./manifest.ts\";\n\nexport type FacetBundleExternalResolver = (specifier: string) => string | URL | undefined;\n\nexport interface FacetBundleLoaderOptions {\n\treadonly manifestPath: string | URL;\n\treadonly entry: string;\n\t/** Verify the entry's SHA-256 integrity before evaluating it. Defaults to true. */\n\treadonly verifyIntegrity?: boolean;\n\t/** Resolve host-provided external imports when the bundle is outside the host's package tree. */\n\treadonly resolveExternal?: FacetBundleExternalResolver;\n}\n\nexport interface FacetBundleArtifactLoaderOptions {\n\treadonly artifact: unknown;\n\t/** Resolve host-provided external imports against the receiving application. */\n\treadonly resolveExternal?: FacetBundleExternalResolver;\n\t/** Parent directory for materialized module generations. Defaults to the operating system temp directory. */\n\treadonly temporaryDirectory?: string;\n}\n\ninterface CommonJsModule {\n\texports: unknown;\n}\n\n/** Read and validate a versioned facet bundle manifest. */\nexport async function readFacetBundleManifest(path: string | URL): Promise<FacetBundleManifest> {\n\tconst manifestPath = toFilePath(path);\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\t} catch (error) {\n\t\tthrow new Error(`Could not read facet bundle manifest ${manifestPath}`, { cause: error });\n\t}\n\treturn validateManifest(parsed, manifestPath);\n}\n\n/** Read and verify one transportable entry from a facet bundle on disk. */\nexport async function readFacetBundleArtifact(options: {\n\treadonly manifestPath: string | URL;\n\treadonly entry: string;\n}): Promise<FacetBundleArtifact> {\n\tif (options.entry.length === 0) throw new TypeError(\"Facet bundle entry name must not be empty\");\n\tconst manifestPath = toFilePath(options.manifestPath);\n\tconst manifest = await readFacetBundleManifest(manifestPath);\n\tconst entry = manifest.entries[options.entry];\n\tif (entry === undefined) throw new Error(`Facet bundle ${manifest.plugin.id} has no entry named ${options.entry}`);\n\tconst modulePath = resolveBundleFile(manifestPath, entry.file, \"entry\");\n\tconst source = await readFile(modulePath, \"utf8\");\n\tverifySource(source, entry);\n\tconst sourceMapContents =\n\t\tentry.sourceMap === undefined\n\t\t\t? undefined\n\t\t\t: await readFile(resolveBundleFile(manifestPath, entry.sourceMap, \"source map\"), \"utf8\");\n\treturn Object.freeze({\n\t\tformat: FACET_BUNDLE_ARTIFACT_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,\n\t\tplugin: manifest.plugin,\n\t\tentryName: options.entry,\n\t\tentry,\n\t\tsource,\n\t\t...(sourceMapContents === undefined ? {} : { sourceMapContents }),\n\t});\n}\n\n/** Materialize a transported artifact and create a fresh VM-compiled CommonJS generation for each load. */\nexport function createFacetBundleArtifactLoader(options: FacetBundleArtifactLoaderOptions): FacetLoader {\n\tconst artifact = validateArtifact(options.artifact);\n\tconst temporaryParent = resolve(options.temporaryDirectory ?? tmpdir());\n\treturn {\n\t\tasync load(): Promise<LoadedFacets> {\n\t\t\tawait mkdir(temporaryParent, { recursive: true });\n\t\t\tconst directory = await mkdtemp(join(temporaryParent, \"chord-facet-\"));\n\t\t\ttry {\n\t\t\t\tawait materializeArtifact(directory, artifact);\n\t\t\t\tconst loaded = await createFacetBundleLoader({\n\t\t\t\t\tmanifestPath: join(directory, FACET_BUNDLE_MANIFEST_FILE),\n\t\t\t\t\tentry: artifact.entryName,\n\t\t\t\t\tresolveExternal: options.resolveExternal,\n\t\t\t\t}).load();\n\t\t\t\tlet disposed = false;\n\t\t\t\treturn {\n\t\t\t\t\tget facets() {\n\t\t\t\t\t\treturn loaded.facets;\n\t\t\t\t\t},\n\t\t\t\t\tasync dispose() {\n\t\t\t\t\t\tif (disposed) return;\n\t\t\t\t\t\tdisposed = true;\n\t\t\t\t\t\tconst errors: unknown[] = [];\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait loaded.dispose();\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\terrors.push(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait rm(directory, { force: true, recursive: true });\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\terrors.push(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (errors.length === 1) throw errors[0];\n\t\t\t\t\t\tif (errors.length > 1) throw new AggregateError(errors, \"Failed to dispose facet bundle artifact\");\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait rm(directory, { force: true, recursive: true });\n\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\tthrow new AggregateError([error, cleanupError], \"Facet bundle artifact loading and cleanup failed\");\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t};\n}\n\n/** Create a reusable loader for one opaque entry in a facet bundle manifest. */\nexport function createFacetBundleLoader(options: FacetBundleLoaderOptions): FacetLoader {\n\tif (options.entry.length === 0) throw new TypeError(\"Facet bundle entry name must not be empty\");\n\tconst manifestPath = toFilePath(options.manifestPath);\n\treturn {\n\t\tasync load(): Promise<LoadedFacets> {\n\t\t\tconst manifest = await readFacetBundleManifest(manifestPath);\n\t\t\tconst entry = manifest.entries[options.entry];\n\t\t\tif (entry === undefined) {\n\t\t\t\tthrow new Error(`Facet bundle ${manifest.plugin.id} has no entry named ${options.entry}`);\n\t\t\t}\n\t\t\tconst modulePath = resolveBundleFile(manifestPath, entry.file, \"entry\");\n\t\t\ttry {\n\t\t\t\tconst source = await readFile(modulePath, \"utf8\");\n\t\t\t\tif (options.verifyIntegrity !== false) verifySource(source, entry);\n\t\t\t\tconst exported = executeCommonJsModule(source, modulePath, entry.externalImports, options.resolveExternal);\n\t\t\t\tlet facets = facetsFromModule(exported, manifest.plugin.id, options.entry);\n\t\t\t\tlet disposed = false;\n\t\t\t\treturn {\n\t\t\t\t\tget facets() {\n\t\t\t\t\t\treturn facets;\n\t\t\t\t\t},\n\t\t\t\t\tasync dispose() {\n\t\t\t\t\t\tif (disposed) return;\n\t\t\t\t\t\tdisposed = true;\n\t\t\t\t\t\tfacets = Object.freeze([]);\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tconst detail = error instanceof Error ? `: ${error.message}` : \"\";\n\t\t\t\tthrow new Error(`Could not load facet bundle entry ${manifest.plugin.id}/${options.entry}${detail}`, {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n\nfunction executeCommonJsModule(\n\tsource: string,\n\tmodulePath: string,\n\texternalImports: readonly string[],\n\tresolver?: FacetBundleExternalResolver,\n): unknown {\n\tconst requireFromModule = createRequire(modulePath);\n\tconst externalTargets = new Map<string, string>();\n\tfor (const specifier of externalImports) {\n\t\tif (!isBuiltin(specifier)) validatePackageSpecifier(specifier);\n\t\texternalTargets.set(specifier, toRequireSpecifier(resolveExternalTarget(specifier, resolver)));\n\t}\n\tconst targetFor = (specifier: string): string => {\n\t\tconst target = externalTargets.get(specifier);\n\t\tif (target === undefined) throw new Error(`Facet bundle required undeclared external import: ${specifier}`);\n\t\treturn target;\n\t};\n\tconst requireExternal = Object.assign((specifier: string): unknown => requireFromModule(targetFor(specifier)), {\n\t\tresolve: (specifier: string): string => requireFromModule.resolve(targetFor(specifier)),\n\t});\n\tconst commonJsModule: CommonJsModule = { exports: Object.create(null) };\n\tconst compiled = compileFunction(source, [\"exports\", \"require\", \"module\", \"__filename\", \"__dirname\"], {\n\t\tfilename: modulePath,\n\t});\n\tReflect.apply(compiled, commonJsModule.exports, [\n\t\tcommonJsModule.exports,\n\t\trequireExternal,\n\t\tcommonJsModule,\n\t\tmodulePath,\n\t\tdirname(modulePath),\n\t]);\n\treturn commonJsModule.exports;\n}\n\nfunction toRequireSpecifier(target: string): string {\n\tif (isAbsolute(target) || isBuiltin(target)) return target;\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(target);\n\t} catch {\n\t\treturn target;\n\t}\n\tif (url.protocol === \"file:\") return fileURLToPath(url);\n\tif (url.protocol === \"node:\") return url.href;\n\tthrow new Error(`Facet bundle external target must be a file, package, or built-in module: ${target}`);\n}\n\nfunction toFilePath(path: string | URL): string {\n\tif (typeof path === \"string\") return resolve(path);\n\tif (path.protocol !== \"file:\") throw new TypeError(`Facet bundle manifest must be a file URL, not ${path.protocol}`);\n\treturn fileURLToPath(path);\n}\n\nfunction resolveBundleFile(manifestPath: string, file: string, label: string): string {\n\tif (file.length === 0 || isAbsolute(file) || basename(file) !== file || file === \".\" || file === \"..\") {\n\t\tthrow new Error(`Facet bundle ${label} must be a filename relative to its manifest`);\n\t}\n\treturn resolve(dirname(manifestPath), file);\n}\n\nfunction verifySource(source: string, entry: FacetBundleEntry): void {\n\tconst expected = parseIntegrity(entry.integrity);\n\tconst actual = createHash(\"sha256\").update(source, \"utf8\").digest(\"base64\");\n\tif (actual !== expected) throw new Error(`Facet bundle integrity check failed for ${entry.file}`);\n}\n\nfunction parseIntegrity(integrity: string): string {\n\tconst prefix = \"sha256-\";\n\tif (!integrity.startsWith(prefix) || integrity.length === prefix.length) {\n\t\tthrow new Error(\"Facet bundle entry has an invalid SHA-256 integrity value\");\n\t}\n\treturn integrity.slice(prefix.length);\n}\n\nfunction facetsFromModule(imported: unknown, pluginId: string, entryName: string): readonly Facet[] {\n\tif (!isRecord(imported)) throw new Error(`Facet bundle entry ${pluginId}/${entryName} did not export a module`);\n\tconst exported = imported.default;\n\tconst candidates: readonly unknown[] = Array.isArray(exported) ? (exported as readonly unknown[]) : [exported];\n\tif (candidates.length === 0) {\n\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} exported no facets`);\n\t}\n\tconst facets: Facet[] = [];\n\tfor (const candidate of candidates) {\n\t\tif (!isRecord(candidate) || typeof candidate.id !== \"string\" || candidate.id.length === 0) {\n\t\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} has a facet with an invalid ID`);\n\t\t}\n\t\tif (typeof candidate.setup !== \"function\") {\n\t\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} facet ${candidate.id} has no setup function`);\n\t\t}\n\t\tfacets.push(candidate as unknown as Facet);\n\t}\n\tconst ids = facets.map(({ id }) => id);\n\tif (new Set(ids).size !== ids.length) {\n\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} exports duplicate facet IDs`);\n\t}\n\treturn Object.freeze(facets);\n}\n\nfunction validateArtifact(value: unknown): FacetBundleArtifact {\n\tif (\n\t\t!isRecord(value) ||\n\t\tvalue.format !== FACET_BUNDLE_ARTIFACT_FORMAT ||\n\t\tvalue.formatVersion !== FACET_BUNDLE_ARTIFACT_FORMAT_VERSION ||\n\t\ttypeof value.entryName !== \"string\" ||\n\t\tvalue.entryName.length === 0 ||\n\t\ttypeof value.source !== \"string\"\n\t) {\n\t\tthrow new Error(\"Invalid facet bundle artifact\");\n\t}\n\tconst manifest = validateManifest(\n\t\t{\n\t\t\tformat: FACET_BUNDLE_FORMAT,\n\t\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\t\tplugin: value.plugin,\n\t\t\tentries: { [value.entryName]: value.entry },\n\t\t},\n\t\t\"facet bundle artifact\",\n\t);\n\tconst entry = manifest.entries[value.entryName]!;\n\tif (entry.sourceMap === undefined) {\n\t\tif (value.sourceMapContents !== undefined) {\n\t\t\tthrow new Error(\"Facet bundle artifact has source map contents without a source map\");\n\t\t}\n\t} else if (typeof value.sourceMapContents !== \"string\") {\n\t\tthrow new Error(\"Facet bundle artifact is missing its source map contents\");\n\t}\n\tverifySource(value.source, entry);\n\treturn Object.freeze({\n\t\tformat: FACET_BUNDLE_ARTIFACT_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,\n\t\tplugin: manifest.plugin,\n\t\tentryName: value.entryName,\n\t\tentry,\n\t\tsource: value.source,\n\t\t...(value.sourceMapContents === undefined ? {} : { sourceMapContents: value.sourceMapContents }),\n\t});\n}\n\nasync function materializeArtifact(directory: string, artifact: FacetBundleArtifact): Promise<void> {\n\tconst manifest: FacetBundleManifest = {\n\t\tformat: FACET_BUNDLE_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\tplugin: artifact.plugin,\n\t\tentries: { [artifact.entryName]: artifact.entry },\n\t};\n\tawait Promise.all([\n\t\twriteFile(join(directory, artifact.entry.file), artifact.source, \"utf8\"),\n\t\twriteFile(join(directory, FACET_BUNDLE_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\\n`, \"utf8\"),\n\t\t...(artifact.entry.sourceMap === undefined\n\t\t\t? []\n\t\t\t: [writeFile(join(directory, artifact.entry.sourceMap), artifact.sourceMapContents!, \"utf8\")]),\n\t]);\n}\n\nfunction resolveExternalTarget(specifier: string, resolver?: FacetBundleExternalResolver): string {\n\tconst resolved = resolver?.(specifier);\n\tif (resolved !== undefined) return typeof resolved === \"string\" ? resolved : resolved.href;\n\tconst extension = import.meta.url.endsWith(\".ts\") ? \"ts\" : \"js\";\n\tif (specifier === \"@ny4n/chord\") return new URL(`../index.${extension}`, import.meta.url).href;\n\tif (specifier === \"@ny4n/chord/context\") {\n\t\treturn new URL(`../context/index.${extension}`, import.meta.url).href;\n\t}\n\tif (specifier === \"@ny4n/chord/node\") return new URL(`../node.${extension}`, import.meta.url).href;\n\treturn import.meta.resolve(specifier);\n}\n\nfunction validatePackageSpecifier(specifier: string): void {\n\tconst segments = specifier.split(\"/\");\n\tconst packageParts = specifier.startsWith(\"@\") ? 2 : 1;\n\tif (\n\t\tspecifier.startsWith(\".\") ||\n\t\tspecifier.startsWith(\"/\") ||\n\t\tspecifier.startsWith(\"#\") ||\n\t\tspecifier.includes(\":\") ||\n\t\tspecifier.includes(\"\\\\\") ||\n\t\tsegments.length < packageParts ||\n\t\tsegments.some((part) => part.length === 0 || part === \".\" || part === \"..\")\n\t) {\n\t\tthrow new Error(`Facet bundle artifact has an unsupported external import: ${specifier}`);\n\t}\n}\n\nfunction validateManifest(value: unknown, path: string): FacetBundleManifest {\n\tif (!isRecord(value) || value.format !== FACET_BUNDLE_FORMAT) {\n\t\tthrow new Error(`Invalid facet bundle manifest format in ${path}`);\n\t}\n\tif (value.formatVersion !== FACET_BUNDLE_FORMAT_VERSION) {\n\t\tthrow new Error(`Unsupported facet bundle manifest version in ${path}: ${String(value.formatVersion)}`);\n\t}\n\tif (!isRecord(value.plugin) || typeof value.plugin.id !== \"string\" || value.plugin.id.length === 0) {\n\t\tthrow new Error(`Facet bundle manifest has an invalid plugin identity in ${path}`);\n\t}\n\tif (\n\t\tvalue.plugin.version !== undefined &&\n\t\t(typeof value.plugin.version !== \"string\" || value.plugin.version.length === 0)\n\t) {\n\t\tthrow new Error(`Facet bundle manifest has an invalid plugin version in ${path}`);\n\t}\n\tif (!isRecord(value.entries) || Object.keys(value.entries).length === 0) {\n\t\tthrow new Error(`Facet bundle manifest has no entries in ${path}`);\n\t}\n\tconst entries: Record<string, FacetBundleEntry> = {};\n\tfor (const [name, candidate] of Object.entries(value.entries)) {\n\t\tif (name.length === 0 || !isRecord(candidate)) {\n\t\t\tthrow new Error(`Facet bundle manifest has an invalid entry in ${path}`);\n\t\t}\n\t\tif (typeof candidate.file !== \"string\") throw new Error(`Facet bundle entry ${name} has no file`);\n\t\tresolveBundleFile(path, candidate.file, `entry ${name}`);\n\t\tif (typeof candidate.integrity !== \"string\") throw new Error(`Facet bundle entry ${name} has no integrity`);\n\t\tparseIntegrity(candidate.integrity);\n\t\tif (\n\t\t\t!Array.isArray(candidate.externalImports) ||\n\t\t\tcandidate.externalImports.some((item) => typeof item !== \"string\")\n\t\t) {\n\t\t\tthrow new Error(`Facet bundle entry ${name} has invalid external imports`);\n\t\t}\n\t\tconst externalImports = Object.freeze([...(candidate.externalImports as readonly string[])]);\n\t\tif (new Set(externalImports).size !== externalImports.length) {\n\t\t\tthrow new Error(`Facet bundle entry ${name} has duplicate external imports`);\n\t\t}\n\t\tif (candidate.sourceMap !== undefined) {\n\t\t\tif (typeof candidate.sourceMap !== \"string\")\n\t\t\t\tthrow new Error(`Facet bundle entry ${name} has an invalid source map`);\n\t\t\tresolveBundleFile(path, candidate.sourceMap, `entry ${name} source map`);\n\t\t}\n\t\tentries[name] = Object.freeze({\n\t\t\tfile: candidate.file,\n\t\t\tintegrity: candidate.integrity,\n\t\t\texternalImports,\n\t\t\t...(candidate.sourceMap === undefined ? {} : { sourceMap: candidate.sourceMap }),\n\t\t});\n\t}\n\treturn Object.freeze({\n\t\tformat: FACET_BUNDLE_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\tplugin: Object.freeze({\n\t\t\tid: value.plugin.id,\n\t\t\t...(value.plugin.version === undefined ? {} : { version: value.plugin.version }),\n\t\t}),\n\t\tentries: Object.freeze(entries),\n\t});\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { type FacetBundleManifest } from "./manifest.ts";
2
+ export type FacetBundlePlatform = "node" | "browser" | "neutral";
3
+ export interface BundleFacetsOptions {
4
+ readonly plugin: {
5
+ readonly id: string;
6
+ readonly version?: string;
7
+ };
8
+ /** Opaque application-selected entry names mapped to TypeScript or JavaScript source files. */
9
+ readonly entries: Readonly<Record<string, string>>;
10
+ readonly outdir: string;
11
+ readonly workingDirectory?: string;
12
+ /** Additional package imports intentionally left for the loading application to resolve. */
13
+ readonly external?: readonly string[];
14
+ readonly sourceMap?: boolean;
15
+ readonly minify?: boolean;
16
+ readonly define?: Readonly<Record<string, string>>;
17
+ readonly platform?: FacetBundlePlatform;
18
+ readonly target?: string | readonly string[];
19
+ }
20
+ export interface BundleFacetsResult {
21
+ readonly manifest: FacetBundleManifest;
22
+ readonly manifestPath: string;
23
+ }
24
+ /** Bundle each opaque facet entry into an independent content-addressed CommonJS file. */
25
+ export declare function bundleFacets(options: BundleFacetsOptions): Promise<BundleFacetsResult>;
26
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/node/bundle.ts"],"names":[],"mappings":"AAIA,OAAO,EAKN,KAAK,mBAAmB,EACxB,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,MAAM,EAAE;QAChB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,+FAA+F;IAC/F,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC;IACvC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC9B;AAED,0FAA0F;AAC1F,wBAAsB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAwC5F"}
@@ -0,0 +1,183 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
3
+ import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
4
+ import { build } from "esbuild";
5
+ import { FACET_BUNDLE_FORMAT, FACET_BUNDLE_FORMAT_VERSION, FACET_BUNDLE_MANIFEST_FILE, } from "./manifest.js";
6
+ /** Bundle each opaque facet entry into an independent content-addressed CommonJS file. */
7
+ export async function bundleFacets(options) {
8
+ validateOptions(options);
9
+ const workingDirectory = resolve(options.workingDirectory ?? process.cwd());
10
+ const outputDirectory = resolve(workingDirectory, options.outdir);
11
+ const outputParent = dirname(outputDirectory);
12
+ await mkdir(outputParent, { recursive: true });
13
+ const temporaryDirectory = join(outputParent, `.${basename(outputDirectory)}.tmp-${randomUUID()}`);
14
+ await mkdir(temporaryDirectory);
15
+ try {
16
+ const entries = {};
17
+ for (const [entryName, source] of Object.entries(options.entries).sort(([left], [right]) => left.localeCompare(right))) {
18
+ entries[entryName] = await bundleEntry({
19
+ entryName,
20
+ source: resolve(workingDirectory, source),
21
+ temporaryDirectory,
22
+ workingDirectory,
23
+ options,
24
+ });
25
+ }
26
+ const manifest = Object.freeze({
27
+ format: FACET_BUNDLE_FORMAT,
28
+ formatVersion: FACET_BUNDLE_FORMAT_VERSION,
29
+ plugin: Object.freeze({
30
+ id: options.plugin.id,
31
+ ...(options.plugin.version === undefined ? {} : { version: options.plugin.version }),
32
+ }),
33
+ entries: Object.freeze(entries),
34
+ });
35
+ await writeFile(join(temporaryDirectory, FACET_BUNDLE_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
36
+ await replaceDirectory(temporaryDirectory, outputDirectory);
37
+ return Object.freeze({
38
+ manifest,
39
+ manifestPath: join(outputDirectory, FACET_BUNDLE_MANIFEST_FILE),
40
+ });
41
+ }
42
+ catch (error) {
43
+ await rm(temporaryDirectory, { force: true, recursive: true });
44
+ throw error;
45
+ }
46
+ }
47
+ async function bundleEntry(input) {
48
+ const entryPrefix = `facet-${shortHash(input.entryName)}`;
49
+ const requestedPlatform = input.options.platform ?? "node";
50
+ const buildOptions = {
51
+ absWorkingDir: input.workingDirectory,
52
+ banner: { js: '"use strict";' },
53
+ bundle: true,
54
+ define: input.options.define,
55
+ entryNames: `${entryPrefix}-[hash]`,
56
+ entryPoints: [input.source],
57
+ external: [...new Set(["@ny4n/chord", "@ny4n/chord/*", ...(input.options.external ?? [])])],
58
+ format: "cjs",
59
+ legalComments: "none",
60
+ logLevel: "silent",
61
+ metafile: true,
62
+ minify: input.options.minify ?? false,
63
+ outdir: input.temporaryDirectory,
64
+ outExtension: { ".js": ".cjs" },
65
+ platform: requestedPlatform,
66
+ sourcemap: input.options.sourceMap === true ? "external" : false,
67
+ supported: { "dynamic-import": false },
68
+ target: input.options.target === undefined
69
+ ? requestedPlatform === "node"
70
+ ? "node22.19"
71
+ : "es2022"
72
+ : typeof input.options.target === "string"
73
+ ? input.options.target
74
+ : [...input.options.target],
75
+ write: true,
76
+ };
77
+ let result;
78
+ try {
79
+ result = await build(buildOptions);
80
+ }
81
+ catch (error) {
82
+ const diagnostics = esbuildMessages(error);
83
+ const detail = diagnostics.length === 0 ? "" : `\n${diagnostics.join("\n")}`;
84
+ throw new Error(`Could not bundle facet entry ${input.entryName}${detail}`, { cause: error });
85
+ }
86
+ const metafile = result.metafile;
87
+ if (metafile === undefined)
88
+ throw new Error(`Facet entry ${input.entryName} produced no build metadata`);
89
+ const outputs = Object.entries(metafile.outputs).filter(([path, output]) => output.entryPoint !== undefined && extname(path) === ".cjs");
90
+ if (outputs.length !== 1)
91
+ throw new Error(`Facet entry ${input.entryName} did not produce exactly one JavaScript file`);
92
+ const [outputPath, metadata] = outputs[0];
93
+ const absoluteOutputPath = resolve(input.workingDirectory, outputPath);
94
+ const file = relative(input.temporaryDirectory, absoluteOutputPath);
95
+ if (file.length === 0 || file.startsWith(`..${sep}`) || basename(file) !== file) {
96
+ throw new Error(`Facet entry ${input.entryName} produced an invalid output path`);
97
+ }
98
+ const sourceMap = input.options.sourceMap === true ? `${file}.map` : undefined;
99
+ const allowedOutputs = new Set([absoluteOutputPath]);
100
+ if (sourceMap !== undefined)
101
+ allowedOutputs.add(join(input.temporaryDirectory, sourceMap));
102
+ const unexpectedOutputs = Object.keys(metafile.outputs)
103
+ .map((path) => resolve(input.workingDirectory, path))
104
+ .filter((path) => !allowedOutputs.has(path));
105
+ if (unexpectedOutputs.length > 0) {
106
+ throw new Error(`Facet entry ${input.entryName} produced files other than its JavaScript bundle and source map`);
107
+ }
108
+ const contents = await readFile(absoluteOutputPath);
109
+ if (sourceMap !== undefined)
110
+ await stat(join(input.temporaryDirectory, sourceMap));
111
+ return Object.freeze({
112
+ file,
113
+ integrity: `sha256-${createHash("sha256").update(contents).digest("base64")}`,
114
+ externalImports: Object.freeze([...new Set(metadata.imports.filter(({ external }) => external).map(({ path }) => path))].sort()),
115
+ ...(sourceMap === undefined ? {} : { sourceMap }),
116
+ });
117
+ }
118
+ function validateOptions(options) {
119
+ if (options.plugin.id.length === 0)
120
+ throw new TypeError("Facet bundle plugin ID must not be empty");
121
+ if (options.plugin.version !== undefined && options.plugin.version.length === 0) {
122
+ throw new TypeError("Facet bundle plugin version must not be empty");
123
+ }
124
+ const entries = Object.entries(options.entries);
125
+ if (entries.length === 0)
126
+ throw new TypeError("Facet bundle must contain at least one entry");
127
+ for (const [name, source] of entries) {
128
+ if (name.length === 0)
129
+ throw new TypeError("Facet bundle entry name must not be empty");
130
+ if (source.length === 0)
131
+ throw new TypeError(`Facet bundle entry ${name} must have a source path`);
132
+ }
133
+ for (const external of options.external ?? []) {
134
+ if (external.length === 0)
135
+ throw new TypeError("Facet bundle external import must not be empty");
136
+ }
137
+ }
138
+ async function replaceDirectory(temporaryDirectory, outputDirectory) {
139
+ const backupDirectory = `${outputDirectory}.old-${randomUUID()}`;
140
+ let movedExisting = false;
141
+ try {
142
+ await rename(outputDirectory, backupDirectory);
143
+ movedExisting = true;
144
+ }
145
+ catch (error) {
146
+ if (!isMissingPath(error))
147
+ throw error;
148
+ }
149
+ try {
150
+ await rename(temporaryDirectory, outputDirectory);
151
+ }
152
+ catch (error) {
153
+ if (movedExisting)
154
+ await rename(backupDirectory, outputDirectory);
155
+ throw error;
156
+ }
157
+ if (movedExisting)
158
+ await rm(backupDirectory, { force: true, recursive: true });
159
+ }
160
+ function shortHash(value) {
161
+ return createHash("sha256").update(value).digest("hex").slice(0, 12);
162
+ }
163
+ function esbuildMessages(error) {
164
+ if (!isRecord(error) || !Array.isArray(error.errors))
165
+ return [];
166
+ return error.errors.flatMap((candidate) => isEsbuildMessage(candidate) ? [formatEsbuildMessage(candidate)] : []);
167
+ }
168
+ function formatEsbuildMessage(message) {
169
+ const location = message.location;
170
+ return location === null
171
+ ? message.text
172
+ : `${location.file}:${location.line}:${location.column + 1}: ${message.text}`;
173
+ }
174
+ function isEsbuildMessage(value) {
175
+ return isRecord(value) && typeof value.text === "string" && (value.location === null || isRecord(value.location));
176
+ }
177
+ function isMissingPath(error) {
178
+ return isRecord(error) && error.code === "ENOENT";
179
+ }
180
+ function isRecord(value) {
181
+ return typeof value === "object" && value !== null && !Array.isArray(value);
182
+ }
183
+ //# sourceMappingURL=bundle.js.map