miqro 6.0.14 → 6.1.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.
Files changed (322) hide show
  1. package/README.md +12 -0
  2. package/build/editor.bundle.js +37 -50409
  3. package/build/esm/src/cluster.js +0 -1
  4. package/build/esm/src/common/arguments.d.ts +12 -0
  5. package/build/esm/src/common/arguments.js +111 -10
  6. package/build/esm/src/common/assets.js +2 -3
  7. package/build/esm/src/common/checksum.js +0 -1
  8. package/build/esm/src/common/constants.js +0 -1
  9. package/build/esm/src/common/content-type.js +0 -1
  10. package/build/esm/src/common/esbuild.js +0 -1
  11. package/build/esm/src/common/exit.js +0 -1
  12. package/build/esm/src/common/fs.js +0 -1
  13. package/build/esm/src/common/help.d.ts +1 -1
  14. package/build/esm/src/common/help.js +4 -1
  15. package/build/esm/src/common/jsx.d.ts +8 -1
  16. package/build/esm/src/common/jsx.js +84 -2
  17. package/build/esm/src/common/paths.d.ts +4 -0
  18. package/build/esm/src/common/paths.js +41 -2
  19. package/build/esm/src/common/watch.js +0 -1
  20. package/build/esm/src/inflate/inflate-sea.js +27 -16
  21. package/build/esm/src/inflate/inflate.js +2 -1
  22. package/build/esm/src/inflate/md.d.ts +1 -0
  23. package/build/esm/src/inflate/md.js +9 -6
  24. package/build/esm/src/inflate/setup-auth.js +0 -1
  25. package/build/esm/src/inflate/setup-cors.js +0 -1
  26. package/build/esm/src/inflate/setup-db.js +0 -1
  27. package/build/esm/src/inflate/setup-error.d.ts +3 -0
  28. package/build/esm/src/inflate/setup-error.js +40 -0
  29. package/build/esm/src/inflate/setup-http.js +13 -4
  30. package/build/esm/src/inflate/setup-log.js +0 -1
  31. package/build/esm/src/inflate/setup-middleware.d.ts +4 -0
  32. package/build/esm/src/inflate/setup-middleware.js +42 -0
  33. package/build/esm/src/inflate/setup-server-config.js +0 -1
  34. package/build/esm/src/inflate/setup-test.js +0 -1
  35. package/build/esm/src/inflate/setup-ws.js +0 -1
  36. package/build/esm/src/inflate/setup.doc.d.ts +4 -0
  37. package/build/esm/src/inflate/setup.doc.js +62 -0
  38. package/build/esm/src/inflate/utils/sea-utils.js +0 -1
  39. package/build/esm/src/lib.js +0 -1
  40. package/build/esm/src/main.js +3 -4
  41. package/build/esm/src/services/app.d.ts +1 -0
  42. package/build/esm/src/services/app.js +18 -2
  43. package/build/esm/src/services/editor.js +0 -1
  44. package/build/esm/src/services/globals.js +0 -1
  45. package/build/esm/src/services/hot-reload.js +0 -1
  46. package/build/esm/src/services/migrations.js +0 -1
  47. package/build/esm/src/services/utils/admin-interface.js +0 -1
  48. package/build/esm/src/services/utils/cache.js +0 -1
  49. package/build/esm/src/services/utils/cluster-cache.js +0 -1
  50. package/build/esm/src/services/utils/cluster-ws.js +0 -1
  51. package/build/esm/src/services/utils/db-manager.js +0 -1
  52. package/build/esm/src/services/utils/get-route.js +0 -1
  53. package/build/esm/src/services/utils/log-transport.js +0 -1
  54. package/build/esm/src/services/utils/log.js +2 -2
  55. package/build/esm/src/services/utils/server-interface.js +0 -1
  56. package/build/esm/src/services/utils/websocketmanager.js +0 -1
  57. package/build/esm/src/types.d.ts +16 -1
  58. package/build/esm/src/types.js +0 -1
  59. package/build/lib.cjs +890 -322
  60. package/package.json +4 -2
  61. package/sea/types.json +1 -1
  62. package/tsconfig.json +1 -1
  63. package/bin/miqro +0 -34
  64. package/build/esm/editor/auth.d.ts +0 -6
  65. package/build/esm/editor/auth.js +0 -42
  66. package/build/esm/editor/auth.js.map +0 -1
  67. package/build/esm/editor/common/admin-interface.d.ts +0 -36
  68. package/build/esm/editor/common/admin-interface.js +0 -45
  69. package/build/esm/editor/common/admin-interface.js.map +0 -1
  70. package/build/esm/editor/common/constants.d.ts +0 -4
  71. package/build/esm/editor/common/constants.js +0 -21
  72. package/build/esm/editor/common/constants.js.map +0 -1
  73. package/build/esm/editor/common/constants.server.d.ts +0 -2
  74. package/build/esm/editor/common/constants.server.js +0 -5
  75. package/build/esm/editor/common/constants.server.js.map +0 -1
  76. package/build/esm/editor/common/editor-index.d.ts +0 -2
  77. package/build/esm/editor/common/editor-index.js +0 -15
  78. package/build/esm/editor/common/editor-index.js.map +0 -1
  79. package/build/esm/editor/common/html-encode.d.ts +0 -1
  80. package/build/esm/editor/common/html-encode.js +0 -15
  81. package/build/esm/editor/common/html-encode.js.map +0 -1
  82. package/build/esm/editor/common/log-socket.d.ts +0 -15
  83. package/build/esm/editor/common/log-socket.js +0 -71
  84. package/build/esm/editor/common/log-socket.js.map +0 -1
  85. package/build/esm/editor/common/templates.d.ts +0 -11
  86. package/build/esm/editor/common/templates.js +0 -444
  87. package/build/esm/editor/common/templates.js.map +0 -1
  88. package/build/esm/editor/components/api-preview.d.ts +0 -11
  89. package/build/esm/editor/components/api-preview.js +0 -91
  90. package/build/esm/editor/components/api-preview.js.map +0 -1
  91. package/build/esm/editor/components/editor.d.ts +0 -16
  92. package/build/esm/editor/components/editor.js +0 -358
  93. package/build/esm/editor/components/editor.js.map +0 -1
  94. package/build/esm/editor/components/file-browser.d.ts +0 -37
  95. package/build/esm/editor/components/file-browser.js +0 -127
  96. package/build/esm/editor/components/file-browser.js.map +0 -1
  97. package/build/esm/editor/components/file-editor-toolbar.d.ts +0 -22
  98. package/build/esm/editor/components/file-editor-toolbar.js +0 -94
  99. package/build/esm/editor/components/file-editor-toolbar.js.map +0 -1
  100. package/build/esm/editor/components/file-editor.d.ts +0 -32
  101. package/build/esm/editor/components/file-editor.js +0 -60
  102. package/build/esm/editor/components/file-editor.js.map +0 -1
  103. package/build/esm/editor/components/filter-query.d.ts +0 -1
  104. package/build/esm/editor/components/filter-query.js +0 -23
  105. package/build/esm/editor/components/filter-query.js.map +0 -1
  106. package/build/esm/editor/components/highlight-text-area.d.ts +0 -11
  107. package/build/esm/editor/components/highlight-text-area.js +0 -139
  108. package/build/esm/editor/components/highlight-text-area.js.map +0 -1
  109. package/build/esm/editor/components/log-viewer.d.ts +0 -6
  110. package/build/esm/editor/components/log-viewer.js +0 -70
  111. package/build/esm/editor/components/log-viewer.js.map +0 -1
  112. package/build/esm/editor/components/new-file.d.ts +0 -10
  113. package/build/esm/editor/components/new-file.js +0 -118
  114. package/build/esm/editor/components/new-file.js.map +0 -1
  115. package/build/esm/editor/components/scroll-query.d.ts +0 -7
  116. package/build/esm/editor/components/scroll-query.js +0 -22
  117. package/build/esm/editor/components/scroll-query.js.map +0 -1
  118. package/build/esm/editor/components/start-page.d.ts +0 -13
  119. package/build/esm/editor/components/start-page.js +0 -31
  120. package/build/esm/editor/components/start-page.js.map +0 -1
  121. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +0 -3
  122. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +0 -30
  123. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js.map +0 -1
  124. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +0 -5
  125. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +0 -50
  126. package/build/esm/editor/http/admin/editor/api/fs/read.api.js.map +0 -1
  127. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +0 -4
  128. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +0 -40
  129. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js.map +0 -1
  130. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +0 -26
  131. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +0 -150
  132. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js.map +0 -1
  133. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +0 -3
  134. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +0 -39
  135. package/build/esm/editor/http/admin/editor/api/fs/write.api.js.map +0 -1
  136. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +0 -10
  137. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +0 -47
  138. package/build/esm/editor/http/admin/editor/api/server/reload.api.js.map +0 -1
  139. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +0 -10
  140. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +0 -46
  141. package/build/esm/editor/http/admin/editor/api/server/restart.api.js.map +0 -1
  142. package/build/esm/editor/http/admin/editor/editor.d.ts +0 -1
  143. package/build/esm/editor/http/admin/editor/editor.js +0 -8
  144. package/build/esm/editor/http/admin/editor/editor.js.map +0 -1
  145. package/build/esm/editor/http/admin/editor/index.api.d.ts +0 -3
  146. package/build/esm/editor/http/admin/editor/index.api.js +0 -22
  147. package/build/esm/editor/http/admin/editor/index.api.js.map +0 -1
  148. package/build/esm/editor/server.d.ts +0 -3
  149. package/build/esm/editor/server.js +0 -50
  150. package/build/esm/editor/server.js.map +0 -1
  151. package/build/esm/editor/ws.d.ts +0 -3
  152. package/build/esm/editor/ws.js +0 -12
  153. package/build/esm/editor/ws.js.map +0 -1
  154. package/build/esm/src/bin/compile.d.ts +0 -3
  155. package/build/esm/src/bin/compile.js +0 -31
  156. package/build/esm/src/bin/compile.js.map +0 -1
  157. package/build/esm/src/bin/doc-md.d.ts +0 -17
  158. package/build/esm/src/bin/doc-md.js +0 -187
  159. package/build/esm/src/bin/doc-md.js.map +0 -1
  160. package/build/esm/src/bin/generate-doc.d.ts +0 -4
  161. package/build/esm/src/bin/generate-doc.js +0 -49
  162. package/build/esm/src/bin/generate-doc.js.map +0 -1
  163. package/build/esm/src/bin/test.d.ts +0 -3
  164. package/build/esm/src/bin/test.js +0 -68
  165. package/build/esm/src/bin/test.js.map +0 -1
  166. package/build/esm/src/bin/types.d.ts +0 -3
  167. package/build/esm/src/bin/types.js +0 -21
  168. package/build/esm/src/bin/types.js.map +0 -1
  169. package/build/esm/src/cluster.js.map +0 -1
  170. package/build/esm/src/common/arguments.js.map +0 -1
  171. package/build/esm/src/common/assets.js.map +0 -1
  172. package/build/esm/src/common/checksum.js.map +0 -1
  173. package/build/esm/src/common/constants.js.map +0 -1
  174. package/build/esm/src/common/content-type.js.map +0 -1
  175. package/build/esm/src/common/esbuild.js.map +0 -1
  176. package/build/esm/src/common/exit.js.map +0 -1
  177. package/build/esm/src/common/fs.js.map +0 -1
  178. package/build/esm/src/common/help.js.map +0 -1
  179. package/build/esm/src/common/jsx.js.map +0 -1
  180. package/build/esm/src/common/paths.js.map +0 -1
  181. package/build/esm/src/common/watch.js.map +0 -1
  182. package/build/esm/src/inflate/inflate-sea.js.map +0 -1
  183. package/build/esm/src/inflate/inflate.js.map +0 -1
  184. package/build/esm/src/inflate/md.js.map +0 -1
  185. package/build/esm/src/inflate/setup-auth.js.map +0 -1
  186. package/build/esm/src/inflate/setup-cors.js.map +0 -1
  187. package/build/esm/src/inflate/setup-db.js.map +0 -1
  188. package/build/esm/src/inflate/setup-http.js.map +0 -1
  189. package/build/esm/src/inflate/setup-log.js.map +0 -1
  190. package/build/esm/src/inflate/setup-server-config.js.map +0 -1
  191. package/build/esm/src/inflate/setup-test.js.map +0 -1
  192. package/build/esm/src/inflate/setup-ws.js.map +0 -1
  193. package/build/esm/src/inflate/utils/sea-utils.js.map +0 -1
  194. package/build/esm/src/lib.js.map +0 -1
  195. package/build/esm/src/main.js.map +0 -1
  196. package/build/esm/src/services/app.js.map +0 -1
  197. package/build/esm/src/services/editor.js.map +0 -1
  198. package/build/esm/src/services/globals.js.map +0 -1
  199. package/build/esm/src/services/hot-reload.js.map +0 -1
  200. package/build/esm/src/services/migrations.js.map +0 -1
  201. package/build/esm/src/services/utils/admin-interface.js.map +0 -1
  202. package/build/esm/src/services/utils/cache.js.map +0 -1
  203. package/build/esm/src/services/utils/cluster-cache.js.map +0 -1
  204. package/build/esm/src/services/utils/cluster-ws.js.map +0 -1
  205. package/build/esm/src/services/utils/db-manager.js.map +0 -1
  206. package/build/esm/src/services/utils/get-route.js.map +0 -1
  207. package/build/esm/src/services/utils/log-transport.js.map +0 -1
  208. package/build/esm/src/services/utils/log.js.map +0 -1
  209. package/build/esm/src/services/utils/server-interface.js.map +0 -1
  210. package/build/esm/src/services/utils/websocketmanager.js.map +0 -1
  211. package/build/esm/src/types.js.map +0 -1
  212. package/editor/auth.ts +0 -51
  213. package/editor/common/admin-interface.ts +0 -84
  214. package/editor/common/constants.server.ts +0 -5
  215. package/editor/common/constants.ts +0 -21
  216. package/editor/common/editor-index.tsx +0 -17
  217. package/editor/common/html-encode.ts +0 -14
  218. package/editor/common/log-socket.tsx +0 -85
  219. package/editor/common/templates.ts +0 -448
  220. package/editor/components/api-preview.tsx +0 -116
  221. package/editor/components/editor.tsx +0 -486
  222. package/editor/components/file-browser.tsx +0 -308
  223. package/editor/components/file-editor-toolbar.tsx +0 -191
  224. package/editor/components/file-editor.tsx +0 -122
  225. package/editor/components/filter-query.tsx +0 -22
  226. package/editor/components/highlight-text-area.tsx +0 -159
  227. package/editor/components/log-viewer.tsx +0 -110
  228. package/editor/components/new-file.tsx +0 -169
  229. package/editor/components/scroll-query.tsx +0 -22
  230. package/editor/components/start-page.tsx +0 -49
  231. package/editor/http/admin/editor/api/fs/delete.api.tsx +0 -32
  232. package/editor/http/admin/editor/api/fs/read.api.tsx +0 -55
  233. package/editor/http/admin/editor/api/fs/rename.api.tsx +0 -41
  234. package/editor/http/admin/editor/api/fs/scan.api.tsx +0 -181
  235. package/editor/http/admin/editor/api/fs/write.api.tsx +0 -41
  236. package/editor/http/admin/editor/api/server/reload.api.ts +0 -53
  237. package/editor/http/admin/editor/api/server/restart.api.tsx +0 -52
  238. package/editor/http/admin/editor/editor.tsx +0 -8
  239. package/editor/http/admin/editor/index.api.tsx +0 -39
  240. package/editor/server.ts +0 -57
  241. package/editor/static/android-chrome-192x192.png +0 -0
  242. package/editor/static/android-chrome-512x512.png +0 -0
  243. package/editor/static/apple-touch-icon.png +0 -0
  244. package/editor/static/editor.bundle.in.mjs +0 -20
  245. package/editor/static/favicon-16x16.png +0 -0
  246. package/editor/static/favicon-32x32.png +0 -0
  247. package/editor/static/favicon.ico +0 -0
  248. package/editor/static/site.webmanifest +0 -19
  249. package/editor/ws.ts +0 -15
  250. package/sea/base64.js +0 -3
  251. package/sea/compile.sh +0 -127
  252. package/sea/copy-types.sh +0 -46
  253. package/sea/editor-assets/editor.bundle.in.mjs +0 -19
  254. package/sea/generate-global-types-asset-json.js +0 -34
  255. package/sea/release-tar.sh +0 -5
  256. package/sea/tsc.sh +0 -1
  257. package/sea/version.tag.js +0 -11
  258. package/src/bin/compile.ts +0 -35
  259. package/src/bin/doc-md.ts +0 -210
  260. package/src/bin/generate-doc.ts +0 -58
  261. package/src/bin/test.ts +0 -92
  262. package/src/bin/types.ts +0 -22
  263. package/src/cluster.ts +0 -27
  264. package/src/common/arguments.ts +0 -382
  265. package/src/common/assets.ts +0 -128
  266. package/src/common/checksum.ts +0 -58
  267. package/src/common/constants.ts +0 -18
  268. package/src/common/content-type.ts +0 -84
  269. package/src/common/esbuild.ts +0 -94
  270. package/src/common/exit.ts +0 -91
  271. package/src/common/fs.ts +0 -17
  272. package/src/common/help.ts +0 -47
  273. package/src/common/jsx.ts +0 -426
  274. package/src/common/paths.ts +0 -117
  275. package/src/common/watch.ts +0 -85
  276. package/src/inflate/inflate-sea.ts +0 -194
  277. package/src/inflate/inflate.ts +0 -96
  278. package/src/inflate/md.ts +0 -20
  279. package/src/inflate/setup-auth.ts +0 -40
  280. package/src/inflate/setup-cors.ts +0 -40
  281. package/src/inflate/setup-db.ts +0 -113
  282. package/src/inflate/setup-http.ts +0 -643
  283. package/src/inflate/setup-log.ts +0 -44
  284. package/src/inflate/setup-server-config.ts +0 -47
  285. package/src/inflate/setup-test.ts +0 -23
  286. package/src/inflate/setup-ws.ts +0 -48
  287. package/src/inflate/utils/sea-utils.ts +0 -14
  288. package/src/lib.ts +0 -19
  289. package/src/main.ts +0 -87
  290. package/src/services/app.ts +0 -640
  291. package/src/services/editor.tsx +0 -101
  292. package/src/services/globals.ts +0 -143
  293. package/src/services/hot-reload.ts +0 -48
  294. package/src/services/migrations.ts +0 -66
  295. package/src/services/utils/admin-interface.ts +0 -37
  296. package/src/services/utils/cache.ts +0 -88
  297. package/src/services/utils/cluster-cache.ts +0 -230
  298. package/src/services/utils/cluster-ws.ts +0 -197
  299. package/src/services/utils/db-manager.ts +0 -92
  300. package/src/services/utils/get-route.ts +0 -70
  301. package/src/services/utils/log-transport.ts +0 -75
  302. package/src/services/utils/log.ts +0 -91
  303. package/src/services/utils/server-interface.ts +0 -172
  304. package/src/services/utils/websocketmanager.ts +0 -149
  305. package/src/types/@esbuild.d.ts +0 -1
  306. package/src/types/@miqro/core.d.ts +0 -2
  307. package/src/types/@miqro/jsx.d.ts +0 -2
  308. package/src/types/@miqro/parser.d.ts +0 -2
  309. package/src/types/@miqro/query.d.ts +0 -2
  310. package/src/types/@miqro/request.d.ts +0 -2
  311. package/src/types/@miqro/test.d.ts +0 -2
  312. package/src/types/@miqro.d.ts +0 -1
  313. package/src/types/@types.d.ts +0 -1
  314. package/src/types/browser.globals.d.ts +0 -9
  315. package/src/types/globals.d.ts +0 -2
  316. package/src/types/jsx.globals.d.ts +0 -37
  317. package/src/types/miqro.d.ts +0 -111
  318. package/src/types/postject.d.ts +0 -1
  319. package/src/types/server.globals.d.ts +0 -72
  320. package/src/types.ts +0 -204
  321. /package/{editor/http/admin/editor → build}/font.ttf +0 -0
  322. /package/{editor/http/admin/editor → build}/style.css +0 -0
