Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 456b2d6

Browse files
committedFeb 23, 2020
Remove experimental protectedMode option.
1 parent 3da84bd commit 456b2d6

File tree

2 files changed

+9
-47
lines changed

2 files changed

+9
-47
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
- Support for RDF transformation of `@direction` when `rdfDirection` is
3030
'i18n-datatype'.
3131

32+
### Removed
33+
- Experimental non-standard `protectedMode` option.
34+
3235
## 2.0.2 - 2020-01-17
3336

3437
### Fixed

‎lib/context.js

+6-47
Original file line numberDiff line numberDiff line change
@@ -97,38 +97,12 @@ api.process = async ({
9797
if(ctx === null) {
9898
// We can't nullify if there are protected terms and we're
9999
// not allowing overrides (e.g. processing a property term scoped context)
100-
if(!overrideProtected &&
101-
Object.keys(activeCtx.protected).length !== 0) {
102-
const protectedMode = (options && options.protectedMode) || 'error';
103-
if(protectedMode === 'error') {
104-
throw new JsonLdError(
105-
'Tried to nullify a context with protected terms outside of ' +
106-
'a term definition.',
107-
'jsonld.SyntaxError',
108-
{code: 'invalid context nullification'});
109-
} else if(protectedMode === 'warn') {
110-
// FIXME: remove logging and use a handler
111-
console.warn('WARNING: invalid context nullification');
112-
const oldActiveCtx = activeCtx;
113-
// copy all protected term definitions to fresh initial context
114-
rval = activeCtx = api.getInitialContext(options).clone();
115-
for(const [term, _protected] of
116-
Object.entries(oldActiveCtx.protected)) {
117-
if(_protected) {
118-
activeCtx.mappings[term] =
119-
util.clone(oldActiveCtx.mappings[term]);
120-
}
121-
}
122-
activeCtx.protected = util.clone(oldActiveCtx.protected);
123-
124-
// cache processed result
125-
resolvedContext.setProcessed(oldActiveCtx, rval);
126-
continue;
127-
}
100+
if(!overrideProtected && Object.keys(activeCtx.protected).length !== 0) {
128101
throw new JsonLdError(
129-
'Invalid protectedMode.',
102+
'Tried to nullify a context with protected terms outside of ' +
103+
'a term definition.',
130104
'jsonld.SyntaxError',
131-
{code: 'invalid protected mode', context: localCtx, protectedMode});
105+
{code: 'invalid context nullification'});
132106
}
133107
rval = activeCtx = api.getInitialContext(options).clone();
134108
continue;
@@ -371,9 +345,6 @@ api.process = async ({
371345
* @param defined a map of defining/defined keys to detect cycles and prevent
372346
* double definitions.
373347
* @param {Object} [options] - creation options.
374-
* @param {string} [options.protectedMode="error"] - "error" to throw error
375-
* on `@protected` constraint violation, "warn" to allow violations and
376-
* signal a warning.
377348
* @param overrideProtected `false` allows protected terms to be modified.
378349
*/
379350
api.createTermDefinition = ({
@@ -859,22 +830,10 @@ api.createTermDefinition = ({
859830
activeCtx.protected[term] = true;
860831
mapping.protected = true;
861832
if(!_deepCompare(previousMapping, mapping)) {
862-
const protectedMode = (options && options.protectedMode) || 'error';
863-
if(protectedMode === 'error') {
864-
throw new JsonLdError(
865-
'Invalid JSON-LD syntax; tried to redefine a protected term.',
866-
'jsonld.SyntaxError',
867-
{code: 'protected term redefinition', context: localCtx, term});
868-
} else if(protectedMode === 'warn') {
869-
// FIXME: remove logging and use a handler
870-
console.warn('WARNING: protected term redefinition', {term});
871-
return;
872-
}
873833
throw new JsonLdError(
874-
'Invalid protectedMode.',
834+
'Invalid JSON-LD syntax; tried to redefine a protected term.',
875835
'jsonld.SyntaxError',
876-
{code: 'invalid protected mode', context: localCtx, term,
877-
protectedMode});
836+
{code: 'protected term redefinition', context: localCtx, term});
878837
}
879838
}
880839
};

0 commit comments

Comments
 (0)
Please sign in to comment.