miqro 7.0.1 → 7.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/build/esm/editor/auth.d.ts +6 -0
  2. package/build/esm/editor/auth.js +41 -0
  3. package/build/esm/editor/common/admin-interface.d.ts +36 -0
  4. package/build/esm/editor/common/admin-interface.js +44 -0
  5. package/build/esm/editor/common/constants.d.ts +4 -0
  6. package/build/esm/editor/common/constants.js +20 -0
  7. package/build/esm/editor/common/constants.server.d.ts +2 -0
  8. package/build/esm/editor/common/constants.server.js +4 -0
  9. package/build/esm/editor/common/editor-index.d.ts +2 -0
  10. package/build/esm/editor/common/editor-index.js +14 -0
  11. package/build/esm/editor/common/html-encode.d.ts +1 -0
  12. package/build/esm/editor/common/html-encode.js +14 -0
  13. package/build/esm/editor/common/log-socket.d.ts +15 -0
  14. package/build/esm/editor/common/log-socket.js +71 -0
  15. package/build/esm/editor/common/templates.d.ts +11 -0
  16. package/build/esm/editor/common/templates.js +477 -0
  17. package/build/esm/editor/components/api-preview.d.ts +11 -0
  18. package/build/esm/editor/components/api-preview.js +92 -0
  19. package/build/esm/editor/components/editor.d.ts +16 -0
  20. package/build/esm/editor/components/editor.js +367 -0
  21. package/build/esm/editor/components/file-browser.d.ts +37 -0
  22. package/build/esm/editor/components/file-browser.js +127 -0
  23. package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
  24. package/build/esm/editor/components/file-editor-toolbar.js +95 -0
  25. package/build/esm/editor/components/file-editor.d.ts +32 -0
  26. package/build/esm/editor/components/file-editor.js +61 -0
  27. package/build/esm/editor/components/filter-query.d.ts +1 -0
  28. package/build/esm/editor/components/filter-query.js +23 -0
  29. package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
  30. package/build/esm/editor/components/highlight-text-area.js +127 -0
  31. package/build/esm/editor/components/log-viewer.d.ts +6 -0
  32. package/build/esm/editor/components/log-viewer.js +71 -0
  33. package/build/esm/editor/components/new-file.d.ts +10 -0
  34. package/build/esm/editor/components/new-file.js +119 -0
  35. package/build/esm/editor/components/scroll-query.d.ts +7 -0
  36. package/build/esm/editor/components/scroll-query.js +22 -0
  37. package/build/esm/editor/components/start-page.d.ts +13 -0
  38. package/build/esm/editor/components/start-page.js +32 -0
  39. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +3 -0
  40. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +30 -0
  41. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +5 -0
  42. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +50 -0
  43. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +4 -0
  44. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +40 -0
  45. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
  46. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +150 -0
  47. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
  48. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +39 -0
  49. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
  50. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
  51. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
  52. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +46 -0
  53. package/build/esm/editor/http/admin/editor/editor.d.ts +1 -0
  54. package/build/esm/editor/http/admin/editor/editor.js +8 -0
  55. package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
  56. package/build/esm/editor/http/admin/editor/index.api.js +22 -0
  57. package/build/esm/editor/server.d.ts +3 -0
  58. package/build/esm/editor/server.js +49 -0
  59. package/build/esm/editor/ws.d.ts +3 -0
  60. package/build/esm/editor/ws.js +11 -0
  61. package/build/esm/src/inflate/inflate-sea.js +8 -1
  62. package/build/esm/src/services/app.js +7 -2
  63. package/build/lib.cjs +14 -3
  64. package/editor/auth.ts +51 -0
  65. package/editor/common/admin-interface.ts +84 -0
  66. package/editor/common/constants.server.ts +5 -0
  67. package/editor/common/constants.ts +21 -0
  68. package/editor/common/editor-index.tsx +17 -0
  69. package/editor/common/html-encode.ts +14 -0
  70. package/editor/common/log-socket.tsx +87 -0
  71. package/editor/common/templates.ts +481 -0
  72. package/editor/components/api-preview.tsx +118 -0
  73. package/editor/components/editor.tsx +496 -0
  74. package/editor/components/file-browser.tsx +311 -0
  75. package/editor/components/file-editor-toolbar.tsx +194 -0
  76. package/editor/components/file-editor.tsx +125 -0
  77. package/editor/components/filter-query.tsx +26 -0
  78. package/editor/components/highlight-text-area.tsx +148 -0
  79. package/editor/components/log-viewer.tsx +113 -0
  80. package/editor/components/new-file.tsx +172 -0
  81. package/editor/components/scroll-query.tsx +25 -0
  82. package/editor/components/start-page.tsx +52 -0
  83. package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
  84. package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
  85. package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
  86. package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
  87. package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
  88. package/editor/http/admin/editor/api/server/reload.api.ts +53 -0
  89. package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
  90. package/editor/http/admin/editor/editor.tsx +10 -0
  91. package/editor/http/admin/editor/index.api.tsx +42 -0
  92. package/editor/server.ts +57 -0
  93. package/editor/ws.ts +15 -0
  94. package/package.json +2 -2
  95. package/src/bin/compile.ts +35 -0
  96. package/src/bin/doc-md.ts +210 -0
  97. package/src/bin/generate-doc.ts +64 -0
  98. package/src/bin/test.ts +92 -0
  99. package/src/bin/types.ts +34 -0
  100. package/src/cluster.ts +27 -0
  101. package/src/common/arguments.ts +762 -0
  102. package/src/common/assets.ts +148 -0
  103. package/src/common/checksum.ts +58 -0
  104. package/src/common/constants.ts +18 -0
  105. package/src/common/content-type.ts +84 -0
  106. package/src/common/esbuild.ts +102 -0
  107. package/src/common/exit.ts +91 -0
  108. package/src/common/fs.ts +82 -0
  109. package/src/common/help.ts +60 -0
  110. package/src/common/jsx.ts +562 -0
  111. package/src/common/jwt.ts +85 -0
  112. package/src/common/paths.ts +107 -0
  113. package/src/common/watch.ts +88 -0
  114. package/src/inflate/inflate-sea.ts +244 -0
  115. package/src/inflate/inflate.ts +101 -0
  116. package/src/inflate/md.ts +25 -0
  117. package/src/inflate/setup-auth.ts +41 -0
  118. package/src/inflate/setup-cors.ts +41 -0
  119. package/src/inflate/setup-db.ts +117 -0
  120. package/src/inflate/setup-error.ts +44 -0
  121. package/src/inflate/setup-http.ts +704 -0
  122. package/src/inflate/setup-log.ts +45 -0
  123. package/src/inflate/setup-middleware.ts +47 -0
  124. package/src/inflate/setup-server-config.ts +48 -0
  125. package/src/inflate/setup-test.ts +23 -0
  126. package/src/inflate/setup-ws.ts +50 -0
  127. package/src/inflate/setup.doc.ts +92 -0
  128. package/src/inflate/utils/sea-utils.ts +14 -0
  129. package/src/lib.ts +34 -0
  130. package/src/main.ts +101 -0
  131. package/src/services/app.ts +703 -0
  132. package/src/services/editor.tsx +101 -0
  133. package/src/services/globals.ts.ignore +186 -0
  134. package/src/services/hot-reload.ts +51 -0
  135. package/src/services/migrations.ts +68 -0
  136. package/src/services/utils/admin-interface.ts +37 -0
  137. package/src/services/utils/cache.ts +88 -0
  138. package/src/services/utils/cluster-cache.ts +230 -0
  139. package/src/services/utils/cluster-ws.ts +202 -0
  140. package/src/services/utils/db-manager.ts +92 -0
  141. package/src/services/utils/get-route.ts +70 -0
  142. package/src/services/utils/jwt.ts +25 -0
  143. package/src/services/utils/log-transport.ts +81 -0
  144. package/src/services/utils/log.ts +92 -0
  145. package/src/services/utils/middleware.ts +10 -0
  146. package/src/services/utils/server-interface.ts +122 -0
  147. package/src/services/utils/websocketmanager.ts +157 -0
  148. package/src/types.ts +307 -0
