This package allows developers to compile raw Kuneiform code in Browser and NodeJS applications.
The Kuneiform Parser parses raw Kuneiform to JSON, which can be used to deploy a database on Kwil with the Kwil-JS SDK. This is an alternative to using the Kuneiform IDE or Kwil CLI to deploy a database on Kwil.
This package downloads the latest production-version WASM binary from the Kuneifrom Release Repo, instantiate the binary, and calls the .parseKuneiform method. Please note the size of the WASM binary (~10 mb) and account for how that may affect your application.
npm i kuneiform-parser
The parser has a slightly different initialization depending on NodeJs or Browser.
Within the .load()
method in both the WebParser
and NodeParser
classes, you can pass an optional configuration option. If using WebParser
, you should pass a CORS proxy, otherwise your browser will block the WASM Download.
const nodeConfig: NodeConfig = {
cacheTtl?: number, // optional number of seconds for the WASM file to be cached. Default is 1 day.
logger?: (msg: string) => void // optional a logging function to capture all logs
}
const webConfig: WebConfig = {
corsProxyUrl: string // URL for CORS proxy
cacheTtl?: number, // same as node
logger?: (msg: string) => void // same as node
}
import { WebParser, WebConfig} from 'kuneiform-parser';
const config: WebParserConfig = {
corsProxyUrl: 'https://cors-anywhere.herokuapp.com/'
};
async function parse() {
const parser = await WebParser.load(config);
}
import { NodeParser } from 'kuneiform-parser';
async function loadParser() {
const parser = await NodeParser.load(config);
}
Once the parser has loaded, you can call .parse()
to parse your raw Kuneiform to JSON.
import { NodeParser, ParseRes } from 'kuneiform-parser';
import kuneiform from 'some_kf_file.kf';
async function loadParser() {
/* previous code */
const res = await parser.parse<ParseRes>(kuneiform)
/*
res = {
json: Stringified<KuneiformObject>
}
*/
}
And that is it! The json
property that is returned can be passed to the KwilJS DBBuilder Payload to create a database on the Kwil Network.
- Kwil JS: https://www.npmjs.com/package/kwil
- Kwil Docs: https://docs.kwil.com/
- Kuneiform IDE: https://ide.kwil.com/
MIT License
Any questions and or feedback is welcomed in the Kwil Discord or to [email protected].