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,149 @@
1
+ import { descentParser } from "../../bnf/data/module.f.js";
2
+ import { eof, join0Plus, max, none, not, notSet, oneEncode, option, range, remove, repeat, repeat0Plus, repeat1Plus, set, unicodeRange } from "../../bnf/module.f.js";
3
+ import { todo } from "../../dev/module.f.js";
4
+ export const parse = (input) => {
5
+ const m = descentParser(jsGrammar());
6
+ return todo();
7
+ };
8
+ export const jsGrammar = () => {
9
+ const onenine = range('19');
10
+ const digit = range('09');
11
+ const string = [
12
+ '"',
13
+ repeat0Plus({
14
+ ...remove(range(` ${max}`), set('"\\')),
15
+ escape: [
16
+ '\\',
17
+ {
18
+ ...set('"\\/bfnrt'),
19
+ u: [
20
+ 'u',
21
+ ...repeat(4)({
22
+ digit,
23
+ AF: range('AF'),
24
+ af: range('af'),
25
+ })
26
+ ],
27
+ }
28
+ ],
29
+ }),
30
+ '"'
31
+ ];
32
+ const digits0 = repeat0Plus(digit);
33
+ const digits = [digit, digits0];
34
+ const number = [
35
+ {
36
+ 0: '0',
37
+ onenine: [onenine, digits0],
38
+ },
39
+ option({
40
+ bigint: 'n',
41
+ frac: [
42
+ option(['.', digits]),
43
+ option([set('Ee'), option(set('+-')), digits])
44
+ ]
45
+ })
46
+ ];
47
+ const ws = set(' \t');
48
+ const newLine = set('\n\r');
49
+ const idStart = {
50
+ smallLetter: range('az'),
51
+ bigLetter: range('AZ'),
52
+ lowLine: '_',
53
+ dollarSign: '$'
54
+ };
55
+ const idChar = {
56
+ ...idStart,
57
+ digit
58
+ };
59
+ const id = [idStart, repeat0Plus(idChar)];
60
+ const operator = {
61
+ '.': '.',
62
+ '=>': '=>',
63
+ '===': '===',
64
+ '==': '==',
65
+ '=': '=',
66
+ '!==': '!==',
67
+ '!=': '!=',
68
+ '!': '!',
69
+ '>>>=': '>>>=',
70
+ '>>>': '>>>',
71
+ '>>=': '>>=',
72
+ '>>': '>>',
73
+ '>=': '>=',
74
+ '>': '>',
75
+ '<<<<=': '<<<=',
76
+ '<<<': '<<<',
77
+ '<<=': '<<=',
78
+ '<<': '<<',
79
+ '<=': '<=',
80
+ '<': '<',
81
+ '+=': '+=',
82
+ '++': '++',
83
+ '+': '+',
84
+ '-=': '-=',
85
+ '--': '--',
86
+ '-': '-',
87
+ '**=': '**=',
88
+ '**': '**',
89
+ '*=': '*=',
90
+ '*': '*',
91
+ '/=': '/=',
92
+ '/': '/',
93
+ '%=': '%=',
94
+ '%': '%',
95
+ '&&=': '&&=',
96
+ '&&': '&&',
97
+ '&=': '&=',
98
+ '&': '&',
99
+ '||=': '||=',
100
+ '||': '||',
101
+ '|=': '|=',
102
+ '|': '|',
103
+ '^=': '^=',
104
+ '^': '^',
105
+ '~': '~',
106
+ '??=': '??=',
107
+ '??': '??',
108
+ '?.': '?.',
109
+ '?': '?',
110
+ '[': '[',
111
+ ']': ']',
112
+ '{': '{',
113
+ '}': '}',
114
+ '(': '(',
115
+ ')': ')',
116
+ ',': ',',
117
+ ':': ':'
118
+ };
119
+ const commentEnd = {
120
+ ...newLine,
121
+ eof
122
+ };
123
+ const comment = ['/', {
124
+ // TODO: investigate why `not(commentEnd)` instead of `remove(unicodeRange, newLine)` fail tests.
125
+ // TODO: should it be `repeat0Plus(not(commentEnd))` instead of `option(remove(unicodeRange, newLine))`.
126
+ oneline: ['/', option(remove(unicodeRange, newLine)), commentEnd],
127
+ multiline: [
128
+ '*',
129
+ repeat0Plus({
130
+ na: notSet('*'),
131
+ a: ['*', notSet('/')]
132
+ }),
133
+ '*/'
134
+ ]
135
+ }
136
+ ];
137
+ const token = {
138
+ number,
139
+ string,
140
+ id,
141
+ comment,
142
+ operator,
143
+ ws,
144
+ newLine,
145
+ eof
146
+ };
147
+ const tokens = repeat0Plus(token);
148
+ return tokens;
149
+ };
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ isValid: (() => void)[];
3
+ parser: (() => void)[];
4
+ };
5
+ export default _default;
@@ -0,0 +1,202 @@
1
+ import { descentParser } from "../../bnf/data/module.f.js";
2
+ import { stringToCodePointList } from "../../text/utf16/module.f.js";
3
+ import { map, toArray } from "../../types/list/module.f.js";
4
+ import { jsGrammar } from "./module.f.js";
5
+ const mapCodePoint = (cp) => [cp, undefined];
6
+ const descentParserCpOnly = (m, name, cp) => {
7
+ const cpm = toArray(map(mapCodePoint)(cp));
8
+ return m(name, cpm);
9
+ };
10
+ export default {
11
+ isValid: [() => {
12
+ const m = descentParser(jsGrammar());
13
+ const expect = (s, expected) => {
14
+ const cp = toArray(stringToCodePointList(s));
15
+ const mr = descentParserCpOnly(m, '', cp);
16
+ const success = mr[1] && mr[2] === cp.length;
17
+ if (success !== expected) {
18
+ throw JSON.stringify([s, mr]);
19
+ }
20
+ };
21
+ expect('"', false);
22
+ expect(' true ', true);
23
+ expect(' tr2ue ', true);
24
+ expect(' 2true ', true);
25
+ expect(' true" ', false);
26
+ expect(' "Hello" ', true);
27
+ expect(' "Hello ', false);
28
+ expect(' "Hello\\n\\r\\"" ', true);
29
+ expect(' 56.7e+5 ', true);
30
+ expect(' -56.7e+5 ', true);
31
+ expect(' h-56.7e+5 ', true);
32
+ expect(' -56.7e+5 3', true);
33
+ expect(' [] ', true);
34
+ expect(' {} ', true);
35
+ expect(' [[[]]] ', true);
36
+ expect(' [1] ', true);
37
+ expect(' [ 12, false, "a"] ', true);
38
+ expect(' [ 12, false2, "a"] ', true);
39
+ expect(' { "q": [ 12, false, [{"b" : "c"}], "a"] } ', true);
40
+ expect(' { "q": [ 12, false, [{}], "a"] } ', true);
41
+ expect(' { "q": [ 12, false, [}], "a"] } ', true);
42
+ expect(' [{ "q": [ 12, false, [{}], "a"] }] ', true);
43
+ expect(' [{ "q": [ 12, false, [}], "a"] }] ', true);
44
+ expect('. + ++ +=', true);
45
+ expect('//12\n', true);
46
+ expect('/*12*/', true);
47
+ expect('/* 1*2 */', true);
48
+ }
49
+ ],
50
+ parser: [
51
+ () => {
52
+ const m = descentParser(jsGrammar());
53
+ const cp = toArray(stringToCodePointList('tr'));
54
+ const mr = descentParserCpOnly(m, '', cp);
55
+ const seq = mr[0].sequence[0];
56
+ if (seq instanceof Array)
57
+ throw JSON.stringify(mr);
58
+ if (seq.tag !== 'id')
59
+ throw JSON.stringify(mr);
60
+ },
61
+ () => {
62
+ const m = descentParser(jsGrammar());
63
+ const cp = toArray(stringToCodePointList('"tr"'));
64
+ const mr = descentParserCpOnly(m, '', cp);
65
+ const seq = mr[0].sequence[0];
66
+ if (seq instanceof Array)
67
+ throw JSON.stringify(mr);
68
+ if (seq.tag !== 'string')
69
+ throw JSON.stringify(mr);
70
+ },
71
+ () => {
72
+ const m = descentParser(jsGrammar());
73
+ const cp = toArray(stringToCodePointList('56.7e+5'));
74
+ const mr = descentParserCpOnly(m, '', cp);
75
+ const seq = mr[0].sequence[0];
76
+ if (seq instanceof Array)
77
+ throw JSON.stringify(mr);
78
+ if (seq.tag !== 'number')
79
+ throw JSON.stringify(mr);
80
+ },
81
+ () => {
82
+ const m = descentParser(jsGrammar());
83
+ const cp = toArray(stringToCodePointList('56n'));
84
+ const mr = descentParserCpOnly(m, '', cp);
85
+ const seq = mr[0].sequence[0];
86
+ if (seq instanceof Array)
87
+ throw JSON.stringify(mr);
88
+ if (seq.tag !== 'number')
89
+ throw JSON.stringify(mr);
90
+ },
91
+ () => {
92
+ const m = descentParser(jsGrammar());
93
+ const cp = toArray(stringToCodePointList('*'));
94
+ const mr = descentParserCpOnly(m, '', cp);
95
+ const seq = mr[0].sequence[0];
96
+ if (seq instanceof Array)
97
+ throw JSON.stringify(mr);
98
+ if (seq.tag !== '*')
99
+ throw JSON.stringify(mr);
100
+ },
101
+ () => {
102
+ const m = descentParser(jsGrammar());
103
+ const cp = toArray(stringToCodePointList('**'));
104
+ const mr = descentParserCpOnly(m, '', cp);
105
+ const seq = mr[0].sequence[0];
106
+ if (seq instanceof Array)
107
+ throw JSON.stringify(mr);
108
+ if (seq.tag !== '**')
109
+ throw JSON.stringify(mr);
110
+ },
111
+ () => {
112
+ const m = descentParser(jsGrammar());
113
+ const cp = toArray(stringToCodePointList('=>'));
114
+ const mr = descentParserCpOnly(m, '', cp);
115
+ const seq = mr[0].sequence[0];
116
+ if (seq instanceof Array)
117
+ throw JSON.stringify(mr);
118
+ if (seq.tag !== '=>')
119
+ throw JSON.stringify(mr);
120
+ },
121
+ () => {
122
+ const m = descentParser(jsGrammar());
123
+ const cp = toArray(stringToCodePointList('=='));
124
+ const mr = descentParserCpOnly(m, '', cp);
125
+ const seq = mr[0].sequence[0];
126
+ if (seq instanceof Array)
127
+ throw JSON.stringify(mr);
128
+ if (seq.tag !== '==')
129
+ throw JSON.stringify(mr);
130
+ },
131
+ () => {
132
+ const m = descentParser(jsGrammar());
133
+ const cp = toArray(stringToCodePointList('==='));
134
+ const mr = descentParserCpOnly(m, '', cp);
135
+ const seq = mr[0].sequence[0];
136
+ if (seq instanceof Array)
137
+ throw JSON.stringify(mr);
138
+ if (seq.tag !== '===')
139
+ throw JSON.stringify(mr);
140
+ },
141
+ () => {
142
+ const m = descentParser(jsGrammar());
143
+ const cp = toArray(stringToCodePointList('='));
144
+ const mr = descentParserCpOnly(m, '', cp);
145
+ const seq = mr[0].sequence[0];
146
+ if (seq instanceof Array)
147
+ throw JSON.stringify(mr);
148
+ if (seq.tag !== '=')
149
+ throw JSON.stringify(mr);
150
+ },
151
+ () => {
152
+ const m = descentParser(jsGrammar());
153
+ const cp = toArray(stringToCodePointList(' '));
154
+ const mr = descentParserCpOnly(m, '', cp);
155
+ const seq = mr[0].sequence[0];
156
+ if (seq instanceof Array)
157
+ throw JSON.stringify(mr);
158
+ if (seq.tag !== ' ')
159
+ throw JSON.stringify(mr);
160
+ },
161
+ () => {
162
+ const m = descentParser(jsGrammar());
163
+ const cp = toArray(stringToCodePointList('\n'));
164
+ const mr = descentParserCpOnly(m, '', cp);
165
+ const seq = mr[0].sequence[0];
166
+ if (seq instanceof Array)
167
+ throw JSON.stringify(mr);
168
+ if (seq.tag !== '\n')
169
+ throw JSON.stringify(mr);
170
+ },
171
+ () => {
172
+ const m = descentParser(jsGrammar());
173
+ const cp = toArray(stringToCodePointList('/\n'));
174
+ const mr = descentParserCpOnly(m, '', cp);
175
+ const seq = mr[0].sequence[0];
176
+ if (seq instanceof Array)
177
+ throw JSON.stringify(mr);
178
+ if (seq.tag !== '/')
179
+ throw JSON.stringify(mr);
180
+ },
181
+ () => {
182
+ const m = descentParser(jsGrammar());
183
+ const cp = toArray(stringToCodePointList('//\n'));
184
+ const mr = descentParserCpOnly(m, '', cp);
185
+ const seq = mr[0].sequence[0];
186
+ if (seq instanceof Array)
187
+ throw JSON.stringify(mr);
188
+ if (seq.tag !== 'comment')
189
+ throw JSON.stringify(mr);
190
+ },
191
+ () => {
192
+ const m = descentParser(jsGrammar());
193
+ const cp = toArray(stringToCodePointList('/*1*/'));
194
+ const mr = descentParserCpOnly(m, '', cp);
195
+ const seq = mr[0].sequence[0];
196
+ if (seq instanceof Array)
197
+ throw JSON.stringify(mr);
198
+ if (seq.tag !== 'comment')
199
+ throw JSON.stringify(mr);
200
+ }
201
+ ]
202
+ };
@@ -53,9 +53,9 @@ export const serializeWithoutConst = sort => {
53
53
  ]);
