soseki 0.0.5 → 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.
Files changed (352) hide show
  1. package/LICENSE +21 -0
  2. package/dist/src/components/browser-router.d.ts +19 -0
  3. package/dist/src/components/browser-router.d.ts.map +1 -0
  4. package/dist/src/components/browser-router.jsx +15 -0
  5. package/dist/src/components/outlet.d.ts +8 -0
  6. package/dist/src/components/outlet.d.ts.map +1 -0
  7. package/dist/src/components/outlet.jsx +15 -0
  8. package/dist/src/components/router.d.ts +21 -0
  9. package/dist/src/components/router.d.ts.map +1 -0
  10. package/dist/src/components/router.jsx +138 -0
  11. package/dist/src/contexts/route-context.d.ts +19 -0
  12. package/dist/src/contexts/route-context.d.ts.map +1 -0
  13. package/dist/src/contexts/route-context.js +6 -0
  14. package/dist/src/contexts/router-context.d.ts +55 -0
  15. package/dist/src/contexts/router-context.d.ts.map +1 -0
  16. package/dist/src/contexts/router-context.js +8 -0
  17. package/dist/src/core/_compare-route-paths.d.ts +11 -0
  18. package/dist/src/core/_compare-route-paths.d.ts.map +1 -0
  19. package/dist/src/core/_compare-route-paths.js +92 -0
  20. package/dist/src/core/_match-route-path.d.ts +22 -0
  21. package/dist/src/core/_match-route-path.d.ts.map +1 -0
  22. package/dist/src/core/_match-route-path.js +26 -0
  23. package/dist/src/core/_process-routes.d.ts +14 -0
  24. package/dist/src/core/_process-routes.d.ts.map +1 -0
  25. package/dist/src/core/_process-routes.js +45 -0
  26. package/dist/src/core/_singleton.d.ts +12 -0
  27. package/dist/src/core/_singleton.d.ts.map +1 -0
  28. package/dist/src/core/_singleton.js +18 -0
  29. package/dist/src/core/_unreachable.d.ts +16 -0
  30. package/dist/src/core/_unreachable.d.ts.map +1 -0
  31. package/dist/src/core/_unreachable.js +8 -0
  32. package/dist/src/core/_valibot.d.ts +25 -0
  33. package/dist/src/core/_valibot.d.ts.map +1 -0
  34. package/dist/src/core/_valibot.js +30 -0
  35. package/dist/src/core/errors.d.ts +182 -0
  36. package/dist/src/core/errors.d.ts.map +1 -0
  37. package/dist/src/core/errors.js +166 -0
  38. package/dist/src/core/expect-history-entry.d.ts +59 -0
  39. package/dist/src/core/expect-history-entry.d.ts.map +1 -0
  40. package/dist/src/core/expect-history-entry.js +42 -0
  41. package/dist/src/core/form-data-to-html-form-element.d.ts +11 -0
  42. package/dist/src/core/form-data-to-html-form-element.d.ts.map +1 -0
  43. package/dist/src/core/form-data-to-html-form-element.js +31 -0
  44. package/dist/src/core/history-entry-id-schema.d.ts +17 -0
  45. package/dist/src/core/history-entry-id-schema.d.ts.map +1 -0
  46. package/dist/src/core/history-entry-id-schema.js +9 -0
  47. package/dist/src/core/history-entry-url-schema.d.ts +18 -0
  48. package/dist/src/core/history-entry-url-schema.d.ts.map +1 -0
  49. package/dist/src/core/history-entry-url-schema.js +20 -0
  50. package/dist/src/core/init-loaders.d.ts +28 -0
  51. package/dist/src/core/init-loaders.d.ts.map +1 -0
  52. package/dist/src/core/init-loaders.js +30 -0
  53. package/dist/src/core/match-routes.d.ts +28 -0
  54. package/dist/src/core/match-routes.d.ts.map +1 -0
  55. package/dist/src/core/match-routes.js +31 -0
  56. package/dist/src/core/readonly-form-data.types.d.ts +74 -0
  57. package/dist/src/core/readonly-form-data.types.d.ts.map +1 -0
  58. package/dist/src/core/readonly-url.types.d.ts +164 -0
  59. package/dist/src/core/readonly-url.types.d.ts.map +1 -0
  60. package/dist/src/core/redirect-response.d.ts +37 -0
  61. package/dist/src/core/redirect-response.d.ts.map +1 -0
  62. package/dist/src/core/redirect-response.js +19 -0
  63. package/dist/src/core/route-path.d.ts +57 -0
  64. package/dist/src/core/route-path.d.ts.map +1 -0
  65. package/dist/src/core/route-path.js +93 -0
  66. package/dist/src/core/route-request.d.ts +149 -0
  67. package/dist/src/core/route-request.d.ts.map +1 -0
  68. package/dist/src/core/route-request.js +41 -0
  69. package/dist/src/core/route.types.d.ts +296 -0
  70. package/dist/src/core/route.types.d.ts.map +1 -0
  71. package/dist/src/core/start-action.d.ts +53 -0
  72. package/dist/src/core/start-action.d.ts.map +1 -0
  73. package/dist/src/core/start-action.js +95 -0
  74. package/dist/src/core/start-loaders.d.ts +63 -0
  75. package/dist/src/core/start-loaders.d.ts.map +1 -0
  76. package/dist/src/core/start-loaders.js +138 -0
  77. package/dist/{core.d.ts → src/core.d.ts} +7 -11
  78. package/dist/src/core.d.ts.map +1 -0
  79. package/dist/{core.js → src/core.js} +2 -4
  80. package/dist/src/engines/engine.types.d.ts +216 -0
  81. package/dist/src/engines/engine.types.d.ts.map +1 -0
  82. package/dist/src/engines/navigation-api-engine.d.ts +50 -0
  83. package/dist/src/engines/navigation-api-engine.d.ts.map +1 -0
  84. package/dist/src/engines/navigation-api-engine.js +411 -0
  85. package/dist/src/engines.d.ts +4 -0
  86. package/dist/src/engines.d.ts.map +1 -0
  87. package/dist/src/engines.js +1 -0
  88. package/dist/src/hooks/_use-singleton.d.ts +11 -0
  89. package/dist/src/hooks/_use-singleton.d.ts.map +1 -0
  90. package/dist/src/hooks/_use-singleton.js +26 -0
  91. package/dist/src/hooks/use-action-data.d.ts +17 -0
  92. package/dist/src/hooks/use-action-data.d.ts.map +1 -0
  93. package/dist/src/hooks/use-action-data.js +16 -0
  94. package/dist/src/hooks/use-form-action.d.ts +7 -0
  95. package/dist/src/hooks/use-form-action.d.ts.map +1 -0
  96. package/dist/src/hooks/use-form-action.js +9 -0
  97. package/dist/src/hooks/use-loader-data.d.ts +9 -0
  98. package/dist/src/hooks/use-loader-data.d.ts.map +1 -0
  99. package/dist/src/hooks/use-loader-data.js +20 -0
  100. package/dist/src/hooks/use-navigate.d.ts +53 -0
  101. package/dist/src/hooks/use-navigate.d.ts.map +1 -0
  102. package/dist/src/hooks/use-navigate.js +43 -0
  103. package/dist/{hooks → src/hooks}/use-params.d.ts +2 -2
  104. package/dist/src/hooks/use-params.d.ts.map +1 -0
  105. package/dist/{hooks → src/hooks}/use-params.js +1 -1
  106. package/dist/src/hooks/use-route-context.d.ts +10 -0
  107. package/dist/src/hooks/use-route-context.d.ts.map +1 -0
  108. package/dist/src/hooks/use-route-context.js +17 -0
  109. package/dist/src/hooks/use-router-context.d.ts +12 -0
  110. package/dist/src/hooks/use-router-context.d.ts.map +1 -0
  111. package/dist/src/hooks/use-router-context.js +20 -0
  112. package/dist/src/hooks/use-submit.d.ts +59 -0
  113. package/dist/src/hooks/use-submit.d.ts.map +1 -0
  114. package/dist/src/hooks/use-submit.js +38 -0
  115. package/dist/src/soseki.d.ts +31 -0
  116. package/dist/src/soseki.d.ts.map +1 -0
  117. package/dist/src/soseki.js +12 -0
  118. package/dist/src/utils/redirect.d.ts +11 -0
  119. package/dist/src/utils/redirect.d.ts.map +1 -0
  120. package/dist/src/utils/redirect.js +12 -0
  121. package/package.json +47 -40
  122. package/src/components/browser-router.tsx +8 -11
  123. package/src/components/outlet.tsx +3 -2
  124. package/src/components/router.tsx +139 -145
  125. package/src/contexts/route-context.ts +6 -5
  126. package/src/contexts/router-context.ts +36 -19
  127. package/src/core/_compare-route-paths.ts +48 -34
  128. package/src/core/_match-route-path.ts +21 -15
  129. package/src/core/_process-routes.ts +44 -46
  130. package/src/core/_singleton.ts +13 -38
  131. package/src/core/_unreachable.ts +12 -7
  132. package/src/core/_valibot.ts +19 -116
  133. package/src/core/errors.ts +150 -495
  134. package/src/core/expect-history-entry.ts +40 -41
  135. package/src/core/form-data-to-html-form-element.ts +37 -0
  136. package/src/core/history-entry-id-schema.ts +6 -11
  137. package/src/core/history-entry-url-schema.ts +25 -18
  138. package/src/core/init-loaders.ts +35 -57
  139. package/src/core/match-routes.ts +33 -65
  140. package/src/core/readonly-form-data.types.ts +48 -28
  141. package/src/core/readonly-url.types.ts +57 -28
  142. package/src/core/redirect-response.ts +26 -15
  143. package/src/core/route-path.ts +114 -0
  144. package/src/core/route-request.ts +144 -32
  145. package/src/core/route.types.ts +250 -226
  146. package/src/core/start-action.ts +164 -0
  147. package/src/core/start-loaders.ts +190 -212
  148. package/src/core.ts +8 -15
  149. package/src/engines/engine.types.ts +204 -166
  150. package/src/engines/navigation-api-engine.ts +332 -233
  151. package/src/engines.ts +4 -0
  152. package/src/hooks/_use-singleton.ts +30 -0
  153. package/src/hooks/use-action-data.ts +21 -26
  154. package/src/hooks/use-form-action.ts +4 -5
  155. package/src/hooks/use-loader-data.ts +16 -18
  156. package/src/hooks/use-navigate.ts +69 -28
  157. package/src/hooks/use-params.ts +4 -4
  158. package/src/hooks/use-route-context.ts +20 -0
  159. package/src/hooks/use-router-context.ts +25 -0
  160. package/src/hooks/use-submit.ts +48 -53
  161. package/src/soseki.ts +27 -34
  162. package/src/utils/redirect.ts +5 -5
  163. package/dist/components/action-id.d.ts +0 -19
  164. package/dist/components/action-id.d.ts.map +0 -1
  165. package/dist/components/action-id.jsx +0 -14
  166. package/dist/components/browser-router.d.ts +0 -17
  167. package/dist/components/browser-router.d.ts.map +0 -1
  168. package/dist/components/browser-router.jsx +0 -13
  169. package/dist/components/hidden-input.d.ts +0 -20
  170. package/dist/components/hidden-input.d.ts.map +0 -1
  171. package/dist/components/hidden-input.jsx +0 -8
  172. package/dist/components/outlet.d.ts +0 -8
  173. package/dist/components/outlet.d.ts.map +0 -1
  174. package/dist/components/outlet.jsx +0 -15
  175. package/dist/components/router.d.ts +0 -23
  176. package/dist/components/router.d.ts.map +0 -1
  177. package/dist/components/router.jsx +0 -128
  178. package/dist/contexts/route-context.d.ts +0 -19
  179. package/dist/contexts/route-context.d.ts.map +0 -1
  180. package/dist/contexts/route-context.js +0 -6
  181. package/dist/contexts/router-context.d.ts +0 -46
  182. package/dist/contexts/router-context.d.ts.map +0 -1
  183. package/dist/contexts/router-context.js +0 -8
  184. package/dist/core/_action-id-registry.d.ts +0 -10
  185. package/dist/core/_action-id-registry.d.ts.map +0 -1
  186. package/dist/core/_action-id-registry.js +0 -8
  187. package/dist/core/_capture-stack-trace.d.ts +0 -8
  188. package/dist/core/_capture-stack-trace.d.ts.map +0 -1
  189. package/dist/core/_capture-stack-trace.js +0 -12
  190. package/dist/core/_compare-route-paths.d.ts +0 -11
  191. package/dist/core/_compare-route-paths.d.ts.map +0 -1
  192. package/dist/core/_compare-route-paths.js +0 -80
  193. package/dist/core/_create-html-form-element-form-form-data.d.ts +0 -9
  194. package/dist/core/_create-html-form-element-form-form-data.d.ts.map +0 -1
  195. package/dist/core/_create-html-form-element-form-form-data.js +0 -27
  196. package/dist/core/_encode-pathname.d.ts +0 -10
  197. package/dist/core/_encode-pathname.d.ts.map +0 -1
  198. package/dist/core/_encode-pathname.js +0 -16
  199. package/dist/core/_is-error.d.ts +0 -3
  200. package/dist/core/_is-error.d.ts.map +0 -1
  201. package/dist/core/_is-error.js +0 -13
  202. package/dist/core/_is-promise-like.d.ts +0 -8
  203. package/dist/core/_is-promise-like.d.ts.map +0 -1
  204. package/dist/core/_is-promise-like.js +0 -12
  205. package/dist/core/_match-route-path.d.ts +0 -19
  206. package/dist/core/_match-route-path.d.ts.map +0 -1
  207. package/dist/core/_match-route-path.js +0 -22
  208. package/dist/core/_process-routes.d.ts +0 -9
  209. package/dist/core/_process-routes.d.ts.map +0 -1
  210. package/dist/core/_process-routes.js +0 -47
  211. package/dist/core/_singleton.d.ts +0 -18
  212. package/dist/core/_singleton.d.ts.map +0 -1
  213. package/dist/core/_singleton.js +0 -37
  214. package/dist/core/_unreachable.d.ts +0 -12
  215. package/dist/core/_unreachable.d.ts.map +0 -1
  216. package/dist/core/_unreachable.js +0 -8
  217. package/dist/core/_use-singleton.d.ts +0 -11
  218. package/dist/core/_use-singleton.d.ts.map +0 -1
  219. package/dist/core/_use-singleton.js +0 -21
  220. package/dist/core/_valibot.d.ts +0 -52
  221. package/dist/core/_valibot.d.ts.map +0 -1
  222. package/dist/core/_valibot.js +0 -107
  223. package/dist/core/_weak-id-registry.d.ts +0 -76
  224. package/dist/core/_weak-id-registry.d.ts.map +0 -1
  225. package/dist/core/_weak-id-registry.js +0 -67
  226. package/dist/core/constants.d.ts +0 -5
  227. package/dist/core/constants.d.ts.map +0 -1
  228. package/dist/core/constants.js +0 -4
  229. package/dist/core/data-map.types.d.ts +0 -23
  230. package/dist/core/data-map.types.d.ts.map +0 -1
  231. package/dist/core/data-map.types.js +0 -1
  232. package/dist/core/data-store.types.d.ts +0 -22
  233. package/dist/core/data-store.types.d.ts.map +0 -1
  234. package/dist/core/data-store.types.js +0 -1
  235. package/dist/core/deferred-promise.d.ts +0 -203
  236. package/dist/core/deferred-promise.d.ts.map +0 -1
  237. package/dist/core/deferred-promise.js +0 -200
  238. package/dist/core/errors.d.ts +0 -303
  239. package/dist/core/errors.d.ts.map +0 -1
  240. package/dist/core/errors.js +0 -400
  241. package/dist/core/expect-history-entry.d.ts +0 -52
  242. package/dist/core/expect-history-entry.d.ts.map +0 -1
  243. package/dist/core/expect-history-entry.js +0 -38
  244. package/dist/core/history-entry-id-schema.d.ts +0 -17
  245. package/dist/core/history-entry-id-schema.d.ts.map +0 -1
  246. package/dist/core/history-entry-id-schema.js +0 -9
  247. package/dist/core/history-entry-url-schema.d.ts +0 -20
  248. package/dist/core/history-entry-url-schema.d.ts.map +0 -1
  249. package/dist/core/history-entry-url-schema.js +0 -16
  250. package/dist/core/init-loaders.d.ts +0 -37
  251. package/dist/core/init-loaders.d.ts.map +0 -1
  252. package/dist/core/init-loaders.js +0 -38
  253. package/dist/core/match-routes.d.ts +0 -31
  254. package/dist/core/match-routes.d.ts.map +0 -1
  255. package/dist/core/match-routes.js +0 -54
  256. package/dist/core/readonly-form-data.types.d.ts +0 -32
  257. package/dist/core/readonly-form-data.types.d.ts.map +0 -1
  258. package/dist/core/readonly-url.types.d.ts +0 -135
  259. package/dist/core/readonly-url.types.d.ts.map +0 -1
  260. package/dist/core/redirect-response.d.ts +0 -29
  261. package/dist/core/redirect-response.d.ts.map +0 -1
  262. package/dist/core/redirect-response.js +0 -17
  263. package/dist/core/route-request.d.ts +0 -52
  264. package/dist/core/route-request.d.ts.map +0 -1
  265. package/dist/core/route-request.js +0 -26
  266. package/dist/core/route.types.d.ts +0 -309
  267. package/dist/core/route.types.d.ts.map +0 -1
  268. package/dist/core/start-actions.d.ts +0 -60
  269. package/dist/core/start-actions.d.ts.map +0 -1
  270. package/dist/core/start-actions.js +0 -186
  271. package/dist/core/start-loaders.d.ts +0 -69
  272. package/dist/core/start-loaders.d.ts.map +0 -1
  273. package/dist/core/start-loaders.js +0 -154
  274. package/dist/core.d.ts.map +0 -1
  275. package/dist/engines/engine.types.d.ts +0 -190
  276. package/dist/engines/engine.types.d.ts.map +0 -1
  277. package/dist/engines/navigation-api-engine.d.ts +0 -48
  278. package/dist/engines/navigation-api-engine.d.ts.map +0 -1
  279. package/dist/engines/navigation-api-engine.js +0 -332
  280. package/dist/hooks/_use-route-context.d.ts +0 -10
  281. package/dist/hooks/_use-route-context.d.ts.map +0 -1
  282. package/dist/hooks/_use-route-context.js +0 -17
  283. package/dist/hooks/_use-router-context.d.ts +0 -10
  284. package/dist/hooks/_use-router-context.d.ts.map +0 -1
  285. package/dist/hooks/_use-router-context.js +0 -18
  286. package/dist/hooks/use-action-data.d.ts +0 -23
  287. package/dist/hooks/use-action-data.d.ts.map +0 -1
  288. package/dist/hooks/use-action-data.js +0 -16
  289. package/dist/hooks/use-form-action.d.ts +0 -7
  290. package/dist/hooks/use-form-action.d.ts.map +0 -1
  291. package/dist/hooks/use-form-action.js +0 -10
  292. package/dist/hooks/use-loader-data.d.ts +0 -11
  293. package/dist/hooks/use-loader-data.d.ts.map +0 -1
  294. package/dist/hooks/use-loader-data.js +0 -19
  295. package/dist/hooks/use-navigate.d.ts +0 -39
  296. package/dist/hooks/use-navigate.d.ts.map +0 -1
  297. package/dist/hooks/use-navigate.js +0 -26
  298. package/dist/hooks/use-params.d.ts.map +0 -1
  299. package/dist/hooks/use-pathname.d.ts +0 -7
  300. package/dist/hooks/use-pathname.d.ts.map +0 -1
  301. package/dist/hooks/use-pathname.js +0 -9
  302. package/dist/hooks/use-submit.d.ts +0 -66
  303. package/dist/hooks/use-submit.d.ts.map +0 -1
  304. package/dist/hooks/use-submit.js +0 -35
  305. package/dist/soseki.d.ts +0 -42
  306. package/dist/soseki.d.ts.map +0 -1
  307. package/dist/soseki.js +0 -19
  308. package/dist/utils/get-action-id.d.ts +0 -8
  309. package/dist/utils/get-action-id.d.ts.map +0 -1
  310. package/dist/utils/get-action-id.js +0 -11
  311. package/dist/utils/href.d.ts +0 -11
  312. package/dist/utils/href.d.ts.map +0 -1
  313. package/dist/utils/href.js +0 -12
  314. package/dist/utils/redirect.d.ts +0 -11
  315. package/dist/utils/redirect.d.ts.map +0 -1
  316. package/dist/utils/redirect.js +0 -12
  317. package/dist/utils/route-index.d.ts +0 -41
  318. package/dist/utils/route-index.d.ts.map +0 -1
  319. package/dist/utils/route-index.js +0 -12
  320. package/dist/utils/route-route.d.ts +0 -62
  321. package/dist/utils/route-route.d.ts.map +0 -1
  322. package/dist/utils/route-route.js +0 -25
  323. package/dist/utils/set-action-id.d.ts +0 -9
  324. package/dist/utils/set-action-id.d.ts.map +0 -1
  325. package/dist/utils/set-action-id.js +0 -12
  326. package/src/components/action-id.tsx +0 -35
  327. package/src/components/hidden-input.tsx +0 -39
  328. package/src/core/_action-id-registry.ts +0 -11
  329. package/src/core/_capture-stack-trace.ts +0 -12
  330. package/src/core/_create-html-form-element-form-form-data.ts +0 -32
  331. package/src/core/_encode-pathname.ts +0 -17
  332. package/src/core/_is-error.ts +0 -16
  333. package/src/core/_is-promise-like.ts +0 -14
  334. package/src/core/_use-singleton.ts +0 -24
  335. package/src/core/_weak-id-registry.ts +0 -125
  336. package/src/core/constants.ts +0 -4
  337. package/src/core/data-map.types.ts +0 -28
  338. package/src/core/data-store.types.ts +0 -25
  339. package/src/core/deferred-promise.ts +0 -408
  340. package/src/core/start-actions.ts +0 -274
  341. package/src/hooks/_use-route-context.ts +0 -19
  342. package/src/hooks/_use-router-context.ts +0 -25
  343. package/src/hooks/use-pathname.ts +0 -10
  344. package/src/utils/get-action-id.ts +0 -12
  345. package/src/utils/href.ts +0 -17
  346. package/src/utils/route-index.ts +0 -70
  347. package/src/utils/route-route.ts +0 -111
  348. package/src/utils/set-action-id.ts +0 -14
  349. /package/dist/{core → src/core}/readonly-form-data.types.js +0 -0
  350. /package/dist/{core → src/core}/readonly-url.types.js +0 -0
  351. /package/dist/{core → src/core}/route.types.js +0 -0
  352. /package/dist/{engines → src/engines}/engine.types.js +0 -0
