Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

import type {
IChannelAttributes,
IFluidDataStoreRuntime,
IChannelFactory,
IChannelServices,
IFluidDataStoreRuntime,
} from "@fluidframework/datastore-definitions/internal";
import type { SharedObjectCore } from "@fluidframework/shared-object-base/internal";
import { createSharedObjectKind } from "@fluidframework/shared-object-base/internal";

// eslint-disable-next-line import-x/no-deprecated -- Internal usage of deprecated class in factory
import { ConsensusQueueClass } from "./consensusQueue.js";
import type {
IConsensusOrderedCollection,
IConsensusOrderedCollectionFactory,
IConsensusOrderedCollectionEvents,
} from "./interfaces.js";
import { pkgVersion } from "./packageVersion.js";

Expand All @@ -23,7 +25,9 @@ import { pkgVersion } from "./packageVersion.js";
*
* @internal
*/
export class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory {
export class ConsensusQueueFactory<T>
implements IChannelFactory<IConsensusOrderedCollection<T>>
{
Comment on lines +28 to +30
// New type string, to be activated once the migration has been fully shipped dark and is safe to flip.
// See LegacyTypeAwareRegistry in packages/runtime/datastore/src/dataStoreRuntime.ts.
// public static Type = "consensus-queue";
Expand All @@ -43,24 +47,26 @@ export class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory
return ConsensusQueueFactory.Attributes;
}

/**
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
*/
public async load(
runtime: IFluidDataStoreRuntime,
id: string,
services: IChannelServices,
attributes: IChannelAttributes,
): Promise<IConsensusOrderedCollection> {
): Promise<
IConsensusOrderedCollection<T> & SharedObjectCore<IConsensusOrderedCollectionEvents<T>>
> {
// eslint-disable-next-line import-x/no-deprecated -- Internal usage of deprecated class
const collection = new ConsensusQueueClass(id, runtime, attributes);
const collection = new ConsensusQueueClass<T>(id, runtime, attributes);
await collection.load(services);
return collection;
}

public create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection {
public create(
document: IFluidDataStoreRuntime,
id: string,
): IConsensusOrderedCollection<T> & SharedObjectCore<IConsensusOrderedCollectionEvents<T>> {
// eslint-disable-next-line import-x/no-deprecated -- Internal usage of deprecated class
const collection = new ConsensusQueueClass(id, document, this.attributes);
const collection = new ConsensusQueueClass<T>(id, document, this.attributes);
collection.initializeLocal();
return collection;
}
Expand All @@ -70,7 +76,23 @@ export class ConsensusQueueFactory implements IConsensusOrderedCollectionFactory
* {@inheritDoc ConsensusQueueClass}
* @legacy @beta
*/
export const ConsensusQueue = createSharedObjectKind(ConsensusQueueFactory);
export const ConsensusQueue = createSharedObjectKind<IConsensusOrderedCollection>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: #22835 Use unknown instead of any (breaking change)
ConsensusQueueFactory<any>,
);
Comment on lines +79 to +82

// For #22835, consider exposing a helper to produce type specific ConsensusQueue.
// One problem, with doing so is that nothing inside ConsensusQueue validates the shape of T.
// A DDS load might find content that is not the same, expected type.
// But that is not any worse than the `any` that exists currently.
// /**
// * Factory for shared object kind for queue-shaped ordered collections of specific type.
// * @legacy @beta
// */
// export function TypedConsensusQueue<T>(): ISharedObjectKind<IConsensusOrderedCollection<T>> &
// SharedObjectKind<IConsensusOrderedCollection<T>> {
// return ConsensusQueue;
// }

/**
* {@inheritDoc ConsensusQueueClass}
Expand Down
1 change: 0 additions & 1 deletion packages/dds/ordered-collection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export {
ConsensusResult,
type IConsensusOrderedCollection,
type IConsensusOrderedCollectionEvents,
type IConsensusOrderedCollectionFactory,
type IOrderedCollection,
type ISnapshotable,
} from "./interfaces.js";
Comment on lines 8 to 13
Expand Down
24 changes: 0 additions & 24 deletions packages/dds/ordered-collection/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
* Licensed under the MIT License.
*/

import type {
IChannelAttributes,
IChannelFactory,
IFluidDataStoreRuntime,
IChannelServices,
} from "@fluidframework/datastore-definitions/internal";
import type {
ISharedObject,
ISharedObjectEvents,
Expand All @@ -29,24 +23,6 @@ export enum ConsensusResult {
*/
export type ConsensusCallback<T> = (value: T) => Promise<ConsensusResult>;

/**
* Consensus Ordered Collection channel factory interface
*
* Extends the base IChannelFactory to return a more definite type of IConsensusOrderedCollection
* Use for the runtime to create and load distributed data structure by type name of each channel
* @internal
*/
export interface IConsensusOrderedCollectionFactory extends IChannelFactory {
load(
document: IFluidDataStoreRuntime,
id: string,
services: IChannelServices,
attributes: IChannelAttributes,
): Promise<IConsensusOrderedCollection>;

create(document: IFluidDataStoreRuntime, id: string): IConsensusOrderedCollection;
}

/**
* Events notifying about addition, acquisition, release and completion of items
* @legacy @beta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
import { strict as assert } from "node:assert";

import { type IGCTestProvider, runGCTests } from "@fluid-private/test-dds-utils";
import type { IFluidHandleInternal } from "@fluidframework/core-interfaces/internal";
import type { IChannelServices } from "@fluidframework/datastore-definitions/internal";
import type { IFluidHandleInternal } from "@fluidframework/core-interfaces/legacy";
import type { IChannelServices } from "@fluidframework/datastore-definitions/legacy";
import type { SharedObjectCore } from "@fluidframework/shared-object-base/legacy";
import {
MockContainerRuntimeFactory,
MockContainerRuntimeFactoryForReconnection,
type MockContainerRuntimeForReconnection,
MockFluidDataStoreRuntime,
MockStorage,
} from "@fluidframework/test-runtime-utils/internal";
} from "@fluidframework/test-runtime-utils/legacy";

import { ConsensusOrderedCollection } from "../consensusOrderedCollection.js";
import {
ConsensusQueueFactory,
type ConsensusQueue,
} from "../consensusOrderedCollectionFactory.js";
import type {
IConsensusOrderedCollection,
IConsensusOrderedCollectionEvents,
} from "@fluidframework/ordered-collection/legacy";
import { ConsensusResult } from "@fluidframework/ordered-collection/legacy";

import { ConsensusQueueFactory } from "../consensusOrderedCollectionFactory.js";
import { ConsensusQueueClass } from "../consensusQueue.js";
import { ConsensusResult, type IConsensusOrderedCollection } from "../interfaces.js";
import {
acquireAndComplete,
acquireAndRelease,
Expand All @@ -32,7 +34,7 @@ import {
/**
* Test class that exposes protected applyStashedOp method for testing
*/
class TestConsensusQueue extends ConsensusQueueClass {
class TestConsensusQueue extends ConsensusQueueClass<unknown> {
public testApplyStashedOp(content: unknown): void {
this.applyStashedOp(content);
}
Expand All @@ -41,7 +43,8 @@ class TestConsensusQueue extends ConsensusQueueClass {
function createConnectedCollection(
id: string,
runtimeFactory: MockContainerRuntimeFactory,
): ConsensusQueue {
): IConsensusOrderedCollection<unknown> &
SharedObjectCore<IConsensusOrderedCollectionEvents<unknown>> {
const dataStoreRuntime = new MockFluidDataStoreRuntime();
runtimeFactory.createContainerRuntime(dataStoreRuntime);
const services: IChannelServices = {
Expand All @@ -52,12 +55,15 @@ function createConnectedCollection(
const factory = new ConsensusQueueFactory();
const testCollection = factory.create(dataStoreRuntime, id);
testCollection.connect(services);
return testCollection as ConsensusQueue;
return testCollection;
}

function createLocalCollection(id: string): ConsensusQueue {
function createLocalCollection(
id: string,
): IConsensusOrderedCollection<unknown> &
SharedObjectCore<IConsensusOrderedCollectionEvents<unknown>> {
const factory = new ConsensusQueueFactory();
return factory.create(new MockFluidDataStoreRuntime(), id) as ConsensusQueue;
return factory.create(new MockFluidDataStoreRuntime(), id);
}

function createCollectionForReconnection(
Expand Down Expand Up @@ -104,10 +110,12 @@ describe("ConsensusOrderedCollection", () => {
function generate(
input: unknown[],
output: unknown[],
creator: () => ConsensusOrderedCollection,
creator: () => IConsensusOrderedCollection &
SharedObjectCore<IConsensusOrderedCollectionEvents<unknown>>,
processMessages: () => void,
): void {
let testCollection: ConsensusOrderedCollection;
let testCollection: IConsensusOrderedCollection &
SharedObjectCore<IConsensusOrderedCollectionEvents<unknown>>;
Comment on lines +113 to +118

async function removeItem(): Promise<unknown> {
const resP = acquireAndComplete(testCollection);
Expand Down Expand Up @@ -155,7 +163,7 @@ describe("ConsensusOrderedCollection", () => {
const acquiredValue = (await removeItem()) as IFluidHandleInternal;

assert.strictEqual(acquiredValue.absolutePath, handle.absolutePath);
const dataStore = (await handle.get()) as ConsensusQueue;
const dataStore = (await handle.get()) as ConsensusQueueClass<unknown>;
assert.strictEqual(dataStore.handle.absolutePath, testCollection.handle.absolutePath);

assert.strictEqual(await removeItem(), undefined);
Expand Down
4 changes: 2 additions & 2 deletions packages/dds/ordered-collection/src/test/fuzzUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const defaultOptions: Partial<DDSFuzzSuiteOptions> = {
saveFailures: { directory: path.join(_dirname, "../../src/test/results") },
};

type FuzzTestState = DDSFuzzTestState<ConsensusQueueFactory>;
type FuzzTestState = DDSFuzzTestState<ConsensusQueueFactory<string>>;

export interface AddOperation {
type: "add";
Expand Down Expand Up @@ -180,7 +180,7 @@ function assertEqualConsensusOrderedCollections(
* Base fuzz model for ConsensusOrderedCollection
*/
export const baseConsensusOrderedCollectionModel: DDSFuzzModel<
ConsensusQueueFactory,
ConsensusQueueFactory<unknown>,
ConsensusOrderedCollectionOperation,
FuzzTestState
> = {
Expand Down
Loading