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.
Files changed (42) hide show
  1. package/bnf/data/module.f.d.ts +67 -1
  2. package/bnf/data/module.f.js +27 -0
  3. package/bnf/module.f.js +8 -0
  4. package/cas/module.f.d.ts +27 -6
  5. package/cas/module.f.js +38 -32
  6. package/ci/module.f.d.ts +4 -3
  7. package/ci/module.f.js +3 -4
  8. package/crypto/sha2/module.f.d.ts +10 -0
  9. package/crypto/sha2/module.f.js +8 -0
  10. package/crypto/sign/module.f.d.ts +15 -0
  11. package/crypto/sign/module.f.js +15 -0
  12. package/dev/index/module.f.d.ts +2 -0
  13. package/dev/index/module.f.js +2 -0
  14. package/dev/module.f.d.ts +4 -2
  15. package/dev/module.f.js +29 -28
  16. package/dev/version/module.f.d.ts +3 -2
  17. package/dev/version/module.f.js +10 -10
  18. package/dev/version/test.f.js +3 -6
  19. package/html/module.f.d.ts +18 -0
  20. package/html/module.f.js +12 -0
  21. package/io/module.f.d.ts +4 -2
  22. package/io/module.f.js +24 -18
  23. package/package.json +4 -4
  24. package/types/effects/mock/module.f.d.ts +5 -4
  25. package/types/effects/mock/module.f.js +6 -4
  26. package/types/effects/module.d.ts +2 -2
  27. package/types/effects/module.f.d.ts +17 -19
  28. package/types/effects/module.f.js +14 -19
  29. package/types/effects/module.js +4 -3
  30. package/types/effects/node/module.f.d.ts +31 -35
  31. package/types/effects/node/module.f.js +16 -7
  32. package/types/effects/node/test.f.js +23 -25
  33. package/types/effects/node/virtual/module.f.d.ts +8 -8
  34. package/types/effects/node/virtual/module.f.js +13 -2
  35. package/website/module.f.d.ts +3 -1
  36. package/website/module.f.js +3 -4
  37. package/ci/module.d.ts +0 -1
  38. package/ci/module.js +0 -3
  39. package/dev/index/module.d.ts +0 -1
  40. package/dev/index/module.js +0 -3
  41. package/website/module.d.ts +0 -1
  42. package/website/module.js +0 -3
@@ -4,24 +4,24 @@
4
4
  * @module
5
5
  */
6
6
  import { utf8, utf8ToString } from "../../text/module.f.js";
7
- import { all, fluent, pure, step } from "../../types/effects/module.f.js";
8
- import { readFile, writeFile } from "../../types/effects/node/module.f.js";
7
+ import { begin, pure } from "../../types/effects/module.f.js";
8
+ import { all, readFile, writeFile } from "../../types/effects/node/module.f.js";
9
9
  import { unwrap } from "../../types/result/module.f.js";
10
10
  const { stringify, parse } = JSON;
11
11
  const jsonFile = (jsonFile) => `${jsonFile}.json`;
12
- const readJson = (name) => fluent
12
+ const readJson = (name) => begin
13
13
  .step(() => readFile(jsonFile(name)))
