miqro 6.0.14 → 6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (318) hide show
  1. package/README.md +12 -0
  2. package/build/editor.bundle.js +37 -50409
  3. package/build/esm/src/bin/compile.js +0 -1
  4. package/build/esm/src/bin/doc-md.js +0 -1
  5. package/build/esm/src/bin/generate-doc.d.ts +3 -1
  6. package/build/esm/src/bin/generate-doc.js +16 -12
  7. package/build/esm/src/bin/test.js +0 -1
  8. package/build/esm/src/bin/types.js +0 -1
  9. package/build/esm/src/cluster.js +0 -1
  10. package/build/esm/src/common/arguments.d.ts +12 -0
  11. package/build/esm/src/common/arguments.js +111 -10
  12. package/build/esm/src/common/assets.js +2 -3
  13. package/build/esm/src/common/checksum.js +0 -1
  14. package/build/esm/src/common/constants.js +0 -1
  15. package/build/esm/src/common/content-type.js +0 -1
  16. package/build/esm/src/common/esbuild.js +0 -1
  17. package/build/esm/src/common/exit.js +0 -1
  18. package/build/esm/src/common/fs.js +0 -1
  19. package/build/esm/src/common/help.d.ts +1 -1
  20. package/build/esm/src/common/help.js +4 -1
  21. package/build/esm/src/common/jsx.d.ts +8 -1
  22. package/build/esm/src/common/jsx.js +84 -2
  23. package/build/esm/src/common/paths.d.ts +4 -0
  24. package/build/esm/src/common/paths.js +41 -2
  25. package/build/esm/src/common/watch.js +0 -1
  26. package/build/esm/src/inflate/inflate-sea.js +27 -16
  27. package/build/esm/src/inflate/inflate.js +2 -1
  28. package/build/esm/src/inflate/md.d.ts +1 -0
  29. package/build/esm/src/inflate/md.js +9 -6
  30. package/build/esm/src/inflate/setup-auth.js +0 -1
  31. package/build/esm/src/inflate/setup-cors.js +0 -1
  32. package/build/esm/src/inflate/setup-db.js +0 -1
  33. package/build/esm/src/inflate/setup-error.d.ts +3 -0
  34. package/build/esm/src/inflate/setup-error.js +40 -0
  35. package/build/esm/src/inflate/setup-http.js +13 -4
  36. package/build/esm/src/inflate/setup-log.js +0 -1
  37. package/build/esm/src/inflate/setup-middleware.d.ts +4 -0
  38. package/build/esm/src/inflate/setup-middleware.js +42 -0
  39. package/build/esm/src/inflate/setup-server-config.js +0 -1
  40. package/build/esm/src/inflate/setup-test.js +0 -1
  41. package/build/esm/src/inflate/setup-ws.js +0 -1
  42. package/build/esm/src/inflate/setup.doc.d.ts +4 -0
  43. package/build/esm/src/inflate/setup.doc.js +62 -0
  44. package/build/esm/src/inflate/utils/sea-utils.js +0 -1
  45. package/build/esm/src/lib.js +0 -1
  46. package/build/esm/src/main.js +3 -4
  47. package/build/esm/src/services/app.d.ts +1 -0
  48. package/build/esm/src/services/app.js +18 -2
  49. package/build/esm/src/services/editor.js +0 -1
  50. package/build/esm/src/services/globals.js +0 -1
  51. package/build/esm/src/services/hot-reload.js +0 -1
  52. package/build/esm/src/services/migrations.js +0 -1
  53. package/build/esm/src/services/utils/admin-interface.js +0 -1
  54. package/build/esm/src/services/utils/cache.js +0 -1
  55. package/build/esm/src/services/utils/cluster-cache.js +0 -1
  56. package/build/esm/src/services/utils/cluster-ws.js +0 -1
  57. package/build/esm/src/services/utils/db-manager.js +0 -1
  58. package/build/esm/src/services/utils/get-route.js +0 -1
  59. package/build/esm/src/services/utils/log-transport.js +0 -1
  60. package/build/esm/src/services/utils/log.js +2 -2
  61. package/build/esm/src/services/utils/server-interface.js +0 -1
  62. package/build/esm/src/services/utils/websocketmanager.js +0 -1
  63. package/build/esm/src/types.d.ts +16 -1
  64. package/build/esm/src/types.js +0 -1
  65. package/build/lib.cjs +890 -322
  66. package/package.json +4 -2
  67. package/sea/types.json +1 -1
  68. package/tsconfig.json +1 -1
  69. package/bin/miqro +0 -34
  70. package/build/esm/editor/auth.d.ts +0 -6
  71. package/build/esm/editor/auth.js +0 -42
  72. package/build/esm/editor/auth.js.map +0 -1
  73. package/build/esm/editor/common/admin-interface.d.ts +0 -36
  74. package/build/esm/editor/common/admin-interface.js +0 -45
  75. package/build/esm/editor/common/admin-interface.js.map +0 -1
  76. package/build/esm/editor/common/constants.d.ts +0 -4
  77. package/build/esm/editor/common/constants.js +0 -21
  78. package/build/esm/editor/common/constants.js.map +0 -1
  79. package/build/esm/editor/common/constants.server.d.ts +0 -2
  80. package/build/esm/editor/common/constants.server.js +0 -5
  81. package/build/esm/editor/common/constants.server.js.map +0 -1
  82. package/build/esm/editor/common/editor-index.d.ts +0 -2
  83. package/build/esm/editor/common/editor-index.js +0 -15
  84. package/build/esm/editor/common/editor-index.js.map +0 -1
  85. package/build/esm/editor/common/html-encode.d.ts +0 -1
  86. package/build/esm/editor/common/html-encode.js +0 -15
  87. package/build/esm/editor/common/html-encode.js.map +0 -1
  88. package/build/esm/editor/common/log-socket.d.ts +0 -15
  89. package/build/esm/editor/common/log-socket.js +0 -71
  90. package/build/esm/editor/common/log-socket.js.map +0 -1
  91. package/build/esm/editor/common/templates.d.ts +0 -11
  92. package/build/esm/editor/common/templates.js +0 -444
  93. package/build/esm/editor/common/templates.js.map +0 -1
  94. package/build/esm/editor/components/api-preview.d.ts +0 -11
  95. package/build/esm/editor/components/api-preview.js +0 -91
  96. package/build/esm/editor/components/api-preview.js.map +0 -1
  97. package/build/esm/editor/components/editor.d.ts +0 -16
  98. package/build/esm/editor/components/editor.js +0 -358
  99. package/build/esm/editor/components/editor.js.map +0 -1
  100. package/build/esm/editor/components/file-browser.d.ts +0 -37
  101. package/build/esm/editor/components/file-browser.js +0 -127
  102. package/build/esm/editor/components/file-browser.js.map +0 -1
  103. package/build/esm/editor/components/file-editor-toolbar.d.ts +0 -22
  104. package/build/esm/editor/components/file-editor-toolbar.js +0 -94
  105. package/build/esm/editor/components/file-editor-toolbar.js.map +0 -1
  106. package/build/esm/editor/components/file-editor.d.ts +0 -32
  107. package/build/esm/editor/components/file-editor.js +0 -60
  108. package/build/esm/editor/components/file-editor.js.map +0 -1
  109. package/build/esm/editor/components/filter-query.d.ts +0 -1
  110. package/build/esm/editor/components/filter-query.js +0 -23
  111. package/build/esm/editor/components/filter-query.js.map +0 -1
  112. package/build/esm/editor/components/highlight-text-area.d.ts +0 -11
  113. package/build/esm/editor/components/highlight-text-area.js +0 -139
  114. package/build/esm/editor/components/highlight-text-area.js.map +0 -1
  115. package/build/esm/editor/components/log-viewer.d.ts +0 -6
  116. package/build/esm/editor/components/log-viewer.js +0 -70
  117. package/build/esm/editor/components/log-viewer.js.map +0 -1
  118. package/build/esm/editor/components/new-file.d.ts +0 -10
  119. package/build/esm/editor/components/new-file.js +0 -118
  120. package/build/esm/editor/components/new-file.js.map +0 -1
  121. package/build/esm/editor/components/scroll-query.d.ts +0 -7
  122. package/build/esm/editor/components/scroll-query.js +0 -22
  123. package/build/esm/editor/components/scroll-query.js.map +0 -1
  124. package/build/esm/editor/components/start-page.d.ts +0 -13
  125. package/build/esm/editor/components/start-page.js +0 -31
  126. package/build/esm/editor/components/start-page.js.map +0 -1
  127. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +0 -3
  128. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +0 -30
  129. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js.map +0 -1
  130. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +0 -5
  131. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +0 -50
  132. package/build/esm/editor/http/admin/editor/api/fs/read.api.js.map +0 -1
  133. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +0 -4
  134. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +0 -40
  135. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js.map +0 -1
  136. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +0 -26
  137. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +0 -150
  138. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js.map +0 -1
  139. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +0 -3
  140. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +0 -39
  141. package/build/esm/editor/http/admin/editor/api/fs/write.api.js.map +0 -1
  142. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +0 -10
  143. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +0 -47
  144. package/build/esm/editor/http/admin/editor/api/server/reload.api.js.map +0 -1
  145. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +0 -10
  146. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +0 -46
  147. package/build/esm/editor/http/admin/editor/api/server/restart.api.js.map +0 -1
  148. package/build/esm/editor/http/admin/editor/editor.d.ts +0 -1
  149. package/build/esm/editor/http/admin/editor/editor.js +0 -8
  150. package/build/esm/editor/http/admin/editor/editor.js.map +0 -1
  151. package/build/esm/editor/http/admin/editor/index.api.d.ts +0 -3
  152. package/build/esm/editor/http/admin/editor/index.api.js +0 -22
  153. package/build/esm/editor/http/admin/editor/index.api.js.map +0 -1
  154. package/build/esm/editor/server.d.ts +0 -3
  155. package/build/esm/editor/server.js +0 -50
  156. package/build/esm/editor/server.js.map +0 -1
  157. package/build/esm/editor/ws.d.ts +0 -3
  158. package/build/esm/editor/ws.js +0 -12
  159. package/build/esm/editor/ws.js.map +0 -1
  160. package/build/esm/src/bin/compile.js.map +0 -1
  161. package/build/esm/src/bin/doc-md.js.map +0 -1
  162. package/build/esm/src/bin/generate-doc.js.map +0 -1
  163. package/build/esm/src/bin/test.js.map +0 -1
  164. package/build/esm/src/bin/types.js.map +0 -1
  165. package/build/esm/src/cluster.js.map +0 -1
  166. package/build/esm/src/common/arguments.js.map +0 -1
  167. package/build/esm/src/common/assets.js.map +0 -1
  168. package/build/esm/src/common/checksum.js.map +0 -1
  169. package/build/esm/src/common/constants.js.map +0 -1
  170. package/build/esm/src/common/content-type.js.map +0 -1
  171. package/build/esm/src/common/esbuild.js.map +0 -1
  172. package/build/esm/src/common/exit.js.map +0 -1
  173. package/build/esm/src/common/fs.js.map +0 -1
  174. package/build/esm/src/common/help.js.map +0 -1
  175. package/build/esm/src/common/jsx.js.map +0 -1
  176. package/build/esm/src/common/paths.js.map +0 -1
  177. package/build/esm/src/common/watch.js.map +0 -1
  178. package/build/esm/src/inflate/inflate-sea.js.map +0 -1
  179. package/build/esm/src/inflate/inflate.js.map +0 -1
  180. package/build/esm/src/inflate/md.js.map +0 -1
  181. package/build/esm/src/inflate/setup-auth.js.map +0 -1
  182. package/build/esm/src/inflate/setup-cors.js.map +0 -1
  183. package/build/esm/src/inflate/setup-db.js.map +0 -1
  184. package/build/esm/src/inflate/setup-http.js.map +0 -1
  185. package/build/esm/src/inflate/setup-log.js.map +0 -1
  186. package/build/esm/src/inflate/setup-server-config.js.map +0 -1
  187. package/build/esm/src/inflate/setup-test.js.map +0 -1
  188. package/build/esm/src/inflate/setup-ws.js.map +0 -1
  189. package/build/esm/src/inflate/utils/sea-utils.js.map +0 -1
  190. package/build/esm/src/lib.js.map +0 -1
  191. package/build/esm/src/main.js.map +0 -1
  192. package/build/esm/src/services/app.js.map +0 -1
  193. package/build/esm/src/services/editor.js.map +0 -1
  194. package/build/esm/src/services/globals.js.map +0 -1
  195. package/build/esm/src/services/hot-reload.js.map +0 -1
  196. package/build/esm/src/services/migrations.js.map +0 -1
  197. package/build/esm/src/services/utils/admin-interface.js.map +0 -1
  198. package/build/esm/src/services/utils/cache.js.map +0 -1
  199. package/build/esm/src/services/utils/cluster-cache.js.map +0 -1
  200. package/build/esm/src/services/utils/cluster-ws.js.map +0 -1
  201. package/build/esm/src/services/utils/db-manager.js.map +0 -1
  202. package/build/esm/src/services/utils/get-route.js.map +0 -1
  203. package/build/esm/src/services/utils/log-transport.js.map +0 -1
  204. package/build/esm/src/services/utils/log.js.map +0 -1
  205. package/build/esm/src/services/utils/server-interface.js.map +0 -1
  206. package/build/esm/src/services/utils/websocketmanager.js.map +0 -1
  207. package/build/esm/src/types.js.map +0 -1
  208. package/editor/auth.ts +0 -51
  209. package/editor/common/admin-interface.ts +0 -84
  210. package/editor/common/constants.server.ts +0 -5
  211. package/editor/common/constants.ts +0 -21
  212. package/editor/common/editor-index.tsx +0 -17
  213. package/editor/common/html-encode.ts +0 -14
  214. package/editor/common/log-socket.tsx +0 -85
  215. package/editor/common/templates.ts +0 -448
  216. package/editor/components/api-preview.tsx +0 -116
  217. package/editor/components/editor.tsx +0 -486
  218. package/editor/components/file-browser.tsx +0 -308
  219. package/editor/components/file-editor-toolbar.tsx +0 -191
  220. package/editor/components/file-editor.tsx +0 -122
  221. package/editor/components/filter-query.tsx +0 -22
  222. package/editor/components/highlight-text-area.tsx +0 -159
  223. package/editor/components/log-viewer.tsx +0 -110
  224. package/editor/components/new-file.tsx +0 -169
  225. package/editor/components/scroll-query.tsx +0 -22
  226. package/editor/components/start-page.tsx +0 -49
  227. package/editor/http/admin/editor/api/fs/delete.api.tsx +0 -32
  228. package/editor/http/admin/editor/api/fs/read.api.tsx +0 -55
  229. package/editor/http/admin/editor/api/fs/rename.api.tsx +0 -41
  230. package/editor/http/admin/editor/api/fs/scan.api.tsx +0 -181
  231. package/editor/http/admin/editor/api/fs/write.api.tsx +0 -41
  232. package/editor/http/admin/editor/api/server/reload.api.ts +0 -53
  233. package/editor/http/admin/editor/api/server/restart.api.tsx +0 -52
  234. package/editor/http/admin/editor/editor.tsx +0 -8
  235. package/editor/http/admin/editor/index.api.tsx +0 -39
  236. package/editor/server.ts +0 -57
  237. package/editor/static/android-chrome-192x192.png +0 -0
  238. package/editor/static/android-chrome-512x512.png +0 -0
  239. package/editor/static/apple-touch-icon.png +0 -0
  240. package/editor/static/editor.bundle.in.mjs +0 -20
  241. package/editor/static/favicon-16x16.png +0 -0
  242. package/editor/static/favicon-32x32.png +0 -0
  243. package/editor/static/favicon.ico +0 -0
  244. package/editor/static/site.webmanifest +0 -19
  245. package/editor/ws.ts +0 -15
  246. package/sea/base64.js +0 -3
  247. package/sea/compile.sh +0 -127
  248. package/sea/copy-types.sh +0 -46
  249. package/sea/editor-assets/editor.bundle.in.mjs +0 -19
  250. package/sea/generate-global-types-asset-json.js +0 -34
  251. package/sea/release-tar.sh +0 -5
  252. package/sea/tsc.sh +0 -1
  253. package/sea/version.tag.js +0 -11
  254. package/src/bin/compile.ts +0 -35
  255. package/src/bin/doc-md.ts +0 -210
  256. package/src/bin/generate-doc.ts +0 -58
  257. package/src/bin/test.ts +0 -92
  258. package/src/bin/types.ts +0 -22
  259. package/src/cluster.ts +0 -27
  260. package/src/common/arguments.ts +0 -382
  261. package/src/common/assets.ts +0 -128
  262. package/src/common/checksum.ts +0 -58
  263. package/src/common/constants.ts +0 -18
  264. package/src/common/content-type.ts +0 -84
  265. package/src/common/esbuild.ts +0 -94
  266. package/src/common/exit.ts +0 -91
  267. package/src/common/fs.ts +0 -17
  268. package/src/common/help.ts +0 -47
  269. package/src/common/jsx.ts +0 -426
  270. package/src/common/paths.ts +0 -117
  271. package/src/common/watch.ts +0 -85
  272. package/src/inflate/inflate-sea.ts +0 -194
  273. package/src/inflate/inflate.ts +0 -96
  274. package/src/inflate/md.ts +0 -20
  275. package/src/inflate/setup-auth.ts +0 -40
  276. package/src/inflate/setup-cors.ts +0 -40
  277. package/src/inflate/setup-db.ts +0 -113
  278. package/src/inflate/setup-http.ts +0 -643
  279. package/src/inflate/setup-log.ts +0 -44
  280. package/src/inflate/setup-server-config.ts +0 -47
  281. package/src/inflate/setup-test.ts +0 -23
  282. package/src/inflate/setup-ws.ts +0 -48
  283. package/src/inflate/utils/sea-utils.ts +0 -14
  284. package/src/lib.ts +0 -19
  285. package/src/main.ts +0 -87
  286. package/src/services/app.ts +0 -640
  287. package/src/services/editor.tsx +0 -101
  288. package/src/services/globals.ts +0 -143
  289. package/src/services/hot-reload.ts +0 -48
  290. package/src/services/migrations.ts +0 -66
  291. package/src/services/utils/admin-interface.ts +0 -37
  292. package/src/services/utils/cache.ts +0 -88
  293. package/src/services/utils/cluster-cache.ts +0 -230
  294. package/src/services/utils/cluster-ws.ts +0 -197
  295. package/src/services/utils/db-manager.ts +0 -92
  296. package/src/services/utils/get-route.ts +0 -70
  297. package/src/services/utils/log-transport.ts +0 -75
  298. package/src/services/utils/log.ts +0 -91
  299. package/src/services/utils/server-interface.ts +0 -172
  300. package/src/services/utils/websocketmanager.ts +0 -149
  301. package/src/types/@esbuild.d.ts +0 -1
  302. package/src/types/@miqro/core.d.ts +0 -2
  303. package/src/types/@miqro/jsx.d.ts +0 -2
  304. package/src/types/@miqro/parser.d.ts +0 -2
  305. package/src/types/@miqro/query.d.ts +0 -2
  306. package/src/types/@miqro/request.d.ts +0 -2
  307. package/src/types/@miqro/test.d.ts +0 -2
  308. package/src/types/@miqro.d.ts +0 -1
  309. package/src/types/@types.d.ts +0 -1
  310. package/src/types/browser.globals.d.ts +0 -9
  311. package/src/types/globals.d.ts +0 -2
  312. package/src/types/jsx.globals.d.ts +0 -37
  313. package/src/types/miqro.d.ts +0 -111
  314. package/src/types/postject.d.ts +0 -1
  315. package/src/types/server.globals.d.ts +0 -72
  316. package/src/types.ts +0 -204
  317. /package/{editor/http/admin/editor → build}/font.ttf +0 -0
  318. /package/{editor/http/admin/editor → build}/style.css +0 -0
package/build/lib.cjs CHANGED
@@ -3854,13 +3854,13 @@ var require_showdown = __commonJS({
3854
3854
  });
3855
3855
 
3856
3856
  // editor/common/constants.server.ts
3857
- var import_node_path16, import_node_process11, PORT, BASE_PATH;
3857
+ var import_node_path19, import_node_process14, PORT, BASE_PATH;
3858
3858
  var init_constants_server = __esm({
3859
3859
  "editor/common/constants.server.ts"() {
3860
- import_node_path16 = require("node:path");
3861
- import_node_process11 = require("node:process");
3860
+ import_node_path19 = require("node:path");
3861
+ import_node_process14 = require("node:process");
3862
3862
  PORT = process.env["PORT"] ? process.env["PORT"] : "8080";
3863
- BASE_PATH = (0, import_node_path16.resolve)((0, import_node_process11.cwd)());
3863
+ BASE_PATH = (0, import_node_path19.resolve)((0, import_node_process14.cwd)());
3864
3864
  }
3865
3865
  });
3866
3866
 
@@ -3877,33 +3877,33 @@ function scanDir(req, basePath = BASE_PATH, ret = []) {
3877
3877
  const admin = req.editor;
3878
3878
  const services = admin ? admin.getServices() : ["."];
3879
3879
  services.forEach((service) => {
3880
- scanDirInternal(req, (0, import_node_path17.resolve)(basePath, service), ret);
3880
+ scanDirInternal(req, (0, import_node_path20.resolve)(basePath, service), ret);
3881
3881
  });
3882
3882
  return ret;
3883
3883
  }
