@hyperspan/framework 0.1.1 → 0.1.3

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/dist/server.js CHANGED
@@ -1,197 +1,14 @@
1
+ import {
2
+ buildClientCSS,
3
+ buildClientJS
4
+ } from "./assets.js";
5
+
1
6
  // src/server.ts
2
- import { readdir as readdir2 } from "node:fs/promises";
7
+ import { readdir } from "node:fs/promises";
3
8
  import { basename, extname, join } from "node:path";
9
+ import { TmplHtml, html, renderStream, renderAsync, render } from "@hyperspan/html";
4
10
 
5
- // node_modules/@hyperspan/html/dist/html.js
6
- /*!
7
- * escape-html
8
- * Copyright(c) 2012-2013 TJ Holowaychuk
9
- * Copyright(c) 2015 Andreas Lubbe
10
- * Copyright(c) 2015 Tiancheng "Timothy" Gu
11
- * MIT Licensed
12
- */
13
- var matchHtmlRegExp = /["'&<>]/;
14
- function escapeHtml(string) {
15
- const str = "" + string;
16
- const match = matchHtmlRegExp.exec(str);
17
- if (!match) {
18
- return str;
19
- }
20
- let escape;
21
- let html = "";
22
- let index = 0;
23
- let lastIndex = 0;
24
- for (index = match.index;index < str.length; index++) {
25
- switch (str.charCodeAt(index)) {
26
- case 34:
27
- escape = "&quot;";
28
- break;
29
- case 38:
30
- escape = "&amp;";
31
- break;
32
- case 39:
33
- escape = "&#39;";
34
- break;
35
- case 60:
36
- escape = "&lt;";
37
- break;
38
- case 62:
39
- escape = "&gt;";
40
- break;
41
- default:
42
- continue;
43
- }
44
- if (lastIndex !== index) {
45
- html += str.substring(lastIndex, index);
46
- }
47
- lastIndex = index + 1;
48
- html += escape;
49
- }
50
- return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
51
- }
52
-
53
- class TmplHtml {
54
- content = "";
55
- asyncContent;
56
- constructor(props) {
57
- this.content = props.content;
58
- this.asyncContent = props.asyncContent;
59
- }
60
- }
61
- var htmlId = 0;
62
- function html(strings, ...values) {
63
- const asyncContent = [];
64
- let content = "";
65
- for (let i = 0;i < strings.length; i++) {
66
- let value = values[i];
67
- let renderValue;
68
- if (value !== null && value !== undefined) {
69
- let id = `async_loading_${htmlId++}`;
70
- let kind = _typeOf(value);
71
- if (!renderValue) {
72
- renderValue = _renderValue(value, { id, kind, asyncContent }) || "";
73
- }
74
- }
75
- content += strings[i] + (renderValue ? renderValue : "");
76
- }
77
- return new TmplHtml({ content, asyncContent });
78
- }
79
- html.raw = (content) => ({ _kind: "html_safe", content });
80
- function _renderValue(value, opts = {
81
- kind: undefined,
82
- id: undefined,
83
- asyncContent: []
84
- }) {
85
- if (value === null || value === undefined || Number.isNaN(value)) {
86
- return "";
87
- }
88
- const kind = opts.kind || _typeOf(value);
89
- const id = opts.id || "";
90
- switch (kind) {
91
- case "array":
92
- return value.map((v) => _renderValue(v, { id, asyncContent: opts.asyncContent })).join("");
93
- case "object":
94
- if (value instanceof TmplHtml) {
95
- opts.asyncContent.push(...value.asyncContent);
96
- return value.content;
97
- }
98
- if (value?._kind === "html_safe") {
99
- return value?.content || "";
100
- }
101
- if (typeof value.renderAsync === "function") {
102
- opts.asyncContent.push({
103
- id,
104
- promise: value.renderAsync().then((result) => ({
105
- id,
106
- value: result,
107
- asyncContent: opts.asyncContent
108
- }))
109
- });
110
- }
111
- if (typeof value.render === "function") {
112
- return render(_htmlPlaceholder(id, value.render()));
113
- }
114
- return JSON.stringify(value);
115
- case "promise":
116
- opts.asyncContent.push({
117
- id,
118
- promise: value.then((result) => ({
119
- id,
120
- value: result,
121
- asyncContent: opts.asyncContent
122
- }))
123
- });
124
- return render(_htmlPlaceholder(id));
125
- case "generator":
126
- throw new Error("Generators are not supported as a template value at this time. Sorry :(");
127
- }
128
- return escapeHtml(String(value));
129
- }
130
- function _htmlPlaceholder(id, content = "Loading...") {
131
- return html`<!--hs:loading:${id}--><slot id="${id}">${content}</slot><!--/hs:loading:${id}-->`;
132
- }
133
- function render(tmpl) {
134
- return tmpl.content;
135
- }
136
- async function renderAsync(tmpl) {
137
- let { content, asyncContent } = tmpl;
138
- while (asyncContent.length !== 0) {
139
- const resolvedHtml = await Promise.all(asyncContent.map((p) => p.promise));
140
- asyncContent = [];
141
- resolvedHtml.map((obj) => {
142
- const r = new RegExp(`<!--hs:loading:${obj.id}-->(.*?)<!--/hs:loading:${obj.id}-->`);
143
- const found = content.match(r);
144
- if (found) {
145
- content = content.replace(found[0], _renderValue(obj.value, { asyncContent }));
146
- }
147
- });
148
- }
149
- return content;
150
- }
151
- async function* renderStream(tmpl) {
152
- yield render(tmpl);
153
- let asyncContent = tmpl.asyncContent;
154
- while (asyncContent.length > 0) {
155
- const nextContent = await Promise.race(asyncContent.map((p) => p.promise));
156
- asyncContent = asyncContent.filter((p) => p.id !== nextContent.id);
157
- const id = nextContent.id;
158
- const content = _renderValue(nextContent.value, {
159
- asyncContent
160
- });
161
- const script = html`<template id="${id}_content">${html.raw(content)}</template>`;
162
- yield render(script);
163
- }
164
- }
165
- function _typeOf(obj) {
166
- if (obj instanceof Promise)
167
- return "promise";
168
- if (obj instanceof Date)
169
- return "date";
170
- if (obj instanceof String)
171
- return "string";
172
- if (obj instanceof Number)
173
- return "number";
174
- if (obj instanceof Boolean)
175
- return "boolean";
176
- if (obj instanceof Function)
177
- return "function";
178
- if (Array.isArray(obj))
179
- return "array";
180
- if (Number.isNaN(obj))
181
- return "NaN";
182
- if (obj === undefined)
183
- return "undefined";
184
- if (obj === null)
185
- return "null";
186
- if (isGenerator(obj))
187
- return "generator";
188
- return typeof obj;
189
- }
190
- function isGenerator(obj) {
191
- return obj && typeof obj.next == "function" && typeof obj.throw == "function";
192
- }
193
-
194
- // ../../node_modules/isbot/index.mjs
11
+ // node_modules/isbot/index.mjs
195
12
  var fullPattern = " daum[ /]| deusu/| yadirectfetcher|(?:^|[^g])news(?!sapphire)|(?<! (?:channel/|google/))google(?!(app|/google| pixel))|(?<! cu)bots?(?:\\b|_)|(?<!(?:lib))http|(?<![hg]m)score|@[a-z][\\w-]+\\.|\\(\\)|\\.com\\b|\\btime/|\\||^<|^[\\w \\.\\-\\(?:\\):%]+(?:/v?\\d+(?:\\.\\d+)?(?:\\.\\d{1,10})*?)?(?:,|$)|^[^ ]{50,}$|^\\d+\\b|^\\w*search\\b|^\\w+/[\\w\\(\\)]*$|^active|^ad muncher|^amaya|^avsdevicesdk/|^biglotron|^bot|^bw/|^clamav[ /]|^client/|^cobweb/|^custom|^ddg[_-]android|^discourse|^dispatch/\\d|^downcast/|^duckduckgo|^email|^facebook|^getright/|^gozilla/|^hobbit|^hotzonu|^hwcdn/|^igetter/|^jeode/|^jetty/|^jigsaw|^microsoft bits|^movabletype|^mozilla/\\d\\.\\d\\s[\\w\\.-]+$|^mozilla/\\d\\.\\d\\s\\(compatible;?(?:\\s\\w+\\/\\d+\\.\\d+)?\\)$|^navermailapp|^netsurf|^offline|^openai/|^owler|^php|^postman|^python|^rank|^read|^reed|^rest|^rss|^snapchat|^space bison|^svn|^swcd |^taringa|^thumbor/|^track|^w3c|^webbandit/|^webcopier|^wget|^whatsapp|^wordpress|^xenu link sleuth|^yahoo|^yandex|^zdm/\\d|^zoom marketplace/|^{{.*}}$|adscanner/|analyzer|archive|ask jeeves/teoma|audit|bit\\.ly/|bluecoat drtr|browsex|burpcollaborator|capture|catch|check\\b|checker|chrome-lighthouse|chromeframe|classifier|cloudflare|convertify|cookiehubscan|crawl|cypress/|dareboost|datanyze|dejaclick|detect|dmbrowser|download|evc-batch/|exaleadcloudview|feed|firephp|functionize|gomezagent|headless|httrack|hubspot marketing grader|hydra|ibisbrowser|infrawatch|insight|inspect|iplabel|ips-agent|java(?!;)|jsjcw_scanner|library|linkcheck|mail\\.ru/|manager|measure|neustar wpm|node|nutch|offbyone|onetrust|optimize|pageburst|pagespeed|parser|perl|phantomjs|pingdom|powermarks|preview|proxy|ptst[ /]\\d|retriever|rexx;|rigor|rss\\b|scanner\\.|scrape|server|sogou|sparkler/|speedcurve|spider|splash|statuscake|supercleaner|synapse|synthetic|tools|torrent|transcoder|url|validator|virtuoso|wappalyzer|webglance|webkit2png|whatcms/|zgrab";
196
13
  var naivePattern = /bot|crawl|http|lighthouse|scan|search|spider/i;
197
14
  var pattern;
@@ -210,49 +27,7 @@ function isbot(userAgent) {
210
27
  return Boolean(userAgent) && getPattern().test(userAgent);
211
28
  }
212
29
 
213
- // src/clientjs/md5.js
214
- var hex_chr = "0123456789abcdef".split("");
215
-
216
- // src/assets.ts
217
- import { readdir } from "node:fs/promises";
218
- import { resolve } from "node:path";
219
- var IS_PROD = false;
220
- var PWD = import.meta.dir;
221
- var clientJSFiles = new Map;
222
- async function buildClientJS() {
223
- const sourceFile = resolve(PWD, "../", "./hyperspan/clientjs/hyperspan-client.ts");
224
- const output = await Bun.build({
225
- entrypoints: [sourceFile],
226
- outdir: `./public/_hs/js`,
227
- naming: IS_PROD ? "[dir]/[name]-[hash].[ext]" : undefined,
228
- minify: IS_PROD
229
- });
230
- const jsFile = output.outputs[0].path.split("/").reverse()[0];
231
- clientJSFiles.set("_hs", { src: "/_hs/js/" + jsFile });
232
- return jsFile;
233
- }
234
- var clientCSSFiles = new Map;
235
- async function buildClientCSS() {
236
- if (clientCSSFiles.has("_hs")) {
237
- return clientCSSFiles.get("_hs");
238
- }
239
- const cssDir = "./public/_hs/css/";
240
- const cssFiles = await readdir(cssDir);
241
- let foundCSSFile = "";
242
- for (const file of cssFiles) {
243
- if (!file.endsWith(".css")) {
244
- continue;
245
- }
246
- foundCSSFile = file.replace(cssDir, "");
247
- clientCSSFiles.set("_hs", foundCSSFile);
248
- break;
249
- }
250
- if (!foundCSSFile) {
251
- console.log(`Unable to build CSS files from ${cssDir}`);
252
- }
253
- }
254
-
255
- // ../../node_modules/hono/dist/compose.js
30
+ // node_modules/hono/dist/compose.js
256
31
  var compose = (middleware, onError, onNotFound) => {
257
32
  return (context, next) => {
258
33
  let index = -1;
@@ -296,7 +71,7 @@ var compose = (middleware, onError, onNotFound) => {
296
71
  };
297
72
  };
298
73
 
299
- // ../../node_modules/hono/dist/utils/body.js
74
+ // node_modules/hono/dist/utils/body.js
300
75
  var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
301
76
  const { all = false, dot = false } = options;
302
77
  const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
@@ -360,7 +135,7 @@ var handleParsingNestedValues = (form, key, value) => {
360
135
  });
361
136
  };
