functionalscript 0.23.0 → 0.25.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/asserts/proof.f.d.ts +8 -0
- package/fs/asserts/proof.f.js +51 -0
- package/fs/bnf/data/proof.f.js +7 -17
- package/fs/bnf/module.f.d.ts +10 -0
- package/fs/bnf/module.f.js +10 -0
- package/fs/bnf/testlib.f.js +4 -9
- package/fs/cas/module.f.d.ts +2 -2
- package/fs/cas/module.f.js +2 -2
- package/fs/cas/proof.f.js +3 -3
- package/fs/ci/common/module.f.d.ts +2 -0
- package/fs/ci/common/module.f.js +4 -1
- 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 +3 -4
- package/fs/ci/module.f.js +10 -8
- package/fs/ci/node/module.f.js +4 -2
- package/fs/ci/proof.f.js +9 -6
- package/fs/crypto/sha2/module.f.js +32 -36
- package/fs/crypto/vdf/module.f.d.ts +21 -0
- package/fs/crypto/vdf/module.f.js +57 -0
- package/fs/crypto/vdf/proof.f.d.ts +32 -0
- package/fs/crypto/vdf/proof.f.js +135 -0
- package/fs/dev/module.f.d.ts +2 -9
- package/fs/dev/module.f.js +10 -9
- 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/{io → effects/node}/module.d.ts +5 -12
- 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/{io → effects/node}/module.js +96 -12
- 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.d.ts +1 -1
- package/fs/emergent_testing/all.test.js +3 -2
- 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 -1
- 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/json/module.f.d.ts +25 -9
- package/fs/json/module.f.js +25 -3
- package/fs/json/rpc/module.f.d.ts +109 -0
- package/fs/json/rpc/module.f.js +84 -0
- package/fs/json/rpc/proof.f.d.ts +35 -0
- package/fs/json/rpc/proof.f.js +68 -0
- package/fs/json/schema/module.f.d.ts +76 -0
- package/fs/json/schema/module.f.js +112 -0
- package/fs/json/schema/proof.f.d.ts +33 -0
- package/fs/json/schema/proof.f.js +71 -0
- package/fs/mcp/module.f.d.ts +88 -0
- package/fs/mcp/module.f.js +69 -0
- package/fs/sul/level/literal/proof.f.d.ts +1 -0
- package/fs/sul/level/literal/proof.f.js +6 -0
- package/fs/text/sgr/module.f.d.ts +2 -17
- package/fs/text/sgr/module.f.js +4 -19
- package/fs/types/array/module.f.d.ts +7 -0
- package/fs/types/array/module.f.js +7 -0
- package/fs/types/prime_field/module.f.d.ts +8 -0
- package/fs/types/prime_field/module.f.js +37 -5
- package/fs/types/prime_field/proof.f.d.ts +3 -0
- package/fs/types/prime_field/proof.f.js +27 -2
- package/fs/types/rtti/parse/module.f.d.ts +28 -0
- package/fs/types/rtti/parse/module.f.js +35 -5
- package/fs/types/rtti/ts/module.f.d.ts +46 -3
- package/fs/types/rtti/validate/module.f.js +5 -0
- package/fs/website/module.f.d.ts +2 -2
- package/fs/website/module.f.js +2 -2
- package/package.json +3 -3
- package/fs/emergent_testing/module.d.ts +0 -1
- package/fs/emergent_testing/module.js +0 -4
- package/fs/io/module.f.d.ts +0 -134
- package/fs/io/module.f.js +0 -113
- /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
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { sloth, p } from "./module.f.js";
|
|
2
|
+
const { eval: evalVdf, verify, modSqrt, quadRes } = sloth;
|
|
3
|
+
// `eval(steps)(x)` expected values for {@link p}; same Sloth algorithm as
|
|
4
|
+
// https://github.com/hyperhyperspace/pulsar/blob/main/src/model/SlothVDF.ts and
|
|
5
|
+
// https://github.com/jose-compu/dignity.js/blob/main/src/security/sloth-vdf.js
|
|
6
|
+
const sampleX = 123456789n;
|
|
7
|
+
const largeX = 12345678901234567890n;
|
|
8
|
+
const smallX = 42n;
|
|
9
|
+
const nonResidue = 2n;
|
|
10
|
+
const sampleY = 72412151236937799598582816305571618206681207952550127764586725290711141789888684237028784568532880529360450375677852568362636821341317217048062977639333459511661887862128325859969604061461913896412260750881385045152117694320409864730924775539555636460819549547999218170813228857928921642957426089461925313163n;
|
|
11
|
+
const smallY = 145151597037272685697451525487035431973338817762329243361437778785747534269376083577375382484815474368317818719265551745910148543423765263685177263740373969289084400977118144482329577335929842301331443392042760708529572252015473334998752211959790788326970269713683808382892472572910797612141527200051803670965n;
|
|
12
|
+
const y6 = 116287514643100261336025249676072556421566393377742705567032370320583145555855278910304225489766306768040386612082033279417845047304479679877515174322332386599890348932893235091525789175564701751964775040887336849457197662999383850490808701700264064812615988837073981567599117932005435532913423970502774287312n;
|
|
13
|
+
const y4 = 64401150265223443694244964595084197237814157534040219819342647664782563317539559768554855806938965782018778040933157632467146168153951260465261118025222264314070274636967492909984790708532033331622332323767105919809000393624013423095812833452440384602112677364631962445309757177309466319657219548312354433189n;
|
|
14
|
+
export const proof = {
|
|
15
|
+
p: {
|
|
16
|
+
matchesField: () => {
|
|
17
|
+
if (sloth.p !== p) {
|
|
18
|
+
throw [sloth.p, p];
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
eval: {
|
|
23
|
+
steps100: () => {
|
|
24
|
+
const y = evalVdf(100n)(sampleX);
|
|
25
|
+
if (y !== sampleY) {
|
|
26
|
+
throw [y, sampleY];
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
steps10: () => {
|
|
30
|
+
const y = evalVdf(10n)(smallX);
|
|
31
|
+
if (y !== smallY) {
|
|
32
|
+
throw [y, smallY];
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
steps6: () => {
|
|
36
|
+
const y = evalVdf(6n)(largeX);
|
|
37
|
+
if (y !== y6) {
|
|
38
|
+
throw [y, y6];
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
steps4: () => {
|
|
42
|
+
const y = evalVdf(4n)(smallX);
|
|
43
|
+
if (y !== y4) {
|
|
44
|
+
throw [y, y4];
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
zeroSteps: () => {
|
|
48
|
+
const y = evalVdf(0n)(sampleX);
|
|
49
|
+
if (y !== sampleX % p) {
|
|
50
|
+
throw [y, sampleX % p];
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
negativeSteps: () => {
|
|
54
|
+
const y = evalVdf(-1n)(sampleX);
|
|
55
|
+
if (y !== null) {
|
|
56
|
+
throw y;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
verify: {
|
|
61
|
+
steps100: () => {
|
|
62
|
+
if (!verify(100n)(sampleX)(sampleY)) {
|
|
63
|
+
throw false;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
steps10: () => {
|
|
67
|
+
if (!verify(10n)(smallX)(smallY)) {
|
|
68
|
+
throw false;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
steps6: () => {
|
|
72
|
+
if (!verify(6n)(largeX)(y6)) {
|
|
73
|
+
throw false;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
steps4: () => {
|
|
77
|
+
if (!verify(4n)(smallX)(y4)) {
|
|
78
|
+
throw false;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
tampered: () => {
|
|
82
|
+
if (verify(4n)(smallX)((y4 + 1n) % p)) {
|
|
83
|
+
throw (y4 + 1n) % p;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
wrongY: () => {
|
|
87
|
+
if (verify(100n)(sampleX)(sampleY + 1n)) {
|
|
88
|
+
throw sampleY + 1n;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
zeroSteps: () => {
|
|
92
|
+
if (!verify(0n)(sampleX)(sampleX % p)) {
|
|
93
|
+
throw [sampleX % p];
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
negativeSteps: () => {
|
|
97
|
+
if (verify(-1n)(sampleX)(sampleY)) {
|
|
98
|
+
throw sampleY;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
invalidY: () => {
|
|
102
|
+
if (verify(100n)(sampleX)(0n)) {
|
|
103
|
+
throw 0n;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
modSqrt: {
|
|
108
|
+
roundTrip: () => {
|
|
109
|
+
const x = 999n;
|
|
110
|
+
if (!verify(1n)(x)(modSqrt(x))) {
|
|
111
|
+
throw modSqrt(x);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
nonResidue: () => {
|
|
115
|
+
if (quadRes(nonResidue)) {
|
|
116
|
+
throw nonResidue;
|
|
117
|
+
}
|
|
118
|
+
if (!verify(1n)(nonResidue)(modSqrt(nonResidue))) {
|
|
119
|
+
throw modSqrt(nonResidue);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
quadRes: {
|
|
124
|
+
one: () => {
|
|
125
|
+
if (!quadRes(1n)) {
|
|
126
|
+
throw 1n;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
nonResidue: () => {
|
|
130
|
+
if (quadRes(nonResidue)) {
|
|
131
|
+
throw nonResidue;
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
};
|
package/fs/dev/module.f.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
import type { Io } from '../io/module.f.ts';
|
|
7
|
-
import { type Access, type All, type Env, type Import, type NodeProgram, type Readdir } from '../types/effects/node/module.f.ts';
|
|
8
|
-
import { type Effect } from '../types/effects/module.f.ts';
|
|
1
|
+
import { type Access, type All, type Env, type Import, type NodeProgram, type Readdir } from '../effects/node/module.f.ts';
|
|
2
|
+
import { type Effect } from '../effects/module.f.ts';
|
|
9
3
|
export type Module = {
|
|
10
4
|
readonly proof?: unknown;
|
|
11
5
|
readonly [k: string]: unknown;
|
|
@@ -13,7 +7,6 @@ export type Module = {
|
|
|
13
7
|
export type ModuleMap = {
|
|
14
8
|
readonly [k in string]: Module;
|
|
15
9
|
};
|
|
16
|
-
export declare const env: (io: Io) => (v: string) => string | undefined;
|
|
17
10
|
/**
|
|
18
11
|
* Returns `true` if the file should be loaded for proof discovery.
|
|
19
12
|
*
|
package/fs/dev/module.f.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Development utilities for indexing modules and loading FunctionalScript files.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import { updateVersion } from "./version/module.f.js";
|
|
2
|
-
import {
|
|
7
|
+
import { all, both, import_, readdir, readFile, writeFile } from "../effects/node/module.f.js";
|
|
3
8
|
import { cmp as strCmp } from "../types/string/module.f.js";
|
|
4
9
|
import { utf8, utf8ToString } from "../text/module.f.js";
|
|
5
10
|
import { unwrap } from "../types/result/module.f.js";
|
|
6
|
-
import { begin, pure } from "../
|
|
11
|
+
import { begin, pure } from "../effects/module.f.js";
|
|
7
12
|
import { parse as jsonParse } from "../json/module.f.js";
|
|
8
13
|
import { record, unknown as rttiUnknown } from "../types/rtti/module.f.js";
|
|
9
14
|
import { parse as rttiParse } from "../types/rtti/parse/module.f.js";
|
|
10
15
|
import { relativize, toPosix } from "../path/module.f.js";
|
|
11
|
-
export const env = ({ process: { env } }) => a => {
|
|
12
|
-
const r = Object.getOwnPropertyDescriptor(env, a);
|
|
13
|
-
return r === undefined ? undefined :
|
|
14
|
-
typeof r.get === 'function' ? r.get() :
|
|
15
|
-
r.value;
|
|
16
|
-
};
|
|
17
16
|
/**
|
|
18
17
|
* Returns `true` if the file should be loaded for proof discovery.
|
|
19
18
|
*
|
|
@@ -92,7 +91,9 @@ const parseDenoJson = rttiParse(record(rttiUnknown));
|
|
|
92
91
|
const index2 = updateVersion
|
|
93
92
|
.step(() => readFile(denoJson))
|
|
94
93
|
.step(v => pure(unwrap(parseDenoJson(jsonParse(utf8ToString(unwrap(v)))))));
|
|
95
|
-
const allFiles2aa = allFiles('.', v => v.endsWith('/module.f.ts') ||
|
|
94
|
+
const allFiles2aa = allFiles('.', v => v.endsWith('/module.f.ts') ||
|
|
95
|
+
v.endsWith('/module.ts') ||
|
|
96
|
+
v.endsWith('/all.test.ts'))
|
|
96
97
|
.step(files => {
|
|
97
98
|
const exportsA = files.map(v => [v, `./${v.substring(2)}`]);
|
|
98
99
|
return pure(Object.fromEntries(exportsA));
|
package/fs/dev/proof.f.d.ts
CHANGED
package/fs/dev/proof.f.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { todo } from "../asserts/module.f.js";
|
|
2
|
-
import { env } from "./module.f.js";
|
|
3
2
|
export const proof = {
|
|
4
3
|
shouldPass: () => ({
|
|
5
4
|
then: () => undefined
|
|
@@ -57,24 +56,4 @@ export const proof = {
|
|
|
57
56
|
throw: () => {
|
|
58
57
|
todo();
|
|
59
58
|
},
|
|
60
|
-
env: () => {
|
|
61
|
-
const mockIo = { process: { env: { MY_VAR: 'hello' } } };
|
|
62
|
-
// missing key → undefined
|
|
63
|
-
const r1 = env(mockIo)('MISSING');
|
|
64
|
-
if (r1 !== undefined) {
|
|
65
|
-
throw r1;
|
|
66
|
-
}
|
|
67
|
-
// regular value property → returns value
|
|
68
|
-
const r2 = env(mockIo)('MY_VAR');
|
|
69
|
-
if (r2 !== 'hello') {
|
|
70
|
-
throw r2;
|
|
71
|
-
}
|
|
72
|
-
// getter property → calls get()
|
|
73
|
-
const envWithGetter = Object.defineProperty({}, 'GETTER_VAR', { get: () => 'from-getter', enumerable: true, configurable: true });
|
|
74
|
-
const mockIo2 = { process: { env: envWithGetter } };
|
|
75
|
-
const r3 = env(mockIo2)('GETTER_VAR');
|
|
76
|
-
if (r3 !== 'from-getter') {
|
|
77
|
-
throw r3;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
59
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type Effect } from '../../
|
|
2
|
-
import { type All, type ReadFile, type WriteFile } from '../../
|
|
1
|
+
import { type Effect } from '../../effects/module.f.ts';
|
|
2
|
+
import { type All, type ReadFile, type WriteFile } from '../../effects/node/module.f.ts';
|
|
3
3
|
export declare const updateVersion: Effect<ReadFile | WriteFile | All, number>;
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import { utf8, utf8ToString } from "../../text/module.f.js";
|
|
7
|
-
import { begin, pure } from "../../
|
|
8
|
-
import { all, readFile, writeFile } from "../../
|
|
7
|
+
import { begin, pure } from "../../effects/module.f.js";
|
|
8
|
+
import { all, readFile, writeFile } from "../../effects/node/module.f.js";
|
|
9
9
|
import { unwrap } from "../../types/result/module.f.js";
|
|
10
10
|
const { stringify, parse } = JSON;
|
|
11
11
|
const jsonFile = (jsonFile) => `${jsonFile}.json`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { utf8, utf8ToString } from "../../text/module.f.js";
|
|
2
2
|
import { isVec } from "../../types/bit_vec/module.f.js";
|
|
3
|
-
import { all, writeFile } from "../../
|
|
4
|
-
import { emptyState, virtual } from "../../
|
|
3
|
+
import { all, writeFile } from "../../effects/node/module.f.js";
|
|
4
|
+
import { emptyState, virtual } from "../../effects/node/virtual/module.f.js";
|
|
5
5
|
import { updateVersion } from "./module.f.js";
|
|
6
6
|
const version = '0.3.0';
|
|
7
7
|
const x = {
|
package/fs/djs/module.f.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import type { Primitive as JsonPrimitive } from '../json/module.f.ts';
|
|
7
|
-
import { type Effect } from '../
|
|
8
|
-
import { type WriteFile, type ReadFile, type Write } from '../
|
|
7
|
+
import { type Effect } from '../effects/module.f.ts';
|
|
8
|
+
import { type WriteFile, type ReadFile, type Write } from '../effects/node/module.f.ts';
|
|
9
9
|
export type Object = {
|
|
10
10
|
readonly [k in string]: Unknown;
|
|
11
11
|
};
|
package/fs/djs/module.f.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { transpile } from "./transpiler/module.f.js";
|
|
2
2
|
import { stringify, stringifyAsTree } from "./serializer/module.f.js";
|
|
3
3
|
import { sort } from "../types/object/module.f.js";
|
|
4
|
-
import { pure } from "../
|
|
5
|
-
import { writeFile, error, } from "../
|
|
4
|
+
import { pure } from "../effects/module.f.js";
|
|
5
|
+
import { writeFile, error, } from "../effects/node/module.f.js";
|
|
6
6
|
import { utf8 } from "../text/module.f.js";
|
|
7
7
|
export const compile = args => {
|
|
8
8
|
if (args.length < 2) {
|
|
@@ -7,11 +7,9 @@ import { type Result } from '../../types/result/module.f.ts';
|
|
|
7
7
|
import { type List } from '../../types/list/module.f.ts';
|
|
8
8
|
import type { DjsTokenWithMetadata } from '../tokenizer/module.f.ts';
|
|
9
9
|
import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
|
|
10
|
-
import type { Fs } from '../../io/module.f.ts';
|
|
11
10
|
import type { AstModule } from '../ast/module.f.ts';
|
|
12
11
|
import type { TokenMetadata } from '../../js/tokenizer/module.f.ts';
|
|
13
12
|
export type ParseContext = {
|
|
14
|
-
readonly fs: Fs;
|
|
15
13
|
readonly complete: OrderedMap<Result<AstModule, string>>;
|
|
16
14
|
readonly stack: List<string>;
|
|
17
15
|
};
|
package/fs/djs/proof.f.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compile } from "./module.f.js";
|
|
2
|
-
import { virtual, emptyState } from "../
|
|
2
|
+
import { virtual, emptyState } from "../effects/node/virtual/module.f.js";
|
|
3
3
|
import { isVec } from "../types/bit_vec/module.f.js";
|
|
4
4
|
import { utf8, utf8ToString } from "../text/module.f.js";
|
|
5
5
|
const readOutput = (root, path) => {
|
|
@@ -8,8 +8,8 @@ import { type Result } from '../../types/result/module.f.ts';
|
|
|
8
8
|
import { type List } from '../../types/list/module.f.ts';
|
|
9
9
|
import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
|
|
10
10
|
import { type ParseError } from '../parser/module.f.ts';
|
|
11
|
-
import { type Effect } from '../../
|
|
12
|
-
import { type ReadFile } from '../../
|
|
11
|
+
import { type Effect } from '../../effects/module.f.ts';
|
|
12
|
+
import { type ReadFile } from '../../effects/node/module.f.ts';
|
|
13
13
|
/**
|
|
14
14
|
* State threaded through the recursive transpilation of a DJS module graph.
|
|
15
15
|
*
|
|
@@ -12,8 +12,8 @@ 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 { foldStep, pure } from "../../
|
|
16
|
-
import { readFile } from "../../
|
|
15
|
+
import { foldStep, pure } from "../../effects/module.f.js";
|
|
16
|
+
import { readFile } from "../../effects/node/module.f.js";
|
|
17
17
|
import { utf8ToString } from "../../text/module.f.js";
|
|
18
18
|
const mapDjs = context => path => {
|
|
19
19
|
const res = at(path)(context.complete);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sort } from "../../types/object/module.f.js";
|
|
2
2
|
import { transpile } from "./module.f.js";
|
|
3
3
|
import { stringifyAsTree } from "../serializer/module.f.js";
|
|
4
|
-
import { virtual, emptyState } from "../../
|
|
4
|
+
import { virtual, emptyState } from "../../effects/node/virtual/module.f.js";
|
|
5
5
|
import { utf8 } from "../../text/module.f.js";
|
|
6
6
|
const run = (root) => (path) => {
|
|
7
7
|
const [_, result] = virtual({ ...emptyState, root })(transpile(path));
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import { type List } from '../list/module.f.ts';
|
|
6
|
+
import { type List } from '../types/list/module.f.ts';
|
|
7
7
|
export type Operation = readonly [string, (..._: readonly never[]) => unknown];
|
|
8
8
|
export type Effect<O extends Operation, T> = {
|
|
9
9
|
value: Value<O, T>;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { type
|
|
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>;
|
|
1
|
+
import { type NodeProgram } from './module.f.ts';
|
|
8
2
|
/**
|
|
9
3
|
* Runs a `NodeProgram` against the real Node `io` and process arguments,
|
|
10
4
|
* resolving to its exit code **without** terminating the process.
|
|
@@ -12,7 +6,7 @@ export type NodeRun = (p: NodeProgram) => Promise<never>;
|
|
|
12
6
|
* Use this when the caller must stay alive afterwards — e.g. when proofs are
|
|
13
7
|
* registered under an external test runner (Node `--test`, Bun, Playwright)
|
|
14
8
|
* that owns the process lifecycle. For a standalone CLI entry point that should
|
|
15
|
-
* exit with the program's code, use
|
|
9
|
+
* exit with the program's code, use {@link run} instead.
|
|
16
10
|
*/
|
|
17
11
|
export declare const runEffect: (p: NodeProgram) => Promise<number>;
|
|
18
12
|
/**
|
|
@@ -20,8 +14,7 @@ export declare const runEffect: (p: NodeProgram) => Promise<number>;
|
|
|
20
14
|
* `process.exit` with its exit code. The `Promise<never>` return type reflects
|
|
21
15
|
* that control never returns to the caller — the process terminates.
|
|
22
16
|
*
|
|
23
|
-
*
|
|
24
|
-
* `import run from '.../
|
|
17
|
+
* A `bin` script can simply
|
|
18
|
+
* `import { run } from '.../fs/effects/node/module.js'; await run(main)`.
|
|
25
19
|
*/
|
|
26
|
-
declare const run:
|
|
27
|
-
export default run;
|
|
20
|
+
export declare const run: (p: NodeProgram) => Promise<never>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Vec } from '../../bit_vec/module.f.ts';
|
|
2
|
-
import type { Nominal } from '../../nominal/module.f.ts';
|
|
3
|
-
import type { Result } from '../../result/module.f.ts';
|
|
1
|
+
import type { Vec } from '../../types/bit_vec/module.f.ts';
|
|
2
|
+
import type { Nominal } from '../../types/nominal/module.f.ts';
|
|
3
|
+
import type { Result } from '../../types/result/module.f.ts';
|
|
4
4
|
import { type Effect, type Func, type Operation, type ToAsyncOperationMap } from '../module.f.ts';
|
|
5
5
|
export type IoResult<T> = Result<T, unknown>;
|
|
6
6
|
export type All = ['all', <T>(...effects: Effect<never, T>[]) => readonly T[]];
|
|
@@ -10,12 +10,97 @@ import http from 'node:http';
|
|
|
10
10
|
import childProcess from 'node:child_process';
|
|
11
11
|
import fs from 'node:fs';
|
|
12
12
|
import process from 'node:process';
|
|
13
|
-
import { concat } from "../path/module.f.js";
|
|
14
13
|
import { once } from 'node:events';
|
|
15
|
-
import { runProgram } from "./module.f.js";
|
|
16
|
-
import { error, ok } from "../types/result/module.f.js";
|
|
17
|
-
import { fromVec } from "../types/uint8array/module.f.js";
|
|
18
14
|
import * as testContext from 'node:test';
|
|
15
|
+
import { concat } from "../../path/module.f.js";
|
|
16
|
+
import { normalize } from "../../path/module.f.js";
|
|
17
|
+
import {} from "../module.f.js";
|
|
18
|
+
import { asyncRun } from "../module.js";
|
|
19
|
+
import {} from "./module.f.js";
|
|
20
|
+
import { asBase, asNominal } from "../../types/nominal/module.f.js";
|
|
21
|
+
import { error, ok } from "../../types/result/module.f.js";
|
|
22
|
+
import { fromVec, listToVec, toVec } from "../../types/uint8array/module.f.js";
|
|
23
|
+
const tc = async (f) => {
|
|
24
|
+
try {
|
|
25
|
+
return ok(await f());
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
return error(e);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const collect = async (v) => {
|
|
32
|
+
let result = [];
|
|
33
|
+
for await (const a of v) {
|
|
34
|
+
result = [...result, a];
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
const fromIo = ({ fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, now: ioNow, sandbox, write, await: awaitPromise, }) => {
|
|
39
|
+
const result = asyncRun({
|
|
40
|
+
all: async (...effects) => await Promise.all(effects.map(result)),
|
|
41
|
+
fetch: async (url) => tc(async () => {
|
|
42
|
+
const response = await fetch(url);
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error(`Fetch error: ${response.status} ${response.statusText}`);
|
|
45
|
+
}
|
|
46
|
+
return toVec(new Uint8Array(await response.arrayBuffer()));
|
|
47
|
+
}),
|
|
48
|
+
mkdir: (...p) => tc(async () => { await mkdir(...p); }),
|
|
49
|
+
readFile: path => tc(async () => toVec(await readFile(path))),
|
|
50
|
+
readdir: (path, r) => tc(async () => (await readdir(path, { ...r, withFileTypes: true }))
|
|
51
|
+
.map(v => ({
|
|
52
|
+
name: v.name,
|
|
53
|
+
parentPath: normalize(v.parentPath),
|
|
54
|
+
isFile: v.isFile()
|
|
55
|
+
}))),
|
|
56
|
+
writeFile: (path, data) => tc(() => writeFile(path, fromVec(data))),
|
|
57
|
+
rm: path => tc(() => rm(path)),
|
|
58
|
+
access: path => tc(() => access(path)),
|
|
59
|
+
import: path => tc(() => asyncImport(path)),
|
|
60
|
+
exec: (command, stdin) => new Promise(resolve => {
|
|
61
|
+
const child = childProcess.exec(command, (e, stdout, stderr) => resolve(e !== null ? ['error', e] : ok({ stdout, stderr })));
|
|
62
|
+
child.stdin?.end(stdin);
|
|
63
|
+
}),
|
|
64
|
+
createServer: async (requestListener) => {
|
|
65
|
+
const erl = requestListener;
|
|
66
|
+
const nodeRl = async (req, res) => {
|
|
67
|
+
const reqBody = await collect(req);
|
|
68
|
+
const { method, url, headers } = req;
|
|
69
|
+
const { status, headers: outHeaders, body: outBody } = await result(erl({
|
|
70
|
+
method,
|
|
71
|
+
url,
|
|
72
|
+
headers,
|
|
73
|
+
body: listToVec(reqBody)
|
|
74
|
+
}));
|
|
75
|
+
res
|
|
76
|
+
.writeHead(status, outHeaders)
|
|
77
|
+
.end(fromVec(outBody));
|
|
78
|
+
};
|
|
79
|
+
const server = asNominal(createServer(nodeRl));
|
|
80
|
+
return server;
|
|
81
|
+
},
|
|
82
|
+
listen: async (server, port) => {
|
|
83
|
+
const s = asBase(server);
|
|
84
|
+
s.listen(port);
|
|
85
|
+
},
|
|
86
|
+
forever: () => new Promise(() => { }),
|
|
87
|
+
now: async () => ioNow(),
|
|
88
|
+
sandbox,
|
|
89
|
+
await: awaitPromise,
|
|
90
|
+
write,
|
|
91
|
+
test: async (ctx, name, expectFailure, test) => ctx.test(name, { expectFailure }, async (t) => result(test(t))),
|
|
92
|
+
});
|
|
93
|
+
return result;
|
|
94
|
+
};
|
|
95
|
+
const runProgram = (io) => {
|
|
96
|
+
const { process: { env, stdout, stderr }, testContext, bunTestContext, playwrightTestContext, engine } = io;
|
|
97
|
+
const std = { stdout, stderr };
|
|
98
|
+
const f = fromIo(io);
|
|
99
|
+
return args => {
|
|
100
|
+
const options = { args, env, std, testContext, bunTestContext, playwrightTestContext, engine };
|
|
101
|
+
return program => f(program(options));
|
|
102
|
+
};
|
|
103
|
+
};
|
|
19
104
|
const isPlaywright = 'PLAYWRIGHT_TEST' in (process?.env ?? {});
|
|
20
105
|
const pwTest = isPlaywright
|
|
21
106
|
? (await import('@playwright/test')).test
|
|
@@ -66,8 +151,8 @@ const writeAll = async (stream, data) => {
|
|
|
66
151
|
await once(stream, 'drain');
|
|
67
152
|
}
|
|
68
153
|
};
|
|
69
|
-
|
|
70
|
-
|
|
154
|
+
const asyncImport = (v) => import(__rewriteRelativeImportExtension(v));
|
|
155
|
+
const tryCatch = f => {
|
|
71
156
|
try {
|
|
72
157
|
return ok(f());
|
|
73
158
|
}
|
|
@@ -76,7 +161,7 @@ export const tryCatch = f => {
|
|
|
76
161
|
}
|
|
77
162
|
};
|
|
78
163
|
const awaitPromise = async (p) => [p instanceof Promise ? await p : p];
|
|
79
|
-
|
|
164
|
+
const io = {
|
|
80
165
|
console,
|
|
81
166
|
fs,
|
|
82
167
|
process,
|
|
@@ -132,7 +217,7 @@ export const io = {
|
|
|
132
217
|
* Use this when the caller must stay alive afterwards — e.g. when proofs are
|
|
133
218
|
* registered under an external test runner (Node `--test`, Bun, Playwright)
|
|
134
219
|
* that owns the process lifecycle. For a standalone CLI entry point that should
|
|
135
|
-
* exit with the program's code, use
|
|
220
|
+
* exit with the program's code, use {@link run} instead.
|
|
136
221
|
*/
|
|
137
222
|
export const runEffect = runProgram(io)(io.process.argv.slice(2));
|
|
138
223
|
/**
|
|
@@ -140,8 +225,7 @@ export const runEffect = runProgram(io)(io.process.argv.slice(2));
|
|
|
140
225
|
* `process.exit` with its exit code. The `Promise<never>` return type reflects
|
|
141
226
|
* that control never returns to the caller — the process terminates.
|
|
142
227
|
*
|
|
143
|
-
*
|
|
144
|
-
* `import run from '.../
|
|
228
|
+
* A `bin` script can simply
|
|
229
|
+
* `import { run } from '.../fs/effects/node/module.js'; await run(main)`.
|
|
145
230
|
*/
|
|
146
|
-
const run = async (p) => process.exit(await runEffect(p));
|
|
147
|
-
export default run;
|
|
231
|
+
export const run = async (p) => process.exit(await runEffect(p));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { empty, isVec, uint, vec8 } from "../../bit_vec/module.f.js";
|
|
1
|
+
import { empty, isVec, uint, vec8 } from "../../types/bit_vec/module.f.js";
|
|
2
2
|
import { pure } from "../module.f.js";
|
|
3
3
|
import { fetch, mkdir, now, readdir, readFile, rm, sandbox, writeFile } from "./module.f.js";
|
|
4
4
|
import { emptyState, virtual } from "./virtual/module.f.js";
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import { parse } from "
|
|
8
|
-
import { utf8ToString } from "
|
|
9
|
-
import { isVec } from "../../../bit_vec/module.f.js";
|
|
10
|
-
import { error, ok } from "../../../result/module.f.js";
|
|
6
|
+
import { todo } from "../../../asserts/module.f.js";
|
|
7
|
+
import { parse } from "../../../path/module.f.js";
|
|
8
|
+
import { utf8ToString } from "../../../text/module.f.js";
|
|
9
|
+
import { isVec } from "../../../types/bit_vec/module.f.js";
|
|
10
|
+
import { error, ok } from "../../../types/result/module.f.js";
|
|
11
11
|
import { run } from "../../mock/module.f.js";
|
|
12
12
|
export const emptyState = {
|
|
13
13
|
stdout: '',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type All, type Await, type NodeProgram, type NodeProgramOptions, type Program, type Sandbox, type SandboxResult, type Test, type TestContext, type Write } from '../
|
|
2
|
-
import { type Effect, type Operation } from '../
|
|
1
|
+
import { type All, type Await, type NodeProgram, type NodeProgramOptions, type Program, type Sandbox, type SandboxResult, type Test, type TestContext, type Write } from '../effects/node/module.f.ts';
|
|
2
|
+
import { type Effect, type Operation } from '../effects/module.f.ts';
|
|
3
3
|
import { type LoadModuleOperations, type ModuleMap } from '../dev/module.f.ts';
|
|
4
4
|
/** A zero-argument test function whose return value may contain sub-tests. */
|
|
5
5
|
export type TestFn = () => unknown;
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* @module
|
|
12
12
|
*/
|
|
13
13
|
import { reset, fgGreen, fgRed, bold, csiWrite } from "../text/sgr/module.f.js";
|
|
14
|
-
import { all, awaitIfPromise, sandbox, test } from "../
|
|
15
|
-
import { pure } from "../
|
|
14
|
+
import { all, awaitIfPromise, sandbox, test } from "../effects/node/module.f.js";
|
|
15
|
+
import { pure } from "../effects/module.f.js";
|
|
16
16
|
import { loadModuleMap, shouldLoad } from "../dev/module.f.js";
|
|
17
17
|
import { invert } from "../types/result/module.f.js";
|
|
18
18
|
const addPass = (delta) => (ts) => ({ ...ts, time: ts.time + delta, pass: ts.pass + 1 });
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { pure } from "../
|
|
2
|
-
import { emptyState } from "../
|
|
3
|
-
import { virtual } from "../
|
|
1
|
+
import { pure } from "../effects/module.f.js";
|
|
2
|
+
import { emptyState } from "../effects/node/virtual/module.f.js";
|
|
3
|
+
import { virtual } from "../effects/node/virtual/module.f.js";
|
|
4
4
|
import { assert, assertEq, todo } from "../asserts/module.f.js";
|
|
5
5
|
import { testAll, defaultReporter, fmtPath, fmtTerm, fmtImport, ghEscape, isInteger, isIdentifier, registerModule, defaultTest, } from "./module.f.js";
|
|
6
|
-
import { run as mockRun } from "../
|
|
6
|
+
import { run as mockRun } from "../effects/mock/module.f.js";
|
|
7
7
|
import { shouldLoad } from "../dev/module.f.js";
|
|
8
8
|
const makeReporter = () => {
|
|
9
9
|
const events = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import '../
|
|
1
|
+
import '../all.test.ts';
|