3884
3884
  function scanDirInternal(req, path = BASE_PATH, ret = []) {
3885
- if (!(0, import_node_fs15.existsSync)(path)) {
3885
+ if (!(0, import_node_fs18.existsSync)(path)) {
3886
3886
  return ret;
3887
3887
  }
3888
- const files = (0, import_node_fs15.readdirSync)(path);
3888
+ const files = (0, import_node_fs18.readdirSync)(path);
3889
3889
  for (const file of files) {
3890
3890
  if (shouldIgnoreFile(file)) {
3891
3891
  continue;
3892
3892
  }
3893
- const filePath = (0, import_node_path17.resolve)(path, file);
3894
- if ((0, import_node_fs15.statSync)(filePath).isDirectory()) {
3893
+ const filePath = (0, import_node_path20.resolve)(path, file);
3894
+ if ((0, import_node_fs18.statSync)(filePath).isDirectory()) {
3895
3895
  scanDirInternal(req, filePath, ret);
3896
3896
  continue;
3897
3897
  } else {
3898
- const ext = (0, import_node_path17.extname)(filePath);
3899
- const fileName = (0, import_node_path17.basename)(filePath);
3898
+ const ext = (0, import_node_path20.extname)(filePath);
3899
+ const fileName = (0, import_node_path20.basename)(filePath);
3900
3900
  const name = fileName.substring(0, fileName.length - ext.length);
3901
- const subExt = (0, import_node_path17.extname)(name);
3901
+ const subExt = (0, import_node_path20.extname)(name);
3902
3902
  const subName = name.substring(0, name.length - subExt.length);
3903
3903
  ret.push({
3904
- dirs: getFileDirs((0, import_node_path17.relative)(BASE_PATH, filePath)),
3904
+ dirs: getFileDirs((0, import_node_path20.relative)(BASE_PATH, filePath)),
3905
3905
  language: getLanguage(filePath),
3906
- filePath: (0, import_node_path17.relative)(BASE_PATH, filePath),
3906
+ filePath: (0, import_node_path20.relative)(BASE_PATH, filePath),
3907
3907
  ext,
3908
3908
  fileName,
3909
3909
  name,
@@ -3921,16 +3921,16 @@ function shouldIgnoreFile(file) {
3921
3921
  }
3922
3922
  function getFileDirs(filePath) {
3923
3923
  const dirs = [];
3924
- let dir = (0, import_node_path17.dirname)(filePath);
3925
- while (dir !== import_node_path17.sep && dir !== "" && dir !== "." && dir !== BASE_PATH) {
3924
+ let dir = (0, import_node_path20.dirname)(filePath);
3925
+ while (dir !== import_node_path20.sep && dir !== "" && dir !== "." && dir !== BASE_PATH) {
3926
3926
  dirs.push(dir);
3927
- dir = (0, import_node_path17.dirname)(dir);
3927
+ dir = (0, import_node_path20.dirname)(dir);
3928
3928
  }
3929
- return dirs.reverse().map((d) => (0, import_node_path17.basename)(d));
3929
+ return dirs.reverse().map((d) => (0, import_node_path20.basename)(d));
3930
3930
  }
3931
3931
  function getLanguage(filePath) {
3932
- const ext = (0, import_node_path17.extname)(filePath);
3933
- const fileName = (0, import_node_path17.basename)(filePath);
3932
+ const ext = (0, import_node_path20.extname)(filePath);
3933
+ const fileName = (0, import_node_path20.basename)(filePath);
3934
3934
  switch (ext.toLocaleLowerCase()) {
3935
3935
  case ".py":
3936
3936
  return "python";
@@ -3998,11 +3998,11 @@ function getAPIPreview(req, filePath) {
3998
3998
  }
3999
3999
  return void 0;
4000
4000
  }
4001
- var import_node_fs15, import_node_path17, scan_api_default;
4001
+ var import_node_fs18, import_node_path20, scan_api_default;
4002
4002
  var init_scan_api = __esm({
4003
4003
  "editor/http/admin/editor/api/fs/scan.api.tsx"() {
4004
- import_node_fs15 = require("node:fs");
4005
- import_node_path17 = require("node:path");
4004
+ import_node_fs18 = require("node:fs");
4005
+ import_node_path20 = require("node:path");
4006
4006
  init_constants_server();
4007
4007
  scan_api_default = {
4008
4008
  method: "GET",
@@ -4038,25 +4038,25 @@ function readFile2(path) {
4038
4038
  const filePath = getPath(path);
4039
4039
  const language = getLanguage(filePath);
4040
4040
  if (SUPPORTED_LANGUAGES.includes(language)) {
4041
- const contents = (0, import_node_fs16.readFileSync)(filePath).toString();
4041
+ const contents = (0, import_node_fs19.readFileSync)(filePath).toString();
4042
4042
  return contents;
4043
4043
  } else {
4044
4044
  throw new Error("unsupported file format");
4045
4045
  }
4046
4046
  }
4047
4047
  function getPath(path) {
4048
- const realPath = (0, import_node_path18.resolve)(BASE_PATH, path);
4049
- if ((0, import_node_path18.relative)(BASE_PATH, realPath).startsWith("..")) {
4048
+ const realPath = (0, import_node_path21.resolve)(BASE_PATH, path);
4049
+ if ((0, import_node_path21.relative)(BASE_PATH, realPath).startsWith("..")) {
4050
4050
  throw new Error("invalid path! [" + path + "]");
4051
4051
  }
4052
4052
  return realPath;
4053
4053
  }
4054
- var import_node_fs16, import_node_path18, read_api_default;
4054
+ var import_node_fs19, import_node_path21, read_api_default;
4055
4055
  var init_read_api = __esm({
4056
4056
  "editor/http/admin/editor/api/fs/read.api.tsx"() {
4057
- import_node_fs16 = require("node:fs");
4057
+ import_node_fs19 = require("node:fs");
4058
4058
  init_constants();
4059
- import_node_path18 = require("node:path");
4059
+ import_node_path21 = require("node:path");
4060
4060
  init_scan_api();
4061
4061
  init_constants_server();
4062
4062
  read_api_default = {
@@ -4094,20 +4094,20 @@ __export(write_api_exports, {
4094
4094
  default: () => write_api_default
4095
4095
  });
4096
4096
  async function writeFile2(path, contents, override) {
4097
- if ((0, import_node_fs17.existsSync)(getPath(path)) && !override) {
4097
+ if ((0, import_node_fs20.existsSync)(getPath(path)) && !override) {
4098
4098
  throw new Error("file already exists!");
4099
4099
  }
4100
- (0, import_node_fs17.mkdirSync)((0, import_node_path19.dirname)(getPath(path)), {
4100
+ (0, import_node_fs20.mkdirSync)((0, import_node_path22.dirname)(getPath(path)), {
4101
4101
  recursive: true
4102
4102
  });
4103
- (0, import_node_fs17.writeFileSync)(getPath(path), contents);
4103
+ (0, import_node_fs20.writeFileSync)(getPath(path), contents);
4104
4104
  }
4105
- var import_node_fs17, import_node_path19, write_api_default;
4105
+ var import_node_fs20, import_node_path22, write_api_default;
4106
4106
  var init_write_api = __esm({
4107
4107
  "editor/http/admin/editor/api/fs/write.api.tsx"() {
4108
- import_node_fs17 = require("node:fs");
4108
+ import_node_fs20 = require("node:fs");
4109
4109
  init_read_api();
4110
- import_node_path19 = require("node:path");
4110
+ import_node_path22 = require("node:path");
4111
4111
  write_api_default = {
4112
4112
  middleware: [server.middleware.json()],
4113
4113
  method: "POST",
@@ -4144,21 +4144,21 @@ __export(rename_api_exports, {
4144
4144
  rename: () => rename
4145
4145
  });
4146
4146
  async function rename(path, newName) {
4147
- if ((0, import_node_fs18.existsSync)(path) && !(0, import_node_fs18.existsSync)(newName)) {
4148
- (0, import_node_fs18.mkdirSync)((0, import_node_path20.dirname)(getPath(newName)), {
4147
+ if ((0, import_node_fs21.existsSync)(path) && !(0, import_node_fs21.existsSync)(newName)) {
4148
+ (0, import_node_fs21.mkdirSync)((0, import_node_path23.dirname)(getPath(newName)), {
4149
4149
  recursive: true
4150
4150
  });
4151
- (0, import_node_fs18.renameSync)(getPath(path), getPath(newName));
4151
+ (0, import_node_fs21.renameSync)(getPath(path), getPath(newName));
4152
4152
  } else {
4153
4153
  throw new Error("invalid paths");
4154
4154
  }
4155
4155
  }
4156
- var import_node_fs18, import_node_path20, rename_api_default;
4156
+ var import_node_fs21, import_node_path23, rename_api_default;
4157
4157
  var init_rename_api = __esm({
4158
4158
  "editor/http/admin/editor/api/fs/rename.api.tsx"() {
4159
- import_node_fs18 = require("node:fs");
4159
+ import_node_fs21 = require("node:fs");
4160
4160
  init_read_api();
4161
- import_node_path20 = require("node:path");
4161
+ import_node_path23 = require("node:path");
4162
4162
  rename_api_default = {
4163
4163
  middleware: [server.middleware.json()],
4164
4164
  method: "POST",
@@ -4193,12 +4193,12 @@ __export(delete_api_exports, {
4193
4193
  default: () => delete_api_default
4194
4194
  });
4195
4195
  function deleteFile(path) {
4196
- (0, import_node_fs19.unlinkSync)(getPath(path));
4196
+ (0, import_node_fs22.unlinkSync)(getPath(path));
4197
4197
  }
4198
- var import_node_fs19, delete_api_default;
4198
+ var import_node_fs22, delete_api_default;
4199
4199
  var init_delete_api = __esm({
4200
4200
  "editor/http/admin/editor/api/fs/delete.api.tsx"() {
4201
- import_node_fs19 = require("node:fs");
4201
+ import_node_fs22 = require("node:fs");
4202
4202
  init_read_api();
4203
4203
  delete_api_default = {
4204
4204
  description: "admin editor file deletion endpoint",
@@ -4236,15 +4236,15 @@ __export(restart_api_exports, {
4236
4236
  function parseInflateErrors(errors) {
4237
4237
  return errors?.map((error2) => {
4238
4238
  return {
4239
- filePath: (0, import_node_path21.relative)(BASE_PATH, error2.filePath),
4239
+ filePath: (0, import_node_path24.relative)(BASE_PATH, error2.filePath),
4240
4240
  error: error2.error.message
4241
4241
  };
4242
4242
  });
4243
4243
  }
4244
- var import_node_path21, restart_api_default;
4244
+ var import_node_path24, restart_api_default;
4245
4245
  var init_restart_api = __esm({
4246
4246
  "editor/http/admin/editor/api/server/restart.api.tsx"() {
4247
- import_node_path21 = require("node:path");
4247
+ import_node_path24 = require("node:path");
4248
4248
  init_constants_server();
4249
4249
  restart_api_default = {
4250
4250
  method: "POST",
@@ -4293,15 +4293,15 @@ __export(reload_api_exports, {
4293
4293
  function parseInflateErrors2(errors) {
4294
4294
  return errors?.map((error2) => {
4295
4295
  return {
4296
- filePath: (0, import_node_path22.relative)(BASE_PATH, error2.filePath),
4296
+ filePath: (0, import_node_path25.relative)(BASE_PATH, error2.filePath),
4297
4297
  error: error2.error.message
4298
4298
  };
4299
4299
  });
4300
4300
  }
4301
- var import_node_path22, reload_api_default;
4301
+ var import_node_path25, reload_api_default;
4302
4302
  var init_reload_api = __esm({
4303
4303
  "editor/http/admin/editor/api/server/reload.api.ts"() {
4304
- import_node_path22 = require("node:path");
4304
+ import_node_path25 = require("node:path");
4305
4305
  init_constants_server();
4306
4306
  reload_api_default = {
4307
4307
  method: "POST",
@@ -4433,7 +4433,7 @@ function newParseOptionsError(baseOption, option, name) {
4433
4433
  return new ParseOptionsError(option.usage ? String(option.usage) : `${name ? `${name} ` : ""}not ${baseOption.type}${option.type === "number" && option.numberMin !== void 0 ? `${option.numberMin}:` : ""}${option.type === "number" && option.numberMax !== void 0 ? `:${option.numberMax}` : ""}${option.numberMinDecimals !== void 0 ? ` min decimals[${option.numberMinDecimals}]` : ""}${option.numberMaxDecimals !== void 0 ? ` max decimals[${option.numberMaxDecimals}]` : ""}${option.type === "string" && option.stringMinLength !== void 0 ? `${option.stringMinLength}:` : ""}${option.type === "string" && option.stringMaxLength !== void 0 ? `:${option.stringMaxLength}` : ""}${option.type === "array" && option.arrayMinLength !== void 0 ? `${option.arrayMinLength}:` : ""}${option.type === "array" && option.arrayMaxLength !== void 0 ? `:${option.arrayMaxLength}` : ""}${option.type === "array" && option.arrayType ? option.arrayType !== "enum" ? ` of ${option.arrayType}` : ` of ${option.arrayType} as defined. valid values [${option.enumValues}]` : ""}${option.type === "enum" ? ` as defined. valid values [${option.enumValues}]` : ""}`, name);
4434
4434
  }
4435
4435
  var parseAny = (value) => value;
4436
- function parseArray(value, args, parser3) {
4436
+ function parseArray(value, args, parser4) {
4437
4437
  let parsedList = [];
4438
4438
  if (!(value instanceof Array)) {
4439
4439
  return;
@@ -4449,7 +4449,7 @@ function parseArray(value, args, parser3) {
4449
4449
  } else {
4450
4450
  for (let i = 0; i < value.length; i++) {
4451
4451
  const v = value[i];
4452
- const parsed = parser3.parse(v, {
4452
+ const parsed = parser4.parse(v, {
4453
4453
  ...args,
4454
4454
  parseJSON: false,
4455
4455
  forceArray: false,
@@ -4467,7 +4467,7 @@ function parseArray(value, args, parser3) {
4467
4467
  function parseBoolean(value) {
4468
4468
  return value === "true" || value === true ? true : value === "false" || value === false ? false : void 0;
4469
4469
  }
4470
- function parseDict(value, args, parser3) {
4470
+ function parseDict(value, args, parser4) {
4471
4471
  const isObject = typeof value === "object";
4472
4472
  if (!isObject || !value) {
4473
4473
  return;
@@ -4476,7 +4476,7 @@ function parseDict(value, args, parser3) {
4476
4476
  const keys = Object.keys(value);
4477
4477
  const parsed = {};
4478
4478
  for (const key of keys) {
4479
- parsed[key] = parser3.parse(value[key], {
4479
+ parsed[key] = parser4.parse(value[key], {
4480
4480
  ...args,
4481
4481
  type: args.dictType
4482
4482
  }, `${args.name ? `${args.name}.` : ""}${key}`);
@@ -4494,14 +4494,14 @@ function parseEmail(value, args) {
4494
4494
  }
4495
4495
  return value;
4496
4496
  }
4497
- function parseEnum(value, args, parser3) {
4497
+ function parseEnum(value, args, parser4) {
4498
4498
  const enumValues = parseArray(args.enumValues, {
4499
4499
  name: args.name,
4500
4500
  mode: args.mode,
4501
4501
  forceArray: false,
4502
4502
  type: "array",
4503
4503
  arrayType: "string"
4504
- }, parser3);
4504
+ }, parser4);
4505
4505
  if (enumValues === void 0) {
4506
4506
  throw new ParseOptionsError(`options.enumValues not a string array`);
4507
4507
  }
@@ -4541,8 +4541,8 @@ function parseDecodeHTML(value, args) {
4541
4541
  return decodeHTML(str);
4542
4542
  }
4543
4543
  }
4544
- function parseInteger(value, args, parser3) {
4545
- return parser3.parse(value, {
4544
+ function parseInteger(value, args, parser4) {
4545
+ return parser4.parse(value, {
4546
4546
  ...args,
4547
4547
  type: "number",
4548
4548
  numberMinDecimals: 0,
@@ -4573,7 +4573,7 @@ function parseNumber(value, args) {
4573
4573
  }
4574
4574
  return parsedValue;
4575
4575
  }
4576
- function parseObject(value, args, parser3) {
4576
+ function parseObject(value, args, parser4) {
4577
4577
  const isObject = typeof value === "object" ? value : void 0;
4578
4578
  if (!isObject || !value) {
4579
4579
  return;
@@ -4585,7 +4585,7 @@ function parseObject(value, args, parser3) {
4585
4585
  const valueLeftOverProperties = new Set(Object.keys(value));
4586
4586
  for (const property of propertyNames) {
4587
4587
  const p = args.properties[property];
4588
- const v = parser3.parse(value[property], p, `${args.name ? `${args.name}.` : ""}${property}`);
4588
+ const v = parser4.parse(value[property], p, `${args.name ? `${args.name}.` : ""}${property}`);
4589
4589
  if (v !== void 0) {
4590
4590
  parsed[property] = v;
4591
4591
  }
@@ -4677,8 +4677,8 @@ var SchemaSchema = {
4677
4677
  enumValues: "string[]?"
4678
4678
  }
4679
4679
  };
4680
- function SchemaParser(value, args, parser3) {
4681
- return parser3.parse(value, {
4680
+ function SchemaParser(value, args, parser4) {
4681
+ return parser4.parse(value, {
4682
4682
  ...args,
4683
4683
  ...SchemaSchema
4684
4684
  }, args.name);
@@ -4699,8 +4699,8 @@ function parseString(value, args) {
4699
4699
  return value;
4700
4700
  }
4701
4701
  }
4702
- function parseString1(value, args, parser3) {
4703
- return parser3.parse(value, {
4702
+ function parseString1(value, args, parser4) {
4703
+ return parser4.parse(value, {
4704
4704
  ...args,
4705
4705
  type: "string",
4706
4706
  stringMinLength: 1
@@ -4733,8 +4733,8 @@ function parseURL(value, args) {
4733
4733
  }
4734
4734
  }
4735
4735
  }
4736
- function runParser(p, parser3, value, args) {
4737
- if (parser3 === void 0) {
4736
+ function runParser(p, parser4, value, args) {
4737
+ if (parser4 === void 0) {
4738
4738
  throw new ParseOptionsError(`unsupported type ${args.type}`);
4739
4739
  }
4740
4740
  if (value === void 0 && (args.required === true || args.required === void 0)) {
@@ -4762,17 +4762,17 @@ function runParser(p, parser3, value, args) {
4762
4762
  value = [value];
4763
4763
  }
4764
4764
  }
4765
- if (typeof parser3 === "function") {
4766
- return parser3(value, args, p);
4767
- } else if (typeof parser3 === "object") {
4765
+ if (typeof parser4 === "function") {
4766
+ return parser4(value, args, p);
4767
+ } else if (typeof parser4 === "object") {
4768
4768
  return p.parse(value, {
4769
4769
  ...args,
4770
- ...parser3
4770
+ ...parser4
4771
4771
  }, args.name);
4772
4772
  } else {
4773
4773
  return p.parse(value, {
4774
4774
  ...args,
4775
- type: parser3
4775
+ type: parser4
4776
4776
  }, args.name);
4777
4777
  }
4778
4778
  }
@@ -4817,11 +4817,11 @@ var Parser = class {
4817
4817
  this.register("decodeHTML", parseDecodeHTML, void 0, true, true);
4818
4818
  this.register("schema", SchemaParser, ["Schema"]);
4819
4819
  }
4820
- register(type, parser3, aliases, noList = false, noDict = false) {
4820
+ register(type, parser4, aliases, noList = false, noDict = false) {
4821
4821
  if (typeof type !== "string") {
4822
4822
  throw new Error("type must be a string");
4823
4823
  }
4824
- if (typeof parser3 !== "function" && typeof parser3 !== "object" && typeof parser3 !== "string") {
4824
+ if (typeof parser4 !== "function" && typeof parser4 !== "object" && typeof parser4 !== "string") {
4825
4825
  throw new Error("parser must be a function or Schema or a string");
4826
4826
  }
4827
4827
  if (typeof noList !== "boolean") {
@@ -4835,7 +4835,7 @@ var Parser = class {
4835
4835
  if (this.parsers.has(type)) {
4836
4836
  throw new Error(`already registered type [${type}]!`);
4837
4837
  }
4838
- this.parsers.set(type, parser3);
4838
+ this.parsers.set(type, parser4);
4839
4839
  if (!noList) {
4840
4840
  this.register(`${type}[]`, {
4841
4841
  type: "array",
@@ -5000,7 +5000,7 @@ function ReadBuffer(options) {
5000
5000
  timeout = parseInt(timeoutS, 10);
5001
5001
  }
5002
5002
  return async function ReadBuffer2(req, res) {
5003
- return new Promise((resolve20, reject) => {
5003
+ return new Promise((resolve24, reject) => {
5004
5004
  try {
5005
5005
  const readTimeout = setTimeout(() => {
5006
5006
  clearTimeout(readTimeout);
@@ -5022,7 +5022,7 @@ function ReadBuffer(options) {
5022
5022
  const responseBuffer = req.headers["content-encoding"] === "gzip" ? (0, import_zlib.gunzipSync)(concatBuffers) : concatBuffers;
5023
5023
  req.logger.trace("ctx.buffer %o", responseBuffer);
5024
5024
  req.buffer = responseBuffer;
5025
- resolve20();
5025
+ resolve24();
5026
5026
  } catch (e) {
5027
5027
  reject(e);
5028
5028
  }
@@ -5206,7 +5206,7 @@ function normalizeParseOptions(option) {
5206
5206
  properties: option !== void 0 && typeof option !== "string" && typeof option !== "boolean" ? option instanceof Array ? option : [option] : typeof option === "boolean" ? option ? ADD_EXTRA : NO_OPTIONS : typeof option === "string" ? [option] : ADD_EXTRA
5207
5207
  };
5208
5208
  }
5209
- function parseRequestPart(part, req, option, mode, parser3) {
5209
+ function parseRequestPart(part, req, option, mode, parser4) {
5210
5210
  if (part === "headers" && mode === void 0) {
5211
5211
  mode = "add_extra";
5212
5212
  }
@@ -5214,7 +5214,7 @@ function parseRequestPart(part, req, option, mode, parser3) {
5214
5214
  for (let i = 0; i < option.length; i++) {
5215
5215
  const o = option[i];
5216
5216
  try {
5217
- req[part] = (parser3 ? parser3 : DEFAULT_PARSER).parse(value, typeof o === "string" ? o : {
5217
+ req[part] = (parser4 ? parser4 : DEFAULT_PARSER).parse(value, typeof o === "string" ? o : {
5218
5218
  type: "object",
5219
5219
  properties: o,
5220
5220
  mode
@@ -5228,7 +5228,7 @@ function parseRequestPart(part, req, option, mode, parser3) {
5228
5228
  }
5229
5229
  }
5230
5230
  }
5231
- function ParseRequest(options, parser3) {
5231
+ function ParseRequest(options, parser4) {
5232
5232
  const query = normalizeParseOptions(options.query);
5233
5233
  const params = normalizeParseOptions(options.params);
5234
5234
  const body = normalizeParseOptions(options.body);
@@ -5237,7 +5237,7 @@ function ParseRequest(options, parser3) {
5237
5237
  try {
5238
5238
  try {
5239
5239
  if (options.headers !== void 0) {
5240
- parseRequestPart("headers", req, headers.properties, options.headersMode ? options.headersMode : headers.mode, parser3);
5240
+ parseRequestPart("headers", req, headers.properties, options.headersMode ? options.headersMode : headers.mode, parser4);
5241
5241
  }
5242
5242
  } catch (e) {
5243
5243
  req.logger.error("error parsing headers %o", req.headers);
@@ -5245,7 +5245,7 @@ function ParseRequest(options, parser3) {
5245
5245
  }
5246
5246
  try {
5247
5247
  if (options.query !== void 0) {
5248
- parseRequestPart("query", req, query.properties, options.queryMode ? options.queryMode : query.mode, parser3);
5248
+ parseRequestPart("query", req, query.properties, options.queryMode ? options.queryMode : query.mode, parser4);
5249
5249
  }
5250
5250
  } catch (e) {
5251
5251
  req.logger.error("error parsing query %o", req.query);
@@ -5253,7 +5253,7 @@ function ParseRequest(options, parser3) {
5253
5253
  }
5254
5254
  try {
5255
5255
  if (options.params !== void 0) {
5256
- parseRequestPart("params", req, params.properties, options.paramsMode ? options.paramsMode : params.mode, parser3);
5256
+ parseRequestPart("params", req, params.properties, options.paramsMode ? options.paramsMode : params.mode, parser4);
5257
5257
  }
5258
5258
  } catch (e) {
5259
5259
  req.logger.error("error parsing params %o", req.params);
@@ -5261,7 +5261,7 @@ function ParseRequest(options, parser3) {
5261
5261
  }
5262
5262
  try {
5263
5263
  if (options.body !== void 0) {
5264
- parseRequestPart("body", req, body.properties, options.bodyMode ? options.bodyMode : body.mode, parser3);
5264
+ parseRequestPart("body", req, body.properties, options.bodyMode ? options.bodyMode : body.mode, parser4);
5265
5265
  }
5266
5266
  } catch (e) {
5267
5267
  req.logger.error("error parsing body %o", req.body);
@@ -5273,7 +5273,7 @@ function ParseRequest(options, parser3) {
5273
5273
  }
5274
5274
  };
5275
5275
  }
5276
- function ResultParser(options, parser3) {
5276
+ function ResultParser(options, parser4) {
5277
5277
  const bodyParser = options.body instanceof Array ? options.body : typeof options.body === "boolean" ? options.body === true ? ["any?"] : [] : typeof options.body === "string" ? [options.body] : options.body ? [options.body] : ["any?"];
5278
5278
  const statusParserSet = options.status instanceof Array ? new Set(options.status) : options.status !== void 0 ? /* @__PURE__ */ new Set([options.status]) : null;
5279
5279
  const headersParser = options.headers instanceof Array ? options.headers : typeof options.headers === "boolean" ? options.headers === true ? ["any?"] : [] : typeof options.headers === "string" ? [options.headers] : options.headers ? [options.headers] : ["any?"];
@@ -5289,7 +5289,7 @@ function ResultParser(options, parser3) {
5289
5289
  const mappedLastResult = {
5290
5290
  ...lastResult
5291
5291
  };
5292
- const parsedStatus = (parser3 ? parser3 : DEFAULT_PARSER).parse(lastResult.status, "number?", `ctx.results.status}`);
5292
+ const parsedStatus = (parser4 ? parser4 : DEFAULT_PARSER).parse(lastResult.status, "number?", `ctx.results.status}`);
5293
5293
  if (statusParserSet) {
5294
5294
  if (parsedStatus === void 0) {
5295
5295
  throw new Error(`error parsing lastResult.status[${lastResult.status}] not defined as [${statusParserSet}]`);
@@ -5305,8 +5305,8 @@ function ResultParser(options, parser3) {
5305
5305
  mappedLastResult.status = parsedStatus;
5306
5306
  req.logger.debug(`ctx.results.status mapped to %o`, mappedLastResult.status);
5307
5307
  }
5308
- mappedLastResult.body = parsePart(req, "body", lastResult.body, bodyParser, options.bodyMode, parser3);
5309
- mappedLastResult.headers = parsePart(req, "headers", lastResult.headers, headersParser, options.headersMode, parser3);
5308
+ mappedLastResult.body = parsePart(req, "body", lastResult.body, bodyParser, options.bodyMode, parser4);
5309
+ mappedLastResult.headers = parsePart(req, "headers", lastResult.headers, headersParser, options.headersMode, parser4);
5310
5310
  return mappedLastResult;
5311
5311
  } catch (e) {
5312
5312
  req.logger.error(`error parsing lastResult[%o]`, lastResult);
@@ -5342,11 +5342,11 @@ async function ResponseHandler(req, res) {
5342
5342
  }
5343
5343
  }
5344
5344
  }
5345
- function parsePart(req, part, value, args, mode, parser3) {
5345
+ function parsePart(req, part, value, args, mode, parser4) {
5346
5346
  for (let i = 0; i < args.length; i++) {
5347
5347
  const o = args[i];
5348
5348
  try {
5349
- const mappedResultBody = (parser3 ? parser3 : DEFAULT_PARSER).parse(value, typeof o === "string" ? o : {
5349
+ const mappedResultBody = (parser4 ? parser4 : DEFAULT_PARSER).parse(value, typeof o === "string" ? o : {
5350
5350
  type: "object",
5351
5351
  properties: o,
5352
5352
  mode
@@ -5853,12 +5853,12 @@ var Response = class _Response extends import_http.ServerResponse {
5853
5853
  });
5854
5854
  }
5855
5855
  async asyncWrite(chunk) {
5856
- return new Promise((resolve20, reject) => {
5856
+ return new Promise((resolve24, reject) => {
5857
5857
  this.write(chunk, function(error2) {
5858
5858
  if (error2) {
5859
5859
  reject(error2);
5860
5860
  } else {
5861
- resolve20();
5861
+ resolve24();
5862
5862
  }
5863
5863
  });
5864
5864
  });
@@ -5867,7 +5867,7 @@ var Response = class _Response extends import_http.ServerResponse {
5867
5867
  if (this.headersSent) {
5868
5868
  return Promise.reject(new Error("already ended"));
5869
5869
  }
5870
- return new Promise((resolve20, reject) => {
5870
+ return new Promise((resolve24, reject) => {
5871
5871
  try {
5872
5872
  if (this.headersSent) {
5873
5873
  reject(new Error("already ended"));
@@ -5896,7 +5896,7 @@ var Response = class _Response extends import_http.ServerResponse {
5896
5896
  this.setHeader("connection", "close");
5897
5897
  const nBody = body !== void 0 ? body instanceof Buffer ? body : String(body) : null;
5898
5898
  this.end(nBody, () => {
5899
- resolve20();
5899
+ resolve24();
5900
5900
  });
5901
5901
  }
5902
5902
  } catch (e) {
@@ -6790,11 +6790,11 @@ var App = class extends Router {
6790
6790
  return this.httpServer.listen(...args);
6791
6791
  }
6792
6792
  async listen(...args) {
6793
- return new Promise((resolve20, reject) => {
6793
+ return new Promise((resolve24, reject) => {
6794
6794
  try {
6795
6795
  this.shouldCloseConnection = false;
6796
6796
  this.httpServer.listen(...args, () => {
6797
- resolve20(this.httpServer);
6797
+ resolve24(this.httpServer);
6798
6798
  });
6799
6799
  } catch (e) {
6800
6800
  reject(e);
@@ -6802,14 +6802,14 @@ var App = class extends Router {
6802
6802
  });
6803
6803
  }
6804
6804
  async close() {
6805
- return new Promise((resolve20, reject) => {
6805
+ return new Promise((resolve24, reject) => {
6806
6806
  try {
6807
6807
  this.shouldCloseConnection = true;
6808
6808
  this.httpServer.close((err) => {
6809
6809
  if (err) {
6810
6810
  reject(err);
6811
6811
  } else {
6812
- resolve20(this.httpServer);
6812
+ resolve24(this.httpServer);
6813
6813
  }
6814
6814
  });
6815
6815
  const keys = Object.keys(this.connections);
@@ -6853,10 +6853,10 @@ var WebSocketServer = class {
6853
6853
  const clients = this.clients.values();
6854
6854
  for (const client of clients) {
6855
6855
  if (fromUUID === void 0 || client.uuid !== fromUUID) {
6856
- tR.push(new Promise(async (resolve20, reject) => {
6856
+ tR.push(new Promise(async (resolve24, reject) => {
6857
6857
  try {
6858
6858
  await this.writeTo(client.uuid, data);
6859
- resolve20();
6859
+ resolve24();
6860
6860
  } catch (e) {
6861
6861
  reject(e);
6862
6862
  }
@@ -6870,7 +6870,7 @@ var WebSocketServer = class {
6870
6870
  if (!client) {
6871
6871
  throw new Error("client not found");
6872
6872
  }
6873
- return new Promise((resolve20, reject) => {
6873
+ return new Promise((resolve24, reject) => {
6874
6874
  try {
6875
6875
  client.req.socket.write(createFrame(data), (err) => {
6876
6876
  if (err) {
@@ -6882,7 +6882,7 @@ var WebSocketServer = class {
6882
6882
  this.clients.delete(clientUUID);
6883
6883
  reject(err);
6884
6884
  } else {
6885
- resolve20();
6885
+ resolve24();
6886
6886
  }
6887
6887
  });
6888
6888
  } catch (e) {
@@ -7145,12 +7145,12 @@ function sqlite3ExecutorPrepare(args) {
7145
7145
  const columnsSQL = isSelect ? `SELECT ${renderNameAS(q._columns)}` : "SELECT count(*) as count";
7146
7146
  const whereSQL = where.sql !== "" ? ` WHERE ${where.sql}` : "";
7147
7147
  const fromSQL = ` FROM ${renderNameAS(q._selectFrom)}`;
7148
- const join9 = q._joins.map((j) => getJoin(j));
7149
- const joinValues = join9.reduce(function(ret, current) {
7148
+ const join14 = q._joins.map((j) => getJoin(j));
7149
+ const joinValues = join14.reduce(function(ret, current) {
7150
7150
  ret = ret.concat(current.values);
7151
7151
  return ret;
7152
7152
  }, []);
7153
- const joinSQL = join9.map((j) => j.sql).join(" ");
7153
+ const joinSQL = join14.map((j) => j.sql).join(" ");
7154
7154
  const sql = `${columnsSQL}${fromSQL}${joinSQL}${whereSQL}${getGroupBy(q._groupBy)}${getOrderBy(q._orderBy)}${getLimit(q._limitBy, q._offsetBy)}`;
7155
7155
  return [{
7156
7156
  sql,
@@ -7179,10 +7179,10 @@ function sqlite3ExecutorPrepare(args) {
7179
7179
  throw new Error(`unsupported ${args}`);
7180
7180
  }
7181
7181
  }
7182
- function getJoin(join9) {
7183
- const wherePrepare = getWhereStatement(join9._on);
7182
+ function getJoin(join14) {
7183
+ const wherePrepare = getWhereStatement(join14._on);
7184
7184
  return {
7185
- sql: ` ${join9._verb ? `${join9._verb} ` : ""}JOIN ${renderNameAS(join9._table)} ON ${wherePrepare.sql}`,
7185
+ sql: ` ${join14._verb ? `${join14._verb} ` : ""}JOIN ${renderNameAS(join14._table)} ON ${wherePrepare.sql}`,
7186
7186
  values: wherePrepare.values
7187
7187
  };
7188
7188
  }
@@ -7366,9 +7366,9 @@ function getInsertValues(columns, values) {
7366
7366
  values: args
7367
7367
  };
7368
7368
  }
7369
- function renderNameAS(input, join9 = ", ") {
7369
+ function renderNameAS(input, join14 = ", ") {
7370
7370
  const list = input instanceof Array ? input : [input];
7371
- return list.map((i) => typeof i === "string" ? i : `${i.name} AS ${i.as}`).join(join9);
7371
+ return list.map((i) => typeof i === "string" ? i : `${i.name} AS ${i.as}`).join(join14);
7372
7372
  }
7373
7373
  function getGroupBy(groupBy) {
7374
7374
  return groupBy.length > 0 ? ` GROUP BY ${groupBy.join(",")}` : "";
@@ -7470,7 +7470,7 @@ async function sqlite3Executor(config) {
7470
7470
  },
7471
7471
  prepare: sqlite3ExecutorPrepare,
7472
7472
  query: async function sqlite3Executor2(sql, values) {
7473
- return new Promise((resolve20, reject) => {
7473
+ return new Promise((resolve24, reject) => {
7474
7474
  const st = driver.prepare(sql, values, function(error2) {
7475
7475
  if (error2) {
7476
7476
  reject(error2);
@@ -7483,7 +7483,7 @@ async function sqlite3Executor(config) {
7483
7483
  if (error4) {
7484
7484
  reject(error4);
7485
7485
  } else {
7486
- resolve20(rows);
7486
+ resolve24(rows);
7487
7487
  }
7488
7488
  });
7489
7489
  }
@@ -8227,7 +8227,7 @@ async function sqlite3CLIExecutor(config) {
8227
8227
  disconnect: async function sqlite3ExecutorDisconnect() {
8228
8228
  },
8229
8229
  query: async function sqlite3Executor2(sql, values) {
8230
- return new Promise((resolve20, reject) => {
8230
+ return new Promise((resolve24, reject) => {
8231
8231
  try {
8232
8232
  let i = 0;
8233
8233
  const raw = sql.replaceAll("?", (sub) => {
@@ -8254,9 +8254,9 @@ async function sqlite3CLIExecutor(config) {
8254
8254
  reject(new Error(stderr));
8255
8255
  } else {
8256
8256
  if (stdout) {
8257
- resolve20(JSON.parse(stdout));
8257
+ resolve24(JSON.parse(stdout));
8258
8258
  } else {
8259
- resolve20([]);
8259
+ resolve24([]);
8260
8260
  }
8261
8261
  }
8262
8262
  }
@@ -8294,7 +8294,7 @@ async function nativeSqlite(config) {
8294
8294
  return driver.close();
8295
8295
  },
8296
8296
  query: async function sqlite3Executor2(sql, values) {
8297
- return new Promise((resolve20, reject) => {
8297
+ return new Promise((resolve24, reject) => {
8298
8298
  try {
8299
8299
  if (values) {
8300
8300
  for (let i = 0; i < values.length; i++) {
@@ -8314,10 +8314,10 @@ async function nativeSqlite(config) {
8314
8314
  stmt.setReadBigInts(true);
8315
8315
  if (values && values.length > 0) {
8316
8316
  const ret = stmt.all(...values);
8317
- resolve20(ret);
8317
+ resolve24(ret);
8318
8318
  } else {
8319
8319
  const ret = stmt.all();
8320
- resolve20(ret);
8320
+ resolve24(ret);
8321
8321
  }
8322
8322
  } catch (e) {
8323
8323
  reject(e);
@@ -9239,7 +9239,8 @@ var LogProvider = class {
9239
9239
  constructor(options) {
9240
9240
  this.options = {
9241
9241
  formatter: options && options.formatter ? options.formatter : DEFAULT_FORMATTER,
9242
- transports: options && options.transports ? options.transports : [ConsoleTransport()]
9242
+ transports: options && options.transports ? options.transports : [ConsoleTransport()],
9243
+ name: options?.name
9243
9244
  };
9244
9245
  this.requestLoggerFactory = this.requestLoggerFactory.bind(this);
9245
9246
  }
@@ -9303,8 +9304,8 @@ var LogProvider = class {
9303
9304
  var import_node_cluster3 = __toESM(require("node:cluster"), 1);
9304
9305
 
9305
9306
  // src/inflate/setup-http.ts
9306
- var import_node_fs9 = require("node:fs");
9307
- var import_node_path10 = require("node:path");
9307
+ var import_node_fs11 = require("node:fs");
9308
+ var import_node_path12 = require("node:path");
9308
9309
 
9309
9310
  // src/common/content-type.ts
9310
9311
  var DEFAULT_CONTENT_TYPE = "application/octet-stream";
@@ -11212,7 +11213,7 @@ async function calculateChecksum(filePath) {
11212
11213
  return calculateChecksumFromStream((0, import_node_fs2.createReadStream)(filePath));
11213
11214
  }
11214
11215
  async function calculateChecksumFromStream(input) {
11215
- return new Promise((resolve20, reject) => {
11216
+ return new Promise((resolve24, reject) => {
11216
11217
  try {
11217
11218
  const hash = (0, import_node_crypto.createHash)("sha256");
11218
11219
  input.on("readable", () => {
@@ -11220,7 +11221,7 @@ async function calculateChecksumFromStream(input) {
11220
11221
  if (data)
11221
11222
  hash.update(data);
11222
11223
  else {
11223
- resolve20(hash.digest("hex").toString());
11224
+ resolve24(hash.digest("hex").toString());
11224
11225
  }
11225
11226
  });
11226
11227
  input.on("error", (e) => {
@@ -11232,11 +11233,11 @@ async function calculateChecksumFromStream(input) {
11232
11233
  });
11233
11234
  }
11234
11235
  async function calculateChecksumFromBuffer(buffer) {
11235
- return new Promise((resolve20, reject) => {
11236
+ return new Promise((resolve24, reject) => {
11236
11237
  try {
11237
11238
  const hash = (0, import_node_crypto.createHash)("sha256");
11238
11239
  hash.update(buffer);
11239
- resolve20(hash.digest("hex").toString());
11240
+ resolve24(hash.digest("hex").toString());
11240
11241
  } catch (e) {
11241
11242
  reject(e);
11242
11243
  }
@@ -11264,8 +11265,8 @@ var ASSETS_ROUTER = {
11264
11265
  "jsx.dom.js": "build/jsx.dom.js",
11265
11266
  "types.json": "sea/types.json",
11266
11267
  "editor-assets/editor.bundle.js": "build/editor.bundle.js",
11267
- "editor-assets/style.css": "editor/http/admin/editor/style.css",
11268
- "editor-assets/font.ttf": "editor/http/admin/editor/font.ttf"
11268
+ "editor-assets/style.css": "build/style.css",
11269
+ "editor-assets/font.ttf": "build/font.ttf"
11269
11270
  };
11270
11271
  function getAsset(key) {
11271
11272
  if ((0, import_node_sea.isSea)()) {
@@ -11417,12 +11418,42 @@ function getStaticFilesPath(servicePath) {
11417
11418
  }
11418
11419
  return false;
11419
11420
  }
11421
+ function getMiddlewareConfigPath(servicePath) {
11422
+ const middlewarePath = (0, import_node_path3.resolve)(servicePath, "middleware.ts");
11423
+ const middlewarePathJS = (0, import_node_path3.resolve)(servicePath, "middleware.js");
11424
+ if ((0, import_node_fs4.existsSync)(middlewarePath) && !(0, import_node_fs4.statSync)(middlewarePath).isDirectory()) {
11425
+ return middlewarePath;
11426
+ } else if ((0, import_node_fs4.existsSync)(middlewarePathJS) && !(0, import_node_fs4.statSync)(middlewarePathJS).isDirectory()) {
11427
+ return middlewarePathJS;
11428
+ }
11429
+ return false;
11430
+ }
11431
+ function getErrorConfigPath(servicePath) {
11432
+ const errorPath = (0, import_node_path3.resolve)(servicePath, "catch.ts");
11433
+ const errorPathJS = (0, import_node_path3.resolve)(servicePath, "catch.js");
11434
+ if ((0, import_node_fs4.existsSync)(errorPath) && !(0, import_node_fs4.statSync)(errorPath).isDirectory()) {
11435
+ return errorPath;
11436
+ } else if ((0, import_node_fs4.existsSync)(errorPathJS) && !(0, import_node_fs4.statSync)(errorPathJS).isDirectory()) {
11437
+ return errorPathJS;
11438
+ }
11439
+ return false;
11440
+ }
11441
+ function getDocConfigPath(servicePath) {
11442
+ const docPath = (0, import_node_path3.resolve)(servicePath, "doc.ts");
11443
+ const docPathJS = (0, import_node_path3.resolve)(servicePath, "doc.js");
11444
+ if ((0, import_node_fs4.existsSync)(docPath) && !(0, import_node_fs4.statSync)(docPath).isDirectory()) {
11445
+ return docPath;
11446
+ } else if ((0, import_node_fs4.existsSync)(docPathJS) && !(0, import_node_fs4.statSync)(docPathJS).isDirectory()) {
11447
+ return docPathJS;
11448
+ }
11449
+ return false;
11450
+ }
11420
11451
  function getAuthConfigPath(servicePath) {
11421
11452
  const authPath = (0, import_node_path3.resolve)(servicePath, "auth.ts");
11422
11453
  const authPathJS = (0, import_node_path3.resolve)(servicePath, "auth.js");
11423
11454
  if ((0, import_node_fs4.existsSync)(authPath) && !(0, import_node_fs4.statSync)(authPath).isDirectory()) {
11424
11455
  return authPath;
11425
- } else if ((0, import_node_fs4.existsSync)(authPath) && !(0, import_node_fs4.statSync)(authPath).isDirectory()) {
11456
+ } else if ((0, import_node_fs4.existsSync)(authPathJS) && !(0, import_node_fs4.statSync)(authPathJS).isDirectory()) {
11426
11457
  return authPathJS;
11427
11458
  }
11428
11459
  return false;
@@ -11492,7 +11523,7 @@ var NODEJS_EXTERNAL = [
11492
11523
  "pg"
11493
11524
  ];
11494
11525
  async function esBuild(options, logger) {
11495
- return new Promise(async (resolve20, reject) => {
11526
+ return new Promise(async (resolve24, reject) => {
11496
11527
  try {
11497
11528
  const valid = await validateESBuild(logger);
11498
11529
  const esBuildCMD = `${getESBuildBinaryPath()} "${options.entryPoints[0]}" ${NODEJS_EXTERNAL.map((e) => `--external:${e}`).join(" ")} --loader:.js=jsx --jsx-factory=${options.jsxFactory} --jsx-fragment=${options.jsxFragment} ${options.bundle ? " --bundle" : ""}${options.minify ? " --minify" : ""}${options.outfile ? ` --outfile="${options.outfile}"` : ""}${options.platform ? ` --platform=${options.platform}` : ""}`;
@@ -11508,7 +11539,7 @@ async function esBuild(options, logger) {
11508
11539
  if (err) {
11509
11540
  reject(err);
11510
11541
  } else {
11511
- resolve20({
11542
+ resolve24({
11512
11543
  outputFiles: [{
11513
11544
  path: "",
11514
11545
  contents: stdout
@@ -11532,10 +11563,8 @@ var showdown = __toESM(require_showdown(), 1);
11532
11563
  var import_node_fs5 = require("node:fs");
11533
11564
  function inflateMD2HTML(inFile, logger) {
11534
11565
  try {
11535
- const converter = new showdown.default.Converter();
11536
- converter.setFlavor("github");
11537
11566
  const text = (0, import_node_fs5.readFileSync)(inFile).toString();
11538
- const html = converter.makeHtml(text);
11567
+ const html = inflateMDString2HTML(text);
11539
11568
  return html;
11540
11569
  } catch (e) {
11541
11570
  logger?.error("error with: " + inFile);
@@ -11543,6 +11572,12 @@ function inflateMD2HTML(inFile, logger) {
11543
11572
  throw e;
11544
11573
  }
11545
11574
  }
11575
+ function inflateMDString2HTML(text, logger) {
11576
+ const converter = new showdown.default.Converter();
11577
+ converter.setFlavor("github");
11578
+ const html = converter.makeHtml(text);
11579
+ return html;
11580
+ }
11546
11581
 
11547
11582
  // src/common/constants.ts
11548
11583
  var EXIT_CODES = {
@@ -11831,6 +11866,53 @@ var AuthConfigSchema = {
11831
11866
  }
11832
11867
  //mode:"add_extra"
11833
11868
  };
11869
+ var MiddlewareConfigSchema = {
11870
+ type: "object",
11871
+ properties: {
11872
+ middleware: {
11873
+ type: "Array",
11874
+ arrayType: "function|object",
11875
+ required: false,
11876
+ properties: {
11877
+ ...HandlerWithOptionsSchema.properties
11878
+ }
11879
+ },
11880
+ post: {
11881
+ type: "Array",
11882
+ arrayType: "function|object",
11883
+ required: false,
11884
+ properties: {
11885
+ ...HandlerWithOptionsSchema.properties
11886
+ }
11887
+ }
11888
+ }
11889
+ };
11890
+ var ErrorConfigSchema = {
11891
+ type: "object",
11892
+ properties: {
11893
+ catch: {
11894
+ type: "Array",
11895
+ required: false,
11896
+ arrayType: "function"
11897
+ }
11898
+ }
11899
+ };
11900
+ var DocConfigSchema = {
11901
+ type: "object",
11902
+ properties: {
11903
+ publish: {
11904
+ type: "dict?",
11905
+ dictType: "object",
11906
+ properties: {
11907
+ type: {
11908
+ type: "enum?",
11909
+ enumValues: ["HTML", "MD", "JSON"]
11910
+ },
11911
+ all: "boolean?"
11912
+ }
11913
+ }
11914
+ }
11915
+ };
11834
11916
  async function importAPIRoute(inFile, logger) {
11835
11917
  const mod = (await importJSXFile(inFile, logger)).default;
11836
11918
  const module2 = typeof mod === "function" ? { handler: mod } : parser2.parse(mod, APIRouteSchema, (0, import_node_path5.basename)(inFile));
@@ -11876,6 +11958,30 @@ async function importAuthModule(inFile, logger) {
11876
11958
  throw new Error(`error with module [${inFile}] undefined`);
11877
11959
  }
11878
11960
  }
11961
+ async function importMiddlewareConfigModule(inFile, logger) {
11962
+ const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, MiddlewareConfigSchema, (0, import_node_path5.basename)(inFile));
11963
+ if (module2 !== void 0) {
11964
+ return module2;
11965
+ } else {
11966
+ throw new Error(`error with module [${inFile}] undefined`);
11967
+ }
11968
+ }
11969
+ async function importErrorConfigModule(inFile, logger) {
11970
+ const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, ErrorConfigSchema, (0, import_node_path5.basename)(inFile));
11971
+ if (module2 !== void 0) {
11972
+ return module2;
11973
+ } else {
11974
+ throw new Error(`error with module [${inFile}] undefined`);
11975
+ }
11976
+ }
11977
+ async function importDocConfigModule(inFile, logger) {
11978
+ const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, DocConfigSchema, (0, import_node_path5.basename)(inFile));
11979
+ if (module2 !== void 0) {
11980
+ return module2;
11981
+ } else {
11982
+ throw new Error(`error with module [${inFile}] undefined`);
11983
+ }
11984
+ }
11879
11985
  async function importCORSModule(inFile, logger) {
11880
11986
  const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, CORSOptionsSchema, (0, import_node_path5.basename)(inFile));
11881
11987
  if (module2 !== void 0) {
@@ -12020,7 +12126,7 @@ socket.addEventListener("error", (err) => {
12020
12126
  }
12021
12127
 
12022
12128
  // src/inflate/setup-http.ts
12023
- var import_node_process6 = require("node:process");
12129
+ var import_node_process8 = require("node:process");
12024
12130
 
12025
12131
  // src/inflate/setup-cors.ts
12026
12132
  var import_node_fs7 = require("node:fs");
@@ -12167,13 +12273,96 @@ function describeFilePath(filePath) {
12167
12273
  };
12168
12274
  }
12169
12275
 
12276
+ // src/inflate/setup-middleware.ts
12277
+ var import_node_path10 = require("node:path");
12278
+ var import_node_fs9 = require("node:fs");
12279
+ var import_node_process6 = require("node:process");
12280
+ async function setupMiddleware(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors) {
12281
+ const middlewarePath = getMiddlewareConfigPath(servicePath);
12282
+ if (middlewarePath) {
12283
+ try {
12284
+ const middewareModule = await importMiddlewareConfigModule(middlewarePath, logger);
12285
+ logger.debug("setting up middleware from [%s]", (0, import_node_path10.join)(service, (0, import_node_path10.basename)(middlewarePath)));
12286
+ if (middewareModule && middewareModule.middleware) {
12287
+ for (const m of middewareModule.middleware) {
12288
+ mainRouter.use(m);
12289
+ }
12290
+ }
12291
+ if (inflateDir && inflateSea) {
12292
+ const inflatePath = (0, import_node_path10.resolve)(inflateDir, service, "middleware.js");
12293
+ (0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(inflatePath), {
12294
+ recursive: true
12295
+ });
12296
+ logger.log("writing [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath));
12297
+ (0, import_node_fs9.writeFileSync)(inflatePath, await inflateJSX(middlewarePath, {
12298
+ embemedJSX: false,
12299
+ minify: false,
12300
+ useExport: true,
12301
+ logger
12302
+ }));
12303
+ }
12304
+ return middewareModule;
12305
+ } catch (e) {
12306
+ errors.push({
12307
+ filePath: middlewarePath,
12308
+ error: e
12309
+ });
12310
+ logger.error("error with " + middlewarePath);
12311
+ logger.error(e);
12312
+ }
12313
+ }
12314
+ return null;
12315
+ }
12316
+
12317
+ // src/inflate/setup-error.ts
12318
+ var import_node_path11 = require("node:path");
12319
+ var import_node_fs10 = require("node:fs");
12320
+ var import_node_process7 = require("node:process");
12321
+ async function setupError(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors) {
12322
+ const errorPath = getErrorConfigPath(servicePath);
12323
+ if (errorPath) {
12324
+ try {
12325
+ const errorModule = await importErrorConfigModule(errorPath, logger);
12326
+ logger.debug("setting up error handling from [%s]", (0, import_node_path11.join)(service, (0, import_node_path11.basename)(errorPath)));
12327
+ if (errorModule && errorModule.catch) {
12328
+ for (const m of errorModule.catch) {
12329
+ mainRouter.catch(m);
12330
+ }
12331
+ }
12332
+ if (inflateDir && inflateSea) {
12333
+ const inflatePath = (0, import_node_path11.resolve)(inflateDir, service, "catch.js");
12334
+ (0, import_node_fs10.mkdirSync)((0, import_node_path11.dirname)(inflatePath), {
12335
+ recursive: true
12336
+ });
12337
+ logger.log("writing [%s]", (0, import_node_path11.relative)((0, import_node_process7.cwd)(), inflatePath));
12338
+ (0, import_node_fs10.writeFileSync)(inflatePath, await inflateJSX(errorPath, {
12339
+ embemedJSX: false,
12340
+ minify: false,
12341
+ useExport: true,
12342
+ logger
12343
+ }));
12344
+ }
12345
+ } catch (e) {
12346
+ errors.push({
12347
+ filePath: errorPath,
12348
+ error: e
12349
+ });
12350
+ logger.error("error with " + errorPath);
12351
+ logger.error(e);
12352
+ }
12353
+ }
12354
+ }
12355
+
12170
12356
  // src/inflate/setup-http.ts
12171
12357
  async function setupHTTPRouter(server2, logger, hotreload, servicePath, service, routeFileMap, staticFileMap, inflateDir, inflateSea, errors) {
12172
12358
  const mainRouter = new Router();
12173
12359
  const apiRouterPath = getHTTPRouterPath(servicePath);
12360
+ let middlewareConfig = null;
12361
+ await setupError(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
12362
+ await setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
12363
+ await setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
12364
+ middlewareConfig = await setupMiddleware(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
12174
12365
  if (apiRouterPath) {
12175
- await setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
12176
- await setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
12177
12366
  logger.trace("setting up http routes from [%s]", service);
12178
12367
  const { router: httpRouter } = await createRouterFromDirectory(server2, hotreload, service, logger, apiRouterPath, errors, routeFileMap, staticFileMap, inflateDir, inflateSea);
12179
12368
  mainRouter.use(httpRouter);
@@ -12184,6 +12373,11 @@ async function setupHTTPRouter(server2, logger, hotreload, servicePath, service,
12184
12373
  const staticRouter = createStaticRouterFromDirectory(service, logger, staticFilesPath, inflateDir, routeFileMap, staticFileMap);
12185
12374
  mainRouter.use(staticRouter);
12186
12375
  }
12376
+ if (middlewareConfig && middlewareConfig.post) {
12377
+ for (const m of middlewareConfig.post) {
12378
+ mainRouter.use(m);
12379
+ }
12380
+ }
12187
12381
  return mainRouter;
12188
12382
  }
12189
12383
  function createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap) {
@@ -12193,7 +12387,7 @@ function createStaticRoute(service, logger, router, dir, file, inflateDir, route
12193
12387
  dir
12194
12388
  });
12195
12389
  const contentType = CONTENT_TYPE_MAP[String(file.ext).toLocaleLowerCase()];
12196
- const path = (0, import_node_path10.join)("/", (0, import_node_path10.relative)(dir, file.filePath));
12390
+ const path = (0, import_node_path12.join)("/", (0, import_node_path12.relative)(dir, file.filePath));
12197
12391
  routeFileMap[file.filePath] = {
12198
12392
  routes: [{
12199
12393
  method: "GET",
@@ -12203,13 +12397,13 @@ function createStaticRoute(service, logger, router, dir, file, inflateDir, route
12203
12397
  previewMethod: "html"
12204
12398
  };
12205
12399
  if (inflateDir) {
12206
- const inflatePath = (0, import_node_path10.join)(inflateDir, service, "static", path);
12207
- (0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(inflatePath), {
12400
+ const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
12401
+ (0, import_node_fs11.mkdirSync)((0, import_node_path12.dirname)(inflatePath), {
12208
12402
  recursive: true
12209
12403
  });
12210
- logger.log("writing [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath));
12211
- const body = (0, import_node_fs9.readFileSync)(file.filePath);
12212
- (0, import_node_fs9.writeFileSync)(inflatePath, body);
12404
+ logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath));
12405
+ const body = (0, import_node_fs11.readFileSync)(file.filePath);
12406
+ (0, import_node_fs11.writeFileSync)(inflatePath, body);
12213
12407
  if (staticFileMap) {
12214
12408
  staticFileMap[file.filePath] = {
12215
12409
  contentType,
@@ -12218,15 +12412,15 @@ function createStaticRoute(service, logger, router, dir, file, inflateDir, route
12218
12412
  method: "GET",
12219
12413
  path: normalizePath(path),
12220
12414
  body: Buffer.from(body),
12221
- inflatePath: inflateDir ? (0, import_node_path10.join)(inflateDir, service, "static", path) : void 0
12415
+ inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
12222
12416
  };
12223
12417
  }
12224
12418
  }
12225
12419
  router.use(assertGlobalTampered);
12226
12420
  router.get(path, async function(_req, res) {
12227
- await new Promise((resolve20, reject) => {
12421
+ await new Promise((resolve24, reject) => {
12228
12422
  try {
12229
- (0, import_node_fs9.readFile)(file.filePath, async (err, body) => {
12423
+ (0, import_node_fs11.readFile)(file.filePath, async (err, body) => {
12230
12424
  if (err) {
12231
12425
  reject(err);
12232
12426
  } else {
@@ -12238,7 +12432,7 @@ function createStaticRoute(service, logger, router, dir, file, inflateDir, route
12238
12432
  },
12239
12433
  body
12240
12434
  });
12241
- resolve20();
12435
+ resolve24();
12242
12436
  } catch (e) {
12243
12437
  reject(e);
12244
12438
  }
@@ -12260,7 +12454,7 @@ function createStaticRouterFromDirectory(service, logger, dir, inflateDir, route
12260
12454
  async function createRouterFromDirectory(server2, hotreload, service, logger, dir, errors = [], routeFileMap = {}, staticFileMap = null, inflateDir, inflateSea) {
12261
12455
  const router = new Router();
12262
12456
  router.use(assertGlobalTampered);
12263
- await Promise.all(scanFiles(dir).map((file) => new Promise(async (resolve20) => {
12457
+ await Promise.all(scanFiles(dir).map((file) => new Promise(async (resolve24) => {
12264
12458
  try {
12265
12459
  switch (file.ext) {
12266
12460
  case ".jsx":
@@ -12269,13 +12463,13 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12269
12463
  case ".tsx": {
12270
12464
  switch (file.subExt) {
12271
12465
  case ".test":
12272
- return resolve20();
12466
+ return resolve24();
12273
12467
  case ".ignore":
12274
12468
  logger.warn("ignoring [%s]", file.filePath);
12275
- return resolve20();
12469
+ return resolve24();
12276
12470
  case ".api": {
12277
12471
  const module2 = await importAPIRoute(file.filePath, logger);
12278
- const routes = getRoutes((0, import_node_path10.join)("/", (0, import_node_path10.dirname)((0, import_node_path10.relative)(dir, file.filePath))), file.subName, module2);
12472
+ const routes = getRoutes((0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath))), file.subName, module2);
12279
12473
  routeFileMap[file.filePath] = {
12280
12474
  routes,
12281
12475
  service,
@@ -12290,21 +12484,21 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12290
12484
  for (const r of routes) {
12291
12485
  if (inflateDir && r.defaultInflatePath && inflateSea) {
12292
12486
  const rPath = r.defaultInflatePath;
12293
- const inflatePath = (0, import_node_path10.join)(inflateDir, service, "http", rPath + ".api.js");
12294
- (0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(inflatePath), {
12487
+ const inflatePath = (0, import_node_path12.join)(inflateDir, service, "http", rPath + ".api.js");
12488
+ (0, import_node_fs11.mkdirSync)((0, import_node_path12.dirname)(inflatePath), {
12295
12489
  recursive: true
12296
12490
  });
12297
- logger.log("writing [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath));
12298
- (0, import_node_fs9.writeFileSync)(inflatePath, inflatedCode);
12491
+ logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath));
12492
+ (0, import_node_fs11.writeFileSync)(inflatePath, inflatedCode);
12299
12493
  }
12300
12494
  router.use(assertGlobalTampered);
12301
12495
  router.use(module2.handler, r.path, r.method, r.options);
12302
12496
  }
12303
- return resolve20();
12497
+ return resolve24();
12304
12498
  }
12305
12499
  case ".json": {
12306
12500
  const module2 = await importJSONModule(file.filePath, logger);
12307
- const routes = getRoutes((0, import_node_path10.join)("/", (0, import_node_path10.dirname)((0, import_node_path10.relative)(dir, file.filePath))), file.subName + ".json", module2.apiOptions);
12501
+ const routes = getRoutes((0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath))), file.subName + ".json", module2.apiOptions);
12308
12502
  routeFileMap[file.filePath] = {
12309
12503
  routes,
12310
12504
  service,
@@ -12315,17 +12509,17 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12315
12509
  if (inflateDir) {
12316
12510
  if (r.inflatePath) {
12317
12511
  const rPath = r.inflatePath;
12318
- const inflatePath = (0, import_node_path10.join)(inflateDir, service, "static", rPath);
12319
- (0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(inflatePath), {
12512
+ const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", rPath);
12513
+ (0, import_node_fs11.mkdirSync)((0, import_node_path12.dirname)(inflatePath), {
12320
12514
  recursive: true
12321
12515
  });
12322
- if ((0, import_node_fs9.existsSync)(inflatePath) && (0, import_node_fs9.statSync)(inflatePath).isDirectory()) {
12323
- logger.trace("ignoring writing over directory [%s] for file [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath), file.filePath);
12516
+ if ((0, import_node_fs11.existsSync)(inflatePath) && (0, import_node_fs11.statSync)(inflatePath).isDirectory()) {
12517
+ logger.trace("ignoring writing over directory [%s] for file [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath), file.filePath);
12324
12518
  continue;
12325
12519
  }
12326
12520
  const JSON_STATIC = await getJSON({ server: server2 }, null, newURL2(r.path), module2.apiOptions?.basePath, module2.default);
12327
- logger.log("writing [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath));
12328
- (0, import_node_fs9.writeFileSync)(inflatePath, JSON_STATIC);
12521
+ logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath));
12522
+ (0, import_node_fs11.writeFileSync)(inflatePath, JSON_STATIC);
12329
12523
  if (staticFileMap && inflateSea) {
12330
12524
  staticFileMap[file.filePath] = {
12331
12525
  contentType,
@@ -12334,7 +12528,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12334
12528
  previewMethod: "html",
12335
12529
  path: r.path,
12336
12530
  body: Buffer.from(JSON_STATIC),
12337
- inflatePath: inflateDir ? (0, import_node_path10.join)(inflateDir, service, "static", r.inflatePath) : void 0
12531
+ inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", r.inflatePath) : void 0
12338
12532
  };
12339
12533
  }
12340
12534
  }
@@ -12351,11 +12545,11 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12351
12545
  });
12352
12546
  }, r.path, r.method, r.options);
12353
12547
  }
12354
- return resolve20();
12548
+ return resolve24();
12355
12549
  }
12356
12550
  case ".html": {
12357
12551
  const module2 = await importHTMLModule(file.filePath, logger);
12358
- const routes = getRoutes((0, import_node_path10.join)("/", (0, import_node_path10.dirname)((0, import_node_path10.relative)(dir, file.filePath))), file.subName + ".html", module2.apiOptions);
12552
+ const routes = getRoutes((0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath))), file.subName + ".html", module2.apiOptions);
12359
12553
  routeFileMap[file.filePath] = {
12360
12554
  routes,
12361
12555
  service,
@@ -12366,18 +12560,18 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12366
12560
  if (inflateDir) {
12367
12561
  if (r.inflatePath) {
12368
12562
  const rPath = r.inflatePath;
12369
- const inflatePath = (0, import_node_path10.join)(inflateDir, service, "static", rPath);
12370
- (0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(inflatePath), {
12563
+ const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", rPath);
12564
+ (0, import_node_fs11.mkdirSync)((0, import_node_path12.dirname)(inflatePath), {
12371
12565
  recursive: true
12372
12566
  });
12373
- if ((0, import_node_fs9.existsSync)(inflatePath) && (0, import_node_fs9.statSync)(inflatePath).isDirectory()) {
12374
- logger.trace("ignoring writing over directory [%s] for file [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath), file.filePath);
12567
+ if ((0, import_node_fs11.existsSync)(inflatePath) && (0, import_node_fs11.statSync)(inflatePath).isDirectory()) {
12568
+ logger.trace("ignoring writing over directory [%s] for file [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath), file.filePath);
12375
12569
  continue;
12376
12570
  }
12377
12571
  const toRender = typeof module2.default === "function" ? module2.default({ server: server2 }, null) : module2.default;
12378
12572
  const HTML_STATIC = await getHTML(hotreload, { server: server2 }, null, newURL2(r.path), module2.apiOptions?.basePath, await toRender);
12379
- logger.log("writing [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath));
12380
- (0, import_node_fs9.writeFileSync)(inflatePath, HTML_STATIC);
12573
+ logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath));
12574
+ (0, import_node_fs11.writeFileSync)(inflatePath, HTML_STATIC);
12381
12575
  if (staticFileMap && inflateSea) {
12382
12576
  staticFileMap[file.filePath + r.method + r.path] = {
12383
12577
  filePath: file.filePath,
@@ -12386,7 +12580,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12386
12580
  previewMethod: "html",
12387
12581
  path: r.path,
12388
12582
  body: Buffer.from(HTML_STATIC),
12389
- inflatePath: inflateDir ? (0, import_node_path10.join)(inflateDir, service, "static", r.inflatePath) : void 0
12583
+ inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", r.inflatePath) : void 0
12390
12584
  };
12391
12585
  }
12392
12586
  }
@@ -12404,7 +12598,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12404
12598
  });
12405
12599
  }, r.path, r.method, r.options);
12406
12600
  }
12407
- return resolve20();
12601
+ return resolve24();
12408
12602
  }
12409
12603
  case ".min":
12410
12604
  case ".js":
@@ -12417,7 +12611,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12417
12611
  logger
12418
12612
  });
12419
12613
  const contentType = CONTENT_TYPE_MAP[".js"];
12420
- const path = (0, import_node_path10.join)("/", (0, import_node_path10.dirname)((0, import_node_path10.relative)(dir, file.filePath)), file.name + ".js");
12614
+ const path = (0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath)), file.name + ".js");
12421
12615
  routeFileMap[file.filePath] = {
12422
12616
  routes: [{
12423
12617
  method: "GET",
@@ -12427,12 +12621,12 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12427
12621
  previewMethod: "html"
12428
12622
  };
12429
12623
  if (inflateDir) {
12430
- const inflatePath = (0, import_node_path10.join)(inflateDir, service, "static", path);
12431
- (0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(inflatePath), {
12624
+ const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
12625
+ (0, import_node_fs11.mkdirSync)((0, import_node_path12.dirname)(inflatePath), {
12432
12626
  recursive: true
12433
12627
  });
12434
- logger.log("writing [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath));
12435
- (0, import_node_fs9.writeFileSync)(inflatePath, code);
12628
+ logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath));
12629
+ (0, import_node_fs11.writeFileSync)(inflatePath, code);
12436
12630
  if (staticFileMap && inflateSea) {
12437
12631
  staticFileMap[file.filePath] = {
12438
12632
  contentType,
@@ -12441,7 +12635,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12441
12635
  previewMethod: "html",
12442
12636
  path,
12443
12637
  body: Buffer.from(code),
12444
- inflatePath: inflateDir ? (0, import_node_path10.join)(inflateDir, service, "static", path) : void 0
12638
+ inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
12445
12639
  };
12446
12640
  }
12447
12641
  }
@@ -12455,7 +12649,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12455
12649
  body: code
12456
12650
  });
12457
12651
  });
12458
- return resolve20();
12652
+ return resolve24();
12459
12653
  }
12460
12654
  }
12461
12655
  }
@@ -12465,7 +12659,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12465
12659
  case ".html": {
12466
12660
  const code = await inflateMD2HTML(file.filePath, logger);
12467
12661
  const contentType = CONTENT_TYPE_MAP[".html"];
12468
- const path = (0, import_node_path10.join)("/", (0, import_node_path10.dirname)((0, import_node_path10.relative)(dir, file.filePath)), file.name);
12662
+ const path = (0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath)), file.name);
12469
12663
  routeFileMap[file.filePath] = {
12470
12664
  routes: [{
12471
12665
  method: "GET",
@@ -12475,12 +12669,12 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12475
12669
  previewMethod: "html"
12476
12670
  };
12477
12671
  if (inflateDir) {
12478
- const inflatePath = (0, import_node_path10.join)(inflateDir, service, "static", path);
12479
- (0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(inflatePath), {
12672
+ const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
12673
+ (0, import_node_fs11.mkdirSync)((0, import_node_path12.dirname)(inflatePath), {
12480
12674
  recursive: true
12481
12675
  });
12482
- logger.log("writing [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath));
12483
- (0, import_node_fs9.writeFileSync)(inflatePath, code);
12676
+ logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath));
12677
+ (0, import_node_fs11.writeFileSync)(inflatePath, code);
12484
12678
  if (staticFileMap && inflateSea) {
12485
12679
  staticFileMap[file.filePath] = {
12486
12680
  contentType,
@@ -12489,7 +12683,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12489
12683
  previewMethod: "html",
12490
12684
  path,
12491
12685
  body: Buffer.from(code),
12492
- inflatePath: inflateDir ? (0, import_node_path10.join)(inflateDir, service, "static", path) : void 0
12686
+ inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
12493
12687
  };
12494
12688
  }
12495
12689
  }
@@ -12503,7 +12697,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12503
12697
  body: code
12504
12698
  });
12505
12699
  });
12506
- return resolve20();
12700
+ return resolve24();
12507
12701
  }
12508
12702
  }
12509
12703
  }
@@ -12512,7 +12706,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12512
12706
  switch (file.subExt) {
12513
12707
  case ".ignore": {
12514
12708
  logger.warn("ignoring [%s]", file.filePath);
12515
- return resolve20();
12709
+ return resolve24();
12516
12710
  }
12517
12711
  case ".bundle":
12518
12712
  case ".min": {
@@ -12523,7 +12717,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12523
12717
  logger
12524
12718
  });
12525
12719
  const contentType = CONTENT_TYPE_MAP[".js"];
12526
- const path = (0, import_node_path10.join)("/", (0, import_node_path10.dirname)((0, import_node_path10.relative)(dir, file.filePath)), file.name + ".js");
12720
+ const path = (0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath)), file.name + ".js");
12527
12721
  routeFileMap[file.filePath] = {
12528
12722
  routes: [{
12529
12723
  method: "GET",
@@ -12533,12 +12727,12 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12533
12727
  previewMethod: "html"
12534
12728
  };
12535
12729
  if (inflateDir) {
12536
- const inflatePath = (0, import_node_path10.join)(inflateDir, service, "static", path);
12537
- (0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(inflatePath), {
12730
+ const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
12731
+ (0, import_node_fs11.mkdirSync)((0, import_node_path12.dirname)(inflatePath), {
12538
12732
  recursive: true
12539
12733
  });
12540
- logger.log("writing [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath));
12541
- (0, import_node_fs9.writeFileSync)(inflatePath, code);
12734
+ logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath));
12735
+ (0, import_node_fs11.writeFileSync)(inflatePath, code);
12542
12736
  if (staticFileMap && inflateSea) {
12543
12737
  staticFileMap[file.filePath] = {
12544
12738
  contentType,
@@ -12547,7 +12741,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12547
12741
  previewMethod: "html",
12548
12742
  path,
12549
12743
  body: Buffer.from(code),
12550
- inflatePath: inflateDir ? (0, import_node_path10.join)(inflateDir, service, "static", path) : void 0
12744
+ inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
12551
12745
  };
12552
12746
  }
12553
12747
  }
@@ -12561,19 +12755,19 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12561
12755
  body: code
12562
12756
  });
12563
12757
  });
12564
- return resolve20();
12758
+ return resolve24();
12565
12759
  }
12566
12760
  }
12567
12761
  } else if (file.ext === ".bundle") {
12568
12762
  switch (file.subExt) {
12569
12763
  case ".ignore": {
12570
12764
  logger.warn("ignoring [%s]", file.filePath);
12571
- return resolve20();
12765
+ return resolve24();
12572
12766
  }
12573
12767
  case ".css": {
12574
- const code = (0, import_node_fs9.readFileSync)(file.filePath).toString().split("\n").filter((c) => c).filter((c) => c.charAt(0) !== "#").map((cssPath) => (0, import_node_fs9.readFileSync)((0, import_node_path10.resolve)((0, import_node_path10.dirname)(file.filePath), cssPath)).toString()).join("\n");
12768
+ const code = (0, import_node_fs11.readFileSync)(file.filePath).toString().split("\n").filter((c) => c).filter((c) => c.charAt(0) !== "#").map((cssPath) => (0, import_node_fs11.readFileSync)((0, import_node_path12.resolve)((0, import_node_path12.dirname)(file.filePath), cssPath)).toString()).join("\n");
12575
12769
  const contentType = CONTENT_TYPE_MAP[".css"];
12576
- const path = (0, import_node_path10.join)("/", (0, import_node_path10.dirname)((0, import_node_path10.relative)(dir, file.filePath)), file.name);
12770
+ const path = (0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath)), file.name);
12577
12771
  routeFileMap[file.filePath] = {
12578
12772
  routes: [{
12579
12773
  method: "GET",
@@ -12583,12 +12777,12 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12583
12777
  previewMethod: "html"
12584
12778
  };
12585
12779
  if (inflateDir) {
12586
- const inflatePath = (0, import_node_path10.join)(inflateDir, service, "static", path);
12587
- (0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(inflatePath), {
12780
+ const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
12781
+ (0, import_node_fs11.mkdirSync)((0, import_node_path12.dirname)(inflatePath), {
12588
12782
  recursive: true
12589
12783
  });
12590
- logger.log("writing [%s]", (0, import_node_path10.relative)((0, import_node_process6.cwd)(), inflatePath));
12591
- (0, import_node_fs9.writeFileSync)(inflatePath, code);
12784
+ logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath));
12785
+ (0, import_node_fs11.writeFileSync)(inflatePath, code);
12592
12786
  if (staticFileMap && inflateSea) {
12593
12787
  staticFileMap[file.filePath] = {
12594
12788
  contentType,
@@ -12597,7 +12791,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12597
12791
  previewMethod: "html",
12598
12792
  path,
12599
12793
  body: Buffer.from(code),
12600
- inflatePath: inflateDir ? (0, import_node_path10.join)(inflateDir, service, "static", path) : void 0
12794
+ inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
12601
12795
  };
12602
12796
  }
12603
12797
  }
@@ -12611,12 +12805,12 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12611
12805
  body: code
12612
12806
  });
12613
12807
  });
12614
- return resolve20();
12808
+ return resolve24();
12615
12809
  }
12616
12810
  }
12617
12811
  }
12618
12812
  createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
12619
- return resolve20();
12813
+ return resolve24();
12620
12814
  }
12621
12815
  } catch (e) {
12622
12816
  logger.error("error with " + file.filePath);
@@ -12626,7 +12820,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12626
12820
  error: e
12627
12821
  });
12628
12822
  } finally {
12629
- return resolve20();
12823
+ return resolve24();
12630
12824
  }
12631
12825
  })));
12632
12826
  router.use(assertGlobalTampered);
@@ -12637,10 +12831,10 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
12637
12831
  };
12638
12832
  }
12639
12833
  function scanFiles(path, ret = []) {
12640
- const files = (0, import_node_fs9.readdirSync)(path);
12834
+ const files = (0, import_node_fs11.readdirSync)(path).sort();
12641
12835
  for (const file of files) {
12642
- const filePath = (0, import_node_path10.resolve)(path, file);
12643
- if ((0, import_node_fs9.statSync)(filePath).isDirectory()) {
12836
+ const filePath = (0, import_node_path12.resolve)(path, file);
12837
+ if ((0, import_node_fs11.statSync)(filePath).isDirectory()) {
12644
12838
  scanFiles(filePath, ret);
12645
12839
  continue;
12646
12840
  } else {
@@ -12670,9 +12864,9 @@ async function getJSON(req, res, url, basePath, out) {
12670
12864
  }
12671
12865
 
12672
12866
  // src/inflate/setup-ws.ts
12673
- var import_node_path11 = require("node:path");
12674
- var import_node_process7 = require("node:process");
12675
- var import_node_fs10 = require("node:fs");
12867
+ var import_node_path13 = require("node:path");
12868
+ var import_node_process9 = require("node:process");
12869
+ var import_node_fs12 = require("node:fs");
12676
12870
  async function inflateWSConfig(logger, servicePath, service, wsConfigList, inflateDir, errors) {
12677
12871
  const wsPath = getWSConfigPath(servicePath);
12678
12872
  if (wsPath) {
@@ -12682,16 +12876,16 @@ async function inflateWSConfig(logger, servicePath, service, wsConfigList, infla
12682
12876
  if (wsConfig && wsConfigList.filter((c) => c.path === wsConfig.path).length > 0) {
12683
12877
  throw new Error(`ws path [${wsConfig.path}] already defined! from [${wsPath}]`);
12684
12878
  } else if (wsConfigList) {
12685
- logger.debug("importing websocket on path [%s] from [%s]", wsConfig.path, (0, import_node_path11.join)(service, "ws.ts"));
12879
+ logger.debug("importing websocket on path [%s] from [%s]", wsConfig.path, (0, import_node_path13.join)(service, "ws.ts"));
12686
12880
  wsConfigList.push(wsConfig);
12687
12881
  }
12688
12882
  if (inflateDir) {
12689
- const inflatePath = (0, import_node_path11.resolve)(inflateDir, service, "ws.js");
12690
- (0, import_node_fs10.mkdirSync)((0, import_node_path11.dirname)(inflatePath), {
12883
+ const inflatePath = (0, import_node_path13.resolve)(inflateDir, service, "ws.js");
12884
+ (0, import_node_fs12.mkdirSync)((0, import_node_path13.dirname)(inflatePath), {
12691
12885
  recursive: true
12692
12886
  });
12693
- logger.log("writing [%s]", (0, import_node_path11.relative)((0, import_node_process7.cwd)(), inflatePath));
12694
- (0, import_node_fs10.writeFileSync)(inflatePath, await inflateJSX(wsPath, {
12887
+ logger.log("writing [%s]", (0, import_node_path13.relative)((0, import_node_process9.cwd)(), inflatePath));
12888
+ (0, import_node_fs12.writeFileSync)(inflatePath, await inflateJSX(wsPath, {
12695
12889
  embemedJSX: false,
12696
12890
  minify: false,
12697
12891
  useExport: true,
@@ -12712,37 +12906,37 @@ async function inflateWSConfig(logger, servicePath, service, wsConfigList, infla
12712
12906
  }
12713
12907
 
12714
12908
  // src/inflate/inflate-sea.ts
12715
- var import_node_fs11 = require("node:fs");
12716
- var import_node_path12 = require("node:path");
12717
- var import_node_process8 = require("node:process");
12909
+ var import_node_fs13 = require("node:fs");
12910
+ var import_node_path14 = require("node:path");
12911
+ var import_node_process10 = require("node:process");
12718
12912
  async function inflateSeaAssets(logger, inflateDir) {
12719
12913
  const esbuildBinaryBuffer2 = Buffer.from(getAsset("esbuild-binary"));
12720
- if (import_node_process8.platform === "win32") {
12721
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "sea", "esbuild.exe"), esbuildBinaryBuffer2);
12722
- (0, import_node_fs11.chmodSync)((0, import_node_path12.resolve)(inflateDir, "sea", "esbuild.exe"), import_node_fs11.constants.S_IXUSR | import_node_fs11.constants.S_IRUSR | import_node_fs11.constants.S_IWUSR);
12914
+ if (import_node_process10.platform === "win32") {
12915
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "esbuild.exe"), esbuildBinaryBuffer2);
12916
+ (0, import_node_fs13.chmodSync)((0, import_node_path14.resolve)(inflateDir, "sea", "esbuild.exe"), import_node_fs13.constants.S_IXUSR | import_node_fs13.constants.S_IRUSR | import_node_fs13.constants.S_IWUSR);
12723
12917
  } else {
12724
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "sea", "esbuild"), esbuildBinaryBuffer2);
12725
- (0, import_node_fs11.chmodSync)((0, import_node_path12.resolve)(inflateDir, "sea", "esbuild"), import_node_fs11.constants.S_IXUSR | import_node_fs11.constants.S_IRUSR | import_node_fs11.constants.S_IWUSR);
12726
- }
12727
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "sea", "postject.cjs"), Buffer.from(Buffer.from(getAsset("postject.base64.cjs")).toString(), "base64"));
12728
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "sea", "config.json"), Buffer.from(getAsset("sea.basic.config.json")));
12729
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "sea", "run.sh"), Buffer.from(getAsset("app.sh")));
12730
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "sea", "node.sh"), Buffer.from(getAsset("node.sh")));
12731
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "compile.sh"), Buffer.from(Buffer.from(getAsset("compile.base64.sh")).toString(), "base64"));
12732
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "sea", "sign-add.sh"), Buffer.from(getAsset("sign-add.sh")));
12733
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "sea", "sign-remove.sh"), Buffer.from(getAsset("sign-remove.sh")));
12734
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "install-nodejs.sh"), Buffer.from(getAsset("install-nodejs.sh")));
12918
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "esbuild"), esbuildBinaryBuffer2);
12919
+ (0, import_node_fs13.chmodSync)((0, import_node_path14.resolve)(inflateDir, "sea", "esbuild"), import_node_fs13.constants.S_IXUSR | import_node_fs13.constants.S_IRUSR | import_node_fs13.constants.S_IWUSR);
12920
+ }
12921
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "postject.cjs"), Buffer.from(Buffer.from(getAsset("postject.base64.cjs")).toString(), "base64"));
12922
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "config.json"), Buffer.from(getAsset("sea.basic.config.json")));
12923
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "run.sh"), Buffer.from(getAsset("app.sh")));
12924
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "node.sh"), Buffer.from(getAsset("node.sh")));
12925
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "compile.sh"), Buffer.from(Buffer.from(getAsset("compile.base64.sh")).toString(), "base64"));
12926
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "sign-add.sh"), Buffer.from(getAsset("sign-add.sh")));
12927
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "sign-remove.sh"), Buffer.from(getAsset("sign-remove.sh")));
12928
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "install-nodejs.sh"), Buffer.from(getAsset("install-nodejs.sh")));
12735
12929
  }
12736
12930
  async function inflateAppForSea(logger, inflateDir, services) {
12737
12931
  inflateSeaAssets(logger, inflateDir);
12738
- writeFile(logger, (0, import_node_path12.resolve)(inflateDir, "sea", "lib.cjs"), Buffer.from(getAsset("lib.cjs")));
12739
- const WSLIST = services.filter((service) => getWSConfigPath((0, import_node_path12.resolve)((0, import_node_process8.cwd)(), service))).map((service) => {
12932
+ writeFile(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "lib.cjs"), Buffer.from(getAsset("lib.cjs")));
12933
+ const WSLIST = services.filter((service) => getWSConfigPath((0, import_node_path14.resolve)((0, import_node_process10.cwd)(), service))).map((service) => {
12740
12934
  return `(await import("../${service}/ws.js")).default`;
12741
12935
  }).join(",");
12742
- const SERVERCONFIGLIST = services.filter((service) => getServerConfigPath((0, import_node_path12.resolve)((0, import_node_process8.cwd)(), service))).map((service) => {
12936
+ const SERVERCONFIGLIST = services.filter((service) => getServerConfigPath((0, import_node_path14.resolve)((0, import_node_process10.cwd)(), service))).map((service) => {
12743
12937
  return `(await import("../${service}/server.js")).default`;
12744
12938
  }).join(",\n");
12745
- const DBCONFIGLIST = services.filter((service) => getDBConfigPath((0, import_node_path12.resolve)((0, import_node_process8.cwd)(), service))).map((service) => {
12939
+ const DBCONFIGLIST = services.filter((service) => getDBConfigPath((0, import_node_path14.resolve)((0, import_node_process10.cwd)(), service))).map((service) => {
12746
12940
  return `new Promise(async (resolve, reject) => {
12747
12941
  try {
12748
12942
  const db = await dbManager.setupDB((await import("../${service}/db.js")).default);
@@ -12754,10 +12948,10 @@ async function inflateAppForSea(logger, inflateDir, services) {
12754
12948
 
12755
12949
  })`;
12756
12950
  }).join(",");
12757
- writeFile(logger, (0, import_node_path12.join)(inflateDir, "sea", "package.json"), `{ "type": "module", "private": true }`);
12951
+ writeFile(logger, (0, import_node_path14.join)(inflateDir, "sea", "package.json"), `{ "type": "module", "private": true }`);
12758
12952
  writeFile(
12759
12953
  logger,
12760
- (0, import_node_path12.join)(inflateDir, "sea", "app.cjs"),
12954
+ (0, import_node_path14.join)(inflateDir, "sea", "app.cjs"),
12761
12955
  `const { ServerInterfaceImpl, ServerRequestHandler, WebSocketManager, initGlobals, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
12762
12956
 
12763
12957
  async function main() {
@@ -12790,22 +12984,11 @@ async function main() {
12790
12984
  ` : ""}
12791
12985
  app.use(ServerRequestHandler(serverInterface));
12792
12986
  app.use(LoggerHandler());
12793
- ${services.map((service) => {
12794
- const servicePath = getServicePath(service);
12795
- return `${getCORSConfigPath(servicePath) ? `app.use(server.middleware.cors((await import("../${service}/cors.js")).default));` : ""}`;
12796
- })}
12797
- ${services.map((service) => {
12798
- const servicePath = getServicePath(service);
12799
- return `${getAuthConfigPath(servicePath) ? `app.use(server.middleware.session((await import("../${service}/auth.js")).default));` : ""}`;
12800
- })}
12801
- ${services.map((service) => `
12802
- app.use(await (await import("./${(0, import_node_path12.join)(service, "api-router.js")}")).setupRouter());
12803
- app.use(await (await import("./${(0, import_node_path12.join)(service, "static-router.js")}")).setupRouter())`).join("\n")}
12987
+ ${services.map((service) => `app.use(await (await import("./${(0, import_node_path14.join)(service, "router.js")}")).setupRouter());`).join("\n")}
12804
12988
  ${SERVERCONFIGLIST ? `
12805
12989
  await Promise.all([${SERVERCONFIGLIST}].filter(config=>config.load).map(config=>config.load(serverInterface)));
12806
12990
  ` : ""}
12807
12991
 
12808
-
12809
12992
  await app.listen(PORT);
12810
12993
  ${SERVERCONFIGLIST ? `
12811
12994
  await Promise.all([${SERVERCONFIGLIST}].filter(config=>config.start).map(config=>config.start(serverInterface)));` : ""}
@@ -12817,43 +13000,66 @@ main().catch(e=>console.error(e));
12817
13000
  async function inflateServiceForSea(logger, inflateDir, service, servicePath, serviceRouteFileMap, serviceStaticFileMap) {
12818
13001
  const migrationsFolderPath = getMigrationsPath(servicePath);
12819
13002
  const serviceMigrations = migrationsFolderPath ? lib_exports.getSortedMigrations(migrationsFolderPath) : [];
12820
- writeFile(logger, (0, import_node_path12.join)(inflateDir, "sea", service, "api-router.js"), `import { appendAPIModule, Router } from "./../lib.cjs";
13003
+ writeFile(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "router.js"), `import { appendAPIModule, Router } from "./../lib.cjs";
12821
13004
 
12822
13005
  export async function setupRouter() {
12823
13006
  const router = new Router();
12824
-
13007
+ ${getErrorConfigPath(servicePath) ? `
13008
+ const errorConfig = (await import("../../${service}/catch.js")).default;
13009
+ if(errorConfig && errorConfig.catch) {
13010
+ for(const m of errorConfig.catch) {
13011
+ router.catch(m);
13012
+ }
13013
+ }` : ""}
13014
+ ${getCORSConfigPath(servicePath) ? ` router.use(server.middleware.cors((await import("../../${service}/cors.js")).default));` : ""}
13015
+ ${getAuthConfigPath(servicePath) ? ` router.use(server.middleware.session((await import("../../${service}/auth.js")).default));` : ""}
13016
+ ${getMiddlewareConfigPath(servicePath) ? `
13017
+ const middlewareConfig = (await import("../../${service}/middleware.js")).default;
13018
+ if(middlewareConfig && middlewareConfig.middleware) {
13019
+ for(const m of middlewareConfig.middleware) {
13020
+ router.use(m);
13021
+ }
13022
+ }` : ""}
12825
13023
  ${Object.keys(serviceRouteFileMap).map((filePath) => serviceRouteFileMap[filePath]).filter((data) => data.previewMethod === "api").map((data) => data.routes.map((r) => {
12826
13024
  const rPath = r.inflatePath;
12827
13025
  if (rPath) {
12828
- const apiInflatedPath = (0, import_node_path12.join)("..", "..", service, "http", rPath + ".api.js");
13026
+ const apiInflatedPath = (0, import_node_path14.join)("..", "..", service, "http", rPath + ".api.js");
12829
13027
  return ` await appendAPIModule(router, "../../${service}/http", "./${apiInflatedPath}", (await import("./${apiInflatedPath}")).default);`;
12830
13028
  } else {
12831
13029
  return "";
12832
13030
  }
12833
13031
  }).filter((l) => l)[0]).join("\n")}
13032
+ router.use(await (await import("./static-router.js")).setupRouter())
12834
13033
 
13034
+ ${getMiddlewareConfigPath(servicePath) ? `
13035
+ if(middlewareConfig && middlewareConfig.post) {
13036
+ for(const m of middlewareConfig.post) {
13037
+ router.use(m);
13038
+ }
13039
+ }` : ""}
13040
+
12835
13041
  return router;
12836
13042
  }`);
12837
- writeFile(logger, (0, import_node_path12.join)(inflateDir, "sea", service, "migration-up.js"), `import { migration } from "./../lib.cjs";
13043
+ writeFile(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "migration-up.js"), `import { migration } from "./../lib.cjs";
12838
13044
 
12839
13045
  export async function runMigrations(db) {
12840
13046
  await migration.init(db);
12841
13047
  ${serviceMigrations.map((file) => {
12842
- const name = `${file.substring(0, file.length - (0, import_node_path12.extname)(file).length)}`;
13048
+ const name = `${file.substring(0, file.length - (0, import_node_path14.extname)(file).length)}`;
12843
13049
  return ` await migration.up.module(db, "${name}", (await import("../../${service}/migration/${name}.js")).default)`;
12844
13050
  }).join("\n")}
12845
13051
  }`);
12846
- writeFile(logger, (0, import_node_path12.join)(inflateDir, "sea", service, "migration-down.js"), `import { migration } from "./../lib.cjs";
13052
+ writeFile(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "migration-down.js"), `import { migration } from "./../lib.cjs";
12847
13053
 
12848
13054
  export async function runMigrations(db) {
12849
13055
  await migration.init(db);
12850
13056
  ${serviceMigrations.reverse().map((file) => {
12851
- const name = `${file.substring(0, file.length - (0, import_node_path12.extname)(file).length)}`;
13057
+ const name = `${file.substring(0, file.length - (0, import_node_path14.extname)(file).length)}`;
12852
13058
  return ` await migration.down.module(db, "${name}", (await import("../../${service}/migration/${name}.js")).default)`;
12853
13059
  }).join("\n")}
12854
13060
  }`);
12855
13061
  const staticFiles = Object.keys(serviceStaticFileMap);
12856
- writeFile(logger, (0, import_node_path12.join)(inflateDir, "sea", service, "static-router.js"), `import { appendAPIModule, Router } from "./../lib.cjs";
13062
+ writeFile(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "static-router.js"), `import { appendAPIModule, Router } from "./../lib.cjs";
12857
13063
 
12858
13064
  export async function setupRouter() {
12859
13065
  const router = new Router();
@@ -12874,17 +13080,17 @@ ${staticFiles.map((filePath) => {
12874
13080
  }`);
12875
13081
  }
12876
13082
  function writeFile(logger, path, buffer) {
12877
- logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), path));
12878
- (0, import_node_fs11.mkdirSync)((0, import_node_path12.dirname)(path), {
13083
+ logger.log("writing [%s]", (0, import_node_path14.relative)((0, import_node_process10.cwd)(), path));
13084
+ (0, import_node_fs13.mkdirSync)((0, import_node_path14.dirname)(path), {
12879
13085
  recursive: true
12880
13086
  });
12881
- (0, import_node_fs11.writeFileSync)(path, buffer);
13087
+ (0, import_node_fs13.writeFileSync)(path, buffer);
12882
13088
  }
12883
13089
 
12884
13090
  // src/inflate/setup-log.ts
12885
- var import_node_path13 = require("node:path");
12886
- var import_node_fs12 = require("node:fs");
12887
- var import_node_process9 = require("node:process");
13091
+ var import_node_path15 = require("node:path");
13092
+ var import_node_fs14 = require("node:fs");
13093
+ var import_node_process11 = require("node:process");
12888
13094
  async function setupLogConfig(logger, servicePath, service, logConfigMap, inflateDir, errors) {
12889
13095
  const logPath = getLogConfigPath(servicePath);
12890
13096
  if (logPath) {
@@ -12892,12 +13098,12 @@ async function setupLogConfig(logger, servicePath, service, logConfigMap, inflat
12892
13098
  const logConfig = await importLogConfigModule(logPath, logger);
12893
13099
  logConfigMap[service] = logConfig;
12894
13100
  if (inflateDir) {
12895
- const inflatePath = (0, import_node_path13.resolve)(inflateDir, service, "log.js");
12896
- (0, import_node_fs12.mkdirSync)((0, import_node_path13.dirname)(inflatePath), {
13101
+ const inflatePath = (0, import_node_path15.resolve)(inflateDir, service, "log.js");
13102
+ (0, import_node_fs14.mkdirSync)((0, import_node_path15.dirname)(inflatePath), {
12897
13103
  recursive: true
12898
13104
  });
12899
- logger.log("writing [%s]", (0, import_node_path13.relative)((0, import_node_process9.cwd)(), inflatePath));
12900
- (0, import_node_fs12.writeFileSync)(inflatePath, await inflateJSX(logPath, {
13105
+ logger.log("writing [%s]", (0, import_node_path15.relative)((0, import_node_process11.cwd)(), inflatePath));
13106
+ (0, import_node_fs14.writeFileSync)(inflatePath, await inflateJSX(logPath, {
12901
13107
  embemedJSX: false,
12902
13108
  minify: false,
12903
13109
  useExport: true,
@@ -12915,6 +13121,330 @@ async function setupLogConfig(logger, servicePath, service, logConfigMap, inflat
12915
13121
  }
12916
13122
  }
12917
13123
 
13124
+ // src/inflate/setup.doc.ts
13125
+ var import_node_path16 = require("node:path");
13126
+ var import_node_fs15 = require("node:fs");
13127
+ var import_node_process12 = require("node:process");
13128
+
13129
+ // src/bin/doc-md.ts
13130
+ async function getMDDoc(args, logger) {
13131
+ const pathList = Object.keys(args.jsonDoc).sort();
13132
+ let outMD = "";
13133
+ const tableIndexItems = [];
13134
+ for (const path of pathList) {
13135
+ const pathData = args.jsonDoc[path];
13136
+ const methods = Object.keys(pathData);
13137
+ for (const method of methods) {
13138
+ if (method) {
13139
+ const apiDataList = pathData[method];
13140
+ for (const apiData of apiDataList) {
13141
+ tableIndexItems.push({
13142
+ apiData
13143
+ });
13144
+ outMD += `## ${apiData.identifier}
13145
+
13146
+ `;
13147
+ outMD += `${args.showFilePath && apiData.___filePath ? apiData.___filePath + "\n\n" : ""}`;
13148
+ if (apiData.name) {
13149
+ outMD += `${apiData.name}
13150
+
13151
+ `;
13152
+ }
13153
+ if (apiData.description) {
13154
+ outMD += `${apiData.description}
13155
+
13156
+ `;
13157
+ }
13158
+ outMD += `[${method}] ${path}
13159
+
13160
+ `;
13161
+ outMD += `[${path}](${path})
13162
+
13163
+ `;
13164
+ if (apiData.policy) {
13165
+ outMD += `### policy
13166
+
13167
+ `;
13168
+ outMD += policyToString(apiData.policy);
13169
+ }
13170
+ if (apiData.request) {
13171
+ const requestOutMD = parserToString(apiData.request);
13172
+ outMD += requestOutMD !== "" ? `### request
13173
+
13174
+ ${requestOutMD}` : "";
13175
+ }
13176
+ if (apiData.response && typeof apiData.response !== "boolean") {
13177
+ const responseOutMD = parserToString(apiData.response);
13178
+ outMD += responseOutMD !== "" ? `### response
13179
+
13180
+ ${responseOutMD}` : "";
13181
+ }
13182
+ }
13183
+ }
13184
+ }
13185
+ }
13186
+ const indexTable = getIndexTable(tableIndexItems);
13187
+ return `${indexTable}
13188
+
13189
+ ${outMD}`;
13190
+ }
13191
+ function getIndexTable(data) {
13192
+ return `${data.map((api) => `[${api.apiData.identifier}](#${api.apiData.identifier.toLocaleLowerCase()})${api.apiData.name || api.apiData.description ? `
13193
+
13194
+ ${api.apiData.name ? api.apiData.name + " " : ""}${api.apiData.description ? api.apiData.description : ""}` : ""}`).join("\n\n")}`;
13195
+ }
13196
+ function policyToString(policy) {
13197
+ let outMD = "| groups | policy |\n";
13198
+ outMD += "|--------|--------|\n";
13199
+ outMD += `| ${(policy.groups instanceof Array ? policy.groups : [policy.groups]).join(",")} | ${policy.groupPolicy} |
13200
+
13201
+ `;
13202
+ return outMD;
13203
+ }
13204
+ function parserToString(parser4) {
13205
+ let outMD = "";
13206
+ if (parser4.status) {
13207
+ outMD += `#### status
13208
+
13209
+ ${parser4.status instanceof Array ? parser4.status.join(",") : parser4.status}
13210
+
13211
+ `;
13212
+ }
13213
+ if (parser4.params && typeof parser4.params !== "boolean") {
13214
+ outMD += `#### path params
13215
+
13216
+ `;
13217
+ outMD += parserPartToString(parser4.params, parser4.paramsMode);
13218
+ }
13219
+ if (parser4.headers) {
13220
+ outMD += `#### headers
13221
+
13222
+ `;
13223
+ outMD += parserPartToString(parser4.headers, parser4.headersMode);
13224
+ }
13225
+ if (parser4.query && parser4.query !== true) {
13226
+ outMD += `#### query
13227
+
13228
+ `;
13229
+ outMD += parserPartToString(parser4.query, parser4.queryMode);
13230
+ }
13231
+ if (parser4.body && parser4.body !== true) {
13232
+ outMD += `#### body
13233
+
13234
+ `;
13235
+ outMD += parserPartToString(parser4.body, parser4.bodyMode);
13236
+ }
13237
+ return outMD;
13238
+ }
13239
+ function parserPartToString(arg, mode) {
13240
+ if (arg === false) {
13241
+ return "not allowed";
13242
+ }
13243
+ let outMD = "";
13244
+ let maxTabulation = 1;
13245
+ const parsers = arg instanceof Array ? arg : typeof arg === "string" ? [arg] : [arg];
13246
+ for (const parser4 of parsers) {
13247
+ const ret = internalParserToString(parser4);
13248
+ if (ret.maxTabulation > maxTabulation) {
13249
+ maxTabulation = ret.maxTabulation;
13250
+ }
13251
+ outMD += `| | | | ${getTabulation(ret.maxTabulation * 2)}
13252
+ `;
13253
+ outMD += `|--------|-------|-------|${getTabulation(ret.maxTabulation * 2, true)}
13254
+ `;
13255
+ outMD += `${ret.out}
13256
+
13257
+ `;
13258
+ }
13259
+ return outMD;
13260
+ }
13261
+ function internalParserToString(parser4, tabulation = 1) {
13262
+ let outMD = "";
13263
+ let maxTabulation = tabulation;
13264
+ if (typeof parser4 === "string") {
13265
+ outMD += `${getTabulation(tabulation)}${parser4}|
13266
+ `;
13267
+ } else {
13268
+ const attrNames = Object.keys(parser4);
13269
+ for (const name of attrNames) {
13270
+ const p = parser4[name];
13271
+ const description = typeof p === "string" ? "" : p.description ? p.description : "";
13272
+ if (typeof p === "string") {
13273
+ outMD += `${getTabulation(tabulation)}${name} | ${p}|
13274
+ `;
13275
+ } else if (p.type.toLocaleLowerCase() === "object" || p.type.toLocaleLowerCase() === "object?") {
13276
+ const rString = p.required === false || p.type.toLocaleLowerCase() === "object?" ? "?" : "";
13277
+ outMD += `${getTabulation(tabulation)}${name} | object${rString}| ${description}|
13278
+ `;
13279
+ const ret = parserBaseObjectTypeToString(p, tabulation + 1);
13280
+ if (maxTabulation < ret.maxTabulation) {
13281
+ maxTabulation = ret.maxTabulation;
13282
+ }
13283
+ outMD += `${ret.out}`;
13284
+ } else if (p.type.toLocaleLowerCase() === "dict" || p.type.toLocaleLowerCase() === "dict?") {
13285
+ const rString = p.required === false || p.type.toLocaleLowerCase() === "dict?" ? "?" : "";
13286
+ outMD += `${getTabulation(tabulation)}${name} | Dict\\<${p.dictType}>${rString}| ${description}|
13287
+ `;
13288
+ if (p.dictType === "object") {
13289
+ const ret = parserBaseObjectTypeToString(p, tabulation + 1);
13290
+ if (maxTabulation < ret.maxTabulation) {
13291
+ maxTabulation = ret.maxTabulation;
13292
+ }
13293
+ outMD += `${ret.out}`;
13294
+ }
13295
+ } else if (p.type.toLocaleLowerCase() === "array" || p.type.toLocaleLowerCase() === "array?") {
13296
+ const rString = p.required === false || p.type.toLocaleLowerCase() === "array?" ? "?" : "";
13297
+ outMD += `${getTabulation(tabulation)}${name} | Array\\<${p.arrayType}>${rString}| ${description}|
13298
+ `;
13299
+ if (p.arrayType.toLocaleLowerCase() === "object") {
13300
+ const ret = parserBaseObjectTypeToString(p, tabulation + 1);
13301
+ if (maxTabulation < ret.maxTabulation) {
13302
+ maxTabulation = ret.maxTabulation;
13303
+ }
13304
+ outMD += `${ret.out}`;
13305
+ }
13306
+ } else if (p.type.toLocaleLowerCase() === "regex") {
13307
+ outMD += `${getTabulation(tabulation)}${name} | ${p.regex}| ${description}|
13308
+ `;
13309
+ } else if (p.type.toLocaleLowerCase() === "regex?") {
13310
+ outMD += `${getTabulation(tabulation)}${name} | ${p.regex}?| ${description}|
13311
+ `;
13312
+ } else if (p.type.toLocaleLowerCase() === "enum") {
13313
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}| ${description}|
13314
+ `;
13315
+ outMD += `${getTabulation(tabulation + 1)}| ${p.enumValues?.join(",")}|
13316
+ `;
13317
+ if (maxTabulation < tabulation + 1) {
13318
+ maxTabulation = tabulation + 1;
13319
+ }
13320
+ } else if (p.type.toLocaleLowerCase() === "enum?") {
13321
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}?| ${description}|
13322
+ `;
13323
+ outMD += `${getTabulation(tabulation + 1)}| ${p.enumValues?.join(",")}|
13324
+ `;
13325
+ if (maxTabulation < tabulation + 1) {
13326
+ maxTabulation = tabulation + 1;
13327
+ }
13328
+ } else {
13329
+ const rString = p.required === false ? "?" : "";
13330
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}${rString}| ${description}|
13331
+ `;
13332
+ }
13333
+ }
13334
+ }
13335
+ return {
13336
+ out: outMD,
13337
+ maxTabulation
13338
+ };
13339
+ }
13340
+ function parserBaseObjectTypeToString(arg, tabulation) {
13341
+ const options = arg.properties ? arg.properties : {};
13342
+ return internalParserToString(options, tabulation + 1);
13343
+ }
13344
+ function getTabulation(n, header = false) {
13345
+ let out = "";
13346
+ for (let i = 0; i < n; i++) {
13347
+ out += header ? "-|" : "| ";
13348
+ }
13349
+ return out;
13350
+ }
13351
+
13352
+ // src/bin/generate-doc.ts
13353
+ async function getDocOutput(router, fileMap, generateDocAll, generateDocType) {
13354
+ const fileMapAPIRouteList = Object.keys(fileMap).map((f) => fileMap[f]).filter((fMap) => fMap.previewMethod === "api").map((fMap) => fMap.routes);
13355
+ const jsonDoc = router.getJSONDoc();
13356
+ if (!generateDocAll) {
13357
+ Object.keys(jsonDoc).forEach((path) => {
13358
+ const methods = Object.keys(jsonDoc[path]);
13359
+ methods.forEach((method) => {
13360
+ const data = jsonDoc[path][method];
13361
+ if (fileMapAPIRouteList.filter((f) => {
13362
+ for (const r of f) {
13363
+ if (r.method === String(method).toUpperCase() && r.path === path) {
13364
+ return true;
13365
+ }
13366
+ }
13367
+ return false;
13368
+ }).length === 0) {
13369
+ delete jsonDoc[path][method];
13370
+ } else {
13371
+ }
13372
+ });
13373
+ });
13374
+ }
13375
+ switch (generateDocType) {
13376
+ case "JSON":
13377
+ return JSON.stringify(jsonDoc, void 0, 2);
13378
+ break;
13379
+ case "MD":
13380
+ return await getMDDoc({ showFilePath: true, jsonDoc });
13381
+ break;
13382
+ case "HTML":
13383
+ const md = await getMDDoc({ showFilePath: true, jsonDoc });
13384
+ const html = inflateMDString2HTML(md);
13385
+ return html;
13386
+ break;
13387
+ default:
13388
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
13389
+ }
13390
+ }
13391
+
13392
+ // src/inflate/setup.doc.ts
13393
+ async function setupDoc(logger, servicePath, service, mainRouter, fileMap, inflateDir, errors) {
13394
+ const docPath = getDocConfigPath(servicePath);
13395
+ if (docPath) {
13396
+ try {
13397
+ const docModule = await importDocConfigModule(docPath, logger);
13398
+ logger.debug("setting up error handling from [%s]", (0, import_node_path16.join)(service, (0, import_node_path16.basename)(docPath)));
13399
+ if (docModule && docModule.publish) {
13400
+ const paths = Object.keys(docModule.publish);
13401
+ for (const path of paths) {
13402
+ const config = docModule.publish[path];
13403
+ const body = await getDocOutput(mainRouter, fileMap, config.all, config.type);
13404
+ mainRouter.get(path, async (_, res) => {
13405
+ switch (config.type) {
13406
+ case "MD": {
13407
+ const contentType = CONTENT_TYPE_MAP[".md"];
13408
+ return await res.asyncEnd({
13409
+ headers: {
13410
+ "content-type": contentType
13411
+ },
13412
+ status: 200,
13413
+ body
13414
+ });
13415
+ }
13416
+ case "JSON": {
13417
+ return await res.json(body);
13418
+ }
13419
+ case "HTML": {
13420
+ return await res.html(body);
13421
+ }
13422
+ default:
13423
+ return true;
13424
+ }
13425
+ });
13426
+ if (inflateDir) {
13427
+ const inflatePath = (0, import_node_path16.join)(inflateDir, service, "static", path);
13428
+ (0, import_node_fs15.mkdirSync)((0, import_node_path16.dirname)(inflatePath), {
13429
+ recursive: true
13430
+ });
13431
+ logger.log("writing [%s]", (0, import_node_path16.relative)((0, import_node_process12.cwd)(), inflatePath));
13432
+ (0, import_node_fs15.writeFileSync)(inflatePath, body);
13433
+ }
13434
+ }
13435
+ }
13436
+ } catch (e) {
13437
+ errors.push({
13438
+ filePath: docPath,
13439
+ error: e
13440
+ });
13441
+ logger.error("error with " + docPath);
13442
+ logger.error(e);
13443
+ }
13444
+ }
13445
+ return null;
13446
+ }
13447
+
12918
13448
  // src/inflate/inflate.ts
12919
13449
  async function inflateApp({
12920
13450
  serverInterface,
@@ -12942,6 +13472,7 @@ async function inflateApp({
12942
13472
  ...routeFileMap,
12943
13473
  ...serviceRouteFileMap
12944
13474
  };
13475
+ await setupDoc(logger, servicePath, service, router, routeFileMap, inflateDir, errors);
12945
13476
  await inflateWSConfig(logger, servicePath, service, wsConfigList, inflateSea ? inflateDir : void 0, errors);
12946
13477
  if (inflateDir && inflateSea) {
12947
13478
  await inflateServiceForSea(logger, inflateDir, service, servicePath, serviceRouteFileMap, serviceStaticFileMap);
@@ -12955,9 +13486,9 @@ async function inflateApp({
12955
13486
  }
12956
13487
 
12957
13488
  // src/inflate/setup-server-config.ts
12958
- var import_node_fs13 = require("node:fs");
12959
- var import_node_path14 = require("node:path");
12960
- var import_node_process10 = require("node:process");
13489
+ var import_node_fs16 = require("node:fs");
13490
+ var import_node_path17 = require("node:path");
13491
+ var import_node_process13 = require("node:process");
12961
13492
  async function setupServerConfig(logger, servicePath, service, serverConfigMap, inflateDir, errors) {
12962
13493
  const serverPath = getServerConfigPath(servicePath);
12963
13494
  if (serverPath) {
@@ -12965,12 +13496,12 @@ async function setupServerConfig(logger, servicePath, service, serverConfigMap,
12965
13496
  const serverConfig = await importServerConfigModule(serverPath, logger);
12966
13497
  serverConfigMap[service] = serverConfig;
12967
13498
  if (inflateDir) {
12968
- const inflatePath = (0, import_node_path14.resolve)(inflateDir, service, "server.js");
12969
- (0, import_node_fs13.mkdirSync)((0, import_node_path14.dirname)(inflatePath), {
13499
+ const inflatePath = (0, import_node_path17.resolve)(inflateDir, service, "server.js");
13500
+ (0, import_node_fs16.mkdirSync)((0, import_node_path17.dirname)(inflatePath), {
12970
13501
  recursive: true
12971
13502
  });
12972
- logger.log("writing [%s]", (0, import_node_path14.relative)((0, import_node_process10.cwd)(), inflatePath));
12973
- (0, import_node_fs13.writeFileSync)(inflatePath, await inflateJSX(serverPath, {
13503
+ logger.log("writing [%s]", (0, import_node_path17.relative)((0, import_node_process13.cwd)(), inflatePath));
13504
+ (0, import_node_fs16.writeFileSync)(inflatePath, await inflateJSX(serverPath, {
12974
13505
  embemedJSX: false,
12975
13506
  minify: false,
12976
13507
  useExport: true,
@@ -13007,8 +13538,8 @@ var ws_default = {
13007
13538
  // editor/server.ts
13008
13539
  var import_node_crypto4 = require("node:crypto");
13009
13540
  init_constants();
13010
- var import_node_fs14 = require("node:fs");
13011
- var import_node_path15 = require("node:path");
13541
+ var import_node_fs17 = require("node:fs");
13542
+ var import_node_path18 = require("node:path");
13012
13543
 
13013
13544
  // editor/auth.ts
13014
13545
  var ADMIN_EDITOR_AUTH_KEY = "$$ADMIN_EDITOR_AUTH_KEY$$";
@@ -13058,10 +13589,10 @@ var server_default = {
13058
13589
  if (serverInterface?.isPrimaryWorker()) {
13059
13590
  const cache = adminInterface ? adminInterface.getCache() : serverInterface.cache;
13060
13591
  if (!cache.has(ADMIN_EDITOR_AUTH_KEY)) {
13061
- const adminKEYPath = (0, import_node_path15.resolve)(".admin_key");
13062
- if ((0, import_node_fs14.existsSync)(adminKEYPath)) {
13063
- serverInterface.logger.warn("loading static ADMIN_KEY from [%s]", (0, import_node_path15.relative)(process.cwd(), adminKEYPath));
13064
- cache.set(ADMIN_EDITOR_AUTH_KEY, (0, import_node_fs14.readFileSync)(adminKEYPath).toString().trim());
13592
+ const adminKEYPath = (0, import_node_path18.resolve)(".admin_key");
13593
+ if ((0, import_node_fs17.existsSync)(adminKEYPath)) {
13594
+ serverInterface.logger.warn("loading static ADMIN_KEY from [%s]", (0, import_node_path18.relative)(process.cwd(), adminKEYPath));
13595
+ cache.set(ADMIN_EDITOR_AUTH_KEY, (0, import_node_fs17.readFileSync)(adminKEYPath).toString().trim());
13065
13596
  } else {
13066
13597
  cache.set(ADMIN_EDITOR_AUTH_KEY, (0, import_node_crypto4.randomUUID)());
13067
13598
  }
@@ -13171,8 +13702,8 @@ function getHandler(router) {
13171
13702
  }
13172
13703
 
13173
13704
  // src/common/watch.ts
13174
- var import_node_fs20 = require("node:fs");
13175
- var import_node_path23 = require("node:path");
13705
+ var import_node_fs23 = require("node:fs");
13706
+ var import_node_path26 = require("node:path");
13176
13707
  async function watchAndServer(app) {
13177
13708
  let timeout;
13178
13709
  const watchLogger = app.logger;
@@ -13201,13 +13732,13 @@ async function watchAndServer(app) {
13201
13732
  }, 2e3);
13202
13733
  }
13203
13734
  function watchDir(toWatch) {
13204
- const files = (0, import_node_fs20.existsSync)(toWatch) ? (0, import_node_fs20.readdirSync)(toWatch) : [];
13735
+ const files = (0, import_node_fs23.existsSync)(toWatch) ? (0, import_node_fs23.readdirSync)(toWatch) : [];
13205
13736
  for (const file of files) {
13206
- const filePath = (0, import_node_path23.resolve)(toWatch, file);
13207
- if ((0, import_node_fs20.statSync)(filePath).isDirectory()) {
13737
+ const filePath = (0, import_node_path26.resolve)(toWatch, file);
13738
+ if ((0, import_node_fs23.statSync)(filePath).isDirectory()) {
13208
13739
  watchDir(filePath);
13209
13740
  } else {
13210
- watchers.push((0, import_node_fs20.watch)(filePath, watchHandler));
13741
+ watchers.push((0, import_node_fs23.watch)(filePath, watchHandler));
13211
13742
  }
13212
13743
  }
13213
13744
  }
@@ -13220,7 +13751,7 @@ async function watchAndServer(app) {
13220
13751
  function reWatch() {
13221
13752
  stopWatch();
13222
13753
  for (const service of app.options.services) {
13223
- const toWatch = (0, import_node_path23.resolve)(process.cwd(), service);
13754
+ const toWatch = (0, import_node_path26.resolve)(process.cwd(), service);
13224
13755
  watchDir(toWatch);
13225
13756
  }
13226
13757
  }
@@ -13234,30 +13765,30 @@ async function watchAndServer(app) {
13234
13765
  }
13235
13766
 
13236
13767
  // src/common/exit.ts
13237
- var import_node_fs21 = require("node:fs");
13238
- var import_node_path24 = require("node:path");
13768
+ var import_node_fs24 = require("node:fs");
13769
+ var import_node_path27 = require("node:path");
13239
13770
  function cleanJSX(app) {
13240
13771
  app.logger?.trace("trying to clean up esbuild installation at [%s]", getESBuildBinaryPath());
13241
- if ((0, import_node_fs21.existsSync)(getESBuildBinaryPath())) {
13242
- (0, import_node_fs21.unlinkSync)(getESBuildBinaryPath());
13772
+ if ((0, import_node_fs24.existsSync)(getESBuildBinaryPath())) {
13773
+ (0, import_node_fs24.unlinkSync)(getESBuildBinaryPath());
13243
13774
  }
13244
13775
  if (CLEAR_JSX_CACHE) {
13245
13776
  app.logger?.trace("trying to clean up jsx.js installation at [%s]", getJSXJSPath());
13246
- if ((0, import_node_fs21.existsSync)(getJSXJSPath())) {
13247
- (0, import_node_fs21.unlinkSync)(getJSXJSPath());
13777
+ if ((0, import_node_fs24.existsSync)(getJSXJSPath())) {
13778
+ (0, import_node_fs24.unlinkSync)(getJSXJSPath());
13248
13779
  }
13249
- const buildParendDir = (0, import_node_path24.resolve)(JSX_TMP_DIR, String(process.pid));
13780
+ const buildParendDir = (0, import_node_path27.resolve)(JSX_TMP_DIR, String(process.pid));
13250
13781
  app.logger?.trace("trying to clean up jsx build/import folders at [%s]", buildParendDir);
13251
- const buildDir = (0, import_node_path24.resolve)(buildParendDir, "build");
13252
- const importDir = (0, import_node_path24.resolve)(buildParendDir, "import");
13253
- if ((0, import_node_fs21.existsSync)(buildDir)) {
13254
- (0, import_node_fs21.rmdirSync)(buildDir);
13782
+ const buildDir = (0, import_node_path27.resolve)(buildParendDir, "build");
13783
+ const importDir = (0, import_node_path27.resolve)(buildParendDir, "import");
13784
+ if ((0, import_node_fs24.existsSync)(buildDir)) {
13785
+ (0, import_node_fs24.rmdirSync)(buildDir);
13255
13786
  }
13256
- if ((0, import_node_fs21.existsSync)(importDir)) {
13257
- (0, import_node_fs21.rmdirSync)(importDir);
13787
+ if ((0, import_node_fs24.existsSync)(importDir)) {
13788
+ (0, import_node_fs24.rmdirSync)(importDir);
13258
13789
  }
13259
- if ((0, import_node_fs21.existsSync)(buildParendDir)) {
13260
- (0, import_node_fs21.rmdirSync)(buildParendDir);
13790
+ if ((0, import_node_fs24.existsSync)(buildParendDir)) {
13791
+ (0, import_node_fs24.rmdirSync)(buildParendDir);
13261
13792
  }
13262
13793
  }
13263
13794
  }
@@ -13298,9 +13829,9 @@ function setupExitHandlers(app) {
13298
13829
  }
13299
13830
 
13300
13831
  // src/inflate/setup-db.ts
13301
- var import_node_path25 = require("node:path");
13302
- var import_node_fs22 = require("node:fs");
13303
- var import_node_process12 = require("node:process");
13832
+ var import_node_path28 = require("node:path");
13833
+ var import_node_fs25 = require("node:fs");
13834
+ var import_node_process15 = require("node:process");
13304
13835
  async function inflateDBConfig(logger, service, dbConfigList, inflateDir, errors) {
13305
13836
  const servicePath = getServicePath(service);
13306
13837
  const dbConfigPath = getDBConfigPath(servicePath);
@@ -13316,12 +13847,12 @@ async function inflateDBConfig(logger, service, dbConfigList, inflateDir, errors
13316
13847
  }
13317
13848
  if (config) {
13318
13849
  if (inflateDir) {
13319
- const inflatePath = (0, import_node_path25.resolve)(inflateDir, service, "db.js");
13320
- (0, import_node_fs22.mkdirSync)((0, import_node_path25.dirname)(inflatePath), {
13850
+ const inflatePath = (0, import_node_path28.resolve)(inflateDir, service, "db.js");
13851
+ (0, import_node_fs25.mkdirSync)((0, import_node_path28.dirname)(inflatePath), {
13321
13852
  recursive: true
13322
13853
  });
13323
- logger.log("writing [%s]", (0, import_node_path25.relative)((0, import_node_process12.cwd)(), inflatePath));
13324
- (0, import_node_fs22.writeFileSync)(inflatePath, await inflateJSX(dbConfigPath, {
13854
+ logger.log("writing [%s]", (0, import_node_path28.relative)((0, import_node_process15.cwd)(), inflatePath));
13855
+ (0, import_node_fs25.writeFileSync)(inflatePath, await inflateJSX(dbConfigPath, {
13325
13856
  embemedJSX: false,
13326
13857
  minify: false,
13327
13858
  useExport: true,
@@ -13350,7 +13881,7 @@ async function inflateDBMigrations(logger, service, dbName, inflateDir, errors)
13350
13881
  const serviceMigrations = lib_exports.getSortedMigrations(migrationsFolderPath);
13351
13882
  const migrationModules = [];
13352
13883
  for (const migrationName of serviceMigrations) {
13353
- const migrationPath = (0, import_node_path25.resolve)(migrationsFolderPath, migrationName);
13884
+ const migrationPath = (0, import_node_path28.resolve)(migrationsFolderPath, migrationName);
13354
13885
  try {
13355
13886
  const migrationModule = await importMigrationModule(migrationPath);
13356
13887
  migrationModules.push({
@@ -13360,12 +13891,12 @@ async function inflateDBMigrations(logger, service, dbName, inflateDir, errors)
13360
13891
  ...migrationModule
13361
13892
  });
13362
13893
  if (inflateDir) {
13363
- const inflatePath = (0, import_node_path25.resolve)(inflateDir, service, "migration", migrationName.substring(0, migrationName.length - (0, import_node_path25.extname)(migrationName).length) + ".js");
13364
- (0, import_node_fs22.mkdirSync)((0, import_node_path25.dirname)(inflatePath), {
13894
+ const inflatePath = (0, import_node_path28.resolve)(inflateDir, service, "migration", migrationName.substring(0, migrationName.length - (0, import_node_path28.extname)(migrationName).length) + ".js");
13895
+ (0, import_node_fs25.mkdirSync)((0, import_node_path28.dirname)(inflatePath), {
13365
13896
  recursive: true
13366
13897
  });
13367
- logger?.log("writing [%s]", (0, import_node_path25.relative)((0, import_node_process12.cwd)(), inflatePath));
13368
- (0, import_node_fs22.writeFileSync)(inflatePath, await inflateJSX((0, import_node_path25.resolve)(migrationsFolderPath, migrationName), {
13898
+ logger?.log("writing [%s]", (0, import_node_path28.relative)((0, import_node_process15.cwd)(), inflatePath));
13899
+ (0, import_node_fs25.writeFileSync)(inflatePath, await inflateJSX((0, import_node_path28.resolve)(migrationsFolderPath, migrationName), {
13369
13900
  embemedJSX: false,
13370
13901
  minify: false,
13371
13902
  useExport: true,
@@ -13468,7 +13999,8 @@ var ServerInterfaceImpl = class {
13468
13999
  };
13469
14000
 
13470
14001
  // src/common/arguments.ts
13471
- var import_node_path26 = require("node:path");
14002
+ var import_node_fs26 = require("node:fs");
14003
+ var import_node_path29 = require("node:path");
13472
14004
 
13473
14005
  // src/common/help.ts
13474
14006
  var BIN_NAME = "miqro";
@@ -13485,6 +14017,25 @@ CLUSTER_COUNT=10 ${BIN_NAME}-cluster --service api/`;
13485
14017
 
13486
14018
  // src/common/arguments.ts
13487
14019
  var import_node_sea2 = require("node:sea");
14020
+ var parser3 = new Parser();
14021
+ var MiqroJSONSchema = {
14022
+ type: "object",
14023
+ properties: {
14024
+ name: "string?",
14025
+ services: "string[]?",
14026
+ port: "number?|string?",
14027
+ inflateDir: "string?"
14028
+ }
14029
+ };
14030
+ function importMiqroJSON(inFile) {
14031
+ const mod = JSON.parse((0, import_node_fs26.readFileSync)(inFile).toString());
14032
+ const module2 = parser3.parse(mod, MiqroJSONSchema, (0, import_node_path29.basename)(inFile));
14033
+ if (module2 !== void 0) {
14034
+ return module2;
14035
+ } else {
14036
+ throw new Error(`error loading [${inFile}] undefined`);
14037
+ }
14038
+ }
13488
14039
  function getPORT() {
13489
14040
  return checkEnvVariable("PORT", "8080");
13490
14041
  }
@@ -13594,6 +14145,8 @@ function createAdminInterface(app) {
13594
14145
  }
13595
14146
 
13596
14147
  // src/services/app.ts
14148
+ var import_node_path30 = require("node:path");
14149
+ var import_node_process16 = require("node:process");
13597
14150
  var MiqroApplicationMessageType = "$$$MiqroApplicationMessageType$$$";
13598
14151
  var Miqro = class _Miqro {
13599
14152
  status = "stopped";
@@ -13669,6 +14222,21 @@ var Miqro = class _Miqro {
13669
14222
  this.adminInterface = createAdminInterface(this);
13670
14223
  setupExitHandlers(this);
13671
14224
  }
14225
+ static async import(inFile, options, inflate) {
14226
+ const miqroJSON = importMiqroJSON((0, import_node_path30.resolve)(inFile));
14227
+ const miqroJSONDir = (0, import_node_path30.dirname)((0, import_node_path30.resolve)(inFile));
14228
+ const app = new _Miqro({
14229
+ name: miqroJSON.name ? miqroJSON.name : void 0,
14230
+ port: miqroJSON.port ? String(miqroJSON.port) : void 0,
14231
+ services: miqroJSON.services ? miqroJSON.services.map((s) => (0, import_node_path30.join)((0, import_node_path30.relative)((0, import_node_process16.cwd)(), miqroJSONDir), s)) : void 0,
14232
+ ...options ? options : {}
14233
+ });
14234
+ await app.inflate({
14235
+ inflateDir: miqroJSON.inflateDir ? String(miqroJSON.inflateDir) : void 0,
14236
+ ...inflate ? inflate : {}
14237
+ });
14238
+ return app;
14239
+ }
13672
14240
  connect() {
13673
14241
  if (process.send) {
13674
14242
  process.removeListener("message", this.listener);
@@ -14025,7 +14593,7 @@ function reloadInflatedRouter(app) {
14025
14593
  async function notifiyServerConfig(logger, serverInterface, adminInterface, serverConfigMap, method) {
14026
14594
  if (serverConfigMap) {
14027
14595
  await Promise.allSettled(Object.keys(serverConfigMap).map((name) => {
14028
- return new Promise(async (resolve20) => {
14596
+ return new Promise(async (resolve24) => {
14029
14597
  try {
14030
14598
  const serverConfig = serverConfigMap[name];
14031
14599
  if (serverConfig && serverConfig[method]) {
@@ -14035,10 +14603,10 @@ async function notifiyServerConfig(logger, serverInterface, adminInterface, serv
14035
14603
  await serverConfig[method](serverInterface);
14036
14604
  }
14037
14605
  }
14038
- resolve20();
14606
+ resolve24();
14039
14607
  } catch (e) {
14040
14608
  logger?.error(e);
14041
- resolve20();
14609
+ resolve24();
14042
14610
  }
14043
14611
  });
14044
14612
  }));
@@ -14062,10 +14630,10 @@ function notifiyServerConfigSync(app, method) {
14062
14630
  }
14063
14631
 
14064
14632
  // src/inflate/utils/sea-utils.ts
14065
- var import_node_path27 = require("node:path");
14633
+ var import_node_path31 = require("node:path");
14066
14634
  async function appendAPIModule(router, dir, filePath, module2) {
14067
14635
  const file = describeFilePath(filePath);
14068
- const routes = getRoutes((0, import_node_path27.join)("/", (0, import_node_path27.dirname)((0, import_node_path27.relative)(dir, file.filePath))), file.subName, module2);
14636
+ const routes = getRoutes((0, import_node_path31.join)("/", (0, import_node_path31.dirname)((0, import_node_path31.relative)(dir, file.filePath))), file.subName, module2);
14069
14637
  for (const r of routes) {
14070
14638
  router.use(assertGlobalTampered);
14071
14639
  router.use(module2.handler, r.path, r.method, r.options);