@weconjs/core 0.1.1 → 1.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.
- package/README.md +460 -41
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +6 -8
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +30 -21
- package/dist/context.js.map +1 -1
- package/dist/database/index.d.ts +108 -5
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +148 -12
- package/dist/database/index.js.map +1 -1
- package/dist/devtools/controllers/config.controller.d.ts +28 -0
- package/dist/devtools/controllers/config.controller.d.ts.map +1 -0
- package/dist/devtools/controllers/config.controller.js +100 -0
- package/dist/devtools/controllers/config.controller.js.map +1 -0
- package/dist/devtools/controllers/i18n.controller.d.ts +22 -0
- package/dist/devtools/controllers/i18n.controller.d.ts.map +1 -0
- package/dist/devtools/controllers/i18n.controller.js +93 -0
- package/dist/devtools/controllers/i18n.controller.js.map +1 -0
- package/dist/devtools/controllers/modules.controller.d.ts +16 -0
- package/dist/devtools/controllers/modules.controller.d.ts.map +1 -0
- package/dist/devtools/controllers/modules.controller.js +73 -0
- package/dist/devtools/controllers/modules.controller.js.map +1 -0
- package/dist/devtools/controllers/routes.controller.d.ts +13 -0
- package/dist/devtools/controllers/routes.controller.d.ts.map +1 -0
- package/dist/devtools/controllers/routes.controller.js +32 -0
- package/dist/devtools/controllers/routes.controller.js.map +1 -0
- package/dist/devtools/index.d.ts +28 -0
- package/dist/devtools/index.d.ts.map +1 -0
- package/dist/devtools/index.js +66 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/devtools/middleware.d.ts +11 -0
- package/dist/devtools/middleware.d.ts.map +1 -0
- package/dist/devtools/middleware.js +30 -0
- package/dist/devtools/middleware.js.map +1 -0
- package/dist/devtools/types.d.ts +59 -0
- package/dist/devtools/types.d.ts.map +1 -0
- package/dist/devtools/types.js +5 -0
- package/dist/devtools/types.js.map +1 -0
- package/dist/errors/ConfigError.d.ts +6 -0
- package/dist/errors/ConfigError.d.ts.map +1 -0
- package/dist/errors/ConfigError.js +16 -0
- package/dist/errors/ConfigError.js.map +1 -0
- package/dist/errors/RequestError.d.ts +6 -0
- package/dist/errors/RequestError.d.ts.map +1 -0
- package/dist/errors/RequestError.js +16 -0
- package/dist/errors/RequestError.js.map +1 -0
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +5 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +15 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/dist/logger/index.d.ts +102 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +147 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/module/index.d.ts +6 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +5 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/module-loader.d.ts +60 -0
- package/dist/module/module-loader.d.ts.map +1 -0
- package/dist/module/module-loader.js +119 -0
- package/dist/module/module-loader.js.map +1 -0
- package/dist/routing/ErrorCatcher.d.ts +18 -0
- package/dist/routing/ErrorCatcher.d.ts.map +1 -0
- package/dist/routing/ErrorCatcher.js +50 -0
- package/dist/routing/ErrorCatcher.js.map +1 -0
- package/dist/routing/RaiMatcher.d.ts +27 -0
- package/dist/routing/RaiMatcher.d.ts.map +1 -0
- package/dist/routing/RaiMatcher.js +127 -0
- package/dist/routing/RaiMatcher.js.map +1 -0
- package/dist/routing/Route.d.ts +28 -0
- package/dist/routing/Route.d.ts.map +1 -0
- package/dist/routing/Route.js +125 -0
- package/dist/routing/Route.js.map +1 -0
- package/dist/routing/Routes.d.ts +31 -0
- package/dist/routing/Routes.d.ts.map +1 -0
- package/dist/routing/Routes.js +151 -0
- package/dist/routing/Routes.js.map +1 -0
- package/dist/routing/RoutesParam.d.ts +29 -0
- package/dist/routing/RoutesParam.d.ts.map +1 -0
- package/dist/routing/RoutesParam.js +113 -0
- package/dist/routing/RoutesParam.js.map +1 -0
- package/dist/routing/Wecon.d.ts +66 -0
- package/dist/routing/Wecon.d.ts.map +1 -0
- package/dist/routing/Wecon.js +248 -0
- package/dist/routing/Wecon.js.map +1 -0
- package/dist/routing/index.d.ts +9 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +7 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/server/index.d.ts +162 -10
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +339 -25
- package/dist/server/index.js.map +1 -1
- package/dist/types.d.ts +75 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +21 -4
package/dist/index.js
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @weconjs/core
|
|
3
3
|
*
|
|
4
4
|
* Core package for the Wecon framework.
|
|
5
|
-
* Provides configuration, module system, and runtime utilities.
|
|
5
|
+
* Provides configuration, module system, routing, and runtime utilities.
|
|
6
6
|
*/
|
|
7
7
|
// Configuration
|
|
8
8
|
export { defineConfig, resolveConfig, loadConfig } from "./config.js";
|
|
9
9
|
// Module System
|
|
10
10
|
export { defineModule, loadModule, discoverSocketHandlers, discoverSocketMiddleware, resolveModuleDependencies, } from "./module.js";
|
|
11
|
+
// Module Loader (per-module package.json support)
|
|
12
|
+
export { readModulePackageJson, checkModuleDeps, detectPackageManager, installModuleDeps, resolveAllModuleDeps, } from "./module/index.js";
|
|
11
13
|
// Context
|
|
12
14
|
export { createContext, createLogger } from "./context.js";
|
|
15
|
+
// Logger
|
|
16
|
+
export { createWinstonLogger, createConsoleLogger, } from "./logger/index.js";
|
|
13
17
|
// Server
|
|
14
18
|
export { createWecon } from "./server/index.js";
|
|
19
|
+
// Routing
|
|
20
|
+
export { Wecon, Route, Routes, RoutesParam, RaiMatcher, ErrorCatcher, } from "./routing/index.js";
|
|
21
|
+
// Errors
|
|
22
|
+
export { ConfigError, RequestError } from "./errors/index.js";
|
|
15
23
|
// i18n
|
|
16
24
|
export { loadI18nResources, createI18nMiddleware, initI18n } from "./i18n/index.js";
|
|
17
25
|
// Database
|
|
18
|
-
export { createDatabaseConnection } from "./database/index.js";
|
|
26
|
+
export { createDatabaseConnection, buildMongoUri, buildUriFromConfig, } from "./database/index.js";
|
|
19
27
|
// Socket.IO
|
|
20
28
|
export { createSocketServer, discoverSocketHandlers as discoverSocketHandlersFromModules, discoverSocketMiddleware as discoverSocketMiddlewareFromModules, initializeSocket, setupSocketIO, } from "./socket/index.js";
|
|
29
|
+
// DevTools
|
|
30
|
+
export { createDevToolsRouter } from "./devtools/index.js";
|
|
21
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEtE,gBAAgB;AAChB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AAErB,UAAU;AACV,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE3D,SAAS;AACT,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEtE,gBAAgB;AAChB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AAErB,kDAAkD;AAClD,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAG3B,UAAU;AACV,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE3D,SAAS;AACT,OAAO,EACL,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAG3B,SAAS;AACT,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAShD,UAAU;AACV,OAAO,EACL,KAAK,EACL,KAAK,EACL,MAAM,EACN,WAAW,EACX,UAAU,EACV,YAAY,GACb,MAAM,oBAAoB,CAAC;AAG5B,SAAS;AACT,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO;AACP,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGpF,WAAW;AACX,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAO7B,YAAY;AACZ,OAAO,EACL,kBAAkB,EAClB,sBAAsB,IAAI,iCAAiC,EAC3D,wBAAwB,IAAI,mCAAmC,EAC/D,gBAAgB,EAChB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAU3B,WAAW;AACX,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @weconjs/core - Logger Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates Winston-based loggers with optional file rotation.
|
|
5
|
+
* This is the production-ready logger for Wecon applications.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createWinstonLogger } from '@weconjs/core';
|
|
10
|
+
*
|
|
11
|
+
* const logger = createWinstonLogger({
|
|
12
|
+
* level: 'debug',
|
|
13
|
+
* appName: 'my-app',
|
|
14
|
+
* enableFile: true,
|
|
15
|
+
* enableConsole: true,
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* logger.info('Server started', { port: 3000 });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import type { WeconLogger } from "../types.js";
|
|
22
|
+
/**
|
|
23
|
+
* Logger configuration options
|
|
24
|
+
*/
|
|
25
|
+
export interface LoggerOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Log level: 'debug' | 'info' | 'warn' | 'error'
|
|
28
|
+
* @default 'info'
|
|
29
|
+
*/
|
|
30
|
+
level?: "debug" | "info" | "warn" | "error";
|
|
31
|
+
/**
|
|
32
|
+
* Application name (used in log prefix)
|
|
33
|
+
*/
|
|
34
|
+
appName?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Enable console output
|
|
37
|
+
* @default true
|
|
38
|
+
*/
|
|
39
|
+
enableConsole?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Enable file output with daily rotation
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
enableFile?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Directory for log files
|
|
47
|
+
* @default 'logs'
|
|
48
|
+
*/
|
|
49
|
+
logDir?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Max file size before rotation (e.g., '20m', '100m')
|
|
52
|
+
* @default '20m'
|
|
53
|
+
*/
|
|
54
|
+
maxSize?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Max days to keep logs
|
|
57
|
+
* @default '14d'
|
|
58
|
+
*/
|
|
59
|
+
maxFiles?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Use JSON format (for production/log aggregation)
|
|
62
|
+
* @default false (uses pretty format)
|
|
63
|
+
*/
|
|
64
|
+
jsonFormat?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Extended logger with Winston instance access
|
|
68
|
+
*/
|
|
69
|
+
export interface WinstonBasedLogger extends WeconLogger {
|
|
70
|
+
/**
|
|
71
|
+
* Access the underlying Winston logger (if available)
|
|
72
|
+
* This is undefined when Winston is not installed
|
|
73
|
+
*/
|
|
74
|
+
winston?: unknown;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a production-ready Winston logger
|
|
78
|
+
*
|
|
79
|
+
* Falls back to console-based logger if winston is not installed.
|
|
80
|
+
*
|
|
81
|
+
* @param options - Logger configuration
|
|
82
|
+
* @returns WeconLogger instance
|
|
83
|
+
*/
|
|
84
|
+
export declare function createWinstonLogger(options?: LoggerOptions): Promise<WinstonBasedLogger>;
|
|
85
|
+
/**
|
|
86
|
+
* Create a simple console-based logger
|
|
87
|
+
*
|
|
88
|
+
* This is a fallback when Winston is not available.
|
|
89
|
+
*
|
|
90
|
+
* @param options - Logger configuration
|
|
91
|
+
* @returns WeconLogger instance
|
|
92
|
+
*/
|
|
93
|
+
export declare function createConsoleLogger(options?: LoggerOptions): WinstonBasedLogger;
|
|
94
|
+
/**
|
|
95
|
+
* Default export for convenience
|
|
96
|
+
*/
|
|
97
|
+
declare const _default: {
|
|
98
|
+
createWinstonLogger: typeof createWinstonLogger;
|
|
99
|
+
createConsoleLogger: typeof createConsoleLogger;
|
|
100
|
+
};
|
|
101
|
+
export default _default;
|
|
102
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAE5C;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAyG7B;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,aAAkB,GAAG,kBAAkB,CAoCnF;AAED;;GAEG;;;;;AACH,wBAA4D"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @weconjs/core - Logger Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates Winston-based loggers with optional file rotation.
|
|
5
|
+
* This is the production-ready logger for Wecon applications.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createWinstonLogger } from '@weconjs/core';
|
|
10
|
+
*
|
|
11
|
+
* const logger = createWinstonLogger({
|
|
12
|
+
* level: 'debug',
|
|
13
|
+
* appName: 'my-app',
|
|
14
|
+
* enableFile: true,
|
|
15
|
+
* enableConsole: true,
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* logger.info('Server started', { port: 3000 });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Create a production-ready Winston logger
|
|
23
|
+
*
|
|
24
|
+
* Falls back to console-based logger if winston is not installed.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Logger configuration
|
|
27
|
+
* @returns WeconLogger instance
|
|
28
|
+
*/
|
|
29
|
+
export async function createWinstonLogger(options = {}) {
|
|
30
|
+
const { level = "info", appName = "wecon", enableConsole = true, enableFile = false, logDir = "logs", maxSize = "20m", maxFiles = "14d", jsonFormat = false, } = options;
|
|
31
|
+
try {
|
|
32
|
+
// Dynamic import to avoid bundling issues if winston is not installed
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
const winston = await import("winston");
|
|
35
|
+
const { combine, timestamp, printf, json, errors, colorize } = winston.format;
|
|
36
|
+
// Pretty format for development
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
const prettyFormat = printf(({ level, message, timestamp, stack, ...meta }) => {
|
|
39
|
+
const metaStr = Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : "";
|
|
40
|
+
const logMessage = stack ? `${message}\n${stack}` : message;
|
|
41
|
+
return `${timestamp} [${level.toUpperCase()}] [${appName}]: ${logMessage}${metaStr}`;
|
|
42
|
+
});
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
const transports = [];
|
|
45
|
+
// Console transport
|
|
46
|
+
if (enableConsole) {
|
|
47
|
+
transports.push(new winston.transports.Console({
|
|
48
|
+
handleExceptions: true,
|
|
49
|
+
format: jsonFormat ? json() : combine(colorize(), prettyFormat),
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
// File transports with daily rotation
|
|
53
|
+
if (enableFile) {
|
|
54
|
+
try {
|
|
55
|
+
// Dynamic import for winston-daily-rotate-file
|
|
56
|
+
await import("winston-daily-rotate-file");
|
|
57
|
+
const DailyRotateFile = winston.transports.DailyRotateFile;
|
|
58
|
+
// Application logs
|
|
59
|
+
transports.push(new DailyRotateFile({
|
|
60
|
+
filename: `${logDir}/app-%DATE%.log`,
|
|
61
|
+
datePattern: "YYYY-MM-DD",
|
|
62
|
+
zippedArchive: true,
|
|
63
|
+
maxSize,
|
|
64
|
+
maxFiles,
|
|
65
|
+
level: "info",
|
|
66
|
+
}));
|
|
67
|
+
// Error logs (separate file)
|
|
68
|
+
transports.push(new DailyRotateFile({
|
|
69
|
+
filename: `${logDir}/error-%DATE%.log`,
|
|
70
|
+
datePattern: "YYYY-MM-DD",
|
|
71
|
+
zippedArchive: true,
|
|
72
|
+
maxSize,
|
|
73
|
+
maxFiles: "30d", // Keep error logs longer
|
|
74
|
+
level: "error",
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
console.warn("[Wecon] winston-daily-rotate-file not installed. File logging disabled.");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const winstonLogger = winston.createLogger({
|
|
82
|
+
level,
|
|
83
|
+
format: combine(errors({ stack: true }), timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), jsonFormat ? json() : prettyFormat),
|
|
84
|
+
transports,
|
|
85
|
+
exitOnError: false,
|
|
86
|
+
});
|
|
87
|
+
// Return WeconLogger interface
|
|
88
|
+
return {
|
|
89
|
+
debug: (message, meta) => winstonLogger.debug(message, meta),
|
|
90
|
+
info: (message, meta) => winstonLogger.info(message, meta),
|
|
91
|
+
warn: (message, meta) => winstonLogger.warn(message, meta),
|
|
92
|
+
error: (message, meta) => winstonLogger.error(message, meta),
|
|
93
|
+
winston: winstonLogger,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Winston not installed - fall back to console logger
|
|
98
|
+
console.warn("[Wecon] winston not installed. Using console-based logger.");
|
|
99
|
+
return createConsoleLogger(options);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a simple console-based logger
|
|
104
|
+
*
|
|
105
|
+
* This is a fallback when Winston is not available.
|
|
106
|
+
*
|
|
107
|
+
* @param options - Logger configuration
|
|
108
|
+
* @returns WeconLogger instance
|
|
109
|
+
*/
|
|
110
|
+
export function createConsoleLogger(options = {}) {
|
|
111
|
+
const { level = "info", appName = "wecon" } = options;
|
|
112
|
+
const levels = ["debug", "info", "warn", "error"];
|
|
113
|
+
const minLevel = levels.indexOf(level);
|
|
114
|
+
const shouldLog = (logLevel) => levels.indexOf(logLevel) >= minLevel;
|
|
115
|
+
const formatMessage = (lvl, message, meta) => {
|
|
116
|
+
const timestamp = new Date().toISOString();
|
|
117
|
+
const metaStr = meta && Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : "";
|
|
118
|
+
return `${timestamp} [${lvl.toUpperCase()}] [${appName}]: ${message}${metaStr}`;
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
debug: (message, meta) => {
|
|
122
|
+
if (shouldLog("debug")) {
|
|
123
|
+
console.debug(formatMessage("debug", message, meta));
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
info: (message, meta) => {
|
|
127
|
+
if (shouldLog("info")) {
|
|
128
|
+
console.info(formatMessage("info", message, meta));
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
warn: (message, meta) => {
|
|
132
|
+
if (shouldLog("warn")) {
|
|
133
|
+
console.warn(formatMessage("warn", message, meta));
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
error: (message, meta) => {
|
|
137
|
+
if (shouldLog("error")) {
|
|
138
|
+
console.error(formatMessage("error", message, meta));
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Default export for convenience
|
|
145
|
+
*/
|
|
146
|
+
export default { createWinstonLogger, createConsoleLogger };
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAmEH;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC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B,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - Module utilities
|
|
3
|
+
*/
|
|
4
|
+
export { readModulePackageJson, checkModuleDeps, detectPackageManager, installModuleDeps, resolveAllModuleDeps, } from "./module-loader.js";
|
|
5
|
+
export type { ModulePackageJson, DepsCheckResult, } from "./module-loader.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/module/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,iBAAiB,EACjB,eAAe,GAChB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/module/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - Module Loader
|
|
3
|
+
*
|
|
4
|
+
* Reads per-module package.json files and manages module-specific dependencies.
|
|
5
|
+
* Supports auto-installation of missing deps in development mode.
|
|
6
|
+
*/
|
|
7
|
+
import type { WeconLogger } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Parsed module package.json
|
|
10
|
+
*/
|
|
11
|
+
export interface ModulePackageJson {
|
|
12
|
+
name?: string;
|
|
13
|
+
private?: boolean;
|
|
14
|
+
dependencies?: Record<string, string>;
|
|
15
|
+
devDependencies?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Result of checking module dependencies
|
|
19
|
+
*/
|
|
20
|
+
export interface DepsCheckResult {
|
|
21
|
+
moduleName: string;
|
|
22
|
+
modulePath: string;
|
|
23
|
+
/** Dependencies declared in module package.json */
|
|
24
|
+
declared: Record<string, string>;
|
|
25
|
+
/** Dependencies missing from root node_modules */
|
|
26
|
+
missing: string[];
|
|
27
|
+
/** Dependencies already installed */
|
|
28
|
+
installed: string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Read a module's package.json if it exists
|
|
32
|
+
*/
|
|
33
|
+
export declare function readModulePackageJson(modulePath: string): ModulePackageJson | null;
|
|
34
|
+
/**
|
|
35
|
+
* Check which module dependencies are missing from root node_modules
|
|
36
|
+
*/
|
|
37
|
+
export declare function checkModuleDeps(modulePath: string, rootDir: string, moduleName: string): DepsCheckResult;
|
|
38
|
+
/**
|
|
39
|
+
* Detect which package manager is being used in the project
|
|
40
|
+
*/
|
|
41
|
+
export declare function detectPackageManager(rootDir: string): "npm" | "yarn" | "pnpm";
|
|
42
|
+
/**
|
|
43
|
+
* Install missing module dependencies into the root project
|
|
44
|
+
*/
|
|
45
|
+
export declare function installModuleDeps(missing: string[], declared: Record<string, string>, rootDir: string, logger: WeconLogger): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Check and optionally install all module dependencies.
|
|
48
|
+
* Called during createWecon bootstrap.
|
|
49
|
+
*
|
|
50
|
+
* @param modules - Array of { name, path } for each module
|
|
51
|
+
* @param rootDir - Root project directory (where node_modules lives)
|
|
52
|
+
* @param logger - Logger instance
|
|
53
|
+
* @param autoInstall - Whether to auto-install missing deps
|
|
54
|
+
* @returns Array of check results
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveAllModuleDeps(modules: Array<{
|
|
57
|
+
name: string;
|
|
58
|
+
path: string;
|
|
59
|
+
}>, rootDir: string, logger: WeconLogger, autoInstall?: boolean): Promise<DepsCheckResult[]>;
|
|
60
|
+
//# sourceMappingURL=module-loader.d.ts.map
|
|
@@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B,oBAAoB,CACxC,OAAO,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAC9C,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,WAAW,EACnB,WAAW,GAAE,OAAe,GAC3B,OAAO,CAAC,eAAe,EAAE,CAAC,CAwB5B"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - Module Loader
|
|
3
|
+
*
|
|
4
|
+
* Reads per-module package.json files and manages module-specific dependencies.
|
|
5
|
+
* Supports auto-installation of missing deps in development mode.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync } from "fs";
|
|
8
|
+
import { join, resolve } from "path";
|
|
9
|
+
import { execSync } from "child_process";
|
|
10
|
+
/**
|
|
11
|
+
* Read a module's package.json if it exists
|
|
12
|
+
*/
|
|
13
|
+
export function readModulePackageJson(modulePath) {
|
|
14
|
+
const pkgPath = join(modulePath, "package.json");
|
|
15
|
+
if (!existsSync(pkgPath)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const raw = readFileSync(pkgPath, "utf-8");
|
|
20
|
+
return JSON.parse(raw);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check which module dependencies are missing from root node_modules
|
|
28
|
+
*/
|
|
29
|
+
export function checkModuleDeps(modulePath, rootDir, moduleName) {
|
|
30
|
+
const pkg = readModulePackageJson(modulePath);
|
|
31
|
+
const declared = pkg?.dependencies ?? {};
|
|
32
|
+
const missing = [];
|
|
33
|
+
const installed = [];
|
|
34
|
+
const nodeModulesDir = join(rootDir, "node_modules");
|
|
35
|
+
for (const dep of Object.keys(declared)) {
|
|
36
|
+
// Check if the package exists in root node_modules
|
|
37
|
+
const depPath = join(nodeModulesDir, dep);
|
|
38
|
+
if (existsSync(depPath)) {
|
|
39
|
+
installed.push(dep);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
missing.push(dep);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { moduleName, modulePath, declared, missing, installed };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Detect which package manager is being used in the project
|
|
49
|
+
*/
|
|
50
|
+
export function detectPackageManager(rootDir) {
|
|
51
|
+
if (existsSync(join(rootDir, "pnpm-lock.yaml")))
|
|
52
|
+
return "pnpm";
|
|
53
|
+
if (existsSync(join(rootDir, "yarn.lock")))
|
|
54
|
+
return "yarn";
|
|
55
|
+
return "npm";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Install missing module dependencies into the root project
|
|
59
|
+
*/
|
|
60
|
+
export function installModuleDeps(missing, declared, rootDir, logger) {
|
|
61
|
+
if (missing.length === 0)
|
|
62
|
+
return true;
|
|
63
|
+
const pm = detectPackageManager(rootDir);
|
|
64
|
+
// Build install args with version specifiers
|
|
65
|
+
const packages = missing.map((name) => {
|
|
66
|
+
const version = declared[name];
|
|
67
|
+
return version ? `${name}@${version}` : name;
|
|
68
|
+
});
|
|
69
|
+
const installCmd = pm === "yarn"
|
|
70
|
+
? `yarn add ${packages.join(" ")}`
|
|
71
|
+
: pm === "pnpm"
|
|
72
|
+
? `pnpm add ${packages.join(" ")}`
|
|
73
|
+
: `npm install ${packages.join(" ")}`;
|
|
74
|
+
logger.info(`Installing module dependencies: ${missing.join(", ")}`);
|
|
75
|
+
try {
|
|
76
|
+
execSync(installCmd, { cwd: rootDir, stdio: "pipe" });
|
|
77
|
+
logger.info(`Dependencies installed successfully`);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
logger.error("Failed to install module dependencies", {
|
|
82
|
+
error: err.message,
|
|
83
|
+
packages: missing,
|
|
84
|
+
});
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check and optionally install all module dependencies.
|
|
90
|
+
* Called during createWecon bootstrap.
|
|
91
|
+
*
|
|
92
|
+
* @param modules - Array of { name, path } for each module
|
|
93
|
+
* @param rootDir - Root project directory (where node_modules lives)
|
|
94
|
+
* @param logger - Logger instance
|
|
95
|
+
* @param autoInstall - Whether to auto-install missing deps
|
|
96
|
+
* @returns Array of check results
|
|
97
|
+
*/
|
|
98
|
+
export async function resolveAllModuleDeps(modules, rootDir, logger, autoInstall = false) {
|
|
99
|
+
const results = [];
|
|
100
|
+
const allMissing = [];
|
|
101
|
+
const allDeclared = {};
|
|
102
|
+
for (const mod of modules) {
|
|
103
|
+
const absolutePath = resolve(rootDir, mod.path);
|
|
104
|
+
const result = checkModuleDeps(absolutePath, rootDir, mod.name);
|
|
105
|
+
results.push(result);
|
|
106
|
+
if (result.missing.length > 0) {
|
|
107
|
+
logger.warn(`Module "${mod.name}" has missing dependencies: ${result.missing.join(", ")}`);
|
|
108
|
+
allMissing.push(...result.missing);
|
|
109
|
+
Object.assign(allDeclared, result.declared);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Deduplicate and install all at once
|
|
113
|
+
if (autoInstall && allMissing.length > 0) {
|
|
114
|
+
const unique = [...new Set(allMissing)];
|
|
115
|
+
installModuleDeps(unique, allDeclared, rootDir, logger);
|
|
116
|
+
}
|
|
117
|
+
return results;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=module-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-loader.js","sourceRoot":"","sources":["../../src/module/module-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AA2BzC;;GAEG;AAC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CAAC,UAAU,CAAC,CAAC,CAAC;QACxC,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ErrorInfoType, ErrorTraceType } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for configuration error tracking.
|
|
4
|
+
* Captures caller info from stack traces for precise error reporting.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class ErrorCatcher {
|
|
7
|
+
/**
|
|
8
|
+
* Extract caller file, line, column from the stack trace.
|
|
9
|
+
* Skips internal frames to point to the user's code.
|
|
10
|
+
*/
|
|
11
|
+
static getCallerInfo(): ErrorTraceType;
|
|
12
|
+
/**
|
|
13
|
+
* Log a formatted config error with location info, then exit.
|
|
14
|
+
*/
|
|
15
|
+
static logError(error: ErrorInfoType, tracedStackInfo: ErrorTraceType): void;
|
|
16
|
+
}
|
|
17
|
+
export default ErrorCatcher;
|
|
18
|
+
//# sourceMappingURL=ErrorCatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorCatcher.d.ts","sourceRoot":"","sources":["../../src/routing/ErrorCatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEjE;;;GAGG;AACH,8BAAsB,YAAY;IAChC;;;OAGG;IACH,MAAM,CAAC,aAAa,IAAI,cAAc;IA8BtC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,GAAG,IAAI;CAqB7E;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for configuration error tracking.
|
|
4
|
+
* Captures caller info from stack traces for precise error reporting.
|
|
5
|
+
*/
|
|
6
|
+
export class ErrorCatcher {
|
|
7
|
+
/**
|
|
8
|
+
* Extract caller file, line, column from the stack trace.
|
|
9
|
+
* Skips internal frames to point to the user's code.
|
|
10
|
+
*/
|
|
11
|
+
static getCallerInfo() {
|
|
12
|
+
const err = new Error();
|
|
13
|
+
const stack = err.stack || "";
|
|
14
|
+
const stackLines = stack.split("\n").slice(1);
|
|
15
|
+
// Skip getCallerInfo and constructor frames
|
|
16
|
+
const callerLine = stackLines[2] || stackLines[1] || "";
|
|
17
|
+
// V8 format: " at ClassName.method (file:///path/file.ts:15:23)"
|
|
18
|
+
let match = callerLine.match(/\((.+?):(\d+):(\d+)\)$/);
|
|
19
|
+
if (!match) {
|
|
20
|
+
// Format without parentheses: " at file:///path/file.ts:15:23"
|
|
21
|
+
match = callerLine.match(/at\s+(.+?):(\d+):(\d+)$/);
|
|
22
|
+
}
|
|
23
|
+
if (match) {
|
|
24
|
+
const file = match[1].replace("file://", "");
|
|
25
|
+
const line = parseInt(match[2], 10);
|
|
26
|
+
const column = parseInt(match[3], 10);
|
|
27
|
+
const functionMatch = callerLine.match(/at\s+(?:async\s+)?(\S+?)\s+\(/);
|
|
28
|
+
const functionName = functionMatch ? functionMatch[1] : null;
|
|
29
|
+
return { file, line, column, function: functionName };
|
|
30
|
+
}
|
|
31
|
+
return { file: "unknown", line: 0, column: 0, function: null };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Log a formatted config error with location info, then exit.
|
|
35
|
+
*/
|
|
36
|
+
static logError(error, tracedStackInfo) {
|
|
37
|
+
console.error(chalk.red.bold("\n-=>") +
|
|
38
|
+
chalk.white.bold(" Whoops! We caught an error for you.") +
|
|
39
|
+
chalk.red.bold(" <=-\n"));
|
|
40
|
+
console.error(chalk.red.bold("✖ Error:"), chalk.white(error.title));
|
|
41
|
+
console.error(chalk.gray("\n Details:"), chalk.white(error.details));
|
|
42
|
+
console.error(chalk.gray("\n Location:"), chalk.cyan(`${tracedStackInfo.file}:${tracedStackInfo.line}:${tracedStackInfo.column}`));
|
|
43
|
+
console.error(chalk.yellow.bold("\n 💡 How to fix:"));
|
|
44
|
+
console.error(chalk.yellow(` ${error.fix.replace(/\n/g, "\n ")}`));
|
|
45
|
+
console.error("");
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default ErrorCatcher;
|
|
50
|
+
//# sourceMappingURL=ErrorCatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorCatcher.js","sourceRoot":"","sources":["../../src/routing/ErrorCatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;GAGG;AACH,MAAM,OAAgB,YAAY;IAChC;;;OAGG;IACH,MAAM,CAAC,aAAa;QAClB,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;QAC9B,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE9C,4CAA4C;QAC5C,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAExD,oEAAoE;QACpE,IAAI,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAEvD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,kEAAkE;YAClE,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;YAC7C,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAA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ACF,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;QACvD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACrE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAElB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type Route from "./Route.js";
|
|
2
|
+
export type RaiRoutesList = Array<Pick<Route, "path" | "method" | "rai">>;
|
|
3
|
+
/**
|
|
4
|
+
* High-performance RAI lookup engine.
|
|
5
|
+
* Pre-compiles path matchers, uses exact + runtime caches for O(1) lookups.
|
|
6
|
+
*/
|
|
7
|
+
declare class RaiMatcher {
|
|
8
|
+
private cache;
|
|
9
|
+
private routesByMethod;
|
|
10
|
+
private exactRoutes;
|
|
11
|
+
constructor(raisList: RaiRoutesList);
|
|
12
|
+
/** Pre-compile all route matchers and organize by HTTP method */
|
|
13
|
+
private initialize;
|
|
14
|
+
/** Score route specificity: static=10, dynamic=1, wildcard=0.5 */
|
|
15
|
+
private getRouteSpecificity;
|
|
16
|
+
/** Normalize trailing slashes */
|
|
17
|
+
private normalizeRoute;
|
|
18
|
+
/** Find RAI for the given request path and method */
|
|
19
|
+
findRai(path: string, method: string): string;
|
|
20
|
+
clearCache(): void;
|
|
21
|
+
getCacheStats(): {
|
|
22
|
+
size: number;
|
|
23
|
+
methods: string[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export default RaiMatcher;
|
|
27
|
+
//# sourceMappingURL=RaiMatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RaiMatcher.d.ts","sourceRoot":"","sources":["../../src/routing/RaiMatcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC;AAS1E;;;GAGG;AACH,cAAM,UAAU;IACd,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,WAAW,CAAsB;gBAE7B,QAAQ,EAAE,aAAa;IAOnC,iEAAiE;IACjE,OAAO,CAAC,UAAU;IA2ClB,kEAAkE;IAClE,OAAO,CAAC,mBAAmB;IAmB3B,iCAAiC;IACjC,OAAO,CAAC,cAAc;IAQtB,qDAAqD;IAC9C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAsD7C,UAAU,IAAI,IAAI;IAIlB,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE;CAM5D;AAED,eAAe,UAAU,CAAC"}
|