mozithermodb-settings
v1.1.4
Published
Shared TypeScript schemas and type definitions for thermodynamic models, units, and components used across the Mozi ecosystem. Provides strong typing and optional runtime validation for temperature, pressure, phase, and chemical component data.
Readme
MoziThermoDB-Settings
Shared TypeScript schemas, types, and utility functions for thermodynamic components and mixture identifiers in the Mozi ecosystem.
Features
- Zod schemas for temperature, pressure, volume, and custom properties
- Zod schemas and inferred types for thermodynamic components
- Consistent component identifier helpers
- Deterministic binary and multi-component mixture ID creation
- Component state setters with in-place mutation parity for interop scenarios
- ESM, CJS, browser, and
.d.tsoutputs
Installation
npm install mozithermodb-settingsQuick Start
import {
ComponentSchema,
TemperatureSchema,
create_component_id,
create_mixture_id,
set_component_state,
} from "mozithermodb-settings";
const water = ComponentSchema.parse({
name: " Water ",
formula: " H2O ",
state: "l",
});
const temperature = TemperatureSchema.parse({
value: 298.15,
unit: "K",
source: "lab", // passthrough extra property
});
const identity = create_component_id(water);
// { name_state: "Water-l", formula_state: "H2O-l", name_formula: "Water-H2O" }
const mixture = create_mixture_id(
[
water,
{ name: "Ethanol", formula: "C2H5OH", state: "l" },
{ name: "Methanol", formula: "CH3OH", state: "l" },
],
"Name",
);
// "Ethanol|Methanol|Water"
set_component_state(water, "g"); // mutates same object referenceAPI
Condition Schemas
TemperatureSchemaPressureSchemaVolumeSchemaCustomPropSchema
All condition schemas are z.looseObject(...), so unknown keys are preserved.
Component Schemas and Types
ComponentStateSchema:"g" | "l" | "s" | "aq"ComponentKeySchema:"Name-State""Formula-State""Name-Formula""Name""Formula""Name-Formula-State""Formula-Name-State"
MixtureKeySchema: same asComponentKeySchemaBinaryMixtureKeySchema:"Name" | "Formula"ComponentSchema:name: stringformula: stringstate: ComponentStatemole_fraction: number(default:1)
ComponentIdentitySchema:name_state: stringformula_state: stringname_formula: string
Inferred TypeScript exports:
Temperature,Pressure,Volume,CustomPropComponentState,ComponentKey,MixtureKey,BinaryMixtureKeyComponent,ComponentInput,ComponentIdentity
Utility Functions
create_component_id(component, separator_symbol?)- Returns
{ name_state, formula_state, name_formula } - Trims fields and normalizes
stateto lowercase in state-based identifiers
- Returns
set_component_id(component, component_key, separator_symbol?, case_value?)- Returns a string identifier for a selected key format
case_valueis"lower" | "upper" | null
create_binary_mixture_id(component_1, component_2, mixture_key?, delimiter?)- Supports
mixture_key:"Name"or"Formula" - Sorts component IDs before joining, so ordering is deterministic
- Supports
create_mixture_id(components, mixture_key?, delimiter?, case_value?)- Supports all
MixtureKeySchemakey styles - Sorts component IDs before joining
- Throws if
componentsis empty
- Supports all
set_component_state(component, state)- Validates and mutates the original input object reference
set_components_state(components, state)- Applies
set_component_stateto each item
- Applies
Errors
The package exports ERRORS from src/core/errors.ts for consistent error messages around:
- invalid component key
- invalid case value
- invalid mixture key
- empty component list
- delimiter type mismatch
Deterministic ID Behavior
Mixture ID helpers always sort generated component identifiers before joining with a delimiter:
- Binary:
[id1, id2].sort().join(delimiter) - Multi-component:
ids.sort().join(delimiter)
This guarantees stable IDs independent of input order.
Build and Test
npm run build
npm run typecheck
npm run lint
npm testPackage outputs:
dist/index.mjs(ESM)dist/index.cjs(CommonJS)dist/index.browser.mjs(browser ESM)dist/index.d.ts(types)
Example Script
See examples/exp-1.ts for a complete end-to-end usage sample covering:
- schema parsing
- component defaults
- component and mixture IDs
- state updates
License
Apache-2.0
