wooks 0.4.10 → 0.4.13
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/dist/index.cjs +16 -18
- package/dist/index.d.ts +52 -61
- package/dist/index.mjs +16 -18
- package/package.json +11 -3
package/dist/index.cjs
CHANGED
|
@@ -17,8 +17,11 @@ function getDefaultLogger(topic) {
|
|
|
17
17
|
|
|
18
18
|
class Wooks {
|
|
19
19
|
constructor(opts) {
|
|
20
|
-
this.router = new router.ProstoRouter(
|
|
21
|
-
|
|
20
|
+
this.router = new router.ProstoRouter({
|
|
21
|
+
silent: true,
|
|
22
|
+
...(opts?.router || {}),
|
|
23
|
+
});
|
|
24
|
+
this.logger = opts?.logger || getDefaultLogger('wooks');
|
|
22
25
|
}
|
|
23
26
|
getRouter() {
|
|
24
27
|
return this.router;
|
|
@@ -36,13 +39,12 @@ class Wooks {
|
|
|
36
39
|
return {};
|
|
37
40
|
}
|
|
38
41
|
lookup(method, path) {
|
|
39
|
-
var _a, _b, _c, _d;
|
|
40
42
|
const found = this.getRouter().lookup(method, path || '');
|
|
41
|
-
eventCore.useEventContext().store('routeParams').value =
|
|
43
|
+
eventCore.useEventContext().store('routeParams').value = found?.ctx?.params || {};
|
|
42
44
|
return {
|
|
43
|
-
handlers:
|
|
44
|
-
segments:
|
|
45
|
-
firstStatic:
|
|
45
|
+
handlers: found?.route?.handlers || null,
|
|
46
|
+
segments: found?.route?.segments || null,
|
|
47
|
+
firstStatic: found?.route?.firstStatic || null,
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
on(method, path, handler) {
|
|
@@ -74,16 +76,6 @@ class WooksAdapterBase {
|
|
|
74
76
|
getWooks() {
|
|
75
77
|
return this.wooks;
|
|
76
78
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Get logger instance for application logs
|
|
79
|
-
* ```js
|
|
80
|
-
* const app = createHttpApp()
|
|
81
|
-
* const logger = app.getLogger('app-logger')
|
|
82
|
-
* logger.log('My App log message')
|
|
83
|
-
* ```
|
|
84
|
-
* @param topic topic for logger
|
|
85
|
-
* @returns logger instance
|
|
86
|
-
*/
|
|
87
79
|
getLogger(topic) {
|
|
88
80
|
return this.getWooks().getLogger(topic);
|
|
89
81
|
}
|
|
@@ -91,7 +83,13 @@ class WooksAdapterBase {
|
|
|
91
83
|
return this.getWooks().getLoggerOptions();
|
|
92
84
|
}
|
|
93
85
|
mergeEventOptions(opts) {
|
|
94
|
-
return
|
|
86
|
+
return {
|
|
87
|
+
...(opts || {}),
|
|
88
|
+
eventLogger: {
|
|
89
|
+
...this.getLoggerOptions(),
|
|
90
|
+
...(opts?.eventLogger || {}),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
95
93
|
}
|
|
96
94
|
on(method, path, handler) {
|
|
97
95
|
return this.wooks.on(method, path, handler);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,61 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { TEventOptions } from '@wooksjs/event-core';
|
|
4
|
-
|
|
5
|
-
import { TProstoLoggerOptions } from '@prostojs/logger';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* @returns logger instance
|
|
54
|
-
*/
|
|
55
|
-
getLogger(topic: string): TConsoleBase;
|
|
56
|
-
protected getLoggerOptions(): TProstoLoggerOptions<Record<string, never>>;
|
|
57
|
-
protected mergeEventOptions(opts?: TEventOptions): TEventOptions;
|
|
58
|
-
on<ResType = unknown, ParamsType = Record<string, string | string[]>>(method: string, path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { }
|
|
1
|
+
import * as _prostojs_router from '@prostojs/router';
|
|
2
|
+
import { ProstoRouter } from '@prostojs/router';
|
|
3
|
+
import { TEventOptions } from '@wooksjs/event-core';
|
|
4
|
+
export { useRouteParams } from '@wooksjs/event-core';
|
|
5
|
+
import { TConsoleBase, TProstoLoggerOptions } from '@prostojs/logger';
|
|
6
|
+
|
|
7
|
+
type TWooksHandler<ResType = unknown> = () => Promise<ResType> | ResType;
|
|
8
|
+
|
|
9
|
+
interface TWooksOptions {
|
|
10
|
+
logger?: TConsoleBase;
|
|
11
|
+
router?: {
|
|
12
|
+
ignoreTrailingSlash?: boolean;
|
|
13
|
+
ignoreCase?: boolean;
|
|
14
|
+
cacheLimit?: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
declare class Wooks {
|
|
18
|
+
protected router: ProstoRouter<TWooksHandler>;
|
|
19
|
+
protected logger: TConsoleBase;
|
|
20
|
+
constructor(opts?: TWooksOptions);
|
|
21
|
+
getRouter(): ProstoRouter<TWooksHandler>;
|
|
22
|
+
getLogger(topic: string): TConsoleBase;
|
|
23
|
+
getLoggerOptions(): TProstoLoggerOptions;
|
|
24
|
+
lookup(method: string, path: string): {
|
|
25
|
+
handlers: TWooksHandler[] | null;
|
|
26
|
+
segments: _prostojs_router.TParsedSegment[] | null;
|
|
27
|
+
firstStatic: string | null;
|
|
28
|
+
};
|
|
29
|
+
on<ResType = unknown, ParamsType = Record<string, string | string[]>>(method: string, path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
|
|
30
|
+
}
|
|
31
|
+
declare function getGlobalWooks(logger?: TConsoleBase, routerOpts?: TWooksOptions['router']): Wooks;
|
|
32
|
+
declare class WooksAdapterBase {
|
|
33
|
+
protected wooks: Wooks;
|
|
34
|
+
constructor(wooks?: Wooks | WooksAdapterBase, logger?: TConsoleBase, routerOpts?: TWooksOptions['router']);
|
|
35
|
+
getWooks(): Wooks;
|
|
36
|
+
/**
|
|
37
|
+
* Get logger instance for application logs
|
|
38
|
+
* ```js
|
|
39
|
+
* const app = createHttpApp()
|
|
40
|
+
* const logger = app.getLogger('app-logger')
|
|
41
|
+
* logger.log('My App log message')
|
|
42
|
+
* ```
|
|
43
|
+
* @param topic topic for logger
|
|
44
|
+
* @returns logger instance
|
|
45
|
+
*/
|
|
46
|
+
getLogger(topic: string): TConsoleBase;
|
|
47
|
+
protected getLoggerOptions(): TProstoLoggerOptions<Record<string, never>>;
|
|
48
|
+
protected mergeEventOptions(opts?: TEventOptions): TEventOptions;
|
|
49
|
+
on<ResType = unknown, ParamsType = Record<string, string | string[]>>(method: string, path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { type TWooksHandler, type TWooksOptions, Wooks, WooksAdapterBase, getGlobalWooks };
|
package/dist/index.mjs
CHANGED
|
@@ -16,8 +16,11 @@ function getDefaultLogger(topic) {
|
|
|
16
16
|
|
|
17
17
|
class Wooks {
|
|
18
18
|
constructor(opts) {
|
|
19
|
-
this.router = new ProstoRouter(
|
|
20
|
-
|
|
19
|
+
this.router = new ProstoRouter({
|
|
20
|
+
silent: true,
|
|
21
|
+
...(opts?.router || {}),
|
|
22
|
+
});
|
|
23
|
+
this.logger = opts?.logger || getDefaultLogger('wooks');
|
|
21
24
|
}
|
|
22
25
|
getRouter() {
|
|
23
26
|
return this.router;
|
|
@@ -35,13 +38,12 @@ class Wooks {
|
|
|
35
38
|
return {};
|
|
36
39
|
}
|
|
37
40
|
lookup(method, path) {
|
|
38
|
-
var _a, _b, _c, _d;
|
|
39
41
|
const found = this.getRouter().lookup(method, path || '');
|
|
40
|
-
useEventContext().store('routeParams').value =
|
|
42
|
+
useEventContext().store('routeParams').value = found?.ctx?.params || {};
|
|
41
43
|
return {
|
|
42
|
-
handlers:
|
|
43
|
-
segments:
|
|
44
|
-
firstStatic:
|
|
44
|
+
handlers: found?.route?.handlers || null,
|
|
45
|
+
segments: found?.route?.segments || null,
|
|
46
|
+
firstStatic: found?.route?.firstStatic || null,
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
49
|
on(method, path, handler) {
|
|
@@ -73,16 +75,6 @@ class WooksAdapterBase {
|
|
|
73
75
|
getWooks() {
|
|
74
76
|
return this.wooks;
|
|
75
77
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Get logger instance for application logs
|
|
78
|
-
* ```js
|
|
79
|
-
* const app = createHttpApp()
|
|
80
|
-
* const logger = app.getLogger('app-logger')
|
|
81
|
-
* logger.log('My App log message')
|
|
82
|
-
* ```
|
|
83
|
-
* @param topic topic for logger
|
|
84
|
-
* @returns logger instance
|
|
85
|
-
*/
|
|
86
78
|
getLogger(topic) {
|
|
87
79
|
return this.getWooks().getLogger(topic);
|
|
88
80
|
}
|
|
@@ -90,7 +82,13 @@ class WooksAdapterBase {
|
|
|
90
82
|
return this.getWooks().getLoggerOptions();
|
|
91
83
|
}
|
|
92
84
|
mergeEventOptions(opts) {
|
|
93
|
-
return
|
|
85
|
+
return {
|
|
86
|
+
...(opts || {}),
|
|
87
|
+
eventLogger: {
|
|
88
|
+
...this.getLoggerOptions(),
|
|
89
|
+
...(opts?.eventLogger || {}),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
94
92
|
}
|
|
95
93
|
on(method, path, handler) {
|
|
96
94
|
return this.wooks.on(method, path, handler);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wooks",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "wooks",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
|
+
"exports": {
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
".": {
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
11
19
|
"repository": {
|
|
12
20
|
"type": "git",
|
|
13
21
|
"url": "git+https://github.com/wooksjs/wooksjs.git",
|
|
@@ -32,8 +40,8 @@
|
|
|
32
40
|
},
|
|
33
41
|
"dependencies": {
|
|
34
42
|
"@prostojs/router": "^0.2.1",
|
|
35
|
-
"@prostojs/logger": "^0.
|
|
36
|
-
"@wooksjs/event-core": "0.4.
|
|
43
|
+
"@prostojs/logger": "^0.4.0",
|
|
44
|
+
"@wooksjs/event-core": "0.4.13"
|
|
37
45
|
},
|
|
38
46
|
"homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/wooks#readme"
|
|
39
47
|
}
|