miqro 7.3.5 → 8.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.
Files changed (203) hide show
  1. package/README.md +3 -7
  2. package/build/esm/{src/bin → bin}/types.js +1 -2
  3. package/build/esm/{src/common → common}/arguments.d.ts +0 -2
  4. package/build/esm/{src/common → common}/arguments.js +5 -38
  5. package/build/esm/{src/common → common}/assets.js +1 -1
  6. package/build/esm/{src/common → common}/constants.d.ts +11 -0
  7. package/build/esm/{editor/common/templates.js → common/constants.js} +14 -0
  8. package/build/esm/{src/common → common}/esbuild.js +0 -1
  9. package/build/esm/common/help.d.ts +3 -0
  10. package/build/esm/{src/common → common}/help.js +0 -1
  11. package/build/esm/{src/inflate → inflate}/inflate-sea.js +3 -0
  12. package/build/esm/inflate/md.d.ts +1 -0
  13. package/build/esm/inflate/md.js +4 -0
  14. package/build/esm/{src/inflate → inflate}/setup-http.js +2 -3
  15. package/build/esm/{src/main.js → main.js} +0 -1
  16. package/build/esm/{src/services → services}/app.d.ts +0 -1
  17. package/build/esm/{src/services → services}/app.js +1 -53
  18. package/build/esm/{src/services → services}/utils/server-interface.js +18 -3
  19. package/build/esm/{src/services → services}/utils/websocketmanager.d.ts +0 -1
  20. package/build/esm/{src/services → services}/utils/websocketmanager.js +10 -20
  21. package/build/esm/{src/types.d.ts → types.d.ts} +2 -1
  22. package/build/lib.cjs +8297 -11619
  23. package/package.json +11 -23
  24. package/build/editor.bundle.js +0 -12329
  25. package/build/esm/editor/auth.d.ts +0 -6
  26. package/build/esm/editor/auth.js +0 -44
  27. package/build/esm/editor/common/constants.d.ts +0 -4
  28. package/build/esm/editor/common/constants.js +0 -20
  29. package/build/esm/editor/common/constants.server.d.ts +0 -2
  30. package/build/esm/editor/common/constants.server.js +0 -4
  31. package/build/esm/editor/common/editor-index.d.ts +0 -2
  32. package/build/esm/editor/common/editor-index.js +0 -14
  33. package/build/esm/editor/common/html-encode.d.ts +0 -1
  34. package/build/esm/editor/common/html-encode.js +0 -14
  35. package/build/esm/editor/common/log-socket.d.ts +0 -15
  36. package/build/esm/editor/common/log-socket.js +0 -71
  37. package/build/esm/editor/common/templates.d.ts +0 -11
  38. package/build/esm/editor/components/api-preview.d.ts +0 -11
  39. package/build/esm/editor/components/api-preview.js +0 -92
  40. package/build/esm/editor/components/editor.d.ts +0 -16
  41. package/build/esm/editor/components/editor.js +0 -367
  42. package/build/esm/editor/components/file-browser.d.ts +0 -37
  43. package/build/esm/editor/components/file-browser.js +0 -127
  44. package/build/esm/editor/components/file-editor-toolbar.d.ts +0 -22
  45. package/build/esm/editor/components/file-editor-toolbar.js +0 -95
  46. package/build/esm/editor/components/file-editor.d.ts +0 -32
  47. package/build/esm/editor/components/file-editor.js +0 -61
  48. package/build/esm/editor/components/filter-query.d.ts +0 -1
  49. package/build/esm/editor/components/filter-query.js +0 -23
  50. package/build/esm/editor/components/highlight-text-area.d.ts +0 -11
  51. package/build/esm/editor/components/highlight-text-area.js +0 -127
  52. package/build/esm/editor/components/log-viewer.d.ts +0 -6
  53. package/build/esm/editor/components/log-viewer.js +0 -71
  54. package/build/esm/editor/components/new-file.d.ts +0 -10
  55. package/build/esm/editor/components/new-file.js +0 -119
  56. package/build/esm/editor/components/scroll-query.d.ts +0 -7
  57. package/build/esm/editor/components/scroll-query.js +0 -22
  58. package/build/esm/editor/components/start-page.d.ts +0 -13
  59. package/build/esm/editor/components/start-page.js +0 -32
  60. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +0 -4
  61. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +0 -30
  62. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +0 -7
  63. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +0 -50
  64. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +0 -7
  65. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +0 -40
  66. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +0 -26
  67. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +0 -150
  68. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +0 -3
  69. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +0 -39
  70. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +0 -10
  71. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +0 -46
  72. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +0 -10
  73. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +0 -46
  74. package/build/esm/editor/http/admin/editor/editor.d.ts +0 -1
  75. package/build/esm/editor/http/admin/editor/editor.js +0 -8
  76. package/build/esm/editor/http/admin/editor/index.api.d.ts +0 -3
  77. package/build/esm/editor/http/admin/editor/index.api.js +0 -23
  78. package/build/esm/editor/server.d.ts +0 -3
  79. package/build/esm/editor/server.js +0 -49
  80. package/build/esm/editor/ws.d.ts +0 -3
  81. package/build/esm/editor/ws.js +0 -12
  82. package/build/esm/src/common/constants.js +0 -14
  83. package/build/esm/src/common/help.d.ts +0 -3
  84. package/build/esm/src/inflate/md.d.ts +0 -3
  85. package/build/esm/src/inflate/md.js +0 -22
  86. package/build/esm/src/services/editor.d.ts +0 -3
  87. package/build/esm/src/services/editor.js +0 -66
  88. package/build/esm/src/services/utils/admin-interface.d.ts +0 -3
  89. package/build/esm/src/services/utils/admin-interface.js +0 -33
  90. package/build/style.css +0 -620
  91. package/editor/auth.ts +0 -53
  92. package/editor/common/constants.server.ts +0 -5
  93. package/editor/common/constants.ts +0 -21
  94. package/editor/common/editor-index.tsx +0 -17
  95. package/editor/common/html-encode.ts +0 -14
  96. package/editor/common/log-socket.tsx +0 -87
  97. package/editor/common/templates.ts +0 -481
  98. package/editor/components/api-preview.tsx +0 -118
  99. package/editor/components/editor.tsx +0 -496
  100. package/editor/components/file-browser.tsx +0 -311
  101. package/editor/components/file-editor-toolbar.tsx +0 -194
  102. package/editor/components/file-editor.tsx +0 -125
  103. package/editor/components/filter-query.tsx +0 -26
  104. package/editor/components/highlight-text-area.tsx +0 -148
  105. package/editor/components/log-viewer.tsx +0 -113
  106. package/editor/components/new-file.tsx +0 -172
  107. package/editor/components/scroll-query.tsx +0 -25
  108. package/editor/components/start-page.tsx +0 -52
  109. package/editor/http/admin/editor/api/fs/delete.api.tsx +0 -32
  110. package/editor/http/admin/editor/api/fs/read.api.tsx +0 -55
  111. package/editor/http/admin/editor/api/fs/rename.api.tsx +0 -41
  112. package/editor/http/admin/editor/api/fs/scan.api.tsx +0 -181
  113. package/editor/http/admin/editor/api/fs/write.api.tsx +0 -41
  114. package/editor/http/admin/editor/api/server/reload.api.ts +0 -53
  115. package/editor/http/admin/editor/api/server/restart.api.tsx +0 -52
  116. package/editor/http/admin/editor/editor.tsx +0 -10
  117. package/editor/http/admin/editor/index.api.tsx +0 -43
  118. package/editor/server.ts +0 -57
  119. package/editor/ws.ts +0 -17
  120. /package/build/esm/{src/bin → bin}/compile.d.ts +0 -0
  121. /package/build/esm/{src/bin → bin}/compile.js +0 -0
  122. /package/build/esm/{src/bin → bin}/doc-md.d.ts +0 -0
  123. /package/build/esm/{src/bin → bin}/doc-md.js +0 -0
  124. /package/build/esm/{src/bin → bin}/generate-doc.d.ts +0 -0
  125. /package/build/esm/{src/bin → bin}/generate-doc.js +0 -0
  126. /package/build/esm/{src/bin → bin}/test.d.ts +0 -0
  127. /package/build/esm/{src/bin → bin}/test.js +0 -0
  128. /package/build/esm/{src/bin → bin}/types.d.ts +0 -0
  129. /package/build/esm/{src/cluster.d.ts → cluster.d.ts} +0 -0
  130. /package/build/esm/{src/cluster.js → cluster.js} +0 -0
  131. /package/build/esm/{src/common → common}/admin-interface.d.ts +0 -0
  132. /package/build/esm/{src/common → common}/admin-interface.js +0 -0
  133. /package/build/esm/{src/common → common}/assets.d.ts +0 -0
  134. /package/build/esm/{src/common → common}/checksum.d.ts +0 -0
  135. /package/build/esm/{src/common → common}/checksum.js +0 -0
  136. /package/build/esm/{src/common → common}/content-type.d.ts +0 -0
  137. /package/build/esm/{src/common → common}/content-type.js +0 -0
  138. /package/build/esm/{src/common → common}/esbuild.d.ts +0 -0
  139. /package/build/esm/{src/common → common}/exit.d.ts +0 -0
  140. /package/build/esm/{src/common → common}/exit.js +0 -0
  141. /package/build/esm/{src/common → common}/fs.d.ts +0 -0
  142. /package/build/esm/{src/common → common}/fs.js +0 -0
  143. /package/build/esm/{src/common → common}/jsx.d.ts +0 -0
  144. /package/build/esm/{src/common → common}/jsx.js +0 -0
  145. /package/build/esm/{src/common → common}/jwt.d.ts +0 -0
  146. /package/build/esm/{src/common → common}/jwt.js +0 -0
  147. /package/build/esm/{src/common → common}/paths.d.ts +0 -0
  148. /package/build/esm/{src/common → common}/paths.js +0 -0
  149. /package/build/esm/{src/common → common}/watch.d.ts +0 -0
  150. /package/build/esm/{src/common → common}/watch.js +0 -0
  151. /package/build/esm/{src/inflate → inflate}/inflate-sea.d.ts +0 -0
  152. /package/build/esm/{src/inflate → inflate}/inflate.d.ts +0 -0
  153. /package/build/esm/{src/inflate → inflate}/inflate.js +0 -0
  154. /package/build/esm/{src/inflate → inflate}/setup-auth.d.ts +0 -0
  155. /package/build/esm/{src/inflate → inflate}/setup-auth.js +0 -0
  156. /package/build/esm/{src/inflate → inflate}/setup-cors.d.ts +0 -0
  157. /package/build/esm/{src/inflate → inflate}/setup-cors.js +0 -0
  158. /package/build/esm/{src/inflate → inflate}/setup-db.d.ts +0 -0
  159. /package/build/esm/{src/inflate → inflate}/setup-db.js +0 -0
  160. /package/build/esm/{src/inflate → inflate}/setup-error.d.ts +0 -0
  161. /package/build/esm/{src/inflate → inflate}/setup-error.js +0 -0
  162. /package/build/esm/{src/inflate → inflate}/setup-http.d.ts +0 -0
  163. /package/build/esm/{src/inflate → inflate}/setup-log.d.ts +0 -0
  164. /package/build/esm/{src/inflate → inflate}/setup-log.js +0 -0
  165. /package/build/esm/{src/inflate → inflate}/setup-middleware.d.ts +0 -0
  166. /package/build/esm/{src/inflate → inflate}/setup-middleware.js +0 -0
  167. /package/build/esm/{src/inflate → inflate}/setup-server-config.d.ts +0 -0
  168. /package/build/esm/{src/inflate → inflate}/setup-server-config.js +0 -0
  169. /package/build/esm/{src/inflate → inflate}/setup-test.d.ts +0 -0
  170. /package/build/esm/{src/inflate → inflate}/setup-test.js +0 -0
  171. /package/build/esm/{src/inflate → inflate}/setup-ws.d.ts +0 -0
  172. /package/build/esm/{src/inflate → inflate}/setup-ws.js +0 -0
  173. /package/build/esm/{src/inflate → inflate}/setup.doc.d.ts +0 -0
  174. /package/build/esm/{src/inflate → inflate}/setup.doc.js +0 -0
  175. /package/build/esm/{src/inflate → inflate}/utils/sea-utils.d.ts +0 -0
  176. /package/build/esm/{src/inflate → inflate}/utils/sea-utils.js +0 -0
  177. /package/build/esm/{src/lib.d.ts → lib.d.ts} +0 -0
  178. /package/build/esm/{src/lib.js → lib.js} +0 -0
  179. /package/build/esm/{src/main.d.ts → main.d.ts} +0 -0
  180. /package/build/esm/{src/services → services}/hot-reload.d.ts +0 -0
  181. /package/build/esm/{src/services → services}/hot-reload.js +0 -0
  182. /package/build/esm/{src/services → services}/migrations.d.ts +0 -0
  183. /package/build/esm/{src/services → services}/migrations.js +0 -0
  184. /package/build/esm/{src/services → services}/utils/cache.d.ts +0 -0
  185. /package/build/esm/{src/services → services}/utils/cache.js +0 -0
  186. /package/build/esm/{src/services → services}/utils/cluster-cache.d.ts +0 -0
  187. /package/build/esm/{src/services → services}/utils/cluster-cache.js +0 -0
  188. /package/build/esm/{src/services → services}/utils/cluster-ws.d.ts +0 -0
  189. /package/build/esm/{src/services → services}/utils/cluster-ws.js +0 -0
  190. /package/build/esm/{src/services → services}/utils/db-manager.d.ts +0 -0
  191. /package/build/esm/{src/services → services}/utils/db-manager.js +0 -0
  192. /package/build/esm/{src/services → services}/utils/get-route.d.ts +0 -0
  193. /package/build/esm/{src/services → services}/utils/get-route.js +0 -0
  194. /package/build/esm/{src/services → services}/utils/jwt.d.ts +0 -0
  195. /package/build/esm/{src/services → services}/utils/jwt.js +0 -0
  196. /package/build/esm/{src/services → services}/utils/log-transport.d.ts +0 -0
  197. /package/build/esm/{src/services → services}/utils/log-transport.js +0 -0
  198. /package/build/esm/{src/services → services}/utils/log.d.ts +0 -0
  199. /package/build/esm/{src/services → services}/utils/log.js +0 -0
  200. /package/build/esm/{src/services → services}/utils/middleware.d.ts +0 -0
  201. /package/build/esm/{src/services → services}/utils/middleware.js +0 -0
  202. /package/build/esm/{src/services → services}/utils/server-interface.d.ts +0 -0
  203. /package/build/esm/{src/types.js → types.js} +0 -0
