Skip to content

Commit 3cf7dfb

Browse files
committed
Remove experimental protectedMode option.
1 parent b7bc6d6 commit 3cf7dfb

File tree

2 files changed

+9
-56
lines changed

2 files changed

+9
-56
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
### Changed
1010
- Change EARL Assertor to Digital Bazaar, Inc.
1111

12+
### Removed
13+
- Experimental non-standard `protectedMode` option.
14+
1215
## 5.2.0 - 2021-04-07
1316

1417
### Changed

lib/context.js

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -98,46 +98,12 @@ api.process = async ({
9898
if(ctx === null) {
9999
// We can't nullify if there are protected terms and we're
100100
// not allowing overrides (e.g. processing a property term scoped context)
101-
if(!overrideProtected &&
102-
Object.keys(activeCtx.protected).length !== 0) {
103-
const protectedMode = (options && options.protectedMode) || 'error';
104-
if(protectedMode === 'error') {
105-
throw new JsonLdError(
106-
'Tried to nullify a context with protected terms outside of ' +
107-
'a term definition.',
108-
'jsonld.SyntaxError',
109-
{code: 'invalid context nullification'});
110-
} else if(protectedMode === 'warn') {
111-
// FIXME: remove logging and use a handler
112-
console.warn('WARNING: invalid context nullification');
113-
114-
// get processed context from cache if available
115-
const processed = resolvedContext.getProcessed(activeCtx);
116-
if(processed) {
117-
rval = activeCtx = processed;
118-
continue;
119-
}
120-
121-
const oldActiveCtx = activeCtx;
122-
// copy all protected term definitions to fresh initial context
123-
rval = activeCtx = api.getInitialContext(options).clone();
124-
for(const [term, _protected] of
125-
Object.entries(oldActiveCtx.protected)) {
126-
if(_protected) {
127-
activeCtx.mappings[term] =
128-
util.clone(oldActiveCtx.mappings[term]);
129-
}
130-
}
131-
activeCtx.protected = util.clone(oldActiveCtx.protected);
132-
133-
// cache processed result
134-
resolvedContext.setProcessed(oldActiveCtx, rval);
135-
continue;
136-
}
101+
if(!overrideProtected && Object.keys(activeCtx.protected).length !== 0) {
137102
throw new JsonLdError(
138-
'Invalid protectedMode.',
103+
'Tried to nullify a context with protected terms outside of ' +
104+
'a term definition.',
139105
'jsonld.SyntaxError',
140-
{code: 'invalid protected mode', context: localCtx, protectedMode});
106+
{code: 'invalid context nullification'});
141107
}
142108
rval = activeCtx = api.getInitialContext(options).clone();
143109
continue;
@@ -429,9 +395,6 @@ api.process = async ({
429395
* @param defined a map of defining/defined keys to detect cycles and prevent
430396
* double definitions.
431397
* @param {Object} [options] - creation options.
432-
* @param {string} [options.protectedMode="error"] - "error" to throw error
433-
* on `@protected` constraint violation, "warn" to allow violations and
434-
* signal a warning.
435398
* @param overrideProtected `false` allows protected terms to be modified.
436399
*/
437400
api.createTermDefinition = ({
@@ -918,23 +881,10 @@ api.createTermDefinition = ({
918881
activeCtx.protected[term] = true;
919882
mapping.protected = true;
920883
if(!_deepCompare(previousMapping, mapping)) {
921-
const protectedMode = (options && options.protectedMode) || 'error';
922-
if(protectedMode === 'error') {
923-
throw new JsonLdError(
924-
`Invalid JSON-LD syntax; tried to redefine "${term}" which is a ` +
925-
'protected term.',
926-
'jsonld.SyntaxError',
927-
{code: 'protected term redefinition', context: localCtx, term});
928-
} else if(protectedMode === 'warn') {
929-
// FIXME: remove logging and use a handler
930-
console.warn('WARNING: protected term redefinition', {term});
931-
return;
932-
}
933884
throw new JsonLdError(
934-
'Invalid protectedMode.',
885+
'Invalid JSON-LD syntax; tried to redefine a protected term.',
935886
'jsonld.SyntaxError',
936-
{code: 'invalid protected mode', context: localCtx, term,
937-
protectedMode});
887+
{code: 'protected term redefinition', context: localCtx, term});
938888
}
939889
}
940890
};

0 commit comments

Comments
 (0)