@@ -1,643 +0,0 @@
1
- import { Router, newURL, Response, Request, RouterHandlerOptions, Logger, APIRoute, normalizePath } from "@miqro/core";
2
- import { existsSync, mkdirSync, readFile, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
3
- import { dirname, join, relative, resolve as pathResolve } from "node:path";
4
-
5
- import { CONTENT_TYPE_MAP, DEFAULT_CONTENT_TYPE } from "../common/content-type.js";
6
- import { InflateError, importHTMLModule, importAPIRoute, inflateJSX, importJSONModule, JSONModuleValue, jsx2HTML } from "../common/jsx.js";
7
- import { createNodeRuntime } from "@miqro/jsx-node";
8
- import { getHotReloadScript } from "../services/hot-reload.js";
9
- import { RuntimeURL } from "@miqro/jsx";
10
- import { cwd } from "node:process";
11
- import { assertGlobalTampered } from "../services/globals.js";
12
- import { getHTTPRouterPath, getStaticFilesPath } from "../common/paths.js";
13
- import { setupCORS } from "./setup-cors.js";
14
- import { setupAUTH } from "./setup-auth.js";
15
- import { getRoutes } from "../services/utils/get-route.js";
16
- import { describeFilePath } from "../common/fs.js";
17
- import { inflateMD2HTML } from "./md.js";
18
- import { ServerInterface, ServerRequest } from "../types.js";
19
-
20
- export interface RouteFileMap {
21
- [filePath: string]: {
22
- routes: {
23
- path?: string;
24
- method?: string;
25
- options?: RouterHandlerOptions;
26
- inflatePath?: string;
27
- }[];
28
- service: string;
29
- previewMethod: "api" | "html" | null;
30
- }
31
- }
32
-
33
- export interface StaticFileMap {
34
- [filePathKey: string]: {
35
- path: string;
36
- filePath: string;
37
- method: string | null;
38
- inflatePath?: string;
39
- contentType: string;
40
- previewMethod: "html" | null;
41
- body: Buffer;
42
- }
43
- }
44
-
45
- export async function setupHTTPRouter(server: ServerInterface, logger: Logger, hotreload: boolean, servicePath: string, service: string, routeFileMap: RouteFileMap, staticFileMap: StaticFileMap | null, inflateDir: string | undefined | false, inflateSea: boolean, errors: InflateError[]) {
46
- const mainRouter = new Router();
47
- const apiRouterPath = getHTTPRouterPath(servicePath); //resolve(process.cwd(), service, "http");
48
- if (apiRouterPath) {
49
-
50
- await setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
51
-
52
- await setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
53
- logger.trace("setting up http routes from [%s]", service);
54
- const { router: httpRouter } = await createRouterFromDirectory(server, hotreload, service, logger, apiRouterPath, errors, routeFileMap, staticFileMap, inflateDir, inflateSea);
55
-
56
- mainRouter.use(httpRouter);
57
- }
58
-
59
- const staticFilesPath = getStaticFilesPath(servicePath); //resolve(process.cwd(), service, "static");
60
- if (staticFilesPath) {
61
- logger.trace("setting up static file routes from [%s]", service);
62
- const staticRouter = createStaticRouterFromDirectory(service, logger, staticFilesPath, inflateDir, routeFileMap, staticFileMap);
63
- mainRouter.use(staticRouter);
64
- }
65
- return mainRouter;
66
- }
67
-
68
- function createStaticRoute(service: string, logger: Logger, router: Router, dir: string, file: ScannedFile, inflateDir?: string | undefined | false, routeFileMap?: RouteFileMap, staticFileMap?: StaticFileMap) {
69
- logger.trace("creating static route for [%s]", file.filePath);
70
- logger.trace("[%o]", {
71
- file,
72
- dir
73
- });
74
- const contentType = CONTENT_TYPE_MAP[String(file.ext).toLocaleLowerCase()];
75
- const path = join("/", relative(dir, file.filePath));
76
-
77
-
78
- routeFileMap[file.filePath] = {
79
- routes: [{
80
- method: "GET",
81
- path: normalizePath(path)
82
- }],
83
- service,
84
- previewMethod: "html"
85
- };
86
-
87
- if (inflateDir) {
88
- const inflatePath = join(inflateDir, service, "static", path);
89
- mkdirSync(dirname(inflatePath), {
90
- recursive: true
91
- });
92
- logger.log("writing [%s]", relative(cwd(), inflatePath));
93
- const body = readFileSync(file.filePath);
94
- writeFileSync(inflatePath, body);
95
- if (staticFileMap) {
96
- staticFileMap[file.filePath] = {
97
- contentType,
98
- filePath: file.filePath,
99
- previewMethod: "html",
100
- method: "GET",
101
- path: normalizePath(path),
102
- body: Buffer.from(body),
103
- inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
104
- }
105
- }
106
- }
107
-
108
-
109
-
110
- router.use(assertGlobalTampered);
111
- router.get(path, async function (_req, res) {
112
- await new Promise<void>((resolve, reject) => {
113
- try {
114
- readFile(file.filePath, async (err, body) => {
115
- if (err) {
116
- reject(err);
117
- } else {
118
- try {
119
- await res.asyncEnd({
120
- status: 200,
121
- headers: {
122
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
123
- },
124
- body
125
- });
126
- resolve();
127
- } catch (e) {
128
- reject(e);
129
- }
130
- }
131
- })
132
- } catch (e) {
133
- reject(e);
134
- }
135
- });
136
- });
137
- }
138
-
139
- function createStaticRouterFromDirectory(service: string, logger: Logger, dir: string, inflateDir: string | false | undefined, routeFileMap: RouteFileMap | undefined, staticFileMap: StaticFileMap | null): Router {
140
- const router = new Router();
141
- scanFiles(dir).forEach(file => {
142
- createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
143
- });
144
- return router;
145
- }
146
-
147
- async function createRouterFromDirectory(server: ServerInterface, hotreload: boolean, service: string, logger: Logger, dir: string, errors: InflateError[] = [], routeFileMap: RouteFileMap = {}, staticFileMap: StaticFileMap | null = null, inflateDir: string | undefined | false, inflateSea: boolean): Promise<{
148
- router: Router;
149
- errors: InflateError[];
150
- routeFileMap: RouteFileMap;
151
- }> {
152
- const router = new Router();
153
- router.use(assertGlobalTampered);
154
- await Promise.all(scanFiles(dir).map(file => new Promise<void>(async (resolve) => {
155
- try {
156
- switch (file.ext) {
157
- case ".jsx":
158
- case ".js":
159
- case ".ts":
160
- case ".tsx": {
161
- switch (file.subExt) {
162
- case ".test":
163
- return resolve();
164
- case ".ignore":
165
- logger.warn("ignoring [%s]", file.filePath);
166
- return resolve();
167
- case ".api": {
168
-
169
- const module = await importAPIRoute(file.filePath, logger);
170
-
171
- const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName, module);
172
-
173
- routeFileMap[file.filePath] = {
174
- routes,
175
- service,
176
- previewMethod: "api"
177
- };
178
-
179
- const inflatedCode = inflateDir ? await inflateJSX(file.filePath, {
180
- embemedJSX: false,
181
- minify: false,
182
- useExport: true,
183
- logger
184
- }) : "";
185
-
186
- for (const r of routes) {
187
-
188
- /*if (inflateDir && r.inflatePath) {
189
- const rPath = r.inflatePath;
190
- const inflatePath = join(inflateDir, service, "http", rPath + ".api.js");
191
- mkdirSync(dirname(inflatePath), {
192
- recursive: true
193
- });
194
- logger.log("writing [%s]", relative(cwd(), inflatePath));
195
- writeFileSync(inflatePath, inflatedCode);
196
- }*/
197
-
198
- if (inflateDir && r.defaultInflatePath && inflateSea) {
199
- const rPath = r.defaultInflatePath;
200
- const inflatePath = join(inflateDir, service, "http", rPath + ".api.js");
201
- mkdirSync(dirname(inflatePath), {
202
- recursive: true
203
- });
204
- logger.log("writing [%s]", relative(cwd(), inflatePath));
205
- writeFileSync(inflatePath, inflatedCode);
206
- }
207
-
208
-
209
- router.use(assertGlobalTampered);
210
- router.use(module.handler, r.path, r.method as any, r.options);
211
- }
212
- return resolve();
213
- }
214
- case ".json": {
215
- const module = await importJSONModule(file.filePath, logger);
216
- const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".json", module.apiOptions as Partial<APIRoute>);
217
-
218
- routeFileMap[file.filePath] = {
219
- routes,
220
- service,
221
- previewMethod: "html"
222
- };
223
-
224
- for (const r of routes) {
225
-
226
- const contentType = CONTENT_TYPE_MAP[".json"] ? CONTENT_TYPE_MAP[".json"] : DEFAULT_CONTENT_TYPE;
227
-
228
-
229
-
230
- if (inflateDir) {
231
-
232
- if (r.inflatePath) {
233
- //if (r.method === "GET" || r.method === "get") {
234
- const rPath = r.inflatePath;
235
- const inflatePath = join(inflateDir, service, "static", rPath);
236
- mkdirSync(dirname(inflatePath), {
237
- recursive: true
238
- });
239
- if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
240
- logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
241
- continue;
242
- }
243
- const JSON_STATIC = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
244
- //const JSON = await getJSON({ server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, module.default);
245
- logger.log("writing [%s]", relative(cwd(), inflatePath));
246
- writeFileSync(inflatePath, JSON_STATIC);
247
- //}
248
-
249
- if (staticFileMap && inflateSea) {
250
- staticFileMap[file.filePath] = {
251
- contentType,
252
- filePath: file.filePath,
253
- method: r.method,
254
- previewMethod: "html",
255
- path: r.path,
256
- body: Buffer.from(JSON_STATIC),
257
- inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
258
- }
259
- }
260
- }
261
- }
262
-
263
- router.use(assertGlobalTampered);
264
- router.use(async function (req: Request, res: Response) {
265
-
266
- const JSON = await getJSON(req, res, newURL(req.path), module.apiOptions?.basePath, module.default);
267
-
268
- return res.asyncEnd({
269
- status: 200,
270
- headers: {
271
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
272
- },
273
- body: JSON
274
- });
275
- }, r.path, r.method as any, r.options)
276
- }
277
-
278
- return resolve();
279
- }
280
- case ".html": {
281
-
282
- const module = await importHTMLModule(file.filePath, logger);
283
-
284
- const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".html", module.apiOptions as Partial<APIRoute>);
285
-
286
- routeFileMap[file.filePath] = {
287
- routes,
288
- service,
289
- previewMethod: "html"
290
- };
291
-
292
- for (const r of routes) {
293
-
294
- const contentType = CONTENT_TYPE_MAP[".html"] ? CONTENT_TYPE_MAP[".html"] : DEFAULT_CONTENT_TYPE;
295
-
296
- if (inflateDir) {
297
-
298
- if (r.inflatePath) {
299
- //if (r.method === "GET" || r.method === "get") {
300
- const rPath = r.inflatePath;
301
- const inflatePath = join(inflateDir, service, "static", rPath);
302
- mkdirSync(dirname(inflatePath), {
303
- recursive: true
304
- });
305
- if (existsSync(inflatePath) && statSync(inflatePath).isDirectory()) {
306
- logger.trace("ignoring writing over directory [%s] for file [%s]", relative(cwd(), inflatePath), file.filePath);
307
- continue;
308
- }
309
- const toRender = typeof module.default === "function" ? module.default({ server } as ServerRequest, null) : module.default;
310
- const HTML_STATIC = await getHTML(hotreload, { server } as ServerRequest, null, newURL(r.path), module.apiOptions?.basePath, await toRender);
311
-
312
- logger.log("writing [%s]", relative(cwd(), inflatePath));
313
- writeFileSync(inflatePath, HTML_STATIC);
314
- //}
315
-
316
-
317
- if (staticFileMap && inflateSea) {
318
- staticFileMap[file.filePath + r.method + r.path] = {
319
- filePath: file.filePath,
320
- contentType,
321
- method: r.method,
322
- previewMethod: "html",
323
- path: r.path,
324
- body: Buffer.from(HTML_STATIC),
325
- inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
326
- }
327
- }
328
- }
329
- }
330
-
331
- router.use(assertGlobalTampered);
332
- router.use(async function (req: Request, res: Response) {
333
- const toRender = typeof module.default === "function" ? module.default(req, res) : module.default;
334
- const HTML = await getHTML(hotreload, req, res, newURL(req.path), module.apiOptions?.basePath, await toRender);
335
-
336
- return res.asyncEnd({
337
- status: 200,
338
- headers: {
339
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
340
- },
341
- body: HTML
342
- });
343
- }, r.path, r.method as any, r.options)
344
- }
345
- return resolve();
346
- }
347
- case ".min":
348
- case ".js":
349
- default: {
350
- // allow fall-through when extension is .js and .ts because is a static route without embemedJSX
351
- if (file.ext !== ".js" && file.ext !== ".ts") {
352
- const code = await inflateJSX(file.filePath, {
353
- embemedJSX: true,
354
- minify: file.subExt === ".min" ? true : false,
355
- useExport: false,
356
- logger
357
- });
358
- const contentType = CONTENT_TYPE_MAP[".js"];
359
- const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
360
-
361
- routeFileMap[file.filePath] = {
362
- routes: [{
363
- method: "GET",
364
- path
365
- }],
366
- service,
367
- previewMethod: "html"
368
- };
369
-
370
- if (inflateDir) {
371
- const inflatePath = join(inflateDir, service, "static", path);
372
- mkdirSync(dirname(inflatePath), {
373
- recursive: true
374
- });
375
- logger.log("writing [%s]", relative(cwd(), inflatePath));
376
- writeFileSync(inflatePath, code);
377
-
378
-
379
- if (staticFileMap && inflateSea) {
380
- staticFileMap[file.filePath] = {
381
- contentType,
382
- filePath: file.filePath,
383
- method: "GET",
384
- previewMethod: "html",
385
- path,
386
- body: Buffer.from(code),
387
- inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
388
- }
389
- }
390
- }
391
-
392
- router.use(assertGlobalTampered);
393
- router.get(path, async function (req, res) {
394
- return res.asyncEnd({
395
- status: 200,
396
- headers: {
397
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
398
- },
399
- body: code
400
- });
401
- });
402
- return resolve();
403
- }
404
- }
405
- }
406
- }
407
- case ".md": {
408
- switch (file.subExt) {
409
- case ".html": {
410
- const code = await inflateMD2HTML(file.filePath, logger);
411
- const contentType = CONTENT_TYPE_MAP[".html"];
412
- const path = join("/", dirname(relative(dir, file.filePath)), file.name);
413
- routeFileMap[file.filePath] = {
414
- routes: [{
415
- method: "GET",
416
- path
417
- }],
418
- service,
419
- previewMethod: "html"
420
- };
421
-
422
- if (inflateDir) {
423
- const inflatePath = join(inflateDir, service, "static", path);
424
- mkdirSync(dirname(inflatePath), {
425
- recursive: true
426
- });
427
- logger.log("writing [%s]", relative(cwd(), inflatePath));
428
- writeFileSync(inflatePath, code);
429
- if (staticFileMap && inflateSea) {
430
- staticFileMap[file.filePath] = {
431
- contentType,
432
- method: "GET",
433
- filePath: file.filePath,
434
- previewMethod: "html",
435
- path,
436
- body: Buffer.from(code),
437
- inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
438
- }
439
- }
440
- }
441
-
442
- router.use(assertGlobalTampered);
443
- router.get(path, async function (_req, res) {
444
- res.asyncEnd({
445
- status: 200,
446
- headers: {
447
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
448
- },
449
- body: code
450
- });
451
- });
452
- return resolve();
453
- }
454
- }
455
- }
456
- default:
457
- if (file.ext === ".js" || file.ext === ".ts") {
458
- switch (file.subExt) {
459
- case ".ignore": {
460
- logger.warn("ignoring [%s]", file.filePath);
461
- return resolve();
462
- }
463
- case ".bundle":
464
- case ".min": {
465
- const code = await inflateJSX(file.filePath, {
466
- embemedJSX: false,
467
- minify: file.subExt === ".min" ? true : false,
468
- useExport: false,
469
- logger
470
- });
471
- const contentType = CONTENT_TYPE_MAP[".js"];
472
- const path = join("/", dirname(relative(dir, file.filePath)), file.name + ".js");
473
- routeFileMap[file.filePath] = {
474
- routes: [{
475
- method: "GET",
476
- path
477
- }],
478
- service,
479
- previewMethod: "html"
480
- };
481
-
482
- if (inflateDir) {
483
- const inflatePath = join(inflateDir, service, "static", path);
484
- mkdirSync(dirname(inflatePath), {
485
- recursive: true
486
- });
487
- logger.log("writing [%s]", relative(cwd(), inflatePath));
488
- writeFileSync(inflatePath, code);
489
- if (staticFileMap && inflateSea) {
490
- staticFileMap[file.filePath] = {
491
- contentType,
492
- method: "GET",
493
- filePath: file.filePath,
494
- previewMethod: "html",
495
- path,
496
- body: Buffer.from(code),
497
- inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
498
- }
499
- }
500
- }
501
-
502
- router.use(assertGlobalTampered);
503
- router.get(path, async function (_req, res) {
504
- res.asyncEnd({
505
- status: 200,
506
- headers: {
507
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
508
- },
509
- body: code
510
- });
511
- });
512
- return resolve();
513
- }
514
- }
515
- } else if (file.ext === ".bundle") {
516
- switch (file.subExt) {
517
- case ".ignore": {
518
- logger.warn("ignoring [%s]", file.filePath);
519
- return resolve();
520
- }
521
- case ".css": {
522
- const code = readFileSync(file.filePath).toString()
523
- .split("\n")
524
- .filter(c => c)
525
- .filter(c => c.charAt(0) !== "#")
526
- .map(cssPath => readFileSync(pathResolve(dirname(file.filePath), cssPath)).toString())
527
- .join("\n");
528
- const contentType = CONTENT_TYPE_MAP[".css"];
529
- const path = join("/", dirname(relative(dir, file.filePath)), file.name);
530
- routeFileMap[file.filePath] = {
531
- routes: [{
532
- method: "GET",
533
- path
534
- }],
535
- service,
536
- previewMethod: "html"
537
- };
538
-
539
- if (inflateDir) {
540
- const inflatePath = join(inflateDir, service, "static", path);
541
- mkdirSync(dirname(inflatePath), {
542
- recursive: true
543
- });
544
- logger.log("writing [%s]", relative(cwd(), inflatePath));
545
- writeFileSync(inflatePath, code);
546
- if (staticFileMap && inflateSea) {
547
- staticFileMap[file.filePath] = {
548
- contentType,
549
- method: "GET",
550
- filePath: file.filePath,
551
- previewMethod: "html",
552
- path,
553
- body: Buffer.from(code),
554
- inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
555
- }
556
- }
557
- }
558
-
559
- router.use(assertGlobalTampered);
560
- router.get(path, async function (_req, res) {
561
- res.asyncEnd({
562
- status: 200,
563
- headers: {
564
- ["Content-Type"]: contentType ? contentType : DEFAULT_CONTENT_TYPE
565
- },
566
- body: code
567
- });
568
- });
569
- return resolve();
570
- }
571
- }
572
- }
573
- createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
574
- return resolve();
575
-
576
- }
577
- } catch (e) {
578
- logger.error("error with " + file.filePath);
579
- logger.error(e);
580
- errors.push({
581
- filePath: file.filePath,
582
- error: e
583
- });
584
- } finally {
585
- return resolve();
586
- }
587
- })));
588
- router.use(assertGlobalTampered);
589
- return {
590
- routeFileMap,
591
- router,
592
- errors
593
- };
594
- }
595
-
596
- interface ScannedFile {
597
- filePath: string;
598
- ext: string;
599
- fileName: string;
600
- name: string;
601
- subExt: string;
602
- subName: string;
603
- }
604
-
605
- export function scanFiles(path: string, ret: ScannedFile[] = []): ScannedFile[] {
606
- const files = readdirSync(path);
607
- for (const file of files) {
608
- const filePath = pathResolve(path, file);
609
- if (statSync(filePath).isDirectory()) {
610
- scanFiles(filePath, ret);
611
- continue;
612
- } else {
613
- const description = describeFilePath(filePath);
614
- if (description.fileName === ".DS_Store") {
615
- continue;
616
- }
617
- ret.push(description);
618
- }
619
- }
620
- return ret;
621
- }
622
-
623
-
624
-
625
- function getHTML(hotreload: boolean, req: ServerRequest, res: Response | null, url: RuntimeURL, basePath: string | undefined, out: JSX.Element): string {
626
- let HTML = `<!DOCTYPE html>\n${jsx2HTML(out, createNodeRuntime({
627
- url,
628
- basePath
629
- }))}`;
630
-
631
- //console.log("GET_HTML[%s] [%o]", HTML, out);
632
-
633
- if (hotreload) {
634
- HTML += getHotReloadScript()
635
- }
636
- return HTML;
637
- }
638
-
639
- async function getJSON(req: ServerRequest, res: Response | null, url: RuntimeURL, basePath: string | undefined, out: JSONModuleValue | Promise<JSONModuleValue> | ((req: Request | null, res: Response | null) => JSONModuleValue | Promise<JSONModuleValue>)) {
640
-
641
- const toRender = await (typeof out === "function" ? out(req, res) : out);
642
- return JSON.stringify(toRender, undefined, 2);
643
- }
@@ -1,44 +0,0 @@
1
- import { Logger } from "@miqro/core";
2
- import { importLogConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
3
- import { getLogConfigPath } from "../common/paths.js";
4
- import { dirname, relative, resolve } from "node:path";
5
- import { mkdirSync, writeFileSync } from "node:fs";
6
- import { cwd } from "node:process";
7
- import { LogConfig } from "../types.js";
8
-
9
- export interface LogConfigMap {
10
- [service: string]: LogConfig | undefined;
11
- }
12
-
13
- export async function setupLogConfig(logger: Logger, servicePath: string, service: string, logConfigMap: LogConfigMap, inflateDir: string | undefined | false, errors: InflateError[]) {
14
- const logPath = getLogConfigPath(servicePath); // resolve(process.cwd(), service, "server.ts");
15
- if (logPath) {
16
- try {
17
- //logger.debug("setting up server config from [%s]", join(service, basename(serverPath)));
18
-
19
- const logConfig = await importLogConfigModule(logPath, logger);
20
- logConfigMap[service] = logConfig;
21
-
22
- if (inflateDir) {
23
- const inflatePath = resolve(inflateDir, service, "log.js");
24
- mkdirSync(dirname(inflatePath), {
25
- recursive: true
26
- });
27
- logger.log("writing [%s]", relative(cwd(), inflatePath));
28
- writeFileSync(inflatePath, await inflateJSX(logPath, {
29
- embemedJSX: false,
30
- minify: false,
31
- useExport: true,
32
- logger
33
- }));
34
- }
35
- } catch (e) {
36
- errors.push({
37
- filePath: logPath,
38
- error: e
39
- });
40
- logger.error("error with " + logPath);
41
- logger.error(e);
42
- }
43
- }
44
- }