@lovrozagar/honey 0.6.8 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (674) hide show
  1. package/README.md +514 -192
  2. package/bin/honey.js +25 -0
  3. package/dist/accepts.d.ts +7 -1
  4. package/dist/accepts.d.ts.map +1 -1
  5. package/dist/accepts.js +126 -0
  6. package/dist/accepts.js.map +1 -0
  7. package/dist/body-kind.d.ts +26 -0
  8. package/dist/body-kind.d.ts.map +1 -0
  9. package/dist/body-kind.js +70 -0
  10. package/dist/body-kind.js.map +1 -0
  11. package/dist/body-limit.d.ts +5 -1
  12. package/dist/body-limit.d.ts.map +1 -1
  13. package/dist/body-limit.js +126 -0
  14. package/dist/body-limit.js.map +1 -0
  15. package/dist/build/index.d.ts +19 -3
  16. package/dist/build/index.d.ts.map +1 -1
  17. package/dist/build/index.js +173 -0
  18. package/dist/build/index.js.map +1 -0
  19. package/dist/cli-args.d.ts +33 -0
  20. package/dist/cli-args.d.ts.map +1 -0
  21. package/dist/cli-args.js +102 -0
  22. package/dist/cli-args.js.map +1 -0
  23. package/dist/cli-go/auth.go +26 -0
  24. package/dist/cli-go/config.go +192 -0
  25. package/dist/cli-go/errors.go +75 -0
  26. package/dist/cli-go/multipart.go +79 -0
  27. package/dist/cli-go/output.go +163 -0
  28. package/dist/cli-go/root.go +30 -0
  29. package/dist/cli-go/stream.go +88 -0
  30. package/dist/cli-go/version.go +5 -0
  31. package/dist/cli.d.ts +1 -1
  32. package/dist/cli.js +209 -0
  33. package/dist/cli.js.map +1 -0
  34. package/dist/client/defaults.js +48 -0
  35. package/dist/client/defaults.js.map +1 -0
  36. package/dist/client/error.d.ts +35 -0
  37. package/dist/client/error.d.ts.map +1 -1
  38. package/dist/client/error.js +71 -0
  39. package/dist/client/error.js.map +1 -0
  40. package/dist/client/http.d.ts +67 -8
  41. package/dist/client/http.d.ts.map +1 -1
  42. package/dist/client/http.js +571 -0
  43. package/dist/client/http.js.map +1 -0
  44. package/dist/client/index.d.ts +3 -2
  45. package/dist/client/index.d.ts.map +1 -1
  46. package/dist/client/index.js +95 -0
  47. package/dist/client/index.js.map +1 -0
  48. package/dist/client/path.d.ts +26 -0
  49. package/dist/client/path.d.ts.map +1 -0
  50. package/dist/client/path.js +163 -0
  51. package/dist/client/path.js.map +1 -0
  52. package/dist/client/redirect-policy.d.ts +12 -0
  53. package/dist/client/redirect-policy.d.ts.map +1 -0
  54. package/dist/client/redirect-policy.js +20 -0
  55. package/dist/client/redirect-policy.js.map +1 -0
  56. package/dist/client/sdk.d.ts +36 -0
  57. package/dist/client/sdk.d.ts.map +1 -1
  58. package/dist/client/sdk.js +292 -0
  59. package/dist/client/sdk.js.map +1 -0
  60. package/dist/client/sse.d.ts +13 -0
  61. package/dist/client/sse.d.ts.map +1 -1
  62. package/dist/client/sse.js +129 -0
  63. package/dist/client/sse.js.map +1 -0
  64. package/dist/client/types.js +2 -0
  65. package/dist/client/types.js.map +1 -0
  66. package/dist/client/ws.d.ts +9 -2
  67. package/dist/client/ws.d.ts.map +1 -1
  68. package/dist/client/ws.js +112 -0
  69. package/dist/client/ws.js.map +1 -0
  70. package/dist/client-go/errors.go +236 -0
  71. package/dist/client-go/export.go +44 -0
  72. package/dist/client-go/invalidation.go +371 -0
  73. package/dist/client-go/nullable.go +62 -0
  74. package/dist/client-go/realtime.go +354 -0
  75. package/dist/client-go/result.go +20 -0
  76. package/dist/client-go/runtime.go +975 -0
  77. package/dist/client-go/sse.go +159 -0
  78. package/dist/client-go/transport.go +495 -0
  79. package/dist/client-go/ws.go +128 -0
  80. package/dist/client-info.d.ts +36 -0
  81. package/dist/client-info.d.ts.map +1 -0
  82. package/dist/client-info.js +53 -0
  83. package/dist/client-info.js.map +1 -0
  84. package/dist/client-mcp/README.md +10 -0
  85. package/dist/client-mcp/server.ts +221 -0
  86. package/dist/client-mcp/types.ts +19 -0
  87. package/dist/client-python/_errors.py +115 -0
  88. package/dist/client-python/_invalidation.py +494 -0
  89. package/dist/client-python/_realtime.py +179 -0
  90. package/dist/client-python/_runtime.py +860 -0
  91. package/dist/client-python/_sse.py +155 -0
  92. package/dist/client-python/_transport.py +366 -0
  93. package/dist/client-python/_ws.py +159 -0
  94. package/dist/client-python/py.typed +0 -0
  95. package/dist/client-rust/errors.rs +220 -0
  96. package/dist/client-rust/invalidation.rs +412 -0
  97. package/dist/client-rust/invalidation_sync.rs +93 -0
  98. package/dist/client-rust/nullable.rs +17 -0
  99. package/dist/client-rust/realtime.rs +702 -0
  100. package/dist/client-rust/result.rs +22 -0
  101. package/dist/client-rust/runtime.rs +980 -0
  102. package/dist/client-rust/runtime_sync.rs +484 -0
  103. package/dist/client-rust/sse.rs +188 -0
  104. package/dist/client-rust/ws.rs +167 -0
  105. package/dist/codegen-go-cli.d.ts.map +1 -1
  106. package/dist/codegen-go-cli.js +964 -0
  107. package/dist/codegen-go-cli.js.map +1 -0
  108. package/dist/codegen-go.d.ts +15 -3
  109. package/dist/codegen-go.d.ts.map +1 -1
  110. package/dist/codegen-go.js +872 -0
  111. package/dist/codegen-go.js.map +1 -0
  112. package/dist/codegen-hash.js +9 -0
  113. package/dist/codegen-hash.js.map +1 -0
  114. package/dist/codegen-ir.d.ts +69 -2
  115. package/dist/codegen-ir.d.ts.map +1 -1
  116. package/dist/codegen-ir.js +661 -0
  117. package/dist/codegen-ir.js.map +1 -0
  118. package/dist/codegen-lang.d.ts +65 -0
  119. package/dist/codegen-lang.d.ts.map +1 -0
  120. package/dist/codegen-lang.js +526 -0
  121. package/dist/codegen-lang.js.map +1 -0
  122. package/dist/codegen-load.d.ts +31 -0
  123. package/dist/codegen-load.d.ts.map +1 -0
  124. package/dist/codegen-load.js +138 -0
  125. package/dist/codegen-load.js.map +1 -0
  126. package/dist/codegen-loaders.js +55 -0
  127. package/dist/codegen-loaders.js.map +1 -0
  128. package/dist/codegen-mcp.d.ts.map +1 -1
  129. package/dist/codegen-mcp.js +368 -0
  130. package/dist/codegen-mcp.js.map +1 -0
  131. package/dist/codegen-python.d.ts +13 -1
  132. package/dist/codegen-python.d.ts.map +1 -1
  133. package/dist/codegen-python.js +828 -0
  134. package/dist/codegen-python.js.map +1 -0
  135. package/dist/codegen-route-tree-intern.d.ts +15 -5
  136. package/dist/codegen-route-tree-intern.d.ts.map +1 -1
  137. package/dist/codegen-route-tree-intern.js +221 -0
  138. package/dist/codegen-route-tree-intern.js.map +1 -0
  139. package/dist/codegen-rust.d.ts.map +1 -1
  140. package/dist/codegen-rust.js +1293 -0
  141. package/dist/codegen-rust.js.map +1 -0
  142. package/dist/codegen-sanitize.d.ts.map +1 -1
  143. package/dist/codegen-sanitize.js +56 -0
  144. package/dist/codegen-sanitize.js.map +1 -0
  145. package/dist/codegen-schema-naming.d.ts +5 -0
  146. package/dist/codegen-schema-naming.d.ts.map +1 -1
  147. package/dist/codegen-schema-naming.js +150 -0
  148. package/dist/codegen-schema-naming.js.map +1 -0
  149. package/dist/codegen-sdk-model.d.ts +71 -0
  150. package/dist/codegen-sdk-model.d.ts.map +1 -0
  151. package/dist/codegen-sdk-model.js +179 -0
  152. package/dist/codegen-sdk-model.js.map +1 -0
  153. package/dist/codegen.d.ts +41 -23
  154. package/dist/codegen.d.ts.map +1 -1
  155. package/dist/codegen.js +4610 -0
  156. package/dist/codegen.js.map +1 -0
  157. package/dist/context.d.ts +36 -6
  158. package/dist/context.d.ts.map +1 -1
  159. package/dist/context.js +242 -0
  160. package/dist/context.js.map +1 -0
  161. package/dist/cookie-sign.d.ts +16 -2
  162. package/dist/cookie-sign.d.ts.map +1 -1
  163. package/dist/cookie-sign.js +104 -0
  164. package/dist/cookie-sign.js.map +1 -0
  165. package/dist/cookie.d.ts +12 -0
  166. package/dist/cookie.d.ts.map +1 -1
  167. package/dist/cookie.js +138 -0
  168. package/dist/cookie.js.map +1 -0
  169. package/dist/cors.d.ts +1 -0
  170. package/dist/cors.d.ts.map +1 -1
  171. package/dist/cors.js +87 -0
  172. package/dist/cors.js.map +1 -0
  173. package/dist/crypto.d.ts +6 -1
  174. package/dist/crypto.d.ts.map +1 -1
  175. package/dist/crypto.js +38 -0
  176. package/dist/crypto.js.map +1 -0
  177. package/dist/csrf.d.ts +19 -0
  178. package/dist/csrf.d.ts.map +1 -1
  179. package/dist/csrf.js +79 -0
  180. package/dist/csrf.js.map +1 -0
  181. package/dist/curl-logger.d.ts +14 -3
  182. package/dist/curl-logger.d.ts.map +1 -1
  183. package/dist/curl-logger.js +199 -0
  184. package/dist/curl-logger.js.map +1 -0
  185. package/dist/detect-runtime.js +13 -0
  186. package/dist/detect-runtime.js.map +1 -0
  187. package/dist/dict.d.ts +11 -0
  188. package/dist/dict.d.ts.map +1 -0
  189. package/dist/dict.js +13 -0
  190. package/dist/dict.js.map +1 -0
  191. package/dist/error.d.ts.map +1 -1
  192. package/dist/error.js +44 -0
  193. package/dist/error.js.map +1 -0
  194. package/dist/errors.js +39 -0
  195. package/dist/errors.js.map +1 -0
  196. package/dist/etag.d.ts +2 -0
  197. package/dist/etag.d.ts.map +1 -1
  198. package/dist/etag.js +82 -0
  199. package/dist/etag.js.map +1 -0
  200. package/dist/feature-detect.d.ts +25 -0
  201. package/dist/feature-detect.d.ts.map +1 -0
  202. package/dist/feature-detect.js +144 -0
  203. package/dist/feature-detect.js.map +1 -0
  204. package/dist/feature-load.js +36 -0
  205. package/dist/feature-load.js.map +1 -0
  206. package/dist/feature-slots.d.ts +44 -0
  207. package/dist/feature-slots.d.ts.map +1 -0
  208. package/dist/feature-slots.js +48 -0
  209. package/dist/feature-slots.js.map +1 -0
  210. package/dist/fetch-request.d.ts +10 -0
  211. package/dist/fetch-request.d.ts.map +1 -0
  212. package/dist/fetch-request.js +13 -0
  213. package/dist/fetch-request.js.map +1 -0
  214. package/dist/gen-process.d.ts +15 -0
  215. package/dist/gen-process.d.ts.map +1 -0
  216. package/dist/gen-process.js +43 -0
  217. package/dist/gen-process.js.map +1 -0
  218. package/dist/gen-write.d.ts +19 -0
  219. package/dist/gen-write.d.ts.map +1 -0
  220. package/dist/gen-write.js +120 -0
  221. package/dist/gen-write.js.map +1 -0
  222. package/dist/glob.d.ts +21 -0
  223. package/dist/glob.d.ts.map +1 -0
  224. package/dist/glob.js +115 -0
  225. package/dist/glob.js.map +1 -0
  226. package/dist/go-type-emitter.d.ts +18 -4
  227. package/dist/go-type-emitter.d.ts.map +1 -1
  228. package/dist/go-type-emitter.js +594 -0
  229. package/dist/go-type-emitter.js.map +1 -0
  230. package/dist/honey-response.d.ts.map +1 -1
  231. package/dist/honey-response.js +338 -0
  232. package/dist/honey-response.js.map +1 -0
  233. package/dist/i18n-slot.d.ts +8 -0
  234. package/dist/i18n-slot.d.ts.map +1 -1
  235. package/dist/i18n-slot.js +14 -0
  236. package/dist/i18n-slot.js.map +1 -0
  237. package/dist/i18n.d.ts +3 -0
  238. package/dist/i18n.d.ts.map +1 -1
  239. package/dist/i18n.js +250 -0
  240. package/dist/i18n.js.map +1 -0
  241. package/dist/index.d.ts +408 -148
  242. package/dist/index.d.ts.map +1 -1
  243. package/dist/index.js +2324 -0
  244. package/dist/index.js.map +1 -0
  245. package/dist/init.d.ts +3 -5
  246. package/dist/init.d.ts.map +1 -1
  247. package/dist/init.js +140 -0
  248. package/dist/init.js.map +1 -0
  249. package/dist/input.js +4 -0
  250. package/dist/input.js.map +1 -0
  251. package/dist/invalidate-check.d.ts +11 -0
  252. package/dist/invalidate-check.d.ts.map +1 -1
  253. package/dist/invalidate-check.js +163 -0
  254. package/dist/invalidate-check.js.map +1 -0
  255. package/dist/invoke-user.d.ts +35 -0
  256. package/dist/invoke-user.d.ts.map +1 -0
  257. package/dist/invoke-user.js +73 -0
  258. package/dist/invoke-user.js.map +1 -0
  259. package/dist/ip-restrict.d.ts +13 -1
  260. package/dist/ip-restrict.d.ts.map +1 -1
  261. package/dist/ip-restrict.js +60 -0
  262. package/dist/ip-restrict.js.map +1 -0
  263. package/dist/ip.d.ts +39 -0
  264. package/dist/ip.d.ts.map +1 -0
  265. package/dist/ip.js +209 -0
  266. package/dist/ip.js.map +1 -0
  267. package/dist/logger.d.ts.map +1 -1
  268. package/dist/logger.js +113 -0
  269. package/dist/logger.js.map +1 -0
  270. package/dist/media-type.d.ts +30 -0
  271. package/dist/media-type.d.ts.map +1 -0
  272. package/dist/media-type.js +97 -0
  273. package/dist/media-type.js.map +1 -0
  274. package/dist/meta-spec-merge.d.ts +32 -0
  275. package/dist/meta-spec-merge.d.ts.map +1 -0
  276. package/dist/meta-spec-merge.js +68 -0
  277. package/dist/meta-spec-merge.js.map +1 -0
  278. package/dist/meta-spec.d.ts +16 -3
  279. package/dist/meta-spec.d.ts.map +1 -1
  280. package/dist/meta-spec.js +535 -0
  281. package/dist/meta-spec.js.map +1 -0
  282. package/dist/middleware.d.ts +23 -6
  283. package/dist/middleware.d.ts.map +1 -1
  284. package/dist/middleware.js +253 -0
  285. package/dist/middleware.js.map +1 -0
  286. package/dist/node-request.d.ts +57 -12
  287. package/dist/node-request.d.ts.map +1 -1
  288. package/dist/node-request.js +407 -0
  289. package/dist/node-request.js.map +1 -0
  290. package/dist/node.d.ts +20 -3
  291. package/dist/node.d.ts.map +1 -1
  292. package/dist/node.js +396 -0
  293. package/dist/node.js.map +1 -0
  294. package/dist/openapi/collect.d.ts +6 -3
  295. package/dist/openapi/collect.d.ts.map +1 -1
  296. package/dist/openapi/collect.js +30 -0
  297. package/dist/openapi/collect.js.map +1 -0
  298. package/dist/openapi/docs-page.d.ts +42 -0
  299. package/dist/openapi/docs-page.d.ts.map +1 -0
  300. package/dist/openapi/docs-page.js +80 -0
  301. package/dist/openapi/docs-page.js.map +1 -0
  302. package/dist/openapi/document.d.ts +4 -0
  303. package/dist/openapi/document.d.ts.map +1 -1
  304. package/dist/openapi/document.js +785 -0
  305. package/dist/openapi/document.js.map +1 -0
  306. package/dist/openapi/json-schema-slot.d.ts +7 -0
  307. package/dist/openapi/json-schema-slot.d.ts.map +1 -1
  308. package/dist/openapi/json-schema-slot.js +38 -0
  309. package/dist/openapi/json-schema-slot.js.map +1 -0
  310. package/dist/openapi/register.d.ts.map +1 -1
  311. package/dist/openapi/register.js +20 -0
  312. package/dist/openapi/register.js.map +1 -0
  313. package/dist/openapi/scalar.d.ts +3 -1
  314. package/dist/openapi/scalar.d.ts.map +1 -1
  315. package/dist/openapi/scalar.js +21 -0
  316. package/dist/openapi/scalar.js.map +1 -0
  317. package/dist/openapi/serve.d.ts +9 -0
  318. package/dist/openapi/serve.d.ts.map +1 -0
  319. package/dist/openapi/serve.js +36 -0
  320. package/dist/openapi/serve.js.map +1 -0
  321. package/dist/openapi/spec-factory.d.ts +30 -1
  322. package/dist/openapi/spec-factory.d.ts.map +1 -1
  323. package/dist/openapi/spec-factory.js +52 -0
  324. package/dist/openapi/spec-factory.js.map +1 -0
  325. package/dist/openapi/spec.d.ts +14 -5
  326. package/dist/openapi/spec.d.ts.map +1 -1
  327. package/dist/openapi/spec.js +50 -0
  328. package/dist/openapi/spec.js.map +1 -0
  329. package/dist/openapi/swagger.d.ts +3 -1
  330. package/dist/openapi/swagger.d.ts.map +1 -1
  331. package/dist/openapi/swagger.js +22 -0
  332. package/dist/openapi/swagger.js.map +1 -0
  333. package/dist/pattern.d.ts +71 -0
  334. package/dist/pattern.d.ts.map +1 -0
  335. package/dist/pattern.js +239 -0
  336. package/dist/pattern.js.map +1 -0
  337. package/dist/peer.d.ts +17 -0
  338. package/dist/peer.d.ts.map +1 -0
  339. package/dist/peer.js +50 -0
  340. package/dist/peer.js.map +1 -0
  341. package/dist/plugin.d.ts +67 -16
  342. package/dist/plugin.d.ts.map +1 -1
  343. package/dist/plugin.js +649 -0
  344. package/dist/plugin.js.map +1 -0
  345. package/dist/powered-by.d.ts.map +1 -1
  346. package/dist/powered-by.js +11 -0
  347. package/dist/powered-by.js.map +1 -0
  348. package/dist/pretty-json.d.ts.map +1 -1
  349. package/dist/pretty-json.js +47 -0
  350. package/dist/pretty-json.js.map +1 -0
  351. package/dist/producer-stream.d.ts +47 -0
  352. package/dist/producer-stream.d.ts.map +1 -0
  353. package/dist/producer-stream.js +267 -0
  354. package/dist/producer-stream.js.map +1 -0
  355. package/dist/proxy.d.ts +47 -8
  356. package/dist/proxy.d.ts.map +1 -1
  357. package/dist/proxy.js +274 -0
  358. package/dist/proxy.js.map +1 -0
  359. package/dist/python-type-emitter.d.ts +14 -1
  360. package/dist/python-type-emitter.d.ts.map +1 -1
  361. package/dist/python-type-emitter.js +157 -0
  362. package/dist/python-type-emitter.js.map +1 -0
  363. package/dist/realtime/bus.d.ts +17 -1
  364. package/dist/realtime/bus.d.ts.map +1 -1
  365. package/dist/realtime/bus.js +112 -0
  366. package/dist/realtime/bus.js.map +1 -0
  367. package/dist/realtime/register.d.ts +3 -0
  368. package/dist/realtime/register.d.ts.map +1 -0
  369. package/dist/realtime/register.js +10 -0
  370. package/dist/realtime/register.js.map +1 -0
  371. package/dist/realtime/route.d.ts +65 -26
  372. package/dist/realtime/route.d.ts.map +1 -1
  373. package/dist/realtime/route.js +72 -0
  374. package/dist/realtime/route.js.map +1 -0
  375. package/dist/realtime/server.d.ts +43 -0
  376. package/dist/realtime/server.d.ts.map +1 -0
  377. package/dist/realtime/server.js +255 -0
  378. package/dist/realtime/server.js.map +1 -0
  379. package/dist/request-id.d.ts +7 -0
  380. package/dist/request-id.d.ts.map +1 -1
  381. package/dist/request-id.js +16 -0
  382. package/dist/request-id.js.map +1 -0
  383. package/dist/request-limits.d.ts +3 -0
  384. package/dist/request-limits.d.ts.map +1 -0
  385. package/dist/request-limits.js +3 -0
  386. package/dist/request-limits.js.map +1 -0
  387. package/dist/request-path.d.ts +33 -0
  388. package/dist/request-path.d.ts.map +1 -0
  389. package/dist/request-path.js +178 -0
  390. package/dist/request-path.js.map +1 -0
  391. package/dist/request-to-curl.d.ts +7 -1
  392. package/dist/request-to-curl.d.ts.map +1 -1
  393. package/dist/request-to-curl.js +48 -0
  394. package/dist/request-to-curl.js.map +1 -0
  395. package/dist/response.d.ts +25 -2
  396. package/dist/response.d.ts.map +1 -1
  397. package/dist/response.js +313 -0
  398. package/dist/response.js.map +1 -0
  399. package/dist/rust-type-emitter.d.ts +14 -2
  400. package/dist/rust-type-emitter.d.ts.map +1 -1
  401. package/dist/rust-type-emitter.js +463 -0
  402. package/dist/rust-type-emitter.js.map +1 -0
  403. package/dist/secure-headers.d.ts.map +1 -1
  404. package/dist/secure-headers.js +53 -0
  405. package/dist/secure-headers.js.map +1 -0
  406. package/dist/serve-register.d.ts +4 -0
  407. package/dist/serve-register.d.ts.map +1 -1
  408. package/dist/serve-register.js +9 -0
  409. package/dist/serve-register.js.map +1 -0
  410. package/dist/serve-slot.d.ts +3 -0
  411. package/dist/serve-slot.d.ts.map +1 -1
  412. package/dist/serve-slot.js +52 -0
  413. package/dist/serve-slot.js.map +1 -0
  414. package/dist/serve.d.ts +18 -1
  415. package/dist/serve.d.ts.map +1 -1
  416. package/dist/serve.js +157 -0
  417. package/dist/serve.js.map +1 -0
  418. package/dist/server-timing.d.ts.map +1 -1
  419. package/dist/server-timing.js +51 -0
  420. package/dist/server-timing.js.map +1 -0
  421. package/dist/static.d.ts +9 -0
  422. package/dist/static.d.ts.map +1 -1
  423. package/dist/static.js +102 -0
  424. package/dist/static.js.map +1 -0
  425. package/dist/telemetry/otel.d.ts +2 -0
  426. package/dist/telemetry/otel.d.ts.map +1 -1
  427. package/dist/telemetry/otel.js +135 -0
  428. package/dist/telemetry/otel.js.map +1 -0
  429. package/dist/testing.d.ts +12 -0
  430. package/dist/testing.d.ts.map +1 -1
  431. package/dist/testing.js +124 -0
  432. package/dist/testing.js.map +1 -0
  433. package/dist/timeout.d.ts +6 -0
  434. package/dist/timeout.d.ts.map +1 -1
  435. package/dist/timeout.js +36 -0
  436. package/dist/timeout.js.map +1 -0
  437. package/dist/tree.d.ts +133 -36
  438. package/dist/tree.d.ts.map +1 -1
  439. package/dist/tree.js +437 -0
  440. package/dist/tree.js.map +1 -0
  441. package/dist/trust.d.ts +21 -0
  442. package/dist/trust.d.ts.map +1 -0
  443. package/dist/trust.js +100 -0
  444. package/dist/trust.js.map +1 -0
  445. package/dist/ts-type-emitter.d.ts.map +1 -1
  446. package/dist/ts-type-emitter.js +150 -0
  447. package/dist/ts-type-emitter.js.map +1 -0
  448. package/dist/type-emitter.d.ts +16 -2
  449. package/dist/type-emitter.d.ts.map +1 -1
  450. package/dist/type-emitter.js +729 -0
  451. package/dist/type-emitter.js.map +1 -0
  452. package/dist/type-extractor.d.ts +8 -4
  453. package/dist/type-extractor.d.ts.map +1 -1
  454. package/dist/type-extractor.js +776 -0
  455. package/dist/type-extractor.js.map +1 -0
  456. package/dist/types.d.ts +7 -0
  457. package/dist/types.d.ts.map +1 -1
  458. package/dist/types.js +96 -0
  459. package/dist/types.js.map +1 -0
  460. package/dist/validation.d.ts +14 -2
  461. package/dist/validation.d.ts.map +1 -1
  462. package/dist/validation.js +335 -0
  463. package/dist/validation.js.map +1 -0
  464. package/dist/with-headers.d.ts +15 -0
  465. package/dist/with-headers.d.ts.map +1 -0
  466. package/dist/with-headers.js +45 -0
  467. package/dist/with-headers.js.map +1 -0
  468. package/dist/ws/bun.d.ts +11 -5
  469. package/dist/ws/bun.d.ts.map +1 -1
  470. package/dist/ws/bun.js +82 -0
  471. package/dist/ws/bun.js.map +1 -0
  472. package/dist/ws/cloudflare.d.ts +25 -3
  473. package/dist/ws/cloudflare.d.ts.map +1 -1
  474. package/dist/ws/cloudflare.js +117 -0
  475. package/dist/ws/cloudflare.js.map +1 -0
  476. package/dist/ws/deno.d.ts +4 -4
  477. package/dist/ws/deno.d.ts.map +1 -1
  478. package/dist/ws/deno.js +133 -0
  479. package/dist/ws/deno.js.map +1 -0
  480. package/dist/ws/node.d.ts +20 -3
  481. package/dist/ws/node.d.ts.map +1 -1
  482. package/dist/ws/node.js +173 -0
  483. package/dist/ws/node.js.map +1 -0
  484. package/dist/ws/session.d.ts +11 -0
  485. package/dist/ws/session.d.ts.map +1 -0
  486. package/dist/ws/session.js +60 -0
  487. package/dist/ws/session.js.map +1 -0
  488. package/dist/ws/shared.d.ts +65 -0
  489. package/dist/ws/shared.d.ts.map +1 -0
  490. package/dist/ws/shared.js +103 -0
  491. package/dist/ws/shared.js.map +1 -0
  492. package/dist/ws-origin.d.ts +20 -0
  493. package/dist/ws-origin.d.ts.map +1 -0
  494. package/dist/ws-origin.js +41 -0
  495. package/dist/ws-origin.js.map +1 -0
  496. package/dist/yaml.d.ts +15 -1
  497. package/dist/yaml.d.ts.map +1 -1
  498. package/dist/yaml.js +101 -0
  499. package/dist/yaml.js.map +1 -0
  500. package/docs/invalidate-spec.md +13 -1
  501. package/docs/meta-spec.md +36 -12
  502. package/docs/packaging.md +43 -24
  503. package/docs/regression-matrix/README.md +32 -0
  504. package/docs/regression-matrix/review.md +44 -0
  505. package/docs/regression-matrix/ws1-3.md +97 -0
  506. package/docs/regression-matrix/ws4-8.md +107 -0
  507. package/docs/regression-matrix/ws9-12.md +266 -0
  508. package/docs/sdk.md +102 -52
  509. package/package.json +183 -52
  510. package/src/accepts.ts +91 -33
  511. package/src/body-kind.ts +67 -0
  512. package/src/body-limit.ts +102 -87
  513. package/src/build/index.ts +104 -54
  514. package/src/cli-args.ts +123 -0
  515. package/src/cli-go/auth.go +12 -1
  516. package/src/cli-go/config.go +29 -2
  517. package/src/cli-go/errors.go +28 -10
  518. package/src/cli-go/multipart.go +51 -27
  519. package/src/cli-go/output.go +58 -4
  520. package/src/cli-go/root.go +1 -1
  521. package/src/cli-go/version.go +2 -2
  522. package/src/cli.ts +154 -148
  523. package/src/client/error.ts +56 -1
  524. package/src/client/http.ts +479 -256
  525. package/src/client/index.ts +55 -17
  526. package/src/client/path.ts +169 -0
  527. package/src/client/redirect-policy.ts +19 -0
  528. package/src/client/sdk.ts +180 -101
  529. package/src/client/sse.ts +92 -66
  530. package/src/client/ws.ts +67 -31
  531. package/src/client-go/errors.go +41 -12
  532. package/src/client-go/export.go +44 -0
  533. package/src/client-go/invalidation.go +52 -54
  534. package/src/client-go/nullable.go +62 -0
  535. package/src/client-go/realtime.go +147 -110
  536. package/src/client-go/runtime.go +646 -88
  537. package/src/client-go/sse.go +104 -94
  538. package/src/client-go/transport.go +67 -27
  539. package/src/client-go/ws.go +49 -25
  540. package/src/client-info.ts +79 -0
  541. package/src/client-mcp/server.ts +133 -3
  542. package/src/client-python/_invalidation.py +207 -291
  543. package/src/client-python/_realtime.py +63 -40
  544. package/src/client-python/_runtime.py +501 -119
  545. package/src/client-python/_sse.py +130 -74
  546. package/src/client-python/_transport.py +37 -9
  547. package/src/client-python/_ws.py +50 -22
  548. package/src/client-rust/errors.rs +21 -1
  549. package/src/client-rust/invalidation.rs +202 -231
  550. package/src/client-rust/invalidation_sync.rs +16 -229
  551. package/src/client-rust/nullable.rs +17 -0
  552. package/src/client-rust/realtime.rs +217 -217
  553. package/src/client-rust/runtime.rs +602 -177
  554. package/src/client-rust/runtime_sync.rs +169 -145
  555. package/src/client-rust/sse.rs +142 -121
  556. package/src/client-rust/ws.rs +61 -37
  557. package/src/codegen-go-cli.ts +607 -728
  558. package/src/codegen-go.ts +710 -770
  559. package/src/codegen-ir.ts +381 -75
  560. package/src/codegen-lang.ts +517 -0
  561. package/src/codegen-load.ts +150 -0
  562. package/src/codegen-mcp.ts +207 -108
  563. package/src/codegen-python.ts +684 -816
  564. package/src/codegen-route-tree-intern.ts +51 -25
  565. package/src/codegen-rust.ts +946 -1240
  566. package/src/codegen-sanitize.ts +0 -4
  567. package/src/codegen-schema-naming.ts +19 -6
  568. package/src/codegen-sdk-model.ts +228 -0
  569. package/src/codegen.ts +1488 -1140
  570. package/src/context.ts +130 -11
  571. package/src/cookie-sign.ts +85 -16
  572. package/src/cookie.ts +66 -11
  573. package/src/cors.ts +55 -54
  574. package/src/crypto.ts +27 -5
  575. package/src/csrf.ts +57 -25
  576. package/src/curl-logger.ts +155 -114
  577. package/src/dict.ts +12 -0
  578. package/src/error.ts +4 -2
  579. package/src/etag.ts +58 -34
  580. package/src/feature-detect.ts +147 -0
  581. package/src/feature-slots.ts +70 -0
  582. package/src/fetch-request.ts +13 -0
  583. package/src/gen-process.ts +42 -0
  584. package/src/gen-write.ts +127 -0
  585. package/src/glob.ts +109 -0
  586. package/src/go-type-emitter.ts +406 -155
  587. package/src/honey-response.ts +36 -9
  588. package/src/i18n-slot.ts +10 -0
  589. package/src/i18n.ts +98 -23
  590. package/src/index.ts +1887 -1756
  591. package/src/init.ts +40 -28
  592. package/src/invalidate-check.ts +42 -4
  593. package/src/invoke-user.ts +95 -0
  594. package/src/ip-restrict.ts +47 -161
  595. package/src/ip.ts +194 -0
  596. package/src/logger.ts +65 -36
  597. package/src/media-type.ts +104 -0
  598. package/src/meta-spec-merge.ts +80 -0
  599. package/src/meta-spec.ts +0 -0
  600. package/src/middleware.ts +112 -12
  601. package/src/node-request.ts +242 -52
  602. package/src/node.ts +318 -75
  603. package/src/openapi/collect.ts +19 -44
  604. package/src/openapi/docs-page.ts +89 -0
  605. package/src/openapi/document.ts +503 -224
  606. package/src/openapi/json-schema-slot.ts +40 -0
  607. package/src/openapi/register.ts +7 -2
  608. package/src/openapi/scalar.ts +11 -10
  609. package/src/openapi/serve.ts +39 -0
  610. package/src/openapi/spec-factory.ts +50 -1
  611. package/src/openapi/spec.ts +53 -30
  612. package/src/openapi/swagger.ts +12 -11
  613. package/src/pattern.ts +245 -0
  614. package/src/peer.ts +53 -0
  615. package/src/plugin.ts +270 -185
  616. package/src/powered-by.ts +2 -2
  617. package/src/pretty-json.ts +25 -9
  618. package/src/producer-stream.ts +296 -0
  619. package/src/proxy.ts +253 -55
  620. package/src/python-type-emitter.ts +68 -56
  621. package/src/realtime/bus.ts +56 -9
  622. package/src/realtime/register.ts +13 -0
  623. package/src/realtime/route.ts +129 -80
  624. package/src/realtime/server.ts +298 -0
  625. package/src/request-id.ts +13 -3
  626. package/src/request-limits.ts +2 -0
  627. package/src/request-path.ts +165 -0
  628. package/src/request-to-curl.ts +28 -7
  629. package/src/response.ts +143 -103
  630. package/src/rust-type-emitter.ts +265 -170
  631. package/src/secure-headers.ts +8 -4
  632. package/src/serve-register.ts +4 -0
  633. package/src/serve-slot.ts +38 -0
  634. package/src/serve.ts +113 -25
  635. package/src/server-timing.ts +11 -7
  636. package/src/static.ts +85 -32
  637. package/src/telemetry/otel.ts +29 -7
  638. package/src/testing.ts +76 -14
  639. package/src/timeout.ts +15 -7
  640. package/src/tree.ts +405 -333
  641. package/src/trust.ts +117 -0
  642. package/src/ts-type-emitter.ts +18 -12
  643. package/src/type-emitter.ts +227 -89
  644. package/src/type-extractor.ts +562 -424
  645. package/src/types.ts +8 -0
  646. package/src/validation.ts +221 -96
  647. package/src/with-headers.ts +45 -0
  648. package/src/ws/bun.ts +53 -15
  649. package/src/ws/cloudflare.ts +81 -19
  650. package/src/ws/deno.ts +124 -36
  651. package/src/ws/node.ts +173 -79
  652. package/src/ws/session.ts +73 -0
  653. package/src/ws/shared.ts +140 -0
  654. package/src/ws-origin.ts +53 -0
  655. package/src/yaml.ts +45 -22
  656. package/dist/client-mcp/server.d.ts +0 -10
  657. package/dist/client-mcp/server.d.ts.map +0 -1
  658. package/dist/client-mcp/types.d.ts +0 -16
  659. package/dist/client-mcp/types.d.ts.map +0 -1
  660. package/dist/cloudflare/realtime.d.ts +0 -30
  661. package/dist/cloudflare/realtime.d.ts.map +0 -1
  662. package/dist/realtime/buffer.d.ts +0 -18
  663. package/dist/realtime/buffer.d.ts.map +0 -1
  664. package/dist/realtime/longpoll.d.ts +0 -23
  665. package/dist/realtime/longpoll.d.ts.map +0 -1
  666. package/dist/realtime/protocol.d.ts +0 -50
  667. package/dist/realtime/protocol.d.ts.map +0 -1
  668. package/dist/realtime/runtime.d.ts +0 -74
  669. package/dist/realtime/runtime.d.ts.map +0 -1
  670. package/src/cloudflare/realtime.ts +0 -234
  671. package/src/realtime/buffer.ts +0 -101
  672. package/src/realtime/longpoll.ts +0 -148
  673. package/src/realtime/protocol.ts +0 -128
  674. package/src/realtime/runtime.ts +0 -427
