soseki 0.0.5 → 0.0.7
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/LICENSE +21 -0
- package/dist/src/components/browser-router.d.ts +19 -0
- package/dist/src/components/browser-router.d.ts.map +1 -0
- package/dist/src/components/browser-router.jsx +15 -0
- package/dist/src/components/outlet.d.ts +8 -0
- package/dist/src/components/outlet.d.ts.map +1 -0
- package/dist/src/components/outlet.jsx +15 -0
- package/dist/src/components/router.d.ts +21 -0
- package/dist/src/components/router.d.ts.map +1 -0
- package/dist/src/components/router.jsx +138 -0
- package/dist/src/contexts/route-context.d.ts +19 -0
- package/dist/src/contexts/route-context.d.ts.map +1 -0
- package/dist/src/contexts/route-context.js +6 -0
- package/dist/src/contexts/router-context.d.ts +55 -0
- package/dist/src/contexts/router-context.d.ts.map +1 -0
- package/dist/src/contexts/router-context.js +8 -0
- package/dist/src/core/_compare-route-paths.d.ts +11 -0
- package/dist/src/core/_compare-route-paths.d.ts.map +1 -0
- package/dist/src/core/_compare-route-paths.js +92 -0
- package/dist/src/core/_match-route-path.d.ts +22 -0
- package/dist/src/core/_match-route-path.d.ts.map +1 -0
- package/dist/src/core/_match-route-path.js +26 -0
- package/dist/src/core/_process-routes.d.ts +14 -0
- package/dist/src/core/_process-routes.d.ts.map +1 -0
- package/dist/src/core/_process-routes.js +45 -0
- package/dist/src/core/_singleton.d.ts +12 -0
- package/dist/src/core/_singleton.d.ts.map +1 -0
- package/dist/src/core/_singleton.js +18 -0
- package/dist/src/core/_unreachable.d.ts +16 -0
- package/dist/src/core/_unreachable.d.ts.map +1 -0
- package/dist/src/core/_unreachable.js +8 -0
- package/dist/src/core/_valibot.d.ts +25 -0
- package/dist/src/core/_valibot.d.ts.map +1 -0
- package/dist/src/core/_valibot.js +30 -0
- package/dist/src/core/errors.d.ts +182 -0
- package/dist/src/core/errors.d.ts.map +1 -0
- package/dist/src/core/errors.js +166 -0
- package/dist/src/core/expect-history-entry.d.ts +59 -0
- package/dist/src/core/expect-history-entry.d.ts.map +1 -0
- package/dist/src/core/expect-history-entry.js +42 -0
- package/dist/src/core/form-data-to-html-form-element.d.ts +11 -0
- package/dist/src/core/form-data-to-html-form-element.d.ts.map +1 -0
- package/dist/src/core/form-data-to-html-form-element.js +31 -0
- package/dist/src/core/history-entry-id-schema.d.ts +17 -0
- package/dist/src/core/history-entry-id-schema.d.ts.map +1 -0
- package/dist/src/core/history-entry-id-schema.js +9 -0
- package/dist/src/core/history-entry-url-schema.d.ts +18 -0
- package/dist/src/core/history-entry-url-schema.d.ts.map +1 -0
- package/dist/src/core/history-entry-url-schema.js +20 -0
- package/dist/src/core/init-loaders.d.ts +28 -0
- package/dist/src/core/init-loaders.d.ts.map +1 -0
- package/dist/src/core/init-loaders.js +30 -0
- package/dist/src/core/match-routes.d.ts +28 -0
- package/dist/src/core/match-routes.d.ts.map +1 -0
- package/dist/src/core/match-routes.js +31 -0
- package/dist/src/core/readonly-form-data.types.d.ts +74 -0
- package/dist/src/core/readonly-form-data.types.d.ts.map +1 -0
- package/dist/src/core/readonly-url.types.d.ts +164 -0
- package/dist/src/core/readonly-url.types.d.ts.map +1 -0
- package/dist/src/core/redirect-response.d.ts +37 -0
- package/dist/src/core/redirect-response.d.ts.map +1 -0
- package/dist/src/core/redirect-response.js +19 -0
- package/dist/src/core/route-path.d.ts +57 -0
- package/dist/src/core/route-path.d.ts.map +1 -0
- package/dist/src/core/route-path.js +93 -0
- package/dist/src/core/route-request.d.ts +149 -0
- package/dist/src/core/route-request.d.ts.map +1 -0
- package/dist/src/core/route-request.js +41 -0
- package/dist/src/core/route.types.d.ts +296 -0
- package/dist/src/core/route.types.d.ts.map +1 -0
- package/dist/src/core/start-action.d.ts +53 -0
- package/dist/src/core/start-action.d.ts.map +1 -0
- package/dist/src/core/start-action.js +95 -0
- package/dist/src/core/start-loaders.d.ts +63 -0
- package/dist/src/core/start-loaders.d.ts.map +1 -0
- package/dist/src/core/start-loaders.js +138 -0
- package/dist/{core.d.ts → src/core.d.ts} +7 -11
- package/dist/src/core.d.ts.map +1 -0
- package/dist/{core.js → src/core.js} +2 -4
- package/dist/src/engines/engine.types.d.ts +216 -0
- package/dist/src/engines/engine.types.d.ts.map +1 -0
- package/dist/src/engines/navigation-api-engine.d.ts +50 -0
- package/dist/src/engines/navigation-api-engine.d.ts.map +1 -0
- package/dist/src/engines/navigation-api-engine.js +411 -0
- package/dist/src/engines.d.ts +4 -0
- package/dist/src/engines.d.ts.map +1 -0
- package/dist/src/engines.js +1 -0
- package/dist/src/hooks/_use-singleton.d.ts +11 -0
- package/dist/src/hooks/_use-singleton.d.ts.map +1 -0
- package/dist/src/hooks/_use-singleton.js +26 -0
- package/dist/src/hooks/use-action-data.d.ts +17 -0
- package/dist/src/hooks/use-action-data.d.ts.map +1 -0
- package/dist/src/hooks/use-action-data.js +16 -0
- package/dist/src/hooks/use-form-action.d.ts +7 -0
- package/dist/src/hooks/use-form-action.d.ts.map +1 -0
- package/dist/src/hooks/use-form-action.js +9 -0
- package/dist/src/hooks/use-loader-data.d.ts +9 -0
- package/dist/src/hooks/use-loader-data.d.ts.map +1 -0
- package/dist/src/hooks/use-loader-data.js +20 -0
- package/dist/src/hooks/use-navigate.d.ts +53 -0
- package/dist/src/hooks/use-navigate.d.ts.map +1 -0
- package/dist/src/hooks/use-navigate.js +43 -0
- package/dist/{hooks → src/hooks}/use-params.d.ts +2 -2
- package/dist/src/hooks/use-params.d.ts.map +1 -0
- package/dist/{hooks → src/hooks}/use-params.js +1 -1
- package/dist/src/hooks/use-route-context.d.ts +10 -0
- package/dist/src/hooks/use-route-context.d.ts.map +1 -0
- package/dist/src/hooks/use-route-context.js +17 -0
- package/dist/src/hooks/use-router-context.d.ts +12 -0
- package/dist/src/hooks/use-router-context.d.ts.map +1 -0
- package/dist/src/hooks/use-router-context.js +20 -0
- package/dist/src/hooks/use-submit.d.ts +59 -0
- package/dist/src/hooks/use-submit.d.ts.map +1 -0
- package/dist/src/hooks/use-submit.js +38 -0
- package/dist/src/soseki.d.ts +31 -0
- package/dist/src/soseki.d.ts.map +1 -0
- package/dist/src/soseki.js +12 -0
- package/dist/src/utils/redirect.d.ts +11 -0
- package/dist/src/utils/redirect.d.ts.map +1 -0
- package/dist/src/utils/redirect.js +12 -0
- package/package.json +47 -40
- package/src/components/browser-router.tsx +8 -11
- package/src/components/outlet.tsx +3 -2
- package/src/components/router.tsx +139 -145
- package/src/contexts/route-context.ts +6 -5
- package/src/contexts/router-context.ts +36 -19
- package/src/core/_compare-route-paths.ts +48 -34
- package/src/core/_match-route-path.ts +21 -15
- package/src/core/_process-routes.ts +44 -46
- package/src/core/_singleton.ts +13 -38
- package/src/core/_unreachable.ts +12 -7
- package/src/core/_valibot.ts +19 -116
- package/src/core/errors.ts +150 -495
- package/src/core/expect-history-entry.ts +40 -41
- package/src/core/form-data-to-html-form-element.ts +37 -0
- package/src/core/history-entry-id-schema.ts +6 -11
- package/src/core/history-entry-url-schema.ts +25 -18
- package/src/core/init-loaders.ts +35 -57
- package/src/core/match-routes.ts +33 -65
- package/src/core/readonly-form-data.types.ts +48 -28
- package/src/core/readonly-url.types.ts +57 -28
- package/src/core/redirect-response.ts +26 -15
- package/src/core/route-path.ts +114 -0
- package/src/core/route-request.ts +144 -32
- package/src/core/route.types.ts +250 -226
- package/src/core/start-action.ts +164 -0
- package/src/core/start-loaders.ts +190 -212
- package/src/core.ts +8 -15
- package/src/engines/engine.types.ts +204 -166
- package/src/engines/navigation-api-engine.ts +332 -233
- package/src/engines.ts +4 -0
- package/src/hooks/_use-singleton.ts +30 -0
- package/src/hooks/use-action-data.ts +21 -26
- package/src/hooks/use-form-action.ts +4 -5
- package/src/hooks/use-loader-data.ts +16 -18
- package/src/hooks/use-navigate.ts +69 -28
- package/src/hooks/use-params.ts +4 -4
- package/src/hooks/use-route-context.ts +20 -0
- package/src/hooks/use-router-context.ts +25 -0
- package/src/hooks/use-submit.ts +48 -53
- package/src/soseki.ts +27 -34
- package/src/utils/redirect.ts +5 -5
- package/dist/components/action-id.d.ts +0 -19
- package/dist/components/action-id.d.ts.map +0 -1
- package/dist/components/action-id.jsx +0 -14
- package/dist/components/browser-router.d.ts +0 -17
- package/dist/components/browser-router.d.ts.map +0 -1
- package/dist/components/browser-router.jsx +0 -13
- package/dist/components/hidden-input.d.ts +0 -20
- package/dist/components/hidden-input.d.ts.map +0 -1
- package/dist/components/hidden-input.jsx +0 -8
- package/dist/components/outlet.d.ts +0 -8
- package/dist/components/outlet.d.ts.map +0 -1
- package/dist/components/outlet.jsx +0 -15
- package/dist/components/router.d.ts +0 -23
- package/dist/components/router.d.ts.map +0 -1
- package/dist/components/router.jsx +0 -128
- package/dist/contexts/route-context.d.ts +0 -19
- package/dist/contexts/route-context.d.ts.map +0 -1
- package/dist/contexts/route-context.js +0 -6
- package/dist/contexts/router-context.d.ts +0 -46
- package/dist/contexts/router-context.d.ts.map +0 -1
- package/dist/contexts/router-context.js +0 -8
- package/dist/core/_action-id-registry.d.ts +0 -10
- package/dist/core/_action-id-registry.d.ts.map +0 -1
- package/dist/core/_action-id-registry.js +0 -8
- package/dist/core/_capture-stack-trace.d.ts +0 -8
- package/dist/core/_capture-stack-trace.d.ts.map +0 -1
- package/dist/core/_capture-stack-trace.js +0 -12
- package/dist/core/_compare-route-paths.d.ts +0 -11
- package/dist/core/_compare-route-paths.d.ts.map +0 -1
- package/dist/core/_compare-route-paths.js +0 -80
- package/dist/core/_create-html-form-element-form-form-data.d.ts +0 -9
- package/dist/core/_create-html-form-element-form-form-data.d.ts.map +0 -1
- package/dist/core/_create-html-form-element-form-form-data.js +0 -27
- package/dist/core/_encode-pathname.d.ts +0 -10
- package/dist/core/_encode-pathname.d.ts.map +0 -1
- package/dist/core/_encode-pathname.js +0 -16
- package/dist/core/_is-error.d.ts +0 -3
- package/dist/core/_is-error.d.ts.map +0 -1
- package/dist/core/_is-error.js +0 -13
- package/dist/core/_is-promise-like.d.ts +0 -8
- package/dist/core/_is-promise-like.d.ts.map +0 -1
- package/dist/core/_is-promise-like.js +0 -12
- package/dist/core/_match-route-path.d.ts +0 -19
- package/dist/core/_match-route-path.d.ts.map +0 -1
- package/dist/core/_match-route-path.js +0 -22
- package/dist/core/_process-routes.d.ts +0 -9
- package/dist/core/_process-routes.d.ts.map +0 -1
- package/dist/core/_process-routes.js +0 -47
- package/dist/core/_singleton.d.ts +0 -18
- package/dist/core/_singleton.d.ts.map +0 -1
- package/dist/core/_singleton.js +0 -37
- package/dist/core/_unreachable.d.ts +0 -12
- package/dist/core/_unreachable.d.ts.map +0 -1
- package/dist/core/_unreachable.js +0 -8
- package/dist/core/_use-singleton.d.ts +0 -11
- package/dist/core/_use-singleton.d.ts.map +0 -1
- package/dist/core/_use-singleton.js +0 -21
- package/dist/core/_valibot.d.ts +0 -52
- package/dist/core/_valibot.d.ts.map +0 -1
- package/dist/core/_valibot.js +0 -107
- package/dist/core/_weak-id-registry.d.ts +0 -76
- package/dist/core/_weak-id-registry.d.ts.map +0 -1
- package/dist/core/_weak-id-registry.js +0 -67
- package/dist/core/constants.d.ts +0 -5
- package/dist/core/constants.d.ts.map +0 -1
- package/dist/core/constants.js +0 -4
- package/dist/core/data-map.types.d.ts +0 -23
- package/dist/core/data-map.types.d.ts.map +0 -1
- package/dist/core/data-map.types.js +0 -1
- package/dist/core/data-store.types.d.ts +0 -22
- package/dist/core/data-store.types.d.ts.map +0 -1
- package/dist/core/data-store.types.js +0 -1
- package/dist/core/deferred-promise.d.ts +0 -203
- package/dist/core/deferred-promise.d.ts.map +0 -1
- package/dist/core/deferred-promise.js +0 -200
- package/dist/core/errors.d.ts +0 -303
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/errors.js +0 -400
- package/dist/core/expect-history-entry.d.ts +0 -52
- package/dist/core/expect-history-entry.d.ts.map +0 -1
- package/dist/core/expect-history-entry.js +0 -38
- package/dist/core/history-entry-id-schema.d.ts +0 -17
- package/dist/core/history-entry-id-schema.d.ts.map +0 -1
- package/dist/core/history-entry-id-schema.js +0 -9
- package/dist/core/history-entry-url-schema.d.ts +0 -20
- package/dist/core/history-entry-url-schema.d.ts.map +0 -1
- package/dist/core/history-entry-url-schema.js +0 -16
- package/dist/core/init-loaders.d.ts +0 -37
- package/dist/core/init-loaders.d.ts.map +0 -1
- package/dist/core/init-loaders.js +0 -38
- package/dist/core/match-routes.d.ts +0 -31
- package/dist/core/match-routes.d.ts.map +0 -1
- package/dist/core/match-routes.js +0 -54
- package/dist/core/readonly-form-data.types.d.ts +0 -32
- package/dist/core/readonly-form-data.types.d.ts.map +0 -1
- package/dist/core/readonly-url.types.d.ts +0 -135
- package/dist/core/readonly-url.types.d.ts.map +0 -1
- package/dist/core/redirect-response.d.ts +0 -29
- package/dist/core/redirect-response.d.ts.map +0 -1
- package/dist/core/redirect-response.js +0 -17
- package/dist/core/route-request.d.ts +0 -52
- package/dist/core/route-request.d.ts.map +0 -1
- package/dist/core/route-request.js +0 -26
- package/dist/core/route.types.d.ts +0 -309
- package/dist/core/route.types.d.ts.map +0 -1
- package/dist/core/start-actions.d.ts +0 -60
- package/dist/core/start-actions.d.ts.map +0 -1
- package/dist/core/start-actions.js +0 -186
- package/dist/core/start-loaders.d.ts +0 -69
- package/dist/core/start-loaders.d.ts.map +0 -1
- package/dist/core/start-loaders.js +0 -154
- package/dist/core.d.ts.map +0 -1
- package/dist/engines/engine.types.d.ts +0 -190
- package/dist/engines/engine.types.d.ts.map +0 -1
- package/dist/engines/navigation-api-engine.d.ts +0 -48
- package/dist/engines/navigation-api-engine.d.ts.map +0 -1
- package/dist/engines/navigation-api-engine.js +0 -332
- package/dist/hooks/_use-route-context.d.ts +0 -10
- package/dist/hooks/_use-route-context.d.ts.map +0 -1
- package/dist/hooks/_use-route-context.js +0 -17
- package/dist/hooks/_use-router-context.d.ts +0 -10
- package/dist/hooks/_use-router-context.d.ts.map +0 -1
- package/dist/hooks/_use-router-context.js +0 -18
- package/dist/hooks/use-action-data.d.ts +0 -23
- package/dist/hooks/use-action-data.d.ts.map +0 -1
- package/dist/hooks/use-action-data.js +0 -16
- package/dist/hooks/use-form-action.d.ts +0 -7
- package/dist/hooks/use-form-action.d.ts.map +0 -1
- package/dist/hooks/use-form-action.js +0 -10
- package/dist/hooks/use-loader-data.d.ts +0 -11
- package/dist/hooks/use-loader-data.d.ts.map +0 -1
- package/dist/hooks/use-loader-data.js +0 -19
- package/dist/hooks/use-navigate.d.ts +0 -39
- package/dist/hooks/use-navigate.d.ts.map +0 -1
- package/dist/hooks/use-navigate.js +0 -26
- package/dist/hooks/use-params.d.ts.map +0 -1
- package/dist/hooks/use-pathname.d.ts +0 -7
- package/dist/hooks/use-pathname.d.ts.map +0 -1
- package/dist/hooks/use-pathname.js +0 -9
- package/dist/hooks/use-submit.d.ts +0 -66
- package/dist/hooks/use-submit.d.ts.map +0 -1
- package/dist/hooks/use-submit.js +0 -35
- package/dist/soseki.d.ts +0 -42
- package/dist/soseki.d.ts.map +0 -1
- package/dist/soseki.js +0 -19
- package/dist/utils/get-action-id.d.ts +0 -8
- package/dist/utils/get-action-id.d.ts.map +0 -1
- package/dist/utils/get-action-id.js +0 -11
- package/dist/utils/href.d.ts +0 -11
- package/dist/utils/href.d.ts.map +0 -1
- package/dist/utils/href.js +0 -12
- package/dist/utils/redirect.d.ts +0 -11
- package/dist/utils/redirect.d.ts.map +0 -1
- package/dist/utils/redirect.js +0 -12
- package/dist/utils/route-index.d.ts +0 -41
- package/dist/utils/route-index.d.ts.map +0 -1
- package/dist/utils/route-index.js +0 -12
- package/dist/utils/route-route.d.ts +0 -62
- package/dist/utils/route-route.d.ts.map +0 -1
- package/dist/utils/route-route.js +0 -25
- package/dist/utils/set-action-id.d.ts +0 -9
- package/dist/utils/set-action-id.d.ts.map +0 -1
- package/dist/utils/set-action-id.js +0 -12
- package/src/components/action-id.tsx +0 -35
- package/src/components/hidden-input.tsx +0 -39
- package/src/core/_action-id-registry.ts +0 -11
- package/src/core/_capture-stack-trace.ts +0 -12
- package/src/core/_create-html-form-element-form-form-data.ts +0 -32
- package/src/core/_encode-pathname.ts +0 -17
- package/src/core/_is-error.ts +0 -16
- package/src/core/_is-promise-like.ts +0 -14
- package/src/core/_use-singleton.ts +0 -24
- package/src/core/_weak-id-registry.ts +0 -125
- package/src/core/constants.ts +0 -4
- package/src/core/data-map.types.ts +0 -28
- package/src/core/data-store.types.ts +0 -25
- package/src/core/deferred-promise.ts +0 -408
- package/src/core/start-actions.ts +0 -274
- package/src/hooks/_use-route-context.ts +0 -19
- package/src/hooks/_use-router-context.ts +0 -25
- package/src/hooks/use-pathname.ts +0 -10
- package/src/utils/get-action-id.ts +0 -12
- package/src/utils/href.ts +0 -17
- package/src/utils/route-index.ts +0 -70
- package/src/utils/route-route.ts +0 -111
- package/src/utils/set-action-id.ts +0 -14
- /package/dist/{core → src/core}/readonly-form-data.types.js +0 -0
- /package/dist/{core → src/core}/readonly-url.types.js +0 -0
- /package/dist/{core → src/core}/route.types.js +0 -0
- /package/dist/{engines → src/engines}/engine.types.js +0 -0
|
@@ -1,102 +1,110 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 読み取り専用の URL 操作を行うためのインターフェースです。
|
|
3
|
+
*
|
|
4
|
+
* 標準の `URL` オブジェクトから、プロパティーへの代入による破壊的な変更を禁止し、安全な参照を可能にします。
|
|
3
5
|
*
|
|
4
6
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL)
|
|
7
|
+
*
|
|
8
|
+
* [プロパティーの構成](https://nodejs.org/api/url.html#url-strings-and-url-objects)
|
|
5
9
|
*/
|
|
6
10
|
export interface ReadonlyURL {
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
12
|
+
* URL のハッシュ(シャープ記号 `#` を含むフラグメント識別子)を表します。
|
|
9
13
|
*
|
|
10
14
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/hash)
|
|
11
15
|
*/
|
|
12
16
|
readonly hash: string;
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
|
-
*
|
|
19
|
+
* URL のホスト情報(ホスト名とポート番号 `hostname:port`)を表します。
|
|
16
20
|
*
|
|
17
21
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/host)
|
|
18
22
|
*/
|
|
19
23
|
readonly host: string;
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
|
-
*
|
|
26
|
+
* URL のホスト名を表します。ポート番号は含みません。
|
|
23
27
|
*
|
|
24
28
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/hostname)
|
|
25
29
|
*/
|
|
26
30
|
readonly hostname: string;
|
|
27
31
|
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
33
|
+
* 完全にシリアライズされた URL 文字列全体を表します。
|
|
30
34
|
*
|
|
31
35
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/href)
|
|
32
36
|
*/
|
|
33
37
|
readonly href: string;
|
|
34
38
|
|
|
35
39
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/toString)
|
|
39
|
-
*/
|
|
40
|
-
toString(): string;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* ReadonlyURL インターフェースの **`origin`** プロパティーは、対象となる ReadonlyURL のオリジンを Unicode 形式でシリアライズした文字列を返します。
|
|
40
|
+
* URL のオリジン(プロトコル、ドメイン、およびポート番号)を表します。
|
|
44
41
|
*
|
|
45
42
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/origin)
|
|
46
43
|
*/
|
|
47
44
|
readonly origin: string;
|
|
48
45
|
|
|
49
46
|
/**
|
|
50
|
-
*
|
|
47
|
+
* ドメインの前に指定されたパスワードを表します。
|
|
51
48
|
*
|
|
52
49
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/password)
|
|
53
50
|
*/
|
|
54
51
|
readonly password: string;
|
|
55
52
|
|
|
56
53
|
/**
|
|
57
|
-
*
|
|
54
|
+
* 最初のスラッシュ `/` から始まる URL のパス部分を表します。
|
|
58
55
|
*
|
|
59
56
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/pathname)
|
|
60
57
|
*/
|
|
61
58
|
readonly pathname: string;
|
|
62
59
|
|
|
63
60
|
/**
|
|
64
|
-
*
|
|
61
|
+
* URL のポート番号を表します。デフォルトのポート番号である場合は空文字列を返します。
|
|
65
62
|
*
|
|
66
63
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/port)
|
|
67
64
|
*/
|
|
68
65
|
readonly port: string;
|
|
69
66
|
|
|
70
67
|
/**
|
|
71
|
-
*
|
|
68
|
+
* 末尾のコロン `:` を含む URL のプロトコルスキームを表します。
|
|
72
69
|
*
|
|
73
70
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/protocol)
|
|
74
71
|
*/
|
|
75
72
|
readonly protocol: string;
|
|
76
73
|
|
|
77
74
|
/**
|
|
78
|
-
*
|
|
75
|
+
* 先頭のクエスチョンマーク `?` を含む URL のクエリー文字列を表します。
|
|
79
76
|
*
|
|
80
77
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/search)
|
|
81
78
|
*/
|
|
82
79
|
readonly search: string;
|
|
83
80
|
|
|
84
81
|
/**
|
|
85
|
-
*
|
|
82
|
+
* クエリーパラメーターを操作するための読み取り専用オブジェクトを返します。
|
|
86
83
|
*
|
|
87
84
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/searchParams)
|
|
88
85
|
*/
|
|
89
86
|
readonly searchParams: ReadonlyURLSearchParams;
|
|
90
87
|
|
|
91
88
|
/**
|
|
92
|
-
*
|
|
89
|
+
* ドメインの前に指定されたユーザー名を表します。
|
|
93
90
|
*
|
|
94
91
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/username)
|
|
95
92
|
*/
|
|
96
93
|
readonly username: string;
|
|
97
94
|
|
|
98
95
|
/**
|
|
99
|
-
*
|
|
96
|
+
* `href` プロパティーと同じシリアライズされた URL 文字列を返します。
|
|
97
|
+
*
|
|
98
|
+
* @returns URL の文字列表現です。
|
|
99
|
+
*
|
|
100
|
+
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/toString)
|
|
101
|
+
*/
|
|
102
|
+
toString(): string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* JSON シリアライズの際に呼び出され、`href` プロパティーと同じ文字列を返します。
|
|
106
|
+
*
|
|
107
|
+
* @returns URL の文字列表現です。
|
|
100
108
|
*
|
|
101
109
|
* [MDN リファレンス](https://developer.mozilla.org/docs/Web/API/URL/toJSON)
|
|
102
110
|
*/
|
|
@@ -104,48 +112,69 @@ export interface ReadonlyURL {
|
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
/**
|
|
107
|
-
*
|
|
115
|
+
* 読み取り専用の URL 検索パラメーターを操作するためのインターフェースです。
|
|
116
|
+
*
|
|
117
|
+
* `URLSearchParams` から破壊的な変更を行うメソッドを排除し、参照専用として定義しています。
|
|
108
118
|
*
|
|
109
119
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams)
|
|
110
120
|
*/
|
|
111
121
|
export interface ReadonlyURLSearchParams {
|
|
112
122
|
/**
|
|
113
|
-
*
|
|
123
|
+
* 検索パラメーターの総数です。
|
|
114
124
|
*
|
|
115
125
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/size)
|
|
116
126
|
*/
|
|
117
127
|
readonly size: number;
|
|
118
128
|
|
|
119
129
|
/**
|
|
120
|
-
*
|
|
130
|
+
* 指定された名前に関連付けられた最初のパラメーターの値を返します。
|
|
131
|
+
*
|
|
132
|
+
* 該当する名前が存在しない場合は `null` を返します。
|
|
133
|
+
*
|
|
134
|
+
* @param name 検索するパラメーターの名前です。
|
|
135
|
+
* @returns パラメーターの値、または `null` です。
|
|
121
136
|
*
|
|
122
137
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/get)
|
|
123
138
|
*/
|
|
124
139
|
get(name: string): string | null;
|
|
125
140
|
|
|
126
141
|
/**
|
|
127
|
-
*
|
|
142
|
+
* 指定された名前に関連付けられたすべてのパラメーターの値を配列として返します。
|
|
143
|
+
*
|
|
144
|
+
* 該当する名前が存在しない場合は空の配列を返します。
|
|
145
|
+
*
|
|
146
|
+
* @param name 検索するパラメーターの名前です。
|
|
147
|
+
* @returns パラメーターの値を格納した文字列の配列です。
|
|
128
148
|
*
|
|
129
149
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/getAll)
|
|
130
150
|
*/
|
|
131
151
|
getAll(name: string): string[];
|
|
132
152
|
|
|
133
153
|
/**
|
|
134
|
-
*
|
|
154
|
+
* 指定された名前(およびオプションで指定された値)に一致するパラメーターが存在するかどうかを判定します。
|
|
155
|
+
*
|
|
156
|
+
* @param name 判定するパラメーターの名前です。
|
|
157
|
+
* @param value 判定に含めるパラメーターの値です。
|
|
158
|
+
* @returns 一致するパラメーターが存在する場合は `true`、存在しない場合は `false` です。
|
|
135
159
|
*
|
|
136
160
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/has)
|
|
137
161
|
*/
|
|
138
162
|
has(name: string, value?: string): boolean;
|
|
139
163
|
|
|
140
164
|
/**
|
|
141
|
-
*
|
|
165
|
+
* すべての検索パラメーターを URL エンコードされた文字列として返します。
|
|
166
|
+
*
|
|
167
|
+
* @returns URL エンコードされたパラメーター文字列です。
|
|
142
168
|
*
|
|
143
169
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/toString)
|
|
144
170
|
*/
|
|
145
171
|
toString(): string;
|
|
146
172
|
|
|
147
173
|
/**
|
|
148
|
-
*
|
|
174
|
+
* 検索パラメーターに含まれるすべての要素に対して、指定されたコールバック関数を巡回して実行します。
|
|
175
|
+
*
|
|
176
|
+
* @param callbackfn 各要素に対して実行するコールバック関数です。
|
|
177
|
+
* @param thisArg コールバック関数の実行時に `this` として使用する値です。
|
|
149
178
|
*
|
|
150
179
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/forEach)
|
|
151
180
|
*/
|
|
@@ -1,36 +1,47 @@
|
|
|
1
|
-
import
|
|
1
|
+
import RoutePath from "./route-path.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* 他のクラスやオブジェクトとの混同を避けるための、このクラス固有の一意の識別シンボル(名目的型付け用)です。
|
|
5
5
|
*/
|
|
6
|
-
declare const
|
|
6
|
+
declare const REDIRECT_RESPONSE_SYMBOL: unique symbol;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* アプリケーション内におけるリダイレクト(画面遷移)の応答を表す不変のデータ構造クラスです。
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* アクションやローダーの処理過程で遷移要求が発生した際、その移動先となるリダイレクトパスの各コンポーネント(パス名、クエリー、ハッシュフラグメント)を解析・保持します。
|
|
12
12
|
*/
|
|
13
13
|
export default class RedirectResponse {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* クラスの型としてのユニーク性を TypeScript 上で強制するためのダミーの読み取り専用プロパティーです。
|
|
16
16
|
*
|
|
17
|
-
*
|
|
17
|
+
* 構造が部分的に一致するだけの他のオブジェクトによる誤入力を防ぎます。
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
public readonly ID: typeof ID;
|
|
19
|
+
public readonly [REDIRECT_RESPONSE_SYMBOL]!: never;
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
|
-
*
|
|
22
|
+
* 遷移先 URL のハッシュフラグメントです。
|
|
23
|
+
*/
|
|
24
|
+
public readonly hash: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 遷移先 URL のクエリー文字列です。
|
|
28
|
+
*/
|
|
29
|
+
public readonly search: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 遷移先 URL のドメイン部分を除いたパスです。
|
|
24
33
|
*/
|
|
25
34
|
public readonly pathname: string;
|
|
26
35
|
|
|
27
36
|
/**
|
|
28
|
-
* RedirectResponse クラスの新しいインスタンスを初期化します。
|
|
37
|
+
* 指定された遷移先パス文字列を解析し、`RedirectResponse` クラスの新しいインスタンスを初期化します。
|
|
29
38
|
*
|
|
30
|
-
* @param
|
|
39
|
+
* @param destination リダイレクト先となる対象のパスです。
|
|
31
40
|
*/
|
|
32
|
-
public constructor(
|
|
33
|
-
|
|
34
|
-
this.
|
|
41
|
+
public constructor(destination: string) {
|
|
42
|
+
const { hash, search, pathname } = new RoutePath(destination);
|
|
43
|
+
this.hash = hash;
|
|
44
|
+
this.search = search;
|
|
45
|
+
this.pathname = pathname;
|
|
35
46
|
}
|
|
36
47
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { ReadonlyURL } from "./readonly-url.types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 連続する複数のスラッシュを検出するための正規表現です。
|
|
5
|
+
*/
|
|
6
|
+
const MULTI_SLASH = /\/\/+/gu;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* アプリケーション内のルーティングにおけるパスを安全に構築・解析・操作するためのクラスです。
|
|
10
|
+
*
|
|
11
|
+
* 内包するホストやプロトコルといった余分な情報を排除し、パス、クエリー、ハッシュのみを一貫した規則で管理します。
|
|
12
|
+
*/
|
|
13
|
+
export default class RoutePath {
|
|
14
|
+
/**
|
|
15
|
+
* 与えられた文字列または URL オブジェクトから、正規化されたパス文字列を即座に生成する静的メソッドです。
|
|
16
|
+
*
|
|
17
|
+
* @param path 正規化の対象となるパス文字列、または `ReadonlyURL` の一部分を構成するオブジェクトです。
|
|
18
|
+
* @returns 冗長なスラッシュや末尾のスラッシュが取り除かれた、結合済みのパス文字列を返します。
|
|
19
|
+
*/
|
|
20
|
+
public static encode(path: string | Pick<ReadonlyURL, "pathname" | "search" | "hash">): string {
|
|
21
|
+
return new RoutePath(path).toString();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 内部でパスコンポーネントの解析と検証を委譲するために保持する、組み込みの `URL` インスタンスです。
|
|
26
|
+
*
|
|
27
|
+
* 基底となる仮想的なオリジンと結合して管理されます。
|
|
28
|
+
*/
|
|
29
|
+
private url: URL;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 新しい `RoutePath` インスタンスを初期化します。
|
|
33
|
+
*
|
|
34
|
+
* 引数として渡された入力値を解析し、スラッシュの重複排除および末尾のスラッシュ削除を自動的に行います。
|
|
35
|
+
*
|
|
36
|
+
* @param path 初期化に使用するパス文字列、または `ReadonlyURL` の一部のプロパティーを持つオブジェクトです。既定値は空文字列です。
|
|
37
|
+
*/
|
|
38
|
+
public constructor(path: string | Pick<ReadonlyURL, "pathname" | "search" | "hash"> = "") {
|
|
39
|
+
if (typeof path === "string") {
|
|
40
|
+
path = ("/" + path).replace(MULTI_SLASH, "/");
|
|
41
|
+
} else {
|
|
42
|
+
const { hash, search, pathname } = path;
|
|
43
|
+
path = ("/" + pathname).replace(MULTI_SLASH, "/") + search + hash;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 組み込みの URL クラスによる厳密な解析機能を利用するため、仮想のプロトコルとホストを前置きして初期化します。
|
|
47
|
+
this.url = new URL("x://y" + path);
|
|
48
|
+
|
|
49
|
+
// ルートパス(/)単体である場合を除き、末尾に存在する不要なスラッシュを削除して一貫性を保ちます。
|
|
50
|
+
const { pathname } = this.url;
|
|
51
|
+
if (pathname !== "/" && pathname.endsWith("/")) {
|
|
52
|
+
this.url.pathname = pathname.substring(0, pathname.length - 1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 正規化されたパス部分の文字列です。
|
|
58
|
+
*/
|
|
59
|
+
public get pathname(): string {
|
|
60
|
+
return this.url.pathname;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public set pathname(value: string) {
|
|
64
|
+
this.url.pathname = value;
|
|
65
|
+
|
|
66
|
+
// ルートパス(/)単体である場合を除き、末尾に存在する不要なスラッシュを削除して一貫性を保ちます。
|
|
67
|
+
const pathname = ("/" + this.url.pathname).replace(MULTI_SLASH, "/");
|
|
68
|
+
if (pathname !== "/" && pathname.endsWith("/")) {
|
|
69
|
+
this.url.pathname = pathname.substring(0, pathname.length - 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 先頭に `?` を含むクエリー文字列です。
|
|
75
|
+
*
|
|
76
|
+
* 常にソートされます。
|
|
77
|
+
*/
|
|
78
|
+
public get search(): string {
|
|
79
|
+
this.url.searchParams.sort();
|
|
80
|
+
return this.url.search;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public set search(value: string) {
|
|
84
|
+
this.url.search = value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 内部の `URL` インスタンスが保持する、クエリーパラメーターを操作するための `URLSearchParams` オブジェクトを取得します。
|
|
89
|
+
*/
|
|
90
|
+
public get searchParams(): URLSearchParams {
|
|
91
|
+
return this.url.searchParams;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 先頭に `#` を含むハッシュ文字列を取得します。
|
|
96
|
+
*/
|
|
97
|
+
public get hash(): string {
|
|
98
|
+
return this.url.hash;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public set hash(value: string) {
|
|
102
|
+
this.url.hash = value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 現在保持しているすべてのコンポーネントを結合し、ルーティング用のパス文字列として出力します。
|
|
107
|
+
*
|
|
108
|
+
* @returns ソート済みのクエリーおよびハッシュを含んだ、正規化されたパス全体の文字列を返します。
|
|
109
|
+
*/
|
|
110
|
+
public toString(): string {
|
|
111
|
+
const { hash, search, pathname } = this;
|
|
112
|
+
return pathname + search + hash;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -2,53 +2,152 @@ import type { ReadonlyFormData } from "./readonly-form-data.types.js";
|
|
|
2
2
|
import type { ReadonlyURL } from "./readonly-url.types.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* HTTP の GET メソッドによるルーティングリクエストを表すインターフェースです。
|
|
6
|
+
*
|
|
7
|
+
* GET リクエストの特性上、`formData` は常に `null` となります。
|
|
6
8
|
*/
|
|
7
|
-
|
|
9
|
+
interface RouteGetRequest {
|
|
8
10
|
/**
|
|
9
|
-
* HTTP
|
|
11
|
+
* HTTP メソッドを表します。常に `"GET"` です。
|
|
10
12
|
*/
|
|
11
|
-
|
|
13
|
+
readonly method: "GET";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* リクエスト対象の読み取り専用 URL オブジェクトです。
|
|
17
|
+
*/
|
|
18
|
+
readonly url: ReadonlyURL;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 非同期処理やフェッチを中断するための中断シグナルです。
|
|
22
|
+
*/
|
|
23
|
+
readonly signal: AbortSignal;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* フォームデータです。GET リクエストではデータを本文に含めないため、常に `null` です。
|
|
27
|
+
*/
|
|
28
|
+
readonly formData: null;
|
|
12
29
|
|
|
13
30
|
/**
|
|
14
|
-
*
|
|
31
|
+
* Web 標準の `Request` オブジェクトに変換します。
|
|
15
32
|
*
|
|
16
|
-
*
|
|
33
|
+
* @param init 変換時に上書きまたは追加するリクエストの設定オプションです。
|
|
34
|
+
* @returns 構築された `Request` インスタンスを返します。
|
|
17
35
|
*/
|
|
18
|
-
|
|
36
|
+
toRequest(init?: RequestInit): Request;
|
|
37
|
+
}
|
|
19
38
|
|
|
39
|
+
/**
|
|
40
|
+
* HTTP の POST メソッドによるルーティングリクエストを表すインターフェースです。
|
|
41
|
+
*
|
|
42
|
+
* POST リクエストに伴う読み取り専用の `formData` を保持します。
|
|
43
|
+
*/
|
|
44
|
+
interface RoutePostRequest {
|
|
20
45
|
/**
|
|
21
|
-
*
|
|
46
|
+
* HTTP メソッドを表します。常に `"POST"` です。
|
|
22
47
|
*/
|
|
23
|
-
|
|
48
|
+
readonly method: "POST";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* リクエスト対象の読み取り専用 URL オブジェクトです。
|
|
52
|
+
*/
|
|
53
|
+
readonly url: ReadonlyURL;
|
|
24
54
|
|
|
25
55
|
/**
|
|
26
|
-
*
|
|
56
|
+
* 非同期処理やフェッチを中断するための中断シグナルです。
|
|
57
|
+
*/
|
|
58
|
+
readonly signal: AbortSignal;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* リクエスト本文に紐付けられた、読み取り専用のフォームデータです。
|
|
62
|
+
*/
|
|
63
|
+
readonly formData: ReadonlyFormData;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Web 標準の `Request` オブジェクトに変換します。
|
|
27
67
|
*
|
|
28
|
-
*
|
|
68
|
+
* @param init 変換時に上書きまたは追加するリクエストの設定オプションです。
|
|
69
|
+
* @returns 構築された `Request` インスタンスを返します。
|
|
29
70
|
*/
|
|
30
|
-
|
|
71
|
+
toRequest(init?: RequestInit): Request;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* GET または POST のルーティングリクエストを表す識別子付きユニオン型です。
|
|
76
|
+
*/
|
|
77
|
+
type RouteRequest = RouteGetRequest | RoutePostRequest;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* `RouteGetRequest` と `RoutePostRequest` の両インターフェースに共通するプロパティーの型を抽出した定義です。
|
|
81
|
+
*
|
|
82
|
+
* 実装クラスにおいて最低限満たすべき型安全性の担保に使用します。
|
|
83
|
+
*/
|
|
84
|
+
type RouteRequestImpl = {
|
|
85
|
+
[P in keyof RouteGetRequest & keyof RoutePostRequest]: RouteRequest[P];
|
|
86
|
+
};
|
|
31
87
|
|
|
88
|
+
/**
|
|
89
|
+
* ルーティングコンテキストにおける HTTP リクエストを抽象化し、管理するクラスです。
|
|
90
|
+
*
|
|
91
|
+
* メソッドの種類(GET / POST)に応じて、型安全なリクエストの生成と Web 標準の `Request` オブジェクトへの変換を提供します。
|
|
92
|
+
*/
|
|
93
|
+
const RouteRequest = class RouteRequest implements RouteRequestImpl {
|
|
32
94
|
/**
|
|
33
|
-
*
|
|
95
|
+
* GET メソッド用の `RouteGetRequest` インスタンスを生成するファクトリーメソッドです。
|
|
34
96
|
*
|
|
35
|
-
* @param method
|
|
36
|
-
* @param url
|
|
37
|
-
* @param signal
|
|
97
|
+
* @param method HTTP メソッド名("GET")です。
|
|
98
|
+
* @param url 読み取り専用の URL オブジェクトです。
|
|
99
|
+
* @param signal 処理中断用の中断シグナルです。
|
|
100
|
+
* @returns `RouteGetRequest` インターフェースを満たすインスタンスを返します。
|
|
38
101
|
*/
|
|
39
|
-
public
|
|
40
|
-
|
|
102
|
+
public static new(method: "GET", url: ReadonlyURL, signal: AbortSignal): RouteGetRequest;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* POST メソッド用の `RoutePostRequest` インスタンスを生成するファクトリーメソッドです。
|
|
106
|
+
*
|
|
107
|
+
* @param method HTTP メソッド名("POST")です。
|
|
108
|
+
* @param url 読み取り専用の URL オブジェクトです。
|
|
109
|
+
* @param signal 処理中断用の中断シグナルです。
|
|
110
|
+
* @param formData 読み取り専用のフォームデータです。
|
|
111
|
+
* @returns `RoutePostRequest` インターフェースを満たすインスタンスを返します。
|
|
112
|
+
*/
|
|
113
|
+
public static new(
|
|
114
|
+
method: "POST",
|
|
41
115
|
url: ReadonlyURL,
|
|
42
116
|
signal: AbortSignal,
|
|
43
|
-
|
|
117
|
+
formData: ReadonlyFormData,
|
|
118
|
+
): RoutePostRequest;
|
|
119
|
+
|
|
120
|
+
public static new(...args: [any, any, any, any?]): RouteRequest {
|
|
121
|
+
return new RouteRequest(...args);
|
|
122
|
+
}
|
|
44
123
|
|
|
45
124
|
/**
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
125
|
+
* 読み取り専用の URL オブジェクトです。
|
|
126
|
+
*/
|
|
127
|
+
public readonly url: ReadonlyURL;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 使用される HTTP メソッドです。
|
|
131
|
+
*/
|
|
132
|
+
public readonly method: "GET" | "POST";
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 処理中断用の中断シグナルです。
|
|
136
|
+
*/
|
|
137
|
+
public readonly signal: AbortSignal;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 保持されている読み取り専用のフォームデータです。GET リクエストの場合は `null` となります。
|
|
141
|
+
*/
|
|
142
|
+
public readonly formData: ReadonlyFormData | null;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* GET メソッド用の `RouteRequest` インスタンスを初期化するためのコンストラクターオーバーロードです。
|
|
146
|
+
*/
|
|
147
|
+
public constructor(method: "GET", url: ReadonlyURL, signal: AbortSignal);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* POST メソッド用の `RouteRequest` インスタンスを初期化するためのコンストラクターオーバーロードです。
|
|
52
151
|
*/
|
|
53
152
|
public constructor(
|
|
54
153
|
method: "POST",
|
|
@@ -57,31 +156,40 @@ export default class RouteRequest {
|
|
|
57
156
|
formData: ReadonlyFormData,
|
|
58
157
|
);
|
|
59
158
|
|
|
159
|
+
/**
|
|
160
|
+
* `RouteRequest` コンストラクターの実装本体です。
|
|
161
|
+
*
|
|
162
|
+
* 渡された引数をそれぞれのプロパティーに代入して内部状態を初期化します。
|
|
163
|
+
*/
|
|
60
164
|
public constructor(
|
|
61
165
|
method: "GET" | "POST",
|
|
62
166
|
url: ReadonlyURL,
|
|
63
167
|
signal: AbortSignal,
|
|
64
|
-
formData
|
|
168
|
+
formData: ReadonlyFormData | null = null,
|
|
65
169
|
) {
|
|
66
170
|
this.url = url;
|
|
67
171
|
this.method = method;
|
|
68
172
|
this.signal = signal;
|
|
69
|
-
this.formData = formData
|
|
173
|
+
this.formData = formData;
|
|
70
174
|
}
|
|
71
175
|
|
|
72
176
|
/**
|
|
73
|
-
*
|
|
177
|
+
* インスタンスが保持する情報を基に、Web 標準である Fetch API の `Request` オブジェクトを構築して返します。
|
|
178
|
+
*
|
|
179
|
+
* 外部から任意の `RequestInit` オプションが指定された場合は、インスタンス固有の既定値を上書きします。
|
|
74
180
|
*
|
|
75
|
-
* @param init
|
|
76
|
-
* @returns
|
|
181
|
+
* @param init リクエストの生成オプションを上書きするための初期化オブジェクトです。既定値は空のオブジェクトです。
|
|
182
|
+
* @returns Fetch API でそのまま利用可能な `Request` インスタンスです。
|
|
77
183
|
*/
|
|
78
|
-
public toRequest(init: RequestInit
|
|
184
|
+
public toRequest(init: RequestInit = {}): Request {
|
|
79
185
|
const {
|
|
186
|
+
// 内部の型定義の整合性を維持するため、読み取り専用のインターフェースである formData を、標準の Request の body に適合する FormData 型にキャストしています。
|
|
80
187
|
body = this.formData as FormData | null,
|
|
81
188
|
method = this.method,
|
|
82
189
|
signal = this.signal,
|
|
83
190
|
...other
|
|
84
191
|
} = init;
|
|
192
|
+
|
|
85
193
|
return new Request(this.url.href, {
|
|
86
194
|
body,
|
|
87
195
|
method,
|
|
@@ -89,4 +197,8 @@ export default class RouteRequest {
|
|
|
89
197
|
...other,
|
|
90
198
|
});
|
|
91
199
|
}
|
|
92
|
-
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export type { RouteGetRequest, RoutePostRequest };
|
|
203
|
+
|
|
204
|
+
export default RouteRequest;
|