functionalscript 0.44.0 → 0.46.0

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 (571) hide show
  1. package/README.md +5 -3
  2. package/fjs/asn.1/module.f.mjs +8 -1
  3. package/fjs/asn.1/proof.f.d.mts +15 -0
  4. package/fjs/asn.1/proof.f.mjs +31 -3
  5. package/fjs/asserts/module.f.d.mts +14 -0
  6. package/fjs/asserts/module.f.mjs +20 -0
  7. package/fjs/asserts/proof.f.d.mts +3 -0
  8. package/fjs/asserts/proof.f.mjs +15 -1
  9. package/fjs/basen/base128/module.f.mjs +22 -5
  10. package/fjs/basen/base128/proof.f.d.mts +3 -1
  11. package/fjs/basen/base128/proof.f.mjs +3 -1
  12. package/fjs/basen/base64/module.f.mjs +7 -3
  13. package/fjs/basen/base64/proof.f.d.mts +3 -1
  14. package/fjs/basen/base64/proof.f.mjs +7 -4
  15. package/fjs/basen/cbase32/proof.f.d.mts +3 -1
  16. package/fjs/basen/cbase32/proof.f.mjs +3 -1
  17. package/fjs/bnf/data/module.f.d.mts +32 -6
  18. package/fjs/bnf/data/module.f.mjs +112 -7
  19. package/fjs/bnf/data/proof.f.d.mts +2 -0
  20. package/fjs/bnf/data/proof.f.mjs +74 -4
  21. package/fjs/bnf/data/types.d.ts +20 -2
  22. package/fjs/bnf/descent/module.f.d.mts +34 -5
  23. package/fjs/bnf/descent/module.f.mjs +176 -54
  24. package/fjs/bnf/descent/proof.f.d.mts +3 -0
  25. package/fjs/bnf/descent/proof.f.mjs +189 -27
  26. package/fjs/bnf/descent/types.d.ts +24 -18
  27. package/fjs/bnf/ll1/module.f.d.mts +74 -6
  28. package/fjs/bnf/ll1/module.f.mjs +297 -95
  29. package/fjs/bnf/ll1/proof.f.d.mts +17 -2
  30. package/fjs/bnf/ll1/proof.f.mjs +372 -137
  31. package/fjs/bnf/ll1/types.d.ts +25 -27
  32. package/fjs/bnf/matcher/module.f.d.mts +66 -0
  33. package/fjs/bnf/matcher/module.f.mjs +81 -0
  34. package/fjs/bnf/matcher/proof.f.d.mts +10 -0
  35. package/fjs/bnf/matcher/proof.f.mjs +79 -0
  36. package/fjs/bnf/matcher/types.d.ts +54 -0
  37. package/fjs/bnf/module.f.d.mts +15 -6
  38. package/fjs/bnf/module.f.mjs +52 -11
  39. package/fjs/bnf/proof.f.d.mts +2 -0
  40. package/fjs/bnf/proof.f.mjs +79 -3
  41. package/fjs/bnf/testlib.f.d.mts +31 -0
  42. package/fjs/bnf/testlib.f.mjs +80 -0
  43. package/fjs/bnf/token_symbol/module.f.d.mts +4 -3
  44. package/fjs/bnf/token_symbol/module.f.mjs +7 -6
  45. package/fjs/bnf/token_symbol/proof.f.mjs +5 -2
  46. package/fjs/bnf/token_symbol/types.d.ts +2 -2
  47. package/fjs/bnf/types.d.ts +10 -3
  48. package/fjs/cas/cli/module.f.d.mts +1 -1
  49. package/fjs/cas/cli/module.f.mjs +14 -20
  50. package/fjs/cas/cli/proof.f.d.mts +4 -4
  51. package/fjs/cas/cli/proof.f.mjs +47 -34
  52. package/fjs/cas/evo/module.f.d.mts +71 -31
  53. package/fjs/cas/evo/module.f.mjs +223 -138
  54. package/fjs/cas/evo/proof.f.d.mts +10 -1
  55. package/fjs/cas/evo/proof.f.mjs +311 -226
  56. package/fjs/cas/evo/types.d.ts +45 -9
  57. package/fjs/cas/module.f.d.mts +18 -32
  58. package/fjs/cas/module.f.mjs +164 -176
  59. package/fjs/cas/proof.f.d.mts +11 -8
  60. package/fjs/cas/proof.f.mjs +259 -147
  61. package/fjs/cas/types.d.ts +24 -10
  62. package/fjs/ci/common/module.f.d.mts +1 -1
  63. package/fjs/ci/common/module.f.mjs +1 -0
  64. package/fjs/ci/config/module.f.d.mts +3 -3
  65. package/fjs/ci/config/module.f.mjs +3 -3
  66. package/fjs/ci/module.f.d.mts +5 -5
  67. package/fjs/ci/module.f.mjs +8 -7
  68. package/fjs/ci/nix/module.f.d.mts +7 -5
  69. package/fjs/ci/nix/module.f.mjs +13 -12
  70. package/fjs/ci/nix/proof.f.d.mts +2 -0
  71. package/fjs/ci/nix/proof.f.mjs +4 -4
  72. package/fjs/ci/proof.f.d.mts +4 -2
  73. package/fjs/ci/proof.f.mjs +13 -8
  74. package/fjs/cli/module.f.d.mts +4 -6
  75. package/fjs/cli/module.f.mjs +4 -8
  76. package/fjs/cli/proof.f.d.mts +4 -2
  77. package/fjs/cli/proof.f.mjs +21 -18
  78. package/fjs/cli/types.d.ts +2 -3
  79. package/fjs/common/monoid/module.f.d.mts +70 -12
  80. package/fjs/common/monoid/module.f.mjs +177 -14
  81. package/fjs/common/monoid/proof.f.d.mts +12 -1
  82. package/fjs/common/monoid/proof.f.mjs +88 -4
  83. package/fjs/common/monoid/types.d.ts +23 -0
  84. package/fjs/crypto/hmac/module.f.mjs +2 -2
  85. package/fjs/crypto/secp/proof.f.d.mts +3 -1
  86. package/fjs/crypto/secp/proof.f.mjs +3 -1
  87. package/fjs/crypto/sha2/module.f.mjs +3 -1
  88. package/fjs/crypto/sha2/proof.f.d.mts +4 -1
  89. package/fjs/crypto/sha2/proof.f.mjs +27 -1
  90. package/fjs/crypto/sha2/types.d.ts +11 -0
  91. package/fjs/crypto/sign/module.f.mjs +2 -2
  92. package/fjs/crypto/vdf/module.f.d.mts +23 -4
  93. package/fjs/crypto/vdf/module.f.mjs +6 -4
  94. package/fjs/dev/module.f.d.mts +17 -5
  95. package/fjs/dev/module.f.mjs +60 -30
  96. package/fjs/dev/update/module.f.d.mts +11 -3
  97. package/fjs/dev/update/module.f.mjs +16 -11
  98. package/fjs/dev/update/proof.f.d.mts +4 -3
  99. package/fjs/dev/update/proof.f.mjs +11 -7
  100. package/fjs/djs/module.f.d.mts +13 -5
  101. package/fjs/djs/module.f.mjs +31 -16
  102. package/fjs/djs/parser/module.f.d.mts +16 -3
  103. package/fjs/djs/parser/module.f.mjs +135 -16
  104. package/fjs/djs/parser/proof.f.d.mts +8 -1
  105. package/fjs/djs/parser/proof.f.mjs +287 -13
  106. package/fjs/djs/parser/types.d.ts +7 -1
  107. package/fjs/djs/proof.f.d.mts +20 -1
  108. package/fjs/djs/proof.f.mjs +190 -12
  109. package/fjs/djs/serializer/module.f.d.mts +25 -8
  110. package/fjs/djs/serializer/module.f.mjs +66 -19
  111. package/fjs/djs/serializer/proof.f.d.mts +5 -0
  112. package/fjs/djs/serializer/proof.f.mjs +23 -1
  113. package/fjs/djs/tokenizer/module.f.d.mts +17 -5
  114. package/fjs/djs/tokenizer/module.f.mjs +120 -73
  115. package/fjs/djs/tokenizer/proof.f.d.mts +3 -0
  116. package/fjs/djs/tokenizer/proof.f.mjs +86 -67
  117. package/fjs/djs/transpiler/module.f.d.mts +13 -19
  118. package/fjs/djs/transpiler/module.f.mjs +79 -72
  119. package/fjs/djs/transpiler/types.d.ts +29 -0
  120. package/fjs/djs/types.d.ts +7 -1
  121. package/fjs/effects/list/module.f.d.mts +23 -12
  122. package/fjs/effects/list/module.f.mjs +16 -12
  123. package/fjs/effects/list/types.d.ts +27 -7
  124. package/fjs/effects/memory/module.f.d.mts +6 -3
  125. package/fjs/effects/memory/module.f.mjs +7 -7
  126. package/fjs/effects/memory/proof.f.d.mts +4 -0
  127. package/fjs/effects/memory/proof.f.mjs +18 -9
  128. package/fjs/effects/memory/types.d.ts +4 -3
  129. package/fjs/effects/mock/module.f.d.mts +28 -4
  130. package/fjs/effects/mock/module.f.mjs +39 -5
  131. package/fjs/effects/mock/types.d.ts +10 -1
  132. package/fjs/effects/module.d.mts +12 -2
  133. package/fjs/effects/module.f.d.mts +469 -281
  134. package/fjs/effects/module.f.mjs +538 -299
  135. package/fjs/effects/module.mjs +11 -2
  136. package/fjs/effects/node/memory/module.d.mts +7 -2
  137. package/fjs/effects/node/memory/module.mjs +9 -5
  138. package/fjs/effects/node/memory/proof.d.mts +2 -0
  139. package/fjs/effects/node/memory/proof.mjs +12 -5
  140. package/fjs/effects/node/module.d.mts +8 -2
  141. package/fjs/effects/node/module.f.d.mts +183 -43
  142. package/fjs/effects/node/module.f.mjs +260 -62
  143. package/fjs/effects/node/module.mjs +61 -50
  144. package/fjs/effects/node/proof.f.d.mts +28 -2
  145. package/fjs/effects/node/proof.f.mjs +161 -42
  146. package/fjs/effects/node/types.d.ts +106 -18
  147. package/fjs/effects/node/virtual/module.f.d.mts +21 -4
  148. package/fjs/effects/node/virtual/module.f.mjs +113 -70
  149. package/fjs/effects/node/virtual/proof.f.d.mts +31 -2
  150. package/fjs/effects/node/virtual/proof.f.mjs +201 -8
  151. package/fjs/effects/proof.f.d.mts +69 -34
  152. package/fjs/effects/proof.f.mjs +413 -130
  153. package/fjs/effects/types.d.ts +161 -33
  154. package/fjs/emergent_testing/all.test.d.mts +8 -0
  155. package/fjs/emergent_testing/all.test.mjs +14 -0
  156. package/fjs/emergent_testing/module.f.d.mts +22 -10
  157. package/fjs/emergent_testing/module.f.mjs +119 -85
  158. package/fjs/emergent_testing/proof.f.d.mts +21 -7
  159. package/fjs/emergent_testing/proof.f.mjs +169 -35
  160. package/fjs/emergent_testing/types.d.ts +22 -4
  161. package/fjs/fsc/bnf.f.d.mts +3 -0
  162. package/fjs/fsc/bnf.f.mjs +4 -1
  163. package/fjs/fsc/json.f.d.mts +3 -0
  164. package/fjs/fsc/json.f.mjs +4 -1
  165. package/fjs/fsc/module.f.d.mts +9 -0
  166. package/fjs/fsc/module.f.mjs +5 -3
  167. package/fjs/fsm/module.f.d.mts +14 -4
  168. package/fjs/fsm/module.f.mjs +54 -37
  169. package/fjs/fsm/proof.f.d.mts +5 -0
  170. package/fjs/fsm/proof.f.mjs +87 -115
  171. package/fjs/js/keywords/module.f.d.mts +52 -0
  172. package/fjs/js/keywords/module.f.mjs +72 -0
  173. package/fjs/{emergent_testing/scenarios/return-value.pass.d.ts → js/keywords/proof.f.d.mts} +1 -1
  174. package/fjs/js/keywords/proof.f.mjs +13 -0
  175. package/fjs/js/tokenizer/module.f.d.mts +30 -3
  176. package/fjs/js/tokenizer/module.f.mjs +161 -211
  177. package/fjs/js/tokenizer/proof.f.d.mts +1 -0
  178. package/fjs/js/tokenizer/proof.f.mjs +54 -24
  179. package/fjs/js/tokenizer/types.d.ts +33 -24
  180. package/fjs/mcp/cas/module.f.d.mts +1 -6
  181. package/fjs/mcp/cas/module.f.mjs +55 -51
  182. package/fjs/mcp/cas/proof.f.d.mts +15 -0
  183. package/fjs/mcp/cas/proof.f.mjs +174 -0
  184. package/fjs/mcp/evo/module.f.d.mts +19 -10
  185. package/fjs/mcp/evo/module.f.mjs +48 -27
  186. package/fjs/mcp/evo/proof.f.d.mts +6 -1
  187. package/fjs/mcp/evo/proof.f.mjs +115 -31
  188. package/fjs/mcp/module.f.d.mts +39 -4
  189. package/fjs/mcp/module.f.mjs +14 -12
  190. package/fjs/mcp/proof.f.d.mts +13 -1
  191. package/fjs/mcp/proof.f.mjs +120 -61
  192. package/fjs/media/html/module.f.d.mts +12 -0
  193. package/fjs/media/html/module.f.mjs +7 -5
  194. package/fjs/media/html/proof.f.d.mts +3 -0
  195. package/fjs/media/html/proof.f.mjs +4 -1
  196. package/fjs/media/json/extended/module.f.d.mts +82 -0
  197. package/fjs/media/json/extended/module.f.mjs +153 -0
  198. package/fjs/media/json/extended/proof.f.d.mts +42 -0
  199. package/fjs/media/json/extended/proof.f.mjs +127 -0
  200. package/fjs/media/json/extended/types.d.ts +23 -0
  201. package/fjs/media/json/module.f.d.mts +8 -2
  202. package/fjs/media/json/module.f.mjs +43 -41
  203. package/fjs/media/json/number/module.f.d.mts +59 -0
  204. package/fjs/media/json/number/module.f.mjs +136 -0
  205. package/fjs/media/json/number/proof.f.d.mts +24 -0
  206. package/fjs/media/json/number/proof.f.mjs +86 -0
  207. package/fjs/media/json/number/types.d.ts +28 -0
  208. package/fjs/media/json/parser/module.f.d.mts +25 -13
  209. package/fjs/media/json/parser/module.f.mjs +133 -72
  210. package/fjs/media/json/parser/proof.f.d.mts +5 -0
  211. package/fjs/media/json/parser/proof.f.mjs +31 -1
  212. package/fjs/media/json/parser/types.d.ts +38 -14
  213. package/fjs/media/json/rtti/module.f.d.mts +1 -1
  214. package/fjs/media/json/rtti/module.f.mjs +1 -1
  215. package/fjs/media/json/rtti/proof.f.d.mts +3 -0
  216. package/fjs/media/json/rtti/proof.f.mjs +12 -12
  217. package/fjs/media/json/schema/module.f.d.mts +61 -27
  218. package/fjs/media/json/schema/module.f.mjs +218 -63
  219. package/fjs/media/json/schema/proof.f.d.mts +41 -1
  220. package/fjs/media/json/schema/proof.f.mjs +220 -9
  221. package/fjs/media/json/serializer/module.f.d.mts +44 -0
  222. package/fjs/media/json/serializer/module.f.mjs +71 -9
  223. package/fjs/media/json/tokenizer/module.f.d.mts +8 -0
  224. package/fjs/media/json/tokenizer/module.f.mjs +31 -8
  225. package/fjs/media/json/tokenizer/proof.f.d.mts +6 -0
  226. package/fjs/media/json/tokenizer/proof.f.mjs +62 -21
  227. package/fjs/media/json/types.d.ts +36 -10
  228. package/fjs/media/lock/module.f.d.mts +100 -0
  229. package/fjs/media/lock/module.f.mjs +125 -0
  230. package/fjs/media/lock/proof.f.d.mts +33 -0
  231. package/fjs/media/lock/proof.f.mjs +196 -0
  232. package/fjs/media/lock/types.d.ts +15 -0
  233. package/fjs/media/module.f.d.mts +6 -5
  234. package/fjs/media/module.f.mjs +8 -7
  235. package/fjs/media/nix/module.f.d.mts +13 -0
  236. package/fjs/media/nix/module.f.mjs +4 -2
  237. package/fjs/media/nix/proof.f.d.mts +3 -0
  238. package/fjs/media/nix/proof.f.mjs +4 -1
  239. package/fjs/media/note/module.f.d.mts +121 -0
  240. package/fjs/media/note/module.f.mjs +131 -0
  241. package/fjs/media/note/proof.f.d.mts +29 -0
  242. package/fjs/media/note/proof.f.mjs +150 -0
  243. package/fjs/media/note/types.d.ts +10 -0
  244. package/fjs/media/proof.f.d.mts +4 -1
  245. package/fjs/media/proof.f.mjs +40 -21
  246. package/fjs/media/revision/module.f.d.mts +83 -7
  247. package/fjs/media/revision/module.f.mjs +127 -23
  248. package/fjs/media/revision/proof.f.d.mts +14 -0
  249. package/fjs/media/revision/proof.f.mjs +93 -2
  250. package/fjs/media/revision/types.d.ts +34 -5
  251. package/fjs/media/type/module.f.d.mts +53 -18
  252. package/fjs/media/type/module.f.mjs +87 -97
  253. package/fjs/media/type/proof.f.d.mts +17 -0
  254. package/fjs/media/type/proof.f.mjs +73 -13
  255. package/fjs/module.d.mts +5 -0
  256. package/fjs/module.f.d.mts +8 -0
  257. package/fjs/module.f.mjs +33 -10
  258. package/fjs/module.mjs +6 -0
  259. package/fjs/nanvm/proof.f.mjs +3 -3
  260. package/fjs/nanvm/rust/module.f.mjs +1 -1
  261. package/fjs/nanvm/update/module.f.d.mts +4 -4
  262. package/fjs/nanvm/update/module.f.mjs +8 -9
  263. package/fjs/nanvm/update/proof.f.mjs +4 -3
  264. package/fjs/path/module.f.d.mts +8 -0
  265. package/fjs/path/module.f.mjs +4 -2
  266. package/fjs/proof.f.d.mts +7 -3
  267. package/fjs/proof.f.mjs +41 -12
  268. package/fjs/protocol/json_rpc/module.f.d.mts +3 -3
  269. package/fjs/protocol/json_rpc/module.f.mjs +10 -7
  270. package/fjs/protocol/json_rpc/proof.f.d.mts +6 -0
  271. package/fjs/protocol/json_rpc/proof.f.mjs +26 -5
  272. package/fjs/protocol/mcp/module.f.d.mts +10 -13
  273. package/fjs/protocol/mcp/module.f.mjs +74 -58
  274. package/fjs/protocol/mcp/proof.f.d.mts +16 -3
  275. package/fjs/protocol/mcp/proof.f.mjs +224 -69
  276. package/fjs/protocol/mcp/stdio/module.f.d.mts +17 -11
  277. package/fjs/protocol/mcp/stdio/module.f.mjs +39 -33
  278. package/fjs/protocol/mcp/stdio/proof.f.d.mts +5 -3
  279. package/fjs/protocol/mcp/stdio/proof.f.mjs +46 -13
  280. package/fjs/protocol/mcp/stdio/types.d.ts +14 -0
  281. package/fjs/protocol/mcp/types.d.ts +17 -6
  282. package/fjs/sul/id/module.f.d.mts +4 -0
  283. package/fjs/sul/id/module.f.mjs +6 -6
  284. package/fjs/sul/level/hash/module.f.d.mts +4 -1
  285. package/fjs/sul/level/hash/module.f.mjs +6 -4
  286. package/fjs/sul/level/hash/proof.f.d.mts +4 -0
  287. package/fjs/sul/level/hash/proof.f.mjs +7 -4
  288. package/fjs/sul/level/literal/module.f.d.mts +4 -1
  289. package/fjs/sul/level/literal/module.f.mjs +4 -3
  290. package/fjs/sul/level/literal/proof.f.d.mts +3 -0
  291. package/fjs/sul/level/literal/proof.f.mjs +4 -1
  292. package/fjs/sul/module.f.d.mts +5 -3
  293. package/fjs/sul/module.f.mjs +23 -17
  294. package/fjs/sul/proof.f.d.mts +4 -0
  295. package/fjs/sul/proof.f.mjs +5 -2
  296. package/fjs/text/ascii/module.f.d.mts +26 -0
  297. package/fjs/text/ascii/module.f.mjs +49 -1
  298. package/fjs/text/ascii/proof.f.d.mts +10 -0
  299. package/fjs/text/ascii/proof.f.mjs +33 -1
  300. package/fjs/text/code_point/module.f.d.mts +29 -3
  301. package/fjs/text/code_point/module.f.mjs +32 -9
  302. package/fjs/text/code_point/proof.f.d.mts +2 -0
  303. package/fjs/text/code_point/proof.f.mjs +39 -0
  304. package/fjs/text/module.f.d.mts +4 -2
  305. package/fjs/text/module.f.mjs +4 -3
  306. package/fjs/text/proof.f.d.mts +3 -0
  307. package/fjs/text/proof.f.mjs +4 -1
  308. package/fjs/text/sgr/module.f.d.mts +6 -5
  309. package/fjs/text/sgr/module.f.mjs +8 -8
  310. package/fjs/text/sgr/proof.f.d.mts +3 -0
  311. package/fjs/text/sgr/proof.f.mjs +4 -1
  312. package/fjs/text/utf16/module.f.d.mts +5 -1
  313. package/fjs/text/utf16/module.f.mjs +38 -35
  314. package/fjs/text/utf16/proof.f.d.mts +3 -1
  315. package/fjs/text/utf16/proof.f.mjs +19 -2
  316. package/fjs/text/utf8/module.f.d.mts +9 -5
  317. package/fjs/text/utf8/module.f.mjs +20 -20
  318. package/fjs/types/array/module.f.d.mts +2 -1
  319. package/fjs/types/array/module.f.mjs +16 -4
  320. package/fjs/types/bigfloat/module.f.d.mts +21 -1
  321. package/fjs/types/bigfloat/module.f.mjs +33 -7
  322. package/fjs/types/bigfloat/proof.f.d.mts +1 -0
  323. package/fjs/types/bigfloat/proof.f.mjs +46 -0
  324. package/fjs/types/bigint/module.f.d.mts +4 -0
  325. package/fjs/types/bigint/module.f.mjs +4 -3
  326. package/fjs/types/bit_vec/module.f.d.mts +10 -16
  327. package/fjs/types/bit_vec/module.f.mjs +99 -95
  328. package/fjs/types/bit_vec/proof.f.d.mts +6 -0
  329. package/fjs/types/bit_vec/proof.f.mjs +31 -5
  330. package/fjs/types/btree/find/module.f.d.mts +5 -1
  331. package/fjs/types/btree/find/module.f.mjs +5 -5
  332. package/fjs/types/btree/find/proof.f.d.mts +5 -1
  333. package/fjs/types/btree/find/proof.f.mjs +5 -3
  334. package/fjs/types/btree/module.f.d.mts +3 -0
  335. package/fjs/types/btree/module.f.mjs +3 -2
  336. package/fjs/types/btree/proof.f.d.mts +5 -1
  337. package/fjs/types/btree/proof.f.mjs +5 -3
  338. package/fjs/types/btree/remove/module.f.d.mts +11 -0
  339. package/fjs/types/btree/remove/module.f.mjs +10 -10
  340. package/fjs/types/btree/remove/proof.f.d.mts +3 -0
  341. package/fjs/types/btree/remove/proof.f.mjs +4 -1
  342. package/fjs/types/btree/set/module.f.d.mts +9 -0
  343. package/fjs/types/btree/set/module.f.mjs +14 -17
  344. package/fjs/types/btree/set/proof.f.d.mts +3 -0
  345. package/fjs/types/btree/set/proof.f.mjs +16 -1
  346. package/fjs/types/btree/types/module.f.d.mts +2 -1
  347. package/fjs/types/btree/types/module.f.mjs +2 -1
  348. package/fjs/types/byte_set/module.f.d.mts +20 -4
  349. package/fjs/types/byte_set/module.f.mjs +18 -8
  350. package/fjs/types/byte_set/proof.f.d.mts +3 -1
  351. package/fjs/types/byte_set/proof.f.mjs +10 -8
  352. package/fjs/types/function/compare/module.f.d.mts +3 -2
  353. package/fjs/types/function/compare/module.f.mjs +13 -5
  354. package/fjs/types/function/module.f.d.mts +8 -1
  355. package/fjs/types/function/module.f.mjs +8 -1
  356. package/fjs/types/function/operator/module.f.d.mts +2 -1
  357. package/fjs/types/function/operator/module.f.mjs +2 -2
  358. package/fjs/types/list/module.f.d.mts +10 -3
  359. package/fjs/types/list/module.f.mjs +6 -4
  360. package/fjs/types/list/proof.f.d.mts +4 -1
  361. package/fjs/types/list/proof.f.mjs +4 -2
  362. package/fjs/types/nibble_set/module.f.d.mts +2 -1
  363. package/fjs/types/nibble_set/module.f.mjs +2 -2
  364. package/fjs/types/nominal/module.f.d.mts +2 -1
  365. package/fjs/types/nominal/module.f.mjs +2 -1
  366. package/fjs/types/nullable/module.f.d.mts +26 -6
  367. package/fjs/types/nullable/module.f.mjs +25 -6
  368. package/fjs/types/nullable/proof.f.d.mts +4 -0
  369. package/fjs/types/nullable/proof.f.mjs +15 -0
  370. package/fjs/types/number/module.f.d.mts +4 -0
  371. package/fjs/types/number/module.f.mjs +4 -3
  372. package/fjs/types/object/module.f.d.mts +26 -4
  373. package/fjs/types/object/module.f.mjs +26 -7
  374. package/fjs/types/object/proof.f.d.mts +5 -2
  375. package/fjs/types/object/proof.f.mjs +6 -3
  376. package/fjs/types/object/structurally_same/module.f.d.mts +39 -0
  377. package/fjs/types/object/structurally_same/module.f.mjs +59 -0
  378. package/fjs/types/object/structurally_same/proof.f.d.mts +6 -0
  379. package/fjs/types/object/structurally_same/proof.f.mjs +73 -0
  380. package/fjs/types/ordered_map/module.f.d.mts +5 -0
  381. package/fjs/types/ordered_map/module.f.mjs +5 -4
  382. package/fjs/types/ordered_map/proof.f.d.mts +3 -0
  383. package/fjs/types/ordered_map/proof.f.mjs +4 -1
  384. package/fjs/types/patricia_trie/module.f.d.mts +2 -1
  385. package/fjs/types/patricia_trie/module.f.mjs +27 -12
  386. package/fjs/types/patricia_trie/proof.f.d.mts +3 -0
  387. package/fjs/types/patricia_trie/proof.f.mjs +4 -1
  388. package/fjs/types/prime_field/module.f.d.mts +3 -1
  389. package/fjs/types/prime_field/module.f.mjs +3 -2
  390. package/fjs/types/range/module.f.d.mts +2 -1
  391. package/fjs/types/range/module.f.mjs +2 -2
  392. package/fjs/types/range_map/module.f.d.mts +6 -0
  393. package/fjs/types/range_map/module.f.mjs +6 -9
  394. package/fjs/types/range_map/proof.f.d.mts +5 -1
  395. package/fjs/types/range_map/proof.f.mjs +5 -3
  396. package/fjs/types/range_set/module.f.d.mts +5 -0
  397. package/fjs/types/range_set/module.f.mjs +1 -0
  398. package/fjs/types/range_set/proof.f.d.mts +3 -0
  399. package/fjs/types/range_set/proof.f.mjs +4 -1
  400. package/fjs/types/result/module.d.mts +8 -0
  401. package/fjs/types/result/module.f.d.mts +37 -7
  402. package/fjs/types/result/module.f.mjs +38 -8
  403. package/fjs/types/result/module.mjs +9 -1
  404. package/fjs/types/result/proof.f.d.mts +5 -0
  405. package/fjs/types/result/proof.f.mjs +22 -2
  406. package/fjs/types/rtti/common/module.f.d.mts +44 -14
  407. package/fjs/types/rtti/common/module.f.mjs +42 -36
  408. package/fjs/types/rtti/common/proof.f.d.mts +4 -0
  409. package/fjs/types/rtti/common/proof.f.mjs +10 -7
  410. package/fjs/types/rtti/data/module.f.d.mts +134 -0
  411. package/fjs/types/rtti/data/module.f.mjs +1053 -0
  412. package/fjs/types/rtti/data/proof.f.d.mts +76 -0
  413. package/fjs/types/rtti/data/proof.f.mjs +589 -0
  414. package/fjs/types/rtti/data/types.d.ts +83 -0
  415. package/fjs/types/rtti/module.f.d.mts +12 -5
  416. package/fjs/types/rtti/module.f.mjs +7 -5
  417. package/fjs/types/rtti/parse/module.f.d.mts +48 -0
  418. package/fjs/types/rtti/parse/module.f.mjs +45 -34
  419. package/fjs/types/rtti/parse/proof.f.d.mts +3 -2
  420. package/fjs/types/rtti/parse/proof.f.mjs +51 -52
  421. package/fjs/types/rtti/proof.f.d.mts +3 -1
  422. package/fjs/types/rtti/proof.f.mjs +6 -2
  423. package/fjs/types/rtti/ts/module.f.d.mts +68 -9
  424. package/fjs/types/rtti/ts/module.f.mjs +258 -30
  425. package/fjs/types/rtti/ts/proof.f.d.mts +44 -0
  426. package/fjs/types/rtti/ts/proof.f.mjs +152 -4
  427. package/fjs/types/rtti/ts/types.d.ts +25 -1
  428. package/fjs/types/rtti/types.d.ts +40 -0
  429. package/fjs/types/sorted_list/module.f.d.mts +4 -1
  430. package/fjs/types/sorted_list/module.f.mjs +21 -12
  431. package/fjs/types/sorted_list/proof.f.d.mts +3 -1
  432. package/fjs/types/sorted_list/proof.f.mjs +3 -1
  433. package/fjs/types/sorted_set/module.f.d.mts +49 -1
  434. package/fjs/types/sorted_set/module.f.mjs +26 -2
  435. package/fjs/types/sorted_set/proof.f.d.mts +4 -1
  436. package/fjs/types/sorted_set/proof.f.mjs +19 -2
  437. package/fjs/types/string/module.f.d.mts +4 -0
  438. package/fjs/types/string/module.f.mjs +4 -3
  439. package/fjs/types/string_set/module.f.d.mts +3 -1
  440. package/fjs/types/string_set/module.f.mjs +3 -2
  441. package/fjs/types/ts/module.f.d.mts +2 -0
  442. package/fjs/types/ts/module.f.mjs +3 -3
  443. package/fjs/types/ts/proof.f.d.mts +1 -0
  444. package/fjs/types/ts/proof.f.mjs +5 -0
  445. package/fjs/types/ts/types.d.ts +6 -1
  446. package/fjs/types/uint8array/module.f.d.mts +13 -2
  447. package/fjs/types/uint8array/module.f.mjs +20 -15
  448. package/fjs/website/module.f.d.mts +5 -2
  449. package/fjs/website/module.f.mjs +6 -8
  450. package/fjs/website/proof.f.mjs +2 -1
  451. package/package.json +3 -3
  452. package/fjs/asn.1/types.js +0 -6
  453. package/fjs/asserts/types.js +0 -6
  454. package/fjs/basen/types.js +0 -6
  455. package/fjs/bnf/data/types.js +0 -6
  456. package/fjs/bnf/descent/types.js +0 -6
  457. package/fjs/bnf/ll1/types.js +0 -6
  458. package/fjs/bnf/token_symbol/types.js +0 -6
  459. package/fjs/bnf/types.js +0 -6
  460. package/fjs/cas/evo/types.js +0 -7
  461. package/fjs/cas/types.js +0 -6
  462. package/fjs/ci/common/types.js +0 -1
  463. package/fjs/ci/nix/types.js +0 -6
  464. package/fjs/ci/types.js +0 -6
  465. package/fjs/cli/types.js +0 -6
  466. package/fjs/common/monoid/types.js +0 -6
  467. package/fjs/crypto/pow/types.js +0 -6
  468. package/fjs/crypto/secp/types.js +0 -6
  469. package/fjs/crypto/sha2/types.js +0 -6
  470. package/fjs/crypto/sign/types.js +0 -6
  471. package/fjs/crypto/vdf/types.js +0 -6
  472. package/fjs/dev/package_json/module.f.d.mts +0 -32
  473. package/fjs/dev/package_json/module.f.mjs +0 -37
  474. package/fjs/dev/package_json/proof.f.d.mts +0 -6
  475. package/fjs/dev/package_json/proof.f.mjs +0 -32
  476. package/fjs/dev/types.js +0 -6
  477. package/fjs/djs/ast/types.js +0 -8
  478. package/fjs/djs/parser/types.js +0 -7
  479. package/fjs/djs/tokenizer/types.js +0 -7
  480. package/fjs/djs/types.js +0 -7
  481. package/fjs/effects/eff/module.f.d.mts +0 -10
  482. package/fjs/effects/eff/module.f.mjs +0 -68
  483. package/fjs/effects/eff/proof.f.d.mts +0 -12
  484. package/fjs/effects/eff/proof.f.mjs +0 -66
  485. package/fjs/effects/eff/types.d.ts +0 -71
  486. package/fjs/effects/eff/types.js +0 -6
  487. package/fjs/effects/list/types.js +0 -6
  488. package/fjs/effects/memory/types.js +0 -6
  489. package/fjs/effects/mock/types.js +0 -6
  490. package/fjs/effects/node/types.js +0 -6
  491. package/fjs/effects/node/virtual/types.js +0 -7
  492. package/fjs/effects/types.js +0 -6
  493. package/fjs/emergent_testing/all.test.d.ts +0 -1
  494. package/fjs/emergent_testing/all.test.js +0 -5
  495. package/fjs/emergent_testing/scenarios/all.d.ts +0 -1
  496. package/fjs/emergent_testing/scenarios/all.js +0 -1
  497. package/fjs/emergent_testing/scenarios/async-subtests.fail.d.ts +0 -6
  498. package/fjs/emergent_testing/scenarios/async-subtests.fail.js +0 -9
  499. package/fjs/emergent_testing/scenarios/async-subtests.pass.d.ts +0 -6
  500. package/fjs/emergent_testing/scenarios/async-subtests.pass.js +0 -9
  501. package/fjs/emergent_testing/scenarios/async.fail.d.ts +0 -3
  502. package/fjs/emergent_testing/scenarios/async.fail.js +0 -6
  503. package/fjs/emergent_testing/scenarios/async.pass.d.ts +0 -3
  504. package/fjs/emergent_testing/scenarios/async.pass.js +0 -5
  505. package/fjs/emergent_testing/scenarios/fail.fail.d.ts +0 -3
  506. package/fjs/emergent_testing/scenarios/fail.fail.js +0 -3
  507. package/fjs/emergent_testing/scenarios/return-value.pass.js +0 -4
  508. package/fjs/emergent_testing/scenarios/thenable.pass.d.ts +0 -5
  509. package/fjs/emergent_testing/scenarios/thenable.pass.js +0 -11
  510. package/fjs/emergent_testing/scenarios/thenable2.pass.d.ts +0 -5
  511. package/fjs/emergent_testing/scenarios/thenable2.pass.js +0 -3
  512. package/fjs/emergent_testing/scenarios/throw.pass.d.ts +0 -5
  513. package/fjs/emergent_testing/scenarios/throw.pass.js +0 -3
  514. package/fjs/emergent_testing/types.js +0 -6
  515. package/fjs/js/tokenizer/types.js +0 -6
  516. package/fjs/media/html/types.js +0 -6
  517. package/fjs/media/json/parser/types.js +0 -6
  518. package/fjs/media/json/tokenizer/types.js +0 -6
  519. package/fjs/media/json/types.js +0 -13
  520. package/fjs/media/nix/types.js +0 -6
  521. package/fjs/media/revision/types.js +0 -8
  522. package/fjs/media/type/types.js +0 -6
  523. package/fjs/media/types.js +0 -7
  524. package/fjs/nanvm/types.js +0 -11
  525. package/fjs/protocol/json_rpc/types.js +0 -8
  526. package/fjs/protocol/mcp/types.js +0 -8
  527. package/fjs/sul/id/types.js +0 -6
  528. package/fjs/sul/level/hash/types.js +0 -6
  529. package/fjs/sul/level/literal/types.js +0 -6
  530. package/fjs/sul/types.js +0 -6
  531. package/fjs/text/sgr/types.js +0 -6
  532. package/fjs/text/types.js +0 -6
  533. package/fjs/text/utf16/types.js +0 -6
  534. package/fjs/text/utf8/types.js +0 -6
  535. package/fjs/types/array/types.js +0 -6
  536. package/fjs/types/bigfloat/types.js +0 -6
  537. package/fjs/types/bigint/types.js +0 -6
  538. package/fjs/types/bit_vec/types.js +0 -6
  539. package/fjs/types/btree/find/types.js +0 -6
  540. package/fjs/types/btree/types/types.js +0 -6
  541. package/fjs/types/byte_set/types.js +0 -6
  542. package/fjs/types/function/compare/types.js +0 -6
  543. package/fjs/types/function/operator/types.js +0 -6
  544. package/fjs/types/function/types.js +0 -6
  545. package/fjs/types/list/types.js +0 -6
  546. package/fjs/types/nibble_set/types.js +0 -6
  547. package/fjs/types/nominal/types.js +0 -6
  548. package/fjs/types/nullable/types.js +0 -6
  549. package/fjs/types/object/types.js +0 -8
  550. package/fjs/types/option/types.js +0 -6
  551. package/fjs/types/ordered_map/types.js +0 -6
  552. package/fjs/types/patricia_trie/types.js +0 -6
  553. package/fjs/types/phantom/types.js +0 -11
  554. package/fjs/types/prime_field/types.js +0 -6
  555. package/fjs/types/range/types.js +0 -6
  556. package/fjs/types/range_map/types.js +0 -6
  557. package/fjs/types/result/types.js +0 -6
  558. package/fjs/types/rtti/common/types.js +0 -1
  559. package/fjs/types/rtti/parse/types.js +0 -1
  560. package/fjs/types/rtti/ts/types.js +0 -1
  561. package/fjs/types/rtti/types.js +0 -1
  562. package/fjs/types/rtti/validate/module.f.d.mts +0 -6
  563. package/fjs/types/rtti/validate/module.f.mjs +0 -169
  564. package/fjs/types/rtti/validate/proof.f.d.mts +0 -125
  565. package/fjs/types/rtti/validate/proof.f.mjs +0 -437
  566. package/fjs/types/rtti/validate/types.d.ts +0 -6
  567. package/fjs/types/rtti/validate/types.js +0 -1
  568. package/fjs/types/sorted_list/types.js +0 -6
  569. package/fjs/types/sorted_set/types.js +0 -6
  570. package/fjs/types/string_set/types.js +0 -6
  571. package/fjs/types/ts/types.js +0 -8