@@ -1,3 +1,4 @@
1
+ import { sanitizeZodJsonSchema } from "../codegen-sanitize.ts"
1
2
  import type { StandardSchemaLike } from "../types.ts"
2
3
 
3
4
  export type JsonSchemaConverter = (schema: StandardSchemaLike, io?: "input" | "output") => Record<string, unknown>
@@ -11,3 +12,42 @@ export function setJsonSchemaConverter(next: JsonSchemaConverter | undefined): v
11
12
  export function getJsonSchemaConverter(): JsonSchemaConverter | undefined {
12
13
  return converter
13
14
  }
15
+
16
+ type InstanceConverters = {
17
+ "~standard": {
18
+ jsonSchema?: Partial<Record<"input" | "output", (params?: unknown) => unknown>>
19
+ vendor: string
20
+ }
21
+ toJsonSchema?: () => unknown
22
+ }
23
+
24
+ /**
25
+ * The converter used when the full codegen one is not loaded (`@lovrozagar/honey/openapi/spec`
26
+ * on a worker). It uses only what the schema instance carries — Zod 4's Standard JSON Schema
27
+ * and ArkType's `toJsonSchema()` — so it pulls in no validator package. A node JSON Schema
28
+ * cannot express degrades to `{}`, never the whole schema.
29
+ */
30
+ export function instanceJsonSchema(
31
+ schema: StandardSchemaLike,
32
+ io: "input" | "output" = "output",
33
+ ): Record<string, unknown> {
34
+ const s = schema as unknown as InstanceConverters
35
+ try {
36
+ const fromStandard = s["~standard"].jsonSchema?.[io]
37
+ if (typeof fromStandard === "function") {
38
+ const result = fromStandard({ libraryOptions: { unrepresentable: "any" }, target: "draft-2020-12" })
39
+ if (result !== null && typeof result === "object") {
40
+ return s["~standard"].vendor === "zod"
41
+ ? sanitizeZodJsonSchema(result as Record<string, unknown>)
42
+ : (result as Record<string, unknown>)
43
+ }
44
+ }
45
+ if (typeof s.toJsonSchema === "function") {
46
+ const result = s.toJsonSchema()
47
+ if (result !== null && typeof result === "object") return result as Record<string, unknown>
48
+ }
49
+ } catch {
50
+ /* the schema cannot describe itself — an unconstrained schema is the honest answer */
51
+ }
52
+ return {}
53
+ }
@@ -1,14 +1,19 @@
1
1
  import { generateManifest, generateOpenApi } from "../codegen.ts"
