@wheeparam/library 0.0.1 → 0.0.3

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": "@wheeparam/library",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
package/dist/index.cjs DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- matchRoute: () => matchRoute,
24
- routeResponse: () => routeResponse
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
-
28
- // src/route.ts
29
- async function matchRoute(path, slug) {
30
- const pathSegments = path.split("/").filter(Boolean);
31
- const isDynamic = (segment) => segment.startsWith("[") && segment.endsWith("]");
32
- if (pathSegments.length !== slug.length) return null;
33
- const params = {};
34
- for (let i = 0; i < pathSegments.length; i++) {
35
- if (isDynamic(pathSegments[i])) {
36
- const key = pathSegments[i].slice(1, -1);
37
- params[key] = slug[i];
38
- } else if (pathSegments[i] !== slug[i]) {
39
- return null;
40
- }
41
- }
42
- return { params };
43
- }
44
- async function routeResponse(slug, routes, request) {
45
- for (const route of routes) {
46
- const matched = await matchRoute(route.path, slug);
47
- if (matched) {
48
- return route.handler(request, matched.params);
49
- }
50
- }
51
- return Response.json({ error: "Not Found" }, { status: 404 });
52
- }
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- matchRoute,
56
- routeResponse
57
- });
package/dist/index.d.cts DELETED
@@ -1,31 +0,0 @@
1
- type ApiParams = Record<string, string>;
2
- type RouteHandler = (request: Request, params: ApiParams) => Promise<Response>;
3
- type Routes = {
4
- path: string;
5
- handler: RouteHandler;
6
- };
7
- type ApiProps = {
8
- params: Promise<{
9
- slug?: string[];
10
- }>;
11
- };
12
- type ListResponse<T> = {
13
- result: T[];
14
- totalCount: number;
15
- };
16
- type RowResponse<T> = {
17
- result: T;
18
- };
19
- type ApiResult<T> = {
20
- result: T;
21
- };
22
- type ApiErrorResponse = {
23
- error: string;
24
- };
25
-
26
- declare function matchRoute(path: string, slug: string[]): Promise<{
27
- params: Record<string, string>;
28
- } | null>;
29
- declare function routeResponse(slug: string[], routes: Routes[], request: Request): Promise<Response>;
30
-
31
- export { type ApiErrorResponse, type ApiParams, type ApiProps, type ApiResult, type ListResponse, type RouteHandler, type Routes, type RowResponse, matchRoute, routeResponse };
package/dist/index.d.ts DELETED
@@ -1,31 +0,0 @@
1
- type ApiParams = Record<string, string>;
2
- type RouteHandler = (request: Request, params: ApiParams) => Promise<Response>;
3
- type Routes = {
4
- path: string;
5
- handler: RouteHandler;
6
- };
7
- type ApiProps = {
8
- params: Promise<{
9
- slug?: string[];
10
- }>;
11
- };
12
- type ListResponse<T> = {
13
- result: T[];
14
- totalCount: number;
15
- };
16
- type RowResponse<T> = {
17
- result: T;
18
- };
19
- type ApiResult<T> = {
20
- result: T;
21
- };
22
- type ApiErrorResponse = {
23
- error: string;
24
- };
25
-
26
- declare function matchRoute(path: string, slug: string[]): Promise<{
27
- params: Record<string, string>;
28
- } | null>;
29
- declare function routeResponse(slug: string[], routes: Routes[], request: Request): Promise<Response>;
30
-
31
- export { type ApiErrorResponse, type ApiParams, type ApiProps, type ApiResult, type ListResponse, type RouteHandler, type Routes, type RowResponse, matchRoute, routeResponse };
package/dist/index.js DELETED
@@ -1,29 +0,0 @@
1
- // src/route.ts
2
- async function matchRoute(path, slug) {
3
- const pathSegments = path.split("/").filter(Boolean);
4
- const isDynamic = (segment) => segment.startsWith("[") && segment.endsWith("]");
5
- if (pathSegments.length !== slug.length) return null;
6
- const params = {};
7
- for (let i = 0; i < pathSegments.length; i++) {
8
- if (isDynamic(pathSegments[i])) {
9
- const key = pathSegments[i].slice(1, -1);
10
- params[key] = slug[i];
11
- } else if (pathSegments[i] !== slug[i]) {
12
- return null;
13
- }
14
- }
15
- return { params };
16
- }
17
- async function routeResponse(slug, routes, request) {
18
- for (const route of routes) {
19
- const matched = await matchRoute(route.path, slug);
20
- if (matched) {
21
- return route.handler(request, matched.params);
22
- }
23
- }
24
- return Response.json({ error: "Not Found" }, { status: 404 });
25
- }
26
- export {
27
- matchRoute,
28
- routeResponse
29
- };