Skip to content

Commit

Permalink
fix: expose parserOptions more
Browse files Browse the repository at this point in the history
  • Loading branch information
ajuvercr committed Oct 15, 2024
1 parent a788a8f commit 381073f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
11 changes: 6 additions & 5 deletions src/acl/acl.internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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]]
Expand All @@ -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<WithAcl["internal_acl"]> {
if (!hasAccessibleAcl(resourceInfo)) {
return {
Expand Down Expand Up @@ -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<AclDataset | null> {
if (!hasAccessibleAcl(dataset)) {
return null;
Expand Down Expand Up @@ -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<AclDataset | null> {
const resourceUrl = new URL(getSourceUrl(resource));
const resourcePath = resourceUrl.pathname;
Expand Down
3 changes: 2 additions & 1 deletion src/acl/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,7 +115,7 @@ export function hasResourceAcl<
*/
export async function getSolidDatasetWithAcl(
url: UrlString | Url,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & ParserOptions,
): Promise<SolidDataset & WithServerResourceInfo & WithAcl> {
const solidDataset = await getSolidDataset(url, options);
const acl = await internal_fetchAcl(solidDataset, options);
Expand Down
7 changes: 4 additions & 3 deletions src/acp/acp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<SolidDataset & WithServerResourceInfo & WithAcp> {
const urlString = internal_toIriString(url);
const solidDataset = await getSolidDataset(urlString, options);
Expand Down Expand Up @@ -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<SolidDataset & (WithAcp | WithAcl)> {
const urlString = internal_toIriString(url);
const solidDataset = await getSolidDataset(urlString, options);
Expand Down Expand Up @@ -266,7 +267,7 @@ export function hasAccessibleAcr(

async function fetchAcr(
resource: WithServerResourceInfo,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & ParserOptions,
): Promise<WithAcp> {
let acrUrl: UrlString | undefined;
if (hasLinkedAcr(resource)) {
Expand Down
20 changes: 12 additions & 8 deletions src/profile/webid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { ParserOptions } from "n3";
import type {
SolidDataset,
UrlString,
Expand Down Expand Up @@ -90,11 +91,11 @@ export async function getProfileAll<
options?: {
fetch?: typeof fetch;
webIdProfile?: T;
},
} & ParserOptions,
): Promise<ProfileAll<T>>;
export async function getProfileAll(
webId: WebId,
options?: { fetch?: typeof fetch; webIdProfile: undefined },
options?: { fetch?: typeof fetch; webIdProfile: undefined } & ParserOptions,
): Promise<ProfileAll<SolidDataset & WithServerResourceInfo>>;
export async function getProfileAll<
T extends SolidDataset & WithServerResourceInfo,
Expand All @@ -103,17 +104,19 @@ export async function getProfileAll<
options?: {
fetch?: typeof fetch;
webIdProfile?: T;
},
} & ParserOptions,
): Promise<ProfileAll<T | (SolidDataset & WithServerResourceInfo)>> {
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),
),
)
)
Expand Down Expand Up @@ -147,7 +150,7 @@ export async function getProfileAll<
*/
export async function getPodUrlAll(
webId: WebId,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & ParserOptions,
): Promise<UrlString[]> {
const profiles = await getProfileAll(webId, options);
return getPodUrlAllFrom(profiles, webId);
Expand Down Expand Up @@ -201,6 +204,7 @@ export function getPodUrlAllFrom(
*/
export async function getWebIdDataset(
webId: WebId,
options?: { fetch?: typeof fetch } & ParserOptions,
): Promise<ReturnType<typeof getSolidDataset>> {
return getSolidDataset(webId);
return getSolidDataset(webId, options);
}

0 comments on commit 381073f

Please sign in to comment.