Registry / serialization / ord-schema

ord-schema

JSON →
library0.6.8jsnpmunverified

The `ord-schema` package provides JavaScript and TypeScript wrappers for interacting with the Open Reaction Database (ORD) schema. The ORD project standardizes the representation of chemical reaction data, facilitating data exchange, analysis, and machine learning applications within the chemistry domain. This library offers client-side tools, primarily built on Protocol Buffers (protobuf), to create, manipulate, and validate reaction data according to the ORD specification. Currently at version 0.4.7, the package has a consistent release cadence, often addressing internal tooling, dependency updates (like Protobuf), and minor bug fixes. Its core differentiator lies in enabling structured, interoperable chemical reaction data handling.

npm install ord-schema
INSTALL
IMPORT
SIG · ORD-SCHEMA
O
ord-schema
serializationjavascriptv0.6.8
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Reaction
import { Reaction } from 'ord-schema';
import Reaction from 'ord-schema';
Main Protobuf message type for a chemical reaction. It is a named export.
validateReaction
import { validateReaction } from 'ord-schema';
import { validate } from 'ord-schema';
Utility function for schema validation of Reaction messages. Specific named export.
Reaction.toObject
import { Reaction } from 'ord-schema'; const reaction = new Reaction(); const obj = reaction.toObject();
import { toObject } from 'ord-schema'; // ... `toObject` is a method on Reaction instances, not a direct export.
Protobuf messages have methods like `toObject()` and `serializeBinary()`. These are instance methods, not top-level exports.

Demonstrates creating a new Reaction object, populating basic fields, performing client-side validation, and handling Protobuf serialization/deserialization.

import { Reaction, validateReaction, ReactionMeasurement, Product } from 'ord-schema'; const reaction = new Reaction(); reaction.setReactionId('my-unique-reaction-id'); const measurement = new ReactionMeasurement(); measurement.setOutcome('SUCCESS'); reaction.addMeasurements(measurement); const product = new Product(); product.setReactionProduct('my-product-smiles'); // Example SMILES string reaction.addProducts(product); // Add a textual description reaction.setText('A simple example reaction with one product and a success outcome.'); // Validate the reaction object against the schema try { validateReaction(reaction); console.log('Reaction is valid:', reaction.toObject()); } catch (error) { console.error('Reaction validation failed:', error); } // Example of serializing to binary (for sending over network/saving) const binaryData = reaction.serializeBinary(); console.log(`Serialized reaction to ${binaryData.length} bytes.`); // Example of deserializing from binary const deserializedReaction = Reaction.deserializeBinary(binaryData); console.log('Deserialized reaction ID:', deserializedReaction.getReactionId());
Debug
Known issues
breakingThe underlying `protobuf` dependency was updated from `v4` to `v5` in `ord-schema@0.4.4`. While efforts are made to ensure backward compatibility for generated code, direct usage of `protobufjs` APIs or interaction with other libraries that strictly depend on `protobufjs@4` might lead to unexpected behavior or dependency conflicts.
fix
Review your `package.json` for other `protobufjs` dependencies. If conflicts arise, consider upgrading other dependencies or using package manager overrides if possible. Thoroughly test your application after upgrading `ord-schema` to version `0.4.4` or later.
affects: >=0.4.4
gotchaDirect modification of Protobuf message objects returned by `get*()` methods (e.g., `reaction.getMeasurements()`) can lead to unexpected behavior or state management issues, as these often return references. Use `add*()` or `set*()` methods for collections, or create new instances for nested objects.
fix
Always use the provided setters (`set*`, `add*`) to modify Protobuf message fields. For example, instead of `reaction.getMeasurements()[0].setOutcome('FAILURE')`, create a new `ReactionMeasurement` or ensure you're modifying a detached copy if complex manipulation is needed.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: reaction.setReactionId is not a function
Attempting to call Protobuf setter methods on a plain JavaScript object or an uninitialized message.
fix
Ensure `reaction` is an instance of `ord-schema.Reaction`. Instantiate it with `const reaction = new Reaction();` before calling any Protobuf-specific methods.
Error: Reaction validation failed: Error: Reaction.reaction_id is required.
A required field in the ORD schema was not set or was set with an invalid value before calling `validateReaction`.
fix
Consult the ORD schema documentation for the specific message type (e.g., `Reaction`) to identify all required fields and their expected data types. Ensure all mandatory fields are populated correctly before validation.
Error: Cannot find module 'ord-schema/proto/ord_pb' or its corresponding type declarations.
Trying to import directly from internal Protobuf-generated paths instead of the main `ord-schema` entry point.
fix
Most common symbols like `Reaction`, `validateReaction`, etc., are re-exported directly from the root `ord-schema` package. Use `import { Reaction } from 'ord-schema';` instead of `import { Reaction } from 'ord-schema/proto/ord_pb';`.
Upgrade
Version history
0.6.8latest on npm
Audit
Dependencies
protobufjsrequiredUsed for Protocol Buffers message definition and serialization/deserialization.
Agent activity
4 hits · last 30 days
node
4
Resources
ord-schema — npm install ord-schema · libregistry