@lovrozagar/honey 0.1.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 (131) hide show
  1. package/README.md +51 -0
  2. package/docs/api-ref/go.md +399 -0
  3. package/docs/api-ref/python.md +399 -0
  4. package/docs/api-ref/rust.md +399 -0
  5. package/docs/api-ref/typescript.md +399 -0
  6. package/docs/invalidate-spec.md +303 -0
  7. package/docs/sdk.md +722 -0
  8. package/package.json +120 -0
  9. package/src/accepts.ts +78 -0
  10. package/src/body-limit.ts +100 -0
  11. package/src/build/index.ts +174 -0
  12. package/src/cli-go/auth.go +15 -0
  13. package/src/cli-go/config.go +165 -0
  14. package/src/cli-go/errors.go +57 -0
  15. package/src/cli-go/multipart.go +55 -0
  16. package/src/cli-go/output.go +109 -0
  17. package/src/cli-go/root.go +30 -0
  18. package/src/cli-go/stream.go +88 -0
  19. package/src/cli-go/version.go +5 -0
  20. package/src/cli.ts +204 -0
  21. package/src/client/error.ts +27 -0
  22. package/src/client/http.ts +502 -0
  23. package/src/client/index.ts +127 -0
  24. package/src/client/sdk.ts +265 -0
  25. package/src/client/sse.ts +102 -0
  26. package/src/client/types.ts +211 -0
  27. package/src/client/ws.ts +115 -0
  28. package/src/client-go/errors.go +207 -0
  29. package/src/client-go/invalidation.go +373 -0
  30. package/src/client-go/realtime.go +317 -0
  31. package/src/client-go/result.go +20 -0
  32. package/src/client-go/runtime.go +413 -0
  33. package/src/client-go/sse.go +149 -0
  34. package/src/client-go/transport.go +452 -0
  35. package/src/client-go/ws.go +104 -0
  36. package/src/client-mcp/README.md +10 -0
  37. package/src/client-mcp/server.ts +94 -0
  38. package/src/client-mcp/types.ts +19 -0
  39. package/src/client-python/_errors.py +115 -0
  40. package/src/client-python/_invalidation.py +578 -0
  41. package/src/client-python/_realtime.py +156 -0
  42. package/src/client-python/_runtime.py +469 -0
  43. package/src/client-python/_sse.py +99 -0
  44. package/src/client-python/_transport.py +335 -0
  45. package/src/client-python/_ws.py +131 -0
  46. package/src/client-python/py.typed +0 -0
  47. package/src/client-rust/errors.rs +200 -0
  48. package/src/client-rust/invalidation.rs +441 -0
  49. package/src/client-rust/invalidation_sync.rs +306 -0
  50. package/src/client-rust/realtime.rs +695 -0
  51. package/src/client-rust/result.rs +22 -0
  52. package/src/client-rust/runtime.rs +547 -0
  53. package/src/client-rust/runtime_sync.rs +452 -0
  54. package/src/client-rust/sse.rs +167 -0
  55. package/src/client-rust/ws.rs +143 -0
  56. package/src/cloudflare/realtime.ts +236 -0
  57. package/src/codegen-go-cli.ts +1180 -0
  58. package/src/codegen-go.ts +1010 -0
  59. package/src/codegen-hash.ts +8 -0
  60. package/src/codegen-ir.ts +517 -0
  61. package/src/codegen-loaders.ts +53 -0
  62. package/src/codegen-mcp.ts +364 -0
  63. package/src/codegen-python.ts +1028 -0
  64. package/src/codegen-rust.ts +1652 -0
  65. package/src/codegen-sanitize.ts +67 -0
  66. package/src/codegen-schema-naming.ts +146 -0
  67. package/src/codegen.ts +5015 -0
  68. package/src/context.ts +210 -0
  69. package/src/cookie-sign.ts +58 -0
  70. package/src/cookie.ts +89 -0
  71. package/src/cors.ts +96 -0
  72. package/src/crypto.ts +19 -0
  73. package/src/csrf.ts +54 -0
  74. package/src/curl-logger.ts +235 -0
  75. package/src/detect-runtime.ts +19 -0
  76. package/src/error.ts +52 -0
  77. package/src/errors.ts +87 -0
  78. package/src/etag.ts +74 -0
  79. package/src/feature-load.ts +23 -0
  80. package/src/go-type-emitter.ts +404 -0
  81. package/src/honey-response.ts +354 -0
  82. package/src/i18n-slot.ts +20 -0
  83. package/src/i18n.ts +234 -0
  84. package/src/index.ts +3843 -0
  85. package/src/init.ts +149 -0
  86. package/src/input.ts +8 -0
  87. package/src/ip-restrict.ts +192 -0
  88. package/src/logger.ts +149 -0
  89. package/src/middleware.ts +199 -0
  90. package/src/node-request.ts +240 -0
  91. package/src/node.ts +212 -0
  92. package/src/openapi/register.ts +19 -0
  93. package/src/openapi/scalar.ts +33 -0
  94. package/src/openapi/spec-factory.ts +46 -0
  95. package/src/openapi/spec.ts +31 -0
  96. package/src/openapi/swagger.ts +34 -0
  97. package/src/plugin.ts +771 -0
  98. package/src/powered-by.ts +17 -0
  99. package/src/pretty-json.ts +39 -0
  100. package/src/proxy.ts +155 -0
  101. package/src/python-type-emitter.ts +144 -0
  102. package/src/realtime/buffer.ts +101 -0
  103. package/src/realtime/bus.ts +93 -0
  104. package/src/realtime/longpoll.ts +148 -0
  105. package/src/realtime/protocol.ts +128 -0
  106. package/src/realtime/route.ts +104 -0
  107. package/src/realtime/runtime.ts +430 -0
  108. package/src/request-id.ts +23 -0
  109. package/src/request-to-curl.ts +34 -0
  110. package/src/response.ts +414 -0
  111. package/src/rust-type-emitter.ts +412 -0
  112. package/src/secure-headers.ts +69 -0
  113. package/src/serve-register.ts +8 -0
  114. package/src/serve-slot.ts +20 -0
  115. package/src/serve.ts +141 -0
  116. package/src/server-timing.ts +66 -0
  117. package/src/static.ts +60 -0
  118. package/src/telemetry/otel.ts +139 -0
  119. package/src/testing.ts +114 -0
  120. package/src/timeout.ts +36 -0
  121. package/src/tree.ts +464 -0
  122. package/src/ts-type-emitter.ts +106 -0
  123. package/src/type-emitter.ts +524 -0
  124. package/src/type-extractor.ts +749 -0
  125. package/src/types.ts +638 -0
  126. package/src/validation.ts +300 -0
  127. package/src/ws/bun.ts +89 -0
  128. package/src/ws/cloudflare.ts +133 -0
  129. package/src/ws/deno.ts +109 -0
  130. package/src/ws/node.ts +161 -0
  131. package/src/yaml.ts +80 -0
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Honey
2
+
3
+ Type-safe API framework on Web Standards. Builder-pattern DX, precompiled radix-tree router, OpenAPI, and generated clients.
4
+
5
+ ## Start
6
+
7
+ ```bash
8
+ bun add @lovrozagar/honey
9
+ honey init
10
+ bun run dev
11
+ ```
12
+
13
+ ```ts
14
+ import { honey } from "@lovrozagar/honey"
15
+
16
+ export const app = honey()
17
+ .get("/health")
18
+ .handler((ctx) => ctx.res.text("ok", "ok"))
19
+ .openapi({ docs: "scalar", title: "My API", version: "1.0.0" })
20
+
21
+ await app.serve({ cors: true, port: 3000 })
22
+ ```
23
+
24
+ ```bash
25
+ curl http://127.0.0.1:3000/health
26
+ # ok
27
+
28
+ curl http://127.0.0.1:3000/openapi.json
29
+ # open http://127.0.0.1:3000/docs
30
+ ```
31
+
32
+ `honey init` writes `src/app.ts`, `src/server.ts`, `vite.config.ts`, and `dev` / `generate` scripts. `honey init --cf` also writes `wrangler.jsonc` and a worker that exports `fetch`.
33
+
34
+ `app.serve()` detects bun / node / deno and loads only that WebSocket adapter. Pass `runtime` to pin it. Cloudflare Workers cannot listen — export `fetch: (req, env, ctx) => app.fetch(req, env, ctx)`.
35
+
36
+ `app.serve()`, `app.openapi()`, and `app.errorI18n()` load their implementations when called. A fetch-only production bundle does not include listen adapters, spec generation, or i18n. Spec and docs routes stay out of the generated document.
37
+
38
+ ```bash
39
+ honey generate # writes src/_gen/
40
+ honey generate --watch
41
+ ```
42
+
43
+ ## Generated clients
44
+
45
+ Honey emits TypeScript, Python, Go, and Rust SDKs from the same spec. See [the SDK index](./docs/sdk.md).
46
+
47
+ Full framework guide (builder, serve, OpenAPI, WS, e2e, bench): the [repository README](https://github.com/lovrozagar/honey#table-of-contents).
48
+
49
+ ## License
50
+
51
+ MIT
@@ -0,0 +1,399 @@
1
+ # Go API Reference
2
+
3
+ Generated from OpenAPI via the shared codegen IR. Do not edit by hand —
4
+ run `bun run public/honey/core/scripts/gen-api-ref.ts` to regenerate.
5
+
6
+ ## Typed Errors
7
+
8
+ Every operation's error channel surfaces one of:
9
+
10
+ | Canonical | Status | Lang symbol | Notes |
11
+ | --------- | ------ | ----------- | ----- |
12
+ | `BadRequest` | 400 | `ErrBadRequest` | invalid request payload |
13
+ | `Unauthorized` | 401 | `ErrUnauthorized` | missing/invalid auth; triggers onAuthExpired + 1 retry |
14
+ | `Forbidden` | 403 | `ErrForbidden` | authenticated but not permitted |
15
+ | `NotFound` | 404 | `ErrNotFound` | resource does not exist |
16
+ | `Conflict` | 409 | `ErrConflict` | state conflict / unique violation |
17
+ | `UnprocessableEntity` | 422 | `ErrUnprocessableEntity` | schema-valid but semantically rejected |
18
+ | `TooManyRequests` | 429 | `ErrTooManyRequests` | rate-limited; consumer handles backoff via hooks |
19
+ | `InternalServerError` | 500 | `ErrInternalServerError` | server crash |
20
+ | `BadGateway` | 502 | `ErrBadGateway` | upstream failure |
21
+ | `ServiceUnavailable` | 503 | `ErrServiceUnavailable` | server temporarily unavailable |
22
+ | `GatewayTimeout` | 504 | `ErrGatewayTimeout` | upstream timeout |
23
+ | `StatusError` | * | `ErrStatusError` | fallback for undeclared/other statuses |
24
+
25
+ Operations with declared `responses: { 4xx: { schema } }` parse the response body into the error's typed `data` field.
26
+
27
+ ## Operations
28
+
29
+ ### RefreshToken
30
+
31
+ `POST /auth/refresh`
32
+
33
+ **Signature**
34
+
35
+ ```
36
+ func (c *Client) RefreshToken(ctx context.Context, body struct { RefreshToken string }) (struct { AccessToken string; ExpiresIn int }, error)
37
+ ```
38
+
39
+ **Request body**
40
+
41
+ - Content-type: `application/json`
42
+ - Required: yes
43
+ - Type: `struct { RefreshToken string }`
44
+
45
+ **Responses**
46
+
47
+ | Status | Content-type | Type |
48
+ | ------ | ------------ | ---- |
49
+ | `200` | `application/json` | `struct { AccessToken string; ExpiresIn int }` |
50
+ | `401` | `application/json` | `struct { Status int; Message string }` |
51
+
52
+ ---
53
+
54
+ ### GetDeclaredError
55
+
56
+ `GET /declared-errors/{status}`
57
+
58
+ **Signature**
59
+
60
+ ```
61
+ func (c *Client) GetDeclaredError(ctx context.Context, Status string) (struct{}, error)
62
+ ```
63
+
64
+ **Path params**
65
+
66
+ | Name | Type |
67
+ | ---- | ---- |
68
+ | `status` | `string` |
69
+
70
+ **Responses**
71
+
72
+ | Status | Content-type | Type |
73
+ | ------ | ------------ | ---- |
74
+ | `400` | `application/json` | `struct { Status int; Message string }` |
75
+ | `404` | `application/json` | `struct { Status int; Message string }` |
76
+ | `default` | `application/json` | `struct { Status int; Message string }` |
77
+
78
+ ---
79
+
80
+ ### GetError
81
+
82
+ `GET /errors/{status}`
83
+
84
+ **Signature**
85
+
86
+ ```
87
+ func (c *Client) GetError(ctx context.Context, Status int) (struct{}, error)
88
+ ```
89
+
90
+ **Path params**
91
+
92
+ | Name | Type |
93
+ | ---- | ---- |
94
+ | `status` | `int` |
95
+
96
+ **Responses**
97
+
98
+ | Status | Content-type | Type |
99
+ | ------ | ------------ | ---- |
100
+ | `default` | `application/json` | `struct { Status int; Message string }` |
101
+
102
+ ---
103
+
104
+ ### IdempotentCreate
105
+
106
+ `POST /idempotent-create`
107
+
108
+ **Signature**
109
+
110
+ ```
111
+ func (c *Client) IdempotentCreate(ctx context.Context) (struct { IdempotencyKey string }, error)
112
+ ```
113
+
114
+ **Responses**
115
+
116
+ | Status | Content-type | Type |
117
+ | ------ | ------------ | ---- |
118
+ | `200` | `application/json` | `struct { IdempotencyKey string }` |
119
+
120
+ **Extensions**
121
+
122
+ - `x-idempotency-key`: yes — auto-sent if omitted
123
+
124
+ ---
125
+
126
+ ### ConnectRealtime
127
+
128
+ `GET /realtime`
129
+
130
+ **Signature**
131
+
132
+ ```
133
+ func (c *Client) ConnectRealtime(ctx context.Context, ReconnectToken string) (*ResumableConnection, error)
134
+ ```
135
+
136
+ **Query params**
137
+
138
+ | Name | Type |
139
+ | ---- | ---- |
140
+ | `reconnect_token` | `string` |
141
+
142
+ **Responses**
143
+
144
+ | Status | Content-type | Type |
145
+ | ------ | ------------ | ---- |
146
+ | `101` | `—` | — |
147
+
148
+ **Extensions**
149
+
150
+ - `x-realtime`: yes
151
+
152
+ ---
153
+
154
+ ### Slow
155
+
156
+ `GET /slow`
157
+
158
+ **Signature**
159
+
160
+ ```
161
+ func (c *Client) Slow(ctx context.Context, Ms int) (struct { Ok bool }, error)
162
+ ```
163
+
164
+ **Query params**
165
+
166
+ | Name | Type |
167
+ | ---- | ---- |
168
+ | `ms` | `int` |
169
+
170
+ **Responses**
171
+
172
+ | Status | Content-type | Type |
173
+ | ------ | ------------ | ---- |
174
+ | `200` | `application/json` | `struct { Ok bool }` |
175
+
176
+ ---
177
+
178
+ ### StreamEvents
179
+
180
+ `GET /stream`
181
+
182
+ **Signature**
183
+
184
+ ```
185
+ func (c *Client) StreamEvents(ctx context.Context, LastEventID string) (<-chan struct { Event *string; Data *string; Id *string }, error)
186
+ ```
187
+
188
+ **Header params**
189
+
190
+ | Name | Type |
191
+ | ---- | ---- |
192
+ | `Last-Event-ID` | `string` |
193
+
194
+ **Responses**
195
+
196
+ | Status | Content-type | Type |
197
+ | ------ | ------------ | ---- |
198
+ | `200` | `text/event-stream` | `struct { Event *string; Data *string; Id *string }` |
199
+ | `401` | `application/json` | `struct { Status int; Message string }` |
200
+
201
+ **Extensions**
202
+
203
+ - SSE response detected (`text/event-stream`)
204
+
205
+ ---
206
+
207
+ ### UploadBlob
208
+
209
+ `POST /upload`
210
+
211
+ **Signature**
212
+
213
+ ```
214
+ func (c *Client) UploadBlob(ctx context.Context, body io.Reader) (struct { Size int; Hash string }, error)
215
+ ```
216
+
217
+ **Request body**
218
+
219
+ - Content-type: `application/octet-stream`
220
+ - Required: yes
221
+ - Type: `io.Reader`
222
+
223
+ **Responses**
224
+
225
+ | Status | Content-type | Type |
226
+ | ------ | ------------ | ---- |
227
+ | `200` | `application/json` | `struct { Size int; Hash string }` |
228
+ | `401` | `application/json` | `struct { Status int; Message string }` |
229
+
230
+ ---
231
+
232
+ ### ListUsers
233
+
234
+ `GET /users`
235
+
236
+ **Signature**
237
+
238
+ ```
239
+ func (c *Client) ListUsers(ctx context.Context) (struct { Items []struct { Id string; Name string; Email string }; Total int }, error)
240
+ ```
241
+
242
+ **Responses**
243
+
244
+ | Status | Content-type | Type |
245
+ | ------ | ------------ | ---- |
246
+ | `200` | `application/json` | `struct { Items []struct { Id string; Name string; Email string }; Total int }` |
247
+ | `401` | `application/json` | `struct { Status int; Message string }` |
248
+
249
+ ---
250
+
251
+ ### CreateUser
252
+
253
+ `POST /users`
254
+
255
+ **Signature**
256
+
257
+ ```
258
+ func (c *Client) CreateUser(ctx context.Context, body struct { Name string; Email string }) (struct { Id string; Name string; Email string }, error)
259
+ ```
260
+
261
+ **Request body**
262
+
263
+ - Content-type: `application/json`
264
+ - Required: yes
265
+ - Type: `struct { Name string; Email string }`
266
+
267
+ **Responses**
268
+
269
+ | Status | Content-type | Type |
270
+ | ------ | ------------ | ---- |
271
+ | `201` | `application/json` | `struct { Id string; Name string; Email string }` |
272
+ | `401` | `application/json` | `struct { Status int; Message string }` |
273
+ | `422` | `application/json` | `struct { Status int; Message string }` |
274
+
275
+ **Extensions**
276
+
277
+ - `x-invalidate`: `GET /users`
278
+
279
+ ---
280
+
281
+ ### DeleteUser
282
+
283
+ `DELETE /users/{id}`
284
+
285
+ **Signature**
286
+
287
+ ```
288
+ func (c *Client) DeleteUser(ctx context.Context, Id string) (struct{}, error)
289
+ ```
290
+
291
+ **Path params**
292
+
293
+ | Name | Type |
294
+ | ---- | ---- |
295
+ | `id` | `string` |
296
+
297
+ **Responses**
298
+
299
+ | Status | Content-type | Type |
300
+ | ------ | ------------ | ---- |
301
+ | `204` | `—` | — |
302
+ | `401` | `application/json` | `struct { Status int; Message string }` |
303
+ | `404` | `application/json` | `struct { Status int; Message string }` |
304
+
305
+ **Extensions**
306
+
307
+ - `x-invalidate`: `GET /users`, `GET /users/{id}`
308
+
309
+ ---
310
+
311
+ ### GetUser
312
+
313
+ `GET /users/{id}`
314
+
315
+ **Signature**
316
+
317
+ ```
318
+ func (c *Client) GetUser(ctx context.Context, Id string) (struct { Id string; Name string; Email string }, error)
319
+ ```
320
+
321
+ **Path params**
322
+
323
+ | Name | Type |
324
+ | ---- | ---- |
325
+ | `id` | `string` |
326
+
327
+ **Responses**
328
+
329
+ | Status | Content-type | Type |
330
+ | ------ | ------------ | ---- |
331
+ | `200` | `application/json` | `struct { Id string; Name string; Email string }` |
332
+ | `401` | `application/json` | `struct { Status int; Message string }` |
333
+ | `404` | `application/json` | `struct { Status int; Message string }` |
334
+
335
+ ---
336
+
337
+ ### UpdateUser
338
+
339
+ `PUT /users/{id}`
340
+
341
+ **Signature**
342
+
343
+ ```
344
+ func (c *Client) UpdateUser(ctx context.Context, Id string, body struct { Name *string; Email *string }) (struct { Id string; Name string; Email string }, error)
345
+ ```
346
+
347
+ **Path params**
348
+
349
+ | Name | Type |
350
+ | ---- | ---- |
351
+ | `id` | `string` |
352
+
353
+ **Request body**
354
+
355
+ - Content-type: `application/json`
356
+ - Required: yes
357
+ - Type: `struct { Name *string; Email *string }`
358
+
359
+ **Responses**
360
+
361
+ | Status | Content-type | Type |
362
+ | ------ | ------------ | ---- |
363
+ | `200` | `application/json` | `struct { Id string; Name string; Email string }` |
364
+ | `401` | `application/json` | `struct { Status int; Message string }` |
365
+ | `404` | `application/json` | `struct { Status int; Message string }` |
366
+
367
+ **Extensions**
368
+
369
+ - `x-invalidate`: `GET /users`, `GET /users/{id}`
370
+
371
+ ---
372
+
373
+ ### ConnectWs
374
+
375
+ `GET /ws`
376
+
377
+ **Signature**
378
+
379
+ ```
380
+ func (c *Client) ConnectWs(ctx context.Context, Token string) (*ResumableConnection, error)
381
+ ```
382
+
383
+ **Query params**
384
+
385
+ | Name | Type |
386
+ | ---- | ---- |
387
+ | `token` | `string` |
388
+
389
+ **Responses**
390
+
391
+ | Status | Content-type | Type |
392
+ | ------ | ------------ | ---- |
393
+ | `101` | `—` | — |
394
+
395
+ **Extensions**
396
+
397
+ - `x-websocket`: yes
398
+
399
+ ---