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.
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,351 +1,375 @@
1
1
  import type * as React from "react";
2
- import type { RouteParams } from "regexparam";
2
+
3
3
  import type { ReadonlyURL } from "./readonly-url.types.js";
4
- import type RouteRequest from "./route-request.js";
4
+ import type { RouteGetRequest, RoutePostRequest } from "./route-request.js";
5
5
 
6
6
  /**
7
- * パスパラメーターの内部的な型定義です。
7
+ * 個別のパスパラメーターを解析し、適切なプロパティーの型オブジェクトへと変換する内部ユーティリティー型です。
8
+ *
9
+ * パラメーターの末尾の形状を条件付き型により詳細に選別します。
8
10
  *
9
- * @template TParams `regexparam` から抽出されたパラメーターの型です。
11
+ * @template Param 解析対象となる単一のパラメーター文字列です。
10
12
  */
11
- // dprint-ignore
12
- type PathParams_<TParams extends { [_ in string]?: string }> =
13
- [keyof TParams] extends [never]
14
- ? { readonly [_ in string]?: string }
15
- : Readonly<TParams>
13
+ // oxfmt-ignore
14
+ type ParamRecord<Param extends string> =
15
+ // パラメーター末尾に「?」がある場合、オプショナルなプロパティー型に変換します
16
+ Param extends `${infer Name}?`
17
+ ? { [K in Name]?: string }
18
+
19
+ // パラメーターに拡張子が含まれている場合、拡張子を除いた名前を必須のプロパティー型に変換します。
20
+ : Param extends `${infer Name}.${string}`
21
+ ? { [K in Name]: string }
22
+
23
+ // 上記のいずれのパターンにも該当しない場合は、パラメーター名をそのまま必須のプロパティー型に変換します。
24
+ : { [K in Param]: string };
16
25
 
17
26
  /**
18
- * 指定されたパス文字列からパラメーターを抽出するための型定義です。
27
+ * パス文字列のセグメントから動的なパラメーターやワイルドカードを再帰的に抽出し、型安全なオブジェクト構造を構築するユーティリティー型です。
19
28
  *
20
- * @template TPath 解析対象となるパス文字列の型です。
29
+ * 開発者が指定した文字列リテラル型の形状に基づいて、ルーティングに必要なパラメーターの型を静的に決定します。
30
+ *
31
+ * このユーティリティー型は、ライブラリー `regexparam` の改良版です。
32
+ *
33
+ * @template T 解析対象となる URL パス全体の文字列リテラル型です。
34
+ * @see https://github.com/lukeed/regexparam
35
+ * @see https://github.com/lukeed/regexparam/issues/31
36
+ * @see https://github.com/lukeed/regexparam/pull/33
21
37
  */
22
- export type PathParams<TPath extends string = string> = PathParams_<RouteParams<TPath>>;
38
+ // oxfmt-ignore
39
+ type RouteParams<T extends string> =
40
+ // 与えられた型が具体的なリテラルでなく文字列型である場合は、汎用的なレコード型へとフォールバックします。
41
+ string extends T
42
+ ? { [K in string]?: string }
43
+
44
+ // パスの中間にワイルドカードが存在する場合、前後のパラメーターに加えて、必須のワイルドカードプロパティーを結合します。
45
+ : T extends `${infer Prev}/*/${infer Rest}`
46
+ ? & RouteParams<Prev>
47
+ & { wild: string }
48
+ & RouteParams<`/${Rest}`>
49
+
50
+ // パスの先頭がコロンで開始されている場合、先頭にスラッシュ(/)を補正して再帰的に再評価します。
51
+ : T extends `:${infer Rest}`
52
+ ? RouteParams<`/:${Rest}`>
53
+
54
+ // パスの中間にコロンで始まるパラメーターが含まれている場合、そのセグメントの型情報を抽出し、スラッシュ以降の残りのパスの解析結果と交差型で結合します。
55
+ : T extends `${string}:${infer Param}/${infer Rest}`
56
+ ? & ParamRecord<Param>
57
+ & RouteParams<`/${Rest}`>
58
+
59
+ // パスの末尾がコロンで始まるパラメーターで終了している場合、そのセグメントの型情報を判定して抽出を完了します。
60
+ : T extends `${string}/:${infer Param}`
61
+ ? ParamRecord<Param>
62
+
63
+ // パスの末尾がオプショナルワイルドカードで終了している場合、キー名を「"*"」としたオプショナルなプロパティー型を返します。
64
+ : T extends `${string}/*?`
65
+ ? { "*"?: string }
66
+
67
+ // パスの末尾が通常のワイルドカードで終了している場合、キー名を「"*"」とした必須のプロパティー型を返します。
68
+ : T extends `${string}/*`
69
+ ? { "*": string }
70
+
71
+ // 抽出可能なパラメーターやワイルドカードが一切検出されなかった場合は、空のオブジェクト型を返します。
72
+ : {};
23
73
 