2
2
  import { toYaml } from "../yaml.ts"
3
3
  import { scalar } from "./scalar.ts"
4
+ import { artifactResponse, toServedArtifact } from "./serve.ts"
4
5
  import { swagger } from "./swagger.ts"
5
6
  import { registerOpenApiRuntime } from "./spec-factory.ts"
6
7
 
7
8
  export function enableOpenApi(): void {
8
9
  registerOpenApiRuntime({
10
+ artifactResponse,
9
11
  docsUi: (kind, specUrl) => (kind === "swagger" ? swagger({ url: specUrl }) : scalar({ url: specUrl })),
10
- generateManifest: (app) => Promise.resolve(generateManifest(app as never)),
11
- generateOpenApi: (app, options) => generateOpenApi(app as never, options),
12
+ /* served artifacts follow the document's visibility policy and never fail on one schema */
13
+ generateManifest: (app, options) =>
14
+ Promise.resolve(generateManifest(app as never, { visibility: "published", ...options })),
15
+ generateOpenApi: (app, options) => generateOpenApi(app as never, { onSchemaError: "warn", ...options }),
16
+ toServedArtifact,
12
17
  toYaml,
13
18
  })
14
19
  }
@@ -1,4 +1,5 @@
1
1
  import type { TypedResponse } from "../response.ts"