@@ -1,30 +1,42 @@
1
1
  /**
2
- * JSON parser that consumes tokenizer output into JSON values.
2
+ * The shared structural JSON parser: one tokenizer, one container state
3
+ * machine, and a numeric policy per codec.
4
+ *
5
+ * The state machine builds objects and arrays; a number token is handed to the
6
+ * `NumberPolicy` the caller supplies, together with its exact lexeme. Numeric
7
+ * syntax therefore stays lossless all the way to the policy, and each codec
8
+ * chooses its own runtime numeric domain from the same parse:
9
+ *
10
+ * ```text
11
+ * JSON text -> tokenizer -> parse(policy) -+-> json.Unknown (number)
12
+ * +-> extended.Unknown (number | bigint)
13
+ * +-> another policy's domain
14
+ * ```
15
+ *
16
+ * No codec has to materialize another codec's domain first: standard JSON
17
+ * parsing never needs an intermediate `bigint`, and extended parsing never
18
+ * needs an intermediate rounded `number`.
3
19
  *
4
20
  * @module
5
21
  *
6
- * @import { Unknown } from '../types.ts'
7
22
  * @import { Result } from '../../../types/result/types.ts'
8
23
  * @import { List } from '../../../types/list/types.ts'
9
24
  * @import { Fold } from '../../../types/function/operator/types.ts'
10
25
  * @import { JsonToken } from '../tokenizer/types.ts'
11
- * @import { _JsonObject, _JsonArray, _StateParse, _JsonState, _JsonStack } from './types.ts'
26
+ * @import { NumberPolicy, ParseUnknown, _JsonObject, _JsonArray, _StateParse, _JsonState, _JsonStack, _ValueToken } from './types.ts'
12
27
  */
