@fireproof/vendor 1.0.0 → 1.0.1

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.
Files changed (136) hide show
  1. package/package.json +12 -8
  2. package/src/@ipld/car/README.md +229 -175
  3. package/src/@ipld/car/dist/src/reader.d.ts.map +1 -1
  4. package/src/@ipld/car/src/reader.js +19 -2
  5. package/src/cborg/.github/dependabot.yml +16 -0
  6. package/src/cborg/.github/workflows/test-and-release.yml +52 -0
  7. package/src/cborg/{lib → cborg}/bin.js +2 -2
  8. package/src/cborg/cborg/common.js +28 -0
  9. package/src/cborg/{lib → cborg}/decode.js +24 -22
  10. package/src/cborg/{lib → cborg}/diagnostic.js +6 -4
  11. package/src/cborg/{lib → cborg}/diagnostic_test.js +1 -1
  12. package/src/cborg/{lib → cborg}/encode.js +23 -21
  13. package/src/cborg/{cborg.js → cborg/index.js} +12 -10
  14. package/src/cborg/{lib → cborg}/length.js +3 -2
  15. package/src/cborg/interface.ts +7 -4
  16. package/src/cborg/{lib/json → json}/decode.js +25 -25
  17. package/src/cborg/{lib/json → json}/encode.js +19 -16
  18. package/src/cborg/package.json +15 -11
  19. package/src/cborg/taglib.js +3 -1
  20. package/src/cborg/test/common.js +1 -1
  21. package/src/cborg/test/noop-bin-test.js +1 -1
  22. package/src/cborg/test/test-0uint.js +2 -2
  23. package/src/cborg/test/test-1negint.js +2 -2
  24. package/src/cborg/test/test-2bytes.js +2 -2
  25. package/src/cborg/test/test-3string.js +2 -2
  26. package/src/cborg/test/test-4array.js +2 -2
  27. package/src/cborg/test/test-5map.js +2 -2
  28. package/src/cborg/test/test-6tag.js +2 -3
  29. package/src/cborg/test/test-7float.js +2 -2
  30. package/src/cborg/test/test-bl.js +1 -1
  31. package/src/cborg/test/test-cbor-vectors.js +2 -2
  32. package/src/cborg/test/test-decode-errors.js +2 -2
  33. package/src/cborg/test/test-fuzz.js +1 -1
  34. package/src/cborg/test/test-json.js +25 -25
  35. package/src/cborg/test/test-length.js +3 -3
  36. package/src/cborg/test/test-partial.js +2 -2
  37. package/src/cborg/tsconfig.json +5 -2
  38. package/src/cborg/types/{lib → cborg}/decode.d.ts +5 -3
  39. package/src/cborg/types/cborg/decode.d.ts.map +1 -0
  40. package/src/cborg/types/{lib → cborg}/encode.d.ts +4 -3
  41. package/src/cborg/types/cborg/encode.d.ts.map +1 -0
  42. package/src/cborg/types/cborg/index.d.ts +26 -0
  43. package/src/cborg/types/cborg/index.d.ts.map +1 -0
  44. package/src/cborg/types/cborg/is.d.ts.map +1 -0
  45. package/src/cborg/types/interface.d.ts +6 -4
  46. package/src/cborg/types/interface.d.ts.map +1 -1
  47. package/src/cborg/types/{lib/json → json}/decode.d.ts +7 -7
  48. package/src/cborg/types/json/decode.d.ts.map +1 -0
  49. package/src/cborg/types/json/encode.d.ts +11 -0
  50. package/src/cborg/types/json/encode.d.ts.map +1 -0
  51. package/src/cborg/types/json/json.d.ts.map +1 -0
  52. package/src/cborg/types/taglib.d.ts +1 -1
  53. package/src/cborg/types/taglib.d.ts.map +1 -1
  54. package/src/cborg/types/tsconfig.tsbuildinfo +1 -1
  55. package/src/cborg/types/{lib → utils}/0uint.d.ts +6 -4
  56. package/src/cborg/types/utils/0uint.d.ts.map +1 -0
  57. package/src/cborg/types/{lib → utils}/1negint.d.ts +4 -3
  58. package/src/cborg/types/utils/1negint.d.ts.map +1 -0
  59. package/src/cborg/types/{lib → utils}/2bytes.d.ts +5 -4
  60. package/src/cborg/types/utils/2bytes.d.ts.map +1 -0
  61. package/src/cborg/types/{lib → utils}/3string.d.ts +1 -1
  62. package/src/cborg/types/utils/3string.d.ts.map +1 -0
  63. package/src/cborg/types/{lib → utils}/4array.d.ts +3 -2
  64. package/src/cborg/types/utils/4array.d.ts.map +1 -0
  65. package/src/cborg/types/{lib → utils}/5map.d.ts +3 -2
  66. package/src/cborg/types/utils/5map.d.ts.map +1 -0
  67. package/src/cborg/types/{lib → utils}/6tag.d.ts +4 -3
  68. package/src/cborg/types/utils/6tag.d.ts.map +1 -0
  69. package/src/cborg/types/{lib → utils}/7float.d.ts +2 -2
  70. package/src/cborg/types/utils/7float.d.ts.map +1 -0
  71. package/src/cborg/types/utils/bl.d.ts.map +1 -0
  72. package/src/cborg/types/utils/byte-utils.d.ts.map +1 -0
  73. package/src/cborg/types/utils/common.d.ts +8 -0
  74. package/src/cborg/types/utils/common.d.ts.map +1 -0
  75. package/src/cborg/types/utils/index.d.ts +13 -0
  76. package/src/cborg/types/utils/index.d.ts.map +1 -0
  77. package/src/cborg/types/utils/jump.d.ts +16 -0
  78. package/src/cborg/types/utils/jump.d.ts.map +1 -0
  79. package/src/cborg/types/utils/token.d.ts.map +1 -0
  80. package/src/cborg/{lib → utils}/0uint.js +16 -14
  81. package/src/cborg/{lib → utils}/1negint.js +5 -5
  82. package/src/cborg/{lib → utils}/2bytes.js +16 -14
  83. package/src/cborg/{lib → utils}/3string.js +4 -4
  84. package/src/cborg/{lib → utils}/4array.js +7 -6
  85. package/src/cborg/{lib → utils}/5map.js +6 -6
  86. package/src/cborg/{lib → utils}/6tag.js +4 -3
  87. package/src/cborg/{lib → utils}/7float.js +23 -21
  88. package/src/cborg/{lib → utils}/bl.js +1 -1
  89. package/src/cborg/utils/common.js +11 -0
  90. package/src/cborg/utils/index.js +12 -0
  91. package/src/cborg/utils/jump.js +222 -0
  92. package/src/cborg/lib/common.js +0 -27
  93. package/src/cborg/lib/jump.js +0 -209
  94. package/src/cborg/types/cborg.d.ts +0 -28
  95. package/src/cborg/types/cborg.d.ts.map +0 -1
  96. package/src/cborg/types/lib/0uint.d.ts.map +0 -1
  97. package/src/cborg/types/lib/1negint.d.ts.map +0 -1
  98. package/src/cborg/types/lib/2bytes.d.ts.map +0 -1
  99. package/src/cborg/types/lib/3string.d.ts.map +0 -1
  100. package/src/cborg/types/lib/4array.d.ts.map +0 -1
  101. package/src/cborg/types/lib/5map.d.ts.map +0 -1
  102. package/src/cborg/types/lib/6tag.d.ts.map +0 -1
  103. package/src/cborg/types/lib/7float.d.ts.map +0 -1
  104. package/src/cborg/types/lib/bin.d.ts +0 -4
  105. package/src/cborg/types/lib/bin.d.ts.map +0 -1
  106. package/src/cborg/types/lib/bl.d.ts.map +0 -1
  107. package/src/cborg/types/lib/byte-utils.d.ts.map +0 -1
  108. package/src/cborg/types/lib/common.d.ts +0 -10
  109. package/src/cborg/types/lib/common.d.ts.map +0 -1
  110. package/src/cborg/types/lib/decode.d.ts.map +0 -1
  111. package/src/cborg/types/lib/diagnostic.d.ts +0 -12
  112. package/src/cborg/types/lib/diagnostic.d.ts.map +0 -1
  113. package/src/cborg/types/lib/diagnostic_test.d.ts +0 -2
  114. package/src/cborg/types/lib/diagnostic_test.d.ts.map +0 -1
  115. package/src/cborg/types/lib/encode.d.ts.map +0 -1
  116. package/src/cborg/types/lib/is.d.ts.map +0 -1
  117. package/src/cborg/types/lib/json/decode.d.ts.map +0 -1
  118. package/src/cborg/types/lib/json/encode.d.ts +0 -11
  119. package/src/cborg/types/lib/json/encode.d.ts.map +0 -1
  120. package/src/cborg/types/lib/json/forward-cborg.d.ts +0 -6
  121. package/src/cborg/types/lib/json/forward-cborg.d.ts.map +0 -1
  122. package/src/cborg/types/lib/json/json.d.ts.map +0 -1
  123. package/src/cborg/types/lib/jump.d.ts +0 -12
  124. package/src/cborg/types/lib/jump.d.ts.map +0 -1
  125. package/src/cborg/types/lib/length.d.ts +0 -27
  126. package/src/cborg/types/lib/length.d.ts.map +0 -1
  127. package/src/cborg/types/lib/token.d.ts.map +0 -1
  128. /package/src/cborg/{lib → cborg}/is.js +0 -0
  129. /package/src/cborg/{lib/json → json}/json.js +0 -0
  130. /package/src/cborg/types/{lib → cborg}/is.d.ts +0 -0
  131. /package/src/cborg/types/{lib/json → json}/json.d.ts +0 -0
  132. /package/src/cborg/types/{lib → utils}/bl.d.ts +0 -0
  133. /package/src/cborg/types/{lib → utils}/byte-utils.d.ts +0 -0
  134. /package/src/cborg/types/{lib → utils}/token.d.ts +0 -0
  135. /package/src/cborg/{lib → utils}/byte-utils.js +0 -0
  136. /package/src/cborg/{lib → utils}/token.js +0 -0
