functionalscript 0.11.4 → 0.11.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.js
CHANGED
|
@@ -53,14 +53,16 @@ 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
|
createServer: async (requestListener) => {
|
|
56
|
+
const erl = requestListener;
|
|
56
57
|
const nodeRl = async (req, res) => {
|
|
58
|
+
const reqBody = await collect(req);
|
|
57
59
|
const { method, url, headers } = req;
|
|
58
|
-
const { status, headers: outHeaders, body: outBody } =
|
|
60
|
+
const { status, headers: outHeaders, body: outBody } = await result(erl({
|
|
59
61
|
method,
|
|
60
62
|
url,
|
|
61
63
|
headers,
|
|
62
|
-
body: listToVec(
|
|
63
|
-
});
|
|
64
|
+
body: listToVec(reqBody)
|
|
65
|
+
}));
|
|
64
66
|
res
|
|
65
67
|
.writeHead(status, outHeaders)
|
|
66
68
|
.end(fromVec(outBody));
|
|
@@ -72,6 +74,7 @@ export const fromIo = ({ console: { error, log }, fs: { promises: { mkdir, readF
|
|
|
72
74
|
const s = asBase(server);
|
|
73
75
|
s.listen(port);
|
|
74
76
|
},
|
|
77
|
+
forever: () => new Promise(() => { })
|
|
75
78
|
});
|
|
76
79
|
return result;
|
|
77
80
|
};
|
package/package.json
CHANGED
|
@@ -62,13 +62,15 @@ export type ServerResponse = {
|
|
|
62
62
|
readonly headers: Headers;
|
|
63
63
|
readonly body: Vec;
|
|
64
64
|
};
|
|
65
|
-
export type RequestListener = (_: IncomingMessage) => ServerResponse
|
|
66
|
-
export type CreateServer = ['createServer', (_: RequestListener) => Server];
|
|
67
|
-
export declare const createServer:
|
|
65
|
+
export type RequestListener<O extends Operation> = (_: IncomingMessage) => Effect<O, ServerResponse>;
|
|
66
|
+
export type CreateServer = ['createServer', (_: RequestListener<Operation>) => Server];
|
|
67
|
+
export declare const createServer: <O extends Operation>(listener: RequestListener<O>) => Effect<O | CreateServer, Server>;
|
|
68
68
|
export type Listen = ['listen', (_: readonly [Server, number]) => void];
|
|
69
69
|
export declare const listen: RestFunc<Listen>;
|
|
70
70
|
export type Http = CreateServer | Listen;
|
|
71
|
-
export type
|
|
71
|
+
export type Forever = ['forever', () => never];
|
|
72
|
+
export declare const forever: Func<Forever>;
|
|
73
|
+
export type NodeOp = All | Fetch | Console | Fs | Http | Forever;
|
|
72
74
|
export type NodeEffect<T> = Effect<NodeOp, T>;
|
|
73
75
|
export type NodeOperationMap = ToAsyncOperationMap<NodeOp>;
|
|
74
76
|
export type NodeProgram = (argv: readonly string[]) => Effect<NodeOp, number>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { doRest, do_ } from "../module.f.js";
|
|
2
|
+
const doAll = do_('all');
|
|
2
3
|
/**
|
|
3
4
|
* To run the operation `O` should be known by the runner/engine.
|
|
4
5
|
* This is the reason why we merge `O` with `All` in the resulted `Effect`.
|
|
@@ -6,7 +7,7 @@ import { doRest, do_ } from "../module.f.js";
|
|
|
6
7
|
* @param a
|
|
7
8
|
* @returns
|
|
8
9
|
*/
|
|
9
|
-
export const all = (...a) =>
|
|
10
|
+
export const all = (...a) => doAll(a);
|
|
10
11
|
export const both = (a) => (b) => all(a, b);
|
|
11
12
|
export const fetch = do_('fetch');
|
|
12
13
|
export const mkdir = doRest('mkdir');
|
|
@@ -17,3 +18,4 @@ export const error = do_('error');
|
|
|
17
18
|
export const log = do_('log');
|
|
18
19
|
export const createServer = do_('createServer');
|
|
19
20
|
export const listen = doRest('listen');
|
|
21
|
+
export const forever = do_('forever');
|
package/website/module.f.js
CHANGED
|
@@ -7,10 +7,13 @@ import { htmlToString } from "../html/module.f.js";
|
|
|
7
7
|
import { writeFile } from "../types/effects/node/module.f.js";
|
|
8
8
|
import { utf8 } from "../text/module.f.js";
|
|
9
9
|
import { begin, pure } from "../types/effects/module.f.js";
|
|
10
|
-
const html = ['body',
|
|
11
|
-
['a',
|
|
12
|
-
|
|
10
|
+
const html = utf8(htmlToString(['body',
|
|
11
|
+
['a',
|
|
12
|
+
{ href: 'https://github.com/functionalscript/functionalscript' },
|
|
13
|
+
'GitHub Repository'
|
|
14
|
+
]
|
|
15
|
+
]));
|
|
13
16
|
const program = begin
|
|
14
|
-
.step(() => writeFile('index.html',
|
|
17
|
+
.step(() => writeFile('index.html', html))
|
|
15
18
|
.step(() => pure(0));
|
|
16
19
|
export default () => program;
|