@thi.ng/rstream-query
Version:
@thi.ng/rstream based triple store & reactive query engine
54 lines • 1.96 kB
TypeScript
/**
* Converts given object into an iterable of triples, with the following
* conversion rules:
*
* - Toplevel object keys are used as subjects and MUST each have a
* plain object as value, where its keys are used as predicates and
* values as objects (in the SPO sense).
* - Plain objects in SPO object position are translated into unique IDs
* in order to allow the nested map to become a subject itself. In RDF
* terms, this is equivalent to BNodes.
* - Arrays in SPO object position cause multiple triples with same
* subject & predicate to be emitted. If any of the items in the array
* is a plain object, it will be treated as BNode and transformed as
* described in the previous rule
*
* @example
* ```ts tangle:../export/as-triples.ts
* import { asTriples } from "@thi.ng/rstream-query";
*
* const src = {
* "@thi.ng/rstream-query": {
* type: "project",
* author: "toxi",
* tag: ["ES6", "TypeScript", "graph"]
* },
* toxi: {
* type: "person",
* hasAccount: [
* {type: "twitter", id: "toxi"},
* {type: "github", id: "postspectacular"}
* ]
* }
* };
*
* console.log([...asTriples(src)]);
* // [ [ '@thi.ng/rstream-query', 'type', 'project' ],
* // [ '@thi.ng/rstream-query', 'author', 'toxi' ],
* // [ '@thi.ng/rstream-query', 'tag', 'ES6' ],
* // [ '@thi.ng/rstream-query', 'tag', 'TypeScript' ],
* // [ '@thi.ng/rstream-query', 'tag', 'graph' ],
* // [ 'toxi', 'type', 'person' ],
* // [ 'toxi', 'hasAccount', '__b0__' ],
* // [ '__b0__', 'type', 'twitter' ],
* // [ '__b0__', 'id', 'toxi' ],
* // [ 'toxi', 'hasAccount', '__b1__' ],
* // [ '__b1__', 'type', 'github' ],
* // [ '__b1__', 'id', 'postspectacular' ] ]
* ```
*
* @param obj -
* @param subject - internal use only, do not specify!
*/
export declare const asTriples: (obj: any, subject?: any) => IterableIterator<any[]>;
//# sourceMappingURL=convert.d.ts.map