@spirobel/mininext 0.7.1 → 0.7.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/dist/url.d.ts +3 -2
- package/dist/url.js +8 -8
- package/package.json +1 -1
package/dist/url.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type MiniNextRouteValue<T extends string> = HtmlHandler<unknown, T> | Min
|
|
|
17
17
|
export type BunRoutes<R extends {
|
|
18
18
|
[K in keyof R]: RouterTypes.RouteValue<Extract<K, string>>;
|
|
19
19
|
}> = R;
|
|
20
|
+
export type MiniNextRoutes = Record<string, MiniNextRouteValue<"">>;
|
|
20
21
|
/**
|
|
21
22
|
* A helper function that helps narrow unknown objects
|
|
22
23
|
* @param object - the object of type unknown that is to be narrowed
|
|
@@ -107,7 +108,7 @@ interface LinkSettings {
|
|
|
107
108
|
export declare class url {
|
|
108
109
|
static websocket: WebSocketHandler | undefined;
|
|
109
110
|
static server: Server;
|
|
110
|
-
static routes:
|
|
111
|
+
static routes: MiniNextRoutes;
|
|
111
112
|
static direct_handlers_html: Map<string, HtmlHandler>;
|
|
112
113
|
private static frontends;
|
|
113
114
|
private static svgs;
|
|
@@ -282,7 +283,7 @@ export declare class url {
|
|
|
282
283
|
static install(): {
|
|
283
284
|
fetch: (req: Request, server: Server) => Response;
|
|
284
285
|
websocket: WebSocketHandler<undefined> | undefined;
|
|
285
|
-
routes:
|
|
286
|
+
routes: Record<string, RouterTypes.RouteValue<string>>;
|
|
286
287
|
};
|
|
287
288
|
}
|
|
288
289
|
export {};
|
package/dist/url.js
CHANGED
|
@@ -67,7 +67,7 @@ export class Mini {
|
|
|
67
67
|
export class url {
|
|
68
68
|
static websocket = undefined;
|
|
69
69
|
static server;
|
|
70
|
-
static routes;
|
|
70
|
+
static routes = {};
|
|
71
71
|
// direct mapping of "url string" -> function leads to Html Response
|
|
72
72
|
static direct_handlers_html = new Map();
|
|
73
73
|
// An array of the uncompiled frontend files, example frontends[0] = "index.tsx" -> frontend/index.tsx (from the project root)
|
|
@@ -491,31 +491,31 @@ export class url {
|
|
|
491
491
|
* @return {Promise<Response>} - The Response object.
|
|
492
492
|
*/
|
|
493
493
|
static install() {
|
|
494
|
+
const transformedRouteObject = {};
|
|
494
495
|
for (const route in url.routes) {
|
|
495
496
|
//handle route object split by methods and pull them through mininext
|
|
496
497
|
const handler = url.routes[route];
|
|
497
498
|
if (typeof handler === "function") {
|
|
498
|
-
|
|
499
|
+
transformedRouteObject[route] = (req, server) => url.handleWithMini(req, server, handler);
|
|
499
500
|
}
|
|
500
501
|
else {
|
|
501
502
|
const newHandlerObject = {};
|
|
502
503
|
for (const HTTPmethod in handler) {
|
|
503
504
|
newHandlerObject[HTTPmethod] = (req, server) => url.handleWithMini(req, server, handler[HTTPmethod]);
|
|
504
505
|
}
|
|
505
|
-
|
|
506
|
+
transformedRouteObject[route] = newHandlerObject;
|
|
506
507
|
}
|
|
507
508
|
}
|
|
508
|
-
//TODO add fronted + svg to routes object
|
|
509
509
|
for (const [route, handler] of url.direct_handlers_html) {
|
|
510
|
-
|
|
510
|
+
transformedRouteObject[route] = (req, server) => url.handleWithMini(req, server, handler);
|
|
511
511
|
}
|
|
512
512
|
for (const svgUrl in bundledSVGs) {
|
|
513
513
|
const resolvedSvg = bundledSVGs[svgUrl];
|
|
514
|
-
|
|
514
|
+
transformedRouteObject[svgUrl] = (req, server) => new Response(resolvedSvg.svgContent, resolvedSvg.options);
|
|
515
515
|
}
|
|
516
516
|
for (const frontendUrl in bundledFrontends) {
|
|
517
517
|
const resolvedFrontend = bundledFrontends[frontendUrl];
|
|
518
|
-
|
|
518
|
+
transformedRouteObject[frontendUrl] = (req, server) => new Response(resolvedFrontend.frontendContent, {
|
|
519
519
|
headers: {
|
|
520
520
|
"Content-Type": "application/javascript; charset=utf-8",
|
|
521
521
|
},
|
|
@@ -527,7 +527,7 @@ export class url {
|
|
|
527
527
|
return {
|
|
528
528
|
fetch: fetchFunction,
|
|
529
529
|
websocket: url.websocket,
|
|
530
|
-
routes:
|
|
530
|
+
routes: transformedRouteObject,
|
|
531
531
|
};
|
|
532
532
|
}
|
|
533
533
|
}
|