{"id":17323,"library":"ord-schema","title":"Open Reaction Database Schema (JavaScript)","description":"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.","status":"active","version":"0.4.7","language":"javascript","source_language":"en","source_url":"https://github.com/open-reaction-database/ord-schema","tags":["javascript","typescript"],"install":[{"cmd":"npm install ord-schema","lang":"bash","label":"npm"},{"cmd":"yarn add ord-schema","lang":"bash","label":"yarn"},{"cmd":"pnpm add ord-schema","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for Protocol Buffers message definition and serialization/deserialization.","package":"protobufjs","optional":false}],"imports":[{"note":"Main Protobuf message type for a chemical reaction. It is a named export.","wrong":"import Reaction from 'ord-schema';","symbol":"Reaction","correct":"import { Reaction } from 'ord-schema';"},{"note":"Utility function for schema validation of Reaction messages. Specific named export.","wrong":"import { validate } from 'ord-schema';","symbol":"validateReaction","correct":"import { validateReaction } from 'ord-schema';"},{"note":"Protobuf messages have methods like `toObject()` and `serializeBinary()`. These are instance methods, not top-level exports.","wrong":"import { toObject } from 'ord-schema'; // ... `toObject` is a method on Reaction instances, not a direct export.","symbol":"Reaction.toObject","correct":"import { Reaction } from 'ord-schema'; const reaction = new Reaction(); const obj = reaction.toObject();"}],"quickstart":{"code":"import { Reaction, validateReaction, ReactionMeasurement, Product } from 'ord-schema';\n\nconst reaction = new Reaction();\nreaction.setReactionId('my-unique-reaction-id');\n\nconst measurement = new ReactionMeasurement();\nmeasurement.setOutcome('SUCCESS');\nreaction.addMeasurements(measurement);\n\nconst product = new Product();\nproduct.setReactionProduct('my-product-smiles'); // Example SMILES string\nreaction.addProducts(product);\n\n// Add a textual description\nreaction.setText('A simple example reaction with one product and a success outcome.');\n\n// Validate the reaction object against the schema\ntry {\n  validateReaction(reaction);\n  console.log('Reaction is valid:', reaction.toObject());\n} catch (error) {\n  console.error('Reaction validation failed:', error);\n}\n\n// Example of serializing to binary (for sending over network/saving)\nconst binaryData = reaction.serializeBinary();\nconsole.log(`Serialized reaction to ${binaryData.length} bytes.`);\n\n// Example of deserializing from binary\nconst deserializedReaction = Reaction.deserializeBinary(binaryData);\nconsole.log('Deserialized reaction ID:', deserializedReaction.getReactionId());","lang":"typescript","description":"Demonstrates creating a new Reaction object, populating basic fields, performing client-side validation, and handling Protobuf serialization/deserialization."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":">=0.4.4"},{"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.","message":"Direct 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure `reaction` is an instance of `ord-schema.Reaction`. Instantiate it with `const reaction = new Reaction();` before calling any Protobuf-specific methods.","cause":"Attempting to call Protobuf setter methods on a plain JavaScript object or an uninitialized message.","error":"TypeError: reaction.setReactionId is not a function"},{"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.","cause":"A required field in the ORD schema was not set or was set with an invalid value before calling `validateReaction`.","error":"Error: Reaction validation failed: Error: Reaction.reaction_id is required."},{"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';`.","cause":"Trying to import directly from internal Protobuf-generated paths instead of the main `ord-schema` entry point.","error":"Error: Cannot find module 'ord-schema/proto/ord_pb' or its corresponding type declarations."}],"ecosystem":"npm","meta_description":null}