miqro 7.0.1 → 7.0.3

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 (148) hide show
  1. package/build/esm/editor/auth.d.ts +6 -0
  2. package/build/esm/editor/auth.js +41 -0
  3. package/build/esm/editor/common/admin-interface.d.ts +36 -0
  4. package/build/esm/editor/common/admin-interface.js +44 -0
  5. package/build/esm/editor/common/constants.d.ts +4 -0
  6. package/build/esm/editor/common/constants.js +20 -0
  7. package/build/esm/editor/common/constants.server.d.ts +2 -0
  8. package/build/esm/editor/common/constants.server.js +4 -0
  9. package/build/esm/editor/common/editor-index.d.ts +2 -0
  10. package/build/esm/editor/common/editor-index.js +14 -0
  11. package/build/esm/editor/common/html-encode.d.ts +1 -0
  12. package/build/esm/editor/common/html-encode.js +14 -0
  13. package/build/esm/editor/common/log-socket.d.ts +15 -0
  14. package/build/esm/editor/common/log-socket.js +71 -0
  15. package/build/esm/editor/common/templates.d.ts +11 -0
  16. package/build/esm/editor/common/templates.js +477 -0
  17. package/build/esm/editor/components/api-preview.d.ts +11 -0
  18. package/build/esm/editor/components/api-preview.js +92 -0
  19. package/build/esm/editor/components/editor.d.ts +16 -0
  20. package/build/esm/editor/components/editor.js +367 -0
  21. package/build/esm/editor/components/file-browser.d.ts +37 -0
  22. package/build/esm/editor/components/file-browser.js +127 -0
  23. package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
  24. package/build/esm/editor/components/file-editor-toolbar.js +95 -0
  25. package/build/esm/editor/components/file-editor.d.ts +32 -0
  26. package/build/esm/editor/components/file-editor.js +61 -0
  27. package/build/esm/editor/components/filter-query.d.ts +1 -0
  28. package/build/esm/editor/components/filter-query.js +23 -0
  29. package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
  30. package/build/esm/editor/components/highlight-text-area.js +127 -0
  31. package/build/esm/editor/components/log-viewer.d.ts +6 -0
  32. package/build/esm/editor/components/log-viewer.js +71 -0
  33. package/build/esm/editor/components/new-file.d.ts +10 -0
  34. package/build/esm/editor/components/new-file.js +119 -0
  35. package/build/esm/editor/components/scroll-query.d.ts +7 -0
  36. package/build/esm/editor/components/scroll-query.js +22 -0
  37. package/build/esm/editor/components/start-page.d.ts +13 -0
  38. package/build/esm/editor/components/start-page.js +32 -0
  39. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +3 -0
  40. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +30 -0
  41. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +5 -0
  42. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +50 -0
  43. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +4 -0
  44. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +40 -0
  45. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
  46. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +150 -0
  47. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
  48. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +39 -0
  49. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
  50. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
  51. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
  52. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +46 -0
  53. package/build/esm/editor/http/admin/editor/editor.d.ts +1 -0
  54. package/build/esm/editor/http/admin/editor/editor.js +8 -0
  55. package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
  56. package/build/esm/editor/http/admin/editor/index.api.js +22 -0
  57. package/build/esm/editor/server.d.ts +3 -0
  58. package/build/esm/editor/server.js +49 -0
  59. package/build/esm/editor/ws.d.ts +3 -0
  60. package/build/esm/editor/ws.js +11 -0
  61. package/build/esm/src/inflate/inflate-sea.js +8 -1
  62. package/build/esm/src/services/app.js +7 -2
  63. package/build/lib.cjs +14 -3
  64. package/editor/auth.ts +51 -0
  65. package/editor/common/admin-interface.ts +84 -0
  66. package/editor/common/constants.server.ts +5 -0
  67. package/editor/common/constants.ts +21 -0
  68. package/editor/common/editor-index.tsx +17 -0
  69. package/editor/common/html-encode.ts +14 -0
  70. package/editor/common/log-socket.tsx +87 -0
  71. package/editor/common/templates.ts +481 -0
  72. package/editor/components/api-preview.tsx +118 -0
  73. package/editor/components/editor.tsx +496 -0
  74. package/editor/components/file-browser.tsx +311 -0
  75. package/editor/components/file-editor-toolbar.tsx +194 -0
  76. package/editor/components/file-editor.tsx +125 -0
  77. package/editor/components/filter-query.tsx +26 -0
  78. package/editor/components/highlight-text-area.tsx +148 -0
  79. package/editor/components/log-viewer.tsx +113 -0
  80. package/editor/components/new-file.tsx +172 -0
  81. package/editor/components/scroll-query.tsx +25 -0
  82. package/editor/components/start-page.tsx +52 -0
  83. package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
  84. package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
  85. package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
  86. package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
  87. package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
  88. package/editor/http/admin/editor/api/server/reload.api.ts +53 -0
  89. package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
  90. package/editor/http/admin/editor/editor.tsx +10 -0
  91. package/editor/http/admin/editor/index.api.tsx +42 -0
  92. package/editor/server.ts +57 -0
  93. package/editor/ws.ts +15 -0
  94. package/package.json +2 -2
  95. package/src/bin/compile.ts +35 -0
  96. package/src/bin/doc-md.ts +210 -0
  97. package/src/bin/generate-doc.ts +64 -0
  98. package/src/bin/test.ts +92 -0
  99. package/src/bin/types.ts +34 -0
  100. package/src/cluster.ts +27 -0
  101. package/src/common/arguments.ts +762 -0
  102. package/src/common/assets.ts +148 -0
  103. package/src/common/checksum.ts +58 -0
  104. package/src/common/constants.ts +18 -0
  105. package/src/common/content-type.ts +84 -0
  106. package/src/common/esbuild.ts +102 -0
  107. package/src/common/exit.ts +91 -0
  108. package/src/common/fs.ts +82 -0
  109. package/src/common/help.ts +60 -0
  110. package/src/common/jsx.ts +562 -0
  111. package/src/common/jwt.ts +85 -0
  112. package/src/common/paths.ts +107 -0
  113. package/src/common/watch.ts +88 -0
  114. package/src/inflate/inflate-sea.ts +244 -0
  115. package/src/inflate/inflate.ts +101 -0
  116. package/src/inflate/md.ts +25 -0
  117. package/src/inflate/setup-auth.ts +41 -0
  118. package/src/inflate/setup-cors.ts +41 -0
  119. package/src/inflate/setup-db.ts +117 -0
  120. package/src/inflate/setup-error.ts +44 -0
  121. package/src/inflate/setup-http.ts +704 -0
  122. package/src/inflate/setup-log.ts +45 -0
  123. package/src/inflate/setup-middleware.ts +47 -0
  124. package/src/inflate/setup-server-config.ts +48 -0
  125. package/src/inflate/setup-test.ts +23 -0
  126. package/src/inflate/setup-ws.ts +50 -0
  127. package/src/inflate/setup.doc.ts +92 -0
  128. package/src/inflate/utils/sea-utils.ts +14 -0
  129. package/src/lib.ts +34 -0
  130. package/src/main.ts +101 -0
  131. package/src/services/app.ts +703 -0
  132. package/src/services/editor.tsx +101 -0
  133. package/src/services/globals.ts.ignore +186 -0
  134. package/src/services/hot-reload.ts +51 -0
  135. package/src/services/migrations.ts +68 -0
  136. package/src/services/utils/admin-interface.ts +37 -0
  137. package/src/services/utils/cache.ts +88 -0
  138. package/src/services/utils/cluster-cache.ts +230 -0
  139. package/src/services/utils/cluster-ws.ts +202 -0
  140. package/src/services/utils/db-manager.ts +92 -0
  141. package/src/services/utils/get-route.ts +70 -0
  142. package/src/services/utils/jwt.ts +25 -0
  143. package/src/services/utils/log-transport.ts +81 -0
  144. package/src/services/utils/log.ts +92 -0
  145. package/src/services/utils/middleware.ts +10 -0
  146. package/src/services/utils/server-interface.ts +122 -0
  147. package/src/services/utils/websocketmanager.ts +157 -0
  148. package/src/types.ts +307 -0