@@ -1,13 +1,11 @@
1
1
  // never reference the file directly to ensure the
2
2
  // indepency of the json module
3
3
  import { decode as _decode, decodeFirst as _decodeFirst } from "@fireproof/vendor/cborg"
4
- import { Token, Type } from "@fireproof/vendor/cborg"
5
- import { decodeCodePointsArray } from "@fireproof/vendor/cborg"
6
- import { decodeErrPrefix } from "@fireproof/vendor/cborg"
4
+ import { Token, Type, decodeCodePointsArray } from 'cborg/utils'
7
5
 
8
6
  /**
9
- * @typedef {import('../../interface').DecodeOptions} DecodeOptions
10
- * @typedef {import('../../interface').DecodeTokenizer} DecodeTokenizer
7
+ * @typedef {import('../interface').DecodeOptions} DecodeOptions
8
+ * @typedef {import('../interface').DecodeTokenizer} DecodeTokenizer
11
9
  */
12
10
 
13
11
  /**
@@ -18,7 +16,7 @@ class Tokenizer {
18
16
  * @param {Uint8Array} data
19
17
  * @param {DecodeOptions} options
20
18
  */
21
- constructor (data, options = {}) {
19
+ constructor (data, options) {
22
20
  this._pos = 0
23
21
  this.data = data
24
22
  this.options = options
@@ -65,11 +63,11 @@ class Tokenizer {
65
63
  */
66
64
  expect (str) {
67
65
  if (this.data.length - this._pos < str.length) {
68
- throw new Error(`${decodeErrPrefix} unexpected end of input at position ${this._pos}`)
66
+ throw new Error(`${this.options.decodeErrPrefix} unexpected end of input at position ${this._pos}`)
69
67
  }
70
68
  for (let i = 0; i < str.length; i++) {
71
69
  if (this.data[this._pos++] !== str[i]) {
72
- throw new Error(`${decodeErrPrefix} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...str)}'`)
70
+ throw new Error(`${this.options.decodeErrPrefix} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...str)}'`)
73
71
  }
74
72
  }
75
73
  }
@@ -109,11 +107,11 @@ class Tokenizer {
109
107
  }
110
108
  swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]) // DIGIT
111
109
  if (negative && this._pos === startPos + 1) {
112
- throw new Error(`${decodeErrPrefix} unexpected token at position ${this._pos}`)
110
+ throw new Error(`${this.options.decodeErrPrefix} unexpected token at position ${this._pos}`)
113
111
  }
114
112
  if (!this.done() && this.ch() === 46) { // '.'
115
113
  if (float) {
116
- throw new Error(`${decodeErrPrefix} unexpected token at position ${this._pos}`)
114
+ throw new Error(`${this.options.decodeErrPrefix} unexpected token at position ${this._pos}`)
117
115
  }
118
116
  float = true
119
117
  this._pos++
@@ -146,7 +144,7 @@ class Tokenizer {
146
144
  /* c8 ignore next 4 */
147
145
  if (this.ch() !== 34) { // '"'
148
146
  // this would be a programming error
149
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}; this shouldn't happen`)
147
+ throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}; this shouldn't happen`)
150
148
  }
151
149
  this._pos++
152
150
 
@@ -170,7 +168,7 @@ class Tokenizer {
170
168
 
171
169
  const readu4 = () => {
172
170
  if (this._pos + 4 >= this.data.length) {
173
- throw new Error(`${decodeErrPrefix} unexpected end of unicode escape sequence at position ${this._pos}`)
171
+ throw new Error(`${this.options.decodeErrPrefix} unexpected end of unicode escape sequence at position ${this._pos}`)
174
172
  }
175
173
  let u4 = 0
176
174
  for (let i = 0; i < 4; i++) {
@@ -182,7 +180,7 @@ class Tokenizer {
182
180
  } else if (ch >= 65 && ch <= 70) { // 'A' && 'F'
183
181
  ch = ch - 65 + 10
184
182
  } else {
185
- throw new Error(`${decodeErrPrefix} unexpected unicode escape character at position ${this._pos}`)
183
+ throw new Error(`${this.options.decodeErrPrefix} unexpected unicode escape character at position ${this._pos}`)
186
184
  }
187
185
  u4 = u4 * 16 + ch
188
186
  this._pos++
@@ -198,7 +196,7 @@ class Tokenizer {
198
196
  let bytesPerSequence = (firstByte > 0xef) ? 4 : (firstByte > 0xdf) ? 3 : (firstByte > 0xbf) ? 2 : 1
199
197
 
200
198
  if (this._pos + bytesPerSequence > this.data.length) {
201
- throw new Error(`${decodeErrPrefix} unexpected unicode sequence at position ${this._pos}`)
199
+ throw new Error(`${this.options.decodeErrPrefix} unexpected unicode sequence at position ${this._pos}`)
202
200
  }
203
201
 
204
202
  let secondByte, thirdByte, fourthByte, tempCodePoint
@@ -269,7 +267,7 @@ class Tokenizer {
269
267
  case 92: // '\'
270
268
  this._pos++
271
269
  if (this.done()) {
272
- throw new Error(`${decodeErrPrefix} unexpected string termination at position ${this._pos}`)
270
+ throw new Error(`${this.options.decodeErrPrefix} unexpected string termination at position ${this._pos}`)
273
271
  }
274
272
  ch1 = this.ch()
275
273
  this._pos++
@@ -299,7 +297,7 @@ class Tokenizer {
299
297
  chars.push(readu4())
300
298
  break
301
299
  default:
302
- throw new Error(`${decodeErrPrefix} unexpected string escape character at position ${this._pos}`)
300
+ throw new Error(`${this.options.decodeErrPrefix} unexpected string escape character at position ${this._pos}`)
303
301
  }
304
302
  break
305
303
  case 34: // '"'
@@ -307,7 +305,7 @@ class Tokenizer {
307
305
  return new Token(Type.string, decodeCodePointsArray(chars), this._pos - startPos)
308
306
  default:
309
307
  if (ch < 32) { // ' '
310
- throw new Error(`${decodeErrPrefix} invalid control character at position ${this._pos}`)
308
+ throw new Error(`${this.options.decodeErrPrefix} invalid control character at position ${this._pos}`)
311
309
  } else if (ch < 0x80) {
312
310
  chars.push(ch)
313
311
  this._pos++
@@ -317,7 +315,7 @@ class Tokenizer {
317
315
  }
318
316
  }
319
317
 
320
- throw new Error(`${decodeErrPrefix} unexpected end of string at position ${this._pos}`)
318
+ throw new Error(`${this.options.decodeErrPrefix} unexpected end of string at position ${this._pos}`)
321
319
  }
322
320
 
323
321
  /**
@@ -358,7 +356,7 @@ class Tokenizer {
358
356
  case 57: // '9'
359
357
  return this.parseNumber()
360
358
  default:
361
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}`)
359
+ throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}`)
362
360
  }
363
361
  }
364
362
 
@@ -379,7 +377,7 @@ class Tokenizer {
379
377
  return new Token(Type.break, undefined, 1)
380
378
  }
381
379
  if (this.ch() !== 44) { // ','
382
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`)
380
+ throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`)
383
381
  }
384
382
  this._pos++
385
383
  this.modeStack.push('array-value')
@@ -406,7 +404,7 @@ class Tokenizer {
406
404
  return new Token(Type.break, undefined, 1)
407
405
  }
408
406
  if (this.ch() !== 44) { // ','
409
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`)
407
+ throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`)
410
408
  }
411
409
  this._pos++
412
410
  this.skipWhitespace()
@@ -420,7 +418,7 @@ class Tokenizer {
420
418
  const token = this.parseString()
421
419
  this.skipWhitespace()
422
420
  if (this.ch() !== 58) { // ':'
423
- throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`)
421
+ throw new Error(`${this.options.decodeErrPrefix} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`)
424
422
  }
425
423
  this._pos++
426
424
  this.modeStack.push('obj-value')
@@ -434,7 +432,7 @@ class Tokenizer {
434
432
  }
435
433
  /* c8 ignore next 2 */
436
434
  default:
437
- throw new Error(`${decodeErrPrefix} unexpected parse state at position ${this._pos}; this shouldn't happen`)
435
+ throw new Error(`${this.options.decodeErrPrefix} unexpected parse state at position ${this._pos}; this shouldn't happen`)
438
436
  }
439
437
  }
440
438
  }
@@ -445,7 +443,8 @@ class Tokenizer {
445
443
  * @returns {any}
446
444
  */
447
445
  function decode (data, options) {
448
- options = Object.assign({ tokenizer: new Tokenizer(data, options) }, options)
446
+ options = { decodeErrPrefix: 'JSON decode error:', ...options }
447
+ options.tokenizer = options.tokenizer || new Tokenizer(data, options)
449
448
  return _decode(data, options)
450
449
  }
451
450
 
@@ -455,7 +454,8 @@ function decode (data, options) {
455
454
  * @returns {[any, Uint8Array]}
456
455
  */
457
456
  function decodeFirst (data, options) {
458
- options = Object.assign({ tokenizer: new Tokenizer(data, options) }, options)
457
+ options = { decodeErrPrefix: 'JSON decode error:', ...options }
458
+ options.tokenizer = options.tokenizer || new Tokenizer(data, options)
459
459
  return _decodeFirst(data, options)
460
460
  }
461
461
 
@@ -1,23 +1,21 @@
1
1
  // never reference the file directly to ensure the
2
2
  // indepency of the json module
3
- import { Type } from "@fireproof/vendor/cborg"
4
3
  import { encodeCustom } from "@fireproof/vendor/cborg"
5
- import { encodeErrPrefix } from "@fireproof/vendor/cborg"
6
- import { asU8A, fromString } from "@fireproof/vendor/cborg"
4
+ import { Type, asU8A, fromString } from 'cborg/utils'
7
5
 
8
6
  /**
9
- * @typedef {import('../../interface').EncodeOptions} EncodeOptions
10
- * @typedef {import('../../interface').TokenTypeEncoder} TokenTypeEncoder
11
- * @typedef {import('../token').Token} Token
12
- * @typedef {import('../bl').Bl} Bl
7
+ * @typedef {import('../interface').EncodeOptions} EncodeOptions
8
+ * @typedef {import('../interface').TokenTypeEncoder} TokenTypeEncoder
9
+ * @typedef {import('cborg/utils').Token} Token
10
+ * @typedef {import('cborg/utils').Bl} Bl
13
11
  */
14
12
 
15
13
  /**
16
- * @param {(buf: Bl, token: Token) => void} action
14
+ * @param {(buf: Bl, token: Token, opt: EncodeOptions) => void} action
17
15
  * @returns {TokenTypeEncoder}
18
16
  */
19
17
  function wrapCompareTokens (action) {
20
- const wrapped = (/** @type {Bl} */ buf, /** @type {Token} */token) => action(buf, token)
18
+ const wrapped = (/** @type {Bl} */ buf, /** @type {Token} */token, /** @type {EncodeOptions} */opt) => action(buf, token, opt)
21
19
  /**
22
20
  * @param {Token} tok1
23
21
  * @param {Token} tok2
@@ -32,7 +30,7 @@ function wrapCompareTokens (action) {
32
30
  /**
33
31
  * @returns {TokenTypeEncoder[]}
34
32
  */
35
- function makeJSONEncoders() {
33
+ function makeJSONEncoders () {
36
34
  /** @type {TokenTypeEncoder[]} */
37
35
  const encoders = []
38
36
  /** @type {{type:Type,elements:number}[]} */
@@ -73,11 +71,11 @@ function makeJSONEncoders() {
73
71
  buf.push(isa)
74
72
  })
75
73
 
76
- encoders[Type.negint.major] = wrapCompareTokens((buf, token) => {
77
- encoders[Type.uint.major](buf, token)
78
- })
74
+ encoders[Type.negint.major] = wrapCompareTokens((buf, token, opt) => {
75
+ encoders[Type.uint.major](buf, token, opt)
76
+ })
79
77
 
80
- encoders[Type.bytes.major] = wrapCompareTokens((_buf, _token) => {
78
+ encoders[Type.bytes.major] = wrapCompareTokens((_buf, _token, { encodeErrPrefix }) => {
81
79
  throw new Error(`${encodeErrPrefix} unsupported type: Uint8Array`)
82
80
  })
83
81
 
@@ -102,7 +100,7 @@ function makeJSONEncoders() {
102
100
  encoders[Type.tag.major] = wrapCompareTokens((_buf, _token) => {
103
101
  })
104
102
 
105
- encoders[Type.float.major] = wrapCompareTokens((buf, token) => {
103
+ encoders[Type.float.major] = wrapCompareTokens((buf, token, { encodeErrPrefix }) => {
106
104
  if (token.type.equals(Type.break)) {
107
105
  const recurs = inRecursive.pop()
108
106
  if (recurs) {
@@ -260,6 +258,7 @@ function makeJSONEncoders() {
260
258
  // }
261
259
  // }
262
260
 
261
+ const encodeErrPrefix = 'JSON encode error:'
263
262
  /**
264
263
  * @param {(Token|Token[])[]} e1
265
264
  * @param {(Token|Token[])[]} e2
@@ -284,7 +283,11 @@ function mapSorter (e1, e2) {
284
283
  throw new Error(`${encodeErrPrefix} unexpected duplicate map keys, this is not supported`)
285
284
  }
286
285
 
287
- const defaultEncodeOptions = { addBreakTokens: true, mapSorter }
286
+ const defaultEncodeOptions = {
287
+ addBreakTokens: true,
288
+ encodeErrPrefix,
289
+ mapSorter
290
+ }
288
291
 
289
292
  /**
290
293
  * @param {any} data
@@ -2,10 +2,10 @@
2
2
  "name": "cborg",
3
3
  "version": "4.2.7",
4
4
  "description": "Fast CBOR with a focus on strictness",
5
- "main": "cborg.js",
5
+ "main": "cborg/index.js",
6
6
  "type": "module",
7
7
  "bin": {
8
- "cborg": "lib/bin.js"
8
+ "cborg": "cborg/bin.js"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
@@ -38,33 +38,37 @@
38
38
  },
39
39
  "exports": {
40
40
  ".": {
41
- "import": "./cborg.js",
42
- "types": "./types/cborg.d.ts"
41
+ "import": "./cborg/index.js",
42
+ "types": "./types/cborg/index.d.ts"
43
43
  },
44
44
  "./length": {
45
- "import": "./lib/length.js",
46
- "types": "./types/lib/length.d.ts"
45
+ "import": "./cborg/length.js",
46
+ "types": "./types/cborg/length.d.ts"
47
47
  },
48
48
  "./taglib": {
49
49
  "import": "./taglib.js",
50
50
  "types": "./types/taglib.d.ts"
51
51
  },
52
52
  "./json": {
53
- "import": "./lib/json/json.js",
54
- "types": "./types/lib/json/json.d.ts"
53
+ "import": "./json/json.js",
54
+ "types": "./types/json/json.d.ts"
55
55
  },
56
56
  "./interface": {
57
57
  "types": "./types/interface.d.ts"
58
+ },
59
+ "./utils": {
60
+ "import": "./utils/index.js",
61
+ "types": "./types/utils/index.d.ts"
58
62
  }
59
63
  },
60
64
  "types": "cborg.d.ts",
61
65
  "typesVersions": {
62
66
  "*": {
63
67
  "json": [
64
- "types/lib/json/json.d.ts"
68
+ "types/json/json.d.ts"
65
69
  ],
66
70
  "length": [
67
- "types/lib/length.d.ts"
71
+ "types/cborg/length.d.ts"
68
72
  ],
69
73
  "*": [
70
74
  "types/*"
@@ -156,7 +160,7 @@
156
160
  ]
157
161
  },
158
162
  "scripts": {
159
- "lint": "standard *.js lib/*.js test/*.js",
163
+ "lint": "standard *.js cborg/*.js json/*.js utils/*.js test/*.js",
160
164
  "build": "npm run build:types",
161
165
  "build:types": "tsc --build",
162
166
  "test:node": "c8 --check-coverage --exclude=test/** mocha test/test-*.js",
@@ -1,4 +1,6 @@
1
- import { Token, Type } from './cborg.js'
1
+ // never reference the file directly to ensure the
2
+ // indepency of the json module
3
+ import { Token, Type } from 'cborg/utils'
2
4
 
3
5
  /*
4
6
  A collection of some standard CBOR tags.
@@ -1,4 +1,4 @@
1
- import { Token, Type } from '../lib/token.js'
1
+ import { Token, Type } from 'cborg/utils'
2
2
 
3
3
  export function dateDecoder (obj) {
4
4
  if (typeof obj !== 'string') {
@@ -1,3 +1,3 @@
1
1
  // file included so ipjs will compile ../lib/bin.js
2
2
  // this test file is not intended to be run or loaded
3
- import bin from '../lib/bin.js' // eslint-disable-line
3
+ import bin from "@fireproof/vendor/cborg" // eslint-disable-line
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { decode, encode } from '../cborg.js'
6
- import { fromHex, toHex } from '../lib/byte-utils.js'
5
+ import { decode, encode } from "@fireproof/vendor/cborg"
6
+ import { fromHex, toHex } from 'cborg/utils'
7
7
 
8
8
  const { assert } = chai
9
9
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { decode, encode } from '../cborg.js'
6
- import { fromHex, toHex } from '../lib/byte-utils.js'
5
+ import { decode, encode } from "@fireproof/vendor/cborg"
6
+ import { fromHex, toHex } from 'cborg/utils'
7
7
 
8
8
  const { assert } = chai
9
9
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { decode, encode } from '../cborg.js'
6
- import { useBuffer, fromHex, toHex } from '../lib/byte-utils.js'
5
+ import { decode, encode } from "@fireproof/vendor/cborg"
6
+ import { useBuffer, fromHex, toHex } from 'cborg/utils'
7
7
 
8
8
  const { assert } = chai
9
9
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { decode, encode } from '../cborg.js'
6
- import { fromHex, toHex } from '../lib/byte-utils.js'
5
+ import { decode, encode } from "@fireproof/vendor/cborg"
6
+ import { fromHex, toHex } from 'cborg/utils'
7
7
 
8
8
  const { assert } = chai
9
9
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { decode, encode } from '../cborg.js'
6
- import { fromHex, toHex } from '../lib/byte-utils.js'
5
+ import { decode, encode } from "@fireproof/vendor/cborg"
6
+ import { fromHex, toHex } from 'cborg/utils'
7
7
 
8
8
  const { assert } = chai
9
9
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { decode, encode } from '../cborg.js'
6
- import { fromHex, toHex } from '../lib/byte-utils.js'
5
+ import { decode, encode } from "@fireproof/vendor/cborg"
6
+ import { fromHex, toHex } from 'cborg/utils'
7
7
 
8
8
  const { assert } = chai
9
9
 
@@ -2,9 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { Token, Type } from '../lib/token.js'
6
- import { decode, encode } from '../cborg.js'
7
- import { fromHex, toHex } from '../lib/byte-utils.js'
5
+ import { decode, encode } from "@fireproof/vendor/cborg"
6
+ import { fromHex, toHex, Token, Type } from 'cborg/utils'
8
7
  import { dateDecoder, dateEncoder } from './common.js'
9
8
 
10
9
  const { assert } = chai
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { decode, encode } from '../cborg.js'
6
- import { fromHex, toHex } from '../lib/byte-utils.js'
5
+ import { decode, encode } from "@fireproof/vendor/cborg"
6
+ import { fromHex, toHex } from 'cborg/utils'
7
7
 
8
8
  const { assert } = chai
9
9
 
@@ -1,7 +1,7 @@
1
1
  /* eslint-env mocha */
2
2
 
3
3
  import * as chai from 'chai'
4
- import { Bl } from '../lib/bl.js'
4
+ import { Bl } from 'cborg/utils'
5
5
 
6
6
  const { assert } = chai
7
7
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { decode, encode } from '../cborg.js'
5
+ import { decode, encode } from "@fireproof/vendor/cborg"
6
6
  import * as taglib from "@fireproof/vendor/cborg/taglib"
7
- import { fromHex, toHex } from '../lib/byte-utils.js'
7
+ import { fromHex, toHex } from 'cborg/utils'
8
8
  // fixtures from https://github.com/cbor/test-vectors
9
9
  import { fixtures } from './appendix_a.js'
10
10
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
 
5
- import { decode } from '../cborg.js'
6
- import { fromHex } from '../lib/byte-utils.js'
5
+ import { decode } from "@fireproof/vendor/cborg"
6
+ import { fromHex } from 'cborg/utils'
7
7
 
8
8
  const { assert } = chai
9
9
 
@@ -1,7 +1,7 @@
1
1
  /* eslint-env mocha */
2
2
 
3
3
  import { garbage } from 'ipld-garbage'
4
- import { decode, encode } from '../cborg.js'
4
+ import { decode, encode } from "@fireproof/vendor/cborg"
5
5
  import * as chai from 'chai'
6
6
 
7
7
  const { assert } = chai
@@ -154,39 +154,39 @@ describe('json basics', () => {
154
154
  })
155
155
 
156
156
  it('should throw on bad types', () => {
157
- assert.throws(() => encode(new Uint8Array([1, 2])), /CBOR encode error: unsupported type: Uint8Array/)
158
- assert.throws(() => encode({ boop: new Uint8Array([1, 2]) }), /CBOR encode error: unsupported type: Uint8Array/)
159
- assert.throws(() => encode(undefined), /CBOR encode error: unsupported type: undefined/)
160
- assert.throws(() => encode(new Map([[1, 2], [2, 3]])), /CBOR encode error: non-string map keys are not supported/)
161
- assert.throws(() => encode(new Map([[['foo', 'bar'], 2], [['bar', 'foo'], 3]])), /CBOR encode error: complex map keys are not supported/)
157
+ assert.throws(() => encode(new Uint8Array([1, 2])), /JSON encode error: unsupported type: Uint8Array/)
158
+ assert.throws(() => encode({ boop: new Uint8Array([1, 2]) }), /JSON encode error: unsupported type: Uint8Array/)
159
+ assert.throws(() => encode(undefined), /JSON encode error: unsupported type: undefined/)
160
+ assert.throws(() => encode(new Map([[1, 2], [2, 3]])), /JSON encode error: non-string map keys are not supported/)
161
+ assert.throws(() => encode(new Map([[['foo', 'bar'], 2], [['bar', 'foo'], 3]])), /JSON encode error: complex map keys are not supported/)
162
162
  })
163
163
 
164
164
  it('should throw on bad decode failure modes', () => {
165
- assert.throws(() => decode(toBytes('{"a":1 & "b":2}')), 'CBOR decode error: unexpected character at position 7, was expecting object delimiter but found \'&\'')
166
- assert.throws(() => decode(toBytes('{"a":1,"b"!2}')), 'CBOR decode error: unexpected character at position 10, was expecting key/value delimiter \':\' but found \'!\'')
167
- assert.throws(() => decode(toBytes('[1,2&3]')), 'CBOR decode error: unexpected character at position 4, was expecting array delimiter but found \'&\'')
168
- assert.throws(() => decode(toBytes('{"a":!}')), 'CBOR decode error: unexpected character at position 5')
169
- assert.throws(() => decode(toBytes('"abc')), 'CBOR decode error: unexpected end of string at position 4')
170
- assert.throws(() => decode(toBytes('"ab\\xc"')), 'CBOR decode error: unexpected string escape character at position 5')
171
- assert.throws(() => decode(toBytes('"ab\x1Ec"')), 'CBOR decode error: invalid control character at position 3')
172
- assert.throws(() => decode(toBytes('"ab\\')), 'CBOR decode error: unexpected string termination at position 4')
165
+ assert.throws(() => decode(toBytes('{"a":1 & "b":2}')), 'JSON decode error: unexpected character at position 7, was expecting object delimiter but found \'&\'')
166
+ assert.throws(() => decode(toBytes('{"a":1,"b"!2}')), 'JSON decode error: unexpected character at position 10, was expecting key/value delimiter \':\' but found \'!\'')
167
+ assert.throws(() => decode(toBytes('[1,2&3]')), 'JSON decode error: unexpected character at position 4, was expecting array delimiter but found \'&\'')
168
+ assert.throws(() => decode(toBytes('{"a":!}')), 'JSON decode error: unexpected character at position 5')
169
+ assert.throws(() => decode(toBytes('"abc')), 'JSON decode error: unexpected end of string at position 4')
170
+ assert.throws(() => decode(toBytes('"ab\\xc"')), 'JSON decode error: unexpected string escape character at position 5')
171
+ assert.throws(() => decode(toBytes('"ab\x1Ec"')), 'JSON decode error: invalid control character at position 3')
172
+ assert.throws(() => decode(toBytes('"ab\\')), 'JSON decode error: unexpected string termination at position 4')
173
173
  // begining of a quoted string with 3-byte unicode sequence with the last one truncated
174
- assert.throws(() => decode(toBytes('"☺').subarray(0, 3)), 'CBOR decode error: unexpected unicode sequence at position 1')
175
- assert.throws(() => decode(toBytes('"\\uxyza"')), 'CBOR decode error: unexpected unicode escape character at position 3')
176
- assert.throws(() => decode(toBytes('"\\u11"')), 'CBOR decode error: unexpected end of unicode escape sequence at position 3')
177
- assert.throws(() => decode(toBytes('-boop')), 'CBOR decode error: unexpected token at position 1')
178
- assert.throws(() => decode(toBytes('{"v":nope}')), 'CBOR decode error: unexpected token at position 7, expected to find \'null\'')
179
- assert.throws(() => decode(toBytes('[n]')), 'CBOR decode error: unexpected end of input at position 1')
180
- assert.throws(() => decode(toBytes('{"v":truu}')), 'CBOR decode error: unexpected token at position 9, expected to find \'true\'')
181
- assert.throws(() => decode(toBytes('[tr]')), 'CBOR decode error: unexpected end of input at position 1')
182
- assert.throws(() => decode(toBytes('{"v":flase}')), 'CBOR decode error: unexpected token at position 7, expected to find \'false\'')
183
- assert.throws(() => decode(toBytes('[fa]')), 'CBOR decode error: unexpected end of input at position 1')
184
- assert.throws(() => decode(toBytes('-0..1')), 'CBOR decode error: unexpected token at position 3')
174
+ assert.throws(() => decode(toBytes('"☺').subarray(0, 3)), 'JSON decode error: unexpected unicode sequence at position 1')
175
+ assert.throws(() => decode(toBytes('"\\uxyza"')), 'JSON decode error: unexpected unicode escape character at position 3')
176
+ assert.throws(() => decode(toBytes('"\\u11"')), 'JSON decode error: unexpected end of unicode escape sequence at position 3')
177
+ assert.throws(() => decode(toBytes('-boop')), 'JSON decode error: unexpected token at position 1')
178
+ assert.throws(() => decode(toBytes('{"v":nope}')), 'JSON decode error: unexpected token at position 7, expected to find \'null\'')
179
+ assert.throws(() => decode(toBytes('[n]')), 'JSON decode error: unexpected end of input at position 1')
180
+ assert.throws(() => decode(toBytes('{"v":truu}')), 'JSON decode error: unexpected token at position 9, expected to find \'true\'')
181
+ assert.throws(() => decode(toBytes('[tr]')), 'JSON decode error: unexpected end of input at position 1')
182
+ assert.throws(() => decode(toBytes('{"v":flase}')), 'JSON decode error: unexpected token at position 7, expected to find \'false\'')
183
+ assert.throws(() => decode(toBytes('[fa]')), 'JSON decode error: unexpected end of input at position 1')
184
+ assert.throws(() => decode(toBytes('-0..1')), 'JSON decode error: unexpected token at position 3')
185
185
  })
186
186
 
187
187
  it('should throw when rejectDuplicateMapKeys enabled on duplicate keys', () => {
188
188
  assert.deepStrictEqual(decode(toBytes('{"foo":1,"foo":2}')), { foo: 2 })
189
- assert.throws(() => decode(toBytes('{"foo":1,"foo":2}'), { rejectDuplicateMapKeys: true }), /CBOR decode error: found repeat map key "foo"/)
189
+ assert.throws(() => decode(toBytes('{"foo":1,"foo":2}'), { rejectDuplicateMapKeys: true }), /JSON decode error: found repeat map key "foo"/)
190
190
  })
191
191
 
192
192
  it('decodeFirst', () => {
@@ -2,9 +2,9 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
  import { garbage } from 'ipld-garbage'
5
- import { uintBoundaries } from '../lib/0uint.js'
6
- import { encode } from '../cborg.js'
7
- import { encodedLength } from '../lib/length.js'
5
+ import { uintBoundaries } from 'cborg/utils'
6
+ import { encode } from "@fireproof/vendor/cborg"
7
+ import { encodedLength } from "@fireproof/vendor/cborg/length"
8
8
  import { dateEncoder } from './common.js'
9
9
 
10
10
  const { assert } = chai
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as chai from 'chai'
4
4
  import { garbage } from 'ipld-garbage'
5
- import { uintBoundaries } from '../lib/0uint.js'
6
- import { encode, decodeFirst } from '../cborg.js'
5
+ import { uintBoundaries } from 'cborg/utils'
6
+ import { encode, decodeFirst } from "@fireproof/vendor/cborg"
7
7
  import { dateDecoder, dateEncoder } from './common.js'
8
8
 
9
9
  const { assert } = chai
@@ -28,7 +28,10 @@
28
28
  "emitDeclarationOnly": true,
29
29
  "paths": {
30
30
  "cborg": [
31
- "cborg.js"
31
+ "cborg/index.js"
32
+ ],
33
+ "cborg/utils": [
34
+ "./utils/index.js"
32
35
  ]
33
36
  }
34
37
  },
@@ -37,7 +40,7 @@
37
40
  "example.js",
38
41
  "taglib.js",
39
42
  "lib/"
40
- ],
43
+ , "utils/byte-utils.js", "utils/jump.js", "utils/0uint.js", "utils/1negint.js", "utils/2bytes.js", "utils/3string.js", "utils/4array.js", "utils/5map.js", "utils/6tag.js", "utils/7float.js", "json" ],
41
44
  "exclude": [
42
45
  "node_modules"
43
46
  ],