miqro 7.2.6 → 7.2.8
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.
- package/README.md +1 -21
- package/build/esm/editor/auth.js +0 -1
- package/build/esm/editor/common/constants.js +0 -1
- package/build/esm/editor/common/constants.server.js +0 -1
- package/build/esm/editor/common/editor-index.d.ts +1 -1
- package/build/esm/editor/common/editor-index.js +0 -1
- package/build/esm/editor/common/html-encode.js +0 -1
- package/build/esm/editor/common/log-socket.js +0 -1
- package/build/esm/editor/common/templates.js +0 -1
- package/build/esm/editor/components/api-preview.js +0 -1
- package/build/esm/editor/components/editor.js +0 -1
- package/build/esm/editor/components/file-browser.js +0 -1
- package/build/esm/editor/components/file-editor-toolbar.js +0 -1
- package/build/esm/editor/components/file-editor.js +0 -1
- package/build/esm/editor/components/filter-query.js +0 -1
- package/build/esm/editor/components/highlight-text-area.js +0 -1
- package/build/esm/editor/components/log-viewer.js +0 -1
- package/build/esm/editor/components/new-file.js +0 -1
- package/build/esm/editor/components/scroll-query.js +0 -1
- package/build/esm/editor/components/start-page.js +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +1 -1
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js +0 -1
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js +0 -1
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js +0 -1
- package/build/esm/editor/http/admin/editor/editor.js +0 -1
- package/build/esm/editor/http/admin/editor/index.api.js +2 -2
- package/build/esm/editor/server.js +0 -1
- package/build/esm/editor/ws.js +3 -3
- package/build/esm/src/bin/compile.js +0 -1
- package/build/esm/src/bin/doc-md.js +0 -1
- package/build/esm/src/bin/generate-doc.js +0 -1
- package/build/esm/src/bin/test.js +0 -1
- package/build/esm/src/bin/types.js +0 -1
- package/build/esm/src/cluster.js +0 -1
- package/build/esm/{editor → src}/common/admin-interface.d.ts +2 -2
- package/build/esm/{editor → src}/common/admin-interface.js +0 -1
- package/build/esm/src/common/arguments.js +0 -1
- package/build/esm/src/common/assets.js +2 -3
- package/build/esm/src/common/checksum.js +0 -1
- package/build/esm/src/common/constants.js +0 -1
- package/build/esm/src/common/content-type.js +0 -1
- package/build/esm/src/common/esbuild.js +0 -1
- package/build/esm/src/common/exit.js +0 -1
- package/build/esm/src/common/fs.js +0 -1
- package/build/esm/src/common/help.js +0 -1
- package/build/esm/src/common/jsx.js +0 -1
- package/build/esm/src/common/jwt.js +0 -1
- package/build/esm/src/common/paths.js +0 -1
- package/build/esm/src/common/watch.js +0 -1
- package/build/esm/src/inflate/inflate-sea.js +0 -1
- package/build/esm/src/inflate/inflate.js +0 -1
- package/build/esm/src/inflate/md.js +0 -1
- package/build/esm/src/inflate/setup-auth.js +0 -1
- package/build/esm/src/inflate/setup-cors.js +0 -1
- package/build/esm/src/inflate/setup-db.js +0 -1
- package/build/esm/src/inflate/setup-error.js +0 -1
- package/build/esm/src/inflate/setup-http.js +0 -1
- package/build/esm/src/inflate/setup-log.js +0 -1
- package/build/esm/src/inflate/setup-middleware.js +0 -1
- package/build/esm/src/inflate/setup-server-config.js +0 -1
- package/build/esm/src/inflate/setup-test.js +0 -1
- package/build/esm/src/inflate/setup-ws.js +0 -1
- package/build/esm/src/inflate/setup.doc.js +0 -1
- package/build/esm/src/inflate/utils/sea-utils.js +0 -1
- package/build/esm/src/lib.js +0 -1
- package/build/esm/src/main.js +0 -1
- package/build/esm/src/services/app.d.ts +1 -1
- package/build/esm/src/services/app.js +1 -1
- package/build/esm/src/services/editor.d.ts +1 -1
- package/build/esm/src/services/editor.js +10 -12
- package/build/esm/src/services/hot-reload.js +0 -1
- package/build/esm/src/services/migrations.js +0 -1
- package/build/esm/src/services/utils/admin-interface.d.ts +1 -1
- package/build/esm/src/services/utils/admin-interface.js +0 -1
- package/build/esm/src/services/utils/cache.js +0 -1
- package/build/esm/src/services/utils/cluster-cache.js +0 -1
- package/build/esm/src/services/utils/cluster-ws.js +0 -1
- package/build/esm/src/services/utils/db-manager.js +0 -1
- package/build/esm/src/services/utils/get-route.js +0 -1
- package/build/esm/src/services/utils/jwt.js +0 -1
- package/build/esm/src/services/utils/log-transport.js +0 -1
- package/build/esm/src/services/utils/log.js +0 -1
- package/build/esm/src/services/utils/middleware.js +0 -1
- package/build/esm/src/services/utils/server-interface.js +0 -1
- package/build/esm/src/services/utils/websocketmanager.d.ts +2 -0
- package/build/esm/src/services/utils/websocketmanager.js +8 -2
- package/build/esm/src/types.js +0 -1
- package/build/lib.cjs +27 -29
- package/build/style.css +3 -3
- package/editor/auth.ts +1 -1
- package/editor/common/editor-index.tsx +1 -1
- package/editor/http/admin/editor/api/fs/scan.api.tsx +1 -1
- package/editor/http/admin/editor/api/server/reload.api.ts +1 -1
- package/editor/http/admin/editor/api/server/restart.api.tsx +1 -1
- package/editor/http/admin/editor/index.api.tsx +3 -2
- package/editor/server.ts +1 -1
- package/editor/ws.ts +5 -3
- package/package.json +2 -2
- package/build/esm/editor/auth.js.map +0 -1
- package/build/esm/editor/common/admin-interface.js.map +0 -1
- package/build/esm/editor/common/constants.js.map +0 -1
- package/build/esm/editor/common/constants.server.js.map +0 -1
- package/build/esm/editor/common/editor-index.js.map +0 -1
- package/build/esm/editor/common/html-encode.js.map +0 -1
- package/build/esm/editor/common/log-socket.js.map +0 -1
- package/build/esm/editor/common/templates.js.map +0 -1
- package/build/esm/editor/components/api-preview.js.map +0 -1
- package/build/esm/editor/components/editor.js.map +0 -1
- package/build/esm/editor/components/file-browser.js.map +0 -1
- package/build/esm/editor/components/file-editor-toolbar.js.map +0 -1
- package/build/esm/editor/components/file-editor.js.map +0 -1
- package/build/esm/editor/components/filter-query.js.map +0 -1
- package/build/esm/editor/components/highlight-text-area.js.map +0 -1
- package/build/esm/editor/components/log-viewer.js.map +0 -1
- package/build/esm/editor/components/new-file.js.map +0 -1
- package/build/esm/editor/components/scroll-query.js.map +0 -1
- package/build/esm/editor/components/start-page.js.map +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js.map +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js.map +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js.map +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js.map +0 -1
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js.map +0 -1
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js.map +0 -1
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js.map +0 -1
- package/build/esm/editor/http/admin/editor/editor.js.map +0 -1
- package/build/esm/editor/http/admin/editor/index.api.js.map +0 -1
- package/build/esm/editor/server.js.map +0 -1
- package/build/esm/editor/ws.js.map +0 -1
- package/build/esm/src/bin/compile.js.map +0 -1
- package/build/esm/src/bin/doc-md.js.map +0 -1
- package/build/esm/src/bin/generate-doc.js.map +0 -1
- package/build/esm/src/bin/test.js.map +0 -1
- package/build/esm/src/bin/types.js.map +0 -1
- package/build/esm/src/cluster.js.map +0 -1
- package/build/esm/src/common/arguments.js.map +0 -1
- package/build/esm/src/common/assets.js.map +0 -1
- package/build/esm/src/common/checksum.js.map +0 -1
- package/build/esm/src/common/constants.js.map +0 -1
- package/build/esm/src/common/content-type.js.map +0 -1
- package/build/esm/src/common/esbuild.js.map +0 -1
- package/build/esm/src/common/exit.js.map +0 -1
- package/build/esm/src/common/fs.js.map +0 -1
- package/build/esm/src/common/help.js.map +0 -1
- package/build/esm/src/common/jsx.js.map +0 -1
- package/build/esm/src/common/jwt.js.map +0 -1
- package/build/esm/src/common/paths.js.map +0 -1
- package/build/esm/src/common/watch.js.map +0 -1
- package/build/esm/src/inflate/inflate-sea.js.map +0 -1
- package/build/esm/src/inflate/inflate.js.map +0 -1
- package/build/esm/src/inflate/md.js.map +0 -1
- package/build/esm/src/inflate/setup-auth.js.map +0 -1
- package/build/esm/src/inflate/setup-cors.js.map +0 -1
- package/build/esm/src/inflate/setup-db.js.map +0 -1
- package/build/esm/src/inflate/setup-error.js.map +0 -1
- package/build/esm/src/inflate/setup-http.js.map +0 -1
- package/build/esm/src/inflate/setup-log.js.map +0 -1
- package/build/esm/src/inflate/setup-middleware.js.map +0 -1
- package/build/esm/src/inflate/setup-server-config.js.map +0 -1
- package/build/esm/src/inflate/setup-test.js.map +0 -1
- package/build/esm/src/inflate/setup-ws.js.map +0 -1
- package/build/esm/src/inflate/setup.doc.js.map +0 -1
- package/build/esm/src/inflate/utils/sea-utils.js.map +0 -1
- package/build/esm/src/lib.js.map +0 -1
- package/build/esm/src/main.js.map +0 -1
- package/build/esm/src/services/app.js.map +0 -1
- package/build/esm/src/services/editor.js.map +0 -1
- package/build/esm/src/services/hot-reload.js.map +0 -1
- package/build/esm/src/services/migrations.js.map +0 -1
- package/build/esm/src/services/utils/admin-interface.js.map +0 -1
- package/build/esm/src/services/utils/cache.js.map +0 -1
- package/build/esm/src/services/utils/cluster-cache.js.map +0 -1
- package/build/esm/src/services/utils/cluster-ws.js.map +0 -1
- package/build/esm/src/services/utils/db-manager.js.map +0 -1
- package/build/esm/src/services/utils/get-route.js.map +0 -1
- package/build/esm/src/services/utils/jwt.js.map +0 -1
- package/build/esm/src/services/utils/log-transport.js.map +0 -1
- package/build/esm/src/services/utils/log.js.map +0 -1
- package/build/esm/src/services/utils/middleware.js.map +0 -1
- package/build/esm/src/services/utils/server-interface.js.map +0 -1
- package/build/esm/src/services/utils/websocketmanager.js.map +0 -1
- package/build/esm/src/types.js.map +0 -1
- package/build/font.ttf +0 -0
- package/editor/common/admin-interface.ts +0 -84
- package/src/bin/compile.ts +0 -35
- package/src/bin/doc-md.ts +0 -210
- package/src/bin/generate-doc.ts +0 -64
- package/src/bin/test.ts +0 -93
- package/src/bin/types.ts +0 -34
- package/src/cluster.ts +0 -27
- package/src/common/arguments.ts +0 -853
- package/src/common/assets.ts +0 -148
- package/src/common/checksum.ts +0 -58
- package/src/common/constants.ts +0 -19
- package/src/common/content-type.ts +0 -84
- package/src/common/esbuild.ts +0 -103
- package/src/common/exit.ts +0 -91
- package/src/common/fs.ts +0 -82
- package/src/common/help.ts +0 -65
- package/src/common/jsx.ts +0 -574
- package/src/common/jwt.ts +0 -85
- package/src/common/paths.ts +0 -107
- package/src/common/watch.ts +0 -88
- package/src/inflate/inflate-sea.ts +0 -268
- package/src/inflate/inflate.ts +0 -105
- package/src/inflate/md.ts +0 -25
- package/src/inflate/setup-auth.ts +0 -41
- package/src/inflate/setup-cors.ts +0 -42
- package/src/inflate/setup-db.ts +0 -117
- package/src/inflate/setup-error.ts +0 -44
- package/src/inflate/setup-http.ts +0 -720
- package/src/inflate/setup-log.ts +0 -45
- package/src/inflate/setup-middleware.ts +0 -47
- package/src/inflate/setup-server-config.ts +0 -48
- package/src/inflate/setup-test.ts +0 -23
- package/src/inflate/setup-ws.ts +0 -50
- package/src/inflate/setup.doc.ts +0 -92
- package/src/inflate/utils/sea-utils.ts +0 -14
- package/src/lib.ts +0 -35
- package/src/main.ts +0 -107
- package/src/services/app.ts +0 -750
- package/src/services/editor.tsx +0 -101
- package/src/services/globals.ts.ignore +0 -186
- package/src/services/hot-reload.ts +0 -55
- package/src/services/migrations.ts +0 -68
- package/src/services/utils/admin-interface.ts +0 -37
- package/src/services/utils/cache.ts +0 -88
- package/src/services/utils/cluster-cache.ts +0 -255
- package/src/services/utils/cluster-ws.ts +0 -202
- package/src/services/utils/db-manager.ts +0 -92
- package/src/services/utils/get-route.ts +0 -70
- package/src/services/utils/jwt.ts +0 -25
- package/src/services/utils/log-transport.ts +0 -81
- package/src/services/utils/log.ts +0 -92
- package/src/services/utils/middleware.ts +0 -10
- package/src/services/utils/server-interface.ts +0 -122
- package/src/services/utils/websocketmanager.ts +0 -158
- package/src/types.ts +0 -287
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { Logger } from "@miqro/core";
|
|
2
|
-
import { CacheInterface } from "../../types.js";
|
|
3
|
-
|
|
4
|
-
const ClusterCacheType = "$$$$$$$$$$$ClusterCacheType$$$$$$$$$$$";
|
|
5
|
-
|
|
6
|
-
interface ClusterCacheMessage {
|
|
7
|
-
type: typeof ClusterCacheType;
|
|
8
|
-
target: string;
|
|
9
|
-
action: "set" | "unset" | "set_add" | "set_delete" | "array_push" | "set_clear" | "array_clear";
|
|
10
|
-
fromPID: number;
|
|
11
|
-
key: string;
|
|
12
|
-
value?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class ClusterCache implements CacheInterface {
|
|
16
|
-
private localCache = new Map<string, unknown>();
|
|
17
|
-
//private logger: Logger;
|
|
18
|
-
listener: (data: any) => Promise<void>;
|
|
19
|
-
|
|
20
|
-
constructor(public name: string, public logger?: Logger) {
|
|
21
|
-
this.listener = async (data) => {
|
|
22
|
-
try {
|
|
23
|
-
const msg = (data as ClusterCacheMessage);
|
|
24
|
-
|
|
25
|
-
//console.dir(msg);
|
|
26
|
-
if (
|
|
27
|
-
msg &&
|
|
28
|
-
msg.key &&
|
|
29
|
-
msg.action &&
|
|
30
|
-
msg.type === ClusterCacheType &&
|
|
31
|
-
msg.fromPID !== process.pid &&
|
|
32
|
-
(msg.action === "set_clear" || msg.action === "array_clear" || msg.action === "set_add" || msg.action === "set" || msg.action === "unset" || msg.action === "set_delete" || msg.action === "array_push") &&
|
|
33
|
-
msg.target === this.name) {
|
|
34
|
-
this.logger?.debug("remote cluster cache message from [%s] [%s] [%s] [%s]", msg.fromPID, msg.target, msg.action, msg.key);
|
|
35
|
-
switch (msg.action) {
|
|
36
|
-
case "set_clear": {
|
|
37
|
-
const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : new Set<string>();
|
|
38
|
-
if (!(list instanceof Set)) {
|
|
39
|
-
throw new Error("cannot apply clear on non set");
|
|
40
|
-
}
|
|
41
|
-
list.clear();
|
|
42
|
-
this.localCache.set(msg.key, list);
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
case "array_clear": {
|
|
46
|
-
//this.localCache.set(msg.key, msg.value);
|
|
47
|
-
const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : [];
|
|
48
|
-
if (!(list instanceof Array)) {
|
|
49
|
-
throw new Error("cannot apply clear on non array");
|
|
50
|
-
}
|
|
51
|
-
this.localCache.set(msg.key, []);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case "unset":
|
|
55
|
-
this.localCache.delete(msg.key);
|
|
56
|
-
break;
|
|
57
|
-
case "set":
|
|
58
|
-
this.localCache.set(msg.key, msg.value);
|
|
59
|
-
break;
|
|
60
|
-
case "set_add": {
|
|
61
|
-
//this.localCache.set(msg.key, msg.value);
|
|
62
|
-
const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : new Set<string>();
|
|
63
|
-
if (!(list instanceof Set)) {
|
|
64
|
-
throw new Error("cannot apply add on non set");
|
|
65
|
-
}
|
|
66
|
-
if (!list.has(msg.value)) {
|
|
67
|
-
list.add(msg.value);
|
|
68
|
-
}
|
|
69
|
-
this.localCache.set(msg.key, list);
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
case "set_delete": {
|
|
73
|
-
//this.localCache.set(msg.key, msg.value);
|
|
74
|
-
const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : new Set<string>();
|
|
75
|
-
if (!(list instanceof Set)) {
|
|
76
|
-
throw new Error("cannot apply delete on non set");
|
|
77
|
-
}
|
|
78
|
-
if (list.has(msg.value)) {
|
|
79
|
-
list.delete(msg.value);
|
|
80
|
-
}
|
|
81
|
-
this.localCache.set(msg.key, list);
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case "array_push": {
|
|
85
|
-
//this.localCache.set(msg.key, msg.value);
|
|
86
|
-
const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : [];
|
|
87
|
-
if (!(list instanceof Array)) {
|
|
88
|
-
throw new Error("cannot apply push on non array");
|
|
89
|
-
}
|
|
90
|
-
list.push(msg.value);
|
|
91
|
-
this.localCache.set(msg.key, list);
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} catch (e) {
|
|
97
|
-
this.logger?.error(e);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
this.connect();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
connect() {
|
|
104
|
-
if (process.send) {
|
|
105
|
-
process.removeListener("message", this.listener);
|
|
106
|
-
process.on("message", this.listener);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
disconnect() {
|
|
111
|
-
process.removeListener("message", this.listener);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
get<T = any>(key: string): T | undefined {
|
|
115
|
-
this.logger?.trace("get(%s)", key);
|
|
116
|
-
return this.localCache.get(key) as T;
|
|
117
|
-
}
|
|
118
|
-
set(key: string, value: unknown): void {
|
|
119
|
-
this.localCache.set(key, value);
|
|
120
|
-
this.logger?.trace("set(%s, ...)", key);
|
|
121
|
-
sendTimeout({
|
|
122
|
-
type: ClusterCacheType,
|
|
123
|
-
action: "set",
|
|
124
|
-
target: this.name,
|
|
125
|
-
fromPID: process.pid,
|
|
126
|
-
key,
|
|
127
|
-
value
|
|
128
|
-
} as ClusterCacheMessage);
|
|
129
|
-
}
|
|
130
|
-
unset(key: string): void {
|
|
131
|
-
this.logger?.trace("unset(%s)", key);
|
|
132
|
-
this.localCache.delete(key);
|
|
133
|
-
sendTimeout({
|
|
134
|
-
type: ClusterCacheType,
|
|
135
|
-
target: this.name,
|
|
136
|
-
action: "unset",
|
|
137
|
-
fromPID: process.pid,
|
|
138
|
-
key
|
|
139
|
-
} as ClusterCacheMessage);
|
|
140
|
-
}
|
|
141
|
-
has(key: string): boolean {
|
|
142
|
-
this.logger?.trace("has(%s)", key);
|
|
143
|
-
return this.localCache.has(key);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
set_add(key: string, value: unknown): void {
|
|
147
|
-
this.logger?.trace("push(%s)", key);
|
|
148
|
-
const list = this.localCache.has(key) ? this.localCache.get(key) : new Set<string>();
|
|
149
|
-
if (!(list instanceof Set)) {
|
|
150
|
-
throw new Error("cannot apply on non Set");
|
|
151
|
-
}
|
|
152
|
-
if (!list.has(value)) {
|
|
153
|
-
list.add(value);
|
|
154
|
-
}
|
|
155
|
-
this.localCache.set(key, list);
|
|
156
|
-
sendTimeout({
|
|
157
|
-
type: ClusterCacheType,
|
|
158
|
-
target: this.name,
|
|
159
|
-
action: "set_add",
|
|
160
|
-
fromPID: process.pid,
|
|
161
|
-
key,
|
|
162
|
-
value
|
|
163
|
-
} as ClusterCacheMessage);
|
|
164
|
-
}
|
|
165
|
-
set_delete(key: string, value: unknown): void {
|
|
166
|
-
this.logger?.trace("delete(%s)", key);
|
|
167
|
-
const list = this.localCache.has(key) ? this.localCache.get(key) : new Set<string>();
|
|
168
|
-
if (!(list instanceof Set)) {
|
|
169
|
-
throw new Error("cannot apply on non Set");
|
|
170
|
-
}
|
|
171
|
-
if (list.has(value)) {
|
|
172
|
-
list.delete(value);
|
|
173
|
-
}
|
|
174
|
-
this.localCache.set(key, list);
|
|
175
|
-
sendTimeout({
|
|
176
|
-
type: ClusterCacheType,
|
|
177
|
-
target: this.name,
|
|
178
|
-
action: "set_delete",
|
|
179
|
-
fromPID: process.pid,
|
|
180
|
-
key,
|
|
181
|
-
value
|
|
182
|
-
} as ClusterCacheMessage);
|
|
183
|
-
}
|
|
184
|
-
set_has(key: string, value: unknown): boolean {
|
|
185
|
-
this.logger?.trace("set_has(%s)", key);
|
|
186
|
-
const list = this.localCache.has(key) ? this.localCache.get(key) : new Set<string>();
|
|
187
|
-
if (!(list instanceof Set)) {
|
|
188
|
-
throw new Error("cannot apply on non Set");
|
|
189
|
-
}
|
|
190
|
-
const ret = list.has(value);
|
|
191
|
-
this.localCache.set(key, list);
|
|
192
|
-
return ret;
|
|
193
|
-
}
|
|
194
|
-
set_clear(key: string): void {
|
|
195
|
-
this.logger?.trace("set_clear(%s)", key);
|
|
196
|
-
const list = this.localCache.has(key) ? this.localCache.get(key) : new Set<string>();
|
|
197
|
-
if (!(list instanceof Set)) {
|
|
198
|
-
throw new Error("cannot apply on non Set");
|
|
199
|
-
}
|
|
200
|
-
list.clear();
|
|
201
|
-
this.localCache.set(key, list);
|
|
202
|
-
sendTimeout({
|
|
203
|
-
type: ClusterCacheType,
|
|
204
|
-
target: this.name,
|
|
205
|
-
action: "set_clear",
|
|
206
|
-
fromPID: process.pid,
|
|
207
|
-
key
|
|
208
|
-
} as ClusterCacheMessage);
|
|
209
|
-
}
|
|
210
|
-
array_push(key: string, value: unknown): void {
|
|
211
|
-
this.logger?.trace("array_push(%s)", key);
|
|
212
|
-
const list = this.localCache.has(key) ? this.localCache.get(key) : [];
|
|
213
|
-
if (!(list instanceof Array)) {
|
|
214
|
-
throw new Error("cannot apply on non Array");
|
|
215
|
-
}
|
|
216
|
-
list.push(value);
|
|
217
|
-
this.localCache.set(key, list);
|
|
218
|
-
sendTimeout({
|
|
219
|
-
type: ClusterCacheType,
|
|
220
|
-
target: this.name,
|
|
221
|
-
action: "array_push",
|
|
222
|
-
fromPID: process.pid,
|
|
223
|
-
key,
|
|
224
|
-
value
|
|
225
|
-
} as ClusterCacheMessage);
|
|
226
|
-
}
|
|
227
|
-
array_clear(key: string): void {
|
|
228
|
-
this.logger?.trace("array_clear(%s)", key);
|
|
229
|
-
if (this.localCache.has(key) && !(this.localCache.get(key) instanceof Array)) {
|
|
230
|
-
throw new Error("cannot apply on non Array");
|
|
231
|
-
}
|
|
232
|
-
this.localCache.set(key, []);
|
|
233
|
-
sendTimeout({
|
|
234
|
-
type: ClusterCacheType,
|
|
235
|
-
target: this.name,
|
|
236
|
-
action: "array_clear",
|
|
237
|
-
fromPID: process.pid,
|
|
238
|
-
key
|
|
239
|
-
} as ClusterCacheMessage);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function sendTimeout(msg: ClusterCacheMessage) {
|
|
244
|
-
if (process.send) {
|
|
245
|
-
setTimeout(() => {
|
|
246
|
-
try {
|
|
247
|
-
if (process.send) {
|
|
248
|
-
process.send(msg);
|
|
249
|
-
}
|
|
250
|
-
} catch (e) {
|
|
251
|
-
console.error(e);
|
|
252
|
-
}
|
|
253
|
-
}, 10);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { Logger, WebSocketServer, WebSocketServerOptions } from "@miqro/core";
|
|
2
|
-
import { Serializable } from "node:child_process";
|
|
3
|
-
|
|
4
|
-
const ClusterWebSocketServer2MessageType = "$$$$ClusterWebSocketServer2Message$$$$$";
|
|
5
|
-
|
|
6
|
-
export interface ClusterWebSocketServer2Message {
|
|
7
|
-
type: typeof ClusterWebSocketServer2MessageType;
|
|
8
|
-
target: string;
|
|
9
|
-
action: "connection" | "disconnection" | "sendMessage" | "error" | "sync";
|
|
10
|
-
clientUUID?: string;
|
|
11
|
-
errorMessage?: string;
|
|
12
|
-
fromUUID?: string;
|
|
13
|
-
fromPID: string,
|
|
14
|
-
payload?: Serializable;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class ClusterWebSocketServer2 extends WebSocketServer {
|
|
18
|
-
public remoteClients: Set<string> = new Set();
|
|
19
|
-
listener: (data: any) => Promise<void>;
|
|
20
|
-
public constructor(protected name: string, public path: string, public logger: Logger | Console, options: WebSocketServerOptions) {
|
|
21
|
-
super({
|
|
22
|
-
...options,
|
|
23
|
-
validate: (req) => {
|
|
24
|
-
if (
|
|
25
|
-
this.options.maxConnections !== undefined &&
|
|
26
|
-
this.clients.size + this.remoteClients.size >= this.options.maxConnections
|
|
27
|
-
) {
|
|
28
|
-
this.logger?.warn("[%s] max web socket connection reached! connection refused from [%s]", req.uuid, req.socket.remoteAddress);
|
|
29
|
-
return false;
|
|
30
|
-
} else {
|
|
31
|
-
return options.validate ? options.validate(req) : true;
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
onError: (req, error) => {
|
|
35
|
-
if (process.send) {
|
|
36
|
-
process.send({
|
|
37
|
-
type: ClusterWebSocketServer2MessageType,
|
|
38
|
-
action: "error",
|
|
39
|
-
target: this.name,
|
|
40
|
-
clientUUID: req.uuid,
|
|
41
|
-
fromPID: String(process.pid),
|
|
42
|
-
errorMessage: error.message
|
|
43
|
-
} as ClusterWebSocketServer2Message);
|
|
44
|
-
}
|
|
45
|
-
this.logger?.error("[%s] error from (%s) error [%s]", req.uuid, req.req.socket.remoteAddress, error);
|
|
46
|
-
this.logger?.error(error);
|
|
47
|
-
if (options.onError) {
|
|
48
|
-
options.onError(req, error);
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
onConnection: (req) => {
|
|
52
|
-
if (process.send) {
|
|
53
|
-
process.send({
|
|
54
|
-
type: ClusterWebSocketServer2MessageType,
|
|
55
|
-
action: "connection",
|
|
56
|
-
target: this.name,
|
|
57
|
-
fromPID: String(process.pid),
|
|
58
|
-
clientUUID: req.uuid
|
|
59
|
-
} as ClusterWebSocketServer2Message);
|
|
60
|
-
}
|
|
61
|
-
this.logger?.debug("[%s] new web socket connection from (%s)", req.uuid, req.req.socket.remoteAddress);
|
|
62
|
-
if (options.onConnection) {
|
|
63
|
-
options.onConnection(req);
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
onDisconnect: (req) => {
|
|
67
|
-
if (process.send) {
|
|
68
|
-
process.send({
|
|
69
|
-
type: ClusterWebSocketServer2MessageType,
|
|
70
|
-
action: "disconnection",
|
|
71
|
-
target: this.name,
|
|
72
|
-
fromPID: String(process.pid),
|
|
73
|
-
clientUUID: req.uuid
|
|
74
|
-
} as ClusterWebSocketServer2Message);
|
|
75
|
-
}
|
|
76
|
-
this.logger?.debug("[%s] [%s] web socket disconnection from (%s)", req.uuid, this.path, req.req.socket.remoteAddress);
|
|
77
|
-
if (options.onDisconnect) {
|
|
78
|
-
options.onDisconnect(req);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
this.listener = async (data) => {
|
|
83
|
-
try {
|
|
84
|
-
const msg = (data as ClusterWebSocketServer2Message);
|
|
85
|
-
if (
|
|
86
|
-
msg &&
|
|
87
|
-
msg.type === ClusterWebSocketServer2MessageType &&
|
|
88
|
-
msg.target === this.name &&
|
|
89
|
-
msg.action) {
|
|
90
|
-
// receive message from cluster workers
|
|
91
|
-
//console.dir(data);
|
|
92
|
-
//this.logger?.debug("remote web socket server message from [%s] [%s] [%s]", msg.fromPID, msg.target, msg.action);
|
|
93
|
-
switch (msg.action) {
|
|
94
|
-
case "sync":
|
|
95
|
-
if (process.send) {
|
|
96
|
-
for (const clientUUID of this.clients.keys()) {
|
|
97
|
-
process.send({
|
|
98
|
-
type: ClusterWebSocketServer2MessageType,
|
|
99
|
-
action: "connection",
|
|
100
|
-
target: this.name,
|
|
101
|
-
fromPID: String(process.pid),
|
|
102
|
-
clientUUID
|
|
103
|
-
} as ClusterWebSocketServer2Message);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
case "connection":
|
|
108
|
-
if (!msg.clientUUID) {
|
|
109
|
-
throw new Error(`action [${msg.action}] without clientUUID`);
|
|
110
|
-
}
|
|
111
|
-
if (!this.remoteClients.has(msg.clientUUID)) {
|
|
112
|
-
this.remoteClients.add(msg.clientUUID);
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
case "disconnection":
|
|
116
|
-
if (!msg.clientUUID) {
|
|
117
|
-
throw new Error(`action [${msg.action}] without clientUUID`);
|
|
118
|
-
}
|
|
119
|
-
if (this.remoteClients.has(msg.clientUUID)) {
|
|
120
|
-
this.remoteClients.delete(msg.clientUUID);
|
|
121
|
-
}
|
|
122
|
-
break;
|
|
123
|
-
case "sendMessage": {
|
|
124
|
-
const payload = String(msg.payload);
|
|
125
|
-
if (!msg.clientUUID) {
|
|
126
|
-
// broadcast to local clients
|
|
127
|
-
await super.broadcast(payload, msg.fromUUID);
|
|
128
|
-
} else if (this.isConnected(msg.clientUUID)) {
|
|
129
|
-
// write if local client
|
|
130
|
-
await super.writeTo(msg.clientUUID, payload);
|
|
131
|
-
}
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
default:
|
|
135
|
-
throw new Error(`action [${msg.action}] not supported`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
} catch (e) {
|
|
139
|
-
console.error(e);
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
this.connect();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
public connect() {
|
|
147
|
-
if (process.send) {
|
|
148
|
-
process.removeListener("message", this.listener);
|
|
149
|
-
process.on("message", this.listener);
|
|
150
|
-
process.send({
|
|
151
|
-
type: ClusterWebSocketServer2MessageType,
|
|
152
|
-
action: "sync",
|
|
153
|
-
fromPID: String(process.pid),
|
|
154
|
-
target: this.name
|
|
155
|
-
} as ClusterWebSocketServer2Message);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
public dispose() {
|
|
160
|
-
process.removeListener("message", this.listener);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
public async broadcast(payload: string, fromUUID?: string): Promise<void> {
|
|
164
|
-
if (process.send) {
|
|
165
|
-
process.send({
|
|
166
|
-
type: ClusterWebSocketServer2MessageType,
|
|
167
|
-
action: "sendMessage",
|
|
168
|
-
payload,
|
|
169
|
-
target: this.name,
|
|
170
|
-
fromPID: String(process.pid),
|
|
171
|
-
fromUUID
|
|
172
|
-
} as ClusterWebSocketServer2Message);
|
|
173
|
-
}
|
|
174
|
-
return super.broadcast(payload, fromUUID);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public async writeTo(clientUUID: string, payload: string): Promise<void> {
|
|
178
|
-
if (this.remoteClients.has(clientUUID)) {
|
|
179
|
-
// write to remote client via IPC
|
|
180
|
-
if (process.send) {
|
|
181
|
-
process.send({
|
|
182
|
-
type: ClusterWebSocketServer2MessageType,
|
|
183
|
-
action: "sendMessage",
|
|
184
|
-
clientUUID,
|
|
185
|
-
target: this.name,
|
|
186
|
-
fromPID: String(process.pid),
|
|
187
|
-
payload
|
|
188
|
-
} as ClusterWebSocketServer2Message);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// due to the implementation of isUUIDValid depends on this.remoteClients to be sync there can be two clients registered with the same UUID in the cluster
|
|
193
|
-
if (this.clients.has(clientUUID)) {
|
|
194
|
-
// write to local client
|
|
195
|
-
return super.writeTo(clientUUID, payload);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
public isUUIDValid(uuid: string) {
|
|
200
|
-
return !this.clients.has(uuid) && !this.remoteClients.has(uuid);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import cluster from "node:cluster";
|
|
2
|
-
import { Database } from "@miqro/query";
|
|
3
|
-
import { DBConfig } from "../../types.js";
|
|
4
|
-
import { LogProvider } from "./log.js";
|
|
5
|
-
import { Logger } from "@miqro/core";
|
|
6
|
-
|
|
7
|
-
export class DBManager {
|
|
8
|
-
private map = new Map<string, Database>();
|
|
9
|
-
public options: {
|
|
10
|
-
loggerProvider?: LogProvider;
|
|
11
|
-
logger?: Logger;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
constructor(options?: {
|
|
15
|
-
loggerProvider?: LogProvider;
|
|
16
|
-
logger?: Logger;
|
|
17
|
-
}) {
|
|
18
|
-
this.options = options ? options : {};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async setupDB(config: DBConfig) {
|
|
22
|
-
if (this.getDB(config.name)) {
|
|
23
|
-
throw new Error("cannot override db");
|
|
24
|
-
}
|
|
25
|
-
if (!config.disabled) {
|
|
26
|
-
const DB_IDENTIFIER = cluster.isPrimary ? "DATABASE" : process.env["CLUSTER_NODE_NUMBER"] ? `WORKER_${process.env["CLUSTER_NODE_NUMBER"]}_DATABASE` : "WORKER_DATABASE";
|
|
27
|
-
this.options?.logger?.debug("setting up db connection [%s]", config.name);
|
|
28
|
-
this.options?.logger?.trace("creating db connection [%s]", config.name);
|
|
29
|
-
const db = new Database({
|
|
30
|
-
dialect: config.dialect ? config.dialect as any : "node:sqlite",
|
|
31
|
-
storage: config.storage ? config.storage : "./db.sqlite3",
|
|
32
|
-
connectionString: config.url,
|
|
33
|
-
logger: this.options?.loggerProvider?.getLogger(`${DB_IDENTIFIER}_${config.name}`)
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
this.options?.logger?.trace("connecting db connection [%s]", config.name);
|
|
37
|
-
await db.connect();
|
|
38
|
-
this.options?.logger?.trace("db connection [%s] connected", config.name);
|
|
39
|
-
|
|
40
|
-
/*if (config.name && config.name !== name) {
|
|
41
|
-
this.setDB(config.name, db);
|
|
42
|
-
}*/
|
|
43
|
-
|
|
44
|
-
this.setDB(config.name, db);
|
|
45
|
-
|
|
46
|
-
return db;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async connectAll() {
|
|
51
|
-
this.options?.logger?.debug("connection all db connections");
|
|
52
|
-
const tR = [];
|
|
53
|
-
for (const name of this.map.keys()) {
|
|
54
|
-
const db = this.map.get(name);
|
|
55
|
-
if (db && db.status === "disconnected") {
|
|
56
|
-
this.options?.logger?.debug("connecting db connection [%s]", name);
|
|
57
|
-
tR.push(db.connect());
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
await Promise.all(tR);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async closeAll() {
|
|
64
|
-
this.options?.logger?.debug("closing all db connections");
|
|
65
|
-
for (const name of this.map.keys()) {
|
|
66
|
-
const db = this.map.get(name);
|
|
67
|
-
if (db && db.status === "connected") {
|
|
68
|
-
this.options?.logger?.debug("disconnecting db connection [%s]", name);
|
|
69
|
-
await db.disconnect();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async deleteAll() {
|
|
75
|
-
await this.closeAll();
|
|
76
|
-
this.options?.logger?.debug("clear all db connections");
|
|
77
|
-
this.map.clear();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
getDB(name: string): Database | null {
|
|
81
|
-
const db = this.map.get(name);
|
|
82
|
-
return db ? db : null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
setDB(name: string, db: Database): void {
|
|
86
|
-
if (this.getDB(name)) {
|
|
87
|
-
throw new Error("cannot override db connection [" + name + "]");
|
|
88
|
-
}
|
|
89
|
-
this.map.set(name, db);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { APIRoute, normalizePath, RouterHandlerOptions } from "@miqro/core";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
|
|
4
|
-
export interface RouterUseCall {
|
|
5
|
-
path?: string;
|
|
6
|
-
method?: string;
|
|
7
|
-
inflatePath: string;
|
|
8
|
-
defaultInflatePath: string;
|
|
9
|
-
options?: RouterHandlerOptions;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function getRoutes(prePath: string, defaultPath: string, apiOptions?: Partial<APIRoute>): RouterUseCall[] {
|
|
13
|
-
const ret: RouterUseCall[] = [];
|
|
14
|
-
const path = apiOptions && apiOptions.path ? apiOptions.path : defaultPath;
|
|
15
|
-
const defaultInflatePath = join(prePath, defaultPath);
|
|
16
|
-
const method = apiOptions && apiOptions.method ? apiOptions.method : "GET";
|
|
17
|
-
|
|
18
|
-
const methods = method instanceof Array ? method : [method];
|
|
19
|
-
const paths = path instanceof Array ? path : [path];
|
|
20
|
-
|
|
21
|
-
if (apiOptions && apiOptions.path === null) {
|
|
22
|
-
for (const m of methods) {
|
|
23
|
-
ret.push({
|
|
24
|
-
options: {
|
|
25
|
-
apiName: apiOptions?.apiName,
|
|
26
|
-
description: apiOptions?.description,
|
|
27
|
-
identifier: apiOptions?.identifier,
|
|
28
|
-
middleware: apiOptions?.middleware,
|
|
29
|
-
name: apiOptions?.name,
|
|
30
|
-
parser: apiOptions?.parser,
|
|
31
|
-
policy: apiOptions?.policy,
|
|
32
|
-
request: apiOptions?.request,
|
|
33
|
-
response: apiOptions?.response,
|
|
34
|
-
session: apiOptions?.session
|
|
35
|
-
},
|
|
36
|
-
inflatePath: defaultInflatePath,
|
|
37
|
-
defaultInflatePath,
|
|
38
|
-
method: m.toLocaleLowerCase() !== "use" ? m.toUpperCase() : undefined,
|
|
39
|
-
path: undefined
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
for (const p of paths) {
|
|
44
|
-
for (const m of methods) {
|
|
45
|
-
ret.push({
|
|
46
|
-
options: {
|
|
47
|
-
apiName: apiOptions?.apiName,
|
|
48
|
-
description: apiOptions?.description,
|
|
49
|
-
identifier: apiOptions?.identifier,
|
|
50
|
-
middleware: apiOptions?.middleware,
|
|
51
|
-
name: apiOptions?.name,
|
|
52
|
-
parser: apiOptions?.parser,
|
|
53
|
-
policy: apiOptions?.policy,
|
|
54
|
-
request: apiOptions?.request,
|
|
55
|
-
response: apiOptions?.response,
|
|
56
|
-
session: apiOptions?.session
|
|
57
|
-
},
|
|
58
|
-
inflatePath: p !== "/" ? join(prePath, p) : defaultInflatePath,
|
|
59
|
-
defaultInflatePath,
|
|
60
|
-
method: m.toLocaleLowerCase() !== "use" ? m.toUpperCase() : undefined,
|
|
61
|
-
path: normalizePath(join(prePath, p))
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return ret;
|
|
70
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { decodeJWT, decodeProtectedHeaderJWT, decryptJWT, encryptJWT, signJWT, verifyJWT } from "../../common/jwt.js";
|
|
2
|
-
import { JWTInterface } from "../../types.js";
|
|
3
|
-
import { createSecretKey } from "node:crypto";
|
|
4
|
-
|
|
5
|
-
export const jwt: JWTInterface = {
|
|
6
|
-
createSecretKey,
|
|
7
|
-
decode(jwt) {
|
|
8
|
-
return decodeJWT(jwt);
|
|
9
|
-
},
|
|
10
|
-
decodeProtectedHeader(token) {
|
|
11
|
-
return decodeProtectedHeaderJWT(token);
|
|
12
|
-
},
|
|
13
|
-
decrypt(jwt, secret, options) {
|
|
14
|
-
return decryptJWT(jwt, secret, options);
|
|
15
|
-
},
|
|
16
|
-
encrypt(payload, secret, options) {
|
|
17
|
-
return encryptJWT(payload, secret, options);
|
|
18
|
-
},
|
|
19
|
-
sign(payload, secret, options) {
|
|
20
|
-
return signJWT(payload, secret, options);
|
|
21
|
-
},
|
|
22
|
-
verify(jwt, secret, options) {
|
|
23
|
-
return verifyJWT(jwt, secret, options);
|
|
24
|
-
}
|
|
25
|
-
};
|