Js: Uses Rome instead of JS standard

Provides a built-in linter.

Some formatting parameter are overriden to align with Rust and Python.
pull/382/head
Tpt 2 years ago committed by Thomas Tanon
parent 70d4eef803
commit f15101a2b3
  1. 42
      js/build_package.js
  2. 7
      js/package.json
  3. 10
      js/rome.json
  4. 86
      js/test/model.mjs
  5. 345
      js/test/store.mjs

@ -1,31 +1,29 @@
#! /usr/bin/env node #! /usr/bin/env node
const fs = require('fs') const fs = require("fs");
// We copy file to the new directory // We copy file to the new directory
fs.mkdirSync('pkg') fs.mkdirSync("pkg");
for (const file of fs.readdirSync('./pkg-web')) { for (const file of fs.readdirSync("./pkg-web")) {
fs.copyFileSync('./pkg-web/' + file, './pkg/' + file) fs.copyFileSync(`./pkg-web/${file}`, `./pkg/${file}`);
} }
for (const file of fs.readdirSync('./pkg-node')) { for (const file of fs.readdirSync("./pkg-node")) {
fs.copyFileSync('./pkg-node/' + file, './pkg/' + file) fs.copyFileSync(`./pkg-node/${file}`, `./pkg/${file}`);
} }
const pkg = JSON.parse(fs.readFileSync('./pkg/package.json')) const pkg = JSON.parse(fs.readFileSync("./pkg/package.json"));
pkg.name = 'oxigraph' pkg.name = "oxigraph";
pkg.main = 'node.js' pkg.main = "node.js";
pkg.browser = 'web.js' pkg.browser = "web.js";
pkg.files = [ pkg.files = ["*.{js,wasm,d.ts}"];
'*.{js,wasm,d.ts}' pkg.homepage = "https://github.com/oxigraph/oxigraph/tree/main/js";
]
pkg.homepage = 'https://github.com/oxigraph/oxigraph/tree/main/js'
pkg.bugs = { pkg.bugs = {
url: 'https://github.com/oxigraph/oxigraph/issues' url: "https://github.com/oxigraph/oxigraph/issues",
} };
pkg.collaborators = undefined pkg.collaborators = undefined;
pkg.repository = { pkg.repository = {
type: 'git', type: "git",
url: 'https://github.com/oxigraph/oxigraph.git', url: "https://github.com/oxigraph/oxigraph.git",
directory: 'js' directory: "js",
} };
fs.writeFileSync('./pkg/package.json', JSON.stringify(pkg, null, 2)) fs.writeFileSync("./pkg/package.json", JSON.stringify(pkg, null, 2));

