From 8ece67b53b30c56c6779423e5455390e9f004311 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 7 Oct 2019 10:24:49 +0200 Subject: [PATCH 01/10] WIP types added --- src/{node-internal.js => node-internal.ts} | 3 + src/{statement.js => statement.ts} | 0 src/types.ts | 1399 ++++++++++++++++++++ 3 files changed, 1402 insertions(+) rename src/{node-internal.js => node-internal.ts} (95%) rename src/{statement.js => statement.ts} (100%) create mode 100644 src/types.ts diff --git a/src/node-internal.js b/src/node-internal.ts similarity index 95% rename from src/node-internal.js rename to src/node-internal.ts index 2c5e63b8d..cf8a0daf5 100644 --- a/src/node-internal.js +++ b/src/node-internal.ts @@ -7,6 +7,9 @@ */ export default class Node { + classOrder!: number; + termType!: string; + substitute (bindings) { console.log('@@@ node substitute' + this) return this diff --git a/src/statement.js b/src/statement.ts similarity index 100% rename from src/statement.js rename to src/statement.ts diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 000000000..be7d6a14f --- /dev/null +++ b/src/types.ts @@ -0,0 +1,1399 @@ +// Type definitions for rdflib 0.20 +// Project: http://github.com/linkeddata/rdflib.js +// Definitions by: Cénotélie +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 +// Acknowledgements: This work has been financed by Logilab SA, FRANCE, logilab.fr + +export interface Bindings { + [id: string]: Node; +} +/** +* Class orders +*/ +export const ClassOrder: { + [id: string]: number; +}; +/** +* A type for values that serves as inputs +*/ +export type ValueType = Node | Date | string | number | boolean | undefined; +/** +* The superclass of all RDF Statement objects, that is NamedNode, Literal, BlankNode, etc. +*/ +export class Node { + /** + * The type of node + */ + termType: string; + /** + * Whether this node is a variable + */ + isVar: boolean; + /** + * The class order for this node + */ + classOrder: number; + /** + * The nod's value + */ + value: string; + /** + * Gets the substituted node for this one, according to the specified bindings + * @param bindings Bindings of identifiers to nodes + */ + substitute(bindings: Bindings): Node; + /** + * Compares this node with another + * @param term The other node + */ + compareTerm(term: Node): number; + /** + * Gets whether the two nodes are equal + * @param other The other node + */ + equals(other: Node): boolean; + /** + * Gets a hash for this node + */ + hashString(): string; + /** + * Gets whether this node is the same as the other one + * @param other Another node + */ + sameTerm(other: Node): boolean; + /** + * Gets the canonical string representation of this node + */ + toCanonical(): string; + /** + * Gets the n-triples string representation of this node + */ + toNT(): string; + /** + * Gets the string representation of this node + */ + toString(): string; + /** + * Gets a node for the specifed input + * @param value An input value + */ + static fromValue(value: ValueType): Node | ValueType; + /** + * Gets the javascript object equivalent to a node + * @param term The RDF node + */ + static toJS(term: Node): any; +} +/** +* An empty node +*/ +export class Empty extends Node { + constructor(); + static termType: string; +} +/** +* A collection of other RDF nodes +*/ +export class Collection extends Node { + /** + * The identifier for this collection + */ + id: string; + /** + * The nodes in this collection + */ + elements: Node[]; + /** + * Whether this collection is closed + */ + closed: boolean; + /** + * Initializes this collection + * @param initial The initial elements + */ + constructor(initial: ReadonlyArray); + /** + * Appends an element to this collection + * @param element The new element + */ + append(element: Node): number; + /** + * Closes this collection + */ + close(): boolean; + /** + * Removes the first element from the collection (and return it) + */ + shift(): Node; + /** + * Preprends the specified element to the colelction's front + * @param element The element to preprend + */ + unshift(element: Node): number; + static termType: string; +} +/** +* An RDF blank node +*/ +export class BlankNode extends Node { + /** + * The identifier for the blank node + */ + id: string; + /** + * Whether this is a blank node + */ + isBlank: boolean; + /** + * Initializes this node + * @param id The identifier for the blank node + */ + constructor(id: string); + /** + * Gets a copy of this blank node in the specified formula + * @param formula The formula + */ + copy(formula: Formula): BlankNode; + /** + * The next unique identifier for blank nodes + */ + static nextId: number; + static termType: string; + static NTAnonymousNodePrefix: string; +} +/** +* A named (IRI) RDF node +*/ +export class NamedNode extends Node { + /** + * The URI for this node + */ + uri: string; + /** + * Initializes this node + * @param iri The IRI for this node + */ + constructor(iri: NamedNode | string); + /** + * Returns an RDF node for the containing directory, ending in slash. + */ + dir(): NamedNode; + /** + * Returns an named node for the whole web site, ending in slash. + * Contrast with the "origin" which does NOT have a trailing slash + */ + site(): NamedNode; + /** + * Gets the named node for the document + */ + doc(): NamedNode; + static termType: string; + /** + * Gets a named node from the specified input value + * @param value An input value + */ + static fromValue(value: ValueType): NamedNode | ValueType; +} +/** +* A RDF literal node +*/ +export class Literal extends Node { + /** + * The language for the literal + */ + lang: string; + /** + * The language for the literal + */ + language: string; + /** + * The literal's datatype as a named node + */ + datatype: NamedNode; + /** + * Initializes this literal + * @param value The literal's lexical value + * @param language The language for the literal + * @param datatype The literal's datatype as a named node + */ + constructor(value: string, language?: string, datatype?: NamedNode); + /** + * Gets a copy of this literal + */ + copy(): Literal; + static termType: string; + /** + * Builds a literal node from a boolean value + * @param value The value + */ + static fromBoolean(value: boolean): Literal; + /** + * Builds a literal node from a date value + * @param value The value + */ + static fromDate(value: Date): Literal; + /** + * Builds a literal node from a number value + * @param value The value + */ + static fromNumber(value: number): Literal; + /** + * Builds a literal node from an input value + * @param value The input value + */ + static fromValue(value: ValueType): Literal | ValueType; +} +/** +* Variables are placeholders used in patterns to be matched. +* In cwm they are symbols which are the formula's list of quantified variables. +* In sparql they are not visibly URIs. Here we compromise, by having +* a common special base URI for variables. Their names are uris, +* but the ? notation has an implicit base uri of 'varid:' +*/ +export class Variable extends Node { + /** + * The base string for a variable's name + */ + base: string; + /** + * The unique identifier of this variable + */ + uri: string; + /** + * Initializes this variable + * @param name The variable's name + */ + constructor(name?: string); + static termType: string; +} +/** +* The RDF default graph +*/ +export class DefaultGraph extends Node { + /** + * Initializes this graph + */ + constructor(); +} +export namespace uri { + /** + * Gets the document part of an URI + * @param uri The URI + */ + function docpart(uri: string): string; + /** + * Gets the document part of an URI as a named node + * @param x The URI + */ + function document(x: string): NamedNode; + /** + * Gets the hostname in an URI + * @param u The URI + */ + function hostpart(u: string): string; + /** + * Joins an URI with a base + * @param given The relative part + * @param base The base URI + */ + function join(given: string, base: string): string; + /** + * Gets the protocol part of an URI + * @param uri The URI + */ + function protocol(uri: string): string; + /** + * Gets a relative uri + * @param base The base URI + * @param uri The absolute URI + */ + function refTo(base: string, uri: string): string; +} +export namespace log { + /** + * Logs a debug event + * @param x The event + */ + function debug(x: any): void; + /** + * Logs a warning event + * @param x The event + */ + function warn(x: any): void; + /** + * Logs an information event + * @param x The event + */ + function info(x: any): void; + /** + * Logs an error event + * @param x The event + */ + function error(x: any): void; + /** + * Logs a success event + * @param x The event + */ + function success(x: any): void; + /** + * Logs a message event + * @param x The event + */ + function msg(x: any): void; +} +/** +* An RDF statement (subject, predicate, object) +*/ +export class Statement { + /** + * The statement's subject + */ + subject: Node; + /** + * The statement's predicate + */ + predicate: Node; + /** + * The statement's object + */ + object: Node; + /** + * The origin of this statement + */ + why: ValueType; + /** + * The graph the contains this statement + */ + graph: ValueType; + /** + * Initializes this statement + * @param subject The statement's subject + * @param predicate The statement's predicate + * @param object The statement's object + * @param graph The graph the contains this statement + */ + constructor( + subject: ValueType, + predicate: ValueType, + object: ValueType, + graph: ValueType + ); + /** + * Gets whether two statements are the same + * @param other The other statement + */ + equals(other: Statement): boolean; + /** + * Gets this statement with the bindings substituted + * @param bindings The bindings + */ + substitute(bindings: Bindings): Statement; + /** + * Gets the canonical string representation of this statement + */ + toCanonical(): string; + /** + * Gets the n-triples string representation of this statement + */ + toNT(): string; + /** + * Gets the string representation of this statement + */ + toString(): string; +} +export namespace convert { + /** + * Converts an n3 string to JSON + * @param n3String The n3 string + * @param jsonCallback Callback when the operation terminated + */ + function convertToJson( + n3String: string, + jsonCallback: (err: string, jsonString: string) => void + ): void; + /** + * Converts an n3 string to n-quads + * @param n3String The n3 string + * @param nquadCallback Callback when the operation terminated + */ + function convertToNQuads( + n3String: string, + nquadCallback: (err: string, nquadString: string) => void + ): void; +} +/** +* A formula, or store of RDF statements +*/ +export class Formula extends Node { + /** + * The stored statements + */ + statements: Statement[]; + /** + * Initializes this formula + * @param statements The initial statements in this formulat + * @param constraints The additional constraints + * @param initBindings The initial bindings + * @param optional + */ + constructor( + statements: ReadonlyArray, + constraints: ReadonlyArray, + initBindings: { + [id: string]: Node; + }, + optional: ReadonlyArray + ); + /** + * Adds a statement to this formula + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + add(s: Node, p: NamedNode, o: Node, g: NamedNode): number; + /** + * Adds a statement to this formula + * @param st The statement to add + */ + addStatement(st: Statement): number; + /** + * Gets a blank node + * @param id The node's identifier + */ + bnode(id: string): BlankNode; + /** + * Adds all the statements to this formula + * @param statements A collection of statements + */ + addAll(statements: Iterable): void; + /** + * Gets a node that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + any( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): Node | null; + /** + * Gets the value of a node that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + anyValue( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): string; + /** + * Gets the first JavaScript object equivalent to a node based on the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + anyJS( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): any; + /** + * Gets the first statement that matches the specified pattern + * @param subj The subject + * @param pred The predicate + * @param obj The object + * @param why The graph that contains the statement + */ + anyStatementMatching( + subj?: Node | null, + pred?: Node | null, + obj?: Node | null, + why?: Node | null + ): Statement; + /** + * Gets the statements matching the specified pattern + * @param subj The subject + * @param pred The predicate + * @param obj The object + * @param why The graph that contains the statement + * @param justOne Whether to only get one statement + */ + statementsMatching( + subj?: Node | null, + pred?: Node | null, + obj?: Node | null, + why?: Node | null, + justOne?: boolean + ): Statement[]; + /** + * Finds the types in the list which have no *stored* subtypes + * These are a set of classes which provide by themselves complete + * information -- the other classes are redundant for those who + * know the class DAG. + * @param types A map of the types + */ + bottomTypeURIs(types: { + [id: string]: string | NamedNode; + }): { + [id: string]: string | NamedNode; + }; + /** + * Gets a new collection + */ + collection(): Collection; + /** + * Gets each node that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + each( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): Node[]; + /** + * Gets whether this formula is equals to the other one + * @param other The other formula + */ + equals(other: Formula): boolean; + /** + * For thisClass or any subclass, anything which has it is its type + * or is the object of something which has the type as its range, or subject + * of something which has the type as its domain + * We don't bother doing subproperty (yet?)as it doesn't seeem to be used + * much. + * Get all the Classes of which we can RDFS-infer the subject is a member + * @param thisClass A named node + */ + findMembersNT( + thisClass: Node + ): { + [uri: string]: Statement; + }; + /** + * For thisClass or any subclass, anything which has it is its type + * or is the object of something which has the type as its range, or subject + * of something which has the type as its domain + * We don't bother doing subproperty (yet?)as it doesn't seeem to be used + * much. + * Get all the Classes of which we can RDFS-infer the subject is a member + * @param subject A named node + */ + findMemberURIs( + subject: Node + ): { + [uri: string]: Statement; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a superclass + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findSubClassesNT( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a subclass + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findSuperClassesNT( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a member + * todo: This will loop is there is a class subclass loop (Sublass loops are + * not illegal) + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findTypesNT( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a member + * todo: This will loop is there is a class subclass loop (Sublass loops are + * not illegal) + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findTypeURIs( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Trace the statements which connect directly, or through bnodes + * Returns an array of statements + * doc param may be null to search all documents in store + * @param subject A subject node + * @param doc A document (the graph that contains statements) + * @param excludePredicateURIs The predicate URIs to exclude + */ + connectedStatements( + subject: Node, + doc: ValueType, + excludePredicateURIs: ReadonlyArray + ): Statement[]; + /** + * Creates a new empty formula - features not applicable, but necessary for typing to pass + */ + formula(features?: ReadonlyArray): Formula; + /** + * Transforms an NTriples string format into a Node. + * The bnode bit should not be used on program-external values; designed + * for internal work such as storing a bnode id in an HTML attribute. + * This will only parse the strings generated by the vaious toNT() methods. + * @param str A string representation + */ + fromNT(str: string): Node; + /** + * Gets whether this formula holds the specified statement + * @param s A subject + * @param p A predicate + * @param o An object + * @param g A containing graph + */ + holds( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): boolean; + /** + * Gets whether this formula holds the specified statement + * @param st A statement + */ + holdsStatement(st: Statement): boolean; + /** + * Gets a collection from a list of values + * @param values The values + */ + list(values: Iterable): Collection; + /** + * Gets a literal node + * @param val The literal's lexical value + * @param lang The language + * @param dt The datatype as a named node + */ + literal(val: string, lang: string, dt: NamedNode): Literal; + /** + * Transform a collection of NTriple URIs into their URI strings + * @param t some iterable colletion of NTriple URI strings + * @return a collection of the URIs as strings + */ + NTtoURI(t: { + [uri: string]: any; + }): { + [uri: string]: any; + }; + /** + * Serializes this formula + * @param base The base string + * @param contentType The content type of the syntax to use + * @param provenance The provenance URI + */ + serialize(base: string, contentType: string, provenance: string): string; + /** + * Gets a new formula with the substituting bindings applied + * @param bindings The bindings to substitute + */ + substitute(bindings: Bindings): Formula; + /** + * Gets an named node for an URI + * @param uri The URI + */ + sym(uri: string | NamedNode): NamedNode; + /** + * Gets the node matching the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + the( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): Node; + /** + * RDFS Inference + * These are hand-written implementations of a backward-chaining reasoner + * over the RDFS axioms. + * @param seeds A hash of NTs of classes to start with + * @param predicate The property to trace though + * @param inverse Trace inverse direction + */ + transitiveClosure( + seeds: { + [uri: string]: boolean; + }, + predicate: Node, + inverse: Node + ): { + [uri: string]: boolean; + }; + /** + * Finds the types in the list which have no *stored* supertypes + * We exclude the universal class, owl:Things and rdf:Resource, as it is + * information-free. + * @param types The types + */ + topTypeURIs(types: { + [id: string]: string | NamedNode; + }): { + [id: string]: string | NamedNode; + }; + /** + * Gets the number of statements in this formulat that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + whether( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): number; + /** + * Serializes this formulat to a string + */ + toString(): string; + /** + * Gets a namespace for the specified namespace's URI + * @param nsuri The URI for the namespace + */ + ns(nsuri: string): (ln: string) => NamedNode; + /** + * Gets a new variable + * @param name The variable's name + */ + variable(name: string): Variable; + static termType: string; +} + +export class Query { + pat: IndexedFormula; + name: string; + id?: string; + constructor(name: string, id?: any); + } + +/** +* A formula (set of triples) which indexes by predicate, subject and object. +* It "smushes" (merges into a single node) things which are identical +* according to owl:sameAs or an owl:InverseFunctionalProperty +* or an owl:FunctionalProperty +*/ +export class IndexedFormula extends Formula { + /** + * An UpdateManager initialised to this store + */ + updater?: UpdateManager; + /** + * Creates a new formula + * @param features The list of features to support + */ + constructor(features: ReadonlyArray); + /** + * Dictionary of namespace prefixes + */ + namespaces: {[key: string]: string}; + /** + * Gets the URI of the default graph + */ + static defaultGraphURI(): string; + /** + * Gets this graph with the bindings substituted + * @param bindings The bindings + */ + substitute(bindings: Bindings): IndexedFormula; + + /** + * Apply a set of statements to be deleted and to be inserted + * + * @param patch The set of statements to be deleted and to be inserted + * @param target The name of the document to patch + * @param patchCallback Callback to be called when patching is complete + */ + applyPatch( + patch: { + delete?: ReadonlyArray, + patch?: ReadonlyArray + }, + target: NamedNode, + patchCallback: () => void + ): void; + + /** + * N3 allows for declaring blank nodes, this function enables that support + * + * @param x The blank node to be declared, supported in N3 + */ + declareExistential(x: Node): Node; + + /** + * @param features + */ + initPropertyActions(features: Array<('sameAs' | 'InverseFunctionalProperty' | 'FunctionalProperty')>): boolean; + /** + * Returns the symbol with canonical URI as smushed + * @param term A RDF node + */ + canon(term: Node): Node; + /** + * Checks this formula for consistency + */ + check(): void; + /** + * Checks a list of statements for consistency + * @param sts The list of statements to check + * @param from An index with the array ['subject', 'predicate', 'object', 'why'] + */ + checkStatementList(sts: ReadonlyArray, from: number): boolean; + /** + * Closes this formula (and return it) + */ + close(): IndexedFormula; + /** + * replaces @template with @target and add appropriate triples + * removes no triples by default and is a one-direction replication + * @param template node to copy + * @param target node to copy to + * @param flags Whether or not to do a two-directional copy and/or delete triples + * + */ + copyTo( + template: Node, + target: Node, + flags?: Array<('two-direction' | 'delete')> + ): void; + /** + * Simplify graph in store when we realize two identifiers are equivalent + * We replace the bigger with the smaller. + * @param u1 The first node + * @param u2 The second node + */ + equate(u1: Node, u2: Node): boolean; + /** + * Creates a new empty indexed formula + * Only applicable for IndexedFormula, but TypeScript won't allow a subclass to override a property + * @param features The list of features + */ + formula(features: ReadonlyArray): IndexedFormula; + /** + * The number of statements in this formula + */ + length: number; + /** + * eturns any quads matching the given arguments. + * Standard RDFJS Taskforce method for Source objects, implemented as an + * alias to `statementsMatching()` + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The graph that contains the statement + */ + match( + subject: ValueType, + predicate: ValueType, + object: ValueType, + graph: ValueType + ): Statement[]; + /** + * Find out whether a given URI is used as symbol in the formula + * @param uri The URI to look for + */ + mentionsURI(uri: string): boolean; + /** + * Existentials are BNodes - something exists without naming + * @param uri An URI + */ + newExistential(uri: string): Node; + + /** + * Adds a new property action + * @param pred the predicate that the function should be triggered on + * @param action the function that should trigger + */ + newPropertyAction(pred: Node, action: (store: IndexedFormula, subject: NamedNode, object: NamedNode) => boolean): boolean; + /** + * Creates a new universal node + * Universals are Variables + * @param uri An URI + */ + newUniversal(uri: string): Node; + /** + * Find an unused id for a file being edited: return a symbol + * (Note: Slow iff a lot of them -- could be O(log(k)) ) + * @param doc A document named node + */ + nextSymbol(doc: NamedNode): NamedNode; + + /** + * Query this store asynchronously, return bindings in callback + * + * @param myQuery The query to be run + * @param callback Function to call when bindings + * @param dummy OBSOLETE - do not use this + * @param onDone OBSOLETE - do not use this + */ + query( + myQuery: Query, + callback: (bindings: Bindings) => void, + dummy?: null, + onDone?: () => void + ): void; + /** + * Query this store synchronously and return bindings + * + * @param myQuery The query to be run + */ + querySync(myQuery: Query): Bindings[]; + /** + * Removes a statement from this formula + * @param st A statement to remove + */ + remove(st: Statement): IndexedFormula; + /** + * Removes all statemnts in a doc + * @param doc The document + */ + removeDocument(doc: NamedNode): IndexedFormula; + /** + * Remove all statements matching args (within limit) * + * @param subj The subject + * @param pred The predicate + * @param obj The object + * @param why The graph that contains the statement + * @param limit The number of statements to remove + */ + removeMany( + subj?: Node | null, + pred?: Node | null, + obj?: Node | null, + why?: Node | null, + limit?: number + ): void; + /** + * Remove all matching statements + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The graph that contains the statement + */ + removeMatches( + subject?: Node | null, + predicate?: Node | null, + object?: Node | null, + graph?: Node | null + ): void; + /** + * Removes a statement + * @param st The statement to remove + */ + removeStatement(st: Statement): Formula; + /** + * Removes statements + * @param sts The statements to remove + */ + removeStatements(sts: ReadonlyArray): Formula; + /** + * Return all equivalent URIs by which this is known + * @param x A named node + */ + allAliases(x: NamedNode): NamedNode[]; + /** + * Compare by canonical URI as smushed + * @param x A named node + * @param y Another named node + */ + sameThings(x: NamedNode, y: NamedNode): boolean; + /** + * A list of all the URIs by which this thing is known + * @param term + */ + uris(term: NamedNode): string[]; +} +export namespace DataFactory { + /** + * Creates a new blank node + * @param value The blank node's identifier + */ + function blankNode(value: string): BlankNode; + /** + * Creates a new collection + * @param elements The initial element + */ + function collection(elements: ReadonlyArray): Collection; + /** + * Gets the default graph + */ + function defaultGraph(): DefaultGraph; + /** + * Creates a new fetcher + * @param store The store to use + * @param options The options + */ + function fetcher(store: Formula, options: any): Fetcher; + /** + * Creates a new graph (store) + */ + function graph(): IndexedFormula; + /** + * Creates a new literal node + * @param val The lexical value + * @param lang The language + * @param dt The datatype + */ + function lit(val: string, lang?: string, dt?: NamedNode): Literal; + /** + * Creates a new literal node + * @param value The lexical value + * @param languageOrDatatype Either the language or the datatype + */ + function literal( + value: string, + languageOrDatatype?: string | NamedNode + ): Literal; + /** + * Creates a new named node + * @param value The new named node + */ + function namedNode(value: string): NamedNode; + /** + * Creates a new statement + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The containing graph + */ + function quad( + subject: Node, + predicate: Node, + object: Node, + graph: Node + ): Statement; + /** + * Creates a new statement + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The containing graph + */ + function st( + subject: Node, + predicate: Node, + object: Node, + graph: Node + ): Statement; + /** + * Creates a new statement + * @param subject The subject + * @param predicate The predicate + * @param object The object + */ + function triple(subject: Node, predicate: Node, object: Node): Statement; + /** + * Creates a new variable + * @param name The name for the variable + */ + function variable(name?: string): Variable; +} +export namespace Util { + /** + * Gets a named node for a media type + * @param mediaType A media type + */ + function mediaTypeClass(mediaType: string): NamedNode; + /** + * Gets a named node from the name of a relation + * @param relation The name of a relation + */ + function linkRelationProperty(relation: string): NamedNode; + /** + * Loads ontologies of the data we load (this is the callback from the kb to + * the fetcher). Exports as `AJAR_handleNewTerm` + * @param kb The store + * @param p A property + * @param requestedBy + */ + function AJAR_handleNewTerm( + kb: Formula, + p: NamedNode, + requestedBy: string + ): Promise; +} +/** +* A datatype-specific handler for fetching data +*/ +export interface Handler { + response: any; + dom: any; +} +export interface FetchOptions { + fetch?: typeof fetch; + /** + * The resource which referred to this (for tracking bad links). + */ + referringTerm?: NamedNode; + /** + * Provided content type (for writes). + */ + contentType?: string; + /** + * Override the incoming header to force the data to be treated as this content-type (for reads). + */ + forceContentType?: string; + /** + * Load the data even if loaded before. Also sets the `Cache-Control:` header to `no-cache`. + */ + force?: boolean; + /** + * Original uri to preserve through proxying etc (`xhr.original`). + */ + baseUri?: Node | string; + /** + * Whether this request is a retry via a proxy (generally done from an error handler). + */ + proxyUsed?: boolean; + /** + * Flag for XHR/CORS etc + */ + withCredentials?: boolean; + /** + * Before we parse new data, clear old, but only on status 200 responses. + */ + clearPreviousData?: boolean; + /** + * Prevents the addition of various metadata triples (about the fetch request) to the store. + */ + noMeta?: boolean; + noRDFa?: boolean; +} +/** +* Responsible for fetching RDF data +*/ +export class Fetcher { + store: any; + timeout: number; + appNode: BlankNode; + requested: { + [uri: string]: any; + }; + timeouts: any; + redirectedTo: any; + constructor(store: any, options: any); + static HANDLERS: { + RDFXMLHandler: Handler; + XHTMLHandler: Handler; + XMLHandler: Handler; + HTMLHandler: Handler; + TextHandler: Handler; + N3Handler: Handler; + }; + static CONTENT_TYPE_BY_EXT: { + [ext: string]: string; + }; + /** + * Loads a web resource or resources into the store. + * @param uri Resource to load, provided either as a NamedNode object or a plain URL. If multiple resources are passed as an array, they will be fetched in parallel. + */ + load: (uri: ReadonlyArray | ReadonlyArray | NamedNode | string, options?: FetchOptions) => Promise; +} +/** +* Gets a node for the specified input +* @param value An input value +*/ +export function term(value: ValueType): Node | Collection | ValueType; +/** +* Gets a namespace +* @param nsuri The URI for the namespace +*/ +export function Namespace(nsuri: string): (ln: string) => NamedNode; +/** +* Transforms an NTriples string format into a Node. +* The bnode bit should not be used on program-external values; designed +* for internal work such as storing a bnode id in an HTML attribute. +* This will only parse the strings generated by the vaious toNT() methods. +* @param str A string representation +*/ +export function fromNT(str: string): Node; +/** +* Creates a new fetcher +* @param store The store to use +* @param options The options +*/ +export function fetcher(store: Formula, options: any): Fetcher; +/** +* Creates a new graph (store) +*/ +export function graph(): IndexedFormula; +/** +* Creates a new literal node +* @param val The lexical value +* @param lang The language +* @param dt The datatype +*/ +export function lit(val: string, lang: string, dt: NamedNode): Literal; +/** +* Creates a new statement +* @param subject The subject +* @param predicate The predicate +* @param object The object +* @param graph The containing graph +*/ +export function st( + subject: Node | Date | string, + predicate: Node, + object: Node | Date | string, + graph: Node +): Statement; +/** +* Creates a new named node +* @param value The new named node +*/ +export function sym(value: string): NamedNode; +/** +* Creates a new variable +* @param name The name for the variable +*/ +export function variable(name: string): Variable; +/** +* Creates a new blank node +* @param value The blank node's identifier +*/ +export function blankNode(value: string): BlankNode; +/** +* Gets the default graph +*/ +export function defaultGraph(): DefaultGraph; +/** +* Creates a new literal node +* @param value The lexical value +* @param languageOrDatatype Either the language or the datatype +*/ +export function literal( + value: string, + languageOrDatatype: string | NamedNode +): Literal; +/** +* Creates a new named node +* @param value The new named node +*/ +export function namedNode(value: string): NamedNode; +/** +* Creates a new statement +* @param subject The subject +* @param predicate The predicate +* @param object The object +* @param graph The containing graph +*/ +export function quad( + subject: Node, + predicate: Node, + object: Node, + graph: Node +): Statement; +/** +* Creates a new statement +* @param subject The subject +* @param predicate The predicate +* @param object The object +*/ +export function triple(subject: Node, predicate: Node, object: Node): Statement; +/** +* Parse a string and put the result into the graph kb. +* Normal method is sync. +* Unfortunately jsdonld is currently written to need to be called async. +* Hence the mess below with executeCallback. +* @param str The input string to parse +* @param kb The store to use +* @param base The base URI to use +* @param contentType The content type for the input +* @param callback The callback to call when the data has been loaded +*/ +export function parse( + str: string, + kb: Formula, + base: string, + contentType: string, + callback: (error: any, kb: Formula) => void +): void; +/** +* Get the next available unique identifier +*/ +export let NextId: number; + +/** +* The update manager is a helper object for a store. +* Just as a Fetcher provides the store with the ability to read and write, the Update Manager provides functionality for making small patches in real time, +* and also looking out for concurrent updates from other agents. +*/ +export class UpdateManager { + /** + * @param store The quadstore to store data and metadata. Created if not passed. + */ + constructor(store?: IndexedFormula) + + /** + * This is suitable for an initial creation of a document. + * @param document + * @param data + * @param contentType + * @param callback + */ + put( + document: Node, + data: string | ReadonlyArray, + contentType: string, + callback: (uri: string, ok: boolean, errorMessage: string, response?: unknown) => void, + ): Promise; + + /** + * This high-level function updates the local store iff the web is changed successfully. + * Deletions, insertions may be undefined or single statements or lists or formulae (may contain bnodes which can be indirectly identified by a where clause). + * The `why` property of each statement must be the same and give the web document to be updated. + * @param statementsToDelete Statement or statements to be deleted. + * @param statementsToAdd Statement or statements to be inserted. + * @param callback + */ + update( + statementsToDelete: ReadonlyArray, + statementsToAdd: ReadonlyArray, + callback: (uri: string | undefined, success: boolean, errorBody?: string) => void + ): void; From ecf5ad2e1eeaf50fd7b4f94283ac2f39af92979b Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Mon, 7 Oct 2019 18:05:23 +0200 Subject: [PATCH 02/10] Fix resolve .ts files #355 --- webpack.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webpack.config.js b/webpack.config.js index 5198dab44..5d76939a2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -26,6 +26,7 @@ module.exports = (env, args) => { } ] }, + resolve: { extensions: ['.js', '.ts'] }, plugins: [ new WrapperPlugin({ // Fall back to window.fetch when solid-auth-client is not present, From 97be965da79ad127b97913a438786e75f29a3109 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Mon, 7 Oct 2019 20:05:53 +0200 Subject: [PATCH 03/10] Node and Statement to TS #355 --- package.json | 8 + src/default-graph.js | 2 +- src/empty.js | 2 +- src/formula.js | 2 +- src/literal.js | 2 +- src/node-internal.ts | 145 ++++- src/node.js | 57 -- src/node.ts | 65 ++ src/statement.ts | 116 +++- src/store.js | 2 +- src/types.ts | 1395 +---------------------------------------- src/variable.js | 2 +- types-temp.ts | 1403 ++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 1702 insertions(+), 1499 deletions(-) delete mode 100644 src/node.js create mode 100644 src/node.ts create mode 100644 types-temp.ts diff --git a/package.json b/package.json index f00cbba91..cefb30ded 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,14 @@ { "name": "Daniel Friedman", "url": "https://github.com/dan-f/" + }, + { + "name": "Cénotélie", + "url": "https://github.com/cenotelie/" + }, + { + "name": "Joep Meindertsma", + "url": "https://github.com/joepio/" } ], "license": "MIT", diff --git a/src/default-graph.js b/src/default-graph.js index a45cd7af5..3183c021c 100644 --- a/src/default-graph.js +++ b/src/default-graph.js @@ -1,5 +1,5 @@ 'use strict' -import Node from './node' +import Node from './node-internal' export default class DefaultGraph extends Node { constructor () { diff --git a/src/empty.js b/src/empty.js index a24ee039d..1bbe6bf50 100644 --- a/src/empty.js +++ b/src/empty.js @@ -1,5 +1,5 @@ 'use strict' -import Node from './node' +import Node from './node-internal' /** * Singleton subclass of an empty Collection. diff --git a/src/formula.js b/src/formula.js index b5c0e32fb..bd3552999 100644 --- a/src/formula.js +++ b/src/formula.js @@ -6,7 +6,7 @@ import Literal from './literal' import log from './log' import NamedNode from './named-node' import Namespace from './namespace' -import Node from './node' +import Node from './node-internal' import Serializer from './serialize' import Statement from './statement' import Variable from './variable' diff --git a/src/literal.js b/src/literal.js index c1e89f027..4c989bf31 100644 --- a/src/literal.js +++ b/src/literal.js @@ -141,4 +141,4 @@ Literal.termType = 'Literal' Literal.prototype.classOrder = ClassOrder['Literal'] Literal.prototype.datatype = XSD.string Literal.prototype.lang = '' -Literal.prototype.isVar = 0 +Literal.prototype.isVar = false diff --git a/src/node-internal.ts b/src/node-internal.ts index cf8a0daf5..40987d354 100644 --- a/src/node-internal.ts +++ b/src/node-internal.ts @@ -1,54 +1,173 @@ -'use strict' +import { ValueType, Bindings } from './types' +import Collection from './collection' +import Literal from './literal' /** * The superclass of all RDF Statement objects, that is * NamedNode, Literal, BlankNode, etc. + * Also called Term. + * @link https://rdf.js.org/data-model-spec/#term-interface * @class Node */ +export default abstract class Node { + /** + * The nodes in this collection + */ + elements!: Node[]; -export default class Node { - classOrder!: number; + /** + * The type of node + */ termType!: string; - substitute (bindings) { + /** + * Whether this node is a variable + */ + isVar!: boolean | 1 | 0; + + /** + * The class order for this node + */ + classOrder!: number; + + /** + * The node's value + */ + value!: string; + + // Specified in './node.ts' to prevent circulur dependency + static fromValue: (value: ValueType | null) => Node | Literal | undefined | null | Collection + + // Specified in './node.ts' to prevent circulur dependency + static toJS: (term: Node | Literal) => any + + /** + * Gets the substituted node for this one, according to the specified bindings + * @param bindings Bindings of identifiers to nodes + */ + substitute (bindings: Bindings): Node { console.log('@@@ node substitute' + this) return this } - compareTerm (other) { + + /** + * Compares this node with another + * @param term The other node + */ + compareTerm (other: Node): number { if (this.classOrder < other.classOrder) { return -1 } if (this.classOrder > other.classOrder) { return +1 } - if (this.value < other.value) { + if (this.value && this.value < other.value) { return -1 } - if (this.value > other.value) { + if (this.value && this.value > other.value) { return +1 } return 0 } - equals (other) { + + /** + * Gets whether the two nodes are equal + * @param other The other node + */ + equals (other: Node): boolean { if (!other) { return false } return (this.termType === other.termType) && (this.value === other.value) } - hashString () { + + /** + * Gets a hash for this node + */ + hashString (): string { return this.toCanonical() } - sameTerm (other) { + + /** + * Gets whether this node is the same as the other one + * @param other Another node + */ + sameTerm(other: Node): boolean { return this.equals(other) } - toCanonical () { + + /** + * Gets the canonical string representation of this node + */ + toCanonical (): string { return this.toNT() } - toNT () { + + /** + * Gets the n-triples string representation of this node + */ + toNT (): string { return this.toString() } - toString () { + + /** + * Gets the string representation of this node + */ + toString (): string { throw new Error('Node.toString() is abstract - see the subclasses instead') } + + // /** + // * Creates an RDF Node from a native javascript value. + // * RDF Nodes are returned unchanged, undefined returned as itself. + // * @method fromValue + // * @param value - Any native Javascript value + // */ + // static fromValue (value: ValueType | null): Node | Literal | undefined | null | Collection { + // if (typeof value === 'undefined' || value === null) { + // return value + // } + // const isNode = Object.prototype.hasOwnProperty.call(value, 'termType') + // if (isNode) { // a Node subclass or a Collection + // // @ts-ignore + // return value + // } + // if (Array.isArray(value)) { + // return new Collection(value) + // } + // return Literal.fromValue(value) + // } + + // /** + // * Gets the javascript object equivalent to a node + // * @param term The RDF node + // */ + // static toJS (term: Node | Literal) { + // if (term.elements) { + // return term.elements.map(Node.toJS) // Array node (not standard RDFJS) + // } + // // Node remains Node + // if (!term.hasOwnProperty('dataType')) { + // return term + // } + // const literalTerm = term as Literal + // // if (!Object.prototype.hasOwnProperty.call(term, 'dataType')) return term // Objects remain objects + // if (literalTerm.datatype.sameTerm(ns.xsd('boolean'))) { + // return literalTerm.value === '1' + // } + // if (literalTerm.datatype.sameTerm(ns.xsd('dateTime')) || + // literalTerm.datatype.sameTerm(ns.xsd('date'))) { + // return new Date(literalTerm.value) + // } + // if ( + // literalTerm.datatype.sameTerm(ns.xsd('integer')) || + // literalTerm.datatype.sameTerm(ns.xsd('float')) || + // literalTerm.datatype.sameTerm(ns.xsd('decimal')) + // ) { + // let z = Number(literalTerm.value) + // return Number(literalTerm.value) + // } + // return literalTerm.value + // } } diff --git a/src/node.js b/src/node.js deleted file mode 100644 index a9df9975c..000000000 --- a/src/node.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict' - -// This file attaches all functionality to Node -// that would otherwise require circular dependencies. -import Node from './node-internal' -import Collection from './collection' -import Literal from './literal' - -export default Node - -/** - * Creates an RDF Node from a native javascript value. - * RDF Nodes are returned unchanged, undefined returned as itself. - * @method fromValue - * @static - * @param value {Node|Date|String|Number|Boolean|Undefined} - * @return {Node|Collection} - */ -Node.fromValue = function fromValue (value) { - if (typeof value === 'undefined' || value === null) { - return value - } - const isNode = value && value.termType - if (isNode) { // a Node subclass or a Collection - return value - } - if (Array.isArray(value)) { - return new Collection(value) - } - return Literal.fromValue(value) -} - -import Namespace from './namespace' -const ns = { xsd: Namespace('http://www.w3.org/2001/XMLSchema#') } - -Node.toJS = function toJS (term) { - if (term.elements) { - return term.elements.map(Node.toJS) // Array node (not standard RDFJS) - } - if (!term.datatype) return term // Objects remain objects - if (term.datatype.sameTerm(ns.xsd('boolean'))) { - return term.value === '1' - } - if (term.datatype.sameTerm(ns.xsd('dateTime')) || - term.datatype.sameTerm(ns.xsd('date'))) { - return new Date(term.value) - } - if ( - term.datatype.sameTerm(ns.xsd('integer')) || - term.datatype.sameTerm(ns.xsd('float')) || - term.datatype.sameTerm(ns.xsd('decimal')) - ) { - let z = Number(term.value) - return Number(term.value) - } - return term.value -} diff --git a/src/node.ts b/src/node.ts new file mode 100644 index 000000000..de2c3564c --- /dev/null +++ b/src/node.ts @@ -0,0 +1,65 @@ +// This file attaches all functionality to Node +// that would otherwise require circular dependencies. +import Node from './node-internal' +import Collection from './collection' +import Literal from './literal' +import { ValueType } from './types' + +export default Node + +/** + * Creates an RDF Node from a native javascript value. + * RDF Nodes are returned unchanged, undefined returned as itself. + * @method fromValue + * @param value - Any native Javascript value + */ +Node.fromValue = function (value: ValueType | null): Node | Literal | undefined | null | Collection { + if (typeof value === 'undefined' || value === null) { + return value + } + const isNode = Object.prototype.hasOwnProperty.call(value, 'termType') + if (isNode) { // a Node subclass or a Collection + // @ts-ignore + return value + } + if (Array.isArray(value)) { + return new Collection(value) + } + return Literal.fromValue(value) +} + +import Namespace from './namespace' +const ns = { xsd: Namespace('http://www.w3.org/2001/XMLSchema#') } + +/** + * Gets the javascript object equivalent to a node + * @param term The RDF node + */ +Node.toJS = function (term: Node | Literal) { + if (term.elements) { + return term.elements.map(Node.toJS) // Array node (not standard RDFJS) + } + // Node remains Node + // @ts-ignore + if (!term.datatype) return term // Objects remain objects + const literalTerm = term as Literal + // if (!Object.prototype.hasOwnProperty.call(term, 'dataType')) return term // Objects remain objects + if (literalTerm.datatype.sameTerm(ns.xsd('boolean'))) { + return literalTerm.value === '1' + } + console.log("4", term) + if (literalTerm.datatype.sameTerm(ns.xsd('dateTime')) || + literalTerm.datatype.sameTerm(ns.xsd('date'))) { + return new Date(literalTerm.value) + } + if ( + literalTerm.datatype.sameTerm(ns.xsd('integer')) || + literalTerm.datatype.sameTerm(ns.xsd('float')) || + literalTerm.datatype.sameTerm(ns.xsd('decimal')) + ) { + let z = Number(literalTerm.value) + return Number(literalTerm.value) + } + console.log("7", term) + return literalTerm.value +} diff --git a/src/statement.ts b/src/statement.ts index 006eb7f12..391b1426d 100644 --- a/src/statement.ts +++ b/src/statement.ts @@ -1,49 +1,95 @@ -'use strict' -import Node from './node' +import { Bindings, ValueType } from './types' +import Literal from './literal' +import Node from './node-internal' +import Collection from './collection' +/** A Statement represents an RDF Triple or Quad. */ export default class Statement { - /* Construct a new statment - ** - ** @param {Term} subject - The subject of the triple. What the efact is about - ** @ param {Term} predciate - The relationship which is assrted between the subject and object - ** @param {Term} object - The thing or data value which is asserted to be related to the subject - ** @param {NamedNode} why - The document where thr triple is or was or will be stored on the web. - ** - ** The why param is a named node of the document in which the triple when - ** it is stored on the web. - ** It is called “why” because when you have read data from varou slaces the - ** “why” tells you why you have the triple. (At the moment, it is just the - ** document, in future it could be an inference step). When you do - ** UpdateManager.update() then the why’s of all the statmemts must be the same, - ** and give the document you are patching. In future, we may have a more - ** powerful update() which can update more than one docment. + /** The subject of the triple. What the Statement is about. */ + subject: Node; + + /** The relationship which is asserted between the subject and object */ + predicate: Node; + + /** The thing or data value which is asserted to be related to the subject */ + object: Node | Literal | Collection; + + /** + * The why param is a named node of the document in which the triple when + * it is stored on the web. + */ + why: Node; + + /** + * Construct a new Triple Statment + * + * @param subject - The subject of the triple. What the Statement is about. + * @param predicate - The relationship which is asserted between the subject and object. + * @param object - The thing or data value which is asserted to be related to the subject. + * @param why - The document where the triple is or was or will be stored on the web. + * The why param is a named node of the document in which the triple when + * it is stored on the web. + * It is called “why” because when you have read data from varou slaces the + * “why” tells you why you have the triple. (At the moment, it is just the + * document, in future it could be an inference step). When you do + * UpdateManager.update() then the why’s of all the statmemts must be the same, + * and give the document you are patching. In future, we may have a more + * powerful update() which can update more than one docment. */ - constructor (subject, predicate, object, graph) { - this.subject = Node.fromValue(subject) - this.predicate = Node.fromValue(predicate) - this.object = Node.fromValue(object) - this.why = graph // property currently used by rdflib + constructor ( + subject: Node, + predicate: Node, + object: Node | ValueType, + why, + ) { + this.subject = Node.fromValue(subject) as Node + this.predicate = Node.fromValue(predicate) as Node + this.object = Node.fromValue(object) as Node + this.why = why // property currently used by rdflib } - get graph () { + + /** + * The graph param is a named node of the document in which the triple is stored on the web. + */ + get graph (): Node { return this.why } + set graph (g) { this.why = g } - equals (other) { - return other.subject.equals(this.subject) && other.predicate.equals(this.predicate) && - other.object.equals(this.object) && other.graph.equals(this.graph) + + /** + * Gets whether two statements are the same + * @param other The other statement + */ + equals (other: Statement): boolean { + return ( + other.subject.equals(this.subject) && + other.predicate.equals(this.predicate) && + other.object.equals(this.object as Node) && + other.graph.equals(this.graph) + ) } - substitute (bindings) { + + /** + * Gets this statement with the bindings substituted + * @param bindings The bindings + */ + substitute (bindings: Bindings): Statement { const y = new Statement( this.subject.substitute(bindings), this.predicate.substitute(bindings), - this.object.substitute(bindings), + this.object.substitute(bindings) as Node, this.why.substitute(bindings)) // 2016 console.log('@@@ statement substitute:' + y) return y } - toCanonical () { + + /** + * Gets the canonical string representation of this statement + */ + toCanonical (): string { let terms = [ this.subject.toCanonical(), this.predicate.toCanonical(), @@ -54,11 +100,19 @@ export default class Statement { } return terms.join(' ') + ' .' } - toNT () { + + /** + * Gets the n-triples string representation of this statement + */ + toNT (): string { return [this.subject.toNT(), this.predicate.toNT(), this.object.toNT()].join(' ') + ' .' } - toString () { + + /** + * Gets the string representation of this statement + */ + toString (): string { return this.toNT() } } diff --git a/src/store.js b/src/store.js index 7c1ec52b5..d308e8aa4 100644 --- a/src/store.js +++ b/src/store.js @@ -20,7 +20,7 @@ import { ArrayIndexOf } from './util' import Formula from './formula' import { RDFArrayRemove } from './util' import Statement from './statement' -import Node from './node' +import Node from './node-internal' import Variable from './variable' import { Query, indexedFormulaQuery } from './query' diff --git a/src/types.ts b/src/types.ts index be7d6a14f..fc106eb00 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,1399 +1,10 @@ -// Type definitions for rdflib 0.20 -// Project: http://github.com/linkeddata/rdflib.js -// Definitions by: Cénotélie -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.0 -// Acknowledgements: This work has been financed by Logilab SA, FRANCE, logilab.fr +import Node from './node-internal'; -export interface Bindings { - [id: string]: Node; -} -/** -* Class orders -*/ -export const ClassOrder: { - [id: string]: number; -}; /** * A type for values that serves as inputs */ export type ValueType = Node | Date | string | number | boolean | undefined; -/** -* The superclass of all RDF Statement objects, that is NamedNode, Literal, BlankNode, etc. -*/ -export class Node { - /** - * The type of node - */ - termType: string; - /** - * Whether this node is a variable - */ - isVar: boolean; - /** - * The class order for this node - */ - classOrder: number; - /** - * The nod's value - */ - value: string; - /** - * Gets the substituted node for this one, according to the specified bindings - * @param bindings Bindings of identifiers to nodes - */ - substitute(bindings: Bindings): Node; - /** - * Compares this node with another - * @param term The other node - */ - compareTerm(term: Node): number; - /** - * Gets whether the two nodes are equal - * @param other The other node - */ - equals(other: Node): boolean; - /** - * Gets a hash for this node - */ - hashString(): string; - /** - * Gets whether this node is the same as the other one - * @param other Another node - */ - sameTerm(other: Node): boolean; - /** - * Gets the canonical string representation of this node - */ - toCanonical(): string; - /** - * Gets the n-triples string representation of this node - */ - toNT(): string; - /** - * Gets the string representation of this node - */ - toString(): string; - /** - * Gets a node for the specifed input - * @param value An input value - */ - static fromValue(value: ValueType): Node | ValueType; - /** - * Gets the javascript object equivalent to a node - * @param term The RDF node - */ - static toJS(term: Node): any; -} -/** -* An empty node -*/ -export class Empty extends Node { - constructor(); - static termType: string; -} -/** -* A collection of other RDF nodes -*/ -export class Collection extends Node { - /** - * The identifier for this collection - */ - id: string; - /** - * The nodes in this collection - */ - elements: Node[]; - /** - * Whether this collection is closed - */ - closed: boolean; - /** - * Initializes this collection - * @param initial The initial elements - */ - constructor(initial: ReadonlyArray); - /** - * Appends an element to this collection - * @param element The new element - */ - append(element: Node): number; - /** - * Closes this collection - */ - close(): boolean; - /** - * Removes the first element from the collection (and return it) - */ - shift(): Node; - /** - * Preprends the specified element to the colelction's front - * @param element The element to preprend - */ - unshift(element: Node): number; - static termType: string; -} -/** -* An RDF blank node -*/ -export class BlankNode extends Node { - /** - * The identifier for the blank node - */ - id: string; - /** - * Whether this is a blank node - */ - isBlank: boolean; - /** - * Initializes this node - * @param id The identifier for the blank node - */ - constructor(id: string); - /** - * Gets a copy of this blank node in the specified formula - * @param formula The formula - */ - copy(formula: Formula): BlankNode; - /** - * The next unique identifier for blank nodes - */ - static nextId: number; - static termType: string; - static NTAnonymousNodePrefix: string; -} -/** -* A named (IRI) RDF node -*/ -export class NamedNode extends Node { - /** - * The URI for this node - */ - uri: string; - /** - * Initializes this node - * @param iri The IRI for this node - */ - constructor(iri: NamedNode | string); - /** - * Returns an RDF node for the containing directory, ending in slash. - */ - dir(): NamedNode; - /** - * Returns an named node for the whole web site, ending in slash. - * Contrast with the "origin" which does NOT have a trailing slash - */ - site(): NamedNode; - /** - * Gets the named node for the document - */ - doc(): NamedNode; - static termType: string; - /** - * Gets a named node from the specified input value - * @param value An input value - */ - static fromValue(value: ValueType): NamedNode | ValueType; -} -/** -* A RDF literal node -*/ -export class Literal extends Node { - /** - * The language for the literal - */ - lang: string; - /** - * The language for the literal - */ - language: string; - /** - * The literal's datatype as a named node - */ - datatype: NamedNode; - /** - * Initializes this literal - * @param value The literal's lexical value - * @param language The language for the literal - * @param datatype The literal's datatype as a named node - */ - constructor(value: string, language?: string, datatype?: NamedNode); - /** - * Gets a copy of this literal - */ - copy(): Literal; - static termType: string; - /** - * Builds a literal node from a boolean value - * @param value The value - */ - static fromBoolean(value: boolean): Literal; - /** - * Builds a literal node from a date value - * @param value The value - */ - static fromDate(value: Date): Literal; - /** - * Builds a literal node from a number value - * @param value The value - */ - static fromNumber(value: number): Literal; - /** - * Builds a literal node from an input value - * @param value The input value - */ - static fromValue(value: ValueType): Literal | ValueType; -} -/** -* Variables are placeholders used in patterns to be matched. -* In cwm they are symbols which are the formula's list of quantified variables. -* In sparql they are not visibly URIs. Here we compromise, by having -* a common special base URI for variables. Their names are uris, -* but the ? notation has an implicit base uri of 'varid:' -*/ -export class Variable extends Node { - /** - * The base string for a variable's name - */ - base: string; - /** - * The unique identifier of this variable - */ - uri: string; - /** - * Initializes this variable - * @param name The variable's name - */ - constructor(name?: string); - static termType: string; -} -/** -* The RDF default graph -*/ -export class DefaultGraph extends Node { - /** - * Initializes this graph - */ - constructor(); -} -export namespace uri { - /** - * Gets the document part of an URI - * @param uri The URI - */ - function docpart(uri: string): string; - /** - * Gets the document part of an URI as a named node - * @param x The URI - */ - function document(x: string): NamedNode; - /** - * Gets the hostname in an URI - * @param u The URI - */ - function hostpart(u: string): string; - /** - * Joins an URI with a base - * @param given The relative part - * @param base The base URI - */ - function join(given: string, base: string): string; - /** - * Gets the protocol part of an URI - * @param uri The URI - */ - function protocol(uri: string): string; - /** - * Gets a relative uri - * @param base The base URI - * @param uri The absolute URI - */ - function refTo(base: string, uri: string): string; -} -export namespace log { - /** - * Logs a debug event - * @param x The event - */ - function debug(x: any): void; - /** - * Logs a warning event - * @param x The event - */ - function warn(x: any): void; - /** - * Logs an information event - * @param x The event - */ - function info(x: any): void; - /** - * Logs an error event - * @param x The event - */ - function error(x: any): void; - /** - * Logs a success event - * @param x The event - */ - function success(x: any): void; - /** - * Logs a message event - * @param x The event - */ - function msg(x: any): void; -} -/** -* An RDF statement (subject, predicate, object) -*/ -export class Statement { - /** - * The statement's subject - */ - subject: Node; - /** - * The statement's predicate - */ - predicate: Node; - /** - * The statement's object - */ - object: Node; - /** - * The origin of this statement - */ - why: ValueType; - /** - * The graph the contains this statement - */ - graph: ValueType; - /** - * Initializes this statement - * @param subject The statement's subject - * @param predicate The statement's predicate - * @param object The statement's object - * @param graph The graph the contains this statement - */ - constructor( - subject: ValueType, - predicate: ValueType, - object: ValueType, - graph: ValueType - ); - /** - * Gets whether two statements are the same - * @param other The other statement - */ - equals(other: Statement): boolean; - /** - * Gets this statement with the bindings substituted - * @param bindings The bindings - */ - substitute(bindings: Bindings): Statement; - /** - * Gets the canonical string representation of this statement - */ - toCanonical(): string; - /** - * Gets the n-triples string representation of this statement - */ - toNT(): string; - /** - * Gets the string representation of this statement - */ - toString(): string; -} -export namespace convert { - /** - * Converts an n3 string to JSON - * @param n3String The n3 string - * @param jsonCallback Callback when the operation terminated - */ - function convertToJson( - n3String: string, - jsonCallback: (err: string, jsonString: string) => void - ): void; - /** - * Converts an n3 string to n-quads - * @param n3String The n3 string - * @param nquadCallback Callback when the operation terminated - */ - function convertToNQuads( - n3String: string, - nquadCallback: (err: string, nquadString: string) => void - ): void; -} -/** -* A formula, or store of RDF statements -*/ -export class Formula extends Node { - /** - * The stored statements - */ - statements: Statement[]; - /** - * Initializes this formula - * @param statements The initial statements in this formulat - * @param constraints The additional constraints - * @param initBindings The initial bindings - * @param optional - */ - constructor( - statements: ReadonlyArray, - constraints: ReadonlyArray, - initBindings: { - [id: string]: Node; - }, - optional: ReadonlyArray - ); - /** - * Adds a statement to this formula - * @param s The subject - * @param p The predicate - * @param o The object - * @param g The graph that contains the statement - */ - add(s: Node, p: NamedNode, o: Node, g: NamedNode): number; - /** - * Adds a statement to this formula - * @param st The statement to add - */ - addStatement(st: Statement): number; - /** - * Gets a blank node - * @param id The node's identifier - */ - bnode(id: string): BlankNode; - /** - * Adds all the statements to this formula - * @param statements A collection of statements - */ - addAll(statements: Iterable): void; - /** - * Gets a node that matches the specified pattern - * @param s The subject - * @param p The predicate - * @param o The object - * @param g The graph that contains the statement - */ - any( - s?: Node | null, - p?: Node | null, - o?: Node | null, - g?: Node | null - ): Node | null; - /** - * Gets the value of a node that matches the specified pattern - * @param s The subject - * @param p The predicate - * @param o The object - * @param g The graph that contains the statement - */ - anyValue( - s?: Node | null, - p?: Node | null, - o?: Node | null, - g?: Node | null - ): string; - /** - * Gets the first JavaScript object equivalent to a node based on the specified pattern - * @param s The subject - * @param p The predicate - * @param o The object - * @param g The graph that contains the statement - */ - anyJS( - s?: Node | null, - p?: Node | null, - o?: Node | null, - g?: Node | null - ): any; - /** - * Gets the first statement that matches the specified pattern - * @param subj The subject - * @param pred The predicate - * @param obj The object - * @param why The graph that contains the statement - */ - anyStatementMatching( - subj?: Node | null, - pred?: Node | null, - obj?: Node | null, - why?: Node | null - ): Statement; - /** - * Gets the statements matching the specified pattern - * @param subj The subject - * @param pred The predicate - * @param obj The object - * @param why The graph that contains the statement - * @param justOne Whether to only get one statement - */ - statementsMatching( - subj?: Node | null, - pred?: Node | null, - obj?: Node | null, - why?: Node | null, - justOne?: boolean - ): Statement[]; - /** - * Finds the types in the list which have no *stored* subtypes - * These are a set of classes which provide by themselves complete - * information -- the other classes are redundant for those who - * know the class DAG. - * @param types A map of the types - */ - bottomTypeURIs(types: { - [id: string]: string | NamedNode; - }): { - [id: string]: string | NamedNode; - }; - /** - * Gets a new collection - */ - collection(): Collection; - /** - * Gets each node that matches the specified pattern - * @param s The subject - * @param p The predicate - * @param o The object - * @param g The graph that contains the statement - */ - each( - s?: Node | null, - p?: Node | null, - o?: Node | null, - g?: Node | null - ): Node[]; - /** - * Gets whether this formula is equals to the other one - * @param other The other formula - */ - equals(other: Formula): boolean; - /** - * For thisClass or any subclass, anything which has it is its type - * or is the object of something which has the type as its range, or subject - * of something which has the type as its domain - * We don't bother doing subproperty (yet?)as it doesn't seeem to be used - * much. - * Get all the Classes of which we can RDFS-infer the subject is a member - * @param thisClass A named node - */ - findMembersNT( - thisClass: Node - ): { - [uri: string]: Statement; - }; - /** - * For thisClass or any subclass, anything which has it is its type - * or is the object of something which has the type as its range, or subject - * of something which has the type as its domain - * We don't bother doing subproperty (yet?)as it doesn't seeem to be used - * much. - * Get all the Classes of which we can RDFS-infer the subject is a member - * @param subject A named node - */ - findMemberURIs( - subject: Node - ): { - [uri: string]: Statement; - }; - /** - * Get all the Classes of which we can RDFS-infer the subject is a superclass - * Returns a hash table where key is NT of type and value is statement why we - * think so. - * Does NOT return terms, returns URI strings. - * We use NT representations in this version because they handle blank nodes. - * @param subject A subject node - */ - findSubClassesNT( - subject: Node - ): { - [uri: string]: boolean; - }; - /** - * Get all the Classes of which we can RDFS-infer the subject is a subclass - * Returns a hash table where key is NT of type and value is statement why we - * think so. - * Does NOT return terms, returns URI strings. - * We use NT representations in this version because they handle blank nodes. - * @param subject A subject node - */ - findSuperClassesNT( - subject: Node - ): { - [uri: string]: boolean; - }; - /** - * Get all the Classes of which we can RDFS-infer the subject is a member - * todo: This will loop is there is a class subclass loop (Sublass loops are - * not illegal) - * Returns a hash table where key is NT of type and value is statement why we - * think so. - * Does NOT return terms, returns URI strings. - * We use NT representations in this version because they handle blank nodes. - * @param subject A subject node - */ - findTypesNT( - subject: Node - ): { - [uri: string]: boolean; - }; - /** - * Get all the Classes of which we can RDFS-infer the subject is a member - * todo: This will loop is there is a class subclass loop (Sublass loops are - * not illegal) - * Returns a hash table where key is NT of type and value is statement why we - * think so. - * Does NOT return terms, returns URI strings. - * We use NT representations in this version because they handle blank nodes. - * @param subject A subject node - */ - findTypeURIs( - subject: Node - ): { - [uri: string]: boolean; - }; - /** - * Trace the statements which connect directly, or through bnodes - * Returns an array of statements - * doc param may be null to search all documents in store - * @param subject A subject node - * @param doc A document (the graph that contains statements) - * @param excludePredicateURIs The predicate URIs to exclude - */ - connectedStatements( - subject: Node, - doc: ValueType, - excludePredicateURIs: ReadonlyArray - ): Statement[]; - /** - * Creates a new empty formula - features not applicable, but necessary for typing to pass - */ - formula(features?: ReadonlyArray): Formula; - /** - * Transforms an NTriples string format into a Node. - * The bnode bit should not be used on program-external values; designed - * for internal work such as storing a bnode id in an HTML attribute. - * This will only parse the strings generated by the vaious toNT() methods. - * @param str A string representation - */ - fromNT(str: string): Node; - /** - * Gets whether this formula holds the specified statement - * @param s A subject - * @param p A predicate - * @param o An object - * @param g A containing graph - */ - holds( - s?: Node | null, - p?: Node | null, - o?: Node | null, - g?: Node | null - ): boolean; - /** - * Gets whether this formula holds the specified statement - * @param st A statement - */ - holdsStatement(st: Statement): boolean; - /** - * Gets a collection from a list of values - * @param values The values - */ - list(values: Iterable): Collection; - /** - * Gets a literal node - * @param val The literal's lexical value - * @param lang The language - * @param dt The datatype as a named node - */ - literal(val: string, lang: string, dt: NamedNode): Literal; - /** - * Transform a collection of NTriple URIs into their URI strings - * @param t some iterable colletion of NTriple URI strings - * @return a collection of the URIs as strings - */ - NTtoURI(t: { - [uri: string]: any; - }): { - [uri: string]: any; - }; - /** - * Serializes this formula - * @param base The base string - * @param contentType The content type of the syntax to use - * @param provenance The provenance URI - */ - serialize(base: string, contentType: string, provenance: string): string; - /** - * Gets a new formula with the substituting bindings applied - * @param bindings The bindings to substitute - */ - substitute(bindings: Bindings): Formula; - /** - * Gets an named node for an URI - * @param uri The URI - */ - sym(uri: string | NamedNode): NamedNode; - /** - * Gets the node matching the specified pattern - * @param s The subject - * @param p The predicate - * @param o The object - * @param g The graph that contains the statement - */ - the( - s?: Node | null, - p?: Node | null, - o?: Node | null, - g?: Node | null - ): Node; - /** - * RDFS Inference - * These are hand-written implementations of a backward-chaining reasoner - * over the RDFS axioms. - * @param seeds A hash of NTs of classes to start with - * @param predicate The property to trace though - * @param inverse Trace inverse direction - */ - transitiveClosure( - seeds: { - [uri: string]: boolean; - }, - predicate: Node, - inverse: Node - ): { - [uri: string]: boolean; - }; - /** - * Finds the types in the list which have no *stored* supertypes - * We exclude the universal class, owl:Things and rdf:Resource, as it is - * information-free. - * @param types The types - */ - topTypeURIs(types: { - [id: string]: string | NamedNode; - }): { - [id: string]: string | NamedNode; - }; - /** - * Gets the number of statements in this formulat that matches the specified pattern - * @param s The subject - * @param p The predicate - * @param o The object - * @param g The graph that contains the statement - */ - whether( - s?: Node | null, - p?: Node | null, - o?: Node | null, - g?: Node | null - ): number; - /** - * Serializes this formulat to a string - */ - toString(): string; - /** - * Gets a namespace for the specified namespace's URI - * @param nsuri The URI for the namespace - */ - ns(nsuri: string): (ln: string) => NamedNode; - /** - * Gets a new variable - * @param name The variable's name - */ - variable(name: string): Variable; - static termType: string; -} - -export class Query { - pat: IndexedFormula; - name: string; - id?: string; - constructor(name: string, id?: any); - } - -/** -* A formula (set of triples) which indexes by predicate, subject and object. -* It "smushes" (merges into a single node) things which are identical -* according to owl:sameAs or an owl:InverseFunctionalProperty -* or an owl:FunctionalProperty -*/ -export class IndexedFormula extends Formula { - /** - * An UpdateManager initialised to this store - */ - updater?: UpdateManager; - /** - * Creates a new formula - * @param features The list of features to support - */ - constructor(features: ReadonlyArray); - /** - * Dictionary of namespace prefixes - */ - namespaces: {[key: string]: string}; - /** - * Gets the URI of the default graph - */ - static defaultGraphURI(): string; - /** - * Gets this graph with the bindings substituted - * @param bindings The bindings - */ - substitute(bindings: Bindings): IndexedFormula; - /** - * Apply a set of statements to be deleted and to be inserted - * - * @param patch The set of statements to be deleted and to be inserted - * @param target The name of the document to patch - * @param patchCallback Callback to be called when patching is complete - */ - applyPatch( - patch: { - delete?: ReadonlyArray, - patch?: ReadonlyArray - }, - target: NamedNode, - patchCallback: () => void - ): void; - - /** - * N3 allows for declaring blank nodes, this function enables that support - * - * @param x The blank node to be declared, supported in N3 - */ - declareExistential(x: Node): Node; - - /** - * @param features - */ - initPropertyActions(features: Array<('sameAs' | 'InverseFunctionalProperty' | 'FunctionalProperty')>): boolean; - /** - * Returns the symbol with canonical URI as smushed - * @param term A RDF node - */ - canon(term: Node): Node; - /** - * Checks this formula for consistency - */ - check(): void; - /** - * Checks a list of statements for consistency - * @param sts The list of statements to check - * @param from An index with the array ['subject', 'predicate', 'object', 'why'] - */ - checkStatementList(sts: ReadonlyArray, from: number): boolean; - /** - * Closes this formula (and return it) - */ - close(): IndexedFormula; - /** - * replaces @template with @target and add appropriate triples - * removes no triples by default and is a one-direction replication - * @param template node to copy - * @param target node to copy to - * @param flags Whether or not to do a two-directional copy and/or delete triples - * - */ - copyTo( - template: Node, - target: Node, - flags?: Array<('two-direction' | 'delete')> - ): void; - /** - * Simplify graph in store when we realize two identifiers are equivalent - * We replace the bigger with the smaller. - * @param u1 The first node - * @param u2 The second node - */ - equate(u1: Node, u2: Node): boolean; - /** - * Creates a new empty indexed formula - * Only applicable for IndexedFormula, but TypeScript won't allow a subclass to override a property - * @param features The list of features - */ - formula(features: ReadonlyArray): IndexedFormula; - /** - * The number of statements in this formula - */ - length: number; - /** - * eturns any quads matching the given arguments. - * Standard RDFJS Taskforce method for Source objects, implemented as an - * alias to `statementsMatching()` - * @param subject The subject - * @param predicate The predicate - * @param object The object - * @param graph The graph that contains the statement - */ - match( - subject: ValueType, - predicate: ValueType, - object: ValueType, - graph: ValueType - ): Statement[]; - /** - * Find out whether a given URI is used as symbol in the formula - * @param uri The URI to look for - */ - mentionsURI(uri: string): boolean; - /** - * Existentials are BNodes - something exists without naming - * @param uri An URI - */ - newExistential(uri: string): Node; - - /** - * Adds a new property action - * @param pred the predicate that the function should be triggered on - * @param action the function that should trigger - */ - newPropertyAction(pred: Node, action: (store: IndexedFormula, subject: NamedNode, object: NamedNode) => boolean): boolean; - /** - * Creates a new universal node - * Universals are Variables - * @param uri An URI - */ - newUniversal(uri: string): Node; - /** - * Find an unused id for a file being edited: return a symbol - * (Note: Slow iff a lot of them -- could be O(log(k)) ) - * @param doc A document named node - */ - nextSymbol(doc: NamedNode): NamedNode; - - /** - * Query this store asynchronously, return bindings in callback - * - * @param myQuery The query to be run - * @param callback Function to call when bindings - * @param dummy OBSOLETE - do not use this - * @param onDone OBSOLETE - do not use this - */ - query( - myQuery: Query, - callback: (bindings: Bindings) => void, - dummy?: null, - onDone?: () => void - ): void; - /** - * Query this store synchronously and return bindings - * - * @param myQuery The query to be run - */ - querySync(myQuery: Query): Bindings[]; - /** - * Removes a statement from this formula - * @param st A statement to remove - */ - remove(st: Statement): IndexedFormula; - /** - * Removes all statemnts in a doc - * @param doc The document - */ - removeDocument(doc: NamedNode): IndexedFormula; - /** - * Remove all statements matching args (within limit) * - * @param subj The subject - * @param pred The predicate - * @param obj The object - * @param why The graph that contains the statement - * @param limit The number of statements to remove - */ - removeMany( - subj?: Node | null, - pred?: Node | null, - obj?: Node | null, - why?: Node | null, - limit?: number - ): void; - /** - * Remove all matching statements - * @param subject The subject - * @param predicate The predicate - * @param object The object - * @param graph The graph that contains the statement - */ - removeMatches( - subject?: Node | null, - predicate?: Node | null, - object?: Node | null, - graph?: Node | null - ): void; - /** - * Removes a statement - * @param st The statement to remove - */ - removeStatement(st: Statement): Formula; - /** - * Removes statements - * @param sts The statements to remove - */ - removeStatements(sts: ReadonlyArray): Formula; - /** - * Return all equivalent URIs by which this is known - * @param x A named node - */ - allAliases(x: NamedNode): NamedNode[]; - /** - * Compare by canonical URI as smushed - * @param x A named node - * @param y Another named node - */ - sameThings(x: NamedNode, y: NamedNode): boolean; - /** - * A list of all the URIs by which this thing is known - * @param term - */ - uris(term: NamedNode): string[]; -} -export namespace DataFactory { - /** - * Creates a new blank node - * @param value The blank node's identifier - */ - function blankNode(value: string): BlankNode; - /** - * Creates a new collection - * @param elements The initial element - */ - function collection(elements: ReadonlyArray): Collection; - /** - * Gets the default graph - */ - function defaultGraph(): DefaultGraph; - /** - * Creates a new fetcher - * @param store The store to use - * @param options The options - */ - function fetcher(store: Formula, options: any): Fetcher; - /** - * Creates a new graph (store) - */ - function graph(): IndexedFormula; - /** - * Creates a new literal node - * @param val The lexical value - * @param lang The language - * @param dt The datatype - */ - function lit(val: string, lang?: string, dt?: NamedNode): Literal; - /** - * Creates a new literal node - * @param value The lexical value - * @param languageOrDatatype Either the language or the datatype - */ - function literal( - value: string, - languageOrDatatype?: string | NamedNode - ): Literal; - /** - * Creates a new named node - * @param value The new named node - */ - function namedNode(value: string): NamedNode; - /** - * Creates a new statement - * @param subject The subject - * @param predicate The predicate - * @param object The object - * @param graph The containing graph - */ - function quad( - subject: Node, - predicate: Node, - object: Node, - graph: Node - ): Statement; - /** - * Creates a new statement - * @param subject The subject - * @param predicate The predicate - * @param object The object - * @param graph The containing graph - */ - function st( - subject: Node, - predicate: Node, - object: Node, - graph: Node - ): Statement; - /** - * Creates a new statement - * @param subject The subject - * @param predicate The predicate - * @param object The object - */ - function triple(subject: Node, predicate: Node, object: Node): Statement; - /** - * Creates a new variable - * @param name The name for the variable - */ - function variable(name?: string): Variable; -} -export namespace Util { - /** - * Gets a named node for a media type - * @param mediaType A media type - */ - function mediaTypeClass(mediaType: string): NamedNode; - /** - * Gets a named node from the name of a relation - * @param relation The name of a relation - */ - function linkRelationProperty(relation: string): NamedNode; - /** - * Loads ontologies of the data we load (this is the callback from the kb to - * the fetcher). Exports as `AJAR_handleNewTerm` - * @param kb The store - * @param p A property - * @param requestedBy - */ - function AJAR_handleNewTerm( - kb: Formula, - p: NamedNode, - requestedBy: string - ): Promise; -} -/** -* A datatype-specific handler for fetching data -*/ -export interface Handler { - response: any; - dom: any; -} -export interface FetchOptions { - fetch?: typeof fetch; - /** - * The resource which referred to this (for tracking bad links). - */ - referringTerm?: NamedNode; - /** - * Provided content type (for writes). - */ - contentType?: string; - /** - * Override the incoming header to force the data to be treated as this content-type (for reads). - */ - forceContentType?: string; - /** - * Load the data even if loaded before. Also sets the `Cache-Control:` header to `no-cache`. - */ - force?: boolean; - /** - * Original uri to preserve through proxying etc (`xhr.original`). - */ - baseUri?: Node | string; - /** - * Whether this request is a retry via a proxy (generally done from an error handler). - */ - proxyUsed?: boolean; - /** - * Flag for XHR/CORS etc - */ - withCredentials?: boolean; - /** - * Before we parse new data, clear old, but only on status 200 responses. - */ - clearPreviousData?: boolean; - /** - * Prevents the addition of various metadata triples (about the fetch request) to the store. - */ - noMeta?: boolean; - noRDFa?: boolean; -} -/** -* Responsible for fetching RDF data -*/ -export class Fetcher { - store: any; - timeout: number; - appNode: BlankNode; - requested: { - [uri: string]: any; - }; - timeouts: any; - redirectedTo: any; - constructor(store: any, options: any); - static HANDLERS: { - RDFXMLHandler: Handler; - XHTMLHandler: Handler; - XMLHandler: Handler; - HTMLHandler: Handler; - TextHandler: Handler; - N3Handler: Handler; - }; - static CONTENT_TYPE_BY_EXT: { - [ext: string]: string; - }; - /** - * Loads a web resource or resources into the store. - * @param uri Resource to load, provided either as a NamedNode object or a plain URL. If multiple resources are passed as an array, they will be fetched in parallel. - */ - load: (uri: ReadonlyArray | ReadonlyArray | NamedNode | string, options?: FetchOptions) => Promise; +export interface Bindings { + [id: string]: Node; } -/** -* Gets a node for the specified input -* @param value An input value -*/ -export function term(value: ValueType): Node | Collection | ValueType; -/** -* Gets a namespace -* @param nsuri The URI for the namespace -*/ -export function Namespace(nsuri: string): (ln: string) => NamedNode; -/** -* Transforms an NTriples string format into a Node. -* The bnode bit should not be used on program-external values; designed -* for internal work such as storing a bnode id in an HTML attribute. -* This will only parse the strings generated by the vaious toNT() methods. -* @param str A string representation -*/ -export function fromNT(str: string): Node; -/** -* Creates a new fetcher -* @param store The store to use -* @param options The options -*/ -export function fetcher(store: Formula, options: any): Fetcher; -/** -* Creates a new graph (store) -*/ -export function graph(): IndexedFormula; -/** -* Creates a new literal node -* @param val The lexical value -* @param lang The language -* @param dt The datatype -*/ -export function lit(val: string, lang: string, dt: NamedNode): Literal; -/** -* Creates a new statement -* @param subject The subject -* @param predicate The predicate -* @param object The object -* @param graph The containing graph -*/ -export function st( - subject: Node | Date | string, - predicate: Node, - object: Node | Date | string, - graph: Node -): Statement; -/** -* Creates a new named node -* @param value The new named node -*/ -export function sym(value: string): NamedNode; -/** -* Creates a new variable -* @param name The name for the variable -*/ -export function variable(name: string): Variable; -/** -* Creates a new blank node -* @param value The blank node's identifier -*/ -export function blankNode(value: string): BlankNode; -/** -* Gets the default graph -*/ -export function defaultGraph(): DefaultGraph; -/** -* Creates a new literal node -* @param value The lexical value -* @param languageOrDatatype Either the language or the datatype -*/ -export function literal( - value: string, - languageOrDatatype: string | NamedNode -): Literal; -/** -* Creates a new named node -* @param value The new named node -*/ -export function namedNode(value: string): NamedNode; -/** -* Creates a new statement -* @param subject The subject -* @param predicate The predicate -* @param object The object -* @param graph The containing graph -*/ -export function quad( - subject: Node, - predicate: Node, - object: Node, - graph: Node -): Statement; -/** -* Creates a new statement -* @param subject The subject -* @param predicate The predicate -* @param object The object -*/ -export function triple(subject: Node, predicate: Node, object: Node): Statement; -/** -* Parse a string and put the result into the graph kb. -* Normal method is sync. -* Unfortunately jsdonld is currently written to need to be called async. -* Hence the mess below with executeCallback. -* @param str The input string to parse -* @param kb The store to use -* @param base The base URI to use -* @param contentType The content type for the input -* @param callback The callback to call when the data has been loaded -*/ -export function parse( - str: string, - kb: Formula, - base: string, - contentType: string, - callback: (error: any, kb: Formula) => void -): void; -/** -* Get the next available unique identifier -*/ -export let NextId: number; - -/** -* The update manager is a helper object for a store. -* Just as a Fetcher provides the store with the ability to read and write, the Update Manager provides functionality for making small patches in real time, -* and also looking out for concurrent updates from other agents. -*/ -export class UpdateManager { - /** - * @param store The quadstore to store data and metadata. Created if not passed. - */ - constructor(store?: IndexedFormula) - - /** - * This is suitable for an initial creation of a document. - * @param document - * @param data - * @param contentType - * @param callback - */ - put( - document: Node, - data: string | ReadonlyArray, - contentType: string, - callback: (uri: string, ok: boolean, errorMessage: string, response?: unknown) => void, - ): Promise; - - /** - * This high-level function updates the local store iff the web is changed successfully. - * Deletions, insertions may be undefined or single statements or lists or formulae (may contain bnodes which can be indirectly identified by a where clause). - * The `why` property of each statement must be the same and give the web document to be updated. - * @param statementsToDelete Statement or statements to be deleted. - * @param statementsToAdd Statement or statements to be inserted. - * @param callback - */ - update( - statementsToDelete: ReadonlyArray, - statementsToAdd: ReadonlyArray, - callback: (uri: string | undefined, success: boolean, errorBody?: string) => void - ): void; diff --git a/src/variable.js b/src/variable.js index 5632e7965..7b88bb2a8 100644 --- a/src/variable.js +++ b/src/variable.js @@ -1,6 +1,6 @@ 'use strict' import ClassOrder from './class-order' -import Node from './node' +import Node from './node-internal' import * as Uri from './uri' /** diff --git a/types-temp.ts b/types-temp.ts new file mode 100644 index 000000000..43d106a08 --- /dev/null +++ b/types-temp.ts @@ -0,0 +1,1403 @@ +// This is a Temporary file to help with the migration to typescript. +// See issue: https://github.com/linkeddata/rdflib.js/issues/355 +// Don't import types from this file. +// When you do use a type from this file, move it to `./types.ts` +// And import it here. + +import { + Bindings, + ValueType, +} from './src/types'; + +// Type definitions for rdflib 0.20 +// Project: http://github.com/linkeddata/rdflib.js +// Definitions by: Cénotélie +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 +// Acknowledgements: This work has been financed by Logilab SA, FRANCE, logilab.fr + +/** +* Class orders +*/ +export const ClassOrder: { + [id: string]: number; +}; +/** +* The superclass of all RDF Statement objects, that is NamedNode, Literal, BlankNode, etc. +*/ +export interface Node { + /** + * The type of node + */ + termType: string; + /** + * Whether this node is a variable + */ + isVar: boolean; + /** + * The class order for this node + */ + classOrder: number; + /** + * The nod's value + */ + value: string; + /** + * Gets the substituted node for this one, according to the specified bindings + * @param bindings Bindings of identifiers to nodes + */ + substitute(bindings: Bindings): Node; + /** + * Compares this node with another + * @param term The other node + */ + compareTerm(term: Node): number; + /** + * Gets whether the two nodes are equal + * @param other The other node + */ + equals(other: Node): boolean; + /** + * Gets a hash for this node + */ + hashString(): string; + /** + * Gets whether this node is the same as the other one + * @param other Another node + */ + sameTerm(other: Node): boolean; + /** + * Gets the canonical string representation of this node + */ + toCanonical(): string; + /** + * Gets the n-triples string representation of this node + */ + toNT(): string; + /** + * Gets the string representation of this node + */ + toString(): string; + /** + * Gets a node for the specifed input + * @param value An input value + */ + static fromValue(value: ValueType | Node): Node; + /** + * Gets the javascript object equivalent to a node + * @param term The RDF node + */ + static toJS(term: Node): any; +} +/** +* An empty node +*/ +export interface Empty extends Node { + constructor(); + static termType: string; +} +/** +* A collection of other RDF nodes +*/ +export interface Collection extends Node { + /** + * The identifier for this collection + */ + id: string; + /** + * The nodes in this collection + */ + elements: Node[]; + /** + * Whether this collection is closed + */ + closed: boolean; + /** + * Initializes this collection + * @param initial The initial elements + */ + constructor(initial: ReadonlyArray); + /** + * Appends an element to this collection + * @param element The new element + */ + append(element: Node): number; + /** + * Closes this collection + */ + close(): boolean; + /** + * Removes the first element from the collection (and return it) + */ + shift(): Node; + /** + * Preprends the specified element to the colelction's front + * @param element The element to preprend + */ + unshift(element: Node): number; + static termType: string; +} +/** +* An RDF blank node +*/ +export interface BlankNode extends Node { + /** + * The identifier for the blank node + */ + id: string; + /** + * Whether this is a blank node + */ + isBlank: boolean; + /** + * Initializes this node + * @param id The identifier for the blank node + */ + constructor(id: string); + /** + * Gets a copy of this blank node in the specified formula + * @param formula The formula + */ + copy(formula: Formula): BlankNode; + /** + * The next unique identifier for blank nodes + */ + static nextId: number; + static termType: string; + static NTAnonymousNodePrefix: string; +} +/** +* A named (IRI) RDF node +*/ +export interface NamedNode extends Node { + /** + * The URI for this node + */ + uri: string; + /** + * Initializes this node + * @param iri The IRI for this node + */ + constructor(iri: NamedNode | string); + /** + * Returns an RDF node for the containing directory, ending in slash. + */ + dir(): NamedNode; + /** + * Returns an named node for the whole web site, ending in slash. + * Contrast with the "origin" which does NOT have a trailing slash + */ + site(): NamedNode; + /** + * Gets the named node for the document + */ + doc(): NamedNode; + static termType: string; + /** + * Gets a named node from the specified input value + * @param value An input value + */ + static fromValue(value: ValueType): NamedNode | ValueType; +} +/** +* A RDF literal node +*/ +export interface Literal extends Node { + /** + * The language for the literal + */ + lang: string; + /** + * The language for the literal + */ + language: string; + /** + * The literal's datatype as a named node + */ + datatype: NamedNode; + /** + * Initializes this literal + * @param value The literal's lexical value + * @param language The language for the literal + * @param datatype The literal's datatype as a named node + */ + constructor(value: string, language?: string, datatype?: NamedNode); + /** + * Gets a copy of this literal + */ + copy(): Literal; + static termType: string; + /** + * Builds a literal node from a boolean value + * @param value The value + */ + static fromBoolean(value: boolean): Literal; + /** + * Builds a literal node from a date value + * @param value The value + */ + static fromDate(value: Date): Literal; + /** + * Builds a literal node from a number value + * @param value The value + */ + static fromNumber(value: number): Literal; + /** + * Builds a literal node from an input value + * @param value The input value + */ + static fromValue(value: ValueType): Literal | ValueType; +} +/** +* Variables are placeholders used in patterns to be matched. +* In cwm they are symbols which are the formula's list of quantified variables. +* In sparql they are not visibly URIs. Here we compromise, by having +* a common special base URI for variables. Their names are uris, +* but the ? notation has an implicit base uri of 'varid:' +*/ +export interface Variable extends Node { + /** + * The base string for a variable's name + */ + base: string; + /** + * The unique identifier of this variable + */ + uri: string; + /** + * Initializes this variable + * @param name The variable's name + */ + constructor(name?: string); + static termType: string; +} +/** +* The RDF default graph +*/ +export interface DefaultGraph extends Node { + /** + * Initializes this graph + */ + constructor(); +} +export namespace uri { + /** + * Gets the document part of an URI + * @param uri The URI + */ + function docpart(uri: string): string; + /** + * Gets the document part of an URI as a named node + * @param x The URI + */ + function document(x: string): NamedNode; + /** + * Gets the hostname in an URI + * @param u The URI + */ + function hostpart(u: string): string; + /** + * Joins an URI with a base + * @param given The relative part + * @param base The base URI + */ + function join(given: string, base: string): string; + /** + * Gets the protocol part of an URI + * @param uri The URI + */ + function protocol(uri: string): string; + /** + * Gets a relative uri + * @param base The base URI + * @param uri The absolute URI + */ + function refTo(base: string, uri: string): string; +} +export namespace log { + /** + * Logs a debug event + * @param x The event + */ + function debug(x: any): void; + /** + * Logs a warning event + * @param x The event + */ + function warn(x: any): void; + /** + * Logs an information event + * @param x The event + */ + function info(x: any): void; + /** + * Logs an error event + * @param x The event + */ + function error(x: any): void; + /** + * Logs a success event + * @param x The event + */ + function success(x: any): void; + /** + * Logs a message event + * @param x The event + */ + function msg(x: any): void; +} +/** +* An RDF statement (subject, predicate, object) +*/ +export interface Statement { + /** + * The statement's subject + */ + subject: Node; + /** + * The statement's predicate + */ + predicate: Node; + /** + * The statement's object + */ + object: Node; + /** + * The origin of this statement + */ + why: ValueType; + /** + * The graph the contains this statement + */ + graph: ValueType; + /** + * Initializes this statement + * @param subject The statement's subject + * @param predicate The statement's predicate + * @param object The statement's object + * @param graph The graph the contains this statement + */ + constructor( + subject: ValueType, + predicate: ValueType, + object: ValueType, + graph: ValueType + ); + /** + * Gets whether two statements are the same + * @param other The other statement + */ + equals(other: Statement): boolean; + /** + * Gets this statement with the bindings substituted + * @param bindings The bindings + */ + substitute(bindings: Bindings): Statement; + /** + * Gets the canonical string representation of this statement + */ + toCanonical(): string; + /** + * Gets the n-triples string representation of this statement + */ + toNT(): string; + /** + * Gets the string representation of this statement + */ + toString(): string; +} +export namespace convert { + /** + * Converts an n3 string to JSON + * @param n3String The n3 string + * @param jsonCallback Callback when the operation terminated + */ + function convertToJson( + n3String: string, + jsonCallback: (err: string, jsonString: string) => void + ): void; + /** + * Converts an n3 string to n-quads + * @param n3String The n3 string + * @param nquadCallback Callback when the operation terminated + */ + function convertToNQuads( + n3String: string, + nquadCallback: (err: string, nquadString: string) => void + ): void; +} +/** +* A formula, or store of RDF statements +*/ +export interface Formula extends Node { + /** + * The stored statements + */ + statements: Statement[]; + /** + * Initializes this formula + * @param statements The initial statements in this formulat + * @param constraints The additional constraints + * @param initBindings The initial bindings + * @param optional + */ + constructor( + statements: ReadonlyArray, + constraints: ReadonlyArray, + initBindings: { + [id: string]: Node; + }, + optional: ReadonlyArray + ); + /** + * Adds a statement to this formula + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + add(s: Node, p: NamedNode, o: Node, g: NamedNode): number; + /** + * Adds a statement to this formula + * @param st The statement to add + */ + addStatement(st: Statement): number; + /** + * Gets a blank node + * @param id The node's identifier + */ + bnode(id: string): BlankNode; + /** + * Adds all the statements to this formula + * @param statements A collection of statements + */ + addAll(statements: Iterable): void; + /** + * Gets a node that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + any( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): Node | null; + /** + * Gets the value of a node that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + anyValue( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): string; + /** + * Gets the first JavaScript object equivalent to a node based on the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + anyJS( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): any; + /** + * Gets the first statement that matches the specified pattern + * @param subj The subject + * @param pred The predicate + * @param obj The object + * @param why The graph that contains the statement + */ + anyStatementMatching( + subj?: Node | null, + pred?: Node | null, + obj?: Node | null, + why?: Node | null + ): Statement; + /** + * Gets the statements matching the specified pattern + * @param subj The subject + * @param pred The predicate + * @param obj The object + * @param why The graph that contains the statement + * @param justOne Whether to only get one statement + */ + statementsMatching( + subj?: Node | null, + pred?: Node | null, + obj?: Node | null, + why?: Node | null, + justOne?: boolean + ): Statement[]; + /** + * Finds the types in the list which have no *stored* subtypes + * These are a set of classes which provide by themselves complete + * information -- the other classes are redundant for those who + * know the class DAG. + * @param types A map of the types + */ + bottomTypeURIs(types: { + [id: string]: string | NamedNode; + }): { + [id: string]: string | NamedNode; + }; + /** + * Gets a new collection + */ + collection(): Collection; + /** + * Gets each node that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + each( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): Node[]; + /** + * Gets whether this formula is equals to the other one + * @param other The other formula + */ + equals(other: Formula): boolean; + /** + * For thisClass or any subclass, anything which has it is its type + * or is the object of something which has the type as its range, or subject + * of something which has the type as its domain + * We don't bother doing subproperty (yet?)as it doesn't seeem to be used + * much. + * Get all the Classes of which we can RDFS-infer the subject is a member + * @param thisClass A named node + */ + findMembersNT( + thisClass: Node + ): { + [uri: string]: Statement; + }; + /** + * For thisClass or any subclass, anything which has it is its type + * or is the object of something which has the type as its range, or subject + * of something which has the type as its domain + * We don't bother doing subproperty (yet?)as it doesn't seeem to be used + * much. + * Get all the Classes of which we can RDFS-infer the subject is a member + * @param subject A named node + */ + findMemberURIs( + subject: Node + ): { + [uri: string]: Statement; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a superclass + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findSubClassesNT( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a subclass + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findSuperClassesNT( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a member + * todo: This will loop is there is a class subclass loop (Sublass loops are + * not illegal) + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findTypesNT( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a member + * todo: This will loop is there is a class subclass loop (Sublass loops are + * not illegal) + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findTypeURIs( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Trace the statements which connect directly, or through bnodes + * Returns an array of statements + * doc param may be null to search all documents in store + * @param subject A subject node + * @param doc A document (the graph that contains statements) + * @param excludePredicateURIs The predicate URIs to exclude + */ + connectedStatements( + subject: Node, + doc: ValueType, + excludePredicateURIs: ReadonlyArray + ): Statement[]; + /** + * Creates a new empty formula - features not applicable, but necessary for typing to pass + */ + formula(features?: ReadonlyArray): Formula; + /** + * Transforms an NTriples string format into a Node. + * The bnode bit should not be used on program-external values; designed + * for internal work such as storing a bnode id in an HTML attribute. + * This will only parse the strings generated by the vaious toNT() methods. + * @param str A string representation + */ + fromNT(str: string): Node; + /** + * Gets whether this formula holds the specified statement + * @param s A subject + * @param p A predicate + * @param o An object + * @param g A containing graph + */ + holds( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): boolean; + /** + * Gets whether this formula holds the specified statement + * @param st A statement + */ + holdsStatement(st: Statement): boolean; + /** + * Gets a collection from a list of values + * @param values The values + */ + list(values: Iterable): Collection; + /** + * Gets a literal node + * @param val The literal's lexical value + * @param lang The language + * @param dt The datatype as a named node + */ + literal(val: string, lang: string, dt: NamedNode): Literal; + /** + * Transform a collection of NTriple URIs into their URI strings + * @param t some iterable colletion of NTriple URI strings + * @return a collection of the URIs as strings + */ + NTtoURI(t: { + [uri: string]: any; + }): { + [uri: string]: any; + }; + /** + * Serializes this formula + * @param base The base string + * @param contentType The content type of the syntax to use + * @param provenance The provenance URI + */ + serialize(base: string, contentType: string, provenance: string): string; + /** + * Gets a new formula with the substituting bindings applied + * @param bindings The bindings to substitute + */ + substitute(bindings: Bindings): Formula; + /** + * Gets an named node for an URI + * @param uri The URI + */ + sym(uri: string | NamedNode): NamedNode; + /** + * Gets the node matching the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + the( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): Node; + /** + * RDFS Inference + * These are hand-written implementations of a backward-chaining reasoner + * over the RDFS axioms. + * @param seeds A hash of NTs of classes to start with + * @param predicate The property to trace though + * @param inverse Trace inverse direction + */ + transitiveClosure( + seeds: { + [uri: string]: boolean; + }, + predicate: Node, + inverse: Node + ): { + [uri: string]: boolean; + }; + /** + * Finds the types in the list which have no *stored* supertypes + * We exclude the universal class, owl:Things and rdf:Resource, as it is + * information-free. + * @param types The types + */ + topTypeURIs(types: { + [id: string]: string | NamedNode; + }): { + [id: string]: string | NamedNode; + }; + /** + * Gets the number of statements in this formulat that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + whether( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): number; + /** + * Serializes this formulat to a string + */ + toString(): string; + /** + * Gets a namespace for the specified namespace's URI + * @param nsuri The URI for the namespace + */ + ns(nsuri: string): (ln: string) => NamedNode; + /** + * Gets a new variable + * @param name The variable's name + */ + variable(name: string): Variable; + static termType: string; +} + +export class Query { + pat: IndexedFormula; + name: string; + id?: string; + constructor(name: string, id?: any); + } + +/** +* A formula (set of triples) which indexes by predicate, subject and object. +* It "smushes" (merges into a single node) things which are identical +* according to owl:sameAs or an owl:InverseFunctionalProperty +* or an owl:FunctionalProperty +*/ +export class IndexedFormula extends Formula { + /** + * An UpdateManager initialised to this store + */ + updater?: UpdateManager; + /** + * Creates a new formula + * @param features The list of features to support + */ + constructor(features: ReadonlyArray); + /** + * Dictionary of namespace prefixes + */ + namespaces: {[key: string]: string}; + /** + * Gets the URI of the default graph + */ + static defaultGraphURI(): string; + /** + * Gets this graph with the bindings substituted + * @param bindings The bindings + */ + substitute(bindings: Bindings): IndexedFormula; + + /** + * Apply a set of statements to be deleted and to be inserted + * + * @param patch The set of statements to be deleted and to be inserted + * @param target The name of the document to patch + * @param patchCallback Callback to be called when patching is complete + */ + applyPatch( + patch: { + delete?: ReadonlyArray, + patch?: ReadonlyArray + }, + target: NamedNode, + patchCallback: () => void + ): void; + + /** + * N3 allows for declaring blank nodes, this function enables that support + * + * @param x The blank node to be declared, supported in N3 + */ + declareExistential(x: Node): Node; + + /** + * @param features + */ + initPropertyActions(features: Array<('sameAs' | 'InverseFunctionalProperty' | 'FunctionalProperty')>): boolean; + /** + * Returns the symbol with canonical URI as smushed + * @param term A RDF node + */ + canon(term: Node): Node; + /** + * Checks this formula for consistency + */ + check(): void; + /** + * Checks a list of statements for consistency + * @param sts The list of statements to check + * @param from An index with the array ['subject', 'predicate', 'object', 'why'] + */ + checkStatementList(sts: ReadonlyArray, from: number): boolean; + /** + * Closes this formula (and return it) + */ + close(): IndexedFormula; + /** + * replaces @template with @target and add appropriate triples + * removes no triples by default and is a one-direction replication + * @param template node to copy + * @param target node to copy to + * @param flags Whether or not to do a two-directional copy and/or delete triples + * + */ + copyTo( + template: Node, + target: Node, + flags?: Array<('two-direction' | 'delete')> + ): void; + /** + * Simplify graph in store when we realize two identifiers are equivalent + * We replace the bigger with the smaller. + * @param u1 The first node + * @param u2 The second node + */ + equate(u1: Node, u2: Node): boolean; + /** + * Creates a new empty indexed formula + * Only applicable for IndexedFormula, but TypeScript won't allow a subclass to override a property + * @param features The list of features + */ + formula(features: ReadonlyArray): IndexedFormula; + /** + * The number of statements in this formula + */ + length: number; + /** + * eturns any quads matching the given arguments. + * Standard RDFJS Taskforce method for Source objects, implemented as an + * alias to `statementsMatching()` + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The graph that contains the statement + */ + match( + subject: ValueType, + predicate: ValueType, + object: ValueType, + graph: ValueType + ): Statement[]; + /** + * Find out whether a given URI is used as symbol in the formula + * @param uri The URI to look for + */ + mentionsURI(uri: string): boolean; + /** + * Existentials are BNodes - something exists without naming + * @param uri An URI + */ + newExistential(uri: string): Node; + + /** + * Adds a new property action + * @param pred the predicate that the function should be triggered on + * @param action the function that should trigger + */ + newPropertyAction(pred: Node, action: (store: IndexedFormula, subject: NamedNode, object: NamedNode) => boolean): boolean; + /** + * Creates a new universal node + * Universals are Variables + * @param uri An URI + */ + newUniversal(uri: string): Node; + /** + * Find an unused id for a file being edited: return a symbol + * (Note: Slow iff a lot of them -- could be O(log(k)) ) + * @param doc A document named node + */ + nextSymbol(doc: NamedNode): NamedNode; + + /** + * Query this store asynchronously, return bindings in callback + * + * @param myQuery The query to be run + * @param callback Function to call when bindings + * @param dummy OBSOLETE - do not use this + * @param onDone OBSOLETE - do not use this + */ + query( + myQuery: Query, + callback: (bindings: Bindings) => void, + dummy?: null, + onDone?: () => void + ): void; + /** + * Query this store synchronously and return bindings + * + * @param myQuery The query to be run + */ + querySync(myQuery: Query): Bindings[]; + /** + * Removes a statement from this formula + * @param st A statement to remove + */ + remove(st: Statement): IndexedFormula; + /** + * Removes all statemnts in a doc + * @param doc The document + */ + removeDocument(doc: NamedNode): IndexedFormula; + /** + * Remove all statements matching args (within limit) * + * @param subj The subject + * @param pred The predicate + * @param obj The object + * @param why The graph that contains the statement + * @param limit The number of statements to remove + */ + removeMany( + subj?: Node | null, + pred?: Node | null, + obj?: Node | null, + why?: Node | null, + limit?: number + ): void; + /** + * Remove all matching statements + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The graph that contains the statement + */ + removeMatches( + subject?: Node | null, + predicate?: Node | null, + object?: Node | null, + graph?: Node | null + ): void; + /** + * Removes a statement + * @param st The statement to remove + */ + removeStatement(st: Statement): Formula; + /** + * Removes statements + * @param sts The statements to remove + */ + removeStatements(sts: ReadonlyArray): Formula; + /** + * Return all equivalent URIs by which this is known + * @param x A named node + */ + allAliases(x: NamedNode): NamedNode[]; + /** + * Compare by canonical URI as smushed + * @param x A named node + * @param y Another named node + */ + sameThings(x: NamedNode, y: NamedNode): boolean; + /** + * A list of all the URIs by which this thing is known + * @param term + */ + uris(term: NamedNode): string[]; +} +export namespace DataFactory { + /** + * Creates a new blank node + * @param value The blank node's identifier + */ + function blankNode(value: string): BlankNode; + /** + * Creates a new collection + * @param elements The initial element + */ + function collection(elements: ReadonlyArray): Collection; + /** + * Gets the default graph + */ + function defaultGraph(): DefaultGraph; + /** + * Creates a new fetcher + * @param store The store to use + * @param options The options + */ + function fetcher(store: Formula, options: any): Fetcher; + /** + * Creates a new graph (store) + */ + function graph(): IndexedFormula; + /** + * Creates a new literal node + * @param val The lexical value + * @param lang The language + * @param dt The datatype + */ + function lit(val: string, lang?: string, dt?: NamedNode): Literal; + /** + * Creates a new literal node + * @param value The lexical value + * @param languageOrDatatype Either the language or the datatype + */ + function literal( + value: string, + languageOrDatatype?: string | NamedNode + ): Literal; + /** + * Creates a new named node + * @param value The new named node + */ + function namedNode(value: string): NamedNode; + /** + * Creates a new statement + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The containing graph + */ + function quad( + subject: Node, + predicate: Node, + object: Node, + graph: Node + ): Statement; + /** + * Creates a new statement + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The containing graph + */ + function st( + subject: Node, + predicate: Node, + object: Node, + graph: Node + ): Statement; + /** + * Creates a new statement + * @param subject The subject + * @param predicate The predicate + * @param object The object + */ + function triple(subject: Node, predicate: Node, object: Node): Statement; + /** + * Creates a new variable + * @param name The name for the variable + */ + function variable(name?: string): Variable; +} +export namespace Util { + /** + * Gets a named node for a media type + * @param mediaType A media type + */ + function mediaTypeClass(mediaType: string): NamedNode; + /** + * Gets a named node from the name of a relation + * @param relation The name of a relation + */ + function linkRelationProperty(relation: string): NamedNode; + /** + * Loads ontologies of the data we load (this is the callback from the kb to + * the fetcher). Exports as `AJAR_handleNewTerm` + * @param kb The store + * @param p A property + * @param requestedBy + */ + function AJAR_handleNewTerm( + kb: Formula, + p: NamedNode, + requestedBy: string + ): Promise; +} +/** +* A datatype-specific handler for fetching data +*/ +export interface Handler { + response: any; + dom: any; +} +export interface FetchOptions { + fetch?: typeof fetch; + /** + * The resource which referred to this (for tracking bad links). + */ + referringTerm?: NamedNode; + /** + * Provided content type (for writes). + */ + contentType?: string; + /** + * Override the incoming header to force the data to be treated as this content-type (for reads). + */ + forceContentType?: string; + /** + * Load the data even if loaded before. Also sets the `Cache-Control:` header to `no-cache`. + */ + force?: boolean; + /** + * Original uri to preserve through proxying etc (`xhr.original`). + */ + baseUri?: Node | string; + /** + * Whether this request is a retry via a proxy (generally done from an error handler). + */ + proxyUsed?: boolean; + /** + * Flag for XHR/CORS etc + */ + withCredentials?: boolean; + /** + * Before we parse new data, clear old, but only on status 200 responses. + */ + clearPreviousData?: boolean; + /** + * Prevents the addition of various metadata triples (about the fetch request) to the store. + */ + noMeta?: boolean; + noRDFa?: boolean; +} +/** +* Responsible for fetching RDF data +*/ +export class Fetcher { + store: any; + timeout: number; + appNode: BlankNode; + requested: { + [uri: string]: any; + }; + timeouts: any; + redirectedTo: any; + constructor(store: any, options: any); + static HANDLERS: { + RDFXMLHandler: Handler; + XHTMLHandler: Handler; + XMLHandler: Handler; + HTMLHandler: Handler; + TextHandler: Handler; + N3Handler: Handler; + }; + static CONTENT_TYPE_BY_EXT: { + [ext: string]: string; + }; + /** + * Loads a web resource or resources into the store. + * @param uri Resource to load, provided either as a NamedNode object or a plain URL. If multiple resources are passed as an array, they will be fetched in parallel. + */ + load: (uri: ReadonlyArray | ReadonlyArray | NamedNode | string, options?: FetchOptions) => Promise; +} +/** +* Gets a node for the specified input +* @param value An input value +*/ +export function term(value: ValueType): Node | Collection | ValueType; +/** +* Gets a namespace +* @param nsuri The URI for the namespace +*/ +export function Namespace(nsuri: string): (ln: string) => NamedNode; +/** +* Transforms an NTriples string format into a Node. +* The bnode bit should not be used on program-external values; designed +* for internal work such as storing a bnode id in an HTML attribute. +* This will only parse the strings generated by the vaious toNT() methods. +* @param str A string representation +*/ +export function fromNT(str: string): Node; +/** +* Creates a new fetcher +* @param store The store to use +* @param options The options +*/ +export function fetcher(store: Formula, options: any): Fetcher; +/** +* Creates a new graph (store) +*/ +export function graph(): IndexedFormula; +/** +* Creates a new literal node +* @param val The lexical value +* @param lang The language +* @param dt The datatype +*/ +export function lit(val: string, lang: string, dt: NamedNode): Literal; +/** +* Creates a new statement +* @param subject The subject +* @param predicate The predicate +* @param object The object +* @param graph The containing graph +*/ +export function st( + subject: Node | Date | string, + predicate: Node, + object: Node | Date | string, + graph: Node +): Statement; +/** +* Creates a new named node +* @param value The new named node +*/ +export function sym(value: string): NamedNode; +/** +* Creates a new variable +* @param name The name for the variable +*/ +export function variable(name: string): Variable; +/** +* Creates a new blank node +* @param value The blank node's identifier +*/ +export function blankNode(value: string): BlankNode; +/** +* Gets the default graph +*/ +export function defaultGraph(): DefaultGraph; +/** +* Creates a new literal node +* @param value The lexical value +* @param languageOrDatatype Either the language or the datatype +*/ +export function literal( + value: string, + languageOrDatatype: string | NamedNode +): Literal; +/** +* Creates a new named node +* @param value The new named node +*/ +export function namedNode(value: string): NamedNode; +/** +* Creates a new statement +* @param subject The subject +* @param predicate The predicate +* @param object The object +* @param graph The containing graph +*/ +export function quad( + subject: Node, + predicate: Node, + object: Node, + graph: Node +): Statement; +/** +* Creates a new statement +* @param subject The subject +* @param predicate The predicate +* @param object The object +*/ +export function triple(subject: Node, predicate: Node, object: Node): Statement; +/** +* Parse a string and put the result into the graph kb. +* Normal method is sync. +* Unfortunately jsdonld is currently written to need to be called async. +* Hence the mess below with executeCallback. +* @param str The input string to parse +* @param kb The store to use +* @param base The base URI to use +* @param contentType The content type for the input +* @param callback The callback to call when the data has been loaded +*/ +export function parse( + str: string, + kb: Formula, + base: string, + contentType: string, + callback: (error: any, kb: Formula) => void +): void; +/** +* Get the next available unique identifier +*/ +export let NextId: number; + +/** +* The update manager is a helper object for a store. +* Just as a Fetcher provides the store with the ability to read and write, the Update Manager provides functionality for making small patches in real time, +* and also looking out for concurrent updates from other agents. +*/ +export class UpdateManager { + /** + * @param store The quadstore to store data and metadata. Created if not passed. + */ + constructor(store?: IndexedFormula) + + /** + * This is suitable for an initial creation of a document. + * @param document + * @param data + * @param contentType + * @param callback + */ + put( + document: Node, + data: string | ReadonlyArray, + contentType: string, + callback: (uri: string, ok: boolean, errorMessage: string, response?: unknown) => void, + ): Promise; + + /** + * This high-level function updates the local store iff the web is changed successfully. + * Deletions, insertions may be undefined or single statements or lists or formulae (may contain bnodes which can be indirectly identified by a where clause). + * The `why` property of each statement must be the same and give the web document to be updated. + * @param statementsToDelete Statement or statements to be deleted. + * @param statementsToAdd Statement or statements to be inserted. + * @param callback + */ + update( + statementsToDelete: ReadonlyArray, + statementsToAdd: ReadonlyArray, + callback: (uri: string | undefined, success: boolean, errorBody?: string) => void + ): void; From f078b3c4945b513ff9d94fc975baa142320f6a84 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Mon, 7 Oct 2019 21:03:08 +0200 Subject: [PATCH 04/10] Literal and NamedNode to ts #355 --- src/{literal.js => literal.ts} | 87 ++++++++++++++++++---------- src/{named-node.js => named-node.ts} | 77 ++++++++++++++---------- src/node-internal.ts | 2 +- src/node.ts | 2 +- src/types.ts | 2 +- 5 files changed, 109 insertions(+), 61 deletions(-) rename src/{literal.js => literal.ts} (67%) rename src/{named-node.js => named-node.ts} (55%) diff --git a/src/literal.js b/src/literal.ts similarity index 67% rename from src/literal.js rename to src/literal.ts index 4c989bf31..6850add1e 100644 --- a/src/literal.js +++ b/src/literal.ts @@ -1,13 +1,36 @@ 'use strict' -import ClassOrder from './class-order' import NamedNode from './named-node' import Node from './node-internal' import XSD from './xsd' +import { ValueType } from './types' +import classOrder from './class-order' +/** +* An RDF literal node, containing something different than a URI. +* @link https://rdf.js.org/data-model-spec/#literal-interface +*/ export default class Literal extends Node { - constructor (value, language, datatype) { + /** + * The language for the literal + */ + lang!: string + + /** + * The literal's datatype as a named node + */ + datatype!: NamedNode + + termType: string + + /** + * Initializes this literal + * @param value The literal's lexical value + * @param language The language for the literal + * @param datatype The literal's datatype as a named node + */ + constructor (value: string, language?: string | null, datatype?: NamedNode) { super() - this.termType = Literal.termType + this.termType = 'Literal' this.value = value if (language) { this.lang = language @@ -17,8 +40,14 @@ export default class Literal extends Node { if (datatype) { this.datatype = NamedNode.fromValue(datatype) } + if (!datatype) { + this.datatype = XSD.string + } } - copy () { + /** + * Gets a copy of this literal + */ + copy (): Literal { return new Literal(this.value, this.lang, this.datatype) } equals (other) { @@ -31,7 +60,10 @@ export default class Literal extends Node { ((!this.datatype && !other.datatype) || (this.datatype && this.datatype.equals(other.datatype))) } - get language () { + /** + * The language for the literal + */ + get language (): string { return this.lang } set language (language) { @@ -61,23 +93,21 @@ export default class Literal extends Node { toString () { return '' + this.value } + /** - * @method fromBoolean - * @static - * @param value {Boolean} - * @return {Literal} + * Builds a literal node from a boolean value + * @param value The value */ - static fromBoolean (value) { + static fromBoolean(value: boolean): Literal { let strValue = value ? '1' : '0' return new Literal(strValue, null, XSD.boolean) } + /** - * @method fromDate - * @static - * @param value {Date} - * @return {Literal} + * Builds a literal node from a date value + * @param value The value */ - static fromDate (value) { + static fromDate(value: Date): Literal { if (!(value instanceof Date)) { throw new TypeError('Invalid argument to Literal.fromDate()') } @@ -89,13 +119,12 @@ export default class Literal extends Node { d2(value.getUTCMinutes()) + ':' + d2(value.getUTCSeconds()) + 'Z' return new Literal(date, null, XSD.dateTime) } + /** - * @method fromNumber - * @static - * @param value {Number} - * @return {Literal} + * Builds a literal node from a number value + * @param value The value */ - static fromNumber (value) { + static fromNumber(value: number): Literal { if (typeof value !== 'number') { throw new TypeError('Invalid argument to Literal.fromNumber()') } @@ -108,17 +137,18 @@ export default class Literal extends Node { } return new Literal(strValue, null, datatype) } + /** - * @method fromValue - * @param value - * @return {Literal} + * Builds a literal node from an input value + * @param value The input value */ - static fromValue (value) { + static fromValue(value: ValueType): Literal | Node | undefined | null { if (typeof value === 'undefined' || value === null) { return value } + // @ts-ignore if (typeof value === 'object' && value.termType) { // this is a Node instance - return value + return value as Node } switch (typeof value) { case 'object': @@ -126,7 +156,7 @@ export default class Literal extends Node { return Literal.fromDate(value) } case 'boolean': - return Literal.fromBoolean(value) + return Literal.fromBoolean(value as boolean) case 'number': return Literal.fromNumber(value) case 'string': @@ -137,8 +167,7 @@ export default class Literal extends Node { } } -Literal.termType = 'Literal' -Literal.prototype.classOrder = ClassOrder['Literal'] -Literal.prototype.datatype = XSD.string + +Literal.prototype.classOrder = classOrder['Literal'] Literal.prototype.lang = '' Literal.prototype.isVar = false diff --git a/src/named-node.js b/src/named-node.ts similarity index 55% rename from src/named-node.js rename to src/named-node.ts index b806386ca..0b4284255 100644 --- a/src/named-node.js +++ b/src/named-node.ts @@ -1,54 +1,58 @@ -'use strict' import ClassOrder from './class-order' import Node from './node-internal' +import { ValueType } from './types'; /** - * @class NamedNode - * @extends Node - */ +* A named (IRI) RDF node +*/ export default class NamedNode extends Node { + static termType: string; + /** - * @constructor - * @param iri {String} + * Initializes this node + * @param iri The IRI for this node */ - constructor (iri) { + constructor (iri: NamedNode | string) { super() this.termType = NamedNode.termType - if (iri && iri.termType === NamedNode.termType) { // param is a named node - iri = iri.value + if (iri && (iri as NamedNode).termType === NamedNode.termType) { // param is a named node + iri = (iri as NamedNode).value } if (!iri) { throw new Error('Missing IRI for NamedNode') } - if (!iri.includes(':')) { + const iriString = iri as string + + if (!iriString.includes(':')) { throw new Error('NamedNode IRI "' + iri + '" must be absolute.') } - if (iri.includes(' ')) { + if (iriString.includes(' ')) { var message = 'Error: NamedNode IRI "' + iri + '" must not contain unencoded spaces.' throw new Error(message) } - this.value = iri + this.value = iriString } /** - * Returns an $rdf node for the containing directory, ending in slash. + * Returns an RDF node for the containing directory, ending in slash. */ - dir () { + dir (): NamedNode | null{ var str = this.uri.split('#')[0] var p = str.slice(0, -1).lastIndexOf('/') var q = str.indexOf('//') if ((q >= 0 && p < q + 2) || p < 0) return null return new NamedNode(str.slice(0, p + 1)) } - /** - * Returns an NN for the whole web site, ending in slash. - * Contrast with the "origin" which does NOT have a trailing slash - */ - site () { + + /** + * Returns an NamedNOde for the whole web site, ending in slash. + * Contrast with the "origin" which does NOT have a trailing slash + */ + site (): NamedNode { var str = this.uri.split('#')[0] var p = str.indexOf('//') if (p < 0) throw new Error('This URI does not have a web site part (origin)') @@ -59,19 +63,28 @@ export default class NamedNode extends Node { return new NamedNode(str.slice(0, q + 1)) } } - doc () { + + /** + * Gets the named node for the document + */ + doc (): NamedNode { if (this.uri.indexOf('#') < 0) { return this } else { return new NamedNode(this.uri.split('#')[0]) } } - toString () { + + /** + * Returns the URI including + */ + toString (): string { return '<' + this.uri + '>' } - /* The local identifier with the document - */ + /** + * The local identifier with the document + */ id () { return this.uri.split('#')[1] } @@ -79,23 +92,29 @@ export default class NamedNode extends Node { /** * Legacy getter and setter alias, node.uri */ - get uri () { + get uri (): string { return this.value } - set uri (uri) { + set uri (uri: string) { this.value = uri } - static fromValue (value) { + + /** + * Gets a named node from the specified input value + * @param value An input value + */ + static fromValue(value: ValueType): NamedNode | null | undefined | Node { if (typeof value === 'undefined' || value === null) { return value } + // @ts-ignore const isNode = value && value.termType if (isNode) { - return value + return value as NamedNode } - return new NamedNode(value) + return new NamedNode(value as string) } } NamedNode.termType = 'NamedNode' NamedNode.prototype.classOrder = ClassOrder['NamedNode'] -NamedNode.prototype.isVar = 0 +NamedNode.prototype.isVar = false diff --git a/src/node-internal.ts b/src/node-internal.ts index 40987d354..7ffadad48 100644 --- a/src/node-internal.ts +++ b/src/node-internal.ts @@ -23,7 +23,7 @@ export default abstract class Node { /** * Whether this node is a variable */ - isVar!: boolean | 1 | 0; + isVar!: boolean; /** * The class order for this node diff --git a/src/node.ts b/src/node.ts index de2c3564c..4cb9d1b4d 100644 --- a/src/node.ts +++ b/src/node.ts @@ -13,7 +13,7 @@ export default Node * @method fromValue * @param value - Any native Javascript value */ -Node.fromValue = function (value: ValueType | null): Node | Literal | undefined | null | Collection { +Node.fromValue = function (value: ValueType): Node | Literal | undefined | null | Collection { if (typeof value === 'undefined' || value === null) { return value } diff --git a/src/types.ts b/src/types.ts index fc106eb00..4c84edb92 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,7 +3,7 @@ import Node from './node-internal'; /** * A type for values that serves as inputs */ -export type ValueType = Node | Date | string | number | boolean | undefined; +export type ValueType = Node | Date | string | number | boolean | undefined | null; export interface Bindings { [id: string]: Node; From 778b8cea44d9fd997eea700f1218e118bf549824 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Mon, 7 Oct 2019 21:23:25 +0200 Subject: [PATCH 05/10] Convert BlankNode, Empty and ClassOrder to ts #355 --- src/{blank-node.js => blank-node.ts} | 40 +++- src/{class-order.js => class-order.ts} | 9 +- src/{empty.js => empty.ts} | 5 +- types-temp.ts | 257 +------------------------ 4 files changed, 51 insertions(+), 260 deletions(-) rename src/{blank-node.js => blank-node.ts} (61%) rename src/{class-order.js => class-order.ts} (50%) rename src/{empty.js => empty.ts} (82%) diff --git a/src/blank-node.js b/src/blank-node.ts similarity index 61% rename from src/blank-node.js rename to src/blank-node.ts index 40aaffa36..2666d1510 100644 --- a/src/blank-node.js +++ b/src/blank-node.ts @@ -1,11 +1,37 @@ -'use strict' import ClassOrder from './class-order' import Node from './node-internal' +import { IndexedFormula } from './index'; +/** + * An RDF blank node is a Node without a URI + * @link https://rdf.js.org/data-model-spec/#blanknode-interface + */ export default class BlankNode extends Node { - constructor (id) { + /** + * The identifier for the blank node + */ + id: string; + + /** + * Whether this is a blank node + */ + isBlank: boolean; + + /** + * The next unique identifier for blank nodes + */ + static nextId: number; + static termType: string; + static NTAnonymousNodePrefix: string; + + /** + * Initializes this node + * @param id The identifier for the blank node + */ + constructor (id?: string) { super() this.termType = BlankNode.termType + this.isBlank = true if (id) { if (typeof id !== 'string') { @@ -42,7 +68,11 @@ export default class BlankNode extends Node { return 0 } - copy (formula) { // depends on the formula + /** + * Gets a copy of this blank node in the specified formula + * @param formula The formula + */ + copy (formula: IndexedFormula): BlankNode { // depends on the formula var bnodeNew = new BlankNode() formula.copyTo(this, bnodeNew) return bnodeNew @@ -61,5 +91,5 @@ BlankNode.nextId = 0 BlankNode.termType = 'BlankNode' BlankNode.NTAnonymousNodePrefix = '_:' BlankNode.prototype.classOrder = ClassOrder['BlankNode'] -BlankNode.prototype.isBlank = 1 -BlankNode.prototype.isVar = 1 +BlankNode.prototype.isBlank = true +BlankNode.prototype.isVar = true diff --git a/src/class-order.js b/src/class-order.ts similarity index 50% rename from src/class-order.js rename to src/class-order.ts index f2529983e..d614b56e5 100644 --- a/src/class-order.js +++ b/src/class-order.ts @@ -1,4 +1,9 @@ -export default { +/** +* Class orders +*/ +const ClassOrder: { + [id: string]: number; +} = { 'Literal': 1, 'Collection': 3, 'Graph': 4, @@ -6,3 +11,5 @@ export default { 'BlankNode': 6, 'Variable': 7 } + +export default ClassOrder diff --git a/src/empty.js b/src/empty.ts similarity index 82% rename from src/empty.js rename to src/empty.ts index 1bbe6bf50..47ea62a9d 100644 --- a/src/empty.js +++ b/src/empty.ts @@ -2,9 +2,10 @@ import Node from './node-internal' /** - * Singleton subclass of an empty Collection. - */ +* An empty node +*/ export default class Empty extends Node { + static termType: string constructor () { super() this.termType = Empty.termType diff --git a/types-temp.ts b/types-temp.ts index 43d106a08..b59f6f1c9 100644 --- a/types-temp.ts +++ b/types-temp.ts @@ -1,13 +1,15 @@ // This is a Temporary file to help with the migration to typescript. // See issue: https://github.com/linkeddata/rdflib.js/issues/355 +// Migrate these types and comments to the according files, then remove them from this list. // Don't import types from this file. -// When you do use a type from this file, move it to `./types.ts` +// When you do want to use a type from this file, move it to `./types.ts` // And import it here. import { Bindings, ValueType, } from './src/types'; +import { NamedNode } from './src'; // Type definitions for rdflib 0.20 // Project: http://github.com/linkeddata/rdflib.js @@ -16,86 +18,6 @@ import { // TypeScript Version: 3.0 // Acknowledgements: This work has been financed by Logilab SA, FRANCE, logilab.fr -/** -* Class orders -*/ -export const ClassOrder: { - [id: string]: number; -}; -/** -* The superclass of all RDF Statement objects, that is NamedNode, Literal, BlankNode, etc. -*/ -export interface Node { - /** - * The type of node - */ - termType: string; - /** - * Whether this node is a variable - */ - isVar: boolean; - /** - * The class order for this node - */ - classOrder: number; - /** - * The nod's value - */ - value: string; - /** - * Gets the substituted node for this one, according to the specified bindings - * @param bindings Bindings of identifiers to nodes - */ - substitute(bindings: Bindings): Node; - /** - * Compares this node with another - * @param term The other node - */ - compareTerm(term: Node): number; - /** - * Gets whether the two nodes are equal - * @param other The other node - */ - equals(other: Node): boolean; - /** - * Gets a hash for this node - */ - hashString(): string; - /** - * Gets whether this node is the same as the other one - * @param other Another node - */ - sameTerm(other: Node): boolean; - /** - * Gets the canonical string representation of this node - */ - toCanonical(): string; - /** - * Gets the n-triples string representation of this node - */ - toNT(): string; - /** - * Gets the string representation of this node - */ - toString(): string; - /** - * Gets a node for the specifed input - * @param value An input value - */ - static fromValue(value: ValueType | Node): Node; - /** - * Gets the javascript object equivalent to a node - * @param term The RDF node - */ - static toJS(term: Node): any; -} -/** -* An empty node -*/ -export interface Empty extends Node { - constructor(); - static termType: string; -} /** * A collection of other RDF nodes */ @@ -137,117 +59,7 @@ export interface Collection extends Node { unshift(element: Node): number; static termType: string; } -/** -* An RDF blank node -*/ -export interface BlankNode extends Node { - /** - * The identifier for the blank node - */ - id: string; - /** - * Whether this is a blank node - */ - isBlank: boolean; - /** - * Initializes this node - * @param id The identifier for the blank node - */ - constructor(id: string); - /** - * Gets a copy of this blank node in the specified formula - * @param formula The formula - */ - copy(formula: Formula): BlankNode; - /** - * The next unique identifier for blank nodes - */ - static nextId: number; - static termType: string; - static NTAnonymousNodePrefix: string; -} -/** -* A named (IRI) RDF node -*/ -export interface NamedNode extends Node { - /** - * The URI for this node - */ - uri: string; - /** - * Initializes this node - * @param iri The IRI for this node - */ - constructor(iri: NamedNode | string); - /** - * Returns an RDF node for the containing directory, ending in slash. - */ - dir(): NamedNode; - /** - * Returns an named node for the whole web site, ending in slash. - * Contrast with the "origin" which does NOT have a trailing slash - */ - site(): NamedNode; - /** - * Gets the named node for the document - */ - doc(): NamedNode; - static termType: string; - /** - * Gets a named node from the specified input value - * @param value An input value - */ - static fromValue(value: ValueType): NamedNode | ValueType; -} -/** -* A RDF literal node -*/ -export interface Literal extends Node { - /** - * The language for the literal - */ - lang: string; - /** - * The language for the literal - */ - language: string; - /** - * The literal's datatype as a named node - */ - datatype: NamedNode; - /** - * Initializes this literal - * @param value The literal's lexical value - * @param language The language for the literal - * @param datatype The literal's datatype as a named node - */ - constructor(value: string, language?: string, datatype?: NamedNode); - /** - * Gets a copy of this literal - */ - copy(): Literal; - static termType: string; - /** - * Builds a literal node from a boolean value - * @param value The value - */ - static fromBoolean(value: boolean): Literal; - /** - * Builds a literal node from a date value - * @param value The value - */ - static fromDate(value: Date): Literal; - /** - * Builds a literal node from a number value - * @param value The value - */ - static fromNumber(value: number): Literal; - /** - * Builds a literal node from an input value - * @param value The input value - */ - static fromValue(value: ValueType): Literal | ValueType; -} + /** * Variables are placeholders used in patterns to be matched. * In cwm they are symbols which are the formula's list of quantified variables. @@ -346,66 +158,7 @@ export namespace log { */ function msg(x: any): void; } -/** -* An RDF statement (subject, predicate, object) -*/ -export interface Statement { - /** - * The statement's subject - */ - subject: Node; - /** - * The statement's predicate - */ - predicate: Node; - /** - * The statement's object - */ - object: Node; - /** - * The origin of this statement - */ - why: ValueType; - /** - * The graph the contains this statement - */ - graph: ValueType; - /** - * Initializes this statement - * @param subject The statement's subject - * @param predicate The statement's predicate - * @param object The statement's object - * @param graph The graph the contains this statement - */ - constructor( - subject: ValueType, - predicate: ValueType, - object: ValueType, - graph: ValueType - ); - /** - * Gets whether two statements are the same - * @param other The other statement - */ - equals(other: Statement): boolean; - /** - * Gets this statement with the bindings substituted - * @param bindings The bindings - */ - substitute(bindings: Bindings): Statement; - /** - * Gets the canonical string representation of this statement - */ - toCanonical(): string; - /** - * Gets the n-triples string representation of this statement - */ - toNT(): string; - /** - * Gets the string representation of this statement - */ - toString(): string; -} + export namespace convert { /** * Converts an n3 string to JSON From 519584e0c7804095d752c38708d75a2ca6a62414 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Tue, 8 Oct 2019 11:02:03 +0200 Subject: [PATCH 06/10] Use Typedoc instead of JSDoc #355 --- package-lock.json | 285 ++++++++++++++++++++++++---------------------- package.json | 4 +- tsconfig.json | 2 +- typedoc.js | 18 +++ 4 files changed, 168 insertions(+), 141 deletions(-) create mode 100644 typedoc.js diff --git a/package-lock.json b/package-lock.json index ead45f5df..1ed2ed9db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1634,6 +1634,15 @@ } } }, + "backbone": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/backbone/-/backbone-1.4.0.tgz", + "integrity": "sha512-RLmDrRXkVdouTg38jcgHhyQ/2zjg7a8E6sz2zxfz21Hh17xDJYUHBZimVIt5fUyS8vbfpeSmTL3gUjTEvUV3qQ==", + "dev": true, + "requires": { + "underscore": ">=1.8.3" + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -2038,15 +2047,6 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, - "catharsis": { - "version": "0.8.11", - "resolved": "https://registry.npmjs.org/catharsis/-/catharsis-0.8.11.tgz", - "integrity": "sha512-a+xUyMV7hD1BrDQA/3iPV7oc+6W26BgVJO05PGEoatMyIuPScQKsde6i3YorWX1qs+AZjnJ18NqdKoCtKiNh1g==", - "dev": true, - "requires": { - "lodash": "^4.17.14" - } - }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", @@ -2839,12 +2839,6 @@ "tapable": "^1.0.0" } }, - "entities": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", - "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==", - "dev": true - }, "errno": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", @@ -4236,6 +4230,26 @@ "integrity": "sha512-d4sze1JNC454Wdo2fkuyzCr6aHcbL6PGGuFAz0Li/NcOm1tCHGnWDRmJP85dh9IhQErTc2svWFEX5xHIOo//kQ==", "dev": true }, + "handlebars": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.2.tgz", + "integrity": "sha512-cIv17+GhL8pHHnRJzGu2wwcthL5sb8uDKBHvZ2Dtu5s1YNt0ljbzKbamnc+gr69y7bzwQiBdr5+hOpRd5pnOdg==", + "dev": true, + "requires": { + "neo-async": "^2.6.0", + "optimist": "^0.6.1", + "source-map": "^0.6.1", + "uglify-js": "^3.1.4" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, "har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", @@ -4328,6 +4342,12 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, + "highlight.js": { + "version": "9.15.10", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.15.10.tgz", + "integrity": "sha512-RoV7OkQm0T3os3Dd2VHLNMoaoDVx77Wygln3n9l5YV172XonWG6rgQD3XnF/BuFFZw9A0TJgmMSO8FEWQgvcXw==", + "dev": true + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -4842,6 +4862,12 @@ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" }, + "jquery": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz", + "integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==", + "dev": true + }, "js-levenshtein": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz", @@ -4864,59 +4890,11 @@ "esprima": "^4.0.0" } }, - "js2xmlparser": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-4.0.0.tgz", - "integrity": "sha512-WuNgdZOXVmBk5kUPMcTcVUpbGRzLfNkv7+7APq7WiDihpXVKrgxo6wwRpRl9OQeEBgKCVk9mR7RbzrnNWC8oBw==", - "dev": true, - "requires": { - "xmlcreate": "^2.0.0" - } - }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, - "jsdoc": { - "version": "3.6.3", - "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.3.tgz", - "integrity": "sha512-Yf1ZKA3r9nvtMWHO1kEuMZTlHOF8uoQ0vyo5eH7SQy5YeIiHM+B0DgKnn+X6y6KDYZcF7G2SPkKF+JORCXWE/A==", - "dev": true, - "requires": { - "@babel/parser": "^7.4.4", - "bluebird": "^3.5.4", - "catharsis": "^0.8.11", - "escape-string-regexp": "^2.0.0", - "js2xmlparser": "^4.0.0", - "klaw": "^3.0.0", - "markdown-it": "^8.4.2", - "markdown-it-anchor": "^5.0.2", - "marked": "^0.7.0", - "mkdirp": "^0.5.1", - "requizzle": "^0.2.3", - "strip-json-comments": "^3.0.1", - "taffydb": "2.6.2", - "underscore": "~1.9.1" - }, - "dependencies": { - "escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, - "requires": { - "minimist": "0.0.8" - } - } - } - }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -5022,15 +5000,6 @@ "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", "dev": true }, - "klaw": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/klaw/-/klaw-3.0.0.tgz", - "integrity": "sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==", - "dev": true, - "requires": { - "graceful-fs": "^4.1.9" - } - }, "lcid": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", @@ -5040,15 +5009,6 @@ "invert-kv": "^2.0.0" } }, - "linkify-it": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz", - "integrity": "sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==", - "dev": true, - "requires": { - "uc.micro": "^1.0.1" - } - }, "loader-runner": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-2.4.0.tgz", @@ -5142,6 +5102,12 @@ "yallist": "^3.0.2" } }, + "lunr": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.7.tgz", + "integrity": "sha512-HjFSiy0Y0qZoW5OA1I6qBi7OnsDdqQnaUr03jhorh30maQoaP+4lQCKklYE3Nq3WJMSUfuBl6N+bKY5wxCb9hw==", + "dev": true + }, "make-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", @@ -5182,25 +5148,6 @@ "object-visit": "^1.0.0" } }, - "markdown-it": { - "version": "8.4.2", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz", - "integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==", - "dev": true, - "requires": { - "argparse": "^1.0.7", - "entities": "~1.1.1", - "linkify-it": "^2.0.0", - "mdurl": "^1.0.1", - "uc.micro": "^1.0.5" - } - }, - "markdown-it-anchor": { - "version": "5.2.4", - "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-5.2.4.tgz", - "integrity": "sha512-n8zCGjxA3T+Mx1pG8HEgbJbkB8JFUuRkeTZQuIM8iPY6oQ8sWOPRZJDFC9a/pNg2QkHEjjGkhBEl/RSyzaDZ3A==", - "dev": true - }, "marked": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", @@ -5218,12 +5165,6 @@ "safe-buffer": "^5.1.2" } }, - "mdurl": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", - "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", - "dev": true - }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -6089,6 +6030,16 @@ "is-wsl": "^1.1.0" } }, + "optimist": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", + "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", + "dev": true, + "requires": { + "minimist": "~0.0.1", + "wordwrap": "~0.0.2" + } + }, "original": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/original/-/original-1.0.2.tgz", @@ -6462,6 +6413,12 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "dev": true }, + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, "promise-inflight": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz", @@ -6677,6 +6634,15 @@ } } }, + "rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", + "dev": true, + "requires": { + "resolve": "^1.1.6" + } + }, "regenerate": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", @@ -6822,15 +6788,6 @@ "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=", "dev": true }, - "requizzle": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.3.tgz", - "integrity": "sha512-YanoyJjykPxGHii0fZP0uUPEXpvqfBDxWV7s6GKAiiOsiqhX6vHNyW3Qzdmqp/iq/ExbhaGbVrjB4ruEVSM4GQ==", - "dev": true, - "requires": { - "lodash": "^4.17.14" - } - }, "resolve": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", @@ -7136,6 +7093,17 @@ "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "dev": true }, + "shelljs": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.3.tgz", + "integrity": "sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==", + "dev": true, + "requires": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + } + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", @@ -7749,12 +7717,6 @@ "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "dev": true }, - "strip-json-comments": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", - "integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==", - "dev": true - }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -7764,12 +7726,6 @@ "has-flag": "^3.0.0" } }, - "taffydb": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/taffydb/-/taffydb-2.6.2.tgz", - "integrity": "sha1-fLy2S1oUG2ou/CxdLGe04VCyomg=", - "dev": true - }, "tapable": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/tapable/-/tapable-1.1.3.tgz", @@ -8018,17 +7974,70 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, + "typedoc": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.15.0.tgz", + "integrity": "sha512-NOtfq5Tis4EFt+J2ozhVq9RCeUnfEYMFKoU6nCXCXUULJz1UQynOM+yH3TkfZCPLzigbqB0tQYGVlktUWweKlw==", + "dev": true, + "requires": { + "@types/minimatch": "3.0.3", + "fs-extra": "^8.1.0", + "handlebars": "^4.1.2", + "highlight.js": "^9.15.8", + "lodash": "^4.17.15", + "marked": "^0.7.0", + "minimatch": "^3.0.0", + "progress": "^2.0.3", + "shelljs": "^0.8.3", + "typedoc-default-themes": "^0.6.0", + "typescript": "3.5.x" + }, + "dependencies": { + "typescript": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.3.tgz", + "integrity": "sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==", + "dev": true + } + } + }, + "typedoc-default-themes": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/typedoc-default-themes/-/typedoc-default-themes-0.6.0.tgz", + "integrity": "sha512-MdTROOojxod78CEv22rIA69o7crMPLnVZPefuDLt/WepXqJwgiSu8Xxq+H36x0Jj3YGc7lOglI2vPJ2GhoOybw==", + "dev": true, + "requires": { + "backbone": "^1.4.0", + "jquery": "^3.4.1", + "lunr": "^2.3.6", + "underscore": "^1.9.1" + } + }, "typescript": { "version": "3.6.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.3.tgz", "integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==", "dev": true }, - "uc.micro": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", - "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", - "dev": true + "uglify-js": { + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.1.tgz", + "integrity": "sha512-+dSJLJpXBb6oMHP+Yvw8hUgElz4gLTh82XuX68QiJVTXaE5ibl6buzhNkQdYhBlIhozWOC9ge16wyRmjG4TwVQ==", + "dev": true, + "optional": true, + "requires": { + "commander": "2.20.0", + "source-map": "~0.6.1" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "optional": true + } + } }, "underscore": { "version": "1.9.1", @@ -8674,6 +8683,12 @@ "integrity": "sha1-+OGqHuWlPsW/FR/6CXQqatdpeHY=", "dev": true }, + "wordwrap": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", + "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=", + "dev": true + }, "worker-farm": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/worker-farm/-/worker-farm-1.7.0.tgz", @@ -8754,12 +8769,6 @@ "async-limiter": "~1.0.0" } }, - "xmlcreate": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.1.tgz", - "integrity": "sha512-MjGsXhKG8YjTKrDCXseFo3ClbMGvUD4en29H2Cev1dv4P/chlpw6KdYmlCWDkhosBVKRDjM836+3e3pm1cBNJA==", - "dev": true - }, "xmldom": { "version": "0.1.27", "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz", diff --git a/package.json b/package.json index cefb30ded..7ab6add6f 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "diff": "^4.0.1", "dirty-chai": "^2.0.1", "fs-grep": "^0.0.5", - "jsdoc": "^3.6.3", "mocha": "^6.2.0", "nock": "^10.0.6", "node-fetch": "^2.6.0", @@ -72,6 +71,7 @@ "sinon": "^7.4.1", "sinon-chai": "^3.3.0", "source-map-loader": "^0.2.4", + "typedoc": "^0.15.0", "typescript": "^3.6.3", "webpack": "^4.39.2", "webpack-cli": "^3.3.6", @@ -82,7 +82,7 @@ "build": "babel src --extensions \".ts,.js\" -d lib", "build:browser": "webpack --progress", "build:types": "tsc --emitDeclarationOnly -d --declarationDir lib --allowJs false", - "doc": "rm -r doc ; jsdoc -d doc README.md src/*.js", + "doc": "rm -r doc ; typedoc", "prepare": "npm run build && npm run build:browser", "start": "webpack-dev-server --https --port 4800", "test": "npm run test:unit && npm run test:serialize", diff --git a/tsconfig.json b/tsconfig.json index 4b78c20c4..def80648e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "allowSyntheticDefaultImports": true, "checkJs": false, "allowJs": true, - "target": "es6", + "target": "es5", "module": "es6", "strict": true, "noImplicitAny": false, diff --git a/typedoc.js b/typedoc.js new file mode 100644 index 000000000..c3592bae5 --- /dev/null +++ b/typedoc.js @@ -0,0 +1,18 @@ +module.exports = { + src: ['./src'], + mode: "file", + out: "doc", + tsconfig: "tsconfig.json", + theme: "default", + hideGenerator: true, + ignoreCompilerErrors: true, + excludePrivate: true, + excludeNotExported: "true", + target: "ES6", + moduleResolution: "node", + preserveConstEnums: "true", + stripInternal: "true", + suppressExcessPropertyErrors: "true", + suppressImplicitAnyIndexErrors: "true", + module: "commonjs" +} From 80b8803245ab2603a39f14ad41b978f4597c1b15 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Tue, 8 Oct 2019 11:44:45 +0200 Subject: [PATCH 07/10] Convert Collection to TS #355 --- src/collection.js | 48 ------------------------- src/collection.ts | 90 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 48 deletions(-) delete mode 100644 src/collection.js create mode 100644 src/collection.ts diff --git a/src/collection.js b/src/collection.js deleted file mode 100644 index e73d2fa76..000000000 --- a/src/collection.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict' -import BlankNode from './blank-node' -import ClassOrder from './class-order' -import Node from './node-internal' - -export default class Collection extends Node { - constructor (initial) { - super() - this.termType = Collection.termType - this.id = BlankNode.nextId++ - this.elements = [] - this.closed = false - if (initial && initial.length > 0) { - initial.forEach(element => { - this.elements.push(Node.fromValue(element)) - }) - } - } - append (element) { - return this.elements.push(element) - } - close () { - this.closed = true - return this.closed - } - shift () { - return this.elements.shift() - } - substitute (bindings) { - var elementsCopy = this.elements.map(function (ea) { - ea.substitute(bindings) - }) - return new Collection(elementsCopy) - } - toNT () { - return BlankNode.NTAnonymousNodePrefix + this.id - } - toString () { - return '(' + this.elements.join(' ') + ')' - } - unshift (element) { - return this.elements.unshift(element) - } -} -Collection.termType = 'Collection' -Collection.prototype.classOrder = ClassOrder['Collection'] -Collection.prototype.compareTerm = BlankNode.prototype.compareTerm -Collection.prototype.isVar = 0 diff --git a/src/collection.ts b/src/collection.ts new file mode 100644 index 000000000..2b9627e1c --- /dev/null +++ b/src/collection.ts @@ -0,0 +1,90 @@ +import BlankNode from './blank-node' +import ClassOrder from './class-order' +import Node from './node-internal' +import { ValueType, Bindings } from './types'; + +/** +* A collection of other RDF nodes +*/ +export default class Collection extends Node { + /** + * The identifier for this collection + */ + id: number; + /** + * The nodes in this collection + */ + elements: Node[]; + /** + * Whether this collection is closed + */ + closed: boolean; + /** + * Initializes this collection + * @param initial The initial elements + */ + constructor(initial: ReadonlyArray) { + super() + this.termType = Collection.termType + this.id = BlankNode.nextId++ + this.elements = [] + this.closed = false + if (initial && initial.length > 0) { + initial.forEach(element => { + this.elements.push(Node.fromValue(element)) + }) + } + } + /** + * Appends an element to this collection + * @param element The new element + */ + append (element: Node): number { + return this.elements.push(element) + } + /** + * Closes this collection + */ + close (): boolean { + this.closed = true + return this.closed + } + /** + * Removes the first element from the collection (and return it) + */ + shift (): Node | undefined { + return this.elements.shift() + } + /** + * Gets a new Collection with the substituting bindings applied + * @param bindings The bindings to substitute + */ + substitute(bindings: Bindings): Collection { + var elementsCopy = this.elements.map(function (ea) { + ea.substitute(bindings) + }) + return new Collection(elementsCopy as []) + } + toNT () { + return BlankNode.NTAnonymousNodePrefix + this.id + } + /** + * Serializes the collection to a string. + * Surounded by (parantheses) and seperated by spaces. + */ + toString () { + return '(' + this.elements.join(' ') + ')' + } + /** + * Preprends the specified element to the colelction's front + * @param element The element to preprend + */ + unshift (element: Node): number { + return this.elements.unshift(element) + } + static termType: string; +} +Collection.termType = 'Collection' +Collection.prototype.classOrder = ClassOrder['Collection'] +Collection.prototype.compareTerm = BlankNode.prototype.compareTerm +Collection.prototype.isVar = false From 7a9c7c3e7b6e46a0bdee68087160060f182c46d9 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Tue, 8 Oct 2019 11:59:53 +0200 Subject: [PATCH 08/10] isVar Type consistency #355 --- src/formula.js | 2 +- src/variable.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/formula.js b/src/formula.js index bd3552999..645c96ffd 100644 --- a/src/formula.js +++ b/src/formula.js @@ -644,7 +644,7 @@ export default class Formula extends Node { Formula.termType = 'Graph' Formula.prototype.classOrder = ClassOrder['Graph'] -Formula.prototype.isVar = 0 +Formula.prototype.isVar = false Formula.prototype.ns = Namespace Formula.prototype.variable = name => new Variable(name) diff --git a/src/variable.js b/src/variable.js index 7b88bb2a8..030ebf88a 100644 --- a/src/variable.js +++ b/src/variable.js @@ -42,4 +42,4 @@ export default class Variable extends Node { Variable.termType = 'Variable' Variable.prototype.classOrder = ClassOrder['Variable'] -Variable.prototype.isVar = 1 +Variable.prototype.isVar = true From 3320c43d10d2fd1881b96cac5047258878e1e72d Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Tue, 8 Oct 2019 12:00:11 +0200 Subject: [PATCH 09/10] Remove collection from temp types #355 --- src/node-internal.ts | 53 -------------------------------------------- types-temp.ts | 42 ----------------------------------- 2 files changed, 95 deletions(-) diff --git a/src/node-internal.ts b/src/node-internal.ts index 7ffadad48..4b24aff9c 100644 --- a/src/node-internal.ts +++ b/src/node-internal.ts @@ -117,57 +117,4 @@ export default abstract class Node { toString (): string { throw new Error('Node.toString() is abstract - see the subclasses instead') } - - // /** - // * Creates an RDF Node from a native javascript value. - // * RDF Nodes are returned unchanged, undefined returned as itself. - // * @method fromValue - // * @param value - Any native Javascript value - // */ - // static fromValue (value: ValueType | null): Node | Literal | undefined | null | Collection { - // if (typeof value === 'undefined' || value === null) { - // return value - // } - // const isNode = Object.prototype.hasOwnProperty.call(value, 'termType') - // if (isNode) { // a Node subclass or a Collection - // // @ts-ignore - // return value - // } - // if (Array.isArray(value)) { - // return new Collection(value) - // } - // return Literal.fromValue(value) - // } - - // /** - // * Gets the javascript object equivalent to a node - // * @param term The RDF node - // */ - // static toJS (term: Node | Literal) { - // if (term.elements) { - // return term.elements.map(Node.toJS) // Array node (not standard RDFJS) - // } - // // Node remains Node - // if (!term.hasOwnProperty('dataType')) { - // return term - // } - // const literalTerm = term as Literal - // // if (!Object.prototype.hasOwnProperty.call(term, 'dataType')) return term // Objects remain objects - // if (literalTerm.datatype.sameTerm(ns.xsd('boolean'))) { - // return literalTerm.value === '1' - // } - // if (literalTerm.datatype.sameTerm(ns.xsd('dateTime')) || - // literalTerm.datatype.sameTerm(ns.xsd('date'))) { - // return new Date(literalTerm.value) - // } - // if ( - // literalTerm.datatype.sameTerm(ns.xsd('integer')) || - // literalTerm.datatype.sameTerm(ns.xsd('float')) || - // literalTerm.datatype.sameTerm(ns.xsd('decimal')) - // ) { - // let z = Number(literalTerm.value) - // return Number(literalTerm.value) - // } - // return literalTerm.value - // } } diff --git a/types-temp.ts b/types-temp.ts index b59f6f1c9..0a8d6d738 100644 --- a/types-temp.ts +++ b/types-temp.ts @@ -18,48 +18,6 @@ import { NamedNode } from './src'; // TypeScript Version: 3.0 // Acknowledgements: This work has been financed by Logilab SA, FRANCE, logilab.fr -/** -* A collection of other RDF nodes -*/ -export interface Collection extends Node { - /** - * The identifier for this collection - */ - id: string; - /** - * The nodes in this collection - */ - elements: Node[]; - /** - * Whether this collection is closed - */ - closed: boolean; - /** - * Initializes this collection - * @param initial The initial elements - */ - constructor(initial: ReadonlyArray); - /** - * Appends an element to this collection - * @param element The new element - */ - append(element: Node): number; - /** - * Closes this collection - */ - close(): boolean; - /** - * Removes the first element from the collection (and return it) - */ - shift(): Node; - /** - * Preprends the specified element to the colelction's front - * @param element The element to preprend - */ - unshift(element: Node): number; - static termType: string; -} - /** * Variables are placeholders used in patterns to be matched. * In cwm they are symbols which are the formula's list of quantified variables. From 918730c89a77d21bc5bf0a18c96eae5f41b96b47 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Tue, 8 Oct 2019 14:38:14 +0200 Subject: [PATCH 10/10] ts-ignore, use instanceof, termtype, lint #355 --- src/blank-node.ts | 4 +++- src/collection.ts | 16 ++++++++++++++-- src/empty.ts | 5 +++-- src/literal.ts | 29 +++++++++++++++++------------ src/named-node.ts | 9 +++++---- src/node.ts | 6 +----- src/statement.ts | 2 +- src/store.js | 2 +- src/variable.js | 2 +- 9 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/blank-node.ts b/src/blank-node.ts index 2666d1510..2f997d632 100644 --- a/src/blank-node.ts +++ b/src/blank-node.ts @@ -7,6 +7,9 @@ import { IndexedFormula } from './index'; * @link https://rdf.js.org/data-model-spec/#blanknode-interface */ export default class BlankNode extends Node { + + static termType: 'BlankNode'; + /** * The identifier for the blank node */ @@ -21,7 +24,6 @@ export default class BlankNode extends Node { * The next unique identifier for blank nodes */ static nextId: number; - static termType: string; static NTAnonymousNodePrefix: string; /** diff --git a/src/collection.ts b/src/collection.ts index 2b9627e1c..79852277f 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -7,18 +7,25 @@ import { ValueType, Bindings } from './types'; * A collection of other RDF nodes */ export default class Collection extends Node { + + static termType: 'Collection'; + /** * The identifier for this collection */ id: number; + /** * The nodes in this collection */ - elements: Node[]; + + elements: Node[]; + /** * Whether this collection is closed */ closed: boolean; + /** * Initializes this collection * @param initial The initial elements @@ -35,6 +42,7 @@ export default class Collection extends Node { }) } } + /** * Appends an element to this collection * @param element The new element @@ -42,6 +50,7 @@ export default class Collection extends Node { append (element: Node): number { return this.elements.push(element) } + /** * Closes this collection */ @@ -49,12 +58,14 @@ export default class Collection extends Node { this.closed = true return this.closed } + /** * Removes the first element from the collection (and return it) */ shift (): Node | undefined { return this.elements.shift() } + /** * Gets a new Collection with the substituting bindings applied * @param bindings The bindings to substitute @@ -68,6 +79,7 @@ export default class Collection extends Node { toNT () { return BlankNode.NTAnonymousNodePrefix + this.id } + /** * Serializes the collection to a string. * Surounded by (parantheses) and seperated by spaces. @@ -75,6 +87,7 @@ export default class Collection extends Node { toString () { return '(' + this.elements.join(' ') + ')' } + /** * Preprends the specified element to the colelction's front * @param element The element to preprend @@ -82,7 +95,6 @@ export default class Collection extends Node { unshift (element: Node): number { return this.elements.unshift(element) } - static termType: string; } Collection.termType = 'Collection' Collection.prototype.classOrder = ClassOrder['Collection'] diff --git a/src/empty.ts b/src/empty.ts index 47ea62a9d..30eabad51 100644 --- a/src/empty.ts +++ b/src/empty.ts @@ -1,11 +1,12 @@ -'use strict' import Node from './node-internal' /** * An empty node */ export default class Empty extends Node { - static termType: string + + static termType: 'empty' + constructor () { super() this.termType = Empty.termType diff --git a/src/literal.ts b/src/literal.ts index 6850add1e..847241c99 100644 --- a/src/literal.ts +++ b/src/literal.ts @@ -1,4 +1,3 @@ -'use strict' import NamedNode from './named-node' import Node from './node-internal' import XSD from './xsd' @@ -6,10 +5,13 @@ import { ValueType } from './types' import classOrder from './class-order' /** -* An RDF literal node, containing something different than a URI. -* @link https://rdf.js.org/data-model-spec/#literal-interface -*/ + * An RDF literal node, containing something different than a URI. + * @link https://rdf.js.org/data-model-spec/#literal-interface + */ export default class Literal extends Node { + + termType: 'Literal' + /** * The language for the literal */ @@ -20,8 +22,6 @@ export default class Literal extends Node { */ datatype!: NamedNode - termType: string - /** * Initializes this literal * @param value The literal's lexical value @@ -34,23 +34,29 @@ export default class Literal extends Node { this.value = value if (language) { this.lang = language - datatype = XSD.langString + this.datatype = XSD.langString } // If not specified, a literal has the implied XSD.string default datatype if (datatype) { this.datatype = NamedNode.fromValue(datatype) } - if (!datatype) { + if (!datatype && !this.datatype) { this.datatype = XSD.string } } - /** + + /** * Gets a copy of this literal */ copy (): Literal { return new Literal(this.value, this.lang, this.datatype) } - equals (other) { + + /** + * Gets whether two literals are the same + * @param other The other statement + */ + equals (other: Literal): boolean { if (!other) { return false } @@ -146,8 +152,7 @@ export default class Literal extends Node { if (typeof value === 'undefined' || value === null) { return value } - // @ts-ignore - if (typeof value === 'object' && value.termType) { // this is a Node instance + if (Object.prototype.hasOwnProperty.call(value, 'termType')) { // this is a Node instance return value as Node } switch (typeof value) { diff --git a/src/named-node.ts b/src/named-node.ts index 0b4284255..30849945f 100644 --- a/src/named-node.ts +++ b/src/named-node.ts @@ -6,7 +6,8 @@ import { ValueType } from './types'; * A named (IRI) RDF node */ export default class NamedNode extends Node { - static termType: string; + + static termType: 'NamedNode'; /** * Initializes this node @@ -37,6 +38,7 @@ export default class NamedNode extends Node { this.value = iriString } + /** * Returns an RDF node for the containing directory, ending in slash. */ @@ -49,7 +51,7 @@ export default class NamedNode extends Node { } /** - * Returns an NamedNOde for the whole web site, ending in slash. + * Returns a NamedNode for the whole web site, ending in slash. * Contrast with the "origin" which does NOT have a trailing slash */ site (): NamedNode { @@ -107,8 +109,7 @@ export default class NamedNode extends Node { if (typeof value === 'undefined' || value === null) { return value } - // @ts-ignore - const isNode = value && value.termType + const isNode = value && (value as Node).termType if (isNode) { return value as NamedNode } diff --git a/src/node.ts b/src/node.ts index 4cb9d1b4d..4b0aca7aa 100644 --- a/src/node.ts +++ b/src/node.ts @@ -4,6 +4,7 @@ import Node from './node-internal' import Collection from './collection' import Literal from './literal' import { ValueType } from './types' +import Namespace from './namespace' export default Node @@ -19,7 +20,6 @@ Node.fromValue = function (value: ValueType): Node | Literal | undefined | null } const isNode = Object.prototype.hasOwnProperty.call(value, 'termType') if (isNode) { // a Node subclass or a Collection - // @ts-ignore return value } if (Array.isArray(value)) { @@ -28,7 +28,6 @@ Node.fromValue = function (value: ValueType): Node | Literal | undefined | null return Literal.fromValue(value) } -import Namespace from './namespace' const ns = { xsd: Namespace('http://www.w3.org/2001/XMLSchema#') } /** @@ -40,14 +39,12 @@ Node.toJS = function (term: Node | Literal) { return term.elements.map(Node.toJS) // Array node (not standard RDFJS) } // Node remains Node - // @ts-ignore if (!term.datatype) return term // Objects remain objects const literalTerm = term as Literal // if (!Object.prototype.hasOwnProperty.call(term, 'dataType')) return term // Objects remain objects if (literalTerm.datatype.sameTerm(ns.xsd('boolean'))) { return literalTerm.value === '1' } - console.log("4", term) if (literalTerm.datatype.sameTerm(ns.xsd('dateTime')) || literalTerm.datatype.sameTerm(ns.xsd('date'))) { return new Date(literalTerm.value) @@ -60,6 +57,5 @@ Node.toJS = function (term: Node | Literal) { let z = Number(literalTerm.value) return Number(literalTerm.value) } - console.log("7", term) return literalTerm.value } diff --git a/src/statement.ts b/src/statement.ts index 391b1426d..122b96398 100644 --- a/src/statement.ts +++ b/src/statement.ts @@ -67,7 +67,7 @@ export default class Statement { return ( other.subject.equals(this.subject) && other.predicate.equals(this.predicate) && - other.object.equals(this.object as Node) && + other.object.equals(this.object as Literal) && other.graph.equals(this.graph) ) } diff --git a/src/store.js b/src/store.js index d308e8aa4..7c1ec52b5 100644 --- a/src/store.js +++ b/src/store.js @@ -20,7 +20,7 @@ import { ArrayIndexOf } from './util' import Formula from './formula' import { RDFArrayRemove } from './util' import Statement from './statement' -import Node from './node-internal' +import Node from './node' import Variable from './variable' import { Query, indexedFormulaQuery } from './query' diff --git a/src/variable.js b/src/variable.js index 030ebf88a..0ac8d6f81 100644 --- a/src/variable.js +++ b/src/variable.js @@ -1,6 +1,6 @@ 'use strict' import ClassOrder from './class-order' -import Node from './node-internal' +import Node from './node' import * as Uri from './uri' /**