@uploadista/core 0.0.2

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 (359) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/.turbo/turbo-check.log +231 -0
  3. package/.turbo/turbo-format.log +5 -0
  4. package/LICENSE +21 -0
  5. package/README.md +1120 -0
  6. package/dist/chunk-CUT6urMc.cjs +1 -0
  7. package/dist/debounce-C2SeqcxD.js +2 -0
  8. package/dist/debounce-C2SeqcxD.js.map +1 -0
  9. package/dist/debounce-LZK7yS7Z.cjs +1 -0
  10. package/dist/errors/index.cjs +1 -0
  11. package/dist/errors/index.d.cts +3 -0
  12. package/dist/errors/index.d.ts +3 -0
  13. package/dist/errors/index.d.ts.map +1 -0
  14. package/dist/errors/index.js +2 -0
  15. package/dist/errors/uploadista-error.d.ts +209 -0
  16. package/dist/errors/uploadista-error.d.ts.map +1 -0
  17. package/dist/errors/uploadista-error.js +322 -0
  18. package/dist/errors-8i_aMxOE.js +1 -0
  19. package/dist/errors-CRm1FHHT.cjs +0 -0
  20. package/dist/flow/edge.d.ts +47 -0
  21. package/dist/flow/edge.d.ts.map +1 -0
  22. package/dist/flow/edge.js +40 -0
  23. package/dist/flow/event.d.ts +206 -0
  24. package/dist/flow/event.d.ts.map +1 -0
  25. package/dist/flow/event.js +53 -0
  26. package/dist/flow/flow-server.d.ts +223 -0
  27. package/dist/flow/flow-server.d.ts.map +1 -0
  28. package/dist/flow/flow-server.js +614 -0
  29. package/dist/flow/flow.d.ts +238 -0
  30. package/dist/flow/flow.d.ts.map +1 -0
  31. package/dist/flow/flow.js +629 -0
  32. package/dist/flow/index.cjs +1 -0
  33. package/dist/flow/index.d.cts +6 -0
  34. package/dist/flow/index.d.ts +24 -0
  35. package/dist/flow/index.d.ts.map +1 -0
  36. package/dist/flow/index.js +24 -0
  37. package/dist/flow/node.d.ts +136 -0
  38. package/dist/flow/node.d.ts.map +1 -0
  39. package/dist/flow/node.js +153 -0
  40. package/dist/flow/nodes/index.d.ts +8 -0
  41. package/dist/flow/nodes/index.d.ts.map +1 -0
  42. package/dist/flow/nodes/index.js +7 -0
  43. package/dist/flow/nodes/input-node.d.ts +78 -0
  44. package/dist/flow/nodes/input-node.d.ts.map +1 -0
  45. package/dist/flow/nodes/input-node.js +233 -0
  46. package/dist/flow/nodes/storage-node.d.ts +67 -0
  47. package/dist/flow/nodes/storage-node.d.ts.map +1 -0
  48. package/dist/flow/nodes/storage-node.js +94 -0
  49. package/dist/flow/nodes/streaming-input-node.d.ts +69 -0
  50. package/dist/flow/nodes/streaming-input-node.d.ts.map +1 -0
  51. package/dist/flow/nodes/streaming-input-node.js +156 -0
  52. package/dist/flow/nodes/transform-node.d.ts +85 -0
  53. package/dist/flow/nodes/transform-node.d.ts.map +1 -0
  54. package/dist/flow/nodes/transform-node.js +107 -0
  55. package/dist/flow/parallel-scheduler.d.ts +175 -0
  56. package/dist/flow/parallel-scheduler.d.ts.map +1 -0
  57. package/dist/flow/parallel-scheduler.js +193 -0
  58. package/dist/flow/plugins/credential-provider.d.ts +47 -0
  59. package/dist/flow/plugins/credential-provider.d.ts.map +1 -0
  60. package/dist/flow/plugins/credential-provider.js +24 -0
  61. package/dist/flow/plugins/image-ai-plugin.d.ts +61 -0
  62. package/dist/flow/plugins/image-ai-plugin.d.ts.map +1 -0
  63. package/dist/flow/plugins/image-ai-plugin.js +21 -0
  64. package/dist/flow/plugins/image-plugin.d.ts +52 -0
  65. package/dist/flow/plugins/image-plugin.d.ts.map +1 -0
  66. package/dist/flow/plugins/image-plugin.js +22 -0
  67. package/dist/flow/plugins/types/describe-image-node.d.ts +16 -0
  68. package/dist/flow/plugins/types/describe-image-node.d.ts.map +1 -0
  69. package/dist/flow/plugins/types/describe-image-node.js +9 -0
  70. package/dist/flow/plugins/types/index.d.ts +9 -0
  71. package/dist/flow/plugins/types/index.d.ts.map +1 -0
  72. package/dist/flow/plugins/types/index.js +8 -0
  73. package/dist/flow/plugins/types/optimize-node.d.ts +20 -0
  74. package/dist/flow/plugins/types/optimize-node.d.ts.map +1 -0
  75. package/dist/flow/plugins/types/optimize-node.js +11 -0
  76. package/dist/flow/plugins/types/remove-background-node.d.ts +16 -0
  77. package/dist/flow/plugins/types/remove-background-node.d.ts.map +1 -0
  78. package/dist/flow/plugins/types/remove-background-node.js +9 -0
  79. package/dist/flow/plugins/types/resize-node.d.ts +21 -0
  80. package/dist/flow/plugins/types/resize-node.d.ts.map +1 -0
  81. package/dist/flow/plugins/types/resize-node.js +16 -0
  82. package/dist/flow/plugins/zip-plugin.d.ts +62 -0
  83. package/dist/flow/plugins/zip-plugin.d.ts.map +1 -0
  84. package/dist/flow/plugins/zip-plugin.js +21 -0
  85. package/dist/flow/typed-flow.d.ts +90 -0
  86. package/dist/flow/typed-flow.d.ts.map +1 -0
  87. package/dist/flow/typed-flow.js +59 -0
  88. package/dist/flow/types/flow-file.d.ts +45 -0
  89. package/dist/flow/types/flow-file.d.ts.map +1 -0
  90. package/dist/flow/types/flow-file.js +27 -0
  91. package/dist/flow/types/flow-job.d.ts +118 -0
  92. package/dist/flow/types/flow-job.d.ts.map +1 -0
  93. package/dist/flow/types/flow-job.js +11 -0
  94. package/dist/flow/types/flow-types.d.ts +321 -0
  95. package/dist/flow/types/flow-types.d.ts.map +1 -0
  96. package/dist/flow/types/flow-types.js +52 -0
  97. package/dist/flow/types/index.d.ts +4 -0
  98. package/dist/flow/types/index.d.ts.map +1 -0
  99. package/dist/flow/types/index.js +3 -0
  100. package/dist/flow/types/run-args.d.ts +38 -0
  101. package/dist/flow/types/run-args.d.ts.map +1 -0
  102. package/dist/flow/types/run-args.js +30 -0
  103. package/dist/flow/types/type-validator.d.ts +26 -0
  104. package/dist/flow/types/type-validator.d.ts.map +1 -0
  105. package/dist/flow/types/type-validator.js +134 -0
  106. package/dist/flow/utils/resolve-upload-metadata.d.ts +11 -0
  107. package/dist/flow/utils/resolve-upload-metadata.d.ts.map +1 -0
  108. package/dist/flow/utils/resolve-upload-metadata.js +28 -0
  109. package/dist/flow-2zXnEiWL.cjs +1 -0
  110. package/dist/flow-CRaKy7Vj.js +2 -0
  111. package/dist/flow-CRaKy7Vj.js.map +1 -0
  112. package/dist/generate-id-Dm-Vboxq.d.ts +34 -0
  113. package/dist/generate-id-Dm-Vboxq.d.ts.map +1 -0
  114. package/dist/generate-id-LjJRLD6N.d.cts +34 -0
  115. package/dist/generate-id-LjJRLD6N.d.cts.map +1 -0
  116. package/dist/generate-id-xHp_Z7Cl.cjs +1 -0
  117. package/dist/generate-id-yohS1ZDk.js +2 -0
  118. package/dist/generate-id-yohS1ZDk.js.map +1 -0
  119. package/dist/index-BO8GZlbD.d.cts +1040 -0
  120. package/dist/index-BO8GZlbD.d.cts.map +1 -0
  121. package/dist/index-BoGG5KAY.d.ts +1 -0
  122. package/dist/index-BtBZHVmz.d.cts +1 -0
  123. package/dist/index-D-CoVpkZ.d.ts +1004 -0
  124. package/dist/index-D-CoVpkZ.d.ts.map +1 -0
  125. package/dist/index.cjs +1 -0
  126. package/dist/index.d.cts +6 -0
  127. package/dist/index.d.ts +5 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.js +5 -0
  130. package/dist/logger/logger.cjs +1 -0
  131. package/dist/logger/logger.d.cts +8 -0
  132. package/dist/logger/logger.d.cts.map +1 -0
  133. package/dist/logger/logger.d.ts +5 -0
  134. package/dist/logger/logger.d.ts.map +1 -0
  135. package/dist/logger/logger.js +10 -0
  136. package/dist/logger/logger.js.map +1 -0
  137. package/dist/semaphore-0ZwjVpyF.js +2 -0
  138. package/dist/semaphore-0ZwjVpyF.js.map +1 -0
  139. package/dist/semaphore-BHprIjFI.d.cts +37 -0
  140. package/dist/semaphore-BHprIjFI.d.cts.map +1 -0
  141. package/dist/semaphore-DThupBkc.d.ts +37 -0
  142. package/dist/semaphore-DThupBkc.d.ts.map +1 -0
  143. package/dist/semaphore-DVrONiAV.cjs +1 -0
  144. package/dist/stream-limiter-CoWKv39w.js +2 -0
  145. package/dist/stream-limiter-CoWKv39w.js.map +1 -0
  146. package/dist/stream-limiter-JgOwmkMa.cjs +1 -0
  147. package/dist/streams/multi-stream.cjs +1 -0
  148. package/dist/streams/multi-stream.d.cts +91 -0
  149. package/dist/streams/multi-stream.d.cts.map +1 -0
  150. package/dist/streams/multi-stream.d.ts +86 -0
  151. package/dist/streams/multi-stream.d.ts.map +1 -0
  152. package/dist/streams/multi-stream.js +149 -0
  153. package/dist/streams/multi-stream.js.map +1 -0
  154. package/dist/streams/stream-limiter.cjs +1 -0
  155. package/dist/streams/stream-limiter.d.cts +36 -0
  156. package/dist/streams/stream-limiter.d.cts.map +1 -0
  157. package/dist/streams/stream-limiter.d.ts +27 -0
  158. package/dist/streams/stream-limiter.d.ts.map +1 -0
  159. package/dist/streams/stream-limiter.js +49 -0
  160. package/dist/streams/stream-splitter.cjs +1 -0
  161. package/dist/streams/stream-splitter.d.cts +68 -0
  162. package/dist/streams/stream-splitter.d.cts.map +1 -0
  163. package/dist/streams/stream-splitter.d.ts +51 -0
  164. package/dist/streams/stream-splitter.d.ts.map +1 -0
  165. package/dist/streams/stream-splitter.js +175 -0
  166. package/dist/streams/stream-splitter.js.map +1 -0
  167. package/dist/types/data-store-registry.d.ts +13 -0
  168. package/dist/types/data-store-registry.d.ts.map +1 -0
  169. package/dist/types/data-store-registry.js +4 -0
  170. package/dist/types/data-store.d.ts +316 -0
  171. package/dist/types/data-store.d.ts.map +1 -0
  172. package/dist/types/data-store.js +157 -0
  173. package/dist/types/event-broadcaster.d.ts +28 -0
  174. package/dist/types/event-broadcaster.d.ts.map +1 -0
  175. package/dist/types/event-broadcaster.js +6 -0
  176. package/dist/types/event-emitter.d.ts +378 -0
  177. package/dist/types/event-emitter.d.ts.map +1 -0
  178. package/dist/types/event-emitter.js +223 -0
  179. package/dist/types/index.cjs +1 -0
  180. package/dist/types/index.d.cts +6 -0
  181. package/dist/types/index.d.ts +10 -0
  182. package/dist/types/index.d.ts.map +1 -0
  183. package/dist/types/index.js +9 -0
  184. package/dist/types/input-file.d.ts +104 -0
  185. package/dist/types/input-file.d.ts.map +1 -0
  186. package/dist/types/input-file.js +27 -0
  187. package/dist/types/kv-store.d.ts +281 -0
  188. package/dist/types/kv-store.d.ts.map +1 -0
  189. package/dist/types/kv-store.js +234 -0
  190. package/dist/types/middleware.d.ts +17 -0
  191. package/dist/types/middleware.d.ts.map +1 -0
  192. package/dist/types/middleware.js +21 -0
  193. package/dist/types/upload-event.d.ts +105 -0
  194. package/dist/types/upload-event.d.ts.map +1 -0
  195. package/dist/types/upload-event.js +71 -0
  196. package/dist/types/upload-file.d.ts +136 -0
  197. package/dist/types/upload-file.d.ts.map +1 -0
  198. package/dist/types/upload-file.js +34 -0
  199. package/dist/types/websocket.d.ts +144 -0
  200. package/dist/types/websocket.d.ts.map +1 -0
  201. package/dist/types/websocket.js +40 -0
  202. package/dist/types-BT-cvi7T.cjs +1 -0
  203. package/dist/types-DhU2j-XF.js +2 -0
  204. package/dist/types-DhU2j-XF.js.map +1 -0
  205. package/dist/upload/convert-to-stream.d.ts +38 -0
  206. package/dist/upload/convert-to-stream.d.ts.map +1 -0
  207. package/dist/upload/convert-to-stream.js +43 -0
  208. package/dist/upload/convert-upload-to-flow-file.d.ts +14 -0
  209. package/dist/upload/convert-upload-to-flow-file.d.ts.map +1 -0
  210. package/dist/upload/convert-upload-to-flow-file.js +21 -0
  211. package/dist/upload/create-upload.d.ts +68 -0
  212. package/dist/upload/create-upload.d.ts.map +1 -0
  213. package/dist/upload/create-upload.js +157 -0
  214. package/dist/upload/index.cjs +1 -0
  215. package/dist/upload/index.d.cts +6 -0
  216. package/dist/upload/index.d.ts +4 -0
  217. package/dist/upload/index.d.ts.map +1 -0
  218. package/dist/upload/index.js +3 -0
  219. package/dist/upload/mime.d.ts +24 -0
  220. package/dist/upload/mime.d.ts.map +1 -0
  221. package/dist/upload/mime.js +351 -0
  222. package/dist/upload/upload-chunk.d.ts +58 -0
  223. package/dist/upload/upload-chunk.d.ts.map +1 -0
  224. package/dist/upload/upload-chunk.js +277 -0
  225. package/dist/upload/upload-server.d.ts +221 -0
  226. package/dist/upload/upload-server.d.ts.map +1 -0
  227. package/dist/upload/upload-server.js +181 -0
  228. package/dist/upload/upload-strategy-negotiator.d.ts +148 -0
  229. package/dist/upload/upload-strategy-negotiator.d.ts.map +1 -0
  230. package/dist/upload/upload-strategy-negotiator.js +217 -0
  231. package/dist/upload/upload-url.d.ts +68 -0
  232. package/dist/upload/upload-url.d.ts.map +1 -0
  233. package/dist/upload/upload-url.js +142 -0
  234. package/dist/upload/write-to-store.d.ts +77 -0
  235. package/dist/upload/write-to-store.d.ts.map +1 -0
  236. package/dist/upload/write-to-store.js +147 -0
  237. package/dist/upload-DLuICjpP.cjs +1 -0
  238. package/dist/upload-DaXO34dE.js +2 -0
  239. package/dist/upload-DaXO34dE.js.map +1 -0
  240. package/dist/uploadista-error-BB-Wdiz9.cjs +22 -0
  241. package/dist/uploadista-error-BVsVxqvz.js +23 -0
  242. package/dist/uploadista-error-BVsVxqvz.js.map +1 -0
  243. package/dist/uploadista-error-CwxYs4EB.d.ts +52 -0
  244. package/dist/uploadista-error-CwxYs4EB.d.ts.map +1 -0
  245. package/dist/uploadista-error-kKlhLRhY.d.cts +52 -0
  246. package/dist/uploadista-error-kKlhLRhY.d.cts.map +1 -0
  247. package/dist/utils/checksum.d.ts +22 -0
  248. package/dist/utils/checksum.d.ts.map +1 -0
  249. package/dist/utils/checksum.js +49 -0
  250. package/dist/utils/debounce.cjs +1 -0
  251. package/dist/utils/debounce.d.cts +38 -0
  252. package/dist/utils/debounce.d.cts.map +1 -0
  253. package/dist/utils/debounce.d.ts +36 -0
  254. package/dist/utils/debounce.d.ts.map +1 -0
  255. package/dist/utils/debounce.js +73 -0
  256. package/dist/utils/generate-id.cjs +1 -0
  257. package/dist/utils/generate-id.d.cts +2 -0
  258. package/dist/utils/generate-id.d.ts +32 -0
  259. package/dist/utils/generate-id.d.ts.map +1 -0
  260. package/dist/utils/generate-id.js +23 -0
  261. package/dist/utils/md5.cjs +1 -0
  262. package/dist/utils/md5.d.cts +73 -0
  263. package/dist/utils/md5.d.cts.map +1 -0
  264. package/dist/utils/md5.d.ts +71 -0
  265. package/dist/utils/md5.d.ts.map +1 -0
  266. package/dist/utils/md5.js +417 -0
  267. package/dist/utils/md5.js.map +1 -0
  268. package/dist/utils/once.cjs +1 -0
  269. package/dist/utils/once.d.cts +25 -0
  270. package/dist/utils/once.d.cts.map +1 -0
  271. package/dist/utils/once.d.ts +21 -0
  272. package/dist/utils/once.d.ts.map +1 -0
  273. package/dist/utils/once.js +54 -0
  274. package/dist/utils/once.js.map +1 -0
  275. package/dist/utils/semaphore.cjs +1 -0
  276. package/dist/utils/semaphore.d.cts +3 -0
  277. package/dist/utils/semaphore.d.ts +78 -0
  278. package/dist/utils/semaphore.d.ts.map +1 -0
  279. package/dist/utils/semaphore.js +134 -0
  280. package/dist/utils/throttle.cjs +1 -0
  281. package/dist/utils/throttle.d.cts +24 -0
  282. package/dist/utils/throttle.d.cts.map +1 -0
  283. package/dist/utils/throttle.d.ts +18 -0
  284. package/dist/utils/throttle.d.ts.map +1 -0
  285. package/dist/utils/throttle.js +20 -0
  286. package/dist/utils/throttle.js.map +1 -0
  287. package/docs/PARALLEL_EXECUTION.md +206 -0
  288. package/docs/PARALLEL_EXECUTION_QUICKSTART.md +142 -0
  289. package/docs/PARALLEL_EXECUTION_REFACTOR.md +184 -0
  290. package/package.json +80 -0
  291. package/src/errors/__tests__/uploadista-error.test.ts +251 -0
  292. package/src/errors/index.ts +2 -0
  293. package/src/errors/uploadista-error.ts +394 -0
  294. package/src/flow/README.md +352 -0
  295. package/src/flow/edge.test.ts +146 -0
  296. package/src/flow/edge.ts +60 -0
  297. package/src/flow/event.ts +229 -0
  298. package/src/flow/flow-server.ts +1089 -0
  299. package/src/flow/flow.ts +1050 -0
  300. package/src/flow/index.ts +28 -0
  301. package/src/flow/node.ts +249 -0
  302. package/src/flow/nodes/index.ts +8 -0
  303. package/src/flow/nodes/input-node.ts +296 -0
  304. package/src/flow/nodes/storage-node.ts +128 -0
  305. package/src/flow/nodes/transform-node.ts +154 -0
  306. package/src/flow/parallel-scheduler.ts +259 -0
  307. package/src/flow/plugins/credential-provider.ts +48 -0
  308. package/src/flow/plugins/image-ai-plugin.ts +66 -0
  309. package/src/flow/plugins/image-plugin.ts +60 -0
  310. package/src/flow/plugins/types/describe-image-node.ts +16 -0
  311. package/src/flow/plugins/types/index.ts +9 -0
  312. package/src/flow/plugins/types/optimize-node.ts +18 -0
  313. package/src/flow/plugins/types/remove-background-node.ts +18 -0
  314. package/src/flow/plugins/types/resize-node.ts +26 -0
  315. package/src/flow/plugins/zip-plugin.ts +69 -0
  316. package/src/flow/typed-flow.ts +279 -0
  317. package/src/flow/types/flow-file.ts +51 -0
  318. package/src/flow/types/flow-job.ts +138 -0
  319. package/src/flow/types/flow-types.ts +353 -0
  320. package/src/flow/types/index.ts +6 -0
  321. package/src/flow/types/run-args.ts +40 -0
  322. package/src/flow/types/type-validator.ts +204 -0
  323. package/src/flow/utils/resolve-upload-metadata.ts +48 -0
  324. package/src/index.ts +5 -0
  325. package/src/logger/logger.ts +14 -0
  326. package/src/streams/stream-limiter.test.ts +150 -0
  327. package/src/streams/stream-limiter.ts +75 -0
  328. package/src/types/data-store.ts +427 -0
  329. package/src/types/event-broadcaster.ts +39 -0
  330. package/src/types/event-emitter.ts +349 -0
  331. package/src/types/index.ts +9 -0
  332. package/src/types/input-file.ts +107 -0
  333. package/src/types/kv-store.ts +375 -0
  334. package/src/types/middleware.ts +54 -0
  335. package/src/types/upload-event.ts +75 -0
  336. package/src/types/upload-file.ts +139 -0
  337. package/src/types/websocket.ts +65 -0
  338. package/src/upload/convert-to-stream.ts +48 -0
  339. package/src/upload/create-upload.ts +214 -0
  340. package/src/upload/index.ts +3 -0
  341. package/src/upload/mime.ts +436 -0
  342. package/src/upload/upload-chunk.ts +364 -0
  343. package/src/upload/upload-server.ts +390 -0
  344. package/src/upload/upload-strategy-negotiator.ts +316 -0
  345. package/src/upload/upload-url.ts +173 -0
  346. package/src/upload/write-to-store.ts +211 -0
  347. package/src/utils/checksum.ts +61 -0
  348. package/src/utils/debounce.test.ts +126 -0
  349. package/src/utils/debounce.ts +89 -0
  350. package/src/utils/generate-id.ts +35 -0
  351. package/src/utils/md5.ts +475 -0
  352. package/src/utils/once.test.ts +83 -0
  353. package/src/utils/once.ts +63 -0
  354. package/src/utils/throttle.test.ts +101 -0
  355. package/src/utils/throttle.ts +29 -0
  356. package/tsconfig.json +20 -0
  357. package/tsconfig.tsbuildinfo +1 -0
  358. package/tsdown.config.ts +25 -0
  359. package/vitest.config.ts +15 -0
