SqCalculator.js (1615B)
1 import * as Result from "../../utility/result.js"; 2 import { SqOtherError } from "../SqError.js"; 3 import { SqLambda } from "./SqLambda.js"; 4 import { wrapValue } from "./index.js"; 5 import { wrapInput } from "./SqInput.js"; 6 export class SqCalculator { 7 constructor(_value, context) { 8 this._value = _value; 9 this.context = context; 10 } 11 run(_arguments, env) { 12 const sqLambda = new SqLambda(this._value.fn, undefined); 13 const response = sqLambda.call(_arguments, env); 14 const newContext = this.context && this.context.extend({ type: "calculator" }); 15 if (!newContext) { 16 return Result.Err(new SqOtherError("Context creation for calculator failed.")); 17 } 18 else if (!response.ok) { 19 return response; 20 } 21 else { 22 return Result.Ok(wrapValue(response.value._value, newContext)); 23 } 24 } 25 get title() { 26 return this._value.title; 27 } 28 get description() { 29 return this._value.description; 30 } 31 get autorun() { 32 return this._value.autorun; 33 } 34 get sampleCount() { 35 return this._value.sampleCount; 36 } 37 get hashString() { 38 const rowData = JSON.stringify(this._value.inputs); 39 const paramData = this._value.fn.toString() || ""; 40 return (rowData + 41 paramData + 42 this._value.description + 43 this._value.title + 44 this._value.autorun + 45 this._value.sampleCount); 46 } 47 get inputs() { 48 return this._value.inputs.map(wrapInput); 49 } 50 } 51 //# sourceMappingURL=SqCalculator.js.map