@webpieces/core-meta 0.2.7 → 0.2.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/core-meta",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Core metadata interfaces for WebPieces framework",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -23,39 +23,55 @@ export interface RouteBuilder {
23
23
  * Generic type parameter TResult represents the return type of the route handler.
24
24
  * This provides type safety for the entire request/response cycle.
25
25
  */
26
- export interface RouteDefinition<TResult = unknown> {
26
+ export declare class RouteDefinition<TResult = unknown> {
27
27
  method: string;
28
28
  path: string;
29
29
  handler: RouteHandler<TResult>;
30
+ controllerFilepath?: string;
31
+ constructor(method: string, path: string, handler: RouteHandler<TResult>, controllerFilepath?: string);
30
32
  }
31
33
  /**
32
34
  * Definition of a filter with priority.
35
+ *
36
+ * Use filepathPattern to scope filters to specific controllers:
37
+ * - 'src/controllers/admin/**' + '/*.ts' - All admin controllers
38
+ * - '**' + '/admin/**' - Any file in admin directories
39
+ * - '**' + '/UserController.ts' - Specific controller file
40
+ *
41
+ * If filepathPattern is not specified, the filter matches all controllers.
33
42
  */
34
- export interface FilterDefinition {
43
+ export declare class FilterDefinition {
35
44
  priority: number;
36
45
  filterClass: any;
37
- packageRegex?: RegExp;
46
+ /**
47
+ * Glob pattern to match controller file paths.
48
+ * If not specified, defaults to matching all controllers.
49
+ */
50
+ filepathPattern: string;
51
+ constructor(priority: number, filterClass: any, filepathPattern: string);
38
52
  }
39
53
  /**
40
54
  * Request data passed to route handlers.
41
55
  */
42
- export interface RouteRequest {
56
+ export declare class RouteRequest {
43
57
  body?: any;
44
58
  query?: Record<string, any>;
45
59
  params?: Record<string, any>;
46
60
  headers?: Record<string, any>;
61
+ constructor(body?: any, query?: Record<string, any>, params?: Record<string, any>, headers?: Record<string, any>);
47
62
  }
48
63
  /**
49
64
  * Context passed to route handlers.
50
65
  * Contains DI container, request data, and extracted parameters.
51
66
  */
52
- export interface RouteContext {
67
+ export declare class RouteContext {
53
68
  /** DI container for resolving dependencies */
54
69
  container: Container;
55
70
  /** Extracted parameters (e.g., from request body, path params) */
56
71
  params: any[];
57
72
  /** Original request data */
58
73
  request?: RouteRequest;
74
+ constructor(container: Container, params: any[], request?: RouteRequest);
59
75
  }
60
76
  /**
61
77
  * Handler class for routes.
package/src/WebAppMeta.js CHANGED
@@ -1,6 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RouteHandler = void 0;
3
+ exports.RouteHandler = exports.RouteContext = exports.RouteRequest = exports.FilterDefinition = exports.RouteDefinition = void 0;
4
+ /**
5
+ * Definition of a single route.
6
+ *
7
+ * Generic type parameter TResult represents the return type of the route handler.
8
+ * This provides type safety for the entire request/response cycle.
9
+ */
10
+ class RouteDefinition {
11
+ constructor(method, path, handler, controllerFilepath) {
12
+ this.method = method;
13
+ this.path = path;
14
+ this.handler = handler;
15
+ this.controllerFilepath = controllerFilepath;
16
+ }
17
+ }
18
+ exports.RouteDefinition = RouteDefinition;
19
+ /**
20
+ * Definition of a filter with priority.
21
+ *
22
+ * Use filepathPattern to scope filters to specific controllers:
23
+ * - 'src/controllers/admin/**' + '/*.ts' - All admin controllers
24
+ * - '**' + '/admin/**' - Any file in admin directories
25
+ * - '**' + '/UserController.ts' - Specific controller file
26
+ *
27
+ * If filepathPattern is not specified, the filter matches all controllers.
28
+ */
29
+ class FilterDefinition {
30
+ constructor(priority, filterClass, filepathPattern) {
31
+ this.priority = priority;
32
+ this.filterClass = filterClass;
33
+ this.filepathPattern = filepathPattern;
34
+ }
35
+ }
36
+ exports.FilterDefinition = FilterDefinition;
37
+ /**
38
+ * Request data passed to route handlers.
39
+ */
40
+ class RouteRequest {
41
+ constructor(body, query, params, headers) {
42
+ this.body = body;
43
+ this.query = query;
44
+ this.params = params;
45
+ this.headers = headers;
46
+ }
47
+ }
48
+ exports.RouteRequest = RouteRequest;
49
+ /**
50
+ * Context passed to route handlers.
51
+ * Contains DI container, request data, and extracted parameters.
52
+ */
53
+ class RouteContext {
54
+ constructor(container, params, request) {
55
+ this.container = container;
56
+ this.params = params;
57
+ this.request = request;
58
+ }
59
+ }
60
+ exports.RouteContext = RouteContext;
4
61
  /**
5
62
  * Handler class for routes.
6
63
  * Takes a RouteContext and returns the controller method result.
@@ -1 +1 @@
1
- {"version":3,"file":"WebAppMeta.js","sourceRoot":"","sources":["../../../../../packages/core/core-meta/src/WebAppMeta.ts"],"names":[],"mappings":";;;AAkEA;;;;;;;;;;;;GAYG;AACH,MAAsB,YAAY;CAOjC;AAPD,oCAOC"}
1
+ {"version":3,"file":"WebAppMeta.js","sourceRoot":"","sources":["../../../../../packages/core/core-meta/src/WebAppMeta.ts"],"names":[],"mappings":";;;AAsBA;;;;;GAKG;AACH,MAAa,eAAe;IAM1B,YACE,MAAc,EACd,IAAY,EACZ,OAA8B,EAC9B,kBAA2B;QAE3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;CACF;AAjBD,0CAiBC;AAED;;;;;;;;;GASG;AACH,MAAa,gBAAgB;IAU3B,YACE,QAAgB,EAChB,WAAgB,EAChB,eAAuB;QAEvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;CACF;AAnBD,4CAmBC;AAED;;GAEG;AACH,MAAa,YAAY;IAMvB,YACE,IAAU,EACV,KAA2B,EAC3B,MAA4B,EAC5B,OAA6B;QAE7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAjBD,oCAiBC;AAED;;;GAGG;AACH,MAAa,YAAY;IAQvB,YACE,SAAoB,EACpB,MAAa,EACb,OAAsB;QAEtB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAjBD,oCAiBC;AAED;;;;;;;;;;;;GAYG;AACH,MAAsB,YAAY;CAOjC;AAPD,oCAOC","sourcesContent":["import { ContainerModule, Container } from 'inversify';\n\n/**\n * Represents a route configuration that can be registered with the router.\n * Similar to Java WebPieces Routes interface.\n */\nexport interface Routes {\n /**\n * Configure routes using the provided RouteBuilder.\n */\n configure(routeBuilder: RouteBuilder): void;\n}\n\n/**\n * Builder for registering routes.\n * Will be implemented in http-routing package.\n */\nexport interface RouteBuilder {\n addRoute<TResult = unknown>(route: RouteDefinition<TResult>): void;\n addFilter(filter: FilterDefinition): void;\n}\n\n/**\n * Definition of a single route.\n *\n * Generic type parameter TResult represents the return type of the route handler.\n * This provides type safety for the entire request/response cycle.\n */\nexport class RouteDefinition<TResult = unknown> {\n method: string;\n path: string;\n handler: RouteHandler<TResult>;\n controllerFilepath?: string;\n\n constructor(\n method: string,\n path: string,\n handler: RouteHandler<TResult>,\n controllerFilepath?: string\n ) {\n this.method = method;\n this.path = path;\n this.handler = handler;\n this.controllerFilepath = controllerFilepath;\n }\n}\n\n/**\n * Definition of a filter with priority.\n *\n * Use filepathPattern to scope filters to specific controllers:\n * - 'src/controllers/admin/**' + '/*.ts' - All admin controllers\n * - '**' + '/admin/**' - Any file in admin directories\n * - '**' + '/UserController.ts' - Specific controller file\n *\n * If filepathPattern is not specified, the filter matches all controllers.\n */\nexport class FilterDefinition {\n priority: number;\n filterClass: any;\n\n /**\n * Glob pattern to match controller file paths.\n * If not specified, defaults to matching all controllers.\n */\n filepathPattern: string;\n\n constructor(\n priority: number,\n filterClass: any,\n filepathPattern: string,\n ) {\n this.priority = priority;\n this.filterClass = filterClass;\n this.filepathPattern = filepathPattern;\n }\n}\n\n/**\n * Request data passed to route handlers.\n */\nexport class RouteRequest {\n body?: any;\n query?: Record<string, any>;\n params?: Record<string, any>;\n headers?: Record<string, any>;\n\n constructor(\n body?: any,\n query?: Record<string, any>,\n params?: Record<string, any>,\n headers?: Record<string, any>\n ) {\n this.body = body;\n this.query = query;\n this.params = params;\n this.headers = headers;\n }\n}\n\n/**\n * Context passed to route handlers.\n * Contains DI container, request data, and extracted parameters.\n */\nexport class RouteContext {\n /** DI container for resolving dependencies */\n container: Container;\n /** Extracted parameters (e.g., from request body, path params) */\n params: any[];\n /** Original request data */\n request?: RouteRequest;\n\n constructor(\n container: Container,\n params: any[],\n request?: RouteRequest\n ) {\n this.container = container;\n this.params = params;\n this.request = request;\n }\n}\n\n/**\n * Handler class for routes.\n * Takes a RouteContext and returns the controller method result.\n *\n * Generic type parameter TResult represents the return type of the controller method.\n * Example: RouteHandler<SaveResponse> for a method that returns Promise<SaveResponse>\n *\n * Using unknown as default instead of any forces type safety - consumers must\n * handle the result appropriately rather than assuming any type.\n *\n * This is a class instead of a function type to make it easier to trace\n * who is calling what in the debugger/IDE.\n */\nexport abstract class RouteHandler<TResult = unknown> {\n /**\n * Execute the route handler.\n * @param context - The route context containing DI container, params, and request\n * @returns Promise of the controller method result\n */\n abstract execute(context: RouteContext): Promise<TResult>;\n}\n\n/**\n * Main application metadata interface.\n * Similar to Java WebPieces WebAppMeta.\n *\n * This is the entry point that WebpiecesServer calls to configure your application.\n */\nexport interface WebAppMeta {\n /**\n * Returns the list of Inversify container modules for dependency injection.\n * Similar to getGuiceModules() in Java.\n */\n getDIModules(): ContainerModule[];\n\n /**\n * Returns the list of route configurations.\n * Similar to getRouteModules() in Java.\n */\n getRoutes(): Routes[];\n}\n"]}
package/src/index.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RouteHandler = void 0;
3
+ exports.RouteRequest = exports.RouteContext = exports.RouteHandler = exports.FilterDefinition = exports.RouteDefinition = void 0;
4
4
  var WebAppMeta_1 = require("./WebAppMeta");
5
+ Object.defineProperty(exports, "RouteDefinition", { enumerable: true, get: function () { return WebAppMeta_1.RouteDefinition; } });
6
+ Object.defineProperty(exports, "FilterDefinition", { enumerable: true, get: function () { return WebAppMeta_1.FilterDefinition; } });
5
7
  Object.defineProperty(exports, "RouteHandler", { enumerable: true, get: function () { return WebAppMeta_1.RouteHandler; } });
8
+ Object.defineProperty(exports, "RouteContext", { enumerable: true, get: function () { return WebAppMeta_1.RouteContext; } });
9
+ Object.defineProperty(exports, "RouteRequest", { enumerable: true, get: function () { return WebAppMeta_1.RouteRequest; } });
6
10
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/core-meta/src/index.ts"],"names":[],"mappings":";;;AAAA,2CASsB;AAHpB,0GAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/core-meta/src/index.ts"],"names":[],"mappings":";;;AAAA,2CASsB;AALpB,6GAAA,eAAe,OAAA;AACf,8GAAA,gBAAgB,OAAA;AAChB,0GAAA,YAAY,OAAA;AACZ,0GAAA,YAAY,OAAA;AACZ,0GAAA,YAAY,OAAA","sourcesContent":["export {\n WebAppMeta,\n Routes,\n RouteBuilder,\n RouteDefinition,\n FilterDefinition,\n RouteHandler,\n RouteContext,\n RouteRequest,\n} from './WebAppMeta';\n"]}