Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial change to fix some warning if strictNullCheck is enabled for merge-tree package #4812

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/dds/merge-tree/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type ConflictAction<TKey, TData> =
(key: TKey, currentKey: TKey, data: TData, currentData: TData) => QProperty<TKey, TData>;

export interface Dictionary<TKey, TData> {
get(key: TKey): Property<TKey, TData>;
get(key: TKey): Property<TKey, TData> | undefined;
put(key: TKey, data: TData, conflict?: ConflictAction<TKey, TData>);
remove(key: TKey);
map<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum);
Expand Down
52 changes: 28 additions & 24 deletions packages/dds/merge-tree/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Client {
public accumWindow = 0;
public accumOps = 0;
public maxWindowTime = 0;
public longClientId: string;
public longClientId: string | undefined;

get mergeTreeDeltaCallback(): MergeTreeDeltaCallback { return this.mergeTree.mergeTreeDeltaCallback; }
set mergeTreeDeltaCallback(callback: MergeTreeDeltaCallback) { this.mergeTree.mergeTreeDeltaCallback = callback; }
Expand Down Expand Up @@ -113,7 +113,7 @@ export class Client {
public annotateMarkerNotifyConsensus(
marker: Marker,
props: Properties.PropertySet,
consensusCallback: (m: Marker) => void): ops.IMergeTreeAnnotateMsg {
consensusCallback: (m: Marker) => void): ops.IMergeTreeAnnotateMsg | undefined {
const combiningOp: ops.ICombiningOp = {
name: "consensus",
};
Expand Down Expand Up @@ -142,7 +142,7 @@ export class Client {
public annotateMarker(
marker: Marker,
props: Properties.PropertySet,
combiningOp: ops.ICombiningOp): ops.IMergeTreeAnnotateMsg {
combiningOp: ops.ICombiningOp): ops.IMergeTreeAnnotateMsg | undefined {
const annotateOp =
OpBuilder.createAnnotateMarkerOp(marker, props, combiningOp);

Expand All @@ -164,7 +164,7 @@ export class Client {
start: number,
end: number,
props: Properties.PropertySet,
combiningOp: ops.ICombiningOp): ops.IMergeTreeAnnotateMsg {
combiningOp: ops.ICombiningOp): ops.IMergeTreeAnnotateMsg | undefined {
const annotateOp = OpBuilder.createAnnotateRangeOp(
start,
end,
Expand Down Expand Up @@ -198,7 +198,7 @@ export class Client {
* @param pos - The position to insert the segment at
* @param segment - The segment to insert
*/
public insertSegmentLocal(pos: number, segment: ISegment): ops.IMergeTreeInsertMsg {
public insertSegmentLocal(pos: number, segment: ISegment): ops.IMergeTreeInsertMsg | undefined {
if (segment.cachedLength <= 0) {
return undefined;
}
Expand All @@ -213,7 +213,10 @@ export class Client {
* @param refPos - The reference position to insert the segment at
* @param segment - The segment to insert
*/
public insertAtReferencePositionLocal(refPos: ReferencePosition, segment: ISegment): ops.IMergeTreeInsertMsg {
public insertAtReferencePositionLocal(
refPos: ReferencePosition,
segment: ISegment,
): ops.IMergeTreeInsertMsg | undefined {
const pos = this.mergeTree.referencePositionToLocalPosition(
refPos,
this.getCurrentSeq(),
Expand All @@ -227,7 +230,7 @@ export class Client {
segment);

const opArgs = { op };
let traceStart: Trace;
let traceStart: Trace | undefined;
if (this.measureOps) {
traceStart = Trace.start();
}
Expand Down Expand Up @@ -293,7 +296,7 @@ export class Client {
* @param segment - The segment to get the position of
*/
public getPosition(segment: ISegment): number {
if(segment?.parent === undefined) {
if (segment?.parent === undefined) {
return -1;
}
return this.mergeTree.getPosition(segment, this.getCurrentSeq(), this.getClientId());
Expand Down Expand Up @@ -339,7 +342,7 @@ export class Client {
this.copy(range, op.register, clientArgs);
}

let traceStart: Trace;
let traceStart: Trace | undefined;
if (this.measureOps) {
traceStart = Trace.start();
}
Expand Down Expand Up @@ -373,7 +376,7 @@ export class Client {
return false;
}

let traceStart: Trace;
let traceStart: Trace | undefined;
if (this.measureOps) {
traceStart = Trace.start();
}
Expand Down Expand Up @@ -408,7 +411,7 @@ export class Client {
return false;
}

let segments: ISegment[];
let segments: ISegment[] | undefined;
if (op.seg) {
segments = [this.specToSegment(op.seg)];
} else if (op.register) {
Expand All @@ -430,7 +433,7 @@ export class Client {
return false;
}

let traceStart: Trace;
let traceStart: Trace | undefined;
if (this.measureOps) {
traceStart = Trace.start();
}
Expand Down Expand Up @@ -492,16 +495,16 @@ export class Client {
*/
private getValidOpRange(
op: ops.IMergeTreeAnnotateMsg | ops.IMergeTreeInsertMsg | ops.IMergeTreeRemoveMsg,
clientArgs: IMergeTreeClientSequenceArgs): IIntegerRange {
let start: number = op.pos1;
clientArgs: IMergeTreeClientSequenceArgs): IIntegerRange | undefined {
let start: number | undefined = op.pos1;
if (start === undefined && op.relativePos1) {
start = this.mergeTree.posFromRelativePos(
op.relativePos1,
clientArgs.referenceSequenceNumber,
clientArgs.clientId);
}

let end: number = op.pos2;
let end: number | undefined = op.pos2;
if (end === undefined && op.relativePos2) {
end = this.mergeTree.posFromRelativePos(
op.relativePos2,
Expand Down Expand Up @@ -595,7 +598,7 @@ export class Client {

private ackPendingSegment(opArgs: IMergeTreeDeltaOpArgs) {
const ackOp = (deltaOpArgs: IMergeTreeDeltaOpArgs) => {
let trace: Trace;
let trace: Trace | undefined;
if (this.measureOps) {
trace = Trace.start();
}
Expand All @@ -607,7 +610,7 @@ export class Client {
}
}

if (this.measureOps) {
if (trace) {
this.accumTime += elapsedMicroseconds(trace);
this.accumOps++;
this.accumWindow += (this.getCurrentSeq() - this.getCollabWindow().minSeq);
Expand Down Expand Up @@ -731,7 +734,7 @@ export class Client {
assert(segmentGroup === segmentSegGroup,
"Segment group not at head of segment pending queue");
const segmentPosition = this.findReconnectionPostition(segment, segmentGroup.localSeq);
let newOp: ops.IMergeTreeDeltaOp;
let newOp: ops.IMergeTreeDeltaOp | undefined;
switch (resetOp.type) {
case ops.MergeTreeDeltaType.ANNOTATE:
assert(segment.propertyManager.hasPendingProperties(), "Segment has no pending properties");
Expand Down Expand Up @@ -995,12 +998,12 @@ export class Client {
}

updateMinSeq(minSeq: number) {
let trace: Trace;
let trace: Trace | undefined;
if (this.measureOps) {
trace = Trace.start();
}
this.mergeTree.setMinSeq(minSeq);
if (this.measureOps) {
if (trace) {
const elapsed = elapsedMicroseconds(trace);
this.accumWindowTime += elapsed;
if (elapsed > this.maxWindowTime) {
Expand All @@ -1021,7 +1024,7 @@ export class Client {
console.log(`getPropertiesAtPosition cli ${this.getLongClientId(segWindow.clientId)} ref seq ${segWindow.currentSeq}`);
}

let propertiesAtPosition: Properties.PropertySet;
let propertiesAtPosition: Properties.PropertySet | undefined;
const segoff = this.getContainingSegment(pos);
const seg = segoff.segment;
if (seg) {
Expand All @@ -1036,8 +1039,8 @@ export class Client {
console.log(`getRangeExtentsOfPosition cli ${this.getLongClientId(segWindow.clientId)} ref seq ${segWindow.currentSeq}`);
}

let posStart: number;
let posAfterEnd: number;
let posStart: number | undefined;
let posAfterEnd: number | undefined;

const segoff = this.getContainingSegment(pos);
const seg = segoff.segment;
Expand Down Expand Up @@ -1070,7 +1073,8 @@ export class Client {
this.getShortClientId(this.longClientId), minSeq, currentSeq, branchId);
} else {
const oldClientId = this.longClientId;
const oldData = this.clientNameToIds.get(oldClientId).data;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const oldData = this.clientNameToIds.get(oldClientId)!.data;
this.longClientId = longClientId;
this.clientNameToIds.put(longClientId, oldData);
this.shortClientIdMap[oldData.clientId] = longClientId;
Expand Down
Loading