Skip to content

Commit

Permalink
BREAKING CHANGE: Make class Term constructors internal (#338)
Browse files Browse the repository at this point in the history
These constructors take the `id` at face value so can be interpreted as the
wrong term type if an invalid value is given; for instance a `NamedNode` can
be interpred as a `Literal` if instantiated with `new NamedNode('"hellow world"')`.

Consumers of the library should use the `DataFactory` instead to create new terms.
  • Loading branch information
jeswr authored Mar 27, 2023
1 parent e733c1f commit f4887f3
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 49 deletions.
27 changes: 0 additions & 27 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ import * as Util from './N3Util';
import {
default as DataFactory,

Term,
NamedNode,
Literal,
BlankNode,
Variable,
DefaultGraph,
Quad,
Triple,

termFromId,
termToId,
} from './N3DataFactory';
Expand All @@ -34,15 +25,6 @@ export {

DataFactory,

Term,
NamedNode,
Literal,
BlankNode,
Variable,
DefaultGraph,
Quad,
Triple,

termFromId,
termToId,
};
Expand All @@ -59,15 +41,6 @@ export default {

DataFactory,

Term,
NamedNode,
Literal,
BlankNode,
Variable,
DefaultGraph,
Quad,
Triple,

termFromId,
termToId,
};
2 changes: 1 addition & 1 deletion test/BlankNode-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlankNode, Term } from '../src/';
import { BlankNode, Term } from '../src/N3DataFactory';

describe('BlankNode', () => {
describe('The BlankNode module', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/DefaultGraph-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DefaultGraph, Term } from '../src/';
import { DefaultGraph, Term } from '../src/N3DataFactory';

describe('DefaultGraph', () => {
describe('The DefaultGraph module', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/Literal-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Literal, NamedNode, Term } from '../src/';
import { Literal, NamedNode, Term } from '../src/N3DataFactory';

describe('Literal', () => {
describe('The Literal module', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/N3DataFactory-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
DataFactory,
NamedNode,
Literal,
BlankNode,
Variable,
DefaultGraph,
Quad,
} from '../src/';
} from '../src/N3DataFactory';
import { DataFactory } from '../src';

describe('DataFactory', () => {
describe('namedNode', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/N3Parser-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Parser, NamedNode, BlankNode, Quad, termFromId } from '../src/';
import { Parser, termFromId } from '../src/';
import { NamedNode, BlankNode, Quad } from '../src/N3DataFactory';

const BASE_IRI = 'http://example.org/';

Expand Down
6 changes: 4 additions & 2 deletions test/N3Store-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
Store,
termFromId, termToId,
} from '../src/';
import {
NamedNode,
Literal,
DefaultGraph,
Quad,
termFromId, termToId,
} from '../src/';
} from '../src/N3DataFactory';
import namespaces from '../src/IRIs';
import chai, { expect } from 'chai';
import { Readable } from 'readable-stream';
Expand Down
3 changes: 2 additions & 1 deletion test/N3StreamParser-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StreamParser, NamedNode } from '../src/';
import { StreamParser } from '../src/';
import { NamedNode } from '../src/N3DataFactory';
import { Readable, Writable } from 'readable-stream';

describe('StreamParser', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/N3StreamWriter-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StreamWriter, Quad, NamedNode, termFromId } from '../src/';
import { StreamWriter, termFromId } from '../src/';
import { Quad, NamedNode } from '../src/N3DataFactory';
import { Readable, Writable } from 'readable-stream';

describe('StreamWriter', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/N3Writer-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
Writer,
NamedNode,
BlankNode,
Literal,
Quad,
termFromId,
} from '../src/';
import { NamedNode,
BlankNode,
Literal,
Quad } from '../src/N3DataFactory';
import namespaces from '../src/IRIs';

const { xsd } = namespaces;
Expand Down
2 changes: 1 addition & 1 deletion test/NamedNode-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NamedNode, Term } from '../src/';
import { NamedNode, Term } from '../src/N3DataFactory';

describe('NamedNode', () => {
describe('The NamedNode module', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/Quad-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Quad, Triple, DefaultGraph, termFromId, Term } from '../src/';
import { Quad, Triple, DefaultGraph, termFromId, Term } from '../src/N3DataFactory';

describe('Quad', () => {
describe('The Quad module', () => {
Expand Down
10 changes: 5 additions & 5 deletions test/Term-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
termToId,
termFromId,
} from '../src/';

import {
Term,
NamedNode,
Expand All @@ -6,11 +11,6 @@ import {
Variable,
DefaultGraph,
Quad,
termToId,
termFromId,
} from '../src/';

import {
escapeQuotes,
unescapeQuotes,
} from '../src/N3DataFactory';
Expand Down
2 changes: 1 addition & 1 deletion test/Variable-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Variable, Term } from '../src/';
import { Variable, Term } from '../src/N3DataFactory';

describe('Variable', () => {
describe('The Variable module', () => {
Expand Down

0 comments on commit f4887f3

Please sign in to comment.