yedra 0.12.6 → 0.12.7
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/routing/app.d.ts +8 -1
- package/dist/routing/app.js +23 -5
- package/dist/routing/rest.js +1 -1
- package/dist/routing/websocket.js +3 -3
- package/dist/validation/none.d.ts +1 -1
- package/dist/validation/none.js +1 -1
- package/dist/validation/raw.d.ts +1 -1
- package/dist/validation/raw.js +1 -1
- package/package.json +2 -2
package/dist/routing/app.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { Server } from 'bun';
|
|
2
2
|
import type { Endpoint } from './endpoint.js';
|
|
3
|
+
declare class Counter {
|
|
4
|
+
private count;
|
|
5
|
+
increment(): void;
|
|
6
|
+
decrement(): void;
|
|
7
|
+
wait(): Promise<void>;
|
|
8
|
+
}
|
|
3
9
|
declare class Context {
|
|
4
10
|
private server;
|
|
5
|
-
|
|
11
|
+
private counter;
|
|
12
|
+
constructor(server: Server, counter: Counter);
|
|
6
13
|
stop(): Promise<void>;
|
|
7
14
|
}
|
|
8
15
|
export declare class Yedra {
|
package/dist/routing/app.js
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import { HttpError } from './errors.js';
|
|
2
2
|
import { Path } from './path.js';
|
|
3
|
+
class Counter {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.count = 0;
|
|
6
|
+
}
|
|
7
|
+
increment() {
|
|
8
|
+
this.count += 1;
|
|
9
|
+
}
|
|
10
|
+
decrement() {
|
|
11
|
+
this.count -= 1;
|
|
12
|
+
}
|
|
13
|
+
async wait() {
|
|
14
|
+
while (this.count > 0) {
|
|
15
|
+
await Bun.sleep(1000);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
3
19
|
class Context {
|
|
4
|
-
constructor(server) {
|
|
20
|
+
constructor(server, counter) {
|
|
5
21
|
this.server = server;
|
|
22
|
+
this.counter = counter;
|
|
6
23
|
}
|
|
7
24
|
async stop() {
|
|
8
25
|
// stop accepting new connections
|
|
9
26
|
this.server.stop();
|
|
10
27
|
// wait for current connections to be closed
|
|
11
|
-
|
|
12
|
-
await Bun.sleep(1000);
|
|
13
|
-
}
|
|
28
|
+
await this.counter.wait();
|
|
14
29
|
}
|
|
15
30
|
}
|
|
16
31
|
export class Yedra {
|
|
@@ -80,9 +95,11 @@ export class Yedra {
|
|
|
80
95
|
};
|
|
81
96
|
}
|
|
82
97
|
listen(port) {
|
|
98
|
+
const counter = new Counter();
|
|
83
99
|
const server = Bun.serve({
|
|
84
100
|
port: port,
|
|
85
101
|
fetch: async (req, server) => {
|
|
102
|
+
counter.increment();
|
|
86
103
|
const url = new URL(req.url).pathname;
|
|
87
104
|
const begin = Date.now();
|
|
88
105
|
const response = await this.handle(req, server);
|
|
@@ -90,6 +107,7 @@ export class Yedra {
|
|
|
90
107
|
if (response !== undefined) {
|
|
91
108
|
console.log(`${req.method} ${url} -> ${response.status} (${duration}ms)`);
|
|
92
109
|
}
|
|
110
|
+
counter.decrement();
|
|
93
111
|
return response;
|
|
94
112
|
},
|
|
95
113
|
websocket: {
|
|
@@ -105,7 +123,7 @@ export class Yedra {
|
|
|
105
123
|
},
|
|
106
124
|
});
|
|
107
125
|
console.log(`yedra listening on http://localhost:${port}...`);
|
|
108
|
-
return new Context(server);
|
|
126
|
+
return new Context(server, counter);
|
|
109
127
|
}
|
|
110
128
|
static errorResponse(status, errorMessage) {
|
|
111
129
|
return Response.json({
|
package/dist/routing/rest.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { paramDocs } from '../util/docs.js';
|
|
1
2
|
import { ValidationError } from '../validation/error.js';
|
|
2
3
|
import { NoneBody, none } from '../validation/none.js';
|
|
3
4
|
import { object } from '../validation/object.js';
|
|
4
5
|
import { BadRequestError } from './errors.js';
|
|
5
|
-
import { paramDocs } from '../util/docs.js';
|
|
6
6
|
class RestEndpoint {
|
|
7
7
|
constructor(method, options) {
|
|
8
8
|
this._method = method;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { paramDocs } from '../util/docs.js';
|
|
1
2
|
import { ValidationError } from '../validation/error.js';
|
|
2
3
|
import { object } from '../validation/object.js';
|
|
3
4
|
import { BadRequestError } from './errors.js';
|
|
4
|
-
import { paramDocs } from '../util/docs.js';
|
|
5
5
|
export class WebSocketHandler {
|
|
6
6
|
constructor(open) {
|
|
7
7
|
this.messageCbs = [];
|
|
@@ -61,7 +61,7 @@ export class Ws {
|
|
|
61
61
|
get method() {
|
|
62
62
|
return 'GET';
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
handle(req, params, server) {
|
|
65
65
|
const url = new URL(req.url);
|
|
66
66
|
if (req.headers.get('upgrade') !== 'websocket') {
|
|
67
67
|
throw new BadRequestError(`WebSocket required for ${url.pathname}`);
|
|
@@ -93,7 +93,7 @@ export class Ws {
|
|
|
93
93
|
})) {
|
|
94
94
|
throw new BadRequestError('Upgrading to WebSocket failed.');
|
|
95
95
|
}
|
|
96
|
-
return undefined;
|
|
96
|
+
return Promise.resolve(undefined);
|
|
97
97
|
}
|
|
98
98
|
documentation() {
|
|
99
99
|
const parameters = [
|
package/dist/validation/none.js
CHANGED
package/dist/validation/raw.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BodyType } from './body.js';
|
|
|
2
2
|
declare class RawBody extends BodyType<Uint8Array> {
|
|
3
3
|
private contentType;
|
|
4
4
|
constructor(contentType: string | undefined);
|
|
5
|
-
deserialize(buffer: Uint8Array,
|
|
5
|
+
deserialize(buffer: Uint8Array, _contentType: string): Uint8Array;
|
|
6
6
|
bodyDocs(): object;
|
|
7
7
|
}
|
|
8
8
|
/**
|
package/dist/validation/raw.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yedra",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.7",
|
|
4
4
|
"repository": "github:0codekit/yedra",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@biomejs/biome": "^1.9.3",
|
|
8
8
|
"@types/bun": "^1.1.10",
|
|
9
|
-
"@types/node": "^22.7.
|
|
9
|
+
"@types/node": "^22.7.5",
|
|
10
10
|
"@types/uuid": "^10.0.0",
|
|
11
11
|
"typescript": "^5.6.2"
|
|
12
12
|
},
|