rescript-iof-xml
v0.0.6
Published
IOF XML 3.0 types and parser for ReScript
Readme
rescript-iof-xml
IOF XML 3.0 types and parser for ReScript. Covers CompetitorList, EntryList, StartList, CourseData, ResultList, and EventList document types.
Types and their fields are documented based on the official IOF XML 3.0 XSD. Hover any type or function in your editor to see the relevant XSD documentation.
API docs
Full API reference is available at rescript-iof-xml.pages.dev/api.
Installation
npm install --save-exact rescript-iof-xmlAdd to rescript.json:
{
"dependencies": ["rescript-iof-xml"]
}Usage
let xml = "<EntryList>...</EntryList>"
switch IofXml.EntryList.parse(xml) {
| Ok(entryList) => Console.log(entryList)
| Error(msg) => Console.error(msg)
}TypeScript types
This package also publishes generated TypeScript declarations, so non-ReScript projects can install it and use the exported IOF XML types.
npm install --save-exact rescript-iof-xml @rescript/runtimeThe @rescript/runtime package is required when consuming the generated JavaScript from TypeScript or other non-ReScript projects.
Import runtime functions and types from the public package subpaths:
import {
parse as parseResultList,
serialize as serializeResultList,
} from "rescript-iof-xml/ResultList"
import type {t as ResultList} from "rescript-iof-xml/ResultList"
const parseResultListXml = (xml: string): {ok: true; doc: ResultList} | {ok: false; error: string} => {
const res = parseResultList(xml)
if (res.TAG === "Error") {
return {ok: false, error: res._0}
}
return {ok: true, doc: res._0}
}
const parsed = parseResultListXml("<ResultList>...</ResultList>")
if (parsed.ok) {
const xml = serializeResultList(parsed.doc)
console.log(xml)
}See typescript-iof-xml-validator for a small TypeScript project that verifies the exported declarations. That project is also used as release-level validation for the published package from a TypeScript consumer's perspective.
Highlights
- CourseData — parses full race controls, georeferenced positions, map positions, course-control metadata, class/person/team assignments, and includes
CourseData.resolveCourseControlsfor resolving course references to full controls. - ResultList — parses
PersonResult,TeamResult, andTeamMemberResult(relay).statusfields use typed variant unions (resultStatus,splitTimeStatus,resultListStatus) instead of raw strings. - Multi-race —
PersonResult.resultsis an array (one entry per race leg), andClassResult.coursesis an array. - Organisations —
countryis typed as{code, name}instead of a plain string. - Persons —
sexis a typed variant (Male | Female) with@as("M")/@as("F")for correct wire values. - EventorExtensions — opt-in helper for reading the Eventor-specific data carried in
<Extensions>elements (namespacehttp://eventor.orientering.se/iofxmlextensions) emitted by the Eventor REST API's/.../iofxmlendpoints. CallEventorExtensions.fromElement(eventEl)on any<Event>or<Race>XML element to get a typed record witheventRaceId,startListExists,resultListExists,disciplines(an array — events/races can accommodate multiple),lightConditionandattributes(custom Eventor event attributes, each with anidandvalue).
Runtime XML parser
Parsing uses the standard DOMParser API.
Browsers provide this natively.
Node.js, Cloudflare Workers, and other non-browser runtimes should install or inject a DOMParser-compatible implementation on globalThis.DOMParser before calling parse.
