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,164 +1,60 @@
1
+ import { type ErrorMeta, type ErrorOptions, I18nErrorBase, setErrorMessage } from "i18n-error-base";
2
+ import { inspect } from "inspect-lite";
3
+ import { isThenable } from "maypromise";
1
4
  import getTypeName from "type-name";
2
- import { type BaseIssue, getGlobalConfig } from "valibot";
3
- import isPromiseLike from "./_is-promise-like.js";
4
- import singleton from "./_singleton.js";
5
+ import type { BaseIssue } from "valibot";
5
6
 
6
- /***************************************************************************************************
7
- *
8
- * 型
9
- *
10
- **************************************************************************************************/
11
-
12
- /**
13
- * エラーのオプションです。
14
- */
15
- export type ErrorOptions = Readonly<{
16
- /**
17
- * エラーの原因です。
18
- */
19
- cause?: unknown;
20
- }>;
21
-
22
- /**
23
- * エラーに紐づくメタデータです。
24
- */
25
- export type ErrorMeta = {
26
- readonly [prop: string]: unknown;
27
- };
28
-
29
- /**
30
- * soseki におけるエラーのコンストラクターです。
31
- */
32
- export interface ISosekiErrorConstructor {
33
- new(...args: any): ErrorBase<ErrorMeta | undefined>;
34
- }
35
-
36
- /**
37
- * 検証エラーの問題点です。
38
- */
39
- export type Issue = BaseIssue<unknown>;
40
-
41
- /***************************************************************************************************
42
- *
43
- * ユーティリティー
44
- *
45
- **************************************************************************************************/
7
+ /**************************************************************************************************/
46
8
 
47
- /**
48
- * エラーコンストラクターと言語ごとのエラーメッセージ作成関数のマップを取得します。
49
- *
50
- * @returns エラーコンストラクターと言語ごとのエラーメッセージ作成関数のマップです。
51
- */
52
- function getMessage(): WeakMap<Function | object, Map<string, (error: any) => string>> {
53
- return singleton("errors__message", () => new WeakMap());
54
- }
9
+ export type { ErrorMeta, ErrorOptions };
10
+ export { setErrorMessage };
55
11
 
56
- /**
57
- * エラーコンストラクター内でメッセージプロパティーを初期化します。
58
- *
59
- * @template TInstance エラーオブジェクトの型です。
60
- * @param instance エラーオブジェクトです。
61
- * @param message エラーメッセージです。
62
- */
63
- function initMessage<TInstance extends Error>(
64
- instance: TInstance,
65
- message: (error: TInstance) => string,
66
- ): void {
67
- const reference = instance.constructor;
68
- const { lang = "en" } = getGlobalConfig();
69
- const msg = getMessage();
70
- const store = msg.get(reference);
71
- const genMessage = store?.get(lang) ?? message;
72
- instance.message = genMessage(instance);
73
- }
12
+ /**************************************************************************************************/
74
13
 
75
14
  /**
76
- * soseki のエラーに特定の言語でエラーメッセージを設定します。
15
+ * データ検証の過程で検出された具体的な問題点を表す型定義です。
77
16
  *
78
- * @template TReference soseki のエラーコンストラクターの型です。
79
- * @param reference soseki のエラーコンストラクターです。
80
- * @param message エラーメッセージです。
81
- * @param lang 言語です。
82
- * @example
83
- * ```ts
84
- * setErrorMessage(
85
- * TypeError,
86
- * ({ meta }) => `${meta.expected} を期待しましたが、${meta.actual} を得ました`,
87
- * "ja",
88
- * );
89
- * ```
17
+ * 外部のスキーマ検証ライブラリーである `valibot` `BaseIssue` を基盤としています。
90
18
  */
91
- export function setErrorMessage<TReference extends ISosekiErrorConstructor>(
92
- reference: TReference,
93
- message: (error: InstanceType<TReference>) => string,
94
- lang: string,
95
- ): void {
96
- const msg = getMessage();
97
- let store = msg.get(reference);
98
- if (store === undefined) {
99
- store = new Map();
100
- msg.set(reference, store);
101
- }
19
+ export type Issue = BaseIssue<unknown>;
102
20
 
103
- store.set(lang, message);
104
- }
21
+ /**************************************************************************************************/
105
22
 