13
- import type { Unknown } from '../types.ts';
14
28
  import type { Result } from '../../../types/result/types.ts';
15
29
  import type { List } from '../../../types/list/types.ts';
16
30
  import type { JsonToken } from '../tokenizer/types.ts';
31
+ import type { NumberPolicy, ParseUnknown } from './types.ts';
17
32
  /**
18
- * Parses a list of JSON tokens into a JSON-compatible value.
33
+ * Parses a list of JSON tokens into the value domain `policy` materializes
34
+ * numbers into.
19
35
  *
20
36
  * Returns `ok` with the parsed value on success, or `error` with a message
21
- * when the token sequence is invalid or incomplete.
37
+ * when the token sequence is invalid or incomplete — or when `policy` rejects
38
+ * a number token that its domain cannot represent.
22
39
  *
23
- * @type {(tokenList: List<JsonToken>) => Result<Unknown, string>}
40
+ * @type {<P>(policy: NumberPolicy<P>) => (tokenList: List<JsonToken>) => Result<ParseUnknown<P>, string>}
24
41
  */
25
- export declare const parse: (tokenList: List<JsonToken>) => Result<Unknown, string>;
26
- export declare const proof: {
27
- pushKey: {
28
- nonObjectTop: () => void;
29
- };
30
- };
42
+ export declare const parse: <P>(policy: NumberPolicy<P>) => (tokenList: List<JsonToken>) => Result<ParseUnknown<P>, string>;
@@ -1,48 +1,86 @@
1
1
  /**
2
- * JSON parser that consumes tokenizer output into JSON values.
2
+ * The shared structural JSON parser: one tokenizer, one container state
3
+ * machine, and a numeric policy per codec.
4
+ *
5
+ * The state machine builds objects and arrays; a number token is handed to the
6
+ * `NumberPolicy` the caller supplies, together with its exact lexeme. Numeric
7
+ * syntax therefore stays lossless all the way to the policy, and each codec
8
+ * chooses its own runtime numeric domain from the same parse:
9
+ *
10
+ * ```text
11
+ * JSON text -> tokenizer -> parse(policy) -+-> json.Unknown (number)
12
+ * +-> extended.Unknown (number | bigint)
13
+ * +-> another policy's domain
14
+ * ```
15
+ *
16
+ * No codec has to materialize another codec's domain first: standard JSON
17
+ * parsing never needs an intermediate `bigint`, and extended parsing never
18
+ * needs an intermediate rounded `number`.
3
19
  *
4
20
  * @module
5
21
  *
6
- * @import { Unknown } from '../types.ts'
7
22
  * @import { Result } from '../../../types/result/types.ts'
8
23
  * @import { List } from '../../../types/list/types.ts'
9
24
  * @import { Fold } from '../../../types/function/operator/types.ts'
10
25
  * @import { JsonToken } from '../tokenizer/types.ts'
11
- * @import { _JsonObject, _JsonArray, _StateParse, _JsonState, _JsonStack } from './types.ts'
26
+ * @import { NumberPolicy, ParseUnknown, _JsonObject, _JsonArray, _StateParse, _JsonState, _JsonStack, _ValueToken } from './types.ts'
12
27
  */
