Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Pete Edwards <[email protected]>
  • Loading branch information
NSeydoux and edwardsph authored Dec 10, 2024
1 parent 9b03277 commit 65b82e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The following changes are pending, and will be applied on the next major release
custom fields, and via a set of dedicated getters in the `getters/` module. A generic getter
is introduced, `getCustomFields`, as well as a set of typed helpers, such as `getCustomInteger`
and `getCustomIntegers`. Typed helpers are available for integers, floats, strings and booleans,
with a scalar and array value for each.
with a scalar and array version of each.

## [3.1.1](https://github.com/inrupt/solid-client-access-grants-js/releases/tag/v3.1.1) - 2024-10-23

Expand Down
17 changes: 11 additions & 6 deletions src/common/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ export function getCustomFields(

/**
* Internal function. Deserializes a literal using the provided function.
* If the literal cannot be deserialized as expected (e.g. a string attempted
* to be deserialized as an integer), an error is thrown.
* If the literal cannot be deserialized as expected (e.g. an attempt to
* deserialize a string as an integer), an error is thrown.
*
* @hidden
*/
Expand Down Expand Up @@ -578,7 +578,7 @@ function deserializeField<T>(
* ]),
* });
* // s is [true, false, true]
* const s = getCustomBoolean(accessRequest, new URL("https://example.org/ns/customBoolean"));
* const s = getCustomBooleans(accessRequest, new URL("https://example.org/ns/customBoolean"));
* ```
*
* @param accessCredential The Access Credential (Access Grant or Access Request)
Expand Down Expand Up @@ -753,7 +753,7 @@ export function getCustomIntegers(
* ]),
* });
* // i is 1
* const i = getCustomString(accessRequest, new URL("https://example.org/ns/customInteger"));
* const i = getCustomInteger(accessRequest, new URL("https://example.org/ns/customInteger"));
* ```
*
* @param accessCredential The Access Credential (Access Grant or Access Request)
Expand Down Expand Up @@ -795,8 +795,13 @@ export function getCustomInteger(
* @returns the custom string array field with the provided name
* @since unreleased
*/
export function getCustomStrings(vc: DatasetWithId, field: URL): string[] {
return deserializeFields(vc, field, (s) => typeof s === "string", "string");
export function getCustomStrings(accessCredential: DatasetWithId, field: URL): string[] {

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

View workflow job for this annotation

GitHub Actions / lint / lint

Replace `accessCredential:·DatasetWithId,·field:·URL` with `⏎··accessCredential:·DatasetWithId,⏎··field:·URL,⏎`
return deserializeFields(
accessCredential,
field,
(s) => typeof s === "string",
"string",
);

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

View workflow job for this annotation

GitHub Actions / lint / lint

Delete `··`
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/type/CustomField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ export const toJson = (
// Append the new value to the existing array.
[`${curKey}`]: [...acc[curKey], cur[curKey]],
// TS is rightfully upset here, because we're pretending
// all the values for a given key is of the same type,
// all the values for a given key are of the same type,
// which is not enforced at write time. Typed helpers
// will throw at read time, but untyped reader will allow
// to read back whathever.
// will throw at read time, but untyped readers will allow
// anything to be read back.
} as Record<string, CustomField["value"]>;
}
return {
Expand Down

0 comments on commit 65b82e9

Please sign in to comment.