-
Notifications
You must be signed in to change notification settings - Fork 203
Expand expansion map to support calling when a relative IRI is detected #452
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
60f3bc2
9a8117f
15775b0
53048ba
229bdb1
72bb834
bc55956
1910df9
24c1e30
560b729
6045c7a
5c3dad0
fd132f5
f0b7045
57ae8a6
3814473
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 |
---|---|---|
|
@@ -478,3 +478,531 @@ describe('literal JSON', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('expansionMap', () => { | ||
describe('unmappedProperty', () => { | ||
it('should be called on unmapped term', async () => { | ||
const docWithUnMappedTerm = { | ||
'@context': { | ||
'definedTerm': 'https://example.com#definedTerm' | ||
}, | ||
definedTerm: "is defined", | ||
testUndefined: "is undefined" | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.unmappedProperty === 'testUndefined') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithUnMappedTerm, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it('should be called on nested unmapped term', async () => { | ||
const docWithUnMappedTerm = { | ||
'@context': { | ||
'definedTerm': 'https://example.com#definedTerm' | ||
}, | ||
definedTerm: { | ||
testUndefined: "is undefined" | ||
} | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.unmappedProperty === 'testUndefined') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithUnMappedTerm, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
}); | ||
|
||
describe('relativeIri', () => { | ||
it('should be called on relative iri for id term', async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
'definedTerm': 'https://example.com#definedTerm' | ||
}, | ||
'@id': "relativeiri", | ||
definedTerm: "is defined" | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === 'relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it('should be called on relative iri for id term (nested)', async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
'definedTerm': 'https://example.com#definedTerm' | ||
}, | ||
'@id': "urn:absoluteIri", | ||
definedTerm: { | ||
'@id': "relativeiri" | ||
} | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === 'relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it('should be called on relative iri for aliased id term', async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
'id': '@id', | ||
'definedTerm': 'https://example.com#definedTerm' | ||
}, | ||
'id': "relativeiri", | ||
definedTerm: "is defined" | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === 'relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it('should be called on relative iri for type term', async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
'definedTerm': 'https://example.com#definedTerm' | ||
}, | ||
'id': "urn:absoluteiri", | ||
'@type': "relativeiri", | ||
definedTerm: "is defined" | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === 'relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it('should be called on relative iri for type\ | ||
term in scoped context', async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
'definedType': { | ||
'@id': 'https://example.com#definedType', | ||
'@context': { | ||
'definedTerm': 'https://example.com#definedTerm' | ||
|
||
} | ||
} | ||
}, | ||
'id': "urn:absoluteiri", | ||
'@type': "definedType", | ||
definedTerm: { | ||
'@type': 'relativeiri' | ||
} | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === 'relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it('should be called on relative iri for \ | ||
type term with multiple relative iri types', async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
'definedTerm': 'https://example.com#definedTerm' | ||
}, | ||
'id': "urn:absoluteiri", | ||
'@type': ["relativeiri", "anotherRelativeiri" ], | ||
definedTerm: "is defined" | ||
}; | ||
|
||
let expansionMapCalledTimes = 0; | ||
const expansionMap = info => { | ||
if(info.relativeIri === 'relativeiri' || | ||
info.relativeIri === 'anotherRelativeiri') { | ||
expansionMapCalledTimes++; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalledTimes, 3); | ||
}); | ||
|
||
it('should be called on relative iri for \ | ||
type term with multiple relative iri types in scoped context', async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
'definedType': { | ||
'@id': 'https://example.com#definedType', | ||
'@context': { | ||
'definedTerm': 'https://example.com#definedTerm' | ||
|
||
} | ||
} | ||
}, | ||
'id': "urn:absoluteiri", | ||
'@type': "definedType", | ||
definedTerm: { | ||
'@type': ["relativeiri", "anotherRelativeiri" ] | ||
} | ||
}; | ||
|
||
let expansionMapCalledTimes = 0; | ||
const expansionMap = info => { | ||
if(info.relativeIri === 'relativeiri' || | ||
info.relativeIri === 'anotherRelativeiri') { | ||
expansionMapCalledTimes++; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalledTimes, 3); | ||
}); | ||
|
||
it('should be called on relative iri for \ | ||
type term with multiple types', async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
'definedTerm': 'https://example.com#definedTerm' | ||
}, | ||
'id': "urn:absoluteiri", | ||
'@type': ["relativeiri", "definedTerm" ], | ||
definedTerm: "is defined" | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === 'relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it('should be called on relative iri for aliased type term', async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
'type': "@type", | ||
'definedTerm': 'https://example.com#definedTerm' | ||
}, | ||
'id': "urn:absoluteiri", | ||
'type': "relativeiri", | ||
definedTerm: "is defined" | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === 'relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it("should be called on relative iri when \ | ||
@base value is './'", async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
"@base": "./", | ||
}, | ||
'@id': "relativeiri", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === '/relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it("should be called on relative iri when \ | ||
@base value is './'", async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
"@base": "./", | ||
}, | ||
'@id': "relativeiri", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === '/relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it("should be called on relative iri when \ | ||
@vocab value is './'", async () => { | ||
const docWithRelativeIriId = { | ||
'@context': { | ||
"@vocab": "./", | ||
}, | ||
'@type': "relativeiri", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.relativeIri === '/relativeiri') { | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(docWithRelativeIriId, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
}); | ||
|
||
describe('prependedIri', () => { | ||
it("should be called when property is \ | ||
being expanded with `@vocab`", async () => { | ||
const doc = { | ||
'@context': { | ||
"@vocab": "http://example.com/", | ||
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. was there a release that included this? 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. No, because we're working on a new "safe mode" feature right now that more cleanly and efficiently addresses the problem of "lossy" JSON that goes through JSON-LD transformations. 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. @OR13 -- a release was made with the new |
||
}, | ||
'term': "termValue", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
assert.deepStrictEqual(info.prependedIri, { | ||
type: '@vocab', | ||
vocab: 'http://example.com/', | ||
value: 'term', | ||
typeExpansion: false, | ||
result: 'http://example.com/term' | ||
}); | ||
expansionMapCalled = true; | ||
}; | ||
|
||
await jsonld.expand(doc, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it("should be called when '@type' is \ | ||
being expanded with `@vocab`", async () => { | ||
const doc = { | ||
'@context': { | ||
"@vocab": "http://example.com/", | ||
}, | ||
'@type': "relativeIri", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
assert.deepStrictEqual(info.prependedIri, { | ||
type: '@vocab', | ||
vocab: 'http://example.com/', | ||
value: 'relativeIri', | ||
typeExpansion: true, | ||
result: 'http://example.com/relativeIri' | ||
}); | ||
expansionMapCalled = true; | ||
}; | ||
|
||
await jsonld.expand(doc, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it("should be called when aliased '@type' is \ | ||
being expanded with `@vocab`", async () => { | ||
const doc = { | ||
'@context': { | ||
"@vocab": "http://example.com/", | ||
"type": "@type" | ||
}, | ||
'type': "relativeIri", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
assert.deepStrictEqual(info.prependedIri, { | ||
type: '@vocab', | ||
vocab: 'http://example.com/', | ||
value: 'relativeIri', | ||
typeExpansion: true, | ||
result: 'http://example.com/relativeIri' | ||
}); | ||
expansionMapCalled = true; | ||
}; | ||
|
||
await jsonld.expand(doc, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it("should be called when '@id' is being \ | ||
expanded with `@base`", async () => { | ||
const doc = { | ||
'@context': { | ||
"@base": "http://example.com/", | ||
}, | ||
'@id': "relativeIri", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.prependedIri) { | ||
assert.deepStrictEqual(info.prependedIri, { | ||
type: '@base', | ||
base: 'http://example.com/', | ||
value: 'relativeIri', | ||
typeExpansion: false, | ||
result: 'http://example.com/relativeIri' | ||
}); | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(doc, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it("should be called when aliased '@id' \ | ||
is being expanded with `@base`", async () => { | ||
const doc = { | ||
'@context': { | ||
"@base": "http://example.com/", | ||
"id": "@id" | ||
}, | ||
'id': "relativeIri", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.prependedIri) { | ||
assert.deepStrictEqual(info.prependedIri, { | ||
type: '@base', | ||
base: 'http://example.com/', | ||
value: 'relativeIri', | ||
typeExpansion: false, | ||
result: 'http://example.com/relativeIri' | ||
}); | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(doc, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it("should be called when '@type' is \ | ||
being expanded with `@base`", async () => { | ||
const doc = { | ||
'@context': { | ||
"@base": "http://example.com/", | ||
}, | ||
'@type': "relativeIri", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.prependedIri) { | ||
assert.deepStrictEqual(info.prependedIri, { | ||
type: '@base', | ||
base: 'http://example.com/', | ||
value: 'relativeIri', | ||
typeExpansion: true, | ||
result: 'http://example.com/relativeIri' | ||
}); | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(doc, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
|
||
it("should be called when aliased '@type' is \ | ||
being expanded with `@base`", async () => { | ||
const doc = { | ||
'@context': { | ||
"@base": "http://example.com/", | ||
"type": "@type" | ||
}, | ||
'type': "relativeIri", | ||
}; | ||
|
||
let expansionMapCalled = false; | ||
const expansionMap = info => { | ||
if(info.prependedIri) { | ||
assert.deepStrictEqual(info.prependedIri, { | ||
type: '@base', | ||
base: 'http://example.com/', | ||
value: 'relativeIri', | ||
typeExpansion: true, | ||
result: 'http://example.com/relativeIri' | ||
}); | ||
expansionMapCalled = true; | ||
} | ||
}; | ||
|
||
await jsonld.expand(doc, {expansionMap}); | ||
|
||
assert.equal(expansionMapCalled, true); | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.