Loading CHANGES.md +9 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,12 @@ To be released. ### @fedify/fedify - Fixed handling of ActivityPub objects containing relative URLs. The Activity Vocabulary classes now properly resolve relative URLs when a `baseUrl` option is provided to `fromJsonLd()` method, improving interoperability with ActivityPub servers that emit relative URLs in properties like `icon.url` and `image.url`. [[#411], [#443] by Jiwon Kwon] - Added inverse properties for collections to Vocabulary API. [[FEP-5711], [#373], [#381] by Jiwon Kwon] Loading Loading @@ -78,7 +84,10 @@ To be released. [#402]: https://github.com/fedify-dev/fedify/issues/402 [#404]: https://github.com/fedify-dev/fedify/pull/404 [#407]: https://github.com/fedify-dev/fedify/pull/407 [#411]: https://github.com/fedify-dev/fedify/issues/411 [#429]: https://github.com/fedify-dev/fedify/issues/429 [#431]: https://github.com/fedify-dev/fedify/pull/431 [#443]: https://github.com/fedify-dev/fedify/pull/443 ### @fedify/cli Loading packages/fedify/src/codegen/__snapshots__/class.test.ts.snap +1493 −656 File changed.Preview size limit exceeded, changes collapsed. Show changes packages/fedify/src/codegen/codec.ts +2 −0 Original line number Diff line number Diff line Loading @@ -287,6 +287,7 @@ export async function* generateDecoder( documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, ): Promise<${type.name}> { const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); Loading Loading @@ -324,6 +325,7 @@ export async function* generateDecoder( documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, ): Promise<${type.name}> { if (typeof json === "undefined") { Loading packages/fedify/src/codegen/property.ts +13 −6 Original line number Diff line number Diff line Loading @@ -64,7 +64,8 @@ async function* generateProperty( contextLoader?: DocumentLoader, suppressError?: boolean, tracerProvider?: TracerProvider, } = {} baseUrl?: URL } = {}, ): Promise<${getTypeNames(property.range, types)} | null> { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); Loading @@ -76,6 +77,7 @@ async function* generateProperty( ${JSON.stringify(metadata.name)}, ${JSON.stringify(metadata.version)}, ); const baseUrl = options.baseUrl; return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { let fetchResult: RemoteDocument; try { Loading @@ -99,7 +101,7 @@ async function* generateProperty( try { const obj = await this.#${property.singularName}_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider } { documentLoader, contextLoader, tracerProvider, baseUrl } ); span.setAttribute("activitypub.object.id", (obj.id ?? url).href); span.setAttribute( Loading Loading @@ -133,6 +135,7 @@ async function* generateProperty( documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, tracerProvider?: TracerProvider, baseUrl?: URL } ): Promise<${getTypeNames(property.range, types)}> { const documentLoader = Loading @@ -141,6 +144,7 @@ async function* generateProperty( options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); const tracerProvider = options.tracerProvider ?? this._tracerProvider ?? trace.getTracerProvider(); const baseUrl = options.baseUrl; `; for (const range of property.range) { if (!(range in types)) continue; Loading @@ -149,7 +153,7 @@ async function* generateProperty( try { return await ${rangeType.name}.fromJsonLd( jsonLd, { documentLoader, contextLoader, tracerProvider }, { documentLoader, contextLoader, tracerProvider, baseUrl }, ); } catch (e) { if (!(e instanceof TypeError)) throw e; Loading Loading @@ -190,6 +194,7 @@ async function* generateProperty( contextLoader?: DocumentLoader, suppressError?: boolean, tracerProvider?: TracerProvider, baseUrl?: URL } = {} ): Promise<${getTypeNames(property.range, types)} | null> { if (this._warning != null) { Loading Loading @@ -221,7 +226,7 @@ async function* generateProperty( ${JSON.stringify(property.compactName)}]; const obj = Array.isArray(prop) ? prop[0] : prop; if (obj != null && typeof obj === "object" && "@context" in obj) { return await this.#${property.singularName}_fromJsonLd(obj, options); return await this.#${property.singularName}_fromJsonLd(obj, {...options, baseUrl: options.baseUrl}); } } `; Loading Loading @@ -258,6 +263,7 @@ async function* generateProperty( contextLoader?: DocumentLoader, suppressError?: boolean, tracerProvider?: TracerProvider, baseUrl?: URL } = {} ): AsyncIterable<${getTypeNames(property.range, types)}> { if (this._warning != null) { Loading @@ -272,7 +278,7 @@ async function* generateProperty( if (v instanceof URL) { const fetched = await this.#fetch${pascalCase(property.singularName)}( v, options); v, {...options, baseUrl: options.baseUrl}); if (fetched == null) continue; vs[i] = fetched; this._cachedJsonLd = undefined; Loading @@ -292,7 +298,8 @@ async function* generateProperty( ${JSON.stringify(property.compactName)}]; const obj = Array.isArray(prop) ? prop[i] : prop; if (obj != null && typeof obj === "object" && "@context" in obj) { yield await this.#${property.singularName}_fromJsonLd(obj, options); yield await this.#${property.singularName}_fromJsonLd(obj, {...options, baseUrl: options.baseUrl }); continue; } } Loading packages/fedify/src/codegen/type.ts +12 −5 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ interface ScalarType { encoder(variable: string): string; compactEncoder?: (variable: string) => string; dataCheck(variable: string): string; decoder(variable: string): string; decoder(variable: string, baseUrlVar: string): string; } const scalarTypes: Record<string, ScalarType> = { Loading Loading @@ -141,9 +141,9 @@ const scalarTypes: Record<string, ScalarType> = { dataCheck(v) { return `typeof ${v} === "object" && "@id" in ${v} && typeof ${v}["@id"] === "string" && ${v}["@id"] !== "" && ${v}["@id"] !== "/"`; && ${v}["@id"] !== ""`; }, decoder(v) { decoder(v, baseUrlVar) { return `${v}["@id"].startsWith("at://") ? new URL("at://" + encodeURIComponent( Loading @@ -157,7 +157,9 @@ const scalarTypes: Record<string, ScalarType> = { : "" ) ) : new URL(${v}["@id"])`; : URL.canParse(${v}["@id"]) && ${baseUrlVar} ? new URL(${v}["@id"]) : new URL(${v}["@id"], ${baseUrlVar})`; }, }, "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString": { Loading Loading @@ -576,7 +578,12 @@ export function getDecoder( variable: string, optionsVariable: string, ): string { if (typeUri in scalarTypes) return scalarTypes[typeUri].decoder(variable); if (typeUri in scalarTypes) { return scalarTypes[typeUri].decoder( variable, `${optionsVariable}?.baseUrl`, ); } if (typeUri in types) { return `await ${types[typeUri].name}.fromJsonLd( ${variable}, ${optionsVariable})`; Loading Loading
CHANGES.md +9 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,12 @@ To be released. ### @fedify/fedify - Fixed handling of ActivityPub objects containing relative URLs. The Activity Vocabulary classes now properly resolve relative URLs when a `baseUrl` option is provided to `fromJsonLd()` method, improving interoperability with ActivityPub servers that emit relative URLs in properties like `icon.url` and `image.url`. [[#411], [#443] by Jiwon Kwon] - Added inverse properties for collections to Vocabulary API. [[FEP-5711], [#373], [#381] by Jiwon Kwon] Loading Loading @@ -78,7 +84,10 @@ To be released. [#402]: https://github.com/fedify-dev/fedify/issues/402 [#404]: https://github.com/fedify-dev/fedify/pull/404 [#407]: https://github.com/fedify-dev/fedify/pull/407 [#411]: https://github.com/fedify-dev/fedify/issues/411 [#429]: https://github.com/fedify-dev/fedify/issues/429 [#431]: https://github.com/fedify-dev/fedify/pull/431 [#443]: https://github.com/fedify-dev/fedify/pull/443 ### @fedify/cli Loading
packages/fedify/src/codegen/__snapshots__/class.test.ts.snap +1493 −656 File changed.Preview size limit exceeded, changes collapsed. Show changes
packages/fedify/src/codegen/codec.ts +2 −0 Original line number Diff line number Diff line Loading @@ -287,6 +287,7 @@ export async function* generateDecoder( documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, ): Promise<${type.name}> { const tracerProvider = options.tracerProvider ?? trace.getTracerProvider(); Loading Loading @@ -324,6 +325,7 @@ export async function* generateDecoder( documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, tracerProvider?: TracerProvider, baseUrl?: URL, } = {}, ): Promise<${type.name}> { if (typeof json === "undefined") { Loading
packages/fedify/src/codegen/property.ts +13 −6 Original line number Diff line number Diff line Loading @@ -64,7 +64,8 @@ async function* generateProperty( contextLoader?: DocumentLoader, suppressError?: boolean, tracerProvider?: TracerProvider, } = {} baseUrl?: URL } = {}, ): Promise<${getTypeNames(property.range, types)} | null> { const documentLoader = options.documentLoader ?? this._documentLoader ?? getDocumentLoader(); Loading @@ -76,6 +77,7 @@ async function* generateProperty( ${JSON.stringify(metadata.name)}, ${JSON.stringify(metadata.version)}, ); const baseUrl = options.baseUrl; return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => { let fetchResult: RemoteDocument; try { Loading @@ -99,7 +101,7 @@ async function* generateProperty( try { const obj = await this.#${property.singularName}_fromJsonLd( document, { documentLoader, contextLoader, tracerProvider } { documentLoader, contextLoader, tracerProvider, baseUrl } ); span.setAttribute("activitypub.object.id", (obj.id ?? url).href); span.setAttribute( Loading Loading @@ -133,6 +135,7 @@ async function* generateProperty( documentLoader?: DocumentLoader, contextLoader?: DocumentLoader, tracerProvider?: TracerProvider, baseUrl?: URL } ): Promise<${getTypeNames(property.range, types)}> { const documentLoader = Loading @@ -141,6 +144,7 @@ async function* generateProperty( options.contextLoader ?? this._contextLoader ?? getDocumentLoader(); const tracerProvider = options.tracerProvider ?? this._tracerProvider ?? trace.getTracerProvider(); const baseUrl = options.baseUrl; `; for (const range of property.range) { if (!(range in types)) continue; Loading @@ -149,7 +153,7 @@ async function* generateProperty( try { return await ${rangeType.name}.fromJsonLd( jsonLd, { documentLoader, contextLoader, tracerProvider }, { documentLoader, contextLoader, tracerProvider, baseUrl }, ); } catch (e) { if (!(e instanceof TypeError)) throw e; Loading Loading @@ -190,6 +194,7 @@ async function* generateProperty( contextLoader?: DocumentLoader, suppressError?: boolean, tracerProvider?: TracerProvider, baseUrl?: URL } = {} ): Promise<${getTypeNames(property.range, types)} | null> { if (this._warning != null) { Loading Loading @@ -221,7 +226,7 @@ async function* generateProperty( ${JSON.stringify(property.compactName)}]; const obj = Array.isArray(prop) ? prop[0] : prop; if (obj != null && typeof obj === "object" && "@context" in obj) { return await this.#${property.singularName}_fromJsonLd(obj, options); return await this.#${property.singularName}_fromJsonLd(obj, {...options, baseUrl: options.baseUrl}); } } `; Loading Loading @@ -258,6 +263,7 @@ async function* generateProperty( contextLoader?: DocumentLoader, suppressError?: boolean, tracerProvider?: TracerProvider, baseUrl?: URL } = {} ): AsyncIterable<${getTypeNames(property.range, types)}> { if (this._warning != null) { Loading @@ -272,7 +278,7 @@ async function* generateProperty( if (v instanceof URL) { const fetched = await this.#fetch${pascalCase(property.singularName)}( v, options); v, {...options, baseUrl: options.baseUrl}); if (fetched == null) continue; vs[i] = fetched; this._cachedJsonLd = undefined; Loading @@ -292,7 +298,8 @@ async function* generateProperty( ${JSON.stringify(property.compactName)}]; const obj = Array.isArray(prop) ? prop[i] : prop; if (obj != null && typeof obj === "object" && "@context" in obj) { yield await this.#${property.singularName}_fromJsonLd(obj, options); yield await this.#${property.singularName}_fromJsonLd(obj, {...options, baseUrl: options.baseUrl }); continue; } } Loading
packages/fedify/src/codegen/type.ts +12 −5 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ interface ScalarType { encoder(variable: string): string; compactEncoder?: (variable: string) => string; dataCheck(variable: string): string; decoder(variable: string): string; decoder(variable: string, baseUrlVar: string): string; } const scalarTypes: Record<string, ScalarType> = { Loading Loading @@ -141,9 +141,9 @@ const scalarTypes: Record<string, ScalarType> = { dataCheck(v) { return `typeof ${v} === "object" && "@id" in ${v} && typeof ${v}["@id"] === "string" && ${v}["@id"] !== "" && ${v}["@id"] !== "/"`; && ${v}["@id"] !== ""`; }, decoder(v) { decoder(v, baseUrlVar) { return `${v}["@id"].startsWith("at://") ? new URL("at://" + encodeURIComponent( Loading @@ -157,7 +157,9 @@ const scalarTypes: Record<string, ScalarType> = { : "" ) ) : new URL(${v}["@id"])`; : URL.canParse(${v}["@id"]) && ${baseUrlVar} ? new URL(${v}["@id"]) : new URL(${v}["@id"], ${baseUrlVar})`; }, }, "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString": { Loading Loading @@ -576,7 +578,12 @@ export function getDecoder( variable: string, optionsVariable: string, ): string { if (typeUri in scalarTypes) return scalarTypes[typeUri].decoder(variable); if (typeUri in scalarTypes) { return scalarTypes[typeUri].decoder( variable, `${optionsVariable}?.baseUrl`, ); } if (typeUri in types) { return `await ${types[typeUri].name}.fromJsonLd( ${variable}, ${optionsVariable})`; Loading