@spirobel/mininext 0.3.0 → 0.3.1
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/html.d.ts +16 -1
- package/dist/html.js +32 -0
- package/dist/mininext.d.ts +3 -3
- package/dist/mininext.js +2 -2
- package/mininext/html.ts +44 -1
- package/mininext/mininext.ts +11 -1
- package/package.json +1 -1
package/dist/html.d.ts
CHANGED
|
@@ -54,5 +54,20 @@ export declare function isError(submissionResult: any | {
|
|
|
54
54
|
error: HtmlString;
|
|
55
55
|
};
|
|
56
56
|
declare global {
|
|
57
|
-
var Reloader: HtmlString | undefined;
|
|
57
|
+
var Reloader: BasedHtml | HtmlString | undefined;
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The difference between this and HtmlString is that it is fully resolved and only accepts primitive types.
|
|
61
|
+
* In plain english this means:
|
|
62
|
+
* It does not accept functions (that will be resolved at request time with (mini)=>mini.html) like mini.html does.
|
|
63
|
+
*/
|
|
64
|
+
export declare class BasedHtml extends String {
|
|
65
|
+
}
|
|
66
|
+
export type BasedHtmlValues = number | string | undefined | null | boolean | BasedHtml | BasedHtml[];
|
|
67
|
+
/**
|
|
68
|
+
* The difference between this and HtmlString is that it is fully resolved and only accepts primitive types.
|
|
69
|
+
* @param strings - html literals
|
|
70
|
+
* @param values - values will get escaped to prevent xss
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
export declare const basedHtml: (strings: TemplateStringsArray, ...values: BasedHtmlValues[]) => BasedHtml;
|
package/dist/html.js
CHANGED
|
@@ -245,3 +245,35 @@ export async function htmlResponder(mini, maybeUnresolved, head = default_head,
|
|
|
245
245
|
export function isError(submissionResult) {
|
|
246
246
|
return ("error" in submissionResult && submissionResult.error instanceof HtmlString);
|
|
247
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* The difference between this and HtmlString is that it is fully resolved and only accepts primitive types.
|
|
250
|
+
* In plain english this means:
|
|
251
|
+
* It does not accept functions (that will be resolved at request time with (mini)=>mini.html) like mini.html does.
|
|
252
|
+
*/
|
|
253
|
+
export class BasedHtml extends String {
|
|
254
|
+
}
|
|
255
|
+
//TODO make it so we can embed BasedHtml into mini.html partially resolved html strings
|
|
256
|
+
/**
|
|
257
|
+
* The difference between this and HtmlString is that it is fully resolved and only accepts primitive types.
|
|
258
|
+
* @param strings - html literals
|
|
259
|
+
* @param values - values will get escaped to prevent xss
|
|
260
|
+
* @returns
|
|
261
|
+
*/
|
|
262
|
+
export const basedHtml = (strings, ...values) => {
|
|
263
|
+
// Apply escapeHtml to each value before using them in the template string
|
|
264
|
+
// In case it didn't already get escaped
|
|
265
|
+
for (const [index, value] of values.entries()) {
|
|
266
|
+
// we can pass arrays of BasedHtml and they will get flattened automatically
|
|
267
|
+
if (Array.isArray(value) &&
|
|
268
|
+
value.every((val) => val instanceof BasedHtml)) {
|
|
269
|
+
// If the value is an array of BasedHtml objects, flatten it and add to ...values
|
|
270
|
+
values[index] = value.join("");
|
|
271
|
+
}
|
|
272
|
+
else if (!(value instanceof BasedHtml)) {
|
|
273
|
+
const notEmpty = value || "";
|
|
274
|
+
// values will be escaped by default
|
|
275
|
+
values[index] = Bun.escapeHTML(notEmpty + "");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return new BasedHtml(String.raw({ raw: strings }, ...values));
|
|
279
|
+
};
|
package/dist/mininext.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/// <reference types="bun-types" />
|
|
2
2
|
/// <reference types="bun-types" />
|
|
3
3
|
import { url, Mini, type HtmlHandler } from "./url";
|
|
4
|
-
import { isError, HtmlString, head, commonHead, cssReset } from "./html";
|
|
4
|
+
import { isError, HtmlString, BasedHtml, head, commonHead, cssReset, basedHtml as html } from "./html";
|
|
5
5
|
import type { Server, WebSocketHandler } from "bun";
|
|
6
6
|
declare global {
|
|
7
7
|
var PROJECT_ROOT: string | undefined;
|
|
8
8
|
}
|
|
9
9
|
declare function build(backendPath?: string): Promise<void>;
|
|
10
|
-
declare const standardDevReloader:
|
|
10
|
+
declare const standardDevReloader: BasedHtml;
|
|
11
11
|
declare function makeEntrypoint(): Promise<{
|
|
12
12
|
fetch: (req: Request, server: Server) => Promise<Response>;
|
|
13
13
|
websocket: WebSocketHandler;
|
|
14
14
|
}>;
|
|
15
|
-
export { url, head, build, makeEntrypoint, isError, HtmlString, type HtmlHandler, Mini, standardDevReloader, commonHead, cssReset, };
|
|
15
|
+
export { html, url, head, build, makeEntrypoint, isError, BasedHtml, HtmlString, type HtmlHandler, Mini, standardDevReloader, commonHead, cssReset, };
|
package/dist/mininext.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { url, Mini } from "./url";
|
|
2
|
-
import {
|
|
2
|
+
import { isError, HtmlString, BasedHtml, head, commonHead, cssReset, basedHtml as html, } from "./html";
|
|
3
3
|
import { watch } from "fs/promises";
|
|
4
4
|
import * as path from "path";
|
|
5
5
|
function projectRoot() {
|
|
@@ -158,4 +158,4 @@ async function makeEntrypoint() {
|
|
|
158
158
|
}
|
|
159
159
|
return module.default();
|
|
160
160
|
}
|
|
161
|
-
export { url, head, build, makeEntrypoint, isError, HtmlString, Mini, standardDevReloader, commonHead, cssReset, };
|
|
161
|
+
export { html, url, head, build, makeEntrypoint, isError, BasedHtml, HtmlString, Mini, standardDevReloader, commonHead, cssReset, };
|
package/mininext/html.ts
CHANGED
|
@@ -295,5 +295,48 @@ export function isError(
|
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
declare global {
|
|
298
|
-
var Reloader: HtmlString | undefined;
|
|
298
|
+
var Reloader: BasedHtml | HtmlString | undefined;
|
|
299
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* The difference between this and HtmlString is that it is fully resolved and only accepts primitive types.
|
|
302
|
+
* In plain english this means:
|
|
303
|
+
* It does not accept functions (that will be resolved at request time with (mini)=>mini.html) like mini.html does.
|
|
304
|
+
*/
|
|
305
|
+
export class BasedHtml extends String {}
|
|
306
|
+
export type BasedHtmlValues =
|
|
307
|
+
| number
|
|
308
|
+
| string
|
|
309
|
+
| undefined
|
|
310
|
+
| null
|
|
311
|
+
| boolean
|
|
312
|
+
| BasedHtml
|
|
313
|
+
| BasedHtml[];
|
|
314
|
+
//TODO make it so we can embed BasedHtml into mini.html partially resolved html strings
|
|
315
|
+
/**
|
|
316
|
+
* The difference between this and HtmlString is that it is fully resolved and only accepts primitive types.
|
|
317
|
+
* @param strings - html literals
|
|
318
|
+
* @param values - values will get escaped to prevent xss
|
|
319
|
+
* @returns
|
|
320
|
+
*/
|
|
321
|
+
export const basedHtml = (
|
|
322
|
+
strings: TemplateStringsArray,
|
|
323
|
+
...values: BasedHtmlValues[]
|
|
324
|
+
) => {
|
|
325
|
+
// Apply escapeHtml to each value before using them in the template string
|
|
326
|
+
// In case it didn't already get escaped
|
|
327
|
+
for (const [index, value] of values.entries()) {
|
|
328
|
+
// we can pass arrays of BasedHtml and they will get flattened automatically
|
|
329
|
+
if (
|
|
330
|
+
Array.isArray(value) &&
|
|
331
|
+
value.every((val) => val instanceof BasedHtml)
|
|
332
|
+
) {
|
|
333
|
+
// If the value is an array of BasedHtml objects, flatten it and add to ...values
|
|
334
|
+
values[index] = value.join("");
|
|
335
|
+
} else if (!(value instanceof BasedHtml)) {
|
|
336
|
+
const notEmpty = value || "";
|
|
337
|
+
// values will be escaped by default
|
|
338
|
+
values[index] = Bun.escapeHTML(notEmpty + "");
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return new BasedHtml(String.raw({ raw: strings }, ...values));
|
|
342
|
+
};
|
package/mininext/mininext.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { url, Mini, type HtmlHandler } from "./url";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isError,
|
|
4
|
+
HtmlString,
|
|
5
|
+
BasedHtml,
|
|
6
|
+
head,
|
|
7
|
+
commonHead,
|
|
8
|
+
cssReset,
|
|
9
|
+
basedHtml as html,
|
|
10
|
+
} from "./html";
|
|
3
11
|
import type { BunPlugin, Server, WebSocketHandler } from "bun";
|
|
4
12
|
import { watch } from "fs/promises";
|
|
5
13
|
import * as path from "path";
|
|
@@ -174,11 +182,13 @@ async function makeEntrypoint() {
|
|
|
174
182
|
};
|
|
175
183
|
}
|
|
176
184
|
export {
|
|
185
|
+
html,
|
|
177
186
|
url,
|
|
178
187
|
head,
|
|
179
188
|
build,
|
|
180
189
|
makeEntrypoint,
|
|
181
190
|
isError,
|
|
191
|
+
BasedHtml,
|
|
182
192
|
HtmlString,
|
|
183
193
|
type HtmlHandler,
|
|
184
194
|
Mini,
|