miqro 6.2.8 → 6.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { createNodeRuntime } from "@miqro/jsx-node";
2
- import { basename, dirname, relative, resolve } from "node:path";
2
+ import { basename, dirname, extname, relative, resolve } from "node:path";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { mkdirSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
5
5
  import { Parser } from "@miqro/parser";
@@ -264,7 +264,8 @@ export const DocConfigSchema = {
264
264
  }
265
265
  };
266
266
  export async function importAPIRoute(inFile, logger) {
267
- const mod = (await importJSXFile(inFile, logger)).default;
267
+ const isCJS = extname(inFile) === ".cjs";
268
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
268
269
  const module = typeof mod === "function" ? { handler: mod } : parser.parse(mod, APIRouteSchema, basename(inFile));
269
270
  if (module !== undefined) {
270
271
  return module;
@@ -274,7 +275,9 @@ export async function importAPIRoute(inFile, logger) {
274
275
  }
275
276
  }
276
277
  export async function importMigrationModule(inFile, logger) {
277
- const module = parser.parse((await importJSXFile(inFile, logger)).default, MigrationSchema, basename(inFile));
278
+ const isCJS = extname(inFile) === ".cjs";
279
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
280
+ const module = parser.parse(mod, MigrationSchema, basename(inFile));
278
281
  if (module !== undefined) {
279
282
  return module;
280
283
  }
@@ -305,7 +308,9 @@ export async function importJSONModule(inFile, logger) {
305
308
  }
306
309
  }
307
310
  export async function importAuthModule(inFile, logger) {
308
- const module = parser.parse((await importJSXFile(inFile, logger)).default, AuthConfigSchema, basename(inFile));
311
+ const isCJS = extname(inFile) === ".cjs";
312
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
313
+ const module = parser.parse(mod, AuthConfigSchema, basename(inFile));
309
314
  if (module !== undefined) {
310
315
  return module;
311
316
  }
@@ -314,7 +319,9 @@ export async function importAuthModule(inFile, logger) {
314
319
  }
315
320
  }
316
321
  export async function importMiddlewareConfigModule(inFile, logger) {
317
- const module = parser.parse((await importJSXFile(inFile, logger)).default, MiddlewareConfigSchema, basename(inFile));
322
+ const isCJS = extname(inFile) === ".cjs";
323
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
324
+ const module = parser.parse(mod, MiddlewareConfigSchema, basename(inFile));
318
325
  if (module !== undefined) {
319
326
  return module;
320
327
  }
@@ -323,7 +330,9 @@ export async function importMiddlewareConfigModule(inFile, logger) {
323
330
  }
324
331
  }
325
332
  export async function importErrorConfigModule(inFile, logger) {
326
- const module = parser.parse((await importJSXFile(inFile, logger)).default, ErrorConfigSchema, basename(inFile));
333
+ const isCJS = extname(inFile) === ".cjs";
334
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
335
+ const module = parser.parse(mod, ErrorConfigSchema, basename(inFile));
327
336
  if (module !== undefined) {
328
337
  return module;
329
338
  }
@@ -332,7 +341,9 @@ export async function importErrorConfigModule(inFile, logger) {
332
341
  }
333
342
  }
334
343
  export async function importDocConfigModule(inFile, logger) {
335
- const module = parser.parse((await importJSXFile(inFile, logger)).default, DocConfigSchema, basename(inFile));
344
+ const isCJS = extname(inFile) === ".cjs";
345
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
346
+ const module = parser.parse(mod, DocConfigSchema, basename(inFile));
336
347
  if (module !== undefined) {
337
348
  return module;
338
349
  }
@@ -341,7 +352,9 @@ export async function importDocConfigModule(inFile, logger) {
341
352
  }
342
353
  }
343
354
  export async function importConfigConfigModule(inFile, logger) {
344
- const module = parser.parse((await importJSXFile(inFile, logger)).default, MiddlewareConfigSchema, basename(inFile));
355
+ const isCJS = extname(inFile) === ".cjs";
356
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
357
+ const module = parser.parse(mod, MiddlewareConfigSchema, basename(inFile));
345
358
  if (module !== undefined) {
346
359
  return module;
347
360
  }
@@ -350,7 +363,9 @@ export async function importConfigConfigModule(inFile, logger) {
350
363
  }
351
364
  }
352
365
  export async function importCORSModule(inFile, logger) {
353
- const module = parser.parse((await importJSXFile(inFile, logger)).default, CORSOptionsSchema, basename(inFile));
366
+ const isCJS = extname(inFile) === ".cjs";
367
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
368
+ const module = parser.parse(mod, CORSOptionsSchema, basename(inFile));
354
369
  if (module !== undefined) {
355
370
  return module;
356
371
  }
@@ -359,7 +374,9 @@ export async function importCORSModule(inFile, logger) {
359
374
  }
360
375
  }
361
376
  export async function importWSConfigModule(inFile, logger) {
362
- const module = parser.parse((await importJSXFile(inFile, logger)).default, WSConfigSchema, basename(inFile));
377
+ const isCJS = extname(inFile) === ".cjs";
378
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
379
+ const module = parser.parse(mod, WSConfigSchema, basename(inFile));
363
380
  if (module !== undefined) {
364
381
  return module;
365
382
  }
@@ -368,7 +385,9 @@ export async function importWSConfigModule(inFile, logger) {
368
385
  }
369
386
  }
370
387
  export async function importDBConfigModule(inFile, logger) {
371
- const module = parser.parse((await importJSXFile(inFile, logger)).default, DBConfigSchema, basename(inFile));
388
+ const isCJS = extname(inFile) === ".cjs";
389
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
390
+ const module = parser.parse(mod, DBConfigSchema, basename(inFile));
372
391
  if (module !== undefined) {
373
392
  return module;
374
393
  }
@@ -386,7 +405,9 @@ export async function importLogConfigModule(inFile, logger) {
386
405
  }
387
406
  }
388
407
  export async function importServerConfigModule(inFile, logger) {
389
- const module = parser.parse((await importJSXFile(inFile, logger)).default, ServerConfigSchema, basename(inFile));
408
+ const isCJS = extname(inFile) === ".cjs";
409
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
410
+ const module = parser.parse(mod, ServerConfigSchema, basename(inFile));
390
411
  if (module !== undefined) {
391
412
  return module;
392
413
  }
@@ -9,60 +9,30 @@ export const TEST_SOCKET = resolve(JSX_TMP_DIR, `test.${randomUUID()}.sock`);
9
9
  export function getServicePath(service) {
10
10
  return resolve(cwd(), service);
11
11
  }
12
- export function getLogConfigPath(servicePath) {
13
- const logConfigPath = resolve(servicePath, "log.ts");
14
- const logConfigPathJS = resolve(servicePath, "log.js");
15
- if (existsSync(logConfigPath) && !statSync(logConfigPath).isDirectory()) {
16
- return logConfigPath;
17
- }
18
- else if (existsSync(logConfigPathJS) && !statSync(logConfigPathJS).isDirectory()) {
19
- return logConfigPathJS;
12
+ const EXTENSIONS = [".ts", ".js", ".cjs"];
13
+ function getFilePath(dirname, name, extensions) {
14
+ for (const ex of extensions) {
15
+ const path = resolve(dirname, name + ex);
16
+ if (existsSync(path) && !statSync(path).isDirectory()) {
17
+ return path;
18
+ }
20
19
  }
21
20
  return false;
22
21
  }
22
+ export function getLogConfigPath(servicePath) {
23
+ return getFilePath(servicePath, "log", EXTENSIONS);
24
+ }
23
25
  export function getCORSConfigPath(servicePath) {
24
- const corsPath = resolve(servicePath, "cors.ts");
25
- const corsPathJS = resolve(servicePath, "cors.js");
26
- if (existsSync(corsPath) && !statSync(corsPath).isDirectory()) {
27
- return corsPath;
28
- }
29
- else if (existsSync(corsPathJS) && !statSync(corsPathJS).isDirectory()) {
30
- return corsPathJS;
31
- }
32
- return false;
26
+ return getFilePath(servicePath, "cors", EXTENSIONS);
33
27
  }
34
28
  export function getServerConfigPath(servicePath) {
35
- const serverPath = resolve(servicePath, "server.ts");
36
- const serverPathJS = resolve(servicePath, "server.js");
37
- if (existsSync(serverPath)) {
38
- return serverPath;
39
- }
40
- else if (existsSync(serverPathJS)) {
41
- return serverPathJS;
42
- }
43
- return false;
29
+ return getFilePath(servicePath, "server", EXTENSIONS);
44
30
  }
45
31
  export function getWSConfigPath(servicePath) {
46
- const wsPath = resolve(servicePath, "ws.ts");
47
- const wsPathJS = resolve(servicePath, "ws.js");
48
- if (existsSync(wsPath)) {
49
- return wsPath;
50
- }
51
- else if (existsSync(wsPathJS)) {
52
- return wsPathJS;
53
- }
54
- return false;
32
+ return getFilePath(servicePath, "ws", EXTENSIONS);
55
33
  }
56
34
  export function getDBConfigPath(servicePath) {
57
- const dbPath = resolve(servicePath, "db.ts");
58
- const dbPathJS = resolve(servicePath, "db.js");
59
- if (existsSync(dbPath)) {
60
- return dbPath;
61
- }
62
- else if (existsSync(dbPathJS)) {
63
- return dbPathJS;
64
- }
65
- return false;
35
+ return getFilePath(servicePath, "db", EXTENSIONS);
66
36
  }
67
37
  export function getStaticFilesPath(servicePath) {
68
38
  const staticFilesPath = resolve(servicePath, "static");
@@ -72,37 +42,13 @@ export function getStaticFilesPath(servicePath) {
72
42
  return false;
73
43
  }
74
44
  export function getMiddlewareConfigPath(servicePath) {
75
- const middlewarePath = resolve(servicePath, "middleware.ts");
76
- const middlewarePathJS = resolve(servicePath, "middleware.js");
77
- if (existsSync(middlewarePath) && !statSync(middlewarePath).isDirectory()) {
78
- return middlewarePath;
79
- }
80
- else if (existsSync(middlewarePathJS) && !statSync(middlewarePathJS).isDirectory()) {
81
- return middlewarePathJS;
82
- }
83
- return false;
45
+ return getFilePath(servicePath, "middleware", EXTENSIONS);
84
46
  }
85
47
  export function getErrorConfigPath(servicePath) {
86
- const errorPath = resolve(servicePath, "catch.ts");
87
- const errorPathJS = resolve(servicePath, "catch.js");
88
- if (existsSync(errorPath) && !statSync(errorPath).isDirectory()) {
89
- return errorPath;
90
- }
91
- else if (existsSync(errorPathJS) && !statSync(errorPathJS).isDirectory()) {
92
- return errorPathJS;
93
- }
94
- return false;
48
+ return getFilePath(servicePath, "catch", EXTENSIONS);
95
49
  }
96
50
  export function getDocConfigPath(servicePath) {
97
- const docPath = resolve(servicePath, "doc.ts");
98
- const docPathJS = resolve(servicePath, "doc.js");
99
- if (existsSync(docPath) && !statSync(docPath).isDirectory()) {
100
- return docPath;
101
- }
102
- else if (existsSync(docPathJS) && !statSync(docPathJS).isDirectory()) {
103
- return docPathJS;
104
- }
105
- return false;
51
+ return getFilePath(servicePath, "doc", EXTENSIONS);
106
52
  }
107
53
  export function getMiqroJSONPath() {
108
54
  const miqroRCPath = resolve(cwd(), "miqro.json");
@@ -112,15 +58,7 @@ export function getMiqroJSONPath() {
112
58
  return false;
113
59
  }
114
60
  export function getAuthConfigPath(servicePath) {
115
- const authPath = resolve(servicePath, "auth.ts");
116
- const authPathJS = resolve(servicePath, "auth.js");
117
- if (existsSync(authPath) && !statSync(authPath).isDirectory()) {
118
- return authPath;
119
- }
120
- else if (existsSync(authPathJS) && !statSync(authPathJS).isDirectory()) {
121
- return authPathJS;
122
- }
123
- return false;
61
+ return getFilePath(servicePath, "auth", EXTENSIONS);
124
62
  }
125
63
  export function getHTTPRouterPath(servicePath) {
126
64
  const apiRouterPath = resolve(servicePath, "http");
package/build/lib.cjs CHANGED
@@ -11376,55 +11376,30 @@ var TEST_SOCKET = (0, import_node_path3.resolve)(JSX_TMP_DIR, `test.${(0, import
11376
11376
  function getServicePath(service) {
11377
11377
  return (0, import_node_path3.resolve)((0, import_node_process2.cwd)(), service);
11378
11378
  }
11379
- function getLogConfigPath(servicePath) {
11380
- const logConfigPath = (0, import_node_path3.resolve)(servicePath, "log.ts");
11381
- const logConfigPathJS = (0, import_node_path3.resolve)(servicePath, "log.js");
11382
- if ((0, import_node_fs4.existsSync)(logConfigPath) && !(0, import_node_fs4.statSync)(logConfigPath).isDirectory()) {
11383
- return logConfigPath;
11384
- } else if ((0, import_node_fs4.existsSync)(logConfigPathJS) && !(0, import_node_fs4.statSync)(logConfigPathJS).isDirectory()) {
11385
- return logConfigPathJS;
11379
+ var EXTENSIONS = [".ts", ".js", ".cjs"];
11380
+ function getFilePath(dirname21, name, extensions) {
11381
+ for (const ex of extensions) {
11382
+ const path = (0, import_node_path3.resolve)(dirname21, name + ex);
11383
+ if ((0, import_node_fs4.existsSync)(path) && !(0, import_node_fs4.statSync)(path).isDirectory()) {
11384
+ return path;
11385
+ }
11386
11386
  }
11387
11387
  return false;
11388
11388
  }
11389
+ function getLogConfigPath(servicePath) {
11390
+ return getFilePath(servicePath, "log", EXTENSIONS);
11391
+ }
11389
11392
  function getCORSConfigPath(servicePath) {
11390
- const corsPath = (0, import_node_path3.resolve)(servicePath, "cors.ts");
11391
- const corsPathJS = (0, import_node_path3.resolve)(servicePath, "cors.js");
11392
- if ((0, import_node_fs4.existsSync)(corsPath) && !(0, import_node_fs4.statSync)(corsPath).isDirectory()) {
11393
- return corsPath;
11394
- } else if ((0, import_node_fs4.existsSync)(corsPathJS) && !(0, import_node_fs4.statSync)(corsPathJS).isDirectory()) {
11395
- return corsPathJS;
11396
- }
11397
- return false;
11393
+ return getFilePath(servicePath, "cors", EXTENSIONS);
11398
11394
  }
11399
11395
  function getServerConfigPath(servicePath) {
11400
- const serverPath = (0, import_node_path3.resolve)(servicePath, "server.ts");
11401
- const serverPathJS = (0, import_node_path3.resolve)(servicePath, "server.js");
11402
- if ((0, import_node_fs4.existsSync)(serverPath)) {
11403
- return serverPath;
11404
- } else if ((0, import_node_fs4.existsSync)(serverPathJS)) {
11405
- return serverPathJS;
11406
- }
11407
- return false;
11396
+ return getFilePath(servicePath, "server", EXTENSIONS);
11408
11397
  }
11409
11398
  function getWSConfigPath(servicePath) {
11410
- const wsPath = (0, import_node_path3.resolve)(servicePath, "ws.ts");
11411
- const wsPathJS = (0, import_node_path3.resolve)(servicePath, "ws.js");
11412
- if ((0, import_node_fs4.existsSync)(wsPath)) {
11413
- return wsPath;
11414
- } else if ((0, import_node_fs4.existsSync)(wsPathJS)) {
11415
- return wsPathJS;
11416
- }
11417
- return false;
11399
+ return getFilePath(servicePath, "ws", EXTENSIONS);
11418
11400
  }
11419
11401
  function getDBConfigPath(servicePath) {
11420
- const dbPath = (0, import_node_path3.resolve)(servicePath, "db.ts");
11421
- const dbPathJS = (0, import_node_path3.resolve)(servicePath, "db.js");
11422
- if ((0, import_node_fs4.existsSync)(dbPath)) {
11423
- return dbPath;
11424
- } else if ((0, import_node_fs4.existsSync)(dbPathJS)) {
11425
- return dbPathJS;
11426
- }
11427
- return false;
11402
+ return getFilePath(servicePath, "db", EXTENSIONS);
11428
11403
  }
11429
11404
  function getStaticFilesPath(servicePath) {
11430
11405
  const staticFilesPath = (0, import_node_path3.resolve)(servicePath, "static");
@@ -11434,44 +11409,16 @@ function getStaticFilesPath(servicePath) {
11434
11409
  return false;
11435
11410
  }
11436
11411
  function getMiddlewareConfigPath(servicePath) {
11437
- const middlewarePath = (0, import_node_path3.resolve)(servicePath, "middleware.ts");
11438
- const middlewarePathJS = (0, import_node_path3.resolve)(servicePath, "middleware.js");
11439
- if ((0, import_node_fs4.existsSync)(middlewarePath) && !(0, import_node_fs4.statSync)(middlewarePath).isDirectory()) {
11440
- return middlewarePath;
11441
- } else if ((0, import_node_fs4.existsSync)(middlewarePathJS) && !(0, import_node_fs4.statSync)(middlewarePathJS).isDirectory()) {
11442
- return middlewarePathJS;
11443
- }
11444
- return false;
11412
+ return getFilePath(servicePath, "middleware", EXTENSIONS);
11445
11413
  }
11446
11414
  function getErrorConfigPath(servicePath) {
11447
- const errorPath = (0, import_node_path3.resolve)(servicePath, "catch.ts");
11448
- const errorPathJS = (0, import_node_path3.resolve)(servicePath, "catch.js");
11449
- if ((0, import_node_fs4.existsSync)(errorPath) && !(0, import_node_fs4.statSync)(errorPath).isDirectory()) {
11450
- return errorPath;
11451
- } else if ((0, import_node_fs4.existsSync)(errorPathJS) && !(0, import_node_fs4.statSync)(errorPathJS).isDirectory()) {
11452
- return errorPathJS;
11453
- }
11454
- return false;
11415
+ return getFilePath(servicePath, "catch", EXTENSIONS);
11455
11416
  }
11456
11417
  function getDocConfigPath(servicePath) {
11457
- const docPath = (0, import_node_path3.resolve)(servicePath, "doc.ts");
11458
- const docPathJS = (0, import_node_path3.resolve)(servicePath, "doc.js");
11459
- if ((0, import_node_fs4.existsSync)(docPath) && !(0, import_node_fs4.statSync)(docPath).isDirectory()) {
11460
- return docPath;
11461
- } else if ((0, import_node_fs4.existsSync)(docPathJS) && !(0, import_node_fs4.statSync)(docPathJS).isDirectory()) {
11462
- return docPathJS;
11463
- }
11464
- return false;
11418
+ return getFilePath(servicePath, "doc", EXTENSIONS);
11465
11419
  }
11466
11420
  function getAuthConfigPath(servicePath) {
11467
- const authPath = (0, import_node_path3.resolve)(servicePath, "auth.ts");
11468
- const authPathJS = (0, import_node_path3.resolve)(servicePath, "auth.js");
11469
- if ((0, import_node_fs4.existsSync)(authPath) && !(0, import_node_fs4.statSync)(authPath).isDirectory()) {
11470
- return authPath;
11471
- } else if ((0, import_node_fs4.existsSync)(authPathJS) && !(0, import_node_fs4.statSync)(authPathJS).isDirectory()) {
11472
- return authPathJS;
11473
- }
11474
- return false;
11421
+ return getFilePath(servicePath, "auth", EXTENSIONS);
11475
11422
  }
11476
11423
  function getHTTPRouterPath(servicePath) {
11477
11424
  const apiRouterPath = (0, import_node_path3.resolve)(servicePath, "http");
@@ -14550,7 +14497,8 @@ var DocConfigSchema = {
14550
14497
  }
14551
14498
  };
14552
14499
  async function importAPIRoute(inFile, logger) {
14553
- const mod = (await importJSXFile(inFile, logger)).default;
14500
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14501
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14554
14502
  const module2 = typeof mod === "function" ? { handler: mod } : parser2.parse(mod, APIRouteSchema, (0, import_node_path5.basename)(inFile));
14555
14503
  if (module2 !== void 0) {
14556
14504
  return module2;
@@ -14559,7 +14507,9 @@ async function importAPIRoute(inFile, logger) {
14559
14507
  }
14560
14508
  }
14561
14509
  async function importMigrationModule(inFile, logger) {
14562
- const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, MigrationSchema, (0, import_node_path5.basename)(inFile));
14510
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14511
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14512
+ const module2 = parser2.parse(mod, MigrationSchema, (0, import_node_path5.basename)(inFile));
14563
14513
  if (module2 !== void 0) {
14564
14514
  return module2;
14565
14515
  } else {
@@ -14587,7 +14537,9 @@ async function importJSONModule(inFile, logger) {
14587
14537
  }
14588
14538
  }
14589
14539
  async function importAuthModule(inFile, logger) {
14590
- const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, AuthConfigSchema, (0, import_node_path5.basename)(inFile));
14540
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14541
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14542
+ const module2 = parser2.parse(mod, AuthConfigSchema, (0, import_node_path5.basename)(inFile));
14591
14543
  if (module2 !== void 0) {
14592
14544
  return module2;
14593
14545
  } else {
@@ -14595,7 +14547,9 @@ async function importAuthModule(inFile, logger) {
14595
14547
  }
14596
14548
  }
14597
14549
  async function importMiddlewareConfigModule(inFile, logger) {
14598
- const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, MiddlewareConfigSchema, (0, import_node_path5.basename)(inFile));
14550
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14551
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14552
+ const module2 = parser2.parse(mod, MiddlewareConfigSchema, (0, import_node_path5.basename)(inFile));
14599
14553
  if (module2 !== void 0) {
14600
14554
  return module2;
14601
14555
  } else {
@@ -14603,7 +14557,9 @@ async function importMiddlewareConfigModule(inFile, logger) {
14603
14557
  }
14604
14558
  }
14605
14559
  async function importErrorConfigModule(inFile, logger) {
14606
- const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, ErrorConfigSchema, (0, import_node_path5.basename)(inFile));
14560
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14561
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14562
+ const module2 = parser2.parse(mod, ErrorConfigSchema, (0, import_node_path5.basename)(inFile));
14607
14563
  if (module2 !== void 0) {
14608
14564
  return module2;
14609
14565
  } else {
@@ -14611,7 +14567,9 @@ async function importErrorConfigModule(inFile, logger) {
14611
14567
  }
14612
14568
  }
14613
14569
  async function importDocConfigModule(inFile, logger) {
14614
- const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, DocConfigSchema, (0, import_node_path5.basename)(inFile));
14570
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14571
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14572
+ const module2 = parser2.parse(mod, DocConfigSchema, (0, import_node_path5.basename)(inFile));
14615
14573
  if (module2 !== void 0) {
14616
14574
  return module2;
14617
14575
  } else {
@@ -14619,7 +14577,9 @@ async function importDocConfigModule(inFile, logger) {
14619
14577
  }
14620
14578
  }
14621
14579
  async function importCORSModule(inFile, logger) {
14622
- const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, CORSOptionsSchema, (0, import_node_path5.basename)(inFile));
14580
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14581
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14582
+ const module2 = parser2.parse(mod, CORSOptionsSchema, (0, import_node_path5.basename)(inFile));
14623
14583
  if (module2 !== void 0) {
14624
14584
  return module2;
14625
14585
  } else {
@@ -14627,7 +14587,9 @@ async function importCORSModule(inFile, logger) {
14627
14587
  }
14628
14588
  }
14629
14589
  async function importWSConfigModule(inFile, logger) {
14630
- const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, WSConfigSchema, (0, import_node_path5.basename)(inFile));
14590
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14591
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14592
+ const module2 = parser2.parse(mod, WSConfigSchema, (0, import_node_path5.basename)(inFile));
14631
14593
  if (module2 !== void 0) {
14632
14594
  return module2;
14633
14595
  } else {
@@ -14635,7 +14597,9 @@ async function importWSConfigModule(inFile, logger) {
14635
14597
  }
14636
14598
  }
14637
14599
  async function importDBConfigModule(inFile, logger) {
14638
- const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, DBConfigSchema, (0, import_node_path5.basename)(inFile));
14600
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14601
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14602
+ const module2 = parser2.parse(mod, DBConfigSchema, (0, import_node_path5.basename)(inFile));
14639
14603
  if (module2 !== void 0) {
14640
14604
  return module2;
14641
14605
  } else {
@@ -14651,7 +14615,9 @@ async function importLogConfigModule(inFile, logger) {
14651
14615
  }
14652
14616
  }
14653
14617
  async function importServerConfigModule(inFile, logger) {
14654
- const module2 = parser2.parse((await importJSXFile(inFile, logger)).default, ServerConfigSchema, (0, import_node_path5.basename)(inFile));
14618
+ const isCJS = (0, import_node_path5.extname)(inFile) === ".cjs";
14619
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
14620
+ const module2 = parser2.parse(mod, ServerConfigSchema, (0, import_node_path5.basename)(inFile));
14655
14621
  if (module2 !== void 0) {
14656
14622
  return module2;
14657
14623
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "6.2.8",
3
+ "version": "6.2.10",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "build/esm/src/lib.js",
package/src/common/jsx.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Runtime } from "@miqro/jsx";
2
2
  import { createNodeRuntime } from "@miqro/jsx-node";
3
- import { basename, dirname, relative, resolve } from "node:path";
3
+ import { basename, dirname, extname, relative, resolve } from "node:path";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { mkdirSync, readFileSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
6
6
  import { Request, Response, CORSOptions, Logger, APIRoute } from "@miqro/core";
@@ -80,7 +80,7 @@ export async function inflateJSX(inFile: string, options: InflateOptions): Promi
80
80
  ...DEFAULT_ESOPTION,
81
81
  entryPoints: [inFileTmp],
82
82
  minify: options.minify,
83
- platform: options.platform ? options.platform: DEFAULT_ESOPTION.platform
83
+ platform: options.platform ? options.platform : DEFAULT_ESOPTION.platform
84
84
  });
85
85
  if (CLEAR_JSX_CACHE) {
86
86
  logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
@@ -100,7 +100,7 @@ export async function inflateJSX(inFile: string, options: InflateOptions): Promi
100
100
  ...DEFAULT_ESOPTION,
101
101
  entryPoints: [inFileTmp],
102
102
  minify: options.minify,
103
- platform: options.platform ? options.platform: DEFAULT_ESOPTION.platform
103
+ platform: options.platform ? options.platform : DEFAULT_ESOPTION.platform
104
104
  });
105
105
  if (CLEAR_JSX_CACHE) {
106
106
  logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
@@ -317,7 +317,8 @@ export const DocConfigSchema: Schema<DocConfig> = {
317
317
  }
318
318
 
319
319
  export async function importAPIRoute(inFile: string, logger?: Logger) {
320
- const mod = (await importJSXFile(inFile, logger)).default;
320
+ const isCJS = extname(inFile) === ".cjs";
321
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
321
322
  const module = typeof mod === "function" ? { handler: mod } : parser.parse(mod, APIRouteSchema, basename(inFile));
322
323
  if (module !== undefined) {
323
324
  return module as APIRoute;
@@ -327,7 +328,9 @@ export async function importAPIRoute(inFile: string, logger?: Logger) {
327
328
  }
328
329
 
329
330
  export async function importMigrationModule(inFile: string, logger?: Logger) {
330
- const module = parser.parse((await importJSXFile(inFile, logger)).default, MigrationSchema, basename(inFile));
331
+ const isCJS = extname(inFile) === ".cjs";
332
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
333
+ const module = parser.parse(mod, MigrationSchema, basename(inFile));
331
334
  if (module !== undefined) {
332
335
  return module;
333
336
  } else {
@@ -358,7 +361,10 @@ export async function importJSONModule(inFile: string, logger?: Logger) {
358
361
  }
359
362
 
360
363
  export async function importAuthModule(inFile: string, logger?: Logger) {
361
- const module = parser.parse((await importJSXFile(inFile, logger)).default, AuthConfigSchema, basename(inFile));
364
+ const isCJS = extname(inFile) === ".cjs";
365
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
366
+
367
+ const module = parser.parse(mod, AuthConfigSchema, basename(inFile));
362
368
  if (module !== undefined) {
363
369
  return module;
364
370
  } else {
@@ -367,7 +373,10 @@ export async function importAuthModule(inFile: string, logger?: Logger) {
367
373
  }
368
374
 
369
375
  export async function importMiddlewareConfigModule(inFile: string, logger?: Logger) {
370
- const module = parser.parse((await importJSXFile(inFile, logger)).default, MiddlewareConfigSchema, basename(inFile));
376
+ const isCJS = extname(inFile) === ".cjs";
377
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
378
+
379
+ const module = parser.parse(mod, MiddlewareConfigSchema, basename(inFile));
371
380
  if (module !== undefined) {
372
381
  return module;
373
382
  } else {
@@ -376,7 +385,10 @@ export async function importMiddlewareConfigModule(inFile: string, logger?: Logg
376
385
  }
377
386
 
378
387
  export async function importErrorConfigModule(inFile: string, logger?: Logger) {
379
- const module = parser.parse((await importJSXFile(inFile, logger)).default, ErrorConfigSchema, basename(inFile));
388
+ const isCJS = extname(inFile) === ".cjs";
389
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
390
+
391
+ const module = parser.parse(mod, ErrorConfigSchema, basename(inFile));
380
392
  if (module !== undefined) {
381
393
  return module;
382
394
  } else {
@@ -385,7 +397,10 @@ export async function importErrorConfigModule(inFile: string, logger?: Logger) {
385
397
  }
386
398
 
387
399
  export async function importDocConfigModule(inFile: string, logger?: Logger) {
388
- const module = parser.parse((await importJSXFile(inFile, logger)).default, DocConfigSchema, basename(inFile));
400
+ const isCJS = extname(inFile) === ".cjs";
401
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
402
+
403
+ const module = parser.parse(mod, DocConfigSchema, basename(inFile));
389
404
  if (module !== undefined) {
390
405
  return module;
391
406
  } else {
@@ -394,7 +409,10 @@ export async function importDocConfigModule(inFile: string, logger?: Logger) {
394
409
  }
395
410
 
396
411
  export async function importConfigConfigModule(inFile: string, logger?: Logger) {
397
- const module = parser.parse((await importJSXFile(inFile, logger)).default, MiddlewareConfigSchema, basename(inFile));
412
+ const isCJS = extname(inFile) === ".cjs";
413
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
414
+
415
+ const module = parser.parse(mod, MiddlewareConfigSchema, basename(inFile));
398
416
  if (module !== undefined) {
399
417
  return module;
400
418
  } else {
@@ -403,7 +421,10 @@ export async function importConfigConfigModule(inFile: string, logger?: Logger)
403
421
  }
404
422
 
405
423
  export async function importCORSModule(inFile: string, logger?: Logger) {
406
- const module = parser.parse((await importJSXFile(inFile, logger)).default, CORSOptionsSchema, basename(inFile));
424
+ const isCJS = extname(inFile) === ".cjs";
425
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
426
+
427
+ const module = parser.parse(mod, CORSOptionsSchema, basename(inFile));
407
428
  if (module !== undefined) {
408
429
  return module;
409
430
  } else {
@@ -412,7 +433,10 @@ export async function importCORSModule(inFile: string, logger?: Logger) {
412
433
  }
413
434
 
414
435
  export async function importWSConfigModule(inFile: string, logger?: Logger) {
415
- const module = parser.parse((await importJSXFile(inFile, logger)).default, WSConfigSchema, basename(inFile));
436
+ const isCJS = extname(inFile) === ".cjs";
437
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
438
+
439
+ const module = parser.parse(mod, WSConfigSchema, basename(inFile));
416
440
  if (module !== undefined) {
417
441
  return module;
418
442
  } else {
@@ -421,7 +445,10 @@ export async function importWSConfigModule(inFile: string, logger?: Logger) {
421
445
  }
422
446
 
423
447
  export async function importDBConfigModule(inFile: string, logger?: Logger) {
424
- const module = parser.parse((await importJSXFile(inFile, logger)).default, DBConfigSchema, basename(inFile));
448
+ const isCJS = extname(inFile) === ".cjs";
449
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
450
+
451
+ const module = parser.parse(mod, DBConfigSchema, basename(inFile));
425
452
  if (module !== undefined) {
426
453
  return module;
427
454
  } else {
@@ -439,7 +466,10 @@ export async function importLogConfigModule(inFile: string, logger?: Logger) {
439
466
  }
440
467
 
441
468
  export async function importServerConfigModule(inFile: string, logger?: Logger) {
442
- const module = parser.parse((await importJSXFile(inFile, logger)).default, ServerConfigSchema, basename(inFile));
469
+ const isCJS = extname(inFile) === ".cjs";
470
+ const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
471
+
472
+ const module = parser.parse(mod, ServerConfigSchema, basename(inFile));
443
473
  if (module !== undefined) {
444
474
  return module;
445
475
  } else {
@@ -13,59 +13,36 @@ export function getServicePath(service: string) {
13
13
  return resolve(cwd(), service);
14
14
  }
15
15
 
16
- export function getLogConfigPath(servicePath: string) {
17
- const logConfigPath = resolve(servicePath, "log.ts");
18
- const logConfigPathJS = resolve(servicePath, "log.js");
19
- if (existsSync(logConfigPath) && !statSync(logConfigPath).isDirectory()) {
20
- return logConfigPath;
21
- } else if (existsSync(logConfigPathJS) && !statSync(logConfigPathJS).isDirectory()) {
22
- return logConfigPathJS;
16
+ const EXTENSIONS = [".ts", ".js", ".cjs"];
17
+
18
+ function getFilePath(dirname: string, name: string, extensions: string[]) {
19
+ for (const ex of extensions) {
20
+ const path = resolve(dirname, name + ex);
21
+ if (existsSync(path) && !statSync(path).isDirectory()) {
22
+ return path;
23
+ }
23
24
  }
24
25
  return false;
25
26
  }
26
27
 
28
+ export function getLogConfigPath(servicePath: string) {
29
+ return getFilePath(servicePath, "log", EXTENSIONS);
30
+ }
31
+
27
32
  export function getCORSConfigPath(servicePath: string) {
28
- const corsPath = resolve(servicePath, "cors.ts");
29
- const corsPathJS = resolve(servicePath, "cors.js");
30
- if (existsSync(corsPath) && !statSync(corsPath).isDirectory()) {
31
- return corsPath;
32
- } else if (existsSync(corsPathJS) && !statSync(corsPathJS).isDirectory()) {
33
- return corsPathJS;
34
- }
35
- return false;
33
+ return getFilePath(servicePath, "cors", EXTENSIONS);
36
34
  }
37
35
 
38
36
  export function getServerConfigPath(servicePath: string) {
39
- const serverPath = resolve(servicePath, "server.ts");
40
- const serverPathJS = resolve(servicePath, "server.js");
41
- if (existsSync(serverPath)) {
42
- return serverPath;
43
- } else if (existsSync(serverPathJS)) {
44
- return serverPathJS;
45
- }
46
- return false;
37
+ return getFilePath(servicePath, "server", EXTENSIONS);
47
38
  }
48
39
 
49
40
  export function getWSConfigPath(servicePath: string) {
50
- const wsPath = resolve(servicePath, "ws.ts");
51
- const wsPathJS = resolve(servicePath, "ws.js");
52
- if (existsSync(wsPath)) {
53
- return wsPath;
54
- } else if (existsSync(wsPathJS)) {
55
- return wsPathJS;
56
- }
57
- return false;
41
+ return getFilePath(servicePath, "ws", EXTENSIONS);
58
42
  }
59
43
 
60
44
  export function getDBConfigPath(servicePath: string) {
61
- const dbPath = resolve(servicePath, "db.ts");
62
- const dbPathJS = resolve(servicePath, "db.js");
63
- if (existsSync(dbPath)) {
64
- return dbPath;
65
- } else if (existsSync(dbPathJS)) {
66
- return dbPathJS;
67
- }
68
- return false;
45
+ return getFilePath(servicePath, "db", EXTENSIONS);
69
46
  }
70
47
 
71
48
  export function getStaticFilesPath(servicePath: string) {
@@ -77,36 +54,15 @@ export function getStaticFilesPath(servicePath: string) {
77
54
  }
78
55
 
79
56
  export function getMiddlewareConfigPath(servicePath: string) {
80
- const middlewarePath = resolve(servicePath, "middleware.ts");
81
- const middlewarePathJS = resolve(servicePath, "middleware.js");
82
- if (existsSync(middlewarePath) && !statSync(middlewarePath).isDirectory()) {
83
- return middlewarePath;
84
- } else if (existsSync(middlewarePathJS) && !statSync(middlewarePathJS).isDirectory()) {
85
- return middlewarePathJS;
86
- }
87
- return false;
57
+ return getFilePath(servicePath, "middleware", EXTENSIONS);
88
58
  }
89
59
 
90
60
  export function getErrorConfigPath(servicePath: string) {
91
- const errorPath = resolve(servicePath, "catch.ts");
92
- const errorPathJS = resolve(servicePath, "catch.js");
93
- if (existsSync(errorPath) && !statSync(errorPath).isDirectory()) {
94
- return errorPath;
95
- } else if (existsSync(errorPathJS) && !statSync(errorPathJS).isDirectory()) {
96
- return errorPathJS;
97
- }
98
- return false;
61
+ return getFilePath(servicePath, "catch", EXTENSIONS);
99
62
  }
100
63
 
101
64
  export function getDocConfigPath(servicePath: string) {
102
- const docPath = resolve(servicePath, "doc.ts");
103
- const docPathJS = resolve(servicePath, "doc.js");
104
- if (existsSync(docPath) && !statSync(docPath).isDirectory()) {
105
- return docPath;
106
- } else if (existsSync(docPathJS) && !statSync(docPathJS).isDirectory()) {
107
- return docPathJS;
108
- }
109
- return false;
65
+ return getFilePath(servicePath, "doc", EXTENSIONS);
110
66
  }
111
67
 
112
68
  export function getMiqroJSONPath() {
@@ -118,14 +74,7 @@ export function getMiqroJSONPath() {
118
74
  }
119
75
 
120
76
  export function getAuthConfigPath(servicePath: string) {
121
- const authPath = resolve(servicePath, "auth.ts");
122
- const authPathJS = resolve(servicePath, "auth.js");
123
- if (existsSync(authPath) && !statSync(authPath).isDirectory()) {
124
- return authPath;
125
- } else if (existsSync(authPathJS) && !statSync(authPathJS).isDirectory()) {
126
- return authPathJS;
127
- }
128
- return false;
77
+ return getFilePath(servicePath, "auth", EXTENSIONS);
129
78
  }
130
79
 
131
80
  export function getHTTPRouterPath(servicePath: string) {