miqro 7.2.7 → 7.2.8
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.
- package/build/esm/editor/auth.d.ts +6 -0
- package/build/esm/editor/auth.js +42 -0
- package/build/esm/editor/common/constants.d.ts +4 -0
- package/build/esm/editor/common/constants.js +20 -0
- package/build/esm/editor/common/constants.server.d.ts +2 -0
- package/build/esm/editor/common/constants.server.js +4 -0
- package/build/esm/editor/common/editor-index.d.ts +2 -0
- package/build/esm/editor/common/editor-index.js +14 -0
- package/build/esm/editor/common/html-encode.d.ts +1 -0
- package/build/esm/editor/common/html-encode.js +14 -0
- package/build/esm/editor/common/log-socket.d.ts +15 -0
- package/build/esm/editor/common/log-socket.js +71 -0
- package/build/esm/editor/common/templates.d.ts +11 -0
- package/build/esm/editor/common/templates.js +477 -0
- package/build/esm/editor/components/api-preview.d.ts +11 -0
- package/build/esm/editor/components/api-preview.js +92 -0
- package/build/esm/editor/components/editor.d.ts +16 -0
- package/build/esm/editor/components/editor.js +367 -0
- package/build/esm/editor/components/file-browser.d.ts +37 -0
- package/build/esm/editor/components/file-browser.js +127 -0
- package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
- package/build/esm/editor/components/file-editor-toolbar.js +95 -0
- package/build/esm/editor/components/file-editor.d.ts +32 -0
- package/build/esm/editor/components/file-editor.js +61 -0
- package/build/esm/editor/components/filter-query.d.ts +1 -0
- package/build/esm/editor/components/filter-query.js +23 -0
- package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
- package/build/esm/editor/components/highlight-text-area.js +127 -0
- package/build/esm/editor/components/log-viewer.d.ts +6 -0
- package/build/esm/editor/components/log-viewer.js +71 -0
- package/build/esm/editor/components/new-file.d.ts +10 -0
- package/build/esm/editor/components/new-file.js +119 -0
- package/build/esm/editor/components/scroll-query.d.ts +7 -0
- package/build/esm/editor/components/scroll-query.js +22 -0
- package/build/esm/editor/components/start-page.d.ts +13 -0
- package/build/esm/editor/components/start-page.js +32 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +4 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +30 -0
- package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +7 -0
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js +50 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +7 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +40 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +150 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js +39 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js +46 -0
- package/build/esm/editor/http/admin/editor/editor.d.ts +1 -0
- package/build/esm/editor/http/admin/editor/editor.js +8 -0
- package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
- package/build/esm/editor/http/admin/editor/index.api.js +23 -0
- package/build/esm/editor/server.d.ts +3 -0
- package/build/esm/editor/server.js +49 -0
- package/build/esm/editor/ws.d.ts +3 -0
- package/build/esm/editor/ws.js +12 -0
- package/build/esm/src/common/admin-interface.d.ts +36 -0
- package/build/esm/src/common/admin-interface.js +44 -0
- package/build/esm/src/services/app.d.ts +1 -1
- package/build/esm/src/services/editor.d.ts +1 -1
- package/build/esm/src/services/utils/admin-interface.d.ts +1 -1
- package/build/esm/src/services/utils/websocketmanager.d.ts +1 -1
- package/editor/auth.ts +52 -0
- package/editor/common/constants.server.ts +5 -0
- package/editor/common/constants.ts +21 -0
- package/editor/common/editor-index.tsx +17 -0
- package/editor/common/html-encode.ts +14 -0
- package/editor/common/log-socket.tsx +87 -0
- package/editor/common/templates.ts +481 -0
- package/editor/components/api-preview.tsx +118 -0
- package/editor/components/editor.tsx +496 -0
- package/editor/components/file-browser.tsx +311 -0
- package/editor/components/file-editor-toolbar.tsx +194 -0
- package/editor/components/file-editor.tsx +125 -0
- package/editor/components/filter-query.tsx +26 -0
- package/editor/components/highlight-text-area.tsx +148 -0
- package/editor/components/log-viewer.tsx +113 -0
- package/editor/components/new-file.tsx +172 -0
- package/editor/components/scroll-query.tsx +25 -0
- package/editor/components/start-page.tsx +52 -0
- package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
- package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
- package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
- package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
- package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
- package/editor/http/admin/editor/api/server/reload.api.ts +53 -0
- package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
- package/editor/http/admin/editor/editor.tsx +10 -0
- package/editor/http/admin/editor/index.api.tsx +43 -0
- package/editor/server.ts +57 -0
- package/editor/ws.ts +17 -0
- package/package.json +1 -1
|
@@ -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 "../../src/common/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
|
+
}
|