miqro 6.1.3 → 6.2.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.
Files changed (62) hide show
  1. package/build/editor.bundle.js +26 -2
  2. package/build/esm/editor/common/templates.js +16 -0
  3. package/build/esm/editor/components/editor.js +8 -0
  4. package/build/esm/editor/components/file-editor.js +1 -1
  5. package/build/esm/editor/components/highlight-text-area.js +2 -1
  6. package/build/esm/src/bin/types.js +8 -0
  7. package/build/esm/src/common/arguments.d.ts +7 -1
  8. package/build/esm/src/common/arguments.js +72 -10
  9. package/build/esm/src/common/help.d.ts +1 -1
  10. package/build/esm/src/common/help.js +33 -29
  11. package/build/esm/src/common/jwt.d.ts +49 -0
  12. package/build/esm/src/common/jwt.js +76 -0
  13. package/build/esm/src/inflate/inflate-sea.js +9 -8
  14. package/build/esm/src/inflate/setup-http.d.ts +1 -0
  15. package/build/esm/src/inflate/setup-http.js +8 -0
  16. package/build/esm/src/inflate/setup-ws.d.ts +1 -1
  17. package/build/esm/src/inflate/setup-ws.js +2 -2
  18. package/build/esm/src/lib.d.ts +1 -1
  19. package/build/esm/src/lib.js +2 -2
  20. package/build/esm/src/main.js +3 -1
  21. package/build/esm/src/services/app.d.ts +2 -0
  22. package/build/esm/src/services/app.js +7 -6
  23. package/build/esm/src/services/globals.js +45 -1
  24. package/build/esm/src/services/utils/cluster-ws.d.ts +4 -2
  25. package/build/esm/src/services/utils/cluster-ws.js +10 -1
  26. package/build/esm/src/services/utils/log-transport.d.ts +2 -2
  27. package/build/esm/src/services/utils/log-transport.js +8 -3
  28. package/build/esm/src/services/utils/server-interface.d.ts +4 -30
  29. package/build/esm/src/services/utils/server-interface.js +44 -59
  30. package/build/esm/src/services/utils/websocketmanager.d.ts +3 -0
  31. package/build/esm/src/services/utils/websocketmanager.js +8 -2
  32. package/build/esm/src/types.d.ts +76 -5
  33. package/build/lib.cjs +2992 -369
  34. package/editor/common/templates.ts +15 -0
  35. package/editor/components/editor.tsx +8 -0
  36. package/editor/components/file-editor.tsx +1 -1
  37. package/editor/components/highlight-text-area.tsx +2 -1
  38. package/package.json +4 -3
  39. package/sea/install-nodejs.sh +1 -1
  40. package/sea/node.version.tag +1 -1
  41. package/sea/types.json +1 -1
  42. package/src/bin/types.ts +7 -0
  43. package/src/common/arguments.ts +84 -11
  44. package/src/common/help.ts +33 -29
  45. package/src/common/jwt.ts +85 -0
  46. package/src/inflate/inflate-sea.ts +9 -8
  47. package/src/inflate/setup-db.ts +3 -1
  48. package/src/inflate/setup-http.ts +9 -0
  49. package/src/inflate/setup-ws.ts +4 -3
  50. package/src/lib.ts +2 -2
  51. package/src/main.ts +3 -1
  52. package/src/services/app.ts +10 -6
  53. package/src/services/globals.ts +45 -2
  54. package/src/services/utils/cluster-ws.ts +6 -1
  55. package/src/services/utils/log-transport.ts +10 -4
  56. package/src/services/utils/server-interface.ts +44 -133
  57. package/src/services/utils/websocketmanager.ts +10 -2
  58. package/src/types/cookie.d.ts +2 -0
  59. package/src/types/jose.d.ts +2 -0
  60. package/src/types/miqro.d.ts +92 -2
  61. package/src/types/server.globals.d.ts +4 -29
  62. package/src/types.ts +78 -5
package/src/bin/types.ts CHANGED
@@ -18,5 +18,12 @@ export async function installTypings(args: Arguments, logger: MinimalLogger) {
18
18
  logger.error("tsconfig.json already exists!");
19
19
  process.exit(EXIT_CODES.ABNORMAL);
20
20
  }
