miqro 6.3.0 → 7.0.1
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/README.md +9 -17
- package/build/editor.bundle.js +11601 -10129
- package/build/esm/src/bin/types.js +10 -5
- package/build/esm/src/cluster.js +1 -1
- package/build/esm/src/common/arguments.d.ts +1 -1
- package/build/esm/src/common/arguments.js +28 -14
- package/build/esm/src/common/assets.d.ts +1 -1
- package/build/esm/src/common/assets.js +34 -13
- package/build/esm/src/common/esbuild.d.ts +4 -1
- package/build/esm/src/common/esbuild.js +31 -26
- package/build/esm/src/common/exit.js +4 -4
- package/build/esm/src/common/help.d.ts +1 -1
- package/build/esm/src/common/help.js +0 -1
- package/build/esm/src/common/jsx.d.ts +2 -3
- package/build/esm/src/common/jsx.js +70 -75
- package/build/esm/src/common/paths.d.ts +0 -1
- package/build/esm/src/common/paths.js +3 -3
- package/build/esm/src/common/watch.d.ts +0 -1
- package/build/esm/src/common/watch.js +1 -1
- package/build/esm/src/inflate/inflate-sea.js +35 -24
- package/build/esm/src/inflate/inflate.js +4 -4
- package/build/esm/src/inflate/setup-auth.js +1 -1
- package/build/esm/src/inflate/setup-cors.js +1 -1
- package/build/esm/src/inflate/setup-db.js +2 -2
- package/build/esm/src/inflate/setup-error.js +1 -1
- package/build/esm/src/inflate/setup-http.js +16 -16
- package/build/esm/src/inflate/setup-log.js +1 -1
- package/build/esm/src/inflate/setup-middleware.js +1 -1
- package/build/esm/src/inflate/setup-server-config.js +1 -1
- package/build/esm/src/inflate/setup-ws.js +1 -1
- package/build/esm/src/inflate/setup.doc.d.ts +2 -2
- package/build/esm/src/inflate/setup.doc.js +23 -2
- package/build/esm/src/inflate/utils/sea-utils.js +2 -2
- package/build/esm/src/lib.d.ts +10 -1
- package/build/esm/src/lib.js +16 -1
- package/build/esm/src/main.js +1 -1
- package/build/esm/src/services/app.js +3 -4
- package/build/esm/src/services/migrations.js +2 -2
- package/build/esm/src/services/utils/jwt.d.ts +2 -0
- package/build/esm/src/services/utils/jwt.js +23 -0
- package/build/esm/src/services/utils/middleware.d.ts +9 -0
- package/build/esm/src/services/utils/middleware.js +9 -0
- package/build/esm/src/services/utils/server-interface.js +33 -4
- package/build/esm/src/types.d.ts +50 -83
- package/build/lib.cjs +15684 -15612
- package/package.json +6 -8
- package/sea/basic-compile.base64.sh +1 -1
- package/sea/basic-compile.sh +1 -1
- package/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +1 -1
- package/.eslintrc +0 -15
- package/build/esm/editor/auth.d.ts +0 -6
- package/build/esm/editor/auth.js +0 -41
- package/build/esm/editor/common/admin-interface.d.ts +0 -36
- package/build/esm/editor/common/admin-interface.js +0 -44
- package/build/esm/editor/common/constants.d.ts +0 -4
- package/build/esm/editor/common/constants.js +0 -20
- package/build/esm/editor/common/constants.server.d.ts +0 -2
- package/build/esm/editor/common/constants.server.js +0 -4
- package/build/esm/editor/common/editor-index.d.ts +0 -2
- package/build/esm/editor/common/editor-index.js +0 -14
- package/build/esm/editor/common/html-encode.d.ts +0 -1
- package/build/esm/editor/common/html-encode.js +0 -14
- package/build/esm/editor/common/log-socket.d.ts +0 -15
- package/build/esm/editor/common/log-socket.js +0 -70
- package/build/esm/editor/common/templates.d.ts +0 -11
- package/build/esm/editor/common/templates.js +0 -477
- package/build/esm/editor/components/api-preview.d.ts +0 -11
- package/build/esm/editor/components/api-preview.js +0 -90
- package/build/esm/editor/components/editor.d.ts +0 -16
- package/build/esm/editor/components/editor.js +0 -365
- package/build/esm/editor/components/file-browser.d.ts +0 -37
- package/build/esm/editor/components/file-browser.js +0 -126
- package/build/esm/editor/components/file-editor-toolbar.d.ts +0 -22
- package/build/esm/editor/components/file-editor-toolbar.js +0 -93
- package/build/esm/editor/components/file-editor.d.ts +0 -32
- package/build/esm/editor/components/file-editor.js +0 -59
- package/build/esm/editor/components/filter-query.d.ts +0 -1
- package/build/esm/editor/components/filter-query.js +0 -22
- package/build/esm/editor/components/highlight-text-area.d.ts +0 -11
- package/build/esm/editor/components/highlight-text-area.js +0 -125
- package/build/esm/editor/components/log-viewer.d.ts +0 -6
- package/build/esm/editor/components/log-viewer.js +0 -69
- package/build/esm/editor/components/new-file.d.ts +0 -10
- package/build/esm/editor/components/new-file.js +0 -117
- package/build/esm/editor/components/scroll-query.d.ts +0 -7
- package/build/esm/editor/components/scroll-query.js +0 -21
- package/build/esm/editor/components/start-page.d.ts +0 -13
- package/build/esm/editor/components/start-page.js +0 -30
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +0 -3
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +0 -29
- package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +0 -5
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js +0 -49
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +0 -4
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +0 -39
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +0 -26
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +0 -149
- package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +0 -3
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js +0 -38
- package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +0 -10
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js +0 -46
- package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +0 -10
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js +0 -45
- package/build/esm/editor/http/admin/editor/editor.d.ts +0 -1
- package/build/esm/editor/http/admin/editor/editor.js +0 -7
- package/build/esm/editor/http/admin/editor/index.api.d.ts +0 -3
- package/build/esm/editor/http/admin/editor/index.api.js +0 -21
- package/build/esm/editor/server.d.ts +0 -3
- package/build/esm/editor/server.js +0 -49
- package/build/esm/editor/ws.d.ts +0 -3
- package/build/esm/editor/ws.js +0 -11
- package/build/esm/src/services/globals.d.ts +0 -3
- package/build/esm/src/services/globals.js +0 -182
- package/build/jsx.dom.js +0 -1587
- package/build/postject.base64.cjs +0 -1
- package/editor/auth.ts +0 -51
- package/editor/common/admin-interface.ts +0 -84
- package/editor/common/constants.server.ts +0 -5
- package/editor/common/constants.ts +0 -21
- package/editor/common/editor-index.tsx +0 -17
- package/editor/common/html-encode.ts +0 -14
- package/editor/common/log-socket.tsx +0 -85
- package/editor/common/templates.ts +0 -481
- package/editor/components/api-preview.tsx +0 -116
- package/editor/components/editor.tsx +0 -494
- package/editor/components/file-browser.tsx +0 -308
- package/editor/components/file-editor-toolbar.tsx +0 -191
- package/editor/components/file-editor.tsx +0 -122
- package/editor/components/filter-query.tsx +0 -22
- package/editor/components/highlight-text-area.tsx +0 -145
- package/editor/components/log-viewer.tsx +0 -110
- package/editor/components/new-file.tsx +0 -169
- package/editor/components/scroll-query.tsx +0 -22
- package/editor/components/start-page.tsx +0 -49
- package/editor/http/admin/editor/api/fs/delete.api.tsx +0 -32
- package/editor/http/admin/editor/api/fs/read.api.tsx +0 -55
- package/editor/http/admin/editor/api/fs/rename.api.tsx +0 -41
- package/editor/http/admin/editor/api/fs/scan.api.tsx +0 -181
- package/editor/http/admin/editor/api/fs/write.api.tsx +0 -41
- package/editor/http/admin/editor/api/server/reload.api.ts +0 -53
- package/editor/http/admin/editor/api/server/restart.api.tsx +0 -52
- package/editor/http/admin/editor/editor.tsx +0 -8
- package/editor/http/admin/editor/index.api.tsx +0 -39
- package/editor/server.ts +0 -57
- package/editor/ws.ts +0 -15
- package/sea/types.json +0 -1
- package/src/bin/compile.ts +0 -35
- package/src/bin/doc-md.ts +0 -210
- package/src/bin/generate-doc.ts +0 -64
- package/src/bin/test.ts +0 -92
- package/src/bin/types.ts +0 -29
- package/src/cluster.ts +0 -27
- package/src/common/arguments.ts +0 -745
- package/src/common/assets.ts +0 -128
- package/src/common/checksum.ts +0 -58
- package/src/common/constants.ts +0 -18
- package/src/common/content-type.ts +0 -84
- package/src/common/esbuild.ts +0 -94
- package/src/common/exit.ts +0 -91
- package/src/common/fs.ts +0 -82
- package/src/common/help.ts +0 -61
- package/src/common/jsx.ts +0 -547
- package/src/common/jwt.ts +0 -85
- package/src/common/paths.ts +0 -107
- package/src/common/watch.ts +0 -88
- package/src/inflate/inflate-sea.ts +0 -226
- package/src/inflate/inflate.ts +0 -101
- package/src/inflate/md.ts +0 -25
- package/src/inflate/setup-auth.ts +0 -41
- package/src/inflate/setup-cors.ts +0 -41
- package/src/inflate/setup-db.ts +0 -117
- package/src/inflate/setup-error.ts +0 -44
- package/src/inflate/setup-http.ts +0 -704
- package/src/inflate/setup-log.ts +0 -45
- package/src/inflate/setup-middleware.ts +0 -47
- package/src/inflate/setup-server-config.ts +0 -48
- package/src/inflate/setup-test.ts +0 -23
- package/src/inflate/setup-ws.ts +0 -50
- package/src/inflate/setup.doc.ts +0 -68
- package/src/inflate/utils/sea-utils.ts +0 -14
- package/src/lib.ts +0 -19
- package/src/main.ts +0 -101
- package/src/services/app.ts +0 -699
- package/src/services/editor.tsx +0 -101
- package/src/services/globals.ts +0 -186
- package/src/services/hot-reload.ts +0 -51
- package/src/services/migrations.ts +0 -68
- package/src/services/utils/admin-interface.ts +0 -37
- package/src/services/utils/cache.ts +0 -88
- package/src/services/utils/cluster-cache.ts +0 -230
- package/src/services/utils/cluster-ws.ts +0 -202
- package/src/services/utils/db-manager.ts +0 -92
- package/src/services/utils/get-route.ts +0 -70
- package/src/services/utils/log-transport.ts +0 -81
- package/src/services/utils/log.ts +0 -92
- package/src/services/utils/server-interface.ts +0 -92
- package/src/services/utils/websocketmanager.ts +0 -157
- package/src/types/@esbuild.d.ts +0 -1
- package/src/types/@miqro/core.d.ts +0 -2
- package/src/types/@miqro/jsx.d.ts +0 -2
- package/src/types/@miqro/parser.d.ts +0 -2
- package/src/types/@miqro/query.d.ts +0 -2
- package/src/types/@miqro/request.d.ts +0 -2
- package/src/types/@miqro/test.d.ts +0 -2
- package/src/types/@miqro.d.ts +0 -1
- package/src/types/@types.d.ts +0 -1
- package/src/types/browser.globals.d.ts +0 -1
- package/src/types/cookie.d.ts +0 -2
- package/src/types/globals.d.ts +0 -2
- package/src/types/jose.d.ts +0 -2
- package/src/types/jsx.globals.d.ts +0 -38
- package/src/types/miqro.d.ts +0 -228
- package/src/types/postject.d.ts +0 -1
- package/src/types/server.globals.d.ts +0 -47
- package/src/types.ts +0 -304
- package/tsconfig.json +0 -35
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, renameSync } from "node:fs";
|
|
2
|
-
import { getPath } from "./read.api.js";
|
|
3
|
-
import { dirname } from "node:path";
|
|
4
|
-
export default {
|
|
5
|
-
middleware: [server.middleware.json()],
|
|
6
|
-
method: "POST",
|
|
7
|
-
description: "admin editor file rename endpoint",
|
|
8
|
-
path: "/rename",
|
|
9
|
-
request: {
|
|
10
|
-
body: {
|
|
11
|
-
path: "string",
|
|
12
|
-
newName: "string"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
response: {
|
|
16
|
-
status: [200, 400],
|
|
17
|
-
body: {
|
|
18
|
-
message: "string"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
handler: async (req, res) => {
|
|
22
|
-
const { path, newName } = req.body;
|
|
23
|
-
await rename(path, newName);
|
|
24
|
-
return res?.json({
|
|
25
|
-
message: "OK"
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
export async function rename(path, newName) {
|
|
30
|
-
if (existsSync(path) && !existsSync(newName)) {
|
|
31
|
-
mkdirSync(dirname(getPath(newName)), {
|
|
32
|
-
recursive: true
|
|
33
|
-
});
|
|
34
|
-
renameSync(getPath(path), getPath(newName));
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
throw new Error("invalid paths");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { APIRoute } from "@miqro/core";
|
|
2
|
-
import { AdminRequest } from "../../../../../common/admin-interface.js";
|
|
3
|
-
export interface ScannedFile {
|
|
4
|
-
filePath: string;
|
|
5
|
-
ext: string;
|
|
6
|
-
fileName: string;
|
|
7
|
-
name: string;
|
|
8
|
-
subExt: string;
|
|
9
|
-
subName: string;
|
|
10
|
-
language: string;
|
|
11
|
-
previewPath?: string;
|
|
12
|
-
dirs: string[];
|
|
13
|
-
apiPreview?: {
|
|
14
|
-
path: string;
|
|
15
|
-
method: string;
|
|
16
|
-
}[];
|
|
17
|
-
}
|
|
18
|
-
declare const _default: APIRoute;
|
|
19
|
-
export default _default;
|
|
20
|
-
export declare function scanDir(req: AdminRequest, basePath?: string, ret?: ScannedFile[]): ScannedFile[];
|
|
21
|
-
export declare function getLanguage(filePath: string): string;
|
|
22
|
-
export declare function getPreview(req: AdminRequest, filePath: string): undefined | string;
|
|
23
|
-
export declare function getAPIPreview(req: any, filePath: string): undefined | {
|
|
24
|
-
path: string;
|
|
25
|
-
method: string;
|
|
26
|
-
}[];
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, extname, relative, resolve, sep } from "node:path";
|
|
3
|
-
import { BASE_PATH } from "../../../../../common/constants.server.js";
|
|
4
|
-
export default {
|
|
5
|
-
method: "GET",
|
|
6
|
-
path: "/scan",
|
|
7
|
-
description: "admin editor file scan endpoint",
|
|
8
|
-
middleware: [server.middleware.json()],
|
|
9
|
-
request: {
|
|
10
|
-
body: false
|
|
11
|
-
},
|
|
12
|
-
response: {
|
|
13
|
-
status: [200, 400]
|
|
14
|
-
},
|
|
15
|
-
handler: async (req, res) => {
|
|
16
|
-
const admin = req.editor;
|
|
17
|
-
const services = admin ? admin.getServices() : ["."];
|
|
18
|
-
return res.json({
|
|
19
|
-
files: scanDir(req),
|
|
20
|
-
services
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
export function scanDir(req, basePath = BASE_PATH, ret = []) {
|
|
25
|
-
const admin = req.editor;
|
|
26
|
-
const services = admin ? admin.getServices() : ["."];
|
|
27
|
-
services.forEach(service => {
|
|
28
|
-
scanDirInternal(req, resolve(basePath, service), ret);
|
|
29
|
-
});
|
|
30
|
-
return ret;
|
|
31
|
-
}
|
|
32
|
-
function scanDirInternal(req, path = BASE_PATH, ret = []) {
|
|
33
|
-
if (!existsSync(path)) {
|
|
34
|
-
return ret;
|
|
35
|
-
}
|
|
36
|
-
const files = readdirSync(path);
|
|
37
|
-
for (const file of files) {
|
|
38
|
-
if (shouldIgnoreFile(file)) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
const filePath = resolve(path, file);
|
|
42
|
-
if (statSync(filePath).isDirectory()) {
|
|
43
|
-
scanDirInternal(req, filePath, ret);
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
const ext = extname(filePath);
|
|
48
|
-
const fileName = basename(filePath);
|
|
49
|
-
const name = fileName.substring(0, fileName.length - ext.length);
|
|
50
|
-
const subExt = extname(name);
|
|
51
|
-
const subName = name.substring(0, name.length - subExt.length);
|
|
52
|
-
ret.push({
|
|
53
|
-
dirs: getFileDirs(relative(BASE_PATH, filePath)),
|
|
54
|
-
language: getLanguage(filePath),
|
|
55
|
-
filePath: relative(BASE_PATH, filePath),
|
|
56
|
-
ext,
|
|
57
|
-
fileName,
|
|
58
|
-
name,
|
|
59
|
-
subExt,
|
|
60
|
-
subName,
|
|
61
|
-
previewPath: getPreview(req, filePath),
|
|
62
|
-
apiPreview: getAPIPreview(req, filePath)
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return ret;
|
|
67
|
-
}
|
|
68
|
-
function shouldIgnoreFile(file) {
|
|
69
|
-
return file === ".git" || file === ".types" || file === ".DS_Store" || file === "node_modules";
|
|
70
|
-
}
|
|
71
|
-
function getFileDirs(filePath) {
|
|
72
|
-
const dirs = [];
|
|
73
|
-
let dir = dirname(filePath);
|
|
74
|
-
while (dir !== sep && dir !== "" && dir !== "." && dir !== BASE_PATH) {
|
|
75
|
-
dirs.push(dir);
|
|
76
|
-
dir = dirname(dir);
|
|
77
|
-
}
|
|
78
|
-
return dirs.reverse().map(d => basename(d));
|
|
79
|
-
}
|
|
80
|
-
export function getLanguage(filePath) {
|
|
81
|
-
const ext = extname(filePath);
|
|
82
|
-
const fileName = basename(filePath);
|
|
83
|
-
switch (ext.toLocaleLowerCase()) {
|
|
84
|
-
case ".py":
|
|
85
|
-
return "python";
|
|
86
|
-
case ".sh":
|
|
87
|
-
return "bash";
|
|
88
|
-
case ".webmanifest":
|
|
89
|
-
case ".json":
|
|
90
|
-
return "json";
|
|
91
|
-
case ".xml":
|
|
92
|
-
return "xml";
|
|
93
|
-
case ".jsx":
|
|
94
|
-
case ".js":
|
|
95
|
-
return "javascript";
|
|
96
|
-
case ".tsx":
|
|
97
|
-
case ".ts":
|
|
98
|
-
case "d.ts":
|
|
99
|
-
return "typescript";
|
|
100
|
-
case ".htm":
|
|
101
|
-
case ".html":
|
|
102
|
-
return "html";
|
|
103
|
-
case ".scss":
|
|
104
|
-
case ".css":
|
|
105
|
-
return "css";
|
|
106
|
-
case ".md":
|
|
107
|
-
return "markdown";
|
|
108
|
-
case ".c":
|
|
109
|
-
return "c";
|
|
110
|
-
case ".h":
|
|
111
|
-
case ".cpp":
|
|
112
|
-
return "cpp";
|
|
113
|
-
case ".yml":
|
|
114
|
-
case ".yaml":
|
|
115
|
-
return "yaml";
|
|
116
|
-
case ".txt":
|
|
117
|
-
case ".log":
|
|
118
|
-
return "text";
|
|
119
|
-
default:
|
|
120
|
-
switch (fileName) {
|
|
121
|
-
case "dockerfile":
|
|
122
|
-
return "dockerfile";
|
|
123
|
-
case ".gitignore":
|
|
124
|
-
return "text";
|
|
125
|
-
}
|
|
126
|
-
return "text";
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
export function getPreview(req, filePath) {
|
|
130
|
-
const admin = req.editor;
|
|
131
|
-
const inflateData = admin ? admin.getRouteFileMap()[filePath] : undefined;
|
|
132
|
-
if (inflateData) {
|
|
133
|
-
return inflateData.previewMethod === "html" ? inflateData.routes[0].path : undefined;
|
|
134
|
-
}
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
export function getAPIPreview(req, filePath) {
|
|
138
|
-
const admin = req.editor;
|
|
139
|
-
const inflateData = admin ? admin.getRouteFileMap()[filePath] : undefined;
|
|
140
|
-
if (inflateData) {
|
|
141
|
-
return inflateData.previewMethod === "api" ? inflateData.routes.map(r => {
|
|
142
|
-
return {
|
|
143
|
-
path: r.path,
|
|
144
|
-
method: r.method ? r.method : "GET"
|
|
145
|
-
};
|
|
146
|
-
}) : undefined;
|
|
147
|
-
}
|
|
148
|
-
return undefined;
|
|
149
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { getPath } from "./read.api.js";
|
|
3
|
-
import { dirname } from "node:path";
|
|
4
|
-
export default {
|
|
5
|
-
middleware: [server.middleware.json()],
|
|
6
|
-
method: "POST",
|
|
7
|
-
path: "/write",
|
|
8
|
-
description: "admin editor file write endpoint",
|
|
9
|
-
request: {
|
|
10
|
-
body: {
|
|
11
|
-
path: "string",
|
|
12
|
-
contents: "string",
|
|
13
|
-
override: "boolean?"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
response: {
|
|
17
|
-
status: [200, 400],
|
|
18
|
-
body: {
|
|
19
|
-
message: "string"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
handler: async (req, res) => {
|
|
23
|
-
const { path, contents, override } = req.body;
|
|
24
|
-
await writeFile(path, contents, override);
|
|
25
|
-
return res.json({
|
|
26
|
-
message: "OK"
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
async function writeFile(path, contents, override) {
|
|
31
|
-
if (existsSync(getPath(path)) && !override) {
|
|
32
|
-
throw new Error("file already exists!");
|
|
33
|
-
}
|
|
34
|
-
mkdirSync(dirname(getPath(path)), {
|
|
35
|
-
recursive: true
|
|
36
|
-
});
|
|
37
|
-
writeFileSync(getPath(path), contents);
|
|
38
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
|
-
import { BASE_PATH } from "../../../../../common/constants.server.js";
|
|
3
|
-
export default {
|
|
4
|
-
method: "POST",
|
|
5
|
-
path: "/reload",
|
|
6
|
-
description: "admin editor server reload endpoint. reloads the server without closing the port",
|
|
7
|
-
middleware: [],
|
|
8
|
-
request: {
|
|
9
|
-
body: false
|
|
10
|
-
},
|
|
11
|
-
response: {
|
|
12
|
-
status: [200, 400],
|
|
13
|
-
body: {
|
|
14
|
-
message: "string",
|
|
15
|
-
reloadString: "string",
|
|
16
|
-
migrations: "string[]",
|
|
17
|
-
errors: {
|
|
18
|
-
allowNull: true,
|
|
19
|
-
type: "array",
|
|
20
|
-
arrayType: "object",
|
|
21
|
-
properties: {
|
|
22
|
-
filePath: "string",
|
|
23
|
-
error: "string"
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
handler: async (req, res) => {
|
|
29
|
-
const errors = await req?.editor?.reload();
|
|
30
|
-
const parsedErrors = parseInflateErrors(errors);
|
|
31
|
-
return res.json({
|
|
32
|
-
message: "OK",
|
|
33
|
-
reloadString: req.uuid,
|
|
34
|
-
migrations: req?.editor?.getMigrations().map(m => m.name),
|
|
35
|
-
errors: parsedErrors ? parsedErrors : []
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
export function parseInflateErrors(errors) {
|
|
40
|
-
return errors?.map(error => {
|
|
41
|
-
return {
|
|
42
|
-
filePath: relative(BASE_PATH, error.filePath),
|
|
43
|
-
error: error.error.message
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
|
-
import { BASE_PATH } from "../../../../../common/constants.server.js";
|
|
3
|
-
export default {
|
|
4
|
-
method: "POST",
|
|
5
|
-
path: "/restart",
|
|
6
|
-
description: "admin editor server restart endpoint",
|
|
7
|
-
middleware: [server.middleware.json()],
|
|
8
|
-
request: {
|
|
9
|
-
body: false
|
|
10
|
-
},
|
|
11
|
-
response: {
|
|
12
|
-
status: [200, 400],
|
|
13
|
-
body: {
|
|
14
|
-
message: "string",
|
|
15
|
-
reloadString: "string",
|
|
16
|
-
migrations: "string[]",
|
|
17
|
-
errors: {
|
|
18
|
-
allowNull: true,
|
|
19
|
-
type: "array",
|
|
20
|
-
arrayType: "object",
|
|
21
|
-
properties: {
|
|
22
|
-
filePath: "string",
|
|
23
|
-
error: "string"
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
handler: async (req, res) => {
|
|
29
|
-
const errors = await req?.editor?.restart();
|
|
30
|
-
return res.json({
|
|
31
|
-
message: "OK",
|
|
32
|
-
reloadString: req.uuid,
|
|
33
|
-
migrations: req?.editor?.getMigrations().map(m => m.name),
|
|
34
|
-
errors: parseInflateErrors(errors)
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
export function parseInflateErrors(errors) {
|
|
39
|
-
return errors?.map(error => {
|
|
40
|
-
return {
|
|
41
|
-
filePath: relative(BASE_PATH, error.filePath),
|
|
42
|
-
error: error.error.message
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { scanDir } from "./api/fs/scan.api.js";
|
|
2
|
-
import { HTMLEncode } from "../../../common/html-encode.js";
|
|
3
|
-
export default {
|
|
4
|
-
description: "ADMIN EDITOR GUI",
|
|
5
|
-
path: "/",
|
|
6
|
-
method: "GET",
|
|
7
|
-
handler: async (req, res) => {
|
|
8
|
-
const admin = req.editor;
|
|
9
|
-
const errors = admin ? admin.getInflateErrors() : [];
|
|
10
|
-
const files = scanDir(req);
|
|
11
|
-
const migrations = admin ? admin.getMigrations().map(m => m.name) : [];
|
|
12
|
-
const services = admin ? admin.getServices() : ["."];
|
|
13
|
-
return res.html("<!DOCTYPE html>" + String(JSX.createElement("html", null,
|
|
14
|
-
JSX.createElement("head", null,
|
|
15
|
-
JSX.createElement("link", { rel: "stylesheet", href: "/admin/editor/style.css" })),
|
|
16
|
-
JSX.createElement("body", null,
|
|
17
|
-
JSX.createElement("script", { type: "module", src: "/admin/editor/editor.js" }),
|
|
18
|
-
JSX.createElement("editor-component", { disablelog: "true", disablepreview: "true", disablereload: "true", 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))}` },
|
|
19
|
-
JSX.createElement("noscript", null, "Enable JavaScript"))))));
|
|
20
|
-
}
|
|
21
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { BASEEDITOR_PATH } from "./common/constants.js";
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
-
import { relative, resolve } from "node:path";
|
|
5
|
-
import { ADMIN_EDITOR_AUTH_KEY, ADMIN_EDITOR_AUTH_QUERY } from "./auth.js";
|
|
6
|
-
//import { getEditorAdmin } from "./common/admin-interface.js";
|
|
7
|
-
const ADMIN_EDITOR_BROWSER_OPEN_KEY = "ADMIN_EDITOR_BROWSER_OPEN_KEY$$";
|
|
8
|
-
export default {
|
|
9
|
-
preload: (serverInterface, adminInterface) => {
|
|
10
|
-
//console.dir(server);
|
|
11
|
-
if (serverInterface?.isPrimaryWorker()) {
|
|
12
|
-
const cache = (adminInterface ? adminInterface.getCache() : serverInterface.cache);
|
|
13
|
-
if (!cache.has(ADMIN_EDITOR_AUTH_KEY)) {
|
|
14
|
-
const adminKEYPath = resolve(".admin_key");
|
|
15
|
-
if (existsSync(adminKEYPath)) {
|
|
16
|
-
serverInterface.logger.warn("loading static ADMIN_KEY from [%s]", relative(process.cwd(), adminKEYPath));
|
|
17
|
-
cache.set(ADMIN_EDITOR_AUTH_KEY, readFileSync(adminKEYPath).toString().trim());
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
cache.set(ADMIN_EDITOR_AUTH_KEY, randomUUID());
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
start: (serverInterface, adminInterface) => {
|
|
26
|
-
//console.dir(server);
|
|
27
|
-
const cache = (adminInterface ? adminInterface.getCache() : serverInterface.cache);
|
|
28
|
-
if (!cache.has(ADMIN_EDITOR_BROWSER_OPEN_KEY)) {
|
|
29
|
-
const KEY = cache.get(ADMIN_EDITOR_AUTH_KEY);
|
|
30
|
-
const adminPath = `${BASEEDITOR_PATH}?${ADMIN_EDITOR_AUTH_QUERY}=${KEY}`;
|
|
31
|
-
if (serverInterface?.isPrimaryWorker()) {
|
|
32
|
-
serverInterface.logger.log("\n\n\tADMIN_EDITOR\n\n\t%s\n\n", adminPath);
|
|
33
|
-
}
|
|
34
|
-
//const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
35
|
-
//const OPEN = process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
36
|
-
if (serverInterface.isPrimaryWorker()) {
|
|
37
|
-
cache.set(ADMIN_EDITOR_BROWSER_OPEN_KEY, true);
|
|
38
|
-
try {
|
|
39
|
-
serverInterface.openBrowser(`${BASEEDITOR_PATH}?${ADMIN_EDITOR_AUTH_QUERY}=${KEY}`);
|
|
40
|
-
//serverInterface.logger.log(`${OPEN} "${adminPath}"`);
|
|
41
|
-
//execSync(`${OPEN} "${adminPath}"`);
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
serverInterface.logger.error(e.message);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
package/build/esm/editor/ws.d.ts
DELETED
package/build/esm/editor/ws.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { LOG_SOCKET_PATH } from "./common/constants.js";
|
|
2
|
-
export default {
|
|
3
|
-
path: LOG_SOCKET_PATH,
|
|
4
|
-
validate(req) {
|
|
5
|
-
const admin = req.editor;
|
|
6
|
-
const cache = (admin ? admin.getCache() : req.server.cache);
|
|
7
|
-
const KEY = cache.get("AUTH_KEY");
|
|
8
|
-
const cookieToken = req.cookies["auth"];
|
|
9
|
-
return cookieToken === KEY ? true : false;
|
|
10
|
-
},
|
|
11
|
-
};
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
//@ts-ignore
|
|
2
|
-
import { ReadBuffer, URLEncodedParser, JSONParser, TextParser, CORS, SessionHandler } from "@miqro/core";
|
|
3
|
-
import cluster from "node:cluster";
|
|
4
|
-
import { strictEqual } from "node:assert";
|
|
5
|
-
import { HTMLEncode } from "@miqro/jsx-node";
|
|
6
|
-
import { createElement as realCreateElement, enableDebugLog, useRuntime, Link, Router, usePathname, Fragment, useEffect, useRef, useState, useQuery, useRefresh, useElement, createContext, useContext } from "@miqro/jsx";
|
|
7
|
-
import { jsx2HTML } from "../common/jsx.js";
|
|
8
|
-
import { inflateMD2HTML } from "../inflate/md.js";
|
|
9
|
-
import { EXIT_CODES } from "../common/constants.js";
|
|
10
|
-
import { ClusterCache, LocalCache } from "../lib.js";
|
|
11
|
-
import { decodeJWT, decodeProtectedHeaderJWT, decryptJWT, encryptJWT, signJWT, verifyJWT } from "../common/jwt.js";
|
|
12
|
-
import { createSecretKey } from "node:crypto";
|
|
13
|
-
import { Parser } from "@miqro/parser";
|
|
14
|
-
/*const globaljsx: any = Object.freeze({
|
|
15
|
-
useContext,
|
|
16
|
-
useRuntime,
|
|
17
|
-
createContext,
|
|
18
|
-
useState,
|
|
19
|
-
useEffect,
|
|
20
|
-
useQuery,
|
|
21
|
-
useRef,
|
|
22
|
-
useElement,
|
|
23
|
-
useRefresh,
|
|
24
|
-
Link,
|
|
25
|
-
Router,
|
|
26
|
-
usePathname
|
|
27
|
-
});*/
|
|
28
|
-
const globalJSX = Object.freeze({
|
|
29
|
-
createElement: (...args) => {
|
|
30
|
-
const ret = realCreateElement(...args);
|
|
31
|
-
ret.toString = () => jsx2HTML(ret);
|
|
32
|
-
return ret;
|
|
33
|
-
},
|
|
34
|
-
Fragment,
|
|
35
|
-
enableDebugLog
|
|
36
|
-
});
|
|
37
|
-
const globaljsx = Object.freeze({
|
|
38
|
-
useContext,
|
|
39
|
-
useRuntime,
|
|
40
|
-
createContext,
|
|
41
|
-
useState,
|
|
42
|
-
useEffect,
|
|
43
|
-
useQuery,
|
|
44
|
-
useRef,
|
|
45
|
-
useElement,
|
|
46
|
-
useRefresh,
|
|
47
|
-
Link,
|
|
48
|
-
Router,
|
|
49
|
-
usePathname,
|
|
50
|
-
define: function define() {
|
|
51
|
-
/*const callSites = getCallSite();
|
|
52
|
-
const caller = callSites[2];
|
|
53
|
-
if (CLEAR_JSX_CACHE) {
|
|
54
|
-
const scriptName = basename(caller.scriptName);
|
|
55
|
-
const originalName = scriptName.substring(0, scriptName.length - ".mjs".length);
|
|
56
|
-
//server.logger.debug("browser.define not available server side!");
|
|
57
|
-
//server.logger.trace("browser.define not available server side! %s", originalName);
|
|
58
|
-
} else {
|
|
59
|
-
//server.logger.debug("browser.define not available server side!");
|
|
60
|
-
//server.logger.trace("browser.define not available server side! %s:%s:%s", caller.scriptName, caller.lineNumber, caller.column);
|
|
61
|
-
}*/
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const globalWindow = Object.freeze({
|
|
65
|
-
addEventListener: function define() {
|
|
66
|
-
/*const callSites = getCallSite();
|
|
67
|
-
const caller = callSites[2];
|
|
68
|
-
if (CLEAR_JSX_CACHE) {
|
|
69
|
-
const scriptName = basename(caller.scriptName);
|
|
70
|
-
//server.logger.debug("window.addEventListener not available server side!");
|
|
71
|
-
server.logger.trace("window.addEventListener not available server side! %s", scriptName.substring(0, scriptName.length - ".mjs".length));
|
|
72
|
-
} else {
|
|
73
|
-
//server.logger.debug("window.addEventListener not available server side!");
|
|
74
|
-
server.logger.trace("window.addEventListener not available server side! %s:%s:%s", caller.scriptName, caller.lineNumber, caller.column);
|
|
75
|
-
}*/
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
const globalServer = Object.freeze({
|
|
79
|
-
middleware: Object.freeze({
|
|
80
|
-
buffer: ReadBuffer,
|
|
81
|
-
url: URLEncodedParser,
|
|
82
|
-
json: JSONParser,
|
|
83
|
-
text: TextParser,
|
|
84
|
-
cors: CORS,
|
|
85
|
-
session: SessionHandler
|
|
86
|
-
}),
|
|
87
|
-
encodeHTML: HTMLEncode,
|
|
88
|
-
inflateMDtoHTML: inflateMD2HTML,
|
|
89
|
-
createSecretKey,
|
|
90
|
-
newParser() {
|
|
91
|
-
return new Parser();
|
|
92
|
-
},
|
|
93
|
-
newClusterCache(name, logger) {
|
|
94
|
-
return new ClusterCache(name, logger);
|
|
95
|
-
},
|
|
96
|
-
newLocalCache(name, logger) {
|
|
97
|
-
return new LocalCache(name, logger);
|
|
98
|
-
},
|
|
99
|
-
getWorkerNumber() {
|
|
100
|
-
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === undefined ? 0 : parseInt(process.env["CLUSTER_NODE_NUMBER"], 10);
|
|
101
|
-
},
|
|
102
|
-
getWorkerCount() {
|
|
103
|
-
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === undefined || process.env["CLUSTER_COUNT"] === undefined ? 1 : parseInt(process.env["CLUSTER_COUNT"], 10);
|
|
104
|
-
},
|
|
105
|
-
isPrimaryWorker() {
|
|
106
|
-
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
|
|
107
|
-
},
|
|
108
|
-
jwt: {
|
|
109
|
-
decode(jwt) {
|
|
110
|
-
return decodeJWT(jwt);
|
|
111
|
-
},
|
|
112
|
-
decodeProtectedHeader(token) {
|
|
113
|
-
return decodeProtectedHeaderJWT(token);
|
|
114
|
-
},
|
|
115
|
-
decrypt(jwt, secret, options) {
|
|
116
|
-
return decryptJWT(jwt, secret, options);
|
|
117
|
-
},
|
|
118
|
-
encrypt(payload, secret, options) {
|
|
119
|
-
return encryptJWT(payload, secret, options);
|
|
120
|
-
},
|
|
121
|
-
sign(payload, secret, options) {
|
|
122
|
-
return signJWT(payload, secret, options);
|
|
123
|
-
},
|
|
124
|
-
verify(jwt, secret, options) {
|
|
125
|
-
return verifyJWT(jwt, secret, options);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
export function browserJSXGlobals(inFile, jsxPath = false, useExport = true) {
|
|
130
|
-
const PRE = `import { enableDebugLog, useRuntime, Link, usePathname, createContext, useContext, useElement, useRefresh, useQuery, define, Router, useState, useEffect, useRef, createElement, Fragment } from "${jsxPath}";
|
|
131
|
-
globalThis.JSX = Object.freeze({
|
|
132
|
-
createElement,
|
|
133
|
-
Fragment,
|
|
134
|
-
enableDebugLog
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
globalThis.newParser = () => new Parser();
|
|
138
|
-
globalThis.jsx = Object.freeze({
|
|
139
|
-
define,
|
|
140
|
-
useRuntime,
|
|
141
|
-
createContext,
|
|
142
|
-
useContext,
|
|
143
|
-
useState,
|
|
144
|
-
useEffect,
|
|
145
|
-
useQuery,
|
|
146
|
-
useRef,
|
|
147
|
-
useElement,
|
|
148
|
-
useRefresh,
|
|
149
|
-
usePathname,
|
|
150
|
-
Link,
|
|
151
|
-
Router
|
|
152
|
-
});`;
|
|
153
|
-
return `${jsxPath ? PRE : ""}\n${useExport ? `export * from "${inFile}";import * as lib from "${inFile}";export default lib.default;` : `import * as lib from "${inFile}"`}`;
|
|
154
|
-
}
|
|
155
|
-
export function initGlobals() {
|
|
156
|
-
//const logger = getLogger(SERVER_IDENTIFIER);
|
|
157
|
-
globalThis.server = globalServer;
|
|
158
|
-
//globalThis.jsx = globaljsx;
|
|
159
|
-
/*for (const key of Object.keys(globaljsx)) {
|
|
160
|
-
globalThis[key] = globaljsx[key];
|
|
161
|
-
}*/
|
|
162
|
-
globalThis.JSX = globalJSX;
|
|
163
|
-
globalThis.jsx = globaljsx;
|
|
164
|
-
globalThis.window = globalWindow;
|
|
165
|
-
}
|
|
166
|
-
export function assertGlobalTampered() {
|
|
167
|
-
try {
|
|
168
|
-
//strictEqual(globalThis.utils, globalUtils, "globalThis.utils tamperered");
|
|
169
|
-
strictEqual(globalThis.JSX, globalJSX, "globalThis.JSX tamperered");
|
|
170
|
-
//strictEqual(globalThis.jsx, globaljsx, "globalThis.jsx tamperered");
|
|
171
|
-
/*for (const key of Object.keys(globaljsx)) {
|
|
172
|
-
strictEqual(globalThis[key], globaljsx[key], "globalThis.jsx tamperered");
|
|
173
|
-
}*/
|
|
174
|
-
strictEqual(globalThis.server, globalServer, "globalThis.server tamperered");
|
|
175
|
-
strictEqual(globalThis.jsx, globaljsx, "globalThis.jsx tamperered");
|
|
176
|
-
strictEqual(globalThis.window, globalWindow, "globalThis.window tamperered");
|
|
177
|
-
}
|
|
178
|
-
catch (e) {
|
|
179
|
-
console.error(e);
|
|
180
|
-
process.exit(EXIT_CODES.GLOBALS_ALTERED);
|
|
181
|
-
}
|
|
182
|
-
}
|