Skip to content

Commit 0478801

Browse files
committed
Change handleEvent option to eventHandler.
1 parent e84e691 commit 0478801

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- Support test environment in EARL output.
66
- Support benchmark output in EARL output.
77
- Benchmark comparison tool.
8-
- Event handler option "`handleEvent`" to allow custom handling of warnings and
8+
- Event handler option `"eventHandler"` to allow custom handling of warnings and
99
potentially other events in the future. Handles event replay for cached
1010
contexts.
1111

lib/context.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ api.process = async ({
6767

6868
// event handler for capturing events to replay when using a cached context
6969
const events = [];
70-
const handleEvent = [
70+
const eventHandler = [
7171
({event, next}) => {
7272
events.push(event);
7373
next();
7474
}
7575
];
7676
// chain to original handler
77-
if(options.handleEvent) {
78-
handleEvent.push(options.handleEvent);
77+
if(options.eventHandler) {
78+
eventHandler.push(options.eventHandler);
7979
}
8080
// store original options to use when replaying events
8181
const originalOptions = options;
8282
// shallow clone options with custom event handler
83-
options = Object.assign({}, options, {handleEvent});
83+
options = Object.assign({}, options, {eventHandler});
8484

8585
// resolve contexts
8686
const resolved = await options.contextResolver.resolve({

lib/events.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = api;
1919
/**
2020
* Handle an event.
2121
*
22-
* Top level APIs have a common 'handleEvent' option. This option can be a
22+
* Top level APIs have a common 'eventHandler' option. This option can be a
2323
* function, array of functions, object mapping event.code to functions (with a
2424
* default to call next()), or any combination of such handlers. Handlers will
2525
* be called with an object with an 'event' entry and a 'next' function. Custom
@@ -34,14 +34,14 @@ module.exports = api;
3434
* {string} level - severity level, one of: ['warning']
3535
* {string} message - human readable message
3636
* {object} details - event specific details
37-
* @param {object} options - original API options
37+
* @param {object} options - processing options
3838
*/
3939
api.handleEvent = ({
4040
event,
4141
options
4242
}) => {
4343
const handlers = [].concat(
44-
options.handleEvent ? _asArray(options.handleEvent) : [],
44+
options.eventHandler ? _asArray(options.eventHandler) : [],
4545
_defaultHandler
4646
);
4747
_handle({event, handlers});

lib/jsonld.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const _resolvedContextCache = new LRU({max: RESOLVED_CONTEXT_CACHE_MAX_SIZE});
119119
* unmappable values (or to throw an error when they are detected);
120120
* if this function returns `undefined` then the default behavior
121121
* will be used.
122-
* [handleEvent] handler for events such as warnings.
122+
* [eventHandler] handler for events.
123123
* [contextResolver] internal use only.
124124
*
125125
* @return a Promise that resolves to the compacted output.
@@ -258,7 +258,7 @@ jsonld.compact = async function(input, ctx, options) {
258258
* unmappable values (or to throw an error when they are detected);
259259
* if this function returns `undefined` then the default behavior
260260
* will be used.
261-
* [handleEvent] handler for events such as warnings.
261+
* [eventHandler] handler for events.
262262
* [contextResolver] internal use only.
263263
*
264264
* @return a Promise that resolves to the expanded output.
@@ -356,7 +356,7 @@ jsonld.expand = async function(input, options) {
356356
* [base] the base IRI to use.
357357
* [expandContext] a context to expand with.
358358
* [documentLoader(url, options)] the document loader.
359-
* [handleEvent] handler for events such as warnings.
359+
* [eventHandler] handler for events.
360360
* [contextResolver] internal use only.
361361
*
362362
* @return a Promise that resolves to the flattened output.
@@ -412,7 +412,7 @@ jsonld.flatten = async function(input, ctx, options) {
412412
* [requireAll] default @requireAll flag (default: true).
413413
* [omitDefault] default @omitDefault flag (default: false).
414414
* [documentLoader(url, options)] the document loader.
415-
* [handleEvent] handler for events such as warnings.
415+
* [eventHandler] handler for events.
416416
* [contextResolver] internal use only.
417417
*
418418
* @return a Promise that resolves to the framed output.
@@ -511,7 +511,7 @@ jsonld.frame = async function(input, frame, options) {
511511
* [base] the base IRI to use.
512512
* [expandContext] a context to expand with.
513513
* [documentLoader(url, options)] the document loader.
514-
* [handleEvent] handler for events such as warnings.
514+
* [eventHandler] handler for events.
515515
* [contextResolver] internal use only.
516516
*
517517
* @return a Promise that resolves to the linked output.
@@ -547,7 +547,7 @@ jsonld.link = async function(input, ctx, options) {
547547
* 'application/n-quads' for N-Quads.
548548
* [documentLoader(url, options)] the document loader.
549549
* [useNative] true to use a native canonize algorithm
550-
* [handleEvent] handler for events such as warnings.
550+
* [eventHandler] handler for events.
551551
* [contextResolver] internal use only.
552552
*
553553
* @return a Promise that resolves to the normalized output.
@@ -604,7 +604,7 @@ jsonld.normalize = jsonld.canonize = async function(input, options) {
604604
* (boolean, integer, double), false not to (default: false).
605605
* [rdfDirection] 'i18n-datatype' to support RDF transformation of
606606
* @direction (default: null).
607-
* [handleEvent] handler for events such as warnings.
607+
* [eventHandler] handler for events.
608608
*
609609
* @return a Promise that resolves to the JSON-LD document.
610610
*/
@@ -654,7 +654,7 @@ jsonld.fromRDF = async function(dataset, options) {
654654
* [produceGeneralizedRdf] true to output generalized RDF, false
655655
* to produce only standard RDF (default: false).
656656
* [documentLoader(url, options)] the document loader.
657-
* [handleEvent] handler for events such as warnings.
657+
* [eventHandler] handler for events.
658658
* [contextResolver] internal use only.
659659
*
660660
* @return a Promise that resolves to the RDF dataset.
@@ -708,7 +708,7 @@ jsonld.toRDF = async function(input, options) {
708708
* [expandContext] a context to expand with.
709709
* [issuer] a jsonld.IdentifierIssuer to use to label blank nodes.
710710
* [documentLoader(url, options)] the document loader.
711-
* [handleEvent] handler for events such as warnings.
711+
* [eventHandler] handler for events.
712712
* [contextResolver] internal use only.
713713
*
714714
* @return a Promise that resolves to the merged node map.
@@ -748,7 +748,7 @@ jsonld.createNodeMap = async function(input, options) {
748748
* new properties where a node is in the `object` position
749749
* (default: true).
750750
* [documentLoader(url, options)] the document loader.
751-
* [handleEvent] handler for events such as warnings.
751+
* [eventHandler] handler for events.
752752
* [contextResolver] internal use only.
753753
*
754754
* @return a Promise that resolves to the merged output.
@@ -911,7 +911,7 @@ jsonld.get = async function(url, options) {
911911
* @param localCtx the local context to process.
912912
* @param [options] the options to use:
913913
* [documentLoader(url, options)] the document loader.
914-
* [handleEvent] handler for events such as warnings.
914+
* [eventHandler] handler for events.
915915
* [contextResolver] internal use only.
916916
*
917917
* @return a Promise that resolves to the new active context.

tests/misc.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ describe('events', () => {
10211021

10221022
let handled = false;
10231023
const e = await jsonld.expand(d, {
1024-
handleEvent: ({event, next}) => {
1024+
eventHandler: ({event, next}) => {
10251025
if(event.code === 'invalid reserved term') {
10261026
handled = true;
10271027
} else {
@@ -1046,15 +1046,15 @@ describe('events', () => {
10461046
let handled0 = false;
10471047
let handled1 = false;
10481048
const e0 = await jsonld.expand(d, {
1049-
handleEvent: {
1049+
eventHandler: {
10501050
'invalid reserved term': () => {
10511051
handled0 = true;
10521052
}
10531053
}
10541054
});
10551055
// FIXME: ensure cache is being used
10561056
const e1 = await jsonld.expand(d, {
1057-
handleEvent: {
1057+
eventHandler: {
10581058
'invalid reserved term': () => {
10591059
handled1 = true;
10601060
}
@@ -1080,7 +1080,7 @@ describe('events', () => {
10801080
let ranHandler1 = false;
10811081
let handled = false;
10821082
const e = await jsonld.expand(d, {
1083-
handleEvent: [
1083+
eventHandler: [
10841084
({next}) => {
10851085
ranHandler0 = true;
10861086
// skip to next handler
@@ -1114,7 +1114,7 @@ describe('events', () => {
11141114

11151115
let handled = false;
11161116
const e = await jsonld.expand(d, {
1117-
handleEvent: {
1117+
eventHandler: {
11181118
'invalid reserved term': ({event}) => {
11191119
assert.equal(event.details.term, '@RESERVED');
11201120
handled = true;
@@ -1141,7 +1141,7 @@ describe('events', () => {
11411141
let ranHandler3 = false;
11421142
let handled = false;
11431143
const e = await jsonld.expand(d, {
1144-
handleEvent: [
1144+
eventHandler: [
11451145
({next}) => {
11461146
ranHandler0 = true;
11471147
next();
@@ -1205,7 +1205,7 @@ describe('events', () => {
12051205
let handledReservedValue = false;
12061206
let handledLanguage = false;
12071207
const e = await jsonld.expand(d, {
1208-
handleEvent: {
1208+
eventHandler: {
12091209
'invalid reserved term': () => {
12101210
handledReservedTerm = true;
12111211
},
@@ -1270,7 +1270,7 @@ describe('events', () => {
12701270
let handledLanguage2 = false;
12711271
const e2 = await jsonld.fromRDF(d2, {
12721272
rdfDirection: 'i18n-datatype',
1273-
handleEvent: {
1273+
eventHandler: {
12741274
'invalid @language value': () => {
12751275
handledLanguage2 = true;
12761276
}

0 commit comments

Comments
 (0)