srvx 0.6.0 → 0.7.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.
@@ -1,24 +0,0 @@
1
- import { ServerOptions, Server, BunFetchHandler } from '../types.mjs';
2
- import * as Bun from 'bun';
3
- export { F as FastURL } from '../shared/srvx.DEE2RO4O.mjs';
4
- import 'node:http';
5
- import 'node:https';
6
- import 'node:net';
7
- import '@cloudflare/workers-types';
8
-
9
- declare const FastResponse: typeof globalThis.Response;
10
- declare function serve(options: ServerOptions): BunServer;
11
- declare class BunServer implements Server<BunFetchHandler> {
12
- readonly runtime = "bun";
13
- readonly options: ServerOptions;
14
- readonly bun: Server["bun"];
15
- readonly serveOptions: Bun.ServeOptions | Bun.TLSServeOptions;
16
- readonly fetch: BunFetchHandler;
17
- constructor(options: ServerOptions);
18
- serve(): Promise<this>;
19
- get url(): string | undefined;
20
- ready(): Promise<this>;
21
- close(closeAll?: boolean): Promise<void>;
22
- }
23
-
24
- export { FastResponse, serve };
@@ -1,80 +0,0 @@
1
- import { r as resolveTLSOptions, a as resolvePortAndHost, p as printListening, f as fmtURL } from '../shared/srvx.Ctaz0clH.mjs';
2
- export { F as FastURL } from '../shared/srvx.Ctaz0clH.mjs';
3
- import { w as wrapFetch } from '../shared/srvx.zEohKxBQ.mjs';
4
- import { w as wsUpgradePlugin } from '../shared/srvx.BMykKwGg.mjs';
5
- import 'node:fs';
6
-
7
- const FastResponse = Response;
8
- function serve(options) {
9
- return new BunServer(options);
10
- }
11
- class BunServer {
12
- constructor(options) {
13
- this.runtime = "bun";
14
- this.bun = {};
15
- this.options = options;
16
- const fetchHandler = wrapFetch(this, [wsUpgradePlugin]);
17
- this.fetch = (request, server) => {
18
- Object.defineProperties(request, {
19
- runtime: {
20
- enumerable: true,
21
- value: { runtime: "bun", bun: { server } }
22
- },
23
- ip: {
24
- enumerable: true,
25
- get() {
26
- return server?.requestIP(request)?.address;
27
- }
28
- }
29
- });
30
- return fetchHandler(request);
31
- };
32
- const tls = resolveTLSOptions(this.options);
33
- this.serveOptions = {
34
- ...resolvePortAndHost(this.options),
35
- reusePort: this.options.reusePort,
36
- error: this.options.error,
37
- ...this.options.bun,
38
- tls: {
39
- cert: tls?.cert,
40
- key: tls?.key,
41
- passphrase: tls?.passphrase,
42
- ...this.options.bun?.tls
43
- },
44
- fetch: this.fetch
45
- };
46
- if (!options.manual) {
47
- this.serve();
48
- }
49
- }
50
- serve() {
51
- if (!this.bun.server) {
52
- this.bun.server = Bun.serve(this.serveOptions);
53
- }
54
- printListening(this.options, this.url);
55
- return Promise.resolve(this);
56
- }
57
- get url() {
58
- const server = this.bun?.server;
59
- if (!server) {
60
- return;
61
- }
62
- const address = server.address;
63
- if (address) {
64
- return fmtURL(
65
- address.address,
66
- address.port,
67
- server.protocol === "https"
68
- );
69
- }
70
- return server.url.href;
71
- }
72
- ready() {
73
- return Promise.resolve(this);
74
- }
75
- close(closeAll) {
76
- return Promise.resolve(this.bun?.server?.stop(closeAll));
77
- }
78
- }
79
-
80
- export { FastResponse, serve };
@@ -1,12 +0,0 @@
1
- import { ServerOptions, Server } from '../types.mjs';
2
- import * as CF from '@cloudflare/workers-types';
3
- import 'node:http';
4
- import 'node:https';
5
- import 'node:net';
6
- import 'bun';
7
-
8
- declare const FastURL: typeof globalThis.URL;
9
- declare const FastResponse: typeof globalThis.Response;
10
- declare function serve(options: ServerOptions): Server<CF.ExportedHandlerFetchHandler>;
11
-
12
- export { FastResponse, FastURL, serve };
@@ -1,54 +0,0 @@
1
- import { w as wrapFetch } from '../shared/srvx.zEohKxBQ.mjs';
2
- import { e as errorPlugin } from '../shared/srvx.CEIXM-sv.mjs';
3
- import { w as wsUpgradePlugin } from '../shared/srvx.BMykKwGg.mjs';
4
-
5
- const FastURL = URL;
6
- const FastResponse = Response;
7
- function serve(options) {
8
- return new CloudflareServer(options);
9
- }
10
- class CloudflareServer {
11
- constructor(options) {
12
- this.runtime = "cloudflare";
13
- this.options = options;
14
- const fetchHandler = wrapFetch(this, [
15
- errorPlugin,
16
- wsUpgradePlugin
17
- ]);
18
- this.fetch = (request, env, context) => {
19
- Object.defineProperties(request, {
20
- runtime: {
21
- enumerable: true,
22
- value: { runtime: "cloudflare", cloudflare: { env, context } }
23
- }
24
- // TODO
25
- // ip: {
26
- // enumerable: true,
27
- // get() {
28
- // return;
29
- // },
30
- // },
31
- });
32
- return fetchHandler(request);
33
- };
34
- this.serveOptions = {
35
- fetch: this.fetch
36
- };
37
- if (!options.manual) {
38
- this.serve();
39
- }
40
- }
41
- serve() {
42
- addEventListener("fetch", (event) => {
43
- event.respondWith(this.fetch(event.request, {}, event));
44
- });
45
- }
46
- ready() {
47
- return Promise.resolve().then(() => this);
48
- }
49
- close() {
50
- return Promise.resolve();
51
- }
52
- }
53
-
54
- export { FastResponse, FastURL, serve };
@@ -1,25 +0,0 @@
1
- import { ServerOptions, Server, DenoFetchHandler } from '../types.mjs';
2
- export { F as FastURL } from '../shared/srvx.DEE2RO4O.mjs';
3
- import 'node:http';
4
- import 'node:https';
5
- import 'node:net';
6
- import 'bun';
7
- import '@cloudflare/workers-types';
8
-
9
- declare const FastResponse: typeof globalThis.Response;
10
- declare function serve(options: ServerOptions): DenoServer;
11
- declare class DenoServer implements Server<DenoFetchHandler> {
12
- #private;
13
- readonly runtime = "deno";
14
- readonly options: ServerOptions;
15
- readonly deno: Server["deno"];
16
- readonly serveOptions: Deno.ServeTcpOptions | (Deno.ServeTcpOptions & Deno.TlsCertifiedKeyPem);
17
- readonly fetch: DenoFetchHandler;
18
- constructor(options: ServerOptions);
19
- serve(): Promise<this>;
20
- get url(): string | undefined;
21
- ready(): Promise<Server>;
22
- close(): Promise<void | undefined>;
23
- }
24
-
25
- export { FastResponse, serve };
@@ -1,83 +0,0 @@
1
- import { r as resolveTLSOptions, a as resolvePortAndHost, p as printListening, f as fmtURL } from '../shared/srvx.Ctaz0clH.mjs';
2
- export { F as FastURL } from '../shared/srvx.Ctaz0clH.mjs';
3
- import { w as wrapFetch } from '../shared/srvx.zEohKxBQ.mjs';
4
- import { w as wsUpgradePlugin } from '../shared/srvx.BMykKwGg.mjs';
5
- import 'node:fs';
6
-
7
- const FastResponse = Response;
8
- function serve(options) {
9
- return new DenoServer(options);
10
- }
11
- class DenoServer {
12
- constructor(options) {
13
- this.runtime = "deno";
14
- this.deno = {};
15
- this.options = options;
16
- const fetchHandler = wrapFetch(this, [wsUpgradePlugin]);
17
- this.fetch = (request, info) => {
18
- Object.defineProperties(request, {
19
- runtime: {
20
- enumerable: true,
21
- value: { runtime: "deno", deno: { info, server: this.deno?.server } }
22
- },
23
- ip: {
24
- enumerable: true,
25
- get() {
26
- return info?.remoteAddr?.hostname;
27
- }
28
- }
29
- });
30
- return fetchHandler(request);
31
- };
32
- const tls = resolveTLSOptions(this.options);
33
- this.serveOptions = {
34
- ...resolvePortAndHost(this.options),
35
- reusePort: this.options.reusePort,
36
- onError: this.options.error,
37
- ...tls ? { key: tls.key, cert: tls.cert, passphrase: tls.passphrase } : {},
38
- ...this.options.deno
39
- };
40
- if (!options.manual) {
41
- this.serve();
42
- }
43
- }
44
- #listeningPromise;
45
- #listeningInfo;
46
- serve() {
47
- if (this.deno?.server) {
48
- return Promise.resolve(this.#listeningPromise).then(() => this);
49
- }
50
- const onListenPromise = Promise.withResolvers();
51
- this.#listeningPromise = onListenPromise.promise;
52
- this.deno.server = Deno.serve(
53
- {
54
- ...this.serveOptions,
55
- onListen: (info) => {
56
- this.#listeningInfo = info;
57
- if (this.options.deno?.onListen) {
58
- this.options.deno.onListen(info);
59
- }
60
- printListening(this.options, this.url);
61
- onListenPromise.resolve();
62
- }
63
- },
64
- this.fetch
65
- );
66
- return Promise.resolve(this.#listeningPromise).then(() => this);
67
- }
68
- get url() {
69
- return this.#listeningInfo ? fmtURL(
70
- this.#listeningInfo.hostname,
71
- this.#listeningInfo.port,
72
- !!this.serveOptions.cert
73
- ) : void 0;
74
- }
75
- ready() {
76
- return Promise.resolve(this.#listeningPromise).then(() => this);
77
- }
78
- close() {
79
- return Promise.resolve(this.deno?.server?.shutdown());
80
- }
81
- }
82
-
83
- export { FastResponse, serve };
@@ -1,12 +0,0 @@
1
- import { ServerOptions, Server } from '../types.mjs';
2
- import 'node:http';
3
- import 'node:https';
4
- import 'node:net';
5
- import 'bun';
6
- import '@cloudflare/workers-types';
7
-
8
- declare const FastURL: typeof globalThis.URL;
9
- declare const FastResponse: typeof globalThis.Response;
10
- declare function serve(options: ServerOptions): Server;
11
-
12
- export { FastResponse, FastURL, serve };
@@ -1,28 +0,0 @@
1
- import { w as wrapFetch } from '../shared/srvx.zEohKxBQ.mjs';
2
- import { e as errorPlugin } from '../shared/srvx.CEIXM-sv.mjs';
3
-
4
- const FastURL = URL;
5
- const FastResponse = Response;
6
- function serve(options) {
7
- return new GenericServer(options);
8
- }
9
- class GenericServer {
10
- constructor(options) {
11
- this.runtime = "generic";
12
- this.options = options;
13
- const fetchHandler = wrapFetch(this, [errorPlugin]);
14
- this.fetch = (request) => {
15
- return Promise.resolve(fetchHandler(request));
16
- };
17
- }
18
- serve() {
19
- }
20
- ready() {
21
- return Promise.resolve(this);
22
- }
23
- close() {
24
- return Promise.resolve();
25
- }
26
- }
27
-
28
- export { FastResponse, FastURL, serve };
@@ -1,55 +0,0 @@
1
- import { ServerRequest, ServerOptions, Server, FetchHandler, NodeHttpHandler } from '../types.mjs';
2
- export { F as FastURL } from '../shared/srvx.DEE2RO4O.mjs';
3
- import NodeHttp__default from 'node:http';
4
- import NodeStream, { Readable } from 'node:stream';
5
- import 'node:https';
6
- import 'node:net';
7
- import 'bun';
8
- import '@cloudflare/workers-types';
9
-
10
- type NodeResponse = InstanceType<typeof NodeResponse>;
11
- /**
12
- * Fast Response for Node.js runtime
13
- *
14
- * It is faster because in most cases it doesn't create a full Response instance.
15
- */
16
- declare const NodeResponse: {
17
- new (body?: BodyInit | null, init?: ResponseInit): globalThis.Response & {
18
- readonly nodeResponse: () => {
19
- status: number;
20
- statusText: string;
21
- headers: NodeHttp__default.OutgoingHttpHeader[];
22
- body: string | Buffer | Uint8Array | DataView | ReadableStream<Uint8Array> | Readable | undefined | null;
23
- };
24
- };
25
- };
26
-
27
- type NodeRequestContext = {
28
- req: NodeHttp__default.IncomingMessage;
29
- res?: NodeHttp__default.ServerResponse;
30
- upgrade?: {
31
- socket: NodeStream.Duplex;
32
- header: Buffer;
33
- };
34
- };
35
- declare const NodeRequest: {
36
- new (nodeCtx: NodeRequestContext): ServerRequest;
37
- };
38
-
39
- declare const NodeRequestHeaders: {
40
- new (nodeCtx: {
41
- req: NodeHttp__default.IncomingMessage;
42
- res?: NodeHttp__default.ServerResponse;
43
- }): globalThis.Headers;
44
- };
45
- declare const NodeResponseHeaders: {
46
- new (nodeCtx: {
47
- req?: NodeHttp__default.IncomingMessage;
48
- res: NodeHttp__default.ServerResponse;
49
- }): globalThis.Headers;
50
- };
51
-
52
- declare function serve(options: ServerOptions): Server;
53
- declare function toNodeHandler(fetchHandler: FetchHandler): NodeHttpHandler;
54
-
55
- export { NodeResponse as FastResponse, NodeRequest, NodeRequestHeaders, NodeResponse, NodeResponseHeaders, serve, toNodeHandler };