ovr 3.0.0 → 4.0.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.
Files changed (62) hide show
  1. package/dist/app/context.d.ts +1 -0
  2. package/dist/app/context.d.ts.map +1 -0
  3. package/dist/app/context.js +46 -27
  4. package/dist/app/{page.d.ts → get.d.ts} +5 -6
  5. package/dist/app/get.d.ts.map +1 -0
  6. package/dist/app/{page.js → get.js} +4 -6
  7. package/dist/app/index.d.ts +5 -4
  8. package/dist/app/index.d.ts.map +1 -0
  9. package/dist/app/index.js +7 -7
  10. package/dist/app/memo/index.d.ts +1 -0
  11. package/dist/app/memo/index.d.ts.map +1 -0
  12. package/dist/app/mw/csrf.d.ts +1 -0
  13. package/dist/app/mw/csrf.d.ts.map +1 -0
  14. package/dist/app/{action.d.ts → post.d.ts} +8 -9
  15. package/dist/app/post.d.ts.map +1 -0
  16. package/dist/app/{action.js → post.js} +1 -1
  17. package/dist/index.d.ts +3 -2
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +2 -2
  20. package/dist/jsx/chunk/index.d.ts +14 -11
  21. package/dist/jsx/chunk/index.d.ts.map +1 -0
  22. package/dist/jsx/chunk/index.js +26 -28
  23. package/dist/jsx/index.d.ts +13 -9
  24. package/dist/jsx/index.d.ts.map +1 -0
  25. package/dist/jsx/index.js +57 -36
  26. package/dist/jsx/{elements.d.ts → intrinsic-elements.d.ts} +2 -1
  27. package/dist/jsx/intrinsic-elements.d.ts.map +1 -0
  28. package/dist/jsx/{merge-async-iterables.d.ts → merge-async-generators.d.ts} +2 -4
  29. package/dist/jsx/merge-async-generators.d.ts.map +1 -0
  30. package/dist/jsx/{merge-async-iterables.js → merge-async-generators.js} +7 -9
  31. package/dist/jsx-dev-runtime.d.ts +1 -0
  32. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  33. package/dist/jsx-runtime.d.ts +1 -0
  34. package/dist/jsx-runtime.d.ts.map +1 -0
  35. package/dist/trie/index.d.ts +1 -0
  36. package/dist/trie/index.d.ts.map +1 -0
  37. package/dist/trie/insert-params.d.ts +1 -0
  38. package/dist/trie/insert-params.d.ts.map +1 -0
  39. package/dist/types/index.d.ts +1 -0
  40. package/dist/types/index.d.ts.map +1 -0
  41. package/dist/util/hash.d.ts +10 -0
  42. package/dist/util/hash.d.ts.map +1 -0
  43. package/dist/util/hash.js +9 -2
  44. package/package.json +4 -2
  45. package/src/app/context.ts +350 -0
  46. package/src/app/get.ts +54 -0
  47. package/src/app/index.ts +302 -0
  48. package/src/app/memo/index.ts +40 -0
  49. package/src/app/mw/csrf.ts +28 -0
  50. package/src/app/post.ts +79 -0
  51. package/src/index.ts +9 -0
  52. package/src/jsx/chunk/index.ts +68 -0
  53. package/src/jsx/index.ts +247 -0
  54. package/src/jsx/intrinsic-elements.ts +812 -0
  55. package/src/jsx/merge-async-generators.ts +42 -0
  56. package/src/jsx-dev-runtime.ts +1 -0
  57. package/src/jsx-runtime.ts +1 -0
  58. package/src/trie/index.ts +335 -0
  59. package/src/trie/insert-params.ts +31 -0
  60. package/src/types/index.ts +23 -0
  61. package/src/util/hash.ts +17 -0
  62. /package/dist/jsx/{elements.js → intrinsic-elements.js} +0 -0
@@ -141,3 +141,4 @@ export declare class Context<P extends Params = Params> {
141
141
  static get(): Context<Params>;
142
142
  }
143
143
  export {};
