@spirobel/mininext 0.2.13 → 0.2.15

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/README.md CHANGED
@@ -20,6 +20,12 @@ quickstart:
20
20
  bun create spirobel/gucci yournewproject
21
21
  ```
22
22
 
23
+ barebones quickstart:
24
+
25
+ ```bash
26
+ bun create spirobel/aldi yournewproject
27
+ ```
28
+
23
29
  if you don't have bun installed, run first:
24
30
 
25
31
  ```bash
package/dist/html.js CHANGED
@@ -13,6 +13,16 @@ export class HtmlString extends Array {
13
13
  if (resolvedHtmlPiece instanceof HtmlString) {
14
14
  resolvedHtmlPiece = await resolvedHtmlPiece.resolve(mini);
15
15
  }
16
+ else {
17
+ if (this instanceof JsonString) {
18
+ resolvedHtmlPiece = JSON.stringify(resolvedHtmlPiece);
19
+ }
20
+ else {
21
+ const notEmpty = resolvedHtmlPiece || "";
22
+ // values will be escaped by default
23
+ resolvedHtmlPiece = Bun.escapeHTML(notEmpty + "");
24
+ }
25
+ }
16
26
  // Replace the function with the resolved HTML piece in place
17
27
  this[index] = resolvedHtmlPiece;
18
28
  }
@@ -40,6 +50,7 @@ export function html(strings, ...values) {
40
50
  value.every((val) => val instanceof HtmlString)) {
41
51
  // If the value is an array of HtmlString objects, add the whole array as a single value
42
52
  values[index] = value;
53
+ htmlStringArray.resolved = false; // we could bother with .find here
43
54
  }
44
55
  else if (typeof value === "function") {
45
56
  htmlStringArray.resolved = false;
@@ -57,6 +68,11 @@ export function html(strings, ...values) {
57
68
  // values will be escaped by default
58
69
  values[index] = Bun.escapeHTML(notEmpty + "");
59
70
  }
71
+ else if (value instanceof HtmlString) {
72
+ if (!value.resolved) {
73
+ htmlStringArray.resolved = false;
74
+ }
75
+ }
60
76
  htmlStringArray.push(values[index]);
61
77
  }
62
78
  }
@@ -84,6 +100,7 @@ function JsonTemplateProcessor(danger = false) {
84
100
  value.every((val) => val instanceof HtmlString)) {
85
101
  // If the value is an array of HtmlString objects, add the whole array as a single value
86
102
  values[index] = value;
103
+ jsonStringArray.resolved = false; // we could bother with .find here
87
104
  }
88
105
  else if (typeof value === "function") {
89
106
  jsonStringArray.resolved = false;
@@ -94,6 +111,11 @@ function JsonTemplateProcessor(danger = false) {
94
111
  // values will be turned into a JSON string
95
112
  values[index] = JSON.stringify(notEmpty);
96
113
  }
114
+ else if (value instanceof HtmlString) {
115
+ if (!value.resolved) {
116
+ jsonStringArray.resolved = false;
117
+ }
118
+ }
97
119
  jsonStringArray.push(values[index]);
98
120
  }
99
121
  }
package/dist/url.d.ts CHANGED
@@ -41,6 +41,7 @@ export declare class Mini<X = undefined> {
41
41
  route: string;
42
42
  params: URLSearchParams;
43
43
  form: Form;
44
+ requrl: Readonly<URL>;
44
45
  constructor(mini: Mini<undefined | any>, data: X);
45
46
  }
