cbor-x 0.9.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -21
- package/decode.d.ts +2 -0
- package/decode.js +306 -109
- package/dist/index.js +536 -258
- package/dist/index.min.js +99 -70
- package/dist/node.cjs +538 -253
- package/dist/test.js +51 -7
- package/encode.d.ts +1 -1
- package/encode.js +232 -86
- package/index.js +0 -2
- package/package.json +13 -4
- package/.vscode/launch.json +0 -22
- package/dist/index.js.map +0 -1
- package/tests/benchmark-stream.cjs +0 -282
- package/tests/benchmark.cjs +0 -245
- package/tests/example.json +0 -52
- package/tests/example2.json +0 -26
- package/tests/example3.json +0 -22
- package/tests/example4.json +0 -1
- package/tests/example5.json +0 -12
- package/tests/floats.json +0 -1
- package/tests/index.html +0 -28
- package/tests/sample-large.json +0 -231
- package/tests/strings2.json +0 -1
- package/tests/test-compatibility.cjs +0 -36
- package/tests/test-incomplete.js +0 -41
- package/tests/test-node-iterators.js +0 -72
- package/tests/test-node-stream.js +0 -60
- package/tests/test.js +0 -596
package/tests/strings2.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
["metadata","Designs","Randomized Controlled Trial","Types","BriefSummary","To determine the efficacy, long-term safety, and tolerability of alirocumab , mg every ,\n weeks (Q,W), in comparison with placebo, as well as its potential as a starting regimen. The\n dose regimen of , mg every , weeks (Q,W), as used in other studies, was added as a\n calibrator.","Abstract","To determine the efficacy, long-term safety, and tolerability of alirocumab , mg every ,\n weeks (Q,W), in comparison with placebo, as well as its potential as a starting regimen. The\n dose regimen of , mg every , weeks (Q,W), as used in other studies, was added as a\n calibrator.","Acronym","null","ArticleId","Qy,gwKWSoaWRmbmFEQA","Authors","null","CochraneID","null","Confidential","false","CorporateAuthor","null","Country","Bulgaria, Canada, Hungary, Israel, Norway, Slovakia, United Kingdom, United States","CustomData","null","DatabaseType","ClinicalTrials.gov","DOI","null","EmbaseAccessionNumber","null","Emtree","null","ErrataText","null","FullTextURL","null","Institution","null","ISSN","null","Issue","null","JournalTitle","null","MedlineID","null","MeSH","Hypercholesterolemia|Antibodies, Monoclonal","Pages","null","ParentChildStatus","null","ParentID","null","PublicationDate","March","PublicationYear","PubType","null","ReferenceStudy","null","SecondarySourceID","null","Source","Regeneron Pharmaceuticals","SourceReferenceId","NCT","TaStudyDesign","Randomized","Title","A Randomized, Double-Blind, Placebo-Controlled Study to Evaluate the Efficacy and Safety of an Every Four Weeks Treatment Regimen of Alirocumab in Patients With Primary Hypercholesterolemia","TrialOutcome","null","Volume","null","Id","Created","VersionNo","ExtractData","null","Digitized","null","IsRapidExtract","false","IsUploaded","false","design","Randomized Controlled Trial","conditions","label","Cholesterol Total Increased","id","SUE_c","phase","name","NCT","trialIds","NCT","acronyms","outcomeCount","id","groups","Id","RefId","B,|O,~Alirocumab , mg Q,W/Up , mg Q,W Without Concomitant Statin","OriginalName","Alirocumab , mg Q,W/Up , mg Q,W Without Concomitant Statin","N","age","ageSD","male","Interventions","termIds","SUBYEL","SUB_Oc","SUNUVb","analyzeAs","Alirocumab","analyzableScore","matchingScore","Id","zB","RefId","B,|O,~Alirocumab , mg Q,W/Up , mg Q,W Without Concomitant Statin","OriginalName","Alirocumab , mg Q,W/Up , mg Q,W Without Concomitant Statin","N","age","ageSD","male","Interventions","termIds","SUBYEL","SUB_Oc","analyzeAs","Statins","analyzableScore","matchingScore","Id","RefId","B,|O,~Placebo Q,W Without Concomitant Statin","OriginalName","Placebo Q,W Without Concomitant Statin","N","age","ageSD","male","Interventions","termIds","SUGeLS","SUBYEL","SUB_Oc","analyzeAs","Control","analyzableScore","matchingScore","Id","tv","RefId","OriginalName","Alirocumab , mg Q,W/Up , mg Q,W","Interventions","termIds","SUCO","SUNUVb","Id","jt","RefId","B,|O,~Alirocumab , mg Q,W/Up , mg Q,W With Concomitant Statin","OriginalName","Alirocumab , mg Q,W/Up , mg Q,W With Concomitant Statin","N","age","ageSD","male","Interventions","termIds","SUBYEL","SUB_Oc","Id","RefId","OriginalName","Alirocumab , mg Q,W/Up , mg Q,W","Interventions","termIds","SUNUVb","Id","RefId","B,|O,~Alirocumab , mg Q,W/Up , mg Q,W With Concomitant Statin","OriginalName","Alirocumab , mg Q,W/Up , mg Q,W With Concomitant Statin","N","age","ageSD","male","Interventions","termIds","SUBYEL","SUB_Oc","SUNUVb","Id","Interventions","Id","Ya","Name","Treatments","Id","((","Phase","k)","Type","Drug","termIds","SUGeLS","SUNUVb","terms","Placebo","Alirocumab","Id","o)","Name","Treatments","Id","Phase","k)","Type","Drug","termIds","SUBYEL","terms","Statins","RefId","E,|Placebo Q,W","OriginalName","Placebo Q,W","Id","Ls","RefId","B,|O,~Placebo Q,W With Concomitant Statin","OriginalName","Placebo Q,W With Concomitant Statin","N","age","ageSD","male","Interventions","termIds","SUGeLS","SUBYEL","SUB_Oc","hasDocData","null","hasRapidExtract","false","N","queryScore","matchingScore","score","outcomes","id","type","Change","unit","%","termIds","SUF,R","SUBskP","quantifiers","name","Calculated LDL-C in Not Receiving Concomitant Statin Therapy - On-Treatment Analysis","cells","number","unit","%","group","!","varType","se","N","se","sd","number","unit","%","group","varType","se","N","se","sd","number","unit","%","group","zB","varType","se","N","se","sd","time","Id","Low","Value","Baseline","High","Number","Unit","wk","Type","Total","days","description","wk","score","matchingTerm","SUF,R","suggestedPositive","false","sourceUnit","%","id","type","Change","unit","%","termIds","SUF,R","SUBskP","quantifiers","name","Calculated LDL-C in Receiving Concomitant Statin Therapy - On-Treatment Analysis","cells","number","unit","%","group","Ls","varType","se","N","se","sd","number","unit","%","group","varType","se","N","se","sd","number","unit","%","group","jt","varType","se","N","se","sd","time","Id","Low","Value","Baseline","High","Number","Unit","wk","Type","Total","days","description","wk","score","matchingTerm","SUF,R","suggestedPositive","false","sourceUnit","%","id","type","Change","unit","%","termIds","SUF,R","SUBskP","quantifiers","name","Calculated LDL-C in Not Receiving Concomitant Statin Therapy - On-Treatment Analysis","cells","number","unit","%","group","varType","se","N","se","sd","number","unit","%","group","varType","se","N","se","sd","number","unit","%","group","zB","varType","se","N","se","sd","time","Id","Low","Value","Baseline","High","Number","Unit","wk","Type","Total","days","description","score","matchingTerm","SUF,R","suggestedPositive","false","sourceUnit","%","id","type","Change","unit","%","termIds","SUF,R","SUBskP","quantifiers","name","Calculated LDL-C in Receiving Concomitant Statin Therapy - On-Treatment Analysis","cells","number","unit","%","group","Ls","varType","se","N","se","sd","number","unit","%","group","E","varType","se","N","se","sd","number","unit","%","group","jt","varType","se","N","se","sd","time","Id","Low","Value","Baseline","High","Number","Unit","wk","Type","Total","days","description","wk","score","matchingTerm","SUF,R","suggestedPositive","false","sourceUnit","%","characteristics","id","type","Binary","isCharacteristic","null","termIds","SUE_c","SUCbN","SUyJj","quantifiers","name","Patients not having adequate control of their hypercholesterolemia based on their individual level of CVD risk","cells","number","outcomesScore"]
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const data = require('./example4.json');
|
|
2
|
-
const cborX = require('..');
|
|
3
|
-
const chai = require('chai');
|
|
4
|
-
|
|
5
|
-
function tryRequire(module) {
|
|
6
|
-
try {
|
|
7
|
-
return require(module)
|
|
8
|
-
} catch(error) {
|
|
9
|
-
console.log(error)
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
//if (typeof chai === 'undefined') { chai = require('chai') }
|
|
13
|
-
const assert = chai.assert
|
|
14
|
-
var cbor_module = tryRequire('cbor');
|
|
15
|
-
var decode = cborX.decode
|
|
16
|
-
var encode = cborX.encode
|
|
17
|
-
|
|
18
|
-
const addCompatibilitySuite = (data) => () => {
|
|
19
|
-
if (cbor_module) {
|
|
20
|
-
test('from cbor', function(){
|
|
21
|
-
var serialized = cbor_module.encode(data)
|
|
22
|
-
var deserialized = decode(serialized)
|
|
23
|
-
assert.deepEqual(deserialized, data)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
test('to cbor', function(){
|
|
27
|
-
var serialized = encode(data)
|
|
28
|
-
var deserialized = cbor_module.decodeFirstSync(serialized)
|
|
29
|
-
assert.deepEqual(deserialized, data)
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
suite('cbor-x compatibility tests (example)', addCompatibilitySuite(require('./example.json')))
|
|
35
|
-
suite('cbor-x compatibility tests (example4)', addCompatibilitySuite(require('./example4.json')))
|
|
36
|
-
suite('cbor-x compatibility tests (example5)', addCompatibilitySuite(require('./example5.json')))
|
package/tests/test-incomplete.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { encode } from '../index.js'
|
|
2
|
-
import { assert } from 'chai'
|
|
3
|
-
import { Encoder } from '../encode.js'
|
|
4
|
-
|
|
5
|
-
const tests = {
|
|
6
|
-
string: 'interesting string',
|
|
7
|
-
number: 12345,
|
|
8
|
-
buffer: Buffer.from('hello world'),
|
|
9
|
-
bigint: 12345678910n,
|
|
10
|
-
array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
11
|
-
'many-strings': [],
|
|
12
|
-
set: new Set('abcdefghijklmnopqrstuvwxyz'.split('')),
|
|
13
|
-
object: { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }
|
|
14
|
-
}
|
|
15
|
-
for (let i = 0; i < 100; i++) {
|
|
16
|
-
tests['many-strings'].push('test-data-' + i)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
suite('encode and decode tests with partial values', function () {
|
|
20
|
-
const encoder = new Encoder({ objectMode: true, structures: [] })
|
|
21
|
-
|
|
22
|
-
for (const [label, testData] of Object.entries(tests)) {
|
|
23
|
-
test(label, () => {
|
|
24
|
-
const encoded = encoder.encode(testData)
|
|
25
|
-
assert.isTrue(Buffer.isBuffer(encoded), 'encode returns a Buffer')
|
|
26
|
-
assert.deepStrictEqual(encoder.decode(encoded, encoded.length, true), testData, 'full buffer decodes well')
|
|
27
|
-
const firstHalf = encoded.slice(0, Math.floor(encoded.length / 2))
|
|
28
|
-
let value
|
|
29
|
-
try {
|
|
30
|
-
value = encoder.decode(firstHalf, firstHalf.length, true)
|
|
31
|
-
} catch (err) {
|
|
32
|
-
if (err.incomplete !== true) {
|
|
33
|
-
assert.fail(`Should throw an error with .incomplete set to true, instead threw error <${err}>`)
|
|
34
|
-
} else {
|
|
35
|
-
return; // victory! correct outcome!
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
assert.fail(`Should throw an error with .incomplete set to true, instead returned value ${JSON.stringify(value)}`)
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
})
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { encodeIter, decodeIter } from '../index.js'
|
|
2
|
-
import { decode } from '../index.js'
|
|
3
|
-
import { assert } from 'chai'
|
|
4
|
-
|
|
5
|
-
const tests = [
|
|
6
|
-
null,
|
|
7
|
-
false,
|
|
8
|
-
true,
|
|
9
|
-
'interesting string',
|
|
10
|
-
12345,
|
|
11
|
-
123456789n,
|
|
12
|
-
123.456,
|
|
13
|
-
Buffer.from('Hello World'),
|
|
14
|
-
new Set('abcdefghijklmnopqrstuvwxyz'.split(''))
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
suite('cbor-x iterators interface tests', function () {
|
|
18
|
-
test('sync encode iterator', () => {
|
|
19
|
-
const encodings = [...encodeIter(tests)]
|
|
20
|
-
const decodings = encodings.map(x => decode(x))
|
|
21
|
-
assert.deepStrictEqual(decodings, tests)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('async encode iterator', async () => {
|
|
25
|
-
async function * generate () {
|
|
26
|
-
for (const test of tests) {
|
|
27
|
-
await new Promise((resolve, reject) => setImmediate(resolve))
|
|
28
|
-
yield test
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const chunks = []
|
|
33
|
-
for await (const chunk of encodeIter(generate())) {
|
|
34
|
-
chunks.push(chunk)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const decodings = chunks.map(x => decode(x))
|
|
38
|
-
assert.deepStrictEqual(decodings, tests)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
test('sync encode and decode iterator', () => {
|
|
42
|
-
const encodings = [...encodeIter(tests)]
|
|
43
|
-
assert.isTrue(encodings.every(v => Buffer.isBuffer(v)))
|
|
44
|
-
const decodings = [...decodeIter(encodings)]
|
|
45
|
-
assert.deepStrictEqual(decodings, tests)
|
|
46
|
-
|
|
47
|
-
// also test decodings work with buffers multiple values in a buffer
|
|
48
|
-
const concatEncoding = Buffer.concat([...encodings])
|
|
49
|
-
const decodings2 = [...decodeIter([concatEncoding])]
|
|
50
|
-
assert.deepStrictEqual(decodings2, tests)
|
|
51
|
-
|
|
52
|
-
// also test decodings work with partial buffers that don't align to values perfectly
|
|
53
|
-
const half1 = concatEncoding.slice(0, Math.floor(concatEncoding.length / 2))
|
|
54
|
-
const half2 = concatEncoding.slice(Math.floor(concatEncoding.length / 2))
|
|
55
|
-
const decodings3 = [...decodeIter([half1, half2])]
|
|
56
|
-
assert.deepStrictEqual(decodings3, tests)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
test('async encode and decode iterator', async () => {
|
|
60
|
-
async function * generator () {
|
|
61
|
-
for (const obj of tests) {
|
|
62
|
-
await new Promise((resolve, reject) => setImmediate(resolve))
|
|
63
|
-
yield obj
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const yields = []
|
|
67
|
-
for await (const value of decodeIter(encodeIter(generator()))) {
|
|
68
|
-
yields.push(value)
|
|
69
|
-
}
|
|
70
|
-
assert.deepStrictEqual(yields, tests)
|
|
71
|
-
})
|
|
72
|
-
})
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { EncoderStream, DecoderStream } from '../node-index.js'
|
|
2
|
-
import stream from 'stream'
|
|
3
|
-
import chai from 'chai'
|
|
4
|
-
import util from 'util'
|
|
5
|
-
import fs from 'fs'
|
|
6
|
-
const finished = util.promisify(stream.finished)
|
|
7
|
-
var assert = chai.assert
|
|
8
|
-
|
|
9
|
-
suite('cbor-x node stream tests', function(){
|
|
10
|
-
test('serialize/parse stream', () => {
|
|
11
|
-
const serializeStream = new EncoderStream({
|
|
12
|
-
})
|
|
13
|
-
const parseStream = new DecoderStream()
|
|
14
|
-
serializeStream.pipe(parseStream)
|
|
15
|
-
const received = []
|
|
16
|
-
parseStream.on('data', data => {
|
|
17
|
-
received.push(data)
|
|
18
|
-
})
|
|
19
|
-
const messages = [{
|
|
20
|
-
name: 'first'
|
|
21
|
-
}, {
|
|
22
|
-
name: 'second'
|
|
23
|
-
}, {
|
|
24
|
-
name: 'third'
|
|
25
|
-
}, {
|
|
26
|
-
name: 'third',
|
|
27
|
-
extra: [1, 3, { foo: 'hi'}, 'bye']
|
|
28
|
-
}]
|
|
29
|
-
for (const message of messages)
|
|
30
|
-
serializeStream.write(message)
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
setTimeout(() => {
|
|
33
|
-
assert.deepEqual(received, messages)
|
|
34
|
-
resolve()
|
|
35
|
-
}, 10)
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
test('stream from buffer', () => new Promise(async resolve => {
|
|
39
|
-
const parseStream = new DecoderStream()
|
|
40
|
-
let values = []
|
|
41
|
-
parseStream.on('data', (value) => {
|
|
42
|
-
values.push(value)
|
|
43
|
-
})
|
|
44
|
-
parseStream.on('end', () => {
|
|
45
|
-
assert.deepEqual(values, [1, 2])
|
|
46
|
-
resolve()
|
|
47
|
-
})
|
|
48
|
-
let bufferStream = new stream.Duplex()
|
|
49
|
-
bufferStream.pipe(parseStream)
|
|
50
|
-
bufferStream.push(new Uint8Array([1, 2]))
|
|
51
|
-
bufferStream.push(null)
|
|
52
|
-
}))
|
|
53
|
-
|
|
54
|
-
teardown(function() {
|
|
55
|
-
try {
|
|
56
|
-
fs.unlinkSync('test-output.msgpack')
|
|
57
|
-
}catch(error){}
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
|