functionalscript 0.10.3 → 0.11.1
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/bnf/data/module.f.d.ts +67 -1
- package/bnf/data/module.f.js +27 -0
- package/bnf/module.f.js +8 -0
- package/cas/module.f.d.ts +27 -6
- package/cas/module.f.js +38 -32
- package/ci/module.f.d.ts +4 -3
- package/ci/module.f.js +3 -4
- package/crypto/sha2/module.f.d.ts +10 -0
- package/crypto/sha2/module.f.js +8 -0
- package/crypto/sign/module.f.d.ts +15 -0
- package/crypto/sign/module.f.js +15 -0
- package/dev/index/module.f.d.ts +2 -0
- package/dev/index/module.f.js +2 -0
- package/dev/module.f.d.ts +4 -2
- package/dev/module.f.js +29 -28
- package/dev/version/module.f.d.ts +3 -2
- package/dev/version/module.f.js +10 -10
- package/dev/version/test.f.js +3 -6
- package/html/module.f.d.ts +18 -0
- package/html/module.f.js +12 -0
- package/io/module.f.d.ts +4 -2
- package/io/module.f.js +24 -18
- package/package.json +4 -4
- package/types/effects/mock/module.f.d.ts +5 -4
- package/types/effects/mock/module.f.js +6 -4
- package/types/effects/module.d.ts +2 -2
- package/types/effects/module.f.d.ts +17 -19
- package/types/effects/module.f.js +14 -19
- package/types/effects/module.js +4 -3
- package/types/effects/node/module.f.d.ts +31 -35
- package/types/effects/node/module.f.js +16 -7
- package/types/effects/node/test.f.js +23 -25
- package/types/effects/node/virtual/module.f.d.ts +8 -8
- package/types/effects/node/virtual/module.f.js +13 -2
- package/website/module.f.d.ts +3 -1
- package/website/module.f.js +3 -4
- package/ci/module.d.ts +0 -1
- package/ci/module.js +0 -3
- package/dev/index/module.d.ts +0 -1
- package/dev/index/module.js +0 -3
- package/website/module.d.ts +0 -1
- package/website/module.js +0 -3
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { empty, isVec, uint, vec8 } from "../../bit_vec/module.f.js";
|
|
2
|
-
import { map } from "../module.f.js";
|
|
3
2
|
import { run } from "../mock/module.f.js";
|
|
3
|
+
import { pure } from "../module.f.js";
|
|
4
4
|
import { fetch, mkdir, readdir, readFile, writeFile } from "./module.f.js";
|
|
5
5
|
import { emptyState, virtual } from "./virtual/module.f.js";
|
|
6
6
|
export default {
|
|
7
7
|
map: () => {
|
|
8
|
-
let e =
|
|
8
|
+
let e = readFile('hello').step(([k, v]) => {
|
|
9
9
|
if (k === 'error') {
|
|
10
10
|
throw v;
|
|
11
11
|
}
|
|
12
|
-
return uint(v) * 2n;
|
|
12
|
+
return pure(uint(v) * 2n);
|
|
13
13
|
});
|
|
14
14
|
//
|
|
15
15
|
while (true) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const { value } = e;
|
|
17
|
+
if (value.length === 1) {
|
|
18
|
+
const [result] = value;
|
|
18
19
|
if (result !== 0x2an) {
|
|
19
20
|
throw result;
|
|
20
21
|
}
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
|
-
const [cmd, p, cont] =
|
|
24
|
+
const [cmd, p, cont] = value;
|
|
24
25
|
if (cmd !== 'readFile') {
|
|
25
26
|
throw cmd;
|
|
26
27
|
}
|
|
@@ -31,8 +32,7 @@ export default {
|
|
|
31
32
|
}
|
|
32
33
|
},
|
|
33
34
|
fetch: () => {
|
|
34
|
-
const
|
|
35
|
-
const [_, [t, result]] = v({
|
|
35
|
+
const [_, [t, result]] = virtual({
|
|
36
36
|
...emptyState,
|
|
37
37
|
internet: {
|
|
38
38
|
'https://example.com/data': vec8(0x2an),
|
|
@@ -50,8 +50,7 @@ export default {
|
|
|
50
50
|
},
|
|
51
51
|
mkdir: {
|
|
52
52
|
one: () => {
|
|
53
|
-
const
|
|
54
|
-
const [state, [t, result]] = v(emptyState)(mkdir('a'));
|
|
53
|
+
const [state, [t, result]] = virtual(emptyState)(mkdir('a'));
|
|
55
54
|
if (t === 'error') {
|
|
56
55
|
throw result;
|
|
57
56
|
}
|
|
@@ -61,7 +60,7 @@ export default {
|
|
|
61
60
|
}
|
|
62
61
|
},
|
|
63
62
|
rec: () => {
|
|
64
|
-
const [state, [t, result]] =
|
|
63
|
+
const [state, [t, result]] = virtual(emptyState)(mkdir('tmp/cache', { recursive: true }));
|
|
65
64
|
if (t !== 'ok') {
|
|
66
65
|
throw result;
|
|
67
66
|
}
|
|
@@ -75,7 +74,7 @@ export default {
|
|
|
75
74
|
}
|
|
76
75
|
},
|
|
77
76
|
nonRec: () => {
|
|
78
|
-
const [state, [t, result]] =
|
|
77
|
+
const [state, [t, result]] = virtual(emptyState)(mkdir('tmp/cache'));
|
|
79
78
|
if (t !== 'error') {
|
|
80
79
|
throw result;
|
|
81
80
|
}
|
|
@@ -86,14 +85,13 @@ export default {
|
|
|
86
85
|
},
|
|
87
86
|
readFile: {
|
|
88
87
|
one: () => {
|
|
89
|
-
const v = run(virtual);
|
|
90
88
|
const initial = {
|
|
91
89
|
...emptyState,
|
|
92
90
|
root: {
|
|
93
91
|
hello: vec8(0x2an),
|
|
94
92
|
},
|
|
95
93
|
};
|
|
96
|
-
const [state, [t, result]] =
|
|
94
|
+
const [state, [t, result]] = virtual(initial)(readFile('hello'));
|
|
97
95
|
if (t === 'error') {
|
|
98
96
|
throw result;
|
|
99
97
|
}
|
|
@@ -108,7 +106,7 @@ export default {
|
|
|
108
106
|
}
|
|
109
107
|
},
|
|
110
108
|
nested: () => {
|
|
111
|
-
const [_, [tag, result]] =
|
|
109
|
+
const [_, [tag, result]] = virtual({
|
|
112
110
|
...emptyState,
|
|
113
111
|
root: { tmp: { cache: vec8(0x15n) } }
|
|
114
112
|
})(readFile('tmp/cache'));
|
|
@@ -120,13 +118,13 @@ export default {
|
|
|
120
118
|
}
|
|
121
119
|
},
|
|
122
120
|
noSuchFile: () => {
|
|
123
|
-
const [_, [t, result]] =
|
|
121
|
+
const [_, [t, result]] = virtual(emptyState)(readFile('hello'));
|
|
124
122
|
if (t !== 'error') {
|
|
125
123
|
throw result;
|
|
126
124
|
}
|
|
127
125
|
},
|
|
128
126
|
nestedPath: () => {
|
|
129
|
-
const [_, [t, result]] =
|
|
127
|
+
const [_, [t, result]] = virtual(emptyState)(readFile('tmp/cache'));
|
|
130
128
|
if (t !== 'error') {
|
|
131
129
|
throw result;
|
|
132
130
|
}
|
|
@@ -137,7 +135,7 @@ export default {
|
|
|
137
135
|
},
|
|
138
136
|
readdir: {
|
|
139
137
|
one: () => {
|
|
140
|
-
const [_, [t, result]] =
|
|
138
|
+
const [_, [t, result]] = virtual({
|
|
141
139
|
...emptyState,
|
|
142
140
|
root: {
|
|
143
141
|
file: vec8(0x2an),
|
|
@@ -159,7 +157,7 @@ export default {
|
|
|
159
157
|
}
|
|
160
158
|
},
|
|
161
159
|
nonRecursive: () => {
|
|
162
|
-
const [_, [t, result]] =
|
|
160
|
+
const [_, [t, result]] = virtual({
|
|
163
161
|
...emptyState,
|
|
164
162
|
root: {
|
|
165
163
|
file: vec8(0x2an),
|
|
@@ -184,7 +182,7 @@ export default {
|
|
|
184
182
|
}
|
|
185
183
|
},
|
|
186
184
|
nested: () => {
|
|
187
|
-
const [_, [t, result]] =
|
|
185
|
+
const [_, [t, result]] = virtual({
|
|
188
186
|
...emptyState,
|
|
189
187
|
root: { tmp: { cache: vec8(0x15n) } }
|
|
190
188
|
})(readdir('tmp', { recursive: true }));
|
|
@@ -203,7 +201,7 @@ export default {
|
|
|
203
201
|
}
|
|
204
202
|
},
|
|
205
203
|
noSuchDir: () => {
|
|
206
|
-
const [_, [t, result]] =
|
|
204
|
+
const [_, [t, result]] = virtual(emptyState)(readdir('tmp', { recursive: true }));
|
|
207
205
|
if (t !== 'error') {
|
|
208
206
|
throw result;
|
|
209
207
|
}
|
|
@@ -214,7 +212,7 @@ export default {
|
|
|
214
212
|
},
|
|
215
213
|
writeFile: {
|
|
216
214
|
one: () => {
|
|
217
|
-
const [state, [t, result]] =
|
|
215
|
+
const [state, [t, result]] = virtual(emptyState)(writeFile('hello', vec8(0x2an)));
|
|
218
216
|
if (t !== 'ok') {
|
|
219
217
|
throw result;
|
|
220
218
|
}
|
|
@@ -227,7 +225,7 @@ export default {
|
|
|
227
225
|
}
|
|
228
226
|
},
|
|
229
227
|
overwrite: () => {
|
|
230
|
-
const [state, [t, result]] =
|
|
228
|
+
const [state, [t, result]] = virtual({
|
|
231
229
|
...emptyState,
|
|
232
230
|
root: {
|
|
233
231
|
hello: vec8(0x15n),
|
|
@@ -245,7 +243,7 @@ export default {
|
|
|
245
243
|
}
|
|
246
244
|
},
|
|
247
245
|
nestedPath: () => {
|
|
248
|
-
const [state, [t, result]] =
|
|
246
|
+
const [state, [t, result]] = virtual(emptyState)(writeFile('tmp/cache', vec8(0x2an)));
|
|
249
247
|
if (t !== 'error') {
|
|
250
248
|
throw result;
|
|
251
249
|
}
|
|
@@ -257,7 +255,7 @@ export default {
|
|
|
257
255
|
}
|
|
258
256
|
},
|
|
259
257
|
directory: () => {
|
|
260
|
-
const [state, [t, result]] =
|
|
258
|
+
const [state, [t, result]] = virtual({
|
|
261
259
|
...emptyState,
|
|
262
260
|
root: {
|
|
263
261
|
tmp: {},
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { type Vec } from "../../../bit_vec/module.f.ts";
|
|
2
|
-
import type
|
|
3
|
-
import type {
|
|
4
|
-
export type
|
|
5
|
-
readonly [name in string]?:
|
|
2
|
+
import { type RunInstance } from "../../mock/module.f.ts";
|
|
3
|
+
import type { NodeOp } from "../module.f.ts";
|
|
4
|
+
export type Dir = {
|
|
5
|
+
readonly [name in string]?: Dir | Vec;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
7
|
+
export type State = {
|
|
8
8
|
stdout: string;
|
|
9
9
|
stderr: string;
|
|
10
|
-
root:
|
|
10
|
+
root: Dir;
|
|
11
11
|
internet: {
|
|
12
12
|
readonly [url: string]: Vec;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
export declare const emptyState:
|
|
16
|
-
export declare const virtual:
|
|
15
|
+
export declare const emptyState: State;
|
|
16
|
+
export declare const virtual: RunInstance<NodeOp, State>;
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import { parse } from "../../../../path/module.f.js";
|
|
7
7
|
import { isVec } from "../../../bit_vec/module.f.js";
|
|
8
8
|
import { error, ok } from "../../../result/module.f.js";
|
|
9
|
+
import { run } from "../../mock/module.f.js";
|
|
10
|
+
import { pure } from "../../module.f.js";
|
|
9
11
|
export const emptyState = {
|
|
10
12
|
stdout: '',
|
|
11
13
|
stderr: '',
|
|
@@ -30,7 +32,6 @@ const operation = (op) => {
|
|
|
30
32
|
return [{ ...state, root }, result];
|
|
31
33
|
};
|
|
32
34
|
};
|
|
33
|
-
// TODO: we can have a better implementation with some code shared with `operation`.
|
|
34
35
|
const readOperation = (op) => operation((dir, path) => [dir, op(dir, path)]);
|
|
35
36
|
const okVoid = ok(undefined);
|
|
36
37
|
const mkdir = (recursive) => operation((dir, path) => {
|
|
@@ -94,7 +95,16 @@ const readdir = (base, recursive) => readOperation((dir, path) => {
|
|
|
94
95
|
return ok(f(base, dir));
|
|
95
96
|
});
|
|
96
97
|
const console = (name) => (state, payload) => [{ ...state, [name]: `${state[name]}${payload}\n` }, undefined];
|
|
97
|
-
|
|
98
|
+
const map = {
|
|
99
|
+
all: (state, a) => {
|
|
100
|
+
let e = [];
|
|
101
|
+
for (const i of a) {
|
|
102
|
+
const [ns, ei] = virtual(state)(i);
|
|
103
|
+
state = ns;
|
|
104
|
+
e = [...e, ei];
|
|
105
|
+
}
|
|
106
|
+
return [state, e];
|
|
107
|
+
},
|
|
98
108
|
error: console('stderr'),
|
|
99
109
|
log: console('stdout'),
|
|
100
110
|
fetch: (state, url) => {
|
|
@@ -106,3 +116,4 @@ export const virtual = {
|
|
|
106
116
|
readdir: (state, [path, { recursive }]) => readdir(path, recursive === true)(state, path),
|
|
107
117
|
writeFile: (state, [path, payload]) => writeFile(payload)(state, path),
|
|
108
118
|
};
|
|
119
|
+
export const virtual = run(map);
|
package/website/module.f.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { type NodeOp } from '../types/effects/node/module.f.ts';
|
|
2
|
+
import { type Effect } from '../types/effects/module.f.ts';
|
|
3
|
+
declare const _default: () => Effect<NodeOp, number>;
|
|
2
4
|
export default _default;
|
package/website/module.f.js
CHANGED
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
import { htmlToString } from "../html/module.f.js";
|
|
7
7
|
import { writeFile } from "../types/effects/node/module.f.js";
|
|
8
8
|
import { utf8 } from "../text/module.f.js";
|
|
9
|
-
import {
|
|
9
|
+
import { begin, pure } from "../types/effects/module.f.js";
|
|
10
10
|
const html = ['body',
|
|
11
11
|
['a', { href: 'https://github.com/functionalscript/functionalscript' }, 'GitHub Repository']
|
|
12
12
|
];
|
|
13
|
-
const program =
|
|
13
|
+
const program = begin
|
|
14
14
|
.step(() => writeFile('index.html', utf8(htmlToString(html))))
|
|
15
|
-
.step(() => pure(0))
|
|
16
|
-
.effect;
|
|
15
|
+
.step(() => pure(0));
|
|
17
16
|
export default () => program;
|
package/ci/module.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/ci/module.js
DELETED
package/dev/index/module.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dev/index/module.js
DELETED
package/website/module.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/website/module.js
DELETED