Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1630f55
Add vocabulary property preprocessors to vocab-tools
dahlia Jun 5, 2026
82ec5ea
Normalize Link icon and image values to Image objects
dahlia Jun 5, 2026
469803e
Document property preprocessor changes
dahlia Jun 5, 2026
e479455
Expand JSON-LD before preprocessors in property path
dahlia Jun 5, 2026
1db7fb7
Update Node.js and Bun snapshots for preprocessor changes
dahlia Jun 5, 2026
bbfe8d0
Use static imports and fix review issues
dahlia Jun 5, 2026
3152298
Guard blank-node IDs in remaining URL construction sites
dahlia Jun 5, 2026
cc35832
Resolve relative @id URLs against baseUrl in decoder
dahlia Jun 5, 2026
57eb851
Throw on missing preprocessor module and extract baseUrl
dahlia Jun 5, 2026
6a5265a
Compute resolved URL once for both options.baseUrl and _baseUrl
dahlia Jun 5, 2026
2185439
Add JSDoc to new exported APIs
dahlia Jun 5, 2026
456127f
Note normalizeLinkToImage is exported in CHANGES.md
dahlia Jun 5, 2026
14d24ad
Update Node.js and Bun snapshots for codegen changes
dahlia Jun 5, 2026
0749718
Update Deno snapshot for codegen changes
dahlia Jun 5, 2026
2548564
Re-export normalizeLinkToImage and fix root @id resolution
dahlia Jun 6, 2026
9fed078
Guard root @id URL construction and update snapshots
dahlia Jun 6, 2026
a29690b
Revert URL resolution changes and scope baseUrl spread
dahlia Jun 6, 2026
688a54c
Silence baseUrl deprecation in Twoslash compiler options
dahlia Jun 6, 2026
fe1a813
Throw on missing preprocessor module in property.ts
dahlia Jun 6, 2026
b34f17a
Fix relative @id resolution and preserve Link id
dahlia Jun 6, 2026
92b66cb
Update snapshots for @id resolution changes
dahlia Jun 6, 2026
996c3b7
Restore taskLists plugin accidentally dropped during merge
dahlia Jun 6, 2026
c8872aa
Guard URL construction and jsonld.expand calls
dahlia Jun 6, 2026
78f293d
Keep only safe URL.canParse guards, revert decoder guard
dahlia Jun 6, 2026
a4b1a72
Restore docs nav entries damaged by stash conflict
dahlia Jun 6, 2026
f1a9bde
Handle relative IDs in nested decoders
dahlia Jun 6, 2026
5d2708b
Preserve baseUrl for cached re-parse of preprocessed properties
dahlia Jun 6, 2026
62100f2
Guard blank node @id from baseUrl resolution in constructor
dahlia Jun 6, 2026
7eed2c6
Complete blank-node and non-preprocessor baseUrl coverage
dahlia Jun 6, 2026
540de76
Add URL.canParse guard and deduplicate accessor baseUrl logic
dahlia Jun 6, 2026
61cc233
Drop redundant as string casts and fix preprocessor docs
dahlia Jun 6, 2026
d262252
Reject malformed decoded IDs
dahlia Jun 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,42 @@ To be released.