@@ -0,0 +1,2 @@
1
+ import{UploadistaError as e}from"./uploadista-error-BVsVxqvz.js";import{UploadEventEmitter as t,UploadEventType as n,UploadFileDataStores as r,UploadFileKVStore as i}from"./types-DhU2j-XF.js";import{GenerateId as a}from"./generate-id-yohS1ZDk.js";import{StreamLimiterEffect as o}from"./stream-limiter-CoWKv39w.js";import{Context as s,Effect as c,Layer as l,Ref as u,Stream as d}from"effect";const f=(e,t)=>{if(e.length>=4){let t=e.slice(0,4);if(t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71)return`image/png`;if(t[0]===255&&t[1]===216)return`image/jpeg`;if(t[0]===71&&t[1]===73&&t[2]===70)return`image/gif`;if(t[0]===82&&t[1]===73&&t[2]===70&&t[3]===70)return`image/webp`}if(t)switch(t.split(`.`).pop()?.toLowerCase()){case`jpg`:case`jpeg`:return`image/jpeg`;case`png`:return`image/png`;case`gif`:return`image/gif`;case`webp`:return`image/webp`;case`pdf`:return`application/pdf`;case`txt`:return`text/plain`;case`json`:return`application/json`;default:return`application/octet-stream`}return`application/octet-stream`},p=(e,{dataStoreService:t,kvStore:r,eventEmitter:i,generateId:a,isBuffer:o})=>c.gen(function*(){let s=yield*t.getDataStore(e.storageId,o),c=yield*a.generateId(),{size:l,type:u,fileName:d,lastModified:f}=e,p={type:u,fileName:d??``};f&&(p.lastModified=f.toString());let m={id:c,size:l,metadata:p,offset:0,creationDate:new Date().toISOString(),storage:{id:e.storageId,isBuffer:o,type:u,path:``,bucket:s.bucket}},h=yield*s.create(m);return yield*r.set(c,h),yield*i.emit(c,{type:n.UPLOAD_STARTED,data:h}),h});function m(t){return d.fromReadableStream(()=>t,t=>new e({code:`UNKNOWN_ERROR`,status:500,body:String(t)}))}function h({data:t,upload:r,dataStore:i,maxFileSize:a,controller:s,eventEmitter:l,uploadProgressInterval:d=200}){return c.gen(function*(){let f=m(t);if(s.signal.aborted)return yield*c.fail(e.fromCode(`ABORTED`));let p=new AbortController,{signal:h}=p,g=()=>{p.abort()};return s.signal.addEventListener(`abort`,g,{once:!0}),yield*c.acquireUseRelease(c.sync(()=>({signal:h,onAbort:g})),({signal:t})=>c.gen(function*(){let e=yield*u.make(0),t=o.limit({maxSize:a})(f);return yield*i.write({stream:t,file_id:r.id,offset:r.offset},{onProgress:t=>{let i=Date.now();u.get(e).pipe(c.flatMap(a=>i-a>=d?c.gen(function*(){yield*u.set(e,i),yield*l.emit(r.id,{type:n.UPLOAD_PROGRESS,data:{id:r.id,progress:t,total:r.size??0}})}):c.void),c.runPromise).catch(()=>{})}})}).pipe(c.catchAll(t=>t instanceof Error&&t.name===`AbortError`?c.fail(e.fromCode(`ABORTED`)):t instanceof e?c.fail(t):c.fail(e.fromCode(`FILE_WRITE_ERROR`,{cause:t})))),({onAbort:e})=>c.sync(()=>{s.signal.removeEventListener(`abort`,e)}))})}const g=(e,t,{dataStoreService:r,kvStore:i,eventEmitter:a})=>c.gen(function*(){let o=yield*i.get(e),s=yield*r.getDataStore(o.storage.id,o.storage.isBuffer),c=new AbortController;return o.offset=yield*h({dataStore:s,data:t,upload:o,maxFileSize:1e8,controller:c,uploadProgressInterval:200,eventEmitter:a}),yield*i.set(e,o),yield*a.emit(o.id,{type:n.UPLOAD_PROGRESS,data:{id:o.id,progress:o.offset,total:o.size??0}}),o});var _=class extends s.Tag(`UploadServer`)(){};function v(){return c.gen(function*(){let e=yield*i,n=yield*t,o=yield*a,s=yield*r;return{upload:(t,r)=>c.gen(function*(){let i=yield*p(t,{dataStoreService:s,kvStore:e,eventEmitter:n,generateId:o});return yield*g(i.id,r,{dataStoreService:s,kvStore:e,eventEmitter:n})}),createUpload:t=>c.gen(function*(){return yield*p(t,{dataStoreService:s,kvStore:e,eventEmitter:n,generateId:o})}),uploadChunk:(t,r)=>c.gen(function*(){return yield*g(t,r,{dataStoreService:s,kvStore:e,eventEmitter:n})}),getUpload:t=>c.gen(function*(){return yield*e.get(t)}),read:e=>c.gen(function*(){return yield*(yield*s.getDataStore(e)).read(e)}),getCapabilities:e=>c.gen(function*(){return(yield*s.getDataStore(e)).getCapabilities()}),subscribeToUploadEvents:(e,t)=>c.gen(function*(){yield*n.subscribe(e,t)}),unsubscribeFromUploadEvents:e=>c.gen(function*(){yield*n.unsubscribe(e)})}})}const y=l.effect(_,v());var b=class{constructor(e,t){this.capabilities=e,this.validateUploadStrategy=t}negotiateStrategy(e){let t=[],n=[],r=`single`,i=e.preferredChunkSize??this.capabilities.optimalChunkSize??1024*1024,a=e.parallelUploads??1;if(e.preferredStrategy&&(this.validateUploadStrategy(e.preferredStrategy)?(r=e.preferredStrategy,t.push(`Using preferred strategy: ${r}`)):n.push(`Preferred strategy '${e.preferredStrategy}' not supported by data store, falling back`)),(!e.preferredStrategy||!this.validateUploadStrategy(e.preferredStrategy))&&(this.capabilities.supportsParallelUploads&&e.fileSize>(e.minChunkSizeForParallel??10*1024*1024)?(r=`parallel`,t.push(`Selected parallel upload for large file (${e.fileSize} bytes)`)):(r=`single`,t.push(this.capabilities.supportsParallelUploads?`Selected single upload for small file (${e.fileSize} bytes)`:`Selected single upload (parallel not supported by data store)`))),this.capabilities.minChunkSize&&i<this.capabilities.minChunkSize&&(n.push(`Chunk size ${i} below minimum ${this.capabilities.minChunkSize}, adjusting`),i=this.capabilities.minChunkSize),this.capabilities.maxChunkSize&&i>this.capabilities.maxChunkSize&&(n.push(`Chunk size ${i} above maximum ${this.capabilities.maxChunkSize}, adjusting`),i=this.capabilities.maxChunkSize),r===`parallel`&&(this.capabilities.maxConcurrentUploads&&a>this.capabilities.maxConcurrentUploads&&(n.push(`Parallel uploads ${a} exceeds maximum ${this.capabilities.maxConcurrentUploads}, adjusting`),a=this.capabilities.maxConcurrentUploads),this.capabilities.maxParts)){let t=Math.ceil(e.fileSize/i);if(t>this.capabilities.maxParts){let r=Math.ceil(e.fileSize/this.capabilities.maxParts);n.push(`Estimated parts ${t} exceeds maximum ${this.capabilities.maxParts}, increasing chunk size`),i=Math.max(i,r)}}return this.validateUploadStrategy(r)||(n.push(`Final strategy validation failed, falling back to single upload`),r=`single`,a=1),t.push(`Data store capabilities: parallel=${this.capabilities.supportsParallelUploads}, concatenation=${this.capabilities.supportsConcatenation}, resumable=${this.capabilities.supportsResumableUploads}`),{strategy:r,chunkSize:i,parallelUploads:r===`parallel`?a:1,reasoning:t,warnings:n}}getDataStoreCapabilities(){return this.capabilities}validateConfiguration(e){let t=[];return e.preferredStrategy&&!this.validateUploadStrategy(e.preferredStrategy)&&t.push(`Preferred strategy '${e.preferredStrategy}' not supported by data store`),e.preferredChunkSize&&(this.capabilities.minChunkSize&&e.preferredChunkSize<this.capabilities.minChunkSize&&t.push(`Chunk size ${e.preferredChunkSize} below data store minimum ${this.capabilities.minChunkSize}`),this.capabilities.maxChunkSize&&e.preferredChunkSize>this.capabilities.maxChunkSize&&t.push(`Chunk size ${e.preferredChunkSize} above data store maximum ${this.capabilities.maxChunkSize}`)),e.parallelUploads&&this.capabilities.maxConcurrentUploads&&e.parallelUploads>this.capabilities.maxConcurrentUploads&&t.push(`Parallel uploads ${e.parallelUploads} exceeds data store maximum ${this.capabilities.maxConcurrentUploads}`),{valid:t.length===0,errors:t}}};export{_ as UploadServer,b as UploadStrategyNegotiator,v as createUploadServer,f as detectMimeType,y as uploadServer};
2
+ //# sourceMappingURL=upload-DaXO34dE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-DaXO34dE.js","names":["metadataObject: Record<string, string>","file: UploadFile","onAbort","capabilities: DataStoreCapabilities","validateUploadStrategy: (strategy: UploadStrategy) => boolean","reasoning: string[]","warnings: string[]","strategy: UploadStrategy","errors: string[]"],"sources":["../src/upload/mime.ts","../src/upload/create-upload.ts","../src/upload/convert-to-stream.ts","../src/upload/write-to-store.ts","../src/upload/upload-chunk.ts","../src/upload/upload-server.ts","../src/upload/upload-strategy-negotiator.ts"],"sourcesContent":["// Helper to detect mime type from buffer\nexport const detectMimeType = (\n buffer: Uint8Array,\n filename?: string,\n): string => {\n if (buffer.length >= 4) {\n const header = buffer.slice(0, 4);\n\n // PNG\n if (\n header[0] === 0x89 &&\n header[1] === 0x50 &&\n header[2] === 0x4e &&\n header[3] === 0x47\n ) {\n return \"image/png\";\n }\n\n // JPEG\n if (header[0] === 0xff && header[1] === 0xd8) {\n return \"image/jpeg\";\n }\n\n // GIF\n if (header[0] === 0x47 && header[1] === 0x49 && header[2] === 0x46) {\n return \"image/gif\";\n }\n\n // WebP\n if (\n header[0] === 0x52 &&\n header[1] === 0x49 &&\n header[2] === 0x46 &&\n header[3] === 0x46\n ) {\n return \"image/webp\";\n }\n }\n\n // Fallback to extension-based detection\n if (filename) {\n const ext = filename.split(\".\").pop()?.toLowerCase();\n switch (ext) {\n case \"jpg\":\n case \"jpeg\":\n return \"image/jpeg\";\n case \"png\":\n return \"image/png\";\n case \"gif\":\n return \"image/gif\";\n case \"webp\":\n return \"image/webp\";\n case \"pdf\":\n return \"application/pdf\";\n case \"txt\":\n return \"text/plain\";\n case \"json\":\n return \"application/json\";\n default:\n return \"application/octet-stream\";\n }\n }\n\n return \"application/octet-stream\";\n};\n","import { Effect } from \"effect\";\nimport {\n type EventEmitter,\n type InputFile,\n type KvStore,\n type UploadEvent,\n UploadEventType,\n type UploadFile,\n type UploadFileDataStoresShape,\n} from \"../types\";\nimport type { GenerateIdShape } from \"../utils/generate-id\";\n\n// File creation\nexport const createUpload = (\n inputFile: InputFile,\n {\n dataStoreService,\n kvStore,\n eventEmitter,\n generateId,\n isBuffer,\n }: {\n dataStoreService: UploadFileDataStoresShape;\n kvStore: KvStore<UploadFile>;\n eventEmitter: EventEmitter<UploadEvent>;\n generateId: GenerateIdShape;\n isBuffer?: boolean;\n },\n) =>\n Effect.gen(function* () {\n // Get datastore using Effect\n const dataStore = yield* dataStoreService.getDataStore(\n inputFile.storageId,\n isBuffer,\n );\n\n const id = yield* generateId.generateId();\n const { size, type, fileName, lastModified } = inputFile;\n\n const metadataObject: Record<string, string> = {\n type,\n fileName: fileName ?? \"\",\n };\n if (lastModified) {\n metadataObject.lastModified = lastModified.toString();\n }\n\n const file: UploadFile = {\n id,\n size,\n metadata: metadataObject,\n offset: 0,\n creationDate: new Date().toISOString(),\n storage: {\n id: inputFile.storageId,\n isBuffer,\n type,\n path: \"\",\n bucket: dataStore.bucket,\n },\n };\n\n // Create file using Effect\n const fileCreated = yield* dataStore.create(file);\n\n // Store in KV store\n yield* kvStore.set(id, fileCreated);\n\n // Emit event\n yield* eventEmitter.emit(id, {\n type: UploadEventType.UPLOAD_STARTED,\n data: fileCreated,\n });\n\n return fileCreated;\n });\n","import { Stream } from \"effect\";\nimport { UploadistaError } from \"../errors\";\n\nexport function convertToStream<T>(data: ReadableStream<T>) {\n return Stream.fromReadableStream(\n () => data,\n (error) =>\n new UploadistaError({\n code: \"UNKNOWN_ERROR\",\n status: 500,\n body: String(error),\n }),\n );\n}\n","import { Effect, Ref } from \"effect\";\nimport { UploadistaError } from \"../errors\";\nimport { StreamLimiterEffect } from \"../streams/stream-limiter\";\nimport type { DataStore, UploadEvent, UploadFile } from \"../types\";\nimport { type EventEmitter, UploadEventType } from \"../types\";\nimport { convertToStream } from \"./convert-to-stream\";\n\ntype WriteToStoreOptions = {\n data: ReadableStream<Uint8Array>;\n upload: UploadFile;\n dataStore: DataStore<UploadFile>;\n maxFileSize: number;\n controller: AbortController;\n eventEmitter: EventEmitter<UploadEvent>;\n uploadProgressInterval?: number;\n};\n\nexport function writeToStore({\n data,\n upload,\n dataStore,\n maxFileSize,\n controller,\n eventEmitter,\n uploadProgressInterval = 200,\n}: WriteToStoreOptions) {\n return Effect.gen(function* () {\n const stream = convertToStream(data);\n // Check if already aborted\n if (controller.signal.aborted) {\n return yield* Effect.fail(UploadistaError.fromCode(\"ABORTED\"));\n }\n\n // Create an AbortController to manage the stream pipeline\n const abortController = new AbortController();\n const { signal } = abortController;\n\n // Set up abort handling\n const onAbort = () => {\n // stream.cancel();\n abortController.abort();\n };\n\n controller.signal.addEventListener(\"abort\", onAbort, { once: true });\n\n return yield* Effect.acquireUseRelease(\n Effect.sync(() => ({ signal, onAbort })),\n ({ signal: _signal }) =>\n Effect.gen(function* () {\n // Create a ref to track the last progress emission time for throttling\n const lastEmitTime = yield* Ref.make(0);\n\n // Create the stream limiter\n const limiter = StreamLimiterEffect.limit({\n maxSize: maxFileSize,\n });\n\n // Pipe the data through the limiter\n const limitedStream = limiter(stream);\n\n // Write to the data store with progress tracking\n const offset = yield* dataStore.write(\n {\n stream: limitedStream,\n file_id: upload.id,\n offset: upload.offset,\n },\n {\n onProgress: (newOffset: number) => {\n // Simple throttling using timestamp check\n const now = Date.now();\n Ref.get(lastEmitTime)\n .pipe(\n Effect.flatMap((lastTime) => {\n if (now - lastTime >= uploadProgressInterval) {\n return Effect.gen(function* () {\n yield* Ref.set(lastEmitTime, now);\n yield* eventEmitter.emit(upload.id, {\n type: UploadEventType.UPLOAD_PROGRESS,\n data: {\n id: upload.id,\n progress: newOffset,\n total: upload.size ?? 0,\n },\n });\n });\n }\n return Effect.void;\n }),\n Effect.runPromise,\n )\n .catch(() => {\n // Ignore errors during progress emission\n });\n },\n },\n );\n\n return offset;\n }).pipe(\n Effect.catchAll((error) => {\n if (error instanceof Error && error.name === \"AbortError\") {\n return Effect.fail(UploadistaError.fromCode(\"ABORTED\"));\n }\n if (error instanceof UploadistaError) {\n return Effect.fail(error);\n }\n return Effect.fail(\n UploadistaError.fromCode(\"FILE_WRITE_ERROR\", { cause: error }),\n );\n }),\n ),\n ({ onAbort }) =>\n Effect.sync(() => {\n controller.signal.removeEventListener(\"abort\", onAbort);\n }),\n );\n });\n}\n","import { Effect } from \"effect\";\nimport {\n type EventEmitter,\n type KvStore,\n type UploadEvent,\n UploadEventType,\n type UploadFile,\n type UploadFileDataStoresShape,\n} from \"../types\";\nimport { writeToStore } from \"./write-to-store\";\n\n// Chunk upload\nexport const uploadChunk = (\n uploadId: string,\n chunk: ReadableStream,\n {\n dataStoreService,\n kvStore,\n eventEmitter,\n }: {\n dataStoreService: UploadFileDataStoresShape;\n kvStore: KvStore<UploadFile>;\n eventEmitter: EventEmitter<UploadEvent>;\n },\n) =>\n Effect.gen(function* () {\n // Get file from KV store\n const file = yield* kvStore.get(uploadId);\n\n // Get datastore\n const dataStore = yield* dataStoreService.getDataStore(\n file.storage.id,\n file.storage.isBuffer,\n );\n\n // Note: AbortController could be used for cancellation if needed\n\n // Write to store using writeToStore Effect\n const controller = new AbortController();\n\n const chunkSize = yield* writeToStore({\n dataStore,\n data: chunk,\n upload: file,\n maxFileSize: 100_000_000,\n controller,\n uploadProgressInterval: 200,\n eventEmitter,\n });\n\n file.offset = chunkSize;\n\n // Update KV store\n yield* kvStore.set(uploadId, file);\n\n // Emit progress event\n yield* eventEmitter.emit(file.id, {\n type: UploadEventType.UPLOAD_PROGRESS,\n data: {\n id: file.id,\n progress: file.offset,\n total: file.size ?? 0,\n },\n });\n\n return file;\n });\n","import { Context, Effect, Layer } from \"effect\";\nimport type { UploadistaError } from \"../errors\";\nimport type {\n DataStore,\n DataStoreCapabilities,\n EventEmitter,\n InputFile,\n KvStore,\n Middleware,\n UploadEvent,\n UploadFile,\n WebSocketConnection,\n} from \"../types\";\nimport {\n UploadEventEmitter,\n UploadFileDataStores,\n UploadFileKVStore,\n} from \"../types\";\nimport { GenerateId, type GenerateIdShape } from \"../utils/generate-id\";\nimport { createUpload } from \"./create-upload\";\nimport { uploadChunk } from \"./upload-chunk\";\n\nexport type UploadServerOptions = {\n dataStore:\n | ((storageId: string) => Promise<DataStore<UploadFile>>)\n | DataStore<UploadFile>;\n kvStore: KvStore<UploadFile>;\n eventEmitter: EventEmitter<UploadEvent>;\n generateId?: GenerateIdShape;\n middlewares?: Middleware[];\n withTracing?: boolean;\n};\n\n// Effect-based UploadServer type\nexport type UploadServerShape = {\n createUpload: (\n inputFile: InputFile,\n isBuffer?: boolean,\n ) => Effect.Effect<UploadFile, UploadistaError>;\n uploadChunk: (\n uploadId: string,\n chunk: ReadableStream,\n isBuffer?: boolean,\n ) => Effect.Effect<UploadFile, UploadistaError>;\n getCapabilities: (\n storageId: string,\n ) => Effect.Effect<DataStoreCapabilities, UploadistaError>;\n upload: (\n file: InputFile,\n stream: ReadableStream,\n ) => Effect.Effect<UploadFile, UploadistaError>;\n getUpload: (uploadId: string) => Effect.Effect<UploadFile, UploadistaError>;\n read: (uploadId: string) => Effect.Effect<Uint8Array, UploadistaError>;\n subscribeToUploadEvents: (\n uploadId: string,\n connection: WebSocketConnection,\n ) => Effect.Effect<void, UploadistaError>;\n unsubscribeFromUploadEvents: (\n uploadId: string,\n ) => Effect.Effect<void, UploadistaError>;\n};\nexport class UploadServer extends Context.Tag(\"UploadServer\")<\n UploadServer,\n UploadServerShape\n>() {}\n\nexport function createUploadServer() {\n return Effect.gen(function* () {\n const kvStore = yield* UploadFileKVStore;\n const eventEmitter = yield* UploadEventEmitter;\n const generateId = yield* GenerateId;\n const dataStoreService = yield* UploadFileDataStores;\n\n return {\n upload: (inputFile: InputFile, stream: ReadableStream) =>\n Effect.gen(function* () {\n const fileCreated = yield* createUpload(inputFile, {\n dataStoreService,\n kvStore,\n eventEmitter,\n generateId,\n });\n return yield* uploadChunk(fileCreated.id, stream, {\n dataStoreService,\n kvStore,\n eventEmitter,\n });\n }),\n createUpload: (inputFile: InputFile) =>\n Effect.gen(function* () {\n const fileCreated = yield* createUpload(inputFile, {\n dataStoreService,\n kvStore,\n eventEmitter,\n generateId,\n });\n return fileCreated;\n }),\n uploadChunk: (uploadId: string, chunk: ReadableStream) =>\n Effect.gen(function* () {\n const file = yield* uploadChunk(uploadId, chunk, {\n dataStoreService,\n kvStore,\n eventEmitter,\n });\n return file;\n }),\n getUpload: (uploadId: string) =>\n Effect.gen(function* () {\n const file = yield* kvStore.get(uploadId);\n return file;\n }),\n read: (uploadId: string) =>\n Effect.gen(function* () {\n const dataStore = yield* dataStoreService.getDataStore(uploadId);\n return yield* dataStore.read(uploadId);\n }),\n getCapabilities: (storageId: string) =>\n Effect.gen(function* () {\n const dataStore = yield* dataStoreService.getDataStore(storageId);\n return dataStore.getCapabilities();\n }),\n subscribeToUploadEvents: (\n uploadId: string,\n connection: WebSocketConnection,\n ) =>\n Effect.gen(function* () {\n yield* eventEmitter.subscribe(uploadId, connection);\n }),\n unsubscribeFromUploadEvents: (uploadId: string) =>\n Effect.gen(function* () {\n yield* eventEmitter.unsubscribe(uploadId);\n }),\n } satisfies UploadServerShape;\n });\n}\n\nexport const uploadServer = Layer.effect(UploadServer, createUploadServer());\n","import type { DataStoreCapabilities, UploadStrategy } from \"../types\";\n\nexport type UploadStrategyOptions = {\n fileSize: number;\n preferredStrategy?: UploadStrategy;\n preferredChunkSize?: number;\n parallelUploads?: number;\n minChunkSizeForParallel?: number;\n};\n\nexport type NegotiatedStrategy = {\n strategy: UploadStrategy;\n chunkSize: number;\n parallelUploads: number;\n reasoning: string[];\n warnings: string[];\n};\n\nexport class UploadStrategyNegotiator {\n constructor(\n private capabilities: DataStoreCapabilities,\n private validateUploadStrategy: (strategy: UploadStrategy) => boolean,\n ) {}\n\n negotiateStrategy(options: UploadStrategyOptions): NegotiatedStrategy {\n const reasoning: string[] = [];\n const warnings: string[] = [];\n\n let strategy: UploadStrategy = \"single\";\n let chunkSize =\n options.preferredChunkSize ??\n this.capabilities.optimalChunkSize ??\n 1024 * 1024;\n let parallelUploads = options.parallelUploads ?? 1;\n\n // Check if data store supports the preferred strategy\n if (options.preferredStrategy) {\n if (!this.validateUploadStrategy(options.preferredStrategy)) {\n warnings.push(\n `Preferred strategy '${options.preferredStrategy}' not supported by data store, falling back`,\n );\n } else {\n strategy = options.preferredStrategy;\n reasoning.push(`Using preferred strategy: ${strategy}`);\n }\n }\n\n // Automatic strategy selection based on capabilities and file size\n if (\n !options.preferredStrategy ||\n !this.validateUploadStrategy(options.preferredStrategy)\n ) {\n if (\n this.capabilities.supportsParallelUploads &&\n options.fileSize > (options.minChunkSizeForParallel ?? 10 * 1024 * 1024)\n ) {\n strategy = \"parallel\";\n reasoning.push(\n `Selected parallel upload for large file (${options.fileSize} bytes)`,\n );\n } else {\n strategy = \"single\";\n reasoning.push(\n this.capabilities.supportsParallelUploads\n ? `Selected single upload for small file (${options.fileSize} bytes)`\n : \"Selected single upload (parallel not supported by data store)\",\n );\n }\n }\n\n // Validate and adjust chunk size based on data store constraints\n if (\n this.capabilities.minChunkSize &&\n chunkSize < this.capabilities.minChunkSize\n ) {\n warnings.push(\n `Chunk size ${chunkSize} below minimum ${this.capabilities.minChunkSize}, adjusting`,\n );\n chunkSize = this.capabilities.minChunkSize;\n }\n\n if (\n this.capabilities.maxChunkSize &&\n chunkSize > this.capabilities.maxChunkSize\n ) {\n warnings.push(\n `Chunk size ${chunkSize} above maximum ${this.capabilities.maxChunkSize}, adjusting`,\n );\n chunkSize = this.capabilities.maxChunkSize;\n }\n\n // Validate parallel upload settings\n if (strategy === \"parallel\") {\n if (\n this.capabilities.maxConcurrentUploads &&\n parallelUploads > this.capabilities.maxConcurrentUploads\n ) {\n warnings.push(\n `Parallel uploads ${parallelUploads} exceeds maximum ${this.capabilities.maxConcurrentUploads}, adjusting`,\n );\n parallelUploads = this.capabilities.maxConcurrentUploads;\n }\n\n // Check if file would exceed max parts limit\n if (this.capabilities.maxParts) {\n const estimatedParts = Math.ceil(options.fileSize / chunkSize);\n if (estimatedParts > this.capabilities.maxParts) {\n const minChunkForParts = Math.ceil(\n options.fileSize / this.capabilities.maxParts,\n );\n warnings.push(\n `Estimated parts ${estimatedParts} exceeds maximum ${this.capabilities.maxParts}, increasing chunk size`,\n );\n chunkSize = Math.max(chunkSize, minChunkForParts);\n }\n }\n }\n\n // Final validation - ensure strategy is still valid after adjustments\n if (!this.validateUploadStrategy(strategy)) {\n warnings.push(\n `Final strategy validation failed, falling back to single upload`,\n );\n strategy = \"single\";\n parallelUploads = 1;\n }\n\n // Add capability information to reasoning\n reasoning.push(\n `Data store capabilities: parallel=${this.capabilities.supportsParallelUploads}, concatenation=${this.capabilities.supportsConcatenation}, resumable=${this.capabilities.supportsResumableUploads}`,\n );\n\n return {\n strategy,\n chunkSize,\n parallelUploads: strategy === \"parallel\" ? parallelUploads : 1,\n reasoning,\n warnings,\n };\n }\n\n getDataStoreCapabilities(): DataStoreCapabilities {\n return this.capabilities;\n }\n\n validateConfiguration(options: UploadStrategyOptions): {\n valid: boolean;\n errors: string[];\n } {\n const errors: string[] = [];\n\n if (\n options.preferredStrategy &&\n !this.validateUploadStrategy(options.preferredStrategy)\n ) {\n errors.push(\n `Preferred strategy '${options.preferredStrategy}' not supported by data store`,\n );\n }\n\n if (options.preferredChunkSize) {\n if (\n this.capabilities.minChunkSize &&\n options.preferredChunkSize < this.capabilities.minChunkSize\n ) {\n errors.push(\n `Chunk size ${options.preferredChunkSize} below data store minimum ${this.capabilities.minChunkSize}`,\n );\n }\n if (\n this.capabilities.maxChunkSize &&\n options.preferredChunkSize > this.capabilities.maxChunkSize\n ) {\n errors.push(\n `Chunk size ${options.preferredChunkSize} above data store maximum ${this.capabilities.maxChunkSize}`,\n );\n }\n }\n\n if (\n options.parallelUploads &&\n this.capabilities.maxConcurrentUploads &&\n options.parallelUploads > this.capabilities.maxConcurrentUploads\n ) {\n errors.push(\n `Parallel uploads ${options.parallelUploads} exceeds data store maximum ${this.capabilities.maxConcurrentUploads}`,\n );\n }\n\n return {\n valid: errors.length === 0,\n errors,\n };\n }\n}\n"],"mappings":"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"}
@@ -0,0 +1,22 @@
1
+ const e=require(`./chunk-CUT6urMc.cjs`);let t=require(`effect`);t=e.__toESM(t);const n={MISSING_OFFSET:{status:403,body:`Upload-Offset header required
2
+ `},ABORTED:{status:400,body:`Request aborted due to lock acquired`},INVALID_TERMINATION:{status:400,body:`Cannot terminate an already completed upload`},ERR_LOCK_TIMEOUT:{status:500,body:`failed to acquire lock before timeout`},INVALID_CONTENT_TYPE:{status:403,body:`Content-Type header required
3
+ `},DATASTORE_NOT_FOUND:{status:500,body:`The datastore was not found
4
+ `},UPLOAD_ID_NOT_FOUND:{status:500,body:`The upload id was not found
5
+ `},FILE_NOT_FOUND:{status:404,body:`The file for this url was not found
6
+ `},FLOW_STRUCTURE_ERROR:{status:500,body:`The flow structure is invalid
7
+ `},FLOW_CYCLE_ERROR:{status:500,body:`The flow contains a cycle
8
+ `},FLOW_NODE_NOT_FOUND:{status:500,body:`The flow node was not found
9
+ `},FLOW_NODE_ERROR:{status:500,body:`The flow node failed
10
+ `},FLOW_JOB_NOT_FOUND:{status:404,body:`The flow job was not found
11
+ `},FLOW_JOB_ERROR:{status:500,body:`The flow job failed
12
+ `},FLOW_INPUT_VALIDATION_ERROR:{status:500,body:`The flow input validation failed
13
+ `},FLOW_OUTPUT_VALIDATION_ERROR:{status:500,body:`The flow output validation failed
14
+ `},INVALID_OFFSET:{status:409,body:`Upload-Offset conflict
15
+ `},FILE_NO_LONGER_EXISTS:{status:410,body:`The file for this url no longer exists
16
+ `},ERR_SIZE_EXCEEDED:{status:413,body:`upload's size exceeded
17
+ `},ERR_MAX_SIZE_EXCEEDED:{status:413,body:`Maximum size exceeded
18
+ `},INVALID_LENGTH:{status:400,body:`Upload-Length or Upload-Defer-Length header required
19
+ `},INVALID_METADATA:{status:400,body:`Upload-Metadata is invalid. It MUST consist of one or more comma-separated key-value pairs. The key and value MUST be separated by a space. The key MUST NOT contain spaces and commas and MUST NOT be empty. The key SHOULD be ASCII encoded and the value MUST be Base64 encoded. All keys MUST be unique`},VALIDATION_ERROR:{status:400,body:`Validation failed
20
+ `},UNKNOWN_ERROR:{status:500,body:`Something went wrong with that request
21
+ `},FILE_WRITE_ERROR:{status:500,body:`Something went wrong receiving the file
22
+ `}};var r=class e extends t.Data.TaggedError(`UploadistaError`){code;status;status_code;body;details;constructor({code:e,status:t,body:n,cause:r,details:i}){super(),this.name=`UploadistaError`,this.code=e,this.status=t,this.status_code=t,this.body=n,this.details=i,r&&(this.cause=r)}static fromCode(t,r){let i=n[t];return new e({code:t,status:r?.status??i.status,body:r?.body??i.body,details:r?.details,cause:r?.cause})}toEffect(){return t.Effect.fail(this)}};function i(e){return e instanceof r}function a(e,t){return r.fromCode(e,t).toEffect()}Object.defineProperty(exports,`ERROR_CATALOG`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`UploadistaError`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`httpFailureEffect`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`isUploadistaError`,{enumerable:!0,get:function(){return i}});
@@ -0,0 +1,23 @@
1
+ import{Data as e,Effect as t}from"effect";const n={MISSING_OFFSET:{status:403,body:`Upload-Offset header required
2
+ `},ABORTED:{status:400,body:`Request aborted due to lock acquired`},INVALID_TERMINATION:{status:400,body:`Cannot terminate an already completed upload`},ERR_LOCK_TIMEOUT:{status:500,body:`failed to acquire lock before timeout`},INVALID_CONTENT_TYPE:{status:403,body:`Content-Type header required
3
+ `},DATASTORE_NOT_FOUND:{status:500,body:`The datastore was not found
4
+ `},UPLOAD_ID_NOT_FOUND:{status:500,body:`The upload id was not found
5
+ `},FILE_NOT_FOUND:{status:404,body:`The file for this url was not found
6
+ `},FLOW_STRUCTURE_ERROR:{status:500,body:`The flow structure is invalid
7
+ `},FLOW_CYCLE_ERROR:{status:500,body:`The flow contains a cycle
8
+ `},FLOW_NODE_NOT_FOUND:{status:500,body:`The flow node was not found
9
+ `},FLOW_NODE_ERROR:{status:500,body:`The flow node failed
10
+ `},FLOW_JOB_NOT_FOUND:{status:404,body:`The flow job was not found
11
+ `},FLOW_JOB_ERROR:{status:500,body:`The flow job failed
12
+ `},FLOW_INPUT_VALIDATION_ERROR:{status:500,body:`The flow input validation failed
13
+ `},FLOW_OUTPUT_VALIDATION_ERROR:{status:500,body:`The flow output validation failed
14
+ `},INVALID_OFFSET:{status:409,body:`Upload-Offset conflict
15
+ `},FILE_NO_LONGER_EXISTS:{status:410,body:`The file for this url no longer exists
16
+ `},ERR_SIZE_EXCEEDED:{status:413,body:`upload's size exceeded
17
+ `},ERR_MAX_SIZE_EXCEEDED:{status:413,body:`Maximum size exceeded
18
+ `},INVALID_LENGTH:{status:400,body:`Upload-Length or Upload-Defer-Length header required
19
+ `},INVALID_METADATA:{status:400,body:`Upload-Metadata is invalid. It MUST consist of one or more comma-separated key-value pairs. The key and value MUST be separated by a space. The key MUST NOT contain spaces and commas and MUST NOT be empty. The key SHOULD be ASCII encoded and the value MUST be Base64 encoded. All keys MUST be unique`},VALIDATION_ERROR:{status:400,body:`Validation failed
20
+ `},UNKNOWN_ERROR:{status:500,body:`Something went wrong with that request
21
+ `},FILE_WRITE_ERROR:{status:500,body:`Something went wrong receiving the file
22
+ `}};var r=class r extends e.TaggedError(`UploadistaError`){code;status;status_code;body;details;constructor({code:e,status:t,body:n,cause:r,details:i}){super(),this.name=`UploadistaError`,this.code=e,this.status=t,this.status_code=t,this.body=n,this.details=i,r&&(this.cause=r)}static fromCode(e,t){let i=n[e];return new r({code:e,status:t?.status??i.status,body:t?.body??i.body,details:t?.details,cause:t?.cause})}toEffect(){return t.fail(this)}};function i(e){return e instanceof r}function a(e,t){return r.fromCode(e,t).toEffect()}export{n as ERROR_CATALOG,r as UploadistaError,a as httpFailureEffect,i as isUploadistaError};
23
+ //# sourceMappingURL=uploadista-error-BVsVxqvz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadista-error-BVsVxqvz.js","names":["ERROR_CATALOG: Readonly<\n Record<UploadistaErrorCode, { status: number; body: string }>\n>"],"sources":["../src/errors/uploadista-error.ts"],"sourcesContent":["import { Data, Effect } from \"effect\";\n\nexport type UploadistaErrorCode =\n | \"MISSING_OFFSET\"\n | \"ABORTED\"\n | \"INVALID_TERMINATION\"\n | \"ERR_LOCK_TIMEOUT\"\n | \"INVALID_CONTENT_TYPE\"\n | \"FLOW_STRUCTURE_ERROR\"\n | \"FLOW_CYCLE_ERROR\"\n | \"FLOW_NODE_NOT_FOUND\"\n | \"FLOW_NODE_ERROR\"\n | \"FLOW_JOB_NOT_FOUND\"\n | \"FLOW_JOB_ERROR\"\n | \"DATASTORE_NOT_FOUND\"\n | \"FILE_NOT_FOUND\"\n | \"INVALID_OFFSET\"\n | \"FILE_NO_LONGER_EXISTS\"\n | \"ERR_SIZE_EXCEEDED\"\n | \"ERR_MAX_SIZE_EXCEEDED\"\n | \"INVALID_LENGTH\"\n | \"INVALID_METADATA\"\n | \"VALIDATION_ERROR\"\n | \"UNKNOWN_ERROR\"\n | \"FILE_WRITE_ERROR\"\n | \"UPLOAD_ID_NOT_FOUND\"\n | \"FLOW_OUTPUT_VALIDATION_ERROR\"\n | \"FLOW_INPUT_VALIDATION_ERROR\";\n// | \"UNSUPPORTED_CONCATENATION_EXTENSION\"\n// | \"UNSUPPORTED_CREATION_DEFER_LENGTH_EXTENSION\"\n// | \"UNSUPPORTED_EXPIRATION_EXTENSION\";\n\nexport const ERROR_CATALOG: Readonly<\n Record<UploadistaErrorCode, { status: number; body: string }>\n> = {\n MISSING_OFFSET: { status: 403, body: \"Upload-Offset header required\\n\" },\n ABORTED: { status: 400, body: \"Request aborted due to lock acquired\" },\n INVALID_TERMINATION: {\n status: 400,\n body: \"Cannot terminate an already completed upload\",\n },\n ERR_LOCK_TIMEOUT: {\n status: 500,\n body: \"failed to acquire lock before timeout\",\n },\n INVALID_CONTENT_TYPE: {\n status: 403,\n body: \"Content-Type header required\\n\",\n },\n DATASTORE_NOT_FOUND: {\n status: 500,\n body: \"The datastore was not found\\n\",\n },\n UPLOAD_ID_NOT_FOUND: {\n status: 500,\n body: \"The upload id was not found\\n\",\n },\n FILE_NOT_FOUND: {\n status: 404,\n body: \"The file for this url was not found\\n\",\n },\n FLOW_STRUCTURE_ERROR: {\n status: 500,\n body: \"The flow structure is invalid\\n\",\n },\n FLOW_CYCLE_ERROR: {\n status: 500,\n body: \"The flow contains a cycle\\n\",\n },\n FLOW_NODE_NOT_FOUND: {\n status: 500,\n body: \"The flow node was not found\\n\",\n },\n FLOW_NODE_ERROR: {\n status: 500,\n body: \"The flow node failed\\n\",\n },\n FLOW_JOB_NOT_FOUND: {\n status: 404,\n body: \"The flow job was not found\\n\",\n },\n FLOW_JOB_ERROR: {\n status: 500,\n body: \"The flow job failed\\n\",\n },\n FLOW_INPUT_VALIDATION_ERROR: {\n status: 500,\n body: \"The flow input validation failed\\n\",\n },\n FLOW_OUTPUT_VALIDATION_ERROR: {\n status: 500,\n body: \"The flow output validation failed\\n\",\n },\n INVALID_OFFSET: { status: 409, body: \"Upload-Offset conflict\\n\" },\n FILE_NO_LONGER_EXISTS: {\n status: 410,\n body: \"The file for this url no longer exists\\n\",\n },\n ERR_SIZE_EXCEEDED: { status: 413, body: \"upload's size exceeded\\n\" },\n ERR_MAX_SIZE_EXCEEDED: { status: 413, body: \"Maximum size exceeded\\n\" },\n INVALID_LENGTH: {\n status: 400,\n body: \"Upload-Length or Upload-Defer-Length header required\\n\",\n },\n INVALID_METADATA: {\n status: 400,\n body: \"Upload-Metadata is invalid. It MUST consist of one or more comma-separated key-value pairs. The key and value MUST be separated by a space. The key MUST NOT contain spaces and commas and MUST NOT be empty. The key SHOULD be ASCII encoded and the value MUST be Base64 encoded. All keys MUST be unique\",\n },\n VALIDATION_ERROR: {\n status: 400,\n body: \"Validation failed\\n\",\n },\n UNKNOWN_ERROR: {\n status: 500,\n body: \"Something went wrong with that request\\n\",\n },\n FILE_WRITE_ERROR: {\n status: 500,\n body: \"Something went wrong receiving the file\\n\",\n },\n // UNSUPPORTED_CONCATENATION_EXTENSION: {\n // status: 501,\n // body: \"Concatenation extension is not (yet) supported. Disable parallel uploads in the tus client.\\n\",\n // },\n // UNSUPPORTED_CREATION_DEFER_LENGTH_EXTENSION: {\n // status: 501,\n // body: \"creation-defer-length extension is not (yet) supported.\\n\",\n // },\n // UNSUPPORTED_EXPIRATION_EXTENSION: {\n // status: 501,\n // body: \"expiration extension is not (yet) supported.\\n\",\n // },\n} as const;\n\nexport class UploadistaError extends Data.TaggedError(\"UploadistaError\") {\n readonly code: string;\n readonly status: number;\n // Keep legacy property names for backward compatibility\n readonly status_code: number;\n readonly body: string;\n readonly details?: unknown;\n\n constructor({\n code,\n status,\n body,\n cause,\n details,\n }: {\n code: UploadistaErrorCode | string;\n status: number;\n body: string;\n cause?: unknown;\n details?: unknown;\n }) {\n super();\n this.name = \"UploadistaError\";\n this.code = code;\n this.status = status;\n this.status_code = status; // legacy alias\n this.body = body;\n this.details = details;\n if (cause) (this as unknown as { cause?: unknown }).cause = cause;\n }\n\n static fromCode(\n code: UploadistaErrorCode,\n overrides?: Partial<Pick<UploadistaError, \"status\" | \"body\">> & {\n details?: unknown;\n cause?: unknown;\n },\n ): UploadistaError {\n const base = ERROR_CATALOG[code];\n return new UploadistaError({\n code,\n status: overrides?.status ?? base.status,\n body: overrides?.body ?? base.body,\n details: overrides?.details,\n cause: overrides?.cause,\n });\n }\n\n /**\n * Convert this error to an Effect that fails\n */\n toEffect<T = never>(): Effect.Effect<T, UploadistaError> {\n return Effect.fail(this);\n }\n}\n\nexport function isUploadistaError(error: unknown): error is UploadistaError {\n return error instanceof UploadistaError;\n}\n\n/**\n * Create an Effect that fails with an UploadistaError\n */\nexport function httpFailureEffect(\n code: UploadistaErrorCode,\n overrides?: Partial<Pick<UploadistaError, \"status\" | \"body\">> & {\n details?: unknown;\n cause?: unknown;\n },\n): Effect.Effect<never, UploadistaError> {\n return UploadistaError.fromCode(code, overrides).toEffect();\n}\n"],"mappings":"0CAgCA,MAAaA,EAET,CACF,eAAgB,CAAE,OAAQ,IAAK,KAAM;EAAmC,CACxE,QAAS,CAAE,OAAQ,IAAK,KAAM,uCAAwC,CACtE,oBAAqB,CACnB,OAAQ,IACR,KAAM,+CACP,CACD,iBAAkB,CAChB,OAAQ,IACR,KAAM,wCACP,CACD,qBAAsB,CACpB,OAAQ,IACR,KAAM;EACP,CACD,oBAAqB,CACnB,OAAQ,IACR,KAAM;EACP,CACD,oBAAqB,CACnB,OAAQ,IACR,KAAM;EACP,CACD,eAAgB,CACd,OAAQ,IACR,KAAM;EACP,CACD,qBAAsB,CACpB,OAAQ,IACR,KAAM;EACP,CACD,iBAAkB,CAChB,OAAQ,IACR,KAAM;EACP,CACD,oBAAqB,CACnB,OAAQ,IACR,KAAM;EACP,CACD,gBAAiB,CACf,OAAQ,IACR,KAAM;EACP,CACD,mBAAoB,CAClB,OAAQ,IACR,KAAM;EACP,CACD,eAAgB,CACd,OAAQ,IACR,KAAM;EACP,CACD,4BAA6B,CAC3B,OAAQ,IACR,KAAM;EACP,CACD,6BAA8B,CAC5B,OAAQ,IACR,KAAM;EACP,CACD,eAAgB,CAAE,OAAQ,IAAK,KAAM;EAA4B,CACjE,sBAAuB,CACrB,OAAQ,IACR,KAAM;EACP,CACD,kBAAmB,CAAE,OAAQ,IAAK,KAAM;EAA4B,CACpE,sBAAuB,CAAE,OAAQ,IAAK,KAAM;EAA2B,CACvE,eAAgB,CACd,OAAQ,IACR,KAAM;EACP,CACD,iBAAkB,CAChB,OAAQ,IACR,KAAM,8SACP,CACD,iBAAkB,CAChB,OAAQ,IACR,KAAM;EACP,CACD,cAAe,CACb,OAAQ,IACR,KAAM;EACP,CACD,iBAAkB,CAChB,OAAQ,IACR,KAAM;EACP,CAaF,CAED,IAAa,EAAb,MAAa,UAAwB,EAAK,YAAY,kBAAkB,AAAC,CACvE,KACA,OAEA,YACA,KACA,QAEA,YAAY,CACV,OACA,SACA,OACA,QACA,WAOC,CACD,OAAO,CACP,KAAK,KAAO,kBACZ,KAAK,KAAO,EACZ,KAAK,OAAS,EACd,KAAK,YAAc,EACnB,KAAK,KAAO,EACZ,KAAK,QAAU,EACX,IAAQ,KAAwC,MAAQ,GAG9D,OAAO,SACL,EACA,EAIiB,CACjB,IAAM,EAAO,EAAc,GAC3B,OAAO,IAAI,EAAgB,CACzB,OACA,OAAQ,GAAW,QAAU,EAAK,OAClC,KAAM,GAAW,MAAQ,EAAK,KAC9B,QAAS,GAAW,QACpB,MAAO,GAAW,MACnB,CAAC,CAMJ,UAAyD,CACvD,OAAO,EAAO,KAAK,KAAK,GAI5B,SAAgB,EAAkB,EAA0C,CAC1E,OAAO,aAAiB,EAM1B,SAAgB,EACd,EACA,EAIuC,CACvC,OAAO,EAAgB,SAAS,EAAM,EAAU,CAAC,UAAU"}
@@ -0,0 +1,52 @@
1
+ import { Effect } from "effect";
2
+ import * as effect_Types0 from "effect/Types";
3
+ import * as effect_Cause0 from "effect/Cause";
4
+
5
+ //#region src/errors/uploadista-error.d.ts
6
+ type UploadistaErrorCode = "MISSING_OFFSET" | "ABORTED" | "INVALID_TERMINATION" | "ERR_LOCK_TIMEOUT" | "INVALID_CONTENT_TYPE" | "FLOW_STRUCTURE_ERROR" | "FLOW_CYCLE_ERROR" | "FLOW_NODE_NOT_FOUND" | "FLOW_NODE_ERROR" | "FLOW_JOB_NOT_FOUND" | "FLOW_JOB_ERROR" | "DATASTORE_NOT_FOUND" | "FILE_NOT_FOUND" | "INVALID_OFFSET" | "FILE_NO_LONGER_EXISTS" | "ERR_SIZE_EXCEEDED" | "ERR_MAX_SIZE_EXCEEDED" | "INVALID_LENGTH" | "INVALID_METADATA" | "VALIDATION_ERROR" | "UNKNOWN_ERROR" | "FILE_WRITE_ERROR" | "UPLOAD_ID_NOT_FOUND" | "FLOW_OUTPUT_VALIDATION_ERROR" | "FLOW_INPUT_VALIDATION_ERROR";
7
+ declare const ERROR_CATALOG: Readonly<Record<UploadistaErrorCode, {
8
+ status: number;
9
+ body: string;
10
+ }>>;
11
+ declare const UploadistaError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => effect_Cause0.YieldableError & {
12
+ readonly _tag: "UploadistaError";
13
+ } & Readonly<A>;
14
+ declare class UploadistaError extends UploadistaError_base {
15
+ readonly code: string;
16
+ readonly status: number;
17
+ readonly status_code: number;
18
+ readonly body: string;
19
+ readonly details?: unknown;
20
+ constructor({
21
+ code,
22
+ status,
23
+ body,
24
+ cause,
25
+ details
26
+ }: {
27
+ code: UploadistaErrorCode | string;
28
+ status: number;
29
+ body: string;
30
+ cause?: unknown;
31
+ details?: unknown;
32
+ });
33
+ static fromCode(code: UploadistaErrorCode, overrides?: Partial<Pick<UploadistaError, "status" | "body">> & {
34
+ details?: unknown;
35
+ cause?: unknown;
36
+ }): UploadistaError;
37
+ /**
38
+ * Convert this error to an Effect that fails
39
+ */
40
+ toEffect<T = never>(): Effect.Effect<T, UploadistaError>;
41
+ }
42
+ declare function isUploadistaError(error: unknown): error is UploadistaError;
43
+ /**
44
+ * Create an Effect that fails with an UploadistaError
45
+ */
46
+ declare function httpFailureEffect(code: UploadistaErrorCode, overrides?: Partial<Pick<UploadistaError, "status" | "body">> & {
47
+ details?: unknown;
48
+ cause?: unknown;
49
+ }): Effect.Effect<never, UploadistaError>;
50
+ //#endregion
51
+ export { ERROR_CATALOG, UploadistaError, UploadistaErrorCode, httpFailureEffect, isUploadistaError };
52
+ //# sourceMappingURL=uploadista-error-CwxYs4EB.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadista-error-CwxYs4EB.d.ts","names":[],"sources":["../src/errors/uploadista-error.ts"],"sourcesContent":[],"mappings":";;;;;KAEY,mBAAA;cA8BC,eAAe,SAC1B,OAAO;;;AA/BT,CAAA,CAAA,CAAA;AA8BA,cAoGW,oBAAD,EAAA,IAAA,CAAA,gBAAA,CAAA,MAAA,EAAA,GAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,IAAA,sBAAA,EAAA,EAAA,CAAA,CAAA,CAAA,SAAA,IAAA,GAAA,IAAA,GAAA,iBAAA,OAAA,KAAA,SAAA,MAAA,GAAA,KAAA,IAAA,IAAA,EAAA,CAAA,EAAA,EAAA,kCAAA;EAAA,SAAA,IAAA,EAAA,iBAAA;YAnGD,EAAA,CAAA;AAAP,cAqGW,eAAA,SAAwB,oBAAA,CArGnC;WAD0B,IAAA,EAAA,MAAA;EAAQ,SAAA,MAAA,EAAA,MAAA;EAoGzB,SAAA,WAAA,EAAA,MAAA;;;;;;;;;;UAiBD;;;;;;wBAiBA,iCACM,QAAQ,KAAK;;;MAIxB;EArCQ;;;UAUT,CAAA,IAAA,KAAA,CAAA,CAAA,CAAA,EAyCqB,MAAA,CAAO,MAzC5B,CAyCmC,CAzCnC,EAyCsC,eAzCtC,CAAA;;AAEA,iBA4CY,iBAAA,CA5CZ,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IA4CwD,eA5CxD;;;;AAqByB,iBA8Bb,iBAAA,CA9Ba,IAAA,EA+BrB,mBA/BqB,EAAA,UAAA,EAgCf,OAhCe,CAgCP,IAhCO,CAgCF,eAhCE,EAAA,QAAA,GAAA,MAAA,CAAA,CAAA,GAAA;SAAL,CAAA,EAAA,OAAA;OAAR,CAAA,EAAA,OAAA;IAoCb,MAAA,CAAO,MAhCL,CAAA,KAAA,EAgCmB,eAhCnB,CAAA"}
@@ -0,0 +1,52 @@
1
+ import * as effect_Types0 from "effect/Types";
2
+ import * as effect_Cause0 from "effect/Cause";
3
+ import { Effect } from "effect";
4
+
5
+ //#region src/errors/uploadista-error.d.ts
6
+ type UploadistaErrorCode = "MISSING_OFFSET" | "ABORTED" | "INVALID_TERMINATION" | "ERR_LOCK_TIMEOUT" | "INVALID_CONTENT_TYPE" | "FLOW_STRUCTURE_ERROR" | "FLOW_CYCLE_ERROR" | "FLOW_NODE_NOT_FOUND" | "FLOW_NODE_ERROR" | "FLOW_JOB_NOT_FOUND" | "FLOW_JOB_ERROR" | "DATASTORE_NOT_FOUND" | "FILE_NOT_FOUND" | "INVALID_OFFSET" | "FILE_NO_LONGER_EXISTS" | "ERR_SIZE_EXCEEDED" | "ERR_MAX_SIZE_EXCEEDED" | "INVALID_LENGTH" | "INVALID_METADATA" | "VALIDATION_ERROR" | "UNKNOWN_ERROR" | "FILE_WRITE_ERROR" | "UPLOAD_ID_NOT_FOUND" | "FLOW_OUTPUT_VALIDATION_ERROR" | "FLOW_INPUT_VALIDATION_ERROR";
7
+ declare const ERROR_CATALOG: Readonly<Record<UploadistaErrorCode, {
8
+ status: number;
9
+ body: string;
10
+ }>>;
11
+ declare const UploadistaError_base: new <A extends Record<string, any> = {}>(args: effect_Types0.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => effect_Cause0.YieldableError & {
12
+ readonly _tag: "UploadistaError";
13
+ } & Readonly<A>;
14
+ declare class UploadistaError extends UploadistaError_base {
15
+ readonly code: string;
16
+ readonly status: number;
17
+ readonly status_code: number;
18
+ readonly body: string;
19
+ readonly details?: unknown;
20
+ constructor({
21
+ code,
22
+ status,
23
+ body,
24
+ cause,
25
+ details
26
+ }: {
27
+ code: UploadistaErrorCode | string;
28
+ status: number;
29
+ body: string;
30
+ cause?: unknown;
31
+ details?: unknown;
32
+ });
33
+ static fromCode(code: UploadistaErrorCode, overrides?: Partial<Pick<UploadistaError, "status" | "body">> & {
34
+ details?: unknown;
35
+ cause?: unknown;
36
+ }): UploadistaError;
37
+ /**
38
+ * Convert this error to an Effect that fails
39
+ */
40
+ toEffect<T = never>(): Effect.Effect<T, UploadistaError>;
41
+ }
42
+ declare function isUploadistaError(error: unknown): error is UploadistaError;
43
+ /**
44
+ * Create an Effect that fails with an UploadistaError
45
+ */
46
+ declare function httpFailureEffect(code: UploadistaErrorCode, overrides?: Partial<Pick<UploadistaError, "status" | "body">> & {
47
+ details?: unknown;
48
+ cause?: unknown;
49
+ }): Effect.Effect<never, UploadistaError>;
50
+ //#endregion
51
+ export { ERROR_CATALOG, UploadistaError, UploadistaErrorCode, httpFailureEffect, isUploadistaError };
52
+ //# sourceMappingURL=uploadista-error-kKlhLRhY.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadista-error-kKlhLRhY.d.cts","names":[],"sources":["../src/errors/uploadista-error.ts"],"sourcesContent":[],"mappings":";;;;;KAEY,mBAAA;cA8BC,eAAe,SAC1B,OAAO;;;AA/BT,CAAA,CAAA,CAAA;AA8BA,cAoGW,oBAAD,EAAA,IAAA,CAAA,gBAAA,CAAA,MAAA,EAAA,GAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,IAAA,sBAAA,EAAA,EAAA,CAAA,CAAA,CAAA,SAAA,IAAA,GAAA,IAAA,GAAA,iBAAA,OAAA,KAAA,SAAA,MAAA,GAAA,KAAA,IAAA,IAAA,EAAA,CAAA,EAAA,EAAA,kCAAA;EAAA,SAAA,IAAA,EAAA,iBAAA;YAnGD,EAAA,CAAA;AAAP,cAqGW,eAAA,SAAwB,oBAAA,CArGnC;WAD0B,IAAA,EAAA,MAAA;EAAQ,SAAA,MAAA,EAAA,MAAA;EAoGzB,SAAA,WAAA,EAAA,MAAA;;;;;;;;;;UAiBD;;;;;;wBAiBA,iCACM,QAAQ,KAAK;;;MAIxB;EArCQ;;;UAUT,CAAA,IAAA,KAAA,CAAA,CAAA,CAAA,EAyCqB,MAAA,CAAO,MAzC5B,CAyCmC,CAzCnC,EAyCsC,eAzCtC,CAAA;;AAEA,iBA4CY,iBAAA,CA5CZ,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IA4CwD,eA5CxD;;;;AAqByB,iBA8Bb,iBAAA,CA9Ba,IAAA,EA+BrB,mBA/BqB,EAAA,UAAA,EAgCf,OAhCe,CAgCP,IAhCO,CAgCF,eAhCE,EAAA,QAAA,GAAA,MAAA,CAAA,CAAA,GAAA;SAAL,CAAA,EAAA,OAAA;OAAR,CAAA,EAAA,OAAA;IAoCb,MAAA,CAAO,MAhCL,CAAA,KAAA,EAgCmB,eAhCnB,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { Effect } from "effect";
2
+ import { UploadistaError } from "../errors/uploadista-error";
3
+ /**
4
+ * Supported checksum algorithms
5
+ */
6
+ declare const SUPPORTED_ALGORITHMS: readonly ["sha256"];
7
+ export type ChecksumAlgorithm = (typeof SUPPORTED_ALGORITHMS)[number];
8
+ /**
9
+ * Check if a checksum algorithm is supported
10
+ */
11
+ export declare function isSupportedAlgorithm(algorithm: string): algorithm is ChecksumAlgorithm;
12
+ /**
13
+ * Compute checksum of file bytes using the Web Crypto API.
14
+ * This works across all modern platforms: browsers, Node.js 15+, Deno, Bun, and Cloudflare Workers.
15
+ *
16
+ * @param bytes - File content as Uint8Array
17
+ * @param algorithm - Hashing algorithm to use (currently only 'sha256' is supported)
18
+ * @returns Effect that resolves to hex-encoded checksum string
19
+ */
20
+ export declare function computeChecksum(bytes: Uint8Array, algorithm: string): Effect.Effect<string, UploadistaError>;
21
+ export {};
22
+ //# sourceMappingURL=checksum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checksum.d.ts","sourceRoot":"","sources":["../../src/utils/checksum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;GAEG;AACH,QAAA,MAAM,oBAAoB,qBAAsB,CAAC;AACjD,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,IAAI,iBAAiB,CAEtF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,MAAM,GAChB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAiCxC"}
@@ -0,0 +1,49 @@
1
+ import { Effect } from "effect";
2
+ import { UploadistaError } from "../errors/uploadista-error";
3
+ /**
4
+ * Supported checksum algorithms
5
+ */
6
+ const SUPPORTED_ALGORITHMS = ["sha256"];
7
+ /**
8
+ * Check if a checksum algorithm is supported
9
+ */
10
+ export function isSupportedAlgorithm(algorithm) {
11
+ return SUPPORTED_ALGORITHMS.includes(algorithm);
12
+ }
13
+ /**
14
+ * Compute checksum of file bytes using the Web Crypto API.
15
+ * This works across all modern platforms: browsers, Node.js 15+, Deno, Bun, and Cloudflare Workers.
16
+ *
17
+ * @param bytes - File content as Uint8Array
18
+ * @param algorithm - Hashing algorithm to use (currently only 'sha256' is supported)
19
+ * @returns Effect that resolves to hex-encoded checksum string
20
+ */
21
+ export function computeChecksum(bytes, algorithm) {
22
+ return Effect.gen(function* () {
23
+ // Validate algorithm is supported
24
+ if (!isSupportedAlgorithm(algorithm)) {
25
+ return yield* UploadistaError.fromCode("UNSUPPORTED_CHECKSUM_ALGORITHM", {
26
+ body: `Checksum algorithm '${algorithm}' is not supported. Supported algorithms: ${SUPPORTED_ALGORITHMS.join(", ")}`,
27
+ details: { algorithm, supportedAlgorithms: SUPPORTED_ALGORITHMS },
28
+ }).toEffect();
29
+ }
30
+ // Map algorithm name to Web Crypto API algorithm name
31
+ const webCryptoAlgorithm = algorithm.toUpperCase().replace(/\d+/, "-$&"); // "sha256" -> "SHA-256"
32
+ // Compute hash using Web Crypto API (available in browsers, Node.js 15+, Deno, Bun, Cloudflare Workers)
33
+ // Pass Uint8Array directly - it's a valid BufferSource
34
+ const hashBuffer = yield* Effect.tryPromise({
35
+ try: () => crypto.subtle.digest(webCryptoAlgorithm, bytes),
36
+ catch: (error) => UploadistaError.fromCode("UNKNOWN_ERROR", {
37
+ body: `Failed to compute checksum: ${error instanceof Error ? error.message : "Unknown error"}`,
38
+ cause: error,
39
+ details: { algorithm },
40
+ }),
41
+ });
42
+ // Convert ArrayBuffer to hex string
43
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
44
+ const hashHex = hashArray
45
+ .map((byte) => byte.toString(16).padStart(2, "0"))
46
+ .join("");
47
+ return hashHex;
48
+ });
49
+ }
@@ -0,0 +1 @@
1
+ const e=require(`../debounce-LZK7yS7Z.cjs`);exports.debounce=e.debounce;
@@ -0,0 +1,38 @@
1
+ //#region src/utils/debounce.d.ts
2
+ type DebounceOptions = {
3
+ leading?: boolean;
4
+ trailing?: boolean;
5
+ };
6
+ /**
7
+ * Returns `fn` wrapped by a function that delays invoking `fn` for `delay`
8
+ * milliseconds since the last call. Set `options.leading` to invoke `fn` on
9
+ * the leading edge of the delay, and/or set `options.trailing` to invoke `fn`
10
+ * on the trailing edge of the delay (true by default).
11
+ *
12
+ * Example for `debounce(fn, 30, {leading: true, trailing: true})`,
13
+ * where `fn` is called twice, with the second call made 20 ms after the first:
14
+ *
15
+ * Time: 0 20 50 (ms)
16
+ * Timeline: |----------------------------------------------------------------|
17
+ * ^ ^ ^
18
+ * | | |
19
+ * | First call. | Second call 20ms after the | End of delay.
20
+ * | (instant leading | first. | (trailing edge
21
+ * | edge call) | | call)
22
+ * |-----------------------------|
23
+ * | 30 ms delay for debounce. |
24
+ *
25
+ *
26
+ * Note that if both `options.leading` and `options.trailing` are true, `fn`
27
+ * will only be invoked on the trailing edge if the debounced function is called
28
+ * more than once during the delay.
29
+ *
30
+ * @param fn - Function to debounce.
31
+ * @param delay - Milliseconds to delay calling `fn` since the last call.
32
+ * @param debounceOptions - See `DebounceOptions` and `defaultDebounceOptions`.
33
+ * @returns A debounced `fn`.
34
+ */
35
+ declare function debounce<T, A extends unknown[]>(fn: (this: T, ...args: A) => void, delay: number, debounceOptions?: DebounceOptions): (this: T, ...args: A) => void;
36
+ //#endregion
37
+ export { debounce };
38
+ //# sourceMappingURL=debounce.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.d.cts","names":[],"sources":["../../src/utils/debounce.ts"],"sourcesContent":[],"mappings":";KAAK,eAAA;EAAA,OAAA,CAAA,EAAA,OAAA;EA2CW,QAAA,CAAA,EAAQ,OAAA;CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAR,4CACH,YAAY,6CAEN,yBACT,YAAY"}
@@ -0,0 +1,36 @@
1
+ type DebounceOptions = {
2
+ leading?: boolean;
3
+ trailing?: boolean;
4
+ };
5
+ /**
6
+ * Returns `fn` wrapped by a function that delays invoking `fn` for `delay`
7
+ * milliseconds since the last call. Set `options.leading` to invoke `fn` on
8
+ * the leading edge of the delay, and/or set `options.trailing` to invoke `fn`
9
+ * on the trailing edge of the delay (true by default).
10
+ *
11
+ * Example for `debounce(fn, 30, {leading: true, trailing: true})`,
12
+ * where `fn` is called twice, with the second call made 20 ms after the first:
13
+ *
14
+ * Time: 0 20 50 (ms)
15
+ * Timeline: |----------------------------------------------------------------|
16
+ * ^ ^ ^
17
+ * | | |
18
+ * | First call. | Second call 20ms after the | End of delay.
19
+ * | (instant leading | first. | (trailing edge
20
+ * | edge call) | | call)
21
+ * |-----------------------------|
22
+ * | 30 ms delay for debounce. |
23
+ *
24
+ *
25
+ * Note that if both `options.leading` and `options.trailing` are true, `fn`
26
+ * will only be invoked on the trailing edge if the debounced function is called
27
+ * more than once during the delay.
28
+ *
29
+ * @param fn - Function to debounce.
30
+ * @param delay - Milliseconds to delay calling `fn` since the last call.
31
+ * @param debounceOptions - See `DebounceOptions` and `defaultDebounceOptions`.
32
+ * @returns A debounced `fn`.
33
+ */
34
+ export declare function debounce<T, A extends unknown[]>(fn: (this: T, ...args: A) => void, delay: number, debounceOptions?: DebounceOptions): (this: T, ...args: A) => void;
35
+ export {};
36
+ //# sourceMappingURL=debounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/utils/debounce.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IAErB,OAAO,CAAC,EAAE,OAAO,CAAC;IAIlB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAOF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAC7C,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,EACjC,KAAK,EAAE,MAAM,EACb,eAAe,GAAE,eAAoB,GACpC,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,CAyC/B"}
@@ -0,0 +1,73 @@
1
+ const defaultDebounceOptions = {
2
+ leading: false,
3
+ trailing: true,
4
+ };
5
+ /**
6
+ * Returns `fn` wrapped by a function that delays invoking `fn` for `delay`
7
+ * milliseconds since the last call. Set `options.leading` to invoke `fn` on
8
+ * the leading edge of the delay, and/or set `options.trailing` to invoke `fn`
9
+ * on the trailing edge of the delay (true by default).
10
+ *
11
+ * Example for `debounce(fn, 30, {leading: true, trailing: true})`,
12
+ * where `fn` is called twice, with the second call made 20 ms after the first:
13
+ *
14
+ * Time: 0 20 50 (ms)
15
+ * Timeline: |----------------------------------------------------------------|
16
+ * ^ ^ ^
17
+ * | | |
18
+ * | First call. | Second call 20ms after the | End of delay.
19
+ * | (instant leading | first. | (trailing edge
20
+ * | edge call) | | call)
21
+ * |-----------------------------|
22
+ * | 30 ms delay for debounce. |
23
+ *
24
+ *
25
+ * Note that if both `options.leading` and `options.trailing` are true, `fn`
26
+ * will only be invoked on the trailing edge if the debounced function is called
27
+ * more than once during the delay.
28
+ *
29
+ * @param fn - Function to debounce.
30
+ * @param delay - Milliseconds to delay calling `fn` since the last call.
31
+ * @param debounceOptions - See `DebounceOptions` and `defaultDebounceOptions`.
32
+ * @returns A debounced `fn`.
33
+ */
34
+ export function debounce(fn, delay, debounceOptions = {}) {
35
+ const options = { ...defaultDebounceOptions, ...debounceOptions };
36
+ let timer;
37
+ return function (...args) {
38
+ if (options.leading && !timer) {
39
+ // Leading edge.
40
+ // Call fn on the leading edge, when debouncing hasn't started yet.
41
+ console.log("leading");
42
+ fn.apply(this, args);
43
+ // Debounce the next call.
44
+ timer = setTimeout(() => {
45
+ timer = undefined;
46
+ }, delay);
47
+ }
48
+ else {
49
+ // Trailing edge.
50
+ // Postpone calling fn until the delay has elapsed since the last call.
51
+ // Each call clears any previously delayed call and resets the delay, so
52
+ // the postponed call will always be the last one.
53
+ clearTimeout(timer);
54
+ timer = setTimeout(() => {
55
+ if (options.trailing) {
56
+ // Call fn on the trailing edge.
57
+ fn.apply(this, args);
58
+ if (options.leading) {
59
+ // Debounce next leading call since a trailing call was just made.
60
+ setTimeout(() => {
61
+ timer = undefined;
62
+ }, delay);
63
+ }
64
+ }
65
+ else {
66
+ // No trailing call. Since the delay has elapsed since the last call,
67
+ // immediately reset the debouncing delay.
68
+ timer = undefined;
69
+ }
70
+ }, delay);
71
+ }
72
+ };
73
+ }
@@ -0,0 +1 @@
1
+ const e=require(`../generate-id-xHp_Z7Cl.cjs`);exports.GenerateId=e.GenerateId,exports.GenerateIdLive=e.GenerateIdLive,exports.GenerateIdRandom=e.GenerateIdRandom,exports.GenerateIdService=e.GenerateIdService,exports.GenerateIdTimestamp=e.GenerateIdTimestamp;
@@ -0,0 +1,2 @@
1
+ import { GenerateId, GenerateIdLive, GenerateIdRandom, GenerateIdService, GenerateIdShape, GenerateIdTimestamp } from "../generate-id-LjJRLD6N.cjs";
2
+ export { GenerateId, GenerateIdLive, GenerateIdRandom, GenerateIdService, GenerateIdShape, GenerateIdTimestamp };
@@ -0,0 +1,32 @@
1
+ import { Context, Effect, Layer } from "effect";
2
+ export type GenerateIdShape = {
3
+ generateId: () => Effect.Effect<string>;
4
+ };
5
+ declare const GenerateId_base: Context.TagClass<GenerateId, "UploadistaGenerateIdService", {
6
+ readonly generateId: () => Effect.Effect<string>;
7
+ }>;
8
+ export declare class GenerateId extends GenerateId_base {
9
+ }
10
+ /**
11
+ * Effect-based ID generation services
12
+ */
13
+ export declare const GenerateIdService: {
14
+ readonly generateId: () => Effect.Effect<string>;
15
+ };
16
+ /**
17
+ * Generates a random UUID using Effect
18
+ * @returns Effect that produces a random UUID string
19
+ */
20
+ export declare const GenerateIdRandom: {
21
+ readonly generateId: () => Effect.Effect<string>;
22
+ };
23
+ export declare const GenerateIdLive: Layer.Layer<GenerateId, never, never>;
24
+ /**
25
+ * Generates a timestamp-based ID using Effect
26
+ * @returns Effect that produces a timestamp-based ID
27
+ */
28
+ export declare const GenerateIdTimestamp: {
29
+ readonly generateId: () => Effect.Effect<string>;
30
+ };
31
+ export {};
32
+ //# sourceMappingURL=generate-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-id.d.ts","sourceRoot":"","sources":["../../src/utils/generate-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CACzC,CAAC;;yBAKuB,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;;AAFpD,qBAAa,UAAW,SAAQ,eAG7B;CAAG;AAEN;;GAEG;AACH,eAAO,MAAM,iBAAiB;yBANL,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;CAMD,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,gBAAgB;yBAZJ,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;CAclD,CAAC;AAEH,eAAO,MAAM,cAAc,uCAA8C,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,mBAAmB;yBAtBP,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;CAyBlD,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Context, Effect, Layer } from "effect";
2
+ // Declaring a tag for a service that generates random id
3
+ export class GenerateId extends Context.Tag("UploadistaGenerateIdService")() {
4
+ }
5
+ /**
6
+ * Effect-based ID generation services
7
+ */
8
+ export const GenerateIdService = GenerateId.Service;
9
+ /**
10
+ * Generates a random UUID using Effect
11
+ * @returns Effect that produces a random UUID string
12
+ */
13
+ export const GenerateIdRandom = GenerateId.of({
14
+ generateId: () => Effect.succeed(crypto.randomUUID()),
15
+ });
16
+ export const GenerateIdLive = Layer.succeed(GenerateId, GenerateIdRandom);
17
+ /**
18
+ * Generates a timestamp-based ID using Effect
19
+ * @returns Effect that produces a timestamp-based ID
20
+ */
21
+ export const GenerateIdTimestamp = GenerateId.of({
22
+ generateId: () => Effect.succeed(`${Date.now()}-${Math.random().toString(36).slice(2, 11)}`),
23
+ });
@@ -0,0 +1 @@
1
+ var e=class e{static hashStr(t,n=!1){return e.onePassHasher.start().appendStr(t).end(n)}static hashAsciiStr(t,n=!1){return e.onePassHasher.start().appendAsciiStr(t).end(n)}static stateIdentity=new Int32Array([1732584193,-271733879,-1732584194,271733878]);static buffer32Identity=new Int32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);static hexChars=`0123456789abcdef`;static hexOut=[];static onePassHasher=new e;static _hex(t){let n=e.hexChars,r=e.hexOut,i,a,o,s;for(s=0;s<4;s+=1)for(a=s*8,i=t[s]??0,o=0;o<8;o+=2)r[a+1+o]=n.charAt(i&15),i>>>=4,r[a+0+o]=n.charAt(i&15),i>>>=4;return r.join(``)}static _md5cycle(e,t){let n=e[0]??0,r=e[1]??0,i=e[2]??0,a=e[3]??0;n+=(r&i|~r&a)+(t[0]??0)-680876936|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+(t[1]??0)-389564586|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+(t[2]??0)+606105819|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+(t[3]??0)-1044525330|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+(t[4]??0)-176418897|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+(t[5]??0)+1200080426|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+(t[6]??0)-1473231341|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+(t[7]??0)-45705983|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+(t[8]??0)+1770035416|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+(t[9]??0)-1958414417|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+(t[10]??0)-42063|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+(t[11]??0)-1990404162|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+(t[12]??0)+1804603682|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+(t[13]??0)-40341101|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+(t[14]??0)-1502002290|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+(t[15]??0)+1236535329|0,r=(r<<22|r>>>10)+i|0,n+=(r&a|i&~a)+(t[1]??0)-165796510|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+(t[6]??0)-1069501632|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+(t[11]??0)+643717713|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+(t[0]??0)-373897302|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+(t[5]??0)-701558691|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+(t[10]??0)+38016083|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+(t[15]??0)-660478335|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+(t[4]??0)-405537848|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+(t[9]??0)+568446438|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+(t[14]??0)-1019803690|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+(t[3]??0)-187363961|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+(t[8]??0)+1163531501|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+(t[13]??0)-1444681467|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+(t[2]??0)-51403784|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+(t[7]??0)+1735328473|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+(t[12]??0)-1926607734|0,r=(r<<20|r>>>12)+i|0,n+=(r^i^a)+(t[5]??0)-378558|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+(t[8]??0)-2022574463|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+(t[11]??0)+1839030562|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+(t[14]??0)-35309556|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+(t[1]??0)-1530992060|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+(t[4]??0)+1272893353|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+(t[7]??0)-155497632|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+(t[10]??0)-1094730640|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+(t[13]??0)+681279174|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+(t[0]??0)-358537222|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+(t[3]??0)-722521979|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+(t[6]??0)+76029189|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+(t[9]??0)-640364487|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+(t[12]??0)-421815835|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+(t[15]??0)+530742520|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+(t[2]??0)-995338651|0,r=(r<<23|r>>>9)+i|0,n+=(i^(r|~a))+(t[0]??0)-198630844|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+(t[7]??0)+1126891415|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+(t[14]??0)-1416354905|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+(t[5]??0)-57434055|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+(t[12]??0)+1700485571|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+(t[3]??0)-1894986606|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+(t[10]??0)-1051523|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+(t[1]??0)-2054922799|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+(t[8]??0)+1873313359|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+(t[15]??0)-30611744|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+(t[6]??0)-1560198380|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+(t[13]??0)+1309151649|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+(t[4]??0)-145523070|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+(t[11]??0)-1120210379|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+(t[2]??0)+718787259|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+(t[9]??0)-343485551|0,r=(r<<21|r>>>11)+i|0,e[0]=n+(e[0]??0)|0,e[1]=r+(e[1]??0)|0,e[2]=i+(e[2]??0)|0,e[3]=a+(e[3]??0)|0}_dataLength=0;_bufferLength=0;_state=new Int32Array(4);_buffer=new ArrayBuffer(68);_buffer8;_buffer32;constructor(){this._buffer8=new Uint8Array(this._buffer,0,68),this._buffer32=new Uint32Array(this._buffer,0,17),this.start()}start(){return this._dataLength=0,this._bufferLength=0,this._state.set(e.stateIdentity),this}appendStr(t){let n=this._buffer8,r=this._buffer32,i=this._bufferLength,a,o;for(o=0;o<t.length;o+=1){if(a=t.charCodeAt(o),a<128)n[i++]=a;else if(a<2048)n[i++]=(a>>>6)+192,n[i++]=a&63|128;else if(a<55296||a>56319)n[i++]=(a>>>12)+224,n[i++]=a>>>6&63|128,n[i++]=a&63|128;else{if(a=(a-55296)*1024+(t.charCodeAt(++o)-56320)+65536,a>1114111)throw Error(`Unicode standard supports code points up to U+10FFFF`);n[i++]=(a>>>18)+240,n[i++]=a>>>12&63|128,n[i++]=a>>>6&63|128,n[i++]=a&63|128}i>=64&&(this._dataLength+=64,e._md5cycle(this._state,r),i-=64,r[0]=r[16]??0)}return this._bufferLength=i,this}appendAsciiStr(t){let n=this._buffer8,r=this._buffer32,i=this._bufferLength,a,o=0;for(;;){for(a=Math.min(t.length-o,64-i);a--;)n[i++]=t.charCodeAt(o++);if(i<64)break;this._dataLength+=64,e._md5cycle(this._state,r),i=0}return this._bufferLength=i,this}appendByteArray(t){let n=this._buffer8,r=this._buffer32,i=this._bufferLength,a,o=0;for(;;){for(a=Math.min(t.length-o,64-i);a--;)n[i++]=t[o++]??0;if(i<64)break;this._dataLength+=64,e._md5cycle(this._state,r),i=0}return this._bufferLength=i,this}getState(){let e=this._state;return{buffer:String.fromCharCode.apply(null,Array.from(this._buffer8)),buflen:this._bufferLength,length:this._dataLength,state:[e[0]??0,e[1]??0,e[2]??0,e[3]??0]}}setState(e){let t=e.buffer,n=e.state,r=this._state,i;for(this._dataLength=e.length,this._bufferLength=e.buflen,r[0]=n[0]??0,r[1]=n[1]??0,r[2]=n[2]??0,r[3]=n[3]??0,i=0;i<t.length;i+=1)this._buffer8[i]=t.charCodeAt(i)}end(t=!1){let n=this._bufferLength,r=this._buffer8,i=this._buffer32,a=(n>>2)+1;this._dataLength+=n;let o=this._dataLength*8;if(r[n]=128,r[n+1]=r[n+2]=r[n+3]=0,i.set(e.buffer32Identity.subarray(a),a),n>55&&(e._md5cycle(this._state,i),i.set(e.buffer32Identity)),o<=4294967295)i[14]=o;else{let e=o.toString(16).match(/(.*?)(.{0,8})$/);if(e===null)return;let t=Number.parseInt(e[2]??``,16),n=Number.parseInt(e[1]??``,16)||0;i[14]=t,i[15]=n}return e._md5cycle(this._state,i),t?this._state:e._hex(this._state)}};if(e.hashStr(`hello`)!==`5d41402abc4b2a76b9719d911017c592`)throw Error(`Md5 self test failed.`);exports.Md5=e;