hono 3.11.12 → 3.12.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.
Files changed (62) hide show
  1. package/dist/adapter/bun/serve-static.js +1 -1
  2. package/dist/adapter/cloudflare-workers/index.js +1 -1
  3. package/dist/adapter/cloudflare-workers/serve-static-module.js +10 -0
  4. package/dist/adapter/cloudflare-workers/serve-static.js +2 -3
  5. package/dist/adapter/deno/serve-static.js +2 -3
  6. package/dist/cjs/adapter/bun/serve-static.js +1 -1
  7. package/dist/cjs/adapter/cloudflare-workers/index.js +2 -2
  8. package/dist/cjs/adapter/cloudflare-workers/{server-static-module.js → serve-static-module.js} +5 -9
  9. package/dist/cjs/adapter/cloudflare-workers/serve-static.js +2 -3
  10. package/dist/cjs/adapter/deno/serve-static.js +2 -3
  11. package/dist/cjs/client/client.js +3 -0
  12. package/dist/cjs/context.js +7 -5
  13. package/dist/cjs/helper/css/index.js +225 -0
  14. package/dist/cjs/helper/dev/index.js +8 -1
  15. package/dist/cjs/helper/streaming/index.js +11 -39
  16. package/dist/cjs/helper/streaming/sse.js +67 -0
  17. package/dist/cjs/helper/streaming/stream.js +34 -0
  18. package/dist/cjs/helper/streaming/text.js +35 -0
  19. package/dist/cjs/helper.js +1 -0
  20. package/dist/cjs/jsx/components.js +24 -9
  21. package/dist/cjs/jsx/index.js +3 -0
  22. package/dist/cjs/jsx/streaming.js +28 -16
  23. package/dist/cjs/middleware/csrf/index.js +58 -0
  24. package/dist/cjs/utils/html.js +21 -7
  25. package/dist/cjs/utils/stream.js +19 -1
  26. package/dist/client/client.js +3 -0
  27. package/dist/context.js +6 -5
  28. package/dist/helper/css/index.js +197 -0
  29. package/dist/helper/dev/index.js +7 -1
  30. package/dist/helper/streaming/index.js +7 -38
  31. package/dist/helper/streaming/sse.js +43 -0
  32. package/dist/helper/streaming/stream.js +11 -0
  33. package/dist/helper/streaming/text.js +12 -0
  34. package/dist/helper.js +1 -0
  35. package/dist/jsx/components.js +27 -9
  36. package/dist/jsx/index.js +3 -0
  37. package/dist/jsx/streaming.js +28 -16
  38. package/dist/middleware/csrf/index.js +35 -0
  39. package/dist/types/adapter/bun/serve-static.d.ts +4 -3
  40. package/dist/types/adapter/cloudflare-workers/index.d.ts +1 -1
  41. package/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +4 -0
  42. package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +5 -3
  43. package/dist/types/adapter/deno/serve-static.d.ts +4 -3
  44. package/dist/types/client/types.d.ts +7 -1
  45. package/dist/types/context.d.ts +7 -0
  46. package/dist/types/helper/css/index.d.ts +53 -0
  47. package/dist/types/helper/dev/index.d.ts +2 -0
  48. package/dist/types/helper/streaming/index.d.ts +4 -13
  49. package/dist/types/helper/streaming/sse.d.ts +12 -0
  50. package/dist/types/helper/streaming/stream.d.ts +3 -0
  51. package/dist/types/helper/streaming/text.d.ts +3 -0
  52. package/dist/types/hono-base.d.ts +5 -0
  53. package/dist/types/jsx/components.d.ts +1 -1
  54. package/dist/types/jsx/intrinsic-elements.d.ts +1 -1
  55. package/dist/types/middleware/csrf/index.d.ts +8 -0
  56. package/dist/types/utils/html.d.ts +9 -3
  57. package/dist/types/utils/stream.d.ts +4 -1
  58. package/dist/utils/html.js +19 -6
  59. package/dist/utils/stream.js +19 -1
  60. package/package.json +17 -1
  61. package/dist/adapter/cloudflare-workers/server-static-module.js +0 -14
  62. package/dist/types/adapter/cloudflare-workers/server-static-module.d.ts +0 -3
