Skip to content

Commit

Permalink
chore: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Nov 27, 2023
1 parent c4fa721 commit 9affa28
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 156 deletions.
2 changes: 1 addition & 1 deletion src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const solidVc = {
SolidAccessRequest: namedNode(`${VC}SolidAccessRequest`),
SolidAccessGrant: namedNode(`${VC}SolidAccessGrant`),
SolidAccessDenial: namedNode(`${VC}SolidAccessDenial`),
}
};

export const gc = {
providedConsent: namedNode(`${GC}providedConsent`),
Expand Down
61 changes: 21 additions & 40 deletions src/common/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import type { DatasetWithId } from "@inrupt/solid-client-vc";
import {
getCredentialSubject,
getExpirationDate,
getId,
getIssuanceDate,
getIssuer,
} from "@inrupt/solid-client-vc";

Check failure on line 28 in src/common/getters.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Unable to resolve path to module '@inrupt/solid-client-vc'
import type {
BlankNode,
DatasetCore,
Expand All @@ -26,18 +34,9 @@ import type {
Term,
} from "@rdfjs/types";
import { DataFactory } from "n3";
import {
getId,
getCredentialSubject,
getIssuer,
getIssuanceDate,
getExpirationDate,
DatasetWithId,
} from "@inrupt/solid-client-vc";
import type { AccessGrantGConsent } from "../gConsent/type/AccessGrant";
import type { AccessRequestGConsent } from "../gConsent/type/AccessRequest";
import type { AccessModes } from "../type/AccessModes";
import { INHERIT, XSD_BOOLEAN, gc, acl, TYPE } from "./constants";
import { INHERIT, TYPE, XSD_BOOLEAN, acl, gc } from "./constants";

const { namedNode, defaultGraph, quad, literal } = DataFactory;

Expand Down Expand Up @@ -118,11 +117,11 @@ function getSingleObject(
return object;
}
export {
getId,
getIssuer,
getIssuanceDate,
getCredentialSubject,
getExpirationDate,
getId,
getIssuanceDate,
getIssuer,
};

/**
Expand Down Expand Up @@ -160,9 +159,7 @@ export function getConsent(vc: DatasetWithId) {
* @param vc The Access Grant/Request
* @returns The resources IRIs
*/
export function getResources(
vc: DatasetWithId,
): string[] {
export function getResources(vc: DatasetWithId): string[] {
const resources: string[] = [];

for (const { object } of vc.match(
Expand Down Expand Up @@ -194,9 +191,7 @@ export function getResources(
* @param vc The Access Grant/Request
* @returns The purpose IRIs
*/
export function getPurposes(
vc: DatasetWithId,
): string[] {
export function getPurposes(vc: DatasetWithId): string[] {
const consent = getConsent(vc);
const purposes: string[] = [];

Expand All @@ -217,9 +212,7 @@ export function getPurposes(
return purposes;
}

export function isGConsentAccessGrant(
vc: DatasetWithId,
): boolean {
export function isGConsentAccessGrant(vc: DatasetWithId): boolean {
const credentialSubject = getCredentialSubject(vc);
const providedConsent = getSingleObject(
vc,
Expand Down Expand Up @@ -263,12 +256,8 @@ export function isGConsentAccessGrant(
* @returns The resource owner WebID
*/
export function getResourceOwner(vc: AccessGrantGConsent): string;
export function getResourceOwner(
vc: DatasetWithId,
): string | undefined;
export function getResourceOwner(
vc: DatasetWithId,
): string | undefined {
export function getResourceOwner(vc: DatasetWithId): string | undefined;
export function getResourceOwner(vc: DatasetWithId): string | undefined {
const credentialSubject = getCredentialSubject(vc);
if (isGConsentAccessGrant(vc)) {
return credentialSubject.value;
Expand All @@ -294,9 +283,7 @@ export function getResourceOwner(
* @param vc The Access Grant/Request
* @returns The requestor WebID
*/
export function getRequestor(
vc: DatasetWithId,
): string {
export function getRequestor(vc: DatasetWithId): string {
const credentialSubject = getCredentialSubject(vc);
const providedConsent = getSingleObject(
vc,
Expand Down Expand Up @@ -324,9 +311,7 @@ export function getRequestor(
* @param vc The Access Grant/Request
* @returns The access modes the grant recipient can exercise.
*/
export function getAccessModes(
vc: DatasetWithId,
): AccessModes {
export function getAccessModes(vc: DatasetWithId): AccessModes {
const consent = getConsent(vc);
return {
read: vc.has(quad(consent, acl.mode, acl.Read, defaultGraph())),
Expand Down Expand Up @@ -357,9 +342,7 @@ const shorthand = {
* @param vc The Access Grant/Request
* @returns The VC types
*/
export function getTypes(
vc: DatasetWithId,
): string[] {
export function getTypes(vc: DatasetWithId): string[] {
const results = [
...vc.match(namedNode(getId(vc)), TYPE, undefined, defaultGraph()),
].map((res) => res.object);
Expand Down Expand Up @@ -393,9 +376,7 @@ export function getTypes(
* @param vc The Access Grant/Request
* @returns true if the Grant applies to contained resources, false otherwise.
*/
export function getInherit(
vc: DatasetWithId,
): boolean {
export function getInherit(vc: DatasetWithId): boolean {
return !vc.has(
quad(
getConsent(vc),
Expand Down
39 changes: 22 additions & 17 deletions src/gConsent/guard/isBaseAccessGrantVerifiableCredential.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
//

import { it, describe, expect } from "@jest/globals";
import { isBaseAccessGrantVerifiableCredential, isRdfjsBaseAccessGrantVerifiableCredential } from "./isBaseAccessGrantVerifiableCredential";
import { verifiableCredentialToDataset } from "@inrupt/solid-client-vc";

Check failure on line 23 in src/gConsent/guard/isBaseAccessGrantVerifiableCredential.test.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Unable to resolve path to module '@inrupt/solid-client-vc'
import {
isBaseAccessGrantVerifiableCredential,
isRdfjsBaseAccessGrantVerifiableCredential,
} from "./isBaseAccessGrantVerifiableCredential";

const validAccessGrantVerifiableCredential = {
"@context": [
Expand Down Expand Up @@ -64,7 +67,9 @@ describe("isBaseAccessGrantVerifiableCredential", () => {
).toBe(true);
expect(
isRdfjsBaseAccessGrantVerifiableCredential(
await verifiableCredentialToDataset(validAccessGrantVerifiableCredential),
await verifiableCredentialToDataset(
validAccessGrantVerifiableCredential,
),
),
).toBe(true);
});
Expand All @@ -80,12 +85,12 @@ describe("isBaseAccessGrantVerifiableCredential", () => {
forPersonalData: ["https://example.pod/resourceX", {}],
},
},
}
expect(
isBaseAccessGrantVerifiableCredential(vc),
).toBe(false);
};
expect(isBaseAccessGrantVerifiableCredential(vc)).toBe(false);
expect(
isRdfjsBaseAccessGrantVerifiableCredential(await verifiableCredentialToDataset(vc)),
isRdfjsBaseAccessGrantVerifiableCredential(
await verifiableCredentialToDataset(vc),
),
).toBe(false);
});

Expand All @@ -94,32 +99,32 @@ describe("isBaseAccessGrantVerifiableCredential", () => {
...validAccessGrantVerifiableCredential,
issuanceDate: [],
};
expect(isBaseAccessGrantVerifiableCredential(vc)).toBe(false);
expect(
isBaseAccessGrantVerifiableCredential(vc),
).toBe(false);
expect(
isRdfjsBaseAccessGrantVerifiableCredential(await verifiableCredentialToDataset(vc)),
isRdfjsBaseAccessGrantVerifiableCredential(
await verifiableCredentialToDataset(vc),
),
).toBe(false);
});

it("Returns true on undefined issuance date", async () => {
const vc = {
...validAccessGrantVerifiableCredential,
issuanceDate: undefined,
}
expect(
isBaseAccessGrantVerifiableCredential(vc),
).toBe(true);
};
expect(isBaseAccessGrantVerifiableCredential(vc)).toBe(true);
});

// FIXME: Work out why undefined issuance dates are allowed when they are required in the VC type
it.skip("Returns true on undefined issuance date in RDFJS", async () => {

Check warning on line 119 in src/gConsent/guard/isBaseAccessGrantVerifiableCredential.test.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Disabled test
const vc = {
...validAccessGrantVerifiableCredential,
issuanceDate: undefined,
}
};
expect(
isRdfjsBaseAccessGrantVerifiableCredential(await verifiableCredentialToDataset(vc)),
isRdfjsBaseAccessGrantVerifiableCredential(
await verifiableCredentialToDataset(vc),
),
).toBe(true);
});
});
29 changes: 19 additions & 10 deletions src/gConsent/guard/isBaseAccessGrantVerifiableCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import type { DatasetWithId } from "@inrupt/solid-client-vc";
import { getId, getIssuanceDate } from "@inrupt/solid-client-vc";

Check failure on line 23 in src/gConsent/guard/isBaseAccessGrantVerifiableCredential.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Unable to resolve path to module '@inrupt/solid-client-vc'
import { DataFactory } from "n3";
import { TYPE, solidVc } from "../../common/constants";
import { getConsent } from "../../common/getters";
import type {
BaseGrantBody,
GrantCredentialSubject,
GrantCredentialSubjectPayload,
RequestCredentialSubject,
RequestCredentialSubjectPayload,
} from "../type/AccessVerifiableCredential";
import { isGConsentAttributes, isRdfjsGConsentAttributes } from "./isGConsentAttributes";
import { isBaseAccessVcBody } from "./isBaseAccessVcBody";
import { DatasetWithId, getCredentialSubject, getExpirationDate, getId, getIssuanceDate, getIssuer } from "@inrupt/solid-client-vc";
import { TYPE, gc, solidVc } from "../../common/constants";
import { DataFactory } from "n3";
import { NamedNode } from "@rdfjs/types";
import { getAccessModes, getResources } from "../../common";
import { getConsent, getPurposes } from "../../common/getters";
import {
isGConsentAttributes,
isRdfjsGConsentAttributes,
} from "./isGConsentAttributes";

const { namedNode, quad } = DataFactory;

function isGrantCredentialSubject(
Expand All @@ -56,16 +59,22 @@ export function isBaseAccessGrantVerifiableCredential(
);
}

export function isRdfjsBaseAccessGrantVerifiableCredential(data: DatasetWithId) {
export function isRdfjsBaseAccessGrantVerifiableCredential(
data: DatasetWithId,
) {
const s = namedNode(getId(data));
if(!data.has(quad(s, TYPE, solidVc.SolidAccessDenial)) && !data.has(quad(s, TYPE, solidVc.SolidAccessGrant)) && !data.has(quad(s, TYPE, solidVc.SolidAccessRequest))) {
if (
!data.has(quad(s, TYPE, solidVc.SolidAccessDenial)) &&
!data.has(quad(s, TYPE, solidVc.SolidAccessGrant)) &&
!data.has(quad(s, TYPE, solidVc.SolidAccessRequest))
) {
return false;
}

// getConsent and getIssuanceDate can error
try {
getIssuanceDate(data);
return isRdfjsGConsentAttributes(data, getConsent(data))
return isRdfjsGConsentAttributes(data, getConsent(data));
} catch (e) {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion src/gConsent/guard/isGConsentAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export function isRdfjsGConsentAttributes(
if (
![acl.Append, acl.Read, acl.Write].some((mode) => mode.equals(object))
) {
console.log('mode issue')
return false;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/gConsent/manage/approveAccessRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import type { UrlString, WebId } from "@inrupt/solid-client";
// eslint-disable-next-line camelcase
import { acp_ess_2 } from "@inrupt/solid-client";
import type { VerifiableCredential, VerifiableCredentialBase } from "@inrupt/solid-client-vc";
import type {
VerifiableCredential,
VerifiableCredentialBase,
} from "@inrupt/solid-client-vc";
import type { AccessBaseOptions } from "../type/AccessBaseOptions";
import type { AccessGrantBody } from "../type/AccessVerifiableCredential";
import type { AccessGrantParameters } from "../type/Parameter";
Expand Down
Loading

0 comments on commit 9affa28

Please sign in to comment.