Skip to content

Commit

Permalink
refactor(rstream-query): TS strictNullChecks
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 9, 2019
1 parent 29ef1a5 commit 0c05d6c
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions packages/rstream-query/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IObjectOf } from "@thi.ng/api";
import { assert, IObjectOf } from "@thi.ng/api";
import { intersection, join } from "@thi.ng/associative";
import { equiv } from "@thi.ng/equiv";
import { illegalArgs } from "@thi.ng/errors";
Expand Down Expand Up @@ -143,16 +143,16 @@ export class TripleStore implements Iterable<Triple>, IToDot {
let o = this.indexO.get(t[2]);
const id = this.findTriple(s, p, o, t);
if (id === -1) return false;
s.delete(id);
!s.size && this.indexS.delete(t[0]);
p.delete(id);
!p.size && this.indexP.delete(t[1]);
o.delete(id);
!o.size && this.indexO.delete(t[2]);
s!.delete(id);
!s!.size && this.indexS.delete(t[0]);
p!.delete(id);
!p!.size && this.indexP.delete(t[1]);
o!.delete(id);
!o!.size && this.indexO.delete(t[2]);
this.allIDs.delete(id);
delete this.triples[id];
this.freeIDs.push(id);
this.broadcastTriple(s, p, o, t);
this.broadcastTriple(s!, p!, o!, t);
return true;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ export class TripleStore implements Iterable<Triple>, IToDot {
emitTriples?: true
): ISubscribable<Triples>;
addPatternQuery(pattern: Pattern, id?: string, emitTriples = true) {
let results: ISubscribable<TripleIds | Triples>;
let results: ISubscribable<TripleIds | Triples> | undefined;
const [s, p, o] = pattern;
if (s == null && p == null && o == null) {
results = <ISubscribable<TripleIds>>this.streamAll;
Expand Down Expand Up @@ -272,10 +272,10 @@ export class TripleStore implements Iterable<Triple>, IToDot {
)
);
return query.transform(
map((triples) => {
map((triples: Triples) => {
const res = new Set<any>();
for (let f of triples) {
res.add(resolve(f));
res.add(resolve!(f));
}
return res;
}),
Expand Down Expand Up @@ -356,8 +356,8 @@ export class TripleStore implements Iterable<Triple>, IToDot {
* @param spec
*/
addQueryFromSpec(spec: QuerySpec): QuerySolution {
let query: QuerySolution;
let curr: QuerySolution;
let query: QuerySolution | undefined;
let curr: QuerySolution | undefined;
for (let q of spec.q) {
if (isWhereQuery(q)) {
curr = this.addMultiJoin(this.addParamQueries(q.where));
Expand All @@ -368,6 +368,7 @@ export class TripleStore implements Iterable<Triple>, IToDot {
}
query = curr;
}
assert(!!query, "illegal query spec");
let xforms: Transducer<any, any>[] = [];
if (spec.limit) {
xforms.push(limitSolutions(spec.limit));
Expand All @@ -380,10 +381,10 @@ export class TripleStore implements Iterable<Triple>, IToDot {
}
if (xforms.length) {
query = <ISubscribable<any>>(
query.subscribe(comp.apply(null, <any>xforms))
query!.subscribe(comp.apply(null, <any>xforms))
);
}
return query;
return query!;
}

toDot(opts?: Partial<DotOpts>) {
Expand All @@ -398,7 +399,7 @@ export class TripleStore implements Iterable<Triple>, IToDot {

protected nextID() {
if (this.freeIDs.length) {
return this.freeIDs.pop();
return this.freeIDs.pop()!;
}
return this.NEXT_ID++;
}
Expand All @@ -415,7 +416,12 @@ export class TripleStore implements Iterable<Triple>, IToDot {
this.streamO.next({ index: o, key: t[2] });
}

protected findTriple(s: TripleIds, p: TripleIds, o: TripleIds, f: Triple) {
protected findTriple(
s: TripleIds | undefined,
p: TripleIds | undefined,
o: TripleIds | undefined,
f: Triple
) {
if (s && p && o) {
const triples = this.triples;
const index =
Expand Down

0 comments on commit 0c05d6c

Please sign in to comment.