@fragno-dev/upload 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (355) hide show
  1. package/LICENSE.md +16 -0
  2. package/README.md +43 -0
  3. package/bin/run.js +5 -0
  4. package/dist/browser/client/clients.js +49 -0
  5. package/dist/browser/client/clients.js.map +1 -0
  6. package/dist/browser/client/helpers.d.ts +51 -0
  7. package/dist/browser/client/helpers.d.ts.map +1 -0
  8. package/dist/browser/client/helpers.js +242 -0
  9. package/dist/browser/client/helpers.js.map +1 -0
  10. package/dist/browser/client/node_modules/.pnpm/@nanostores_query@0.3.4_nanostores@1.1.0/node_modules/@nanostores/query/dist/nanoquery.js +354 -0
  11. package/dist/browser/client/node_modules/.pnpm/@nanostores_query@0.3.4_nanostores@1.1.0/node_modules/@nanostores/query/dist/nanoquery.js.map +1 -0
  12. package/dist/browser/client/node_modules/.pnpm/@nanostores_solid@1.1.1_nanostores@1.1.0_solid-js@1.9.10/node_modules/@nanostores/solid/dist/index.js +14 -0
  13. package/dist/browser/client/node_modules/.pnpm/@nanostores_solid@1.1.1_nanostores@1.1.0_solid-js@1.9.10/node_modules/@nanostores/solid/dist/index.js.map +1 -0
  14. package/dist/browser/client/node_modules/.pnpm/nanoevents@9.1.0/node_modules/nanoevents/index.js +17 -0
  15. package/dist/browser/client/node_modules/.pnpm/nanoevents@9.1.0/node_modules/nanoevents/index.js.map +1 -0
  16. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/atom/index.js +62 -0
  17. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/atom/index.js.map +1 -0
  18. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/clean-stores/index.js +6 -0
  19. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/clean-stores/index.js.map +1 -0
  20. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/computed/index.js +50 -0
  21. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/computed/index.js.map +1 -0
  22. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/lifecycle/index.js +99 -0
  23. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/lifecycle/index.js.map +1 -0
  24. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/listen-keys/index.js +11 -0
  25. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/listen-keys/index.js.map +1 -0
  26. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/map/index.js +25 -0
  27. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/map/index.js.map +1 -0
  28. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/task/index.js +24 -0
  29. package/dist/browser/client/node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/task/index.js.map +1 -0
  30. package/dist/browser/client/packages/fragment-upload/src/definition.js +49 -0
  31. package/dist/browser/client/packages/fragment-upload/src/definition.js.map +1 -0
  32. package/dist/browser/client/packages/fragment-upload/src/keys.d.ts +7 -0
  33. package/dist/browser/client/packages/fragment-upload/src/keys.d.ts.map +1 -0
  34. package/dist/browser/client/packages/fragment-upload/src/keys.js +28 -0
  35. package/dist/browser/client/packages/fragment-upload/src/keys.js.map +1 -0
  36. package/dist/browser/client/packages/fragment-upload/src/routes/files.js +98 -0
  37. package/dist/browser/client/packages/fragment-upload/src/routes/files.js.map +1 -0
  38. package/dist/browser/client/packages/fragment-upload/src/routes/index.js +9 -0
  39. package/dist/browser/client/packages/fragment-upload/src/routes/index.js.map +1 -0
  40. package/dist/browser/client/packages/fragment-upload/src/routes/shared.js +41 -0
  41. package/dist/browser/client/packages/fragment-upload/src/routes/shared.js.map +1 -0
  42. package/dist/browser/client/packages/fragment-upload/src/routes/uploads.js +186 -0
  43. package/dist/browser/client/packages/fragment-upload/src/routes/uploads.js.map +1 -0
  44. package/dist/browser/client/packages/fragment-upload/src/schema.js +8 -0
  45. package/dist/browser/client/packages/fragment-upload/src/schema.js.map +1 -0
  46. package/dist/browser/client/packages/fragment-upload/src/storage/types.d.ts +9 -0
  47. package/dist/browser/client/packages/fragment-upload/src/storage/types.d.ts.map +1 -0
  48. package/dist/browser/client/packages/fragment-upload/src/types.d.ts +31 -0
  49. package/dist/browser/client/packages/fragment-upload/src/types.d.ts.map +1 -0
  50. package/dist/browser/client/packages/fragno/dist/api/error.js +48 -0
  51. package/dist/browser/client/packages/fragno/dist/api/error.js.map +1 -0
  52. package/dist/browser/client/packages/fragno/dist/api/internal/path.js +76 -0
  53. package/dist/browser/client/packages/fragno/dist/api/internal/path.js.map +1 -0
  54. package/dist/browser/client/packages/fragno/dist/api/internal/response-stream.js +81 -0
  55. package/dist/browser/client/packages/fragno/dist/api/internal/response-stream.js.map +1 -0
  56. package/dist/browser/client/packages/fragno/dist/api/internal/route.js +10 -0
  57. package/dist/browser/client/packages/fragno/dist/api/internal/route.js.map +1 -0
  58. package/dist/browser/client/packages/fragno/dist/api/request-input-context.js +185 -0
  59. package/dist/browser/client/packages/fragno/dist/api/request-input-context.js.map +1 -0
  60. package/dist/browser/client/packages/fragno/dist/api/request-output-context.js +119 -0
  61. package/dist/browser/client/packages/fragno/dist/api/request-output-context.js.map +1 -0
  62. package/dist/browser/client/packages/fragno/dist/api/route.js +17 -0
  63. package/dist/browser/client/packages/fragno/dist/api/route.js.map +1 -0
  64. package/dist/browser/client/packages/fragno/dist/client/client-error.js +92 -0
  65. package/dist/browser/client/packages/fragno/dist/client/client-error.js.map +1 -0
  66. package/dist/browser/client/packages/fragno/dist/client/client.js +495 -0
  67. package/dist/browser/client/packages/fragno/dist/client/client.js.map +1 -0
  68. package/dist/browser/client/packages/fragno/dist/client/client.svelte.js +120 -0
  69. package/dist/browser/client/packages/fragno/dist/client/client.svelte.js.map +1 -0
  70. package/dist/browser/client/packages/fragno/dist/client/internal/fetcher-merge.js +36 -0
  71. package/dist/browser/client/packages/fragno/dist/client/internal/fetcher-merge.js.map +1 -0
  72. package/dist/browser/client/packages/fragno/dist/client/internal/ndjson-streaming.js +139 -0
  73. package/dist/browser/client/packages/fragno/dist/client/internal/ndjson-streaming.js.map +1 -0
  74. package/dist/browser/client/packages/fragno/dist/client/react.js +70 -0
  75. package/dist/browser/client/packages/fragno/dist/client/react.js.map +1 -0
  76. package/dist/browser/client/packages/fragno/dist/client/solid.js +108 -0
  77. package/dist/browser/client/packages/fragno/dist/client/solid.js.map +1 -0
  78. package/dist/browser/client/packages/fragno/dist/client/vanilla.js +96 -0
  79. package/dist/browser/client/packages/fragno/dist/client/vanilla.js.map +1 -0
  80. package/dist/browser/client/packages/fragno/dist/client/vue.js +120 -0
  81. package/dist/browser/client/packages/fragno/dist/client/vue.js.map +1 -0
  82. package/dist/browser/client/packages/fragno/dist/util/async.js +40 -0
  83. package/dist/browser/client/packages/fragno/dist/util/async.js.map +1 -0
  84. package/dist/browser/client/packages/fragno/dist/util/content-type.js +49 -0
  85. package/dist/browser/client/packages/fragno/dist/util/content-type.js.map +1 -0
  86. package/dist/browser/client/packages/fragno/dist/util/nanostores.js +31 -0
  87. package/dist/browser/client/packages/fragno/dist/util/nanostores.js.map +1 -0
  88. package/dist/browser/client/packages/fragno/dist/util/ssr.js +18 -0
  89. package/dist/browser/client/packages/fragno/dist/util/ssr.js.map +1 -0
  90. package/dist/browser/client/react.d.ts +295 -0
  91. package/dist/browser/client/react.d.ts.map +1 -0
  92. package/dist/browser/client/react.js +11 -0
  93. package/dist/browser/client/react.js.map +1 -0
  94. package/dist/browser/client/solid.d.ts +303 -0
  95. package/dist/browser/client/solid.d.ts.map +1 -0
  96. package/dist/browser/client/solid.js +11 -0
  97. package/dist/browser/client/solid.js.map +1 -0
  98. package/dist/browser/client/svelte.d.ts +295 -0
  99. package/dist/browser/client/svelte.d.ts.map +1 -0
  100. package/dist/browser/client/svelte.js +11 -0
  101. package/dist/browser/client/svelte.js.map +1 -0
  102. package/dist/browser/client/vanilla.d.ts +296 -0
  103. package/dist/browser/client/vanilla.d.ts.map +1 -0
  104. package/dist/browser/client/vanilla.js +11 -0
  105. package/dist/browser/client/vanilla.js.map +1 -0
  106. package/dist/browser/client/vue.d.ts +295 -0
  107. package/dist/browser/client/vue.d.ts.map +1 -0
  108. package/dist/browser/client/vue.js +11 -0
  109. package/dist/browser/client/vue.js.map +1 -0
  110. package/dist/browser/index-BdjKPO4J.d.ts +177 -0
  111. package/dist/browser/index-BdjKPO4J.d.ts.map +1 -0
  112. package/dist/browser/index.js +3 -0
  113. package/dist/browser/src-vdNJUbjT.js +1982 -0
  114. package/dist/browser/src-vdNJUbjT.js.map +1 -0
  115. package/dist/cli/commands/files/delete.d.ts +40 -0
  116. package/dist/cli/commands/files/delete.d.ts.map +1 -0
  117. package/dist/cli/commands/files/delete.js +31 -0
  118. package/dist/cli/commands/files/delete.js.map +1 -0
  119. package/dist/cli/commands/files/download-url.d.ts +40 -0
  120. package/dist/cli/commands/files/download-url.d.ts.map +1 -0
  121. package/dist/cli/commands/files/download-url.js +31 -0
  122. package/dist/cli/commands/files/download-url.js.map +1 -0
  123. package/dist/cli/commands/files/download.d.ts +49 -0
  124. package/dist/cli/commands/files/download.d.ts.map +1 -0
  125. package/dist/cli/commands/files/download.js +65 -0
  126. package/dist/cli/commands/files/download.js.map +1 -0
  127. package/dist/cli/commands/files/get.d.ts +40 -0
  128. package/dist/cli/commands/files/get.d.ts.map +1 -0
  129. package/dist/cli/commands/files/get.js +31 -0
  130. package/dist/cli/commands/files/get.js.map +1 -0
  131. package/dist/cli/commands/files/list.d.ts +56 -0
  132. package/dist/cli/commands/files/list.d.ts.map +1 -0
  133. package/dist/cli/commands/files/list.js +53 -0
  134. package/dist/cli/commands/files/list.js.map +1 -0
  135. package/dist/cli/commands/files/update.d.ts +56 -0
  136. package/dist/cli/commands/files/update.d.ts.map +1 -0
  137. package/dist/cli/commands/files/update.js +53 -0
  138. package/dist/cli/commands/files/update.js.map +1 -0
  139. package/dist/cli/commands/files/upload.d.ts +73 -0
  140. package/dist/cli/commands/files/upload.d.ts.map +1 -0
  141. package/dist/cli/commands/files/upload.js +87 -0
  142. package/dist/cli/commands/files/upload.js.map +1 -0
  143. package/dist/cli/commands/uploads/abort.d.ts +37 -0
  144. package/dist/cli/commands/uploads/abort.d.ts.map +1 -0
  145. package/dist/cli/commands/uploads/abort.js +26 -0
  146. package/dist/cli/commands/uploads/abort.js.map +1 -0
  147. package/dist/cli/commands/uploads/complete.d.ts +41 -0
  148. package/dist/cli/commands/uploads/complete.d.ts.map +1 -0
  149. package/dist/cli/commands/uploads/complete.js +45 -0
  150. package/dist/cli/commands/uploads/complete.js.map +1 -0
  151. package/dist/cli/commands/uploads/content.d.ts +46 -0
  152. package/dist/cli/commands/uploads/content.d.ts.map +1 -0
  153. package/dist/cli/commands/uploads/content.js +43 -0
  154. package/dist/cli/commands/uploads/content.js.map +1 -0
  155. package/dist/cli/commands/uploads/create.d.ts +72 -0
  156. package/dist/cli/commands/uploads/create.d.ts.map +1 -0
  157. package/dist/cli/commands/uploads/create.js +84 -0
  158. package/dist/cli/commands/uploads/create.js.map +1 -0
  159. package/dist/cli/commands/uploads/get.d.ts +37 -0
  160. package/dist/cli/commands/uploads/get.d.ts.map +1 -0
  161. package/dist/cli/commands/uploads/get.js +26 -0
  162. package/dist/cli/commands/uploads/get.js.map +1 -0
  163. package/dist/cli/commands/uploads/parts-complete.d.ts +41 -0
  164. package/dist/cli/commands/uploads/parts-complete.d.ts.map +1 -0
  165. package/dist/cli/commands/uploads/parts-complete.js +44 -0
  166. package/dist/cli/commands/uploads/parts-complete.js.map +1 -0
  167. package/dist/cli/commands/uploads/parts-list.d.ts +37 -0
  168. package/dist/cli/commands/uploads/parts-list.d.ts.map +1 -0
  169. package/dist/cli/commands/uploads/parts-list.js +26 -0
  170. package/dist/cli/commands/uploads/parts-list.js.map +1 -0
  171. package/dist/cli/commands/uploads/parts-urls.d.ts +46 -0
  172. package/dist/cli/commands/uploads/parts-urls.d.ts.map +1 -0
  173. package/dist/cli/commands/uploads/parts-urls.js +57 -0
  174. package/dist/cli/commands/uploads/parts-urls.js.map +1 -0
  175. package/dist/cli/commands/uploads/progress.d.ts +45 -0
  176. package/dist/cli/commands/uploads/progress.d.ts.map +1 -0
  177. package/dist/cli/commands/uploads/progress.js +40 -0
  178. package/dist/cli/commands/uploads/progress.js.map +1 -0
  179. package/dist/cli/commands/uploads/transfer.d.ts +73 -0
  180. package/dist/cli/commands/uploads/transfer.d.ts.map +1 -0
  181. package/dist/cli/commands/uploads/transfer.js +170 -0
  182. package/dist/cli/commands/uploads/transfer.js.map +1 -0
  183. package/dist/cli/index.d.ts +27 -0
  184. package/dist/cli/index.d.ts.map +1 -0
  185. package/dist/cli/index.js +198 -0
  186. package/dist/cli/index.js.map +1 -0
  187. package/dist/cli/keys.js +32 -0
  188. package/dist/cli/keys.js.map +1 -0
  189. package/dist/cli/utils/client.js +174 -0
  190. package/dist/cli/utils/client.js.map +1 -0
  191. package/dist/cli/utils/options.js +135 -0
  192. package/dist/cli/utils/options.js.map +1 -0
  193. package/dist/node/cli/commands/files/delete.d.ts +40 -0
  194. package/dist/node/cli/commands/files/delete.d.ts.map +1 -0
  195. package/dist/node/cli/commands/files/delete.js +31 -0
  196. package/dist/node/cli/commands/files/delete.js.map +1 -0
  197. package/dist/node/cli/commands/files/download-url.d.ts +40 -0
  198. package/dist/node/cli/commands/files/download-url.d.ts.map +1 -0
  199. package/dist/node/cli/commands/files/download-url.js +31 -0
  200. package/dist/node/cli/commands/files/download-url.js.map +1 -0
  201. package/dist/node/cli/commands/files/download.d.ts +49 -0
  202. package/dist/node/cli/commands/files/download.d.ts.map +1 -0
  203. package/dist/node/cli/commands/files/download.js +65 -0
  204. package/dist/node/cli/commands/files/download.js.map +1 -0
  205. package/dist/node/cli/commands/files/get.d.ts +40 -0
  206. package/dist/node/cli/commands/files/get.d.ts.map +1 -0
  207. package/dist/node/cli/commands/files/get.js +31 -0
  208. package/dist/node/cli/commands/files/get.js.map +1 -0
  209. package/dist/node/cli/commands/files/list.d.ts +56 -0
  210. package/dist/node/cli/commands/files/list.d.ts.map +1 -0
  211. package/dist/node/cli/commands/files/list.js +53 -0
  212. package/dist/node/cli/commands/files/list.js.map +1 -0
  213. package/dist/node/cli/commands/files/update.d.ts +56 -0
  214. package/dist/node/cli/commands/files/update.d.ts.map +1 -0
  215. package/dist/node/cli/commands/files/update.js +53 -0
  216. package/dist/node/cli/commands/files/update.js.map +1 -0
  217. package/dist/node/cli/commands/files/upload.d.ts +73 -0
  218. package/dist/node/cli/commands/files/upload.d.ts.map +1 -0
  219. package/dist/node/cli/commands/files/upload.js +87 -0
  220. package/dist/node/cli/commands/files/upload.js.map +1 -0
  221. package/dist/node/cli/commands/uploads/abort.d.ts +37 -0
  222. package/dist/node/cli/commands/uploads/abort.d.ts.map +1 -0
  223. package/dist/node/cli/commands/uploads/abort.js +26 -0
  224. package/dist/node/cli/commands/uploads/abort.js.map +1 -0
  225. package/dist/node/cli/commands/uploads/complete.d.ts +41 -0
  226. package/dist/node/cli/commands/uploads/complete.d.ts.map +1 -0
  227. package/dist/node/cli/commands/uploads/complete.js +45 -0
  228. package/dist/node/cli/commands/uploads/complete.js.map +1 -0
  229. package/dist/node/cli/commands/uploads/content.d.ts +46 -0
  230. package/dist/node/cli/commands/uploads/content.d.ts.map +1 -0
  231. package/dist/node/cli/commands/uploads/content.js +43 -0
  232. package/dist/node/cli/commands/uploads/content.js.map +1 -0
  233. package/dist/node/cli/commands/uploads/create.d.ts +72 -0
  234. package/dist/node/cli/commands/uploads/create.d.ts.map +1 -0
  235. package/dist/node/cli/commands/uploads/create.js +84 -0
  236. package/dist/node/cli/commands/uploads/create.js.map +1 -0
  237. package/dist/node/cli/commands/uploads/get.d.ts +37 -0
  238. package/dist/node/cli/commands/uploads/get.d.ts.map +1 -0
  239. package/dist/node/cli/commands/uploads/get.js +26 -0
  240. package/dist/node/cli/commands/uploads/get.js.map +1 -0
  241. package/dist/node/cli/commands/uploads/parts-complete.d.ts +41 -0
  242. package/dist/node/cli/commands/uploads/parts-complete.d.ts.map +1 -0
  243. package/dist/node/cli/commands/uploads/parts-complete.js +44 -0
  244. package/dist/node/cli/commands/uploads/parts-complete.js.map +1 -0
  245. package/dist/node/cli/commands/uploads/parts-list.d.ts +37 -0
  246. package/dist/node/cli/commands/uploads/parts-list.d.ts.map +1 -0
  247. package/dist/node/cli/commands/uploads/parts-list.js +26 -0
  248. package/dist/node/cli/commands/uploads/parts-list.js.map +1 -0
  249. package/dist/node/cli/commands/uploads/parts-urls.d.ts +46 -0
  250. package/dist/node/cli/commands/uploads/parts-urls.d.ts.map +1 -0
  251. package/dist/node/cli/commands/uploads/parts-urls.js +57 -0
  252. package/dist/node/cli/commands/uploads/parts-urls.js.map +1 -0
  253. package/dist/node/cli/commands/uploads/progress.d.ts +45 -0
  254. package/dist/node/cli/commands/uploads/progress.d.ts.map +1 -0
  255. package/dist/node/cli/commands/uploads/progress.js +40 -0
  256. package/dist/node/cli/commands/uploads/progress.js.map +1 -0
  257. package/dist/node/cli/commands/uploads/transfer.d.ts +73 -0
  258. package/dist/node/cli/commands/uploads/transfer.d.ts.map +1 -0
  259. package/dist/node/cli/commands/uploads/transfer.js +170 -0
  260. package/dist/node/cli/commands/uploads/transfer.js.map +1 -0
  261. package/dist/node/cli/index.d.ts +27 -0
  262. package/dist/node/cli/index.d.ts.map +1 -0
  263. package/dist/node/cli/index.js +198 -0
  264. package/dist/node/cli/index.js.map +1 -0
  265. package/dist/node/cli/utils/client.js +174 -0
  266. package/dist/node/cli/utils/client.js.map +1 -0
  267. package/dist/node/cli/utils/options.js +135 -0
  268. package/dist/node/cli/utils/options.js.map +1 -0
  269. package/dist/node/client/clients.d.ts +295 -0
  270. package/dist/node/client/clients.d.ts.map +1 -0
  271. package/dist/node/client/clients.js +49 -0
  272. package/dist/node/client/clients.js.map +1 -0
  273. package/dist/node/client/helpers.d.ts +51 -0
  274. package/dist/node/client/helpers.d.ts.map +1 -0
  275. package/dist/node/client/helpers.js +242 -0
  276. package/dist/node/client/helpers.js.map +1 -0
  277. package/dist/node/client/react.d.ts +295 -0
  278. package/dist/node/client/react.d.ts.map +1 -0
  279. package/dist/node/client/react.js +11 -0
  280. package/dist/node/client/react.js.map +1 -0
  281. package/dist/node/client/solid.d.ts +303 -0
  282. package/dist/node/client/solid.d.ts.map +1 -0
  283. package/dist/node/client/solid.js +11 -0
  284. package/dist/node/client/solid.js.map +1 -0
  285. package/dist/node/client/svelte.d.ts +295 -0
  286. package/dist/node/client/svelte.d.ts.map +1 -0
  287. package/dist/node/client/svelte.js +11 -0
  288. package/dist/node/client/svelte.js.map +1 -0
  289. package/dist/node/client/vanilla.d.ts +296 -0
  290. package/dist/node/client/vanilla.d.ts.map +1 -0
  291. package/dist/node/client/vanilla.js +11 -0
  292. package/dist/node/client/vanilla.js.map +1 -0
  293. package/dist/node/client/vue.d.ts +295 -0
  294. package/dist/node/client/vue.d.ts.map +1 -0
  295. package/dist/node/client/vue.js +11 -0
  296. package/dist/node/client/vue.js.map +1 -0
  297. package/dist/node/config.d.ts +41 -0
  298. package/dist/node/config.d.ts.map +1 -0
  299. package/dist/node/config.js +26 -0
  300. package/dist/node/config.js.map +1 -0
  301. package/dist/node/definition.d.ts +829 -0
  302. package/dist/node/definition.d.ts.map +1 -0
  303. package/dist/node/definition.js +59 -0
  304. package/dist/node/definition.js.map +1 -0
  305. package/dist/node/index.d.ts +1246 -0
  306. package/dist/node/index.d.ts.map +1 -0
  307. package/dist/node/index.js +19 -0
  308. package/dist/node/index.js.map +1 -0
  309. package/dist/node/keys.d.ts +12 -0
  310. package/dist/node/keys.d.ts.map +1 -0
  311. package/dist/node/keys.js +63 -0
  312. package/dist/node/keys.js.map +1 -0
  313. package/dist/node/routes/files.js +450 -0
  314. package/dist/node/routes/files.js.map +1 -0
  315. package/dist/node/routes/index.d.ts +2023 -0
  316. package/dist/node/routes/index.d.ts.map +1 -0
  317. package/dist/node/routes/index.js +9 -0
  318. package/dist/node/routes/index.js.map +1 -0
  319. package/dist/node/routes/shared.js +66 -0
  320. package/dist/node/routes/shared.js.map +1 -0
  321. package/dist/node/routes/uploads.js +454 -0
  322. package/dist/node/routes/uploads.js.map +1 -0
  323. package/dist/node/schema.d.ts +14 -0
  324. package/dist/node/schema.d.ts.map +1 -0
  325. package/dist/node/schema.js +30 -0
  326. package/dist/node/schema.js.map +1 -0
  327. package/dist/node/services/files.d.ts +20 -0
  328. package/dist/node/services/files.d.ts.map +1 -0
  329. package/dist/node/services/files.js +93 -0
  330. package/dist/node/services/files.js.map +1 -0
  331. package/dist/node/services/helpers.js +36 -0
  332. package/dist/node/services/helpers.js.map +1 -0
  333. package/dist/node/services/index.js +4 -0
  334. package/dist/node/services/uploads.d.ts +50 -0
  335. package/dist/node/services/uploads.d.ts.map +1 -0
  336. package/dist/node/services/uploads.js +358 -0
  337. package/dist/node/services/uploads.js.map +1 -0
  338. package/dist/node/storage/fs.d.ts +16 -0
  339. package/dist/node/storage/fs.d.ts.map +1 -0
  340. package/dist/node/storage/fs.js +94 -0
  341. package/dist/node/storage/fs.js.map +1 -0
  342. package/dist/node/storage/r2.d.ts +103 -0
  343. package/dist/node/storage/r2.d.ts.map +1 -0
  344. package/dist/node/storage/r2.js +23 -0
  345. package/dist/node/storage/r2.js.map +1 -0
  346. package/dist/node/storage/s3.d.ts +44 -0
  347. package/dist/node/storage/s3.d.ts.map +1 -0
  348. package/dist/node/storage/s3.js +398 -0
  349. package/dist/node/storage/s3.js.map +1 -0
  350. package/dist/node/storage/types.d.ts +118 -0
  351. package/dist/node/storage/types.d.ts.map +1 -0
  352. package/dist/node/types.d.ts +32 -0
  353. package/dist/node/types.d.ts.map +1 -0
  354. package/dist/tsconfig.tsbuildinfo +1 -0
  355. package/package.json +105 -0
