ovr 1.2.0 → 1.2.2

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.
@@ -26,7 +26,7 @@ type Attributes<P extends Props = Props, Children = JSX.Element> = Partial<{
26
26
  lang: string;
27
27
  nonce: string;
28
28
  part: string;
29
- popover: string;
29
+ popover: boolean | "auto" | "hint" | "manual";
30
30
  role: "alert" | "alertdialog" | "application" | "article" | "banner" | "button" | "cell" | "checkbox" | "columnheader" | "combobox" | "complementary" | "contentinfo" | "definition" | "dialog" | "directory" | "document" | "feed" | "figure" | "form" | "grid" | "gridcell" | "group" | "heading" | "img" | "link" | "list" | "listbox" | "listitem" | "log" | "main" | "marquee" | "math" | "menu" | "menubar" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "navigation" | "none" | "note" | "option" | "presentation" | "progressbar" | "radio" | "radiogroup" | "region" | "row" | "rowgroup" | "rowheader" | "scrollbar" | "search" | "searchbox" | "separator" | "slider" | "spinbutton" | "status" | "switch" | "tab" | "table" | "tablist" | "tabpanel" | "term" | "textbox" | "timer" | "toolbar" | "tooltip" | "tree" | "treegrid" | "treeitem";
31
31
  slot: string;
32
32
  spellcheck: "true" | "false";
@@ -17,7 +17,7 @@ export type FC<Props> = (props: Props) => JSX.Element;
17
17
  */
18
18
  export declare function jsx(tag: FC<Props> | string, props: Props): AsyncGenerator<string, void, unknown>;
19
19
  /**
20
- * jsx requires a `Fragment` export to resolve <></>
20
+ * JSX requires a `Fragment` export to resolve <></>
21
21
  *
22
22
  * @param props containing `children` to render
23
23
  * @returns async generator that yields concatenated children
@@ -27,11 +27,11 @@ export declare function Fragment(props?: {
27
27
  }): AsyncGenerator<string, void, unknown>;
28
28
  /**
29
29
  * @param element
30
- * @returns async generator that yields concatenated children
30
+ * @yields Rendered strings of HTML as the `Element` resolves.
31
31
  */
32
32
  export declare function toGenerator(element: JSX.Element): AsyncGenerator<string, void, unknown>;
33
33
  /**
34
- * Converts a `JSX.Element` into its fully concatenated string representation.
34
+ * Converts a `JSX.Element` into a fully concatenated string of HTML.
35
35
  *
36
36
  * > [!WARNING]
37
37
  * >
package/dist/jsx/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { mergeAsyncIterables } from "./merge-async-iterables.js";
1
+ import { merge } from "./merge-async-iterables.js";
2
2
  // https://developer.mozilla.org/en-US/docs/Glossary/Void_element#self-closing_tags
3
3
  const voidElements = new Set([
4
4
  "area",
@@ -32,7 +32,7 @@ export async function* jsx(tag, props) {
32
32
  const { children, ...attrs } = props;
33
33
  let attrStr = "";
34
34
  for (let key in attrs) {
35
- const value = attrs[key];
35
+ const value = attrs[key]; // needs to come before reassigning keys
36
36
  if (key === "className")
37
37
  key = "class";
38
38
  else if (key === "htmlFor")
@@ -57,7 +57,7 @@ export async function* jsx(tag, props) {
57
57
  }
58
58
  }
59
59
  /**
60
- * jsx requires a `Fragment` export to resolve <></>
60
+ * JSX requires a `Fragment` export to resolve <></>
61
61
  *
62
62
  * @param props containing `children` to render
63
63
  * @returns async generator that yields concatenated children
@@ -67,15 +67,15 @@ export async function* Fragment(props = {}) {
67
67
  }
68
68
  /**
69
69
  * @param element
70
- * @returns async generator that yields concatenated children
70
+ * @yields Rendered strings of HTML as the `Element` resolves.
71
71
  */
72
72
  export async function* toGenerator(element) {
73
73
  if (typeof element === "function")
74
74
  element = element();
75
75
  if (element instanceof Promise)
76
76
  element = await element;
77
- // undefined, null, or false should render ""
78
- if (element == null || element === false)
77
+ // undefined, null, or boolean should not render
78
+ if (element == null || typeof element === "boolean")
79
79
  return;
80
80
  if (typeof element === "object") {
81
81
  if (Symbol.asyncIterator in element) {
@@ -89,8 +89,8 @@ export async function* toGenerator(element) {
89
89
  const queue = new Array(generators.length).fill("");
90
90
  const complete = new Set();
91
91
  let current = 0;
92
- for await (const { index, value, done } of mergeAsyncIterables(generators)) {
93
- if (done) {
92
+ for await (const { index, result } of merge(generators)) {
93
+ if (result.done) {
94
94
  complete.add(index);
95
95
  if (index === current) {
96
96
  while (++current < generators.length) {
@@ -106,10 +106,10 @@ export async function* toGenerator(element) {
106
106
  }
107
107
  }
108
108
  else if (index === current) {
109
- yield value; // stream the current value directly
109
+ yield result.value; // stream the current value directly
110
110
  }
111
111
  else {
112
- queue[index] += value; // queue the value for later
112
+ queue[index] += result.value; // queue the value for later
113
113
  }
114
114
  }
115
115
  yield queue.join(""); // clear the queue
@@ -123,7 +123,7 @@ export async function* toGenerator(element) {
123
123
  }
124
124
  }
125
125
  /**
126
- * Converts a `JSX.Element` into its fully concatenated string representation.
126
+ * Converts a `JSX.Element` into a fully concatenated string of HTML.
127
127
  *
128
128
  * > [!WARNING]
129
129
  * >
@@ -1,12 +1,13 @@
1
1
  /**
2
- * @param iterables `AsyncIterable` array to merge into one
2
+ * Merges `AsyncIterable[]` into a single `AsyncGenerator`, resolving all in parallel.
3
+ * The return of each `AsyncIterable` is yielded from the generator with `done: true`.
4
+ *
5
+ * Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
6
+ *
7
+ * @param iterables Resolved in parallel.
8
+ * @yields `IteratorResult` and `index` of the resolved iterator.
3
9
  */
4
- export declare function mergeAsyncIterables<T>(iterables: AsyncIterable<T>[]): AsyncGenerator<{
10
+ export declare function merge<T, R>(iterables: AsyncIterable<T, R>[]): AsyncGenerator<{
5
11
  index: number;
6
- done: true;
7
- value?: undefined;
8
- } | {
9
- index: number;
10
- value: T;
11
- done: false;
12
+ result: IteratorResult<T, R>;
12
13
  }, void, unknown>;
@@ -1,39 +1,30 @@
1
- class IterableHandler {
2
- index;
3
- iterator;
4
- promise;
5
- constructor(index, iterable) {
6
- this.index = index;
7
- this.iterator = iterable[Symbol.asyncIterator]();
8
- this.promise = this.next();
9
- }
10
- next() {
11
- return (this.promise = this.iterator.next().then((result) => ({
12
- result,
13
- handler: this,
14
- })));
15
- }
16
- }
17
- function* getPromises(handlers) {
18
- for (const handler of handlers)
19
- yield handler.promise;
20
- }
1
+ const never = new Promise(() => { });
2
+ const next = async (iterator, index) => ({
3
+ index,
4
+ result: await iterator.next(),
5
+ });
21
6
  /**
22
- * @param iterables `AsyncIterable` array to merge into one
7
+ * Merges `AsyncIterable[]` into a single `AsyncGenerator`, resolving all in parallel.
8
+ * The return of each `AsyncIterable` is yielded from the generator with `done: true`.
9
+ *
10
+ * Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
11
+ *
12
+ * @param iterables Resolved in parallel.
13
+ * @yields `IteratorResult` and `index` of the resolved iterator.
23
14
  */
24
- export async function* mergeAsyncIterables(iterables) {
25
- const handlers = new Set();
26
- for (let i = 0; i < iterables.length; i++)
27
- handlers.add(new IterableHandler(i, iterables[i]));
28
- while (handlers.size) {
29
- const { result, handler } = await Promise.race(getPromises(handlers));
30
- if (result.done) {
31
- handlers.delete(handler);
32
- yield { index: handler.index, done: true };
15
+ export async function* merge(iterables) {
16
+ const iterators = iterables.map((iter) => iter[Symbol.asyncIterator]());
17
+ const promises = iterators.map(next);
18
+ let remaining = promises.length;
19
+ let current;
20
+ while (remaining) {
21
+ yield (current = await Promise.race(promises));
22
+ if (current.result.done) {
23
+ promises[current.index] = never;
24
+ remaining--;
33
25
  }
34
26
  else {
35
- yield { index: handler.index, value: result.value, done: false };
36
- handler.next();
27
+ promises[current.index] = next(iterators[current.index], current.index);
37
28
  }
38
29
  }
39
30
  }
@@ -169,7 +169,7 @@ export class Context {
169
169
  elements[3] = bodyParts[0];
170
170
  elements.push(Page, bodyClose + bodyParts[1]);
171
171
  this.html(new ReadableStream({
172
- start: async (c) => {
172
+ async start(c) {
173
173
  for await (const value of toGenerator(elements))
174
174
  c.enqueue(value);
175
175
  c.close();
@@ -204,15 +204,9 @@ export class Trie {
204
204
  if (pathname === this.segment) {
205
205
  // reached the end of the path
206
206
  if (this.route)
207
- return {
208
- route: this.route,
209
- params: {},
210
- };
207
+ return { route: this.route, params: {} };
211
208
  if (this.wildcardRoute)
212
- return {
213
- route: this.wildcardRoute,
214
- params: { "*": "" },
215
- };
209
+ return { route: this.wildcardRoute, params: { "*": "" } };
216
210
  return null;
217
211
  }
218
212
  if (this.staticMap) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ovr",
3
3
  "description": "Asynchronous streaming server framework",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",