-
Notifications
You must be signed in to change notification settings - Fork 36
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
WIP: Improve parser for WAC Allow header #1326
base: main
Are you sure you want to change the base?
Conversation
This new parser is more thoroughly tested, and also has a small efficiency gain: we only parse the header once, and then make assertions on it, rather than parsing once for each scope group.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit dafe51d:
|
*/ | ||
|
||
// TODO: Should we move this type internally, as the Access in this file is not strictly the same as ACL Access | ||
import { Access } from "../acl/acl"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NSeydoux @VirginiaBalseiro what're your thoughts on this one? I think parsing WAC Allow shouldn't be re-using data structures from ACL, as they are different things (the types just happen to currently be compatible)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it kind of makes sense that the Access
definition defined in ACL is used for the WAC-Allow header, given that the WAC-Allow header was initially described in the ACL spec. We have another Access
type definition from the access/universal
submodule for universal (i.e. for both ACL-controlled and ACP-controlled Pods), which is somewhat different (because ACP has a different notion of Control than ACL), but could maybe used here, since the WAC-Allow header is now present in both ACL and ACP specs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to rename Access
in ./acl/acl
to AclAccess
(we would need to export it still as Access
but mark that as a deprecated name (that'd give interface/type naming consistency within Acl
Then have wacAllow
use a internal_Access
type that's compatible? There's also a WacAccess
in https://github.com/inrupt/solid-client-js/blob/c8da4e5b0a7baa20ff04558b7e06d1a42e8df3ae/src/access/wac.ts — I'm not sure what this is exactly, and it's undocumented in the currently released SDK version, as far as I can tell.
Perhaps we move the WacAccess up to a ./wac-allow
directory, and move WacAccess
and the parser / transform there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Access interface (there is no reason for it to be a type considering its declaration) should in my opinion:
- Be moved to a type folder under src:
/src/type/
- Have all the modes
- Be used everywhere such Objects are inputs/outputs (we need to remove all the aliasing and other similar definitions)
It would be particularly convenient to have one place where all the standard interfaces are defined.
We really need to remove all the aliasing going on, it is exactly the opposite of what interfaces are for. You don't want 20 names for the same thing, you want 1 name for a specific shape and as few of them as required.
As a sidenote, the ACP specification will adopt the standard Solid access modes shortly, that is, use the acl:Control
mode just like WAC. It is a design flaw that it currently invents another mechanism. The operations entailed by Access Modes are defined at the Solid protocol level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Highlighted a few areas in the diff that might be of interest
return entries; | ||
} | ||
|
||
function internal_getWacPermissions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is named correctly / strictly belongs here; perhaps internal_getPermissions
would be better, as it's just checking a parsed WAC Allow for given values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me, we can always move it if it becomes relevant elsewhere.
|
||
return { | ||
read: permissions.includes("read"), | ||
append: permissions.includes("append") || permissions.includes("write"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same logic as, but simpler than: https://github.com/inrupt/solid-client-js/blob/main/src/resource/resource.internal.ts#L87-L100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the way https://github.com/inrupt/solid-client-js/blob/main/src/resource/resource.internal.ts#L87-L100 is written was motivated by type definitions, if I recall correctly the TS compiler was complaining if the append
and write
values were not constants, but this looks definitely simpler.
I'm not sure why |
*/ | ||
|
||
// TODO: Should we move this type internally, as the Access in this file is not strictly the same as ACL Access | ||
import { Access } from "../acl/acl"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it kind of makes sense that the Access
definition defined in ACL is used for the WAC-Allow header, given that the WAC-Allow header was initially described in the ACL spec. We have another Access
type definition from the access/universal
submodule for universal (i.e. for both ACL-controlled and ACP-controlled Pods), which is somewhat different (because ACP has a different notion of Control than ACL), but could maybe used here, since the WAC-Allow header is now present in both ACL and ACP specs.
return entries; | ||
} | ||
|
||
function internal_getWacPermissions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me, we can always move it if it becomes relevant elsewhere.
|
||
return { | ||
read: permissions.includes("read"), | ||
append: permissions.includes("append") || permissions.includes("write"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the way https://github.com/inrupt/solid-client-js/blob/main/src/resource/resource.internal.ts#L87-L100 is written was motivated by type definitions, if I recall correctly the TS compiler was complaining if the append
and write
values were not constants, but this looks definitely simpler.
This new parser is more thoroughly tested, and also has a small efficiency gain: we only parse the header once, and then make assertions on it, rather than parsing once for each scope group.
There's not yet a ticket for this work, as it was just an improvement I saw that we could make to improve code quality (I wasn't working on anything else more important today whilst I was waiting for feedback on scheduled work)
Related work: https://github.com/solid/wac-allow
Checklist
index.ts
, if applicable. n/a.ts
files) are listed in theexports
field inpackage.json
, if applicable. n/a.ts
files) are listed in thetypedocOptions.entryPoints
field intsconfig.json
, if applicable. n/a