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.
Files changed (216) hide show
  1. package/README.md +9 -17
  2. package/build/editor.bundle.js +11601 -10129
  3. package/build/esm/src/bin/types.js +10 -5
  4. package/build/esm/src/cluster.js +1 -1
  5. package/build/esm/src/common/arguments.d.ts +1 -1
  6. package/build/esm/src/common/arguments.js +28 -14
  7. package/build/esm/src/common/assets.d.ts +1 -1
  8. package/build/esm/src/common/assets.js +34 -13
  9. package/build/esm/src/common/esbuild.d.ts +4 -1
  10. package/build/esm/src/common/esbuild.js +31 -26
  11. package/build/esm/src/common/exit.js +4 -4
  12. package/build/esm/src/common/help.d.ts +1 -1
  13. package/build/esm/src/common/help.js +0 -1
  14. package/build/esm/src/common/jsx.d.ts +2 -3
  15. package/build/esm/src/common/jsx.js +70 -75
  16. package/build/esm/src/common/paths.d.ts +0 -1
  17. package/build/esm/src/common/paths.js +3 -3
  18. package/build/esm/src/common/watch.d.ts +0 -1
  19. package/build/esm/src/common/watch.js +1 -1
  20. package/build/esm/src/inflate/inflate-sea.js +35 -24
  21. package/build/esm/src/inflate/inflate.js +4 -4
  22. package/build/esm/src/inflate/setup-auth.js +1 -1
  23. package/build/esm/src/inflate/setup-cors.js +1 -1
  24. package/build/esm/src/inflate/setup-db.js +2 -2
  25. package/build/esm/src/inflate/setup-error.js +1 -1
  26. package/build/esm/src/inflate/setup-http.js +16 -16
  27. package/build/esm/src/inflate/setup-log.js +1 -1
  28. package/build/esm/src/inflate/setup-middleware.js +1 -1
  29. package/build/esm/src/inflate/setup-server-config.js +1 -1
  30. package/build/esm/src/inflate/setup-ws.js +1 -1
  31. package/build/esm/src/inflate/setup.doc.d.ts +2 -2
  32. package/build/esm/src/inflate/setup.doc.js +23 -2
  33. package/build/esm/src/inflate/utils/sea-utils.js +2 -2
  34. package/build/esm/src/lib.d.ts +10 -1
  35. package/build/esm/src/lib.js +16 -1
  36. package/build/esm/src/main.js +1 -1
  37. package/build/esm/src/services/app.js +3 -4
  38. package/build/esm/src/services/migrations.js +2 -2
  39. package/build/esm/src/services/utils/jwt.d.ts +2 -0
  40. package/build/esm/src/services/utils/jwt.js +23 -0
  41. package/build/esm/src/services/utils/middleware.d.ts +9 -0
  42. package/build/esm/src/services/utils/middleware.js +9 -0
  43. package/build/esm/src/services/utils/server-interface.js +33 -4
  44. package/build/esm/src/types.d.ts +50 -83
  45. package/build/lib.cjs +15684 -15612
  46. package/package.json +6 -8
  47. package/sea/basic-compile.base64.sh +1 -1
  48. package/sea/basic-compile.sh +1 -1
  49. package/sea/install-nodejs.sh +1 -1
  50. package/sea/node.version.tag +1 -1
  51. package/.eslintrc +0 -15
  52. package/build/esm/editor/auth.d.ts +0 -6
  53. package/build/esm/editor/auth.js +0 -41
  54. package/build/esm/editor/common/admin-interface.d.ts +0 -36
  55. package/build/esm/editor/common/admin-interface.js +0 -44
  56. package/build/esm/editor/common/constants.d.ts +0 -4
  57. package/build/esm/editor/common/constants.js +0 -20
  58. package/build/esm/editor/common/constants.server.d.ts +0 -2
  59. package/build/esm/editor/common/constants.server.js +0 -4
  60. package/build/esm/editor/common/editor-index.d.ts +0 -2
  61. package/build/esm/editor/common/editor-index.js +0 -14
  62. package/build/esm/editor/common/html-encode.d.ts +0 -1
  63. package/build/esm/editor/common/html-encode.js +0 -14
  64. package/build/esm/editor/common/log-socket.d.ts +0 -15
  65. package/build/esm/editor/common/log-socket.js +0 -70
  66. package/build/esm/editor/common/templates.d.ts +0 -11
  67. package/build/esm/editor/common/templates.js +0 -477
  68. package/build/esm/editor/components/api-preview.d.ts +0 -11
  69. package/build/esm/editor/components/api-preview.js +0 -90
  70. package/build/esm/editor/components/editor.d.ts +0 -16
  71. package/build/esm/editor/components/editor.js +0 -365
  72. package/build/esm/editor/components/file-browser.d.ts +0 -37
  73. package/build/esm/editor/components/file-browser.js +0 -126
  74. package/build/esm/editor/components/file-editor-toolbar.d.ts +0 -22
  75. package/build/esm/editor/components/file-editor-toolbar.js +0 -93
  76. package/build/esm/editor/components/file-editor.d.ts +0 -32
  77. package/build/esm/editor/components/file-editor.js +0 -59
  78. package/build/esm/editor/components/filter-query.d.ts +0 -1
  79. package/build/esm/editor/components/filter-query.js +0 -22
  80. package/build/esm/editor/components/highlight-text-area.d.ts +0 -11
  81. package/build/esm/editor/components/highlight-text-area.js +0 -125
  82. package/build/esm/editor/components/log-viewer.d.ts +0 -6
  83. package/build/esm/editor/components/log-viewer.js +0 -69
  84. package/build/esm/editor/components/new-file.d.ts +0 -10
  85. package/build/esm/editor/components/new-file.js +0 -117
  86. package/build/esm/editor/components/scroll-query.d.ts +0 -7
  87. package/build/esm/editor/components/scroll-query.js +0 -21
  88. package/build/esm/editor/components/start-page.d.ts +0 -13
  89. package/build/esm/editor/components/start-page.js +0 -30
  90. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +0 -3
  91. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +0 -29
  92. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +0 -5
  93. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +0 -49
  94. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +0 -4
  95. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +0 -39
  96. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +0 -26
  97. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +0 -149
  98. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +0 -3
  99. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +0 -38
  100. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +0 -10
  101. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +0 -46
  102. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +0 -10
  103. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +0 -45
  104. package/build/esm/editor/http/admin/editor/editor.d.ts +0 -1
  105. package/build/esm/editor/http/admin/editor/editor.js +0 -7
  106. package/build/esm/editor/http/admin/editor/index.api.d.ts +0 -3
  107. package/build/esm/editor/http/admin/editor/index.api.js +0 -21
  108. package/build/esm/editor/server.d.ts +0 -3
  109. package/build/esm/editor/server.js +0 -49
  110. package/build/esm/editor/ws.d.ts +0 -3
  111. package/build/esm/editor/ws.js +0 -11
  112. package/build/esm/src/services/globals.d.ts +0 -3
  113. package/build/esm/src/services/globals.js +0 -182
  114. package/build/jsx.dom.js +0 -1587
  115. package/build/postject.base64.cjs +0 -1
  116. package/editor/auth.ts +0 -51
  117. package/editor/common/admin-interface.ts +0 -84
  118. package/editor/common/constants.server.ts +0 -5
  119. package/editor/common/constants.ts +0 -21
  120. package/editor/common/editor-index.tsx +0 -17
  121. package/editor/common/html-encode.ts +0 -14
  122. package/editor/common/log-socket.tsx +0 -85
  123. package/editor/common/templates.ts +0 -481
  124. package/editor/components/api-preview.tsx +0 -116
  125. package/editor/components/editor.tsx +0 -494
  126. package/editor/components/file-browser.tsx +0 -308
  127. package/editor/components/file-editor-toolbar.tsx +0 -191
  128. package/editor/components/file-editor.tsx +0 -122
  129. package/editor/components/filter-query.tsx +0 -22
  130. package/editor/components/highlight-text-area.tsx +0 -145
  131. package/editor/components/log-viewer.tsx +0 -110
  132. package/editor/components/new-file.tsx +0 -169
  133. package/editor/components/scroll-query.tsx +0 -22
  134. package/editor/components/start-page.tsx +0 -49
  135. package/editor/http/admin/editor/api/fs/delete.api.tsx +0 -32
  136. package/editor/http/admin/editor/api/fs/read.api.tsx +0 -55
  137. package/editor/http/admin/editor/api/fs/rename.api.tsx +0 -41
  138. package/editor/http/admin/editor/api/fs/scan.api.tsx +0 -181
  139. package/editor/http/admin/editor/api/fs/write.api.tsx +0 -41
  140. package/editor/http/admin/editor/api/server/reload.api.ts +0 -53
  141. package/editor/http/admin/editor/api/server/restart.api.tsx +0 -52
  142. package/editor/http/admin/editor/editor.tsx +0 -8
  143. package/editor/http/admin/editor/index.api.tsx +0 -39
  144. package/editor/server.ts +0 -57
  145. package/editor/ws.ts +0 -15
  146. package/sea/types.json +0 -1
  147. package/src/bin/compile.ts +0 -35
  148. package/src/bin/doc-md.ts +0 -210
  149. package/src/bin/generate-doc.ts +0 -64
  150. package/src/bin/test.ts +0 -92
  151. package/src/bin/types.ts +0 -29
  152. package/src/cluster.ts +0 -27
  153. package/src/common/arguments.ts +0 -745
  154. package/src/common/assets.ts +0 -128
  155. package/src/common/checksum.ts +0 -58
  156. package/src/common/constants.ts +0 -18
  157. package/src/common/content-type.ts +0 -84
  158. package/src/common/esbuild.ts +0 -94
  159. package/src/common/exit.ts +0 -91
  160. package/src/common/fs.ts +0 -82
  161. package/src/common/help.ts +0 -61
  162. package/src/common/jsx.ts +0 -547
  163. package/src/common/jwt.ts +0 -85
  164. package/src/common/paths.ts +0 -107
  165. package/src/common/watch.ts +0 -88
  166. package/src/inflate/inflate-sea.ts +0 -226
  167. package/src/inflate/inflate.ts +0 -101
  168. package/src/inflate/md.ts +0 -25
  169. package/src/inflate/setup-auth.ts +0 -41
  170. package/src/inflate/setup-cors.ts +0 -41
  171. package/src/inflate/setup-db.ts +0 -117
  172. package/src/inflate/setup-error.ts +0 -44
  173. package/src/inflate/setup-http.ts +0 -704
  174. package/src/inflate/setup-log.ts +0 -45
  175. package/src/inflate/setup-middleware.ts +0 -47
  176. package/src/inflate/setup-server-config.ts +0 -48
  177. package/src/inflate/setup-test.ts +0 -23
  178. package/src/inflate/setup-ws.ts +0 -50
  179. package/src/inflate/setup.doc.ts +0 -68
  180. package/src/inflate/utils/sea-utils.ts +0 -14
  181. package/src/lib.ts +0 -19
  182. package/src/main.ts +0 -101
  183. package/src/services/app.ts +0 -699
  184. package/src/services/editor.tsx +0 -101
  185. package/src/services/globals.ts +0 -186
  186. package/src/services/hot-reload.ts +0 -51
  187. package/src/services/migrations.ts +0 -68
  188. package/src/services/utils/admin-interface.ts +0 -37
  189. package/src/services/utils/cache.ts +0 -88
  190. package/src/services/utils/cluster-cache.ts +0 -230
  191. package/src/services/utils/cluster-ws.ts +0 -202
  192. package/src/services/utils/db-manager.ts +0 -92
  193. package/src/services/utils/get-route.ts +0 -70
  194. package/src/services/utils/log-transport.ts +0 -81
  195. package/src/services/utils/log.ts +0 -92
  196. package/src/services/utils/server-interface.ts +0 -92
  197. package/src/services/utils/websocketmanager.ts +0 -157
  198. package/src/types/@esbuild.d.ts +0 -1
  199. package/src/types/@miqro/core.d.ts +0 -2
  200. package/src/types/@miqro/jsx.d.ts +0 -2
  201. package/src/types/@miqro/parser.d.ts +0 -2
  202. package/src/types/@miqro/query.d.ts +0 -2
  203. package/src/types/@miqro/request.d.ts +0 -2
  204. package/src/types/@miqro/test.d.ts +0 -2
  205. package/src/types/@miqro.d.ts +0 -1
  206. package/src/types/@types.d.ts +0 -1
  207. package/src/types/browser.globals.d.ts +0 -1
  208. package/src/types/cookie.d.ts +0 -2
  209. package/src/types/globals.d.ts +0 -2
  210. package/src/types/jose.d.ts +0 -2
  211. package/src/types/jsx.globals.d.ts +0 -38
  212. package/src/types/miqro.d.ts +0 -228
  213. package/src/types/postject.d.ts +0 -1
  214. package/src/types/server.globals.d.ts +0 -47
  215. package/src/types.ts +0 -304
  216. package/tsconfig.json +0 -35