@@ -1,7 +0,0 @@
1
- import { APIRoute } from "@miqro/core";
2
- declare const _default: APIRoute<import("@miqro/core").Request, {
3
- readonly path: "string";
4
- readonly newName: "string";
5
- }, undefined, undefined>;
6
- export default _default;
7
- export declare function rename(path: string, newName: string): Promise<void>;
@@ -1,40 +0,0 @@
1
- import { defineRoute, JSONParser } from "@miqro/core";
2
- import { existsSync, mkdirSync, renameSync } from "node:fs";
3
- import { getPath } from "./read.api.js";
4
- import { dirname } from "node:path";
5
- export default defineRoute({
6
- middleware: [JSONParser()],
7
- method: "POST",
8
- description: "admin editor file rename endpoint",
9
- path: "/rename",
10
- request: {
11
- body: {
12
- path: "string",
13
- newName: "string"
14
- }
15
- },
16
- response: {
17
- status: [200, 400],
18
- body: {
19
- message: "string"
20
- }
21
- },
22
- handler: async (req, res) => {
23
- const { path, newName } = req.body;
24
- await rename(path, newName);
25
- return res?.json({
26
- message: "OK"
27
- });
28
- }
29
- });
30
- export async function rename(path, newName) {
31
- if (existsSync(path) && !existsSync(newName)) {
32
- mkdirSync(dirname(getPath(newName)), {
33
- recursive: true
34
- });
35
- renameSync(getPath(path), getPath(newName));
36
- }
37
- else {
38
- throw new Error("invalid paths");
39
- }
40
- }
@@ -1,26 +0,0 @@
1
- import { APIRoute } from "@miqro/core";
2
- import { AdminRequest } from "../../../../../../src/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,150 +0,0 @@
1
- import { JSONParser } from "@miqro/core";
2
- import { existsSync, readdirSync, statSync } from "node:fs";
3
- import { basename, dirname, extname, relative, resolve, sep } from "node:path";
4
- import { BASE_PATH } from "../../../../../common/constants.server.js";
5
- export default {
6
- method: "GET",
7
- path: "/scan",
8
- description: "admin editor file scan endpoint",
9
- middleware: [JSONParser()],
10
- request: {
11
- body: false
12
- },
13
- response: {
14
- status: [200, 400]
15
- },
16
- handler: async (req, res) => {
17
- const admin = req.editor;
18
- const services = admin ? admin.getServices() : ["."];
19
- return res.json({
20
- files: scanDir(req),
21
- services
22
- });
23
- },
24
- };
25
- export function scanDir(req, basePath = BASE_PATH, ret = []) {
26
- const admin = req.editor;
27
- const services = admin ? admin.getServices() : ["."];
28
- services.forEach(service => {
29
- scanDirInternal(req, resolve(basePath, service), ret);
30
- });
31
- return ret;
32
- }
33
- function scanDirInternal(req, path = BASE_PATH, ret = []) {
34
- if (!existsSync(path)) {
35
- return ret;
36
- }
37
- const files = readdirSync(path);
38
- for (const file of files) {
39
- if (shouldIgnoreFile(file)) {
40
- continue;
41
- }
42
- const filePath = resolve(path, file);
43
- if (statSync(filePath).isDirectory()) {
44
- scanDirInternal(req, filePath, ret);
45
- continue;
46
- }
47
- else {
48
- const ext = extname(filePath);
49
- const fileName = basename(filePath);
50
- const name = fileName.substring(0, fileName.length - ext.length);
51
- const subExt = extname(name);
52
- const subName = name.substring(0, name.length - subExt.length);
53
- ret.push({
54
- dirs: getFileDirs(relative(BASE_PATH, filePath)),
55
- language: getLanguage(filePath),
56
- filePath: relative(BASE_PATH, filePath),
57
- ext,
58
- fileName,
59
- name,
60
- subExt,
61
- subName,
62
- previewPath: getPreview(req, filePath),
63
- apiPreview: getAPIPreview(req, filePath)
64
- });
65
- }
66
- }
67
- return ret;
68
- }
69
- function shouldIgnoreFile(file) {
70
- return file === ".git" || file === ".types" || file === ".DS_Store" || file === "node_modules";
71
- }
72
- function getFileDirs(filePath) {
73
- const dirs = [];
74
- let dir = dirname(filePath);
75
- while (dir !== sep && dir !== "" && dir !== "." && dir !== BASE_PATH) {
76
- dirs.push(dir);
77
- dir = dirname(dir);
78
- }
79
- return dirs.reverse().map(d => basename(d));
80
- }
81
- export function getLanguage(filePath) {
82
- const ext = extname(filePath);
83
- const fileName = basename(filePath);
84
- switch (ext.toLocaleLowerCase()) {
85
- case ".py":
86
- return "python";
87
- case ".sh":
88
- return "bash";
89
- case ".webmanifest":
90
- case ".json":
91
- return "json";
92
- case ".xml":
93
- return "xml";
94
- case ".jsx":
95
- case ".js":
96
- return "javascript";
97
- case ".tsx":
98
- case ".ts":
99
- case "d.ts":
100
- return "typescript";
101
- case ".htm":
102
- case ".html":
103
- return "html";
104
- case ".scss":
105
- case ".css":
106
- return "css";
107
- case ".md":
108
- return "markdown";
109
- case ".c":
110
- return "c";
111
- case ".h":
112
- case ".cpp":
113
- return "cpp";
114
- case ".yml":
115
- case ".yaml":
116
- return "yaml";
117
- case ".txt":
118
- case ".log":
119
- return "text";
120
- default:
121
- switch (fileName) {
122
- case "dockerfile":
123
- return "dockerfile";
124
- case ".gitignore":
125
- return "text";
126
- }
127
- return "text";
128
- }
129
- }
130
- export function getPreview(req, filePath) {
131
- const admin = req.editor;
132
- const inflateData = admin ? admin.getRouteFileMap()[filePath] : undefined;
133
- if (inflateData) {
134
- return inflateData.previewMethod === "html" ? inflateData.routes[0].path : undefined;
135
- }
136
- return undefined;
137
- }
138
- export function getAPIPreview(req, filePath) {
139
- const admin = req.editor;
140
- const inflateData = admin ? admin.getRouteFileMap()[filePath] : undefined;
141
- if (inflateData) {
142
- return inflateData.previewMethod === "api" ? inflateData.routes.map(r => {
143
- return {
144
- path: r.path,
145
- method: r.method ? r.method : "GET"
146
- };
147
- }) : undefined;
148
- }
149
- return undefined;
150
- }
@@ -1,3 +0,0 @@
1
- import { APIRoute } from "@miqro/core";
2
- declare const _default: APIRoute;
3
- export default _default;
@@ -1,39 +0,0 @@
1
- import { JSONParser } from "@miqro/core";
2
- import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
- import { getPath } from "./read.api.js";
4
- import { dirname } from "node:path";
5
- export default {
6
- middleware: [JSONParser()],
7
- method: "POST",
8
- path: "/write",
9
- description: "admin editor file write endpoint",
10
- request: {
11
- body: {
12
- path: "string",
13
- contents: "string",
14
- override: "boolean?"
15
- }
16
- },
17
- response: {
18
- status: [200, 400],
19
- body: {
20
- message: "string"
21
- }
22
- },
23
- handler: async (req, res) => {
24
- const { path, contents, override } = req.body;
25
- await writeFile(path, contents, override);
26
- return res.json({
27
- message: "OK"
28
- });
29
- }
30
- };
31
- async function writeFile(path, contents, override) {
32
- if (existsSync(getPath(path)) && !override) {
33
- throw new Error("file already exists!");
34
- }
35
- mkdirSync(dirname(getPath(path)), {
36
- recursive: true
37
- });
38
- writeFileSync(getPath(path), contents);
39
- }
@@ -1,10 +0,0 @@
1
- import { APIRoute } from "@miqro/core";
2
- declare const _default: APIRoute;
3
- export default _default;
4
- export declare function parseInflateErrors(errors: {
5
- filePath: string;
6
- error: Error;
7
- }[] | null): {
8
- filePath: string;
9
- error: string;
10
- }[];
@@ -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,10 +0,0 @@
1
- import { APIRoute } from "@miqro/core";
2
- declare const _default: APIRoute;
3
- export default _default;
4
- export declare function parseInflateErrors(errors: {
5
- filePath: string;
6
- error: Error;
7
- }[] | null): {
8
- filePath: string;
9
- error: string;
10
- }[];
@@ -1,46 +0,0 @@
1
- import { JSONParser } from "@miqro/core";
2
- import { relative } from "node:path";
3
- import { BASE_PATH } from "../../../../../common/constants.server.js";
4
- export default {
5
- method: "POST",
6
- path: "/restart",
7
- description: "admin editor server restart endpoint",
8
- middleware: [JSONParser()],
9
- request: {
10
- body: false
11
- },
12
- response: {
13
- status: [200, 400],
14
- body: {
15
- message: "string",
16
- reloadString: "string",
17
- migrations: "string[]",
18
- errors: {
19
- allowNull: true,
20
- type: "array",
21
- arrayType: "object",
22
- properties: {
23
- filePath: "string",
24
- error: "string"
25
- }
26
- }
27
- }
28
- },
29
- handler: async (req, res) => {
30
- const errors = await req?.editor?.restart();
31
- return res.json({
32
- message: "OK",
33
- reloadString: req.uuid,
34
- migrations: req?.editor?.getMigrations().map(m => m.name),
35
- errors: parseInflateErrors(errors)
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 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import { define } from "@miqro/jsx-dom";
2
- //import "../../../../.types/browser.globals";
3
- import { Editor } from "../../../components/editor.js";
4
- window.addEventListener("load", async (event) => {
5
- define("editor-component", Editor, {
6
- shadowInit: false
7
- });
8
- });
@@ -1,3 +0,0 @@
1
- import { APIRoute } from "@miqro/core";
2
- declare const _default: APIRoute;
3
- export default _default;
@@ -1,23 +0,0 @@
1
- import JSX from "@miqro/jsx";
2
- import { scanDir } from "./api/fs/scan.api.js";
3
- import { HTMLEncode } from "../../../common/html-encode.js";
4
- import { jsx2HTML } from "../../../../src/lib.js";
5
- export default {
6
- description: "ADMIN EDITOR GUI",
7
- path: "/",
8
- method: "GET",
9
- handler: async (req, res) => {
10
- const admin = req.editor;
11
- const errors = admin ? admin.getInflateErrors() : [];
12
- const files = scanDir(req);
13
- const migrations = admin ? admin.getMigrations().map(m => m.name) : [];
14
- const services = admin ? admin.getServices() : ["."];
15
- return res.html("<!DOCTYPE html>" + jsx2HTML(JSX.createElement("html", null,
16
- JSX.createElement("head", null,
17
- JSX.createElement("link", { rel: "stylesheet", href: "/admin/editor/style.css" })),
18
- JSX.createElement("body", null,
19
- JSX.createElement("script", { type: "module", src: "/admin/editor/editor.js" }),
20
- 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))}` },
21
- JSX.createElement("noscript", null, "Enable JavaScript"))))));
22
- }
23
- };
@@ -1,3 +0,0 @@
1
- import { ServerConfig } from "../src/types.js";
2
- declare const _default: ServerConfig;
3
- export default _default;
@@ -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
- };
@@ -1,3 +0,0 @@
1
- import { WSConfig } from "../src/types.js";
2
- declare const _default: WSConfig;
3
- export default _default;
@@ -1,12 +0,0 @@
1
- import { LOG_SOCKET_PATH } from "./common/constants.js";
2
- import { ADMIN_EDITOR_AUTH_KEY } from "./auth.js";
3
- export default {
4
- path: LOG_SOCKET_PATH,
5
- validate(req) {
6
- const admin = req.editor;
7
- const cache = (admin ? admin.getCache() : req.server.cache);
8
- const KEY = cache.get(ADMIN_EDITOR_AUTH_KEY);
9
- const cookieToken = req.cookies[ADMIN_EDITOR_AUTH_KEY];
10
- return cookieToken && KEY && cookieToken === KEY ? true : false;
11
- },
12
- };
@@ -1,14 +0,0 @@
1
- export const EXIT_CODES = {
2
- BAD_ARGUMENTS: 10,
3
- NORMAL_EXIT: 0,
4
- GLOBALS_ALTERED: 80,
5
- ABNORMAL: 98,
6
- ABNORMAL_UNCONTROLLED: 99,
7
- TEST_FAILED: 30,
8
- };
9
- export const CLEAR_JSX_CACHE = (process.env["CLEAR_JSX_CACHE"] !== undefined ? process.env["CLEAR_JSX_CACHE"] : "1") === "1";
10
- export const EDITOR_CONFIG_KEY = "$$editor$$";
11
- export const HOT_RELOAD_PATH = "/hot-reload";
12
- export const HOT_RELOAD_SCRIPT_PATH = "/hot-reload.js";
13
- //export const SERVER_IDENTIFIER = cluster.isPrimary ? "SERVER" : process.env["CLUSTER_NODE_NUMBER"] ? `WORKER_${process.env["CLUSTER_NODE_NUMBER"]}` : "WORKER";
14
- //export const DB_IDENTIFIER = cluster.isPrimary ? "DATABASE" : process.env["CLUSTER_NODE_NUMBER"] ? `WORKER_${process.env["CLUSTER_NODE_NUMBER"]}_DATABASE` : "WORKER_DATABASE";
@@ -1,3 +0,0 @@
1
- export declare const BIN_NAME = "miqro";
2
- export declare const usage = "usage: miqro [...FLAGS] --service app/\n\n==examples==\n\nmiqro --watch --service front/\nPORT=8181 miqro --service api/ --service front/\nmiqro --test --service front/\nmiqro --inflate --service front/\nmiqro --generate-doc --generate-doc-out API.md --service front/\nCLUSTER_COUNT=10 miqro-cluster --service api/";
3
- export declare const help = "\n==flags==\n\n-v, --version\n\toutputs the version number\n-h, --help\n\toutputs this page.\n--disable-etag\n\tuse to disable etag generation by default. each route can still enable this.\n--enable-etag\n\tuse to enable etag generation by default. each route can still disable this. ( by default etag is enabled )\n--watch\n\tuse to auto reload the server when files change.\n--hot-reload\n\tenables the hot-reload functionality use with --watch.\n--test\n\trun the tests for a service.\n--migrate-up\n\tmigrations up.\n--migrate-down\n\tmigrations down.\n--inflate\n\tinflates the application into a directory using esbuild.\n--inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.\n--editor\n\truns the application with a built-in editor.\n--generate-doc\n\tgenerates a documentation for the api endpoints of the service.\n--generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.\n--generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.\n--generate-doc-all\n\toutputs all the server routes in the documentation output.\n--compile\n\tinflates the application and tries to create a NODE SEA binary.\n--no-build\n\tdisables calling esbuild during imports in runtime. Notice that to use jsx you will need to run tsc or esbuild on your jsx files to transpile them to js.\n--no-minify\n\tdisables calling minifing min.js files.\n--inflate-only-assets\n\tinflates ONLY the application assets. must be used with --inflate.\n--inflate-flat\n\tinflates files into the inflate-dir directly.\n--inflate-sea\n\tinflates the application with sea compilation scripts.\n--install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.\n--install-miqrojson\n\tcreates a default miqro.json file.\n--install\n\tcreates a node_modules folder from binary cache (only available in sea binary).\n--disable-miqrojson\n\tdisables the load of miqro.json file.\n--log-file\n\toverrides the default log file from LOG_FILE.\n--browser\n\toverrides the default browser from BROWSER.\n--config\n\toverrides the default miqro.json path.\n--port\n\toverrides the default port from PORT.\n--name\n\toverrides the default name of the server.\n--https\n\tserves the server in https instead of http\n--https-key\n\tpoint to a server.key file for https.\n--https-cert\n\tpoint to a server.cert file for https.\n--https-redirect\n\tserves an aditional http server that redirects to https. it needs a port number.\n--inflate-parallel\n\tsets the max parallel esbuild instances. defaults to 1.\n\n==environment variables==\n\nPORT\n\toverride the default 8080 port.\nBROWSER\n\toverride the default browser. change to none to disable.\".\nLOG_FILE\n\toverride the default ./server.log file\nDB\n\tenable the server.db features\nDB_STORAGE\n\toverride the default local db location ./db.sqlite3\nDB_DIALECT\n\toverride the default node:sqlite\nDB_CONNECTION\n\toverride the default connection url\nCLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.\nJSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.\n";
@@ -1,3 +0,0 @@
1
- import { Logger } from "@miqro/core";
2
- export declare function inflateMD2HTML(inFile: string, logger?: Logger): string;
3
- export declare function inflateMDString2HTML(text: string, logger?: Logger): string;
@@ -1,22 +0,0 @@
1
- import * as showdown from "showdown";
2
- import { readFileSync } from "node:fs";
3
- export function inflateMD2HTML(inFile, logger) {
4
- try {
5
- const text = readFileSync(inFile).toString();
6
- const html = inflateMDString2HTML(text);
7
- return html;
8
- }
9
- catch (e) {
10
- logger?.error("error with: " + inFile);
11
- logger?.error(e);
12
- throw e;
13
- }
14
- }
15
- export function inflateMDString2HTML(text, logger) {
16
- const converter = new showdown.default.Converter();
17
- converter.setFlavor('github');
18
- /*converter.setOption("tables", true);
19
- converter.setOption("rawHeaderId", true);*/
20
- const html = converter.makeHtml(text);
21
- return html;
22
- }
@@ -1,3 +0,0 @@
1
- import { Router } from "@miqro/core";
2
- import { EditorAdminInterface } from "../common/admin-interface.js";
3
- export declare function createEditorRouter(adminInterface: EditorAdminInterface): Promise<Router>;
@@ -1,66 +0,0 @@
1
- import { Router, SessionHandler } from "@miqro/core";
2
- import { getAsset } from "../common/assets.js";
3
- import { BASEEDITOR_PATH } from "../../editor/common/constants.js";
4
- import EDITOR_AUTH from "../../editor/auth.js";
5
- export async function createEditorRouter(adminInterface) {
6
- const router = new Router();
7
- const innerRouter = new Router();
8
- innerRouter.use(async (req, res) => {
9
- res.setHeader("x-uuid", req.uuid);
10
- req.editor = adminInterface;
11
- });
12
- //const editorFont = Buffer.from(getAsset("editor-assets/font.ttf"));
13
- const editorJS = Buffer.from(getAsset("editor-assets/editor.bundle.js")).toString().trim();
14
- const editorCSS = Buffer.from(getAsset("editor-assets/style.css")).toString().trim().split("\n").map(l => l.trim()).filter(l => l).join("");
15
- const writeAPI = (await import("../../editor/http/admin/editor/api/fs/write.api.js")).default;
16
- const renameAPI = (await import("../../editor/http/admin/editor/api/fs/rename.api.js")).default;
17
- const deleteAPI = (await import("../../editor/http/admin/editor/api/fs/delete.api.js")).default;
18
- const readAPI = (await import("../../editor/http/admin/editor/api/fs/read.api.js")).default;
19
- const scanAPI = (await import("../../editor/http/admin/editor/api/fs/scan.api.js")).default;
20
- const restartAPI = (await import("../../editor/http/admin/editor/api/server/restart.api.js")).default;
21
- const reloadAPI = (await import("../../editor/http/admin/editor/api/server/reload.api.js")).default;
22
- const authHandler = SessionHandler(EDITOR_AUTH);
23
- const { EditorIndex } = await import("../../editor/common/editor-index.js");
24
- innerRouter.use(authHandler);
25
- innerRouter.post(`/api/fs/write`, getHandler(/*authHandler, */ writeAPI));
26
- innerRouter.post(`/api/fs/rename`, getHandler(/*authHandler, */ renameAPI));
27
- innerRouter.post(`/api/fs/read`, getHandler(/*authHandler, */ readAPI));
28
- innerRouter.post(`/api/fs/delete`, getHandler(/*authHandler, */ deleteAPI));
29
- innerRouter.get(`/api/fs/scan`, getHandler(/*authHandler, */ scanAPI));
30
- innerRouter.post(`/api/server/restart`, getHandler(/*authHandler, */ restartAPI));
31
- innerRouter.post(`/api/server/reload`, getHandler(/*authHandler, */ reloadAPI));
32
- /*innerRouter.get(`/font.ttf`, async (_req, res) => {
33
- return await res.asyncEnd({
34
- status: 200,
35
- headers: {
36
- ["Content-Type"]: CONTENT_TYPE_MAP[".ttf"]
37
- },
38
- body: editorFont
39
- })
40
- });*/
41
- innerRouter.get("/", EditorIndex(editorCSS, editorJS, false));
42
- innerRouter.use(async (req, res) => {
43
- delete req.editor;
44
- });
45
- router.use(innerRouter, BASEEDITOR_PATH);
46
- return router;
47
- }
48
- function getHandlerOptions(router) {
49
- return {
50
- description: router.description,
51
- //handler: router,
52
- middleware: router.middleware,
53
- request: router.request,
54
- response: router.response,
55
- };
56
- }
57
- function getHandler(/*auth: Handler, */ router) {
58
- /*const ret = new Router();
59
- ret.use(auth);
60
- ret.use(router.handler, undefined, undefined, getHandlerOptions(router));
61
- return ret;*/
62
- return {
63
- ...getHandlerOptions(router),
64
- handler: router.handler
65
- };
66
- }
@@ -1,3 +0,0 @@
1
- import { EditorAdminInterface } from "../../common/admin-interface.js";
2
- import { Miqro } from "../app.js";
3
- export declare function createAdminInterface(app: Miqro): EditorAdminInterface;