13
28
 
29
+ import { assert } from '../../../asserts/module.f.mjs'
14
30
  import { error, ok } from '../../../types/result/module.f.mjs'
15
31
  import { fold, next, toArray, concat } from '../../../types/list/module.f.mjs'
16
32
  import { setReplace } from '../../../types/ordered_map/module.f.mjs'
17
33
  import { fromMap } from '../../../types/object/module.f.mjs'
18
- import { assertEq } from '../../../asserts/module.f.mjs'
19
34
 
20
- /** @type {(obj: _JsonObject) => (key: string) => _JsonObject} */
35
+ /**
36
+ * Every syntax error the parser can report is the same one: a token that
37
+ * cannot follow the state it arrived in. It carries no position or metadata,
38
+ * so one shared value serves all of them — and no numeric policy either, so
39
+ * the same value serves every instantiation of the parser.
40
+ *
41
+ * @type {_JsonState<never>}
42
+ */
43
+ const unexpectedToken = { status: 'error', message: 'unexpected token' }
44
+
45
+ /** @type {<P>(obj: _JsonObject<P>) => (key: string) => _JsonObject<P>} */
21
46
  const addKeyToObject =
22
47
  obj => key => ({ kind: 'object', values: obj.values, key: key })
23
48
 
24
- /** @type {(obj: _JsonObject) => (value: Unknown) => _JsonObject} */
49
+ /** @type {<P>(obj: _JsonObject<P>) => (value: ParseUnknown<P>) => _JsonObject<P>} */
25
50
  const addValueToObject =