21
+ if (args.installMiqroJSON && !existsSync("miqro.json")) {
22
+ logger.info("writing miqro.json");
23
+ writeFileSync("miqro.json", TEMPLATES["MIQROJSON"].template("", ""));
24
+ } else if (args.installMiqroJSON) {
25
+ logger.error("miqro.json already exists!");
26
+ process.exit(EXIT_CODES.ABNORMAL);
27
+ }
21
28
  process.exit(EXIT_CODES.NORMAL_EXIT);
22
29
  }
@@ -20,6 +20,9 @@ interface MiqroJSON {
20
20
  port?: string | number;
21
21
  inflateDir?: string;
22
22
  name?: string;
23
+ browser?: string | boolean;
24
+ logFile?: string | boolean;
25
+ editor?: boolean;
23
26
  }
24
27
 
25
28
  const MiqroJSONSchema: Schema<MiqroJSON> = {
@@ -28,7 +31,10 @@ const MiqroJSONSchema: Schema<MiqroJSON> = {
28
31
  name: "string?",
29
32
  services: "string[]?",
30
33
  port: "number?|string?",
31
- inflateDir: "string?"
34
+ inflateDir: "string?",
35
+ browser: "boolean?|string?",
36
+ logFile: "boolean?|string?",
37
+ editor: "boolean?"
32
38
  }
33
39
  }
34
40
 
@@ -47,8 +53,11 @@ export function getPORT() {
47
53
  }
48
54
 