362
137
 
363
- // ../../node_modules/hono/dist/utils/url.js
138
+ // node_modules/hono/dist/utils/url.js
364
139
  var splitPath = (path) => {
365
140
  const paths = path.split("/");
366
141
  if (paths[0] === "") {
@@ -555,7 +330,7 @@ var getQueryParams = (url, key) => {
555
330
  };
556
331
  var decodeURIComponent_ = decodeURIComponent;
557
332
 
558
- // ../../node_modules/hono/dist/request.js
333
+ // node_modules/hono/dist/request.js
559
334
  var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
560
335
  var HonoRequest = class {
561
336
  raw;
@@ -663,7 +438,7 @@ var HonoRequest = class {
663
438
  }
664
439
  };
665
440
 
666
- // ../../node_modules/hono/dist/utils/html.js
441
+ // node_modules/hono/dist/utils/html.js
667
442
  var HtmlEscapedCallbackPhase = {
668
443
  Stringify: 1,
669
444
  BeforeStream: 2,
@@ -701,7 +476,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
701
476
  }
702
477
  };
703
478
 
704
- // ../../node_modules/hono/dist/context.js
479
+ // node_modules/hono/dist/context.js
705
480
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
706
481
  var setHeaders = (headers, map = {}) => {
707
482
  for (const key of Object.keys(map)) {
@@ -762,30 +537,19 @@ var Context = class {
762
537
  set res(_res) {
763
538
  this.#isFresh = false;
764
539
  if (this.#res && _res) {
765
- try {
766
- for (const [k, v] of this.#res.headers.entries()) {
767
- if (k === "content-type") {
768
- continue;
769
- }
770
- if (k === "set-cookie") {
771
- const cookies = this.#res.headers.getSetCookie();
772
- _res.headers.delete("set-cookie");
773
- for (const cookie of cookies) {
774
- _res.headers.append("set-cookie", cookie);
775
- }
776
- } else {
777
- _res.headers.set(k, v);
778
- }
540
+ _res = new Response(_res.body, _res);
541
+ for (const [k, v] of this.#res.headers.entries()) {
542
+ if (k === "content-type") {
543
+ continue;
779
544
  }
780
- } catch (e) {
781
- if (e instanceof TypeError && e.message.includes("immutable")) {
782
- this.res = new Response(_res.body, {
783
- headers: _res.headers,
784
- status: _res.status
785
- });
786
- return;
545
+ if (k === "set-cookie") {
546
+ const cookies = this.#res.headers.getSetCookie();
547
+ _res.headers.delete("set-cookie");
548
+ for (const cookie of cookies) {
549
+ _res.headers.append("set-cookie", cookie);
550
+ }
787
551
  } else {
788
- throw e;
552
+ _res.headers.set(k, v);
789
553
  }
790
554
  }
791
555
  }
@@ -802,6 +566,9 @@ var Context = class {
802
566
  this.#renderer = renderer;
803
567
  };
804
568
  header = (name, value, options) => {
569
+ if (this.finalized) {
570
+ this.#res = new Response(this.#res.body, this.#res);
571
+ }
805
572
  if (value === undefined) {
806
573
  if (this.#headers) {
807
574
  this.#headers.delete(name);
@@ -929,15 +696,15 @@ var Context = class {
929
696
  this.#preparedHeaders["content-type"] = "application/json";
930
697
  return typeof arg === "number" ? this.#newResponse(body, arg, headers) : this.#newResponse(body, arg);
931
698
  };
932
- html = (html2, arg, headers) => {
699
+ html = (html, arg, headers) => {
933
700
  this.#preparedHeaders ??= {};
934
701
  this.#preparedHeaders["content-type"] = "text/html; charset=UTF-8";
935
- if (typeof html2 === "object") {
936
- return resolveCallback(html2, HtmlEscapedCallbackPhase.Stringify, false, {}).then((html22) => {
937
- return typeof arg === "number" ? this.#newResponse(html22, arg, headers) : this.#newResponse(html22, arg);
702
+ if (typeof html === "object") {
703
+ return resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then((html2) => {
704
+ return typeof arg === "number" ? this.#newResponse(html2, arg, headers) : this.#newResponse(html2, arg);
938
705
  });
939
706
  }
940
- return typeof arg === "number" ? this.#newResponse(html2, arg, headers) : this.#newResponse(html2, arg);
707
+ return typeof arg === "number" ? this.#newResponse(html, arg, headers) : this.#newResponse(html, arg);
941
708
  };
942
709
  redirect = (location, status) => {
943
710
  this.#headers ??= new Headers;
@@ -950,7 +717,7 @@ var Context = class {
950
717
  };
951
718
  };
952
719
 
953
- // ../../node_modules/hono/dist/router.js
720
+ // node_modules/hono/dist/router.js
954
721
  var METHOD_NAME_ALL = "ALL";
955
722
  var METHOD_NAME_ALL_LOWERCASE = "all";
956
723
  var METHODS = ["get", "post", "put", "delete", "options", "patch"];
@@ -958,10 +725,10 @@ var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is
958
725
  var UnsupportedPathError = class extends Error {
959
726
  };
960
727
 
961
- // ../../node_modules/hono/dist/utils/constants.js
728
+ // node_modules/hono/dist/utils/constants.js
962
729
  var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
963
730
 
964
- // ../../node_modules/hono/dist/hono-base.js
731
+ // node_modules/hono/dist/hono-base.js
965
732
  var notFoundHandler = (c) => {
966
733
  return c.text("404 Not Found", 404);
967
734
  };
@@ -1173,7 +940,7 @@ var Hono = class {
1173
940
  };
1174
941
  };
1175
942
 
1176
- // ../../node_modules/hono/dist/router/reg-exp-router/node.js
943
+ // node_modules/hono/dist/router/reg-exp-router/node.js
1177
944
  var LABEL_REG_EXP_STR = "[^/]+";
1178
945
  var ONLY_WILDCARD_REG_EXP_STR = ".*";
1179
946
  var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
@@ -1274,7 +1041,7 @@ var Node = class {
1274
1041
  }
1275
1042
  };
1276
1043
 
1277
- // ../../node_modules/hono/dist/router/reg-exp-router/trie.js
1044
+ // node_modules/hono/dist/router/reg-exp-router/trie.js
1278
1045
  var Trie = class {
1279
1046
  #context = { varIndex: 0 };
1280
1047
  #root = new Node;
@@ -1330,7 +1097,7 @@ var Trie = class {
1330
1097
  }
1331
1098
  };
1332
1099
 
1333
- // ../../node_modules/hono/dist/router/reg-exp-router/router.js
1100
+ // node_modules/hono/dist/router/reg-exp-router/router.js
1334
1101
  var emptyParam = [];
1335
1102
  var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
1336
1103
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
@@ -1512,7 +1279,7 @@ var RegExpRouter = class {
1512
1279
  }
1513
1280
  };
1514
1281
 
1515
- // ../../node_modules/hono/dist/router/smart-router/router.js
1282
+ // node_modules/hono/dist/router/smart-router/router.js
1516
1283
  var SmartRouter = class {
1517
1284
  name = "SmartRouter";
1518
1285
  #routers = [];
@@ -1567,7 +1334,7 @@ var SmartRouter = class {
1567
1334
  }
1568
1335
  };
1569
1336
 
1570
- // ../../node_modules/hono/dist/router/trie-router/node.js
1337
+ // node_modules/hono/dist/router/trie-router/node.js
1571
1338
  var emptyParams = /* @__PURE__ */ Object.create(null);
1572
1339
  var Node2 = class {
1573
1340
  #methods;
@@ -1723,7 +1490,7 @@ var Node2 = class {
1723
1490
  }
1724
1491
  };
1725
1492
 
1726
- // ../../node_modules/hono/dist/router/trie-router/router.js
1493
+ // node_modules/hono/dist/router/trie-router/router.js
1727
1494
  var TrieRouter = class {
1728
1495
  name = "TrieRouter";
1729
1496
  #node;
@@ -1745,7 +1512,7 @@ var TrieRouter = class {
1745
1512
  }
1746
1513
  };
1747
1514
 
1748
- // ../../node_modules/hono/dist/hono.js
1515
+ // node_modules/hono/dist/hono.js
1749
1516
  var Hono2 = class extends Hono {
1750
1517
  constructor(options = {}) {
1751
1518
  super(options);
@@ -1755,13 +1522,13 @@ var Hono2 = class extends Hono {
1755
1522
  }
1756
1523
  };
1757
1524
 
1758
- // ../../node_modules/hono/dist/adapter/bun/serve-static.js
1525
+ // node_modules/hono/dist/adapter/bun/serve-static.js
1759
1526
  import { stat } from "node:fs/promises";
1760
1527
 
1761
- // ../../node_modules/hono/dist/utils/compress.js
1528
+ // node_modules/hono/dist/utils/compress.js
1762
1529
  var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\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;
1763
1530
 
1764
- // ../../node_modules/hono/dist/utils/filepath.js
1531
+ // node_modules/hono/dist/utils/filepath.js
1765
1532
  var getFilePath = (options) => {
1766
1533
  let filename = options.filename;
1767
1534
  const defaultDocument = options.defaultDocument || "index.html";
@@ -1793,7 +1560,7 @@ var getFilePathWithoutDefaultDocument = (options) => {
1793
1560
  return path;
1794
1561
  };
1795
1562
 
1796
- // ../../node_modules/hono/dist/utils/mime.js
1563
+ // node_modules/hono/dist/utils/mime.js
1797
1564
  var getMimeType = (filename, mimes = baseMimes) => {
1798
1565
  const regexp = /\.([a-zA-Z0-9]+?)$/;
1799
1566
  const match = filename.match(regexp);
@@ -1865,7 +1632,7 @@ var _baseMimes = {
1865
1632
  };
1866
1633
  var baseMimes = _baseMimes;
1867
1634
 
1868
- // ../../node_modules/hono/dist/middleware/serve-static/index.js
1635
+ // node_modules/hono/dist/middleware/serve-static/index.js
1869
1636
  var ENCODINGS = {
1870
1637
  br: ".br",
1871
1638
  zstd: ".zst",
@@ -1962,7 +1729,7 @@ var serveStatic = (options) => {
1962
1729
  };
1963
1730
  };
1964
1731
 
1965
- // ../../node_modules/hono/dist/adapter/bun/serve-static.js
1732
+ // node_modules/hono/dist/adapter/bun/serve-static.js
1966
1733
  var serveStatic2 = (options) => {
1967
1734
  return async function serveStatic2(c, next) {
1968
1735
  const getContent = async (path) => {
@@ -1990,7 +1757,7 @@ var serveStatic2 = (options) => {
1990
1757
  };
1991
1758
  };
1992
1759
 
1993
- // ../../node_modules/hono/dist/helper/ssg/middleware.js
1760
+ // node_modules/hono/dist/helper/ssg/middleware.js
1994
1761
  var X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
1995
1762
  var SSG_DISABLED_RESPONSE = (() => {
1996
1763
  try {
@@ -2002,10 +1769,10 @@ var SSG_DISABLED_RESPONSE = (() => {
2002
1769
  return null;
2003
1770
  }
2004
1771
  })();
2005
- // ../../node_modules/hono/dist/adapter/bun/ssg.js
1772
+ // node_modules/hono/dist/adapter/bun/ssg.js
2006
1773
  var { write } = Bun;
2007
1774
 
2008
- // ../../node_modules/hono/dist/helper/websocket/index.js
1775
+ // node_modules/hono/dist/helper/websocket/index.js
2009
1776
  var WSContext = class {
2010
1777
  #init;
2011
1778
  constructor(init) {
@@ -2029,7 +1796,7 @@ var WSContext = class {
2029
1796
  }
2030
1797
  };
2031
1798
 
2032
- // ../../node_modules/@zod/core/dist/esm/core.js
1799
+ // node_modules/@zod/core/dist/esm/core.js
2033
1800
  var $brand = Symbol("zod_brand");
2034
1801
 
2035
1802
  class $ZodAsyncError extends Error {
@@ -2044,7 +1811,7 @@ function config(config2) {
2044
1811
  return globalConfig;
2045
1812
  }
2046
1813
 
2047
- // ../../node_modules/@zod/core/dist/esm/util.js
1814
+ // node_modules/@zod/core/dist/esm/util.js
2048
1815
  function jsonStringifyReplacer(_, value) {
2049
1816
  if (typeof value === "bigint")
2050
1817
  return value.toString();
@@ -2097,7 +1864,7 @@ function finalizeIssue(iss, ctx, config2) {
2097
1864
  return full;
2098
1865
  }
2099
1866
 
2100
- // ../../node_modules/@zod/core/dist/esm/errors.js
1867
+ // node_modules/@zod/core/dist/esm/errors.js
2101
1868
  var ZOD_ERROR = Symbol.for("{{zod.error}}");
2102
1869
 
2103
1870
  class $ZodError {
@@ -2163,7 +1930,7 @@ function formatError(error, _mapper) {
2163
1930
  return fieldErrors;
2164
1931
  }
2165
1932
 
2166
- // ../../node_modules/@zod/core/dist/esm/parse.js
1933
+ // node_modules/@zod/core/dist/esm/parse.js
2167
1934
  function _parse(schema, value, _ctx) {
2168
1935
  const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
2169
1936
  const result = schema._zod.run({ value, issues: [] }, ctx);
@@ -2176,7 +1943,7 @@ function _parse(schema, value, _ctx) {
2176
1943
  return result.value;
2177
1944
  }
2178
1945
 
2179
- // ../../node_modules/zod/dist/esm/errors.js
1946
+ // node_modules/zod/dist/esm/errors.js
2180
1947
  class ZodError extends $ZodError {
2181
1948
  format(mapper) {
2182
1949
  return formatError(this, mapper);
@@ -2195,11 +1962,11 @@ class ZodError extends $ZodError {
2195
1962
  }
2196
1963
  }
2197
1964
 
2198
- // ../../node_modules/zod/dist/esm/parse.js
1965
+ // node_modules/zod/dist/esm/parse.js
2199
1966
  var parse = /* @__PURE__ */ _parse.bind({ Error: ZodError });
2200
1967
 
2201
1968
  // src/server.ts
2202
- var IS_PROD2 = false;
1969
+ var IS_PROD = false;
2203
1970
  var CWD = process.cwd();
2204
1971
  function createRoute(handler) {
2205
1972
  return new HSRoute(handler);
@@ -2313,7 +2080,8 @@ async function runFileRoute(RouteModule, context) {
2313
2080
  if (routeContent instanceof Response) {
2314
2081
  return routeContent;
2315
2082
  }
2316
- if (routeContent instanceof TmplHtml) {
2083
+ let routeKind = typeof routeContent;
2084
+ if (routeKind === "object" && (routeContent instanceof TmplHtml || routeContent.constructor.name === "TmplHtml" || routeContent?._kind === "TmplHtml")) {
2317
2085
  if (streamingEnabled) {
2318
2086
  return new StreamResponse(renderStream(routeContent));
2319
2087
  } else {
@@ -2321,6 +2089,7 @@ async function runFileRoute(RouteModule, context) {
2321
2089
  return context.html(output);
2322
2090
  }
2323
2091
  }
2092
+ console.log("Returning unknown type... ", routeContent);
2324
2093
  return routeContent;
2325
2094
  } catch (e) {
2326
2095
  console.error(e);
@@ -2337,7 +2106,7 @@ async function runAPIRoute(routeFn, context, middlewareResult) {
2337
2106
  meta: { success: false },
2338
2107
  data: {
2339
2108
  message: e.message,
2340
- stack: IS_PROD2 ? undefined : e.stack?.split(`
2109
+ stack: IS_PROD ? undefined : e.stack?.split(`
2341
2110
  `)
2342
2111
  }
2343
2112
  }, { status: 500 });
@@ -2348,7 +2117,7 @@ async function showErrorReponse(context, err) {
2348
2117
  <main>
2349
2118
  <h1>Error</h1>
2350
2119
  <pre>${err.message}</pre>
2351
- <pre>${!IS_PROD2 && err.stack ? err.stack.split(`
2120
+ <pre>${!IS_PROD && err.stack ? err.stack.split(`
2352
2121
  `).slice(1).join(`
2353
2122
  `) : ""}</pre>
2354
2123
  </main>
@@ -2361,7 +2130,7 @@ var ROUTE_SEGMENT = /(\[[a-zA-Z_\.]+\])/g;
2361
2130
  async function buildRoutes(config2) {
2362
2131
  const routesDir = join(config2.appDir, "routes");
2363
2132
  console.log(routesDir);
2364
- const files = await readdir2(routesDir, { recursive: true });
2133
+ const files = await readdir(routesDir, { recursive: true });
2365
2134
  const routes = [];
2366
2135
  for (const file of files) {
2367
2136
  if (!file.includes(".") || basename(file).startsWith(".")) {
@@ -2419,7 +2188,7 @@ async function createServer(config2) {
2419
2188
  return context.text("No routes found. Add routes to app/routes. Example: `app/routes/index.ts`", { status: 404 });
2420
2189
  });
2421
2190
  }
2422
- if (!IS_PROD2) {
2191
+ if (!IS_PROD) {
2423
2192
  console.log("[Hyperspan] File system routes (in app/routes):");
2424
2193
  console.table(routeMap);
2425
2194
  }
@@ -2476,7 +2245,7 @@ export {
2476
2245
  createComponent,
2477
2246
  buildRoutes,
2478
2247
  StreamResponse,
2479
- IS_PROD2 as IS_PROD,
2248
+ IS_PROD,
2480
2249
  HS_DEFAULT_LOADING,
2481
2250
  HSRoute,
2482
2251
  HSFormRoute,
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@hyperspan/framework",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Hyperspan Web Framework",
5
- "main": "dist/index.js",
5
+ "main": "dist/server.js",
6
6
  "public": true,
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
10
10
  "exports": {
11
11
  ".": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/index.js"
12
+ "types": "./dist/server.d.ts",
13
+ "default": "./dist/server.js"
14
+ },
15
+ "./server": {
16
+ "types": "./dist/server.d.ts",
17
+ "default": "./dist/server.js"
14
18
  },
15
19
  "./assets": {
16
20
  "types": "./dist/assets.d.ts",
@@ -38,10 +42,10 @@
38
42
  "url": "https://github.com/vlucas/hyperspan/issues"
39
43
  },
40
44
  "scripts": {
41
- "build": "bun ./build.ts",
45
+ "build": "bun ./build.ts && sed -i '' -e '$ d' dist/assets.js",
42
46
  "clean": "rm -rf dist",
43
47
  "test": "bun test",
44
- "prepack": "npm run clean && npm run build"
48
+ "prepack": "bun run clean && bun run build"
45
49
  },
46
50
  "devDependencies": {
47
51
  "@types/bun": "^1.1.9",
@@ -55,7 +59,7 @@
55
59
  "typescript": "^5.0.0"
56
60
  },
57
61
  "dependencies": {
58
- "@hyperspan/html": "^0.1.1",
62
+ "@hyperspan/html": "^0.1.2",
59
63
  "@preact/compat": "^18.3.1",
60
64
  "hono": "^4.7.4",
61
65
  "isbot": "^5.1.25",