Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Typescript migrations - switch to Typedoc #363

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 147 additions & 138 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -55,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",
Expand All @@ -64,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",
Expand All @@ -74,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",
Expand Down
40 changes: 35 additions & 5 deletions src/blank-node.js → src/blank-node.ts
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down Expand Up @@ -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
Expand All @@ -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
9 changes: 8 additions & 1 deletion src/class-order.js → src/class-order.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
export default {
/**
* Class orders
*/
const ClassOrder: {
[id: string]: number;
} = {
'Literal': 1,
'Collection': 3,
'Graph': 4,
'NamedNode': 5,
'BlankNode': 6,
'Variable': 7
}

export default ClassOrder
48 changes: 0 additions & 48 deletions src/collection.js

This file was deleted.

90 changes: 90 additions & 0 deletions src/collection.ts
Original file line number Diff line number Diff line change
@@ -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<ValueType>) {
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
2 changes: 1 addition & 1 deletion src/default-graph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
import Node from './node'
import Node from './node-internal'

export default class DefaultGraph extends Node {
constructor () {
Expand Down
7 changes: 4 additions & 3 deletions src/empty.js → src/empty.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict'
import Node from './node'
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
Expand Down
4 changes: 2 additions & 2 deletions src/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Loading