@mastra/deployer 1.75.0 → 1.76.0-alpha.1

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.
@@ -6,7 +6,7 @@ import { dirname, join } from "path";
6
6
  import { fileURLToPath } from "url";
7
7
  import { Readable, Writable } from "stream";
8
8
  import * as https from "https";
9
- import { STATUS_CODES, createServer } from "http";
9
+ import { STATUS_CODES, ServerResponse, createServer } from "http";
10
10
  import { Http2ServerRequest, constants } from "http2";
11
11
  import { defineWebSocketHelper } from "hono/ws";
12
12
  import process$1, { versions } from "process";
@@ -31,13 +31,161 @@ import "hono/utils/handler";
31
31
  import "hono/validator";
32
32
  import { HTTPException } from "hono/http-exception";
33
33
  //#endregion
34
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@hono/node-server/2.0.10/6be43c83777d669b036e653a8b7e871f80da198738a293161ba1a45b77e87eb5/node_modules/@hono/node-server/dist/index.mjs
34
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@hono/node-server/2.1.3/19d7f8738ee0bdda5c921e6b78e7282a61a457f5cbca86ce0e563f0efa4986d3/node_modules/@hono/node-server/dist/index.mjs
35
35
  var RequestError = class extends Error {
36
36
  constructor(message, options) {
37
37
  super(message, options);
38
38
  this.name = "RequestError";
39
39
  }
40
40
  };