24
74
  /**
25
- * アクションを実行すべきかどうかを判定する関数(`shouldAction`)に渡される引数の型定義です。
75
+ * 文字列リテラルとして定義されたパスの形状から、含まれるパスパラメーターを解析し、静的に型付けされたオブジェクトとして抽出する型定義です。
26
76
  *
27
- * @template TPath パス文字列の型です。
77
+ * @template TRoutePath パラメーター抽出の対象となるパス文字列リテラル型です。
28
78
  */
29
- export type ShouldActionArgs<TPath extends string = string> = {
30
- /**
31
- * URL から抽出されたパスパラメーターのオブジェクトです。
32
- */
33
- params: PathParams<TPath>;
79
+ export type RoutePathParams<TRoutePath extends string = string> = Readonly<RouteParams<TRoutePath>>;
34
80
 
81
+ /**
82
+ * データ更新などのアクション処理を実行する際に、該当する関数へ渡される引数の型定義です。
83
+ *
84
+ * 解析済みのパスパラメーターと、HTTP の POST メソッドを抽象化したリクエストオブジェクトを含みます。
85
+ *
86
+ * @template TRoutePath 対象となるルートのパス文字列リテラル型です。
87
+ */
88
+ export type ActionFunctionArgs<TRoutePath extends string = string> = {
35
89
  /**
36
- * ルーティングに関するリクエスト情報です。
90
+ * 現在の URL パスから抽出されたパラメーターオブジェクトです。
37
91
  */
38
- request: RouteRequest;
92
+ params: RoutePathParams<TRoutePath>;
39
93
 
40
94
  /**
41
- * デフォルトのルールに基づいた判定結果です。
95
+ * フォームデータなどを内包する、HTTP の POST メソッドに特化したルーティングリクエストオブジェクトです。
42
96
  */
43
- defaultShouldAction: boolean;
97
+ request: RoutePostRequest;
44
98
  };
45
99
 
46
100
  /**
47
- * 特定の条件でアクションを実行するかどうかを制御するインターフェースです。
101
+ * データの登録、更新、削除といった副作用を伴うアクション処理を定義するための関数インターフェースです。
48
102
  *
49
- * @template TPath パス文字列の型です。
103
+ * @template TRoutePath 対象となるルートのパス文字列リテラル型です。
104
+ * @template TData アクション関数が返す戻り値の型定義です。既定値は `unknown` です。
50
105
  */
51
- export interface IShouldAction<TPath extends string = string> {
52
- /**
53
- * アクションの実行可否を判定します。
54
- *
55
- * @param args 判定に必要なパラメーターとリクエスト情報です。
56
- * @returns アクションを実行する場合は `true`、そうでない場合は `false` を返します。
57
- */
58
- (args: ShouldActionArgs<TPath>): boolean;
106
+ export interface ActionFunction<TRoutePath extends string = string, TData = unknown> {
107
+ (args: ActionFunctionArgs<TRoutePath>): TData;
59
108
  }
60
109
 
61
110
  /**
62
- * アクション関数(`action`)に渡される引数の型定義です。
111
+ * ページ遷移やデータ更新が発生した際、現在の画面データを再読み込みすべきかどうかを判定する関数へ渡される引数の型定義です。
112
+ *
113
+ * アクションを実行した契機となる HTTP メソッドの種類(GET / POST)に応じて、含まれるコンテキスト情報が分岐します。
63
114
  *
64
- * @template TPath パス文字列の型です。
115
+ * @template TRoutePath 対象となるルートのパス文字列リテラル型です。
65
116
  */
66
- export type ActionArgs<TPath extends string = string> = {
67
- /**
68
- * URL から抽出されたパスパラメーターのオブジェクトです。
69
- */
70
- params: PathParams<TPath>;
71
-
72
- /**
73
- * ルーティングに関するリクエスト情報です。
74
- */
75
- request: RouteRequest;
76
- };
117
+ export type ShouldReloadFunctionArgs<TRoutePath extends string = string> =
118
+ | {
119
+ /**
120
+ * 再読み込みを引き起こした HTTP メソッドの種別です。
121
+ */
122
+ triggerMethod: "GET";
123
+
124
+ /**
125
+ * 現在の画面に対応する読み取り専用 URL オブジェクトです。
126
+ */
127
+ currentUrl: ReadonlyURL;
128
+
129
+ /**
130
+ * 現在の URL から抽出されたパスパラメーターです。
131
+ */
132
+ currentParams: RoutePathParams<TRoutePath>;
133
+
134
+ /**
135
+ * POST リクエストが発生する直前の読み取り専用 URL オブジェクトです。
136
+ */
137
+ prevUrl: ReadonlyURL;
138
+
139
+ /**
140
+ * POST リクエストが発生する直前の URL から抽出されたパスパラメーターです。
141
+ */
142
+ prevParams: RoutePathParams;
143
+
144
+ /**
145
+ * システムが内部ロジックに基づいて判断した、再読み込み実行の既定の判定フラグです。
146
+ */
147
+ defaultShouldReload: boolean;
148
+ }
149
+ | {
150
+ /**
151
+ * 再読み込みを引き起こした HTTP メソッドの種別です。
152
+ */
153
+ triggerMethod: "POST";
154
+
155
+ /**
156
+ * 現在の画面に対応する読み取り専用 URL オブジェクトです。
157
+ */
158
+ currentUrl: ReadonlyURL;
159
+
160
+ /**
161
+ * 現在の URL から抽出されたパスパラメーターです。
162
+ */
163
+ currentParams: RoutePathParams<TRoutePath>;
164
+
165
+ /**
166
+ * POST リクエストが発生する直前の読み取り専用 URL オブジェクトです。
167
+ */
168
+ prevUrl: ReadonlyURL;
169
+
170
+ /**
171
+ * POST リクエストが発生する直前の URL から抽出されたパスパラメーターです。
172
+ */
173
+ prevParams: RoutePathParams;
174
+
175
+ /**
176
+ * POST リクエストと共に送信された標準のフォームデータオブジェクトです。
177
+ */
178
+ formData: FormData;
179
+
180
+ /**
181
+ * 直前に実行されたアクション関数から返されたデータです。
182
+ */
183
+ actionData: unknown;
184
+
185
+ /**
186
+ * システムが内部ロジックに基づいて判断した、再読み込み実行の既定の判定フラグです。
187
+ */
188
+ defaultShouldReload: boolean;
189
+ };
77
190
 
78
191
  /**
79
- * データの更新処理などを行うアクション関数のインターフェースです。
192
+ * ルートデータの再読み込みが不必要な場合に、余分な通信や再取得処理を抑制するための判定関数インターフェースです。
80
193
  *
81
- * @template TPath パス文字列の型です。
82
- * @template TData アクションが返すデータの型です。
194
+ * @template TRoutePath 対象となるルートのパス文字列リテラル型です。
195
+ * @returns データを再読み込みする場合は `true`、スキップする場合は `false` を返します。
83
196
  */
84
- export interface IAction<TPath extends string = string, TData = unknown> {
85
- /**
86
- * 指定された引数に基づいてアクションを実行します。
87
- *
88
- * @param args アクションの実行に必要なパラメーターとリクエスト情報です。
89
- * @returns 処理結果として任意のデータを返します。
90
- */
91
- (args: ActionArgs<TPath>): TData;
197
+ export interface ShouldReloadFunction<TRoutePath extends string = string> {
198
+ (args: ShouldReloadFunctionArgs<TRoutePath>): boolean;
92
199
  }
93
200
 
94
201
  /**
95
- * データの再読み込み(リロード)を行うべきかどうかを判定する関数に渡される引数の型定義です。
202
+ * 画面の描画に必要なデータを取得(ロード)する際に、該当する関数へ渡される引数の型定義です。
96
203
  *
97
- * GET リクエスト時と POST リクエスト時で異なるプロパティーを持ちます。
204
+ * 解析済みのパスパラメーターと、HTTP GET メソッドを抽象化したリクエストオブジェクトを含みます。
98
205
  *
99
- * @template TPath 現在のパス文字列の型です。
206
+ * @template TRoutePath 対象となるルートのパス文字列リテラル型です。
100
207
  */
101
- export type ShouldReloadArgs<TPath extends string = string> = {
208
+ export type LoaderFunctionArgs<TRoutePath extends string = string> = {
102
209
  /**
103
- * 最読み込みをトリガーしたリクエストメソッドです。
210
+ * 現在の URL パスから抽出されたパラメーターオブジェクトです。
104
211
  */
105
- triggerMethod: "GET";
212
+ params: RoutePathParams<TRoutePath>;
106
213
 
107
214
  /**
108
- * 現在の URL オブジェクトです。
215
+ * HTTP GET メソッドに特化したルーティングリクエストオブジェクトです。
109
216
  */
110
- currentUrl: ReadonlyURL;
111
-
112
- /**
113
- * 現在のパスパラメーターです。
114
- */
115
- currentParams: PathParams<TPath>;
116
-
117
- /**
118
- * 遷移前の URL オブジェクトです。
119
- */
120
- prevUrl: ReadonlyURL;
121
-
122
- /**
123
- * 遷移前のパスパラメーターです。
124
- */
125
- prevParams: PathParams;
126
-
127
- /**
128
- * 送信されたフォームデータです。GET 時は常にありません。
129
- */
130
- formData?: undefined;
131
-
132
- /**
133
- * 直前に行われたアクションの結果です。GET 時は常にありません。
134
- */
135
- actionResult?: undefined;
136
-
137
- /**
138
- * デフォルトのルールに基づいた判定結果です。
139
- */
140
- defaultShouldReload: boolean;
141
- } | {
142
- /**
143
- * 最読み込みをトリガーしたリクエストメソッドです。
144
- */
145
- triggerMethod: "POST";
217
+ request: RouteGetRequest;
218
+ };
146
219
 
147
- /**
148
- * 現在の URL オブジェクトです。
149
- */
150
- currentUrl: ReadonlyURL;
220
+ /**
221
+ * 画面の初期描画時や遷移時にデータをオンデマンドで取得するための関数インターフェースです。
222
+ *
223
+ * @template TRoutePath 対象となるルートのパス文字列リテラル型です。
224
+ * @template TData ローダー関数が返す戻り値の型定義です。既定値は `unknown` です。
225
+ */
226
+ export interface LoaderFunction<TRoutePath extends string = string, TData = unknown> {
227
+ (args: LoaderFunctionArgs<TRoutePath>): TData;
228
+ }
151
229
 
230
+ /**
231
+ * アプリケーションのルーティング設定を定義するためのオブジェクトの型定義です。
232
+ *
233
+ * 開発者が宣言的にルーティングのツリーやリストを記述する際に使用します。
234
+ *
235
+ * @template TPath ルートに関連付けるパス文字列リテラル型です。
236
+ */
237
+ export type RouteDefinitionObject<TPath extends string = string> = {
152
238
  /**
153
- * 現在のパスパラメーターです。
239
+ * マッチングの対象となる URL パスのパターン文字列です。
154
240
  */
155
- currentParams: PathParams<TPath>;
241
+ readonly path: TPath;
156
242
 
157
243
  /**
158
- * 遷移前の URL オブジェクトです。
244
+ * 親ルートのパスにおいて、インデックスルートとして機能させるかどうかのフラグです。
159
245
  */
160
- prevUrl: ReadonlyURL;
246
+ readonly index?: boolean | undefined;
161
247
 
162
248
  /**
163
- * 遷移前のパスパラメーターです。
249
+ * このルートで実行されるデータ更新用のアクション関数です。
164
250
  */
165
- prevParams: PathParams;
251
+ readonly action?: ActionFunction<TPath> | undefined;
166
252
 
167
253
  /**
168
- * 送信されたフォームデータです。
254
+ * このルートのデータ再読み込み動作を制御する判定関数です。
169
255
  */
170
- formData: FormData;
256
+ readonly shouldReload?: ShouldReloadFunction<TPath> | undefined;
171
257
 
172
258
  /**
173
- * 直前に行われたアクションの結果です。
259
+ * このルートの画面描画に必要なデータを取得する関数です。
174
260
  */
175
- actionResult?: unknown;
261
+ readonly loader?: LoaderFunction<TPath> | undefined;
176
262
 
177
263
  /**
178
- * デフォルトのルールに基づいた判定結果です。
264
+ * このルートに対応して描画される React のコンポーネントです。
179
265
  */
180
- defaultShouldReload: boolean;
266
+ readonly component?: React.ComponentType<{}> | undefined;
181
267
  };
182
-
183
268
  /**
184
- * データの再読み込みが必要かどうかを判定するインターフェースです。
269
+ * ルーティング設定をインポート経由で定義するための構造体型定義です。
185
270
  *
186
- * @template TPath パス文字列の型です。
271
+ * @template TPath ルートに関連付けるパス文字列リテラル型です。
187
272
  */
188
- export interface IShouldReload<TPath extends string = string> {
273
+ export type RouteDefinitionModule<TPath extends string = string> = {
189
274
  /**
190
- * 再読み込みの要否を判定します。
191
- *
192
- * @param args 遷移先後やアクションの結果を含む判定用データです。
193
- * @returns 再読み込みを行う場合は `true`、そうでない場合は `false` を返します。
275
+ * マッチングの対象となる URL パスのパターン文字列です。
194
276
  */
195
- (args: ShouldReloadArgs<TPath>): boolean;
196
- }
277
+ readonly path: TPath;
197
278
 
198
- /**
199
- * ローダー関数(`loader`)に渡される引数の型定義です。
200
- *
201
- * @template TPath パス文字列の型です。
202
- */
203
- export type LoaderArgs<TPath extends string = string> = {
204
279
  /**
205
- * URL から抽出されたパスパラメーターのオブジェクトです。
280
+ * 親ルートのパスにおいて、インデックスルートとして機能させるかどうかのフラグです。
206
281
  */
207
- params: PathParams<TPath>;
282
+ readonly index?: boolean | undefined;
208
283
 
209
284
  /**
210
- * ルーティングに関するリクエスト情報です。
285
+ * このルートで実行されるデータ更新用のアクション関数です。
211
286
  */
212
- request: RouteRequest;
213
- };
287
+ readonly action?: ActionFunction<TPath> | undefined;
214
288
 
215
- /**
216
- * データを取得するためのローダー関数のインターフェースです。
217
- *
218
- * @template TPath パス文字列の型です。
219
- * @template TData ローダーが取得するデータの型です。
220
- */
221
- export interface ILoader<TPath extends string = string, TData = unknown> {
222
289
  /**
223
- * 指定された引数に基づいてデータを読み込みます。
224
- *
225
- * @param args データ取得に必要なパラメーターとリクエスト情報です。
226
- * @returns 取得したデータを返します。
290
+ * このルートのデータ再読み込み動作を制御する判定関数です。
227
291
  */
228
- (args: LoaderArgs<TPath>): TData;
229
- }
292
+ readonly shouldReload?: ShouldReloadFunction<TPath> | undefined;
230
293
 
231
- /**
232
- * ルートに紐づくデータ処理用の関数群をまとめたオブジェクトの型定義です。
233
- *
234
- * @template TPath パス文字列の型です。
235
- */
236
- export type DataFunctionObject<TPath extends string = string> = {
237
294
  /**
238
- * アクションを実行すべきか判定するオプションの関数です。
295
+ * このルートの画面描画に必要なデータを取得する関数です。
239
296
  */
240
- readonly shouldAction?: IShouldAction<TPath> | undefined;
297
+ readonly loader?: LoaderFunction<TPath> | undefined;
241
298
 
242
299
  /**
243
- * データの更新などを行うオプションのアクション関数です。
300
+ * このルートに対応して描画される React のコンポーネントです。
301
+ *
302
+ * `default` プロパティーよりこちらが優先されます。
244
303
  */
245
- readonly action?: IAction<TPath> | undefined;
304
+ readonly component?: React.ComponentType<{}> | undefined;
246
305
 
247
306
  /**
248
- * データを再読み込みすべきか判定するオプションの関数です。
307
+ * ES モジュールのデフォルトエクスポートとして定義された、描画対象となる React のコンポーネントです。
308
+ *
309
+ * `component` プロパティーがない場合はこちらにフォールバックされます。
249
310
  */
250
- readonly shouldReload?: IShouldReload<TPath> | undefined;
311
+ readonly default?: React.ComponentType<{}> | undefined;
251
312
 
252
313
  /**
253
- * データを取得するオプションのローダー関数です。
314
+ * オブジェクトの文字列表現をカスタマイズするための組み込みタグプロパティーです。
315
+ *
316
+ * モジュールオブジェクトとしての識別に使用します。
254
317
  */
255
- readonly loader?: ILoader<TPath> | undefined;
318
+ get [Symbol.toStringTag](): string;
256
319
  };
257
320
 
258
321
  /**
259
- * ルーティングの定義を表す型定義です。
322
+ * アプリケーションのルーティング設定を定義するためのオブジェクトの型定義です。
260
323
  *
261
- * @template TPath パス文字列の型です。
324
+ * @template TPath ルートに関連付けるパス文字列リテラル型です。
262
325
  */
263
- export type RouteDefinition<TPath extends string = string> = {
264
- /**
265
- * ルートのパス(パスパターン)です。
266
- */
267
- readonly path: TPath;
268
-
269
- /**
270
- * このルートで使用するデータ操作関数の配列です。
271
- */
272
- readonly dataFunctions?: readonly DataFunctionObject<TPath>[] | undefined;
273
-
274
- /**
275
- * このルートで描画される React コンポーネントです。
276
- */
277
- readonly component?: React.ComponentType<{}> | undefined;
278
-
279
- /**
280
- * 子ルートの定義リストです。
281
- */
282
- readonly children?: readonly RouteDefinition[] | undefined;
283
- };
326
+ export type RouteDefinition<TPath extends string = string> =
327
+ | RouteDefinitionObject<TPath>
328
+ | RouteDefinitionModule<TPath>;
284
329
 
285
330
  /**
286
- * ルート情報を表す型定義です。
331
+ * `RouteDefinition` を基にシステム内部で解析・コンパイルされ、ルーティングエンジンが直接処理を行うための実体化されたルートオブジェクトの型定義です。
332
+ *
333
+ * 省略可能だったプロパティーが正規化され、正規表現によるマッチング機構が追加されています。
287
334
  */
288
335
  export type Route = {
289
336
  /**
290
- * 正規化されたルートのパス(パスパターン)です。
337
+ * マッチングの対象となる URL パスのパターン文字列です。
291
338
  */
292
339
  readonly path: string;
293
340
 
294
341
  /**
295
- * このルートがインデックスルート(子ルートを持たない末端のルート)かどうかを示します。
342
+ * インデックスルートであるかどうかの確定的なフラグです。
296
343
  */
297
344
  readonly index: boolean;
298
345
 
299
346
  /**
300
- * パスマッチングに使用される正規表現オブジェクトです。
347
+ * 実際の URL パスがこのルートに合致するかを検証するために動的に生成された正規表現オブジェクトです。
301
348
  */
302
349
  readonly pathPattern: RegExp;
303
350
 
304
351
  /**
305
- * パスから抽出されたパラメーター名の配列です。
352
+ * パスパターン内に含まれるパラメーターのキー名を、順番通りに格納した読み取り専用の配列です。
306
353
  */
307
354
  readonly paramKeys: readonly string[];
308
355
 
309
356
  /**
310
- * このルートに紐づくデータ操作関数群の配列です。
311
- *
312
- * デフォルトの判定関数などが補完された状態で保持されます。
357
+ * データ更新用のアクション関数です。未定義の場合は `undefined` となります。
313
358
  */
314
- readonly dataFuncs: readonly {
315
- /**
316
- * アクションの実行可否を判定します。
317
- *
318
- * @param args 判定に必要なパラメーターとリクエスト情報です。
319
- * @returns アクションを実行する場合は `true`、そうでない場合は `false` を返すはずです。
320
- */
321
- readonly shouldAction: (args: ShouldActionArgs) => unknown;
322
-
323
- /**
324
- * データの更新などを行うオプションのアクション関数です。
325
- */
326
- readonly action: IAction | undefined;
327
-
328
- /**
329
- * 再読み込みの要否を判定します。
330
- *
331
- * @param args 遷移先後やアクションの結果を含む判定用データです。
332
- * @returns 再読み込みを行う場合は `true`、そうでない場合は `false` を返すはずです。
333
- */
334
- readonly shouldReload: (args: ShouldReloadArgs) => unknown;
335
-
336
- /**
337
- * データを取得するオプションのローダー関数です。
338
- */
339
- readonly loader: ILoader | undefined;
340
- }[];
359
+ readonly action: ActionFunction | undefined;
341
360
 
342
361
  /**
343
- * このルートで描画される React コンポーネントです。
362
+ * データの再読み込み動作を制御する確定的な判定関数です。定義がない場合はシステム既定の挙動を行う関数が割り当てられます。
344
363
  */
345
- readonly component: React.ComponentType<{}> | undefined;
364
+ readonly shouldReload: ShouldReloadFunction;
365
+
366
+ /**
367
+ * 画面描画に必要なデータを取得する関数です。未定義の場合は `undefined` となります。
368
+ */
369
+ readonly loader: LoaderFunction | undefined;
346
370
 
347
371
  /**
348
- * 前処理済みの子ルートの配列です。
372
+ * 表示対象となる React のコンポーネントです。未定義の場合は `undefined` となります。
349
373
  */
350
- readonly children: readonly Route[];
374
+ readonly component: React.ComponentType<{}> | undefined;
351
375
  };