@tpluscode/rdfine
Advanced tools
Comparing version 0.2.7 to 0.2.8
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.2.8](https://github.com/tpluscode/rdfine/compare/v0.2.7...v0.2.8) (2020-01-23) | ||
### Bug Fixes | ||
* proxy indexer also returns rdf lists as array ([9cd04bd](https://github.com/tpluscode/rdfine/commit/9cd04bd3fa3d02ad6d531dd80c8704c1caf30a52)) | ||
### [0.2.7](https://github.com/tpluscode/rdfine/compare/v0.2.6...v0.2.7) (2020-01-22) | ||
@@ -7,0 +14,0 @@ |
@@ -13,4 +13,1 @@ import rdf from '@rdfjs/data-model'; | ||
} | ||
export function fromResource(parent, obj, mixins) { | ||
return parent._create(obj, mixins); | ||
} |
@@ -1,2 +0,1 @@ | ||
import { fromResource } from '../../conversion'; | ||
import { propertyDecorator } from '../property'; | ||
@@ -7,3 +6,3 @@ function resourcePropertyDecorator(options = {}) { | ||
fromTerm(obj) { | ||
return fromResource(this, obj, options.as); | ||
return this._create(obj, options.as); | ||
}, | ||
@@ -10,0 +9,0 @@ toTerm(value) { |
@@ -1,2 +0,17 @@ | ||
import { fromResource } from './conversion'; | ||
import * as rdfList from './rdf-list'; | ||
function nodeToValue(target) { | ||
const fromTerm = (obj) => { | ||
switch (obj.term.termType) { | ||
case 'BlankNode': | ||
case 'NamedNode': | ||
if (rdfList.isList(obj)) { | ||
return rdfList.enumerateList(target, obj, fromTerm); | ||
} | ||
return target._create(obj); | ||
default: | ||
return obj.term; | ||
} | ||
}; | ||
return fromTerm; | ||
} | ||
export function createProxy(resource) { | ||
@@ -12,12 +27,3 @@ return new Proxy(resource, { | ||
} | ||
const results = objects | ||
.map(obj => { | ||
switch (obj.term.termType) { | ||
case 'BlankNode': | ||
case 'NamedNode': | ||
return fromResource(target, obj); | ||
default: | ||
return obj.term; | ||
} | ||
}); | ||
const results = objects.map(nodeToValue(target)); | ||
return results.length === 1 ? results[0] : results; | ||
@@ -24,0 +30,0 @@ }, |
@@ -19,5 +19,1 @@ "use strict"; | ||
exports.fromLiteral = fromLiteral; | ||
function fromResource(parent, obj, mixins) { | ||
return parent._create(obj, mixins); | ||
} | ||
exports.fromResource = fromResource; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const conversion_1 = require("../../conversion"); | ||
const property_1 = require("../property"); | ||
function resourcePropertyDecorator(options = {}) { | ||
return property_1.propertyDecorator(Object.assign(Object.assign({}, options), { fromTerm(obj) { | ||
return conversion_1.fromResource(this, obj, options.as); | ||
return this._create(obj, options.as); | ||
}, | ||
@@ -9,0 +8,0 @@ toTerm(value) { |
"use strict"; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const conversion_1 = require("./conversion"); | ||
const rdfList = __importStar(require("./rdf-list")); | ||
function nodeToValue(target) { | ||
const fromTerm = (obj) => { | ||
switch (obj.term.termType) { | ||
case 'BlankNode': | ||
case 'NamedNode': | ||
if (rdfList.isList(obj)) { | ||
return rdfList.enumerateList(target, obj, fromTerm); | ||
} | ||
return target._create(obj); | ||
default: | ||
return obj.term; | ||
} | ||
}; | ||
return fromTerm; | ||
} | ||
function createProxy(resource) { | ||
@@ -14,12 +36,3 @@ return new Proxy(resource, { | ||
} | ||
const results = objects | ||
.map(obj => { | ||
switch (obj.term.termType) { | ||
case 'BlankNode': | ||
case 'NamedNode': | ||
return conversion_1.fromResource(target, obj); | ||
default: | ||
return obj.term; | ||
} | ||
}); | ||
const results = objects.map(nodeToValue(target)); | ||
return results.length === 1 ? results[0] : results; | ||
@@ -26,0 +39,0 @@ }, |
@@ -1,7 +0,3 @@ | ||
import { DatasetCore } from 'rdf-js'; | ||
import { SingleContextClownface } from 'clownface'; | ||
import { Constructor, Mixin } from './ResourceFactory'; | ||
import { RdfResource, ResourceIdentifier } from './RdfResource'; | ||
export declare function fromLiteral(type: BooleanConstructor | StringConstructor | NumberConstructor, obj: SingleContextClownface): string | number | boolean; | ||
export declare function fromResource(parent: RdfResource, obj: SingleContextClownface<DatasetCore, ResourceIdentifier>, mixins?: Mixin<any>[] | [Constructor, ...Mixin<any>[]]): RdfResource<DatasetCore<import("rdf-js").Quad>> & import("./ResourceFactory").ResourceIndexer<RdfResource<DatasetCore<import("rdf-js").Quad>>>; | ||
//# sourceMappingURL=conversion.d.ts.map |
import { RdfResource } from './RdfResource'; | ||
export declare function createProxy<T extends RdfResource>(resource: T): T & Record<string, any>; | ||
import { ResourceIndexer } from './ResourceFactory'; | ||
export declare function createProxy<T extends RdfResource>(resource: T): T & ResourceIndexer; | ||
//# sourceMappingURL=proxy.d.ts.map |
@@ -12,4 +12,5 @@ import { Clownface } from 'clownface'; | ||
} | ||
declare type MaybeArray<T> = T | T[]; | ||
export interface ResourceIndexer<T extends RdfResource = RdfResource> { | ||
[prop: string]: T | Literal | Array<T | Literal>; | ||
[prop: string]: null | undefined | MaybeArray<T> | MaybeArray<Literal> | MaybeArray<T & ResourceIndexer>; | ||
} | ||
@@ -16,0 +17,0 @@ export declare type Mixin<T extends AnyFunction> = InstanceType<ReturnType<T>>; |
{ | ||
"name": "@tpluscode/rdfine", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "RDF/JS idiomatic, native, enjoyable", | ||
@@ -5,0 +5,0 @@ "main": "dist/node/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1206
71457