Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "json-rel", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Transparent data references in JSON", | ||
@@ -46,3 +46,2 @@ "main": "src/index.js", | ||
"blanket": "^1.2.3", | ||
"browserify": "^13.0.0", | ||
"chai": "^3.5.0", | ||
@@ -49,0 +48,0 @@ "chai-things": "^0.2.0", |
@@ -8,2 +8,6 @@ 'use strict' | ||
constructor({path, spec, value}) { | ||
if (new.target === AbstractRel && !spec) { | ||
throw new TypeError('Cannot construct AbstractRel instances without a defined `spec`') | ||
} | ||
this.path = path | ||
@@ -14,3 +18,3 @@ this.spec = spec | ||
from(obj) { | ||
use(obj) { | ||
this.value = obj | ||
@@ -53,4 +57,4 @@ | ||
static identify(data) { | ||
return _specs.find((spec, label) => { | ||
if (spec.matches(data)) { | ||
return Object.keys(_specs).find((label) => { | ||
if (_specs[label].matches(data)) { | ||
return label | ||
@@ -62,1 +66,3 @@ } | ||
} | ||
export default {AbstractRel, AbstractRelSpec} |
@@ -1,6 +0,11 @@ | ||
import {AbstractRel, AbstractRelSpec} from './abstract' | ||
import PathRelSpec from './path' | ||
import PointerRelSpec from './pointer' | ||
import QueryRelSpec from './query' | ||
import {AbstractRel, AbstractRelSpec} from './abstract' | ||
import {PathRel, PathRelSpec, path} from './path' | ||
import {PointerRel, PointerRelSpec, pointer} from './pointer' | ||
import {QueryRel, QueryRelSpec, query} from './query' | ||
export default {AbstractRel, AbstractRelSpec, PathRelSpec, PointerRelSpec, QueryRelSpec} | ||
export default { | ||
AbstractRel, AbstractRelSpec, | ||
PathRel, PathRelSpec, path, | ||
PointerRel, PointerRelSpec, pointer, | ||
QueryRel, QueryRelSpec, query | ||
} |
@@ -49,4 +49,6 @@ import jsonPath from 'jsonpath' | ||
export const $ = () => new PathRel(...arguments) | ||
delete new PathRelSpec() // ensure spec is registered with global pool by invoking it | ||
export default {PathRel, PathRelSpec, $} | ||
export const path = (path, value) => new PathRel(path, value) | ||
export default {PathRel, PathRelSpec, path} |
@@ -34,3 +34,3 @@ import jsonPointer from 'jsonpointer' | ||
if (this.matches(rel)) { | ||
return jsonPointer.get(data, rel) || [] // ? - settle on always collection or always entity | ||
return jsonPointer.get(data, rel) || [] | ||
} | ||
@@ -45,4 +45,6 @@ } | ||
export const _ = () => new PointerRel(...arguments) | ||
delete new PointerRelSpec() // ensure spec is registered with global pool by invoking it | ||
export default {PointerRel, PointerRelSpec, _} | ||
export const pointer = (path, value) => new PointerRel(path, value) | ||
export default {PointerRel, PointerRelSpec, pointer} |
@@ -40,2 +40,6 @@ import jsonQuery from 'json-query' | ||
export const ø = () => new QueryRel(...arguments) | ||
delete new QueryRelSpec() // ensure spec is registered with global pool by invoking it | ||
export const query = (path, value) => new QueryRel(path, value) | ||
export default {QueryRel, QueryRelSpec, query} |
import 'blanket' | ||
import {$, PathRel, PathRelSpec} from '../src/path' | ||
import {path, PathRel, PathRelSpec} from '../src/path' | ||
@@ -14,10 +14,15 @@ import chai from 'chai' | ||
it('should properly query paths against objects', () => { | ||
new PathRel('foo').from({foo: 'win'}).get().should.contain('win') | ||
new PathRel('foo').from({bar: 'fail'}).get().should.be.empty | ||
new PathRel('foo').use({foo: 'win'}).get().should.contain('win') | ||
new PathRel('foo').use({bar: 'fail'}).get().should.be.empty | ||
}) | ||
it('should ignore invalid query paths against objects', () => { | ||
chai.should(new PathRel('!').from({bar: 'fail'}).get()).not.throw | ||
chai.should(new PathRel('!').use({bar: 'fail'}).get()).not.throw | ||
}) | ||
it('should have a short-hand alias', () => { | ||
path('foo').use({foo: 'win'}).get().should.contain('win') | ||
}) | ||
}) |
import 'blanket' | ||
import {_, PointerRel, PointerRelSpec} from '../src/pointer' | ||
import {pointer, PointerRel, PointerRelSpec} from '../src/pointer' | ||
@@ -14,10 +14,10 @@ import chai from 'chai' | ||
it('should properly query paths against objects', () => { | ||
new PointerRel('/foo').from({foo: 'win'}).get().should.equal('win') | ||
new PointerRel('/foo').from({bar: 'fail'}).get().should.be.empty | ||
new PointerRel('/foo').use({foo: 'win'}).get().should.equal('win') | ||
new PointerRel('/foo').use({bar: 'fail'}).get().should.be.empty | ||
}) | ||
it('should ignore invalid query paths against objects', () => { | ||
chai.should(new PointerRel('!').from({bar: 'fail'}).get()).not.throw | ||
chai.should(new PointerRel('!').use({bar: 'fail'}).get()).not.throw | ||
}) | ||
}) |
import 'blanket' | ||
import {_, QueryRel, QueryRelSpec} from '../src/query' | ||
import {query, QueryRel, QueryRelSpec} from '../src/query' | ||
@@ -14,12 +14,16 @@ import chai from 'chai' | ||
it('should properly query paths against objects', () => { | ||
new QueryRel('foo.bar').from({foo: {bar: 'win'}}).get().should.equal('win') | ||
new QueryRel('foo.bar').from({bar: {foo: 'fail'}}).get().should.be.empty | ||
new QueryRel('foo.bar').use({foo: {bar: 'win'}}).get().should.equal('win') | ||
new QueryRel('foo.bar').use({bar: {foo: 'fail'}}).get().should.be.empty | ||
}) | ||
it('should ignore invalid query paths against objects', () => { | ||
chai.should(new QueryRel('!').from({bar: 'fail'}).get()).not.throw | ||
chai.should(new QueryRel('!').use({bar: 'fail'}).get()).not.throw | ||
}) | ||
it('should have a short-hand alias', () => { | ||
query('foo.bar').use({foo: {bar: 'win'}}).get().should.equal('win') | ||
}) | ||
// TODO - test array rel | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10511
7
14
224