Skip to content

Commit

Permalink
Taskforce compatibility linkeddata#355
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Nov 4, 2019
1 parent ed0b3a8 commit 645d25b
Show file tree
Hide file tree
Showing 21 changed files with 612 additions and 833 deletions.
6 changes: 0 additions & 6 deletions .npmignore

This file was deleted.

18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions reference/fetcher-classes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { isNamedNode } from '../src/util'
import { isTFNamedNode } from '../src/utils'

const log = require('./log')
const N3Parser = require('./n3parser')
const NamedNode = require('./named-node')
const Namespace = require('./namespace')
const rdfParse = require('./parse')
const parseRDFaDOM = require('./rdfaparser').parseRDFaDOM
Expand Down Expand Up @@ -668,7 +667,7 @@ class Fetcher {
userCallback = p2
} else if (typeof p2 === 'undefined') { // original calling signature
// referingTerm = undefined
} else if (isNamedNode(p2)) {
} else if (isTFNamedNode(p2)) {
// referingTerm = p2
options = {referingTerm: p2}
} else {
Expand Down
53 changes: 46 additions & 7 deletions src/data-factory-internal.js → src/data-factory-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import Literal from './literal'
import NamedNode from './named-node'
import Statement from './statement'
import Variable from './variable'
import { TFSubject, TFPredicate, TFObject, TFGraph, TFNamedNode } from './types'

export const defaultGraphURI = 'chrome:theSession'

function blankNode (value) {
/**
* Creates a new blank node
* @param value The blank node's identifier
*/
function blankNode(value: string): BlankNode {
return new BlankNode(value)
}

function defaultGraph () {
/**
* Gets the default graph
*/
function defaultGraph(): TFNamedNode {
return new NamedNode(defaultGraphURI)
}

Expand Down Expand Up @@ -44,9 +52,17 @@ function id (term) {
}
}

function literal (value, languageOrDatatype) {
/**
* Creates a new literal node
* @param value The lexical value
* @param languageOrDatatype Either the language or the datatype
*/
function literal(
value: string,
languageOrDatatype?: string | TFNamedNode
): Literal {
if (typeof value !== "string" && !languageOrDatatype) {
return Literal.fromValue(value)
return Literal.fromValue(value) as Literal
}

const strValue = typeof value === 'string' ? value : '' + value
Expand All @@ -60,14 +76,37 @@ function literal (value, languageOrDatatype) {
return new Literal(strValue, null, languageOrDatatype)
}
}
function namedNode (value) {

/**
* Creates a new named node
* @param value The new named node
*/
function namedNode(value: string): NamedNode {
return new NamedNode(value)
}
function quad (subject, predicate, object, graph) {

/**
* Creates a new statement
* @param subject The subject
* @param predicate The predicate
* @param object The object
* @param graph The containing graph
*/
function quad(
subject: TFSubject,
predicate: TFPredicate,
object: TFObject,
graph?: TFGraph
): Statement {
graph = graph || defaultGraph()
return new Statement(subject, predicate, object, graph)
}
function variable (name) {

/**
* Creates a new variable
* @param name The name for the variable
*/
function variable(name?: string): Variable {
return new Variable(name)
}

Expand Down
54 changes: 48 additions & 6 deletions src/data-factory.js → src/data-factory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict'
import Collection from './collection'
import CanonicalDataFactory from './data-factory-internal'
import Fetcher from './fetcher'
import Literal from './literal'
import Statement from './statement'
import { ValueType, TFNamedNode, TFSubject, TFPredicate, TFObject, TFGraph } from './types'
import IndexedFormula from './store'
import Formula from './formula'

/**
* Data factory which also supports Collections
Expand Down Expand Up @@ -52,21 +53,62 @@ function id (term) {

return CanonicalDataFactory.id(term)
}
function collection (elements) {
/**
* Creates a new collection
* @param elements - The initial element
*/
function collection(elements: ReadonlyArray<ValueType>): Collection {
return new Collection(elements)
}
function fetcher (store, options) {
/**
* Creates a new fetcher
* @param store - The store to use
* @param options - The options
*/
function fetcher(store: Formula, options: any): Fetcher {
return new Fetcher(store, options)
}
function graph (features = undefined, opts = undefined) {
/**
* Creates a new graph (store)
*/
function graph (features = undefined, opts = undefined): IndexedFormula {
return new IndexedFormula(features, opts || { rdfFactory: ExtendedTermFactory })
}
function lit (val, lang, dt) {
/**
* 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?: TFNamedNode): Literal {
return new Literal('' + val, lang, dt)
}
/**
* Creates a new statement
* @param subject The subject
* @param predicate The predicate
* @param object The object
* @param graph The containing graph
*/
function st(
subject: TFSubject,
predicate: TFPredicate,
object: TFObject,
graph?: TFGraph
): Statement;
function st (subject, predicate, object, graph) {
return new Statement(subject, predicate, object, graph)
}
function triple (subject, predicate, object) {
/**
* Creates a new statement
* @param subject The subject
* @param predicate The predicate
* @param object The object
*/
function triple(
subject: TFSubject,
predicate: TFPredicate,
object: TFObject
): Statement {
return CanonicalDataFactory.quad(subject, predicate, object)
}
8 changes: 6 additions & 2 deletions src/default-graph.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import Node from './node-internal'
import { TFDefaultGraph } from './types';
import { TFDefaultGraph, TermType, DefaultGraphTermType } from './types';

/**
* The RDF default graph
*/
export default class DefaultGraph extends Node implements TFDefaultGraph {
value: ''
termType: DefaultGraphTermType;

constructor () {
super()
this.termType = 'DefaultGraph'
this.termType = TermType.DefaultGraph
this.value = ''
}
toCanonical () {
Expand Down
4 changes: 2 additions & 2 deletions src/fetcher.js
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 { isNamedNode } from './util'
import { isTFNamedNode } from './utils'
import * as Util from './util'
import serialize from './serialize'

Expand Down Expand Up @@ -875,7 +875,7 @@ export default class Fetcher {
userCallback = p2
} else if (typeof p2 === 'undefined') { // original calling signature
// referringTerm = undefined
} else if (isNamedNode(p2)) {
} else if (isTFNamedNode(p2)) {
// referringTerm = p2
options.referringTerm = p2
} else {
Expand Down
Loading

0 comments on commit 645d25b

Please sign in to comment.