Skip to content

Commit d18b377

Browse files
authored
refactor(client): Add explicit function return types (#26013)
In preparation for globally enabling an eslint rule that requires them.
1 parent 0106829 commit d18b377

31 files changed

+205
-129
lines changed

packages/dds/register-collection/src/consensusRegisterCollection.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,27 +182,27 @@ export class ConsensusRegisterCollection<T>
182182
// 3. The runtime is disposed
183183
// The boolean value returned by the promise is true if the attempted write was ack'd and won, false otherwise.
184184
return new Promise<boolean>((resolve) => {
185-
const handleAck = (ackMessageId: number, isWinner: boolean) => {
185+
const handleAck = (ackMessageId: number, isWinner: boolean): void => {
186186
if (ackMessageId === pendingMessageId) {
187187
resolve(isWinner);
188188
removeListeners();
189189
}
190190
};
191191

192-
const handleRollback = (rollbackMessageId: number) => {
192+
const handleRollback = (rollbackMessageId: number): void => {
193193
if (rollbackMessageId === pendingMessageId) {
194194
// If we rolled back the pending message, resolve the promise with false.
195195
resolve(false);
196196
removeListeners();
197197
}
198198
};
199199

200-
const handleDisposed = () => {
200+
const handleDisposed = (): void => {
201201
resolve(false);
202202
removeListeners();
203203
};
204204

205-
const removeListeners = () => {
205+
const removeListeners = (): void => {
206206
this.internalEvents.off("pendingMessageAck", handleAck);
207207
this.internalEvents.off("pendingMessageRollback", handleRollback);
208208
this.runtime.off("dispose", handleDisposed);
@@ -272,7 +272,7 @@ export class ConsensusRegisterCollection<T>
272272
}
273273
}
274274

275-
protected onDisconnect() {}
275+
protected onDisconnect(): void {}
276276

277277
/**
278278
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}

packages/dds/register-collection/src/consensusRegisterCollectionFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export class ConsensusRegisterCollectionFactory
3030
packageVersion: pkgVersion,
3131
};
3232

33-
public get type() {
33+
public get type(): string {
3434
return ConsensusRegisterCollectionFactory.Type;
3535
}
3636

37-
public get attributes() {
37+
public get attributes(): IChannelAttributes {
3838
return ConsensusRegisterCollectionFactory.Attributes;
3939
}
4040

packages/dds/register-collection/src/test/consensusRegisterCollection.spec.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import type { ConsensusRegisterCollection } from "../consensusRegisterCollection
2323
import { ConsensusRegisterCollectionFactory } from "../consensusRegisterCollectionFactory.js";
2424
import { IConsensusRegisterCollection } from "../interfaces.js";
2525

26-
function createConnectedCollection(id: string, runtimeFactory: MockContainerRuntimeFactory) {
26+
function createConnectedCollection(
27+
id: string,
28+
runtimeFactory: MockContainerRuntimeFactory,
29+
): ConsensusRegisterCollection<unknown> {
2730
const dataStoreRuntime = new MockFluidDataStoreRuntime();
2831
runtimeFactory.createContainerRuntime(dataStoreRuntime);
2932
const services = {
@@ -35,23 +38,26 @@ function createConnectedCollection(id: string, runtimeFactory: MockContainerRunt
3538
const collection = crcFactory.create(
3639
dataStoreRuntime,
3740
id,
38-
) as ConsensusRegisterCollection<any>;
41+
) as ConsensusRegisterCollection<unknown>;
3942
collection.connect(services);
4043
return collection;
4144
}
4245

43-
function createLocalCollection(id: string) {
46+
function createLocalCollection(id: string): ConsensusRegisterCollection<unknown> {
4447
const factory = new ConsensusRegisterCollectionFactory();
4548
return factory.create(
4649
new MockFluidDataStoreRuntime(),
4750
id,
48-
) as ConsensusRegisterCollection<any>;
51+
) as ConsensusRegisterCollection<unknown>;
4952
}
5053

5154
function createCollectionForReconnection(
5255
id: string,
5356
runtimeFactory: MockContainerRuntimeFactoryForReconnection,
54-
) {
57+
): {
58+
collection: IConsensusRegisterCollection<unknown>;
59+
containerRuntime: MockContainerRuntimeForReconnection;
60+
} {
5561
const dataStoreRuntime = new MockFluidDataStoreRuntime();
5662
const containerRuntime = runtimeFactory.createContainerRuntime(dataStoreRuntime);
5763
const services = {
@@ -76,7 +82,7 @@ describe("ConsensusRegisterCollection", () => {
7682
crc = createConnectedCollection(collectionId, containerRuntimeFactory);
7783
});
7884

79-
async function writeAndProcessMsg(key: string, value: any) {
85+
async function writeAndProcessMsg(key: string, value: any): Promise<boolean> {
8086
const waitP = crc.write(key, value);
8187
containerRuntimeFactory.processAllMessages();
8288
return waitP;
@@ -133,7 +139,7 @@ describe("ConsensusRegisterCollection", () => {
133139
versions: [{ sequenceNumber: 1, value: { type: "Shared", value: "sharedObjId" } }],
134140
},
135141
});
136-
const buildTree = (serialized: string) => ({
142+
const buildTree = (serialized: string): ITree => ({
137143
entries: [new BlobTreeEntry(snapshotFileName, serialized)],
138144
});
139145

@@ -341,29 +347,25 @@ describe("ConsensusRegisterCollection", () => {
341347
);
342348
}
343349

344-
private async writeAndProcessMsg(key: string, value: any) {
350+
private async writeAndProcessMsg(key: string, value: unknown): Promise<boolean> {
345351
const waitP = this.collection1.write(key, value);
346352
this.containerRuntimeFactory.processAllMessages();
347353
return waitP;
348354
}
349-
350-
public get sharedObject() {
355+
public get sharedObject(): IConsensusRegisterCollection {
351356
// Return the remote collection because we want to verify its summary data.
352357
return this.collection2;
353358
}
354-
355-
public get expectedOutboundRoutes() {
359+
public get expectedOutboundRoutes(): string[] {
356360
return this._expectedRoutes;
357361
}
358-
359-
public async addOutboundRoutes() {
362+
public async addOutboundRoutes(): Promise<void> {
360363
const subCollectionId = `subCollection-${++this.subCollectionCount}`;
361364
const subTestCollection = createLocalCollection(subCollectionId);
362365
await this.writeAndProcessMsg(subCollectionId, subTestCollection.handle);
363366
this._expectedRoutes.push(subTestCollection.handle.absolutePath);
364367
}
365-
366-
public async deleteOutboundRoutes() {
368+
public async deleteOutboundRoutes(): Promise<void> {
367369
const subCollectionId = `subCollection-${this.subCollectionCount}`;
368370
const deletedHandle = this.collection1.read(subCollectionId) as IFluidHandleInternal;
369371
assert(deletedHandle !== undefined, "Route must be added before deleting");
@@ -375,8 +377,7 @@ describe("ConsensusRegisterCollection", () => {
375377
(route) => route !== deletedHandle.absolutePath,
376378
);
377379
}
378-
379-
public async addNestedHandles() {
380+
public async addNestedHandles(): Promise<void> {
380381
const subCollectionId1 = `subCollection-${++this.subCollectionCount}`;
381382
const subCollectionId2 = `subCollection-${++this.subCollectionCount}`;
382383
const subTestCollection1 = createLocalCollection(subCollectionId1);

packages/test/functional-tests/src/test/containerRuntime.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe("Container Runtime", () => {
156156
),
157157
);
158158

159-
const mockProvideEntryPoint = async () => ({
159+
const mockProvideEntryPoint = async (): Promise<{ myProp: string }> => ({
160160
myProp: "myValue",
161161
});
162162
containerRuntime = await loadContainerRuntime({

packages/test/functional-tests/src/test/ddsHandleEncoding.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe("DDS Handle Encoding", () => {
5555
*
5656
* @returns The list of handles found in the given contents object
5757
*/
58-
function findAllHandles(contents: unknown) {
58+
function findAllHandles(contents: unknown): string[] {
5959
const handlesFound: string[] = [];
6060
detectOutboundReferences("envelope", contents, (from, to) => {
6161
handlesFound.push(to);
@@ -156,7 +156,7 @@ describe("DDS Handle Encoding", () => {
156156
),
157157
createTestCase(
158158
LegacySharedTree.getFactory(),
159-
(tree) => {
159+
(tree): void => {
160160
const legacyNodeId: TraitLabel = "inventory" as TraitLabel;
161161

162162
const handleNode: BuildNode = {

packages/test/local-server-stress-tests/src/baseModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type StressOperations = StressDataObjectOperations | DDSModelOp | OrderSe
3636
const orderSequentiallyReducer = async (
3737
state: LocalServerStressState,
3838
op: OrderSequentially,
39-
) => {
39+
): Promise<void> => {
4040
const { baseModel, taggedHandles } = await loadAllHandles(state);
4141
const ddsState = await covertLocalServerStateToDdsState(state);
4242
const rollbackError = new Error("rollback");

packages/test/local-server-stress-tests/src/dataStoreOperations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { assert } from "@fluidframework/core-utils/internal";
77

88
import type { Client } from "./localServerStressHarness";
99

10-
export const validateAllDataStoresSaved = async (...clients: Client[]) => {
10+
export const validateAllDataStoresSaved = async (...clients: Client[]): Promise<void> => {
1111
for (const client of clients) {
1212
assert(client.container.isDirty === false, `[${client.tag}] Container is dirty!`);
1313
for (const entry of (await client.entryPoint.getContainerObjects()).filter(

packages/test/local-server-stress-tests/src/ddsModels.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function repeatFactoryAsync<T, TState = void>(
2424
factory: () => AsyncGenerator<T, TState>,
2525
): AsyncGenerator<T, TState> {
2626
let generator = factory();
27-
return async (state: TState) => {
27+
return async (state: TState): Promise<typeof done | T> => {
2828
const next = await generator(state);
2929
if (next !== done) {
3030
return next;
@@ -36,7 +36,16 @@ function repeatFactoryAsync<T, TState = void>(
3636

3737
const generateSubModelMap = (
3838
...models: Omit<DDSFuzzModel<IChannelFactory, any>, "workloadName">[]
39-
) => {
39+
): Map<
40+
string,
41+
{
42+
factory: IChannelFactory;
43+
generator: AsyncGenerator<any, DDSFuzzTestState<IChannelFactory>>;
44+
reducer: DDSFuzzModel<IChannelFactory, any>["reducer"];
45+
validateConsistency: DDSFuzzModel<IChannelFactory, any>["validateConsistency"];
46+
minimizationTransforms?: DDSFuzzModel<IChannelFactory, any>["minimizationTransforms"];
47+
}
48+
> => {
4049
const modelMap = new Map<
4150
string,
4251
{

packages/test/local-server-stress-tests/src/ddsOperations.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
*/
55

66
import { type AsyncGenerator, type AsyncReducer } from "@fluid-private/stochastic-test-utils";
7-
import { DDSFuzzTestState, Client as DDSClient } from "@fluid-private/test-dds-utils";
7+
import {
8+
DDSFuzzTestState,
9+
Client as DDSClient,
10+
type DDSFuzzModel,
11+
} from "@fluid-private/test-dds-utils";
812
import { AttachState } from "@fluidframework/container-definitions/internal";
9-
import { fluidHandleSymbol, type IFluidHandle } from "@fluidframework/core-interfaces";
13+
import {
14+
fluidHandleSymbol,
15+
type IFluidHandle,
16+
type IFluidHandleErased,
17+
} from "@fluidframework/core-interfaces/internal";
1018
import { assert, isObject } from "@fluidframework/core-utils/internal";
1119
import type {
1220
IChannel,
@@ -17,6 +25,7 @@ import { timeoutAwait } from "@fluidframework/test-utils/internal";
1725

1826
import { ddsModelMap } from "./ddsModels.js";
1927
import { LocalServerStressState, Client } from "./localServerStressHarness.js";
28+
import type { ContainerObjects } from "./stressDataObject.js";
2029
import { makeUnreachableCodePathProxy } from "./utils.js";
2130

2231
export interface DDSModelOp {
@@ -59,7 +68,13 @@ export const covertLocalServerStateToDdsState = async (
5968

6069
const random = {
6170
...state.random,
62-
handle: () => {
71+
handle: (): {
72+
tag: string;
73+
absolutePath: string;
74+
[fluidHandleSymbol]: IFluidHandleErased<unknown>;
75+
get(): Promise<unknown>;
76+
isAttached: boolean;
77+
} => {
6378
/**
6479
* here we do some funky stuff with handles so we can serialize them like json for output, but not bind them,
6580
* as they may not be attached. look at the reduce code to see how we deserialized these fake handles into real
@@ -70,10 +85,10 @@ export const covertLocalServerStateToDdsState = async (
7085
return {
7186
tag,
7287
absolutePath: realHandle.absolutePath,
73-
get [fluidHandleSymbol]() {
88+
get [fluidHandleSymbol](): IFluidHandleErased<unknown> {
7489
return realHandle[fluidHandleSymbol];
7590
},
76-
async get() {
91+
async get(): Promise<unknown> {
7792
return realHandle.get();
7893
},
7994
get isAttached() {
@@ -128,7 +143,24 @@ export const DDSModelOpReducer: AsyncReducer<DDSModelOp, LocalServerStressState>
128143
baseModel.reducer(await covertLocalServerStateToDdsState(state), subOp);
129144
};
130145

131-
export const loadAllHandles = async (state: LocalServerStressState) => {
146+
export const loadAllHandles = async (
147+
state: LocalServerStressState,
148+
): Promise<{
149+
baseModel: {
150+
factory: IChannelFactory;
151+
generator: AsyncGenerator<any, DDSFuzzTestState<IChannelFactory>>;
152+
reducer: DDSFuzzModel<IChannelFactory, any>["reducer"];
153+
validateConsistency: DDSFuzzModel<IChannelFactory, any>["validateConsistency"];
154+
minimizationTransforms?: DDSFuzzModel<IChannelFactory, any>["minimizationTransforms"];
155+
};
156+
taggedHandles: (
157+
| Readonly<ContainerObjects>
158+
| {
159+
tag: string;
160+
handle: IFluidHandle;
161+
}
162+
)[];
163+
}> => {
132164
const baseModel = ddsModelMap.get(state.channel.attributes.type);
133165
assert(baseModel !== undefined, "must have base model");
134166
const channels = await state.datastore.getChannels();
@@ -161,8 +193,11 @@ export const convertToRealHandles = (
161193
});
162194
};
163195

164-
export const validateConsistencyOfAllDDS = async (clientA: Client, clientB: Client) => {
165-
const buildChannelMap = async (client: Client) => {
196+
export const validateConsistencyOfAllDDS = async (
197+
clientA: Client,
198+
clientB: Client,
199+
): Promise<void> => {
200+
const buildChannelMap = async (client: Client): Promise<Map<string, IChannel>> => {
166201
/**
167202
* here we build a map of all the channels in the container based on their absolute path,
168203
* once we have this we can match channels in different container (clientA and clientB),

0 commit comments

Comments
 (0)