@metamask/snaps-jest 8.3.2 → 8.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/CHANGELOG.md +80 -1
  2. package/LICENSE +15 -0
  3. package/dist/environment.cjs +2 -1
  4. package/dist/environment.cjs.map +1 -1
  5. package/dist/environment.d.cts +2 -2
  6. package/dist/environment.d.cts.map +1 -1
  7. package/dist/environment.d.mts +2 -2
  8. package/dist/environment.d.mts.map +1 -1
  9. package/dist/environment.mjs +3 -2
  10. package/dist/environment.mjs.map +1 -1
  11. package/dist/helpers.cjs +9 -176
  12. package/dist/helpers.cjs.map +1 -1
  13. package/dist/helpers.d.cts +1 -44
  14. package/dist/helpers.d.cts.map +1 -1
  15. package/dist/helpers.d.mts +1 -44
  16. package/dist/helpers.d.mts.map +1 -1
  17. package/dist/helpers.mjs +11 -171
  18. package/dist/helpers.mjs.map +1 -1
  19. package/dist/index.cjs +8 -2
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +2 -1
  22. package/dist/index.d.cts.map +1 -1
  23. package/dist/index.d.mts +2 -1
  24. package/dist/index.d.mts.map +1 -1
  25. package/dist/index.mjs +1 -1
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/internals/index.cjs +0 -3
  28. package/dist/internals/index.cjs.map +1 -1
  29. package/dist/internals/index.d.cts +0 -3
  30. package/dist/internals/index.d.cts.map +1 -1
  31. package/dist/internals/index.d.mts +0 -3
  32. package/dist/internals/index.d.mts.map +1 -1
  33. package/dist/internals/index.mjs +0 -3
  34. package/dist/internals/index.mjs.map +1 -1
  35. package/dist/matchers.cjs +3 -3
  36. package/dist/matchers.cjs.map +1 -1
  37. package/dist/matchers.d.cts.map +1 -1
  38. package/dist/matchers.d.mts.map +1 -1
  39. package/dist/matchers.mjs +1 -1
  40. package/dist/matchers.mjs.map +1 -1
  41. package/package.json +38 -33
  42. package/dist/internals/request.cjs +0 -143
  43. package/dist/internals/request.cjs.map +0 -1
  44. package/dist/internals/request.d.cts +0 -56
  45. package/dist/internals/request.d.cts.map +0 -1
  46. package/dist/internals/request.d.mts +0 -56
  47. package/dist/internals/request.d.mts.map +0 -1
  48. package/dist/internals/request.mjs +0 -138
  49. package/dist/internals/request.mjs.map +0 -1
  50. package/dist/internals/simulation/constants.cjs +0 -21
  51. package/dist/internals/simulation/constants.cjs.map +0 -1
  52. package/dist/internals/simulation/constants.d.cts +0 -18
  53. package/dist/internals/simulation/constants.d.cts.map +0 -1
  54. package/dist/internals/simulation/constants.d.mts +0 -18
  55. package/dist/internals/simulation/constants.d.mts.map +0 -1
  56. package/dist/internals/simulation/constants.mjs +0 -18
  57. package/dist/internals/simulation/constants.mjs.map +0 -1
  58. package/dist/internals/simulation/controllers.cjs +0 -101
  59. package/dist/internals/simulation/controllers.cjs.map +0 -1
  60. package/dist/internals/simulation/controllers.d.cts +0 -41
  61. package/dist/internals/simulation/controllers.d.cts.map +0 -1
  62. package/dist/internals/simulation/controllers.d.mts +0 -41
  63. package/dist/internals/simulation/controllers.d.mts.map +0 -1
  64. package/dist/internals/simulation/controllers.mjs +0 -96
  65. package/dist/internals/simulation/controllers.mjs.map +0 -1
  66. package/dist/internals/simulation/files.cjs +0 -94
  67. package/dist/internals/simulation/files.cjs.map +0 -1
  68. package/dist/internals/simulation/files.d.cts +0 -49
  69. package/dist/internals/simulation/files.d.cts.map +0 -1
  70. package/dist/internals/simulation/files.d.mts +0 -49
  71. package/dist/internals/simulation/files.d.mts.map +0 -1
  72. package/dist/internals/simulation/files.mjs +0 -91
  73. package/dist/internals/simulation/files.mjs.map +0 -1
  74. package/dist/internals/simulation/index.cjs +0 -22
  75. package/dist/internals/simulation/index.cjs.map +0 -1
  76. package/dist/internals/simulation/index.d.cts +0 -6
  77. package/dist/internals/simulation/index.d.cts.map +0 -1
  78. package/dist/internals/simulation/index.d.mts +0 -6
  79. package/dist/internals/simulation/index.d.mts.map +0 -1
  80. package/dist/internals/simulation/index.mjs +0 -6
  81. package/dist/internals/simulation/index.mjs.map +0 -1
  82. package/dist/internals/simulation/interface.cjs +0 -527
  83. package/dist/internals/simulation/interface.cjs.map +0 -1
  84. package/dist/internals/simulation/interface.d.cts +0 -152
  85. package/dist/internals/simulation/interface.d.cts.map +0 -1
  86. package/dist/internals/simulation/interface.d.mts +0 -152
  87. package/dist/internals/simulation/interface.d.mts.map +0 -1
  88. package/dist/internals/simulation/interface.mjs +0 -513
  89. package/dist/internals/simulation/interface.mjs.map +0 -1
  90. package/dist/internals/simulation/methods/constants.cjs +0 -72
  91. package/dist/internals/simulation/methods/constants.cjs.map +0 -1
  92. package/dist/internals/simulation/methods/constants.d.cts +0 -11
  93. package/dist/internals/simulation/methods/constants.d.cts.map +0 -1
  94. package/dist/internals/simulation/methods/constants.d.mts +0 -11
  95. package/dist/internals/simulation/methods/constants.d.mts.map +0 -1
  96. package/dist/internals/simulation/methods/constants.mjs +0 -69
  97. package/dist/internals/simulation/methods/constants.mjs.map +0 -1
  98. package/dist/internals/simulation/methods/hooks/get-preferences.cjs +0 -18
  99. package/dist/internals/simulation/methods/hooks/get-preferences.cjs.map +0 -1
  100. package/dist/internals/simulation/methods/hooks/get-preferences.d.cts +0 -14
  101. package/dist/internals/simulation/methods/hooks/get-preferences.d.cts.map +0 -1
  102. package/dist/internals/simulation/methods/hooks/get-preferences.d.mts +0 -14
  103. package/dist/internals/simulation/methods/hooks/get-preferences.d.mts.map +0 -1
  104. package/dist/internals/simulation/methods/hooks/get-preferences.mjs +0 -14
  105. package/dist/internals/simulation/methods/hooks/get-preferences.mjs.map +0 -1
  106. package/dist/internals/simulation/methods/hooks/index.cjs +0 -22
  107. package/dist/internals/simulation/methods/hooks/index.cjs.map +0 -1
  108. package/dist/internals/simulation/methods/hooks/index.d.cts +0 -6
  109. package/dist/internals/simulation/methods/hooks/index.d.cts.map +0 -1
  110. package/dist/internals/simulation/methods/hooks/index.d.mts +0 -6
  111. package/dist/internals/simulation/methods/hooks/index.d.mts.map +0 -1
  112. package/dist/internals/simulation/methods/hooks/index.mjs +0 -6
  113. package/dist/internals/simulation/methods/hooks/index.mjs.map +0 -1
  114. package/dist/internals/simulation/methods/hooks/interface.cjs +0 -24
  115. package/dist/internals/simulation/methods/hooks/interface.cjs.map +0 -1
  116. package/dist/internals/simulation/methods/hooks/interface.d.cts +0 -17
  117. package/dist/internals/simulation/methods/hooks/interface.d.cts.map +0 -1
  118. package/dist/internals/simulation/methods/hooks/interface.d.mts +0 -17
  119. package/dist/internals/simulation/methods/hooks/interface.d.mts.map +0 -1
  120. package/dist/internals/simulation/methods/hooks/interface.mjs +0 -19
  121. package/dist/internals/simulation/methods/hooks/interface.mjs.map +0 -1
  122. package/dist/internals/simulation/methods/hooks/notifications.cjs +0 -58
  123. package/dist/internals/simulation/methods/hooks/notifications.cjs.map +0 -1
  124. package/dist/internals/simulation/methods/hooks/notifications.d.cts +0 -17
  125. package/dist/internals/simulation/methods/hooks/notifications.d.cts.map +0 -1
  126. package/dist/internals/simulation/methods/hooks/notifications.d.mts +0 -17
  127. package/dist/internals/simulation/methods/hooks/notifications.d.mts.map +0 -1
  128. package/dist/internals/simulation/methods/hooks/notifications.mjs +0 -55
  129. package/dist/internals/simulation/methods/hooks/notifications.mjs.map +0 -1
  130. package/dist/internals/simulation/methods/hooks/request-user-approval.cjs +0 -38
  131. package/dist/internals/simulation/methods/hooks/request-user-approval.cjs.map +0 -1
  132. package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts +0 -16
  133. package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts.map +0 -1
  134. package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts +0 -16
  135. package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts.map +0 -1
  136. package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +0 -35
  137. package/dist/internals/simulation/methods/hooks/request-user-approval.mjs.map +0 -1
  138. package/dist/internals/simulation/methods/hooks/state.cjs +0 -84
  139. package/dist/internals/simulation/methods/hooks/state.cjs.map +0 -1
  140. package/dist/internals/simulation/methods/hooks/state.d.cts +0 -24
  141. package/dist/internals/simulation/methods/hooks/state.d.cts.map +0 -1
  142. package/dist/internals/simulation/methods/hooks/state.d.mts +0 -24
  143. package/dist/internals/simulation/methods/hooks/state.d.mts.map +0 -1
  144. package/dist/internals/simulation/methods/hooks/state.mjs +0 -79
  145. package/dist/internals/simulation/methods/hooks/state.mjs.map +0 -1
  146. package/dist/internals/simulation/methods/index.cjs +0 -18
  147. package/dist/internals/simulation/methods/index.cjs.map +0 -1
  148. package/dist/internals/simulation/methods/index.d.cts +0 -2
  149. package/dist/internals/simulation/methods/index.d.cts.map +0 -1
  150. package/dist/internals/simulation/methods/index.d.mts +0 -2
  151. package/dist/internals/simulation/methods/index.d.mts.map +0 -1
  152. package/dist/internals/simulation/methods/index.mjs +0 -2
  153. package/dist/internals/simulation/methods/index.mjs.map +0 -1
  154. package/dist/internals/simulation/methods/specifications.cjs +0 -85
  155. package/dist/internals/simulation/methods/specifications.cjs.map +0 -1
  156. package/dist/internals/simulation/methods/specifications.d.cts +0 -57
  157. package/dist/internals/simulation/methods/specifications.d.cts.map +0 -1
  158. package/dist/internals/simulation/methods/specifications.d.mts +0 -57
  159. package/dist/internals/simulation/methods/specifications.d.mts.map +0 -1
  160. package/dist/internals/simulation/methods/specifications.mjs +0 -78
  161. package/dist/internals/simulation/methods/specifications.mjs.map +0 -1
  162. package/dist/internals/simulation/middleware/engine.cjs +0 -37
  163. package/dist/internals/simulation/middleware/engine.cjs.map +0 -1
  164. package/dist/internals/simulation/middleware/engine.d.cts +0 -27
  165. package/dist/internals/simulation/middleware/engine.d.cts.map +0 -1
  166. package/dist/internals/simulation/middleware/engine.d.mts +0 -27
  167. package/dist/internals/simulation/middleware/engine.d.mts.map +0 -1
  168. package/dist/internals/simulation/middleware/engine.mjs +0 -34
  169. package/dist/internals/simulation/middleware/engine.mjs.map +0 -1
  170. package/dist/internals/simulation/middleware/index.cjs +0 -18
  171. package/dist/internals/simulation/middleware/index.cjs.map +0 -1
  172. package/dist/internals/simulation/middleware/index.d.cts +0 -2
  173. package/dist/internals/simulation/middleware/index.d.cts.map +0 -1
  174. package/dist/internals/simulation/middleware/index.d.mts +0 -2
  175. package/dist/internals/simulation/middleware/index.d.mts.map +0 -1
  176. package/dist/internals/simulation/middleware/index.mjs +0 -2
  177. package/dist/internals/simulation/middleware/index.mjs.map +0 -1
  178. package/dist/internals/simulation/middleware/internal-methods/accounts.cjs +0 -34
  179. package/dist/internals/simulation/middleware/internal-methods/accounts.cjs.map +0 -1
  180. package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts +0 -20
  181. package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts.map +0 -1
  182. package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts +0 -20
  183. package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts.map +0 -1
  184. package/dist/internals/simulation/middleware/internal-methods/accounts.mjs +0 -30
  185. package/dist/internals/simulation/middleware/internal-methods/accounts.mjs.map +0 -1
  186. package/dist/internals/simulation/middleware/internal-methods/index.cjs +0 -18
  187. package/dist/internals/simulation/middleware/internal-methods/index.cjs.map +0 -1
  188. package/dist/internals/simulation/middleware/internal-methods/index.d.cts +0 -2
  189. package/dist/internals/simulation/middleware/internal-methods/index.d.cts.map +0 -1
  190. package/dist/internals/simulation/middleware/internal-methods/index.d.mts +0 -2
  191. package/dist/internals/simulation/middleware/internal-methods/index.d.mts.map +0 -1
  192. package/dist/internals/simulation/middleware/internal-methods/index.mjs +0 -2
  193. package/dist/internals/simulation/middleware/internal-methods/index.mjs.map +0 -1
  194. package/dist/internals/simulation/middleware/internal-methods/middleware.cjs +0 -44
  195. package/dist/internals/simulation/middleware/internal-methods/middleware.cjs.map +0 -1
  196. package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts +0 -23
  197. package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts.map +0 -1
  198. package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts +0 -23
  199. package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts.map +0 -1
  200. package/dist/internals/simulation/middleware/internal-methods/middleware.mjs +0 -40
  201. package/dist/internals/simulation/middleware/internal-methods/middleware.mjs.map +0 -1
  202. package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs +0 -28
  203. package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs.map +0 -1
  204. package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts +0 -16
  205. package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts.map +0 -1
  206. package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts +0 -16
  207. package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts.map +0 -1
  208. package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs +0 -24
  209. package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs.map +0 -1
  210. package/dist/internals/simulation/middleware/mock.cjs +0 -22
  211. package/dist/internals/simulation/middleware/mock.cjs.map +0 -1
  212. package/dist/internals/simulation/middleware/mock.d.cts +0 -11
  213. package/dist/internals/simulation/middleware/mock.d.cts.map +0 -1
  214. package/dist/internals/simulation/middleware/mock.d.mts +0 -11
  215. package/dist/internals/simulation/middleware/mock.d.mts.map +0 -1
  216. package/dist/internals/simulation/middleware/mock.mjs +0 -18
  217. package/dist/internals/simulation/middleware/mock.mjs.map +0 -1
  218. package/dist/internals/simulation/options.cjs +0 -25
  219. package/dist/internals/simulation/options.cjs.map +0 -1
  220. package/dist/internals/simulation/options.d.cts +0 -40
  221. package/dist/internals/simulation/options.d.cts.map +0 -1
  222. package/dist/internals/simulation/options.d.mts +0 -40
  223. package/dist/internals/simulation/options.d.mts.map +0 -1
  224. package/dist/internals/simulation/options.mjs +0 -21
  225. package/dist/internals/simulation/options.mjs.map +0 -1
  226. package/dist/internals/simulation/simulation.cjs +0 -155
  227. package/dist/internals/simulation/simulation.cjs.map +0 -1
  228. package/dist/internals/simulation/simulation.d.cts +0 -103
  229. package/dist/internals/simulation/simulation.d.cts.map +0 -1
  230. package/dist/internals/simulation/simulation.d.mts +0 -103
  231. package/dist/internals/simulation/simulation.d.mts.map +0 -1
  232. package/dist/internals/simulation/simulation.mjs +0 -150
  233. package/dist/internals/simulation/simulation.mjs.map +0 -1
  234. package/dist/internals/simulation/store/index.cjs +0 -21
  235. package/dist/internals/simulation/store/index.cjs.map +0 -1
  236. package/dist/internals/simulation/store/index.d.cts +0 -5
  237. package/dist/internals/simulation/store/index.d.cts.map +0 -1
  238. package/dist/internals/simulation/store/index.d.mts +0 -5
  239. package/dist/internals/simulation/store/index.d.mts.map +0 -1
  240. package/dist/internals/simulation/store/index.mjs +0 -5
  241. package/dist/internals/simulation/store/index.mjs.map +0 -1
  242. package/dist/internals/simulation/store/mocks.cjs +0 -39
  243. package/dist/internals/simulation/store/mocks.cjs.map +0 -1
  244. package/dist/internals/simulation/store/mocks.d.cts +0 -36
  245. package/dist/internals/simulation/store/mocks.d.cts.map +0 -1
  246. package/dist/internals/simulation/store/mocks.d.mts +0 -36
  247. package/dist/internals/simulation/store/mocks.d.mts.map +0 -1
  248. package/dist/internals/simulation/store/mocks.mjs +0 -35
  249. package/dist/internals/simulation/store/mocks.mjs.map +0 -1
  250. package/dist/internals/simulation/store/notifications.cjs +0 -35
  251. package/dist/internals/simulation/store/notifications.cjs.map +0 -1
  252. package/dist/internals/simulation/store/notifications.d.cts +0 -45
  253. package/dist/internals/simulation/store/notifications.d.cts.map +0 -1
  254. package/dist/internals/simulation/store/notifications.d.mts +0 -45
  255. package/dist/internals/simulation/store/notifications.d.mts.map +0 -1
  256. package/dist/internals/simulation/store/notifications.mjs +0 -32
  257. package/dist/internals/simulation/store/notifications.mjs.map +0 -1
  258. package/dist/internals/simulation/store/state.cjs +0 -54
  259. package/dist/internals/simulation/store/state.cjs.map +0 -1
  260. package/dist/internals/simulation/store/state.d.cts +0 -56
  261. package/dist/internals/simulation/store/state.d.cts.map +0 -1
  262. package/dist/internals/simulation/store/state.d.mts +0 -56
  263. package/dist/internals/simulation/store/state.d.mts.map +0 -1
  264. package/dist/internals/simulation/store/state.mjs +0 -50
  265. package/dist/internals/simulation/store/state.mjs.map +0 -1
  266. package/dist/internals/simulation/store/store.cjs +0 -51
  267. package/dist/internals/simulation/store/store.cjs.map +0 -1
  268. package/dist/internals/simulation/store/store.d.cts +0 -22
  269. package/dist/internals/simulation/store/store.d.cts.map +0 -1
  270. package/dist/internals/simulation/store/store.d.mts +0 -22
  271. package/dist/internals/simulation/store/store.d.mts.map +0 -1
  272. package/dist/internals/simulation/store/store.mjs +0 -45
  273. package/dist/internals/simulation/store/store.mjs.map +0 -1
  274. package/dist/internals/simulation/store/ui.cjs +0 -24
  275. package/dist/internals/simulation/store/ui.cjs.map +0 -1
  276. package/dist/internals/simulation/store/ui.d.cts +0 -27
  277. package/dist/internals/simulation/store/ui.d.cts.map +0 -1
  278. package/dist/internals/simulation/store/ui.d.mts +0 -27
  279. package/dist/internals/simulation/store/ui.d.mts.map +0 -1
  280. package/dist/internals/simulation/store/ui.mjs +0 -21
  281. package/dist/internals/simulation/store/ui.mjs.map +0 -1
  282. package/dist/internals/structs.cjs +0 -157
  283. package/dist/internals/structs.cjs.map +0 -1
  284. package/dist/internals/structs.d.cts +0 -205
  285. package/dist/internals/structs.d.cts.map +0 -1
  286. package/dist/internals/structs.d.mts +0 -205
  287. package/dist/internals/structs.d.mts.map +0 -1
  288. package/dist/internals/structs.mjs +0 -154
  289. package/dist/internals/structs.mjs.map +0 -1
  290. package/dist/types/index.cjs +0 -18
  291. package/dist/types/index.cjs.map +0 -1
  292. package/dist/types/index.d.cts +0 -2
  293. package/dist/types/index.d.cts.map +0 -1
  294. package/dist/types/index.d.mts +0 -2
  295. package/dist/types/index.d.mts.map +0 -1
  296. package/dist/types/index.mjs +0 -2
  297. package/dist/types/index.mjs.map +0 -1
  298. package/dist/types/types.cjs +0 -3
  299. package/dist/types/types.cjs.map +0 -1
  300. package/dist/types/types.d.cts +0 -386
  301. package/dist/types/types.d.cts.map +0 -1
  302. package/dist/types/types.d.mts +0 -386
  303. package/dist/types/types.d.mts.map +0 -1
  304. package/dist/types/types.mjs +0 -2
  305. package/dist/types/types.mjs.map +0 -1
