functionalscript 0.19.0 → 0.20.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 (219) hide show
  1. package/fs/asn.1/{test.f.d.ts → proof.f.d.ts} +1 -2
  2. package/fs/asn.1/{test.f.js → proof.f.js} +1 -1
  3. package/fs/base128/proof.f.d.ts +1 -0
  4. package/fs/base128/{test.f.js → proof.f.js} +1 -1
  5. package/fs/bnf/data/{test.f.d.ts → proof.f.d.ts} +1 -2
  6. package/fs/bnf/data/{test.f.js → proof.f.js} +1 -1
  7. package/fs/bnf/proof.f.d.ts +3 -0
  8. package/fs/bnf/{test.f.js → proof.f.js} +1 -1
  9. package/fs/cas/module.f.js +2 -12
  10. package/fs/cas/proof.f.d.ts +1 -0
  11. package/fs/cas/proof.f.js +1 -0
  12. package/fs/cbase32/{test.f.d.ts → proof.f.d.ts} +1 -2
  13. package/fs/cbase32/{test.f.js → proof.f.js} +1 -1
  14. package/fs/ci/node/module.f.js +12 -7
  15. package/fs/ci/{test.f.d.ts → proof.f.d.ts} +1 -2
  16. package/fs/ci/{test.f.js → proof.f.js} +1 -1
  17. package/fs/crypto/hmac/{test.f.d.ts → proof.f.d.ts} +1 -2
  18. package/fs/crypto/hmac/{test.f.js → proof.f.js} +1 -1
  19. package/fs/crypto/secp/{test.f.d.ts → proof.f.d.ts} +1 -2
  20. package/fs/crypto/secp/{test.f.js → proof.f.js} +1 -1
  21. package/fs/crypto/sha2/{test.f.d.ts → proof.f.d.ts} +1 -2
  22. package/fs/crypto/sha2/{test.f.js → proof.f.js} +1 -1
  23. package/fs/crypto/sign/{test.f.d.ts → proof.f.d.ts} +1 -2
  24. package/fs/crypto/sign/{test.f.js → proof.f.js} +1 -1
  25. package/fs/dev/module.f.d.ts +28 -2
  26. package/fs/dev/module.f.js +38 -22
  27. package/fs/dev/{test.f.d.ts → proof.f.d.ts} +5 -2
  28. package/fs/dev/{test.f.js → proof.f.js} +25 -2
  29. package/fs/dev/tf/module.f.d.ts +63 -5
  30. package/fs/dev/tf/module.f.js +77 -20
  31. package/fs/dev/tf/{test.f.d.ts → proof.f.d.ts} +26 -0
  32. package/fs/dev/tf/{test.f.js → proof.f.js} +76 -34
  33. package/fs/dev/tf/scenarios/async-subtests.fail.d.ts +4 -0
  34. package/fs/dev/tf/scenarios/async-subtests.fail.js +7 -0
  35. package/fs/dev/tf/scenarios/async-subtests.pass.d.ts +4 -0
  36. package/fs/dev/tf/scenarios/async-subtests.pass.js +7 -0
  37. package/fs/dev/tf/scenarios/async.fail.d.ts +1 -0
  38. package/fs/dev/tf/scenarios/async.fail.js +4 -0
  39. package/fs/dev/tf/scenarios/async.pass.d.ts +1 -0
  40. package/fs/dev/tf/scenarios/async.pass.js +3 -0
  41. package/fs/dev/tf/scenarios/thenable.pass.d.ts +3 -0
  42. package/fs/dev/tf/scenarios/thenable.pass.js +9 -0
  43. package/fs/dev/tf/scenarios/thenable2.pass.f.d.ts +3 -0
  44. package/fs/dev/tf/scenarios/thenable2.pass.f.js +3 -0
  45. package/fs/dev/version/proof.f.d.ts +3 -0
  46. package/fs/dev/version/{test.f.js → proof.f.js} +1 -1
  47. package/fs/djs/ast/{test.f.d.ts → proof.f.d.ts} +1 -2
  48. package/fs/djs/ast/{test.f.js → proof.f.js} +1 -1
  49. package/fs/djs/parser/{test.f.d.ts → proof.f.d.ts} +1 -2
  50. package/fs/djs/parser/{test.f.js → proof.f.js} +1 -1
  51. package/fs/djs/{test.f.d.ts → proof.f.d.ts} +1 -2
  52. package/fs/djs/{test.f.js → proof.f.js} +1 -1
  53. package/fs/djs/serializer/module.f.d.ts +2 -2
  54. package/fs/djs/serializer/module.f.js +47 -79
  55. package/fs/djs/serializer/{test.f.d.ts → proof.f.d.ts} +1 -2
  56. package/fs/djs/serializer/{test.f.js → proof.f.js} +8 -8
  57. package/fs/djs/tokenizer/{test.f.d.ts → proof.f.d.ts} +1 -2
  58. package/fs/djs/tokenizer/{test.f.js → proof.f.js} +1 -1
  59. package/fs/djs/tokenizer-new/{test.f.d.ts → proof.f.d.ts} +1 -2
  60. package/fs/djs/tokenizer-new/{test.f.js → proof.f.js} +1 -1
  61. package/fs/djs/transpiler/module.f.d.ts +15 -0
  62. package/fs/djs/transpiler/module.f.js +10 -2
  63. package/fs/djs/transpiler/{test.f.d.ts → proof.f.d.ts} +1 -2
  64. package/fs/djs/transpiler/{test.f.js → proof.f.js} +1 -1
  65. package/fs/fsc/{test.f.d.ts → proof.f.d.ts} +1 -2
  66. package/fs/fsc/{test.f.js → proof.f.js} +1 -1
  67. package/fs/fsm/proof.f.d.ts +4 -0
  68. package/fs/fsm/{test.f.js → proof.f.js} +1 -1
  69. package/fs/html/{test.f.d.ts → proof.f.d.ts} +1 -2
  70. package/fs/html/{test.f.js → proof.f.js} +1 -1
  71. package/fs/io/module.d.ts +1 -1
  72. package/fs/io/module.f.d.ts +3 -2
  73. package/fs/io/module.f.js +4 -3
  74. package/fs/io/module.js +19 -11
  75. package/fs/js/tokenizer/{test.f.d.ts → proof.f.d.ts} +1 -2
  76. package/fs/js/tokenizer/{test.f.js → proof.f.js} +1 -1
  77. package/fs/json/parser/{test.f.d.ts → proof.f.d.ts} +1 -2
  78. package/fs/json/parser/{test.f.js → proof.f.js} +1 -1
  79. package/fs/json/{test.f.d.ts → proof.f.d.ts} +1 -2
  80. package/fs/json/{test.f.js → proof.f.js} +1 -1
  81. package/fs/json/serializer/{test.f.d.ts → proof.f.d.ts} +1 -2
  82. package/fs/json/serializer/{test.f.js → proof.f.js} +1 -1
  83. package/fs/json/tokenizer/{test.f.d.ts → proof.f.d.ts} +1 -2
  84. package/fs/json/tokenizer/{test.f.js → proof.f.js} +1 -1
  85. package/fs/path/proof.f.d.ts +5 -0
  86. package/fs/path/{test.f.js → proof.f.js} +4 -3
  87. package/fs/sul/id/{test.f.d.ts → proof.f.d.ts} +1 -2
  88. package/fs/sul/id/{test.f.js → proof.f.js} +1 -1
  89. package/fs/sul/level/hash/{test.f.d.ts → proof.f.d.ts} +1 -2
  90. package/fs/sul/level/hash/{test.f.js → proof.f.js} +1 -1
  91. package/fs/sul/level/literal/{test.f.d.ts → proof.f.d.ts} +1 -2
  92. package/fs/sul/level/literal/{test.f.js → proof.f.js} +1 -1
  93. package/fs/sul/{test.f.d.ts → proof.f.d.ts} +1 -2
  94. package/fs/sul/{test.f.js → proof.f.js} +1 -1
  95. package/fs/text/ascii/proof.f.d.ts +3 -0
  96. package/fs/text/ascii/{test.f.js → proof.f.js} +1 -1
  97. package/fs/text/code_point/module.f.d.ts +28 -0
  98. package/fs/text/code_point/module.f.js +31 -0
  99. package/fs/text/{test.f.d.ts → proof.f.d.ts} +1 -2
  100. package/fs/text/{test.f.js → proof.f.js} +1 -1
  101. package/fs/text/sgr/proof.f.d.ts +1 -0
  102. package/fs/text/sgr/{test.f.js → proof.f.js} +1 -1
  103. package/fs/text/utf16/module.f.js +3 -53
  104. package/fs/text/utf16/{test.f.d.ts → proof.f.d.ts} +1 -2
  105. package/fs/text/utf16/{test.f.js → proof.f.js} +1 -1
  106. package/fs/text/utf8/module.f.js +3 -25
  107. package/fs/text/utf8/{test.f.d.ts → proof.f.d.ts} +1 -2
  108. package/fs/text/utf8/{test.f.js → proof.f.js} +1 -1
  109. package/fs/types/array/{test.f.d.ts → proof.f.d.ts} +1 -2
  110. package/fs/types/array/{test.f.js → proof.f.js} +1 -1
  111. package/fs/types/bigfloat/{test.f.d.ts → proof.f.d.ts} +1 -2
  112. package/fs/types/bigfloat/{test.f.js → proof.f.js} +1 -1
  113. package/fs/types/bigint/{test.f.d.ts → proof.f.d.ts} +1 -2
  114. package/fs/types/bigint/{test.f.js → proof.f.js} +1 -1
  115. package/fs/types/bit_vec/{test.f.d.ts → proof.f.d.ts} +1 -2
  116. package/fs/types/bit_vec/{test.f.js → proof.f.js} +1 -1
  117. package/fs/types/btree/find/proof.f.d.ts +1 -0
  118. package/fs/types/btree/find/{test.f.js → proof.f.js} +1 -1
  119. package/fs/types/btree/{test.f.d.ts → proof.f.d.ts} +1 -2
  120. package/fs/types/btree/{test.f.js → proof.f.js} +1 -1
  121. package/fs/types/btree/remove/proof.f.d.ts +4 -0
  122. package/fs/types/btree/remove/{test.f.js → proof.f.js} +1 -1
  123. package/fs/types/btree/set/proof.f.d.ts +1 -0
  124. package/fs/types/btree/set/{test.f.js → proof.f.js} +1 -1
  125. package/fs/types/btree/types/module.f.d.ts +8 -0
  126. package/fs/types/btree/types/module.f.js +8 -0
  127. package/fs/types/byte_set/{test.f.d.ts → proof.f.d.ts} +1 -2
  128. package/fs/types/byte_set/{test.f.js → proof.f.js} +1 -1
  129. package/fs/types/effects/module.f.d.ts +17 -0
  130. package/fs/types/effects/module.f.js +17 -0
  131. package/fs/types/effects/node/module.f.d.ts +54 -5
  132. package/fs/types/effects/node/module.f.js +4 -1
  133. package/fs/types/effects/node/{test.f.d.ts → proof.f.d.ts} +1 -2
  134. package/fs/types/effects/node/{test.f.js → proof.f.js} +1 -1
  135. package/fs/types/effects/node/virtual/module.f.js +1 -0
  136. package/fs/types/effects/proof.f.d.ts +11 -0
  137. package/fs/types/effects/proof.f.js +57 -0
  138. package/fs/types/function/compare/proof.f.d.ts +1 -0
  139. package/fs/types/function/compare/{test.f.js → proof.f.js} +1 -1
  140. package/fs/types/function/operator/proof.f.d.ts +12 -0
  141. package/fs/types/function/operator/{test.f.js → proof.f.js} +11 -10
  142. package/fs/types/function/proof.f.d.ts +1 -0
  143. package/fs/types/function/{test.f.js → proof.f.js} +1 -1
  144. package/fs/types/list/{test.f.d.ts → proof.f.d.ts} +1 -2
  145. package/fs/types/list/{test.f.js → proof.f.js} +1 -1
  146. package/fs/types/map/proof.f.d.ts +4 -0
  147. package/fs/types/map/{test.f.js → proof.f.js} +1 -1
  148. package/fs/types/monoid/{test.f.d.ts → proof.f.d.ts} +1 -2
  149. package/fs/types/monoid/{test.f.js → proof.f.js} +1 -1
  150. package/fs/types/nibble_set/{test.f.d.ts → proof.f.d.ts} +1 -2
  151. package/fs/types/nibble_set/{test.f.js → proof.f.js} +1 -1
  152. package/fs/types/nominal/proof.f.d.ts +4 -0
  153. package/fs/types/nominal/{test.f.js → proof.f.js} +1 -1
  154. package/fs/types/nullable/proof.f.d.ts +1 -0
  155. package/fs/types/nullable/{test.f.js → proof.f.js} +1 -1
  156. package/fs/types/number/{test.f.d.ts → proof.f.d.ts} +1 -2
  157. package/fs/types/number/{test.f.js → proof.f.js} +1 -1
  158. package/fs/types/object/{test.f.d.ts → proof.f.d.ts} +1 -2
  159. package/fs/types/object/{test.f.js → proof.f.js} +1 -1
  160. package/fs/types/ordered_map/{test.f.d.ts → proof.f.d.ts} +1 -2
  161. package/fs/types/ordered_map/{test.f.js → proof.f.js} +1 -1
  162. package/fs/types/patricia_trie/{test.f.d.ts → proof.f.d.ts} +1 -2
  163. package/fs/types/patricia_trie/{test.f.js → proof.f.js} +1 -1
  164. package/fs/types/prime_field/{test.f.d.ts → proof.f.d.ts} +1 -2
  165. package/fs/types/prime_field/{test.f.js → proof.f.js} +1 -1
  166. package/fs/types/range/proof.f.d.ts +1 -0
  167. package/fs/types/range/{test.f.js → proof.f.js} +1 -1
  168. package/fs/types/range_map/{test.f.d.ts → proof.f.d.ts} +1 -2
  169. package/fs/types/range_map/{test.f.js → proof.f.js} +1 -1
  170. package/fs/types/result/proof.f.d.ts +5 -0
  171. package/fs/types/result/{test.f.js → proof.f.js} +18 -2
  172. package/fs/types/rtti/parse/{test.f.d.ts → proof.f.d.ts} +1 -2
  173. package/fs/types/rtti/parse/{test.f.js → proof.f.js} +1 -1
  174. package/fs/types/rtti/{test.f.d.ts → proof.f.d.ts} +1 -2
  175. package/fs/types/rtti/{test.f.js → proof.f.js} +1 -1
  176. package/fs/types/rtti/ts/{test.f.d.ts → proof.f.d.ts} +1 -2
  177. package/fs/types/rtti/ts/{test.f.js → proof.f.js} +1 -1
  178. package/fs/types/rtti/validate/{test.f.d.ts → proof.f.d.ts} +1 -2
  179. package/fs/types/rtti/validate/{test.f.js → proof.f.js} +1 -1
  180. package/fs/types/sorted_list/{test.f.d.ts → proof.f.d.ts} +1 -2
  181. package/fs/types/sorted_list/{test.f.js → proof.f.js} +1 -1
  182. package/fs/types/sorted_set/{test.f.d.ts → proof.f.d.ts} +1 -2
  183. package/fs/types/sorted_set/{test.f.js → proof.f.js} +1 -1
  184. package/fs/types/string/{test.f.d.ts → proof.f.d.ts} +1 -2
  185. package/fs/types/string/{test.f.js → proof.f.js} +1 -1
  186. package/fs/types/string_set/{test.f.d.ts → proof.f.d.ts} +1 -2
  187. package/fs/types/string_set/{test.f.js → proof.f.js} +1 -1
  188. package/fs/types/ts/{test.f.d.ts → proof.f.d.ts} +20 -0
  189. package/fs/types/ts/{test.f.js → proof.f.js} +1 -0
  190. package/fs/types/uint8array/{test.f.d.ts → proof.f.d.ts} +1 -2
  191. package/fs/types/uint8array/{test.f.js → proof.f.js} +1 -1
  192. package/issues/demo/sample/{test.f.js → proof.f.js} +1 -1
  193. package/issues/{test.f.d.ts → proof.f.d.ts} +1 -2
  194. package/issues/{test.f.js → proof.f.js} +1 -1
  195. package/nanvm-lib/tests/{test.f.d.ts → proof.f.d.ts} +1 -2
  196. package/nanvm-lib/tests/{test.f.js → proof.f.js} +1 -1
  197. package/nanvm-lib/tests/vm/{test.f.d.ts → proof.f.d.ts} +1 -2
  198. package/nanvm-lib/tests/vm/{test.f.js → proof.f.js} +1 -1
  199. package/package.json +2 -2
  200. package/fs/base128/test.f.d.ts +0 -2
  201. package/fs/bnf/test.f.d.ts +0 -4
  202. package/fs/cas/test.f.d.ts +0 -2
  203. package/fs/cas/test.f.js +0 -1
  204. package/fs/dev/version/test.f.d.ts +0 -4
  205. package/fs/fsm/test.f.d.ts +0 -5
  206. package/fs/path/test.f.d.ts +0 -3
  207. package/fs/text/ascii/test.f.d.ts +0 -4
  208. package/fs/text/sgr/test.f.d.ts +0 -2
  209. package/fs/types/btree/find/test.f.d.ts +0 -2
  210. package/fs/types/btree/remove/test.f.d.ts +0 -5
  211. package/fs/types/btree/set/test.f.d.ts +0 -2
  212. package/fs/types/function/compare/test.f.d.ts +0 -2
  213. package/fs/types/function/operator/test.f.d.ts +0 -10
  214. package/fs/types/function/test.f.d.ts +0 -2
  215. package/fs/types/map/test.f.d.ts +0 -5
  216. package/fs/types/nominal/test.f.d.ts +0 -5
  217. package/fs/types/nullable/test.f.d.ts +0 -2
  218. package/fs/types/range/test.f.d.ts +0 -2
  219. package/fs/types/result/test.f.d.ts +0 -2
