miqro 7.2.6 → 7.2.7

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