@@ -1,94 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getFileToUpload = exports.getFileSize = exports.getContentType = exports.getSnapFile = void 0;
7
- const snaps_sdk_1 = require("@metamask/snaps-sdk");
8
- const snaps_utils_1 = require("@metamask/snaps-utils");
9
- const utils_1 = require("@metamask/utils");
10
- const promises_1 = require("fs/promises");
11
- const mime_1 = __importDefault(require("mime/index.js"));
12
- const path_1 = require("path");
13
- /**
14
- * Get a statically defined Snap file from an array of files.
15
- *
16
- * @param files - The Snap files.
17
- * @param path - The file path.
18
- * @param encoding - The requested file encoding.
19
- * @returns The file in the requested encoding if found, otherwise null.
20
- */
21
- async function getSnapFile(files, path, encoding = snaps_sdk_1.AuxiliaryFileEncoding.Base64) {
22
- const normalizedPath = (0, snaps_utils_1.normalizeRelative)(path);
23
- const base64 = files
24
- .find((file) => file.path === normalizedPath)
25
- ?.toString('base64');
26
- if (!base64) {
27
- return null;
28
- }
29
- return await (0, snaps_utils_1.encodeAuxiliaryFile)(base64, encoding);
30
- }
31
- exports.getSnapFile = getSnapFile;
32
- /**
33
- * Get the content type of a file based on its extension.
34
- *
35
- * @param extension - The file extension.
36
- * @returns The content type of the file. If the content type cannot be inferred
37
- * from the extension, `application/octet-stream` is returned.
38
- */
39
- function getContentType(extension) {
40
- return mime_1.default.getType(extension) ?? 'application/octet-stream';
41
- }
42
- exports.getContentType = getContentType;
43
- /**
44
- * Get the size of a file, from a file path or a `Uint8Array`.
45
- *
46
- * @param file - The file to get the size of. This can be a path to a file or a
47
- * `Uint8Array` containing the file contents. If this is a path, the file is
48
- * resolved relative to the current working directory.
49
- * @returns The size of the file in bytes.
50
- */
51
- async function getFileSize(file) {
52
- if (typeof file === 'string') {
53
- const { size } = await (0, promises_1.stat)((0, path_1.resolve)(process.cwd(), file));
54
- return size;
55
- }
56
- return file.length;
57
- }
58
- exports.getFileSize = getFileSize;
59
- /**
60
- * Get a file object to upload, from a file path or a `Uint8Array`, with an
61
- * optional file name and content type.
62
- *
63
- * @param file - The file to upload. This can be a path to a file or a
64
- * `Uint8Array` containing the file contents. If this is a path, the file is
65
- * resolved relative to the current working directory.
66
- * @param options - The file options.
67
- * @param options.fileName - The name of the file. By default, this is
68
- * inferred from the file path if it's a path, and defaults to an empty string
69
- * if it's a `Uint8Array`.
70
- * @param options.contentType - The content type of the file. By default, this
71
- * is inferred from the file name if it's a path, and defaults to
72
- * `application/octet-stream` if it's a `Uint8Array` or the content type
73
- * cannot be inferred from the file name.
74
- * @returns The file object to upload.
75
- */
76
- async function getFileToUpload(file, { fileName, contentType } = {}) {
77
- if (typeof file === 'string') {
78
- const buffer = await (0, promises_1.readFile)((0, path_1.resolve)(process.cwd(), file));
79
- return {
80
- name: fileName ?? (0, path_1.basename)(file),
81
- size: buffer.byteLength,
82
- contentType: contentType ?? getContentType((0, path_1.extname)(file)),
83
- contents: (0, utils_1.bytesToBase64)(buffer),
84
- };
85
- }
86
- return {
87
- name: fileName ?? '',
88
- size: file.length,
89
- contentType: contentType ?? 'application/octet-stream',
90
- contents: (0, utils_1.bytesToBase64)(file),
91
- };
92
- }
93
- exports.getFileToUpload = getFileToUpload;
94
- //# sourceMappingURL=files.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files.cjs","sourceRoot":"","sources":["../../../src/internals/simulation/files.ts"],"names":[],"mappings":";;;;;;AACA,mDAA4D;AAE5D,uDAA+E;AAC/E,2CAAgD;AAChD,0CAA6C;AAC7C,yDAAwB;AACxB,+BAAkD;AAIlD;;;;;;;GAOG;AACI,KAAK,UAAU,WAAW,CAC/B,KAAoB,EACpB,IAAY,EACZ,WAAkC,iCAAqB,CAAC,MAAM;IAE9D,MAAM,cAAc,GAAG,IAAA,+BAAiB,EAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,KAAK;SACjB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC;QAC7C,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEvB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,IAAA,iCAAmB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACrD,CAAC;AAfD,kCAeC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,SAAiB;IAC9C,OAAO,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,0BAA0B,CAAC;AAC/D,CAAC;AAFD,wCAEC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,WAAW,CAAC,IAAyB;IACzD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,eAAI,EAAC,IAAA,cAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,CAAC,MAAM,CAAC;AACrB,CAAC;AAPD,kCAOC;AAED;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,eAAe,CACnC,IAAyB,EACzB,EAAE,QAAQ,EAAE,WAAW,KAAkB,EAAE;IAE3C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAA,cAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QAE5D,OAAO;YACL,IAAI,EAAE,QAAQ,IAAI,IAAA,eAAQ,EAAC,IAAI,CAAC;YAChC,IAAI,EAAE,MAAM,CAAC,UAAU;YACvB,WAAW,EAAE,WAAW,IAAI,cAAc,CAAC,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;YACzD,QAAQ,EAAE,IAAA,qBAAa,EAAC,MAAM,CAAC;SAChC,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ,IAAI,EAAE;QACpB,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,WAAW,EAAE,WAAW,IAAI,0BAA0B;QACtD,QAAQ,EAAE,IAAA,qBAAa,EAAC,IAAI,CAAC;KAC9B,CAAC;AACJ,CAAC;AArBD,0CAqBC","sourcesContent":["import type { File } from '@metamask/snaps-sdk';\nimport { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport type { VirtualFile } from '@metamask/snaps-utils';\nimport { encodeAuxiliaryFile, normalizeRelative } from '@metamask/snaps-utils';\nimport { bytesToBase64 } from '@metamask/utils';\nimport { readFile, stat } from 'fs/promises';\nimport mime from 'mime';\nimport { basename, extname, resolve } from 'path';\n\nimport type { FileOptions } from '../../types';\n\n/**\n * Get a statically defined Snap file from an array of files.\n *\n * @param files - The Snap files.\n * @param path - The file path.\n * @param encoding - The requested file encoding.\n * @returns The file in the requested encoding if found, otherwise null.\n */\nexport async function getSnapFile(\n files: VirtualFile[],\n path: string,\n encoding: AuxiliaryFileEncoding = AuxiliaryFileEncoding.Base64,\n) {\n const normalizedPath = normalizeRelative(path);\n const base64 = files\n .find((file) => file.path === normalizedPath)\n ?.toString('base64');\n\n if (!base64) {\n return null;\n }\n\n return await encodeAuxiliaryFile(base64, encoding);\n}\n\n/**\n * Get the content type of a file based on its extension.\n *\n * @param extension - The file extension.\n * @returns The content type of the file. If the content type cannot be inferred\n * from the extension, `application/octet-stream` is returned.\n */\nexport function getContentType(extension: string) {\n return mime.getType(extension) ?? 'application/octet-stream';\n}\n\n/**\n * Get the size of a file, from a file path or a `Uint8Array`.\n *\n * @param file - The file to get the size of. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @returns The size of the file in bytes.\n */\nexport async function getFileSize(file: string | Uint8Array) {\n if (typeof file === 'string') {\n const { size } = await stat(resolve(process.cwd(), file));\n return size;\n }\n\n return file.length;\n}\n\n/**\n * Get a file object to upload, from a file path or a `Uint8Array`, with an\n * optional file name and content type.\n *\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n * @returns The file object to upload.\n */\nexport async function getFileToUpload(\n file: string | Uint8Array,\n { fileName, contentType }: FileOptions = {},\n): Promise<File> {\n if (typeof file === 'string') {\n const buffer = await readFile(resolve(process.cwd(), file));\n\n return {\n name: fileName ?? basename(file),\n size: buffer.byteLength,\n contentType: contentType ?? getContentType(extname(file)),\n contents: bytesToBase64(buffer),\n };\n }\n\n return {\n name: fileName ?? '',\n size: file.length,\n contentType: contentType ?? 'application/octet-stream',\n contents: bytesToBase64(file),\n };\n}\n"]}
@@ -1,49 +0,0 @@
1
- import type { File } from "@metamask/snaps-sdk";
2
- import { AuxiliaryFileEncoding } from "@metamask/snaps-sdk";
3
- import type { VirtualFile } from "@metamask/snaps-utils";
4
- import type { FileOptions } from "../../types/index.cjs";
5
- /**
6
- * Get a statically defined Snap file from an array of files.
7
- *
8
- * @param files - The Snap files.
9
- * @param path - The file path.
10
- * @param encoding - The requested file encoding.
11
- * @returns The file in the requested encoding if found, otherwise null.
12
- */
13
- export declare function getSnapFile(files: VirtualFile[], path: string, encoding?: AuxiliaryFileEncoding): Promise<string | null>;
14
- /**
15
- * Get the content type of a file based on its extension.
16
- *
17
- * @param extension - The file extension.
18
- * @returns The content type of the file. If the content type cannot be inferred
19
- * from the extension, `application/octet-stream` is returned.
20
- */
21
- export declare function getContentType(extension: string): string;
22
- /**
23
- * Get the size of a file, from a file path or a `Uint8Array`.
24
- *
25
- * @param file - The file to get the size of. This can be a path to a file or a
26
- * `Uint8Array` containing the file contents. If this is a path, the file is
27
- * resolved relative to the current working directory.
28
- * @returns The size of the file in bytes.
29
- */
30
- export declare function getFileSize(file: string | Uint8Array): Promise<number>;
31
- /**
32
- * Get a file object to upload, from a file path or a `Uint8Array`, with an
33
- * optional file name and content type.
34
- *
35
- * @param file - The file to upload. This can be a path to a file or a
36
- * `Uint8Array` containing the file contents. If this is a path, the file is
37
- * resolved relative to the current working directory.
38
- * @param options - The file options.
39
- * @param options.fileName - The name of the file. By default, this is
40
- * inferred from the file path if it's a path, and defaults to an empty string
41
- * if it's a `Uint8Array`.
42
- * @param options.contentType - The content type of the file. By default, this
43
- * is inferred from the file name if it's a path, and defaults to
44
- * `application/octet-stream` if it's a `Uint8Array` or the content type
45
- * cannot be inferred from the file name.
46
- * @returns The file object to upload.
47
- */
48
- export declare function getFileToUpload(file: string | Uint8Array, { fileName, contentType }?: FileOptions): Promise<File>;
49
- //# sourceMappingURL=files.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files.d.cts","sourceRoot":"","sources":["../../../src/internals/simulation/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAChD,OAAO,EAAE,qBAAqB,EAAE,4BAA4B;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAOzD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAAoB;AAE/C;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,WAAW,EAAE,EACpB,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,qBAAoD,0BAY/D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,UAE/C;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,mBAO1D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAE,WAAgB,GAC1C,OAAO,CAAC,IAAI,CAAC,CAkBf"}
@@ -1,49 +0,0 @@
1
- import type { File } from "@metamask/snaps-sdk";
2
- import { AuxiliaryFileEncoding } from "@metamask/snaps-sdk";
3
- import type { VirtualFile } from "@metamask/snaps-utils";
4
- import type { FileOptions } from "../../types/index.mjs";
5
- /**
6
- * Get a statically defined Snap file from an array of files.
7
- *
8
- * @param files - The Snap files.
9
- * @param path - The file path.
10
- * @param encoding - The requested file encoding.
11
- * @returns The file in the requested encoding if found, otherwise null.
12
- */
13
- export declare function getSnapFile(files: VirtualFile[], path: string, encoding?: AuxiliaryFileEncoding): Promise<string | null>;
14
- /**
15
- * Get the content type of a file based on its extension.
16
- *
17
- * @param extension - The file extension.
18
- * @returns The content type of the file. If the content type cannot be inferred
19
- * from the extension, `application/octet-stream` is returned.
20
- */
21
- export declare function getContentType(extension: string): string;
22
- /**
23
- * Get the size of a file, from a file path or a `Uint8Array`.
24
- *
25
- * @param file - The file to get the size of. This can be a path to a file or a
26
- * `Uint8Array` containing the file contents. If this is a path, the file is
27
- * resolved relative to the current working directory.
28
- * @returns The size of the file in bytes.
29
- */
30
- export declare function getFileSize(file: string | Uint8Array): Promise<number>;
31
- /**
32
- * Get a file object to upload, from a file path or a `Uint8Array`, with an
33
- * optional file name and content type.
34
- *
35
- * @param file - The file to upload. This can be a path to a file or a
36
- * `Uint8Array` containing the file contents. If this is a path, the file is
37
- * resolved relative to the current working directory.
38
- * @param options - The file options.
39
- * @param options.fileName - The name of the file. By default, this is
40
- * inferred from the file path if it's a path, and defaults to an empty string
41
- * if it's a `Uint8Array`.
42
- * @param options.contentType - The content type of the file. By default, this
43
- * is inferred from the file name if it's a path, and defaults to
44
- * `application/octet-stream` if it's a `Uint8Array` or the content type
45
- * cannot be inferred from the file name.
46
- * @returns The file object to upload.
47
- */
48
- export declare function getFileToUpload(file: string | Uint8Array, { fileName, contentType }?: FileOptions): Promise<File>;
49
- //# sourceMappingURL=files.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files.d.mts","sourceRoot":"","sources":["../../../src/internals/simulation/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAChD,OAAO,EAAE,qBAAqB,EAAE,4BAA4B;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAOzD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAAoB;AAE/C;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,WAAW,EAAE,EACpB,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,qBAAoD,0BAY/D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,UAE/C;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,mBAO1D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAE,WAAgB,GAC1C,OAAO,CAAC,IAAI,CAAC,CAkBf"}
@@ -1,91 +0,0 @@
1
- function $importDefault(module) {
2
- if (module?.__esModule) {
3
- return module.default;
4
- }
5
- return module;
6
- }
7
- import { AuxiliaryFileEncoding } from "@metamask/snaps-sdk";
8
- import { encodeAuxiliaryFile, normalizeRelative } from "@metamask/snaps-utils";
9
- import { bytesToBase64 } from "@metamask/utils";
10
- import { readFile, stat } from "fs/promises";
11
- import $mime from "mime/index.js";
12
- const mime = $importDefault($mime);
13
- import { basename, extname, resolve } from "path";
14
- /**
15
- * Get a statically defined Snap file from an array of files.
16
- *
17
- * @param files - The Snap files.
18
- * @param path - The file path.
19
- * @param encoding - The requested file encoding.
20
- * @returns The file in the requested encoding if found, otherwise null.
21
- */
22
- export async function getSnapFile(files, path, encoding = AuxiliaryFileEncoding.Base64) {
23
- const normalizedPath = normalizeRelative(path);
24
- const base64 = files
25
- .find((file) => file.path === normalizedPath)
26
- ?.toString('base64');
27
- if (!base64) {
28
- return null;
29
- }
30
- return await encodeAuxiliaryFile(base64, encoding);
31
- }
32
- /**
33
- * Get the content type of a file based on its extension.
34
- *
35
- * @param extension - The file extension.
36
- * @returns The content type of the file. If the content type cannot be inferred
37
- * from the extension, `application/octet-stream` is returned.
38
- */
39
- export function getContentType(extension) {
40
- return mime.getType(extension) ?? 'application/octet-stream';
41
- }
42
- /**
43
- * Get the size of a file, from a file path or a `Uint8Array`.
44
- *
45
- * @param file - The file to get the size of. This can be a path to a file or a
46
- * `Uint8Array` containing the file contents. If this is a path, the file is
47
- * resolved relative to the current working directory.
48
- * @returns The size of the file in bytes.
49
- */
50
- export async function getFileSize(file) {
51
- if (typeof file === 'string') {
52
- const { size } = await stat(resolve(process.cwd(), file));
53
- return size;
54
- }
55
- return file.length;
56
- }
57
- /**
58
- * Get a file object to upload, from a file path or a `Uint8Array`, with an
59
- * optional file name and content type.
60
- *
61
- * @param file - The file to upload. This can be a path to a file or a
62
- * `Uint8Array` containing the file contents. If this is a path, the file is
63
- * resolved relative to the current working directory.
64
- * @param options - The file options.
65
- * @param options.fileName - The name of the file. By default, this is
66
- * inferred from the file path if it's a path, and defaults to an empty string
67
- * if it's a `Uint8Array`.
68
- * @param options.contentType - The content type of the file. By default, this
69
- * is inferred from the file name if it's a path, and defaults to
70
- * `application/octet-stream` if it's a `Uint8Array` or the content type
71
- * cannot be inferred from the file name.
72
- * @returns The file object to upload.
73
- */
74
- export async function getFileToUpload(file, { fileName, contentType } = {}) {
75
- if (typeof file === 'string') {
76
- const buffer = await readFile(resolve(process.cwd(), file));
77
- return {
78
- name: fileName ?? basename(file),
79
- size: buffer.byteLength,
80
- contentType: contentType ?? getContentType(extname(file)),
81
- contents: bytesToBase64(buffer),
82
- };
83
- }
84
- return {
85
- name: fileName ?? '',
86
- size: file.length,
87
- contentType: contentType ?? 'application/octet-stream',
88
- contents: bytesToBase64(file),
89
- };
90
- }
91
- //# sourceMappingURL=files.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files.mjs","sourceRoot":"","sources":["../../../src/internals/simulation/files.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,qBAAqB,EAAE,4BAA4B;AAE5D,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,8BAA8B;AAC/E,OAAO,EAAE,aAAa,EAAE,wBAAwB;AAChD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,oBAAoB;AAC7C,OAAO,KAAI,sBAAa;;AACxB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa;AAIlD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAoB,EACpB,IAAY,EACZ,WAAkC,qBAAqB,CAAC,MAAM;IAE9D,MAAM,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,KAAK;SACjB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC;QAC7C,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEvB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,0BAA0B,CAAC;AAC/D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAyB;IACzD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,CAAC,MAAM,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,IAAyB,EACzB,EAAE,QAAQ,EAAE,WAAW,KAAkB,EAAE;IAE3C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QAE5D,OAAO;YACL,IAAI,EAAE,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC;YAChC,IAAI,EAAE,MAAM,CAAC,UAAU;YACvB,WAAW,EAAE,WAAW,IAAI,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACzD,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC;SAChC,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ,IAAI,EAAE;QACpB,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,WAAW,EAAE,WAAW,IAAI,0BAA0B;QACtD,QAAQ,EAAE,aAAa,CAAC,IAAI,CAAC;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import type { File } from '@metamask/snaps-sdk';\nimport { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport type { VirtualFile } from '@metamask/snaps-utils';\nimport { encodeAuxiliaryFile, normalizeRelative } from '@metamask/snaps-utils';\nimport { bytesToBase64 } from '@metamask/utils';\nimport { readFile, stat } from 'fs/promises';\nimport mime from 'mime';\nimport { basename, extname, resolve } from 'path';\n\nimport type { FileOptions } from '../../types';\n\n/**\n * Get a statically defined Snap file from an array of files.\n *\n * @param files - The Snap files.\n * @param path - The file path.\n * @param encoding - The requested file encoding.\n * @returns The file in the requested encoding if found, otherwise null.\n */\nexport async function getSnapFile(\n files: VirtualFile[],\n path: string,\n encoding: AuxiliaryFileEncoding = AuxiliaryFileEncoding.Base64,\n) {\n const normalizedPath = normalizeRelative(path);\n const base64 = files\n .find((file) => file.path === normalizedPath)\n ?.toString('base64');\n\n if (!base64) {\n return null;\n }\n\n return await encodeAuxiliaryFile(base64, encoding);\n}\n\n/**\n * Get the content type of a file based on its extension.\n *\n * @param extension - The file extension.\n * @returns The content type of the file. If the content type cannot be inferred\n * from the extension, `application/octet-stream` is returned.\n */\nexport function getContentType(extension: string) {\n return mime.getType(extension) ?? 'application/octet-stream';\n}\n\n/**\n * Get the size of a file, from a file path or a `Uint8Array`.\n *\n * @param file - The file to get the size of. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @returns The size of the file in bytes.\n */\nexport async function getFileSize(file: string | Uint8Array) {\n if (typeof file === 'string') {\n const { size } = await stat(resolve(process.cwd(), file));\n return size;\n }\n\n return file.length;\n}\n\n/**\n * Get a file object to upload, from a file path or a `Uint8Array`, with an\n * optional file name and content type.\n *\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n * @returns The file object to upload.\n */\nexport async function getFileToUpload(\n file: string | Uint8Array,\n { fileName, contentType }: FileOptions = {},\n): Promise<File> {\n if (typeof file === 'string') {\n const buffer = await readFile(resolve(process.cwd(), file));\n\n return {\n name: fileName ?? basename(file),\n size: buffer.byteLength,\n contentType: contentType ?? getContentType(extname(file)),\n contents: bytesToBase64(buffer),\n };\n }\n\n return {\n name: fileName ?? '',\n size: file.length,\n contentType: contentType ?? 'application/octet-stream',\n contents: bytesToBase64(file),\n };\n}\n"]}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./constants.cjs"), exports);
18
- __exportStar(require("./interface.cjs"), exports);
19
- __exportStar(require("./simulation.cjs"), exports);
20
- __exportStar(require("./options.cjs"), exports);
21
- __exportStar(require("./store/index.cjs"), exports);
22
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/internals/simulation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA4B;AAC5B,kDAA4B;AAC5B,mDAA6B;AAC7B,gDAA0B;AAC1B,oDAAwB","sourcesContent":["export * from './constants';\nexport * from './interface';\nexport * from './simulation';\nexport * from './options';\nexport * from './store';\n"]}
@@ -1,6 +0,0 @@
1
- export * from "./constants.cjs";
2
- export * from "./interface.cjs";
3
- export * from "./simulation.cjs";
4
- export * from "./options.cjs";
5
- export * from "./store/index.cjs";
6
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/internals/simulation/index.ts"],"names":[],"mappings":"AAAA,gCAA4B;AAC5B,gCAA4B;AAC5B,iCAA6B;AAC7B,8BAA0B;AAC1B,kCAAwB"}
@@ -1,6 +0,0 @@
1
- export * from "./constants.mjs";
2
- export * from "./interface.mjs";
3
- export * from "./simulation.mjs";
4
- export * from "./options.mjs";
5
- export * from "./store/index.mjs";
6
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/internals/simulation/index.ts"],"names":[],"mappings":"AAAA,gCAA4B;AAC5B,gCAA4B;AAC5B,iCAA6B;AAC7B,8BAA0B;AAC1B,kCAAwB"}
@@ -1,6 +0,0 @@
1
- export * from "./constants.mjs";
2
- export * from "./interface.mjs";
3
- export * from "./simulation.mjs";
4
- export * from "./options.mjs";
5
- export * from "./store/index.mjs";
6
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/internals/simulation/index.ts"],"names":[],"mappings":"AAAA,gCAA4B;AAC5B,gCAA4B;AAC5B,iCAA6B;AAC7B,8BAA0B;AAC1B,kCAAwB","sourcesContent":["export * from './constants';\nexport * from './interface';\nexport * from './simulation';\nexport * from './options';\nexport * from './store';\n"]}