Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/montferret/ferret-wasm
Ferret compiler and runtime ported to WASM
https://github.com/montferret/ferret-wasm
dsl ferret query-language wasm
Last synced: about 2 months ago
JSON representation
Ferret compiler and runtime ported to WASM
- Host: GitHub
- URL: https://github.com/montferret/ferret-wasm
- Owner: MontFerret
- License: apache-2.0
- Created: 2019-06-04T18:09:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T17:47:40.000Z (almost 2 years ago)
- Last Synced: 2024-04-23T17:07:04.528Z (8 months ago)
- Topics: dsl, ferret, query-language, wasm
- Language: TypeScript
- Size: 366 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ferret-wasm
Ferret compiler and runtime ported to WASM
[![npm version](https://badge.fury.io/js/%40montferret%2Fferret-wasm.svg)](https://badge.fury.io/js/%40montferret%2Fferret-wasm)
[![Build Status](https://secure.travis-ci.org/montferret/ferret-wasm.svg?branch=master)](http://travis-ci.org/montferret/ferret-wasm)## Installation
```sh
npm install @montferret/ferret-wasm
```## Limitations
- Supports only static HTTP driver (Go WASM does not support WebSocket yet)
## Quick start
```javascript
const { create } = require('@montferret/ferret-wasm');async function test() {
const compiler = await create();const out = await compiler.exec(`
FOR i IN 1..10
RETURN i * 2
`);console.log(out); // [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
}test();
``````javascript
const { create } = require('@montferret/ferret-wasm');async function test() {
const compiler = await create();const program = compiler.compile(`
FOR i IN 1..10
RETURN i * @factor
`);const out1 = await program.run({ factor: 2 });
console.log(out1); // [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
const out2 = await program.run({ factor: 3 });
console.log(out2); // [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
// Destroy when you are done with the program
program.destroy();
}test();
```### Function registration
Sync functions
```javascript
const { create } = require('@montferret/ferret-wasm');async function test() {
const compiler = await create();
compiler.register('MY_FUNC', (...args) => {
return args.join('-');
});const out = await compiler.exec(`
RETURN MY_FUNC('foo', 'bar')
`);console.log(out); // foo-bar
}test();
```Async functions
```javascript
const { create } = require('@montferret/ferret-wasm');async function test() {
const compiler = await create();
compiler.register('MY_FUNC', (...args) => {
return new Promise(resolve => {
setTimeout(() => {
resolve(args.join('-'));
}, 10);
});
});const out = await compiler.exec(`
RETURN MY_FUNC('foo', 'bar')
`);console.log(out); // foo-bar
}test();
```