miqro 6.2.13 → 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 (217) 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 +2 -1
  6. package/build/esm/src/common/arguments.js +42 -18
  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 +2 -2
  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 +4 -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 +2 -1
  37. package/build/esm/src/services/app.d.ts +1 -0
  38. package/build/esm/src/services/app.js +4 -5
  39. package/build/esm/src/services/migrations.js +2 -2
  40. package/build/esm/src/services/utils/jwt.d.ts +2 -0
  41. package/build/esm/src/services/utils/jwt.js +23 -0
  42. package/build/esm/src/services/utils/middleware.d.ts +9 -0
  43. package/build/esm/src/services/utils/middleware.js +9 -0
  44. package/build/esm/src/services/utils/server-interface.js +33 -4
  45. package/build/esm/src/types.d.ts +50 -83
  46. package/build/lib.cjs +15694 -15619
  47. package/package.json +6 -8
  48. package/sea/basic-compile.base64.sh +1 -1
  49. package/sea/basic-compile.sh +1 -1
  50. package/sea/install-nodejs.sh +1 -1
  51. package/sea/node.version.tag +1 -1
  52. package/.eslintrc +0 -15
  53. package/build/esm/editor/auth.d.ts +0 -6
  54. package/build/esm/editor/auth.js +0 -41
  55. package/build/esm/editor/common/admin-interface.d.ts +0 -36
  56. package/build/esm/editor/common/admin-interface.js +0 -44
  57. package/build/esm/editor/common/constants.d.ts +0 -4
  58. package/build/esm/editor/common/constants.js +0 -20
  59. package/build/esm/editor/common/constants.server.d.ts +0 -2
  60. package/build/esm/editor/common/constants.server.js +0 -4
  61. package/build/esm/editor/common/editor-index.d.ts +0 -2
  62. package/build/esm/editor/common/editor-index.js +0 -14
  63. package/build/esm/editor/common/html-encode.d.ts +0 -1
  64. package/build/esm/editor/common/html-encode.js +0 -14
  65. package/build/esm/editor/common/log-socket.d.ts +0 -15
  66. package/build/esm/editor/common/log-socket.js +0 -70
  67. package/build/esm/editor/common/templates.d.ts +0 -11
  68. package/build/esm/editor/common/templates.js +0 -477
  69. package/build/esm/editor/components/api-preview.d.ts +0 -11
  70. package/build/esm/editor/components/api-preview.js +0 -90
  71. package/build/esm/editor/components/editor.d.ts +0 -16
  72. package/build/esm/editor/components/editor.js +0 -365
  73. package/build/esm/editor/components/file-browser.d.ts +0 -37
  74. package/build/esm/editor/components/file-browser.js +0 -126
  75. package/build/esm/editor/components/file-editor-toolbar.d.ts +0 -22
  76. package/build/esm/editor/components/file-editor-toolbar.js +0 -93
  77. package/build/esm/editor/components/file-editor.d.ts +0 -32
  78. package/build/esm/editor/components/file-editor.js +0 -59
  79. package/build/esm/editor/components/filter-query.d.ts +0 -1
  80. package/build/esm/editor/components/filter-query.js +0 -22
  81. package/build/esm/editor/components/highlight-text-area.d.ts +0 -11
  82. package/build/esm/editor/components/highlight-text-area.js +0 -125
  83. package/build/esm/editor/components/log-viewer.d.ts +0 -6
  84. package/build/esm/editor/components/log-viewer.js +0 -69
  85. package/build/esm/editor/components/new-file.d.ts +0 -10
  86. package/build/esm/editor/components/new-file.js +0 -117
  87. package/build/esm/editor/components/scroll-query.d.ts +0 -7
  88. package/build/esm/editor/components/scroll-query.js +0 -21
  89. package/build/esm/editor/components/start-page.d.ts +0 -13
  90. package/build/esm/editor/components/start-page.js +0 -30
  91. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +0 -3
  92. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +0 -29
  93. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +0 -5
  94. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +0 -49
  95. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +0 -4
  96. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +0 -39
  97. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +0 -26
  98. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +0 -149
  99. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +0 -3
  100. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +0 -38
  101. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +0 -10
  102. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +0 -46
  103. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +0 -10
  104. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +0 -45
  105. package/build/esm/editor/http/admin/editor/editor.d.ts +0 -1
  106. package/build/esm/editor/http/admin/editor/editor.js +0 -7
  107. package/build/esm/editor/http/admin/editor/index.api.d.ts +0 -3
  108. package/build/esm/editor/http/admin/editor/index.api.js +0 -21
  109. package/build/esm/editor/server.d.ts +0 -3
  110. package/build/esm/editor/server.js +0 -49
  111. package/build/esm/editor/ws.d.ts +0 -3
  112. package/build/esm/editor/ws.js +0 -11
  113. package/build/esm/src/services/globals.d.ts +0 -3
  114. package/build/esm/src/services/globals.js +0 -182
  115. package/build/jsx.dom.js +0 -1587
  116. package/build/postject.base64.cjs +0 -1
  117. package/editor/auth.ts +0 -51
  118. package/editor/common/admin-interface.ts +0 -84
  119. package/editor/common/constants.server.ts +0 -5
  120. package/editor/common/constants.ts +0 -21
  121. package/editor/common/editor-index.tsx +0 -17
  122. package/editor/common/html-encode.ts +0 -14
  123. package/editor/common/log-socket.tsx +0 -85
  124. package/editor/common/templates.ts +0 -481
  125. package/editor/components/api-preview.tsx +0 -116
  126. package/editor/components/editor.tsx +0 -494
  127. package/editor/components/file-browser.tsx +0 -308
  128. package/editor/components/file-editor-toolbar.tsx +0 -191
  129. package/editor/components/file-editor.tsx +0 -122
  130. package/editor/components/filter-query.tsx +0 -22
  131. package/editor/components/highlight-text-area.tsx +0 -145
  132. package/editor/components/log-viewer.tsx +0 -110
  133. package/editor/components/new-file.tsx +0 -169
  134. package/editor/components/scroll-query.tsx +0 -22
  135. package/editor/components/start-page.tsx +0 -49
  136. package/editor/http/admin/editor/api/fs/delete.api.tsx +0 -32
  137. package/editor/http/admin/editor/api/fs/read.api.tsx +0 -55
  138. package/editor/http/admin/editor/api/fs/rename.api.tsx +0 -41
  139. package/editor/http/admin/editor/api/fs/scan.api.tsx +0 -181
  140. package/editor/http/admin/editor/api/fs/write.api.tsx +0 -41
  141. package/editor/http/admin/editor/api/server/reload.api.ts +0 -53
  142. package/editor/http/admin/editor/api/server/restart.api.tsx +0 -52
  143. package/editor/http/admin/editor/editor.tsx +0 -8
  144. package/editor/http/admin/editor/index.api.tsx +0 -39
  145. package/editor/server.ts +0 -57
  146. package/editor/ws.ts +0 -15
  147. package/sea/types.json +0 -1
  148. package/src/bin/compile.ts +0 -35
  149. package/src/bin/doc-md.ts +0 -210
  150. package/src/bin/generate-doc.ts +0 -64
  151. package/src/bin/test.ts +0 -92
  152. package/src/bin/types.ts +0 -29
  153. package/src/cluster.ts +0 -27
  154. package/src/common/arguments.ts +0 -733
  155. package/src/common/assets.ts +0 -128
  156. package/src/common/checksum.ts +0 -58
  157. package/src/common/constants.ts +0 -18
  158. package/src/common/content-type.ts +0 -84
  159. package/src/common/esbuild.ts +0 -94
  160. package/src/common/exit.ts +0 -91
  161. package/src/common/fs.ts +0 -82
  162. package/src/common/help.ts +0 -60
  163. package/src/common/jsx.ts +0 -547
  164. package/src/common/jwt.ts +0 -85
  165. package/src/common/paths.ts +0 -107
  166. package/src/common/watch.ts +0 -85
  167. package/src/inflate/inflate-sea.ts +0 -226
  168. package/src/inflate/inflate.ts +0 -101
  169. package/src/inflate/md.ts +0 -25
  170. package/src/inflate/setup-auth.ts +0 -41
  171. package/src/inflate/setup-cors.ts +0 -41
  172. package/src/inflate/setup-db.ts +0 -117
  173. package/src/inflate/setup-error.ts +0 -44
  174. package/src/inflate/setup-http.ts +0 -704
  175. package/src/inflate/setup-log.ts +0 -45
  176. package/src/inflate/setup-middleware.ts +0 -47
  177. package/src/inflate/setup-server-config.ts +0 -48
  178. package/src/inflate/setup-test.ts +0 -23
  179. package/src/inflate/setup-ws.ts +0 -50
  180. package/src/inflate/setup.doc.ts +0 -68
  181. package/src/inflate/utils/sea-utils.ts +0 -14
  182. package/src/lib.ts +0 -19
  183. package/src/main.ts +0 -100
  184. package/src/services/app.ts +0 -698
  185. package/src/services/editor.tsx +0 -101
  186. package/src/services/globals.ts +0 -186
  187. package/src/services/hot-reload.ts +0 -51
  188. package/src/services/migrations.ts +0 -68
  189. package/src/services/utils/admin-interface.ts +0 -37
  190. package/src/services/utils/cache.ts +0 -88
  191. package/src/services/utils/cluster-cache.ts +0 -230
  192. package/src/services/utils/cluster-ws.ts +0 -202
  193. package/src/services/utils/db-manager.ts +0 -92
  194. package/src/services/utils/get-route.ts +0 -70
  195. package/src/services/utils/log-transport.ts +0 -81
  196. package/src/services/utils/log.ts +0 -92
  197. package/src/services/utils/server-interface.ts +0 -92
  198. package/src/services/utils/websocketmanager.ts +0 -157
  199. package/src/types/@esbuild.d.ts +0 -1
  200. package/src/types/@miqro/core.d.ts +0 -2
  201. package/src/types/@miqro/jsx.d.ts +0 -2
  202. package/src/types/@miqro/parser.d.ts +0 -2
  203. package/src/types/@miqro/query.d.ts +0 -2
  204. package/src/types/@miqro/request.d.ts +0 -2
  205. package/src/types/@miqro/test.d.ts +0 -2
  206. package/src/types/@miqro.d.ts +0 -1
  207. package/src/types/@types.d.ts +0 -1
  208. package/src/types/browser.globals.d.ts +0 -1
  209. package/src/types/cookie.d.ts +0 -2
  210. package/src/types/globals.d.ts +0 -2
  211. package/src/types/jose.d.ts +0 -2
  212. package/src/types/jsx.globals.d.ts +0 -38
  213. package/src/types/miqro.d.ts +0 -228
  214. package/src/types/postject.d.ts +0 -1
  215. package/src/types/server.globals.d.ts +0 -47
  216. package/src/types.ts +0 -304
  217. package/tsconfig.json +0 -35
