soseki 0.0.10 → 0.0.12

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 (43) hide show
  1. package/dist/src/core/_process-routes.d.ts.map +1 -1
  2. package/dist/src/core/_process-routes.js +8 -10
  3. package/dist/src/core/_regexparam.d.ts +37 -0
  4. package/dist/src/core/_regexparam.d.ts.map +1 -0
  5. package/dist/src/core/_regexparam.js +1 -0
  6. package/dist/src/core/errors.d.ts +29 -0
  7. package/dist/src/core/errors.d.ts.map +1 -1
  8. package/dist/src/core/errors.js +20 -1
  9. package/dist/src/core/match-routes.d.ts +2 -2
  10. package/dist/src/core/match-routes.d.ts.map +1 -1
  11. package/dist/src/core/match-routes.js +4 -6
  12. package/dist/src/core/route-pattern-utils.d.ts +163 -0
  13. package/dist/src/core/route-pattern-utils.d.ts.map +1 -0
  14. package/dist/src/core/route-pattern-utils.js +222 -0
  15. package/dist/src/core/route.types.d.ts +27 -65
  16. package/dist/src/core/route.types.d.ts.map +1 -1
  17. package/dist/src/core/start-action.d.ts.map +1 -1
  18. package/dist/src/engines/navigation-api-engine.d.ts.map +1 -1
  19. package/dist/src/engines/navigation-api-engine.js +2 -1
  20. package/dist/src/hooks/use-params.d.ts +2 -2
  21. package/dist/src/hooks/use-params.d.ts.map +1 -1
  22. package/dist/src/soseki.d.ts +2 -2
  23. package/dist/src/soseki.d.ts.map +1 -1
  24. package/dist/src/soseki.js +1 -1
  25. package/package.json +1 -1
  26. package/src/core/_process-routes.ts +7 -12
  27. package/src/core/_regexparam.ts +67 -0
  28. package/src/core/errors.ts +52 -0
  29. package/src/core/match-routes.ts +6 -9
  30. package/src/core/route-pattern-utils.ts +327 -0
  31. package/src/core/route.types.ts +29 -98
  32. package/src/core/start-action.ts +2 -2
  33. package/src/engines/navigation-api-engine.ts +2 -1
  34. package/src/hooks/use-params.ts +3 -3
  35. package/src/soseki.ts +3 -3
  36. package/dist/src/core/_match-route-path.d.ts +0 -22
  37. package/dist/src/core/_match-route-path.d.ts.map +0 -1
  38. package/dist/src/core/_match-route-path.js +0 -26
  39. package/dist/src/core/match-route-path.d.ts +0 -46
  40. package/dist/src/core/match-route-path.d.ts.map +0 -1
  41. package/dist/src/core/match-route-path.js +0 -16
  42. package/src/core/_match-route-path.ts +0 -45
  43. package/src/core/match-route-path.ts +0 -78
