This library provides TypeScript type definitions and conversion utilities for the IVMS101 (interVASP Messaging Standard) in both its original 2020 version and the updated 2023 version.
- Type definitions for IVMS101 2020 and 2023 versions
- Conversion functions between 2020 and 2023 formats
- Version detection and automatic conversion
- Runtime validation using Zod schemas
npm install ivms101
import { IVMS101, ensureVersion, PayloadVersionCode } from 'ivms101';
import { IVMS101, ensureVersion, PayloadVersionCode } from 'ivms101';
// Assuming you have some IVMS101 data
const ivmsData: IVMS101 = { /* ... */ };
// Convert to 2023 version (default)
const ivms2023 = ensureVersion(ivmsData); // Defaults to 2023 version
// Or explicitly specify version
const ivms2023Explicit = ensureVersion(PayloadVersionCode.V2023, ivmsData);
// Convert to 2020 version
const ivms2020 = ensureVersion(PayloadVersionCode.V2020, ivmsData);
The library provides type definitions for both versions, allowing for type-safe usage in TypeScript projects.
import { IVMS101_2020, IVMS101_2023 } from 'ivms101';
function processIVMS101(data: IVMS101_2020.IVMS101 | IVMS101_2023.IVMS101) {
// Process the data...
}
Use Zod schemas for runtime validation of IVMS101 data:
import {
validateIVMS101,
isValidIVMS101,
isValidIVMS101_2020,
isValidIVMS101_2023,
IVMS101Schema,
IVMS101_2020Schema,
IVMS101_2023Schema
} from 'ivms101';
// Validate and parse data (throws on invalid data)
const validData = validateIVMS101(unknownData);
// Type guards for version checking
if (isValidIVMS101_2020(data)) {
// data is now typed as IVMS101_2020.IVMS101
}
if (isValidIVMS101_2023(data)) {
// data is now typed as IVMS101_2023.IVMS101
}
// Check if data is valid (returns boolean)
const isValid = isValidIVMS101(data);
// Use schemas directly for more control
const result = IVMS101Schema.safeParse(data);
if (result.success) {
console.log('Valid data:', result.data);
} else {
console.log('Validation errors:', result.error.issues);
}
Converts the given IVMS101 data to the specified version. Defaults to 2023 version if no version is specified.
Detects the version of the given IVMS101 data.
Converts IVMS101 2020 data to 2023 format.
Converts IVMS101 2023 data back to 2020 format.
Validates and parses IVMS101 data (either version). Throws a ZodError if validation fails.
Type guard that returns true if data is valid IVMS101 (either version).
Type guard that returns true if data is valid IVMS101 2020 format.
Type guard that returns true if data is valid IVMS101 2023 format.
IVMS101Schema
- Union schema for either versionIVMS101_2020Schema
- Schema for 2020 version onlyIVMS101_2023Schema
- Schema for 2023 version only
These schemas can be used directly with Zod's .parse()
, .safeParse()
, and other methods for more advanced validation scenarios.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.