@lovrozagar/honey 0.5.2 → 0.6.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.
- package/README.md +11 -9
- package/dist/codegen.d.ts +4 -21
- package/dist/codegen.d.ts.map +1 -1
- package/dist/openapi/collect.d.ts +17 -0
- package/dist/openapi/collect.d.ts.map +1 -0
- package/dist/openapi/document.d.ts +29 -0
- package/dist/openapi/document.d.ts.map +1 -0
- package/dist/openapi/json-schema-slot.d.ts +5 -0
- package/dist/openapi/json-schema-slot.d.ts.map +1 -0
- package/dist/openapi/spec-factory.d.ts +1 -0
- package/dist/openapi/spec-factory.d.ts.map +1 -1
- package/dist/openapi/spec.d.ts +1 -1
- package/dist/openapi/spec.d.ts.map +1 -1
- package/dist/proxy.d.ts +3 -3
- package/dist/proxy.d.ts.map +1 -1
- package/dist/tree.d.ts +5 -5
- package/dist/tree.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/codegen.ts +19 -615
- package/src/index.ts +7 -7
- package/src/openapi/collect.ts +75 -0
- package/src/openapi/document.ts +614 -0
- package/src/openapi/json-schema-slot.ts +13 -0
- package/src/openapi/spec-factory.ts +4 -0
- package/src/openapi/spec.ts +21 -11
- package/src/proxy.ts +6 -5
- package/src/tree.ts +5 -5
package/src/proxy.ts
CHANGED
|
@@ -42,9 +42,9 @@ export type ProxyConfig<TCtx> = {
|
|
|
42
42
|
rewriteUrl?: (url: string, ctx: TCtx) => string
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Timeout in milliseconds.
|
|
46
|
-
* Accepts a number or a function that receives ctx
|
|
47
|
-
* Disabled for WebSocket upgrades.
|
|
45
|
+
* Timeout in milliseconds. Omitted: no abort. `0` or a non-positive
|
|
46
|
+
* value: no abort. Accepts a number or a function that receives ctx
|
|
47
|
+
* and returns a number. Disabled for WebSocket upgrades.
|
|
48
48
|
*/
|
|
49
49
|
timeout?: number | ((ctx: TCtx) => number)
|
|
50
50
|
}
|
|
@@ -58,7 +58,7 @@ export type ProxyConfig<TCtx> = {
|
|
|
58
58
|
* which has both fields — we access them via property access on the object.
|
|
59
59
|
*/
|
|
60
60
|
export function createProxyHandler<TCtx>(config: ProxyConfig<TCtx>): (ctx: TCtx) => Promise<Response> {
|
|
61
|
-
const timeoutOpt = config.timeout
|
|
61
|
+
const timeoutOpt = config.timeout
|
|
62
62
|
|
|
63
63
|
return async (ctx: TCtx) => {
|
|
64
64
|
const timeoutMs = typeof timeoutOpt === "function" ? timeoutOpt(ctx) : timeoutOpt
|
|
@@ -67,6 +67,7 @@ export function createProxyHandler<TCtx>(config: ProxyConfig<TCtx>): (ctx: TCtx)
|
|
|
67
67
|
const request = c["req"] as Request
|
|
68
68
|
const method = request.method
|
|
69
69
|
const isWs = request.headers.get("upgrade") === "websocket"
|
|
70
|
+
const abortMs = !isWs && timeoutMs != null && timeoutMs > 0 ? timeoutMs : undefined
|
|
70
71
|
|
|
71
72
|
/* URL resolution — path + query, no new URL() */
|
|
72
73
|
const rawUrl = request.url
|
|
@@ -108,7 +109,7 @@ export function createProxyHandler<TCtx>(config: ProxyConfig<TCtx>): (ctx: TCtx)
|
|
|
108
109
|
headers,
|
|
109
110
|
method,
|
|
110
111
|
redirect: "manual",
|
|
111
|
-
signal:
|
|
112
|
+
signal: abortMs == null ? undefined : AbortSignal.timeout(abortMs),
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
/* duplex required for streaming body (Node needs it, CF handles implicitly) */
|
package/src/tree.ts
CHANGED
|
@@ -12,8 +12,8 @@ export type RouteHandler = {
|
|
|
12
12
|
_skip?: boolean
|
|
13
13
|
/** boundary error key — wraps undeclared/unexpected errors (null = use default or internal_server_error) */
|
|
14
14
|
bek: string | null
|
|
15
|
-
/** pre-computed error factory subset (null = use global factory) */
|
|
16
|
-
ef
|
|
15
|
+
/** pre-computed error factory subset (omit/`null` = use global factory) */
|
|
16
|
+
ef?: Record<string, (...args: never[]) => unknown> | null
|
|
17
17
|
/** declared error keys for this route — used for runtime enforcement */
|
|
18
18
|
ek: Set<string>
|
|
19
19
|
/** handler function */
|
|
@@ -32,9 +32,9 @@ export type RouteHandler = {
|
|
|
32
32
|
/** output schemas by content-type (null = no output validation) */
|
|
33
33
|
os: OutputSchemaDef | null
|
|
34
34
|
/** output validator function — validates response body against schema */
|
|
35
|
-
ov
|
|
36
|
-
/** registered path pattern (e.g. "/users/:id") */
|
|
37
|
-
rp
|
|
35
|
+
ov?: OutputValidator | null
|
|
36
|
+
/** registered path pattern (e.g. "/users/:id"); intern trees omit this */
|
|
37
|
+
rp?: string
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export type { OutputSchemaDef }
|