functionalscript 0.9.1 → 0.9.3
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/README.md +3 -3
- package/bnf/data/test.f.d.ts +2 -0
- package/bnf/data/test.f.js +39 -2
- package/bnf/module.f.d.ts +6 -2
- package/bnf/module.f.js +10 -11
- package/cas/module.f.d.ts +14 -13
- package/cas/module.f.js +78 -60
- package/ci/module.f.d.ts +3 -2
- package/ci/module.f.js +6 -8
- package/ci/module.js +3 -3
- package/crypto/hmac/test.f.js +1 -1
- package/crypto/sign/test.f.js +1 -1
- package/dev/module.f.d.ts +1 -1
- package/dev/module.f.js +13 -6
- package/dev/tf/all.test.js +2 -2
- package/dev/tf/module.f.js +2 -2
- package/dev/version/module.f.d.ts +2 -11
- package/dev/version/module.f.js +17 -15
- package/dev/version/test.f.d.ts +3 -1
- package/dev/version/test.f.js +26 -11
- package/djs/parser-new/module.f.d.ts +3 -0
- package/djs/parser-new/module.f.js +149 -0
- package/djs/parser-new/test.f.d.ts +5 -0
- package/djs/parser-new/test.f.js +202 -0
- package/djs/serializer/module.f.js +6 -6
- package/fjs/module.f.d.ts +1 -1
- package/fjs/module.f.js +3 -2
- package/fsc/module.f.js +1 -1
- package/io/module.d.ts +4 -0
- package/io/module.f.d.ts +10 -4
- package/io/module.f.js +28 -0
- package/io/module.js +7 -1
- package/json/module.f.js +3 -3
- package/package.json +3 -2
- package/path/module.f.d.ts +1 -0
- package/path/module.f.js +6 -3
- package/text/utf16/module.f.js +1 -1
- package/text/utf8/module.f.d.ts +1 -1
- package/types/asn.1/module.f.d.ts +62 -0
- package/types/asn.1/module.f.js +276 -0
- package/types/asn.1/test.f.d.ts +44 -0
- package/types/asn.1/test.f.js +312 -0
- package/types/base128/module.f.d.ts +15 -0
- package/types/base128/module.f.js +38 -0
- package/types/base128/test.f.d.ts +2 -0
- package/types/base128/test.f.js +26 -0
- package/types/bit_vec/module.f.d.ts +15 -3
- package/types/bit_vec/module.f.js +22 -2
- package/types/bit_vec/test.f.d.ts +1 -0
- package/types/bit_vec/test.f.js +28 -6
- package/types/effect/mock/module.f.d.ts +5 -0
- package/types/effect/mock/module.f.js +14 -0
- package/types/effect/module.d.ts +2 -0
- package/types/effect/module.f.d.ts +23 -0
- package/types/effect/module.f.js +14 -0
- package/types/effect/module.js +11 -0
- package/types/effect/node/module.f.d.ts +56 -0
- package/types/effect/node/module.f.js +8 -0
- package/types/effect/node/test.f.d.ts +28 -0
- package/types/effect/node/test.f.js +277 -0
- package/types/effect/node/virtual/module.f.d.ts +16 -0
- package/types/effect/node/virtual/module.f.js +103 -0
- package/types/function/module.f.d.ts +1 -1
- package/types/function/module.f.js +1 -1
- package/types/function/test.f.js +1 -1
- package/types/list/module.f.js +4 -4
- package/website/module.d.ts +1 -0
- package/website/module.f.d.ts +3 -0
- package/website/module.f.js +9 -0
- package/website/module.js +3 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { parse } from "../../../../path/module.f.js";
|
|
2
|
+
import { isVec } from "../../../bit_vec/module.f.js";
|
|
3
|
+
import { error, ok } from "../../../result/module.f.js";
|
|
4
|
+
export const emptyState = {
|
|
5
|
+
stdout: '',
|
|
6
|
+
stderr: '',
|
|
7
|
+
root: {},
|
|
8
|
+
internet: {},
|
|
9
|
+
};
|
|
10
|
+
const operation = (op) => {
|
|
11
|
+
const f = (dir, path) => {
|
|
12
|
+
if (path.length === 0) {
|
|
13
|
+
return op(dir, path);
|
|
14
|
+
}
|
|
15
|
+
const [first, ...rest] = path;
|
|
16
|
+
const subDir = dir[first];
|
|
17
|
+
if (subDir === undefined || isVec(subDir)) {
|
|
18
|
+
return op(dir, path);
|
|
19
|
+
}
|
|
20
|
+
const [newSubDir, r] = f(subDir, rest);
|
|
21
|
+
return [{ ...dir, [first]: newSubDir }, r];
|
|
22
|
+
};
|
|
23
|
+
return (state, path) => {
|
|
24
|
+
const [root, result] = f(state.root, parse(path));
|
|
25
|
+
return [{ ...state, root }, result];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
// TODO: we can have a better implementation with some code shared with `operation`.
|
|
29
|
+
const readOperation = (op) => operation((dir, path) => [dir, op(dir, path)]);
|
|
30
|
+
const okVoid = ok(undefined);
|
|
31
|
+
const mkdir = (recursive) => operation((dir, path) => {
|
|
32
|
+
let d = {};
|
|
33
|
+
let i = path.length;
|
|
34
|
+
if (i > 1 && !recursive) {
|
|
35
|
+
return [dir, error('non-recursive')];
|
|
36
|
+
}
|
|
37
|
+
while (i > 0) {
|
|
38
|
+
i -= 1;
|
|
39
|
+
d = { [path[i]]: d };
|
|
40
|
+
}
|
|
41
|
+
dir = { ...dir, ...d };
|
|
42
|
+
return [dir, okVoid];
|
|
43
|
+
});
|
|
44
|
+
const readFileError = error('no such file');
|
|
45
|
+
const readFile = readOperation((dir, path) => {
|
|
46
|
+
if (path.length !== 1) {
|
|
47
|
+
return readFileError;
|
|
48
|
+
}
|
|
49
|
+
const file = dir[path[0]];
|
|
50
|
+
if (!isVec(file)) {
|
|
51
|
+
return error(`'${path[0]}' is not a file`);
|
|
52
|
+
}
|
|
53
|
+
return ok(file);
|
|
54
|
+
});
|
|
55
|
+
const writeFileError = error('invalid file');
|
|
56
|
+
const writeFile = (payload) => operation((dir, path) => {
|
|
57
|
+
if (path.length !== 1) {
|
|
58
|
+
return [dir, writeFileError];
|
|
59
|
+
}
|
|
60
|
+
const [name] = path;
|
|
61
|
+
const file = dir[name];
|
|
62
|
+
// fail if the file is a directory
|
|
63
|
+
if (file !== undefined && !isVec(file)) {
|
|
64
|
+
return [dir, writeFileError];
|
|
65
|
+
}
|
|
66
|
+
dir = { ...dir, [name]: payload };
|
|
67
|
+
return [dir, okVoid];
|
|
68
|
+
});
|
|
69
|
+
const invalidPath = error('invalid path');
|
|
70
|
+
const { entries } = Object;
|
|
71
|
+
const readdir = (base, recursive) => readOperation((dir, path) => {
|
|
72
|
+
if (path.length !== 0) {
|
|
73
|
+
return invalidPath;
|
|
74
|
+
}
|
|
75
|
+
const f = (parentPath, d) => {
|
|
76
|
+
let result = [];
|
|
77
|
+
for (const [name, content] of entries(d)) {
|
|
78
|
+
if (content === undefined) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const isFile = isVec(content);
|
|
82
|
+
result = [...result, { name, parentPath, isFile }];
|
|
83
|
+
if (!isFile && recursive) {
|
|
84
|
+
result = [...result, ...f(`${parentPath}/${name}`, content)];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
return ok(f(base, dir));
|
|
90
|
+
});
|
|
91
|
+
const console = (name) => (state, payload) => [{ ...state, [name]: `${state[name]}${payload}\n` }, undefined];
|
|
92
|
+
export const virtual = {
|
|
93
|
+
error: console('stderr'),
|
|
94
|
+
log: console('stdout'),
|
|
95
|
+
fetch: (state, url) => {
|
|
96
|
+
const result = state.internet[url];
|
|
97
|
+
return result === undefined ? [state, error('not found')] : [state, ok(result)];
|
|
98
|
+
},
|
|
99
|
+
mkdir: (state, [path, p]) => mkdir(p !== undefined)(state, path),
|
|
100
|
+
readFile,
|
|
101
|
+
readdir: (state, [path, { recursive }]) => readdir(path, recursive === true)(state, path),
|
|
102
|
+
writeFile: (state, [path, payload]) => writeFile(payload)(state, path),
|
|
103
|
+
};
|
|
@@ -19,7 +19,7 @@ export declare const flip: <A, B, C>(f: (a: A) => (b: B) => C) => (b: B) => (a:
|
|
|
19
19
|
*/
|
|
20
20
|
type Fn<I, O> = {
|
|
21
21
|
readonly result: Func<I, O>;
|
|
22
|
-
readonly
|
|
22
|
+
readonly map: <T>(g: Func<O, T>) => Fn<I, T>;
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Creates an `Fn` instance from a function, enabling chaining of transformations.
|
package/types/function/test.f.js
CHANGED
package/types/list/module.f.js
CHANGED
|
@@ -96,12 +96,12 @@ export const last = first => tail => {
|
|
|
96
96
|
export const find = def => f => compose(filter(f))(first(def));
|
|
97
97
|
export const some = find(false)(identity);
|
|
98
98
|
export const isEmpty = fn(map(() => true))
|
|
99
|
-
.
|
|
100
|
-
.
|
|
99
|
+
.map(some)
|
|
100
|
+
.map(logicalNot)
|
|
101
101
|
.result;
|
|
102
102
|
export const every = fn(map(logicalNot))
|
|
103
|
-
.
|
|
104
|
-
.
|
|
103
|
+
.map(some)
|
|
104
|
+
.map(logicalNot)
|
|
105
105
|
.result;
|
|
106
106
|
export const includes = value => compose(map(strictEqual(value)))(some);
|
|
107
107
|
export const countdown = count => () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { htmlToString } from "../html/module.f.js";
|
|
2
|
+
import { writeFile } from "../types/effect/node/module.f.js";
|
|
3
|
+
import { utf8 } from "../text/module.f.js";
|
|
4
|
+
const html = ['body',
|
|
5
|
+
['a', { href: 'https://github.com/functionalscript/functionalscript' }, 'GitHub Repository']
|
|
6
|
+
];
|
|
7
|
+
const program = writeFile('index.html', utf8(htmlToString(html)))
|
|
8
|
+
.map(() => 0);
|
|
9
|
+
export default () => program;
|