functionalscript 0.11.5 → 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));
|
package/package.json
CHANGED
|
@@ -62,9 +62,9 @@ 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;
|
|
@@ -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');
|
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;
|