49
55
  export interface Arguments {
50
- name: string;
56
+ name?: string;
57
+ browser?: string | boolean;
58
+ logFile?: string | boolean;
51
59
  installTypes: boolean;
60
+ installMiqroJSON: boolean;
52
61
  installTSConfig: boolean;
53
62
  test: boolean;
54
63
  port: string;
@@ -78,8 +87,11 @@ export function parseArguments(): Arguments {
78
87
 
79
88
  const args = cluster.isPrimary ? process.argv.slice(2, process.argv.length) : process.argv.slice(3, process.argv.length);
80
89
  const flags: {
90
+ logFile: string | boolean | null;
91
+ browser: string | boolean | null;
81
92
  name: string | null;
82
93
  installTypes: boolean | null;
94
+ installMiqroJSON: boolean | null;
83
95
  installTSConfig: boolean | null;
84
96
  inflate: boolean | null;
85
97
  port: string | null;
@@ -99,8 +111,11 @@ export function parseArguments(): Arguments {
99
111
  hotreload?: boolean | null;
100
112
  } = {
101
113
  name: null,
114
+ browser: null,
115
+ logFile: null,
102
116
  hotreload: null,
103
117
  miqroJSONPath: null,
118
+ installMiqroJSON: null,
104
119
  disableMiqroJSON: null,
105
120
  installTypes: null,
106
121
  port: null,
@@ -187,7 +202,7 @@ export function parseArguments(): Arguments {
187
202
  console.error(usage);
188
203
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
189
204
  }
190
- const cPort = String(args[i + 1]).toUpperCase() as any;
205
+ const cPort = String(args[i + 1]) as any;
191
206
  if (typeof cPort !== "string") {
192
207
  console.error("bad arguments. --port must be a string.");
193
208
  console.error(usage);
@@ -211,6 +226,36 @@ export function parseArguments(): Arguments {
211
226
  flags.name = cName;
212
227
  i++;
213
228
  continue;
229
+ case "--log-file":
230
+ if (flags.logFile !== null) {
231
+ console.error("bad arguments.");
232
+ console.error(usage);
233
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
234
+ }
235
+ const cLofFile = String(args[i + 1]) as any;
236
+ if (typeof cLofFile !== "string") {
237
+ console.error("bad arguments. --port must be a string.");
238
+ console.error(usage);
239
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
240
+ }
241
+ flags.logFile = cLofFile;
242
+ i++;
243
+ continue;
244
+ case "--browser":
245
+ if (flags.browser !== null) {
246
+ console.error("bad arguments.");
247
+ console.error(usage);
248
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
249
+ }
250
+ const cBrowser = String(args[i + 1]) as any;
251
+ if (typeof cBrowser !== "string") {
252
+ console.error("bad arguments. --port must be a string.");
253
+ console.error(usage);
254
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
255
+ }
256
+ flags.browser = cBrowser;
257
+ i++;
258
+ continue;
214
259
  case "--generate-doc":
215
260
  if (flags.generateDoc !== null) {
216
261
  console.error("bad arguments.");
@@ -285,6 +330,14 @@ export function parseArguments(): Arguments {
285
330
  }
286
331
  flags.editor = true;
287
332
  continue;
333
+ case "--install-miqrojson":
334
+ if (flags.installMiqroJSON !== null) {
335
+ console.error("bad arguments. --install-miqrojson already set.");
336
+ console.error(usage);
337
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
338
+ }
339
+ flags.installMiqroJSON = true;
340
+ continue;
288
341
  case "--inflate-sea":
289
342
  if (flags.inflateSEA !== null) {
290
343
  console.error("bad arguments. --inflate-sea already set.");
@@ -366,7 +419,7 @@ export function parseArguments(): Arguments {
366
419
  }
367
420
 
368
421
  flags.inflate = flags.inflate ? flags.inflate : false;
369
- flags.editor = flags.editor ? flags.editor : false;
422
+
370
423
  flags.test = flags.test ? flags.test : false;
371
424
  flags.inflateDir = flags.inflateDir ? flags.inflateDir : undefined;
372
425
 
@@ -382,7 +435,7 @@ export function parseArguments(): Arguments {
382
435
  }
383
436
  }
384
437
  }
385
- if (!flags.port) {
438
+ if (flags.port === null) {
386
439
  if (miqroRC.port) {
387
440
  flags.port = String(miqroRC.port);
388
441
  }
@@ -392,14 +445,31 @@ export function parseArguments(): Arguments {
392
445
  flags.inflateDir = miqroRC.inflateDir;
393
446
  }
394
447
  }
395
- if (!flags.name) {
448
+ if (flags.name === null) {
396
449
  if (miqroRC.name) {
397
450
  flags.name = miqroRC.name;
398
451
  }
399
452
  }
453
+ if (flags.logFile === null) {
454
+ if (miqroRC.logFile !== undefined) {
455
+ flags.logFile = miqroRC.logFile;
456
+ }
457
+ }
458
+ if (flags.browser === null) {
459
+ if (miqroRC.browser !== undefined) {
460
+ flags.browser = miqroRC.browser;
461
+ }
462
+ }
463
+ if (flags.editor === null) {
464
+ if (miqroRC.editor !== undefined) {
465
+ flags.editor = miqroRC.editor;
466
+ }
467
+ }
400
468
  }
401
469
 
402
- if (services.length === 0 && (!flags.installTSConfig && !flags.installTypes)) {
470
+ flags.editor = flags.editor ? flags.editor : false;
471
+
472
+ if (services.length === 0 && (!flags.installTSConfig && !flags.installTypes && !flags.installMiqroJSON)) {
403
473
  flags.inflateDir = flags.inflateDir ? flags.inflateDir : undefined;
404
474
  console.error(`bad arguments. missing --service argument`);
405
475
  console.error(usage);
@@ -436,8 +506,8 @@ export function parseArguments(): Arguments {
436
506
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
437
507
  }
438
508
 
439
- if (flags.inflate && (flags.installTypes || flags.installTSConfig)) {
440
- console.error("bad arguments. cannot use --inflate with --install-types");
509
+ if (flags.inflate && (flags.installTypes || flags.installTSConfig || flags.installMiqroJSON)) {
510
+ console.error("bad arguments. cannot use --inflate with --install-types, --install-tsconfig or --install-miqrojson");
441
511
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
442
512
  }
443
513
 
@@ -446,8 +516,8 @@ export function parseArguments(): Arguments {
446
516
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
447
517
  }
448
518
 
449
- if (flags.editor && (flags.installTypes || flags.installTSConfig)) {
450
- console.error("bad arguments. cannot use --editor with --install-types");
519
+ if (flags.editor && (flags.installTypes || flags.installTSConfig || flags.installMiqroJSON)) {
520
+ console.error("bad arguments. cannot use --editor with--install-types, --install-tsconfig or --install-miqrojson");
451
521
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
452
522
  }
453
523
 
@@ -480,11 +550,14 @@ export function parseArguments(): Arguments {
480
550
 
481
551
  return {
482
552
  name: flags.name ? flags.name : undefined,
553
+ browser: flags.browser !== null ? flags.browser : undefined,
554
+ logFile: flags.logFile !== null ? flags.logFile : undefined,
483
555
  generateDocAll: flags.generateDocAll ? true : false,
484
556
  hotreload: flags.hotreload ? true : false,
485
557
  disableMiqroJSON: flags.disableMiqroJSON !== null ? flags.disableMiqroJSON : false,
486
558
  miqroJSONPath: miqroJSONPath ? miqroJSONPath : false,
487
559
  installTypes: flags.installTypes ? true : false,
560
+ installMiqroJSON: flags.installMiqroJSON ? true : false,
488
561
  installTSConfig: flags.installTSConfig ? true : false,
489
562
  inflate: flags.inflate,
490
563
  port: flags.port ? flags.port : getPORT(),
@@ -16,36 +16,40 @@ CLUSTER_COUNT=10 ${BIN_NAME}-cluster --service api/`;
16
16
  export const help = `
17
17
  ==flags==
18
18
 
19
- -v, --version\t\toutputs the version number
20
- -h, --help\t\toutputs this page.
21
- --watch\t\t\tuse to enable the hot-reload functionality.
22
- --test\t\t\trun the tests for a service.
23
- --migrate-up\t\tmigrations up.
24
- --migrate-down\t\tmigrations down.
25
- --inflate\t\tinflates the application.
26
- --inflate-dir\t\tto set the output directory of the --inflate command. default value is inflated/.
27
- --editor\t\truns the application with a built-in editor.
28
- --generate-doc\t\tgenerates a documentation for the api endpoints of the service.
29
- --generate-doc-out\tthe output file for the generated documentation. default value is API.md.
30
- --generate-doc-type\tthe format of the generated documentation. it can be JSON or MD. default value is MD.
31
- --generate-doc-all\toutputs all the server routes in the documentation output.
32
- --compile\t\tinflates the application and tries to create a NODE SEA binary.
33
- --inflate-sea\t\tinflates the application with sea compilation scripts.
34
- --install-tsconfig\tcreates a tsconfig.json configured to use with --install-types.
35
- --install-types\t\tcreates and updates the .types/ folder use together with --install-tsconfig.
36
- --disable-miqrojson\tdisables the load of miqro.json file.
37
- --config\toverrides the default miqro.json path with a new one.
38
- --port\toverrides the default port loading from environment variables.
39
- --name\toverrides the default name of the server.
19
+ -v, --version\n\toutputs the version number
20
+ -h, --help\n\toutputs this page.
21
+ --watch\n\tuse to enable the hot-reload functionality.
22
+ --test\n\trun the tests for a service.
23
+ --migrate-up\n\tmigrations up.
24
+ --migrate-down\n\tmigrations down.
25
+ --inflate\n\tinflates the application.
26
+ --inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.
27
+ --editor\n\truns the application with a built-in editor.
28
+ --generate-doc\n\tgenerates a documentation for the api endpoints of the service.
29
+ --generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.
30
+ --generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.
31
+ --generate-doc-all\n\toutputs all the server routes in the documentation output.
32
+ --compile\n\tinflates the application and tries to create a NODE SEA binary.
33
+ --inflate-sea\n\tinflates the application with sea compilation scripts.
34
+ --install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.
35
+ --install-types\n\tcreates and updates the .types/ folder use together with --install-tsconfig.
36
+ --install-miqrojson\n\tcreates a default miqro.json file.
37
+ --disable-miqrojson\n\tdisables the load of miqro.json file.
38
+ --log-file\n\toverrides the default log file from LOG_FILE.
39
+ --browser\n\toverrides the default browser from BROWSER.
40
+ --config\n\toverrides the default miqro.json path.
41
+ --port\n\toverrides the default port from PORT.
42
+ --name\n\toverrides the default name of the server.
40
43
 
41
44
  ==environment variables==
42
45
 
43
- PORT\t\t\toverride the default 8080 port.
44
- LOG_FILE\t\toverride the default ./server.log file
45
- DB\t\t\tenable the server.db features
46
- DB_STORAGE\t\toverride the default local db location ./db.sqlite3
47
- DB_DIALECT\t\toverride the default node:sqlite
48
- DB_CONNECTION\t\toverride the default connection url
49
- CLEAR_JSX_CACHE\t\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.
50
- JSX_TMP\t\t\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.
46
+ PORT\n\toverride the default 8080 port.
47
+ BROWSER\n\toverride the default browser. change to none to disable.".
48
+ LOG_FILE\n\toverride the default ./server.log file
49
+ DB\n\tenable the server.db features
50
+ DB_STORAGE\n\toverride the default local db location ./db.sqlite3
51
+ DB_DIALECT\n\toverride the default node:sqlite
52
+ DB_CONNECTION\n\toverride the default connection url
53
+ CLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.
54
+ JSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.
51
55
  `;
@@ -0,0 +1,85 @@
1
+ import { EncryptJWT, EncryptOptions, JWTDecryptOptions, JWTDecryptResult, JWTPayload, JWTVerifyOptions, JWTVerifyResult, ProtectedHeaderParameters, SignJWT, SignOptions, decodeJwt, decodeProtectedHeader, jwtDecrypt as joseJWTDecrypt, jwtVerify } from "jose";
2
+ import { KeyObject } from "node:crypto";
3
+ import { EncryptJWTOptions, JWTSignOptions } from "../types.js";
4
+
5
+ /**
6
+ * creates a JWT encrypted token with jose
7
+ *
8
+ * @param payload the payload to encrypt
9
+ * @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
10
+ * @param options options like expiratation date, issuer and audience
11
+ * @returns
12
+ */
13
+ export async function encryptJWT(payload: JWTPayload, secret: KeyObject, options?: Partial<EncryptJWTOptions>): Promise<string> {
14
+ const en = new EncryptJWT(payload)
15
+ .setProtectedHeader({
16
+ alg: options?.alg ? options?.alg : 'dir',
17
+ enc: options?.enc ? options?.enc : 'A128CBC-HS256'
18
+ })
19
+ .setIssuedAt(options?.iat)
20
+ .setIssuer(options?.iss ? options?.iss : 'urn:example:issuer')
21
+ .setAudience(options?.aud ? options?.aud : 'urn:example:audience')
22
+ .setExpirationTime(options?.exp ? options?.exp : '2h');
23
+
24
+ return await en.encrypt(secret, options?.options);
25
+ }
26
+
27
+ /**
28
+ * decrypts a JWT token with jose
29
+ * @param jwt the JWT token
30
+ * @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
31
+ * @param options options like issuer and audience
32
+ * @returns
33
+ */
34
+ export async function decryptJWT<PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTDecryptOptions>): Promise<JWTDecryptResult<PayloadType>> {
35
+ return await joseJWTDecrypt(jwt, secret, options)
36
+ }
37
+
38
+ /**
39
+ * verify a JWT token with jose
40
+ * @param jwt the JWT token
41
+ * @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
42
+ * @param options options like issuer and audience
43
+ * @returns
44
+ */
45
+ export async function verifyJWT<PayloadType = JWTPayload>(jwt: string, secret: KeyObject, options?: Partial<JWTVerifyOptions>): Promise<JWTVerifyResult<PayloadType>> {
46
+ return await jwtVerify(jwt, secret, options)
47
+ }
48
+
49
+ /**
50
+ * creates a signed JWT with jose
51
+ *
52
+ * @param payload the payload to encrypt
53
+ * @param secret the secret example. const secret = createSecretKey(process.env.JWT_SECRET, 'utf-8');
54
+ * @param options options like expiratation date, issuer and audience
55
+ * @returns
56
+ */
57
+ export async function signJWT(payload: JWTPayload, secret: KeyObject, options?: Partial<JWTSignOptions>): Promise<string> {
58
+ const sign = new SignJWT(payload)
59
+ .setProtectedHeader({
60
+ alg: options?.alg ? options?.alg : 'HS256',
61
+ })
62
+ .setIssuedAt(options?.iat)
63
+ .setIssuer(options?.iss ? options?.iss : 'urn:example:issuer')
64
+ .setAudience(options?.aud ? options?.aud : 'urn:example:audience')
65
+ .setExpirationTime(options?.exp ? options?.exp : '2h');
66
+ return sign.sign(secret, options?.options);
67
+ }
68
+
69
+ /**
70
+ * decodes a protected header with jose
71
+ * @param token
72
+ * @returns
73
+ */
74
+ export function decodeProtectedHeaderJWT(token: string | object): ProtectedHeaderParameters {
75
+ return decodeProtectedHeader(token);
76
+ }
77
+
78
+ /**
79
+ * decodes a jwt token
80
+ * @param jwt
81
+ * @returns
82
+ */
83
+ export function decodeJWT<PayloadType = JWTPayload>(jwt: string): PayloadType & JWTPayload {
84
+ return decodeJwt<PayloadType>(jwt)
85
+ }
@@ -1,6 +1,6 @@
1
1
  import { Logger } from "@miqro/core";
2
2
  import { chmodSync, constants, mkdirSync, writeFileSync } from "node:fs";
3
- import { dirname, extname, join, relative, resolve } from "node:path";
3
+ 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";
@@ -66,22 +66,22 @@ export async function inflateAppForSea(logger: Logger, inflateDir: string, servi
66
66
 
67
67
  writeFile(logger, join(inflateDir, "sea", "package.json"), `{ "type": "module", "private": true }`);
68
68
 
69
- writeFile(logger, join(inflateDir, "sea", "app.cjs"), `const { ServerInterfaceImpl, ServerRequestHandler, WebSocketManager, initGlobals, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
69
+ writeFile(logger, join(inflateDir, "sea", "app.cjs"), `const { createServerInterface, ServerRequestHandler, WebSocketManager, initGlobals, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
70
70
 
71
71
  async function main() {
72
72
  const PORT = process.env["PORT"] ? process.env["PORT"] : 8080;
73
- const logProvider = new LogProvider();
73
+ const loggerProvider = new LogProvider();
74
74
  const localCache = new LocalCache();
75
75
  const cache = new ClusterCache();
76
76
  const webSocketManager = new WebSocketManager();
77
77
  const dbManager = new DBManager();
78
78
  await initGlobals();
79
- const serverInterface = new ServerInterfaceImpl({
79
+ const serverInterface = createServerInterface({
80
80
  cache,
81
81
  localCache,
82
- logProvider,
82
+ loggerProvider,
83
83
  wsManager: webSocketManager,
84
- logger: logProvider.getLogger("server"),
84
+ logger: loggerProvider.getLogger("server"),
85
85
  dbManager,
86
86
  port: PORT
87
87
  });
@@ -133,9 +133,10 @@ ${Object.keys(serviceRouteFileMap)
133
133
  .map(filePath => serviceRouteFileMap[filePath])
134
134
  .filter(data => data.previewMethod === "api")
135
135
  .map(data => data.routes.map(r => {
136
- const rPath = r.inflatePath;
136
+ const rPath = join(relative(cwd(), dirname(data.filePath)), basename(data.filePath));
137
137
  if (rPath) {
138
- const apiInflatedPath = join("..", "..", service, "http", rPath + ".api.js");
138
+ const rPathExt = extname(rPath);
139
+ const apiInflatedPath = join("..", "..", rPath.substring(0, rPath.length - rPathExt.length) + ".js");
139
140
  return ` await appendAPIModule(router, "../../${service}/http", "./${apiInflatedPath}", (await import("./${apiInflatedPath}")).default);`;
140
141
  } else {
141
142
  return "";
@@ -8,7 +8,7 @@ import { cwd } from "node:process";
8
8
  import { DBConfig, NamedMigration } from "../types.js";
9
9
 
10
10
  export interface MigrationModule extends Migration, NamedMigration {
11
-
11
+
12
12
  }
13
13
 
14
14
  export async function inflateDBConfig(logger: Logger, service: string, dbConfigList: DBConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]) {
@@ -26,6 +26,8 @@ export async function inflateDBConfig(logger: Logger, service: string, dbConfigL
26
26
  dbConfigList.push(config);
27
27
  }
28
28
  }
29
+
30
+
29
31
  if (config) {
30
32
  if (inflateDir) {
31
33
  const inflatePath = resolve(inflateDir, service, "db.js");
@@ -27,6 +27,7 @@ export interface RouteFileMap {
27
27
  options?: RouterHandlerOptions;
28
28
  inflatePath?: string;
29
29
  }[];
30
+ filePath: string;
30
31
  service: string;
31
32
  previewMethod: "api" | "html" | null;
32
33
  }
@@ -93,6 +94,7 @@ function createStaticRoute(service: string, logger: Logger, router: Router, dir:
93
94
  path: normalizePath(path)
94
95
  }],
95
96
  service,
97
+ filePath: file.filePath,
96
98
  previewMethod: "html"
97
99
  };
98
100
 
@@ -185,6 +187,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
185
187
  routeFileMap[file.filePath] = {
186
188
  routes,
187
189
  service,
190
+ filePath: file.filePath,
188
191
  previewMethod: "api"
189
192
  };
190
193
 
@@ -230,6 +233,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
230
233
  routeFileMap[file.filePath] = {
231
234
  routes,
232
235
  service,
236
+ filePath: file.filePath,
233
237
  previewMethod: "html"
234
238
  };
235
239
 
@@ -297,6 +301,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
297
301
 
298
302
  routeFileMap[file.filePath] = {
299
303
  routes,
304
+ filePath: file.filePath,
300
305
  service,
301
306
  previewMethod: "html"
302
307
  };
@@ -375,6 +380,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
375
380
  method: "GET",
376
381
  path
377
382
  }],
383
+ filePath: file.filePath,
378
384
  service,
379
385
  previewMethod: "html"
380
386
  };
@@ -428,6 +434,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
428
434
  path
429
435
  }],
430
436
  service,
437
+ filePath: file.filePath,
431
438
  previewMethod: "html"
432
439
  };
433
440
 
@@ -487,6 +494,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
487
494
  method: "GET",
488
495
  path
489
496
  }],
497
+ filePath: file.filePath,
490
498
  service,
491
499
  previewMethod: "html"
492
500
  };
@@ -545,6 +553,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
545
553
  path
546
554
  }],
547
555
  service,
556
+ filePath: file.filePath,
548
557
  previewMethod: "html"
549
558
  };
550
559
 
@@ -7,7 +7,7 @@ import { importWSConfigModule, InflateError, inflateJSX } from "../common/jsx.js
7
7
  import { getWSConfigPath } from "../common/paths.js";
8
8
  import { WSConfig } from "../types.js";
9
9
 
10
- export async function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<false | WSConfig> {
10
+ export async function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<void> {
11
11
  const wsPath = getWSConfigPath(servicePath); // resolve(process.cwd(), service, "ws.ts");
12
12
 
13
13
  if (wsPath) {
@@ -21,6 +21,7 @@ export async function inflateWSConfig(logger: Logger, servicePath: string, servi
21
21
  wsConfigList.push(wsConfig);
22
22
  //wsMap[wsConfig.path] = { name: service, options: wsConfig };
23
23
  }
24
+
24
25
  if (inflateDir) {
25
26
  const inflatePath = resolve(inflateDir, service, "ws.js");
26
27
  mkdirSync(dirname(inflatePath), {
@@ -34,7 +35,7 @@ export async function inflateWSConfig(logger: Logger, servicePath: string, servi
34
35
  logger
35
36
  }));
36
37
  }
37
- return wsConfig;
38
+ //return wsConfigList;
38
39
  } catch (e) {
39
40
  errors.push({
40
41
  filePath: wsPath,
@@ -42,7 +43,7 @@ export async function inflateWSConfig(logger: Logger, servicePath: string, servi
42
43
  });
43
44
  logger.error("error with " + wsPath);
44
45
  logger.error(e);
45
- return false;
46
+ //return false;
46
47
  }
47
48
  }
48
49
  }
package/src/lib.ts CHANGED
@@ -10,10 +10,10 @@ export { DBManager } from "./services/utils/db-manager.js";
10
10
  export { LogProvider, LogProviderOptions } from "./services/utils/log.js";
11
11
  export { Miqro, MiqroOptions, ServerRequestHandler } from "./services/app.js";
12
12
  export { initGlobals, assertGlobalTampered } from "./services/globals.js";
13
- export { appendAPIModule } from "./inflate/utils/sea-utils.js";
14
13
 
15
14
  //exported for --inflate-sea
16
- export { ServerInterfaceImpl, ServerInterfaceImplOptions } from "./services/utils/server-interface.js";
15
+ export { appendAPIModule } from "./inflate/utils/sea-utils.js";
16
+ export { createServerInterface, ServerInterfaceImplOptions } from "./services/utils/server-interface.js";
17
17
  export { App, LoggerHandler, Router } from "@miqro/core";
18
18
  export { migration } from "@miqro/query";
19
19
 
package/src/main.ts CHANGED
@@ -11,7 +11,7 @@ import { TEST_SOCKET } from "./common/paths.js";
11
11
  import { Logger } from "@miqro/core";
12
12
 
13
13
  async function main(args: Arguments) {
14
- if (args.installTypes || args.installTSConfig) {
14
+ if (args.installTypes || args.installTSConfig || args.installMiqroJSON) {
15
15
  await installTypings(args, new Logger(""));
16
16
  process.exit(EXIT_CODES.NORMAL_EXIT);
17
17
  } else {
@@ -20,6 +20,8 @@ async function main(args: Arguments) {
20
20
  name: args.name ? args.name : undefined,
21
21
  port: args.test ? TEST_SOCKET : args.port,
22
22
  services: args.services,
23
+ browser: args.browser,
24
+ logFile: args.logFile,
23
25
  hotreload: args.test ? false : args.hotreload
24
26
  });
25
27
  // check arguments
@@ -25,7 +25,7 @@ import { setupExitHandlers } from "../common/exit.js";
25
25
  import { inflateDBConfig, inflateDBMigrations, MigrationModule } from "../inflate/setup-db.js";
26
26
  import { getServicePath } from "../common/paths.js";
27
27
  import { LogConfigMap } from "../inflate/setup-log.js";
28
- import { ServerInterfaceImpl } from "./utils/server-interface.js";
28
+ import { createServerInterface } from "./utils/server-interface.js";
29
29
  import { getPORT, importMiqroJSON } from "../common/arguments.js";
30
30
  import { createLogProviderOptions } from "./utils/log-transport.js";
31
31
  import { createAdminInterface } from "./utils/admin-interface.js";
@@ -39,6 +39,8 @@ export interface MiqroOptions {
39
39
  services: string[];
40
40
  editor: boolean;
41
41
  port: string;
42
+ browser?: string | boolean;
43
+ logFile?: string | boolean;
42
44
  hotreload?: boolean;
43
45
  }
44
46
 
@@ -137,6 +139,7 @@ export class Miqro {
137
139
  this.localCache = new LocalCache(`MiqroApplicationLocalCache[${this.options.name}]`, this.logger);
138
140
  this.webSocketManager = new WebSocketManager({
139
141
  logger: this.logger,
142
+ loggerProvider: this.loggerProvider,
140
143
  name: `MiqroApplicationWebsocketManager[${this.options.name}]`,
141
144
  avoidLogSocket: this.options.editor
142
145
  });
@@ -148,16 +151,17 @@ export class Miqro {
148
151
  logger: this.logger
149
152
  });
150
153
 
151
- this.serverInterface = new ServerInterfaceImpl({
154
+ this.serverInterface = createServerInterface({
152
155
  cache: this.cache,
153
- localCache: this.localCache,
154
156
  dbManager: this.dbManager,
155
- wsManager: this.webSocketManager,
157
+ localCache: this.localCache,
158
+ webSocketManager: this.webSocketManager,
156
159
  app: this,
157
160
  logger: this.logger,
158
161
  loggerProvider: this.loggerProvider,
159
162
  port: this.options.port
160
163
  });
164
+
161
165
  this.serverRequestHandler = ServerRequestHandler(this.serverInterface);
162
166
 
163
167
  this.adminInterface = createAdminInterface(this);
@@ -249,9 +253,9 @@ export class Miqro {
249
253
  dbConfig: DBConfig;
250
254
  migrations: MigrationModule[];
251
255
  }[] = [];
252
- const dbConfigList: DBConfig[] = [];
256
+ const dbConfigListALL: DBConfig[] = [];
253
257
  for (const service of this.options.services) {
254
- const dbConfig = await inflateDBConfig(this.logger, service, dbConfigList, options?.inflateSea ? options?.inflateDir : undefined, errors);
258
+ const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : undefined, errors);
255
259
  if (dbConfig) {
256
260
  const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : undefined, errors);
257
261
  dbList.push({