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,92 +0,0 @@
1
- import { ConsoleTransport, getEnvVariable, Logger, LoggerTransport, MinimalLogger, newURL, normalizePath, Request, WriteArgs } from "@miqro/core";
2
- import { format } from "node:util";
3
-
4
- const DEFAULT_ENV_NAME = "LOG_LEVEL";
5
-
6
- export interface LogProviderOptions {
7
- name?: string;
8
- transports: LoggerTransport[];
9
- formatter: (args: WriteArgs) => string;
10
- }
11
-
12
- export const DEFAULT_FORMATTER = ({ identifier, level, message, optionalParams }: WriteArgs) => format(`${new Date().toISOString()} PID[${process.pid}] ` +
13
- `${identifier ? `[${identifier}] ` : ""}` +
14
- `${level !== "info" ? (level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] `) : ""}` +
15
- `${message}`, ...optionalParams)
16
-
17
- export class LogProvider {
18
-
19
- public options: LogProviderOptions;
20
- public constructor(options?: LogProviderOptions) {
21
- this.options = {
22
- formatter: options && options.formatter ? options.formatter : DEFAULT_FORMATTER,
23
- transports: options && options.transports ? options.transports : [ConsoleTransport()],
24
- name: options?.name
25
- };
26
- this.requestLoggerFactory = this.requestLoggerFactory.bind(this);
27
- }
28
-
29
- public requestLoggerFactory(uuid: string, req: Request): MinimalLogger {
30
- let path = "";
31
- let query = "";
32
- let urlParsingError;
33
- let method = "GET";
34
- let remoteAddress: string | undefined = "";
35
- try {
36
- const url = newURL(req.url ? req.url : "/") as URL;
37
- query = url.searchParams.toString();
38
- path = normalizePath(url.pathname); // normalized path
39
- method = req.method ? req.method.toUpperCase() as string : "GET";
40
- remoteAddress = req.socket.remoteAddress;
41
- } catch (e) {
42
- urlParsingError = e;
43
- }
44
- const pathToEnv = path.replace(/\//ig, "_").replace(/\./ig, "_").replace(/-/ig, "_").toUpperCase();
45
- const WORKER_IDENTIFIER = process.env["CLUSTER_NODE_NUMBER"] ? `WORKER_${process.env["CLUSTER_NODE_NUMBER"]}_` : "";
46
- const identifier = `${pathToEnv === "_" ? "" : `${pathToEnv.substring(1)}`}${pathToEnv.charAt(pathToEnv.length - 1) !== "_" ? "_" : ""}${method.toUpperCase()}`;
47
- const upgrade = req.headers.connection?.indexOf("Upgrade") !== -1;
48
-
49
- const logger = this.getLogger(
50
- `${WORKER_IDENTIFIER}${identifier}`, {
51
- formatter: (args: WriteArgs) => {
52
- args.message = `%s${upgrade ? " UPGRADE" : ""} %s%s [%s] (%s) ${args.message}`;
53
- args.optionalParams = [method, path, query ? `?${query}` : "", uuid, remoteAddress].concat(args.optionalParams);
54
- args.meta.push(req);
55
- args.meta.push(uuid);
56
- return this.options.formatter(args);
57
- }
58
- });
59
-
60
-
61
- if (urlParsingError) {
62
- logger.error(urlParsingError);
63
- }
64
-
65
- return logger;
66
- };
67
-
68
- public getLogger(identifier: string, options?: { level?: any; transports?: any[]; formatter?: any; }): Logger {
69
-
70
- identifier = this.options.name ?
71
- `${this.options.name}${identifier ?
72
- `_${identifier}` : ""}`.toUpperCase() :
73
- identifier ? identifier.toUpperCase() : "";
74
-
75
- const envVarName = `LOG_LEVEL_${identifier}`;
76
- const level = options && options.level ? options.level : getEnvVariable(envVarName) ? getEnvVariable(envVarName) : getEnvVariable(DEFAULT_ENV_NAME, "info");
77
-
78
- const logger = new Logger(identifier, level, {
79
- transports: [],
80
- formatter: options && options.formatter ? options.formatter : this.options.formatter
81
- });
82
- for (const t of this.options.transports) {
83
- logger.addTransport(t);
84
- }
85
- if (options && options.transports) {
86
- for (const t of options.transports) {
87
- logger.addTransport(t);
88
- }
89
- }
90
- return logger;
91
- }
92
- }
@@ -1,92 +0,0 @@
1
- import { WebSocketServer, Logger } from "@miqro/core";
2
- import { Database } from "@miqro/query";
3
- import cluster from "node:cluster";
4
- import { CacheInterface, MigrateOptions, NamedMigration, ServerInterface } from "../../types.js";
5
- import { DBManager } from "./db-manager.js";
6
- import { Miqro } from "../app.js";
7
- import { WebSocketManager } from "./websocketmanager.js";
8
- import { execSync } from "node:child_process";
9
- import { LogProvider } from "./log.js";
10
- import { initGlobals } from "../globals.js";
11
-
12
- export interface ServerInterfaceImplOptions {
13
- cache: CacheInterface;
14
- localCache: CacheInterface;
15
- dbManager: DBManager;
16
- webSocketManager: WebSocketManager;
17
- logger?: Logger;
18
- app?: Miqro;
19
- port?: string;
20
- loggerProvider?: LogProvider;
21
- }
22
-
23
- export function createServerInterface(options: ServerInterfaceImplOptions): ServerInterface {
24
- initGlobals();
25
- return Object.freeze<ServerInterface>({
26
- cache: options.cache,
27
- localCache: options.localCache,
28
- logger: options.logger,
29
- reload() {
30
- return options?.app?.reload();
31
- },
32
- restart() {
33
- return options?.app?.restart();
34
- },
35
- stop() {
36
- return options?.app?.stop();
37
- },
38
- db: {
39
- get(name) {
40
- return options.dbManager.getDB(name);
41
- },
42
- getMigrations() {
43
- if (options.app?.inflated) {
44
- const ret: NamedMigration[] = [];
45
- for (const d of options.app?.inflated.dbList) {
46
- ret.push(...(d.migrations.map(m => {
47
- return {
48
- name: m.name,
49
- service: m.service,
50
- dbName: m.dbName
51
- }
52
- })));
53
- }
54
- return ret;
55
- }
56
- return [];
57
- },
58
- migrate(migrateOptions) {
59
- return options?.app?.migrate(migrateOptions);
60
- },
61
- },
62
- ws: {
63
- get: (name: string) => {
64
- return options?.webSocketManager?.getWS(name);
65
- },
66
- disconnectAll: (path: string) => {
67
- return options?.webSocketManager?.disconnectAllButLOGSocket();
68
- }
69
- },
70
- openBrowser(path) {
71
- const PORT = options.port;
72
- const URL = `http://localhost${PORT ? `:${PORT}` : ""}${path}`;
73
- const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
74
- const OPEN = options?.app?.options.browser !== undefined && String(options?.app?.options.browser).toUpperCase() !== "TRUE" && String(options?.app?.options.browser).toUpperCase() !== "1" ?
75
- String(options?.app.options.browser).toUpperCase() !== "0" && String(options?.app?.options.browser).toUpperCase() !== "FALSE" && String(options?.app?.options.browser).toUpperCase() !== "NONE" && options?.app?.options.browser ?
76
- options?.app.options.browser : false :
77
- process.env["BROWSER"] ?
78
- process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
79
- if (OPEN) {
80
- const openCMD = `${OPEN} "${URL}"`;
81
- options?.logger?.info("opening browser with [%s]", openCMD);
82
- execSync(openCMD);
83
- } else {
84
- options?.logger?.warn("ignoring browser [%s]", OPEN);
85
- }
86
- },
87
- getLogger(identifier, loggerOptions) {
88
- return options?.loggerProvider?.getLogger(identifier, loggerOptions);
89
- },
90
- ...server
91
- });
92
- }
@@ -1,157 +0,0 @@
1
- import { Logger } from "@miqro/core";
2
- import { LOG_SOCKET_PATH } from "../../../editor/common/constants.js";
3
- import { ClusterWebSocketServer2 } from "./cluster-ws.js";
4
- import { WSConfig } from "../../types.js";
5
- import { LogProvider } from "./log.js";
6
-
7
- export interface WebSocketManagerOptions {
8
- logger?: Logger | Console;
9
- loggerProvider?: LogProvider;
10
- name?: string;
11
- avoidLogSocket?: boolean;
12
- }
13
-
14
- export class WebSocketManager {
15
- public runningGlobalWSMap = new Map<string, ClusterWebSocketServer2>();
16
- public logger?: Logger | Console | null = null;
17
- public name: string;
18
- public avoidLogSocket: boolean;
19
- public loggerProvider: LogProvider;
20
- constructor(options?: WebSocketManagerOptions) {
21
- this.onUpgrade = this.onUpgrade.bind(this);
22
- this.logger = options && options.logger ? options.logger : null;
23
- this.name = options && options.name ? options.name : "WebSocketManager";
24
- this.loggerProvider = options && options.loggerProvider;
25
- this.avoidLogSocket = options && options.avoidLogSocket ? options.avoidLogSocket : false;
26
- }
27
-
28
- public deleteWS(path: string) {
29
- const ws = this.runningGlobalWSMap.get(path);
30
- this.disconnectAllFrom(path);
31
- ws.dispose();
32
- this.runningGlobalWSMap.delete(path);
33
- }
34
-
35
- public deleteAllWS() {
36
- for (const path of this.runningGlobalWSMap.keys()) {
37
- this.deleteWS(path);
38
- }
39
- }
40
-
41
- public getWS(path: string): ClusterWebSocketServer2 | undefined {
42
- return this.runningGlobalWSMap.get(path);
43
- }
44
-
45
- public replaceALLWS(list: WSConfig[]) {
46
- this.deleteAllWS();
47
- for (const wsConfig of list) {
48
- if (!wsConfig.disabled) {
49
- if (this.runningGlobalWSMap.has(wsConfig.path)) {
50
- throw new Error(`ws on path ${wsConfig.path} already setup!`);
51
- }
52
- this.logger?.debug("setting up websocket on [%s]", wsConfig.path);
53
- const identifier = wsConfig.path.replaceAll("/", "_").toUpperCase();
54
- const logger = this.loggerProvider && identifier.length >= 0 ? this.loggerProvider.getLogger(identifier.substring(identifier.charAt(0) === "_" ? 1 : 0)) : this.logger;
55
- const server = new ClusterWebSocketServer2(this.name + wsConfig.path, wsConfig.path, logger, wsConfig);
56
- this.runningGlobalWSMap.set(wsConfig.path, server);
57
- }
58
- }
59
- }
60
-
61
- public replaceALLWSBuLOGSocket(list: WSConfig[]) {
62
- for (const path of this.runningGlobalWSMap.keys()) {
63
- if (path !== LOG_SOCKET_PATH || !this.avoidLogSocket) {
64
- this.deleteWS(path);
65
- }
66
- }
67
- for (const wsConfig of list) {
68
- if (!wsConfig.disabled) {
69
- if (wsConfig.path !== LOG_SOCKET_PATH || !this.avoidLogSocket) {
70
- if (this.runningGlobalWSMap.has(wsConfig.path)) {
71
- throw new Error(`ws on path ${wsConfig.path} already setup!`);
72
- }
73
- this.logger?.debug("setting up websocket on [%s]", wsConfig.path);
74
- const identifier = wsConfig.path.replaceAll("/", "_").toUpperCase();
75
- const logger = this.loggerProvider && identifier.length >= 0 ? this.loggerProvider.getLogger(identifier.substring(identifier.charAt(0) === "_" ? 1 : 0)) : this.logger;
76
- const server = new ClusterWebSocketServer2(this.name + wsConfig.path, wsConfig.path, logger, wsConfig);
77
- this.runningGlobalWSMap.set(wsConfig.path, server);
78
- }
79
- }
80
- }
81
- }
82
-
83
- /*public setupWS(path: string, server: ClusterWebSocketServer2) {
84
- if (this.runningGlobalWSMap.has(path)) {
85
- throw new Error(`ws on path ${path} already setup!`);
86
- }
87
- this.runningGlobalWSMap.set(path, server);
88
- }*/
89
-
90
- public disconnectAllFrom(path: string) {
91
- try {
92
- this.logger?.debug("disconnect all from [%s]", path);
93
- const ws = this.getWS(path);
94
- if (ws) {
95
- const clients = ws.clients.values();
96
- if (clients) {
97
- for (const client of clients) {
98
- try {
99
- client.socket.destroy();
100
- } catch (e2) {
101
- this.logger?.error("error disconnecting web socket client");
102
- this.logger?.error(e2);
103
- }
104
- }
105
- }
106
- //ws.dispose();
107
- }
108
- } catch (e) {
109
- this.logger?.error("error disconnecting web socket clients");
110
- this.logger?.error(e.message);
111
- }
112
- }
113
-
114
- public disconnectAllButLOGSocket() {
115
- try {
116
- for (const wsPath of this.runningGlobalWSMap.keys()) {
117
- if (wsPath !== LOG_SOCKET_PATH || !this.avoidLogSocket) {
118
- this.disconnectAllFrom(wsPath);
119
- }
120
- }
121
- } catch (e) {
122
- this.logger?.error("error disconnecting web socket clients");
123
- this.logger?.error(e.message);
124
- }
125
- }
126
-
127
- public disconnectAll() {
128
- try {
129
- for (const wsPath of this.runningGlobalWSMap.keys()) {
130
- this.disconnectAllFrom(wsPath);
131
- }
132
- } catch (e) {
133
- this.logger?.error("error disconnecting web socket clients");
134
- this.logger?.error(e.message);
135
- }
136
- }
137
-
138
- public onUpgrade(req, socket, head) {
139
- try {
140
- const wsServer = this.getWS(req.path);
141
- if (wsServer) {
142
- return wsServer.onUpgrade(req, socket, head);
143
- } else {
144
- socket.destroy();
145
- }
146
- } catch (e) {
147
- this.logger?.error(e);
148
- }
149
- }
150
- }
151
-
152
- /*export interface WSMapConfig {
153
- [path: string]: {
154
- name: string;
155
- options: WSConfig;
156
- } | undefined;
157
- }*/
@@ -1 +0,0 @@
1
- import "../globals.js";
@@ -1,2 +0,0 @@
1
- import "../globals.js";
2
- export * from "@miqro/core/lib.js";
@@ -1,2 +0,0 @@
1
- import "../globals.js";
2
- export * from "@miqro/jsx/esm/lib.js";
@@ -1,2 +0,0 @@
1
- import "../globals.js";
2
- export * from "@miqro/parser/lib.js";
@@ -1,2 +0,0 @@
1
- import "../globals.js";
2
- export * from "@miqro/query/lib.js";
@@ -1,2 +0,0 @@
1
- import "../globals.js";
2
- export * from "@miqro/request/lib.js";
@@ -1,2 +0,0 @@
1
- import "../globals.js";
2
- export * from "@miqro/test/dist/index.js";
@@ -1 +0,0 @@
1
- import "../globals.js";
@@ -1 +0,0 @@
1
- import "../globals.js";
@@ -1 +0,0 @@
1
- import "./jsx.globals.js";
@@ -1,2 +0,0 @@
1
- import "../globals.js";
2
- export * from "cookie/index.js";
@@ -1,2 +0,0 @@
1
- import "./browser.globals.js";
2
- import "./server.globals.js";
@@ -1,2 +0,0 @@
1
- import "../globals.js";
2
- export * from "jose/types/index.js";
@@ -1,38 +0,0 @@
1
- import * as jsxLib from "@miqro/jsx/esm/lib.js";
2
-
3
- declare global {
4
- // jsx only for the default value of tsconfig.json
5
- var React: {};
6
- var jsx: {
7
- define: (tagName: string, component: jsxLib.Component, options?: jsxLib.RuntimeElementDefinitionOptions) => void;
8
- useRuntime: typeof jsxLib.useRuntime;
9
- usePathname: typeof jsxLib.usePathname;
10
- Link: typeof jsxLib.Link;
11
- Router: typeof jsxLib.Router;
12
- createContext: typeof jsxLib.createContext;
13
- useContext: typeof jsxLib.useContext;
14
- useState: typeof jsxLib.useState;
15
- useEffect: typeof jsxLib.useEffect;
16
- useQuery: typeof jsxLib.useQuery;
17
- useRef: typeof jsxLib.useRef;
18
- useElement: typeof jsxLib.useElement;
19
- useRefresh: typeof jsxLib.useRefresh;
20
- }
21
- /*var useRuntime: typeof jsxLib.useRuntime;
22
- var usePathname: typeof jsxLib.usePathname;
23
- var Link: typeof jsxLib.Link;
24
- var Router: typeof jsxLib.Router;
25
- var createContext: typeof jsxLib.createContext;
26
- var useContext: typeof jsxLib.useContext;
27
- var useState: typeof jsxLib.useState;
28
- var useEffect: typeof jsxLib.useEffect;
29
- var useQuery: typeof jsxLib.useQuery;
30
- var useRef: typeof jsxLib.useRef;
31
- var useElement: typeof jsxLib.useElement;
32
- var useRefresh: typeof jsxLib.useRefresh;*/
33
- var JSX: {
34
- createElement: typeof jsxLib.createElement;
35
- Fragment: typeof jsxLib.Fragment;
36
- enableDebugLog: typeof jsxLib.enableDebugLog;
37
- }
38
- }
@@ -1,228 +0,0 @@
1
- import "./globals.js";
2
- import { Database, Migration } from "@miqro/query/lib.js";
3
- import { ReadBuffer, URLEncodedParser, JSONParser, TextParser, CORS, SessionHandler } from "@miqro/core/lib.js";
4
- import { ErrorHandler, HandlerWithOptions, CORSOptions, LogLevel, LoggerTransportWriteArgs, Request, Response, WebSocketServer, Logger, WebSocketServerOptions, SessionHandlerOptions, RouteOptions, Handler } from "@miqro/core/lib.js";
5
- import { Parser, ParserInterface } from "@miqro/parser/lib.js";
6
- import { ProtectedHeaderParameters, EncryptOptions, SignOptions, JWTPayload, JWTDecryptOptions, JWTDecryptResult, JWTVerifyResult, JWTVerifyOptions } from "jose/types/index.js";
7
- import { KeyObject } from "node:crypto";
8
-
9
- /*export * from "@miqro/core/lib.js";
10
- export * from "@miqro/query/lib.js";*/
11
-
12
- export interface AuthConfig extends SessionHandlerOptions {
13
-
14
- }
15
-
16
- export interface EncryptJWTOptions {
17
- alg?: string;
18
- enc?: string;
19
- iat?: number | string | Date;
20
- iss?: string;
21
- aud?: string;
22
- exp?: number | string | Date;
23
- options?: EncryptOptions;
24
- }
25
-
26
- export interface JWTSignOptions {
27
- alg?: string;
28
- iat?: number | string | Date;
29
- iss?: string;
30
- aud?: string;
31
- exp?: number | string | Date;
32
- options?: SignOptions;
33
- }
34
-
35
- export interface ServerGlobal {
36
- encodeHTML: (str: string) => string;
37
- inflateMDtoHTML: (str: string) => string;
38
- middleware: {
39
- buffer: typeof ReadBuffer;
40
- url: typeof URLEncodedParser;
41
- json: typeof JSONParser;
42
- text: typeof TextParser;
43
- cors: typeof CORS;
44
- session: typeof SessionHandler;
45
- };
46
- newParser(): Parser;
47
- newClusterCache: (name: string, logger?: Logger) => CacheInterface;
48
- newLocalCache: (name: string, logger?: Logger) => CacheInterface;
49
- createSecretKey: (key: string, encoding: BufferEncoding) => KeyObject;
50
- getWorkerCount: () => number;
51
- getWorkerNumber: () => number;
52
- isPrimaryWorker: () => boolean;
53
- jwt: {
54
- /**
55
- * creates a JWT encrypted token with jose
56
- *
57
- * @param payload the payload to encrypt
58
- * @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
59
- * @param options options like expiratation date, issuer and audience
60
- * @returns
61
- */
62
- encrypt: (payload: JWTPayload, secret: KeyObject, options?: Partial<EncryptJWTOptions>) => Promise<string>
63
- /**
64
- * decrypts a JWT token with jose
65
- * @param jwt the JWT token
66
- * @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
67
- * @param options options like issuer and audience
68
- * @returns
69
- */
70
- decrypt: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTDecryptOptions>) => Promise<JWTDecryptResult<PayloadType>>;
71
- /**
72
- * verify a JWT token with jose
73
- * @param jwt the JWT token
74
- * @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
75
- * @param options options like issuer and audience
76
- * @returns
77
- */
78
- verify: <PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTVerifyOptions>) => Promise<JWTVerifyResult<PayloadType>>;
79
- /**
80
- * creates a signed JWT with jose
81
- *
82
- * @param payload the payload to encrypt
83
- * @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
84
- * @param options options like expiratation date, issuer and audience
85
- * @returns
86
- */
87
- sign: (payload: JWTPayload, secret: KeyObject, options?: Partial<JWTSignOptions>) => Promise<string>;
88
- /**
89
- * decodes a protected header with jose
90
- * @param token
91
- * @returns
92
- */
93
- decodeProtectedHeader: (token: string | object) => ProtectedHeaderParameters;
94
- /**
95
- * decodes a jwt token
96
- * @param jwt
97
- * @returns
98
- */
99
- decode: <PayloadType = JWTPayload>(jwt: string) => PayloadType & JWTPayload;
100
- }
101
- }
102
-
103
- export interface MiddlewareConfig {
104
- middleware?: Array<HandlerWithOptions | Handler>;
105
- post?: Array<HandlerWithOptions | Handler>;
106
- }
107
-
108
- export interface CORSConfig extends CORSOptions {
109
-
110
- }
111
-
112
- export interface ErrorConfig {
113
- catch?: Array<ErrorHandler>;
114
- }
115
-
116
- export interface WSConfig extends WebSocketServerOptions {
117
- path: string;
118
- disabled?: boolean;
119
- }
120
-
121
- export interface DocConfig {
122
- publish: {
123
- [path: string]: {
124
- type?: "HTML" | "MD" | "JSON",
125
- all?: boolean;
126
- }
127
- }
128
- }
129
-
130
- export interface ServerConfig {
131
- start?: (server: ServerInterface) => Promise<void> | void;
132
- preload?: (server: ServerInterface) => Promise<void> | void;
133
- load?: (server: ServerInterface) => Promise<void> | void;
134
- unload?: (server: ServerInterface) => void;
135
- stop?: (server: ServerInterface) => void;
136
- }
137
-
138
- export interface DBConfig {
139
- dialect?: string;
140
- storage?: string;
141
- url?: string;
142
- disabled?: boolean;
143
- name: string;
144
- }
145
-
146
- export interface CacheInterface {
147
- get<T = any>(key: string): T | undefined;
148
- set: (key: string, value: unknown) => void;
149
- unset: (key: string) => void;
150
- has: (key: string) => boolean;
151
-
152
- set_add: (key: string, value: unknown) => void;
153
- set_delete: (key: string, value: unknown) => void;
154
- set_has: (key: string, value: unknown) => boolean;
155
- set_clear: (key: string) => void;
156
-
157
- array_push: (key: string, value: unknown) => void;
158
- array_clear: (key: string) => void;
159
- }
160
-
161
- export interface APIOptions extends Partial<RouteOptions> {
162
- basePath?: string;
163
- path?: string | string[];
164
- method?: string | string[];
165
- parser?: ParserInterface;
166
- middleware?: Handler | Handler[];
167
- session?: SessionHandlerOptions | Handler;
168
- }
169
-
170
- export interface NamedMigration {
171
- name: string;
172
- service: string;
173
- dbName: string;
174
- }
175
-
176
- export interface LogConfig {
177
- level?: LogLevel;
178
- replaceConsoleTransport?: boolean;
179
- replaceFileTransport?: boolean;
180
- write: (args: LoggerTransportWriteArgs) => Promise<void> | void;
181
- }
182
-
183
- export interface MigrateOptions {
184
- direction: "up" | "down";
185
- service?: string;
186
- dbName?: string;
187
- name?: string;
188
- }
189
-
190
- export interface ServerInterface extends ServerGlobal{
191
- // null values are if the feature has been disabled
192
- db: {
193
- get(name: string): Database | null;
194
- getMigrations(): NamedMigration[];
195
- migrate(options?: MigrateOptions): Promise<void>;
196
- },
197
- ws: {
198
- get(path: string): WebSocketServer | undefined;
199
- disconnectAll(path: string): void;
200
- };
201
- cache: CacheInterface;
202
- localCache: CacheInterface;
203
- logger: Logger;
204
- isPrimaryWorker: () => boolean;
205
- getWorkerNumber: () => number;
206
- getWorkerCount: () => number;
207
- openBrowser: (path: string) => void;
208
- getLogger: (identifier: string, options?: { level?: any; transports?: any[]; formatter?: any; }) => Logger;
209
- stop: () => Promise<void>;
210
- reload: () => Promise<null | {
211
- filePath: string;
212
- error: Error;
213
- }[]>;
214
- restart: () => Promise<null | {
215
- filePath: string;
216
- error: Error;
217
- }[]>;
218
- }
219
-
220
- export interface ServerRequest extends Request {
221
- server?: ServerInterface;
222
- }
223
-
224
- export interface ServerResponse extends Response {
225
- }
226
-
227
- export { App, LoggerHandler, Router, APIRoute } from "@miqro/core/lib.js";
228
- export { migration, Migration } from "@miqro/query/lib.js";
@@ -1 +0,0 @@
1
- import "../globals.js";