@metamask-previews/utils 11.12.1-preview-c44fd50 → 11.12.1-preview-2caaa71

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 (282) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{assert.d.mts → assert.d.ts} +2 -2
  3. package/dist/assert.d.ts.map +1 -0
  4. package/dist/{assert.mjs → assert.js} +4 -4
  5. package/dist/assert.js.map +1 -0
  6. package/dist/{base64.d.cts → base64.d.ts} +2 -2
  7. package/dist/base64.d.ts.map +1 -0
  8. package/dist/{base64.mjs → base64.js} +3 -3
  9. package/dist/base64.js.map +1 -0
  10. package/dist/{bytes.d.cts → bytes.d.ts} +2 -2
  11. package/dist/bytes.d.ts.map +1 -0
  12. package/dist/{bytes.mjs → bytes.js} +4 -4
  13. package/dist/bytes.js.map +1 -0
  14. package/dist/{caip-types.d.cts → caip-types.d.ts} +2 -2
  15. package/dist/caip-types.d.ts.map +1 -0
  16. package/dist/{caip-types.mjs → caip-types.js} +2 -2
  17. package/dist/caip-types.js.map +1 -0
  18. package/dist/{checksum.d.cts → checksum.d.ts} +1 -1
  19. package/dist/checksum.d.ts.map +1 -0
  20. package/dist/checksum.js +4 -0
  21. package/dist/checksum.js.map +1 -0
  22. package/dist/{coercers.d.cts → coercers.d.ts} +4 -4
  23. package/dist/coercers.d.ts.map +1 -0
  24. package/dist/{coercers.mjs → coercers.js} +5 -5
  25. package/dist/coercers.js.map +1 -0
  26. package/dist/{collections.d.cts → collections.d.ts} +9 -9
  27. package/dist/collections.d.ts.map +1 -0
  28. package/dist/collections.js +93 -0
  29. package/dist/collections.js.map +1 -0
  30. package/dist/{encryption-types.d.cts → encryption-types.d.ts} +1 -1
  31. package/dist/encryption-types.d.ts.map +1 -0
  32. package/dist/encryption-types.js +2 -0
  33. package/dist/encryption-types.js.map +1 -0
  34. package/dist/{errors.d.mts → errors.d.ts} +1 -1
  35. package/dist/errors.d.ts.map +1 -0
  36. package/dist/{errors.mjs → errors.js} +4 -10
  37. package/dist/errors.js.map +1 -0
  38. package/dist/{fs.d.cts → fs.d.ts} +2 -2
  39. package/dist/fs.d.ts.map +1 -0
  40. package/dist/{fs.mjs → fs.js} +7 -7
  41. package/dist/fs.js.map +1 -0
  42. package/dist/{hashing.d.cts → hashing.d.ts} +1 -1
  43. package/dist/hashing.d.ts.map +1 -0
  44. package/dist/{hashing.mjs → hashing.js} +8 -3
  45. package/dist/hashing.js.map +1 -0
  46. package/dist/{hex.d.cts → hex.d.ts} +5 -6
  47. package/dist/hex.d.ts.map +1 -0
  48. package/dist/{hex.mjs → hex.js} +5 -6
  49. package/dist/hex.js.map +1 -0
  50. package/dist/index.d.ts +26 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +21 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/{json.d.cts → json.d.ts} +19 -29
  55. package/dist/json.d.ts.map +1 -0
  56. package/dist/{json.mjs → json.js} +5 -4
  57. package/dist/json.js.map +1 -0
  58. package/dist/{keyring.d.mts → keyring.d.ts} +5 -5
  59. package/dist/keyring.d.ts.map +1 -0
  60. package/dist/keyring.js +2 -0
  61. package/dist/keyring.js.map +1 -0
  62. package/dist/{logging.d.cts → logging.d.ts} +2 -2
  63. package/dist/logging.d.ts.map +1 -0
  64. package/dist/{logging.mjs → logging.js} +2 -9
  65. package/dist/logging.js.map +1 -0
  66. package/dist/{misc.d.mts → misc.d.ts} +1 -1
  67. package/dist/misc.d.ts.map +1 -0
  68. package/dist/{misc.mjs → misc.js} +1 -1
  69. package/dist/misc.js.map +1 -0
  70. package/dist/{mnemonic.d.cts → mnemonic.d.ts} +1 -1
  71. package/dist/mnemonic.d.ts.map +1 -0
  72. package/dist/{mnemonic.mjs → mnemonic.js} +2 -2
  73. package/dist/mnemonic.js.map +1 -0
  74. package/dist/node.d.ts +3 -0
  75. package/dist/node.d.ts.map +1 -0
  76. package/dist/node.js +3 -0
  77. package/dist/node.js.map +1 -0
  78. package/dist/{number.d.mts → number.d.ts} +2 -2
  79. package/dist/number.d.ts.map +1 -0
  80. package/dist/{number.mjs → number.js} +3 -3
  81. package/dist/number.js.map +1 -0
  82. package/dist/{opaque.d.cts → opaque.d.ts} +1 -1
  83. package/dist/opaque.d.ts.map +1 -0
  84. package/dist/opaque.js +2 -0
  85. package/dist/opaque.js.map +1 -0
  86. package/dist/{promise.d.cts → promise.d.ts} +1 -1
  87. package/dist/promise.d.ts.map +1 -0
  88. package/dist/{promise.mjs → promise.js} +1 -1
  89. package/dist/promise.js.map +1 -0
  90. package/dist/{superstruct.d.mts → superstruct.d.ts} +2 -2
  91. package/dist/superstruct.d.ts.map +1 -0
  92. package/dist/{superstruct.mjs → superstruct.js} +2 -2
  93. package/dist/superstruct.js.map +1 -0
  94. package/dist/{time.d.mts → time.d.ts} +1 -1
  95. package/dist/time.d.ts.map +1 -0
  96. package/dist/{time.mjs → time.js} +1 -1
  97. package/dist/time.js.map +1 -0
  98. package/dist/{transaction-types.d.cts → transaction-types.d.ts} +3 -3
  99. package/dist/transaction-types.d.ts.map +1 -0
  100. package/dist/transaction-types.js +2 -0
  101. package/dist/transaction-types.js.map +1 -0
  102. package/dist/{unitsConversion.d.cts → unitsConversion.d.ts} +28 -28
  103. package/dist/unitsConversion.d.ts.map +1 -0
  104. package/dist/{unitsConversion.mjs → unitsConversion.js} +1 -1
  105. package/dist/unitsConversion.js.map +1 -0
  106. package/dist/{versions.d.mts → versions.d.ts} +3 -3
  107. package/dist/versions.d.ts.map +1 -0
  108. package/dist/{versions.mjs → versions.js} +4 -4
  109. package/dist/versions.js.map +1 -0
  110. package/package.json +21 -30
  111. package/dist/assert.cjs +0 -122
  112. package/dist/assert.cjs.map +0 -1
  113. package/dist/assert.d.cts +0 -61
  114. package/dist/assert.d.cts.map +0 -1
  115. package/dist/assert.d.mts.map +0 -1
  116. package/dist/assert.mjs.map +0 -1
  117. package/dist/base64.cjs +0 -34
  118. package/dist/base64.cjs.map +0 -1
  119. package/dist/base64.d.cts.map +0 -1
  120. package/dist/base64.d.mts +0 -25
  121. package/dist/base64.d.mts.map +0 -1
  122. package/dist/base64.mjs.map +0 -1
  123. package/dist/bytes.cjs +0 -427
  124. package/dist/bytes.cjs.map +0 -1
  125. package/dist/bytes.d.cts.map +0 -1
  126. package/dist/bytes.d.mts +0 -198
  127. package/dist/bytes.d.mts.map +0 -1
  128. package/dist/bytes.mjs.map +0 -1
  129. package/dist/caip-types.cjs +0 -390
  130. package/dist/caip-types.cjs.map +0 -1
  131. package/dist/caip-types.d.cts.map +0 -1
  132. package/dist/caip-types.d.mts +0 -294
  133. package/dist/caip-types.d.mts.map +0 -1
  134. package/dist/caip-types.mjs.map +0 -1
  135. package/dist/checksum.cjs +0 -7
  136. package/dist/checksum.cjs.map +0 -1
  137. package/dist/checksum.d.cts.map +0 -1
  138. package/dist/checksum.d.mts +0 -2
  139. package/dist/checksum.d.mts.map +0 -1
  140. package/dist/checksum.mjs +0 -4
  141. package/dist/checksum.mjs.map +0 -1
  142. package/dist/coercers.cjs +0 -166
  143. package/dist/coercers.cjs.map +0 -1
  144. package/dist/coercers.d.cts.map +0 -1
  145. package/dist/coercers.d.mts +0 -97
  146. package/dist/coercers.d.mts.map +0 -1
  147. package/dist/coercers.mjs.map +0 -1
  148. package/dist/collections.cjs +0 -109
  149. package/dist/collections.cjs.map +0 -1
  150. package/dist/collections.d.cts.map +0 -1
  151. package/dist/collections.d.mts +0 -39
  152. package/dist/collections.d.mts.map +0 -1
  153. package/dist/collections.mjs +0 -105
  154. package/dist/collections.mjs.map +0 -1
  155. package/dist/encryption-types.cjs +0 -3
  156. package/dist/encryption-types.cjs.map +0 -1
  157. package/dist/encryption-types.d.cts.map +0 -1
  158. package/dist/encryption-types.d.mts +0 -7
  159. package/dist/encryption-types.d.mts.map +0 -1
  160. package/dist/encryption-types.mjs +0 -2
  161. package/dist/encryption-types.mjs.map +0 -1
  162. package/dist/errors.cjs +0 -129
  163. package/dist/errors.cjs.map +0 -1
  164. package/dist/errors.d.cts +0 -68
  165. package/dist/errors.d.cts.map +0 -1
  166. package/dist/errors.d.mts.map +0 -1
  167. package/dist/errors.mjs.map +0 -1
  168. package/dist/fs.cjs +0 -248
  169. package/dist/fs.cjs.map +0 -1
  170. package/dist/fs.d.cts.map +0 -1
  171. package/dist/fs.d.mts +0 -133
  172. package/dist/fs.d.mts.map +0 -1
  173. package/dist/fs.mjs.map +0 -1
  174. package/dist/hashing.cjs +0 -60
  175. package/dist/hashing.cjs.map +0 -1
  176. package/dist/hashing.d.cts.map +0 -1
  177. package/dist/hashing.d.mts +0 -28
  178. package/dist/hashing.d.mts.map +0 -1
  179. package/dist/hashing.mjs.map +0 -1
  180. package/dist/hex.cjs +0 -188
  181. package/dist/hex.cjs.map +0 -1
  182. package/dist/hex.d.cts.map +0 -1
  183. package/dist/hex.d.mts +0 -118
  184. package/dist/hex.d.mts.map +0 -1
  185. package/dist/hex.mjs.map +0 -1
  186. package/dist/index.cjs +0 -58
  187. package/dist/index.cjs.map +0 -1
  188. package/dist/index.d.cts +0 -26
  189. package/dist/index.d.cts.map +0 -1
  190. package/dist/index.d.mts +0 -26
  191. package/dist/index.d.mts.map +0 -1
  192. package/dist/index.mjs +0 -21
  193. package/dist/index.mjs.map +0 -1
  194. package/dist/json.cjs +0 -425
  195. package/dist/json.cjs.map +0 -1
  196. package/dist/json.d.cts.map +0 -1
  197. package/dist/json.d.mts +0 -398
  198. package/dist/json.d.mts.map +0 -1
  199. package/dist/json.mjs.map +0 -1
  200. package/dist/keyring.cjs +0 -3
  201. package/dist/keyring.cjs.map +0 -1
  202. package/dist/keyring.d.cts +0 -243
  203. package/dist/keyring.d.cts.map +0 -1
  204. package/dist/keyring.d.mts.map +0 -1
  205. package/dist/keyring.mjs +0 -2
  206. package/dist/keyring.mjs.map +0 -1
  207. package/dist/logging.cjs +0 -43
  208. package/dist/logging.cjs.map +0 -1
  209. package/dist/logging.d.cts.map +0 -1
  210. package/dist/logging.d.mts +0 -30
  211. package/dist/logging.d.mts.map +0 -1
  212. package/dist/logging.mjs.map +0 -1
  213. package/dist/misc.cjs +0 -154
  214. package/dist/misc.cjs.map +0 -1
  215. package/dist/misc.d.cts +0 -127
  216. package/dist/misc.d.cts.map +0 -1
  217. package/dist/misc.d.mts.map +0 -1
  218. package/dist/misc.mjs.map +0 -1
  219. package/dist/mnemonic.cjs +0 -53
  220. package/dist/mnemonic.cjs.map +0 -1
  221. package/dist/mnemonic.d.cts.map +0 -1
  222. package/dist/mnemonic.d.mts +0 -14
  223. package/dist/mnemonic.d.mts.map +0 -1
  224. package/dist/mnemonic.mjs.map +0 -1
  225. package/dist/node.cjs +0 -19
  226. package/dist/node.cjs.map +0 -1
  227. package/dist/node.d.cts +0 -3
  228. package/dist/node.d.cts.map +0 -1
  229. package/dist/node.d.mts +0 -3
  230. package/dist/node.d.mts.map +0 -1
  231. package/dist/node.mjs +0 -3
  232. package/dist/node.mjs.map +0 -1
  233. package/dist/number.cjs +0 -102
  234. package/dist/number.cjs.map +0 -1
  235. package/dist/number.d.cts +0 -74
  236. package/dist/number.d.cts.map +0 -1
  237. package/dist/number.d.mts.map +0 -1
  238. package/dist/number.mjs.map +0 -1
  239. package/dist/opaque.cjs +0 -3
  240. package/dist/opaque.cjs.map +0 -1
  241. package/dist/opaque.d.cts.map +0 -1
  242. package/dist/opaque.d.mts +0 -6
  243. package/dist/opaque.d.mts.map +0 -1
  244. package/dist/opaque.mjs +0 -2
  245. package/dist/opaque.mjs.map +0 -1
  246. package/dist/promise.cjs +0 -44
  247. package/dist/promise.cjs.map +0 -1
  248. package/dist/promise.d.cts.map +0 -1
  249. package/dist/promise.d.mts +0 -45
  250. package/dist/promise.d.mts.map +0 -1
  251. package/dist/promise.mjs.map +0 -1
  252. package/dist/superstruct.cjs +0 -28
  253. package/dist/superstruct.cjs.map +0 -1
  254. package/dist/superstruct.d.cts +0 -20
  255. package/dist/superstruct.d.cts.map +0 -1
  256. package/dist/superstruct.d.mts.map +0 -1
  257. package/dist/superstruct.mjs.map +0 -1
  258. package/dist/time.cjs +0 -67
  259. package/dist/time.cjs.map +0 -1
  260. package/dist/time.d.cts +0 -49
  261. package/dist/time.d.cts.map +0 -1
  262. package/dist/time.d.mts.map +0 -1
  263. package/dist/time.mjs.map +0 -1
  264. package/dist/transaction-types.cjs +0 -3
  265. package/dist/transaction-types.cjs.map +0 -1
  266. package/dist/transaction-types.d.cts.map +0 -1
  267. package/dist/transaction-types.d.mts +0 -117
  268. package/dist/transaction-types.d.mts.map +0 -1
  269. package/dist/transaction-types.mjs +0 -2
  270. package/dist/transaction-types.mjs.map +0 -1
  271. package/dist/unitsConversion.cjs +0 -217
  272. package/dist/unitsConversion.cjs.map +0 -1
  273. package/dist/unitsConversion.d.cts.map +0 -1
  274. package/dist/unitsConversion.d.mts +0 -80
  275. package/dist/unitsConversion.d.mts.map +0 -1
  276. package/dist/unitsConversion.mjs.map +0 -1
  277. package/dist/versions.cjs +0 -95
  278. package/dist/versions.cjs.map +0 -1
  279. package/dist/versions.d.cts +0 -101
  280. package/dist/versions.d.cts.map +0 -1
  281. package/dist/versions.d.mts.map +0 -1
  282. package/dist/versions.mjs.map +0 -1