@@ -1,37 +1,43 @@
1
- import type { PathParams, Route } from "./route.types.js";
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: PathParams;
11
+ params: RoutePathParams;
11
12
  };
12
13
 
13
14
  /**
14
- * 指定されたルートの正規表現パターンを使用して、パス名がマッチするかどうかを判定します。
15
+ * 指定されたルートの正規表現パターンと URL のパス部分を照合し、マッチング検証およびパラメーター抽出を行う関数です。
15
16
  *
16
- * @param route 判定対象となる前処理済みのルートオブジェクトです。
17
- * @param pathname マッチングを行う対象のパス名(URL のパス部分)です。
18
- * @returns マッチした場合はパラメーターを含むオブジェクトを返し、マッチしない場合は `null` を返します。
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
- pathname: string,
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, value: string | undefined; i < route.paramKeys.length; i++) {
31
- value = matches[i + 1];
32
- if (value !== undefined) {
33
- // route.paramKeys のインデックスと matches のキャプチャーグループを対応させます。
34
- params[route.paramKeys[i]!] = value;
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 encodePathname from "./_encode-pathname.js";
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
- * @param defs 処理対象のルート定義の配列です。
10
- * @param prefix 親ルートから引き継いだパスのプレフィックスです。
11
- * @returns 変換後のルート配列です。
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 前処理が施された `Route` オブジェクトの配列を返します。
15
+ * @param routes ルーティング定義を格納した読み取り専用の配列です。
16
+ * @returns 読み取り専用の正規化済みルートオブジェクトの配列です。
53
17
  */
