Loading packages/fedify/src/runtime/authdocloader.ts +5 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import { createRequest, type DocumentLoader, type DocumentLoaderFactoryOptions, type DocumentLoaderOptions, getRemoteDocument, logRequest, type RemoteDocument, Loading Loading @@ -58,7 +59,10 @@ export function getAuthenticatedDocumentLoader( GetAuthenticatedDocumentLoaderOptions = {}, ): DocumentLoader { validateCryptoKey(identity.privateKey); async function load(url: string): Promise<RemoteDocument> { async function load( url: string, _options?: DocumentLoaderOptions, ): Promise<RemoteDocument> { if (!allowPrivateAddress) { try { await validatePublicUrl(url); Loading packages/fedify/src/runtime/docloader.ts +38 −7 Original line number Diff line number Diff line Loading @@ -29,12 +29,24 @@ export interface RemoteDocument { documentUrl: string; } /** * Options for {@link DocumentLoader}. * @since 1.8.0 */ export interface DocumentLoaderOptions { signal?: AbortSignal; } /** * A JSON-LD document loader that fetches documents from the Web. * @param url The URL of the document to load. * @param options The options for the document loader. * @returns The loaded remote document. */ export type DocumentLoader = (url: string) => Promise<RemoteDocument>; export type DocumentLoader = ( url: string, options?: DocumentLoaderOptions, ) => Promise<RemoteDocument>; /** * A factory function that creates a {@link DocumentLoader} with options. Loading Loading @@ -163,7 +175,10 @@ export function logRequest(request: Request) { export async function getRemoteDocument( url: string, response: Response, fetch: (url: string) => Promise<RemoteDocument>, fetch: ( url: string, options?: DocumentLoaderOptions, ) => Promise<RemoteDocument>, ): Promise<RemoteDocument> { const documentUrl = response.url === "" ? url : response.url; const docUrl = new URL(documentUrl); Loading Loading @@ -311,7 +326,10 @@ export function getDocumentLoader( { allowPrivateAddress, skipPreloadedContexts, userAgent }: GetDocumentLoaderOptions = {}, ): DocumentLoader { async function load(url: string): Promise<RemoteDocument> { async function load( url: string, _options?: DocumentLoaderOptions, ): Promise<RemoteDocument> { if (!skipPreloadedContexts && url in preloadedContexts) { logger.debug("Using preloaded context: {url}.", { url }); return { Loading Loading @@ -375,15 +393,25 @@ const _fetchDocumentLoader_allowPrivateAddress = getDocumentLoader({ */ export function fetchDocumentLoader( url: string, allowPrivateAddress: boolean = false, allowPrivateAddress?: boolean, ): Promise<RemoteDocument>; export function fetchDocumentLoader( url: string, options?: DocumentLoaderOptions, ): Promise<RemoteDocument>; export function fetchDocumentLoader( url: string, arg: boolean | DocumentLoaderOptions = false, ): Promise<RemoteDocument> { const allowPrivateAddress = typeof arg === "boolean" ? arg : false; logger.warn( "fetchDocumentLoader() function is deprecated. " + "Use getDocumentLoader() function instead.", ); return (allowPrivateAddress const loader = allowPrivateAddress ? _fetchDocumentLoader_allowPrivateAddress : _fetchDocumentLoader)(url); : _fetchDocumentLoader; return loader(url); } /** Loading Loading @@ -455,7 +483,10 @@ export function kvCache( return null; } return async (url: string): Promise<RemoteDocument> => { return async ( url: string, _options?: DocumentLoaderOptions, ): Promise<RemoteDocument> => { const match = matchRule(url); if (match == null) return await loader(url); const key: KvKey = [...keyPrefix, url]; Loading packages/fedify/src/testing/docloader.ts +5 −1 Original line number Diff line number Diff line import { getLogger } from "@logtape/logtape"; import type { RemoteDocument } from "../runtime/docloader.ts"; import type { DocumentLoaderOptions, RemoteDocument, } from "../runtime/docloader.ts"; const logger = getLogger(["fedify", "testing", "docloader"]); Loading @@ -13,6 +16,7 @@ const logger = getLogger(["fedify", "testing", "docloader"]); */ export async function mockDocumentLoader( resource: string, _options?: DocumentLoaderOptions, ): Promise<RemoteDocument> { const url = new URL(resource); if ( Loading Loading
packages/fedify/src/runtime/authdocloader.ts +5 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ import { createRequest, type DocumentLoader, type DocumentLoaderFactoryOptions, type DocumentLoaderOptions, getRemoteDocument, logRequest, type RemoteDocument, Loading Loading @@ -58,7 +59,10 @@ export function getAuthenticatedDocumentLoader( GetAuthenticatedDocumentLoaderOptions = {}, ): DocumentLoader { validateCryptoKey(identity.privateKey); async function load(url: string): Promise<RemoteDocument> { async function load( url: string, _options?: DocumentLoaderOptions, ): Promise<RemoteDocument> { if (!allowPrivateAddress) { try { await validatePublicUrl(url); Loading
packages/fedify/src/runtime/docloader.ts +38 −7 Original line number Diff line number Diff line Loading @@ -29,12 +29,24 @@ export interface RemoteDocument { documentUrl: string; } /** * Options for {@link DocumentLoader}. * @since 1.8.0 */ export interface DocumentLoaderOptions { signal?: AbortSignal; } /** * A JSON-LD document loader that fetches documents from the Web. * @param url The URL of the document to load. * @param options The options for the document loader. * @returns The loaded remote document. */ export type DocumentLoader = (url: string) => Promise<RemoteDocument>; export type DocumentLoader = ( url: string, options?: DocumentLoaderOptions, ) => Promise<RemoteDocument>; /** * A factory function that creates a {@link DocumentLoader} with options. Loading Loading @@ -163,7 +175,10 @@ export function logRequest(request: Request) { export async function getRemoteDocument( url: string, response: Response, fetch: (url: string) => Promise<RemoteDocument>, fetch: ( url: string, options?: DocumentLoaderOptions, ) => Promise<RemoteDocument>, ): Promise<RemoteDocument> { const documentUrl = response.url === "" ? url : response.url; const docUrl = new URL(documentUrl); Loading Loading @@ -311,7 +326,10 @@ export function getDocumentLoader( { allowPrivateAddress, skipPreloadedContexts, userAgent }: GetDocumentLoaderOptions = {}, ): DocumentLoader { async function load(url: string): Promise<RemoteDocument> { async function load( url: string, _options?: DocumentLoaderOptions, ): Promise<RemoteDocument> { if (!skipPreloadedContexts && url in preloadedContexts) { logger.debug("Using preloaded context: {url}.", { url }); return { Loading Loading @@ -375,15 +393,25 @@ const _fetchDocumentLoader_allowPrivateAddress = getDocumentLoader({ */ export function fetchDocumentLoader( url: string, allowPrivateAddress: boolean = false, allowPrivateAddress?: boolean, ): Promise<RemoteDocument>; export function fetchDocumentLoader( url: string, options?: DocumentLoaderOptions, ): Promise<RemoteDocument>; export function fetchDocumentLoader( url: string, arg: boolean | DocumentLoaderOptions = false, ): Promise<RemoteDocument> { const allowPrivateAddress = typeof arg === "boolean" ? arg : false; logger.warn( "fetchDocumentLoader() function is deprecated. " + "Use getDocumentLoader() function instead.", ); return (allowPrivateAddress const loader = allowPrivateAddress ? _fetchDocumentLoader_allowPrivateAddress : _fetchDocumentLoader)(url); : _fetchDocumentLoader; return loader(url); } /** Loading Loading @@ -455,7 +483,10 @@ export function kvCache( return null; } return async (url: string): Promise<RemoteDocument> => { return async ( url: string, _options?: DocumentLoaderOptions, ): Promise<RemoteDocument> => { const match = matchRule(url); if (match == null) return await loader(url); const key: KvKey = [...keyPrefix, url]; Loading
packages/fedify/src/testing/docloader.ts +5 −1 Original line number Diff line number Diff line import { getLogger } from "@logtape/logtape"; import type { RemoteDocument } from "../runtime/docloader.ts"; import type { DocumentLoaderOptions, RemoteDocument, } from "../runtime/docloader.ts"; const logger = getLogger(["fedify", "testing", "docloader"]); Loading @@ -13,6 +16,7 @@ const logger = getLogger(["fedify", "testing", "docloader"]); */ export async function mockDocumentLoader( resource: string, _options?: DocumentLoaderOptions, ): Promise<RemoteDocument> { const url = new URL(resource); if ( Loading