@@ -0,0 +1,6 @@
1
+ import { AuthConfig } from "../src/types.js";
2
+ export declare const ADMIN_EDITOR_AUTH_KEY = "$$ADMIN_EDITOR_AUTH_KEY$$";
3
+ export declare const ADMIN_EDITOR_AUTH_QUERY = "key";
4
+ export declare const ADMIN_EDITOR_AUTH_COOKIE = "$$ADMIN_EDITOR_AUTH_KEY$$";
5
+ declare const _default: AuthConfig;
6
+ export default _default;
@@ -0,0 +1,41 @@
1
+ export const ADMIN_EDITOR_AUTH_KEY = "$$ADMIN_EDITOR_AUTH_KEY$$";
2
+ export const ADMIN_EDITOR_AUTH_QUERY = "key";
3
+ export const ADMIN_EDITOR_AUTH_COOKIE = ADMIN_EDITOR_AUTH_KEY;
4
+ export default {
5
+ authService: {
6
+ verify: async (args) => {
7
+ const adminInterface = args.req.editor;
8
+ const serverInterface = args.req.server;
9
+ const KEY = (adminInterface ? adminInterface.getCache() : serverInterface.cache).get(ADMIN_EDITOR_AUTH_KEY);
10
+ const validSesson = {
11
+ username: "username",
12
+ account: "account",
13
+ groups: [],
14
+ token: args.token
15
+ };
16
+ const queryToken = args.req.query[ADMIN_EDITOR_AUTH_QUERY];
17
+ const cookieToken = args.req.cookies[ADMIN_EDITOR_AUTH_COOKIE];
18
+ //console.log("\n\nqueryToken[%s] cookieToken[%s] KEY[%s]\n\n", queryToken, cookieToken, KEY);
19
+ if (queryToken) {
20
+ if (queryToken === KEY) {
21
+ args.res.setCookie(ADMIN_EDITOR_AUTH_COOKIE, KEY, {
22
+ expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 31 * 12 * 500),
23
+ httpOnly: true,
24
+ //secure: true,
25
+ path: "/",
26
+ //sameSite: "strict"
27
+ });
28
+ args.req.searchParams.delete(ADMIN_EDITOR_AUTH_QUERY);
29
+ const queryString = args.req.searchParams.toString();
30
+ const redirect = args.req.path + (queryString ? "?" + queryString : "");
31
+ await args.res.redirect(redirect);
32
+ return validSesson;
33
+ }
34
+ }
35
+ else if (cookieToken) {
36
+ return cookieToken === KEY ? validSesson : null;
37
+ }
38
+ return null;
39
+ },
40
+ }
41
+ };
@@ -0,0 +1,36 @@
1
+ import { RouterHandlerOptions } from "@miqro/core";
2
+ import { CacheInterface, ServerRequest } from "../../src/types.js";
3
+ import { MigrationModule } from "../../src/inflate/setup-db.js";
4
+ export interface EditorAdminInterface {
5
+ getCache: () => CacheInterface;
6
+ getMigrations(): MigrationModule[];
7
+ stop: () => Promise<void>;
8
+ reload: () => Promise<null | {
9
+ filePath: string;
10
+ error: Error;
11
+ }[]>;
12
+ restart: () => Promise<null | {
13
+ filePath: string;
14
+ error: Error;
15
+ }[]>;
16
+ getHotReloadHTML(): string;
17
+ getInflateErrors(): null | {
18
+ filePath: string;
19
+ error: Error;
20
+ }[];
21
+ getServices(): string[];
22
+ getRouteFileMap(): {
23
+ [filePath: string]: {
24
+ routes: {
25
+ path?: string;
26
+ method?: string | null;
27
+ options?: RouterHandlerOptions;
28
+ inflatePath?: string;
29
+ }[];
30
+ previewMethod: "api" | "html" | null;
31
+ };
32
+ };
33
+ }
34
+ export interface AdminRequest extends ServerRequest {
35
+ editor?: EditorAdminInterface;
36
+ }
@@ -0,0 +1,44 @@
1
+ export {};
2
+ /*let currentAdminInterface: EditorAdminInterface | null = null;
3
+ function createFakeAdminInterface(server: any): EditorAdminInterface {
4
+ return {
5
+ getCache: () => {
6
+ return server.cache;
7
+ },
8
+ stop: async () => {
9
+
10
+ },
11
+ restart: async () => {
12
+ return null;
13
+ },
14
+ reload: async () => {
15
+ return null;
16
+ },
17
+ getHotReloadHTML: () => {
18
+ return "";
19
+ },
20
+ getMigrations: () => {
21
+ return [];
22
+ },
23
+ getServices: () => {
24
+ return ["."];
25
+ },
26
+ getRouteFileMap: () => {
27
+ return {};
28
+ },
29
+ getInflateErrors: () => {
30
+ return [];
31
+ },
32
+ inflateJSX: async function inflateJSX(path, minify: boolean = true) {
33
+ return "";
34
+ }
35
+ }
36
+ }
37
+
38
+ export function getEditorAdmin(server): EditorAdminInterface {
39
+ return currentAdminInterface ? currentAdminInterface : createFakeAdminInterface(server);
40
+ }
41
+
42
+ export function setEditorAdmin(admin: EditorAdminInterface): void {
43
+ currentAdminInterface = admin;
44
+ }*/
@@ -0,0 +1,4 @@
1
+ export declare const BASEEDITOR_PATH = "/admin/editor";
2
+ export declare const LOG_SOCKET_PATH = "/admin/socket";
3
+ export declare const LOG_WRITE_EVENT = "LogWrite";
4
+ export declare const SUPPORTED_LANGUAGES: string[];
@@ -0,0 +1,20 @@
1
+ export const BASEEDITOR_PATH = "/admin/editor";
2
+ export const LOG_SOCKET_PATH = "/admin/socket";
3
+ export const LOG_WRITE_EVENT = "LogWrite";
4
+ export const SUPPORTED_LANGUAGES = [
5
+ "text",
6
+ "json",
7
+ "javascript",
8
+ "typescript",
9
+ "dockerfile",
10
+ "yaml",
11
+ "xml",
12
+ "html",
13
+ "css",
14
+ "scss",
15
+ "markdown",
16
+ "c",
17
+ "cpp",
18
+ "bash",
19
+ "python"
20
+ ];
@@ -0,0 +1,2 @@
1
+ export declare const PORT: string;
2
+ export declare const BASE_PATH: string;
@@ -0,0 +1,4 @@
1
+ import { resolve } from "node:path";
2
+ import { cwd } from "node:process";
3
+ export const PORT = process.env["PORT"] ? process.env["PORT"] : "8080";
4
+ export const BASE_PATH = resolve(cwd());
@@ -0,0 +1,2 @@
1
+ import { AdminRequest } from "./admin-interface.js";
2
+ export declare function EditorIndex(editorCSS: string, editorJS: string, enableHotReload: boolean): (req: AdminRequest, res: any) => Promise<void>;
@@ -0,0 +1,14 @@
1
+ import { scanDir } from "../http/admin/editor/api/fs/scan.api.js";
2
+ import { parseInflateErrors } from "../http/admin/editor/api/server/restart.api.js";
3
+ import { HTMLEncode } from "./html-encode.js";
4
+ export function EditorIndex(editorCSS, editorJS, enableHotReload) {
5
+ return async function editorIndex(req, res) {
6
+ const admin = req.editor;
7
+ const errors = parseInflateErrors(admin ? admin.getInflateErrors() : []);
8
+ const files = scanDir(req);
9
+ const migrations = admin ? admin.getMigrations().map(m => m.name) : [];
10
+ const services = admin ? admin.getServices() : ["."];
11
+ const hotReload = enableHotReload ? (admin ? admin.getHotReloadHTML() : "") : "";
12
+ res.html(`<!DOCTYPE html><html><body><style>${editorCSS}</style><script type="module">${editorJS}</script><editor-component class="main-container" reloadstring="${req.uuid}" migrations="${HTMLEncode(JSON.stringify(migrations))}" services="${HTMLEncode(JSON.stringify(services))}" errors="${HTMLEncode(JSON.stringify(errors))}" files="${HTMLEncode(JSON.stringify(files))}"><noscript>Enable JavaScript</noscript></editor-component>${hotReload}</body></html>`);
13
+ };
14
+ }
@@ -0,0 +1 @@
1
+ export declare function HTMLEncode(str: string): string;
@@ -0,0 +1,14 @@
1
+ export function HTMLEncode(str) {
2
+ let i = str.length;
3
+ const aRet = [];
4
+ while (i--) {
5
+ const iC = str[i].charCodeAt(0);
6
+ if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) {
7
+ aRet[i] = '&#' + iC + ';';
8
+ }
9
+ else {
10
+ aRet[i] = str[i];
11
+ }
12
+ }
13
+ return aRet.join('');
14
+ }
@@ -0,0 +1,15 @@
1
+ interface LogLine {
2
+ out: string;
3
+ identifier: string;
4
+ level: "error" | "warn" | "debug" | "trace" | "info";
5
+ }
6
+ export interface LogSocket {
7
+ lines: LogLine[];
8
+ clearLog: () => void;
9
+ getMaxlogsize: () => number | "unlimited";
10
+ setMaxLogSize: (val: number | "unlimited") => void;
11
+ }
12
+ export declare function useLogSocket(options: {
13
+ disableLog?: boolean;
14
+ }): LogSocket;
15
+ export {};
@@ -0,0 +1,71 @@
1
+ import * as jsx from "@miqro/jsx";
2
+ export function useLogSocket(options) {
3
+ const [_, setmaxLogSize, getMaxlogsize] = jsx.useState(1000000);
4
+ const [__, setlines, getLines] = jsx.useState([]);
5
+ const refresh = jsx.useRefresh();
6
+ jsx.useEffect(() => {
7
+ let timeout;
8
+ function setupSocket() {
9
+ try {
10
+ if (options.disableLog) {
11
+ return;
12
+ }
13
+ console.log("setting up log socket");
14
+ const socket = new WebSocket("/admin/socket");
15
+ socket.addEventListener("error", (err) => {
16
+ console.error(err);
17
+ clearTimeout(timeout);
18
+ timeout = setTimeout(() => {
19
+ setupSocket();
20
+ }, 1000);
21
+ });
22
+ socket.addEventListener("open", () => {
23
+ console.log("log socket open");
24
+ clearTimeout(timeout);
25
+ socket.addEventListener("message", (msg) => {
26
+ const lines = getLines();
27
+ const data = JSON.parse(msg.data);
28
+ //console.log(data.out);
29
+ const maxLogSize = getMaxlogsize();
30
+ if (maxLogSize !== "unlimited" && lines.length >= maxLogSize) {
31
+ lines.splice(0, (lines.length - maxLogSize) + 1);
32
+ }
33
+ lines.push(data);
34
+ setlines(lines);
35
+ refresh();
36
+ });
37
+ });
38
+ socket.addEventListener("close", () => {
39
+ console.log("log socket close");
40
+ clearTimeout(timeout);
41
+ timeout = setTimeout(() => {
42
+ setupSocket();
43
+ }, 1000);
44
+ });
45
+ }
46
+ catch (e) {
47
+ console.error(e);
48
+ clearTimeout(timeout);
49
+ timeout = setTimeout(() => {
50
+ setupSocket();
51
+ }, 1000);
52
+ }
53
+ }
54
+ setupSocket();
55
+ }, []);
56
+ return {
57
+ lines: getLines(),
58
+ clearLog: () => {
59
+ setlines([]);
60
+ },
61
+ getMaxlogsize,
62
+ setMaxLogSize: (newValue) => {
63
+ if (newValue === "unlimited") {
64
+ setmaxLogSize(newValue);
65
+ }
66
+ else {
67
+ setmaxLogSize(newValue);
68
+ }
69
+ }
70
+ };
71
+ }
@@ -0,0 +1,11 @@
1
+ export declare const TEMPLATES: {
2
+ [name: string]: {
3
+ displayName: string;
4
+ template?: ((filename: string, httpPath: string) => string);
5
+ httpSufix?: string;
6
+ sufix?: string;
7
+ prefix?: string;
8
+ language: string;
9
+ filename?: string;
10
+ };
11
+ };