Use bson library to parse to json
This commit is contained in:
parent
405de459ce
commit
0ea7a515de
File diff suppressed because one or more lines are too long
|
@ -1 +1,4 @@
|
||||||
|
import { EJSON } from "bson"
|
||||||
|
|
||||||
export { deserialize } from "bson"
|
export { deserialize } from "bson"
|
||||||
|
export const toJson = EJSON.deserialize
|
||||||
|
|
|
@ -26,8 +26,8 @@ class ScriptRunner {
|
||||||
// 1. Serialise the data from potential BSON to buffer before passing it to the isolate
|
// 1. Serialise the data from potential BSON to buffer before passing it to the isolate
|
||||||
// 2. Deserialise the data within the isolate, to get the original data
|
// 2. Deserialise the data within the isolate, to get the original data
|
||||||
// 3. Process script
|
// 3. Process script
|
||||||
// 4. Stringify and parse result in order to convert the result from BSON to json
|
// 4. Stringify the result in order to convert the result from BSON to json
|
||||||
script = `return JSON.parse(JSON.stringify((function(){data=deserialize(data).data;${script}})()));`
|
script = `return toJson((function(){data=deserialize(data, { validation: { utf8: true } }).data;${script}})());`
|
||||||
}
|
}
|
||||||
|
|
||||||
this.vm.code = script
|
this.vm.code = script
|
||||||
|
@ -93,7 +93,7 @@ class IsolatedVM {
|
||||||
set code(code: string) {
|
set code(code: string) {
|
||||||
code = `const fn=function(){${code}};results.out=fn();`
|
code = `const fn=function(){${code}};results.out=fn();`
|
||||||
if (this.#bsonModule) {
|
if (this.#bsonModule) {
|
||||||
code = `import {deserialize} from "compiled_module";${code}`
|
code = `import {deserialize, toJson} from "compiled_module";${code}`
|
||||||
}
|
}
|
||||||
this.#script = this.#isolate.compileModuleSync(code)
|
this.#script = this.#isolate.compileModuleSync(code)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue