Skip to content

Conversation

@roadrouting
Copy link

The problem was described in #5742 that the Node.js bindings did not support binary outputs, and they would result in corrupt strings.

This PR adds support for the 6 methods I found that support returning a PBF format.

While I was at it, I:

  • updated the API list (added missing matrix, isochrone, expansion) and added Node.js bindings section to protocol-buffers.md
  • Included the Proto files in the npm package at @valhallajs/valhallajs/proto/

Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this, I've been wanting to do that with the python bindings for a long time, but so far never needed it myself.

I just have a couple of things.

BTW: PBF input is not currently supported for the JS bindings is it?

return worker->GetPromise();
}

Napi::Value CreateAsyncRequestWithFormat(const Napi::CallbackInfo& info,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the need for this function: in the ValhallaAsyncWorker you already have the request available, so you can do the format checking in OnOK() directly?

I also wonder if we couldnt do that in the JS layer where we know the format already (prior to calling C++ Actor) and save ourselves the string -> ptree conversion in the c++ layer. wdyt @roadrouting @SiarheiFedartsou ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was looking for a way to avoid double-parsing the request, but didn't see an easy way on the c++ side. Doing it in the JS layer seems better, so I have done that.

@roadrouting roadrouting force-pushed the 5742-javascript-binary-formats branch from e855e36 to f091b32 Compare December 31, 2025 12:43
@roadrouting
Copy link
Author

@nilsnolde thanks for the quick review! Changes made.

BTW: PBF input is not currently supported for the JS bindings is it?

Correct, this is only for the output

nilsnolde
nilsnolde previously approved these changes Dec 31, 2025
Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for addressing the review!

just a small confusion left what osmc is in the format context, which can probably go.

@nilsnolde
Copy link
Member

The package_nodejs_bindings job was failing because the proto directory
wasn't included in the sparse-checkout, causing the create-package.sh
script to fail when trying to copy proto files for npm distribution.
@roadrouting
Copy link
Author

Thanks! Changes pushed and that should hopefully fix the CI

Add darwin/, linux/, and valhalla_* to package.json files array.
When the files array was introduced in commit 08aee166d, it omitted
the platform-specific binary directories, causing the native bindings
to be excluded from the published package.
@roadrouting
Copy link
Author

@nilsnolde fix pushed for the latest CI failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants