miqro 5.0.5 → 6.0.4

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 (372) hide show
  1. package/.eslintrc +15 -0
  2. package/README.md +618 -20
  3. package/bin/miqro +34 -0
  4. package/build/editor.bundle.js +61154 -0
  5. package/build/esm/editor/auth.d.ts +6 -0
  6. package/build/esm/editor/auth.js +42 -0
  7. package/build/esm/editor/auth.js.map +1 -0
  8. package/build/esm/editor/common/admin-interface.d.ts +36 -0
  9. package/build/esm/editor/common/admin-interface.js +45 -0
  10. package/build/esm/editor/common/admin-interface.js.map +1 -0
  11. package/build/esm/editor/common/constants.d.ts +4 -0
  12. package/build/esm/editor/common/constants.js +21 -0
  13. package/build/esm/editor/common/constants.js.map +1 -0
  14. package/build/esm/editor/common/constants.server.d.ts +2 -0
  15. package/build/esm/editor/common/constants.server.js +5 -0
  16. package/build/esm/editor/common/constants.server.js.map +1 -0
  17. package/build/esm/editor/common/editor-index.d.ts +2 -0
  18. package/build/esm/editor/common/editor-index.js +15 -0
  19. package/build/esm/editor/common/editor-index.js.map +1 -0
  20. package/build/esm/editor/common/html-encode.d.ts +1 -0
  21. package/build/esm/editor/common/html-encode.js +15 -0
  22. package/build/esm/editor/common/html-encode.js.map +1 -0
  23. package/build/esm/editor/common/log-socket.d.ts +13 -0
  24. package/build/esm/editor/common/log-socket.js +68 -0
  25. package/build/esm/editor/common/log-socket.js.map +1 -0
  26. package/build/esm/editor/common/templates.d.ts +11 -0
  27. package/build/esm/editor/common/templates.js +444 -0
  28. package/build/esm/editor/common/templates.js.map +1 -0
  29. package/build/esm/editor/components/api-preview.d.ts +11 -0
  30. package/build/esm/editor/components/api-preview.js +91 -0
  31. package/build/esm/editor/components/api-preview.js.map +1 -0
  32. package/build/esm/editor/components/editor.d.ts +16 -0
  33. package/build/esm/editor/components/editor.js +355 -0
  34. package/build/esm/editor/components/editor.js.map +1 -0
  35. package/build/esm/editor/components/file-browser.d.ts +37 -0
  36. package/build/esm/editor/components/file-browser.js +122 -0
  37. package/build/esm/editor/components/file-browser.js.map +1 -0
  38. package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
  39. package/build/esm/editor/components/file-editor-toolbar.js +94 -0
  40. package/build/esm/editor/components/file-editor-toolbar.js.map +1 -0
  41. package/build/esm/editor/components/file-editor.d.ts +32 -0
  42. package/build/esm/editor/components/file-editor.js +60 -0
  43. package/build/esm/editor/components/file-editor.js.map +1 -0
  44. package/build/esm/editor/components/filter-query.d.ts +1 -0
  45. package/build/esm/editor/components/filter-query.js +23 -0
  46. package/build/esm/editor/components/filter-query.js.map +1 -0
  47. package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
  48. package/build/esm/editor/components/highlight-text-area.js +139 -0
  49. package/build/esm/editor/components/highlight-text-area.js.map +1 -0
  50. package/build/esm/editor/components/log-viewer.d.ts +6 -0
  51. package/build/esm/editor/components/log-viewer.js +70 -0
  52. package/build/esm/editor/components/log-viewer.js.map +1 -0
  53. package/build/esm/editor/components/new-file.d.ts +10 -0
  54. package/build/esm/editor/components/new-file.js +118 -0
  55. package/build/esm/editor/components/new-file.js.map +1 -0
  56. package/build/esm/editor/components/scroll-query.d.ts +7 -0
  57. package/build/esm/editor/components/scroll-query.js +22 -0
  58. package/build/esm/editor/components/scroll-query.js.map +1 -0
  59. package/build/esm/editor/components/start-page.d.ts +13 -0
  60. package/build/esm/editor/components/start-page.js +31 -0
  61. package/build/esm/editor/components/start-page.js.map +1 -0
  62. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +3 -0
  63. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +30 -0
  64. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js.map +1 -0
  65. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +5 -0
  66. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +50 -0
  67. package/build/esm/editor/http/admin/editor/api/fs/read.api.js.map +1 -0
  68. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +4 -0
  69. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +40 -0
  70. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js.map +1 -0
  71. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
  72. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +150 -0
  73. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js.map +1 -0
  74. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
  75. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +39 -0
  76. package/build/esm/editor/http/admin/editor/api/fs/write.api.js.map +1 -0
  77. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
  78. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
  79. package/build/esm/editor/http/admin/editor/api/server/reload.api.js.map +1 -0
  80. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
  81. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +46 -0
  82. package/build/esm/editor/http/admin/editor/api/server/restart.api.js.map +1 -0
  83. package/build/esm/editor/http/admin/editor/editor.js +8 -0
  84. package/build/esm/editor/http/admin/editor/editor.js.map +1 -0
  85. package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
  86. package/build/esm/editor/http/admin/editor/index.api.js +22 -0
  87. package/build/esm/editor/http/admin/editor/index.api.js.map +1 -0
  88. package/build/esm/editor/server.d.ts +3 -0
  89. package/build/esm/editor/server.js +50 -0
  90. package/build/esm/editor/server.js.map +1 -0
  91. package/build/esm/editor/ws.d.ts +3 -0
  92. package/build/esm/editor/ws.js +12 -0
  93. package/build/esm/editor/ws.js.map +1 -0
  94. package/build/esm/src/bin/compile.d.ts +3 -0
  95. package/build/esm/src/bin/compile.js +31 -0
  96. package/build/esm/src/bin/compile.js.map +1 -0
  97. package/build/{utils/doc/md.d.ts → esm/src/bin/doc-md.d.ts} +2 -4
  98. package/build/{utils/doc/md.js → esm/src/bin/doc-md.js} +32 -18
  99. package/build/esm/src/bin/doc-md.js.map +1 -0
  100. package/build/esm/src/bin/generate-doc.d.ts +4 -0
  101. package/build/esm/src/bin/generate-doc.js +47 -0
  102. package/build/esm/src/bin/generate-doc.js.map +1 -0
  103. package/build/esm/src/bin/test.d.ts +3 -0
  104. package/build/esm/src/bin/test.js +68 -0
  105. package/build/esm/src/bin/test.js.map +1 -0
  106. package/build/esm/src/bin/types.d.ts +3 -0
  107. package/build/esm/src/bin/types.js +21 -0
  108. package/build/esm/src/bin/types.js.map +1 -0
  109. package/build/esm/src/cluster.js +11 -0
  110. package/build/esm/src/cluster.js.map +1 -0
  111. package/build/esm/src/common/arguments.d.ts +22 -0
  112. package/build/esm/src/common/arguments.js +310 -0
  113. package/build/esm/src/common/arguments.js.map +1 -0
  114. package/build/esm/src/common/assets.d.ts +11 -0
  115. package/build/esm/src/common/assets.js +121 -0
  116. package/build/esm/src/common/assets.js.map +1 -0
  117. package/build/esm/src/common/checksum.d.ts +19 -0
  118. package/build/esm/src/common/checksum.js +57 -0
  119. package/build/esm/src/common/checksum.js.map +1 -0
  120. package/build/esm/src/common/constants.d.ts +10 -0
  121. package/build/esm/src/common/constants.js +14 -0
  122. package/build/esm/src/common/constants.js.map +1 -0
  123. package/build/esm/src/common/content-type.d.ts +4 -0
  124. package/build/esm/src/common/content-type.js +82 -0
  125. package/build/esm/src/common/content-type.js.map +1 -0
  126. package/build/esm/src/common/esbuild.d.ts +17 -0
  127. package/build/esm/src/common/esbuild.js +79 -0
  128. package/build/esm/src/common/esbuild.js.map +1 -0
  129. package/build/esm/src/common/exit.d.ts +2 -0
  130. package/build/esm/src/common/exit.js +84 -0
  131. package/build/esm/src/common/exit.js.map +1 -0
  132. package/build/esm/src/common/fs.d.ts +8 -0
  133. package/build/esm/src/common/fs.js +17 -0
  134. package/build/esm/src/common/fs.js.map +1 -0
  135. package/build/esm/src/common/help.d.ts +3 -0
  136. package/build/esm/src/common/help.js +44 -0
  137. package/build/esm/src/common/help.js.map +1 -0
  138. package/build/esm/src/common/jsx.d.ts +52 -0
  139. package/build/esm/src/common/jsx.js +365 -0
  140. package/build/esm/src/common/jsx.js.map +1 -0
  141. package/build/esm/src/common/paths.d.ts +14 -0
  142. package/build/esm/src/common/paths.js +110 -0
  143. package/build/esm/src/common/paths.js.map +1 -0
  144. package/build/esm/src/common/watch.d.ts +3 -0
  145. package/build/esm/src/common/watch.js +74 -0
  146. package/build/esm/src/common/watch.js.map +1 -0
  147. package/build/esm/src/inflate/inflate-sea.d.ts +5 -0
  148. package/build/esm/src/inflate/inflate-sea.js +175 -0
  149. package/build/esm/src/inflate/inflate-sea.js.map +1 -0
  150. package/build/esm/src/inflate/inflate.d.ts +14 -0
  151. package/build/esm/src/inflate/inflate.js +65 -0
  152. package/build/esm/src/inflate/inflate.js.map +1 -0
  153. package/build/esm/src/inflate/md.d.ts +2 -0
  154. package/build/esm/src/inflate/md.js +19 -0
  155. package/build/esm/src/inflate/md.js.map +1 -0
  156. package/build/esm/src/inflate/setup-auth.d.ts +3 -0
  157. package/build/esm/src/inflate/setup-auth.js +38 -0
  158. package/build/esm/src/inflate/setup-auth.js.map +1 -0
  159. package/build/esm/src/inflate/setup-cors.d.ts +3 -0
  160. package/build/esm/src/inflate/setup-cors.js +38 -0
  161. package/build/esm/src/inflate/setup-cors.js.map +1 -0
  162. package/build/esm/src/inflate/setup-db.d.ts +8 -0
  163. package/build/esm/src/inflate/setup-db.js +99 -0
  164. package/build/esm/src/inflate/setup-db.js.map +1 -0
  165. package/build/esm/src/inflate/setup-http.d.ts +37 -0
  166. package/build/esm/src/inflate/setup-http.js +543 -0
  167. package/build/esm/src/inflate/setup-http.js.map +1 -0
  168. package/build/esm/src/inflate/setup-log.d.ts +7 -0
  169. package/build/esm/src/inflate/setup-log.js +37 -0
  170. package/build/esm/src/inflate/setup-log.js.map +1 -0
  171. package/build/esm/src/inflate/setup-server-config.d.ts +7 -0
  172. package/build/esm/src/inflate/setup-server-config.js +37 -0
  173. package/build/esm/src/inflate/setup-server-config.js.map +1 -0
  174. package/build/esm/src/inflate/setup-test.d.ts +2 -0
  175. package/build/esm/src/inflate/setup-test.js +22 -0
  176. package/build/esm/src/inflate/setup-test.js.map +1 -0
  177. package/build/esm/src/inflate/setup-ws.d.ts +4 -0
  178. package/build/esm/src/inflate/setup-ws.js +46 -0
  179. package/build/esm/src/inflate/setup-ws.js.map +1 -0
  180. package/build/esm/src/inflate/utils/sea-utils.d.ts +2 -0
  181. package/build/esm/src/inflate/utils/sea-utils.js +13 -0
  182. package/build/esm/src/inflate/utils/sea-utils.js.map +1 -0
  183. package/build/esm/src/lib.d.ts +13 -0
  184. package/build/esm/src/lib.js +17 -0
  185. package/build/esm/src/lib.js.map +1 -0
  186. package/build/esm/src/main.d.ts +2 -0
  187. package/build/esm/src/main.js +92 -0
  188. package/build/esm/src/main.js.map +1 -0
  189. package/build/esm/src/services/app.d.ts +88 -0
  190. package/build/esm/src/services/app.js +619 -0
  191. package/build/esm/src/services/app.js.map +1 -0
  192. package/build/esm/src/services/editor.d.ts +3 -0
  193. package/build/esm/src/services/editor.js +61 -0
  194. package/build/esm/src/services/editor.js.map +1 -0
  195. package/build/esm/src/services/globals.d.ts +3 -0
  196. package/build/esm/src/services/globals.js +139 -0
  197. package/build/esm/src/services/globals.js.map +1 -0
  198. package/build/esm/src/services/hot-reload.d.ts +1 -0
  199. package/build/esm/src/services/hot-reload.js +45 -0
  200. package/build/esm/src/services/hot-reload.js.map +1 -0
  201. package/build/esm/src/services/migrations.d.ts +4 -0
  202. package/build/esm/src/services/migrations.js +61 -0
  203. package/build/esm/src/services/migrations.js.map +1 -0
  204. package/build/esm/src/services/utils/cache.d.ts +19 -0
  205. package/build/esm/src/services/utils/cache.js +85 -0
  206. package/build/esm/src/services/utils/cache.js.map +1 -0
  207. package/build/esm/src/services/utils/cluster-cache.d.ts +20 -0
  208. package/build/esm/src/services/utils/cluster-cache.js +211 -0
  209. package/build/esm/src/services/utils/cluster-cache.js.map +1 -0
  210. package/build/esm/src/services/utils/cluster-ws.d.ts +24 -0
  211. package/build/esm/src/services/utils/cluster-ws.js +176 -0
  212. package/build/esm/src/services/utils/cluster-ws.js.map +1 -0
  213. package/build/esm/src/services/utils/db-manager.d.ts +20 -0
  214. package/build/esm/src/services/utils/db-manager.js +59 -0
  215. package/build/esm/src/services/utils/db-manager.js.map +1 -0
  216. package/build/esm/src/services/utils/get-route.d.ts +9 -0
  217. package/build/esm/src/services/utils/get-route.js +58 -0
  218. package/build/esm/src/services/utils/get-route.js.map +1 -0
  219. package/build/esm/src/services/utils/log.d.ts +17 -0
  220. package/build/esm/src/services/utils/log.js +74 -0
  221. package/build/esm/src/services/utils/log.js.map +1 -0
  222. package/build/esm/src/services/utils/server-interface.d.ts +41 -0
  223. package/build/esm/src/services/utils/server-interface.js +74 -0
  224. package/build/esm/src/services/utils/server-interface.js.map +1 -0
  225. package/build/esm/src/services/utils/websocketmanager.d.ts +23 -0
  226. package/build/esm/src/services/utils/websocketmanager.js +128 -0
  227. package/build/esm/src/services/utils/websocketmanager.js.map +1 -0
  228. package/build/esm/src/types.d.ts +166 -0
  229. package/build/esm/src/types.js +2 -0
  230. package/build/esm/src/types.js.map +1 -0
  231. package/build/jsx.dom.js +1585 -0
  232. package/build/lib.cjs +14009 -0
  233. package/build/postject.base64.cjs +1 -0
  234. package/editor/auth.ts +51 -0
  235. package/editor/common/admin-interface.ts +84 -0
  236. package/editor/common/constants.server.ts +5 -0
  237. package/editor/common/constants.ts +21 -0
  238. package/editor/common/editor-index.tsx +17 -0
  239. package/editor/common/html-encode.ts +14 -0
  240. package/editor/common/log-socket.tsx +82 -0
  241. package/editor/common/templates.ts +448 -0
  242. package/editor/components/api-preview.tsx +116 -0
  243. package/editor/components/editor.tsx +483 -0
  244. package/editor/components/file-browser.tsx +295 -0
  245. package/editor/components/file-editor-toolbar.tsx +187 -0
  246. package/editor/components/file-editor.tsx +122 -0
  247. package/editor/components/filter-query.tsx +22 -0
  248. package/editor/components/highlight-text-area.tsx +159 -0
  249. package/editor/components/log-viewer.tsx +110 -0
  250. package/editor/components/new-file.tsx +169 -0
  251. package/editor/components/scroll-query.tsx +22 -0
  252. package/editor/components/start-page.tsx +49 -0
  253. package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
  254. package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
  255. package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
  256. package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
  257. package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
  258. package/editor/http/admin/editor/api/server/reload.api.ts +52 -0
  259. package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
  260. package/editor/http/admin/editor/editor.tsx +8 -0
  261. package/editor/http/admin/editor/font.ttf +0 -0
  262. package/editor/http/admin/editor/index.api.tsx +39 -0
  263. package/editor/http/admin/editor/style.css +620 -0
  264. package/editor/server.ts +57 -0
  265. package/editor/static/android-chrome-192x192.png +0 -0
  266. package/editor/static/android-chrome-512x512.png +0 -0
  267. package/editor/static/apple-touch-icon.png +0 -0
  268. package/editor/static/editor.bundle.in.mjs +20 -0
  269. package/editor/static/favicon-16x16.png +0 -0
  270. package/editor/static/favicon-32x32.png +0 -0
  271. package/editor/static/favicon.ico +0 -0
  272. package/editor/static/site.webmanifest +19 -0
  273. package/editor/ws.ts +15 -0
  274. package/package.json +43 -24
  275. package/package.json--OLD +36 -0
  276. package/sea/app.sh +33 -0
  277. package/sea/base64.js +3 -0
  278. package/sea/basic-compile.base64.sh +1 -0
  279. package/sea/basic-compile.sh +73 -0
  280. package/sea/basic-config.json +9 -0
  281. package/sea/compile.sh +124 -0
  282. package/sea/copy-types.sh +46 -0
  283. package/sea/editor-assets/editor.bundle.in.mjs +19 -0
  284. package/sea/esbuild.sh +31 -0
  285. package/sea/generate-global-types-asset-json.js +34 -0
  286. package/sea/install-esbuild.sh +53 -0
  287. package/sea/install-nodejs.sh +49 -0
  288. package/sea/main.sh +34 -0
  289. package/sea/node.sh +33 -0
  290. package/sea/node.version.tag +1 -0
  291. package/sea/precompile.sh +7 -0
  292. package/sea/release-tar.sh +5 -0
  293. package/sea/sign-add.sh +22 -0
  294. package/sea/sign-remove.sh +22 -0
  295. package/sea/tsc.sh +1 -0
  296. package/sea/types.json +1 -0
  297. package/src/bin/compile.ts +35 -0
  298. package/src/bin/doc-md.ts +210 -0
  299. package/src/bin/generate-doc.ts +55 -0
  300. package/src/bin/test.ts +92 -0
  301. package/src/bin/types.ts +22 -0
  302. package/src/cluster.ts +16 -0
  303. package/src/common/arguments.ts +366 -0
  304. package/src/common/assets.ts +124 -0
  305. package/src/common/checksum.ts +58 -0
  306. package/src/common/constants.ts +18 -0
  307. package/src/common/content-type.ts +84 -0
  308. package/src/common/esbuild.ts +94 -0
  309. package/src/common/exit.ts +91 -0
  310. package/src/common/fs.ts +17 -0
  311. package/src/common/help.ts +46 -0
  312. package/src/common/jsx.ts +414 -0
  313. package/src/common/paths.ts +117 -0
  314. package/src/common/watch.ts +80 -0
  315. package/src/inflate/inflate-sea.ts +193 -0
  316. package/src/inflate/inflate.ts +96 -0
  317. package/src/inflate/md.ts +20 -0
  318. package/src/inflate/setup-auth.ts +40 -0
  319. package/src/inflate/setup-cors.ts +40 -0
  320. package/src/inflate/setup-db.ts +113 -0
  321. package/src/inflate/setup-http.ts +643 -0
  322. package/src/inflate/setup-log.ts +44 -0
  323. package/src/inflate/setup-server-config.ts +47 -0
  324. package/src/inflate/setup-test.ts +23 -0
  325. package/src/inflate/setup-ws.ts +48 -0
  326. package/src/inflate/utils/sea-utils.ts +14 -0
  327. package/src/lib.ts +19 -0
  328. package/src/main.ts +87 -0
  329. package/src/services/app.ts +718 -0
  330. package/src/services/editor.tsx +93 -0
  331. package/src/services/globals.ts +143 -0
  332. package/src/services/hot-reload.ts +46 -0
  333. package/src/services/migrations.ts +66 -0
  334. package/src/services/utils/cache.ts +88 -0
  335. package/src/services/utils/cluster-cache.ts +225 -0
  336. package/src/services/utils/cluster-ws.ts +192 -0
  337. package/src/services/utils/db-manager.ts +79 -0
  338. package/src/services/utils/get-route.ts +70 -0
  339. package/src/services/utils/log.ts +91 -0
  340. package/src/services/utils/server-interface.ts +166 -0
  341. package/src/services/utils/websocketmanager.ts +139 -0
  342. package/src/types/@esbuild.d.ts +1 -0
  343. package/src/types/@miqro/core.d.ts +2 -0
  344. package/src/types/@miqro/jsx.d.ts +2 -0
  345. package/src/types/@miqro/parser.d.ts +2 -0
  346. package/src/types/@miqro/query.d.ts +2 -0
  347. package/src/types/@miqro/request.d.ts +2 -0
  348. package/src/types/@miqro/test.d.ts +2 -0
  349. package/src/types/@miqro.d.ts +1 -0
  350. package/src/types/@types.d.ts +1 -0
  351. package/src/types/browser.globals.d.ts +9 -0
  352. package/src/types/globals.d.ts +2 -0
  353. package/src/types/jsx.globals.d.ts +37 -0
  354. package/src/types/miqro.d.ts +109 -0
  355. package/src/types/postject.d.ts +1 -0
  356. package/src/types/server.globals.d.ts +72 -0
  357. package/src/types.ts +199 -0
  358. package/tsconfig.json +35 -0
  359. package/build/cli.js +0 -4
  360. package/build/cmd-map.d.ts +0 -90
  361. package/build/cmd-map.js +0 -460
  362. package/build/index.js +0 -2
  363. package/build/utils/doc/json.d.ts +0 -7
  364. package/build/utils/doc/json.js +0 -12
  365. package/build/utils/exec.d.ts +0 -32
  366. package/build/utils/exec.js +0 -102
  367. package/build/utils/templates.d.ts +0 -33
  368. package/build/utils/templates.js +0 -302
  369. package/build/utils/watch.d.ts +0 -1
  370. package/build/utils/watch.js +0 -35
  371. /package/build/{index.d.ts → esm/editor/http/admin/editor/editor.d.ts} +0 -0
  372. /package/build/{cli.d.ts → esm/src/cluster.d.ts} +0 -0
