miqro 6.1.2 → 6.1.4

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 (175) hide show
  1. package/build/editor.bundle.js +16 -0
  2. package/build/esm/editor/auth.d.ts +6 -0
  3. package/build/esm/editor/auth.js +41 -0
  4. package/build/esm/editor/common/admin-interface.d.ts +36 -0
  5. package/build/esm/editor/common/admin-interface.js +44 -0
  6. package/build/esm/editor/common/constants.d.ts +4 -0
  7. package/build/esm/editor/common/constants.js +20 -0
  8. package/build/esm/editor/common/constants.server.d.ts +2 -0
  9. package/build/esm/editor/common/constants.server.js +4 -0
  10. package/build/esm/editor/common/editor-index.d.ts +2 -0
  11. package/build/esm/editor/common/editor-index.js +14 -0
  12. package/build/esm/editor/common/html-encode.d.ts +1 -0
  13. package/build/esm/editor/common/html-encode.js +14 -0
  14. package/build/esm/editor/common/log-socket.d.ts +15 -0
  15. package/build/esm/editor/common/log-socket.js +70 -0
  16. package/build/esm/editor/common/templates.d.ts +11 -0
  17. package/build/esm/editor/common/templates.js +477 -0
  18. package/build/esm/editor/components/api-preview.d.ts +11 -0
  19. package/build/esm/editor/components/api-preview.js +90 -0
  20. package/build/esm/editor/components/editor.d.ts +16 -0
  21. package/build/esm/editor/components/editor.js +357 -0
  22. package/build/esm/editor/components/file-browser.d.ts +37 -0
  23. package/build/esm/editor/components/file-browser.js +126 -0
  24. package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
  25. package/build/esm/editor/components/file-editor-toolbar.js +93 -0
  26. package/build/esm/editor/components/file-editor.d.ts +32 -0
  27. package/build/esm/editor/components/file-editor.js +59 -0
  28. package/build/esm/editor/components/filter-query.d.ts +1 -0
  29. package/build/esm/editor/components/filter-query.js +22 -0
  30. package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
  31. package/build/esm/editor/components/highlight-text-area.js +124 -0
  32. package/build/esm/editor/components/log-viewer.d.ts +6 -0
  33. package/build/esm/editor/components/log-viewer.js +69 -0
  34. package/build/esm/editor/components/new-file.d.ts +10 -0
  35. package/build/esm/editor/components/new-file.js +117 -0
  36. package/build/esm/editor/components/scroll-query.d.ts +7 -0
  37. package/build/esm/editor/components/scroll-query.js +21 -0
  38. package/build/esm/editor/components/start-page.d.ts +13 -0
  39. package/build/esm/editor/components/start-page.js +30 -0
  40. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +3 -0
  41. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +29 -0
  42. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +5 -0
  43. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +49 -0
  44. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +4 -0
  45. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +39 -0
  46. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
  47. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +149 -0
  48. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
  49. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +38 -0
  50. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
  51. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
  52. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
  53. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +45 -0
  54. package/build/esm/editor/http/admin/editor/editor.d.ts +1 -0
  55. package/build/esm/editor/http/admin/editor/editor.js +7 -0
  56. package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
  57. package/build/esm/editor/http/admin/editor/index.api.js +21 -0
  58. package/build/esm/editor/server.d.ts +3 -0
  59. package/build/esm/editor/server.js +49 -0
  60. package/build/esm/editor/ws.d.ts +3 -0
  61. package/build/esm/editor/ws.js +11 -0
  62. package/build/esm/src/bin/types.js +8 -0
  63. package/build/esm/src/common/arguments.d.ts +7 -1
  64. package/build/esm/src/common/arguments.js +72 -10
  65. package/build/esm/src/common/help.d.ts +1 -1
  66. package/build/esm/src/common/help.js +33 -29
  67. package/build/esm/src/inflate/setup-ws.d.ts +1 -1
  68. package/build/esm/src/inflate/setup-ws.js +2 -2
  69. package/build/esm/src/main.js +3 -1
  70. package/build/esm/src/services/app.d.ts +2 -0
  71. package/build/esm/src/services/app.js +2 -2
  72. package/build/esm/src/services/utils/log-transport.d.ts +2 -2
  73. package/build/esm/src/services/utils/log-transport.js +8 -3
  74. package/build/esm/src/services/utils/server-interface.d.ts +1 -1
  75. package/build/esm/src/services/utils/server-interface.js +19 -14
  76. package/build/lib.cjs +23 -21
  77. package/editor/auth.ts +51 -0
  78. package/editor/common/admin-interface.ts +84 -0
  79. package/editor/common/constants.server.ts +5 -0
  80. package/editor/common/constants.ts +21 -0
  81. package/editor/common/editor-index.tsx +17 -0
  82. package/editor/common/html-encode.ts +14 -0
  83. package/editor/common/log-socket.tsx +85 -0
  84. package/editor/common/templates.ts +481 -0
  85. package/editor/components/api-preview.tsx +116 -0
  86. package/editor/components/editor.tsx +486 -0
  87. package/editor/components/file-browser.tsx +308 -0
  88. package/editor/components/file-editor-toolbar.tsx +191 -0
  89. package/editor/components/file-editor.tsx +122 -0
  90. package/editor/components/filter-query.tsx +22 -0
  91. package/editor/components/highlight-text-area.tsx +144 -0
  92. package/editor/components/log-viewer.tsx +110 -0
  93. package/editor/components/new-file.tsx +169 -0
  94. package/editor/components/scroll-query.tsx +22 -0
  95. package/editor/components/start-page.tsx +49 -0
  96. package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
  97. package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
  98. package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
  99. package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
  100. package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
  101. package/editor/http/admin/editor/api/server/reload.api.ts +53 -0
  102. package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
  103. package/editor/http/admin/editor/editor.tsx +8 -0
  104. package/editor/http/admin/editor/index.api.tsx +39 -0
  105. package/editor/server.ts +57 -0
  106. package/editor/ws.ts +15 -0
  107. package/package.json +1 -1
  108. package/sea/install-nodejs.sh +1 -1
  109. package/sea/node.version.tag +1 -1
  110. package/src/bin/compile.ts +35 -0
  111. package/src/bin/doc-md.ts +210 -0
  112. package/src/bin/generate-doc.ts +64 -0
  113. package/src/bin/test.ts +92 -0
  114. package/src/bin/types.ts +29 -0
  115. package/src/cluster.ts +27 -0
  116. package/src/common/arguments.ts +576 -0
  117. package/src/common/assets.ts +128 -0
  118. package/src/common/checksum.ts +58 -0
  119. package/src/common/constants.ts +18 -0
  120. package/src/common/content-type.ts +84 -0
  121. package/src/common/esbuild.ts +94 -0
  122. package/src/common/exit.ts +91 -0
  123. package/src/common/fs.ts +17 -0
  124. package/src/common/help.ts +55 -0
  125. package/src/common/jsx.ts +512 -0
  126. package/src/common/paths.ts +158 -0
  127. package/src/common/watch.ts +85 -0
  128. package/src/inflate/inflate-sea.ts +206 -0
  129. package/src/inflate/inflate.ts +99 -0
  130. package/src/inflate/md.ts +25 -0
  131. package/src/inflate/setup-auth.ts +40 -0
  132. package/src/inflate/setup-cors.ts +40 -0
  133. package/src/inflate/setup-db.ts +115 -0
  134. package/src/inflate/setup-error.ts +43 -0
  135. package/src/inflate/setup-http.ts +655 -0
  136. package/src/inflate/setup-log.ts +44 -0
  137. package/src/inflate/setup-middleware.ts +46 -0
  138. package/src/inflate/setup-server-config.ts +47 -0
  139. package/src/inflate/setup-test.ts +23 -0
  140. package/src/inflate/setup-ws.ts +49 -0
  141. package/src/inflate/setup.doc.ts +68 -0
  142. package/src/inflate/utils/sea-utils.ts +14 -0
  143. package/src/lib.ts +19 -0
  144. package/src/main.ts +89 -0
  145. package/src/services/app.ts +660 -0
  146. package/src/services/editor.tsx +101 -0
  147. package/src/services/globals.ts +143 -0
  148. package/src/services/hot-reload.ts +48 -0
  149. package/src/services/migrations.ts +66 -0
  150. package/src/services/utils/admin-interface.ts +37 -0
  151. package/src/services/utils/cache.ts +88 -0
  152. package/src/services/utils/cluster-cache.ts +230 -0
  153. package/src/services/utils/cluster-ws.ts +197 -0
  154. package/src/services/utils/db-manager.ts +92 -0
  155. package/src/services/utils/get-route.ts +70 -0
  156. package/src/services/utils/log-transport.ts +81 -0
  157. package/src/services/utils/log.ts +92 -0
  158. package/src/services/utils/server-interface.ts +179 -0
  159. package/src/services/utils/websocketmanager.ts +149 -0
  160. package/src/types/@esbuild.d.ts +1 -0
  161. package/src/types/@miqro/core.d.ts +2 -0
  162. package/src/types/@miqro/jsx.d.ts +2 -0
  163. package/src/types/@miqro/parser.d.ts +2 -0
  164. package/src/types/@miqro/query.d.ts +2 -0
  165. package/src/types/@miqro/request.d.ts +2 -0
  166. package/src/types/@miqro/test.d.ts +2 -0
  167. package/src/types/@miqro.d.ts +1 -0
  168. package/src/types/@types.d.ts +1 -0
  169. package/src/types/browser.globals.d.ts +9 -0
  170. package/src/types/globals.d.ts +2 -0
  171. package/src/types/jsx.globals.d.ts +37 -0
  172. package/src/types/miqro.d.ts +129 -0
  173. package/src/types/postject.d.ts +1 -0
  174. package/src/types/server.globals.d.ts +72 -0
  175. package/src/types.ts +222 -0