@@ -30,7 +30,7 @@ var serveStatic = (options = { root: "" }) => {
30
30
  return c.body(content);
31
31
  }
32
32
  }
33
- console.warn(`Static file: ${path} is not found`);
33
+ await options.onNotFound?.(path, c);
34
34
  await next();
35
35
  return;
36
36
  };
@@ -1,5 +1,5 @@
1
1
  // src/adapter/cloudflare-workers/index.ts
2
- import { serveStatic } from "./server-static-module.js";
2
+ import { serveStatic } from "./serve-static-module.js";
3
3
  export {
4
4
  serveStatic
5
5
  };
@@ -0,0 +1,10 @@
1
+ // src/adapter/cloudflare-workers/serve-static-module.ts
2
+ import manifest from "__STATIC_CONTENT_MANIFEST";
3
+ import { serveStatic } from "./serve-static.js";
4
+ var module = (options = { root: "" }) => {
5
+ options.manifest ?? (options.manifest = manifest);
6
+ return serveStatic(options);
7
+ };
8
+ export {
9
+ module as serveStatic
10
+ };
@@ -28,10 +28,9 @@ var serveStatic = (options = { root: "" }) => {
28
28
  c.header("Content-Type", mimeType);
29
29
  }
30
30
  return c.body(content);
31
- } else {
32
- console.warn(`Static file: ${path} is not found`);
33
- await next();
34
31
  }
32
+ await options.onNotFound?.(path, c);
33
+ await next();
35
34
  return;
36
35
  };
37
36
  };
@@ -31,10 +31,9 @@ var serveStatic = (options = { root: "" }) => {
31
31
  c.header("Content-Type", mimeType);
32
32
  }
33
33
  return c.body(file.readable);
34
- } else {
35
- console.warn(`Static file: ${path} is not found`);
36
- await next();
37
34
  }
35
+ await options.onNotFound?.(path, c);
36
+ await next();
38
37
  return;
39
38
  };
40
39
  };
@@ -52,7 +52,7 @@ const serveStatic = (options = { root: "" }) => {
52
52
  return c.body(content);
53
53
  }
54
54
  }
55
- console.warn(`Static file: ${path} is not found`);
55
+ await options.onNotFound?.(path, c);
56
56
  await next();
57
57
  return;
58
58
  };
@@ -18,10 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var cloudflare_workers_exports = {};
20
20
  __export(cloudflare_workers_exports, {
21
- serveStatic: () => import_server_static_module.serveStatic
21
+ serveStatic: () => import_serve_static_module.serveStatic
22
22
  });
23
23
  module.exports = __toCommonJS(cloudflare_workers_exports);
24
- var import_server_static_module = require("./server-static-module");
24
+ var import_serve_static_module = require("./serve-static-module");
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
27
  serveStatic
@@ -22,20 +22,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  mod
23
23
  ));
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
- var server_static_module_exports = {};
26
- __export(server_static_module_exports, {
25
+ var serve_static_module_exports = {};
26
+ __export(serve_static_module_exports, {
27
27
  serveStatic: () => module2
28
28
  });
29
- module.exports = __toCommonJS(server_static_module_exports);
29
+ module.exports = __toCommonJS(serve_static_module_exports);
30
30
  var import_STATIC_CONTENT_MANIFEST = __toESM(require("__STATIC_CONTENT_MANIFEST"), 1);
31
31
  var import_serve_static = require("./serve-static");
32
32
  const module2 = (options = { root: "" }) => {
33
- return (0, import_serve_static.serveStatic)({
34
- root: options.root,
35
- path: options.path,
36
- manifest: options.manifest ? options.manifest : import_STATIC_CONTENT_MANIFEST.default,
37
- rewriteRequestPath: options.rewriteRequestPath
38
- });
33
+ options.manifest ?? (options.manifest = import_STATIC_CONTENT_MANIFEST.default);
34
+ return (0, import_serve_static.serveStatic)(options);
39
35
  };
40
36
  // Annotate the CommonJS export names for ESM import in node:
41
37
  0 && (module.exports = {
@@ -50,10 +50,9 @@ const serveStatic = (options = { root: "" }) => {
50
50
  c.header("Content-Type", mimeType);
51
51
  }
52
52
  return c.body(content);
53
- } else {
54
- console.warn(`Static file: ${path} is not found`);
55
- await next();
56
53
  }
54
+ await options.onNotFound?.(path, c);
55
+ await next();
57
56
  return;
58
57
  };
59
58
  };
@@ -53,10 +53,9 @@ const serveStatic = (options = { root: "" }) => {
53
53
  c.header("Content-Type", mimeType);
54
54
  }
55
55
  return c.body(file.readable);
56
- } else {
57
- console.warn(`Static file: ${path} is not found`);
58
- await next();
59
56
  }
