@aura-stack/router 0.2.0 → 0.3.0
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/assert.cjs +61 -3
- package/dist/assert.d.cts +21 -1
- package/dist/assert.d.ts +21 -1
- package/dist/assert.js +8 -3
- package/dist/chunk-6PZEXNTS.js +31 -0
- package/dist/{chunk-O6SY753N.js → chunk-FWDOXDWG.js} +6 -6
- package/dist/{chunk-RFYOPPMW.js → chunk-GJC3ODME.js} +15 -6
- package/dist/chunk-JIA6NLL6.js +143 -0
- package/dist/{chunk-JRJKKBSH.js → chunk-JNMXLKDG.js} +12 -2
- package/dist/chunk-PT4GU6PH.js +78 -0
- package/dist/context.cjs +50 -47
- package/dist/context.d.cts +3 -2
- package/dist/context.d.ts +3 -2
- package/dist/context.js +3 -4
- package/dist/endpoint.cjs +29 -29
- package/dist/endpoint.d.cts +17 -16
- package/dist/endpoint.d.ts +17 -16
- package/dist/endpoint.js +5 -7
- package/dist/error.cjs +19 -7
- package/dist/error.d.cts +28 -3
- package/dist/error.d.ts +28 -3
- package/dist/error.js +9 -3
- package/dist/index.cjs +192 -110
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +19 -9
- package/dist/middlewares.cjs +15 -9
- package/dist/middlewares.d.cts +1 -0
- package/dist/middlewares.d.ts +1 -0
- package/dist/middlewares.js +2 -2
- package/dist/router.cjs +180 -98
- package/dist/router.d.cts +24 -2
- package/dist/router.d.ts +24 -2
- package/dist/router.js +13 -8
- package/dist/types.d.cts +67 -10
- package/dist/types.d.ts +67 -10
- package/package.json +7 -1
- package/dist/chunk-DR4C6QTF.js +0 -72
- package/dist/chunk-OXDCFAMF.js +0 -78
- package/dist/chunk-YUX3YHXF.js +0 -36
package/dist/context.cjs
CHANGED
|
@@ -27,12 +27,6 @@ __export(context_exports, {
|
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(context_exports);
|
|
29
29
|
|
|
30
|
-
// src/assert.ts
|
|
31
|
-
var supportedBodyMethods = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
32
|
-
var isSupportedBodyMethod = (method) => {
|
|
33
|
-
return supportedBodyMethods.has(method);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
30
|
// src/error.ts
|
|
37
31
|
var statusCode = {
|
|
38
32
|
OK: 200,
|
|
@@ -60,50 +54,50 @@ var statusCode = {
|
|
|
60
54
|
SERVICE_UNAVAILABLE: 503,
|
|
61
55
|
HTTP_VERSION_NOT_SUPPORTED: 505
|
|
62
56
|
};
|
|
63
|
-
var statusText = Object.
|
|
64
|
-
(previous,
|
|
65
|
-
return { ...previous, [
|
|
57
|
+
var statusText = Object.keys(statusCode).reduce(
|
|
58
|
+
(previous, status) => {
|
|
59
|
+
return { ...previous, [status]: status };
|
|
66
60
|
},
|
|
67
61
|
{}
|
|
68
62
|
);
|
|
69
63
|
var AuraStackRouterError = class extends Error {
|
|
70
64
|
constructor(type, message, name) {
|
|
71
65
|
super(message);
|
|
72
|
-
this.name = name ?? "
|
|
66
|
+
this.name = name ?? "RouterError";
|
|
73
67
|
this.status = statusCode[type];
|
|
74
|
-
this.statusText = statusText[
|
|
68
|
+
this.statusText = statusText[type];
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var RouterError = class extends AuraStackRouterError {
|
|
72
|
+
constructor(type, message, name) {
|
|
73
|
+
super(type, message, name);
|
|
74
|
+
this.name = name ?? "RouterError";
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
// src/
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
return
|
|
78
|
+
// src/assert.ts
|
|
79
|
+
var supportedBodyMethods = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
80
|
+
var isSupportedBodyMethod = (method) => {
|
|
81
|
+
return supportedBodyMethods.has(method);
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
// src/context.ts
|
|
85
|
-
var getRouteParams = (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
var getRouteParams = (params, config) => {
|
|
86
|
+
if (config.schemas?.params) {
|
|
87
|
+
const parsed = config.schemas.params.safeParse(params);
|
|
88
|
+
if (!parsed.success) {
|
|
89
|
+
throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid route parameters");
|
|
90
|
+
}
|
|
91
|
+
return parsed.data;
|
|
89
92
|
}
|
|
90
|
-
|
|
91
|
-
if (!params) return {};
|
|
92
|
-
const values = routeRegex.exec(path)?.slice(1);
|
|
93
|
-
return params.reduce(
|
|
94
|
-
(previous, now, idx) => ({
|
|
95
|
-
...previous,
|
|
96
|
-
[now]: decodeURIComponent(values?.[idx] ?? "")
|
|
97
|
-
}),
|
|
98
|
-
{}
|
|
99
|
-
);
|
|
93
|
+
return params;
|
|
100
94
|
};
|
|
101
95
|
var getSearchParams = (url, config) => {
|
|
102
96
|
const route = new URL(url);
|
|
103
97
|
if (config.schemas?.searchParams) {
|
|
104
98
|
const parsed = config.schemas.searchParams.safeParse(Object.fromEntries(route.searchParams.entries()));
|
|
105
99
|
if (!parsed.success) {
|
|
106
|
-
throw new
|
|
100
|
+
throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid search parameters");
|
|
107
101
|
}
|
|
108
102
|
return parsed.data;
|
|
109
103
|
}
|
|
@@ -114,33 +108,42 @@ var getHeaders = (request) => {
|
|
|
114
108
|
};
|
|
115
109
|
var getBody = async (request, config) => {
|
|
116
110
|
if (!isSupportedBodyMethod(request.method)) {
|
|
117
|
-
return
|
|
111
|
+
return null;
|
|
118
112
|
}
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
const clone = request.clone();
|
|
114
|
+
const contentType = clone.headers.get("Content-Type") ?? "";
|
|
115
|
+
if (contentType.includes("application/json") || config.schemas?.body) {
|
|
116
|
+
const json = await clone.json();
|
|
122
117
|
if (config.schemas?.body) {
|
|
123
118
|
const parsed = config.schemas.body.safeParse(json);
|
|
124
119
|
if (!parsed.success) {
|
|
125
|
-
throw new
|
|
120
|
+
throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid request body");
|
|
126
121
|
}
|
|
127
122
|
return parsed.data;
|
|
128
123
|
}
|
|
129
124
|
return json;
|
|
130
125
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
126
|
+
try {
|
|
127
|
+
if (createContentTypeRegex(["application/x-www-form-urlencoded", "multipart/form-data"], contentType)) {
|
|
128
|
+
return await clone.formData();
|
|
129
|
+
}
|
|
130
|
+
if (createContentTypeRegex(["text/", "application/xml"], contentType)) {
|
|
131
|
+
return await clone.text();
|
|
132
|
+
}
|
|
133
|
+
if (createContentTypeRegex(["application/octet-stream"], contentType)) {
|
|
134
|
+
return await clone.arrayBuffer();
|
|
135
|
+
}
|
|
136
|
+
if (createContentTypeRegex(["image/", "video/", "audio/", "application/pdf"], contentType)) {
|
|
137
|
+
return await clone.blob();
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
} catch {
|
|
141
|
+
throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid request body, the content-type does not match the body format");
|
|
142
142
|
}
|
|
143
|
-
|
|
143
|
+
};
|
|
144
|
+
var createContentTypeRegex = (contentTypes, contenType) => {
|
|
145
|
+
const regex = new RegExp(`${contentTypes.join("|")}`);
|
|
146
|
+
return regex.test(contenType);
|
|
144
147
|
};
|
|
145
148
|
// Annotate the CommonJS export names for ESM import in node:
|
|
146
149
|
0 && (module.exports = {
|
package/dist/context.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EndpointConfig, ContextSearchParams } from './types.cjs';
|
|
2
2
|
import 'zod';
|
|
3
|
+
import './error.cjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Extracts route parameters from a given path using the specified route pattern.
|
|
@@ -19,7 +20,7 @@ import 'zod';
|
|
|
19
20
|
* // Expected: { userId: "123", postId: "456" }
|
|
20
21
|
* const params = getRouteParams(route, path);
|
|
21
22
|
*/
|
|
22
|
-
declare const getRouteParams:
|
|
23
|
+
declare const getRouteParams: (params: Record<string, string>, config: EndpointConfig) => Record<string, unknown>;
|
|
23
24
|
/**
|
|
24
25
|
* Extracts and validates search parameters from a given URL from the request.
|
|
25
26
|
*
|
package/dist/context.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EndpointConfig, ContextSearchParams } from './types.js';
|
|
2
2
|
import 'zod';
|
|
3
|
+
import './error.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Extracts route parameters from a given path using the specified route pattern.
|
|
@@ -19,7 +20,7 @@ import 'zod';
|
|
|
19
20
|
* // Expected: { userId: "123", postId: "456" }
|
|
20
21
|
* const params = getRouteParams(route, path);
|
|
21
22
|
*/
|
|
22
|
-
declare const getRouteParams:
|
|
23
|
+
declare const getRouteParams: (params: Record<string, string>, config: EndpointConfig) => Record<string, unknown>;
|
|
23
24
|
/**
|
|
24
25
|
* Extracts and validates search parameters from a given URL from the request.
|
|
25
26
|
*
|
package/dist/context.js
CHANGED
|
@@ -3,10 +3,9 @@ import {
|
|
|
3
3
|
getHeaders,
|
|
4
4
|
getRouteParams,
|
|
5
5
|
getSearchParams
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-RFYOPPMW.js";
|
|
6
|
+
} from "./chunk-PT4GU6PH.js";
|
|
7
|
+
import "./chunk-JNMXLKDG.js";
|
|
8
|
+
import "./chunk-GJC3ODME.js";
|
|
10
9
|
export {
|
|
11
10
|
getBody,
|
|
12
11
|
getHeaders,
|
package/dist/endpoint.cjs
CHANGED
|
@@ -21,24 +21,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var endpoint_exports = {};
|
|
22
22
|
__export(endpoint_exports, {
|
|
23
23
|
createEndpoint: () => createEndpoint,
|
|
24
|
-
createEndpointConfig: () => createEndpointConfig
|
|
25
|
-
createRoutePattern: () => createRoutePattern
|
|
24
|
+
createEndpointConfig: () => createEndpointConfig
|
|
26
25
|
});
|
|
27
26
|
module.exports = __toCommonJS(endpoint_exports);
|
|
28
27
|
|
|
29
|
-
// src/assert.ts
|
|
30
|
-
var supportedMethods = /* @__PURE__ */ new Set(["GET", "POST", "DELETE", "PUT", "PATCH"]);
|
|
31
|
-
var isSupportedMethod = (method) => {
|
|
32
|
-
return supportedMethods.has(method);
|
|
33
|
-
};
|
|
34
|
-
var isValidRoute = (route) => {
|
|
35
|
-
const routePattern = /^\/[a-zA-Z0-9/_:-]*$/;
|
|
36
|
-
return routePattern.test(route);
|
|
37
|
-
};
|
|
38
|
-
var isValidHandler = (handler) => {
|
|
39
|
-
return typeof handler === "function";
|
|
40
|
-
};
|
|
41
|
-
|
|
42
28
|
// src/error.ts
|
|
43
29
|
var statusCode = {
|
|
44
30
|
OK: 200,
|
|
@@ -66,35 +52,50 @@ var statusCode = {
|
|
|
66
52
|
SERVICE_UNAVAILABLE: 503,
|
|
67
53
|
HTTP_VERSION_NOT_SUPPORTED: 505
|
|
68
54
|
};
|
|
69
|
-
var statusText = Object.
|
|
70
|
-
(previous,
|
|
71
|
-
return { ...previous, [
|
|
55
|
+
var statusText = Object.keys(statusCode).reduce(
|
|
56
|
+
(previous, status) => {
|
|
57
|
+
return { ...previous, [status]: status };
|
|
72
58
|
},
|
|
73
59
|
{}
|
|
74
60
|
);
|
|
75
61
|
var AuraStackRouterError = class extends Error {
|
|
76
62
|
constructor(type, message, name) {
|
|
77
63
|
super(message);
|
|
78
|
-
this.name = name ?? "
|
|
64
|
+
this.name = name ?? "RouterError";
|
|
79
65
|
this.status = statusCode[type];
|
|
80
|
-
this.statusText = statusText[
|
|
66
|
+
this.statusText = statusText[type];
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var RouterError = class extends AuraStackRouterError {
|
|
70
|
+
constructor(type, message, name) {
|
|
71
|
+
super(type, message, name);
|
|
72
|
+
this.name = name ?? "RouterError";
|
|
81
73
|
}
|
|
82
74
|
};
|
|
83
75
|
|
|
84
|
-
// src/
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
return
|
|
76
|
+
// src/assert.ts
|
|
77
|
+
var supportedMethods = /* @__PURE__ */ new Set(["GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS", "HEAD", "TRACE", "CONNECT"]);
|
|
78
|
+
var isSupportedMethod = (method) => {
|
|
79
|
+
return supportedMethods.has(method);
|
|
80
|
+
};
|
|
81
|
+
var isValidRoute = (route) => {
|
|
82
|
+
const routePattern = /^\/[a-zA-Z0-9/_:-]*$/;
|
|
83
|
+
return routePattern.test(route);
|
|
88
84
|
};
|
|
85
|
+
var isValidHandler = (handler) => {
|
|
86
|
+
return typeof handler === "function";
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/endpoint.ts
|
|
89
90
|
var createEndpoint = (method, route, handler, config = {}) => {
|
|
90
91
|
if (!isSupportedMethod(method)) {
|
|
91
|
-
throw new
|
|
92
|
+
throw new RouterError("METHOD_NOT_ALLOWED", `Unsupported HTTP method: ${method}`);
|
|
92
93
|
}
|
|
93
94
|
if (!isValidRoute(route)) {
|
|
94
|
-
throw new
|
|
95
|
+
throw new RouterError("BAD_REQUEST", `Invalid route format: ${route}`);
|
|
95
96
|
}
|
|
96
97
|
if (!isValidHandler(handler)) {
|
|
97
|
-
throw new
|
|
98
|
+
throw new RouterError("BAD_REQUEST", "Handler must be a function");
|
|
98
99
|
}
|
|
99
100
|
return { method, route, handler, config };
|
|
100
101
|
};
|
|
@@ -105,6 +106,5 @@ function createEndpointConfig(...args) {
|
|
|
105
106
|
// Annotate the CommonJS export names for ESM import in node:
|
|
106
107
|
0 && (module.exports = {
|
|
107
108
|
createEndpoint,
|
|
108
|
-
createEndpointConfig
|
|
109
|
-
createRoutePattern
|
|
109
|
+
createEndpointConfig
|
|
110
110
|
});
|
package/dist/endpoint.d.cts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTTPMethod, RoutePattern, EndpointSchemas, RouteHandler, EndpointConfig, RouteEndpoint } from './types.cjs';
|
|
2
2
|
import 'zod';
|
|
3
|
+
import './error.cjs';
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* Create a RegExp pattern from a route string. This function allows segment the
|
|
6
|
-
* dynamic params in the route. For example, the route `/users/:id` will be
|
|
7
|
-
* converted to a regex pattern that captures the `id` parameter.
|
|
8
|
-
*
|
|
9
|
-
* @param route - The route pattern string
|
|
10
|
-
* @returns A RegExp object that matches the route pattern
|
|
11
|
-
* @example
|
|
12
|
-
* // Expected: /^\/users\/([^/]+)$/
|
|
13
|
-
* const pattern = createRoutePattern("/users/:id");
|
|
14
|
-
*/
|
|
15
|
-
declare const createRoutePattern: (route: RoutePattern) => RegExp;
|
|
16
5
|
/**
|
|
17
6
|
* Defines an API endpoint for the router by specifying the HTTP method, route pattern,
|
|
18
7
|
* handler function, and optional configuration such as validation schemas or middlewares.
|
|
@@ -36,10 +25,13 @@ declare const createEndpoint: <const Method extends Uppercase<HTTPMethod>, const
|
|
|
36
25
|
* Create an endpoint configuration to be passed to the `createEndpoint` function.
|
|
37
26
|
* This function is primarily for type inference and does not perform any runtime checks.
|
|
38
27
|
*
|
|
39
|
-
*
|
|
28
|
+
* This overload is recommended when the route pattern does not need to be specified explicitly,
|
|
29
|
+
* otherwise use the overload that accepts the route pattern as the first argument.
|
|
30
|
+
*
|
|
40
31
|
* @param config - The endpoint configuration object
|
|
41
32
|
* @returns The same configuration object, typed as EndpointConfig
|
|
42
33
|
* @example
|
|
34
|
+
* // Without route pattern
|
|
43
35
|
* const config = createEndpointConfig({
|
|
44
36
|
* middlewares: [myMiddleware],
|
|
45
37
|
* schemas: {
|
|
@@ -52,8 +44,17 @@ declare const createEndpoint: <const Method extends Uppercase<HTTPMethod>, const
|
|
|
52
44
|
* const search = createEndpoint("GET", "/search", async (request, ctx) => {
|
|
53
45
|
* return new Response("Search results");
|
|
54
46
|
* }, config);
|
|
47
|
+
*
|
|
48
|
+
* // Overload with route pattern
|
|
49
|
+
* const config = createEndpointConfig("/users/:userId", {
|
|
50
|
+
* middlewares: [myMiddleware],
|
|
51
|
+
* })
|
|
52
|
+
*
|
|
53
|
+
* const getUser = createEndpoint("GET", "/users/:userId", async (request, ctx) => {
|
|
54
|
+
* return new Response("User details");
|
|
55
|
+
* }, config);
|
|
55
56
|
*/
|
|
56
57
|
declare function createEndpointConfig<Schemas extends EndpointSchemas>(config: EndpointConfig<RoutePattern, Schemas>): EndpointConfig<RoutePattern, Schemas>;
|
|
57
|
-
declare function createEndpointConfig<Route extends RoutePattern,
|
|
58
|
+
declare function createEndpointConfig<Route extends RoutePattern, Schemas extends EndpointSchemas>(route: Route, config: EndpointConfig<Route, Schemas>): EndpointConfig<Route, Schemas>;
|
|
58
59
|
|
|
59
|
-
export { createEndpoint, createEndpointConfig
|
|
60
|
+
export { createEndpoint, createEndpointConfig };
|
package/dist/endpoint.d.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTTPMethod, RoutePattern, EndpointSchemas, RouteHandler, EndpointConfig, RouteEndpoint } from './types.js';
|
|
2
2
|
import 'zod';
|
|
3
|
+
import './error.js';
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* Create a RegExp pattern from a route string. This function allows segment the
|
|
6
|
-
* dynamic params in the route. For example, the route `/users/:id` will be
|
|
7
|
-
* converted to a regex pattern that captures the `id` parameter.
|
|
8
|
-
*
|
|
9
|
-
* @param route - The route pattern string
|
|
10
|
-
* @returns A RegExp object that matches the route pattern
|
|
11
|
-
* @example
|
|
12
|
-
* // Expected: /^\/users\/([^/]+)$/
|
|
13
|
-
* const pattern = createRoutePattern("/users/:id");
|
|
14
|
-
*/
|
|
15
|
-
declare const createRoutePattern: (route: RoutePattern) => RegExp;
|
|
16
5
|
/**
|
|
17
6
|
* Defines an API endpoint for the router by specifying the HTTP method, route pattern,
|
|
18
7
|
* handler function, and optional configuration such as validation schemas or middlewares.
|
|
@@ -36,10 +25,13 @@ declare const createEndpoint: <const Method extends Uppercase<HTTPMethod>, const
|
|
|
36
25
|
* Create an endpoint configuration to be passed to the `createEndpoint` function.
|
|
37
26
|
* This function is primarily for type inference and does not perform any runtime checks.
|
|
38
27
|
*
|
|
39
|
-
*
|
|
28
|
+
* This overload is recommended when the route pattern does not need to be specified explicitly,
|
|
29
|
+
* otherwise use the overload that accepts the route pattern as the first argument.
|
|
30
|
+
*
|
|
40
31
|
* @param config - The endpoint configuration object
|
|
41
32
|
* @returns The same configuration object, typed as EndpointConfig
|
|
42
33
|
* @example
|
|
34
|
+
* // Without route pattern
|
|
43
35
|
* const config = createEndpointConfig({
|
|
44
36
|
* middlewares: [myMiddleware],
|
|
45
37
|
* schemas: {
|
|
@@ -52,8 +44,17 @@ declare const createEndpoint: <const Method extends Uppercase<HTTPMethod>, const
|
|
|
52
44
|
* const search = createEndpoint("GET", "/search", async (request, ctx) => {
|
|
53
45
|
* return new Response("Search results");
|
|
54
46
|
* }, config);
|
|
47
|
+
*
|
|
48
|
+
* // Overload with route pattern
|
|
49
|
+
* const config = createEndpointConfig("/users/:userId", {
|
|
50
|
+
* middlewares: [myMiddleware],
|
|
51
|
+
* })
|
|
52
|
+
*
|
|
53
|
+
* const getUser = createEndpoint("GET", "/users/:userId", async (request, ctx) => {
|
|
54
|
+
* return new Response("User details");
|
|
55
|
+
* }, config);
|
|
55
56
|
*/
|
|
56
57
|
declare function createEndpointConfig<Schemas extends EndpointSchemas>(config: EndpointConfig<RoutePattern, Schemas>): EndpointConfig<RoutePattern, Schemas>;
|
|
57
|
-
declare function createEndpointConfig<Route extends RoutePattern,
|
|
58
|
+
declare function createEndpointConfig<Route extends RoutePattern, Schemas extends EndpointSchemas>(route: Route, config: EndpointConfig<Route, Schemas>): EndpointConfig<Route, Schemas>;
|
|
58
59
|
|
|
59
|
-
export { createEndpoint, createEndpointConfig
|
|
60
|
+
export { createEndpoint, createEndpointConfig };
|
package/dist/endpoint.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createEndpoint,
|
|
3
|
-
createEndpointConfig
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-RFYOPPMW.js";
|
|
3
|
+
createEndpointConfig
|
|
4
|
+
} from "./chunk-6PZEXNTS.js";
|
|
5
|
+
import "./chunk-JNMXLKDG.js";
|
|
6
|
+
import "./chunk-GJC3ODME.js";
|
|
8
7
|
export {
|
|
9
8
|
createEndpoint,
|
|
10
|
-
createEndpointConfig
|
|
11
|
-
createRoutePattern
|
|
9
|
+
createEndpointConfig
|
|
12
10
|
};
|
package/dist/error.cjs
CHANGED
|
@@ -20,7 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/error.ts
|
|
21
21
|
var error_exports = {};
|
|
22
22
|
__export(error_exports, {
|
|
23
|
-
AuraStackRouterError: () => AuraStackRouterError
|
|
23
|
+
AuraStackRouterError: () => AuraStackRouterError,
|
|
24
|
+
RouterError: () => RouterError,
|
|
25
|
+
statusCode: () => statusCode,
|
|
26
|
+
statusText: () => statusText
|
|
24
27
|
});
|
|
25
28
|
module.exports = __toCommonJS(error_exports);
|
|
26
29
|
var statusCode = {
|
|
@@ -49,21 +52,30 @@ var statusCode = {
|
|
|
49
52
|
SERVICE_UNAVAILABLE: 503,
|
|
50
53
|
HTTP_VERSION_NOT_SUPPORTED: 505
|
|
51
54
|
};
|
|
52
|
-
var statusText = Object.
|
|
53
|
-
(previous,
|
|
54
|
-
return { ...previous, [
|
|
55
|
+
var statusText = Object.keys(statusCode).reduce(
|
|
56
|
+
(previous, status) => {
|
|
57
|
+
return { ...previous, [status]: status };
|
|
55
58
|
},
|
|
56
59
|
{}
|
|
57
60
|
);
|
|
58
61
|
var AuraStackRouterError = class extends Error {
|
|
59
62
|
constructor(type, message, name) {
|
|
60
63
|
super(message);
|
|
61
|
-
this.name = name ?? "
|
|
64
|
+
this.name = name ?? "RouterError";
|
|
62
65
|
this.status = statusCode[type];
|
|
63
|
-
this.statusText = statusText[
|
|
66
|
+
this.statusText = statusText[type];
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var RouterError = class extends AuraStackRouterError {
|
|
70
|
+
constructor(type, message, name) {
|
|
71
|
+
super(type, message, name);
|
|
72
|
+
this.name = name ?? "RouterError";
|
|
64
73
|
}
|
|
65
74
|
};
|
|
66
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
67
76
|
0 && (module.exports = {
|
|
68
|
-
AuraStackRouterError
|
|
77
|
+
AuraStackRouterError,
|
|
78
|
+
RouterError,
|
|
79
|
+
statusCode,
|
|
80
|
+
statusText
|
|
69
81
|
});
|
package/dist/error.d.cts
CHANGED
|
@@ -27,14 +27,39 @@ declare const statusCode: {
|
|
|
27
27
|
SERVICE_UNAVAILABLE: number;
|
|
28
28
|
HTTP_VERSION_NOT_SUPPORTED: number;
|
|
29
29
|
};
|
|
30
|
+
type StatusCode = keyof typeof statusCode;
|
|
31
|
+
/**
|
|
32
|
+
* Reverse mapping of status codes to their corresponding status text.
|
|
33
|
+
*/
|
|
34
|
+
declare const statusText: Record<"OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "UNPROCESSABLE_ENTITY" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "HTTP_VERSION_NOT_SUPPORTED", "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "UNPROCESSABLE_ENTITY" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "HTTP_VERSION_NOT_SUPPORTED">;
|
|
30
35
|
/**
|
|
31
36
|
* Defines the errors used in AuraStack Router. Includes HTTP status code and
|
|
32
37
|
* status text.
|
|
38
|
+
* @deprecated Use RouterError instead
|
|
33
39
|
*/
|
|
34
40
|
declare class AuraStackRouterError extends Error {
|
|
41
|
+
/**
|
|
42
|
+
* The HTTP status code associated with the error.
|
|
43
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
|
|
44
|
+
* @example
|
|
45
|
+
* NOT_FOUND: 404
|
|
46
|
+
* METHOD_NOT_ALLOWED: 405
|
|
47
|
+
* INTERNAL_SERVER_ERROR: 500
|
|
48
|
+
*/
|
|
35
49
|
readonly status: number;
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
/**
|
|
51
|
+
* The HTTP status text associated with the status code of the error.
|
|
52
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
|
|
53
|
+
* @example
|
|
54
|
+
* NOT_FOUND: NOT_FOUND
|
|
55
|
+
* METHOD_NOT_ALLOWED: METHOD_NOT_ALLOWED
|
|
56
|
+
* INTERNAL_SERVER_ERROR: INTERNAL_SERVER_ERROR
|
|
57
|
+
*/
|
|
58
|
+
readonly statusText: StatusCode;
|
|
59
|
+
constructor(type: StatusCode, message: string, name?: string);
|
|
60
|
+
}
|
|
61
|
+
declare class RouterError extends AuraStackRouterError {
|
|
62
|
+
constructor(type: StatusCode, message: string, name?: string);
|
|
38
63
|
}
|
|
39
64
|
|
|
40
|
-
export { AuraStackRouterError };
|
|
65
|
+
export { AuraStackRouterError, RouterError, statusCode, statusText };
|
package/dist/error.d.ts
CHANGED
|
@@ -27,14 +27,39 @@ declare const statusCode: {
|
|
|
27
27
|
SERVICE_UNAVAILABLE: number;
|
|
28
28
|
HTTP_VERSION_NOT_SUPPORTED: number;
|
|
29
29
|
};
|
|
30
|
+
type StatusCode = keyof typeof statusCode;
|
|
31
|
+
/**
|
|
32
|
+
* Reverse mapping of status codes to their corresponding status text.
|
|
33
|
+
*/
|
|
34
|
+
declare const statusText: Record<"OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "UNPROCESSABLE_ENTITY" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "HTTP_VERSION_NOT_SUPPORTED", "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "UNPROCESSABLE_ENTITY" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "HTTP_VERSION_NOT_SUPPORTED">;
|
|
30
35
|
/**
|
|
31
36
|
* Defines the errors used in AuraStack Router. Includes HTTP status code and
|
|
32
37
|
* status text.
|
|
38
|
+
* @deprecated Use RouterError instead
|
|
33
39
|
*/
|
|
34
40
|
declare class AuraStackRouterError extends Error {
|
|
41
|
+
/**
|
|
42
|
+
* The HTTP status code associated with the error.
|
|
43
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
|
|
44
|
+
* @example
|
|
45
|
+
* NOT_FOUND: 404
|
|
46
|
+
* METHOD_NOT_ALLOWED: 405
|
|
47
|
+
* INTERNAL_SERVER_ERROR: 500
|
|
48
|
+
*/
|
|
35
49
|
readonly status: number;
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
/**
|
|
51
|
+
* The HTTP status text associated with the status code of the error.
|
|
52
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
|
|
53
|
+
* @example
|
|
54
|
+
* NOT_FOUND: NOT_FOUND
|
|
55
|
+
* METHOD_NOT_ALLOWED: METHOD_NOT_ALLOWED
|
|
56
|
+
* INTERNAL_SERVER_ERROR: INTERNAL_SERVER_ERROR
|
|
57
|
+
*/
|
|
58
|
+
readonly statusText: StatusCode;
|
|
59
|
+
constructor(type: StatusCode, message: string, name?: string);
|
|
60
|
+
}
|
|
61
|
+
declare class RouterError extends AuraStackRouterError {
|
|
62
|
+
constructor(type: StatusCode, message: string, name?: string);
|
|
38
63
|
}
|
|
39
64
|
|
|
40
|
-
export { AuraStackRouterError };
|
|
65
|
+
export { AuraStackRouterError, RouterError, statusCode, statusText };
|
package/dist/error.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AuraStackRouterError
|
|
3
|
-
|
|
2
|
+
AuraStackRouterError,
|
|
3
|
+
RouterError,
|
|
4
|
+
statusCode,
|
|
5
|
+
statusText
|
|
6
|
+
} from "./chunk-GJC3ODME.js";
|
|
4
7
|
export {
|
|
5
|
-
AuraStackRouterError
|
|
8
|
+
AuraStackRouterError,
|
|
9
|
+
RouterError,
|
|
10
|
+
statusCode,
|
|
11
|
+
statusText
|
|
6
12
|
};
|