@@ -1,97 +0,0 @@
1
- import type { Infer } from "@metamask/superstruct";
2
- import type { Hex } from "./hex.mjs";
3
- declare const NumberLikeStruct: import("@metamask/superstruct").Struct<string | number | bigint, null>;
4
- declare const BytesLikeStruct: import("@metamask/superstruct").Struct<Uint8Array | `0x${string}`, null>;
5
- export type NumberLike = Infer<typeof NumberLikeStruct>;
6
- export type BytesLike = Infer<typeof BytesLikeStruct>;
7
- /**
8
- * Create a number from a number-like value.
9
- *
10
- * - If the value is a number, it is returned as-is.
11
- * - If the value is a `bigint`, it is converted to a number.
12
- * - If the value is a string, it is interpreted as a decimal number.
13
- * - If the value is a hex string (i.e., it starts with "0x"), it is
14
- * interpreted as a hexadecimal number.
15
- *
16
- * This validates that the value is a number-like value, and that the resulting
17
- * number is not `NaN` or `Infinity`.
18
- *
19
- * @example
20
- * ```typescript
21
- * const value = createNumber('0x010203');
22
- * console.log(value); // 66051
23
- *
24
- * const otherValue = createNumber(123n);
25
- * console.log(otherValue); // 123
26
- * ```
27
- * @param value - The value to create the number from.
28
- * @returns The created number.
29
- * @throws If the value is not a number-like value, or if the resulting number
30
- * is `NaN` or `Infinity`.
31
- */
32
- export declare function createNumber(value: NumberLike): number;
33
- /**
34
- * Create a `bigint` from a number-like value.
35
- *
36
- * - If the value is a number, it is converted to a `bigint`.
37
- * - If the value is a `bigint`, it is returned as-is.
38
- * - If the value is a string, it is interpreted as a decimal number and
39
- * converted to a `bigint`.
40
- * - If the value is a hex string (i.e., it starts with "0x"), it is
41
- * interpreted as a hexadecimal number and converted to a `bigint`.
42
- *
43
- * @example
44
- * ```typescript
45
- * const value = createBigInt('0x010203');
46
- * console.log(value); // 16909060n
47
- *
48
- * const otherValue = createBigInt(123);
49
- * console.log(otherValue); // 123n
50
- * ```
51
- * @param value - The value to create the bigint from.
52
- * @returns The created bigint.
53
- * @throws If the value is not a number-like value.
54
- */
55
- export declare function createBigInt(value: NumberLike): bigint;
56
- /**
57
- * Create a byte array from a bytes-like value.
58
- *
59
- * - If the value is a byte array, it is returned as-is.
60
- * - If the value is a hex string (i.e., it starts with "0x"), it is interpreted
61
- * as a hexadecimal number and converted to a byte array.
62
- *
63
- * @example
64
- * ```typescript
65
- * const value = createBytes('0x010203');
66
- * console.log(value); // Uint8Array [ 1, 2, 3 ]
67
- *
68
- * const otherValue = createBytes('0x010203');
69
- * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]
70
- * ```
71
- * @param value - The value to create the byte array from.
72
- * @returns The created byte array.
73
- * @throws If the value is not a bytes-like value.
74
- */
75
- export declare function createBytes(value: BytesLike): Uint8Array;
76
- /**
77
- * Create a hexadecimal string from a bytes-like value.
78
- *
79
- * - If the value is a hex string (i.e., it starts with "0x"), it is returned
80
- * as-is.
81
- * - If the value is a `Uint8Array`, it is converted to a hex string.
82
- *
83
- * @example
84
- * ```typescript
85
- * const value = createHex(new Uint8Array([1, 2, 3]));
86
- * console.log(value); // '0x010203'
87
- *
88
- * const otherValue = createHex('0x010203');
89
- * console.log(otherValue); // '0x010203'
90
- * ```
91
- * @param value - The value to create the hex string from.
92
- * @returns The created hex string.
93
- * @throws If the value is not a bytes-like value.
94
- */
95
- export declare function createHex(value: BytesLike): Hex;
96
- export {};
97
- //# sourceMappingURL=coercers.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coercers.d.mts","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAcnD,OAAO,KAAK,EAAE,GAAG,EAAE,kBAAc;AAGjC,QAAA,MAAM,gBAAgB,wEAAyD,CAAC;AAKhF,QAAA,MAAM,eAAe,0EAAiD,CAAC;AASvE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAkBtD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAgBtD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAkBxD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAqB/C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"coercers.mjs","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,WAAW,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AAC,WAAW,EAAE,KAAK,IAAI,CAAC,EAC3D,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iHAAiH;QACjH,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,qCAAqC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAC7D,CAAC;QACJ,CAAC;QAED,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n bigint,\n coerce,\n create,\n instance,\n number,\n string,\n StructError,\n union,\n} from '@metamask/superstruct';\n\nimport { assert } from './assert';\nimport { bytesToHex, hexToBytes } from './bytes';\nimport type { Hex } from './hex';\nimport { StrictHexStruct } from './hex';\n\nconst NumberLikeStruct = union([number(), bigint(), string(), StrictHexStruct]);\nconst NumberCoercer = coerce(number(), NumberLikeStruct, Number);\nconst BigIntCoercer = coerce(bigint(), NumberLikeStruct, BigInt);\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Only referenced via `Infer<typeof ...>` below, but the value is required for that.\nconst BytesLikeStruct = union([StrictHexStruct, instance(Uint8Array)]);\nconst BytesCoercer = coerce(\n instance(Uint8Array),\n union([StrictHexStruct]),\n hexToBytes,\n);\n\nconst HexCoercer = coerce(StrictHexStruct, instance(Uint8Array), bytesToHex);\n\nexport type NumberLike = Infer<typeof NumberLikeStruct>;\nexport type BytesLike = Infer<typeof BytesLikeStruct>;\n\n/**\n * Create a number from a number-like value.\n *\n * - If the value is a number, it is returned as-is.\n * - If the value is a `bigint`, it is converted to a number.\n * - If the value is a string, it is interpreted as a decimal number.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number.\n *\n * This validates that the value is a number-like value, and that the resulting\n * number is not `NaN` or `Infinity`.\n *\n * @example\n * ```typescript\n * const value = createNumber('0x010203');\n * console.log(value); // 66051\n *\n * const otherValue = createNumber(123n);\n * console.log(otherValue); // 123\n * ```\n * @param value - The value to create the number from.\n * @returns The created number.\n * @throws If the value is not a number-like value, or if the resulting number\n * is `NaN` or `Infinity`.\n */\nexport function createNumber(value: NumberLike): number {\n try {\n const result = create(value, NumberCoercer);\n\n assert(\n Number.isFinite(result),\n `Expected a number-like value, got \"${value}\".`,\n );\n\n return result;\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(`Expected a number-like value, got \"${value}\".`);\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a `bigint` from a number-like value.\n *\n * - If the value is a number, it is converted to a `bigint`.\n * - If the value is a `bigint`, it is returned as-is.\n * - If the value is a string, it is interpreted as a decimal number and\n * converted to a `bigint`.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number and converted to a `bigint`.\n *\n * @example\n * ```typescript\n * const value = createBigInt('0x010203');\n * console.log(value); // 16909060n\n *\n * const otherValue = createBigInt(123);\n * console.log(otherValue); // 123n\n * ```\n * @param value - The value to create the bigint from.\n * @returns The created bigint.\n * @throws If the value is not a number-like value.\n */\nexport function createBigInt(value: NumberLike): bigint {\n try {\n // The `BigInt` constructor throws if the value is not a number-like value.\n // There is no need to validate the value manually.\n return create(value, BigIntCoercer);\n } catch (error) {\n /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\n if (error instanceof StructError) {\n throw new Error(\n `Expected a number-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a byte array from a bytes-like value.\n *\n * - If the value is a byte array, it is returned as-is.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is interpreted\n * as a hexadecimal number and converted to a byte array.\n *\n * @example\n * ```typescript\n * const value = createBytes('0x010203');\n * console.log(value); // Uint8Array [ 1, 2, 3 ]\n *\n * const otherValue = createBytes('0x010203');\n * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]\n * ```\n * @param value - The value to create the byte array from.\n * @returns The created byte array.\n * @throws If the value is not a bytes-like value.\n */\nexport function createBytes(value: BytesLike): Uint8Array {\n if (typeof value === 'string' && value.toLowerCase() === '0x') {\n return new Uint8Array();\n }\n\n try {\n return create(value, BytesCoercer);\n } catch (error) {\n /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a hexadecimal string from a bytes-like value.\n *\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is returned\n * as-is.\n * - If the value is a `Uint8Array`, it is converted to a hex string.\n *\n * @example\n * ```typescript\n * const value = createHex(new Uint8Array([1, 2, 3]));\n * console.log(value); // '0x010203'\n *\n * const otherValue = createHex('0x010203');\n * console.log(otherValue); // '0x010203'\n * ```\n * @param value - The value to create the hex string from.\n * @returns The created hex string.\n * @throws If the value is not a bytes-like value.\n */\nexport function createHex(value: BytesLike): Hex {\n if (\n (value instanceof Uint8Array && value.length === 0) ||\n (typeof value === 'string' && value.toLowerCase() === '0x')\n ) {\n return '0x';\n }\n\n try {\n return create(value, HexCoercer);\n } catch (error) {\n /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n"]}
@@ -1,109 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
- if (kind === "m") throw new TypeError("Private method is not writable");
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
- };
13
- var _FrozenMap_map, _FrozenSet_set;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.FrozenSet = exports.FrozenMap = void 0;
16
- /**
17
- * A {@link ReadonlyMap} that cannot be modified after instantiation.
18
- * The implementation uses an inner map hidden via a private field, and the
19
- * immutability guarantee relies on it being impossible to get a reference
20
- * to this map.
21
- */
22
- class FrozenMap {
23
- get size() {
24
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").size;
25
- }
26
- [(_FrozenMap_map = new WeakMap(), Symbol.iterator)]() {
27
- return __classPrivateFieldGet(this, _FrozenMap_map, "f")[Symbol.iterator]();
28
- }
29
- constructor(entries) {
30
- _FrozenMap_map.set(this, void 0);
31
- __classPrivateFieldSet(this, _FrozenMap_map, new Map(entries), "f");
32
- Object.freeze(this);
33
- }
34
- entries() {
35
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").entries();
36
- }
37
- forEach(callbackfn, thisArg) {
38
- // We have to wrap the specified callback in order to prevent it from
39
- // receiving a reference to the inner map.
40
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").forEach((value, key, _map) => callbackfn.call(thisArg, value, key, this));
41
- }
42
- get(key) {
43
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").get(key);
44
- }
45
- has(key) {
46
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").has(key);
47
- }
48
- keys() {
49
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").keys();
50
- }
51
- values() {
52
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").values();
53
- }
54
- toString() {
55
- return `FrozenMap(${this.size}) {${this.size > 0
56
- ? ` ${[...this.entries()]
57
- .map(([key, value]) => `${String(key)} => ${String(value)}`)
58
- .join(', ')} `
59
- : ''}}`;
60
- }
61
- }
62
- exports.FrozenMap = FrozenMap;
63
- /**
64
- * A {@link ReadonlySet} that cannot be modified after instantiation.
65
- * The implementation uses an inner set hidden via a private field, and the
66
- * immutability guarantee relies on it being impossible to get a reference
67
- * to this set.
68
- */
69
- class FrozenSet {
70
- get size() {
71
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").size;
72
- }
73
- [(_FrozenSet_set = new WeakMap(), Symbol.iterator)]() {
74
- return __classPrivateFieldGet(this, _FrozenSet_set, "f")[Symbol.iterator]();
75
- }
76
- constructor(values) {
77
- _FrozenSet_set.set(this, void 0);
78
- __classPrivateFieldSet(this, _FrozenSet_set, new Set(values), "f");
79
- Object.freeze(this);
80
- }
81
- entries() {
82
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").entries();
83
- }
84
- forEach(callbackfn, thisArg) {
85
- // We have to wrap the specified callback in order to prevent it from
86
- // receiving a reference to the inner set.
87
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").forEach((value, value2, _set) => callbackfn.call(thisArg, value, value2, this));
88
- }
89
- has(value) {
90
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").has(value);
91
- }
92
- keys() {
93
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").keys();
94
- }
95
- values() {
96
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").values();
97
- }
98
- toString() {
99
- return `FrozenSet(${this.size}) {${this.size > 0
100
- ? ` ${[...this.values()].map((member) => String(member)).join(', ')} `
101
- : ''}}`;
102
- }
103
- }
104
- exports.FrozenSet = FrozenSet;
105
- Object.freeze(FrozenMap);
106
- Object.freeze(FrozenMap.prototype);
107
- Object.freeze(FrozenSet);
108
- Object.freeze(FrozenSet.prototype);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AAI,sBAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAEM,IAAI;QACT,OAAO,uBAAA,IAAI,sBAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAEM,MAAM;QACX,OAAO,uBAAA,IAAI,sBAAK,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAEM,QAAQ;QACb,OAAO,aAAa,IAAI,CAAC,IAAI,MAC3B,IAAI,CAAC,IAAI,GAAG,CAAC;YACX,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YACtE,CAAC,CAAC,EACN,GAAG,CAAC;IACN,CAAC;CACF;AAQmB,8BAAS;AAN7B,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC","sourcesContent":["/**\n * A {@link ReadonlyMap} that cannot be modified after instantiation.\n * The implementation uses an inner map hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this map.\n */\nclass FrozenMap<Key, Value> implements ReadonlyMap<Key, Value> {\n readonly #map: Map<Key, Value>;\n\n public get size() {\n return this.#map.size;\n }\n\n public [Symbol.iterator]() {\n return this.#map[Symbol.iterator]();\n }\n\n constructor(entries?: readonly (readonly [Key, Value])[] | null) {\n this.#map = new Map<Key, Value>(entries);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#map.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, key: Key, map: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner map.\n return this.#map.forEach((value: Value, key: Key, _map: unknown) =>\n callbackfn.call(thisArg, value, key, this),\n );\n }\n\n public get(key: Key) {\n return this.#map.get(key);\n }\n\n public has(key: Key) {\n return this.#map.has(key);\n }\n\n public keys() {\n return this.#map.keys();\n }\n\n public values() {\n return this.#map.values();\n }\n\n public toString(): string {\n return `FrozenMap(${this.size}) {${\n this.size > 0\n ? ` ${[...this.entries()]\n .map(([key, value]) => `${String(key)} => ${String(value)}`)\n .join(', ')} `\n : ''\n }}`;\n }\n}\n\n/**\n * A {@link ReadonlySet} that cannot be modified after instantiation.\n * The implementation uses an inner set hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this set.\n */\nclass FrozenSet<Value> implements ReadonlySet<Value> {\n readonly #set: Set<Value>;\n\n public get size() {\n return this.#set.size;\n }\n\n public [Symbol.iterator]() {\n return this.#set[Symbol.iterator]();\n }\n\n constructor(values?: readonly Value[] | null) {\n this.#set = new Set<Value>(values);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#set.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, value2: Value, set: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner set.\n return this.#set.forEach((value: Value, value2: Value, _set: unknown) =>\n callbackfn.call(thisArg, value, value2, this),\n );\n }\n\n public has(value: Value) {\n return this.#set.has(value);\n }\n\n public keys() {\n return this.#set.keys();\n }\n\n public values() {\n return this.#set.values();\n }\n\n public toString(): string {\n return `FrozenSet(${this.size}) {${\n this.size > 0\n ? ` ${[...this.values()].map((member) => String(member)).join(', ')} `\n : ''\n }}`;\n }\n}\n\nObject.freeze(FrozenMap);\nObject.freeze(FrozenMap.prototype);\n\nObject.freeze(FrozenSet);\nObject.freeze(FrozenSet.prototype);\n\nexport { FrozenMap, FrozenSet };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"collections.d.cts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAM,SAAS,CAAC,GAAG,EAAE,KAAK,CAAE,YAAW,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC;;IAG5D,IAAW,IAAI,WAEd;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;gBAIZ,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI;IAKxD,OAAO;IAIP,OAAO,CACZ,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK,IAAI,EACvD,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI;IAQA,GAAG,CAAC,GAAG,EAAE,GAAG;IAIZ,GAAG,CAAC,GAAG,EAAE,GAAG;IAIZ,IAAI;IAIJ,MAAM;IAIN,QAAQ,IAAI,MAAM;CAS1B;AAED;;;;;GAKG;AACH,cAAM,SAAS,CAAC,KAAK,CAAE,YAAW,WAAW,CAAC,KAAK,CAAC;;IAGlD,IAAW,IAAI,WAEd;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;gBAIZ,MAAM,CAAC,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI;IAKrC,OAAO;IAIP,OAAO,CACZ,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,KAAK,IAAI,EAC5D,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI;IAQA,GAAG,CAAC,KAAK,EAAE,KAAK;IAIhB,IAAI;IAIJ,MAAM;IAIN,QAAQ,IAAI,MAAM;CAO1B;AAQD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC"}
@@ -1,39 +0,0 @@
1
- /**
2
- * A {@link ReadonlyMap} that cannot be modified after instantiation.
3
- * The implementation uses an inner map hidden via a private field, and the
4
- * immutability guarantee relies on it being impossible to get a reference
5
- * to this map.
6
- */
7
- declare class FrozenMap<Key, Value> implements ReadonlyMap<Key, Value> {
8
- #private;
9
- get size(): number;
10
- [Symbol.iterator](): IterableIterator<[Key, Value]>;
11
- constructor(entries?: readonly (readonly [Key, Value])[] | null);
12
- entries(): IterableIterator<[Key, Value]>;
13
- forEach(callbackfn: (value: Value, key: Key, map: this) => void, thisArg?: any): void;
14
- get(key: Key): Value | undefined;
15
- has(key: Key): boolean;
16
- keys(): IterableIterator<Key>;
17
- values(): IterableIterator<Value>;
18
- toString(): string;
19
- }
20
- /**
21
- * A {@link ReadonlySet} that cannot be modified after instantiation.
22
- * The implementation uses an inner set hidden via a private field, and the
23
- * immutability guarantee relies on it being impossible to get a reference
24
- * to this set.
25
- */
26
- declare class FrozenSet<Value> implements ReadonlySet<Value> {
27
- #private;
28
- get size(): number;
29
- [Symbol.iterator](): IterableIterator<Value>;
30
- constructor(values?: readonly Value[] | null);
31
- entries(): IterableIterator<[Value, Value]>;
32
- forEach(callbackfn: (value: Value, value2: Value, set: this) => void, thisArg?: any): void;
33
- has(value: Value): boolean;
34
- keys(): IterableIterator<Value>;
35
- values(): IterableIterator<Value>;
36
- toString(): string;
37
- }
38
- export { FrozenMap, FrozenSet };
39
- //# sourceMappingURL=collections.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collections.d.mts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAM,SAAS,CAAC,GAAG,EAAE,KAAK,CAAE,YAAW,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC;;IAG5D,IAAW,IAAI,WAEd;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;gBAIZ,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI;IAKxD,OAAO;IAIP,OAAO,CACZ,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK,IAAI,EACvD,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI;IAQA,GAAG,CAAC,GAAG,EAAE,GAAG;IAIZ,GAAG,CAAC,GAAG,EAAE,GAAG;IAIZ,IAAI;IAIJ,MAAM;IAIN,QAAQ,IAAI,MAAM;CAS1B;AAED;;;;;GAKG;AACH,cAAM,SAAS,CAAC,KAAK,CAAE,YAAW,WAAW,CAAC,KAAK,CAAC;;IAGlD,IAAW,IAAI,WAEd;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;gBAIZ,MAAM,CAAC,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI;IAKrC,OAAO;IAIP,OAAO,CACZ,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,KAAK,IAAI,EAC5D,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI;IAQA,GAAG,CAAC,KAAK,EAAE,KAAK;IAIhB,IAAI;IAIJ,MAAM;IAIN,QAAQ,IAAI,MAAM;CAO1B;AAQD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC"}
@@ -1,105 +0,0 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _FrozenMap_map, _FrozenSet_set;
13
- /**
14
- * A {@link ReadonlyMap} that cannot be modified after instantiation.
15
- * The implementation uses an inner map hidden via a private field, and the
16
- * immutability guarantee relies on it being impossible to get a reference
17
- * to this map.
18
- */
19
- class FrozenMap {
20
- get size() {
21
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").size;
22
- }
23
- [(_FrozenMap_map = new WeakMap(), Symbol.iterator)]() {
24
- return __classPrivateFieldGet(this, _FrozenMap_map, "f")[Symbol.iterator]();
25
- }
26
- constructor(entries) {
27
- _FrozenMap_map.set(this, void 0);
28
- __classPrivateFieldSet(this, _FrozenMap_map, new Map(entries), "f");
29
- Object.freeze(this);
30
- }
31
- entries() {
32
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").entries();
33
- }
34
- forEach(callbackfn, thisArg) {
35
- // We have to wrap the specified callback in order to prevent it from
36
- // receiving a reference to the inner map.
37
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").forEach((value, key, _map) => callbackfn.call(thisArg, value, key, this));
38
- }
39
- get(key) {
40
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").get(key);
41
- }
42
- has(key) {
43
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").has(key);
44
- }
45
- keys() {
46
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").keys();
47
- }
48
- values() {
49
- return __classPrivateFieldGet(this, _FrozenMap_map, "f").values();
50
- }
51
- toString() {
52
- return `FrozenMap(${this.size}) {${this.size > 0
53
- ? ` ${[...this.entries()]
54
- .map(([key, value]) => `${String(key)} => ${String(value)}`)
55
- .join(', ')} `
56
- : ''}}`;
57
- }
58
- }
59
- /**
60
- * A {@link ReadonlySet} that cannot be modified after instantiation.
61
- * The implementation uses an inner set hidden via a private field, and the
62
- * immutability guarantee relies on it being impossible to get a reference
63
- * to this set.
64
- */
65
- class FrozenSet {
66
- get size() {
67
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").size;
68
- }
69
- [(_FrozenSet_set = new WeakMap(), Symbol.iterator)]() {
70
- return __classPrivateFieldGet(this, _FrozenSet_set, "f")[Symbol.iterator]();
71
- }
72
- constructor(values) {
73
- _FrozenSet_set.set(this, void 0);
74
- __classPrivateFieldSet(this, _FrozenSet_set, new Set(values), "f");
75
- Object.freeze(this);
76
- }
77
- entries() {
78
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").entries();
79
- }
80
- forEach(callbackfn, thisArg) {
81
- // We have to wrap the specified callback in order to prevent it from
82
- // receiving a reference to the inner set.
83
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").forEach((value, value2, _set) => callbackfn.call(thisArg, value, value2, this));
84
- }
85
- has(value) {
86
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").has(value);
87
- }
88
- keys() {
89
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").keys();
90
- }
91
- values() {
92
- return __classPrivateFieldGet(this, _FrozenSet_set, "f").values();
93
- }
94
- toString() {
95
- return `FrozenSet(${this.size}) {${this.size > 0
96
- ? ` ${[...this.values()].map((member) => String(member)).join(', ')} `
97
- : ''}}`;
98
- }
99
- }
100
- Object.freeze(FrozenMap);
101
- Object.freeze(FrozenMap.prototype);
102
- Object.freeze(FrozenSet);
103
- Object.freeze(FrozenSet.prototype);
104
- export { FrozenMap, FrozenSet };
105
- //# sourceMappingURL=collections.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collections.mjs","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;GAKG;AACH,MAAM,SAAS;IAGb,IAAW,IAAI;QACb,OAAO,uBAAA,IAAI,sBAAK,CAAC,IAAI,CAAC;IACxB,CAAC;IAEM,kCAAC,MAAM,CAAC,QAAQ,EAAC;QACtB,OAAO,uBAAA,IAAI,sBAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACtC,CAAC;IAED,YAAY,OAAmD;QAVtD,iCAAsB;QAW7B,uBAAA,IAAI,kBAA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,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YACtE,CAAC,CAAC,EACN,GAAG,CAAC;IACN,CAAC;CACF;AAED,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC","sourcesContent":["/**\n * A {@link ReadonlyMap} that cannot be modified after instantiation.\n * The implementation uses an inner map hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this map.\n */\nclass FrozenMap<Key, Value> implements ReadonlyMap<Key, Value> {\n readonly #map: Map<Key, Value>;\n\n public get size() {\n return this.#map.size;\n }\n\n public [Symbol.iterator]() {\n return this.#map[Symbol.iterator]();\n }\n\n constructor(entries?: readonly (readonly [Key, Value])[] | null) {\n this.#map = new Map<Key, Value>(entries);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#map.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, key: Key, map: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner map.\n return this.#map.forEach((value: Value, key: Key, _map: unknown) =>\n callbackfn.call(thisArg, value, key, this),\n );\n }\n\n public get(key: Key) {\n return this.#map.get(key);\n }\n\n public has(key: Key) {\n return this.#map.has(key);\n }\n\n public keys() {\n return this.#map.keys();\n }\n\n public values() {\n return this.#map.values();\n }\n\n public toString(): string {\n return `FrozenMap(${this.size}) {${\n this.size > 0\n ? ` ${[...this.entries()]\n .map(([key, value]) => `${String(key)} => ${String(value)}`)\n .join(', ')} `\n : ''\n }}`;\n }\n}\n\n/**\n * A {@link ReadonlySet} that cannot be modified after instantiation.\n * The implementation uses an inner set hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this set.\n */\nclass FrozenSet<Value> implements ReadonlySet<Value> {\n readonly #set: Set<Value>;\n\n public get size() {\n return this.#set.size;\n }\n\n public [Symbol.iterator]() {\n return this.#set[Symbol.iterator]();\n }\n\n constructor(values?: readonly Value[] | null) {\n this.#set = new Set<Value>(values);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#set.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, value2: Value, set: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner set.\n return this.#set.forEach((value: Value, value2: Value, _set: unknown) =>\n callbackfn.call(thisArg, value, value2, this),\n );\n }\n\n public has(value: Value) {\n return this.#set.has(value);\n }\n\n public keys() {\n return this.#set.keys();\n }\n\n public values() {\n return this.#set.values();\n }\n\n public toString(): string {\n return `FrozenSet(${this.size}) {${\n this.size > 0\n ? ` ${[...this.values()].map((member) => String(member)).join(', ')} `\n : ''\n }}`;\n }\n}\n\nObject.freeze(FrozenMap);\nObject.freeze(FrozenMap.prototype);\n\nObject.freeze(FrozenSet);\nObject.freeze(FrozenSet.prototype);\n\nexport { FrozenMap, FrozenSet };\n"]}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=encryption-types.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryption-types.cjs","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"","sourcesContent":["export type Eip1024EncryptedData = {\n version: string;\n nonce: string;\n ephemPublicKey: string;\n ciphertext: string;\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryption-types.d.cts","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -1,7 +0,0 @@
1
- export type Eip1024EncryptedData = {
2
- version: string;
3
- nonce: string;
4
- ephemPublicKey: string;
5
- ciphertext: string;
6
- };
7
- //# sourceMappingURL=encryption-types.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryption-types.d.mts","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=encryption-types.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryption-types.mjs","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"","sourcesContent":["export type Eip1024EncryptedData = {\n version: string;\n nonce: string;\n ephemPublicKey: string;\n ciphertext: string;\n};\n"]}
package/dist/errors.cjs DELETED
@@ -1,129 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureError = exports.wrapError = exports.getErrorMessage = exports.isErrorWithStack = exports.isErrorWithMessage = exports.isErrorWithCode = void 0;
4
- const pony_cause_1 = require("pony-cause");
5
- const misc_1 = require("./misc.cjs");
6
- /**
7
- * Type guard for determining whether the given value is an instance of Error.
8
- * For errors generated via `fs.promises`, `error instanceof Error` won't work,
9
- * so we have to come up with another way of testing.
10
- *
11
- * @param error - The object to check.
12
- * @returns A boolean.
13
- */
14
- function isError(error) {
15
- return (error instanceof Error ||
16
- ((0, misc_1.isObject)(error) && error.constructor.name === 'Error'));
17
- }
18
- /**
19
- * Type guard for determining whether the given value is an error object with a
20
- * `code` property such as the type of error that Node throws for filesystem
21
- * operations, etc.
22
- *
23
- * @param error - The object to check.
24
- * @returns A boolean.
25
- */
26
- function isErrorWithCode(error) {
27
- return typeof error === 'object' && error !== null && 'code' in error;
28
- }
29
- exports.isErrorWithCode = isErrorWithCode;
30
- /**
31
- * Type guard for determining whether the given value is an error object with a
32
- * `message` property, such as an instance of Error.
33
- *
34
- * @param error - The object to check.
35
- * @returns A boolean.
36
- */
37
- function isErrorWithMessage(error) {
38
- return typeof error === 'object' && error !== null && 'message' in error;
39
- }
40
- exports.isErrorWithMessage = isErrorWithMessage;
41
- /**
42
- * Type guard for determining whether the given value is an error object with a
43
- * `stack` property, such as an instance of Error.
44
- *
45
- * @param error - The object to check.
46
- * @returns A boolean.
47
- */
48
- function isErrorWithStack(error) {
49
- return typeof error === 'object' && error !== null && 'stack' in error;
50
- }
51
- exports.isErrorWithStack = isErrorWithStack;
52
- /**
53
- * Attempts to obtain the message from a possible error object, defaulting to an
54
- * empty string if it is impossible to do so.
55
- *
56
- * @param error - The possible error to get the message from.
57
- * @returns The message if `error` is an object with a `message` property;
58
- * the string version of `error` if it is not `undefined` or `null`; otherwise
59
- * an empty string.
60
- */
61
- function getErrorMessage(error) {
62
- if (isErrorWithMessage(error) && typeof error.message === 'string') {
63
- return error.message;
64
- }
65
- if ((0, misc_1.isNullOrUndefined)(error)) {
66
- return '';
67
- }
68
- return String(error);
69
- }
70
- exports.getErrorMessage = getErrorMessage;
71
- /**
72
- * Builds a new error object, linking it to the original error via the `cause`
73
- * property if it is an Error.
74
- *
75
- * This function is useful to reframe error messages in general, but is
76
- * _critical_ when interacting with any of Node's filesystem functions as
77
- * provided via `fs.promises`, because these do not produce stack traces in the
78
- * case of an I/O error (see <https://github.com/nodejs/node/issues/30944>).
79
- *
80
- * @param originalError - The error to be wrapped (something throwable).
81
- * @param message - The desired message of the new error.
82
- * @returns A new error object.
83
- */
84
- function wrapError(originalError, message) {
85
- if (isError(originalError)) {
86
- let error;
87
- if (Error.length === 2) {
88
- // for some reason `tsserver` is not complaining that the
89
- // Error constructor doesn't support a second argument in the editor,
90
- // but `tsc` does. Error causes are not supported by our current tsc target (ES2020, we need ES2022 to make this work)
91
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
92
- // @ts-ignore
93
- error = new Error(message, { cause: originalError });
94
- }
95
- else {
96
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
97
- // @ts-ignore
98
- error = new pony_cause_1.ErrorWithCause(message, { cause: originalError });
99
- }
100
- if (isErrorWithCode(originalError)) {
101
- error.code = originalError.code;
102
- }
103
- return error;
104
- }
105
- if (message.length > 0) {
106
- return new Error(`${String(originalError)}: ${message}`);
107
- }
108
- return new Error(String(originalError));
109
- }
110
- exports.wrapError = wrapError;
111
- /**
112
- * Ensures we have a proper Error object.
113
- * If the input is already an Error, returns it unchanged.
114
- * Otherwise, converts to an Error with an appropriate message and preserves
115
- * the original value as the cause.
116
- *
117
- * @param error - The caught error (could be Error, string, or unknown).
118
- * @returns A proper Error instance.
119
- */
120
- function ensureError(error) {
121
- if (isError(error)) {
122
- return error;
123
- }
124
- const newError = new Error('Unknown error');
125
- newError.cause = error;
126
- return newError;
127
- }
128
- exports.ensureError = ensureError;
129
- //# sourceMappingURL=errors.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,qCAAqD;AAErD;;;;;;;GAOG;AACH,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,CAAC,IAAA,eAAQ,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,OAAO,CAAC,CACxD,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,CAAC;AACxE,CAAC;AAFD,0CAEC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,KAAc;IAEd,OAAO,OAAO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ClC,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AAC1C,CAAC;AA/BD,8BA+BC;AAED;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAgC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACzE,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,OAAO,QAAQ,CAAC;AAClB,CAAC;AARD,kCAQC","sourcesContent":["import { ErrorWithCause } from 'pony-cause';\n\nimport { isNullOrUndefined, isObject } from './misc';\n\n/**\n * Type guard for determining whether the given value is an instance of Error.\n * For errors generated via `fs.promises`, `error instanceof Error` won't work,\n * so we have to come up with another way of testing.\n *\n * @param error - The object to check.\n * @returns A boolean.\n */\nfunction isError(error: unknown): error is Error {\n return (\n error instanceof Error ||\n (isObject(error) && error.constructor.name === 'Error')\n );\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `code` property such as the type of error that Node throws for filesystem\n * operations, etc.\n *\n * @param error - The object to check.\n * @returns A boolean.\n */\nexport function isErrorWithCode(error: unknown): error is { code: string } {\n return typeof error === 'object' && error !== null && 'code' in error;\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `message` property, such as an instance of Error.\n *\n * @param error - The object to check.\n * @returns A boolean.\n */\nexport function isErrorWithMessage(\n error: unknown,\n): error is { message: string } {\n return typeof error === 'object' && error !== null && 'message' in error;\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `stack` property, such as an instance of Error.\n *\n * @param error - The object to check.\n * @returns A boolean.\n */\nexport function isErrorWithStack(error: unknown): error is { stack: string } {\n return typeof error === 'object' && error !== null && 'stack' in error;\n}\n\n/**\n * Attempts to obtain the message from a possible error object, defaulting to an\n * empty string if it is impossible to do so.\n *\n * @param error - The possible error to get the message from.\n * @returns The message if `error` is an object with a `message` property;\n * the string version of `error` if it is not `undefined` or `null`; otherwise\n * an empty string.\n */\nexport function getErrorMessage(error: unknown): string {\n if (isErrorWithMessage(error) && typeof error.message === 'string') {\n return error.message;\n }\n\n if (isNullOrUndefined(error)) {\n return '';\n }\n\n return String(error);\n}\n\n/**\n * Builds a new error object, linking it to the original error via the `cause`\n * property if it is an Error.\n *\n * This function is useful to reframe error messages in general, but is\n * _critical_ when interacting with any of Node's filesystem functions as\n * provided via `fs.promises`, because these do not produce stack traces in the\n * case of an I/O error (see <https://github.com/nodejs/node/issues/30944>).\n *\n * @param originalError - The error to be wrapped (something throwable).\n * @param message - The desired message of the new error.\n * @returns A new error object.\n */\nexport function wrapError<Throwable>(\n originalError: Throwable,\n message: string,\n): Error & { code?: string } {\n if (isError(originalError)) {\n let error: Error & { code?: string };\n if (Error.length === 2) {\n // for some reason `tsserver` is not complaining that the\n // Error constructor doesn't support a second argument in the editor,\n // but `tsc` does. Error causes are not supported by our current tsc target (ES2020, we need ES2022 to make this work)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n error = new Error(message, { cause: originalError });\n } else {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n error = new ErrorWithCause(message, { cause: originalError });\n }\n\n if (isErrorWithCode(originalError)) {\n error.code = originalError.code;\n }\n\n return error;\n }\n\n if (message.length > 0) {\n return new Error(`${String(originalError)}: ${message}`);\n }\n\n return new Error(String(originalError));\n}\n\n/**\n * Ensures we have a proper Error object.\n * If the input is already an Error, returns it unchanged.\n * Otherwise, converts to an Error with an appropriate message and preserves\n * the original value as the cause.\n *\n * @param error - The caught error (could be Error, string, or unknown).\n * @returns A proper Error instance.\n */\nexport function ensureError(error: unknown): Error {\n if (isError(error)) {\n return error;\n }\n\n const newError: Error & { cause?: unknown } = new Error('Unknown error');\n newError.cause = error;\n return newError;\n}\n"]}