cloudant / nodejs-cloudant

Cloudant Node.js client library
Apache License 2.0
255 stars 90 forks source link

partitionedFind is not a function #414

Closed playground closed 4 years ago

playground commented 4 years ago

Bug Description

Seems like none of the partition functions are available or do not get transpiled in the resulting js file from typescript.

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

db.find(query, (err, doc)) works fine db.partitionedFind(pid, query, (err, doc)) not working db.partitionInfo(pid) not working

2. What you expected to happen

Would expect db.partitionedFind to be available in the output of js from transpiling typescript code.

3. What actually happened

db.partitionedFind gives error that it is not a function

Environment details

"@cloudant/cloudant": "^4.2.3" node v10

bessbd commented 4 years ago

Hi @playground ,

Thank you for this bug report. Can you please supply steps to reproduce the issue you are currently facing? Perhaps a sample code that results in the error you are describing?

I'm asking, because the following compiles and runs with no errors for me:

import cloudant = require('@cloudant/cloudant');
import nano = require('nano');

const instance = cloudant('http://localhost:5984');
const testdb: cloudant.DocumentScope<{}> = instance.use('testdb');
const doc: nano.MaybeDocument = {
    _id: "part1:testdocid2"
};

testdb.insert(doc, (error, response) => {
    console.log(error, response);
    testdb.partitionInfo("part1", ((error1, response1) => {
        console.log({error1, response1});
        testdb.partitionedFind("part1", {selector: {_id: "testdocid2"}}, (error2, response2) => {
            console.log(error2, response2);
        });
    }));
});
playground commented 4 years ago

It compiled and deployed to IBM cloud function with no errors. However when the cloud function is executed, it threw that error "TypeError: l.db.partitionedFind is not a function"

 let query = {
      "selector": {
        "time": {
          "$gt": time-5,
          "$lt": time+5
        }
      },
      "fields": ["_id", "_rev", "time"],
      "skip": 0,
      "execution_stats": true
    };

db.partitionedFind(pkey, query, (err, doc:any) => {
...
}
bessbd commented 4 years ago

@playground : it's likely that the version of @cloudant/cloudant bundled in Cloud Functions isn't the latest one. It mentions version 3.0.0 in the docs here https://cloud.ibm.com/docs/openwhisk?topic=cloud-functions-runtimes. You can bundle your own npm modules in a zip file on deploy to override

ricellis commented 4 years ago

Closing as not a nodejs-cloudant issue.