miqro 7.0.9 → 7.1.0

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.
@@ -1,7 +1,7 @@
1
1
  import { chmodSync, constants, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { basename, dirname, extname, join, relative, resolve } from "node:path";
3
3
  import { cwd, platform } from "node:process";
4
- import { getAuthConfigPath, getCORSConfigPath, getDBConfigPath, getErrorConfigPath, getMiddlewareConfigPath, getMigrationsPath, getMiqroJSONPath, getServerConfigPath, getWSConfigPath } from "../common/paths.js";
4
+ import { getAuthConfigPath, getCORSConfigPath, getDBConfigPath, getErrorConfigPath, getLogConfigPath, getMiddlewareConfigPath, getMigrationsPath, getMiqroJSONPath, getServerConfigPath, getWSConfigPath } from "../common/paths.js";
5
5
  import { getAsset } from "../common/assets.js";
6
6
  import { migration } from "@miqro/query";
7
7
  import { esBuild } from "../common/esbuild.js";
@@ -38,10 +38,13 @@ export async function inflateAppForSea(logger, inflateDir, services, port) {
38
38
  inflateSeaAssets(logger, inflateDir);
39
39
  writeFile(logger, resolve(inflateDir, "sea", "lib.cjs"), Buffer.from(getAsset("lib.cjs")));
40
40
  const WSLIST = services.filter(service => getWSConfigPath(resolve(cwd(), service))).map(service => {
41
- return `(await require("../${service}/ws.cjs")).default`;
41
+ return `(await require("./../${service}/ws.cjs")).default`;
42
+ }).join(",");
43
+ const LOGCONFIGLIST = services.filter(service => getLogConfigPath(resolve(cwd(), service))).map(service => {
44
+ return `{config: (await require("./../${service}/log.cjs")).default, service: "${service}" }`;
42
45
  }).join(",");
43
46
  const SERVERCONFIGLIST = services.filter(service => getServerConfigPath(resolve(cwd(), service))).map(service => {
44
- return `(await require("../${service}/server.cjs")).default`;
47
+ return `(await require("./../${service}/server.cjs")).default`;
45
48
  }).join(",\n");
46
49
  const DBCONFIGLIST = services.filter(service => getDBConfigPath(resolve(cwd(), service))).map(service => {
47
50
  return `new Promise(async (resolve, reject) => {
@@ -56,21 +59,38 @@ export async function inflateAppForSea(logger, inflateDir, services, port) {
56
59
  })`;
57
60
  }).join(",");
58
61
  writeFile(logger, join(inflateDir, "sea", "package.json"), `{ "type": "module", "private": true }`);
59
- writeFile(logger, join(inflateDir, "sea", "app.cjs"), `const { createServerInterface, ServerRequestHandler, WebSocketManager, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
62
+ writeFile(logger, join(inflateDir, "sea", "app.cjs"), `const { createLogProviderOptions, createServerInterface, ServerRequestHandler, WebSocketManager, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
60
63
 
61
64
  async function main() {
62
- const PORT = "${PORT}";
63
- const loggerProvider = new LogProvider();
65
+ const PORT = "${PORT}";
66
+
67
+ const logConfigList = await Promise.all([${LOGCONFIGLIST}]);
68
+
69
+ const loggerProvider = new LogProvider(createLogProviderOptions({
70
+ inflated: {
71
+ logConfigMap: logConfigList.reduce((ret, config)=>{
72
+ ret[config.service] = config.config;
73
+ return ret;
74
+ }, {})
75
+ }
76
+ }));
77
+ const logger = loggerProvider.getLogger("SERVER");
64
78
  const localCache = new LocalCache();
65
79
  const cache = new ClusterCache();
66
- const webSocketManager = new WebSocketManager();
67
- const dbManager = new DBManager();
80
+ const webSocketManager = new WebSocketManager({
81
+ loggerProvider,
82
+ logger
83
+ });
84
+ const dbManager = new DBManager({
85
+ loggerProvider,
86
+ logger
87
+ });
68
88
  const serverInterface = createServerInterface({
69
89
  cache,
70
90
  localCache,
71
91
  loggerProvider,
72
92
  webSocketManager,
73
- logger: loggerProvider.getLogger("server"),
93
+ logger,
74
94
  dbManager,
75
95
  port: PORT
76
96
  });
@@ -81,6 +101,7 @@ async function main() {
81
101
 
82
102
  ${!WSLIST ? "" : `\n webSocketManager.replaceALLWS(await Promise.all([${WSLIST}]))`}
83
103
  const app = new App({
104
+ loggerFactory: loggerProvider.requestLoggerFactory,
84
105
  onUpgrade: (req, socket, head) => {
85
106
  try {
86
107
  req.server = serverInterface;
@@ -120,20 +141,20 @@ main().catch(e=>console.error(e));
120
141
  export async function inflateServiceForSea(logger, inflateDir, service, servicePath /*, serviceMigrations: string[]*/, serviceRouteFileMap, serviceStaticFileMap) {
121
142
  const migrationsFolderPath = getMigrationsPath(servicePath);
122
143
  const serviceMigrations = migrationsFolderPath ? migration.getSortedMigrations(migrationsFolderPath) : [];
123
- writeFile(logger, join(inflateDir, "sea", service, "router.cjs"), `const { appendAPIModule, Router, middleware } = require("./../lib.cjs");\n
144
+ writeFile(logger, join(inflateDir, "sea", service, "router.cjs"), `const { appendAPIModule, Router, middleware } = require("./${relative(service, "")}/lib.cjs");\n
124
145
  async function setupRouter() {
125
146
  const router = new Router();
126
147
  ${getErrorConfigPath(servicePath) ? `
127
- const errorConfig = (await require("../../${service}/catch.cjs")).default;
148
+ const errorConfig = (await require("../${relative(service, "")}/${service}/catch.cjs")).default;
128
149
  if(errorConfig && errorConfig.catch) {
129
150
  for(const m of errorConfig.catch) {
130
151
  router.catch(m);
131
152
  }
132
153
  }` : ""}
133
- ${getCORSConfigPath(servicePath) ? ` router.use(middleware.cors((await require("../../${service}/cors.cjs")).default));` : ""}
134
- ${getAuthConfigPath(servicePath) ? ` router.use(middleware.session((await require("../../${service}/auth.cjs")).default));` : ""}
154
+ ${getCORSConfigPath(servicePath) ? ` router.use(middleware.cors((await require("../${relative(service, "")}/${service}/cors.cjs")).default));` : ""}
155
+ ${getAuthConfigPath(servicePath) ? ` router.use(middleware.session((await require("../${relative(service, "")}/${service}/auth.cjs")).default));` : ""}
135
156
  ${getMiddlewareConfigPath(servicePath) ? `
136
- const middlewareConfig = (await require("../../${service}/middleware.cjs")).default;
157
+ const middlewareConfig = (await require("../${relative(service, "")}/${service}/middleware.cjs")).default;
137
158
  if(middlewareConfig && middlewareConfig.middleware) {
138
159
  for(const m of middlewareConfig.middleware) {
139
160
  router.use(m);
@@ -146,8 +167,8 @@ ${Object.keys(serviceRouteFileMap)
146
167
  const rPath = join(relative(cwd(), dirname(data.filePath)), basename(data.filePath));
147
168
  if (rPath) {
148
169
  const rPathExt = extname(rPath);
149
- const apiInflatedPath = join("..", "..", rPath.substring(0, rPath.length - rPathExt.length) + ".cjs");
150
- return ` await appendAPIModule(router, "../../${service}/http", "./${apiInflatedPath}", (await require("./${apiInflatedPath}")).default);`;
170
+ const apiInflatedPath = join("..", relative(service, ""), rPath.substring(0, rPath.length - rPathExt.length) + ".cjs");
171
+ return ` await appendAPIModule(router, "../${relative(service, "")}/${service}/http", "./${apiInflatedPath}", (await require("./${apiInflatedPath}")).default);`;
151
172
  }
152
173
  else {
153
174
  return "";
@@ -168,23 +189,23 @@ ${getMiddlewareConfigPath(servicePath) ? `
168
189
  module.exports = {
169
190
  setupRouter
170
191
  }`);
171
- writeFile(logger, join(inflateDir, "sea", service, "migration-up.cjs"), `const { migration } = require("./../lib.cjs");\n
192
+ writeFile(logger, join(inflateDir, "sea", service, "migration-up.cjs"), `const { migration } = require("./${relative(service, "")}/lib.cjs");\n
172
193
  async function runMigrations(db) {
173
194
  await migration.init(db);
174
195
  ${serviceMigrations.map(file => {
175
196
  const name = `${file.substring(0, file.length - extname(file).length)}`;
176
- return ` await migration.up.module(db, "${file}", (await require("../../${service}/migration/${name}.cjs")).default)`;
197
+ return ` await migration.up.module(db, "${file}", (await require("../${relative(service, "")}/${service}/migration/${name}.cjs")).default)`;
177
198
  }).join("\n")}
178
199
  }
179
200
  module.exports = {
180
201
  runMigrations
181
202
  }`);
182
- writeFile(logger, join(inflateDir, "sea", service, "migration-down.cjs"), `const { migration } = require("./../lib.cjs");\n
203
+ writeFile(logger, join(inflateDir, "sea", service, "migration-down.cjs"), `const { migration } = require("./${relative(service, "")}/lib.cjs");\n
183
204
  async function runMigrations(db) {
184
205
  await migration.init(db);
185
206
  ${serviceMigrations.reverse().map(file => {
186
207
  const name = `${file.substring(0, file.length - extname(file).length)}`;
187
- return ` await migration.down.module(db, "${file}", (await require("../../${service}/migration/${name}.cjs")).default)`;
208
+ return ` await migration.down.module(db, "${file}", (await require("../${relative(service, "")}/${service}/migration/${name}.cjs")).default)`;
188
209
  }).join("\n")}
189
210
  }
190
211
  module.exports = {
@@ -194,7 +215,7 @@ module.exports = {
194
215
  /*if (staticFiles.length !== 0) {
195
216
  writeFile(logger, join(inflateDir, "sea", service, "static.base64.json"), JSON.stringify(serviceStaticFileMap));
196
217
  }*/
197
- writeFile(logger, join(inflateDir, "sea", service, "static-router.cjs"), `const { appendAPIModule, Router } = require("./../lib.cjs");\n
218
+ writeFile(logger, join(inflateDir, "sea", service, "static-router.cjs"), `const { appendAPIModule, Router } = require("./${relative(service, "")}/lib.cjs");\n
198
219
  async function setupRouter() {
199
220
  const router = new Router();
200
221
  ${staticFiles.length === 0 ? "" : `
@@ -8,6 +8,7 @@ export { DBManager } from "./services/utils/db-manager.js";
8
8
  export { LogProvider, LogProviderOptions } from "./services/utils/log.js";
9
9
  export { Miqro, MiqroOptions, ServerRequestHandler } from "./services/app.js";
10
10
  export { jsx2HTML } from "./common/jsx.js";
11
+ export { createLogProviderOptions } from "./services/utils/log-transport.js";
11
12
  export { appendAPIModule } from "./inflate/utils/sea-utils.js";
12
13
  export { createServerInterface, ServerInterfaceImplOptions } from "./services/utils/server-interface.js";
13
14
  export { App, LoggerHandler, Router } from "@miqro/core";
@@ -13,6 +13,7 @@ export { Miqro, ServerRequestHandler } from "./services/app.js";
13
13
  // export { initGlobals, assertGlobalTampered } from "./services/globals.js";
14
14
  export { jsx2HTML } from "./common/jsx.js";
15
15
  //exported for --inflate-sea
16
+ export { createLogProviderOptions } from "./services/utils/log-transport.js";
16
17
  export { appendAPIModule } from "./inflate/utils/sea-utils.js";
17
18
  export { createServerInterface } from "./services/utils/server-interface.js";
18
19
  export { App, LoggerHandler, Router } from "@miqro/core";
@@ -5,7 +5,7 @@ import { WebSocketManager } from "./utils/websocketmanager.js";
5
5
  import { DBManager } from "./utils/db-manager.js";
6
6
  import { inflateApp } from "../inflate/inflate.js";
7
7
  import { setupServerConfig } from "../inflate/setup-server-config.js";
8
- import { BASEEDITOR_PATH, LOG_SOCKET_PATH } from "../../editor/common/constants.js";
8
+ import { BASEEDITOR_PATH, LOG_SOCKET_PATH, LOG_WRITE_EVENT } from "../../editor/common/constants.js";
9
9
  import editorWSConfig from "../../editor/ws.js";
10
10
  import editorServerConfig from "../../editor/server.js";
11
11
  import { ClusterCache } from "./utils/cluster-cache.js";
@@ -51,7 +51,9 @@ export class Miqro {
51
51
  services: [],
52
52
  ...(options ? options : {})
53
53
  };
54
- this.loggerProvider = new LogProvider(createLogProviderOptions(this));
54
+ const loggerOptions = createLogProviderOptions(this);
55
+ loggerOptions.transports.push(createEditorLoggerTransport(this));
56
+ this.loggerProvider = new LogProvider(loggerOptions);
55
57
  //if (!this.options.logger) {
56
58
  const SERVER_IDENTIFIER = cluster.isPrimary ?
57
59
  "" :
@@ -588,3 +590,32 @@ export function notifiyServerConfigSync(app, method) {
588
590
  });
589
591
  }
590
592
  }
593
+ function createEditorLoggerTransport(app) {
594
+ return {
595
+ level: "trace",
596
+ write: async (args) => {
597
+ try {
598
+ if (app.options.editor) {
599
+ try {
600
+ const ws = app.webSocketManager.getWS(LOG_SOCKET_PATH);
601
+ if (ws) {
602
+ //console.log("\n\n" + process.pid + " broadcasting " + LOG_SOCKET_PATH + "\n\n\n")
603
+ await ws.broadcast(JSON.stringify({
604
+ type: LOG_WRITE_EVENT,
605
+ level: args.level,
606
+ identifier: args.identifier,
607
+ out: args.out
608
+ }));
609
+ }
610
+ }
611
+ catch (e) {
612
+ console.error(e);
613
+ }
614
+ }
615
+ }
616
+ catch (e) {
617
+ console.error(e);
618
+ }
619
+ }
620
+ };
621
+ }
@@ -1,6 +1,18 @@
1
1
  import { LoggerTransport, WriteArgs } from "@miqro/core";
2
- import { Miqro } from "../app.js";
3
- export declare function createLogProviderOptions(app: Miqro): {
2
+ import { LogConfigMap } from "../../inflate/setup-log.js";
3
+ import { LogProviderOptions } from "./log.js";
4
+ export declare function createLogProviderOptions(app?: {
5
+ options?: {
6
+ dateTimeFormatOptions?: Intl.DateTimeFormatOptions;
7
+ logProviderOptions?: LogProviderOptions;
8
+ name?: string;
9
+ editor?: boolean;
10
+ logFile?: string | boolean;
11
+ };
12
+ inflated?: {
13
+ logConfigMap: LogConfigMap;
14
+ };
15
+ }): {
4
16
  name: string;
5
17
  transports: LoggerTransport[];
6
18
  formatter: (args: WriteArgs) => string;
@@ -1,38 +1,46 @@
1
1
  import { ConsoleTransport, FileTransport } from "@miqro/core";
2
2
  import { format } from "node:util";
3
- import { LOG_SOCKET_PATH, LOG_WRITE_EVENT } from "../../../editor/common/constants.js";
4
3
  export function createLogProviderOptions(app) {
5
4
  const defaultConsole = ConsoleTransport();
6
5
  //console.log("app.options.logFile [%s]", app.options.logFile);
7
- const defaultFile = app.options.logFile !== true && app.options.logFile !== false && String(app.options.logFile).toUpperCase() !== "TRUE" && String(app.options.logFile).toUpperCase() !== "FALSE" &&
6
+ const defaultFile = app && app.options && app?.options?.logFile !== true && app?.options?.logFile !== false && String(app?.options?.logFile).toUpperCase() !== "TRUE" && String(app?.options?.logFile).toUpperCase() !== "FALSE" &&
8
7
  app.options.logFile ? FileTransport(app.options.logFile) :
9
- String(app.options.logFile).toUpperCase() === "TRUE" || app.options.logFile === true || app.options.logFile === undefined ?
8
+ app && app.options && String(app?.options?.logFile).toUpperCase() === "TRUE" || app?.options?.logFile === true || app?.options?.logFile === undefined ?
10
9
  FileTransport() :
11
10
  undefined;
12
11
  const defaultWrite = async (args, level) => {
13
12
  try {
14
- const serviceNamesWithLogConfigReplaceConsole = level === undefined && app.inflated ?
15
- Object.keys(app.inflated.logConfigMap).filter(serviceName => app.inflated.logConfigMap[serviceName].replaceConsoleTransport) : [];
16
- const serviceNamesWithLogConfigReplaceFile = level === undefined && app.inflated ?
17
- Object.keys(app.inflated.logConfigMap).filter(serviceName => app.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
13
+ // console.dir(app.inflated);
14
+ const serviceNamesWithLogConfigReplaceConsole = app?.inflated ?
15
+ Object.keys(app?.inflated?.logConfigMap).filter(serviceName => app?.inflated?.logConfigMap[serviceName].replaceConsoleTransport) : [];
16
+ const serviceNamesWithLogConfigReplaceFile = app?.inflated ?
17
+ Object.keys(app?.inflated?.logConfigMap).filter(serviceName => app?.inflated?.logConfigMap[serviceName].replaceFileTransport) : [];
18
+ // console.dir(level);
19
+ // console.dir(app?.inflated?.logConfigMap["m-admin"])
20
+ // console.dir(serviceNamesWithLogConfigReplaceConsole.length);
21
+ // console.dir(serviceNamesWithLogConfigReplaceFile.length);
18
22
  await Promise.allSettled((level === undefined ?
19
23
  [
20
24
  level === undefined && serviceNamesWithLogConfigReplaceConsole.length === 0 && defaultConsole ?
21
25
  defaultConsole.write(args) : Promise.resolve(),
22
26
  level === undefined && serviceNamesWithLogConfigReplaceFile.length === 0 && defaultFile ?
23
27
  defaultFile.write(args) : Promise.resolve()
24
- ] : []).concat(app.inflated ?
25
- Object.keys(app.inflated.logConfigMap).map(serviceName => app.inflated.logConfigMap[serviceName]).filter(c => c.level === level).map(c => c.write(args)) : []));
28
+ ] : []).concat(app && app.inflated && app?.inflated ?
29
+ Object.keys(app?.inflated?.logConfigMap).map(serviceName => app?.inflated?.logConfigMap[serviceName]).filter(c => c.level === level).map(c => c.write(args)) : []));
26
30
  }
27
31
  catch (e) {
28
32
  console.error(e);
29
33
  }
30
34
  };
31
35
  return {
32
- name: app.options.name,
36
+ name: app?.options?.name,
33
37
  formatter: (args) => {
34
38
  const params = args.optionalParams;
35
- return format(`${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}`, ...params);
39
+ return format(`${new Date().toLocaleDateString(undefined, app?.options?.dateTimeFormatOptions ? app?.options?.dateTimeFormatOptions : {
40
+ hour12: false
41
+ })} ${new Date().toLocaleTimeString(undefined, app?.options?.dateTimeFormatOptions ? app?.options?.dateTimeFormatOptions : {
42
+ hour12: false
43
+ })} PID[${process.pid}] ${args.identifier ? `[${args.identifier}] ` : ""}${args.level !== "info" ? (args.level === "error" || args.level === "warn" ? `[${args.level.toUpperCase()}] ` : `[${args.level}] `) : ""}${args.message}`, ...params);
36
44
  },
37
45
  transports: [
38
46
  ...([undefined, "error", "warn", "info", "debug", "trace"].map(level => {
@@ -46,34 +54,8 @@ export function createLogProviderOptions(app) {
46
54
  await defaultWrite(args, undefined);
47
55
  }
48
56
  };
49
- })), {
50
- level: "trace",
51
- write: async (args) => {
52
- try {
53
- if (app.options.editor) {
54
- try {
55
- const ws = app.webSocketManager.getWS(LOG_SOCKET_PATH);
56
- if (ws) {
57
- //console.log("\n\n" + process.pid + " broadcasting " + LOG_SOCKET_PATH + "\n\n\n")
58
- await ws.broadcast(JSON.stringify({
59
- type: LOG_WRITE_EVENT,
60
- level: args.level,
61
- identifier: args.identifier,
62
- out: args.out
63
- }));
64
- }
65
- }
66
- catch (e) {
67
- console.error(e);
68
- }
69
- }
70
- }
71
- catch (e) {
72
- console.error(e);
73
- }
74
- }
75
- }
57
+ }))
76
58
  ],
77
- ...(app.options.logProviderOptions ? app.options.logProviderOptions : {})
59
+ ...(app?.options?.logProviderOptions ? app?.options?.logProviderOptions : {})
78
60
  };
79
61
  }
package/build/lib.cjs CHANGED
@@ -7133,6 +7133,7 @@ __export(lib_exports3, {
7133
7133
  ServerRequestHandler: () => ServerRequestHandler,
7134
7134
  WebSocketManager: () => WebSocketManager,
7135
7135
  appendAPIModule: () => appendAPIModule,
7136
+ createLogProviderOptions: () => createLogProviderOptions,
7136
7137
  createServerInterface: () => createServerInterface,
7137
7138
  jsx: () => lib_exports,
7138
7139
  jsx2HTML: () => jsx2HTML,
@@ -13051,10 +13052,13 @@ async function inflateAppForSea(logger, inflateDir, services, port) {
13051
13052
  inflateSeaAssets(logger, inflateDir);
13052
13053
  writeFile2(logger, (0, import_node_path14.resolve)(inflateDir, "sea", "lib.cjs"), Buffer.from(getAsset("lib.cjs")));
13053
13054
  const WSLIST = services.filter((service) => getWSConfigPath((0, import_node_path14.resolve)((0, import_node_process10.cwd)(), service))).map((service) => {
13054
- return `(await require("../${service}/ws.cjs")).default`;
13055
+ return `(await require("./../${service}/ws.cjs")).default`;
13056
+ }).join(",");
13057
+ const LOGCONFIGLIST = services.filter((service) => getLogConfigPath((0, import_node_path14.resolve)((0, import_node_process10.cwd)(), service))).map((service) => {
13058
+ return `{config: (await require("./../${service}/log.cjs")).default, service: "${service}" }`;
13055
13059
  }).join(",");
13056
13060
  const SERVERCONFIGLIST = services.filter((service) => getServerConfigPath((0, import_node_path14.resolve)((0, import_node_process10.cwd)(), service))).map((service) => {
13057
- return `(await require("../${service}/server.cjs")).default`;
13061
+ return `(await require("./../${service}/server.cjs")).default`;
13058
13062
  }).join(",\n");
13059
13063
  const DBCONFIGLIST = services.filter((service) => getDBConfigPath((0, import_node_path14.resolve)((0, import_node_process10.cwd)(), service))).map((service) => {
13060
13064
  return `new Promise(async (resolve, reject) => {
@@ -13072,21 +13076,38 @@ async function inflateAppForSea(logger, inflateDir, services, port) {
13072
13076
  writeFile2(
13073
13077
  logger,
13074
13078
  (0, import_node_path14.join)(inflateDir, "sea", "app.cjs"),
13075
- `const { createServerInterface, ServerRequestHandler, WebSocketManager, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
13079
+ `const { createLogProviderOptions, createServerInterface, ServerRequestHandler, WebSocketManager, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
13076
13080
 
13077
13081
  async function main() {
13078
- const PORT = "${PORT2}";
13079
- const loggerProvider = new LogProvider();
13082
+ const PORT = "${PORT2}";
13083
+
13084
+ const logConfigList = await Promise.all([${LOGCONFIGLIST}]);
13085
+
13086
+ const loggerProvider = new LogProvider(createLogProviderOptions({
13087
+ inflated: {
13088
+ logConfigMap: logConfigList.reduce((ret, config)=>{
13089
+ ret[config.service] = config.config;
13090
+ return ret;
13091
+ }, {})
13092
+ }
13093
+ }));
13094
+ const logger = loggerProvider.getLogger("SERVER");
13080
13095
  const localCache = new LocalCache();
13081
13096
  const cache = new ClusterCache();
13082
- const webSocketManager = new WebSocketManager();
13083
- const dbManager = new DBManager();
13097
+ const webSocketManager = new WebSocketManager({
13098
+ loggerProvider,
13099
+ logger
13100
+ });
13101
+ const dbManager = new DBManager({
13102
+ loggerProvider,
13103
+ logger
13104
+ });
13084
13105
  const serverInterface = createServerInterface({
13085
13106
  cache,
13086
13107
  localCache,
13087
13108
  loggerProvider,
13088
13109
  webSocketManager,
13089
- logger: loggerProvider.getLogger("server"),
13110
+ logger,
13090
13111
  dbManager,
13091
13112
  port: PORT
13092
13113
  });
@@ -13100,6 +13121,7 @@ async function main() {
13100
13121
  ${!WSLIST ? "" : `
13101
13122
  webSocketManager.replaceALLWS(await Promise.all([${WSLIST}]))`}
13102
13123
  const app = new App({
13124
+ loggerFactory: loggerProvider.requestLoggerFactory,
13103
13125
  onUpgrade: (req, socket, head) => {
13104
13126
  try {
13105
13127
  req.server = serverInterface;
@@ -13143,21 +13165,21 @@ main().catch(e=>console.error(e));
13143
13165
  async function inflateServiceForSea(logger, inflateDir, service, servicePath, serviceRouteFileMap, serviceStaticFileMap) {
13144
13166
  const migrationsFolderPath = getMigrationsPath(servicePath);
13145
13167
  const serviceMigrations = migrationsFolderPath ? lib_exports2.getSortedMigrations(migrationsFolderPath) : [];
13146
- writeFile2(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "router.cjs"), `const { appendAPIModule, Router, middleware } = require("./../lib.cjs");
13168
+ writeFile2(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "router.cjs"), `const { appendAPIModule, Router, middleware } = require("./${(0, import_node_path14.relative)(service, "")}/lib.cjs");
13147
13169
 
13148
13170
  async function setupRouter() {
13149
13171
  const router = new Router();
13150
13172
  ${getErrorConfigPath(servicePath) ? `
13151
- const errorConfig = (await require("../../${service}/catch.cjs")).default;
13173
+ const errorConfig = (await require("../${(0, import_node_path14.relative)(service, "")}/${service}/catch.cjs")).default;
13152
13174
  if(errorConfig && errorConfig.catch) {
13153
13175
  for(const m of errorConfig.catch) {
13154
13176
  router.catch(m);
13155
13177
  }
13156
13178
  }` : ""}
13157
- ${getCORSConfigPath(servicePath) ? ` router.use(middleware.cors((await require("../../${service}/cors.cjs")).default));` : ""}
13158
- ${getAuthConfigPath(servicePath) ? ` router.use(middleware.session((await require("../../${service}/auth.cjs")).default));` : ""}
13179
+ ${getCORSConfigPath(servicePath) ? ` router.use(middleware.cors((await require("../${(0, import_node_path14.relative)(service, "")}/${service}/cors.cjs")).default));` : ""}
13180
+ ${getAuthConfigPath(servicePath) ? ` router.use(middleware.session((await require("../${(0, import_node_path14.relative)(service, "")}/${service}/auth.cjs")).default));` : ""}
13159
13181
  ${getMiddlewareConfigPath(servicePath) ? `
13160
- const middlewareConfig = (await require("../../${service}/middleware.cjs")).default;
13182
+ const middlewareConfig = (await require("../${(0, import_node_path14.relative)(service, "")}/${service}/middleware.cjs")).default;
13161
13183
  if(middlewareConfig && middlewareConfig.middleware) {
13162
13184
  for(const m of middlewareConfig.middleware) {
13163
13185
  router.use(m);
@@ -13167,8 +13189,8 @@ ${Object.keys(serviceRouteFileMap).map((filePath) => serviceRouteFileMap[filePat
13167
13189
  const rPath = (0, import_node_path14.join)((0, import_node_path14.relative)((0, import_node_process10.cwd)(), (0, import_node_path14.dirname)(data.filePath)), (0, import_node_path14.basename)(data.filePath));
13168
13190
  if (rPath) {
13169
13191
  const rPathExt = (0, import_node_path14.extname)(rPath);
13170
- const apiInflatedPath = (0, import_node_path14.join)("..", "..", rPath.substring(0, rPath.length - rPathExt.length) + ".cjs");
13171
- return ` await appendAPIModule(router, "../../${service}/http", "./${apiInflatedPath}", (await require("./${apiInflatedPath}")).default);`;
13192
+ const apiInflatedPath = (0, import_node_path14.join)("..", (0, import_node_path14.relative)(service, ""), rPath.substring(0, rPath.length - rPathExt.length) + ".cjs");
13193
+ return ` await appendAPIModule(router, "../${(0, import_node_path14.relative)(service, "")}/${service}/http", "./${apiInflatedPath}", (await require("./${apiInflatedPath}")).default);`;
13172
13194
  } else {
13173
13195
  return "";
13174
13196
  }
@@ -13187,32 +13209,32 @@ ${getMiddlewareConfigPath(servicePath) ? `
13187
13209
  module.exports = {
13188
13210
  setupRouter
13189
13211
  }`);
13190
- writeFile2(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "migration-up.cjs"), `const { migration } = require("./../lib.cjs");
13212
+ writeFile2(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "migration-up.cjs"), `const { migration } = require("./${(0, import_node_path14.relative)(service, "")}/lib.cjs");
13191
13213
 
13192
13214
  async function runMigrations(db) {
13193
13215
  await migration.init(db);
13194
13216
  ${serviceMigrations.map((file) => {
13195
13217
  const name = `${file.substring(0, file.length - (0, import_node_path14.extname)(file).length)}`;
13196
- return ` await migration.up.module(db, "${file}", (await require("../../${service}/migration/${name}.cjs")).default)`;
13218
+ return ` await migration.up.module(db, "${file}", (await require("../${(0, import_node_path14.relative)(service, "")}/${service}/migration/${name}.cjs")).default)`;
13197
13219
  }).join("\n")}
13198
13220
  }
13199
13221
  module.exports = {
13200
13222
  runMigrations
13201
13223
  }`);
13202
- writeFile2(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "migration-down.cjs"), `const { migration } = require("./../lib.cjs");
13224
+ writeFile2(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "migration-down.cjs"), `const { migration } = require("./${(0, import_node_path14.relative)(service, "")}/lib.cjs");
13203
13225
 
13204
13226
  async function runMigrations(db) {
13205
13227
  await migration.init(db);
13206
13228
  ${serviceMigrations.reverse().map((file) => {
13207
13229
  const name = `${file.substring(0, file.length - (0, import_node_path14.extname)(file).length)}`;
13208
- return ` await migration.down.module(db, "${file}", (await require("../../${service}/migration/${name}.cjs")).default)`;
13230
+ return ` await migration.down.module(db, "${file}", (await require("../${(0, import_node_path14.relative)(service, "")}/${service}/migration/${name}.cjs")).default)`;
13209
13231
  }).join("\n")}
13210
13232
  }
13211
13233
  module.exports = {
13212
13234
  runMigrations
13213
13235
  }`);
13214
13236
  const staticFiles = Object.keys(serviceStaticFileMap);
13215
- writeFile2(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "static-router.cjs"), `const { appendAPIModule, Router } = require("./../lib.cjs");
13237
+ writeFile2(logger, (0, import_node_path14.join)(inflateDir, "sea", service, "static-router.cjs"), `const { appendAPIModule, Router } = require("./${(0, import_node_path14.relative)(service, "")}/lib.cjs");
13216
13238
 
13217
13239
  async function setupRouter() {
13218
13240
  const router = new Router();
@@ -14366,6 +14388,13 @@ function checkSigCryptoKey(key, alg, usage2) {
14366
14388
  throw unusable("Ed25519");
14367
14389
  break;
14368
14390
  }
14391
+ case "ML-DSA-44":
14392
+ case "ML-DSA-65":
14393
+ case "ML-DSA-87": {
14394
+ if (!isAlgorithm(key.algorithm, alg))
14395
+ throw unusable(alg);
14396
+ break;
14397
+ }
14369
14398
  case "ES256":
14370
14399
  case "ES384":
14371
14400
  case "ES512": {
@@ -14659,33 +14688,41 @@ var digest_default = async (algorithm, data) => {
14659
14688
  function lengthAndInput(input) {
14660
14689
  return concat(uint32be(input.length), input);
14661
14690
  }
14662
- async function concatKdf(secret, bits, value) {
14663
- const iterations = Math.ceil((bits >> 3) / 32);
14664
- const res = new Uint8Array(iterations * 32);
14665
- for (let iter = 0; iter < iterations; iter++) {
14666
- const buf = new Uint8Array(4 + secret.length + value.length);
14667
- buf.set(uint32be(iter + 1));
14668
- buf.set(secret, 4);
14669
- buf.set(value, 4 + secret.length);
14670
- res.set(await digest_default("sha256", buf), iter * 32);
14671
- }
14672
- return res.slice(0, bits >> 3);
14691
+ async function concatKdf(Z, L, OtherInfo) {
14692
+ const dkLen = L >> 3;
14693
+ const hashLen = 32;
14694
+ const reps = Math.ceil(dkLen / hashLen);
14695
+ const dk = new Uint8Array(reps * hashLen);
14696
+ for (let i = 1; i <= reps; i++) {
14697
+ const hashInput = new Uint8Array(4 + Z.length + OtherInfo.length);
14698
+ hashInput.set(uint32be(i), 0);
14699
+ hashInput.set(Z, 4);
14700
+ hashInput.set(OtherInfo, 4 + Z.length);
14701
+ const hashResult = await digest_default("sha256", hashInput);
14702
+ dk.set(hashResult, (i - 1) * hashLen);
14703
+ }
14704
+ return dk.slice(0, dkLen);
14673
14705
  }
14674
14706
  async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) {
14675
14707
  checkEncCryptoKey(publicKey, "ECDH");
14676
14708
  checkEncCryptoKey(privateKey, "ECDH", "deriveBits");
14677
- const value = concat(lengthAndInput(encoder.encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));
14678
- let length;
14679
- if (publicKey.algorithm.name === "X25519") {
14680
- length = 256;
14681
- } else {
14682
- length = Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3;
14683
- }
14684
- const sharedSecret = new Uint8Array(await crypto.subtle.deriveBits({
14709
+ const algorithmID = lengthAndInput(encoder.encode(algorithm));
14710
+ const partyUInfo = lengthAndInput(apu);
14711
+ const partyVInfo = lengthAndInput(apv);
14712
+ const suppPubInfo = uint32be(keyLength);
14713
+ const suppPrivInfo = new Uint8Array(0);
14714
+ const otherInfo = concat(algorithmID, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo);
14715
+ const Z = new Uint8Array(await crypto.subtle.deriveBits({
14685
14716
  name: publicKey.algorithm.name,
14686
14717
  public: publicKey
14687
- }, privateKey, length));
14688
- return concatKdf(sharedSecret, keyLength, value);
14718
+ }, privateKey, getEcdhBitLength(publicKey)));
14719
+ return concatKdf(Z, keyLength, otherInfo);
14720
+ }
14721
+ function getEcdhBitLength(publicKey) {
14722
+ if (publicKey.algorithm.name === "X25519") {
14723
+ return 256;
14724
+ }
14725
+ return Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3;
14689
14726
  }
14690
14727
  function allowed(key) {
14691
14728
  switch (key.algorithm.namedCurve) {
@@ -14790,6 +14827,19 @@ function subtleMapping(jwk) {
14790
14827
  let algorithm;
14791
14828
  let keyUsages;
14792
14829
  switch (jwk.kty) {
14830
+ case "AKP": {
14831
+ switch (jwk.alg) {
14832
+ case "ML-DSA-44":
14833
+ case "ML-DSA-65":
14834
+ case "ML-DSA-87":
14835
+ algorithm = { name: jwk.alg };
14836
+ keyUsages = jwk.priv ? ["sign"] : ["verify"];
14837
+ break;
14838
+ default:
14839
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
14840
+ }
14841
+ break;
14842
+ }
14793
14843
  case "RSA": {
14794
14844
  switch (jwk.alg) {
14795
14845
  case "PS256":
@@ -14875,9 +14925,11 @@ var jwk_to_key_default = async (jwk) => {
14875
14925
  }
14876
14926
  const { algorithm, keyUsages } = subtleMapping(jwk);
14877
14927
  const keyData = { ...jwk };
14878
- delete keyData.alg;
14928
+ if (keyData.kty !== "AKP") {
14929
+ delete keyData.alg;
14930
+ }
14879
14931
  delete keyData.use;
14880
- return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d ? false : true), jwk.key_ops ?? keyUsages);
14932
+ return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
14881
14933
  };
14882
14934
 
14883
14935
  // node_modules/jose/dist/webapi/key/import.js
@@ -14898,6 +14950,16 @@ async function importJWK(jwk, alg, options) {
14898
14950
  if ("oth" in jwk && jwk.oth !== void 0) {
14899
14951
  throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
14900
14952
  }
14953
+ return jwk_to_key_default({ ...jwk, alg, ext });
14954
+ case "AKP": {
14955
+ if (typeof jwk.alg !== "string" || !jwk.alg) {
14956
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
14957
+ }
14958
+ if (alg !== void 0 && alg !== jwk.alg) {
14959
+ throw new TypeError("JWK alg and alg option value mismatch");
14960
+ }
14961
+ return jwk_to_key_default({ ...jwk, ext });
14962
+ }
14901
14963
  case "EC":
14902
14964
  case "OKP":
14903
14965
  return jwk_to_key_default({ ...jwk, alg, ext });
@@ -15147,10 +15209,10 @@ function isJWK(key) {
15147
15209
  return is_object_default(key) && typeof key.kty === "string";
15148
15210
  }
15149
15211
  function isPrivateJWK(key) {
15150
- return key.kty !== "oct" && typeof key.d === "string";
15212
+ return key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
15151
15213
  }
15152
15214
  function isPublicJWK(key) {
15153
- return key.kty !== "oct" && typeof key.d === "undefined";
15215
+ return key.kty !== "oct" && typeof key.d === "undefined" && typeof key.priv === "undefined";
15154
15216
  }
15155
15217
  function isSecretJWK(key) {
15156
15218
  return key.kty === "oct" && typeof key.k === "string";
@@ -15203,6 +15265,18 @@ var handleKeyObject = (keyObject, alg) => {
15203
15265
  isPublic ? "verify" : "sign"
15204
15266
  ]);
15205
15267
  }
15268
+ switch (keyObject.asymmetricKeyType) {
15269
+ case "ml-dsa-44":
15270
+ case "ml-dsa-65":
15271
+ case "ml-dsa-87": {
15272
+ if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
15273
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
15274
+ }
15275
+ cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
15276
+ isPublic ? "verify" : "sign"
15277
+ ]);
15278
+ }
15279
+ }
15206
15280
  if (keyObject.asymmetricKeyType === "rsa") {
15207
15281
  let hash;
15208
15282
  switch (alg) {
@@ -15630,6 +15704,10 @@ async function keyToJWK(key) {
15630
15704
  throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
15631
15705
  }
15632
15706
  const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
15707
+ if (jwk.kty === "AKP") {
15708
+ ;
15709
+ jwk.alg = alg;
15710
+ }
15633
15711
  return jwk;
15634
15712
  }
15635
15713
 
@@ -15895,6 +15973,10 @@ var subtle_dsa_default = (alg, algorithm) => {
15895
15973
  case "Ed25519":
15896
15974
  case "EdDSA":
15897
15975
  return { name: "Ed25519" };
15976
+ case "ML-DSA-44":
15977
+ case "ML-DSA-65":
15978
+ case "ML-DSA-87":
15979
+ return { name: alg };
15898
15980
  default:
15899
15981
  throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
15900
15982
  }
@@ -16850,30 +16932,33 @@ function getPORT() {
16850
16932
  // src/services/utils/log-transport.ts
16851
16933
  init_lib3();
16852
16934
  var import_node_util3 = require("node:util");
16853
- init_constants();
16854
16935
  function createLogProviderOptions(app) {
16855
16936
  const defaultConsole = ConsoleTransport();
16856
- const defaultFile = app.options.logFile !== true && app.options.logFile !== false && String(app.options.logFile).toUpperCase() !== "TRUE" && String(app.options.logFile).toUpperCase() !== "FALSE" && app.options.logFile ? FileTransport(app.options.logFile) : String(app.options.logFile).toUpperCase() === "TRUE" || app.options.logFile === true || app.options.logFile === void 0 ? FileTransport() : void 0;
16937
+ const defaultFile = app && app.options && app?.options?.logFile !== true && app?.options?.logFile !== false && String(app?.options?.logFile).toUpperCase() !== "TRUE" && String(app?.options?.logFile).toUpperCase() !== "FALSE" && app.options.logFile ? FileTransport(app.options.logFile) : app && app.options && String(app?.options?.logFile).toUpperCase() === "TRUE" || app?.options?.logFile === true || app?.options?.logFile === void 0 ? FileTransport() : void 0;
16857
16938
  const defaultWrite = async (args, level) => {
16858
16939
  try {
16859
- const serviceNamesWithLogConfigReplaceConsole = level === void 0 && app.inflated ? Object.keys(app.inflated.logConfigMap).filter((serviceName) => app.inflated.logConfigMap[serviceName].replaceConsoleTransport) : [];
16860
- const serviceNamesWithLogConfigReplaceFile = level === void 0 && app.inflated ? Object.keys(app.inflated.logConfigMap).filter((serviceName) => app.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
16940
+ const serviceNamesWithLogConfigReplaceConsole = app?.inflated ? Object.keys(app?.inflated?.logConfigMap).filter((serviceName) => app?.inflated?.logConfigMap[serviceName].replaceConsoleTransport) : [];
16941
+ const serviceNamesWithLogConfigReplaceFile = app?.inflated ? Object.keys(app?.inflated?.logConfigMap).filter((serviceName) => app?.inflated?.logConfigMap[serviceName].replaceFileTransport) : [];
16861
16942
  await Promise.allSettled((level === void 0 ? [
16862
16943
  level === void 0 && serviceNamesWithLogConfigReplaceConsole.length === 0 && defaultConsole ? defaultConsole.write(args) : Promise.resolve(),
16863
16944
  level === void 0 && serviceNamesWithLogConfigReplaceFile.length === 0 && defaultFile ? defaultFile.write(args) : Promise.resolve()
16864
16945
  ] : []).concat(
16865
- app.inflated ? Object.keys(app.inflated.logConfigMap).map((serviceName) => app.inflated.logConfigMap[serviceName]).filter((c) => c.level === level).map((c) => c.write(args)) : []
16946
+ app && app.inflated && app?.inflated ? Object.keys(app?.inflated?.logConfigMap).map((serviceName) => app?.inflated?.logConfigMap[serviceName]).filter((c) => c.level === level).map((c) => c.write(args)) : []
16866
16947
  ));
16867
16948
  } catch (e) {
16868
16949
  console.error(e);
16869
16950
  }
16870
16951
  };
16871
16952
  return {
16872
- name: app.options.name,
16953
+ name: app?.options?.name,
16873
16954
  formatter: (args) => {
16874
16955
  const params = args.optionalParams;
16875
16956
  return (0, import_node_util3.format)(
16876
- `${(/* @__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}`,
16957
+ `${(/* @__PURE__ */ new Date()).toLocaleDateString(void 0, app?.options?.dateTimeFormatOptions ? app?.options?.dateTimeFormatOptions : {
16958
+ hour12: false
16959
+ })} ${(/* @__PURE__ */ new Date()).toLocaleTimeString(void 0, app?.options?.dateTimeFormatOptions ? app?.options?.dateTimeFormatOptions : {
16960
+ hour12: false
16961
+ })} PID[${process.pid}] ${args.identifier ? `[${args.identifier}] ` : ""}${args.level !== "info" ? args.level === "error" || args.level === "warn" ? `[${args.level.toUpperCase()}] ` : `[${args.level}] ` : ""}${args.message}`,
16877
16962
  ...params
16878
16963
  );
16879
16964
  },
@@ -16889,33 +16974,9 @@ function createLogProviderOptions(app) {
16889
16974
  await defaultWrite(args, void 0);
16890
16975
  }
16891
16976
  };
16892
- }),
16893
- {
16894
- level: "trace",
16895
- write: async (args) => {
16896
- try {
16897
- if (app.options.editor) {
16898
- try {
16899
- const ws = app.webSocketManager.getWS(LOG_SOCKET_PATH);
16900
- if (ws) {
16901
- await ws.broadcast(JSON.stringify({
16902
- type: LOG_WRITE_EVENT,
16903
- level: args.level,
16904
- identifier: args.identifier,
16905
- out: args.out
16906
- }));
16907
- }
16908
- } catch (e) {
16909
- console.error(e);
16910
- }
16911
- }
16912
- } catch (e) {
16913
- console.error(e);
16914
- }
16915
- }
16916
- }
16977
+ })
16917
16978
  ],
16918
- ...app.options.logProviderOptions ? app.options.logProviderOptions : {}
16979
+ ...app?.options?.logProviderOptions ? app?.options?.logProviderOptions : {}
16919
16980
  };
16920
16981
  }
16921
16982
 
@@ -16982,7 +17043,9 @@ var Miqro = class _Miqro {
16982
17043
  services: [],
16983
17044
  ...options ? options : {}
16984
17045
  };
16985
- this.loggerProvider = new LogProvider(createLogProviderOptions(this));
17046
+ const loggerOptions = createLogProviderOptions(this);
17047
+ loggerOptions.transports.push(createEditorLoggerTransport(this));
17048
+ this.loggerProvider = new LogProvider(loggerOptions);
16986
17049
  const SERVER_IDENTIFIER = import_node_cluster3.default.isPrimary ? "" : process.env["CLUSTER_NODE_NUMBER"] ? `WORKER_${process.env["CLUSTER_NODE_NUMBER"]}`.toUpperCase() : `WORKER`;
16987
17050
  this.logger = this.options.logger ? this.options.logger : this.loggerProvider.getLogger(SERVER_IDENTIFIER);
16988
17051
  this.listener = async (data) => {
@@ -17451,6 +17514,32 @@ function notifiyServerConfigSync(app, method) {
17451
17514
  });
17452
17515
  }
17453
17516
  }
17517
+ function createEditorLoggerTransport(app) {
17518
+ return {
17519
+ level: "trace",
17520
+ write: async (args) => {
17521
+ try {
17522
+ if (app.options.editor) {
17523
+ try {
17524
+ const ws = app.webSocketManager.getWS(LOG_SOCKET_PATH);
17525
+ if (ws) {
17526
+ await ws.broadcast(JSON.stringify({
17527
+ type: LOG_WRITE_EVENT,
17528
+ level: args.level,
17529
+ identifier: args.identifier,
17530
+ out: args.out
17531
+ }));
17532
+ }
17533
+ } catch (e) {
17534
+ console.error(e);
17535
+ }
17536
+ }
17537
+ } catch (e) {
17538
+ console.error(e);
17539
+ }
17540
+ }
17541
+ };
17542
+ }
17454
17543
 
17455
17544
  // src/inflate/utils/sea-utils.ts
17456
17545
  var import_node_path31 = require("node:path");
@@ -17488,6 +17577,7 @@ var JSX2 = {
17488
17577
  ServerRequestHandler,
17489
17578
  WebSocketManager,
17490
17579
  appendAPIModule,
17580
+ createLogProviderOptions,
17491
17581
  createServerInterface,
17492
17582
  jsx,
17493
17583
  jsx2HTML,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "7.0.9",
3
+ "version": "7.1.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "build/esm/src/lib.js",
@@ -50,8 +50,8 @@
50
50
  "@miqro/runner": "^2.0.1",
51
51
  "@miqro/test": "^0.2.9",
52
52
  "@miqro/test-http": "^0.1.2",
53
- "esbuild": "0.25.6",
54
- "jose": "6.0.11",
53
+ "esbuild": "0.25.9 ",
54
+ "jose": "6.1.0",
55
55
  "showdown": "2.1.0"
56
56
  }
57
57
  }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env sh
2
2
 
3
3
  TARGET="${PWD}/sea/deps/esbuild"
4
- VERSION="0.25.6"
4
+ VERSION="0.25.9"
5
5
 
6
6
  if [ -d "$TARGET" ]; then
7
7
  echo "$TARGET already exists exist."
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env sh
2
2
 
3
3
  TARGET="${PWD}/sea/deps/nodejs"
4
- VERSION="24.4.0"
4
+ VERSION="24.7.0"
5
5
 
6
6
  if [ -d "$TARGET" ]; then
7
7
  echo "$TARGET already exists exist."
@@ -1 +1 @@
1
- 24.4.0
1
+ 24.7.0
@@ -4,7 +4,7 @@ import { basename, dirname, extname, join, relative, resolve } from "node:path";
4
4
  import { cwd, platform } from "node:process";
5
5
 
6
6
  import { RouteFileMap, StaticFileMap } from "./setup-http.js";
7
- import { getAuthConfigPath, getCORSConfigPath, getDBConfigPath, getErrorConfigPath, getMiddlewareConfigPath, getMigrationsPath, getMiqroJSONPath, getServerConfigPath, getServicePath, getWSConfigPath } from "../common/paths.js";
7
+ import { getAuthConfigPath, getCORSConfigPath, getDBConfigPath, getErrorConfigPath, getLogConfigPath, getMiddlewareConfigPath, getMigrationsPath, getMiqroJSONPath, getServerConfigPath, getServicePath, getWSConfigPath } from "../common/paths.js";
8
8
  import { getAsset } from "../common/assets.js";
9
9
  import { migration } from "@miqro/query";
10
10
  import { esBuild } from "../common/esbuild.js";
@@ -47,11 +47,15 @@ export async function inflateAppForSea(logger: Logger, inflateDir: string, servi
47
47
  writeFile(logger, resolve(inflateDir, "sea", "lib.cjs"), Buffer.from(getAsset("lib.cjs")));
48
48
 
49
49
  const WSLIST = services.filter(service => getWSConfigPath(resolve(cwd(), service))).map(service => {
50
- return `(await require("../${service}/ws.cjs")).default`;
51
- }).join(",")
50
+ return `(await require("./../${service}/ws.cjs")).default`;
51
+ }).join(",");
52
+
53
+ const LOGCONFIGLIST = services.filter(service => getLogConfigPath(resolve(cwd(), service))).map(service => {
54
+ return `{config: (await require("./../${service}/log.cjs")).default, service: "${service}" }`;
55
+ }).join(",");
52
56
 
53
57
  const SERVERCONFIGLIST = services.filter(service => getServerConfigPath(resolve(cwd(), service))).map(service => {
54
- return `(await require("../${service}/server.cjs")).default`;
58
+ return `(await require("./../${service}/server.cjs")).default`;
55
59
  }).join(",\n");
56
60
 
57
61
  const DBCONFIGLIST = services.filter(service => getDBConfigPath(resolve(cwd(), service))).map(service => {
@@ -69,21 +73,38 @@ export async function inflateAppForSea(logger: Logger, inflateDir: string, servi
69
73
 
70
74
  writeFile(logger, join(inflateDir, "sea", "package.json"), `{ "type": "module", "private": true }`);
71
75
 
72
- writeFile(logger, join(inflateDir, "sea", "app.cjs"), `const { createServerInterface, ServerRequestHandler, WebSocketManager, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
76
+ writeFile(logger, join(inflateDir, "sea", "app.cjs"), `const { createLogProviderOptions, createServerInterface, ServerRequestHandler, WebSocketManager, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
73
77
 
74
78
  async function main() {
75
- const PORT = "${PORT}";
76
- const loggerProvider = new LogProvider();
79
+ const PORT = "${PORT}";
80
+
81
+ const logConfigList = await Promise.all([${LOGCONFIGLIST}]);
82
+
83
+ const loggerProvider = new LogProvider(createLogProviderOptions({
84
+ inflated: {
85
+ logConfigMap: logConfigList.reduce((ret, config)=>{
86
+ ret[config.service] = config.config;
87
+ return ret;
88
+ }, {})
89
+ }
90
+ }));
91
+ const logger = loggerProvider.getLogger("SERVER");
77
92
  const localCache = new LocalCache();
78
93
  const cache = new ClusterCache();
79
- const webSocketManager = new WebSocketManager();
80
- const dbManager = new DBManager();
94
+ const webSocketManager = new WebSocketManager({
95
+ loggerProvider,
96
+ logger
97
+ });
98
+ const dbManager = new DBManager({
99
+ loggerProvider,
100
+ logger
101
+ });
81
102
  const serverInterface = createServerInterface({
82
103
  cache,
83
104
  localCache,
84
105
  loggerProvider,
85
106
  webSocketManager,
86
- logger: loggerProvider.getLogger("server"),
107
+ logger,
87
108
  dbManager,
88
109
  port: PORT
89
110
  });
@@ -94,6 +115,7 @@ async function main() {
94
115
 
95
116
  ${!WSLIST ? "" : `\n webSocketManager.replaceALLWS(await Promise.all([${WSLIST}]))`}
96
117
  const app = new App({
118
+ loggerFactory: loggerProvider.requestLoggerFactory,
97
119
  onUpgrade: (req, socket, head) => {
98
120
  try {
99
121
  req.server = serverInterface;
@@ -137,20 +159,20 @@ export async function inflateServiceForSea(logger: Logger, inflateDir: string, s
137
159
  const migrationsFolderPath = getMigrationsPath(servicePath);
138
160
 
139
161
  const serviceMigrations: string[] = migrationsFolderPath ? migration.getSortedMigrations(migrationsFolderPath) : [];
140
- writeFile(logger, join(inflateDir, "sea", service, "router.cjs"), `const { appendAPIModule, Router, middleware } = require("./../lib.cjs");\n
162
+ writeFile(logger, join(inflateDir, "sea", service, "router.cjs"), `const { appendAPIModule, Router, middleware } = require("./${relative(service, "")}/lib.cjs");\n
141
163
  async function setupRouter() {
142
164
  const router = new Router();
143
165
  ${getErrorConfigPath(servicePath) ? `
144
- const errorConfig = (await require("../../${service}/catch.cjs")).default;
166
+ const errorConfig = (await require("../${relative(service, "")}/${service}/catch.cjs")).default;
145
167
  if(errorConfig && errorConfig.catch) {
146
168
  for(const m of errorConfig.catch) {
147
169
  router.catch(m);
148
170
  }
149
171
  }` : ""}
150
- ${getCORSConfigPath(servicePath) ? ` router.use(middleware.cors((await require("../../${service}/cors.cjs")).default));` : ""}
151
- ${getAuthConfigPath(servicePath) ? ` router.use(middleware.session((await require("../../${service}/auth.cjs")).default));` : ""}
172
+ ${getCORSConfigPath(servicePath) ? ` router.use(middleware.cors((await require("../${relative(service, "")}/${service}/cors.cjs")).default));` : ""}
173
+ ${getAuthConfigPath(servicePath) ? ` router.use(middleware.session((await require("../${relative(service, "")}/${service}/auth.cjs")).default));` : ""}
152
174
  ${getMiddlewareConfigPath(servicePath) ? `
153
- const middlewareConfig = (await require("../../${service}/middleware.cjs")).default;
175
+ const middlewareConfig = (await require("../${relative(service, "")}/${service}/middleware.cjs")).default;
154
176
  if(middlewareConfig && middlewareConfig.middleware) {
155
177
  for(const m of middlewareConfig.middleware) {
156
178
  router.use(m);
@@ -163,8 +185,8 @@ ${Object.keys(serviceRouteFileMap)
163
185
  const rPath = join(relative(cwd(), dirname(data.filePath)), basename(data.filePath));
164
186
  if (rPath) {
165
187
  const rPathExt = extname(rPath);
166
- const apiInflatedPath = join("..", "..", rPath.substring(0, rPath.length - rPathExt.length) + ".cjs");
167
- return ` await appendAPIModule(router, "../../${service}/http", "./${apiInflatedPath}", (await require("./${apiInflatedPath}")).default);`;
188
+ const apiInflatedPath = join("..", relative(service, ""), rPath.substring(0, rPath.length - rPathExt.length) + ".cjs");
189
+ return ` await appendAPIModule(router, "../${relative(service, "")}/${service}/http", "./${apiInflatedPath}", (await require("./${apiInflatedPath}")).default);`;
168
190
  } else {
169
191
  return "";
170
192
  }
@@ -185,24 +207,24 @@ module.exports = {
185
207
  setupRouter
186
208
  }`);
187
209
 
188
- writeFile(logger, join(inflateDir, "sea", service, "migration-up.cjs"), `const { migration } = require("./../lib.cjs");\n
210
+ writeFile(logger, join(inflateDir, "sea", service, "migration-up.cjs"), `const { migration } = require("./${relative(service, "")}/lib.cjs");\n
189
211
  async function runMigrations(db) {
190
212
  await migration.init(db);
191
213
  ${serviceMigrations.map(file => {
192
214
  const name = `${file.substring(0, file.length - extname(file).length)}`;
193
- return ` await migration.up.module(db, "${file}", (await require("../../${service}/migration/${name}.cjs")).default)`;
215
+ return ` await migration.up.module(db, "${file}", (await require("../${relative(service, "")}/${service}/migration/${name}.cjs")).default)`;
194
216
  }).join("\n")}
195
217
  }
196
218
  module.exports = {
197
219
  runMigrations
198
220
  }`);
199
221
 
200
- writeFile(logger, join(inflateDir, "sea", service, "migration-down.cjs"), `const { migration } = require("./../lib.cjs");\n
222
+ writeFile(logger, join(inflateDir, "sea", service, "migration-down.cjs"), `const { migration } = require("./${relative(service, "")}/lib.cjs");\n
201
223
  async function runMigrations(db) {
202
224
  await migration.init(db);
203
225
  ${serviceMigrations.reverse().map(file => {
204
226
  const name = `${file.substring(0, file.length - extname(file).length)}`;
205
- return ` await migration.down.module(db, "${file}", (await require("../../${service}/migration/${name}.cjs")).default)`;
227
+ return ` await migration.down.module(db, "${file}", (await require("../${relative(service, "")}/${service}/migration/${name}.cjs")).default)`;
206
228
  }).join("\n")}
207
229
  }
208
230
  module.exports = {
@@ -213,7 +235,7 @@ module.exports = {
213
235
  /*if (staticFiles.length !== 0) {
214
236
  writeFile(logger, join(inflateDir, "sea", service, "static.base64.json"), JSON.stringify(serviceStaticFileMap));
215
237
  }*/
216
- writeFile(logger, join(inflateDir, "sea", service, "static-router.cjs"), `const { appendAPIModule, Router } = require("./../lib.cjs");\n
238
+ writeFile(logger, join(inflateDir, "sea", service, "static-router.cjs"), `const { appendAPIModule, Router } = require("./${relative(service, "")}/lib.cjs");\n
217
239
  async function setupRouter() {
218
240
  const router = new Router();
219
241
  ${staticFiles.length === 0 ? "" : `
package/src/lib.ts CHANGED
@@ -16,6 +16,7 @@ export { Miqro, MiqroOptions, ServerRequestHandler } from "./services/app.js";
16
16
  export { jsx2HTML } from "./common/jsx.js";
17
17
 
18
18
  //exported for --inflate-sea
19
+ export { createLogProviderOptions } from "./services/utils/log-transport.js";
19
20
  export { appendAPIModule } from "./inflate/utils/sea-utils.js";
20
21
  export { createServerInterface, ServerInterfaceImplOptions } from "./services/utils/server-interface.js";
21
22
  export { App, LoggerHandler, Router } from "@miqro/core";
@@ -1,5 +1,5 @@
1
1
  import cluster from "node:cluster";
2
- import { App, Router, Logger, LoggerHandler } from "@miqro/core";
2
+ import { App, Router, Logger, LoggerHandler, LogLevel } 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 } from "../../editor/common/constants.js";
11
+ import { BASEEDITOR_PATH, LOG_SOCKET_PATH, LOG_WRITE_EVENT } from "../../editor/common/constants.js";
12
12
  import editorWSConfig from "../../editor/ws.js";
13
13
  import editorServerConfig from "../../editor/server.js";
14
14
 
@@ -107,7 +107,11 @@ export class Miqro {
107
107
  services: [],
108
108
  ...(options ? options : {})
109
109
  };
110
- this.loggerProvider = new LogProvider(createLogProviderOptions(this));
110
+
111
+ const loggerOptions = createLogProviderOptions(this);
112
+ loggerOptions.transports.push(createEditorLoggerTransport(this));
113
+ this.loggerProvider = new LogProvider(loggerOptions);
114
+
111
115
  //if (!this.options.logger) {
112
116
  const SERVER_IDENTIFIER = cluster.isPrimary ?
113
117
  "" :
@@ -701,3 +705,31 @@ export function notifiyServerConfigSync(app: Miqro, method: "unload" | "stop") {
701
705
  });
702
706
  }
703
707
  }
708
+
709
+ function createEditorLoggerTransport(app: Miqro) {
710
+ return {
711
+ level: "trace" as LogLevel,
712
+ write: async (args) => {
713
+ try {
714
+ if (app.options.editor) {
715
+ try {
716
+ const ws = app.webSocketManager.getWS(LOG_SOCKET_PATH);
717
+ if (ws) {
718
+ //console.log("\n\n" + process.pid + " broadcasting " + LOG_SOCKET_PATH + "\n\n\n")
719
+ await ws.broadcast(JSON.stringify({
720
+ type: LOG_WRITE_EVENT,
721
+ level: args.level,
722
+ identifier: args.identifier,
723
+ out: args.out
724
+ }));
725
+ }
726
+ } catch (e) {
727
+ console.error(e);
728
+ }
729
+ }
730
+ } catch (e) {
731
+ console.error(e);
732
+ }
733
+ }
734
+ }
735
+ }
@@ -2,41 +2,65 @@ import { ConsoleTransport, FileTransport, LoggerTransport, LoggerTransportWriteA
2
2
  import { format } from "node:util";
3
3
  import { LOG_SOCKET_PATH, LOG_WRITE_EVENT } from "../../../editor/common/constants.js";
4
4
  import { Miqro } from "../app.js";
5
+ import { LogConfigMap } from "../../inflate/setup-log.js";
6
+ // import { WebSocketManager } from "./websocketmanager.js";
7
+ import { LogProviderOptions } from "./log.js";
5
8
 
6
- export function createLogProviderOptions(app: Miqro) {
9
+ export function createLogProviderOptions(app?: {
10
+ options?: {
11
+ dateTimeFormatOptions?: Intl.DateTimeFormatOptions;
12
+ logProviderOptions?: LogProviderOptions;
13
+ name?: string;
14
+ editor?: boolean;
15
+ logFile?: string | boolean;
16
+ },
17
+ inflated?: {
18
+ logConfigMap: LogConfigMap;
19
+ }
20
+ }) {
7
21
  const defaultConsole = ConsoleTransport();
8
22
  //console.log("app.options.logFile [%s]", app.options.logFile);
9
23
  const defaultFile: LoggerTransport | undefined =
10
- app.options.logFile !== true && app.options.logFile !== false && String(app.options.logFile).toUpperCase() !== "TRUE" && String(app.options.logFile).toUpperCase() !== "FALSE" &&
24
+ app && app.options && app?.options?.logFile !== true && app?.options?.logFile !== false && String(app?.options?.logFile).toUpperCase() !== "TRUE" && String(app?.options?.logFile).toUpperCase() !== "FALSE" &&
11
25
  app.options.logFile ? FileTransport(app.options.logFile) :
12
- String(app.options.logFile).toUpperCase() === "TRUE" || app.options.logFile === true || app.options.logFile === undefined ?
26
+ app && app.options && String(app?.options?.logFile).toUpperCase() === "TRUE" || app?.options?.logFile === true || app?.options?.logFile === undefined ?
13
27
  FileTransport() :
14
28
  undefined;
15
29
  const defaultWrite = async (args: LoggerTransportWriteArgs, level?: LogLevel) => {
16
30
  try {
17
- const serviceNamesWithLogConfigReplaceConsole = level === undefined && app.inflated ?
18
- Object.keys(app.inflated.logConfigMap).filter(serviceName => app.inflated.logConfigMap[serviceName].replaceConsoleTransport) : [];
19
- const serviceNamesWithLogConfigReplaceFile = level === undefined && app.inflated ?
20
- Object.keys(app.inflated.logConfigMap).filter(serviceName => app.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
31
+ // console.dir(app.inflated);
32
+ const serviceNamesWithLogConfigReplaceConsole = app?.inflated ?
33
+ Object.keys(app?.inflated?.logConfigMap).filter(serviceName => app?.inflated?.logConfigMap[serviceName].replaceConsoleTransport) : [];
34
+ const serviceNamesWithLogConfigReplaceFile = app?.inflated ?
35
+ Object.keys(app?.inflated?.logConfigMap).filter(serviceName => app?.inflated?.logConfigMap[serviceName].replaceFileTransport) : [];
36
+ // console.dir(level);
37
+
38
+ // console.dir(app?.inflated?.logConfigMap["m-admin"])
39
+ // console.dir(serviceNamesWithLogConfigReplaceConsole.length);
40
+ // console.dir(serviceNamesWithLogConfigReplaceFile.length);
21
41
  await Promise.allSettled((level === undefined ?
22
42
  [
23
43
  level === undefined && serviceNamesWithLogConfigReplaceConsole.length === 0 && defaultConsole ?
24
44
  defaultConsole.write(args) : Promise.resolve(),
25
45
  level === undefined && serviceNamesWithLogConfigReplaceFile.length === 0 && defaultFile ?
26
46
  defaultFile.write(args) : Promise.resolve()
27
- ] : []).concat(app.inflated ?
28
- Object.keys(app.inflated.logConfigMap).map(serviceName => app.inflated.logConfigMap[serviceName]).filter(c => c.level === level).map(c => c.write(args)) : []
47
+ ] : []).concat(app && app.inflated && app?.inflated ?
48
+ Object.keys(app?.inflated?.logConfigMap).map(serviceName => app?.inflated?.logConfigMap[serviceName]).filter(c => c.level === level).map(c => c.write(args)) : []
29
49
  ));
30
50
  } catch (e) {
31
51
  console.error(e);
32
52
  }
33
53
  }
34
54
  return {
35
- name: app.options.name,
55
+ name: app?.options?.name,
36
56
  formatter: (args: WriteArgs) => {
37
57
  const params: string[] = args.optionalParams;
38
58
  return format(
39
- `${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}`,
59
+ `${new Date().toLocaleDateString(undefined, app?.options?.dateTimeFormatOptions ? app?.options?.dateTimeFormatOptions : {
60
+ hour12: false
61
+ })} ${new Date().toLocaleTimeString(undefined, app?.options?.dateTimeFormatOptions ? app?.options?.dateTimeFormatOptions : {
62
+ hour12: false
63
+ })} PID[${process.pid}] ${args.identifier ? `[${args.identifier}] ` : ""}${args.level !== "info" ? (args.level === "error" || args.level === "warn" ? `[${args.level.toUpperCase()}] ` : `[${args.level}] `) : ""}${args.message}`,
40
64
  ...params)
41
65
  },
42
66
  transports: [
@@ -51,31 +75,7 @@ export function createLogProviderOptions(app: Miqro) {
51
75
  await defaultWrite(args, undefined);
52
76
  }
53
77
  }
54
- })), {
55
- level: "trace" as LogLevel,
56
- write: async (args) => {
57
- try {
58
- if (app.options.editor) {
59
- try {
60
- const ws = app.webSocketManager.getWS(LOG_SOCKET_PATH);
61
- if (ws) {
62
- //console.log("\n\n" + process.pid + " broadcasting " + LOG_SOCKET_PATH + "\n\n\n")
63
- await ws.broadcast(JSON.stringify({
64
- type: LOG_WRITE_EVENT,
65
- level: args.level,
66
- identifier: args.identifier,
67
- out: args.out
68
- }));
69
- }
70
- } catch (e) {
71
- console.error(e);
72
- }
73
- }
74
- } catch (e) {
75
- console.error(e);
76
- }
77
- }
78
- }],
79
- ...(app.options.logProviderOptions ? app.options.logProviderOptions : {})
78
+ }))],
79
+ ...(app?.options?.logProviderOptions ? app?.options?.logProviderOptions : {})
80
80
  };
81
81
  }