2
+ import { docsPage, escapeAttribute, inlineJson, SCALAR } from "./docs-page.ts"
2
3
 
3
4
  type ScalarOptions = {
4
5
  url: string
@@ -7,11 +8,14 @@ type ScalarOptions = {
7
8
 
8
9
  export function scalar(
9
10
  options: ScalarOptions,
10
- ): (ctx: { res: { html(sk: "ok", body: string): TypedResponse } }) => TypedResponse {
11
+ ): (ctx: {
12
+ res: { html(sk: "ok", body: string, opts?: { headers?: Record<string, string> }): TypedResponse }
13
+ }) => TypedResponse {
11
14
  const { url, ...rest } = options
12
- const config = JSON.stringify({ url, ...rest })
15
+ const config = inlineJson({ url, ...rest })
13
16
 
14
- const html = `<!DOCTYPE html>
17
+ return docsPage(
18
+ (nonce) => `<!DOCTYPE html>
15
19
  <html>
16
20
  <head>
17
21
  <meta charset="utf-8" />
@@ -20,14 +24,11 @@ export function scalar(
20
24
  </head>
21
25
  <body>
22
26
  <div id="app"></div>
23
- <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
24
- <script>
27
+ <script src="${SCALAR.js.url}" integrity="${SCALAR.js.integrity}" crossorigin="anonymous"></script>
28
+ <script nonce="${escapeAttribute(nonce)}">
25
29
  Scalar.createApiReference(document.getElementById("app"), ${config})
26
30
  </script>
27
31
  </body>
28
- </html>`
29
-
30
- const handler = (ctx: { res: { html(sk: "ok", body: string): TypedResponse } }) => ctx.res.html("ok", html)
31
- Object.defineProperty(handler, Symbol.for("honey.internal"), { value: true })
32
- return handler
32
+ </html>`,
33
+ )
33
34
  }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Serving side of `app.openapi()` and `app.manifest()`: serialize a document once, tag it, and
3
+ * answer conditional requests. Part of the lazily loaded OpenAPI feature, so none of this sits
4
+ * in the core bundle.
5
+ */
6
+ import { ifNoneMatchHits } from "../etag.ts"
7
+ import type { ServedArtifact } from "./spec-factory.ts"
8
+
9
+ const encoder = new TextEncoder()
10
+
11
+ /** Base64url of the first 16 bytes of SHA-256, quoted: a strong validator for the exact bytes. */
12
+ async function entityTag(body: string): Promise<string> {
13
+ const hash = new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(body))).subarray(0, 16)
14
+ let binary = ""
15
+ for (let i = 0; i < hash.length; i++) binary += String.fromCharCode(hash[i])
16
+ return `"${btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")}"`
17
+ }
18
+
19
+ /** Serialize `value` once; the result is cached per route epoch by the caller. */
20
+ export async function toServedArtifact(body: string, contentType: string): Promise<ServedArtifact> {
21
+ return { body, contentType, etag: await entityTag(body) }
22
+ }
23
+
24
+ /**
25
+ * The response for a served artifact. Clients revalidate (`no-cache`) rather than reuse a stale
26
+ * document after a deploy; an unchanged document costs a 304.
27
+ */
28
+ export function artifactResponse(request: Request, artifact: ServedArtifact): Response {
29
+ const headers = {
30
+ "cache-control": "no-cache",
31
+ "content-type": artifact.contentType,
32
+ etag: artifact.etag,
33
+ "x-content-type-options": "nosniff",
34
+ }
35
+ if (ifNoneMatchHits(request.headers.get("if-none-match"), artifact.etag)) {
36
+ return new Response(null, { headers, status: 304 })
37
+ }
38
+ return new Response(artifact.body, { headers })
39
+ }
@@ -6,12 +6,19 @@ export type OpenApiGenerate = (
6
6
  filterRoutes?: (route: { meta: unknown; method: string; path: string }) => boolean
7
7
  info: { description?: string; title: string; version: string }
8
8
  invalidate?: "error" | "off" | "warn" | { entityKey?: string; level?: "error" | "off" | "warn" }
9
+ onSchemaError?: "throw" | "warn"
9
10
  profile?: string
10
11
  securitySchemes?: Record<string, unknown>
11
12
  },
