From 381073f3eb32d651697352a30183682695af95bb Mon Sep 17 00:00:00 2001 From: ajuvercr Date: Tue, 15 Oct 2024 10:50:31 +0200 Subject: [PATCH] fix: expose parserOptions more --- src/acl/acl.internal.ts | 11 ++++++----- src/acl/acl.ts | 3 ++- src/acp/acp.ts | 7 ++++--- src/profile/webid.ts | 20 ++++++++++++-------- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/acl/acl.internal.ts b/src/acl/acl.internal.ts index 3d30b5abdd..bc6f57c66e 100644 --- a/src/acl/acl.internal.ts +++ b/src/acl/acl.internal.ts @@ -23,14 +23,14 @@ import type { Quad } from "@rdfjs/types"; import { getSolidDataset } from "../resource/solidDataset"; import type { IriString, - WithChangeLog, Thing, + WithChangeLog, WithServerResourceInfo, } from "../interfaces"; import { - getSourceUrl, getResourceInfo, getSourceIri, + getSourceUrl, } from "../resource/resource"; import { acl, rdf } from "../constants"; import { DataFactory, subjectToRdfJsQuads } from "../rdfjs.internal"; @@ -57,6 +57,7 @@ import { removeAll, removeIri } from "../thing/remove"; import { freeze } from "../rdf.internal"; import { internal_cloneResource } from "../resource/resource.internal"; import { isAcr } from "../acp/acp.internal"; +import { ParserOptions } from "n3"; /** * This (currently internal) function fetches the ACL indicated in the [[WithServerResourceInfo]] @@ -68,7 +69,7 @@ import { isAcr } from "../acp/acp.internal"; */ export async function internal_fetchAcl( resourceInfo: WithServerResourceInfo, - options?: { fetch?: typeof fetch }, + options?: { fetch?: typeof fetch } & ParserOptions, ): Promise { if (!hasAccessibleAcl(resourceInfo)) { return { @@ -104,7 +105,7 @@ export async function internal_fetchAcl( /** @internal */ export async function internal_fetchResourceAcl( dataset: WithServerResourceInfo, - options?: { fetch?: typeof fetch }, + options?: { fetch?: typeof fetch } & ParserOptions, ): Promise { if (!hasAccessibleAcl(dataset)) { return null; @@ -136,7 +137,7 @@ export async function internal_fetchResourceAcl( /** @internal */ export async function internal_fetchFallbackAcl( resource: WithAccessibleAcl, - options?: { fetch?: typeof fetch }, + options?: { fetch?: typeof fetch } & ParserOptions, ): Promise { const resourceUrl = new URL(getSourceUrl(resource)); const resourcePath = resourceUrl.pathname; diff --git a/src/acl/acl.ts b/src/acl/acl.ts index 6aee565068..3edc074344 100644 --- a/src/acl/acl.ts +++ b/src/acl/acl.ts @@ -47,6 +47,7 @@ import { internal_setAcl, } from "./acl.internal"; import { freeze } from "../rdf.internal"; +import { ParserOptions } from "n3"; /** * ```{note} The Web Access Control specification is not yet finalised. As such, this @@ -114,7 +115,7 @@ export function hasResourceAcl< */ export async function getSolidDatasetWithAcl( url: UrlString | Url, - options?: { fetch?: typeof fetch }, + options?: { fetch?: typeof fetch } & ParserOptions, ): Promise { const solidDataset = await getSolidDataset(url, options); const acl = await internal_fetchAcl(solidDataset, options); diff --git a/src/acp/acp.ts b/src/acp/acp.ts index 746a748aa1..707786975b 100644 --- a/src/acp/acp.ts +++ b/src/acp/acp.ts @@ -47,6 +47,7 @@ import { import { internal_getAcr, internal_setAcr } from "./control.internal"; import { normalizeServerSideIri } from "../resource/iri.internal"; import { isAcr } from "./acp.internal"; +import { ParserOptions } from "n3"; /** * ```{note} The Web Access Control specification is not yet finalised. As such, this @@ -62,7 +63,7 @@ import { isAcr } from "./acp.internal"; */ export async function getSolidDatasetWithAcr( url: Url | UrlString, - options?: { fetch?: typeof fetch }, + options?: { fetch?: typeof fetch } & ParserOptions, ): Promise { const urlString = internal_toIriString(url); const solidDataset = await getSolidDataset(urlString, options); @@ -135,7 +136,7 @@ export async function getResourceInfoWithAcr( */ export async function getSolidDatasetWithAccessDatasets( url: Url | UrlString, - options?: { fetch?: typeof fetch }, + options?: { fetch?: typeof fetch } & ParserOptions, ): Promise { const urlString = internal_toIriString(url); const solidDataset = await getSolidDataset(urlString, options); @@ -266,7 +267,7 @@ export function hasAccessibleAcr( async function fetchAcr( resource: WithServerResourceInfo, - options?: { fetch?: typeof fetch }, + options?: { fetch?: typeof fetch } & ParserOptions, ): Promise { let acrUrl: UrlString | undefined; if (hasLinkedAcr(resource)) { diff --git a/src/profile/webid.ts b/src/profile/webid.ts index f014553ebd..6533bc28c2 100644 --- a/src/profile/webid.ts +++ b/src/profile/webid.ts @@ -19,6 +19,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // +import { ParserOptions } from "n3"; import type { SolidDataset, UrlString, @@ -90,11 +91,11 @@ export async function getProfileAll< options?: { fetch?: typeof fetch; webIdProfile?: T; - }, + } & ParserOptions, ): Promise>; export async function getProfileAll( webId: WebId, - options?: { fetch?: typeof fetch; webIdProfile: undefined }, + options?: { fetch?: typeof fetch; webIdProfile: undefined } & ParserOptions, ): Promise>; export async function getProfileAll< T extends SolidDataset & WithServerResourceInfo, @@ -103,17 +104,19 @@ export async function getProfileAll< options?: { fetch?: typeof fetch; webIdProfile?: T; - }, + } & ParserOptions, ): Promise> { - const authFetch = options?.fetch ?? fetch; + const unauthenticatedOptions = Object.assign({}, options); + delete unauthenticatedOptions["fetch"]; + const webIdProfile = options?.webIdProfile ?? // This should always use an unauthenticated fetch. - (await getSolidDataset(webId)); + (await getSolidDataset(webId, unauthenticatedOptions)); const altProfileAll = ( await Promise.allSettled( getAltProfileUrlAllFrom(webId, webIdProfile).map((uniqueProfileIri) => - getSolidDataset(uniqueProfileIri, { fetch: authFetch }), + getSolidDataset(uniqueProfileIri, options), ), ) ) @@ -147,7 +150,7 @@ export async function getProfileAll< */ export async function getPodUrlAll( webId: WebId, - options?: { fetch?: typeof fetch }, + options?: { fetch?: typeof fetch } & ParserOptions, ): Promise { const profiles = await getProfileAll(webId, options); return getPodUrlAllFrom(profiles, webId); @@ -201,6 +204,7 @@ export function getPodUrlAllFrom( */ export async function getWebIdDataset( webId: WebId, + options?: { fetch?: typeof fetch } & ParserOptions, ): Promise> { - return getSolidDataset(webId); + return getSolidDataset(webId, options); }