54
54
  const mapPropertySerialize = map(propertySerialize);
55
55
  const objectSerialize = fn(entries)
56
- .then(sort)
57
- .then(mapPropertySerialize)
58
- .then(objectWrap)
56
+ .map(sort)
57
+ .map(mapPropertySerialize)
58
+ .map(objectWrap)
59
59
  .result;
60
60
  const f = value => {
61
61
  switch (typeof value) {
@@ -96,9 +96,9 @@ const serializeWithConst = sort => refs => root => {
96
96
  ]);
97
97
  const mapPropertySerialize = map(propertySerialize);
98
98
  const objectSerialize = fn(entries)
99
- .then(sort)
100
- .then(mapPropertySerialize)
101
- .then(objectWrap)
99
+ .map(sort)
100
+ .map(mapPropertySerialize)
101
+ .map(objectWrap)
102
102
  .result;
103
103
  const f = value => {
104
104
  if (value !== root) {
package/fjs/module.f.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { Io } from '../io/module.f.ts';
1
+ import { type Io } from '../io/module.f.ts';
2
2
  export declare const main: (io: Io) => Promise<number>;
package/fjs/module.f.js CHANGED
@@ -1,5 +1,7 @@
1
+ import { fromIo } from "../io/module.f.js";
1
2
  import { compile } from "../djs/module.f.js";
2
3
  import { main as testMain } from "../dev/tf/module.f.js";
4
+ import { main as casMain } from "../cas/module.f.js";
3
5
  export const main = (io) => {
4
6
  const { error } = io.console;
5
7
  const [command, ...rest] = io.process.argv.slice(2);
@@ -12,8 +14,7 @@ export const main = (io) => {
12
14
  return compile(io)(rest);
13
15
  case 'cas':
14
16
  case 's':
15
- error('cas command is not implemented yet');
16
- return Promise.resolve(1);
17
+ return fromIo(io)(casMain(rest));
17
18
  case undefined:
18
19
  error('Error: command is required');
19
20
  return Promise.resolve(1);
package/fsc/module.f.js CHANGED
@@ -26,7 +26,7 @@ const reduce = (a) => {
26
26
  return toArray(listReduce(merge)(empty)(a));
27
27
  };
28
28
  const codePointRange = fromRange(def);
29
- const range = fn(asciiRange).then(codePointRange).result;
29
+ const range = fn(asciiRange).map(codePointRange).result;
30
30
  const rangeSet = (l) => (f) => {
31
31
  const codePointRange = fromRange(def);
32
32
  const g = r => codePointRange(asciiRange(r))(f);
package/io/module.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import { type Io, type Run } from './module.f.ts';
2
+ import type { NodeProgram } from '../types/effect/node/module.f.ts';
2
3
  export declare const io: Io;
3
4
  declare const runDefault: Run;
4
5
  export default runDefault;
6
+ export type NodeRun = (p: NodeProgram) => Promise<number>;
7
+ export declare const ioRun: (io: Io) => NodeRun;
8
+ export declare const nodeRun: NodeRun;
package/io/module.f.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- import type { Result } from '../types/result/module.f.ts';
1
+ import type { NodeEffect } from '../types/effect/node/module.f.ts';
2
+ import { type Result } from '../types/result/module.f.ts';
2
3
  /**
3
4
  * Represents a directory entry (file or directory) in the filesystem
4
5
  * @see https://nodejs.org/api/fs.html#class-fsdirent
5
6
  */
6
7
  export type Dirent = {
7
8
  readonly name: string;
9
+ readonly parentPath: string;
8
10
  readonly isDirectory: () => boolean;
9
11
  readonly isFile: () => boolean;
10
12
  };
@@ -15,6 +17,11 @@ export type RmOptions = {
15
17
  export type MakeDirectoryOptions = {
16
18
  readonly recursive?: boolean;
17
19
  };
20
+ export type ReadDir = ((path: string, options: {
21
+ withFileTypes: true;
22
+ }) => Promise<Dirent[]>) & ((path: string, options: {
23
+ recursive?: true;
24
+ }) => Promise<readonly string[]>);
18
25
  /**
19
26
  * File system operations interface
20
27
  * @see https://nodejs.org/api/fs.html
@@ -27,9 +34,7 @@ export type Fs = {
27
34
  readonly promises: {
28
35
  readonly readFile: (path: string) => Promise<Uint8Array>;
29
36
  readonly writeFile: (path: string, data: Uint8Array) => Promise<void>;
30
- readonly readdir: (path: string, options: {
31
- withFileTypes: true;
32
- }) => Promise<Dirent[]>;
37
+ readonly readdir: ReadDir;
33
38
  readonly rm: (path: string, options?: RmOptions) => Promise<void>;
34
39
  readonly mkdir: (path: string, options?: MakeDirectoryOptions) => Promise<string | undefined>;
35
40
  readonly copyFile: (src: string, dest: string) => Promise<void>;
@@ -99,3 +104,4 @@ export type Run = (f: App) => Promise<never>;
99
104
  * Handles errors by exiting with code 1
100
105
  */
101
106
  export declare const run: (io: Io) => Run;
107
+ export declare const fromIo: ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile } }, fetch, }: Io) => <T>(effect: NodeEffect<T>) => Promise<T>;
package/io/module.f.js CHANGED
@@ -1,3 +1,7 @@
1
+ import { normalize } from "../path/module.f.js";
2
+ import { asyncRun } from "../types/effect/module.js";
3
+ import { error, ok } from "../types/result/module.f.js";
4
+ import { fromVec, toVec } from "../types/uint8array/module.f.js";
1
5
  /**
2
6
  * Runs a function and exits the process with the returned code
3
7
  * Handles errors by exiting with code 1
@@ -14,3 +18,27 @@ export const run = (io) => {
14
18
  };
15
19
  return async (f) => io.process.exit(code(await io.asyncTryCatch(() => f(io))));
16
20
  };
21
+ const tc = async (f) => {
22
+ try {
23
+ return ok(await f());
24
+ }
25
+ catch (e) {
26
+ return error(e);
27
+ }
28
+ };
29
+ export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile } }, fetch, }) => asyncRun({
30
+ error: async (message) => error(message),
31
+ log: async (message) => log(message),
32
+ fetch: async (url) => tc(async () => {
33
+ const response = await fetch(url);
34
+ if (!response.ok) {
35
+ throw new Error(`Fetch error: ${response.status} ${response.statusText}`);
36
+ }
37
+ return toVec(new Uint8Array(await response.arrayBuffer()));
38
+ }),
39
+ mkdir: param => tc(async () => { await mkdir(...param); }),
40
+ readFile: path => tc(async () => toVec(await readFile(path))),
41
+ readdir: ([path, r]) => tc(async () => (await readdir(path, { ...r, withFileTypes: true }))
42
+ .map(v => ({ name: v.name, parentPath: normalize(v.parentPath), isFile: v.isFile() }))),
43
+ writeFile: ([path, data]) => tc(() => writeFile(path, fromVec(data))),
44
+ });
package/io/module.js CHANGED
@@ -6,7 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
- import { run } from "./module.f.js";
9
+ import { fromIo, run } from "./module.f.js";
10
10
  import fs from 'node:fs';
11
11
  import process from "node:process";
12
12
  import { concat } from "../path/module.f.js";
@@ -41,3 +41,9 @@ export const io = {
41
41
  };
42
42
  const runDefault = run(io);
43
43
  export default runDefault;
44
+ export const ioRun = (io) => {
45
+ const r = fromIo(io);
46
+ const { argv } = io.process;
47
+ return p => r(p(argv));
48
+ };
49
+ export const nodeRun = ioRun(io);
package/json/module.f.js CHANGED
@@ -25,9 +25,9 @@ export const serialize = sort => {
25
25
  ]);
26
26
  const mapPropertySerialize = map(propertySerialize);
27
27
  const objectSerialize = fn(entries)
28
- .then(sort)
29
- .then(mapPropertySerialize)
30
- .then(objectWrap)
28
+ .map(sort)
29
+ .map(mapPropertySerialize)
30
+ .map(objectWrap)
31
31
  .result;
32
32
  const f = value => {
33
33
  switch (typeof value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "**/*.js",
@@ -15,7 +15,8 @@
15
15
  "fst": "node ./fjs/module.ts t",
16
16
  "fjs": "node ./fjs/module.ts",
17
17
  "ci-update": "node ./ci/module.ts",
18
- "update": "git clean -fdx && npm install && npm run index && npm run ci-update"
18
+ "update": "git clean -fdx && npm install && npm run index && npm run ci-update",
19
+ "website": "node --experimental-strip-types ./website/module.ts"
19
20
  },
20
21
  "engines": {
21
22
  "node": ">=20"
@@ -1,3 +1,4 @@
1
1
  import type { Reduce, Unary } from "../types/function/operator/module.f.ts";
2
+ export declare const parse: (path: string) => readonly string[];
2
3
  export declare const normalize: Unary<string, string>;
3
4
  export declare const concat: Reduce<string>;
package/path/module.f.js CHANGED
@@ -1,4 +1,4 @@
1
- import { fold, last, take, length, concat as listConcat } from "../types/list/module.f.js";
1
+ import { fold, last, take, length, concat as listConcat, toArray } from "../types/list/module.f.js";
2
2
  import { join } from "../types/string/module.f.js";
3
3
  import { concat as stringConcat } from "../types/string/module.f.js";
4
4
  const foldNormalizeOp = input => state => {
@@ -21,9 +21,12 @@ const foldNormalizeOp = input => state => {
21
21
  }
22
22
  }
23
23
  };
24
- export const normalize = path => {
24
+ export const parse = (path) => {
25
25
  const split = path.replaceAll('\\', '/').split('/');
26
- const foldResult = fold(foldNormalizeOp)([])(split);
26
+ return toArray(fold(foldNormalizeOp)([])(split));
27
+ };
28
+ export const normalize = path => {
29
+ const foldResult = parse(path);
27
30
  return join('/')(foldResult);
28
31
  };
29
32
  export const concat = a => b => {
@@ -332,7 +332,7 @@ export const stringToCodePointList = (input) => toCodePointList(stringToList(inp
332
332
  * ```
333
333
  */
334
334
  export const listToString = fn(map(String.fromCharCode))
335
- .then(reduce(concat)(''))
335
+ .map(reduce(concat)(''))
336
336
  .result;
337
337
  /**
338
338
  * Converts a list of Unicode code points (CodePoint) to a string.
@@ -9,7 +9,7 @@ export type U8 = number;
9
9
  */
10
10
  export type I32 = number;
11
11
  /**
12
- * Represents an unsigend 8-bit type - U8 or the end-of-file indicator.
12
+ * Represents an unsigned 8-bit type - U8 or the end-of-file indicator.
13
13
  * The U8 represents the byte itself, and null indicates that reading does not return anything else.
14
14
  */
15
15
  export type ByteOrEof = U8 | null;
@@ -0,0 +1,62 @@
1
+ import { type Vec } from "../bit_vec/module.f.ts";
2
+ /** ASN.1 tag number. */
3
+ type Tag = bigint;
4
+ /** ASN.1 universal BOOLEAN tag. */
5
+ export declare const boolean = 1n;
6
+ /** ASN.1 universal INTEGER tag. */
7
+ export declare const integer = 2n;
8
+ /** ASN.1 universal OCTET STRING tag. */
9
+ export declare const octetString = 4n;
10
+ /** ASN.1 universal OBJECT IDENTIFIER tag. */
11
+ export declare const objectIdentifier = 6n;
12
+ export declare const constructedSequence = 48n;
13
+ export declare const constructedSet = 49n;
14
+ /** Raw ASN.1 TLV tuple. */
15
+ export type Raw = readonly [Tag, Vec];
16
+ /** Encodes a raw ASN.1 TLV tuple into a bit vector. */
17
+ export declare const encodeRaw: ([tag, value]: Raw) => Vec;
18
+ /** Decodes a raw ASN.1 TLV tuple and returns the remaining input. */
19
+ export declare const decodeRaw: (v: Vec) => readonly [Raw, Vec];
20
+ /** Encodes a JavaScript boolean as an ASN.1 BOOLEAN value. */
21
+ export declare const encodeBoolean: (b: boolean) => Vec;
22
+ /** Decodes an ASN.1 BOOLEAN value. */
23
+ export declare const decodeBoolean: (v: Vec) => boolean;
24
+ /** Encodes a signed bigint using ASN.1 INTEGER two's complement representation. */
25
+ export declare const encodeInteger: (uint: bigint) => Vec;
26
+ /** Decodes an ASN.1 INTEGER encoded in two's complement. */
27
+ export declare const decodeInteger: (v: Vec) => bigint;
28
+ /** Encodes an OCTET STRING value. */
29
+ export declare const encodeOctetString: (v: Vec) => Vec;
30
+ /** Decodes an OCTET STRING value. */
31
+ export declare const decodeOctetString: (v: Vec) => Vec;
32
+ /** ASN.1 OBJECT IDENTIFIER components. */
33
+ export type ObjectIdentifier = readonly bigint[];
34
+ /** Encodes an OBJECT IDENTIFIER value. */
35
+ export declare const encodeObjectIdentifier: (oid: ObjectIdentifier) => Vec;
36
+ /** Decodes an OBJECT IDENTIFIER value. */
37
+ export declare const decodeObjectIdentifier: (v: Vec) => ObjectIdentifier;
38
+ /** ASN.1 ordered collection of records. */
39
+ export type Sequence = readonly Record[];
40
+ /** Encodes a SEQUENCE payload from ordered records. */
41
+ export declare const encodeSequence: (...records: Sequence) => Vec;
42
+ /** Decodes a SEQUENCE payload into records. */
43
+ export declare const decodeSequence: (v: Vec) => Sequence;
44
+ /** ASN.1 SET represented as a sequence of records. */
45
+ export type Set = Sequence;
46
+ /** Encodes a SET payload with canonical byte ordering. */
47
+ export declare const encodeSet: (...records: Sequence) => Vec;
48
+ /** Decodes a SET payload. */
49
+ export declare const decodeSet: (v: Vec) => Sequence;
50
+ /** Supported ASN.1 record variants. */
51
+ export type SupportedRecord = readonly [typeof boolean, boolean] | readonly [typeof integer, bigint] | readonly [typeof octetString, Vec] | readonly [typeof objectIdentifier, ObjectIdentifier] | readonly [typeof constructedSequence, Sequence] | readonly [typeof constructedSet, Set];
52
+ /**
53
+ * For unsupported tags, we just store the raw value including the tag and length,
54
+ * so that it can be re-encoded without loss of information.
55
+ */
56
+ export type UnsupportedRecord = Vec;
57
+ export type Record = SupportedRecord | UnsupportedRecord;
58
+ /** Encodes a supported ASN.1 record as TLV. */
59
+ export declare const encode: (record: Record) => Vec;
60
+ /** Decodes one supported ASN.1 record and returns the remaining input. */
61
+ export declare const decode: (v: Vec) => readonly [Record, Vec];
62
+ export {};