12
13
  ) => Promise<unknown>
13
14
 
14
- export type ManifestGenerate = (app: unknown) => Promise<unknown>
15
+ export type ManifestGenerate = (
16
+ app: unknown,
17
+ options?: {
18
+ filterRoutes?: (route: { meta: unknown; method: string; path: string }) => boolean
19
+ visibility?: "all" | "published"
20
+ },
21
+ ) => Promise<unknown>
15
22
 
16
23
  export type YamlGenerate = (value: unknown) => string
17
24
 
@@ -22,10 +29,16 @@ export type DocsUi = (
22
29
  specUrl: string,
23
30
  ) => (ctx: { res: HoneyRes }) => Response | Promise<Response>
24
31
 
32
+ /** A served document, serialized once per route epoch: the bytes, their type and a strong ETag. */
33
+ export type ServedArtifact = { body: string; contentType: string; etag: string }
34
+
25
35
  export type OpenApiRuntime = {
36
+ /** Answer a request for a served artifact: `ETag`, `Cache-Control`, and 304 on a match. */
37
+ artifactResponse: (request: Request, artifact: ServedArtifact) => Response
26
38
  docsUi: DocsUi
27
39
  generateManifest: ManifestGenerate
28
40
  generateOpenApi: OpenApiGenerate
41
+ toServedArtifact: (body: string, contentType: string) => Promise<ServedArtifact>
29
42
  toYaml: YamlGenerate
30
43
  }
