UNPKG

@thi.ng/rstream-query

Version:

@thi.ng/rstream based triple store & reactive query engine

112 lines 4.68 kB
import type { IObjectOf, Maybe } from "@thi.ng/api"; import type { ISubscription } from "@thi.ng/rstream"; import { type DotOpts, type IToDot } from "@thi.ng/rstream-dot"; import { Stream } from "@thi.ng/rstream/stream"; import type { Edit, PathPattern, Pattern, QuerySolution, QuerySpec, Triple, TripleIds, Triples } from "./api.js"; export declare class TripleStore implements Iterable<Triple>, IToDot { NEXT_ID: number; freeIDs: number[]; triples: Triple[]; indexS: Map<any, TripleIds>; indexP: Map<any, TripleIds>; indexO: Map<any, TripleIds>; indexSelections: IObjectOf<Map<any, ISubscription<Edit, TripleIds>>>; queries: Map<string, ISubscription<any, TripleIds>>; allIDs: TripleIds; streamAll: Stream<TripleIds>; streamS: Stream<Edit>; streamP: Stream<Edit>; streamO: Stream<Edit>; constructor(triples?: Iterable<Triple>); [Symbol.iterator](): IterableIterator<Triple>; has(t: Triple): boolean; get(t: Triple, notFound?: any): any; add(t: Triple): boolean; into(triples: Iterable<Triple>): boolean; delete(t: Triple): boolean; /** * Replaces triple `a` with `b`, *iff* `a` is actually in the store. * Else does nothing. * * @param a - * @param b - */ replace(a: Triple, b: Triple): boolean; /** * Creates a new query subscription from given SPO pattern. Any * `null` values in the pattern act as wildcard selectors and any * other value as filter for the given triple component. E.g. the * pattern `[null, "type", "person"]` matches all triples which have * `"type"` as predicate and `"person"` as object. Likewise the * pattern `[null, null, null]` matches ALL triples in the graph. * * By default, the returned rstream subscription emits sets of * matched triples. If only the raw triple IDs are wanted, set * `emitTriples` arg to `false`. * * @param pattern - * @param id - */ addPatternQuery(pattern: Pattern, id?: string): ISubscription<any, Triples>; addPatternQuery(pattern: Pattern, id?: string, emitTriples?: false): ISubscription<any, TripleIds>; addPatternQuery(pattern: Pattern, id?: string, emitTriples?: true): ISubscription<any, Triples>; /** * Creates a new parametric query using given pattern with at least * 1 query variable. Query vars are strings with `?` prefix. The * rest of the string is considered the variable name. * * ```js * g.addParamQuery(["?a", "friend", "?b"]); * ``` * * Internally, the query pattern is translated into a basic param * query with an additional result transformation to resolve the * stated query variable solutions. Returns a rstream subscription * emitting arrays of solution objects like: * * ```js * [{ a: "asterix", b: "obelix" }, { a: "romeo", b: "julia" }] * ``` * * @param pattern - * @param id - */ addParamQuery([s, p, o]: Pattern, id?: string): QuerySolution; /** * Converts the given path pattern into a number of sub-queries and * return a rstream subscription of re-joined result solutions. If * `maxLen` is given and greater than the number of actual path * predicates, the predicates are repeated. * * @param path - * @param maxDepth - * @param id - */ addPathQuery(path: PathPattern, maxDepth?: number, id?: string): QuerySolution; /** * Like {@link TripleStore.addMultiJoin}, but optimized for only two * input queries. Returns a rstream subscription computing the * natural join of the given input query results. * * @param id - * @param a - * @param b - */ addJoin(a: QuerySolution, b: QuerySolution, id?: string): QuerySolution; addMultiJoin(queries: Iterable<QuerySolution>, keepVars?: Iterable<string>, id?: string): QuerySolution; /** * Compiles given query spec into a number of sub-queries and result * transformations. Returns rstream subscription of final result * sets. See {@link QuerySpec} docs for further details. * * @param spec - */ addQueryFromSpec(spec: QuerySpec): QuerySolution; toDot(opts?: Partial<DotOpts>): string; protected nextID(): number; private broadcastTriple; protected findTriple(s: Maybe<TripleIds>, p: Maybe<TripleIds>, o: Maybe<TripleIds>, f: Triple): number; protected getIndexSelection(stream: Stream<Edit>, key: any, id: string): ISubscription<any, TripleIds>; protected addParamQueries(patterns: Iterable<Pattern>): IterableIterator<QuerySolution>; } //# sourceMappingURL=store.d.ts.map