-
Notifications
You must be signed in to change notification settings - Fork 0
Guides
Task-by-task usage. Each section: a code example and when to use it.
ErrorCode is the enum every HOLON error and error response uses. HolonError is the base error class that carries it, with a machine-readable code and optional details.
// throw and match on HOLON errors
import { ErrorCode, HolonError, ValidationError } from "@ontomorph/holon-types";
throw new ValidationError("age must be a positive integer");
// HolonError carries a machine-readable code and optional response detail:
if (err instanceof HolonError && err.code === ErrorCode.CONCEPT_NOT_FOUND) { … }The subclasses are thrown by the query and validation layers:
Thrown when an ECL query is malformed.
Thrown when a CQL query is malformed.
Thrown when input fails validation.
Thrown when a transaction fails.
Use these when you want to raise or catch a HOLON error and branch on err.code rather than parsing message strings.
ServiceResult<T> is a discriminated-union result type used across the HOLON services. Build it with ok() for success and err() for failure.
// return a ServiceResult instead of throwing
import { ok, err, ErrorCode, type ServiceResult } from "@ontomorph/holon-types";
function lookup(id: number): ServiceResult<Concept> {
const row = find(id);
return row ? ok(row) : err("no such concept", ErrorCode.CONCEPT_NOT_FOUND);
}Callers branch on .success. Use this when a function has an expected failure path and you want that failure in the return type instead of a thrown exception.
The enums name the source vocabularies, the concept domains, and the mapping classifiers.
// the supported source vocabularies
import { VocabularyId, DomainId, StandardConcept, MappingEquivalence, MappingOrigin } from "@ontomorph/holon-types";
VocabularyId.SNOMED_CT; // "SNOMED-CT"
VocabularyId.RXNORM; // "RxNorm"
VocabularyId.LOINC; // "LOINC"The supported source vocabularies (SNOMED-CT, RxNorm, LOINC, ICD11, HPO, FMA, and others).
The concept domains, naming what kind of thing a concept is (a Drug, a Measurement, a Condition).
The standard-concept flags.
A classifier for how two mapped concepts relate.
A classifier for where a mapping came from.
Use these to validate identifiers from user input, or to compare against a value the API returned, without hardcoding strings. See Use-Cases for a validation example.
Parse and emit holon: concept URIs, and name the Turtle MIME type.
// parse and emit holon: concept URIs
import { HOLON_URI_SCHEME, type HolonUriParts, MIME_TURTLE } from "@ontomorph/holon-types";
// HOLON_URI_SCHEME === "holon"; parse and emit holon:… concept URIs, serialize as text/turtleThe URI scheme, equal to "holon".
The parsed pieces of a holon: URI.
The text/turtle MIME type, for serializing concepts as Turtle.
Use these when you emit or read HOLON concept URIs, or set a content type for Turtle output.
- Concepts: what each term means.
- API-Reference: the full symbol list.