@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
@@ -2,11 +2,10 @@
2
2
 
3
3
  import { Token, Type } from './token.js'
4
4
  import * as uint from './0uint.js'
5
- import { decodeErrPrefix } from './common.js'
6
5
 
7
6
  /**
8
7
  * @typedef {import('./bl.js').Bl} Bl
9
- * @typedef {import('../interface').DecodeOptions} DecodeOptions
8
+ * @typedef {import('../interface.js').DecodeOptions} DecodeOptions
10
9
  */
11
10
 
12
11
  /**
@@ -61,7 +60,7 @@ export function decodeNegint64 (data, pos, _minor, options) {
61
60
  }
62
61
  }
63
62
  if (options.allowBigInt !== true) {
64
- throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`)
63
+ throw new Error(`${options.decodeErrPrefix} integers outside of the safe integer range are not supported`)
65
64
  }
66
65
  return new Token(Type.negint, neg1b - BigInt(int), 9)
67
66
  }
@@ -69,11 +68,12 @@ export function decodeNegint64 (data, pos, _minor, options) {
69
68
  /**
70
69
  * @param {Bl} buf
71
70
  * @param {Token} token
71
+ * @param {import('../interface.js').EncodeOptions} options
72
72
  */
73
- export function encodeNegint (buf, token) {
73
+ export function encodeNegint (buf, token, { encodeErrPrefix }) {
74
74
  const negint = token.value
75
75
  const unsigned = (typeof negint === 'bigint' ? (negint * neg1b - pos1b) : (negint * -1 - 1))
76
- uint.encodeUintValue(buf, token.type.majorEncoded, unsigned)
76
+ uint.encodeUintValue(buf, token.type.majorEncoded, unsigned, encodeErrPrefix)
77
77
  }
78
78
 
79
79
  /**
@@ -1,11 +1,11 @@
1
1
  import { Token, Type } from './token.js'
2
- import { assertEnoughData, decodeErrPrefix } from './common.js'
2
+ import { assertEnoughData } from './common.js'
3
3
  import * as uint from './0uint.js'
4
4
  import { compare, fromString, slice } from './byte-utils.js'
5
5
 
6
6
  /**
7
7
  * @typedef {import('./bl.js').Bl} Bl
8
- * @typedef {import('../interface').DecodeOptions} DecodeOptions
8
+ * @typedef {import('../interface.js').DecodeOptions} DecodeOptions
9
9
  */
10
10
 
11
11
  /**
@@ -13,10 +13,11 @@ import { compare, fromString, slice } from './byte-utils.js'
13
13
  * @param {number} pos
14
14
  * @param {number} prefix
15
15
  * @param {number} length
16
+ * @param {string} decodeErrPrefix
16
17
  * @returns {Token}
17
18
  */
18
- function toToken (data, pos, prefix, length) {
19
- assertEnoughData(data, pos, prefix + length)
19
+ function toToken (data, pos, prefix, length, decodeErrPrefix) {
20
+ assertEnoughData(data, pos, prefix + length, decodeErrPrefix)
20
21
  const buf = slice(data, pos + prefix, pos + prefix + length)
21
22
  return new Token(Type.bytes, buf, prefix + length)
22
23
  }
@@ -25,11 +26,11 @@ function toToken (data, pos, prefix, length) {
25
26
  * @param {Uint8Array} data
26
27
  * @param {number} pos
27
28
  * @param {number} minor
28
- * @param {DecodeOptions} _options
29
+ * @param {DecodeOptions} options
29
30
  * @returns {Token}
30
31
  */
31
- export function decodeBytesCompact (data, pos, minor, _options) {
32
- return toToken(data, pos, 1, minor)
32
+ export function decodeBytesCompact (data, pos, minor, options) {
33
+ return toToken(data, pos, 1, minor, options.decodeErrPrefix)
33
34
  }
34
35
 
35
36
  /**
@@ -40,7 +41,7 @@ export function decodeBytesCompact (data, pos, minor, _options) {
40
41
  * @returns {Token}
41
42
  */
42
43
  export function decodeBytes8 (data, pos, _minor, options) {
43
- return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options))
44
+ return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options), options.decodeErrPrefix)
44
45
  }
