@01/as-virtual-code
Advanced tools
Comparing version 0.0.1-alpha5 to 0.0.1-alpha6
@@ -120,2 +120,33 @@ import { JSON } from "assemblyscript-json"; | ||
export class EvaluationPayload { | ||
constructor( | ||
public code: JSON.Obj, | ||
public context: EvaluationContext, | ||
public store: EvaluationStore | ||
) {} | ||
fromJSON(data: JSON.Obj): EvaluationPayload { | ||
if (data.isObj) { | ||
const code: JSON.Obj | null = data.get("code") as JSON.Obj; | ||
const ctxData: JSON.Obj | null = data.get("context") as JSON.Obj; | ||
const storeData: JSON.Obj | null = data.get("store") as JSON.Obj; | ||
if (code != null) { | ||
const context = new EvaluationContext( | ||
ctxData ? ctxData : new JSON.Obj() | ||
); | ||
const store = new EvaluationStore( | ||
storeData ? storeData : new JSON.Obj() | ||
); | ||
return new EvaluationPayload(code, context, store); | ||
} | ||
throw new Error(`Invalid payload, code is null`); | ||
} | ||
throw new Error(`Invalid payload, data not an object`); | ||
} | ||
fromString(data: string): EvaluationPayload { | ||
return this.fromJSON(<JSON.Obj>JSON.parse(data)); | ||
} | ||
} | ||
export function evaluate( | ||
@@ -122,0 +153,0 @@ codeData: string, |
{ | ||
"name": "@01/as-virtual-code", | ||
"description": "JSON Based Virtual Code Evaluator written in AssemblyScript", | ||
"version": "0.0.1-alpha5", | ||
"version": "0.0.1-alpha6", | ||
"types": "assembly/index.ts", | ||
@@ -6,0 +6,0 @@ "private": false, |
151560
4227