@mastra/hono 1.4.19-alpha.1 → 1.4.19-alpha.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @mastra/hono
2
2
 
3
+ ## 1.4.19-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`df1947a`](https://github.com/mastra-ai/mastra/commit/df1947affa40f742067542251fac7ca759492ef4), [`ee59b74`](https://github.com/mastra-ai/mastra/commit/ee59b743ce73ad11784b4d9c6fbba8568edee1c8), [`a97b1a0`](https://github.com/mastra-ai/mastra/commit/a97b1a0abaed83946c3519d1e0f680d0815b8a67)]:
8
+ - @mastra/core@1.37.0-alpha.2
9
+ - @mastra/server@1.37.0-alpha.2
10
+
3
11
  ## 1.4.19-alpha.1
4
12
 
5
13
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -2,211 +2,13 @@
2
2
 
3
3
  var serverAdapter = require('@mastra/server/server-adapter');
4
4
  var fetchToNode = require('fetch-to-node');
5
+ var bodyLimit = require('hono/body-limit');
6
+ var streaming = require('hono/streaming');
5
7
  var requestContext = require('@mastra/core/request-context');
6
8
  var auth = require('@mastra/server/auth');
7
9
  var browserStream = require('@mastra/server/browser-stream');
8
10
 
9
11
  // src/index.ts
