UNPKG

eyereasoner

Version:

Distributing the [EYE](https://github.com/eyereasoner/eye) reasoner for browser and node using WebAssembly.

42 lines (41 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildQuery = buildQuery; exports.qaQuery = qaQuery; exports.query = query; exports.queryOnce = queryOnce; function buildQuery(name, args) { return `${name}(${ /* istanbul ignore next */ typeof args === 'string' ? `"${args}"` : `[${args.map((arg) => `'${arg}'`).join(', ')}]`}).`; } /** * Executes a question/answer query * @param Module The module to execute the query on * @param name The name of the query function * @param args The arguments of the query function * @param cb The callback for question/answering * @returns The result of the query */ async function qaQuery(module, queryString, args, cb) { let res = module.prolog.call(buildQuery(queryString, args), { async: true }); while (!res.done) { // eslint-disable-next-line no-await-in-loop res = res.resume(await cb(res.yield)); } } /** * Executes a query * @param Module The module to execute the query on * @param name The name of the query function * @param args The arguments of the query function * @returns The result of the query */ function query(Module, name, args) { return Module.prolog.query(buildQuery(name, args)); } function queryOnce(Module, name, args) { return query(Module, name, args).once(); }