wooks 0.6.2 → 0.6.4

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
@@ -32,9 +32,19 @@ function getDefaultLogger(topic) {
32
32
  transports: [(0, __prostojs_logger.createConsoleTransort)({ format: __prostojs_logger.coloredConsole })]
33
33
  }, topic);
34
34
  }
35
+ /**
36
+ * Core Wooks framework class that manages routing and logging.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const wooks = new Wooks({ router: { ignoreTrailingSlash: true } })
41
+ * wooks.on('GET', '/hello', () => 'Hello World')
42
+ * ```
43
+ */
35
44
  var Wooks = class {
36
45
  router;
37
46
  logger;
47
+ /** @param opts - Optional configuration for router and logger. */
38
48
  constructor(opts) {
39
49
  this.router = new __prostojs_router.ProstoRouter({
40
50
  silent: true,
@@ -42,17 +52,28 @@ var Wooks = class {
42
52
  });
43
53
  this.logger = opts?.logger || getDefaultLogger(`[wooks]`);
44
54
  }
55
+ /** Returns the underlying ProstoRouter instance. */
45
56
  getRouter() {
46
57
  return this.router;
47
58
  }
59
+ /**
60
+ * Creates a child logger with the given topic.
61
+ * @param topic - Label for the logger topic.
62
+ */
48
63
  getLogger(topic) {
49
64
  if (this.logger instanceof __prostojs_logger.ProstoLogger) return this.logger.createTopic(topic);
50
65
  return this.logger;
51
66
  }
67
+ /** Returns the current logger configuration options. */
52
68
  getLoggerOptions() {
53
69
  if (this.logger instanceof __prostojs_logger.ProstoLogger) return this.logger.getOptions();
54
70
  return {};
55
71
  }
72
+ /**
73
+ * Looks up a route by method and path, setting route params in the current event context.
74
+ * @param method - HTTP method (e.g., "GET", "POST").
75
+ * @param path - URL path to match against registered routes.
76
+ */
56
77
  lookup(method, path) {
57
78
  const found = this.getRouter().lookup(method, path || "");
58
79
  (0, __wooksjs_event_core.useAsyncEventContext)().store("routeParams").value = found?.ctx?.params || {};
@@ -65,6 +86,12 @@ var Wooks = class {
65
86
  path: found?.route?.path || null
66
87
  };
67
88
  }
89
+ /**
90
+ * Registers a route handler for the given method and path.
91
+ * @param method - HTTP method (e.g., "GET", "POST").
92
+ * @param path - URL path pattern (supports parameters like `/users/:id`).
93
+ * @param handler - Handler function invoked when the route matches.
94
+ */
68
95
  on(method, path, handler) {
69
96
  return this.router.on(method, path, handler);
70
97
  }
@@ -79,10 +106,9 @@ function clearGlobalWooks() {
79
106
  gWooks = void 0;
80
107
  }
81
108
  /**
82
- * Creates global wooks singleton instance to share across adapters
83
- * @param logger
84
- * @param routerOpts
85
- * @returns
109
+ * Returns the global Wooks singleton, creating it on first call.
110
+ * @param logger - Optional custom logger for the instance.
111
+ * @param routerOpts - Optional router configuration.
86
112
  */
87
113
  function getGlobalWooks(logger, routerOpts) {
88
114
  if (!gWooks) gWooks = new Wooks({
@@ -91,13 +117,31 @@ function getGlobalWooks(logger, routerOpts) {
91
117
  });
92
118
  return gWooks;
93
119
  }
120
+ /**
121
+ * Base class for Wooks adapters that bridges a specific runtime (e.g., HTTP, CLI) with Wooks routing.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * class MyAdapter extends WooksAdapterBase {
126
+ * constructor(wooks?: Wooks) {
127
+ * super(wooks)
128
+ * }
129
+ * }
130
+ * ```
131
+ */
94
132
  var WooksAdapterBase = class WooksAdapterBase {
95
133
  wooks;
134
+ /**
135
+ * @param wooks - Existing Wooks or adapter instance to share; creates/uses global instance if omitted.
136
+ * @param logger - Custom logger for the global Wooks instance (ignored when `wooks` is provided).
137
+ * @param routerOpts - Router options for the global Wooks instance (ignored when `wooks` is provided).
138
+ */
96
139
  constructor(wooks, logger, routerOpts) {
97
140
  if (wooks && wooks instanceof WooksAdapterBase) this.wooks = wooks.getWooks();
98
141
  else if (wooks && wooks instanceof Wooks) this.wooks = wooks;
99
142
  else this.wooks = getGlobalWooks(logger, routerOpts);
100
143
  }
144
+ /** Returns the underlying Wooks instance. */
101
145
  getWooks() {
102
146
  return this.wooks;
103
147
  }
@@ -117,6 +161,7 @@ var WooksAdapterBase = class WooksAdapterBase {
117
161
  getLoggerOptions() {
118
162
  return this.getWooks().getLoggerOptions();
119
163
  }
164
+ /** Merges the given event options with the current logger configuration. */
120
165
  mergeEventOptions(opts) {
121
166
  return {
122
167
  ...opts,
@@ -126,6 +171,12 @@ var WooksAdapterBase = class WooksAdapterBase {
126
171
  }
127
172
  };
128
173
  }
174
+ /**
175
+ * Registers a route handler for the given method and path.
176
+ * @param method - HTTP method (e.g., "GET", "POST").
177
+ * @param path - URL path pattern (supports parameters like `/users/:id`).
178
+ * @param handler - Handler function invoked when the route matches.
179
+ */
129
180
  on(method, path, handler) {
130
181
  return this.wooks.on(method, path, handler);
131
182
  }
package/dist/index.d.ts CHANGED
@@ -4,29 +4,63 @@ export { TProstoRouterPathHandle } from '@prostojs/router';
4
4
  import { TEventOptions } from '@wooksjs/event-core';
5
5
  export { useEventId, useEventLogger, useRouteParams } from '@wooksjs/event-core';
6
6
 
7
+ /** A route handler function that returns a response synchronously or asynchronously. */
7
8
  type TWooksHandler<ResType = unknown> = () => Promise<ResType> | ResType;
8
9
 
10
+ /** Configuration options for the Wooks instance. */
9
11
  interface TWooksOptions {
12
+ /** Custom logger instance to use instead of the default. */
10
13
  logger?: TConsoleBase;
14
+ /** Router configuration options. */
11
15
  router?: {
16
+ /** When true, `/path` and `/path/` are treated as the same route. */
12
17
  ignoreTrailingSlash?: boolean;
18
+ /** When true, route matching is case-insensitive. */
13
19
  ignoreCase?: boolean;
20
+ /** Maximum number of parsed routes to cache. */
14
21
  cacheLimit?: number;
15
22
  };
16
23
  }
24
+ /**
25
+ * Core Wooks framework class that manages routing and logging.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const wooks = new Wooks({ router: { ignoreTrailingSlash: true } })
30
+ * wooks.on('GET', '/hello', () => 'Hello World')
31
+ * ```
32
+ */
17
33
  declare class Wooks {
18
34
  protected router: ProstoRouter<TWooksHandler>;
19
35
  protected logger: TConsoleBase;
36
+ /** @param opts - Optional configuration for router and logger. */
20
37
  constructor(opts?: TWooksOptions);
38
+ /** Returns the underlying ProstoRouter instance. */
21
39
  getRouter(): ProstoRouter<TWooksHandler>;
40
+ /**
41
+ * Creates a child logger with the given topic.
42
+ * @param topic - Label for the logger topic.
43
+ */
22
44
  getLogger(topic: string): TConsoleBase;
45
+ /** Returns the current logger configuration options. */
23
46
  getLoggerOptions(): TProstoLoggerOptions;
47
+ /**
48
+ * Looks up a route by method and path, setting route params in the current event context.
49
+ * @param method - HTTP method (e.g., "GET", "POST").
50
+ * @param path - URL path to match against registered routes.
51
+ */
24
52
  lookup(method: string, path: string): {
25
53
  handlers: TWooksHandler[] | null;
26
54
  segments: TParsedSegment[] | null;
27
55
  firstStatic: string | null;
28
56
  path: string | null;
29
57
  };
58
+ /**
59
+ * Registers a route handler for the given method and path.
60
+ * @param method - HTTP method (e.g., "GET", "POST").
61
+ * @param path - URL path pattern (supports parameters like `/users/:id`).
62
+ * @param handler - Handler function invoked when the route matches.
63
+ */
30
64
  on<ResType = unknown, ParamsType = Record<string, string | string[]>>(method: string, path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
31
65
  }
32
66
  /**
@@ -36,15 +70,32 @@ declare class Wooks {
36
70
  */
37
71
  declare function clearGlobalWooks(): void;
38
72
  /**
39
- * Creates global wooks singleton instance to share across adapters
40
- * @param logger
41
- * @param routerOpts
42
- * @returns
73
+ * Returns the global Wooks singleton, creating it on first call.
74
+ * @param logger - Optional custom logger for the instance.
75
+ * @param routerOpts - Optional router configuration.
43
76
  */
44
77
  declare function getGlobalWooks(logger?: TConsoleBase, routerOpts?: TWooksOptions['router']): Wooks;
78
+ /**
79
+ * Base class for Wooks adapters that bridges a specific runtime (e.g., HTTP, CLI) with Wooks routing.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * class MyAdapter extends WooksAdapterBase {
84
+ * constructor(wooks?: Wooks) {
85
+ * super(wooks)
86
+ * }
87
+ * }
88
+ * ```
89
+ */
45
90
  declare class WooksAdapterBase {
46
91
  protected wooks: Wooks;
92
+ /**
93
+ * @param wooks - Existing Wooks or adapter instance to share; creates/uses global instance if omitted.
94
+ * @param logger - Custom logger for the global Wooks instance (ignored when `wooks` is provided).
95
+ * @param routerOpts - Router options for the global Wooks instance (ignored when `wooks` is provided).
96
+ */
47
97
  constructor(wooks?: Wooks | WooksAdapterBase, logger?: TConsoleBase, routerOpts?: TWooksOptions['router']);
98
+ /** Returns the underlying Wooks instance. */
48
99
  getWooks(): Wooks;
49
100
  /**
50
101
  * Get logger instance for application logs
@@ -58,8 +109,16 @@ declare class WooksAdapterBase {
58
109
  */
59
110
  getLogger(topic: string): TConsoleBase;
60
111
  protected getLoggerOptions(): TProstoLoggerOptions;
112
+ /** Merges the given event options with the current logger configuration. */
61
113
  protected mergeEventOptions(opts?: TEventOptions): TEventOptions;
114
+ /**
115
+ * Registers a route handler for the given method and path.
116
+ * @param method - HTTP method (e.g., "GET", "POST").
117
+ * @param path - URL path pattern (supports parameters like `/users/:id`).
118
+ * @param handler - Handler function invoked when the route matches.
119
+ */
62
120
  on<ResType = unknown, ParamsType = Record<string, string | string[]>>(method: string, path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
63
121
  }
64
122
 
65
- export { type TWooksHandler, type TWooksOptions, Wooks, WooksAdapterBase, clearGlobalWooks, getGlobalWooks };
123
+ export { Wooks, WooksAdapterBase, clearGlobalWooks, getGlobalWooks };
124
+ export type { TWooksHandler, TWooksOptions };
package/dist/index.mjs CHANGED
@@ -9,9 +9,19 @@ function getDefaultLogger(topic) {
9
9
  transports: [createConsoleTransort({ format: coloredConsole })]
10
10
  }, topic);
11
11
  }
12
+ /**
13
+ * Core Wooks framework class that manages routing and logging.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const wooks = new Wooks({ router: { ignoreTrailingSlash: true } })
18
+ * wooks.on('GET', '/hello', () => 'Hello World')
19
+ * ```
20
+ */
12
21
  var Wooks = class {
13
22
  router;
14
23
  logger;
24
+ /** @param opts - Optional configuration for router and logger. */
15
25
  constructor(opts) {
16
26
  this.router = new ProstoRouter({
17
27
  silent: true,
@@ -19,17 +29,28 @@ var Wooks = class {
19
29
  });
20
30
  this.logger = opts?.logger || getDefaultLogger(`[wooks]`);
21
31
  }
32
+ /** Returns the underlying ProstoRouter instance. */
22
33
  getRouter() {
23
34
  return this.router;
24
35
  }
36
+ /**
37
+ * Creates a child logger with the given topic.
38
+ * @param topic - Label for the logger topic.
39
+ */
25
40
  getLogger(topic) {
26
41
  if (this.logger instanceof ProstoLogger) return this.logger.createTopic(topic);
27
42
  return this.logger;
28
43
  }
44
+ /** Returns the current logger configuration options. */
29
45
  getLoggerOptions() {
30
46
  if (this.logger instanceof ProstoLogger) return this.logger.getOptions();
31
47
  return {};
32
48
  }
49
+ /**
50
+ * Looks up a route by method and path, setting route params in the current event context.
51
+ * @param method - HTTP method (e.g., "GET", "POST").
52
+ * @param path - URL path to match against registered routes.
53
+ */
33
54
  lookup(method, path) {
34
55
  const found = this.getRouter().lookup(method, path || "");
35
56
  useAsyncEventContext().store("routeParams").value = found?.ctx?.params || {};
@@ -42,6 +63,12 @@ var Wooks = class {
42
63
  path: found?.route?.path || null
43
64
  };
44
65
  }
66
+ /**
67
+ * Registers a route handler for the given method and path.
68
+ * @param method - HTTP method (e.g., "GET", "POST").
69
+ * @param path - URL path pattern (supports parameters like `/users/:id`).
70
+ * @param handler - Handler function invoked when the route matches.
71
+ */
45
72
  on(method, path, handler) {
46
73
  return this.router.on(method, path, handler);
47
74
  }
@@ -56,10 +83,9 @@ function clearGlobalWooks() {
56
83
  gWooks = void 0;
57
84
  }
58
85
  /**
59
- * Creates global wooks singleton instance to share across adapters
60
- * @param logger
61
- * @param routerOpts
62
- * @returns
86
+ * Returns the global Wooks singleton, creating it on first call.
87
+ * @param logger - Optional custom logger for the instance.
88
+ * @param routerOpts - Optional router configuration.
63
89
  */
64
90
  function getGlobalWooks(logger, routerOpts) {
65
91
  if (!gWooks) gWooks = new Wooks({
@@ -68,13 +94,31 @@ function getGlobalWooks(logger, routerOpts) {
68
94
  });
69
95
  return gWooks;
70
96
  }
97
+ /**
98
+ * Base class for Wooks adapters that bridges a specific runtime (e.g., HTTP, CLI) with Wooks routing.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * class MyAdapter extends WooksAdapterBase {
103
+ * constructor(wooks?: Wooks) {
104
+ * super(wooks)
105
+ * }
106
+ * }
107
+ * ```
108
+ */
71
109
  var WooksAdapterBase = class WooksAdapterBase {
72
110
  wooks;
111
+ /**
112
+ * @param wooks - Existing Wooks or adapter instance to share; creates/uses global instance if omitted.
113
+ * @param logger - Custom logger for the global Wooks instance (ignored when `wooks` is provided).
114
+ * @param routerOpts - Router options for the global Wooks instance (ignored when `wooks` is provided).
115
+ */
73
116
  constructor(wooks, logger, routerOpts) {
74
117
  if (wooks && wooks instanceof WooksAdapterBase) this.wooks = wooks.getWooks();
75
118
  else if (wooks && wooks instanceof Wooks) this.wooks = wooks;
76
119
  else this.wooks = getGlobalWooks(logger, routerOpts);
77
120
  }
121
+ /** Returns the underlying Wooks instance. */
78
122
  getWooks() {
79
123
  return this.wooks;
80
124
  }
@@ -94,6 +138,7 @@ var WooksAdapterBase = class WooksAdapterBase {
94
138
  getLoggerOptions() {
95
139
  return this.getWooks().getLoggerOptions();
96
140
  }
141
+ /** Merges the given event options with the current logger configuration. */
97
142
  mergeEventOptions(opts) {
98
143
  return {
99
144
  ...opts,
@@ -103,6 +148,12 @@ var WooksAdapterBase = class WooksAdapterBase {
103
148
  }
104
149
  };
105
150
  }
151
+ /**
152
+ * Registers a route handler for the given method and path.
153
+ * @param method - HTTP method (e.g., "GET", "POST").
154
+ * @param path - URL path pattern (supports parameters like `/users/:id`).
155
+ * @param handler - Handler function invoked when the route matches.
156
+ */
106
157
  on(method, path, handler) {
107
158
  return this.wooks.on(method, path, handler);
108
159
  }
package/package.json CHANGED
@@ -1,13 +1,36 @@
1
1
  {
2
2
  "name": "wooks",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "wooks",
5
- "main": "dist/index.cjs",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
5
+ "keywords": [
6
+ "api",
7
+ "app",
8
+ "composables",
9
+ "framework",
10
+ "http",
11
+ "prostojs",
12
+ "rest",
13
+ "restful",
14
+ "web",
15
+ "wooks"
16
+ ],
17
+ "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/wooks#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/wooksjs/wooksjs/issues"
20
+ },
21
+ "license": "MIT",
22
+ "author": "Artem Maltsev",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/wooksjs/wooksjs.git",
26
+ "directory": "packages/wooks"
27
+ },
8
28
  "files": [
9
29
  "dist"
10
30
  ],
31
+ "main": "dist/index.cjs",
32
+ "module": "dist/index.mjs",
33
+ "types": "dist/index.d.ts",
11
34
  "exports": {
12
35
  "./package.json": "./package.json",
13
36
  ".": {
@@ -16,39 +39,16 @@
16
39
  "import": "./dist/index.mjs"
17
40
  }
18
41
  },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/wooksjs/wooksjs.git",
22
- "directory": "packages/wooks"
23
- },
24
- "keywords": [
25
- "http",
26
- "wooks",
27
- "composables",
28
- "web",
29
- "framework",
30
- "app",
31
- "api",
32
- "rest",
33
- "restful",
34
- "prostojs"
35
- ],
36
- "author": "Artem Maltsev",
37
- "license": "MIT",
38
- "bugs": {
39
- "url": "https://github.com/wooksjs/wooksjs/issues"
40
- },
41
42
  "dependencies": {
42
43
  "@prostojs/logger": "^0.4.3",
43
44
  "@prostojs/router": "^0.2.1",
44
- "@wooksjs/event-core": "^0.6.2"
45
+ "@wooksjs/event-core": "^0.6.4"
45
46
  },
46
- "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/wooks#readme",
47
47
  "devDependencies": {
48
- "typescript": "^5.8.3",
48
+ "typescript": "^5.9.3",
49
49
  "vitest": "^3.2.4",
50
- "@wooksjs/event-http": "^0.6.2",
51
- "@wooksjs/http-body": "^0.6.2"
50
+ "@wooksjs/event-http": "^0.6.4",
51
+ "@wooksjs/http-body": "^0.6.4"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "rolldown -c ../../rolldown.config.mjs"