Skip to content

Commit 3b11981

Browse files
znewtonCopilot
andauthored
Create odsp-client-specific fluidcontainer interface (#25727)
## Description #25597 includes several changes that require exposing a slightly different, ODSPClient-specific `IFluidContainer` that exposes container methods like `serialize` and `uploadBlob`. Additionally, ODSPClient already returns a customized version of `FluidContainer` with an overwritten `attach` method, but the param types are not represented in the standard IFluidContainer type. ## Breaking Changes None. ## Reviewer Guidance For examples of how this interface will be extended, see #25597. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent eb99bcd commit 3b11981

File tree

5 files changed

+71
-22
lines changed

5 files changed

+71
-22
lines changed

packages/service-clients/odsp-client/api-report/odsp-client.alpha.api.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
// @beta
88
export type IOdspAudience = IServiceAudience<OdspMember>;
99

10+
// @beta
11+
export interface IOdspFluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema> extends IFluidContainer<TContainerSchema> {
12+
attach(props?: ContainerAttachProps<OdspContainerAttachProps>): Promise<string>;
13+
}
14+
1015
// @beta
1116
export interface IOdspTokenProvider {
1217
fetchStorageToken(siteUrl: string, refresh: boolean): Promise<TokenResponse>;
@@ -18,12 +23,12 @@ export class OdspClient {
1823
constructor(properties: OdspClientProps);
1924
// (undocumented)
2025
createContainer<T extends ContainerSchema>(containerSchema: T): Promise<{
21-
container: IFluidContainer<T>;
26+
container: IOdspFluidContainer<T>;
2227
services: OdspContainerServices;
2328
}>;
2429
// (undocumented)
2530
getContainer<T extends ContainerSchema>(id: string, containerSchema: T): Promise<{
26-
container: IFluidContainer<T>;
31+
container: IOdspFluidContainer<T>;
2732
services: OdspContainerServices;
2833
}>;
2934
}
@@ -43,6 +48,12 @@ export interface OdspConnectionConfig {
4348
tokenProvider: IOdspTokenProvider;
4449
}
4550

51+
// @beta (undocumented)
52+
export interface OdspContainerAttachProps {
53+
fileName: string | undefined;
54+
filePath: string | undefined;
55+
}
56+
4657
// @beta
4758
export interface OdspContainerServices {
4859
audience: IOdspAudience;

packages/service-clients/odsp-client/api-report/odsp-client.beta.api.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
// @beta
88
export type IOdspAudience = IServiceAudience<OdspMember>;
99

10+
// @beta
11+
export interface IOdspFluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema> extends IFluidContainer<TContainerSchema> {
12+
attach(props?: ContainerAttachProps<OdspContainerAttachProps>): Promise<string>;
13+
}
14+
1015
// @beta
1116
export interface IOdspTokenProvider {
1217
fetchStorageToken(siteUrl: string, refresh: boolean): Promise<TokenResponse>;
@@ -18,12 +23,12 @@ export class OdspClient {
1823
constructor(properties: OdspClientProps);
1924
// (undocumented)
2025
createContainer<T extends ContainerSchema>(containerSchema: T): Promise<{
21-
container: IFluidContainer<T>;
26+
container: IOdspFluidContainer<T>;
2227
services: OdspContainerServices;
2328
}>;
2429
// (undocumented)
2530
getContainer<T extends ContainerSchema>(id: string, containerSchema: T): Promise<{
26-
container: IFluidContainer<T>;
31+
container: IOdspFluidContainer<T>;
2732
services: OdspContainerServices;
2833
}>;
2934
}
@@ -43,6 +48,12 @@ export interface OdspConnectionConfig {
4348
tokenProvider: IOdspTokenProvider;
4449
}
4550

51+
// @beta (undocumented)
52+
export interface OdspContainerAttachProps {
53+
fileName: string | undefined;
54+
filePath: string | undefined;
55+
}
56+
4657
// @beta
4758
export interface OdspContainerServices {
4859
audience: IOdspAudience;

packages/service-clients/odsp-client/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
*/
1515

1616
export type {
17-
OdspConnectionConfig,
17+
IOdspAudience,
18+
IOdspFluidContainer,
1819
OdspClientProps,
20+
OdspConnectionConfig,
21+
OdspContainerAttachProps,
1922
OdspContainerServices,
20-
IOdspAudience,
2123
OdspMember,
2224
TokenResponse,
2325
} from "./interfaces.js";

packages/service-clients/odsp-client/src/interfaces.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import type {
77
IConfigProviderBase,
88
ITelemetryBaseLogger,
99
} from "@fluidframework/core-interfaces";
10-
import type { IMember, IServiceAudience } from "@fluidframework/fluid-static";
10+
import type {
11+
ContainerAttachProps,
12+
ContainerSchema,
13+
IFluidContainer,
14+
IMember,
15+
IServiceAudience,
16+
} from "@fluidframework/fluid-static";
1117

1218
import type { IOdspTokenProvider } from "./token.js";
1319

@@ -59,7 +65,6 @@ export interface OdspClientProps {
5965
}
6066

6167
/**
62-
* @legacy
6368
* @beta
6469
*/
6570
export interface OdspContainerAttachProps {
@@ -74,6 +79,26 @@ export interface OdspContainerAttachProps {
7479
fileName: string | undefined;
7580
}
7681

82+
/**
83+
* ODSP version of the IFluidContainer interface.
84+
* @beta
85+
*/
86+
export interface IOdspFluidContainer<
87+
TContainerSchema extends ContainerSchema = ContainerSchema,
88+
> extends IFluidContainer<TContainerSchema> {
89+
/**
90+
* A newly created container starts detached from the collaborative service.
91+
* Calling `attach()` uploads the new container to the service and connects to the collaborative service.
92+
*
93+
* This function is the same as the IFluidContainer.attach function, but has ODSP specific function signatures.
94+
*
95+
* @param props - Optional properties to pass to the attach function.
96+
*
97+
* @returns A promise which resolves when the attach is complete, with the string identifier of the container.
98+
*/
99+
attach(props?: ContainerAttachProps<OdspContainerAttachProps>): Promise<string>;
100+
}
101+
77102
/**
78103
* OdspContainerServices is returned by the OdspClient alongside a FluidContainer. It holds the
79104
* functionality specifically tied to the ODSP service, and how the data stored in the

packages/service-clients/odsp-client/src/odspClient.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ import type {
2020
} from "@fluidframework/core-interfaces";
2121
import type { IClient } from "@fluidframework/driver-definitions";
2222
import type { IDocumentServiceFactory } from "@fluidframework/driver-definitions/internal";
23-
import type {
24-
ContainerAttachProps,
25-
ContainerSchema,
26-
IFluidContainer,
27-
} from "@fluidframework/fluid-static";
23+
import type { ContainerAttachProps, ContainerSchema } from "@fluidframework/fluid-static";
2824
import {
2925
createDOProviderContainerRuntimeFactory,
3026
createFluidContainer,
@@ -46,6 +42,7 @@ import type {
4642
OdspConnectionConfig,
4743
OdspContainerAttachProps,
4844
OdspContainerServices as IOdspContainerServices,
45+
IOdspFluidContainer,
4946
} from "./interfaces.js";
5047
import { OdspContainerServices } from "./odspContainerServices.js";
5148
import type { IOdspTokenProvider } from "./token.js";
@@ -116,7 +113,7 @@ export class OdspClient {
116113
public async createContainer<T extends ContainerSchema>(
117114
containerSchema: T,
118115
): Promise<{
119-
container: IFluidContainer<T>;
116+
container: IOdspFluidContainer<T>;
120117
services: IOdspContainerServices;
121118
}> {
122119
const loaderProps = this.getLoaderProps(containerSchema);
@@ -129,18 +126,21 @@ export class OdspClient {
129126
},
130127
});
131128

132-
const fluidContainer = await this.createFluidContainer(container, this.connectionConfig);
129+
const fluidContainer = await this.createFluidContainer<T>(
130+
container,
131+
this.connectionConfig,
132+
);
133133

134134
const services = await this.getContainerServices(container);
135135

136-
return { container: fluidContainer as IFluidContainer<T>, services };
136+
return { container: fluidContainer, services };
137137
}
138138

139139
public async getContainer<T extends ContainerSchema>(
140140
id: string,
141141
containerSchema: T,
142142
): Promise<{
143-
container: IFluidContainer<T>;
143+
container: IOdspFluidContainer<T>;
144144
services: IOdspContainerServices;
145145
}> {
146146
const loaderProps = this.getLoaderProps(containerSchema);
@@ -152,11 +152,11 @@ export class OdspClient {
152152
});
153153
const container = await loadExistingContainer({ ...loaderProps, request: { url } });
154154

155-
const fluidContainer = await createFluidContainer({
155+
const fluidContainer = await createFluidContainer<T>({
156156
container,
157157
});
158158
const services = await this.getContainerServices(container);
159-
return { container: fluidContainer as IFluidContainer<T>, services };
159+
return { container: fluidContainer, services };
160160
}
161161

162162
private getLoaderProps(schema: ContainerSchema): ILoaderProps {
@@ -192,10 +192,10 @@ export class OdspClient {
192192
};
193193
}
194194

195-
private async createFluidContainer(
195+
private async createFluidContainer<T extends ContainerSchema>(
196196
container: IContainer,
197197
connection: OdspConnectionConfig,
198-
): Promise<IFluidContainer> {
198+
): Promise<IOdspFluidContainer<T>> {
199199
/**
200200
* See {@link FluidContainer.attach}
201201
*/
@@ -226,7 +226,7 @@ export class OdspClient {
226226
*/
227227
return resolvedUrl.itemId;
228228
};
229-
const fluidContainer = await createFluidContainer({ container });
229+
const fluidContainer = await createFluidContainer<T>({ container });
230230
fluidContainer.attach = attach;
231231
return fluidContainer;
232232
}

0 commit comments

Comments
 (0)