wooks 0.2.13 → 0.2.14

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 CHANGED
@@ -2,16 +2,35 @@
2
2
 
3
3
  var router = require('@prostojs/router');
4
4
  var eventCore = require('@wooksjs/event-core');
5
+ var logger = require('@prostojs/logger');
6
+
7
+ function getDefaultLogger(topic) {
8
+ return new logger.ProstoLogger({
9
+ level: 4,
10
+ transports: [
11
+ logger.createConsoleTransort({
12
+ format: logger.coloredConsole,
13
+ }),
14
+ ],
15
+ }, topic);
16
+ }
5
17
 
6
18
  class Wooks {
7
- constructor() {
19
+ constructor(opts) {
8
20
  this.router = new router.ProstoRouter({
9
21
  silent: true,
10
22
  });
23
+ this.logger = (opts === null || opts === void 0 ? void 0 : opts.logger) || getDefaultLogger('wooks');
11
24
  }
12
25
  getRouter() {
13
26
  return this.router;
14
27
  }
28
+ getLogger(topic) {
29
+ if (this.logger instanceof logger.ProstoLogger) {
30
+ return this.logger.createTopic(topic);
31
+ }
32
+ return this.logger;
33
+ }
15
34
  lookup(method, path) {
16
35
  var _a, _b;
17
36
  const found = this.getRouter().lookup(method, path || '');
@@ -44,6 +63,9 @@ class WooksAdapterBase {
44
63
  getWooks() {
45
64
  return this.wooks;
46
65
  }
66
+ getLogger(topic) {
67
+ return this.wooks.getLogger(topic);
68
+ }
47
69
  on(method, path, handler) {
48
70
  return this.wooks.on(method, path, handler);
49
71
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ProstoRouter } from '@prostojs/router';
2
+ import { TConsoleBase } from '@prostojs/logger';
2
3
  import { TProstoRouterPathBuilder } from '@prostojs/router';
3
4
 
4
5
  export declare function getGlobalWooks(): Wooks;
@@ -6,6 +7,7 @@ export declare function getGlobalWooks(): Wooks;
6
7
  export declare type TWooksHandler<ResType = unknown> = () => Promise<ResType> | ResType;
7
8
 
8
9
  export declare interface TWooksOptions {
10
+ logger?: TConsoleBase;
9
11
  }
10
12
 
11
13
  export declare function useRouteParams<T extends object = Record<string, string | string[]>>(): {
@@ -15,8 +17,10 @@ export declare function useRouteParams<T extends object = Record<string, string
15
17
 
16
18
  export declare class Wooks {
17
19
  protected router: ProstoRouter<TWooksHandler>;
18
- constructor();
20
+ protected logger: TConsoleBase;
21
+ constructor(opts?: TWooksOptions);
19
22
  getRouter(): ProstoRouter<TWooksHandler<unknown>>;
23
+ getLogger(topic: string): TConsoleBase;
20
24
  lookup(method: string, path: string): TWooksHandler<unknown>[] | null;
21
25
  on<ResType = unknown, ParamsType = Record<string, string | string[]>>(method: string, path: string, handler: TWooksHandler<ResType>): TProstoRouterPathBuilder<ParamsType>;
22
26
  }
@@ -25,6 +29,7 @@ export declare class WooksAdapterBase {
25
29
  protected wooks: Wooks;
26
30
  constructor(wooks?: Wooks | WooksAdapterBase);
27
31
  getWooks(): Wooks;
32
+ getLogger(topic: string): TConsoleBase;
28
33
  on<ResType = unknown, ParamsType = Record<string, string | string[]>>(method: string, path: string, handler: TWooksHandler<ResType>): TProstoRouterPathBuilder<ParamsType>;
29
34
  }
30
35
 
package/dist/index.mjs CHANGED
@@ -1,16 +1,35 @@
1
1
  import { ProstoRouter } from '@prostojs/router';
2
2
  import { useEventContext } from '@wooksjs/event-core';
3
3
  export { useRouteParams } from '@wooksjs/event-core';
4
+ import { ProstoLogger, createConsoleTransort, coloredConsole } from '@prostojs/logger';
5
+
6
+ function getDefaultLogger(topic) {
7
+ return new ProstoLogger({
8
+ level: 4,
9
+ transports: [
10
+ createConsoleTransort({
11
+ format: coloredConsole,
12
+ }),
13
+ ],
14
+ }, topic);
15
+ }
4
16
 
5
17
  class Wooks {
6
- constructor() {
18
+ constructor(opts) {
7
19
  this.router = new ProstoRouter({
8
20
  silent: true,
9
21
  });
22
+ this.logger = (opts === null || opts === void 0 ? void 0 : opts.logger) || getDefaultLogger('wooks');
10
23
  }
11
24
  getRouter() {
12
25
  return this.router;
13
26
  }
27
+ getLogger(topic) {
28
+ if (this.logger instanceof ProstoLogger) {
29
+ return this.logger.createTopic(topic);
30
+ }
31
+ return this.logger;
32
+ }
14
33
  lookup(method, path) {
15
34
  var _a, _b;
16
35
  const found = this.getRouter().lookup(method, path || '');
@@ -43,6 +62,9 @@ class WooksAdapterBase {
43
62
  getWooks() {
44
63
  return this.wooks;
45
64
  }
65
+ getLogger(topic) {
66
+ return this.wooks.getLogger(topic);
67
+ }
46
68
  on(method, path, handler) {
47
69
  return this.wooks.on(method, path, handler);
48
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wooks",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "wooks",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -32,7 +32,8 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@prostojs/router": "^0.0.16",
35
- "@wooksjs/event-core": "0.2.13"
35
+ "@prostojs/logger": "^0.3.2",
36
+ "@wooksjs/event-core": "0.2.14"
36
37
  },
37
38
  "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/wooks#readme"
38
39
  }