Skip to content

postDocument doesn't support ReadableStream for document parameter #1942

@eiri

Description

@eiri

Describe the bug

Documentation indicate that document parameter of postDocument could be Buffer<ArrayBufferLike> | ReadableStream |CloudantV1.Document, but it appears that only the latter is supported.

The issue seems to be that postDocument passes document through CloudantV1.Document.serialize and it fails to pass-through ReadableStream (and Buffer as a matter of fact).

The result that passed in stream got serialized into Document.Transport that includes parameter _events and that fails on DB side with doc_validation error.

To Reproduce

import { CloudantV1 } from '@ibm-cloud/cloudant';

import { createReadStream } from "node:fs";

const service = CloudantV1.newInstance({});

const productsDoc = createReadStream('products_doc.json', { encoding: 'utf8' })

service.postDocument({
  db: 'db',
  contentType: 'application/json',
  document: productsDoc
}).then(response => {
  console.log(response.result);
});
  statusText: 'Bad Request',
  status: 400,
  code: 400,
  result: {
    error: 'doc_validation',
    reason: 'Bad special document member: _events',
    errors: [
      {
        code: 'doc_validation',
        message: 'doc_validation: Bad special document member: _events'
      }
    ],

Expected behavior

postDocument should accept document parameter both as Buffer and ReadableStream and create a new document.

Must gather (please complete the following information):

  • SDK Version 0.12.10
  • Node.js Version v22.15.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions