Skip to content

Commit 264b981

Browse files
authored
refactor(experimental): Add missing function return types (#26006)
In preparation for globally enabling an eslint rule that will require them.
1 parent f85c24e commit 264b981

File tree

13 files changed

+108
-88
lines changed

13 files changed

+108
-88
lines changed

experimental/dds/ot/ot/src/ot.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export abstract class SharedOT<TState, TOp> extends SharedObject {
6767
this.global = this.local = initialValue;
6868
}
6969

70-
protected apply(op: TOp) {
70+
protected apply(op: TOp): void {
7171
this.local = this.applyCore(this.state, op);
7272

7373
// If we are not attached, don't submit the op.
@@ -105,7 +105,7 @@ export abstract class SharedOT<TState, TOp> extends SharedObject {
105105
this.global = this.local = this.serializer.parse(rawContent) as TState;
106106
}
107107

108-
protected onDisconnect() {}
108+
protected onDisconnect(): void {}
109109

110110
/**
111111
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}
@@ -121,7 +121,7 @@ export abstract class SharedOT<TState, TOp> extends SharedObject {
121121
messageEnvelope: ISequencedMessageEnvelope,
122122
messagesContent: IRuntimeMessagesContent,
123123
local: boolean,
124-
) {
124+
): void {
125125
// Discard any sequenced ops that are now below the minimum sequence number.
126126
const minSeq = this.deltaManager.minimumSequenceNumber;
127127
while (this.sequencedOps[0]?.seq < minSeq) {
@@ -171,7 +171,7 @@ export abstract class SharedOT<TState, TOp> extends SharedObject {
171171
}
172172
}
173173

174-
protected get state() {
174+
protected get state(): TState {
175175
// If the locally cached state is dirty, reset it to the global state and reapply our
176176
// pending ops to bring it up to date.
177177
if (this.localDirty) {

experimental/dds/ot/ot/src/test/delta.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class SharedDelta extends SharedOT<Delta, Delta> {
1818
return runtime.createChannel(id, DeltaFactory.Type) as SharedDelta;
1919
}
2020

21-
public static getFactory() {
21+
public static getFactory(): DeltaFactory {
2222
return new DeltaFactory();
2323
}
2424

@@ -30,14 +30,14 @@ export class SharedDelta extends SharedOT<Delta, Delta> {
3030
return this.state;
3131
}
3232

33-
public get text() {
33+
public get text(): string {
3434
return this.state.reduce((s, delta) => {
3535
// eslint-disable-next-line @typescript-eslint/no-base-to-string
3636
return `${s}${delta.insert?.toString()}`;
3737
}, "");
3838
}
3939

40-
public get length() {
40+
public get length(): number {
4141
return this.text.length;
4242
}
4343

@@ -49,11 +49,11 @@ export class SharedDelta extends SharedOT<Delta, Delta> {
4949
return state.compose(op);
5050
}
5151

52-
public insert(position: number, text: string) {
52+
public insert(position: number, text: string): void {
5353
this.apply(new Delta().retain(position).insert(text));
5454
}
5555

56-
public delete(start: number, end: number) {
56+
public delete(start: number, end: number): void {
5757
this.apply(new Delta().retain(start).delete(end - start));
5858
}
5959
}
@@ -67,10 +67,10 @@ export class DeltaFactory implements IChannelFactory {
6767
packageVersion: "test",
6868
};
6969

70-
public get type() {
70+
public get type(): string {
7171
return DeltaFactory.Type;
7272
}
73-
public get attributes() {
73+
public get attributes(): IChannelAttributes {
7474
return DeltaFactory.Attributes;
7575
}
7676

@@ -82,13 +82,13 @@ export class DeltaFactory implements IChannelFactory {
8282
id: string,
8383
services: IChannelServices,
8484
attributes: IChannelAttributes,
85-
) {
85+
): Promise<SharedDelta> {
8686
const instance = new SharedDelta(id, runtime, attributes);
8787
await instance.load(services);
8888
return instance;
8989
}
9090

91-
public create(runtime: IFluidDataStoreRuntime, id: string) {
91+
public create(runtime: IFluidDataStoreRuntime, id: string): SharedDelta {
9292
const instance = new SharedDelta(id, runtime, this.attributes);
9393
instance.initializeLocal();
9494
return instance;

experimental/dds/ot/ot/src/test/ot.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ import {
1313

1414
import { DeltaFactory, SharedDelta } from "./delta.js";
1515

16-
const createLocalOT = (id: string) => {
16+
const createLocalOT = (id: string): SharedDelta => {
1717
const factory = SharedDelta.getFactory();
1818
return factory.create(new MockFluidDataStoreRuntime(), id);
1919
};
2020

21-
function createConnectedOT(id: string, runtimeFactory: MockContainerRuntimeFactory) {
21+
function createConnectedOT(
22+
id: string,
23+
runtimeFactory: MockContainerRuntimeFactory,
24+
): SharedDelta {
2225
// Create and connect a second SharedCell.
2326
const dataStoreRuntime = new MockFluidDataStoreRuntime();
2427
runtimeFactory.createContainerRuntime(dataStoreRuntime);
@@ -40,7 +43,7 @@ describe("SharedDelta", () => {
4043
delta = createLocalOT("OT");
4144
});
4245

43-
const expect = (expected: string) => {
46+
const expect = (expected: string): void => {
4447
assert.deepEqual(delta.text, expected);
4548
};
4649

@@ -115,7 +118,7 @@ describe("SharedDelta", () => {
115118
expect();
116119
});
117120

118-
const expect = (expected?: string) => {
121+
const expect = (expected?: string): void => {
119122
containerRuntimeFactory.processAllMessages();
120123

121124
const actual1 = doc1.text;

experimental/dds/ot/ot/src/test/ot.stress.spec.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ describe("SharedOT", () => {
2323
let runtimes: MockContainerRuntimeForReconnection[] = [];
2424
let trace: string[]; // Repro steps to be printed if a failure is encountered.
2525

26-
const extract = (doc: SharedDelta) => {
26+
const extract = (doc: SharedDelta): string => {
2727
return doc.text;
2828
};
2929

3030
/**
3131
* Drains the queue of pending ops for each client and vets that all docs converged on the same state.
3232
*/
33-
const expect = async () => {
33+
const expect = async (): Promise<void> => {
3434
// Reconnect any disconnected clients before processing pending ops.
3535
{
3636
for (let i = 0; i < runtimes.length; i++) {
@@ -76,7 +76,7 @@ describe("SharedOT", () => {
7676
syncProbability: number,
7777
disconnectProbability: number,
7878
seed: number,
79-
) {
79+
): Promise<void> {
8080
try {
8181
docs = [];
8282
runtimes = [];
@@ -108,11 +108,10 @@ describe("SharedOT", () => {
108108

109109
// Returns a pseudorandom 32b integer in the range [0 .. max).
110110
// eslint-disable-next-line no-bitwise
111-
const int32 = (max = 0x7fffffff) => (float64() * max) | 0;
111+
const int32 = (max = 0x7fffffff): number => (float64() * max) | 0;
112+
const randomText = (): string => `${float64().toString(36).substr(0, int32(12))}`;
112113

113-
const randomText = () => `${float64().toString(36).substr(0, int32(12))}`;
114-
115-
const insert = (docIndex: number, position: number, text: string) => {
114+
const insert = (docIndex: number, position: number, text: string): void => {
116115
trace?.push(
117116
`doc${
118117
docIndex + 1
@@ -121,7 +120,7 @@ describe("SharedOT", () => {
121120
docs[docIndex].insert(position, text);
122121
};
123122

124-
const del = (docIndex: number, start: number, end: number) => {
123+
const del = (docIndex: number, start: number, end: number): void => {
125124
trace?.push(`doc${docIndex + 1}.delete(/* start: */ ${start}, /* end: */ ${end});`);
126125
docs[docIndex].delete(start, end);
127126
};

experimental/dds/ot/sharejs/json1/src/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export class Json1Factory implements IChannelFactory {
2626
packageVersion: pkgVersion,
2727
};
2828

29-
public get type() {
29+
public get type(): string {
3030
return Json1Factory.Type;
3131
}
32-
public get attributes() {
32+
public get attributes(): IChannelAttributes {
3333
return Json1Factory.Attributes;
3434
}
3535

experimental/dds/ot/sharejs/json1/src/json1.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class SharedJson1 extends SharedOT<Doc, JSONOp> {
3030
return runtime.createChannel(id, Json1Factory.Type) as SharedJson1;
3131
}
3232

33-
public static getFactory() {
33+
public static getFactory(): Json1Factory {
3434
return new Json1Factory();
3535
}
3636

@@ -43,31 +43,35 @@ export class SharedJson1 extends SharedOT<Doc, JSONOp> {
4343
return this.state;
4444
}
4545

46-
public apply(op: JSONOp) {
46+
public apply(op: JSONOp): void {
4747
super.apply(op);
4848
}
4949

5050
protected transform(input: JSONOp, transform: JSONOp): JSONOp {
5151
return Json1OTType.transformNoConflict(input, transform, "left");
5252
}
5353

54-
protected applyCore(state: Doc, op: JSONOp) {
54+
protected applyCore(state: Doc, op: JSONOp): Doc {
5555
return Json1OTType.apply(state, op) as Doc;
5656
}
5757

58-
public insert<T>(path: Path, value: Serializable<T>) {
58+
public insert<T>(path: Path, value: Serializable<T>): void {
5959
this.apply(insertOp(path, value as Doc));
6060
}
6161

62-
public move(from: Path, to: Path) {
62+
public move(from: Path, to: Path): void {
6363
this.apply(moveOp(from, to));
6464
}
6565

66-
public remove(path: Path, value?: boolean) {
66+
public remove(path: Path, value?: boolean): void {
6767
this.apply(removeOp(path, value));
6868
}
6969

70-
public replace<T, U>(path: Path, oldValue: Serializable<T>, newValue: Serializable<U>) {
70+
public replace<T, U>(
71+
path: Path,
72+
oldValue: Serializable<T>,
73+
newValue: Serializable<U>,
74+
): void {
7175
this.apply(replaceOp(path, oldValue as Doc, newValue as Doc));
7276
}
7377
}

experimental/dds/ot/sharejs/json1/src/test/json1.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ import {
1414

1515
import { Json1Factory, SharedJson1 } from "../index.js";
1616

17-
const createLocalOT = (id: string) => {
17+
const createLocalOT = (id: string): SharedJson1 => {
1818
const factory = SharedJson1.getFactory();
1919
return factory.create(new MockFluidDataStoreRuntime(), id) as SharedJson1;
2020
};
2121

22-
function createConnectedOT(id: string, runtimeFactory: MockContainerRuntimeFactory) {
22+
function createConnectedOT(
23+
id: string,
24+
runtimeFactory: MockContainerRuntimeFactory,
25+
): SharedJson1 {
2326
// Create and connect a second SharedCell.
2427
const dataStoreRuntime = new MockFluidDataStoreRuntime();
2528
runtimeFactory.createContainerRuntime(dataStoreRuntime);
@@ -47,7 +50,7 @@ describe("SharedJson1", () => {
4750
ot.replace([], null, {});
4851
});
4952

50-
const expect = <T>(expected: Jsonable<T>) => {
53+
const expect = <T>(expected: Jsonable<T>): void => {
5154
assert.deepEqual(ot.get(), expected);
5255
};
5356

@@ -122,7 +125,7 @@ describe("SharedJson1", () => {
122125
expect([]);
123126
});
124127

125-
const expect = <T>(expected?: Jsonable<T>) => {
128+
const expect = <T>(expected?: Jsonable<T>): void => {
126129
containerRuntimeFactory.processAllMessages();
127130

128131
const actual1 = doc1.get();

experimental/dds/sequence-deprecated/src/sequenceFactory.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ export class SharedObjectSequenceFactory implements IChannelFactory {
5959
* @deprecated SharedObjectSequence is not recommended for use and will be removed in an upcoming release.
6060
* For more info, please see {@link https://github.com/microsoft/FluidFramework/issues/8526 | Github issue 8526}
6161
*/
62-
public get type() {
62+
public get type(): string {
6363
return SharedObjectSequenceFactory.Type;
6464
}
6565

6666
/**
6767
* @deprecated SharedObjectSequence is not recommended for use and will be removed in an upcoming release.
6868
* For more info, please see {@link https://github.com/microsoft/FluidFramework/issues/8526 | Github issue 8526}
6969
*/
70-
public get attributes() {
70+
public get attributes(): IChannelAttributes {
7171
return SharedObjectSequenceFactory.Attributes;
7272
}
7373

@@ -138,15 +138,15 @@ export class SharedNumberSequenceFactory implements IChannelFactory {
138138
* @deprecated SharedNumberSequence is not recommended for use and will be removed in an upcoming release.
139139
* For more info, please see {@link https://github.com/microsoft/FluidFramework/issues/8526 | Github issue 8526}
140140
*/
141-
public get type() {
141+
public get type(): string {
142142
return SharedNumberSequenceFactory.Type;
143143
}
144144

145145
/**
146146
* @deprecated SharedNumberSequence is not recommended for use and will be removed in an upcoming release.
147147
* For more info, please see {@link https://github.com/microsoft/FluidFramework/issues/8526 | Github issue 8526}
148148
*/
149-
public get attributes() {
149+
public get attributes(): IChannelAttributes {
150150
return SharedNumberSequenceFactory.Attributes;
151151
}
152152

experimental/dds/sequence-deprecated/src/sharedNumberSequence.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class SharedNumberSequenceClass extends SharedSequence<number> {
4444
* @deprecated SharedNumberSequence is not recommended for use and will be removed in an upcoming release.
4545
* For more info, please see {@link https://github.com/microsoft/FluidFramework/issues/8526 | Github issue 8526}.
4646
*/
47-
public getRange(start: number, end?: number) {
47+
public getRange(start: number, end?: number): number[] {
4848
return this.getItems(start, end);
4949
}
5050
}

0 commit comments

Comments
 (0)