Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expose parserOptions more #2530

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/acl/acl.internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
//

import type { Quad } from "@rdfjs/types";
import { getSolidDataset } from "../resource/solidDataset";
import { getSolidDataset, ParseOptions } 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 Down Expand Up @@ -68,7 +68,7 @@ import { isAcr } from "../acp/acp.internal";
*/
export async function internal_fetchAcl(
resourceInfo: WithServerResourceInfo,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & Partial<ParseOptions>,
): Promise<WithAcl["internal_acl"]> {
if (!hasAccessibleAcl(resourceInfo)) {
return {
Expand Down Expand Up @@ -104,7 +104,7 @@ export async function internal_fetchAcl(
/** @internal */
export async function internal_fetchResourceAcl(
dataset: WithServerResourceInfo,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & Partial<ParseOptions>,
): Promise<AclDataset | null> {
if (!hasAccessibleAcl(dataset)) {
return null;
Expand Down Expand Up @@ -136,7 +136,7 @@ export async function internal_fetchResourceAcl(
/** @internal */
export async function internal_fetchFallbackAcl(
resource: WithAccessibleAcl,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & Partial<ParseOptions>,
): 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 @@ -23,6 +23,7 @@ import { acl } from "../constants";
import {
createSolidDataset,
getSolidDataset,
ParseOptions,
saveSolidDatasetAt,
} from "../resource/solidDataset";
import type {
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 } & Partial<ParseOptions>,
): Promise<SolidDataset & WithServerResourceInfo & WithAcl> {
const solidDataset = await getSolidDataset(url, options);
const acl = await internal_fetchAcl(solidDataset, options);
Expand Down
8 changes: 4 additions & 4 deletions src/acp/acp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { getResourceInfo, getSourceUrl } from "../resource/resource";
import type { WithAcl } from "../acl/acl";
import { hasAccessibleAcl } from "../acl/acl";
import { internal_fetchAcl, internal_setAcl } from "../acl/acl.internal";
import { getSolidDataset, saveSolidDatasetAt } from "../resource/solidDataset";
import { getSolidDataset, ParseOptions, saveSolidDatasetAt } from "../resource/solidDataset";
import type { AccessControlResource } from "./control";
import {
getAcrPolicyUrlAll,
Expand All @@ -62,7 +62,7 @@ import { isAcr } from "./acp.internal";
*/
export async function getSolidDatasetWithAcr(
url: Url | UrlString,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & Partial<ParseOptions>,
): Promise<SolidDataset & WithServerResourceInfo & WithAcp> {
const urlString = internal_toIriString(url);
const solidDataset = await getSolidDataset(urlString, options);
Expand Down Expand Up @@ -135,7 +135,7 @@ export async function getResourceInfoWithAcr(
*/
export async function getSolidDatasetWithAccessDatasets(
url: Url | UrlString,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & Partial<ParseOptions>,
): Promise<SolidDataset & (WithAcp | WithAcl)> {
const urlString = internal_toIriString(url);
const solidDataset = await getSolidDataset(urlString, options);
Expand Down Expand Up @@ -266,7 +266,7 @@ export function hasAccessibleAcr(

async function fetchAcr(
resource: WithServerResourceInfo,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & Partial<ParseOptions>,
): Promise<WithAcp> {
let acrUrl: UrlString | undefined;
if (hasLinkedAcr(resource)) {
Expand Down
23 changes: 15 additions & 8 deletions src/profile/webid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
//

import type {
ParseOptions,
SolidDataset,
UrlString,
WebId,
Expand Down Expand Up @@ -90,11 +91,14 @@ export async function getProfileAll<
options?: {
fetch?: typeof fetch;
webIdProfile?: T;
},
} & Partial<ParseOptions>,
): Promise<ProfileAll<T>>;
export async function getProfileAll(
webId: WebId,
options?: { fetch?: typeof fetch; webIdProfile: undefined },
options?: {
fetch?: typeof fetch;
webIdProfile: undefined;
} & Partial<ParseOptions>,
): Promise<ProfileAll<SolidDataset & WithServerResourceInfo>>;
export async function getProfileAll<
T extends SolidDataset & WithServerResourceInfo,
Expand All @@ -103,17 +107,19 @@ export async function getProfileAll<
options?: {
fetch?: typeof fetch;
webIdProfile?: T;
},
} & Partial<ParseOptions>,
): 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 +153,7 @@ export async function getProfileAll<
*/
export async function getPodUrlAll(
webId: WebId,
options?: { fetch?: typeof fetch },
options?: { fetch?: typeof fetch } & Partial<ParseOptions>,
): Promise<UrlString[]> {
const profiles = await getProfileAll(webId, options);
return getPodUrlAllFrom(profiles, webId);
Expand Down Expand Up @@ -201,6 +207,7 @@ export function getPodUrlAllFrom(
*/
export async function getWebIdDataset(
webId: WebId,
options?: { fetch?: typeof fetch } & Partial<ParseOptions>,
): Promise<ReturnType<typeof getSolidDataset>> {
return getSolidDataset(webId);
return getSolidDataset(webId, options);
}
4 changes: 2 additions & 2 deletions src/resource/solidDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export async function responseToSolidDataset(
*/
export async function getSolidDataset(
url: UrlString | Url,
options?: Partial<{ fetch: typeof fetch } & ParseOptions>,
options?: Partial<{ fetch: typeof fetch } & Partial<ParseOptions>>,
): Promise<SolidDataset & WithServerResourceInfo> {
const normalizedUrl = normalizeUrl(internal_toIriString(url));
const parserContentTypes = Object.keys(options?.parsers ?? {});
Expand Down Expand Up @@ -1151,7 +1151,7 @@ function resolveLocalIrisInThing(
*/
export async function getWellKnownSolid(
url: UrlString | Url,
options?: Partial<{ fetch?: typeof fetch } & ParseOptions>,
options?: Partial<{ fetch?: typeof fetch } & Partial<ParseOptions>>,
): Promise<SolidDataset & WithServerResourceInfo> {
const urlString = internal_toIriString(url);

Expand Down