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

Typescript #373

Merged
merged 29 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f0a166c
Enable class properties
Nov 29, 2019
dbf61f9
Move term utils to separate file
Nov 29, 2019
071eeaf
Convert terms to typescript
Nov 29, 2019
5442f71
Convert statement and formula
Nov 29, 2019
5e7c08c
Migrate to Typescript #355 (includes #363)
joepio Oct 22, 2019
bbd3820
Minimize circular dependencies
Dec 2, 2019
595e02b
Remove and simplify some generics, improve `identity` documentation
Dec 2, 2019
038ed76
Patch up the test suite
Dec 3, 2019
0e54248
Rework, complete and test the data factories
Dec 3, 2019
82910de
Cleanup some TS & build things
Dec 3, 2019
eb86e63
Extract all 'tf' types to a separate file
Dec 3, 2019
cae463f
fixup! Patch up the test suite
joepio Dec 9, 2019
4f3053d
Typeguard fixes & refactor TF names
joepio Dec 9, 2019
0f61303
Add tests to utils
joepio Dec 9, 2019
963ab63
TypeGuard tests, renames #355
joepio Dec 9, 2019
3ba17c6
Rename TFTypes, remove TF namespace
joepio Dec 9, 2019
279a2a2
Apply suggestions from code review
joepio Dec 13, 2019
ae83701
Rename Utils, add tests for .equals in datafactory
joepio Dec 16, 2019
30fc8db
PR Feedack: Cleanup data factory tests, docs
joepio Dec 16, 2019
79684f4
TermTypes as consts, not enums
joepio Dec 16, 2019
dfc669e
Remove static termtypes
joepio Dec 17, 2019
637eba0
More tests for utils, stricter types in store.ts
joepio Dec 10, 2019
faeddd2
Match bolean simplification, use helper for URI
joepio Dec 13, 2019
d0ec4bc
Implement feedback Vinnl and Megoth
joepio Dec 13, 2019
bdfbcbe
Use union type and consts for mime types
joepio Dec 17, 2019
f4c4604
Removed taskforce references
joepio Dec 17, 2019
b6448da
Fix ContentType imports
joepio Dec 17, 2019
0ea38a7
Fix import, rename TFDataFactory to RdfJs
joepio Dec 17, 2019
d41ef37
Stricter type Formula.fetcher
joepio Dec 17, 2019
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
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
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 './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 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
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