functionalscript 0.45.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 (296) 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 +10 -0
  4. package/fjs/asn.1/proof.f.mjs +16 -0
  5. package/fjs/basen/base128/module.f.mjs +22 -5
  6. package/fjs/bnf/data/module.f.d.mts +32 -6
  7. package/fjs/bnf/data/module.f.mjs +112 -7
  8. package/fjs/bnf/data/proof.f.d.mts +2 -0
  9. package/fjs/bnf/data/proof.f.mjs +74 -3
  10. package/fjs/bnf/data/types.d.ts +20 -2
  11. package/fjs/bnf/descent/module.f.d.mts +28 -14
  12. package/fjs/bnf/descent/module.f.mjs +122 -77
  13. package/fjs/bnf/descent/proof.f.d.mts +2 -0
  14. package/fjs/bnf/descent/proof.f.mjs +117 -31
  15. package/fjs/bnf/descent/types.d.ts +12 -14
  16. package/fjs/bnf/ll1/module.f.d.mts +64 -22
  17. package/fjs/bnf/ll1/module.f.mjs +214 -154
  18. package/fjs/bnf/ll1/proof.f.d.mts +15 -2
  19. package/fjs/bnf/ll1/proof.f.mjs +323 -149
  20. package/fjs/bnf/ll1/types.d.ts +16 -24
  21. package/fjs/bnf/matcher/module.f.d.mts +66 -0
  22. package/fjs/bnf/matcher/module.f.mjs +81 -0
  23. package/fjs/bnf/matcher/proof.f.d.mts +10 -0
  24. package/fjs/bnf/matcher/proof.f.mjs +79 -0
  25. package/fjs/bnf/matcher/types.d.ts +54 -0
  26. package/fjs/bnf/testlib.f.d.mts +31 -0
  27. package/fjs/bnf/testlib.f.mjs +80 -0
  28. package/fjs/cas/cli/module.f.d.mts +1 -1
  29. package/fjs/cas/cli/module.f.mjs +14 -20
  30. package/fjs/cas/cli/proof.f.d.mts +1 -3
  31. package/fjs/cas/cli/proof.f.mjs +44 -33
  32. package/fjs/cas/evo/module.f.d.mts +64 -18
  33. package/fjs/cas/evo/module.f.mjs +148 -70
  34. package/fjs/cas/evo/proof.f.d.mts +10 -1
  35. package/fjs/cas/evo/proof.f.mjs +305 -223
  36. package/fjs/cas/evo/types.d.ts +45 -9
  37. package/fjs/cas/module.f.d.mts +18 -32
  38. package/fjs/cas/module.f.mjs +129 -128
  39. package/fjs/cas/proof.f.d.mts +11 -8
  40. package/fjs/cas/proof.f.mjs +259 -147
  41. package/fjs/cas/types.d.ts +24 -10
  42. package/fjs/ci/config/module.f.d.mts +2 -2
  43. package/fjs/ci/config/module.f.mjs +2 -2
  44. package/fjs/ci/module.f.d.mts +5 -5
  45. package/fjs/ci/module.f.mjs +8 -7
  46. package/fjs/ci/nix/module.f.d.mts +7 -5
  47. package/fjs/ci/nix/module.f.mjs +13 -12
  48. package/fjs/ci/nix/proof.f.mjs +2 -2
  49. package/fjs/ci/proof.f.mjs +9 -5
  50. package/fjs/cli/module.f.d.mts +4 -6
  51. package/fjs/cli/module.f.mjs +4 -8
  52. package/fjs/cli/proof.f.mjs +17 -16
  53. package/fjs/cli/types.d.ts +2 -3
  54. package/fjs/common/monoid/types.d.ts +1 -1
  55. package/fjs/crypto/hmac/module.f.mjs +2 -2
  56. package/fjs/crypto/sha2/module.f.mjs +3 -1
  57. package/fjs/crypto/sha2/proof.f.d.mts +1 -0
  58. package/fjs/crypto/sha2/proof.f.mjs +24 -0
  59. package/fjs/crypto/sha2/types.d.ts +11 -0
  60. package/fjs/crypto/sign/module.f.mjs +2 -2
  61. package/fjs/dev/module.f.d.mts +13 -4
  62. package/fjs/dev/module.f.mjs +56 -27
  63. package/fjs/dev/update/module.f.d.mts +9 -4
  64. package/fjs/dev/update/module.f.mjs +14 -10
  65. package/fjs/dev/update/proof.f.d.mts +1 -3
  66. package/fjs/dev/update/proof.f.mjs +10 -5
  67. package/fjs/djs/module.f.d.mts +13 -5
  68. package/fjs/djs/module.f.mjs +31 -16
  69. package/fjs/djs/parser/module.f.d.mts +13 -3
  70. package/fjs/djs/parser/module.f.mjs +117 -16
  71. package/fjs/djs/parser/proof.f.d.mts +5 -1
  72. package/fjs/djs/parser/proof.f.mjs +274 -12
  73. package/fjs/djs/parser/types.d.ts +7 -1
  74. package/fjs/djs/proof.f.d.mts +18 -2
  75. package/fjs/djs/proof.f.mjs +187 -12
  76. package/fjs/djs/serializer/module.f.d.mts +25 -8
  77. package/fjs/djs/serializer/module.f.mjs +61 -15
  78. package/fjs/djs/serializer/proof.f.d.mts +5 -0
  79. package/fjs/djs/serializer/proof.f.mjs +23 -1
  80. package/fjs/djs/tokenizer/module.f.d.mts +17 -5
  81. package/fjs/djs/tokenizer/module.f.mjs +99 -60
  82. package/fjs/djs/tokenizer/proof.f.d.mts +1 -1
  83. package/fjs/djs/tokenizer/proof.f.mjs +74 -67
  84. package/fjs/djs/transpiler/module.f.d.mts +12 -7
  85. package/fjs/djs/transpiler/module.f.mjs +82 -56
  86. package/fjs/djs/transpiler/types.d.ts +7 -3
  87. package/fjs/djs/types.d.ts +7 -1
  88. package/fjs/effects/list/module.f.d.mts +14 -11
  89. package/fjs/effects/list/module.f.mjs +13 -11
  90. package/fjs/effects/list/types.d.ts +27 -7
  91. package/fjs/effects/memory/module.f.d.mts +2 -1
  92. package/fjs/effects/memory/module.f.mjs +3 -4
  93. package/fjs/effects/memory/proof.f.mjs +13 -7
  94. package/fjs/effects/memory/types.d.ts +4 -3
  95. package/fjs/effects/mock/module.f.d.mts +20 -4
  96. package/fjs/effects/mock/module.f.mjs +37 -5
  97. package/fjs/effects/mock/types.d.ts +10 -1
  98. package/fjs/effects/module.d.mts +4 -2
  99. package/fjs/effects/module.f.d.mts +466 -280
  100. package/fjs/effects/module.f.mjs +537 -299
  101. package/fjs/effects/module.mjs +2 -1
  102. package/fjs/effects/node/memory/module.d.mts +4 -2
  103. package/fjs/effects/node/memory/module.mjs +6 -3
  104. package/fjs/effects/node/memory/proof.mjs +10 -4
  105. package/fjs/effects/node/module.d.mts +4 -3
  106. package/fjs/effects/node/module.f.d.mts +168 -33
  107. package/fjs/effects/node/module.f.mjs +256 -52
  108. package/fjs/effects/node/module.mjs +57 -34
  109. package/fjs/effects/node/proof.f.d.mts +28 -2
  110. package/fjs/effects/node/proof.f.mjs +161 -42
  111. package/fjs/effects/node/types.d.ts +106 -18
  112. package/fjs/effects/node/virtual/module.f.d.mts +18 -4
  113. package/fjs/effects/node/virtual/module.f.mjs +110 -68
  114. package/fjs/effects/node/virtual/proof.f.d.mts +28 -2
  115. package/fjs/effects/node/virtual/proof.f.mjs +190 -9
  116. package/fjs/effects/proof.f.d.mts +69 -37
  117. package/fjs/effects/proof.f.mjs +410 -130
  118. package/fjs/effects/types.d.ts +161 -33
  119. package/fjs/emergent_testing/module.f.d.mts +19 -12
  120. package/fjs/emergent_testing/module.f.mjs +93 -33
  121. package/fjs/emergent_testing/proof.f.d.mts +21 -7
  122. package/fjs/emergent_testing/proof.f.mjs +166 -32
  123. package/fjs/emergent_testing/types.d.ts +22 -4
  124. package/fjs/fsm/module.f.d.mts +14 -4
  125. package/fjs/fsm/module.f.mjs +54 -37
  126. package/fjs/fsm/proof.f.d.mts +2 -0
  127. package/fjs/fsm/proof.f.mjs +83 -114
  128. package/fjs/js/keywords/module.f.d.mts +52 -0
  129. package/fjs/js/keywords/module.f.mjs +72 -0
  130. package/fjs/js/keywords/proof.f.d.mts +3 -0
  131. package/fjs/js/keywords/proof.f.mjs +13 -0
  132. package/fjs/js/tokenizer/module.f.d.mts +26 -6
  133. package/fjs/js/tokenizer/module.f.mjs +145 -159
  134. package/fjs/js/tokenizer/proof.f.d.mts +1 -0
  135. package/fjs/js/tokenizer/proof.f.mjs +54 -24
  136. package/fjs/js/tokenizer/types.d.ts +33 -24
  137. package/fjs/mcp/cas/module.f.d.mts +1 -6
  138. package/fjs/mcp/cas/module.f.mjs +55 -51
  139. package/fjs/mcp/cas/proof.f.d.mts +15 -0
  140. package/fjs/mcp/cas/proof.f.mjs +174 -0
  141. package/fjs/mcp/evo/module.f.d.mts +19 -10
  142. package/fjs/mcp/evo/module.f.mjs +48 -27
  143. package/fjs/mcp/evo/proof.f.d.mts +6 -1
  144. package/fjs/mcp/evo/proof.f.mjs +115 -31
  145. package/fjs/mcp/module.f.d.mts +4 -4
  146. package/fjs/mcp/module.f.mjs +6 -6
  147. package/fjs/mcp/proof.f.d.mts +5 -3
  148. package/fjs/mcp/proof.f.mjs +112 -46
  149. package/fjs/media/html/module.f.mjs +1 -1
  150. package/fjs/media/json/extended/module.f.d.mts +82 -0
  151. package/fjs/media/json/extended/module.f.mjs +153 -0
  152. package/fjs/media/json/extended/proof.f.d.mts +42 -0
  153. package/fjs/media/json/extended/proof.f.mjs +127 -0
  154. package/fjs/media/json/extended/types.d.ts +23 -0
  155. package/fjs/media/json/module.f.d.mts +8 -2
  156. package/fjs/media/json/module.f.mjs +43 -41
  157. package/fjs/media/json/number/module.f.d.mts +59 -0
  158. package/fjs/media/json/number/module.f.mjs +136 -0
  159. package/fjs/media/json/number/proof.f.d.mts +24 -0
  160. package/fjs/media/json/number/proof.f.mjs +86 -0
  161. package/fjs/media/json/number/types.d.ts +28 -0
  162. package/fjs/media/json/parser/module.f.d.mts +25 -13
  163. package/fjs/media/json/parser/module.f.mjs +114 -70
  164. package/fjs/media/json/parser/proof.f.d.mts +5 -0
  165. package/fjs/media/json/parser/proof.f.mjs +31 -1
  166. package/fjs/media/json/parser/types.d.ts +33 -14
  167. package/fjs/media/json/rtti/module.f.d.mts +1 -1
  168. package/fjs/media/json/rtti/module.f.mjs +1 -1
  169. package/fjs/media/json/rtti/proof.f.mjs +9 -9
  170. package/fjs/media/json/schema/module.f.mjs +3 -13
  171. package/fjs/media/json/schema/proof.f.d.mts +0 -1
  172. package/fjs/media/json/schema/proof.f.mjs +1 -2
  173. package/fjs/media/json/serializer/module.f.d.mts +32 -1
  174. package/fjs/media/json/serializer/module.f.mjs +64 -2
  175. package/fjs/media/json/tokenizer/module.f.mjs +7 -3
  176. package/fjs/media/json/tokenizer/proof.f.d.mts +6 -0
  177. package/fjs/media/json/tokenizer/proof.f.mjs +62 -21
  178. package/fjs/media/json/types.d.ts +36 -10
  179. package/fjs/media/lock/module.f.d.mts +100 -0
  180. package/fjs/media/lock/module.f.mjs +125 -0
  181. package/fjs/media/lock/proof.f.d.mts +33 -0
  182. package/fjs/media/lock/proof.f.mjs +196 -0
  183. package/fjs/media/lock/types.d.ts +15 -0
  184. package/fjs/media/module.f.d.mts +6 -5
  185. package/fjs/media/module.f.mjs +8 -7
  186. package/fjs/media/note/module.f.d.mts +121 -0
  187. package/fjs/media/note/module.f.mjs +131 -0
  188. package/fjs/media/note/proof.f.d.mts +29 -0
  189. package/fjs/media/note/proof.f.mjs +150 -0
  190. package/fjs/media/note/types.d.ts +10 -0
  191. package/fjs/media/proof.f.d.mts +4 -1
  192. package/fjs/media/proof.f.mjs +40 -21
  193. package/fjs/media/revision/module.f.d.mts +78 -7
  194. package/fjs/media/revision/module.f.mjs +119 -12
  195. package/fjs/media/revision/proof.f.d.mts +10 -0
  196. package/fjs/media/revision/proof.f.mjs +88 -0
  197. package/fjs/media/revision/types.d.ts +34 -5
  198. package/fjs/media/type/module.f.d.mts +33 -15
  199. package/fjs/media/type/module.f.mjs +35 -29
  200. package/fjs/media/type/proof.f.d.mts +2 -1
  201. package/fjs/media/type/proof.f.mjs +30 -10
  202. package/fjs/module.f.mjs +29 -8
  203. package/fjs/nanvm/proof.f.mjs +3 -3
  204. package/fjs/nanvm/rust/module.f.mjs +1 -1
  205. package/fjs/nanvm/update/module.f.d.mts +4 -4
  206. package/fjs/nanvm/update/module.f.mjs +8 -9
  207. package/fjs/nanvm/update/proof.f.mjs +4 -3
  208. package/fjs/proof.f.d.mts +3 -3
  209. package/fjs/proof.f.mjs +36 -10
  210. package/fjs/protocol/json_rpc/module.f.d.mts +2 -2
  211. package/fjs/protocol/json_rpc/module.f.mjs +3 -3
  212. package/fjs/protocol/json_rpc/proof.f.mjs +4 -4
  213. package/fjs/protocol/mcp/module.f.d.mts +10 -13
  214. package/fjs/protocol/mcp/module.f.mjs +74 -58
  215. package/fjs/protocol/mcp/proof.f.d.mts +13 -4
  216. package/fjs/protocol/mcp/proof.f.mjs +193 -61
  217. package/fjs/protocol/mcp/stdio/module.f.d.mts +15 -7
  218. package/fjs/protocol/mcp/stdio/module.f.mjs +38 -25
  219. package/fjs/protocol/mcp/stdio/proof.f.d.mts +4 -2
  220. package/fjs/protocol/mcp/stdio/proof.f.mjs +45 -12
  221. package/fjs/protocol/mcp/stdio/types.d.ts +1 -1
  222. package/fjs/protocol/mcp/types.d.ts +17 -6
  223. package/fjs/sul/id/module.f.d.mts +0 -1
  224. package/fjs/sul/id/module.f.mjs +2 -3
  225. package/fjs/sul/level/hash/module.f.mjs +2 -1
  226. package/fjs/sul/level/hash/proof.f.mjs +2 -2
  227. package/fjs/sul/module.f.mjs +18 -13
  228. package/fjs/text/code_point/module.f.d.mts +8 -0
  229. package/fjs/text/code_point/module.f.mjs +8 -1
  230. package/fjs/text/code_point/proof.f.d.mts +1 -0
  231. package/fjs/text/code_point/proof.f.mjs +11 -0
  232. package/fjs/text/sgr/module.f.d.mts +4 -6
  233. package/fjs/text/sgr/module.f.mjs +6 -7
  234. package/fjs/text/utf16/module.f.mjs +7 -2
  235. package/fjs/text/utf16/proof.f.mjs +3 -3
  236. package/fjs/text/utf8/module.f.mjs +4 -2
  237. package/fjs/types/array/module.f.mjs +14 -2
  238. package/fjs/types/bit_vec/module.f.d.mts +0 -2
  239. package/fjs/types/bit_vec/module.f.mjs +46 -32
  240. package/fjs/types/bit_vec/proof.f.mjs +2 -2
  241. package/fjs/types/btree/remove/module.f.mjs +1 -1
  242. package/fjs/types/btree/set/module.f.mjs +9 -11
  243. package/fjs/types/btree/set/proof.f.mjs +12 -0
  244. package/fjs/types/byte_set/module.f.d.mts +11 -4
  245. package/fjs/types/byte_set/module.f.mjs +14 -6
  246. package/fjs/types/byte_set/proof.f.mjs +7 -7
  247. package/fjs/types/function/compare/module.f.mjs +10 -3
  248. package/fjs/types/list/module.f.d.mts +1 -1
  249. package/fjs/types/list/module.f.mjs +1 -1
  250. package/fjs/types/nullable/module.f.d.mts +18 -4
  251. package/fjs/types/nullable/module.f.mjs +21 -4
  252. package/fjs/types/nullable/proof.f.d.mts +4 -0
  253. package/fjs/types/nullable/proof.f.mjs +15 -0
  254. package/fjs/types/object/module.f.d.mts +12 -2
  255. package/fjs/types/object/module.f.mjs +11 -1
  256. package/fjs/types/patricia_trie/module.f.mjs +26 -11
  257. package/fjs/types/result/module.f.d.mts +3 -3
  258. package/fjs/types/result/module.f.mjs +3 -3
  259. package/fjs/types/rtti/common/module.f.d.mts +25 -28
  260. package/fjs/types/rtti/common/module.f.mjs +36 -32
  261. package/fjs/types/rtti/common/proof.f.mjs +5 -5
  262. package/fjs/types/rtti/data/module.f.d.mts +14 -0
  263. package/fjs/types/rtti/data/module.f.mjs +25 -2
  264. package/fjs/types/rtti/data/proof.f.d.mts +1 -0
  265. package/fjs/types/rtti/data/proof.f.mjs +25 -2
  266. package/fjs/types/rtti/parse/module.f.d.mts +24 -14
  267. package/fjs/types/rtti/parse/module.f.mjs +37 -28
  268. package/fjs/types/rtti/parse/proof.f.d.mts +3 -2
  269. package/fjs/types/rtti/parse/proof.f.mjs +33 -14
  270. package/fjs/types/rtti/proof.f.mjs +3 -1
  271. package/fjs/types/rtti/ts/module.f.mjs +13 -17
  272. package/fjs/types/rtti/ts/types.d.ts +14 -1
  273. package/fjs/types/sorted_set/module.f.d.mts +18 -0
  274. package/fjs/types/sorted_set/module.f.mjs +22 -0
  275. package/fjs/types/sorted_set/proof.f.d.mts +1 -0
  276. package/fjs/types/sorted_set/proof.f.mjs +16 -1
  277. package/fjs/types/uint8array/module.f.d.mts +1 -1
  278. package/fjs/types/uint8array/module.f.mjs +1 -1
  279. package/fjs/website/module.f.d.mts +3 -3
  280. package/fjs/website/module.f.mjs +4 -7
  281. package/fjs/website/proof.f.mjs +2 -1
  282. package/package.json +2 -2
  283. package/fjs/dev/package_json/module.f.d.mts +0 -39
  284. package/fjs/dev/package_json/module.f.mjs +0 -40
  285. package/fjs/dev/package_json/proof.f.d.mts +0 -6
  286. package/fjs/dev/package_json/proof.f.mjs +0 -32
  287. package/fjs/effects/eff/module.f.d.mts +0 -20
  288. package/fjs/effects/eff/module.f.mjs +0 -70
  289. package/fjs/effects/eff/proof.f.d.mts +0 -15
  290. package/fjs/effects/eff/proof.f.mjs +0 -69
  291. package/fjs/effects/eff/types.d.ts +0 -71
  292. package/fjs/types/rtti/validate/module.f.d.mts +0 -41
  293. package/fjs/types/rtti/validate/module.f.mjs +0 -171
  294. package/fjs/types/rtti/validate/proof.f.d.mts +0 -125
  295. package/fjs/types/rtti/validate/proof.f.mjs +0 -437
  296. package/fjs/types/rtti/validate/types.d.ts +0 -6