@@ -1,26 +0,0 @@
1
- /**
2
- * 指定されたルートの正規表現パターンと URL のパス部分を照合し、マッチング検証およびパラメーター抽出を行う関数です。
3
- *
4
- * ルーティングエンジンが、現在の遷移先 URL に適合するルートを特定し、動的セグメントの値を型安全に回収する目的で使用します。
5
- *
6
- * @param route 検証対象となるルートオブジェクトから、マッチングに必要な `paramKeys` と `pathPattern` を抽出したオブジェクトです。
7
- * @param url マッチングの判定元となる、読み取り専用の URL オブジェクトです。
8
- * @returns マッチした場合は抽出されたパラメーターを含む `MatchPathResult` を返し、マッチしなかった場合は `null` を返します。
9
- */
10
- export default function matchPath(route, url) {
11
- const matches = route.pathPattern.exec(url.pathname);
12
- if (!matches) {
13
- return null;
14
- }
15
- const params = {};
16
- for (let i = 0, param; i < route.paramKeys.length; i++) {
17
- // exec メソッドの戻り値のインデックス 0 にはマッチした文字列全体が格納されているため、各パラメーターの値はインデックス 1 以降(i + 1)から取得します。
18
- param = matches[i + 1];
19
- // キャプチャーされたセグメントが存在し、かつ文字列型である場合にのみ、対応するパラメーターキーと値をマッピングします。
20
- // オプショナルなパラメーターが URL 側で省略されている場合は undefined となるため、この条件節により除外されます。
21
- if (typeof param === "string") {
22
- params[route.paramKeys[i]] = param;
23
- }
24
- }
25
- return { params };
26
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * ルーティングの照合対象となる URL 情報を表すインターフェースです。
3
- */
4
- export interface MatchRoutePathTargetURL {
5
- /**
6
- * 照合対象のパス名です。
7
- */
8
- readonly pathname: string;
9
- }
10
- /**
11
- * `matchRoutePath` 関数の動作を設定するための型定義です。
12
- */
13
- export type MatchRoutePathOptions = {
14
- /**
15
- * 照合の基準となるルーティングのパターン文字列です。
16
- */
17
- readonly pattern: string;
18
- /**
19
- * 照合対象とする文字列または URL オブジェクトです。
20
- */
21
- readonly target: string | MatchRoutePathTargetURL;
22
- /**
23
- * 子ディレクトリーへの前方一致を許可するかどうかを制御するフラグです。
24
- *
25
- * @default false
26
- */
27
- readonly allowChild?: boolean | undefined;
28
- };
29
- /**
30
- * 指定されたパターンと対象のパス名が一致するかどうかを判定します。
31
- *
32
- * @param options パターン、対象、および一致条件を含む設定オブジェクトです。
33
- * @returns パターンに一致した場合は `true` を、一致しない場合は `false` を返します。
34
- */
35
- declare function matchRoutePath(options: MatchRoutePathOptions): boolean;
36
- /**
37
- * 指定されたパターンと対象のパス名が一致するかどうかを判定します。
38
- *
39
- * @param pattern 照合の基準となるルーティングのパターン文字列です。
40
- * @param target 照合対象とする文字列または URL オブジェクトです。
41
- * @param options オプションです。
42
- * @returns パターンに一致した場合は `true` を、一致しない場合は `false` を返します。
43
- */
44
- declare function matchRoutePath(pattern: MatchRoutePathOptions["pattern"], target: MatchRoutePathOptions["target"], options?: Omit<MatchRoutePathOptions, "pattern" | "target">): boolean;
45
- export default matchRoutePath;
46
- //# sourceMappingURL=match-route-path.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"match-route-path.d.ts","sourceRoot":"","sources":["../../../src/core/match-route-path.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,uBAAuB,CAAC;IAElD;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,iBAAS,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC;AAEjE;;;;;;;GAOG;AACH,iBAAS,cAAc,CACrB,OAAO,EAAE,qBAAqB,CAAC,SAAS,CAAC,EACzC,MAAM,EAAE,qBAAqB,CAAC,QAAQ,CAAC,EACvC,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,EAAE,SAAS,GAAG,QAAQ,CAAC,GAC1D,OAAO,CAAC;AAqBX,eAAe,cAAc,CAAC"}
@@ -1,16 +0,0 @@
1
- import { parse } from "regexparam";
2
- import RoutePath from "./route-path.js";
3
- function matchRoutePath(...args) {
4
- const { target, pattern, allowChild = false, } = typeof args[0] !== "string"
5
- ? args[0]
6
- : {
7
- ...args[2],
8
- target: args[1],
9
- pattern: args[0],
10
- };
11
- const patternPathname = new RoutePath(pattern).pathname;
12
- const targetPathname = typeof target === "string" ? target : target.pathname;
13
- const patternRegex = parse(patternPathname, allowChild).pattern;
14
- return patternRegex.test(targetPathname);
15
- }
16
- export default matchRoutePath;
@@ -1,45 +0,0 @@
1
- import type { ReadonlyURL } from "./readonly-url.types.js";
2
- import type { Route, RoutePathParams } from "./route.types.js";
3
-
4
- /**
5
- * パスマッチングの処理結果を表すオブジェクトの型定義です。
6
- */
7
- export type MatchPathResult = {
8
- /**
9
- * マッチした URL パスから抽出されたパラメーターのキーと値のオブジェクトです。
10
- */
11
- params: RoutePathParams;
12
- };
13
-
14
- /**
15
- * 指定されたルートの正規表現パターンと URL のパス部分を照合し、マッチング検証およびパラメーター抽出を行う関数です。
16
- *
17
- * ルーティングエンジンが、現在の遷移先 URL に適合するルートを特定し、動的セグメントの値を型安全に回収する目的で使用します。
18
- *
19
- * @param route 検証対象となるルートオブジェクトから、マッチングに必要な `paramKeys` と `pathPattern` を抽出したオブジェクトです。
20
- * @param url マッチングの判定元となる、読み取り専用の URL オブジェクトです。
21
- * @returns マッチした場合は抽出されたパラメーターを含む `MatchPathResult` を返し、マッチしなかった場合は `null` を返します。
22
- */
23
- export default function matchPath(
24
- route: Pick<Route, "paramKeys" | "pathPattern">,
25
- url: ReadonlyURL,
26
- ): MatchPathResult | null {
27
- const matches = route.pathPattern.exec(url.pathname);
28
- if (!matches) {
29
- return null;
30
- }
31
-
32
- const params: Record<string, string> = {};
33
- for (let i = 0, param: string | undefined; i < route.paramKeys.length; i++) {
34
- // exec メソッドの戻り値のインデックス 0 にはマッチした文字列全体が格納されているため、各パラメーターの値はインデックス 1 以降(i + 1)から取得します。
35
- param = matches[i + 1];
36
-
37
- // キャプチャーされたセグメントが存在し、かつ文字列型である場合にのみ、対応するパラメーターキーと値をマッピングします。
38
- // オプショナルなパラメーターが URL 側で省略されている場合は undefined となるため、この条件節により除外されます。
39
- if (typeof param === "string") {
40
- params[route.paramKeys[i]!] = param;
41
- }
42
- }
43
-
44
- return { params };
45
- }
@@ -1,78 +0,0 @@
1
- import { parse } from "regexparam";
2
-
3
- import RoutePath from "./route-path.js";
4
-
5
- /**
6
- * ルーティングの照合対象となる URL 情報を表すインターフェースです。
7
- */
8
- export interface MatchRoutePathTargetURL {
9
- /**
10
- * 照合対象のパス名です。
11
- */
12
- readonly pathname: string;
13
- }
14
-
15
- /**
16
- * `matchRoutePath` 関数の動作を設定するための型定義です。
17
- */
18
- export type MatchRoutePathOptions = {
19
- /**
20
- * 照合の基準となるルーティングのパターン文字列です。
21
- */
22
- readonly pattern: string;
23
-
24
- /**
25
- * 照合対象とする文字列または URL オブジェクトです。
26
- */
27
- readonly target: string | MatchRoutePathTargetURL;
28
-
29
- /**
30
- * 子ディレクトリーへの前方一致を許可するかどうかを制御するフラグです。
31
- *
32
- * @default false
33
- */
34
- readonly allowChild?: boolean | undefined;
35
- };
36
-
37
- /**
38
- * 指定されたパターンと対象のパス名が一致するかどうかを判定します。
39
- *
40
- * @param options パターン、対象、および一致条件を含む設定オブジェクトです。
41
- * @returns パターンに一致した場合は `true` を、一致しない場合は `false` を返します。
42
- */
43
- function matchRoutePath(options: MatchRoutePathOptions): boolean;
44
-
45
- /**
46
- * 指定されたパターンと対象のパス名が一致するかどうかを判定します。
47
- *
48
- * @param pattern 照合の基準となるルーティングのパターン文字列です。
49
- * @param target 照合対象とする文字列または URL オブジェクトです。
50
- * @param options オプションです。
51
- * @returns パターンに一致した場合は `true` を、一致しない場合は `false` を返します。
52
- */
53
- function matchRoutePath(
54
- pattern: MatchRoutePathOptions["pattern"],
55
- target: MatchRoutePathOptions["target"],
56
- options?: Omit<MatchRoutePathOptions, "pattern" | "target">,
57
- ): boolean;
58
-
59
- function matchRoutePath(...args: any): boolean {
60
- const {
61
- target,
62
- pattern,
63
- allowChild = false,
64
- }: MatchRoutePathOptions = typeof args[0] !== "string"
65
- ? args[0]
66
- : {
67
- ...args[2],
68
- target: args[1],
69
- pattern: args[0],
70
- };
71
- const patternPathname = new RoutePath(pattern).pathname;
72
- const targetPathname = typeof target === "string" ? target : target.pathname;
73
- const patternRegex = parse(patternPathname, allowChild).pattern;
74
-
75
- return patternRegex.test(targetPathname);
76
- }
77
-
78
- export default matchRoutePath;