Skip to content

Commit

Permalink
Merge pull request #373 from ontola/typescript-4-rebased-squashed
Browse files Browse the repository at this point in the history
Typescript
  • Loading branch information
megoth authored Dec 17, 2019
2 parents e698778 + d41ef37 commit d5000f5
Show file tree
Hide file tree
Showing 71 changed files with 5,304 additions and 2,747 deletions.
7 changes: 4 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-typescript",
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-transform-runtime"
],
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties"
]
}
6 changes: 0 additions & 6 deletions .npmignore

This file was deleted.

683 changes: 448 additions & 235 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
{
"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/"
},
{
"name": "Thom van Kalkeren",
"url": "https://github.com/fletcher91/"
}
],
"license": "MIT",
Expand All @@ -43,28 +55,31 @@
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-typescript": "^7.6.0",
"@babel/register": "^7.5.5",
"@types/chai": "^4.2.3",
"@types/dirty-chai": "^2.0.2",
"@types/express": "^4.17.1",
"@types/jsonld": "^1.5.0",
"@types/mocha": "^5.2.7",
"babel-loader": "^8.0.6",
"chai": "^4.2.0",
"diff": "^4.0.1",
"dirty-chai": "^2.0.1",
"fs-grep": "^0.0.5",
"jsdoc": "^3.6.3",
"mocha": "^6.2.0",
"mocha": "^6.2.2",
"nock": "^10.0.6",
"node-fetch": "^2.6.0",
"node-mkdirp": "0.0.1",
"rimraf": "^3.0.0",
"sinon": "^7.4.1",
"sinon-chai": "^3.3.0",
"source-map-loader": "^0.2.4",
"typescript": "^3.6.3",
"typedoc": "^0.15.3",
"typescript": "^3.7.2",
"webpack": "^4.39.2",
"webpack-cli": "^3.3.6",
"webpack-dev-server": "^3.8.0",
Expand All @@ -74,8 +89,8 @@
"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",
"prepare": "npm run build && npm run build:browser",
"doc": "rm -r doc ; typedoc",
"prepare": "npm run build && npm run build:types && npm run build:browser",
"start": "webpack-dev-server --https --port 4800",
"test": "npm run test:unit && npm run test:serialize",
"test:clean": "rimraf tests/serialize/,*",
Expand All @@ -94,7 +109,7 @@
"test:serialize:11": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=application/rdf+xml -out=,structures.xml && node diff ,structures.xml t11-ref.xml",
"test:serialize:12": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=text/turtle -out=,structures.ttl && node diff ,structures.ttl t12-ref.ttl",
"test:serialize:13": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=application/n-triples -out=,structures.nt && node ./data.js -format=application/n-triples -in=,structures.nt -format=text/turtle -out=,structures.nt.ttl && node diff ,structures.nt.ttl t13-ref.ttl",
"test:unit": "mocha --growl --require ./tests/babel-register.js tests/unit/**-test.js",
"test:unit": "mocha --growl --require ./tests/babel-register.js tests/unit/**-test.*",
"test:unit:egp": "mocha --require ./tests/babel-register.js tests/unit/fetcher-egp-test.js",
"test:unit:dev": "mocha --watch --growl --require ./tests/babel-register.js tests/unit/**-test.js"
},
Expand Down
3 changes: 1 addition & 2 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 { isNamedNode } from './utils/terms'

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
65 changes: 0 additions & 65 deletions src/blank-node.js

This file was deleted.

101 changes: 101 additions & 0 deletions src/blank-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import ClassOrder from './class-order'
import Node from './node-internal'
import IndexedFormula from './store'
import { BlankNodeTermType } from './types'
import { BlankNode as TFBlankNode } from './tf-types'

/**
* 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 implements TFBlankNode {
termType: typeof BlankNodeTermType = BlankNodeTermType;
/**
* The next unique identifier for blank nodes
*/
static nextId: number = 0;
static NTAnonymousNodePrefix: '_:' = '_:'

private static getId (id: string | unknown): string {
if (id) {
if (typeof id !== 'string') {
console.log('Bad blank id:', id)
throw new Error('Bad id argument to new blank node: ' + id)
}

if (id.includes('#')) {
// Is a URI with hash fragment
let fragments = id.split('#')
return fragments[fragments.length - 1]
}

return id
}

return 'n' + BlankNode.nextId++
}

classOrder = ClassOrder.BlankNode
/** Whether this is a blank node */
isBlank: number = 1
/**
* This type of node is a variable.
*
* Note that the existence of this property already indicates that it is a variable.
*/
isVar = 1

/**
* Initializes this node
* @param [id] The identifier for the blank node
*/
constructor (id?: string | unknown) {
super(BlankNode.getId(id))
}

/**
* The identifier for the blank node
* @deprecated use [[value]] instead.
*/
public get id (): string {
return this.value
}

public set id (value: string) {
this.value = value
}

compareTerm (other: BlankNode): number {
if (this.classOrder < other.classOrder) {
return -1
}
if (this.classOrder > other.classOrder) {
return +1
}
if (this.id < other.id) {
return -1
}
if (this.id > other.id) {
return +1
}
return 0
}

/**
* 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
}

toCanonical () {
return BlankNode.NTAnonymousNodePrefix + this.value
}

toString () {
return BlankNode.NTAnonymousNodePrefix + this.id
}
}
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
51 changes: 0 additions & 51 deletions src/collection.js

This file was deleted.

Loading

0 comments on commit d5000f5

Please sign in to comment.