@lovrozagar/honey 0.5.1 → 0.5.3
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-route-tree-intern.d.ts +29 -0
- package/dist/codegen-route-tree-intern.d.ts.map +1 -0
- package/dist/codegen.d.ts +5 -22
- 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/tree.d.ts +5 -39
- package/dist/tree.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/codegen-route-tree-intern.ts +171 -0
- package/src/codegen.ts +210 -728
- 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/tree.ts +5 -398
package/src/index.ts
CHANGED
|
@@ -533,7 +533,7 @@ export class Honey<
|
|
|
533
533
|
walkTreeHandlers(
|
|
534
534
|
this._root,
|
|
535
535
|
(h) => {
|
|
536
|
-
if (scopeMatches(entry.prefix, h.rp)) {
|
|
536
|
+
if (scopeMatches(entry.prefix, h.rp ?? "")) {
|
|
537
537
|
for (const k of errors) h.ek.add(k)
|
|
538
538
|
}
|
|
539
539
|
},
|
|
@@ -568,8 +568,8 @@ export class Honey<
|
|
|
568
568
|
private _applyScopedEntryMeta(entry: ScopedEntry): void {
|
|
569
569
|
const meta = (entry.mw as { meta?: Record<string, unknown> }).meta
|
|
570
570
|
if (!meta) return
|
|
571
|
-
const apply = (h: { mt: Record<string, unknown> | null; rp
|
|
572
|
-
if (!scopeMatches(entry.prefix, h.rp)) return
|
|
571
|
+
const apply = (h: { mt: Record<string, unknown> | null; rp?: string }): void => {
|
|
572
|
+
if (!scopeMatches(entry.prefix, h.rp ?? "")) return
|
|
573
573
|
/* contributed meta never overwrites what the route or chain stated explicitly */
|
|
574
574
|
h.mt = Object.freeze(h.mt ? { ...meta, ...h.mt } : { ...meta })
|
|
575
575
|
}
|
|
@@ -2314,7 +2314,7 @@ export class Honey<
|
|
|
2314
2314
|
params,
|
|
2315
2315
|
path,
|
|
2316
2316
|
req: fc.request,
|
|
2317
|
-
routePattern: handler.rp,
|
|
2317
|
+
routePattern: handler.rp ?? "",
|
|
2318
2318
|
urlFn: fc.url,
|
|
2319
2319
|
})
|
|
2320
2320
|
if (this._contextValues) Object.assign(ctx, this._contextValues)
|
|
@@ -2404,7 +2404,7 @@ export class Honey<
|
|
|
2404
2404
|
|
|
2405
2405
|
/* resolve error factory — pre-computed ef preferred, else build/use global */
|
|
2406
2406
|
let errors: Record<string, (...args: never[]) => unknown> | undefined
|
|
2407
|
-
if (handler.ef
|
|
2407
|
+
if (handler.ef != null) {
|
|
2408
2408
|
errors = handler.ef
|
|
2409
2409
|
} else if (this._errorFactory !== null) {
|
|
2410
2410
|
if (handler.ek.size > 0) {
|
|
@@ -2431,7 +2431,7 @@ export class Honey<
|
|
|
2431
2431
|
params,
|
|
2432
2432
|
path,
|
|
2433
2433
|
req: request,
|
|
2434
|
-
routePattern: handler.rp,
|
|
2434
|
+
routePattern: handler.rp ?? "",
|
|
2435
2435
|
urlFn: fc.url,
|
|
2436
2436
|
})
|
|
2437
2437
|
if (this._contextValues) Object.assign(ctx, this._contextValues)
|
|
@@ -2516,7 +2516,7 @@ export class Honey<
|
|
|
2516
2516
|
return after(result)
|
|
2517
2517
|
}
|
|
2518
2518
|
|
|
2519
|
-
const scopedForPath = this._filterScopedForPath(handler.rp)
|
|
2519
|
+
const scopedForPath = this._filterScopedForPath(handler.rp ?? "")
|
|
2520
2520
|
const chainMw = this._chainMiddlewares
|
|
2521
2521
|
const handlerHasChain = chainMw.length > 0 && chainMw.every((mw, i) => handler.mw[i] === mw)
|
|
2522
2522
|
/*
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { RouteHandler, TreeNode, WSRouteHandler } from "../tree.ts"
|
|
2
|
+
import type { InputSchemaEntry, StandardSchemaLike } from "../types.ts"
|
|
3
|
+
|
|
4
|
+
export type CollectedRoute = {
|
|
5
|
+
handler: RouteHandler
|
|
6
|
+
method: string
|
|
7
|
+
path: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type CollectedWSRoute = {
|
|
11
|
+
handler: WSRouteHandler
|
|
12
|
+
path: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function extractParams(path: string): string[] {
|
|
16
|
+
const params: string[] = []
|
|
17
|
+
for (const seg of path.split("/")) {
|
|
18
|
+
if (seg.startsWith(":")) {
|
|
19
|
+
params.push(seg.endsWith("?") ? seg.slice(1, -1) : seg.slice(1))
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return params
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function toOpenApiPath(path: string): string {
|
|
26
|
+
return path.replace(/:(\w+)\??/g, "{$1}")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function walkTree(
|
|
30
|
+
node: TreeNode,
|
|
31
|
+
currentPath: string,
|
|
32
|
+
routes: CollectedRoute[],
|
|
33
|
+
includeSkipped?: boolean,
|
|
34
|
+
): void {
|
|
35
|
+
if (node.m !== null) {
|
|
36
|
+
for (const [method, handler] of Object.entries(node.m)) {
|
|
37
|
+
if (handler._skip && !includeSkipped) continue
|
|
38
|
+
routes.push({ handler, method, path: currentPath || "/" })
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const [seg, child] of Object.entries(node.s)) {
|
|
43
|
+
walkTree(child, `${currentPath}/${seg}`, routes, includeSkipped)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (node.d !== null) {
|
|
47
|
+
walkTree(node.d.c, `${currentPath}/:${node.d.n}`, routes, includeSkipped)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (node.w !== null) {
|
|
51
|
+
for (const [method, handler] of Object.entries(node.w.m)) {
|
|
52
|
+
if (handler._skip && !includeSkipped) continue
|
|
53
|
+
routes.push({ handler, method, path: `${currentPath}/*${node.w.n}` })
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function walkWSRoutes(node: TreeNode, currentPath: string, routes: CollectedWSRoute[]): void {
|
|
59
|
+
if (node.ws !== null) {
|
|
60
|
+
routes.push({ handler: node.ws, path: currentPath || "/" })
|
|
61
|
+
}
|
|
62
|
+
for (const [seg, child] of Object.entries(node.s)) {
|
|
63
|
+
walkWSRoutes(child, `${currentPath}/${seg}`, routes)
|
|
64
|
+
}
|
|
65
|
+
if (node.d !== null) {
|
|
66
|
+
walkWSRoutes(node.d.c, `${currentPath}/:${node.d.n}`, routes)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function unwrapEntry(entry: InputSchemaEntry): StandardSchemaLike {
|
|
71
|
+
if ("_tag" in entry) {
|
|
72
|
+
return entry.schema as StandardSchemaLike
|
|
73
|
+
}
|
|
74
|
+
return entry
|
|
75
|
+
}
|