functionalscript 0.22.0 → 0.24.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.
- package/fs/asn.1/module.f.js +2 -1
- package/fs/cas/module.f.d.ts +2 -2
- package/fs/cas/module.f.js +2 -2
- package/fs/cas/proof.f.d.ts +9 -0
- package/fs/cas/proof.f.js +98 -4
- package/fs/ci/config/module.f.d.ts +2 -2
- package/fs/ci/config/module.f.js +2 -2
- package/fs/ci/module.f.d.ts +2 -2
- package/fs/ci/module.f.js +2 -2
- package/fs/ci/proof.f.js +1 -1
- package/fs/crypto/pow/module.f.d.ts +37 -0
- package/fs/crypto/pow/module.f.js +72 -0
- package/fs/crypto/pow/proof.f.d.ts +33 -0
- package/fs/crypto/pow/proof.f.js +161 -0
- package/fs/dev/module.f.d.ts +2 -9
- package/fs/dev/module.f.js +12 -11
- package/fs/dev/proof.f.d.ts +0 -1
- package/fs/dev/proof.f.js +0 -21
- package/fs/dev/version/module.f.d.ts +2 -2
- package/fs/dev/version/module.f.js +2 -2
- package/fs/dev/version/proof.f.js +2 -2
- package/fs/djs/module.f.d.ts +2 -2
- package/fs/djs/module.f.js +2 -2
- package/fs/djs/parser/module.f.d.ts +0 -2
- package/fs/djs/proof.f.js +1 -1
- package/fs/djs/transpiler/module.f.d.ts +2 -2
- package/fs/djs/transpiler/module.f.js +2 -2
- package/fs/djs/transpiler/proof.f.js +1 -1
- package/fs/{types/effects → effects}/module.f.d.ts +1 -1
- package/fs/{types/effects → effects}/module.f.js +1 -1
- package/fs/effects/node/module.d.ts +20 -0
- package/fs/{types/effects → effects}/node/module.f.d.ts +3 -3
- package/fs/{types/effects → effects}/node/module.f.js +1 -1
- package/fs/effects/node/module.js +231 -0
- package/fs/{types/effects → effects}/node/proof.f.js +1 -1
- package/fs/{types/effects → effects}/node/virtual/module.f.d.ts +1 -1
- package/fs/{types/effects → effects}/node/virtual/module.f.js +5 -5
- package/fs/emergent_testing/all.test.js +3 -2
- package/fs/emergent_testing/example.f.d.ts +13 -0
- package/fs/emergent_testing/example.f.js +31 -0
- package/fs/emergent_testing/module.f.d.ts +2 -2
- package/fs/emergent_testing/module.f.js +2 -2
- package/fs/emergent_testing/proof.f.js +4 -4
- package/fs/emergent_testing/scenarios/all.d.ts +1 -1
- package/fs/emergent_testing/scenarios/all.js +1 -3
- package/fs/fjs/module.f.d.ts +1 -1
- package/fs/fjs/module.f.js +1 -1
- package/fs/fjs/module.js +2 -2
- package/fs/path/module.f.d.ts +4 -0
- package/fs/path/module.f.js +5 -1
- package/fs/path/proof.f.d.ts +1 -0
- package/fs/path/proof.f.js +28 -2
- package/fs/text/sgr/module.f.d.ts +2 -17
- package/fs/text/sgr/module.f.js +4 -19
- package/fs/types/bigint/module.f.d.ts +0 -15
- package/fs/types/bigint/module.f.js +0 -15
- package/fs/types/bigint/proof.f.js +2 -1
- package/fs/types/bit_vec/module.f.js +2 -2
- package/fs/types/function/compare/module.f.d.ts +12 -0
- package/fs/types/function/compare/module.f.js +12 -0
- package/fs/types/function/compare/proof.f.js +31 -1
- package/fs/types/function/operator/module.f.d.ts +0 -2
- package/fs/types/function/operator/module.f.js +0 -2
- package/fs/types/function/operator/proof.f.d.ts +0 -2
- package/fs/types/function/operator/proof.f.js +2 -18
- package/fs/types/number/module.f.js +4 -4
- package/fs/website/module.f.d.ts +2 -2
- package/fs/website/module.f.js +2 -2
- package/package.json +1 -1
- package/fs/emergent_testing/module.d.ts +0 -1
- package/fs/emergent_testing/module.js +0 -4
- package/fs/io/module.d.ts +0 -9
- package/fs/io/module.f.d.ts +0 -134
- package/fs/io/module.f.js +0 -113
- package/fs/io/module.js +0 -132
- /package/fs/{types/effects → effects}/mock/module.f.d.ts +0 -0
- /package/fs/{types/effects → effects}/mock/module.f.js +0 -0
- /package/fs/{types/effects → effects}/module.d.ts +0 -0
- /package/fs/{types/effects → effects}/module.js +0 -0
- /package/fs/{types/effects → effects}/node/proof.f.d.ts +0 -0
- /package/fs/{types/effects → effects}/proof.f.d.ts +0 -0
- /package/fs/{types/effects → effects}/proof.f.js +0 -0
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
import type
|
|
8
|
-
import { type
|
|
9
|
-
import { type Effect } from '../../types/effects/module.f.ts';
|
|
7
|
+
import { type Write, type WriteConsoles, type NodeProgramOptions } from '../../effects/node/module.f.ts';
|
|
8
|
+
import { type Effect } from '../../effects/module.f.ts';
|
|
10
9
|
export declare const backspace: string;
|
|
11
10
|
type End = 'm';
|
|
12
11
|
type Csi = (code: number | string) => string;
|
|
@@ -45,20 +44,6 @@ export type WriteText = (text: string) => WriteText;
|
|
|
45
44
|
*/
|
|
46
45
|
export declare const createConsoleText: (stdout: Stdout) => WriteText;
|
|
47
46
|
export type CsiConsole = (s: string) => void;
|
|
48
|
-
/**
|
|
49
|
-
* Creates a TTY-aware console function. Appends `\n` to each string before writing.
|
|
50
|
-
*
|
|
51
|
-
* For TTY destinations, ANSI SGR sequences are preserved.
|
|
52
|
-
* For non-TTY destinations, ANSI SGR sequences are stripped.
|
|
53
|
-
*
|
|
54
|
-
* @param io - Runtime IO bindings.
|
|
55
|
-
* @returns A function that targets a writable stream.
|
|
56
|
-
*/
|
|
57
|
-
export declare const console: ({ fs: { writeSync } }: Io) => (w: Writable) => CsiConsole;
|
|
58
|
-
/** Writes to process stdout using a TTY-aware CSI console. */
|
|
59
|
-
export declare const stdio: (io: Io) => CsiConsole;
|
|
60
|
-
/** Writes to process stderr using a TTY-aware CSI console. */
|
|
61
|
-
export declare const stderr: (io: Io) => CsiConsole;
|
|
62
47
|
/**
|
|
63
48
|
* Effect-based TTY-aware write. Strips ANSI SGR sequences when the target
|
|
64
49
|
* stream is not a TTY, then encodes to UTF-8 and emits a `Write` effect.
|
package/fs/text/sgr/module.f.js
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
// C0 control codes
|
|
8
|
+
// https://en.wikipedia.org/wiki/ANSI_escape_code#C0_control_codes
|
|
9
|
+
import { write } from "../../effects/node/module.f.js";
|
|
10
|
+
import {} from "../../effects/module.f.js";
|
|
9
11
|
import { utf8 } from "../module.f.js";
|
|
10
12
|
export const backspace = '\x08';
|
|
11
13
|
const begin = '\x1b[';
|
|
@@ -50,23 +52,6 @@ export const createConsoleText = (stdout) => {
|
|
|
50
52
|
return f('');
|
|
51
53
|
};
|
|
52
54
|
const str = (isTTY) => (s) => isTTY ? s : s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
53
|
-
/**
|
|
54
|
-
* Creates a TTY-aware console function. Appends `\n` to each string before writing.
|
|
55
|
-
*
|
|
56
|
-
* For TTY destinations, ANSI SGR sequences are preserved.
|
|
57
|
-
* For non-TTY destinations, ANSI SGR sequences are stripped.
|
|
58
|
-
*
|
|
59
|
-
* @param io - Runtime IO bindings.
|
|
60
|
-
* @returns A function that targets a writable stream.
|
|
61
|
-
*/
|
|
62
|
-
export const console = ({ fs: { writeSync } }) => (w) => {
|
|
63
|
-
const toStr = str(w.isTTY);
|
|
64
|
-
return (s) => writeSync(w.fd, toStr(s) + '\n');
|
|
65
|
-
};
|
|
66
|
-
/** Writes to process stdout using a TTY-aware CSI console. */
|
|
67
|
-
export const stdio = (io) => console(io)(io.process.stdout);
|
|
68
|
-
/** Writes to process stderr using a TTY-aware CSI console. */
|
|
69
|
-
export const stderr = (io) => console(io)(io.process.stderr);
|
|
70
55
|
/**
|
|
71
56
|
* Effect-based TTY-aware write. Strips ANSI SGR sequences when the target
|
|
72
57
|
* stream is not a TTY, then encodes to UTF-8 and emits a `Write` effect.
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* const logValue = log2(8n) // 3n
|
|
14
14
|
* const bitCount = bitLength(255n) // 8n
|
|
15
15
|
* const bitmask = mask(5n) // 31n
|
|
16
|
-
* const m = min(3n)(13n) // 3n
|
|
17
16
|
* const c = combination([3n, 2n, 1n]) // 60n
|
|
18
17
|
* ```
|
|
19
18
|
*/
|
|
@@ -130,20 +129,6 @@ export declare const bitLength: (v: bigint) => bigint;
|
|
|
130
129
|
* ```
|
|
131
130
|
*/
|
|
132
131
|
export declare const mask: (len: bigint) => bigint;
|
|
133
|
-
/**
|
|
134
|
-
* Returns the smaller of two `bigint` values.
|
|
135
|
-
*
|
|
136
|
-
* @param a - The first bigint.
|
|
137
|
-
* @returns A function that takes the second bigint and returns the smaller value.
|
|
138
|
-
*/
|
|
139
|
-
export declare const min: (a: bigint) => (b: bigint) => bigint;
|
|
140
|
-
/**
|
|
141
|
-
* Returns the larger of two `bigint` values.
|
|
142
|
-
*
|
|
143
|
-
* @param a - The first bigint.
|
|
144
|
-
* @returns A function that takes the second bigint and returns the larger value.
|
|
145
|
-
*/
|
|
146
|
-
export declare const max: (a: bigint) => (b: bigint) => bigint;
|
|
147
132
|
/**
|
|
148
133
|
* Calculates the partial factorial `b!/a!`.
|
|
149
134
|
*
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* const logValue = log2(8n) // 3n
|
|
14
14
|
* const bitCount = bitLength(255n) // 8n
|
|
15
15
|
* const bitmask = mask(5n) // 31n
|
|
16
|
-
* const m = min(3n)(13n) // 3n
|
|
17
16
|
* const c = combination([3n, 2n, 1n]) // 60n
|
|
18
17
|
* ```
|
|
19
18
|
*/
|
|
@@ -174,20 +173,6 @@ export const bitLength = (v) => log2(abs(v)) + 1n;
|
|
|
174
173
|
* ```
|
|
175
174
|
*/
|
|
176
175
|
export const mask = (len) => (1n << len) - 1n;
|
|
177
|
-
/**
|
|
178
|
-
* Returns the smaller of two `bigint` values.
|
|
179
|
-
*
|
|
180
|
-
* @param a - The first bigint.
|
|
181
|
-
* @returns A function that takes the second bigint and returns the smaller value.
|
|
182
|
-
*/
|
|
183
|
-
export const min = (a) => (b) => a < b ? a : b;
|
|
184
|
-
/**
|
|
185
|
-
* Returns the larger of two `bigint` values.
|
|
186
|
-
*
|
|
187
|
-
* @param a - The first bigint.
|
|
188
|
-
* @returns A function that takes the second bigint and returns the larger value.
|
|
189
|
-
*/
|
|
190
|
-
export const max = (a) => (b) => a < b ? b : a;
|
|
191
176
|
/**
|
|
192
177
|
* Calculates the partial factorial `b!/a!`.
|
|
193
178
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { sum, abs, serialize, log2, bitLength, mask,
|
|
1
|
+
import { sum, abs, serialize, log2, bitLength, mask, combination, factorial, divUp, roundUp } from "./module.f.js";
|
|
2
|
+
import { min } from "../function/compare/module.f.js";
|
|
2
3
|
const oldLog2 = (v) => {
|
|
3
4
|
if (v <= 0n) {
|
|
4
5
|
return -1n;
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
*
|
|
22
22
|
* @module
|
|
23
23
|
*/
|
|
24
|
-
import { bitLength, divUp, mask,
|
|
24
|
+
import { bitLength, divUp, mask, xor } from "../bigint/module.f.js";
|
|
25
25
|
import { flip, identity } from "../function/module.f.js";
|
|
26
26
|
import { fold, iterable, map } from "../list/module.f.js";
|
|
27
27
|
import { asBase, asNominal } from "../nominal/module.f.js";
|
|
28
28
|
import { repeat as mRepeat } from "../monoid/module.f.js";
|
|
29
|
-
import { cmp } from "../function/compare/module.f.js";
|
|
29
|
+
import { cmp, max, min } from "../function/compare/module.f.js";
|
|
30
30
|
/**
|
|
31
31
|
* An empty vector of bits.
|
|
32
32
|
*/
|
|
@@ -24,6 +24,18 @@ export type Cmp2<A, B> = [
|
|
|
24
24
|
B
|
|
25
25
|
] extends [bigint, bigint] ? bigint : never;
|
|
26
26
|
export declare const cmp: <A extends Cmp1>(a: A) => <B extends Cmp2<A, B>>(b: B) => Sign;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the smaller of two comparable values. The `Cmp2<A, B>` constraint
|
|
29
|
+
* is the same one `cmp` uses: it rejects calls that mix incompatible primitive
|
|
30
|
+
* types (e.g. `min(1)("a")`) at compile time.
|
|
31
|
+
*/
|
|
32
|
+
export declare const min: <A extends Cmp1>(a: A) => <B extends Cmp2<A, B>>(b: B) => A | B;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the larger of two comparable values. The `Cmp2<A, B>` constraint
|
|
35
|
+
* is the same one `cmp` uses: it rejects calls that mix incompatible primitive
|
|
36
|
+
* types (e.g. `max(1)("a")`) at compile time.
|
|
37
|
+
*/
|
|
38
|
+
export declare const max: <A extends Cmp1>(a: A) => <B extends Cmp2<A, B>>(b: B) => A | B;
|
|
27
39
|
/**
|
|
28
40
|
* Binary search over `[0, len)`. `probe(mid)` returns the sign of the search
|
|
29
41
|
* key relative to the element at `mid` (`-1` before, `0` at, `1` after). On a
|
|
@@ -4,6 +4,18 @@ export const index5 = cmp => ([v0, v1]) => {
|
|
|
4
4
|
return (_0 <= 0 ? _0 + 1 : cmp(v1) + 3);
|
|
5
5
|
};
|
|
6
6
|
export const cmp = (a) => (b) => a < b ? -1 : a > b ? 1 : 0;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the smaller of two comparable values. The `Cmp2<A, B>` constraint
|
|
9
|
+
* is the same one `cmp` uses: it rejects calls that mix incompatible primitive
|
|
10
|
+
* types (e.g. `min(1)("a")`) at compile time.
|
|
11
|
+
*/
|
|
12
|
+
export const min = (a) => (b) => cmp(a)(b) < 0 ? a : b;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the larger of two comparable values. The `Cmp2<A, B>` constraint
|
|
15
|
+
* is the same one `cmp` uses: it rejects calls that mix incompatible primitive
|
|
16
|
+
* types (e.g. `max(1)("a")`) at compile time.
|
|
17
|
+
*/
|
|
18
|
+
export const max = (a) => (b) => cmp(a)(b) > 0 ? a : b;
|
|
7
19
|
/**
|
|
8
20
|
* Binary search over `[0, len)`. `probe(mid)` returns the sign of the search
|
|
9
21
|
* key relative to the element at `mid` (`-1` before, `0` at, `1` after). On a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cmp } from "./module.f.js";
|
|
1
|
+
import { cmp, min, max } from "./module.f.js";
|
|
2
2
|
export const proof = () => {
|
|
3
3
|
{
|
|
4
4
|
const result = cmp(true)(false);
|
|
@@ -37,4 +37,34 @@ export const proof = () => {
|
|
|
37
37
|
// const f = (a: string|number, b: string|number) => cmp(a)(b) // compilation error
|
|
38
38
|
// const f = (a: number, b: string|number) => cmp(a)(b) // compilation error
|
|
39
39
|
}
|
|
40
|
+
{
|
|
41
|
+
if (min(3)(5) !== 3) {
|
|
42
|
+
throw 'min(3)(5)';
|
|
43
|
+
}
|
|
44
|
+
if (min(7)(2) !== 2) {
|
|
45
|
+
throw 'min(7)(2)';
|
|
46
|
+
}
|
|
47
|
+
if (min(3n)(13n) !== 3n) {
|
|
48
|
+
throw 'min(3n)(13n)';
|
|
49
|
+
}
|
|
50
|
+
if (min("a")("b") !== "a") {
|
|
51
|
+
throw 'min("a")("b")';
|
|
52
|
+
}
|
|
53
|
+
// const _ = min(1)("a") // compilation error
|
|
54
|
+
}
|
|
55
|
+
{
|
|
56
|
+
if (max(3)(5) !== 5) {
|
|
57
|
+
throw 'max(3)(5)';
|
|
58
|
+
}
|
|
59
|
+
if (max(7)(2) !== 7) {
|
|
60
|
+
throw 'max(7)(2)';
|
|
61
|
+
}
|
|
62
|
+
if (max(3n)(13n) !== 13n) {
|
|
63
|
+
throw 'max(3n)(13n)';
|
|
64
|
+
}
|
|
65
|
+
if (max("a")("b") !== "b") {
|
|
66
|
+
throw 'max("a")("b")';
|
|
67
|
+
}
|
|
68
|
+
// const _ = max(1)("a") // compilation error
|
|
69
|
+
}
|
|
40
70
|
};
|
|
@@ -18,7 +18,5 @@ export declare const foldToScan: <I, O>(fold: Fold<I, O>) => (prior: O) => Scan<
|
|
|
18
18
|
export type Reduce<T> = Fold<T, T>;
|
|
19
19
|
export declare const reduceToScan: <T>(op: Reduce<T>) => Scan<T, T>;
|
|
20
20
|
export declare const addition: Reduce<number>;
|
|
21
|
-
export declare const min: Reduce<number>;
|
|
22
|
-
export declare const max: Reduce<number>;
|
|
23
21
|
export declare const increment: (b: number) => number;
|
|
24
22
|
export declare const counter: () => (b: number) => number;
|
|
@@ -12,7 +12,5 @@ export const foldToScan = (fold) => (prior) => i => {
|
|
|
12
12
|
};
|
|
13
13
|
export const reduceToScan = (op) => init => [init, foldToScan(op)(init)];
|
|
14
14
|
export const addition = a => b => a + b;
|
|
15
|
-
export const min = a => b => a < b ? a : b;
|
|
16
|
-
export const max = a => b => a > b ? a : b;
|
|
17
15
|
export const increment = addition(1);
|
|
18
16
|
export const counter = () => increment;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, concat, logicalNot, strictEqual, addition,
|
|
1
|
+
import { join, concat, logicalNot, strictEqual, addition, increment, foldToScan, reduceToScan, } from "./module.f.js";
|
|
2
2
|
const joinTest = () => {
|
|
3
3
|
const result = join(', ')('world')('hello');
|
|
4
4
|
if (result !== 'hello, world') {
|
|
@@ -33,22 +33,6 @@ const additionTest = () => {
|
|
|
33
33
|
throw result;
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
const minTest = () => {
|
|
37
|
-
if (min(3)(5) !== 3) {
|
|
38
|
-
throw 'min(3)(5)';
|
|
39
|
-
}
|
|
40
|
-
if (min(7)(2) !== 2) {
|
|
41
|
-
throw 'min(7)(2)';
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const maxTest = () => {
|
|
45
|
-
if (max(3)(5) !== 5) {
|
|
46
|
-
throw 'max(3)(5)';
|
|
47
|
-
}
|
|
48
|
-
if (max(7)(2) !== 7) {
|
|
49
|
-
throw 'max(7)(2)';
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
36
|
const incrementTest = () => {
|
|
53
37
|
if (increment(4) !== 5) {
|
|
54
38
|
throw 'increment(4)';
|
|
@@ -79,4 +63,4 @@ const reduceToScanTest = () => {
|
|
|
79
63
|
throw v1;
|
|
80
64
|
}
|
|
81
65
|
};
|
|
82
|
-
export const proof = { joinTest, concatTest, logicalNotTest, strictEqualTest, additionTest,
|
|
66
|
+
export const proof = { joinTest, concatTest, logicalNotTest, strictEqualTest, additionTest, incrementTest, foldToScanTest, reduceToScanTest };
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
import { reduce } from "../list/module.f.js";
|
|
8
|
-
import { addition
|
|
9
|
-
import { cmp as uCmp } from "../function/compare/module.f.js";
|
|
8
|
+
import { addition } from "../function/operator/module.f.js";
|
|
9
|
+
import { cmp as uCmp, min as uMin, max as uMax } from "../function/compare/module.f.js";
|
|
10
10
|
export const sum = reduce(addition)(0);
|
|
11
|
-
export const min = reduce(
|
|
12
|
-
export const max = reduce(
|
|
11
|
+
export const min = reduce((uMin))(null);
|
|
12
|
+
export const max = reduce((uMax))(null);
|
|
13
13
|
export const cmp = uCmp;
|
|
14
14
|
const mo = [
|
|
15
15
|
[0x5555_5555, 1],
|
package/fs/website/module.f.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type WriteFile } from '../
|
|
2
|
-
import { type Effect } from '../
|
|
1
|
+
import { type WriteFile } from '../effects/node/module.f.ts';
|
|
2
|
+
import { type Effect } from '../effects/module.f.ts';
|
|
3
3
|
declare const _default: () => Effect<WriteFile, number>;
|
|
4
4
|
export default _default;
|
package/fs/website/module.f.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import { htmlUtf8 } from "../html/module.f.js";
|
|
7
|
-
import { writeFile } from "../
|
|
8
|
-
import { pure } from "../
|
|
7
|
+
import { writeFile } from "../effects/node/module.f.js";
|
|
8
|
+
import { pure } from "../effects/module.f.js";
|
|
9
9
|
const html = htmlUtf8()(['a',
|
|
10
10
|
{ href: 'https://github.com/functionalscript/functionalscript' },
|
|
11
11
|
'GitHub Repository'
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const run: () => Promise<number>;
|
package/fs/io/module.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Io } from './module.f.ts';
|
|
2
|
-
import type { Module, NodeProgram } from '../types/effects/node/module.f.ts';
|
|
3
|
-
import { type Result } from '../types/result/module.f.ts';
|
|
4
|
-
export declare const asyncImport: (v: string) => Promise<Module>;
|
|
5
|
-
export declare const tryCatch: <T>(f: () => T) => Result<T, unknown>;
|
|
6
|
-
export declare const io: Io;
|
|
7
|
-
export type NodeRun = (p: NodeProgram) => Promise<never>;
|
|
8
|
-
declare const effectRun: NodeRun;
|
|
9
|
-
export default effectRun;
|
package/fs/io/module.f.d.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { type Effect } from '../types/effects/module.f.ts';
|
|
2
|
-
import { type Headers, type Module, type NodeOp, type Env, type SandboxResult, type NodeProgram, type WriteConsoles, type TestContext, type Engine } from '../types/effects/node/module.f.ts';
|
|
3
|
-
import type { Vec } from '../types/bit_vec/module.f.ts';
|
|
4
|
-
import { type Result } from '../types/result/module.f.ts';
|
|
5
|
-
/**
|
|
6
|
-
* Represents a directory entry (file or directory) in the filesystem
|
|
7
|
-
* @see https://nodejs.org/api/fs.html#class-fsdirent
|
|
8
|
-
*/
|
|
9
|
-
export type Dirent = {
|
|
10
|
-
readonly name: string;
|
|
11
|
-
readonly parentPath: string;
|
|
12
|
-
readonly isDirectory: () => boolean;
|
|
13
|
-
readonly isFile: () => boolean;
|
|
14
|
-
};
|
|
15
|
-
export type RmOptions = {
|
|
16
|
-
readonly force?: boolean;
|
|
17
|
-
readonly recursive?: boolean;
|
|
18
|
-
};
|
|
19
|
-
export type MakeDirectoryOptions = {
|
|
20
|
-
readonly recursive?: boolean;
|
|
21
|
-
};
|
|
22
|
-
export type ReadDir = ((path: string, options: {
|
|
23
|
-
withFileTypes: true;
|
|
24
|
-
}) => Promise<Dirent[]>) & ((path: string, options: {
|
|
25
|
-
recursive?: true;
|
|
26
|
-
}) => Promise<readonly string[]>);
|
|
27
|
-
/**
|
|
28
|
-
* File system operations interface
|
|
29
|
-
* @see https://nodejs.org/api/fs.html
|
|
30
|
-
*/
|
|
31
|
-
export type Fs = {
|
|
32
|
-
readonly writeSync: (fd: number, s: string) => void;
|
|
33
|
-
readonly writeFileSync: (file: string, data: Uint8Array) => void;
|
|
34
|
-
readonly readFileSync: (path: string) => Uint8Array | null;
|
|
35
|
-
readonly promises: {
|
|
36
|
-
readonly readFile: (path: string) => Promise<Uint8Array>;
|
|
37
|
-
readonly writeFile: (path: string, data: Uint8Array) => Promise<void>;
|
|
38
|
-
readonly readdir: ReadDir;
|
|
39
|
-
readonly rm: (path: string, options?: RmOptions) => Promise<void>;
|
|
40
|
-
readonly mkdir: (path: string, options?: MakeDirectoryOptions) => Promise<string | undefined>;
|
|
41
|
-
readonly copyFile: (src: string, dest: string) => Promise<void>;
|
|
42
|
-
readonly access: (path: string) => Promise<void>;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Console operations interface
|
|
47
|
-
* @see https://nodejs.org/api/console.html
|
|
48
|
-
*/
|
|
49
|
-
export type Console = {
|
|
50
|
-
readonly log: (...d: unknown[]) => void;
|
|
51
|
-
readonly error: (...d: unknown[]) => void;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* High-resolution time measurement interface
|
|
55
|
-
* @see https://nodejs.org/api/perf_hooks.html#performance-now
|
|
56
|
-
*/
|
|
57
|
-
export type Performance = {
|
|
58
|
-
readonly now: () => number;
|
|
59
|
-
};
|
|
60
|
-
export type Writable = {
|
|
61
|
-
readonly fd: number;
|
|
62
|
-
readonly isTTY: boolean;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Node.js Process interface
|
|
66
|
-
* @see https://nodejs.org/api/process.html
|
|
67
|
-
*/
|
|
68
|
-
export type Process = {
|
|
69
|
-
readonly argv: string[];
|
|
70
|
-
readonly env: Env;
|
|
71
|
-
readonly exit: (code: number) => never;
|
|
72
|
-
readonly cwd: () => string;
|
|
73
|
-
readonly stdout: Writable;
|
|
74
|
-
readonly stderr: Writable;
|
|
75
|
-
};
|
|
76
|
-
export type TryCatch = <T>(f: () => T) => Result<T, unknown>;
|
|
77
|
-
export type Sandbox = <T>(f: () => T) => Promise<SandboxResult<T>>;
|
|
78
|
-
export type Server = {
|
|
79
|
-
readonly listen: (port: number) => void;
|
|
80
|
-
};
|
|
81
|
-
export type Readable = AsyncIterable<Uint8Array>;
|
|
82
|
-
export type IncomingMessage = Readable & {
|
|
83
|
-
readonly method: string;
|
|
84
|
-
readonly url: string;
|
|
85
|
-
readonly headers: Headers;
|
|
86
|
-
};
|
|
87
|
-
export type ServerResponse = {
|
|
88
|
-
readonly writeHead: (status: number, headers: Record<string, string>) => ServerResponse;
|
|
89
|
-
readonly end: (body: Uint8Array) => void;
|
|
90
|
-
};
|
|
91
|
-
export type RequestListener = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
92
|
-
export type Http = {
|
|
93
|
-
readonly createServer: (_: RequestListener) => Server;
|
|
94
|
-
};
|
|
95
|
-
export type ChildProcess = {
|
|
96
|
-
readonly exec: (command: string, callback: (error: unknown, stdout: string, stderr: string) => void) => {
|
|
97
|
-
readonly stdin: null | {
|
|
98
|
-
readonly end: (data?: string) => void;
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Core IO operations interface providing access to system resources
|
|
104
|
-
*/
|
|
105
|
-
export type Io = {
|
|
106
|
-
readonly console: Console;
|
|
107
|
-
readonly fs: Fs;
|
|
108
|
-
readonly process: Process;
|
|
109
|
-
readonly asyncImport: (s: string) => Promise<Module>;
|
|
110
|
-
readonly performance: Performance;
|
|
111
|
-
readonly fetch: (url: string) => Promise<Response>;
|
|
112
|
-
readonly tryCatch: TryCatch;
|
|
113
|
-
readonly asyncTryCatch: <T>(f: () => Promise<T>) => Promise<Result<T, unknown>>;
|
|
114
|
-
readonly http: Http;
|
|
115
|
-
readonly childProcess: ChildProcess;
|
|
116
|
-
readonly now: () => number;
|
|
117
|
-
readonly sandbox: Sandbox;
|
|
118
|
-
readonly write: (stream: WriteConsoles, data: Vec) => Promise<void>;
|
|
119
|
-
readonly testContext: TestContext;
|
|
120
|
-
readonly bunTestContext: TestContext;
|
|
121
|
-
readonly playwrightTestContext: TestContext;
|
|
122
|
-
readonly engine: Engine;
|
|
123
|
-
readonly await: (p: unknown) => Promise<readonly [unknown]>;
|
|
124
|
-
};
|
|
125
|
-
export type App = (io: Io) => Promise<number>;
|
|
126
|
-
export type Run = (f: App) => Promise<never>;
|
|
127
|
-
/**
|
|
128
|
-
* Runs a function and exits the process with the returned code
|
|
129
|
-
* Handles errors by exiting with code 1
|
|
130
|
-
*/
|
|
131
|
-
export declare const run: (io: Io) => Run;
|
|
132
|
-
export type EffectToPromise = <T>(effect: Effect<NodeOp, T>) => Promise<T>;
|
|
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;
|
|
134
|
-
export declare const runProgram: (io: Io) => (args: readonly string[]) => (program: NodeProgram) => Promise<number>;
|
package/fs/io/module.f.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Legacy `Io` interface and adapter (`fromIo`) bridging the old IO API to the
|
|
3
|
-
* effect runner.
|
|
4
|
-
*
|
|
5
|
-
* @deprecated Use `fs/types/effects/node` (see issue
|
|
6
|
-
* [i139](../../issues/README.md)).
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
import { normalize } from "../path/module.f.js";
|
|
11
|
-
import {} from "../types/effects/module.f.js";
|
|
12
|
-
import { asyncRun } from "../types/effects/module.js";
|
|
13
|
-
import {} from "../types/effects/node/module.f.js";
|
|
14
|
-
import { asBase, asNominal } from "../types/nominal/module.f.js";
|
|
15
|
-
import { error, ok } from "../types/result/module.f.js";
|
|
16
|
-
import { fromVec, listToVec, toVec } from "../types/uint8array/module.f.js";
|
|
17
|
-
/**
|
|
18
|
-
* Runs a function and exits the process with the returned code
|
|
19
|
-
* Handles errors by exiting with code 1
|
|
20
|
-
*/
|
|
21
|
-
export const run = (io) => {
|
|
22
|
-
const exitCode = ([x, b]) => {
|
|
23
|
-
if (x === 'error') {
|
|
24
|
-
io.console.error(b);
|
|
25
|
-
return 1;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return b;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
return async (f) => io.process.exit(exitCode(await io.asyncTryCatch(() => f(io))));
|
|
32
|
-
};
|
|
33
|
-
const tc = async (f) => {
|
|
34
|
-
try {
|
|
35
|
-
return ok(await f());
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
return error(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const collect = async (v) => {
|
|
42
|
-
let result = [];
|
|
43
|
-
for await (const a of v) {
|
|
44
|
-
result = [...result, a];
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
48
|
-
export const fromIo = ({ fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, now: ioNow, sandbox, write, await: awaitPromise, }) => {
|
|
49
|
-
const result = asyncRun({
|
|
50
|
-
all: async (...effects) => await Promise.all(effects.map(result)),
|
|
51
|
-
fetch: async (url) => tc(async () => {
|
|
52
|
-
const response = await fetch(url);
|
|
53
|
-
if (!response.ok) {
|
|
54
|
-
throw new Error(`Fetch error: ${response.status} ${response.statusText}`);
|
|
55
|
-
}
|
|
56
|
-
return toVec(new Uint8Array(await response.arrayBuffer()));
|
|
57
|
-
}),
|
|
58
|
-
mkdir: (...p) => tc(async () => { await mkdir(...p); }),
|
|
59
|
-
readFile: path => tc(async () => toVec(await readFile(path))),
|
|
60
|
-
readdir: (path, r) => tc(async () => (await readdir(path, { ...r, withFileTypes: true }))
|
|
61
|
-
.map(v => ({
|
|
62
|
-
name: v.name,
|
|
63
|
-
parentPath: normalize(v.parentPath),
|
|
64
|
-
isFile: v.isFile()
|
|
65
|
-
}))),
|
|
66
|
-
writeFile: (path, data) => tc(() => writeFile(path, fromVec(data))),
|
|
67
|
-
rm: path => tc(() => rm(path)),
|
|
68
|
-
access: path => tc(() => access(path)),
|
|
69
|
-
import: path => tc(() => asyncImport(path)),
|
|
70
|
-
exec: (command, stdin) => new Promise(resolve => {
|
|
71
|
-
const child = childProcess.exec(command, (e, stdout, stderr) => resolve(e !== null ? ['error', e] : ok({ stdout, stderr })));
|
|
72
|
-
child.stdin?.end(stdin);
|
|
73
|
-
}),
|
|
74
|
-
createServer: async (requestListener) => {
|
|
75
|
-
const erl = requestListener;
|
|
76
|
-
const nodeRl = async (req, res) => {
|
|
77
|
-
const reqBody = await collect(req);
|
|
78
|
-
const { method, url, headers } = req;
|
|
79
|
-
const { status, headers: outHeaders, body: outBody } = await result(erl({
|
|
80
|
-
method,
|
|
81
|
-
url,
|
|
82
|
-
headers,
|
|
83
|
-
body: listToVec(reqBody)
|
|
84
|
-
}));
|
|
85
|
-
res
|
|
86
|
-
.writeHead(status, outHeaders)
|
|
87
|
-
.end(fromVec(outBody));
|
|
88
|
-
};
|
|
89
|
-
const server = asNominal(createServer(nodeRl));
|
|
90
|
-
return server;
|
|
91
|
-
},
|
|
92
|
-
listen: async (server, port) => {
|
|
93
|
-
const s = asBase(server);
|
|
94
|
-
s.listen(port);
|
|
95
|
-
},
|
|
96
|
-
forever: () => new Promise(() => { }),
|
|
97
|
-
now: async () => ioNow(),
|
|
98
|
-
sandbox,
|
|
99
|
-
await: awaitPromise,
|
|
100
|
-
write,
|
|
101
|
-
test: async (ctx, name, expectFailure, test) => ctx.test(name, { expectFailure }, async (t) => result(test(t))),
|
|
102
|
-
});
|
|
103
|
-
return result;
|
|
104
|
-
};
|
|
105
|
-
export const runProgram = (io) => {
|
|
106
|
-
const { process: { env, stdout, stderr }, testContext, bunTestContext, playwrightTestContext, engine } = io;
|
|
107
|
-
const std = { stdout, stderr };
|
|
108
|
-
const f = fromIo(io);
|
|
109
|
-
return args => {
|
|
110
|
-
const options = { args, env, std, testContext, bunTestContext, playwrightTestContext, engine };
|
|
111
|
-
return program => f(program(options));
|
|
112
|
-
};
|
|
113
|
-
};
|