Skip to content

Commit b47cc24

Browse files
committed
Remove eventHandler docs.
- The `eventHandler` design and implementation has not been finalized for external use yet.
1 parent 59fc87b commit b47cc24

File tree

3 files changed

+0
-168
lines changed

3 files changed

+0
-168
lines changed

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
- Support test environment in EARL output.
1010
- Support benchmark output in EARL output.
1111
- Benchmark comparison tool.
12-
- Event handler option `"eventHandler"` to allow custom handling of warnings
13-
and potentially other events in the future. Handles event replay for cached
14-
contexts.
1512

1613
## 6.0.0 - 2022-06-06
1714

README.md

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -346,160 +346,6 @@ It is recommended to set a default `user-agent` header for Node.js
346346
applications. The default for the default Node.js document loader is
347347
`jsonld.js`.
348348

349-
### Events
350-
351-
**WARNING**: This feature is **experimental** and the API, events, codes,
352-
levels, and messages may change.
353-
354-
Various events may occur during processing. The event handler system allows
355-
callers to handle events as appropriate. Use cases can be as simple as logging
356-
warnings, to displaying helpful UI hints, to failing on specific conditions.
357-
358-
**Note**: By default no event handler is used. This is due to general
359-
performance considerations and the impossibility of providing a default handler
360-
that would work for all use cases. Event construction and the handling system
361-
are avoided by default providing the best performance for use cases where data
362-
quality is known events are unnecessary.
363-
364-
#### Event Structure
365-
366-
Events are JSON objects with the following properties:
367-
368-
- **`type`**: ['JsonLdEvent'] and optionally an array with others.
369-
- **`code`**: A basic string code, similar to existing JSON-LD error codes.
370-
- **`level`**: The severity level. Currently only `warning` is emitted.
371-
- **`message`**: A human readable message describing the event.
372-
- **`details`**: A JSON object with event specific details.
373-
374-
#### Event Handlers
375-
376-
Event handlers are chainable functions, arrays of handlers, objects mapping
377-
codes to handlers, or any mix of these structures. Each function is passed an
378-
object with two properties:
379-
380-
- **`event`**: The event data.
381-
- **`next`**: A function to call to an `event` and a `next`.
382-
383-
The event handling system will process the handler structure, calling all
384-
handlers, and continuing onto the next handler if `next()` is called. To stop
385-
processing, throw an error, or return without calling `next()`.
386-
387-
This design allows for composable handler structures, for instance to handle
388-
some conditions with a custom handler, and default to generic "unknown event"
389-
or logging handler.
390-
391-
**Note**: Handlers are currently synchronous due to possible performance
392-
issues. This may change to an `async`/`await` design in the future.
393-
394-
```js
395-
// expand a document with a logging event handler
396-
const expanded = await jsonld.expand(data, {
397-
// simple logging handler
398-
eventHandler: function({event, next}) {
399-
console.log('event', {event});
400-
}
401-
});
402-
```
403-
404-
```js
405-
function logEventHandler({event, next}) {
406-
console.log('event', {event});
407-
next();
408-
}
409-
410-
function noWarningsEventHandler({event, next}) {
411-
if(event.level === 'warning') {
412-
throw new Error('No warnings!', {event});
413-
}
414-
next();
415-
}
416-
417-
function unknownEventHandler({event, next}) {
418-
throw new Error('Unknown event', {event});
419-
}
420-
421-
// expand a document with an array of event handlers
422-
const expanded = await jsonld.expand(data, {
423-
// array of handlers
424-
eventHandler: [
425-
logEventHandler,
426-
noWarningsEventHandler,
427-
unknownEventHandler
428-
]}
429-
});
430-
```
431-
432-
```js
433-
const handler = {
434-
'a mild event code': function({event}) {
435-
console.log('the thing happened', {event});
436-
},
437-
'a serious event code': function({event}) {
438-
throw new Error('the specific thing happened', {event});
439-
}
440-
};
441-
// expand a document with a code map event handler
442-
const expanded = await jsonld.expand(data, {eventHandler});
443-
```
444-
445-
#### Safe Validation
446-
447-
A common use case is to avoid JSON-LD constructs that will result in lossy
448-
behavior. The JSON-LD specifications have notes about when data is dropped.
449-
This can be especially important when calling [`canonize`][] in order to
450-
digitally sign data. The event system can be used to detect and avoid these
451-
situations. A special "safe mode" is available that will inject an initial
452-
event handler that fails on conditions that would result in data loss. More
453-
benign events may fall back to the passed event handler, if any.
454-
455-
**Note**: This mode is designed to be the common way that digital signing and
456-
similar applications use this library.
457-
458-
The `safe` options flag set to `true` enables this behavior:
459-
460-
```js
461-
// expand a document in safe mode
462-
const expanded = await jsonld.expand(data, {safe: true});
463-
```
464-
465-
```js
466-
// expand a document in safe mode, with fallback handler
467-
const expanded = await jsonld.expand(data, {
468-
safe: true
469-
eventHandler: function({event}) { /* ... */ }
470-
});
471-
```
472-
473-
#### Available Handlers
474-
475-
Some predefined event handlers are available to use alone or as part of a more
476-
complex handler:
477-
478-
- **safeEventHandler**: The handler used when `safe` is `true`.
479-
- **logEventHandler**: A debugging handler that outputs to the console.
480-
- **logWarningHandler**: A debugging handler that outputs `warning` level
481-
events to the console.
482-
- **unhandledEventHandler**: Throws on all events not yet handled.
483-
484-
#### Default Event Handler
485-
486-
A default event handler can be set. It will be the only handler when not in
487-
safe mode, and the second handler when in safe mode.
488-
489-
```js
490-
// fail on unknown events
491-
jsonld.setDefaultEventHandler(jsonld.unhandledEventHandler);
492-
// will use unhandled event handler by default
493-
const expanded = await jsonld.expand(data);
494-
```
495-
496-
```js
497-
// always use safe mode event handler, ignore other events
498-
jsonld.setDefaultEventHandler(jsonld.safeEventHandler);
499-
// will use safe mode handler, like `{safe: true}`
500-
const expanded = await jsonld.expand(data);
501-
```
502-
503349
Related Modules
504350
---------------
505351

