ovr 4.4.0 → 4.5.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.
@@ -1,10 +1,10 @@
1
1
  import { type JSX } from "../../jsx/index.js";
2
2
  import type { ExtractParams } from "../../types/index.js";
3
3
  import type { Middleware } from "../index.js";
4
- import { Helper, type HelperComponentProps } from "./index.js";
4
+ import { Helper, type UrlOptions } from "./index.js";
5
5
  export declare class Get<Pattern extends string = string> extends Helper<Pattern> {
6
6
  /** `<a>` component with preset `href` attribute. */
7
- Anchor: (props: JSX.IntrinsicElements["a"] & HelperComponentProps<ExtractParams<Pattern>>) => JSX.Element;
7
+ Anchor: (props: JSX.IntrinsicElements["a"] & UrlOptions<ExtractParams<Pattern>>) => JSX.Element;
8
8
  /**
9
9
  * @param pattern Route pattern
10
10
  * @param middleware GET middleware
@@ -1 +1 @@
1
- {"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/app/helper/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE/D,qBAAa,GAAG,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,MAAM,CAAC,OAAO,CAAC;IACxE,oDAAoD;IACpD,MAAM,EAAE,CACP,KAAK,EAAE,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAChC,oBAAoB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KACzC,GAAG,CAAC,OAAO,CAAC;IAEjB;;;;;;;;;;;;;;;;;;;OAmBG;gBAEF,OAAO,EAAE,OAAO,EAChB,GAAG,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE;CAYpD"}
1
+ {"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/app/helper/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAErD,qBAAa,GAAG,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,MAAM,CAAC,OAAO,CAAC;IACxE,oDAAoD;IACpD,MAAM,EAAE,CACP,KAAK,EAAE,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAClE,GAAG,CAAC,OAAO,CAAC;IAEjB;;;;;;;;;;;;;;;;;;;OAmBG;gBAEF,OAAO,EAAE,OAAO,EAChB,GAAG,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE;CAYpD"}
@@ -2,13 +2,17 @@ import { type JSX } from "../../jsx/index.js";
2
2
  import type { Params } from "../../trie/index.js";
3
3
  import type { ExtractParams, InsertParams } from "../../types/index.js";
4
4
  import type { Middleware } from "../index.js";
5
- export type HelperComponentProps<P extends Params> = {
5
+ export type UrlOptions<P extends Params> = {
6
6
  /**
7
- * Passed into `URLSearchParams` constructor.
7
+ * If `true` the current request's `url.search` is forwarded, this option
8
+ * can only be used in the context of a request.
9
+ *
10
+ * Otherwise the value is passed into `URLSearchParams` constructor to
11
+ * create new params.
8
12
  *
9
13
  * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
10
14
  */
11
- search?: string | Iterable<[string, string]> | Record<string, string>;
15
+ search?: boolean | string | Iterable<[string, string]> | Record<string, string>;
12
16
  /**
13
17
  * Hash (fragment) of the URL. `"#"` prefix is added if not present.
14
18
  *
@@ -31,9 +35,9 @@ export declare class Helper<Pattern extends string> {
31
35
  /** GET middleware */
32
36
  middleware: Middleware<any>[];
33
37
  /** `<button>` component with preset `formaction` and `formmethod` attributes. */
34
- Button: (props: JSX.IntrinsicElements["button"] & HelperComponentProps<ExtractParams<Pattern>>) => JSX.Element;
38
+ Button: (props: JSX.IntrinsicElements["button"] & UrlOptions<ExtractParams<Pattern>>) => JSX.Element;
35
39
  /** `<form>` component with preset `method` and `action` attributes. */
36
- Form: (props: JSX.IntrinsicElements["form"] & HelperComponentProps<ExtractParams<Pattern>>) => JSX.Element;
40
+ Form: (props: JSX.IntrinsicElements["form"] & UrlOptions<ExtractParams<Pattern>>) => JSX.Element;
37
41
  constructor(method: string, pattern: Pattern, ...middleware: Middleware<ExtractParams<Pattern>>[]);
38
42
  /**
39
43
  * Constructs a _relative_ URL for the route.
@@ -41,7 +45,7 @@ export declare class Helper<Pattern extends string> {
41
45
  * @param [options] Options with type safe parameters
42
46
  * @returns `pathname` + `search` + `hash`
43
47
  */
44
- url(...[options]: keyof ExtractParams<Pattern> extends never ? [HelperComponentProps<ExtractParams<Pattern>>] | [] : [HelperComponentProps<ExtractParams<Pattern>>]): string;
48
+ url(...[options]: keyof ExtractParams<Pattern> extends never ? [UrlOptions<ExtractParams<Pattern>>] | [] : [UrlOptions<ExtractParams<Pattern>>]): string;
45
49
  /**
46
50
  * @param [params] Parameters to insert
47
51
  * @returns Resolved `pathname` with params
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/helper/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAO,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAA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Aa,CAAC,OAAO,CAAC,CAAC;IAEhD,oBAAoB;IACpB,OAAO,EAAE,OAAO,CAAC;IAEjB,qBAAqB;IACrB,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IAE9B,iFAAiF;IACjF,MAAM,EAAE,CACP,KAAK,EAAE,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KACvE,GAAG,CAAC,OAAO,CAAC;IAEjB,uEAAuE;IACvE,IAAI,EAAE,CACL,KAAK,EAAE,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KACrE,GAAG,CAAC,OAAO,CAAC;gBAMhB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,GAAG,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE;IAyBpD;;;;;OAKG;IACH,GAAG,CACF,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,aAAa,CAAC,OAAO,CAAC,SAAS,KAAK,GACrD,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GACzC,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IAwCxC;;;OAGG;IACH,QAAQ,CAAC,MAAM,SAAS,aAAa,CAAC,OAAO,CAAC,EAC7C,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,MAAM,SAAS,KAAK,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,GACrD,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC;CA2BhC"}
@@ -1,4 +1,5 @@
1
1
  import { jsx } from "../../jsx/index.js";
2
+ import { Context } from "../context.js";
2
3
  export class Helper {
3
4
  /** Route pattern */
4
5
  pattern;
@@ -35,14 +36,26 @@ export class Helper {
35
36
  const pathname = this.pathname(
36
37
  // @ts-expect-error - do not have to pass in {} if no params
37
38
  options?.params);
38
- const search = options?.search
39
- ? "?" +
40
- new URLSearchParams(options.search)
41
- : "";
42
- // adding # prefix if not present matches the URL setter:
43
- // https://developer.mozilla.org/en-US/docs/Web/API/URL/hash
39
+ let search;
40
+ if (options?.search) {
41
+ if (options.search === true) {
42
+ // forward current request's search
43
+ search = Context.get().url.search;
44
+ }
45
+ else {
46
+ // use the value as the init
47
+ search =
48
+ "?" +
49
+ new URLSearchParams(options.search);
50
+ }
51
+ }
52
+ else {
53
+ search = "";
54
+ }
44
55
  let hash;
45
56
  if (options?.hash) {
57
+ // adding # prefix if not present matches the URL setter:
58
+ // https://developer.mozilla.org/en-US/docs/Web/API/URL/hash
46
59
  if (options.hash.startsWith("#")) {
47
60
  hash = options.hash;
48
61
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ovr",
3
3
  "description": "Progressive HTML Rendering",
4
- "version": "4.4.0",
4
+ "version": "4.5.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,13 +1,12 @@
1
1
  import { type JSX, jsx } from "../../jsx/index.js";
2
2
  import type { ExtractParams } from "../../types/index.js";
3
3
  import type { Middleware } from "../index.js";
4
- import { Helper, type HelperComponentProps } from "./index.js";
4
+ import { Helper, type UrlOptions } from "./index.js";
5
5
 
6
6
  export class Get<Pattern extends string = string> extends Helper<Pattern> {
7
7
  /** `<a>` component with preset `href` attribute. */
8
8
  Anchor: (
9
- props: JSX.IntrinsicElements["a"] &
10
- HelperComponentProps<ExtractParams<Pattern>>,
9
+ props: JSX.IntrinsicElements["a"] & UrlOptions<ExtractParams<Pattern>>,
11
10
  ) => JSX.Element;
12
11
 
13
12
  /**
@@ -38,7 +37,7 @@ export class Get<Pattern extends string = string> extends Helper<Pattern> {
38
37
 
39
38
  this.Anchor = ({ params, search, hash, ...rest }) =>
40
39
  jsx("a", {
41
- href: this.url({ params, search, hash } as HelperComponentProps<
40
+ href: this.url({ params, search, hash } as UrlOptions<
42
41
  ExtractParams<Pattern>
43
42
  >),
44
43
  ...rest,
@@ -1,15 +1,21 @@
1
1
  import { type JSX, jsx } from "../../jsx/index.js";
2
2
  import type { Params } from "../../trie/index.js";
3
3
  import type { ExtractParams, InsertParams } from "../../types/index.js";
4
+ import { Context } from "../context.js";
4
5
  import type { Middleware } from "../index.js";
5
6
 
6
- export type HelperComponentProps<P extends Params> = {
7
+ export type UrlOptions<P extends Params> = {
7
8
  /**
8
- * Passed into `URLSearchParams` constructor.
9
+ * If `true` the current request's `url.search` is forwarded, this option
10
+ * can only be used in the context of a request.
11
+ *
12
+ * Otherwise the value is passed into `URLSearchParams` constructor to
13
+ * create new params.
9
14
  *
10
15
  * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
11
16
  */
12
17
  search?:
18
+ | boolean
13
19
  | string
14
20
  // Iterable is more accurate than the built in string[][] + URLSearchParams
15
21
  // https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/2070
@@ -44,14 +50,12 @@ export class Helper<Pattern extends string> {
44
50
 
45
51
  /** `<button>` component with preset `formaction` and `formmethod` attributes. */
46
52
  Button: (
47
- props: JSX.IntrinsicElements["button"] &
48
- HelperComponentProps<ExtractParams<Pattern>>,
53
+ props: JSX.IntrinsicElements["button"] & UrlOptions<ExtractParams<Pattern>>,
49
54
  ) => JSX.Element;
50
55
 
51
56
  /** `<form>` component with preset `method` and `action` attributes. */
52
57
  Form: (
53
- props: JSX.IntrinsicElements["form"] &
54
- HelperComponentProps<ExtractParams<Pattern>>,
58
+ props: JSX.IntrinsicElements["form"] & UrlOptions<ExtractParams<Pattern>>,
55
59
  ) => JSX.Element;
56
60
 
57
61
  /** Pattern parts */
@@ -68,7 +72,7 @@ export class Helper<Pattern extends string> {
68
72
 
69
73
  this.Button = ({ params, search, hash, ...rest }) =>
70
74
  jsx("button", {
71
- formaction: this.url({ params, search, hash } as HelperComponentProps<
75
+ formaction: this.url({ params, search, hash } as UrlOptions<
72
76
  ExtractParams<Pattern>
73
77
  >),
74
78
  formmethod: method,
@@ -77,7 +81,7 @@ export class Helper<Pattern extends string> {
77
81
 
78
82
  this.Form = ({ params, search, hash, ...rest }) =>
79
83
  jsx("form", {
80
- action: this.url({ params, search, hash } as HelperComponentProps<
84
+ action: this.url({ params, search, hash } as UrlOptions<
81
85
  ExtractParams<Pattern>
82
86
  >),
83
87
  method,
@@ -93,24 +97,35 @@ export class Helper<Pattern extends string> {
93
97
  */
94
98
  url(
95
99
  ...[options]: keyof ExtractParams<Pattern> extends never
96
- ? [HelperComponentProps<ExtractParams<Pattern>>] | []
97
- : [HelperComponentProps<ExtractParams<Pattern>>]
100
+ ? [UrlOptions<ExtractParams<Pattern>>] | []
101
+ : [UrlOptions<ExtractParams<Pattern>>]
98
102
  ) {
99
103
  const pathname = this.pathname(
100
104
  // @ts-expect-error - do not have to pass in {} if no params
101
105
  options?.params,
102
106
  );
103
- const search = options?.search
104
- ? "?" +
105
- new URLSearchParams(
106
- options.search as ConstructorParameters<typeof URLSearchParams>[0],
107
- )
108
- : "";
109
-
110
- // adding # prefix if not present matches the URL setter:
111
- // https://developer.mozilla.org/en-US/docs/Web/API/URL/hash
107
+
108
+ let search: string;
109
+ if (options?.search) {
110
+ if (options.search === true) {
111
+ // forward current request's search
112
+ search = Context.get().url.search;
113
+ } else {
114
+ // use the value as the init
115
+ search =
116
+ "?" +
117
+ new URLSearchParams(
118
+ options.search as ConstructorParameters<typeof URLSearchParams>[0],
119
+ );
120
+ }
121
+ } else {
122
+ search = "";
123
+ }
124
+
112
125
  let hash: string;
113
126
  if (options?.hash) {
127
+ // adding # prefix if not present matches the URL setter:
128
+ // https://developer.mozilla.org/en-US/docs/Web/API/URL/hash
114
129
  if (options.hash.startsWith("#")) {
115
130
  hash = options.hash;
116
131
  } else {