-
Notifications
You must be signed in to change notification settings - Fork 203
Adds support for @included
in compaction, expansion and flattening.
#349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
326cf30
43d6680
c5ba474
59159bf
063ab32
75bf623
bdba8d1
7d48f60
0c6501b
7c566e5
462e1be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ const { | |
|
||
const INITIAL_CONTEXT_CACHE = new Map(); | ||
const INITIAL_CONTEXT_CACHE_MAX_SIZE = 10000; | ||
const KEYWORD_PATTERN = /^@[a-zA-Z]+$/; | ||
|
||
const api = {}; | ||
module.exports = api; | ||
|
@@ -382,7 +383,7 @@ api.createTermDefinition = ({ | |
|
||
if(term === '@type' && | ||
_isObject(value) && | ||
value['@container'] === '@set' && | ||
(value['@container'] || '@set') === '@set' && | ||
api.processingMode(activeCtx, 1.1)) { | ||
|
||
const validKeys = ['@container', '@id', '@protected']; | ||
|
@@ -397,6 +398,11 @@ api.createTermDefinition = ({ | |
'Invalid JSON-LD syntax; keywords cannot be overridden.', | ||
'jsonld.SyntaxError', | ||
{code: 'keyword redefinition', context: localCtx, term}); | ||
} else if(term.match(KEYWORD_PATTERN)) { | ||
// FIXME: remove logging and use a handler | ||
console.warn('WARNING: terms beginning with "@" are reserved' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll leave this for you to come up with a comprehensive solution. There are other areas where the spec says to generate warnings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Printing out warnings to a console can be invisible for backend code and UIs, hence the idea to have some of handler. I haven't put time into a design for that. A more strict mode that throws errors seems useful to me as well. |
||
' for future use and ignored', {term}); | ||
return; | ||
} else if(term === '') { | ||
throw new JsonLdError( | ||
'Invalid JSON-LD syntax; a term cannot be an empty string.', | ||
|
@@ -484,6 +490,19 @@ api.createTermDefinition = ({ | |
'absolute IRI or a blank node identifier.', | ||
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx}); | ||
} | ||
|
||
if(reverse.match(KEYWORD_PATTERN)) { | ||
// FIXME: remove logging and use a handler | ||
console.warn('WARNING: values beginning with "@" are reserved' + | ||
' for future use and ignored', {reverse}); | ||
if(previousMapping) { | ||
activeCtx.mappings.set(term, previousMapping); | ||
} else { | ||
activeCtx.mappings.delete(term); | ||
} | ||
return; | ||
} | ||
|
||
mapping['@id'] = id; | ||
mapping.reverse = true; | ||
} else if('@id' in value) { | ||
|
@@ -497,6 +516,16 @@ api.createTermDefinition = ({ | |
if(id === null) { | ||
// reserve a null term, which may be protected | ||
mapping['@id'] = null; | ||
} else if(!api.isKeyword(id) && id.match(KEYWORD_PATTERN)) { | ||
// FIXME: remove logging and use a handler | ||
console.warn('WARNING: values beginning with "@" are reserved' + | ||
' for future use and ignored', {id}); | ||
if(previousMapping) { | ||
activeCtx.mappings.set(term, previousMapping); | ||
} else { | ||
activeCtx.mappings.delete(term); | ||
} | ||
return; | ||
} else if(id !== term) { | ||
// expand and add @id mapping | ||
id = _expandIri( | ||
|
@@ -750,6 +779,12 @@ api.createTermDefinition = ({ | |
'jsonld.SyntaxError', | ||
{code: 'invalid term definition', context: localCtx}); | ||
} | ||
if(api.isKeyword(mapping['@id'])) { | ||
throw new JsonLdError( | ||
'Invalid JSON-LD syntax; keywords may not be used as prefixes', | ||
'jsonld.SyntaxError', | ||
{code: 'invalid term definition', context: localCtx}); | ||
} | ||
if(typeof value['@prefix'] === 'boolean') { | ||
mapping._prefix = value['@prefix'] === true; | ||
} else { | ||
|
@@ -850,6 +885,11 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) { | |
return value; | ||
} | ||
|
||
// ignore non-keyword things that look like a keyword | ||
if(value.match(KEYWORD_PATTERN)) { | ||
return null; | ||
} | ||
|
||
// define term dependency if not defined | ||
if(localCtx && localCtx.hasOwnProperty(value) && | ||
defined.get(value) !== true) { | ||
|
@@ -1230,6 +1270,7 @@ api.isKeyword = v => { | |
case '@explicit': | ||
case '@graph': | ||
case '@id': | ||
case '@included': | ||
case '@index': | ||
case '@json': | ||
case '@language': | ||
|
Uh oh!
There was an error while loading. Please reload this page.