14
- .step(v => pure(parse(utf8ToString(unwrap(v)))))
15
- .effect;
16
- const writeVersion = (version) => (name) => step(readJson(name))(json => writeFile(jsonFile(name), utf8(stringify({
14
+ .step(v => pure(parse(utf8ToString(unwrap(v)))));
15
+ const writeVersion = (version) => (name) => begin
16
+ .step(() => readJson(name))
17
+ .step(json => writeFile(jsonFile(name), utf8(stringify({
17
18
  ...json,
18
19
  version,
19
20
  }, null, 2))));
20
- export const updateVersion = fluent
21
+ export const updateVersion = begin
21
22
  .step(() => readJson('package'))
22
23
  .step(p => {
23
24
  const w = writeVersion(p.version);
24
- return all([w('package'), w('deno')]);
25
+ return all(w('package'), w('deno'));
25
26
  })
26
- .step(() => pure(0))
27
- .effect;
27
+ .step(() => pure(0));
@@ -1,8 +1,6 @@
1
1
  import { utf8, utf8ToString } from "../../text/module.f.js";
2
2
  import { isVec } from "../../types/bit_vec/module.f.js";
3
- import { run } from "../../types/effects/mock/module.f.js";
4
- import { all } from "../../types/effects/module.f.js";
5
- import { writeFile } from "../../types/effects/node/module.f.js";
3
+ import { all, writeFile } from "../../types/effects/node/module.f.js";
6
4
  import { emptyState, virtual } from "../../types/effects/node/virtual/module.f.js";
7
5
  import { updateVersion } from "./module.f.js";
8
6
  const version = '0.3.0';
@@ -81,13 +79,12 @@ const e = '{\n' +
81
79
  '}';
82
80
  export default {
83
81
  new: () => {
84
- const rv = run(virtual);
85
82
  const w = (name) => {
86
83
  const fn = `${name}.json`;
87
84
  return writeFile(fn, utf8(JSON.stringify(x[fn])));
88
85
  };
89
- const [state] = rv(emptyState)(all([w('package'), w('deno')]));
90
- const [newState, result] = rv(state)(updateVersion);
86
+ const [state] = virtual(emptyState)(all(w('package'), w('deno')));
87
+ const [newState, result] = virtual(state)(updateVersion);
91
88
  if (result !== 0) {
92
89
  throw result;
93
90
  }
@@ -2,12 +2,30 @@ import { type List } from '../types/list/module.f.ts';
2
2
  type Tag = string;
3
3
  type Element1 = readonly [Tag, ...Node[]];
4
4
  type Element2 = readonly [Tag, Attributes, ...Node[]];
5
+ /**
6
+ * A FunctionalScript representation of an HTML element.
7
+ *
8
+ * - `[tag, ...children]` for elements without attributes.
9
+ * - `[tag, attributes, ...children]` for elements with attributes.
10
+ */
5
11
  export type Element = Element1 | Element2;
6
12
  type Attributes = {
7
13
  readonly [k in string]: string;
8
14
  };
9
15
  export type Node = Element | string;
16
+ /**
17
+ * Converts a FunctionalScript element into a list of HTML string chunks.
18
+ *
19
+ * Chunks are returned instead of a single string to support composition with
20
+ * other list/string helpers in this codebase.
21
+ */
10
22
  export declare const element: (e: Element) => List<string>;
23
+ /**
24
+ * Builds a complete HTML document by prepending `<!DOCTYPE html>`.
25
+ */
11
26
  export declare const html: (_: Element) => List<string>;
27
+ /**
28
+ * Renders an HTML element tree to a final string.
29
+ */
12
30
  export declare const htmlToString: (_: Element) => string;
13
31
  export {};
package/html/module.f.js CHANGED
@@ -62,6 +62,12 @@ const parseElement = (e) => {
62
62
  [tag, item1, list] :
63
63
  [tag, {}, [item1, ...list]];
64
64
  };
65
+ /**
66
+ * Converts a FunctionalScript element into a list of HTML string chunks.
67
+ *
68
+ * Chunks are returned instead of a single string to support composition with
69
+ * other list/string helpers in this codebase.
70
+ */
65
71
  export const element = (e) => {
66
72
  const [tag, a, n] = parseElement(e);
67
73
  const open = flat([[`<`, tag], attributes(a), [`>`]]);
@@ -70,5 +76,11 @@ export const element = (e) => {
70
76
  }
71
77
  return flat([open, rawText.includes(tag) ? [rawMap(n)] : nodes(n), ['</', tag, '>']]);
72
78
  };
79
+ /**
80
+ * Builds a complete HTML document by prepending `<!DOCTYPE html>`.
81
+ */
73
82
  export const html = compose(element)(listConcat(['<!DOCTYPE html>']));
83
+ /**
84
+ * Renders an HTML element tree to a final string.
85
+ */
74
86
  export const htmlToString = compose(html)(stringConcat);
package/io/module.f.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { NodeEffect } from '../types/effects/node/module.f.ts';
1
+ import { type Effect } from '../types/effects/module.f.ts';
2
+ import type { NodeOp } from '../types/effects/node/module.f.ts';
2
3
  import { type Result } from '../types/result/module.f.ts';
3
4
  /**
4
5
  * Represents a directory entry (file or directory) in the filesystem
@@ -104,4 +105,5 @@ export type Run = (f: App) => Promise<never>;
104
105
  * Handles errors by exiting with code 1
105
106
  */
106
107
  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>;
108
+ export type EffectToPromise = <T>(effect: Effect<NodeOp, T>) => Promise<T>;
109
+ export declare const fromIo: ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile } }, fetch, }: Io) => EffectToPromise;
package/io/module.f.js CHANGED
@@ -1,4 +1,6 @@
1
+ import { todo } from "../dev/module.f.js";
1
2
  import { normalize } from "../path/module.f.js";
3
+ import { pure } from "../types/effects/module.f.js";
2
4
  import { asyncRun } from "../types/effects/module.js";
3
5
  import { error, ok } from "../types/result/module.f.js";
4
6
  import { fromVec, toVec } from "../types/uint8array/module.f.js";
@@ -7,7 +9,7 @@ import { fromVec, toVec } from "../types/uint8array/module.f.js";
7
9
  * Handles errors by exiting with code 1
8
10
  */
9
11
  export const run = (io) => {
10
- const code = ([x, b]) => {
12
+ const exitCode = ([x, b]) => {
11
13
  if (x === 'error') {
12
14
  io.console.error(b);
13
15
  return 1;
@@ -16,7 +18,7 @@ export const run = (io) => {
16
18
  return b;
17
19
  }
18
20
  };
19
- return async (f) => io.process.exit(code(await io.asyncTryCatch(() => f(io))));
21
+ return async (f) => io.process.exit(exitCode(await io.asyncTryCatch(() => f(io))));
20
22
  };
21
23
  const tc = async (f) => {
22
24
  try {
@@ -26,19 +28,23 @@ const tc = async (f) => {
26
28
  return error(e);
27
29
  }
28
30
  };
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
- });
31
+ export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile } }, fetch, }) => {
32
+ const result = asyncRun({
33
+ all: async (effects) => await Promise.all(effects.map(v => result(v))),
34
+ error: async (message) => error(message),
35
+ log: async (message) => log(message),
36
+ fetch: async (url) => tc(async () => {
37
+ const response = await fetch(url);
38
+ if (!response.ok) {
39
+ throw new Error(`Fetch error: ${response.status} ${response.statusText}`);
40
+ }
41
+ return toVec(new Uint8Array(await response.arrayBuffer()));
42
+ }),
43
+ mkdir: param => tc(async () => { await mkdir(...param); }),
44
+ readFile: path => tc(async () => toVec(await readFile(path))),
45
+ readdir: ([path, r]) => tc(async () => (await readdir(path, { ...r, withFileTypes: true }))
46
+ .map(v => ({ name: v.name, parentPath: normalize(v.parentPath), isFile: v.isFile() }))),
47
+ writeFile: ([path, data]) => tc(() => writeFile(path, fromVec(data))),
48
+ });
49
+ return result;
50
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.10.3",
3
+ "version": "0.11.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "**/*.js",
@@ -11,12 +11,12 @@
11
11
  "prepack": "tsc --NoEmit false",
12
12
  "test20": "npm run prepack && node --test",
13
13
  "test": "tsc && node --test --experimental-strip-types --experimental-test-coverage --test-coverage-include=**/module.f.ts",
14
- "index": "node ./dev/index/module.ts",
14
+ "index": "node ./fjs/module.ts r ./dev/index/module.f.ts",
15
15
  "fst": "node ./fjs/module.ts t",
16
16
  "fjs": "node ./fjs/module.ts",
17
- "ci-update": "node ./ci/module.ts",
17
+ "ci-update": "node ./fjs/module.ts r ./ci/module.f.ts",
18
18
  "update": "git clean -fdx && npm install && npm run index && npm run ci-update",
19
- "website": "node --experimental-strip-types ./website/module.ts"
19
+ "website": "node --experimental-strip-types ./fjs/module.ts r ./website/module.f.ts"
20
20
  },
