Skip to content

Commit

Permalink
Merge pull request #2 from tpluscode/dt-history
Browse files Browse the repository at this point in the history
Migrate types from DefinitelyTyped
  • Loading branch information
blake-regalia authored Oct 29, 2020
2 parents c15ded5 + b1f9170 commit e021fe6
Show file tree
Hide file tree
Showing 10 changed files with 2,183 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off"
}
};
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- run: yarn
- run: yarn test
- run: yarn lint
290 changes: 290 additions & 0 deletions data-model.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
/* Data Model Interfaces */
/* https://rdf.js.org/data-model-spec/ */

/**
* Contains an Iri, RDF blank Node, RDF literal, variable name, default graph, or a quad
* @see NamedNode
* @see BlankNode
* @see Literal
* @see Variable
* @see DefaultGraph
* @see Quad
*/
export type Term = NamedNode | BlankNode | Literal | Variable | DefaultGraph | BaseQuad;

/**
* Contains an IRI.
*/
export interface NamedNode<Iri extends string = string> {
/**
* Contains the constant "NamedNode".
*/
termType: "NamedNode";
/**
* The IRI of the named node (example: `http://example.org/resource`)
*/
value: Iri;

/**
* @param other The term to compare with.
* @return True if and only if other has termType "NamedNode" and the same `value`.
*/
equals(other: Term | null | undefined): boolean;
}

/**
* Contains an RDF blank node.
*/
export interface BlankNode {
/**
* Contains the constant "BlankNode".
*/
termType: "BlankNode";
/**
* Blank node name as a string, without any serialization specific prefixes,
* e.g. when parsing,
* if the data was sourced from Turtle, remove _:,
* if it was sourced from RDF/XML, do not change the blank node name (example: blank3).
*/
value: string;

/**
* @param other The term to compare with.
* @return True if and only if other has termType "BlankNode" and the same `value`.
*/
equals(other: Term | null | undefined): boolean;
}

/**
* An RDF literal, containing a string with an optional language tag and/or datatype.
*/
export interface Literal {
/**
* Contains the constant "Literal".
*/
termType: "Literal";
/**
* The text value, unescaped, without language or type (example: Brad Pitt).
*/
value: string;
/**
* the language as lowercase BCP47 string (examples: en, en-gb)
* or an empty string if the literal has no language.
* @link http://tools.ietf.org/html/bcp47
*/
language: string;
/**
* A NamedNode whose IRI represents the datatype of the literal.
*/
datatype: NamedNode;

/**
* @param other The term to compare with.
* @return True if and only if other has termType "Literal"
* and the same `value`, `language`, and `datatype`.
*/
equals(other: Term | null | undefined): boolean;
}

/**
* A variable name.
*/
export interface Variable {
/**
* Contains the constant "Variable".
*/
termType: "Variable";
/**
* The name of the variable *without* leading ? (example: a).
*/
value: string;

/**
* @param other The term to compare with.
* @return True if and only if other has termType "Variable" and the same `value`.
*/
equals(other: Term | null | undefined): boolean;
}

/**
* An instance of DefaultGraph represents the default graph.
* It's only allowed to assign a DefaultGraph to the .graph property of a Quad.
*/
export interface DefaultGraph {
/**
* Contains the constant "DefaultGraph".
*/
termType: "DefaultGraph";
/**
* Contains an empty string as constant value.
*/
value: "";

/**
* @param other The term to compare with.
* @return True if and only if other has termType "DefaultGraph".
*/
equals(other: Term | null | undefined): boolean;
}

/**
* The subject, which is a NamedNode, BlankNode or Variable.
* @see NamedNode
* @see BlankNode
* @see Variable
*/
export type Quad_Subject = NamedNode | BlankNode | Quad | Variable;

/**
* The predicate, which is a NamedNode or Variable.
* @see NamedNode
* @see Variable
*/
export type Quad_Predicate = NamedNode | Variable;

/**
* The object, which is a NamedNode, Literal, BlankNode or Variable.
* @see NamedNode
* @see Literal
* @see BlankNode
* @see Variable
*/
export type Quad_Object = NamedNode | Literal | BlankNode | Quad | Variable;

/**
* The named graph, which is a DefaultGraph, NamedNode, BlankNode or Variable.
* @see DefaultGraph
* @see NamedNode
* @see BlankNode
* @see Variable
*/
export type Quad_Graph = DefaultGraph | NamedNode | BlankNode | Variable;

/**
* An RDF quad, taking any Term in its positions, containing the subject, predicate, object and graph terms.
*/
export interface BaseQuad {
/**
* Contains the constant "Quad".
*/
termType: "Quad";
/**
* Contains an empty string as constant value.
*/
value: "";

/**
* The subject.
* @see Quad_Subject
*/
subject: Term;
/**
* The predicate.
* @see Quad_Predicate
*/
predicate: Term;
/**
* The object.
* @see Quad_Object
*/
object: Term;
/**
* The named graph.
* @see Quad_Graph
*/
graph: Term;

/**
* @param other The term to compare with.
* @return True if and only if the argument is a) of the same type b) has all components equal.
*/
equals(other: Term | null | undefined): boolean;
}

/**
* An RDF quad, containing the subject, predicate, object and graph terms.
*/
export interface Quad extends BaseQuad {
/**
* The subject.
* @see Quad_Subject
*/
subject: Quad_Subject;
/**
* The predicate.
* @see Quad_Predicate
*/
predicate: Quad_Predicate;
/**
* The object.
* @see Quad_Object
*/
object: Quad_Object;
/**
* The named graph.
* @see Quad_Graph
*/
graph: Quad_Graph;

/**
* @param other The term to compare with.
* @return True if and only if the argument is a) of the same type b) has all components equal.
*/
equals(other: Term | null | undefined): boolean;
}

/**
* A factory for instantiating RDF terms and quads.
*/
export interface DataFactory<OutQuad extends BaseQuad = Quad, InQuad extends BaseQuad = OutQuad> {
/**
* @param value The IRI for the named node.
* @return A new instance of NamedNode.
* @see NamedNode
*/
namedNode<Iri extends string = string>(value: Iri): NamedNode<Iri>;

/**
* @param value The optional blank node identifier.
* @return A new instance of BlankNode.
* If the `value` parameter is undefined a new identifier
* for the blank node is generated for each call.
* @see BlankNode
*/
blankNode(value?: string): BlankNode;

/**
* @param value The literal value.
* @param languageOrDatatype The optional language or datatype.
* If `languageOrDatatype` is a NamedNode,
* then it is used for the value of `NamedNode.datatype`.
* Otherwise `languageOrDatatype` is used for the value
* of `NamedNode.language`.
* @return A new instance of Literal.
* @see Literal
*/
literal(value: string, languageOrDatatype?: string | NamedNode): Literal;

/**
* This method is optional.
* @param value The variable name
* @return A new instance of Variable.
* @see Variable
*/
variable?(value: string): Variable;

/**
* @return An instance of DefaultGraph.
*/
defaultGraph(): DefaultGraph;

/**
* @param subject The quad subject term.
* @param predicate The quad predicate term.
* @param object The quad object term.
* @param graph The quad graph term.
* @return A new instance of Quad.
* @see Quad
*/
quad(subject: InQuad['subject'], predicate: InQuad['predicate'], object: InQuad['object'], graph?: InQuad['graph']): OutQuad;
}
Loading

0 comments on commit e021fe6

Please sign in to comment.