sqrl-cli-functions
Version:
SQRL (A Safe, Stateful Rules Language for Event Streams) - functions intended for command line tools
59 lines (58 loc) • 2.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerSourceFunction = void 0;
const sqrl_1 = require("sqrl");
function registerSourceFunction(instance) {
instance.registerSync(function allSource(state, props = {}) {
return state.sourcePrinter.getHumanAllSource(props);
}, {
args: [sqrl_1.AT.state, sqrl_1.AT.any.optional],
argstring: "",
docstring: "Returns all of the source code for this execution",
});
instance.registerSync(function featureSource(state, featureName, props = {}) {
return state.getSourcePrinter().getSourceForSlotName(featureName, props);
}, {
args: [sqrl_1.AT.state, sqrl_1.AT.constant.string, sqrl_1.AT.any.optional],
argstring: "feature",
docstring: "Returns the source code for the given feature",
});
instance.registerStatement("SqrlLogStatements", async function _printSource(state, featureName) {
console.log(state.getSourcePrinter().getSourceForSlotName(featureName));
}, {
args: [sqrl_1.AT.state, sqrl_1.AT.constant.string.optional],
});
instance.registerStatement("SqrlLogStatements", async function printAllSource(state) {
state.getSourcePrinter().printAllSource();
}, {
args: [sqrl_1.AT.state],
argstring: "",
docstring: "Prints the SQRL execution source",
});
instance.registerTransform(function printSource(state, ast) {
const arg = ast.args[0];
if (arg.type !== "feature") {
throw new Error("Expected feature arguments");
}
return sqrl_1.AstBuilder.call("_printSource", [sqrl_1.AstBuilder.constant(arg.value)]);
}, {
args: [sqrl_1.AT.feature],
argstring: "feature",
docstring: "Prints the SQRL source of the given feature",
});
instance.registerTransform(function source(state, ast) {
const feature = ast.args[0];
if (feature.type !== "feature") {
throw new Error("Expected feature argument");
}
return sqrl_1.AstBuilder.call("featureSource", [
sqrl_1.AstBuilder.constant(feature.value),
...ast.args.slice(1),
]);
}, {
args: [sqrl_1.AT.feature, sqrl_1.AT.any.optional],
argstring: "feature",
docstring: "Returns the source code of the given feature",
});
}
exports.registerSourceFunction = registerSourceFunction;