Comparing version 2.0.1 to 2.0.2
# jsonld ChangeLog | ||
## 2.0.2 - 2020-01-17 | ||
### Fixed | ||
- More support for `"@type": "@none"`. | ||
- JSON literal value handling issues (`null` and `[]`). | ||
- Fix resolving context `null` values. | ||
### Changed | ||
- `isKeyword()` optimization for non-keyword fast path. | ||
## 2.0.1 - 2019-12-10 | ||
@@ -4,0 +14,0 @@ |
@@ -1057,3 +1057,3 @@ /* | ||
if (!preserveIndex) { | ||
if (!preserveIndex && type !== '@none') { | ||
// matching @type or @language specified in context, compact value | ||
@@ -1077,3 +1077,3 @@ if (value['@type'] === type || value['@language'] === language) { | ||
if (isValueOnlyKey && (!hasDefaultLanguage || !isValueString || hasNullMapping)) { | ||
if (isValueOnlyKey && type !== '@none' && (!hasDefaultLanguage || !isValueString || hasNullMapping)) { | ||
return value['@value']; | ||
@@ -1315,6 +1315,4 @@ } | ||
for (let ci = 0; ci < containers.length; ++ci) { | ||
for (const container of containers) { | ||
// if container not available in the map, continue | ||
const container = containers[ci]; | ||
if (!(container in containerMap)) { | ||
@@ -1326,6 +1324,4 @@ continue; | ||
for (let pi = 0; pi < prefs.length; ++pi) { | ||
for (const pref of prefs) { | ||
// if type/language option not available in the map, continue | ||
const pref = prefs[pi]; | ||
if (!(pref in typeOrLanguageValueMap)) { | ||
@@ -1332,0 +1328,0 @@ continue; |
@@ -561,3 +561,10 @@ /* | ||
if (type !== '@id' && type !== '@vocab' && type !== '@json') { | ||
if (type === '@json' || type === '@none') { | ||
if (api.processingMode(activeCtx, 1.0)) { | ||
throw new JsonLdError('Invalid JSON-LD syntax; an @context @type value must not be ' + `"${type}" in JSON-LD 1.0 mode.`, 'jsonld.SyntaxError', { | ||
code: 'invalid type mapping', | ||
context: localCtx | ||
}); | ||
} | ||
} else if (type !== '@id' && type !== '@vocab') { | ||
// expand @type to full IRI | ||
@@ -1017,2 +1024,8 @@ type = _expandIri(activeCtx, type, { | ||
_addPreferredTerm(term, entry['@type'], '@reverse'); | ||
} else if (mapping['@type'] === '@none') { | ||
_addPreferredTerm(term, entry['@any'], '@none'); | ||
_addPreferredTerm(term, entry['@language'], '@none'); | ||
_addPreferredTerm(term, entry['@type'], '@none'); | ||
} else if ('@type' in mapping) { | ||
@@ -1223,3 +1236,3 @@ // term is preferred for values using specific type | ||
api.isKeyword = v => { | ||
if (!_isString(v)) { | ||
if (!_isString(v) || v[0] !== '@') { | ||
return false; | ||
@@ -1226,0 +1239,0 @@ } |
@@ -307,2 +307,6 @@ /* | ||
}) { | ||
if (!context) { | ||
return; | ||
} | ||
const ctx = context['@context']; | ||
@@ -309,0 +313,0 @@ |
@@ -239,4 +239,6 @@ /* | ||
typeScopedContext = activeCtx; // look for scoped contexts on `@type` | ||
typeScopedContext = activeCtx; // Remember the first key found expanding to @type | ||
let typeKey = null; // look for scoped contexts on `@type` | ||
for (const key of keys) { | ||
@@ -250,2 +252,3 @@ const expandedProperty = _expandIri(activeCtx, key, { | ||
// avoid sorting if possible | ||
typeKey = typeKey || key; | ||
const value = element[key]; | ||
@@ -280,2 +283,3 @@ const types = Array.isArray(value) ? value.length > 1 ? value.slice().sort() : value : [value]; | ||
typeScopedContext, | ||
typeKey, | ||
expansionMap | ||
@@ -322,3 +326,4 @@ }); // get property count on expanded output | ||
if (values.length === 0) { | ||
if (_processingMode(activeCtx, 1.1) && types.includes('@json') && types.length === 1) {// Any value of @value is okay if @type: @json | ||
} else if (values.length === 0) { | ||
const mapped = yield expansionMap({ | ||
@@ -344,3 +349,2 @@ unmappedValue: rval, | ||
}); | ||
} else if (_processingMode(activeCtx, 1.1) && types.includes('@json') && types.length === 1) {// Any value of @value is okay if @type: @json | ||
} else if (!types.every(t => _isAbsoluteIri(t) && !(_isString(t) && t.indexOf('_:') === 0) || _isEmptyObject(t))) { | ||
@@ -461,2 +465,3 @@ throw new JsonLdError('Invalid JSON-LD syntax; an element containing "@value" and "@type" ' + 'must have an absolute IRI for the value of "@type".', 'jsonld.SyntaxError', { | ||
typeScopedContext, | ||
typeKey, | ||
expansionMap | ||
@@ -466,4 +471,8 @@ }) { | ||
const nests = []; | ||
let unexpandedValue; | ||
let unexpandedValue; // Figure out if this is the type for a JSON literal | ||
const isJsonType = element[typeKey] && _expandIri(activeCtx, _isArray(element[typeKey]) ? element[typeKey][0] : element[typeKey], { | ||
vocab: true | ||
}, options) == '@json'; | ||
for (const key of keys) { | ||
@@ -585,5 +594,10 @@ let value = element[key]; | ||
_addValue(expandedParent, '@value', value, { | ||
propertyIsArray: options.isFrame | ||
}); | ||
if (isJsonType && _processingMode(activeCtx, 1.1)) { | ||
// no coercion to array, and retain all values | ||
expandedParent['@value'] = value; | ||
} else { | ||
_addValue(expandedParent, '@value', value, { | ||
propertyIsArray: options.isFrame | ||
}); | ||
} | ||
@@ -904,2 +918,3 @@ continue; | ||
insideList, | ||
typeKey, | ||
expansionMap | ||
@@ -969,3 +984,3 @@ }); | ||
if (type && !['@id', '@vocab'].includes(type)) { | ||
if (type && !['@id', '@vocab', '@none'].includes(type)) { | ||
// other type | ||
@@ -972,0 +987,0 @@ rval['@type'] = type; |
@@ -955,3 +955,3 @@ /* | ||
// if there's no @index to preserve ... | ||
if(!preserveIndex) { | ||
if(!preserveIndex && type !== '@none') { | ||
// matching @type or @language specified in context, compact value | ||
@@ -975,2 +975,3 @@ if(value['@type'] === type || value['@language'] === language) { | ||
if(isValueOnlyKey && | ||
type !== '@none' && | ||
(!hasDefaultLanguage || !isValueString || hasNullMapping)) { | ||
@@ -1174,5 +1175,4 @@ return value['@value']; | ||
const containerMap = activeCtx.inverse[iri]; | ||
for(let ci = 0; ci < containers.length; ++ci) { | ||
for(const container of containers) { | ||
// if container not available in the map, continue | ||
const container = containers[ci]; | ||
if(!(container in containerMap)) { | ||
@@ -1183,5 +1183,4 @@ continue; | ||
const typeOrLanguageValueMap = containerMap[container][typeOrLanguage]; | ||
for(let pi = 0; pi < prefs.length; ++pi) { | ||
for(const pref of prefs) { | ||
// if type/language option not available in the map, continue | ||
const pref = prefs[pi]; | ||
if(!(pref in typeOrLanguageValueMap)) { | ||
@@ -1188,0 +1187,0 @@ continue; |
@@ -530,3 +530,11 @@ /* | ||
if(type !== '@id' && type !== '@vocab' && type !== '@json') { | ||
if((type === '@json' || type === '@none')) { | ||
if(api.processingMode(activeCtx, 1.0)) { | ||
throw new JsonLdError( | ||
'Invalid JSON-LD syntax; an @context @type value must not be ' + | ||
`"${type}" in JSON-LD 1.0 mode.`, | ||
'jsonld.SyntaxError', | ||
{code: 'invalid type mapping', context: localCtx}); | ||
} | ||
} else if(type !== '@id' && type !== '@vocab') { | ||
// expand @type to full IRI | ||
@@ -963,2 +971,6 @@ type = _expandIri( | ||
_addPreferredTerm(term, entry['@type'], '@reverse'); | ||
} else if(mapping['@type'] === '@none') { | ||
_addPreferredTerm(term, entry['@any'], '@none'); | ||
_addPreferredTerm(term, entry['@language'], '@none'); | ||
_addPreferredTerm(term, entry['@type'], '@none'); | ||
} else if('@type' in mapping) { | ||
@@ -1149,3 +1161,3 @@ // term is preferred for values using specific type | ||
api.isKeyword = v => { | ||
if(!_isString(v)) { | ||
if(!_isString(v) || v[0] !== '@') { | ||
return false; | ||
@@ -1152,0 +1164,0 @@ } |
@@ -213,2 +213,6 @@ /* | ||
function _resolveContextUrls({context, base}) { | ||
if(!context) { | ||
return; | ||
} | ||
const ctx = context['@context']; | ||
@@ -215,0 +219,0 @@ |
@@ -216,2 +216,5 @@ /* | ||
// Remember the first key found expanding to @type | ||
let typeKey = null; | ||
// look for scoped contexts on `@type` | ||
@@ -223,2 +226,3 @@ for(const key of keys) { | ||
// avoid sorting if possible | ||
typeKey = typeKey || key; | ||
const value = element[key]; | ||
@@ -253,2 +257,3 @@ const types = | ||
typeScopedContext, | ||
typeKey, | ||
expansionMap}); | ||
@@ -289,3 +294,6 @@ | ||
// drop null @values unless custom mapped | ||
if(values.length === 0) { | ||
if(_processingMode(activeCtx, 1.1) && types.includes('@json') && | ||
types.length === 1) { | ||
// Any value of @value is okay if @type: @json | ||
} else if(values.length === 0) { | ||
const mapped = await expansionMap({ | ||
@@ -311,5 +319,2 @@ unmappedValue: rval, | ||
{code: 'invalid language-tagged value', element: rval}); | ||
} else if(_processingMode(activeCtx, 1.1) && types.includes('@json') && | ||
types.length === 1) { | ||
// Any value of @value is okay if @type: @json | ||
} else if(!types.every(t => | ||
@@ -410,2 +415,3 @@ (_isAbsoluteIri(t) && !(_isString(t) && t.indexOf('_:') === 0) || | ||
typeScopedContext, | ||
typeKey, | ||
expansionMap | ||
@@ -416,2 +422,9 @@ }) { | ||
let unexpandedValue; | ||
// Figure out if this is the type for a JSON literal | ||
const isJsonType = element[typeKey] && | ||
_expandIri(activeCtx, | ||
(_isArray(element[typeKey]) ? element[typeKey][0] : element[typeKey]), | ||
{vocab: true}, options) == '@json'; | ||
for(const key of keys) { | ||
@@ -527,4 +540,9 @@ let value = element[key]; | ||
unexpandedValue = value; | ||
_addValue( | ||
expandedParent, '@value', value, {propertyIsArray: options.isFrame}); | ||
if(isJsonType && _processingMode(activeCtx, 1.1)) { | ||
// no coercion to array, and retain all values | ||
expandedParent['@value'] = value; | ||
} else { | ||
_addValue( | ||
expandedParent, '@value', value, {propertyIsArray: options.isFrame}); | ||
} | ||
continue; | ||
@@ -814,2 +832,3 @@ } | ||
insideList, | ||
typeKey, | ||
expansionMap}); | ||
@@ -867,3 +886,3 @@ } | ||
if(type && !['@id', '@vocab'].includes(type)) { | ||
if(type && !['@id', '@vocab', '@none'].includes(type)) { | ||
// other type | ||
@@ -870,0 +889,0 @@ rval['@type'] = type; |
{ | ||
"name": "jsonld", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A JSON-LD Processor and API implementation in JavaScript.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/digitalbazaar/jsonld.js", |
@@ -391,3 +391,3 @@ jsonld.js | ||
JSONLD_TESTS=./tests npm test | ||
JSONLD_TESTS=`pwd`/tests npm test | ||
@@ -394,0 +394,0 @@ To generate earl reports: |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1592911
19091