@stele-climbing/stele1-datatypes
v0.0.2
Published
core datatypes for stele1 catalogs
Maintainers
Readme
@stele-climbing/stele1-datatypes
Core datatypes for stele1 catalogs.
Covers Metadata, Climb, Area, Photo, Parking, and Trail.
See the stele1 spec for the data model these implement.
Each datatype validates its input and exposes fromData / toData for serialization to and from plain JSON.
Invalid input throws.
This package is ESM-only.
Use
import { Climb } from '@stele-climbing/stele1-datatypes';
// from existing data
const climb = Climb.fromData({
uuid: '550e8400-e29b-41d4-a716-446655440000',
name: 'The Mandala',
rating: { difficulty: 'V12' },
});
// or built up directly
const other = new Climb('123e4567-e89b-42d3-a456-426614174000')
.setName('Evilution')
.setRating({ difficulty: 'V12' });
climb.getName(); // 'The Mandala'
climb.setName('The Mandala Direct');
climb.dropRating(); // remove an attribute
climb.toData(); // plain JS object, ready for JSON.stringifytoData returns fresh plain objects;
JSON.stringify(climb.toData()) produces spec-compliant output.
Formatting is up to the caller.
Getters return the record's internal values, not copies.
Attribute validators
Each datatype module also exports its attribute validators, usable on their own via subpath imports:
import { assertRating } from '@stele-climbing/stele1-datatypes/climb';
assertRating({ difficulty: 'V12' }); // returns the validated value
assertRating({}); // throwsCatalog adapter
For use with @stele-climbing/stele1-filesystem, this package ships a ready-made adapter:
import { Catalog } from '@stele-climbing/stele1-filesystem';
import { adapter } from '@stele-climbing/stele1-datatypes/adapter';
const catalog = new Catalog('/path/to/catalog', adapter);
catalog.getClimb(uuid); // a validated Climb instance
catalog.setClimb(climb); // serialized via toDataRecords are validated on read;
a file that fails validation throws (or is skipped by each*).
Output is written with sorted keys and stable indentation,
matching the plain adapter's formatting,
so a catalog diffs cleanly regardless of which adapter wrote it.
Compatibility behavior
Per the spec's versioning rules:
unknown top-level attributes are preserved verbatim through fromData / toData,
and unknown nested keys throw.
Install
npm install @stele-climbing/stele1-datatypesDevelopment
Source and issues live at codeberg.org/stele-climbing/stele1.
License
MIT
