Skip to content

Commit 365603a

Browse files
authored
Expose creation of a frozen document service factory. (#25653)
Exposing creation of a frozen document service factory via standalone function. Given Pages container load flow, this is the step of less friction where we can enforce storage only in containers that were loaded with pending local state.
1 parent 5f52833 commit 365603a

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

packages/loader/container-loader/api-report/container-loader.legacy.alpha.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export interface ContainerAlpha extends IContainer {
2323
// @beta @legacy
2424
export function createDetachedContainer(createDetachedContainerProps: ICreateDetachedContainerProps): Promise<IContainer>;
2525

26+
// @alpha @legacy
27+
export function createFrozenDocumentServiceFactory(factory?: IDocumentServiceFactory | Promise<IDocumentServiceFactory>): IDocumentServiceFactory;
28+
2629
// @beta @legacy (undocumented)
2730
export interface IBaseProtocolHandler {
2831
// (undocumented)

packages/loader/container-loader/src/createAndLoadContainerUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
IUrlResolver,
2222
} from "@fluidframework/driver-definitions/internal";
2323

24-
import { FrozenDocumentServiceFactory } from "./frozenServices.js";
24+
import { createFrozenDocumentServiceFactory } from "./frozenServices.js";
2525
import { Loader } from "./loader.js";
2626
import type { ProtocolHandlerBuilder } from "./protocol.js";
2727

@@ -197,6 +197,6 @@ export async function loadFrozenContainerFromPendingState(
197197
): Promise<IContainer> {
198198
return loadExistingContainer({
199199
...props,
200-
documentServiceFactory: new FrozenDocumentServiceFactory(props.documentServiceFactory),
200+
documentServiceFactory: createFrozenDocumentServiceFactory(props.documentServiceFactory),
201201
});
202202
}

packages/loader/container-loader/src/frozenServices.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { TypedEventEmitter } from "@fluid-internal/client-utils";
77
import type { IDisposable } from "@fluidframework/core-interfaces";
8+
import { isPromiseLike } from "@fluidframework/core-utils/internal";
89
import {
910
ScopeType,
1011
type ConnectionMode,
@@ -28,13 +29,38 @@ import {
2829

2930
import type { IConnectionStateChangeReason } from "./contracts.js";
3031

32+
/**
33+
* Creation of a FrozenDocumentServiceFactory which wraps an existing
34+
* DocumentServiceFactory to provide a storage-only document service.
35+
*
36+
* @param documentServiceFactory - The underlying DocumentServiceFactory to wrap.
37+
* @returns A FrozenDocumentServiceFactory
38+
* @legacy @alpha
39+
*/
40+
export function createFrozenDocumentServiceFactory(
41+
factory?: IDocumentServiceFactory | Promise<IDocumentServiceFactory>,
42+
): IDocumentServiceFactory {
43+
// Sync path
44+
return factory instanceof FrozenDocumentServiceFactory
45+
? factory
46+
: new FrozenDocumentServiceFactory(factory);
47+
}
48+
3149
export class FrozenDocumentServiceFactory implements IDocumentServiceFactory {
32-
constructor(private readonly documentServiceFactory?: IDocumentServiceFactory) {}
50+
constructor(
51+
private readonly documentServiceFactory?:
52+
| IDocumentServiceFactory
53+
| Promise<IDocumentServiceFactory>,
54+
) {}
3355

3456
async createDocumentService(resolvedUrl: IResolvedUrl): Promise<IDocumentService> {
57+
let factory = this.documentServiceFactory;
58+
if (isPromiseLike(factory)) {
59+
factory = await this.documentServiceFactory;
60+
}
3561
return new FrozenDocumentService(
3662
resolvedUrl,
37-
await this.documentServiceFactory?.createDocumentService(resolvedUrl),
63+
await factory?.createDocumentService(resolvedUrl),
3864
);
3965
}
4066
async createContainer(): Promise<IDocumentService> {

packages/loader/container-loader/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
export { ConnectionState } from "./connectionState.js";
77
export { type ContainerAlpha, waitContainerToCatchUp, asLegacyAlpha } from "./container.js";
8+
export { createFrozenDocumentServiceFactory } from "./frozenServices.js";
89
export {
910
createDetachedContainer,
1011
loadExistingContainer,

0 commit comments

Comments
 (0)