diff --git a/CHANGELOG.md b/CHANGELOG.md index bd95db9..497b1bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,23 @@ # @digitalbazaar/cborld ChangeLog +## 8.0.0 - 2025-04-dd + +### Changed +- **BREAKING**: The default `format` for `encode()` is now "cbor-ld-1.0". To + generate output using pre-1.0 CBOR-LD tags (legacy tags), pass a different + format (e.g, "legacy-range" or "legacy-singleton"). +- **BREAKING**: The `registryEntryId` parameter for `encode()` can no longer + be the string "legacy"; it can only be a number. To output pre-1.0 CBOR-LD + tags 1280/1281 (0x0500/0x0501) pass "legacy-singleton" for `format`. + +### Removed +- **BREAKING**: Remove `typeTable` parameter from `encode()` and `decode()`; + use `typeTableLoader` instead. + ## 7.3.0 - 2025-04-24 ### Added -- Added new tag system for use with a single CBOR tag (0xcb1d). The tagged +- Add a new tag system for use with a single CBOR tag (0xcb1d). The tagged item is always an array of two elements. The first element is a CBOR integer representation of the registry entry ID for the payload, and the second element is the encoded JSON-LD. To use the new mode when encoding, pass diff --git a/lib/decode.js b/lib/decode.js index 408be2c..8471d87 100644 --- a/lib/decode.js +++ b/lib/decode.js @@ -16,31 +16,37 @@ import {parse} from './parser.js'; * decode. * @param {documentLoaderFunction} options.documentLoader - The document loader * to use when resolving JSON-LD Context URLs. - * @param {Map} [options.typeTable] - A map of possible value types, including - * `context`, `url`, `none`, and any JSON-LD type, each of which maps to - * another map of values of that type to their associated CBOR-LD integer - * values. - * @param {Function} [options.typeTableLoader] - The typeTable loader to use to - * resolve a registryEntryId to a typeTable. + * @param {Function} [options.typeTableLoader] - The `typeTable` loader to use + * to resolve a `registryEntryId` to a `typeTable`. A `typeTable` is a Map of + * possible value types, including `context`, `url`, `none`, and any JSON-LD + * type, each of which maps to another Map of values of that type to their + * associated CBOR-LD integer values. * @param {diagnosticFunction} [options.diagnose] - A function that, if * provided, is called with diagnostic information. - * @param {Map} [options.appContextMap] - A map of context string values - * to their associated CBOR-LD integer values. For use with legacy - * cborldBytes. + * @param {Map} [options.appContextMap] - For use with "legacy-singleton" + * formatted inputs only; a map of context string values to their associated + * CBOR-LD integer values. + * @param {*} [options.typeTable] - NOT permitted; use `typeTableLoader`. * * @returns {Promise} - The decoded JSON-LD Document. */ export async function decode({ cborldBytes, documentLoader, - typeTable, typeTableLoader, diagnose, - appContextMap = new Map(), -}) { + // for "legacy-singleton" format only + appContextMap, + // no longer permitted + typeTable +} = {}) { if(!(cborldBytes instanceof Uint8Array)) { throw new TypeError('"cborldBytes" must be a Uint8Array.'); } + // throw on `typeTable` param which is no longer permitted + if(typeTable !== undefined) { + throw new TypeError('"typeTable" is not allowed; use "typeTableLoader".'); + } // parse CBOR-LD into a header and payload const {header, payload} = parse({cborldBytes}); @@ -55,37 +61,42 @@ export async function decode({ diagnose(inspect(input, {depth: null, colors: true})); } - // lookup typeTable by id if needed + // get `typeTable` by `registryEntryId` / `format` const {format, registryEntryId} = header; if(format === 'legacy-singleton') { // generate legacy type table - typeTable = createLegacyTypeTable({typeTable, appContextMap}); + typeTable = createLegacyTypeTable({appContextMap}); + } else if(registryEntryId === 1) { + // use default table (empty) for registry entry ID `1` + typeTable = createTypeTable({typeTable}); } else { - if(typeTable && typeTableLoader) { - throw new TypeError('Use either "typeTable" or "typeTableLoader".'); - } - if(!typeTable && typeTableLoader) { - if(registryEntryId === 1) { - // use default table (empty) for registry entry ID `1` - typeTable = createTypeTable({typeTable}); - } else { - typeTable = await typeTableLoader({registryEntryId}); - } + if(typeof typeTableLoader === 'function') { + typeTable = await typeTableLoader({registryEntryId}); } - if(!typeTable) { + if(!(typeTable instanceof Map)) { throw new CborldError( 'ERR_NO_TYPETABLE', - '"typeTable" not provided or found for registryEntryId ' + + '"typeTable" not found for "registryEntryId" ' + `"${registryEntryId}".`); } + // check to make sure unsupported types not present in `typeTable` + if(typeTable.has('http://www.w3.org/2001/XMLSchema#integer') || + typeTable.has('http://www.w3.org/2001/XMLSchema#double') || + typeTable.has('http://www.w3.org/2001/XMLSchema#boolean')) { + throw new CborldError( + 'ERR_UNSUPPORTED_LITERAL_TYPE', + '"typeTable" must not contain XSD integers, doubles, or booleans.'); + } // normalize type table typeTable = createTypeTable({typeTable}); } - const converter = _createConverter({ - format, - typeTable, - documentLoader + const converter = new Converter({ + // decompress CBOR-LD => JSON-LD + strategy: new Decompressor({typeTable}), + documentLoader, + // FIXME: try to eliminate need for legacy flag + legacy: format === 'legacy-singleton' }); const output = await converter.convert({input}); if(diagnose) { @@ -95,21 +106,6 @@ export async function decode({ return output; } -// FIXME: consider making static method on `Converter` -function _createConverter({ - format, - typeTable, - documentLoader -}) { - return new Converter({ - // decompress CBOR-LD => JSON-LD - strategy: new Decompressor({typeTable}), - documentLoader, - // FIXME: try to eliminate need for legacy flag - legacy: format === 'legacy-singleton' - }); -} - /** * A diagnostic function that is called with diagnostic information. Typically * set to `console.log` when debugging. diff --git a/lib/encode.js b/lib/encode.js index a3feea7..afcc6e3 100644 --- a/lib/encode.js +++ b/lib/encode.js @@ -27,55 +27,42 @@ const typeEncoders = { * CBOR-LD bytes. * @param {documentLoaderFunction} options.documentLoader - The document loader * to use when resolving JSON-LD Context URLs. - * @param {number|string} [options.registryEntryId='legacy'] - The registry + * @param {string} [options.format='cbor-ld-1.0'] - The CBOR-LD output format + * to use; this will default to `cbor-ld-1.0` to use CBOR-LD 1.0 tag + * `0xcb1d` (51997); to create output with a pre-1.0 CBOR-LD tag, then + * 'legacy-range' can be passed to use tags `0x0600-0x06ff` (1526-1791) and + * 'legacy-singleton' can be passed to use tags `0x0500-0x0501`. +* @param {number|string} [options.registryEntryId] - The registry * entry ID for the registry entry associated with the resulting CBOR-LD - * payload. For legacy singleton support, use registryEntryId = 'legacy'. - * @param {string} [options.format] - The CBOR-LD output format to use; this - * SHOULD be set by the caller to `cbor-ld-1.0` to use CBOR-LD 1.0 tag - * `0xcb1d` (51997); if this is not provided, then for backwards - * compatibility purposes, `registryEntryId` will control which legacy tags - * are used (if `registryEntryId` is a number, then the output will use tags - * `0x0600-0x06ff` (1526-1791) and if it is the string 'legacy' then it will - * use tags `0x0500-0x0501` depending on `compressionMode`). - * @param {Map} [options.typeTable] - A map of possible value types, including - * `context`, `url`, `none`, and any JSON-LD type, each of which maps to - * another map of values of that type to their associated CBOR-LD integer - * values; can only be used if a number if provided for `registryEntryId`. - * @param {Function} [options.typeTableLoader] - The loader to use to resolve - * a `registryEntryId` to a `typeTable`; can only be used if a number is - * provided for `registryEntryId`. + * payload. + * @param {Function} [options.typeTableLoader] - The `typeTable` loader to use + * to resolve `registryEntryId` to a `typeTable`. A `typeTable` is a Map of + * possible value types, including `context`, `url`, `none`, and any JSON-LD + * type, each of which maps to another Map of values of that type to their + * associated CBOR-LD integer values. * @param {diagnosticFunction} [options.diagnose] - A function that, if * provided, is called with diagnostic information. - * @param {Map} [options.appContextMap] - For use with the 'legacy' value of - * `registryEntryId`. - * @param {number} [options.compressionMode] - For use with the 'legacy' value - * of `registryEntryId`. + * @param {Map} [options.appContextMap] - Only for use with the + * 'legacy-singleton' format. + * @param {number} [options.compressionMode] - Only for use with the + * 'legacy-singleton' format. + * @param {*} [options.typeTable] - NOT permitted; use `typeTableLoader`. * * @returns {Promise} - The encoded CBOR-LD bytes. */ export async function encode({ jsonldDocument, documentLoader, - format, - registryEntryId = 'legacy', - typeTable, + format = 'cbor-ld-1.0', + registryEntryId, typeTableLoader, diagnose, + // for "legacy-singleton" format only appContextMap, - compressionMode + compressionMode, + // no longer permitted + typeTable } = {}) { - // validate that an acceptable value for `registryEntryId` was passed - if(!((typeof registryEntryId === 'number' && registryEntryId >= 0) || - registryEntryId === 'legacy')) { - throw new TypeError( - '"registryEntryId" must be either an integer or `legacy`.'); - } - - // if `format` is undefined, determine it based on other parameters... - if(format === undefined) { - format = registryEntryId === 'legacy' ? 'legacy-singleton' : 'legacy-range'; - } - // validate `format` if(!(format === 'cbor-ld-1.0' || format === 'legacy-range' || format === 'legacy-singleton')) { @@ -85,22 +72,21 @@ export async function encode({ '"legacy-range" (tags 0x0600-0x06ff = 1536-1791) or ' + '"legacy-singleton" (tags 0x0500-0x0501 = 1280-1281).'); } + // throw on `typeTable` param which is no longer permitted + if(typeTable !== undefined) { + throw new TypeError('"typeTable" is not allowed; use "typeTableLoader".'); + } // validate parameter combinations let compressPayload; if(format === 'legacy-singleton') { - if(registryEntryId !== 'legacy') { - throw new TypeError( - '"registryEntryId" must be set to "legacy" to use ' + - 'the "legacy-singleton" format'); - } - if(typeTable !== undefined) { + if(registryEntryId !== undefined) { throw new TypeError( - '"typeTable" must only be passed when "registryEntryId" is a number.'); + '"registryEntryId" must not be used with format "legacy-singleton".'); } if(typeTableLoader !== undefined) { throw new TypeError( - '"typeTable" must only be passed when "registryEntryId" is a number.'); + '"typeTableLoader" must not be used with format "legacy-singleton".'); } // default compression mode to `1` @@ -115,47 +101,45 @@ export async function encode({ // generate legacy type table typeTable = createLegacyTypeTable({typeTable, appContextMap}); } else { + // validate that an acceptable value for `registryEntryId` was passed + if(!(typeof registryEntryId === 'number' && registryEntryId >= 0)) { + throw new TypeError('"registryEntryId" must be a non-negative integer.'); + } + if(appContextMap !== undefined) { throw new TypeError( - '"appContextMap" must only be passed in "legacy" mode.'); + '"appContextMap" must only be used with format "legacy-singleton".'); } if(compressionMode !== undefined) { throw new TypeError( - '"compressionMode" must only be passed in "legacy" mode.'); - } - if(typeTable !== undefined) { - if(typeTableLoader !== undefined) { - throw new TypeError('Use either "typeTable" or "typeTableLoader".'); - } - if(!(typeTable instanceof Map)) { - throw new TypeError('"typeTable" must be a Map.'); - } - } else if(registryEntryId === 1) { - // use default table (empty) for registry entry ID `1` - typeTable = createTypeTable({typeTable}); - } else if(typeTableLoader) { - if(typeof typeTableLoader !== 'function') { - throw new TypeError('"typeTableLoader" must be a function.'); - } - typeTable = await typeTableLoader({registryEntryId}); + '"compressionMode" must only be used with format "legacy-singleton".'); } if(registryEntryId !== 0) { - if(!typeTable) { - throw new CborldError( - 'ERR_NO_TYPETABLE', - '"typeTable" not provided or found for "registryEntryId" ' + - `"${registryEntryId}".`); - } - // check to make sure unsupported types not present in `typeTable` - if(typeTable.has('http://www.w3.org/2001/XMLSchema#integer') || - typeTable.has('http://www.w3.org/2001/XMLSchema#double') || - typeTable.has('http://www.w3.org/2001/XMLSchema#boolean')) { - throw new CborldError( - 'ERR_UNSUPPORTED_LITERAL_TYPE', - '"typeTable" must not contain XSD integers, doubles, or booleans.'); + if(registryEntryId === 1) { + // use default table (empty) for registry entry ID `1` + typeTable = createTypeTable({typeTable}); + } else { + if(typeof typeTableLoader !== 'function') { + throw new TypeError('"typeTableLoader" must be a function.'); + } + typeTable = await typeTableLoader({registryEntryId}); + if(!(typeTable instanceof Map)) { + throw new CborldError( + 'ERR_NO_TYPETABLE', + '"typeTable" not found for "registryEntryId" ' + + `"${registryEntryId}".`); + } + // check to make sure unsupported types not present in `typeTable` + if(typeTable.has('http://www.w3.org/2001/XMLSchema#integer') || + typeTable.has('http://www.w3.org/2001/XMLSchema#double') || + typeTable.has('http://www.w3.org/2001/XMLSchema#boolean')) { + throw new CborldError( + 'ERR_UNSUPPORTED_LITERAL_TYPE', + '"typeTable" must not contain XSD integers, doubles, or booleans.'); + } + // normalize type table + typeTable = createTypeTable({typeTable}); } - // normalize type table - typeTable = createTypeTable({typeTable}); } // any registry entry ID other than zero uses compression by default compressPayload = registryEntryId !== 0; @@ -167,7 +151,12 @@ export async function encode({ // output uncompressed CBOR-LD suffix = cborg.encode(jsonldDocument); } else { - const converter = _createConverter({format, typeTable, documentLoader}); + const converter = new Converter({ + // compress JSON-LD => CBOR-LD + strategy: new Compressor({typeTable}), + documentLoader, + legacy: format === 'legacy-singleton' + }); const output = await converter.convert({input: jsonldDocument}); if(diagnose) { diagnose('Diagnostic CBOR-LD compression transform map(s):'); @@ -235,15 +224,6 @@ function _getPrefix({format, compressionMode, registryEntryId}) { ]); } -function _createConverter({format, typeTable, documentLoader}) { - return new Converter({ - // compress JSON-LD => CBOR-LD - strategy: new Compressor({typeTable}), - documentLoader, - legacy: format === 'legacy-singleton' - }); -} - /** * A diagnostic function that is called with diagnostic information. Typically * set to `console.log` when debugging. diff --git a/tests/decode.spec.js b/tests/decode.spec.js index 66a70d7..ff329d9 100644 --- a/tests/decode.spec.js +++ b/tests/decode.spec.js @@ -22,23 +22,17 @@ function _makeTypeTableLoader(entries) { } describe('cborld decode', () => { - it('should decode CBOR-LD bytes (direct type table)', + it('should decode CBOR-LD bytes (no type table loader)', async () => { const cborldBytes = new Uint8Array([0xd9, 0xcb, 0x1d, 0x82, 0x01, 0xa0]); - const jsonldDocument = await decode({ - cborldBytes, - typeTable: new Map() - }); + const jsonldDocument = await decode({cborldBytes}); expect(jsonldDocument).deep.equal({}); }); it('should decode CBOR-LD bytes (no compression)', async () => { const cborldBytes = new Uint8Array([0xd9, 0xcb, 0x1d, 0x82, 0x00, 0xa0]); - const jsonldDocument = await decode({ - cborldBytes, - typeTable: new Map() - }); + const jsonldDocument = await decode({cborldBytes}); expect(jsonldDocument).deep.equal({}); }); @@ -54,7 +48,7 @@ describe('cborld decode', () => { it('should fail to decode with no typeTable or typeTableLoader', async () => { - const cborldBytes = new Uint8Array([0xd9, 0xcb, 0x1d, 0x82, 0x01, 0xa0]); + const cborldBytes = new Uint8Array([0xd9, 0xcb, 0x1d, 0x82, 0x02, 0xa0]); let result; let error; try { @@ -85,7 +79,7 @@ describe('cborld decode', () => { expect(error?.code).to.eql('ERR_NO_TYPETABLE'); }); - it('should fail with typeTable and typeTableLoader', + it('should fail with typeTable', async () => { const cborldBytes = new Uint8Array([0xd9, 0xcb, 0x1d, 0x82, 0x01, 0xa0]); let result; @@ -93,8 +87,7 @@ describe('cborld decode', () => { try { result = await decode({ cborldBytes, - typeTable: new Map(), - typeTableLoader: _makeTypeTableLoader([]) + typeTable: new Map() }); } catch(e) { error = e; @@ -179,7 +172,7 @@ describe('cborld decode', () => { result = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); } catch(e) { error = e; @@ -226,7 +219,7 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -278,7 +271,7 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -326,13 +319,13 @@ describe('cborld decode', () => { jsonldDocument, registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -378,7 +371,7 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -422,7 +415,7 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -466,7 +459,7 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -515,7 +508,7 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -563,7 +556,7 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -611,7 +604,7 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -658,7 +651,7 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -705,14 +698,15 @@ describe('cborld decode', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); it('should decode a CIT type token', async () => { + // note: CIT type tokens are presently only encoded using tag 0x0501 const cborldBytes = _hexToUint8Array( - 'd9cb1d8201a40015186c1864186e4c7ad90501a2011987430518411870583b7a' + + 'd90501a40015186c1864186e4c7ad90501a2011987430518411870583b7a' + '0000e190818fdd92908425370e0b5dad9ad92dc956b5ec2ab41ce76b8c70' + 'cb859a7c88ca6ba68b1ff238a70ed674999b6ff5179b0ebb10140b23'); @@ -796,12 +790,9 @@ describe('cborld decode', () => { payload: 'z1177JK4h25dHEAXAVMUMpn2zWcxLCeMLP3oVFQFQ11xHFtE9BhyoU2g47D6Xod1Mu99JR9YJdY184HY' }; - const typeTable = new Map(TYPE_TABLE); - const decodedDocument = await decode({ cborldBytes, - documentLoader, - typeTable + documentLoader }); expect(decodedDocument).to.eql(jsonldDocument); diff --git a/tests/encode.spec.js b/tests/encode.spec.js index b0c703f..8aa942b 100644 --- a/tests/encode.spec.js +++ b/tests/encode.spec.js @@ -46,32 +46,19 @@ describe('cborld encode', () => { expect(cborldBytes).equalBytes('d9cb1d8201a0'); }); - it('should encode an empty JSON-LD Document (direct type table)', + it('should encode an empty JSON-LD Document (type table loader)', async () => { const jsonldDocument = {}; const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', registryEntryId: 2, - typeTable: new Map() + typeTableLoader: _makeTypeTableLoader([[2, new Map()]]) }); expect(cborldBytes).instanceof(Uint8Array); expect(cborldBytes).equalBytes('d9cb1d8202a0'); }); - it('should encode an empty JSON-LD Document (type table loader)', - async () => { - const jsonldDocument = {}; - const cborldBytes = await encode({ - jsonldDocument, - format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTableLoader: _makeTypeTableLoader([[1, new Map()]]) - }); - expect(cborldBytes).instanceof(Uint8Array); - expect(cborldBytes).equalBytes('d9cb1d8201a0'); - }); - it('should fail to encode with no typeTableLoader id found', async () => { const jsonldDocument = {}; @@ -91,7 +78,7 @@ describe('cborld encode', () => { expect(error?.code).to.eql('ERR_NO_TYPETABLE'); }); - it('should fail with typeTable and typeTableLoader', + it('should fail with typeTable', async () => { const jsonldDocument = {}; let result; @@ -101,8 +88,7 @@ describe('cborld encode', () => { jsonldDocument, format: 'cbor-ld-1.0', registryEntryId: 1, - typeTable: new Map(), - typeTableLoader: _makeTypeTableLoader([]) + typeTable: new Map() }); } catch(e) { error = e; @@ -204,7 +190,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d9cb1d8202a20019800018661a6070bb5f'); }); @@ -252,7 +238,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d9cb1d8202a2001980001866428001'); }); @@ -296,7 +282,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d9cb1d8202a20019800018661a606f9900'); }); @@ -343,7 +329,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a600198000' + @@ -424,7 +410,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a800198000' + @@ -491,7 +477,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a200198000186583444d010203447a0102034475010203'); @@ -540,7 +526,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a300198000021864186783444d010203447a0102034475010203'); @@ -588,7 +574,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a20019800063666f6f83654d41514944647a4c6470657541514944'); @@ -641,7 +627,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( // type 'Foo', etc. @@ -696,7 +682,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a2001980001864a1186783444d010203447a0102034475010203'); @@ -751,7 +737,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a2001980001864a21866a1' + @@ -807,7 +793,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( // type 'Foo', etc. @@ -872,7 +858,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a200198000' + @@ -928,7 +914,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a20019800063666f6f83654d41514944647a4c6470657541514944'); @@ -994,7 +980,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( // type Foo, etc. @@ -1049,7 +1035,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); } catch(e) { error = e; @@ -1103,7 +1089,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); } catch(e) { error = e; @@ -1154,7 +1140,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d9cb1d8202a200198000021864'); }); @@ -1203,7 +1189,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a2001980001866a1186467616c6c6f776564'); @@ -1255,7 +1241,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a200198000186583198001198002198003'); @@ -1302,7 +1288,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d9cb1d8202a200198000186583010203'); }); @@ -1348,7 +1334,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a30019800018661a6070bb5f186882035075ef3fcc9ae311eb8e3e' + @@ -1396,7 +1382,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a30019800018661a6070bb5f1868820378243735454633464343' + @@ -1444,7 +1430,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a30019800018661a6070bb5f186882026c746573742e6578616d706c65'); @@ -1495,14 +1481,14 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a30019800018661a6070bb5f1868428001'); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1548,7 +1534,7 @@ describe('cborld encode', () => { format: 'cbor-ld-1.0', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd9cb1d8202a30019800018661a6070bb5f186882016c746573742e6578616d706c65'); diff --git a/tests/examples.spec.js b/tests/examples.spec.js index da756aa..4c75432 100644 --- a/tests/examples.spec.js +++ b/tests/examples.spec.js @@ -84,6 +84,7 @@ describe('cborld examples', () => { const expectedCborldBytes = await fsp.readFile(cfn, null); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader }); expect(cborldBytes).equalBytes(expectedCborldBytes); diff --git a/tests/roundtrip.spec.js b/tests/roundtrip.spec.js index 12cfb97..de8a369 100644 --- a/tests/roundtrip.spec.js +++ b/tests/roundtrip.spec.js @@ -58,13 +58,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -112,13 +112,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 20, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -166,13 +166,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 200, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -220,13 +220,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 2000, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -274,13 +274,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 200000, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -328,13 +328,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 20000000000, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -354,12 +354,12 @@ describe('cborld round trip', () => { jsonldDocument, format: 'cbor-ld-1.0', registryEntryId: 1, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -380,12 +380,12 @@ describe('cborld round trip', () => { jsonldDocument, format: 'cbor-ld-1.0', registryEntryId: 1, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -428,12 +428,12 @@ describe('cborld round trip', () => { jsonldDocument, format: 'cbor-ld-1.0', registryEntryId: 1, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -460,12 +460,12 @@ describe('cborld round trip', () => { jsonldDocument, format: 'cbor-ld-1.0', registryEntryId: 1, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -485,11 +485,11 @@ describe('cborld round trip', () => { jsonldDocument, format: 'cbor-ld-1.0', registryEntryId: 1, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -516,13 +516,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -556,14 +556,14 @@ describe('cborld round trip', () => { jsonldDocument, format: 'cbor-ld-1.0', registryEntryId: 1, - typeTable, + typeTableLoader: () => typeTable, documentLoader }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -602,13 +602,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -641,13 +641,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -692,13 +692,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -739,12 +739,12 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -797,13 +797,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -843,13 +843,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -901,13 +901,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -953,13 +953,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1017,13 +1017,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1092,13 +1092,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', registryEntryId: 1, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1143,13 +1143,13 @@ describe('cborld round trip', () => { format: 'cbor-ld-1.0', documentLoader, registryEntryId: 1, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql({ @@ -1201,13 +1201,13 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, + registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( - 'd9cb1d8201a300198744186581831904015822ed0194966b7c08e4' + + 'd9cb1d8202a300198744186581831904015822ed0194966b7c08e4' + '05775f8de6cc1c4508f6eb227403e1025b2c8ad2d7477398c5' + 'b25822ed0194966b7c08e405775f8de6cc1c4508f6eb227403' + 'e1025b2c8ad2d7477398c5b21866821904015822ed0194966b' + @@ -1217,7 +1217,7 @@ describe('cborld round trip', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); @@ -1267,13 +1267,13 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, + registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( - 'd9cb1d8201a300198744186581831904005822ed0194966b7c08e4' + + 'd9cb1d8202a300198744186581831904005822ed0194966b7c08e4' + '05775f8de6cc1c4508f6eb227403e1025b2c8ad2d7477398c5' + 'b25822ed0194966b7c08e405775f8de6cc1c4508f6eb227403' + 'e1025b2c8ad2d7477398c5b21866821904005822ed0194966b' + @@ -1283,7 +1283,7 @@ describe('cborld round trip', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); @@ -1306,12 +1306,12 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 2, + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1333,12 +1333,12 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 2, + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1354,13 +1354,10 @@ describe('cborld round trip', () => { foo: [-1, 0, 1, true, false, 1.1, 1.0, -1.1, 'text'] }; - const typeTable = new Map(TYPE_TABLE); - const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 1 }); expect(cborldBytes).equalBytes( @@ -1368,8 +1365,7 @@ describe('cborld round trip', () => { 'f5f4fb3ff199999999999a01fbbff199999999999a6474657874'); const decodedDocument = await decode({ - cborldBytes, - typeTable + cborldBytes }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1393,17 +1389,17 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 2, + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( - 'd9cb1d8201a200a163666f6f6665783a666f6f186589200001' + + 'd9cb1d8202a200a163666f6f6665783a666f6f186589200001' + 'f5f4fb3ff199999999999a01fbbff199999999999a6474657874'); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1428,16 +1424,16 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 2, + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( - 'd9cb1d8201a200a163666f6f6665783a666f6f186589200001' + + 'd9cb1d8202a200a163666f6f6665783a666f6f186589200001' + 'f5f4fb3ff199999999999a01fbbff199999999999a4101'); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1462,12 +1458,12 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 2, + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1486,13 +1482,10 @@ describe('cborld round trip', () => { foo: [-1, 0, 1, true, false, 1.1, 1.0, -1.1, 'text'] }; - const typeTable = new Map(TYPE_TABLE); - const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 1 }); expect(cborldBytes).equalBytes( @@ -1501,10 +1494,7 @@ describe('cborld round trip', () => { 'f5f4fb3ff199999999999a01fbbff199999999999a6474' + '657874'); - const decodedDocument = await decode({ - cborldBytes, - typeTable - }); + const decodedDocument = await decode({cborldBytes}); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1520,23 +1510,17 @@ describe('cborld round trip', () => { foo: 1 }; - const typeTable = new Map(TYPE_TABLE); - const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 1 }); expect(cborldBytes).equalBytes( 'd9cb1d8201a200a2634069646665783a666f6f654074797065' + '6b65783a536f6d655479706563666f6f01'); - const decodedDocument = await decode({ - cborldBytes, - typeTable - }); + const decodedDocument = await decode({cborldBytes}); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1562,17 +1546,17 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 2, + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( - 'd9cb1d8201a200a163666f6fa2634069646665783a666f6f65' + + 'd9cb1d8202a200a163666f6fa2634069646665783a666f6f65' + '40747970656b65783a536f6d655479706518644101'); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1599,19 +1583,19 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 2, + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( - 'd9cb1d8201a200a163666f6fa2634069646665783a666f6f65' + + 'd9cb1d8202a200a163666f6fa2634069646665783a666f6f65' + '40747970656b65783a536f6d655479706518658941ff41' + '004101f5f4fb3ff199999999999a4101fbbff199999999' + '999a6474657874'); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1639,19 +1623,19 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, - typeTable + registryEntryId: 2, + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( - 'd9cb1d8201a200a163666f6fa2634069646665783a666f6f65' + + 'd9cb1d8202a200a163666f6fa2634069646665783a666f6f65' + '40747970656b65783a536f6d655479706518658941ff41' + '004101f5f4fb3ff199999999999a4101fbbff199999999' + '999a01'); const decodedDocument = await decode({ cborldBytes, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1683,32 +1667,32 @@ describe('cborld round trip', () => { { name: 'empty plain data: (1)', data: 'data:', - cborldHex: 'd9cb1d8201a2001980001864820460' + cborldHex: 'd9cb1d8202a2001980001864820460' }, { name: 'empty plain data: (2)', data: 'data:,', - cborldHex: 'd9cb1d8201a20019800018648204612c' + cborldHex: 'd9cb1d8202a20019800018648204612c' }, { name: 'empty plain data: set (1)', data: ['data:', 'data:'], - cborldHex: 'd9cb1d8201a200198000186582820460820460' + cborldHex: 'd9cb1d8202a200198000186582820460820460' }, { name: 'empty plain data: set (2)', data: ['other:url', 'data:'], - cborldHex: 'd9cb1d8201a200198000186582696f746865723a75726c820460' + cborldHex: 'd9cb1d8202a200198000186582696f746865723a75726c820460' }, { name: 'empty base64 data:', data: 'data:;base64,', - cborldHex: 'd9cb1d8201a200198000186483046040' + cborldHex: 'd9cb1d8202a200198000186483046040' }, { name: 'empty typed base64 data:', data: 'data:image/gif;base64,', - cborldHex: 'd9cb1d8201a2001980001864830469696d6167652f67696640' + cborldHex: 'd9cb1d8202a2001980001864830469696d6167652f67696640' }, { name: 'base64 data:', @@ -1716,7 +1700,7 @@ describe('cborld round trip', () => { 'data:image/gif;base64,' + 'R0lGODdhAQABAIABAAAAAAAAACwAAAAAAQABAAACAkwBADs=', cborldHex: - 'd9cb1d8201a2001980001864830469696d6167652f6769665823474946383761010001008001000000000000002c00000000010001000002024c01003b' + 'd9cb1d8202a2001980001864830469696d6167652f6769665823474946383761010001008001000000000000002c00000000010001000002024c01003b' }, { name: 'base64 data: set', @@ -1727,7 +1711,7 @@ describe('cborld round trip', () => { 'R0lGODdhAQABAIABAAAAAAAAACwAAAAAAQABAAACAkwBADs=', ], cborldHex: - 'd9cb1d8201a200198000186582830469696d6167652f6769665823474946383761010001008001000000000000002c00000000010001000002024c01003b830469696d6167652f6769665823474946383761010001008001000000000000002c00000000010001000002024c01003b' + 'd9cb1d8202a200198000186582830469696d6167652f6769665823474946383761010001008001000000000000002c00000000010001000002024c01003b830469696d6167652f6769665823474946383761010001008001000000000000002c00000000010001000002024c01003b' }, { name: 'non-base64 data:', @@ -1735,7 +1719,7 @@ describe('cborld round trip', () => { 'data:text/plain,' + 'test', cborldHex: - 'd9cb1d8201a200198000186482046f746578742f706c61696e2c74657374' + 'd9cb1d8202a200198000186482046f746578742f706c61696e2c74657374' }, { name: 'bad base64 data:', @@ -1744,21 +1728,21 @@ describe('cborld round trip', () => { 'data:image/gif;base64,' + 'R0lGODdhAQABAIABAAAAAAAAACwAAAAAAQABAAACAkwBADs', cborldHex: - 'd9cb1d8201a200198000186482047840696d6167652f6769663b6261736536342c52306c474f4464684151414241494142414141414141414141437741414141414151414241414143416b7742414473' + 'd9cb1d8202a200198000186482047840696d6167652f6769663b6261736536342c52306c474f4464684151414241494142414141414141414141437741414141414151414241414143416b7742414473' }, { // RFC2397 example name: 'plain text', data: 'data:,A%20brief%20note', cborldHex: - 'd9cb1d8201a20019800018648204712c4125323062726965662532306e6f7465' + 'd9cb1d8202a20019800018648204712c4125323062726965662532306e6f7465' }, { // RFC2397 example name: 'plain text with charset:', data: 'data:text/plain;charset=iso-8859-7,%be%fg%be', cborldHex: - 'd9cb1d8201a200198000186482047827746578742f706c61696e3b636861727365743d69736f2d383835392d372c256265256667256265' + 'd9cb1d8202a200198000186482047827746578742f706c61696e3b636861727365743d69736f2d383835392d372c256265256667256265' }, { // RFC2397 example @@ -1767,21 +1751,21 @@ describe('cborld round trip', () => { 'data:application/vnd-xxx-query,' + 'select_vcount,fcol_from_fieldtable/local', cborldHex: - 'd9cb1d8201a2001980001864820478426170706c69636174696f6e2f766e642d7878782d71756572792c73656c6563745f76636f756e742c66636f6c5f66726f6d5f6669656c647461626c652f6c6f63616c' + 'd9cb1d8202a2001980001864820478426170706c69636174696f6e2f766e642d7878782d71756572792c73656c6563745f76636f756e742c66636f6c5f66726f6d5f6669656c647461626c652f6c6f63616c' }, { // MDN example name: 'plain text', data: 'data:,Hello%2C%20World%21', cborldHex: - 'd9cb1d8201a20019800018648204742c48656c6c6f253243253230576f726c64253231' + 'd9cb1d8202a20019800018648204742c48656c6c6f253243253230576f726c64253231' }, { // MDN example name: 'base64 plain text', data: 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==', cborldHex: - 'd9cb1d8201a200198000186483046a746578742f706c61696e4d48656c6c6f2c20576f726c6421' + 'd9cb1d8202a200198000186483046a746578742f706c61696e4d48656c6c6f2c20576f726c6421' }, { // MDN example @@ -1789,7 +1773,7 @@ describe('cborld round trip', () => { data: 'data:text/html,%3Cscript%3Ealert%28%27hi%27%29%3B%3C%2Fscript%3E', cborldHex: - 'd9cb1d8201a20019800018648204783b746578742f68746d6c2c253343736372697074253345616c6572742532382532376869253237253239253342253343253246736372697074253345' + 'd9cb1d8202a20019800018648204783b746578742f68746d6c2c253343736372697074253345616c6572742532382532376869253237253239253342253343253246736372697074253345' } ]; /* eslint-enable max-len */ @@ -1814,9 +1798,9 @@ describe('cborld round trip', () => { const cborldBytes = await encode({ jsonldDocument, format: 'cbor-ld-1.0', - registryEntryId: 1, + registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes(d.cborldHex); @@ -1824,7 +1808,7 @@ describe('cborld round trip', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); diff --git a/tests/test.legacy-range.spec.js b/tests/test.legacy-range.spec.js index 27f43fd..c024855 100644 --- a/tests/test.legacy-range.spec.js +++ b/tests/test.legacy-range.spec.js @@ -29,6 +29,7 @@ describe('legacy cborld (range)', () => { const jsonldDocument = {}; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 0 }); expect(cborldBytes).instanceof(Uint8Array); @@ -40,31 +41,33 @@ describe('legacy cborld (range)', () => { const jsonldDocument = {}; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 1 }); expect(cborldBytes).instanceof(Uint8Array); expect(cborldBytes).equalBytes('d90601a0'); }); - it('should encode an empty JSON-LD Document (direct type table)', + it('should encode an empty JSON-LD Document w/empty type table', async () => { const jsonldDocument = {}; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, - typeTable: new Map() + typeTableLoader: () => new Map() }); expect(cborldBytes).instanceof(Uint8Array); expect(cborldBytes).equalBytes('d90602a0'); }); - it('should encode an empty JSON-LD Document (type table loader)', + it('should encode an empty JSON-LD Document (no type table loader)', async () => { const jsonldDocument = {}; const cborldBytes = await encode({ jsonldDocument, - registryEntryId: 1, - typeTableLoader: _makeTypeTableLoader([[1, new Map()]]) + format: 'legacy-range', + registryEntryId: 1 }); expect(cborldBytes).instanceof(Uint8Array); expect(cborldBytes).equalBytes('d90601a0'); @@ -78,6 +81,7 @@ describe('legacy cborld (range)', () => { try { result = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, typeTableLoader: _makeTypeTableLoader([]) }); @@ -88,7 +92,25 @@ describe('legacy cborld (range)', () => { expect(error?.code).to.eql('ERR_NO_TYPETABLE'); }); - it('should fail with typeTable and typeTableLoader', + it('should fail with no typeTableLoader', + async () => { + const jsonldDocument = {}; + let result; + let error; + try { + result = await encode({ + jsonldDocument, + format: 'legacy-range', + registryEntryId: 2 + }); + } catch(e) { + error = e; + } + expect(result).to.eql(undefined); + expect(error?.name).to.eql('TypeError'); + }); + + it('should fail with typeTable', async () => { const jsonldDocument = {}; let result; @@ -96,9 +118,9 @@ describe('legacy cborld (range)', () => { try { result = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 1, - typeTable: new Map(), - typeTableLoader: _makeTypeTableLoader([]) + typeTable: new Map() }); } catch(e) { error = e; @@ -111,6 +133,7 @@ describe('legacy cborld (range)', () => { const jsonldDocument = {}; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 1, typeTableLoader: _makeTypeTableLoader([[1, new Map()]]) }); @@ -124,6 +147,7 @@ describe('legacy cborld (range)', () => { const registryEntryId = 16; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId, typeTableLoader: _makeTypeTableLoader([[16, new Map()]]) }); @@ -137,6 +161,7 @@ describe('legacy cborld (range)', () => { const registryEntryId = 128; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId, typeTableLoader: _makeTypeTableLoader([[128, new Map()]]) }); @@ -150,6 +175,7 @@ describe('legacy cborld (range)', () => { const registryEntryId = 1000000000; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId, typeTableLoader: _makeTypeTableLoader([[1000000000, new Map()]]) }); @@ -193,9 +219,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d90602a20019800018661a6070bb5f'); }); @@ -240,9 +267,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d90602a2001980001866428001'); }); @@ -283,9 +311,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d90602a20019800018661a606f9900'); }); @@ -329,9 +358,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a600198000' + @@ -409,9 +439,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a800198000' + @@ -475,9 +506,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a200198000186583444d010203447a0102034475010203'); @@ -523,9 +555,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a300198000021864186783444d010203447a0102034475010203'); @@ -570,9 +603,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a20019800063666f6f83654d41514944647a4c6470657541514944'); @@ -622,9 +656,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( // type 'Foo', etc. @@ -676,9 +711,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a2001980001864a1186783444d010203447a0102034475010203'); @@ -730,9 +766,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a2001980001864a21866a1' + @@ -785,9 +822,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( // type 'Foo', etc. @@ -849,9 +887,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a200198000' + @@ -904,9 +943,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a20019800063666f6f83654d41514944647a4c6470657541514944'); @@ -969,9 +1009,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( // type Foo, etc. @@ -1023,9 +1064,10 @@ describe('legacy cborld (range)', () => { try { result = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); } catch(e) { error = e; @@ -1076,9 +1118,10 @@ describe('legacy cborld (range)', () => { try { result = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); } catch(e) { error = e; @@ -1126,9 +1169,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d90602a200198000021864'); }); @@ -1174,9 +1218,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a2001980001866a1186467616c6c6f776564'); @@ -1225,9 +1270,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a200198000186583198001198002198003'); @@ -1271,9 +1317,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes('d90602a200198000186583010203'); }); @@ -1316,9 +1363,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a30019800018661a6070bb5f186882035075ef3fcc9ae311eb8e3e' + @@ -1363,9 +1411,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a30019800018661a6070bb5f1868820378243735454633464343' + @@ -1410,9 +1459,10 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a30019800018661a6070bb5f186882026c746573742e6578616d706c65'); @@ -1460,16 +1510,17 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a30019800018661a6070bb5f1868428001'); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1512,34 +1563,22 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(cborldBytes).equalBytes( 'd90602a30019800018661a6070bb5f186882016c746573742e6578616d706c65'); }); }); describe('decode', () => { - it('should decode CBOR-LD bytes (direct type table)', - async () => { - const cborldBytes = new Uint8Array([0xd9, 0x06, 0x01, 0xa0]); - const jsonldDocument = await decode({ - cborldBytes, - typeTable: new Map() - }); - expect(jsonldDocument).deep.equal({}); - }); - it('should decode CBOR-LD bytes (no compression)', async () => { const cborldBytes = new Uint8Array([ 0xd9, 0x06, 0x00, 0x82, 0x00, 0xa0 ]); - const jsonldDocument = await decode({ - cborldBytes, - typeTable: new Map() - }); + const jsonldDocument = await decode({cborldBytes}); expect(jsonldDocument).deep.equal({}); }); @@ -1553,15 +1592,13 @@ describe('legacy cborld (range)', () => { expect(jsonldDocument).deep.equal({}); }); - it('should fail to decode with no typeTable or typeTableLoader', + it('should fail to decode with no typeTableLoader', async () => { - const cborldBytes = new Uint8Array([0xd9, 0x06, 0x01, 0xa0]); + const cborldBytes = new Uint8Array([0xd9, 0x06, 0x02, 0xa0]); let result; let error; try { - result = await decode({ - cborldBytes - }); + result = await decode({cborldBytes}); } catch(e) { error = e; } @@ -1586,7 +1623,7 @@ describe('legacy cborld (range)', () => { expect(error?.code).to.eql('ERR_NO_TYPETABLE'); }); - it('should fail with typeTable and typeTableLoader', + it('should fail with no typeTableLoader', async () => { const cborldBytes = new Uint8Array([0xd9, 0x06, 0x01, 0xa0]); let result; @@ -1594,8 +1631,7 @@ describe('legacy cborld (range)', () => { try { result = await decode({ cborldBytes, - typeTable: new Map(), - typeTableLoader: _makeTypeTableLoader([]) + typeTable: new Map() }); } catch(e) { error = e; @@ -1680,7 +1716,7 @@ describe('legacy cborld (range)', () => { result = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); } catch(e) { error = e; @@ -1727,7 +1763,7 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1779,7 +1815,7 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1825,15 +1861,16 @@ describe('legacy cborld (range)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-range', registryEntryId: 2, documentLoader, - typeTable + typeTableLoader: () => typeTable }); const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1879,7 +1916,7 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1923,7 +1960,7 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -1967,7 +2004,7 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -2016,7 +2053,7 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -2064,7 +2101,7 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -2112,7 +2149,7 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -2159,7 +2196,7 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); @@ -2206,14 +2243,15 @@ describe('legacy cborld (range)', () => { const decodedDocument = await decode({ cborldBytes, documentLoader, - typeTable + typeTableLoader: () => typeTable }); expect(decodedDocument).to.eql(jsonldDocument); }); it('should decode a CIT type token', async () => { + // note: CIT type tokens are presently only encoded using tag 0x0501 const cborldBytes = _hexToUint8Array( - 'd90601a40015186c1864186e4c7ad90501a2011987430518411870583b7a' + + 'd90501a40015186c1864186e4c7ad90501a2011987430518411870583b7a' + '0000e190818fdd92908425370e0b5dad9ad92dc956b5ec2ab41ce76b8c70' + 'cb859a7c88ca6ba68b1ff238a70ed674999b6ff5179b0ebb10140b23'); @@ -2297,12 +2335,9 @@ describe('legacy cborld (range)', () => { payload: 'z1177JK4h25dHEAXAVMUMpn2zWcxLCeMLP3oVFQFQ11xHFtE9BhyoU2g47D6Xod1Mu99JR9YJdY184HY' }; - const typeTable = new Map(TYPE_TABLE); - const decodedDocument = await decode({ cborldBytes, - documentLoader, - typeTable + documentLoader }); expect(decodedDocument).to.eql(jsonldDocument); diff --git a/tests/test.legacy-singleton.spec.js b/tests/test.legacy-singleton.spec.js index 69ce4cc..d4df6c3 100644 --- a/tests/test.legacy-singleton.spec.js +++ b/tests/test.legacy-singleton.spec.js @@ -15,7 +15,8 @@ describe('legacy cborld (singleton)', () => { it('should encode an empty JSON-LD Document', async () => { const jsonldDocument = {}; const cborldBytes = await encode({ - jsonldDocument + jsonldDocument, + format: 'legacy-singleton' }); expect(cborldBytes).instanceof(Uint8Array); expect(cborldBytes).equalBytes('d90501a0'); @@ -52,6 +53,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -89,6 +91,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -124,6 +127,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -164,6 +168,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -203,6 +208,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -244,6 +250,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -285,6 +292,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -325,6 +333,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -789,6 +798,7 @@ describe('legacy cborld (singleton)', () => { }; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader }); @@ -815,6 +825,7 @@ describe('legacy cborld (singleton)', () => { }; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader }); @@ -850,6 +861,7 @@ describe('legacy cborld (singleton)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader }); @@ -886,6 +898,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -920,6 +933,7 @@ describe('legacy cborld (singleton)', () => { }; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader }); @@ -962,6 +976,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -1004,6 +1019,7 @@ describe('legacy cborld (singleton)', () => { }; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader }); @@ -1055,6 +1071,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -1096,6 +1113,7 @@ describe('legacy cborld (singleton)', () => { }; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader }); @@ -1145,6 +1163,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -1192,6 +1211,7 @@ describe('legacy cborld (singleton)', () => { }; const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader }); @@ -1247,6 +1267,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -1315,6 +1336,7 @@ describe('legacy cborld (singleton)', () => { const appContextMap = new Map([[CONTEXT_URL, 0x8000]]); const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader, appContextMap }); @@ -1358,6 +1380,7 @@ describe('legacy cborld (singleton)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', documentLoader }); @@ -1410,6 +1433,7 @@ describe('legacy cborld (singleton)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', appContextMap, documentLoader }); @@ -1470,6 +1494,7 @@ describe('legacy cborld (singleton)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', appContextMap, documentLoader }); @@ -1645,6 +1670,7 @@ describe('legacy cborld (singleton)', () => { const cborldBytes = await encode({ jsonldDocument, + format: 'legacy-singleton', appContextMap, documentLoader, });