106
23
  /**
107
- * あらゆる値を文字列に整形します。
24
+ * soseki ルーティングライブラリーにおける、すべてのカスタムエラーの頂点に位置する基底クラスです。
108
25
  *
109
- * @param value 文字列に整形する値です。
110
- * @returns 文字列に整形された値です。
26
+ * @template TMeta エラーの発生コンテキストを保持するために紐付けるメタデータオブジェクトの型定義です。
111
27
  */
112
- function formatErrorValue(value: unknown): string {
113
- try {
114
- return JSON.stringify(value);
115
- } catch {
116
- return String(value);
117
- }
118
- }
28
+ export class ErrorBase<
29
+ TMeta extends ErrorMeta | undefined = undefined,
30
+ > extends I18nErrorBase<TMeta> {}
119
31
 
120
- /***************************************************************************************************
121
- *
122
- * エラークラス
123
- *
124
- **************************************************************************************************/
32
+ /**************************************************************************************************/
125
33
 
126
34
  /**
127
- * soseki エラーの基底クラスです。
128
- *
129
- * @template TMeta エラーに紐づくメタデータです。
35
+ * プログラムの制御フローにおいて、理論上到達しないはずのコード領域へ侵入した際に付与されるメタデータの型定義です。
130
36
  */
131
- export class ErrorBase<TMeta extends ErrorMeta | undefined = undefined> extends Error {
37
+ export type UnreachableErrorMeta = {
132
38
  /**
133
- * エラーのメタデータです。
39
+ * 網羅性チェックをすり抜けて、実行時に入り込んできた予期せぬ不正な値です。
134
40
  */
135
- public meta: Readonly<TMeta>;
41
+ readonly value?: unknown;
42
+ };
136
43
 
44
+ /**
45
+ * `UnreachableError` のインスタンスを初期化する際に渡される引数オブジェクトの型定義です。
46
+ */
47
+ export type UnreachableErrorArgs = ErrorOptions & {
137
48
  /**
138
- * @internal
49
+ * 網羅性検証において `never` 型となるべき変数を格納した、要素数 1 のタプルまたは空の配列です。
139
50
  */
140
- public constructor(options: ErrorOptions | undefined, meta: TMeta) {
141
- super("", options);
142
-
143
- if (!("cause" in this) && options && "cause" in options) {
144
- this.cause = options.cause;
145
- }
146
-
147
- this.meta = meta;
148
- }
149
- }
150
-
151
- /**************************************************************************************************/
51
+ readonly actual: [never?];
52
+ };
152
53
 
153
54
  /**
154
- * 到達不能なコードに到達した場合に投げられるエラーです。
55
+ * 網羅性チェックにおいて、プログラムの制御フローが理論上決して到達しないはずの場所に達した場合に投げるエラーです。
155
56
  */
