functionalscript 0.16.1 → 0.18.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 (88) hide show
  1. package/fs/asn.1/module.f.js +6 -0
  2. package/fs/ci/bun/module.f.js +6 -0
  3. package/fs/ci/common/module.f.d.ts +11 -5
  4. package/fs/ci/common/module.f.js +11 -4
  5. package/fs/ci/config/module.f.d.ts +11 -4
  6. package/fs/ci/config/module.f.js +11 -4
  7. package/fs/ci/deno/module.f.js +6 -0
  8. package/fs/ci/node/module.f.js +6 -0
  9. package/fs/ci/playwright/module.f.js +6 -0
  10. package/fs/ci/rust/module.f.js +7 -0
  11. package/fs/ci/test.f.js +2 -4
  12. package/fs/crypto/secp/module.f.d.ts +7 -0
  13. package/fs/dev/index/module.f.d.ts +6 -0
  14. package/fs/dev/index/module.f.js +6 -0
  15. package/fs/dev/module.f.d.ts +4 -3
  16. package/fs/dev/module.f.js +13 -11
  17. package/fs/dev/tf/module.d.ts +1 -0
  18. package/fs/dev/tf/module.f.d.ts +70 -22
  19. package/fs/dev/tf/module.f.js +134 -97
  20. package/fs/dev/tf/module.js +66 -16
  21. package/fs/dev/tf/test.f.d.ts +21 -20
  22. package/fs/dev/tf/test.f.js +249 -31
  23. package/fs/djs/module.f.d.ts +5 -2
  24. package/fs/djs/module.f.js +16 -21
  25. package/fs/djs/test.f.d.ts +11 -0
  26. package/fs/djs/test.f.js +74 -0
  27. package/fs/djs/tokenizer-new/test.f.js +126 -78
  28. package/fs/djs/transpiler/module.f.d.ts +3 -3
  29. package/fs/djs/transpiler/module.f.js +34 -29
  30. package/fs/djs/transpiler/test.f.js +19 -26
  31. package/fs/fjs/module.f.d.ts +2 -7
  32. package/fs/fjs/module.f.js +17 -17
  33. package/fs/fjs/module.js +2 -2
  34. package/fs/html/module.f.d.ts +6 -0
  35. package/fs/html/module.f.js +6 -0
  36. package/fs/io/module.d.ts +3 -3
  37. package/fs/io/module.f.d.ts +8 -2
  38. package/fs/io/module.f.js +25 -4
  39. package/fs/io/module.js +54 -15
  40. package/fs/js/tokenizer/module.f.js +7 -0
  41. package/fs/json/module.f.d.ts +7 -0
  42. package/fs/json/module.f.js +7 -0
  43. package/fs/path/module.f.d.ts +6 -0
  44. package/fs/path/module.f.js +6 -0
  45. package/fs/path/test.f.d.ts +3 -5
  46. package/fs/path/test.f.js +67 -49
  47. package/fs/text/module.f.d.ts +7 -0
  48. package/fs/text/module.f.js +7 -0
  49. package/fs/text/sgr/module.f.d.ts +9 -1
  50. package/fs/text/sgr/module.f.js +16 -5
  51. package/fs/text/utf16/module.f.d.ts +7 -0
  52. package/fs/text/utf16/module.f.js +7 -0
  53. package/fs/types/effects/node/module.f.d.ts +51 -9
  54. package/fs/types/effects/node/module.f.js +39 -2
  55. package/fs/types/effects/node/test.f.d.ts +4 -0
  56. package/fs/types/effects/node/test.f.js +33 -6
  57. package/fs/types/effects/node/virtual/module.f.d.ts +12 -3
  58. package/fs/types/effects/node/virtual/module.f.js +32 -9
  59. package/fs/types/function/compare/module.f.d.ts +12 -0
  60. package/fs/types/function/compare/module.f.js +33 -0
  61. package/fs/types/function/operator/test.f.d.ts +10 -0
  62. package/fs/types/function/operator/test.f.js +81 -0
  63. package/fs/types/monoid/module.f.d.ts +7 -0
  64. package/fs/types/number/module.f.d.ts +6 -0
  65. package/fs/types/number/module.f.js +6 -0
  66. package/fs/types/object/module.f.js +7 -0
  67. package/fs/types/prime_field/module.f.d.ts +8 -0
  68. package/fs/types/range_map/module.f.js +3 -18
  69. package/fs/types/result/module.f.d.ts +4 -0
  70. package/fs/types/result/module.f.js +4 -0
  71. package/fs/types/result/test.f.d.ts +2 -4
  72. package/fs/types/result/test.f.js +24 -16
  73. package/fs/types/rtti/common/module.f.d.ts +10 -1
  74. package/fs/types/rtti/common/module.f.js +7 -2
  75. package/fs/types/rtti/parse/module.f.js +35 -46
  76. package/fs/types/rtti/validate/module.f.js +9 -12
  77. package/fs/types/sorted_list/module.f.d.ts +1 -2
  78. package/fs/types/sorted_list/module.f.js +8 -21
  79. package/fs/types/sorted_set/module.f.d.ts +1 -3
  80. package/fs/types/ts/module.f.d.ts +7 -0
  81. package/fs/types/ts/test.f.d.ts +18 -0
  82. package/fs/types/ts/test.f.js +111 -0
  83. package/fs/types/uint8array/module.f.js +7 -1
  84. package/fs/types/uint8array/test.f.d.ts +1 -0
  85. package/fs/types/uint8array/test.f.js +5 -1
  86. package/package.json +3 -2
  87. package/fs/io/virtual/module.f.d.ts +0 -8
  88. package/fs/io/virtual/module.f.js +0 -43
