functionalscript 0.14.8 → 0.16.0
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/fs/ci/common/module.f.d.ts +50 -16
- package/fs/ci/common/module.f.js +19 -0
- package/fs/ci/config/module.f.d.ts +2 -2
- package/fs/ci/config/module.f.js +2 -2
- package/fs/ci/module.f.js +1 -1
- package/fs/ci/test.f.js +6 -2
- package/fs/dev/module.f.d.ts +2 -1
- package/fs/dev/module.f.js +25 -16
- package/fs/dev/tf/module.f.js +10 -0
- package/fs/dev/tf/test.f.d.ts +5 -0
- package/fs/dev/tf/test.f.js +14 -0
- package/fs/fjs/module.f.js +5 -3
- package/fs/io/module.d.ts +2 -2
- package/fs/io/module.f.d.ts +3 -15
- package/fs/io/module.f.js +14 -8
- package/fs/io/module.js +2 -2
- package/fs/io/virtual/module.f.js +2 -2
- package/fs/types/effects/mock/module.f.d.ts +1 -1
- package/fs/types/effects/mock/module.f.js +1 -1
- package/fs/types/effects/module.f.d.ts +5 -7
- package/fs/types/effects/module.f.js +1 -2
- package/fs/types/effects/module.js +1 -1
- package/fs/types/effects/node/module.f.d.ts +34 -25
- package/fs/types/effects/node/module.f.js +9 -7
- package/fs/types/effects/node/test.f.js +1 -1
- package/fs/types/effects/node/virtual/module.f.js +16 -5
- package/fs/types/rtti/common/module.f.d.ts +77 -0
- package/fs/types/rtti/common/module.f.js +45 -0
- package/fs/types/rtti/module.f.d.ts +4 -8
- package/fs/types/rtti/module.f.js +5 -71
- package/fs/types/rtti/parse/module.f.d.ts +3 -27
- package/fs/types/rtti/parse/module.f.js +12 -20
- package/fs/types/rtti/test.f.d.ts +0 -28
- package/fs/types/rtti/test.f.js +0 -107
- package/fs/types/rtti/ts/module.f.d.ts +9 -6
- package/fs/types/rtti/validate/module.f.d.ts +3 -79
- package/fs/types/rtti/validate/module.f.js +13 -36
- package/package.json +2 -2
|
@@ -1,30 +1,63 @@
|
|
|
1
1
|
import { images } from '../config/module.f.ts';
|
|
2
|
+
import { type Ts } from '../../types/rtti/ts/module.f.ts';
|
|
2
3
|
export declare const os: readonly ["ubuntu", "macos", "windows"];
|
|
3
4
|
export type Os = typeof os[number];
|
|
4
5
|
export declare const architecture: readonly ["intel", "arm"];
|
|
5
6
|
export type Architecture = typeof architecture[number];
|
|
6
7
|
export type Image = typeof images[Os][Architecture];
|
|
7
|
-
|
|
8
|
-
readonly run
|
|
9
|
-
readonly uses
|
|
10
|
-
readonly with
|
|
11
|
-
readonly [k: string]: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export type Job = {
|
|
15
|
-
readonly 'runs-on': Image;
|
|
16
|
-
readonly steps: readonly Step[];
|
|
8
|
+
declare const stepSchema: {
|
|
9
|
+
readonly run: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
10
|
+
readonly uses: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
11
|
+
readonly with: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").Type1<"record", import("../../types/rtti/module.f.ts").String>, undefined]>;
|
|
17
12
|
};
|
|
18
|
-
|
|
19
|
-
readonly
|
|
13
|
+
declare const jobSchema: {
|
|
14
|
+
readonly 'runs-on': import("../../types/rtti/module.f.ts").String;
|
|
15
|
+
readonly steps: import("../../types/rtti/module.f.ts").Type1<"array", {
|
|
16
|
+
readonly run: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
17
|
+
readonly uses: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
18
|
+
readonly with: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").Type1<"record", import("../../types/rtti/module.f.ts").String>, undefined]>;
|
|
19
|
+
}>;
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
readonly
|
|
21
|
+
declare const jobsSchema: import("../../types/rtti/module.f.ts").Type1<"record", {
|
|
22
|
+
readonly 'runs-on': import("../../types/rtti/module.f.ts").String;
|
|
23
|
+
readonly steps: import("../../types/rtti/module.f.ts").Type1<"array", {
|
|
24
|
+
readonly run: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
25
|
+
readonly uses: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
26
|
+
readonly with: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").Type1<"record", import("../../types/rtti/module.f.ts").String>, undefined]>;
|
|
27
|
+
}>;
|
|
28
|
+
}>;
|
|
29
|
+
declare const gitHubActionSchema: {
|
|
30
|
+
readonly name: import("../../types/rtti/module.f.ts").String;
|
|
23
31
|
readonly on: {
|
|
24
|
-
readonly pull_request
|
|
32
|
+
readonly pull_request: import("../../types/rtti/module.f.ts").Or<readonly [{}, undefined]>;
|
|
25
33
|
};
|
|
26
|
-
readonly jobs:
|
|
34
|
+
readonly jobs: import("../../types/rtti/module.f.ts").Type1<"record", {
|
|
35
|
+
readonly 'runs-on': import("../../types/rtti/module.f.ts").String;
|
|
36
|
+
readonly steps: import("../../types/rtti/module.f.ts").Type1<"array", {
|
|
37
|
+
readonly run: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
38
|
+
readonly uses: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
39
|
+
readonly with: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").Type1<"record", import("../../types/rtti/module.f.ts").String>, undefined]>;
|
|
40
|
+
}>;
|
|
41
|
+
}>;
|
|
27
42
|
};
|
|
43
|
+
export type Step = Ts<typeof stepSchema>;
|
|
44
|
+
export type Job = Ts<typeof jobSchema>;
|
|
45
|
+
export type Jobs = Ts<typeof jobsSchema>;
|
|
46
|
+
export type GitHubAction = Ts<typeof gitHubActionSchema>;
|
|
47
|
+
export declare const parseGitHubAction: import("../../types/rtti/parse/module.f.ts").Parse<{
|
|
48
|
+
readonly name: import("../../types/rtti/module.f.ts").String;
|
|
49
|
+
readonly on: {
|
|
50
|
+
readonly pull_request: import("../../types/rtti/module.f.ts").Or<readonly [{}, undefined]>;
|
|
51
|
+
};
|
|
52
|
+
readonly jobs: import("../../types/rtti/module.f.ts").Type1<"record", {
|
|
53
|
+
readonly 'runs-on': import("../../types/rtti/module.f.ts").String;
|
|
54
|
+
readonly steps: import("../../types/rtti/module.f.ts").Type1<"array", {
|
|
55
|
+
readonly run: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
56
|
+
readonly uses: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").String, undefined]>;
|
|
57
|
+
readonly with: import("../../types/rtti/module.f.ts").Or<readonly [import("../../types/rtti/module.f.ts").Type1<"record", import("../../types/rtti/module.f.ts").String>, undefined]>;
|
|
58
|
+
}>;
|
|
59
|
+
}>;
|
|
60
|
+
}>;
|
|
28
61
|
export type StepType = 'install' | 'test';
|
|
29
62
|
export type MetaStep = {
|
|
30
63
|
readonly type: StepType;
|
|
@@ -42,3 +75,4 @@ export declare const clean: (steps: readonly MetaStep[]) => readonly MetaStep[];
|
|
|
42
75
|
export declare const toSteps: (m: readonly MetaStep[]) => readonly Step[];
|
|
43
76
|
export declare const ubuntu: (ms: readonly MetaStep[]) => Job;
|
|
44
77
|
export declare const findTgz: (v: Os) => "(Get-ChildItem *.tgz).FullName" | "./*.tgz";
|
|
78
|
+
export {};
|
package/fs/ci/common/module.f.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { images, rust } from "../config/module.f.js";
|
|
2
|
+
import { option, array, record, string } from "../../types/rtti/module.f.js";
|
|
3
|
+
import {} from "../../types/rtti/ts/module.f.js";
|
|
4
|
+
import { parse as rttiParse } from "../../types/rtti/parse/module.f.js";
|
|
2
5
|
export const os = ['ubuntu', 'macos', 'windows'];
|
|
3
6
|
export const architecture = ['intel', 'arm'];
|
|
7
|
+
const stepSchema = {
|
|
8
|
+
run: option(string),
|
|
9
|
+
uses: option(string),
|
|
10
|
+
with: option(record(string))
|
|
11
|
+
};
|
|
12
|
+
const jobSchema = {
|
|
13
|
+
'runs-on': string,
|
|
14
|
+
steps: array(stepSchema)
|
|
15
|
+
};
|
|
16
|
+
const jobsSchema = record(jobSchema);
|
|
17
|
+
const gitHubActionSchema = {
|
|
18
|
+
name: string,
|
|
19
|
+
on: { pull_request: option({}) },
|
|
20
|
+
jobs: jobsSchema
|
|
21
|
+
};
|
|
22
|
+
export const parseGitHubAction = rttiParse(gitHubActionSchema);
|
|
4
23
|
export const install = (step) => ({ type: 'install', step });
|
|
5
24
|
export const test = (step) => ({ type: 'test', step });
|
|
6
25
|
export const clean = (steps) => [
|
|
@@ -18,8 +18,8 @@ export declare const playwright = "1.60.0";
|
|
|
18
18
|
export declare const rust = "1.95.0";
|
|
19
19
|
export declare const node: {
|
|
20
20
|
readonly default: "26.1.0";
|
|
21
|
-
readonly others: readonly ["22.22.
|
|
21
|
+
readonly others: readonly ["22.22.3", "24.15.0"];
|
|
22
22
|
};
|
|
23
23
|
export declare const wasmtime = "44.0.1";
|
|
24
24
|
export declare const wasmer = "7.1.0";
|
|
25
|
-
export declare const tsgo = "7.0.0-dev.
|
|
25
|
+
export declare const tsgo = "7.0.0-dev.20260517.1";
|
package/fs/ci/config/module.f.js
CHANGED
|
@@ -24,11 +24,11 @@ export const rust = '1.95.0';
|
|
|
24
24
|
// https://nodejs.org/en/download
|
|
25
25
|
export const node = {
|
|
26
26
|
default: '26.1.0',
|
|
27
|
-
others: ['22.22.
|
|
27
|
+
others: ['22.22.3', '24.15.0'],
|
|
28
28
|
};
|
|
29
29
|
// https://github.com/bytecodealliance/wasmtime/releases
|
|
30
30
|
export const wasmtime = '44.0.1';
|
|
31
31
|
// https://github.com/wasmerio/wasmer/releases
|
|
32
32
|
export const wasmer = '7.1.0';
|
|
33
33
|
// https://www.npmjs.com/package/@typescript/native-preview?activeTab=versions
|
|
34
|
-
export const tsgo = '7.0.0-dev.
|
|
34
|
+
export const tsgo = '7.0.0-dev.20260517.1';
|
package/fs/ci/module.f.js
CHANGED
|
@@ -51,7 +51,7 @@ const defaultEffect = ci({
|
|
|
51
51
|
denoExtra: [
|
|
52
52
|
test({ run: 'deno task fjs compile issues/demo/data/tree.json _tree.f.js' }),
|
|
53
53
|
test({ run: 'deno task fjs t' }),
|
|
54
|
-
test({ run: 'deno publish --dry-run' }),
|
|
54
|
+
test({ run: 'deno publish --dry-run --allow-slow-types' }),
|
|
55
55
|
],
|
|
56
56
|
bunExtra: [
|
|
57
57
|
test({ run: 'bun ./fs/fjs/module.ts t' }),
|
package/fs/ci/test.f.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { ci } from "./module.f.js";
|
|
2
2
|
import { utf8ToString } from "../text/module.f.js";
|
|
3
3
|
import { isVec } from "../types/bit_vec/module.f.js";
|
|
4
|
-
import { test } from "./common/module.f.js";
|
|
4
|
+
import { test, parseGitHubAction } from "./common/module.f.js";
|
|
5
5
|
import { assert } from "../dev/module.f.js";
|
|
6
6
|
import { emptyState, virtual } from "../types/effects/node/virtual/module.f.js";
|
|
7
|
+
import {} from "../types/rtti/ts/module.f.js";
|
|
8
|
+
import { parse as jsonParse } from "../json/module.f.js";
|
|
9
|
+
import { unwrap } from "../types/result/module.f.js";
|
|
10
|
+
// type Gha = Ts<typeof gitHubActionSchema>
|
|
7
11
|
const hasRun = (cmd) => (gha) => Object.values(gha.jobs).some(job => job.steps.some(step => step.run?.includes(cmd)));
|
|
8
12
|
const hasRunInJob = (jobId, cmd) => (gha) => gha.jobs[jobId]?.steps.some(step => step.run?.includes(cmd)) ?? false;
|
|
9
13
|
const githubState = {
|
|
@@ -19,7 +23,7 @@ const run = (rust, nodeExtra = () => []) => {
|
|
|
19
23
|
assert(workflows !== undefined && !isVec(workflows), workflows);
|
|
20
24
|
const file = workflows['ci.yml'];
|
|
21
25
|
assert(isVec(file), file);
|
|
22
|
-
return
|
|
26
|
+
return unwrap(parseGitHubAction(jsonParse(utf8ToString(file))));
|
|
23
27
|
};
|
|
24
28
|
export default {
|
|
25
29
|
rust: () => {
|
package/fs/dev/module.f.d.ts
CHANGED
|
@@ -11,11 +11,12 @@ export declare const assert: (v: boolean, msg?: unknown) => asserts v;
|
|
|
11
11
|
export declare const assertEq: <T>(a: T, b: T) => void;
|
|
12
12
|
export type Module = {
|
|
13
13
|
readonly default?: unknown;
|
|
14
|
+
readonly [k: string]: unknown;
|
|
14
15
|
};
|
|
15
16
|
export type ModuleMap = {
|
|
16
17
|
readonly [k in string]: Module;
|
|
17
18
|
};
|
|
18
19
|
export declare const env: (io: Io) => (v: string) => string | undefined;
|
|
19
|
-
export declare const
|
|
20
|
+
export declare const allFiles: (s: string) => Effect<Readdir | All, readonly string[]>;
|
|
20
21
|
export declare const loadModuleMap: (io: Io) => Promise<ModuleMap>;
|
|
21
22
|
export declare const index4: NodeProgram;
|
package/fs/dev/module.f.js
CHANGED
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { fromIo } from "../io/module.f.js";
|
|
7
7
|
import { updateVersion } from "./version/module.f.js";
|
|
8
|
-
import { all, both, readdir, readFile, writeFile } from "../types/effects/node/module.f.js";
|
|
8
|
+
import { access, all, both, import_, readdir, readFile, writeFile } from "../types/effects/node/module.f.js";
|
|
9
9
|
import { utf8, utf8ToString } from "../text/module.f.js";
|
|
10
10
|
import { unwrap } from "../types/result/module.f.js";
|
|
11
11
|
import { begin, pure } from "../types/effects/module.f.js";
|
|
12
|
+
import { parse as jsonParse } from "../json/module.f.js";
|
|
13
|
+
import { record, unknown as rttiUnknown } from "../types/rtti/module.f.js";
|
|
14
|
+
import { parse as rttiParse } from "../types/rtti/parse/module.f.js";
|
|
12
15
|
export const todo = () => { throw 'not implemented'; };
|
|
13
16
|
export const assert = (v, msg = 'assertion failed') => {
|
|
14
17
|
if (!v)
|
|
@@ -22,7 +25,7 @@ export const env = ({ process: { env } }) => a => {
|
|
|
22
25
|
typeof r.get === 'function' ? r.get() :
|
|
23
26
|
r.value;
|
|
24
27
|
};
|
|
25
|
-
export const
|
|
28
|
+
export const allFiles = (s) => {
|
|
26
29
|
const load = (p) => begin
|
|
27
30
|
.step(() => readdir(p, {}))
|
|
28
31
|
.step(d => {
|
|
@@ -49,28 +52,34 @@ export const allFiles2 = (s) => {
|
|
|
49
52
|
.step(v => pure(v.flat()));
|
|
50
53
|
return load(s);
|
|
51
54
|
};
|
|
52
|
-
const
|
|
55
|
+
const loadFile = (f) => {
|
|
56
|
+
const doImport = import_(f).step(r => pure([[f, unwrap(r)]]));
|
|
57
|
+
if (f.endsWith('.f.js')) {
|
|
58
|
+
return doImport;
|
|
59
|
+
}
|
|
60
|
+
if (f.endsWith('.f.ts')) {
|
|
61
|
+
return access(f.substring(0, f.length - 3) + '.js')
|
|
62
|
+
.step(r => r[0] === 'ok' ? pure([]) : doImport);
|
|
63
|
+
}
|
|
64
|
+
return pure([]);
|
|
65
|
+
};
|
|
53
66
|
export const loadModuleMap = async (io) => {
|
|
54
|
-
const {
|
|
55
|
-
|
|
56
|
-
const initCwd = env(io)('INIT_CWD');
|
|
67
|
+
const { process: { env } } = io;
|
|
68
|
+
const initCwd = env['INIT_CWD'];
|
|
57
69
|
const s = initCwd === undefined ? '.' : `${initCwd.replaceAll('\\', '/')}`;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
map = [...map, [f, source]];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return Object.fromEntries(map.toSorted(cmp));
|
|
70
|
+
const effect = allFiles(s)
|
|
71
|
+
.step(files => all(...files.map(loadFile)))
|
|
72
|
+
.step(entries => pure(Object.fromEntries(entries.flat().toSorted(cmp))));
|
|
73
|
+
return fromIo(io)(effect);
|
|
66
74
|
};
|
|
67
75
|
const denoJson = './deno.json';
|
|
76
|
+
const parseDenoJson = rttiParse(record(rttiUnknown));
|
|
68
77
|
const index2 = begin
|
|
69
78
|
.step(() => updateVersion)
|
|
70
79
|
.step(() => readFile(denoJson))
|
|
71
|
-
.step(v => pure(
|
|
80
|
+
.step(v => pure(unwrap(parseDenoJson(jsonParse(utf8ToString(unwrap(v)))))));
|
|
72
81
|
const allFiles2aa = begin
|
|
73
|
-
.step(() =>
|
|
82
|
+
.step(() => allFiles('.'))
|
|
74
83
|
.step(files => {
|
|
75
84
|
const list = files.filter(v => v.endsWith('/module.f.ts') || v.endsWith('/module.ts'));
|
|
76
85
|
const exportsA = list.map(v => [v, `./${v.substring(2)}`]);
|
package/fs/dev/tf/module.f.js
CHANGED
|
@@ -93,6 +93,16 @@ export const test = (input) => {
|
|
|
93
93
|
if (isTest(k)) {
|
|
94
94
|
log(`testing ${k}`);
|
|
95
95
|
[ts, state] = test('| ')(false)(v.default)([ts, state]);
|
|
96
|
+
// Non-default exports are walked as a sibling test group so
|
|
97
|
+
// a test file can spread its tests across multiple named
|
|
98
|
+
// exports (see issue 27 in `issues/README.md`). Skip exports
|
|
99
|
+
// that parseTestSet would treat as empty (constants, types,
|
|
100
|
+
// non-test helpers) to avoid noisy empty entries in output.
|
|
101
|
+
const others = Object.fromEntries(Object.entries(v).filter(([key, val]) => key !== 'default' && ((typeof val === 'function' && val.length === 0) ||
|
|
102
|
+
(typeof val === 'object' && val !== null))));
|
|
103
|
+
if (Object.keys(others).length !== 0) {
|
|
104
|
+
[ts, state] = test('| ')(false)(others)([ts, state]);
|
|
105
|
+
}
|
|
96
106
|
}
|
|
97
107
|
return [ts, state];
|
|
98
108
|
};
|
package/fs/dev/tf/test.f.d.ts
CHANGED
package/fs/dev/tf/test.f.js
CHANGED
|
@@ -20,3 +20,17 @@ export default {
|
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
|
+
// Non-default exports are walked as a sibling test group (see issue 27).
|
|
24
|
+
export const namedExportTest = () => {
|
|
25
|
+
if (2 + 2 !== 4) {
|
|
26
|
+
throw 'arithmetic broken';
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export const namedExportGroup = {
|
|
30
|
+
nested: () => {
|
|
31
|
+
if ('a' + 'b' !== 'ab') {
|
|
32
|
+
throw 'string concat broken';
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
throw: () => { throw 'expected to throw'; },
|
|
36
|
+
};
|
package/fs/fjs/module.f.js
CHANGED
|
@@ -9,7 +9,9 @@ import { main as testMain } from "../dev/tf/module.f.js";
|
|
|
9
9
|
import { main as casMain } from "../cas/module.f.js";
|
|
10
10
|
export const main = async (io) => {
|
|
11
11
|
const { error } = io.console;
|
|
12
|
-
const
|
|
12
|
+
const { process, asyncImport } = io;
|
|
13
|
+
const { env } = process;
|
|
14
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
13
15
|
const eRun = fromIo(io);
|
|
14
16
|
switch (command) {
|
|
15
17
|
case 'test':
|
|
@@ -24,8 +26,8 @@ export const main = async (io) => {
|
|
|
24
26
|
case 'run':
|
|
25
27
|
case 'r':
|
|
26
28
|
const [file, ...args] = rest;
|
|
27
|
-
const m = await
|
|
28
|
-
return eRun(m.default(args));
|
|
29
|
+
const m = await asyncImport(file);
|
|
30
|
+
return eRun(m.default(args, env));
|
|
29
31
|
case undefined:
|
|
30
32
|
error('Error: command is required');
|
|
31
33
|
return Promise.resolve(1);
|
package/fs/io/module.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Io, type
|
|
2
|
-
import type { NodeProgram } from '../types/effects/node/module.f.ts';
|
|
1
|
+
import { type Io, type Run } from './module.f.ts';
|
|
2
|
+
import type { Module, NodeProgram } from '../types/effects/node/module.f.ts';
|
|
3
3
|
export declare const asyncImport: (v: string) => Promise<Module>;
|
|
4
4
|
export declare const io: Io;
|
|
5
5
|
export declare const legacyRun: Run;
|
package/fs/io/module.f.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Effect } from '../types/effects/module.f.ts';
|
|
2
|
-
import type { Headers, NodeOp } from '../types/effects/node/module.f.ts';
|
|
2
|
+
import type { Headers, Module, NodeOp, Env } from '../types/effects/node/module.f.ts';
|
|
3
3
|
import { type Result } from '../types/result/module.f.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Represents a directory entry (file or directory) in the filesystem
|
|
@@ -31,7 +31,6 @@ export type Fs = {
|
|
|
31
31
|
readonly writeSync: (fd: number, s: string) => void;
|
|
32
32
|
readonly writeFileSync: (file: string, data: Uint8Array) => void;
|
|
33
33
|
readonly readFileSync: (path: string) => Uint8Array | null;
|
|
34
|
-
readonly existsSync: (path: string) => boolean;
|
|
35
34
|
readonly promises: {
|
|
36
35
|
readonly readFile: (path: string) => Promise<Uint8Array>;
|
|
37
36
|
readonly writeFile: (path: string, data: Uint8Array) => Promise<void>;
|
|
@@ -39,6 +38,7 @@ export type Fs = {
|
|
|
39
38
|
readonly rm: (path: string, options?: RmOptions) => Promise<void>;
|
|
40
39
|
readonly mkdir: (path: string, options?: MakeDirectoryOptions) => Promise<string | undefined>;
|
|
41
40
|
readonly copyFile: (src: string, dest: string) => Promise<void>;
|
|
41
|
+
readonly access: (path: string) => Promise<void>;
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
@@ -49,12 +49,6 @@ export type Console = {
|
|
|
49
49
|
readonly log: (...d: unknown[]) => void;
|
|
50
50
|
readonly error: (...d: unknown[]) => void;
|
|
51
51
|
};
|
|
52
|
-
/**
|
|
53
|
-
* Represents an ES module with a default export
|
|
54
|
-
*/
|
|
55
|
-
export type Module = {
|
|
56
|
-
readonly default: unknown;
|
|
57
|
-
};
|
|
58
52
|
/**
|
|
59
53
|
* High-resolution time measurement interface
|
|
60
54
|
* @see https://nodejs.org/api/perf_hooks.html#performance-now
|
|
@@ -118,12 +112,6 @@ export type Io = {
|
|
|
118
112
|
readonly http: Http;
|
|
119
113
|
readonly childProcess: ChildProcess;
|
|
120
114
|
};
|
|
121
|
-
/**
|
|
122
|
-
* The environment variables.
|
|
123
|
-
*/
|
|
124
|
-
export type Env = {
|
|
125
|
-
readonly [k: string]: string | undefined;
|
|
126
|
-
};
|
|
127
115
|
export type App = (io: Io) => Promise<number>;
|
|
128
116
|
export type Run = (f: App) => Promise<never>;
|
|
129
117
|
/**
|
|
@@ -132,4 +120,4 @@ export type Run = (f: App) => Promise<never>;
|
|
|
132
120
|
*/
|
|
133
121
|
export declare const run: (io: Io) => Run;
|
|
134
122
|
export type EffectToPromise = <T>(effect: Effect<NodeOp, T>) => Promise<T>;
|
|
135
|
-
export declare const fromIo: ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile, rm } }, fetch, http: { createServer }, childProcess, }: Io) => EffectToPromise;
|
|
123
|
+
export declare const fromIo: ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, }: Io) => EffectToPromise;
|
package/fs/io/module.f.js
CHANGED
|
@@ -35,9 +35,9 @@ const collect = async (v) => {
|
|
|
35
35
|
}
|
|
36
36
|
return result;
|
|
37
37
|
};
|
|
38
|
-
export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile, rm } }, fetch, http: { createServer }, childProcess, }) => {
|
|
38
|
+
export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile, rm, access } }, fetch, http: { createServer }, childProcess, asyncImport, }) => {
|
|
39
39
|
const result = asyncRun({
|
|
40
|
-
all: async (effects) => await Promise.all(effects.map(result)),
|
|
40
|
+
all: async (...effects) => await Promise.all(effects.map(result)),
|
|
41
41
|
error: async (message) => error(message),
|
|
42
42
|
log: async (message) => log(message),
|
|
43
43
|
fetch: async (url) => tc(async () => {
|
|
@@ -47,13 +47,19 @@ export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readF
|
|
|
47
47
|
}
|
|
48
48
|
return toVec(new Uint8Array(await response.arrayBuffer()));
|
|
49
49
|
}),
|
|
50
|
-
mkdir:
|
|
50
|
+
mkdir: (...p) => tc(async () => { await mkdir(...p); }),
|
|
51
51
|
readFile: path => tc(async () => toVec(await readFile(path))),
|
|
52
|
-
readdir: (
|
|
53
|
-
.map(v => ({
|
|
54
|
-
|
|
52
|
+
readdir: (path, r) => tc(async () => (await readdir(path, { ...r, withFileTypes: true }))
|
|
53
|
+
.map(v => ({
|
|
54
|
+
name: v.name,
|
|
55
|
+
parentPath: normalize(v.parentPath),
|
|
56
|
+
isFile: v.isFile()
|
|
57
|
+
}))),
|
|
58
|
+
writeFile: (path, data) => tc(() => writeFile(path, fromVec(data))),
|
|
55
59
|
rm: path => tc(() => rm(path)),
|
|
56
|
-
|
|
60
|
+
access: path => tc(() => access(path)),
|
|
61
|
+
import: path => tc(() => asyncImport(path)),
|
|
62
|
+
exec: (command, stdin) => new Promise(resolve => {
|
|
57
63
|
const child = childProcess.exec(command, (e, stdout, stderr) => resolve(e !== null ? ['error', e] : ok({ stdout, stderr })));
|
|
58
64
|
child.stdin?.end(stdin);
|
|
59
65
|
}),
|
|
@@ -75,7 +81,7 @@ export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readF
|
|
|
75
81
|
const server = asNominal(createServer(nodeRl));
|
|
76
82
|
return server;
|
|
77
83
|
},
|
|
78
|
-
listen: async (
|
|
84
|
+
listen: async (server, port) => {
|
|
79
85
|
const s = asBase(server);
|
|
80
86
|
s.listen(port);
|
|
81
87
|
},
|
package/fs/io/module.js
CHANGED
|
@@ -48,8 +48,8 @@ export const io = {
|
|
|
48
48
|
export const legacyRun = run(io);
|
|
49
49
|
export const ioRun = (io) => {
|
|
50
50
|
const r = fromIo(io);
|
|
51
|
-
const { argv } = io.process;
|
|
52
|
-
return p => r(p(argv));
|
|
51
|
+
const { argv, env } = io.process;
|
|
52
|
+
return p => r(p(argv, env));
|
|
53
53
|
};
|
|
54
54
|
const effectRun = ioRun(io);
|
|
55
55
|
export default effectRun;
|
|
@@ -6,10 +6,9 @@ export const createVirtualIo = (files) => ({
|
|
|
6
6
|
error: (..._d) => { }
|
|
7
7
|
},
|
|
8
8
|
fs: {
|
|
9
|
-
writeSync: (
|
|
9
|
+
writeSync: (_fd, _s) => { },
|
|
10
10
|
writeFileSync: (_file, _data) => { },
|
|
11
11
|
readFileSync: (path) => { return at(path)(files); },
|
|
12
|
-
existsSync: (path) => { return at(path)(files) !== null; },
|
|
13
12
|
promises: {
|
|
14
13
|
readdir: (_path) => Promise.resolve([]),
|
|
15
14
|
readFile: (_path) => Promise.resolve(new Uint8Array()),
|
|
@@ -17,6 +16,7 @@ export const createVirtualIo = (files) => ({
|
|
|
17
16
|
rm: (_path, _options) => Promise.resolve(),
|
|
18
17
|
mkdir: (_path, _options) => Promise.resolve(undefined),
|
|
19
18
|
copyFile: (_src, _dest) => Promise.resolve(),
|
|
19
|
+
access: (_path) => Promise.resolve(),
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
process: {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { Effect, Operation, Pr } from "../module.f.ts";
|
|
7
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]];
|
|
8
|
+
readonly [K in O[0]]: (state: S, ...payload: Pr<O, K>[0]) => readonly [S, Pr<O, K>[1]];
|
|
9
9
|
};
|
|
10
10
|
export type RunInstance<O extends Operation, S> = (state: S) => <O1 extends O, T>(effect: Effect<O1, T>) => readonly [S, T];
|
|
11
11
|
export declare const run: <O extends Operation, S>(o: MemOperationMap<O, S>) => RunInstance<O, S>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
export type Operation = readonly [string, (_: never) => unknown];
|
|
6
|
+
export type Operation = readonly [string, (..._: readonly never[]) => unknown];
|
|
7
7
|
export type Effect<O extends Operation, T> = {
|
|
8
8
|
value: Value<O, T>;
|
|
9
9
|
step: <Q extends Operation, R>(f: (p: T) => Effect<Q, R>) => Effect<O | Q, R>;
|
|
@@ -11,20 +11,18 @@ export type Effect<O extends Operation, T> = {
|
|
|
11
11
|
export type Value<O extends Operation, T> = Pure<T> | Do<O, T>;
|
|
12
12
|
export type Pure<T> = readonly [T];
|
|
13
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, (
|
|
14
|
+
export type Pr<O extends Operation, K extends O[0]> = O extends readonly [K, (...args: infer P) => infer R] ? readonly [P, R] : never;
|
|
15
15
|
export type DoK<O extends Operation, T, K extends O[0]> = DoKPR<O, T, K, Pr<O, K>>;
|
|
16
16
|
export type Do<O extends Operation, T> = DoK<O, T, O[0]>;
|
|
17
17
|
export declare const pure: <T>(v: T) => Effect<never, T>;
|
|
18
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
19
|
export type Param<O extends Operation> = F<O>[0];
|
|
20
20
|
export type Return<O extends Operation> = F<O>[1];
|
|
21
|
-
export declare const do_: <O extends Operation>(cmd: O[0]) => (param: Param<O>) => Effect<O, Return<O>>;
|
|
22
|
-
export declare const doRest: <O extends Operation>(cmd: O[0]) => (...param: Param<O>) => Effect<O, Return<O>>;
|
|
21
|
+
export declare const do_: <O extends Operation>(cmd: O[0]) => (...param: Param<O>) => Effect<O, Return<O>>;
|
|
23
22
|
export declare const begin: Effect<never, void>;
|
|
24
23
|
export type ToAsyncOperationMap<O extends Operation> = {
|
|
25
|
-
readonly [K in O[0]]: (payload: Pr<O, K>[0]) => Promise<Pr<O, K>[1]>;
|
|
24
|
+
readonly [K in O[0]]: (...payload: Pr<O, K>[0]) => Promise<Pr<O, K>[1]>;
|
|
26
25
|
};
|
|
27
26
|
export type F<O extends Operation> = Pr<O, O[0]>;
|
|
28
|
-
export type Func<O extends Operation> = (_: Param<O>) => Effect<O, Return<O>>;
|
|
29
|
-
export type RestFunc<O extends Operation> = (..._: Param<O>) => Effect<O, Return<O>>;
|
|
27
|
+
export type Func<O extends Operation> = (..._: Param<O>) => Effect<O, Return<O>>;
|
|
30
28
|
export type ListEffect<O extends Operation, T> = Effect<O, readonly [T, ListEffect<O, T>] | undefined>;
|
|
@@ -11,6 +11,5 @@ export const doFull = (cmd, param, cont) => ({
|
|
|
11
11
|
value: [cmd, param, cont],
|
|
12
12
|
step: (f) => doFull(cmd, param, x => cont(x).step(f)),
|
|
13
13
|
});
|
|
14
|
-
export const do_ = (cmd) => (param) => doFull(cmd, param, pure);
|
|
15
|
-
export const doRest = (cmd) => (...param) => do_(cmd)(param);
|
|
14
|
+
export const do_ = (cmd) => (...param) => doFull(cmd, param, pure);
|
|
16
15
|
export const begin = pure(undefined);
|
|
@@ -6,7 +6,7 @@ export const asyncRun = (map) => async (effect) => {
|
|
|
6
6
|
}
|
|
7
7
|
const [command, payload, continuation] = value;
|
|
8
8
|
const operation = map[command];
|
|
9
|
-
const result = await operation(payload);
|
|
9
|
+
const result = await operation(...payload);
|
|
10
10
|
effect = continuation(result);
|
|
11
11
|
}
|
|
12
12
|
};
|