@ -3,12 +3,13 @@
"description": "Oxigraph JS build and tests", "description": "Oxigraph JS build and tests",
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"mocha": "^10.0.0",
"@rdfjs/data-model": "^2.0.1", "@rdfjs/data-model": "^2.0.1",
"standard": "^17.0.0" "mocha": "^10.0.0",
"rome": "^11.0.0"
}, },
"scripts": { "scripts": {
"test": "standard && wasm-pack build --debug --target nodejs && mocha", "fmt": "rome format . --write && rome check . --apply-suggested",
"test": "rome ci . && wasm-pack build --debug --target nodejs && mocha",
"build": "rm -rf pkg && wasm-pack build --release --target web --out-name web && mv pkg pkg-web && wasm-pack build --release --target nodejs --out-name node && mv pkg pkg-node && node build_package.js && rm -r pkg-web && rm -r pkg-node", "build": "rm -rf pkg && wasm-pack build --release --target web --out-name web && mv pkg pkg-web && wasm-pack build --release --target nodejs --out-name node && mv pkg pkg-node && node build_package.js && rm -r pkg-web && rm -r pkg-node",
"release": "npm run build && npm publish ./pkg", "release": "npm run build && npm publish ./pkg",
"pack": "npm run build && npm pack ./pkg" "pack": "npm run build && npm pack ./pkg"

@ -0,0 +1,10 @@
{
"formatter": {
"indentStyle": "space",
"indentSize": 4,
"lineWidth": 100
},
"linter": {
"ignore": ["pkg"]
}
}

@ -1,38 +1,52 @@
/* global describe, it */ /* global describe, it */
import oxigraph from '../pkg/oxigraph.js' import oxigraph from "../pkg/oxigraph.js";
import assert from 'assert' import assert from "assert";
import runTests from '../node_modules/@rdfjs/data-model/test/index.js' import runTests from "../node_modules/@rdfjs/data-model/test/index.js";
runTests({ factory: oxigraph }) runTests({ factory: oxigraph });
describe('DataModel', function () { describe("DataModel", function () {
describe('#toString()', function () { describe("#toString()", function () {
it('namedNode().toString() should return SPARQL compatible syntax', function () { it("namedNode().toString() should return SPARQL compatible syntax", function () {
assert.strictEqual('<http://example.com>', oxigraph.namedNode('http://example.com').toString()) assert.strictEqual(
}) "<http://example.com>",
oxigraph.namedNode("http://example.com").toString(),
it('blankNode().toString() should return SPARQL compatible syntax', function () { );
assert.strictEqual('_:a', oxigraph.blankNode('a').toString()) });
})
it("blankNode().toString() should return SPARQL compatible syntax", function () {
it('literal().toString() should return SPARQL compatible syntax', function () { assert.strictEqual("_:a", oxigraph.blankNode("a").toString());
assert.strictEqual('"a\\"b"@en', oxigraph.literal('a"b', 'en').toString()) });
})
it("literal().toString() should return SPARQL compatible syntax", function () {
it('defaultGraph().toString() should return SPARQL compatible syntax', function () { assert.strictEqual('"a\\"b"@en', oxigraph.literal('a"b', "en").toString());
assert.strictEqual('DEFAULT', oxigraph.defaultGraph().toString()) });
})
it("defaultGraph().toString() should return SPARQL compatible syntax", function () {
it('variable().toString() should return SPARQL compatible syntax', function () { assert.strictEqual("DEFAULT", oxigraph.defaultGraph().toString());
assert.strictEqual('?a', oxigraph.variable('a').toString()) });
})
it("variable().toString() should return SPARQL compatible syntax", function () {
it('quad().toString() should return SPARQL compatible syntax', function () { assert.strictEqual("?a", oxigraph.variable("a").toString());
assert.strictEqual( });
'<http://example.com/s> <http://example.com/p> <<<http://example.com/s1> <http://example.com/p1> <http://example.com/o1>>> <http://example.com/g>',
oxigraph.quad(oxigraph.namedNode('http://example.com/s'), oxigraph.namedNode('http://example.com/p'), oxigraph.quad(oxigraph.namedNode('http://example.com/s1'), oxigraph.namedNode('http://example.com/p1'), oxigraph.namedNode('http://example.com/o1')), oxigraph.namedNode('http://example.com/g')).toString() it("quad().toString() should return SPARQL compatible syntax", function () {
) assert.strictEqual(
}) "<http://example.com/s> <http://example.com/p> <<<http://example.com/s1> <http://example.com/p1> <http://example.com/o1>>> <http://example.com/g>",
}) oxigraph
}) .quad(
oxigraph.namedNode("http://example.com/s"),
oxigraph.namedNode("http://example.com/p"),
oxigraph.quad(
oxigraph.namedNode("http://example.com/s1"),
oxigraph.namedNode("http://example.com/p1"),
oxigraph.namedNode("http://example.com/o1"),
),
oxigraph.namedNode("http://example.com/g"),
)
.toString(),
);
});
});
});

@ -1,161 +1,192 @@
/* global describe, it */ /* global describe, it */
import { Store } from '../pkg/oxigraph.js' import { Store } from "../pkg/oxigraph.js";
import assert from 'assert' import assert from "assert";
import dataModel from '@rdfjs/data-model' import dataModel from "@rdfjs/data-model";
const ex = dataModel.namedNode('http://example.com') const ex = dataModel.namedNode("http://example.com");
const triple = dataModel.quad( const triple = dataModel.quad(
dataModel.blankNode('s'), dataModel.blankNode("s"),
dataModel.namedNode('http://example.com/p'), dataModel.namedNode("http://example.com/p"),
dataModel.literal('o') dataModel.literal("o"),
) );
describe('Store', function () { describe("Store", function () {
describe('#add()', function () { describe("#add()", function () {
it('an added quad should be in the store', function () { it("an added quad should be in the store", function () {
const store = new Store() const store = new Store();
store.add(dataModel.quad(ex, ex, triple)) store.add(dataModel.quad(ex, ex, triple));
assert(store.has(dataModel.quad(ex, ex, triple))) assert(store.has(dataModel.quad(ex, ex, triple)));
}) });
}) });
describe('#delete()', function () { describe("#delete()", function () {
it('an removed quad should not be in the store anymore', function () { it("an removed quad should not be in the store anymore", function () {
const store = new Store([dataModel.quad(triple, ex, ex)]) const store = new Store([dataModel.quad(triple, ex, ex)]);
assert(store.has(dataModel.quad(triple, ex, ex))) assert(store.has(dataModel.quad(triple, ex, ex)));
store.delete(dataModel.quad(triple, ex, ex)) store.delete(dataModel.quad(triple, ex, ex));
assert(!store.has(dataModel.quad(triple, ex, ex))) assert(!store.has(dataModel.quad(triple, ex, ex)));
}) });
}) });
describe('#has()', function () { describe("#has()", function () {
it('an added quad should be in the store', function () { it("an added quad should be in the store", function () {
const store = new Store([dataModel.quad(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)]);
assert(store.has(dataModel.quad(ex, ex, ex))) assert(store.has(dataModel.quad(ex, ex, ex)));
}) });
}) });
describe('#size()', function () { describe("#size()", function () {
it('A store with one quad should have 1 for size', function () { it("A store with one quad should have 1 for size", function () {
const store = new Store([dataModel.quad(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)]);
assert.strictEqual(1, store.size) assert.strictEqual(1, store.size);
}) });
}) });
describe('#match_quads()', function () { describe("#match_quads()", function () {
it('blank pattern should return all quads', function () { it("blank pattern should return all quads", function () {
const store = new Store([dataModel.quad(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)]);
const results = store.match() const results = store.match();
assert.strictEqual(1, results.length) assert.strictEqual(1, results.length);
assert(dataModel.quad(ex, ex, ex).equals(results[0])) assert(dataModel.quad(ex, ex, ex).equals(results[0]));
}) });
}) });
describe('#query()', function () { describe("#query()", function () {
it('ASK true', function () { it("ASK true", function () {
const store = new Store([dataModel.quad(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)]);
assert.strictEqual(true, store.query('ASK { ?s ?s ?s }')) assert.strictEqual(true, store.query("ASK { ?s ?s ?s }"));
}) });
it('ASK false', function () { it("ASK false", function () {
const store = new Store() const store = new Store();
assert.strictEqual(false, store.query('ASK { FILTER(false)}')) assert.strictEqual(false, store.query("ASK { FILTER(false)}"));
}) });
it('CONSTRUCT', function () { it("CONSTRUCT", function () {
const store = new Store([dataModel.quad(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)]);
const results = store.query('CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }') const results = store.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }");
assert.strictEqual(1, results.length) assert.strictEqual(1, results.length);
assert(dataModel.quad(ex, ex, ex).equals(results[0])) assert(dataModel.quad(ex, ex, ex).equals(results[0]));
}) });
it('SELECT', function () { it("SELECT", function () {
const store = new Store([dataModel.quad(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)]);
const results = store.query('SELECT ?s WHERE { ?s ?p ?o }') const results = store.query("SELECT ?s WHERE { ?s ?p ?o }");
assert.strictEqual(1, results.length) assert.strictEqual(1, results.length);
assert(ex.equals(results[0].get('s'))) assert(ex.equals(results[0].get("s")));
}) });
it('SELECT with NOW()', function () { it("SELECT with NOW()", function () {
const store = new Store([dataModel.quad(ex, ex, ex)]) const store = new Store([dataModel.quad(ex, ex, ex)]);
const results = store.query('SELECT * WHERE { FILTER(2022 <= YEAR(NOW()) && YEAR(NOW()) <= 2100) }') const results = store.query(
assert.strictEqual(1, results.length) "SELECT * WHERE { FILTER(2022 <= YEAR(NOW()) && YEAR(NOW()) <= 2100) }",
}) );
assert.strictEqual(1, results.length);
it('SELECT with RAND()', function () { });
const store = new Store([dataModel.quad(ex, ex, ex)])
const results = store.query('SELECT (RAND() AS ?y) WHERE {}') it("SELECT with RAND()", function () {
assert.strictEqual(1, results.length) const store = new Store([dataModel.quad(ex, ex, ex)]);
}) const results = store.query("SELECT (RAND() AS ?y) WHERE {}");
}) assert.strictEqual(1, results.length);
});
describe('#update()', function () { });
it('INSERT DATA', function () {
const store = new Store() describe("#update()", function () {
store.update('INSERT DATA { <http://example.com> <http://example.com> <http://example.com> }') it("INSERT DATA", function () {
assert.strictEqual(1, store.size) const store = new Store();
}) store.update(
"INSERT DATA { <http://example.com> <http://example.com> <http://example.com> }",
it('DELETE DATA', function () { );
const store = new Store([dataModel.quad(ex, ex, ex)]) assert.strictEqual(1, store.size);
store.update('DELETE DATA { <http://example.com> <http://example.com> <http://example.com> }') });
assert.strictEqual(0, store.size)
}) it("DELETE DATA", function () {
const store = new Store([dataModel.quad(ex, ex, ex)]);
it('DELETE WHERE', function () { store.update(
const store = new Store([dataModel.quad(ex, ex, ex)]) "DELETE DATA { <http://example.com> <http://example.com> <http://example.com> }",
store.update('DELETE WHERE { ?v ?v ?v }') );
assert.strictEqual(0, store.size) assert.strictEqual(0, store.size);
}) });
})
it("DELETE WHERE", function () {
describe('#load()', function () { const store = new Store([dataModel.quad(ex, ex, ex)]);
it('load NTriples in the default graph', function () { store.update("DELETE WHERE { ?v ?v ?v }");
const store = new Store() assert.strictEqual(0, store.size);
store.load('<http://example.com> <http://example.com> <http://example.com> .', 'application/n-triples') });
assert(store.has(dataModel.quad(ex, ex, ex))) });
})
describe("#load()", function () {
it('load NTriples in an other graph', function () { it("load NTriples in the default graph", function () {
const store = new Store() const store = new Store();
store.load('<http://example.com> <http://example.com> <http://example.com> .', 'application/n-triples', null, ex) store.load(
assert(store.has(dataModel.quad(ex, ex, ex, ex))) "<http://example.com> <http://example.com> <http://example.com> .",
}) "application/n-triples",
);
it('load Turtle with a base IRI', function () { assert(store.has(dataModel.quad(ex, ex, ex)));
const store = new Store() });
store.load('<http://example.com> <http://example.com> <> .', 'text/turtle', 'http://example.com')
assert(store.has(dataModel.quad(ex, ex, ex))) it("load NTriples in an other graph", function () {
}) const store = new Store();
store.load(
it('load NQuads', function () { "<http://example.com> <http://example.com> <http://example.com> .",
const store = new Store() "application/n-triples",
store.load('<http://example.com> <http://example.com> <http://example.com> <http://example.com> .', 'application/n-quads') null,
assert(store.has(dataModel.quad(ex, ex, ex, ex))) ex,
}) );
assert(store.has(dataModel.quad(ex, ex, ex, ex)));
it('load TriG with a base IRI', function () { });
const store = new Store()
store.load('GRAPH <> { <http://example.com> <http://example.com> <> }', 'application/trig', 'http://example.com') it("load Turtle with a base IRI", function () {
assert(store.has(dataModel.quad(ex, ex, ex, ex))) const store = new Store();
}) store.load(
}) "<http://example.com> <http://example.com> <> .",
"text/turtle",
describe('#dump()', function () { "http://example.com",
it('dump dataset content', function () { );
const store = new Store([dataModel.quad(ex, ex, ex, ex)]) assert(store.has(dataModel.quad(ex, ex, ex)));
assert.strictEqual('<http://example.com> <http://example.com> <http://example.com> <http://example.com> .\n', store.dump('application/n-quads')) });
})
it("load NQuads", function () {
it('dump named graph content', function () { const store = new Store();
const store = new Store([dataModel.quad(ex, ex, ex, ex)]) store.load(
assert.strictEqual('<http://example.com> <http://example.com> <http://example.com> .\n', store.dump('application/n-triples', ex)) "<http://example.com> <http://example.com> <http://example.com> <http://example.com> .",
}) "application/n-quads",
);
it('dump default graph content', function () { assert(store.has(dataModel.quad(ex, ex, ex, ex)));
const store = new Store([dataModel.quad(ex, ex, ex, ex)]) });
assert.strictEqual('', store.dump('application/n-triples'))
}) it("load TriG with a base IRI", function () {
}) const store = new Store();
}) store.load(
"GRAPH <> { <http://example.com> <http://example.com> <> }",
"application/trig",
"http://example.com",
);
assert(store.has(dataModel.quad(ex, ex, ex, ex)));
});
});
describe("#dump()", function () {
it("dump dataset content", function () {
const store = new Store([dataModel.quad(ex, ex, ex, ex)]);
assert.strictEqual(
"<http://example.com> <http://example.com> <http://example.com> <http://example.com> .\n",
store.dump("application/n-quads"),
);
});
it("dump named graph content", function () {
const store = new Store([dataModel.quad(ex, ex, ex, ex)]);
assert.strictEqual(
"<http://example.com> <http://example.com> <http://example.com> .\n",
store.dump("application/n-triples", ex),
);
});
it("dump default graph content", function () {
const store = new Store([dataModel.quad(ex, ex, ex, ex)]);
assert.strictEqual("", store.dump("application/n-triples"));
});
});
});

Loading…
Cancel
Save