sleepy-serv 0.6.2 → 0.8.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/README.md +20 -4
- package/dist/errors.d.ts +173 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/messages.d.ts +63 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/middleware.d.ts +19 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/socket.d.ts +50 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/utils.d.ts +125 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +17 -3
- package/src/{errors.js → errors.ts} +171 -80
- package/src/{index.js → index.ts} +215 -59
- package/src/messages.ts +237 -0
- package/src/middleware.ts +209 -0
- package/src/{socket.js → socket.ts} +247 -86
- package/src/utils.ts +204 -0
- package/src/messages.js +0 -164
- package/src/meta.js +0 -65
- package/src/middleware.js +0 -138
- package/src/utils.js +0 -49
package/README.md
CHANGED
|
@@ -26,9 +26,25 @@ The parameter for `import.meta.dirname` can be any directory you prefer, but it'
|
|
|
26
26
|
|
|
27
27
|
### Return Value
|
|
28
28
|
|
|
29
|
-
`sleepy-serv` was originally built for NodeJS, but it was ported to `bun` recently (before the initial release). The `createApp()` function merely calls `Bun.serve()` under-the-hood, and returns the `app` object that contains
|
|
29
|
+
`sleepy-serv` was originally built for NodeJS, but it was ported to `bun` recently (before the initial release). The `createApp()` function merely calls `Bun.serve()` under-the-hood, and returns the `app` object that contains these properties:
|
|
30
30
|
- `routes`: Contains a list of all of the routes defined by the file structure. This is useful for debugging.
|
|
31
|
-
- `server`: this is the object that's returned from `Bun.serve()`. The `server` object has an `async` `.stop()` method on it, which
|
|
31
|
+
- `server`: this is the object that's returned from `Bun.serve()`. The `server` object has an `async` `.stop()` method on it, but prefer `app.close()` (see [Shutting Down](#shutting-down)), which stops the server and releases everything else the app holds.
|
|
32
|
+
- `commands`: WebSocket helpers for pushing messages out to connected clients: `send(clientId, event, body)` and `broadcast(event, body)`.
|
|
33
|
+
- `close`: an `async` function that shuts the app down. See [Shutting Down](#shutting-down).
|
|
34
|
+
|
|
35
|
+
### Shutting Down
|
|
36
|
+
|
|
37
|
+
`app.close()` shuts the app down and releases everything it holds:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const app = await createApp(PORT, import.meta.dirname)
|
|
41
|
+
|
|
42
|
+
await app.close()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
It stops the server, tears down the Ctrl+D shutdown handler, and calls [`onClose`](#onclose). Pass `close(true)` to force-close active connections rather than waiting for in-flight requests to finish. That argument is handed straight to `server.stop()`, so it behaves exactly as it does in `Bun.serve()`.
|
|
46
|
+
|
|
47
|
+
This matters most for tests that start and stop an app per case. Calling `server.stop()` on its own stops the HTTP listener but leaves the Ctrl+D shutdown handler attached to `stdin`, which holds an open handle and can keep the process from exiting. `app.close()` does not have that problem.
|
|
32
48
|
|
|
33
49
|
### Adding Routes
|
|
34
50
|
|
|
@@ -315,7 +331,7 @@ export default [
|
|
|
315
331
|
This function returns a middleware function that validates request data against provided schemas. The returned middleware function has the signature `(req, res, next)` and forwards `res` via `next(res)` after successful validation.
|
|
316
332
|
|
|
317
333
|
The `schemas` object can contain these optional properties:
|
|
318
|
-
- `headers`: takes a string formatter schema to evaluate `req.headers`
|
|
334
|
+
- `headers`: takes a string formatter schema to evaluate `req.headers`. Header names are case-insensitive, so schema keys are lowercased to match; validation errors report the lowercased name (e.g. `headers.userid`).
|
|
319
335
|
- `params`: takes a string formatter schema to evaluate `req.params`
|
|
320
336
|
- `query`: takes a string formatter schema to evaluate `req.query`
|
|
321
337
|
- `body`: takes a JSON validation schema to evaluate `res` (the body value passed in via `next`)
|
|
@@ -465,7 +481,7 @@ Yields these routes:
|
|
|
465
481
|
|
|
466
482
|
### `onClose`
|
|
467
483
|
|
|
468
|
-
When the app is started, the app can be shutdown gracefully by pressing Ctrl+D in the terminal. The `onClose` hook will be called during that shutdown if it's defined. `onClose` can also be `async` as well.
|
|
484
|
+
When the app is started, the app can be shutdown gracefully by pressing Ctrl+D in the terminal. That handler is only wired up when `stdin` is a TTY, so it's skipped in CI, in test runners, and anywhere `stdin` is piped. The `onClose` hook will be called during that shutdown if it's defined, and it's also called by [`app.close()`](#shutting-down). `onClose` can also be `async` as well.
|
|
469
485
|
|
|
470
486
|
```js
|
|
471
487
|
const app = await createApp(PORT, import.meta.dirname, {
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { StatusCode } from './utils';
|
|
2
|
+
import type { FormattedError } from './utils';
|
|
3
|
+
export type ErrorOutput = {
|
|
4
|
+
message: string;
|
|
5
|
+
} | FormattedError[] | null;
|
|
6
|
+
export declare class RequestError extends Error {
|
|
7
|
+
static get status(): StatusCode;
|
|
8
|
+
get output(): ErrorOutput;
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class BadRequestError extends RequestError {
|
|
12
|
+
static get status(): StatusCode;
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class UnauthorizedError extends RequestError {
|
|
16
|
+
static get status(): StatusCode;
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class PaymentRequiredError extends RequestError {
|
|
20
|
+
static get status(): StatusCode;
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class ForbiddenError extends RequestError {
|
|
24
|
+
static get status(): StatusCode;
|
|
25
|
+
constructor(message: string);
|
|
26
|
+
}
|
|
27
|
+
export declare class NotFoundError extends RequestError {
|
|
28
|
+
static get status(): StatusCode;
|
|
29
|
+
constructor();
|
|
30
|
+
}
|
|
31
|
+
export declare class MethodNotAllowedError extends RequestError {
|
|
32
|
+
static get status(): StatusCode;
|
|
33
|
+
constructor();
|
|
34
|
+
}
|
|
35
|
+
export declare class NotAcceptableError extends RequestError {
|
|
36
|
+
static get status(): StatusCode;
|
|
37
|
+
constructor(message: string);
|
|
38
|
+
}
|
|
39
|
+
export declare class ProxyAuthenticationRequiredError extends RequestError {
|
|
40
|
+
static get status(): StatusCode;
|
|
41
|
+
constructor(message: string);
|
|
42
|
+
}
|
|
43
|
+
export declare class RequestTimeoutError extends RequestError {
|
|
44
|
+
static get status(): StatusCode;
|
|
45
|
+
constructor(message: string);
|
|
46
|
+
}
|
|
47
|
+
export declare class ConflictError extends RequestError {
|
|
48
|
+
static get status(): StatusCode;
|
|
49
|
+
constructor(message: string);
|
|
50
|
+
}
|
|
51
|
+
export declare class GoneError extends RequestError {
|
|
52
|
+
static get status(): StatusCode;
|
|
53
|
+
constructor(message: string);
|
|
54
|
+
}
|
|
55
|
+
export declare class LengthRequiredError extends RequestError {
|
|
56
|
+
static get status(): StatusCode;
|
|
57
|
+
constructor(message: string);
|
|
58
|
+
}
|
|
59
|
+
export declare class PreconditionFailedError extends RequestError {
|
|
60
|
+
static get status(): StatusCode;
|
|
61
|
+
constructor(message: string);
|
|
62
|
+
}
|
|
63
|
+
export declare class PayloadTooLargeError extends RequestError {
|
|
64
|
+
static get status(): StatusCode;
|
|
65
|
+
constructor(message: string);
|
|
66
|
+
}
|
|
67
|
+
export declare class UriTooLongError extends RequestError {
|
|
68
|
+
static get status(): StatusCode;
|
|
69
|
+
constructor(message: string);
|
|
70
|
+
}
|
|
71
|
+
export declare class UnsupportedMediaTypeError extends RequestError {
|
|
72
|
+
static get status(): StatusCode;
|
|
73
|
+
constructor(subject: string);
|
|
74
|
+
}
|
|
75
|
+
export declare class RangeNotSatisfiableError extends RequestError {
|
|
76
|
+
static get status(): StatusCode;
|
|
77
|
+
constructor(message: string);
|
|
78
|
+
}
|
|
79
|
+
export declare class ExpectationFailedError extends RequestError {
|
|
80
|
+
static get status(): StatusCode;
|
|
81
|
+
constructor(message: string);
|
|
82
|
+
}
|
|
83
|
+
export declare class ImATeapotError extends RequestError {
|
|
84
|
+
static get status(): StatusCode;
|
|
85
|
+
constructor(message: string);
|
|
86
|
+
}
|
|
87
|
+
export declare class MisdirectedRequestError extends RequestError {
|
|
88
|
+
static get status(): StatusCode;
|
|
89
|
+
constructor(message: string);
|
|
90
|
+
}
|
|
91
|
+
export declare class UnprocessableContentError extends RequestError {
|
|
92
|
+
static get status(): StatusCode;
|
|
93
|
+
get output(): ErrorOutput;
|
|
94
|
+
constructor(errors: FormattedError[]);
|
|
95
|
+
}
|
|
96
|
+
export declare class LockedError extends RequestError {
|
|
97
|
+
static get status(): StatusCode;
|
|
98
|
+
constructor(message: string);
|
|
99
|
+
}
|
|
100
|
+
export declare class FailedDependencyError extends RequestError {
|
|
101
|
+
static get status(): StatusCode;
|
|
102
|
+
constructor(message: string);
|
|
103
|
+
}
|
|
104
|
+
export declare class TooEarlyError extends RequestError {
|
|
105
|
+
static get status(): StatusCode;
|
|
106
|
+
constructor(message: string);
|
|
107
|
+
}
|
|
108
|
+
export declare class UpgradeRequiredError extends RequestError {
|
|
109
|
+
static get status(): StatusCode;
|
|
110
|
+
constructor(message: string);
|
|
111
|
+
}
|
|
112
|
+
export declare class PreconditionRequiredError extends RequestError {
|
|
113
|
+
static get status(): StatusCode;
|
|
114
|
+
constructor(message: string);
|
|
115
|
+
}
|
|
116
|
+
export declare class TooManyRequestsError extends RequestError {
|
|
117
|
+
static get status(): StatusCode;
|
|
118
|
+
constructor(message: string);
|
|
119
|
+
}
|
|
120
|
+
export declare class RequestHeaderFieldsTooLargeError extends RequestError {
|
|
121
|
+
static get status(): StatusCode;
|
|
122
|
+
constructor(message: string);
|
|
123
|
+
}
|
|
124
|
+
export declare class UnavailableForLegalReasonsError extends RequestError {
|
|
125
|
+
static get status(): StatusCode;
|
|
126
|
+
constructor(message: string);
|
|
127
|
+
}
|
|
128
|
+
export declare class InternalServerError extends RequestError {
|
|
129
|
+
static get status(): StatusCode;
|
|
130
|
+
ctx: unknown;
|
|
131
|
+
constructor(message: string, ctx?: unknown);
|
|
132
|
+
}
|
|
133
|
+
export declare class NotImplementedError extends RequestError {
|
|
134
|
+
static get status(): StatusCode;
|
|
135
|
+
constructor();
|
|
136
|
+
}
|
|
137
|
+
export declare class BadGatewayError extends RequestError {
|
|
138
|
+
static get status(): StatusCode;
|
|
139
|
+
constructor(message: string);
|
|
140
|
+
}
|
|
141
|
+
export declare class ServiceUnavailableError extends RequestError {
|
|
142
|
+
static get status(): StatusCode;
|
|
143
|
+
constructor(message: string);
|
|
144
|
+
}
|
|
145
|
+
export declare class GatewayTimeoutError extends RequestError {
|
|
146
|
+
static get status(): StatusCode;
|
|
147
|
+
constructor();
|
|
148
|
+
}
|
|
149
|
+
export declare class HTTPVersionNotSupportedError extends RequestError {
|
|
150
|
+
static get status(): StatusCode;
|
|
151
|
+
constructor(message: string);
|
|
152
|
+
}
|
|
153
|
+
export declare class VariantAlsoNegotiatesError extends RequestError {
|
|
154
|
+
static get status(): StatusCode;
|
|
155
|
+
constructor(message: string);
|
|
156
|
+
}
|
|
157
|
+
export declare class InsufficientStorageError extends RequestError {
|
|
158
|
+
static get status(): StatusCode;
|
|
159
|
+
constructor(message: string);
|
|
160
|
+
}
|
|
161
|
+
export declare class LoopDetectedError extends RequestError {
|
|
162
|
+
static get status(): StatusCode;
|
|
163
|
+
constructor(message: string);
|
|
164
|
+
}
|
|
165
|
+
export declare class NotExtendedError extends RequestError {
|
|
166
|
+
static get status(): StatusCode;
|
|
167
|
+
constructor(message: string);
|
|
168
|
+
}
|
|
169
|
+
export declare class NetworkAuthenticationRequiredError extends RequestError {
|
|
170
|
+
static get status(): StatusCode;
|
|
171
|
+
constructor(message: string);
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpC,OAAO,KAAK,EAAE,cAAc,EAA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,SAAQ,YAAY;IAC/C,MAAM,KAAK,MAAM,IAAK,UAAU,CAE/B;gBAEY,OAAO,EAAE,MAAM;CAK7B;AAED,qBAAa,uBAAwB,SAAQ,YAAY;IACvD,MAAM,KAAK,MAAM,IAAK,UAAU,CAE/B;gBAEY,OAAO,EAAE,MAAM;CAK7B;AAED,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,MAAM,KAAK,MAAM,IAAK,UAAU,CAE/B;;CAOF;AAED,qBAAa,4BAA6B,SAAQ,YAAY;IAC5D,MAAM,KAAK,MAAM,IAAK,UAAU,CAE/B;gBAEY,OAAO,EAAE,MAAM;CAK7B;AAED,qBAAa,0BAA2B,SAAQ,YAAY;IAC1D,MAAM,KAAK,MAAM,IAAK,UAAU,CAE/B;gBAEY,OAAO,EAAE,MAAM;CAK7B;AAED,qBAAa,wBAAyB,SAAQ,YAAY;IACxD,MAAM,KAAK,MAAM,IAAK,UAAU,CAE/B;gBAEY,OAAO,EAAE,MAAM;CAK7B;AAED,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,MAAM,KAAK,MAAM,IAAK,UAAU,CAE/B;gBAEY,OAAO,EAAE,MAAM;CAK7B;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,MAAM,KAAK,MAAM,IAAK,UAAU,CAE/B;gBAEY,OAAO,EAAE,MAAM;CAK7B;AAED,qBAAa,kCAAmC,SAAQ,YAAY;IAClE,MAAM,KAAK,MAAM,IAAK,UAAU,CAE/B;gBAEY,OAAO,EAAE,MAAM;CAK7B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AppOptions, Server } from './utils';
|
|
2
|
+
import type { SocketCommands } from './socket';
|
|
3
|
+
export * from './errors';
|
|
4
|
+
export { parseJsonBody, setValidationFormats, validateSchemas, } from './middleware';
|
|
5
|
+
export { HttpMethod, StatusCode } from './utils';
|
|
6
|
+
export type { AppOptions, EndpointRequest, FormattedError, Middleware, NextFn, Request, Server, SocketOptions, WebSocketRequest, } from './utils';
|
|
7
|
+
export type { FormatterField, FormatterSchema, ValidationSchemas, } from './middleware';
|
|
8
|
+
export type { SocketCommands } from './socket';
|
|
9
|
+
type OutputRoutes = Record<string, string[]>;
|
|
10
|
+
type CloseFn = (force?: boolean) => Promise<void>;
|
|
11
|
+
export type App = {
|
|
12
|
+
server: Server;
|
|
13
|
+
commands: SocketCommands;
|
|
14
|
+
routes: OutputRoutes;
|
|
15
|
+
close: CloseFn;
|
|
16
|
+
};
|
|
17
|
+
export declare function createApp(port: number, rootPath: string, opts?: AppOptions): Promise<App>;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAIV,UAAU,EACV,MAAM,EACP,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAGV,cAAc,EACf,MAAM,UAAU,CAAA;AAEjB,cAAc,UAAU,CAAA;AAExB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,eAAe,GAChB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEhD,YAAY,EACV,UAAU,EACV,eAAe,EACf,cAAc,EACd,UAAU,EACV,MAAM,EACN,OAAO,EACP,MAAM,EACN,aAAa,EACb,gBAAgB,GACjB,MAAM,SAAS,CAAA;AAEhB,YAAY,EACV,cAAc,EACd,eAAe,EACf,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AA4C5C,KAAK,OAAO,GAAG,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAEjD,MAAM,MAAM,GAAG,GAAG;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,cAAc,CAAA;IACxB,MAAM,EAAE,YAAY,CAAA;IACpB,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AA4ZD,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,UAAe,GACpB,OAAO,CAAC,GAAG,CAAC,CAad"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { HttpMethod } from './utils';
|
|
2
|
+
export declare const MessageType: {
|
|
3
|
+
readonly Request: "request";
|
|
4
|
+
readonly Response: "response";
|
|
5
|
+
readonly Welcome: "welcome";
|
|
6
|
+
readonly Heartbeat: "heartbeat";
|
|
7
|
+
readonly Notification: "notification";
|
|
8
|
+
};
|
|
9
|
+
export type MessageType = typeof MessageType[keyof typeof MessageType];
|
|
10
|
+
export declare const RECEIVED_MESSAGE_TYPES: string[];
|
|
11
|
+
export type BaseMessage = {
|
|
12
|
+
id: string;
|
|
13
|
+
clientId: string;
|
|
14
|
+
type: MessageType;
|
|
15
|
+
timestamp: string;
|
|
16
|
+
};
|
|
17
|
+
export type HeartbeatMessage = BaseMessage & {
|
|
18
|
+
type: typeof MessageType.Heartbeat;
|
|
19
|
+
};
|
|
20
|
+
export type RequestMessage = BaseMessage & {
|
|
21
|
+
type: typeof MessageType.Request;
|
|
22
|
+
method: HttpMethod;
|
|
23
|
+
route: string;
|
|
24
|
+
headers: Bun.HeadersInit;
|
|
25
|
+
query: Record<string, unknown>;
|
|
26
|
+
body: unknown;
|
|
27
|
+
};
|
|
28
|
+
export type ResponseMessage = BaseMessage & {
|
|
29
|
+
type: typeof MessageType.Response;
|
|
30
|
+
status: number;
|
|
31
|
+
headers: Headers;
|
|
32
|
+
body: unknown;
|
|
33
|
+
};
|
|
34
|
+
export type WelcomeMessage = BaseMessage & {
|
|
35
|
+
type: typeof MessageType.Welcome;
|
|
36
|
+
headers: Headers;
|
|
37
|
+
body: {
|
|
38
|
+
heartbeatInterval: number;
|
|
39
|
+
token: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export type NotificationMessage = BaseMessage & {
|
|
43
|
+
type: typeof MessageType.Notification;
|
|
44
|
+
event: string;
|
|
45
|
+
headers: Headers;
|
|
46
|
+
body: unknown;
|
|
47
|
+
};
|
|
48
|
+
export type Message = HeartbeatMessage | RequestMessage | ResponseMessage | WelcomeMessage | NotificationMessage;
|
|
49
|
+
export type RawMessage = {
|
|
50
|
+
type?: string;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
};
|
|
53
|
+
export type IncomingMessage = HeartbeatMessage | RequestMessage;
|
|
54
|
+
export type MessageContent<T extends MessageType = MessageType> = Partial<Pick<Extract<Message, {
|
|
55
|
+
type: T;
|
|
56
|
+
}>, 'id'>> & Omit<Extract<Message, {
|
|
57
|
+
type: T;
|
|
58
|
+
}>, keyof BaseMessage>;
|
|
59
|
+
export declare function createMessage<T extends MessageType>(clientId: string, type: T, content: MessageContent<T>): Extract<Message, {
|
|
60
|
+
type: T;
|
|
61
|
+
}>;
|
|
62
|
+
export declare function validateMessage(message: RawMessage): IncomingMessage;
|
|
63
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,eAAO,MAAM,WAAW;;;;;;CAMd,CAAA;AAEV,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,MAAM,OAAO,WAAW,CAAC,CAAA;AAEtE,eAAO,MAAM,sBAAsB,EAAE,MAAM,EAG1C,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,WAAW,CAAA;IACjB,SAAS,EAA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CACvB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,cAAc,CAAA;AAE/D,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAC5D,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,EAAE,IAAI,CAAC,CAAC,GAC9C,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,EAAE,MAAM,WAAW,CAAC,CAAA;AAwG5D,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,EACjD,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAe/B;AAED,wBAAgB,eAAe,CAAE,OAAO,EAAE,UAAU,GAAG,eAAe,CA4BrE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Format, Schema } from 'ajv';
|
|
2
|
+
import type { Middleware } from './utils';
|
|
3
|
+
export type FormatterField = {
|
|
4
|
+
type: string;
|
|
5
|
+
value: unknown;
|
|
6
|
+
};
|
|
7
|
+
export type FormatterSchema = Record<string, FormatterField>;
|
|
8
|
+
export type ValidationSchemas = {
|
|
9
|
+
headers?: FormatterSchema;
|
|
10
|
+
params?: FormatterSchema;
|
|
11
|
+
query?: FormatterSchema;
|
|
12
|
+
body?: Schema;
|
|
13
|
+
};
|
|
14
|
+
export type SchemaKey = keyof ValidationSchemas;
|
|
15
|
+
export declare function parseJsonBody(): Middleware;
|
|
16
|
+
export declare function setValidationFormats(formats: Record<string, Format>): void;
|
|
17
|
+
export declare function resetValidationFormatsState(): void;
|
|
18
|
+
export declare function validateSchemas(schemas: ValidationSchemas): Middleware;
|
|
19
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAoB,MAAM,KAAK,CAAA;AAC3D,OAAO,KAAK,EAAkB,UAAU,EAAmB,MAAM,SAAS,CAAA;AAE1E,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAE5D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,eAAe,CAAA;IACzB,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,KAAK,CAAC,EAAE,eAAe,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAA;AA2F/C,wBAAgB,aAAa,IAAK,UAAU,CAoB3C;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,IAAI,CAUN;AAID,wBAAgB,2BAA2B,IAAK,IAAI,CAGnD;AAcD,wBAAgB,eAAe,CAC7B,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAgCZ"}
|
package/dist/socket.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { WebSocketHandler } from 'bun';
|
|
2
|
+
import type { HttpMethod, Request, Middleware, SocketData, AppOptions } from './utils';
|
|
3
|
+
export type Ticket = {
|
|
4
|
+
clientId: string;
|
|
5
|
+
expiresAt: number;
|
|
6
|
+
};
|
|
7
|
+
export type SocketConnection = {
|
|
8
|
+
data: SocketData;
|
|
9
|
+
send: (data: string) => unknown;
|
|
10
|
+
close: () => void;
|
|
11
|
+
};
|
|
12
|
+
export type ActiveSession = {
|
|
13
|
+
token: string;
|
|
14
|
+
ws: SocketConnection;
|
|
15
|
+
};
|
|
16
|
+
export type InactiveSession = {
|
|
17
|
+
token: string;
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
};
|
|
20
|
+
export type Session = ActiveSession | InactiveSession;
|
|
21
|
+
export type SocketState = {
|
|
22
|
+
disconnectThreshold: number;
|
|
23
|
+
heartbeatInterval: number;
|
|
24
|
+
maxTickets: number;
|
|
25
|
+
reclaimTtl: number;
|
|
26
|
+
ticketTtl: number;
|
|
27
|
+
tickets: Map<string, Ticket>;
|
|
28
|
+
activeSessions: Map<string, ActiveSession>;
|
|
29
|
+
inactiveSessions: Map<string, InactiveSession>;
|
|
30
|
+
};
|
|
31
|
+
export type SocketRoute = {
|
|
32
|
+
method: HttpMethod;
|
|
33
|
+
path: string;
|
|
34
|
+
segments: string[];
|
|
35
|
+
chain: Middleware[];
|
|
36
|
+
};
|
|
37
|
+
export type SocketEndpoint = {
|
|
38
|
+
method: HttpMethod;
|
|
39
|
+
path: string;
|
|
40
|
+
handler: (req: Request, res: unknown) => Response;
|
|
41
|
+
};
|
|
42
|
+
export type SocketCommands = {
|
|
43
|
+
send: (clientId: string, event: string, body: unknown) => void;
|
|
44
|
+
broadcast: (event: string, body: unknown) => void;
|
|
45
|
+
};
|
|
46
|
+
export declare function buildSocketState(opts?: AppOptions): SocketState;
|
|
47
|
+
export declare function buildSocketServer(routes: SocketRoute[], state: SocketState): WebSocketHandler<SocketData>;
|
|
48
|
+
export declare function buildSocketHandlers(state: SocketState): SocketEndpoint[];
|
|
49
|
+
export declare function buildSocketCommands(state: SocketState): SocketCommands;
|
|
50
|
+
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../src/socket.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAG3C,O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AU,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,QAAQ,CAAA;CAClD,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IAC9D,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;CAClD,CAAA;AAmTD,wBAAgB,gBAAgB,CAAE,IAAI,GAAE,UAAe,GAAG,WAAW,CAWpE;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,EAAE,EACrB,KAAK,EAAE,WAAW,GACjB,gBAAgB,CAAC,UAAU,CAAC,CAuH9B;AAED,wBAAgB,mBAAmB,CAAE,KAAK,EAAE,WAAW,GAAG,cAAc,EAAE,CAqIzE;AAED,wBAAgB,mBAAmB,CAAE,KAAK,EAAE,WAAW,GAAG,cAAc,CA+BvE"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { ErrorObject } from 'ajv';
|
|
2
|
+
import type { BunRequest, Server as BunServer } from 'bun';
|
|
3
|
+
export declare const HttpMethod: {
|
|
4
|
+
readonly Head: "HEAD";
|
|
5
|
+
readonly Get: "GET";
|
|
6
|
+
readonly Post: "POST";
|
|
7
|
+
readonly Put: "PUT";
|
|
8
|
+
readonly Patch: "PATCH";
|
|
9
|
+
readonly Delete: "DELETE";
|
|
10
|
+
};
|
|
11
|
+
export type HttpMethod = typeof HttpMethod[keyof typeof HttpMethod];
|
|
12
|
+
export declare const StatusCode: {
|
|
13
|
+
readonly Continue: 100;
|
|
14
|
+
readonly SwitchingProtocols: 101;
|
|
15
|
+
readonly Processing: 102;
|
|
16
|
+
readonly EarlyHints: 103;
|
|
17
|
+
readonly Ok: 200;
|
|
18
|
+
readonly Created: 201;
|
|
19
|
+
readonly Accepted: 202;
|
|
20
|
+
readonly NonAuthoritativeInformation: 203;
|
|
21
|
+
readonly NoContent: 204;
|
|
22
|
+
readonly ResetContent: 205;
|
|
23
|
+
readonly PartialContent: 206;
|
|
24
|
+
readonly MultiStatus: 207;
|
|
25
|
+
readonly AlreadyReported: 208;
|
|
26
|
+
readonly ImUsed: 226;
|
|
27
|
+
readonly MultipleChoices: 300;
|
|
28
|
+
readonly MovedPermanently: 301;
|
|
29
|
+
readonly Found: 302;
|
|
30
|
+
readonly SeeOther: 303;
|
|
31
|
+
readonly NotModified: 304;
|
|
32
|
+
readonly UseProxy: 305;
|
|
33
|
+
readonly TemporaryRedirect: 307;
|
|
34
|
+
readonly PermanentRedirect: 308;
|
|
35
|
+
readonly BadRequest: 400;
|
|
36
|
+
readonly Unauthorized: 401;
|
|
37
|
+
readonly PaymentRequired: 402;
|
|
38
|
+
readonly Forbidden: 403;
|
|
39
|
+
readonly NotFound: 404;
|
|
40
|
+
readonly MethodNotAllowed: 405;
|
|
41
|
+
readonly NotAcceptable: 406;
|
|
42
|
+
readonly ProxyAuthenticationRequired: 407;
|
|
43
|
+
readonly RequestTimeout: 408;
|
|
44
|
+
readonly Conflict: 409;
|
|
45
|
+
readonly Gone: 410;
|
|
46
|
+
readonly LengthRequired: 411;
|
|
47
|
+
readonly PreconditionFailed: 412;
|
|
48
|
+
readonly PayloadTooLarge: 413;
|
|
49
|
+
readonly UriTooLong: 414;
|
|
50
|
+
readonly UnsupportedMediaType: 415;
|
|
51
|
+
readonly RangeNotSatisfiable: 416;
|
|
52
|
+
readonly ExpectationFailed: 417;
|
|
53
|
+
readonly ImATeapot: 418;
|
|
54
|
+
readonly MisdirectedRequest: 421;
|
|
55
|
+
readonly UnprocessableContent: 422;
|
|
56
|
+
readonly Locked: 423;
|
|
57
|
+
readonly FailedDependency: 424;
|
|
58
|
+
readonly TooEarly: 425;
|
|
59
|
+
readonly UpgradeRequired: 426;
|
|
60
|
+
readonly PreconditionRequired: 428;
|
|
61
|
+
readonly TooManyRequests: 429;
|
|
62
|
+
readonly RequestHeaderFieldsTooLarge: 431;
|
|
63
|
+
readonly UnavailableForLegalReasons: 451;
|
|
64
|
+
readonly InternalServerError: 500;
|
|
65
|
+
readonly NotImplemented: 501;
|
|
66
|
+
readonly BadGateway: 502;
|
|
67
|
+
readonly ServiceUnavailable: 503;
|
|
68
|
+
readonly GatewayTimeout: 504;
|
|
69
|
+
readonly HTTPVersionNotSupported: 505;
|
|
70
|
+
readonly VariantAlsoNegotiates: 506;
|
|
71
|
+
readonly InsufficientStorage: 507;
|
|
72
|
+
readonly LoopDetected: 508;
|
|
73
|
+
readonly NotExtended: 510;
|
|
74
|
+
readonly NetworkAuthenticationRequired: 511;
|
|
75
|
+
};
|
|
76
|
+
export type StatusCode = typeof StatusCode[keyof typeof StatusCode];
|
|
77
|
+
export type ValidationError = Partial<ErrorObject>;
|
|
78
|
+
export type FormattedError = {
|
|
79
|
+
path: string;
|
|
80
|
+
message: string;
|
|
81
|
+
};
|
|
82
|
+
export type NextFn = (data?: unknown) => Response | Promise<Response>;
|
|
83
|
+
export type BaseRequest = {
|
|
84
|
+
method: HttpMethod;
|
|
85
|
+
route: string;
|
|
86
|
+
headers: Headers;
|
|
87
|
+
params: Record<string, string>;
|
|
88
|
+
query: Record<string, unknown>;
|
|
89
|
+
json: () => Promise<unknown>;
|
|
90
|
+
};
|
|
91
|
+
export type EndpointRequest = BaseRequest & {
|
|
92
|
+
raw: BunRequest;
|
|
93
|
+
server: Server;
|
|
94
|
+
};
|
|
95
|
+
export type WebSocketRequest = BaseRequest & {
|
|
96
|
+
id: string;
|
|
97
|
+
clientId: string;
|
|
98
|
+
};
|
|
99
|
+
export type Request = EndpointRequest | WebSocketRequest;
|
|
100
|
+
export type Middleware = (req: Request, res: unknown, next: NextFn | null) => unknown;
|
|
101
|
+
export type SocketOptions = {
|
|
102
|
+
disconnectThreshold?: number;
|
|
103
|
+
heartbeatInterval?: number;
|
|
104
|
+
maxTickets?: number;
|
|
105
|
+
reclaimTtl?: number;
|
|
106
|
+
ticketTtl?: number;
|
|
107
|
+
};
|
|
108
|
+
export type SocketData = {
|
|
109
|
+
clientId: string;
|
|
110
|
+
superseded: boolean;
|
|
111
|
+
reaped: boolean;
|
|
112
|
+
reaperHandle: ReturnType<typeof setTimeout> | null;
|
|
113
|
+
};
|
|
114
|
+
export type Server = BunServer<SocketData>;
|
|
115
|
+
export type AppOptions = {
|
|
116
|
+
hostname?: string;
|
|
117
|
+
mountPath?: string;
|
|
118
|
+
middleware?: Middleware[];
|
|
119
|
+
ws?: SocketOptions;
|
|
120
|
+
onClose?: () => Promise<void> | void;
|
|
121
|
+
};
|
|
122
|
+
export declare function toSegments(pathString: string): string[];
|
|
123
|
+
export declare function formatError(prefix: string, input: ValidationError): FormattedError;
|
|
124
|
+
export declare function executeMiddlewareChain(req: Request, chain: Middleware[]): Promise<Response>;
|
|
125
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,CAAA;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,KAAK,CAAA;AAE1D,eAAO,MAAM,UAAU;;;;;;;CAOb,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AAEnE,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEb,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AAEnE,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,W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AE,MAAM,CAAA;IAChB,UAAU,EAAE,OAAO,CAAA;IACnB,MAAM,EAAE,OAAO,CAAA;IACf,YAAY,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,IAAI,CAAA;CACnD,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,CAAA;AAE1C,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,UAAU,EAAE,CAAA;IACzB,EAAE,CAAC,EAAE,aAAa,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACrC,CAAA;AAED,wBAAgB,UAAU,CAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAaxD;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,eAAe,GACrB,cAAc,CAQhB;AAED,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,UAAU,EAAE,GAClB,OAAO,CAAC,QAAQ,CAAC,CA0BnB"}
|
package/package.json
CHANGED
|
@@ -3,9 +3,20 @@
|
|
|
3
3
|
"description": "A more opinionated web server for building REST-ful applications",
|
|
4
4
|
"author": "Travis J True",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
7
|
-
"exports": "./src/index.js",
|
|
6
|
+
"version": "0.8.0",
|
|
8
7
|
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"bun": "./src/index.ts",
|
|
12
|
+
"default": "./src/index.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"!src/**/*.test.*"
|
|
19
|
+
],
|
|
9
20
|
"repository": {
|
|
10
21
|
"type": "git",
|
|
11
22
|
"url": "git+https://github.com/travistrue2008/sleepy-serv.git",
|
|
@@ -18,7 +29,10 @@
|
|
|
18
29
|
"web server",
|
|
19
30
|
"www"
|
|
20
31
|
],
|
|
21
|
-
"scripts": {
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.build.json",
|
|
34
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
35
|
+
},
|
|
22
36
|
"dependencies": {
|
|
23
37
|
"ajv": "^8.20.0",
|
|
24
38
|
"ajv-formats": "^3.0.1"
|