Skip to content

Commit 7e38ae1

Browse files
fix: the registry stores the manifest the engine read
1 parent fa9b12a commit 7e38ae1

3 files changed

Lines changed: 37 additions & 11 deletions

File tree

‎site/src/lib/server/bundle.ts‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { unpack } from './engine'
1+
import { manifestFields, unpack } from './engine'
22

33
// The prefix the CLI packs documentation under, which no import can reach.
44
const DOCS = '@docs/'
@@ -31,16 +31,7 @@ export function packed(artifact: Uint8Array): Packed {
3131
const declared = files.get('edge.json')
3232
if (!declared) throw new Error('That package carries no edge.json, so it has nothing to publish under.')
3333

34-
let manifest: Record<string, unknown>
35-
try {
36-
manifest = JSON.parse(text.decode(declared))
37-
} catch {
38-
throw new Error('The edge.json inside that package is not JSON.')
39-
}
40-
41-
if (manifest == null || typeof manifest !== 'object' || Array.isArray(manifest)) {
42-
throw new Error('The edge.json inside that package is not an object.')
43-
}
34+
const manifest = manifestFields(declared)
4435

4536
return {
4637
name: manifest.name,

‎site/src/lib/server/engine.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Exports = {
1212
wasm_alloc(size: number): number
1313
wasm_free(ptr: number, size: number): void
1414
manifest_check(manifest: number, manifestLen: number, lock: number, lockLen: number, system: number, systemLen: number): number
15+
manifest_fields(manifest: number, manifestLen: number): number
1516
bundle_index(bundle: number, bundleLen: number): number
1617
}
1718

@@ -58,6 +59,13 @@ export function unpack(artifact: Uint8Array): Map<string, Uint8Array> {
5859
return new Map((answer.files ?? []).map(([path, at, len]) => [path, artifact.subarray(at, at + len)]))
5960
}
6061

62+
/* The fields a registry stores from a manifest, read by the engine that holds it to the rules, so what is stored is what was checked. */
63+
export function manifestFields(manifest: Uint8Array): Record<'name' | 'version' | 'description' | 'repository' | 'edge', string | null> {
64+
const read = JSON.parse(call([manifest], (e, [at]) => e.manifest_fields(at!, manifest.length)))
65+
if (read.error !== undefined) throw new Error(`The edge.json inside that package does not hold, ${read.error}`)
66+
return read
67+
}
68+
6169
/* Holds each manifest a bundle carries to the engine's rules, its lock and its grants, here since Node cannot load the compiler. */
6270
export function checkManifests(manifests: Record<string, string>, locks: Record<string, string>) {
6371
for (const [dir, source] of Object.entries(manifests)) {

‎src/wasm/package.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,33 @@ pub unsafe extern "C" fn manifest_check(m_ptr: *const u8, m_len: u32, l_ptr: *co
2626
write_out(&checked.err().unwrap_or_default()) as u32
2727
}
2828

29+
/* The fields a registry stores from the manifest at `ptr`, read as the rules read them, as JSON, or why it is not one. */
30+
#[unsafe(no_mangle)]
31+
pub unsafe extern "C" fn manifest_fields(ptr: *const u8, len: u32) -> u32 {
32+
let mut out = String::from("{");
33+
match parse_manifest(unsafe { safe_bytes(ptr, len) }) {
34+
Err(e) => {
35+
out.push_str("\"error\":");
36+
quote(&mut out, &e);
37+
}
38+
Ok(m) => {
39+
for (i, (key, value)) in [("name", m.name), ("version", m.version), ("description", m.description), ("repository", m.repository), ("edge", m.edge)].into_iter().enumerate() {
40+
if i > 0 {
41+
out.push(',');
42+
}
43+
quote(&mut out, key);
44+
out.push(':');
45+
match value {
46+
Some(text) => quote(&mut out, &text),
47+
None => out.push_str("null"),
48+
}
49+
}
50+
}
51+
}
52+
out.push('}');
53+
write_out(&out) as u32
54+
}
55+
2956
/* Where each file of the bundle at `ptr` sits inside it, as JSON, or why it is not a bundle. */
3057
#[unsafe(no_mangle)]
3158
pub unsafe extern "C" fn bundle_index(ptr: *const u8, len: u32) -> u32 {

0 commit comments

Comments
 (0)