context-router 0.0.1 → 0.0.2

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,16 +1,20 @@
1
1
  {
2
2
  "name": "context-router",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "HTTP request router with URL pattern matching and context support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
- "import": "./dist/index.js",
10
- "require": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
9
+ "import": "./dist/router.js",
10
+ "require": "./dist/router.js",
11
+ "types": "./dist/router.d.ts"
12
12
  }
13
13
  },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/octoth0rpe/context-router.git"
17
+ },
14
18
  "scripts": {
15
19
  "build": "tsc",
16
20
  "dev": "tsc --watch",
package/dist/index.d.ts DELETED
@@ -1,14 +0,0 @@
1
- type HttpMethod = 'GET' | 'POST' | 'DELETE' | 'PATCH' | 'PUT';
2
- export type HandlerParams<Context extends Record<string, any> = {}> = {
3
- body: string;
4
- urlParams: Record<string, string | undefined>;
5
- searchParams: URLSearchParams;
6
- } & Context;
7
- export type Handler<Context extends Record<string, any> = {}> = (params: HandlerParams<Context>) => Response | Promise<Response>;
8
- export declare class Router<Context extends Record<string, any> = {}> {
9
- private routes;
10
- add: (method: HttpMethod, pathname: string, handler: Handler<Context>) => Router<Context>;
11
- match: (request: Request, context: Context) => Promise<Response>;
12
- }
13
- export {};
14
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,KAAK,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,CAAA;AAG7D,MAAM,MAAM,aAAa,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI;IACrE,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IAC7C,YAAY,EAAE,eAAe,CAAA;CAC7B,GAAG,OAAO,CAAA;AAGX,MAAM,MAAM,OAAO,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,CAC/D,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,KAC1B,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAGjC,qBAAa,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE;IAC3D,OAAO,CAAC,MAAM,CAMb;IAGD,GAAG,GAAI,QAAQ,UAAU,EAAE,UAAU,MAAM,EAAE,SAAS,OAAO,CAAC,OAAO,CAAC,KAAG,MAAM,CAAC,OAAO,CAAC,CAGvF;IAGD,KAAK,GAAU,SAAS,OAAO,EAAE,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAmBpE;CACD"}
package/dist/index.js DELETED
@@ -1,37 +0,0 @@
1
- // HTTP router with URLPattern-based matching and context injection
2
- export class Router {
3
- constructor() {
4
- this.routes = {
5
- GET: [],
6
- POST: [],
7
- DELETE: [],
8
- PATCH: [],
9
- PUT: [],
10
- };
11
- // Register route: creates URLPattern, stores handler, enables chaining
12
- this.add = (method, pathname, handler) => {
13
- this.routes[method].push({ pattern: new URLPattern({ pathname }), handler });
14
- return this;
15
- };
16
- // Match request: iterate routes by method, invoke first match with merged params
17
- this.match = async (request, context) => {
18
- const method = request.method.toUpperCase();
19
- const possibleRoutes = this.routes[method] || [];
20
- const body = await request.text();
21
- const { searchParams, pathname } = new URL(request.url);
22
- for (const route of possibleRoutes) {
23
- const result = route.pattern.exec({ pathname });
24
- if (result !== null) {
25
- return route.handler({
26
- body,
27
- urlParams: result.pathname.groups,
28
- searchParams,
29
- ...context,
30
- });
31
- }
32
- }
33
- return new Response('Not Found', { status: 404 });
34
- };
35
- }
36
- }
37
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAeA,mEAAmE;AACnE,MAAM,OAAO,MAAM;IAAnB;QACS,WAAM,GAA6E;YAC1F,GAAG,EAAE,EAAE;YACP,IAAI,EAAE,EAAE;YACR,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,GAAG,EAAE,EAAE;SACP,CAAA;QAED,uEAAuE;QACvE,QAAG,GAAG,CAAC,MAAkB,EAAE,QAAgB,EAAE,OAAyB,EAAmB,EAAE;YAC1F,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;YAC5E,OAAO,IAAI,CAAA;QACZ,CAAC,CAAA;QAED,iFAAiF;QACjF,UAAK,GAAG,KAAK,EAAE,OAAgB,EAAE,OAAgB,EAAqB,EAAE;YACvE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAgB,CAAA;YACzD,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;YAChD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,CAAA;YACjC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAEvD,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;gBACpC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;gBAC/C,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;oBACrB,OAAO,KAAK,CAAC,OAAO,CAAC;wBACpB,IAAI;wBACJ,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;wBACjC,YAAY;wBACZ,GAAG,OAAO;qBACV,CAAC,CAAA;gBACH,CAAC;YACF,CAAC;YAED,OAAO,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;QAClD,CAAC,CAAA;IACF,CAAC;CAAA"}