soseki 0.0.4 → 0.0.6
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 +48 -30
- 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,37 +1,43 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReadonlyURL } from "./readonly-url.types.js";
|
|
2
|
+
import type { Route, RoutePathParams } from "./route.types.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* パスマッチングの処理結果を表すオブジェクトの型定義です。
|
|
5
6
|
*/
|
|
6
7
|
export type MatchPathResult = {
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* マッチした URL パスから抽出されたパラメーターのキーと値のオブジェクトです。
|
|
9
10
|
*/
|
|
10
|
-
params:
|
|
11
|
+
params: RoutePathParams;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
+
* 指定されたルートの正規表現パターンと URL のパス部分を照合し、マッチング検証およびパラメーター抽出を行う関数です。
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
17
|
+
* ルーティングエンジンが、現在の遷移先 URL に適合するルートを特定し、動的セグメントの値を型安全に回収する目的で使用します。
|
|
18
|
+
*
|
|
19
|
+
* @param route 検証対象となるルートオブジェクトから、マッチングに必要な `paramKeys` と `pathPattern` を抽出したオブジェクトです。
|
|
20
|
+
* @param url マッチングの判定元となる、読み取り専用の URL オブジェクトです。
|
|
21
|
+
* @returns マッチした場合は抽出されたパラメーターを含む `MatchPathResult` を返し、マッチしなかった場合は `null` を返します。
|
|
19
22
|
*/
|
|
20
23
|
export default function matchPath(
|
|
21
24
|
route: Pick<Route, "paramKeys" | "pathPattern">,
|
|
22
|
-
|
|
25
|
+
url: ReadonlyURL,
|
|
23
26
|
): MatchPathResult | null {
|
|
24
|
-
const matches = route.pathPattern.exec(pathname);
|
|
27
|
+
const matches = route.pathPattern.exec(url.pathname);
|
|
25
28
|
if (!matches) {
|
|
26
29
|
return null;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
const params: Record<string, string> = {};
|
|
30
|
-
for (let i = 0,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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;
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
|
|
@@ -1,56 +1,54 @@
|
|
|
1
1
|
import { parse } from "regexparam";
|
|
2
|
+
|
|
2
3
|
import compareRoutePaths from "./_compare-route-paths.js";
|
|
3
|
-
import
|
|
4
|
+
import RoutePath from "./route-path.js";
|
|
4
5
|
import type { Route, RouteDefinition } from "./route.types.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* 定義したルーティング設定の配列を、内部のルーティングエンジンが直接利用可能な正規化済みのルートオブジェクトの配列へと変換します。
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
function processRoutesImpl(routes: readonly RouteDefinition[], prefix = ""): readonly Route[] {
|
|
14
|
-
return routes
|
|
15
|
-
.map(route => {
|
|
16
|
-
const path = encodePathname(prefix + "/" + route.path);
|
|
17
|
-
const isIndex = !route.children;
|
|
18
|
-
const {
|
|
19
|
-
keys: paramKeys,
|
|
20
|
-
pattern: pathPattern,
|
|
21
|
-
} = parse(
|
|
22
|
-
path,
|
|
23
|
-
// インデックスルートでないとき loose オプションを `true` にして子ルートに対してもマッチするようにします。
|
|
24
|
-
!isIndex,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
path,
|
|
29
|
-
index: isIndex,
|
|
30
|
-
children: route.children
|
|
31
|
-
? processRoutesImpl(route.children, path)
|
|
32
|
-
: [],
|
|
33
|
-
component: route.component,
|
|
34
|
-
dataFuncs: (route.dataFunctions || []).map(f => ({
|
|
35
|
-
action: f.action,
|
|
36
|
-
loader: f.loader,
|
|
37
|
-
// 未定義の場合は常に true を返すデフォルト関数を設定します。
|
|
38
|
-
shouldAction: f.shouldAction || (a => a.defaultShouldAction),
|
|
39
|
-
shouldReload: f.shouldReload || (a => a.defaultShouldReload),
|
|
40
|
-
})),
|
|
41
|
-
paramKeys,
|
|
42
|
-
pathPattern,
|
|
43
|
-
};
|
|
44
|
-
})
|
|
45
|
-
.sort((a, b) => compareRoutePaths(a.path, b.path));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* ルート定義の配列を再帰的に処理し、実行時に適した `Route` オブジェクトの配列に変換します。
|
|
10
|
+
* 実行内容:
|
|
11
|
+
* - 各ルートのパス正規化
|
|
12
|
+
* - 動的解析用の正規表現コンパイル
|
|
13
|
+
* - 詳細度に基づく優先順位ソート
|
|
50
14
|
*
|
|
51
|
-
* @param routes
|
|
52
|
-
* @returns
|
|
15
|
+
* @param routes ルーティング定義を格納した読み取り専用の配列です。
|
|
16
|
+
* @returns 読み取り専用の正規化済みルートオブジェクトの配列です。
|
|
53
17
|
*/
|
|
54
18
|
export default function processRoutes(routes: readonly RouteDefinition[]): readonly Route[] {
|
|
55
|
-
return
|
|
19
|
+
return (
|
|
20
|
+
routes
|
|
21
|
+
.map((route) => {
|
|
22
|
+
const path = RoutePath.encode(route.path);
|
|
23
|
+
const index = route.index === true;
|
|
24
|
+
const { keys: paramKeys, pattern: pathPattern } = parse(
|
|
25
|
+
path,
|
|
26
|
+
// インデックスルートでないとき loose オプションを `true` にして子ルートに対してもマッチするようにします。
|
|
27
|
+
// これにより、前方一致による階層的なマッチングが有効になります。
|
|
28
|
+
!index,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
path,
|
|
33
|
+
index,
|
|
34
|
+
action: route.action,
|
|
35
|
+
loader: route.loader,
|
|
36
|
+
// オブジェクト形式またはモジュール形式の双方を安全に評価し、描画対象となる React コンポーネントを確定します。
|
|
37
|
+
component:
|
|
38
|
+
typeof route.component === "function"
|
|
39
|
+
? route.component
|
|
40
|
+
: Symbol.toStringTag in route &&
|
|
41
|
+
route[Symbol.toStringTag] === "Module" &&
|
|
42
|
+
typeof route.default === "function"
|
|
43
|
+
? route.default
|
|
44
|
+
: undefined,
|
|
45
|
+
paramKeys,
|
|
46
|
+
pathPattern,
|
|
47
|
+
shouldReload: route.shouldReload || ((args) => args.defaultShouldReload),
|
|
48
|
+
};
|
|
49
|
+
})
|
|
50
|
+
// すべてのルートを正規化した後、compareRoutePaths 関数を用いて詳細度が高い順にソートします。
|
|
51
|
+
// マッチング漏れや誤ったルートへの誤認を防ぐため、制限の厳しい(具体的な)パスパターンを持つルートオブジェクトが配列のより前方に配置されます。
|
|
52
|
+
.sort((a, b) => compareRoutePaths(a.path, b.path))
|
|
53
|
+
);
|
|
56
54
|
}
|
package/src/core/_singleton.ts
CHANGED
|
@@ -1,45 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { callFnOnce } from "call-fn-once";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var soseki__singleton: Map<unknown, any> | undefined;
|
|
8
|
-
}
|
|
3
|
+
/**
|
|
4
|
+
* 初回実行時の生成結果を保持するためのグローバルなキャッシュ管理マップです。
|
|
5
|
+
*/
|
|
6
|
+
const cacheMap: callFnOnce.CacheMap = new Map();
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
|
-
*
|
|
9
|
+
* 指定された識別子に対して、渡されたファクトリー関数を一度だけ実行し、その生成結果をシングルトンとして永続化および共有します。
|
|
12
10
|
*
|
|
13
|
-
*
|
|
11
|
+
* 2回目以降の呼び出しでは、ファクトリー関数は実行されず、初回に生成されたキャッシュデータが即座に返されます。
|
|
14
12
|
*
|
|
15
|
-
* @template T
|
|
16
|
-
* @param key
|
|
17
|
-
* @param fn
|
|
18
|
-
* @returns
|
|
13
|
+
* @template T ファクトリー関数が生成するシングルトンオブジェクトの型定義です。
|
|
14
|
+
* @param key シングルトンオブジェクトをキャッシュ内で一意に識別するためのキーです。
|
|
15
|
+
* @param fn 初回呼び出し時にのみ実行される、オブジェクト生成用のファクトリー関数です。
|
|
16
|
+
* @returns 初回実行時に生成された、またはキャッシュから回収された型 `T` のシングルトンインスタンスを返します。
|
|
19
17
|
*/
|
|
20
|
-
export default function singleton<T>(key: unknown, fn: (...args: any) => T): T
|
|
21
|
-
|
|
22
|
-
if (cache.has(key)) {
|
|
23
|
-
return cache.get(key);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let returns = fn();
|
|
27
|
-
if (isPromiseLike<T>(returns)) {
|
|
28
|
-
const promise = (async () => {
|
|
29
|
-
try {
|
|
30
|
-
const value = await returns;
|
|
31
|
-
cache.set(key, value);
|
|
32
|
-
return value;
|
|
33
|
-
} catch (ex) {
|
|
34
|
-
// エラーが発生した場合はキャッシュを削除し、エラーを投げます。
|
|
35
|
-
cache.delete(key);
|
|
36
|
-
throw ex;
|
|
37
|
-
}
|
|
38
|
-
})();
|
|
39
|
-
cache.set(key, promise);
|
|
40
|
-
} else {
|
|
41
|
-
cache.set(key, returns);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return cache.get(key);
|
|
18
|
+
export default function singleton<T>(key: unknown, fn: (...args: any) => T): T {
|
|
19
|
+
return callFnOnce(cacheMap, key, fn);
|
|
45
20
|
}
|
package/src/core/_unreachable.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { tryCaptureStackTrace } from "try-capture-stack-trace";
|
|
2
|
+
|
|
2
3
|
import { UnreachableError } from "./errors.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* 網羅性チェックにおいて、プログラムの制御フローが理論上決して到達しないはずの場所に達したことを示すための関数です。
|
|
6
7
|
*/
|
|
7
8
|
function unreachable(): never;
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* 網羅性チェックにおいて、プログラムの制御フローが理論上決して到達しないはずの場所に達したことを示すための関数です。
|
|
12
|
+
*
|
|
13
|
+
* * `switch` 文の `default` 句などでこの関数に値を渡すことにより、すべての列挙型やユニオン型のケースが処理し尽くされているかを静的に検証します。
|
|
14
|
+
*
|
|
15
|
+
* 漏れがある場合、TypeScript は引数が `never` 型に適合しないというコンパイルエラーを報告します。
|
|
11
16
|
*
|
|
12
|
-
* @param value `never`
|
|
17
|
+
* @param value すべての分岐が処理された結果として、理論上 `never` 型になっているべき変数です。
|
|
13
18
|
*/
|
|
14
19
|
function unreachable(value: never): never;
|
|
15
20
|
|
|
16
|
-
function unreachable(...
|
|
17
|
-
const error = new UnreachableError(
|
|
18
|
-
|
|
21
|
+
function unreachable(...actual: [never?]): never {
|
|
22
|
+
const error = new UnreachableError({ actual });
|
|
23
|
+
tryCaptureStackTrace(error, unreachable);
|
|
19
24
|
throw error;
|
|
20
25
|
}
|
|
21
26
|
|
package/src/core/_valibot.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import isError from "./_is-error.js";
|
|
4
|
-
import { UnexpectedValidationError } from "./errors.js";
|
|
1
|
+
import { tryCaptureStackTrace } from "try-capture-stack-trace";
|
|
2
|
+
import { type InferOutput, safeParse } from "valibot";
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* 共通の型
|
|
9
|
-
*
|
|
10
|
-
**************************************************************************************************/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Valibot のスキーマの基底型を抽出するための型定義です。
|
|
14
|
-
*/
|
|
15
|
-
type BaseSchema = typeof safeParse extends (schema: infer TSchema, ...args: any) => any ? TSchema
|
|
16
|
-
: never;
|
|
4
|
+
import { UnexpectedValidationError } from "./errors.js";
|
|
17
5
|
|
|
18
6
|
/***************************************************************************************************
|
|
19
7
|
*
|
|
@@ -21,101 +9,10 @@ type BaseSchema = typeof safeParse extends (schema: infer TSchema, ...args: any)
|
|
|
21
9
|
*
|
|
22
10
|
**************************************************************************************************/
|
|
23
11
|
|
|
24
|
-
export {
|
|
25
|
-
brand,
|
|
26
|
-
minValue,
|
|
27
|
-
nullable,
|
|
28
|
-
number,
|
|
29
|
-
object,
|
|
30
|
-
pipe,
|
|
31
|
-
safeInteger,
|
|
32
|
-
string,
|
|
33
|
-
union,
|
|
34
|
-
url,
|
|
35
|
-
uuid,
|
|
36
|
-
} from "valibot";
|
|
12
|
+
export { url, pipe, uuid, brand, number, string, minValue, nullable, safeInteger } from "valibot";
|
|
37
13
|
export type { InferInput, InferOutput } from "valibot";
|
|
38
14
|
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
* transform
|
|
42
|
-
*
|
|
43
|
-
**************************************************************************************************/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 入力値を変換するアクションを作成します。例外が投げられた場合は Issue として登録します。
|
|
47
|
-
*
|
|
48
|
-
* @template TInput 入力値の型です。
|
|
49
|
-
* @template TOutput 出力値の型です。
|
|
50
|
-
* @param operation 変換処理を行う関数です。
|
|
51
|
-
* @returns Valibot の RawTransformAction オブジェクトです。
|
|
52
|
-
*/
|
|
53
|
-
export function transform<TInput, TOutput>(
|
|
54
|
-
operation: (input: TInput) => TOutput,
|
|
55
|
-
): RawTransformAction<TInput, TOutput> {
|
|
56
|
-
return rawTransform<TInput, TOutput>(({ dataset, addIssue, NEVER }) => {
|
|
57
|
-
const input = dataset.value;
|
|
58
|
-
try {
|
|
59
|
-
return operation(input);
|
|
60
|
-
} catch (ex) {
|
|
61
|
-
let message: string;
|
|
62
|
-
if (isError(ex)) {
|
|
63
|
-
message = `${ex.name}: ${ex.message}`;
|
|
64
|
-
} else {
|
|
65
|
-
try {
|
|
66
|
-
message = JSON.stringify(ex);
|
|
67
|
-
} catch {
|
|
68
|
-
message = String(ex);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
addIssue({
|
|
73
|
-
input,
|
|
74
|
-
message,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return NEVER;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/***************************************************************************************************
|
|
83
|
-
*
|
|
84
|
-
* parse
|
|
85
|
-
*
|
|
86
|
-
**************************************************************************************************/
|
|
87
|
-
|
|
88
|
-
// /**
|
|
89
|
-
// * バリデーションエラーを生成するためのコンストラクター型インターフェースです。
|
|
90
|
-
// */
|
|
91
|
-
// export interface IParseErrorConstructor {
|
|
92
|
-
// new(issues: [Issue, ...Issue[]], input: unknown): ValidationErrorBase<ErrorMeta>;
|
|
93
|
-
// }
|
|
94
|
-
|
|
95
|
-
// /**
|
|
96
|
-
// * 指定されたスキーマに従って入力を検証し、失敗した場合は指定されたエラーを投げます。
|
|
97
|
-
// *
|
|
98
|
-
// * @template TSchema 使用するスキーマの型です。
|
|
99
|
-
// * @param schema 検証に使用する Valibot スキーマです。
|
|
100
|
-
// * @param input 検証対象の入力値です。
|
|
101
|
-
// * @param Error バリデーション失敗時に投げるエラークラスです。デフォルトは InvalidInputError です。
|
|
102
|
-
// * @returns 検証に成功した出力値です。
|
|
103
|
-
// * @throws 検証に失敗した場合、指定された Error を投げます。
|
|
104
|
-
// */
|
|
105
|
-
// export function parse<const TSchema extends BaseSchema>(
|
|
106
|
-
// schema: TSchema,
|
|
107
|
-
// input: unknown,
|
|
108
|
-
// Error: IParseErrorConstructor = InvalidInputError,
|
|
109
|
-
// ): InferOutput<TSchema> {
|
|
110
|
-
// const result = safeParse(schema, input);
|
|
111
|
-
// if (result.success) {
|
|
112
|
-
// return result.output;
|
|
113
|
-
// }
|
|
114
|
-
|
|
115
|
-
// const error = new Error(result.issues, input);
|
|
116
|
-
// captureStackTrace(error, parse);
|
|
117
|
-
// throw error;
|
|
118
|
-
// }
|
|
15
|
+
export { object, transform } from "@tai-kun/valibot-extra-lab";
|
|
119
16
|
|
|
120
17
|
/***************************************************************************************************
|
|
121
18
|
*
|
|
@@ -123,14 +20,17 @@ export function transform<TInput, TOutput>(
|
|
|
123
20
|
*
|
|
124
21
|
**************************************************************************************************/
|
|
125
22
|
|
|
23
|
+
type BaseSchema = typeof safeParse extends (schema: infer TSchema, ...args: any) => any
|
|
24
|
+
? TSchema
|
|
25
|
+
: never;
|
|
26
|
+
|
|
126
27
|
/**
|
|
127
|
-
*
|
|
28
|
+
* 指定されたスキーマに基づいて入力値の構造を検証し、成功した場合は型安全に解析済みの値を出力します。
|
|
128
29
|
*
|
|
129
|
-
* @template TSchema
|
|
130
|
-
* @param schema
|
|
131
|
-
* @param input
|
|
132
|
-
* @returns
|
|
133
|
-
* @throws 検証に失敗した場合、UnexpectedValidationError を投げます。
|
|
30
|
+
* @template TSchema 評価に使用する `valibot` 形式のスキーマ定義型です。
|
|
31
|
+
* @param schema 入力値を検証するためのスキーマ定義オブジェクトです。
|
|
32
|
+
* @param input 整合性を検証する対象となる未知のデータです。
|
|
33
|
+
* @returns スキマの定義に完全に合致し、型付けが完了した解析済みの出力データを返します。
|
|
134
34
|
*/
|
|
135
35
|
export function expect<const TSchema extends BaseSchema>(
|
|
136
36
|
schema: TSchema,
|
|
@@ -141,7 +41,10 @@ export function expect<const TSchema extends BaseSchema>(
|
|
|
141
41
|
return result.output;
|
|
142
42
|
}
|
|
143
43
|
|
|
144
|
-
const error = new UnexpectedValidationError(
|
|
145
|
-
|
|
44
|
+
const error = new UnexpectedValidationError({
|
|
45
|
+
value: input,
|
|
46
|
+
issues: result.issues,
|
|
47
|
+
});
|
|
48
|
+
tryCaptureStackTrace(error, expect);
|
|
146
49
|
throw error;
|
|
147
50
|
}
|