@@ -1,69 +0,0 @@
1
- /**
2
- * @import { Effect, OperationMap } from '../types.ts'
3
- */
4
-
5
- import { do_, match, pure } from '../module.f.mjs'
6
- import { assert, assertEq } from '../../asserts/module.f.mjs'
7
- import { assertPure } from '../proof.f.mjs'
8
- import { eff } from './module.f.mjs'
9
-
10
- /** @typedef {readonly['add', (a: number, b: number) => number]} _AddOp */
11
-
12
- /** @type {(command: 'add') => (a: number, b: number) => Effect<_AddOp, number>} */
13
- const doAdd = do_
14
-
15
- const next = match(/** @type {OperationMap<_AddOp, number>} */ ({ add: (a, b) => a + b }))
16
-
17
- export const proof = {
18
- value: () => {
19
- assertPure(eff(pure(5)).value, 5)
20
- },
21
- pure: () => {
22
- assertPure(pure(5), 5)
23
- },
24
- chain: () => {
25
- const x = eff(pure(5))
26
- .step(v => pure(v + 1))
27
- .step(v => pure(v * 2))
28
- .value
29
- assertPure(x, 12)
30
- },
31
- overDo: () => {
32
- const e = eff(doAdd('add')(2, 3))
33
- .step(r => pure(r + 1))
34
- .value
35
- const r = next(e)
36
- assert(r[0] === 'cont', r)
37
- assertEq(r[1], 5)
38
- assertPure(r[2](r[1]), 6)
39
- },
40
- map: {
41
- chain: () => {
42
- const x = eff(pure(5))
43
- .map(v => v + 1)
44
- .map(v => v * 2)
45
- .value
46
- assertPure(x, 12)
47
- },
48
- // `.map` grows the history exactly as `.step` does, so a callback after
49
- // it still reaches the pre-`map` value. This is the contract that makes
50
- // rewriting `.step(v => pure(f(v)))` into `.map(f)` a pure readability
51
- // change rather than one that alters what later callbacks receive.
52
- growsHistory: () => {
53
- const x = eff(pure(5))
54
- .map(v => v + 1)
55
- .step((v, prev) => pure(`${prev}${v}`))
56
- .value
57
- assertPure(x, '56')
58
- },
59
- overDo: () => {
60
- const e = eff(doAdd('add')(2, 3))
61
- .map(r => r + 1)
62
- .value
63
- const r = next(e)
64
- assert(r[0] === 'cont', r)
65
- assertEq(r[1], 5)
66
- assertPure(r[2](r[1]), 6)
67
- },
68
- },
69
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * Types for the `Eff` fluent, method-chaining monad.
3
- *
4
- * @module
5
- */
6
- import type { Effect, Operation } from '../types.ts';
7
- /**
8
- * A fluent, method-chaining monad over a raw `Effect` that also
9
- * accumulates the history of every value the chain has produced. `.step(f)`
10
- * is bind — `f` receives the current value followed by every prior value,
11
- * most recent first (`f(t, ...p)`), and returns a raw `Effect`; `.step`
12
- * re-wraps the result together with that history so `.step(f).step(g)`
13
- * chains and stays in the `Eff` world throughout. `.map(f)` is the functor
14
- * map — the same thing for an `f` that returns a plain value rather than an
15
- * effect, so it is exactly `.step((...tp) => pure(f(...tp)))`. `P` is the
16
- * tuple of prior values available to the *next* `.step` call; it grows by one
17
- * element (the current `T`) on every step, starting empty at `eff`.
18
- * `.value` is the exit back to a raw `Effect`, discarding the history. An
19
- * `Eff` is not assignable to `Effect`; unwrap through `.value`.
20
- *
21
- * **`.map` grows the history just as `.step` does, and does not widen `O`.**
22
- * Both follow from it being that `.step` call and nothing else: a chain
23
- * rewritten from `.step(v => pure(f(v)))` to `.map(f)` must hand later
24
- * callbacks the same prior values it did before, and a projection performs no
25
- * command, so it contributes no operation for a runner to interpret.
26
- *
27
- * **The history is positional, so every parameter a callback declares is
28
- * meaningful.** `f` is applied as `f(...tp)`, so a callback written
29
- * `(v, n = 1) => …` or `(v, ...rest) => …` receives prior chain values in `n` /
30
- * `rest` rather than the default or an empty rest — and where the types line up,
31
- * TypeScript will not object. Declare exactly as many parameters as the callback
32
- * intends to read; a defaulted or rest parameter after the current value is a
33
- * bug, not a convenience. This is what makes `.map(g)` a *different* call from
34
- * `.step(v => pure(g(v)))` whenever `g` is not genuinely unary — the lambda
35
- * pins the arity at one, while passing `g` point-free exposes it to the prior
36
- * values, the way `['1', '2', '3'].map(parseInt)` does.
37
- *
38
- * **`.value` is always an already-built `Effect`.** Reading it composes
39
- * nothing: the projection that drops the history tuple to its current value is
40
- * performed by the `.step` that produced the link, not deferred to the read.
41
- * An `Eff` is a record to look into, not an object with a method that quietly
42
- * does work when called.
43
- *
44
- * That costs one projection per link, paid whether or not the link is ever
45
- * unwrapped — an n-link chain builds n of them where a deferred `.result()`
46
- * method would build one. It is a constant factor on construction, with no
47
- * extra forcing of the wrapped effect and no change in growth rate, bought in
48
- * exchange for a uniform rule at the boundary every caller touches.
49
- *
50
- * At the entry it costs nothing at all: `eff(e).value` **is** `e`, because
51
- * `eff` stores what it was handed rather than rebuilding it from the
52
- * history, so wrapping and unwrapping round-trip to identity. `h` is still a
53
- * thunk, so `eff(e)` composes nothing and never forces `e`: an `Eff` that is
54
- * built and only read does no work at all.
55
- *
56
- * **`P` has no default, on purpose.** A default of `readonly[]` would make
57
- * `Eff<O, T>` a spelling that silently erases history: an
58
- * `Eff<O, T, readonly[A]>` is assignable to it, because `f` sits in a
59
- * contravariant position and TypeScript accepts a callback declaring fewer
60
- * parameters than the type it is checked against. The next `.step` callback
61
- * would then be typed as receiving no prior values while the runtime still
62
- * passes them, and any callback destructuring a rest parameter would be handed
63
- * entries its type says cannot exist. Requiring the third argument means that
64
- * erasure cannot be written at all, rather than merely being discouraged;
65
- * `eff` spells `readonly[]` itself.
66
- */
67
- export type Eff<O extends Operation, T, P extends readonly unknown[]> = {
68
- readonly value: Effect<O, T>;
69
- readonly step: <Q extends Operation, R>(f: (...tp: readonly [T, ...P]) => Effect<Q, R>) => Eff<O | Q, R, readonly [T, ...P]>;
70
- readonly map: <R>(f: (...tp: readonly [T, ...P]) => R) => Eff<O, R, readonly [T, ...P]>;
71
- };
@@ -1,41 +0,0 @@
1
- /**
2
- * Runtime validation of unknown values against RTTI schemas.
3
- *
4
- * The main entry point is `validate(rtti)`, which takes a schema `Type` and returns
5
- * a `Validate<T>` function. When called with an unknown value, it returns a `Result`
6
- * that is either `['ok', typedValue]` or `['error', { path, message }]`.
7
- *
8
- * ## Error path
9
- *
10
- * On failure, the error carries a `path` pointing at the offending sub-value:
11
- * each step is the string property name (for structs/records) or the stringified
12
- * index (for tuples/arrays). The path is empty when the failure is at the root.
13
- *
14
- * ## Dispatch strategy
15
- *
16
- * Schema recognition is delegated to `visit` in `../common/module.f.mjs`,
17
- * which routes each `Type` variant to a handler in the `Visitor` record
18
- * defined below. `validate` returns the original value on success — no
19
- * fresh allocation — which is the only behavior that distinguishes it
20
- * from `parse`.
21
- *
22
- * ## Recursion safety
23
- *
24
- * For `array` and `record` schemas, the inner item validator is instantiated lazily —
25
- * only after confirming the container is non-empty. This prevents infinite recursion
26
- * when validating recursive schemas like `const list = () => ['array', list]`.
27
- *
28
- * See `./types.ts` for the `Path`/`Result`/`Validate`/`ValidationError` type-level API.
29
- *
30
- * @module
31
- *
32
- * @import { Unknown } from '../ts/types.ts'
33
- * @import { Info1, Struct, Tag1, Tuple, Type } from '../types.ts'
34
- * @import { StringMap } from '../../object/types.ts'
35
- * @import { Container, IsContainer, Validate, ValidateE, Visitor } from '../common/types.ts'
36
- */
37
- import type { Type } from '../types.ts';
38
- import type { Validate } from '../common/types.ts';
39
- export { constPrimitiveValidate, prependPath, primitive0Validate, verror, } from '../common/module.f.mjs';
40
- /** @type {<T extends Type>(rtti: T) => Validate<T>} */
41
- export declare const validate: <T extends Type>(rtti: T) => Validate<T>;
@@ -1,171 +0,0 @@
1
- /**
2
- * Runtime validation of unknown values against RTTI schemas.
3
- *
4
- * The main entry point is `validate(rtti)`, which takes a schema `Type` and returns
5
- * a `Validate<T>` function. When called with an unknown value, it returns a `Result`
6
- * that is either `['ok', typedValue]` or `['error', { path, message }]`.
7
- *
8
- * ## Error path
9
- *
10
- * On failure, the error carries a `path` pointing at the offending sub-value:
11
- * each step is the string property name (for structs/records) or the stringified
12
- * index (for tuples/arrays). The path is empty when the failure is at the root.
13
- *
14
- * ## Dispatch strategy
15
- *
16
- * Schema recognition is delegated to `visit` in `../common/module.f.mjs`,
17
- * which routes each `Type` variant to a handler in the `Visitor` record
18
- * defined below. `validate` returns the original value on success — no
19
- * fresh allocation — which is the only behavior that distinguishes it
20
- * from `parse`.
21
- *
22
- * ## Recursion safety
23
- *
24
- * For `array` and `record` schemas, the inner item validator is instantiated lazily —
25
- * only after confirming the container is non-empty. This prevents infinite recursion
26
- * when validating recursive schemas like `const list = () => ['array', list]`.
27
- *
28
- * See `./types.ts` for the `Path`/`Result`/`Validate`/`ValidationError` type-level API.
29
- *
30
- * @module
31
- *
32
- * @import { Unknown } from '../ts/types.ts'
33
- * @import { Info1, Struct, Tag1, Tuple, Type } from '../types.ts'
34
- * @import { StringMap } from '../../object/types.ts'
35
- * @import { Container, IsContainer, Validate, ValidateE, Visitor } from '../common/types.ts'
36
- */
37
-
38
- import { ok } from '../../result/module.f.mjs'
39
- import {
40
- constPrimitiveValidate,
41
- eachEntry,
42
- isArray,
43
- isObject,
44
- orVisit,
45
- primitive0Validate,
46
- verror,
47
- visit,
48
- } from '../common/module.f.mjs'
49
-
50
- export {
51
- constPrimitiveValidate,
52
- prependPath,
53
- primitive0Validate,
54
- verror,
55
- } from '../common/module.f.mjs'
56
-
57
- const { entries } = Object
58
-
59
- /** `validate` has nothing to collect from a successful entry — only pass/fail matters. */
60
- const noAccumulate = () => undefined
61
-
62
- /**
63
- * Builds a validator for `array` or `record` schemas.
64
- * The inner item validator is instantiated lazily (only when the container is
65
- * non-empty) to avoid infinite recursion with recursive schemas.
66
- */
67
- const containerValidate =
68
- /**
69
- * @template {Tag1} K
70
- * @param {IsContainer<Container<K>>} isContainer
71
- * @returns {<I extends Type>(item: I) => Validate<Info1<K, I>>}
72
- */
73
- isContainer =>
74
- item => value => {
75
- if (!isContainer(value)) {
76
- return verror('unexpected value')
77
- }
78
- const e = entries(value)
79
- if (e.length === 0) {
80
- return ok(value)
81
- }
82
- // Note: we shouldn't instantiate `itemValidate` until we make sure `entries` is not empty.
83
- // Otherwise, we can get infinite recursion on empty arrays and objects
84
- const itemValidate = validate(item)
85
- const r = eachEntry(e, (_k, v) => itemValidate(v), undefined, noAccumulate)
86
- // `value` is Container<K>, but Ts<Info1<K,I>> = readonly Ts<I>[] | Record<string,Ts<I>>.
87
- // TypeScript can't narrow the container's element types through the validation loop.
88
- return r[0] === 'error' ? r : /** @type {any} */ (ok(value))
89
- }
90
-
91
- const arrayValidate = containerValidate(isArray)
92
-
93
- const recordValidate = containerValidate(isObject)
94
-
95
- /**
96
- * Builds a validator for `Tuple` or `Struct` const schemas.
97
- * Iterates over the schema's entries and validates each corresponding
98
- * element/property of the value.
99
- */
100
- const constContainerValidate =
101
- /**
102
- * @template {Unknown} C
103
- * @param {IsContainer<C>} isContainer
104
- * @param {(value: C, k: string) => Unknown} getItem
105
- * @returns {<T extends Tuple | Struct>(rtti: T) => Validate<T>}
106
- */
107
- (isContainer, getItem) =>
108
- rtti => value => {
109
- if (!isContainer(value)) {
110
- return verror('unexpected value')
111
- }
112
- const r = eachEntry(
113
- Object.entries(rtti),
114
- (k, v) => /** @type {any} */ (validate(v))(getItem(value, k)),
115
- undefined,
116
- noAccumulate,
117
- )
118
- // `value` is C (Unknown container), but Ts<T> for T extends Tuple|Struct is not
119
- // structurally equivalent to C — TypeScript can't narrow element types through the loop.
120
- return r[0] === 'error' ? r : /** @type {any} */ (ok(value))
121
- }
122
-
123
- const tupleValidate = constContainerValidate(
124
- isArray,
125
- (value, k) => value[Number(k)]
126
- )
127
-
128
- const structValidate = constContainerValidate(
129
- isObject,
130
- (value, k) => value[k]
131
- )
132
-
133
- const orValidate =
134
- /**
135
- * @template {readonly Type[]} T
136
- * @param {T} rtti
137
- * @returns {Validate<() => readonly ['or', ...T]>}
138
- */
139
- rtti =>
140
- /** @type {any} */ (orVisit(/** @type {(t: Type) => ValidateE} */ (/** @type {any} */ (validate)))(rtti))
141
-
142
- /**
143
- * Creates a validator function for the given RTTI schema.
144
- *
145
- * @param rtti - A schema `Type`: a `Thunk` for tag-based schemas, or a `Const`
146
- * (primitive literal, tuple, or struct) for exact-value schemas.
147
- * @returns A `Validate<T>` function that checks an unknown value and returns
148
- * `['ok', value]` or `['error', { path, message }]`.
149
- *
150
- * @example
151
- * ```js
152
- * const v = validate(array(number))
153
- * v([1, 2, 3]) // ['ok', [1, 2, 3]]
154
- * v([1, 'two']) // ['error', { path: ['1'], message: 'unexpected value' }]
155
- * v(['a']) // ['error', { path: ['0'], message: 'unexpected value' }]
156
- * ```
157
- */
158
- const validateVisitor = /** @type {any} */ ({
159
- tuple: tupleValidate,
160
- struct: structValidate,
161
- array: arrayValidate,
162
- record: recordValidate,
163
- or: orValidate,
164
- constPrimitive: constPrimitiveValidate,
165
- primitive0: primitive0Validate,
166
- unknown: () => ok,
167
- })
168
-
169
- /** @type {<T extends Type>(rtti: T) => Validate<T>} */
170
- export const validate = rtti =>
171
- /** @type {any} */ (visit(validateVisitor)(rtti))
@@ -1,125 +0,0 @@
1
- /**
2
- * @import { ValidationError } from '../common/types.ts'
3
- * @import { Equal } from '../../ts/types.ts'
4
- * @import { Ts } from '../ts/types.ts'
5
- * @import { Unknown as DjsUnknown } from '../../../djs/types.ts'
6
- * @import { Assert } from '../../../asserts/types.ts'
7
- */
8
- export declare const proof: {
9
- boolean: {
10
- ok: () => void;
11
- error: () => void;
12
- };
13
- number: {
14
- ok: () => void;
15
- error: () => void;
16
- };
17
- string: {
18
- ok: () => void;
19
- error: () => void;
20
- };
21
- bigint: {
22
- ok: () => void;
23
- error: () => void;
24
- };
25
- unknown: {
26
- ok: () => void;
27
- };
28
- const: {
29
- null: {
30
- ok: () => void;
31
- error: () => void;
32
- };
33
- undefined: {
34
- ok: () => void;
35
- error: () => void;
36
- };
37
- number: {
38
- ok: () => void;
39
- error: () => void;
40
- };
41
- nan: {
42
- ok: () => void;
43
- error: () => void;
44
- };
45
- infinity: {
46
- ok: () => void;
47
- error: () => void;
48
- };
49
- signedZero: {
50
- distinct: () => void;
51
- self: () => void;
52
- };
53
- string: {
54
- ok: () => void;
55
- error: () => void;
56
- };
57
- bigint: {
58
- ok: () => void;
59
- error: () => void;
60
- };
61
- boolean: {
62
- ok: () => void;
63
- error: () => void;
64
- };
65
- tuple: {
66
- ok: () => void;
67
- extraItems: () => void;
68
- error: () => void;
69
- };
70
- struct: {
71
- ok: () => void;
72
- extraKeys: () => void;
73
- error: () => void;
74
- };
75
- };
76
- array: {
77
- empty: () => void;
78
- ok: () => void;
79
- error: () => void;
80
- nested: () => void;
81
- };
82
- record: {
83
- empty: () => void;
84
- ok: () => void;
85
- error: () => void;
86
- };
87
- constThunk: {
88
- primitive: () => void;
89
- };
90
- or: {
91
- consts: {
92
- ok: () => void;
93
- error: () => void;
94
- };
95
- thunks: {
96
- ok: () => void;
97
- error: () => void;
98
- };
99
- mixed: {
100
- ok: () => void;
101
- error: () => void;
102
- };
103
- };
104
- option: {
105
- ok: () => void;
106
- error: () => void;
107
- };
108
- path: {
109
- rootMismatch: () => void;
110
- arrayIndex: () => void;
111
- recordKey: () => void;
112
- nestedArray: () => void;
113
- tupleIndex: () => void;
114
- structKey: () => void;
115
- deepStruct: () => void;
116
- recursiveSchema: () => void;
117
- orRoot: () => void;
118
- };
119
- recursive: {
120
- arrayOfArrays: () => void;
121
- recordOfRecords: () => void;
122
- };
123
- funcParam: () => () => void;
124
- funcObj: () => () => void;
125
- };