@@ -1,107 +0,0 @@
1
- import { checkEnvVariable } from "@miqro/core";
2
- import { randomUUID } from "node:crypto";
3
- import { existsSync, statSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import { resolve } from "node:path";
6
- import { cwd, platform } from "node:process";
7
-
8
- export const JSX_TMP_DIR = checkEnvVariable(`JSX_TMP`, resolve(tmpdir(), "jsx_tmp"));
9
-
10
- export const TEST_SOCKET = resolve(JSX_TMP_DIR, `test.${randomUUID()}.sock`);
11
-
12
- export function getServicePath(service: string) {
13
- return resolve(cwd(), service);
14
- }
15
-
16
- const EXTENSIONS = [".ts", ".js", ".cjs"];
17
-
18
- function getFilePath(dirname: string, name: string, extensions: string[]) {
19
- for (const ex of extensions) {
20
- const path = resolve(dirname, name + ex);
21
- if (existsSync(path) && !statSync(path).isDirectory()) {
22
- return path;
23
- }
24
- }
25
- return false;
26
- }
27
-
28
- export function getLogConfigPath(servicePath: string) {
29
- return getFilePath(servicePath, "log", EXTENSIONS);
30
- }
31
-
32
- export function getCORSConfigPath(servicePath: string) {
33
- return getFilePath(servicePath, "cors", EXTENSIONS);
34
- }
35
-
36
- export function getServerConfigPath(servicePath: string) {
37
- return getFilePath(servicePath, "server", EXTENSIONS);
38
- }
39
-
40
- export function getWSConfigPath(servicePath: string) {
41
- return getFilePath(servicePath, "ws", EXTENSIONS);
42
- }
43
-
44
- export function getDBConfigPath(servicePath: string) {
45
- return getFilePath(servicePath, "db", EXTENSIONS);
46
- }
47
-
48
- export function getStaticFilesPath(servicePath: string) {
49
- const staticFilesPath = resolve(servicePath, "static");
50
- if (existsSync(staticFilesPath) && statSync(staticFilesPath).isDirectory()) {
51
- return staticFilesPath;
52
- }
53
- return false;
54
- }
55
-
56
- export function getMiddlewareConfigPath(servicePath: string) {
57
- return getFilePath(servicePath, "middleware", EXTENSIONS);
58
- }
59
-
60
- export function getErrorConfigPath(servicePath: string) {
61
- return getFilePath(servicePath, "catch", EXTENSIONS);
62
- }
63
-
64
- export function getDocConfigPath(servicePath: string) {
65
- return getFilePath(servicePath, "doc", EXTENSIONS);
66
- }
67
-
68
- export function getMiqroJSONPath() {
69
- const miqroRCPath = resolve(cwd(), "miqro.json");
70
- if (existsSync(miqroRCPath) && !statSync(miqroRCPath).isDirectory()) {
71
- return miqroRCPath;
72
- }
73
- return false;
74
- }
75
-
76
- export function getAuthConfigPath(servicePath: string) {
77
- return getFilePath(servicePath, "auth", EXTENSIONS);
78
- }
79
-
80
- export function getHTTPRouterPath(servicePath: string) {
81
- const apiRouterPath = resolve(servicePath, "http");
82
- if (existsSync(apiRouterPath) && statSync(apiRouterPath).isDirectory()) {
83
- return apiRouterPath;
84
- }
85
- return false;
86
- }
87
-
88
- export function getMigrationsPath(servicePath: string) {
89
- const migrationsFolderPath = resolve(servicePath, "migration");
90
- if (existsSync(migrationsFolderPath) && statSync(migrationsFolderPath).isDirectory()) {
91
- return migrationsFolderPath;
92
- }
93
- return false;
94
- }
95
-
96
- export function getESBuildBinaryPath() {
97
- if (platform === "win32") {
98
- return resolve(JSX_TMP_DIR, String(process.pid), "esbuild.exe");
99
- } else {
100
- return resolve(JSX_TMP_DIR, String(process.pid), "esbuild");
101
- }
102
- }
103
-
104
- export function getJSXJSPath() {
105
- return resolve(JSX_TMP_DIR, String(process.pid), "jsx.js");
106
- }
107
-
@@ -1,85 +0,0 @@
1
- import "../services/globals.js";
2
- import { FSWatcher, existsSync, readdirSync, statSync, watch } from "node:fs";
3
- import { resolve } from "node:path";
4
- import { Miqro } from "../services/app.js";
5
-
6
- export async function watchAndServer(app: Miqro) {
7
- let timeout: any;
8
- const watchLogger = app.logger;
9
- const watchers: FSWatcher[] = [];
10
-
11
- /*await start({
12
- logger,
13
- webSocketManager,
14
- dbManager,
15
- services,
16
- editor,
17
- inflateTests: false,
18
- inflateDir: false,
19
- inflateSea: false,
20
- runOnTestPort: false
21
- });*/
22
-
23
- //await app.start();
24
-
25
- function watchHandler(eventType: any, filename: any) {
26
- stopWatch();
27
- watchLogger?.debug(`event type is: ${eventType}`);
28
- if (filename) {
29
- watchLogger?.debug(`filename provided: ${filename}`);
30
- } else {
31
- watchLogger?.debug('filename not provided');
32
- }
33
- watchLogger?.info(`${eventType} on ${filename}`);
34
- clearTimeout(timeout);
35
- timeout = setTimeout(async () => {
36
- try {
37
- stopWatch();
38
- setTimeout(async () => {
39
- watchLogger?.debug("closed");
40
- await app.reload();
41
- reWatch();
42
- }, 500);
43
- } catch (e) {
44
- watchLogger?.error(e);
45
- }
46
- }, 2000);
47
- }
48
-
49
- function watchDir(toWatch: string) {
50
- const files = existsSync(toWatch) ? readdirSync(toWatch) : [];
51
- for (const file of files) {
52
- const filePath = resolve(toWatch, file);
53
- if (statSync(filePath).isDirectory()) {
54
- watchDir(filePath);
55
- } else {
56
- //console.log("toWatch=" + filePath);
57
- watchers.push(watch(filePath, watchHandler));
58
- }
59
- }
60
- }
61
-
62
- function stopWatch() {
63
- const toClose = watchers.splice(0, watchers.length);
64
- for (const watcher of toClose) {
65
- watcher.close();
66
- }
67
- }
68
-
69
-
70
- function reWatch() {
71
- stopWatch();
72
- for (const service of app.options.services) {
73
- const toWatch = resolve(process.cwd(), service);
74
- watchDir(toWatch);
75
- }
76
- }
77
-
78
- watchLogger?.info("watching for changes on [%s]", app.options.services.join(","));
79
- reWatch();
80
- return {
81
- stopWatch: () => {
82
- stopWatch();
83
- }
84
- };
85
- }
@@ -1,226 +0,0 @@
1
- import { Logger } from "@miqro/core";
2
- import { chmodSync, constants, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { basename, dirname, extname, join, relative, resolve } from "node:path";
4
- import { cwd, platform } from "node:process";
5
-
6
- import { RouteFileMap, StaticFileMap } from "./setup-http.js";
7
- import { getAuthConfigPath, getCORSConfigPath, getDBConfigPath, getErrorConfigPath, getMiddlewareConfigPath, getMigrationsPath, getMiqroJSONPath, getServerConfigPath, getServicePath, getWSConfigPath } from "../common/paths.js";
8
- import { getAsset } from "../common/assets.js";
9
- import { migration } from "@miqro/query";
10
- import { esBuild } from "../common/esbuild.js";
11
-
12
- //export const libCJSBuffer = Buffer.from(getAsset("lib.cjs"));
13
- /*export const COMPILESH = Buffer.from(Buffer.from(getAsset("compile.base64.sh")).toString(), "base64");
14
- export const SIGN_REMOVESH = Buffer.from(getAsset("sign-remove.sh"));
15
- export const SIGN_ADDSH = Buffer.from(getAsset("sign-add.sh"));
16
- export const INSTALLNODEJSSH = Buffer.from(getAsset("install-nodejs.sh"));
17
- export const APPSH = Buffer.from(getAsset("app.sh"));
18
- export const NODESH = Buffer.from(getAsset("node.sh"));
19
- export const SEACONFIGJSON = Buffer.from(getAsset("sea.basic.config.json"));
20
- export const POSTJECTCJS = Buffer.from(Buffer.from(getAsset("postject.base64.cjs")).toString(), "base64");*/
21
-
22
- export async function inflateSeaAssets(logger: Logger, inflateDir: string) {
23
- const esbuildBinaryBuffer = Buffer.from(getAsset("esbuild-binary"));
24
- if (platform === "win32") {
25
- writeFile(logger, resolve(inflateDir, "sea", "esbuild.exe"), esbuildBinaryBuffer);
26
- chmodSync(resolve(inflateDir, "sea", "esbuild.exe"), constants.S_IXUSR | constants.S_IRUSR | constants.S_IWUSR);
27
- } else {
28
- writeFile(logger, resolve(inflateDir, "sea", "esbuild"), esbuildBinaryBuffer);
29
- chmodSync(resolve(inflateDir, "sea", "esbuild"), constants.S_IXUSR | constants.S_IRUSR | constants.S_IWUSR);
30
- }
31
- writeFile(logger, resolve(inflateDir, "sea", "postject.cjs"), Buffer.from(Buffer.from(getAsset("postject.base64.cjs")).toString(), "base64"));
32
- writeFile(logger, resolve(inflateDir, "sea", "config.json"), Buffer.from(getAsset("sea.basic.config.json")));
33
- writeFile(logger, resolve(inflateDir, "sea", "run.sh"), Buffer.from(getAsset("app.sh")));
34
- writeFile(logger, resolve(inflateDir, "sea", "node.sh"), Buffer.from(getAsset("node.sh")));
35
- writeFile(logger, resolve(inflateDir, "compile.sh"), Buffer.from(Buffer.from(getAsset("compile.base64.sh")).toString(), "base64"));
36
- writeFile(logger, resolve(inflateDir, "sea", "sign-add.sh"), Buffer.from(getAsset("sign-add.sh")));
37
- writeFile(logger, resolve(inflateDir, "sea", "sign-remove.sh"), Buffer.from(getAsset("sign-remove.sh")));
38
- writeFile(logger, resolve(inflateDir, "install-nodejs.sh"), Buffer.from(getAsset("install-nodejs.sh")));
39
- }
40
-
41
- export async function inflateAppForSea(logger: Logger, inflateDir: string, services: string[], port: string) {
42
-
43
- const PORT = port;
44
-
45
- inflateSeaAssets(logger, inflateDir);
46
-
47
- writeFile(logger, resolve(inflateDir, "sea", "lib.cjs"), Buffer.from(getAsset("lib.cjs")));
48
-
49
- const WSLIST = services.filter(service => getWSConfigPath(resolve(cwd(), service))).map(service => {
50
- return `(await import("../${service}/ws.cjs")).default`;
51
- }).join(",")
52
-
53
- const SERVERCONFIGLIST = services.filter(service => getServerConfigPath(resolve(cwd(), service))).map(service => {
54
- return `(await import("../${service}/server.cjs")).default`;
55
- }).join(",\n");
56
-
57
- const DBCONFIGLIST = services.filter(service => getDBConfigPath(resolve(cwd(), service))).map(service => {
58
- return `new Promise(async (resolve, reject) => {
59
- try {
60
- const db = await dbManager.setupDB((await import("../${service}/db.cjs")).default);
61
- await (await import("./${service}/migration-up.js")).runMigrations(db);
62
- resolve();
63
- } catch(e) {
64
- reject(e);
65
- }
66
-
67
- })`;
68
- }).join(",");
69
-
70
- writeFile(logger, join(inflateDir, "sea", "package.json"), `{ "type": "module", "private": true }`);
71
-
72
- writeFile(logger, join(inflateDir, "sea", "app.cjs"), `const { createServerInterface, ServerRequestHandler, WebSocketManager, initGlobals, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
73
-
74
- async function main() {
75
- const PORT = "${PORT}";
76
- const loggerProvider = new LogProvider();
77
- const localCache = new LocalCache();
78
- const cache = new ClusterCache();
79
- const webSocketManager = new WebSocketManager();
80
- const dbManager = new DBManager();
81
- await initGlobals();
82
- const serverInterface = createServerInterface({
83
- cache,
84
- localCache,
85
- loggerProvider,
86
- wsManager: webSocketManager,
87
- logger: loggerProvider.getLogger("server"),
88
- dbManager,
89
- port: PORT
90
- });
91
-
92
- await Promise.all([${DBCONFIGLIST}]);
93
-
94
- ${!WSLIST ? "" : `\n webSocketManager.replaceALLWS(await Promise.all([${WSLIST}]))`}
95
- const app = new App({
96
- onUpgrade: webSocketManager.onUpgrade
97
- });
98
- ${SERVERCONFIGLIST ? `\n await Promise.all([${SERVERCONFIGLIST}].filter(config=>config.preload).map(config=>config.preload(serverInterface)));\n` : ""}
99
- app.use(ServerRequestHandler(serverInterface));
100
- app.use(LoggerHandler());
101
- ${services.map(service => `app.use(await (await import("./${join(service, "router.js")}")).setupRouter());`).join("\n")}
102
- ${SERVERCONFIGLIST ? `\n await Promise.all([${SERVERCONFIGLIST}].filter(config=>config.load).map(config=>config.load(serverInterface)));\n` : ""}
103
-
104
- await app.listen(PORT);
105
- ${SERVERCONFIGLIST ? `\n await Promise.all([${SERVERCONFIGLIST}].filter(config=>config.start).map(config=>config.start(serverInterface)));` : ""}
106
- loggerProvider.getLogger("server").info("listening on [%s]", PORT);
107
- }
108
- main().catch(e=>console.error(e));
109
- `
110
- );
111
-
112
- logger.log("writing [%s]", relative(cwd(), join(inflateDir, "sea", "app.bundle.cjs")));
113
- await esBuild({
114
- entryPoints: [join(inflateDir, "sea", "app.cjs")],
115
- bundle: true,
116
- minify: true,
117
- jsxFactory: "JSX.createElement",
118
- jsxFragment: "JSX.Fragment",
119
- platform: "node",
120
- outfile: join(inflateDir, "sea", "app.bundle.cjs")
121
- });
122
- const miqroRCPath = getMiqroJSONPath();
123
- if (miqroRCPath) {
124
- writeFile(logger, join(inflateDir, "miqro.json"), readFileSync(miqroRCPath));
125
- }
126
- }
127
-
128
- export async function inflateServiceForSea(logger: Logger, inflateDir: string, service: string, servicePath: string/*, serviceMigrations: string[]*/, serviceRouteFileMap: RouteFileMap, serviceStaticFileMap: StaticFileMap) {
129
- const migrationsFolderPath = getMigrationsPath(servicePath);
130
-
131
- const serviceMigrations: string[] = migrationsFolderPath ? migration.getSortedMigrations(migrationsFolderPath) : [];
132
- writeFile(logger, join(inflateDir, "sea", service, "router.js"), `import { appendAPIModule, Router } from "./../lib.cjs";\n
133
- export async function setupRouter() {
134
- const router = new Router();
135
- ${getErrorConfigPath(servicePath) ? `
136
- const errorConfig = (await import("../../${service}/catch.cjs")).default.default;
137
- if(errorConfig && errorConfig.catch) {
138
- for(const m of errorConfig.catch) {
139
- router.catch(m);
140
- }
141
- }` : ""}
142
- ${getCORSConfigPath(servicePath) ? ` router.use(server.middleware.cors((await import("../../${service}/cors.cjs")).default.default));` : ""}
143
- ${getAuthConfigPath(servicePath) ? ` router.use(server.middleware.session((await import("../../${service}/auth.cjs")).default.default));` : ""}
144
- ${getMiddlewareConfigPath(servicePath) ? `
145
- const middlewareConfig = (await import("../../${service}/middleware.cjs")).default.default;
146
- if(middlewareConfig && middlewareConfig.middleware) {
147
- for(const m of middlewareConfig.middleware) {
148
- router.use(m);
149
- }
150
- }` : ""}
151
- ${Object.keys(serviceRouteFileMap)
152
- .map(filePath => serviceRouteFileMap[filePath])
153
- .filter(data => data.previewMethod === "api")
154
- .map(data => data.routes.map(r => {
155
- const rPath = join(relative(cwd(), dirname(data.filePath)), basename(data.filePath));
156
- if (rPath) {
157
- const rPathExt = extname(rPath);
158
- const apiInflatedPath = join("..", "..", rPath.substring(0, rPath.length - rPathExt.length) + ".cjs");
159
- return ` await appendAPIModule(router, "../../${service}/http", "./${apiInflatedPath}", (await import("./${apiInflatedPath}")).default.default);`;
160
- } else {
161
- return "";
162
- }
163
- }).filter(l => l)[0])
164
- .join("\n")}
165
- router.use(await (await import("./static-router.js")).setupRouter())
166
-
167
- ${getMiddlewareConfigPath(servicePath) ? `
168
- if(middlewareConfig && middlewareConfig.post) {
169
- for(const m of middlewareConfig.post) {
170
- router.use(m);
171
- }
172
- }` : ""}
173
-
174
- return router;
175
- }`);
176
-
177
- writeFile(logger, join(inflateDir, "sea", service, "migration-up.js"), `import { migration } from "./../lib.cjs";\n
178
- export async function runMigrations(db) {
179
- await migration.init(db);
180
- ${serviceMigrations.map(file => {
181
- const name = `${file.substring(0, file.length - extname(file).length)}`;
182
- return ` await migration.up.module(db, "${file}", (await import("../../${service}/migration/${name}.cjs")).default.default)`;
183
- }).join("\n")}
184
- }`);
185
-
186
- writeFile(logger, join(inflateDir, "sea", service, "migration-down.js"), `import { migration } from "./../lib.cjs";\n
187
- export async function runMigrations(db) {
188
- await migration.init(db);
189
- ${serviceMigrations.reverse().map(file => {
190
- const name = `${file.substring(0, file.length - extname(file).length)}`;
191
- return ` await migration.down.module(db, "${file}", (await import("../../${service}/migration/${name}.cjs")).default.default)`;
192
- }).join("\n")}
193
- }`);
194
-
195
- const staticFiles = Object.keys(serviceStaticFileMap);
196
- /*if (staticFiles.length !== 0) {
197
- writeFile(logger, join(inflateDir, "sea", service, "static.base64.json"), JSON.stringify(serviceStaticFileMap));
198
- }*/
199
- writeFile(logger, join(inflateDir, "sea", service, "static-router.js"), `import { appendAPIModule, Router } from "./../lib.cjs";\n
200
- export async function setupRouter() {
201
- const router = new Router();
202
- ${staticFiles.length === 0 ? "" : `
203
- ${staticFiles.map((filePath) => {
204
- return ` router.get("${serviceStaticFileMap[filePath].path}", async (_, res) => {
205
- return res.asyncEnd({
206
- status: 200,
207
- headers: {
208
- ["Content-Type"]: "${serviceStaticFileMap[filePath].contentType}"
209
- },
210
- body: Buffer.from("${serviceStaticFileMap[filePath].body.toString("base64")}", "base64")
211
- });
212
- });`;
213
- }).join("\n")}
214
- `}
215
- return router;
216
- }`);
217
-
218
- }
219
-
220
- function writeFile(logger: Logger, path: string, buffer: Buffer | string) {
221
- logger.log("writing [%s]", relative(cwd(), path));
222
- mkdirSync(dirname(path), {
223
- recursive: true
224
- });
225
- writeFileSync(path, buffer);
226
- }
@@ -1,101 +0,0 @@
1
- import { InflateError } from "../common/jsx.js";
2
- import { Logger, Router } from "@miqro/core";
3
- import { RouteFileMap, setupHTTPRouter, StaticFileMap } from "./setup-http.js";
4
- //import { WSMapConfig } from "./utils/websocketmanager.js";
5
- //import { ServerConfigMap, setupServerConfig } from "./setup-server-config.js";
6
- import { assertGlobalTampered } from "../services/globals.js";
7
- import { getServicePath } from "../common/paths.js";
8
- import { inflateWSConfig } from "./setup-ws.js";
9
- import { inflateAppForSea, inflateServiceForSea } from "./inflate-sea.js";
10
- import { ServerInterface, WSConfig } from "../types.js";
11
- import { LogConfigMap, setupLogConfig } from "./setup-log.js";
12
- import { setupDoc } from "./setup.doc.js";
13
-
14
- export interface InflateAppOptions {
15
- logger?: Logger;
16
- services: string[];
17
- //dbManager: DBManager;
18
- inflateDir: string | undefined | false;
19
- inflateSea: boolean;
20
- //editor: boolean;
21
- //inflateTests: boolean;
22
- hotreload?: boolean;
23
- port: string;
24
- serverInterface: ServerInterface;
25
- inflateParallel?: number;
26
- }
27
-
28
- export async function inflateApp({ inflateParallel, serverInterface, logger, hotreload, services/*, dbManager*/, inflateDir, inflateSea/*, editor, inflateTests*/, port }: InflateAppOptions): Promise<[Router, InflateError[] | null, RouteFileMap, WSConfig[]/*, ServerConfigMap*/, LogConfigMap]> {
29
- logger.trace("inflateApp");
30
- const errors: InflateError[] = [];
31
- //const migrations: string[] = [];
32
- let routeFileMap: RouteFileMap = {};
33
- const wsConfigList: WSConfig[] = [];
34
- const router = new Router();
35
- const logConfigMap: LogConfigMap = {};
36
- //const serverConfigMap: ServerConfigMap = {};
37
-
38
- router.use(assertGlobalTampered);
39
-
40
- /*if (editor) {
41
- logger.info("setting up editor on %s", BASEEDITOR_PATH);
42
- const editorRouter = await createEditorRouter();
43
- router.use(editorRouter);
44
- logger.info("setting up ws on [%s]", LOG_SOCKET_PATH);
45
- wsConfigList.push(editorWSConfig);
46
- serverConfigMap[EDITOR_CONFIG_KEY] = editorServerConfig;
47
- }*/
48
-
49
-
50
-
51
- for (const service of services) {
52
- const serviceRouteFileMap: RouteFileMap = {};
53
- const serviceStaticFileMap: StaticFileMap | null = inflateSea ? {} : null;
54
- const servicePath = getServicePath(service);
55
-
56
- /*const migrationsFolderPath = getMigrationsPath(servicePath);
57
-
58
- const serviceMigrations: string[] = migrationsFolderPath ? migration.getSortedMigrations(migrationsFolderPath) : [];*/
59
-
60
- /*const db = dbManager.getDB(service) ? dbManager.getDB(service) : await setupDB(logger, service, dbManager, inflateDir);;
61
-
62
- if (db && (cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
63
- await runMigrations(logger, db, servicePath, service, inflateDir, serviceMigrations);
64
- }
65
- if (db) {
66
- migrations.push(...serviceMigrations);
67
- }*/
68
-
69
- //await setupDB(logger, service, dbConfigList, inflateDir);
70
-
71
- await setupLogConfig(logger, servicePath, service, logConfigMap, inflateSea ? inflateDir : false, errors);
72
-
73
- router.use(await setupHTTPRouter(serverInterface, logger, hotreload ? hotreload : false, servicePath, service, serviceRouteFileMap, serviceStaticFileMap, inflateDir, inflateSea, errors, inflateParallel));
74
- routeFileMap = {
75
- ...routeFileMap,
76
- ...serviceRouteFileMap
77
- };
78
-
79
- await setupDoc(logger, servicePath, service, router, routeFileMap, inflateDir, errors);
80
-
81
- await inflateWSConfig(logger, servicePath, service, wsConfigList, inflateSea ? inflateDir : undefined, errors);
82
-
83
- //await setupServerConfig(logger, servicePath, service, serverConfigMap, inflateSea ? inflateDir : undefined, errors);
84
-
85
- if (inflateDir && inflateSea) {
86
- await inflateServiceForSea(logger, inflateDir, service, servicePath /*, serviceMigrations*/, serviceRouteFileMap, serviceStaticFileMap);
87
- }
88
-
89
- /*if (inflateTests) {
90
- await setupTests(logger, servicePath);
91
- }*/
92
- }
93
-
94
- if (inflateDir && inflateSea) {
95
- await inflateAppForSea(logger, inflateDir, services, port);
96
- }
97
-
98
- router.use(assertGlobalTampered);
99
-
100
- return errors.length === 0 ? [router, null, routeFileMap/*, migrations*/, wsConfigList/*, serverConfigMap*/, logConfigMap] : [router, errors, routeFileMap/*, migrations*/, wsConfigList/*, serverConfigMap*/, logConfigMap];
101
- }
package/src/inflate/md.ts DELETED
@@ -1,25 +0,0 @@
1
-
2
- import * as showdown from "showdown";
3
- import { readFileSync } from "node:fs";
4
- import { Logger } from "@miqro/core";
5
-
6
- export function inflateMD2HTML(inFile: string, logger?: Logger): string {
7
- try {
8
- const text = readFileSync(inFile).toString();
9
- const html = inflateMDString2HTML(text);
10
- return html;
11
- } catch (e) {
12
- logger?.error("error with: " + inFile);
13
- logger?.error(e);
14
- throw e;
15
- }
16
- }
17
-
18
- export function inflateMDString2HTML(text: string, logger?: Logger): string {
19
- const converter = new (showdown as any).default.Converter();
20
- converter.setFlavor('github');
21
- /*converter.setOption("tables", true);
22
- converter.setOption("rawHeaderId", true);*/
23
- const html = converter.makeHtml(text);
24
- return html;
25
- }
@@ -1,41 +0,0 @@
1
- import { Logger, Router, SessionHandler } from "@miqro/core";
2
- import { importAuthModule, InflateError, inflateJSX } from "../common/jsx.js";
3
- import { getAuthConfigPath } from "../common/paths.js";
4
- import { basename, dirname, join, relative, resolve } from "node:path";
5
- import { mkdirSync, writeFileSync } from "node:fs";
6
- import { cwd } from "node:process";
7
-
8
- export async function setupAUTH(logger: Logger, servicePath: string, service: string, mainRouter: Router, inflateDir: string | undefined | false, inflateSea: boolean, errors: InflateError[]) {
9
- const authPath = getAuthConfigPath(servicePath); //resolve(process.cwd(), service, "auth.ts");
10
-
11
- if (authPath) {
12
- try {
13
- const authModule = await importAuthModule(authPath, logger);
14
- logger.debug("setting up authentication from [%s]", join(service, basename(authPath)));
15
- mainRouter.use(SessionHandler(authModule));
16
-
17
- if (inflateDir && inflateSea) {
18
- const inflatePath = resolve(inflateDir, service, "auth.cjs");
19
- mkdirSync(dirname(inflatePath), {
20
- recursive: true
21
- });
22
- logger.log("writing [%s]", relative(cwd(), inflatePath));
23
- writeFileSync(inflatePath, await inflateJSX(authPath, {
24
- embemedJSX: false,
25
- minify: false,
26
- useExport: true,
27
- platform: "node",
28
- logger
29
- }));
30
- }
31
-
32
- } catch (e) {
33
- errors.push({
34
- filePath: authPath,
35
- error: e
36
- });
37
- logger.error("error with " + authPath);
38
- logger.error(e);
39
- }
40
- }
41
- }
@@ -1,41 +0,0 @@
1
- import { mkdirSync, writeFileSync } from "node:fs";
2
- import { importCORSModule, InflateError, inflateJSX } from "../common/jsx.js";
3
- import { getCORSConfigPath } from "../common/paths.js";
4
- import { CORS, Logger, Router } from "@miqro/core";
5
- import { basename, dirname, join, relative, resolve } from "node:path";
6
- import { cwd } from "node:process";
7
-
8
- export async function setupCORS(logger: Logger, servicePath: string, service: string, mainRouter: Router, inflateDir: string | undefined | false, inflateSea: boolean, errors: InflateError[]) {
9
- const corsPath = getCORSConfigPath(servicePath);
10
-
11
- if (corsPath) {
12
- try {
13
- const corsOptions = await importCORSModule(corsPath, logger);
14
- logger.debug("setting up cors from [%s]", join(service, basename(corsPath)));
15
- mainRouter.use(CORS(corsOptions));
16
-
17
- if (inflateDir && inflateSea) {
18
- const inflatePath = resolve(inflateDir, service, "cors.cjs");
19
- mkdirSync(dirname(inflatePath), {
20
- recursive: true
21
- });
22
- logger.log("writing [%s]", relative(cwd(), inflatePath));
23
- writeFileSync(inflatePath, await inflateJSX(corsPath, {
24
- embemedJSX: false,
25
- minify: false,
26
- useExport: true,
27
- platform: "node",
28
- logger
29
- }));
30
- }
31
-
32
- } catch (e) {
33
- errors.push({
34
- filePath: corsPath,
35
- error: e
36
- });
37
- logger.error("error with " + corsPath);
38
- logger.error(e);
39
- }
40
- }
41
- }