From 0c05d6cf88c720fb1e37e36310e57f3f78f9a977 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Sun, 9 Jun 2019 22:06:17 +0100 Subject: [PATCH] refactor(rstream-query): TS strictNullChecks --- packages/rstream-query/src/store.ts | 40 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/packages/rstream-query/src/store.ts b/packages/rstream-query/src/store.ts index b9efaf683a..0e44fdd1d3 100644 --- a/packages/rstream-query/src/store.ts +++ b/packages/rstream-query/src/store.ts @@ -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"; @@ -143,16 +143,16 @@ export class TripleStore implements Iterable, 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; } @@ -197,7 +197,7 @@ export class TripleStore implements Iterable, IToDot { emitTriples?: true ): ISubscribable; addPatternQuery(pattern: Pattern, id?: string, emitTriples = true) { - let results: ISubscribable; + let results: ISubscribable | undefined; const [s, p, o] = pattern; if (s == null && p == null && o == null) { results = >this.streamAll; @@ -272,10 +272,10 @@ export class TripleStore implements Iterable, IToDot { ) ); return query.transform( - map((triples) => { + map((triples: Triples) => { const res = new Set(); for (let f of triples) { - res.add(resolve(f)); + res.add(resolve!(f)); } return res; }), @@ -356,8 +356,8 @@ export class TripleStore implements Iterable, 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)); @@ -368,6 +368,7 @@ export class TripleStore implements Iterable, IToDot { } query = curr; } + assert(!!query, "illegal query spec"); let xforms: Transducer[] = []; if (spec.limit) { xforms.push(limitSolutions(spec.limit)); @@ -380,10 +381,10 @@ export class TripleStore implements Iterable, IToDot { } if (xforms.length) { query = >( - query.subscribe(comp.apply(null, xforms)) + query!.subscribe(comp.apply(null, xforms)) ); } - return query; + return query!; } toDot(opts?: Partial) { @@ -398,7 +399,7 @@ export class TripleStore implements Iterable, IToDot { protected nextID() { if (this.freeIDs.length) { - return this.freeIDs.pop(); + return this.freeIDs.pop()!; } return this.NEXT_ID++; } @@ -415,7 +416,12 @@ export class TripleStore implements Iterable, 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 =