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.
Files changed (70) hide show
  1. package/README.md +3 -3
  2. package/bnf/data/test.f.d.ts +2 -0
  3. package/bnf/data/test.f.js +39 -2
  4. package/bnf/module.f.d.ts +6 -2
  5. package/bnf/module.f.js +10 -11
  6. package/cas/module.f.d.ts +14 -13
  7. package/cas/module.f.js +78 -60
  8. package/ci/module.f.d.ts +3 -2
  9. package/ci/module.f.js +6 -8
  10. package/ci/module.js +3 -3
  11. package/crypto/hmac/test.f.js +1 -1
  12. package/crypto/sign/test.f.js +1 -1
  13. package/dev/module.f.d.ts +1 -1
  14. package/dev/module.f.js +13 -6
  15. package/dev/tf/all.test.js +2 -2
  16. package/dev/tf/module.f.js +2 -2
  17. package/dev/version/module.f.d.ts +2 -11
  18. package/dev/version/module.f.js +17 -15
  19. package/dev/version/test.f.d.ts +3 -1
  20. package/dev/version/test.f.js +26 -11
  21. package/djs/parser-new/module.f.d.ts +3 -0
  22. package/djs/parser-new/module.f.js +149 -0
  23. package/djs/parser-new/test.f.d.ts +5 -0
  24. package/djs/parser-new/test.f.js +202 -0
  25. package/djs/serializer/module.f.js +6 -6
  26. package/fjs/module.f.d.ts +1 -1
  27. package/fjs/module.f.js +3 -2
  28. package/fsc/module.f.js +1 -1
  29. package/io/module.d.ts +4 -0
  30. package/io/module.f.d.ts +10 -4
  31. package/io/module.f.js +28 -0
  32. package/io/module.js +7 -1
  33. package/json/module.f.js +3 -3
  34. package/package.json +3 -2
  35. package/path/module.f.d.ts +1 -0
  36. package/path/module.f.js +6 -3
  37. package/text/utf16/module.f.js +1 -1
  38. package/text/utf8/module.f.d.ts +1 -1
  39. package/types/asn.1/module.f.d.ts +62 -0
  40. package/types/asn.1/module.f.js +276 -0
  41. package/types/asn.1/test.f.d.ts +44 -0
  42. package/types/asn.1/test.f.js +312 -0
  43. package/types/base128/module.f.d.ts +15 -0
  44. package/types/base128/module.f.js +38 -0
  45. package/types/base128/test.f.d.ts +2 -0
  46. package/types/base128/test.f.js +26 -0
  47. package/types/bit_vec/module.f.d.ts +15 -3
  48. package/types/bit_vec/module.f.js +22 -2
  49. package/types/bit_vec/test.f.d.ts +1 -0
  50. package/types/bit_vec/test.f.js +28 -6
  51. package/types/effect/mock/module.f.d.ts +5 -0
  52. package/types/effect/mock/module.f.js +14 -0
  53. package/types/effect/module.d.ts +2 -0
  54. package/types/effect/module.f.d.ts +23 -0
  55. package/types/effect/module.f.js +14 -0
  56. package/types/effect/module.js +11 -0
  57. package/types/effect/node/module.f.d.ts +56 -0
  58. package/types/effect/node/module.f.js +8 -0
  59. package/types/effect/node/test.f.d.ts +28 -0
  60. package/types/effect/node/test.f.js +277 -0
  61. package/types/effect/node/virtual/module.f.d.ts +16 -0
  62. package/types/effect/node/virtual/module.f.js +103 -0
  63. package/types/function/module.f.d.ts +1 -1
  64. package/types/function/module.f.js +1 -1
  65. package/types/function/test.f.js +1 -1
  66. package/types/list/module.f.js +4 -4
  67. package/website/module.d.ts +1 -0
  68. package/website/module.f.d.ts +3 -0
  69. package/website/module.f.js +9 -0
  70. 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 then: <T>(g: Func<O, T>) => Fn<I, T>;
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.
@@ -15,5 +15,5 @@ export const flip = f => b => a => f(a)(b);
15
15
  */
16
16
  export const fn = (result) => ({
17
17
  result,
18
- then: g => fn(compose(result)(g))
18
+ map: g => fn(compose(result)(g))
19
19
  });
@@ -3,7 +3,7 @@ export default () => {
3
3
  const f = x => [x];
4
4
  const g = ([x]) => [x.length];
5
5
  const w = ([x]) => x;
6
- const r = fn(f).then(g).then(w).result;
6
+ const r = fn(f).map(g).map(w).result;
7
7
  const result = r('hello');
8
8
  if (result !== 5) {
9
9
  throw r;
@@ -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
- .then(some)
100
- .then(logicalNot)
99
+ .map(some)
100
+ .map(logicalNot)
101
101
  .result;
102
102
  export const every = fn(map(logicalNot))
103
- .then(some)
104
- .then(logicalNot)
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,3 @@
1
+ import { type NodeEffect } from '../types/effect/node/module.f.ts';
2
+ declare const _default: () => NodeEffect<number>;
3
+ export default _default;
@@ -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;
@@ -0,0 +1,3 @@
1
+ import { nodeRun } from "../io/module.js";
2
+ import run from "./module.f.js";
3
+ await nodeRun(run);