Skip to content

Commit

Permalink
WIP: allow skipping of normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Nov 29, 2023
1 parent 5a3512d commit e627b74
Show file tree
Hide file tree
Showing 16 changed files with 595 additions and 188 deletions.
124 changes: 58 additions & 66 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
},
"dependencies": {
"@inrupt/solid-client": "^1.25.1",
"@inrupt/solid-client-vc": "^0.8.0-beta.2",
"@inrupt/solid-client-vc": "file:../solid-client-vc-js",
"@inrupt/universal-fetch": "^1.0.1",
"@types/rdfjs__dataset": "^1.0.5",
"auth-header": "^1.0.0",
Expand Down
16 changes: 8 additions & 8 deletions src/common/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,51 +43,51 @@ const { namedNode, defaultGraph, quad, literal } = DataFactory;
/**
* @internal
*/
function getSingleObject(
export function getSingleObject(
vc: DatasetCore,
subject: Term,
predicate: Term,
type: "NamedNode",
): NamedNode;
function getSingleObject(
export function getSingleObject(
vc: DatasetCore,
subject: Term,
predicate: Term,
type: "NamedNode",
required: false,
): NamedNode | undefined;
function getSingleObject(
export function getSingleObject(
vc: DatasetCore,
subject: Term,
predicate: Term,
type: "Literal",
required: false,
): Literal | undefined;
function getSingleObject(
export function getSingleObject(
vc: DatasetCore,
subject: Term,
predicate: Term,
type: "BlankNode",
): BlankNode;
function getSingleObject(
export function getSingleObject(
vc: DatasetCore,
subject: Term,
predicate: Term,
type: "Literal",
): Literal;
function getSingleObject(
export function getSingleObject(
vc: DatasetCore,
subject: Term,
predicate: Term,
): NamedNode | BlankNode;
function getSingleObject(
export function getSingleObject(
vc: DatasetCore,
subject: Term,
predicate: Term,
type: undefined,
required: false,
): NamedNode | BlankNode | undefined;
function getSingleObject(
export function getSingleObject(
vc: DatasetCore,
subject: Term,
predicate: Term,
Expand Down
36 changes: 36 additions & 0 deletions src/gConsent/guard/isAccessRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

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

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

View workflow job for this annotation

GitHub Actions / lint / lint

Unable to resolve path to module '@inrupt/solid-client-vc'
import type { BlankNode, NamedNode } from "@rdfjs/types";
import { DataFactory } from "n3";
import { ACCESS_REQUEST_STATUS } from "../constants";
import type { AccessRequestBody } from "../type/AccessVerifiableCredential";
import { isRdfjsBaseAccessGrantVerifiableCredential } from "./isBaseAccessGrantVerifiableCredential";

Check failure on line 28 in src/gConsent/guard/isAccessRequest.ts

View workflow job for this annotation

GitHub Actions / lint / lint

'isRdfjsBaseAccessGrantVerifiableCredential' is defined but never used
import { isBaseAccessRequestVerifiableCredential } from "./isBaseAccessRequestVerifiableCredential";
import { gc } from "../../common/constants";
import { getResourceOwner, getSingleObject } from "../../common/getters";

Check failure on line 31 in src/gConsent/guard/isAccessRequest.ts

View workflow job for this annotation

GitHub Actions / lint / lint

'getResourceOwner' is defined but never used
import { isRdfjsGConsentAttributes } from "./isGConsentAttributes";

const { quad, defaultGraph, namedNode } = DataFactory;

Check failure on line 34 in src/gConsent/guard/isAccessRequest.ts

View workflow job for this annotation

GitHub Actions / lint / lint

'namedNode' is assigned a value but never used

export function isAccessRequest(
x: unknown,
Expand All @@ -33,3 +43,29 @@ export function isAccessRequest(
typeof x.issuanceDate === "string"
);
}

export function isRdfjsAccessRequest(dataset: DatasetWithId) {
let consent: NamedNode | BlankNode;
try {
// There must be an issuance date
getIssuanceDate(dataset);
consent = getSingleObject(
dataset,
getCredentialSubject(dataset),
gc.hasConsent,
);
} catch {
return false;
}

return (
isRdfjsGConsentAttributes(dataset, consent) &&
dataset.has(quad(consent, gc.hasStatus, gc.ConsentStatusRequested)) &&
dataset.match(consent, gc.isConsentForDataSubject, null, defaultGraph())
.size === 1
);

// return isRdfjsBaseAccessGrantVerifiableCredential(dataset)
// && dataset.has(quad(consent, gc.hasStatus, gc.ConsentStatusRequested))
// && dataset.match(consent, gc.isConsentForDataSubject, null, defaultGraph()).size === 1
}
7 changes: 7 additions & 0 deletions src/gConsent/manage/getAccessGrantAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {
import { getAccessGrantAll } from "./getAccessGrantAll";
import { getAccessApiEndpoint } from "../discover/getAccessApiEndpoint";
import { mockAccessGrantVc } from "../util/access.mock";
import { normalizeAccessGrant } from "./approveAccessRequest";

const otherFetch = jest.fn(global.fetch);

Expand Down Expand Up @@ -187,6 +188,7 @@ describe("getAccessGrantAll", () => {
expect.objectContaining(expectedVcShape),
{
fetch: otherFetch,
normalize: normalizeAccessGrant,
},
);
});
Expand Down Expand Up @@ -221,6 +223,7 @@ describe("getAccessGrantAll", () => {
expect.objectContaining(expectedVcShape),
{
fetch: otherFetch,
normalize: normalizeAccessGrant,
},
);
});
Expand Down Expand Up @@ -255,6 +258,7 @@ describe("getAccessGrantAll", () => {
expect.objectContaining(expectedVcShape),
{
fetch: otherFetch,
normalize: normalizeAccessGrant,
},
);
});
Expand Down Expand Up @@ -289,6 +293,7 @@ describe("getAccessGrantAll", () => {
expect.objectContaining(expectedVcShapeOpen),
{
fetch: otherFetch,
normalize: normalizeAccessGrant,
},
);
});
Expand Down Expand Up @@ -326,6 +331,7 @@ describe("getAccessGrantAll", () => {
expect.objectContaining(expectedVcShape),
{
fetch: otherFetch,
normalize: normalizeAccessGrant,
},
);
});
Expand Down Expand Up @@ -363,6 +369,7 @@ describe("getAccessGrantAll", () => {
expect.objectContaining(expectedVcShape),
{
fetch: otherFetch,
normalize: normalizeAccessGrant,
},
);
});
Expand Down
Loading

0 comments on commit e627b74

Please sign in to comment.