Skip to content

Commit

Permalink
Rename uriCreator to nodeValue, various ts linkeddata#355
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Nov 14, 2019
1 parent 86c0269 commit adc9f31
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default class Collection extends Node {
* Gets a new Collection with the substituting bindings applied
* @param bindings The bindings to substitute
*/
//@ts-ignore Incompatible signature with Node.substitute
substitute(bindings: Bindings): Collection {
var elementsCopy = this.elements.map(function (ea) {
ea.substitute(bindings)
Expand Down
1 change: 1 addition & 0 deletions src/data-factory-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function variable(name?: string): Variable {
return new Variable(name)
}

/** The internal RDFlib datafactory, which uses Collections */
const CanonicalDataFactory: TFDataFactory<
NamedNode,
BlankNode,
Expand Down
2 changes: 1 addition & 1 deletion src/data-factory-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface DataFactory<
toNQ(term: FactoryTypes): string
}

export type TFIDFactoryTypes = TFNamedNode | TFBlankNode | TFLiteral | TFQuad
export type TFIDFactoryTypes = TFNamedNode | TFBlankNode | TFLiteral | TFQuad | TFTerm

export interface IdentityFactory<
Quad = TFQuad,
Expand Down
22 changes: 8 additions & 14 deletions src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import rdfParse from './parse'
import { parseRDFaDOM } from './rdfaparser'
import RDFParser from './rdfxmlparser'
import * as Uri from './uri'
import { isTFNamedNode, isCollection, uriCreator } from './utils'
import { isTFNamedNode, isCollection, nodeValue } from './utils'
import * as Util from './util'
import serialize from './serialize'

Expand Down Expand Up @@ -180,7 +180,7 @@ interface AutoInitOptions extends RequestInit{
// Like requeststatus? Can contain text with error.
data?: string
// Probably an identifier for request?s
req?: TFBlankNode
req: TFBlankNode
// Might be the same as Options.data
body?: string
headers: Headers
Expand Down Expand Up @@ -914,20 +914,14 @@ export default class Fetcher {
)
}

let docuri = uriCreator(uri as NamedNode)
let docuri = nodeValue(uri as NamedNode)
docuri = docuri.split('#')[0]

options = this.initFetchOptions(docuri, options)

return this.pendingFetchPromise(docuri, (options as AutoInitOptions).baseURI, options)
}

/**
* @param uri {string}
* @param originalUri {string}
* @param options {Object}
* @returns {Promise<Result>}
*/
pendingFetchPromise (
uri: string,
originalUri: string,
Expand Down Expand Up @@ -1009,7 +1003,7 @@ export default class Fetcher {
}
options.actualProxyURI = actualProxyURI

return options
return options as AutoInitOptions
}

/**
Expand Down Expand Up @@ -1139,7 +1133,7 @@ export default class Fetcher {
userCallback?: UserCallback,
options: Options = {}
): void {
const uri = uriCreator(uriIn)
const uri = nodeValue(uriIn)

if (typeof p2 === 'function') {
// nowOrWhenFetched (uri, userCallback)
Expand Down Expand Up @@ -1371,7 +1365,7 @@ export default class Fetcher {
putBack (
uri: TFNamedNode | string,
options: Options = {}
): Promise<Response> {
): Promise<ResponseType> {
uri = (uri as TFNamedNode).value || uri // Accept object or string
let doc = new NamedNode(uri).doc() // strip off #
options.contentType = options.contentType || 'text/turtle'
Expand Down Expand Up @@ -1495,9 +1489,9 @@ export default class Fetcher {
method: HTTPMethods,
uriIn: string | TFNamedNode,
// Not sure about this type. Maybe this Options is different?
options: Options
options: Options = {}
): Promise<ResponseType> {
const uri = uriCreator(uriIn)
const uri = nodeValue(uriIn)
options.method = method
options.body = options.data || options.body
options.force = true
Expand Down
39 changes: 18 additions & 21 deletions src/formula.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import BlankNode from './blank-node'
import ClassOrder from './class-order'
import Collection from './collection'
import CanonicalDataFactory from './data-factory-internal'
Expand All @@ -8,7 +7,7 @@ import Namespace from './namespace'
import Node from './node-internal'
import Serializer from './serialize'
import Statement from './statement'
import { appliedFactoryMethods, arrayToStatements, isTFStatement, uriCreator, isStatement } from './utils'
import { appliedFactoryMethods, arrayToStatements, isTFStatement, nodeValue } from './utils'
import {
TFTerm,
TFPredicate,
Expand Down Expand Up @@ -37,7 +36,7 @@ export interface FormulaOpts {
rdfFactory?: IdentityFactory & DataFactory
}

interface SeedsMap {
interface BooleanMap {
[uri: string]: boolean;
}

Expand Down Expand Up @@ -409,7 +408,7 @@ export default class Formula extends Node {
var len4: number
var m: number
var members: MembersMap
var pred: TFTerm
var pred: TFPredicate
var q: number
var ref
var ref1: TFQuad[]
Expand Down Expand Up @@ -438,7 +437,7 @@ export default class Formula extends Node {
this.sym('http://www.w3.org/2000/01/rdf-schema#domain'),
this.fromNT(t))
for (l = 0, len1 = ref2.length; l < len1; l++) {
pred = ref2[l]
pred = ref2[l] as TFPredicate
ref3 = this.statementsMatching(void 0, pred)
for (m = 0, len2 = ref3.length; m < len2; m++) {
st = ref3[m]
Expand All @@ -449,7 +448,7 @@ export default class Formula extends Node {
this.sym('http://www.w3.org/2000/01/rdf-schema#range'),
this.fromNT(t))
for (q = 0, len3 = ref4.length; q < len3; q++) {
pred = ref4[q]
pred = ref4[q] as TFPredicate
ref5 = this.statementsMatching(void 0, pred)
for (u = 0, len4 = ref5.length; u < len4; u++) {
st = ref5[u]
Expand All @@ -471,7 +470,7 @@ export default class Formula extends Node {
*/
findMemberURIs(
subject: Node
): MembersMap {
): UriMap {
return this.NTtoURI(this.findMembersNT(subject))
}

Expand Down Expand Up @@ -526,9 +525,7 @@ export default class Formula extends Node {
*/
findTypesNT(
subject: TFSubject
): {
[uri: string]: boolean;
} {
): BooleanMap {
var domain: TFTerm
var i: number
var l: number
Expand Down Expand Up @@ -585,9 +582,7 @@ export default class Formula extends Node {
*/
findTypeURIs(
subject: TFSubject
): {
[uri: string]: string;
} {
): UriMap {
return this.NTtoURI(this.findTypesNT(subject))
}

Expand All @@ -602,12 +597,12 @@ export default class Formula extends Node {
subject: TFSubject,
doc: TFGraph,
excludePredicateURIs: ReadonlyArray<string>
): Statement[] {
): TFQuad[] {
excludePredicateURIs = excludePredicateURIs || []
var todo: TFSubject[] = [subject]
var done: any[] = []
var doneArcs = []
var result: Statement[] = []
var result: TFQuad[] = []
var self = this
var follow = function (x) {
var queue = function (x) {
Expand All @@ -618,9 +613,9 @@ export default class Formula extends Node {
}
var sts = self.statementsMatching(null, null, x, doc)
.concat(self.statementsMatching(x, null, null, doc))
sts = sts.filter(function (st: Statement) {
sts = sts.filter(function (st: TFQuad): boolean {
if (excludePredicateURIs[st.predicate.value]) return false
var hash = st.toNT()
var hash = (st as Statement).toNT()
if (doneArcs[hash]) return false
doneArcs[hash] = true
return true
Expand Down Expand Up @@ -767,7 +762,7 @@ export default class Formula extends Node {
* @return a collection of the URIs as strings
* todo: explain why it is important to go through NT
*/
NTtoURI(t: MembersMap): UriMap{
NTtoURI(t: BooleanMap | MembersMap): UriMap{
var k, v
var uris: UriMap = {}
for (k in t) {
Expand Down Expand Up @@ -839,7 +834,7 @@ export default class Formula extends Node {
if (name) {
throw new Error('This feature (kb.sym with 2 args) is removed. Do not assume prefix mappings.')
}
const uriString = uriCreator(uri)
const uriString = nodeValue(uri)
return this.rdfFactory.namedNode(uriString)
}

Expand Down Expand Up @@ -872,7 +867,7 @@ export default class Formula extends Node {
* @param inverse - Trace inverse direction
*/
transitiveClosure(
seeds: SeedsMap,
seeds: BooleanMap,
predicate: TFPredicate,
inverse?: boolean
): {
Expand All @@ -892,7 +887,9 @@ export default class Formula extends Node {
if (t == null) {
return done
}
sups = inverse ? this.each(void 0, predicate, this.fromNT(t)) : this.each(this.fromNT(t), predicate)
sups = inverse ?
this.each(void 0, predicate, this.fromNT(t))
: this.each(this.fromNT(t) as TFPredicate, predicate)
for (i = 0, len = sups.length; i < len; i++) {
elt = sups[i]
s = elt.toNT()
Expand Down
8 changes: 5 additions & 3 deletions src/named-node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ClassOrder from './class-order'
import Node from './node-internal'
import { ValueType, TFNamedNode, TermType, NamedNodeTermType } from './types';
import { uriCreator } from './utils';
import { nodeValue } from './utils';

export function isNamedNode<T>(value: T | Node): value is NamedNode {
return (value as Node).termType === TermType.NamedNode
Expand All @@ -10,6 +10,7 @@ export function isNamedNode<T>(value: T | Node): value is NamedNode {
/**
* A named (IRI) RDF node
*/
//@ts-ignore incompatible signatures for .fromValue
export default class NamedNode extends Node implements TFNamedNode {
static termType: NamedNodeTermType;

Expand All @@ -23,7 +24,7 @@ export default class NamedNode extends Node implements TFNamedNode {
super()
this.termType = TermType.NamedNode

const iri = uriCreator(iriIn)
const iri = nodeValue(iriIn)

if (!iri) {
throw new Error('Missing IRI for NamedNode')
Expand Down Expand Up @@ -71,7 +72,8 @@ export default class NamedNode extends Node implements TFNamedNode {
}

/**
* Gets the named node for the document
* Gets the fetchable named node for the document.
* Removes everything from the # anchor tag.
*/
doc (): NamedNode {
if (this.uri.indexOf('#') < 0) {
Expand Down
5 changes: 3 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ export default function parse (

function executeErrorCallback (e: Error): void {
if (
// TODO: Always true, what is the right behavior
contentType !== ContentType.jsonld ||
//@ts-ignore always true?
// @ts-ignore always true?
contentType !== ContentType.nQuads ||
//@ts-ignore always true?
// @ts-ignore always true?
contentType !== ContentType.nQuadsAlt
) {
if (callback) {
Expand Down
Loading

0 comments on commit adc9f31

Please sign in to comment.