diff --git a/CHANGES.md b/CHANGES.md index 679cf4860..8bd936766 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,18 @@ Version 2.4.0 To be released. +### @fedify/vocab + + - Added support for [FEP-ef61] portable ActivityPub IRIs in generated + vocabulary codecs. `ap:` and `ap+ef61:` values with decoded or + percent-encoded DID authorities now parse as `URL` objects, and JSON-LD + serialization emits canonical `ap+ef61:` values with decoded DID + authorities. [[#826], [#850]] + +[FEP-ef61]: https://w3id.org/fep/ef61 +[#826]: https://github.com/fedify-dev/fedify/issues/826 +[#850]: https://github.com/fedify-dev/fedify/pull/850 + Version 2.3.1 ------------- diff --git a/docs/manual/vocab.md b/docs/manual/vocab.md index 26bd8c661..c5899c3d2 100644 --- a/docs/manual/vocab.md +++ b/docs/manual/vocab.md @@ -108,12 +108,19 @@ const create = new Create({ Note that every URI is represented as a [`URL`] object. This is for distinguishing the URIs from the other strings. +Fedify also accepts [FEP-ef61] portable ActivityPub IRIs in JSON-LD input. +Both the `ap:` and `ap+ef61:` schemes are accepted, whether the DID authority +is decoded (e.g., `ap+ef61://did:key:.../actor`) or percent-encoded. Fedify +stores these IRIs as `URL` objects with a URL-safe authority internally, and +serializes them as canonical `ap+ef61:` IRIs with the decoded DID authority. + > [!TIP] > You can instantiate an object from a JSON-LD document by calling the > `fromJsonLd()` method of the object. See the [*JSON-LD* section](#json-ld) > for details. [`URL`]: https://developer.mozilla.org/en-US/docs/Web/API/URL +[FEP-ef61]: https://w3id.org/fep/ef61 Properties diff --git a/packages/vocab-runtime/deno.json b/packages/vocab-runtime/deno.json index ed0b883cf..6f56da282 100644 --- a/packages/vocab-runtime/deno.json +++ b/packages/vocab-runtime/deno.json @@ -4,6 +4,7 @@ "license": "MIT", "exports": { ".": "./src/mod.ts", + "./internal/jsonld-cache": "./src/internal/jsonld-cache.ts", "./jsonld": "./src/jsonld.ts", "./temporal": "./src/temporal.ts" }, diff --git a/packages/vocab-runtime/package.json b/packages/vocab-runtime/package.json index c2a3a39fb..92b9c2656 100644 --- a/packages/vocab-runtime/package.json +++ b/packages/vocab-runtime/package.json @@ -42,6 +42,16 @@ "require": "./dist/jsonld.cjs", "default": "./dist/jsonld.js" }, + "./internal/jsonld-cache": { + "types": { + "import": "./dist/internal/jsonld-cache.d.ts", + "require": "./dist/internal/jsonld-cache.d.cts", + "default": "./dist/internal/jsonld-cache.d.ts" + }, + "import": "./dist/internal/jsonld-cache.js", + "require": "./dist/internal/jsonld-cache.cjs", + "default": "./dist/internal/jsonld-cache.js" + }, "./temporal": { "types": { "import": "./dist/temporal.d.ts", diff --git a/packages/vocab-runtime/src/internal/jsonld-cache.ts b/packages/vocab-runtime/src/internal/jsonld-cache.ts new file mode 100644 index 000000000..190ad7595 --- /dev/null +++ b/packages/vocab-runtime/src/internal/jsonld-cache.ts @@ -0,0 +1,538 @@ +import type { DocumentLoader } from "../docloader.ts"; +import jsonld from "../jsonld.ts"; +import { formatIri, haveSameIriOrigin } from "../url.ts"; + +const noJsonLdContext = Symbol("noJsonLdContext"); + +/** + * Options for deciding whether two IRIs should be treated as same-origin. + * + * @internal Technically exported for generated vocabulary classes, but not + * part of the public API contract. This is not considered public API for + * Semantic Versioning decisions. + */ +export interface IriTrustOptions { + crossOrigin?: "ignore" | "throw" | "trust"; +} + +/** + * Checks whether an IRI is trusted relative to another IRI. + * + * @internal Technically exported for generated vocabulary classes, but not + * part of the public API contract. This is not considered public API for + * Semantic Versioning decisions. + */ +export function isTrustedIriOrigin( + options: IriTrustOptions, + left: URL | null | undefined, + right: URL | null | undefined, +): boolean { + return options.crossOrigin === "trust" || left == null || + (right != null && haveSameIriOrigin(left, right)); +} + +/** + * Normalizes portable IRIs in JSON-LD cache data. + * + * @internal Technically exported for generated vocabulary classes, but not + * part of the public API contract. This is not considered public API for + * Semantic Versioning decisions. + */ +export function normalizeJsonLdIris( + value: unknown, + iriKeys: ReadonlySet, + iriPattern: RegExp = /^ap(?:\+ef61)?:\/\//i, +): unknown { + return normalize(value, undefined, 0, undefined); + + function isIriPosition(key: string, parentKey?: string): boolean { + return iriKeys.has(key) || + ((key === "@value" || key === "@list" || key === "@set") && + parentKey != null && iriKeys.has(parentKey)); + } + + function arrayItemParentKey( + key?: string, + parentKey?: string, + ): string | undefined { + return key === "@list" || key === "@set" ? parentKey : key; + } + + function entryParentKey( + entryKey: string, + key?: string, + parentKey?: string, + ): string | undefined { + if (entryKey === "@list" || entryKey === "@set") return parentKey ?? key; + return key === "@list" || key === "@set" ? parentKey : key; + } + + function normalize( + value: unknown, + key?: string, + depth = 0, + parentKey?: string, + ): unknown { + if (depth > 32 || key === "@context") return value; + if (typeof value === "string") { + if ( + key != null && isIriPosition(key, parentKey) && iriPattern.test(value) + ) { + try { + return formatIri(value); + } catch { + return value; + } + } + return value; + } + if (Array.isArray(value)) { + let clone: unknown[] | undefined; + const itemParentKey = arrayItemParentKey(key, parentKey); + for (let i = 0; i < value.length; i++) { + const result = normalize(value[i], key, depth + 1, itemParentKey); + if (result !== value[i]) { + clone ??= value.slice(0, i); + clone.push(result); + } else if (clone != null) { + clone.push(value[i]); + } + } + return clone ?? value; + } + if (value == null || typeof value !== "object") return value; + const object = value as Record; + let clone: Record | undefined; + for (const entryKey of globalThis.Object.keys(object)) { + const result = normalize( + object[entryKey], + entryKey, + depth + 1, + entryParentKey(entryKey, key, parentKey), + ); + if (result !== object[entryKey]) { + clone ??= { ...object }; + defineJsonLdProperty(clone, entryKey, result); + } + } + return clone ?? object; + } +} + +/** + * Finds the first JSON-LD context in a value. + * + * @internal Technically exported for generated vocabulary classes, but not + * part of the public API contract. This is not considered public API for + * Semantic Versioning decisions. + */ +export function getJsonLdContext(value: unknown, depth = 0): unknown { + if (depth > 32) return undefined; + if (Array.isArray(value)) { + for (const item of value) { + const context = getJsonLdContext(item, depth + 1); + if (context !== undefined) return context; + } + return undefined; + } + if ( + value == null || typeof value !== "object" || + !("@context" in value) + ) { + return undefined; + } + return (value as Record)["@context"]; +} + +function getOwnJsonLdContext(value: unknown): unknown | typeof noJsonLdContext { + if ( + value == null || typeof value !== "object" || Array.isArray(value) || + !("@context" in value) + ) { + return noJsonLdContext; + } + return (value as Record)["@context"]; +} + +/** + * Recompacts normalized JSON-LD cache data against the original context. + * + * @internal Technically exported for generated vocabulary classes, but not + * part of the public API contract. This is not considered public API for + * Semantic Versioning decisions. + */ +export async function compactJsonLdCache( + normalized: unknown, + original: unknown, + documentLoader?: DocumentLoader, + depth = 0, + inheritedContext?: unknown, +): Promise { + if (depth > 32) return normalized; + if (Array.isArray(original)) { + const normalizedArray = Array.isArray(normalized) + ? normalized + : normalized != null && typeof normalized === "object" && + "@graph" in normalized && + Array.isArray((normalized as Record)["@graph"]) + ? (normalized as Record)["@graph"] as unknown[] + : undefined; + if (normalizedArray == null) return normalized; + let clone: unknown[] | undefined; + for (let i = 0; i < normalizedArray.length; i++) { + const item = await compactJsonLdCache( + normalizedArray[i], + original[i], + documentLoader, + depth + 1, + inheritedContext, + ); + if (item !== normalizedArray[i]) { + clone ??= normalizedArray.slice(0, i); + clone.push(item); + } else if (clone != null) { + clone.push(normalizedArray[i]); + } + } + return clone ?? (Array.isArray(normalized) ? normalized : normalizedArray); + } + const ownContext = getOwnJsonLdContext(original); + const context = ownContext === noJsonLdContext + ? inheritedContext + : ownContext; + if (context == null) { + return preserveNoContextJsonLdShape(normalized, original, depth); + } + return await preserveJsonLdShape( + await mergeUnmappedTerms( + await jsonld.compact( + Array.isArray(normalized) && normalized.length === 1 + ? normalized[0] + : normalized, + context, + { documentLoader }, + ), + original, + context, + documentLoader, + ), + original, + context, + documentLoader, + depth, + ); +} + +function preserveNoContextJsonLdShape( + normalized: unknown, + original: unknown, + depth = 0, +): unknown { + if (depth > 32) return normalized; + if ( + original == null || typeof original !== "object" || + Array.isArray(original) + ) { + return normalized; + } + const normalizedObject = Array.isArray(normalized) && normalized.length === 1 + ? normalized[0] + : normalized; + if ( + normalizedObject == null || typeof normalizedObject !== "object" || + Array.isArray(normalizedObject) + ) { + return normalized; + } + const source = normalizedObject as Record; + const originalObject = original as Record; + let clone: Record | undefined; + for (const key of globalThis.Object.keys(originalObject)) { + if (!globalThis.Object.prototype.hasOwnProperty.call(source, key)) { + continue; + } + const value = preserveNoContextValue( + source[key], + originalObject[key], + depth + 1, + ); + if (value !== originalObject[key]) { + clone ??= { ...originalObject }; + defineJsonLdProperty(clone, key, value); + } + } + return clone ?? original; +} + +function preserveNoContextValue( + normalized: unknown, + original: unknown, + depth: number, +): unknown { + if (depth > 32) return normalized; + if (Array.isArray(original)) { + const normalizedArray = Array.isArray(normalized) + ? normalized + : [normalized]; + let clone: unknown[] | undefined; + for (let i = 0; i < original.length; i++) { + const value = preserveNoContextValue( + normalizedArray[i], + original[i], + depth + 1, + ); + if (value !== original[i]) { + clone ??= original.slice(0, i); + clone.push(value); + } else if (clone != null) { + clone.push(original[i]); + } + } + return clone ?? original; + } + const normalizedValue = Array.isArray(normalized) + ? normalized[0] + : normalized; + if ( + normalizedValue == null || typeof normalizedValue !== "object" || + Array.isArray(normalizedValue) + ) { + return normalizedValue; + } + const normalizedObject = normalizedValue as Record; + if ( + original != null && typeof original === "object" && !Array.isArray(original) + ) { + return preserveNoContextJsonLdShape(normalizedObject, original, depth + 1); + } + if (typeof normalizedObject["@id"] === "string") { + return normalizedObject["@id"]; + } + if ("@value" in normalizedObject) return normalizedObject["@value"]; + return normalizedValue; +} + +function getTopLevelTerms(value: unknown): ReadonlySet { + const terms = new Set(); + const nodes = Array.isArray(value) ? value : [value]; + for (const node of nodes) { + if (node == null || typeof node !== "object" || Array.isArray(node)) { + continue; + } + for (const key of globalThis.Object.keys(node)) { + if (key.startsWith("@")) continue; + terms.add(key); + } + } + return terms; +} + +async function mergeUnmappedTerms( + compacted: unknown, + original: unknown, + context: unknown, + documentLoader?: DocumentLoader, +): Promise { + if ( + original == null || typeof original !== "object" || + Array.isArray(original) || + compacted == null || typeof compacted !== "object" || + Array.isArray(compacted) + ) { + return compacted; + } + const unmappedKeys = globalThis.Object.keys(original).filter((key) => + key !== "@context" && + !globalThis.Object.prototype.hasOwnProperty.call(compacted, key) + ); + if (unmappedKeys.length < 1) return compacted; + const result = { ...compacted as Record }; + const compactedWithContext = compacted != null && + typeof compacted === "object" && !Array.isArray(compacted) && + !("@context" in compacted) + ? { "@context": context, ...compacted as Record } + : compacted; + const compactedTerms = getTopLevelTerms( + await jsonld.expand(compactedWithContext, { documentLoader }), + ); + const dummyPrefix = "urn:fedify:dummy:"; + const dummy: Record = { "@context": context }; + for (let i = 0; i < unmappedKeys.length; i++) { + defineJsonLdProperty(dummy, unmappedKeys[i], `${dummyPrefix}${i}`); + } + const expanded = await jsonld.expand(dummy, { documentLoader }); + const representedKeys = new Set(); + const nodes = Array.isArray(expanded) ? expanded : [expanded]; + for (const node of nodes) { + if (node == null || typeof node !== "object" || Array.isArray(node)) { + continue; + } + for (const [term, termValue] of globalThis.Object.entries(node)) { + if (!compactedTerms.has(term)) continue; + for (let i = 0; i < unmappedKeys.length; i++) { + if (containsValue(termValue, `${dummyPrefix}${i}`)) { + representedKeys.add(unmappedKeys[i]); + } + } + } + } + for (const key of unmappedKeys) { + if (!representedKeys.has(key)) { + defineJsonLdProperty( + result, + key, + (original as Record)[key], + ); + } + } + return result; +} + +function defineJsonLdProperty( + object: Record, + key: string, + value: unknown, +): void { + globalThis.Object.defineProperty(object, key, { + value, + enumerable: true, + configurable: true, + writable: true, + }); +} + +function containsValue(value: unknown, expected: string, depth = 0): boolean { + if (depth > 32) return false; + if (value === expected) return true; + if (Array.isArray(value)) { + return value.some((item) => containsValue(item, expected, depth + 1)); + } + if (value == null || typeof value !== "object") return false; + return globalThis.Object.entries(value).some(([key, item]) => + key !== "@context" && containsValue(item, expected, depth + 1) + ); +} + +async function preserveJsonLdShape( + compacted: unknown, + original: unknown, + context: unknown, + documentLoader?: DocumentLoader, + depth = 0, +): Promise { + if (depth > 32) return compacted; + if (compacted === original) return compacted; + if ( + original == null || typeof original !== "object" || + compacted == null || typeof compacted !== "object" + ) { + return compacted; + } + if (Array.isArray(original)) { + const compactedArray = Array.isArray(compacted) + ? compacted + : "@graph" in compacted && + Array.isArray((compacted as Record)["@graph"]) + ? (compacted as Record)["@graph"] as unknown[] + : undefined; + if (compactedArray == null) return compacted; + let clone: unknown[] | undefined; + for (let i = 0; i < compactedArray.length; i++) { + const value = await preserveJsonLdShape( + compactedArray[i], + original[i], + context, + documentLoader, + depth + 1, + ); + const originalContext = original[i] != null && + typeof original[i] === "object" && !Array.isArray(original[i]) && + "@context" in original[i] + ? (original[i] as Record)["@context"] + : undefined; + const shaped = originalContext !== undefined && + value != null && typeof value === "object" && + !Array.isArray(value) && !("@context" in value) + ? { "@context": originalContext, ...value as Record } + : value; + if (shaped !== compactedArray[i]) { + clone ??= compactedArray.slice(0, i); + clone.push(shaped); + } else if (clone != null) { + clone.push(compactedArray[i]); + } + } + return clone ?? (Array.isArray(compacted) ? compacted : compactedArray); + } + if (Array.isArray(compacted)) return compacted; + let clone: Record | undefined; + const ownContext = getOwnJsonLdContext(original); + const objectContext = combineContexts(context, ownContext); + const objectCompacted = depth > 0 && ownContext === null + ? await compactWithEmptyContext(compacted, context, documentLoader) + : compacted; + const compactedObject = depth > 0 + ? await mergeUnmappedTerms( + objectCompacted, + original, + objectContext, + documentLoader, + ) as Record + : objectCompacted as Record; + const originalObject = original as Record; + for (const key of globalThis.Object.keys(compactedObject)) { + if (key === "@context") continue; + const value = await preserveJsonLdShape( + compactedObject[key], + originalObject[key], + objectContext, + documentLoader, + depth + 1, + ); + const shaped = Array.isArray(originalObject[key]) && !Array.isArray(value) + ? [value] + : value; + if (shaped !== compactedObject[key]) { + clone ??= { ...compactedObject }; + defineJsonLdProperty(clone, key, shaped); + } + } + if (depth > 0) { + if ("@context" in originalObject && !("@context" in compactedObject)) { + clone ??= { ...compactedObject }; + clone["@context"] = originalObject["@context"]; + } + } + return clone ?? compactedObject; +} + +async function compactWithEmptyContext( + compacted: unknown, + context: unknown, + documentLoader?: DocumentLoader, +): Promise { + const compactedWithContext = compacted != null && + typeof compacted === "object" && !Array.isArray(compacted) && + !("@context" in compacted) + ? { "@context": context, ...compacted as Record } + : compacted; + const expanded = await jsonld.expand(compactedWithContext, { + documentLoader, + }); + return await jsonld.compact(expanded, {}, { documentLoader }); +} + +function combineContexts( + inheritedContext: unknown, + ownContext: unknown, +): unknown { + if (ownContext === noJsonLdContext || ownContext === inheritedContext) { + return inheritedContext; + } + if (ownContext == null) return ownContext; + const inherited = Array.isArray(inheritedContext) + ? inheritedContext + : [inheritedContext]; + const own = Array.isArray(ownContext) ? ownContext : [ownContext]; + return [...inherited, ...own]; +} diff --git a/packages/vocab-runtime/src/jsonld-cache.test.ts b/packages/vocab-runtime/src/jsonld-cache.test.ts new file mode 100644 index 000000000..6f95fde19 --- /dev/null +++ b/packages/vocab-runtime/src/jsonld-cache.test.ts @@ -0,0 +1,554 @@ +import { deepStrictEqual, ok, strictEqual } from "node:assert"; +import { test } from "node:test"; +import { + compactJsonLdCache, + getJsonLdContext, + isTrustedIriOrigin, + normalizeJsonLdIris, +} from "./internal/jsonld-cache.ts"; +import jsonld from "./jsonld.ts"; +import { parseIri } from "./url.ts"; + +test("isTrustedIriOrigin() trusts same portable IRI origins", () => { + ok(isTrustedIriOrigin( + {}, + parseIri("ap://did:key:z6Mkabc/actor"), + parseIri("ap+ef61://did:key:z6Mkabc/outbox"), + )); + ok( + !isTrustedIriOrigin( + {}, + parseIri("ap://did:key:z6Mkabc/actor"), + parseIri("ap://did:key:z6Mkdef/outbox"), + ), + ); + ok(isTrustedIriOrigin( + { crossOrigin: "trust" }, + parseIri("ap://did:key:z6Mkabc/actor"), + parseIri("ap://did:key:z6Mkdef/outbox"), + )); +}); + +test("normalizeJsonLdIris() normalizes selected JSON-LD IRI positions", () => { + const iriKeys = new Set(["@id", "https://example.com/ns#ref"]); + const value = { + "@id": "ap://did:key:z6Mkabc/object", + "https://example.com/ns#ref": [ + { "@value": "ap://did:key:z6Mkabc/ref" }, + ], + "https://example.com/ns#text": [ + { "@value": "ap://did:key:z6Mkabc/not-an-iri-position" }, + ], + }; + + deepStrictEqual(normalizeJsonLdIris(value, iriKeys), { + "@id": "ap+ef61://did:key:z6Mkabc/object", + "https://example.com/ns#ref": [ + { "@value": "ap+ef61://did:key:z6Mkabc/ref" }, + ], + "https://example.com/ns#text": [ + { "@value": "ap://did:key:z6Mkabc/not-an-iri-position" }, + ], + }); +}); + +test("normalizeJsonLdIris() preserves IRI context in list/set wrappers", () => { + const iriKeys = new Set(["https://example.com/ns#ref"]); + const value = { + "https://example.com/ns#ref": [ + { + "@list": [ + { "@value": "ap://did:key:z6Mkabc/listed" }, + ], + }, + { + "@set": [ + { "@value": "ap://did:key:z6Mkabc/set" }, + ], + }, + ], + }; + + deepStrictEqual(normalizeJsonLdIris(value, iriKeys), { + "https://example.com/ns#ref": [ + { + "@list": [ + { "@value": "ap+ef61://did:key:z6Mkabc/listed" }, + ], + }, + { + "@set": [ + { "@value": "ap+ef61://did:key:z6Mkabc/set" }, + ], + }, + ], + }); +}); + +test("normalizeJsonLdIris() defines prototype-like keys safely", () => { + const iriKeys = new Set(["__proto__"]); + const value: Record = {}; + globalThis.Object.defineProperty(value, "__proto__", { + value: "ap://did:key:z6Mkabc/object", + enumerable: true, + configurable: true, + writable: true, + }); + + const normalized = normalizeJsonLdIris(value, iriKeys) as Record< + string, + unknown + >; + + strictEqual( + globalThis.Object.getOwnPropertyDescriptor(normalized, "__proto__")?.value, + "ap+ef61://did:key:z6Mkabc/object", + ); + strictEqual(globalThis.Object.getPrototypeOf(normalized), Object.prototype); +}); + +test("getJsonLdContext() finds nested contexts", () => { + const context = { name: "https://example.com/ns#name" }; + deepStrictEqual( + getJsonLdContext([{ type: "Note" }, { "@context": context }]), + context, + ); +}); + +test("compactJsonLdCache() preserves no-context object shape", async () => { + const original = { + "@id": "ap://did:key:z6Mkabc/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { "@id": "ap://did:key:z6Mkabc/actor" }, + ], + "https://www.w3.org/ns/activitystreams#content": [ + { "@value": "No-context object shape should stay cached." }, + ], + }; + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris( + expanded, + new Set([ + "@id", + "https://www.w3.org/ns/activitystreams#attributedTo", + ]), + ); + + deepStrictEqual(await compactJsonLdCache(normalized, original), { + "@id": "ap+ef61://did:key:z6Mkabc/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { "@id": "ap+ef61://did:key:z6Mkabc/actor" }, + ], + "https://www.w3.org/ns/activitystreams#content": [ + { "@value": "No-context object shape should stay cached." }, + ], + }); +}); + +test("compactJsonLdCache() ignores nested contexts for no-context parents", async () => { + const nestedContext = { + type: "@type", + name: "https://www.w3.org/ns/activitystreams#name", + }; + const original = { + "@id": "ap://did:key:z6Mkabc/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attachment": [ + { + "@context": nestedContext, + type: "https://www.w3.org/ns/activitystreams#Object", + name: "Nested object", + }, + ], + }; + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris(expanded, new Set(["@id"])); + + deepStrictEqual(await compactJsonLdCache(normalized, original), { + "@id": "ap+ef61://did:key:z6Mkabc/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attachment": [ + { + "@context": nestedContext, + type: "https://www.w3.org/ns/activitystreams#Object", + name: "Nested object", + }, + ], + }); +}); + +test("compactJsonLdCache() defines no-context prototype-like keys safely", async () => { + const original: Record = { + "@id": "ap://did:key:z6Mkabc/objects/1", + }; + globalThis.Object.defineProperty(original, "__proto__", { + value: "ap://did:key:z6Mkabc/proto", + enumerable: true, + configurable: true, + writable: true, + }); + const normalized: Record = { + "@id": "ap+ef61://did:key:z6Mkabc/objects/1", + }; + globalThis.Object.defineProperty(normalized, "__proto__", { + value: "ap+ef61://did:key:z6Mkabc/proto", + enumerable: true, + configurable: true, + writable: true, + }); + + const compacted = await compactJsonLdCache([normalized], original) as Record< + string, + unknown + >; + + strictEqual( + globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__")?.value, + "ap+ef61://did:key:z6Mkabc/proto", + ); + strictEqual(globalThis.Object.getPrototypeOf(compacted), Object.prototype); +}); + +test("compactJsonLdCache() preserves nested unmapped terms", async () => { + const context = { + as: "https://www.w3.org/ns/activitystreams#", + id: "@id", + type: "@type", + attachment: { "@id": "as:attachment" }, + name: "as:name", + }; + const original = { + "@context": context, + type: "as:Note", + id: "ap://did:key:z6Mkabc/objects/1", + attachment: { + type: "as:Object", + name: "Attachment with an unmapped extension.", + extra: "This nested unmapped property should stay cached.", + }, + }; + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris(expanded, new Set(["@id"])); + + deepStrictEqual(await compactJsonLdCache(normalized, original), { + "@context": context, + type: "as:Note", + id: "ap+ef61://did:key:z6Mkabc/objects/1", + attachment: { + type: "as:Object", + name: "Attachment with an unmapped extension.", + extra: "This nested unmapped property should stay cached.", + }, + }); +}); + +test("compactJsonLdCache() reuses unchanged unmapped values", async () => { + const context = { + as: "https://www.w3.org/ns/activitystreams#", + id: "@id", + type: "@type", + attachment: { "@id": "as:attachment" }, + name: "as:name", + }; + const extra = { source: "unchanged nested extension" }; + const rootExtra = { source: "unchanged root extension" }; + const original = { + "@context": context, + type: "as:Note", + id: "ap://did:key:z6Mkabc/objects/1", + rootExtra, + attachment: { + type: "as:Object", + name: "Attachment with an unmapped extension.", + extra, + }, + }; + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris(expanded, new Set(["@id"])); + const compacted = await compactJsonLdCache(normalized, original) as { + rootExtra: unknown; + attachment: { extra: unknown }; + }; + + strictEqual(compacted.rootExtra, rootExtra); + strictEqual(compacted.attachment.extra, extra); +}); + +test("compactJsonLdCache() defines prototype-like unmapped keys safely", async () => { + const context = { + id: "@id", + type: "@type", + }; + const protoValue = { source: "own __proto__ extension" }; + const original: Record = { + "@context": context, + type: "https://example.com/ns#Object", + id: "ap://did:key:z6Mkabc/objects/1", + }; + globalThis.Object.defineProperty(original, "__proto__", { + value: protoValue, + enumerable: true, + configurable: true, + writable: true, + }); + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris(expanded, new Set(["@id"])); + const compacted = await compactJsonLdCache(normalized, original) as Record< + string, + unknown + >; + + strictEqual( + globalThis.Object.getOwnPropertyDescriptor(compacted, "__proto__")?.value, + protoValue, + ); + strictEqual(globalThis.Object.getPrototypeOf(compacted), Object.prototype); +}); + +test("compactJsonLdCache() checks prototype-like aliases safely", async () => { + const context: Record = { + ex: "https://example.com/ns#", + id: "@id", + represented: "ex:represented", + }; + globalThis.Object.defineProperty(context, "__proto__", { + value: "ex:represented", + enumerable: true, + configurable: true, + writable: true, + }); + const original: Record = { + "@context": context, + id: "ap://did:key:z6Mkabc/objects/1", + represented: "Compacted term already present.", + }; + globalThis.Object.defineProperty(original, "__proto__", { + value: "Alias represented by the compacted term.", + enumerable: true, + configurable: true, + writable: true, + }); + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris(expanded, new Set(["@id"])); + const compacted = await compactJsonLdCache(normalized, original) as Record< + string, + unknown + >; + + const protoDescriptor = globalThis.Object.getOwnPropertyDescriptor( + compacted, + "__proto__", + ); + ok( + protoDescriptor?.value === "Alias represented by the compacted term." || + Array.isArray(protoDescriptor?.value) && + protoDescriptor.value.includes( + "Alias represented by the compacted term.", + ), + ); + strictEqual(protoDescriptor?.enumerable, true); + strictEqual(compacted.id, "ap+ef61://did:key:z6Mkabc/objects/1"); + strictEqual( + globalThis.Object.getPrototypeOf(compacted), + Object.prototype, + ); +}); + +test("compactJsonLdCache() preserves nested contexts", async () => { + const context = { + as: "https://www.w3.org/ns/activitystreams#", + id: "@id", + type: "@type", + attachment: { "@id": "as:attachment" }, + name: "as:name", + }; + const nestedContext = { + id: "@id", + type: "@type", + title: "https://example.com/ns#title", + }; + const original = { + "@context": context, + type: "as:Note", + id: "ap://did:key:z6Mkabc/objects/1", + attachment: { + "@context": nestedContext, + type: "as:Object", + title: "Nested title.", + }, + }; + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris(expanded, new Set(["@id"])); + + deepStrictEqual(await compactJsonLdCache(normalized, original), { + "@context": context, + type: "as:Note", + id: "ap+ef61://did:key:z6Mkabc/objects/1", + attachment: { + "@context": nestedContext, + type: "as:Object", + "https://example.com/ns#title": "Nested title.", + }, + }); +}); + +test("compactJsonLdCache() preserves nested array contexts", async () => { + const context = { + as: "https://www.w3.org/ns/activitystreams#", + id: "@id", + type: "@type", + attachment: { "@id": "as:attachment" }, + }; + const nestedContext = [ + { + id: "@id", + type: "@type", + }, + { + title: "https://example.com/ns#title", + }, + ]; + const original = { + "@context": context, + type: "as:Note", + id: "ap://did:key:z6Mkabc/objects/1", + attachment: { + "@context": nestedContext, + type: "as:Object", + title: "Nested title.", + }, + }; + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris(expanded, new Set(["@id"])); + + deepStrictEqual(await compactJsonLdCache(normalized, original), { + "@context": context, + type: "as:Note", + id: "ap+ef61://did:key:z6Mkabc/objects/1", + attachment: { + "@context": nestedContext, + type: "as:Object", + "https://example.com/ns#title": "Nested title.", + }, + }); +}); + +test("compactJsonLdCache() preserves nested null contexts", async () => { + const context = { + as: "https://www.w3.org/ns/activitystreams#", + id: "@id", + type: "@type", + attachment: { "@id": "as:attachment" }, + title: "https://example.com/ns#title", + }; + const original = { + "@context": context, + type: "as:Note", + id: "ap://did:key:z6Mkabc/objects/1", + attachment: { + "@context": null, + "https://example.com/ns#title": "Absolute title.", + }, + }; + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris(expanded, new Set(["@id"])); + + deepStrictEqual(await compactJsonLdCache(normalized, original), { + "@context": context, + type: "as:Note", + id: "ap+ef61://did:key:z6Mkabc/objects/1", + attachment: { + "@context": null, + "https://example.com/ns#title": "Absolute title.", + }, + }); +}); + +test("compactJsonLdCache() does not re-add represented nested aliases", async () => { + const context = { + as: "https://www.w3.org/ns/activitystreams#", + id: "@id", + type: "@type", + attachment: { "@id": "as:attachment" }, + actor: { "@id": "as:actor", "@type": "@id" }, + }; + const nestedContext = { + id: "@id", + type: "@type", + actorRef: { "@id": "as:actor", "@type": "@id" }, + }; + const original = { + "@context": context, + type: "as:Note", + id: "ap://did:key:z6Mkabc/objects/1", + attachment: { + "@context": nestedContext, + type: "as:Object", + actorRef: "ap://did:key:z6Mkabc/actor", + }, + }; + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris( + expanded, + new Set(["@id", "https://www.w3.org/ns/activitystreams#actor"]), + ); + + deepStrictEqual(await compactJsonLdCache(normalized, original), { + "@context": context, + type: "as:Note", + id: "ap+ef61://did:key:z6Mkabc/objects/1", + attachment: { + "@context": nestedContext, + type: "as:Object", + actor: "ap+ef61://did:key:z6Mkabc/actor", + }, + }); +}); + +test("compactJsonLdCache() does not confuse dummy marker prefixes", async () => { + const context = { + ex: "https://example.com/ns#", + id: "@id", + represented: "ex:represented", + key10: "ex:represented", + }; + const original = { + "@context": context, + id: "ap://did:key:z6Mkabc/objects/1", + represented: "Compacted term already present.", + key0: "Extension 0", + key1: "Extension 1", + key2: "Extension 2", + key3: "Extension 3", + key4: "Extension 4", + key5: "Extension 5", + key6: "Extension 6", + key7: "Extension 7", + key8: "Extension 8", + key9: "Extension 9", + key10: "Alias represented by the compacted term.", + }; + const expanded = await jsonld.expand(original); + const normalized = normalizeJsonLdIris(expanded, new Set(["@id"])); + + deepStrictEqual(await compactJsonLdCache(normalized, original), { + "@context": context, + id: "ap+ef61://did:key:z6Mkabc/objects/1", + key0: "Extension 0", + key1: "Extension 1", + key2: "Extension 2", + key3: "Extension 3", + key4: "Extension 4", + key5: "Extension 5", + key6: "Extension 6", + key7: "Extension 7", + key8: "Extension 8", + key9: "Extension 9", + key10: [ + "Alias represented by the compacted term.", + "Compacted term already present.", + ], + }); +}); diff --git a/packages/vocab-runtime/src/mod.ts b/packages/vocab-runtime/src/mod.ts index 9e7967c9e..5208edfde 100644 --- a/packages/vocab-runtime/src/mod.ts +++ b/packages/vocab-runtime/src/mod.ts @@ -51,8 +51,12 @@ export { } from "./preprocessor.ts"; export { expandIPv6Address, + formatIri, + haveSameIriOrigin, isValidPublicIPv4Address, isValidPublicIPv6Address, + parseIri, + parseJsonLdId, UrlError, validatePublicUrl, } from "./url.ts"; diff --git a/packages/vocab-runtime/src/url.test.ts b/packages/vocab-runtime/src/url.test.ts index 35aad4658..84c421e9d 100644 --- a/packages/vocab-runtime/src/url.test.ts +++ b/packages/vocab-runtime/src/url.test.ts @@ -1,13 +1,264 @@ -import { deepStrictEqual, ok, rejects } from "node:assert"; +import { deepStrictEqual, ok, rejects, throws } from "node:assert"; import { test } from "node:test"; import { expandIPv6Address, + formatIri, + haveSameIriOrigin, isValidPublicIPv4Address, isValidPublicIPv6Address, + parseIri, + parseJsonLdId, UrlError, validatePublicUrl, } from "./url.ts"; +test("parseIri() accepts portable ActivityPub URI schemes", () => { + const cases = [ + "ap://did:key:z6Mkabc/actor", + "ap://did%3Akey%3Az6Mkabc/actor", + "ap+ef61://did:key:z6Mkabc/actor", + "ap+ef61://did%3Akey%3Az6Mkabc/actor", + "AP+EF61://did:key:z6Mkabc/actor", + ]; + for (const iri of cases) { + deepStrictEqual( + parseIri(iri), + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"), + ); + } +}); + +test("parseIri() accepts DID schemes case-insensitively", () => { + const cases = [ + "ap://DID:key:z6Mkabc/actor", + "ap://DID%3Akey%3Az6Mkabc/actor", + ]; + for (const iri of cases) { + deepStrictEqual( + parseIri(iri), + new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"), + ); + } +}); + +test("parseIri() accepts DID method names that start with digits", () => { + deepStrictEqual( + parseIri("ap://did:3:abc/actor"), + new URL("ap+ef61://did%3A3%3Aabc/actor"), + ); +}); + +test("parseIri() accepts hyphens in DID method-specific IDs", () => { + deepStrictEqual( + parseIri("ap+ef61://did:web:foo-bar.example/actor"), + new URL("ap+ef61://did%3Aweb%3Afoo-bar.example/actor"), + ); +}); + +test("parseIri() preserves existing URL parsing behavior", () => { + deepStrictEqual( + parseIri("/actor", new URL("https://example.com/users/alice")), + new URL("https://example.com/actor"), + ); + deepStrictEqual( + parseIri("at://did:plc:example/record"), + new URL("at://did%3Aplc%3Aexample/record"), + ); + throws(() => parseIri("ap://not-a-did/actor"), TypeError); +}); + +test("parseJsonLdId() parses JSON-LD ids", () => { + deepStrictEqual(parseJsonLdId(undefined), undefined); + deepStrictEqual(parseJsonLdId("_:blank"), undefined); + deepStrictEqual( + parseJsonLdId("/actor", new URL("https://example.com/users/alice")), + new URL("https://example.com/actor"), + ); + deepStrictEqual( + parseJsonLdId("ap://did:key:z6Mkabc/actor"), + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"), + ); + throws(() => parseJsonLdId("/actor"), { + name: "TypeError", + message: "Invalid @id: /actor", + }); +}); + +test("parseIri() resolves relative IRIs against portable string bases", () => { + deepStrictEqual( + parseIri("/actor", "ap://did:key:z6Mkabc/objects/1"), + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"), + ); + deepStrictEqual( + parseIri("attachments/1", "ap://did:key:z6Mkabc/objects/1"), + new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/attachments/1"), + ); + throws( + () => parseIri("//example.com/outbox", "ap://did:key:z6Mkabc/objects/1"), + TypeError, + ); +}); + +test("parseIri() resolves relative IRIs against at:// string bases", () => { + deepStrictEqual( + parseIri("/record", "at://did:plc:example/collection/item"), + new URL("at://did%3Aplc%3Aexample/record"), + ); + deepStrictEqual( + parseIri("reply", "at://did:plc:example/collection/item"), + new URL("at://did%3Aplc%3Aexample/collection/reply"), + ); + deepStrictEqual( + parseIri("reply", "at://did%3Aplc%3Aexample/collection/item"), + new URL("at://did%3Aplc%3Aexample/collection/reply"), + ); +}); + +test("parseIri() rejects portable IRIs without paths", () => { + throws(() => parseIri("ap://did:key:z6Mkabc"), TypeError); + throws( + () => + parseIri("ap://did:key:z6Mkabc?gateways=https%3A%2F%2Fserver.example"), + TypeError, + ); + throws(() => parseIri("ap://did:key:z6Mkabc#actor"), TypeError); +}); + +test("parseIri() rejects malformed portable DID authorities", () => { + const cases = [ + "ap://did:/actor", + "ap://did:key/actor", + "ap://did%3Akey%3Aabc%25zz/actor", + "ap://did:key:abc%25zz/actor", + ]; + for (const iri of cases) { + throws(() => parseIri(iri), TypeError); + } +}); + +test("haveSameIriOrigin() compares portable IRI authorities", () => { + ok(haveSameIriOrigin( + parseIri("ap://did:key:z6Mkabc/actor"), + parseIri("ap://did:key:z6Mkabc/outbox"), + )); + ok(haveSameIriOrigin( + new URL("ap://did%3Akey%3Az6Mkabc/actor"), + new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox"), + )); + ok(haveSameIriOrigin( + parseIri("ap://DID:key:z6Mkabc/actor"), + parseIri("ap://did:key:z6Mkabc/outbox"), + )); + ok(haveSameIriOrigin( + new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"), + new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox"), + )); + ok( + !haveSameIriOrigin( + parseIri("ap://did:key:z6Mkabc/actor"), + parseIri("ap://did:key:z6Mkdef/actor"), + ), + ); +}); + +test("parseIri() normalizes portable URL instances", () => { + deepStrictEqual( + parseIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), + new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"), + ); + throws(() => parseIri("ap+ef61://not-a-did/actor"), TypeError); +}); + +test("formatIri() emits canonical portable ActivityPub URI syntax", () => { + const cases = [ + new URL("ap://did%3Akey%3Az6Mkabc/actor"), + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"), + ]; + for (const iri of cases) { + deepStrictEqual(formatIri(iri), "ap+ef61://did:key:z6Mkabc/actor"); + } + deepStrictEqual( + formatIri(new URL("https://example.com/actor")), + "https://example.com/actor", + ); + deepStrictEqual(formatIri("/actor"), "/actor"); +}); + +test("formatIri() preserves DID authority pct-encoded delimiters", () => { + const parsed = parseIri("ap://did:example:abc%2Fdef/actor"); + deepStrictEqual( + parsed, + new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"), + ); + deepStrictEqual( + formatIri(parsed), + "ap+ef61://did:example:abc%2Fdef/actor", + ); + deepStrictEqual( + parseIri(formatIri(parsed)), + parsed, + ); + deepStrictEqual( + formatIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), + "ap+ef61://did:example:abc%2Fdef/actor", + ); +}); + +test("parseIri() normalizes equivalent encoded DID authorities", () => { + deepStrictEqual( + parseIri("ap://did:example:abc%252Fdef/actor"), + parseIri("ap://did%3Aexample%3Aabc%252Fdef/actor"), + ); +}); + +test("formatIri() preserves DID-internal pct-encoded authority characters", () => { + const parsed = parseIri("ap://did:web:example.com%3A3000/actor"); + deepStrictEqual( + parsed, + new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/actor"), + ); + deepStrictEqual( + formatIri(parsed), + "ap+ef61://did:web:example.com%3A3000/actor", + ); +}); + +test("parseIri() accepts portable DID URLs with encoded DID delimiters", () => { + const parsed = parseIri("ap://did:web:example.com%3A3000/u/1"); + deepStrictEqual( + parsed, + new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"), + ); + deepStrictEqual( + formatIri(parsed), + "ap+ef61://did:web:example.com%3A3000/u/1", + ); +}); + +test("parseIri() decodes pct-encoded DID delimiters in order", () => { + const parsed = parseIri("ap://did%3Aweb%3Aexample.com%253A3000/u/1"); + deepStrictEqual( + parsed, + new URL("ap+ef61://did%3Aweb%3Aexample.com%253A3000/u/1"), + ); + deepStrictEqual( + formatIri(parsed), + "ap+ef61://did:web:example.com%3A3000/u/1", + ); +}); + +test("parseIri() preserves encoded percent signs while decoding delimiters", () => { + const parsed = parseIri("ap://did%3Aweb%3Aexample.com%2500/u/1"); + deepStrictEqual( + parsed, + new URL("ap+ef61://did%3Aweb%3Aexample.com%2500/u/1"), + ); + deepStrictEqual( + formatIri(parsed), + "ap+ef61://did:web:example.com%00/u/1", + ); +}); + test("validatePublicUrl()", async () => { await rejects(() => validatePublicUrl("ftp://localhost"), UrlError); await rejects( diff --git a/packages/vocab-runtime/src/url.ts b/packages/vocab-runtime/src/url.ts index 0274e669f..4211b67ef 100644 --- a/packages/vocab-runtime/src/url.ts +++ b/packages/vocab-runtime/src/url.ts @@ -9,6 +9,147 @@ export class UrlError extends Error { } } +const PORTABLE_IRI_PATTERN = + /^(ap|ap\+ef61):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i; +const INVALID_PERCENT_ENCODING_PATTERN = /%(?![0-9A-Fa-f]{2})/; +const DID_SCHEME_PATTERN = /^did:/i; +const DID_PATTERN = /^did:[a-z0-9]+:[-A-Za-z0-9._%]+(?::[-A-Za-z0-9._%]+)*$/i; + +/** + * Parses a JSON-LD `@id` value as an IRI. + */ +export function parseJsonLdId( + id: string | undefined, + base?: string | URL, +): URL | undefined { + if (id == null || id.startsWith("_:")) return undefined; + try { + return parseIri(id, base); + } catch { + throw new TypeError("Invalid @id: " + id); + } +} + +/** + * Parses an IRI as a URL, including FEP-ef61 portable ActivityPub IRIs. + */ +export function parseIri(iri: string | URL, base?: string | URL): URL { + if (iri instanceof URL) { + return normalizePortableUrl(iri) ?? new URL(iri.href); + } + const portable = parsePortableIri(iri); + if (portable != null) return portable; + base = normalizeBaseIri(base); + if (!URL.canParse(iri, base) && iri.startsWith("at://")) { + return parseAtUri(iri); + } + const parsed = new URL(iri, base); + return normalizePortableUrl(parsed) ?? parsed; +} + +/** + * Formats a URL as an IRI, including FEP-ef61 portable ActivityPub IRIs. + */ +export function formatIri(iri: string | URL): string { + const parsed = parsePortableIri(iri instanceof URL ? iri.href : iri); + if (parsed == null) { + return iri instanceof URL + ? iri.href + : URL.canParse(iri) + ? new URL(iri).href + : iri; + } + const authority = decodePortableAuthority(parsed.host); + return `ap+ef61://${authority}${parsed.pathname}${parsed.search}${parsed.hash}`; +} + +/** + * Checks whether two IRIs have the same origin. + */ +export function haveSameIriOrigin(left: URL, right: URL): boolean { + return getComparableIriOrigin(left) === getComparableIriOrigin(right); +} + +function getComparableIriOrigin(iri: URL): string { + iri = normalizePortableUrl(iri) ?? iri; + if (iri.origin !== "null") return iri.origin; + if (iri.host !== "") { + const host = iri.protocol === "ap+ef61:" + ? encodeURIComponent( + decodePortableAuthority(iri.host).replace(DID_SCHEME_PATTERN, "did:"), + ) + : iri.host; + return `${iri.protocol}//${host}`; + } + return iri.href; +} + +function parsePortableIri(iri: string): URL | null { + const match = iri.match(PORTABLE_IRI_PATTERN); + if (match == null) return null; + // The readable ap://did:... authority form is not RFC 3986 compliant: + // colons are not valid in a URI reg-name authority. Keep accepting it for + // current FEP-ef61 interoperability, but normalize it to a percent-encoded + // URL authority internally. The ap: URI syntax may change later; see: + // https://bnewbold.leaflet.pub/3mph4hzvbdc2v + const authority = decodePortableAuthority(match[2]); + if (!DID_PATTERN.test(authority)) { + throw new TypeError("Invalid portable ActivityPub IRI authority."); + } + if (match[3] === "") { + throw new TypeError("Invalid portable ActivityPub IRI path."); + } + return new URL( + `ap+ef61://${encodeURIComponent(authority)}${match[3]}${match[4] ?? ""}${ + match[5] ?? "" + }`, + ); +} + +function normalizePortableUrl(iri: URL): URL | null { + if (iri.protocol !== "ap:" && iri.protocol !== "ap+ef61:") return null; + return parsePortableIri( + `ap+ef61://${iri.host}${iri.pathname}${iri.search}${iri.hash}`, + ); +} + +function normalizeBaseIri(base?: string | URL): string | URL | undefined { + if (base == null) return undefined; + if (base instanceof URL) return normalizePortableUrl(base) ?? base; + return parsePortableIri(base) ?? + (base.startsWith("at://") && !URL.canParse(".", base) + ? parseAtUri(base) + : base); +} + +function decodePortableAuthority(authority: string): string { + if (INVALID_PERCENT_ENCODING_PATTERN.test(authority)) { + throw new TypeError("Invalid portable ActivityPub IRI authority."); + } + if (DID_SCHEME_PATTERN.test(authority)) { + const decoded = authority.replace(/%25/gi, "%"); + if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) { + throw new TypeError("Invalid portable ActivityPub IRI authority."); + } + return decoded; + } + const decoded = authority.replace( + /%(25|3A)/gi, + (match) => match.toLowerCase() === "%3a" ? ":" : "%", + ); + if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) { + throw new TypeError("Invalid portable ActivityPub IRI authority."); + } + return decoded; +} + +function parseAtUri(uri: string): URL { + const index = uri.indexOf("/", 5); + const authority = index >= 0 ? uri.slice(5, index) : uri.slice(5); + const path = index >= 0 ? uri.slice(index) : ""; + return new URL("at://" + encodeURIComponent(authority) + path); +} + /** * Validates a URL to prevent SSRF attacks. */ diff --git a/packages/vocab-runtime/tsdown.config.ts b/packages/vocab-runtime/tsdown.config.ts index 3726e6eda..4e23314be 100644 --- a/packages/vocab-runtime/tsdown.config.ts +++ b/packages/vocab-runtime/tsdown.config.ts @@ -4,7 +4,12 @@ import { defineConfig } from "tsdown"; export default [ defineConfig({ - entry: ["src/mod.ts", "src/jsonld.ts", "src/temporal.ts"], + entry: [ + "src/mod.ts", + "src/internal/jsonld-cache.ts", + "src/jsonld.ts", + "src/temporal.ts", + ], dts: { compilerOptions: { isolatedDeclarations: true, declaration: true } }, format: ["esm", "cjs"], platform: "neutral", diff --git a/packages/vocab-tools/src/__snapshots__/class.test.ts.deno.snap b/packages/vocab-tools/src/__snapshots__/class.test.ts.deno.snap index 3a126114c..054901727 100644 --- a/packages/vocab-tools/src/__snapshots__/class.test.ts.deno.snap +++ b/packages/vocab-tools/src/__snapshots__/class.test.ts.deno.snap @@ -14,19 +14,29 @@ import { encodeMultibase, exportMultibaseKey, exportSpki, + formatIri, getDocumentLoader, importMultibaseKey, importPem, isDecimal, LanguageString, parseDecimal, + parseIri, + parseJsonLdId, type RemoteDocument } from \\"@fedify/vocab-runtime\\"; +import { + compactJsonLdCache, + getJsonLdContext, + isTrustedIriOrigin, + normalizeJsonLdIris +} from \\"@fedify/vocab-runtime/internal/jsonld-cache\\"; import { isTemporalDuration, isTemporalInstant, } from \\"@fedify/vocab-runtime/temporal\\"; - +const PORTABLE_IRI_PATTERN = /^ap(?:\\\\+ef61)?:\\\\/\\\\//i; +const PORTABLE_IRI_KEYS: ReadonlySet = new Set([\\"@id\\",\\"_misskey_quote\\",\\"actor\\",\\"alsoKnownAs\\",\\"announceAuthorization\\",\\"anyOf\\",\\"approvedBy\\",\\"assertionMethod\\",\\"attachment\\",\\"attributedTo\\",\\"audience\\",\\"automaticApproval\\",\\"bcc\\",\\"bto\\",\\"cc\\",\\"context\\",\\"controller\\",\\"current\\",\\"describes\\",\\"emojiReactions\\",\\"featured\\",\\"featuredTags\\",\\"first\\",\\"followers\\",\\"followersOf\\",\\"following\\",\\"followingOf\\",\\"generator\\",\\"href\\",\\"http://fedibird.com/ns#emojiReactions\\",\\"http://fedibird.com/ns#quoteUri\\",\\"http://joinmastodon.org/ns#featured\\",\\"http://joinmastodon.org/ns#featuredTags\\",\\"http://www.w3.org/ns/ldp#inbox\\",\\"https://gotosocial.org/ns#announceAuthorization\\",\\"https://gotosocial.org/ns#approvedBy\\",\\"https://gotosocial.org/ns#automaticApproval\\",\\"https://gotosocial.org/ns#interactingObject\\",\\"https://gotosocial.org/ns#interactionTarget\\",\\"https://gotosocial.org/ns#likeAuthorization\\",\\"https://gotosocial.org/ns#manualApproval\\",\\"https://gotosocial.org/ns#replyAuthorization\\",\\"https://misskey-hub.net/ns#_misskey_quote\\",\\"https://w3id.org/fep/044f#quote\\",\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"https://w3id.org/fep/5711#followersOf\\",\\"https://w3id.org/fep/5711#followingOf\\",\\"https://w3id.org/fep/5711#inboxOf\\",\\"https://w3id.org/fep/5711#likedOf\\",\\"https://w3id.org/fep/5711#likesOf\\",\\"https://w3id.org/fep/5711#outboxOf\\",\\"https://w3id.org/fep/5711#repliesOf\\",\\"https://w3id.org/fep/5711#sharesOf\\",\\"https://w3id.org/security#assertionMethod\\",\\"https://w3id.org/security#controller\\",\\"https://w3id.org/security#owner\\",\\"https://w3id.org/security#proof\\",\\"https://w3id.org/security#publicKey\\",\\"https://w3id.org/security#verificationMethod\\",\\"https://w3id.org/valueflows/ont/vf#resourceConformsTo\\",\\"https://w3id.org/valueflows/ont/vf#satisfies\\",\\"https://www.w3.org/ns/activitystreams#actor\\",\\"https://www.w3.org/ns/activitystreams#alsoKnownAs\\",\\"https://www.w3.org/ns/activitystreams#anyOf\\",\\"https://www.w3.org/ns/activitystreams#attachment\\",\\"https://www.w3.org/ns/activitystreams#attributedTo\\",\\"https://www.w3.org/ns/activitystreams#audience\\",\\"https://www.w3.org/ns/activitystreams#bcc\\",\\"https://www.w3.org/ns/activitystreams#bto\\",\\"https://www.w3.org/ns/activitystreams#cc\\",\\"https://www.w3.org/ns/activitystreams#context\\",\\"https://www.w3.org/ns/activitystreams#current\\",\\"https://www.w3.org/ns/activitystreams#describes\\",\\"https://www.w3.org/ns/activitystreams#first\\",\\"https://www.w3.org/ns/activitystreams#followers\\",\\"https://www.w3.org/ns/activitystreams#following\\",\\"https://www.w3.org/ns/activitystreams#generator\\",\\"https://www.w3.org/ns/activitystreams#href\\",\\"https://www.w3.org/ns/activitystreams#icon\\",\\"https://www.w3.org/ns/activitystreams#image\\",\\"https://www.w3.org/ns/activitystreams#inReplyTo\\",\\"https://www.w3.org/ns/activitystreams#instrument\\",\\"https://www.w3.org/ns/activitystreams#items\\",\\"https://www.w3.org/ns/activitystreams#last\\",\\"https://www.w3.org/ns/activitystreams#liked\\",\\"https://www.w3.org/ns/activitystreams#likes\\",\\"https://www.w3.org/ns/activitystreams#location\\",\\"https://www.w3.org/ns/activitystreams#movedTo\\",\\"https://www.w3.org/ns/activitystreams#next\\",\\"https://www.w3.org/ns/activitystreams#oauthAuthorizationEndpoint\\",\\"https://www.w3.org/ns/activitystreams#oauthTokenEndpoint\\",\\"https://www.w3.org/ns/activitystreams#object\\",\\"https://www.w3.org/ns/activitystreams#oneOf\\",\\"https://www.w3.org/ns/activitystreams#origin\\",\\"https://www.w3.org/ns/activitystreams#outbox\\",\\"https://www.w3.org/ns/activitystreams#partOf\\",\\"https://www.w3.org/ns/activitystreams#prev\\",\\"https://www.w3.org/ns/activitystreams#preview\\",\\"https://www.w3.org/ns/activitystreams#provideClientKey\\",\\"https://www.w3.org/ns/activitystreams#proxyUrl\\",\\"https://www.w3.org/ns/activitystreams#quoteUrl\\",\\"https://www.w3.org/ns/activitystreams#relationship\\",\\"https://www.w3.org/ns/activitystreams#replies\\",\\"https://www.w3.org/ns/activitystreams#result\\",\\"https://www.w3.org/ns/activitystreams#sharedInbox\\",\\"https://www.w3.org/ns/activitystreams#shares\\",\\"https://www.w3.org/ns/activitystreams#signClientKey\\",\\"https://www.w3.org/ns/activitystreams#streams\\",\\"https://www.w3.org/ns/activitystreams#subject\\",\\"https://www.w3.org/ns/activitystreams#tag\\",\\"https://www.w3.org/ns/activitystreams#target\\",\\"https://www.w3.org/ns/activitystreams#to\\",\\"https://www.w3.org/ns/activitystreams#units\\",\\"https://www.w3.org/ns/activitystreams#url\\",\\"https://www.w3.org/ns/did#service\\",\\"https://www.w3.org/ns/did#serviceEndpoint\\",\\"icon\\",\\"id\\",\\"image\\",\\"inReplyTo\\",\\"inbox\\",\\"inboxOf\\",\\"instrument\\",\\"interactingObject\\",\\"interactionTarget\\",\\"items\\",\\"last\\",\\"likeAuthorization\\",\\"liked\\",\\"likedOf\\",\\"likes\\",\\"likesOf\\",\\"location\\",\\"manualApproval\\",\\"movedTo\\",\\"next\\",\\"oauthAuthorizationEndpoint\\",\\"oauthTokenEndpoint\\",\\"object\\",\\"oneOf\\",\\"orderedItems\\",\\"origin\\",\\"outbox\\",\\"outboxOf\\",\\"owner\\",\\"partOf\\",\\"prev\\",\\"preview\\",\\"proof\\",\\"provideClientKey\\",\\"proxyUrl\\",\\"publicKey\\",\\"quote\\",\\"quoteAuthorization\\",\\"quoteUri\\",\\"quoteUrl\\",\\"relationship\\",\\"replies\\",\\"repliesOf\\",\\"replyAuthorization\\",\\"resourceConformsTo\\",\\"result\\",\\"satisfies\\",\\"service\\",\\"sharedInbox\\",\\"shares\\",\\"sharesOf\\",\\"signClientKey\\",\\"streams\\",\\"subject\\",\\"tag\\",\\"target\\",\\"to\\",\\"units\\",\\"url\\"]); import * as _ppM0 from \\"./preprocessors.ts\\"; @@ -2157,9 +2167,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -2169,21 +2180,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#attachment_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -2212,7 +2222,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -2317,8 +2327,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_49BipA5dq9eoH8LX8xdsVumveTca_attachment.has(i)) { v = v.id; } @@ -2358,9 +2369,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_49BipA5dq9eoH8LX8xdsVumveTca_attachment.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_49BipA5dq9eoH8LX8xdsVumveTca_attachment.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -2405,9 +2416,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -2417,21 +2429,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#attribution_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -2460,7 +2471,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -2583,8 +2594,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.length < 1) return null; let v = this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(0)) { v = v.id; } @@ -2623,8 +2635,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -2689,8 +2701,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(i)) { v = v.id; } @@ -2730,9 +2743,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -2777,9 +2790,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -2789,21 +2803,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#audience_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -2832,7 +2845,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -2918,8 +2931,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.length < 1) return null; let v = this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(0)) { v = v.id; } @@ -2958,8 +2972,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -3023,8 +3037,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(i)) { v = v.id; } @@ -3064,9 +3079,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -3140,9 +3155,10 @@ get contents(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -3152,21 +3168,20 @@ get contents(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#context_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -3195,7 +3210,7 @@ get contents(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -3295,8 +3310,9 @@ get contents(): ((string | LanguageString))[] { const vs = this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3mhZzGXSpQ431mBSz2kvych22v4e_context.has(i)) { v = v.id; } @@ -3336,9 +3352,9 @@ get contents(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3mhZzGXSpQ431mBSz2kvych22v4e_context.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3mhZzGXSpQ431mBSz2kvych22v4e_context.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -3425,9 +3441,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -3437,21 +3454,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#generator_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -3480,7 +3496,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -3574,8 +3590,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_86xFhmgBapoMvYqjbjRuDPayTrS_generator.has(i)) { v = v.id; } @@ -3615,9 +3632,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_86xFhmgBapoMvYqjbjRuDPayTrS_generator.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_86xFhmgBapoMvYqjbjRuDPayTrS_generator.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -3662,9 +3679,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -3674,21 +3692,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#icon_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -3717,7 +3734,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -3825,8 +3842,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.length < 1) return null; let v = this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(0)) { v = v.id; } @@ -3865,8 +3883,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -3931,8 +3949,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(i)) { v = v.id; } @@ -3972,9 +3991,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -4019,9 +4038,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -4031,21 +4051,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#image_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -4074,7 +4093,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -4182,8 +4201,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.length < 1) return null; let v = this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(0)) { v = v.id; } @@ -4222,8 +4242,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -4288,8 +4308,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(i)) { v = v.id; } @@ -4329,9 +4350,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -4376,9 +4397,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -4388,21 +4410,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#replyTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -4431,7 +4452,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -4526,8 +4547,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.length < 1) return null; let v = this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(0)) { v = v.id; } @@ -4566,8 +4588,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -4631,8 +4653,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(i)) { v = v.id; } @@ -4672,9 +4695,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -4719,9 +4742,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -4731,21 +4755,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#location_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -4774,7 +4797,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -4869,8 +4892,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.length < 1) return null; let v = this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(0)) { v = v.id; } @@ -4909,8 +4933,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -4974,8 +4998,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(i)) { v = v.id; } @@ -5015,9 +5040,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -5062,9 +5087,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5074,21 +5100,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#preview_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -5117,7 +5142,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -5211,8 +5236,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview.length < 1) return null; let v = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { v = v.id; } @@ -5251,8 +5277,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -5315,8 +5341,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { v = v.id; } @@ -5356,9 +5383,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -5416,9 +5443,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5428,21 +5456,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#replies_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -5471,7 +5498,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -5557,8 +5584,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_7UpwM3JWcXhADcscukEehBorf6k_replies.length < 1) return null; let v = this.#_7UpwM3JWcXhADcscukEehBorf6k_replies[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_7UpwM3JWcXhADcscukEehBorf6k_replies.has(0)) { v = v.id; } @@ -5597,8 +5625,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_7UpwM3JWcXhADcscukEehBorf6k_replies.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -5643,9 +5671,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5655,21 +5684,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#shares_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -5698,7 +5726,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -5790,8 +5818,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares.length < 1) return null; let v = this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3kAfck9PcEYt2L7xug5y99YPbANs_shares.has(0)) { v = v.id; } @@ -5830,8 +5859,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3kAfck9PcEYt2L7xug5y99YPbANs_shares.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -5876,9 +5905,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5888,21 +5918,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likes_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -5931,7 +5960,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6023,8 +6052,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.length < 1) return null; let v = this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.has(0)) { v = v.id; } @@ -6063,8 +6093,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -6109,9 +6139,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6121,21 +6152,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#emojiReactions_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -6164,7 +6194,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6250,8 +6280,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.length < 1) return null; let v = this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.has(0)) { v = v.id; } @@ -6290,8 +6321,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -6376,9 +6407,10 @@ get summaries(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6388,21 +6420,20 @@ get summaries(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#tag_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -6431,7 +6462,7 @@ get summaries(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6528,8 +6559,9 @@ get summaries(): ((string | LanguageString))[] { const vs = this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_5chuqj6s95p5gg2sk1HntGfarRf_tag.has(i)) { v = v.id; } @@ -6569,9 +6601,9 @@ get summaries(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_5chuqj6s95p5gg2sk1HntGfarRf_tag.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_5chuqj6s95p5gg2sk1HntGfarRf_tag.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -6650,9 +6682,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6662,21 +6695,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#to_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -6705,7 +6737,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6791,8 +6823,9 @@ get urls(): ((URL | Link))[] { } if (this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.length < 1) return null; let v = this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(0)) { v = v.id; } @@ -6831,8 +6864,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -6896,8 +6929,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(i)) { v = v.id; } @@ -6937,9 +6971,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -6984,9 +7018,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6996,21 +7031,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#bto_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -7039,7 +7073,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -7125,8 +7159,9 @@ get urls(): ((URL | Link))[] { } if (this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.length < 1) return null; let v = this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(0)) { v = v.id; } @@ -7165,8 +7200,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -7230,8 +7265,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(i)) { v = v.id; } @@ -7271,9 +7307,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -7318,9 +7354,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -7330,21 +7367,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#cc_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -7373,7 +7409,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -7459,8 +7495,9 @@ get urls(): ((URL | Link))[] { } if (this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.length < 1) return null; let v = this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(0)) { v = v.id; } @@ -7499,8 +7536,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -7564,8 +7601,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(i)) { v = v.id; } @@ -7605,9 +7643,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -7652,9 +7690,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -7664,21 +7703,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#bcc_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -7707,7 +7745,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -7793,8 +7831,9 @@ get urls(): ((URL | Link))[] { } if (this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.length < 1) return null; let v = this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(0)) { v = v.id; } @@ -7833,8 +7872,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -7898,8 +7937,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(i)) { v = v.id; } @@ -7939,9 +7979,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -8050,9 +8090,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8062,21 +8103,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#proof_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -8105,7 +8145,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -8190,8 +8230,9 @@ get urls(): ((URL | Link))[] { } if (this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.length < 1) return null; let v = this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(0)) { v = v.id; } @@ -8230,8 +8271,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -8294,8 +8335,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(i)) { v = v.id; } @@ -8335,9 +8377,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -8421,9 +8463,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8433,21 +8476,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likeAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -8476,7 +8518,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -8562,8 +8604,9 @@ get urls(): ((URL | Link))[] { } if (this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.length < 1) return null; let v = this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.has(0)) { v = v.id; } @@ -8602,8 +8645,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -8648,9 +8691,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8660,21 +8704,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#replyAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -8703,7 +8746,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -8789,8 +8832,9 @@ get urls(): ((URL | Link))[] { } if (this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.length < 1) return null; let v = this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.has(0)) { v = v.id; } @@ -8829,8 +8873,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -8875,9 +8919,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8887,21 +8932,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#announceAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -8930,7 +8974,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -9016,8 +9060,9 @@ get urls(): ((URL | Link))[] { } if (this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.length < 1) return null; let v = this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.has(0)) { v = v.id; } @@ -9056,8 +9101,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -9118,7 +9163,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9146,7 +9191,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9182,7 +9227,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9221,7 +9266,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9280,7 +9325,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9304,7 +9349,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9324,7 +9369,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9344,7 +9389,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9368,7 +9413,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9392,7 +9437,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const item = ( - v instanceof URL ? v.href : v instanceof Link ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Link ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9432,7 +9477,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_7UpwM3JWcXhADcscukEehBorf6k_replies) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9452,7 +9497,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9472,7 +9517,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9492,7 +9537,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9547,7 +9592,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9587,7 +9632,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9607,7 +9652,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9627,7 +9672,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9647,7 +9692,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9667,7 +9712,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9755,7 +9800,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9795,7 +9840,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_23YiVs2miQcEiUdn4u8SvjQKWYim_approvedBy) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -9811,7 +9856,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9831,7 +9876,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9851,7 +9896,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9869,7 +9914,7 @@ get urls(): ((URL | Link))[] { } result[\\"type\\"] = \\"Object\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -9880,7 +9925,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -9895,7 +9940,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -9910,7 +9955,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -9943,7 +9988,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -9994,7 +10039,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10009,7 +10054,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10024,7 +10069,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10039,7 +10084,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10054,7 +10099,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10069,7 +10114,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10102,7 +10147,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_7UpwM3JWcXhADcscukEehBorf6k_replies) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10117,7 +10162,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10132,7 +10177,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10147,7 +10192,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10198,7 +10243,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10231,7 +10276,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10246,7 +10291,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10261,7 +10306,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10276,7 +10321,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10291,7 +10336,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10369,7 +10414,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push({ \\"@graph\\": element });; } @@ -10399,7 +10444,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_23YiVs2miQcEiUdn4u8SvjQKWYim_approvedBy) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -10414,7 +10459,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10429,7 +10474,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10444,7 +10489,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10457,7 +10502,7 @@ get urls(): ((URL | Link))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Object\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -10589,10 +10634,12 @@ get urls(): ((URL | Link))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -10600,11 +10647,9 @@ get urls(): ((URL | Link))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -10874,8 +10919,21 @@ get urls(): ((URL | Link))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); @@ -10896,11 +10954,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _49BipA5dq9eoH8LX8xdsVumveTca_attachment.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _49BipA5dq9eoH8LX8xdsVumveTca_attachment.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -10944,11 +10998,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -10998,11 +11048,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11056,11 +11102,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3mhZzGXSpQ431mBSz2kvych22v4e_context.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3mhZzGXSpQ431mBSz2kvych22v4e_context.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11146,11 +11188,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _86xFhmgBapoMvYqjbjRuDPayTrS_generator.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _86xFhmgBapoMvYqjbjRuDPayTrS_generator.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11212,11 +11250,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11268,11 +11302,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3dXrUdkARxwyJLtJcYi1AJ92H41U_image.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3dXrUdkARxwyJLtJcYi1AJ92H41U_image.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11302,11 +11332,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11346,11 +11372,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _31k5MUZJsnsPNg8dQQJieWaXTFnR_location.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _31k5MUZJsnsPNg8dQQJieWaXTFnR_location.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11390,11 +11412,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11456,11 +11474,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _7UpwM3JWcXhADcscukEehBorf6k_replies.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _7UpwM3JWcXhADcscukEehBorf6k_replies.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11490,11 +11504,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3kAfck9PcEYt2L7xug5y99YPbANs_shares.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3kAfck9PcEYt2L7xug5y99YPbANs_shares.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11524,11 +11534,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11558,11 +11564,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11638,11 +11640,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _5chuqj6s95p5gg2sk1HntGfarRf_tag.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _5chuqj6s95p5gg2sk1HntGfarRf_tag.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11702,22 +11700,7 @@ get urls(): ((URL | Link))[] { const decoded = v != null && typeof v === \\"object\\" && \\"@id\\" in v && typeof v[\\"@id\\"] === \\"string\\" - && v[\\"@id\\"] !== \\"\\" ? v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl) : typeof v === \\"object\\" && \\"@type\\" in v + && v[\\"@id\\"] !== \\"\\" ? parseIri(v[\\"@id\\"], options.baseUrl) : typeof v === \\"object\\" && \\"@type\\" in v && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Link\\",\\"https://www.w3.org/ns/activitystreams#Hashtag\\",\\"https://www.w3.org/ns/activitystreams#Mention\\"].some( t => v[\\"@type\\"].includes(t)) ? await Link.fromJsonLd( v, @@ -11747,11 +11730,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11781,11 +11760,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11815,11 +11790,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11849,11 +11820,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11958,11 +11925,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -12008,22 +11971,7 @@ get urls(): ((URL | Link))[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _23YiVs2miQcEiUdn4u8SvjQKWYim_approvedBy.push(decoded); } @@ -12046,11 +11994,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -12080,11 +12024,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -12114,11 +12054,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -12133,7 +12069,19 @@ get urls(): ((URL | Link))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -13165,7 +13113,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Emoji\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\"}]; return result; } @@ -13184,7 +13132,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"http://joinmastodon.org/ns#Emoji\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -13291,10 +13239,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -13302,11 +13252,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -13320,6 +13268,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -13332,7 +13291,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -13575,9 +13546,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -13587,21 +13559,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -13630,7 +13601,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -13717,8 +13688,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -13757,8 +13729,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -13826,9 +13798,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -13838,21 +13811,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -13881,7 +13853,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -13967,8 +13939,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -14007,8 +13980,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -14075,7 +14048,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -14095,7 +14068,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -14121,7 +14094,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -14139,7 +14112,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"ChatMessage\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -14160,7 +14133,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -14175,7 +14148,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { \\"@value\\": v.href } + { \\"@value\\": formatIri(v) } ); array.push(element);; } @@ -14194,7 +14167,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -14207,7 +14180,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"http://litepub.social/ns#ChatMessage\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -14314,10 +14287,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -14325,11 +14300,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -14343,6 +14316,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -14370,11 +14354,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -14407,7 +14387,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ) { if (v == null) continue; - const decoded = new URL(v[\\"@value\\"]); + const decoded = parseIri(v[\\"@value\\"]); if (typeof decoded === \\"undefined\\") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -14430,11 +14410,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -14449,7 +14425,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -15183,9 +15171,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -15195,21 +15184,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#actor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -15238,7 +15226,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -15361,8 +15349,9 @@ instruments?: (Object | URL)[];} } if (this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.length < 1) return null; let v = this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(0)) { v = v.id; } @@ -15401,8 +15390,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -15467,8 +15456,9 @@ instruments?: (Object | URL)[];} const vs = this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(i)) { v = v.id; } @@ -15508,9 +15498,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -15555,9 +15545,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -15567,21 +15558,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#object_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -15610,7 +15600,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -15697,8 +15687,9 @@ instruments?: (Object | URL)[];} } if (this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.length < 1) return null; let v = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { v = v.id; } @@ -15737,8 +15728,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -15803,8 +15794,9 @@ instruments?: (Object | URL)[];} const vs = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { v = v.id; } @@ -15844,9 +15836,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -15891,9 +15883,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -15903,21 +15896,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#target_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -15946,7 +15938,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -16036,8 +16028,9 @@ instruments?: (Object | URL)[];} } if (this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.length < 1) return null; let v = this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(0)) { v = v.id; } @@ -16076,8 +16069,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -16145,8 +16138,9 @@ instruments?: (Object | URL)[];} const vs = this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(i)) { v = v.id; } @@ -16186,9 +16180,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -16233,9 +16227,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -16245,21 +16240,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#result_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -16288,7 +16282,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -16375,8 +16369,9 @@ instruments?: (Object | URL)[];} } if (this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.length < 1) return null; let v = this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(0)) { v = v.id; } @@ -16415,8 +16410,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -16481,8 +16476,9 @@ instruments?: (Object | URL)[];} const vs = this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(i)) { v = v.id; } @@ -16522,9 +16518,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -16569,9 +16565,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -16581,21 +16578,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#origin_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -16624,7 +16620,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -16712,8 +16708,9 @@ instruments?: (Object | URL)[];} } if (this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin.length < 1) return null; let v = this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(0)) { v = v.id; } @@ -16752,8 +16749,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -16819,8 +16816,9 @@ instruments?: (Object | URL)[];} const vs = this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(i)) { v = v.id; } @@ -16860,9 +16858,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -16907,9 +16905,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -16919,21 +16918,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#instrument_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -16962,7 +16960,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -17048,8 +17046,9 @@ instruments?: (Object | URL)[];} } if (this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.length < 1) return null; let v = this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(0)) { v = v.id; } @@ -17088,8 +17087,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -17153,8 +17152,9 @@ instruments?: (Object | URL)[];} const vs = this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(i)) { v = v.id; } @@ -17194,9 +17194,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -17265,7 +17265,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -17280,7 +17280,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17295,7 +17295,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17310,7 +17310,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17325,7 +17325,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17340,7 +17340,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17353,7 +17353,7 @@ instruments?: (Object | URL)[];} } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Activity\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -17460,10 +17460,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -17471,11 +17473,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -17625,6 +17625,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -17652,11 +17663,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17706,11 +17713,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17740,11 +17743,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17774,11 +17773,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17808,11 +17803,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _25zu2s3VxVujgEKqrDycjE284XQR_origin.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _25zu2s3VxVujgEKqrDycjE284XQR_origin.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17842,11 +17833,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17861,7 +17848,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -18205,7 +18204,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"http://litepub.social/ns#EmojiReact\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -18312,10 +18311,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -18323,11 +18324,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -18341,6 +18340,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -18353,7 +18363,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -18674,7 +18696,7 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} } result[\\"type\\"] = \\"PropertyValue\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\"}]; return result; } @@ -18719,7 +18741,7 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} } values[\\"@type\\"] = [\\"http://schema.org#PropertyValue\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -18825,10 +18847,12 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -18836,11 +18860,9 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -18854,8 +18876,21 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name: ((string | LanguageString))[] = []; @@ -18909,7 +18944,19 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -19283,7 +19330,7 @@ unit?: string | null;numericalValue?: Decimal | null;} } result[\\"type\\"] = \\"om2:Measure\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -19325,7 +19372,7 @@ unit?: string | null;numericalValue?: Decimal | null;} } values[\\"@type\\"] = [\\"http://www.ontology-of-units-of-measure.org/resource/om-2/Measure\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -19421,10 +19468,12 @@ unit?: string | null;numericalValue?: Decimal | null;} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -19432,11 +19481,9 @@ unit?: string | null;numericalValue?: Decimal | null;} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -19450,8 +19497,21 @@ unit?: string | null;numericalValue?: Decimal | null;} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _27fgyFbosTtMAhuepJH8K3ZGURT6: (string)[] = []; @@ -19493,7 +19553,19 @@ unit?: string | null;numericalValue?: Decimal | null;} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -19768,9 +19840,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -19780,21 +19853,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -19823,7 +19895,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -19909,8 +19981,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -19949,8 +20022,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -19995,9 +20068,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -20007,21 +20081,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -20050,7 +20123,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -20135,8 +20208,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -20175,8 +20249,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -20243,7 +20317,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -20263,7 +20337,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -20281,7 +20355,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"AnnounceAuthorization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -20302,7 +20376,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -20317,7 +20391,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -20330,7 +20404,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://gotosocial.org/ns#AnnounceAuthorization\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -20437,10 +20511,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -20448,11 +20524,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -20466,6 +20540,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -20493,11 +20578,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -20527,11 +20608,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -20546,7 +20623,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -20784,7 +20873,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://gotosocial.org/ns#AnnounceRequest\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -20891,10 +20980,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -20902,11 +20993,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -20920,6 +21009,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -20932,7 +21032,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -21376,7 +21488,7 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: } - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -21492,10 +21604,12 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -21503,11 +21617,9 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -21521,8 +21633,21 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike: (InteractionRule)[] = []; @@ -21612,7 +21737,19 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -22126,7 +22263,7 @@ get manualApprovals(): (URL)[] { array = []; for (const v of this.#_2rFyCF14HoyNjitj9PmCzek5iSsg_automaticApproval) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -22141,7 +22278,7 @@ get manualApprovals(): (URL)[] { array = []; for (const v of this.#_sxj8y5XMMMBWUnRYFw85MKedCMj_manualApproval) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -22154,7 +22291,7 @@ get manualApprovals(): (URL)[] { } - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -22250,10 +22387,12 @@ get manualApprovals(): (URL)[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -22261,11 +22400,9 @@ get manualApprovals(): (URL)[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -22279,8 +22416,21 @@ get manualApprovals(): (URL)[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _2rFyCF14HoyNjitj9PmCzek5iSsg_automaticApproval: (URL)[] = []; @@ -22296,22 +22446,7 @@ get manualApprovals(): (URL)[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _2rFyCF14HoyNjitj9PmCzek5iSsg_automaticApproval.push(decoded); } @@ -22329,22 +22464,7 @@ get manualApprovals(): (URL)[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _sxj8y5XMMMBWUnRYFw85MKedCMj_manualApproval.push(decoded); } @@ -22352,7 +22472,19 @@ get manualApprovals(): (URL)[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -22638,9 +22770,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -22650,21 +22783,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -22693,7 +22825,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -22779,8 +22911,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -22819,8 +22952,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -22865,9 +22998,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -22877,21 +23011,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -22920,7 +23053,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -23005,8 +23138,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -23045,8 +23179,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -23113,7 +23247,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -23133,7 +23267,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -23151,7 +23285,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"LikeAuthorization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -23172,7 +23306,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -23187,7 +23321,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -23200,7 +23334,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://gotosocial.org/ns#LikeApproval\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -23307,10 +23441,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -23318,11 +23454,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -23336,6 +23470,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -23363,11 +23508,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -23397,11 +23538,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -23416,7 +23553,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -23653,7 +23802,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://gotosocial.org/ns#LikeRequest\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -23760,10 +23909,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -23771,11 +23922,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -23789,6 +23938,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -23801,7 +23961,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -24020,9 +24192,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -24032,21 +24205,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -24075,7 +24247,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -24161,8 +24333,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -24201,8 +24374,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -24247,9 +24420,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -24259,21 +24433,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -24302,7 +24475,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -24387,8 +24560,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -24427,8 +24601,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -24495,7 +24669,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -24515,7 +24689,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -24533,7 +24707,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"ReplyAuthorization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -24554,7 +24728,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -24569,7 +24743,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -24582,7 +24756,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://gotosocial.org/ns#ReplyAuthorization\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -24689,10 +24863,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -24700,11 +24876,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -24718,6 +24892,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -24745,11 +24930,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -24779,11 +24960,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -24798,7 +24975,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -25035,7 +25224,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://gotosocial.org/ns#ReplyRequest\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -25142,10 +25331,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -25153,11 +25344,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -25171,6 +25360,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -25183,7 +25383,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -25402,9 +25614,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -25414,21 +25627,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -25457,7 +25669,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -25542,8 +25754,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -25582,8 +25795,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -25628,9 +25841,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -25640,21 +25854,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -25683,7 +25896,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -25768,8 +25981,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -25808,8 +26022,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -25876,7 +26090,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -25896,7 +26110,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -25914,7 +26128,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"QuoteAuthorization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\"}]; return result; } @@ -25935,7 +26149,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -25950,7 +26164,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -25963,7 +26177,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://w3id.org/fep/044f#QuoteAuthorization\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -26070,10 +26284,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -26081,11 +26297,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -26099,6 +26313,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -26126,11 +26351,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -26160,11 +26381,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -26179,7 +26396,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -26416,7 +26645,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://w3id.org/fep/044f#QuoteRequest\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -26523,10 +26752,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -26534,11 +26765,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -26552,6 +26781,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -26564,7 +26804,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -26869,7 +27121,7 @@ get endpoints(): (URL)[] { array = []; for (const v of this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -26882,7 +27134,7 @@ get endpoints(): (URL)[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/did#Service\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -26978,10 +27230,12 @@ get endpoints(): (URL)[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -26989,11 +27243,9 @@ get endpoints(): (URL)[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -27011,8 +27263,21 @@ get endpoints(): (URL)[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint: (URL)[] = []; @@ -27028,22 +27293,7 @@ get endpoints(): (URL)[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.push(decoded); } @@ -27051,7 +27301,19 @@ get endpoints(): (URL)[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -27238,7 +27500,7 @@ endpoints?: (URL)[];} >; values[\\"@type\\"] = [\\"https://w3id.org/fep/9091#Export\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -27334,10 +27596,12 @@ endpoints?: (URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -27345,11 +27609,9 @@ endpoints?: (URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -27363,6 +27625,17 @@ endpoints?: (URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -27375,7 +27648,19 @@ endpoints?: (URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -27721,9 +28006,10 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -27733,21 +28019,20 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#verificationMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -27776,7 +28061,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -27864,8 +28149,9 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | } if (this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.length < 1) return null; let v = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { v = v.id; } @@ -27879,8 +28165,8 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | return fetched; } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -28000,7 +28286,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | array = []; for (const v of this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -28066,7 +28352,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | } values[\\"@type\\"] = [\\"https://w3id.org/security#DataIntegrityProof\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -28162,10 +28448,12 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -28173,11 +28461,9 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -28191,8 +28477,21 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite: (\\"eddsa-jcs-2022\\")[] = []; @@ -28231,11 +28530,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -28308,7 +28603,19 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -28674,9 +28981,10 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -28686,21 +28994,20 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#owner_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -28729,7 +29036,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -28849,8 +29156,9 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } if (this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.length < 1) return null; let v = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { v = v.id; } @@ -28889,8 +29197,8 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -28964,7 +29272,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi compactItems = []; for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -29014,7 +29322,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } result[\\"type\\"] = \\"CryptographicKey\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://w3id.org/security/v1\\"; return result; } @@ -29025,7 +29333,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi array = []; for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -29053,7 +29361,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } values[\\"@type\\"] = [\\"https://w3id.org/security#Key\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -29149,10 +29457,12 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -29160,11 +29470,9 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -29178,8 +29486,21 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); @@ -29200,11 +29521,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -29257,7 +29574,19 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -29567,9 +29896,10 @@ controller?: Application | Group | Organization | Person | Service | URL | null; \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -29579,21 +29909,20 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#controller_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -29622,7 +29951,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -29742,8 +30071,9 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } if (this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.length < 1) return null; let v = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { v = v.id; } @@ -29782,8 +30112,8 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -29861,7 +30191,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; compactItems = []; for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -29911,7 +30241,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } result[\\"type\\"] = \\"Multikey\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://w3id.org/security/multikey/v1\\"; return result; } @@ -29922,7 +30252,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; array = []; for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -29953,7 +30283,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } values[\\"@type\\"] = [\\"https://w3id.org/security#Multikey\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -30049,10 +30379,12 @@ controller?: Application | Group | Organization | Person | Service | URL | null; }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -30060,11 +30392,9 @@ controller?: Application | Group | Organization | Person | Service | URL | null; // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -30078,8 +30408,21 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); @@ -30100,11 +30443,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -30157,7 +30496,19 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -30523,7 +30874,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Agreement\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Agreement\\":\\"vf:Agreement\\",\\"Commitment\\":\\"vf:Commitment\\",\\"stipulates\\":\\"vf:stipulates\\",\\"stipulatesReciprocal\\":\\"vf:stipulatesReciprocal\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -30572,7 +30923,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Agreement\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -30679,10 +31030,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -30690,11 +31043,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -30708,6 +31059,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -30762,7 +31124,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -31099,7 +31473,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} compactItems = []; for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -31133,7 +31507,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} } result[\\"type\\"] = \\"Commitment\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Commitment\\":\\"vf:Commitment\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -31144,7 +31518,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} array = []; for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -31172,7 +31546,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} } values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Commitment\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -31268,10 +31642,12 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -31279,11 +31655,9 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -31297,8 +31671,21 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies: (URL)[] = []; @@ -31314,22 +31701,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies.push(decoded); } @@ -31358,7 +31730,19 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -31842,7 +32226,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur compactItems = []; for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -31916,7 +32300,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur } result[\\"type\\"] = \\"Intent\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Intent\\":\\"vf:Intent\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -31942,7 +32326,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur array = []; for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -32000,7 +32384,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur } values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Intent\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -32096,10 +32480,12 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -32107,11 +32493,9 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -32125,8 +32509,21 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _38VmZKmXJSBy3AvgqNa9GVqbdphy_action: (string)[] = []; @@ -32160,22 +32557,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo.push(decoded); } @@ -32246,7 +32628,19 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -32785,7 +33179,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Proposal\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Proposal\\":\\"vf:Proposal\\",\\"Intent\\":\\"vf:Intent\\",\\"purpose\\":\\"vf:purpose\\",\\"unitBased\\":\\"vf:unitBased\\",\\"publishes\\":\\"vf:publishes\\",\\"reciprocal\\":\\"vf:reciprocal\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -32864,7 +33258,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Proposal\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -32971,10 +33365,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -32982,11 +33378,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -33000,6 +33394,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -33090,7 +33495,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -33360,7 +33777,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Accept\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -33467,10 +33884,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -33478,11 +33897,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -33500,6 +33917,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -33512,7 +33940,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -33703,7 +34143,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Add\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -33810,10 +34250,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -33821,11 +34263,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -33839,6 +34279,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -33851,7 +34302,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -34041,7 +34504,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Announce\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -34148,10 +34611,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -34159,11 +34624,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -34177,6 +34640,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -34189,7 +34663,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -35274,9 +35760,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -35286,21 +35773,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -35329,7 +35815,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -35413,8 +35899,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -35453,8 +35940,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -35516,8 +36003,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -35557,9 +36045,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -35604,9 +36092,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -35616,21 +36105,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -35659,7 +36147,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -35747,8 +36235,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -35787,8 +36276,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -35854,8 +36343,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -35895,9 +36385,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -35961,9 +36451,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -35973,21 +36464,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36016,7 +36506,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36122,8 +36612,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -36162,8 +36653,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -36208,9 +36699,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36220,21 +36712,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36263,7 +36754,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36366,8 +36857,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -36406,8 +36898,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -36452,9 +36944,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36464,21 +36957,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36507,7 +36999,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36596,8 +37088,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -36636,8 +37129,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -36682,9 +37175,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36694,21 +37188,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36737,7 +37230,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36829,8 +37322,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -36869,8 +37363,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -36915,9 +37409,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36927,21 +37422,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36970,7 +37464,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37060,8 +37554,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -37100,8 +37595,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -37146,9 +37641,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37158,21 +37654,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -37201,7 +37696,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37289,8 +37784,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -37329,8 +37825,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -37375,9 +37871,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37387,21 +37884,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -37430,7 +37926,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37518,8 +38014,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -37558,8 +38055,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -37604,9 +38101,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37616,21 +38114,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -37659,7 +38156,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37744,8 +38241,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -37785,9 +38283,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -37907,9 +38405,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37919,21 +38418,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -37962,7 +38460,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -38082,8 +38580,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -38122,8 +38621,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -38168,9 +38667,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -38180,21 +38680,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -38223,7 +38722,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -38347,8 +38846,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -38387,8 +38887,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -38454,8 +38954,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -38495,9 +38996,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -38542,9 +39043,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -38554,21 +39056,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -38597,7 +39098,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -38685,8 +39186,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -38725,8 +39227,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -38792,8 +39294,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -38833,9 +39336,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -38952,7 +39455,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -38972,7 +39475,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39008,7 +39511,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39032,7 +39535,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39056,7 +39559,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39076,7 +39579,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39096,7 +39599,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39116,7 +39619,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39136,7 +39639,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39156,7 +39659,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39260,7 +39763,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39296,7 +39799,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39332,7 +39835,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39382,7 +39885,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Application\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -39421,7 +39924,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39436,7 +39939,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39466,7 +39969,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39481,7 +39984,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39496,7 +39999,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39511,7 +40014,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39526,7 +40029,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39541,7 +40044,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39556,7 +40059,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39571,7 +40074,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39661,7 +40164,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39676,7 +40179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39691,7 +40194,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39734,7 +40237,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Application\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -39851,10 +40354,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -39862,11 +40367,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -39880,6 +40383,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -39931,11 +40445,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -39965,11 +40475,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40017,11 +40523,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40059,11 +40561,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40101,11 +40599,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40135,11 +40629,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40169,11 +40659,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40203,11 +40689,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40237,11 +40719,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40271,11 +40749,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40398,11 +40872,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40452,11 +40922,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40506,11 +40972,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40561,7 +41023,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -41223,7 +41697,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -41330,10 +41804,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -41341,11 +41817,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -41371,6 +41845,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -41383,7 +41868,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -41573,7 +42070,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Arrive\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -41680,10 +42177,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -41691,11 +42190,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -41709,6 +42206,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -41721,7 +42229,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -41959,9 +42479,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -41971,21 +42492,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -42014,7 +42534,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -42101,8 +42621,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -42141,8 +42662,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -42210,9 +42731,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -42222,21 +42744,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -42265,7 +42786,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -42351,8 +42872,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -42391,8 +42913,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -42459,7 +42981,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -42479,7 +43001,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -42505,7 +43027,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -42523,7 +43045,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Article\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -42544,7 +43066,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -42559,7 +43081,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { \\"@value\\": v.href } + { \\"@value\\": formatIri(v) } ); array.push(element);; } @@ -42578,7 +43100,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -42591,7 +43113,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Article\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -42698,10 +43220,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -42709,11 +43233,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -42727,6 +43249,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -42754,11 +43287,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -42791,7 +43320,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ) { if (v == null) continue; - const decoded = new URL(v[\\"@value\\"]); + const decoded = parseIri(v[\\"@value\\"]); if (typeof decoded === \\"undefined\\") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -42814,11 +43343,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -42833,7 +43358,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -43182,7 +43719,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Document\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -43237,7 +43774,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Document\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -43344,10 +43881,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -43355,11 +43894,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -43389,6 +43926,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -43437,7 +43985,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -43650,7 +44210,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Audio\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -43669,7 +44229,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Audio\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -43776,10 +44336,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -43787,11 +44349,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -43805,6 +44365,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -43817,7 +44388,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -44006,7 +44589,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Ignore\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -44113,10 +44696,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -44124,11 +44709,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -44146,6 +44729,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -44158,7 +44752,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -44349,7 +44955,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Block\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -44456,10 +45062,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -44467,11 +45075,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -44485,6 +45091,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -44497,7 +45114,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -45059,9 +45688,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45071,21 +45701,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#current_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -45114,7 +45743,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45200,8 +45829,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current.length < 1) return null; let v = this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.has(0)) { v = v.id; } @@ -45240,8 +45870,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -45286,9 +45916,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45298,21 +45929,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#first_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -45341,7 +45971,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45427,8 +46057,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first.length < 1) return null; let v = this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.has(0)) { v = v.id; } @@ -45467,8 +46098,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -45513,9 +46144,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45525,21 +46157,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#last_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -45568,7 +46199,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45654,8 +46285,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.length < 1) return null; let v = this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.has(0)) { v = v.id; } @@ -45694,8 +46326,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -45740,9 +46372,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45752,21 +46385,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#item_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -45795,7 +46427,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45890,8 +46522,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { v = v.id; } @@ -45931,9 +46564,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -45978,9 +46611,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45990,21 +46624,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likesOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46033,7 +46666,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46118,8 +46751,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.length < 1) return null; let v = this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.has(0)) { v = v.id; } @@ -46158,8 +46792,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -46204,9 +46838,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46216,21 +46851,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#sharesOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46259,7 +46893,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46344,8 +46978,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.length < 1) return null; let v = this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.has(0)) { v = v.id; } @@ -46384,8 +47019,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -46430,9 +47065,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46442,21 +47078,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#repliesOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46485,7 +47120,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46570,8 +47205,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.length < 1) return null; let v = this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.has(0)) { v = v.id; } @@ -46610,8 +47246,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -46656,9 +47292,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46668,21 +47305,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inboxOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46711,7 +47347,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46796,8 +47432,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.length < 1) return null; let v = this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.has(0)) { v = v.id; } @@ -46836,8 +47473,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -46882,9 +47519,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46894,21 +47532,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outboxOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46937,7 +47574,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47022,8 +47659,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.length < 1) return null; let v = this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.has(0)) { v = v.id; } @@ -47062,8 +47700,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -47108,9 +47746,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -47120,21 +47759,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followersOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -47163,7 +47801,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47248,8 +47886,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.length < 1) return null; let v = this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.has(0)) { v = v.id; } @@ -47288,8 +47927,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -47334,9 +47973,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -47346,21 +47986,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followingOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -47389,7 +48028,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47474,8 +48113,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.length < 1) return null; let v = this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.has(0)) { v = v.id; } @@ -47514,8 +48154,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -47560,9 +48200,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -47572,21 +48213,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likedOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -47615,7 +48255,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47700,8 +48340,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.length < 1) return null; let v = this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.has(0)) { v = v.id; } @@ -47740,8 +48381,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -47824,7 +48465,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47844,7 +48485,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47864,7 +48505,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47884,7 +48525,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47908,7 +48549,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47928,7 +48569,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47948,7 +48589,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47968,7 +48609,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47988,7 +48629,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48008,7 +48649,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48028,7 +48669,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48048,7 +48689,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48066,7 +48707,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Collection\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -48105,7 +48746,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48120,7 +48761,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48135,7 +48776,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48150,7 +48791,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -48165,7 +48806,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48180,7 +48821,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48195,7 +48836,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48210,7 +48851,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48225,7 +48866,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48240,7 +48881,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48255,7 +48896,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48270,7 +48911,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48283,7 +48924,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Collection\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -48390,10 +49031,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -48401,11 +49044,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -48431,6 +49072,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -48476,11 +49128,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3UyUdxnyn6cDn53QKrh4MBiearma_current.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3UyUdxnyn6cDn53QKrh4MBiearma_current.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48510,11 +49158,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _J52RqweMe6hhv7RnLJMC8BExTE5_first.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _J52RqweMe6hhv7RnLJMC8BExTE5_first.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48544,11 +49188,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48578,11 +49218,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48622,11 +49258,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48656,11 +49288,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48690,11 +49318,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48724,11 +49348,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48758,11 +49378,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48792,11 +49408,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48826,11 +49438,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48860,11 +49468,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48879,7 +49483,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -49384,9 +50000,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -49396,21 +50013,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#partOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -49439,7 +50055,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -49525,8 +50141,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.length < 1) return null; let v = this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.has(0)) { v = v.id; } @@ -49565,8 +50182,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -49611,9 +50228,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -49623,21 +50241,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#next_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -49666,7 +50283,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -49750,8 +50367,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.length < 1) return null; let v = this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.has(0)) { v = v.id; } @@ -49790,8 +50408,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -49836,9 +50454,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -49848,21 +50467,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#prev_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -49891,7 +50509,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -49976,8 +50594,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.length < 1) return null; let v = this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.has(0)) { v = v.id; } @@ -50016,8 +50635,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -50084,7 +50703,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -50104,7 +50723,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -50124,7 +50743,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -50142,7 +50761,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"CollectionPage\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -50163,7 +50782,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -50178,7 +50797,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -50193,7 +50812,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -50206,7 +50825,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#CollectionPage\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -50313,10 +50932,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -50324,11 +50945,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -50346,6 +50965,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -50373,11 +51003,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -50407,11 +51033,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -50441,11 +51063,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -50460,7 +51078,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -50707,7 +51337,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Create\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -50814,10 +51444,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -50825,11 +51457,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -50843,6 +51473,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -50855,7 +51496,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -51044,7 +51697,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Delete\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -51151,10 +51804,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -51162,11 +51817,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -51180,6 +51833,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -51192,7 +51856,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -51379,7 +52055,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Dislike\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -51486,10 +52162,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -51497,11 +52175,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -51515,6 +52191,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -51527,7 +52214,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -52001,7 +52700,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52017,7 +52716,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_25S6UmgzDead8hxL5sQFezZTAusd_oauthAuthorizationEndpoint) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52033,7 +52732,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_iAMxqrSba7yBCRB1FZ5kEVdKEZ3_oauthTokenEndpoint) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52049,7 +52748,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_8Bx9qN8oU7Bpt2xi6khaxWp1gMr_provideClientKey) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52065,7 +52764,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_3dU7PMVQZJpsCpo2F4RQXxBXdPmS_signClientKey) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52081,7 +52780,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_3JprUSDLVqqX4dwHRi37qGZZCRCc_sharedInbox) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52095,7 +52794,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint } - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://www.w3.org/ns/activitystreams\\"; return result; } @@ -52106,7 +52805,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52121,7 +52820,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_25S6UmgzDead8hxL5sQFezZTAusd_oauthAuthorizationEndpoint) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52136,7 +52835,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_iAMxqrSba7yBCRB1FZ5kEVdKEZ3_oauthTokenEndpoint) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52151,7 +52850,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_8Bx9qN8oU7Bpt2xi6khaxWp1gMr_provideClientKey) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52166,7 +52865,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_3dU7PMVQZJpsCpo2F4RQXxBXdPmS_signClientKey) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52181,7 +52880,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_3JprUSDLVqqX4dwHRi37qGZZCRCc_sharedInbox) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52194,7 +52893,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint } - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -52290,10 +52989,12 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -52301,11 +53002,9 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -52319,8 +53018,21 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl: (URL)[] = []; @@ -52336,22 +53048,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl.push(decoded); } @@ -52369,22 +53066,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _25S6UmgzDead8hxL5sQFezZTAusd_oauthAuthorizationEndpoint.push(decoded); } @@ -52402,22 +53084,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _iAMxqrSba7yBCRB1FZ5kEVdKEZ3_oauthTokenEndpoint.push(decoded); } @@ -52435,22 +53102,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _8Bx9qN8oU7Bpt2xi6khaxWp1gMr_provideClientKey.push(decoded); } @@ -52468,22 +53120,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _3dU7PMVQZJpsCpo2F4RQXxBXdPmS_signClientKey.push(decoded); } @@ -52501,22 +53138,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _3JprUSDLVqqX4dwHRi37qGZZCRCc_sharedInbox.push(decoded); } @@ -52524,7 +53146,19 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -52832,7 +53466,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Event\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -52851,7 +53485,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Event\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -52958,10 +53592,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -52969,11 +53605,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -52987,6 +53621,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -52999,7 +53644,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -53189,7 +53846,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Flag\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -53296,10 +53953,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -53307,11 +53966,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -53325,6 +53982,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -53337,7 +54005,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -53528,7 +54208,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Follow\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -53635,10 +54315,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -53646,11 +54328,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -53664,6 +54344,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -53676,7 +54367,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -54761,9 +55464,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -54773,21 +55477,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -54816,7 +55519,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -54900,8 +55603,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -54940,8 +55644,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -55003,8 +55707,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -55044,9 +55749,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -55091,9 +55796,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55103,21 +55809,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -55146,7 +55851,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -55234,8 +55939,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -55274,8 +55980,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -55341,8 +56047,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -55382,9 +56089,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -55448,9 +56155,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55460,21 +56168,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -55503,7 +56210,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -55609,8 +56316,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -55649,8 +56357,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -55695,9 +56403,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55707,21 +56416,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -55750,7 +56458,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -55853,8 +56561,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -55893,8 +56602,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -55939,9 +56648,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55951,21 +56661,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -55994,7 +56703,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56083,8 +56792,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -56123,8 +56833,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -56169,9 +56879,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56181,21 +56892,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -56224,7 +56934,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56316,8 +57026,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -56356,8 +57067,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -56402,9 +57113,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56414,21 +57126,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -56457,7 +57168,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56547,8 +57258,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -56587,8 +57299,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -56633,9 +57345,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56645,21 +57358,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -56688,7 +57400,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56776,8 +57488,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -56816,8 +57529,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -56862,9 +57575,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56874,21 +57588,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -56917,7 +57630,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57005,8 +57718,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -57045,8 +57759,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -57091,9 +57805,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -57103,21 +57818,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -57146,7 +57860,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57231,8 +57945,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -57272,9 +57987,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -57394,9 +58109,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -57406,21 +58122,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -57449,7 +58164,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57569,8 +58284,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -57609,8 +58325,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -57655,9 +58371,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -57667,21 +58384,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -57710,7 +58426,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57834,8 +58550,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -57874,8 +58591,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -57941,8 +58658,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -57982,9 +58700,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -58029,9 +58747,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -58041,21 +58760,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -58084,7 +58802,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -58172,8 +58890,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -58212,8 +58931,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -58279,8 +58998,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -58320,9 +59040,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -58439,7 +59159,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58459,7 +59179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58495,7 +59215,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58519,7 +59239,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58543,7 +59263,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58563,7 +59283,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58583,7 +59303,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58603,7 +59323,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58623,7 +59343,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58643,7 +59363,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58747,7 +59467,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58783,7 +59503,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58819,7 +59539,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58869,7 +59589,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Group\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -58908,7 +59628,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -58923,7 +59643,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -58953,7 +59673,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -58968,7 +59688,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -58983,7 +59703,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -58998,7 +59718,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59013,7 +59733,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59028,7 +59748,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59043,7 +59763,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59058,7 +59778,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59148,7 +59868,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -59163,7 +59883,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -59178,7 +59898,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59221,7 +59941,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Group\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -59338,10 +60058,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -59349,11 +60071,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -59367,6 +60087,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -59418,11 +60149,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59452,11 +60179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59504,11 +60227,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59546,11 +60265,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59588,11 +60303,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59622,11 +60333,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59656,11 +60363,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59690,11 +60393,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59724,11 +60423,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59758,11 +60453,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59885,11 +60576,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59939,11 +60626,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59993,11 +60676,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -60048,7 +60727,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -61173,9 +61864,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -61185,21 +61877,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#preview_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -61228,7 +61919,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -61321,8 +62012,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { v = v.id; } @@ -61362,9 +62054,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -61425,7 +62117,7 @@ get names(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_pVjLsybKQdmkjuU7MHjiVmNnuj7_href) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -61540,7 +62232,7 @@ get names(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const item = ( - v instanceof URL ? v.href : v instanceof Link ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Link ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -61562,7 +62254,7 @@ get names(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Link\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://www.w3.org/ns/activitystreams\\"; return result; } @@ -61573,7 +62265,7 @@ get names(): ((string | LanguageString))[] { array = []; for (const v of this.#_pVjLsybKQdmkjuU7MHjiVmNnuj7_href) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -61687,7 +62379,7 @@ get names(): ((string | LanguageString))[] { array = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -61700,7 +62392,7 @@ get names(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Link\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -61801,10 +62493,12 @@ get names(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -61812,11 +62506,9 @@ get names(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -61838,8 +62530,21 @@ get names(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _pVjLsybKQdmkjuU7MHjiVmNnuj7_href: (URL)[] = []; @@ -61855,22 +62560,7 @@ get names(): ((string | LanguageString))[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _pVjLsybKQdmkjuU7MHjiVmNnuj7_href.push(decoded); } @@ -62007,11 +62697,7 @@ get names(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -62036,7 +62722,19 @@ get names(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -62373,7 +63071,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num let compactItems: unknown[]; result[\\"type\\"] = \\"Hashtag\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"Hashtag\\":\\"as:Hashtag\\"}]; return result; } @@ -62392,7 +63090,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Hashtag\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -62488,10 +63186,12 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -62499,11 +63199,9 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -62517,6 +63215,17 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -62529,7 +63238,19 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -62702,7 +63423,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Image\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -62721,7 +63442,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Image\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -62828,10 +63549,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -62839,11 +63562,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -62857,6 +63578,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -62869,7 +63601,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -63059,7 +63803,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Offer\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -63166,10 +63910,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -63177,11 +63923,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -63199,6 +63943,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -63211,7 +63966,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -63400,7 +64167,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Invite\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -63507,10 +64274,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -63518,11 +64287,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -63536,6 +64303,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -63548,7 +64326,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -63737,7 +64527,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Join\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -63844,10 +64634,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -63855,11 +64647,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -63873,6 +64663,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -63885,7 +64686,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -64074,7 +64887,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Leave\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -64181,10 +64994,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -64192,11 +65007,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -64210,6 +65023,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -64222,7 +65046,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -64411,7 +65247,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Like\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -64518,10 +65354,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -64529,11 +65367,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -64547,6 +65383,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -64559,7 +65406,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -64746,7 +65605,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Listen\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -64853,10 +65712,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -64864,11 +65725,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -64882,6 +65741,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -64894,7 +65764,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -65039,7 +65921,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num let compactItems: unknown[]; result[\\"type\\"] = \\"Mention\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://www.w3.org/ns/activitystreams\\"; return result; } @@ -65058,7 +65940,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Mention\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -65154,10 +66036,12 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -65165,11 +66049,9 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -65183,6 +66065,17 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -65195,7 +66088,19 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -65385,7 +66290,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Move\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -65492,10 +66397,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -65503,11 +66410,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -65521,6 +66426,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -65533,7 +66449,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -65773,9 +66701,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -65785,21 +66714,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -65828,7 +66756,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -65915,8 +66843,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -65955,8 +66884,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -66024,9 +66953,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -66036,21 +66966,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -66079,7 +67008,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -66165,8 +67094,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -66205,8 +67135,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -66273,7 +67203,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -66293,7 +67223,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -66319,7 +67249,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -66337,7 +67267,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Note\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -66358,7 +67288,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -66373,7 +67303,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { \\"@value\\": v.href } + { \\"@value\\": formatIri(v) } ); array.push(element);; } @@ -66392,7 +67322,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -66405,7 +67335,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Note\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -66512,10 +67442,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -66523,11 +67455,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -66541,6 +67471,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -66568,11 +67509,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -66605,7 +67542,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ) { if (v == null) continue; - const decoded = new URL(v[\\"@value\\"]); + const decoded = parseIri(v[\\"@value\\"]); if (typeof decoded === \\"undefined\\") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -66628,11 +67565,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -66647,7 +67580,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -66904,9 +67849,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -66916,21 +67862,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#item_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -66959,7 +67904,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -67054,8 +67999,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { v = v.id; } @@ -67095,9 +68041,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -67164,7 +68110,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -67183,7 +68129,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"OrderedCollection\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -67204,7 +68150,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -67217,7 +68163,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -67324,10 +68270,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -67335,11 +68283,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -67353,6 +68299,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -67380,11 +68337,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -67409,7 +68362,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -67656,9 +68621,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -67668,21 +68634,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#item_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -67711,7 +68676,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -67806,8 +68771,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { v = v.id; } @@ -67847,9 +68813,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -67931,7 +68897,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -67966,7 +68932,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"OrderedCollectionPage\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -67987,7 +68953,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -68018,7 +68984,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -68125,10 +69091,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -68136,11 +69104,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -68154,6 +69120,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -68181,11 +69158,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -68228,7 +69201,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -69355,9 +70340,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -69367,21 +70353,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -69410,7 +70395,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -69494,8 +70479,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -69534,8 +70520,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -69597,8 +70583,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -69638,9 +70625,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -69685,9 +70672,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -69697,21 +70685,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -69740,7 +70727,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -69828,8 +70815,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -69868,8 +70856,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -69935,8 +70923,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -69976,9 +70965,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -70042,9 +71031,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70054,21 +71044,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -70097,7 +71086,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70203,8 +71192,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -70243,8 +71233,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -70289,9 +71279,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70301,21 +71292,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -70344,7 +71334,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70447,8 +71437,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -70487,8 +71478,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -70533,9 +71524,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70545,21 +71537,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -70588,7 +71579,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70677,8 +71668,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -70717,8 +71709,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -70763,9 +71755,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70775,21 +71768,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -70818,7 +71810,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70910,8 +71902,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -70950,8 +71943,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -70996,9 +71989,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71008,21 +72002,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -71051,7 +72044,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71141,8 +72134,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -71181,8 +72175,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -71227,9 +72221,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71239,21 +72234,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -71282,7 +72276,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71370,8 +72364,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -71410,8 +72405,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -71456,9 +72451,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71468,21 +72464,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -71511,7 +72506,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71599,8 +72594,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -71639,8 +72635,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -71685,9 +72681,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71697,21 +72694,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -71740,7 +72736,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71825,8 +72821,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -71866,9 +72863,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -71988,9 +72985,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -72000,21 +72998,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -72043,7 +73040,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -72163,8 +73160,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -72203,8 +73201,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -72249,9 +73247,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -72261,21 +73260,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -72304,7 +73302,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -72428,8 +73426,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -72468,8 +73467,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -72535,8 +73534,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -72576,9 +73576,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -72623,9 +73623,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -72635,21 +73636,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -72678,7 +73678,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -72766,8 +73766,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -72806,8 +73807,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -72873,8 +73874,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -72914,9 +73916,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -73033,7 +74035,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73053,7 +74055,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73089,7 +74091,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73113,7 +74115,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73137,7 +74139,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73157,7 +74159,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73177,7 +74179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73197,7 +74199,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73217,7 +74219,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73237,7 +74239,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73341,7 +74343,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73377,7 +74379,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73413,7 +74415,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73463,7 +74465,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Organization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -73502,7 +74504,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73517,7 +74519,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73547,7 +74549,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73562,7 +74564,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73577,7 +74579,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73592,7 +74594,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73607,7 +74609,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73622,7 +74624,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73637,7 +74639,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73652,7 +74654,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73742,7 +74744,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73757,7 +74759,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73772,7 +74774,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73815,7 +74817,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Organization\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -73932,10 +74934,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -73943,11 +74947,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -73961,6 +74963,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -74012,11 +75025,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74046,11 +75055,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74098,11 +75103,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74140,11 +75141,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74182,11 +75179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74216,11 +75209,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74250,11 +75239,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74284,11 +75269,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74318,11 +75299,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74352,11 +75329,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74479,11 +75452,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74533,11 +75502,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74587,11 +75552,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74642,7 +75603,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -75287,7 +76260,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Page\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -75306,7 +76279,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Page\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -75413,10 +76386,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -75424,11 +76399,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -75442,6 +76415,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -75454,7 +76438,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -76539,9 +77535,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -76551,21 +77548,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -76594,7 +77590,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -76678,8 +77674,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -76718,8 +77715,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -76781,8 +77778,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -76822,9 +77820,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -76869,9 +77867,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -76881,21 +77880,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -76924,7 +77922,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77012,8 +78010,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -77052,8 +78051,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -77119,8 +78118,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -77160,9 +78160,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -77226,9 +78226,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77238,21 +78239,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -77281,7 +78281,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77387,8 +78387,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -77427,8 +78428,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -77473,9 +78474,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77485,21 +78487,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -77528,7 +78529,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77631,8 +78632,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -77671,8 +78673,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -77717,9 +78719,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77729,21 +78732,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -77772,7 +78774,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77861,8 +78863,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -77901,8 +78904,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -77947,9 +78950,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77959,21 +78963,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78002,7 +79005,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78094,8 +79097,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -78134,8 +79138,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -78180,9 +79184,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78192,21 +79197,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78235,7 +79239,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78325,8 +79329,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -78365,8 +79370,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -78411,9 +79416,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78423,21 +79429,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78466,7 +79471,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78554,8 +79559,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -78594,8 +79600,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -78640,9 +79646,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78652,21 +79659,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78695,7 +79701,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78783,8 +79789,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -78823,8 +79830,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -78869,9 +79876,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78881,21 +79889,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78924,7 +79931,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79009,8 +80016,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -79050,9 +80058,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -79172,9 +80180,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -79184,21 +80193,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -79227,7 +80235,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79347,8 +80355,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -79387,8 +80396,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -79433,9 +80442,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -79445,21 +80455,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -79488,7 +80497,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79612,8 +80621,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -79652,8 +80662,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -79719,8 +80729,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -79760,9 +80771,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -79807,9 +80818,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -79819,21 +80831,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -79862,7 +80873,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79950,8 +80961,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -79990,8 +81002,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -80057,8 +81069,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -80098,9 +81111,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -80217,7 +81230,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80237,7 +81250,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80273,7 +81286,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80297,7 +81310,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80321,7 +81334,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80341,7 +81354,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80361,7 +81374,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80381,7 +81394,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80401,7 +81414,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80421,7 +81434,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80525,7 +81538,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80561,7 +81574,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80597,7 +81610,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80647,7 +81660,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Person\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -80686,7 +81699,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80701,7 +81714,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80731,7 +81744,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80746,7 +81759,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80761,7 +81774,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80776,7 +81789,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80791,7 +81804,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80806,7 +81819,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80821,7 +81834,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80836,7 +81849,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80926,7 +81939,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80941,7 +81954,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80956,7 +81969,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80999,7 +82012,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Person\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -81116,10 +82129,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -81127,11 +82142,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -81145,6 +82158,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -81196,11 +82220,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81230,11 +82250,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81282,11 +82298,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81324,11 +82336,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81366,11 +82374,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81400,11 +82404,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81434,11 +82434,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81468,11 +82464,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81502,11 +82494,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81536,11 +82524,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81663,11 +82647,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81717,11 +82697,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81771,11 +82747,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81826,7 +82798,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -82808,7 +83792,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_oKrwxU4V8wiKhMW1QEYQibcJh8c_units) { const item = ( - v == \\"cm\\" || v == \\"feet\\" || v == \\"inches\\" || v == \\"km\\" || v == \\"m\\" || v == \\"miles\\" ? v : v.href + v == \\"cm\\" || v == \\"feet\\" || v == \\"inches\\" || v == \\"km\\" || v == \\"m\\" || v == \\"miles\\" ? v : formatIri(v) ); compactItems.push(item); } @@ -82822,7 +83806,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Place\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -82933,7 +83917,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_oKrwxU4V8wiKhMW1QEYQibcJh8c_units) { const element = ( - v == \\"cm\\" || v == \\"feet\\" || v == \\"inches\\" || v == \\"km\\" || v == \\"m\\" || v == \\"miles\\" ? { \\"@value\\": v } : { \\"@id\\": v.href } + v == \\"cm\\" || v == \\"feet\\" || v == \\"inches\\" || v == \\"km\\" || v == \\"m\\" || v == \\"miles\\" ? { \\"@value\\": v } : { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -82946,7 +83930,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Place\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -83053,10 +84037,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -83064,11 +84050,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -83082,6 +84066,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -83198,22 +84193,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu typeof v === \\"object\\" && \\"@value\\" in v && (v[\\"@value\\"] == \\"cm\\" || v[\\"@value\\"] == \\"feet\\" || v[\\"@value\\"] == \\"inches\\" || v[\\"@value\\"] == \\"km\\" || v[\\"@value\\"] == \\"m\\" || v[\\"@value\\"] == \\"miles\\") ? v[\\"@value\\"] : v != null && typeof v === \\"object\\" && \\"@id\\" in v && typeof v[\\"@id\\"] === \\"string\\" - && v[\\"@id\\"] !== \\"\\" ? v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl) : undefined + && v[\\"@id\\"] !== \\"\\" ? parseIri(v[\\"@id\\"], options.baseUrl) : undefined ; if (typeof decoded === \\"undefined\\") continue; _oKrwxU4V8wiKhMW1QEYQibcJh8c_units.push(decoded); @@ -83223,7 +84203,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -83530,9 +84522,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -83542,21 +84535,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#describes_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -83585,7 +84577,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -83671,8 +84663,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.length < 1) return null; let v = this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.has(0)) { v = v.id; } @@ -83711,8 +84704,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -83779,7 +84772,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -83797,7 +84790,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Profile\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -83818,7 +84811,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -83831,7 +84824,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Profile\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -83938,10 +84931,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -83949,11 +84944,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -83967,6 +84960,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -83994,11 +84998,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -84013,7 +85013,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -84429,9 +85441,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -84441,21 +85454,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#exclusiveOption_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -84484,7 +85496,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -84571,8 +85583,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti const vs = this.#_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.has(i)) { v = v.id; } @@ -84612,9 +85625,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -84659,9 +85672,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -84671,21 +85685,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inclusiveOption_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -84714,7 +85727,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -84801,8 +85814,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti const vs = this.#_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.has(i)) { v = v.id; } @@ -84842,9 +85856,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -84919,9 +85933,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -84931,21 +85946,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -84974,7 +85988,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -85061,8 +86075,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -85101,8 +86116,8 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -85170,9 +86185,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -85182,21 +86198,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -85225,7 +86240,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -85311,8 +86326,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -85351,8 +86367,8 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -85421,7 +86437,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85436,7 +86452,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85487,7 +86503,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85502,7 +86518,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { \\"@value\\": v.href } + { \\"@value\\": formatIri(v) } ); array.push(element);; } @@ -85521,7 +86537,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85534,7 +86550,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Question\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -85641,10 +86657,12 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -85652,11 +86670,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -85670,6 +86686,17 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -85697,11 +86724,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -85731,11 +86754,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -85814,11 +86833,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -85851,7 +86866,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti ) { if (v == null) continue; - const decoded = new URL(v[\\"@value\\"]); + const decoded = parseIri(v[\\"@value\\"]); if (typeof decoded === \\"undefined\\") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -85874,11 +86889,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -85893,7 +86904,19 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -86225,7 +87248,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Read\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -86332,10 +87355,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -86343,11 +87368,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -86361,6 +87384,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -86373,7 +87407,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -86562,7 +87608,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Reject\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -86669,10 +87715,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -86680,11 +87728,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -86702,6 +87748,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -86714,7 +87771,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -87075,9 +88144,10 @@ relationships?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -87087,21 +88157,20 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#subject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -87130,7 +88199,7 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -87218,8 +88287,9 @@ relationships?: (Object | URL)[];} } if (this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.length < 1) return null; let v = this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.has(0)) { v = v.id; } @@ -87258,8 +88328,8 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -87304,9 +88374,10 @@ relationships?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -87316,21 +88387,20 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#object_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -87359,7 +88429,7 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -87444,8 +88514,9 @@ relationships?: (Object | URL)[];} } if (this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.length < 1) return null; let v = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { v = v.id; } @@ -87484,8 +88555,8 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -87548,8 +88619,9 @@ relationships?: (Object | URL)[];} const vs = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { v = v.id; } @@ -87589,9 +88661,9 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -87636,9 +88708,10 @@ relationships?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -87648,21 +88721,20 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#relationship_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -87691,7 +88763,7 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -87778,8 +88850,9 @@ relationships?: (Object | URL)[];} } if (this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.length < 1) return null; let v = this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(0)) { v = v.id; } @@ -87818,8 +88891,8 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -87884,8 +88957,9 @@ relationships?: (Object | URL)[];} const vs = this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(i)) { v = v.id; } @@ -87925,9 +88999,9 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -87994,7 +89068,7 @@ relationships?: (Object | URL)[];} compactItems = []; for (const v of this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -88014,7 +89088,7 @@ relationships?: (Object | URL)[];} compactItems = []; for (const v of this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -88034,7 +89108,7 @@ relationships?: (Object | URL)[];} compactItems = []; for (const v of this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -88052,7 +89126,7 @@ relationships?: (Object | URL)[];} } result[\\"type\\"] = \\"Relationship\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -88073,7 +89147,7 @@ relationships?: (Object | URL)[];} array = []; for (const v of this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -88088,7 +89162,7 @@ relationships?: (Object | URL)[];} array = []; for (const v of this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -88103,7 +89177,7 @@ relationships?: (Object | URL)[];} array = []; for (const v of this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -88116,7 +89190,7 @@ relationships?: (Object | URL)[];} } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Relationship\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -88223,10 +89297,12 @@ relationships?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -88234,11 +89310,9 @@ relationships?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -88252,6 +89326,17 @@ relationships?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -88279,11 +89364,7 @@ relationships?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -88313,11 +89394,7 @@ relationships?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -88347,11 +89424,7 @@ relationships?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -88366,7 +89439,19 @@ relationships?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -88627,7 +89712,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Remove\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -88734,10 +89819,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -88745,11 +89832,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -88763,6 +89848,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -88775,7 +89871,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -89860,9 +90968,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -89872,21 +90981,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -89915,7 +91023,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -89999,8 +91107,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -90039,8 +91148,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -90102,8 +91211,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -90143,9 +91253,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -90190,9 +91300,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -90202,21 +91313,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -90245,7 +91355,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -90333,8 +91443,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -90373,8 +91484,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -90440,8 +91551,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -90481,9 +91593,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -90547,9 +91659,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -90559,21 +91672,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -90602,7 +91714,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -90708,8 +91820,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -90748,8 +91861,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -90794,9 +91907,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -90806,21 +91920,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -90849,7 +91962,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -90952,8 +92065,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -90992,8 +92106,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91038,9 +92152,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91050,21 +92165,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -91093,7 +92207,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91182,8 +92296,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -91222,8 +92337,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91268,9 +92383,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91280,21 +92396,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -91323,7 +92438,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91415,8 +92530,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -91455,8 +92571,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91501,9 +92617,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91513,21 +92630,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -91556,7 +92672,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91646,8 +92762,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -91686,8 +92803,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91732,9 +92849,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91744,21 +92862,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -91787,7 +92904,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91875,8 +92992,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -91915,8 +93033,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91961,9 +93079,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91973,21 +93092,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -92016,7 +93134,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92104,8 +93222,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -92144,8 +93263,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -92190,9 +93309,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -92202,21 +93322,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -92245,7 +93364,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92330,8 +93449,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -92371,9 +93491,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -92493,9 +93613,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -92505,21 +93626,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -92548,7 +93668,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92668,8 +93788,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -92708,8 +93829,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -92754,9 +93875,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -92766,21 +93888,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -92809,7 +93930,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92933,8 +94054,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -92973,8 +94095,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -93040,8 +94162,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -93081,9 +94204,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -93128,9 +94251,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -93140,21 +94264,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -93183,7 +94306,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -93271,8 +94394,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -93311,8 +94435,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -93378,8 +94502,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -93419,9 +94544,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -93538,7 +94663,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93558,7 +94683,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93594,7 +94719,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93618,7 +94743,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93642,7 +94767,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93662,7 +94787,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93682,7 +94807,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93702,7 +94827,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93722,7 +94847,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93742,7 +94867,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93846,7 +94971,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93882,7 +95007,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93918,7 +95043,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93968,7 +95093,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Service\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -94007,7 +95132,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94022,7 +95147,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94052,7 +95177,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94067,7 +95192,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94082,7 +95207,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94097,7 +95222,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94112,7 +95237,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94127,7 +95252,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94142,7 +95267,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94157,7 +95282,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94247,7 +95372,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94262,7 +95387,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94277,7 +95402,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94320,7 +95445,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Service\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -94437,10 +95562,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -94448,11 +95575,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -94466,6 +95591,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -94517,11 +95653,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94551,11 +95683,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94603,11 +95731,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94645,11 +95769,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94687,11 +95807,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94721,11 +95837,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94755,11 +95867,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94789,11 +95897,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94823,11 +95927,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94857,11 +95957,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94984,11 +96080,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -95038,11 +96130,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -95092,11 +96180,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -95147,7 +96231,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -95991,7 +97087,7 @@ get contents(): ((string | LanguageString))[] { } - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://www.w3.org/ns/activitystreams\\"; return result; } @@ -96033,7 +97129,7 @@ get contents(): ((string | LanguageString))[] { } - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -96134,10 +97230,12 @@ get contents(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -96145,11 +97243,9 @@ get contents(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -96163,8 +97259,21 @@ get contents(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content: ((string | LanguageString))[] = []; @@ -96212,7 +97321,19 @@ get contents(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -96462,7 +97583,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -96569,10 +97690,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -96580,11 +97703,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -96598,6 +97719,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -96610,7 +97742,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -96799,7 +97943,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#TentativeReject\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -96906,10 +98050,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -96917,11 +98063,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -96935,6 +98079,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -96947,7 +98102,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -97295,7 +98462,7 @@ get formerTypes(): (\$EntityType)[] { } result[\\"type\\"] = \\"Tombstone\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -97347,7 +98514,7 @@ get formerTypes(): (\$EntityType)[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Tombstone\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -97459,10 +98626,12 @@ get formerTypes(): (\$EntityType)[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -97470,11 +98639,9 @@ get formerTypes(): (\$EntityType)[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -97488,6 +98655,17 @@ get formerTypes(): (\$EntityType)[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -97553,7 +98731,19 @@ get formerTypes(): (\$EntityType)[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -97790,7 +98980,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Travel\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -97897,10 +99087,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -97908,11 +99100,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -97926,6 +99116,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -97938,7 +99139,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -98132,7 +99345,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Undo\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -98239,10 +99452,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -98250,11 +99465,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -98268,6 +99481,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -98280,7 +99504,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -98472,7 +99708,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Update\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -98579,10 +99815,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -98590,11 +99828,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -98608,6 +99844,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -98620,7 +99867,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -98793,7 +100052,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Video\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -98812,7 +100071,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Video\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -98919,10 +100178,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -98930,11 +100191,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -98948,6 +100207,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -98960,7 +100230,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -99148,7 +100430,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#View\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -99255,10 +100537,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -99266,11 +100550,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -99284,6 +100566,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -99296,7 +100589,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", diff --git a/packages/vocab-tools/src/__snapshots__/class.test.ts.node.snap b/packages/vocab-tools/src/__snapshots__/class.test.ts.node.snap index 5fe5c81bc..9c459b572 100644 --- a/packages/vocab-tools/src/__snapshots__/class.test.ts.node.snap +++ b/packages/vocab-tools/src/__snapshots__/class.test.ts.node.snap @@ -12,19 +12,29 @@ import { encodeMultibase, exportMultibaseKey, exportSpki, + formatIri, getDocumentLoader, importMultibaseKey, importPem, isDecimal, LanguageString, parseDecimal, + parseIri, + parseJsonLdId, type RemoteDocument } from \\"@fedify/vocab-runtime\\"; +import { + compactJsonLdCache, + getJsonLdContext, + isTrustedIriOrigin, + normalizeJsonLdIris +} from \\"@fedify/vocab-runtime/internal/jsonld-cache\\"; import { isTemporalDuration, isTemporalInstant, } from \\"@fedify/vocab-runtime/temporal\\"; - +const PORTABLE_IRI_PATTERN = /^ap(?:\\\\+ef61)?:\\\\/\\\\//i; +const PORTABLE_IRI_KEYS: ReadonlySet = new Set([\\"@id\\",\\"_misskey_quote\\",\\"actor\\",\\"alsoKnownAs\\",\\"announceAuthorization\\",\\"anyOf\\",\\"approvedBy\\",\\"assertionMethod\\",\\"attachment\\",\\"attributedTo\\",\\"audience\\",\\"automaticApproval\\",\\"bcc\\",\\"bto\\",\\"cc\\",\\"context\\",\\"controller\\",\\"current\\",\\"describes\\",\\"emojiReactions\\",\\"featured\\",\\"featuredTags\\",\\"first\\",\\"followers\\",\\"followersOf\\",\\"following\\",\\"followingOf\\",\\"generator\\",\\"href\\",\\"http://fedibird.com/ns#emojiReactions\\",\\"http://fedibird.com/ns#quoteUri\\",\\"http://joinmastodon.org/ns#featured\\",\\"http://joinmastodon.org/ns#featuredTags\\",\\"http://www.w3.org/ns/ldp#inbox\\",\\"https://gotosocial.org/ns#announceAuthorization\\",\\"https://gotosocial.org/ns#approvedBy\\",\\"https://gotosocial.org/ns#automaticApproval\\",\\"https://gotosocial.org/ns#interactingObject\\",\\"https://gotosocial.org/ns#interactionTarget\\",\\"https://gotosocial.org/ns#likeAuthorization\\",\\"https://gotosocial.org/ns#manualApproval\\",\\"https://gotosocial.org/ns#replyAuthorization\\",\\"https://misskey-hub.net/ns#_misskey_quote\\",\\"https://w3id.org/fep/044f#quote\\",\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"https://w3id.org/fep/5711#followersOf\\",\\"https://w3id.org/fep/5711#followingOf\\",\\"https://w3id.org/fep/5711#inboxOf\\",\\"https://w3id.org/fep/5711#likedOf\\",\\"https://w3id.org/fep/5711#likesOf\\",\\"https://w3id.org/fep/5711#outboxOf\\",\\"https://w3id.org/fep/5711#repliesOf\\",\\"https://w3id.org/fep/5711#sharesOf\\",\\"https://w3id.org/security#assertionMethod\\",\\"https://w3id.org/security#controller\\",\\"https://w3id.org/security#owner\\",\\"https://w3id.org/security#proof\\",\\"https://w3id.org/security#publicKey\\",\\"https://w3id.org/security#verificationMethod\\",\\"https://w3id.org/valueflows/ont/vf#resourceConformsTo\\",\\"https://w3id.org/valueflows/ont/vf#satisfies\\",\\"https://www.w3.org/ns/activitystreams#actor\\",\\"https://www.w3.org/ns/activitystreams#alsoKnownAs\\",\\"https://www.w3.org/ns/activitystreams#anyOf\\",\\"https://www.w3.org/ns/activitystreams#attachment\\",\\"https://www.w3.org/ns/activitystreams#attributedTo\\",\\"https://www.w3.org/ns/activitystreams#audience\\",\\"https://www.w3.org/ns/activitystreams#bcc\\",\\"https://www.w3.org/ns/activitystreams#bto\\",\\"https://www.w3.org/ns/activitystreams#cc\\",\\"https://www.w3.org/ns/activitystreams#context\\",\\"https://www.w3.org/ns/activitystreams#current\\",\\"https://www.w3.org/ns/activitystreams#describes\\",\\"https://www.w3.org/ns/activitystreams#first\\",\\"https://www.w3.org/ns/activitystreams#followers\\",\\"https://www.w3.org/ns/activitystreams#following\\",\\"https://www.w3.org/ns/activitystreams#generator\\",\\"https://www.w3.org/ns/activitystreams#href\\",\\"https://www.w3.org/ns/activitystreams#icon\\",\\"https://www.w3.org/ns/activitystreams#image\\",\\"https://www.w3.org/ns/activitystreams#inReplyTo\\",\\"https://www.w3.org/ns/activitystreams#instrument\\",\\"https://www.w3.org/ns/activitystreams#items\\",\\"https://www.w3.org/ns/activitystreams#last\\",\\"https://www.w3.org/ns/activitystreams#liked\\",\\"https://www.w3.org/ns/activitystreams#likes\\",\\"https://www.w3.org/ns/activitystreams#location\\",\\"https://www.w3.org/ns/activitystreams#movedTo\\",\\"https://www.w3.org/ns/activitystreams#next\\",\\"https://www.w3.org/ns/activitystreams#oauthAuthorizationEndpoint\\",\\"https://www.w3.org/ns/activitystreams#oauthTokenEndpoint\\",\\"https://www.w3.org/ns/activitystreams#object\\",\\"https://www.w3.org/ns/activitystreams#oneOf\\",\\"https://www.w3.org/ns/activitystreams#origin\\",\\"https://www.w3.org/ns/activitystreams#outbox\\",\\"https://www.w3.org/ns/activitystreams#partOf\\",\\"https://www.w3.org/ns/activitystreams#prev\\",\\"https://www.w3.org/ns/activitystreams#preview\\",\\"https://www.w3.org/ns/activitystreams#provideClientKey\\",\\"https://www.w3.org/ns/activitystreams#proxyUrl\\",\\"https://www.w3.org/ns/activitystreams#quoteUrl\\",\\"https://www.w3.org/ns/activitystreams#relationship\\",\\"https://www.w3.org/ns/activitystreams#replies\\",\\"https://www.w3.org/ns/activitystreams#result\\",\\"https://www.w3.org/ns/activitystreams#sharedInbox\\",\\"https://www.w3.org/ns/activitystreams#shares\\",\\"https://www.w3.org/ns/activitystreams#signClientKey\\",\\"https://www.w3.org/ns/activitystreams#streams\\",\\"https://www.w3.org/ns/activitystreams#subject\\",\\"https://www.w3.org/ns/activitystreams#tag\\",\\"https://www.w3.org/ns/activitystreams#target\\",\\"https://www.w3.org/ns/activitystreams#to\\",\\"https://www.w3.org/ns/activitystreams#units\\",\\"https://www.w3.org/ns/activitystreams#url\\",\\"https://www.w3.org/ns/did#service\\",\\"https://www.w3.org/ns/did#serviceEndpoint\\",\\"icon\\",\\"id\\",\\"image\\",\\"inReplyTo\\",\\"inbox\\",\\"inboxOf\\",\\"instrument\\",\\"interactingObject\\",\\"interactionTarget\\",\\"items\\",\\"last\\",\\"likeAuthorization\\",\\"liked\\",\\"likedOf\\",\\"likes\\",\\"likesOf\\",\\"location\\",\\"manualApproval\\",\\"movedTo\\",\\"next\\",\\"oauthAuthorizationEndpoint\\",\\"oauthTokenEndpoint\\",\\"object\\",\\"oneOf\\",\\"orderedItems\\",\\"origin\\",\\"outbox\\",\\"outboxOf\\",\\"owner\\",\\"partOf\\",\\"prev\\",\\"preview\\",\\"proof\\",\\"provideClientKey\\",\\"proxyUrl\\",\\"publicKey\\",\\"quote\\",\\"quoteAuthorization\\",\\"quoteUri\\",\\"quoteUrl\\",\\"relationship\\",\\"replies\\",\\"repliesOf\\",\\"replyAuthorization\\",\\"resourceConformsTo\\",\\"result\\",\\"satisfies\\",\\"service\\",\\"sharedInbox\\",\\"shares\\",\\"sharesOf\\",\\"signClientKey\\",\\"streams\\",\\"subject\\",\\"tag\\",\\"target\\",\\"to\\",\\"units\\",\\"url\\"]); import * as _ppM0 from \\"./preprocessors.ts\\"; @@ -2155,9 +2165,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -2167,21 +2178,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#attachment_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -2210,7 +2220,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -2315,8 +2325,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_49BipA5dq9eoH8LX8xdsVumveTca_attachment.has(i)) { v = v.id; } @@ -2356,9 +2367,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_49BipA5dq9eoH8LX8xdsVumveTca_attachment.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_49BipA5dq9eoH8LX8xdsVumveTca_attachment.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -2403,9 +2414,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -2415,21 +2427,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#attribution_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -2458,7 +2469,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -2581,8 +2592,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.length < 1) return null; let v = this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(0)) { v = v.id; } @@ -2621,8 +2633,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -2687,8 +2699,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(i)) { v = v.id; } @@ -2728,9 +2741,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -2775,9 +2788,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -2787,21 +2801,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#audience_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -2830,7 +2843,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -2916,8 +2929,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.length < 1) return null; let v = this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(0)) { v = v.id; } @@ -2956,8 +2970,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -3021,8 +3035,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(i)) { v = v.id; } @@ -3062,9 +3077,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -3138,9 +3153,10 @@ get contents(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -3150,21 +3166,20 @@ get contents(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#context_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -3193,7 +3208,7 @@ get contents(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -3293,8 +3308,9 @@ get contents(): ((string | LanguageString))[] { const vs = this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3mhZzGXSpQ431mBSz2kvych22v4e_context.has(i)) { v = v.id; } @@ -3334,9 +3350,9 @@ get contents(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3mhZzGXSpQ431mBSz2kvych22v4e_context.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3mhZzGXSpQ431mBSz2kvych22v4e_context.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -3423,9 +3439,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -3435,21 +3452,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#generator_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -3478,7 +3494,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -3572,8 +3588,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_86xFhmgBapoMvYqjbjRuDPayTrS_generator.has(i)) { v = v.id; } @@ -3613,9 +3630,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_86xFhmgBapoMvYqjbjRuDPayTrS_generator.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_86xFhmgBapoMvYqjbjRuDPayTrS_generator.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -3660,9 +3677,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -3672,21 +3690,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#icon_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -3715,7 +3732,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -3823,8 +3840,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.length < 1) return null; let v = this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(0)) { v = v.id; } @@ -3863,8 +3881,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -3929,8 +3947,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(i)) { v = v.id; } @@ -3970,9 +3989,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -4017,9 +4036,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -4029,21 +4049,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#image_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -4072,7 +4091,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -4180,8 +4199,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.length < 1) return null; let v = this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(0)) { v = v.id; } @@ -4220,8 +4240,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -4286,8 +4306,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(i)) { v = v.id; } @@ -4327,9 +4348,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -4374,9 +4395,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -4386,21 +4408,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#replyTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -4429,7 +4450,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -4524,8 +4545,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.length < 1) return null; let v = this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(0)) { v = v.id; } @@ -4564,8 +4586,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -4629,8 +4651,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(i)) { v = v.id; } @@ -4670,9 +4693,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -4717,9 +4740,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -4729,21 +4753,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#location_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -4772,7 +4795,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -4867,8 +4890,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.length < 1) return null; let v = this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(0)) { v = v.id; } @@ -4907,8 +4931,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -4972,8 +4996,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(i)) { v = v.id; } @@ -5013,9 +5038,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -5060,9 +5085,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5072,21 +5098,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#preview_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -5115,7 +5140,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -5209,8 +5234,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview.length < 1) return null; let v = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { v = v.id; } @@ -5249,8 +5275,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -5313,8 +5339,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { v = v.id; } @@ -5354,9 +5381,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -5414,9 +5441,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5426,21 +5454,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#replies_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -5469,7 +5496,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -5555,8 +5582,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_7UpwM3JWcXhADcscukEehBorf6k_replies.length < 1) return null; let v = this.#_7UpwM3JWcXhADcscukEehBorf6k_replies[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_7UpwM3JWcXhADcscukEehBorf6k_replies.has(0)) { v = v.id; } @@ -5595,8 +5623,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_7UpwM3JWcXhADcscukEehBorf6k_replies.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -5641,9 +5669,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5653,21 +5682,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#shares_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -5696,7 +5724,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -5788,8 +5816,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares.length < 1) return null; let v = this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3kAfck9PcEYt2L7xug5y99YPbANs_shares.has(0)) { v = v.id; } @@ -5828,8 +5857,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3kAfck9PcEYt2L7xug5y99YPbANs_shares.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -5874,9 +5903,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5886,21 +5916,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likes_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -5929,7 +5958,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6021,8 +6050,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.length < 1) return null; let v = this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.has(0)) { v = v.id; } @@ -6061,8 +6091,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -6107,9 +6137,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6119,21 +6150,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#emojiReactions_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -6162,7 +6192,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6248,8 +6278,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.length < 1) return null; let v = this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.has(0)) { v = v.id; } @@ -6288,8 +6319,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -6374,9 +6405,10 @@ get summaries(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6386,21 +6418,20 @@ get summaries(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#tag_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -6429,7 +6460,7 @@ get summaries(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6526,8 +6557,9 @@ get summaries(): ((string | LanguageString))[] { const vs = this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_5chuqj6s95p5gg2sk1HntGfarRf_tag.has(i)) { v = v.id; } @@ -6567,9 +6599,9 @@ get summaries(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_5chuqj6s95p5gg2sk1HntGfarRf_tag.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_5chuqj6s95p5gg2sk1HntGfarRf_tag.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -6648,9 +6680,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6660,21 +6693,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#to_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -6703,7 +6735,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6789,8 +6821,9 @@ get urls(): ((URL | Link))[] { } if (this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.length < 1) return null; let v = this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(0)) { v = v.id; } @@ -6829,8 +6862,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -6894,8 +6927,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(i)) { v = v.id; } @@ -6935,9 +6969,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -6982,9 +7016,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6994,21 +7029,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#bto_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -7037,7 +7071,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -7123,8 +7157,9 @@ get urls(): ((URL | Link))[] { } if (this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.length < 1) return null; let v = this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(0)) { v = v.id; } @@ -7163,8 +7198,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -7228,8 +7263,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(i)) { v = v.id; } @@ -7269,9 +7305,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -7316,9 +7352,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -7328,21 +7365,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#cc_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -7371,7 +7407,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -7457,8 +7493,9 @@ get urls(): ((URL | Link))[] { } if (this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.length < 1) return null; let v = this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(0)) { v = v.id; } @@ -7497,8 +7534,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -7562,8 +7599,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(i)) { v = v.id; } @@ -7603,9 +7641,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -7650,9 +7688,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -7662,21 +7701,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#bcc_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -7705,7 +7743,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -7791,8 +7829,9 @@ get urls(): ((URL | Link))[] { } if (this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.length < 1) return null; let v = this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(0)) { v = v.id; } @@ -7831,8 +7870,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -7896,8 +7935,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(i)) { v = v.id; } @@ -7937,9 +7977,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -8048,9 +8088,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8060,21 +8101,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#proof_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -8103,7 +8143,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -8188,8 +8228,9 @@ get urls(): ((URL | Link))[] { } if (this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.length < 1) return null; let v = this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(0)) { v = v.id; } @@ -8228,8 +8269,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -8292,8 +8333,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(i)) { v = v.id; } @@ -8333,9 +8375,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -8419,9 +8461,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8431,21 +8474,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likeAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -8474,7 +8516,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -8560,8 +8602,9 @@ get urls(): ((URL | Link))[] { } if (this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.length < 1) return null; let v = this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.has(0)) { v = v.id; } @@ -8600,8 +8643,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -8646,9 +8689,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8658,21 +8702,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#replyAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -8701,7 +8744,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -8787,8 +8830,9 @@ get urls(): ((URL | Link))[] { } if (this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.length < 1) return null; let v = this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.has(0)) { v = v.id; } @@ -8827,8 +8871,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -8873,9 +8917,10 @@ get urls(): ((URL | Link))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8885,21 +8930,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#announceAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -8928,7 +8972,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -9014,8 +9058,9 @@ get urls(): ((URL | Link))[] { } if (this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.length < 1) return null; let v = this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.has(0)) { v = v.id; } @@ -9054,8 +9099,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -9116,7 +9161,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9144,7 +9189,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9180,7 +9225,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9219,7 +9264,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9278,7 +9323,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9302,7 +9347,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9322,7 +9367,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9342,7 +9387,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9366,7 +9411,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9390,7 +9435,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const item = ( - v instanceof URL ? v.href : v instanceof Link ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Link ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9430,7 +9475,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_7UpwM3JWcXhADcscukEehBorf6k_replies) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9450,7 +9495,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9470,7 +9515,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9490,7 +9535,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9545,7 +9590,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9585,7 +9630,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9605,7 +9650,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9625,7 +9670,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9645,7 +9690,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9665,7 +9710,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9753,7 +9798,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9793,7 +9838,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_23YiVs2miQcEiUdn4u8SvjQKWYim_approvedBy) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -9809,7 +9854,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9829,7 +9874,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9849,7 +9894,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9867,7 +9912,7 @@ get urls(): ((URL | Link))[] { } result[\\"type\\"] = \\"Object\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -9878,7 +9923,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -9893,7 +9938,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -9908,7 +9953,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -9941,7 +9986,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -9992,7 +10037,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10007,7 +10052,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10022,7 +10067,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10037,7 +10082,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10052,7 +10097,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10067,7 +10112,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10100,7 +10145,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_7UpwM3JWcXhADcscukEehBorf6k_replies) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10115,7 +10160,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10130,7 +10175,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10145,7 +10190,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10196,7 +10241,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10229,7 +10274,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10244,7 +10289,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10259,7 +10304,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10274,7 +10319,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10289,7 +10334,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10367,7 +10412,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push({ \\"@graph\\": element });; } @@ -10397,7 +10442,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_23YiVs2miQcEiUdn4u8SvjQKWYim_approvedBy) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -10412,7 +10457,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10427,7 +10472,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10442,7 +10487,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10455,7 +10500,7 @@ get urls(): ((URL | Link))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Object\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -10587,10 +10632,12 @@ get urls(): ((URL | Link))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -10598,11 +10645,9 @@ get urls(): ((URL | Link))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -10872,8 +10917,21 @@ get urls(): ((URL | Link))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); @@ -10894,11 +10952,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _49BipA5dq9eoH8LX8xdsVumveTca_attachment.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _49BipA5dq9eoH8LX8xdsVumveTca_attachment.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -10942,11 +10996,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -10996,11 +11046,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11054,11 +11100,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3mhZzGXSpQ431mBSz2kvych22v4e_context.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3mhZzGXSpQ431mBSz2kvych22v4e_context.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11144,11 +11186,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _86xFhmgBapoMvYqjbjRuDPayTrS_generator.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _86xFhmgBapoMvYqjbjRuDPayTrS_generator.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11210,11 +11248,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11266,11 +11300,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3dXrUdkARxwyJLtJcYi1AJ92H41U_image.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3dXrUdkARxwyJLtJcYi1AJ92H41U_image.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11300,11 +11330,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11344,11 +11370,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _31k5MUZJsnsPNg8dQQJieWaXTFnR_location.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _31k5MUZJsnsPNg8dQQJieWaXTFnR_location.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11388,11 +11410,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11454,11 +11472,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _7UpwM3JWcXhADcscukEehBorf6k_replies.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _7UpwM3JWcXhADcscukEehBorf6k_replies.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11488,11 +11502,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3kAfck9PcEYt2L7xug5y99YPbANs_shares.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3kAfck9PcEYt2L7xug5y99YPbANs_shares.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11522,11 +11532,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11556,11 +11562,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11636,11 +11638,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _5chuqj6s95p5gg2sk1HntGfarRf_tag.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _5chuqj6s95p5gg2sk1HntGfarRf_tag.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11700,22 +11698,7 @@ get urls(): ((URL | Link))[] { const decoded = v != null && typeof v === \\"object\\" && \\"@id\\" in v && typeof v[\\"@id\\"] === \\"string\\" - && v[\\"@id\\"] !== \\"\\" ? v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl) : typeof v === \\"object\\" && \\"@type\\" in v + && v[\\"@id\\"] !== \\"\\" ? parseIri(v[\\"@id\\"], options.baseUrl) : typeof v === \\"object\\" && \\"@type\\" in v && Array.isArray(v[\\"@type\\"])&& [\\"https://www.w3.org/ns/activitystreams#Link\\",\\"https://www.w3.org/ns/activitystreams#Hashtag\\",\\"https://www.w3.org/ns/activitystreams#Mention\\"].some( t => v[\\"@type\\"].includes(t)) ? await Link.fromJsonLd( v, @@ -11745,11 +11728,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11779,11 +11758,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11813,11 +11788,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11847,11 +11818,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -11956,11 +11923,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -12006,22 +11969,7 @@ get urls(): ((URL | Link))[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _23YiVs2miQcEiUdn4u8SvjQKWYim_approvedBy.push(decoded); } @@ -12044,11 +11992,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -12078,11 +12022,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -12112,11 +12052,7 @@ get urls(): ((URL | Link))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -12131,7 +12067,19 @@ get urls(): ((URL | Link))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -13163,7 +13111,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Emoji\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\"}]; return result; } @@ -13182,7 +13130,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"http://joinmastodon.org/ns#Emoji\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -13289,10 +13237,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -13300,11 +13250,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -13318,6 +13266,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -13330,7 +13289,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -13573,9 +13544,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -13585,21 +13557,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -13628,7 +13599,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -13715,8 +13686,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -13755,8 +13727,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -13824,9 +13796,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -13836,21 +13809,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -13879,7 +13851,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -13965,8 +13937,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -14005,8 +13978,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -14073,7 +14046,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -14093,7 +14066,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -14119,7 +14092,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -14137,7 +14110,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"ChatMessage\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -14158,7 +14131,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -14173,7 +14146,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { \\"@value\\": v.href } + { \\"@value\\": formatIri(v) } ); array.push(element);; } @@ -14192,7 +14165,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -14205,7 +14178,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"http://litepub.social/ns#ChatMessage\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -14312,10 +14285,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -14323,11 +14298,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -14341,6 +14314,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -14368,11 +14352,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -14405,7 +14385,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ) { if (v == null) continue; - const decoded = new URL(v[\\"@value\\"]); + const decoded = parseIri(v[\\"@value\\"]); if (typeof decoded === \\"undefined\\") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -14428,11 +14408,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -14447,7 +14423,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -15181,9 +15169,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -15193,21 +15182,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#actor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -15236,7 +15224,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -15359,8 +15347,9 @@ instruments?: (Object | URL)[];} } if (this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.length < 1) return null; let v = this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(0)) { v = v.id; } @@ -15399,8 +15388,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -15465,8 +15454,9 @@ instruments?: (Object | URL)[];} const vs = this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(i)) { v = v.id; } @@ -15506,9 +15496,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -15553,9 +15543,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -15565,21 +15556,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#object_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -15608,7 +15598,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -15695,8 +15685,9 @@ instruments?: (Object | URL)[];} } if (this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.length < 1) return null; let v = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { v = v.id; } @@ -15735,8 +15726,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -15801,8 +15792,9 @@ instruments?: (Object | URL)[];} const vs = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { v = v.id; } @@ -15842,9 +15834,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -15889,9 +15881,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -15901,21 +15894,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#target_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -15944,7 +15936,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -16034,8 +16026,9 @@ instruments?: (Object | URL)[];} } if (this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.length < 1) return null; let v = this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(0)) { v = v.id; } @@ -16074,8 +16067,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -16143,8 +16136,9 @@ instruments?: (Object | URL)[];} const vs = this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(i)) { v = v.id; } @@ -16184,9 +16178,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -16231,9 +16225,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -16243,21 +16238,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#result_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -16286,7 +16280,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -16373,8 +16367,9 @@ instruments?: (Object | URL)[];} } if (this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.length < 1) return null; let v = this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(0)) { v = v.id; } @@ -16413,8 +16408,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -16479,8 +16474,9 @@ instruments?: (Object | URL)[];} const vs = this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(i)) { v = v.id; } @@ -16520,9 +16516,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -16567,9 +16563,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -16579,21 +16576,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#origin_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -16622,7 +16618,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -16710,8 +16706,9 @@ instruments?: (Object | URL)[];} } if (this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin.length < 1) return null; let v = this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(0)) { v = v.id; } @@ -16750,8 +16747,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -16817,8 +16814,9 @@ instruments?: (Object | URL)[];} const vs = this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(i)) { v = v.id; } @@ -16858,9 +16856,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -16905,9 +16903,10 @@ instruments?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -16917,21 +16916,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#instrument_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -16960,7 +16958,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -17046,8 +17044,9 @@ instruments?: (Object | URL)[];} } if (this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.length < 1) return null; let v = this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(0)) { v = v.id; } @@ -17086,8 +17085,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -17151,8 +17150,9 @@ instruments?: (Object | URL)[];} const vs = this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(i)) { v = v.id; } @@ -17192,9 +17192,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -17263,7 +17263,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -17278,7 +17278,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17293,7 +17293,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17308,7 +17308,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17323,7 +17323,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17338,7 +17338,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17351,7 +17351,7 @@ instruments?: (Object | URL)[];} } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Activity\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -17458,10 +17458,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -17469,11 +17471,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -17623,6 +17623,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -17650,11 +17661,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17704,11 +17711,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17738,11 +17741,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17772,11 +17771,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17806,11 +17801,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _25zu2s3VxVujgEKqrDycjE284XQR_origin.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _25zu2s3VxVujgEKqrDycjE284XQR_origin.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17840,11 +17831,7 @@ instruments?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -17859,7 +17846,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -18203,7 +18202,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"http://litepub.social/ns#EmojiReact\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -18310,10 +18309,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -18321,11 +18322,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -18339,6 +18338,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -18351,7 +18361,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -18672,7 +18694,7 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} } result[\\"type\\"] = \\"PropertyValue\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\"}]; return result; } @@ -18717,7 +18739,7 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} } values[\\"@type\\"] = [\\"http://schema.org#PropertyValue\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -18823,10 +18845,12 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -18834,11 +18858,9 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -18852,8 +18874,21 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name: ((string | LanguageString))[] = []; @@ -18907,7 +18942,19 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -19281,7 +19328,7 @@ unit?: string | null;numericalValue?: Decimal | null;} } result[\\"type\\"] = \\"om2:Measure\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -19323,7 +19370,7 @@ unit?: string | null;numericalValue?: Decimal | null;} } values[\\"@type\\"] = [\\"http://www.ontology-of-units-of-measure.org/resource/om-2/Measure\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -19419,10 +19466,12 @@ unit?: string | null;numericalValue?: Decimal | null;} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -19430,11 +19479,9 @@ unit?: string | null;numericalValue?: Decimal | null;} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -19448,8 +19495,21 @@ unit?: string | null;numericalValue?: Decimal | null;} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _27fgyFbosTtMAhuepJH8K3ZGURT6: (string)[] = []; @@ -19491,7 +19551,19 @@ unit?: string | null;numericalValue?: Decimal | null;} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -19766,9 +19838,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -19778,21 +19851,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -19821,7 +19893,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -19907,8 +19979,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -19947,8 +20020,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -19993,9 +20066,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -20005,21 +20079,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -20048,7 +20121,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -20133,8 +20206,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -20173,8 +20247,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -20241,7 +20315,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -20261,7 +20335,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -20279,7 +20353,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"AnnounceAuthorization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -20300,7 +20374,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -20315,7 +20389,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -20328,7 +20402,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://gotosocial.org/ns#AnnounceAuthorization\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -20435,10 +20509,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -20446,11 +20522,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -20464,6 +20538,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -20491,11 +20576,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -20525,11 +20606,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -20544,7 +20621,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -20782,7 +20871,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://gotosocial.org/ns#AnnounceRequest\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -20889,10 +20978,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -20900,11 +20991,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -20918,6 +21007,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -20930,7 +21030,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -21374,7 +21486,7 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: } - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -21490,10 +21602,12 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -21501,11 +21615,9 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -21519,8 +21631,21 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike: (InteractionRule)[] = []; @@ -21610,7 +21735,19 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -22124,7 +22261,7 @@ get manualApprovals(): (URL)[] { array = []; for (const v of this.#_2rFyCF14HoyNjitj9PmCzek5iSsg_automaticApproval) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -22139,7 +22276,7 @@ get manualApprovals(): (URL)[] { array = []; for (const v of this.#_sxj8y5XMMMBWUnRYFw85MKedCMj_manualApproval) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -22152,7 +22289,7 @@ get manualApprovals(): (URL)[] { } - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -22248,10 +22385,12 @@ get manualApprovals(): (URL)[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -22259,11 +22398,9 @@ get manualApprovals(): (URL)[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -22277,8 +22414,21 @@ get manualApprovals(): (URL)[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _2rFyCF14HoyNjitj9PmCzek5iSsg_automaticApproval: (URL)[] = []; @@ -22294,22 +22444,7 @@ get manualApprovals(): (URL)[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _2rFyCF14HoyNjitj9PmCzek5iSsg_automaticApproval.push(decoded); } @@ -22327,22 +22462,7 @@ get manualApprovals(): (URL)[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _sxj8y5XMMMBWUnRYFw85MKedCMj_manualApproval.push(decoded); } @@ -22350,7 +22470,19 @@ get manualApprovals(): (URL)[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -22636,9 +22768,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -22648,21 +22781,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -22691,7 +22823,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -22777,8 +22909,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -22817,8 +22950,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -22863,9 +22996,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -22875,21 +23009,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -22918,7 +23051,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -23003,8 +23136,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -23043,8 +23177,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -23111,7 +23245,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -23131,7 +23265,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -23149,7 +23283,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"LikeAuthorization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -23170,7 +23304,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -23185,7 +23319,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -23198,7 +23332,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://gotosocial.org/ns#LikeApproval\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -23305,10 +23439,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -23316,11 +23452,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -23334,6 +23468,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -23361,11 +23506,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -23395,11 +23536,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -23414,7 +23551,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -23651,7 +23800,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://gotosocial.org/ns#LikeRequest\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -23758,10 +23907,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -23769,11 +23920,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -23787,6 +23936,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -23799,7 +23959,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -24018,9 +24190,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -24030,21 +24203,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -24073,7 +24245,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -24159,8 +24331,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -24199,8 +24372,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -24245,9 +24418,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -24257,21 +24431,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -24300,7 +24473,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -24385,8 +24558,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -24425,8 +24599,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -24493,7 +24667,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -24513,7 +24687,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -24531,7 +24705,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"ReplyAuthorization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -24552,7 +24726,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -24567,7 +24741,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -24580,7 +24754,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://gotosocial.org/ns#ReplyAuthorization\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -24687,10 +24861,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -24698,11 +24874,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -24716,6 +24890,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -24743,11 +24928,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -24777,11 +24958,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -24796,7 +24973,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -25033,7 +25222,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://gotosocial.org/ns#ReplyRequest\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -25140,10 +25329,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -25151,11 +25342,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -25169,6 +25358,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -25181,7 +25381,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -25400,9 +25612,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -25412,21 +25625,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -25455,7 +25667,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -25540,8 +25752,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -25580,8 +25793,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -25626,9 +25839,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -25638,21 +25852,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -25681,7 +25894,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -25766,8 +25979,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -25806,8 +26020,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -25874,7 +26088,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -25894,7 +26108,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -25912,7 +26126,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"QuoteAuthorization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\"}]; return result; } @@ -25933,7 +26147,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -25948,7 +26162,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -25961,7 +26175,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://w3id.org/fep/044f#QuoteAuthorization\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -26068,10 +26282,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -26079,11 +26295,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -26097,6 +26311,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -26124,11 +26349,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -26158,11 +26379,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -26177,7 +26394,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -26414,7 +26643,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://w3id.org/fep/044f#QuoteRequest\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -26521,10 +26750,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -26532,11 +26763,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -26550,6 +26779,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -26562,7 +26802,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -26867,7 +27119,7 @@ get endpoints(): (URL)[] { array = []; for (const v of this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -26880,7 +27132,7 @@ get endpoints(): (URL)[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/did#Service\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -26976,10 +27228,12 @@ get endpoints(): (URL)[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -26987,11 +27241,9 @@ get endpoints(): (URL)[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -27009,8 +27261,21 @@ get endpoints(): (URL)[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint: (URL)[] = []; @@ -27026,22 +27291,7 @@ get endpoints(): (URL)[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.push(decoded); } @@ -27049,7 +27299,19 @@ get endpoints(): (URL)[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -27236,7 +27498,7 @@ endpoints?: (URL)[];} >; values[\\"@type\\"] = [\\"https://w3id.org/fep/9091#Export\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -27332,10 +27594,12 @@ endpoints?: (URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -27343,11 +27607,9 @@ endpoints?: (URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -27361,6 +27623,17 @@ endpoints?: (URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -27373,7 +27646,19 @@ endpoints?: (URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -27719,9 +28004,10 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -27731,21 +28017,20 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#verificationMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -27774,7 +28059,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -27862,8 +28147,9 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | } if (this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.length < 1) return null; let v = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { v = v.id; } @@ -27877,8 +28163,8 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | return fetched; } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -27998,7 +28284,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | array = []; for (const v of this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -28064,7 +28350,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | } values[\\"@type\\"] = [\\"https://w3id.org/security#DataIntegrityProof\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -28160,10 +28446,12 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -28171,11 +28459,9 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -28189,8 +28475,21 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite: (\\"eddsa-jcs-2022\\")[] = []; @@ -28229,11 +28528,7 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -28306,7 +28601,19 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL | if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -28672,9 +28979,10 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -28684,21 +28992,20 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#owner_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -28727,7 +29034,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -28847,8 +29154,9 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } if (this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.length < 1) return null; let v = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { v = v.id; } @@ -28887,8 +29195,8 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -28962,7 +29270,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi compactItems = []; for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -29012,7 +29320,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } result[\\"type\\"] = \\"CryptographicKey\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://w3id.org/security/v1\\"; return result; } @@ -29023,7 +29331,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi array = []; for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -29051,7 +29359,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } values[\\"@type\\"] = [\\"https://w3id.org/security#Key\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -29147,10 +29455,12 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -29158,11 +29468,9 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -29176,8 +29484,21 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); @@ -29198,11 +29519,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -29255,7 +29572,19 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -29565,9 +29894,10 @@ controller?: Application | Group | Organization | Person | Service | URL | null; \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -29577,21 +29907,20 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#controller_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -29620,7 +29949,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -29740,8 +30069,9 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } if (this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.length < 1) return null; let v = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { v = v.id; } @@ -29780,8 +30110,8 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -29859,7 +30189,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; compactItems = []; for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -29909,7 +30239,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } result[\\"type\\"] = \\"Multikey\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://w3id.org/security/multikey/v1\\"; return result; } @@ -29920,7 +30250,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; array = []; for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -29951,7 +30281,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } values[\\"@type\\"] = [\\"https://w3id.org/security#Multikey\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -30047,10 +30377,12 @@ controller?: Application | Group | Organization | Person | Service | URL | null; }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -30058,11 +30390,9 @@ controller?: Application | Group | Organization | Person | Service | URL | null; // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -30076,8 +30406,21 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); @@ -30098,11 +30441,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -30155,7 +30494,19 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -30521,7 +30872,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Agreement\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Agreement\\":\\"vf:Agreement\\",\\"Commitment\\":\\"vf:Commitment\\",\\"stipulates\\":\\"vf:stipulates\\",\\"stipulatesReciprocal\\":\\"vf:stipulatesReciprocal\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -30570,7 +30921,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Agreement\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -30677,10 +31028,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -30688,11 +31041,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -30706,6 +31057,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -30760,7 +31122,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -31097,7 +31471,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} compactItems = []; for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -31131,7 +31505,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} } result[\\"type\\"] = \\"Commitment\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Commitment\\":\\"vf:Commitment\\",\\"satisfies\\":{\\"@id\\":\\"vf:satisfies\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -31142,7 +31516,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} array = []; for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -31170,7 +31544,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} } values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Commitment\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -31266,10 +31640,12 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -31277,11 +31653,9 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -31295,8 +31669,21 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies: (URL)[] = []; @@ -31312,22 +31699,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies.push(decoded); } @@ -31356,7 +31728,19 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -31840,7 +32224,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur compactItems = []; for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -31914,7 +32298,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur } result[\\"type\\"] = \\"Intent\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"Intent\\":\\"vf:Intent\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -31940,7 +32324,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur array = []; for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -31998,7 +32382,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur } values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Intent\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -32094,10 +32478,12 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -32105,11 +32491,9 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -32123,8 +32507,21 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _38VmZKmXJSBy3AvgqNa9GVqbdphy_action: (string)[] = []; @@ -32158,22 +32555,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo.push(decoded); } @@ -32244,7 +32626,19 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -32783,7 +33177,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Proposal\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"vf\\":\\"https://w3id.org/valueflows/ont/vf#\\",\\"om2\\":\\"http://www.ontology-of-units-of-measure.org/resource/om-2/\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"},\\"Proposal\\":\\"vf:Proposal\\",\\"Intent\\":\\"vf:Intent\\",\\"purpose\\":\\"vf:purpose\\",\\"unitBased\\":\\"vf:unitBased\\",\\"publishes\\":\\"vf:publishes\\",\\"reciprocal\\":\\"vf:reciprocal\\",\\"action\\":\\"vf:action\\",\\"resourceConformsTo\\":{\\"@id\\":\\"vf:resourceConformsTo\\",\\"@type\\":\\"@id\\"},\\"resourceQuantity\\":\\"vf:resourceQuantity\\",\\"availableQuantity\\":\\"vf:availableQuantity\\",\\"minimumQuantity\\":\\"vf:minimumQuantity\\",\\"hasUnit\\":\\"om2:hasUnit\\",\\"hasNumericalValue\\":\\"om2:hasNumericalValue\\"}]; return result; } @@ -32862,7 +33256,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://w3id.org/valueflows/ont/vf#Proposal\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -32969,10 +33363,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -32980,11 +33376,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -32998,6 +33392,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -33088,7 +33493,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -33358,7 +33775,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Accept\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -33465,10 +33882,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -33476,11 +33895,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -33498,6 +33915,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -33510,7 +33938,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -33701,7 +34141,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Add\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -33808,10 +34248,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -33819,11 +34261,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -33837,6 +34277,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -33849,7 +34300,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -34039,7 +34502,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Announce\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -34146,10 +34609,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -34157,11 +34622,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -34175,6 +34638,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -34187,7 +34661,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -35272,9 +35758,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -35284,21 +35771,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -35327,7 +35813,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -35411,8 +35897,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -35451,8 +35938,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -35514,8 +36001,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -35555,9 +36043,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -35602,9 +36090,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -35614,21 +36103,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -35657,7 +36145,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -35745,8 +36233,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -35785,8 +36274,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -35852,8 +36341,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -35893,9 +36383,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -35959,9 +36449,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -35971,21 +36462,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36014,7 +36504,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36120,8 +36610,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -36160,8 +36651,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -36206,9 +36697,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36218,21 +36710,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36261,7 +36752,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36364,8 +36855,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -36404,8 +36896,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -36450,9 +36942,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36462,21 +36955,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36505,7 +36997,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36594,8 +37086,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -36634,8 +37127,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -36680,9 +37173,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36692,21 +37186,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36735,7 +37228,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36827,8 +37320,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -36867,8 +37361,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -36913,9 +37407,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36925,21 +37420,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -36968,7 +37462,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37058,8 +37552,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -37098,8 +37593,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -37144,9 +37639,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37156,21 +37652,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -37199,7 +37694,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37287,8 +37782,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -37327,8 +37823,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -37373,9 +37869,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37385,21 +37882,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -37428,7 +37924,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37516,8 +38012,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -37556,8 +38053,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -37602,9 +38099,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37614,21 +38112,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -37657,7 +38154,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37742,8 +38239,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -37783,9 +38281,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -37905,9 +38403,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37917,21 +38416,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -37960,7 +38458,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -38080,8 +38578,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -38120,8 +38619,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -38166,9 +38665,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -38178,21 +38678,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -38221,7 +38720,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -38345,8 +38844,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -38385,8 +38885,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -38452,8 +38952,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -38493,9 +38994,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -38540,9 +39041,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -38552,21 +39054,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -38595,7 +39096,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -38683,8 +39184,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -38723,8 +39225,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -38790,8 +39292,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -38831,9 +39334,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -38950,7 +39453,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -38970,7 +39473,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39006,7 +39509,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39030,7 +39533,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39054,7 +39557,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39074,7 +39577,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39094,7 +39597,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39114,7 +39617,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39134,7 +39637,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39154,7 +39657,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39258,7 +39761,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39294,7 +39797,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39330,7 +39833,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39380,7 +39883,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Application\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -39419,7 +39922,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39434,7 +39937,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39464,7 +39967,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39479,7 +39982,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39494,7 +39997,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39509,7 +40012,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39524,7 +40027,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39539,7 +40042,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39554,7 +40057,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39569,7 +40072,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39659,7 +40162,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39674,7 +40177,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39689,7 +40192,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39732,7 +40235,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Application\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -39849,10 +40352,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -39860,11 +40365,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -39878,6 +40381,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -39929,11 +40443,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -39963,11 +40473,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40015,11 +40521,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40057,11 +40559,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40099,11 +40597,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40133,11 +40627,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40167,11 +40657,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40201,11 +40687,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40235,11 +40717,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40269,11 +40747,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40396,11 +40870,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40450,11 +40920,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40504,11 +40970,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -40559,7 +41021,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -41221,7 +41695,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#IntransitiveActivity\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -41328,10 +41802,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -41339,11 +41815,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -41369,6 +41843,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -41381,7 +41866,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -41571,7 +42068,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Arrive\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -41678,10 +42175,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -41689,11 +42188,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -41707,6 +42204,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -41719,7 +42227,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -41957,9 +42477,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -41969,21 +42490,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -42012,7 +42532,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -42099,8 +42619,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -42139,8 +42660,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -42208,9 +42729,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -42220,21 +42742,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -42263,7 +42784,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -42349,8 +42870,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -42389,8 +42911,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -42457,7 +42979,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -42477,7 +42999,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -42503,7 +43025,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -42521,7 +43043,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Article\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -42542,7 +43064,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -42557,7 +43079,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { \\"@value\\": v.href } + { \\"@value\\": formatIri(v) } ); array.push(element);; } @@ -42576,7 +43098,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -42589,7 +43111,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Article\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -42696,10 +43218,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -42707,11 +43231,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -42725,6 +43247,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -42752,11 +43285,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -42789,7 +43318,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ) { if (v == null) continue; - const decoded = new URL(v[\\"@value\\"]); + const decoded = parseIri(v[\\"@value\\"]); if (typeof decoded === \\"undefined\\") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -42812,11 +43341,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -42831,7 +43356,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -43180,7 +43717,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Document\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -43235,7 +43772,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Document\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -43342,10 +43879,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -43353,11 +43892,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -43387,6 +43924,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -43435,7 +43983,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -43648,7 +44208,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Audio\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -43667,7 +44227,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Audio\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -43774,10 +44334,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -43785,11 +44347,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -43803,6 +44363,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -43815,7 +44386,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -44004,7 +44587,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Ignore\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -44111,10 +44694,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -44122,11 +44707,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -44144,6 +44727,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -44156,7 +44750,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -44347,7 +44953,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Block\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -44454,10 +45060,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -44465,11 +45073,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -44483,6 +45089,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -44495,7 +45112,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -45057,9 +45686,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45069,21 +45699,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#current_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -45112,7 +45741,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45198,8 +45827,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current.length < 1) return null; let v = this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.has(0)) { v = v.id; } @@ -45238,8 +45868,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -45284,9 +45914,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45296,21 +45927,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#first_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -45339,7 +45969,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45425,8 +46055,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first.length < 1) return null; let v = this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.has(0)) { v = v.id; } @@ -45465,8 +46096,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -45511,9 +46142,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45523,21 +46155,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#last_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -45566,7 +46197,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45652,8 +46283,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.length < 1) return null; let v = this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.has(0)) { v = v.id; } @@ -45692,8 +46324,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -45738,9 +46370,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45750,21 +46383,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#item_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -45793,7 +46425,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45888,8 +46520,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { v = v.id; } @@ -45929,9 +46562,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -45976,9 +46609,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45988,21 +46622,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likesOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46031,7 +46664,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46116,8 +46749,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.length < 1) return null; let v = this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.has(0)) { v = v.id; } @@ -46156,8 +46790,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -46202,9 +46836,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46214,21 +46849,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#sharesOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46257,7 +46891,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46342,8 +46976,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.length < 1) return null; let v = this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.has(0)) { v = v.id; } @@ -46382,8 +47017,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -46428,9 +47063,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46440,21 +47076,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#repliesOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46483,7 +47118,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46568,8 +47203,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.length < 1) return null; let v = this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.has(0)) { v = v.id; } @@ -46608,8 +47244,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -46654,9 +47290,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46666,21 +47303,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inboxOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46709,7 +47345,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46794,8 +47430,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.length < 1) return null; let v = this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.has(0)) { v = v.id; } @@ -46834,8 +47471,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -46880,9 +47517,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46892,21 +47530,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outboxOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -46935,7 +47572,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47020,8 +47657,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.length < 1) return null; let v = this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.has(0)) { v = v.id; } @@ -47060,8 +47698,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -47106,9 +47744,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -47118,21 +47757,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followersOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -47161,7 +47799,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47246,8 +47884,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.length < 1) return null; let v = this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.has(0)) { v = v.id; } @@ -47286,8 +47925,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -47332,9 +47971,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -47344,21 +47984,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followingOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -47387,7 +48026,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47472,8 +48111,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.length < 1) return null; let v = this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.has(0)) { v = v.id; } @@ -47512,8 +48152,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -47558,9 +48198,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -47570,21 +48211,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likedOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -47613,7 +48253,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47698,8 +48338,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.length < 1) return null; let v = this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.has(0)) { v = v.id; } @@ -47738,8 +48379,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -47822,7 +48463,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47842,7 +48483,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47862,7 +48503,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47882,7 +48523,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47906,7 +48547,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47926,7 +48567,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47946,7 +48587,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47966,7 +48607,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47986,7 +48627,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48006,7 +48647,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48026,7 +48667,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48046,7 +48687,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48064,7 +48705,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Collection\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -48103,7 +48744,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48118,7 +48759,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48133,7 +48774,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48148,7 +48789,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -48163,7 +48804,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48178,7 +48819,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48193,7 +48834,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48208,7 +48849,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48223,7 +48864,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48238,7 +48879,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48253,7 +48894,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48268,7 +48909,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48281,7 +48922,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Collection\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -48388,10 +49029,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -48399,11 +49042,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -48429,6 +49070,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -48474,11 +49126,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3UyUdxnyn6cDn53QKrh4MBiearma_current.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3UyUdxnyn6cDn53QKrh4MBiearma_current.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48508,11 +49156,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _J52RqweMe6hhv7RnLJMC8BExTE5_first.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _J52RqweMe6hhv7RnLJMC8BExTE5_first.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48542,11 +49186,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48576,11 +49216,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48620,11 +49256,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48654,11 +49286,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48688,11 +49316,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48722,11 +49346,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48756,11 +49376,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48790,11 +49406,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48824,11 +49436,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48858,11 +49466,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -48877,7 +49481,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -49382,9 +49998,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -49394,21 +50011,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#partOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -49437,7 +50053,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -49523,8 +50139,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.length < 1) return null; let v = this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.has(0)) { v = v.id; } @@ -49563,8 +50180,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -49609,9 +50226,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -49621,21 +50239,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#next_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -49664,7 +50281,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -49748,8 +50365,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.length < 1) return null; let v = this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.has(0)) { v = v.id; } @@ -49788,8 +50406,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -49834,9 +50452,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -49846,21 +50465,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#prev_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -49889,7 +50507,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -49974,8 +50592,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.length < 1) return null; let v = this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.has(0)) { v = v.id; } @@ -50014,8 +50633,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -50082,7 +50701,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -50102,7 +50721,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -50122,7 +50741,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -50140,7 +50759,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"CollectionPage\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -50161,7 +50780,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -50176,7 +50795,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -50191,7 +50810,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -50204,7 +50823,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#CollectionPage\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -50311,10 +50930,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -50322,11 +50943,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -50344,6 +50963,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -50371,11 +51001,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -50405,11 +51031,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -50439,11 +51061,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -50458,7 +51076,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -50705,7 +51335,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Create\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -50812,10 +51442,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -50823,11 +51455,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -50841,6 +51471,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -50853,7 +51494,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -51042,7 +51695,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Delete\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -51149,10 +51802,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -51160,11 +51815,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -51178,6 +51831,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -51190,7 +51854,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -51377,7 +52053,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Dislike\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -51484,10 +52160,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -51495,11 +52173,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -51513,6 +52189,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -51525,7 +52212,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -51999,7 +52698,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52015,7 +52714,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_25S6UmgzDead8hxL5sQFezZTAusd_oauthAuthorizationEndpoint) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52031,7 +52730,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_iAMxqrSba7yBCRB1FZ5kEVdKEZ3_oauthTokenEndpoint) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52047,7 +52746,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_8Bx9qN8oU7Bpt2xi6khaxWp1gMr_provideClientKey) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52063,7 +52762,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_3dU7PMVQZJpsCpo2F4RQXxBXdPmS_signClientKey) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52079,7 +52778,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_3JprUSDLVqqX4dwHRi37qGZZCRCc_sharedInbox) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52093,7 +52792,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint } - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://www.w3.org/ns/activitystreams\\"; return result; } @@ -52104,7 +52803,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52119,7 +52818,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_25S6UmgzDead8hxL5sQFezZTAusd_oauthAuthorizationEndpoint) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52134,7 +52833,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_iAMxqrSba7yBCRB1FZ5kEVdKEZ3_oauthTokenEndpoint) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52149,7 +52848,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_8Bx9qN8oU7Bpt2xi6khaxWp1gMr_provideClientKey) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52164,7 +52863,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_3dU7PMVQZJpsCpo2F4RQXxBXdPmS_signClientKey) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52179,7 +52878,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_3JprUSDLVqqX4dwHRi37qGZZCRCc_sharedInbox) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -52192,7 +52891,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint } - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -52288,10 +52987,12 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -52299,11 +53000,9 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -52317,8 +53016,21 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl: (URL)[] = []; @@ -52334,22 +53046,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl.push(decoded); } @@ -52367,22 +53064,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _25S6UmgzDead8hxL5sQFezZTAusd_oauthAuthorizationEndpoint.push(decoded); } @@ -52400,22 +53082,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _iAMxqrSba7yBCRB1FZ5kEVdKEZ3_oauthTokenEndpoint.push(decoded); } @@ -52433,22 +53100,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _8Bx9qN8oU7Bpt2xi6khaxWp1gMr_provideClientKey.push(decoded); } @@ -52466,22 +53118,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _3dU7PMVQZJpsCpo2F4RQXxBXdPmS_signClientKey.push(decoded); } @@ -52499,22 +53136,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _3JprUSDLVqqX4dwHRi37qGZZCRCc_sharedInbox.push(decoded); } @@ -52522,7 +53144,19 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -52830,7 +53464,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Event\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -52849,7 +53483,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Event\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -52956,10 +53590,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -52967,11 +53603,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -52985,6 +53619,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -52997,7 +53642,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -53187,7 +53844,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Flag\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -53294,10 +53951,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -53305,11 +53964,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -53323,6 +53980,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -53335,7 +54003,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -53526,7 +54206,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Follow\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -53633,10 +54313,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -53644,11 +54326,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -53662,6 +54342,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -53674,7 +54365,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -54759,9 +55462,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -54771,21 +55475,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -54814,7 +55517,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -54898,8 +55601,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -54938,8 +55642,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -55001,8 +55705,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -55042,9 +55747,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -55089,9 +55794,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55101,21 +55807,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -55144,7 +55849,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -55232,8 +55937,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -55272,8 +55978,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -55339,8 +56045,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -55380,9 +56087,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -55446,9 +56153,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55458,21 +56166,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -55501,7 +56208,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -55607,8 +56314,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -55647,8 +56355,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -55693,9 +56401,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55705,21 +56414,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -55748,7 +56456,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -55851,8 +56559,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -55891,8 +56600,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -55937,9 +56646,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55949,21 +56659,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -55992,7 +56701,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56081,8 +56790,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -56121,8 +56831,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -56167,9 +56877,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56179,21 +56890,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -56222,7 +56932,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56314,8 +57024,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -56354,8 +57065,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -56400,9 +57111,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56412,21 +57124,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -56455,7 +57166,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56545,8 +57256,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -56585,8 +57297,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -56631,9 +57343,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56643,21 +57356,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -56686,7 +57398,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56774,8 +57486,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -56814,8 +57527,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -56860,9 +57573,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56872,21 +57586,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -56915,7 +57628,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57003,8 +57716,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -57043,8 +57757,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -57089,9 +57803,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -57101,21 +57816,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -57144,7 +57858,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57229,8 +57943,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -57270,9 +57985,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -57392,9 +58107,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -57404,21 +58120,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -57447,7 +58162,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57567,8 +58282,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -57607,8 +58323,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -57653,9 +58369,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -57665,21 +58382,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -57708,7 +58424,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57832,8 +58548,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -57872,8 +58589,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -57939,8 +58656,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -57980,9 +58698,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -58027,9 +58745,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -58039,21 +58758,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -58082,7 +58800,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -58170,8 +58888,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -58210,8 +58929,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -58277,8 +58996,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -58318,9 +59038,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -58437,7 +59157,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58457,7 +59177,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58493,7 +59213,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58517,7 +59237,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58541,7 +59261,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58561,7 +59281,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58581,7 +59301,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58601,7 +59321,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58621,7 +59341,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58641,7 +59361,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58745,7 +59465,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58781,7 +59501,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58817,7 +59537,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58867,7 +59587,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Group\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -58906,7 +59626,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -58921,7 +59641,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -58951,7 +59671,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -58966,7 +59686,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -58981,7 +59701,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -58996,7 +59716,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59011,7 +59731,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59026,7 +59746,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59041,7 +59761,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59056,7 +59776,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59146,7 +59866,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -59161,7 +59881,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -59176,7 +59896,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59219,7 +59939,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Group\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -59336,10 +60056,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -59347,11 +60069,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -59365,6 +60085,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -59416,11 +60147,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59450,11 +60177,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59502,11 +60225,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59544,11 +60263,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59586,11 +60301,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59620,11 +60331,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59654,11 +60361,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59688,11 +60391,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59722,11 +60421,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59756,11 +60451,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59883,11 +60574,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59937,11 +60624,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -59991,11 +60674,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -60046,7 +60725,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -61171,9 +61862,10 @@ get names(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -61183,21 +61875,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#preview_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -61226,7 +61917,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -61319,8 +62010,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { v = v.id; } @@ -61360,9 +62052,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -61423,7 +62115,7 @@ get names(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_pVjLsybKQdmkjuU7MHjiVmNnuj7_href) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -61538,7 +62230,7 @@ get names(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const item = ( - v instanceof URL ? v.href : v instanceof Link ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Link ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -61560,7 +62252,7 @@ get names(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Link\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://www.w3.org/ns/activitystreams\\"; return result; } @@ -61571,7 +62263,7 @@ get names(): ((string | LanguageString))[] { array = []; for (const v of this.#_pVjLsybKQdmkjuU7MHjiVmNnuj7_href) { const element = ( - { \\"@id\\": v.href } + { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -61685,7 +62377,7 @@ get names(): ((string | LanguageString))[] { array = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -61698,7 +62390,7 @@ get names(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Link\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -61799,10 +62491,12 @@ get names(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -61810,11 +62504,9 @@ get names(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -61836,8 +62528,21 @@ get names(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _pVjLsybKQdmkjuU7MHjiVmNnuj7_href: (URL)[] = []; @@ -61853,22 +62558,7 @@ get names(): ((string | LanguageString))[] { ) { if (v == null) continue; - const decoded = v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl); + const decoded = parseIri(v[\\"@id\\"], options.baseUrl); if (typeof decoded === \\"undefined\\") continue; _pVjLsybKQdmkjuU7MHjiVmNnuj7_href.push(decoded); } @@ -62005,11 +62695,7 @@ get names(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -62034,7 +62720,19 @@ get names(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -62371,7 +63069,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num let compactItems: unknown[]; result[\\"type\\"] = \\"Hashtag\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",{\\"Hashtag\\":\\"as:Hashtag\\"}]; return result; } @@ -62390,7 +63088,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Hashtag\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -62486,10 +63184,12 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -62497,11 +63197,9 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -62515,6 +63213,17 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -62527,7 +63236,19 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -62700,7 +63421,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Image\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -62719,7 +63440,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Image\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -62826,10 +63547,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -62837,11 +63560,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -62855,6 +63576,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -62867,7 +63599,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -63057,7 +63801,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Offer\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -63164,10 +63908,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -63175,11 +63921,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -63197,6 +63941,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -63209,7 +63964,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -63398,7 +64165,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Invite\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -63505,10 +64272,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -63516,11 +64285,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -63534,6 +64301,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -63546,7 +64324,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -63735,7 +64525,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Join\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -63842,10 +64632,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -63853,11 +64645,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -63871,6 +64661,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -63883,7 +64684,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -64072,7 +64885,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Leave\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -64179,10 +64992,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -64190,11 +65005,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -64208,6 +65021,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -64220,7 +65044,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -64409,7 +65245,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Like\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -64516,10 +65352,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -64527,11 +65365,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -64545,6 +65381,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -64557,7 +65404,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -64744,7 +65603,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Listen\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -64851,10 +65710,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -64862,11 +65723,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -64880,6 +65739,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -64892,7 +65762,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -65037,7 +65919,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num let compactItems: unknown[]; result[\\"type\\"] = \\"Mention\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://www.w3.org/ns/activitystreams\\"; return result; } @@ -65056,7 +65938,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Mention\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -65152,10 +66034,12 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -65163,11 +66047,9 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -65181,6 +66063,17 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -65193,7 +66086,19 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -65383,7 +66288,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Move\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -65490,10 +66395,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -65501,11 +66408,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -65519,6 +66424,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -65531,7 +66447,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -65771,9 +66699,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -65783,21 +66712,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -65826,7 +66754,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -65913,8 +66841,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -65953,8 +66882,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -66022,9 +66951,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -66034,21 +66964,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -66077,7 +67006,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -66163,8 +67092,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -66203,8 +67133,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -66271,7 +67201,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -66291,7 +67221,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -66317,7 +67247,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -66335,7 +67265,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Note\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -66356,7 +67286,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -66371,7 +67301,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { \\"@value\\": v.href } + { \\"@value\\": formatIri(v) } ); array.push(element);; } @@ -66390,7 +67320,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -66403,7 +67333,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Note\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -66510,10 +67440,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -66521,11 +67453,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -66539,6 +67469,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -66566,11 +67507,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -66603,7 +67540,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ) { if (v == null) continue; - const decoded = new URL(v[\\"@value\\"]); + const decoded = parseIri(v[\\"@value\\"]); if (typeof decoded === \\"undefined\\") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -66626,11 +67563,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -66645,7 +67578,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -66902,9 +67847,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -66914,21 +67860,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#item_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -66957,7 +67902,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -67052,8 +67997,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { v = v.id; } @@ -67093,9 +68039,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -67162,7 +68108,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -67181,7 +68127,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"OrderedCollection\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -67202,7 +68148,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -67215,7 +68161,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#OrderedCollection\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -67322,10 +68268,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -67333,11 +68281,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -67351,6 +68297,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -67378,11 +68335,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -67407,7 +68360,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -67654,9 +68619,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -67666,21 +68632,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#item_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -67709,7 +68674,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -67804,8 +68769,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { v = v.id; } @@ -67845,9 +68811,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -67929,7 +68895,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -67964,7 +68930,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"OrderedCollectionPage\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"fedibird\\":\\"http://fedibird.com/ns#\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"quote\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quote\\",\\"@type\\":\\"@id\\"},\\"quoteUrl\\":\\"as:quoteUrl\\",\\"_misskey_quote\\":\\"misskey:_misskey_quote\\",\\"quoteUri\\":\\"fedibird:quoteUri\\",\\"QuoteAuthorization\\":\\"https://w3id.org/fep/044f#QuoteAuthorization\\",\\"QuoteRequest\\":\\"https://w3id.org/fep/044f#QuoteRequest\\",\\"quoteAuthorization\\":{\\"@id\\":\\"https://w3id.org/fep/044f#quoteAuthorization\\",\\"@type\\":\\"@id\\"},\\"emojiReactions\\":{\\"@id\\":\\"fedibird:emojiReactions\\",\\"@type\\":\\"@id\\"}}]; return result; } @@ -67985,7 +68951,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -68016,7 +68982,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#OrderedCollectionPage\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -68123,10 +69089,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -68134,11 +69102,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -68152,6 +69118,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -68179,11 +69156,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -68226,7 +69199,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -69353,9 +70338,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -69365,21 +70351,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -69408,7 +70393,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -69492,8 +70477,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -69532,8 +70518,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -69595,8 +70581,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -69636,9 +70623,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -69683,9 +70670,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -69695,21 +70683,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -69738,7 +70725,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -69826,8 +70813,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -69866,8 +70854,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -69933,8 +70921,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -69974,9 +70963,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -70040,9 +71029,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70052,21 +71042,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -70095,7 +71084,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70201,8 +71190,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -70241,8 +71231,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -70287,9 +71277,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70299,21 +71290,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -70342,7 +71332,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70445,8 +71435,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -70485,8 +71476,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -70531,9 +71522,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70543,21 +71535,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -70586,7 +71577,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70675,8 +71666,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -70715,8 +71707,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -70761,9 +71753,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70773,21 +71766,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -70816,7 +71808,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70908,8 +71900,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -70948,8 +71941,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -70994,9 +71987,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71006,21 +72000,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -71049,7 +72042,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71139,8 +72132,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -71179,8 +72173,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -71225,9 +72219,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71237,21 +72232,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -71280,7 +72274,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71368,8 +72362,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -71408,8 +72403,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -71454,9 +72449,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71466,21 +72462,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -71509,7 +72504,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71597,8 +72592,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -71637,8 +72633,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -71683,9 +72679,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71695,21 +72692,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -71738,7 +72734,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71823,8 +72819,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -71864,9 +72861,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -71986,9 +72983,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71998,21 +72996,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -72041,7 +73038,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -72161,8 +73158,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -72201,8 +73199,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -72247,9 +73245,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -72259,21 +73258,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -72302,7 +73300,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -72426,8 +73424,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -72466,8 +73465,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -72533,8 +73532,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -72574,9 +73574,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -72621,9 +73621,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -72633,21 +73634,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -72676,7 +73676,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -72764,8 +73764,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -72804,8 +73805,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -72871,8 +73872,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -72912,9 +73914,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -73031,7 +74033,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73051,7 +74053,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73087,7 +74089,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73111,7 +74113,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73135,7 +74137,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73155,7 +74157,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73175,7 +74177,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73195,7 +74197,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73215,7 +74217,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73235,7 +74237,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73339,7 +74341,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73375,7 +74377,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73411,7 +74413,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73461,7 +74463,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Organization\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -73500,7 +74502,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73515,7 +74517,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73545,7 +74547,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73560,7 +74562,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73575,7 +74577,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73590,7 +74592,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73605,7 +74607,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73620,7 +74622,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73635,7 +74637,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73650,7 +74652,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73740,7 +74742,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73755,7 +74757,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73770,7 +74772,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73813,7 +74815,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Organization\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -73930,10 +74932,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -73941,11 +74945,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -73959,6 +74961,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -74010,11 +75023,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74044,11 +75053,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74096,11 +75101,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74138,11 +75139,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74180,11 +75177,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74214,11 +75207,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74248,11 +75237,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74282,11 +75267,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74316,11 +75297,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74350,11 +75327,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74477,11 +75450,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74531,11 +75500,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74585,11 +75550,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -74640,7 +75601,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -75285,7 +76258,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Page\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -75304,7 +76277,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Page\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -75411,10 +76384,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -75422,11 +76397,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -75440,6 +76413,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -75452,7 +76436,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -76537,9 +77533,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -76549,21 +77546,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -76592,7 +77588,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -76676,8 +77672,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -76716,8 +77713,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -76779,8 +77776,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -76820,9 +77818,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -76867,9 +77865,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -76879,21 +77878,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -76922,7 +77920,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77010,8 +78008,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -77050,8 +78049,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -77117,8 +78116,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -77158,9 +78158,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -77224,9 +78224,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77236,21 +78237,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -77279,7 +78279,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77385,8 +78385,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -77425,8 +78426,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -77471,9 +78472,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77483,21 +78485,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -77526,7 +78527,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77629,8 +78630,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -77669,8 +78671,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -77715,9 +78717,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77727,21 +78730,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -77770,7 +78772,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77859,8 +78861,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -77899,8 +78902,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -77945,9 +78948,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77957,21 +78961,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78000,7 +79003,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78092,8 +79095,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -78132,8 +79136,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -78178,9 +79182,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78190,21 +79195,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78233,7 +79237,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78323,8 +79327,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -78363,8 +79368,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -78409,9 +79414,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78421,21 +79427,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78464,7 +79469,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78552,8 +79557,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -78592,8 +79598,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -78638,9 +79644,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78650,21 +79657,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78693,7 +79699,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78781,8 +79787,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -78821,8 +79828,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -78867,9 +79874,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78879,21 +79887,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -78922,7 +79929,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79007,8 +80014,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -79048,9 +80056,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -79170,9 +80178,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -79182,21 +80191,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -79225,7 +80233,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79345,8 +80353,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -79385,8 +80394,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -79431,9 +80440,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -79443,21 +80453,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -79486,7 +80495,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79610,8 +80619,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -79650,8 +80660,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -79717,8 +80727,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -79758,9 +80769,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -79805,9 +80816,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -79817,21 +80829,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -79860,7 +80871,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79948,8 +80959,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -79988,8 +81000,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -80055,8 +81067,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -80096,9 +81109,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -80215,7 +81228,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80235,7 +81248,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80271,7 +81284,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80295,7 +81308,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80319,7 +81332,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80339,7 +81352,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80359,7 +81372,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80379,7 +81392,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80399,7 +81412,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80419,7 +81432,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80523,7 +81536,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80559,7 +81572,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80595,7 +81608,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80645,7 +81658,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Person\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -80684,7 +81697,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80699,7 +81712,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80729,7 +81742,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80744,7 +81757,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80759,7 +81772,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80774,7 +81787,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80789,7 +81802,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80804,7 +81817,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80819,7 +81832,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80834,7 +81847,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80924,7 +81937,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80939,7 +81952,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80954,7 +81967,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80997,7 +82010,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Person\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -81114,10 +82127,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -81125,11 +82140,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -81143,6 +82156,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -81194,11 +82218,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81228,11 +82248,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81280,11 +82296,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81322,11 +82334,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81364,11 +82372,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81398,11 +82402,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81432,11 +82432,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81466,11 +82462,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81500,11 +82492,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81534,11 +82522,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81661,11 +82645,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81715,11 +82695,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81769,11 +82745,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -81824,7 +82796,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -82806,7 +83790,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_oKrwxU4V8wiKhMW1QEYQibcJh8c_units) { const item = ( - v == \\"cm\\" || v == \\"feet\\" || v == \\"inches\\" || v == \\"km\\" || v == \\"m\\" || v == \\"miles\\" ? v : v.href + v == \\"cm\\" || v == \\"feet\\" || v == \\"inches\\" || v == \\"km\\" || v == \\"m\\" || v == \\"miles\\" ? v : formatIri(v) ); compactItems.push(item); } @@ -82820,7 +83804,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Place\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -82931,7 +83915,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_oKrwxU4V8wiKhMW1QEYQibcJh8c_units) { const element = ( - v == \\"cm\\" || v == \\"feet\\" || v == \\"inches\\" || v == \\"km\\" || v == \\"m\\" || v == \\"miles\\" ? { \\"@value\\": v } : { \\"@id\\": v.href } + v == \\"cm\\" || v == \\"feet\\" || v == \\"inches\\" || v == \\"km\\" || v == \\"m\\" || v == \\"miles\\" ? { \\"@value\\": v } : { \\"@id\\": formatIri(v) } ); array.push(element);; } @@ -82944,7 +83928,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Place\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -83051,10 +84035,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -83062,11 +84048,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -83080,6 +84064,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -83196,22 +84191,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu typeof v === \\"object\\" && \\"@value\\" in v && (v[\\"@value\\"] == \\"cm\\" || v[\\"@value\\"] == \\"feet\\" || v[\\"@value\\"] == \\"inches\\" || v[\\"@value\\"] == \\"km\\" || v[\\"@value\\"] == \\"m\\" || v[\\"@value\\"] == \\"miles\\") ? v[\\"@value\\"] : v != null && typeof v === \\"object\\" && \\"@id\\" in v && typeof v[\\"@id\\"] === \\"string\\" - && v[\\"@id\\"] !== \\"\\" ? v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + - encodeURIComponent( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(5, v[\\"@id\\"].indexOf(\\"/\\", 5)) - : v[\\"@id\\"].slice(5) - ) + - ( - v[\\"@id\\"].includes(\\"/\\", 5) - ? v[\\"@id\\"].slice(v[\\"@id\\"].indexOf(\\"/\\", 5)) - : \\"\\" - ) - ) - : URL.canParse(v[\\"@id\\"]) && options.baseUrl - ? new URL(v[\\"@id\\"]) - : new URL(v[\\"@id\\"], options.baseUrl) : undefined + && v[\\"@id\\"] !== \\"\\" ? parseIri(v[\\"@id\\"], options.baseUrl) : undefined ; if (typeof decoded === \\"undefined\\") continue; _oKrwxU4V8wiKhMW1QEYQibcJh8c_units.push(decoded); @@ -83221,7 +84201,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -83528,9 +84520,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -83540,21 +84533,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#describes_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -83583,7 +84575,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -83669,8 +84661,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.length < 1) return null; let v = this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.has(0)) { v = v.id; } @@ -83709,8 +84702,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -83777,7 +84770,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -83795,7 +84788,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result[\\"type\\"] = \\"Profile\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -83816,7 +84809,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -83829,7 +84822,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Profile\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -83936,10 +84929,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -83947,11 +84942,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -83965,6 +84958,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -83992,11 +84996,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -84011,7 +85011,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -84427,9 +85439,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -84439,21 +85452,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#exclusiveOption_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -84482,7 +85494,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -84569,8 +85581,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti const vs = this.#_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.has(i)) { v = v.id; } @@ -84610,9 +85623,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -84657,9 +85670,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -84669,21 +85683,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inclusiveOption_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -84712,7 +85725,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -84799,8 +85812,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti const vs = this.#_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.has(i)) { v = v.id; } @@ -84840,9 +85854,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -84917,9 +85931,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -84929,21 +85944,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -84972,7 +85986,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -85059,8 +86073,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -85099,8 +86114,8 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -85168,9 +86183,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -85180,21 +86196,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -85223,7 +86238,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -85309,8 +86324,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -85349,8 +86365,8 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -85419,7 +86435,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85434,7 +86450,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85485,7 +86501,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85500,7 +86516,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { \\"@value\\": v.href } + { \\"@value\\": formatIri(v) } ); array.push(element);; } @@ -85519,7 +86535,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85532,7 +86548,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Question\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -85639,10 +86655,12 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -85650,11 +86668,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -85668,6 +86684,17 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -85695,11 +86722,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -85729,11 +86752,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -85812,11 +86831,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -85849,7 +86864,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti ) { if (v == null) continue; - const decoded = new URL(v[\\"@value\\"]); + const decoded = parseIri(v[\\"@value\\"]); if (typeof decoded === \\"undefined\\") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -85872,11 +86887,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -85891,7 +86902,19 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -86223,7 +87246,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Read\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -86330,10 +87353,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -86341,11 +87366,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -86359,6 +87382,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -86371,7 +87405,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -86560,7 +87606,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Reject\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -86667,10 +87713,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -86678,11 +87726,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -86700,6 +87746,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -86712,7 +87769,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -87073,9 +88142,10 @@ relationships?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -87085,21 +88155,20 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#subject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -87128,7 +88197,7 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -87216,8 +88285,9 @@ relationships?: (Object | URL)[];} } if (this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.length < 1) return null; let v = this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.has(0)) { v = v.id; } @@ -87256,8 +88326,8 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -87302,9 +88372,10 @@ relationships?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -87314,21 +88385,20 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#object_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -87357,7 +88427,7 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -87442,8 +88512,9 @@ relationships?: (Object | URL)[];} } if (this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.length < 1) return null; let v = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { v = v.id; } @@ -87482,8 +88553,8 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -87546,8 +88617,9 @@ relationships?: (Object | URL)[];} const vs = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { v = v.id; } @@ -87587,9 +88659,9 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -87634,9 +88706,10 @@ relationships?: (Object | URL)[];} \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -87646,21 +88719,20 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#relationship_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -87689,7 +88761,7 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -87776,8 +88848,9 @@ relationships?: (Object | URL)[];} } if (this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.length < 1) return null; let v = this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(0)) { v = v.id; } @@ -87816,8 +88889,8 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -87882,8 +88955,9 @@ relationships?: (Object | URL)[];} const vs = this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(i)) { v = v.id; } @@ -87923,9 +88997,9 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -87992,7 +89066,7 @@ relationships?: (Object | URL)[];} compactItems = []; for (const v of this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -88012,7 +89086,7 @@ relationships?: (Object | URL)[];} compactItems = []; for (const v of this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -88032,7 +89106,7 @@ relationships?: (Object | URL)[];} compactItems = []; for (const v of this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -88050,7 +89124,7 @@ relationships?: (Object | URL)[];} } result[\\"type\\"] = \\"Relationship\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -88071,7 +89145,7 @@ relationships?: (Object | URL)[];} array = []; for (const v of this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -88086,7 +89160,7 @@ relationships?: (Object | URL)[];} array = []; for (const v of this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -88101,7 +89175,7 @@ relationships?: (Object | URL)[];} array = []; for (const v of this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -88114,7 +89188,7 @@ relationships?: (Object | URL)[];} } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Relationship\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -88221,10 +89295,12 @@ relationships?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -88232,11 +89308,9 @@ relationships?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -88250,6 +89324,17 @@ relationships?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -88277,11 +89362,7 @@ relationships?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -88311,11 +89392,7 @@ relationships?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -88345,11 +89422,7 @@ relationships?: (Object | URL)[];} if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -88364,7 +89437,19 @@ relationships?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -88625,7 +89710,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Remove\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -88732,10 +89817,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -88743,11 +89830,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -88761,6 +89846,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -88773,7 +89869,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -89858,9 +90966,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -89870,21 +90979,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -89913,7 +91021,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -89997,8 +91105,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -90037,8 +91146,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -90100,8 +91209,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -90141,9 +91251,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -90188,9 +91298,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -90200,21 +91311,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -90243,7 +91353,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -90331,8 +91441,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -90371,8 +91482,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -90438,8 +91549,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -90479,9 +91591,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -90545,9 +91657,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -90557,21 +91670,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -90600,7 +91712,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -90706,8 +91818,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -90746,8 +91859,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -90792,9 +91905,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -90804,21 +91918,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -90847,7 +91960,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -90950,8 +92063,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -90990,8 +92104,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91036,9 +92150,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91048,21 +92163,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -91091,7 +92205,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91180,8 +92294,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -91220,8 +92335,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91266,9 +92381,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91278,21 +92394,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -91321,7 +92436,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91413,8 +92528,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -91453,8 +92569,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91499,9 +92615,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91511,21 +92628,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -91554,7 +92670,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91644,8 +92760,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -91684,8 +92801,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91730,9 +92847,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91742,21 +92860,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -91785,7 +92902,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91873,8 +92990,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -91913,8 +93031,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -91959,9 +93077,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91971,21 +93090,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -92014,7 +93132,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92102,8 +93220,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -92142,8 +93261,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -92188,9 +93307,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -92200,21 +93320,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -92243,7 +93362,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92328,8 +93447,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -92369,9 +93489,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -92491,9 +93611,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -92503,21 +93624,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -92546,7 +93666,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92666,8 +93786,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -92706,8 +93827,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -92752,9 +93873,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -92764,21 +93886,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -92807,7 +93928,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92931,8 +94052,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -92971,8 +94093,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -93038,8 +94160,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -93079,9 +94202,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -93126,9 +94249,10 @@ get preferredUsernames(): ((string | LanguageString))[] { \\"0.0.0\\", ); return await tracer.startActiveSpan(\\"activitypub.lookup_object\\", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -93138,21 +94262,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to fetch {url}: {error}\\", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== \\"trust\\" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The object's @id (\\" + obj.id.href + \\") has a different origin \\" + @@ -93181,7 +94304,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger([\\"fedify\\", \\"vocab\\"]).error( \\"Failed to parse {url}: {error}\\", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -93269,8 +94392,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -93309,8 +94433,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === \\"throw\\") { throw new Error( @@ -93376,8 +94500,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== \\"trust\\" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -93417,9 +94542,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== \\"trust\\" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === \\"throw\\") { throw new Error( \\"The property object's @id (\\" + v.id.href + \\") has a different \\" + @@ -93536,7 +94661,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93556,7 +94681,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93592,7 +94717,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93616,7 +94741,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93640,7 +94765,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93660,7 +94785,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93680,7 +94805,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93700,7 +94825,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93720,7 +94845,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93740,7 +94865,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93844,7 +94969,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93880,7 +95005,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93916,7 +95041,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93966,7 +95091,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result[\\"type\\"] = \\"Service\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/v1\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://www.w3.org/ns/did/v1\\",\\"https://w3id.org/security/multikey/v1\\",\\"https://gotosocial.org/ns\\",{\\"alsoKnownAs\\":{\\"@id\\":\\"as:alsoKnownAs\\",\\"@type\\":\\"@id\\"},\\"manuallyApprovesFollowers\\":\\"as:manuallyApprovesFollowers\\",\\"movedTo\\":{\\"@id\\":\\"as:movedTo\\",\\"@type\\":\\"@id\\"},\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"Emoji\\":\\"toot:Emoji\\",\\"featured\\":{\\"@id\\":\\"toot:featured\\",\\"@type\\":\\"@id\\"},\\"featuredTags\\":{\\"@id\\":\\"toot:featuredTags\\",\\"@type\\":\\"@id\\"},\\"discoverable\\":\\"toot:discoverable\\",\\"suspended\\":\\"toot:suspended\\",\\"memorial\\":\\"toot:memorial\\",\\"indexable\\":\\"toot:indexable\\",\\"schema\\":\\"http://schema.org#\\",\\"PropertyValue\\":\\"schema:PropertyValue\\",\\"value\\":\\"schema:value\\",\\"misskey\\":\\"https://misskey-hub.net/ns#\\",\\"_misskey_followedMessage\\":\\"misskey:_misskey_followedMessage\\",\\"isCat\\":\\"misskey:isCat\\"}]; return result; } @@ -94005,7 +95130,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94020,7 +95145,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94050,7 +95175,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94065,7 +95190,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94080,7 +95205,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94095,7 +95220,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94110,7 +95235,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94125,7 +95250,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94140,7 +95265,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94155,7 +95280,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94245,7 +95370,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94260,7 +95385,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94275,7 +95400,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { \\"@id\\": v.href } : await v.toJsonLd(options) + v instanceof URL ? { \\"@id\\": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94318,7 +95443,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Service\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -94435,10 +95560,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -94446,11 +95573,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -94464,6 +95589,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -94515,11 +95651,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94549,11 +95681,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94601,11 +95729,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94643,11 +95767,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94685,11 +95805,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94719,11 +95835,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94753,11 +95865,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94787,11 +95895,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94821,11 +95925,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94855,11 +95955,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -94982,11 +96078,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -95036,11 +96128,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -95090,11 +96178,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === \\"object\\" && \\"@id\\" in v && !(\\"@type\\" in v) && globalThis.Object.keys(v).length === 1) { if (v[\\"@id\\"].startsWith(\\"_:\\")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v[\\"@id\\"], options.baseUrl) && v[\\"@id\\"].startsWith(\\"at://\\") - ? new URL(\\"at://\\" + encodeURIComponent(v[\\"@id\\"].substring(5))) - : new URL(v[\\"@id\\"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v[\\"@id\\"], options.baseUrl)); continue; } @@ -95145,7 +96229,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -95989,7 +97085,7 @@ get contents(): ((string | LanguageString))[] { } - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = \\"https://www.w3.org/ns/activitystreams\\"; return result; } @@ -96031,7 +97127,7 @@ get contents(): ((string | LanguageString))[] { } - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -96132,10 +97228,12 @@ get contents(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -96143,11 +97241,9 @@ get contents(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -96161,8 +97257,21 @@ get contents(): ((string | LanguageString))[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"], options.baseUrl) ? new URL(values[\\"@id\\"], options.baseUrl) : undefined }, + { + id + }, options, ); const _4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content: ((string | LanguageString))[] = []; @@ -96210,7 +97319,19 @@ get contents(): ((string | LanguageString))[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -96460,7 +97581,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#TentativeAccept\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -96567,10 +97688,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -96578,11 +97701,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -96596,6 +97717,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -96608,7 +97740,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -96797,7 +97941,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#TentativeReject\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -96904,10 +98048,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -96915,11 +98061,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -96933,6 +98077,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -96945,7 +98100,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -97293,7 +98460,7 @@ get formerTypes(): ($EntityType)[] { } result[\\"type\\"] = \\"Tombstone\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -97345,7 +98512,7 @@ get formerTypes(): ($EntityType)[] { } values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Tombstone\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -97457,10 +98624,12 @@ get formerTypes(): ($EntityType)[] { }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -97468,11 +98637,9 @@ get formerTypes(): ($EntityType)[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -97486,6 +98653,17 @@ get formerTypes(): ($EntityType)[] { } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -97551,7 +98729,19 @@ get formerTypes(): ($EntityType)[] { if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -97788,7 +98978,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Travel\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -97895,10 +99085,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -97906,11 +99098,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -97924,6 +99114,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -97936,7 +99137,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -98130,7 +99343,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Undo\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -98237,10 +99450,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -98248,11 +99463,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -98266,6 +99479,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -98278,7 +99502,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -98470,7 +99706,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Update\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -98577,10 +99813,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -98588,11 +99826,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -98606,6 +99842,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -98618,7 +99865,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -98791,7 +100050,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result[\\"type\\"] = \\"Video\\"; - if (this.id != null) result[\\"id\\"] = this.id.href; + if (this.id != null) result[\\"id\\"] = formatIri(this.id); result[\\"@context\\"] = [\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",\\"https://gotosocial.org/ns\\"]; return result; } @@ -98810,7 +100069,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Video\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -98917,10 +100176,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -98928,11 +100189,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -98946,6 +100205,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -98958,7 +100228,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", @@ -99146,7 +100428,7 @@ instruments?: (Object | URL)[];} >; values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#View\\"]; - if (this.id != null) values[\\"@id\\"] = this.id.href; + if (this.id != null) values[\\"@id\\"] = formatIri(this.id); if (options.format === \\"expand\\") { return await jsonld.expand( values, @@ -99253,10 +100535,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { \\"@id\\"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -99264,11 +100548,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { \\"@id\\"?: string }); } - if (values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && !URL.canParse(values[\\"@id\\"], options.baseUrl)) { - throw new TypeError(\\"Invalid @id: \\" + values[\\"@id\\"]); - } - if (options.baseUrl == null && values[\\"@id\\"] != null && !values[\\"@id\\"].startsWith(\\"_:\\") && URL.canParse(values[\\"@id\\"])) { - options = { ...options, baseUrl: new URL(values[\\"@id\\"]) }; + const id = parseJsonLdId(values[\\"@id\\"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if (\\"@type\\" in values) { @@ -99282,6 +100564,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !(\\"_fromSubclass\\" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values[\\"@type\\"]; const instance = await super.fromJsonLd(values, { ...options, @@ -99294,7 +100587,19 @@ instruments?: (Object | URL)[];} if (!(\\"_fromSubclass\\" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger([\\"fedify\\", \\"vocab\\"]).warn( \\"Failed to cache JSON-LD: {json}\\", diff --git a/packages/vocab-tools/src/__snapshots__/class.test.ts.snap b/packages/vocab-tools/src/__snapshots__/class.test.ts.snap index 2a93e71a3..5ba9091e0 100644 --- a/packages/vocab-tools/src/__snapshots__/class.test.ts.snap +++ b/packages/vocab-tools/src/__snapshots__/class.test.ts.snap @@ -14,19 +14,29 @@ import { encodeMultibase, exportMultibaseKey, exportSpki, + formatIri, getDocumentLoader, importMultibaseKey, importPem, isDecimal, LanguageString, parseDecimal, + parseIri, + parseJsonLdId, type RemoteDocument } from "@fedify/vocab-runtime"; +import { + compactJsonLdCache, + getJsonLdContext, + isTrustedIriOrigin, + normalizeJsonLdIris +} from "@fedify/vocab-runtime/internal/jsonld-cache"; import { isTemporalDuration, isTemporalInstant, } from "@fedify/vocab-runtime/temporal"; - +const PORTABLE_IRI_PATTERN = /^ap(?:\\+ef61)?:\\/\\//i; +const PORTABLE_IRI_KEYS: ReadonlySet = new Set(["@id","_misskey_quote","actor","alsoKnownAs","announceAuthorization","anyOf","approvedBy","assertionMethod","attachment","attributedTo","audience","automaticApproval","bcc","bto","cc","context","controller","current","describes","emojiReactions","featured","featuredTags","first","followers","followersOf","following","followingOf","generator","href","http://fedibird.com/ns#emojiReactions","http://fedibird.com/ns#quoteUri","http://joinmastodon.org/ns#featured","http://joinmastodon.org/ns#featuredTags","http://www.w3.org/ns/ldp#inbox","https://gotosocial.org/ns#announceAuthorization","https://gotosocial.org/ns#approvedBy","https://gotosocial.org/ns#automaticApproval","https://gotosocial.org/ns#interactingObject","https://gotosocial.org/ns#interactionTarget","https://gotosocial.org/ns#likeAuthorization","https://gotosocial.org/ns#manualApproval","https://gotosocial.org/ns#replyAuthorization","https://misskey-hub.net/ns#_misskey_quote","https://w3id.org/fep/044f#quote","https://w3id.org/fep/044f#quoteAuthorization","https://w3id.org/fep/5711#followersOf","https://w3id.org/fep/5711#followingOf","https://w3id.org/fep/5711#inboxOf","https://w3id.org/fep/5711#likedOf","https://w3id.org/fep/5711#likesOf","https://w3id.org/fep/5711#outboxOf","https://w3id.org/fep/5711#repliesOf","https://w3id.org/fep/5711#sharesOf","https://w3id.org/security#assertionMethod","https://w3id.org/security#controller","https://w3id.org/security#owner","https://w3id.org/security#proof","https://w3id.org/security#publicKey","https://w3id.org/security#verificationMethod","https://w3id.org/valueflows/ont/vf#resourceConformsTo","https://w3id.org/valueflows/ont/vf#satisfies","https://www.w3.org/ns/activitystreams#actor","https://www.w3.org/ns/activitystreams#alsoKnownAs","https://www.w3.org/ns/activitystreams#anyOf","https://www.w3.org/ns/activitystreams#attachment","https://www.w3.org/ns/activitystreams#attributedTo","https://www.w3.org/ns/activitystreams#audience","https://www.w3.org/ns/activitystreams#bcc","https://www.w3.org/ns/activitystreams#bto","https://www.w3.org/ns/activitystreams#cc","https://www.w3.org/ns/activitystreams#context","https://www.w3.org/ns/activitystreams#current","https://www.w3.org/ns/activitystreams#describes","https://www.w3.org/ns/activitystreams#first","https://www.w3.org/ns/activitystreams#followers","https://www.w3.org/ns/activitystreams#following","https://www.w3.org/ns/activitystreams#generator","https://www.w3.org/ns/activitystreams#href","https://www.w3.org/ns/activitystreams#icon","https://www.w3.org/ns/activitystreams#image","https://www.w3.org/ns/activitystreams#inReplyTo","https://www.w3.org/ns/activitystreams#instrument","https://www.w3.org/ns/activitystreams#items","https://www.w3.org/ns/activitystreams#last","https://www.w3.org/ns/activitystreams#liked","https://www.w3.org/ns/activitystreams#likes","https://www.w3.org/ns/activitystreams#location","https://www.w3.org/ns/activitystreams#movedTo","https://www.w3.org/ns/activitystreams#next","https://www.w3.org/ns/activitystreams#oauthAuthorizationEndpoint","https://www.w3.org/ns/activitystreams#oauthTokenEndpoint","https://www.w3.org/ns/activitystreams#object","https://www.w3.org/ns/activitystreams#oneOf","https://www.w3.org/ns/activitystreams#origin","https://www.w3.org/ns/activitystreams#outbox","https://www.w3.org/ns/activitystreams#partOf","https://www.w3.org/ns/activitystreams#prev","https://www.w3.org/ns/activitystreams#preview","https://www.w3.org/ns/activitystreams#provideClientKey","https://www.w3.org/ns/activitystreams#proxyUrl","https://www.w3.org/ns/activitystreams#quoteUrl","https://www.w3.org/ns/activitystreams#relationship","https://www.w3.org/ns/activitystreams#replies","https://www.w3.org/ns/activitystreams#result","https://www.w3.org/ns/activitystreams#sharedInbox","https://www.w3.org/ns/activitystreams#shares","https://www.w3.org/ns/activitystreams#signClientKey","https://www.w3.org/ns/activitystreams#streams","https://www.w3.org/ns/activitystreams#subject","https://www.w3.org/ns/activitystreams#tag","https://www.w3.org/ns/activitystreams#target","https://www.w3.org/ns/activitystreams#to","https://www.w3.org/ns/activitystreams#units","https://www.w3.org/ns/activitystreams#url","https://www.w3.org/ns/did#service","https://www.w3.org/ns/did#serviceEndpoint","icon","id","image","inReplyTo","inbox","inboxOf","instrument","interactingObject","interactionTarget","items","last","likeAuthorization","liked","likedOf","likes","likesOf","location","manualApproval","movedTo","next","oauthAuthorizationEndpoint","oauthTokenEndpoint","object","oneOf","orderedItems","origin","outbox","outboxOf","owner","partOf","prev","preview","proof","provideClientKey","proxyUrl","publicKey","quote","quoteAuthorization","quoteUri","quoteUrl","relationship","replies","repliesOf","replyAuthorization","resourceConformsTo","result","satisfies","service","sharedInbox","shares","sharesOf","signClientKey","streams","subject","tag","target","to","units","url"]); import * as _ppM0 from "./preprocessors.ts"; @@ -2157,9 +2167,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -2169,21 +2180,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#attachment_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -2212,7 +2222,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -2317,8 +2327,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_49BipA5dq9eoH8LX8xdsVumveTca_attachment.has(i)) { v = v.id; } @@ -2358,9 +2369,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_49BipA5dq9eoH8LX8xdsVumveTca_attachment.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_49BipA5dq9eoH8LX8xdsVumveTca_attachment.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -2405,9 +2416,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -2417,21 +2429,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#attribution_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -2460,7 +2471,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -2583,8 +2594,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.length < 1) return null; let v = this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(0)) { v = v.id; } @@ -2623,8 +2635,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -2689,8 +2701,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(i)) { v = v.id; } @@ -2730,9 +2743,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -2777,9 +2790,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -2789,21 +2803,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#audience_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -2832,7 +2845,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -2918,8 +2931,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.length < 1) return null; let v = this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(0)) { v = v.id; } @@ -2958,8 +2972,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -3023,8 +3037,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(i)) { v = v.id; } @@ -3064,9 +3079,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -3140,9 +3155,10 @@ get contents(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -3152,21 +3168,20 @@ get contents(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#context_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -3195,7 +3210,7 @@ get contents(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -3295,8 +3310,9 @@ get contents(): ((string | LanguageString))[] { const vs = this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3mhZzGXSpQ431mBSz2kvych22v4e_context.has(i)) { v = v.id; } @@ -3336,9 +3352,9 @@ get contents(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3mhZzGXSpQ431mBSz2kvych22v4e_context.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3mhZzGXSpQ431mBSz2kvych22v4e_context.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -3425,9 +3441,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -3437,21 +3454,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#generator_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -3480,7 +3496,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -3574,8 +3590,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_86xFhmgBapoMvYqjbjRuDPayTrS_generator.has(i)) { v = v.id; } @@ -3615,9 +3632,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_86xFhmgBapoMvYqjbjRuDPayTrS_generator.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_86xFhmgBapoMvYqjbjRuDPayTrS_generator.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -3662,9 +3679,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -3674,21 +3692,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#icon_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -3717,7 +3734,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -3825,8 +3842,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.length < 1) return null; let v = this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(0)) { v = v.id; } @@ -3865,8 +3883,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -3931,8 +3949,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(i)) { v = v.id; } @@ -3972,9 +3991,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -4019,9 +4038,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -4031,21 +4051,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#image_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -4074,7 +4093,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -4182,8 +4201,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.length < 1) return null; let v = this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(0)) { v = v.id; } @@ -4222,8 +4242,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -4288,8 +4308,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(i)) { v = v.id; } @@ -4329,9 +4350,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3dXrUdkARxwyJLtJcYi1AJ92H41U_image.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -4376,9 +4397,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -4388,21 +4410,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#replyTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -4431,7 +4452,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -4526,8 +4547,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.length < 1) return null; let v = this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(0)) { v = v.id; } @@ -4566,8 +4588,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -4631,8 +4653,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(i)) { v = v.id; } @@ -4672,9 +4695,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -4719,9 +4742,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -4731,21 +4755,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#location_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -4774,7 +4797,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -4869,8 +4892,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.length < 1) return null; let v = this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(0)) { v = v.id; } @@ -4909,8 +4933,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -4974,8 +4998,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(i)) { v = v.id; } @@ -5015,9 +5040,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_31k5MUZJsnsPNg8dQQJieWaXTFnR_location.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -5062,9 +5087,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5074,21 +5100,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#preview_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -5117,7 +5142,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -5211,8 +5236,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview.length < 1) return null; let v = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { v = v.id; } @@ -5251,8 +5277,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -5315,8 +5341,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { v = v.id; } @@ -5356,9 +5383,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -5416,9 +5443,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5428,21 +5456,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#replies_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -5471,7 +5498,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -5557,8 +5584,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_7UpwM3JWcXhADcscukEehBorf6k_replies.length < 1) return null; let v = this.#_7UpwM3JWcXhADcscukEehBorf6k_replies[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_7UpwM3JWcXhADcscukEehBorf6k_replies.has(0)) { v = v.id; } @@ -5597,8 +5625,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_7UpwM3JWcXhADcscukEehBorf6k_replies.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -5643,9 +5671,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5655,21 +5684,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#shares_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -5698,7 +5726,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -5790,8 +5818,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares.length < 1) return null; let v = this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3kAfck9PcEYt2L7xug5y99YPbANs_shares.has(0)) { v = v.id; } @@ -5830,8 +5859,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3kAfck9PcEYt2L7xug5y99YPbANs_shares.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -5876,9 +5905,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -5888,21 +5918,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likes_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -5931,7 +5960,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6023,8 +6052,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.length < 1) return null; let v = this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.has(0)) { v = v.id; } @@ -6063,8 +6093,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -6109,9 +6139,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6121,21 +6152,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#emojiReactions_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -6164,7 +6194,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6250,8 +6280,9 @@ get names(): ((string | LanguageString))[] { } if (this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.length < 1) return null; let v = this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.has(0)) { v = v.id; } @@ -6290,8 +6321,8 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -6376,9 +6407,10 @@ get summaries(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6388,21 +6420,20 @@ get summaries(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#tag_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -6431,7 +6462,7 @@ get summaries(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6528,8 +6559,9 @@ get summaries(): ((string | LanguageString))[] { const vs = this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_5chuqj6s95p5gg2sk1HntGfarRf_tag.has(i)) { v = v.id; } @@ -6569,9 +6601,9 @@ get summaries(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_5chuqj6s95p5gg2sk1HntGfarRf_tag.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_5chuqj6s95p5gg2sk1HntGfarRf_tag.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -6650,9 +6682,10 @@ get urls(): ((URL | Link))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6662,21 +6695,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#to_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -6705,7 +6737,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -6791,8 +6823,9 @@ get urls(): ((URL | Link))[] { } if (this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.length < 1) return null; let v = this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(0)) { v = v.id; } @@ -6831,8 +6864,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -6896,8 +6929,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(i)) { v = v.id; } @@ -6937,9 +6971,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -6984,9 +7018,10 @@ get urls(): ((URL | Link))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -6996,21 +7031,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#bto_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -7039,7 +7073,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -7125,8 +7159,9 @@ get urls(): ((URL | Link))[] { } if (this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.length < 1) return null; let v = this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(0)) { v = v.id; } @@ -7165,8 +7200,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -7230,8 +7265,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(i)) { v = v.id; } @@ -7271,9 +7307,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -7318,9 +7354,10 @@ get urls(): ((URL | Link))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -7330,21 +7367,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#cc_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -7373,7 +7409,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -7459,8 +7495,9 @@ get urls(): ((URL | Link))[] { } if (this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.length < 1) return null; let v = this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(0)) { v = v.id; } @@ -7499,8 +7536,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -7564,8 +7601,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(i)) { v = v.id; } @@ -7605,9 +7643,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -7652,9 +7690,10 @@ get urls(): ((URL | Link))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -7664,21 +7703,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#bcc_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -7707,7 +7745,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -7793,8 +7831,9 @@ get urls(): ((URL | Link))[] { } if (this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.length < 1) return null; let v = this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(0)) { v = v.id; } @@ -7833,8 +7872,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -7898,8 +7937,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(i)) { v = v.id; } @@ -7939,9 +7979,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -8050,9 +8090,10 @@ get urls(): ((URL | Link))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8062,21 +8103,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#proof_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -8105,7 +8145,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -8190,8 +8230,9 @@ get urls(): ((URL | Link))[] { } if (this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.length < 1) return null; let v = this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(0)) { v = v.id; } @@ -8230,8 +8271,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -8294,8 +8335,9 @@ get urls(): ((URL | Link))[] { const vs = this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(i)) { v = v.id; } @@ -8335,9 +8377,9 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -8421,9 +8463,10 @@ get urls(): ((URL | Link))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8433,21 +8476,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likeAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -8476,7 +8518,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -8562,8 +8604,9 @@ get urls(): ((URL | Link))[] { } if (this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.length < 1) return null; let v = this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.has(0)) { v = v.id; } @@ -8602,8 +8645,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -8648,9 +8691,10 @@ get urls(): ((URL | Link))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8660,21 +8704,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#replyAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -8703,7 +8746,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -8789,8 +8832,9 @@ get urls(): ((URL | Link))[] { } if (this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.length < 1) return null; let v = this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.has(0)) { v = v.id; } @@ -8829,8 +8873,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -8875,9 +8919,10 @@ get urls(): ((URL | Link))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -8887,21 +8932,20 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#announceAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -8930,7 +8974,7 @@ get urls(): ((URL | Link))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -9016,8 +9060,9 @@ get urls(): ((URL | Link))[] { } if (this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.length < 1) return null; let v = this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.has(0)) { v = v.id; } @@ -9056,8 +9101,8 @@ get urls(): ((URL | Link))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -9118,7 +9163,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9146,7 +9191,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9182,7 +9227,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9221,7 +9266,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9280,7 +9325,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9304,7 +9349,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9324,7 +9369,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9344,7 +9389,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9368,7 +9413,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9392,7 +9437,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const item = ( - v instanceof URL ? v.href : v instanceof Link ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Link ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9432,7 +9477,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_7UpwM3JWcXhADcscukEehBorf6k_replies) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9452,7 +9497,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9472,7 +9517,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9492,7 +9537,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9547,7 +9592,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9587,7 +9632,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9607,7 +9652,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9627,7 +9672,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9647,7 +9692,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9667,7 +9712,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9755,7 +9800,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9795,7 +9840,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_23YiVs2miQcEiUdn4u8SvjQKWYim_approvedBy) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -9811,7 +9856,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9831,7 +9876,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9851,7 +9896,7 @@ get urls(): ((URL | Link))[] { compactItems = []; for (const v of this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -9869,7 +9914,7 @@ get urls(): ((URL | Link))[] { } result["type"] = "Object"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"fedibird":"http://fedibird.com/ns#","sensitive":"as:sensitive","emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"}}]; return result; } @@ -9880,7 +9925,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_49BipA5dq9eoH8LX8xdsVumveTca_attachment) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Object ? await v.toJsonLd(options) : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -9895,7 +9940,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -9910,7 +9955,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3ocC3VVi88cEd5sPWL8djkZsvTN6_audience) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -9943,7 +9988,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3mhZzGXSpQ431mBSz2kvych22v4e_context) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -9994,7 +10039,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_86xFhmgBapoMvYqjbjRuDPayTrS_generator) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10009,7 +10054,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_33CjRLy5ujtsUrwRSCrsggvGdKuR_icon) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10024,7 +10069,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3dXrUdkARxwyJLtJcYi1AJ92H41U_image) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10039,7 +10084,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10054,7 +10099,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_31k5MUZJsnsPNg8dQQJieWaXTFnR_location) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10069,7 +10114,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10102,7 +10147,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_7UpwM3JWcXhADcscukEehBorf6k_replies) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10117,7 +10162,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3kAfck9PcEYt2L7xug5y99YPbANs_shares) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10132,7 +10177,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_S3ceDnpMdzoTRCccB9FkJWrEzYW_likes) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10147,7 +10192,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10198,7 +10243,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_5chuqj6s95p5gg2sk1HntGfarRf_tag) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -10231,7 +10276,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_2oPEH9MQ3aj8JVwyYuWkqoVwV865_url) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10246,7 +10291,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3hFbw7DTpHhq3cvVhkY8njhcsXbd_to) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10261,7 +10306,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_aLZupjwL8XB7tzdLgCMXdjZ6qej_bto) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10276,7 +10321,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_42a1SvBs24QSLzKcfjCyNTjW5a1g_cc) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10291,7 +10336,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10369,7 +10414,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_42rPnotok1ivQ2RNCKNbeFJgx8b8_proof) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push({ "@graph": element });; } @@ -10399,7 +10444,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_23YiVs2miQcEiUdn4u8SvjQKWYim_approvedBy) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -10414,7 +10459,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10429,7 +10474,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10444,7 +10489,7 @@ get urls(): ((URL | Link))[] { array = []; for (const v of this.#_446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -10457,7 +10502,7 @@ get urls(): ((URL | Link))[] { } values["@type"] = ["https://www.w3.org/ns/activitystreams#Object"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -10589,10 +10634,12 @@ get urls(): ((URL | Link))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -10600,11 +10647,9 @@ get urls(): ((URL | Link))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -10874,8 +10919,21 @@ get urls(): ((URL | Link))[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); @@ -10896,11 +10954,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _49BipA5dq9eoH8LX8xdsVumveTca_attachment.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _49BipA5dq9eoH8LX8xdsVumveTca_attachment.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -10944,11 +10998,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _42CGqJ94zgQ3ZBbfHwD8Hrr2L5Py_attributedTo.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -10998,11 +11048,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3ocC3VVi88cEd5sPWL8djkZsvTN6_audience.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11056,11 +11102,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3mhZzGXSpQ431mBSz2kvych22v4e_context.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3mhZzGXSpQ431mBSz2kvych22v4e_context.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11146,11 +11188,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _86xFhmgBapoMvYqjbjRuDPayTrS_generator.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _86xFhmgBapoMvYqjbjRuDPayTrS_generator.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11212,11 +11250,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _33CjRLy5ujtsUrwRSCrsggvGdKuR_icon.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11268,11 +11302,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3dXrUdkARxwyJLtJcYi1AJ92H41U_image.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3dXrUdkARxwyJLtJcYi1AJ92H41U_image.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11302,11 +11332,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3fpbDrvZgf3Kq1a5V9aByFn8kx3s_inReplyTo.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11346,11 +11372,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _31k5MUZJsnsPNg8dQQJieWaXTFnR_location.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _31k5MUZJsnsPNg8dQQJieWaXTFnR_location.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11390,11 +11412,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11456,11 +11474,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _7UpwM3JWcXhADcscukEehBorf6k_replies.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _7UpwM3JWcXhADcscukEehBorf6k_replies.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11490,11 +11504,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3kAfck9PcEYt2L7xug5y99YPbANs_shares.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3kAfck9PcEYt2L7xug5y99YPbANs_shares.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11524,11 +11534,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _S3ceDnpMdzoTRCccB9FkJWrEzYW_likes.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11558,11 +11564,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _kMatyyNAuxoTD8GQMBfA5ogThMR_emojiReactions.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11638,11 +11640,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _5chuqj6s95p5gg2sk1HntGfarRf_tag.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _5chuqj6s95p5gg2sk1HntGfarRf_tag.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11702,22 +11700,7 @@ get urls(): ((URL | Link))[] { const decoded = v != null && typeof v === "object" && "@id" in v && typeof v["@id"] === "string" - && v["@id"] !== "" ? v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl) : typeof v === "object" && "@type" in v + && v["@id"] !== "" ? parseIri(v["@id"], options.baseUrl) : typeof v === "object" && "@type" in v && Array.isArray(v["@type"])&& ["https://www.w3.org/ns/activitystreams#Link","https://www.w3.org/ns/activitystreams#Hashtag","https://www.w3.org/ns/activitystreams#Mention"].some( t => v["@type"].includes(t)) ? await Link.fromJsonLd( v, @@ -11747,11 +11730,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3hFbw7DTpHhq3cvVhkY8njhcsXbd_to.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11781,11 +11760,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _aLZupjwL8XB7tzdLgCMXdjZ6qej_bto.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11815,11 +11790,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _42a1SvBs24QSLzKcfjCyNTjW5a1g_cc.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11849,11 +11820,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3qvegKUB8YLgTXRpEf8E6JZSkz2H_bcc.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -11958,11 +11925,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _42rPnotok1ivQ2RNCKNbeFJgx8b8_proof.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -12008,22 +11971,7 @@ get urls(): ((URL | Link))[] { ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _23YiVs2miQcEiUdn4u8SvjQKWYim_approvedBy.push(decoded); } @@ -12046,11 +11994,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3fCeb5aXaDDd4fvkQ96BLWifBUBa_likeAuthorization.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -12080,11 +12024,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _YA4wdUW7rYztAQ6SjhMnJCmcmtP_replyAuthorization.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -12114,11 +12054,7 @@ get urls(): ((URL | Link))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _446xEaDBs3Fz6MyzP3PSBaLupkbJ_announceAuthorization.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -12133,7 +12069,19 @@ get urls(): ((URL | Link))[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -13165,7 +13113,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result["type"] = "Emoji"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams",{"toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}]; return result; } @@ -13184,7 +13132,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values["@type"] = ["http://joinmastodon.org/ns#Emoji"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -13291,10 +13239,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -13302,11 +13252,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -13320,6 +13268,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -13332,7 +13291,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -13575,9 +13546,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -13587,21 +13559,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -13630,7 +13601,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -13717,8 +13688,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -13757,8 +13729,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -13826,9 +13798,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -13838,21 +13811,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -13881,7 +13853,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -13967,8 +13939,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -14007,8 +13980,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -14075,7 +14048,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -14095,7 +14068,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -14121,7 +14094,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -14139,7 +14112,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "ChatMessage"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"toot":"http://joinmastodon.org/ns#","misskey":"https://misskey-hub.net/ns#","fedibird":"http://fedibird.com/ns#","Emoji":"toot:Emoji","ChatMessage":"http://litepub.social/ns#ChatMessage","quote":{"@id":"https://w3id.org/fep/044f#quote","@type":"@id"},"quoteUrl":"as:quoteUrl","_misskey_quote":"misskey:_misskey_quote","quoteUri":"fedibird:quoteUri","QuoteAuthorization":"https://w3id.org/fep/044f#QuoteAuthorization","quoteAuthorization":{"@id":"https://w3id.org/fep/044f#quoteAuthorization","@type":"@id"},"emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"}}]; return result; } @@ -14160,7 +14133,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -14175,7 +14148,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { "@value": v.href } + { "@value": formatIri(v) } ); array.push(element);; } @@ -14194,7 +14167,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -14207,7 +14180,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["http://litepub.social/ns#ChatMessage"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -14314,10 +14287,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -14325,11 +14300,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -14343,6 +14316,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -14370,11 +14354,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -14407,7 +14387,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ) { if (v == null) continue; - const decoded = new URL(v["@value"]); + const decoded = parseIri(v["@value"]); if (typeof decoded === "undefined") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -14430,11 +14410,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -14449,7 +14425,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -15183,9 +15171,10 @@ instruments?: (Object | URL)[];} "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -15195,21 +15184,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#actor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -15238,7 +15226,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -15361,8 +15349,9 @@ instruments?: (Object | URL)[];} } if (this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.length < 1) return null; let v = this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(0)) { v = v.id; } @@ -15401,8 +15390,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -15467,8 +15456,9 @@ instruments?: (Object | URL)[];} const vs = this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(i)) { v = v.id; } @@ -15508,9 +15498,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -15555,9 +15545,10 @@ instruments?: (Object | URL)[];} "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -15567,21 +15558,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#object_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -15610,7 +15600,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -15697,8 +15687,9 @@ instruments?: (Object | URL)[];} } if (this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.length < 1) return null; let v = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { v = v.id; } @@ -15737,8 +15728,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -15803,8 +15794,9 @@ instruments?: (Object | URL)[];} const vs = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { v = v.id; } @@ -15844,9 +15836,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -15891,9 +15883,10 @@ instruments?: (Object | URL)[];} "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -15903,21 +15896,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#target_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -15946,7 +15938,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -16036,8 +16028,9 @@ instruments?: (Object | URL)[];} } if (this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.length < 1) return null; let v = this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(0)) { v = v.id; } @@ -16076,8 +16069,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -16145,8 +16138,9 @@ instruments?: (Object | URL)[];} const vs = this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(i)) { v = v.id; } @@ -16186,9 +16180,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -16233,9 +16227,10 @@ instruments?: (Object | URL)[];} "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -16245,21 +16240,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#result_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -16288,7 +16282,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -16375,8 +16369,9 @@ instruments?: (Object | URL)[];} } if (this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.length < 1) return null; let v = this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(0)) { v = v.id; } @@ -16415,8 +16410,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -16481,8 +16476,9 @@ instruments?: (Object | URL)[];} const vs = this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(i)) { v = v.id; } @@ -16522,9 +16518,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -16569,9 +16565,10 @@ instruments?: (Object | URL)[];} "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -16581,21 +16578,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#origin_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -16624,7 +16620,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -16712,8 +16708,9 @@ instruments?: (Object | URL)[];} } if (this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin.length < 1) return null; let v = this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(0)) { v = v.id; } @@ -16752,8 +16749,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -16819,8 +16816,9 @@ instruments?: (Object | URL)[];} const vs = this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(i)) { v = v.id; } @@ -16860,9 +16858,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_25zu2s3VxVujgEKqrDycjE284XQR_origin.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -16907,9 +16905,10 @@ instruments?: (Object | URL)[];} "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -16919,21 +16918,20 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#instrument_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -16962,7 +16960,7 @@ instruments?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -17048,8 +17046,9 @@ instruments?: (Object | URL)[];} } if (this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.length < 1) return null; let v = this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(0)) { v = v.id; } @@ -17088,8 +17087,8 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -17153,8 +17152,9 @@ instruments?: (Object | URL)[];} const vs = this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(i)) { v = v.id; } @@ -17194,9 +17194,9 @@ instruments?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -17265,7 +17265,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -17280,7 +17280,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17295,7 +17295,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17310,7 +17310,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_u4QGFbRFcYmPEKGbPv1hpBR9r5G_result) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17325,7 +17325,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_25zu2s3VxVujgEKqrDycjE284XQR_origin) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17340,7 +17340,7 @@ instruments?: (Object | URL)[];} array = []; for (const v of this.#_3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -17353,7 +17353,7 @@ instruments?: (Object | URL)[];} } values["@type"] = ["https://www.w3.org/ns/activitystreams#Activity"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -17460,10 +17460,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -17471,11 +17473,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -17625,6 +17625,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -17652,11 +17663,7 @@ instruments?: (Object | URL)[];} if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2DjTTboo3CNHU2a2JQqUSE2dbv9D_actor.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -17706,11 +17713,7 @@ instruments?: (Object | URL)[];} if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -17740,11 +17743,7 @@ instruments?: (Object | URL)[];} if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3JQCmF2Ww56Ag9EWRYoSZRDNCYtF_target.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -17774,11 +17773,7 @@ instruments?: (Object | URL)[];} if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _u4QGFbRFcYmPEKGbPv1hpBR9r5G_result.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -17808,11 +17803,7 @@ instruments?: (Object | URL)[];} if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _25zu2s3VxVujgEKqrDycjE284XQR_origin.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _25zu2s3VxVujgEKqrDycjE284XQR_origin.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -17842,11 +17833,7 @@ instruments?: (Object | URL)[];} if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3c5t2x7DYRo2shwTxpkd4kYSS5WQ_instrument.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -17861,7 +17848,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -18205,7 +18204,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["http://litepub.social/ns#EmojiReact"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -18312,10 +18311,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -18323,11 +18324,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -18341,6 +18340,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -18353,7 +18363,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -18674,7 +18696,7 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} } result["type"] = "PropertyValue"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams",{"schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value"}]; return result; } @@ -18719,7 +18741,7 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} } values["@type"] = ["http://schema.org#PropertyValue"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -18825,10 +18847,12 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -18836,11 +18860,9 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -18854,8 +18876,21 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _4ZHbBuK7PrsvGgrjM8wgc6KMWjav_name: ((string | LanguageString))[] = []; @@ -18909,7 +18944,19 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -19283,7 +19330,7 @@ unit?: string | null;numericalValue?: Decimal | null;} } result["type"] = "om2:Measure"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams",{"om2":"http://www.ontology-of-units-of-measure.org/resource/om-2/","hasUnit":"om2:hasUnit","hasNumericalValue":"om2:hasNumericalValue"}]; return result; } @@ -19325,7 +19372,7 @@ unit?: string | null;numericalValue?: Decimal | null;} } values["@type"] = ["http://www.ontology-of-units-of-measure.org/resource/om-2/Measure"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -19421,10 +19468,12 @@ unit?: string | null;numericalValue?: Decimal | null;} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -19432,11 +19481,9 @@ unit?: string | null;numericalValue?: Decimal | null;} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -19450,8 +19497,21 @@ unit?: string | null;numericalValue?: Decimal | null;} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _27fgyFbosTtMAhuepJH8K3ZGURT6: (string)[] = []; @@ -19493,7 +19553,19 @@ unit?: string | null;numericalValue?: Decimal | null;} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -19768,9 +19840,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -19780,21 +19853,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -19823,7 +19895,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -19909,8 +19981,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -19949,8 +20022,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -19995,9 +20068,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -20007,21 +20081,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -20050,7 +20123,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -20135,8 +20208,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -20175,8 +20249,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -20243,7 +20317,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -20263,7 +20337,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -20281,7 +20355,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "AnnounceAuthorization"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -20302,7 +20376,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -20317,7 +20391,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -20330,7 +20404,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://gotosocial.org/ns#AnnounceAuthorization"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -20437,10 +20511,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -20448,11 +20524,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -20466,6 +20540,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -20493,11 +20578,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -20527,11 +20608,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -20546,7 +20623,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -20784,7 +20873,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://gotosocial.org/ns#AnnounceRequest"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -20891,10 +20980,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -20902,11 +20993,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -20920,6 +21009,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -20932,7 +21032,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -21376,7 +21488,7 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: } - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -21492,10 +21604,12 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -21503,11 +21617,9 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -21521,8 +21633,21 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _3JkwVLb3BNCwCWdsb5RftGAg8vyT_canLike: (InteractionRule)[] = []; @@ -21612,7 +21737,19 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?: if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -22126,7 +22263,7 @@ get manualApprovals(): (URL)[] { array = []; for (const v of this.#_2rFyCF14HoyNjitj9PmCzek5iSsg_automaticApproval) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -22141,7 +22278,7 @@ get manualApprovals(): (URL)[] { array = []; for (const v of this.#_sxj8y5XMMMBWUnRYFw85MKedCMj_manualApproval) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -22154,7 +22291,7 @@ get manualApprovals(): (URL)[] { } - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -22250,10 +22387,12 @@ get manualApprovals(): (URL)[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -22261,11 +22400,9 @@ get manualApprovals(): (URL)[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -22279,8 +22416,21 @@ get manualApprovals(): (URL)[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _2rFyCF14HoyNjitj9PmCzek5iSsg_automaticApproval: (URL)[] = []; @@ -22296,22 +22446,7 @@ get manualApprovals(): (URL)[] { ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _2rFyCF14HoyNjitj9PmCzek5iSsg_automaticApproval.push(decoded); } @@ -22329,22 +22464,7 @@ get manualApprovals(): (URL)[] { ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _sxj8y5XMMMBWUnRYFw85MKedCMj_manualApproval.push(decoded); } @@ -22352,7 +22472,19 @@ get manualApprovals(): (URL)[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -22638,9 +22770,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -22650,21 +22783,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -22693,7 +22825,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -22779,8 +22911,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -22819,8 +22952,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -22865,9 +22998,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -22877,21 +23011,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -22920,7 +23053,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -23005,8 +23138,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -23045,8 +23179,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -23113,7 +23247,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -23133,7 +23267,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -23151,7 +23285,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "LikeAuthorization"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -23172,7 +23306,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -23187,7 +23321,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -23200,7 +23334,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://gotosocial.org/ns#LikeApproval"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -23307,10 +23441,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -23318,11 +23454,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -23336,6 +23470,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -23363,11 +23508,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -23397,11 +23538,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -23416,7 +23553,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -23653,7 +23802,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://gotosocial.org/ns#LikeRequest"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -23760,10 +23909,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -23771,11 +23922,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -23789,6 +23938,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -23801,7 +23961,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -24020,9 +24192,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -24032,21 +24205,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -24075,7 +24247,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -24161,8 +24333,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -24201,8 +24374,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -24247,9 +24420,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -24259,21 +24433,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -24302,7 +24475,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -24387,8 +24560,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -24427,8 +24601,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -24495,7 +24669,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -24515,7 +24689,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -24533,7 +24707,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "ReplyAuthorization"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -24554,7 +24728,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -24569,7 +24743,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -24582,7 +24756,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://gotosocial.org/ns#ReplyAuthorization"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -24689,10 +24863,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -24700,11 +24876,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -24718,6 +24892,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -24745,11 +24930,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -24779,11 +24960,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -24798,7 +24975,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -25035,7 +25224,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://gotosocial.org/ns#ReplyRequest"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -25142,10 +25331,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -25153,11 +25344,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -25171,6 +25360,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -25183,7 +25383,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -25402,9 +25614,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -25414,21 +25627,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactingObject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -25457,7 +25669,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -25542,8 +25754,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.length < 1) return null; let v = this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { v = v.id; } @@ -25582,8 +25795,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -25628,9 +25841,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -25640,21 +25854,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#interactionTarget_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -25683,7 +25896,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -25768,8 +25981,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.length < 1) return null; let v = this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { v = v.id; } @@ -25808,8 +26022,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -25876,7 +26090,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -25896,7 +26110,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -25914,7 +26128,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "QuoteAuthorization"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"QuoteAuthorization":"https://w3id.org/fep/044f#QuoteAuthorization"}]; return result; } @@ -25935,7 +26149,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -25950,7 +26164,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -25963,7 +26177,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://w3id.org/fep/044f#QuoteAuthorization"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -26070,10 +26284,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -26081,11 +26297,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -26099,6 +26313,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -26126,11 +26351,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2114kRKbujWhxEUghdkRYYKbXTGi_interactingObject.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -26160,11 +26381,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2wHyG75YnN15CDMaFk3VNjByu4aL_interactionTarget.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -26179,7 +26396,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -26416,7 +26645,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://w3id.org/fep/044f#QuoteRequest"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -26523,10 +26752,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -26534,11 +26765,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -26552,6 +26781,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -26564,7 +26804,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -26869,7 +27121,7 @@ get endpoints(): (URL)[] { array = []; for (const v of this.#_2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -26882,7 +27134,7 @@ get endpoints(): (URL)[] { } values["@type"] = ["https://www.w3.org/ns/did#Service"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -26978,10 +27230,12 @@ get endpoints(): (URL)[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -26989,11 +27243,9 @@ get endpoints(): (URL)[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -27011,8 +27263,21 @@ get endpoints(): (URL)[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint: (URL)[] = []; @@ -27028,22 +27293,7 @@ get endpoints(): (URL)[] { ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _2KM4fetG6FTJ1cphj76rzJ8Dyv7p_serviceEndpoint.push(decoded); } @@ -27051,7 +27301,19 @@ get endpoints(): (URL)[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -27238,7 +27500,7 @@ endpoints?: (URL)[];} >; values["@type"] = ["https://w3id.org/fep/9091#Export"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -27334,10 +27596,12 @@ endpoints?: (URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -27345,11 +27609,9 @@ endpoints?: (URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -27363,6 +27625,17 @@ endpoints?: (URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -27375,7 +27648,19 @@ endpoints?: (URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -27721,9 +28006,10 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -27733,21 +28019,20 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#verificationMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -27776,7 +28061,7 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -27864,8 +28149,9 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null } if (this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.length < 1) return null; let v = this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { v = v.id; } @@ -27879,8 +28165,8 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null return fetched; } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -28000,7 +28286,7 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null array = []; for (const v of this.#_2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -28066,7 +28352,7 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null } values["@type"] = ["https://w3id.org/security#DataIntegrityProof"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -28162,10 +28448,12 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -28173,11 +28461,9 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -28191,8 +28477,21 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _3RurJsa7tnptyqMFR5hDGcP9pMs5_cryptosuite: ("eddsa-jcs-2022")[] = []; @@ -28231,11 +28530,7 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2mHVKxqA7zncjveJrDEo3pWpMZqg_verificationMethod.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -28308,7 +28603,19 @@ cryptosuite?: "eddsa-jcs-2022" | null;verificationMethod?: Multikey | URL | null if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -28674,9 +28981,10 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -28686,21 +28994,20 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#owner_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -28729,7 +29036,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -28849,8 +29156,9 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } if (this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.length < 1) return null; let v = this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { v = v.id; } @@ -28889,8 +29197,8 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -28964,7 +29272,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi compactItems = []; for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -29014,7 +29322,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } result["type"] = "CryptographicKey"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = "https://w3id.org/security/v1"; return result; } @@ -29025,7 +29333,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi array = []; for (const v of this.#_5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -29053,7 +29361,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } values["@type"] = ["https://w3id.org/security#Key"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -29149,10 +29457,12 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -29160,11 +29470,9 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -29178,8 +29486,21 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); @@ -29200,11 +29521,7 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _5UJq9NDh3ZHgswFwwdVxQvJxdx2_owner.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -29257,7 +29574,19 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -29567,9 +29896,10 @@ controller?: Application | Group | Organization | Person | Service | URL | null; "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -29579,21 +29909,20 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#controller_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -29622,7 +29951,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -29742,8 +30071,9 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } if (this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.length < 1) return null; let v = this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { v = v.id; } @@ -29782,8 +30112,8 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -29861,7 +30191,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; compactItems = []; for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -29911,7 +30241,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } result["type"] = "Multikey"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = "https://w3id.org/security/multikey/v1"; return result; } @@ -29922,7 +30252,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; array = []; for (const v of this.#_2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -29953,7 +30283,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } values["@type"] = ["https://w3id.org/security#Multikey"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -30049,10 +30379,12 @@ controller?: Application | Group | Organization | Person | Service | URL | null; }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -30060,11 +30392,9 @@ controller?: Application | Group | Organization | Person | Service | URL | null; // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -30078,8 +30408,21 @@ controller?: Application | Group | Organization | Person | Service | URL | null; } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); @@ -30100,11 +30443,7 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2yr3eUBTP6cNcyaxKzAXWjFsnGzN_controller.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -30157,7 +30496,19 @@ controller?: Application | Group | Organization | Person | Service | URL | null; if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -30523,7 +30874,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "Agreement"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"vf":"https://w3id.org/valueflows/ont/vf#","om2":"http://www.ontology-of-units-of-measure.org/resource/om-2/","fedibird":"http://fedibird.com/ns#","sensitive":"as:sensitive","emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"},"Agreement":"vf:Agreement","Commitment":"vf:Commitment","stipulates":"vf:stipulates","stipulatesReciprocal":"vf:stipulatesReciprocal","satisfies":{"@id":"vf:satisfies","@type":"@id"},"resourceQuantity":"vf:resourceQuantity","hasUnit":"om2:hasUnit","hasNumericalValue":"om2:hasNumericalValue"}]; return result; } @@ -30572,7 +30923,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://w3id.org/valueflows/ont/vf#Agreement"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -30679,10 +31030,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -30690,11 +31043,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -30708,6 +31059,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -30762,7 +31124,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -31099,7 +31473,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} compactItems = []; for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -31133,7 +31507,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} } result["type"] = "Commitment"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams",{"vf":"https://w3id.org/valueflows/ont/vf#","om2":"http://www.ontology-of-units-of-measure.org/resource/om-2/","Commitment":"vf:Commitment","satisfies":{"@id":"vf:satisfies","@type":"@id"},"resourceQuantity":"vf:resourceQuantity","hasUnit":"om2:hasUnit","hasNumericalValue":"om2:hasNumericalValue"}]; return result; } @@ -31144,7 +31518,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} array = []; for (const v of this.#_aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -31172,7 +31546,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} } values["@type"] = ["https://w3id.org/valueflows/ont/vf#Commitment"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -31268,10 +31642,12 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -31279,11 +31655,9 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -31297,8 +31671,21 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies: (URL)[] = []; @@ -31314,22 +31701,7 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _aCyzDK9TkXtLxrZs7JC8emuYisv_satisfies.push(decoded); } @@ -31358,7 +31730,19 @@ satisfies?: URL | null;resourceQuantity?: Measure | null;} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -31842,7 +32226,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur compactItems = []; for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -31916,7 +32300,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur } result["type"] = "Intent"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams",{"vf":"https://w3id.org/valueflows/ont/vf#","om2":"http://www.ontology-of-units-of-measure.org/resource/om-2/","Intent":"vf:Intent","action":"vf:action","resourceConformsTo":{"@id":"vf:resourceConformsTo","@type":"@id"},"resourceQuantity":"vf:resourceQuantity","availableQuantity":"vf:availableQuantity","minimumQuantity":"vf:minimumQuantity","hasUnit":"om2:hasUnit","hasNumericalValue":"om2:hasNumericalValue"}]; return result; } @@ -31942,7 +32326,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur array = []; for (const v of this.#_BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -32000,7 +32384,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur } values["@type"] = ["https://w3id.org/valueflows/ont/vf#Intent"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -32096,10 +32480,12 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -32107,11 +32493,9 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -32125,8 +32509,21 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _38VmZKmXJSBy3AvgqNa9GVqbdphy_action: (string)[] = []; @@ -32160,22 +32557,7 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _BBAeMUUQDwBQn6cvu3P2Csd6b6h_resourceConformsTo.push(decoded); } @@ -32246,7 +32628,19 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -32785,7 +33179,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "Proposal"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"vf":"https://w3id.org/valueflows/ont/vf#","om2":"http://www.ontology-of-units-of-measure.org/resource/om-2/","fedibird":"http://fedibird.com/ns#","sensitive":"as:sensitive","emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"},"Proposal":"vf:Proposal","Intent":"vf:Intent","purpose":"vf:purpose","unitBased":"vf:unitBased","publishes":"vf:publishes","reciprocal":"vf:reciprocal","action":"vf:action","resourceConformsTo":{"@id":"vf:resourceConformsTo","@type":"@id"},"resourceQuantity":"vf:resourceQuantity","availableQuantity":"vf:availableQuantity","minimumQuantity":"vf:minimumQuantity","hasUnit":"om2:hasUnit","hasNumericalValue":"om2:hasNumericalValue"}]; return result; } @@ -32864,7 +33258,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://w3id.org/valueflows/ont/vf#Proposal"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -32971,10 +33365,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -32982,11 +33378,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -33000,6 +33394,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -33090,7 +33495,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -33360,7 +33777,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Accept"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -33467,10 +33884,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -33478,11 +33897,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -33500,6 +33917,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -33512,7 +33940,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -33703,7 +34143,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Add"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -33810,10 +34250,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -33821,11 +34263,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -33839,6 +34279,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -33851,7 +34302,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -34041,7 +34504,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Announce"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -34148,10 +34611,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -34159,11 +34624,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -34177,6 +34640,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -34189,7 +34663,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -35274,9 +35760,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -35286,21 +35773,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -35329,7 +35815,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -35413,8 +35899,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -35453,8 +35940,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -35516,8 +36003,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -35557,9 +36045,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -35604,9 +36092,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -35616,21 +36105,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -35659,7 +36147,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -35747,8 +36235,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -35787,8 +36276,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -35854,8 +36343,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -35895,9 +36385,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -35961,9 +36451,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -35973,21 +36464,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -36016,7 +36506,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36122,8 +36612,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -36162,8 +36653,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -36208,9 +36699,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36220,21 +36712,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -36263,7 +36754,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36366,8 +36857,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -36406,8 +36898,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -36452,9 +36944,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36464,21 +36957,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -36507,7 +36999,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36596,8 +37088,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -36636,8 +37129,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -36682,9 +37175,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36694,21 +37188,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -36737,7 +37230,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -36829,8 +37322,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -36869,8 +37363,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -36915,9 +37409,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -36927,21 +37422,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -36970,7 +37464,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37060,8 +37554,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -37100,8 +37595,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -37146,9 +37641,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37158,21 +37654,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -37201,7 +37696,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37289,8 +37784,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -37329,8 +37825,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -37375,9 +37871,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37387,21 +37884,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -37430,7 +37926,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37518,8 +38014,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -37558,8 +38055,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -37604,9 +38101,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37616,21 +38114,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -37659,7 +38156,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -37744,8 +38241,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -37785,9 +38283,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -37907,9 +38405,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -37919,21 +38418,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -37962,7 +38460,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -38082,8 +38580,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -38122,8 +38621,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -38168,9 +38667,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -38180,21 +38680,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -38223,7 +38722,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -38347,8 +38846,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -38387,8 +38887,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -38454,8 +38954,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -38495,9 +38996,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -38542,9 +39043,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -38554,21 +39056,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -38597,7 +39098,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -38685,8 +39186,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -38725,8 +39227,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -38792,8 +39294,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -38833,9 +39336,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -38952,7 +39455,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -38972,7 +39475,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39008,7 +39511,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39032,7 +39535,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39056,7 +39559,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39076,7 +39579,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39096,7 +39599,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39116,7 +39619,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39136,7 +39639,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39156,7 +39659,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39260,7 +39763,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39296,7 +39799,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39332,7 +39835,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -39382,7 +39885,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result["type"] = "Application"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1","https://w3id.org/security/data-integrity/v1","https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1","https://gotosocial.org/ns",{"alsoKnownAs":{"@id":"as:alsoKnownAs","@type":"@id"},"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","movedTo":{"@id":"as:movedTo","@type":"@id"},"toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","featured":{"@id":"toot:featured","@type":"@id"},"featuredTags":{"@id":"toot:featuredTags","@type":"@id"},"discoverable":"toot:discoverable","suspended":"toot:suspended","memorial":"toot:memorial","indexable":"toot:indexable","schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","misskey":"https://misskey-hub.net/ns#","_misskey_followedMessage":"misskey:_misskey_followedMessage","isCat":"misskey:isCat"}]; return result; } @@ -39421,7 +39924,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39436,7 +39939,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39466,7 +39969,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39481,7 +39984,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39496,7 +39999,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39511,7 +40014,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39526,7 +40029,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39541,7 +40044,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39556,7 +40059,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39571,7 +40074,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39661,7 +40164,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39676,7 +40179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -39691,7 +40194,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -39734,7 +40237,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values["@type"] = ["https://www.w3.org/ns/activitystreams#Application"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -39851,10 +40354,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -39862,11 +40367,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -39880,6 +40383,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -39931,11 +40445,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -39965,11 +40475,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40017,11 +40523,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40059,11 +40561,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40101,11 +40599,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40135,11 +40629,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40169,11 +40659,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40203,11 +40689,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40237,11 +40719,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40271,11 +40749,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40398,11 +40872,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40452,11 +40922,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40506,11 +40972,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -40561,7 +41023,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -41223,7 +41697,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#IntransitiveActivity"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -41330,10 +41804,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -41341,11 +41817,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -41371,6 +41845,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -41383,7 +41868,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -41573,7 +42070,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Arrive"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -41680,10 +42177,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -41691,11 +42190,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -41709,6 +42206,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -41721,7 +42229,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -41959,9 +42479,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -41971,21 +42492,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -42014,7 +42534,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -42101,8 +42621,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -42141,8 +42662,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -42210,9 +42731,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -42222,21 +42744,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -42265,7 +42786,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -42351,8 +42872,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -42391,8 +42913,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -42459,7 +42981,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -42479,7 +43001,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -42505,7 +43027,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -42523,7 +43045,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "Article"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"toot":"http://joinmastodon.org/ns#","misskey":"https://misskey-hub.net/ns#","fedibird":"http://fedibird.com/ns#","sensitive":"as:sensitive","Emoji":"toot:Emoji","Hashtag":"as:Hashtag","quote":{"@id":"https://w3id.org/fep/044f#quote","@type":"@id"},"quoteUrl":"as:quoteUrl","_misskey_quote":"misskey:_misskey_quote","quoteUri":"fedibird:quoteUri","QuoteAuthorization":"https://w3id.org/fep/044f#QuoteAuthorization","quoteAuthorization":{"@id":"https://w3id.org/fep/044f#quoteAuthorization","@type":"@id"},"emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"}}]; return result; } @@ -42544,7 +43066,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -42559,7 +43081,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { "@value": v.href } + { "@value": formatIri(v) } ); array.push(element);; } @@ -42578,7 +43100,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -42591,7 +43113,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://www.w3.org/ns/activitystreams#Article"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -42698,10 +43220,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -42709,11 +43233,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -42727,6 +43249,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -42754,11 +43287,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -42791,7 +43320,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ) { if (v == null) continue; - const decoded = new URL(v["@value"]); + const decoded = parseIri(v["@value"]); if (typeof decoded === "undefined") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -42814,11 +43343,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -42833,7 +43358,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -43182,7 +43719,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "Document"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -43237,7 +43774,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://www.w3.org/ns/activitystreams#Document"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -43344,10 +43881,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -43355,11 +43894,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -43389,6 +43926,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -43437,7 +43985,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -43650,7 +44210,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result["type"] = "Audio"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -43669,7 +44229,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Audio"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -43776,10 +44336,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -43787,11 +44349,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -43805,6 +44365,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -43817,7 +44388,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -44006,7 +44589,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Ignore"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -44113,10 +44696,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -44124,11 +44709,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -44146,6 +44729,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -44158,7 +44752,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -44349,7 +44955,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Block"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -44456,10 +45062,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -44467,11 +45075,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -44485,6 +45091,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -44497,7 +45114,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -45059,9 +45688,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45071,21 +45701,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#current_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -45114,7 +45743,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45200,8 +45829,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current.length < 1) return null; let v = this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.has(0)) { v = v.id; } @@ -45240,8 +45870,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3UyUdxnyn6cDn53QKrh4MBiearma_current.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -45286,9 +45916,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45298,21 +45929,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#first_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -45341,7 +45971,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45427,8 +46057,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first.length < 1) return null; let v = this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.has(0)) { v = v.id; } @@ -45467,8 +46098,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_J52RqweMe6hhv7RnLJMC8BExTE5_first.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -45513,9 +46144,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45525,21 +46157,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#last_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -45568,7 +46199,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45654,8 +46285,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.length < 1) return null; let v = this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.has(0)) { v = v.id; } @@ -45694,8 +46326,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -45740,9 +46372,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45752,21 +46385,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#item_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -45795,7 +46427,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -45890,8 +46522,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { v = v.id; } @@ -45931,9 +46564,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -45978,9 +46611,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -45990,21 +46624,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likesOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -46033,7 +46666,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46118,8 +46751,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.length < 1) return null; let v = this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.has(0)) { v = v.id; } @@ -46158,8 +46792,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -46204,9 +46838,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46216,21 +46851,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#sharesOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -46259,7 +46893,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46344,8 +46978,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.length < 1) return null; let v = this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.has(0)) { v = v.id; } @@ -46384,8 +47019,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -46430,9 +47065,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46442,21 +47078,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#repliesOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -46485,7 +47120,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46570,8 +47205,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.length < 1) return null; let v = this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.has(0)) { v = v.id; } @@ -46610,8 +47246,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -46656,9 +47292,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46668,21 +47305,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inboxOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -46711,7 +47347,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -46796,8 +47432,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.length < 1) return null; let v = this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.has(0)) { v = v.id; } @@ -46836,8 +47473,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -46882,9 +47519,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -46894,21 +47532,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outboxOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -46937,7 +47574,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47022,8 +47659,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.length < 1) return null; let v = this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.has(0)) { v = v.id; } @@ -47062,8 +47700,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -47108,9 +47746,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -47120,21 +47759,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followersOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -47163,7 +47801,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47248,8 +47886,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.length < 1) return null; let v = this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.has(0)) { v = v.id; } @@ -47288,8 +47927,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -47334,9 +47973,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -47346,21 +47986,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followingOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -47389,7 +48028,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47474,8 +48113,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.length < 1) return null; let v = this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.has(0)) { v = v.id; } @@ -47514,8 +48154,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -47560,9 +48200,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -47572,21 +48213,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#likedOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -47615,7 +48255,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -47700,8 +48340,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.length < 1) return null; let v = this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.has(0)) { v = v.id; } @@ -47740,8 +48381,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -47824,7 +48465,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47844,7 +48485,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47864,7 +48505,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47884,7 +48525,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47908,7 +48549,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47928,7 +48569,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47948,7 +48589,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47968,7 +48609,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -47988,7 +48629,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48008,7 +48649,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48028,7 +48669,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48048,7 +48689,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -48066,7 +48707,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "Collection"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"toot":"http://joinmastodon.org/ns#","misskey":"https://misskey-hub.net/ns#","fedibird":"http://fedibird.com/ns#","ChatMessage":"http://litepub.social/ns#ChatMessage","sensitive":"as:sensitive","votersCount":"toot:votersCount","Emoji":"toot:Emoji","Hashtag":"as:Hashtag","quote":{"@id":"https://w3id.org/fep/044f#quote","@type":"@id"},"quoteUrl":"as:quoteUrl","_misskey_quote":"misskey:_misskey_quote","quoteUri":"fedibird:quoteUri","QuoteAuthorization":"https://w3id.org/fep/044f#QuoteAuthorization","QuoteRequest":"https://w3id.org/fep/044f#QuoteRequest","quoteAuthorization":{"@id":"https://w3id.org/fep/044f#quoteAuthorization","@type":"@id"},"emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"}}]; return result; } @@ -48105,7 +48746,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3UyUdxnyn6cDn53QKrh4MBiearma_current) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48120,7 +48761,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_J52RqweMe6hhv7RnLJMC8BExTE5_first) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48135,7 +48776,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_gyJJnyEFnuNVi1HFZKfAn3Hfn26_last) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48150,7 +48791,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -48165,7 +48806,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48180,7 +48821,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48195,7 +48836,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48210,7 +48851,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48225,7 +48866,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48240,7 +48881,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48255,7 +48896,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48270,7 +48911,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -48283,7 +48924,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://www.w3.org/ns/activitystreams#Collection"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -48390,10 +49031,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -48401,11 +49044,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -48431,6 +49072,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -48476,11 +49128,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3UyUdxnyn6cDn53QKrh4MBiearma_current.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3UyUdxnyn6cDn53QKrh4MBiearma_current.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48510,11 +49158,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _J52RqweMe6hhv7RnLJMC8BExTE5_first.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _J52RqweMe6hhv7RnLJMC8BExTE5_first.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48544,11 +49188,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _gyJJnyEFnuNVi1HFZKfAn3Hfn26_last.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48578,11 +49218,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48622,11 +49258,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4TB9Qd9ddtcZEpMfzbHhzafE6jaJ_likesOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48656,11 +49288,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3manzgeKiPsugpztKGiaUUwJ3ito_sharesOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48690,11 +49318,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3T3oGm3twpcQUcrnMisXQtmDZ32X_repliesOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48724,11 +49348,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2bvRkAFZjMfVD8jiUWZJr5YokSeN_inboxOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48758,11 +49378,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4AHzVZDxHjK6uEWa9UiKHGK34yYm_outboxOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48792,11 +49408,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _41aoZ5M6yRUHy3Zx8q6iuZQxtopb_followersOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48826,11 +49438,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2nXT2Ah42UjEEQF5oJQ39CbKB1xj_followingOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48860,11 +49468,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2bsySzmT3qEZcrnoe3tZ5xBjXSju_likedOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -48879,7 +49483,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -49384,9 +50000,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -49396,21 +50013,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#partOf_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -49439,7 +50055,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -49525,8 +50141,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.length < 1) return null; let v = this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.has(0)) { v = v.id; } @@ -49565,8 +50182,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -49611,9 +50228,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -49623,21 +50241,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#next_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -49666,7 +50283,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -49750,8 +50367,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.length < 1) return null; let v = this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.has(0)) { v = v.id; } @@ -49790,8 +50408,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -49836,9 +50454,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -49848,21 +50467,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#prev_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -49891,7 +50509,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -49976,8 +50594,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.length < 1) return null; let v = this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.has(0)) { v = v.id; } @@ -50016,8 +50635,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -50084,7 +50703,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -50104,7 +50723,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -50124,7 +50743,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -50142,7 +50761,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "CollectionPage"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"toot":"http://joinmastodon.org/ns#","misskey":"https://misskey-hub.net/ns#","fedibird":"http://fedibird.com/ns#","ChatMessage":"http://litepub.social/ns#ChatMessage","sensitive":"as:sensitive","votersCount":"toot:votersCount","Emoji":"toot:Emoji","Hashtag":"as:Hashtag","quote":{"@id":"https://w3id.org/fep/044f#quote","@type":"@id"},"quoteUrl":"as:quoteUrl","_misskey_quote":"misskey:_misskey_quote","quoteUri":"fedibird:quoteUri","QuoteAuthorization":"https://w3id.org/fep/044f#QuoteAuthorization","QuoteRequest":"https://w3id.org/fep/044f#QuoteRequest","quoteAuthorization":{"@id":"https://w3id.org/fep/044f#quoteAuthorization","@type":"@id"},"emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"}}]; return result; } @@ -50163,7 +50782,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -50178,7 +50797,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -50193,7 +50812,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3b8yG8tDNzQFFEnWhCc13G8eHooA_prev) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -50206,7 +50825,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://www.w3.org/ns/activitystreams#CollectionPage"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -50313,10 +50932,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -50324,11 +50945,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -50346,6 +50965,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -50373,11 +51003,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2kWgBhQKjEauxx8C6qF3ZQamK4Le_partOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -50407,11 +51033,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3BT4kQLcXhHx7TAWaNDKh8nFn9eY_next.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -50441,11 +51063,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3b8yG8tDNzQFFEnWhCc13G8eHooA_prev.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -50460,7 +51078,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -50707,7 +51337,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Create"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -50814,10 +51444,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -50825,11 +51457,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -50843,6 +51473,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -50855,7 +51496,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -51044,7 +51697,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Delete"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -51151,10 +51804,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -51162,11 +51817,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -51180,6 +51833,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -51192,7 +51856,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -51379,7 +52055,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Dislike"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -51486,10 +52162,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -51497,11 +52175,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -51515,6 +52191,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -51527,7 +52214,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -52001,7 +52700,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52017,7 +52716,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_25S6UmgzDead8hxL5sQFezZTAusd_oauthAuthorizationEndpoint) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52033,7 +52732,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_iAMxqrSba7yBCRB1FZ5kEVdKEZ3_oauthTokenEndpoint) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52049,7 +52748,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_8Bx9qN8oU7Bpt2xi6khaxWp1gMr_provideClientKey) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52065,7 +52764,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_3dU7PMVQZJpsCpo2F4RQXxBXdPmS_signClientKey) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52081,7 +52780,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint compactItems = []; for (const v of this.#_3JprUSDLVqqX4dwHRi37qGZZCRCc_sharedInbox) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -52095,7 +52794,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint } - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = "https://www.w3.org/ns/activitystreams"; return result; } @@ -52106,7 +52805,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -52121,7 +52820,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_25S6UmgzDead8hxL5sQFezZTAusd_oauthAuthorizationEndpoint) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -52136,7 +52835,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_iAMxqrSba7yBCRB1FZ5kEVdKEZ3_oauthTokenEndpoint) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -52151,7 +52850,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_8Bx9qN8oU7Bpt2xi6khaxWp1gMr_provideClientKey) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -52166,7 +52865,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_3dU7PMVQZJpsCpo2F4RQXxBXdPmS_signClientKey) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -52181,7 +52880,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint array = []; for (const v of this.#_3JprUSDLVqqX4dwHRi37qGZZCRCc_sharedInbox) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -52194,7 +52893,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint } - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -52290,10 +52989,12 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -52301,11 +53002,9 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -52319,8 +53018,21 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl: (URL)[] = []; @@ -52336,22 +53048,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _2JCYDbSxEHCCLdBYed33cCETfGyR_proxyUrl.push(decoded); } @@ -52369,22 +53066,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _25S6UmgzDead8hxL5sQFezZTAusd_oauthAuthorizationEndpoint.push(decoded); } @@ -52402,22 +53084,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _iAMxqrSba7yBCRB1FZ5kEVdKEZ3_oauthTokenEndpoint.push(decoded); } @@ -52435,22 +53102,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _8Bx9qN8oU7Bpt2xi6khaxWp1gMr_provideClientKey.push(decoded); } @@ -52468,22 +53120,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _3dU7PMVQZJpsCpo2F4RQXxBXdPmS_signClientKey.push(decoded); } @@ -52501,22 +53138,7 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _3JprUSDLVqqX4dwHRi37qGZZCRCc_sharedInbox.push(decoded); } @@ -52524,7 +53146,19 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -52832,7 +53466,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result["type"] = "Event"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -52851,7 +53485,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Event"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -52958,10 +53592,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -52969,11 +53605,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -52987,6 +53621,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -52999,7 +53644,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -53189,7 +53846,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Flag"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -53296,10 +53953,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -53307,11 +53966,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -53325,6 +53982,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -53337,7 +54005,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -53528,7 +54208,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Follow"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -53635,10 +54315,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -53646,11 +54328,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -53664,6 +54344,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -53676,7 +54367,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -54761,9 +55464,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -54773,21 +55477,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -54816,7 +55519,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -54900,8 +55603,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -54940,8 +55644,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -55003,8 +55707,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -55044,9 +55749,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -55091,9 +55796,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55103,21 +55809,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -55146,7 +55851,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -55234,8 +55939,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -55274,8 +55980,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -55341,8 +56047,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -55382,9 +56089,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -55448,9 +56155,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55460,21 +56168,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -55503,7 +56210,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -55609,8 +56316,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -55649,8 +56357,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -55695,9 +56403,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55707,21 +56416,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -55750,7 +56458,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -55853,8 +56561,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -55893,8 +56602,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -55939,9 +56648,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -55951,21 +56661,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -55994,7 +56703,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56083,8 +56792,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -56123,8 +56833,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -56169,9 +56879,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56181,21 +56892,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -56224,7 +56934,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56316,8 +57026,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -56356,8 +57067,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -56402,9 +57113,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56414,21 +57126,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -56457,7 +57168,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56547,8 +57258,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -56587,8 +57299,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -56633,9 +57345,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56645,21 +57358,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -56688,7 +57400,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -56776,8 +57488,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -56816,8 +57529,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -56862,9 +57575,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -56874,21 +57588,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -56917,7 +57630,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57005,8 +57718,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -57045,8 +57759,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -57091,9 +57805,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -57103,21 +57818,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -57146,7 +57860,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57231,8 +57945,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -57272,9 +57987,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -57394,9 +58109,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -57406,21 +58122,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -57449,7 +58164,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57569,8 +58284,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -57609,8 +58325,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -57655,9 +58371,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -57667,21 +58384,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -57710,7 +58426,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -57834,8 +58550,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -57874,8 +58591,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -57941,8 +58658,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -57982,9 +58700,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -58029,9 +58747,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -58041,21 +58760,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -58084,7 +58802,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -58172,8 +58890,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -58212,8 +58931,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -58279,8 +58998,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -58320,9 +59040,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -58439,7 +59159,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58459,7 +59179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58495,7 +59215,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58519,7 +59239,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58543,7 +59263,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58563,7 +59283,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58583,7 +59303,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58603,7 +59323,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58623,7 +59343,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58643,7 +59363,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58747,7 +59467,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58783,7 +59503,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58819,7 +59539,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -58869,7 +59589,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result["type"] = "Group"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1","https://w3id.org/security/data-integrity/v1","https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1","https://gotosocial.org/ns",{"alsoKnownAs":{"@id":"as:alsoKnownAs","@type":"@id"},"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","movedTo":{"@id":"as:movedTo","@type":"@id"},"toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","featured":{"@id":"toot:featured","@type":"@id"},"featuredTags":{"@id":"toot:featuredTags","@type":"@id"},"discoverable":"toot:discoverable","suspended":"toot:suspended","memorial":"toot:memorial","indexable":"toot:indexable","schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","misskey":"https://misskey-hub.net/ns#","_misskey_followedMessage":"misskey:_misskey_followedMessage","isCat":"misskey:isCat"}]; return result; } @@ -58908,7 +59628,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -58923,7 +59643,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -58953,7 +59673,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -58968,7 +59688,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -58983,7 +59703,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -58998,7 +59718,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59013,7 +59733,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59028,7 +59748,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59043,7 +59763,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59058,7 +59778,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59148,7 +59868,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -59163,7 +59883,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -59178,7 +59898,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -59221,7 +59941,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values["@type"] = ["https://www.w3.org/ns/activitystreams#Group"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -59338,10 +60058,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -59349,11 +60071,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -59367,6 +60087,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -59418,11 +60149,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59452,11 +60179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59504,11 +60227,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59546,11 +60265,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59588,11 +60303,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59622,11 +60333,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59656,11 +60363,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59690,11 +60393,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59724,11 +60423,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59758,11 +60453,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59885,11 +60576,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59939,11 +60626,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -59993,11 +60676,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -60048,7 +60727,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -61173,9 +61864,10 @@ get names(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -61185,21 +61877,20 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#preview_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -61228,7 +61919,7 @@ get names(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -61321,8 +62012,9 @@ get names(): ((string | LanguageString))[] { const vs = this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { v = v.id; } @@ -61362,9 +62054,9 @@ get names(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_gCVTegXxWWCw6wWRxa1QF65zusg_preview.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -61425,7 +62117,7 @@ get names(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_pVjLsybKQdmkjuU7MHjiVmNnuj7_href) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -61540,7 +62232,7 @@ get names(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const item = ( - v instanceof URL ? v.href : v instanceof Link ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Link ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -61562,7 +62254,7 @@ get names(): ((string | LanguageString))[] { } result["type"] = "Link"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = "https://www.w3.org/ns/activitystreams"; return result; } @@ -61573,7 +62265,7 @@ get names(): ((string | LanguageString))[] { array = []; for (const v of this.#_pVjLsybKQdmkjuU7MHjiVmNnuj7_href) { const element = ( - { "@id": v.href } + { "@id": formatIri(v) } ); array.push(element);; } @@ -61687,7 +62379,7 @@ get names(): ((string | LanguageString))[] { array = []; for (const v of this.#_gCVTegXxWWCw6wWRxa1QF65zusg_preview) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Link ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -61700,7 +62392,7 @@ get names(): ((string | LanguageString))[] { } values["@type"] = ["https://www.w3.org/ns/activitystreams#Link"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -61801,10 +62493,12 @@ get names(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -61812,11 +62506,9 @@ get names(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -61838,8 +62530,21 @@ get names(): ((string | LanguageString))[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _pVjLsybKQdmkjuU7MHjiVmNnuj7_href: (URL)[] = []; @@ -61855,22 +62560,7 @@ get names(): ((string | LanguageString))[] { ) { if (v == null) continue; - const decoded = v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl); + const decoded = parseIri(v["@id"], options.baseUrl); if (typeof decoded === "undefined") continue; _pVjLsybKQdmkjuU7MHjiVmNnuj7_href.push(decoded); } @@ -62007,11 +62697,7 @@ get names(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _gCVTegXxWWCw6wWRxa1QF65zusg_preview.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -62036,7 +62722,19 @@ get names(): ((string | LanguageString))[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -62373,7 +63071,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num let compactItems: unknown[]; result["type"] = "Hashtag"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams",{"Hashtag":"as:Hashtag"}]; return result; } @@ -62392,7 +63090,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Hashtag"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -62488,10 +63186,12 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -62499,11 +63199,9 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -62517,6 +63215,17 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -62529,7 +63238,19 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -62702,7 +63423,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result["type"] = "Image"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -62721,7 +63442,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Image"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -62828,10 +63549,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -62839,11 +63562,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -62857,6 +63578,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -62869,7 +63601,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -63059,7 +63803,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Offer"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -63166,10 +63910,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -63177,11 +63923,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -63199,6 +63943,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -63211,7 +63966,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -63400,7 +64167,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Invite"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -63507,10 +64274,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -63518,11 +64287,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -63536,6 +64303,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -63548,7 +64326,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -63737,7 +64527,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Join"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -63844,10 +64634,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -63855,11 +64647,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -63873,6 +64663,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -63885,7 +64686,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -64074,7 +64887,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Leave"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -64181,10 +64994,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -64192,11 +65007,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -64210,6 +65023,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -64222,7 +65046,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -64411,7 +65247,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Like"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -64518,10 +65354,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -64529,11 +65367,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -64547,6 +65383,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -64559,7 +65406,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -64746,7 +65605,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Listen"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -64853,10 +65712,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -64864,11 +65725,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -64882,6 +65741,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -64894,7 +65764,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -65039,7 +65921,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num let compactItems: unknown[]; result["type"] = "Mention"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = "https://www.w3.org/ns/activitystreams"; return result; } @@ -65058,7 +65940,7 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Mention"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -65154,10 +66036,12 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -65165,11 +66049,9 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -65183,6 +66065,17 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -65195,7 +66088,19 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -65385,7 +66290,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Move"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -65492,10 +66397,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -65503,11 +66410,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -65521,6 +66426,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -65533,7 +66449,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -65773,9 +66701,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -65785,21 +66714,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -65828,7 +66756,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -65915,8 +66843,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -65955,8 +66884,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -66024,9 +66953,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -66036,21 +66966,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -66079,7 +67008,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -66165,8 +67094,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -66205,8 +67135,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -66273,7 +67203,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -66293,7 +67223,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const item = ( - v.href + formatIri(v) ); compactItems.push(item); } @@ -66319,7 +67249,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -66337,7 +67267,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "Note"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"toot":"http://joinmastodon.org/ns#","misskey":"https://misskey-hub.net/ns#","fedibird":"http://fedibird.com/ns#","sensitive":"as:sensitive","Emoji":"toot:Emoji","Hashtag":"as:Hashtag","quote":{"@id":"https://w3id.org/fep/044f#quote","@type":"@id"},"quoteUrl":"as:quoteUrl","_misskey_quote":"misskey:_misskey_quote","quoteUri":"fedibird:quoteUri","QuoteAuthorization":"https://w3id.org/fep/044f#QuoteAuthorization","quoteAuthorization":{"@id":"https://w3id.org/fep/044f#quoteAuthorization","@type":"@id"},"emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"}}]; return result; } @@ -66358,7 +67288,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -66373,7 +67303,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { "@value": v.href } + { "@value": formatIri(v) } ); array.push(element);; } @@ -66392,7 +67322,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -66405,7 +67335,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://www.w3.org/ns/activitystreams#Note"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -66512,10 +67442,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -66523,11 +67455,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -66541,6 +67471,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -66568,11 +67509,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -66605,7 +67542,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu ) { if (v == null) continue; - const decoded = new URL(v["@value"]); + const decoded = parseIri(v["@value"]); if (typeof decoded === "undefined") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -66628,11 +67565,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -66647,7 +67580,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -66904,9 +67849,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -66916,21 +67862,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#item_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -66959,7 +67904,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -67054,8 +67999,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { v = v.id; } @@ -67095,9 +68041,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -67164,7 +68110,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -67183,7 +68129,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "OrderedCollection"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"toot":"http://joinmastodon.org/ns#","misskey":"https://misskey-hub.net/ns#","fedibird":"http://fedibird.com/ns#","ChatMessage":"http://litepub.social/ns#ChatMessage","sensitive":"as:sensitive","votersCount":"toot:votersCount","Emoji":"toot:Emoji","Hashtag":"as:Hashtag","quote":{"@id":"https://w3id.org/fep/044f#quote","@type":"@id"},"quoteUrl":"as:quoteUrl","_misskey_quote":"misskey:_misskey_quote","quoteUri":"fedibird:quoteUri","QuoteAuthorization":"https://w3id.org/fep/044f#QuoteAuthorization","QuoteRequest":"https://w3id.org/fep/044f#QuoteRequest","quoteAuthorization":{"@id":"https://w3id.org/fep/044f#quoteAuthorization","@type":"@id"},"emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"}}]; return result; } @@ -67204,7 +68150,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -67217,7 +68163,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://www.w3.org/ns/activitystreams#OrderedCollection"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -67324,10 +68270,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -67335,11 +68283,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -67353,6 +68299,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -67380,11 +68337,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -67409,7 +68362,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -67656,9 +68621,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -67668,21 +68634,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#item_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -67711,7 +68676,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -67806,8 +68771,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu const vs = this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { v = v.id; } @@ -67847,9 +68813,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -67931,7 +68897,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const item = ( - v instanceof URL ? v.href : v instanceof Object ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Object ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -67966,7 +68932,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "OrderedCollectionPage"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns",{"toot":"http://joinmastodon.org/ns#","misskey":"https://misskey-hub.net/ns#","fedibird":"http://fedibird.com/ns#","ChatMessage":"http://litepub.social/ns#ChatMessage","sensitive":"as:sensitive","votersCount":"toot:votersCount","Emoji":"toot:Emoji","Hashtag":"as:Hashtag","quote":{"@id":"https://w3id.org/fep/044f#quote","@type":"@id"},"quoteUrl":"as:quoteUrl","_misskey_quote":"misskey:_misskey_quote","quoteUri":"fedibird:quoteUri","QuoteAuthorization":"https://w3id.org/fep/044f#QuoteAuthorization","QuoteRequest":"https://w3id.org/fep/044f#QuoteRequest","quoteAuthorization":{"@id":"https://w3id.org/fep/044f#quoteAuthorization","@type":"@id"},"emojiReactions":{"@id":"fedibird:emojiReactions","@type":"@id"}}]; return result; } @@ -67987,7 +68953,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Object ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -68018,7 +68984,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://www.w3.org/ns/activitystreams#OrderedCollectionPage"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -68125,10 +69091,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -68136,11 +69104,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -68154,6 +69120,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -68181,11 +69158,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2JPCKWTcfBmTCcW8Tv3TpRaLVaqg_items.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -68228,7 +69201,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -69355,9 +70340,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -69367,21 +70353,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -69410,7 +70395,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -69494,8 +70479,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -69534,8 +70520,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -69597,8 +70583,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -69638,9 +70625,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -69685,9 +70672,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -69697,21 +70685,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -69740,7 +70727,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -69828,8 +70815,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -69868,8 +70856,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -69935,8 +70923,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -69976,9 +70965,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -70042,9 +71031,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70054,21 +71044,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -70097,7 +71086,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70203,8 +71192,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -70243,8 +71233,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -70289,9 +71279,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70301,21 +71292,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -70344,7 +71334,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70447,8 +71437,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -70487,8 +71478,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -70533,9 +71524,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70545,21 +71537,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -70588,7 +71579,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70677,8 +71668,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -70717,8 +71709,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -70763,9 +71755,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -70775,21 +71768,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -70818,7 +71810,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -70910,8 +71902,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -70950,8 +71943,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -70996,9 +71989,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71008,21 +72002,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -71051,7 +72044,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71141,8 +72134,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -71181,8 +72175,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -71227,9 +72221,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71239,21 +72234,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -71282,7 +72276,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71370,8 +72364,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -71410,8 +72405,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -71456,9 +72451,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71468,21 +72464,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -71511,7 +72506,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71599,8 +72594,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -71639,8 +72635,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -71685,9 +72681,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -71697,21 +72694,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -71740,7 +72736,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -71825,8 +72821,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -71866,9 +72863,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -71988,9 +72985,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -72000,21 +72998,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -72043,7 +73040,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -72163,8 +73160,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -72203,8 +73201,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -72249,9 +73247,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -72261,21 +73260,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -72304,7 +73302,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -72428,8 +73426,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -72468,8 +73467,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -72535,8 +73534,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -72576,9 +73576,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -72623,9 +73623,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -72635,21 +73636,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -72678,7 +73678,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -72766,8 +73766,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -72806,8 +73807,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -72873,8 +73874,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -72914,9 +73916,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -73033,7 +74035,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73053,7 +74055,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73089,7 +74091,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73113,7 +74115,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73137,7 +74139,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73157,7 +74159,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73177,7 +74179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73197,7 +74199,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73217,7 +74219,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73237,7 +74239,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73341,7 +74343,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73377,7 +74379,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73413,7 +74415,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -73463,7 +74465,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result["type"] = "Organization"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1","https://w3id.org/security/data-integrity/v1","https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1","https://gotosocial.org/ns",{"alsoKnownAs":{"@id":"as:alsoKnownAs","@type":"@id"},"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","movedTo":{"@id":"as:movedTo","@type":"@id"},"toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","featured":{"@id":"toot:featured","@type":"@id"},"featuredTags":{"@id":"toot:featuredTags","@type":"@id"},"discoverable":"toot:discoverable","suspended":"toot:suspended","memorial":"toot:memorial","indexable":"toot:indexable","schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","misskey":"https://misskey-hub.net/ns#","_misskey_followedMessage":"misskey:_misskey_followedMessage","isCat":"misskey:isCat"}]; return result; } @@ -73502,7 +74504,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73517,7 +74519,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73547,7 +74549,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73562,7 +74564,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73577,7 +74579,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73592,7 +74594,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73607,7 +74609,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73622,7 +74624,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73637,7 +74639,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73652,7 +74654,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73742,7 +74744,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73757,7 +74759,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -73772,7 +74774,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -73815,7 +74817,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values["@type"] = ["https://www.w3.org/ns/activitystreams#Organization"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -73932,10 +74934,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -73943,11 +74947,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -73961,6 +74963,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -74012,11 +75025,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74046,11 +75055,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74098,11 +75103,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74140,11 +75141,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74182,11 +75179,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74216,11 +75209,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74250,11 +75239,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74284,11 +75269,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74318,11 +75299,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74352,11 +75329,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74479,11 +75452,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74533,11 +75502,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74587,11 +75552,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -74642,7 +75603,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -75287,7 +76260,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result["type"] = "Page"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -75306,7 +76279,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Page"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -75413,10 +76386,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -75424,11 +76399,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -75442,6 +76415,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -75454,7 +76438,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -76539,9 +77535,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -76551,21 +77548,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -76594,7 +77590,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -76678,8 +77674,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -76718,8 +77715,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -76781,8 +77778,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -76822,9 +77820,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -76869,9 +77867,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -76881,21 +77880,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -76924,7 +77922,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77012,8 +78010,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -77052,8 +78051,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -77119,8 +78118,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -77160,9 +78160,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -77226,9 +78226,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77238,21 +78239,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -77281,7 +78281,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77387,8 +78387,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -77427,8 +78428,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -77473,9 +78474,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77485,21 +78487,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -77528,7 +78529,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77631,8 +78632,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -77671,8 +78673,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -77717,9 +78719,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77729,21 +78732,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -77772,7 +78774,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -77861,8 +78863,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -77901,8 +78904,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -77947,9 +78950,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -77959,21 +78963,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -78002,7 +79005,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78094,8 +79097,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -78134,8 +79138,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -78180,9 +79184,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78192,21 +79197,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -78235,7 +79239,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78325,8 +79329,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -78365,8 +79370,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -78411,9 +79416,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78423,21 +79429,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -78466,7 +79471,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78554,8 +79559,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -78594,8 +79600,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -78640,9 +79646,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78652,21 +79659,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -78695,7 +79701,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -78783,8 +79789,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -78823,8 +79830,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -78869,9 +79876,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -78881,21 +79889,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -78924,7 +79931,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79009,8 +80016,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -79050,9 +80058,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -79172,9 +80180,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -79184,21 +80193,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -79227,7 +80235,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79347,8 +80355,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -79387,8 +80396,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -79433,9 +80442,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -79445,21 +80455,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -79488,7 +80497,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79612,8 +80621,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -79652,8 +80662,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -79719,8 +80729,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -79760,9 +80771,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -79807,9 +80818,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -79819,21 +80831,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -79862,7 +80873,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -79950,8 +80961,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -79990,8 +81002,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -80057,8 +81069,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -80098,9 +81111,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -80217,7 +81230,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80237,7 +81250,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80273,7 +81286,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80297,7 +81310,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80321,7 +81334,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80341,7 +81354,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80361,7 +81374,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80381,7 +81394,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80401,7 +81414,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80421,7 +81434,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80525,7 +81538,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80561,7 +81574,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80597,7 +81610,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -80647,7 +81660,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result["type"] = "Person"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1","https://w3id.org/security/data-integrity/v1","https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1","https://gotosocial.org/ns",{"alsoKnownAs":{"@id":"as:alsoKnownAs","@type":"@id"},"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","movedTo":{"@id":"as:movedTo","@type":"@id"},"toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","featured":{"@id":"toot:featured","@type":"@id"},"featuredTags":{"@id":"toot:featuredTags","@type":"@id"},"discoverable":"toot:discoverable","suspended":"toot:suspended","memorial":"toot:memorial","indexable":"toot:indexable","schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","misskey":"https://misskey-hub.net/ns#","_misskey_followedMessage":"misskey:_misskey_followedMessage","isCat":"misskey:isCat"}]; return result; } @@ -80686,7 +81699,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80701,7 +81714,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80731,7 +81744,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80746,7 +81759,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80761,7 +81774,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80776,7 +81789,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80791,7 +81804,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80806,7 +81819,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80821,7 +81834,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80836,7 +81849,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80926,7 +81939,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80941,7 +81954,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -80956,7 +81969,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -80999,7 +82012,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values["@type"] = ["https://www.w3.org/ns/activitystreams#Person"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -81116,10 +82129,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -81127,11 +82142,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -81145,6 +82158,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -81196,11 +82220,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81230,11 +82250,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81282,11 +82298,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81324,11 +82336,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81366,11 +82374,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81400,11 +82404,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81434,11 +82434,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81468,11 +82464,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81502,11 +82494,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81536,11 +82524,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81663,11 +82647,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81717,11 +82697,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81771,11 +82747,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -81826,7 +82798,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -82808,7 +83792,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_oKrwxU4V8wiKhMW1QEYQibcJh8c_units) { const item = ( - v == "cm" || v == "feet" || v == "inches" || v == "km" || v == "m" || v == "miles" ? v : v.href + v == "cm" || v == "feet" || v == "inches" || v == "km" || v == "m" || v == "miles" ? v : formatIri(v) ); compactItems.push(item); } @@ -82822,7 +83806,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "Place"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -82933,7 +83917,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_oKrwxU4V8wiKhMW1QEYQibcJh8c_units) { const element = ( - v == "cm" || v == "feet" || v == "inches" || v == "km" || v == "m" || v == "miles" ? { "@value": v } : { "@id": v.href } + v == "cm" || v == "feet" || v == "inches" || v == "km" || v == "m" || v == "miles" ? { "@value": v } : { "@id": formatIri(v) } ); array.push(element);; } @@ -82946,7 +83930,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://www.w3.org/ns/activitystreams#Place"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -83053,10 +84037,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -83064,11 +84050,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -83082,6 +84066,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -83198,22 +84193,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu typeof v === "object" && "@value" in v && (v["@value"] == "cm" || v["@value"] == "feet" || v["@value"] == "inches" || v["@value"] == "km" || v["@value"] == "m" || v["@value"] == "miles") ? v["@value"] : v != null && typeof v === "object" && "@id" in v && typeof v["@id"] === "string" - && v["@id"] !== "" ? v["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - v["@id"].includes("/", 5) - ? v["@id"].slice(5, v["@id"].indexOf("/", 5)) - : v["@id"].slice(5) - ) + - ( - v["@id"].includes("/", 5) - ? v["@id"].slice(v["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(v["@id"]) && options.baseUrl - ? new URL(v["@id"]) - : new URL(v["@id"], options.baseUrl) : undefined + && v["@id"] !== "" ? parseIri(v["@id"], options.baseUrl) : undefined ; if (typeof decoded === "undefined") continue; _oKrwxU4V8wiKhMW1QEYQibcJh8c_units.push(decoded); @@ -83223,7 +84203,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -83530,9 +84522,10 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -83542,21 +84535,20 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#describes_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -83585,7 +84577,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -83671,8 +84663,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } if (this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.length < 1) return null; let v = this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.has(0)) { v = v.id; } @@ -83711,8 +84704,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -83779,7 +84772,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu compactItems = []; for (const v of this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -83797,7 +84790,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } result["type"] = "Profile"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -83818,7 +84811,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu array = []; for (const v of this.#_3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -83831,7 +84824,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } values["@type"] = ["https://www.w3.org/ns/activitystreams#Profile"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -83938,10 +84931,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -83949,11 +84944,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -83967,6 +84960,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -83994,11 +84998,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3CLQ1PLSXrhSQbTGGHuxNyaEFKM1_describes.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -84013,7 +85013,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -84429,9 +85441,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -84441,21 +85454,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#exclusiveOption_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -84484,7 +85496,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -84571,8 +85583,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti const vs = this.#_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.has(i)) { v = v.id; } @@ -84612,9 +85625,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -84659,9 +85672,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -84671,21 +85685,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inclusiveOption_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -84714,7 +85727,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -84801,8 +85814,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti const vs = this.#_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.has(i)) { v = v.id; } @@ -84842,9 +85856,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -84919,9 +85933,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -84931,21 +85946,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quote_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -84974,7 +85988,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -85061,8 +86075,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } if (this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.length < 1) return null; let v = this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { v = v.id; } @@ -85101,8 +86116,8 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -85170,9 +86185,10 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -85182,21 +86198,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#quoteAuthorization_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -85225,7 +86240,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -85311,8 +86326,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } if (this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.length < 1) return null; let v = this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { v = v.id; } @@ -85351,8 +86367,8 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -85421,7 +86437,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85436,7 +86452,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85487,7 +86503,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85502,7 +86518,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl) { const element = ( - { "@value": v.href } + { "@value": formatIri(v) } ); array.push(element);; } @@ -85521,7 +86537,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti array = []; for (const v of this.#_ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -85534,7 +86550,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } values["@type"] = ["https://www.w3.org/ns/activitystreams#Question"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -85641,10 +86657,12 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -85652,11 +86670,9 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -85670,6 +86686,17 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -85697,11 +86724,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2N5scKaVEcdYHFmfKYYacAwUhUgQ_oneOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -85731,11 +86754,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2mV6isMTPRKbWdLCjcpiEysq5dAY_anyOf.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -85814,11 +86833,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3obhVLFML2Fh2Qsbg3BM2dec8S9e_quote.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -85851,7 +86866,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti ) { if (v == null) continue; - const decoded = new URL(v["@value"]); + const decoded = parseIri(v["@value"]); if (typeof decoded === "undefined") continue; _K1zrMQkQjmciFAmGdGLfaDbG925_quoteUrl.push(decoded); } @@ -85874,11 +86889,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _ZKAEiJeuEvjeYkC4pG58D5vAJ4m_quoteAuthorization.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -85893,7 +86904,19 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -86225,7 +87248,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Read"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -86332,10 +87355,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -86343,11 +87368,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -86361,6 +87384,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -86373,7 +87407,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -86562,7 +87608,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Reject"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -86669,10 +87715,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -86680,11 +87728,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -86702,6 +87748,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -86714,7 +87771,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -87075,9 +88144,10 @@ relationships?: (Object | URL)[];} "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -87087,21 +88157,20 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#subject_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -87130,7 +88199,7 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -87218,8 +88287,9 @@ relationships?: (Object | URL)[];} } if (this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.length < 1) return null; let v = this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.has(0)) { v = v.id; } @@ -87258,8 +88328,8 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -87304,9 +88374,10 @@ relationships?: (Object | URL)[];} "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -87316,21 +88387,20 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#object_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -87359,7 +88429,7 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -87444,8 +88514,9 @@ relationships?: (Object | URL)[];} } if (this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.length < 1) return null; let v = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { v = v.id; } @@ -87484,8 +88555,8 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -87548,8 +88619,9 @@ relationships?: (Object | URL)[];} const vs = this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { v = v.id; } @@ -87589,9 +88661,9 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -87636,9 +88708,10 @@ relationships?: (Object | URL)[];} "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -87648,21 +88721,20 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#relationship_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -87691,7 +88763,7 @@ relationships?: (Object | URL)[];} if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -87778,8 +88850,9 @@ relationships?: (Object | URL)[];} } if (this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.length < 1) return null; let v = this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(0)) { v = v.id; } @@ -87818,8 +88891,8 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -87884,8 +88957,9 @@ relationships?: (Object | URL)[];} const vs = this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(i)) { v = v.id; } @@ -87925,9 +88999,9 @@ relationships?: (Object | URL)[];} } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -87994,7 +89068,7 @@ relationships?: (Object | URL)[];} compactItems = []; for (const v of this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -88014,7 +89088,7 @@ relationships?: (Object | URL)[];} compactItems = []; for (const v of this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -88034,7 +89108,7 @@ relationships?: (Object | URL)[];} compactItems = []; for (const v of this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -88052,7 +89126,7 @@ relationships?: (Object | URL)[];} } result["type"] = "Relationship"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -88073,7 +89147,7 @@ relationships?: (Object | URL)[];} array = []; for (const v of this.#_2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -88088,7 +89162,7 @@ relationships?: (Object | URL)[];} array = []; for (const v of this.#_2MH19yxjn1wnHsNfa5n4JBhJzxyc_object) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -88103,7 +89177,7 @@ relationships?: (Object | URL)[];} array = []; for (const v of this.#_4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -88116,7 +89190,7 @@ relationships?: (Object | URL)[];} } values["@type"] = ["https://www.w3.org/ns/activitystreams#Relationship"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -88223,10 +89297,12 @@ relationships?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -88234,11 +89310,9 @@ relationships?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -88252,6 +89326,17 @@ relationships?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -88279,11 +89364,7 @@ relationships?: (Object | URL)[];} if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2Zqdmi46ZnDQsECS6mzwhrv3rUKq_subject.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -88313,11 +89394,7 @@ relationships?: (Object | URL)[];} if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2MH19yxjn1wnHsNfa5n4JBhJzxyc_object.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -88347,11 +89424,7 @@ relationships?: (Object | URL)[];} if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4Lzz89F9qipAQSGkWyX9DGWiUojG_relationship.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -88366,7 +89439,19 @@ relationships?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -88627,7 +89712,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Remove"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -88734,10 +89819,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -88745,11 +89832,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -88763,6 +89848,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -88775,7 +89871,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -89860,9 +90968,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -89872,21 +90981,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#publicKey_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -89915,7 +91023,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -89999,8 +91107,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey.length < 1) return null; let v = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { v = v.id; } @@ -90039,8 +91148,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -90102,8 +91211,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { v = v.id; } @@ -90143,9 +91253,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_axq166E2eZADq34V4MYUc8KMZdC_publicKey.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -90190,9 +91300,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -90202,21 +91313,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#assertionMethod_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -90245,7 +91355,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -90333,8 +91443,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.length < 1) return null; let v = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { v = v.id; } @@ -90373,8 +91484,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -90440,8 +91551,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { v = v.id; } @@ -90481,9 +91593,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -90547,9 +91659,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -90559,21 +91672,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#inbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -90602,7 +91714,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -90708,8 +91820,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.length < 1) return null; let v = this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { v = v.id; } @@ -90748,8 +91861,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -90794,9 +91907,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -90806,21 +91920,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#outbox_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -90849,7 +91962,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -90952,8 +92065,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox.length < 1) return null; let v = this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { v = v.id; } @@ -90992,8 +92106,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_41QwhqJouoLg3h8dRPKat21brynC_outbox.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -91038,9 +92152,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91050,21 +92165,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#following_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -91093,7 +92207,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91182,8 +92296,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.length < 1) return null; let v = this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { v = v.id; } @@ -91222,8 +92337,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -91268,9 +92383,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91280,21 +92396,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#followers_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -91323,7 +92438,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91415,8 +92530,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.length < 1) return null; let v = this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { v = v.id; } @@ -91455,8 +92571,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_BBCTgfphhsFzpVfKTykGSpBNwoA_followers.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -91501,9 +92617,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91513,21 +92630,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#liked_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -91556,7 +92672,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91646,8 +92762,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.length < 1) return null; let v = this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { v = v.id; } @@ -91686,8 +92803,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -91732,9 +92849,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91744,21 +92862,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featured_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -91787,7 +92904,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -91875,8 +92992,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured.length < 1) return null; let v = this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { v = v.id; } @@ -91915,8 +93033,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4N1vBJzXDf8NbBumeECQMFvKetja_featured.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -91961,9 +93079,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -91973,21 +93092,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#featuredTags_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -92016,7 +93134,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92104,8 +93222,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.length < 1) return null; let v = this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { v = v.id; } @@ -92144,8 +93263,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -92190,9 +93309,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -92202,21 +93322,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#stream_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -92245,7 +93364,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92330,8 +93449,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { v = v.id; } @@ -92371,9 +93491,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -92493,9 +93613,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -92505,21 +93626,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#successor_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -92548,7 +93668,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92668,8 +93788,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.length < 1) return null; let v = this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { v = v.id; } @@ -92708,8 +93829,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -92754,9 +93875,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -92766,21 +93888,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#alias_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -92809,7 +93930,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -92933,8 +94054,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.length < 1) return null; let v = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { v = v.id; } @@ -92973,8 +94095,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -93040,8 +94162,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { v = v.id; } @@ -93081,9 +94204,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -93128,9 +94251,10 @@ get preferredUsernames(): ((string | LanguageString))[] { "0.0.0", ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -93140,21 +94264,20 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#service_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -93183,7 +94306,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -93271,8 +94394,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } if (this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.length < 1) return null; let v = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { v = v.id; } @@ -93311,8 +94435,8 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -93378,8 +94502,9 @@ get preferredUsernames(): ((string | LanguageString))[] { const vs = this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { v = v.id; } @@ -93419,9 +94544,9 @@ get preferredUsernames(): ((string | LanguageString))[] { } } - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.#_trust_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + @@ -93538,7 +94663,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93558,7 +94683,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93594,7 +94719,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93618,7 +94743,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const item = ( - v instanceof URL ? v.href : v instanceof OrderedCollection ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof OrderedCollection ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93642,7 +94767,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93662,7 +94787,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93682,7 +94807,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93702,7 +94827,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93722,7 +94847,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93742,7 +94867,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93846,7 +94971,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93882,7 +95007,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const item = ( - v instanceof URL ? v.href : v instanceof Application ? await v.toJsonLd({ + v instanceof URL ? formatIri(v) : v instanceof Application ? await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93918,7 +95043,7 @@ get preferredUsernames(): ((string | LanguageString))[] { compactItems = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const item = ( - v instanceof URL ? v.href : await v.toJsonLd({ + v instanceof URL ? formatIri(v) : await v.toJsonLd({ ...(options), format: undefined, context: undefined, @@ -93968,7 +95093,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } result["type"] = "Service"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1","https://w3id.org/security/data-integrity/v1","https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1","https://gotosocial.org/ns",{"alsoKnownAs":{"@id":"as:alsoKnownAs","@type":"@id"},"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","movedTo":{"@id":"as:movedTo","@type":"@id"},"toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","featured":{"@id":"toot:featured","@type":"@id"},"featuredTags":{"@id":"toot:featuredTags","@type":"@id"},"discoverable":"toot:discoverable","suspended":"toot:suspended","memorial":"toot:memorial","indexable":"toot:indexable","schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","misskey":"https://misskey-hub.net/ns#","_misskey_followedMessage":"misskey:_misskey_followedMessage","isCat":"misskey:isCat"}]; return result; } @@ -94007,7 +95132,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_axq166E2eZADq34V4MYUc8KMZdC_publicKey) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94022,7 +95147,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94052,7 +95177,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94067,7 +95192,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_41QwhqJouoLg3h8dRPKat21brynC_outbox) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof OrderedCollection ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94082,7 +95207,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3yAv8jymNfNuJUDuBzJ1NQhdbAee_following) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94097,7 +95222,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_BBCTgfphhsFzpVfKTykGSpBNwoA_followers) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94112,7 +95237,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3bgkPwJanyTCoVFM9ovRcus8tKkU_liked) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94127,7 +95252,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4N1vBJzXDf8NbBumeECQMFvKetja_featured) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94142,7 +95267,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94157,7 +95282,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94247,7 +95372,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94262,7 +95387,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs) { const element = ( - v instanceof URL ? { "@id": v.href } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : v instanceof Application ? await v.toJsonLd(options) : v instanceof Group ? await v.toJsonLd(options) : v instanceof Organization ? await v.toJsonLd(options) : v instanceof Person ? await v.toJsonLd(options) : await v.toJsonLd(options) ); array.push(element);; } @@ -94277,7 +95402,7 @@ get preferredUsernames(): ((string | LanguageString))[] { array = []; for (const v of this.#_4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service) { const element = ( - v instanceof URL ? { "@id": v.href } : await v.toJsonLd(options) + v instanceof URL ? { "@id": formatIri(v) } : await v.toJsonLd(options) ); array.push(element);; } @@ -94320,7 +95445,7 @@ get preferredUsernames(): ((string | LanguageString))[] { } values["@type"] = ["https://www.w3.org/ns/activitystreams#Service"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -94437,10 +95562,12 @@ get preferredUsernames(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -94448,11 +95575,9 @@ get preferredUsernames(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -94466,6 +95591,17 @@ get preferredUsernames(): ((string | LanguageString))[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -94517,11 +95653,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _axq166E2eZADq34V4MYUc8KMZdC_publicKey.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94551,11 +95683,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4EHQFWZSz1k1d4LmPrQiMba2GbP3_assertionMethod.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94603,11 +95731,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3ghX3VfZXXbLvhCRH7QJqpzLrXjB_inbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94645,11 +95769,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _41QwhqJouoLg3h8dRPKat21brynC_outbox.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _41QwhqJouoLg3h8dRPKat21brynC_outbox.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94687,11 +95807,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3yAv8jymNfNuJUDuBzJ1NQhdbAee_following.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94721,11 +95837,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _BBCTgfphhsFzpVfKTykGSpBNwoA_followers.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94755,11 +95867,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3bgkPwJanyTCoVFM9ovRcus8tKkU_liked.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94789,11 +95897,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4N1vBJzXDf8NbBumeECQMFvKetja_featured.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94823,11 +95927,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2MxnRRLq9iPzx5CFq2NPrXdUDCac_featuredTags.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94857,11 +95957,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3sG2Hdwn9qzKGu9mpYkqakAMUkH9_streams.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -94984,11 +96080,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _2ZNWDhuNdSXBwEmrB5kwffdKGzok_movedTo.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -95038,11 +96130,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _3NV7TGNhuABbryNjNi4wib4DgNpY_alsoKnownAs.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -95092,11 +96180,7 @@ get preferredUsernames(): ((string | LanguageString))[] { if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push( - !URL.canParse(v["@id"], options.baseUrl) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], options.baseUrl) - ); + _4Q6NrKH6bazBGtxwG8vyG77ir7Tg_service.push(parseIri(v["@id"], options.baseUrl)); continue; } @@ -95147,7 +96231,19 @@ get preferredUsernames(): ((string | LanguageString))[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -95991,7 +97087,7 @@ get contents(): ((string | LanguageString))[] { } - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = "https://www.w3.org/ns/activitystreams"; return result; } @@ -96033,7 +97129,7 @@ get contents(): ((string | LanguageString))[] { } - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -96134,10 +97230,12 @@ get contents(): ((string | LanguageString))[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -96145,11 +97243,9 @@ get contents(): ((string | LanguageString))[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -96163,8 +97259,21 @@ get contents(): ((string | LanguageString))[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); const _4HuuRSdSrXq8Jj2J9gcdYfoCzeuz_content: ((string | LanguageString))[] = []; @@ -96212,7 +97321,19 @@ get contents(): ((string | LanguageString))[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -96462,7 +97583,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#TentativeAccept"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -96569,10 +97690,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -96580,11 +97703,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -96598,6 +97719,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -96610,7 +97742,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -96799,7 +97943,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#TentativeReject"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -96906,10 +98050,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -96917,11 +98063,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -96935,6 +98079,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -96947,7 +98102,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -97295,7 +98462,7 @@ get formerTypes(): ($EntityType)[] { } result["type"] = "Tombstone"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -97347,7 +98514,7 @@ get formerTypes(): ($EntityType)[] { } values["@type"] = ["https://www.w3.org/ns/activitystreams#Tombstone"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -97459,10 +98626,12 @@ get formerTypes(): ($EntityType)[] { }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -97470,11 +98639,9 @@ get formerTypes(): ($EntityType)[] { // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -97488,6 +98655,17 @@ get formerTypes(): ($EntityType)[] { } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -97553,7 +98731,19 @@ get formerTypes(): ($EntityType)[] { if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -97790,7 +98980,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Travel"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -97897,10 +99087,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -97908,11 +99100,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -97926,6 +99116,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -97938,7 +99139,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -98132,7 +99345,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Undo"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -98239,10 +99452,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -98250,11 +99465,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -98268,6 +99481,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -98280,7 +99504,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -98472,7 +99708,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Update"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -98579,10 +99815,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -98590,11 +99828,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -98608,6 +99844,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -98620,7 +99867,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -98793,7 +100052,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu let compactItems: unknown[]; result["type"] = "Video"; - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ["https://www.w3.org/ns/activitystreams","https://w3id.org/security/data-integrity/v1","https://gotosocial.org/ns"]; return result; } @@ -98812,7 +100071,7 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu >; values["@type"] = ["https://www.w3.org/ns/activitystreams#Video"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -98919,10 +100178,12 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -98930,11 +100191,9 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -98948,6 +100207,17 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -98960,7 +100230,19 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", @@ -99148,7 +100430,7 @@ instruments?: (Object | URL)[];} >; values["@type"] = ["https://www.w3.org/ns/activitystreams#View"]; - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -99255,10 +100537,12 @@ instruments?: (Object | URL)[];} }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -99266,11 +100550,9 @@ instruments?: (Object | URL)[];} // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } if ("@type" in values) { @@ -99284,6 +100566,17 @@ instruments?: (Object | URL)[];} } } + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + delete values["@type"]; const instance = await super.fromJsonLd(values, { ...options, @@ -99296,7 +100589,19 @@ instruments?: (Object | URL)[];} if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", diff --git a/packages/vocab-tools/src/class.ts b/packages/vocab-tools/src/class.ts index d1943554e..e8ae007dc 100644 --- a/packages/vocab-tools/src/class.ts +++ b/packages/vocab-tools/src/class.ts @@ -3,9 +3,41 @@ import { generateCloner, generateConstructor } from "./constructor.ts"; import { generateFields } from "./field.ts"; import { generateInspector, generateInspectorPostClass } from "./inspector.ts"; import { generateProperties } from "./property.ts"; -import { type TypeSchema, validateTypeSchemas } from "./schema.ts"; +import { + type PropertySchema, + type TypeSchema, + validateTypeSchemas, +} from "./schema.ts"; import { emitOverride } from "./type.ts"; +const XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; +const FEDIFY_URL = "fedify:url"; +const INTERNAL_RUNTIME_IMPORTS = [ + "compactJsonLdCache", + "getJsonLdContext", + "isTrustedIriOrigin", + "normalizeJsonLdIris", +].join(",\n "); +const RUNTIME_IMPORTS = [ + "canParseDecimal", + "decodeMultibase", + "type Decimal", + "type DocumentLoader", + "encodeMultibase", + "exportMultibaseKey", + "exportSpki", + "formatIri", + "getDocumentLoader", + "importMultibaseKey", + "importPem", + "isDecimal", + "LanguageString", + "parseDecimal", + "parseIri", + "parseJsonLdId", + "type RemoteDocument", +].join(",\n "); + /** * Sorts the given types topologically so that the base types come before the * extended types. @@ -169,6 +201,40 @@ export function getEntityTypeById(id: string | URL): $EntityType | undefined { `; } +function canContainIriValue( + property: PropertySchema, + types: Record, +): boolean { + return property.range.some((typeUri) => + typeUri === XSD_ANY_URI || typeUri === FEDIFY_URL || types[typeUri]?.entity + ); +} + +function addKeys( + keys: Set, + property: { uri: string; compactName?: string }, +): void { + keys.add(property.uri); + if (property.compactName != null) keys.add(property.compactName); +} + +function addPortableIriKeys( + keys: Set, + property: PropertySchema, + types: Record, +): void { + if (!canContainIriValue(property, types)) return; + addKeys(keys, property); + if ( + "redundantProperties" in property && + property.redundantProperties != null + ) { + for (const redundantProperty of property.redundantProperties) { + addKeys(keys, redundantProperty); + } + } +} + /** * Generates the TypeScript classes from the given types. * @param types The types to generate classes from. @@ -178,35 +244,27 @@ export async function* generateClasses( types: Record, ): AsyncIterable { validateTypeSchemas(types); - const runtimeImports = [ - "canParseDecimal", - "decodeMultibase", - "type Decimal", - "type DocumentLoader", - "encodeMultibase", - "exportMultibaseKey", - "exportSpki", - "getDocumentLoader", - "importMultibaseKey", - "importPem", - "isDecimal", - "LanguageString", - "parseDecimal", - "type RemoteDocument", - ]; yield "// deno-lint-ignore-file ban-unused-ignore no-explicit-any no-unused-vars prefer-const verbatim-module-syntax\n"; yield 'import jsonld from "@fedify/vocab-runtime/jsonld";\n'; yield 'import { getLogger } from "@logtape/logtape";\n'; yield `import { type Span, SpanStatusCode, type TracerProvider, trace } from "@opentelemetry/api";\n`; - yield `import {\n ${ - runtimeImports.join(",\n ") - }\n} from "@fedify/vocab-runtime";\n`; + yield `import {\n ${RUNTIME_IMPORTS}\n} from "@fedify/vocab-runtime";\n`; + yield `import {\n ${INTERNAL_RUNTIME_IMPORTS}\n} from "@fedify/vocab-runtime/internal/jsonld-cache";\n`; yield `import { isTemporalDuration, isTemporalInstant, } from "@fedify/vocab-runtime/temporal";\n`; - yield "\n\n"; + const portableIriKeys = new Set(["@id", "id"]); + for (const type of Object.values(types)) { + for (const property of type.properties) { + addPortableIriKeys(portableIriKeys, property, types); + } + } + yield "const PORTABLE_IRI_PATTERN = /^ap(?:\\+ef61)?:\\/\\//i;\n"; + yield `const PORTABLE_IRI_KEYS: ReadonlySet = new Set(${ + JSON.stringify([...portableIriKeys].sort()) + });\n\n`; const moduleVarNames = new Map(); const sorted = sortTopologically(types); for (const typeUri of sorted) { diff --git a/packages/vocab-tools/src/codec.ts b/packages/vocab-tools/src/codec.ts index 260f5961c..f7038c965 100644 --- a/packages/vocab-tools/src/codec.ts +++ b/packages/vocab-tools/src/codec.ts @@ -127,7 +127,7 @@ export async function* generateEncoder( const item = ( `; if (!areAllScalarTypes(property.range, types)) { - yield "v instanceof URL ? v.href : "; + yield "v instanceof URL ? formatIri(v) : "; } const encoders = getEncoders( property.range, @@ -178,7 +178,7 @@ export async function* generateEncoder( ? "" : `result["type"] = ${JSON.stringify(type.compactName ?? type.uri)};` } - if (this.id != null) result["id"] = this.id.href; + if (this.id != null) result["id"] = formatIri(this.id); result["@context"] = ${JSON.stringify(type.defaultContext)}; return result; } @@ -210,7 +210,7 @@ export async function* generateEncoder( const element = ( `; if (!areAllScalarTypes(property.range, types)) { - yield 'v instanceof URL ? { "@id": v.href } : '; + yield 'v instanceof URL ? { "@id": formatIri(v) } : '; } for (const code of getEncoders(property.range, types, "v", "options")) { yield code; @@ -250,7 +250,7 @@ export async function* generateEncoder( } yield ` ${type.typeless ? "" : `values["@type"] = [${JSON.stringify(type.uri)}];`} - if (this.id != null) values["@id"] = this.id.href; + if (this.id != null) values["@id"] = formatIri(this.id); if (options.format === "expand") { return await jsonld.expand( values, @@ -393,10 +393,12 @@ export async function* generateDecoder( }; // deno-lint-ignore no-explicit-any let values: Record & { "@id"?: string }; + let expanded: unknown[]; if (globalThis.Object.keys(json).length == 0) { values = {}; + expanded = [values]; } else { - const expanded = await jsonld.expand(json, { + expanded = await jsonld.expand(json, { documentLoader: options.contextLoader, keepFreeFloatingNodes: true, }); @@ -404,11 +406,9 @@ export async function* generateDecoder( // deno-lint-ignore no-explicit-any (expanded[0] ?? {}) as (Record & { "@id"?: string }); } - if (values["@id"] != null && !values["@id"].startsWith("_:") && !URL.canParse(values["@id"], options.baseUrl)) { - throw new TypeError("Invalid @id: " + values["@id"]); - } - if (options.baseUrl == null && values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"])) { - options = { ...options, baseUrl: new URL(values["@id"]) }; + const id = parseJsonLdId(values["@id"], options.baseUrl); + if (id != null && options.baseUrl == null) { + options = { ...options, baseUrl: id }; } `; const subtypes = getSubtypes(typeUri, types, true); @@ -432,10 +432,24 @@ export async function* generateDecoder( } } `; + yield ` + let cacheJsonLd = !("_fromSubclass" in options) || !options._fromSubclass + ? normalizeJsonLdIris( + expanded, + PORTABLE_IRI_KEYS, + PORTABLE_IRI_PATTERN, + ) + : undefined; + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + cacheJsonLd = structuredClone(cacheJsonLd); + } + `; if (type.extends == null) { yield ` const instance = new this( - { id: values["@id"] != null && !values["@id"].startsWith("_:") && URL.canParse(values["@id"], options.baseUrl) ? new URL(values["@id"], options.baseUrl) : undefined }, + { + id + }, options, ); `; @@ -491,11 +505,7 @@ export async function* generateDecoder( if (typeof v === "object" && "@id" in v && !("@type" in v) && globalThis.Object.keys(v).length === 1) { if (v["@id"].startsWith("_:")) continue; - ${variable}.push( - !URL.canParse(v["@id"], ${propertyBaseUrl}) && v["@id"].startsWith("at://") - ? new URL("at://" + encodeURIComponent(v["@id"].substring(5))) - : new URL(v["@id"], ${propertyBaseUrl}) - ); + ${variable}.push(parseIri(v["@id"], ${propertyBaseUrl})); continue; } `; @@ -539,7 +549,19 @@ export async function* generateDecoder( yield ` if (!("_fromSubclass" in options) || !options._fromSubclass) { try { - instance._cachedJsonLd = structuredClone(json); + if (cacheJsonLd != null && cacheJsonLd !== expanded) { + const compactArray = Array.isArray(json) && json.length === 1; + const jsonLd = compactArray ? json[0] : json; + const normalized = cacheJsonLd; + const cachedJsonLd = await compactJsonLdCache( + normalized, + jsonLd, + options.contextLoader, + ); + instance._cachedJsonLd = compactArray ? [cachedJsonLd] : cachedJsonLd; + } else { + instance._cachedJsonLd = structuredClone(json); + } } catch { getLogger(["fedify", "vocab"]).warn( "Failed to cache JSON-LD: {json}", diff --git a/packages/vocab-tools/src/property.ts b/packages/vocab-tools/src/property.ts index e000066b3..28bcbfbfb 100644 --- a/packages/vocab-tools/src/property.ts +++ b/packages/vocab-tools/src/property.ts @@ -86,9 +86,10 @@ async function* generateProperty( ${JSON.stringify(metadata.version)}, ); return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { + const lookupUrl = formatIri(url); let fetchResult: RemoteDocument; try { - fetchResult = await documentLoader(url.href); + fetchResult = await documentLoader(lookupUrl); } catch (error) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -98,21 +99,20 @@ async function* generateProperty( if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to fetch {url}: {error}", - { error, url: url.href } + { error, url: lookupUrl } ); return null; } throw error; } const { document, documentUrl } = fetchResult; - const baseUrl = new URL(documentUrl); + const baseUrl = parseIri(documentUrl); try { const obj = await this.#${property.singularName}_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider, baseUrl } ); - if (options.crossOrigin !== "trust" && obj?.id != null && - obj.id.origin !== baseUrl.origin) { + if (obj?.id != null && !isTrustedIriOrigin(options, obj.id, baseUrl)) { if (options.crossOrigin === "throw") { throw new Error( "The object's @id (" + obj.id.href + ") has a different origin " + @@ -141,7 +141,7 @@ async function* generateProperty( if (options.suppressError) { getLogger(["fedify", "vocab"]).error( "Failed to parse {url}: {error}", - { error: e, url: url.href } + { error: e, url: lookupUrl } ); return null; } @@ -275,8 +275,9 @@ async function* generateProperty( } if (this.${await getFieldName(property.uri)}.length < 1) return null; let v = this.${await getFieldName(property.uri)}[0]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.${await getFieldName(property.uri, "#_trust")}.has(0)) { v = v.id; } @@ -315,8 +316,8 @@ async function* generateProperty( `; } yield ` - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && !this.${await getFieldName(property.uri, "#_trust")}.has(0)) { if (options.crossOrigin === "throw") { throw new Error( @@ -380,8 +381,9 @@ async function* generateProperty( const vs = this.${await getFieldName(property.uri)}; for (let i = 0; i < vs.length; i++) { let v = vs[i]; - if (options.crossOrigin !== "trust" && !(v instanceof URL) && - v.id != null && v.id.origin !== this.id?.origin && + if (!(v instanceof URL) && + v.id != null && + !isTrustedIriOrigin(options, v.id, this.id) && !this.${await getFieldName(property.uri, "#_trust")}.has(i)) { v = v.id; } @@ -421,9 +423,9 @@ async function* generateProperty( `; } yield ` - if (options.crossOrigin !== "trust" && v?.id != null && - this.id != null && v.id.origin !== this.id.origin && - !this.${await getFieldName(property.uri, "#_trust")}.has(0)) { + if (v?.id != null && + this.id != null && !isTrustedIriOrigin(options, v.id, this.id) && + !this.${await getFieldName(property.uri, "#_trust")}.has(i)) { if (options.crossOrigin === "throw") { throw new Error( "The property object's @id (" + v.id.href + ") has a different " + diff --git a/packages/vocab-tools/src/type.ts b/packages/vocab-tools/src/type.ts index 4adc1e7cc..086d75be1 100644 --- a/packages/vocab-tools/src/type.ts +++ b/packages/vocab-tools/src/type.ts @@ -157,10 +157,10 @@ const scalarTypes: Record = { return `${v} instanceof URL`; }, encoder(v) { - return `{ "@id": ${v}.href }`; + return `{ "@id": formatIri(${v}) }`; }, compactEncoder(v) { - return `${v}.href`; + return `formatIri(${v})`; }, dataCheck(v) { return `${v} != null && typeof ${v} === "object" && "@id" in ${v} @@ -168,22 +168,7 @@ const scalarTypes: Record = { && ${v}["@id"] !== ""`; }, decoder(v, baseUrlVar) { - return `${v}["@id"].startsWith("at://") - ? new URL("at://" + - encodeURIComponent( - ${v}["@id"].includes("/", 5) - ? ${v}["@id"].slice(5, ${v}["@id"].indexOf("/", 5)) - : ${v}["@id"].slice(5) - ) + - ( - ${v}["@id"].includes("/", 5) - ? ${v}["@id"].slice(${v}["@id"].indexOf("/", 5)) - : "" - ) - ) - : URL.canParse(${v}["@id"]) && ${baseUrlVar} - ? new URL(${v}["@id"]) - : new URL(${v}["@id"], ${baseUrlVar})`; + return `parseIri(${v}["@id"], ${baseUrlVar})`; }, }, "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString": { @@ -325,10 +310,10 @@ const scalarTypes: Record = { return `${v} instanceof URL`; }, encoder(v) { - return `{ "@value": ${v}.href }`; + return `{ "@value": formatIri(${v}) }`; }, compactEncoder(v) { - return `${v}.href`; + return `formatIri(${v})`; }, dataCheck(v) { return `typeof ${v} === "object" && "@value" in ${v} @@ -336,7 +321,7 @@ const scalarTypes: Record = { && ${v}["@value"] !== "" && ${v}["@value"] !== "/"`; }, decoder(v) { - return `new URL(${v}["@value"])`; + return `parseIri(${v}["@value"])`; }, }, "fedify:publicKey": { diff --git a/packages/vocab/src/lookup.ts b/packages/vocab/src/lookup.ts index d2164ec38..c28d9227a 100644 --- a/packages/vocab/src/lookup.ts +++ b/packages/vocab/src/lookup.ts @@ -2,6 +2,8 @@ import type { GetUserAgentOptions } from "@fedify/vocab-runtime"; import { type DocumentLoader, getDocumentLoader, + haveSameIriOrigin, + parseIri, type RemoteDocument, } from "@fedify/vocab-runtime"; import { lookupWebFinger } from "@fedify/webfinger"; @@ -312,12 +314,14 @@ async function lookupObjectInternal( } if (remoteDoc == null) return null; let object: Object; + let documentUrl: URL; try { + documentUrl = parseIri(remoteDoc.documentUrl); object = await Object.fromJsonLd(remoteDoc.document, { documentLoader, contextLoader: options.contextLoader, tracerProvider: options.tracerProvider, - baseUrl: new URL(remoteDoc.documentUrl), + baseUrl: documentUrl, }); } catch (error) { if (error instanceof TypeError) { @@ -331,7 +335,7 @@ async function lookupObjectInternal( } if ( options.crossOrigin !== "trust" && object.id != null && - object.id.origin !== new URL(remoteDoc.documentUrl).origin + !haveSameIriOrigin(object.id, documentUrl) ) { if (options.crossOrigin === "throw") { throw new Error( diff --git a/packages/vocab/src/vocab.test.ts b/packages/vocab/src/vocab.test.ts index f6cc82e5e..bd7c80fa2 100644 --- a/packages/vocab/src/vocab.test.ts +++ b/packages/vocab/src/vocab.test.ts @@ -1,8 +1,10 @@ import { mockDocumentLoader, test } from "@fedify/fixture"; import { decodeMultibase, + type DocumentLoader, LanguageString, parseDecimal, + type RemoteDocument, } from "@fedify/vocab-runtime"; import { areAllScalarTypes, @@ -479,6 +481,966 @@ test("Activity.fromJsonLd()", async () => { ); }); +test("fromJsonLd() handles portable ActivityPub IRIs", async () => { + const did = "did:key:z6Mkabc"; + const portableActor = + `ap://${did}/actor?gateways=https%3A%2F%2Fserver.example`; + const portableObject = + `ap://${did}/objects/1?gateways=https%3A%2F%2Fserver.example`; + const uppercasePortableObject = + `AP://${did}/objects/1?gateways=https%3A%2F%2Fserver.example`; + const portablePage = `ap://${did}/actor/outbox?page=2`; + + const note = await Note.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + type: "Note", + id: uppercasePortableObject, + attributedTo: `ap+ef61://${ + encodeURIComponent(did) + }/actor?gateways=https%3A%2F%2Fserver.example`, + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + deepStrictEqual( + note.id, + new URL( + "ap+ef61://did%3Akey%3Az6Mkabc/objects/1?gateways=https%3A%2F%2Fserver.example", + ), + ); + deepStrictEqual( + note.attributionId, + new URL( + "ap+ef61://did%3Akey%3Az6Mkabc/actor?gateways=https%3A%2F%2Fserver.example", + ), + ); + const noteJson = await note.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + deepStrictEqual(noteJson.type, "Note"); + deepStrictEqual( + noteJson.id, + "ap+ef61://did:key:z6Mkabc/objects/1?gateways=https%3A%2F%2Fserver.example", + ); + deepStrictEqual( + noteJson.attributedTo, + "ap+ef61://did:key:z6Mkabc/actor?gateways=https%3A%2F%2Fserver.example", + ); + + const activity = await Activity.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + type: "Create", + actor: portableActor, + object: portableObject, + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + deepStrictEqual( + activity.actorId, + new URL( + "ap+ef61://did%3Akey%3Az6Mkabc/actor?gateways=https%3A%2F%2Fserver.example", + ), + ); + const activityJson = await activity.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + deepStrictEqual(activityJson.type, "Create"); + deepStrictEqual( + activityJson.actor, + "ap+ef61://did:key:z6Mkabc/actor?gateways=https%3A%2F%2Fserver.example", + ); + deepStrictEqual( + activityJson.object, + "ap+ef61://did:key:z6Mkabc/objects/1?gateways=https%3A%2F%2Fserver.example", + ); + + const person = await Person.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + type: "Person", + inbox: `ap+ef61://${did}/actor/inbox`, + outbox: `ap+ef61://${did}/actor/outbox`, + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + deepStrictEqual( + person.inboxId, + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor/inbox"), + ); + deepStrictEqual( + person.outboxId, + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor/outbox"), + ); + const personJson = await person.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + deepStrictEqual(personJson.type, "Person"); + deepStrictEqual(personJson.inbox, "ap+ef61://did:key:z6Mkabc/actor/inbox"); + deepStrictEqual( + personJson.outbox, + "ap+ef61://did:key:z6Mkabc/actor/outbox", + ); + + const page = await OrderedCollectionPage.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + type: "OrderedCollectionPage", + next: portablePage, + prev: `ap+ef61://${encodeURIComponent(did)}/actor/outbox?page=1`, + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + deepStrictEqual( + page.nextId, + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor/outbox?page=2"), + ); + deepStrictEqual( + page.prevId, + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor/outbox?page=1"), + ); + const pageJson = await page.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + deepStrictEqual(pageJson.type, "OrderedCollectionPage"); + deepStrictEqual( + pageJson.next, + "ap+ef61://did:key:z6Mkabc/actor/outbox?page=2", + ); + deepStrictEqual( + pageJson.prev, + "ap+ef61://did:key:z6Mkabc/actor/outbox?page=1", + ); +}); + +test("fromJsonLd() caches text that mentions portable ActivityPub IRIs", async () => { + const noteJson = { + "@context": [ + "https://www.w3.org/ns/activitystreams", + { extra: "https://example.com/ns#extra" }, + ], + type: "Note", + id: "https://example.com/notes/1", + content: "This is text about ap://did:key:z6Mkabc/actor.", + extra: "This extension property should stay cached.", + }; + + const note = await Note.fromJsonLd(noteJson, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await note.toJsonLd(), noteJson); +}); + +test("fromJsonLd() preserves extensions with portable ActivityPub IRIs", async () => { + const note = await Note.fromJsonLd({ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { extra: "https://example.com/ns#extra" }, + ], + type: "Note", + id: "ap://did:key:z6Mkabc/objects/1", + extra: "This extension property should stay cached.", + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + + const jsonLd = await note.toJsonLd() as Record; + deepStrictEqual(jsonLd.extra, "This extension property should stay cached."); + deepStrictEqual(jsonLd.id, "ap+ef61://did:key:z6Mkabc/objects/1"); +}); + +test("fromJsonLd() preserves unmapped terms with portable IRIs", async () => { + const note = await Note.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + type: "Note", + id: "ap://did:key:z6Mkabc/objects/1", + extra: "This unmapped property should stay cached.", + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + + const jsonLd = await note.toJsonLd() as Record; + deepStrictEqual( + jsonLd.extra, + "This unmapped property should stay cached.", + ); + deepStrictEqual(jsonLd.id, "ap+ef61://did:key:z6Mkabc/objects/1"); +}); + +test("fromJsonLd() preserves expanded arrays with portable IRIs", async () => { + const expanded = [ + { + "@id": "https://example.com/activities/1", + "@type": ["https://www.w3.org/ns/activitystreams#Create"], + "https://www.w3.org/ns/activitystreams#actor": [ + { "@id": "ap://did:key:z6Mkabc/actor" }, + ], + "https://www.w3.org/ns/activitystreams#object": [ + { "@id": "https://example.com/objects/1" }, + ], + }, + { + "@id": "https://example.com/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#content": [ + { "@value": "Sibling node should stay cached." }, + ], + }, + ]; + + const activity = await Activity.fromJsonLd(expanded, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual( + activity.actorId, + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"), + ); + deepStrictEqual(await activity.toJsonLd(), [ + { + "@id": "https://example.com/activities/1", + "@type": ["https://www.w3.org/ns/activitystreams#Create"], + "https://www.w3.org/ns/activitystreams#actor": [ + { "@id": "ap+ef61://did:key:z6Mkabc/actor" }, + ], + "https://www.w3.org/ns/activitystreams#object": [ + { "@id": "https://example.com/objects/1" }, + ], + }, + { + "@id": "https://example.com/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#content": [ + { "@value": "Sibling node should stay cached." }, + ], + }, + ]); + deepStrictEqual(expanded[0]["https://www.w3.org/ns/activitystreams#actor"], [ + { "@id": "ap://did:key:z6Mkabc/actor" }, + ]); +}); + +test("fromJsonLd() preserves single-node expanded arrays with portable IRIs", async () => { + const expanded = [ + { + "@id": "ap://did:key:z6Mkabc/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { "@id": "ap://did:key:z6Mkabc/actor" }, + ], + "https://www.w3.org/ns/activitystreams#content": [ + { "@value": "Single expanded node should stay cached as an array." }, + ], + }, + ]; + + const note = await Note.fromJsonLd(expanded, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await note.toJsonLd(), [ + { + "@id": "ap+ef61://did:key:z6Mkabc/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { "@id": "ap+ef61://did:key:z6Mkabc/actor" }, + ], + "https://www.w3.org/ns/activitystreams#content": [ + { "@value": "Single expanded node should stay cached as an array." }, + ], + }, + ]); + deepStrictEqual(expanded[0]["@id"], "ap://did:key:z6Mkabc/objects/1"); +}); + +test("fromJsonLd() preserves no-context object shape with portable IRIs", async () => { + const expanded = { + "@id": "ap://did:key:z6Mkabc/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { "@id": "ap://did:key:z6Mkabc/actor" }, + ], + "https://www.w3.org/ns/activitystreams#content": [ + { "@value": "No-context object shape should stay cached." }, + ], + }; + + const note = await Note.fromJsonLd(expanded, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await note.toJsonLd(), { + "@id": "ap+ef61://did:key:z6Mkabc/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { "@id": "ap+ef61://did:key:z6Mkabc/actor" }, + ], + "https://www.w3.org/ns/activitystreams#content": [ + { "@value": "No-context object shape should stay cached." }, + ], + }); + deepStrictEqual(expanded["@id"], "ap://did:key:z6Mkabc/objects/1"); +}); + +test("fromJsonLd() preserves expanded subtype cache types", async () => { + const expanded = [ + { + "@id": "https://example.com/activities/1", + "@type": ["https://www.w3.org/ns/activitystreams#Create"], + "https://www.w3.org/ns/activitystreams#actor": [ + { "@id": "https://example.com/actors/alice" }, + ], + "https://www.w3.org/ns/activitystreams#object": [ + { "@id": "https://example.com/objects/1" }, + ], + }, + { + "@id": "https://example.com/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { "@id": "ap://did:key:z6Mkabc/actor" }, + ], + }, + ]; + + const activity = await Activity.fromJsonLd(expanded, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await activity.toJsonLd(), [ + { + "@id": "https://example.com/activities/1", + "@type": ["https://www.w3.org/ns/activitystreams#Create"], + "https://www.w3.org/ns/activitystreams#actor": [ + { "@id": "https://example.com/actors/alice" }, + ], + "https://www.w3.org/ns/activitystreams#object": [ + { "@id": "https://example.com/objects/1" }, + ], + }, + { + "@id": "https://example.com/objects/1", + "@type": ["https://www.w3.org/ns/activitystreams#Note"], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { "@id": "ap+ef61://did:key:z6Mkabc/actor" }, + ], + }, + ]); + deepStrictEqual(expanded[0]["@type"], [ + "https://www.w3.org/ns/activitystreams#Create", + ]); +}); + +test("fromJsonLd() preserves compact array contexts with portable IRIs", async () => { + const note = await Note.fromJsonLd([{ + "@context": "https://www.w3.org/ns/activitystreams", + type: "Note", + id: "ap://did:key:z6Mkabc/objects/1", + }], { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await note.toJsonLd(), [{ + "@context": "https://www.w3.org/ns/activitystreams", + type: "Note", + id: "ap+ef61://did:key:z6Mkabc/objects/1", + }]); +}); + +test("fromJsonLd() preserves compact single-item arrays with portable IRIs", async () => { + const createJson = { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Create", + actor: ["ap://did:key:z6Mkabc/actor"], + object: "https://example.com/objects/1", + }; + + const create = await Create.fromJsonLd(createJson, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await create.toJsonLd(), { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Create", + actor: ["ap+ef61://did:key:z6Mkabc/actor"], + object: "https://example.com/objects/1", + }); + deepStrictEqual(createJson.actor, ["ap://did:key:z6Mkabc/actor"]); +}); + +test("fromJsonLd() preserves compact multi-node arrays with portable IRIs", async () => { + const activityJson = [ + { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Create", + id: "https://example.com/activities/1", + actor: "https://example.com/actors/alice", + object: "https://example.com/objects/1", + }, + { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Note", + id: "https://example.com/objects/1", + attributedTo: "ap://did:key:z6Mkabc/actor", + }, + ]; + + const activity = await Activity.fromJsonLd(activityJson, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await activity.toJsonLd(), [ + { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Create", + id: "https://example.com/activities/1", + actor: "https://example.com/actors/alice", + object: "https://example.com/objects/1", + }, + { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Note", + id: "https://example.com/objects/1", + attributedTo: "ap+ef61://did:key:z6Mkabc/actor", + }, + ]); +}); + +test("fromJsonLd() preserves nested unmapped terms with portable IRIs", async () => { + const noteJson = { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Note", + id: "ap://did:key:z6Mkabc/objects/1", + attachment: { + type: "Object", + name: "Attachment with an unmapped extension.", + extra: "This nested unmapped property should stay cached.", + }, + }; + + const note = await Note.fromJsonLd(noteJson, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await note.toJsonLd(), { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Note", + id: "ap+ef61://did:key:z6Mkabc/objects/1", + attachment: { + type: "Object", + name: "Attachment with an unmapped extension.", + extra: "This nested unmapped property should stay cached.", + }, + }); +}); + +test("fromJsonLd() preserves compact array item extension contexts with portable IRIs", async () => { + const activityJson = [ + { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Create", + id: "https://example.com/activities/1", + actor: "https://example.com/actors/alice", + object: "https://example.com/objects/1", + }, + { + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + extraRef: { + "@id": "https://example.com/ns#extraRef", + "@type": "@id", + }, + }, + ], + type: "Note", + id: "https://example.com/objects/1", + extraRef: "ap://did:key:z6Mkabc/extra", + }, + ]; + + const activity = await Activity.fromJsonLd(activityJson, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await activity.toJsonLd(), [ + { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Create", + id: "https://example.com/activities/1", + actor: "https://example.com/actors/alice", + object: "https://example.com/objects/1", + }, + { + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + extraRef: { + "@id": "https://example.com/ns#extraRef", + "@type": "@id", + }, + }, + ], + type: "Note", + id: "https://example.com/objects/1", + extraRef: "ap+ef61://did:key:z6Mkabc/extra", + }, + ]); +}); + +test("fromJsonLd() formats portable IRIs in JSON-LD containers", async () => { + const note = await Note.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + type: "Note", + id: "https://example.com/notes/1", + attributedTo: { + "@list": ["ap://did:key:z6Mkabc/actor"], + }, + to: { + "@set": ["ap://did:key:z6Mkabc/followers"], + }, + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + + const jsonLd = await note.toJsonLd() as Record; + deepStrictEqual(jsonLd.attributedTo, { + "@list": ["ap+ef61://did:key:z6Mkabc/actor"], + }); + deepStrictEqual(jsonLd.to, "ap+ef61://did:key:z6Mkabc/followers"); +}); + +test("fromJsonLd() formats portable IRIs hidden behind JSON-LD aliases", async () => { + const activity = await Activity.fromJsonLd({ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + as: { + "@id": "https://www.w3.org/ns/activitystreams#", + "@prefix": true, + }, + extra: "https://example.com/ns#extra", + extraRef: { + "@id": "https://example.com/ns#extraRef", + "@type": "@id", + }, + actorRef: { + "@id": "as:actor", + "@type": "@id", + }, + targetRef: { + "@id": "as:target", + "@type": "@id", + }, + }, + ], + type: "Create", + actorRef: "ap://did:key:z6Mkabc/actor", + object: "https://example.com/objects/1", + targetRef: "ap://did:key:z6Mkabc/target", + extra: "This extension property should stay cached.", + extraRef: "ap://did:key:z6Mkabc/extra", + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + + deepStrictEqual( + activity.actorId, + new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"), + ); + deepStrictEqual( + activity.targetId, + new URL("ap+ef61://did%3Akey%3Az6Mkabc/target"), + ); + const jsonLd = await activity.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + deepStrictEqual(jsonLd.actor, "ap+ef61://did:key:z6Mkabc/actor"); + deepStrictEqual("actorRef" in jsonLd, false); + deepStrictEqual(jsonLd.target, "ap+ef61://did:key:z6Mkabc/target"); + deepStrictEqual("targetRef" in jsonLd, false); + deepStrictEqual(jsonLd.extra, "This extension property should stay cached."); + deepStrictEqual(jsonLd.extraRef, "ap+ef61://did:key:z6Mkabc/extra"); +}); + +test("fromJsonLd() preserves portable IRIs in @id extension terms", async () => { + const note = await Note.fromJsonLd({ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + extraRef: { + "@id": "https://example.com/ns#extraRef", + "@type": "@id", + }, + }, + ], + type: "Note", + id: "https://example.com/notes/1", + extraRef: "ap://did:key:z6Mkabc/extra", + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + + const jsonLd = await note.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + deepStrictEqual(jsonLd.extraRef, "ap+ef61://did:key:z6Mkabc/extra"); +}); + +test("fromJsonLd() ignores malformed portable IRIs in extension cache terms", async () => { + const noteJson = { + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + extraRef: { + "@id": "https://example.com/ns#extraRef", + "@type": "@id", + }, + }, + ], + type: "Note", + id: "https://example.com/notes/1", + extraRef: "ap://example.com/not-portable", + }; + + const note = await Note.fromJsonLd(noteJson, { + documentLoader: mockDocumentLoader, + contextLoader: mockDocumentLoader, + }); + + deepStrictEqual(await note.toJsonLd(), noteJson); +}); + +test("fromJsonLd() preserves portable IRIs in @id typed terms", async () => { + const note = await Note.fromJsonLd({ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "@vocab": "https://example.com/ns#", + extraRef: { "@type": "@id" }, + }, + ], + type: "Note", + id: "https://example.com/notes/1", + content: "This text mentions ap://did:key:z6Mkabc/text.", + extraRef: "ap://did:key:z6Mkabc/extra", + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + + const jsonLd = await note.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + deepStrictEqual( + jsonLd.content, + "This text mentions ap://did:key:z6Mkabc/text.", + ); + deepStrictEqual(jsonLd.extraRef, "ap+ef61://did:key:z6Mkabc/extra"); +}); + +test("fromJsonLd() preserves portable IRIs hidden behind remote contexts", async () => { + const contextUrl = "https://example.com/contexts/portable-iris"; + const contextLoader: DocumentLoader = async ( + resource: string, + options, + ): Promise => { + if (resource === contextUrl) { + return { + contextUrl: null, + documentUrl: resource, + document: { + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "@vocab": "https://example.com/ns#", + extra: "https://example.com/ns#extra", + extraRef: { "@type": "@id" }, + }, + ], + }, + }; + } + return await mockDocumentLoader(resource, options); + }; + const note = await Note.fromJsonLd({ + "@context": contextUrl, + type: "Note", + id: "https://example.com/notes/1", + content: "This text mentions ap://did:key:z6Mkabc/text.", + extra: "This extension property should stay cached.", + extraRef: "ap://did:key:z6Mkabc/extra", + }, { documentLoader: mockDocumentLoader, contextLoader }); + + const jsonLd = await note.toJsonLd({ contextLoader }) as Record< + string, + unknown + >; + deepStrictEqual( + jsonLd.content, + "This text mentions ap://did:key:z6Mkabc/text.", + ); + deepStrictEqual(jsonLd.extra, "This extension property should stay cached."); + deepStrictEqual(jsonLd.extraRef, "ap+ef61://did:key:z6Mkabc/extra"); +}); + +test("fromJsonLd() formats portable IRIs hidden behind nested remote contexts", async () => { + const rootContextUrl = "https://example.com/contexts/nested-portable-iris"; + const nestedContextUrl = "https://example.com/contexts/nested-portable-ref"; + const contextLoader: DocumentLoader = async ( + resource: string, + options, + ): Promise => { + if (resource === rootContextUrl) { + return { + contextUrl: null, + documentUrl: resource, + document: { + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "@vocab": "https://example.com/ns#", + extraContainer: "https://example.com/ns#extraContainer", + }, + ], + }, + }; + } + if (resource === nestedContextUrl) { + return { + contextUrl: null, + documentUrl: resource, + document: { + "@context": { + "@vocab": "https://example.com/ns#", + extra: "https://example.com/ns#extra", + extraRef: { "@type": "@id" }, + }, + }, + }; + } + return await mockDocumentLoader(resource, options); + }; + const note = await Note.fromJsonLd({ + "@context": rootContextUrl, + type: "Note", + id: "https://example.com/notes/1", + extraContainer: { + "@context": nestedContextUrl, + content: "This text mentions ap://did:key:z6Mkabc/text.", + extra: "This nested extension object should stay cached.", + extraRef: "ap://did:key:z6Mkabc/extra", + }, + }, { documentLoader: mockDocumentLoader, contextLoader }); + + const jsonLd = await note.toJsonLd({ contextLoader }) as Record< + string, + unknown + >; + deepStrictEqual(jsonLd.extraContainer, { + "@context": nestedContextUrl, + content: "This text mentions ap://did:key:z6Mkabc/text.", + extra: "This nested extension object should stay cached.", + extraRef: { id: "ap+ef61://did:key:z6Mkabc/extra" }, + }); +}); + +test("fromJsonLd() formats portable IRIs in sibling remote-context objects", async () => { + const rootContextUrl = "https://example.com/contexts/sibling-containers"; + const nestedContextUrl = "https://example.com/contexts/sibling-extra-ref"; + const contextLoader: DocumentLoader = async ( + resource: string, + options, + ): Promise => { + if (resource === rootContextUrl) { + return { + contextUrl: null, + documentUrl: resource, + document: { + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "@vocab": "https://example.com/ns#", + firstExtraContainer: "https://example.com/ns#firstExtraContainer", + secondExtraContainer: + "https://example.com/ns#secondExtraContainer", + }, + ], + }, + }; + } + if (resource === nestedContextUrl) { + return { + contextUrl: null, + documentUrl: resource, + document: { + "@context": { + "@vocab": "https://example.com/ns#", + extraRef: { "@type": "@id" }, + }, + }, + }; + } + return await mockDocumentLoader(resource, options); + }; + const note = await Note.fromJsonLd({ + "@context": rootContextUrl, + type: "Note", + id: "https://example.com/notes/1", + firstExtraContainer: { + "@context": nestedContextUrl, + content: "No portable IRI here.", + }, + secondExtraContainer: { + "@context": nestedContextUrl, + extraRef: "ap://did:key:z6Mkabc/second", + }, + }, { documentLoader: mockDocumentLoader, contextLoader }); + + const jsonLd = await note.toJsonLd({ contextLoader }) as Record< + string, + unknown + >; + deepStrictEqual(jsonLd.firstExtraContainer, { + "@context": nestedContextUrl, + content: "No portable IRI here.", + }); + deepStrictEqual(jsonLd.secondExtraContainer, { + "@context": nestedContextUrl, + extraRef: { id: "ap+ef61://did:key:z6Mkabc/second" }, + }); +}); + +test("fromJsonLd() batches unmapped portable IRI term checks", async () => { + const contextUrl = "https://example.com/contexts/batched-portable-aliases"; + let contextLoads = 0; + const contextLoader: DocumentLoader = async ( + resource: string, + options, + ): Promise => { + if (resource === contextUrl) { + contextLoads++; + return { + contextUrl: null, + documentUrl: resource, + document: { + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + as: { + "@id": "https://www.w3.org/ns/activitystreams#", + "@prefix": true, + }, + actorRef0: { "@id": "as:actor", "@type": "@id" }, + actorRef1: { "@id": "as:actor", "@type": "@id" }, + targetRef0: { "@id": "as:target", "@type": "@id" }, + targetRef1: { "@id": "as:target", "@type": "@id" }, + objectRef0: { "@id": "as:object", "@type": "@id" }, + objectRef1: { "@id": "as:object", "@type": "@id" }, + }, + ], + }, + }; + } + return await mockDocumentLoader(resource, options); + }; + + const activity = await Activity.fromJsonLd({ + "@context": contextUrl, + type: "Create", + actorRef0: "ap://did:key:z6Mkabc/actor0", + actorRef1: "ap://did:key:z6Mkabc/actor1", + targetRef0: "ap://did:key:z6Mkabc/target0", + targetRef1: "ap://did:key:z6Mkabc/target1", + objectRef0: "https://example.com/objects/0", + objectRef1: "https://example.com/objects/1", + }, { documentLoader: mockDocumentLoader, contextLoader }); + + await activity.toJsonLd({ contextLoader }); + + ok(contextLoads <= 5); +}); + +test("fromJsonLd() falls back when portable IRI cache merge fails", async () => { + const contextUrl = "https://example.com/contexts/failing-cache-merge"; + let contextLoads = 0; + const contextLoader: DocumentLoader = async ( + resource: string, + options, + ): Promise => { + if (resource === contextUrl) { + contextLoads++; + if (contextLoads > 1) throw new Error("merge context unavailable"); + return { + contextUrl: null, + documentUrl: resource, + document: { + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "@vocab": "https://example.com/ns#", + extraRef: { "@type": "@id" }, + }, + ], + }, + }; + } + return await mockDocumentLoader(resource, options); + }; + + const note = await Note.fromJsonLd({ + "@context": contextUrl, + type: "Note", + id: "ap://did:key:z6Mkabc/objects/1", + extraRef: "ap://did:key:z6Mkabc/extra", + }, { documentLoader: mockDocumentLoader, contextLoader }); + + const jsonLd = await note.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + + deepStrictEqual(jsonLd.type, "Note"); + deepStrictEqual(jsonLd.id, "ap+ef61://did:key:z6Mkabc/objects/1"); +}); + +test("fromJsonLd() formats portable IRIs in scalar URL values", async () => { + const note = await Note.fromJsonLd({ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://gotosocial.org/ns", + { quoteUrl: "as:quoteUrl" }, + ], + type: "Note", + id: "https://example.com/notes/1", + quoteUrl: "ap://did:key:z6Mkabc/objects/1", + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + + deepStrictEqual( + note.quoteUrl, + new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/1"), + ); + const jsonLd = await note.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + deepStrictEqual(jsonLd.quoteUrl, "ap+ef61://did:key:z6Mkabc/objects/1"); +}); + +test("fromJsonLd() formats portable IRIs in URL value lists", async () => { + const note = await Note.fromJsonLd({ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://gotosocial.org/ns", + { quoteUrl: "as:quoteUrl" }, + ], + type: "Note", + id: "https://example.com/notes/1", + quoteUrl: { + "@list": [ + { "@value": "ap://did:key:z6Mkabc/objects/1" }, + ], + }, + }, { documentLoader: mockDocumentLoader, contextLoader: mockDocumentLoader }); + + deepStrictEqual( + note.quoteUrl, + new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/1"), + ); + const jsonLd = await note.toJsonLd({ + contextLoader: mockDocumentLoader, + }) as Record; + deepStrictEqual(jsonLd.quoteUrl, { + "@list": [ + "ap+ef61://did:key:z6Mkabc/objects/1", + ], + }); +}); + test({ name: "Activity.getObject()", permissions: { env: true, read: true }, @@ -544,6 +1506,37 @@ test({ }, }); +test("Activity.getObject() fetches canonical portable IRIs", async () => { + const fetchedUrls: string[] = []; + // deno-lint-ignore require-await + const documentLoader: DocumentLoader = async (url) => { + fetchedUrls.push(url); + return { + contextUrl: null, + documentUrl: url, + document: { + "@context": "https://www.w3.org/ns/activitystreams", + id: url, + type: "Note", + content: "Fetched portable object", + }, + }; + }; + const activity = await Activity.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + type: "Create", + object: "ap://did:key:z6Mkabc/objects/1", + }, { documentLoader, contextLoader: mockDocumentLoader }); + + const object = await activity.getObject({ + documentLoader, + contextLoader: mockDocumentLoader, + }); + + assertInstanceOf(object, Note); + deepStrictEqual(fetchedUrls, ["ap+ef61://did:key:z6Mkabc/objects/1"]); +}); + test({ name: "Activity.getObjects()", permissions: { env: true, read: true }, @@ -2462,6 +3455,31 @@ test("FEP-fe34: crossOrigin trust behavior", async () => { deepStrictEqual(result?.content, "This is a spoofed note"); }); +test("FEP-fe34: id-less owners honor crossOrigin trust", async () => { + const create = await Create.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + "@type": "Create", + "actor": "https://example.com/actor", + "object": { + "@type": "Note", + "@id": "https://different-origin.com/note", + "content": "Embedded note", + }, + }); + + const result = await create.getObject({ + crossOrigin: "trust", + // deno-lint-ignore require-await + documentLoader: async (url) => { + throw new Error(`Unexpected fetch: ${url}`); + }, + }); + + assertInstanceOf(result, Note); + deepStrictEqual(result.id, new URL("https://different-origin.com/note")); + deepStrictEqual(result.content, "Embedded note"); +}); + test("FEP-fe34: Same origin objects are trusted", async () => { // deno-lint-ignore require-await const sameOriginDocumentLoader = async (url: string) => { @@ -2609,6 +3627,44 @@ test("FEP-fe34: Constructor vs JSON-LD parsing trust difference", async () => { deepStrictEqual(jsonLdResult?.content, "Fetched from origin"); }); +test( + "FEP-fe34: Portable DID authorities are cross-origin boundaries", + async () => { + const create = await Create.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + "@type": "Create", + "@id": "ap://did:key:z6MkOwner/create", + "actor": "ap://did:key:z6MkOwner/actor", + "object": { + "@type": "Note", + "@id": "ap://did:key:z6MkOther/note", + "content": "Embedded portable note", + }, + }); + + // deno-lint-ignore require-await + const documentLoader = async (url: string) => { + if (url === "ap+ef61://did:key:z6MkOther/note") { + return { + documentUrl: url, + contextUrl: null, + document: { + "@context": "https://www.w3.org/ns/activitystreams", + "@type": "Note", + "@id": "ap://did:key:z6MkOther/note", + "content": "Fetched portable note", + }, + }; + } + throw new Error("Document not found"); + }; + + const result = await create.getObject({ documentLoader }); + assertInstanceOf(result, Note); + deepStrictEqual(result.content, "Fetched portable note"); + }, +); + test("FEP-fe34: Array properties respect cross-origin policy", async () => { // deno-lint-ignore require-await const crossOriginDocumentLoader = async (url: string) => { @@ -2716,6 +3772,82 @@ test("FEP-fe34: Array properties with crossOrigin trust option", async () => { deepStrictEqual((items[1] as Note).content, "Legitimate note 2"); }); +test("FEP-fe34: id-less arrays honor crossOrigin trust", async () => { + const collection = await Collection.fromJsonLd({ + "@context": "https://www.w3.org/ns/activitystreams", + "@type": "Collection", + "items": [ + { + "@type": "Note", + "@id": "https://different-origin.com/note1", + "content": "Embedded note 1", + }, + { + "@type": "Note", + "@id": "https://different-origin.com/note2", + "content": "Embedded note 2", + }, + ], + }); + + const items = []; + for await ( + const item of collection.getItems({ + crossOrigin: "trust", + // deno-lint-ignore require-await + documentLoader: async (url) => { + throw new Error(`Unexpected fetch: ${url}`); + }, + }) + ) { + items.push(item); + } + + deepStrictEqual(items.length, 2); + assertInstanceOf(items[0], Note); + assertInstanceOf(items[1], Note); + deepStrictEqual((items[0] as Note).content, "Embedded note 1"); + deepStrictEqual((items[1] as Note).content, "Embedded note 2"); +}); + +test("FEP-fe34: Array properties track trust per item", async () => { + const collection = new Collection({ + id: new URL("https://example.com/collection"), + items: [ + new Note({ + id: new URL("https://malicious.com/fake-note1"), + content: "Trusted constructor note 1", + }), + new URL("https://different-origin.com/note2"), + ], + }); + // deno-lint-ignore require-await + const documentLoader = async (url: string) => { + if (url === "https://different-origin.com/note2") { + return { + documentUrl: url, + contextUrl: null, + document: { + "@context": "https://www.w3.org/ns/activitystreams", + "@type": "Note", + "@id": "https://malicious.com/fake-note2", + "content": "Untrusted fetched note 2", + }, + }; + } + throw new Error("Document not found"); + }; + + const items = []; + for await (const item of collection.getItems({ documentLoader })) { + items.push(item); + } + + deepStrictEqual(items.length, 1); + assertInstanceOf(items[0], Note); + deepStrictEqual((items[0] as Note).content, "Trusted constructor note 1"); +}); + test( "FEP-fe34: Embedded objects in arrays from JSON-LD respect cross-origin policy", async () => {