-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from ontola/typescript-4-rebased-squashed
Typescript
- Loading branch information
Showing
71 changed files
with
5,304 additions
and
2,747 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.