functionalscript 0.12.5 → 0.12.6
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/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 { ExecResult, Headers, IoResult, NodeOp } 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
|
|
@@ -96,6 +96,9 @@ export type RequestListener = (req: IncomingMessage, res: ServerResponse) => Pro
|
|
|
96
96
|
export type Http = {
|
|
97
97
|
readonly createServer: (_: RequestListener) => Server;
|
|
98
98
|
};
|
|
99
|
+
export type ChildProcess = {
|
|
100
|
+
readonly exec: (command: string) => Promise<IoResult<ExecResult>>;
|
|
101
|
+
};
|
|
99
102
|
/**
|
|
100
103
|
* Core IO operations interface providing access to system resources
|
|
101
104
|
*/
|
|
@@ -109,6 +112,7 @@ export type Io = {
|
|
|
109
112
|
readonly tryCatch: TryCatch;
|
|
110
113
|
readonly asyncTryCatch: <T>(f: () => Promise<T>) => Promise<Result<T, unknown>>;
|
|
111
114
|
readonly http: Http;
|
|
115
|
+
readonly childProcess: ChildProcess;
|
|
112
116
|
};
|
|
113
117
|
/**
|
|
114
118
|
* The environment variables.
|
|
@@ -124,4 +128,4 @@ export type Run = (f: App) => Promise<never>;
|
|
|
124
128
|
*/
|
|
125
129
|
export declare const run: (io: Io) => Run;
|
|
126
130
|
export type EffectToPromise = <T>(effect: Effect<NodeOp, T>) => Promise<T>;
|
|
127
|
-
export declare const fromIo: ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile, rm } }, fetch, http: { createServer }, }: Io) => EffectToPromise;
|
|
131
|
+
export declare const fromIo: ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile, rm } }, fetch, http: { createServer }, childProcess: { exec }, }: Io) => EffectToPromise;
|
package/io/module.f.js
CHANGED
|
@@ -35,7 +35,7 @@ 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 }, }) => {
|
|
38
|
+
export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile, rm } }, fetch, http: { createServer }, childProcess: { exec }, }) => {
|
|
39
39
|
const result = asyncRun({
|
|
40
40
|
all: async (effects) => await Promise.all(effects.map(result)),
|
|
41
41
|
error: async (message) => error(message),
|
|
@@ -53,6 +53,7 @@ export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readF
|
|
|
53
53
|
.map(v => ({ name: v.name, parentPath: normalize(v.parentPath), isFile: v.isFile() }))),
|
|
54
54
|
writeFile: ([path, data]) => tc(() => writeFile(path, fromVec(data))),
|
|
55
55
|
rm: path => tc(() => rm(path)),
|
|
56
|
+
exec,
|
|
56
57
|
createServer: async (requestListener) => {
|
|
57
58
|
const erl = requestListener;
|
|
58
59
|
const nodeRl = async (req, res) => {
|
package/io/module.js
CHANGED
|
@@ -7,6 +7,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
9
|
import http from 'node:http';
|
|
10
|
+
import { exec } from 'node:child_process';
|
|
10
11
|
import { fromIo, run } from "./module.f.js";
|
|
11
12
|
import fs from 'node:fs';
|
|
12
13
|
import process from 'node:process';
|
|
@@ -41,6 +42,9 @@ export const io = {
|
|
|
41
42
|
}
|
|
42
43
|
},
|
|
43
44
|
http,
|
|
45
|
+
childProcess: {
|
|
46
|
+
exec: command => new Promise(resolve => exec(command, (e, stdout, stderr) => resolve(e !== null ? error(e) : ok({ stdout, stderr })))),
|
|
47
|
+
},
|
|
44
48
|
};
|
|
45
49
|
export const legacyRun = run(io);
|
|
46
50
|
export const ioRun = (io) => {
|
package/io/virtual/module.f.js
CHANGED
package/package.json
CHANGED
|
@@ -43,7 +43,13 @@ export type WriteFile = readonly ['writeFile', (_: WriteFileParam) => IoResult<v
|
|
|
43
43
|
export declare const writeFile: RestFunc<WriteFile>;
|
|
44
44
|
export type Rm = readonly ['rm', (_: string) => IoResult<void>];
|
|
45
45
|
export declare const rm: Func<Rm>;
|
|
46
|
-
export type
|
|
46
|
+
export type ExecResult = {
|
|
47
|
+
readonly stdout: string;
|
|
48
|
+
readonly stderr: string;
|
|
49
|
+
};
|
|
50
|
+
export type Exec = readonly ['exec', (_: string) => IoResult<ExecResult>];
|
|
51
|
+
export declare const exec: Func<Exec>;
|
|
52
|
+
export type Fs = Mkdir | ReadFile | Readdir | WriteFile | Rm | Exec;
|
|
47
53
|
export type Error = ['error', (_: string) => void];
|
|
48
54
|
export declare const error: Func<Error>;
|
|
49
55
|
export type Log = ['log', (_: string) => void];
|
|
@@ -15,6 +15,7 @@ export const readFile = do_('readFile');
|
|
|
15
15
|
export const readdir = doRest('readdir');
|
|
16
16
|
export const writeFile = doRest('writeFile');
|
|
17
17
|
export const rm = do_('rm');
|
|
18
|
+
export const exec = do_('exec');
|
|
18
19
|
export const error = do_('error');
|
|
19
20
|
export const log = do_('log');
|
|
20
21
|
export const createServer = do_('createServer');
|
|
@@ -131,6 +131,7 @@ const map = {
|
|
|
131
131
|
readdir: (state, [path, { recursive }]) => readdir(path, recursive === true)(state, path),
|
|
132
132
|
writeFile: (state, [path, payload]) => writeFile(payload)(state, path),
|
|
133
133
|
rm: (state, path) => rm(state, path),
|
|
134
|
+
exec: todo,
|
|
134
135
|
createServer: todo,
|
|
135
136
|
listen: todo,
|
|
136
137
|
forever: todo,
|