| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Phase 1 of #7 only embedded the data island when the stored content type was application/ld+json; .ttl/.n3 URLs got the mashlib wrapper without an embedded payload. Extend the embed branch to cover text/turtle and text/n3: - Try JSON.parse first. JSS converts Turtle/N3 to JSON-LD on PUT (handlePut conneg branch), so for HTTP-PUT'd .ttl/.n3 files the bytes on disk are already JSON-LD — pass the Buffer through, no extra string copy. - Fall back to turtleToJsonLd (n3.js) for files placed on the filesystem out-of-band in their native format. JSON.stringify the result compactly so it doesn't burn cap bytes on whitespace. - Both parses failing → drop the island silently. The wrapper still renders and mashlib XHR-fetches the original as before. Other RDF formats (rdf+xml, etc.) are untouched. Add integration coverage: PUT Turtle / PUT N3 → GET text/html shows the embedded JSON-LD with the original literals. The both-parses-fail branch can't be reached via HTTP (PUT validates and rejects malformed Turtle with 400 before storage), so it's covered by inspection only. All 555 tests pass (553 + 2 new).
There was a problem hiding this comment.
Extends the mashlib HTML “data island” embedding path to include resources stored under .ttl and .n3 URLs by translating Turtle/N3 to JSON-LD (falling back to omitting the island on parse failure), aligning with the Phase-1 data island goals.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/handlers/resource.js | Adds Turtle/N3→JSON-LD conversion logic for HTML data-island embedding when serving mashlib wrapper. |
| test/data-island.test.js | Adds integration coverage for Turtle and N3 resources embedding parsed JSON-LD into the data island. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| storedContentType === 'application/ld+json' || | ||
| storedContentType === 'text/turtle' || | ||
| storedContentType === 'text/n3'; |
| try { | ||
| const jsonLd = await turtleToJsonLd(text, resourceUrl); | ||
| embedJsonLd = JSON.stringify(jsonLd); | ||
| } catch { | ||
| // Both parses failed → drop the island. The wrapper | ||
| // still renders and mashlib XHR-fetches the original. | ||
| } |
| const text = buf.toString('utf8'); | ||
| try { | ||
| JSON.parse(text); | ||
| // Already JSON-LD bytes — pass the Buffer through so | ||
| // dataIsland() can coerce it without an extra string copy. | ||
| embedJsonLd = buf; | ||
| } catch { | ||
| try { | ||
| const jsonLd = await turtleToJsonLd(text, resourceUrl); | ||
| embedJsonLd = JSON.stringify(jsonLd); | ||
| } catch { | ||
| // Both parses failed → drop the island. The wrapper | ||
| // still renders and mashlib XHR-fetches the original. |
Three real points addressed:
1. Use `RDF_TYPES.JSON_LD` / `.TURTLE` / `.N3` instead of hardcoded
strings. Already imported and used elsewhere in this file.
2. Avoid double-decode in the JSON-LD-on-disk hot path. Restructure
the embed branch so:
- `application/ld+json` URL: pass Buffer through (no decode,
no parse — matches pre-PR behaviour).
- `text/turtle` / `text/n3` URL: decode once, JSON.parse;
on success pass the decoded *text* through (not the Buffer)
so dataIsland() doesn't re-decode via String() coercion.
- Turtle parse fallback unchanged.
3. Add coverage for the both-parses-fail branch. The handler's
defensive guard fires when a `.ttl`/`.n3` file is placed on disk
out-of-band (bypassing the PUT validator). The new test plants
a malformed Turtle file directly into the test data dir via
node:fs and asserts the wrapper still renders without an island.
556 / 556 tests pass (553 + 3 new).
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Closes #344.
Summary
Test plan