@@ -13,36 +13,40 @@ CLUSTER_COUNT=10 ${BIN_NAME}-cluster --service api/`;
13
13
  export const help = `
14
14
  ==flags==
15
15
 
16
- -v, --version\t\toutputs the version number
17
- -h, --help\t\toutputs this page.
18
- --watch\t\t\tuse to enable the hot-reload functionality.
19
- --test\t\t\trun the tests for a service.
20
- --migrate-up\t\tmigrations up.
21
- --migrate-down\t\tmigrations down.
22
- --inflate\t\tinflates the application.
23
- --inflate-dir\t\tto set the output directory of the --inflate command. default value is inflated/.
24
- --editor\t\truns the application with a built-in editor.
25
- --generate-doc\t\tgenerates a documentation for the api endpoints of the service.
26
- --generate-doc-out\tthe output file for the generated documentation. default value is API.md.
27
- --generate-doc-type\tthe format of the generated documentation. it can be JSON or MD. default value is MD.
28
- --generate-doc-all\toutputs all the server routes in the documentation output.
29
- --compile\t\tinflates the application and tries to create a NODE SEA binary.
30
- --inflate-sea\t\tinflates the application with sea compilation scripts.
31
- --install-tsconfig\tcreates a tsconfig.json configured to use with --install-types.
32
- --install-types\t\tcreates and updates the .types/ folder use together with --install-tsconfig.
33
- --disable-miqrojson\tdisables the load of miqro.json file.
34
- --config\toverrides the default miqro.json path with a new one.
35
- --port\toverrides the default port loading from environment variables.
36
- --name\toverrides the default name of the server.
16
+ -v, --version\n\toutputs the version number
17
+ -h, --help\n\toutputs this page.
18
+ --watch\n\tuse to enable the hot-reload functionality.
19
+ --test\n\trun the tests for a service.
20
+ --migrate-up\n\tmigrations up.
21
+ --migrate-down\n\tmigrations down.
22
+ --inflate\n\tinflates the application.
23
+ --inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.
24
+ --editor\n\truns the application with a built-in editor.
25
+ --generate-doc\n\tgenerates a documentation for the api endpoints of the service.
26
+ --generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.
27
+ --generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.
28
+ --generate-doc-all\n\toutputs all the server routes in the documentation output.
29
+ --compile\n\tinflates the application and tries to create a NODE SEA binary.
30
+ --inflate-sea\n\tinflates the application with sea compilation scripts.
31
+ --install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.
32
+ --install-types\n\tcreates and updates the .types/ folder use together with --install-tsconfig.
33
+ --install-miqrojson\n\tcreates a default miqro.json file.
34
+ --disable-miqrojson\n\tdisables the load of miqro.json file.
35
+ --log-file\n\toverrides the default log file from LOG_FILE.
36
+ --browser\n\toverrides the default browser from BROWSER.
37
+ --config\n\toverrides the default miqro.json path.
38
+ --port\n\toverrides the default port from PORT.
39
+ --name\n\toverrides the default name of the server.
37
40
 