45
46
 
46
47
  /**
@@ -51,7 +52,7 @@ export function decodeBytes8 (data, pos, _minor, options) {
51
52
  * @returns {Token}
52
53
  */
53
54
  export function decodeBytes16 (data, pos, _minor, options) {
54
- return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options))
55
+ return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options), options.decodeErrPrefix)
55
56
  }
56
57
 
57
58
  /**
@@ -62,7 +63,7 @@ export function decodeBytes16 (data, pos, _minor, options) {
62
63
  * @returns {Token}
63
64
  */
64
65
  export function decodeBytes32 (data, pos, _minor, options) {
65
- return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options))
66
+ return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options), options.decodeErrPrefix)
66
67
  }
67
68
 
68
69
  // TODO: maybe we shouldn't support this ..
@@ -76,9 +77,9 @@ export function decodeBytes32 (data, pos, _minor, options) {
76
77
  export function decodeBytes64 (data, pos, _minor, options) {
77
78
  const l = uint.readUint64(data, pos + 1, options)
78
79
  if (typeof l === 'bigint') {
79
- throw new Error(`${decodeErrPrefix} 64-bit integer bytes lengths not supported`)
80
+ throw new Error(`${options.decodeErrPrefix} 64-bit integer bytes lengths not supported`)
80
81
  }
81
- return toToken(data, pos, 9, l)
82
+ return toToken(data, pos, 9, l, options.decodeErrPrefix)
82
83
  }
83
84
 
84
85
  /**
@@ -98,10 +99,11 @@ function tokenBytes (token) {
98
99
  /**
99
100
  * @param {Bl} buf
100
101
  * @param {Token} token
102
+ * @param {import('../interface.js').EncodeOptions} options
101
103
  */
102
- export function encodeBytes (buf, token) {
104
+ export function encodeBytes (buf, token, { encodeErrPrefix }) {
103
105
  const bytes = tokenBytes(token)
104
- uint.encodeUintValue(buf, token.type.majorEncoded, bytes.length)
106
+ uint.encodeUintValue(buf, token.type.majorEncoded, bytes.length, encodeErrPrefix)
105
107
  buf.push(bytes)
106
108
  }
107
109
 
@@ -1,12 +1,12 @@
1
1
  import { Token, Type } from './token.js'
2
- import { assertEnoughData, decodeErrPrefix } from './common.js'
2
+ import { assertEnoughData } from './common.js'
3
3
  import * as uint from './0uint.js'
4
4
  import { encodeBytes } from './2bytes.js'
5
5
  import { toString, slice } from './byte-utils.js'
6
6
 
7
7
  /**
8
8
  * @typedef {import('./bl.js').Bl} Bl
9
- * @typedef {import('../interface').DecodeOptions} DecodeOptions
9
+ * @typedef {import('../interface.js').DecodeOptions} DecodeOptions
10
10
  */
11
11
 
12
12
  /**
@@ -19,7 +19,7 @@ import { toString, slice } from './byte-utils.js'
19
19
  */
20
20
  function toToken (data, pos, prefix, length, options) {
21
21
  const totLength = prefix + length
22
- assertEnoughData(data, pos, totLength)
22
+ assertEnoughData(data, pos, totLength, options.decodeErrPrefix)
23
23
  const tok = new Token(Type.string, toString(data, pos + prefix, pos + totLength), totLength)
24
24
  if (options.retainStringBytes === true) {
25
25
  tok.byteValue = slice(data, pos + prefix, pos + totLength)
@@ -82,7 +82,7 @@ export function decodeString32 (data, pos, _minor, options) {
82
82
  export function decodeString64 (data, pos, _minor, options) {
83
83
  const l = uint.readUint64(data, pos + 1, options)
84
84
  if (typeof l === 'bigint') {
85
- throw new Error(`${decodeErrPrefix} 64-bit integer string lengths not supported`)
85
+ throw new Error(`${options.decodeErrPrefix} 64-bit integer string lengths not supported`)
86
86
  }
87
87
  return toToken(data, pos, 9, l, options)
88
88
  }
@@ -1,10 +1,10 @@
1
1
  import { Token, Type } from './token.js'
2
2
  import * as uint from './0uint.js'
3
- import { decodeErrPrefix } from './common.js'
3
+ // import { decodeErrPrefix } from '../lib/common.js'
4
4
 
5
5
  /**
6
6
  * @typedef {import('./bl.js').Bl} Bl
7
- * @typedef {import('../interface').DecodeOptions} DecodeOptions
7
+ * @typedef {import('../interface.js').DecodeOptions} DecodeOptions
8
8
  */
9
9
 
10
10
  /**
@@ -73,7 +73,7 @@ export function decodeArray32 (data, pos, _minor, options) {
73
73
  export function decodeArray64 (data, pos, _minor, options) {
74
74
  const l = uint.readUint64(data, pos + 1, options)
75
75
  if (typeof l === 'bigint') {
76
- throw new Error(`${decodeErrPrefix} 64-bit integer array lengths not supported`)
76
+ throw new Error(`${options.decodeErrPrefix} 64-bit integer array lengths not supported`)
77
77
  }
78
78
  return toToken(data, pos, 9, l)
79
79
  }
@@ -87,7 +87,7 @@ export function decodeArray64 (data, pos, _minor, options) {
87
87
  */
88
88
  export function decodeArrayIndefinite (data, pos, _minor, options) {
89
89
  if (options.allowIndefinite === false) {
90
- throw new Error(`${decodeErrPrefix} indefinite length items not allowed`)
90
+ throw new Error(`${options.decodeErrPrefix} indefinite length items not allowed`)
91
91
  }
92
92
  return toToken(data, pos, 1, Infinity)
93
93
  }
@@ -95,9 +95,10 @@ export function decodeArrayIndefinite (data, pos, _minor, options) {
95
95
  /**
96
96
  * @param {Bl} buf
97
97
  * @param {Token} token
98
+ * @param {import('../interface.js').EncodeOptions} options
98
99
  */
99
- export function encodeArray (buf, token) {
100
- uint.encodeUintValue(buf, Type.array.majorEncoded, token.value)
100
+ export function encodeArray (buf, token, { encodeErrPrefix }) {
101
+ uint.encodeUintValue(buf, Type.array.majorEncoded, token.value, encodeErrPrefix)
101
102
  }
102
103
 
103
104
  // using an array as a map key, are you sure about this? we can only sort
@@ -1,10 +1,9 @@
1
1
  import { Token, Type } from './token.js'
2
2
  import * as uint from './0uint.js'
3
- import { decodeErrPrefix } from './common.js'
4
3
 
5
4
  /**
6
5
  * @typedef {import('./bl.js').Bl} Bl
7
- * @typedef {import('../interface').DecodeOptions} DecodeOptions
6
+ * @typedef {import('../interface.js').DecodeOptions} DecodeOptions
8
7
  */
9
8
 
10
9
  /**
@@ -73,7 +72,7 @@ export function decodeMap32 (data, pos, _minor, options) {
73
72
  export function decodeMap64 (data, pos, _minor, options) {
74
73
  const l = uint.readUint64(data, pos + 1, options)
75
74
  if (typeof l === 'bigint') {
76
- throw new Error(`${decodeErrPrefix} 64-bit integer map lengths not supported`)
75
+ throw new Error(`${options.decodeErrPrefix} 64-bit integer map lengths not supported`)
77
76
  }
78
77
  return toToken(data, pos, 9, l)
79
78
  }
@@ -87,7 +86,7 @@ export function decodeMap64 (data, pos, _minor, options) {
87
86
  */
88
87
  export function decodeMapIndefinite (data, pos, _minor, options) {
89
88
  if (options.allowIndefinite === false) {
90
- throw new Error(`${decodeErrPrefix} indefinite length items not allowed`)
89
+ throw new Error(`${options.decodeErrPrefix} indefinite length items not allowed`)
91
90
  }
92
91
  return toToken(data, pos, 1, Infinity)
93
92
  }
@@ -95,9 +94,10 @@ export function decodeMapIndefinite (data, pos, _minor, options) {
95
94
  /**
96
95
  * @param {Bl} buf
97
96
  * @param {Token} token
97
+ * @param {import('../interface.js').EncodeOptions} options
98
98
  */
99
- export function encodeMap (buf, token) {
100
- uint.encodeUintValue(buf, Type.map.majorEncoded, token.value)
99
+ export function encodeMap (buf, token, { encodeErrPrefix }) {
100
+ uint.encodeUintValue(buf, Type.map.majorEncoded, token.value, encodeErrPrefix)
101
101
  }
102
102
 
103
103
  // using a map as a map key, are you sure about this? we can only sort
@@ -3,7 +3,7 @@ import * as uint from './0uint.js'
3
3
 
4
4
  /**
5
5
  * @typedef {import('./bl.js').Bl} Bl
6
- * @typedef {import('../interface').DecodeOptions} DecodeOptions
6
+ * @typedef {import('../interface.js').DecodeOptions} DecodeOptions
7
7
  */
8
8
 
9
9
  /**
@@ -64,9 +64,10 @@ export function decodeTag64 (data, pos, _minor, options) {
64
64
  /**
65
65
  * @param {Bl} buf
66
66
  * @param {Token} token
67
+ * @param {import('../interface.js').EncodeOptions} options
67
68
  */
68
- export function encodeTag (buf, token) {
69
- uint.encodeUintValue(buf, Type.tag.majorEncoded, token.value)
69
+ export function encodeTag (buf, token, { encodeErrPrefix }) {
70
+ uint.encodeUintValue(buf, Type.tag.majorEncoded, token.value, encodeErrPrefix)
70
71
  }
71
72
 
72
73
  encodeTag.compareTokens = uint.encodeUint.compareTokens
@@ -2,13 +2,12 @@
2
2
  // where possible
3
3
 
4
4
  import { Token, Type } from './token.js'
5
- import { decodeErrPrefix } from './common.js'
6
5
  import { encodeUint } from './0uint.js'
7
6
 
8
7
  /**
9
8
  * @typedef {import('./bl.js').Bl} Bl
10
- * @typedef {import('../interface').DecodeOptions} DecodeOptions
11
- * @typedef {import('../interface').EncodeOptions} EncodeOptions
9
+ * @typedef {import('../interface.js').DecodeOptions} DecodeOptions
10
+ * @typedef {import('../interface.js').EncodeOptions} EncodeOptions
12
11
  */
13
12
 
14
13
  const MINOR_FALSE = 20
@@ -25,7 +24,7 @@ const MINOR_UNDEFINED = 23
25
24
  */
26
25
  export function decodeUndefined (_data, _pos, _minor, options) {
27
26
  if (options.allowUndefined === false) {
28
- throw new Error(`${decodeErrPrefix} undefined values are not supported`)
27
+ throw new Error(`${options.decodeErrPrefix} undefined values are not supported`)
29
28
  } else if (options.coerceUndefinedToNull === true) {
30
29
  return new Token(Type.null, null, 1)
31
30
  }
@@ -41,7 +40,7 @@ export function decodeUndefined (_data, _pos, _minor, options) {
41
40
  */
42
41
  export function decodeBreak (_data, _pos, _minor, options) {
43
42
  if (options.allowIndefinite === false) {
44
- throw new Error(`${decodeErrPrefix} indefinite length items not allowed`)
43
+ throw new Error(`${options.decodeErrPrefix} indefinite length items not allowed`)
45
44
  }
46
45
  return new Token(Type.break, undefined, 1)
47
46
  }
@@ -55,10 +54,10 @@ export function decodeBreak (_data, _pos, _minor, options) {
55
54
  function createToken (value, bytes, options) {
56
55
  if (options) {
57
56
  if (options.allowNaN === false && Number.isNaN(value)) {
58
- throw new Error(`${decodeErrPrefix} NaN values are not supported`)
57
+ throw new Error(`${options.decodeErrPrefix} NaN values are not supported`)
59
58
  }
60
59
  if (options.allowInfinity === false && (value === Infinity || value === -Infinity)) {
61
- throw new Error(`${decodeErrPrefix} Infinity values are not supported`)
60
+ throw new Error(`${options.decodeErrPrefix} Infinity values are not supported`)
62
61
  }
63
62
  }
64
63
  return new Token(Type.float, value, bytes)
@@ -72,7 +71,7 @@ function createToken (value, bytes, options) {
72
71
  * @returns {Token}
73
72
  */
74
73
  export function decodeFloat16 (data, pos, _minor, options) {
75
- return createToken(readFloat16(data, pos + 1), 3, options)
74
+ return createToken(readFloat16(data, pos + 1, options.decodeErrPrefix), 3, options)
76
75
  }
77
76
 
78
77
  /**
@@ -83,7 +82,7 @@ export function decodeFloat16 (data, pos, _minor, options) {
83
82
  * @returns {Token}
84
83
  */
85
84
  export function decodeFloat32 (data, pos, _minor, options) {
86
- return createToken(readFloat32(data, pos + 1), 5, options)
85
+ return createToken(readFloat32(data, pos + 1, options.decodeErrPrefix), 5, options)
87
86
  }
88
87
 
89
88
  /**
@@ -94,7 +93,7 @@ export function decodeFloat32 (data, pos, _minor, options) {
94
93
  * @returns {Token}
95
94
  */
96
95
  export function decodeFloat64 (data, pos, _minor, options) {
97
- return createToken(readFloat64(data, pos + 1), 9, options)
96
+ return createToken(readFloat64(data, pos + 1, options.decodeErrPrefix), 9, options)
98
97
  }
99
98
 
100
99
  /**
@@ -118,14 +117,14 @@ export function encodeFloat (buf, token, options) {
118
117
  let success = false
119
118
  if (!options || options.float64 !== true) {
120
119
  encodeFloat16(float)
121
- decoded = readFloat16(ui8a, 1)
120
+ decoded = readFloat16(ui8a, 1, options.encodeErrPrefix)
122
121
  if (float === decoded || Number.isNaN(float)) {
123
122
  ui8a[0] = 0xf9
124
123
  buf.push(ui8a.slice(0, 3))
125
124
  success = true
126
125
  } else {
127
126
  encodeFloat32(float)
128
- decoded = readFloat32(ui8a, 1)
127
+ decoded = readFloat32(ui8a, 1, options.encodeErrPrefix)
129
128
  if (float === decoded) {
130
129
  ui8a[0] = 0xfa
131
130
  buf.push(ui8a.slice(0, 5))
@@ -135,7 +134,7 @@ export function encodeFloat (buf, token, options) {
135
134
  }
136
135
  if (!success) {
137
136
  encodeFloat64(float)
138
- decoded = readFloat64(ui8a, 1)
137
+ decoded = readFloat64(ui8a, 1, options.encodeErrPrefix)
139
138
  ui8a[0] = 0xfb
140
139
  buf.push(ui8a.slice(0, 9))
141
140
  }
@@ -156,12 +155,12 @@ encodeFloat.encodedSize = function encodedSize (token, options) {
156
155
 
157
156
  if (!options || options.float64 !== true) {
158
157
  encodeFloat16(float)
159
- let decoded = readFloat16(ui8a, 1)
158
+ let decoded = readFloat16(ui8a, 1, options.encodeErrPrefix)
160
159
  if (float === decoded || Number.isNaN(float)) {
161
160
  return 3
162
161
  }
163
162
  encodeFloat32(float)
164
- decoded = readFloat32(ui8a, 1)
163
+ decoded = readFloat32(ui8a, 1, options.encodeErrPrefix)
165
164
  if (float === decoded) {
166
165
  return 5
167
166
  }
@@ -222,11 +221,12 @@ function encodeFloat16 (inp) {
222
221
  /**
223
222
  * @param {Uint8Array} ui8a
224
223
  * @param {number} pos
224
+ * @param {string} encodeErrPrefix
225
225
  * @returns {number}
226
226
  */
227
- function readFloat16 (ui8a, pos) {
227
+ function readFloat16 (ui8a, pos, encodeErrPrefix) {
228
228
  if (ui8a.length - pos < 2) {
229
- throw new Error(`${decodeErrPrefix} not enough data for float16`)
229
+ throw new Error(`${encodeErrPrefix} not enough data for float16`)
230
230
  }
231
231
 
232
232
  const half = (ui8a[pos] << 8) + ui8a[pos + 1]
@@ -264,11 +264,12 @@ function encodeFloat32 (inp) {
264
264
  /**
265
265
  * @param {Uint8Array} ui8a
266
266
  * @param {number} pos
267
+ * @param {string} encodeErrPrefix
267
268
  * @returns {number}
268
269
  */
269
- function readFloat32 (ui8a, pos) {
270
+ function readFloat32 (ui8a, pos, encodeErrPrefix) {
270
271
  if (ui8a.length - pos < 4) {
271
- throw new Error(`${decodeErrPrefix} not enough data for float32`)
272
+ throw new Error(`${encodeErrPrefix} not enough data for float32`)
272
273
  }
273
274
  const offset = (ui8a.byteOffset || 0) + pos
274
275
  return new DataView(ui8a.buffer, offset, 4).getFloat32(0, false)
@@ -284,11 +285,12 @@ function encodeFloat64 (inp) {
284
285
  /**
285
286
  * @param {Uint8Array} ui8a
286
287
  * @param {number} pos
288
+ * @param {string} encodeErrPrefix
287
289
  * @returns {number}
288
290
  */
289
- function readFloat64 (ui8a, pos) {
291
+ function readFloat64 (ui8a, pos, encodeErrPrefix) {
290
292
  if (ui8a.length - pos < 8) {
291
- throw new Error(`${decodeErrPrefix} not enough data for float64`)
293
+ throw new Error(`${encodeErrPrefix} not enough data for float64`)
292
294
  }
293
295
  const offset = (ui8a.byteOffset || 0) + pos
294
296
  return new DataView(ui8a.buffer, offset, 8).getFloat64(0, false)
@@ -16,7 +16,7 @@
16
16
  */
17
17
 
18
18
  // TODO: ipjs doesn't support this, only for test files: https://github.com/mikeal/ipjs/blob/master/src/package/testFile.js#L39
19
- import { alloc, concat, slice } from './byte-utils.js'
19
+ import { alloc, concat, slice } from 'cborg/utils'
20
20
 
21
21
  // the ts-ignores in this file are almost all for the `Uint8Array|number[]` duality that exists
22
22
  // for perf reasons. Consider better approaches to this or removing it entirely, it is quite
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @param {Uint8Array} data
3
+ * @param {number} pos
4
+ * @param {number} need
5
+ * @param {string} decodeErrPrefix
6
+ */
7
+ export function assertEnoughData (data, pos, need, decodeErrPrefix) {
8
+ if (data.length - pos < need) {
9
+ throw new Error(`${decodeErrPrefix} not enough data for type`)
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ export * from './byte-utils.js'
2
+ export { encodeUint, uintBoundaries } from './0uint.js'
3
+ export { encodeNegint } from './1negint.js'
4
+ export { encodeBytes } from './2bytes.js'
5
+ export { encodeString } from './3string.js'
6
+ export { encodeArray } from './4array.js'
7
+ export { encodeMap } from './5map.js'
8
+ export { encodeTag } from './6tag.js'
9
+ export { encodeFloat } from './7float.js'
10
+ export { Bl } from './bl.js'
11
+ export { Token, Type } from './token.js'
12
+ export * from './jump.js'