21
21
  "engines": {
22
22
  "node": ">=20"
@@ -3,8 +3,9 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import type { Effect, Operations } from "../module.f.ts";
7
- export type MemOperationMap<O extends Operations, S> = {
8
- readonly [K in keyof O]: (state: S, payload: O[K][0]) => readonly [S, O[K][1]];
6
+ import type { Effect, Operation, Pr } from "../module.f.ts";
7
+ export type MemOperationMap<O extends Operation, S> = {
8
+ readonly [K in O[0]]: (state: S, payload: Pr<O, K>[0]) => readonly [S, Pr<O, K>[1]];
9
9
  };
10
- export declare const run: <O extends Operations, S>(o: MemOperationMap<O, S>) => (state: S) => <O1 extends O, T>(effect: Effect<O1, T>) => readonly [S, T];
10
+ export type RunInstance<O extends Operation, S> = (state: S) => <O1 extends O, T>(effect: Effect<O1, T>) => readonly [S, T];
11
+ export declare const run: <O extends Operation, S>(o: MemOperationMap<O, S>) => RunInstance<O, S>;
@@ -1,11 +1,13 @@
1
- export const run = (o) => (state) => (effect) => {
1
+ export const run = (o) => state => effect => {
2
2
  let s = state;
3
3
  let e = effect;
4
4
  while (true) {
5
- if (e.length === 1) {
6
- return [s, e[0]];
5
+ const { value } = e;
6
+ if (value.length === 1) {
7
+ const [v] = value;
8
+ return [s, v];
7
9
  }
8
- const [cmd, payload, cont] = e;
10
+ const [cmd, payload, cont] = value;
9
11
  const operation = o[cmd];
10
12
  const [ns, m] = operation(s, payload);
11
13
  s = ns;
@@ -1,2 +1,2 @@
1
- import type { Effect, Operations, ToAsyncOperationMap } from "./module.f.ts";
2
- export declare const asyncRun: <O extends Operations>(map: ToAsyncOperationMap<O>) => <T, E extends Effect<O, T>>(effect: Effect<O, T>) => Promise<T>;
1
+ import type { Effect, Operation, ToAsyncOperationMap } from "./module.f.ts";
2
+ export declare const asyncRun: <O extends Operation>(map: ToAsyncOperationMap<O>) => <T, E extends Effect<O, T>>(effect: Effect<O, T>) => Promise<T>;
@@ -3,25 +3,23 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- export type Operations = {
7
- readonly [command in string]: readonly [input: unknown, output: unknown];
6
+ export type Operation = readonly [string, (_: never) => unknown];
7
+ export type Effect<O extends Operation, T> = {
8
+ value: Value<O, T>;
9
+ step: <Q extends Operation, R>(f: (p: T) => Effect<Q, R>) => Effect<O | Q, R>;
8
10
  };
9
- export type Effect<O extends Operations, T> = Pure<T> | Do<O, T>;
11
+ export type Value<O extends Operation, T> = Pure<T> | Do<O, T>;
10
12
  export type Pure<T> = readonly [T];
11
- export type One<O extends Operations, T, K extends keyof O & string> = readonly [K, O[K][0], (input: O[K][1]) => Effect<O, T>];
12
- export type Do<O extends Operations, T> = {
13
- readonly [K in keyof O & string]: One<O, T, K>;
14
- }[keyof O & string];
15
- export declare const pure: <T>(value: T) => Pure<T>;
16
- export declare const do_: <O extends Operations, K extends keyof O & string>(cmd: K, payload: O[K][0]) => Do<O, O[K][1]>;
17
- export type ToAsyncOperationMap<O extends Operations> = {
18
- readonly [K in keyof O]: (payload: O[K][0]) => Promise<O[K][1]>;
13
+ export type DoKPR<O extends Operation, T, K extends string, PR extends readonly [unknown, unknown]> = readonly [K, PR[0], (_: PR[1]) => Effect<O, T>];
14
+ export type Pr<O extends Operation, K extends O[0]> = O extends readonly [K, (_: infer P) => infer R] ? readonly [P, R] : never;
15
+ export type DoK<O extends Operation, T, K extends O[0]> = DoKPR<O, T, K, Pr<O, K>>;
16
+ export type Do<O extends Operation, T> = DoK<O, T, O[0]>;
17
+ export declare const pure: <T>(v: T) => Effect<never, T>;
18
+ export declare const doFull: <O extends Operation, T, K extends O[0]>(cmd: K, param: Pr<O, K>[0], cont: (input: Pr<O, K>[1]) => Effect<O, T>) => Effect<O, T>;
19
+ export declare const do_: <O extends Operation>(cmd: O[0]) => (param: Pr<O, O[0]>[0]) => Effect<O, Pr<O, O[0]>[1]>;
20
+ export declare const begin: Effect<never, void>;
21
+ export type ToAsyncOperationMap<O extends Operation> = {
22
+ readonly [K in O[0]]: (payload: Pr<O, K>[0]) => Promise<Pr<O, K>[1]>;
19
23
  };
20
- export declare const step: <O extends Operations, T>(e: Effect<O, T>) => <O1 extends Operations, R>(f: (_: T) => Effect<O1, R>) => Effect<O | O1, R>;
21
- export declare const map: <O extends Operations, T>(e: Effect<O, T>) => <R>(f: (_: T) => R) => Effect<O, R>;
22
- export type Fluent<O extends Operations, T> = {
23
- readonly effect: Effect<O, T>;
24
- readonly step: <O1 extends Operations, R>(f: (_: T) => Effect<O1, R>) => Fluent<O | O1, R>;
25
- };
26
- export declare const fluent: Fluent<{}, void>;
27
- export declare const all: <O extends Operations, T>(set: readonly Effect<O, T>[]) => Effect<O, readonly T[]>;
24
+ export type F<O extends Operation> = Pr<O, O[0]>;
25
+ export type Func<O extends Operation> = (_: F<O>[0]) => Effect<O, F<O>[1]>;
@@ -1,20 +1,15 @@
1
- export const pure = (value) => [value];
2
- const doFull = (cmd, payload, cont) => [cmd, payload, cont];
3
- export const do_ = (cmd, payload) => doFull(cmd, payload, pure);
4
- export const step = (e) => (f) => {
5
- if (e.length === 1) {
6
- const [value] = e;
7
- return f(value);
8
- }
9
- const [cmd, payload, cont] = e;
10
- return doFull(cmd, payload, x => step(cont(x))(f));
11
- };
12
- export const map = (e) => (f) => step(e)(x => pure(f(x)));
13
- const wrap = (effect) => ({
14
- effect,
15
- step: x => wrap(step(effect)(x)),
1
+ /**
2
+ * Core effect type constructors and combinators.
3
+ *
4
+ * @module
5
+ */
6
+ export const pure = (v) => ({
7
+ value: [v],
8
+ step: f => f(v)
16
9
  });
17
- export const fluent = wrap(pure(undefined));
18
- const empty = pure([]);
19
- // TODO: replace with either a `Do` operation or as an addition to `Pure` and `Do`.
20
- export const all = (set) => set.reduce((previous, current) => step(previous)(previousResult => map(current)(currentResult => [...previousResult, currentResult])), empty);
10
+ export const doFull = (cmd, param, cont) => ({
11
+ value: [cmd, param, cont],
12
+ step: (f) => doFull(cmd, param, x => cont(x).step(f)),
13
+ });
14
+ export const do_ = (cmd) => (param) => doFull(cmd, param, pure);
15
+ export const begin = pure(undefined);
@@ -1,9 +1,10 @@
1
1
  export const asyncRun = (map) => async (effect) => {
2
2
  while (true) {
3
- if (effect.length === 1) {
4
- return effect[0];
3
+ const { value } = effect;
4
+ if (value.length === 1) {
5
+ return value[0];
5
6
  }
6
- const [command, payload, continuation] = effect;
7
+ const [command, payload, continuation] = value;
7
8
  const operation = map[command];
8
9
  const result = await operation(payload);
9
10
  effect = continuation(result);
@@ -1,23 +1,27 @@
1
1
  import type { Vec } from '../../bit_vec/module.f.ts';
2
2
  import type { Result } from '../../result/module.f.ts';
3
- import { type Do, type Effect, type ToAsyncOperationMap } from '../module.f.ts';
3
+ import { type Effect, type Func, type Operation, type ToAsyncOperationMap } from '../module.f.ts';
4
4
  export type IoResult<T> = Result<T, unknown>;
5
- export type Fetch = {
6
- readonly fetch: readonly [string, IoResult<Vec>];
7
- };
8
- export declare const fetch: (url: string) => Do<Fetch, IoResult<Vec>>;
5
+ export type All = ['all', <T>(_: readonly Effect<never, T>[]) => readonly T[]];
6
+ /**
7
+ * To run the operation `O` should be known by the runner/engine.
8
+ * This is the reason why we merge `O` with `All` in the resulted `Effect`.
9
+ *
10
+ * @param a
11
+ * @returns
12
+ */
13
+ export declare const all: <O extends Operation, T>(...a: readonly Effect<O, T>[]) => Effect<O | All, readonly T[]>;
14
+ export declare const both: <O0 extends Operation, T0>(a: Effect<O0, T0>) => <O1 extends Operation, T1>(b: Effect<O1, T1>) => Effect<O0 | O1 | All, readonly [T0, T1]>;
15
+ export type Fetch = ['fetch', (_: string) => IoResult<Vec>];
16
+ export declare const fetch: Func<Fetch>;
9
17
  export type MakeDirectoryOptions = {
10
18
  readonly recursive: true;
11
19
  };
12
20
  export type MkdirParam = readonly [string, MakeDirectoryOptions?];
13
- export type Mkdir = {
14
- readonly mkdir: readonly [MkdirParam, IoResult<void>];
15
- };
16
- export declare const mkdir: (...p: MkdirParam) => Do<Mkdir, IoResult<void>>;
17
- export type ReadFile = {
18
- readonly readFile: readonly [string, IoResult<Vec>];
19
- };
20
- export declare const readFile: (path: string) => Do<ReadFile, IoResult<Vec>>;
21
+ export type Mkdir = readonly ['mkdir', (_: MkdirParam) => IoResult<void>];
22
+ export declare const mkdir: (...p: MkdirParam) => Effect<Mkdir, IoResult<void>>;
23
+ export type ReadFile = readonly ['readFile', (_: string) => IoResult<Vec>];
24
+ export declare const readFile: Func<ReadFile>;
21
25
  /**
22
26
  * Represents a directory entry (file or directory) in the filesystem
23
27
  * @see https://nodejs.org/api/fs.html#class-fsdirent
@@ -31,26 +35,18 @@ export type ReaddirOptions = {
31
35
  readonly recursive?: true;
32
36
  };
33
37
  export type ReaddirParam = readonly [string, ReaddirOptions];
34
- export type Readdir = {
35
- readonly readdir: readonly [ReaddirParam, IoResult<readonly Dirent[]>];
36
- };
37
- export declare const readdir: (...p: ReaddirParam) => Do<Readdir, IoResult<readonly Dirent[]>>;
38
+ export type Readdir = readonly ['readdir', (_: ReaddirParam) => IoResult<readonly Dirent[]>];
39
+ export declare const readdir: (...p: ReaddirParam) => Effect<Readdir, IoResult<readonly Dirent[]>>;
38
40
  export type WriteFileParam = readonly [string, Vec];
39
- export type WriteFile = {
40
- readonly writeFile: readonly [WriteFileParam, IoResult<void>];
41
- };
42
- export declare const writeFile: (...p: WriteFileParam) => Do<WriteFile, IoResult<void>>;
43
- export type Fs = Mkdir & ReadFile & Readdir & WriteFile;
44
- export type Error = {
45
- readonly error: readonly [string, void];
46
- };
47
- export declare const error: (msg: string) => Do<Error, void>;
48
- export type Log = {
49
- readonly log: readonly [string, void];
50
- };
51
- export declare const log: (msg: string) => Do<Log, void>;
52
- export type Console = Log & Error;
53
- export type NodeOperations = Fetch & Console & Fs;
54
- export type NodeEffect<T> = Effect<NodeOperations, T>;
55
- export type NodeOperationMap = ToAsyncOperationMap<NodeOperations>;
56
- export type NodeProgram = (argv: readonly string[]) => NodeEffect<number>;
41
+ export type WriteFile = readonly ['writeFile', (_: WriteFileParam) => IoResult<void>];
42
+ export declare const writeFile: (...p: WriteFileParam) => Effect<WriteFile, IoResult<void>>;
43
+ export type Fs = Mkdir | ReadFile | Readdir | WriteFile;
44
+ export type Error = ['error', (_: string) => void];
45
+ export declare const error: Func<Error>;
46
+ export type Log = ['log', (_: string) => void];
47
+ export declare const log: Func<Log>;
48
+ export type Console = Log | Error;
49
+ export type NodeOp = All | Fetch | Console | Fs;
50
+ export type NodeEffect<T> = Effect<NodeOp, T>;
51
+ export type NodeOperationMap = ToAsyncOperationMap<NodeOp>;
52
+ export type NodeProgram = (argv: readonly string[]) => Effect<NodeOp, number>;
@@ -1,8 +1,17 @@
1
1
  import { do_ } from "../module.f.js";
2
- export const fetch = (url) => do_('fetch', url);
3
- export const mkdir = (...p) => do_('mkdir', p);
4
- export const readFile = (path) => do_('readFile', path);
5
- export const readdir = (...p) => do_('readdir', p);
6
- export const writeFile = (...p) => do_('writeFile', p);
7
- export const error = (msg) => do_('error', msg);
8
- export const log = (msg) => do_('log', msg);
2
+ /**
3
+ * To run the operation `O` should be known by the runner/engine.
4
+ * This is the reason why we merge `O` with `All` in the resulted `Effect`.
5
+ *
6
+ * @param a
7
+ * @returns
8
+ */
9
+ export const all = (...a) => do_('all')(a);
10
+ export const both = (a) => (b) => all(a, b);
11
+ export const fetch = do_('fetch');
12
+ export const mkdir = (...p) => do_('mkdir')(p);
13
+ export const readFile = do_('readFile');
14
+ export const readdir = (...p) => do_('readdir')(p);
15
+ export const writeFile = (...p) => do_('writeFile')(p);
16
+ export const error = do_('error');
17
+ export const log = do_('log');