balda-js 0.0.56 → 0.0.58
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/lib/index.cjs +59 -10
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +630 -610
- package/lib/index.d.ts +630 -610
- package/lib/index.js +59 -10
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -6,6 +6,8 @@ var path = require('path');
|
|
|
6
6
|
var zod = require('zod');
|
|
7
7
|
var fs = require('fs');
|
|
8
8
|
var http = require('http');
|
|
9
|
+
var http2 = require('http2');
|
|
10
|
+
var https = require('https');
|
|
9
11
|
|
|
10
12
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
11
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -5051,7 +5053,7 @@ var ServerBun = class {
|
|
|
5051
5053
|
this.tapOptions = input?.tapOptions;
|
|
5052
5054
|
}
|
|
5053
5055
|
listen() {
|
|
5054
|
-
const tapOptions = this.tapOptions?.
|
|
5056
|
+
const tapOptions = this.tapOptions?.bun;
|
|
5055
5057
|
const { fetch, ...rest } = tapOptions ?? {};
|
|
5056
5058
|
this.runtimeServer = Bun.serve({
|
|
5057
5059
|
port: this.port,
|
|
@@ -5108,7 +5110,7 @@ var ServerDeno = class {
|
|
|
5108
5110
|
this.tapOptions = input?.tapOptions;
|
|
5109
5111
|
}
|
|
5110
5112
|
listen() {
|
|
5111
|
-
const tapOptions = this.tapOptions?.
|
|
5113
|
+
const tapOptions = this.tapOptions?.deno;
|
|
5112
5114
|
const { handler, ...rest } = tapOptions ?? {};
|
|
5113
5115
|
this.runtimeServer = Deno.serve({
|
|
5114
5116
|
port: this.port,
|
|
@@ -5178,23 +5180,38 @@ var ServerNode = class {
|
|
|
5178
5180
|
routes;
|
|
5179
5181
|
tapOptions;
|
|
5180
5182
|
runtimeServer;
|
|
5183
|
+
nodeHttpClient;
|
|
5184
|
+
httpsOptions;
|
|
5181
5185
|
constructor(input) {
|
|
5182
5186
|
this.routes = input?.routes ?? [];
|
|
5183
5187
|
this.port = input?.port ?? 80;
|
|
5184
5188
|
this.host = input?.host ?? "0.0.0.0";
|
|
5185
|
-
this.url = `http://${this.host}:${this.port}`;
|
|
5186
5189
|
this.tapOptions = input?.tapOptions;
|
|
5187
|
-
this.
|
|
5190
|
+
this.nodeHttpClient = input?.nodeHttpClient ?? "http";
|
|
5191
|
+
this.httpsOptions = input?.nodeHttpClient === "https" || input?.nodeHttpClient === "http2-secure" ? input?.httpsOptions : void 0;
|
|
5192
|
+
const protocol = this.nodeHttpClient === "https" || this.nodeHttpClient === "http2-secure" ? "https" : "http";
|
|
5193
|
+
this.url = `${protocol}://${this.host}:${this.port}`;
|
|
5194
|
+
this.runtimeServer = this.createServer(
|
|
5188
5195
|
async (req, httpResponse) => {
|
|
5189
|
-
if (this.tapOptions && this.tapOptions.
|
|
5190
|
-
const
|
|
5191
|
-
await
|
|
5196
|
+
if (this.tapOptions && this.tapOptions.node) {
|
|
5197
|
+
const preHandler = this.tapOptions.node;
|
|
5198
|
+
await preHandler?.(req);
|
|
5192
5199
|
}
|
|
5193
5200
|
const match = router.find(req.method, req.url);
|
|
5201
|
+
const filteredHeaders = {};
|
|
5202
|
+
for (const key of Object.keys(req.headers)) {
|
|
5203
|
+
if (key.startsWith(":")) {
|
|
5204
|
+
continue;
|
|
5205
|
+
}
|
|
5206
|
+
const value = req.headers[key];
|
|
5207
|
+
if (value !== void 0) {
|
|
5208
|
+
filteredHeaders[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
5209
|
+
}
|
|
5210
|
+
}
|
|
5194
5211
|
const request = new Request2(`${this.url}${req.url}`, {
|
|
5195
5212
|
method: req.method,
|
|
5196
5213
|
body: canHaveBody(req.method) ? await this.readRequestBody(req) : void 0,
|
|
5197
|
-
headers:
|
|
5214
|
+
headers: filteredHeaders
|
|
5198
5215
|
});
|
|
5199
5216
|
let forwardedFor = req.headers["x-forwarded-for"];
|
|
5200
5217
|
if (Array.isArray(forwardedFor)) {
|
|
@@ -5263,6 +5280,33 @@ var ServerNode = class {
|
|
|
5263
5280
|
req.on("end", () => resolve(Buffer.concat(chunks).toString()));
|
|
5264
5281
|
});
|
|
5265
5282
|
}
|
|
5283
|
+
createServer(handler) {
|
|
5284
|
+
if (this.nodeHttpClient === "http") {
|
|
5285
|
+
return http.createServer(handler);
|
|
5286
|
+
}
|
|
5287
|
+
if (this.nodeHttpClient === "http2") {
|
|
5288
|
+
return http2.createServer(
|
|
5289
|
+
handler
|
|
5290
|
+
);
|
|
5291
|
+
}
|
|
5292
|
+
if (this.nodeHttpClient === "http2-secure") {
|
|
5293
|
+
if (!this.httpsOptions) {
|
|
5294
|
+
throw new Error(
|
|
5295
|
+
"httpsOptions (key, cert) are required when using http2-secure client"
|
|
5296
|
+
);
|
|
5297
|
+
}
|
|
5298
|
+
return http2.createSecureServer(
|
|
5299
|
+
this.httpsOptions,
|
|
5300
|
+
handler
|
|
5301
|
+
);
|
|
5302
|
+
}
|
|
5303
|
+
if (!this.httpsOptions) {
|
|
5304
|
+
throw new Error(
|
|
5305
|
+
"httpsOptions (key, cert) are required when using https client"
|
|
5306
|
+
);
|
|
5307
|
+
}
|
|
5308
|
+
return https.createServer(this.httpsOptions, handler);
|
|
5309
|
+
}
|
|
5266
5310
|
};
|
|
5267
5311
|
|
|
5268
5312
|
// src/runtime/native_server/server_connector.ts
|
|
@@ -5362,6 +5406,7 @@ var Server = class {
|
|
|
5362
5406
|
controllerImportBlacklistedPaths = ["node_modules"];
|
|
5363
5407
|
notFoundHandler;
|
|
5364
5408
|
nativeEnv = new NativeEnv();
|
|
5409
|
+
httpsOptions;
|
|
5365
5410
|
/**
|
|
5366
5411
|
* The constructor for the server
|
|
5367
5412
|
* @warning Routes will only be defined after calling the `listen` method so you're free to define middlewares before calling it
|
|
@@ -5376,6 +5421,7 @@ var Server = class {
|
|
|
5376
5421
|
constructor(options) {
|
|
5377
5422
|
this.wasInitialized = false;
|
|
5378
5423
|
this.serverOptions = {
|
|
5424
|
+
nodeHttpClient: options?.nodeHttpClient ?? "http",
|
|
5379
5425
|
port: options?.port ?? Number(this.nativeEnv.get("PORT")) ?? 80,
|
|
5380
5426
|
host: options?.host ?? this.nativeEnv.get("HOST") ?? "0.0.0.0",
|
|
5381
5427
|
controllerPatterns: options?.controllerPatterns ?? [],
|
|
@@ -5384,12 +5430,15 @@ var Server = class {
|
|
|
5384
5430
|
swagger: options?.swagger ?? true,
|
|
5385
5431
|
useBodyParser: options?.useBodyParser ?? true
|
|
5386
5432
|
};
|
|
5433
|
+
this.httpsOptions = options?.nodeHttpClient === "https" || options?.nodeHttpClient === "http2-secure" ? options.httpsOptions : void 0;
|
|
5387
5434
|
this.serverConnector = new ServerConnector({
|
|
5388
5435
|
routes: [],
|
|
5389
5436
|
port: this.serverOptions.port,
|
|
5390
5437
|
host: this.serverOptions.host,
|
|
5391
5438
|
tapOptions: this.serverOptions.tapOptions,
|
|
5392
|
-
runtime: runtime.type
|
|
5439
|
+
runtime: runtime.type,
|
|
5440
|
+
nodeHttpClient: this.serverOptions.nodeHttpClient,
|
|
5441
|
+
httpsOptions: this.httpsOptions
|
|
5393
5442
|
});
|
|
5394
5443
|
if (this.serverOptions.useBodyParser) {
|
|
5395
5444
|
this.use(bodyParser());
|
|
@@ -5789,7 +5838,7 @@ var Server = class {
|
|
|
5789
5838
|
allowedMethods.push(method);
|
|
5790
5839
|
}
|
|
5791
5840
|
}
|
|
5792
|
-
if (allowedMethods.length
|
|
5841
|
+
if (allowedMethods.length) {
|
|
5793
5842
|
res.setHeader("Allow", allowedMethods.join(", "));
|
|
5794
5843
|
const methodNotAllowedError = new MethodNotAllowedError(
|
|
5795
5844
|
pathname,
|