46
47
  /**
package/dist/url.js CHANGED
@@ -20,6 +20,7 @@ export class Mini {
20
20
  route;
21
21
  params;
22
22
  form;
23
+ requrl;
23
24
  constructor(mini, data) {
24
25
  Object.assign(this, mini);
25
26
  this.html = (html);
@@ -307,8 +308,9 @@ export class url {
307
308
  return Url;
308
309
  }
309
310
  static async match(req, reqPath) {
311
+ const miniurl = Object.freeze(new URL(req.url));
310
312
  if (typeof reqPath === "undefined") {
311
- reqPath = new URL(req.url).pathname;
313
+ reqPath = miniurl.pathname;
312
314
  }
313
315
  const handler = url.direct_handlers_html.get(reqPath);
314
316
  if (handler) {
@@ -331,6 +333,7 @@ export class url {
331
333
  formData = await req.formData();
332
334
  }
333
335
  const mini = new Mini({
336
+ requrl: miniurl,
334
337
  data: undefined,
335
338
  req,
336
339
  html,
package/mininext/html.ts CHANGED
@@ -30,6 +30,14 @@ export class HtmlString extends Array {
30
30
  let resolvedHtmlPiece = await htmlPiece(mini); //passing mini
31
31
  if (resolvedHtmlPiece instanceof HtmlString) {
32
32
  resolvedHtmlPiece = await resolvedHtmlPiece.resolve(mini);
33
+ } else {
34
+ if (this instanceof JsonString) {
35
+ resolvedHtmlPiece = JSON.stringify(resolvedHtmlPiece);
36
+ } else {
37
+ const notEmpty = resolvedHtmlPiece || "";
38
+ // values will be escaped by default
39
+ resolvedHtmlPiece = Bun.escapeHTML(notEmpty + "");
40
+ }
33
41
  }
34
42
  // Replace the function with the resolved HTML piece in place
35
43
  this[index] = resolvedHtmlPiece;
@@ -67,6 +75,7 @@ export function html<X = undefined>(
67
75
  ) {
68
76
  // If the value is an array of HtmlString objects, add the whole array as a single value
69
77
  values[index] = value;
78
+ htmlStringArray.resolved = false; // we could bother with .find here
70
79
  } else if (typeof value === "function") {
71
80
  htmlStringArray.resolved = false;
72
81
  values[index] = value;
@@ -80,6 +89,10 @@ export function html<X = undefined>(
80
89
  const notEmpty = value || "";
81
90
  // values will be escaped by default
82
91
  values[index] = Bun.escapeHTML(notEmpty + "");
92
+ } else if (value instanceof HtmlString) {
93
+ if (!value.resolved) {
94
+ htmlStringArray.resolved = false;
95
+ }
83
96
  }
84
97
  htmlStringArray.push(values[index]);
85
98
  }
@@ -128,6 +141,7 @@ function JsonTemplateProcessor(danger: boolean = false) {
128
141
  ) {
129
142
  // If the value is an array of HtmlString objects, add the whole array as a single value
130
143
  values[index] = value;
144
+ jsonStringArray.resolved = false; // we could bother with .find here
131
145
  } else if (typeof value === "function") {
132
146
  jsonStringArray.resolved = false;
133
147
  values[index] = value;
@@ -135,6 +149,10 @@ function JsonTemplateProcessor(danger: boolean = false) {
135
149
  const notEmpty = value || "";
136
150
  // values will be turned into a JSON string
137
151
  values[index] = JSON.stringify(notEmpty);
152
+ } else if (value instanceof HtmlString) {
153
+ if (!value.resolved) {
154
+ jsonStringArray.resolved = false;
155
+ }
138
156
  }
139
157
  jsonStringArray.push(values[index]);
140
158
  }
package/mininext/url.ts CHANGED
@@ -61,6 +61,7 @@ export class Mini<X = undefined> {
61
61
  route!: string;
62
62
  params!: URLSearchParams;
63
63
  form!: Form;
64
+ requrl!: Readonly<URL>;
64
65
 
65
66
  constructor(mini: Mini<undefined | any>, data: X) {
66
67
  Object.assign(this, mini);
@@ -401,8 +402,9 @@ export class url {
401
402
  return Url;
402
403
  }
403
404
  static async match(req: Request, reqPath?: string) {
405
+ const miniurl: Readonly<URL> = Object.freeze(new URL(req.url));
404
406
  if (typeof reqPath === "undefined") {
405
- reqPath = new URL(req.url).pathname;
407
+ reqPath = miniurl.pathname;
406
408
  }
407
409
  const handler = url.direct_handlers_html.get(reqPath);
408
410
  if (handler) {
@@ -431,6 +433,7 @@ export class url {
431
433
 
432
434
  const mini = new Mini(
433
435
  {
436
+ requrl: miniurl,
434
437
  data: undefined,
435
438
  req,
436
439
  html,
package/package.json CHANGED
@@ -7,12 +7,11 @@
7
7
  "scripts": {
8
8
  "publish": "bun run build && npm publish",
9
9
  "build": "tsc",
10
- "postversion": "git push --follow-tags",
11
10
  "preversion": "bun run build"
12
11
 
13
12
  },
14
13
  "files": ["dist", "mininext"],
15
- "version": "0.2.13",
14
+ "version": "0.2.15",
16
15
  "devDependencies": {
17
16
  "@types/bun": "latest"
18
17
  },