yedra 0.11.6 → 0.12.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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/routing/app.d.ts +2 -2
- package/dist/routing/app.js +10 -10
- package/dist/routing/rest.d.ts +1 -1
- package/dist/routing/rest.js +2 -2
- package/dist/routing/websocket.d.ts +2 -2
- package/dist/routing/websocket.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as y from './lib.js';
|
|
2
2
|
export { y };
|
|
3
|
-
export {
|
|
3
|
+
export { Yedra } from './routing/app.js';
|
|
4
4
|
export { Get, Post, Put, Delete } from './routing/rest.js';
|
|
5
5
|
export { Ws } from './routing/websocket.js';
|
|
6
6
|
export { HttpError, BadRequestError, UnauthorizedError, PaymentRequiredError, ForbiddenError, NotFoundError, ConflictError, } from './routing/errors.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as y from './lib.js';
|
|
2
2
|
export { y };
|
|
3
|
-
export {
|
|
3
|
+
export { Yedra } from './routing/app.js';
|
|
4
4
|
export { Get, Post, Put, Delete } from './routing/rest.js';
|
|
5
5
|
export { Ws } from './routing/websocket.js';
|
|
6
6
|
export { HttpError, BadRequestError, UnauthorizedError, PaymentRequiredError, ForbiddenError, NotFoundError, ConflictError, } from './routing/errors.js';
|
package/dist/routing/app.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ declare class Context {
|
|
|
5
5
|
constructor(server: Server);
|
|
6
6
|
stop(): Promise<void>;
|
|
7
7
|
}
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class Yedra {
|
|
9
9
|
private routes;
|
|
10
|
-
use(path: string, endpoint: Endpoint |
|
|
10
|
+
use(path: string, endpoint: Endpoint | Yedra): Yedra;
|
|
11
11
|
/**
|
|
12
12
|
* Handle an HTTP request.
|
|
13
13
|
* @param req - The HTTP request.
|
package/dist/routing/app.js
CHANGED
|
@@ -13,12 +13,12 @@ class Context {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
export class
|
|
16
|
+
export class Yedra {
|
|
17
17
|
constructor() {
|
|
18
18
|
this.routes = [];
|
|
19
19
|
}
|
|
20
20
|
use(path, endpoint) {
|
|
21
|
-
if (endpoint instanceof
|
|
21
|
+
if (endpoint instanceof Yedra) {
|
|
22
22
|
for (const route of endpoint.routes) {
|
|
23
23
|
const newPath = route.path.withPrefix(path);
|
|
24
24
|
this.routes.push({ path: newPath, endpoint: route.endpoint });
|
|
@@ -40,24 +40,24 @@ export class App {
|
|
|
40
40
|
req.method !== 'POST' &&
|
|
41
41
|
req.method !== 'PUT' &&
|
|
42
42
|
req.method !== 'DELETE') {
|
|
43
|
-
return
|
|
43
|
+
return Yedra.errorResponse(405, `Method '${req.method}' not allowed.`);
|
|
44
44
|
}
|
|
45
45
|
const match = this.matchEndpoint(url, req.method);
|
|
46
46
|
if (!match.result) {
|
|
47
47
|
if (match.invalidMethod) {
|
|
48
|
-
return
|
|
48
|
+
return Yedra.errorResponse(405, `Method '${req.method}' not allowed for path '${url}'.`);
|
|
49
49
|
}
|
|
50
|
-
return
|
|
50
|
+
return Yedra.errorResponse(404, `Path '${url}' not found.`);
|
|
51
51
|
}
|
|
52
52
|
try {
|
|
53
53
|
return await match.result.endpoint.handle(req, match.result.params, server);
|
|
54
54
|
}
|
|
55
55
|
catch (error) {
|
|
56
56
|
if (error instanceof HttpError) {
|
|
57
|
-
return
|
|
57
|
+
return Yedra.errorResponse(error.status, error.message);
|
|
58
58
|
}
|
|
59
59
|
console.error(error);
|
|
60
|
-
return
|
|
60
|
+
return Yedra.errorResponse(500, 'Internal Server Error.');
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
@@ -94,13 +94,13 @@ export class App {
|
|
|
94
94
|
},
|
|
95
95
|
websocket: {
|
|
96
96
|
open(ws) {
|
|
97
|
-
|
|
97
|
+
Yedra.handleWebSocketErrors(ws, () => ws.data.handler.open(ws));
|
|
98
98
|
},
|
|
99
99
|
message(ws, message) {
|
|
100
|
-
|
|
100
|
+
Yedra.handleWebSocketErrors(ws, () => ws.data.handler.message(Buffer.from(message)));
|
|
101
101
|
},
|
|
102
102
|
close(ws, code, reason) {
|
|
103
|
-
|
|
103
|
+
Yedra.handleWebSocketErrors(ws, () => ws.data.handler.close(code, reason));
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
106
|
});
|
package/dist/routing/rest.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Server } from 'bun';
|
|
2
2
|
import type { BodyType, Typeof } from '../validation/body.js';
|
|
3
|
+
import { NoneBody } from '../validation/none.js';
|
|
3
4
|
import { type ObjectSchema } from '../validation/object.js';
|
|
4
5
|
import type { Schema } from '../validation/schema.js';
|
|
5
6
|
import type { Endpoint } from './endpoint.js';
|
|
6
|
-
import { NoneBody } from '../validation/none.js';
|
|
7
7
|
type ReqObject<Params, Query, Headers, Body> = {
|
|
8
8
|
url: string;
|
|
9
9
|
params: Params;
|
package/dist/routing/rest.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { ValidationError } from '../validation/error.js';
|
|
2
|
+
import { NoneBody, none } from '../validation/none.js';
|
|
1
3
|
import { object } from '../validation/object.js';
|
|
2
4
|
import { BadRequestError } from './errors.js';
|
|
3
|
-
import { ValidationError } from '../validation/error.js';
|
|
4
|
-
import { none, NoneBody } from '../validation/none.js';
|
|
5
5
|
class RestEndpoint {
|
|
6
6
|
constructor(method, options) {
|
|
7
7
|
this._method = method;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Server, ServerWebSocket } from 'bun';
|
|
2
|
-
import type { Schema } from '../validation/schema.js';
|
|
3
|
-
import { type ObjectSchema } from '../validation/object.js';
|
|
4
2
|
import type { Typeof } from '../validation/body.js';
|
|
3
|
+
import { type ObjectSchema } from '../validation/object.js';
|
|
4
|
+
import type { Schema } from '../validation/schema.js';
|
|
5
5
|
import type { Endpoint } from './endpoint.js';
|
|
6
6
|
type OpenCb = (ws: ServerWebSocket<{
|
|
7
7
|
handler: WebSocketHandler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ValidationError } from '../validation/error.js';
|
|
1
2
|
import { object } from '../validation/object.js';
|
|
2
3
|
import { BadRequestError } from './errors.js';
|
|
3
|
-
import { ValidationError } from '../validation/error.js';
|
|
4
4
|
export class WebSocketHandler {
|
|
5
5
|
constructor(open) {
|
|
6
6
|
this.messageCbs = [];
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yedra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"repository": "github:0codekit/yedra",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@biomejs/biome": "^1.9.
|
|
8
|
-
"@types/bun": "^1.1.
|
|
7
|
+
"@biomejs/biome": "^1.9.2",
|
|
8
|
+
"@types/bun": "^1.1.10",
|
|
9
9
|
"@types/node": "^22.5.5",
|
|
10
10
|
"@types/uuid": "^10.0.0",
|
|
11
11
|
"typescript": "^5.6.2"
|