hex
✖️Function abstraction framework for better portability between platforms. Write your code once in functional approach, then run on mainstream environments such as cli, bot platforms, cloud-function runtimes and web apis.
This project is in early stages of its development. Descriptions or instructions are not mature yet as well as the project itself.
Functions Roadmap
MVP
-
Basic functions -
Input and context interfaces -
Middlewares -
CLI platform -
Runtime -
Web platform w/ oak - Hypertext format
- Web platform w/ Deno’s http
- Telegram bot platform
Next Milestones
- API Maturity
- AWS Lambda platform
- Knative platform
- Discord bot platform
- Slack bot platform
- Unit and integration testing utilities
- Dockerization
- Manifest files
- Kafka/queue events
- Scheduled events
- Deployments (to cloud providers)
See eser.dev for further development details (in Turkish).
Usage
Basic
import { results, createRuntime, platforms } from "https://deno.land/x/hex/functions/mod.ts";
function main(input) {
const to = input.parameters[0] ?? "world";
const message = `hello ${to}`;
return results.text(message);
}
// will be removed in future versions
// propably will be replaced w/ export
const runtime = createRuntime(platforms.cli);
runtime.execute(main);
With Middlewares
import { composer, results, createRuntime, platforms } from "https://deno.land/x/hex/functions/mod.ts";
function initMiddleware(input, context, next) {
context.vars.number = 1;
return next();
}
function validationMiddleware(input, context, next) {
if (input.parameters[0] === undefined) {
return results.error(
"parameter is not specified",
new Error("parameter is not specified"),
);
}
return next();
}
function main(input, context) {
const message = `hello <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>o</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>x</mi><mi>t</mi><mi mathvariant="normal">.</mi><mi>v</mi><mi>a</mi><mi>r</mi><mi>s</mi><mi mathvariant="normal">.</mi><mi>n</mi><mi>u</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi></mrow><annotation encoding="application/x-tex">{context.vars.number} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord"><span class="mord mathnormal">co</span><span class="mord mathnormal">n</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">a</span><span class="mord mathnormal">rs</span><span class="mord">.</span><span class="mord mathnormal">n</span><span class="mord mathnormal">u</span><span class="mord mathnormal">mb</span><span class="mord mathnormal" style="margin-right:0.02778em;">er</span></span></span></span></span>{input.parameters[0]}`;
return results.text(message);
}
const composed = composer(initMiddleware, validationMiddleware, main);
// will be removed in future versions
// propably will be replaced w/ export
const runtime = createRuntime(platforms.cli);
runtime.execute(composed);
Quick start
Ensure that Deno
is installed on your system first.
Clone this git repo git clone https://github.com/eserozvataf/hex.git
- and checkout the tagged
release you’d like to
use.
Then run a sample file under samples/
directory,
$ deno run samples/functions/cli/basic.ts eser
hello eser
Todo List
See GitHub Projects for more.
Requirements
- Deno (https://deno.land/)
License
Apache 2.0, for further details, please see LICENSE file.
Contributing
See CONTRIBUTING.md for details.
It is publicly open for any contribution. Bugfixes, new features and extra modules are welcome.
- To contribute to code: Fork the repo, push your changes to your fork, and submit a pull request.
- To report a bug: If something does not work, please report it using GitHub Issues.