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

refactor(ordered-collection): Updated eslint to use recommended config #23335

Merged
merged 4 commits into from
Dec 20, 2024
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
5 changes: 1 addition & 4 deletions packages/dds/ordered-collection/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
*/

module.exports = {
extends: [
require.resolve("@fluidframework/eslint-config-fluid/minimal-deprecated"),
"prettier",
],
extends: [require.resolve("@fluidframework/eslint-config-fluid/recommended"), "prettier"],
parserOptions: {
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
},
Expand Down
66 changes: 40 additions & 26 deletions packages/dds/ordered-collection/src/consensusOrderedCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ type IConsensusOrderedCollectionOperation<T> =
| IConsensusOrderedCollectionCompleteOperation
| IConsensusOrderedCollectionReleaseOperation;

/** The type of the resolve function to call after the local operation is ack'd */
/**
* The type of the resolve function to call after the local operation is acknowledged.
*/
type PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;

/**
Expand All @@ -98,6 +100,9 @@ const idForLocalUnattachedClient = undefined;
* @legacy
* @alpha
*/

// TODO: #22835 Use undefined instead of any (breaking change)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export class ConsensusOrderedCollection<T = any>
extends SharedObject<IConsensusOrderedCollectionEvents<T>>
implements IConsensusOrderedCollection<T>
Expand Down Expand Up @@ -163,15 +168,18 @@ export class ConsensusOrderedCollection<T = any>
const res = await callback(result.value);

switch (res) {
case ConsensusResult.Complete:
case ConsensusResult.Complete: {
await this.complete(result.acquireId);
break;
case ConsensusResult.Release:
}
case ConsensusResult.Release: {
this.release(result.acquireId);
this.emit("localRelease", result.value, true /* intentional */);
break;
default:
}
default: {
unreachableCase(res);
}
}

return true;
Expand Down Expand Up @@ -199,16 +207,16 @@ export class ConsensusOrderedCollection<T = any>
const builder = new SummaryTreeBuilder();
let blobContent = this.serializeValue(this.data.asArray(), serializer);
builder.addBlob(snapshotFileNameData, blobContent);
blobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);
blobContent = this.serializeValue([...this.jobTracking.entries()], serializer);
builder.addBlob(snapshotFileNameTracking, blobContent);
return builder.getSummaryTree();
}

