Skip to content
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

Update expandMap and tests. #464

Merged
merged 51 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d9a9efe
Fix test names.
davidlehn Dec 15, 2021
27d40c1
Update expansionMap tests.
davidlehn Dec 15, 2021
e37991f
Start more expansionMap tests.
davidlehn Mar 24, 2022
a05a926
Remove experimental protectedMode option.
davidlehn Feb 23, 2020
3d33a3e
Add event handler.
davidlehn Feb 23, 2020
b5c8847
Use events for language value warnings.
davidlehn Feb 23, 2020
8df3db0
Change handleEvent option to eventHandler.
davidlehn Feb 24, 2020
f2a0ba7
Use object spread.
davidlehn Feb 24, 2020
ccaec14
Temporary restrict tests.
davidlehn Mar 24, 2022
75e9cbe
Test events before expansionMap.
davidlehn Mar 24, 2022
78c29c4
Improve event and expansionMap tests.
davidlehn Mar 24, 2022
62874cc
Update style.
davidlehn Mar 24, 2022
bfd180f
Add expansion warnings events.
davidlehn Mar 26, 2022
2e04ea3
Event handler improvements.
davidlehn Mar 26, 2022
4f5eddf
Fix error messages.
davidlehn Mar 26, 2022
e35c1ff
Track test events.
davidlehn Mar 26, 2022
399e0e2
Event updates and add safe mode.
davidlehn Apr 2, 2022
2d38992
Add events docs.
davidlehn Apr 2, 2022
9ddd16e
Style fix.
davidlehn Apr 2, 2022
c408194
Add tests.
davidlehn Apr 2, 2022
5322f09
Update event and expansionMap tests.
davidlehn Apr 2, 2022
317e330
Improve event handling.
davidlehn Apr 2, 2022
c6eb0fe
Add function names.
davidlehn Apr 3, 2022
f53c907
Fix safe event check.
davidlehn Apr 3, 2022
d6ac40b
Add generic event testing wrapper.
davidlehn Apr 4, 2022
0f981aa
Update events and validation modes.
davidlehn Apr 5, 2022
9cfa812
Fix tests typo.
davidlehn Apr 6, 2022
06eb166
Avoid _expandIri event during `@json` type check.
davidlehn Apr 6, 2022
5720351
Check default `@language` BCP47 format.
davidlehn Apr 6, 2022
92716dd
Add full even test for reserved terms.
davidlehn Apr 6, 2022
27e8b2d
Clean up events.
davidlehn Apr 6, 2022
d79283d
Add language map BCP47 event and test.
davidlehn Apr 6, 2022
b6c88f3
Remove "strict" mode support.
davidlehn Apr 6, 2022
475e22d
Add and test fromRDF event support.
davidlehn Apr 6, 2022
9abe338
Move keword regex to util.js.
davidlehn Apr 8, 2022
911c5a7
Update events and tests.
davidlehn Apr 12, 2022
7ab1749
Update tests.
davidlehn Apr 12, 2022
2a35d62
Add start of normative test flag support.
davidlehn Apr 12, 2022
ad39494
Keep former non-normative edge case behavior.
davidlehn Aug 5, 2022
13de319
Fix null handling.
davidlehn Aug 5, 2022
923b4e3
Handle non-string id blank node edge case.
davidlehn Aug 5, 2022
72f2ac3
Add safe mode default to docs.
davidlehn Aug 5, 2022
27ef24c
Fix tests.
davidlehn Aug 5, 2022
006aa10
Add toRDF events and tests.
davidlehn Aug 5, 2022
15b794e
Remove eventHandler docs.
davidlehn Aug 5, 2022
c0be80e
Add "safe mode" documentation.
davidlehn Aug 5, 2022
52530f8
Remove `compactionMap` and `expansionMap`.
davidlehn Aug 6, 2022
f0eff29
Remove prepending `@base` and `@vocab` events.
davidlehn Aug 6, 2022
9165327
Fix lint issue.
davidlehn Aug 6, 2022
3c9e39d
Fix typo.
davidlehn Aug 10, 2022
87585c2
Fix changelog.
davidlehn Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# jsonld ChangeLog