31
44
 
@@ -49,3 +62,39 @@ export function getOpenApiRuntime(): OpenApiRuntime {
49
62
  export function tryGetOpenApiRuntime(): OpenApiRuntime | undefined {
50
63
  return runtime
51
64
  }
65
+
66
+ /**
67
+ * Memoize `compute` per route epoch. A failure is cached too, until the routes change: a
68
+ * document that cannot be generated fails every request the same way instead of re-running the
69
+ * whole generation per request.
70
+ */
71
+ export function epochCached<T>(epochOf: () => number, compute: () => Promise<T>): () => Promise<T> {
72
+ let entry: { epoch: number; value: Promise<T> } | null = null
73
+ return () => {
74
+ const epoch = epochOf()
75
+ if (entry === null || entry.epoch !== epoch) {
76
+ const value = Promise.resolve().then(compute)
77
+ /* handled here so a failure no request is awaiting yet is never an unhandled rejection */
78
+ value.catch(() => {})
79
+ entry = { epoch, value }
80
+ }
81
+ return entry.value
82
+ }
83
+ }
84
+
85
+ const APP = Symbol.for("honey.app")
86
+
87
+ /**
88
+ * Bind an internal handler (`spec()`, docs UIs) to the app serving it. Returns a new function
89
+ * per app, so one `spec()` handler mounted on two apps documents each of them — binding onto
90
+ * the shared function object would make the second mount throw or steal the first.
91
+ */
92
+ export function bindInternalHandler<F extends (ctx: never, app?: unknown) => unknown>(fn: F, app: unknown): F {
93
+ const bound = ((ctx: never) => fn(ctx, app)) as unknown as F
94
+ for (const key of Reflect.ownKeys(fn)) {
95
+ if (typeof key !== "symbol" || key === APP) continue
96
+ Object.defineProperty(bound, key, { value: (fn as unknown as Record<symbol, unknown>)[key] })
97
+ }
98
+ Object.defineProperty(bound, APP, { value: app })
99
+ return bound
100
+ }
@@ -1,5 +1,5 @@
1
- import type { DefaultMeta } from "../types.ts"
2
1
  import type { TypedResponse } from "../response.ts"
2
+ import type { DefaultMeta } from "../types.ts"
3
3
  import { generateOpenApiFromTree, type OpenApiRouteInfo } from "./document.ts"
4
4
  import { tryGetOpenApiRuntime } from "./spec-factory.ts"
5
5
 
@@ -13,38 +13,61 @@ type SpecOptions<TMeta = Record<string, unknown> | null> = {
13
13
  version: string
14
14
  }
15
15
 
16
- /** Walks the live or intern tree. Intern trees omit `iv`/`os`; serve generate-time OpenAPI JSON as assets instead of this walker on a gateway isolate. */
16
+ type SpecCtx = { res: { raw(response: Response): TypedResponse } }
17
+
18
+ type Cached = { body: Promise<string>; epoch: number }
19
+
20
+ const JSON_HEADERS = { "content-type": "application/json; charset=utf-8" }
21
+
22
+ function appEpoch(app: object): number {
23
+ return (app as { _epoch?: number })._epoch ?? 0
24
+ }
25
+
26
+ /**
27
+ * Serve an OpenAPI document for the app the handler is mounted on.
28
+ *
29
+ * Walks the live route graph. Schemas are converted with the full codegen converter when
30
+ * `@lovrozagar/honey/openapi` is loaded, and otherwise with what the schema instances carry
31
+ * (Zod 4, ArkType), so a worker bundle still documents bodies and parameters. The serialized
32
+ * document is cached per app and rebuilt when routes change; a failed build is cached for the
33
+ * same route graph too, so a broken schema costs one build, not one per request.
34
+ */
17
35
  export function spec<TMeta = Record<string, unknown> | null>(
18
36
  options: SpecOptions<TMeta>,
19
- ): (ctx: { res: { json(sk: "ok", data: unknown): TypedResponse } }) => TypedResponse | Promise<TypedResponse> {
20
- let cached: string | null = null
21
-
22
- const handler = async (ctx: { res: { json(sk: "ok", data: unknown): TypedResponse } }) => {
23
- if (cached === null) {
24
- const desc = Object.getOwnPropertyDescriptor(handler, Symbol.for("honey.app"))
25
- const app = desc?.value
26
- const generateOptions = {
27
- filterRoutes: options.filterRoutes,
28
- info: options,
29
- /* a served document is not an authoring moment — the check belongs to `honey generate` */
30
- invalidate: "off" as const,
31
- profile: options.profile,
32
- securitySchemes: options.securitySchemes,
33
- }
34
- const runtime = tryGetOpenApiRuntime()
35
- const openApiSpec = app
36
- ? runtime
37
- ? await runtime.generateOpenApi(app, {
38
- ...generateOptions,
39
- filterRoutes: options.filterRoutes as
40
- | ((route: { meta: unknown; method: string; path: string }) => boolean)
41
- | undefined,
42
- })
43
- : generateOpenApiFromTree(app, generateOptions)
44
- : {}
45
- cached = JSON.stringify(openApiSpec)
37
+ ): (ctx: SpecCtx, app?: unknown) => Promise<TypedResponse> {
38
+ const cache = new WeakMap<object, Cached>()
39
+ const info = { description: options.description, title: options.title, version: options.version }
40
+
41
+ const build = async (app: object): Promise<string> => {
42
+ const generateOptions = {
43
+ filterRoutes: options.filterRoutes as ((route: OpenApiRouteInfo) => boolean) | undefined,
44
+ info,
45
+ /* a served document is not an authoring moment — the check belongs to `honey generate` */
46
+ invalidate: "off" as const,
47
+ profile: options.profile,
48
+ securitySchemes: options.securitySchemes,
49
+ }
50
+ const runtime = tryGetOpenApiRuntime()
51
+ const document = runtime
52
+ ? await runtime.generateOpenApi(app, { ...generateOptions, onSchemaError: "warn" })
53
+ : generateOpenApiFromTree(app, generateOptions)
54
+ return JSON.stringify(document)
55
+ }
56
+
57
+ const handler = async (ctx: SpecCtx, bound?: unknown): Promise<TypedResponse> => {
58
+ const app = (bound ?? Object.getOwnPropertyDescriptor(handler, Symbol.for("honey.app"))?.value) as
59
+ | object
60
+ | undefined
61
+ if (app === undefined) {
62
+ throw new Error("spec(): the handler is not mounted on an app — register it with app.get(path, spec(...))")
63
+ }
64
+ const epoch = appEpoch(app)
65
+ let entry = cache.get(app)
66
+ if (entry === undefined || entry.epoch !== epoch) {
67
+ entry = { body: build(app), epoch }
68
+ cache.set(app, entry)
46
69
  }
47
- return ctx.res.json("ok", JSON.parse(cached))
70
+ return ctx.res.raw(new Response(await entry.body, { headers: JSON_HEADERS }))
48
71
  }
49
72
  Object.defineProperty(handler, Symbol.for("honey.internal"), { value: true })
50
73
  return handler
@@ -1,4 +1,5 @@
1
1
  import type { TypedResponse } from "../response.ts"
2
+ import { docsPage, escapeAttribute, inlineJson, SWAGGER_UI } from "./docs-page.ts"
2
3
 
3
4
  type SwaggerOptions = {
4
5
  url: string
@@ -7,28 +8,28 @@ type SwaggerOptions = {
7
8
 
8
9
  export function swagger(
9
10
  options: SwaggerOptions,
10
- ): (ctx: { res: { html(sk: "ok", body: string): TypedResponse } }) => TypedResponse {
11
+ ): (ctx: {
12
+ res: { html(sk: "ok", body: string, opts?: { headers?: Record<string, string> }): TypedResponse }
13
+ }) => TypedResponse {
11
14
  const { url, ...rest } = options
12
- const config = JSON.stringify({ dom_id: "#swagger-ui", url, ...rest })
15
+ const config = inlineJson({ dom_id: "#swagger-ui", url, ...rest })
13
16
 
14
- const html = `<!DOCTYPE html>
17
+ return docsPage(
18
+ (nonce) => `<!DOCTYPE html>
15
19
  <html>
16
20
  <head>
17
21
  <meta charset="utf-8" />
18
22
  <meta name="viewport" content="width=device-width, initial-scale=1" />
19
23
  <title>Swagger UI</title>
20
- <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css" />
24
+ <link rel="stylesheet" href="${SWAGGER_UI.css.url}" integrity="${SWAGGER_UI.css.integrity}" crossorigin="anonymous" />
21
25
  </head>
22
26
  <body>
23
27
  <div id="swagger-ui"></div>
24
- <script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
25
- <script>
28
+ <script src="${SWAGGER_UI.js.url}" integrity="${SWAGGER_UI.js.integrity}" crossorigin="anonymous"></script>
29
+ <script nonce="${escapeAttribute(nonce)}">
26
30
  SwaggerUIBundle(${config})
27
31
  </script>
28
32
  </body>
29
- </html>`
30
-
31
- const handler = (ctx: { res: { html(sk: "ok", body: string): TypedResponse } }) => ctx.res.html("ok", html)
32
- Object.defineProperty(handler, Symbol.for("honey.internal"), { value: true })
33
- return handler
33
+ </html>`,
34
+ )
34
35
  }
package/src/pattern.ts ADDED
@@ -0,0 +1,245 @@
1
+ /**
2
+ * The one route-pattern grammar. Registration, the router tree, scope matching, codegen
3
+ * selectors and OpenAPI paths all consume the parsed form; nothing re-derives params from
4
+ * a pattern string with its own regex.
5
+ *
6
+ * pattern = "/" | ("/" segment)+ ["/"]
7
+ * segment = static | param | wildcard
8
+ * param = ":" name ["?"] optional only as the last segment
9
+ * wildcard = "*" [name] last segment only; unnamed is called "*"
10
+ * name = [A-Za-z_$][A-Za-z0-9_$-]*
11
+ *
12
+ * Empty segments are dropped (`//a` is `/a`), a trailing slash is not significant, and a
13
+ * pattern without a leading slash gets one. `.` and `..` segments are rejected.
14
+ */
15
+
16
+ import { encodeSegment } from "./request-path.ts"
17
+
18
+ export type StaticSegment = { readonly k: "static"; readonly v: string }
19
+ export type ParamSegment = { readonly k: "param"; readonly n: string; readonly o: boolean }
20
+ export type WildcardSegment = { readonly k: "wildcard"; readonly n: string }
21
+ export type Segment = StaticSegment | ParamSegment | WildcardSegment
22
+
23
+ /** `METHOD /canonical/pattern` — stable identity of a route across apps, trees and codegen. */
24
+ export type RouteId = string
25
+
26
+ const NAME = /^[A-Za-z_$][A-Za-z0-9_$-]*$/
27
+ const DOT_SEGMENT = /^(?:\.|%2e){1,2}$/i
28
+
29
+ /** Name given to a `*` wildcard without a name. */
30
+ export const UNNAMED_WILDCARD = "*"
31
+
32
+ function invalid(path: string, why: string): never {
33
+ throw new Error(`Invalid route pattern "${path}": ${why}`)
34
+ }
35
+
36
+ export function parsePattern(path: string): Segment[] {
37
+ if (typeof path !== "string") invalid(String(path), "must be a string")
38
+ if (path.includes("#")) invalid(path, "fragments are not part of a route pattern")
39
+ const raw = path.split("/")
40
+ const segments: Segment[] = []
41
+ const names = new Set<string>()
42
+ for (let i = 0; i < raw.length; i++) {
43
+ const seg = raw[i]
44
+ if (seg === "") continue
45
+ /* `%2e` is a dot to every URL parser, so `/%2e%2e` can never be requested either */
46
+ if (DOT_SEGMENT.test(seg)) invalid(path, `"${seg}" segments are not allowed`)
47
+ const c = seg.charCodeAt(0)
48
+ if (c === 58 /* : */) {
49
+ const optional = seg.endsWith("?")
50
+ const name = optional ? seg.slice(1, -1) : seg.slice(1)
51
+ if (!NAME.test(name)) {
52
+ invalid(
53
+ path,
54
+ `parameter ":${name}" is not a valid name (letters, digits, "_", "$" and "-"; it takes the whole segment)`,
55
+ )
56
+ }
57
+ if (names.has(name)) invalid(path, `parameter ":${name}" appears twice`)
58
+ names.add(name)
59
+ segments.push({ k: "param", n: name, o: optional })
60
+ continue
61
+ }
62
+ if (c === 42 /* * */) {
63
+ const name = seg.length > 1 ? seg.slice(1) : UNNAMED_WILDCARD
64
+ if (name !== UNNAMED_WILDCARD && !NAME.test(name)) {
65
+ invalid(path, `wildcard "*${name}" is not a valid name`)
66
+ }
67
+ if (names.has(name)) invalid(path, `"${name}" appears twice`)
68
+ names.add(name)
69
+ segments.push({ k: "wildcard", n: name })
70
+ continue
71
+ }
72
+ if (seg.includes("?")) invalid(path, "query strings are not part of a route pattern")
73
+ /* the request path is percent-encoded the way URL parsing encodes it; so is a literal */
74
+ segments.push({ k: "static", v: encodeSegment(seg) })
75
+ }
76
+ for (let i = 0; i < segments.length - 1; i++) {
77
+ const s = segments[i]
78
+ if (s.k === "wildcard") invalid(path, "a wildcard must be the last segment")
79
+ if (s.k === "param" && s.o) invalid(path, "an optional parameter must be the last segment")
80
+ }
81
+ return segments
82
+ }
83
+
84
+ export function formatSegment(seg: Segment): string {
85
+ if (seg.k === "static") return seg.v
86
+ if (seg.k === "param") return `:${seg.n}${seg.o ? "?" : ""}`
87
+ return seg.n === UNNAMED_WILDCARD ? "*" : `*${seg.n}`
88
+ }
89
+
90
+ /** Canonical pattern string: leading slash, no empty segments, no trailing slash. */
91
+ export function canonical(segments: readonly Segment[]): string {
92
+ if (segments.length === 0) return "/"
93
+ let out = ""
94
+ for (const seg of segments) out += `/${formatSegment(seg)}`
95
+ return out
96
+ }
97
+
98
+ /** Parse and re-print — throws on anything the grammar cannot express. */
99
+ export function normalizePattern(path: string): string {
100
+ return canonical(parsePattern(path))
101
+ }
102
+
103
+ /** Join two patterns: `joinPatterns("/api/", "users")` is `/api/users`. */
104
+ export function joinPatterns(base: string, path: string): string {
105
+ const b = parsePattern(base)
106
+ const p = parsePattern(path)
107
+ if (b.length > 0) {
108
+ const last = b[b.length - 1]
109
+ if (last.k === "wildcard" || (last.k === "param" && last.o)) {
110
+ if (p.length > 0) invalid(`${base}${path}`, "cannot append to a wildcard or optional parameter")
111
+ }
112
+ }
113
+ /* re-parse: a name used on both sides (`/:id` + `/:id`) is only caught on the whole pattern */
114
+ return normalizePattern(canonical([...b, ...p]))
115
+ }
116
+
117
+ /**
118
+ * Concrete variants of a pattern: an optional last parameter yields the pattern with and
119
+ * without it. Every other pattern is its own single variant.
120
+ */
121
+ export function expandOptional(segments: readonly Segment[]): Segment[][] {
122
+ const last = segments[segments.length - 1]
123
+ if (last !== undefined && last.k === "param" && last.o) {
124
+ return [segments.slice(0, -1), [...segments.slice(0, -1), { k: "param", n: last.n, o: false }]]
125
+ }
126
+ return [[...segments]]
127
+ }
128
+
129
+ export function isStaticPattern(segments: readonly Segment[]): boolean {
130
+ for (const s of segments) if (s.k !== "static") return false
131
+ return true
132
+ }
133
+
134
+ /** Parameter and wildcard names, in order. */
135
+ export function patternParams(segments: readonly Segment[]): string[] {
136
+ const out: string[] = []
137
+ for (const s of segments) if (s.k !== "static") out.push(s.n)
138
+ return out
139
+ }
140
+
141
+ export function routeId(method: string, pattern: string): RouteId {
142
+ return `${method} ${pattern}`
143
+ }
144
+
145
+ /** Split a RouteId back into method and canonical pattern. */
146
+ export function splitRouteId(id: RouteId): { method: string; pattern: string } {
147
+ const sp = id.indexOf(" ")
148
+ return { method: id.slice(0, sp), pattern: id.slice(sp + 1) }
149
+ }
150
+
151
+ /** OpenAPI path template: `:id` and named wildcards become `{name}`. */
152
+ export function toOpenApiTemplate(segments: readonly Segment[]): string {
153
+ if (segments.length === 0) return "/"
154
+ let out = ""
155
+ for (const s of segments) {
156
+ if (s.k === "static") out += `/${s.v}`
157
+ else if (s.k === "param") out += `/{${s.n}}`
158
+ else out += s.n === UNNAMED_WILDCARD ? "/{wildcard}" : `/{${s.n}}`
159
+ }
160
+ return out
161
+ }
162
+
163
+ /*
164
+ * Scopes. `app.use("/admin", mw)` guards request paths: a path is inside the scope when its
165
+ * leading segments match the scope pattern — static segments literally, `:param` any one
166
+ * segment, `*` and an optional last param everything below. The scope uses the route
167
+ * grammar, so `/orgs/:id` and `/admin/*` mean what they mean in a route.
168
+ */
169
+
170
+ /** How much of a route a scope covers: every path it serves, none, or only some. */
171
+ export type ScopeCoverage = "all" | "none" | "some"
172
+
173
+ function coverVariant(route: readonly Segment[], scope: readonly Segment[]): ScopeCoverage {
174
+ let uncertain = false
175
+ for (let i = 0; i < scope.length; i++) {
176
+ const s = scope[i] as Segment
177
+ /* a wildcard or optional last param covers everything at and below this depth */
178
+ if (s.k === "wildcard" || (s.k === "param" && s.o)) return uncertain ? "some" : "all"
179
+ const r = route[i]
180
+ /* the route's paths end before the scope's do */
181
+ if (r === undefined) return "none"
182
+ /* a route wildcard serves paths both inside and outside the rest of the scope */
183
+ if (r.k === "wildcard") return "some"
184
+ if (r.k === "static") {
185
+ if (s.k === "static" && s.v !== r.v && safeDecode(r.v) !== safeDecode(s.v)) return "none"
186
+ continue
187
+ }
188
+ /* route param against a scope literal: inside the scope only when the value matches */
189
+ if (s.k === "static") uncertain = true
190
+ }
191
+ return uncertain ? "some" : "all"
192
+ }
193
+
194
+ function combine(a: ScopeCoverage, b: ScopeCoverage): ScopeCoverage {
195
+ return a === b ? a : "some"
196
+ }
197
+
198
+ /**
199
+ * Decide at registration time whether a scope covers a route. `"some"` means the answer
200
+ * depends on the request path (a route param or wildcard can land inside the scope), so the
201
+ * scope's middleware is guarded by {@link pathInScope} at request time.
202
+ */
203
+ export function scopeCoverage(route: readonly Segment[], scope: readonly Segment[]): ScopeCoverage {
204
+ let out: ScopeCoverage | undefined
205
+ for (const rv of expandOptional(route)) {
206
+ const c = coverVariant(rv, scope)
207
+ out = out === undefined ? c : combine(out, c)
208
+ }
209
+ return out ?? "none"
210
+ }
211
+
212
+ function safeDecode(s: string): string {
213
+ if (s.indexOf("%") === -1) return s
214
+ try {
215
+ return decodeURIComponent(s)
216
+ } catch {
217
+ return s
218
+ }
219
+ }
220
+
221
+ /**
222
+ * Is a request path inside a scope? Splits the path the way the router does (empty segments
223
+ * dropped) and compares each segment both as sent and percent-decoded, so a route param that
224
+ * decodes to a scoped literal is guarded exactly like the literal.
225
+ */
226
+ export function pathInScope(path: string, scope: readonly Segment[]): boolean {
227
+ let pos = 0
228
+ const len = path.length
229
+ for (let i = 0; i < scope.length; i++) {
230
+ const s = scope[i] as Segment
231
+ if (s.k === "wildcard" || (s.k === "param" && s.o)) return true
232
+ while (pos < len && path.charCodeAt(pos) === 47) pos++
233
+ if (pos >= len) return false
234
+ let end = path.indexOf("/", pos)
235
+ if (end === -1) end = len
236
+ if (s.k === "static") {
237
+ const seg = path.substring(pos, end)
238
+ /* both sides decoded: a literal is stored encoded (`%C3%A9`), and a request may spell the
239
+ * same bytes with lowercase escapes (`%c3%a9`) or raw */
240
+ if (seg !== s.v && safeDecode(seg) !== safeDecode(s.v)) return false
241
+ }
242
+ pos = end
243
+ }
244
+ return true
245
+ }
package/src/peer.ts ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The address of the TCP peer of a request, as the runtime reports it. Adapters register it;
3
+ * `ctx.ip` reads it through the app's trust setting (`trust.ts`).
4
+ *
5
+ * - Node (`serve()` from `/node`): the socket's `remoteAddress`
6
+ * - Bun: `server.requestIP(req)`, whether `serve()` or `Bun.serve({ fetch: app.fetch })` passed the server
7
+ * - Deno: `info.remoteAddr`, whether `serve()` or `Deno.serve(app.fetch)` passed the info
8
+ * - Cloudflare Workers: `CF-Connecting-IP`, which the edge sets and a client cannot
9
+ */
10
+
11
+ type PeerSource = string | (() => string | null)
12
+
13
+ const peers = new WeakMap<object, PeerSource>()
14
+
15
+ /** A request object can report its own peer under this key (the Node shim does, allocation-free). */
16
+ export const PEER_ADDRESS = Symbol.for("honey.peerAddress")
17
+
18
+ /** Called by adapters before `app.fetch`. A function is called at most once, on first read. */
19
+ export function setPeerAddress(req: Request, address: PeerSource): void {
20
+ peers.set(req, address)
21
+ }
22
+
23
+ function isWorkers(): boolean {
24
+ return (globalThis as { navigator?: { userAgent?: string } }).navigator?.userAgent === "Cloudflare-Workers"
25
+ }
26
+
27
+ type BunServerLike = { requestIP?: (req: Request) => { address?: string } | null }
28
+
29
+ export function peerAddressOf(req: Request, env: unknown): string | null {
30
+ const own = (req as unknown as Record<symbol, unknown>)[PEER_ADDRESS]
31
+ if (typeof own === "string") return own
32
+ const registered = peers.get(req)
33
+ if (registered !== undefined) {
34
+ if (typeof registered === "string") return registered === "" ? null : registered
35
+ const resolved = registered()
36
+ peers.set(req, resolved ?? "")
37
+ return resolved
38
+ }
39
+ if (env !== null && typeof env === "object") {
40
+ const e = env as BunServerLike & { server?: BunServerLike; remoteAddr?: { hostname?: unknown } }
41
+ const server = typeof e.requestIP === "function" ? e : e.server
42
+ if (server !== undefined && typeof server.requestIP === "function") {
43
+ try {
44
+ return server.requestIP(req)?.address ?? null
45
+ } catch {
46
+ return null
47
+ }
48
+ }
49
+ if (typeof e.remoteAddr?.hostname === "string") return e.remoteAddr.hostname
50
+ }
51
+ if (isWorkers()) return req.headers.get("cf-connecting-ip")
52
+ return null
53
+ }