54
18
  export default function processRoutes(routes: readonly RouteDefinition[]): readonly Route[] {
55
- return processRoutesImpl(routes);
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
  }
@@ -1,45 +1,20 @@
1
- import isPromiseLike from "./_is-promise-like.js";
1
+ import { callFnOnce } from "call-fn-once";
2
2
 
3
- declare global {
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 | Awaited<T> {
21
- const cache = globalThis.soseki__singleton ||= new Map<unknown, any>();
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
  }
@@ -1,21 +1,26 @@
1
- import captureStackTrace from "./_capture-stack-trace.js";
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
- * 網羅性チェックを行うためのユーティリティー関数です。`never` 型の変数に予期せぬ値が代入された場合にエラーを投げます。
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(...args: [never?]): never {
17
- const error = new UnreachableError(args);
18
- captureStackTrace(error, unreachable);
21
+ function unreachable(...actual: [never?]): never {
22
+ const error = new UnreachableError({ actual });
23
+ tryCaptureStackTrace(error, unreachable);
19
24
  throw error;
20
25
  }
21
26
 
@@ -1,19 +1,7 @@
1
- import { type InferOutput, rawTransform, type RawTransformAction, safeParse } from "valibot";
2
- import captureStackTrace from "./_capture-stack-trace.js";
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
- * 指定されたスキーマに従って入力を検証し、失敗した場合は UnexpectedValidationError を投げます。
28
+ * 指定されたスキーマに基づいて入力値の構造を検証し、成功した場合は型安全に解析済みの値を出力します。
128
29
  *
129
- * @template TSchema 使用するスキーマの型です。
130
- * @param schema 検証に使用する Valibot スキーマです。
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(result.issues, input);
145
- captureStackTrace(error, expect);
44
+ const error = new UnexpectedValidationError({
45
+ value: input,
46
+ issues: result.issues,
47
+ });
48
+ tryCaptureStackTrace(error, expect);
146
49
  throw error;
147
50
  }