156
- export class UnreachableError extends ErrorBase<{
157
- /**
158
- * 到達しないはずの値です。
159
- */
160
- value?: unknown;
161
- }> {
57
+ export class UnreachableError extends ErrorBase<UnreachableErrorMeta> {
162
58
  static {
163
59
  this.prototype.name = "SosekiUnreachableError";
164
60
  }
@@ -166,337 +62,143 @@ export class UnreachableError extends ErrorBase<{
166
62
  /**
167
63
  * `UnreachableError` クラスの新しいインスタンスを初期化します。
168
64
  *
169
- * @param args 到達しないはずの値があれば指定します。
170
- * @param options エラーのオプションです。
65
+ * @param args エラーオプションおよび実行時に混入した実際の値を含む引数オブジェクトです。
171
66
  */
172
- public constructor(args: [never?], options?: ErrorOptions | undefined) {
173
- super(options, args.length > 0 ? { value: args[0] } : {});
174
- initMessage(this, ({ meta }) => (
175
- "value" in meta
176
- ? "Encountered impossible value: " + formatErrorValue(meta.value)
177
- : "Unreachable code reached"
178
- ));
67
+ public constructor(args: UnreachableErrorArgs) {
68
+ const { actual, ...options } = args;
69
+ super(
70
+ actual.length > 0 ? { value: actual[0] } : {},
71
+ (meta) =>
72
+ "value" in meta
73
+ ? "Encountered impossible value: " + inspect(meta.value)
74
+ : "Unreachable code reached",
75
+ options,
76
+ );
179
77
  }
180
78
  }
181
79
 
182
80
  /*#__PURE__*/ setErrorMessage(
183
81
  UnreachableError,
184
- ({ meta }) => (
82
+ (meta) =>
185
83
  "value" in meta
186
- ? "不可能な値に遭遇しました: " + formatErrorValue(meta.value)
187
- : "到達できないコードに到達しました"
188
- ),
84
+ ? "不可能な値に遭遇しました: " + inspect(meta.value)
85
+ : "到達できないコードに到達しました",
189
86
  "ja",
190
87
  );
191
88
 
192
89
  /**************************************************************************************************/
193
90
 
194
91
  /**
195
- * 検証エラーの基底クラスです。
92
+ * データ検証の失敗に関連するエラーを集約するための共通基底クラスです。
196
93
  *
197
- * @template TMeta エラーに紐づくメタデータです。
94
+ * @template TMeta エラーに紐づく、検証結果の問題点などのメタデータ型定義です。
198
95
  */
199
- export class ValidationErrorBase<TMeta extends ErrorMeta> extends ErrorBase<TMeta> {
200
- /**
201
- * @internal
202
- */
203
- public constructor(options: ErrorOptions | undefined, meta: TMeta) {
204
- super(options, meta);
205
- }
206
- }
207
-
208
- /**************************************************************************************************/
209
-
210
- // /**
211
- // * 入力値検証エラーの基底クラスです。
212
- // *
213
- // * @template TMeta エラーに紐づくメタデータです。
214
- // */
215
- // export class InvalidInputErrorBase<TMeta extends ErrorMeta> extends ValidationErrorBase<TMeta> {
216
- // /**
217
- // * @internal
218
- // */
219
- // public constructor(options: ErrorOptions | undefined, meta: TMeta) {
220
- // super(options, meta);
221
- // }
222
- // }
223
-
224
- /**************************************************************************************************/
225
-
226
- // /**
227
- // * 入力値の検証に失敗した場合に投げられるエラーです。
228
- // */
229
- // export class InvalidInputError extends InvalidInputErrorBase<{
230
- // /**
231
- // * 検証エラーの問題点です。
232
- // */
233
- // issues: [Issue, ...Issue[]];
234
-
235
- // /**
236
- // * 検証した入力値です。
237
- // */
238
- // input: unknown;
239
- // }> {
240
- // static {
241
- // this.prototype.name = "SosekiInvalidInputError";
242
- // }
243
-
244
- // /**
245
- // * `InvalidInputError` クラスの新しいインスタンスを初期化します。
246
- // *
247
- // * @param issues 検証エラーの問題点です。
248
- // * @param input 検証した入力値です。
249
- // * @param options エラーのオプションです。
250
- // */
251
- // public constructor(
252
- // issues: [Issue, ...Issue[]],
253
- // input: unknown,
254
- // options?: ErrorOptions | undefined,
255
- // ) {
256
- // super(options, { issues, input });
257
- // this.message = issues.map(issue => issue.message).join(": ");
258
- // }
259
- // }
96
+ export class ValidationErrorBase<
97
+ TMeta extends ErrorMeta | undefined = ErrorMeta | undefined,
98
+ > extends ErrorBase<TMeta> {}
260
99
 
261
100
  /**************************************************************************************************/
262
101
 
263
102
  /**
264
- * 予期しない値に遭遇した場合に投げられるエラーです。
103
+ * 予期しないデータ構造や型に遭遇した際に付与される、検証エラー情報のメタデータ型定義です。
265
104
  */
266
- export class UnexpectedValidationError extends ValidationErrorBase<{
105
+ export type UnexpectedValidationErrorMeta = {
267
106
  /**
268
- * 検証エラーの問題点です。
107
+ * スキーマ検証によって不適合と判定された問題点のリストです。最低 1 つ以上の要素を持つことが保証された読み取り専用の配列です。
269
108
  */
270
- issues: [Issue, ...Issue[]];
109
+ readonly issues: readonly [Issue, ...Issue[]];
271
110
 
272
111
  /**
273
- * 予期しない値です。
112
+ * 検証の対象となった、予期しない生の入力値です。
274
113
  */
275
- value: unknown;
276
- }> {
277
- static {
278
- this.prototype.name = "SosekiUnexpectedValidationError";
279
- }
280
-
281
- /**
282
- * `UnexpectedValidationError` クラスの新しいインスタンスを初期化します。
283
- *
284
- * @param issues 検証エラーの問題点です。
285
- * @param value 予期しない値です。
286
- * @param options エラーのオプションです。
287
- */
288
- public constructor(
289
- issues: [Issue, ...Issue[]],
290
- value: unknown,
291
- options?: ErrorOptions | undefined,
292
- ) {
293
- super(options, { issues, value });
294
- this.message = issues.map(issue => issue.message).join(": ");
295
- }
296
- }
297
-
298
- /**************************************************************************************************/
114
+ readonly value: unknown;
115
+ };
299
116
 
300
117
  /**
301
- * shouldAction が不正な値を返した場合に投げられるエラーです。
118
+ * `UnexpectedValidationError` のインスタンスを初期化する際に渡される引数オブジェクトの型定義です。
302
119
  */
303
- export class ActionConditionError extends ErrorBase<{
304
- /**
305
- * ルートの URL です。
306
- */
307
- url: string;
308
-
309
- /**
310
- * shouldAction 関数です。
311
- */
312
- shouldAction: Function;
120
+ export type UnexpectedValidationErrorArgs = ErrorOptions & UnexpectedValidationErrorMeta;
313
121
 
314
- /**
315
- * shouldAction が返した値です。
316
- */
317
- returnValue: unknown;
318
- }> {
122
+ /**
123
+ * スキーマによるデータ構造の検証において、予期しない形式の値に遭遇した場合に投げるエラーです。
124
+ */
125
+ export class UnexpectedValidationError extends ValidationErrorBase<UnexpectedValidationErrorMeta> {
319
126
  static {
320
- this.prototype.name = "SosekiActionConditionError";
127
+ this.prototype.name = "SosekiUnexpectedValidationError";
321
128
  }
322
129
 
323
130
  /**
324
- * `ActionConditionError` クラスの新しいインスタンスを初期化します。
131
+ * `UnexpectedValidationError` クラスの新しいインスタンスを初期化します。
325
132
  *
326
- * @param url ルートの URL です。
327
- * @param shouldAction shouldAction 関数です。
328
- * @param returnValue shouldAction が返した値です。
329
- * @param options エラーのオプションです。
133
+ * @param args エラーオプション、入力値、および検出された不適合箇所の一覧を含む引数オブジェクトです。
330
134
  */
331
- public constructor(
332
- url: string,
333
- shouldAction: Function,
334
- returnValue: unknown,
335
- options?: ErrorOptions | undefined,
336
- ) {
337
- super(options, {
338
- url,
339
- returnValue,
340
- shouldAction,
341
- });
342
- initMessage(
343
- this,
344
- ({ meta }) =>
345
- isPromiseLike(meta.returnValue)
346
- ? "shouldAction must return a boolean value synchronously"
347
- : `Expected boolean, but got ${getTypeName(meta.returnValue) || "unknown"}`,
135
+ public constructor(args: UnexpectedValidationErrorArgs) {
136
+ const { value, issues, ...options } = args;
137
+ super(
138
+ { value, issues },
139
+ ({ issues }) => issues.map((issue) => issue.message).join(": "),
140
+ options,
348
141
  );
349
142
  }
350
143
  }
351
144
 
352
- /*#__PURE__*/ setErrorMessage(
353
- ActionConditionError,
354
- ({ meta }) =>
355
- isPromiseLike(meta.returnValue)
356
- ? "shouldAction は同期的に真偽値を返す必要があります"
357
- : `真偽値を期待しましたが、${getTypeName(meta.returnValue) || "unknown"} を得ました`,
358
- "ja",
359
- );
360
-
361
145
  /**************************************************************************************************/
362
146
 
363
147
  /**
364
- * 1 つ以上のアクションが失敗した際に投げられるエラーです。
148
+ * ブラウザー標準の Navigation API が、現在の実行環境でサポートされていない場合に投げるエラーです。
365
149
  */
366
- export class ActionExecutionError extends ErrorBase<{
367
- /**
368
- * ルートの URL です。
369
- */
370
- url: string;
371
-
372
- /**
373
- * エラーのリストです。
374
- */
375
- errors: readonly {
376
- /**
377
- * action 関数です。
378
- */
379
- readonly action: Function;
380
-
381
- /**
382
- * エラーの原因です。
383
- */
384
- readonly reason: unknown;
385
- }[];
386
- }> {
150
+ export class NavigationApiNotSupportedError extends ErrorBase<undefined> {
387
151
  static {
388
- this.prototype.name = "SosekiActionExecutionError";
152
+ this.prototype.name = "SosekiNavigationApiNotSupportedError";
389
153
  }
390
154
 
391
155
  /**
392
- * `ActionExecutionError` クラスの新しいインスタンスを初期化します。
156
+ * `NavigationApiNotSupportedError` クラスの新しいインスタンスを初期化します。
393
157
  *
394
- * @param url ルートの URL です。
395
- * @param errors エラーのリストです。
396
- * @param options エラーのオプションです。
158
+ * @param options エラーの共通オプションです。
397
159
  */
398
- public constructor(
399
- url: string,
400
- errors: readonly {
401
- /**
402
- * action 関数です。
403
- */
404
- action: Function;
405
-
406
- /**
407
- * エラーの原因です。
408
- */
409
- reason: unknown;
410
- }[],
411
- options?: ErrorOptions | undefined,
412
- ) {
413
- super(options, {
414
- url,
415
- errors,
416
- });
417
- initMessage(
418
- this,
419
- ({ meta }) => `Errors occurred in ${meta.errors.length} action(s)`,
420
- );
160
+ public constructor(options?: ErrorOptions) {
161
+ super("The Navigation API is not supported in this environment", options);
421
162
  }
422
163
  }
423
164
 
424
165
  /*#__PURE__*/ setErrorMessage(
425
- ActionExecutionError,
426
- ({ meta }) => `${meta.errors.length} 個のアクションでエラーが発生しました。`,
166
+ NavigationApiNotSupportedError,
167
+ "現在の環境では Navigation API がサポートされていません",
427
168
  "ja",
428
169
  );
429
170
 
430
171
  /**************************************************************************************************/
431
172
 
432
173
  /**
433
- * 複数のアクションからリダイレクトが返された際に投げられるエラーです。
174
+ * データの再読み込み判定において、不正なデータ型が検出された際に付与されるメタデータの型定義です。
434
175
  */
435
- export class MultipleRedirectError extends ErrorBase<{
176
+ export type LoaderConditionErrorMeta = {
436
177
  /**
437
- * ルートの URL です。
178
+ * エラーが発生した対象ルートの URL パス文字列です。
438
179
  */
439
- url: string;
180
+ readonly url: string;
440
181
 
441
182
  /**
442
- * 検出されたリダイレクト先パスのリストです。
183
+ * 不正な値を返した対象の `shouldReload` 関数の参照です。
443
184
  */
444
- redirects: readonly string[];
445
- }> {
446
- static {
447
- this.prototype.name = "SosekiMultipleRedirectError";
448
- }
185
+ readonly shouldReload: Function;
449
186
 
450
187
  /**
451
- * `MultipleRedirectError` クラスの新しいインスタンスを初期化します。
452
- *
453
- * @param url ルートの URL です。
454
- * @param redirects リダイレクト先パスのリストです。
455
- * @param options エラーのオプションです。
188
+ * `shouldReload` 関数が実際に返した、期待値とは異なるオブジェクトやプリミティブ値です。
456
189
  */
457
- public constructor(
458
- url: string,
459
- redirects: readonly string[],
460
- options?: ErrorOptions | undefined,
461
- ) {
462
- super(options, {
463
- url,
464
- redirects,
465
- });
466
- initMessage(
467
- this,
468
- ({ meta }) => `Multiple redirects detected: ${meta.redirects.join(", ")}`,
469
- );
470
- }
471
- }
472
-
473
- /*#__PURE__*/ setErrorMessage(
474
- MultipleRedirectError,
475
- ({ meta }) => `複数のリダイレクトが検出されました: ${meta.redirects.join(", ")}`,
476
- "ja",
477
- );
478
-
479
- /**************************************************************************************************/
190
+ readonly returnValue: unknown;
191
+ };
480
192
 
481
193
  /**
482
- * shouldLoader が不正な値を返した場合に投げられるエラーです。
194
+ * `LoaderConditionError` のインスタンスを初期化する際に渡される引数オブジェクトの型定義です。
483
195
  */
484
- export class LoaderConditionError extends ErrorBase<{
485
- /**
486
- * ルートの URL です。
487
- */
488
- url: string;
196
+ export type LoaderConditionErrorArgs = ErrorOptions & LoaderConditionErrorMeta;
489
197
 
490
- /**
491
- * shouldLoader 関数です。
492
- */
493
- shouldLoader: Function;
494
-
495
- /**
496
- * shouldLoader が返した値です。
497
- */
498
- returnValue: unknown;
499
- }> {
198
+ /**
199
+ * ユーザーが定義した `shouldReload` 関数が、仕様に準拠した同期的な真偽値ではなく、不正な値を返した場合に投げるエラーです。
200
+ */
201
+ export class LoaderConditionError extends ErrorBase<LoaderConditionErrorMeta> {
500
202
  static {
501
203
  this.prototype.name = "SosekiLoaderConditionError";
502
204
  }
@@ -504,84 +206,60 @@ export class LoaderConditionError extends ErrorBase<{
504
206
  /**
505
207
  * `LoaderConditionError` クラスの新しいインスタンスを初期化します。
506
208
  *
507
- * @param url ルートの URL です。
508
- * @param shouldLoader shouldLoader 関数です。
509
- * @param returnValue shouldLoader が返した値です。
510
- * @param options エラーのオプションです。
209
+ * @param args エラーオプション、対象URL、関数の参照、および実際の戻り値を含む引数オブジェクトです。
511
210
  */
512
- public constructor(
513
- url: string,
514
- shouldLoader: Function,
515
- returnValue: unknown,
516
- options?: ErrorOptions | undefined,
517
- ) {
518
- super(options, {
519
- url,
520
- returnValue,
521
- shouldLoader,
522
- });
523
- initMessage(
524
- this,
525
- ({ meta }) =>
526
- isPromiseLike(meta.returnValue)
527
- ? "shouldLoader must return a boolean value synchronously"
528
- : `Expected boolean, but got ${getTypeName(meta.returnValue) || "unknown"}`,
211
+ public constructor(args: LoaderConditionErrorArgs) {
212
+ const { url, returnValue, shouldReload, ...options } = args;
213
+ super(
214
+ { url, returnValue, shouldReload },
215
+ ({ returnValue }) =>
216
+ isThenable(returnValue)
217
+ ? "shouldReload must return a boolean value synchronously"
218
+ : `Expected boolean, but got ${getTypeName(returnValue) || "unknown"}`,
219
+ options,
529
220
  );
530
221
  }
531
222
  }
532
223
 
533
224
  /*#__PURE__*/ setErrorMessage(
534
225
  LoaderConditionError,
535
- ({ meta }) =>
536
- isPromiseLike(meta.returnValue)
537
- ? "shouldLoader は同期的に真偽値を返す必要があります"
538
- : `真偽値を期待しましたが、${getTypeName(meta.returnValue) || "unknown"} を得ました`,
226
+ ({ returnValue }) =>
227
+ isThenable(returnValue)
228
+ ? "shouldReload は同期的に真偽値を返す必要があります"
229
+ : `真偽値を期待しましたが、${getTypeName(returnValue) || "unknown"} を得ました`,
539
230
  "ja",
540
231
  );
541
232
 
542
233
  /**************************************************************************************************/
543
234
 
544
235
  /**
545
- * Navigation API が現在の環境でサポートされていない場合に投げられるエラーです。
236
+ * ルーター全体の共通状態 `RouterContext` が、React のコンポーネントツリー内の上位から供給されていない場合に投げるエラーです。
546
237
  */
547
- export class NavigationApiNotSupportedError extends ErrorBase<{
548
- /**
549
- * 現在のブラウザの UserAgent です。
550
- */
551
- userAgent: string;
552
- }> {
238
+ export class RouterContextMissingError extends ErrorBase<undefined> {
553
239
  static {
554
- this.prototype.name = "SosekiNavigationApiNotSupportedError";
240
+ this.prototype.name = "SosekiRouterContextMissingError";
555
241
  }
556
242
 
557
243
  /**
558
- * `NavigationApiNotSupportedError` クラスの新しいインスタンスを初期化します。
244
+ * `RouterContextMissingError` クラスの新しいインスタンスを初期化します。
559
245
  *
560
- * @param options エラーのオプションです。
246
+ * @param options エラーの共通オプションです。
561
247
  */
562
- public constructor(options?: ErrorOptions | undefined) {
563
- super(options, {
564
- userAgent: typeof window !== "undefined"
565
- ? window.navigator.userAgent
566
- : "unknown",
567
- });
568
- initMessage(
569
- this,
570
- () => "The Navigation API is not supported in this environment",
571
- );
248
+ public constructor(options?: ErrorOptions) {
249
+ super("RouterContext not found. Did you forget to wrap your app in <Router />?", options);
572
250
  }
573
251
  }
574
252
 
575
253
  /*#__PURE__*/ setErrorMessage(
576
- NavigationApiNotSupportedError,
577
- () => "現在の環境では Navigation API がサポートされていません",
254
+ RouterContextMissingError,
255
+ "RouterContext が見つかりません。アプリを <Router /> で囲むのを忘れていませんか?",
578
256
  "ja",
579
257
  );
580
258
 
581
259
  /**************************************************************************************************/
582
260
 
583
261
  /**
584
- * RouteContext が供給されていない場合に投げられるエラーです。
262
+ * 個々のルート固有の状態 `RouteContext` が、React のコンポーネントツリー内の上位から供給されていない場合に投げるエラーです。
585
263
  */
586
264
  export class RouteContextMissingError extends ErrorBase<undefined> {
587
265
  static {
@@ -591,66 +269,40 @@ export class RouteContextMissingError extends ErrorBase<undefined> {
591
269
  /**
592
270
  * `RouteContextMissingError` クラスの新しいインスタンスを初期化します。
593
271
  *
594
- * @param options エラーのオプションです。
272
+ * @param options エラーの共通オプションです。
595
273
  */
596
- public constructor(options?: ErrorOptions | undefined) {
597
- // メタデータは不要なため undefined を渡す
598
- super(options, undefined);
599
- initMessage(
600
- this,
601
- () => "RouteContext not found. Did you forget to wrap your app in <Router />?",
602
- );
274
+ public constructor(options?: ErrorOptions) {
275
+ super("RouteContext not found. Did you forget to wrap your app in <Router />?", options);
603
276
  }
604
277
  }
605
278
 
606
279
  /*#__PURE__*/ setErrorMessage(
607
280
  RouteContextMissingError,
608
- () => "RouteContext が見つかりません。アプリを <Router /> で囲むのを忘れていませんか?",
281
+ "RouteContext が見つかりません。アプリを <Router /> で囲むのを忘れていませんか?",
609
282
  "ja",
610
283
  );
611
284
 
612
285
  /**************************************************************************************************/
613
286
 
614
287
  /**
615
- * RouterContext が供給されていない場合に投げられるエラーです。
288
+ * ローダーデータの紛失を通知する際に付与されるメタデータの型定義です。
616
289
  */
617
- export class RouterContextMissingError extends ErrorBase<undefined> {
618
- static {
619
- this.prototype.name = "SosekiRouterContextMissingError";
620
- }
621
-
290
+ export type LoaderDataNotFoundErrorMeta = {
622
291
  /**
623
- * `RouterContextMissingError` クラスの新しいインスタンスを初期化します。
624
- *
625
- * @param options エラーのオプションです。
292
+ * データの取得を試みた対象のローダー関数の参照です。未定義の場合は `undefined` となることがあります。
626
293
  */
627
- public constructor(options?: ErrorOptions | undefined) {
628
- // メタデータは不要なため undefined を渡す
629
- super(options, undefined);
630
- initMessage(
631
- this,
632
- () => "RouterContext not found. Did you forget to wrap your app in <Router />?",
633
- );
634
- }
635
- }
636
-
637
- /*#__PURE__*/ setErrorMessage(
638
- RouterContextMissingError,
639
- () => "RouterContext が見つかりません。アプリを <Router /> で囲むのを忘れていませんか?",
640
- "ja",
641
- );
294
+ readonly loader: Function | undefined;
295
+ };
642
296
 
643
- /**************************************************************************************************/
297
+ /**
298
+ * `LoaderDataNotFoundError` のインスタンスを初期化する際に渡される引数オブジェクトの型定義です。
299
+ */
300
+ export type LoaderDataNotFoundErrorArgs = ErrorOptions & LoaderDataNotFoundErrorMeta;
644
301
 
645
302
  /**
646
- * ローダーに紐づくデータが見つからない場合に投げられるエラーです。
303
+ * ルートに紐づくデータ取得用のローダー関数が正常に処理されたはずであるにもかかわらず、該当するキャッシュデータや応答結果が見つからない場合に投げるエラーです。
647
304
  */
648
- export class LoaderDataNotFoundError extends ErrorBase<{
649
- /**
650
- * データが見つからなかった loader 関数です。
651
- */
652
- loader: Function;
653
- }> {
305
+ export class LoaderDataNotFoundError extends ErrorBase<LoaderDataNotFoundErrorMeta> {
654
306
  static {
655
307
  this.prototype.name = "SosekiLoaderDataNotFoundError";
656
308
  }
@@ -658,23 +310,26 @@ export class LoaderDataNotFoundError extends ErrorBase<{
658
310
  /**
659
311
  * `LoaderDataNotFoundError` クラスの新しいインスタンスを初期化します。
660
312
  *
661
- * @param loader データが見つからなかった loader 関数です。
662
- * @param options エラーのオプションです。
313
+ * @param args エラーオプションおよび対象ローダー関数の参照を含む引数オブジェクトです。
663
314
  */
664
- public constructor(
665
- loader: Function,
666
- options?: ErrorOptions | undefined,
667
- ) {
668
- super(options, { loader });
669
- initMessage(
670
- this,
671
- ({ meta }) => `Loader data not found (Loader: ${meta.loader.name || "anonymous"})`,
315
+ public constructor(args: LoaderDataNotFoundErrorArgs) {
316
+ const { loader, ...options } = args;
317
+ super(
318
+ { loader },
319
+ ({ loader }) =>
320
+ loader
321
+ ? `Loader data not found (Function name: ${loader.name || "anonymous"})`
322
+ : "Loader is undefined",
323
+ options,
672
324
  );
673
325
  }
674
326
  }
675
327
 
676
328
  /*#__PURE__*/ setErrorMessage(
677
329
  LoaderDataNotFoundError,
678
- ({ meta }) => `ローダーデータが見つかりません(Loader: ${meta.loader.name || "匿名"})`,
330
+ ({ loader }) =>
331
+ loader
332
+ ? `ローダーデータが見つかりません(関数名: ${loader.name || "匿名"})`
333
+ : "ローダーが未定義です。",
679
334
  "ja",
680
335
  );