### Changed
- Change EARL Assertor to Digital Bazaar, Inc.
- Update eslint dependencies.

### Added
- Support benchmarks in Karma tests.
- Support test environment in EARL output.
- Support benchmark output in EARL output.
- Benchmark comparison tool.
- Add "safe mode" to all APIs. Enable by adding `{safe: true}` to API options.
This mode causes processing to fail when data constructs are encountered that
result in lossy behavior or other data warnings. This is intended to be the
common way that digital signing and similar applications use this library.

### Changed
- Change EARL Assertor to Digital Bazaar, Inc.
- Update eslint dependencies.
### Removed
- Experimental non-standard `protectedMode` option.
- **BREAKING**: Various console warnings were removed. The newly added "safe
mode" can stop processing where these warnings occurred.
- **BREAKING**: Remove `compactionMap` and `expansionMap`. Their known use
cases are addressed with "safe mode" and future planned features.

## 6.0.0 - 2022-06-06

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,24 @@ It is recommended to set a default `user-agent` header for Node.js
applications. The default for the default Node.js document loader is
`jsonld.js`.

### Safe Mode

A common use case is to avoid JSON-LD constructs that will result in lossy
behavior. The JSON-LD specifications have notes about when data is dropped.
This can be especially important when calling [`canonize`][] in order to
digitally sign data. A special "safe mode" is available that will detect these
situations and cause processing to fail.

**Note**: This mode is designed to be the common way that digital signing and
similar applications use this library.

The `safe` options flag set to `true` enables this behavior:

```js
// expand a document in safe mode
const expanded = await jsonld.expand(data, {safe: true});
```

Related Modules
---------------

Expand Down
38 changes: 10 additions & 28 deletions lib/compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,41 +51,28 @@ module.exports = api;
* to compact, null for none.
* @param element the element to compact.
* @param options the compaction options.
* @param compactionMap the compaction map to use.
*
* @return a promise that resolves to the compacted value.
*/
api.compact = async ({
activeCtx,
activeProperty = null,
element,
options = {},
compactionMap = () => undefined
options = {}
}) => {
// recursively compact array
if(_isArray(element)) {
let rval = [];
for(let i = 0; i < element.length; ++i) {
// compact, dropping any null values unless custom mapped
let compacted = await api.compact({
const compacted = await api.compact({
activeCtx,
activeProperty,
element: element[i],
options,
compactionMap
options
});
if(compacted === null) {
compacted = await compactionMap({
unmappedValue: element[i],
activeCtx,
activeProperty,
parent: element,
index: i,
options
});
if(compacted === undefined) {
continue;
}
// FIXME: need event?
continue;
}
rval.push(compacted);
}
Expand Down Expand Up @@ -149,8 +136,7 @@ api.compact = async ({
activeCtx,
activeProperty,
element: element['@list'],
options,
compactionMap
options
});
}
}
Expand Down Expand Up @@ -278,8 +264,7 @@ api.compact = async ({
activeCtx,
activeProperty: '@reverse',
element: expandedValue,
options,
compactionMap
options
});

// handle double-reversed properties
Expand Down Expand Up @@ -316,8 +301,7 @@ api.compact = async ({
activeCtx,
activeProperty,
element: expandedValue,
options,
compactionMap
options
});

if(!(_isArray(compactedValue) && compactedValue.length === 0)) {
Expand Down Expand Up @@ -434,8 +418,7 @@ api.compact = async ({
activeCtx,
activeProperty: itemActiveProperty,
element: (isList || isGraph) ? inner : expandedItem,
options,
compactionMap
options
});

// handle @list
Expand Down Expand Up @@ -630,8 +613,7 @@ api.compact = async ({
activeCtx,
activeProperty: itemActiveProperty,
element: {'@id': expandedItem['@id']},
options,
compactionMap
options
});
}
}
Expand Down
Loading