miqro 6.0.9 → 6.0.10
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 +24 -7
- 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/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/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/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/lib.cjs +204 -129
- package/editor/common/log-socket.tsx +4 -1
- 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/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/package.json--OLD +0 -36
package/build/lib.cjs
CHANGED
|
@@ -4336,11 +4336,12 @@ var init_reload_api = __esm({
|
|
|
4336
4336
|
},
|
|
4337
4337
|
handler: async (req, res) => {
|
|
4338
4338
|
const errors = await req?.editor?.reload();
|
|
4339
|
+
const parsedErrors = parseInflateErrors2(errors);
|
|
4339
4340
|
return res.json({
|
|
4340
4341
|
message: "OK",
|
|
4341
4342
|
reloadString: req.uuid,
|
|
4342
4343
|
migrations: req?.editor?.getMigrations().map((m) => m.name),
|
|
4343
|
-
errors:
|
|
4344
|
+
errors: parsedErrors ? parsedErrors : []
|
|
4344
4345
|
});
|
|
4345
4346
|
}
|
|
4346
4347
|
};
|
|
@@ -7176,7 +7177,13 @@ var ClusterWebSocketServer2 = class extends WebSocketServer {
|
|
|
7176
7177
|
console.error(e);
|
|
7177
7178
|
}
|
|
7178
7179
|
};
|
|
7180
|
+
this.connect();
|
|
7181
|
+
}
|
|
7182
|
+
remoteClients = /* @__PURE__ */ new Set();
|
|
7183
|
+
listener;
|
|
7184
|
+
connect() {
|
|
7179
7185
|
if (process.send) {
|
|
7186
|
+
process.removeListener("message", this.listener);
|
|
7180
7187
|
process.on("message", this.listener);
|
|
7181
7188
|
process.send({
|
|
7182
7189
|
type: ClusterWebSocketServer2MessageType,
|
|
@@ -7186,8 +7193,6 @@ var ClusterWebSocketServer2 = class extends WebSocketServer {
|
|
|
7186
7193
|
});
|
|
7187
7194
|
}
|
|
7188
7195
|
}
|
|
7189
|
-
remoteClients = /* @__PURE__ */ new Set();
|
|
7190
|
-
listener;
|
|
7191
7196
|
dispose() {
|
|
7192
7197
|
process.removeListener("message", this.listener);
|
|
7193
7198
|
}
|
|
@@ -7282,14 +7287,18 @@ var ClusterCache = class {
|
|
|
7282
7287
|
this.logger?.error(e);
|
|
7283
7288
|
}
|
|
7284
7289
|
};
|
|
7285
|
-
|
|
7286
|
-
process.on("message", this.listener);
|
|
7287
|
-
}
|
|
7290
|
+
this.connect();
|
|
7288
7291
|
}
|
|
7289
7292
|
localCache = /* @__PURE__ */ new Map();
|
|
7290
7293
|
//private logger: Logger;
|
|
7291
7294
|
listener;
|
|
7292
|
-
|
|
7295
|
+
connect() {
|
|
7296
|
+
if (process.send) {
|
|
7297
|
+
process.removeListener("message", this.listener);
|
|
7298
|
+
process.on("message", this.listener);
|
|
7299
|
+
}
|
|
7300
|
+
}
|
|
7301
|
+
disconnect() {
|
|
7293
7302
|
process.removeListener("message", this.listener);
|
|
7294
7303
|
}
|
|
7295
7304
|
get(key) {
|
|
@@ -7523,8 +7532,16 @@ var WebSocketManager = class {
|
|
|
7523
7532
|
this.name = options && options.name ? options.name : "WebSocketManager";
|
|
7524
7533
|
this.avoidLogSocket = options && options.avoidLogSocket ? options.avoidLogSocket : false;
|
|
7525
7534
|
}
|
|
7535
|
+
deleteWS(path) {
|
|
7536
|
+
const ws = this.runningGlobalWSMap.get(path);
|
|
7537
|
+
this.disconnectAllFrom(path);
|
|
7538
|
+
ws.dispose();
|
|
7539
|
+
this.runningGlobalWSMap.delete(path);
|
|
7540
|
+
}
|
|
7526
7541
|
deleteAllWS() {
|
|
7527
|
-
this.runningGlobalWSMap.
|
|
7542
|
+
for (const path of this.runningGlobalWSMap.keys()) {
|
|
7543
|
+
this.deleteWS(path);
|
|
7544
|
+
}
|
|
7528
7545
|
}
|
|
7529
7546
|
getWS(path) {
|
|
7530
7547
|
return this.runningGlobalWSMap.get(path);
|
|
@@ -7545,7 +7562,7 @@ var WebSocketManager = class {
|
|
|
7545
7562
|
replaceALLWSBuLOGSocket(list) {
|
|
7546
7563
|
for (const path of this.runningGlobalWSMap.keys()) {
|
|
7547
7564
|
if (path !== LOG_SOCKET_PATH || !this.avoidLogSocket) {
|
|
7548
|
-
this.
|
|
7565
|
+
this.deleteWS(path);
|
|
7549
7566
|
}
|
|
7550
7567
|
}
|
|
7551
7568
|
for (const wsConfig of list) {
|
|
@@ -7583,7 +7600,6 @@ var WebSocketManager = class {
|
|
|
7583
7600
|
}
|
|
7584
7601
|
}
|
|
7585
7602
|
}
|
|
7586
|
-
ws.dispose();
|
|
7587
7603
|
}
|
|
7588
7604
|
} catch (e) {
|
|
7589
7605
|
this.logger?.error("error disconnecting web socket clients");
|
|
@@ -9187,6 +9203,18 @@ var DBManager = class {
|
|
|
9187
9203
|
return db;
|
|
9188
9204
|
}
|
|
9189
9205
|
}
|
|
9206
|
+
async connectAll() {
|
|
9207
|
+
this.options?.logger?.debug("connection all db connections");
|
|
9208
|
+
const tR = [];
|
|
9209
|
+
for (const name of this.map.keys()) {
|
|
9210
|
+
const db = this.map.get(name);
|
|
9211
|
+
if (db && db.status === "disconnected") {
|
|
9212
|
+
this.options?.logger?.debug("connecting db connection [%s]", name);
|
|
9213
|
+
tR.push(db.connect());
|
|
9214
|
+
}
|
|
9215
|
+
}
|
|
9216
|
+
await Promise.all(tR);
|
|
9217
|
+
}
|
|
9190
9218
|
async closeAll() {
|
|
9191
9219
|
this.options?.logger?.debug("closing all db connections");
|
|
9192
9220
|
for (const name of this.map.keys()) {
|
|
@@ -11699,15 +11727,6 @@ async function inflateJSX(inFile, options) {
|
|
|
11699
11727
|
throw e;
|
|
11700
11728
|
}
|
|
11701
11729
|
}
|
|
11702
|
-
async function importAPIRoute(inFile, logger) {
|
|
11703
|
-
const mod = (await importJSXFile(inFile, logger)).default;
|
|
11704
|
-
const module2 = typeof mod === "function" ? { handler: mod } : parser2.parse(mod, APIRouteSchema, (0, import_node_path5.basename)(inFile));
|
|
11705
|
-
if (module2 !== void 0) {
|
|
11706
|
-
return module2;
|
|
11707
|
-
} else {
|
|
11708
|
-
throw new Error(`error with module [${inFile}] undefined`);
|
|
11709
|
-
}
|
|
11710
|
-
}
|
|
11711
11730
|
var APIOptionsSchema = {
|
|
11712
11731
|
type: "object?",
|
|
11713
11732
|
properties: {
|
|
@@ -11728,6 +11747,7 @@ var APIOptionsSchema = {
|
|
|
11728
11747
|
},
|
|
11729
11748
|
...RouteOptionsSchema.properties
|
|
11730
11749
|
}
|
|
11750
|
+
//mode:"add_extra"
|
|
11731
11751
|
};
|
|
11732
11752
|
var HTMLModuleSchema = {
|
|
11733
11753
|
type: "object",
|
|
@@ -11737,6 +11757,7 @@ var HTMLModuleSchema = {
|
|
|
11737
11757
|
},
|
|
11738
11758
|
apiOptions: APIOptionsSchema
|
|
11739
11759
|
}
|
|
11760
|
+
//mode:"add_extra"
|
|
11740
11761
|
};
|
|
11741
11762
|
var JSONModuleSchema = {
|
|
11742
11763
|
type: "object",
|
|
@@ -11746,13 +11767,15 @@ var JSONModuleSchema = {
|
|
|
11746
11767
|
},
|
|
11747
11768
|
apiOptions: APIOptionsSchema
|
|
11748
11769
|
}
|
|
11770
|
+
//mode:"add_extra"
|
|
11749
11771
|
};
|
|
11750
11772
|
var MigrationSchema = {
|
|
11751
11773
|
type: "object",
|
|
11752
11774
|
properties: {
|
|
11753
11775
|
up: "function",
|
|
11754
11776
|
down: "function"
|
|
11755
|
-
}
|
|
11777
|
+
},
|
|
11778
|
+
mode: "add_extra"
|
|
11756
11779
|
};
|
|
11757
11780
|
var CORSOptionsSchema = {
|
|
11758
11781
|
type: "object",
|
|
@@ -11762,6 +11785,7 @@ var CORSOptionsSchema = {
|
|
|
11762
11785
|
methods: "string?",
|
|
11763
11786
|
preflightContinue: "boolean?"
|
|
11764
11787
|
}
|
|
11788
|
+
//mode:"add_extra"
|
|
11765
11789
|
};
|
|
11766
11790
|
var WSConfigSchema = {
|
|
11767
11791
|
type: "object",
|
|
@@ -11774,6 +11798,7 @@ var WSConfigSchema = {
|
|
|
11774
11798
|
onMessage: "function?",
|
|
11775
11799
|
onDisconnect: "function?"
|
|
11776
11800
|
}
|
|
11801
|
+
//mode:"add_extra"
|
|
11777
11802
|
};
|
|
11778
11803
|
var DBConfigSchema = {
|
|
11779
11804
|
type: "object",
|
|
@@ -11784,6 +11809,7 @@ var DBConfigSchema = {
|
|
|
11784
11809
|
dialect: "string?",
|
|
11785
11810
|
name: "string"
|
|
11786
11811
|
}
|
|
11812
|
+
//mode:"add_extra"
|
|
11787
11813
|
};
|
|
11788
11814
|
var ServerConfigSchema = {
|
|
11789
11815
|
type: "object",
|
|
@@ -11794,6 +11820,7 @@ var ServerConfigSchema = {
|
|
|
11794
11820
|
start: "function?",
|
|
11795
11821
|
load: "function?"
|
|
11796
11822
|
}
|
|
11823
|
+
//mode:"add_extra"
|
|
11797
11824
|
};
|
|
11798
11825
|
var LogConfigSchema = {
|
|
11799
11826
|
type: "object",
|
|
@@ -11806,13 +11833,24 @@ var LogConfigSchema = {
|
|
|
11806
11833
|
replaceFileTransport: "boolean?",
|
|
11807
11834
|
write: "function"
|
|
11808
11835
|
}
|
|
11836
|
+
//mode:"add_extra"
|
|
11809
11837
|
};
|
|
11810
11838
|
var AuthConfigSchema = {
|
|
11811
11839
|
type: "object",
|
|
11812
11840
|
properties: {
|
|
11813
11841
|
...SessionHandlerOptionsSchema.properties
|
|
11814
11842
|
}
|
|
11843
|
+
//mode:"add_extra"
|
|
11815
11844
|
};
|
|
11845
|
+
async function importAPIRoute(inFile, logger) {
|
|
11846
|
+
const mod = (await importJSXFile(inFile, logger)).default;
|
|
11847
|
+
const module2 = typeof mod === "function" ? { handler: mod } : parser2.parse(mod, APIRouteSchema, (0, import_node_path5.basename)(inFile));
|
|
11848
|
+
if (module2 !== void 0) {
|
|
11849
|
+
return module2;
|
|
11850
|
+
} else {
|
|
11851
|
+
throw new Error(`error with module [${inFile}] undefined`);
|
|
11852
|
+
}
|
|
11853
|
+
}
|
|
11816
11854
|
async function importMigrationModule(inFile, logger) {
|
|
11817
11855
|
const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, MigrationSchema, (0, import_node_path5.basename)(inFile));
|
|
11818
11856
|
if (module2 !== void 0) {
|
|
@@ -11822,7 +11860,9 @@ async function importMigrationModule(inFile, logger) {
|
|
|
11822
11860
|
}
|
|
11823
11861
|
}
|
|
11824
11862
|
async function importHTMLModule(inFile, logger) {
|
|
11825
|
-
const module2 =
|
|
11863
|
+
const module2 = await importJSXFile(inFile, logger);
|
|
11864
|
+
parser2.parse(module2.default, HTMLModuleSchema.properties.default, `${(0, import_node_path5.basename)(inFile)}.default`);
|
|
11865
|
+
parser2.parse(module2.apiOptions, APIOptionsSchema, `${(0, import_node_path5.basename)(inFile)}.apiOptions`);
|
|
11826
11866
|
if (module2 !== void 0) {
|
|
11827
11867
|
return module2;
|
|
11828
11868
|
} else {
|
|
@@ -11830,7 +11870,9 @@ async function importHTMLModule(inFile, logger) {
|
|
|
11830
11870
|
}
|
|
11831
11871
|
}
|
|
11832
11872
|
async function importJSONModule(inFile, logger) {
|
|
11833
|
-
const module2 =
|
|
11873
|
+
const module2 = await importJSXFile(inFile, logger);
|
|
11874
|
+
parser2.parse(module2.default, JSONModuleSchema.properties.default, `${(0, import_node_path5.basename)(inFile)}.default`);
|
|
11875
|
+
parser2.parse(module2.apiOptions, APIOptionsSchema, `${(0, import_node_path5.basename)(inFile)}.apiOptions`);
|
|
11834
11876
|
if (module2 !== void 0) {
|
|
11835
11877
|
return module2;
|
|
11836
11878
|
} else {
|
|
@@ -13170,6 +13212,11 @@ async function watchAndServer(app) {
|
|
|
13170
13212
|
}
|
|
13171
13213
|
watchLogger?.info("watching for changes on [%s]", app.options.services.join(","));
|
|
13172
13214
|
reWatch();
|
|
13215
|
+
return {
|
|
13216
|
+
stopWatch: () => {
|
|
13217
|
+
stopWatch();
|
|
13218
|
+
}
|
|
13219
|
+
};
|
|
13173
13220
|
}
|
|
13174
13221
|
|
|
13175
13222
|
// src/common/exit.ts
|
|
@@ -13326,9 +13373,6 @@ async function inflateDBMigrations(logger, service, dbName, inflateDir, errors)
|
|
|
13326
13373
|
return false;
|
|
13327
13374
|
}
|
|
13328
13375
|
|
|
13329
|
-
// src/services/app.ts
|
|
13330
|
-
var import_node_util3 = require("node:util");
|
|
13331
|
-
|
|
13332
13376
|
// src/services/utils/server-interface.ts
|
|
13333
13377
|
var import_node_cluster2 = __toESM(require("node:cluster"), 1);
|
|
13334
13378
|
var import_node_child_process2 = require("node:child_process");
|
|
@@ -13425,9 +13469,114 @@ function getPORT() {
|
|
|
13425
13469
|
return checkEnvVariable("PORT", "8080");
|
|
13426
13470
|
}
|
|
13427
13471
|
|
|
13472
|
+
// src/services/utils/log-transport.ts
|
|
13473
|
+
var import_node_util3 = require("node:util");
|
|
13474
|
+
init_constants();
|
|
13475
|
+
function createLogProviderOptions(app) {
|
|
13476
|
+
const defaultConsole = ConsoleTransport();
|
|
13477
|
+
const defaultFile = FileTransport();
|
|
13478
|
+
const defaultWrite = async (args, level) => {
|
|
13479
|
+
try {
|
|
13480
|
+
const serviceNamesWithLogConfigReplaceConsole = level === void 0 && app.inflated ? Object.keys(app.inflated.logConfigMap).filter((serviceName) => app.inflated.logConfigMap[serviceName].replaceConsoleTransport) : [];
|
|
13481
|
+
const serviceNamesWithLogConfigReplaceFile = level === void 0 && app.inflated ? Object.keys(app.inflated.logConfigMap).filter((serviceName) => app.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
|
|
13482
|
+
await Promise.allSettled((level === void 0 ? [
|
|
13483
|
+
level === void 0 && serviceNamesWithLogConfigReplaceConsole.length === 0 ? defaultConsole.write(args) : Promise.resolve(),
|
|
13484
|
+
level === void 0 && serviceNamesWithLogConfigReplaceFile.length === 0 ? defaultFile.write(args) : Promise.resolve()
|
|
13485
|
+
] : []).concat(
|
|
13486
|
+
app.inflated ? Object.keys(app.inflated.logConfigMap).map((serviceName) => app.inflated.logConfigMap[serviceName]).filter((c) => c.level === level).map((c) => c.write(args)) : []
|
|
13487
|
+
));
|
|
13488
|
+
} catch (e) {
|
|
13489
|
+
console.error(e);
|
|
13490
|
+
}
|
|
13491
|
+
};
|
|
13492
|
+
return {
|
|
13493
|
+
name: app.options.name,
|
|
13494
|
+
formatter: (args) => {
|
|
13495
|
+
const params = args.optionalParams;
|
|
13496
|
+
return (0, import_node_util3.format)(
|
|
13497
|
+
`${(/* @__PURE__ */ new Date()).toISOString()} PID[${process.pid}] ${args.identifier ? `[${args.identifier}] ` : ""}${args.level !== "info" ? args.level === "error" || args.level === "warn" ? `[${args.level.toUpperCase()}] ` : `[${args.level}] ` : ""}${args.message}`,
|
|
13498
|
+
...params
|
|
13499
|
+
);
|
|
13500
|
+
},
|
|
13501
|
+
transports: [
|
|
13502
|
+
...[void 0, "error", "warn", "info", "debug", "trace"].map((level) => {
|
|
13503
|
+
return level ? {
|
|
13504
|
+
level,
|
|
13505
|
+
write: async (args) => {
|
|
13506
|
+
await defaultWrite(args, level);
|
|
13507
|
+
}
|
|
13508
|
+
} : {
|
|
13509
|
+
write: async (args) => {
|
|
13510
|
+
await defaultWrite(args, void 0);
|
|
13511
|
+
}
|
|
13512
|
+
};
|
|
13513
|
+
}),
|
|
13514
|
+
{
|
|
13515
|
+
level: "trace",
|
|
13516
|
+
write: async (args) => {
|
|
13517
|
+
try {
|
|
13518
|
+
if (app.options.editor) {
|
|
13519
|
+
try {
|
|
13520
|
+
const ws = app.webSocketManager.getWS(LOG_SOCKET_PATH);
|
|
13521
|
+
if (ws) {
|
|
13522
|
+
await ws.broadcast(JSON.stringify({
|
|
13523
|
+
type: LOG_WRITE_EVENT,
|
|
13524
|
+
level: args.level,
|
|
13525
|
+
identifier: args.identifier,
|
|
13526
|
+
out: args.out
|
|
13527
|
+
}));
|
|
13528
|
+
}
|
|
13529
|
+
} catch (e) {
|
|
13530
|
+
console.error(e);
|
|
13531
|
+
}
|
|
13532
|
+
}
|
|
13533
|
+
} catch (e) {
|
|
13534
|
+
console.error(e);
|
|
13535
|
+
}
|
|
13536
|
+
}
|
|
13537
|
+
}
|
|
13538
|
+
],
|
|
13539
|
+
...app.options.logProviderOptions ? app.options.logProviderOptions : {}
|
|
13540
|
+
};
|
|
13541
|
+
}
|
|
13542
|
+
|
|
13543
|
+
// src/services/utils/admin-interface.ts
|
|
13544
|
+
function createAdminInterface(app) {
|
|
13545
|
+
const adminCache = new ClusterCache("EditorCache[" + app.options.name + "]");
|
|
13546
|
+
return {
|
|
13547
|
+
getCache: () => adminCache,
|
|
13548
|
+
stop: () => app.stop(),
|
|
13549
|
+
restart: () => app.restart(),
|
|
13550
|
+
reload: () => app.reload(),
|
|
13551
|
+
getHotReloadHTML: getHotReloadScript,
|
|
13552
|
+
getMigrations: () => {
|
|
13553
|
+
if (app.inflated) {
|
|
13554
|
+
const ret = [];
|
|
13555
|
+
for (const db of app.inflated.dbList) {
|
|
13556
|
+
for (const m of db.migrations) {
|
|
13557
|
+
ret.push(m);
|
|
13558
|
+
}
|
|
13559
|
+
}
|
|
13560
|
+
return ret;
|
|
13561
|
+
}
|
|
13562
|
+
return [];
|
|
13563
|
+
},
|
|
13564
|
+
getServices: () => {
|
|
13565
|
+
return app.options.services;
|
|
13566
|
+
},
|
|
13567
|
+
getRouteFileMap: () => {
|
|
13568
|
+
return app.inflated ? app.inflated.fileMap : {};
|
|
13569
|
+
},
|
|
13570
|
+
getInflateErrors: () => {
|
|
13571
|
+
return app.inflated ? app.inflated.errors : [];
|
|
13572
|
+
}
|
|
13573
|
+
};
|
|
13574
|
+
}
|
|
13575
|
+
|
|
13428
13576
|
// src/services/app.ts
|
|
13429
13577
|
var MiqroApplicationMessageType = "$$$MiqroApplicationMessageType$$$";
|
|
13430
13578
|
var Miqro = class _Miqro {
|
|
13579
|
+
status = "stopped";
|
|
13431
13580
|
options;
|
|
13432
13581
|
server = null;
|
|
13433
13582
|
cache;
|
|
@@ -13442,6 +13591,7 @@ var Miqro = class _Miqro {
|
|
|
13442
13591
|
logger;
|
|
13443
13592
|
loggerProvider;
|
|
13444
13593
|
static initAssetsPromise = null;
|
|
13594
|
+
watcher;
|
|
13445
13595
|
constructor(options) {
|
|
13446
13596
|
this.options = {
|
|
13447
13597
|
editor: false,
|
|
@@ -13450,65 +13600,7 @@ var Miqro = class _Miqro {
|
|
|
13450
13600
|
services: [],
|
|
13451
13601
|
...options ? options : {}
|
|
13452
13602
|
};
|
|
13453
|
-
|
|
13454
|
-
const defaultFile = FileTransport();
|
|
13455
|
-
const defaultWrite = async (args, level) => {
|
|
13456
|
-
try {
|
|
13457
|
-
const serviceNamesWithLogConfigReplaceConsole = level === void 0 && this.inflated ? Object.keys(this.inflated.logConfigMap).filter((serviceName) => this.inflated.logConfigMap[serviceName].replaceConsoleTransport) : [];
|
|
13458
|
-
const serviceNamesWithLogConfigReplaceFile = level === void 0 && this.inflated ? Object.keys(this.inflated.logConfigMap).filter((serviceName) => this.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
|
|
13459
|
-
await Promise.allSettled((level === void 0 ? [
|
|
13460
|
-
level === void 0 && serviceNamesWithLogConfigReplaceConsole.length === 0 ? defaultConsole.write(args) : Promise.resolve(),
|
|
13461
|
-
level === void 0 && serviceNamesWithLogConfigReplaceFile.length === 0 ? defaultFile.write(args) : Promise.resolve()
|
|
13462
|
-
] : []).concat(
|
|
13463
|
-
this.inflated ? Object.keys(this.inflated.logConfigMap).map((serviceName) => this.inflated.logConfigMap[serviceName]).filter((c) => c.level === level).map((c) => c.write(args)) : []
|
|
13464
|
-
));
|
|
13465
|
-
} catch (e) {
|
|
13466
|
-
console.error(e);
|
|
13467
|
-
}
|
|
13468
|
-
};
|
|
13469
|
-
this.loggerProvider = new LogProvider({
|
|
13470
|
-
name: this.options.name,
|
|
13471
|
-
formatter: ({ identifier, level, message, optionalParams }) => (0, import_node_util3.format)(`${(/* @__PURE__ */ new Date()).toISOString()} PID[${process.pid}] ${identifier ? `[${identifier}] ` : ""}${level !== "info" ? level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] ` : ""}${message}`, ...optionalParams),
|
|
13472
|
-
transports: [
|
|
13473
|
-
...[void 0, "error", "warn", "info", "debug", "trace"].map((level) => {
|
|
13474
|
-
return level ? {
|
|
13475
|
-
level,
|
|
13476
|
-
write: async (args) => {
|
|
13477
|
-
await defaultWrite(args, level);
|
|
13478
|
-
}
|
|
13479
|
-
} : {
|
|
13480
|
-
write: async (args) => {
|
|
13481
|
-
await defaultWrite(args, void 0);
|
|
13482
|
-
}
|
|
13483
|
-
};
|
|
13484
|
-
}),
|
|
13485
|
-
{
|
|
13486
|
-
level: "trace",
|
|
13487
|
-
write: async (args) => {
|
|
13488
|
-
try {
|
|
13489
|
-
if (this.options.editor) {
|
|
13490
|
-
try {
|
|
13491
|
-
const ws = this.webSocketManager.getWS(LOG_SOCKET_PATH);
|
|
13492
|
-
if (ws) {
|
|
13493
|
-
await ws.broadcast(JSON.stringify({
|
|
13494
|
-
type: LOG_WRITE_EVENT,
|
|
13495
|
-
level: args.level,
|
|
13496
|
-
identifier: args.identifier,
|
|
13497
|
-
out: args.out
|
|
13498
|
-
}));
|
|
13499
|
-
}
|
|
13500
|
-
} catch (e) {
|
|
13501
|
-
console.error(e);
|
|
13502
|
-
}
|
|
13503
|
-
}
|
|
13504
|
-
} catch (e) {
|
|
13505
|
-
console.error(e);
|
|
13506
|
-
}
|
|
13507
|
-
}
|
|
13508
|
-
}
|
|
13509
|
-
],
|
|
13510
|
-
...this.options.logProviderOptions ? this.options.logProviderOptions : {}
|
|
13511
|
-
});
|
|
13603
|
+
this.loggerProvider = new LogProvider(createLogProviderOptions(this));
|
|
13512
13604
|
const SERVER_IDENTIFIER = import_node_cluster3.default.isPrimary ? "" : process.env["CLUSTER_NODE_NUMBER"] ? `WORKER_${process.env["CLUSTER_NODE_NUMBER"]}`.toUpperCase() : `WORKER`;
|
|
13513
13605
|
this.logger = this.options.logger ? this.options.logger : this.loggerProvider.getLogger(SERVER_IDENTIFIER);
|
|
13514
13606
|
this.listener = async (data) => {
|
|
@@ -13554,56 +13646,26 @@ var Miqro = class _Miqro {
|
|
|
13554
13646
|
port: this.options.port
|
|
13555
13647
|
});
|
|
13556
13648
|
this.serverRequestHandler = ServerRequestHandler(this.serverInterface);
|
|
13557
|
-
|
|
13558
|
-
this.adminInterface = {
|
|
13559
|
-
getCache: () => adminCache,
|
|
13560
|
-
stop: () => this.stop(),
|
|
13561
|
-
restart: () => this.restart(),
|
|
13562
|
-
reload: () => this.reload(),
|
|
13563
|
-
getHotReloadHTML: getHotReloadScript,
|
|
13564
|
-
getMigrations: () => {
|
|
13565
|
-
if (this.inflated) {
|
|
13566
|
-
const ret = [];
|
|
13567
|
-
for (const db of this.inflated.dbList) {
|
|
13568
|
-
for (const m of db.migrations) {
|
|
13569
|
-
ret.push(m);
|
|
13570
|
-
}
|
|
13571
|
-
}
|
|
13572
|
-
return ret;
|
|
13573
|
-
}
|
|
13574
|
-
return [];
|
|
13575
|
-
},
|
|
13576
|
-
getServices: () => {
|
|
13577
|
-
return this.options.services;
|
|
13578
|
-
},
|
|
13579
|
-
getRouteFileMap: () => {
|
|
13580
|
-
return this.inflated ? this.inflated.fileMap : {};
|
|
13581
|
-
},
|
|
13582
|
-
getInflateErrors: () => {
|
|
13583
|
-
return this.inflated ? this.inflated.errors : [];
|
|
13584
|
-
}
|
|
13585
|
-
/*,
|
|
13586
|
-
inflateJSX: async function inflateJSX(path, minify: boolean = true) {
|
|
13587
|
-
return realInflateJSX(path, {
|
|
13588
|
-
embemedJSX: true,
|
|
13589
|
-
minify,
|
|
13590
|
-
useExport: true
|
|
13591
|
-
});
|
|
13592
|
-
}*/
|
|
13593
|
-
};
|
|
13649
|
+
this.adminInterface = createAdminInterface(this);
|
|
13594
13650
|
setupExitHandlers(this);
|
|
13651
|
+
}
|
|
13652
|
+
connect() {
|
|
13595
13653
|
if (process.send) {
|
|
13654
|
+
process.removeListener("message", this.listener);
|
|
13596
13655
|
process.on("message", this.listener);
|
|
13597
13656
|
}
|
|
13657
|
+
this.cache.connect();
|
|
13658
|
+
this.adminInterface?.getCache()?.connect();
|
|
13598
13659
|
}
|
|
13599
|
-
|
|
13660
|
+
disconnect() {
|
|
13600
13661
|
if (this.server !== null) {
|
|
13601
13662
|
throw new Error("already running! call stop() first");
|
|
13602
13663
|
}
|
|
13603
13664
|
if (process.send) {
|
|
13604
13665
|
process.removeListener("message", this.listener);
|
|
13605
13666
|
}
|
|
13606
|
-
this.cache.
|
|
13667
|
+
this.cache.disconnect();
|
|
13668
|
+
this.adminInterface?.getCache()?.disconnect();
|
|
13607
13669
|
this.webSocketManager.disconnectAll();
|
|
13608
13670
|
this.dbManager.closeAll();
|
|
13609
13671
|
}
|
|
@@ -13773,14 +13835,17 @@ var Miqro = class _Miqro {
|
|
|
13773
13835
|
this.inflated = null;
|
|
13774
13836
|
}
|
|
13775
13837
|
async start() {
|
|
13776
|
-
if (this.server !== null) {
|
|
13838
|
+
if (this.server !== null || this.status !== "stopped") {
|
|
13777
13839
|
throw new Error("cannot start app already running.");
|
|
13778
13840
|
}
|
|
13779
13841
|
if (!this.isInflated()) {
|
|
13780
13842
|
throw new Error("cannot start uninflated app. call await app.inflate() first.");
|
|
13781
13843
|
}
|
|
13782
13844
|
this.logger?.debug(" ==start==");
|
|
13845
|
+
this.status = "starting";
|
|
13783
13846
|
this.server = void 0;
|
|
13847
|
+
this.connect();
|
|
13848
|
+
await this.dbManager.connectAll();
|
|
13784
13849
|
this.server = new App({
|
|
13785
13850
|
onUpgrade: (req, socket, head) => {
|
|
13786
13851
|
req.server = this.serverInterface;
|
|
@@ -13811,17 +13876,24 @@ var Miqro = class _Miqro {
|
|
|
13811
13876
|
}
|
|
13812
13877
|
await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "start");
|
|
13813
13878
|
if (this.options.hotreload && (import_node_cluster3.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
|
|
13814
|
-
await watchAndServer(this);
|
|
13879
|
+
this.watcher = await watchAndServer(this);
|
|
13815
13880
|
}
|
|
13816
13881
|
this.logger?.debug(" ==start done==");
|
|
13882
|
+
this.status = "started";
|
|
13817
13883
|
return this.inflated.errors && this.inflated.errors.length > 0 ? this.inflated.errors : null;
|
|
13818
13884
|
}
|
|
13819
13885
|
async stop() {
|
|
13820
|
-
if (!this.server || !this.inflated) {
|
|
13886
|
+
if (!this.server || !this.inflated || this.status !== "started") {
|
|
13821
13887
|
throw new Error("cannot stop server not running");
|
|
13822
13888
|
}
|
|
13889
|
+
this.status = "stopping";
|
|
13890
|
+
if (this.watcher) {
|
|
13891
|
+
this.watcher.stopWatch();
|
|
13892
|
+
this.watcher = null;
|
|
13893
|
+
}
|
|
13823
13894
|
const server2 = this.server;
|
|
13824
13895
|
this.server = null;
|
|
13896
|
+
this.disconnect();
|
|
13825
13897
|
this.logger?.debug(" ==stop==");
|
|
13826
13898
|
this.logger?.debug("clear running server routes");
|
|
13827
13899
|
server2.clear();
|
|
@@ -13831,13 +13903,14 @@ var Miqro = class _Miqro {
|
|
|
13831
13903
|
notifiyServerConfigSync(this, "unload");
|
|
13832
13904
|
this.logger?.debug("stopping");
|
|
13833
13905
|
const p = server2.close();
|
|
13834
|
-
notifiyServerConfigSync(this, "stop");
|
|
13835
13906
|
await p;
|
|
13836
13907
|
await pD;
|
|
13908
|
+
this.status = "stopped";
|
|
13909
|
+
notifiyServerConfigSync(this, "stop");
|
|
13837
13910
|
this.logger?.debug(" ==stop done==");
|
|
13838
13911
|
}
|
|
13839
13912
|
async restart(avoidSend) {
|
|
13840
|
-
if (!this.server || !this.inflated) {
|
|
13913
|
+
if (!this.server || !this.inflated || this.status !== "started") {
|
|
13841
13914
|
throw new Error("cannot start server not running");
|
|
13842
13915
|
}
|
|
13843
13916
|
this.logger?.debug(" ==restart==");
|
|
@@ -13855,9 +13928,10 @@ var Miqro = class _Miqro {
|
|
|
13855
13928
|
return ret;
|
|
13856
13929
|
}
|
|
13857
13930
|
async reload(avoidSend) {
|
|
13858
|
-
if (!this.server || !this.inflated) {
|
|
13931
|
+
if (!this.server || !this.inflated || this.status !== "started") {
|
|
13859
13932
|
throw new Error("cannot reload server not running");
|
|
13860
13933
|
}
|
|
13934
|
+
this.status = "reloading";
|
|
13861
13935
|
if (!avoidSend) {
|
|
13862
13936
|
this.logger?.debug(" ==reload==");
|
|
13863
13937
|
} else {
|
|
@@ -13900,6 +13974,7 @@ var Miqro = class _Miqro {
|
|
|
13900
13974
|
});
|
|
13901
13975
|
}
|
|
13902
13976
|
this.logger?.debug(" ==reload done==");
|
|
13977
|
+
this.status = "started";
|
|
13903
13978
|
return this.inflated.errors && this.inflated.errors.length > 0 ? this.inflated.errors : null;
|
|
13904
13979
|
}
|
|
13905
13980
|
};
|
|
@@ -7,7 +7,7 @@ export interface LogSocket {
|
|
|
7
7
|
setMaxLogSize: (val: number | "unlimited") => void;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function useLogSocket(): LogSocket {
|
|
10
|
+
export function useLogSocket(options: { disableLog?: boolean; }): LogSocket {
|
|
11
11
|
|
|
12
12
|
const [_, setmaxLogSize, getMaxlogsize] = jsx.useState<number | "unlimited">(1000000);
|
|
13
13
|
|
|
@@ -20,6 +20,9 @@ export function useLogSocket(): LogSocket {
|
|
|
20
20
|
|
|
21
21
|
function setupSocket() {
|
|
22
22
|
try {
|
|
23
|
+
if (options.disableLog) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
23
26
|
console.log("setting up log socket");
|
|
24
27
|
const socket = new WebSocket("/admin/socket");
|
|
25
28
|
socket.addEventListener("error", (err) => {
|
|
@@ -28,7 +28,10 @@ function InflateError2Map(errors: {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function Editor(props: { disablelog?: boolean; disablepreview?: boolean; disablereload?: boolean; migrations: string; services: string; reloadstring: string; files: string; initialcurrent: string; classname?: string; errors: string }) {
|
|
31
|
-
|
|
31
|
+
//console.dir(props);
|
|
32
|
+
const logSocket = useLogSocket({
|
|
33
|
+
disableLog: (props as any).disablelog === "true" || props.disablelog === true ? true : false
|
|
34
|
+
});
|
|
32
35
|
|
|
33
36
|
const [services, setservices] = jsx.useState<string[]>(JSON.parse(props.services));
|
|
34
37
|
const [collapsed, setCollapsed] = jsx.useState<{
|