yedra 0.11.3 → 0.11.5

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.
@@ -1,5 +1,10 @@
1
1
  import type { Server } from 'bun';
2
2
  import type { Endpoint } from './endpoint.js';
3
+ declare class Context {
4
+ private server;
5
+ constructor(server: Server);
6
+ stop(): Promise<void>;
7
+ }
3
8
  export declare class App {
4
9
  private routes;
5
10
  use(path: string, endpoint: Endpoint | App): App;
@@ -23,8 +28,9 @@ export declare class App {
23
28
  url: string;
24
29
  }[];
25
30
  }): object;
26
- listen(port: number): void;
31
+ listen(port: number): Context;
27
32
  private static errorResponse;
28
33
  private static handleWebSocketErrors;
29
34
  private matchEndpoint;
30
35
  }
36
+ export {};
@@ -1,5 +1,18 @@
1
1
  import { HttpError } from './errors.js';
2
2
  import { Path } from './path.js';
3
+ class Context {
4
+ constructor(server) {
5
+ this.server = server;
6
+ }
7
+ async stop() {
8
+ // stop accepting new connections
9
+ this.server.stop();
10
+ // wait for current connections to be closed
11
+ while (this.server.pendingRequests > 0) {
12
+ await Bun.sleep(1000);
13
+ }
14
+ }
15
+ }
3
16
  export class App {
4
17
  constructor() {
5
18
  this.routes = [];
@@ -67,7 +80,7 @@ export class App {
67
80
  };
68
81
  }
69
82
  listen(port) {
70
- Bun.serve({
83
+ const server = Bun.serve({
71
84
  port: port,
72
85
  fetch: async (req, server) => {
73
86
  const url = new URL(req.url).pathname;
@@ -92,6 +105,7 @@ export class App {
92
105
  },
93
106
  });
94
107
  console.log(`yedra listening on http://localhost:${port}...`);
108
+ return new Context(server);
95
109
  }
96
110
  static errorResponse(status, errorMessage) {
97
111
  return Response.json({
@@ -15,7 +15,10 @@ export class Path {
15
15
  if (!path.startsWith('/')) {
16
16
  throw new Error(`API path ${path} is invalid: Must start with '/'.`);
17
17
  }
18
- this.expected = path.substring(1).split('/');
18
+ this.expected = path
19
+ .substring(1)
20
+ .split('/')
21
+ .filter((segment) => segment !== '');
19
22
  const invalidSegment = this.expected.find((part) => part.match(/^((:?[a-z0-9-]+\??)|\*)$/) === null);
20
23
  if (invalidSegment) {
21
24
  throw new Error(`API path ${path} is invalid: Segment ${invalidSegment} does not match regex /^((:?[a-z0-9-]+\\??)|\\*)$/.`);
package/package.json CHANGED
@@ -1,20 +1,31 @@
1
1
  {
2
2
  "name": "yedra",
3
- "version": "0.11.3",
3
+ "version": "0.11.5",
4
4
  "repository": "github:0codekit/yedra",
5
5
  "main": "dist/index.js",
6
6
  "devDependencies": {
7
7
  "@biomejs/biome": "^1.8.3",
8
- "@types/bun": "^1.1.6",
9
- "@types/node": "^22.0.3",
8
+ "@types/bun": "^1.1.8",
9
+ "@types/node": "^22.5.3",
10
10
  "typescript": "^5.5.4"
11
11
  },
12
12
  "bugs": "https://github.com/0codekit/yedra/issues",
13
- "contributors": ["Justus Zorn <jzorn@wemakefuture.com>"],
13
+ "contributors": [
14
+ "Justus Zorn <jzorn@wemakefuture.com>"
15
+ ],
14
16
  "description": "A TypeScript web framework with OpenAPI generation.",
15
- "keywords": ["typescript", "web", "http", "schema", "validation", "openapi"],
17
+ "keywords": [
18
+ "typescript",
19
+ "web",
20
+ "http",
21
+ "schema",
22
+ "validation",
23
+ "openapi"
24
+ ],
16
25
  "license": "MIT",
17
- "files": ["./dist/**"],
26
+ "files": [
27
+ "./dist/**"
28
+ ],
18
29
  "scripts": {
19
30
  "check": "biome check src/*"
20
31
  },
@@ -24,4 +35,4 @@
24
35
  "@types/uuid": "^10.0.0",
25
36
  "uuid": "^10.0.0"
26
37
  }
27
- }
38
+ }