protected isActive() {
protected isActive(): boolean {
return this.runtime.connected && this.deltaManager.active;
}

protected async complete(acquireId: string) {
protected async complete(acquireId: string): Promise<void> {
if (!this.isAttached()) {
this.completeCore(acquireId);
return;
Expand All @@ -223,7 +231,7 @@ export class ConsensusOrderedCollection<T = any>
}
}

protected completeCore(acquireId: string) {
protected completeCore(acquireId: string): void {
// Note: item may be no longer in jobTracking and returned back to queue!
const rec = this.jobTracking.get(acquireId);
if (rec !== undefined) {
Expand All @@ -232,7 +240,7 @@ export class ConsensusOrderedCollection<T = any>
}
}

protected release(acquireId: string) {
protected release(acquireId: string): void {
if (!this.isAttached()) {
this.releaseCore(acquireId);
return;
Expand All @@ -249,7 +257,7 @@ export class ConsensusOrderedCollection<T = any>
}
}

protected releaseCore(acquireId: string) {
protected releaseCore(acquireId: string): void {
// Note: item may be no longer in jobTracking and returned back to queue!
const rec = this.jobTracking.get(acquireId);
if (rec !== undefined) {
Expand All @@ -270,7 +278,9 @@ export class ConsensusOrderedCollection<T = any>
const blob = await storage.readBlob(snapshotFileNameTracking);
const rawContentTracking = bufferToString(blob, "utf8");
const content = this.deserializeValue(rawContentTracking, this.serializer);
this.jobTracking = new Map(content) as JobTrackingInfo<T>;
this.jobTracking = new Map(
content as Iterable<[string, { value: T; clientId: string | undefined }]>,
);

assert(
this.data.size() === 0,
Expand All @@ -282,7 +292,7 @@ export class ConsensusOrderedCollection<T = any>
this.data.loadFrom(content2);
}

protected onDisconnect() {
protected onDisconnect(): void {
for (const [, { value, clientId }] of this.jobTracking) {
if (clientId === this.runtime.clientId) {
this.emit("localRelease", value, false /* intentional */);
Expand All @@ -294,33 +304,38 @@ export class ConsensusOrderedCollection<T = any>
message: ISequencedDocumentMessage,
local: boolean,
localOpMetadata: unknown,
) {
): void {
if (message.type === MessageType.Operation) {
const op = message.contents as IConsensusOrderedCollectionOperation<T>;
let value: IConsensusOrderedCollectionValue<T> | undefined;
switch (op.opName) {
case "add":
if (op.deserializedValue !== undefined) {
this.addCore(op.deserializedValue);
} else {
case "add": {
if (op.deserializedValue === undefined) {
this.addCore(this.deserializeValue(op.value, this.serializer) as T);
} else {
this.addCore(op.deserializedValue);
}
break;
}

case "acquire":
case "acquire": {
value = this.acquireCore(op.acquireId, message.clientId ?? undefined);
break;
}

case "complete":
case "complete": {
this.completeCore(op.acquireId);
break;
}

case "release":
case "release": {
this.releaseCore(op.acquireId);
break;
}

default:
default: {
unreachableCase(op);
}
}
if (local) {
// Resolve the pending promise for this operation now that we have received an ack for it.
Expand All @@ -345,7 +360,7 @@ export class ConsensusOrderedCollection<T = any>
).catch((error) => undefined);
}

private addCore(value: T) {
private addCore(value: T): void {
this.data.add(value);
this.emit("add", value, true /* newlyAdded */);
}
Expand Down Expand Up @@ -381,7 +396,7 @@ export class ConsensusOrderedCollection<T = any>
});
}

private removeClient(clientIdToRemove?: string) {
private removeClient(clientIdToRemove?: string): void {
const added: T[] = [];
for (const [acquireId, { value, clientId }] of this.jobTracking) {
if (clientId === clientIdToRemove) {
Expand All @@ -396,12 +411,11 @@ export class ConsensusOrderedCollection<T = any>
added.map((value) => this.emit("add", value, false /* newlyAdded */));
}

private serializeValue(value, serializer: IFluidSerializer) {
private serializeValue(value, serializer: IFluidSerializer): string {
return serializer.stringify(value, this.handle);
}

private deserializeValue(content: string, serializer: IFluidSerializer) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
private deserializeValue(content: string, serializer: IFluidSerializer): unknown {
return serializer.parse(content);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory
packageVersion: pkgVersion,
};

public get type() {
public get type(): string {
return ConsensusQueueFactory.Type;
}

public get attributes() {
public get attributes(): IChannelAttributes {
return ConsensusQueueFactory.Attributes;
}

Expand Down Expand Up @@ -72,4 +72,6 @@ export const ConsensusQueue = createSharedObjectKind(ConsensusQueueFactory);
* @legacy
* @alpha
*/
// TODO: #22835 Use undefined instead of any (breaking change)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO with work item number?

export type ConsensusQueue<T = any> = ConsensusQueueClass<T>;
4 changes: 3 additions & 1 deletion packages/dds/ordered-collection/src/consensusQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SnapshotableArray } from "./snapshotableArray.js";
* An JS array based queue implementation that is the backing data structure for ConsensusQueue
*/
class SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedCollection<T> {
public add(value: T) {
public add(value: T): void {
this.data.push(value);
}

Expand All @@ -35,6 +35,8 @@ class SnapshotableQueue<T> extends SnapshotableArray<T> implements IOrderedColle
* @legacy
* @alpha
*/
// TODO: #22835 Use undefined instead of any (breaking change)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO with work item number?

export class ConsensusQueueClass<T = any> extends ConsensusOrderedCollection<T> {
/**
* Constructs a new consensus queue. If the object is non-local an id and service interfaces will
Expand Down
4 changes: 4 additions & 0 deletions packages/dds/ordered-collection/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export interface IConsensusOrderedCollectionEvents<T> extends ISharedObjectEvent
* @legacy
* @alpha
*/
// TODO: #22835 Use undefined instead of any (breaking change)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO with work item number? And below

export interface IConsensusOrderedCollection<T = any>
extends ISharedObject<IConsensusOrderedCollectionEvents<T>> {
/**
Expand Down Expand Up @@ -152,6 +154,8 @@ export interface ISnapshotable<T> {
* @legacy
* @alpha
*/
// TODO: #22835 Use undefined instead of any (breaking change)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface IOrderedCollection<T = any> extends ISnapshotable<T> {
/**
* Adds a value to the collection
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/ordered-collection/src/snapshotableArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { assert } from "@fluidframework/core-utils/internal";
export class SnapshotableArray<T> extends Array {
protected data: T[] = [];

public asArray() {
public asArray(): T[] {
return this.data;
}

Expand Down
Loading
Loading