41
+ const nonJoinedHeaders = /* @__PURE__ */ new Set([
42
+ "age",
43
+ "authorization",
44
+ "content-length",
45
+ "content-type",
46
+ "etag",
47
+ "expires",
48
+ "from",
49
+ "host",
50
+ "if-modified-since",
51
+ "if-unmodified-since",
52
+ "last-modified",
53
+ "location",
54
+ "max-forwards",
55
+ "proxy-authorization",
56
+ "referer",
57
+ "retry-after",
58
+ "server",
59
+ "user-agent"
60
+ ]);
61
+ const validHeaderName = /^[!#$%&'*+\-.^_`|~\dA-Za-z]+$/;
62
+ const isHttpWhitespace = (code) => code === 9 || code === 10 || code === 13 || code === 32;
63
+ const normalizeHeaderValue = (value) => {
64
+ if (!isHttpWhitespace(value.charCodeAt(0)) && !isHttpWhitespace(value.charCodeAt(value.length - 1))) return value;
65
+ let start = 0;
66
+ let end = value.length;
67
+ while (start < end && isHttpWhitespace(value.charCodeAt(start))) start++;
68
+ while (end > start && isHttpWhitespace(value.charCodeAt(end - 1))) end--;
69
+ return value.slice(start, end);
70
+ };
71
+ const forbiddenHeaderValue = /[\0\r\n]/;
72
+ const GlobalHeaders = globalThis.Headers;
73
+ const materializeHeaders = (rawHeaders, HeadersCtor = GlobalHeaders) => {
74
+ const headers = new HeadersCtor();
75
+ for (let i = 0; i < rawHeaders.length; i += 2) {
76
+ const name = rawHeaders[i];
77
+ if (!name.startsWith(":")) headers.append(name, rawHeaders[i + 1]);
78
+ }
79
+ return headers;
80
+ };
81
+ var RequestHeaders = class {
82
+ #incoming;
83
+ #rawHeaders;
84
+ #headers;
85
+ #invalidValue;
86
+ constructor(incoming) {
87
+ this.#incoming = incoming;
88
+ if (incoming instanceof Http2ServerRequest) this.#rawHeaders = incoming.rawHeaders.slice();
89
+ }
90
+ get #lazyRawHeaders() {
91
+ return this.#rawHeaders ??= this.#incoming.rawHeaders.slice();
92
+ }
93
+ get #native() {
94
+ if (!this.#headers) {
95
+ this.#headers = materializeHeaders(this.#lazyRawHeaders);
96
+ this.#rawHeaders = void 0;
97
+ }
98
+ return this.#headers;
99
+ }
100
+ #normalizedName(name) {
101
+ if (typeof name !== "string") return;
102
+ if (!validHeaderName.test(name)) throw new TypeError(`Invalid header name: ${name}`);
103
+ return name.toLowerCase();
104
+ }
105
+ #lookupHttp1(lowerName) {
106
+ const headers = this.#incoming instanceof Http2ServerRequest ? void 0 : this.#incoming.headers;
107
+ if (!headers || nonJoinedHeaders.has(lowerName) || lowerName === "set-cookie" || lowerName === "__proto__") return;
108
+ if (!Object.hasOwn(headers, lowerName)) return null;
109
+ const rawValue = headers[lowerName];
110
+ if (typeof rawValue === "string") {
111
+ const value = normalizeHeaderValue(rawValue);
112
+ return forbiddenHeaderValue.test(value) ? void 0 : value;
113
+ }
114
+ }
115
+ #lookup(rawHeaders, lowerName) {
116
+ const separator = lowerName === "cookie" ? "; " : ", ";
117
+ let value = null;
118
+ for (let i = 0; i < rawHeaders.length; i += 2) {
119
+ const rawName = rawHeaders[i];
120
+ if (rawName.length === lowerName.length && rawName.toLowerCase() === lowerName) {
121
+ const rawValue = normalizeHeaderValue(rawHeaders[i + 1]);
122
+ if (forbiddenHeaderValue.test(rawValue)) {
123
+ this.#invalidValue = true;
124
+ return;
125
+ }
126
+ value = value === null ? rawValue : value + separator + rawValue;
127
+ }
128
+ }
129
+ return value;
130
+ }
131
+ append(name, value) {
132
+ this.#native.append(name, value);
133
+ }
134
+ delete(name) {
135
+ this.#native.delete(name);
136
+ }
137
+ get(name) {
138
+ const lowerName = this.#normalizedName(name);
139
+ if (lowerName && !this.#headers && !this.#invalidValue) {
140
+ const http1Value = this.#lookupHttp1(lowerName);
141
+ if (http1Value !== void 0) return http1Value;
142
+ const value = this.#lookup(this.#lazyRawHeaders, lowerName);
143
+ if (value !== void 0) return value;
144
+ }
145
+ return this.#native.get(name);
146
+ }
147
+ has(name) {
148
+ const lowerName = this.#normalizedName(name);
149
+ if (lowerName && !this.#headers && !this.#invalidValue) {
150
+ const http1Value = this.#lookupHttp1(lowerName);
151
+ if (http1Value !== void 0) return http1Value !== null;
152
+ const value = this.#lookup(this.#lazyRawHeaders, lowerName);
153
+ if (value !== void 0) return value !== null;
154
+ }
155
+ return this.#native.has(name);
156
+ }
157
+ set(name, value) {
158
+ this.#native.set(name, value);
159
+ }
160
+ getSetCookie() {
161
+ return this.#native.getSetCookie();
162
+ }
163
+ keys() {
164
+ return this.#native.keys();
165
+ }
166
+ values() {
167
+ return this.#native.values();
168
+ }
169
+ entries() {
170
+ return this.#native.entries();
171
+ }
172
+ forEach(callback, thisArg) {
173
+ this.#native.forEach((value, key) => {
174
+ callback.call(thisArg, value, key, this);
175
+ });
176
+ }
177
+ [Symbol.iterator]() {
178
+ return this.entries();
179
+ }
180
+ };
181
+ Object.defineProperty(RequestHeaders.prototype, Symbol.for("nodejs.util.inspect.custom"), { value: function(depth, options, inspectFn) {
182
+ return `Headers (lightweight) ${inspectFn(Object.fromEntries(this), {
183
+ ...options,
184
+ depth: depth == null ? null : depth - 1
185
+ })}`;
186
+ } });
187
+ Object.setPrototypeOf(RequestHeaders.prototype, GlobalHeaders.prototype);
188
+ const newHeadersFromIncoming = (incoming) => globalThis.Headers === GlobalHeaders ? new RequestHeaders(incoming) : materializeHeaders(incoming.rawHeaders, globalThis.Headers);
41
189
  const reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;
42
190
  const reDotSegment = /\/\.\.?(?:[/?#]|$)/;
43
191
  const reValidHost = /^[a-z0-9._-]+(?::(?:[1-5]\d{3,4}|[6-9]\d{3}))?$/;
@@ -70,15 +218,6 @@ var Request$1 = class extends GlobalRequest {
70
218
  super(input, options);
71
219
  }
72
220
  };
73
- const newHeadersFromIncoming = (incoming) => {
74
- const headerRecord = [];
75
- const rawHeaders = incoming.rawHeaders;
76
- for (let i = 0, len = rawHeaders.length; i < len; i += 2) {
77
- const key = rawHeaders[i];
78
- if (key.charCodeAt(0) !== 58) headerRecord.push([key, rawHeaders[i + 1]]);
79
- }
80
- return new Headers(headerRecord);
81
- };
82
221
  const wrapBodyStream = Symbol("wrapBodyStream");
83
222
  const byteExactEncodings = /* @__PURE__ */ new Set([
84
223
  "latin1",
@@ -213,8 +352,10 @@ const normalizeIncomingMethod = (method) => {
213
352
  case "GET":
214
353
  case "HEAD":
215
354
  case "OPTIONS":
355
+ case "PATCH":
216
356
  case "POST":
217
- case "PUT": return method;
357
+ case "PUT":
358
+ case "QUERY": return method;
218
359
  }
219
360
  const upper = method.toUpperCase();
220
361
  switch (upper) {
@@ -508,16 +649,15 @@ var Response$1 = class Response$1 {
508
649
  constructor(body, init) {
509
650
  let headers;
510
651
  this.#body = body;
511
- if (init instanceof Response$1) {
652
+ if (init instanceof GlobalResponse) {
512
653
  const cachedGlobalResponse = init[responseCache];
513
654
  if (cachedGlobalResponse) {
514
655
  this.#init = cachedGlobalResponse;
515
656
  this[getResponseCache]();
516
657
  return;
517
- } else {
518
- this.#init = init.#init;
519
- headers = new Headers(init.headers);
520
658
  }
659
+ this.#init = init instanceof Response$1 ? init.#init : init;
660
+ headers = new Headers(init.headers);
521
661
  } else this.#init = init;
522
662
  if (body == null || typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) this[cacheKey] = [
523
663
  init?.status || 200,
@@ -693,7 +833,10 @@ const drainIncoming = (incoming) => {
693
833
  const forceClose = () => {
694
834
  cleanup();
695
835
  const socket = incoming.socket;
696
- if (socket && !socket.destroyed) socket.destroySoon();
836
+ if (socket && !socket.destroyed) {
837
+ if (typeof socket.destroySoon === "function") socket.destroySoon();
838
+ else if (typeof socket.destroy === "function") socket.destroy();
839
+ }
697
840
  };
698
841
  const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
699
842
  timer.unref?.();
@@ -732,7 +875,10 @@ const handleResponseError = (e, outgoing) => {
732
875
  if (err.code === "ERR_STREAM_PREMATURE_CLOSE") console.info("The user aborted a request.");
733
876
  else {
734
877
  console.error(e);
735
- if (!outgoing.headersSent) outgoing.writeHead(500, { "Content-Type": "text/plain" });
878
+ if (!outgoing.headersSent) {
879
+ if (outgoing instanceof ServerResponse) outgoing._contentLength = null;
880
+ outgoing.writeHead(500, { "Content-Type": "text/plain" });
881
+ }
736
882
  outgoing.end(`Error: ${err.message}`);
737
883
  outgoing.destroy(err);
738
884
  }
@@ -740,6 +886,21 @@ const handleResponseError = (e, outgoing) => {
740
886
  const flushHeaders = (outgoing) => {
741
887
  if ("flushHeaders" in outgoing && outgoing.writable) outgoing.flushHeaders();
742
888
  };
889
+ const trySetContentLength = (outgoing, status, length) => {
890
+ const http1 = outgoing;
891
+ if (http1._contentLength === null && http1._hasBody && http1.useChunkedEncodingByDefault && !http1._removedContLen && status >= 200 && status !== 204 && status !== 304 && !outgoing.hasHeader("content-length") && !outgoing.hasHeader("transfer-encoding") && !outgoing.hasHeader("trailer")) {
892
+ http1._contentLength = length;
893
+ return true;
894
+ }
895
+ return false;
896
+ };
897
+ const writeDefaultHeaders = (outgoing, status, length) => {
898
+ if (trySetContentLength(outgoing, status, length)) outgoing.writeHead(status, { "Content-Type": defaultContentType });
899
+ else outgoing.writeHead(status, {
900
+ "Content-Type": defaultContentType,
901
+ "Content-Length": length
902
+ });
903
+ };
743
904
  const responseViaCache = async (res, outgoing) => {
744
905
  let [status, body, header] = res[cacheKey];
745
906
  if (!header) {
@@ -747,22 +908,13 @@ const responseViaCache = async (res, outgoing) => {
747
908
  outgoing.writeHead(status);
748
909
  outgoing.end();
749
910
  } else if (typeof body === "string") {
750
- outgoing.writeHead(status, {
751
- "Content-Type": defaultContentType,
752
- "Content-Length": Buffer.byteLength(body)
753
- });
911
+ writeDefaultHeaders(outgoing, status, Buffer.byteLength(body));
754
912
  outgoing.end(body);
755
913
  } else if (body instanceof Uint8Array) {
756
- outgoing.writeHead(status, {
757
- "Content-Type": defaultContentType,
758
- "Content-Length": body.byteLength
759
- });
914
+ writeDefaultHeaders(outgoing, status, body.byteLength);
760
915
  outgoing.end(body);
761
916
  } else if (body instanceof Blob) {
762
- outgoing.writeHead(status, {
763
- "Content-Type": defaultContentType,
764
- "Content-Length": body.size
765
- });
917
+ writeDefaultHeaders(outgoing, status, body.size);
766
918
  outgoing.end(new Uint8Array(await body.arrayBuffer()));
767
919
  } else {
768
920
  outgoing.writeHead(status, { "Content-Type": defaultContentType });
@@ -773,6 +925,8 @@ const responseViaCache = async (res, outgoing) => {
773
925
  return;
774
926
  }
775
927
  let hasContentLength = false;
928
+ let plainHeaders = false;
929
+ let canAutoLength = true;
776
930
  if (header instanceof Headers) {
777
931
  hasContentLength = header.has("content-length");
778
932
  header = buildOutgoingHttpHeaders(header, body === null ? void 0 : defaultContentType);
@@ -780,14 +934,25 @@ const responseViaCache = async (res, outgoing) => {
780
934
  const headerObj = new Headers(header);
781
935
  hasContentLength = headerObj.has("content-length");
782
936
  header = buildOutgoingHttpHeaders(headerObj, body === null ? void 0 : defaultContentType);
783
- } else for (const key in header) if (key.length === 14 && key.toLowerCase() === "content-length") {
784
- hasContentLength = true;
785
- break;
937
+ } else {
938
+ plainHeaders = true;
939
+ for (const key in header) {
940
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
941
+ hasContentLength = true;
942
+ break;
943
+ }
944
+ if (key.length === 17 && key.toLowerCase() === "transfer-encoding" || key.length === 7 && key.toLowerCase() === "trailer") canAutoLength = false;
945
+ }
786
946
  }
787
947
  if (!hasContentLength) {
788
- if (typeof body === "string") header["Content-Length"] = Buffer.byteLength(body);
789
- else if (body instanceof Uint8Array) header["Content-Length"] = body.byteLength;
790
- else if (body instanceof Blob) header["Content-Length"] = body.size;
948
+ let length;
949
+ if (typeof body === "string") length = Buffer.byteLength(body);
950
+ else if (body instanceof Uint8Array) length = body.byteLength;
951
+ else if (body instanceof Blob) length = body.size;
952
+ if (length !== void 0 && (!plainHeaders || !canAutoLength || !trySetContentLength(outgoing, status, length))) {
953
+ if (plainHeaders) header = { ...header };
954
+ header["Content-Length"] = length;
955
+ }
791
956
  }
792
957
  outgoing.writeHead(status, header);
793
958
  if (body == null) outgoing.end();
@@ -1168,7 +1333,7 @@ const serve = (options, listeningListener) => {
1168
1333
  return server;
1169
1334
  };
1170
1335
  //#endregion
1171
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@hono/node-server/2.0.10/6be43c83777d669b036e653a8b7e871f80da198738a293161ba1a45b77e87eb5/node_modules/@hono/node-server/dist/utils/stream.mjs
1336
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@hono/node-server/2.1.3/19d7f8738ee0bdda5c921e6b78e7282a61a457f5cbca86ce0e563f0efa4986d3/node_modules/@hono/node-server/dist/utils/stream.mjs
1172
1337
  const pr54206Applied = () => {
1173
1338
  const [major, minor] = versions.node.split(".").map((component) => parseInt(component));
1174
1339
  return major >= 23 || major === 22 && minor >= 7 || major === 20 && minor >= 18;
@@ -1227,7 +1392,7 @@ const createStreamBody = (stream, useNativeReadableToWeb = useReadableToWeb) =>
1227
1392
  });
1228
1393
  };
1229
1394
  //#endregion
1230
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@hono/node-server/2.0.10/6be43c83777d669b036e653a8b7e871f80da198738a293161ba1a45b77e87eb5/node_modules/@hono/node-server/dist/serve-static.mjs
1395
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@hono/node-server/2.1.3/19d7f8738ee0bdda5c921e6b78e7282a61a457f5cbca86ce0e563f0efa4986d3/node_modules/@hono/node-server/dist/serve-static.mjs
1231
1396
  const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
1232
1397
  const ENCODINGS = {
1233
1398
  br: ".br",
@@ -1300,6 +1465,7 @@ const serveStatic = (options = { root: "" }) => {
1300
1465
  let filename;
1301
1466
  if (optionPath) filename = optionPath;
1302
1467
  else try {
1468
+ if (!options.allowPercentInPath && c.req.path.includes("%")) throw new Error();
1303
1469
  filename = tryDecodeURI(c.req.path);
1304
1470
  if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
1305
1471
  } catch {