This utility package, `grpc-create-metadata`, provides a straightforward helper function to convert plain JavaScript objects into gRPC `Metadata` instances. It automatically handles type conversion for common primitives like numbers and booleans by calling their `toString()` method, while `Buffer` and `String` values are passed directly. The package is currently at version 4.0.1 and primarily receives updates for dependency maintenance, especially related to its `@grpc/grpc-js` peer dependency. Its core differentiation lies in simplifying the common task of populating `grpc.Metadata` objects, which strictly require string or buffer values, by abstracting the conversion logic, making it easier for developers to work with gRPC services in Node.js. It maintains a stable, albeit infrequent, release cadence driven by underlying gRPC dependency updates and security patches.
npm install grpc-create-metadataVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the 'grpc-create-metadata' utility to transform a plain JavaScript object into a gRPC Metadata object, inspect its contents, and understand its behavior with existing Metadata instances.
Upgrade package to `^3.0.0` (excluding 3.1.0) or `^4.0.0`. For example: `npm install grpc-create-metadata@^4.0.0`.
Verify and update your project's `@grpc/grpc-js` installation to a compatible version, e.g., `npm install @grpc/grpc-js@^1.2.5`.
For complex data types or specific serialization needs, manually convert them to a string (e.g., `JSON.stringify()`) or a Buffer before passing them to `grpc-create-metadata` if the default `toString()` behavior is insufficient.
Validate input object keys to ensure they are valid gRPC metadata keys (e.g., `/^[a-z0-9][a-z0-9_-]*$/`).
Ensure that plain JavaScript objects intended as metadata are first processed by `create()` from `grpc-create-metadata` before being passed to gRPC client calls: `client.someMethod(request, create(myObject))`.
Use the `grpc-create-metadata` utility, which handles `toString()` conversion for non-string/buffer types, or manually convert values to string/buffer before adding them to `grpc.Metadata`.