@jsreport/jsreport-scripts
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -8,5 +8,5 @@ | ||
requires: { | ||
core: '3.x.x', | ||
studio: '3.x.x' | ||
core: '4.x.x', | ||
studio: '4.x.x' | ||
} | ||
} |
@@ -7,2 +7,3 @@ const extend = require('node.extend.without.arrays') | ||
let entityPath | ||
if (script._id) { | ||
@@ -16,4 +17,11 @@ entityPath = await reporter.folders.resolveEntityPath(script, 'scripts', req) | ||
const reqCloneWithNoData = extend(true, {}, _omit(req, 'data')) | ||
const resClone = extend(true, {}, res) | ||
const scriptResponse = await reporter.Response(req.context.id, res) | ||
await scriptResponse.parse(await res.serialize()) | ||
const serializeResponse = scriptResponse.serialize | ||
// we don't expose the serialize to scripts, because it exposes file path of response | ||
// when the output is stream | ||
delete scriptResponse.serialize | ||
const initialContext = { | ||
@@ -26,3 +34,3 @@ __request: { | ||
}, | ||
__response: resClone | ||
__response: scriptResponse | ||
} | ||
@@ -59,3 +67,3 @@ | ||
const executionFn = async ({ topLevelFunctions, restore, context }) => { | ||
const executionFn = async ({ topLevelFunctions, context }) => { | ||
const onBeforeExecute = context.__request.__onBeforeExecute | ||
@@ -100,2 +108,3 @@ delete context.__request.__onBeforeExecute | ||
} | ||
return { | ||
@@ -114,5 +123,3 @@ shouldRunAfterRender: topLevelFunctions.afterRender != null, | ||
}, | ||
// creating new object avoids passing a proxy object to rest of the | ||
// execution flow when script is running in in-process strategy | ||
res: { ...restoredSandbox.__response }, | ||
res: serializeResponse.call(restoredSandbox.__response), | ||
error: err | ||
@@ -119,0 +126,0 @@ ? { |
@@ -138,3 +138,3 @@ /*! | ||
await this.reporter.beforeScriptListeners.fire({ script }, req) | ||
await this.reporter.beforeScriptListeners.fire({ script }, req, res) | ||
@@ -168,26 +168,2 @@ const scriptExecResult = await (require('./executeScript')(this.reporter, { script, method, onBeforeExecute }, req, res)) | ||
function merge (obj, obj2) { | ||
for (const key in obj2) { | ||
if (typeof obj2[key] === 'undefined') { | ||
continue | ||
} | ||
if (Buffer.isBuffer(obj2[key])) { | ||
obj[key] = Buffer.from(obj2[key]) | ||
} else if (Object.prototype.toString.call(obj2[key]) === '[object Uint8Array]') { | ||
let newBuf = Buffer.from(obj2[key].buffer) | ||
if (obj2[key].byteLength !== obj2[key].buffer.byteLength) { | ||
newBuf = newBuf.slice(obj2[key].byteOffset, obj2[key].byteOffset + obj2[key].byteLength) | ||
} | ||
obj[key] = newBuf | ||
} else if (typeof obj2[key] !== 'object' || typeof obj[key] === 'undefined') { | ||
obj[key] = obj2[key] | ||
} else { | ||
merge(obj[key], obj2[key]) | ||
} | ||
} | ||
} | ||
if (method === 'beforeRender') { | ||
@@ -197,9 +173,8 @@ req.data = scriptExecResult.req.data | ||
merge(req, scriptExecResult.req) | ||
merge(res, scriptExecResult.res) | ||
await res.parse(scriptExecResult.res) | ||
} | ||
if (method === 'afterRender') { | ||
res.content = Buffer.from(scriptExecResult.res.content) | ||
delete scriptExecResult.res.content | ||
merge(res, scriptExecResult.res) | ||
await res.parse(scriptExecResult.res) | ||
@@ -358,1 +333,25 @@ req.data = scriptExecResult.req.data | ||
} | ||
function merge (obj, obj2) { | ||
for (const key in obj2) { | ||
if (typeof obj2[key] === 'undefined') { | ||
continue | ||
} | ||
if (Buffer.isBuffer(obj2[key])) { | ||
obj[key] = Buffer.from(obj2[key]) | ||
} else if (Object.prototype.toString.call(obj2[key]) === '[object Uint8Array]') { | ||
let newBuf = Buffer.from(obj2[key].buffer) | ||
if (obj2[key].byteLength !== obj2[key].buffer.byteLength) { | ||
newBuf = newBuf.slice(obj2[key].byteOffset, obj2[key].byteOffset + obj2[key].byteLength) | ||
} | ||
obj[key] = newBuf | ||
} else if (typeof obj2[key] !== 'object' || typeof obj[key] === 'undefined') { | ||
obj[key] = obj2[key] | ||
} else { | ||
merge(obj[key], obj2[key]) | ||
} | ||
} | ||
} |
{ | ||
"name": "@jsreport/jsreport-scripts", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "jsreport extension capable of running custom javascript functions during the rendering process", | ||
@@ -32,8 +32,8 @@ "keywords": [ | ||
"devDependencies": { | ||
"@jsreport/jsreport-assets": "4.0.0", | ||
"@jsreport/jsreport-core": "4.0.0", | ||
"@jsreport/jsreport-assets": "4.1.0", | ||
"@jsreport/jsreport-core": "4.2.0", | ||
"@jsreport/jsreport-jsrender": "4.0.0", | ||
"@jsreport/studio-dev": "3.2.1", | ||
"@jsreport/studio-dev": "4.0.0", | ||
"bluebird": "3.7.2", | ||
"mocha": "5.2.0", | ||
"mocha": "10.1.0", | ||
"should": "13.2.3", | ||
@@ -40,0 +40,0 @@ "standard": "16.0.4" |
@@ -10,2 +10,6 @@ # @jsreport/jsreport-scripts | ||
### 4.1.0 | ||
- internal changes to support new `response.output` api | ||
### 4.0.0 | ||
@@ -12,0 +16,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87800
1298
44