10
-
11
- // ../../node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/http-exception.js
12
- var HTTPException = class extends Error {
13
- res;
14
- status;
15
- /**
16
- * Creates an instance of `HTTPException`.
17
- * @param status - HTTP status code for the exception. Defaults to 500.
18
- * @param options - Additional options for the exception.
19
- */
20
- constructor(status = 500, options) {
21
- super(options?.message, { cause: options?.cause });
22
- this.res = options?.res;
23
- this.status = status;
24
- }
25
- /**
26
- * Returns the response object associated with the exception.
27
- * If a response object is not provided, a new response is created with the error message and status code.
28
- * @returns The response object.
29
- */
30
- getResponse() {
31
- if (this.res) {
32
- const newResponse = new Response(this.res.body, {
33
- status: this.status,
34
- headers: this.res.headers
35
- });
36
- return newResponse;
37
- }
38
- return new Response(this.message, {
39
- status: this.status
40
- });
41
- }
42
- };
43
-
44
- // ../../node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/middleware/body-limit/index.js
45
- var ERROR_MESSAGE = "Payload Too Large";
46
- var bodyLimit = (options) => {
47
- const onError = options.onError || (() => {
48
- const res = new Response(ERROR_MESSAGE, {
49
- status: 413
50
- });
51
- throw new HTTPException(413, { res });
52
- });
53
- const maxSize = options.maxSize;
54
- return async function bodyLimit2(c, next) {
55
- if (!c.req.raw.body) {
56
- return next();
57
- }
58
- const hasTransferEncoding = c.req.raw.headers.has("transfer-encoding");
59
- const hasContentLength = c.req.raw.headers.has("content-length");
60
- if (hasContentLength && !hasTransferEncoding) {
61
- const contentLength = parseInt(c.req.raw.headers.get("content-length") || "0", 10);
62
- return contentLength > maxSize ? onError(c) : next();
63
- }
64
- let size = 0;
65
- const chunks = [];
66
- const rawReader = c.req.raw.body.getReader();
67
- for (; ; ) {
68
- const { done, value } = await rawReader.read();
69
- if (done) {
70
- break;
71
- }
72
- size += value.length;
73
- if (size > maxSize) {
74
- return onError(c);
75
- }
76
- chunks.push(value);
77
- }
78
- const requestInit = {
79
- body: new ReadableStream({
80
- start(controller) {
81
- for (const chunk of chunks) {
82
- controller.enqueue(chunk);
83
- }
84
- controller.close();
85
- }
86
- }),
87
- duplex: "half"
88
- };
89
- c.req.raw = new Request(c.req.raw, requestInit);
90
- return next();
91
- };
92
- };
93
-
94
- // ../../node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/utils/stream.js
95
- var StreamingApi = class {
96
- writer;
97
- encoder;
98
- writable;
99
- abortSubscribers = [];
100
- responseReadable;
101
- /**
102
- * Whether the stream has been aborted.
103
- */
104
- aborted = false;
105
- /**
106
- * Whether the stream has been closed normally.
107
- */
108
- closed = false;
109
- constructor(writable, _readable) {
110
- this.writable = writable;
111
- this.writer = writable.getWriter();
112
- this.encoder = new TextEncoder();
113
- const reader = _readable.getReader();
114
- this.abortSubscribers.push(async () => {
115
- await reader.cancel();
116
- });
117
- this.responseReadable = new ReadableStream({
118
- async pull(controller) {
119
- const { done, value } = await reader.read();
120
- done ? controller.close() : controller.enqueue(value);
121
- },
122
- cancel: () => {
123
- this.abort();
124
- }
125
- });
126
- }
127
- async write(input) {
128
- try {
129
- if (typeof input === "string") {
130
- input = this.encoder.encode(input);
131
- }
132
- await this.writer.write(input);
133
- } catch {
134
- }
135
- return this;
136
- }
137
- async writeln(input) {
138
- await this.write(input + "\n");
139
- return this;
140
- }
141
- sleep(ms) {
142
- return new Promise((res) => setTimeout(res, ms));
143
- }
144
- async close() {
145
- try {
146
- await this.writer.close();
147
- } catch {
148
- }
149
- this.closed = true;
150
- }
151
- async pipe(body) {
152
- this.writer.releaseLock();
153
- await body.pipeTo(this.writable, { preventClose: true });
154
- this.writer = this.writable.getWriter();
155
- }
156
- onAbort(listener) {
157
- this.abortSubscribers.push(listener);
158
- }
159
- /**
160
- * Abort the stream.
161
- * You can call this method when stream is aborted by external event.
162
- */
163
- abort() {
164
- if (!this.aborted) {
165
- this.aborted = true;
166
- this.abortSubscribers.forEach((subscriber) => subscriber());
167
- }
168
- }
169
- };
170
-
171
- // ../../node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/helper/streaming/utils.js
172
- var isOldBunVersion = () => {
173
- const version2 = typeof Bun !== "undefined" ? Bun.version : void 0;
174
- if (version2 === void 0) {
175
- return false;
176
- }
177
- const result = version2.startsWith("1.1") || version2.startsWith("1.0") || version2.startsWith("0.");
178
- isOldBunVersion = () => result;
179
- return result;
180
- };
181
-
182
- // ../../node_modules/.pnpm/hono@4.12.18/node_modules/hono/dist/helper/streaming/stream.js
183
- var contextStash = /* @__PURE__ */ new WeakMap();
184
- var stream = (c, cb, onError) => {
185
- const { readable, writable } = new TransformStream();
186
- const stream2 = new StreamingApi(writable, readable);
187
- if (isOldBunVersion()) {
188
- c.req.raw.signal.addEventListener("abort", () => {
189
- if (!stream2.closed) {
190
- stream2.abort();
191
- }
192
- });
193
- }
194
- contextStash.set(stream2.responseReadable, c);
195
- (async () => {
196
- try {
197
- await cb(stream2);
198
- } catch (e) {
199
- if (e === void 0) ; else if (e instanceof Error && onError) {
200
- await onError(e, stream2);
201
- } else {
202
- console.error(e);
203
- }
204
- } finally {
205
- stream2.close();
206
- }
207
- })();
208
- return c.newResponse(stream2.responseReadable);
209
- };
210
12
  // @__NO_SIDE_EFFECTS__
211
13
  function $constructor(name, initializer3, params) {
212
14
  function init(inst, def) {
@@ -632,7 +434,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
632
434
  res.header("Content-Type", "text/plain");
633
435
  }
634
436
  res.header("Transfer-Encoding", "chunked");
635
- return stream(
437
+ return streaming.stream(
636
438
  res,
637
439
  async (stream2) => {
638
440
  const readableStream = result instanceof ReadableStream ? result : result.fullStream;
@@ -804,7 +606,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
804
606
  const middlewares = [];
805
607
  if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {
806
608
  middlewares.push(
807
- bodyLimit({
609
+ bodyLimit.bodyLimit({
808
610
  maxSize,
809
611
  onError: this.bodyLimitOptions.onError
810
612
  })