26
51
  obj => value => ({ kind: 'object', values: setReplace(obj.key)(value)(obj.values), key: '' })
27
52
 
28
- /** @type {(array: _JsonArray) => (value: Unknown) => _JsonArray} */
53
+ /** @type {<P>(array: _JsonArray<P>) => (value: ParseUnknown<P>) => _JsonArray<P>} */
29
54
  const addToArray =
30
55
  array => value => ({ kind: 'array', values: concat(array.values)([value]) })
31
56
 
32
- /** @type {(state: _StateParse) => (key: string) => _JsonState} */
57
+ /**
58
+ * `pushKey` only ever runs while parsing the object `startObject` opened
59
+ * (status `'{'`/`'{,'`), so `state.top` is always that object here — the same
60
+ * construction guarantee `endArray` relies on below.
61
+ *
62
+ * @template P
63
+ * @param {_StateParse<P>} state
64
+ * @returns {(key: string) => _JsonState<P>}
65
+ */
33
66
  const pushKey = state => value => {
34
- if (state.top?.kind === 'object') { return { status: '{k', top: addKeyToObject(state.top)(value), stack: state.stack } }
35
- return { status: 'error', message: 'error' }
67
+ const { top } = state
68
+ assert(top !== null && top.kind === 'object', top)
69
+ return {
70
+ status: '{k',
71
+ top: addKeyToObject(top)(value),
72
+ stack: state.stack,
73
+ }
36
74
  }