@@ -0,0 +1,159 @@
1
+ //import hljs from "../lib/highlight/core.min.js"
2
+ import hljs from 'highlight.js';
3
+ import javascript from 'highlight.js/lib/languages/javascript';
4
+ import xml from "highlight.js/lib/languages/xml.js";
5
+ import css from "highlight.js/lib/languages/css.js";
6
+ import scss from "highlight.js/lib/languages/scss.js";
7
+ import markdown from "highlight.js/lib/languages/markdown.js";
8
+ import dockerfile from "highlight.js/lib/languages/dockerfile.js";
9
+ import yaml from "highlight.js/lib/languages/yaml.js";
10
+ import typescript from "highlight.js/lib/languages/typescript.js";
11
+ import c from "highlight.js/lib/languages/c.js";
12
+ import cpp from "highlight.js/lib/languages/cpp.js";
13
+ import bash from "highlight.js/lib/languages/bash.js";
14
+ import python from "highlight.js/lib/languages/python.js";
15
+ import text from "highlight.js/lib/languages/plaintext.js";
16
+ import json from "highlight.js/lib/languages/json.js";
17
+
18
+ /*import javascript from "../lib/highlight/languages/javascript.js";
19
+ import xml from "../lib/highlight/languages/xml.js";
20
+ import css from "../lib/highlight/languages/css.js";
21
+ import scss from "../lib/highlight/languages/scss.js";
22
+ import markdown from "../lib/highlight/languages/markdown.js";
23
+ import dockerfile from "../lib/highlight/languages/dockerfile.js";
24
+ import yaml from "../lib/highlight/languages/yaml.js";
25
+ import typescript from "../lib/highlight/languages/typescript.js";
26
+ import c from "../lib/highlight/languages/c.js";
27
+ import cpp from "../lib/highlight/languages/cpp.js";
28
+ import bash from "../lib/highlight/languages/bash.js";
29
+ import python from "../lib/highlight/languages/python.js";
30
+ import text from "../lib/highlight/languages/plaintext.js";
31
+ import json from "../lib/highlight/languages/json.js";*/
32
+
33
+ // Then register the languages you need
34
+ hljs.registerLanguage('text', text);
35
+ hljs.registerLanguage('dockerfile', dockerfile);
36
+ hljs.registerLanguage('yaml', yaml);
37
+ hljs.registerLanguage('javascript', javascript);
38
+ hljs.registerLanguage('xml', xml);
39
+ hljs.registerLanguage('html', xml);
40
+ hljs.registerLanguage('css', css);
41
+ hljs.registerLanguage('scss', scss);
42
+ hljs.registerLanguage('markdown', markdown);
43
+ hljs.registerLanguage('typescript', typescript);
44
+ hljs.registerLanguage('c', c);
45
+ hljs.registerLanguage('cpp', cpp);
46
+ hljs.registerLanguage('bash', bash);
47
+ hljs.registerLanguage('python', python);
48
+ hljs.registerLanguage('json', json);
49
+
50
+ /*!
51
+ Theme: GitHub Dark
52
+ Description: Dark theme as seen on github.com
53
+ Author: github.com
54
+ Maintainer: @Hirse
55
+ Updated: 2021-05-15
56
+
57
+ Outdated base version: https://github.com/primer/github-syntax-dark
58
+ Current colors taken from GitHub's CSS
59
+ */
60
+ const STYLE = `pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#c9d1d9;background:#0d1117}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#ff7b72}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#d2a8ff}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#79c0ff}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#a5d6ff}.hljs-built_in,.hljs-symbol{color:#ffa657}.hljs-code,.hljs-comment,.hljs-formula{color:#8b949e}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#7ee787}.hljs-subst{color:#c9d1d9}.hljs-section{color:#1f6feb;font-weight:700}.hljs-bullet{color:#f2cc60}.hljs-emphasis{color:#c9d1d9;font-style:italic}.hljs-strong{color:#c9d1d9;font-weight:700}.hljs-addition{color:#aff5b4;background-color:#033a16}.hljs-deletion{color:#ffdcd7;background-color:#67060c}code{outline: 0px solid rgba(0, 0, 0, 0.263);caret-color: red;}.hljs-name{color: #e8910d;}.hljs-tag .hljs-attr, .hljs-tag .hljs-name{color: #e8910d;}`;
61
+ const POSTTYLE = "pre{padding:0; margin:0;} code { background-color: #000000; color: #ffffff; }";
62
+ const TAG_NAME = "HIGHLIGHT-TEXT-AREA";
63
+
64
+ function runHighlight(content: string | null, language: string) {
65
+ const now = Date.now();
66
+ console.log("runHighlight [%s]", language);
67
+ const value = hljs.highlight(String(content), {
68
+ language,
69
+ ignoreIllegals: true
70
+ }).value;
71
+ console.log("runHighlight [%s] took [%s]ms", language, Date.now() - now);
72
+ return value;
73
+ }
74
+
75
+ function emitEvents(elementRef: any, topMost: any, content: string, oncontentchange?: (ev: CustomEvent) => void) {
76
+ if (elementRef.current && topMost.current) {
77
+ const currentContent = elementRef.current.textContent as any;
78
+ const webComponentElement = (topMost.current as HTMLElement).parentNode as HTMLElement;
79
+ const event = new CustomEvent("contentchange", { detail: currentContent });
80
+ if (webComponentElement && webComponentElement instanceof HTMLElement && webComponentElement.tagName === TAG_NAME) {
81
+ try {
82
+ webComponentElement.dispatchEvent(event);
83
+ } catch (e) {
84
+ console.error(e);
85
+ }
86
+ }
87
+ if (typeof oncontentchange === "function") {
88
+ try {
89
+ oncontentchange(event);
90
+ } catch (e) {
91
+ console.error(e);
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ export function HighlightTextArea({ content, language, oncontentchange, tabChar, disabled }:
98
+ { language: string; content: string; disabled?: string; tabChar?: string; oncontentchange?: (ev: CustomEvent) => void }
99
+ ) {
100
+ const elementRef = jsx.useRef();
101
+ const topMost = jsx.useRef();
102
+ const [lastLanguage, setlastLanguage] = jsx.useState(language);
103
+
104
+ // effect to watch changes to language
105
+ jsx.useEffect(() => {
106
+ if (elementRef.current && (lastLanguage !== language || elementRef.current.textContent !== content)) {
107
+ setlastLanguage(language);
108
+ elementRef.current.innerHTML = runHighlight(content, language);
109
+ }
110
+ }, [lastLanguage, language, elementRef.current, content])
111
+
112
+ return <pre ref={topMost}>
113
+ <style innerHTML={STYLE + POSTTYLE} />
114
+ <code
115
+ autocomplete="off"
116
+ autocorrect="off"
117
+ autocapitalize="off"
118
+ spellcheck="false"
119
+ contenteditable={disabled ? "false" : "true"}
120
+ ref={elementRef}
121
+ tabindex="0"
122
+ innerHTML={!elementRef.current ? runHighlight(content, language) : null}
123
+ onfocusout={async (ev) => {
124
+ ev.preventDefault();
125
+ if (elementRef.current) {
126
+ if (content !== elementRef.current.textContent) {
127
+ //setlastContent(String(elementRef.current.textContent));
128
+ elementRef.current.innerHTML = runHighlight(elementRef.current.textContent, language);
129
+ }
130
+ }
131
+ }}
132
+ onkeydown={ev => {
133
+ if (ev.keyCode === 9) {
134
+ ev.preventDefault();
135
+ // now insert four non-breaking spaces for the tab key
136
+ const sel = document.getSelection();
137
+ if (sel && topMost.current) {
138
+ if ((topMost.current as any).contains(sel.anchorNode)) {
139
+ const range = sel.getRangeAt(0);
140
+ const tabNode = document.createTextNode(tabChar ? tabChar : "\t");
141
+ range.insertNode(tabNode);
142
+ range.setStartAfter(tabNode);
143
+ range.setEndAfter(tabNode);
144
+ sel.removeAllRanges();
145
+ sel.addRange(range);
146
+ }
147
+ }
148
+ emitEvents(elementRef, topMost, content, oncontentchange);
149
+ }
150
+ }}
151
+ oninput={ev => {
152
+ ev.preventDefault();
153
+ emitEvents(elementRef, topMost, content, oncontentchange);
154
+ }} />
155
+ </pre>
156
+ }
157
+
158
+ HighlightTextArea.asFragment = true;
159
+ HighlightTextArea.shadowInit = false;
@@ -0,0 +1,110 @@
1
+ import { LogSocket } from "../common/log-socket.js";
2
+
3
+ function getUniqueIdentifiers(lines: {
4
+ out: string;
5
+ identifier: string;
6
+ }[]) {
7
+ const identifiersCache = {};
8
+ return lines.map(l => l.identifier).filter(identifier => {
9
+ const filter = !identifiersCache[identifier];
10
+ identifiersCache[identifier] = true;
11
+ return filter;
12
+ });
13
+ }
14
+
15
+ const LOG_LEVEL_MAP =
16
+ {
17
+ "none": 0,
18
+ "error": 1,
19
+ "warn": 2,
20
+ "info": 3,
21
+ "debug": 4,
22
+ "trace": 5,
23
+ };
24
+
25
+ interface LogViewerProps {
26
+ socket: LogSocket;
27
+ }
28
+
29
+ export function LogViewer(props: LogViewerProps) {
30
+ const { lines, clearLog, getMaxlogsize, setMaxLogSize } = props.socket;
31
+
32
+ const maxLogSize = getMaxlogsize();
33
+
34
+ const refresh = jsx.useRefresh();
35
+
36
+ jsx.useEffect(() => {
37
+ refresh();
38
+ }, [maxLogSize]);
39
+
40
+ const [identifier, setidentifier] = jsx.useState<string>("");
41
+ const [level, setlevel] = jsx.useState<string>("debug");
42
+ const [filter, setfilter] = jsx.useState<string>("");
43
+ const identifiers = getUniqueIdentifiers(lines).sort();
44
+ //console.log(identifiers);
45
+
46
+ return <div class="log-viewer">
47
+ <div class="log-viewer-toolbar">
48
+ <button
49
+ class="btn"
50
+ onclick={e => {
51
+ e.preventDefault();
52
+ clearLog();
53
+ }}>clear log</button>
54
+ <select
55
+ value={maxLogSize}
56
+ oninput={ev => {
57
+ ev.preventDefault();
58
+ if (ev.target.value === "unlimited") {
59
+ setMaxLogSize("unlimited");
60
+ } else {
61
+ setMaxLogSize(parseInt(ev.target.value, 10));
62
+ }
63
+ }}
64
+ style="margin: 0; padding: 0; margin-left:auto; margin-right: 0;">
65
+ {["10", "1000", "5000", "10000", "15000", "20000", "25000", "50000", "100000", "500000", "1000000", "1500000", "5000000"].map(l => <option value={l}>{l}</option>)}
66
+ <option value="unlimited">unlimited</option>
67
+ </select>
68
+ <select
69
+ value={level}
70
+ oninput={ev => {
71
+ ev.preventDefault();
72
+ setlevel(ev.target.value);
73
+ }}
74
+ style="margin: 0; padding: 0; margin-left:var(--file-browser-separation); margin-right: 0;">
75
+ {["error", "warn", "info", "debug", "trace"].map(l => <option value={l}>{l}</option>)}
76
+ <option value="">all</option>
77
+ </select>
78
+ <select
79
+ value={identifier}
80
+ oninput={ev => {
81
+ ev.preventDefault();
82
+ setidentifier(ev.target.value);
83
+ }}
84
+ style="margin: 0; padding: 0; margin-left:var(--file-browser-separation); margin-right: 0;">
85
+ {identifiers.map(identifier => <option value={identifier}>{identifier}</option>)}
86
+ <option value=""></option>
87
+ </select>
88
+ <input
89
+ style="margin: 0; padding: 0; margin-left:var(--file-browser-separation); margin-right: 0;"
90
+ value={filter}
91
+ oninput={ev => {
92
+ ev.preventDefault();
93
+ setfilter(ev.target.value);
94
+ }}
95
+ type="text"
96
+ placeholder="..filter.." />
97
+ </div>
98
+ <div class="log-viewer-log">
99
+ {lines
100
+ .filter(line => identifier === "" || line.identifier === identifier)
101
+ .filter(line => filter === "" || line.out.indexOf(filter) !== -1)
102
+ .filter(line => {
103
+ return (level === "" || LOG_LEVEL_MAP[level] >= LOG_LEVEL_MAP[line.level]);
104
+ })
105
+ .map(line =>
106
+ <p style="margin: 0; padding: 0; border-radius: 0; font-size: 12px;" class={line.level === "error" ? "info-danger" : line.level === "warn" ? "info-warn" : line.level === "trace" ? "info-success" : line.level === "debug" ? "info-info" : ""}>{line.out}</p>
107
+ ).reverse()}
108
+ </div>
109
+ </div>
110
+ }
@@ -0,0 +1,169 @@
1
+ import { BASEEDITOR_PATH } from "../common/constants.js";
2
+ import { TEMPLATES } from "../common/templates.js";
3
+ import { HighlightTextArea } from "./highlight-text-area.js";
4
+
5
+ export function NewFile(props: { migrations: string[]; services: string[]; open: boolean; ondone: (file?: string) => void; }) {
6
+
7
+ const [template, settemplate] = jsx.useState("EMPTY");
8
+
9
+ const refresh = jsx.useRefresh();
10
+
11
+ const [service, setservice] = jsx.useState(props.services[0]);
12
+
13
+ const nameInput = jsx.useRef();
14
+ //const open = dialog ? dialog.open : false;
15
+
16
+ /*jsx.useEffect(() => {
17
+ if (dialog) {
18
+ //console.log((dialogRef.current as any).open);
19
+ if (open !== props.open) {
20
+ if (nameInput.current) {
21
+ nameInput.current.value = "";
22
+ nameInput.current.focus();
23
+ }
24
+ if (props.open) {
25
+ console.log("showModal");
26
+ dialog.showModal();
27
+ //(dialogRef.current as any).show();
28
+ } else {
29
+ console.log("closeModal");
30
+ //dialog.close();
31
+ }
32
+ }
33
+ }
34
+ }, [dialog, open, props.open]);*/
35
+ jsx.useEffect(() => {
36
+
37
+ if (nameInput.current) {
38
+ nameInput.current.value = "";
39
+ nameInput.current.focus();
40
+ }
41
+ }, [nameInput.current]);
42
+
43
+ function close(file?: string) {
44
+ //console.log("closeModal");
45
+ if (props.ondone) {
46
+ props.ondone(file);
47
+ }
48
+ }
49
+
50
+
51
+ let nextMigrationNumber = 1;
52
+ if (props.migrations.length > 0) {
53
+ const lastMigration = props.migrations[props.migrations.length - 1];
54
+ const indexOfDash = lastMigration.indexOf("-");
55
+ if (indexOfDash !== -1) {
56
+ nextMigrationNumber = parseInt(lastMigration.substring(0, indexOfDash), 10) + 1;
57
+ }
58
+ }
59
+
60
+ const httpPath = (TEMPLATES[template].filename ? TEMPLATES[template].filename : nameInput.current?.value) + (TEMPLATES[template].httpSufix ? TEMPLATES[template].httpSufix : "");
61
+
62
+ const filename = (service ? service + "/" : "") + (service && TEMPLATES[template].prefix ? TEMPLATES[template].prefix + "/" : "") + (template === "MIGRATION" ? nextMigrationNumber + "-" : "") + (TEMPLATES[template].filename ? TEMPLATES[template].filename : nameInput.current?.value) + (TEMPLATES[template].sufix ? TEMPLATES[template].sufix : "");
63
+
64
+ async function createNewFile() {
65
+ if ((nameInput.current && nameInput.current.value) || TEMPLATES[template].filename) {
66
+ const t = TEMPLATES[template];
67
+ await fetch(BASEEDITOR_PATH + "/api/fs/write", {
68
+ method: "POST",
69
+ headers: {
70
+ ["content-type"]: "application/json"
71
+ },
72
+ body: JSON.stringify({
73
+ path: filename,
74
+ contents: t.template ? t.template(filename, httpPath) : ""
75
+ })
76
+ });
77
+ return filename;
78
+ }
79
+ }
80
+
81
+ return <>
82
+ {props.open ? <dialog
83
+ class="new-dialog"
84
+ open="">
85
+ <div class="dialog-header">
86
+ <h1>Create new File</h1>
87
+ </div>
88
+ <div class="dialog-body">
89
+ <select
90
+ value={service}
91
+ oninput={ev => {
92
+ ev.preventDefault();
93
+ ev.stopPropagation();
94
+ console.log(ev.target.value);
95
+ setservice(ev.target.value);
96
+ }}
97
+ style="margin: 0; padding: 0; margin-left:auto; margin-right: var(--file-browser-separation); width: 100%; margin-top: var(--file-browser-separation); margin-bottom: var(--file-browser-separation);">
98
+ <option value={""}></option>
99
+ {props.services.map(service => <option value={service}>{service}</option>)}
100
+ </select>
101
+ <p
102
+ style="margin: 0; margin-bottom: var(--file-browser-separation);"
103
+ >{filename}</p>
104
+ {!TEMPLATES[template].filename ? <form
105
+ style="width: 100%;"
106
+ onsubmit={async (ev) => {
107
+ ev.preventDefault();
108
+ ev.stopPropagation();
109
+ const path = await createNewFile();
110
+ close(path);
111
+ }}>
112
+ <input
113
+ style="width: 100%;"
114
+ onkeydown={ev => {
115
+ if (ev.keyCode === 27) {
116
+ // catch esc
117
+ ev.stopPropagation();
118
+ ev.preventDefault();
119
+ close();
120
+ }
121
+ refresh();
122
+ }}
123
+ ref={nameInput}
124
+ type="text"
125
+ placeholder="...filename..." />
126
+ </form> : <></>}
127
+ <select
128
+ value={template}
129
+ oninput={ev => {
130
+ ev.preventDefault();
131
+ ev.stopPropagation();
132
+ console.log(ev.target.value);
133
+ settemplate(ev.target.value);
134
+ }}
135
+ style="margin: 0; padding: 0; margin-left:auto; margin-right: var(--file-browser-separation); width: 100%; margin-top: var(--file-browser-separation);">
136
+ {Object.keys(TEMPLATES).map(templateName => <option value={templateName}>{TEMPLATES[templateName].displayName}</option>)}
137
+ </select>
138
+ {TEMPLATES[template].template ? <div
139
+ class="new-dialog-preview">
140
+ <HighlightTextArea
141
+ content={TEMPLATES[template].template(filename, httpPath)}
142
+ language={TEMPLATES[template].language}
143
+ disabled="true" />
144
+ </div> : <></>}
145
+ </div>
146
+ <div class="dialog-footer">
147
+ <button
148
+ class="btn danger"
149
+ onclick={ev => {
150
+ ev.preventDefault();
151
+ ev.stopPropagation();
152
+ close();
153
+ }}>cancel</button>
154
+ <button
155
+ style="margin-left: auto;"
156
+ class="btn active"
157
+ onclick={async (ev) => {
158
+ ev.preventDefault();
159
+ ev.stopPropagation();
160
+ const path = await createNewFile();
161
+ close(path);
162
+ }}>create</button>
163
+ </div>
164
+ </dialog> : <></>}
165
+ </>
166
+ }
167
+
168
+ NewFile.asFragment = true;
169
+ NewFile.shadowInit = false;
@@ -0,0 +1,22 @@
1
+ let scrollTimeout2: any = null;
2
+
3
+ export function useScroll(): [{ scrollTop: string; scrollLeft: string }, (newScroll: { scrollTop: number; scrollLeft: number; }, inmediate?: boolean) => void] {
4
+ const [scrollTop, setscrollTop] = jsx.useQuery("scrollTop", "0");
5
+ const [scrollLeft, setscrollLeft] = jsx.useQuery("scrollLeft", "0");
6
+
7
+ return [{
8
+ scrollTop: scrollTop as string,
9
+ scrollLeft: scrollLeft as string
10
+ }, (newScroll: { scrollTop: number; scrollLeft: number; }, inmediate?: boolean) => {
11
+ clearTimeout(scrollTimeout2);
12
+ if (inmediate) {
13
+ setscrollTop(String(newScroll.scrollTop));
14
+ setscrollLeft(String(newScroll.scrollLeft));
15
+ } else {
16
+ scrollTimeout2 = setTimeout(() => {
17
+ setscrollTop(String(newScroll.scrollTop));
18
+ setscrollLeft(String(newScroll.scrollLeft));
19
+ }, 1000);
20
+ }
21
+ }]
22
+ }
@@ -0,0 +1,49 @@
1
+ interface StartPageProps {
2
+ togglePanel: (panel: string) => void;
3
+ isPanelVisible: (panel: string) => boolean;
4
+ disableLog?: boolean; disablePreview?: boolean; disableReload?: boolean;
5
+ }
6
+
7
+ export function StartPage(props: StartPageProps) {
8
+
9
+ jsx.useEffect(() => {
10
+ if (!props.isPanelVisible("left")) {
11
+ props.togglePanel("left");
12
+ }
13
+ }, []);
14
+
15
+ return <div class={`start-page`}>
16
+ <div class="row center">
17
+ <h1>Start Page</h1>
18
+ </div>
19
+ <br />
20
+ <div class="row center">
21
+ <div class="row">
22
+ <div class={`toggle-panel-button left-side-panel-button ${props.isPanelVisible("left") ? "active" : ""}`}
23
+ onclick={ev => {
24
+ ev.preventDefault();
25
+ props.togglePanel("left");
26
+ }}
27
+ ></div>
28
+ <br />
29
+ {props.disableLog ? <></> : <div class={`toggle-panel-button bottom-side-panel-button ${props.isPanelVisible("bottom") ? "active" : ""}`}
30
+ onclick={ev => {
31
+ ev.preventDefault();
32
+ props.togglePanel("bottom");
33
+ }}
34
+ ></div>}
35
+ <br />
36
+ {props.disablePreview ? <></> : <div class={`toggle-panel-button right-side-panel-button ${props.isPanelVisible("right") ? "active" : ""}`}
37
+ onclick={ev => {
38
+ ev.preventDefault();
39
+ props.togglePanel("right");
40
+ }}
41
+ ></div>}
42
+ </div>
43
+ </div>
44
+ <br />
45
+ </div>;
46
+ }
47
+
48
+ StartPage.asFragment = true;
49
+ StartPage.shadowInit = false;
@@ -0,0 +1,32 @@
1
+ import { APIRoute } from "@miqro/core";
2
+ import { unlinkSync } from "node:fs";
3
+ import { getPath } from "./read.api.js";
4
+
5
+ export default {
6
+ description: "admin editor file deletion endpoint",
7
+ method: "POST",
8
+ path: "/delete",
9
+ middleware: [server.middleware.json()],
10
+ request: {
11
+ body: {
12
+ path: "string"
13
+ }
14
+ },
15
+ response: {
16
+ status: [200, 400],
17
+ body: {
18
+ message: "string"
19
+ }
20
+ },
21
+ handler: async (req, res) => {
22
+ const { path } = req.body;
23
+ await deleteFile(path);
24
+ return res?.json({
25
+ message: "OK"
26
+ });
27
+ }
28
+ } as APIRoute;
29
+
30
+ function deleteFile(path: string) {
31
+ unlinkSync(getPath(path));
32
+ }
@@ -0,0 +1,55 @@
1
+ import { APIRoute } from "@miqro/core";
2
+ import { readFileSync } from "node:fs";
3
+ import { SUPPORTED_LANGUAGES } from "../../../../../common/constants.js";
4
+ import { relative, resolve } from "node:path";
5
+ import { getLanguage } from "./scan.api.js";
6
+ import { BASE_PATH } from "../../../../../common/constants.server.js";
7
+
8
+ export default {
9
+ method: "POST",
10
+ path: "/read",
11
+ description: "admin editor file read endpoint",
12
+ middleware: [server.middleware.json()],
13
+ request: {
14
+ body: {
15
+ path: "string"
16
+ }
17
+ },
18
+ response: {
19
+ status: [200, 400],
20
+ body: {
21
+ contents: "string",
22
+ path: "string"
23
+ }
24
+ },
25
+ handler: async (req, res) => {
26
+ const { path } = req.body;
27
+ const contents = readFile(path);
28
+ return res?.json({
29
+ contents,
30
+ path
31
+ });
32
+ }
33
+ } as APIRoute;
34
+
35
+ export function readFile(path: string) {
36
+ const filePath = getPath(path);
37
+ const language = getLanguage(filePath);
38
+ if (SUPPORTED_LANGUAGES.includes(language)) {
39
+ const contents = readFileSync(filePath).toString();
40
+ return contents;
41
+ } else {
42
+ throw new Error("unsupported file format");
43
+ }
44
+
45
+ }
46
+
47
+ export function getPath(path: string) {
48
+ const realPath = resolve(BASE_PATH, path);
49
+
50
+ if (relative(BASE_PATH, realPath).startsWith("..")) {
51
+ throw new Error("invalid path! [" + path + "]");
52
+ }
53
+
54
+ return realPath;
55
+ }
@@ -0,0 +1,41 @@
1
+ import { APIRoute } from "@miqro/core";
2
+ import { existsSync, mkdirSync, renameSync } from "node:fs";
3
+ import { getPath } from "./read.api.js";
4
+ import { dirname } from "node:path";
5
+
6
+ export default {
7
+ middleware: [server.middleware.json()],
8
+ method: "POST",
9
+ description: "admin editor file rename endpoint",
10
+ path: "/rename",
11
+ request: {
12
+ body: {
13
+ path: "string",
14
+ newName: "string"
15
+ }
16
+ },
17
+ response: {
18
+ status: [200, 400],
19
+ body: {
20
+ message: "string"
21
+ }
22
+ },
23
+ handler: async (req, res) => {
24
+ const { path, newName } = req.body;
25
+ await rename(path, newName);
26
+ return res?.json({
27
+ message: "OK"
28
+ });
29
+ }
30
+ } as APIRoute;
31
+
32
+ export async function rename(path: string, newName: string) {
33
+ if (existsSync(path) && !existsSync(newName)) {
34
+ mkdirSync(dirname(getPath(newName)), {
35
+ recursive: true
36
+ });
37
+ renameSync(getPath(path), getPath(newName));
38
+ } else {
39
+ throw new Error("invalid paths");
40
+ }
41
+ }