yfinkelstein / node-zookeeper

node.js client for Apache Zookeeper
MIT License
479 stars 111 forks source link

Incorrect type on the .get method #304

Closed Stono closed 2 years ago

Stono commented 2 years ago

Describe the bug The type definition for get is:

(method) ZooKeeperPromise.get(path: string, watch: boolean): Promise<string | Buffer>
@param path

@param watch

@fulfill — {string|Buffer}

@returns

Which indicates a string or a buffer response, however what we actually get back is:

[
  {
    czxid: 287762809020,
    mzxid: 481036345231,
    pzxid: 287762809020,
    dataLength: 28,
    numChildren: 0,
    version: 2,
    cversion: 0,
    aversion: 0,
    ctime: 2021-06-11T09:02:01.479Z,
    mtime: 2021-11-08T18:09:21.176Z,
    ephemeralOwner: '0',
    createdInThisSession: false
  },
  <Buffer 4c 2f 32 6b 69 70 36 35 42 6b 48 4c 6e 6a 4e 52 32 74 77 37 35 68 51 4f 33 74 49 3d>
]

Which is an array, looks like the actual value is in response[0] - so shouldn't the return type be like, [ZKMetadata?, string | Buffer] ?

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

DavidVujic commented 2 years ago

Thank you for reporting @Stono !

Yes, the docs seem to be incorrect. Looks like the first part is an array of stat objects (https://github.com/yfinkelstein/node-zookeeper/blob/master/lib/typedefs.js#L11).

I'll have a look!

Stono commented 2 years ago

No problemo - glad it wasn't user error haha

DavidVujic commented 2 years ago

I couldn't really figure out how to specify the actual types in an array, so I went for a "array of any" with additional doc string. I hope this will solve it 😄