yedra 0.13.13 → 0.13.14
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 +6 -4
- package/dist/routing/app.js +4 -1
- package/dist/util/counter.d.ts +7 -0
- package/dist/util/counter.js +24 -0
- package/dist/util/stream.d.ts +2 -0
- package/dist/util/stream.js +7 -0
- package/dist/validation/stream.d.ts +13 -0
- package/dist/validation/stream.js +26 -0
- package/package.json +5 -5
package/dist/routing/app.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ declare class Context {
|
|
|
8
8
|
constructor(server: Server);
|
|
9
9
|
stop(): Promise<void>;
|
|
10
10
|
}
|
|
11
|
+
type MetricsConfig = {
|
|
12
|
+
port: number;
|
|
13
|
+
path: string;
|
|
14
|
+
get?: () => Promise<string>;
|
|
15
|
+
};
|
|
11
16
|
export declare class Yedra {
|
|
12
17
|
private restRoutes;
|
|
13
18
|
private wsRoutes;
|
|
@@ -15,10 +20,7 @@ export declare class Yedra {
|
|
|
15
20
|
private requestData;
|
|
16
21
|
private readonly metricsEndpoint;
|
|
17
22
|
constructor(options?: {
|
|
18
|
-
metrics:
|
|
19
|
-
port: number;
|
|
20
|
-
path: string;
|
|
21
|
-
};
|
|
23
|
+
metrics: MetricsConfig;
|
|
22
24
|
});
|
|
23
25
|
use(path: string, endpoint: RestEndpoint | WsEndpoint | Yedra): Yedra;
|
|
24
26
|
static(dir: string, fallback?: string): Promise<void>;
|
package/dist/routing/app.js
CHANGED
|
@@ -193,9 +193,12 @@ export class Yedra {
|
|
|
193
193
|
const metricsEndpoint = this.metricsEndpoint;
|
|
194
194
|
if (metricsEndpoint !== undefined) {
|
|
195
195
|
const metricsServer = createHttpServer();
|
|
196
|
-
metricsServer.on('request', (req, res) => {
|
|
196
|
+
metricsServer.on('request', async (req, res) => {
|
|
197
197
|
if (req.method === 'GET' && req.url === metricsEndpoint.path) {
|
|
198
198
|
res.writeHead(200);
|
|
199
|
+
if (metricsEndpoint.get !== undefined) {
|
|
200
|
+
res.write(await metricsEndpoint.get());
|
|
201
|
+
}
|
|
199
202
|
res.end(this.generateMetrics());
|
|
200
203
|
}
|
|
201
204
|
else {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class Counter {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.count = 0;
|
|
4
|
+
}
|
|
5
|
+
wait() {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
if (this.count === 0) {
|
|
8
|
+
resolve();
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
this.resolve = resolve;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
increment() {
|
|
16
|
+
this.count += 1;
|
|
17
|
+
}
|
|
18
|
+
decrement() {
|
|
19
|
+
this.count -= 1;
|
|
20
|
+
if (this.count === 0 && this.resolve !== undefined) {
|
|
21
|
+
this.resolve();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import { BodyType } from './body.js';
|
|
3
|
+
declare class StreamBody extends BodyType<ReadableStream> {
|
|
4
|
+
private readonly contentType;
|
|
5
|
+
constructor(contentType: string);
|
|
6
|
+
deserialize(stream: Readable, _contentType: string): Promise<ReadableStream>;
|
|
7
|
+
bodyDocs(): object;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Accepts a raw buffer of the specified content type, and presents it as a stream.
|
|
11
|
+
*/
|
|
12
|
+
export declare const stream: (contentType?: string) => StreamBody;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BodyType } from './body.js';
|
|
2
|
+
class StreamBody extends BodyType {
|
|
3
|
+
constructor(contentType) {
|
|
4
|
+
super();
|
|
5
|
+
this.contentType = contentType;
|
|
6
|
+
}
|
|
7
|
+
deserialize(stream, _contentType) {
|
|
8
|
+
return Promise.resolve(new ReadableStream({
|
|
9
|
+
async start(controller) {
|
|
10
|
+
for await (const chunk of stream) {
|
|
11
|
+
controller.enqueue(chunk);
|
|
12
|
+
}
|
|
13
|
+
controller.close();
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
bodyDocs() {
|
|
18
|
+
return {
|
|
19
|
+
[this.contentType]: {},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Accepts a raw buffer of the specified content type, and presents it as a stream.
|
|
25
|
+
*/
|
|
26
|
+
export const stream = (contentType) => new StreamBody(contentType ?? 'application/octet-stream');
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yedra",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.14",
|
|
4
4
|
"repository": "github:0codekit/yedra",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@biomejs/biome": "^1.9.4",
|
|
8
|
-
"@types/bun": "^1.2.
|
|
9
|
-
"@types/node": "^22.14.
|
|
8
|
+
"@types/bun": "^1.2.10",
|
|
9
|
+
"@types/node": "^22.14.1",
|
|
10
10
|
"@types/uuid": "^10.0.0",
|
|
11
11
|
"@types/ws": "^8.18.1",
|
|
12
|
-
"typescript": "^5.8.
|
|
12
|
+
"typescript": "^5.8.3"
|
|
13
13
|
},
|
|
14
14
|
"bugs": "https://github.com/0codekit/yedra/issues",
|
|
15
15
|
"contributors": ["Justus Zorn <jzorn@wemakefuture.com>"],
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"types": "dist/index.d.ts",
|
|
24
24
|
"type": "module",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"mime": "^4.0.
|
|
26
|
+
"mime": "^4.0.7",
|
|
27
27
|
"uuid": "^11.1.0",
|
|
28
28
|
"ws": "^8.18.1"
|
|
29
29
|
}
|