@@ -1,71 +1,60 @@
1
1
  import {} from "../module.f.js";
2
2
  import { ok } from "../../result/module.f.js";
3
- import { isArray as commonIsArray } from "../../array/module.f.js";
4
- import { isObject as commonIsObject } from "../../object/module.f.js";
3
+ import {} from "../../object/module.f.js";
5
4
  import { find, map as listMap } from "../../list/module.f.js";
6
- import { constPrimitiveValidate, prependPath, primitive0Validate, verror, visit, } from "../common/module.f.js";
5
+ import { constPrimitiveValidate, isArray, isObject, prependPath, primitive0Validate, verror, visit, } from "../common/module.f.js";
7
6
  export {} from "../common/module.f.js";
8
- const indexedFirstError = (results) => {
9
- // TODO: findIndex breaks type inference,
10
- // we should replace it with something else.
11
- const i = results.findIndex(r => r[0] === 'error');
12
- return i < 0 ? null : [i, results[i]];
13
- };
7
+ const { entries } = Object;
14
8
  const keyedFirstError = (results) => {
15
9
  const e = results.find(([, r]) => r[0] === 'error');
16
10
  return e === undefined ? null : [e[0], e[1]];
17
11
  };
18
- const arrayParse = (item) => value => {
19
- if (!commonIsArray(value)) {
20
- return verror('unexpected value');
21
- }
22
- if (value.length === 0) {
23
- return ok([]);
24
- }
25
- // Note: we shouldn't instantiate `itemParse` until we know the array is non-empty.
26
- // Otherwise, we can get infinite recursion on empty arrays for recursive schemas.
27
- const itemParse = parse(item);
28
- const results = value.map(itemParse);
29
- const err = indexedFirstError(results);
30
- return (err === null
31
- ? ok(results.map(r => r[1]))
32
- : prependPath(String(err[0]), err[1]));
33
- };
34
- const recordParse = (item) => value => {
35
- if (!commonIsObject(value)) {
12
+ const arrayRebuild = entries => entries.map(([, v]) => v);
13
+ const recordRebuild = entries => Object.fromEntries(entries);
14
+ /** Drops the `'ok'` tag from each result, yielding the rebuild's `[key, value]` entries. */
15
+ const okEntries = (results) => results.map(([k, r]) => [k, r[1]]);
16
+ /**
17
+ * Builds a parser for `array` or `record` schemas. Mirrors `validate`'s
18
+ * `containerValidate`, but rebuilds a fresh container from each item's parsed
19
+ * result instead of returning the value unchanged. The inner item parser is
20
+ * instantiated lazily (only when the container is non-empty) so recursive
21
+ * schemas don't recurse forever on empty containers.
22
+ */
23
+ const containerParse = (isContainer, rebuild) => (item) => value => {
24
+ if (!isContainer(value)) {
36
25
  return verror('unexpected value');
37
26
  }
38
- const entries = Object.entries(value);
39
- if (entries.length === 0) {
40
- return ok({});
27
+ const e = entries(value);
28
+ if (e.length === 0) {
29
+ return ok(rebuild([]));
41
30
  }
42
31
  const itemParse = parse(item);
43
- const results = entries.map(([k, v]) => [k, itemParse(v)]);
32
+ const results = e.map(([k, v]) => [k, itemParse(v)]);
44
33
  const err = keyedFirstError(results);
45
34
  return (err === null
46
- ? ok(Object.fromEntries(results.map(([k, r]) => [k, r[1]])))
35
+ ? ok(rebuild(okEntries(results)))
47
36
  : prependPath(err[0], err[1]));
48
37
  };
49
- const tupleParse = (rtti) => value => {
50
- if (!commonIsArray(value)) {
51
- return verror('unexpected value');
52
- }
53
- const results = rtti.map((t, i) => parse(t)(value[i]));
54
- const err = indexedFirstError(results);
55
- return (err === null
56
- ? ok(results.map(r => r[1]))
57
- : prependPath(String(err[0]), err[1]));
58
- };
59
- const structParse = (rtti) => value => {
60
- if (!commonIsObject(value)) {
38
+ const arrayParse = containerParse(isArray, arrayRebuild);
39
+ const recordParse = containerParse(isObject, recordRebuild);
40
+ /**
41
+ * Builds a parser for `Tuple` or `Struct` const schemas. Mirrors `validate`'s
42
+ * `constContainerValidate`: it iterates the schema's entries (so extra tuple
43
+ * elements and undeclared struct keys are dropped) and rebuilds the result
44
+ * from each parsed item.
45
+ */
46
+ const constContainerParse = (isContainer, getItem, rebuild) => (rtti) => value => {
47
+ if (!isContainer(value)) {
61
48
  return verror('unexpected value');
62
49
  }
63
- const results = Object.entries(rtti).map(([k, t]) => [k, parse(t)(value[k])]);
50
+ const results = entries(rtti).map(([k, t]) => [k, parse(t)(getItem(value, k))]);
64
51
  const err = keyedFirstError(results);
65
52
  return (err === null
66
- ? ok(Object.fromEntries(results.map(([k, r]) => [k, r[1]])))
53
+ ? ok(rebuild(okEntries(results)))
67
54
  : prependPath(err[0], err[1]));
68
55
  };
56
+ const tupleParse = constContainerParse(isArray, (value, k) => value[Number(k)], arrayRebuild);
57
+ const structParse = constContainerParse(isObject, (value, k) => value[k], recordRebuild);
69
58
  const findFirst = find(verror('no match'))((k) => k[0] === 'ok');
70
59
  const orParse = (rtti) => value => findFirst(listMap(t => parse(t)(value))(rtti));
71
60
  /**
@@ -1,26 +1,26 @@
1
1
  import {} from "../module.f.js";
2
2
  import { ok } from "../../result/module.f.js";
3
- import { isArray as commonIsArray } from "../../array/module.f.js";
4
- import { isObject as commonIsObject } from "../../object/module.f.js";
5
- import { constPrimitiveValidate, prependPath, primitive0Validate, verror, visit, } from "../common/module.f.js";
3
+ import {} from "../../object/module.f.js";
4
+ import { constPrimitiveValidate, isArray, isObject, prependPath, primitive0Validate, verror, visit, } from "../common/module.f.js";
6
5
  export { constPrimitiveValidate, prependPath, primitive0Validate, verror, } from "../common/module.f.js";
6
+ const { entries } = Object;
7
7
  /**
8
8
  * Builds a validator for `array` or `record` schemas.
9
9
  * The inner item validator is instantiated lazily (only when the container is
10
10
  * non-empty) to avoid infinite recursion with recursive schemas.
11
11
  */
12
- const containerValidate = (isContainer, getEntries) => (item) => value => {
12
+ const containerValidate = (isContainer) => (item) => value => {
13
13
  if (!isContainer(value)) {
14
14
  return verror('unexpected value');
15
15
  }
16
- const entries = getEntries(value);
17
- if (entries.length === 0) {
16
+ const e = entries(value);
17
+ if (e.length === 0) {
18
18
  return ok(value);
19
19
  }
20
20
  // Note: we shouldn't instantiate `itemValidate` until we make sure `entries` is not empty.
21
21
  // Otherwise, we can get infinite recursion on empty arrays and objects
22
22
  const itemValidate = validate(item);
23
- for (const [k, v] of entries) {
23
+ for (const [k, v] of e) {
24
24
  const r = itemValidate(v);
25
25
  if (r[0] === 'error') {
26
26
  return prependPath(k, r);
@@ -28,11 +28,8 @@ const containerValidate = (isContainer, getEntries) => (item) => value => {
28
28
  }
29
29
  return ok(value);
30
30
  };
31
- const isArray = value => commonIsArray(value);
32
- const arrayEntries = (value) => value.map((v, i) => [String(i), v]);
33
- const arrayValidate = containerValidate(isArray, arrayEntries);
34
- const isObject = value => commonIsObject(value);
35
- const recordValidate = containerValidate(isObject, Object.entries);
31
+ const arrayValidate = containerValidate(isArray);
32
+ const recordValidate = containerValidate(isObject);
36
33
  /**
37
34
  * Builds a validator for `Tuple` or `Struct` const schemas.
38
35
  * Iterates over the schema's entries and validates each corresponding
@@ -3,12 +3,11 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import type { Sign } from '../function/compare/module.f.ts';
6
+ import { type Sign, type Cmp } from '../function/compare/module.f.ts';
7
7
  import { type List } from '../list/module.f.ts';
8
8
  import type { Nullable } from '../nullable/module.f.ts';
9
9
  export type SortedList<T> = List<T>;
10
10
  type SortedArray<T> = readonly T[];
11
- type Cmp<T> = (a: T) => (b: T) => Sign;
12
11
  export type ReduceOp<T, S> = (state: S) => (a: T) => (b: T) => readonly [Nullable<T>, Sign, S];
13
12
  export type TailReduce<T, S> = (state: S) => (tail: List<T>) => List<T>;
14
13
  type MergeReduce<T, S> = {
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Sorted immutable list helpers and merge operations.
3
+ *
4
+ * @module
5
+ */
6
+ import { bsearch } from "../function/compare/module.f.js";
1
7
  import { next } from "../list/module.f.js";
2
8
  import { identity } from "../function/module.f.js";
3
9
  export const genericMerge = ({ reduceOp, tailReduce }) => {
@@ -29,25 +35,6 @@ const cmpReduce = (cmp) => () => a => b => {
29
35
  const mergeTail = () => identity;
30
36
  export const find = (cmp) => (value) => (array) => {
31
37
  const cmpValue = cmp(value);
32
- let b = 0;
33
- let e = array.length - 1;
34
- while (true) {
35
- const d = e - b;
36
- if (d < 0)
37
- return null;
38
- const mid = b + (d >> 1);
39
- switch (cmpValue(array[mid])) {
40
- case -1: {
41
- e = mid - 1;
42
- break;
43
- }
44
- case 0: {
45
- return value;
46
- }
47
- case 1: {
48
- b = mid + 1;
49
- break;
50
- }
51
- }
52
- }
38
+ const pos = bsearch(array.length)(mid => cmpValue(array[mid]));
39
+ return pos < array.length && cmpValue(array[pos]) === 0 ? value : null;
53
40
  };
@@ -26,10 +26,8 @@
26
26
  * has(cmp)(2)(setA) // false
27
27
  * ```
28
28
  */
29
- import type { Sign } from '../function/compare/module.f.ts';
29
+ import type { Cmp } from '../function/compare/module.f.ts';
30
30
  export type SortedSet<T> = readonly T[];
31
- type Cmp<T> = (a: T) => (b: T) => Sign;
32
31
  export declare const union: <T>(cmp: Cmp<T>) => (a: SortedSet<T>) => (b: SortedSet<T>) => SortedSet<T>;
33
32
  export declare const intersect: <T>(cmp: Cmp<T>) => (a: SortedSet<T>) => (b: SortedSet<T>) => SortedSet<T>;
34
33
  export declare const has: <T>(cmp: Cmp<T>) => (value: T) => (set: SortedSet<T>) => boolean;
35
- export {};
@@ -1,3 +1,10 @@
1
+ /**
2
+ * TypeScript source-emitter helpers: the `Equal`/`Assert` compile-time
3
+ * predicates and a `Printer` that renders tuples, structs, arrays, records,
4
+ * primitive literals, and unions as TypeScript type expressions.
5
+ *
6
+ * @module
7
+ */
1
8
  export type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
2
9
  export type Assert<T extends true> = T;
3
10
  /** Functions for emitting TypeScript type expression strings. */
@@ -0,0 +1,18 @@
1
+ export declare const primitiveNull: () => void;
2
+ export declare const primitiveBigint: () => void;
3
+ export declare const primitiveString: () => void;
4
+ export declare const primitiveNumberFinite: () => void;
5
+ export declare const primitiveNumberInfinite: () => void;
6
+ export declare const primitiveUndefined: () => void;
7
+ export declare const primitiveBoolean: () => void;
8
+ export declare const unionEmpty: () => void;
9
+ export declare const unionSingle: () => void;
10
+ export declare const unionMulti: () => void;
11
+ export declare const printerReadonlyTuple: () => void;
12
+ export declare const printerReadonlyStruct: () => void;
13
+ export declare const printerReadonlyArray: () => void;
14
+ export declare const printerReadonlyRecord: () => void;
15
+ export declare const printerMutableTuple: () => void;
16
+ export declare const printerMutableStruct: () => void;
17
+ export declare const printerMutableArray: () => void;
18
+ export declare const printerMutableRecord: () => void;
@@ -0,0 +1,111 @@
1
+ import { printer, primitive, union } from "./module.f.js";
2
+ const ro = printer();
3
+ const mut = printer(true);
4
+ export const primitiveNull = () => {
5
+ const r = primitive(null);
6
+ if (r !== 'null') {
7
+ throw r;
8
+ }
9
+ };
10
+ export const primitiveBigint = () => {
11
+ const r = primitive(42n);
12
+ if (r !== '42n') {
13
+ throw r;
14
+ }
15
+ };
16
+ export const primitiveString = () => {
17
+ const r = primitive('hello');
18
+ if (r !== '"hello"') {
19
+ throw r;
20
+ }
21
+ };
22
+ export const primitiveNumberFinite = () => {
23
+ const r = primitive(3.14);
24
+ if (r !== '3.14') {
25
+ throw r;
26
+ }
27
+ };
28
+ export const primitiveNumberInfinite = () => {
29
+ const r = primitive(Infinity);
30
+ if (r !== 'number') {
31
+ throw r;
32
+ }
33
+ };
34
+ export const primitiveUndefined = () => {
35
+ const r = primitive(undefined);
36
+ if (r !== 'undefined') {
37
+ throw r;
38
+ }
39
+ };
40
+ export const primitiveBoolean = () => {
41
+ const r = primitive(true);
42
+ if (r !== 'true') {
43
+ throw r;
44
+ }
45
+ };
46
+ export const unionEmpty = () => {
47
+ const r = union([]);
48
+ if (r !== 'never') {
49
+ throw r;
50
+ }
51
+ };
52
+ export const unionSingle = () => {
53
+ const r = union(['string']);
54
+ if (r !== 'string') {
55
+ throw r;
56
+ }
57
+ };
58
+ export const unionMulti = () => {
59
+ const r = union(['string', 'number']);
60
+ if (r !== 'string|number') {
61
+ throw r;
62
+ }
63
+ };
64
+ export const printerReadonlyTuple = () => {
65
+ const r = ro.tuple(['string', 'number']);
66
+ if (r !== 'readonly[string,number]') {
67
+ throw r;
68
+ }
69
+ };
70
+ export const printerReadonlyStruct = () => {
71
+ const r = ro.struct([['x', 'number'], ['y', 'string']]);
72
+ if (r !== '{readonly"x":number,readonly"y":string}') {
73
+ throw r;
74
+ }
75
+ };
76
+ export const printerReadonlyArray = () => {
77
+ const r = ro.array('string');
78
+ if (r !== 'readonly(string)[]') {
79
+ throw r;
80
+ }
81
+ };
82
+ export const printerReadonlyRecord = () => {
83
+ const r = ro.record('number');
84
+ if (r !== '{readonly[k:string]:number}') {
85
+ throw r;
86
+ }
87
+ };
88
+ export const printerMutableTuple = () => {
89
+ const r = mut.tuple(['string', 'number']);
90
+ if (r !== '[string,number]') {
91
+ throw r;
92
+ }
93
+ };
94
+ export const printerMutableStruct = () => {
95
+ const r = mut.struct([['x', 'number']]);
96
+ if (r !== '{"x":number}') {
97
+ throw r;
98
+ }
99
+ };
100
+ export const printerMutableArray = () => {
101
+ const r = mut.array('string');
102
+ if (r !== '(string)[]') {
103
+ throw r;
104
+ }
105
+ };
106
+ export const printerMutableRecord = () => {
107
+ const r = mut.record('number');
108
+ if (r !== '{[k:string]:number}') {
109
+ throw r;
110
+ }
111
+ };
@@ -1,5 +1,11 @@
1
1
  /**
2
- * Conversions between Uint8Array values and bit vectors.
2
+ * Conversions between `Uint8Array` values and bit vectors.
3
+ *
4
+ * @deprecated FunctionalScript represents byte data as `bigint`-based bit
5
+ * vectors (`Vec` from `fs/types/bit_vec`). Use `utf8`/`utf8ToString` from
6
+ * `fs/text` for string encoding, and the `bit_vec` module directly for raw
7
+ * byte manipulation. `Uint8Array` interop belongs at Node.js boundaries only
8
+ * (e.g. `fromVec`/`toVec` when reading or writing files).
3
9
  *
4
10
  * @module
5
11
  */
@@ -8,5 +8,6 @@ declare const _default: {
8
8
  decodeUtf8Ascii: () => void;
9
9
  decodeUtf8Multibyte: () => void;
10
10
  utf8RoundTrip: () => void;
11
+ listToVec: () => void;
11
12
  };
12
13
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import { vec } from "../bit_vec/module.f.js";
2
- import { toVec, fromVec, decodeUtf8, encodeUtf8 } from "./module.f.js";
2
+ import { toVec, fromVec, listToVec, decodeUtf8, encodeUtf8 } from "./module.f.js";
3
3
  import { strictEqual } from "../function/operator/module.f.js";
4
4
  import { equal, fromArrayLike } from "../list/module.f.js";
5
5
  const assertEq = (a, b) => {
@@ -54,5 +54,9 @@ export default {
54
54
  const input = 'FunctionalScript 🐝';
55
55
  const output = decodeUtf8(encodeUtf8(input));
56
56
  assertEq(output, input);
57
+ },
58
+ listToVec: () => {
59
+ const result = listToVec([Uint8Array.from([1, 2]), Uint8Array.from([3])]);
60
+ assertArrayEq(fromVec(result), Uint8Array.from([1, 2, 3]));
57
61
  }
58
62
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.16.1",
3
+ "version": "0.18.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "**/*.js",
@@ -15,7 +15,8 @@
15
15
  "start": "node ./fs/fjs/module.ts",
16
16
  "ci-update": "node ./fs/fjs/module.ts r ./fs/ci/module.f.ts",
17
17
  "update": "npm install && npm run index && npm run ci-update",
18
- "website": "node --experimental-strip-types ./fs/fjs/module.ts r ./fs/website/module.f.ts"
18
+ "index-html": "node --experimental-strip-types ./fs/fjs/module.ts r ./fs/website/module.f.ts",
19
+ "website": "npm run prepack &&npm run index-html"
19
20
  },
20
21
  "engines": {
21
22
  "node": ">=22"
@@ -1,8 +0,0 @@
1
- /**
2
- * Virtual I/O adapter implementations for deterministic testing.
3
- *
4
- * @module
5
- */
6
- import type { Io } from '../module.f.ts';
7
- import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
8
- export declare const createVirtualIo: (files: OrderedMap<Uint8Array>) => Io;
@@ -1,43 +0,0 @@
1
- import { at } from "../../types/ordered_map/module.f.js";
2
- import { todo } from "../../dev/module.f.js";
3
- export const createVirtualIo = (files) => ({
4
- console: {
5
- log: (..._d) => { },
6
- error: (..._d) => { }
7
- },
8
- fs: {
9
- writeSync: (_fd, _s) => { },
10
- writeFileSync: (_file, _data) => { },
11
- readFileSync: (path) => { return at(path)(files); },
12
- promises: {
13
- readdir: (_path) => Promise.resolve([]),
14
- readFile: (_path) => Promise.resolve(new Uint8Array()),
15
- writeFile: (_path, _data) => Promise.resolve(),
16
- rm: (_path, _options) => Promise.resolve(),
17
- mkdir: (_path, _options) => Promise.resolve(undefined),
18
- copyFile: (_src, _dest) => Promise.resolve(),
19
- access: (_path) => Promise.resolve(),
20
- }
21
- },
22
- process: {
23
- argv: [],
24
- env: {},
25
- exit: n => { throw n; },
26
- cwd: () => '',
27
- stdout: { fd: 1, isTTY: false },
28
- stderr: { fd: 2, isTTY: false },
29
- },
30
- asyncImport: () => Promise.reject(),
31
- performance: {
32
- now: () => 0,
33
- },
34
- fetch: () => Promise.reject(),
35
- tryCatch: f => ['ok', f()],
36
- asyncTryCatch: async (f) => ['ok', await f()],
37
- http: {
38
- createServer: todo
39
- },
40
- childProcess: {
41
- exec: todo,
42
- },
43
- });