miqro 6.0.9 → 6.0.11
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/build/editor.bundle.js +29 -12
- package/build/esm/editor/common/log-socket.d.ts +3 -1
- package/build/esm/editor/common/log-socket.js +4 -1
- package/build/esm/editor/common/log-socket.js.map +1 -1
- package/build/esm/editor/common/templates.js +5 -5
- package/build/esm/editor/components/editor.js +4 -1
- package/build/esm/editor/components/editor.js.map +1 -1
- package/build/esm/editor/components/file-browser.js +28 -23
- package/build/esm/editor/components/file-browser.js.map +1 -1
- package/build/esm/editor/components/file-editor-toolbar.js +4 -4
- package/build/esm/editor/components/file-editor-toolbar.js.map +1 -1
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js +2 -1
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js.map +1 -1
- package/build/esm/editor/http/admin/editor/index.api.js +1 -1
- package/build/esm/src/cluster.js +0 -0
- package/build/esm/src/common/arguments.js +12 -7
- package/build/esm/src/common/arguments.js.map +1 -1
- package/build/esm/src/common/assets.d.ts +1 -0
- package/build/esm/src/common/assets.js +1 -1
- package/build/esm/src/common/assets.js.map +1 -1
- package/build/esm/src/common/jsx.d.ts +3 -3
- package/build/esm/src/common/jsx.js +36 -22
- package/build/esm/src/common/jsx.js.map +1 -1
- package/build/esm/src/common/watch.d.ts +3 -1
- package/build/esm/src/common/watch.js +5 -0
- package/build/esm/src/common/watch.js.map +1 -1
- package/build/esm/src/main.js +0 -0
- package/build/esm/src/services/app.d.ts +6 -1
- package/build/esm/src/services/app.js +36 -117
- package/build/esm/src/services/app.js.map +1 -1
- package/build/esm/src/services/utils/admin-interface.d.ts +3 -0
- package/build/esm/src/services/utils/admin-interface.js +34 -0
- package/build/esm/src/services/utils/admin-interface.js.map +1 -0
- package/build/esm/src/services/utils/cluster-cache.d.ts +2 -1
- package/build/esm/src/services/utils/cluster-cache.js +5 -1
- package/build/esm/src/services/utils/cluster-cache.js.map +1 -1
- package/build/esm/src/services/utils/cluster-ws.d.ts +1 -0
- package/build/esm/src/services/utils/cluster-ws.js +4 -0
- package/build/esm/src/services/utils/cluster-ws.js.map +1 -1
- package/build/esm/src/services/utils/db-manager.d.ts +1 -0
- package/build/esm/src/services/utils/db-manager.js +12 -0
- package/build/esm/src/services/utils/db-manager.js.map +1 -1
- package/build/esm/src/services/utils/log-transport.d.ts +7 -0
- package/build/esm/src/services/utils/log-transport.js +75 -0
- package/build/esm/src/services/utils/log-transport.js.map +1 -0
- package/build/esm/src/services/utils/websocketmanager.d.ts +1 -0
- package/build/esm/src/services/utils/websocketmanager.js +11 -3
- package/build/esm/src/services/utils/websocketmanager.js.map +1 -1
- package/build/esm/src/types.d.ts +2 -0
- package/build/lib.cjs +1268 -1195
- package/editor/common/log-socket.tsx +4 -1
- package/editor/common/templates.ts +5 -5
- package/editor/components/editor.tsx +4 -1
- package/editor/components/file-browser.tsx +48 -35
- package/editor/components/file-editor-toolbar.tsx +4 -0
- package/editor/http/admin/editor/api/server/reload.api.ts +2 -1
- package/editor/http/admin/editor/index.api.tsx +4 -4
- package/package.json +9 -7
- package/sea/compile.sh +8 -5
- package/sea/install-esbuild.sh +1 -1
- package/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +1 -1
- package/sea/types.json +1 -1
- package/sea/version.tag.js +11 -0
- package/src/common/arguments.ts +11 -7
- package/src/common/assets.ts +1 -1
- package/src/common/jsx.ts +35 -23
- package/src/common/watch.ts +5 -0
- package/src/services/app.ts +37 -115
- package/src/services/utils/admin-interface.ts +37 -0
- package/src/services/utils/cluster-cache.ts +6 -1
- package/src/services/utils/cluster-ws.ts +6 -1
- package/src/services/utils/db-manager.ts +13 -0
- package/src/services/utils/log-transport.ts +75 -0
- package/src/services/utils/websocketmanager.ts +13 -3
- package/src/types/miqro.d.ts +2 -2
- package/src/types.ts +3 -0
- package/package.json--OLD +0 -36
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve, dirname } from "node:path";
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
export const __package_dirname = import.meta.url ? resolve(dirname(fileURLToPath(import.meta.url))) : null;
|
|
6
|
+
|
|
7
|
+
const version = JSON.parse(readFileSync(resolve(__package_dirname, "../package.json")).toString()).version;
|
|
8
|
+
|
|
9
|
+
console.log("writing [%s] with [%s]", resolve(__package_dirname, "version.tag"), version);
|
|
10
|
+
|
|
11
|
+
writeFileSync(resolve(__package_dirname, "version.tag"), version);
|
package/src/common/arguments.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkEnvVariable } from "@miqro/core";
|
|
2
|
-
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { cwd, env, platform, arch } from "node:process";
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ import { BIN_NAME, help, usage } from "./help.js";
|
|
|
10
10
|
import { TEST_SOCKET } from "./paths.js";
|
|
11
11
|
import { isSea } from "node:sea";
|
|
12
12
|
import cluster from "node:cluster";
|
|
13
|
-
import { getVersion } from "./assets.js";
|
|
13
|
+
import { __package_dirname, getVersion } from "./assets.js";
|
|
14
14
|
|
|
15
15
|
export function getPORT() {
|
|
16
16
|
return checkEnvVariable("PORT", "8080");
|
|
@@ -84,8 +84,12 @@ export function parseArguments(): Arguments {
|
|
|
84
84
|
console.log("version [%s]", VERSION);
|
|
85
85
|
console.log("Node.js version [%s]", NODE_VERSION);
|
|
86
86
|
console.log("esbuild version [%s]", ESBUILD_VERSION);
|
|
87
|
+
console.log("platform [%s-%s]", platform, arch);
|
|
88
|
+
} else {
|
|
89
|
+
const packageJSON = JSON.parse(readFileSync(resolve(__package_dirname, "package.json")).toString());
|
|
90
|
+
const VERSION = packageJSON.version;
|
|
91
|
+
console.log("version [%s]", VERSION);
|
|
87
92
|
}
|
|
88
|
-
console.log("platform [%s-%s]", platform, arch);
|
|
89
93
|
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
90
94
|
case "-h":
|
|
91
95
|
case "--help":
|
|
@@ -319,22 +323,22 @@ export function parseArguments(): Arguments {
|
|
|
319
323
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
320
324
|
}
|
|
321
325
|
|
|
322
|
-
if (flags.test && (flags.editor)) {
|
|
326
|
+
if (flags.test && (flags.hotreload || flags.editor || flags.compile || flags.inflate)) {
|
|
323
327
|
console.error("bad arguments. cannot use --editor with --test");
|
|
324
328
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
325
329
|
}
|
|
326
330
|
|
|
327
|
-
if (flags.migrateUp && (flags.editor || flags.compile || flags.test || flags.migrateDown || flags.inflate)) {
|
|
331
|
+
if (flags.migrateUp && (flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateDown || flags.inflate)) {
|
|
328
332
|
console.error("bad arguments. cannot use with --migrate-up");
|
|
329
333
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
330
334
|
}
|
|
331
335
|
|
|
332
|
-
if (flags.migrateDown && (flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate)) {
|
|
336
|
+
if (flags.migrateDown && (flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate)) {
|
|
333
337
|
console.error("bad arguments. cannot use with --migrate-down");
|
|
334
338
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
335
339
|
}
|
|
336
340
|
|
|
337
|
-
if (flags.generateDoc && (flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate || flags.migrateDown)) {
|
|
341
|
+
if (flags.generateDoc && (flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate || flags.migrateDown)) {
|
|
338
342
|
console.error("bad arguments. cannot use with --generate-doc");
|
|
339
343
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
340
344
|
}
|
package/src/common/assets.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { initESBuild } from "./esbuild.js";
|
|
|
10
10
|
import { initJSXJS } from "./jsx.js";
|
|
11
11
|
//const require = createRequire(import.meta.url);
|
|
12
12
|
|
|
13
|
-
const __package_dirname = import.meta.url ? resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "..") : null;
|
|
13
|
+
export const __package_dirname = import.meta.url ? resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "..") : null;
|
|
14
14
|
|
|
15
15
|
const ASSETS_ROUTER = {
|
|
16
16
|
"lib.cjs": "build/lib.cjs",
|
package/src/common/jsx.ts
CHANGED
|
@@ -126,16 +126,6 @@ export async function inflateJSX(inFile: string, options: InflateOptions): Promi
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
export async function importAPIRoute(inFile: string, logger?: Logger) {
|
|
130
|
-
const mod = (await importJSXFile(inFile, logger)).default;
|
|
131
|
-
const module = typeof mod === "function" ? { handler: mod } : parser.parse(mod, APIRouteSchema, basename(inFile));
|
|
132
|
-
if (module !== undefined) {
|
|
133
|
-
return module as APIRoute;
|
|
134
|
-
} else {
|
|
135
|
-
throw new Error(`error with module [${inFile}] undefined`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
129
|
export const APIOptionsSchema: Schema<APIOptions> = {
|
|
140
130
|
type: "object?",
|
|
141
131
|
properties: {
|
|
@@ -155,7 +145,8 @@ export const APIOptionsSchema: Schema<APIOptions> = {
|
|
|
155
145
|
properties: SessionHandlerOptionsSchema.properties
|
|
156
146
|
},
|
|
157
147
|
...RouteOptionsSchema.properties
|
|
158
|
-
}
|
|
148
|
+
},
|
|
149
|
+
//mode:"add_extra"
|
|
159
150
|
};
|
|
160
151
|
|
|
161
152
|
export interface HTMLModule {
|
|
@@ -170,7 +161,8 @@ export const HTMLModuleSchema: Schema<HTMLModule> = {
|
|
|
170
161
|
type: "function|object"
|
|
171
162
|
},
|
|
172
163
|
apiOptions: APIOptionsSchema
|
|
173
|
-
}
|
|
164
|
+
},
|
|
165
|
+
//mode:"add_extra"
|
|
174
166
|
}
|
|
175
167
|
|
|
176
168
|
export type JSONModuleValue = string | object;
|
|
@@ -187,7 +179,8 @@ export const JSONModuleSchema: Schema<JSONModule> = {
|
|
|
187
179
|
type: "function|object|string"
|
|
188
180
|
},
|
|
189
181
|
apiOptions: APIOptionsSchema
|
|
190
|
-
}
|
|
182
|
+
},
|
|
183
|
+
//mode:"add_extra"
|
|
191
184
|
}
|
|
192
185
|
|
|
193
186
|
export const MigrationSchema: Schema<Migration> = {
|
|
@@ -195,7 +188,8 @@ export const MigrationSchema: Schema<Migration> = {
|
|
|
195
188
|
properties: {
|
|
196
189
|
up: "function",
|
|
197
190
|
down: "function"
|
|
198
|
-
}
|
|
191
|
+
},
|
|
192
|
+
mode: "add_extra"
|
|
199
193
|
}
|
|
200
194
|
|
|
201
195
|
export const CORSOptionsSchema: Schema<CORSOptions> = {
|
|
@@ -205,7 +199,8 @@ export const CORSOptionsSchema: Schema<CORSOptions> = {
|
|
|
205
199
|
validate: "function?",
|
|
206
200
|
methods: "string?",
|
|
207
201
|
preflightContinue: "boolean?"
|
|
208
|
-
}
|
|
202
|
+
},
|
|
203
|
+
//mode:"add_extra"
|
|
209
204
|
}
|
|
210
205
|
|
|
211
206
|
export const WSConfigSchema: Schema<WSConfig> = {
|
|
@@ -218,7 +213,8 @@ export const WSConfigSchema: Schema<WSConfig> = {
|
|
|
218
213
|
onConnection: "function?",
|
|
219
214
|
onMessage: "function?",
|
|
220
215
|
onDisconnect: "function?"
|
|
221
|
-
}
|
|
216
|
+
},
|
|
217
|
+
//mode:"add_extra"
|
|
222
218
|
};
|
|
223
219
|
|
|
224
220
|
export const DBConfigSchema: Schema<DBConfig> = {
|
|
@@ -229,7 +225,8 @@ export const DBConfigSchema: Schema<DBConfig> = {
|
|
|
229
225
|
storage: "string?",
|
|
230
226
|
dialect: "string?",
|
|
231
227
|
name: "string"
|
|
232
|
-
}
|
|
228
|
+
},
|
|
229
|
+
//mode:"add_extra"
|
|
233
230
|
}
|
|
234
231
|
|
|
235
232
|
export const ServerConfigSchema: Schema<ServerConfig> = {
|
|
@@ -240,7 +237,8 @@ export const ServerConfigSchema: Schema<ServerConfig> = {
|
|
|
240
237
|
stop: "function?",
|
|
241
238
|
start: "function?",
|
|
242
239
|
load: "function?"
|
|
243
|
-
}
|
|
240
|
+
},
|
|
241
|
+
//mode:"add_extra"
|
|
244
242
|
};
|
|
245
243
|
|
|
246
244
|
export const LogConfigSchema: Schema<LogConfig> = {
|
|
@@ -253,17 +251,27 @@ export const LogConfigSchema: Schema<LogConfig> = {
|
|
|
253
251
|
replaceConsoleTransport: "boolean?",
|
|
254
252
|
replaceFileTransport: "boolean?",
|
|
255
253
|
write: "function"
|
|
256
|
-
}
|
|
254
|
+
},
|
|
255
|
+
//mode:"add_extra"
|
|
257
256
|
};
|
|
258
257
|
|
|
259
258
|
export const AuthConfigSchema: Schema<AuthConfig> = {
|
|
260
259
|
type: "object",
|
|
261
260
|
properties: {
|
|
262
261
|
...SessionHandlerOptionsSchema.properties
|
|
263
|
-
}
|
|
262
|
+
},
|
|
263
|
+
//mode:"add_extra"
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
|
|
266
|
+
export async function importAPIRoute(inFile: string, logger?: Logger) {
|
|
267
|
+
const mod = (await importJSXFile(inFile, logger)).default;
|
|
268
|
+
const module = typeof mod === "function" ? { handler: mod } : parser.parse(mod, APIRouteSchema, basename(inFile));
|
|
269
|
+
if (module !== undefined) {
|
|
270
|
+
return module as APIRoute;
|
|
271
|
+
} else {
|
|
272
|
+
throw new Error(`error with module [${inFile}] undefined`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
267
275
|
|
|
268
276
|
export async function importMigrationModule(inFile: string, logger?: Logger) {
|
|
269
277
|
const module = parser.parse((await importJSXFile(inFile, logger)).default, MigrationSchema, basename(inFile));
|
|
@@ -275,7 +283,9 @@ export async function importMigrationModule(inFile: string, logger?: Logger) {
|
|
|
275
283
|
}
|
|
276
284
|
|
|
277
285
|
export async function importHTMLModule(inFile: string, logger?: Logger) {
|
|
278
|
-
const module =
|
|
286
|
+
const module = (await importJSXFile(inFile, logger));
|
|
287
|
+
parser.parse(module.default, HTMLModuleSchema.properties.default, `${basename(inFile)}.default`);
|
|
288
|
+
parser.parse(module.apiOptions, APIOptionsSchema, `${basename(inFile)}.apiOptions`);
|
|
279
289
|
if (module !== undefined) {
|
|
280
290
|
return module;
|
|
281
291
|
} else {
|
|
@@ -284,7 +294,9 @@ export async function importHTMLModule(inFile: string, logger?: Logger) {
|
|
|
284
294
|
}
|
|
285
295
|
|
|
286
296
|
export async function importJSONModule(inFile: string, logger?: Logger) {
|
|
287
|
-
const module =
|
|
297
|
+
const module = (await importJSXFile(inFile, logger));
|
|
298
|
+
parser.parse(module.default, JSONModuleSchema.properties.default, `${basename(inFile)}.default`);
|
|
299
|
+
parser.parse(module.apiOptions, APIOptionsSchema, `${basename(inFile)}.apiOptions`);
|
|
288
300
|
if (module !== undefined) {
|
|
289
301
|
return module;
|
|
290
302
|
} else {
|
package/src/common/watch.ts
CHANGED
package/src/services/app.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cluster from "node:cluster";
|
|
2
|
-
import { App, Router, Logger, LoggerHandler
|
|
2
|
+
import { App, Router, Logger, LoggerHandler } from "@miqro/core";
|
|
3
3
|
import { migration } from "@miqro/query";
|
|
4
4
|
import { WebSocketManager } from "./utils/websocketmanager.js";
|
|
5
5
|
import { DBManager } from "./utils/db-manager.js";
|
|
@@ -8,7 +8,7 @@ import { InflateError } from "../common/jsx.js";
|
|
|
8
8
|
import { DBConfig, MigrateOptions, ServerInterface, ServerRequest, WSConfig } from "../types.js";
|
|
9
9
|
import { RouteFileMap } from "../inflate/setup-http.js";
|
|
10
10
|
import { ServerConfigMap, setupServerConfig } from "../inflate/setup-server-config.js";
|
|
11
|
-
import { BASEEDITOR_PATH, LOG_SOCKET_PATH
|
|
11
|
+
import { BASEEDITOR_PATH, LOG_SOCKET_PATH } from "../../editor/common/constants.js";
|
|
12
12
|
import editorWSConfig from "../../editor/ws.js";
|
|
13
13
|
import editorServerConfig from "../../editor/server.js";
|
|
14
14
|
|
|
@@ -19,16 +19,16 @@ import { watchAndServer } from "../common/watch.js";
|
|
|
19
19
|
import { LocalCache } from "./utils/cache.js";
|
|
20
20
|
import { initGlobals } from "./globals.js";
|
|
21
21
|
import { EditorAdminInterface } from "../../editor/common/admin-interface.js";
|
|
22
|
-
import { getHotReloadScript } from "./hot-reload.js";
|
|
23
22
|
import { LogProvider, LogProviderOptions } from "./utils/log.js";
|
|
24
23
|
import { initAssets } from "../common/assets.js";
|
|
25
24
|
import { setupExitHandlers } from "../common/exit.js";
|
|
26
25
|
import { inflateDBConfig, inflateDBMigrations, MigrationModule } from "../inflate/setup-db.js";
|
|
27
26
|
import { getServicePath } from "../common/paths.js";
|
|
28
27
|
import { LogConfigMap } from "../inflate/setup-log.js";
|
|
29
|
-
import { format } from "node:util";
|
|
30
28
|
import { ServerInterfaceImpl } from "./utils/server-interface.js";
|
|
31
29
|
import { getPORT } from "../common/arguments.js";
|
|
30
|
+
import { createLogProviderOptions } from "./utils/log-transport.js";
|
|
31
|
+
import { createAdminInterface } from "./utils/admin-interface.js";
|
|
32
32
|
|
|
33
33
|
export interface MiqroOptions {
|
|
34
34
|
name: string;
|
|
@@ -69,6 +69,7 @@ export interface MiqroClusterMessage {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
export class Miqro {
|
|
72
|
+
public status: "stopped" | "starting" | "stopping" | "reloading" | "started" = "stopped";
|
|
72
73
|
public options: MiqroOptions;
|
|
73
74
|
public server?: App | null = null;
|
|
74
75
|
public cache: ClusterCache;
|
|
@@ -85,6 +86,7 @@ export class Miqro {
|
|
|
85
86
|
public logger?: Logger;
|
|
86
87
|
public loggerProvider: LogProvider;
|
|
87
88
|
public static initAssetsPromise: Promise<any> | null = null;
|
|
89
|
+
public watcher?: { stopWatch: () => void; };
|
|
88
90
|
|
|
89
91
|
constructor(options?: Partial<MiqroOptions>) {
|
|
90
92
|
this.options = {
|
|
@@ -94,72 +96,7 @@ export class Miqro {
|
|
|
94
96
|
services: [],
|
|
95
97
|
...(options ? options : {})
|
|
96
98
|
};
|
|
97
|
-
|
|
98
|
-
const defaultFile = FileTransport();
|
|
99
|
-
const defaultWrite = async (args: LoggerTransportWriteArgs, level?: LogLevel) => {
|
|
100
|
-
try {
|
|
101
|
-
const serviceNamesWithLogConfigReplaceConsole = level === undefined && this.inflated ?
|
|
102
|
-
Object.keys(this.inflated.logConfigMap).filter(serviceName => this.inflated.logConfigMap[serviceName].replaceConsoleTransport) : [];
|
|
103
|
-
const serviceNamesWithLogConfigReplaceFile = level === undefined && this.inflated ?
|
|
104
|
-
Object.keys(this.inflated.logConfigMap).filter(serviceName => this.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
|
|
105
|
-
await Promise.allSettled((level === undefined ?
|
|
106
|
-
[
|
|
107
|
-
level === undefined && serviceNamesWithLogConfigReplaceConsole.length === 0 ?
|
|
108
|
-
defaultConsole.write(args) : Promise.resolve(),
|
|
109
|
-
level === undefined && serviceNamesWithLogConfigReplaceFile.length === 0 ?
|
|
110
|
-
defaultFile.write(args) : Promise.resolve()
|
|
111
|
-
] : []).concat(this.inflated ?
|
|
112
|
-
Object.keys(this.inflated.logConfigMap).map(serviceName => this.inflated.logConfigMap[serviceName]).filter(c => c.level === level).map(c => c.write(args)) : []
|
|
113
|
-
));
|
|
114
|
-
} catch (e) {
|
|
115
|
-
console.error(e);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
this.loggerProvider = new LogProvider({
|
|
119
|
-
name: this.options.name,
|
|
120
|
-
formatter: ({ identifier, level, message, optionalParams }) => format(`${new Date().toISOString()} PID[${process.pid}] ` +
|
|
121
|
-
`${identifier ? `[${identifier}] ` : ""}` +
|
|
122
|
-
`${level !== "info" ? (level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] `) : ""}` +
|
|
123
|
-
`${message}`, ...optionalParams),
|
|
124
|
-
transports: [
|
|
125
|
-
...(([undefined, "error", "warn", "info", "debug", "trace"] as LogLevel[]).map(level => {
|
|
126
|
-
return level ? {
|
|
127
|
-
level,
|
|
128
|
-
write: async (args) => {
|
|
129
|
-
await defaultWrite(args, level);
|
|
130
|
-
}
|
|
131
|
-
} : {
|
|
132
|
-
write: async (args) => {
|
|
133
|
-
await defaultWrite(args, undefined);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
})), {
|
|
137
|
-
level: "trace",
|
|
138
|
-
write: async (args) => {
|
|
139
|
-
try {
|
|
140
|
-
if (this.options.editor) {
|
|
141
|
-
try {
|
|
142
|
-
const ws = this.webSocketManager.getWS(LOG_SOCKET_PATH);
|
|
143
|
-
if (ws) {
|
|
144
|
-
//console.log("\n\n" + process.pid + " broadcasting " + LOG_SOCKET_PATH + "\n\n\n")
|
|
145
|
-
await ws.broadcast(JSON.stringify({
|
|
146
|
-
type: LOG_WRITE_EVENT,
|
|
147
|
-
level: args.level,
|
|
148
|
-
identifier: args.identifier,
|
|
149
|
-
out: args.out
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
|
-
} catch (e) {
|
|
153
|
-
console.error(e);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
} catch (e) {
|
|
157
|
-
console.error(e);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}],
|
|
161
|
-
...(this.options.logProviderOptions ? this.options.logProviderOptions : {})
|
|
162
|
-
});
|
|
99
|
+
this.loggerProvider = new LogProvider(createLogProviderOptions(this));
|
|
163
100
|
//if (!this.options.logger) {
|
|
164
101
|
const SERVER_IDENTIFIER = cluster.isPrimary ?
|
|
165
102
|
"" :
|
|
@@ -220,59 +157,30 @@ export class Miqro {
|
|
|
220
157
|
port: this.options.port
|
|
221
158
|
});
|
|
222
159
|
this.serverRequestHandler = ServerRequestHandler(this.serverInterface);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
this.adminInterface = {
|
|
226
|
-
getCache: () => adminCache,
|
|
227
|
-
stop: () => this.stop(),
|
|
228
|
-
restart: () => this.restart(),
|
|
229
|
-
reload: () => this.reload(),
|
|
230
|
-
getHotReloadHTML: getHotReloadScript,
|
|
231
|
-
getMigrations: () => {
|
|
232
|
-
if (this.inflated) {
|
|
233
|
-
const ret: MigrationModule[] = [];
|
|
234
|
-
for (const db of this.inflated.dbList) {
|
|
235
|
-
for (const m of db.migrations) {
|
|
236
|
-
ret.push(m);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return ret;
|
|
240
|
-
}
|
|
241
|
-
return [];
|
|
242
|
-
},
|
|
243
|
-
getServices: () => {
|
|
244
|
-
return this.options.services;
|
|
245
|
-
},
|
|
246
|
-
getRouteFileMap: () => {
|
|
247
|
-
return this.inflated ? this.inflated.fileMap : {};
|
|
248
|
-
},
|
|
249
|
-
getInflateErrors: () => {
|
|
250
|
-
return this.inflated ? this.inflated.errors : [];
|
|
251
|
-
}/*,
|
|
252
|
-
inflateJSX: async function inflateJSX(path, minify: boolean = true) {
|
|
253
|
-
return realInflateJSX(path, {
|
|
254
|
-
embemedJSX: true,
|
|
255
|
-
minify,
|
|
256
|
-
useExport: true
|
|
257
|
-
});
|
|
258
|
-
}*/
|
|
259
|
-
};
|
|
160
|
+
|
|
161
|
+
this.adminInterface = createAdminInterface(this);
|
|
260
162
|
|
|
261
163
|
setupExitHandlers(this);
|
|
164
|
+
}
|
|
262
165
|
|
|
166
|
+
public connect() {
|
|
263
167
|
if (process.send) {
|
|
168
|
+
process.removeListener("message", this.listener);
|
|
264
169
|
process.on("message", this.listener);
|
|
265
170
|
}
|
|
171
|
+
this.cache.connect();
|
|
172
|
+
(this.adminInterface?.getCache() as ClusterCache)?.connect();
|
|
266
173
|
}
|
|
267
174
|
|
|
268
|
-
public
|
|
175
|
+
public disconnect() {
|
|
269
176
|
if (this.server !== null) {
|
|
270
177
|
throw new Error("already running! call stop() first");
|
|
271
178
|
}
|
|
272
179
|
if (process.send) {
|
|
273
180
|
process.removeListener("message", this.listener);
|
|
274
181
|
}
|
|
275
|
-
this.cache.
|
|
182
|
+
this.cache.disconnect();
|
|
183
|
+
(this.adminInterface?.getCache() as ClusterCache)?.disconnect();
|
|
276
184
|
this.webSocketManager.disconnectAll();
|
|
277
185
|
this.dbManager.closeAll();
|
|
278
186
|
}
|
|
@@ -482,7 +390,7 @@ export class Miqro {
|
|
|
482
390
|
}
|
|
483
391
|
|
|
484
392
|
public async start() {
|
|
485
|
-
if (this.server !== null) {
|
|
393
|
+
if (this.server !== null || this.status !== "stopped") {
|
|
486
394
|
throw new Error("cannot start app already running.");
|
|
487
395
|
}
|
|
488
396
|
if (!this.isInflated()) {
|
|
@@ -491,7 +399,11 @@ export class Miqro {
|
|
|
491
399
|
//this.logger?.debug("starting");
|
|
492
400
|
this.logger?.debug("\t\t==start==");
|
|
493
401
|
|
|
402
|
+
//this.disconnect();
|
|
403
|
+
this.status = "starting";
|
|
494
404
|
this.server = undefined;
|
|
405
|
+
this.connect();
|
|
406
|
+
await this.dbManager.connectAll();
|
|
495
407
|
this.server = new App({
|
|
496
408
|
onUpgrade: (req: ServerRequest, socket, head) => {
|
|
497
409
|
req.server = this.serverInterface;
|
|
@@ -531,20 +443,27 @@ export class Miqro {
|
|
|
531
443
|
await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "start");
|
|
532
444
|
|
|
533
445
|
if (this.options.hotreload && (cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
|
|
534
|
-
await watchAndServer(this);
|
|
446
|
+
this.watcher = await watchAndServer(this);
|
|
535
447
|
}
|
|
536
448
|
|
|
537
449
|
this.logger?.debug("\t\t==start done==");
|
|
538
450
|
|
|
451
|
+
this.status = "started";
|
|
539
452
|
return this.inflated.errors && this.inflated.errors.length > 0 ? this.inflated.errors : null;
|
|
540
453
|
}
|
|
541
454
|
|
|
542
455
|
public async stop() {
|
|
543
|
-
if (!this.server || !this.inflated) {
|
|
456
|
+
if (!this.server || !this.inflated || this.status !== "started") {
|
|
544
457
|
throw new Error("cannot stop server not running");
|
|
545
458
|
}
|
|
459
|
+
this.status = "stopping";
|
|
460
|
+
if (this.watcher) {
|
|
461
|
+
this.watcher.stopWatch();
|
|
462
|
+
this.watcher = null;
|
|
463
|
+
}
|
|
546
464
|
const server = this.server;
|
|
547
465
|
this.server = null;
|
|
466
|
+
this.disconnect();
|
|
548
467
|
this.logger?.debug("\t\t==stop==");
|
|
549
468
|
this.logger?.debug("clear running server routes");
|
|
550
469
|
server.clear();
|
|
@@ -555,14 +474,15 @@ export class Miqro {
|
|
|
555
474
|
//server.ws.disconnectAll();
|
|
556
475
|
this.logger?.debug("stopping");
|
|
557
476
|
const p = server.close();
|
|
558
|
-
notifiyServerConfigSync(this, "stop");
|
|
559
477
|
await p;
|
|
560
478
|
await pD;
|
|
479
|
+
this.status = "stopped";
|
|
480
|
+
notifiyServerConfigSync(this, "stop");
|
|
561
481
|
this.logger?.debug("\t\t==stop done==");
|
|
562
482
|
}
|
|
563
483
|
|
|
564
484
|
public async restart(avoidSend?: boolean) {
|
|
565
|
-
if (!this.server || !this.inflated) {
|
|
485
|
+
if (!this.server || !this.inflated || this.status !== "started") {
|
|
566
486
|
throw new Error("cannot start server not running");
|
|
567
487
|
}
|
|
568
488
|
this.logger?.debug("\t\t==restart==");
|
|
@@ -581,9 +501,10 @@ export class Miqro {
|
|
|
581
501
|
}
|
|
582
502
|
|
|
583
503
|
public async reload(avoidSend?: boolean) {
|
|
584
|
-
if (!this.server || !this.inflated) {
|
|
504
|
+
if (!this.server || !this.inflated || this.status !== "started") {
|
|
585
505
|
throw new Error("cannot reload server not running");
|
|
586
506
|
}
|
|
507
|
+
this.status = "reloading";
|
|
587
508
|
/*this.logger?.log("====================");
|
|
588
509
|
this.logger?.log("=======reload=======");
|
|
589
510
|
this.logger?.log("====================");*/
|
|
@@ -642,6 +563,7 @@ export class Miqro {
|
|
|
642
563
|
this.logger?.debug("\t\t==reload done==");
|
|
643
564
|
//this.logger?.log("=====================");
|
|
644
565
|
|
|
566
|
+
this.status = "started";
|
|
645
567
|
return this.inflated.errors && this.inflated.errors.length > 0 ? this.inflated.errors : null;
|
|
646
568
|
|
|
647
569
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EditorAdminInterface } from "../../../editor/common/admin-interface.js";
|
|
2
|
+
import { MigrationModule } from "../../inflate/setup-db.js";
|
|
3
|
+
import { Miqro } from "../app.js";
|
|
4
|
+
import { getHotReloadScript } from "../hot-reload.js";
|
|
5
|
+
import { ClusterCache } from "./cluster-cache.js";
|
|
6
|
+
|
|
7
|
+
export function createAdminInterface(app: Miqro): EditorAdminInterface {
|
|
8
|
+
const adminCache = new ClusterCache("EditorCache[" + app.options.name + "]");
|
|
9
|
+
return {
|
|
10
|
+
getCache: () => adminCache,
|
|
11
|
+
stop: () => app.stop(),
|
|
12
|
+
restart: () => app.restart(),
|
|
13
|
+
reload: () => app.reload(),
|
|
14
|
+
getHotReloadHTML: getHotReloadScript,
|
|
15
|
+
getMigrations: () => {
|
|
16
|
+
if (app.inflated) {
|
|
17
|
+
const ret: MigrationModule[] = [];
|
|
18
|
+
for (const db of app.inflated.dbList) {
|
|
19
|
+
for (const m of db.migrations) {
|
|
20
|
+
ret.push(m);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return ret;
|
|
24
|
+
}
|
|
25
|
+
return [];
|
|
26
|
+
},
|
|
27
|
+
getServices: () => {
|
|
28
|
+
return app.options.services;
|
|
29
|
+
},
|
|
30
|
+
getRouteFileMap: () => {
|
|
31
|
+
return app.inflated ? app.inflated.fileMap : {};
|
|
32
|
+
},
|
|
33
|
+
getInflateErrors: () => {
|
|
34
|
+
return app.inflated ? app.inflated.errors : [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -79,12 +79,17 @@ export class ClusterCache implements CacheInterface {
|
|
|
79
79
|
this.logger?.error(e);
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
+
this.connect();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
connect() {
|
|
82
86
|
if (process.send) {
|
|
87
|
+
process.removeListener("message", this.listener);
|
|
83
88
|
process.on("message", this.listener);
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
|
|
87
|
-
|
|
92
|
+
disconnect() {
|
|
88
93
|
process.removeListener("message", this.listener);
|
|
89
94
|
}
|
|
90
95
|
|
|
@@ -135,7 +135,12 @@ export class ClusterWebSocketServer2 extends WebSocketServer {
|
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
+
this.connect();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public connect() {
|
|
138
142
|
if (process.send) {
|
|
143
|
+
process.removeListener("message", this.listener);
|
|
139
144
|
process.on("message", this.listener);
|
|
140
145
|
process.send({
|
|
141
146
|
type: ClusterWebSocketServer2MessageType,
|
|
@@ -146,7 +151,7 @@ export class ClusterWebSocketServer2 extends WebSocketServer {
|
|
|
146
151
|
}
|
|
147
152
|
}
|
|
148
153
|
|
|
149
|
-
dispose() {
|
|
154
|
+
public dispose() {
|
|
150
155
|
process.removeListener("message", this.listener);
|
|
151
156
|
}
|
|
152
157
|
|
|
@@ -47,6 +47,19 @@ export class DBManager {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
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
|
+
|
|
50
63
|
async closeAll() {
|
|
51
64
|
this.options?.logger?.debug("closing all db connections");
|
|
52
65
|
for (const name of this.map.keys()) {
|