144
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/app/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAe,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,MAAM,YAAY,CAAC;AAGpB,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE;I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,EAAE,MAAM,CAAC,EAAE,MAAM;IAO/B;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM;IAOpC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,GAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAS;IAK1E;;OAEG;IACH,IAAI,CAAC,GAAG,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;IAI9B;;OAEG;IACH,MAAM,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE;IAI1B;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM;IAgEvC;;;;;;;;OAQG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM;IAed;;OAEG;IACH,KAAK;IA+BL;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,GAAG;CAUV"}
@@ -136,38 +136,52 @@ export class Context {
136
136
  * @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
137
137
  */
138
138
  page(Page, status) {
139
- for (let i = this.#layouts.length - 1; i >= 0; i--)
139
+ for (let i = this.#layouts.length - 1; i >= 0; i--) {
140
140
  Page = this.#layouts[i]({ children: Page });
141
- const headClose = "</head>";
142
- const bodyClose = "</body>";
143
- const elements = this.base.split(headClose);
144
- if (!elements[1])
145
- throw new TagNotFound(headClose);
146
- elements.splice(1, 0, this.#headElements, headClose);
147
- const bodyParts = elements[3].split(bodyClose);
148
- if (!bodyParts[1])
149
- throw new TagNotFound(bodyClose);
150
- const userAgent = this.req.headers.get("user-agent");
151
- if (userAgent?.includes("Safari") && !userAgent.includes("Chrome")) {
152
- // https://bugs.webkit.org/show_bug.cgi?id=252413
153
- // https://github.com/sveltejs/kit/issues/10315
154
- // https://github.com/remix-run/remix/issues/5804
155
- bodyParts[0] += `<div aria-hidden=true style=position:absolute;width:0;height:0;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0>${"\u200b".repeat(200)}</div>`;
156
141
  }
157
- elements[3] = bodyParts[0];
158
- elements.push(Page, bodyClose + bodyParts[1]);
159
- const gen = toGenerator(elements.map((el) => {
160
- if (typeof el === "string")
161
- return new Chunk(el, true);
162
- return el;
163
- }));
142
+ let gen;
143
+ if (this.base) {
144
+ // inject into base
145
+ const headClose = "</head>";
146
+ const bodyClose = "</body>";
147
+ const elements = this.base.split(headClose);
148
+ if (!elements[1])
149
+ throw new TagNotFound(headClose);
150
+ elements.splice(1, 0, this.#headElements, headClose);
151
+ const bodyParts = elements[3].split(bodyClose);
152
+ if (!bodyParts[1])
153
+ throw new TagNotFound(bodyClose);
154
+ const userAgent = this.req.headers.get("user-agent");
155
+ if (userAgent?.includes("Safari") && !userAgent.includes("Chrome")) {
156
+ // https://bugs.webkit.org/show_bug.cgi?id=252413
157
+ // https://github.com/sveltejs/kit/issues/10315
158
+ // https://github.com/remix-run/remix/issues/5804
159
+ bodyParts[0] += `<div aria-hidden=true style=position:absolute;width:0;height:0;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0>${"\u200b".repeat(200)}</div>`;
160
+ }
161
+ elements[3] = bodyParts[0];
162
+ elements.push(Page, bodyClose + bodyParts[1]);
163
+ gen = toGenerator(elements.map((el) => {
164
+ if (typeof el === "string")
165
+ return new Chunk(el, true);
166
+ return el;
167
+ }));
168
+ }
169
+ else {
170
+ // HTML partial - just use the layouts + page
171
+ gen = toGenerator(Page);
172
+ }
164
173
  this.html(new ReadableStream({
165
- async pull(c) {
166
- const { value, done } = await gen.next();
167
- if (done)
174
+ pull: async (c) => {
175
+ if (this.req.signal.aborted) {
176
+ c.close();
177
+ gen.return();
178
+ return;
179
+ }
180
+ const result = await gen.next();
181
+ if (result.done)
168
182
  c.close();
169
183
  else
170
- c.enqueue(value?.value);
184
+ c.enqueue(result.value.value);
171
185
  },
172
186
  cancel() {
173
187
  gen.return();
@@ -197,6 +211,11 @@ export class Context {
197
211
  * @returns the constructed `Response`
198
212
  */
199
213
  build() {
214
+ if (this.req.signal.aborted) {
215
+ // user cancelled the request
216
+ this.body = null;
217
+ this.status = 408;
218
+ }
200
219
  if ((!this.status || this.status === 404) &&
201
220
  this.#trailingSlash !== "ignore") {
202
221
  const last = this.url.pathname.at(-1);
@@ -6,7 +6,7 @@ type AnchorProps<P extends Params> = JSX.IntrinsicElements["a"] & (keyof P exten
6
6
  } : {
7
7
  params: P;
8
8
  });
9
- export declare class Page<Pattern extends string = string> {
9
+ export declare class Get<Pattern extends string = string> {
10
10
  #private;
11
11
  /** Route pattern */
12
12
  pattern: Pattern;
@@ -21,10 +21,9 @@ export declare class Page<Pattern extends string = string> {
21
21
  * @example
22
22
  *
23
23
  * ```tsx
24
- * // page.tsx
25
- * import { Page } from "ovr";
24
+ * import { Get } from "ovr";
26
25
  *
27
- * export const page = new Page("/", () => {
26
+ * const page = new Get("/", () => {
28
27
  * return <p>Hello world</p>
29
28
  * });
30
29
  *
@@ -32,10 +31,10 @@ export declare class Page<Pattern extends string = string> {
32
31
  * return <page.Anchor>Home</page.Anchor>
33
32
  * }
34
33
  *
35
- * // app.tsx
36
- * app.add(page); registers the page
34
+ * app.add(page); register
37
35
  * ```
38
36
  */
39
37
  constructor(pattern: Pattern, ...middleware: Middleware<ExtractParams<Pattern>>[]);
40
38
  }
41
39
  export {};
40
+ //# sourceMappingURL=get.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../src/app/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAErD,KAAK,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAC9D,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAE9D,qBAAa,GAAG,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;;IAC/C,oBAAoB;IACpB,OAAO,EAAE,OAAO,CAAC;IAEjB,qBAAqB;IACrB,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IAE9B,oDAAoD;IACpD,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAIpE;;;;;;;;;;;;;;;;;;;OAmBG;gBAEF,OAAO,EAAE,OAAO,EAChB,GAAG,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE;CAWpD"}
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "../jsx/index.js";
2
2
  import { insertParams } from "../trie/insert-params.js";
3
- export class Page {
3
+ export class Get {
4
4
  /** Route pattern */
5
5
  pattern;
6
6
  /** GET middleware */
@@ -15,10 +15,9 @@ export class Page {
15
15
  * @example
16
16
  *
17
17
  * ```tsx
18
- * // page.tsx
19
- * import { Page } from "ovr";
18
+ * import { Get } from "ovr";
20
19
  *
21
- * export const page = new Page("/", () => {
20
+ * const page = new Get("/", () => {
22
21
  * return <p>Hello world</p>
23
22
  * });
24
23
  *
@@ -26,8 +25,7 @@ export class Page {
26
25
  * return <page.Anchor>Home</page.Anchor>
27
26
  * }
28
27
  *
29
- * // app.tsx
30
- * app.add(page); registers the page
28
+ * app.add(page); register
31
29
  * ```
32
30
  */
33
31
  constructor(pattern, ...middleware) {
@@ -1,7 +1,7 @@
1
1
  import type { DeepArray, ExtractMultiParams, ExtractParams } from "../types/index.js";
2
- import { Action } from "./action.js";
3
2
  import { Context } from "./context.js";
4
- import { Page } from "./page.js";
3
+ import { Get } from "./get.js";
4
+ import { Post } from "./post.js";
5
5
  import { AsyncLocalStorage } from "node:async_hooks";
6
6
  export type Params = Record<string, string>;
7
7
  export type Middleware<P extends Params = Params> = (context: Context<P>, next: () => Promise<void>) => any;
@@ -57,10 +57,10 @@ export declare class App {
57
57
  /** Stores context per request. */
58
58
  static storage: AsyncLocalStorage<Context<Params>>;
59
59
  /**
60
- * @param routes `Page`s or `Action`s to add to the `App`
60
+ * @param routes `Get` or `Post` to add to `App`
61
61
  * @returns `App` instance
62
62
  */
63
- add(...routes: DeepArray<Page | Action | Record<string, Page | Action>>[]): this;
63
+ add(...routes: DeepArray<Get | Post | Record<string, Get | Post>>[]): this;
64
64
  /**
65
65
  * Add global middleware.
66
66
  *
@@ -113,3 +113,4 @@ export declare class App {
113
113
  fetch: (req: Request) => Promise<Response>;
114
114
  }
115
115
  export {};
116
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,SAAS,EACT,kBAAkB,EAClB,aAAa,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,CACnD,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,MAAM,OAAO,CAAC,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;IACH,KAAK,GAAI,KAAK,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CA8DvC;CACF"}
package/dist/app/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { Trie, Route } from "../trie/index.js";
2
- import { Action } from "./action.js";
1
+ import { Route, Trie } from "../trie/index.js";
3
2
  import { Context } from "./context.js";
4
- import { Page } from "./page.js";
3
+ import { Get } from "./get.js";
4
+ import { Post } from "./post.js";
5
5
  import { AsyncLocalStorage } from "node:async_hooks";
6
6
  export class App {
7
7
  /** Built tries per HTTP method. */
@@ -54,7 +54,7 @@ export class App {
54
54
  /** Stores context per request. */
55
55
  static storage = new AsyncLocalStorage();
56
56
  /**
57
- * @param routes `Page`s or `Action`s to add to the `App`
57
+ * @param routes `Get` or `Post` to add to `App`
58
58
  * @returns `App` instance
59
59
  */
60
60
  add(...routes) {
@@ -62,10 +62,10 @@ export class App {
62
62
  if (route instanceof Array) {
63
63
  this.add(...route);
64
64
  }
65
- else if (route instanceof Page) {
65
+ else if (route instanceof Get) {
66
66
  this.get(route.pattern, ...route.middleware);
67
67
  }
68
- else if (route instanceof Action) {
68
+ else if (route instanceof Post) {
69
69
  this.post(route.pattern, ...route.middleware);
70
70
  }
71
71
  else {
@@ -148,7 +148,7 @@ export class App {
148
148
  c.res(result.body, result);
149
149
  else if (result instanceof ReadableStream)
150
150
  c.body = result;
151
- else if (result)
151
+ else if (result != null)
152
152
  c.page(result);
153
153
  }
154
154
  };
@@ -9,3 +9,4 @@ export declare class Memo {
9
9
  */
10
10
  use: <A extends any[], R>(fn: (...args: A) => R) => (...args: A) => R;
11
11
  }
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/memo/index.ts"],"names":[],"mappings":"AAAA,qBAAa,IAAI;;IAOhB;;;;;;OAMG;IACH,GAAG,GAAI,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,eAAP,CAAC,KAAK,CAAC,CAwB9C;CACF"}
@@ -16,3 +16,4 @@ import type { Middleware } from "../index.js";
16
16
  export declare const csrf: (options: {
17
17
  origin: string | string[];
18
18
  }) => Middleware;
19
+ //# sourceMappingURL=csrf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csrf.d.ts","sourceRoot":"","sources":["../../../src/app/mw/csrf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,IAAI,GAAI,SAAS;IAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,KAAG,UAW7D,CAAC"}
@@ -6,7 +6,7 @@ type FormProps<P extends Params> = JSX.IntrinsicElements["form"] & (keyof P exte
6
6
  } : {
7
7
  params: P;
8
8
  });
9
- export declare class Action<Pattern extends string = string> {
9
+ export declare class Post<Pattern extends string = string> {
10
10
  #private;
11
11
  /** Route pattern */
12
12
  pattern: Pattern;
@@ -20,23 +20,21 @@ export declare class Action<Pattern extends string = string> {
20
20
  * @example
21
21
  *
22
22
  * ```tsx
23
- * // action.tsx
24
- * import { Action } from "ovr";
23
+ * import { Post } from "ovr";
25
24
  *
26
- * export const action = new Action((c) => {
25
+ * const post = new Post((c) => {
27
26
  * console.log("posted");
28
27
  * c.redirect("/", 303);
29
28
  * });
30
29
  *
31
- * export const page = new Page("/", () => (
32
- * <action.Form>
30
+ * const page = new Get("/", () => (
31
+ * <post.Form>
33
32
  * <input />
34
33
  * <button>Submit</button>
35
- * </action.Form>
34
+ * </post.Form>
36
35
  * ));
37
36
  *
38
- * // app.tsx
39
- * app.add(page, action); registers the action
37
+ * app.add(page, post); register
40
38
  * ```
41
39
  */
42
40
  constructor(...middleware: Middleware<{}>[]);
@@ -47,3 +45,4 @@ export declare class Action<Pattern extends string = string> {
47
45
  constructor(pattern: Pattern, ...middleware: Middleware<ExtractParams<Pattern>>[]);
48
46
  }
49
47
  export {};
48
+ //# sourceMappingURL=post.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../src/app/post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAErD,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAC/D,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAE9D,qBAAa,IAAI,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;;IAChD,oBAAoB;IACpB,OAAO,EAAE,OAAO,CAAC;IAEjB,sBAAsB;IACtB,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IAE9B,uEAAuE;IACvE,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAIhE;;;;;;;;;;;;;;;;;;;;;;OAsBG;gBACS,GAAG,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC,EAAE;IAC3C;;;OAGG;gBAEF,OAAO,EAAE,OAAO,EAChB,GAAG,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE;CA2BpD"}
@@ -1,7 +1,7 @@
1
1
  import { jsx } from "../jsx/index.js";
2
2
  import { insertParams } from "../trie/insert-params.js";
3
3
  import { hash } from "../util/hash.js";
4
- export class Action {
4
+ export class Post {
5
5
  /** Route pattern */
6
6
  pattern;
7
7
  /** POST middleware */
package/dist/index.d.ts CHANGED
@@ -3,7 +3,8 @@ export { Chunk } from "./jsx/chunk/index.js";
3
3
  export { Trie, Route } from "./trie/index.js";
4
4
  export { App, type Middleware, type Params } from "./app/index.js";
5
5
  export { Context } from "./app/context.js";
6
- export { Page } from "./app/page.js";
7
- export { Action } from "./app/action.js";
6
+ export { Get } from "./app/get.js";
7
+ export { Post } from "./app/post.js";
8
8
  export { csrf } from "./app/mw/csrf.js";
9
9
  export type * from "./types/index.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,mBAAmB,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -3,6 +3,6 @@ export { Chunk } from "./jsx/chunk/index.js";
3
3
  export { Trie, Route } from "./trie/index.js";
4
4
  export { App } from "./app/index.js";
5
5
  export { Context } from "./app/context.js";
6
- export { Page } from "./app/page.js";
7
- export { Action } from "./app/action.js";
6
+ export { Get } from "./app/get.js";
7
+ export { Post } from "./app/post.js";
8
8
  export { csrf } from "./app/mw/csrf.js";
@@ -1,20 +1,14 @@
1
1
  export declare class Chunk {
2
2
  #private;
3
- /**
4
- * Escapes strings of HTML.
5
- *
6
- * @param str String to escape
7
- * @param attr Set to `true` if the value is an attribute, otherwise it's a string of HTML content
8
- * @returns Escaped string of HTML
9
- */
10
- static escape(str: string, attr?: boolean): string;
11
- /** Safe value to render. */
3
+ /** Safe value to render */
12
4
  value: string;
13
5
  /**
14
- * @param html converted to a string
6
+ * `Chunk` to send in an HTML stream.
7
+ *
8
+ * @param s string of HTML to escape
15
9
  * @param safe Set to `true` if the HTML is safe and should not be escaped
16
10
  */
17
- constructor(html: unknown, safe?: boolean);
11
+ constructor(s: unknown, safe?: boolean);
18
12
  /**
19
13
  * @returns `value`
20
14
  */
@@ -23,4 +17,13 @@ export declare class Chunk {
23
17
  * @param chunks Chunks to append to the end of the chunk
24
18
  */
25
19
  concat(...chunks: Chunk[]): void;
20
+ /**
21
+ * Escapes strings of HTML.
22
+ *
23
+ * @param s String to escape
24
+ * @param attr Set to `true` if the value is an attribute, otherwise it's a string of HTML content
25
+ * @returns Escaped string of HTML
26
+ */
27
+ static escape(s: string, attr?: boolean): string;
26
28
  }
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jsx/chunk/index.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;;IAIjB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;gBACS,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO;IAKtC;;OAEG;IACH,QAAQ;IAIR;;OAEG;IACH,MAAM,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE;IAIzB;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CA4BvC"}
@@ -1,16 +1,39 @@
1
1
  export class Chunk {
2
2
  static #attr = /[&"<]/g;
3
3
  static #content = /[&<]/g;
4
+ /** Safe value to render */
5
+ value;
6
+ /**
7
+ * `Chunk` to send in an HTML stream.
8
+ *
9
+ * @param s string of HTML to escape
10
+ * @param safe Set to `true` if the HTML is safe and should not be escaped
11
+ */
12
+ constructor(s, safe) {
13
+ const value = String(s ?? "");
14
+ this.value = safe ? value : Chunk.escape(value);
15
+ }
16
+ /**
17
+ * @returns `value`
18
+ */
19
+ toString() {
20
+ return this.value;
21
+ }
22
+ /**
23
+ * @param chunks Chunks to append to the end of the chunk
24
+ */
25
+ concat(...chunks) {
26
+ this.value += chunks.join("");
27
+ }
4
28
  /**
5
29
  * Escapes strings of HTML.
6
30
  *
7
- * @param str String to escape
31
+ * @param s String to escape
8
32
  * @param attr Set to `true` if the value is an attribute, otherwise it's a string of HTML content
9
33
  * @returns Escaped string of HTML
10
34
  */
11
- static escape(str, attr) {
35
+ static escape(s, attr) {
12
36
  // adapted from https://github.com/sveltejs/svelte/blob/main/packages/svelte/src/escaping.js
13
- const s = String(str ?? "");
14
37
  const regex = attr ? Chunk.#attr : Chunk.#content;
15
38
  // search starts at beginning of the string
16
39
  regex.lastIndex = 0;
@@ -32,29 +55,4 @@ export class Chunk {
32
55
  }
33
56
  return result + s.slice(start);
34
57
  }
35
- /** Safe value to render. */
36
- value;
37
- /**
38
- * @param html converted to a string
39
- * @param safe Set to `true` if the HTML is safe and should not be escaped
40
- */
41
- constructor(html, safe) {
42
- const str = String(html ?? "");
43
- if (safe)
44
- this.value = str;
45
- else
46
- this.value = Chunk.escape(str);
47
- }
48
- /**
49
- * @returns `value`
50
- */
51
- toString() {
52
- return this.value;
53
- }
54
- /**
55
- * @param chunks Chunks to append to the end of the chunk
56
- */
57
- concat(...chunks) {
58
- this.value += chunks.join("");
59
- }
60
58
  }
@@ -1,24 +1,27 @@
1
1
  import type { MaybeFunction, MaybePromise } from "../types/index.js";
2
2
  import { Chunk } from "./chunk/index.js";
3
- import type { Elements } from "./elements.js";
3
+ import type { IntrinsicElements as IE } from "./intrinsic-elements.js";
4
+ /** ovr JSX namespace */
4
5
  export declare namespace JSX {
5
- interface IntrinsicElements extends Elements {
6
+ /** Standard HTML elements */
7
+ interface IntrinsicElements extends IE {
6
8
  }
9
+ /** ovr Element */
7
10
  type Element = MaybeFunction<MaybePromise<string | number | bigint | boolean | object | null | undefined | Symbol | Iterable<Element> | AsyncIterable<Element>>>;
8
11
  }
9
- export type Props = Record<string, unknown>;
10
- export type FC<Props> = (props: Props) => JSX.Element;
12
+ /** Unknown component props. */
13
+ export type Props = Record<string, JSX.Element>;
11
14
  /**
12
15
  * The main function of the JSX transform cycle, each time JSX is encountered
13
16
  * it is passed into this function to be resolved.
14
17
  *
15
- * @param tag string or function that refers to the component or element type
18
+ * @param tag string or function component
16
19
  * @param props object containing all the properties and attributes passed to the element or component
17
- * @returns an async generator that yields parts of HTML
20
+ * @returns an async generator that yields `Chunk`s of HTML
18
21
  */
19
- export declare function jsx(tag: FC<Props> | string, props: Props): AsyncGenerator<Chunk, void, unknown>;
22
+ export declare function jsx<P extends Props = Props>(tag: ((props: P) => JSX.Element) | string, props: P): AsyncGenerator<Chunk, void, unknown>;
20
23
  /**
21
- * JSX requires a `Fragment` export to resolve <></>
24
+ * JSX requires a `Fragment` export to resolve `<></>`
22
25
  *
23
26
  * @param props containing `children` to render
24
27
  * @returns async generator that yields concatenated children
@@ -40,6 +43,7 @@ export declare function toGenerator(element: JSX.Element): AsyncGenerator<Chunk,
40
43
  * Use `toGenerator` whenever possible.
41
44
  *
42
45
  * @param element
43
- * @returns A promise that resolves to the concatenated HTML.
46
+ * @returns Concatenated HTML
44
47
  */
45
48
  export declare const toString: (element: JSX.Element) => Promise<string>;
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE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