@@ -0,0 +1,210 @@
1
+ import { GroupPolicy, Logger, ParserMode, RouteJSONDoc, RouterJSONDoc, SchemaProperties } from "@miqro/core";
2
+ import { Schema } from "@miqro/parser";
3
+
4
+ /*interface SchemaProperties {
5
+ [key: string]: Schema | string;
6
+ }
7
+
8
+ type ParserMode = "add_extra" | "no_extra" | "remove_extra"*/
9
+
10
+ export async function getMDDoc(args: { ignore?: string[], showFilePath?: boolean; jsonDoc: RouterJSONDoc }, logger?: Logger) {
11
+
12
+ const pathList = Object.keys(args.jsonDoc).sort();
13
+
14
+ let outMD = "";
15
+
16
+ const tableIndexItems = [];
17
+
18
+ for (const path of pathList) {
19
+ const pathData = args.jsonDoc[path];
20
+ const methods = Object.keys(pathData);
21
+ for (const method of methods) {
22
+ if (method) {
23
+ const apiDataList: RouteJSONDoc[] = pathData[method];
24
+ for (const apiData of apiDataList) {
25
+ tableIndexItems.push({
26
+ apiData
27
+ });
28
+ outMD += `## ${apiData.identifier/*.replaceAll("_", "-")*/}\n\n`;
29
+ outMD += `${args.showFilePath && (apiData as any).___filePath ? (apiData as any).___filePath + "\n\n" : ""}`;
30
+
31
+ if (apiData.name) {
32
+ outMD += `${apiData.name}\n\n`;
33
+ }
34
+ if (apiData.description) {
35
+ outMD += `${apiData.description}\n\n`;
36
+ }
37
+ outMD += `[${method}] ${path}\n\n`;
38
+
39
+ outMD += `[${path}](${path}) \n\n`;
40
+
41
+ if (apiData.policy) {
42
+ outMD += `### policy\n\n`;
43
+ outMD += policyToString(apiData.policy);
44
+ }
45
+ if (apiData.request) {
46
+ const requestOutMD = parserToString(apiData.request);
47
+ outMD += requestOutMD !== "" ? `### request\n\n${requestOutMD}` : "";
48
+ }
49
+ if (apiData.response && typeof apiData.response !== "boolean") {
50
+ const responseOutMD = parserToString(apiData.response);
51
+ outMD += responseOutMD !== "" ? `### response\n\n${responseOutMD}` : "";
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ const indexTable = getIndexTable(tableIndexItems);
59
+
60
+ return `${indexTable}\n\n${outMD}`;
61
+ }
62
+
63
+ function getIndexTable(data: {
64
+ apiData: RouteJSONDoc;
65
+ }[]): string {
66
+ return `${data.map(api => `[${api.apiData.identifier/*.replaceAll("_", "-")*/}](#${api.apiData.identifier/*.replaceAll("_", "-")*/.toLocaleLowerCase()})${api.apiData.name || api.apiData.description ? `\n\n\t${api.apiData.name ? api.apiData.name + " " : ""}${api.apiData.description ? api.apiData.description : ""}` : ""}`).join("\n\n")}`;
67
+ }
68
+
69
+ function policyToString(policy: GroupPolicy): string {
70
+ let outMD = "| groups | policy |\n";
71
+ outMD += "|--------|--------|\n";
72
+ outMD += `| ${(policy.groups instanceof Array ? policy.groups : [policy.groups]).join(",")} | ${policy.groupPolicy} |\n\n`;
73
+ return outMD;
74
+ }
75
+
76
+ export function parserToString(parser: {
77
+ status?: number | number[],
78
+ headers?: string | SchemaProperties | SchemaProperties[];
79
+ headersMode?: ParserMode;
80
+ query?: string | SchemaProperties | boolean | SchemaProperties[];
81
+ queryMode?: ParserMode;
82
+ params?: string | SchemaProperties | boolean | SchemaProperties[];
83
+ paramsMode?: ParserMode;
84
+ body?: string | SchemaProperties | boolean | SchemaProperties[];
85
+ bodyMode?: ParserMode;
86
+ }): string {
87
+ let outMD = "";
88
+ if (parser.status) {
89
+ outMD += `#### status\n\n${parser.status instanceof Array ? parser.status.join(",") : parser.status}\n\n`;
90
+ }
91
+ if (parser.params && typeof parser.params !== "boolean") {
92
+ outMD += `#### path params\n\n`;
93
+ outMD += parserPartToString(parser.params, parser.paramsMode);
94
+ }
95
+ if (parser.headers) {
96
+ outMD += `#### headers\n\n`;
97
+ outMD += parserPartToString(parser.headers, parser.headersMode);
98
+ }
99
+ if (parser.query && parser.query !== true) {
100
+ outMD += `#### query\n\n`;
101
+ outMD += parserPartToString(parser.query, parser.queryMode);
102
+ }
103
+ if (parser.body && parser.body !== true) {
104
+ outMD += `#### body\n\n`;
105
+ outMD += parserPartToString(parser.body, parser.bodyMode);
106
+ }
107
+ return outMD;
108
+ }
109
+
110
+ function parserPartToString(arg: string | SchemaProperties | false | SchemaProperties[], mode?: ParserMode): string {
111
+ if (arg === false) {
112
+ return "not allowed";
113
+ }
114
+ let outMD = "";
115
+ let maxTabulation = 1;
116
+ const parsers: Array<SchemaProperties | string> | string = arg instanceof Array ? arg : typeof arg === "string" ? [arg] : [arg];
117
+ for (const parser of parsers) {
118
+ const ret = internalParserToString(parser);
119
+ if (ret.maxTabulation > maxTabulation) {
120
+ maxTabulation = ret.maxTabulation;
121
+ }
122
+ outMD += `| | | | ${getTabulation(ret.maxTabulation * 2)}\n`;
123
+ outMD += `|--------|-------|-------|${getTabulation(ret.maxTabulation * 2, true)}\n`;
124
+ outMD += `${ret.out}\n\n`;
125
+ }
126
+ return outMD
127
+ }
128
+
129
+ function internalParserToString(parser: string | SchemaProperties, tabulation = 1): { out: string, maxTabulation: number } {
130
+ let outMD = "";
131
+ let maxTabulation = tabulation;
132
+ if (typeof parser === "string") {
133
+ outMD += `${getTabulation(tabulation)}${parser}|\n`;
134
+ } else {
135
+ const attrNames = Object.keys(parser);
136
+ for (const name of attrNames) {
137
+ const p = parser[name];
138
+ const description = typeof p === "string" ? "" : p.description ? p.description : "";
139
+
140
+ if (typeof p === "string") {
141
+ outMD += `${getTabulation(tabulation)}${name} | ${p}|\n`;
142
+ } else if (p.type.toLocaleLowerCase() === "object" || p.type.toLocaleLowerCase() === "object?") {
143
+ const rString = p.required === false || p.type.toLocaleLowerCase() === "object?" ? "?" : "";
144
+ outMD += `${getTabulation(tabulation)}${name} | object${rString}| ${description}|\n`;
145
+ const ret = parserBaseObjectTypeToString(p, tabulation + 1);
146
+ if (maxTabulation < ret.maxTabulation) {
147
+ maxTabulation = ret.maxTabulation;
148
+ }
149
+ outMD += `${ret.out}`;
150
+ } else if (p.type.toLocaleLowerCase() === "dict" || p.type.toLocaleLowerCase() === "dict?") {
151
+ const rString = p.required === false || p.type.toLocaleLowerCase() === "dict?" ? "?" : "";
152
+ outMD += `${getTabulation(tabulation)}${name} | Dict\\<${p.dictType}\>${rString}| ${description}|\n`;
153
+ if (p.dictType === "object") {
154
+ const ret = parserBaseObjectTypeToString(p, tabulation + 1);
155
+ if (maxTabulation < ret.maxTabulation) {
156
+ maxTabulation = ret.maxTabulation;
157
+ }
158
+ outMD += `${ret.out}`;
159
+ }
160
+ } else if (p.type.toLocaleLowerCase() === "array" || p.type.toLocaleLowerCase() === "array?") {
161
+ const rString = p.required === false || p.type.toLocaleLowerCase() === "array?" ? "?" : "";
162
+ outMD += `${getTabulation(tabulation)}${name} | Array\\<${p.arrayType}\>${rString}| ${description}|\n`;
163
+ if (p.arrayType.toLocaleLowerCase() === "object") {
164
+ const ret = parserBaseObjectTypeToString(p, tabulation + 1);
165
+ if (maxTabulation < ret.maxTabulation) {
166
+ maxTabulation = ret.maxTabulation;
167
+ }
168
+ outMD += `${ret.out}`;
169
+ }
170
+ } else if (p.type.toLocaleLowerCase() === "regex") {
171
+ outMD += `${getTabulation(tabulation)}${name} | ${p.regex}| ${description}|\n`;
172
+ } else if (p.type.toLocaleLowerCase() === "regex?") {
173
+ outMD += `${getTabulation(tabulation)}${name} | ${p.regex}?| ${description}|\n`;
174
+ } else if (p.type.toLocaleLowerCase() === "enum") {
175
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}| ${description}|\n`;
176
+ outMD += `${getTabulation(tabulation + 1)}| ${p.enumValues?.join(",")}|\n`;
177
+ if (maxTabulation < tabulation + 1) {
178
+ maxTabulation = tabulation + 1;
179
+ }
180
+ } else if (p.type.toLocaleLowerCase() === "enum?") {
181
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}?| ${description}|\n`;
182
+ outMD += `${getTabulation(tabulation + 1)}| ${p.enumValues?.join(",")}|\n`;
183
+ if (maxTabulation < tabulation + 1) {
184
+ maxTabulation = tabulation + 1;
185
+ }
186
+ } else {
187
+ const rString = p.required === false ? "?" : "";
188
+ outMD += `${getTabulation(tabulation)}${name} | ${p.type}${rString}| ${description}|\n`;
189
+ }
190
+ }
191
+ }
192
+ return {
193
+ out: outMD,
194
+ maxTabulation
195
+ };
196
+ }
197
+
198
+ function parserBaseObjectTypeToString(arg: Schema, tabulation: number): { out: string; maxTabulation: number } {
199
+ const options: SchemaProperties = arg.properties ? arg.properties : {};
200
+ //const outMD = `${getTabulation(tabulation)}name | type |\n${getTabulation(tabulation)}--------|--------|\n`;
201
+ return internalParserToString(options, tabulation + 1);
202
+ }
203
+
204
+ function getTabulation(n: number, header = false) {
205
+ let out = "";
206
+ for (let i = 0; i < n; i++) {
207
+ out += header ? "-|" : "| ";
208
+ }
209
+ return out;
210
+ }
@@ -0,0 +1,64 @@
1
+ import { Logger, Router } from "@miqro/core";
2
+ import { Arguments } from "../common/arguments.js";
3
+ import { writeFileSync } from "node:fs";
4
+ import { getMDDoc } from "./doc-md.js";
5
+ import { EXIT_CODES } from "../common/constants.js";
6
+ import { InflatedResult } from "../services/app.js";
7
+ import { RouteFileMap } from "../inflate/setup-http.js";
8
+ import { inflateMD2HTML, inflateMDString2HTML } from "../inflate/md.js";
9
+
10
+ export async function generateDocs(args: Arguments, logger: Logger, result: InflatedResult) {
11
+ logger.info("writing [%s]", args.generateDocOut);
12
+ writeFileSync(args.generateDocOut, await getDocOutput(result.router, result.fileMap, args.generateDocAll, args.generateDocType));
13
+ }
14
+
15
+ export async function getDocOutput(router: Router, fileMap: RouteFileMap, generateDocAll: boolean, generateDocType: "MD" | "JSON" | "HTML") {
16
+ /*
17
+ ** TODO FIX THIS MESS
18
+ */
19
+
20
+ const fileMapAPIRouteList = Object.keys(fileMap).map(f => fileMap[f]).filter(fMap => fMap.previewMethod === "api").map(fMap => fMap.routes);
21
+
22
+ const jsonDoc = router.getJSONDoc();
23
+
24
+ if (!generateDocAll) {
25
+ Object.keys(jsonDoc).forEach(path => {
26
+ const methods = Object.keys(jsonDoc[path]);
27
+ methods.forEach(method => {
28
+ const data = jsonDoc[path][method];
29
+ //console.log("[%s] [%s]", path, method);
30
+
31
+ if (fileMapAPIRouteList.filter(f => {
32
+ for (const r of f) {
33
+ if (r.method === String(method).toUpperCase() && r.path === path) {
34
+ return true;
35
+ }
36
+ }
37
+ return false;
38
+ }).length === 0) {
39
+ //console.log("DELETE [%s] [%s]", path, method);
40
+ delete jsonDoc[path][method];
41
+ } else {
42
+ //console.log("KEEP [%s] [%s]", path, method);
43
+ }
44
+
45
+ });
46
+ });
47
+ }
48
+
49
+ switch (generateDocType) {
50
+ case "JSON":
51
+ return JSON.stringify(jsonDoc, undefined, 2);
52
+ break;
53
+ case "MD":
54
+ return await getMDDoc({ showFilePath: true, jsonDoc });
55
+ break;
56
+ case "HTML":
57
+ const md = await getMDDoc({ showFilePath: true, jsonDoc });
58
+ const html = inflateMDString2HTML(md);
59
+ return html;
60
+ break;
61
+ default:
62
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
63
+ }
64
+ }
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { RequestOptions, request as reqlRequest } from "@miqro/request";
4
+ import { resetGlobals, runTests } from "@miqro/test/dist/runner/common.js";
5
+ import { getServicePath, TEST_SOCKET } from "../common/paths.js";
6
+ import { createNodeRuntime } from "@miqro/jsx-node";
7
+ import { RuntimeOptions, RuntimeShadowRootInit, RuntimeURL } from "@miqro/jsx";
8
+ import { EXIT_CODES } from "../common/constants.js";
9
+ import { Miqro } from "../services/app.js";
10
+ import { setupTests } from "../inflate/setup-test.js";
11
+
12
+ export async function testMain(app: Miqro) {
13
+ const startMS = Date.now();
14
+ //resetTests();
15
+ resetGlobals();
16
+ //const testLogger = getLogger("test");
17
+ globalThis.test = {
18
+ PORT: TEST_SOCKET,
19
+ request: (request: RequestOptions) => reqlRequest({
20
+ ...request,
21
+ socketPath: TEST_SOCKET
22
+ }),
23
+ logger: app.logger,
24
+ sleep: async (ms: number) => new Promise(resolve => setTimeout(resolve, ms)),
25
+ jsx: {
26
+ createRuntime: createNodeRuntime,
27
+ test: (cb, args: {
28
+ runtimeOptions?: {
29
+ basePath?: string | null;
30
+ url?: RuntimeURL;
31
+ logger?: {
32
+ log: Function;
33
+ error: Function;
34
+ };
35
+ },
36
+ containerOptions?: {
37
+ runtimeOptions?: RuntimeOptions;
38
+ shadowInit?: boolean | RuntimeShadowRootInit;
39
+ };
40
+ }) => {
41
+ return async () => {
42
+ const runtime = createNodeRuntime(args.runtimeOptions);
43
+ const root = runtime.createElement("root");
44
+ const container = runtime.createContainer(root, args.containerOptions);
45
+ await cb(container, root, runtime);
46
+ container.disconnect();
47
+ }
48
+ }
49
+ }
50
+ }
51
+
52
+ for (const service of app.options.services) {
53
+ const servicePath = getServicePath(service);
54
+ await setupTests(app.logger, servicePath);
55
+ }
56
+
57
+ console.log("");
58
+ app.logger.log("===starting tests===");
59
+ console.log("");
60
+
61
+ const ret = await runTests(undefined, app.logger);
62
+
63
+ console.log("");
64
+ app.logger.log("===tests ended===");
65
+ if (ret.failed.length > 0) {
66
+ console.log("");
67
+ app.logger.error("===failed tests===");
68
+ console.log("");
69
+ }
70
+
71
+ const took = Date.now() - startMS;
72
+ ret.failed.forEach(e => {
73
+ app.logger.error("\x1b[31m%s\x1b[0m", e.fullName);
74
+ app.logger.error(e.error);
75
+ });
76
+
77
+
78
+ console.log("");
79
+ app.logger.log(ret.passed + " tests passed");
80
+ if (ret.failed.length > 0) {
81
+ app.logger.error(ret.failed.length + " failed");
82
+ } else {
83
+ app.logger.log(ret.failed.length + " failed");
84
+ }
85
+
86
+ app.logger.log("took " + took + "ms");
87
+
88
+ if (ret.failed.length > 0) {
89
+ process.exit(EXIT_CODES.TEST_FAILED);
90
+ }
91
+ await app.dbManager.closeAll();
92
+ }
@@ -0,0 +1,34 @@
1
+ import { MinimalLogger } from "@miqro/core";
2
+ import { Arguments } from "../common/arguments.js";
3
+ // import { initTypes } from "../common/assets.js";
4
+ import { existsSync, writeFileSync } from "node:fs";
5
+ import { TEMPLATES } from "../../editor/common/templates.js";
6
+ import { EXIT_CODES } from "../common/constants.js";
7
+ import { installAsset } from "../common/assets.js";
8
+
9
+ export async function installTypings(args: Arguments, logger: MinimalLogger) {
10
+ /*if (args.installTypes) {
11
+ logger.debug("writing types");
12
+ // install typing for typescript only if argument --install-types is set
13
+ await initTypes(logger);
14
+ }*/
15
+ if (args.install) {
16
+ logger.debug("writing node_modules");
17
+ await installAsset(logger, ["node_modules/"]);
18
+ }
19
+ if (args.installTSConfig && !existsSync("tsconfig.json")) {
20
+ logger.info("writing tsconfig.json");
21
+ writeFileSync("tsconfig.json", TEMPLATES["TSCONFIGJSON"].template("", ""));
22
+ } else if (args.installTSConfig) {
23
+ logger.error("tsconfig.json already exists!");
24
+ process.exit(EXIT_CODES.ABNORMAL);
25
+ }
26
+ if (args.installMiqroJSON && !existsSync("miqro.json")) {
27
+ logger.info("writing miqro.json");
28
+ writeFileSync("miqro.json", TEMPLATES["MIQROJSON"].template("", ""));
29
+ } else if (args.installMiqroJSON) {
30
+ logger.error("miqro.json already exists!");
31
+ process.exit(EXIT_CODES.ABNORMAL);
32
+ }
33
+ process.exit(EXIT_CODES.NORMAL_EXIT);
34
+ }
package/src/cluster.ts ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { mainPath } from "@miqro/runner";
4
+ import { dirname, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { execSync } from "node:child_process";
7
+ import { parseArguments } from "./common/arguments.js";
8
+ import { checkEnvVariable } from "@miqro/core";
9
+ import { cpus } from "node:os";
10
+
11
+ const __package_dirname = import.meta.url ? resolve(dirname(fileURLToPath(import.meta.url))) : null;
12
+
13
+ //const usage = "CLUSTER_COUNT=os.cpus().length [CLUSTER_AUTO_BROADCAST=true|false] [CLUSTER_DISABLE_RESTART=true|false]";
14
+
15
+ const CLUSTER_COUNT = checkEnvVariable("CLUSTER_COUNT", String(cpus().length));
16
+
17
+ const args = parseArguments();
18
+
19
+ if (args.inflate || args.test || args.compile || args.installTSConfig/* || args.installTypes */ || args.migrateDown || args.migrateUp) {
20
+ await import("./main.js");
21
+ } else {
22
+ const CMD = `CLUSTER_COUNT=${CLUSTER_COUNT} CLUSTER_AUTO_BROADCAST=true ${process.argv[0]} ${mainPath()} ${resolve(__package_dirname, "main.js")} ${process.argv.slice(2).join(" ")}`;
23
+
24
+ console.log(CMD);
25
+
26
+ execSync(CMD, { stdio: 'inherit' });
27
+ }