@mionjs/platform-bun 0.8.0-alpha.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.
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const src_bunHttp = require("./src/bunHttp.cjs");
4
+ const src_constants = require("./src/constants.cjs");
5
+ exports.resetBunHttpOpts = src_bunHttp.resetBunHttpOpts;
6
+ exports.setBunHttpOpts = src_bunHttp.setBunHttpOpts;
7
+ exports.startBunServer = src_bunHttp.startBunServer;
8
+ exports.DEFAULT_BUN_HTTP_OPTIONS = src_constants.DEFAULT_BUN_HTTP_OPTIONS;
9
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ export * from './src/types.ts';
2
+ export * from './src/bunHttp.ts';
3
+ export * from './src/constants.ts';
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const router = require("@mionjs/router");
4
+ const src_constants = require("./constants.cjs");
5
+ const core = require("@mionjs/core");
6
+ let httpOptions = { ...src_constants.DEFAULT_BUN_HTTP_OPTIONS };
7
+ let defaultHeaders = [["server", "@mionjs"]];
8
+ function resetBunHttpOpts() {
9
+ httpOptions = { ...src_constants.DEFAULT_BUN_HTTP_OPTIONS };
10
+ defaultHeaders = [["server", "@mionjs"]];
11
+ router.resetRouter();
12
+ }
13
+ function setBunHttpOpts(options) {
14
+ httpOptions = {
15
+ ...httpOptions,
16
+ ...options
17
+ };
18
+ defaultHeaders = [["server", "@mionjs"], ...Object.entries(httpOptions.defaultResponseHeaders)];
19
+ return httpOptions;
20
+ }
21
+ async function startBunServer(options) {
22
+ const isTest = core.getENV("NODE_ENV") === "test";
23
+ const isCompiling = core.isMionCompileMode();
24
+ if (options) setBunHttpOpts(options);
25
+ if (isCompiling) {
26
+ console.log("Compiling routes metadata and skipping mion server initialization...", {
27
+ port: httpOptions.port,
28
+ httpOptions
29
+ });
30
+ return void 0;
31
+ }
32
+ const port = httpOptions.port !== 80 ? `:${httpOptions.port}` : "";
33
+ const url = `http://localhost${port}`;
34
+ if (!isTest && !isCompiling) console.log(`mion bun server running on ${url}`);
35
+ const server = Bun.serve({
36
+ maxRequestBodySize: httpOptions.maxBodySize,
37
+ port: httpOptions.port,
38
+ ...httpOptions.options,
39
+ async fetch(req) {
40
+ const reqUrl = req.url;
41
+ const pathStart = reqUrl.indexOf("/", 8);
42
+ const queryStart = reqUrl.indexOf("?", pathStart);
43
+ const path = queryStart === -1 ? reqUrl.slice(pathStart) : reqUrl.slice(pathStart, queryStart);
44
+ const urlQuery = queryStart === -1 ? void 0 : reqUrl.slice(queryStart + 1);
45
+ const contentType = req.headers.get("content-type") || "";
46
+ const isBinary = contentType.startsWith("application/octet-stream");
47
+ let rawBody = req.body ? isBinary ? await req.arrayBuffer() : await req.json() : void 0;
48
+ let reqBodyType = isBinary ? core.SerializerModes.binary : core.SerializerModes.json;
49
+ const queryBody = router.decodeQueryBody(urlQuery, rawBody);
50
+ if (queryBody) {
51
+ rawBody = queryBody.rawBody;
52
+ reqBodyType = queryBody.bodyType;
53
+ }
54
+ const responseHeaders = new Headers(defaultHeaders);
55
+ try {
56
+ const platformResp = await router.dispatchRoute(
57
+ path,
58
+ rawBody,
59
+ req.headers,
60
+ responseHeaders,
61
+ req,
62
+ void 0,
63
+ reqBodyType,
64
+ urlQuery
65
+ );
66
+ return reply(platformResp, responseHeaders);
67
+ } catch (e) {
68
+ const error = e instanceof core.RpcError ? e : new core.RpcError({
69
+ publicMessage: "Unknown Error",
70
+ type: "unknown-error",
71
+ originalError: e
72
+ });
73
+ return fatalFail(error, responseHeaders);
74
+ }
75
+ },
76
+ error(errReq) {
77
+ const responseHeaders = new Headers({
78
+ server: "@mionjs",
79
+ ...httpOptions.defaultResponseHeaders
80
+ });
81
+ const error = errReq instanceof core.RpcError ? errReq : new core.RpcError({
82
+ publicMessage: "Connection Error",
83
+ type: "response-connection-error",
84
+ originalError: errReq
85
+ });
86
+ return fatalFail(error, responseHeaders);
87
+ }
88
+ });
89
+ const shutdownHandler = function() {
90
+ if (!isTest) console.log(`Shutting down mion server on ${url}`);
91
+ server.stop(true);
92
+ process.exit(0);
93
+ };
94
+ process.on("SIGINT", shutdownHandler);
95
+ process.on("SIGTERM", shutdownHandler);
96
+ if (typeof Bun !== "undefined" && Bun.gc) {
97
+ Bun.gc(false);
98
+ }
99
+ return server;
100
+ }
101
+ function fatalFail(err, responseHeaders) {
102
+ const routeResponse = router.getRouterFatalErrorResponse(err, responseHeaders);
103
+ return reply(routeResponse, responseHeaders);
104
+ }
105
+ function reply(mionResp, responseHeaders) {
106
+ const bodyType = mionResp.serializer;
107
+ switch (bodyType) {
108
+ case core.SerializerModes.stringifyJson: {
109
+ return new Response(mionResp.rawBody, {
110
+ status: mionResp.statusCode,
111
+ headers: responseHeaders
112
+ });
113
+ }
114
+ case core.SerializerModes.json: {
115
+ return Response.json(mionResp.body, {
116
+ status: mionResp.statusCode,
117
+ headers: responseHeaders
118
+ });
119
+ }
120
+ case core.SerializerModes.binary: {
121
+ const serializer = mionResp.binSerializer;
122
+ responseHeaders.set("content-length", String(serializer.getLength()));
123
+ const response = new Response(serializer.getBufferView(), {
124
+ status: mionResp.statusCode,
125
+ headers: responseHeaders
126
+ });
127
+ serializer.markAsEnded();
128
+ return response;
129
+ }
130
+ default: {
131
+ const error = new core.RpcError({
132
+ publicMessage: "unknown-mion-response-format",
133
+ type: "unknown-error",
134
+ errorData: { bodyType }
135
+ });
136
+ return fatalFail(error, responseHeaders);
137
+ }
138
+ }
139
+ }
140
+ exports.resetBunHttpOpts = resetBunHttpOpts;
141
+ exports.setBunHttpOpts = setBunHttpOpts;
142
+ exports.startBunServer = startBunServer;
143
+ //# sourceMappingURL=bunHttp.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bunHttp.cjs","sources":["../../../src/bunHttp.ts"],"sourcesContent":["/* ########\n * 2023 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {\n dispatchRoute,\n getRouterFatalErrorResponse,\n resetRouter,\n decodeQueryBody,\n MionResponse as MionResponse,\n} from '@mionjs/router';\nimport {DEFAULT_BUN_HTTP_OPTIONS} from './constants.ts';\nimport type {BunHttpOptions} from './types.ts';\nimport {getENV, isMionCompileMode, SerializerModes} from '@mionjs/core';\nimport type {SerializerCode} from '@mionjs/core';\nimport {RpcError} from '@mionjs/core';\nimport {Server} from 'bun';\n\n// ############# PRIVATE STATE #############\n\nlet httpOptions: Readonly<BunHttpOptions> = {...DEFAULT_BUN_HTTP_OPTIONS};\nlet defaultHeaders: [string, string][] = [['server', '@mionjs']];\n\nexport function resetBunHttpOpts() {\n httpOptions = {...DEFAULT_BUN_HTTP_OPTIONS};\n defaultHeaders = [['server', '@mionjs']];\n resetRouter();\n}\n\nexport function setBunHttpOpts(options?: Partial<BunHttpOptions>) {\n httpOptions = {\n ...httpOptions,\n ...options,\n };\n // Pre-build default headers array once\n defaultHeaders = [['server', '@mionjs'], ...Object.entries(httpOptions.defaultResponseHeaders)];\n return httpOptions;\n}\n\nexport async function startBunServer(options?: Partial<BunHttpOptions>): Promise<Server<any>> {\n const isTest = getENV('NODE_ENV') === 'test';\n const isCompiling = isMionCompileMode();\n\n if (options) setBunHttpOpts(options);\n\n if (isCompiling) {\n console.log('Compiling routes metadata and skipping mion server initialization...', {\n port: httpOptions.port,\n httpOptions,\n });\n return undefined as any;\n }\n\n const port = httpOptions.port !== 80 ? `:${httpOptions.port}` : '';\n const url = `http://localhost${port}`;\n if (!isTest && !isCompiling) console.log(`mion bun server running on ${url}`);\n const server = Bun.serve({\n maxRequestBodySize: httpOptions.maxBodySize,\n port: httpOptions.port,\n ...httpOptions.options,\n\n async fetch(req) {\n const reqUrl = req.url;\n const pathStart = reqUrl.indexOf('/', 8);\n const queryStart = reqUrl.indexOf('?', pathStart);\n const path = queryStart === -1 ? reqUrl.slice(pathStart) : reqUrl.slice(pathStart, queryStart);\n const urlQuery = queryStart === -1 ? undefined : reqUrl.slice(queryStart + 1);\n const contentType = req.headers.get('content-type') || '';\n const isBinary = contentType.startsWith('application/octet-stream');\n let rawBody: any = req.body\n ? isBinary\n ? await req.arrayBuffer()\n : ((await req.json()) as Record<string, unknown>)\n : undefined;\n let reqBodyType: SerializerCode = isBinary ? SerializerModes.binary : SerializerModes.json;\n const queryBody = decodeQueryBody(urlQuery, rawBody);\n if (queryBody) {\n rawBody = queryBody.rawBody;\n reqBodyType = queryBody.bodyType;\n }\n const responseHeaders = new Headers(defaultHeaders);\n\n try {\n const platformResp = await dispatchRoute(\n path,\n rawBody,\n req.headers,\n responseHeaders,\n req,\n undefined,\n reqBodyType,\n urlQuery\n );\n return reply(platformResp, responseHeaders);\n } catch (e) {\n const error =\n e instanceof RpcError\n ? e\n : new RpcError({\n publicMessage: 'Unknown Error',\n type: 'unknown-error',\n originalError: e as Error,\n });\n return fatalFail(error, responseHeaders);\n }\n },\n error(errReq) {\n const responseHeaders = new Headers({\n server: '@mionjs',\n ...httpOptions.defaultResponseHeaders,\n });\n const error =\n errReq instanceof RpcError\n ? errReq\n : new RpcError({\n publicMessage: 'Connection Error',\n type: 'response-connection-error',\n originalError: errReq,\n });\n return fatalFail(error, responseHeaders);\n },\n });\n\n const shutdownHandler = function () {\n if (!isTest) console.log(`Shutting down mion server on ${url}`);\n server.stop(true);\n process.exit(0);\n };\n\n process.on('SIGINT', shutdownHandler);\n process.on('SIGTERM', shutdownHandler);\n\n // Hint to Bun's GC after initialization to clean up any temporary allocations\n if (typeof Bun !== 'undefined' && Bun.gc) {\n Bun.gc(false);\n }\n return server;\n}\n\n// only called whe there is an htt error or weird unhandled route errors\nfunction fatalFail(err: RpcError<string>, responseHeaders: any): Response {\n const routeResponse = getRouterFatalErrorResponse(err, responseHeaders);\n return reply(routeResponse, responseHeaders);\n}\n\nfunction reply(\n mionResp: MionResponse,\n // TODO: fix issue with Native Bun Headers type messing with Node Headers type\n // responseHeaders: Headers,\n responseHeaders: any\n): Response {\n const bodyType = mionResp.serializer;\n switch (bodyType) {\n case SerializerModes.stringifyJson: {\n // Pass string directly to Response - Bun handles encoding internally\n // and calculates content-length automatically. This avoids TextEncoder allocation.\n // content-type already set by serializer\n return new Response(mionResp.rawBody as string, {\n status: mionResp.statusCode,\n headers: responseHeaders,\n });\n }\n case SerializerModes.json: {\n // Platform adapter uses Response.json() which handles JSON.stringify internally\n return Response.json(mionResp.body, {\n status: mionResp.statusCode,\n headers: responseHeaders,\n });\n }\n case SerializerModes.binary: {\n const serializer = mionResp.binSerializer!;\n responseHeaders.set('content-length', String(serializer.getLength()));\n // content-type already set by serializer\n const response = new Response(serializer.getBufferView(), {\n status: mionResp.statusCode,\n headers: responseHeaders,\n });\n // Mark buffer as ended immediately - Bun copies the buffer to the response\n serializer.markAsEnded();\n return response;\n }\n default: {\n const error = new RpcError({\n publicMessage: 'unknown-mion-response-format',\n type: 'unknown-error',\n errorData: {bodyType},\n });\n return fatalFail(error, responseHeaders);\n }\n }\n}\n"],"names":["DEFAULT_BUN_HTTP_OPTIONS","resetRouter","getENV","isMionCompileMode","SerializerModes","decodeQueryBody","dispatchRoute","RpcError","getRouterFatalErrorResponse"],"mappings":";;;;;AAuBA,IAAI,cAAwC,EAAC,GAAGA,uCAAA;AAChD,IAAI,iBAAqC,CAAC,CAAC,UAAU,SAAS,CAAC;AAExD,SAAS,mBAAmB;AAC/B,gBAAc,EAAC,GAAGA,uCAAA;AAClB,mBAAiB,CAAC,CAAC,UAAU,SAAS,CAAC;AACvCC,qBAAA;AACJ;AAEO,SAAS,eAAe,SAAmC;AAC9D,gBAAc;AAAA,IACV,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAGP,mBAAi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A;AAAA,IACJ,KAAKJ,KAAAA,gBAAgB,eAAe;AAIhC,aAAO,IAAI,SAAS,SAAS,SAAmB;AAAA,QAC5C,QAAQ,SAAS;AAAA,QACjB,SAAS;AAAA,MAAA,CACZ;AAAA,IACL;AAAA,IACA,KAAKA,KAAAA,gBAAgB,MAAM;AAEvB,aAAO,SAAS,KAAK,SAAS,MAAM;AAAA,QAChC,QAAQ,SAAS;AAAA,QACjB,SAAS;AAAA,MAAA,CACZ;AAAA,IACL;AAAA,IACA,KAAKA,KAAAA,gBAAgB,QAAQ;AACzB,YAAM,aAAa,SAAS;AAC5B,sBAAgB,IAAI,kBAAkB,OAAO,WAAW,UAAA,CAAW,CAAC;AAEpE,YAAM,WAAW,IAAI,SAAS,WAAW,iBAAiB;AAAA,QACtD,QAAQ,SAAS;AAAA,QACjB,SAAS;AAAA,MAAA,CACZ;AAED,iBAAW,YAAA;AACX,aAAO;AAAA,IACX;AAAA,IACA,SAAS;AACL,YAAM,QAAQ,IAAIG,cAAS;AAAA,QACvB,eAAe;AAAA,QACf,MAAM;AAAA,QACN,WAAW,EAAC,SAAA;AAAA,MAAQ,CACvB;AACD,aAAO,UAAU,OAAO,eAAe;AAAA,IAC3C;AAAA,EAAA;AAER;;;;"}
@@ -0,0 +1,5 @@
1
+ import { BunHttpOptions } from './types.ts';
2
+ import { Server } from 'bun';
3
+ export declare function resetBunHttpOpts(): void;
4
+ export declare function setBunHttpOpts(options?: Partial<BunHttpOptions>): Readonly<BunHttpOptions>;
5
+ export declare function startBunServer(options?: Partial<BunHttpOptions>): Promise<Server<any>>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const DEFAULT_BUN_HTTP_OPTIONS = {
4
+ port: 80,
5
+ options: {},
6
+ defaultResponseHeaders: {},
7
+ /**
8
+ * 256KB by default, same as lambda payload
9
+ * @link https://docs.aws.amazon.com/lambda/latest/operatorguide/payload.html
10
+ * */
11
+ maxBodySize: 256e3
12
+ // 256KB
13
+ };
14
+ exports.DEFAULT_BUN_HTTP_OPTIONS = DEFAULT_BUN_HTTP_OPTIONS;
15
+ //# sourceMappingURL=constants.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.cjs","sources":["../../../src/constants.ts"],"sourcesContent":["/* ########\n * 2022 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {BunHttpOptions} from './types.ts';\n\nexport const DEFAULT_BUN_HTTP_OPTIONS: BunHttpOptions = {\n port: 80,\n options: {},\n defaultResponseHeaders: {},\n /**\n * 256KB by default, same as lambda payload\n * @link https://docs.aws.amazon.com/lambda/latest/operatorguide/payload.html\n * */\n maxBodySize: 256000, // 256KB\n};\n"],"names":[],"mappings":";;AASO,MAAM,2BAA2C;AAAA,EACpD,MAAM;AAAA,EACN,SAAS,CAAA;AAAA,EACT,wBAAwB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxB,aAAa;AAAA;AACjB;;"}
@@ -0,0 +1,2 @@
1
+ import { BunHttpOptions } from './types.ts';
2
+ export declare const DEFAULT_BUN_HTTP_OPTIONS: BunHttpOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ type BunServeOptions = Omit<Bun.Serve.BaseServeOptions<unknown>, 'error'> & Omit<Bun.Serve.HostnamePortServeOptions<unknown>, 'error'>;
2
+ export interface BunHttpOptions {
3
+ port: number;
4
+ options: BunServeOptions;
5
+ defaultResponseHeaders: Record<string, string>;
6
+ maxBodySize: number;
7
+ }
8
+ export {};
9
+ export declare type __ΩBunHttpOptions = any[];
@@ -0,0 +1,3 @@
1
+ export * from './src/types.ts';
2
+ export * from './src/bunHttp.ts';
3
+ export * from './src/constants.ts';
@@ -0,0 +1,9 @@
1
+ import { resetBunHttpOpts, setBunHttpOpts, startBunServer } from "./src/bunHttp.js";
2
+ import { DEFAULT_BUN_HTTP_OPTIONS } from "./src/constants.js";
3
+ export {
4
+ DEFAULT_BUN_HTTP_OPTIONS,
5
+ resetBunHttpOpts,
6
+ setBunHttpOpts,
7
+ startBunServer
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,5 @@
1
+ import { BunHttpOptions } from './types.ts';
2
+ import { Server } from 'bun';
3
+ export declare function resetBunHttpOpts(): void;
4
+ export declare function setBunHttpOpts(options?: Partial<BunHttpOptions>): Readonly<BunHttpOptions>;
5
+ export declare function startBunServer(options?: Partial<BunHttpOptions>): Promise<Server<any>>;
@@ -0,0 +1,143 @@
1
+ import { resetRouter, decodeQueryBody, dispatchRoute, getRouterFatalErrorResponse } from "@mionjs/router";
2
+ import { DEFAULT_BUN_HTTP_OPTIONS } from "./constants.js";
3
+ import { getENV, isMionCompileMode, RpcError, SerializerModes } from "@mionjs/core";
4
+ let httpOptions = { ...DEFAULT_BUN_HTTP_OPTIONS };
5
+ let defaultHeaders = [["server", "@mionjs"]];
6
+ function resetBunHttpOpts() {
7
+ httpOptions = { ...DEFAULT_BUN_HTTP_OPTIONS };
8
+ defaultHeaders = [["server", "@mionjs"]];
9
+ resetRouter();
10
+ }
11
+ function setBunHttpOpts(options) {
12
+ httpOptions = {
13
+ ...httpOptions,
14
+ ...options
15
+ };
16
+ defaultHeaders = [["server", "@mionjs"], ...Object.entries(httpOptions.defaultResponseHeaders)];
17
+ return httpOptions;
18
+ }
19
+ async function startBunServer(options) {
20
+ const isTest = getENV("NODE_ENV") === "test";
21
+ const isCompiling = isMionCompileMode();
22
+ if (options) setBunHttpOpts(options);
23
+ if (isCompiling) {
24
+ console.log("Compiling routes metadata and skipping mion server initialization...", {
25
+ port: httpOptions.port,
26
+ httpOptions
27
+ });
28
+ return void 0;
29
+ }
30
+ const port = httpOptions.port !== 80 ? `:${httpOptions.port}` : "";
31
+ const url = `http://localhost${port}`;
32
+ if (!isTest && !isCompiling) console.log(`mion bun server running on ${url}`);
33
+ const server = Bun.serve({
34
+ maxRequestBodySize: httpOptions.maxBodySize,
35
+ port: httpOptions.port,
36
+ ...httpOptions.options,
37
+ async fetch(req) {
38
+ const reqUrl = req.url;
39
+ const pathStart = reqUrl.indexOf("/", 8);
40
+ const queryStart = reqUrl.indexOf("?", pathStart);
41
+ const path = queryStart === -1 ? reqUrl.slice(pathStart) : reqUrl.slice(pathStart, queryStart);
42
+ const urlQuery = queryStart === -1 ? void 0 : reqUrl.slice(queryStart + 1);
43
+ const contentType = req.headers.get("content-type") || "";
44
+ const isBinary = contentType.startsWith("application/octet-stream");
45
+ let rawBody = req.body ? isBinary ? await req.arrayBuffer() : await req.json() : void 0;
46
+ let reqBodyType = isBinary ? SerializerModes.binary : SerializerModes.json;
47
+ const queryBody = decodeQueryBody(urlQuery, rawBody);
48
+ if (queryBody) {
49
+ rawBody = queryBody.rawBody;
50
+ reqBodyType = queryBody.bodyType;
51
+ }
52
+ const responseHeaders = new Headers(defaultHeaders);
53
+ try {
54
+ const platformResp = await dispatchRoute(
55
+ path,
56
+ rawBody,
57
+ req.headers,
58
+ responseHeaders,
59
+ req,
60
+ void 0,
61
+ reqBodyType,
62
+ urlQuery
63
+ );
64
+ return reply(platformResp, responseHeaders);
65
+ } catch (e) {
66
+ const error = e instanceof RpcError ? e : new RpcError({
67
+ publicMessage: "Unknown Error",
68
+ type: "unknown-error",
69
+ originalError: e
70
+ });
71
+ return fatalFail(error, responseHeaders);
72
+ }
73
+ },
74
+ error(errReq) {
75
+ const responseHeaders = new Headers({
76
+ server: "@mionjs",
77
+ ...httpOptions.defaultResponseHeaders
78
+ });
79
+ const error = errReq instanceof RpcError ? errReq : new RpcError({
80
+ publicMessage: "Connection Error",
81
+ type: "response-connection-error",
82
+ originalError: errReq
83
+ });
84
+ return fatalFail(error, responseHeaders);
85
+ }
86
+ });
87
+ const shutdownHandler = function() {
88
+ if (!isTest) console.log(`Shutting down mion server on ${url}`);
89
+ server.stop(true);
90
+ process.exit(0);
91
+ };
92
+ process.on("SIGINT", shutdownHandler);
93
+ process.on("SIGTERM", shutdownHandler);
94
+ if (typeof Bun !== "undefined" && Bun.gc) {
95
+ Bun.gc(false);
96
+ }
97
+ return server;
98
+ }
99
+ function fatalFail(err, responseHeaders) {
100
+ const routeResponse = getRouterFatalErrorResponse(err, responseHeaders);
101
+ return reply(routeResponse, responseHeaders);
102
+ }
103
+ function reply(mionResp, responseHeaders) {
104
+ const bodyType = mionResp.serializer;
105
+ switch (bodyType) {
106
+ case SerializerModes.stringifyJson: {
107
+ return new Response(mionResp.rawBody, {
108
+ status: mionResp.statusCode,
109
+ headers: responseHeaders
110
+ });
111
+ }
112
+ case SerializerModes.json: {
113
+ return Response.json(mionResp.body, {
114
+ status: mionResp.statusCode,
115
+ headers: responseHeaders
116
+ });
117
+ }
118
+ case SerializerModes.binary: {
119
+ const serializer = mionResp.binSerializer;
120
+ responseHeaders.set("content-length", String(serializer.getLength()));
121
+ const response = new Response(serializer.getBufferView(), {
122
+ status: mionResp.statusCode,
123
+ headers: responseHeaders
124
+ });
125
+ serializer.markAsEnded();
126
+ return response;
127
+ }
128
+ default: {
129
+ const error = new RpcError({
130
+ publicMessage: "unknown-mion-response-format",
131
+ type: "unknown-error",
132
+ errorData: { bodyType }
133
+ });
134
+ return fatalFail(error, responseHeaders);
135
+ }
136
+ }
137
+ }
138
+ export {
139
+ resetBunHttpOpts,
140
+ setBunHttpOpts,
141
+ startBunServer
142
+ };
143
+ //# sourceMappingURL=bunHttp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bunHttp.js","sources":["../../../src/bunHttp.ts"],"sourcesContent":["/* ########\n * 2023 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {\n dispatchRoute,\n getRouterFatalErrorResponse,\n resetRouter,\n decodeQueryBody,\n MionResponse as MionResponse,\n} from '@mionjs/router';\nimport {DEFAULT_BUN_HTTP_OPTIONS} from './constants.ts';\nimport type {BunHttpOptions} from './types.ts';\nimport {getENV, isMionCompileMode, SerializerModes} from '@mionjs/core';\nimport type {SerializerCode} from '@mionjs/core';\nimport {RpcError} from '@mionjs/core';\nimport {Server} from 'bun';\n\n// ############# PRIVATE STATE #############\n\nlet httpOptions: Readonly<BunHttpOptions> = {...DEFAULT_BUN_HTTP_OPTIONS};\nlet defaultHeaders: [string, string][] = [['server', '@mionjs']];\n\nexport function resetBunHttpOpts() {\n httpOptions = {...DEFAULT_BUN_HTTP_OPTIONS};\n defaultHeaders = [['server', '@mionjs']];\n resetRouter();\n}\n\nexport function setBunHttpOpts(options?: Partial<BunHttpOptions>) {\n httpOptions = {\n ...httpOptions,\n ...options,\n };\n // Pre-build default headers array once\n defaultHeaders = [['server', '@mionjs'], ...Object.entries(httpOptions.defaultResponseHeaders)];\n return httpOptions;\n}\n\nexport async function startBunServer(options?: Partial<BunHttpOptions>): Promise<Server<any>> {\n const isTest = getENV('NODE_ENV') === 'test';\n const isCompiling = isMionCompileMode();\n\n if (options) setBunHttpOpts(options);\n\n if (isCompiling) {\n console.log('Compiling routes metadata and skipping mion server initialization...', {\n port: httpOptions.port,\n httpOptions,\n });\n return undefined as any;\n }\n\n const port = httpOptions.port !== 80 ? `:${httpOptions.port}` : '';\n const url = `http://localhost${port}`;\n if (!isTest && !isCompiling) console.log(`mion bun server running on ${url}`);\n const server = Bun.serve({\n maxRequestBodySize: httpOptions.maxBodySize,\n port: httpOptions.port,\n ...httpOptions.options,\n\n async fetch(req) {\n const reqUrl = req.url;\n const pathStart = reqUrl.indexOf('/', 8);\n const queryStart = reqUrl.indexOf('?', pathStart);\n const path = queryStart === -1 ? reqUrl.slice(pathStart) : reqUrl.slice(pathStart, queryStart);\n const urlQuery = queryStart === -1 ? undefined : reqUrl.slice(queryStart + 1);\n const contentType = req.headers.get('content-type') || '';\n const isBinary = contentType.startsWith('application/octet-stream');\n let rawBody: any = req.body\n ? isBinary\n ? await req.arrayBuffer()\n : ((await req.json()) as Record<string, unknown>)\n : undefined;\n let reqBodyType: SerializerCode = isBinary ? SerializerModes.binary : SerializerModes.json;\n const queryBody = decodeQueryBody(urlQuery, rawBody);\n if (queryBody) {\n rawBody = queryBody.rawBody;\n reqBodyType = queryBody.bodyType;\n }\n const responseHeaders = new Headers(defaultHeaders);\n\n try {\n const platformResp = await dispatchRoute(\n path,\n rawBody,\n req.headers,\n responseHeaders,\n req,\n undefined,\n reqBodyType,\n urlQuery\n );\n return reply(platformResp, responseHeaders);\n } catch (e) {\n const error =\n e instanceof RpcError\n ? e\n : new RpcError({\n publicMessage: 'Unknown Error',\n type: 'unknown-error',\n originalError: e as Error,\n });\n return fatalFail(error, responseHeaders);\n }\n },\n error(errReq) {\n const responseHeaders = new Headers({\n server: '@mionjs',\n ...httpOptions.defaultResponseHeaders,\n });\n const error =\n errReq instanceof RpcError\n ? errReq\n : new RpcError({\n publicMessage: 'Connection Error',\n type: 'response-connection-error',\n originalError: errReq,\n });\n return fatalFail(error, responseHeaders);\n },\n });\n\n const shutdownHandler = function () {\n if (!isTest) console.log(`Shutting down mion server on ${url}`);\n server.stop(true);\n process.exit(0);\n };\n\n process.on('SIGINT', shutdownHandler);\n process.on('SIGTERM', shutdownHandler);\n\n // Hint to Bun's GC after initialization to clean up any temporary allocations\n if (typeof Bun !== 'undefined' && Bun.gc) {\n Bun.gc(false);\n }\n return server;\n}\n\n// only called whe there is an htt error or weird unhandled route errors\nfunction fatalFail(err: RpcError<string>, responseHeaders: any): Response {\n const routeResponse = getRouterFatalErrorResponse(err, responseHeaders);\n return reply(routeResponse, responseHeaders);\n}\n\nfunction reply(\n mionResp: MionResponse,\n // TODO: fix issue with Native Bun Headers type messing with Node Headers type\n // responseHeaders: Headers,\n responseHeaders: any\n): Response {\n const bodyType = mionResp.serializer;\n switch (bodyType) {\n case SerializerModes.stringifyJson: {\n // Pass string directly to Response - Bun handles encoding internally\n // and calculates content-length automatically. This avoids TextEncoder allocation.\n // content-type already set by serializer\n return new Response(mionResp.rawBody as string, {\n status: mionResp.statusCode,\n headers: responseHeaders,\n });\n }\n case SerializerModes.json: {\n // Platform adapter uses Response.json() which handles JSON.stringify internally\n return Response.json(mionResp.body, {\n status: mionResp.statusCode,\n headers: responseHeaders,\n });\n }\n case SerializerModes.binary: {\n const serializer = mionResp.binSerializer!;\n responseHeaders.set('content-length', String(serializer.getLength()));\n // content-type already set by serializer\n const response = new Response(serializer.getBufferView(), {\n status: mionResp.statusCode,\n headers: responseHeaders,\n });\n // Mark buffer as ended immediately - Bun copies the buffer to the response\n serializer.markAsEnded();\n return response;\n }\n default: {\n const error = new RpcError({\n publicMessage: 'unknown-mion-response-format',\n type: 'unknown-error',\n errorData: {bodyType},\n });\n return fatalFail(error, responseHeaders);\n }\n }\n}\n"],"names":[],"mappings":";;;AAuBA,IAAI,cAAwC,EAAC,GAAG,yBAAA;AAChD,IAAI,iBAAqC,CAAC,CAAC,UAAU,SAAS,CAAC;AAExD,SAAS,mBAAmB;AAC/B,gBAAc,EAAC,GAAG,yBAAA;AAClB,mBAAiB,CAAC,CAAC,UAAU,SAAS,CAAC;AACvC,cAAA;AACJ;AAEO,SAAS,eAAe,SAAmC;AAC9D,gBAAc;AAAA,IACV,GAAG;AAAA,IACH,GAAG;AAAA,EAAA;AAGP,mBAAiB,CAAC,CAAC,UAAU,SAAS,GAAG,GAAG,OAAO,QAAQ,YAAY,sBAAsB,CAAC;AAC9F,SAAO;AACX;AAEA,eAAsB,eAAe,SAAyD;AAC1F,QAAM,SAAS,OAAO,UAAU,MAAM;AACtC,QAAM,cAAc,kBAAA;AAEpB,MAAI,wBAAwB,OAAO;AAEnC,MAAI,aAAa;AACb,YAAQ,IAAI,wEAAwE;AAAA,MAChF,MAAM,YAAY;AAAA,MAClB;AAAA,IAAA,CACH;AACD,WAA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AEpE,YAAM,WAAW,IAAI,SAAS,WAAW,iBAAiB;AAAA,QACtD,QAAQ,SAAS;AAAA,QACjB,SAAS;AAAA,MAAA,CACZ;AAED,iBAAW,YAAA;AACX,aAAO;AAAA,IACX;AAAA,IACA,SAAS;AACL,YAAM,QAAQ,IAAI,SAAS;AAAA,QACvB,eAAe;AAAA,QACf,MAAM;AAAA,QACN,WAAW,EAAC,SAAA;AAAA,MAAQ,CACvB;AACD,aAAO,UAAU,OAAO,eAAe;AAAA,IAC3C;AAAA,EAAA;AAER;"}
@@ -0,0 +1,2 @@
1
+ import { BunHttpOptions } from './types.ts';
2
+ export declare const DEFAULT_BUN_HTTP_OPTIONS: BunHttpOptions;
@@ -0,0 +1,15 @@
1
+ const DEFAULT_BUN_HTTP_OPTIONS = {
2
+ port: 80,
3
+ options: {},
4
+ defaultResponseHeaders: {},
5
+ /**
6
+ * 256KB by default, same as lambda payload
7
+ * @link https://docs.aws.amazon.com/lambda/latest/operatorguide/payload.html
8
+ * */
9
+ maxBodySize: 256e3
10
+ // 256KB
11
+ };
12
+ export {
13
+ DEFAULT_BUN_HTTP_OPTIONS
14
+ };
15
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../../src/constants.ts"],"sourcesContent":["/* ########\n * 2022 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {BunHttpOptions} from './types.ts';\n\nexport const DEFAULT_BUN_HTTP_OPTIONS: BunHttpOptions = {\n port: 80,\n options: {},\n defaultResponseHeaders: {},\n /**\n * 256KB by default, same as lambda payload\n * @link https://docs.aws.amazon.com/lambda/latest/operatorguide/payload.html\n * */\n maxBodySize: 256000, // 256KB\n};\n"],"names":[],"mappings":"AASO,MAAM,2BAA2C;AAAA,EACpD,MAAM;AAAA,EACN,SAAS,CAAA;AAAA,EACT,wBAAwB,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxB,aAAa;AAAA;AACjB;"}
@@ -0,0 +1,9 @@
1
+ type BunServeOptions = Omit<Bun.Serve.BaseServeOptions<unknown>, 'error'> & Omit<Bun.Serve.HostnamePortServeOptions<unknown>, 'error'>;
2
+ export interface BunHttpOptions {
3
+ port: number;
4
+ options: BunServeOptions;
5
+ defaultResponseHeaders: Record<string, string>;
6
+ maxBodySize: number;
7
+ }
8
+ export {};
9
+ export declare type __ΩBunHttpOptions = any[];
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mion
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/MionKit/mion/master/assets/public/bannerx90-dark.png">
4
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/MionKit/mion/master/assets/public/bannerx90.png">
5
+ <img alt='mion, a mikro kit for Typescript Serverless APIs' src='https://raw.githubusercontent.com/MionKit/mion/master/assets/public/bannerx90.png'>
6
+ </picture>
7
+ </p>
8
+ <p align="center">
9
+ <strong>Full Stack APIs at the speed of light 🚀
10
+ </strong>
11
+ </p>
12
+ <p align=center>
13
+ <img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square&maxAge=99999999" alt="npm" style="max-width:100%;">
14
+ <img src="https://img.shields.io/badge/license-MIT-97ca00.svg?style=flat-square&maxAge=99999999" alt="npm" style="max-width:100%;">
15
+ </p>
16
+
17
+ # `@mionjs/platform-bun`
18
+
19
+ This package contains a Bun server to run mion APIs!
20
+
21
+ ## Check Out The [Website And Documentation](http://mion.io) 📚
22
+
23
+ [![mion-website-banner](https://raw.githubusercontent.com/MionKit/mion/master/assets/public/mion-website-banner.png)](http://mion.io)
24
+
25
+ ---
26
+
27
+ _[MIT](../../LICENSE) LICENSE_
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@mionjs/platform-bun",
3
+ "version": "0.8.0-alpha.0",
4
+ "description": "mion server for bun runtime",
5
+ "keywords": [
6
+ "typescript",
7
+ "API",
8
+ "RPC",
9
+ "json",
10
+ "schema",
11
+ "generate",
12
+ "server",
13
+ "serverless",
14
+ "framework",
15
+ "node",
16
+ "runtime types"
17
+ ],
18
+ "author": "ma jerez",
19
+ "homepage": "https://mion.io/",
20
+ "license": "MIT",
21
+ "exports": {
22
+ ".": {
23
+ "source": "./index.ts",
24
+ "types": "./.dist/esm/index.d.ts",
25
+ "require": "./.dist/cjs/index.cjs",
26
+ "default": "./.dist/esm/index.js"
27
+ }
28
+ },
29
+ "directories": {
30
+ "lib": ".dist"
31
+ },
32
+ "files": [
33
+ ".dist"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/MionKit/mion.git"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "engines": {
43
+ "bun": ">=1.0.1"
44
+ },
45
+ "scripts": {
46
+ "test": "bun test",
47
+ "dev": "vite build --watch",
48
+ "dev:test": "bun test --watch",
49
+ "lint": "npx eslint src",
50
+ "format": "prettier --write src/**/*.ts",
51
+ "build": "vite build",
52
+ "clean": "rimraf .dist & rimraf .coverage",
53
+ "fresh-start": "npm run clean && rimraf node_modules"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/MionKit/mion/issues"
57
+ },
58
+ "dependencies": {
59
+ "@mionjs/core": "^0.8.0-alpha.0",
60
+ "@mionjs/router": "^0.8.0-alpha.0"
61
+ },
62
+ "devDependencies": {
63
+ "@deepkit/core": "1.0.19",
64
+ "@deepkit/type-compiler": "1.0.19",
65
+ "bun-types": "latest"
66
+ },
67
+ "gitHead": "5d2ec524ba39d040338ce8946d8edf78aa7291a3"
68
+ }