@@ -1,128 +0,0 @@
1
- //import { createRequire } from 'node:module';
2
- import { Logger, MinimalLogger } from "@miqro/core";
3
- import { chmodSync, constants, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
4
- import { getAsset as seaGetAsset, isSea } from "node:sea";
5
- import { dirname, resolve } from "node:path";
6
- import { calculateChecksum, calculateChecksumFromBuffer } from "./checksum.js";
7
- import { arch, cwd, platform } from "node:process";
8
- import { fileURLToPath } from 'node:url';
9
- import { initESBuild } from "./esbuild.js";
10
- import { initJSXJS } from "./jsx.js";
11
- //const require = createRequire(import.meta.url);
12
-
13
- export const __package_dirname = import.meta.url ? resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "..") : null;
14
-
15
- const ASSETS_ROUTER = {
16
- "lib.cjs": "build/lib.cjs",
17
- "version.tag": "sea/version.tag",
18
- "node.version.tag": "sea/node.version.tag",
19
- "esbuild.version.tag": "sea/esbuild.version.tag",
20
- "postject.base64.cjs": "build/postject.base64.cjs",
21
- "sea.basic.config.json": "sea/basic-config.json",
22
- "node.sh": "sea/node.sh",
23
- "install-nodejs.sh": "sea/install-nodejs.sh",
24
- "compile.base64.sh": "sea/basic-compile.base64.sh",
25
- "sign-remove.sh": "sea/sign-remove.sh",
26
- "sign-add.sh": "sea/sign-add.sh",
27
- "app.sh": "sea/app.sh",
28
- "jsx.dom.js": "build/jsx.dom.js",
29
- "types.json": "sea/types.json",
30
- "editor-assets/editor.bundle.js": "build/editor.bundle.js",
31
- "editor-assets/style.css": "build/style.css",
32
- "editor-assets/font.ttf": "build/font.ttf"
33
- }
34
-
35
- export function getAsset(key: string): ArrayBuffer {
36
- if (isSea()) {
37
- return seaGetAsset(key);
38
- } else {
39
- if (!ASSETS_ROUTER[key]) {
40
- if (key === "esbuild-binary") {
41
- if (__package_dirname === null) {
42
- return readFileSync(resolve(`./sea/esbuild`));
43
- } else {
44
- //return readFileSync(resolve(__package_dirname, `./node_modules/@esbuild/${platform}-${arch}/bin/esbuild`));
45
- const esBinaryPath = resolve(dirname(import.meta.resolve(`esbuild`).substring("file://".length)), "..", "..", "@esbuild", `${platform}-${arch}`);
46
- return readFileSync(resolve(esBinaryPath, "bin", "esbuild"));
47
- }
48
- } else {
49
- throw new Error("asset not registered!");
50
- }
51
- }
52
- return readFileSync(resolve(__package_dirname, ASSETS_ROUTER[key]));
53
- }
54
- }
55
-
56
- export function getVersion() {
57
- const VERSION = !isSea() ? "" : Buffer.from(getAsset("version.tag")).toString().trim();
58
- const NODE_VERSION = !isSea() ? "" : Buffer.from(getAsset("node.version.tag")).toString().trim();
59
- const ESBUILD_VERSION = !isSea() ? "" : Buffer.from(getAsset("esbuild.version.tag")).toString().trim();
60
- return {
61
- VERSION,
62
- NODE_VERSION,
63
- ESBUILD_VERSION
64
- }
65
- }
66
-
67
- export async function initAssets(logger: Logger) {
68
- const { VERSION, NODE_VERSION, ESBUILD_VERSION } = getVersion();
69
- if (isSea()) {
70
- logger.debug("version [%s]", VERSION);
71
- logger.debug("Node.js version [%s]", NODE_VERSION);
72
- logger.debug("esbuild version [%s]", ESBUILD_VERSION);
73
- }
74
- logger.debug("platform [%s-%s]", platform, arch);
75
- await Promise.all([initJSXJS(logger), initESBuild(logger)]);
76
- }
77
-
78
- export async function initTypes(logger: MinimalLogger) {
79
- const typesJSON = JSON.parse(Buffer.from(getAsset("types.json")).toString("utf-8"));
80
- await Promise.all(Object.keys(typesJSON).map(typeFile =>
81
- initAsset(logger, resolve(cwd(), "." + typeFile), Buffer.from(typesJSON[typeFile], "base64"))
82
- ));
83
- }
84
-
85
- export async function validateAsset(logger: MinimalLogger | undefined, path: string, internalChecksum: string): Promise<boolean> {
86
- mkdirSync(dirname(path), {
87
- recursive: true
88
- });
89
- if (existsSync(path)) {
90
- logger?.trace("validating [%s]", path);
91
- const checksum = await calculateChecksum(path);
92
- //const internalChecksum = await calculateChecksumFromBuffer(buffer);
93
- if (internalChecksum !== checksum) {
94
- logger?.trace("invalid [%s] checksum", path);
95
- return false;
96
- } else {
97
- logger?.trace("validated [%s]", path);
98
- return true;
99
- }
100
- } else {
101
- logger?.trace("invalid [%s] doesnt exists", path);
102
- return false;
103
- }
104
- }
105
-
106
- export async function initAsset(logger: MinimalLogger, path: string, buffer: Buffer, executable?: boolean, checksum?: Promise<string>, logInstallasInfo = true) {
107
- const valid = await validateAsset(logger, path, checksum === undefined ? await calculateChecksumFromBuffer(buffer) : await checksum);
108
- if (existsSync(path)) {
109
- if (!valid) {
110
- logger.info("updating [%s]", path);
111
- unlinkSync(path);
112
- writeFileSync(path, buffer);
113
- if (executable) {
114
- chmodSync(path, constants.S_IXUSR | constants.S_IRUSR | constants.S_IWUSR);
115
- }
116
- }
117
- } else {
118
- if (!logInstallasInfo) {
119
- logger.debug("installing [%s]", path);
120
- } else {
121
- logger.info("installing [%s]", path);
122
- }
123
- writeFileSync(path, buffer);
124
- if (executable) {
125
- chmodSync(path, constants.S_IXUSR | constants.S_IRUSR | constants.S_IWUSR);
126
- }
127
- }
128
- }
@@ -1,58 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { createReadStream } from "node:fs";
3
- import { Readable } from "node:stream";
4
-
5
- /**
6
- *
7
- * @param {string} filePath
8
- * @returns {Promise<string>} the checksum
9
- */
10
- export async function calculateChecksum(filePath: string): Promise<string> {
11
- return calculateChecksumFromStream(createReadStream(filePath));
12
- }
13
-
14
- /**
15
- *
16
- * @param {string} filePath
17
- * @returns {Promise<string>} the checksum
18
- */
19
- export async function calculateChecksumFromStream(input: Readable): Promise<string> {
20
- return new Promise<string>((resolve, reject) => {
21
- try {
22
- const hash = createHash('sha256');
23
- input.on('readable', () => {
24
- // Only one element is going to be produced by the
25
- // hash stream.
26
- const data = input.read();
27
- if (data)
28
- hash.update(data);
29
- else {
30
- //log(`${hash.digest('hex')} ${filename}`);
31
- resolve(hash.digest('hex').toString());
32
- }
33
- });
34
- input.on("error", (e) => {
35
- reject(e);
36
- });
37
- } catch (e) {
38
- reject(e);
39
- }
40
- });
41
- }
42
-
43
- /**
44
- *
45
- * @param {string} filePath
46
- * @returns {Promise<string>} the checksum
47
- */
48
- export async function calculateChecksumFromBuffer(buffer: Buffer): Promise<string> {
49
- return new Promise<string>((resolve, reject) => {
50
- try {
51
- const hash = createHash('sha256');
52
- hash.update(buffer);
53
- resolve(hash.digest('hex').toString());
54
- } catch (e) {
55
- reject(e);
56
- }
57
- });
58
- }
@@ -1,18 +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
-
10
- export const CLEAR_JSX_CACHE = (process.env["CLEAR_JSX_CACHE"] !== undefined ? process.env["CLEAR_JSX_CACHE"] : "1") === "1";
11
-
12
- export const EDITOR_CONFIG_KEY = "$$editor$$";
13
-
14
- export const HOT_RELOAD_PATH = "/hot-reload";
15
-
16
- //export const SERVER_IDENTIFIER = cluster.isPrimary ? "SERVER" : process.env["CLUSTER_NODE_NUMBER"] ? `WORKER_${process.env["CLUSTER_NODE_NUMBER"]}` : "WORKER";
17
-
18
- //export const DB_IDENTIFIER = cluster.isPrimary ? "DATABASE" : process.env["CLUSTER_NODE_NUMBER"] ? `WORKER_${process.env["CLUSTER_NODE_NUMBER"]}_DATABASE` : "WORKER_DATABASE";
@@ -1,84 +0,0 @@
1
- export const DEFAULT_CONTENT_TYPE = "application/octet-stream";
2
-
3
- export const CONTENT_TYPE_MAP: {
4
- [key: string]: string | undefined;
5
- } = {
6
- ".aac": "audio/aac",
7
- ".abw": "application/x-abiword",
8
- ".arc": "application/x-freearc",
9
- ".avif": "image/avif",
10
- ".avi": "video/x-msvideo",
11
- ".azw": "application/vnd.amazon.ebook",
12
- ".bin": "application/octet-stream",
13
- ".bmp": "image/bmp",
14
- ".bz": "application/x-bzip",
15
- ".bz2": "application/x-bzip2",
16
- ".cda": "application/x-cdf",
17
- ".csh": "application/x-csh",
18
- ".css": "text/css",
19
- ".csv": "text/csv",
20
- ".doc": "application/msword",
21
- ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
22
- ".eot": "application/vnd.ms-fontobject",
23
- ".epub": "application/epub+zip",
24
- ".gz": "application/gzip",
25
- ".gif": "image/gif",
26
- ".htm": "text/html",
27
- ".html": "text/html",
28
- ".ico": "image/vnd.microsoft.icon",
29
- ".ics": "text/calendar",
30
- ".jar": "application/java-archive",
31
- ".jpeg": "image/jpeg",
32
- ".jpg": "image/jpeg",
33
- ".js": "text/javascript",
34
- ".json": "application/json",
35
- ".jsonld": "application/ld+json",
36
- ".mid": "audio/midi audio/x-midi",
37
- ".midi": "audio/midi audio/x-midi",
38
- ".mjs": "text/javascript",
39
- ".mp3": "audio/mpeg",
40
- ".mp4": "video/mp4",
41
- ".mpeg": "video/mpeg",
42
- ".mpkg": "application/vnd.apple.installer+xml",
43
- ".odp": "application/vnd.oasis.opendocument.presentation",
44
- ".ods": "application/vnd.oasis.opendocument.spreadsheet",
45
- ".odt": "application/vnd.oasis.opendocument.text",
46
- ".oga": "audio/ogg",
47
- ".ogv": "video/ogg",
48
- ".ogx": "application/ogg",
49
- ".opus": "audio/opus",
50
- ".otf": "font/otf",
51
- ".png": "image/png",
52
- ".pdf": "application/pdf",
53
- ".php": "application/x-httpd-php",
54
- ".ppt": "application/vnd.ms-powerpoint",
55
- ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
56
- ".rar": "application/vnd.rar",
57
- ".rtf": "application/rtf",
58
- ".sh": "application/x-sh",
59
- ".svg": "image/svg+xml",
60
- ".swf": "application/x-shockwave-flash",
61
- ".tar": "application/x-tar",
62
- ".tif": "image/tiff",
63
- ".tiff": "image/tiff",
64
- ".ts": "video/mp2t",
65
- ".ttf": "font/ttf",
66
- ".txt": "text/plain",
67
- ".vsd": "application/vnd.visio",
68
- ".wav": "audio/wav",
69
- ".weba": "audio/webm",
70
- ".webm": "video/webm",
71
- ".webp": "image/webp",
72
- ".md": "text/markdown",
73
- ".woff": "font/woff",
74
- ".woff2": "font/woff2",
75
- ".xhtml": "application/xhtml+xml",
76
- ".xls": "application/vnd.ms-excel",
77
- ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
78
- ".xml": "application/xml",
79
- ".xul": "application/vnd.mozilla.xul+xml",
80
- ".zip": "application/zip",
81
- ".3gp": "video/3gpp; audio/3gpp",
82
- ".3g2": "video/3gpp2; audio/3gpp2",
83
- ".7z": "application/x-7z-compressed"
84
- };
@@ -1,94 +0,0 @@
1
- import { exec } from "node:child_process";
2
- import { getAsset, initAsset, validateAsset } from "./assets.js";
3
- import { Logger } from "@miqro/core";
4
- import { getESBuildBinaryPath } from "./paths.js";
5
- import { dirname } from "node:path";
6
- import { calculateChecksumFromBuffer } from "./checksum.js";
7
-
8
- let esbuildBinaryBuffer = null; // Buffer.from(getAsset("esbuild-binary"));
9
- let esbuildBinaryChecksumPromise = null; // calculateChecksumFromBuffer(esbuildBinaryBuffer);
10
-
11
- export async function validateESBuild(logger?: Logger) {
12
- return validateAsset(logger, getESBuildBinaryPath(), await esbuildBinaryChecksumPromise);
13
- }
14
-
15
- export async function initESBuild(logger: Logger) {
16
- esbuildBinaryBuffer = esbuildBinaryBuffer ? esbuildBinaryBuffer : Buffer.from(getAsset("esbuild-binary"));
17
- esbuildBinaryChecksumPromise = esbuildBinaryChecksumPromise ? esbuildBinaryChecksumPromise : calculateChecksumFromBuffer(esbuildBinaryBuffer);
18
- return initAsset(logger, getESBuildBinaryPath(), esbuildBinaryBuffer, true, esbuildBinaryChecksumPromise, false);
19
- }
20
-
21
- const NODEJS_EXTERNAL = [
22
- "node:cluster",
23
- "node:assert",
24
- "node:util",
25
- "node:path",
26
- "node:fs",
27
- "node:crypto",
28
- "node:http",
29
- "node:https",
30
- "node:os",
31
- "node:dns",
32
- "node:string_decoder",
33
- "node:stream",
34
- "node:http2",
35
- "node:net",
36
- "node:worker_threads",
37
- "node:process",
38
- "child_process",
39
- "node:child_process",
40
- "core",
41
- "globals",
42
- "jsx.globals",
43
- "server.globals",
44
- "browser.globals",
45
- "sqlite3",
46
- "pg"
47
- ];
48
-
49
- export async function esBuild(options: {
50
- platform?: string;
51
- entryPoints: [string];
52
- bundle?: boolean;
53
- jsxFactory?: string;
54
- jsxFragment?: string;
55
- minify?: boolean;
56
- outfile?: string;
57
- }, logger?: Logger): Promise<{
58
- outputFiles: {
59
- path: string;
60
- contents: any;
61
- }[]
62
- }> {
63
- return new Promise(async (resolve, reject) => {
64
- try {
65
- //const logger = getLogger(`${SERVER_IDENTIFIER}_ESBUILD`);
66
- const valid = await validateESBuild(logger);
67
- const esBuildCMD = `${getESBuildBinaryPath()} "${options.entryPoints[0]}" ${NODEJS_EXTERNAL.map(e => `--external:${e}`).join(" ")} --loader:.js=jsx --jsx-factory=${options.jsxFactory} --jsx-fragment=${options.jsxFragment} ${options.bundle ? " --bundle" : ""}${options.minify ? " --minify" : ""}${options.outfile ? ` --outfile="${options.outfile}"` : ""}${options.platform ? ` --platform=${options.platform}` : ""}`;
68
- logger?.trace(esBuildCMD);
69
- if (!valid) {
70
- const err = new Error(`esbuild installation at [${getESBuildBinaryPath()}] tampered`);
71
- reject(err);
72
- } else {
73
- exec(esBuildCMD, {
74
- maxBuffer: 1024 * 1000 * 2000,
75
- cwd: dirname(options.entryPoints[0])
76
- }, (err, stdout, _stderr) => {
77
- if (err) {
78
- reject(err);
79
- } else {
80
- resolve({
81
- outputFiles: [{
82
- path: "",
83
- contents: stdout
84
- }]
85
- });
86
- }
87
- });
88
- }
89
- } catch (e) {
90
- logger?.error(e);
91
- reject(e);
92
- }
93
- });
94
- }
@@ -1,91 +0,0 @@
1
- import { existsSync, rmdirSync, unlinkSync } from "node:fs";
2
- //import { notifiyServerStop, notifiyServerUnLoad } from "../services/server.js";
3
- import { getESBuildBinaryPath, getJSXJSPath, JSX_TMP_DIR } from "./paths.js";
4
- import { CLEAR_JSX_CACHE } from "./constants.js";
5
- import { resolve } from "node:path";
6
- import { EXIT_CODES } from "./constants.js";
7
- import { Miqro } from "../services/app.js";
8
-
9
- function cleanJSX(app: Miqro) {
10
- app.logger?.trace("trying to clean up esbuild installation at [%s]", getESBuildBinaryPath());
11
- if (existsSync(getESBuildBinaryPath())) {
12
- unlinkSync(getESBuildBinaryPath());
13
- }
14
- if (CLEAR_JSX_CACHE) {
15
- app.logger?.trace("trying to clean up jsx.js installation at [%s]", getJSXJSPath());
16
- if (existsSync(getJSXJSPath())) {
17
- unlinkSync(getJSXJSPath());
18
- }
19
- const buildParendDir = resolve(JSX_TMP_DIR, String(process.pid));
20
- app.logger?.trace("trying to clean up jsx build/import folders at [%s]", buildParendDir);
21
- const buildDir = resolve(buildParendDir, "build");
22
- const importDir = resolve(buildParendDir, "import");
23
- if (existsSync(buildDir)) {
24
- rmdirSync(buildDir);
25
- }
26
- if (existsSync(importDir)) {
27
- rmdirSync(importDir);
28
- }
29
- if (existsSync(buildParendDir)) {
30
- rmdirSync(buildParendDir);
31
- }
32
- }
33
- }
34
-
35
- export function setupExitHandlers(app: Miqro) {
36
- let exceptionOccured = false;
37
-
38
- process.on('uncaughtException', async function (err) {
39
- app.logger?.error('Caught exception: ' + err);
40
- app.logger?.error(err);
41
- exceptionOccured = true;
42
- /*if (app.server) {
43
- notifiyServerConfigSync(app, "unload");
44
- notifiyServerConfigSync(app, "stop");
45
- app.webSocketManager.disconnectAll();
46
- app.dbManager.closeAll();
47
- }*/
48
- cleanJSX(app);
49
- if (app.server) {
50
- app.stop();
51
- }
52
- process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
53
- });
54
-
55
- process.on('exit', async function (code) {
56
- if (exceptionOccured) {
57
- app.logger?.error('Exception occured');
58
- } else {
59
- /*if (app.server) {
60
- notifiyServerConfigSync(app, "unload");
61
- notifiyServerConfigSync(app, "stop");
62
- app.webSocketManager.disconnectAll();
63
- app.dbManager.closeAll();
64
- }*/
65
- cleanJSX(app);
66
- if (app.server) {
67
- app.stop();
68
- }
69
- }
70
- });
71
-
72
- process.on("SIGTERM", function () {
73
- app.logger?.info('SIGTERM received');
74
- process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
75
- });
76
-
77
- process.on('SIGHUP', function () {
78
- app.logger?.info('SIGHUP received');
79
- process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
80
- });
81
-
82
- /*process.on('SIGKILL', function () {
83
- server.logger.info('SIGKILL received');
84
- process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
85
- });*/
86
-
87
- process.on('SIGINT', function () {
88
- app.logger?.info('SIGINT received');
89
- process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
90
- });
91
- }
package/src/common/fs.ts DELETED
@@ -1,82 +0,0 @@
1
- import { mkdir, rmdir, unlink, writeFile } from "node:fs";
2
- import { basename, extname } from "node:path";
3
-
4
- export function describeFilePath(filePath: string) {
5
- const ext = extname(filePath);
6
- const fileName = basename(filePath);
7
- const name = fileName.substring(0, fileName.length - ext.length);
8
- const subExt = extname(name);
9
- const subName = name.substring(0, name.length - subExt.length);
10
- return {
11
- ext,
12
- fileName,
13
- name,
14
- subExt,
15
- subName,
16
- filePath
17
- };
18
- }
19
-
20
- export async function mkdirASync(path: string, options?: Partial<{ recursive: true; }>) {
21
- return new Promise<void>((resolve, reject) => {
22
- try {
23
- mkdir(path, options, (err) => {
24
- if (err) {
25
- reject(err);
26
- } else {
27
- resolve();
28
- }
29
- });
30
- } catch (e) {
31
- reject(e);
32
- }
33
- })
34
- }
35
-
36
- export async function writeFileASync(path: string, body?) {
37
- return new Promise<void>((resolve, reject) => {
38
- try {
39
- writeFile(path, body, (err) => {
40
- if (err) {
41
- reject(err);
42
- } else {
43
- resolve();
44
- }
45
- });
46
- } catch (e) {
47
- reject(e);
48
- }
49
- });
50
- }
51
-
52
- export async function rmdirASync(path: string) {
53
- return new Promise<void>((resolve, reject) => {
54
- try {
55
- rmdir(path, (err) => {
56
- if (err) {
57
- reject(err);
58
- } else {
59
- resolve();
60
- }
61
- });
62
- } catch (e) {
63
- reject(e);
64
- }
65
- });
66
- }
67
-
68
- export async function unlinkASync(path: string) {
69
- return new Promise<void>((resolve, reject) => {
70
- try {
71
- unlink(path, (err) => {
72
- if (err) {
73
- reject(err);
74
- } else {
75
- resolve();
76
- }
77
- });
78
- } catch (e) {
79
- reject(e);
80
- }
81
- });
82
- }
@@ -1,61 +0,0 @@
1
- //import { basename } from "node:path";
2
-
3
- export const BIN_NAME = "miqro"; //,basename(process.argv[0]);
4
-
5
- export const usage = `usage: ${BIN_NAME} [...FLAGS] --service app/
6
-
7
- ==examples==
8
-
9
- ${BIN_NAME} --watch --service front/
10
- PORT=8181 ${BIN_NAME} --service api/ --service front/
11
- ${BIN_NAME} --test --service front/
12
- ${BIN_NAME} --inflate --service front/
13
- ${BIN_NAME} --generate-doc --generate-doc-out API.md --service front/
14
- CLUSTER_COUNT=10 ${BIN_NAME}-cluster --service api/`;
15
-
16
- export const help = `
17
- ==flags==
18
-
19
- -v, --version\n\toutputs the version number
20
- -h, --help\n\toutputs this page.
21
- --watch\n\tuse to auto reload the server when files change.
22
- --hot-reload\n\tenables the hot-reload functionality use with --watch.
23
- --test\n\trun the tests for a service.
24
- --migrate-up\n\tmigrations up.
25
- --migrate-down\n\tmigrations down.
26
- --inflate\n\tinflates the application.
27
- --inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.
28
- --editor\n\truns the application with a built-in editor.
29
- --generate-doc\n\tgenerates a documentation for the api endpoints of the service.
30
- --generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.
31
- --generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.
32
- --generate-doc-all\n\toutputs all the server routes in the documentation output.
33
- --compile\n\tinflates the application and tries to create a NODE SEA binary.
34
- --inflate-sea\n\tinflates the application with sea compilation scripts.
35
- --install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.
36
- --install-types\n\tcreates and updates the .types/ folder use together with --install-tsconfig.
37
- --install-miqrojson\n\tcreates a default miqro.json file.
38
- --disable-miqrojson\n\tdisables the load of miqro.json file.
39
- --log-file\n\toverrides the default log file from LOG_FILE.
40
- --browser\n\toverrides the default browser from BROWSER.
41
- --config\n\toverrides the default miqro.json path.
42
- --port\n\toverrides the default port from PORT.
43
- --name\n\toverrides the default name of the server.
44
- --https\n\tserves the server in https instead of http
45
- --https-key\n\tpoint to a server.key file for https.
46
- --https-cert\n\tpoint to a server.cert file for https.
47
- --https-redirect\n\tserves an aditional http server that redirects to https. it needs a port number.
48
- --inflate-parallel\n\tsets the max parallel esbuild instances. defaults to 1.
49
-
50
- ==environment variables==
51
-
52
- PORT\n\toverride the default 8080 port.
53
- BROWSER\n\toverride the default browser. change to none to disable.".
54
- LOG_FILE\n\toverride the default ./server.log file
55
- DB\n\tenable the server.db features
56
- DB_STORAGE\n\toverride the default local db location ./db.sqlite3
57
- DB_DIALECT\n\toverride the default node:sqlite
58
- DB_CONNECTION\n\toverride the default connection url
59
- CLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.
60
- JSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.
61
- `;