@jsreport/jsreport-core 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -282,6 +282,11 @@ jsreport.documentStore.collection('templates')
282
282
 
283
283
  ## Changelog
284
284
 
285
+ ### 4.2.0
286
+
287
+ - the response object has new structure and api, the `response.output` is new addition and contains different methods to work with the response output. the `response.content`, `response.stream` are now soft deprecated (will be removed in future versions)
288
+ - the internal architecture has been updated to support working with template content and report output as streams, this means that the render will be able to handle and produce bigger reports without getting hit by out of memory errors
289
+
285
290
  ### 4.1.0
286
291
 
287
292
  - update deps to fix npm audit
@@ -61,7 +61,7 @@ module.exports = (reporter, requestId, obj) => {
61
61
  return
62
62
  }
63
63
 
64
- if (isReadableStream(bufOrStreamOrPath)) {
64
+ if (isNodeReadableStream(bufOrStreamOrPath) || isWebReadableStream(bufOrStreamOrPath)) {
65
65
  if (outputImpl instanceof BufferOutput) {
66
66
  outputImpl = new StreamOutput(reporter, requestId)
67
67
  }
@@ -108,7 +108,7 @@ class BufferOutput {
108
108
  }
109
109
 
110
110
  setBuffer (buf) {
111
- // we need to ensure that the buffer is an actually buffer instance,
111
+ // we need to ensure that the buffer is a buffer instance,
112
112
  // so when receiving Uint8Array we convert it to a buffer
113
113
  this.buffer = Buffer.isBuffer(buf) ? buf : Buffer.from(buf)
114
114
  }
@@ -198,8 +198,11 @@ class StreamOutput {
198
198
  }
199
199
 
200
200
  async setStream (stream) {
201
+ // we need to ensure that the stream used in pipeline is node.js readable stream instance,
202
+ // so when receiving Web ReadableStream we convert it to node.js readable stream
203
+ const inputStream = isNodeReadableStream(stream) ? stream : Readable.fromWeb(stream)
201
204
  const { stream: responseFileStream } = await this.reporter.writeTempFileStream(this.filename)
202
- await pipeline(stream, responseFileStream)
205
+ await pipeline(inputStream, responseFileStream)
203
206
  }
204
207
 
205
208
  serialize () {
@@ -220,12 +223,27 @@ class StreamOutput {
220
223
  }
221
224
 
222
225
  // from https://github.com/sindresorhus/is-stream/blob/main/index.js
223
- function isReadableStream (stream) {
226
+ function isNodeReadableStream (stream) {
224
227
  return (
225
228
  stream !== null &&
226
229
  typeof stream === 'object' &&
227
230
  typeof stream.pipe === 'function' &&
228
- stream.readable !== false && typeof stream._read === 'function' &&
229
- typeof stream._readableState === 'object'
231
+ typeof stream.read === 'function' &&
232
+ typeof stream.readable === 'boolean' &&
233
+ typeof stream.readableObjectMode === 'boolean' &&
234
+ typeof stream.destroy === 'function' &&
235
+ typeof stream.destroyed === 'boolean'
236
+ )
237
+ }
238
+
239
+ function isWebReadableStream (stream) {
240
+ return (
241
+ stream !== null &&
242
+ typeof stream === 'object' &&
243
+ typeof stream.locked === 'boolean' &&
244
+ typeof stream.cancel === 'function' &&
245
+ typeof stream.getReader === 'function' &&
246
+ typeof stream.pipeTo === 'function' &&
247
+ typeof stream.pipeThrough === 'function'
230
248
  )
231
249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsreport/jsreport-core",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "javascript based business reporting",
5
5
  "keywords": [
6
6
  "report",