Skip to content

Commit

Permalink
remove universal fetch dep (#2281)
Browse files Browse the repository at this point in the history
* WIP: remove universal fetch dep

* chore: remove unused dependencies

* WIP: removing universal fetch

* chore: fix all broken tests

* chore: fix test coverage

* chore: update changelog
  • Loading branch information
jeswr authored Dec 13, 2023
1 parent cb25776 commit 5f23fc9
Show file tree
Hide file tree
Showing 37 changed files with 974 additions and 2,108 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ The following changes are pending, and will be applied on the next major release

The following changes have been implemented but not released yet:

### Breaking Changes

- Use the global `fetch` function instead of `@inrupt/universal-fetch`. This means this library now only works
with Node 18 and higher.

## [1.30.2] - 2023-09-26

### Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Pods.
[@inrupt/solid-client-authn-browser](https://www.npmjs.com/package/@inrupt/solid-client-authn-browser)
allows apps running in a browser to authenticate against a Solid server. This is
only necessary if you wish to access private resources in a Pod (to access
public resources you could simply use standard `window.fetch()`).
public resources you could simply use standard `fetch()`).

## Vocabularies and interoperability

Expand Down
21 changes: 13 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@inrupt/universal-fetch": "^1.0.1",
"@rdfjs/dataset": "^1.1.0",
"@types/rdfjs__dataset": "^1.0.4",
"buffer": "^6.0.3",
Expand Down
5 changes: 2 additions & 3 deletions src/access/acp_v1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import { jest, describe, it, expect } from "@jest/globals";
import * as fc from "fast-check";
import { Response } from "@inrupt/universal-fetch";
import type { WithAccessibleAcr } from "../acp/acp";
import type { AccessControlResource } from "../acp/control";
import {
Expand Down Expand Up @@ -8454,12 +8453,12 @@ describe("getPoliciesAndRules", () => {
expect(solidDatasetModule.getSolidDataset).toHaveBeenNthCalledWith(
1,
"https://some.pod/policy-resource",
expect.anything(),
undefined,
);
expect(solidDatasetModule.getSolidDataset).toHaveBeenNthCalledWith(
2,
"https://some.pod/rule-resource",
expect.anything(),
undefined,
);
});

Expand Down
5 changes: 2 additions & 3 deletions src/access/acp_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//
import { v4 as uuidv4 } from "uuid";
import { acp } from "../constants";
import { internal_defaultFetchOptions } from "../resource/resource";
import { asIri, getThing } from "../thing/thing";
import type { WithAccessibleAcr, WithAcp } from "../acp/acp";
import { hasAccessibleAcr } from "../acp/acp";
Expand Down Expand Up @@ -1051,7 +1050,7 @@ export type internal_AcpData = {

export async function internal_getPoliciesAndRules(
resource: WithResourceInfo & WithAccessibleAcr,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<internal_AcpData> {
const acrPolicyUrls = getAcrPolicyUrlAll(resource);
const policyUrls = getPolicyUrlAll(resource);
Expand Down Expand Up @@ -1130,7 +1129,7 @@ function getResourceUrls(thingUrls: UrlString[]): UrlString[] {

async function getResources(
resourceUrls: UrlString[],
options: typeof internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Record<UrlString, (SolidDataset & WithServerResourceInfo) | null>> {
const uniqueResourceUrls = Array.from(new Set(resourceUrls));
const resources: Record<
Expand Down
5 changes: 2 additions & 3 deletions src/access/acp_v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import { jest, describe, it, expect } from "@jest/globals";
import * as fc from "fast-check";
import { Response } from "@inrupt/universal-fetch";
import type { WithAccessibleAcr } from "../acp/acp";
import type { AccessControlResource } from "../acp/control";
import {
Expand Down Expand Up @@ -7662,12 +7661,12 @@ describe("getPoliciesAndMatchers", () => {
expect(solidDatasetModule.getSolidDataset).toHaveBeenNthCalledWith(
1,
"https://some.pod/policy-resource",
expect.anything(),
undefined,
);
expect(solidDatasetModule.getSolidDataset).toHaveBeenNthCalledWith(
2,
"https://some.pod/matcher-resource",
expect.anything(),
undefined,
);
});

Expand Down
5 changes: 2 additions & 3 deletions src/access/acp_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//
import { v4 as uuidv4 } from "uuid";
import { acp } from "../constants";
import { internal_defaultFetchOptions } from "../resource/resource";
import { asIri, getThing } from "../thing/thing";
import type { WithAccessibleAcr, WithAcp } from "../acp/acp";
import { hasAccessibleAcr } from "../acp/acp";
Expand Down Expand Up @@ -969,7 +968,7 @@ export type internal_AcpData = {

export async function internal_getPoliciesAndMatchers(
resource: WithResourceInfo & WithAccessibleAcr,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<internal_AcpData> {
const acrPolicyUrls = getAcrPolicyUrlAll(resource);
const policyUrls = getPolicyUrlAll(resource);
Expand Down Expand Up @@ -1053,7 +1052,7 @@ function getResourceUrls(thingUrls: UrlString[]): UrlString[] {

async function getResources(
resourceUrls: UrlString[],
options: typeof internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Record<UrlString, (SolidDataset & WithServerResourceInfo) | null>> {
const uniqueResourceUrls = Array.from(new Set(resourceUrls));
const resources: Record<
Expand Down
35 changes: 14 additions & 21 deletions src/access/for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//

import type { UrlString, WebId } from "../interfaces";
import { internal_defaultFetchOptions } from "../resource/resource";
import type { Access } from "./universal";
import {
getAgentAccess,
Expand Down Expand Up @@ -72,7 +71,7 @@ export async function getAccessFor(
resourceUrl: UrlString,
actorType: "agent" | "group",
actor: UrlString | WebId,
options?: typeof internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null>;
/**
* Get an overview of what access is defined for everyone.
Expand Down Expand Up @@ -106,22 +105,19 @@ export async function getAccessFor(
export async function getAccessFor(
resourceUrl: UrlString,
actorType: "public",
options?: typeof internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null>;
export async function getAccessFor(
resourceUrl: UrlString,
actorType: Actor,
actor?: WebId | UrlString | typeof internal_defaultFetchOptions,
options?: typeof internal_defaultFetchOptions,
actor?: WebId | UrlString | { fetch?: typeof fetch },
options?: { fetch?: typeof fetch },
): Promise<Access | null>;
export async function getAccessFor(
resourceUrl: UrlString,
actorType: Actor,
actor:
| WebId
| UrlString
| typeof internal_defaultFetchOptions = internal_defaultFetchOptions,
options = internal_defaultFetchOptions,
actor?: WebId | UrlString | { fetch?: typeof fetch },
options?: { fetch?: typeof fetch },
): Promise<Access | null> {
if (actorType === "agent") {
if (typeof actor !== "string") {
Expand Down Expand Up @@ -182,7 +178,7 @@ export async function getAccessFor(
export async function getAccessForAll(
resourceUrl: UrlString,
actorType: Exclude<Actor, "public">,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Record<UrlString, Access> | null> {
if (actorType === "agent") {
return getAgentAccessAll(resourceUrl, options);
Expand Down Expand Up @@ -238,7 +234,7 @@ export async function setAccessFor(
actorType: "agent" | "group",
access: Partial<Access>,
actor: UrlString | WebId,
options?: typeof internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null>;
/**
* Set access to a Resource for everyone.
Expand Down Expand Up @@ -283,24 +279,21 @@ export async function setAccessFor(
resourceUrl: UrlString,
actorType: "public",
access: Partial<Access>,
options?: typeof internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null>;
export async function setAccessFor(
resourceUrl: UrlString,
actorType: Actor,
access: Partial<Access>,
actor?: WebId | UrlString | typeof internal_defaultFetchOptions,
options?: typeof internal_defaultFetchOptions,
actor?: WebId | UrlString | { fetch?: typeof fetch },
options?: { fetch?: typeof fetch },
): Promise<Access | null>;
export async function setAccessFor(
resourceUrl: UrlString,
actorType: Actor,
access: Partial<Access>,
actor:
| WebId
| UrlString
| typeof internal_defaultFetchOptions = internal_defaultFetchOptions,
options = internal_defaultFetchOptions,
actor?: WebId | UrlString | { fetch?: typeof fetch },
options?: { fetch?: typeof fetch },
): Promise<Access | null> {
if (actorType === "agent") {
if (typeof actor !== "string") {
Expand All @@ -326,5 +319,5 @@ export async function setAccessFor(
}
return setPublicAccess(resourceUrl, access, actor);
}
return null as never;
return null;
}
21 changes: 9 additions & 12 deletions src/access/universal_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ import {
saveAcrFor,
} from "../acp/acp";
import type { UrlString, WebId } from "../interfaces";
import {
getSourceIri,
internal_defaultFetchOptions,
} from "../resource/resource";
import { getSourceIri } from "../resource/resource";
import {
internal_getAgentAccess as getAgentAccessAcp,
internal_getAgentAccessAll as getAgentAccessAllAcp,
Expand Down Expand Up @@ -98,7 +95,7 @@ export interface Access {
export async function getAgentAccess(
resourceUrl: UrlString,
webId: WebId,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null> {
const resourceInfo = await getResourceInfoWithAcr(resourceUrl, options);
if (hasAccessibleAcr(resourceInfo)) {
Expand Down Expand Up @@ -151,7 +148,7 @@ export async function setAgentAccess(
resourceUrl: UrlString,
webId: WebId,
access: Partial<Access>,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null> {
const resourceInfo = await getResourceInfoWithAcr(resourceUrl, options);
if (hasAccessibleAcr(resourceInfo)) {
Expand Down Expand Up @@ -216,7 +213,7 @@ export async function setAgentAccess(
*/
export async function getAgentAccessAll(
resourceUrl: UrlString,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Record<WebId, Access> | null> {
const resourceInfo = await getResourceInfoWithAcr(resourceUrl, options);
if (hasAccessibleAcr(resourceInfo)) {
Expand Down Expand Up @@ -258,7 +255,7 @@ export async function getAgentAccessAll(
export async function getGroupAccess(
resourceUrl: UrlString,
webId: WebId,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null> {
const resourceInfo = await getResourceInfoWithAcr(resourceUrl, options);
if (hasAccessibleAcr(resourceInfo)) {
Expand Down Expand Up @@ -300,7 +297,7 @@ export async function getGroupAccess(
*/
export async function getGroupAccessAll(
resourceUrl: UrlString,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Record<UrlString, Access> | null> {
const resourceInfo = await getResourceInfoWithAcr(resourceUrl, options);
if (hasAccessibleAcr(resourceInfo)) {
Expand Down Expand Up @@ -353,7 +350,7 @@ export async function setGroupAccess(
resourceUrl: UrlString,
groupUrl: UrlString,
access: Partial<Access>,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null> {
const resourceInfo = await getResourceInfoWithAcr(resourceUrl, options);
if (hasAccessibleAcr(resourceInfo)) {
Expand Down Expand Up @@ -417,7 +414,7 @@ export async function setGroupAccess(
*/
export async function getPublicAccess(
resourceUrl: UrlString,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null> {
const resourceInfo = await getResourceInfoWithAcr(resourceUrl, options);
if (hasAccessibleAcr(resourceInfo)) {
Expand Down Expand Up @@ -469,7 +466,7 @@ export async function getPublicAccess(
export async function setPublicAccess(
resourceUrl: UrlString,
access: Partial<Access>,
options = internal_defaultFetchOptions,
options?: { fetch?: typeof fetch },
): Promise<Access | null> {
const resourceInfo = await getResourceInfoWithAcr(resourceUrl, options);
if (hasAccessibleAcr(resourceInfo)) {
Expand Down
Loading

1 comment on commit 5f23fc9

@vercel
Copy link

@vercel vercel bot commented on 5f23fc9 Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

solid-client-js – ./

solid-client.vercel.app
solid-client-js-inrupt.vercel.app
solid-client-js-git-main-inrupt.vercel.app

Please sign in to comment.