Iritypeno test imports ittype Iri = Brand<string, "rdf/Iri">;An absolute IRI, checked by parseIri or made from a namespace.
RDF terms as typed values (commons 0012-ontology FR-001, FR-002): an IRI branded once checked, a namespace that pairs a prefix with its IRI, a named node branded with the classes its term is an individual of, blank nodes, literals typed by their language or their datatype, and triples and quads of them. A vocabulary is a typed value made from a namespace and the local names of its terms, so a term it does not list does not compile. Generalized from erga's ontology DSL (erga 248-ontology-in-typescript) and stolos' RDF export.
import { en, namespace, vocabulary } from "./rdf-term.ts";
const ex = vocabulary(namespace("ex", "https://example.org/terms#"), { Widget: "rdfs:Class", size: "rdf:Property" });
ex.Widget.iri; // "https://example.org/terms#Widget"
en("a widget"); // { kind: "lang", value: "a widget", language: "en" }Iritypeno test imports ittype Iri = Brand<string, "rdf/Iri">;An absolute IRI, checked by parseIri or made from a namespace.
IriErrortypeno test imports ittype IriError =
| { readonly kind: "not-absolute"; readonly text: string }
| { readonly kind: "forbidden-character"; readonly text: string; readonly at: number };Why a text is not an IRI: it has no scheme, or holds a character an IRI may not hold in N-Triples.
parseIrifunctionfunction parseIri(text: string): Result<Iri, IriError>The text as an IRI, or why it is not one.
formatIriErrorfunctionfunction formatIriError(e: IriError): stringThe sentence an IRI error is told with.
RdfFaultclassclass RdfFault extends ErrorA fault of the code: a constant namespace or term whose IRI does not parse. It is thrown where the constant is made.
| Member | Type | What it is |
|---|---|---|
name | string | |
message | string | |
stack? | string | |
cause? | unknown |
Classestypeno test imports ittype Classes<C extends string> = { readonly [K in C]: true };The classes a named node is an individual of, as the compiler sees them: one key for each class's name.
Namedtypetype Named<C extends string = never> = { readonly kind: "named"; readonly iri: Iri; readonly "@ifc/rdf-classes": Classes<C> };A named node: an IRI, branded with the classes its term is an individual of (by their CURIEs, "pm:PackageManager"). A Named<"a" | "b"> is an individual of both, so it is accepted where either is asked for; a Named<"a"> is not accepted where "b" is, and a Named of no known class (Named, which is Named<never>) is not accepted where any one class is asked for: every named node is a Named, so it is the type of a predicate or of any node at all.
NamedOftypeno test imports ittype NamedOf<C extends string> = C extends string ? Named<C> : never;A named node of any one of the classes C (NamedOf<"a" | "b"> is a Named<"a"> or a Named<"b">).
namedfunctionfunction named<C extends string = never>(iri: Iri): Named<C>The named node of an IRI, as an individual of the classes C; the brand is for the compiler alone.
Namespacetypeno test imports ittype Namespace<P extends string = string> = { readonly prefix: P; readonly iri: Iri };A namespace: a prefix and the IRI its terms' local names are appended to.
namespacefunctionfunction namespace<const P extends string>(prefix: P, iri: string): Namespace<P>A namespace; one whose prefix or IRI is not well formed is a fault of the code, thrown as an RdfFault.
iriInfunctionno test imports itfunction iriIn(ns: Namespace<string>, local: string): IriThe IRI of a local name in a namespace; one that does not parse is a fault of the code, thrown as an RdfFault.
termfunctionfunction term<C extends string = never>(ns: Namespace<string>, local: string): Named<C>The named node of a local name in a namespace, as an individual of the classes C, which the compiler takes from where it is used. It is how a term no module here states is named (an individual of another ontology); a term this code states comes from its schema.
ontologyIrifunctionno test imports itfunction ontologyIri(ns: Namespace<string>): IriThe IRI of the ontology a namespace's terms belong to: the namespace's IRI without its last # or /.
VocabularyTermtypeno test imports ittype VocabularyTerm<C extends string, Curie extends string> = Named<C> & { readonly curie: Curie };A term of a vocabulary: a named node of its class, with its CURIE.
Vocabularytypeno test imports ittype Vocabulary<P extends string, T extends Readonly<Record<string, string>>> = {
readonly [K in keyof T & string]: VocabularyTerm<T[K], `${P}:${K}`>;
};A typed vocabulary: each local name of T gives a term of the class T names for it.
vocabularyfunctionfunction vocabulary<const P extends string, const T extends Readonly<Record<string, string>>>(ns: Namespace<P>, terms: T): Vocabulary<P, T>The vocabulary of a namespace: its terms by local name, each of the class given ({ label: "rdf:Property" }).
LanguageTagtypeno test imports ittype LanguageTag = Brand<string, "rdf/LanguageTag">;A language tag, checked against BCP 47's shape (letters, then subtags of letters and digits, joined by -).
languageTagfunctionno test imports itfunction languageTag(text: string): LanguageTag | undefinedThe text as a language tag, in lower case, or nothing where it is not one.
LangStringtypeno test imports ittype LangString = { readonly kind: "lang"; readonly value: string; readonly language: LanguageTag };A string in a language: "install"@en.
TypedLiteraltypeno test imports ittype TypedLiteral = { readonly kind: "typed"; readonly value: string; readonly datatype: Iri };A literal with its datatype (a plain string is an xsd:string).
Literaltypeno test imports ittype Literal = LangString | TypedLiteral;A literal: a string in a language, or a lexical form with its datatype.
Blanktypeno test imports ittype Blank = { readonly kind: "blank"; readonly label: string };A blank node, by its label.
DefaultGraphtypeno test imports ittype DefaultGraph = { readonly kind: "default" };A node of the default graph's name.
Termtypeno test imports ittype Term = Named | Blank | Literal;Any RDF term.
Subjecttypeno test imports ittype Subject = Named | Blank;What a triple may be about.
Tripletypetype Triple = { readonly subject: Subject; readonly predicate: Named; readonly object: Term };A triple.
Quadtypeno test imports ittype Quad = Triple & { readonly graph: Named | DefaultGraph };A triple in a named graph, or in the default graph.
TermErrortypeno test imports ittype TermError = { readonly kind: "language"; readonly tag: string } | { readonly kind: "blank-label"; readonly label: string };Why a literal or a blank node could not be made.
formatTermErrorfunctionno test imports itfunction formatTermError(e: TermError): stringThe sentence a term error is told with.
langfunctionfunction lang(value: string, tag: string): Result<LangString, TermError>A string in the language of a tag, or why the tag is not one.
enfunctionfunction en(value: string): LangStringA string in English: en("install").
XSD_STRINGconstno test imports itconst XSD_STRING: IriThe IRI of xsd:string.
XSD_INTEGERconstno test imports itconst XSD_INTEGER: IriThe IRI of xsd:integer.
XSD_BOOLEANconstno test imports itconst XSD_BOOLEAN: IriThe IRI of xsd:boolean.
RDF_TYPEconstno test imports itconst RDF_TYPE: IriThe IRI of rdf:type.
typedfunctionfunction typed(value: string, datatype: Named<never>): TypedLiteralA literal of a datatype: typed("2026-11-16", xsd.date).
plainfunctionfunction plain(value: string): TypedLiteralA plain string, an xsd:string.
blankfunctionfunction blank(label: string): Result<Blank, TermError>A blank node, or why its label is not one.
defaultGraphconstconst defaultGraph: DefaultGraphThe default graph.
Valuetypeno test imports ittype Value = string | number | boolean | Literal | Named;One value of a field: a plain string, an integer, a boolean, a literal or a named node.
termOffunctionno test imports itfunction termOf(v: Value): TermThe term of a value: a string is an xsd:string, a number an xsd:integer (in its canonical form), a boolean an xsd:boolean.
quotedfunctionno test imports itfunction quoted(s: string): stringA string's characters escaped as N-Triples and Turtle write them, in quotes: \b \t \n \f \r \" \\ and \uXXXX for the other controls.
nTriplesTermfunctionno test imports itfunction nTriplesTerm(t: Term): stringA term as N-Triples writes it: <iri>, _:label, or a quoted literal with its language or its datatype (none for xsd:string).