@platform/cell.schema
Version:
URI and database schemas for the `cell.os`.
159 lines (158 loc) • 6.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require(".");
var test_1 = require("../test");
describe('Schema', function () {
describe('static', function () {
it('hash', function () {
var res = _1.Schema.Hash.sha256({ msg: 'abc' });
(0, test_1.expect)(res).to.eql('sha256-88e2147d5ed37885f807e219fc43e5e32c150c83a121086b84b6ae43991ca7b7');
});
it('cuid', function () {
var res = _1.Schema.cuid();
(0, test_1.expect)(res.length).to.greaterThan(20);
(0, test_1.expect)(res[0]).to.eql('c');
});
it('slug', function () {
var res = _1.Schema.slug();
(0, test_1.expect)(res.length).to.greaterThan(5);
(0, test_1.expect)(res.length).to.lessThan(10);
});
});
describe('namespace', function () {
it('existing id', function () {
var ns = _1.Schema.ns('foo');
(0, test_1.expect)(ns.id).to.eql('foo');
(0, test_1.expect)(ns.uri).to.eql('ns:foo');
});
it('generated id', function () {
var ns = _1.Schema.ns(_1.Schema.cuid());
(0, test_1.expect)(ns.id.length).to.greaterThan(10);
(0, test_1.expect)(ns.uri).to.eql("ns:".concat(ns.id));
});
it('has path', function () {
var ns = _1.Schema.ns('foo');
(0, test_1.expect)(ns.path).to.eql('NS/foo');
});
it('from uri', function () {
var ns = _1.Schema.ns('ns:foo');
(0, test_1.expect)(ns.id).to.eql('foo');
(0, test_1.expect)(ns.path).to.eql('NS/foo');
(0, test_1.expect)(ns.uri).to.eql('ns:foo');
});
});
describe('cell', function () {
it('cell:A1', function () {
var ns = _1.Schema.ns('foo');
var res = ns.cell('A1');
(0, test_1.expect)(res.id).to.eql('A1');
(0, test_1.expect)(res.path).to.eql('NS/foo/CELL/A1');
(0, test_1.expect)(res.uri.toString()).to.eql('cell:foo:A1');
});
});
describe('column', function () {
it('column:A', function () {
var ns = _1.Schema.ns('foo');
var res = ns.column('A');
(0, test_1.expect)(res.id).to.eql('A');
(0, test_1.expect)(res.path).to.eql('NS/foo/COL/A');
(0, test_1.expect)(res.uri.toString()).to.eql('cell:foo:A');
});
});
describe('row', function () {
it('row:1', function () {
var ns = _1.Schema.ns('foo');
var res = ns.row('1');
(0, test_1.expect)(res.id).to.eql('1');
(0, test_1.expect)(res.path).to.eql('NS/foo/ROW/1');
(0, test_1.expect)(res.uri.toString()).to.eql('cell:foo:1');
});
});
describe('file', function () {
it('foo:123', function () {
var ns = _1.Schema.ns('foo');
var res = ns.file('123');
(0, test_1.expect)(res.fileid).to.eql('123');
(0, test_1.expect)(res.path).to.eql('NS/foo/FILE/123');
(0, test_1.expect)(res.uri).to.eql('file:foo:123');
});
});
describe('Schema.from', function () {
it('ns', function () {
var uri = 'ns:foo';
var path = _1.Schema.ns(uri).path;
var test = function (input) {
var res = _1.Schema.from.ns(input);
(0, test_1.expect)(res.uri).to.eql(uri);
(0, test_1.expect)(res.toString()).to.eql(uri);
(0, test_1.expect)(res.parts.id).to.eql('foo');
(0, test_1.expect)(res.path).to.eql(path);
};
test(uri);
test(path);
test({ path: path });
});
it('cell', function () {
var ns = 'ns:foo';
var uri = 'cell:foo:A1';
var path = _1.Schema.ns(ns).cell('A1').path;
var test = function (input) {
var res = _1.Schema.from.cell(input);
(0, test_1.expect)(res.uri).to.eql(uri);
(0, test_1.expect)(res.toString()).to.eql(uri);
(0, test_1.expect)(res.parts.id).to.eql('foo:A1');
(0, test_1.expect)(res.path).to.eql(path);
};
test(uri);
test(path);
test({ path: path });
});
it('cell (row)', function () {
var ns = 'ns:foo';
var uri = 'cell:foo:1';
var path = _1.Schema.ns(ns).row('1').path;
var test = function (input) {
var res = _1.Schema.from.row(input);
(0, test_1.expect)(res.uri).to.eql(uri);
(0, test_1.expect)(res.toString()).to.eql(uri);
(0, test_1.expect)(res.parts.id).to.eql('foo:1');
(0, test_1.expect)(res.path).to.eql(path);
};
test(uri);
test(path);
test({ path: path });
});
it('cell (column)', function () {
var ns = 'ns:foo';
var uri = 'cell:foo:A';
var path = _1.Schema.ns(ns).column('A').path;
var test = function (input) {
var res = _1.Schema.from.column(input);
(0, test_1.expect)(res.uri).to.eql(uri);
(0, test_1.expect)(res.toString()).to.eql(uri);
(0, test_1.expect)(res.parts.id).to.eql('foo:A');
(0, test_1.expect)(res.path).to.eql(path);
};
test(uri);
test(path);
test({ path: path });
});
it('file', function () {
var ns = 'ns:foo';
var uri = 'file:foo:123';
var path = _1.Schema.ns(ns).file('123').path;
var test = function (input) {
var res = _1.Schema.from.file(input);
(0, test_1.expect)(res.uri).to.eql(uri);
(0, test_1.expect)(res.toString()).to.eql(uri);
(0, test_1.expect)(res.parts.id).to.eql('foo:123');
(0, test_1.expect)(res.parts.ns).to.eql('foo');
(0, test_1.expect)(res.parts.file).to.eql('123');
(0, test_1.expect)(res.path).to.eql(path);
};
test(path);
test(uri);
test({ path: path });
});
});
});