57
+ await options.onNotFound?.(path, c);
58
+ await next();
60
59
  return;
61
60
  };
62
61
  };
@@ -131,6 +131,9 @@ const hc = (baseUrl, options) => createProxy((opts) => {
131
131
  const path = parts.join("/");
132
132
  const url = (0, import_utils.mergePath)(baseUrl, path);
133
133
  if (method === "url") {
134
+ if (opts.args[0] && opts.args[0].param) {
135
+ return new URL((0, import_utils.replaceUrlParam)(url, opts.args[0].param));
136
+ }
134
137
  return new URL(url);
135
138
  }
136
139
  const req = new ClientRequestImpl(url, method);
@@ -36,7 +36,8 @@ var __privateSet = (obj, member, value, setter) => {
36
36
  };
37
37
  var context_exports = {};
38
38
  __export(context_exports, {
39
- Context: () => Context
39
+ Context: () => Context,
40
+ TEXT_PLAIN: () => TEXT_PLAIN
40
41
  });
41
42
  module.exports = __toCommonJS(context_exports);
42
43
  var import_cookie = require("./utils/cookie");
@@ -177,7 +178,7 @@ class Context {
177
178
  html = html.toString();
178
179
  }
179
180
  if (html instanceof Promise) {
180
- return html.then((html2) => (0, import_html.resolveStream)(html2)).then((html2) => {
181
+ return html.then((html2) => (0, import_html.resolveCallback)(html2, import_html.HtmlEscapedCallbackPhase.Stringify, false, {})).then((html2) => {
181
182
  return typeof arg === "number" ? this.newResponse(html2, arg, headers) : this.newResponse(html2, arg);
182
183
  });
183
184
  }
@@ -198,9 +199,9 @@ class Context {
198
199
  };
199
200
  this.stream = (cb, arg, headers) => {
200
201
  const { readable, writable } = new TransformStream();
201
- const stream = new import_stream.StreamingApi(writable);
202
+ const stream = new import_stream.StreamingApi(writable, readable);
202
203
  cb(stream).finally(() => stream.close());
203
- return typeof arg === "number" ? this.newResponse(readable, arg, headers) : this.newResponse(readable, arg);
204
+ return typeof arg === "number" ? this.newResponse(stream.responseReadable, arg, headers) : this.newResponse(stream.responseReadable, arg);
204
205
  };
205
206
  this.cookie = (name, value, opt) => {
206
207
  const cookie = (0, import_cookie.serialize)(name, value, opt);
@@ -284,5 +285,6 @@ _res = new WeakMap();
284
285
  _isFresh = new WeakMap();
285
286
  // Annotate the CommonJS export names for ESM import in node:
286
287
  0 && (module.exports = {
287
- Context
288
+ Context,
289
+ TEXT_PLAIN
288
290
  });
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var css_exports = {};
20
+ __export(css_exports, {
21
+ Style: () => Style,
22
+ createCssContext: () => createCssContext,
23
+ css: () => css,
24
+ cx: () => cx,
25
+ keyframes: () => keyframes,
26
+ rawCssString: () => rawCssString
27
+ });
28
+ module.exports = __toCommonJS(css_exports);
29
+ var import_html = require("../../helper/html");
30
+ const IS_CSS_CLASS_NAME = Symbol("IS_CSS_CLASS_NAME");
31
+ const STYLE_STRING = Symbol("STYLE_STRING");
32
+ const SELECTORS = Symbol("SELECTORS");
33
+ const EXTERNAL_CLASS_NAMES = Symbol("EXTERNAL_CLASS_NAMES");
34
+ const rawCssString = (value) => {
35
+ const escapedString = new String(value);
36
+ escapedString.isCssEscaped = true;
37
+ return escapedString;
38
+ };
39
+ const DEFAULT_STYLE_ID = "hono-css";
40
+ const toHash = (str) => {
41
+ let i = 0, out = 11;
42
+ while (i < str.length) {
43
+ out = 101 * out + str.charCodeAt(i++) >>> 0;
44
+ }
45
+ return "css-" + out;
46
+ };
47
+ const cssStringReStr = [
48
+ '"(?:(?:\\\\[\\s\\S]|[^"\\\\])*)"',
49
+ "'(?:(?:\\\\[\\s\\S]|[^'\\\\])*)'"
50
+ ].join("|");
51
+ const minifyCssRe = new RegExp(
52
+ [
53
+ "(" + cssStringReStr + ")",
54
+ "(?:" + [
55
+ "^\\s+",
56
+ "\\/\\*.*?\\*\\/\\s*",
57
+ "\\/\\/.*\\n\\s*",
58
+ "\\s+$"
59
+ ].join("|") + ")",
60
+ ";\\s*(}|$)\\s*",
61
+ "\\s*([{};:,])\\s*",
62
+ "(\\s)\\s+"
63
+ ].join("|"),
64
+ "g"
65
+ );
66
+ const minify = (css2) => {
67
+ return css2.replace(minifyCssRe, (_, $1, $2, $3, $4) => $1 || $2 || $3 || $4 || "");
68
+ };
69
+ const buildStyleString = async (strings, values, selectors, externalClassNames) => {
70
+ let styleString = "";
71
+ for (let i = 0; i < strings.length; i++) {
72
+ styleString += strings[i];
73
+ let vArray = values[i];
74
+ if (typeof vArray === "boolean" || vArray === null || vArray === void 0) {
75
+ continue;
76
+ }
77
+ if (!Array.isArray(vArray)) {
78
+ vArray = [vArray];
79
+ }
80
+ for (let j = 0; j < vArray.length; j++) {
81
+ let value = vArray[j] instanceof Promise ? await vArray[j] : vArray[j];
82
+ if (typeof value === "boolean" || value === null || value === void 0) {
83
+ continue;
84
+ }
85
+ if (typeof value === "number") {
86
+ styleString += value;
87
+ } else if (value.startsWith("@keyframes ")) {
88
+ selectors.push(value);
89
+ styleString += ` ${value.substring(11)} `;
90
+ } else {
91
+ if (value[IS_CSS_CLASS_NAME]) {
92
+ selectors.push(...value[SELECTORS]);
93
+ externalClassNames.push(...value[EXTERNAL_CLASS_NAMES]);
94
+ value = value[STYLE_STRING];
95
+ if (value.length > 0) {
96
+ const lastChar = value[value.length - 1];
97
+ if (lastChar !== ";" && lastChar !== "}") {
98
+ value += ";";
99
+ }
100
+ }
101
+ } else if (!value.isCssEscaped && /([\\"'\/])/.test(value)) {
102
+ value = value.replace(/([\\"']|(?<=<)\/)/g, "\\$1");
103
+ }
104
+ styleString += `${value || ""}`;
105
+ }
106
+ }
107
+ }
108
+ return minify(styleString);
109
+ };
110
+ const createCssContext = ({ id }) => {
111
+ const contextMap = /* @__PURE__ */ new WeakMap();
112
+ const replaceStyleRe = new RegExp(`(<style id="${id}">.*?)(</style>)`);
113
+ const css2 = async (strings, ...values) => {
114
+ const selectors = [];
115
+ const externalClassNames = [];
116
+ const thisStyleString = await buildStyleString(strings, values, selectors, externalClassNames);
117
+ const thisSelector = toHash(thisStyleString);
118
+ const className = new String([thisSelector, ...externalClassNames].join(" "));
119
+ const appendStyle = ({ buffer, context }) => {
120
+ const [toAdd, added] = contextMap.get(context);
121
+ const names = Object.keys(toAdd);
122
+ if (!names.length) {
123
+ return;
124
+ }
125
+ let stylesStr = "";
126
+ names.forEach((className2) => {
127
+ added[className2] = true;
128
+ stylesStr += `${className2[0] === "@" ? "" : "."}${className2}{${toAdd[className2]}}`;
129
+ });
130
+ contextMap.set(context, [{}, added]);
131
+ if (buffer && replaceStyleRe.test(buffer[0])) {
132
+ buffer[0] = buffer[0].replace(replaceStyleRe, (_, pre, post) => `${pre}${stylesStr}${post}`);
133
+ return;
134
+ }
135
+ const appendStyleScript = `<script>document.querySelector('#${id}').textContent+=${JSON.stringify(
136
+ stylesStr
137
+ )}<\/script>`;
138
+ if (buffer) {
139
+ buffer[0] = `${appendStyleScript}${buffer[0]}`;
140
+ return;
141
+ }
142
+ return Promise.resolve(appendStyleScript);
143
+ };
144
+ const addClassNameToContext = ({ context }) => {
145
+ if (!contextMap.get(context)) {
146
+ contextMap.set(context, [{}, {}]);
147
+ }
148
+ const [toAdd, added] = contextMap.get(context);
149
+ let allAdded = true;
150
+ if (!added[thisSelector]) {
151
+ allAdded = false;
152
+ toAdd[thisSelector] = thisStyleString;
153
+ }
154
+ selectors.forEach((className2) => {
155
+ if (!added[`${className2}`]) {
156
+ allAdded = false;
157
+ toAdd[`${className2}`] = className2[STYLE_STRING];
158
+ }
159
+ });
160
+ if (allAdded) {
161
+ return;
162
+ }
163
+ return Promise.resolve((0, import_html.raw)("", [appendStyle]));
164
+ };
165
+ Object.assign(className, {
166
+ isEscaped: true,
167
+ callbacks: [addClassNameToContext],
168
+ [IS_CSS_CLASS_NAME]: true,
169
+ [STYLE_STRING]: thisStyleString,
170
+ [SELECTORS]: selectors,
171
+ [EXTERNAL_CLASS_NAMES]: externalClassNames
172
+ });
173
+ return className;
174
+ };
175
+ const cx2 = async (...args) => {
176
+ const resolvedArgs = await Promise.all(args);
177
+ for (let i = 0; i < resolvedArgs.length; i++) {
178
+ const arg = resolvedArgs[i];
179
+ if (typeof arg === "string" && !arg[IS_CSS_CLASS_NAME]) {
180
+ const externalClassName = new String(arg);
181
+ resolvedArgs[i] = Object.assign(externalClassName, {
182
+ isEscaped: true,
183
+ [IS_CSS_CLASS_NAME]: true,
184
+ [STYLE_STRING]: "",
185
+ [SELECTORS]: [],
186
+ [EXTERNAL_CLASS_NAMES]: [arg]
187
+ });
188
+ }
189
+ }
190
+ return css2(Array(resolvedArgs.length).fill(""), ...resolvedArgs);
191
+ };
192
+ const keyframes2 = async (strings, ...values) => {
193
+ const styleString = await buildStyleString(strings, values, [], []);
194
+ const className = new String(`@keyframes ${toHash(styleString)}`);
195
+ Object.assign(className, {
196
+ isEscaped: true,
197
+ [IS_CSS_CLASS_NAME]: true,
198
+ [STYLE_STRING]: styleString,
199
+ [SELECTORS]: [],
200
+ [EXTERNAL_CLASS_NAMES]: []
201
+ });
202
+ return className;
203
+ };
204
+ const Style2 = () => (0, import_html.raw)(`<style id="${id}"></style>`);
205
+ return {
206
+ css: css2,
207
+ cx: cx2,
208
+ keyframes: keyframes2,
209
+ Style: Style2
210
+ };
211
+ };
212
+ const defaultContext = createCssContext({ id: DEFAULT_STYLE_ID });
213
+ const css = defaultContext.css;
214
+ const cx = defaultContext.cx;
215
+ const keyframes = defaultContext.keyframes;
216
+ const Style = defaultContext.Style;
217
+ // Annotate the CommonJS export names for ESM import in node:
218
+ 0 && (module.exports = {
219
+ Style,
220
+ createCssContext,
221
+ css,
222
+ cx,
223
+ keyframes,
224
+ rawCssString
225
+ });
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var dev_exports = {};
20
20
  __export(dev_exports, {
21
+ getRouterName: () => getRouterName,
21
22
  inspectRoutes: () => inspectRoutes,
22
23
  showRoutes: () => showRoutes
23
24
  });
@@ -59,7 +60,8 @@ const showRoutes = (hono, opts) => {
59
60
  return;
60
61
  }
61
62
  const { method, path, routes } = data;
62
- console.log(`\x1B[32m${method}\x1B[0m ${" ".repeat(maxMethodLength - method.length)} ${path}`);
63
+ const methodStr = opts?.colorize ?? true ? `\x1B[32m${method}\x1B[0m` : method;
64
+ console.log(`${methodStr} ${" ".repeat(maxMethodLength - method.length)} ${path}`);
63
65
  if (!opts?.verbose) {
64
66
  return;
65
67
  }
@@ -68,8 +70,13 @@ const showRoutes = (hono, opts) => {
68
70
  });
69
71
  });
70
72
  };
73
+ const getRouterName = (app) => {
74
+ app.router.match("GET", "/");
75
+ return app.router.name;
76
+ };
71
77
  // Annotate the CommonJS export names for ESM import in node:
72
78
  0 && (module.exports = {
79
+ getRouterName,
73
80
  inspectRoutes,
74
81
  showRoutes
75
82
  });
@@ -18,47 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var streaming_exports = {};
20
20
  __export(streaming_exports, {
21
- streamSSE: () => streamSSE
21
+ SSEStreamingApi: () => import_sse.SSEStreamingApi,
22
+ stream: () => import_stream.stream,
23
+ streamSSE: () => import_sse.streamSSE,
24
+ streamText: () => import_text.streamText
22
25
  });
23
26
  module.exports = __toCommonJS(streaming_exports);
24
- var import_stream = require("../../utils/stream");
25
- class SSEStreamingApi extends import_stream.StreamingApi {
26
- constructor(writable) {
27
- super(writable);
28
- }
29
- async writeSSE(message) {
30
- const data = message.data.split("\n").map((line) => {
31
- return `data: ${line}`;
32
- }).join("\n");
33
- const sseData = [message.event && `event: ${message.event}`, data, message.id && `id: ${message.id}`].filter(Boolean).join("\n") + "\n\n";
34
- await this.write(sseData);
35
- }
36
- }
37
- const setSSEHeaders = (context) => {
38
- context.header("Transfer-Encoding", "chunked");
39
- context.header("Content-Type", "text/event-stream");
40
- context.header("Cache-Control", "no-cache");
41
- context.header("Connection", "keep-alive");
42
- };
43
- const streamSSE = (c, cb) => {
44
- return c.stream(async (originalStream) => {
45
- const { readable, writable } = new TransformStream();
46
- const stream = new SSEStreamingApi(writable);
47
- originalStream.pipe(readable).catch((err) => {
48
- console.error("Error in stream piping: ", err);
49
- stream.close();
50
- });
51
- setSSEHeaders(c);
52
- try {
53
- await cb(stream);
54
- } catch (err) {
55
- console.error("Error during streaming: ", err);
56
- } finally {
57
- await stream.close();
58
- }
59
- });
60
- };
27
+ var import_stream = require("./stream");
28
+ var import_sse = require("./sse");
29
+ var import_text = require("./text");
61
30
  // Annotate the CommonJS export names for ESM import in node:
62
31
  0 && (module.exports = {
63
- streamSSE
32
+ SSEStreamingApi,
33
+ stream,
34
+ streamSSE,
35
+ streamText
64
36
  });
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var sse_exports = {};
20
+ __export(sse_exports, {
21
+ SSEStreamingApi: () => SSEStreamingApi,
22
+ streamSSE: () => streamSSE
23
+ });
24
+ module.exports = __toCommonJS(sse_exports);
25
+ var import_stream = require("../../utils/stream");
26
+ var import__ = require(".");
27
+ class SSEStreamingApi extends import_stream.StreamingApi {
28
+ constructor(writable, readable) {
29
+ super(writable, readable);
30
+ }
31
+ async writeSSE(message) {
32
+ const data = message.data.split("\n").map((line) => {
33
+ return `data: ${line}`;
34
+ }).join("\n");
35
+ const sseData = [message.event && `event: ${message.event}`, data, message.id && `id: ${message.id}`].filter(Boolean).join("\n") + "\n\n";
36
+ await this.write(sseData);
37
+ }
38
+ }
39
+ const setSSEHeaders = (context) => {
40
+ context.header("Transfer-Encoding", "chunked");
41
+ context.header("Content-Type", "text/event-stream");
42
+ context.header("Cache-Control", "no-cache");
43
+ context.header("Connection", "keep-alive");
44
+ };
45
+ const streamSSE = (c, cb) => {
46
+ return (0, import__.stream)(c, async (originalStream) => {
47
+ const { readable, writable } = new TransformStream();
48
+ const stream2 = new SSEStreamingApi(writable, readable);
49
+ originalStream.pipe(stream2.responseReadable).catch((err) => {
50
+ console.error("Error in stream piping: ", err);
51
+ stream2.close();
52
+ });
53
+ setSSEHeaders(c);
54
+ try {
55
+ await cb(stream2);
56
+ } catch (err) {
57
+ console.error("Error during streaming: ", err);
58
+ } finally {
59
+ await stream2.close();
60
+ }
61
+ });
62
+ };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ SSEStreamingApi,
66
+ streamSSE
67
+ });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var stream_exports = {};
20
+ __export(stream_exports, {
21
+ stream: () => stream
22
+ });
23
+ module.exports = __toCommonJS(stream_exports);
24
+ var import_stream = require("../../utils/stream");
25
+ const stream = (c, cb) => {
26
+ const { readable, writable } = new TransformStream();
27
+ const stream2 = new import_stream.StreamingApi(writable, readable);
28
+ cb(stream2).finally(() => stream2.close());
29
+ return c.newResponse(stream2.responseReadable);
30
+ };
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ stream
34
+ });
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var text_exports = {};
20
+ __export(text_exports, {
21
+ streamText: () => streamText
22
+ });
23
+ module.exports = __toCommonJS(text_exports);
24
+ var import_context = require("../../context");
25
+ var import__ = require(".");
26
+ const streamText = (c, cb) => {
27
+ c.header("Content-Type", import_context.TEXT_PLAIN);
28
+ c.header("X-Content-Type-Options", "nosniff");
29
+ c.header("Transfer-Encoding", "chunked");
30
+ return (0, import__.stream)(c, cb);
31
+ };
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ streamText
35
+ });
@@ -17,6 +17,7 @@ var helper_exports = {};
17
17
  module.exports = __toCommonJS(helper_exports);
18
18
  __reExport(helper_exports, require("./helper/adapter"), module.exports);
19
19
  __reExport(helper_exports, require("./helper/cookie"), module.exports);
20
+ __reExport(helper_exports, require("./helper/css"), module.exports);
20
21
  __reExport(helper_exports, require("./helper/factory"), module.exports);
21
22
  __reExport(helper_exports, require("./helper/html"), module.exports);
22
23
  __reExport(helper_exports, require("./helper/streaming"), module.exports);