@@ -0,0 +1,1982 @@
1
+ import { defineFragment, defineRoutes } from "@fragno-dev/core";
2
+ import { z } from "zod";
3
+
4
+ //#region ../fragno/dist/api/route.js
5
+ /**
6
+ * Helper to resolve route factories into routes
7
+ * @internal
8
+ */
9
+ function resolveRouteFactories(context, routesOrFactories) {
10
+ const routes = [];
11
+ for (const item of routesOrFactories) if (typeof item === "function") {
12
+ const factoryRoutes = item(context);
13
+ routes.push(...factoryRoutes);
14
+ } else routes.push(item);
15
+ return routes;
16
+ }
17
+
18
+ //#endregion
19
+ //#region ../fragno/dist/api/internal/route.js
20
+ function getMountRoute(opts) {
21
+ const mountRoute = opts.mountRoute ?? `/api/${opts.name}`;
22
+ if (mountRoute.endsWith("/")) return mountRoute.slice(0, -1);
23
+ return mountRoute;
24
+ }
25
+
26
+ //#endregion
27
+ //#region ../fragno/dist/api/error.js
28
+ var FragnoApiError = class extends Error {
29
+ #status;
30
+ #code;
31
+ constructor({ message, code }, status) {
32
+ super(message);
33
+ this.name = "FragnoApiError";
34
+ this.#status = status;
35
+ this.#code = code;
36
+ }
37
+ get status() {
38
+ return this.#status;
39
+ }
40
+ get code() {
41
+ return this.#code;
42
+ }
43
+ toResponse() {
44
+ return Response.json({
45
+ message: this.message,
46
+ code: this.code
47
+ }, { status: this.status });
48
+ }
49
+ };
50
+ var FragnoApiValidationError = class extends FragnoApiError {
51
+ #issues;
52
+ constructor(message, issues) {
53
+ super({
54
+ message,
55
+ code: "FRAGNO_VALIDATION_ERROR"
56
+ }, 400);
57
+ this.name = "FragnoApiValidationError";
58
+ this.#issues = issues;
59
+ }
60
+ get issues() {
61
+ return this.#issues;
62
+ }
63
+ toResponse() {
64
+ return Response.json({
65
+ message: this.message,
66
+ issues: this.#issues,
67
+ code: this.code
68
+ }, { status: this.status });
69
+ }
70
+ };
71
+
72
+ //#endregion
73
+ //#region ../fragno/dist/api/request-input-context.js
74
+ var RequestInputContext = class RequestInputContext$1 {
75
+ #path;
76
+ #method;
77
+ #pathParams;
78
+ #searchParams;
79
+ #headers;
80
+ #body;
81
+ #parsedBody;
82
+ #inputSchema;
83
+ #shouldValidateInput;
84
+ constructor(config) {
85
+ this.#path = config.path;
86
+ this.#method = config.method;
87
+ this.#pathParams = config.pathParams;
88
+ this.#searchParams = config.searchParams;
89
+ this.#headers = config.headers;
90
+ this.#body = config.rawBody;
91
+ this.#parsedBody = config.parsedBody;
92
+ this.#inputSchema = config.inputSchema;
93
+ this.#shouldValidateInput = config.shouldValidateInput ?? true;
94
+ }
95
+ /**
96
+ * Create a RequestContext from a Request object for server-side handling
97
+ */
98
+ static async fromRequest(config) {
99
+ return new RequestInputContext$1({
100
+ method: config.method,
101
+ path: config.path,
102
+ pathParams: config.state.pathParams,
103
+ searchParams: config.state.searchParams,
104
+ headers: config.state.headers,
105
+ parsedBody: config.state.body,
106
+ rawBody: config.rawBody,
107
+ inputSchema: config.inputSchema,
108
+ shouldValidateInput: config.shouldValidateInput
109
+ });
110
+ }
111
+ /**
112
+ * Create a RequestContext for server-side rendering contexts (no Request object)
113
+ */
114
+ static fromSSRContext(config) {
115
+ return new RequestInputContext$1({
116
+ method: config.method,
117
+ path: config.path,
118
+ pathParams: config.pathParams,
119
+ searchParams: config.searchParams ?? new URLSearchParams(),
120
+ headers: config.headers ?? new Headers(),
121
+ parsedBody: "body" in config ? config.body : void 0,
122
+ inputSchema: "inputSchema" in config ? config.inputSchema : void 0,
123
+ shouldValidateInput: false
124
+ });
125
+ }
126
+ /**
127
+ * The HTTP method as string (e.g., `GET`, `POST`)
128
+ */
129
+ get method() {
130
+ return this.#method;
131
+ }
132
+ /**
133
+ * The matched route path (e.g., `/users/:id`)
134
+ * @remarks `string`
135
+ */
136
+ get path() {
137
+ return this.#path;
138
+ }
139
+ /**
140
+ * Extracted path parameters as object (e.g., `{ id: '123' }`)
141
+ * @remarks `Record<string, string>`
142
+ */
143
+ get pathParams() {
144
+ return this.#pathParams;
145
+ }
146
+ /**
147
+ * [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) object for query parameters
148
+ * @remarks `URLSearchParams`
149
+ */
150
+ get query() {
151
+ return this.#searchParams;
152
+ }
153
+ /**
154
+ * [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) object for request headers
155
+ * @remarks `Headers`
156
+ */
157
+ get headers() {
158
+ return this.#headers;
159
+ }
160
+ get rawBody() {
161
+ return this.#body;
162
+ }
163
+ /**
164
+ * Access the request body as FormData.
165
+ *
166
+ * Use this method when handling file uploads or multipart form submissions.
167
+ * The request must have been sent with Content-Type: multipart/form-data.
168
+ *
169
+ * @throws Error if the request body is not FormData
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * defineRoute({
174
+ * method: "POST",
175
+ * path: "/upload",
176
+ * async handler(ctx, res) {
177
+ * const formData = ctx.formData();
178
+ * const file = formData.get("file") as File;
179
+ * const description = formData.get("description") as string;
180
+ * // ... process file
181
+ * }
182
+ * });
183
+ * ```
184
+ */
185
+ formData() {
186
+ if (!(this.#parsedBody instanceof FormData)) throw new Error("Request body is not FormData. Ensure the request was sent with Content-Type: multipart/form-data.");
187
+ return this.#parsedBody;
188
+ }
189
+ /**
190
+ * Check if the request body is FormData.
191
+ *
192
+ * Useful for routes that accept both JSON and FormData payloads.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * defineRoute({
197
+ * method: "POST",
198
+ * path: "/upload",
199
+ * async handler(ctx, res) {
200
+ * if (ctx.isFormData()) {
201
+ * const formData = ctx.formData();
202
+ * // handle file upload
203
+ * } else {
204
+ * const json = await ctx.input.valid();
205
+ * // handle JSON payload
206
+ * }
207
+ * }
208
+ * });
209
+ * ```
210
+ */
211
+ isFormData() {
212
+ return this.#parsedBody instanceof FormData;
213
+ }
214
+ /**
215
+ * Input validation context (only if inputSchema is defined)
216
+ * @remarks `InputContext`
217
+ */
218
+ get input() {
219
+ if (!this.#inputSchema) return;
220
+ return {
221
+ schema: this.#inputSchema,
222
+ valid: async () => {
223
+ if (!this.#shouldValidateInput) return this.#parsedBody;
224
+ return this.#validateInput();
225
+ }
226
+ };
227
+ }
228
+ async #validateInput() {
229
+ if (!this.#inputSchema) throw new Error("No input schema defined for this route");
230
+ if (this.#parsedBody instanceof FormData || this.#parsedBody instanceof Blob) throw new Error("Schema validation is only supported for JSON data, not FormData or Blob");
231
+ const result = await this.#inputSchema["~standard"].validate(this.#parsedBody);
232
+ if (result.issues) throw new FragnoApiValidationError("Validation failed", result.issues);
233
+ return result.value;
234
+ }
235
+ };
236
+
237
+ //#endregion
238
+ //#region ../fragno/dist/api/internal/response-stream.js
239
+ var ResponseStream = class {
240
+ #writer;
241
+ #encoder;
242
+ #abortSubscribers = [];
243
+ #responseReadable;
244
+ #aborted = false;
245
+ #closed = false;
246
+ /**
247
+ * Whether the stream has been aborted.
248
+ */
249
+ get aborted() {
250
+ return this.#aborted;
251
+ }
252
+ /**
253
+ * Whether the stream has been closed normally.
254
+ */
255
+ get closed() {
256
+ return this.#closed;
257
+ }
258
+ /**
259
+ * The readable stream that the response is piped to.
260
+ */
261
+ get responseReadable() {
262
+ return this.#responseReadable;
263
+ }
264
+ constructor(writable, readable) {
265
+ this.#writer = writable.getWriter();
266
+ this.#encoder = new TextEncoder();
267
+ const reader = readable.getReader();
268
+ this.#abortSubscribers.push(async () => {
269
+ await reader.cancel();
270
+ });
271
+ this.#responseReadable = new ReadableStream({
272
+ async pull(controller) {
273
+ const { done, value } = await reader.read();
274
+ if (done) controller.close();
275
+ else controller.enqueue(value);
276
+ },
277
+ cancel: () => {
278
+ this.abort();
279
+ }
280
+ });
281
+ }
282
+ async writeRaw(input) {
283
+ try {
284
+ if (typeof input === "string") input = this.#encoder.encode(input);
285
+ await this.#writer.write(input);
286
+ } catch {}
287
+ }
288
+ write(input) {
289
+ return this.writeRaw(JSON.stringify(input) + "\n");
290
+ }
291
+ sleep(ms) {
292
+ return new Promise((res) => setTimeout(res, ms));
293
+ }
294
+ async close() {
295
+ try {
296
+ await this.#writer.close();
297
+ } catch {} finally {
298
+ this.#closed = true;
299
+ }
300
+ }
301
+ onAbort(listener) {
302
+ this.#abortSubscribers.push(listener);
303
+ }
304
+ /**
305
+ * Abort the stream.
306
+ * You can call this method when stream is aborted by external event.
307
+ */
308
+ abort() {
309
+ if (!this.aborted) {
310
+ this.#aborted = true;
311
+ this.#abortSubscribers.forEach((subscriber) => subscriber());
312
+ }
313
+ }
314
+ };
315
+
316
+ //#endregion
317
+ //#region ../fragno/dist/api/request-output-context.js
318
+ /**
319
+ * Utility function to merge headers from multiple sources.
320
+ * Later headers override earlier ones.
321
+ */
322
+ function mergeHeaders$1(...headerSources) {
323
+ const mergedHeaders = new Headers();
324
+ for (const headerSource of headerSources) {
325
+ if (!headerSource) continue;
326
+ if (headerSource instanceof Headers) for (const [key, value] of headerSource.entries()) mergedHeaders.set(key, value);
327
+ else if (Array.isArray(headerSource)) for (const [key, value] of headerSource) mergedHeaders.set(key, value);
328
+ else for (const [key, value] of Object.entries(headerSource)) mergedHeaders.set(key, value);
329
+ }
330
+ return mergedHeaders;
331
+ }
332
+ var OutputContext = class {
333
+ /**
334
+ * Creates an error response.
335
+ *
336
+ * Shortcut for `throw new FragnoApiError(...)`
337
+ */
338
+ error = ({ message, code }, initOrStatus, headers) => {
339
+ if (typeof initOrStatus === "undefined") return Response.json({
340
+ message,
341
+ code
342
+ }, {
343
+ status: 500,
344
+ headers
345
+ });
346
+ if (typeof initOrStatus === "number") return Response.json({
347
+ message,
348
+ code
349
+ }, {
350
+ status: initOrStatus,
351
+ headers
352
+ });
353
+ const mergedHeaders = mergeHeaders$1(initOrStatus.headers, headers);
354
+ return Response.json({
355
+ message,
356
+ code
357
+ }, {
358
+ status: initOrStatus.status,
359
+ headers: mergedHeaders
360
+ });
361
+ };
362
+ empty = (initOrStatus, headers) => {
363
+ const defaultHeaders = {};
364
+ if (typeof initOrStatus === "undefined") {
365
+ const mergedHeaders$1 = mergeHeaders$1(defaultHeaders, headers);
366
+ return new Response(null, {
367
+ status: 201,
368
+ headers: mergedHeaders$1
369
+ });
370
+ }
371
+ if (typeof initOrStatus === "number") {
372
+ const mergedHeaders$1 = mergeHeaders$1(defaultHeaders, headers);
373
+ return new Response(null, {
374
+ status: initOrStatus,
375
+ headers: mergedHeaders$1
376
+ });
377
+ }
378
+ const mergedHeaders = mergeHeaders$1(defaultHeaders, initOrStatus.headers, headers);
379
+ return new Response(null, {
380
+ status: initOrStatus.status,
381
+ headers: mergedHeaders
382
+ });
383
+ };
384
+ json = (object, initOrStatus, headers) => {
385
+ if (typeof initOrStatus === "undefined") return Response.json(object, {
386
+ status: 200,
387
+ headers
388
+ });
389
+ if (typeof initOrStatus === "number") return Response.json(object, {
390
+ status: initOrStatus,
391
+ headers
392
+ });
393
+ const mergedHeaders = mergeHeaders$1(initOrStatus.headers, headers);
394
+ return Response.json(object, {
395
+ status: initOrStatus.status,
396
+ headers: mergedHeaders
397
+ });
398
+ };
399
+ jsonStream = (cb, { onError, headers } = {}) => {
400
+ const defaultHeaders = {
401
+ "content-type": "application/x-ndjson; charset=utf-8",
402
+ "transfer-encoding": "chunked",
403
+ "cache-control": "no-cache"
404
+ };
405
+ const { readable, writable } = new TransformStream();
406
+ const stream = new ResponseStream(writable, readable);
407
+ (async () => {
408
+ try {
409
+ await cb(stream);
410
+ } catch (e) {
411
+ if (e === void 0) {} else if (e instanceof Error && onError) await onError(e, stream);
412
+ else console.error(e);
413
+ } finally {
414
+ stream.close();
415
+ }
416
+ })();
417
+ return new Response(stream.responseReadable, {
418
+ status: 200,
419
+ headers: mergeHeaders$1(defaultHeaders, headers)
420
+ });
421
+ };
422
+ };
423
+ var RequestOutputContext = class extends OutputContext {
424
+ #outputSchema;
425
+ constructor(outputSchema) {
426
+ super();
427
+ this.#outputSchema = outputSchema;
428
+ }
429
+ };
430
+
431
+ //#endregion
432
+ //#region ../fragno/dist/api/internal/path.js
433
+ /**
434
+ * Extract parameter names from a path pattern at runtime.
435
+ * Examples:
436
+ * - "/users/:id" => ["id"]
437
+ * - "/files/**" => ["**"]
438
+ * - "/files/**:rest" => ["rest"]
439
+ */
440
+ function extractPathParams(pathPattern) {
441
+ const segments = pathPattern.split("/").filter((s) => s.length > 0);
442
+ const names = [];
443
+ for (const segment of segments) {
444
+ if (segment.startsWith(":")) {
445
+ names.push(segment.slice(1));
446
+ continue;
447
+ }
448
+ if (segment === "**") {
449
+ names.push("**");
450
+ continue;
451
+ }
452
+ if (segment.startsWith("**:")) {
453
+ names.push(segment.slice(3));
454
+ continue;
455
+ }
456
+ }
457
+ return names;
458
+ }
459
+ /**
460
+ * Build a concrete path by replacing placeholders in a path pattern with values.
461
+ *
462
+ * Supports the same placeholder syntax as the matcher:
463
+ * - Named parameter ":name" is URL-encoded as a single segment
464
+ * - Anonymous wildcard "**" inserts the remainder as-is (slashes preserved)
465
+ * - Named wildcard "**:name" inserts the remainder from the named key
466
+ *
467
+ * Examples:
468
+ * - buildPath("/users/:id", { id: "123" }) => "/users/123"
469
+ * - buildPath("/files/**", { "**": "a/b" }) => "/files/a/b"
470
+ * - buildPath("/files/**:rest", { rest: "a/b" }) => "/files/a/b"
471
+ */
472
+ function buildPath(pathPattern, params) {
473
+ const patternSegments = pathPattern.split("/");
474
+ const builtSegments = [];
475
+ for (const segment of patternSegments) {
476
+ if (segment.length === 0) {
477
+ builtSegments.push("");
478
+ continue;
479
+ }
480
+ if (segment.startsWith(":")) {
481
+ const name = segment.slice(1);
482
+ const value = params[name];
483
+ if (value === void 0) throw new Error(`Missing value for path parameter :${name}`);
484
+ builtSegments.push(encodeURIComponent(value));
485
+ continue;
486
+ }
487
+ if (segment === "**") {
488
+ const value = params["**"];
489
+ if (value === void 0) throw new Error("Missing value for path wildcard **");
490
+ builtSegments.push(value);
491
+ continue;
492
+ }
493
+ if (segment.startsWith("**:")) {
494
+ const name = segment.slice(3);
495
+ const value = params[name];
496
+ if (value === void 0) throw new Error(`Missing value for path wildcard **:${name}`);
497
+ builtSegments.push(value);
498
+ continue;
499
+ }
500
+ builtSegments.push(segment);
501
+ }
502
+ return builtSegments.join("/");
503
+ }
504
+
505
+ //#endregion
506
+ //#region ../fragno/dist/client/client-error.js
507
+ /**
508
+ * Base error class for all Fragno client errors.
509
+ */
510
+ var FragnoClientError = class extends Error {
511
+ #code;
512
+ constructor(message, code, options = {}) {
513
+ super(message, { cause: options.cause });
514
+ this.name = "FragnoClientError";
515
+ this.#code = code;
516
+ }
517
+ get code() {
518
+ return this.#code;
519
+ }
520
+ };
521
+ var FragnoClientFetchError = class extends FragnoClientError {
522
+ constructor(message, code, options = {}) {
523
+ super(message, code, options);
524
+ this.name = "FragnoClientFetchError";
525
+ }
526
+ static fromUnknownFetchError(error) {
527
+ if (!(error instanceof Error)) return new FragnoClientFetchNetworkError("Network request failed", { cause: error });
528
+ if (error.name === "AbortError") return new FragnoClientFetchAbortError("Request was aborted", { cause: error });
529
+ return new FragnoClientFetchNetworkError("Network request failed", { cause: error });
530
+ }
531
+ };
532
+ /**
533
+ * Error thrown when a network request fails (e.g., no internet connection, DNS failure).
534
+ */
535
+ var FragnoClientFetchNetworkError = class extends FragnoClientFetchError {
536
+ constructor(message = "Network request failed", options = {}) {
537
+ super(message, "NETWORK_ERROR", options);
538
+ this.name = "FragnoClientFetchNetworkError";
539
+ }
540
+ };
541
+ /**
542
+ * Error thrown when a request is aborted (e.g., user cancels request, timeout).
543
+ */
544
+ var FragnoClientFetchAbortError = class extends FragnoClientFetchError {
545
+ constructor(message = "Request was aborted", options = {}) {
546
+ super(message, "ABORT_ERROR", options);
547
+ this.name = "FragnoClientFetchAbortError";
548
+ }
549
+ };
550
+ /**
551
+ * Error thrown when the API result is unexpected, e.g. no json is returned.
552
+ */
553
+ var FragnoClientUnknownApiError = class extends FragnoClientError {
554
+ #status;
555
+ constructor(message = "Unknown API error", status, options = {}) {
556
+ super(message, "UNKNOWN_API_ERROR", options);
557
+ this.name = "FragnoClientUnknownApiError";
558
+ this.#status = status;
559
+ }
560
+ get status() {
561
+ return this.#status;
562
+ }
563
+ };
564
+ var FragnoClientApiError = class FragnoClientApiError$1 extends FragnoClientError {
565
+ #status;
566
+ constructor({ message, code }, status, options = {}) {
567
+ super(message, code, options);
568
+ this.name = "FragnoClientApiError";
569
+ this.#status = status;
570
+ }
571
+ get status() {
572
+ return this.#status;
573
+ }
574
+ /**
575
+ * The error code returned by the API.
576
+ *
577
+ * The type is `TErrorCode` (the set of known error codes for this route), but may also be a string
578
+ * for forward compatibility with future error codes.
579
+ */
580
+ get code() {
581
+ return super.code;
582
+ }
583
+ static async fromResponse(response) {
584
+ const unknown = await response.json();
585
+ const status = response.status;
586
+ if (!("message" in unknown || "code" in unknown)) return new FragnoClientUnknownApiError("Unknown API error", status);
587
+ if (!(typeof unknown.message === "string" && typeof unknown.code === "string")) return new FragnoClientUnknownApiError("Unknown API error", status);
588
+ return new FragnoClientApiError$1({
589
+ message: unknown.message,
590
+ code: unknown.code
591
+ }, status);
592
+ }
593
+ };
594
+
595
+ //#endregion
596
+ //#region ../fragno/dist/util/content-type.js
597
+ /**
598
+ * Parses a content-type header string into its components
599
+ *
600
+ * @param contentType - The content-type header value to parse
601
+ * @returns A ParsedContentType object or null if the input is invalid
602
+ *
603
+ * @example
604
+ * ```ts
605
+ * const { type, subtype, mediaType, parameters }
606
+ * = parseContentType("application/json; charset=utf-8");
607
+ * console.assert(type === "application");
608
+ * console.assert(subtype === "json");
609
+ * console.assert(mediaType === "application/json");
610
+ * console.assert(parameters["charset"] === "utf-8");
611
+ */
612
+ function parseContentType(contentType) {
613
+ if (!contentType || typeof contentType !== "string") return null;
614
+ const trimmed = contentType.trim();
615
+ if (!trimmed) return null;
616
+ const parts = trimmed.split(";").map((part) => part.trim());
617
+ const mediaType = parts[0];
618
+ if (!mediaType) return null;
619
+ const typeParts = mediaType.split("/");
620
+ if (typeParts.length !== 2) return null;
621
+ const [type, subtype] = typeParts.map((part) => part.trim().toLowerCase());
622
+ if (!type || !subtype) return null;
623
+ const parameters = {};
624
+ for (let i = 1; i < parts.length; i++) {
625
+ const param = parts[i];
626
+ const equalIndex = param.indexOf("=");
627
+ if (equalIndex > 0) {
628
+ const key = param.slice(0, equalIndex).trim().toLowerCase();
629
+ let value = param.slice(equalIndex + 1).trim();
630
+ if (value.startsWith("\"") && value.endsWith("\"")) value = value.slice(1, -1);
631
+ if (key) parameters[key] = value;
632
+ }
633
+ }
634
+ return {
635
+ type,
636
+ subtype,
637
+ mediaType: `${type}/${subtype}`,
638
+ parameters
639
+ };
640
+ }
641
+
642
+ //#endregion
643
+ //#region ../fragno/dist/client/internal/ndjson-streaming.js
644
+ /**
645
+ * Creates a promise that rejects when the abort signal is triggered
646
+ */
647
+ function createAbortPromise(abortSignal) {
648
+ return new Promise((_, reject) => {
649
+ const abortHandler = () => {
650
+ reject(new FragnoClientFetchAbortError("Operation was aborted"));
651
+ };
652
+ if (abortSignal.aborted) abortHandler();
653
+ else abortSignal.addEventListener("abort", abortHandler, { once: true });
654
+ });
655
+ }
656
+ /**
657
+ * Handles NDJSON streaming responses by returning the first item from the fetcher
658
+ * and then continuing to stream updates via the store's mutate method.
659
+ *
660
+ * This makes it so that we can wait until the first chunk before updating the store, if we did
661
+ * not do this, `loading` would briefly be false before the first item would be populated in the
662
+ * result.
663
+ *
664
+ * @param response - The fetch Response object containing the NDJSON stream
665
+ * @param store - The fetcher store to update with streaming data
666
+ * @param abortSignal - Optional AbortSignal to cancel the streaming operation
667
+ * @returns A promise that resolves to an object containing the first item and a streaming promise
668
+ */
669
+ async function handleNdjsonStreamingFirstItem(response, store, options = {}) {
670
+ if (!response.body) throw new FragnoClientFetchError("Streaming response has no body", "NO_BODY");
671
+ const { abortSignal } = options;
672
+ if (abortSignal?.aborted) throw new FragnoClientFetchAbortError("Operation was aborted");
673
+ const decoder = new TextDecoder();
674
+ const reader = response.body.getReader();
675
+ let buffer = "";
676
+ let firstItem = null;
677
+ const items = [];
678
+ try {
679
+ while (firstItem === null) {
680
+ if (abortSignal?.aborted) {
681
+ reader.releaseLock();
682
+ throw new FragnoClientFetchAbortError("Operation was aborted");
683
+ }
684
+ const { done, value } = await (abortSignal ? Promise.race([reader.read(), createAbortPromise(abortSignal)]) : reader.read());
685
+ if (done) break;
686
+ buffer += decoder.decode(value, { stream: true });
687
+ const lines = buffer.split("\n");
688
+ buffer = lines.pop() || "";
689
+ for (const line of lines) {
690
+ if (!line.trim()) continue;
691
+ try {
692
+ const jsonObject = JSON.parse(line);
693
+ items.push(jsonObject);
694
+ if (firstItem === null) {
695
+ firstItem = jsonObject;
696
+ const streamingPromise = continueStreaming(reader, decoder, buffer, items, store, abortSignal);
697
+ return {
698
+ firstItem,
699
+ streamingPromise
700
+ };
701
+ }
702
+ } catch (parseError) {
703
+ throw new FragnoClientUnknownApiError("Failed to parse NDJSON line", 500, { cause: parseError });
704
+ }
705
+ }
706
+ }
707
+ if (firstItem === null) {
708
+ reader.releaseLock();
709
+ throw new FragnoClientUnknownApiError("NDJSON stream contained no valid items", 500);
710
+ }
711
+ reader.releaseLock();
712
+ throw new FragnoClientFetchError("Unexpected end of stream processing", "NO_BODY");
713
+ } catch (error) {
714
+ if (error instanceof FragnoClientError) {
715
+ store?.setError(error);
716
+ throw error;
717
+ } else {
718
+ const clientError = new FragnoClientUnknownApiError("Unknown streaming error", 500, { cause: error });
719
+ store?.setError(clientError);
720
+ throw clientError;
721
+ }
722
+ }
723
+ }
724
+ /**
725
+ * Continues streaming the remaining items in the background
726
+ */
727
+ async function continueStreaming(reader, decoder, initialBuffer, items, store, abortSignal) {
728
+ let buffer = initialBuffer;
729
+ try {
730
+ while (true) {
731
+ if (abortSignal?.aborted) throw new FragnoClientFetchAbortError("Operation was aborted");
732
+ const { done, value } = await (abortSignal ? Promise.race([reader.read(), createAbortPromise(abortSignal)]) : reader.read());
733
+ if (done) {
734
+ if (buffer.trim()) {
735
+ const lines$1 = buffer.split("\n");
736
+ for (const line of lines$1) {
737
+ if (!line.trim()) continue;
738
+ try {
739
+ const jsonObject = JSON.parse(line);
740
+ items.push(jsonObject);
741
+ store?.setData([...items]);
742
+ } catch (parseError) {
743
+ throw new FragnoClientUnknownApiError("Failed to parse NDJSON line", 400, { cause: parseError });
744
+ }
745
+ }
746
+ }
747
+ break;
748
+ }
749
+ buffer += decoder.decode(value, { stream: true });
750
+ const lines = buffer.split("\n");
751
+ buffer = lines.pop() || "";
752
+ for (const line of lines) {
753
+ if (!line.trim()) continue;
754
+ try {
755
+ const jsonObject = JSON.parse(line);
756
+ items.push(jsonObject);
757
+ store?.setData([...items]);
758
+ } catch (parseError) {
759
+ throw new FragnoClientUnknownApiError("Failed to parse NDJSON line", 400, { cause: parseError });
760
+ }
761
+ }
762
+ }
763
+ } catch (error) {
764
+ if (error instanceof FragnoClientError) store?.setError(error);
765
+ else {
766
+ const clientError = new FragnoClientUnknownApiError("Unknown streaming error", 400, { cause: error });
767
+ store?.setError(clientError);
768
+ throw clientError;
769
+ }
770
+ throw error;
771
+ } finally {
772
+ reader.releaseLock();
773
+ }
774
+ return items;
775
+ }
776
+
777
+ //#endregion
778
+ //#region ../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/task/index.js
779
+ let tasks = 0;
780
+ let resolves = [];
781
+ function startTask() {
782
+ tasks += 1;
783
+ return () => {
784
+ tasks -= 1;
785
+ if (tasks === 0) {
786
+ let prevResolves = resolves;
787
+ resolves = [];
788
+ for (let i of prevResolves) i();
789
+ }
790
+ };
791
+ }
792
+ function task(cb) {
793
+ let endTask = startTask();
794
+ let promise = cb().finally(endTask);
795
+ promise.t = true;
796
+ return promise;
797
+ }
798
+
799
+ //#endregion
800
+ //#region ../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/clean-stores/index.js
801
+ let clean = Symbol("clean");
802
+
803
+ //#endregion
804
+ //#region ../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/atom/index.js
805
+ let listenerQueue = [];
806
+ let lqIndex = 0;
807
+ const QUEUE_ITEMS_PER_LISTENER = 4;
808
+ let epoch = 0;
809
+ const atom = /* @__NO_SIDE_EFFECTS__ */ (initialValue) => {
810
+ let listeners = [];
811
+ let $atom = {
812
+ get() {
813
+ if (!$atom.lc) $atom.listen(() => {})();
814
+ return $atom.value;
815
+ },
816
+ lc: 0,
817
+ listen(listener) {
818
+ $atom.lc = listeners.push(listener);
819
+ return () => {
820
+ for (let i = lqIndex + QUEUE_ITEMS_PER_LISTENER; i < listenerQueue.length;) if (listenerQueue[i] === listener) listenerQueue.splice(i, QUEUE_ITEMS_PER_LISTENER);
821
+ else i += QUEUE_ITEMS_PER_LISTENER;
822
+ let index = listeners.indexOf(listener);
823
+ if (~index) {
824
+ listeners.splice(index, 1);
825
+ if (!--$atom.lc) $atom.off();
826
+ }
827
+ };
828
+ },
829
+ notify(oldValue, changedKey) {
830
+ epoch++;
831
+ let runListenerQueue = !listenerQueue.length;
832
+ for (let listener of listeners) listenerQueue.push(listener, $atom.value, oldValue, changedKey);
833
+ if (runListenerQueue) {
834
+ for (lqIndex = 0; lqIndex < listenerQueue.length; lqIndex += QUEUE_ITEMS_PER_LISTENER) listenerQueue[lqIndex](listenerQueue[lqIndex + 1], listenerQueue[lqIndex + 2], listenerQueue[lqIndex + 3]);
835
+ listenerQueue.length = 0;
836
+ }
837
+ },
838
+ off() {},
839
+ set(newValue) {
840
+ let oldValue = $atom.value;
841
+ if (oldValue !== newValue) {
842
+ $atom.value = newValue;
843
+ $atom.notify(oldValue);
844
+ }
845
+ },
846
+ subscribe(listener) {
847
+ let unbind = $atom.listen(listener);
848
+ listener($atom.value);
849
+ return unbind;
850
+ },
851
+ value: initialValue
852
+ };
853
+ $atom[clean] = () => {
854
+ listeners = [];
855
+ $atom.lc = 0;
856
+ $atom.off();
857
+ };
858
+ return $atom;
859
+ };
860
+
861
+ //#endregion
862
+ //#region ../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/lifecycle/index.js
863
+ const START = 0;
864
+ const STOP = 1;
865
+ const MOUNT = 5;
866
+ const UNMOUNT = 6;
867
+ const REVERT_MUTATION = 10;
868
+ let on = (object, listener, eventKey, mutateStore) => {
869
+ object.events = object.events || {};
870
+ if (!object.events[eventKey + REVERT_MUTATION]) object.events[eventKey + REVERT_MUTATION] = mutateStore((eventProps) => {
871
+ object.events[eventKey].reduceRight((event, l) => (l(event), event), {
872
+ shared: {},
873
+ ...eventProps
874
+ });
875
+ });
876
+ object.events[eventKey] = object.events[eventKey] || [];
877
+ object.events[eventKey].push(listener);
878
+ return () => {
879
+ let currentListeners = object.events[eventKey];
880
+ let index = currentListeners.indexOf(listener);
881
+ currentListeners.splice(index, 1);
882
+ if (!currentListeners.length) {
883
+ delete object.events[eventKey];
884
+ object.events[eventKey + REVERT_MUTATION]();
885
+ delete object.events[eventKey + REVERT_MUTATION];
886
+ }
887
+ };
888
+ };
889
+ let onStart = ($store, listener) => on($store, listener, START, (runListeners) => {
890
+ let originListen = $store.listen;
891
+ $store.listen = (arg) => {
892
+ if (!$store.lc && !$store.starting) {
893
+ $store.starting = true;
894
+ runListeners();
895
+ delete $store.starting;
896
+ }
897
+ return originListen(arg);
898
+ };
899
+ return () => {
900
+ $store.listen = originListen;
901
+ };
902
+ });
903
+ let onStop = ($store, listener) => on($store, listener, STOP, (runListeners) => {
904
+ let originOff = $store.off;
905
+ $store.off = () => {
906
+ runListeners();
907
+ originOff();
908
+ };
909
+ return () => {
910
+ $store.off = originOff;
911
+ };
912
+ });
913
+ let STORE_UNMOUNT_DELAY = 1e3;
914
+ let onMount = ($store, initialize) => {
915
+ let listener = (payload) => {
916
+ let destroy = initialize(payload);
917
+ if (destroy) $store.events[UNMOUNT].push(destroy);
918
+ };
919
+ return on($store, listener, MOUNT, (runListeners) => {
920
+ let originListen = $store.listen;
921
+ $store.listen = (...args) => {
922
+ if (!$store.lc && !$store.active) {
923
+ $store.active = true;
924
+ runListeners();
925
+ }
926
+ return originListen(...args);
927
+ };
928
+ let originOff = $store.off;
929
+ $store.events[UNMOUNT] = [];
930
+ $store.off = () => {
931
+ originOff();
932
+ setTimeout(() => {
933
+ if ($store.active && !$store.lc) {
934
+ $store.active = false;
935
+ for (let destroy of $store.events[UNMOUNT]) destroy();
936
+ $store.events[UNMOUNT] = [];
937
+ }
938
+ }, STORE_UNMOUNT_DELAY);
939
+ };
940
+ {
941
+ let originClean = $store[clean];
942
+ $store[clean] = () => {
943
+ for (let destroy of $store.events[UNMOUNT]) destroy();
944
+ $store.events[UNMOUNT] = [];
945
+ $store.active = false;
946
+ originClean();
947
+ };
948
+ }
949
+ return () => {
950
+ $store.listen = originListen;
951
+ $store.off = originOff;
952
+ };
953
+ });
954
+ };
955
+
956
+ //#endregion
957
+ //#region ../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/computed/index.js
958
+ let computedStore = (stores$1, cb, batched$1) => {
959
+ if (!Array.isArray(stores$1)) stores$1 = [stores$1];
960
+ let previousArgs;
961
+ let currentEpoch;
962
+ let set = () => {
963
+ if (currentEpoch === epoch) return;
964
+ currentEpoch = epoch;
965
+ let args = stores$1.map(($store) => $store.get());
966
+ if (!previousArgs || args.some((arg, i) => arg !== previousArgs[i])) {
967
+ previousArgs = args;
968
+ let value = cb(...args);
969
+ if (value && value.then && value.t) value.then((asyncValue) => {
970
+ if (previousArgs === args) $computed.set(asyncValue);
971
+ });
972
+ else {
973
+ $computed.set(value);
974
+ currentEpoch = epoch;
975
+ }
976
+ }
977
+ };
978
+ let $computed = /* @__PURE__ */ atom(void 0);
979
+ let get = $computed.get;
980
+ $computed.get = () => {
981
+ set();
982
+ return get();
983
+ };
984
+ let timer;
985
+ let run = batched$1 ? () => {
986
+ clearTimeout(timer);
987
+ timer = setTimeout(set);
988
+ } : set;
989
+ onMount($computed, () => {
990
+ let unbinds = stores$1.map(($store) => $store.listen(run));
991
+ set();
992
+ return () => {
993
+ for (let unbind of unbinds) unbind();
994
+ };
995
+ });
996
+ return $computed;
997
+ };
998
+ const computed = /* @__NO_SIDE_EFFECTS__ */ (stores$1, fn) => computedStore(stores$1, fn);
999
+ const batched = /* @__NO_SIDE_EFFECTS__ */ (stores$1, fn) => computedStore(stores$1, fn, true);
1000
+
1001
+ //#endregion
1002
+ //#region ../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/map/index.js
1003
+ const map = /* @__NO_SIDE_EFFECTS__ */ (initial = {}) => {
1004
+ let $map = /* @__PURE__ */ atom(initial);
1005
+ $map.setKey = function(key, value) {
1006
+ let oldMap = $map.value;
1007
+ if (typeof value === "undefined" && key in $map.value) {
1008
+ $map.value = { ...$map.value };
1009
+ delete $map.value[key];
1010
+ $map.notify(oldMap, key);
1011
+ } else if ($map.value[key] !== value) {
1012
+ $map.value = {
1013
+ ...$map.value,
1014
+ [key]: value
1015
+ };
1016
+ $map.notify(oldMap, key);
1017
+ }
1018
+ };
1019
+ return $map;
1020
+ };
1021
+
1022
+ //#endregion
1023
+ //#region ../fragno/dist/util/ssr.js
1024
+ let stores = [];
1025
+ const SSR_ENABLED = false;
1026
+ function addStore(store) {
1027
+ stores.push(store);
1028
+ }
1029
+ let clientInitialData;
1030
+ function getInitialData(key) {
1031
+ if (clientInitialData?.has(key)) {
1032
+ const data = clientInitialData.get(key);
1033
+ clientInitialData.delete(key);
1034
+ return data;
1035
+ }
1036
+ }
1037
+
1038
+ //#endregion
1039
+ //#region ../fragno/dist/util/nanostores.js
1040
+ /**
1041
+ * Normalizes a value that could be a plain value, an Atom, or a Vue Ref to a plain value.
1042
+ */
1043
+ function unwrapAtom(value) {
1044
+ if (value && typeof value === "object" && "get" in value && typeof value.get === "function") return value.get();
1045
+ return value;
1046
+ }
1047
+ /**
1048
+ * Normalizes an object where values can be plain values, Atoms, or Vue Refs.
1049
+ * Returns a new object with all values normalized to plain values.
1050
+ */
1051
+ function unwrapObject(params) {
1052
+ if (!params) return;
1053
+ return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, unwrapAtom(value)]));
1054
+ }
1055
+ function isReadableAtom(value) {
1056
+ if (!value) return false;
1057
+ if (typeof value !== "object" || value === null) return false;
1058
+ if (!("get" in value) || typeof value.get !== "function") return false;
1059
+ if (!("lc" in value) || typeof value.lc !== "number") return false;
1060
+ if (!("notify" in value) || typeof value.notify !== "function") return false;
1061
+ if (!("off" in value) || typeof value.off !== "function") return false;
1062
+ if (!("subscribe" in value) || typeof value.subscribe !== "function") return false;
1063
+ if (!("value" in value)) return false;
1064
+ return true;
1065
+ }
1066
+
1067
+ //#endregion
1068
+ //#region ../fragno/dist/client/internal/fetcher-merge.js
1069
+ /**
1070
+ * Merge two fetcher configurations, with user config taking precedence.
1071
+ * If user provides a custom function, it takes full precedence.
1072
+ * Otherwise, deep merge RequestInit options.
1073
+ */
1074
+ function mergeFetcherConfigs(authorConfig, userConfig) {
1075
+ if (userConfig?.type === "function") return userConfig;
1076
+ if (!userConfig && authorConfig?.type === "function") return authorConfig;
1077
+ const authorOpts = authorConfig?.type === "options" ? authorConfig.options : {};
1078
+ const userOpts = userConfig?.type === "options" ? userConfig.options : {};
1079
+ if (Object.keys(authorOpts).length === 0 && Object.keys(userOpts).length === 0) return;
1080
+ return {
1081
+ type: "options",
1082
+ options: {
1083
+ ...authorOpts,
1084
+ ...userOpts,
1085
+ headers: mergeHeaders(authorOpts.headers, userOpts.headers)
1086
+ }
1087
+ };
1088
+ }
1089
+ /**
1090
+ * Merge headers from author and user configs.
1091
+ * User headers override author headers.
1092
+ */
1093
+ function mergeHeaders(author, user) {
1094
+ if (!author && !user) return;
1095
+ const merged = new Headers(author);
1096
+ new Headers(user).forEach((value, key) => merged.set(key, value));
1097
+ if (merged.keys().next().done) return;
1098
+ return merged;
1099
+ }
1100
+
1101
+ //#endregion
1102
+ //#region ../../node_modules/.pnpm/nanoevents@9.1.0/node_modules/nanoevents/index.js
1103
+ let createNanoEvents = () => ({
1104
+ emit(event, ...args) {
1105
+ for (let callbacks = this.events[event] || [], i = 0, length = callbacks.length; i < length; i++) callbacks[i](...args);
1106
+ },
1107
+ events: {},
1108
+ on(event, cb) {
1109
+ (this.events[event] ||= []).push(cb);
1110
+ return () => {
1111
+ this.events[event] = this.events[event]?.filter((i) => cb !== i);
1112
+ };
1113
+ }
1114
+ });
1115
+
1116
+ //#endregion
1117
+ //#region ../../node_modules/.pnpm/@nanostores+query@0.3.4_nanostores@1.1.0/node_modules/@nanostores/query/dist/nanoquery.js
1118
+ function defaultOnErrorRetry({ retryCount }) {
1119
+ return ~~((Math.random() + .5) * (1 << (retryCount < 8 ? retryCount : 8))) * 2e3;
1120
+ }
1121
+ const nanoqueryFactory = ([isAppVisible, visibilityChangeSubscribe, reconnectChangeSubscribe]) => {
1122
+ const nanoquery$1 = ({ cache = /* @__PURE__ */ new Map(), fetcher: globalFetcher, ...globalSettings } = {}) => {
1123
+ const events = createNanoEvents();
1124
+ let focus = true;
1125
+ visibilityChangeSubscribe(() => {
1126
+ focus = isAppVisible();
1127
+ focus && events.emit(FOCUS);
1128
+ });
1129
+ reconnectChangeSubscribe(() => events.emit(RECONNECT));
1130
+ const _revalidateOnInterval = /* @__PURE__ */ new Map(), _errorInvalidateTimeouts = /* @__PURE__ */ new Map(), _runningFetches = /* @__PURE__ */ new Map();
1131
+ let rewrittenSettings = {};
1132
+ const getCachedValueByKey = (key) => {
1133
+ const fromCache = cache.get(key);
1134
+ if (!fromCache) return [];
1135
+ return (fromCache.expires || 0) > getNow() ? [fromCache.data, fromCache.error] : [];
1136
+ };
1137
+ const runFetcher = async ([key, keyParts], store, settings) => {
1138
+ if (!focus) return;
1139
+ const set = (v) => {
1140
+ if (store.key === key) {
1141
+ store.set(v);
1142
+ events.emit(SET_CACHE, key, v, true);
1143
+ }
1144
+ };
1145
+ const setAsLoading = (prev) => {
1146
+ set({
1147
+ ...prev === void 0 ? {} : { data: prev },
1148
+ ...loading,
1149
+ promise: _runningFetches.get(key)
1150
+ });
1151
+ };
1152
+ let { dedupeTime = 4e3, cacheLifetime = Infinity, fetcher, onErrorRetry = defaultOnErrorRetry } = {
1153
+ ...settings,
1154
+ ...rewrittenSettings
1155
+ };
1156
+ if (cacheLifetime < dedupeTime) cacheLifetime = dedupeTime;
1157
+ const now = getNow();
1158
+ if (_runningFetches.has(key)) {
1159
+ if (!store.value.loading) setAsLoading(getCachedValueByKey(key)[0]);
1160
+ return;
1161
+ }
1162
+ let cachedValue, cachedError;
1163
+ const fromCache = cache.get(key);
1164
+ if (fromCache?.data !== void 0 || fromCache?.error) {
1165
+ [cachedValue, cachedError] = getCachedValueByKey(key);
1166
+ if ((fromCache.created || 0) + dedupeTime > now) {
1167
+ if (store.value.data != cachedValue || store.value.error != cachedError) set({
1168
+ ...notLoading,
1169
+ data: cachedValue,
1170
+ error: cachedError
1171
+ });
1172
+ return;
1173
+ }
1174
+ }
1175
+ const finishTask = startTask();
1176
+ try {
1177
+ clearTimeout(_errorInvalidateTimeouts.get(key));
1178
+ const promise = fetcher(...keyParts);
1179
+ _runningFetches.set(key, promise);
1180
+ setAsLoading(cachedValue);
1181
+ const res = await promise;
1182
+ cache.set(key, {
1183
+ data: res,
1184
+ created: getNow(),
1185
+ expires: getNow() + cacheLifetime
1186
+ });
1187
+ set({
1188
+ data: res,
1189
+ ...notLoading
1190
+ });
1191
+ } catch (error) {
1192
+ settings.onError?.(error);
1193
+ const retryCount = (cache.get(key)?.retryCount || 0) + 1;
1194
+ cache.set(key, {
1195
+ error,
1196
+ created: getNow(),
1197
+ expires: getNow() + cacheLifetime,
1198
+ retryCount
1199
+ });
1200
+ if (onErrorRetry) {
1201
+ const timer = onErrorRetry({
1202
+ error,
1203
+ key,
1204
+ retryCount
1205
+ });
1206
+ if (timer) _errorInvalidateTimeouts.set(key, setTimeout(() => {
1207
+ invalidateKeys(key);
1208
+ cache.set(key, { retryCount });
1209
+ }, timer));
1210
+ }
1211
+ set({
1212
+ data: store.value.data,
1213
+ error,
1214
+ ...notLoading
1215
+ });
1216
+ } finally {
1217
+ finishTask();
1218
+ _runningFetches.delete(key);
1219
+ }
1220
+ };
1221
+ const createFetcherStore = (keyInput, { fetcher = globalFetcher, ...fetcherSettings } = {}) => {
1222
+ if (!fetcher) throw new Error("You need to set up either global fetcher of fetcher in createFetcherStore");
1223
+ const fetcherStore = /* @__PURE__ */ map({ ...notLoading }), settings = {
1224
+ ...globalSettings,
1225
+ ...fetcherSettings,
1226
+ fetcher
1227
+ };
1228
+ fetcherStore._ = fetcherSymbol;
1229
+ fetcherStore.invalidate = () => {
1230
+ const { key } = fetcherStore;
1231
+ if (key) invalidateKeys(key);
1232
+ };
1233
+ fetcherStore.revalidate = () => {
1234
+ const { key } = fetcherStore;
1235
+ if (key) revalidateKeys(key);
1236
+ };
1237
+ fetcherStore.mutate = (data) => {
1238
+ const { key } = fetcherStore;
1239
+ if (key) mutateCache(key, data);
1240
+ };
1241
+ fetcherStore.fetch = async () => {
1242
+ let resolve;
1243
+ const promise = new Promise((r) => resolve = r);
1244
+ const unsub = fetcherStore.listen(({ error, data }) => {
1245
+ if (error !== void 0) resolve({ error });
1246
+ if (data !== void 0) resolve({ data });
1247
+ });
1248
+ return promise.finally(unsub);
1249
+ };
1250
+ let keysInternalUnsub, prevKey, prevKeyParts, keyUnsub, keyStore;
1251
+ let evtUnsubs = [];
1252
+ onStart(fetcherStore, () => {
1253
+ const firstRun = !keysInternalUnsub;
1254
+ [keyStore, keysInternalUnsub] = getKeyStore(keyInput);
1255
+ keyUnsub = keyStore.subscribe((currentKeys) => {
1256
+ if (currentKeys) {
1257
+ const [newKey, keyParts] = currentKeys;
1258
+ fetcherStore.key = newKey;
1259
+ runFetcher([newKey, keyParts], fetcherStore, settings);
1260
+ prevKey = newKey;
1261
+ prevKeyParts = keyParts;
1262
+ } else {
1263
+ fetcherStore.key = prevKey = prevKeyParts = void 0;
1264
+ fetcherStore.set({ ...notLoading });
1265
+ }
1266
+ });
1267
+ const currentKeyValue = keyStore.get();
1268
+ if (currentKeyValue) {
1269
+ [prevKey, prevKeyParts] = currentKeyValue;
1270
+ if (firstRun) handleNewListener();
1271
+ }
1272
+ const { revalidateInterval = 0, revalidateOnFocus, revalidateOnReconnect } = settings;
1273
+ const runRefetcher = () => {
1274
+ if (prevKey) runFetcher([prevKey, prevKeyParts], fetcherStore, settings);
1275
+ };
1276
+ if (revalidateInterval > 0) _revalidateOnInterval.set(keyInput, setInterval(runRefetcher, revalidateInterval));
1277
+ if (revalidateOnFocus) evtUnsubs.push(events.on(FOCUS, runRefetcher));
1278
+ if (revalidateOnReconnect) evtUnsubs.push(events.on(RECONNECT, runRefetcher));
1279
+ const cacheKeyChangeHandler = (keySelector) => {
1280
+ if (prevKey && testKeyAgainstSelector(prevKey, keySelector)) runFetcher([prevKey, prevKeyParts], fetcherStore, settings);
1281
+ };
1282
+ evtUnsubs.push(events.on(INVALIDATE_KEYS, cacheKeyChangeHandler), events.on(REVALIDATE_KEYS, cacheKeyChangeHandler), events.on(SET_CACHE, (keySelector, data, full) => {
1283
+ if (prevKey && testKeyAgainstSelector(prevKey, keySelector) && fetcherStore.value !== data && fetcherStore.value.data !== data) fetcherStore.set(full ? data : {
1284
+ data,
1285
+ ...notLoading
1286
+ });
1287
+ }));
1288
+ });
1289
+ const handleNewListener = () => {
1290
+ if (prevKey && prevKeyParts) runFetcher([prevKey, prevKeyParts], fetcherStore, settings);
1291
+ };
1292
+ const originListen = fetcherStore.listen;
1293
+ fetcherStore.listen = (listener) => {
1294
+ const unsub = originListen(listener);
1295
+ listener(fetcherStore.value);
1296
+ handleNewListener();
1297
+ return unsub;
1298
+ };
1299
+ onStop(fetcherStore, () => {
1300
+ fetcherStore.value = { ...notLoading };
1301
+ keysInternalUnsub?.();
1302
+ evtUnsubs.forEach((fn) => fn());
1303
+ evtUnsubs = [];
1304
+ keyUnsub?.();
1305
+ clearInterval(_revalidateOnInterval.get(keyInput));
1306
+ });
1307
+ return fetcherStore;
1308
+ };
1309
+ const iterOverCache = (keySelector, cb) => {
1310
+ for (const key of cache.keys()) if (testKeyAgainstSelector(key, keySelector)) cb(key);
1311
+ };
1312
+ const invalidateKeys = (keySelector) => {
1313
+ iterOverCache(keySelector, (key) => {
1314
+ cache.delete(key);
1315
+ });
1316
+ events.emit(INVALIDATE_KEYS, keySelector);
1317
+ };
1318
+ const revalidateKeys = (keySelector) => {
1319
+ iterOverCache(keySelector, (key) => {
1320
+ const cached = cache.get(key);
1321
+ if (cached) cache.set(key, {
1322
+ ...cached,
1323
+ created: -Infinity
1324
+ });
1325
+ });
1326
+ events.emit(REVALIDATE_KEYS, keySelector);
1327
+ };
1328
+ const mutateCache = (keySelector, data) => {
1329
+ iterOverCache(keySelector, (key) => {
1330
+ if (data === void 0) cache.delete(key);
1331
+ else cache.set(key, {
1332
+ data,
1333
+ created: getNow(),
1334
+ expires: getNow() + (globalSettings.cacheLifetime ?? 8e3)
1335
+ });
1336
+ });
1337
+ events.emit(SET_CACHE, keySelector, data);
1338
+ };
1339
+ function createMutatorStore(mutator, opts) {
1340
+ const { throttleCalls, onError } = opts ?? {
1341
+ throttleCalls: true,
1342
+ onError: globalSettings?.onError
1343
+ };
1344
+ const mutate = async (data) => {
1345
+ if (throttleCalls && store.value?.loading) return;
1346
+ const newMutator = rewrittenSettings.fetcher ?? mutator;
1347
+ const keysToInvalidate = [], keysToRevalidate = [];
1348
+ const safeKeySet = (k, v) => {
1349
+ if (store.lc) store.setKey(k, v);
1350
+ };
1351
+ try {
1352
+ store.set({
1353
+ error: void 0,
1354
+ data: void 0,
1355
+ mutate,
1356
+ ...loading
1357
+ });
1358
+ const result = await newMutator({
1359
+ data,
1360
+ invalidate: (key) => {
1361
+ keysToInvalidate.push(key);
1362
+ },
1363
+ revalidate: (key) => {
1364
+ keysToRevalidate.push(key);
1365
+ },
1366
+ getCacheUpdater: (key, shouldRevalidate = true) => [(newVal) => {
1367
+ mutateCache(key, newVal);
1368
+ if (shouldRevalidate) keysToRevalidate.push(key);
1369
+ }, cache.get(key)?.data]
1370
+ });
1371
+ safeKeySet("data", result);
1372
+ return result;
1373
+ } catch (error) {
1374
+ onError?.(error);
1375
+ safeKeySet("error", error);
1376
+ store.setKey("error", error);
1377
+ } finally {
1378
+ safeKeySet("loading", false);
1379
+ keysToInvalidate.forEach(invalidateKeys);
1380
+ keysToRevalidate.forEach(revalidateKeys);
1381
+ }
1382
+ };
1383
+ const store = /* @__PURE__ */ map({
1384
+ mutate,
1385
+ ...notLoading
1386
+ });
1387
+ onStop(store, () => store.set({
1388
+ mutate,
1389
+ ...notLoading
1390
+ }));
1391
+ store.mutate = mutate;
1392
+ return store;
1393
+ }
1394
+ const __unsafeOverruleSettings = (data) => {
1395
+ console.warn(`You should only use __unsafeOverruleSettings in test environment`);
1396
+ rewrittenSettings = data;
1397
+ };
1398
+ return [
1399
+ createFetcherStore,
1400
+ createMutatorStore,
1401
+ {
1402
+ __unsafeOverruleSettings,
1403
+ invalidateKeys,
1404
+ revalidateKeys,
1405
+ mutateCache
1406
+ }
1407
+ ];
1408
+ };
1409
+ function isSomeKey(key) {
1410
+ return typeof key === "string" || typeof key === "number" || key === true;
1411
+ }
1412
+ const getKeyStore = (keys) => {
1413
+ if (isSomeKey(keys)) return [/* @__PURE__ */ atom(["" + keys, [keys]]), () => {}];
1414
+ const keyParts = [];
1415
+ const $key = /* @__PURE__ */ atom(null);
1416
+ const keysAsStoresToIndexes = /* @__PURE__ */ new Map();
1417
+ const setKeyStoreValue = () => {
1418
+ if (keyParts.some((v) => v === null || v === void 0 || v === false)) $key.set(null);
1419
+ else $key.set([keyParts.join(""), keyParts]);
1420
+ };
1421
+ for (let i = 0; i < keys.length; i++) {
1422
+ const keyOrStore = keys[i];
1423
+ if (isSomeKey(keyOrStore)) keyParts.push(keyOrStore);
1424
+ else {
1425
+ keyParts.push(null);
1426
+ keysAsStoresToIndexes.set(keyOrStore, i);
1427
+ }
1428
+ }
1429
+ const storesAsArray = [...keysAsStoresToIndexes.keys()];
1430
+ const $storeKeys = /* @__PURE__ */ batched(storesAsArray, (...storeValues) => {
1431
+ for (let i = 0; i < storeValues.length; i++) {
1432
+ const store = storesAsArray[i], partIndex = keysAsStoresToIndexes.get(store);
1433
+ keyParts[partIndex] = store._ === fetcherSymbol ? store.value && "data" in store.value ? store.key : null : storeValues[i];
1434
+ }
1435
+ setKeyStoreValue();
1436
+ });
1437
+ setKeyStoreValue();
1438
+ return [$key, $storeKeys.subscribe(noop)];
1439
+ };
1440
+ function noop() {}
1441
+ const FOCUS = 1, RECONNECT = 2, INVALIDATE_KEYS = 3, REVALIDATE_KEYS = 4, SET_CACHE = 5;
1442
+ const testKeyAgainstSelector = (key, selector) => {
1443
+ if (Array.isArray(selector)) return selector.includes(key);
1444
+ else if (typeof selector === "function") return selector(key);
1445
+ else return key === selector;
1446
+ };
1447
+ const getNow = () => (/* @__PURE__ */ new Date()).getTime();
1448
+ const fetcherSymbol = Symbol();
1449
+ const loading = { loading: true }, notLoading = { loading: false };
1450
+ return nanoquery$1;
1451
+ };
1452
+ const subscribe = (name, fn) => {
1453
+ if (!(typeof window === "undefined")) addEventListener(name, fn);
1454
+ };
1455
+ const nanoquery = nanoqueryFactory([
1456
+ () => !document.hidden,
1457
+ (cb) => subscribe("visibilitychange", cb),
1458
+ (cb) => subscribe("online", cb)
1459
+ ]);
1460
+
1461
+ //#endregion
1462
+ //#region ../fragno/dist/client/client.js
1463
+ /**
1464
+ * Symbols used to identify hook types
1465
+ */
1466
+ const GET_HOOK_SYMBOL = Symbol("fragno-get-hook");
1467
+ const MUTATOR_HOOK_SYMBOL = Symbol("fragno-mutator-hook");
1468
+ const STORE_SYMBOL = Symbol("fragno-store");
1469
+ /**
1470
+ * Check if a value contains files that should be sent as FormData.
1471
+ * @internal
1472
+ */
1473
+ function containsFiles(value) {
1474
+ if (value instanceof File || value instanceof Blob) return true;
1475
+ if (value instanceof FormData) return true;
1476
+ if (typeof value === "object" && value !== null) return Object.values(value).some((v) => v instanceof File || v instanceof Blob || v instanceof FormData);
1477
+ return false;
1478
+ }
1479
+ /**
1480
+ * Convert an object containing files to FormData.
1481
+ * Handles nested File/Blob values by appending them directly.
1482
+ * Other values are JSON-stringified.
1483
+ * @internal
1484
+ */
1485
+ function toFormData(value) {
1486
+ const formData = new FormData();
1487
+ for (const [key, val] of Object.entries(value)) if (val instanceof File) formData.append(key, val, val.name);
1488
+ else if (val instanceof Blob) formData.append(key, val);
1489
+ else if (val !== void 0 && val !== null) formData.append(key, typeof val === "string" ? val : JSON.stringify(val));
1490
+ return formData;
1491
+ }
1492
+ /**
1493
+ * Prepare request body and headers for sending.
1494
+ * Handles FormData (file uploads) vs JSON data.
1495
+ * @internal
1496
+ */
1497
+ function prepareRequestBody(body) {
1498
+ if (body === void 0) return { body: void 0 };
1499
+ if (body instanceof FormData) return { body };
1500
+ if (body instanceof File) {
1501
+ const formData = new FormData();
1502
+ formData.append("file", body, body.name);
1503
+ return { body: formData };
1504
+ }
1505
+ if (body instanceof Blob) {
1506
+ const formData = new FormData();
1507
+ formData.append("file", body);
1508
+ return { body: formData };
1509
+ }
1510
+ if (typeof body === "object" && body !== null && containsFiles(body)) return { body: toFormData(body) };
1511
+ return {
1512
+ body: JSON.stringify(body),
1513
+ headers: { "Content-Type": "application/json" }
1514
+ };
1515
+ }
1516
+ /**
1517
+ * Merge request headers from multiple sources.
1518
+ * Returns undefined if there are no headers to merge.
1519
+ * @internal
1520
+ */
1521
+ function mergeRequestHeaders(...headerSources) {
1522
+ const result = {};
1523
+ let hasHeaders = false;
1524
+ for (const source of headerSources) {
1525
+ if (!source) continue;
1526
+ if (source instanceof Headers) for (const [key, value] of source.entries()) {
1527
+ result[key] = value;
1528
+ hasHeaders = true;
1529
+ }
1530
+ else if (Array.isArray(source)) for (const [key, value] of source) {
1531
+ result[key] = value;
1532
+ hasHeaders = true;
1533
+ }
1534
+ else for (const [key, value] of Object.entries(source)) {
1535
+ result[key] = value;
1536
+ hasHeaders = true;
1537
+ }
1538
+ }
1539
+ return hasHeaders ? result : void 0;
1540
+ }
1541
+ /**
1542
+ * @internal
1543
+ */
1544
+ function buildUrl(config, params) {
1545
+ const { baseUrl = "", mountRoute, path } = config;
1546
+ const { pathParams, queryParams } = params ?? {};
1547
+ const normalizedPathParams = unwrapObject(pathParams);
1548
+ const normalizedQueryParams = unwrapObject(queryParams) ?? {};
1549
+ const filteredQueryParams = Object.fromEntries(Object.entries(normalizedQueryParams).filter(([_, value]) => value !== void 0));
1550
+ const searchParams = new URLSearchParams(filteredQueryParams);
1551
+ return `${baseUrl}${mountRoute}${buildPath(path, normalizedPathParams ?? {})}${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
1552
+ }
1553
+ /**
1554
+ * This method returns an array, which can be passed directly to nanostores.
1555
+ *
1556
+ * The returned array is always: path, pathParams (In order they appear in the path), queryParams (In alphabetical order)
1557
+ * Missing pathParams are replaced with "<missing>".
1558
+ * Atoms with undefined values are wrapped in computed atoms that map undefined to "" to avoid nanoquery treating the key as incomplete.
1559
+ * @param path
1560
+ * @param params
1561
+ * @returns
1562
+ * @internal
1563
+ */
1564
+ function getCacheKey(method, path, params) {
1565
+ if (!params) return [method, path];
1566
+ const { pathParams, queryParams } = params;
1567
+ const pathParamValues = extractPathParams(path).map((name) => pathParams?.[name] ?? "<missing>");
1568
+ const queryParamValues = queryParams ? Object.keys(queryParams).sort().map((key) => {
1569
+ const value = queryParams[key];
1570
+ if (value && typeof value === "object" && "get" in value) return /* @__PURE__ */ computed(value, (v) => v ?? "");
1571
+ return value ?? "";
1572
+ }) : [];
1573
+ return [
1574
+ method,
1575
+ path,
1576
+ ...pathParamValues,
1577
+ ...queryParamValues
1578
+ ];
1579
+ }
1580
+ function isStreamingResponse(response) {
1581
+ const contentType = parseContentType(response.headers.get("content-type"));
1582
+ if (!contentType) return false;
1583
+ if (!(response.headers.get("transfer-encoding") === "chunked")) return false;
1584
+ if (contentType.subtype === "octet-stream") return "octet-stream";
1585
+ if (contentType.subtype === "x-ndjson") return "ndjson";
1586
+ return false;
1587
+ }
1588
+ /**
1589
+ * @internal
1590
+ */
1591
+ function isGetHook(hook) {
1592
+ return typeof hook === "object" && hook !== null && GET_HOOK_SYMBOL in hook && hook[GET_HOOK_SYMBOL] === true;
1593
+ }
1594
+ /**
1595
+ * @internal
1596
+ */
1597
+ function isMutatorHook(hook) {
1598
+ return typeof hook === "object" && hook !== null && MUTATOR_HOOK_SYMBOL in hook && hook[MUTATOR_HOOK_SYMBOL] === true;
1599
+ }
1600
+ /**
1601
+ * @internal
1602
+ */
1603
+ function isStore(obj) {
1604
+ return typeof obj === "object" && obj !== null && STORE_SYMBOL in obj && obj[STORE_SYMBOL] === true;
1605
+ }
1606
+ var ClientBuilder = class {
1607
+ #publicConfig;
1608
+ #fragmentConfig;
1609
+ #fetcherConfig;
1610
+ #cache = /* @__PURE__ */ new Map();
1611
+ #createFetcherStore;
1612
+ #createMutatorStore;
1613
+ #invalidateKeys;
1614
+ constructor(publicConfig, fragmentConfig) {
1615
+ this.#publicConfig = publicConfig;
1616
+ this.#fragmentConfig = fragmentConfig;
1617
+ this.#fetcherConfig = publicConfig.fetcherConfig;
1618
+ const [createFetcherStore, createMutatorStore, { invalidateKeys }] = nanoquery({ cache: this.#cache });
1619
+ this.#createFetcherStore = createFetcherStore;
1620
+ this.#createMutatorStore = createMutatorStore;
1621
+ this.#invalidateKeys = invalidateKeys;
1622
+ }
1623
+ get cacheEntries() {
1624
+ return Object.fromEntries(this.#cache.entries());
1625
+ }
1626
+ createStore(obj) {
1627
+ return {
1628
+ obj,
1629
+ [STORE_SYMBOL]: true
1630
+ };
1631
+ }
1632
+ /**
1633
+ * Build a URL for a custom backend call using the configured baseUrl and mountRoute.
1634
+ * Useful for fragment authors who need to make custom fetch calls.
1635
+ */
1636
+ buildUrl(path, params) {
1637
+ return buildUrl({
1638
+ baseUrl: this.#publicConfig.baseUrl ?? "",
1639
+ mountRoute: getMountRoute(this.#fragmentConfig),
1640
+ path
1641
+ }, {
1642
+ pathParams: params?.path,
1643
+ queryParams: params?.query
1644
+ });
1645
+ }
1646
+ /**
1647
+ * Get the configured fetcher function for custom backend calls.
1648
+ * Returns fetch with merged options applied.
1649
+ */
1650
+ getFetcher() {
1651
+ return {
1652
+ fetcher: this.#getFetcher(),
1653
+ defaultOptions: this.#getFetcherOptions()
1654
+ };
1655
+ }
1656
+ #getFetcher() {
1657
+ if (this.#fetcherConfig?.type === "function") return this.#fetcherConfig.fetcher;
1658
+ return fetch;
1659
+ }
1660
+ #getFetcherOptions() {
1661
+ if (this.#fetcherConfig?.type === "options") return this.#fetcherConfig.options;
1662
+ }
1663
+ createHook(path, options) {
1664
+ const route = this.#fragmentConfig.routes.find((r) => r.path === path && r.method === "GET" && r.outputSchema !== void 0);
1665
+ if (!route) throw new Error(`Route '${path}' not found or is not a GET route with an output schema.`);
1666
+ return this.#createRouteQueryHook(route, options);
1667
+ }
1668
+ createMutator(method, path, onInvalidate) {
1669
+ const route = this.#fragmentConfig.routes.find((r) => r.method !== "GET" && r.path === path && r.method === method);
1670
+ if (!route) throw new Error(`Route '${path}' not found or is a GET route with an input and output schema.`);
1671
+ return this.#createRouteQueryMutator(route, onInvalidate);
1672
+ }
1673
+ #createRouteQueryHook(route, options = {}) {
1674
+ if (route.method !== "GET") throw new Error(`Only GET routes are supported for hooks. Route '${route.path}' is a ${route.method} route.`);
1675
+ if (!route.outputSchema) throw new Error(`Output schema is required for GET routes. Route '${route.path}' has no output schema.`);
1676
+ const baseUrl = this.#publicConfig.baseUrl ?? "";
1677
+ const mountRoute = getMountRoute(this.#fragmentConfig);
1678
+ const fetcher = this.#getFetcher();
1679
+ const fetcherOptions = this.#getFetcherOptions();
1680
+ async function callServerSideHandler(params) {
1681
+ const { pathParams, queryParams } = params ?? {};
1682
+ const normalizedPathParams = unwrapObject(pathParams);
1683
+ const normalizedQueryParams = unwrapObject(queryParams) ?? {};
1684
+ const filteredQueryParams = Object.fromEntries(Object.entries(normalizedQueryParams).filter(([_, value]) => value !== void 0));
1685
+ const searchParams = new URLSearchParams(filteredQueryParams);
1686
+ return await route.handler(RequestInputContext.fromSSRContext({
1687
+ method: route.method,
1688
+ path: route.path,
1689
+ pathParams: normalizedPathParams,
1690
+ searchParams
1691
+ }), new RequestOutputContext(route.outputSchema));
1692
+ }
1693
+ async function executeQuery(params) {
1694
+ const { pathParams, queryParams } = params ?? {};
1695
+ if (typeof window === "undefined") return task(async () => callServerSideHandler({
1696
+ pathParams,
1697
+ queryParams
1698
+ }));
1699
+ const url = buildUrl({
1700
+ baseUrl,
1701
+ mountRoute,
1702
+ path: route.path
1703
+ }, {
1704
+ pathParams,
1705
+ queryParams
1706
+ });
1707
+ let response;
1708
+ try {
1709
+ response = fetcherOptions ? await fetcher(url, fetcherOptions) : await fetcher(url);
1710
+ } catch (error) {
1711
+ throw FragnoClientFetchError.fromUnknownFetchError(error);
1712
+ }
1713
+ if (!response.ok) throw await FragnoClientApiError.fromResponse(response);
1714
+ return response;
1715
+ }
1716
+ return {
1717
+ route,
1718
+ store: (args) => {
1719
+ const { path, query } = args ?? {};
1720
+ const key = getCacheKey(route.method, route.path, {
1721
+ pathParams: path,
1722
+ queryParams: query
1723
+ });
1724
+ const store = this.#createFetcherStore(key, {
1725
+ fetcher: async () => {
1726
+ if (SSR_ENABLED) {
1727
+ const initialData = getInitialData(key.map((d) => typeof d === "string" ? d : d.get()).join(""));
1728
+ if (initialData) return initialData;
1729
+ }
1730
+ const response = await executeQuery({
1731
+ pathParams: path,
1732
+ queryParams: query
1733
+ });
1734
+ const isStreaming = isStreamingResponse(response);
1735
+ if (!isStreaming) return response.json();
1736
+ if (typeof window === "undefined") return [];
1737
+ if (isStreaming === "ndjson") {
1738
+ const { firstItem } = await handleNdjsonStreamingFirstItem(response, {
1739
+ setData: (value) => {
1740
+ store.set({
1741
+ ...store.get(),
1742
+ loading: !(Array.isArray(value) && value.length > 0),
1743
+ data: value
1744
+ });
1745
+ },
1746
+ setError: (value) => {
1747
+ store.set({
1748
+ ...store.get(),
1749
+ error: value
1750
+ });
1751
+ }
1752
+ });
1753
+ return [firstItem];
1754
+ }
1755
+ if (isStreaming === "octet-stream") throw new Error("Octet-stream streaming is not supported.");
1756
+ throw new Error("Unreachable");
1757
+ },
1758
+ onErrorRetry: options?.onErrorRetry,
1759
+ dedupeTime: Infinity
1760
+ });
1761
+ if (typeof window === "undefined") addStore(store);
1762
+ return store;
1763
+ },
1764
+ query: async (args) => {
1765
+ const { path, query } = args ?? {};
1766
+ const response = await executeQuery({
1767
+ pathParams: path,
1768
+ queryParams: query
1769
+ });
1770
+ const isStreaming = isStreamingResponse(response);
1771
+ if (!isStreaming) return await response.json();
1772
+ if (isStreaming === "ndjson") {
1773
+ const { streamingPromise } = await handleNdjsonStreamingFirstItem(response);
1774
+ return await streamingPromise;
1775
+ }
1776
+ if (isStreaming === "octet-stream") throw new Error("Octet-stream streaming is not supported.");
1777
+ throw new Error("Unreachable");
1778
+ },
1779
+ [GET_HOOK_SYMBOL]: true
1780
+ };
1781
+ }
1782
+ #createRouteQueryMutator(route, onInvalidate = (invalidate, params) => invalidate("GET", route.path, params)) {
1783
+ const method = route.method;
1784
+ const baseUrl = this.#publicConfig.baseUrl ?? "";
1785
+ const mountRoute = getMountRoute(this.#fragmentConfig);
1786
+ const fetcher = this.#getFetcher();
1787
+ const fetcherOptions = this.#getFetcherOptions();
1788
+ async function executeMutateQuery({ body, path, query }) {
1789
+ if (typeof window === "undefined") return task(async () => route.handler(RequestInputContext.fromSSRContext({
1790
+ inputSchema: route.inputSchema,
1791
+ method,
1792
+ path: route.path,
1793
+ pathParams: path ?? {},
1794
+ searchParams: new URLSearchParams(query),
1795
+ body
1796
+ }), new RequestOutputContext(route.outputSchema)));
1797
+ const url = buildUrl({
1798
+ baseUrl,
1799
+ mountRoute,
1800
+ path: route.path
1801
+ }, {
1802
+ pathParams: path,
1803
+ queryParams: query
1804
+ });
1805
+ let response;
1806
+ try {
1807
+ const { body: preparedBody, headers: bodyHeaders } = prepareRequestBody(body);
1808
+ const mergedHeaders = mergeRequestHeaders(fetcherOptions?.headers, bodyHeaders);
1809
+ response = await fetcher(url, {
1810
+ ...fetcherOptions,
1811
+ method,
1812
+ body: preparedBody,
1813
+ ...mergedHeaders ? { headers: mergedHeaders } : {}
1814
+ });
1815
+ } catch (error) {
1816
+ throw FragnoClientFetchError.fromUnknownFetchError(error);
1817
+ }
1818
+ if (!response.ok) throw await FragnoClientApiError.fromResponse(response);
1819
+ return response;
1820
+ }
1821
+ const mutatorStore = this.#createMutatorStore(async ({ data }) => {
1822
+ if (typeof window === "undefined") {}
1823
+ const { body, path, query } = data;
1824
+ if (typeof body === "undefined" && route.inputSchema !== void 0) throw new Error("Body is required.");
1825
+ const response = await executeMutateQuery({
1826
+ body,
1827
+ path,
1828
+ query
1829
+ });
1830
+ onInvalidate(this.#invalidate.bind(this), {
1831
+ pathParams: path ?? {},
1832
+ queryParams: query
1833
+ });
1834
+ if (response.status === 201 || response.status === 204) return;
1835
+ const isStreaming = isStreamingResponse(response);
1836
+ if (!isStreaming) return response.json();
1837
+ if (typeof window === "undefined") return [];
1838
+ if (isStreaming === "ndjson") {
1839
+ const { firstItem } = await handleNdjsonStreamingFirstItem(response, {
1840
+ setData: (value) => {
1841
+ mutatorStore.set({
1842
+ ...mutatorStore.get(),
1843
+ loading: !(Array.isArray(value) && value.length > 0),
1844
+ data: value
1845
+ });
1846
+ },
1847
+ setError: (value) => {
1848
+ mutatorStore.set({
1849
+ ...mutatorStore.get(),
1850
+ error: value
1851
+ });
1852
+ }
1853
+ });
1854
+ return [firstItem];
1855
+ }
1856
+ if (isStreaming === "octet-stream") throw new Error("Octet-stream streaming is not supported.");
1857
+ throw new Error("Unreachable");
1858
+ }, { onError: (error) => {
1859
+ console.error("Error in mutatorStore", error);
1860
+ } });
1861
+ const mutateQuery = async (data) => {
1862
+ const { body, path, query } = data;
1863
+ if (typeof body === "undefined" && route.inputSchema !== void 0) throw new Error("Body is required for mutateQuery");
1864
+ const response = await executeMutateQuery({
1865
+ body,
1866
+ path,
1867
+ query
1868
+ });
1869
+ if (response.status === 201 || response.status === 204) return;
1870
+ const isStreaming = isStreamingResponse(response);
1871
+ if (!isStreaming) return response.json();
1872
+ if (isStreaming === "ndjson") {
1873
+ const { streamingPromise } = await handleNdjsonStreamingFirstItem(response);
1874
+ return await streamingPromise;
1875
+ }
1876
+ if (isStreaming === "octet-stream") throw new Error("Octet-stream streaming is not supported for mutations");
1877
+ throw new Error("Unreachable");
1878
+ };
1879
+ return {
1880
+ route,
1881
+ mutateQuery,
1882
+ mutatorStore,
1883
+ [MUTATOR_HOOK_SYMBOL]: true
1884
+ };
1885
+ }
1886
+ #invalidate(method, path, params) {
1887
+ const prefix = getCacheKey(method, path, {
1888
+ pathParams: params?.pathParams,
1889
+ queryParams: params?.queryParams
1890
+ }).map((k) => typeof k === "string" ? k : k.get()).join("");
1891
+ this.#invalidateKeys((key) => key.startsWith(prefix));
1892
+ }
1893
+ };
1894
+ /**
1895
+ * Create a client builder for fragments using the new fragment definition API.
1896
+ * This is the same as createClientBuilder but works with FragmentDefinition.
1897
+ */
1898
+ function createClientBuilder(definition, publicConfig, routesOrFactories, authorFetcherConfig) {
1899
+ const routes = resolveRouteFactories({
1900
+ config: {},
1901
+ deps: {},
1902
+ services: {},
1903
+ serviceDeps: {}
1904
+ }, routesOrFactories);
1905
+ const fragmentConfig = {
1906
+ name: definition.name,
1907
+ routes
1908
+ };
1909
+ const mountRoute = publicConfig.mountRoute ?? `/${definition.name}`;
1910
+ const mergedFetcherConfig = mergeFetcherConfigs(authorFetcherConfig, publicConfig.fetcherConfig);
1911
+ return new ClientBuilder({
1912
+ ...publicConfig,
1913
+ mountRoute,
1914
+ fetcherConfig: mergedFetcherConfig
1915
+ }, fragmentConfig);
1916
+ }
1917
+
1918
+ //#endregion
1919
+ //#region src/index.ts
1920
+ const exampleFragmentDefinition = defineFragment("example-fragment").extend((x) => x).provideHooks(({ defineHook, config }) => ({ onNoteCreated: defineHook(async function(payload) {
1921
+ await config.onNoteCreated?.(this.idempotencyKey, payload);
1922
+ }) })).providesBaseService(() => {}).build();
1923
+ const exampleRoutesFactory = defineRoutes(exampleFragmentDefinition).create(({ services, defineRoute }) => {
1924
+ return [
1925
+ defineRoute({
1926
+ method: "GET",
1927
+ path: "/notes",
1928
+ queryParameters: ["userId"],
1929
+ outputSchema: z.array(z.object({
1930
+ id: z.string(),
1931
+ content: z.string(),
1932
+ userId: z.string(),
1933
+ userName: z.string(),
1934
+ createdAt: z.date()
1935
+ })),
1936
+ handler: () => {}
1937
+ }),
1938
+ defineRoute({
1939
+ method: "POST",
1940
+ path: "/notes",
1941
+ inputSchema: z.object({
1942
+ content: z.string(),
1943
+ userEmail: z.string()
1944
+ }),
1945
+ outputSchema: z.object({
1946
+ id: z.string(),
1947
+ content: z.string(),
1948
+ userId: z.string(),
1949
+ createdAt: z.date()
1950
+ }),
1951
+ errorCodes: [],
1952
+ handler: () => {}
1953
+ }),
1954
+ defineRoute({
1955
+ method: "PATCH",
1956
+ path: "/notes/:noteId",
1957
+ inputSchema: z.object({ content: z.string() }),
1958
+ outputSchema: z.object({
1959
+ id: z.string(),
1960
+ content: z.string(),
1961
+ userId: z.string(),
1962
+ createdAt: z.date()
1963
+ }),
1964
+ errorCodes: [],
1965
+ handler: () => {}
1966
+ })
1967
+ ];
1968
+ });
1969
+ function createExampleFragment(config = {}, options) {
1970
+ return {};
1971
+ }
1972
+ function createExampleFragmentClients(fragnoConfig) {
1973
+ const b = createClientBuilder(exampleFragmentDefinition, fragnoConfig, [exampleRoutesFactory]);
1974
+ return {
1975
+ useNotes: b.createHook("/notes"),
1976
+ useCreateNote: b.createMutator("POST", "/notes")
1977
+ };
1978
+ }
1979
+
1980
+ //#endregion
1981
+ export { isStore as a, isMutatorHook as i, createExampleFragmentClients as n, isReadableAtom as o, isGetHook as r, atom as s, createExampleFragment as t };
1982
+ //# sourceMappingURL=src-vdNJUbjT.js.map