lib/jsonld.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ const _resolvedContextCache = new LRU({max: RESOLVED_CONTEXT_CACHE_MAX_SIZE});
130130
* if this function returns `undefined` then the default behavior
131131
* will be used.
132132
* [safe] true to use safe mode. (default: false)
133-
* [eventHandler] handler for events.
134133
* [contextResolver] internal use only.
135134
*
136135
* @return a Promise that resolves to the compacted output.
@@ -270,7 +269,6 @@ jsonld.compact = async function(input, ctx, options) {
270269
* if this function returns `undefined` then the default behavior
271270
* will be used.
272271
* [safe] true to use safe mode. (default: false)
273-
* [eventHandler] handler for events.
274272
* [contextResolver] internal use only.
275273
*
276274
* @return a Promise that resolves to the expanded output.
@@ -368,7 +366,6 @@ jsonld.expand = async function(input, options) {
368366
* [base] the base IRI to use.
369367
* [expandContext] a context to expand with.
370368
* [documentLoader(url, options)] the document loader.
371-
* [eventHandler] handler for events.
372369
* [contextResolver] internal use only.
373370
*
374371
* @return a Promise that resolves to the flattened output.
@@ -425,7 +422,6 @@ jsonld.flatten = async function(input, ctx, options) {
425422
* [omitDefault] default @omitDefault flag (default: false).
426423
* [documentLoader(url, options)] the document loader.
427424
* [safe] true to use safe mode. (default: false)
428-
* [eventHandler] handler for events.
429425
* [contextResolver] internal use only.
430426
*
431427
* @return a Promise that resolves to the framed output.
@@ -525,7 +521,6 @@ jsonld.frame = async function(input, frame, options) {
525521
* [expandContext] a context to expand with.
526522
* [documentLoader(url, options)] the document loader.
527523
* [safe] true to use safe mode. (default: false)
528-
* [eventHandler] handler for events.
529524
* [contextResolver] internal use only.
530525
*
531526
* @return a Promise that resolves to the linked output.
@@ -562,7 +557,6 @@ jsonld.link = async function(input, ctx, options) {
562557
* [documentLoader(url, options)] the document loader.
563558
* [useNative] true to use a native canonize algorithm
564559
* [safe] true to use safe mode. (default: false)
565-
* [eventHandler] handler for events.
566560
* [contextResolver] internal use only.
567561
*
568562
* @return a Promise that resolves to the normalized output.
@@ -620,7 +614,6 @@ jsonld.normalize = jsonld.canonize = async function(input, options) {
620614
* [rdfDirection] 'i18n-datatype' to support RDF transformation of
621615
* @direction (default: null).
622616
* [safe] true to use safe mode. (default: false)
623-
* [eventHandler] handler for events.
624617
*
625618
* @return a Promise that resolves to the JSON-LD document.
626619
*/
@@ -671,7 +664,6 @@ jsonld.fromRDF = async function(dataset, options) {
671664
* to produce only standard RDF (default: false).
672665
* [documentLoader(url, options)] the document loader.
673666
* [safe] true to use safe mode. (default: false)
674-
* [eventHandler] handler for events.
675667
* [contextResolver] internal use only.
676668
*
677669
* @return a Promise that resolves to the RDF dataset.
@@ -725,7 +717,6 @@ jsonld.toRDF = async function(input, options) {
725717
* [expandContext] a context to expand with.
726718
* [issuer] a jsonld.IdentifierIssuer to use to label blank nodes.
727719
* [documentLoader(url, options)] the document loader.
728-
* [eventHandler] handler for events.
729720
* [contextResolver] internal use only.
730721
*
731722
* @return a Promise that resolves to the merged node map.
@@ -766,7 +757,6 @@ jsonld.createNodeMap = async function(input, options) {
766757
* (default: true).
767758
* [documentLoader(url, options)] the document loader.
768759
* [safe] true to use safe mode. (default: false)
769-
* [eventHandler] handler for events.
770760
* [contextResolver] internal use only.
771761
*
772762
* @return a Promise that resolves to the merged output.
@@ -930,7 +920,6 @@ jsonld.get = async function(url, options) {
930920
* @param [options] the options to use:
931921
* [documentLoader(url, options)] the document loader.
932922
* [safe] true to use safe mode. (default: false)
933-
* [eventHandler] handler for events.
934923
* [contextResolver] internal use only.
935924
*
936925
* @return a Promise that resolves to the new active context.

0 commit comments

Comments
 (0)