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,84 @@
1
+ import { RouterHandlerOptions } from "@miqro/core";
2
+ import { CacheInterface, ServerRequest } from "../../src/types.js";
3
+ import { MigrationModule } from "../../src/inflate/setup-db.js";
4
+
5
+ export interface EditorAdminInterface {
6
+ getCache: () => CacheInterface;
7
+ //inflateJSX: (path: string, minify?: boolean) => Promise<string>;
8
+ getMigrations(): MigrationModule[];
9
+ stop: () => Promise<void>;
10
+ reload: () => Promise<null | {
11
+ filePath: string;
12
+ error: Error;
13
+ }[]>;
14
+ restart: () => Promise<null | {
15
+ filePath: string;
16
+ error: Error;
17
+ }[]>;
18
+ getHotReloadHTML(): string;
19
+ getInflateErrors(): null | {
20
+ filePath: string;
21
+ error: Error;
22
+ }[];
23
+ getServices(): string[];
24
+ getRouteFileMap(): {
25
+ [filePath: string]: {
26
+ routes: {
27
+ path?: string;
28
+ method?: string | null;
29
+ options?: RouterHandlerOptions;
30
+ inflatePath?: string;
31
+ }[];
32
+ previewMethod: "api" | "html" | null;
33
+ }
34
+ };
35
+ }
36
+
37
+ export interface AdminRequest extends ServerRequest {
38
+ editor?: EditorAdminInterface;
39
+ }
40
+
41
+ /*let currentAdminInterface: EditorAdminInterface | null = null;
42
+ function createFakeAdminInterface(server: any): EditorAdminInterface {
43
+ return {
44
+ getCache: () => {
45
+ return server.cache;
46
+ },
47
+ stop: async () => {
48
+
49
+ },
50
+ restart: async () => {
51
+ return null;
52
+ },
53
+ reload: async () => {
54
+ return null;
55
+ },
56
+ getHotReloadHTML: () => {
57
+ return "";
58
+ },
59
+ getMigrations: () => {
60
+ return [];
61
+ },
62
+ getServices: () => {
63
+ return ["."];
64
+ },
65
+ getRouteFileMap: () => {
66
+ return {};
67
+ },
68
+ getInflateErrors: () => {
69
+ return [];
70
+ },
71
+ inflateJSX: async function inflateJSX(path, minify: boolean = true) {
72
+ return "";
73
+ }
74
+ }
75
+ }
76
+
77
+ export function getEditorAdmin(server): EditorAdminInterface {
78
+ return currentAdminInterface ? currentAdminInterface : createFakeAdminInterface(server);
79
+ }
80
+
81
+ export function setEditorAdmin(admin: EditorAdminInterface): void {
82
+ currentAdminInterface = admin;
83
+ }*/
84
+
@@ -0,0 +1,5 @@
1
+ import { resolve } from "node:path";
2
+ import { cwd } from "node:process";
3
+
4
+ export const PORT = process.env["PORT"] ? process.env["PORT"] : "8080";
5
+ export const BASE_PATH = resolve(cwd());
@@ -0,0 +1,21 @@
1
+ export const BASEEDITOR_PATH = "/admin/editor";
2
+ export const LOG_SOCKET_PATH = "/admin/socket";
3
+ export const LOG_WRITE_EVENT = "LogWrite";
4
+
5
+ export const SUPPORTED_LANGUAGES = [
6
+ "text",
7
+ "json",
8
+ "javascript",
9
+ "typescript",
10
+ "dockerfile",
11
+ "yaml",
12
+ "xml",
13
+ "html",
14
+ "css",
15
+ "scss",
16
+ "markdown",
17
+ "c",
18
+ "cpp",
19
+ "bash",
20
+ "python"
21
+ ];
@@ -0,0 +1,17 @@
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 { AdminRequest } from "./admin-interface.js";
4
+ import { HTMLEncode } from "./html-encode.js";
5
+
6
+ export function EditorIndex(editorCSS: string, editorJS: string, enableHotReload: boolean) {
7
+ return async function editorIndex(req: AdminRequest, res) {
8
+ const admin = req.editor;
9
+
10
+ const errors = parseInflateErrors(admin ? admin.getInflateErrors() : []);
11
+ const files = scanDir(req);
12
+ const migrations = admin ? admin.getMigrations().map(m => m.name) : [];
13
+ const services = admin ? admin.getServices() : ["."];
14
+ const hotReload = enableHotReload ? (admin ? admin.getHotReloadHTML() : "") : "";
15
+ 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>`)
16
+ }
17
+ }
@@ -0,0 +1,14 @@
1
+ export function HTMLEncode(str: string): string {
2
+ let i = str.length;
3
+ const aRet: string[] = [];
4
+
5
+ while (i--) {
6
+ const iC = str[i].charCodeAt(0);
7
+ if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) {
8
+ aRet[i] = '&#' + iC + ';';
9
+ } else {
10
+ aRet[i] = str[i];
11
+ }
12
+ }
13
+ return aRet.join('');
14
+ }
@@ -0,0 +1,87 @@
1
+ import * as jsx from "@miqro/jsx";
2
+
3
+ interface LogLine { out: string; identifier: string; level: "error" | "warn" | "debug" | "trace" | "info" }
4
+
5
+ export interface LogSocket {
6
+ lines: LogLine[];
7
+ clearLog: () => void;
8
+ getMaxlogsize: () => number | "unlimited";
9
+ setMaxLogSize: (val: number | "unlimited") => void;
10
+ }
11
+
12
+ export function useLogSocket(options: { disableLog?: boolean; }): LogSocket {
13
+
14
+ const [_, setmaxLogSize, getMaxlogsize] = jsx.useState<number | "unlimited">(1000000);
15
+
16
+ const [__, setlines, getLines] = jsx.useState<LogLine[]>([]);
17
+ const refresh = jsx.useRefresh();
18
+
19
+ jsx.useEffect(() => {
20
+
21
+ let timeout;
22
+
23
+ function setupSocket() {
24
+ try {
25
+ if (options.disableLog) {
26
+ return;
27
+ }
28
+ console.log("setting up log socket");
29
+ const socket = new WebSocket("/admin/socket");
30
+ socket.addEventListener("error", (err) => {
31
+ console.error(err);
32
+ clearTimeout(timeout);
33
+ timeout = setTimeout(() => {
34
+ setupSocket();
35
+ }, 1000);
36
+ });
37
+ socket.addEventListener("open", () => {
38
+ console.log("log socket open");
39
+ clearTimeout(timeout);
40
+ socket.addEventListener("message", (msg) => {
41
+ const lines = getLines();
42
+ const data = JSON.parse(msg.data);
43
+ //console.log(data.out);
44
+ const maxLogSize = getMaxlogsize();
45
+ if (maxLogSize !== "unlimited" && lines.length >= maxLogSize) {
46
+ lines.splice(0, (lines.length - maxLogSize) + 1);
47
+ }
48
+ lines.push(data);
49
+ setlines(lines);
50
+ refresh();
51
+ });
52
+ });
53
+ socket.addEventListener("close", () => {
54
+ console.log("log socket close");
55
+ clearTimeout(timeout);
56
+ timeout = setTimeout(() => {
57
+ setupSocket();
58
+ }, 1000);
59
+ });
60
+ } catch (e) {
61
+ console.error(e);
62
+ clearTimeout(timeout);
63
+ timeout = setTimeout(() => {
64
+ setupSocket();
65
+ }, 1000);
66
+ }
67
+ }
68
+
69
+ setupSocket();
70
+ }, []);
71
+
72
+ return {
73
+ lines: getLines(),
74
+ clearLog: () => {
75
+ setlines([]);
76
+ },
77
+ getMaxlogsize,
78
+ setMaxLogSize: (newValue: number | "unlimited") => {
79
+ if (newValue === "unlimited") {
80
+ setmaxLogSize(newValue);
81
+ } else {
82
+ setmaxLogSize(newValue);
83
+ }
84
+
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,481 @@
1
+ export 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
+ } = {
12
+ EMPTY: {
13
+ displayName: "empty file",
14
+ //template: () => "",
15
+ sufix: "",
16
+ language: "text",
17
+ prefix: ""
18
+ },
19
+ JSON: {
20
+ displayName: "a .json.ts file",
21
+ template: () => `import { ServerRequest, ServerResponse } from "miqro";
22
+
23
+ export default async (req: ServerRequest | null, res: ServerResponse | null) => {
24
+ return {
25
+ count: 1
26
+ }
27
+ }`,
28
+ sufix: ".json.ts",
29
+ language: "typescript",
30
+ prefix: ""
31
+ },
32
+ API: {
33
+ prefix: "http",
34
+ sufix: ".api.ts",
35
+ displayName: ".api.ts file",
36
+ language: "typescript",
37
+ template: () => `import { ServerRequest, ServerResponse, APIRoute } from "miqro";
38
+
39
+ export default {
40
+ path: "/health",
41
+ description: "checks the health of the service",
42
+ method: "GET",
43
+ //middleware: [server.middleware.json()],
44
+ request: {
45
+ /*body: {
46
+ someAttr: "string",
47
+ optionalArray: "number[]?"
48
+ }*/
49
+ },
50
+ response: {
51
+ status: [200, 400],
52
+ body: {
53
+ status: {
54
+ type: "enum",
55
+ enumValues: ["OK", "NOK"]
56
+ },
57
+ message: "string?"
58
+ }
59
+ },
60
+ handler: async (req: ServerRequest, res: ServerResponse) => {
61
+ try {
62
+ const [{ c }] = await req?.server?.db?.get("MyDB")?.query("SELECT 1+1 as c") as [{ c: number }];
63
+ const statusText = String(c) === "2" ? "OK" : "NOK";
64
+ return {
65
+ status: statusText === "OK" ? 200 : 400,
66
+ body: {
67
+ status: statusText
68
+ }
69
+ }
70
+ } catch (e) {
71
+ req.logger.error(e);
72
+ return {
73
+ status: 400,
74
+ body: {
75
+ status: "NOK",
76
+ message: e.message
77
+ }
78
+ };
79
+ }
80
+ }
81
+ } as APIRoute`
82
+ },
83
+ MIGRATION: {
84
+ prefix: "migration",
85
+ sufix: ".ts",
86
+ displayName: "migration file",
87
+ language: "typescript",
88
+ template: () => `import { Migration } from "miqro";
89
+
90
+ export default {
91
+ up: async (db, logger) => {
92
+ await db.createTable("mytable", {
93
+ id: {
94
+ type: "bigint",
95
+ autoIncrement: true,
96
+ primaryKey: true
97
+ },
98
+ name: {
99
+ type: "string"
100
+ }
101
+ }).yield(logger);
102
+ },
103
+ down: async (db, logger) => {
104
+ await db.dropTable("mytable").yield(logger);
105
+ }
106
+ } as Migration;`
107
+ },
108
+ TEST: {
109
+ prefix: "test",
110
+ sufix: ".test.tsx",
111
+ displayName: "a test file",
112
+ language: "typescript",
113
+ template: () => `import JSX from "@miqro/jsx";
114
+ import { strictEqual } from "node:assert";
115
+
116
+ describe("test group", () => {
117
+ it("sample test1", async () => {
118
+ const response = await test.request({
119
+ url: "/index.html"
120
+ });
121
+ strictEqual(response.status, 200);
122
+ });
123
+
124
+ it("sample test2", async () => {
125
+ await test.jsx.test(async (container, root, runtime) => {
126
+ function SomeComponent() {
127
+ return <p id="test-id">HelloWorld</p>
128
+ }
129
+ container.render(<SomeComponent />);
130
+ strictEqual(runtime.getElementById("test-id")?.textContent, "HelloWorld");
131
+ });
132
+ });
133
+ });
134
+ `
135
+ },
136
+ HTMLTSX: {
137
+ prefix: "http",
138
+ sufix: ".html.tsx",
139
+ displayName: ".html.tsx file",
140
+ language: "typescript",
141
+ template: () => `import JSX from "@miqro/jsx";
142
+ import { ServerRequest, ServerResponse, APIOptions } from "miqro";
143
+
144
+ /*export const apiOptions: APIOptions = {
145
+ path: ["/", "/index.html"],
146
+ method: ["GET"]
147
+ };*/
148
+
149
+ export default async (req: ServerRequest | null, res: ServerResponse | null) => {
150
+ return <html>
151
+ <head></head>
152
+ <body>
153
+ <h1>hello world!</h1>
154
+ </body>
155
+ </html>;
156
+ }`
157
+ },
158
+ AUTHCONFIG: {
159
+ prefix: "",
160
+ sufix: ".ts",
161
+ filename: "auth",
162
+ displayName: "auth.ts file",
163
+ language: "typescript",
164
+ template: () => `import { AuthConfig } from "miqro";
165
+
166
+ export default {
167
+ //path: ["/api/"], //optionaly specify a custom path list
168
+ /*options: {
169
+ tokenLocation: "free",// "query"//"cookie" //"header"
170
+ tokenLocationName: "x-auth"
171
+ },*/
172
+ authService: {
173
+ verify: async ({ token, req, res }) => {
174
+ // TODO Implement logic
175
+ return null;
176
+ /*return {
177
+ username: "username",
178
+ groups: ["someapi"],
179
+ account: "account",
180
+ token: ""
181
+ };*/
182
+ }
183
+ }
184
+ } as AuthConfig;
185
+ `
186
+ },
187
+ DOCCONFIG: {
188
+ prefix: "",
189
+ sufix: ".ts",
190
+ filename: "doc",
191
+ displayName: "doc.ts file",
192
+ language: "typescript",
193
+ template: () => `import { DocConfig } from "miqro";
194
+
195
+ export default {
196
+ // auto publish API documentation
197
+ publish: {
198
+ "/api/doc.html": {
199
+ type: "HTML", // can be "MD" | "JSON" | "HTML"
200
+ //all: true, // enable to show .html and other static resources
201
+ }
202
+ }
203
+ } as DocConfig;`
204
+ },
205
+ WSCONFIG: {
206
+ prefix: "",
207
+ sufix: ".ts",
208
+ filename: "ws",
209
+ displayName: "ws.ts file",
210
+ language: "typescript",
211
+ template: () => `import { WSConfig } from "miqro";
212
+
213
+ export default {
214
+ path: "/socket",
215
+ //disabled: true,
216
+ //maxConnections: 100,
217
+ /*onConnection(req) {
218
+
219
+ },*/
220
+ /*onDisconnect: (req) => {
221
+
222
+ },*/
223
+ /*onError: (req, error) => {
224
+
225
+ },*/
226
+ /*onMessage: (req, data) => {
227
+
228
+ },*/
229
+ validate(req) {
230
+ // TODO implement logic
231
+ return false;
232
+ },
233
+ } as WSConfig;
234
+ `
235
+ },
236
+ SERVERCONFIG: {
237
+ prefix: "",
238
+ sufix: ".ts",
239
+ filename: "server",
240
+ displayName: "server.ts file",
241
+ language: "typescript",
242
+ template: () => `import { ServerConfig } from "miqro";
243
+
244
+ export default {
245
+ preload: async (server) => {
246
+ server.logger.info("server preload");
247
+ /* uncomment code below to migrate-up the database "MyDB" before loading */
248
+ /*if (server?.isPrimaryWorker()) {
249
+ await server.db.migrate({ direction: "up", dbName: "MyDB" });
250
+ }*/
251
+ },
252
+ load: async (server) => {
253
+ server.logger.info("server loaded");
254
+ },
255
+ start: async (server) => {
256
+ server.logger.info("server started");
257
+ if (server.isPrimaryWorker()) {
258
+ try {
259
+ server.openBrowser("/index.html");
260
+ } catch (e) {
261
+ server.logger.error(e.message);
262
+ }
263
+ }
264
+ },
265
+ unload: (server) => {
266
+ server.logger.info("server unload");
267
+ },
268
+ stop: (server) => {
269
+ server.logger.info("server stop");
270
+ }
271
+ } as ServerConfig;
272
+ `},
273
+ TSCONFIGJSON: {
274
+ prefix: "",
275
+ sufix: ".json",
276
+ filename: "tsconfig",
277
+ displayName: "tsconfig.json file",
278
+ language: "json",
279
+ template: () => `{
280
+ "compilerOptions": {
281
+ "target": "es2022",
282
+ "noEmit": true,
283
+ "module": "NodeNext",
284
+ "moduleResolution": "nodenext",
285
+ "lib": ["es2021", "dom"],
286
+ "jsx": "react",
287
+ "jsxFactory": "JSX.createElement",
288
+ "jsxFragmentFactory": "JSX.Fragment"
289
+ }
290
+ }
291
+ `},
292
+ MIQROJSON: {
293
+ prefix: "",
294
+ sufix: ".json",
295
+ filename: "miqro",
296
+ displayName: "miqro.json file",
297
+ language: "json",
298
+ template: () => `{
299
+ "services": ["src/"],
300
+ "inflateDir": "build/",
301
+ "name": "server",
302
+ "browser": true,
303
+ "logFile": false,
304
+ "port": "3000"
305
+ }
306
+ `},
307
+ MINIFIEDJSX: {
308
+ prefix: "http",
309
+ sufix: ".min.tsx",
310
+ displayName: "min.tsx file",
311
+ language: "typescript",
312
+ template: () => `import JSX from "@miqro/jsx";
313
+ import { define } from "@miqro/jsx-dom";
314
+
315
+ export function MyComponent() {
316
+ return <p>HelloWorld</p>
317
+ }
318
+ window.addEventListener("load", (event) => {
319
+ define("my-tag", MyComponent, {
320
+ shadowInit: false,
321
+ observedAttributes: []
322
+ });
323
+ });
324
+ `},
325
+ JSX: {
326
+ prefix: "http",
327
+ sufix: ".tsx",
328
+ displayName: ".tsx file",
329
+ language: "typescript",
330
+ template: () => `import JSX from "@miqro/jsx";
331
+ import { define } from "@miqro/jsx-dom";
332
+
333
+ export function MyComponent() {
334
+ return <p>HelloWorld</p>
335
+ }
336
+ window.addEventListener("load", (event) => {
337
+ define("my-tag", MyComponent, {
338
+ shadowInit: false,
339
+ observedAttributes: []
340
+ });
341
+ });
342
+ `},
343
+ /*SSRTSX: {
344
+ prefix: "http",
345
+ sufix: ".tsx",
346
+ displayName: "an ssr component example using webcomponents",
347
+ language: "typescript",
348
+ httpSufix: ".js",
349
+ template: (_filename: string, httpPath: string) => `import { } from "miqro";
350
+
351
+ // TODO change this accordingly
352
+ const TAG = "my-tag";
353
+
354
+ function MyComponent(props, children) {
355
+ const [count, setcount] = jsx.useState(0);
356
+ jsx.useEffect(()=>{
357
+ const timeout = setTimeout(()=>{
358
+ setcount(count+1);
359
+ }, 1000);
360
+ return ()=>{
361
+ clearTimeout(timeout);
362
+ }
363
+ });
364
+ return <p>Count: {count}</p>
365
+ }
366
+
367
+ window.addEventListener("load", (event) => {
368
+ jsx.define(TAG, MyComponent, {
369
+ shadowInit: false,
370
+ observedAttributes: []
371
+ });
372
+ });
373
+
374
+ export function SSRComponent(props, children) {
375
+ return JSX.createElement(
376
+ JSX.Fragment, null,
377
+ JSX.createElement(TAG, props,
378
+ JSX.createElement(MyComponent, props, ...children)
379
+ ),
380
+ JSX.createElement("script", { type: "module", src: "/${httpPath}" })
381
+ );
382
+ }
383
+ `
384
+ },
385
+ SSRMINTSX: {
386
+ prefix: "http",
387
+ sufix: ".min.tsx",
388
+ displayName: "a minified ssr component example using webcomponents",
389
+ language: "typescript",
390
+ httpSufix: ".min.js",
391
+ template: (filename: string, httpPath: string) => `import { } from "miqro";
392
+
393
+ // TODO change this accordingly
394
+ const TAG = "my-tag";
395
+
396
+ function MyComponent(props, children) {
397
+ const [count, setcount] = jsx.useState(0);
398
+ jsx.useEffect(()=>{
399
+ const timeout = setTimeout(()=>{
400
+ setcount(count+1);
401
+ }, 1000);
402
+ return ()=>{
403
+ clearTimeout(timeout);
404
+ }
405
+ });
406
+ return <p>Count: {count}</p>
407
+ }
408
+
409
+ window.addEventListener("load", (event) => {
410
+ jsx.define(TAG, MyComponent, {
411
+ shadowInit: false,
412
+ observedAttributes: []
413
+ });
414
+ });
415
+
416
+ export function SSRComponent(props, children) {
417
+ return JSX.createElement(
418
+ JSX.Fragment, null,
419
+ JSX.createElement(TAG, props,
420
+ JSX.createElement(MyComponent, props, ...children)
421
+ ),
422
+ JSX.createElement("script", { type: "module", src: "/${httpPath}" })
423
+ );
424
+ }
425
+ `
426
+ },*/
427
+ JS: {
428
+ prefix: "http",
429
+ sufix: ".js",
430
+ displayName: ".js file",
431
+ language: "typescript",
432
+ template: () => `window.addEventListener("load", (event) => {
433
+
434
+ });
435
+ `},
436
+ CSS: {
437
+ prefix: "http",
438
+ sufix: ".css",
439
+ displayName: ".css file",
440
+ language: "css",
441
+ template: () => `* {
442
+ font-family: "Menlo" !important;
443
+ font-size: 11px;
444
+ }
445
+ `
446
+ },
447
+ DBCONFIG: {
448
+ prefix: "",
449
+ filename: "db",
450
+ sufix: ".ts",
451
+ displayName: "db.ts file",
452
+ language: "typescript",
453
+ template: () => `import { DBConfig } from "miqro";
454
+
455
+ export default {
456
+ //dialect: "node:sqlite"
457
+ //storage: "./db.sqlite3"
458
+ //url: "..."
459
+ //disabled: false,
460
+ name: "MyDB"
461
+ } as DBConfig`
462
+ },
463
+ CORS: {
464
+ prefix: "",
465
+ filename: "cors",
466
+ sufix: ".ts",
467
+ displayName: "cors.ts file",
468
+ language: "typescript",
469
+ template: () => `import { CORSConfig } from "miqro";
470
+
471
+ export default {
472
+ origins: "*",
473
+ /*validate: (origin: string, origins: string | string[]) => {
474
+ return false
475
+ },
476
+ methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
477
+ preflightContinue: false*/
478
+ } as CORSConfig;
479
+ `
480
+ }
481
+ }