37
75
 
38
- /** @type {(state: _StateParse) => (value: Unknown) => _JsonState} */
76
+ /** @type {<P>(state: _StateParse<P>) => (value: ParseUnknown<P>) => _JsonState<P>} */
39
77
  const pushValue = state => value => {
40
78
  if (state.top === null) { return { status: 'result', value: value } }
41
79
  if (state.top.kind === 'array') { return { status: '[v', top: addToArray(state.top)(value), stack: state.stack } }
42
80
  return { status: '{v', top: addValueToObject(state.top)(value), stack: state.stack }
43
81
  }
44
82
 
45
- /** @type {(state: _StateParse) => _JsonState} */
83
+ /** @type {<P>(state: _StateParse<P>) => _JsonState<P>} */
46
84
  const startArray = state => {
47
85
  const newStack = state.top === null ? null : { first: state.top, tail: state.stack }
48
86
  return { status: '[', top: { kind: 'array', values: null }, stack: newStack }
@@ -54,7 +92,7 @@ const startArray = state => {
54
92
  * always as a literal cons, and a lazy pop would leave one unforced thunk per
55
93
  * closed container — a chain that overflows the stack when it is finally forced.
56
94
  *
57
- * @type {(stack: _JsonStack) => _StateParse}
95
+ * @type {<P>(stack: _JsonStack<P>) => _StateParse<P>}
58
96
  */
59
97
  const popStack = stack => {
60
98
  const ne = next(stack)
@@ -63,39 +101,72 @@ const popStack = stack => {
63
101
  : { status: '', top: ne.first, stack: ne.tail }
64
102
  }
65
103
 
66
- /** @type {(state: _StateParse) => _JsonState} */
104
+ /**
105
+ * `endArray` only ever runs while parsing the array `startArray` opened
106
+ * (status `'['`/`'[v'`), so `state.top` is always that array here.
107
+ *
108
+ * @template P
109
+ * @param {_StateParse<P>} state
110
+ * @returns {_JsonState<P>}
111
+ */
67
112
  const endArray = state => {
68
- const array = state.top !== null ? toArray(state.top.values) : null
113
+ const { top } = state
114
+ assert(top !== null && top.kind === 'array', top)
115
+ const array = toArray(top.values)
69
116
  const newState = popStack(state.stack)
70
117
  return pushValue(newState)(array)
71
118
  }
72
119
 
73
- /** @type {(state: _StateParse) => _JsonState} */
120
+ /** @type {<P>(state: _StateParse<P>) => _JsonState<P>} */
74
121
  const startObject = state => {
75
122
  const newStack = state.top === null ? null : { first: state.top, tail: state.stack }
76
123
  return { status: '{', top: { kind: 'object', values: null, key: '' }, stack: newStack }
77
124
  }
78
125
 
79
- /** @type {(state: _StateParse) => _JsonState} */
126
+ /**
127
+ * `endObject` only ever runs while parsing the object `startObject` opened
128
+ * (status `'{'`/`'{v'`), so `state.top` is always that object here.
129
+ *
130
+ * @template P
131
+ * @param {_StateParse<P>} state
132
+ * @returns {_JsonState<P>}
133
+ */
80
134
  const endObject = state => {
81
- const obj = state.top?.kind === 'object' ? fromMap(state.top.values) : null
135
+ const { top } = state
136
+ assert(top !== null && top.kind === 'object', top)
137
+ const obj = fromMap(top.values)
82
138
  const newState = popStack(state.stack)
83
139
  return pushValue(newState)(obj)
84
140
  }
85
141
 
86
- /** @type {(token: JsonToken) => Unknown} */
87
- const tokenToValue = token => {
142
+ /**
143
+ * Only ever called on a token `isValueToken` has already confirmed carries a
144
+ * value, so the switch covers every `_ValueToken` case with no fallback arm.
145
+ * A number is the one leaf the parser does not know how to build: `policy`
146
+ * owns that decision and may reject the token.
147
+ *
148
+ * @type {<P>(policy: NumberPolicy<P>) => (token: _ValueToken) => Result<ParseUnknown<P>, string>}
149
+ */
150
+ const tokenToValue = policy => token => {
88
151
  switch (token.kind) {
89
- case 'null': return null
90
- case 'false': return false
91
- case 'true': return true
92
- case 'number': return parseFloat(token.value)
93
- case 'string': return token.value
94
- default: return null
152
+ case 'null': return ok(null)
153
+ case 'false': return ok(false)
154
+ case 'true': return ok(true)
155
+ case 'number': return policy(token)
156
+ case 'string': return ok(token.value)
95
157
  }
96
158
  }
97
159
 
98
- /** @type {(token: JsonToken) => boolean} */
160
+ /** @type {<P>(policy: NumberPolicy<P>) => (state: _StateParse<P>) => (token: _ValueToken) => _JsonState<P>} */
161
+ const pushLeaf = policy => state => token => {
162
+ const [kind, value] = tokenToValue(policy)(token)
163
+ return kind === 'error' ? { status: 'error', message: value } : pushValue(state)(value)
164
+ }
165
+
166
+ /**
167
+ * @param {JsonToken} token
168
+ * @returns {token is _ValueToken}
169
+ */
99
170
  const isValueToken = token => {
100
171
  switch (token.kind) {
101
172
  case 'null':
@@ -107,95 +178,99 @@ const isValueToken = token => {
107
178
  }
108
179
  }
109
180
 
110
- /** @type {(token: JsonToken) => (state: _StateParse) => _JsonState} */
111
- const parseValueOp = token => state => {
181
+ /** @type {<P>(policy: NumberPolicy<P>) => (token: JsonToken) => (state: _StateParse<P>) => _JsonState<P>} */
182
+ const parseValueOp = policy => token => state => {
112
183
  switch (token.kind) {
113
184
  // A value is required here (top level, after `[`+`,`, or after `:`),
114
185
  // so `]` is never valid — strict JSON has no trailing commas.
115
186
  case ']':
116
- return { status: 'error', message: 'unexpected token' }
187
+ return unexpectedToken
117
188
  case '[': return startArray(state)
118
189
  case '{': return startObject(state)
119
190
  default:
120
- if (isValueToken(token)) { return pushValue(state)(tokenToValue(token)) }
121
- return { status: 'error', message: 'unexpected token' }
191
+ if (isValueToken(token)) { return pushLeaf(policy)(state)(token) }
192
+ return unexpectedToken
122
193
  }
123
194
  }
124
195
 
125
- /** @type {(token: JsonToken) => (state: _StateParse) => _JsonState} */
126
- const parseArrayStartOp = token => state => {
127
- if (isValueToken(token)) { return pushValue(state)(tokenToValue(token)) }
196
+ /** @type {<P>(policy: NumberPolicy<P>) => (token: JsonToken) => (state: _StateParse<P>) => _JsonState<P>} */
197
+ const parseArrayStartOp = policy => token => state => {
198
+ if (isValueToken(token)) { return pushLeaf(policy)(state)(token) }
128
199
  if (token.kind === '[') { return startArray(state) }
129
200
  if (token.kind === ']') { return endArray(state) }
130
201
  if (token.kind === '{') { return startObject(state) }
131
- return { status: 'error', message: 'unexpected token' }
202
+ return unexpectedToken
132
203
  }
133
204
 
134
- /** @type {(token: JsonToken) => (state: _StateParse) => _JsonState} */
205
+ /** @type {<P>(token: JsonToken) => (state: _StateParse<P>) => _JsonState<P>} */
135
206
  const parseArrayValueOp = token => state => {
136
207
  if (token.kind === ']') { return endArray(state) }
137
208
  if (token.kind === ',') { return { status: '[,', top: state.top, stack: state.stack } }
138
- return { status: 'error', message: 'unexpected token' }
209
+ return unexpectedToken
139
210
  }
140
211
 
141
- /** @type {(token: JsonToken) => (state: _StateParse) => _JsonState} */
212
+ /** @type {<P>(token: JsonToken) => (state: _StateParse<P>) => _JsonState<P>} */
142
213
  const parseObjectStartOp = token => state => {
143
214
  if (token.kind === 'string') { return pushKey(state)(token.value) }
144
215
  if (token.kind === '}') { return endObject(state) }
145
- return { status: 'error', message: 'unexpected token' }
216
+ return unexpectedToken
146
217
  }
147
218
 
148
- /** @type {(token: JsonToken) => (state: _StateParse) => _JsonState} */
219
+ /** @type {<P>(token: JsonToken) => (state: _StateParse<P>) => _JsonState<P>} */
149
220
  const parseObjectKeyOp = token => state => {
150
221
  if (token.kind === ':') { return { status: '{:', top: state.top, stack: state.stack } }
151
- return { status: 'error', message: 'unexpected token' }
222
+ return unexpectedToken
152
223
  }
153
224
 
154
- /** @type {(token: JsonToken) => (state: _StateParse) => _JsonState} */
225
+ /** @type {<P>(token: JsonToken) => (state: _StateParse<P>) => _JsonState<P>} */
155
226
  const parseObjectNextOp = token => state => {
156
227
  if (token.kind === '}') { return endObject(state) }
157
228
  if (token.kind === ',') { return { status: '{,', top: state.top, stack: state.stack } }
158
- return { status: 'error', message: 'unexpected token' }
229
+ return unexpectedToken
159
230
  }
160
231
 
161
- /** @type {(token: JsonToken) => (state: _StateParse) => _JsonState} */
232
+ /** @type {<P>(token: JsonToken) => (state: _StateParse<P>) => _JsonState<P>} */
162
233
  const parseObjectCommaOp = token => state => {
163
234
  // After a `,` a member (string key) is required — `}` here would be a
164
235
  // trailing comma, which strict JSON rejects.
165
236
  if (token.kind === 'string') { return pushKey(state)(token.value) }
166
- return { status: 'error', message: 'unexpected token' }
237
+ return unexpectedToken
167
238
  }
168
239
 
169
- /** @type {Fold<JsonToken, _JsonState>} */
170
- const foldOp = token => state => {
240
+ /** @type {<P>(policy: NumberPolicy<P>) => Fold<JsonToken, _JsonState<P>>} */
241
+ const foldOp = policy => token => state => {
171
242
  if (token.kind === 'eof')
172
243
  return state
173
244
 
174
245
  switch (state.status) {
175
- case 'result': return { status: 'error', message: 'unexpected token' }
246
+ case 'result': return unexpectedToken
176
247
  case 'error': return { status: 'error', message: state.message }
177
- case '': return parseValueOp(token)(state)
178
- case '[': return parseArrayStartOp(token)(state)
248
+ case '': return parseValueOp(policy)(token)(state)
249
+ case '[': return parseArrayStartOp(policy)(token)(state)
179
250
  case '[v': return parseArrayValueOp(token)(state)
180
- case '[,': return parseValueOp(token)(state)
251
+ case '[,': return parseValueOp(policy)(token)(state)
181
252
  case '{': return parseObjectStartOp(token)(state)
182
253
  case '{k': return parseObjectKeyOp(token)(state)
183
- case '{:': return parseValueOp(token)(state)
254
+ case '{:': return parseValueOp(policy)(token)(state)
184
255
  case '{v': return parseObjectNextOp(token)(state)
185
256
  case '{,': return parseObjectCommaOp(token)(state)
186
257
  }
187
258
  }
188
259
 
189
260
  /**
190
- * Parses a list of JSON tokens into a JSON-compatible value.
261
+ * Parses a list of JSON tokens into the value domain `policy` materializes
262
+ * numbers into.
191
263
  *
192
264
  * Returns `ok` with the parsed value on success, or `error` with a message
193
- * when the token sequence is invalid or incomplete.
265
+ * when the token sequence is invalid or incomplete — or when `policy` rejects
266
+ * a number token that its domain cannot represent.
194
267
  *
195
- * @type {(tokenList: List<JsonToken>) => Result<Unknown, string>}
268
+ * @type {<P>(policy: NumberPolicy<P>) => (tokenList: List<JsonToken>) => Result<ParseUnknown<P>, string>}
196
269
  */
197
- export const parse = tokenList => {
198
- const state = fold(foldOp)({ status: '', top: null, stack: null })(tokenList)
270
+ export const parse = policy => tokenList => {
271
+ /** @type {_JsonState<never>} */
272
+ const init = { status: '', top: null, stack: null }
273
+ const state = fold(foldOp(policy))(init)(tokenList)
199
274
  switch (state.status) {
200
275
  case 'result': return ok(state.value)
201
276
  case 'error': return error(state.message)
@@ -203,17 +278,3 @@ export const parse = tokenList => {
203
278
  }
204
279
  }
205
280
 
206
- export const proof = {
207
- pushKey: {
208
- // `pushKey` is only ever invoked while `state.top` is an object (the
209
- // state machine's `'{'`/`'{,'` statuses guarantee it), so its
210
- // non-object guard is a defensive branch unreachable through `parse`.
211
- // Call it directly to cover that branch.
212
- nonObjectTop: () => {
213
- /** @type {_StateParse} */
214
- const state = { status: '[', top: { kind: 'array', values: null }, stack: null }
215
- const result = pushKey(state)('key')
216
- assertEq(result.status, 'error')
217
- },
218
- },
219
- }
@@ -1,8 +1,13 @@
1
1
  /**
2
2
  * @import { JsonToken } from '../tokenizer/types.ts'
3
+ * @import { NumberPolicy } from './types.ts'
3
4
  */
4
5
  export declare const proof: {
5
6
  valid: (() => void)[];
6
7
  invalid: (() => void)[];
7
8
  siblingContainers: (() => void)[];
9
+ policy: {
10
+ exactLexeme: () => void;
11
+ rejected: () => void;
12
+ };
8
13
  };
@@ -1,18 +1,26 @@
1
1
  /**
2
2
  * @import { JsonToken } from '../tokenizer/types.ts'
3
+ * @import { NumberPolicy } from './types.ts'
3
4
  */
4
5
 
5
- import { parse } from './module.f.mjs'
6
+ import { parse as parseWithPolicy } from './module.f.mjs'
6
7
  import { tokenize } from '../tokenizer/module.f.mjs'
7
8
  import { toArray } from '../../../types/list/module.f.mjs'
8
9
  import { stringify as jsonStringify } from '../module.f.mjs'
9
10
  import { sort } from '../../../types/object/module.f.mjs'
10
11
  import { stringToList } from '../../../text/utf16/module.f.mjs'
12
+ import { error, ok } from '../../../types/result/module.f.mjs'
11
13
  import { assertEq } from '../../../asserts/module.f.mjs'
12
14
 
13
15
  /** @type {(s: string) => readonly JsonToken[]} */
14
16
  const tokenizeString = s => toArray(tokenize(stringToList(s)))
15
17
 
18
+ /** The structural machine is proved through the ordinary `number` policy. */
19
+ /** @type {NumberPolicy<number>} */
20
+ const numberPolicy = token => ok(parseFloat(token.value))
21
+
22
+ const parse = parseWithPolicy(numberPolicy)
23
+
16
24
  const stringify = jsonStringify(sort)
17
25
 
18
26
  export const proof = {
@@ -311,4 +319,26 @@ export const proof = {
311
319
  assertEq(Array.isArray(value) ? value.length : -1, 12000)
312
320
  },
313
321
  ],
322
+ // The numeric policy is the parser's only opinion about numbers: it is
323
+ // handed the token, so it reads the exact lexeme, and it may reject one.
324
+ policy: {
325
+ // the lexeme reaches the policy unrounded — `1.0`, `1e0` and `1` are
326
+ // one `number` but three tokens
327
+ exactLexeme: () => {
328
+ /** @type {NumberPolicy<string>} */
329
+ const lexemePolicy = token => ok(token.value)
330
+ const [tag, value] = parseWithPolicy(lexemePolicy)(tokenizeString('[1.0,1e0,1,-0]'))
331
+ assertEq(tag, 'ok')
332
+ assertEq(stringify(value), '["1.0","1e0","1","-0"]')
333
+ },
334
+ // a policy that cannot represent the number fails the parse as an
335
+ // ordinary `Result`, with its own message
336
+ rejected: () => {
337
+ /** @type {NumberPolicy<never>} */
338
+ const rejectPolicy = () => error('no numbers here')
339
+ const [tag, message] = parseWithPolicy(rejectPolicy)(tokenizeString('{"a":[1]}'))
340
+ assertEq(tag, 'error')
341
+ assertEq(message, 'no numbers here')
342
+ },
343
+ },
314
344
  }
@@ -1,34 +1,58 @@
1
1
  /**
2
- * Internal state types for the JSON parser.
2
+ * Types for the shared structural JSON parser: its numeric policy, the tree
3
+ * that policy produces, and the parser's internal state.
3
4
  *
4
5
  * @module
5
6
  */
6
- import type { Unknown } from '../types.ts';
7
+ import type { Tree } from '../types.ts';
7
8
  import type { OrderedMap } from '../../../types/ordered_map/types.ts';
8
9
  import type { List } from '../../../types/list/types.ts';
9
- export type _JsonObject = {
10
+ import type { Result } from '../../../types/result/types.ts';
11
+ import type { JsonToken } from '../tokenizer/types.ts';
12
+ import type { NumberToken } from '../../../js/tokenizer/types.ts';
13
+ /** JSON tokens that carry a directly-usable value. */
14
+ export type _ValueToken = Extract<JsonToken, {
15
+ readonly kind: 'null' | 'false' | 'true' | 'string' | 'number';
16
+ }>;
17
+ /**
18
+ * A numeric policy: how one codec materializes a JSON number token into its
19
+ * own numeric domain `P`.
20
+ *
21
+ * The policy is handed the token itself, so it decides from the exact lexeme —
22
+ * before any narrowing the parser might otherwise have imposed. It may fail:
23
+ * a valid JSON number can be outside the domain the codec offers (the extended
24
+ * codec has no non-finite `number`), and that has to be an ordinary parse
25
+ * error rather than an escaping runtime exception.
26
+ */
27
+ export type NumberPolicy<P> = (token: NumberToken) => Result<P, string>;
28
+ /**
29
+ * The tree a numeric policy `P` parses into: JSON's containers over `P` plus
30
+ * the primitives every policy shares.
31
+ */
32
+ export type ParseUnknown<P> = Tree<P | null | boolean | string>;
33
+ export type _JsonObject<P> = {
10
34
  readonly kind: 'object';
11
- readonly values: OrderedMap<Unknown>;
35
+ readonly values: OrderedMap<ParseUnknown<P>>;
12
36
  readonly key: string;
13
37
  };
14
- export type _JsonArray = {
38
+ export type _JsonArray<P> = {
15
39
  readonly kind: 'array';
16
- readonly values: List<Unknown>;
40
+ readonly values: List<ParseUnknown<P>>;
17
41
  };
18
- type _JsonStackElement = _JsonObject | _JsonArray;
19
- export type _JsonStack = List<_JsonStackElement>;
20
- export type _StateParse = {
42
+ type _JsonStackElement<P> = _JsonObject<P> | _JsonArray<P>;
43
+ export type _JsonStack<P> = List<_JsonStackElement<P>>;
44
+ export type _StateParse<P> = {
21
45
  readonly status: '' | '[' | '[v' | '[,' | '{' | '{k' | '{:' | '{v' | '{,';
22
- readonly top: _JsonStackElement | null;
23
- readonly stack: _JsonStack;
46
+ readonly top: _JsonStackElement<P> | null;
47
+ readonly stack: _JsonStack<P>;
24
48
  };
25
- type _StateResult = {
49
+ type _StateResult<P> = {
26
50
  readonly status: 'result';
27
- readonly value: Unknown;
51
+ readonly value: ParseUnknown<P>;
28
52
  };
29
53
  type _StateError = {
30
54
  readonly status: 'error';
31
55
  readonly message: string;
32
56
  };
33
- export type _JsonState = _StateParse | _StateResult | _StateError;
57
+ export type _JsonState<P> = _StateParse<P> | _StateResult<P> | _StateError;
34
58
  export {};
@@ -8,7 +8,7 @@
8
8
  * `typeof`. That spelling is deliberate: `@type {const}` also type-checks here,
9
9
  * but leaves declaration emit no name for the recursive positions, so it
10
10
  * inlines the structure, gives up at depth, and degrades the emitted `.d.mts`
11
- * to `any`. See AGENTS.md §6.2.
11
+ * to `any`. See `fjs/AGENTS.md` §3.2.
12
12
  *
13
13
  * The TypeScript counterparts live in the sibling
14
14
  * [`../types.ts`](../types.ts), which pins them against these schemas with
@@ -8,7 +8,7 @@
8
8
  * `typeof`. That spelling is deliberate: `@type {const}` also type-checks here,
9
9
  * but leaves declaration emit no name for the recursive positions, so it
10
10
  * inlines the structure, gives up at depth, and degrades the emitted `.d.mts`
11
- * to `any`. See AGENTS.md §6.2.
11
+ * to `any`. See `fjs/AGENTS.md` §3.2.
12
12
  *
13
13
  * The TypeScript counterparts live in the sibling
14
14
  * [`../types.ts`](../types.ts), which pins them against these schemas with
@@ -2,6 +2,9 @@
2
2
  * Proof for the JSON rtti schemas.
3
3
  *
4
4
  * @module
5
+ *
6
+ * @import { ValidateE } from '../../../types/rtti/common/types.ts'
7
+ * @import { Unknown } from '../../../types/rtti/ts/types.ts'
5
8
  */
6
9
  export declare const proof: {
7
10
  primitive: {
@@ -2,26 +2,26 @@
2
2
  * Proof for the JSON rtti schemas.
3
3
  *
4
4
  * @module
5
+ *
6
+ * @import { ValidateE } from '../../../types/rtti/common/types.ts'
7
+ * @import { Unknown } from '../../../types/rtti/ts/types.ts'
5
8
  */
6
9
 
7
10
  import { assertEq } from '../../../asserts/module.f.mjs'
8
- import { validate } from '../../../types/rtti/validate/module.f.mjs'
11
+ import { parse } from '../../../types/rtti/parse/module.f.mjs'
9
12
  import { primitive, unknown, object, array } from './module.f.mjs'
10
13
 
11
- /** @import { ValidateE } from '../../../types/rtti/common/types.ts' */
12
- /** @import { Unknown } from '../../../types/rtti/ts/types.ts' */
13
-
14
- // Reduces a validation to its `ok`/`error` tag: these schemas are about what is
15
- // accepted, not about the payload, which validation returns unchanged. The
16
- // erased `ValidateE` keeps the shared helper from re-instantiating each
17
- // schema's deep recursive result type (TS2589).
14
+ // Reduces a parse to its `ok`/`error` tag: these schemas are about what is
15
+ // accepted, not about the payload `parse` rebuilds. The erased `ValidateE`
16
+ // keeps the shared helper from re-instantiating each schema's deep recursive
17
+ // result type (TS2589).
18
18
  /** @type {(v: ValidateE) => (value: Unknown) => string} */
19
19
  const tag = v => value => v(value)[0]
20
20
 
21
- const primitiveAccepts = tag(validate(primitive))
22
- const unknownAccepts = tag(validate(unknown))
23
- const objectAccepts = tag(validate(object))
24
- const arrayAccepts = tag(validate(array))
21
+ const primitiveAccepts = tag(parse(primitive))
22
+ const unknownAccepts = tag(parse(unknown))
23
+ const objectAccepts = tag(parse(object))
24
+ const arrayAccepts = tag(parse(array))
25
25
 
26
26
  export const proof = {
27
27
  primitive: {