38
41
  ==environment variables==
39
42
 
40
- PORT\t\t\toverride the default 8080 port.
41
- LOG_FILE\t\toverride the default ./server.log file
42
- DB\t\t\tenable the server.db features
43
- DB_STORAGE\t\toverride the default local db location ./db.sqlite3
44
- DB_DIALECT\t\toverride the default node:sqlite
45
- DB_CONNECTION\t\toverride the default connection url
46
- CLEAR_JSX_CACHE\t\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.
47
- JSX_TMP\t\t\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.
43
+ PORT\n\toverride the default 8080 port.
44
+ BROWSER\n\toverride the default browser. change to none to disable.".
45
+ LOG_FILE\n\toverride the default ./server.log file
46
+ DB\n\tenable the server.db features
47
+ DB_STORAGE\n\toverride the default local db location ./db.sqlite3
48
+ DB_DIALECT\n\toverride the default node:sqlite
49
+ DB_CONNECTION\n\toverride the default connection url
50
+ CLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.
51
+ JSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.
48
52
  `;
@@ -1,4 +1,4 @@
1
1
  import { Logger } from "@miqro/core";
2
2
  import { InflateError } from "../common/jsx.js";
3
3
  import { WSConfig } from "../types.js";
4
- export declare function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<false | WSConfig>;
4
+ export declare function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<void>;
@@ -30,7 +30,7 @@ export async function inflateWSConfig(logger, servicePath, service, wsConfigList
30
30
  logger
31
31
  }));
32
32
  }
33
- return wsConfig;
33
+ //return wsConfigList;
34
34
  }
35
35
  catch (e) {
36
36
  errors.push({
@@ -39,7 +39,7 @@ export async function inflateWSConfig(logger, servicePath, service, wsConfigList
39
39
  });
40
40
  logger.error("error with " + wsPath);
41
41
  logger.error(e);
42
- return false;
42
+ //return false;
43
43
  }
44
44
  }
45
45
  }
@@ -9,7 +9,7 @@ import { Miqro } from "./services/app.js";
9
9
  import { TEST_SOCKET } from "./common/paths.js";
10
10
  import { Logger } from "@miqro/core";
11
11
  async function main(args) {
12
- if (args.installTypes || args.installTSConfig) {
12
+ if (args.installTypes || args.installTSConfig || args.installMiqroJSON) {
13
13
  await installTypings(args, new Logger(""));
14
14
  process.exit(EXIT_CODES.NORMAL_EXIT);
15
15
  }
@@ -19,6 +19,8 @@ async function main(args) {
19
19
  name: args.name ? args.name : undefined,
20
20
  port: args.test ? TEST_SOCKET : args.port,
21
21
  services: args.services,
22
+ browser: args.browser,
23
+ logFile: args.logFile,
22
24
  hotreload: args.test ? false : args.hotreload
23
25
  });
24
26
  // check arguments
@@ -18,6 +18,8 @@ export interface MiqroOptions {
18
18
  services: string[];
19
19
  editor: boolean;
20
20
  port: string;
21
+ browser?: string | boolean;
22
+ logFile?: string | boolean;
21
23
  hotreload?: boolean;
22
24
  }
23
25
  export interface InflateOptions {
@@ -183,9 +183,9 @@ export class Miqro {
183
183
  async loadDBConfig(options) {
184
184
  const errors = [];
185
185
  const dbList = [];
186
- const dbConfigList = [];
186
+ const dbConfigListALL = [];
187
187
  for (const service of this.options.services) {
188
- const dbConfig = await inflateDBConfig(this.logger, service, dbConfigList, options?.inflateSea ? options?.inflateDir : undefined, errors);
188
+ const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : undefined, errors);
189
189
  if (dbConfig) {
190
190
  const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : undefined, errors);
191
191
  dbList.push({
@@ -1,7 +1,7 @@
1
- import { WriteArgs } from "@miqro/core";
1
+ import { LoggerTransport, WriteArgs } from "@miqro/core";
2
2
  import { Miqro } from "../app.js";
3
3
  export declare function createLogProviderOptions(app: Miqro): {
4
4
  name: string;
5
- transports: import("@miqro/core").LoggerTransport[];
5
+ transports: LoggerTransport[];
6
6
  formatter: (args: WriteArgs) => string;
7
7
  };
@@ -3,7 +3,12 @@ import { format } from "node:util";
3
3
  import { LOG_SOCKET_PATH, LOG_WRITE_EVENT } from "../../../editor/common/constants.js";
4
4
  export function createLogProviderOptions(app) {
5
5
  const defaultConsole = ConsoleTransport();
6
- const defaultFile = FileTransport();
6
+ //console.log("app.options.logFile [%s]", app.options.logFile);
7
+ const defaultFile = app.options.logFile !== true && app.options.logFile !== false && String(app.options.logFile).toUpperCase() !== "TRUE" && String(app.options.logFile).toUpperCase() !== "FALSE" &&
8
+ app.options.logFile ? FileTransport(app.options.logFile) :
9
+ String(app.options.logFile).toUpperCase() === "TRUE" || app.options.logFile === true || app.options.logFile === undefined ?
10
+ FileTransport() :
11
+ undefined;
7
12
  const defaultWrite = async (args, level) => {
8
13
  try {
9
14
  const serviceNamesWithLogConfigReplaceConsole = level === undefined && app.inflated ?
@@ -12,9 +17,9 @@ export function createLogProviderOptions(app) {
12
17
  Object.keys(app.inflated.logConfigMap).filter(serviceName => app.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
13
18
  await Promise.allSettled((level === undefined ?
14
19
  [
15
- level === undefined && serviceNamesWithLogConfigReplaceConsole.length === 0 ?
20
+ level === undefined && serviceNamesWithLogConfigReplaceConsole.length === 0 && defaultConsole ?
16
21
  defaultConsole.write(args) : Promise.resolve(),
17
- level === undefined && serviceNamesWithLogConfigReplaceFile.length === 0 ?
22
+ level === undefined && serviceNamesWithLogConfigReplaceFile.length === 0 && defaultFile ?
18
23
  defaultFile.write(args) : Promise.resolve()
19
24
  ] : []).concat(app.inflated ?
20
25
  Object.keys(app.inflated.logConfigMap).map(serviceName => app.inflated.logConfigMap[serviceName]).filter(c => c.level === level).map(c => c.write(args)) : []));
@@ -30,11 +30,11 @@ export declare class ServerInterfaceImpl implements ServerInterface {
30
30
  disconnectAll(path: string): void;
31
31
  };
32
32
  loggerProvider?: LogProvider;
33
+ openBrowser: (path: string) => void;
33
34
  constructor(options: ServerInterfaceImplOptions);
34
35
  getWorkerNumber(): number;
35
36
  getWorkerCount(): number;
36
37
  isPrimaryWorker(): boolean;
37
- openBrowser(path: string): void;
38
38
  getLogger(identifier: string, options?: {
39
39
  level?: any;
40
40
  transports?: any[];
@@ -8,6 +8,7 @@ export class ServerInterfaceImpl {
8
8
  db;
9
9
  ws;
10
10
  loggerProvider;
11
+ openBrowser;
11
12
  constructor(options) {
12
13
  this.cache = options.cache;
13
14
  this.localCache = options.localCache;
@@ -17,6 +18,24 @@ export class ServerInterfaceImpl {
17
18
  const wsManager = options.wsManager;
18
19
  this.loggerProvider = options.loggerProvider;
19
20
  const app = options.app;
21
+ this.openBrowser = (path) => {
22
+ const PORT = this.port;
23
+ const URL = `http://localhost${PORT ? `:${PORT}` : ""}${path}`;
24
+ const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
25
+ const OPEN = app.options.browser !== undefined && String(app.options.browser).toUpperCase() !== "TRUE" && String(app.options.browser).toUpperCase() !== "1" ?
26
+ String(app.options.browser).toUpperCase() !== "0" && String(app.options.browser).toUpperCase() !== "FALSE" && String(app.options.browser).toUpperCase() !== "NONE" && app.options.browser ?
27
+ app.options.browser : false :
28
+ process.env["BROWSER"] ?
29
+ process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
30
+ if (OPEN) {
31
+ const openCMD = `${OPEN} "${URL}"`;
32
+ this.logger?.info("opening browser with [%s]", openCMD);
33
+ execSync(openCMD);
34
+ }
35
+ else {
36
+ this.logger?.warn("ignoring browser [%s]", OPEN);
37
+ }
38
+ };
20
39
  this.db = Object.freeze({
21
40
  get: (name) => {
22
41
  return dbManager.getDB(name);
@@ -59,20 +78,6 @@ export class ServerInterfaceImpl {
59
78
  isPrimaryWorker() {
60
79
  return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
61
80
  }
62
- openBrowser(path) {
63
- const PORT = this.port;
64
- const URL = `http://localhost${PORT ? `:${PORT}` : ""}${path}`;
65
- const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
66
- const OPEN = process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
67
- if (OPEN) {
68
- const openCMD = `${OPEN} "${URL}"`;
69
- this.logger?.info("opening browser with [%s]", openCMD);
70
- execSync(openCMD);
71
- }
72
- else {
73
- this.logger?.warn("ignoring browser [%s]", process.env["BROWSER"]);
74
- }
75
- }
76
81
  getLogger(identifier, options) {
77
82
  return this.loggerProvider?.getLogger(identifier, options);
78
83
  }
package/build/lib.cjs CHANGED
@@ -12892,7 +12892,6 @@ async function inflateWSConfig(logger, servicePath, service, wsConfigList, infla
12892
12892
  logger
12893
12893
  }));
12894
12894
  }
12895
- return wsConfig;
12896
12895
  } catch (e) {
12897
12896
  errors.push({
12898
12897
  filePath: wsPath,
@@ -12900,7 +12899,6 @@ async function inflateWSConfig(logger, servicePath, service, wsConfigList, infla
12900
12899
  });
12901
12900
  logger.error("error with " + wsPath);
12902
12901
  logger.error(e);
12903
- return false;
12904
12902
  }
12905
12903
  }
