@spirobel/mininext 0.2.27 → 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/mininext.d.ts +7 -1
- package/dist/mininext.js +1 -1
- package/dist/url.d.ts +15 -2
- package/dist/url.js +32 -18
- package/mininext/mininext.ts +5 -2
- package/mininext/url.ts +31 -16
- package/package.json +1 -1
package/dist/mininext.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
/// <reference types="bun-types" />
|
|
2
|
+
/// <reference types="bun-types" />
|
|
1
3
|
import { url, Mini, type HtmlHandler } from "./url";
|
|
2
4
|
import { isError, HtmlString, head, commonHead, cssReset } from "./html";
|
|
5
|
+
import type { Server, WebSocketHandler } from "bun";
|
|
3
6
|
declare global {
|
|
4
7
|
var PROJECT_ROOT: string | undefined;
|
|
5
8
|
}
|
|
6
9
|
declare function build(backendPath?: string): Promise<void>;
|
|
7
10
|
declare const standardDevReloader: HtmlString;
|
|
8
|
-
declare function makeEntrypoint(): Promise<
|
|
11
|
+
declare function makeEntrypoint(): Promise<{
|
|
12
|
+
fetch: (req: Request, server: Server) => Promise<Response>;
|
|
13
|
+
websocket: WebSocketHandler;
|
|
14
|
+
}>;
|
|
9
15
|
export { url, head, build, makeEntrypoint, isError, HtmlString, type HtmlHandler, Mini, standardDevReloader, commonHead, cssReset, };
|
package/dist/mininext.js
CHANGED
|
@@ -156,6 +156,6 @@ async function makeEntrypoint() {
|
|
|
156
156
|
// @ts-ignore
|
|
157
157
|
module = await import(backendImportPath);
|
|
158
158
|
}
|
|
159
|
-
return module.default;
|
|
159
|
+
return module.default();
|
|
160
160
|
}
|
|
161
161
|
export { url, head, build, makeEntrypoint, isError, HtmlString, Mini, standardDevReloader, commonHead, cssReset, };
|
package/dist/url.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/// <reference types="bun-types" />
|
|
2
|
+
/// <reference types="bun-types" />
|
|
3
|
+
import type { Server, WebSocketHandler } from "bun";
|
|
1
4
|
import { html, json, dangerjson, HtmlString } from "./html";
|
|
2
5
|
import type { DangerJsonInHtml, JsonString, JsonStringValues } from "./html";
|
|
3
6
|
export type Form = {
|
|
@@ -68,6 +71,8 @@ interface LinkSettings {
|
|
|
68
71
|
[key: string]: string | null | undefined;
|
|
69
72
|
}
|
|
70
73
|
export declare class url {
|
|
74
|
+
static websocket: WebSocketHandler | undefined;
|
|
75
|
+
static server: Server;
|
|
71
76
|
static direct_handlers_html: ReadonlyMap<string, HtmlHandler>;
|
|
72
77
|
private static frontends;
|
|
73
78
|
private static svgs;
|
|
@@ -146,7 +151,7 @@ export declare class url {
|
|
|
146
151
|
* @param handler - normal html handler with mini as the argument
|
|
147
152
|
* @returns a wrapped html handler that will only be called when the request is post
|
|
148
153
|
*/
|
|
149
|
-
static post
|
|
154
|
+
static post(handler: HtmlHandler): (mini: Mini) => LazyHandlerReturnType;
|
|
150
155
|
/**
|
|
151
156
|
* wrap your handlers in this if you mutate something to prevent CSRF issues.
|
|
152
157
|
* @param handler - normal html handler with mini as the argument
|
|
@@ -183,11 +188,19 @@ export declare class url {
|
|
|
183
188
|
*/
|
|
184
189
|
static get(Url: string): string;
|
|
185
190
|
static match(req: Request, reqPath?: string): Promise<Response | undefined>;
|
|
191
|
+
/**
|
|
192
|
+
* user this to set the Websocket object. Check out [the bun docs](https://bun.sh/docs/api/websockets) for more details.
|
|
193
|
+
* @param wsObject the websocketsocket object {@link WebSocketHandler}
|
|
194
|
+
*/
|
|
195
|
+
static setWebsocket<T = undefined>(wsObject: WebSocketHandler<T>): void;
|
|
186
196
|
/**
|
|
187
197
|
* Fetch handler that is called by the server when a request is made to any of the urls.
|
|
188
198
|
* @param {Request} req - The Request object.
|
|
189
199
|
* @return {Promise<Response>} - The Response object.
|
|
190
200
|
*/
|
|
191
|
-
static install(
|
|
201
|
+
static install(): {
|
|
202
|
+
fetch: (req: Request, server: Server) => Promise<Response>;
|
|
203
|
+
websocket: WebSocketHandler<undefined> | undefined;
|
|
204
|
+
};
|
|
192
205
|
}
|
|
193
206
|
export {};
|
package/dist/url.js
CHANGED
|
@@ -47,6 +47,8 @@ export class Mini {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
export class url {
|
|
50
|
+
static websocket = undefined;
|
|
51
|
+
static server;
|
|
50
52
|
// direct mapping of "url string" -> function leads to Html Response
|
|
51
53
|
static direct_handlers_html;
|
|
52
54
|
// An array of the uncompiled frontend files, example frontends[0] = "index.tsx" -> frontend/index.tsx (from the project root)
|
|
@@ -386,29 +388,41 @@ export class url {
|
|
|
386
388
|
return htmlResponder(mini, unresolved, handlerHead, handlerOptions);
|
|
387
389
|
}
|
|
388
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* user this to set the Websocket object. Check out [the bun docs](https://bun.sh/docs/api/websockets) for more details.
|
|
393
|
+
* @param wsObject the websocketsocket object {@link WebSocketHandler}
|
|
394
|
+
*/
|
|
395
|
+
static setWebsocket(wsObject) {
|
|
396
|
+
url.websocket = wsObject;
|
|
397
|
+
}
|
|
389
398
|
/**
|
|
390
399
|
* Fetch handler that is called by the server when a request is made to any of the urls.
|
|
391
400
|
* @param {Request} req - The Request object.
|
|
392
401
|
* @return {Promise<Response>} - The Response object.
|
|
393
402
|
*/
|
|
394
|
-
static
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
403
|
+
static install() {
|
|
404
|
+
async function fetchFunction(req, server) {
|
|
405
|
+
if (!url.server)
|
|
406
|
+
url.server = server;
|
|
407
|
+
//go through all the Htmlhandlers and see if there is a match
|
|
408
|
+
let res = await url.match(req);
|
|
409
|
+
if (res)
|
|
410
|
+
return res;
|
|
411
|
+
//handle frontend js file serving
|
|
412
|
+
res = url.serveFrontend(req);
|
|
413
|
+
if (res)
|
|
414
|
+
return res;
|
|
415
|
+
//handle svg file serving
|
|
416
|
+
res = url.serveSvg(req);
|
|
417
|
+
if (res)
|
|
418
|
+
return res;
|
|
419
|
+
// go through all the Htmlhandlers again with added slash at the end.
|
|
420
|
+
res = await url.match(req, new URL(req.url).pathname + "/");
|
|
421
|
+
if (res)
|
|
422
|
+
return res;
|
|
423
|
+
return new Response("No matching url found", { status: 404 });
|
|
424
|
+
}
|
|
425
|
+
return { fetch: fetchFunction, websocket: url.websocket };
|
|
412
426
|
}
|
|
413
427
|
}
|
|
414
428
|
const no_post_warning = html `<div style="color:red;">
|
package/mininext/mininext.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { url, Mini, type HtmlHandler } from "./url";
|
|
2
2
|
import { html, isError, HtmlString, head, commonHead, cssReset } from "./html";
|
|
3
|
+
import type { BunPlugin, Server, WebSocketHandler } from "bun";
|
|
3
4
|
import { watch } from "fs/promises";
|
|
4
5
|
import * as path from "path";
|
|
5
6
|
function projectRoot() {
|
|
@@ -14,7 +15,6 @@ async function build(backendPath: string = "backend/backend.ts") {
|
|
|
14
15
|
await devServer();
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
import type { BunPlugin } from "bun";
|
|
18
18
|
|
|
19
19
|
const myPlugin: BunPlugin = {
|
|
20
20
|
name: "node buffer in the frontend",
|
|
@@ -168,7 +168,10 @@ async function makeEntrypoint() {
|
|
|
168
168
|
// @ts-ignore
|
|
169
169
|
module = await import(backendImportPath);
|
|
170
170
|
}
|
|
171
|
-
return module.default
|
|
171
|
+
return module.default() as {
|
|
172
|
+
fetch: (req: Request, server: Server) => Promise<Response>;
|
|
173
|
+
websocket: WebSocketHandler;
|
|
174
|
+
};
|
|
172
175
|
}
|
|
173
176
|
export {
|
|
174
177
|
url,
|
package/mininext/url.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Server, WebSocketHandler } from "bun";
|
|
1
2
|
import { htmlResponder, html, json, dangerjson, HtmlString } from "./html";
|
|
2
3
|
import type { DangerJsonInHtml, JsonString, JsonStringValues } from "./html";
|
|
3
4
|
export type Form = {
|
|
@@ -116,6 +117,9 @@ interface LinkSettings {
|
|
|
116
117
|
[key: string]: string | null | undefined;
|
|
117
118
|
}
|
|
118
119
|
export class url {
|
|
120
|
+
static websocket: WebSocketHandler | undefined = undefined;
|
|
121
|
+
static server: Server;
|
|
122
|
+
|
|
119
123
|
// direct mapping of "url string" -> function leads to Html Response
|
|
120
124
|
static direct_handlers_html: ReadonlyMap<string, HtmlHandler>;
|
|
121
125
|
|
|
@@ -272,8 +276,8 @@ export class url {
|
|
|
272
276
|
* @param handler - normal html handler with mini as the argument
|
|
273
277
|
* @returns a wrapped html handler that will only be called when the request is post
|
|
274
278
|
*/
|
|
275
|
-
static post
|
|
276
|
-
return (mini: Mini
|
|
279
|
+
static post(handler: HtmlHandler) {
|
|
280
|
+
return (mini: Mini) => {
|
|
277
281
|
if (mini.form.post) {
|
|
278
282
|
return handler(mini);
|
|
279
283
|
} else {
|
|
@@ -486,28 +490,39 @@ export class url {
|
|
|
486
490
|
return htmlResponder(mini, unresolved, handlerHead, handlerOptions);
|
|
487
491
|
}
|
|
488
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* user this to set the Websocket object. Check out [the bun docs](https://bun.sh/docs/api/websockets) for more details.
|
|
495
|
+
* @param wsObject the websocketsocket object {@link WebSocketHandler}
|
|
496
|
+
*/
|
|
497
|
+
static setWebsocket<T = undefined>(wsObject: WebSocketHandler<T>) {
|
|
498
|
+
url.websocket = wsObject as WebSocketHandler;
|
|
499
|
+
}
|
|
489
500
|
|
|
490
501
|
/**
|
|
491
502
|
* Fetch handler that is called by the server when a request is made to any of the urls.
|
|
492
503
|
* @param {Request} req - The Request object.
|
|
493
504
|
* @return {Promise<Response>} - The Response object.
|
|
494
505
|
*/
|
|
495
|
-
static
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
506
|
+
static install() {
|
|
507
|
+
async function fetchFunction(req: Request, server: Server) {
|
|
508
|
+
if (!url.server) url.server = server;
|
|
509
|
+
//go through all the Htmlhandlers and see if there is a match
|
|
510
|
+
let res = await url.match(req);
|
|
511
|
+
if (res) return res;
|
|
499
512
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
513
|
+
//handle frontend js file serving
|
|
514
|
+
res = url.serveFrontend(req);
|
|
515
|
+
if (res) return res;
|
|
516
|
+
//handle svg file serving
|
|
517
|
+
res = url.serveSvg(req);
|
|
518
|
+
if (res) return res;
|
|
519
|
+
// go through all the Htmlhandlers again with added slash at the end.
|
|
520
|
+
res = await url.match(req, new URL(req.url).pathname + "/");
|
|
521
|
+
if (res) return res;
|
|
509
522
|
|
|
510
|
-
|
|
523
|
+
return new Response("No matching url found", { status: 404 });
|
|
524
|
+
}
|
|
525
|
+
return { fetch: fetchFunction, websocket: url.websocket };
|
|
511
526
|
}
|
|
512
527
|
}
|
|
513
528
|
|