Skip to content

Commit 353c192

Browse files
committed
Remove compactionMap and expansionMap.
- **BREAKING**: Remove `compactionMap` and `expansionMap`. Their known use cases are addressed with "safe mode" and future planned features. - Update docs. - Update tests. - Add partial event log tester to simplify checking only some fields. - Add `prepending` events for `@base` and `@vocab`. Likely to be removed since other events better expose what the real data issues are. May return for a debug mode. - Fix some tests.
1 parent a8fc351 commit 353c192

File tree

6 files changed

+522
-1044
lines changed

6 files changed

+522
-1044
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
- Experimental non-standard `protectedMode` option.
4141
- **BREAKING**: Various console warnings were removed. The newly added "safe
4242
mode" can stop processing where these warnings were.
43+
- **BREAKING**: Remove `compactionMap` and `expansionMap`. Their known use
44+
cases are addressed with "safe mode" and future planned features.
4345

4446
## 5.2.0 - 2021-04-07
4547

lib/compact.js

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,28 @@ module.exports = api;
5151
* to compact, null for none.
5252
* @param element the element to compact.
5353
* @param options the compaction options.
54-
* @param compactionMap the compaction map to use.
5554
*
5655
* @return a promise that resolves to the compacted value.
5756
*/
5857
api.compact = async ({
5958
activeCtx,
6059
activeProperty = null,
6160
element,
62-
options = {},
63-
compactionMap = () => undefined
61+
options = {}
6462
}) => {
6563
// recursively compact array
6664
if(_isArray(element)) {
6765
let rval = [];
6866
for(let i = 0; i < element.length; ++i) {
69-
// compact, dropping any null values unless custom mapped
70-
let compacted = await api.compact({
67+
const compacted = await api.compact({
7168
activeCtx,
7269
activeProperty,
7370
element: element[i],
74-
options,
75-
compactionMap
71+
options
7672
});
7773
if(compacted === null) {
78-
compacted = await compactionMap({
79-
unmappedValue: element[i],
80-
activeCtx,
81-
activeProperty,
82-
parent: element,
83-
index: i,
84-
options
85-
});
86-
if(compacted === undefined) {
87-
continue;
88-
}
74+
// FIXME: need event?
75+
continue;
8976
}
9077
rval.push(compacted);
9178
}
@@ -149,8 +136,7 @@ api.compact = async ({
149136
activeCtx,
150137
activeProperty,
151138
element: element['@list'],
152-
options,
153-
compactionMap
139+
options
154140
});
155141
}
156142
}
@@ -278,8 +264,7 @@ api.compact = async ({
278264
activeCtx,
279265
activeProperty: '@reverse',
280266
element: expandedValue,
281-
options,
282-
compactionMap
267+
options
283268
});
284269

285270
// handle double-reversed properties
@@ -316,8 +301,7 @@ api.compact = async ({
316301
activeCtx,
317302
activeProperty,
318303
element: expandedValue,
319-
options,
320-
compactionMap
304+
options
321305
});
322306

323307
if(!(_isArray(compactedValue) && compactedValue.length === 0)) {
@@ -434,8 +418,7 @@ api.compact = async ({
434418
activeCtx,
435419
activeProperty: itemActiveProperty,
436420
element: (isList || isGraph) ? inner : expandedItem,
437-
options,
438-
compactionMap
421+
options
439422
});
440423

441424
// handle @list
@@ -630,8 +613,7 @@ api.compact = async ({
630613
activeCtx,
631614
activeProperty: itemActiveProperty,
632615
element: {'@id': expandedItem['@id']},
633-
options,
634-
compactionMap
616+
options
635617
});
636618
}
637619
}

lib/context.js

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,35 +1106,29 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
11061106
if(relativeTo.vocab && '@vocab' in activeCtx) {
11071107
// prepend vocab
11081108
const prependedResult = activeCtx['@vocab'] + value;
1109-
let expansionMapResult = undefined;
1110-
if(options && options.expansionMap) {
1111-
// if we are about to expand the value by prepending
1112-
// @vocab then call the expansion map to inform
1113-
// interested callers that this is occurring
1114-
1115-
// TODO: use `await` to support async
1116-
expansionMapResult = options.expansionMap({
1117-
prependedIri: {
1118-
type: '@vocab',
1119-
vocab: activeCtx['@vocab'],
1120-
value,
1121-
result: prependedResult,
1122-
typeExpansion,
1109+
if(options && options.eventHandler) {
1110+
_handleEvent({
1111+
event: {
1112+
type: ['JsonLdEvent'],
1113+
code: 'prepending @vocab during expansion',
1114+
level: 'info',
1115+
message: 'Prepending @vocab during expansion.',
1116+
details: {
1117+
type: '@vocab',
1118+
vocab: activeCtx['@vocab'],
1119+
value,
1120+
result: prependedResult,
1121+
typeExpansion
1122+
}
11231123
},
1124-
activeCtx,
11251124
options
11261125
});
11271126
}
1128-
if(expansionMapResult !== undefined) {
1129-
value = expansionMapResult;
1130-
} else {
1131-
// the null case preserves value as potentially relative
1132-
value = prependedResult;
1133-
}
1127+
// the null case preserves value as potentially relative
1128+
value = prependedResult;
11341129
} else if(relativeTo.base) {
11351130
// prepend base
11361131
let prependedResult;
1137-
let expansionMapResult;
11381132
let base;
11391133
if('@base' in activeCtx) {
11401134
if(activeCtx['@base']) {
@@ -1148,50 +1142,50 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
11481142
base = options.base;
11491143
prependedResult = prependBase(options.base, value);
11501144
}
1151-
if(options && options.expansionMap) {
1152-
// if we are about to expand the value by pre-pending
1153-
// @base then call the expansion map to inform
1154-
// interested callers that this is occurring
1155-
1156-
// TODO: use `await` to support async
1157-
expansionMapResult = options.expansionMap({
1158-
prependedIri: {
1159-
type: '@base',
1160-
base,
1161-
value,
1162-
result: prependedResult,
1163-
typeExpansion,
1145+
if(options && options.eventHandler) {
1146+
_handleEvent({
1147+
event: {
1148+
type: ['JsonLdEvent'],
1149+
code: 'prepending @base during expansion',
1150+
level: 'info',
1151+
message: 'Prepending @base during expansion.',
1152+
details: {
1153+
type: '@base',
1154+
base,
1155+
value,
1156+
result: prependedResult,
1157+
typeExpansion
1158+
}
11641159
},
1165-
activeCtx,
11661160
options
11671161
});
11681162
}
1169-
if(expansionMapResult !== undefined) {
1170-
value = expansionMapResult;
1171-
} else {
1172-
// the null case preserves value as potentially relative
1173-
value = prependedResult;
1174-
}
1163+
// the null case preserves value as potentially relative
1164+
value = prependedResult;
11751165
}
11761166

1177-
if(!_isAbsoluteIri(value) && options && options.expansionMap) {
1178-
// if the result of the expansion is not an absolute iri then
1179-
// call the expansion map to inform interested callers that
1180-
// the resulting value is a relative iri, which can result in
1181-
// it being dropped when converting to other RDF representations
1182-
1183-
// TODO: use `await` to support async
1184-
const expandedResult = options.expansionMap({
1185-
relativeIri: value,
1186-
activeCtx,
1187-
typeExpansion,
1167+
// FIXME: duplicate? needed? maybe just enable in a verbose debug mode
1168+
/*
1169+
if(!_isAbsoluteIri(value) && options && options.eventHandler) {
1170+
// emit event indicating a relative IRI was found, which can result in it
1171+
// being dropped when converting to other RDF representations
1172+
_handleEvent({
1173+
event: {
1174+
type: ['JsonLdEvent'],
1175+
code: 'relative IRI after expansion',
1176+
// FIXME: what level?
1177+
level: 'warning',
1178+
message: 'Relative IRI after expansion.',
1179+
details: {
1180+
relativeIri: value,
1181+
typeExpansion
1182+
}
1183+
},
11881184
options
11891185
});
1190-
if(expandedResult !== undefined) {
1191-
value = expandedResult;
1192-
}
11931186
// NOTE: relative reference events emitted at calling sites as needed
11941187
}
1188+
*/
11951189

11961190
return value;
11971191
}

0 commit comments

Comments
 (0)