12906
12904
  }
@@ -13929,6 +13927,7 @@ var ServerInterfaceImpl = class {
13929
13927
  db;
13930
13928
  ws;
13931
13929
  loggerProvider;
13930
+ openBrowser;
13932
13931
  constructor(options) {
13933
13932
  this.cache = options.cache;
13934
13933
  this.localCache = options.localCache;
@@ -13938,6 +13937,19 @@ var ServerInterfaceImpl = class {
13938
13937
  const wsManager = options.wsManager;
13939
13938
  this.loggerProvider = options.loggerProvider;
13940
13939
  const app = options.app;
13940
+ this.openBrowser = (path) => {
13941
+ const PORT2 = this.port;
13942
+ const URL2 = `http://localhost${PORT2 ? `:${PORT2}` : ""}${path}`;
13943
+ const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
13944
+ const OPEN = app.options.browser !== void 0 && String(app.options.browser).toUpperCase() !== "TRUE" && String(app.options.browser).toUpperCase() !== "1" ? String(app.options.browser).toUpperCase() !== "0" && String(app.options.browser).toUpperCase() !== "FALSE" && String(app.options.browser).toUpperCase() !== "NONE" && app.options.browser ? app.options.browser : false : process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
13945
+ if (OPEN) {
13946
+ const openCMD = `${OPEN} "${URL2}"`;
13947
+ this.logger?.info("opening browser with [%s]", openCMD);
13948
+ (0, import_node_child_process2.execSync)(openCMD);
13949
+ } else {
13950
+ this.logger?.warn("ignoring browser [%s]", OPEN);
13951
+ }
13952
+ };
13941
13953
  this.db = Object.freeze({
13942
13954
  get: (name) => {
13943
13955
  return dbManager.getDB(name);
@@ -13980,19 +13992,6 @@ var ServerInterfaceImpl = class {
13980
13992
  isPrimaryWorker() {
13981
13993
  return import_node_cluster2.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
13982
13994
  }
13983
- openBrowser(path) {
13984
- const PORT2 = this.port;
13985
- const URL2 = `http://localhost${PORT2 ? `:${PORT2}` : ""}${path}`;
13986
- const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
13987
- const OPEN = process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
13988
- if (OPEN) {
13989
- const openCMD = `${OPEN} "${URL2}"`;
13990
- this.logger?.info("opening browser with [%s]", openCMD);
13991
- (0, import_node_child_process2.execSync)(openCMD);
13992
- } else {
13993
- this.logger?.warn("ignoring browser [%s]", process.env["BROWSER"]);
13994
- }
13995
- }
13996
13995
  getLogger(identifier, options) {
13997
13996
  return this.loggerProvider?.getLogger(identifier, options);
13998
13997
  }
@@ -14024,7 +14023,10 @@ var MiqroJSONSchema = {
14024
14023
  name: "string?",
14025
14024
  services: "string[]?",
14026
14025
  port: "number?|string?",
14027
- inflateDir: "string?"
14026
+ inflateDir: "string?",
14027
+ browser: "boolean?|string?",
14028
+ logFile: "boolean?|string?",
14029
+ editor: "boolean?"
14028
14030
  }
14029
14031
  };
14030
14032
  function importMiqroJSON(inFile) {
@@ -14045,14 +14047,14 @@ var import_node_util3 = require("node:util");
14045
14047
  init_constants();
14046
14048
  function createLogProviderOptions(app) {
14047
14049
  const defaultConsole = ConsoleTransport();
14048
- const defaultFile = FileTransport();
14050
+ const defaultFile = app.options.logFile !== true && app.options.logFile !== false && String(app.options.logFile).toUpperCase() !== "TRUE" && String(app.options.logFile).toUpperCase() !== "FALSE" && app.options.logFile ? FileTransport(app.options.logFile) : String(app.options.logFile).toUpperCase() === "TRUE" || app.options.logFile === true || app.options.logFile === void 0 ? FileTransport() : void 0;
14049
14051
  const defaultWrite = async (args, level) => {
14050
14052
  try {
14051
14053
  const serviceNamesWithLogConfigReplaceConsole = level === void 0 && app.inflated ? Object.keys(app.inflated.logConfigMap).filter((serviceName) => app.inflated.logConfigMap[serviceName].replaceConsoleTransport) : [];
14052
14054
  const serviceNamesWithLogConfigReplaceFile = level === void 0 && app.inflated ? Object.keys(app.inflated.logConfigMap).filter((serviceName) => app.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
14053
14055
  await Promise.allSettled((level === void 0 ? [
14054
- level === void 0 && serviceNamesWithLogConfigReplaceConsole.length === 0 ? defaultConsole.write(args) : Promise.resolve(),
14055
- level === void 0 && serviceNamesWithLogConfigReplaceFile.length === 0 ? defaultFile.write(args) : Promise.resolve()
14056
+ level === void 0 && serviceNamesWithLogConfigReplaceConsole.length === 0 && defaultConsole ? defaultConsole.write(args) : Promise.resolve(),
14057
+ level === void 0 && serviceNamesWithLogConfigReplaceFile.length === 0 && defaultFile ? defaultFile.write(args) : Promise.resolve()
14056
14058
  ] : []).concat(
14057
14059
  app.inflated ? Object.keys(app.inflated.logConfigMap).map((serviceName) => app.inflated.logConfigMap[serviceName]).filter((c) => c.level === level).map((c) => c.write(args)) : []
14058
14060
  ));
@@ -14290,9 +14292,9 @@ var Miqro = class _Miqro {
14290
14292
  async loadDBConfig(options) {
14291
14293
  const errors = [];
14292
14294
  const dbList = [];
14293
- const dbConfigList = [];
14295
+ const dbConfigListALL = [];
14294
14296
  for (const service of this.options.services) {
14295
- const dbConfig = await inflateDBConfig(this.logger, service, dbConfigList, options?.inflateSea ? options?.inflateDir : void 0, errors);
14297
+ const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : void 0, errors);
14296
14298
  if (dbConfig) {
14297
14299
  const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : void 0, errors);
14298
14300
  dbList.push({
package/editor/auth.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { AuthConfig, ServerRequest } from "../src/types.js";
2
+ import { AdminRequest } from "./common/admin-interface.js";
3
+
4
+ export const ADMIN_EDITOR_AUTH_KEY = "$$ADMIN_EDITOR_AUTH_KEY$$";
5
+
6
+ export const ADMIN_EDITOR_AUTH_QUERY = "key";
7
+ export const ADMIN_EDITOR_AUTH_COOKIE = ADMIN_EDITOR_AUTH_KEY;
8
+
9
+ export default {
10
+ authService: {
11
+ verify: async (args) => {
12
+
13
+ const adminInterface = (args.req as AdminRequest).editor;
14
+ const serverInterface = (args.req as any as ServerRequest).server;
15
+ const KEY = (adminInterface ? adminInterface.getCache() : serverInterface.cache).get<string>(ADMIN_EDITOR_AUTH_KEY);
16
+
17
+ const validSesson = {
18
+ username: "username",
19
+ account: "account",
20
+ groups: [],
21
+ token: args.token
22
+ };
23
+
24
+ const queryToken = args.req.query[ADMIN_EDITOR_AUTH_QUERY];
25
+ const cookieToken = args.req.cookies[ADMIN_EDITOR_AUTH_COOKIE];
26
+
27
+ //console.log("\n\nqueryToken[%s] cookieToken[%s] KEY[%s]\n\n", queryToken, cookieToken, KEY);
28
+
29
+ if (queryToken) {
30
+ if (queryToken === KEY) {
31
+ args.res.setCookie(ADMIN_EDITOR_AUTH_COOKIE, KEY, {
32
+ expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 31 * 12 * 500),
33
+ httpOnly: true,
34
+
35
+ //secure: true,
36
+ path: "/",
37
+ //sameSite: "strict"
38
+ });
39
+ args.req.searchParams.delete(ADMIN_EDITOR_AUTH_QUERY);
40
+ const queryString = args.req.searchParams.toString();
41
+ const redirect = args.req.path + (queryString ? "?" + queryString : "");
42
+ await args.res.redirect(redirect);
43
+ return validSesson;
44
+ }
45
+ } else if (cookieToken) {
46
+ return cookieToken === KEY ? validSesson : null;
47
+ }
48
+ return null;
49
+ },
50
+ }
51
+ } as AuthConfig;
@@ -0,0 +1,84 @@
1
+ import { RouterHandlerOptions } from "@miqro/core";
2
+ import { CacheInterface, ServerRequest } from "../../src/types.js";
3
+ import { MigrationModule } from "../../src/inflate/setup-db.js";
4
+
5
+ export interface EditorAdminInterface {
6
+ getCache: () => CacheInterface;
7
+ //inflateJSX: (path: string, minify?: boolean) => Promise<string>;
8
+ getMigrations(): MigrationModule[];
9
+ stop: () => Promise<void>;
10
+ reload: () => Promise<null | {
11
+ filePath: string;
12
+ error: Error;
13
+ }[]>;
14
+ restart: () => Promise<null | {
15
+ filePath: string;
16
+ error: Error;
17
+ }[]>;
18
+ getHotReloadHTML(): string;
19
+ getInflateErrors(): null | {
20
+ filePath: string;
21
+ error: Error;
22
+ }[];
23
+ getServices(): string[];
24
+ getRouteFileMap(): {
25
+ [filePath: string]: {
26
+ routes: {
27
+ path?: string;
28
+ method?: string | null;
29
+ options?: RouterHandlerOptions;
30
+ inflatePath?: string;
31
+ }[];
32
+ previewMethod: "api" | "html" | null;
33
+ }
34
+ };
35
+ }
36
+
37
+ export interface AdminRequest extends ServerRequest {
38
+ editor?: EditorAdminInterface;
39
+ }
40
+
41
+ /*let currentAdminInterface: EditorAdminInterface | null = null;
42
+ function createFakeAdminInterface(server: any): EditorAdminInterface {
43
+ return {
44
+ getCache: () => {
45
+ return server.cache;
46
+ },
47
+ stop: async () => {
48
+
49
+ },
50
+ restart: async () => {
51
+ return null;
52
+ },
53
+ reload: async () => {
54
+ return null;
55
+ },
56
+ getHotReloadHTML: () => {
57
+ return "";
58
+ },
59
+ getMigrations: () => {
60
+ return [];
61
+ },
62
+ getServices: () => {
63
+ return ["."];
64
+ },
65
+ getRouteFileMap: () => {
66
+ return {};
67
+ },
68
+ getInflateErrors: () => {
69
+ return [];
70
+ },
71
+ inflateJSX: async function inflateJSX(path, minify: boolean = true) {
72
+ return "";
73
+ }
74
+ }
75
+ }
76
+
77
+ export function getEditorAdmin(server): EditorAdminInterface {
78
+ return currentAdminInterface ? currentAdminInterface : createFakeAdminInterface(server);
79
+ }
80
+
81
+ export function setEditorAdmin(admin: EditorAdminInterface): void {
82
+ currentAdminInterface = admin;
83
+ }*/
84
+
@@ -0,0 +1,5 @@
1
+ import { resolve } from "node:path";
2
+ import { cwd } from "node:process";
3
+
4
+ export const PORT = process.env["PORT"] ? process.env["PORT"] : "8080";
5
+ export const BASE_PATH = resolve(cwd());
@@ -0,0 +1,21 @@
1
+ export const BASEEDITOR_PATH = "/admin/editor";
2
+ export const LOG_SOCKET_PATH = "/admin/socket";
3
+ export const LOG_WRITE_EVENT = "LogWrite";
4
+
5
+ export const SUPPORTED_LANGUAGES = [
6
+ "text",
7
+ "json",
8
+ "javascript",
9
+ "typescript",
10
+ "dockerfile",
11
+ "yaml",
12
+ "xml",
13
+ "html",
14
+ "css",
15
+ "scss",
16
+ "markdown",
17
+ "c",
18
+ "cpp",
19
+ "bash",
20
+ "python"
21
+ ];
@@ -0,0 +1,17 @@
1
+ import { scanDir } from "../http/admin/editor/api/fs/scan.api.js";
2
+ import { parseInflateErrors } from "../http/admin/editor/api/server/restart.api.js";
3
+ import { AdminRequest } from "./admin-interface.js";
4
+ import { HTMLEncode } from "./html-encode.js";
5
+
6
+ export function EditorIndex(editorCSS: string, editorJS: string, enableHotReload: boolean) {
7
+ return async function editorIndex(req: AdminRequest, res) {
8
+ const admin = req.editor;
9
+
10
+ const errors = parseInflateErrors(admin ? admin.getInflateErrors() : []);
11
+ const files = scanDir(req);
12
+ const migrations = admin ? admin.getMigrations().map(m => m.name) : [];
13
+ const services = admin ? admin.getServices() : ["."];
14
+ const hotReload = enableHotReload ? (admin ? admin.getHotReloadHTML() : "") : "";
15
+ res.html(`<!DOCTYPE html><html><body><style>${editorCSS}</style><script type="module">${editorJS}</script><editor-component class="main-container" reloadstring="${req.uuid}" migrations="${HTMLEncode(JSON.stringify(migrations))}" services="${HTMLEncode(JSON.stringify(services))}" errors="${HTMLEncode(JSON.stringify(errors))}" files="${HTMLEncode(JSON.stringify(files))}"><noscript>Enable JavaScript</noscript></editor-component>${hotReload}</body></html>`)
16
+ }
17
+ }
@@ -0,0 +1,14 @@
1
+ export function HTMLEncode(str: string): string {
2
+ let i = str.length;
3
+ const aRet: string[] = [];
4
+
5
+ while (i--) {
6
+ const iC = str[i].charCodeAt(0);
7
+ if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) {
8
+ aRet[i] = '&#' + iC + ';';
9
+ } else {
10
+ aRet[i] = str[i];
11
+ }
12
+ }
13
+ return aRet.join('');
14
+ }
@@ -0,0 +1,85 @@
1
+ interface LogLine { out: string; identifier: string; level: "error" | "warn" | "debug" | "trace" | "info" }
2
+
3
+ export interface LogSocket {
4
+ lines: LogLine[];
5
+ clearLog: () => void;
6
+ getMaxlogsize: () => number | "unlimited";
7
+ setMaxLogSize: (val: number | "unlimited") => void;
8
+ }
9
+
10
+ export function useLogSocket(options: { disableLog?: boolean; }): LogSocket {
11
+
12
+ const [_, setmaxLogSize, getMaxlogsize] = jsx.useState<number | "unlimited">(1000000);
13
+
14
+ const [__, setlines, getLines] = jsx.useState<LogLine[]>([]);
15
+ const refresh = jsx.useRefresh();
16
+
17
+ jsx.useEffect(() => {
18
+
19
+ let timeout;
20
+
21
+ function setupSocket() {
22
+ try {
23
+ if (options.disableLog) {
24
+ return;
25
+ }
26
+ console.log("setting up log socket");
27
+ const socket = new WebSocket("/admin/socket");
28
+ socket.addEventListener("error", (err) => {
29
+ console.error(err);
30
+ clearTimeout(timeout);
31
+ timeout = setTimeout(() => {
32
+ setupSocket();
33
+ }, 1000);
34
+ });
35
+ socket.addEventListener("open", () => {
36
+ console.log("log socket open");
37
+ clearTimeout(timeout);
38
+ socket.addEventListener("message", (msg) => {
39
+ const lines = getLines();
40
+ const data = JSON.parse(msg.data);
41
+ //console.log(data.out);
42
+ const maxLogSize = getMaxlogsize();
43
+ if (maxLogSize !== "unlimited" && lines.length >= maxLogSize) {
44
+ lines.splice(0, (lines.length - maxLogSize) + 1);
45
+ }
46
+ lines.push(data);
47
+ setlines(lines);
48
+ refresh();
49
+ });
50
+ });
51
+ socket.addEventListener("close", () => {
52
+ console.log("log socket close");
53
+ clearTimeout(timeout);
54
+ timeout = setTimeout(() => {
55
+ setupSocket();
56
+ }, 1000);
57
+ });
58
+ } catch (e) {
59
+ console.error(e);
60
+ clearTimeout(timeout);
61
+ timeout = setTimeout(() => {
62
+ setupSocket();
63
+ }, 1000);
64
+ }
65
+ }
66
+
67
+ setupSocket();
68
+ }, []);
69
+
70
+ return {
71
+ lines: getLines(),
72
+ clearLog: () => {
73
+ setlines([]);
74
+ },
75
+ getMaxlogsize,
76
+ setMaxLogSize: (newValue: number | "unlimited") => {
77
+ if (newValue === "unlimited") {
78
+ setmaxLogSize(newValue);
79
+ } else {
80
+ setmaxLogSize(newValue);
81
+ }
82
+
83
+ }
84
+ }
85
+ }