@kosmojs/api 0.0.11 → 0.0.21
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/LICENSE +21 -0
- package/package.json +15 -18
- package/pkg/debug.d.ts +16 -0
- package/pkg/errors/index.d.ts +21 -0
- package/pkg/errors/index.js +23 -0
- package/pkg/errors/index.js.map +7 -0
- package/pkg/errors/types.d.ts +43 -0
- package/pkg/index.d.ts +3 -0
- package/pkg/index.js +49 -198
- package/pkg/index.js.map +3 -3
- package/pkg/routes.d.ts +5 -0
- package/pkg/types.d.ts +285 -0
- package/pkg/bodyparser/index.js +0 -111
- package/pkg/bodyparser/index.js.map +0 -7
- package/pkg/queryparser/index.js +0 -37
- package/pkg/queryparser/index.js.map +0 -7
- package/pkg/src/app.d.ts +0 -2
- package/pkg/src/bodyparser/config.d.ts +0 -10
- package/pkg/src/bodyparser/index.d.ts +0 -14
- package/pkg/src/bodyparser/types.d.ts +0 -39
- package/pkg/src/debug.d.ts +0 -10
- package/pkg/src/errors.d.ts +0 -19
- package/pkg/src/index.d.ts +0 -5
- package/pkg/src/queryparser/index.d.ts +0 -5
- package/pkg/src/router.d.ts +0 -6
- package/pkg/src/types.d.ts +0 -136
- package/pkg/src/use.d.ts +0 -2
- package/pkg/test/defineRoute.test.d.ts +0 -1
- package/pkg/test/index.d.ts +0 -5
- package/pkg/test/routerRoutesFactory/params.test.d.ts +0 -1
- package/pkg/test/routerRoutesFactory/routeMiddleware.test.d.ts +0 -1
- package/pkg/test/routerRoutesFactory/useWrappers.test.d.ts +0 -1
- package/pkg/test/use.test.d.ts +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present, Slee Woo and KosmoJS contributors.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@kosmojs/api",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.21",
|
|
5
5
|
"author": "Slee Woo",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
@@ -12,36 +12,33 @@
|
|
|
12
12
|
],
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"types": "./pkg/
|
|
15
|
+
"types": "./pkg/index.d.ts",
|
|
16
16
|
"default": "./pkg/index.js"
|
|
17
17
|
},
|
|
18
|
-
"./
|
|
19
|
-
"types": "./pkg/
|
|
20
|
-
"default": "./pkg/
|
|
21
|
-
},
|
|
22
|
-
"./queryparser": {
|
|
23
|
-
"types": "./pkg/src/queryparser/index.d.ts",
|
|
24
|
-
"default": "./pkg/queryparser/index.js"
|
|
18
|
+
"./errors": {
|
|
19
|
+
"types": "./pkg/errors/index.d.ts",
|
|
20
|
+
"default": "./pkg/errors/index.js"
|
|
25
21
|
}
|
|
26
22
|
},
|
|
27
23
|
"dependencies": {
|
|
28
|
-
"@koa/router": "^15.
|
|
24
|
+
"@koa/router": "^15.3.1",
|
|
29
25
|
"formidable": "^3.5.4",
|
|
30
|
-
"koa": "^3.1.
|
|
31
|
-
"qs": "^6.
|
|
26
|
+
"koa": "^3.1.2",
|
|
27
|
+
"qs": "^6.15.0",
|
|
32
28
|
"raw-body": "^3.0.2",
|
|
33
|
-
"string-width": "^8.
|
|
29
|
+
"string-width": "^8.2.0"
|
|
34
30
|
},
|
|
35
31
|
"devDependencies": {
|
|
36
|
-
"@types/
|
|
32
|
+
"@types/bun": "^1.3.10",
|
|
33
|
+
"@types/formidable": "^3.5.0",
|
|
37
34
|
"@types/koa": "^3.0.1",
|
|
35
|
+
"@types/koa-compose": "^3.2.9",
|
|
38
36
|
"@types/picomatch": "^4.0.2",
|
|
39
|
-
"@types/qs": "^6.
|
|
40
|
-
"
|
|
41
|
-
"@kosmojs/devlib": "^0.0.11"
|
|
37
|
+
"@types/qs": "^6.15.0",
|
|
38
|
+
"koa-compose": "^4.1.0"
|
|
42
39
|
},
|
|
43
40
|
"scripts": {
|
|
44
|
-
"build": "esbuilder src/index.ts src/
|
|
41
|
+
"build": "esbuilder src/index.ts src/errors/index.ts",
|
|
45
42
|
"test": "vitest --root ../../.. --project core/api"
|
|
46
43
|
}
|
|
47
44
|
}
|
package/pkg/debug.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTTPMethod, Route, UseOptions } from "./types";
|
|
2
|
+
export declare const debugRouteEntry: <MiddlewareT>(entry: {
|
|
3
|
+
name: string;
|
|
4
|
+
path: string;
|
|
5
|
+
file: string;
|
|
6
|
+
methods: Array<string>;
|
|
7
|
+
middleware: Array<{
|
|
8
|
+
middleware: Array<MiddlewareT>;
|
|
9
|
+
options?: UseOptions | undefined;
|
|
10
|
+
}>;
|
|
11
|
+
handler: {
|
|
12
|
+
kind: "handler";
|
|
13
|
+
middleware: Array<MiddlewareT>;
|
|
14
|
+
method: HTTPMethod;
|
|
15
|
+
};
|
|
16
|
+
}) => Route<MiddlewareT>["debug"];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ValidationTarget } from "../types";
|
|
2
|
+
import type { ValidationErrorData, ValidationErrorEntry } from "./types";
|
|
3
|
+
export * from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Standardized error wrapper used by validation generators.
|
|
6
|
+
*
|
|
7
|
+
* Instances of this class are thrown whenever validation fails,
|
|
8
|
+
* carrying both the validation target and the list of validation error details.
|
|
9
|
+
* */
|
|
10
|
+
export declare class ValidationError extends Error {
|
|
11
|
+
target: ValidationTarget;
|
|
12
|
+
errors: Array<ValidationErrorEntry>;
|
|
13
|
+
errorMessage: string;
|
|
14
|
+
errorSummary: string;
|
|
15
|
+
route: string;
|
|
16
|
+
data: unknown;
|
|
17
|
+
constructor([target, { errors, errorMessage, errorSummary, route, data }]: [
|
|
18
|
+
ValidationTarget,
|
|
19
|
+
ValidationErrorData
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/errors/index.ts
|
|
2
|
+
var ValidationError = class extends Error {
|
|
3
|
+
target;
|
|
4
|
+
errors = [];
|
|
5
|
+
errorMessage;
|
|
6
|
+
errorSummary;
|
|
7
|
+
route;
|
|
8
|
+
data;
|
|
9
|
+
constructor([target, { errors, errorMessage, errorSummary, route, data }]) {
|
|
10
|
+
super(JSON.stringify(errors, null, 2));
|
|
11
|
+
this.name = `${target}ValidationError`;
|
|
12
|
+
this.target = target;
|
|
13
|
+
this.errors = errors;
|
|
14
|
+
this.errorMessage = errorMessage;
|
|
15
|
+
this.errorSummary = errorSummary;
|
|
16
|
+
this.route = route;
|
|
17
|
+
this.data = data;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
ValidationError
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/errors/index.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ValidationTarget } from \"../types\";\nimport type { ValidationErrorData, ValidationErrorEntry } from \"./types\";\n\nexport * from \"./types\";\n\n/**\n * Standardized error wrapper used by validation generators.\n *\n * Instances of this class are thrown whenever validation fails,\n * carrying both the validation target and the list of validation error details.\n * */\nexport class ValidationError extends Error {\n public target: ValidationTarget;\n public errors: Array<ValidationErrorEntry> = [];\n public errorMessage: string;\n public errorSummary: string;\n public route: string;\n public data: unknown;\n\n constructor([target, { errors, errorMessage, errorSummary, route, data }]: [\n ValidationTarget,\n ValidationErrorData,\n ]) {\n super(JSON.stringify(errors, null, 2));\n this.name = `${target}ValidationError`;\n this.target = target;\n this.errors = errors;\n this.errorMessage = errorMessage;\n this.errorSummary = errorSummary;\n this.route = route;\n this.data = data;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAWO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAClC;AAAA,EACA,SAAsC,CAAC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEP,YAAY,CAAC,QAAQ,EAAE,QAAQ,cAAc,cAAc,OAAO,KAAK,CAAC,GAGrE;AACD,UAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;AACrC,SAAK,OAAO,GAAG,MAAM;AACrB,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,eAAe;AACpB,SAAK,eAAe;AACpB,SAAK,QAAQ;AACb,SAAK,OAAO;AAAA,EACd;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape of individual validation errors emitted by generators.
|
|
3
|
+
* */
|
|
4
|
+
export type ValidationErrorEntry = {
|
|
5
|
+
/**
|
|
6
|
+
* JSON Schema keyword that triggered the error
|
|
7
|
+
* (e.g. `format`, `maxItems`, `maxLength`).
|
|
8
|
+
* */
|
|
9
|
+
keyword: string;
|
|
10
|
+
/**
|
|
11
|
+
* JSON Pointer–style path to the invalid field
|
|
12
|
+
* (matches JSON Schema `instancePath`).
|
|
13
|
+
* */
|
|
14
|
+
path: string;
|
|
15
|
+
/**
|
|
16
|
+
* Human-readable error message.
|
|
17
|
+
* */
|
|
18
|
+
message: string;
|
|
19
|
+
/**
|
|
20
|
+
* Constraint parameters (e.g. `{ limit: 5 }`, `{ format: "email" }`).
|
|
21
|
+
* */
|
|
22
|
+
params?: Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Optional error code for i18n/l10n or custom handling.
|
|
25
|
+
* */
|
|
26
|
+
code?: string;
|
|
27
|
+
};
|
|
28
|
+
export type ValidationErrorData = {
|
|
29
|
+
errors: Array<ValidationErrorEntry>;
|
|
30
|
+
/**
|
|
31
|
+
* Formats errors into a single human-readable message.
|
|
32
|
+
* @example: Validation failed: user: missing required properties:
|
|
33
|
+
* "email", "name"; password: must be at least 8 characters long
|
|
34
|
+
* */
|
|
35
|
+
errorMessage: string;
|
|
36
|
+
/**
|
|
37
|
+
* Gets a simple error summary for quick feedback.
|
|
38
|
+
* @example: 2 validation errors found across 2 fields
|
|
39
|
+
* */
|
|
40
|
+
errorSummary: string;
|
|
41
|
+
route: string;
|
|
42
|
+
data: unknown;
|
|
43
|
+
};
|
package/pkg/index.d.ts
ADDED
package/pkg/index.js
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
// src/app.ts
|
|
2
|
-
import Koa from "koa";
|
|
3
|
-
import withQueryparser from "@kosmojs/api/queryparser";
|
|
4
|
-
var createApp = (options) => {
|
|
5
|
-
return withQueryparser(new Koa(options));
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// src/errors.ts
|
|
9
|
-
var ValidationError = class extends Error {
|
|
10
|
-
scope;
|
|
11
|
-
errors = [];
|
|
12
|
-
errorMessage;
|
|
13
|
-
errorSummary;
|
|
14
|
-
constructor([scope, { errors, errorMessage, errorSummary }]) {
|
|
15
|
-
super(JSON.stringify(errors, null, 2));
|
|
16
|
-
this.name = `${scope}ValidationError`;
|
|
17
|
-
this.scope = scope;
|
|
18
|
-
this.errors = errors;
|
|
19
|
-
this.errorMessage = errorMessage;
|
|
20
|
-
this.errorSummary = errorSummary;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
var createErrorHandler = (handler) => handler;
|
|
24
|
-
|
|
25
|
-
// src/router.ts
|
|
26
|
-
import Router from "@koa/router";
|
|
27
|
-
|
|
28
1
|
// src/debug.ts
|
|
29
2
|
import { styleText } from "node:util";
|
|
30
3
|
import stringWidth from "string-width";
|
|
@@ -39,7 +12,7 @@ var colorizeMethod = (method) => {
|
|
|
39
12
|
}[method];
|
|
40
13
|
return color ? styleText(color, method) : method;
|
|
41
14
|
};
|
|
42
|
-
var
|
|
15
|
+
var debugRouteEntry = (entry) => {
|
|
43
16
|
const { path, file } = entry;
|
|
44
17
|
const methodLines = entry.methods.flatMap((method) => {
|
|
45
18
|
const coloredMethod = colorizeMethod(method);
|
|
@@ -49,13 +22,12 @@ var debug_default = (entry) => {
|
|
|
49
22
|
const lines = [];
|
|
50
23
|
if (options?.slot) {
|
|
51
24
|
lines.push(
|
|
52
|
-
`${styleText("dim", "slot:")} ${styleText("blue", options.slot)}
|
|
25
|
+
`${styleText("dim", "slot:")} ${styleText("blue", options.slot)}`
|
|
53
26
|
);
|
|
54
27
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
lines.push(`${styleText("dim", "exec:")} ${funcNames.join("; ")}`);
|
|
28
|
+
lines.push(
|
|
29
|
+
styleText("dim", middleware2.map(funcName).join("; "))
|
|
30
|
+
);
|
|
59
31
|
return lines.join(" ");
|
|
60
32
|
}).join(`
|
|
61
33
|
${Array(12).fill(" ").join("")}`);
|
|
@@ -99,113 +71,35 @@ var funcName = (fn) => {
|
|
|
99
71
|
return fn.name || fn.toString().split("\n")[0].slice(0, 30);
|
|
100
72
|
};
|
|
101
73
|
|
|
102
|
-
// src/
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
middleware: [middleware].flat(),
|
|
107
|
-
options
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// src/router.ts
|
|
112
|
-
var createRouter = (options) => {
|
|
113
|
-
return new Router(options);
|
|
114
|
-
};
|
|
115
|
-
var defineRoute = (factory) => {
|
|
116
|
-
return factory({
|
|
117
|
-
use(middleware, options) {
|
|
118
|
-
return {
|
|
119
|
-
kind: "middleware",
|
|
120
|
-
middleware: [middleware].flat(),
|
|
121
|
-
options
|
|
122
|
-
};
|
|
123
|
-
},
|
|
124
|
-
HEAD(middleware) {
|
|
125
|
-
return {
|
|
126
|
-
kind: "handler",
|
|
127
|
-
middleware: [middleware].flat(),
|
|
128
|
-
method: "HEAD"
|
|
129
|
-
};
|
|
130
|
-
},
|
|
131
|
-
OPTIONS(middleware) {
|
|
132
|
-
return {
|
|
133
|
-
kind: "handler",
|
|
134
|
-
middleware: [middleware].flat(),
|
|
135
|
-
method: "OPTIONS"
|
|
136
|
-
};
|
|
137
|
-
},
|
|
138
|
-
GET(middleware) {
|
|
139
|
-
return {
|
|
140
|
-
kind: "handler",
|
|
141
|
-
middleware: [middleware].flat(),
|
|
142
|
-
method: "GET"
|
|
143
|
-
};
|
|
144
|
-
},
|
|
145
|
-
POST(middleware) {
|
|
146
|
-
return {
|
|
147
|
-
kind: "handler",
|
|
148
|
-
middleware: [middleware].flat(),
|
|
149
|
-
method: "POST"
|
|
150
|
-
};
|
|
151
|
-
},
|
|
152
|
-
PUT(middleware) {
|
|
153
|
-
return {
|
|
154
|
-
kind: "handler",
|
|
155
|
-
middleware: [middleware].flat(),
|
|
156
|
-
method: "PUT"
|
|
157
|
-
};
|
|
158
|
-
},
|
|
159
|
-
PATCH(middleware) {
|
|
160
|
-
return {
|
|
161
|
-
kind: "handler",
|
|
162
|
-
middleware: [middleware].flat(),
|
|
163
|
-
method: "PATCH"
|
|
164
|
-
};
|
|
165
|
-
},
|
|
166
|
-
DELETE(middleware) {
|
|
167
|
-
return {
|
|
168
|
-
kind: "handler",
|
|
169
|
-
middleware: [middleware].flat(),
|
|
170
|
-
method: "DELETE"
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
var routerRoutesFactory = (routeSources, {
|
|
176
|
-
// Global middleware applied to every route (e.g., logging)
|
|
177
|
-
coreMiddleware
|
|
74
|
+
// src/routes.ts
|
|
75
|
+
var createRoutes = (routeSources, {
|
|
76
|
+
globalMiddleware,
|
|
77
|
+
createRouteMiddleware
|
|
178
78
|
}) => {
|
|
179
79
|
const prioritizedSlots = [
|
|
180
80
|
"errorHandler",
|
|
181
|
-
"
|
|
182
|
-
// Path params processing
|
|
183
|
-
"validateParams",
|
|
184
|
-
// Path params validation
|
|
81
|
+
"extendContext",
|
|
185
82
|
"bodyparser",
|
|
186
|
-
|
|
187
|
-
"
|
|
188
|
-
|
|
189
|
-
"
|
|
190
|
-
|
|
191
|
-
"
|
|
192
|
-
|
|
83
|
+
"validate:params",
|
|
84
|
+
"validate:query",
|
|
85
|
+
"validate:headers",
|
|
86
|
+
"validate:cookies",
|
|
87
|
+
"validate:json",
|
|
88
|
+
"validate:form",
|
|
89
|
+
"validate:raw",
|
|
90
|
+
"validate:response"
|
|
193
91
|
];
|
|
194
92
|
const stack = [];
|
|
195
|
-
for (const
|
|
93
|
+
for (const routeSource of routeSources) {
|
|
94
|
+
const { name, path, file } = routeSource;
|
|
196
95
|
const definitionItems = [
|
|
197
|
-
...
|
|
198
|
-
...
|
|
96
|
+
...routeSource.cascadingMiddleware,
|
|
97
|
+
...routeSource.definitionItems
|
|
199
98
|
].flat();
|
|
200
|
-
const routeMiddleware = definitionItems.filter(
|
|
201
|
-
(e) => e.kind === "middleware"
|
|
202
|
-
);
|
|
99
|
+
const routeMiddleware = definitionItems.filter((e) => e.kind === "middleware");
|
|
203
100
|
const middlewareStack = [
|
|
204
|
-
...
|
|
205
|
-
...
|
|
206
|
-
// core middleware overrides builtin middleware (of same slot)
|
|
207
|
-
...coreMiddleware,
|
|
208
|
-
// route middleware overrides core middleware (of same slot)
|
|
101
|
+
...createRouteMiddleware(routeSource),
|
|
102
|
+
...globalMiddleware,
|
|
209
103
|
...routeMiddleware
|
|
210
104
|
];
|
|
211
105
|
const routeStack = [
|
|
@@ -217,7 +111,7 @@ var routerRoutesFactory = (routeSources, {
|
|
|
217
111
|
);
|
|
218
112
|
return middleware ? [middleware] : [];
|
|
219
113
|
}),
|
|
220
|
-
...
|
|
114
|
+
...globalMiddleware.flatMap((entry) => {
|
|
221
115
|
if (!entry.options?.slot) {
|
|
222
116
|
return [entry];
|
|
223
117
|
}
|
|
@@ -237,7 +131,7 @@ var routerRoutesFactory = (routeSources, {
|
|
|
237
131
|
if (prioritizedSlots.includes(slot)) {
|
|
238
132
|
return [];
|
|
239
133
|
}
|
|
240
|
-
if (
|
|
134
|
+
if (globalMiddleware.some((e) => e.options?.slot === slot)) {
|
|
241
135
|
return [];
|
|
242
136
|
}
|
|
243
137
|
}
|
|
@@ -261,7 +155,7 @@ var routerRoutesFactory = (routeSources, {
|
|
|
261
155
|
...middleware.flatMap((e) => e.middleware),
|
|
262
156
|
...entry.middleware
|
|
263
157
|
],
|
|
264
|
-
debug:
|
|
158
|
+
debug: debugRouteEntry({
|
|
265
159
|
name,
|
|
266
160
|
path,
|
|
267
161
|
file,
|
|
@@ -275,63 +169,6 @@ var routerRoutesFactory = (routeSources, {
|
|
|
275
169
|
}
|
|
276
170
|
return stack;
|
|
277
171
|
};
|
|
278
|
-
var paramsMiddlewareFactory = (params, numericParams) => [
|
|
279
|
-
use(
|
|
280
|
-
function useParams(ctx, next) {
|
|
281
|
-
ctx.typedParams = params.reduce(
|
|
282
|
-
(map, [name, isRest]) => {
|
|
283
|
-
const value = ctx.params[name];
|
|
284
|
-
if (value) {
|
|
285
|
-
if (isRest) {
|
|
286
|
-
map[name] = numericParams.includes(name) ? value.split("/").map(Number) : value.split("/");
|
|
287
|
-
} else {
|
|
288
|
-
map[name] = numericParams.includes(name) ? Number(value) : value;
|
|
289
|
-
}
|
|
290
|
-
} else {
|
|
291
|
-
map[name] = value;
|
|
292
|
-
}
|
|
293
|
-
return map;
|
|
294
|
-
},
|
|
295
|
-
{}
|
|
296
|
-
);
|
|
297
|
-
return next();
|
|
298
|
-
},
|
|
299
|
-
{ slot: "params" }
|
|
300
|
-
)
|
|
301
|
-
];
|
|
302
|
-
var validationMiddlewareFactory = (validationSchemas) => [
|
|
303
|
-
use(
|
|
304
|
-
function useValidateParams(ctx, next) {
|
|
305
|
-
validationSchemas.params?.validate(ctx.typedParams);
|
|
306
|
-
return next();
|
|
307
|
-
},
|
|
308
|
-
{ slot: "validateParams" }
|
|
309
|
-
),
|
|
310
|
-
use(
|
|
311
|
-
function useValidatePayload(ctx, next) {
|
|
312
|
-
validationSchemas.payload?.[ctx.method]?.validate(ctx.payload);
|
|
313
|
-
return next();
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
slot: "validatePayload",
|
|
317
|
-
on: Object.keys(validationSchemas.payload || {})
|
|
318
|
-
}
|
|
319
|
-
),
|
|
320
|
-
use(
|
|
321
|
-
async function useValidateResponse(ctx, next) {
|
|
322
|
-
if (validationSchemas.response?.[ctx.method]) {
|
|
323
|
-
await next();
|
|
324
|
-
validationSchemas.response?.[ctx.method]?.validate(ctx.body);
|
|
325
|
-
} else {
|
|
326
|
-
return next();
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
slot: "validateResponse",
|
|
331
|
-
on: Object.keys(validationSchemas.response || {})
|
|
332
|
-
}
|
|
333
|
-
)
|
|
334
|
-
];
|
|
335
172
|
|
|
336
173
|
// src/types.ts
|
|
337
174
|
var HTTPMethods = /* @__PURE__ */ ((HTTPMethods2) => {
|
|
@@ -344,14 +181,28 @@ var HTTPMethods = /* @__PURE__ */ ((HTTPMethods2) => {
|
|
|
344
181
|
HTTPMethods2["DELETE"] = "DELETE";
|
|
345
182
|
return HTTPMethods2;
|
|
346
183
|
})(HTTPMethods || {});
|
|
184
|
+
var RequestMetadataTargets = {
|
|
185
|
+
query: "URL query parameters",
|
|
186
|
+
headers: "HTTP request headers",
|
|
187
|
+
cookies: "HTTP cookies"
|
|
188
|
+
};
|
|
189
|
+
var RequestBodyTargets = {
|
|
190
|
+
json: "JSON request body",
|
|
191
|
+
form: "URL-encoded or Multipart form",
|
|
192
|
+
raw: "Raw body format (string/Buffer/ArrayBuffer/Blob)"
|
|
193
|
+
};
|
|
194
|
+
var RequestValidationTargets = {
|
|
195
|
+
...RequestMetadataTargets,
|
|
196
|
+
...RequestBodyTargets
|
|
197
|
+
};
|
|
198
|
+
var StateKey = /* @__PURE__ */ Symbol("kosmo.state");
|
|
347
199
|
export {
|
|
348
200
|
HTTPMethods,
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
use
|
|
201
|
+
RequestBodyTargets,
|
|
202
|
+
RequestMetadataTargets,
|
|
203
|
+
RequestValidationTargets,
|
|
204
|
+
StateKey,
|
|
205
|
+
createRoutes,
|
|
206
|
+
debugRouteEntry
|
|
356
207
|
};
|
|
357
208
|
//# sourceMappingURL=index.js.map
|
package/pkg/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
4
|
-
"sourcesContent": ["import Koa from \"koa\";\n\nimport withQueryparser from \"@kosmojs/api/queryparser\";\n\nimport type { CreateApp } from \"./types\";\n\nexport const createApp: CreateApp = (options) => {\n return withQueryparser(new Koa(options));\n};\n", "import type {\n ParameterizedMiddleware,\n ValidationErrorData,\n ValidationErrorEntry,\n ValidationErrorScope,\n} from \"./types\";\n\n/**\n * Standardized error wrapper used by validation generators.\n *\n * Instances of this class are thrown whenever validation fails,\n * carrying both the error scope (e.g. `\"params\"`, `\"payload\"`)\n * and the list of validation error details.\n */\nexport class ValidationError extends Error {\n public scope: ValidationErrorScope;\n public errors: Array<ValidationErrorEntry> = [];\n public errorMessage: string;\n public errorSummary: string;\n\n constructor([scope, { errors, errorMessage, errorSummary }]: [\n ValidationErrorScope,\n ValidationErrorData,\n ]) {\n super(JSON.stringify(errors, null, 2));\n this.name = `${scope}ValidationError`;\n this.scope = scope;\n this.errors = errors;\n this.errorMessage = errorMessage;\n this.errorSummary = errorSummary;\n }\n}\n\nexport const createErrorHandler = (handler: ParameterizedMiddleware) => handler;\n", "import Router, { type RouterMiddleware } from \"@koa/router\";\n\nimport debugRouteEntry from \"./debug\";\nimport type {\n CreateRouter,\n DefineRoute,\n HandlerDefinition,\n MiddlewareDefinition,\n RouterRoute,\n RouterRouteSource,\n UseSlots,\n ValidationSchemas,\n} from \"./types\";\nimport { use } from \"./use\";\n\nexport const createRouter: CreateRouter = (options) => {\n return new Router(options);\n};\n\nexport const defineRoute: DefineRoute = (factory) => {\n return factory({\n use(middleware, options) {\n return {\n kind: \"middleware\",\n middleware: [middleware as never].flat(),\n options,\n };\n },\n HEAD(middleware) {\n return {\n kind: \"handler\",\n middleware: [middleware as never].flat(),\n method: \"HEAD\",\n };\n },\n OPTIONS(middleware) {\n return {\n kind: \"handler\",\n middleware: [middleware as never].flat(),\n method: \"OPTIONS\",\n };\n },\n GET(middleware) {\n return {\n kind: \"handler\",\n middleware: [middleware as never].flat(),\n method: \"GET\",\n };\n },\n POST(middleware) {\n return {\n kind: \"handler\",\n middleware: [middleware as never].flat(),\n method: \"POST\",\n };\n },\n PUT(middleware) {\n return {\n kind: \"handler\",\n middleware: [middleware as never].flat(),\n method: \"PUT\",\n };\n },\n PATCH(middleware) {\n return {\n kind: \"handler\",\n middleware: [middleware as never].flat(),\n method: \"PATCH\",\n };\n },\n DELETE(middleware) {\n return {\n kind: \"handler\",\n middleware: [middleware as never].flat(),\n method: \"DELETE\",\n };\n },\n });\n};\n\nexport const routerRoutesFactory = (\n routeSources: Array<RouterRouteSource>,\n {\n // Global middleware applied to every route (e.g., logging)\n coreMiddleware,\n }: {\n coreMiddleware: Array<MiddlewareDefinition>;\n },\n): Array<RouterRoute> => {\n // WARN:: prioritized middleware must run in this exact order!\n const prioritizedSlots: Array<keyof UseSlots> = [\n \"errorHandler\",\n \"params\", // Path params processing\n \"validateParams\", // Path params validation\n \"bodyparser\", // Raw request body parsing\n \"payload\", // Set ctx.payload\n \"validatePayload\", // Payload validation\n \"validateResponse\", // Response validation\n ];\n\n const stack: Array<RouterRoute> = [];\n\n // Iterate over each route definition\n for (const { name, path, file, ...rest } of routeSources) {\n // Include both middleware and HTTP method handlers\n const definitionItems = [\n ...rest.useWrappers,\n ...rest.definitionItems,\n ].flat();\n\n const routeMiddleware: Array<MiddlewareDefinition> = definitionItems.filter(\n (e) => e.kind === \"middleware\",\n );\n\n // WARN: the order is critical!\n // the last defined middleware will take precedence.\n const middlewareStack: Array<MiddlewareDefinition> = [\n ...paramsMiddlewareFactory(rest.params, rest.numericParams),\n ...validationMiddlewareFactory(rest.validationSchemas),\n // core middleware overrides builtin middleware (of same slot)\n ...coreMiddleware,\n // route middleware overrides core middleware (of same slot)\n ...routeMiddleware,\n ];\n\n const routeStack: Array<MiddlewareDefinition | HandlerDefinition> = [\n ...prioritizedSlots.flatMap((slot) => {\n const middleware = middlewareStack.findLast(\n // Using findLast to pick the latest entry,\n // ensuring later entries override earlier ones.\n (e) => e.options?.slot === slot,\n );\n return middleware //\n ? [middleware]\n : [];\n }),\n\n ...coreMiddleware.flatMap((entry) => {\n if (!entry.options?.slot) {\n // no slot, including regardless\n return [entry];\n }\n if (prioritizedSlots.includes(entry.options?.slot)) {\n // already picked when inserted prioritized middleware, excluding\n return [];\n }\n const override = routeMiddleware.findLast(\n // Using findLast to pick the latest entry,\n // ensuring later entries override earlier ones.\n (e) => e.options?.slot === entry.options?.slot,\n );\n return [override || entry];\n }),\n\n ...definitionItems.flatMap((entry) => {\n const slot =\n entry.kind === \"middleware\" //\n ? entry.options?.slot\n : undefined;\n\n if (slot) {\n if (prioritizedSlots.includes(slot)) {\n // already picked when inserted prioritized middleware, excluding\n return [];\n }\n if (coreMiddleware.some((e) => e.options?.slot === slot)) {\n // already picked when inserted core middleware, excluding\n return [];\n }\n }\n\n return [entry];\n }),\n ];\n\n for (const entry of routeStack) {\n if (entry.kind === \"handler\") {\n const middleware = routeStack.flatMap((e) => {\n if (e.kind === \"middleware\") {\n return !e.options?.on || e.options.on.includes(entry.method)\n ? [e]\n : [];\n }\n return [];\n });\n stack.push({\n name,\n path,\n file,\n methods: [entry.method],\n middleware: [\n ...middleware.flatMap((e) => e.middleware),\n ...entry.middleware,\n ] as unknown as Array<RouterMiddleware>,\n debug: debugRouteEntry({\n name,\n path,\n file,\n methods: [entry.method],\n middleware,\n handler: entry,\n }),\n });\n }\n }\n }\n\n return stack;\n};\n\nconst paramsMiddlewareFactory = (\n params: RouterRouteSource[\"params\"],\n numericParams: RouterRouteSource[\"numericParams\"],\n) => [\n use(\n function useParams(ctx, next) {\n ctx.typedParams = params.reduce(\n (map: Record<string, unknown>, [name, isRest]) => {\n const value = ctx.params[name];\n if (value) {\n if (isRest) {\n map[name] = numericParams.includes(name)\n ? value.split(\"/\").map(Number)\n : value.split(\"/\");\n } else {\n map[name] = numericParams.includes(name) ? Number(value) : value;\n }\n } else {\n map[name] = value;\n }\n return map;\n },\n {},\n ) as never;\n return next();\n },\n { slot: \"params\" },\n ),\n];\n\nconst validationMiddlewareFactory = (validationSchemas: ValidationSchemas) => [\n use(\n function useValidateParams(ctx, next) {\n validationSchemas.params?.validate(ctx.typedParams);\n return next();\n },\n { slot: \"validateParams\" },\n ),\n\n use(\n function useValidatePayload(ctx, next) {\n validationSchemas.payload?.[ctx.method]?.validate(ctx.payload);\n return next();\n },\n {\n slot: \"validatePayload\",\n on: Object.keys(validationSchemas.payload || {}) as never,\n },\n ),\n\n use(\n async function useValidateResponse(ctx, next) {\n if (validationSchemas.response?.[ctx.method]) {\n await next();\n validationSchemas.response?.[ctx.method]?.validate(ctx.body);\n } else {\n return next();\n }\n },\n {\n slot: \"validateResponse\",\n on: Object.keys(validationSchemas.response || {}) as never,\n },\n ),\n];\n", "import { styleText } from \"node:util\";\n\nimport stringWidth from \"string-width\";\n\nimport type {\n HandlerDefinition,\n MiddlewareDefinition,\n RouterRoute,\n} from \"./types\";\n\nconst colorizeMethod = (method: string): string => {\n const color = (\n {\n HEAD: \"gray\",\n GET: \"green\",\n POST: \"blue\",\n PATCH: \"blue\",\n PUT: \"blue\",\n DELETE: \"red\",\n } as const\n )[method];\n return color ? styleText(color, method) : method;\n};\n\nexport default (entry: {\n name: string;\n path: string;\n file: string;\n methods: Array<string>;\n middleware: Array<MiddlewareDefinition>;\n handler: HandlerDefinition;\n}): RouterRoute[\"debug\"] => {\n const { path, file } = entry;\n\n const methodLines = entry.methods.flatMap((method) => {\n const coloredMethod = colorizeMethod(method);\n return method === \"GET\"\n ? [coloredMethod + styleText(\"gray\", \"|HEAD\")]\n : [coloredMethod];\n });\n\n const middlewareLines = entry.middleware\n .map(({ options, middleware }) => {\n const lines: Array<string> = [];\n\n if (options?.slot) {\n lines.push(\n `${styleText(\"dim\", \"slot:\")} ${styleText(\"blue\", options.slot)};`,\n );\n }\n\n const funcNames = middleware.map((fn) => {\n return styleText(\"magenta\", funcName(fn));\n });\n\n lines.push(`${styleText(\"dim\", \"exec:\")} ${funcNames.join(\"; \")}`);\n\n return lines.join(\" \");\n })\n .join(`\\n${Array(12).fill(\" \").join(\"\")}`);\n\n const handlerLines = entry.handler.middleware.map((fn) => {\n return styleText(\"yellow\", funcName(fn));\n });\n\n const headline = `${styleText(\"bgBlue\", styleText(\"black\", ` ${path} `))} ${styleText(\"gray\", `[ ${file} ]`)}`;\n const methods = `${styleText(\"dim\", \" methods:\")} ${methodLines.join(\" \")}`;\n const middleware = `${styleText(\"dim\", \"middleware:\")} ${middlewareLines}`;\n const handler = `${styleText(\"dim\", \" handler:\")} ${handlerLines.join(Array(7).fill(\" \").join(\"\"))}`;\n\n const maxColumns = process.stdout.isTTY\n ? Number(process.stdout.columns || 80)\n : 80;\n\n const debugEntries = [\n [\"headline\", headline],\n [\"methods\", methods],\n [\"middleware\", middleware],\n [\"handler\", handler],\n ] as const;\n\n const lineMapper = (line: string) => {\n const freeColumns = maxColumns - stringWidth(line);\n return freeColumns > 0\n ? [\n line,\n styleText(\n \"dim\",\n styleText(\"gray\", Array(freeColumns).fill(\"\u00B7\").join(\"\")),\n ),\n ].join(\"\")\n : line;\n };\n\n const debug = debugEntries.reduce(\n (map, [key, line]) => {\n map[key] = line.split(\"\\n\").map(lineMapper).join(\"\\n\");\n return map;\n },\n {} as RouterRoute[\"debug\"],\n );\n\n return {\n ...debug,\n full: Object.values(debug).join(\"\\n\"),\n };\n};\n\nconst funcName = (fn: Function) => {\n return fn.name || fn.toString().split(\"\\n\")[0].slice(0, 30);\n};\n", "import type { Use } from \"./types\";\n\nexport const use: Use = (middleware, options) => {\n return {\n kind: \"middleware\",\n middleware: [middleware].flat() as never,\n options,\n };\n};\n", "import type {\n RouterContext,\n RouterMiddleware,\n RouterOptions,\n} from \"@koa/router\";\nimport type { Next } from \"koa\";\n\ndeclare module \"koa\" {\n interface Request {\n body?: unknown;\n rawBody: string;\n }\n}\n\nexport interface DefaultState {}\nexport interface DefaultContext {}\n\nexport enum HTTPMethods {\n HEAD = \"HEAD\",\n OPTIONS = \"OPTIONS\",\n GET = \"GET\",\n PUT = \"PUT\",\n PATCH = \"PATCH\",\n POST = \"POST\",\n DELETE = \"DELETE\",\n}\n\nexport type HTTPMethod = keyof typeof HTTPMethods;\n\nexport type ParameterizedContext<\n ParamsT,\n StateT,\n ContextT,\n PayloadT = unknown,\n ResponseT = unknown,\n> = RouterContext<\n DefaultState & StateT,\n DefaultContext &\n ContextT & {\n typedParams: ParamsT;\n payload: PayloadT;\n },\n ResponseT\n>;\n\nexport type ParameterizedMiddleware<\n ParamsT = {},\n StateT = {},\n ContextT = {},\n> = (\n ctx: ParameterizedContext<ParamsT, StateT, ContextT>,\n next: Next,\n) => Promise<void> | void;\n\nexport type RouteHandler<\n ParamsT,\n StateT,\n ContextT,\n PayloadT = unknown,\n ResponseT = unknown,\n> = (\n ctx: ParameterizedContext<ParamsT, StateT, ContextT, PayloadT, ResponseT>,\n next: Next,\n) => Promise<void> | void;\n\nexport type MiddlewareDefinition = {\n kind: \"middleware\";\n middleware: Array<ParameterizedMiddleware>;\n options?: UseOptions | undefined;\n};\n\nexport type HandlerDefinition = {\n kind: \"handler\";\n middleware: Array<ParameterizedMiddleware>;\n method: HTTPMethod;\n};\n\nexport type RouteDefinitionItem = MiddlewareDefinition | HandlerDefinition;\n\nexport type DefineRouteHelpers<\n ParamsT,\n StateT,\n ContextT,\n OptionalHandlers = undefined,\n> = {\n // INFO: The `use` helper intentionally does not accept type parameters.\n // PayloadT and ResponseT are only relevant to route handlers,\n // as different request methods receive different payloads and return different responses.\n // Allowing these type parameters on `use` would be misleading,\n // since middleware operates across multiple request methods with varying types.\n use: (\n middleware:\n | ParameterizedMiddleware<ParamsT, StateT, ContextT>\n | Array<ParameterizedMiddleware<ParamsT, StateT, ContextT>>,\n options?: UseOptions,\n ) => RouteDefinitionItem;\n} & {\n [M in HTTPMethod]: M extends OptionalHandlers\n ? <PayloadT = unknown, ResponseT = unknown>(\n handler?:\n | RouteHandler<ParamsT, StateT, ContextT, PayloadT, ResponseT>\n | Array<RouteHandler<ParamsT, StateT, ContextT, PayloadT, ResponseT>>,\n ) => RouteDefinitionItem\n : <PayloadT = unknown, ResponseT = unknown>(\n handler:\n | RouteHandler<ParamsT, StateT, ContextT, PayloadT, ResponseT>\n | Array<RouteHandler<ParamsT, StateT, ContextT, PayloadT, ResponseT>>,\n ) => RouteDefinitionItem;\n};\n\nexport type DefineRoute = <\n ParamsT = Record<string, string>,\n StateT = object,\n ContextT = object,\n>(\n factory: (\n helpers: DefineRouteHelpers<ParamsT, StateT, ContextT>,\n ) => Array<RouteDefinitionItem>,\n) => Array<RouteDefinitionItem>;\n\nexport interface UseSlots {\n errorHandler: string;\n params: string;\n validateParams: string;\n bodyparser: string;\n payload: string;\n validatePayload: string;\n validateResponse: string;\n}\n\nexport type UseOptions = {\n on?: Array<HTTPMethod>;\n slot?: keyof UseSlots;\n debug?: string | undefined;\n};\n\nexport type Use = <StateT = DefaultState, ContextT = DefaultContext>(\n middleware:\n | ParameterizedMiddleware<Record<string, string>, StateT, ContextT>\n | Array<ParameterizedMiddleware<Record<string, string>, StateT, ContextT>>,\n options?: UseOptions,\n) => MiddlewareDefinition;\n\nexport type RouterRouteSource = {\n name: string;\n path: string;\n file: string;\n // useWrappers is same as defining middleware inside route definition,\n // just automatically imported from use.ts files\n useWrappers: [...a: Array<MiddlewareDefinition>];\n definitionItems: Array<RouteDefinitionItem>;\n params: Array<[name: string, isRest?: boolean]>;\n numericParams: Array<string>;\n validationSchemas: ValidationSchemas;\n meta?: Record<string, unknown>;\n};\n\nexport type RouterRoute = {\n name: string;\n path: string;\n file: string;\n methods: Array<string>;\n middleware: Array<RouterMiddleware>;\n debug: {\n headline: string;\n methods: string;\n middleware: string;\n handler: string;\n full: string;\n };\n};\n\nimport type Koa from \"koa\";\nexport type App = Koa<DefaultState, DefaultContext>;\nexport type AppOptions = ConstructorParameters<typeof import(\"koa\")>[0];\nexport type CreateApp = (options?: AppOptions) => App;\n\nimport type KoaRouter from \"@koa/router\";\nexport type Router = KoaRouter<DefaultState, DefaultContext>;\nexport type { RouterOptions };\nexport type CreateRouter = (options?: RouterOptions) => Router;\n\nexport type DevMiddlewareFactory = (\n app: App,\n) => (\n req: import(\"node:http\").IncomingMessage,\n res: import(\"node:http\").ServerResponse,\n next: () => Promise<void>,\n) => Promise<void>;\nexport type TeardownHandler = (app: App) => void | Promise<void>;\n\nexport type ValidationSchema = {\n check: (data: unknown) => boolean;\n errors: (data: unknown) => Array<ValidationErrorEntry>;\n errorMessage: (data: unknown) => string;\n errorSummary: (data: unknown) => string;\n validate: (data: unknown) => void;\n};\n\nexport type ValidationSchemas<Extend = object> = {\n params?: ValidationSchema & Extend;\n payload?: Record<string, ValidationSchema & Extend>;\n response?: Record<string, ValidationSchema & Extend>;\n};\n\nexport type ValidationErrorScope = \"params\" | \"payload\" | \"response\";\n\n/**\n * Shape of individual validation errors emitted by generators.\n */\nexport type ValidationErrorEntry = {\n /** JSON Schema keyword that triggered the error (e.g. `format`, `maxItems`, `maxLength`). */\n keyword: string;\n /** JSON Pointer\u2013style path to the invalid field (matches JSON Schema `instancePath`). */\n path: string;\n /** Human-readable error message. */\n message: string;\n /** Constraint parameters (e.g. `{ limit: 5 }`, `{ format: \"email\" }`). */\n params?: Record<string, unknown>;\n /** Optional error code for i18n/l10n or custom handling. */\n code?: string;\n};\n\nexport type ValidationErrorData = {\n errors: Array<ValidationErrorEntry>;\n /**\n * Formats errors into a single human-readable message.\n * @example: Validation failed: user: missing required properties: \"email\", \"name\"; password: must be at least 8 characters long\n */\n errorMessage: string;\n /**\n * Gets a simple error summary for quick feedback.\n * @example: 2 validation errors found across 2 fields\n */\n errorSummary: string;\n};\n"],
|
|
5
|
-
"mappings": ";AAAA,
|
|
3
|
+
"sources": ["../src/debug.ts", "../src/routes.ts", "../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["import { styleText } from \"node:util\";\n\nimport stringWidth from \"string-width\";\n\nimport type { HTTPMethod, Route, UseOptions } from \"./types\";\n\nconst colorizeMethod = (method: string): string => {\n const color = (\n {\n HEAD: \"gray\",\n GET: \"green\",\n POST: \"blue\",\n PATCH: \"blue\",\n PUT: \"blue\",\n DELETE: \"red\",\n } as const\n )[method];\n return color ? styleText(color, method) : method;\n};\n\nexport const debugRouteEntry = <MiddlewareT>(entry: {\n name: string;\n path: string;\n file: string;\n methods: Array<string>;\n middleware: Array<{\n middleware: Array<MiddlewareT>;\n options?: UseOptions | undefined;\n }>;\n handler: {\n kind: \"handler\";\n middleware: Array<MiddlewareT>;\n method: HTTPMethod;\n };\n}): Route<MiddlewareT>[\"debug\"] => {\n const { path, file } = entry;\n\n const methodLines = entry.methods.flatMap((method) => {\n const coloredMethod = colorizeMethod(method);\n return method === \"GET\"\n ? [coloredMethod + styleText(\"gray\", \"|HEAD\")]\n : [coloredMethod];\n });\n\n const middlewareLines = entry.middleware\n .map(({ options, middleware }) => {\n const lines: Array<string> = [];\n\n if (options?.slot) {\n lines.push(\n `${styleText(\"dim\", \"slot:\")} ${styleText(\"blue\", options.slot)}`,\n );\n }\n\n lines.push(\n styleText(\"dim\", middleware.map(funcName as never).join(\"; \")),\n );\n\n return lines.join(\" \");\n })\n .join(`\\n${Array(12).fill(\" \").join(\"\")}`);\n\n const handlerLines = entry.handler.middleware.map((fn) => {\n return styleText(\"yellow\", funcName(fn as Function));\n });\n\n const headline = `${styleText(\"bgBlue\", styleText(\"black\", ` ${path} `))} ${styleText(\"gray\", `[ ${file} ]`)}`;\n const methods = `${styleText(\"dim\", \" methods:\")} ${methodLines.join(\" \")}`;\n const middleware = `${styleText(\"dim\", \"middleware:\")} ${middlewareLines}`;\n const handler = `${styleText(\"dim\", \" handler:\")} ${handlerLines.join(Array(7).fill(\" \").join(\"\"))}`;\n\n const maxColumns = process.stdout.isTTY\n ? Number(process.stdout.columns || 80)\n : 80;\n\n const debugEntries = [\n [\"headline\", headline],\n [\"methods\", methods],\n [\"middleware\", middleware],\n [\"handler\", handler],\n ] as const;\n\n const lineMapper = (line: string) => {\n const freeColumns = maxColumns - stringWidth(line);\n return freeColumns > 0\n ? [\n line,\n styleText(\n \"dim\",\n styleText(\"gray\", Array(freeColumns).fill(\"\u00B7\").join(\"\")),\n ),\n ].join(\"\")\n : line;\n };\n\n const debug = debugEntries.reduce(\n (map, [key, line]) => {\n map[key] = line.split(\"\\n\").map(lineMapper).join(\"\\n\");\n return map;\n },\n {} as Route<MiddlewareT>[\"debug\"],\n );\n\n return {\n ...debug,\n full: Object.values(debug).join(\"\\n\"),\n };\n};\n\nconst funcName = (fn: Function) => {\n return fn.name || fn.toString().split(\"\\n\")[0].slice(0, 30);\n};\n", "import { debugRouteEntry } from \"./debug\";\nimport type {\n CreateRouteMiddleware,\n HandlerDefinition,\n MiddlewareDefinition,\n Route,\n RouteSource,\n UseSlots,\n} from \"./types\";\n\nexport const createRoutes = <MiddlewareT, MiddlewareR>(\n routeSources: Array<RouteSource<MiddlewareT>>,\n {\n globalMiddleware,\n createRouteMiddleware,\n }: {\n // Global middleware applied to every route (e.g., logging)\n globalMiddleware: Array<MiddlewareDefinition<MiddlewareT>>;\n // route-specific middlware\n createRouteMiddleware: CreateRouteMiddleware<MiddlewareT>;\n },\n): Array<Route<MiddlewareR>> => {\n // NOTE:: prioritized middleware must run in this exact order!\n const prioritizedSlots: Array<keyof UseSlots> = [\n \"errorHandler\",\n \"extendContext\",\n \"bodyparser\",\n \"validate:params\",\n \"validate:query\",\n \"validate:headers\",\n \"validate:cookies\",\n \"validate:json\",\n \"validate:form\",\n \"validate:raw\",\n \"validate:response\",\n ];\n\n const stack: Array<Route<MiddlewareR>> = [];\n\n // Iterate over each route definition\n for (const routeSource of routeSources) {\n const { name, path, file } = routeSource;\n\n // Include both middleware and HTTP method handlers\n const definitionItems = [\n ...routeSource.cascadingMiddleware,\n ...routeSource.definitionItems,\n ].flat();\n\n const routeMiddleware: Array<MiddlewareDefinition<MiddlewareT>> =\n definitionItems.filter((e) => e.kind === \"middleware\");\n\n // NOTE: should be built in exactly this order\n const middlewareStack: Array<MiddlewareDefinition<MiddlewareT>> = [\n ...createRouteMiddleware(routeSource),\n ...globalMiddleware,\n ...routeMiddleware,\n ];\n\n // NOTE: later defined middleware should override previous middleware of same slot\n const routeStack: Array<\n MiddlewareDefinition<MiddlewareT> | HandlerDefinition<MiddlewareT>\n > = [\n ...prioritizedSlots.flatMap((slot) => {\n const middleware = middlewareStack.findLast(\n // Using findLast to pick the latest entry,\n // ensuring later entries override earlier ones.\n (e) => e.options?.slot === slot,\n );\n return middleware //\n ? [middleware]\n : [];\n }),\n\n ...globalMiddleware.flatMap((entry) => {\n if (!entry.options?.slot) {\n // no slot, including regardless\n return [entry];\n }\n if (prioritizedSlots.includes(entry.options?.slot)) {\n // already picked when inserted prioritized middleware, excluding\n return [];\n }\n const override = routeMiddleware.findLast(\n // Using findLast to pick the latest entry,\n // ensuring later entries override earlier ones.\n (e) => e.options?.slot === entry.options?.slot,\n );\n return [override || entry];\n }),\n\n ...definitionItems.flatMap((entry) => {\n const slot =\n entry.kind === \"middleware\" //\n ? entry.options?.slot\n : undefined;\n\n if (slot) {\n if (prioritizedSlots.includes(slot)) {\n // already picked when inserted prioritized middleware, excluding\n return [];\n }\n if (globalMiddleware.some((e) => e.options?.slot === slot)) {\n // already picked when inserted core middleware, excluding\n return [];\n }\n }\n\n return [entry];\n }),\n ];\n\n for (const entry of routeStack) {\n if (entry.kind === \"handler\") {\n const middleware = routeStack.flatMap((e) => {\n if (e.kind === \"middleware\") {\n return !e.options?.on || e.options.on.includes(entry.method)\n ? [e]\n : [];\n }\n return [];\n });\n stack.push({\n name,\n path,\n file,\n methods: [entry.method],\n middleware: [\n ...middleware.flatMap((e) => e.middleware),\n ...entry.middleware,\n ] as Array<never>,\n debug: debugRouteEntry<MiddlewareT>({\n name,\n path,\n file,\n methods: [entry.method],\n middleware,\n handler: entry,\n }),\n });\n }\n }\n }\n\n return stack;\n};\n", "/// <reference types=\"@types/bun\" />\n\nimport type { ValidationErrorEntry } from \"./errors/types\";\n\nexport enum HTTPMethods {\n HEAD = \"HEAD\",\n OPTIONS = \"OPTIONS\",\n GET = \"GET\",\n PUT = \"PUT\",\n PATCH = \"PATCH\",\n POST = \"POST\",\n DELETE = \"DELETE\",\n}\n\nexport type HTTPMethod = keyof typeof HTTPMethods;\n\nexport type MiddlewareDefinition<MiddlewareT> = {\n kind: \"middleware\";\n middleware: Array<MiddlewareT>;\n options?: UseOptions | undefined;\n};\n\nexport type HandlerDefinition<MiddlewareT> = {\n kind: \"handler\";\n middleware: Array<MiddlewareT>;\n method: HTTPMethod;\n};\n\nexport type RouteDefinitionItem<MiddlewareT> =\n | MiddlewareDefinition<MiddlewareT>\n | HandlerDefinition<MiddlewareT>;\n\nexport interface UseSlots {\n errorHandler: string;\n extendContext: string;\n bodyparser: string;\n \"validate:params\": string;\n \"validate:query\": string;\n \"validate:headers\": string;\n \"validate:cookies\": string;\n \"validate:json\": string;\n \"validate:form\": string;\n \"validate:raw\": string;\n \"validate:response\": string;\n}\n\nexport type UseOptions = {\n on?: Array<HTTPMethod>;\n slot?: keyof UseSlots;\n debug?: string | undefined;\n};\n\nexport type RouteSource<MiddlewareT> = {\n name: string;\n path: string;\n // path-to-regexp pattern\n pathPattern: string;\n file: string;\n // same as inline middleware inside route definition,\n // just automatically imported from use.ts files\n cascadingMiddleware: [...a: Array<MiddlewareDefinition<MiddlewareT>>];\n definitionItems: Array<RouteDefinitionItem<MiddlewareT>>;\n params: Array<string>;\n numericParams: Array<string>;\n validationSchemas: ValidationSchemas;\n meta?: Record<string, unknown>;\n};\n\nexport type Route<MiddlewareT> = {\n name: string;\n path: string;\n file: string;\n methods: Array<string>;\n middleware: Array<MiddlewareT>;\n debug: {\n headline: string;\n methods: string;\n middleware: string;\n handler: string;\n full: string;\n };\n};\n\nexport type DevSetup = {\n /**\n * API request handler for development mode.\n *\n * In dev mode, incoming requests are routed based on URL:\n * - Requests matching apiurl routed to this handler (your API)\n * - All other requests routed to Vite dev server (pages/assets)\n *\n * Returns a function that processes API requests.\n * */\n requestHandler: () => (\n req: import(\"node:http\").IncomingMessage,\n res: import(\"node:http\").ServerResponse,\n ) => Promise<void>;\n\n /**\n * Custom function to determine if a request should be handled by the API.\n *\n * By default, requests are routed to the API handler if their URL starts with `apiurl`.\n * Use this to implement custom heuristics for detecting API requests.\n * */\n requestMatcher?: (req: import(\"node:http\").IncomingMessage) => boolean;\n\n /**\n * In dev mode, perform cleanup operations before reloading the API handler.\n * */\n teardownHandler?: () => void | Promise<void>;\n};\n\nexport type AppFactory<App, AppOptions = unknown> = (\n factory: (a: { createApp: (o?: AppOptions) => App }) => App,\n) => App;\n\nexport type RouterFactory<Router, RouterOptions = unknown> = (\n factory: (a: { createRouter: (o?: RouterOptions) => Router }) => Router,\n) => Router;\n\nexport type CreateRouteMiddleware<MiddlewareT> = (\n routeSource: RouteSource<MiddlewareT>,\n) => Array<MiddlewareDefinition<MiddlewareT>>;\n\nexport type CreateServer<App, Server> = (\n app: App,\n opt?: {\n port?: number;\n sock?: string;\n callback?: () => void | Promise<void>;\n },\n) => Promise<Server>;\n\nexport type ServerFactory<App, Server> = (\n factory: (a: { createServer: CreateServer<App, Server> }) => void,\n) => void;\n\n/**\n * Request metadata validation targets.\n * */\nexport const RequestMetadataTargets = {\n query: \"URL query parameters\",\n headers: \"HTTP request headers\",\n cookies: \"HTTP cookies\",\n} as const;\n\n/**\n * Request body validation targets.\n *\n * Body formats are mutually exclusive - only one should be specified per handler.\n *\n * **Development behavior:**\n * - If multiple formats are defined, the builder displays a warning and\n * disables validation schemas for the affected handler.\n * - If an unsuitable target is defined (e.g., `json`, `form`)\n * for a method without a body like GET, HEAD), a warning is displayed and\n * validation schemas are disabled for that handler.\n *\n * This ensures misconfigurations are detected during development\n * for runtime to execute without false positive validation failures.\n *\n * Always define exactly one target that is suitable for current handler.\n * */\nexport const RequestBodyTargets = {\n json: \"JSON request body\",\n form: \"URL-encoded or Multipart form\",\n raw: \"Raw body format (string/Buffer/ArrayBuffer/Blob)\",\n} as const;\n\nexport const RequestValidationTargets = {\n ...RequestMetadataTargets,\n ...RequestBodyTargets,\n} as const;\n\nexport type RequestMetadataTarget = keyof typeof RequestMetadataTargets;\nexport type RequestBodyTarget = keyof typeof RequestBodyTargets;\nexport type RequestValidationTarget = keyof typeof RequestValidationTargets;\n\nexport type ValidationTarget = RequestValidationTarget | \"params\" | \"response\";\n\nexport type ValidationDefmap = Partial<{\n /**\n * Request metadata targets.\n * */\n query: Record<string, unknown>;\n headers: Record<string, string>;\n cookies: Record<string, unknown>;\n\n /**\n * Request body targets. One target per handler.\n *\n * POST<\n * json: { id: number }\n * // or form/raw\n * >((ctx) => {})\n * */\n json: unknown;\n form: Record<string, unknown>;\n raw: string | Buffer | ArrayBuffer | Blob;\n\n /**\n * Response variants.\n * Multiple variants can be specified via unions.\n *\n * POST<\n * response:\n * | [200, \"json\", User]\n * | [201, \"json\"]\n * | [301]\n * >((ctx) => {})\n * */\n response: [\n /**\n * HTTP status code to send with the response.\n * Common values: 200 (OK), 400 (Bad Request), 404 (Not Found), 500 (Internal Server Error)\n * */\n status: number,\n /**\n * Content-Type header for the response. Supports shorthand notation that gets\n * resolved via mime-types lookup (e.g., \"json\" becomes \"application/json\",\n * \"html\" becomes \"text/html\", \"png\" becomes \"image/png\")\n * */\n contentType?: string | undefined,\n /** The response body schema */\n body?: unknown,\n ];\n}>;\n\nexport type ValidationCustomErrors = {\n /**\n * Custom error messages for validation failures.\n *\n * Use `error` to set a general error message for the entire validation target.\n * Use `error.<fieldName>` to set specific error messages for individual fields.\n *\n * @example Override validation error messages\n * POST<{\n * json: {\n * id: number;\n * email: string;\n * age: number;\n * }\n * }, {\n * json: {\n * error: \"Invalid user data provided\",\n * \"error.id\": \"User ID must be a valid number\",\n * \"error.email\": \"Please provide a valid email address\",\n * \"error.age\": \"Age must be a number\"\n * }\n * }>\n * */\n error?: string;\n} & {\n [E in `error.${string}`]?: string;\n};\n\nexport type ValidationOptions = {\n /**\n * Controls runtime validation for this target.\n *\n * By default, all validation targets are validated at runtime. Set this to\n * `false` if you only need compile-time type checking without runtime validation.\n *\n * @example Disable runtime validation for JSON payload\n * POST<{\n * json: Payload<User>\n * }, {\n * json: {\n * runtimeValidation: false\n * }\n * }>\n * */\n runtimeValidation?: boolean | undefined;\n\n /**\n * Specifies the request Content-Type for OpenAPI schema generation.\n *\n * When the validation target is `form`, the OpenAPI generator will include\n * both `application/x-www-form-urlencoded` and `multipart/form-data` in the\n * request body content types by default. This indicates the handler accepts\n * either format, which may not be accurate for your use case.\n *\n * Use this option to explicitly declare which content type your handler expects.\n * */\n contentType?: string;\n} & ValidationCustomErrors;\n\nexport type ValidationOptmap = {\n [K in ValidationTarget]?: ValidationOptions;\n};\n\nexport const StateKey: unique symbol = Symbol(\"kosmo.state\");\n\nexport type ExtendContext<\n ParamsT,\n VDefs extends ValidationDefmap,\n VOpts extends ValidationOptmap,\n BodyparserOptions extends Record<RequestBodyTarget, unknown>,\n> = {\n [StateKey]: Map<ValidationTarget, unknown>;\n bodyparser: {\n [T in RequestBodyTarget]: <R = unknown>(\n opts?: BodyparserOptions[T],\n ) => Promise<R>;\n };\n validated: {\n // Only iterate over defined keys\n [K in keyof VDefs as K extends RequestValidationTarget\n ? VOpts[K] extends { runtimeValidation: false }\n ? never\n : K\n : never]: VDefs[K];\n } & { params: ParamsT };\n};\n\nexport type ValidationSchema = {\n check: (data: unknown) => boolean;\n errors: (data: unknown) => Array<ValidationErrorEntry>;\n errorMessage: (data: unknown) => string;\n errorSummary: (data: unknown) => string;\n validate: (data: unknown) => void;\n};\n\nexport type ValidationSchemas<Extend = object> = {\n [T in RequestValidationTarget]?: Record<\n // http method\n string,\n ValidationSchema &\n Extend & {\n runtimeValidation?: boolean;\n customErrors?: ValidationCustomErrors;\n }\n >;\n} & {\n params?: ValidationSchema & Extend;\n response?: Record<\n // http method\n string,\n Array<\n ValidationSchema &\n Extend & {\n status: number;\n contentType?: string;\n runtimeValidation?: boolean;\n customErrors?: ValidationCustomErrors;\n }\n >\n >;\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB;AAE1B,OAAO,iBAAiB;AAIxB,IAAM,iBAAiB,CAAC,WAA2B;AACjD,QAAM,QACJ;AAAA,IACE,MAAM;AAAA,IACN,KAAK;AA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