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
package/README.md CHANGED
@@ -26,7 +26,7 @@ This repository is a [monorepo](https://en.wikipedia.org/wiki/Monorepo) and dist
26
26
  Install FunctionalScript via npm:
27
27
 
28
28
  ```bash
29
- npm install functionalscript
29
+ npm install -g functionalscript
30
30
  ```
31
31
 
32
32
  The FunctionalScript compiler command (`fjs compile`) currently supports:
@@ -39,9 +39,9 @@ It does **not** yet support functions or complex expressions.
39
39
  Example usage with `fjs`:
40
40
 
41
41
  ```bash
42
- npx fjs compile example.f.js output.json
42
+ fjs compile example.f.js output.json
43
43
  # or
44
- npx fjs compile example.f.js output.f.js
44
+ fjs compile example.f.js output.f.js
45
45
  ```
46
46
 
47
47
  FunctionalScript code can be compiled directly into either JSON or JavaScript without imports.
@@ -1,4 +1,6 @@
1
1
  declare const _default: {
2
+ rangeDecode: () => void;
3
+ rangeEncode: () => void;
2
4
  toData: (() => void)[];
3
5
  emptyTags: (() => void)[];
4
6
  variantTest: () => void;
@@ -3,7 +3,7 @@ import { stringToCodePointList } from "../../text/utf16/module.f.js";
3
3
  import { identity } from "../../types/function/module.f.js";
4
4
  import { map, toArray } from "../../types/list/module.f.js";
5
5
  import { sort } from "../../types/object/module.f.js";
6
- import { join0Plus, option, range, repeat0Plus, set } from "../module.f.js";
6
+ import { join0Plus, oneEncode, option, range, rangeDecode, repeat0Plus, set } from "../module.f.js";
7
7
  import { classic, deterministic } from "../testlib.f.js";
8
8
  import { dispatchMap, parser, parserRuleSet, toData, createEmptyTagMap, descentParser } from "./module.f.js";
9
9
  const mapCodePoint = (cp) => [cp, undefined];
@@ -12,6 +12,34 @@ const descentParserCpOnly = (m, name, cp) => {
12
12
  return m(name, cpm);
13
13
  };
14
14
  export default {
15
+ rangeDecode: () => {
16
+ const decoded1 = stringify(sort)(rangeDecode(0x000079_000087));
17
+ if (decoded1 !== '[121,135]') {
18
+ throw decoded1;
19
+ }
20
+ const decoded2 = stringify(sort)(rangeDecode(0x000080_000087));
21
+ if (decoded2 !== '[128,135]') {
22
+ throw decoded2;
23
+ }
24
+ const decoded3 = stringify(sort)(rangeDecode(0x10FFFF_10FFFF));
25
+ if (decoded3 !== '[1114111,1114111]') {
26
+ throw decoded3;
27
+ }
28
+ },
29
+ rangeEncode: () => {
30
+ const encoded1 = oneEncode(0x79);
31
+ if (encoded1 !== 0x000079_000079) {
32
+ throw encoded1;
33
+ }
34
+ const encoded2 = oneEncode(0x80);
35
+ if (encoded2 !== 0x000080_000080) {
36
+ throw encoded2;
37
+ }
38
+ const encoded3 = oneEncode(0x10FFFF);
39
+ if (encoded3 !== 0x10FFFF_10FFFF) {
40
+ throw encoded3;
41
+ }
42
+ },
15
43
  toData: [
16
44
  () => {
17
45
  const c = toData(classic());
@@ -281,7 +309,16 @@ export default {
281
309
  }
282
310
  },
283
311
  () => {
284
- const terminalRangeRule = range('AF');
312
+ const terminalRangeRule = 0x000079_000087;
313
+ const m = parser(terminalRangeRule);
314
+ const mr = m("", [64]);
315
+ const result = JSON.stringify(mr);
316
+ if (result !== '[{"sequence":[]},false,[64]]') {
317
+ throw result;
318
+ }
319
+ },
320
+ () => {
321
+ const terminalRangeRule = 0x000080_000087; //broken range
285
322
  const m = parser(terminalRangeRule);
286
323
  const mr = m("", [64]);
287
324
  const result = JSON.stringify(mr);
package/bnf/module.f.d.ts CHANGED
@@ -7,6 +7,8 @@ import { type Array2 } from '../types/array/module.f.ts';
7
7
  * - 0xEEEEEE is the last symbol (24 bits)
8
8
  */
9
9
  export type TerminalRange = number;
10
+ export declare const fullRange: TerminalRange;
11
+ export declare const unicodeRange: TerminalRange;
10
12
  /** A sequence of rules. */
11
13
  export type Sequence = readonly Rule[];
12
14
  /** A variant */
@@ -19,6 +21,7 @@ export type Rule = DataRule | LazyRule;
19
21
  export declare const max: string;
20
22
  export declare const rangeEncode: (a: number, b: number) => TerminalRange;
21
23
  export declare const oneEncode: (a: number) => TerminalRange;
24
+ export declare const eof: TerminalRange;
22
25
  export declare const rangeDecode: (r: number) => Array2<number>;
23
26
  export declare const toSequence: (s: string) => readonly TerminalRange[];
24
27
  export declare const str: (s: string) => readonly TerminalRange[] | TerminalRange;
@@ -30,8 +33,9 @@ export declare const range: (ab: string) => TerminalRange;
30
33
  export type RangeVariant = {
31
34
  readonly [k in string]: TerminalRange;
32
35
  };
33
- export declare const rangeToId: (r: TerminalRange) => string;
34
- export declare const remove: (range: TerminalRange, removeSet: RangeVariant) => RangeVariant;
36
+ export declare const remove: (range: TerminalRange, v: RangeVariant) => RangeVariant;
37
+ export declare const not: (v: RangeVariant) => RangeVariant;
38
+ export declare const notSet: (s: string) => RangeVariant;
35
39
  export type None = readonly [];
36
40
  export declare const none: None;
37
41
  export type Option<S> = {
package/bnf/module.f.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { codePointListToString, stringToCodePointList } from "../text/utf16/module.f.js";
2
2
  import { isArray2 } from "../types/array/module.f.js";
3
3
  import { map, toArray, repeat as listRepeat } from "../types/list/module.f.js";
4
+ export const fullRange = 0x000000_FFFFFF;
5
+ export const unicodeRange = 0x000000_10FFFF;
4
6
  // Internals:
5
7
  const { fromEntries, values } = Object;
6
8
  const { fromCodePoint } = String;
@@ -15,10 +17,11 @@ export const rangeEncode = (a, b) => {
15
17
  if (!isValid(a) || !isValid(b) || a > b) {
16
18
  throw `Invalid range ${a} ${b}.`;
17
19
  }
18
- return (a << offset) | b;
20
+ return Number((BigInt(a) << BigInt(offset)) | BigInt(b));
19
21
  };
20
22
  export const oneEncode = (a) => rangeEncode(a, a);
21
- export const rangeDecode = (r) => [r >> offset, r & mask];
23
+ export const eof = oneEncode(0x110000);
24
+ export const rangeDecode = (r) => [Number(BigInt(r) >> BigInt(offset)), Number(BigInt(r) & BigInt(mask))];
22
25
  const mapOneEncode = map(oneEncode);
23
26
  export const toSequence = (s) => toArray(mapOneEncode(stringToCodePointList(s)));
24
27
  export const str = (s) => {
@@ -34,13 +37,7 @@ export const range = (ab) => {
34
37
  }
35
38
  return rangeEncode(...a);
36
39
  };
37
- export const rangeToId = (r) => {
38
- const ab = rangeDecode(r);
39
- const [a, b] = ab;
40
- const cp = a === b ? [a] : ab;
41
- return fromCodePoint(...cp);
42
- };
43
- const rangeToEntry = (r) => [rangeToId(r), r];
40
+ const rangeToEntry = (r) => ['0x' + r.toString(16), r];
44
41
  const toVariantRangeSet = (r) => fromEntries(r.map(rangeToEntry));
45
42
  const removeOne = (list, ab) => {
46
43
  const [a, b] = rangeDecode(ab);
@@ -60,13 +57,15 @@ const removeOne = (list, ab) => {
60
57
  }
61
58
  return result;
62
59
  };
63
- export const remove = (range, removeSet) => {
60
+ export const remove = (range, v) => {
64
61
  let result = [range];
65
- for (const r of values(removeSet)) {
62
+ for (const r of values(v)) {
66
63
  result = removeOne(result, r);
67
64
  }
68
65
  return toVariantRangeSet(result);
69
66
  };
67
+ export const not = (v) => remove(fullRange, v);
68
+ export const notSet = (s) => not(set(s));
70
69
  export const none = [];
71
70
  export const option = (some) => ({
72
71
  some,
package/cas/module.f.d.ts CHANGED
@@ -1,17 +1,18 @@
1
1
  import { type Sha2 } from "../crypto/sha2/module.f.ts";
2
- import type { Io } from "../io/module.f.ts";
3
- import { type Vec } from "../types/bit_vec/module.f.ts";
4
- export type KvStore = {
5
- readonly read: (key: Vec) => Promise<Vec | undefined>;
6
- readonly write: (key: Vec, value: Vec) => Promise<KvStore>;
7
- readonly list: () => Promise<Iterable<Vec>>;
2
+ import type { Vec } from "../types/bit_vec/module.f.ts";
3
+ import { type Effect, type Operations } from "../types/effect/module.f.ts";
4
+ import { type Fs, type NodeOperations } from "../types/effect/node/module.f.ts";
5
+ export type KvStore<O extends Operations> = {
6
+ readonly read: (key: Vec) => Effect<O, Vec | undefined>;
7
+ readonly write: (key: Vec, value: Vec) => Effect<O, void>;
8
+ readonly list: () => Effect<O, readonly Vec[]>;
8
9
  };
9
10
  export type Kv = readonly [Vec, Vec];
10
- export declare const memKvStore: () => KvStore;
11
- export declare const fileKvStore: (io: Io) => (path: string) => KvStore;
12
- export type Cas = {
13
- readonly read: (key: Vec) => Promise<Vec | undefined>;
14
- readonly write: (value: Vec) => Promise<readonly [Cas, Vec]>;
15
- readonly list: () => Promise<Iterable<Vec>>;
11
+ export declare const fileKvStore: (path: string) => KvStore<Fs>;
12
+ export type Cas<O extends Operations> = {
13
+ readonly read: (key: Vec) => Effect<O, Vec | undefined>;
14
+ readonly write: (value: Vec) => Effect<O, Vec>;
15
+ readonly list: () => Effect<O, readonly Vec[]>;
16
16
  };
17
- export declare const cas: (sha2: Sha2) => (s: KvStore) => Cas;
17
+ export declare const cas: (sha2: Sha2) => <O extends Operations>(_: KvStore<O>) => Cas<O>;
18
+ export declare const main: (args: readonly string[]) => Effect<NodeOperations, number>;
package/cas/module.f.js CHANGED
@@ -1,77 +1,95 @@
1
- import { computeSync } from "../crypto/sha2/module.f.js";
2
- import { todo } from "../dev/module.f.js";
3
- import {} from "../types/bit_vec/module.f.js";
1
+ import { computeSync, sha256 } from "../crypto/sha2/module.f.js";
2
+ import { parse } from "../path/module.f.js";
4
3
  import { cBase32ToVec, vecToCBase32 } from "../types/cbase32/module.f.js";
5
- import { compose } from "../types/function/module.f.js";
4
+ import { pure } from "../types/effect/module.f.js";
5
+ import { error, log, mkdir, readdir, readFile, writeFile } from "../types/effect/node/module.f.js";
6
6
  import { toOption } from "../types/nullable/module.f.js";
7
- import { fromVec, toVec } from "../types/uint8array/module.f.js";
8
- export const memKvStore = () => {
9
- const create = (...i) => {
10
- const store = new Map(i);
11
- return {
12
- read: async (key) => store.get(key),
13
- write: async (...kv) => create(...store, kv),
14
- list: async () => store.keys(),
15
- };
16
- };
17
- return create();
18
- };
7
+ import { unwrap } from "../types/result/module.f.js";
19
8
  const o = { withFileTypes: true };
20
9
  const split = (s) => [s.substring(0, 2), s.substring(2)];
10
+ const prefix = '.cas';
21
11
  const toPath = (key) => {
22
12
  const s = vecToCBase32(key);
23
13
  const [a, bc] = split(s);
24
14
  const [b, c] = split(bc);
25
- return `${a}/${b}/${c}`;
26
- };
27
- export const fileKvStore = (io) => (path) => {
28
- const { readdir, readFile, writeFile } = io.fs.promises;
29
- const { asyncTryCatch } = io;
30
- const result = {
31
- read: async (key) => {
32
- const p = toPath(key);
33
- const [s, v] = await asyncTryCatch(() => readFile(`${path}/${p}`));
34
- if (s === 'error') {
35
- return undefined;
36
- }
37
- return toVec(v);
38
- },
39
- write: async (key, value) => {
40
- const p = toPath(key);
41
- await writeFile(`${path}/${p}`, fromVec(value));
42
- return result;
43
- },
44
- list: async () => {
45
- const f = async (p) => {
46
- const dir = await readdir(p, o);
47
- let result = [];
48
- for (const entry of dir) {
49
- const { name } = entry;
50
- if (entry.isFile()) {
51
- result = [...result, name];
52
- continue;
53
- }
54
- // directory
55
- const sub = await f(`${p}/${name}`);
56
- result = [...result, ...sub.map(x => `${name}${x}`)];
57
- }
58
- return result;
59
- };
60
- const all = await f(path);
61
- return all.flatMap(compose(cBase32ToVec)(toOption));
62
- },
63
- };
64
- return result;
15
+ return `${prefix}/${a}/${b}/${c}`;
65
16
  };
17
+ export const fileKvStore = (path) => ({
18
+ read: (key) => readFile(toPath(key))
19
+ .map(([status, data]) => status === 'error' ? undefined : data),
20
+ write: (key, value) => {
21
+ const p = toPath(key);
22
+ const parts = parse(p);
23
+ const dir = `${path}/${parts.slice(0, -1).join('/')}`;
24
+ // TODO: error handling
25
+ return mkdir(dir, { recursive: true })
26
+ .pipe(() => writeFile(`${path}/${p}`, value))
27
+ .map(() => undefined);
28
+ },
29
+ list: () => readdir('.cas', { recursive: true })
30
+ // TODO: remove unwrap
31
+ .map(r => unwrap(r).flatMap(({ name, parentPath, isFile }) => toOption(isFile ? cBase32ToVec(parentPath.substring(prefix.length).replaceAll('/', '') + name) : null))),
32
+ });
66
33
  export const cas = (sha2) => {
67
34
  const compute = computeSync(sha2);
68
- const f = ({ read, list, write }) => ({
35
+ return ({ read, write, list }) => ({
69
36
  read,
70
- write: async (value) => {
37
+ write: (value) => {
71
38
  const hash = compute([value]);
72
- return [f(await write(hash, value)), hash];
39
+ return write(hash, value)
40
+ .map(() => hash);
73
41
  },
74
42
  list,
75
43
  });
76
- return f;
44
+ };
45
+ const e = (s) => error(s).map(() => 1);
46
+ export const main = (args) => {
47
+ const c = cas(sha256)(fileKvStore('.'));
48
+ const [cmd, ...options] = args;
49
+ switch (cmd) {
50
+ case 'add': {
51
+ if (options.length !== 1) {
52
+ return e("'cas add' expects one parameter");
53
+ }
54
+ const [path] = options;
55
+ return readFile(path)
56
+ .pipe(v => c.write(unwrap(v)))
57
+ .pipe(hash => log(vecToCBase32(hash)))
58
+ .map(() => 0);
59
+ }
60
+ case 'get': {
61
+ if (options.length !== 2) {
62
+ return e("'cas get' expects two parameters");
63
+ }
64
+ const [hashCBase32, path] = options;
65
+ const hash = cBase32ToVec(hashCBase32);
66
+ if (hash === null) {
67
+ return e(`invalid hash format: ${hashCBase32}`);
68
+ }
69
+ return c.read(hash)
70
+ .pipe(v => {
71
+ const result = v === undefined
72
+ ? e(`no such hash: ${hashCBase32}`)
73
+ : writeFile(path, v).map(() => 0);
74
+ return result;
75
+ });
76
+ }
77
+ case 'list': {
78
+ return c.list()
79
+ .pipe(v => {
80
+ // TODO: make it lazy.
81
+ let i = pure(undefined);
82
+ for (const j of v) {
83
+ i = i.pipe(() => log(vecToCBase32(j)));
84
+ }
85
+ return i;
86
+ })
87
+ .map(() => 0);
88
+ }
89
+ case undefined: {
90
+ return e('Error: CAS command requires subcommand');
91
+ }
92
+ default:
93
+ return e(`Error: Unknown CAS subcommand "${args[0]}"`);
94
+ }
77
95
  };
package/ci/module.f.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import type { Io } from '../io/module.f.ts';
2
- declare const _default: (io: Io) => Promise<number>;
1
+ import { type NodeEffect } from '../types/effect/node/module.f.ts';
2
+ export declare const effect: NodeEffect<number>;
3
+ declare const _default: () => NodeEffect<number>;
3
4
  export default _default;
package/ci/module.f.js CHANGED
@@ -1,4 +1,5 @@
1
- import { encodeUtf8 } from "../types/uint8array/module.f.js";
1
+ import { utf8 } from "../text/module.f.js";
2
+ import { writeFile } from "../types/effect/node/module.f.js";
2
3
  const os = ['ubuntu', 'macos', 'windows'];
3
4
  const architecture = ['intel', 'arm'];
4
5
  // https://docs.github.com/en/actions/reference/runners/github-hosted-runners#standard-github-hosted-runners-for-public-repositories
@@ -72,9 +73,7 @@ const toSteps = (m) => {
72
73
  return [
73
74
  ...(aptGet !== '' ? [{ run: `sudo apt-get update && sudo apt-get install -y ${aptGet}` }] : []),
74
75
  ...(rust ? [{
75
- // wasm32-wasip1-threads doesn't work on Rust 1.91 in the release mode.
76
- // See https://github.com/sergey-shandar/wasmtime-crash
77
- uses: 'dtolnay/rust-toolchain@1.92.0',
76
+ uses: 'dtolnay/rust-toolchain@1.93.1',
78
77
  with: {
79
78
  components: 'rustfmt,clippy',
80
79
  targets
@@ -165,7 +164,6 @@ const gha = {
165
164
  on: { pull_request: {} },
166
165
  jobs,
167
166
  };
168
- export default async (io) => {
169
- io.fs.writeFileSync('.github/workflows/ci.yml', encodeUtf8(JSON.stringify(gha, null, ' ')));
170
- return 0;
171
- };
167
+ export const effect = writeFile('.github/workflows/ci.yml', utf8(JSON.stringify(gha, null, ' ')))
168
+ .map(() => 0);
169
+ export default () => effect;
package/ci/module.js CHANGED
@@ -1,3 +1,3 @@
1
- import node from "../io/module.js";
2
- import x from "./module.f.js";
3
- await node(x);
1
+ import { nodeRun } from "../io/module.js";
2
+ import run from "./module.f.js";
3
+ await nodeRun(run);
@@ -1,5 +1,5 @@
1
1
  import { utf8 } from "../../text/module.f.js";
2
- import { length, uint, vec } from "../../types/bit_vec/module.f.js";
2
+ import { uint, vec } from "../../types/bit_vec/module.f.js";
3
3
  import { sha256, sha384, sha512 } from "../sha2/module.f.js";
4
4
  import { hmac } from "./module.f.js";
5
5
  export default {
@@ -1,7 +1,7 @@
1
1
  import { utf8 } from "../../text/module.f.js";
2
2
  import { empty, msb, repeat, vec, vec8 } from "../../types/bit_vec/module.f.js";
3
3
  import { hmac } from "../hmac/module.f.js";
4
- import { curve, secp192r1, secp256r1, secp384r1, secp521r1 } from "../secp/module.f.js";
4
+ import { secp192r1, secp256r1, secp384r1, secp521r1 } from "../secp/module.f.js";
5
5
  import { computeSync, sha224, sha256, sha384, sha512 } from "../sha2/module.f.js";
6
6
  import { all, concat, computeK, fromCurve, sign } from "./module.f.js";
7
7
  const sample = utf8("sample");
package/dev/module.f.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Io } from '../io/module.f.ts';
1
+ import { type Io } from '../io/module.f.ts';
2
2
  export declare const todo: () => never;
3
3
  export type Module = {
4
4
  readonly default?: unknown;
package/dev/module.f.js CHANGED
@@ -1,5 +1,9 @@
1
+ import { fromIo } from "../io/module.f.js";
1
2
  import { updateVersion } from "./version/module.f.js";
2
3
  import { decodeUtf8, encodeUtf8 } from "../types/uint8array/module.f.js";
4
+ import { readFile } from "../types/effect/node/module.f.js";
5
+ import { utf8ToString } from "../text/module.f.js";
6
+ import { unwrap } from "../types/result/module.f.js";
3
7
  export const todo = () => { throw 'not implemented'; };
4
8
  const cmp = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0;
5
9
  export const env = ({ process: { env } }) => a => {
@@ -9,7 +13,7 @@ export const env = ({ process: { env } }) => a => {
9
13
  r.value;
10
14
  };
11
15
  export const allFiles = (io) => (s) => {
12
- const { fs: { promises: { readdir } }, process: { cwd } } = io;
16
+ const { fs: { promises: { readdir } } } = io;
13
17
  const load = async (p) => {
14
18
  let result = [];
15
19
  for (const i of await readdir(p, { withFileTypes: true })) {
@@ -47,18 +51,21 @@ export const loadModuleMap = async (io) => {
47
51
  }
48
52
  return Object.fromEntries(map.toSorted(cmp));
49
53
  };
54
+ const denoJson = './deno.json';
55
+ const index2 = updateVersion
56
+ .pipe(() => readFile(denoJson))
57
+ .map(v => JSON.parse(utf8ToString(unwrap(v))));
50
58
  export const index = async (io) => {
51
- updateVersion(io);
52
- const jj = './deno.json';
53
- const jsr_json = JSON.parse(decodeUtf8(await io.fs.promises.readFile(jj)));
59
+ const runner = fromIo(io);
60
+ const jsr_json = await runner(index2);
54
61
  const list = (await allFiles(io)('.')).filter(v => v.endsWith('/module.f.ts') || v.endsWith('/module.ts'));
55
- //console.log(list)
62
+ // console.log(list)
56
63
  const exportsA = list.map(v => [v, `./${v.substring(2)}`]);
57
64
  // console.log(exportsA)
58
65
  const exports = Object.fromEntries(exportsA);
59
66
  // console.log(exports)
60
67
  const json = JSON.stringify({ ...jsr_json, exports }, null, 2);
61
68
  // console.log(json)
62
- await io.fs.promises.writeFile(jj, encodeUtf8(json));
69
+ await io.fs.promises.writeFile(denoJson, encodeUtf8(json));
63
70
  return 0;
64
71
  };
@@ -7,11 +7,11 @@ const isPlaywright = typeof process !== 'undefined' && process?.env?.PLAYWRIGHT_
7
7
  const createFramework = (fw) => (prefix, f) => fw.test(prefix, t => f((name, v) => t.test(name, v)));
8
8
  // Bun doesn't support nested tests yet.
9
9
  const createBunFramework = (fw) => (prefix, f) => f((name, v) => fw.test(`${prefix}: ${name}`, v));
10
- const createPlaywrihtFramework = async () => {
10
+ const createPlaywrightFramework = async () => {
11
11
  const pwTest = (await import('@playwright/test')).test;
12
12
  return (prefix, f) => f((name, v) => pwTest(`${prefix}: ${name}`, v));
13
13
  };
14
- const framework = isPlaywright ? await createPlaywrihtFramework() :
14
+ const framework = isPlaywright ? await createPlaywrightFramework() :
15
15
  isBun ? createBunFramework(nodeTest) :
16
16
  createFramework(nodeTest);
17
17
  const parse = parseTestSet(io.tryCatch);
@@ -1,4 +1,4 @@
1
- import { entries, fold } from "../../types/list/module.f.js";
1
+ import { fold } from "../../types/list/module.f.js";
2
2
  import { reset, fgGreen, fgRed, bold, stdio, stderr } from "../../text/sgr/module.f.js";
3
3
  import { env, loadModuleMap } from "../module.f.js";
4
4
  export const isTest = (s) => s.endsWith('test.f.js') || s.endsWith('test.f.ts');
@@ -58,7 +58,7 @@ export const test = (input) => {
58
58
  if (isGitHub) {
59
59
  // https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions
60
60
  // https://github.com/OndraM/ci-detector/blob/main/src/Ci/GitHubActions.php
61
- error(`::error file=${k},line=1,title=[3]['a']()::${r}`);
61
+ error(`::error file=${k},line=1,title=${i}()::${r}`);
62
62
  }
63
63
  else {
64
64
  error(`${i}() ${fgRed}error${reset}, ${timeFormat(delta)}`);
@@ -1,11 +1,2 @@
1
- export type Buffer = object;
2
- type Fs<T> = {
3
- readonly readFileSync: (name: string) => Uint8Array;
4
- readonly writeFileSync: (name: string, content: Uint8Array) => T;
5
- };
6
- export type Node<T> = {
7
- readonly fs: Fs<T>;
8
- };
9
- export declare const getVersion: <T>(fs: Fs<T>) => string;
10
- export declare const updateVersion: <T>(node: Node<T>) => readonly [T, T];
11
- export {};
1
+ import { type NodeEffect } from "../../types/effect/node/module.f.ts";
2
+ export declare const updateVersion: NodeEffect<number>;
@@ -1,17 +1,19 @@
1
- import { decodeUtf8, encodeUtf8 } from "../../types/uint8array/module.f.js";
1
+ import { utf8, utf8ToString } from "../../text/module.f.js";
2
+ import { all } from "../../types/effect/module.f.js";
3
+ import { readFile, writeFile } from "../../types/effect/node/module.f.js";
4
+ import { unwrap } from "../../types/result/module.f.js";
2
5
  const { stringify, parse } = JSON;
3
- export const getVersion = fs => readJson(fs)('package').version;
4
6
  const jsonFile = (jsonFile) => `${jsonFile}.json`;
5
- const readJson = fs => name => parse(decodeUtf8(fs.readFileSync(jsonFile(name))));
6
- export const updateVersion = ({ fs }) => {
7
- const f = (name) => {
8
- return fs.writeFileSync(jsonFile(name), encodeUtf8(stringify({
9
- ...readJson(fs)(name),
10
- version: getVersion(fs)
11
- }, null, 2)));
12
- };
13
- return [
14
- f('package'),
15
- f('deno')
16
- ];
17
- };
7
+ const readJson = (name) => readFile(jsonFile(name))
8
+ .map(v => parse(utf8ToString(unwrap(v))));
9
+ const writeVersion = (version) => (name) => readJson(name)
10
+ .pipe(json => writeFile(jsonFile(name), utf8(stringify({
11
+ ...json,
12
+ version,
13
+ }, null, 2))));
14
+ export const updateVersion = readJson('package')
15
+ .pipe(p => {
16
+ const w = writeVersion(p.version);
17
+ return all([w('package'), w('deno')]);
18
+ })
19
+ .map(() => 0);
@@ -1,2 +1,4 @@
1
- declare const _default: () => void;
1
+ declare const _default: {
2
+ new: () => void;
3
+ };
2
4
  export default _default;
@@ -1,5 +1,10 @@
1
- import { decodeUtf8, encodeUtf8 } from "../../types/uint8array/module.f.js";
2
- import * as _ from "./module.f.js";
1
+ import { utf8, utf8ToString } from "../../text/module.f.js";
2
+ import { isVec } from "../../types/bit_vec/module.f.js";
3
+ import { run } from "../../types/effect/mock/module.f.js";
4
+ import { all } from "../../types/effect/module.f.js";
5
+ import { writeFile } from "../../types/effect/node/module.f.js";
6
+ import { emptyState, virtual } from "../../types/effect/node/virtual/module.f.js";
7
+ import { updateVersion } from "./module.f.js";
3
8
  const version = '0.3.0';
4
9
  const x = {
5
10
  'package.json': {
@@ -74,15 +79,25 @@ const e = '{\n' +
74
79
  ' "typescript": "^4.7.4"\n' +
75
80
  ' }\n' +
76
81
  '}';
77
- export default () => {
78
- const node = {
79
- fs: {
80
- readFileSync: n => encodeUtf8(JSON.stringify(x[n])),
81
- writeFileSync: (_, content) => decodeUtf8(content)
82
+ export default {
83
+ new: () => {
84
+ const rv = run(virtual);
85
+ const w = (name) => {
86
+ const fn = `${name}.json`;
87
+ return writeFile(fn, utf8(JSON.stringify(x[fn])));
88
+ };
89
+ const [state] = rv(emptyState)(all([w('package'), w('deno')]));
90
+ const [newState, result] = rv(state)(updateVersion);
91
+ if (result !== 0) {
92
+ throw result;
93
+ }
94
+ const vec = newState.root['package.json'];
95
+ if (!isVec(vec)) {
96
+ throw vec;
97
+ }
98
+ const n = utf8ToString(vec);
99
+ if (n !== e) {
100
+ throw [n, e];
82
101
  }
83
- };
84
- const [n, d] = _.updateVersion(node);
85
- if (n !== e) {
86
- throw [n, e];
87
102
  }
88
103
  };
@@ -0,0 +1,3 @@
1
+ import { type Rule } from "../../bnf/module.f.ts";
2
+ export declare const parse: (input: string) => boolean;
3
+ export declare const jsGrammar: () => Rule;