@@ -7,88 +7,47 @@ import { serialize as bigintSerialize } from "../../types/bigint/module.f.js";
7
7
  import { objectWrap, arrayWrap, stringSerialize, numberSerialize, nullSerialize, boolSerialize } from "../../json/serializer/module.f.js";
8
8
  const colon = [':'];
9
9
  export const undefinedSerialize = ['undefined'];
10
- const getConstantsOp = djs => state => {
11
- switch (typeof djs) {
12
- case 'boolean': {
13
- return state;
14
- }
15
- case 'number':
16
- case 'string':
17
- case 'bigint': {
18
- return getConstantSelf(djs)(state);
19
- }
20
- default: {
21
- if (djs === null) {
22
- return state;
23
- }
24
- if (djs === undefined) {
25
- return state;
26
- }
27
- if (djs instanceof Array) {
28
- return getConstantSelf(djs)(fold(getConstantsOp)(state)(djs));
29
- }
30
- return getConstantSelf(djs)(fold(getConstantsOp)(state)(map(entryValue)(entries(djs))));
10
+ const getConstants = refs => {
11
+ const checkSelf = djs => state => {
12
+ const refCounter = refs.get(djs);
13
+ if (refCounter !== undefined && refCounter[1] > 1 && !state.added.has(djs)) {
14
+ return {
15
+ added: new Set([...state.added, djs]),
16
+ consts: { head: state.consts, tail: [djs] }
17
+ };
31
18
  }
32
- }
33
- };
34
- const getConstantSelf = djs => state => {
35
- const refs = state.refs;
36
- const refCounter = refs.get(djs);
37
- if (refCounter !== undefined && refCounter[1] > 1 && !refCounter[2]) {
38
- refCounter[2] = true;
39
- refs.set(djs, refCounter);
40
- return { refs, consts: { head: state.consts, tail: [djs] } };
41
- }
42
- return state;
43
- };
44
- const getConstants = djs => refs => {
45
- return getConstantsOp(djs)(refs);
46
- };
47
- const entryValue = kv => kv[1];
48
- export const serializeWithoutConst = sort => {
49
- const propertySerialize = ([k, v]) => flat([
50
- stringSerialize(k),
51
- colon,
52
- f(v)
53
- ]);
54
- const mapPropertySerialize = map(propertySerialize);
55
- const objectSerialize = fn(entries)
56
- .map(sort)
57
- .map(mapPropertySerialize)
58
- .map(objectWrap)
59
- .result;
60
- const f = value => {
61
- switch (typeof value) {
19
+ return state;
20
+ };
21
+ const op = djs => state => {
22
+ switch (typeof djs) {
62
23
  case 'boolean': {
63
- return boolSerialize(value);
64
- }
65
- case 'number': {
66
- return numberSerialize(value);
67
- }
68
- case 'string': {
69
- return stringSerialize(value);
24
+ return state;
70
25
  }
26
+ case 'number':
27
+ case 'string':
71
28
  case 'bigint': {
72
- return [bigintSerialize(value)];
29
+ return checkSelf(djs)(state);
73
30
  }
74
31
  default: {
75
- if (value === null) {
76
- return nullSerialize;
32
+ if (djs === null) {
33
+ return state;
77
34
  }
78
- if (value === undefined) {
79
- return undefinedSerialize;
35
+ if (djs === undefined) {
36
+ return state;
80
37
  }
81
- if (value instanceof Array) {
82
- return arraySerialize(value);
38
+ if (djs instanceof Array) {
39
+ return checkSelf(djs)(fold(op)(state)(djs));
83
40
  }
84
- return objectSerialize(value);
41
+ return checkSelf(djs)(fold(op)(state)(map(entryValue)(entries(djs))));
85
42
  }
86
43
  }
87
44
  };
88
- const arraySerialize = compose(map(f))(arrayWrap);
89
- return f;
45
+ const init = { added: new Set(), consts: [] };
46
+ return djs => op(djs)(init).consts;
90
47
  };
91
- const serializeWithConst = sort => refs => root => {
48
+ const entryValue = kv => kv[1];
49
+ const noRef = () => null;
50
+ const buildSerialize = refLookup => sort => {
92
51
  const propertySerialize = ([k, v]) => flat([
93
52
  stringSerialize(k),
94
53
  colon,
@@ -101,11 +60,9 @@ const serializeWithConst = sort => refs => root => {
101
60
  .map(objectWrap)
102
61
  .result;
103
62
  const f = value => {
104
- if (value !== root) {
105
- const refCounter = refs.get(value);
106
- if (refCounter !== undefined && refCounter[1] > 1) {
107
- return [`c${refCounter[0]}`];
108
- }
63
+ const ref = refLookup(value);
64
+ if (ref !== null) {
65
+ return ref;
109
66
  }
110
67
  switch (typeof value) {
111
68
  case 'boolean': {
@@ -137,6 +94,17 @@ const serializeWithConst = sort => refs => root => {
137
94
  const arraySerialize = compose(map(f))(arrayWrap);
138
95
  return f;
139
96
  };
97
+ export const serializeWithoutConst = buildSerialize(noRef);
98
+ const serializeWithConst = sort => refs => root => buildSerialize(value => {
99
+ if (value === root) {
100
+ return null;
101
+ }
102
+ const refCounter = refs.get(value);
103
+ if (refCounter !== undefined && refCounter[1] > 1) {
104
+ return [`c${refCounter[0]}`];
105
+ }
106
+ return null;
107
+ })(sort);
140
108
  const countRefsOp = djs => refs => {
141
109
  switch (typeof djs) {
142
110
  case 'boolean':
@@ -167,14 +135,14 @@ const countRefsOp = djs => refs => {
167
135
  };
168
136
  const addRef = djs => refs => {
169
137
  const refCounter = refs.get(djs);
170
- if (refCounter === undefined) {
171
- return refs.set(djs, [refs.size, 1, false]);
172
- }
173
- return refs.set(djs, [refCounter[0], refCounter[1] + 1, false]);
138
+ const newCounter = refCounter === undefined
139
+ ? [refs.size, 1]
140
+ : [refCounter[0], refCounter[1] + 1];
141
+ return new Map([...refs, [djs, newCounter]]);
174
142
  };
175
143
  export const stringify = sort => djs => {
176
144
  const refs = countRefs(djs);
177
- const consts = getConstants(djs)({ refs, consts: [] }).consts;
145
+ const consts = getConstants(refs)(djs);
178
146
  const constSerialize = entry => {
179
147
  const refCounter = refs.get(entry);
180
148
  if (refCounter === undefined) {
@@ -1,4 +1,4 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  stringify: ({
3
3
  testPrimitives: () => void;
4
4
  testArray: () => void;
@@ -22,4 +22,3 @@ declare const _default: {
22
22
  stringify: () => void;
23
23
  })[];
24
24
  };
25
- export default _default;
@@ -2,7 +2,7 @@ import { countRefs, stringify, stringifyAsTree } from "./module.f.js";
2
2
  import { sort } from "../../types/object/module.f.js";
3
3
  import { identity } from "../../types/function/module.f.js";
4
4
  import { setProperty } from "../../json/module.f.js";
5
- export default {
5
+ export const proof = {
6
6
  stringify: [
7
7
  {
8
8
  testPrimitives: () => {
@@ -12,15 +12,15 @@ export default {
12
12
  throw refs.size;
13
13
  }
14
14
  const refsBigInt = stringifyAsTree(sort)(refs.get(3n));
15
- if (refsBigInt !== '[0,1,false]') {
15
+ if (refsBigInt !== '[0,1]') {
16
16
  throw refsBigInt;
17
17
  }
18
18
  const refsString = stringifyAsTree(sort)(refs.get("str"));
19
- if (refsString !== '[1,1,false]') {
19
+ if (refsString !== '[1,1]') {
20
20
  throw refsString;
21
21
  }
22
22
  const refsRoot = stringifyAsTree(sort)(refs.get(djs));
23
- if (refsRoot !== '[2,1,false]') {
23
+ if (refsRoot !== '[2,1]') {
24
24
  throw refsRoot;
25
25
  }
26
26
  if (refs.get(null) !== undefined) {
@@ -35,11 +35,11 @@ export default {
35
35
  throw refs.size;
36
36
  }
37
37
  const refsArray = stringifyAsTree(sort)(refs.get(array));
38
- if (refsArray !== '[0,3,false]') {
38
+ if (refsArray !== '[0,3]') {
39
39
  throw refsArray;
40
40
  }
41
41
  const refsRoot = stringifyAsTree(sort)(refs.get(djs));
42
- if (refsRoot !== '[1,1,false]') {
42
+ if (refsRoot !== '[1,1]') {
43
43
  throw refsRoot;
44
44
  }
45
45
  },
@@ -51,11 +51,11 @@ export default {
51
51
  throw refs.size;
52
52
  }
53
53
  const refsObj = stringifyAsTree(sort)(refs.get(obj));
54
- if (refsObj !== '[0,2,false]') {
54
+ if (refsObj !== '[0,2]') {
55
55
  throw refsObj;
56
56
  }
57
57
  const refsRoot = stringifyAsTree(sort)(refs.get(djs));
58
- if (refsRoot !== '[1,1,false]') {
58
+ if (refsRoot !== '[1,1]') {
59
59
  throw refsRoot;
60
60
  }
61
61
  },
@@ -1,8 +1,7 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  djs: (() => void)[];
3
3
  id: (() => void)[];
4
4
  keywords: (() => void)[];
5
5
  comments: (() => void)[];
6
6
  metadata: (() => void)[];
7
7
  };
8
- export default _default;
@@ -7,7 +7,7 @@ const tokenizeString = s => toArray(map(withoutMetada)(tokenize(stringToList(s))
7
7
  const tokenizeStringWithMetadata = s => toArray(tokenize(stringToList(s))(''));
8
8
  const stringify = stringifyAsTree(sort);
9
9
  const withoutMetada = tokenWithMetada => { return tokenWithMetada.token; };
10
- export default {
10
+ export const proof = {
11
11
  djs: [
12
12
  () => {
13
13
  const result = stringify(tokenizeString(''));
@@ -1,6 +1,5 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  isValid: (() => void)[];
3
3
  tokenizer: (() => void)[];
4
4
  djs: (() => void)[];
5
5
  };
6
- export default _default;
@@ -108,7 +108,7 @@ const getTokensFromAstRule = ast => {
108
108
  return [token];
109
109
  return { first: token, tail: getTokensFromAstSequence(ast.sequence) };
110
110
  };
111
- export default {
111
+ export const proof = {
112
112
  isValid: [() => {
113
113
  const m = descentParser(jsGrammar());
114
114
  const expect = (s, expected) => {
@@ -10,12 +10,27 @@ import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
10
10
  import { type ParseError } from '../parser/module.f.ts';
11
11
  import { type Effect } from '../../types/effects/module.f.ts';
12
12
  import { type ReadFile } from '../../types/effects/node/module.f.ts';
13
+ /**
14
+ * State threaded through the recursive transpilation of a DJS module graph.
15
+ *
16
+ * - `complete`: modules that have been fully parsed and evaluated, keyed by path.
17
+ * - `stack`: import chain currently being resolved (used to detect circular dependencies).
18
+ * - `error`: the first parse error encountered, or `null` while everything is clean.
19
+ */
13
20
  export type ParseContext = {
14
21
  readonly complete: OrderedMap<djsResult>;
15
22
  readonly stack: List<string>;
16
23
  readonly error: ParseError | null;
17
24
  };
25
+ /** The evaluated DJS value produced for one successfully transpiled module. */
18
26
  export type djsResult = {
19
27
  djs: Unknown;
20
28
  };
29
+ /**
30
+ * Transpiles a DJS module graph rooted at `path` into a single `Unknown` value.
31
+ *
32
+ * Reads each file via the `ReadFile` effect, resolves imports recursively, and
33
+ * evaluates the AST. Returns `['ok', value]` on success, or `['error', ParseError]`
34
+ * on a parse failure or circular dependency.
35
+ */
21
36
  export declare const transpile: (path: string) => Effect<ReadFile, Result<Unknown, ParseError>>;
@@ -12,7 +12,7 @@ import { stringToList } from "../../text/utf16/module.f.js";
12
12
  import { concat as pathConcat } from "../../path/module.f.js";
13
13
  import { parseFromTokens } from "../parser/module.f.js";
14
14
  import { run } from "../ast/module.f.js";
15
- import { pure } from "../../types/effects/module.f.js";
15
+ import { foldStep, pure } from "../../types/effects/module.f.js";
16
16
  import { readFile } from "../../types/effects/node/module.f.js";
17
17
  import { utf8ToString } from "../../text/module.f.js";
18
18
  const mapDjs = context => path => {
@@ -35,7 +35,8 @@ const transpileWithImports = path => parseModuleResult => context => {
35
35
  const pathsCombine = listMap(pathConcat(dir))(parseModuleResult[1][0]);
36
36
  const pathsArray = toArray(pathsCombine);
37
37
  const contextWithStack = { ...context, stack: { first: path, tail: context.stack } };
38
- return pathsArray.reduce((acc, p) => acc.step(ctx => foldNextModuleOp(p)(ctx)), pure(contextWithStack)).step(contextWithImports => {
38
+ return foldStep(foldNextModuleOp)(contextWithStack)(pathsArray)
39
+ .step(contextWithImports => {
39
40
  if (contextWithImports.error !== null) {
40
41
  return pure(contextWithImports);
41
42
  }
@@ -62,6 +63,13 @@ const foldNextModuleOp = path => context => {
62
63
  }
63
64
  return parseModule(path).step(parseModuleResult => transpileWithImports(path)(parseModuleResult)(context));
64
65
  };
66
+ /**
67
+ * Transpiles a DJS module graph rooted at `path` into a single `Unknown` value.
68
+ *
69
+ * Reads each file via the `ReadFile` effect, resolves imports recursively, and
70
+ * evaluates the AST. Returns `['ok', value]` on success, or `['error', ParseError]`
71
+ * on a parse failure or circular dependency.
72
+ */
65
73
  export const transpile = path => foldNextModuleOp(path)({ stack: null, complete: null, error: null }).step((context) => {
66
74
  if (context.error !== null) {
67
75
  return pure(error(context.error));
@@ -1,8 +1,7 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  parse: () => void;
3
3
  parseWithSubModule: () => void;
4
4
  parseWithSubModules: () => void;
5
5
  parseWithFileNotFoundError: () => void;
6
6
  parseWithCycleError: () => void;
7
7
  };
8
- export default _default;
@@ -7,7 +7,7 @@ const run = (root) => (path) => {
7
7
  const [_, result] = virtual({ ...emptyState, root })(transpile(path));
8
8
  return result;
9
9
  };
10
- export default {
10
+ export const proof = {
11
11
  parse: () => {
12
12
  const result = run({ a: utf8('export default 1') })('a');
13
13
  if (result[0] === 'error') {
@@ -1,4 +1,4 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  a: () => void;
3
3
  fn: () => void;
4
4
  f1: () => void;
@@ -6,4 +6,3 @@ declare const _default: {
6
6
  f3: () => void;
7
7
  f4: () => void;
8
8
  };
9
- export default _default;
@@ -11,7 +11,7 @@ const fn = (f, name) => ({ [name]: f }[name]);
11
11
  const withName = (name) =>
12
12
  // translated into one command: define a `function [name]() { return undefined }`
13
13
  Object.getOwnPropertyDescriptor({ [name]: () => undefined }, name).value;
14
- export default {
14
+ export const proof = {
15
15
  a: () => {
16
16
  const x = f('1');
17
17
  if (x !== '["1"]') {
@@ -0,0 +1,4 @@
1
+ export declare const proof: {
2
+ dfa: () => void;
3
+ run: (() => void)[];
4
+ };
@@ -28,7 +28,7 @@ const buildDfa = () => {
28
28
  ];
29
29
  return dfa(grammar);
30
30
  };
31
- export default {
31
+ export const proof = {
32
32
  dfa: () => {
33
33
  const dfa = buildDfa();
34
34
  const entries = Object.entries(dfa);
@@ -1,4 +1,4 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  empty: () => void;
3
3
  empty2: () => void;
4
4
  void: () => void;
@@ -13,4 +13,3 @@ declare const _default: {
13
13
  noRaw: () => void;
14
14
  };
15
15
  };
16
- export default _default;
@@ -1,5 +1,5 @@
1
1
  import { htmlToString } from "./module.f.js";
2
- export default {
2
+ export const proof = {
3
3
  empty: () => {
4
4
  const r = htmlToString(['html']);
5
5
  if (r !== '<!DOCTYPE html><html></html>') {
package/fs/io/module.d.ts CHANGED
@@ -4,6 +4,6 @@ import { type Result } from '../types/result/module.f.ts';
4
4
  export declare const asyncImport: (v: string) => Promise<Module>;
5
5
  export declare const tryCatch: <T>(f: () => T) => Result<T, unknown>;
6
6
  export declare const io: Io;
7
- export type NodeRun = (p: NodeProgram) => Promise<number>;
7
+ export type NodeRun = (p: NodeProgram) => Promise<never>;
8
8
  declare const effectRun: NodeRun;
9
9
  export default effectRun;
@@ -74,7 +74,7 @@ export type Process = {
74
74
  readonly stderr: Writable;
75
75
  };
76
76
  export type TryCatch = <T>(f: () => T) => Result<T, unknown>;
77
- export type Sandbox = <T>(f: () => T) => SandboxResult<T>;
77
+ export type Sandbox = <T>(f: () => T) => Promise<SandboxResult<T>>;
78
78
  export type Server = {
79
79
  readonly listen: (port: number) => void;
80
80
  };
@@ -120,6 +120,7 @@ export type Io = {
120
120
  readonly bunTestContext: TestContext;
121
121
  readonly playwrightTestContext: TestContext;
122
122
  readonly engine: Engine;
123
+ readonly await: (p: unknown) => Promise<readonly [unknown]>;
123
124
  };
124
125
  export type App = (io: Io) => Promise<number>;
125
126
  export type Run = (f: App) => Promise<never>;
@@ -129,5 +130,5 @@ export type Run = (f: App) => Promise<never>;
129
130
  */
130
131
  export declare const run: (io: Io) => Run;
131
132
  export type EffectToPromise = <T>(effect: Effect<NodeOp, T>) => Promise<T>;
132
- export declare const fromIo: ({ fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, now: ioNow, sandbox: ioSandbox, write: ioWrite, }: Io) => EffectToPromise;
133
+ export declare const fromIo: ({ fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, now: ioNow, sandbox, write, await: awaitPromise, }: Io) => EffectToPromise;
133
134
  export declare const runProgram: (io: Io) => (args: readonly string[]) => (program: NodeProgram) => Promise<number>;
package/fs/io/module.f.js CHANGED
@@ -45,7 +45,7 @@ const collect = async (v) => {
45
45
  }
46
46
  return result;
47
47
  };
48
- export const fromIo = ({ fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, now: ioNow, sandbox: ioSandbox, write: ioWrite, }) => {
48
+ export const fromIo = ({ fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, now: ioNow, sandbox, write, await: awaitPromise, }) => {
49
49
  const result = asyncRun({
50
50
  all: async (...effects) => await Promise.all(effects.map(result)),
51
51
  fetch: async (url) => tc(async () => {
@@ -95,8 +95,9 @@ export const fromIo = ({ fs: { promises: { mkdir, readFile, readdir, writeFile,
95
95
  },
96
96
  forever: () => new Promise(() => { }),
97
97
  now: async () => ioNow(),
98
- sandbox: async (f) => ioSandbox(f),
99
- write: ioWrite,
98
+ sandbox,
99
+ await: awaitPromise,
100
+ write,
100
101
  test: async (ctx, name, expectFailure, test) => ctx.test(name, { expectFailure }, async (t) => result(test(t))),
101
102
  });
102
103
  return result;
package/fs/io/module.js CHANGED
@@ -12,7 +12,7 @@ import fs from 'node:fs';
12
12
  import process from 'node:process';
13
13
  import { concat } from "../path/module.f.js";
14
14
  import { once } from 'node:events';
15
- import { fromIo, runProgram } from "./module.f.js";
15
+ import { runProgram } from "./module.f.js";
16
16
  import { error, ok } from "../types/result/module.f.js";
17
17
  import { fromVec } from "../types/uint8array/module.f.js";
18
18
  import * as testContext from 'node:test';
@@ -35,12 +35,11 @@ const inlineTest = async (name, { expectFailure }, fn) => {
35
35
  }
36
36
  };
37
37
  const inlineContext = { test: inlineTest };
38
- const bunTestContext = {
39
- test: (name, opts, fn) => testContext.test(name, () => inlineTest(name, opts, fn))
40
- };
41
- const playwrightTestContext = {
42
- test: (name, opts, fn) => pwTest(name, () => inlineTest(name, opts, fn))
43
- };
38
+ const wrapInlineTest = (register) => ({
39
+ test: (name, opts, fn) => register(name, () => inlineTest(name, opts, fn))
40
+ });
41
+ const bunTestContext = wrapInlineTest(testContext.test);
42
+ const playwrightTestContext = wrapInlineTest(pwTest);
44
43
  const prefix = 'file:///';
45
44
  const { now } = Date;
46
45
  /** Maps `WriteConsoles` names to the corresponding Node.js writable streams. */
@@ -76,6 +75,7 @@ export const tryCatch = f => {
76
75
  return error(e);
77
76
  }
78
77
  };
78
+ const awaitPromise = async (p) => [p instanceof Promise ? await p : p];
79
79
  export const io = {
80
80
  console,
81
81
  fs,
@@ -99,14 +99,18 @@ export const io = {
99
99
  http,
100
100
  childProcess,
101
101
  now,
102
- sandbox: (f) => {
102
+ sandbox: async (f) => {
103
103
  let result;
104
104
  let after;
105
105
  const before = performance.now();
106
106
  try {
107
- const value = f();
107
+ let p = f();
108
108
  after = performance.now();
109
- result = ok(value);
109
+ if (p instanceof Promise) {
110
+ p = await p;
111
+ after = performance.now();
112
+ }
113
+ result = ok(p);
110
114
  }
111
115
  catch (e) {
112
116
  after = performance.now();
@@ -115,10 +119,14 @@ export const io = {
115
119
  return { result, duration: after - before };
116
120
  },
117
121
  write: (stream, data) => writeAll(streams[stream], fromVec(data)),
122
+ await: awaitPromise,
118
123
  testContext,
119
124
  bunTestContext,
120
125
  playwrightTestContext,
121
126
  engine: isPlaywright ? 'playwright' : 'Bun' in globalThis ? 'bun' : 'node',
122
127
  };
123
- const effectRun = runProgram(io)(io.process.argv.slice(2));
128
+ const effectRun = async (p) => {
129
+ const code = await runProgram(io)(io.process.argv.slice(2))(p);
130
+ return process.exit(code);
131
+ };
124
132
  export default effectRun;
@@ -1,4 +1,4 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  djs: (() => void)[];
3
3
  operators: (() => void)[];
4
4
  ws: (() => void)[];
@@ -7,4 +7,3 @@ declare const _default: {
7
7
  comments: (() => void)[];
8
8
  metadata: (() => void)[];
9
9
  };
10
- export default _default;
@@ -7,7 +7,7 @@ const tokenizeString = s => toArray(map(withoutMetada)(tokenize(stringToList(s))
7
7
  const tokenizeStringWithMetadata = s => toArray(tokenize(stringToList(s))(''));
8
8
  const stringify = stringifyAsTree(sort);
9
9
  const withoutMetada = tokenWithMetada => tokenWithMetada.token;
10
- export default {
10
+ export const proof = {
11
11
  djs: [
12
12
  () => {
13
13
  const result = stringify(tokenizeString(''));
@@ -1,5 +1,4 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  valid: (() => void)[];
3
3
  invalid: (() => void)[];
4
4
  };
5
- export default _default;
@@ -6,7 +6,7 @@ import { sort } from "../../types/object/module.f.js";
6
6
  import { stringToList } from "../../text/utf16/module.f.js";
7
7
  const tokenizeString = s => toArray(tokenize(stringToList(s)));
8
8
  const stringify = jsonStringify(sort);
9
- export default {
9
+ export const proof = {
10
10
  valid: [
11
11
  () => {
12
12
  const tokenList = tokenizeString('null');
@@ -1,8 +1,7 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  setProperty: () => void;
3
3
  stringify: {
4
4
  sort: () => void;
5
5
  identity: () => void;
6
6
  }[];
7
7
  };
8
- export default _default;
@@ -1,7 +1,7 @@
1
1
  import { setProperty, stringify } from "./module.f.js";
2
2
  import { sort } from "../types/object/module.f.js";
3
3
  import { identity } from "../types/function/module.f.js";
4
- export default {
4
+ export const proof = {
5
5
  setProperty: () => {
6
6
  if (setProperty("Hello")([])({}) !== "Hello") {
7
7
  throw 'error';
@@ -1,8 +1,7 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  arrayWrap: (() => void)[];
3
3
  objectWrap: (() => void)[];
4
4
  stringSerialize: (() => void)[];
5
5
  numberSerialize: (() => void)[];
6
6
  boolSerialize: (() => void)[];
7
7
  };
8
- export default _default;
@@ -1,7 +1,7 @@
1
1
  import { arrayWrap, boolSerialize, numberSerialize, objectWrap, stringSerialize } from "./module.f.js";
2
2
  import * as list from "../../types/list/module.f.js";
3
3
  const { toArray } = list;
4
- export default {
4
+ export const proof = {
5
5
  arrayWrap: [
6
6
  () => {
7
7
  const result = JSON.stringify(toArray(arrayWrap(null)));
@@ -1,6 +1,5 @@
1
- declare const _default: {
1
+ export declare const proof: {
2
2
  json: (() => void)[];
3
3
  id: (() => void)[];
4
4
  keywords: (() => void)[];
5
5
  };
6
- export default _default;
@@ -5,7 +5,7 @@ import { sort } from "../../types/object/module.f.js";
5
5
  import { stringToList } from "../../text/utf16/module.f.js";
6
6
  const tokenizeString = s => toArray(tokenize(stringToList(s)));
7
7
  const stringify = stringifyAsTree(sort);
8
- export default {
8
+ export const proof = {
9
9
  json: [
10
10
  () => {
11
11
  const result = stringify(tokenizeString(''));