functionalscript 0.12.4 → 0.12.5
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/ci/module.f.js +1 -1
- package/io/module.f.d.ts +1 -1
- package/io/module.f.js +2 -1
- package/package.json +1 -1
- package/types/effects/node/module.f.d.ts +3 -1
- package/types/effects/node/module.f.js +1 -0
- package/types/effects/node/test.f.d.ts +6 -0
- package/types/effects/node/test.f.js +55 -1
- package/types/effects/node/virtual/module.f.js +16 -0
package/ci/module.f.js
CHANGED
|
@@ -69,7 +69,7 @@ const node = (version) => (extra) => basicNode(version)([
|
|
|
69
69
|
const findTgz = (v) => v === 'windows' ? '(Get-ChildItem *.tgz).FullName' : './*.tgz';
|
|
70
70
|
const playwrightVersion = '1.58.2';
|
|
71
71
|
const playwrightAndVersion = `playwright@${playwrightVersion}`;
|
|
72
|
-
const rustToolchain = '1.
|
|
72
|
+
const rustToolchain = '1.94.1';
|
|
73
73
|
const toSteps = (m) => {
|
|
74
74
|
const filter = (st) => m.flatMap((mt) => mt.type === st ? [mt.step] : []);
|
|
75
75
|
const aptGet = m.flatMap(v => v.type === 'apt-get' ? [v.package] : []).join(' ');
|
package/io/module.f.d.ts
CHANGED
|
@@ -124,4 +124,4 @@ export type Run = (f: App) => Promise<never>;
|
|
|
124
124
|
*/
|
|
125
125
|
export declare const run: (io: Io) => Run;
|
|
126
126
|
export type EffectToPromise = <T>(effect: Effect<NodeOp, T>) => Promise<T>;
|
|
127
|
-
export declare const fromIo: ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile } }, fetch, http: { createServer }, }: Io) => EffectToPromise;
|
|
127
|
+
export declare const fromIo: ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile, rm } }, fetch, http: { createServer }, }: 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 } }, fetch, http: { createServer }, }) => {
|
|
38
|
+
export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readFile, readdir, writeFile, rm } }, fetch, http: { createServer }, }) => {
|
|
39
39
|
const result = asyncRun({
|
|
40
40
|
all: async (effects) => await Promise.all(effects.map(result)),
|
|
41
41
|
error: async (message) => error(message),
|
|
@@ -52,6 +52,7 @@ export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readF
|
|
|
52
52
|
readdir: ([path, r]) => tc(async () => (await readdir(path, { ...r, withFileTypes: true }))
|
|
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
|
+
rm: path => tc(() => rm(path)),
|
|
55
56
|
createServer: async (requestListener) => {
|
|
56
57
|
const erl = requestListener;
|
|
57
58
|
const nodeRl = async (req, res) => {
|
package/package.json
CHANGED
|
@@ -41,7 +41,9 @@ export declare const readdir: RestFunc<Readdir>;
|
|
|
41
41
|
export type WriteFileParam = readonly [string, Vec];
|
|
42
42
|
export type WriteFile = readonly ['writeFile', (_: WriteFileParam) => IoResult<void>];
|
|
43
43
|
export declare const writeFile: RestFunc<WriteFile>;
|
|
44
|
-
export type
|
|
44
|
+
export type Rm = readonly ['rm', (_: string) => IoResult<void>];
|
|
45
|
+
export declare const rm: Func<Rm>;
|
|
46
|
+
export type Fs = Mkdir | ReadFile | Readdir | WriteFile | Rm;
|
|
45
47
|
export type Error = ['error', (_: string) => void];
|
|
46
48
|
export declare const error: Func<Error>;
|
|
47
49
|
export type Log = ['log', (_: string) => void];
|
|
@@ -14,6 +14,7 @@ export const mkdir = doRest('mkdir');
|
|
|
14
14
|
export const readFile = do_('readFile');
|
|
15
15
|
export const readdir = doRest('readdir');
|
|
16
16
|
export const writeFile = doRest('writeFile');
|
|
17
|
+
export const rm = do_('rm');
|
|
17
18
|
export const error = do_('error');
|
|
18
19
|
export const log = do_('log');
|
|
19
20
|
export const createServer = do_('createServer');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { empty, isVec, uint, vec8 } from "../../bit_vec/module.f.js";
|
|
2
2
|
import { pure } from "../module.f.js";
|
|
3
|
-
import { fetch, mkdir, readdir, readFile, writeFile } from "./module.f.js";
|
|
3
|
+
import { fetch, mkdir, readdir, readFile, rm, writeFile } from "./module.f.js";
|
|
4
4
|
import { emptyState, virtual } from "./virtual/module.f.js";
|
|
5
5
|
export default {
|
|
6
6
|
map: () => {
|
|
@@ -272,4 +272,58 @@ export default {
|
|
|
272
272
|
}
|
|
273
273
|
},
|
|
274
274
|
},
|
|
275
|
+
rm: {
|
|
276
|
+
one: () => {
|
|
277
|
+
const [state, [t, result]] = virtual({
|
|
278
|
+
...emptyState,
|
|
279
|
+
root: { hello: vec8(0x2an) },
|
|
280
|
+
})(rm('hello'));
|
|
281
|
+
if (t !== 'ok') {
|
|
282
|
+
throw result;
|
|
283
|
+
}
|
|
284
|
+
if (state.root.hello !== undefined) {
|
|
285
|
+
throw state.root;
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
nested: () => {
|
|
289
|
+
const [state, [t, result]] = virtual({
|
|
290
|
+
...emptyState,
|
|
291
|
+
root: { tmp: { cache: vec8(0x15n) } },
|
|
292
|
+
})(rm('tmp/cache'));
|
|
293
|
+
if (t !== 'ok') {
|
|
294
|
+
throw result;
|
|
295
|
+
}
|
|
296
|
+
const tmp = state.root.tmp;
|
|
297
|
+
if (tmp === undefined || isVec(tmp)) {
|
|
298
|
+
throw state.root;
|
|
299
|
+
}
|
|
300
|
+
if (tmp.cache !== undefined) {
|
|
301
|
+
throw tmp;
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
noSuchFile: () => {
|
|
305
|
+
const [_, [t, result]] = virtual(emptyState)(rm('hello'));
|
|
306
|
+
if (t !== 'error') {
|
|
307
|
+
throw result;
|
|
308
|
+
}
|
|
309
|
+
if (result !== 'no such file') {
|
|
310
|
+
throw result;
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
isDirectory: () => {
|
|
314
|
+
const [state, [t, result]] = virtual({
|
|
315
|
+
...emptyState,
|
|
316
|
+
root: { tmp: {} },
|
|
317
|
+
})(rm('tmp'));
|
|
318
|
+
if (t !== 'error') {
|
|
319
|
+
throw result;
|
|
320
|
+
}
|
|
321
|
+
if (result !== 'invalid path') {
|
|
322
|
+
throw result;
|
|
323
|
+
}
|
|
324
|
+
if (state.root.tmp === undefined) {
|
|
325
|
+
throw state.root;
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
},
|
|
275
329
|
};
|
|
@@ -94,6 +94,21 @@ const readdir = (base, recursive) => readOperation((dir, path) => {
|
|
|
94
94
|
};
|
|
95
95
|
return ok(f(base, dir));
|
|
96
96
|
});
|
|
97
|
+
const rm = operation((dir, path) => {
|
|
98
|
+
if (path.length !== 1) {
|
|
99
|
+
return [dir, error('invalid path')];
|
|
100
|
+
}
|
|
101
|
+
const [name] = path;
|
|
102
|
+
const entry = dir[name];
|
|
103
|
+
if (entry === undefined) {
|
|
104
|
+
return [dir, error('no such file')];
|
|
105
|
+
}
|
|
106
|
+
if (!isVec(entry)) {
|
|
107
|
+
return [dir, error('is a directory')];
|
|
108
|
+
}
|
|
109
|
+
const { [name]: _, ...rest } = dir;
|
|
110
|
+
return [rest, okVoid];
|
|
111
|
+
});
|
|
97
112
|
const console = (name) => (state, payload) => [{ ...state, [name]: `${state[name]}${payload}\n` }, undefined];
|
|
98
113
|
const map = {
|
|
99
114
|
all: (state, a) => {
|
|
@@ -115,6 +130,7 @@ const map = {
|
|
|
115
130
|
readFile,
|
|
116
131
|
readdir: (state, [path, { recursive }]) => readdir(path, recursive === true)(state, path),
|
|
117
132
|
writeFile: (state, [path, payload]) => writeFile(payload)(state, path),
|
|
133
|
+
rm: (state, path) => rm(state, path),
|
|
118
134
|
createServer: todo,
|
|
119
135
|
listen: todo,
|
|
120
136
|
forever: todo,
|