[#489]: https://github.com/fedify-dev/fedify/issues/489

### @fedify/vocab-runtime

- Added `PropertyPreprocessor`, `PropertyPreprocessorContext`, and `Json`
types for normalizing wire-level JSON-LD property values before the
generated range decoder runs. [[#792]]

[#792]: https://github.com/fedify-dev/fedify/issues/792

### @fedify/vocab

- Explicit ActivityStreams `Link` objects in `icon` and `image` properties
are now normalized to `Image` during decoding via the new exported
`normalizeLinkToImage()` preprocessor. The public `Image`-oriented
TypeScript API is unchanged. [[#790], [#792]]

- The generated `fromJsonLd()` methods no longer resolve blank node
identifiers (`_:b0`) against `options.baseUrl`; blank nodes are left
as `null` in the resulting instance's `id` field. [[#792]]

[#790]: https://github.com/fedify-dev/fedify/issues/790

### @fedify/vocab-tools

- Property schemas now support a `preprocessors` field that lists
module/function pairs. Generated decoders dynamically import and run
these preprocessors for each expanded JSON-LD property value before
falling back to the normal range decoder. [[#792]]

- The generated base class now stores the `baseUrl` from `fromJsonLd()`
as a protected `_baseUrl` field. This URL is used to resolve
relative URIs when cached embedded property documents are re-parsed
lazily by accessors like `getIcon()`, so that callers do not need to
pass an explicit `baseUrl`. The stored URL is defensively copied so
that mutation of the caller's original `URL` object does not affect
later resolution. [[#792]]


Version 2.2.5
-------------
Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.jsr-cache.json
.jsr-cache-*.json
.jsr-*-cache.json
.vitepress/cache/
.vitepress/dist/
Expand Down
42 changes: 25 additions & 17 deletions packages/cli/src/lookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ import {
writeSeparator,
} from "./lookup.ts";

const testRuntime = "Bun" in globalThis ? "bun" : "node";

function getTestOutputDir(name: string): string {
return `./test_output_${testRuntime}_${name}`;
}

async function parseWithConfig<TValue, TState>(
parser: Parser<"sync", TValue, TState>,
args: readonly string[],
Expand All @@ -54,7 +60,7 @@ async function parseWithConfig<TValue, TState>(
}

test("writeObjectToStream - writes Note object with default options", async () => {
const testDir = "./test_output_note";
const testDir = getTestOutputDir("note");
const testFile = `${testDir}/note.txt`;

await mkdir(testDir, { recursive: true });
Expand All @@ -78,7 +84,7 @@ test("writeObjectToStream - writes Note object with default options", async () =
});

test("writeObjectToStream - writes Activity object in raw JSON-LD format", async () => {
const testDir = "./test_output_activity";
const testDir = getTestOutputDir("activity");
const testFile = `${testDir}/raw.json`;

await mkdir(testDir, { recursive: true });
Expand All @@ -102,7 +108,7 @@ test("writeObjectToStream - writes Activity object in raw JSON-LD format", async
});

test("writeObjectToStream - writes object in compact JSON-LD format", async () => {
const testDir = "./test_output_compact";
const testDir = getTestOutputDir("compact");
const testFile = `${testDir}/compact.json`;

await mkdir(testDir, { recursive: true });
Expand All @@ -125,7 +131,7 @@ test("writeObjectToStream - writes object in compact JSON-LD format", async () =
});

test("writeObjectToStream - writes object in expanded JSON-LD format", async () => {
const testDir = "./test_output_expand";
const testDir = getTestOutputDir("expand");
const testFile = `${testDir}/expand.json`;

await mkdir(testDir, { recursive: true });
Expand All @@ -147,7 +153,7 @@ test("writeObjectToStream - writes object in expanded JSON-LD format", async ()
});

test("writeObjectToStream - supports reusing an output stream", async () => {
const testDir = "./test_output_reused_stream";
const testDir = getTestOutputDir("reused_stream");
const testFile = `${testDir}/notes.txt`;

await mkdir(testDir, { recursive: true });
Expand Down Expand Up @@ -181,7 +187,7 @@ test("writeObjectToStream - supports reusing an output stream", async () => {
});

test("writeSeparator - writes to provided output stream", async () => {
const testDir = "./test_output_separator";
const testDir = getTestOutputDir("separator");
const testFile = `${testDir}/separator.txt`;
await mkdir(testDir, { recursive: true });

Expand Down Expand Up @@ -244,7 +250,7 @@ test("writeObjectToStream - writes to stdout when no output file specified", asy
});

test("writeObjectToStream - handles empty content properly", async () => {
const testDir = "./test_output_empty";
const testDir = getTestOutputDir("empty");
const testFile = `${testDir}/empty.txt`;

await mkdir(testDir, { recursive: true });
Expand Down Expand Up @@ -1191,7 +1197,7 @@ async function withRecursiveLookupServer<T>(
}

test("runLookup - rejects recursive private targets by default", async () => {
const testDir = "./test_output_runlookup_recurse_private_default";
const testDir = getTestOutputDir("runlookup_recurse_private_default");
const testFile = `${testDir}/out.jsonl`;
await mkdir(testDir, { recursive: true });
try {
Expand Down Expand Up @@ -1226,7 +1232,7 @@ test("runLookup - rejects recursive private targets by default", async () => {
});

test("runLookup - allows recursive private targets with allowPrivateAddress", async () => {
const testDir = "./test_output_runlookup_recurse_private_allowed";
const testDir = getTestOutputDir("runlookup_recurse_private_allowed");
const testFile = `${testDir}/out.jsonl`;
await mkdir(testDir, { recursive: true });
try {
Expand Down Expand Up @@ -1258,7 +1264,7 @@ test("runLookup - allows recursive private targets with allowPrivateAddress", as
});

test("runLookup - keeps recursive private contexts blocked", async () => {
const testDir = "./test_output_runlookup_recurse_private_context";
const testDir = getTestOutputDir("runlookup_recurse_private_context");
const testFile = `${testDir}/out.jsonl`;
await mkdir(testDir, { recursive: true });
try {
Expand Down Expand Up @@ -1293,7 +1299,7 @@ test("runLookup - keeps recursive private contexts blocked", async () => {
});

test("runLookup - reverses output order in default multi-input mode", async () => {
const testDir = "./test_output_runlookup_default_reverse";
const testDir = getTestOutputDir("runlookup_default_reverse");
const testFile = `${testDir}/out.jsonl`;
await mkdir(testDir, { recursive: true });
try {
Expand Down Expand Up @@ -1349,7 +1355,7 @@ test("runLookup - reverses output order in default multi-input mode", async () =
});

test("runLookup - reverses output order in recurse mode", async () => {
const testDir = "./test_output_runlookup_recurse_reverse";
const testDir = getTestOutputDir("runlookup_recurse_reverse");
const testFile = `${testDir}/out.jsonl`;
await mkdir(testDir, { recursive: true });
try {
Expand Down Expand Up @@ -1412,7 +1418,7 @@ test("runLookup - reverses output order in recurse mode", async () => {
});

test("runLookup - reverses output order in traverse mode", async () => {
const testDir = "./test_output_runlookup_traverse_reverse";
const testDir = getTestOutputDir("runlookup_traverse_reverse");
const testFile = `${testDir}/out.jsonl`;
await mkdir(testDir, { recursive: true });
try {
Expand Down Expand Up @@ -1455,7 +1461,9 @@ test("runLookup - reverses output order in traverse mode", async () => {
});

test("runLookup - emits reversed partial items on traverse reverse failure", async () => {
const testDir = "./test_output_runlookup_traverse_reverse_partial_failure";
const testDir = getTestOutputDir(
"runlookup_traverse_reverse_partial_failure",
);
const testFile = `${testDir}/out.jsonl`;
await mkdir(testDir, { recursive: true });
try {
Expand Down Expand Up @@ -1503,7 +1511,7 @@ test("runLookup - emits reversed partial items on traverse reverse failure", asy
});

test("runLookup - writes separators between adjacent traversed items", async () => {
const testDir = "./test_output_runlookup_traverse_separator";
const testDir = getTestOutputDir("runlookup_traverse_separator");
const testFile = `${testDir}/out.jsonl`;
const separator = "<SEP>";
await mkdir(testDir, { recursive: true });
Expand Down Expand Up @@ -1566,7 +1574,7 @@ test("runLookup - writes separators between adjacent traversed items", async ()
test(
"runLookup - writes separators between adjacent traversed items in reverse mode",
async () => {
const testDir = "./test_output_runlookup_traverse_separator_reverse";
const testDir = getTestOutputDir("runlookup_traverse_separator_reverse");
const testFile = `${testDir}/out.jsonl`;
const separator = "<SEP>";
await mkdir(testDir, { recursive: true });
Expand Down Expand Up @@ -1629,7 +1637,7 @@ test(
);

test("runLookup - emits root object on recurse reverse failure", async () => {
const testDir = "./test_output_runlookup_recurse_reverse_partial_failure";
const testDir = getTestOutputDir("runlookup_recurse_reverse_partial_failure");
const testFile = `${testDir}/out.jsonl`;
await mkdir(testDir, { recursive: true });
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/fedify/src/federation/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function isInvalidJsonLdError(error: unknown): error is Error {

function isValidationTypeError(error: unknown): error is TypeError {
return error instanceof TypeError &&
(/^(Invalid JSON-LD:|Invalid type:|Unexpected type:)/
(/^(Invalid JSON-LD:|Invalid type:|Unexpected type:|Invalid @id:)/
.test(error.message) ||
isInvalidUrlTypeError(error));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fedify/src/federation/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ function isPermanentInboxParseError(error: unknown): error is Error {
(error.name === "jsonld.SyntaxError" &&
!isRemoteContextLoadingFailure(error)))) ||
(error instanceof TypeError &&
(/^(Invalid JSON-LD:|Invalid type:|Unexpected type:)/
(/^(Invalid JSON-LD:|Invalid type:|Unexpected type:|Invalid @id:)/
.test(error.message) ||
isInvalidUrlTypeError(error)));
}
Expand Down
5 changes: 5 additions & 0 deletions packages/vocab-runtime/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export {
type GetUserAgentOptions,
logRequest,
} from "./request.ts";
export {
type Json,
type PropertyPreprocessor,
type PropertyPreprocessorContext,
} from "./preprocessor.ts";
export {
expandIPv6Address,
isValidPublicIPv4Address,
Expand Down
43 changes: 43 additions & 0 deletions packages/vocab-runtime/src/preprocessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { DocumentLoader } from "./docloader.ts";
import type { TracerProvider } from "@opentelemetry/api";

/**
* JSON value shape passed to property preprocessors.
* @since 2.3.0
*/
export type Json =
| string
| number
| boolean
| null
| readonly Json[]
| { readonly [key: string]: Json };

/**
* Runtime context provided to property preprocessors.
* @since 2.3.0
*/
export interface PropertyPreprocessorContext {
/** Loader for remote JSON-LD documents. */
documentLoader?: DocumentLoader;
/** Loader for remote JSON-LD contexts. */
contextLoader?: DocumentLoader;
/** OpenTelemetry tracer provider for instrumentation. */
tracerProvider?: TracerProvider;
/** Base URL for resolving relative references. */
baseUrl?: URL;
}

/**
* Function signature for schema-configured property preprocessors.
*
* Receives an expanded JSON-LD property value and returns a vocabulary
* object when the value is handled, `undefined` when the value should
* fall through to the normal range decoder, or an `Error` when the value
* is recognized but cannot be converted.
* @since 2.3.0
*/
export type PropertyPreprocessor<T = unknown> = (
value: Json,
context: PropertyPreprocessorContext,
) => T | undefined | Error | Promise<T | undefined | Error>;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Loading