ovr 4.0.0 → 4.1.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/app/get.d.ts +6 -8
- package/dist/app/get.d.ts.map +1 -1
- package/dist/app/get.js +19 -0
- package/dist/app/post.d.ts +5 -9
- package/dist/app/post.d.ts.map +1 -1
- package/dist/app/post.js +11 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/jsx/merge-async-generators.d.ts +0 -1
- package/dist/jsx/merge-async-generators.d.ts.map +1 -1
- package/dist/jsx/merge-async-generators.js +4 -3
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/app/get.ts +33 -5
- package/src/app/post.ts +17 -7
- package/src/index.ts +0 -1
- package/src/jsx/merge-async-generators.ts +4 -2
- package/src/types/index.ts +12 -0
package/dist/app/get.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { type JSX } from "../jsx/index.js";
|
|
2
|
-
import type { ExtractParams } from "../types/index.js";
|
|
3
|
-
import type { Middleware
|
|
4
|
-
type AnchorProps<P extends Params> = JSX.IntrinsicElements["a"] & (keyof P extends never ? {
|
|
5
|
-
params?: never;
|
|
6
|
-
} : {
|
|
7
|
-
params: P;
|
|
8
|
-
});
|
|
2
|
+
import type { AnchorProps, ButtonProps, ExtractParams, FormProps } from "../types/index.js";
|
|
3
|
+
import type { Middleware } from "./index.js";
|
|
9
4
|
export declare class Get<Pattern extends string = string> {
|
|
10
5
|
#private;
|
|
11
6
|
/** Route pattern */
|
|
@@ -14,6 +9,10 @@ export declare class Get<Pattern extends string = string> {
|
|
|
14
9
|
middleware: Middleware<any>[];
|
|
15
10
|
/** `<a>` component with preset `href` attribute. */
|
|
16
11
|
Anchor: (props: AnchorProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
12
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
13
|
+
Button: (props: ButtonProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
14
|
+
/** `<form>` component with preset `method` and `action` attributes. */
|
|
15
|
+
Form: (props: FormProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
17
16
|
/**
|
|
18
17
|
* @param pattern Route pattern
|
|
19
18
|
* @param middleware GET middleware
|
|
@@ -36,5 +35,4 @@ export declare class Get<Pattern extends string = string> {
|
|
|
36
35
|
*/
|
|
37
36
|
constructor(pattern: Pattern, ...middleware: Middleware<ExtractParams<Pattern>>[]);
|
|
38
37
|
}
|
|
39
|
-
export {};
|
|
40
38
|
//# sourceMappingURL=get.d.ts.map
|
package/dist/app/get.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,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;IAEpE,iFAAiF;IACjF,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAEpE,uEAAuE;IACvE,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAIhE;;;;;;;;;;;;;;;;;;;OAmBG;gBAEF,OAAO,EAAE,OAAO,EAChB,GAAG,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE;CA+BpD"}
|
package/dist/app/get.js
CHANGED
|
@@ -7,6 +7,10 @@ export class Get {
|
|
|
7
7
|
middleware;
|
|
8
8
|
/** `<a>` component with preset `href` attribute. */
|
|
9
9
|
Anchor;
|
|
10
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
11
|
+
Button;
|
|
12
|
+
/** `<form>` component with preset `method` and `action` attributes. */
|
|
13
|
+
Form;
|
|
10
14
|
#parts;
|
|
11
15
|
/**
|
|
12
16
|
* @param pattern Route pattern
|
|
@@ -36,5 +40,20 @@ export class Get {
|
|
|
36
40
|
const { params = {}, ...rest } = props;
|
|
37
41
|
return jsx("a", { href: insertParams(this.#parts, params), ...rest });
|
|
38
42
|
};
|
|
43
|
+
this.Button = (props) => {
|
|
44
|
+
const { params = {}, ...rest } = props;
|
|
45
|
+
return jsx("button", {
|
|
46
|
+
formaction: insertParams(this.#parts, params),
|
|
47
|
+
formmethod: "get",
|
|
48
|
+
...rest,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
this.Form = (props) => {
|
|
52
|
+
const { params = {}, ...rest } = props;
|
|
53
|
+
return jsx("form", {
|
|
54
|
+
action: insertParams(this.#parts, params),
|
|
55
|
+
...rest,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
39
58
|
}
|
|
40
59
|
}
|
package/dist/app/post.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { type JSX } from "../jsx/index.js";
|
|
2
|
-
import type { ExtractParams } from "../types/index.js";
|
|
3
|
-
import type { Middleware
|
|
4
|
-
type FormProps<P extends Params> = JSX.IntrinsicElements["form"] & (keyof P extends never ? {
|
|
5
|
-
params?: never;
|
|
6
|
-
} : {
|
|
7
|
-
params: P;
|
|
8
|
-
});
|
|
2
|
+
import type { ButtonProps, ExtractParams, FormProps } from "../types/index.js";
|
|
3
|
+
import type { Middleware } from "./index.js";
|
|
9
4
|
export declare class Post<Pattern extends string = string> {
|
|
10
5
|
#private;
|
|
11
6
|
/** Route pattern */
|
|
12
7
|
pattern: Pattern;
|
|
13
8
|
/** POST middleware */
|
|
14
9
|
middleware: Middleware<any>[];
|
|
10
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
11
|
+
Button: (props: ButtonProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
15
12
|
/** `<form>` component with preset `method` and `action` attributes. */
|
|
16
13
|
Form: (props: FormProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
17
14
|
/**
|
|
@@ -29,7 +26,7 @@ export declare class Post<Pattern extends string = string> {
|
|
|
29
26
|
*
|
|
30
27
|
* const page = new Get("/", () => (
|
|
31
28
|
* <post.Form>
|
|
32
|
-
* <input />
|
|
29
|
+
* <input type="text" name="name" />
|
|
33
30
|
* <button>Submit</button>
|
|
34
31
|
* </post.Form>
|
|
35
32
|
* ));
|
|
@@ -44,5 +41,4 @@ export declare class Post<Pattern extends string = string> {
|
|
|
44
41
|
*/
|
|
45
42
|
constructor(pattern: Pattern, ...middleware: Middleware<ExtractParams<Pattern>>[]);
|
|
46
43
|
}
|
|
47
|
-
export {};
|
|
48
44
|
//# sourceMappingURL=post.d.ts.map
|
package/dist/app/post.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,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,iFAAiF;IACjF,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAEpE,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;CAqCpD"}
|
package/dist/app/post.js
CHANGED
|
@@ -6,6 +6,8 @@ export class Post {
|
|
|
6
6
|
pattern;
|
|
7
7
|
/** POST middleware */
|
|
8
8
|
middleware;
|
|
9
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
10
|
+
Button;
|
|
9
11
|
/** `<form>` component with preset `method` and `action` attributes. */
|
|
10
12
|
Form;
|
|
11
13
|
#parts = [];
|
|
@@ -16,9 +18,17 @@ export class Post {
|
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
18
20
|
this.middleware.unshift(patternOrMiddleware);
|
|
19
|
-
this.pattern = `/
|
|
21
|
+
this.pattern = `/_p/${hash(this.middleware.join())}`;
|
|
20
22
|
}
|
|
21
23
|
this.#parts = this.pattern.split("/");
|
|
24
|
+
this.Button = (props) => {
|
|
25
|
+
const { params = {}, ...rest } = props;
|
|
26
|
+
return jsx("button", {
|
|
27
|
+
formaction: insertParams(this.#parts, params),
|
|
28
|
+
formmethod: "post",
|
|
29
|
+
...rest,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
22
32
|
this.Form = (props) => {
|
|
23
33
|
const { params = {}, ...rest } = props;
|
|
24
34
|
return jsx("form", {
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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
|
|
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"}
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
|
|
6
6
|
*
|
|
7
7
|
* @param generators Resolved in parallel.
|
|
8
|
-
* @param returnValue Passed into each `iterator.return()`
|
|
9
8
|
* @yields `IteratorResult` and `index` of the resolved generator.
|
|
10
9
|
*/
|
|
11
10
|
export declare function merge<T>(generators: AsyncGenerator<T, void>[]): AsyncGenerator<any, void, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-async-generators.d.ts","sourceRoot":"","sources":["../../src/jsx/merge-async-generators.ts"],"names":[],"mappings":"AAKA
|
|
1
|
+
{"version":3,"file":"merge-async-generators.d.ts","sourceRoot":"","sources":["../../src/jsx/merge-async-generators.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAAuB,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,sCA6BpE"}
|
|
@@ -9,7 +9,6 @@ const next = async (iterator, index) => ({
|
|
|
9
9
|
* Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
|
|
10
10
|
*
|
|
11
11
|
* @param generators Resolved in parallel.
|
|
12
|
-
* @param returnValue Passed into each `iterator.return()`
|
|
13
12
|
* @yields `IteratorResult` and `index` of the resolved generator.
|
|
14
13
|
*/
|
|
15
14
|
export async function* merge(generators) {
|
|
@@ -29,7 +28,9 @@ export async function* merge(generators) {
|
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
finally {
|
|
32
|
-
for (const
|
|
33
|
-
|
|
31
|
+
for (const iterator of iterators) {
|
|
32
|
+
// catch - could have already returned
|
|
33
|
+
iterator.return().catch(() => { });
|
|
34
|
+
}
|
|
34
35
|
}
|
|
35
36
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Params } from "../app/index.js";
|
|
2
|
+
import type { JSX } from "../jsx/index.js";
|
|
1
3
|
export type MaybePromise<T> = T | Promise<T>;
|
|
2
4
|
export type MaybeFunction<T> = T | (() => T);
|
|
3
5
|
export type DeepArray<T> = T | DeepArray<T>[];
|
|
@@ -12,4 +14,19 @@ export type ExtractMultiParams<Patterns extends string[]> = Patterns extends [
|
|
|
12
14
|
infer First extends string,
|
|
13
15
|
...infer Rest extends string[]
|
|
14
16
|
] ? Rest["length"] extends 0 ? ExtractParams<First> : ExtractParams<First> | ExtractMultiParams<Rest> : never;
|
|
17
|
+
export type AnchorProps<P extends Params> = JSX.IntrinsicElements["a"] & (keyof P extends never ? {
|
|
18
|
+
params?: never;
|
|
19
|
+
} : {
|
|
20
|
+
params: P;
|
|
21
|
+
});
|
|
22
|
+
export type FormProps<P extends Params> = JSX.IntrinsicElements["form"] & (keyof P extends never ? {
|
|
23
|
+
params?: never;
|
|
24
|
+
} : {
|
|
25
|
+
params: P;
|
|
26
|
+
});
|
|
27
|
+
export type ButtonProps<P extends Params> = JSX.IntrinsicElements["button"] & (keyof P extends never ? {
|
|
28
|
+
params?: never;
|
|
29
|
+
} : {
|
|
30
|
+
params: P;
|
|
31
|
+
});
|
|
15
32
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;AAE9C,MAAM,MAAM,aAAa,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,IACxD,OAAO,SAAS,GAAG,MAAM,MAAM,IAAI,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GAC3D;KAAG,CAAC,IAAI,KAAK,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,GAAG,MAAM;CAAE,GACpD,OAAO,SAAS,GAAG,MAAM,MAAM,IAAI,MAAM,KAAK,EAAE,GAC/C;KAAG,CAAC,IAAI,KAAK,GAAG,MAAM;CAAE,GACxB,OAAO,SAAS,GAAG,MAAM,KAAK,GAAG,GAChC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GACf,EAAE,CAAC;AAET,MAAM,MAAM,kBAAkB,CAAC,QAAQ,SAAS,MAAM,EAAE,IAAI,QAAQ,SAAS;IAC5E,MAAM,KAAK,SAAS,MAAM;IAC1B,GAAG,MAAM,IAAI,SAAS,MAAM,EAAE;CAC9B,GACE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GACvB,aAAa,CAAC,KAAK,CAAC,GACpB,aAAa,CAAC,KAAK,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAChD,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;AAE9C,MAAM,MAAM,aAAa,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,IACxD,OAAO,SAAS,GAAG,MAAM,MAAM,IAAI,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GAC3D;KAAG,CAAC,IAAI,KAAK,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,GAAG,MAAM;CAAE,GACpD,OAAO,SAAS,GAAG,MAAM,MAAM,IAAI,MAAM,KAAK,EAAE,GAC/C;KAAG,CAAC,IAAI,KAAK,GAAG,MAAM;CAAE,GACxB,OAAO,SAAS,GAAG,MAAM,KAAK,GAAG,GAChC;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GACf,EAAE,CAAC;AAET,MAAM,MAAM,kBAAkB,CAAC,QAAQ,SAAS,MAAM,EAAE,IAAI,QAAQ,SAAS;IAC5E,MAAM,KAAK,SAAS,MAAM;IAC1B,GAAG,MAAM,IAAI,SAAS,MAAM,EAAE;CAC9B,GACE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GACvB,aAAa,CAAC,KAAK,CAAC,GACpB,aAAa,CAAC,KAAK,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAChD,KAAK,CAAC;AAET,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,GACrE,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAE9D,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,GACtE,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAE9D,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAC1E,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/app/get.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type JSX, jsx } from "../jsx/index.js";
|
|
2
2
|
import { insertParams } from "../trie/insert-params.js";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import type {
|
|
4
|
+
AnchorProps,
|
|
5
|
+
ButtonProps,
|
|
6
|
+
ExtractParams,
|
|
7
|
+
FormProps,
|
|
8
|
+
} from "../types/index.js";
|
|
9
|
+
import type { Middleware } from "./index.js";
|
|
8
10
|
|
|
9
11
|
export class Get<Pattern extends string = string> {
|
|
10
12
|
/** Route pattern */
|
|
@@ -16,6 +18,12 @@ export class Get<Pattern extends string = string> {
|
|
|
16
18
|
/** `<a>` component with preset `href` attribute. */
|
|
17
19
|
Anchor: (props: AnchorProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
18
20
|
|
|
21
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
22
|
+
Button: (props: ButtonProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
23
|
+
|
|
24
|
+
/** `<form>` component with preset `method` and `action` attributes. */
|
|
25
|
+
Form: (props: FormProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
26
|
+
|
|
19
27
|
#parts: string[];
|
|
20
28
|
|
|
21
29
|
/**
|
|
@@ -45,10 +53,30 @@ export class Get<Pattern extends string = string> {
|
|
|
45
53
|
this.pattern = pattern;
|
|
46
54
|
this.middleware = middleware;
|
|
47
55
|
this.#parts = pattern.split("/");
|
|
56
|
+
|
|
48
57
|
this.Anchor = (props) => {
|
|
49
58
|
const { params = {}, ...rest } = props;
|
|
50
59
|
|
|
51
60
|
return jsx("a", { href: insertParams(this.#parts, params), ...rest });
|
|
52
61
|
};
|
|
62
|
+
|
|
63
|
+
this.Button = (props) => {
|
|
64
|
+
const { params = {}, ...rest } = props;
|
|
65
|
+
|
|
66
|
+
return jsx("button", {
|
|
67
|
+
formaction: insertParams(this.#parts, params),
|
|
68
|
+
formmethod: "get",
|
|
69
|
+
...rest,
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
this.Form = (props) => {
|
|
74
|
+
const { params = {}, ...rest } = props;
|
|
75
|
+
|
|
76
|
+
return jsx("form", {
|
|
77
|
+
action: insertParams(this.#parts, params),
|
|
78
|
+
...rest,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
53
81
|
}
|
|
54
82
|
}
|
package/src/app/post.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { type JSX, jsx } from "../jsx/index.js";
|
|
2
2
|
import { insertParams } from "../trie/insert-params.js";
|
|
3
|
-
import type { ExtractParams } from "../types/index.js";
|
|
3
|
+
import type { ButtonProps, ExtractParams, FormProps } from "../types/index.js";
|
|
4
4
|
import { hash } from "../util/hash.js";
|
|
5
|
-
import type { Middleware
|
|
6
|
-
|
|
7
|
-
type FormProps<P extends Params> = JSX.IntrinsicElements["form"] &
|
|
8
|
-
(keyof P extends never ? { params?: never } : { params: P });
|
|
5
|
+
import type { Middleware } from "./index.js";
|
|
9
6
|
|
|
10
7
|
export class Post<Pattern extends string = string> {
|
|
11
8
|
/** Route pattern */
|
|
@@ -14,6 +11,9 @@ export class Post<Pattern extends string = string> {
|
|
|
14
11
|
/** POST middleware */
|
|
15
12
|
middleware: Middleware<any>[];
|
|
16
13
|
|
|
14
|
+
/** `<button>` component with preset `formaction` and `formmethod` attributes. */
|
|
15
|
+
Button: (props: ButtonProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
16
|
+
|
|
17
17
|
/** `<form>` component with preset `method` and `action` attributes. */
|
|
18
18
|
Form: (props: FormProps<ExtractParams<Pattern>>) => JSX.Element;
|
|
19
19
|
|
|
@@ -34,7 +34,7 @@ export class Post<Pattern extends string = string> {
|
|
|
34
34
|
*
|
|
35
35
|
* const page = new Get("/", () => (
|
|
36
36
|
* <post.Form>
|
|
37
|
-
* <input />
|
|
37
|
+
* <input type="text" name="name" />
|
|
38
38
|
* <button>Submit</button>
|
|
39
39
|
* </post.Form>
|
|
40
40
|
* ));
|
|
@@ -61,11 +61,21 @@ export class Post<Pattern extends string = string> {
|
|
|
61
61
|
this.pattern = patternOrMiddleware;
|
|
62
62
|
} else {
|
|
63
63
|
this.middleware.unshift(patternOrMiddleware);
|
|
64
|
-
this.pattern = `/
|
|
64
|
+
this.pattern = `/_p/${hash(this.middleware.join())}` as Pattern;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
this.#parts = this.pattern.split("/");
|
|
68
68
|
|
|
69
|
+
this.Button = (props) => {
|
|
70
|
+
const { params = {}, ...rest } = props;
|
|
71
|
+
|
|
72
|
+
return jsx("button", {
|
|
73
|
+
formaction: insertParams(this.#parts, params),
|
|
74
|
+
formmethod: "post",
|
|
75
|
+
...rest,
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
69
79
|
this.Form = (props) => {
|
|
70
80
|
const { params = {}, ...rest } = props;
|
|
71
81
|
|
package/src/index.ts
CHANGED
|
@@ -10,7 +10,6 @@ const next = async <T, R>(iterator: AsyncIterator<T, R>, index: number) => ({
|
|
|
10
10
|
* Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
|
|
11
11
|
*
|
|
12
12
|
* @param generators Resolved in parallel.
|
|
13
|
-
* @param returnValue Passed into each `iterator.return()`
|
|
14
13
|
* @yields `IteratorResult` and `index` of the resolved generator.
|
|
15
14
|
*/
|
|
16
15
|
export async function* merge<T>(generators: AsyncGenerator<T, void>[]) {
|
|
@@ -37,6 +36,9 @@ export async function* merge<T>(generators: AsyncGenerator<T, void>[]) {
|
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
} finally {
|
|
40
|
-
for (const
|
|
39
|
+
for (const iterator of iterators) {
|
|
40
|
+
// catch - could have already returned
|
|
41
|
+
iterator.return().catch(() => {});
|
|
42
|
+
}
|
|
41
43
|
}
|
|
42
44
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { Params } from "../app/index.js";
|
|
2
|
+
import type { JSX } from "../jsx/index.js";
|
|
3
|
+
|
|
1
4
|
export type MaybePromise<T> = T | Promise<T>;
|
|
2
5
|
|
|
3
6
|
export type MaybeFunction<T> = T | (() => T);
|
|
@@ -21,3 +24,12 @@ export type ExtractMultiParams<Patterns extends string[]> = Patterns extends [
|
|
|
21
24
|
? ExtractParams<First>
|
|
22
25
|
: ExtractParams<First> | ExtractMultiParams<Rest>
|
|
23
26
|
: never;
|
|
27
|
+
|
|
28
|
+
export type AnchorProps<P extends Params> = JSX.IntrinsicElements["a"] &
|
|
29
|
+
(keyof P extends never ? { params?: never } : { params: P });
|
|
30
|
+
|
|
31
|
+
export type FormProps<P extends Params> = JSX.IntrinsicElements["form"] &
|
|
32
|
+
(keyof P extends never ? { params?: never } : { params: P });
|
|
33
|
+
|
|
34
|
+
export type ButtonProps<P extends Params> = JSX.IntrinsicElements["button"] &
|
|
35
|
+
(keyof P extends never ? { params?: never } : { params: P });
|