-
Notifications
You must be signed in to change notification settings - Fork 558
feat(odsp-client): Expose container serialize and rehydrate functionality #25802
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -265,6 +265,11 @@ export interface IFluidContainerInternal extends ContainerExtensionStore { | |
| * @remarks This method is used to expose uploadBlob to the IFluidContainer level. UploadBlob will upload data to server side (as of now, ODSP only). There is no downloadBlob provided as it is not needed(blob lifetime managed by server). | ||
| */ | ||
| uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>>; | ||
|
|
||
| /** | ||
| * Serialize a detached container to a string representation. This can be saved for later rehydration. | ||
| */ | ||
| serialize(): string; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -401,4 +406,13 @@ class FluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema> | |
| public async uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> { | ||
| return this.rootDataObject.uploadBlob(blob); | ||
| } | ||
|
|
||
| public serialize(): string { | ||
| if (this.container.closed || this.container.attachState !== AttachState.Detached) { | ||
| throw new Error( | ||
| "Cannot serialize container. Container must be in detached state and not closed.", | ||
| ); | ||
| } | ||
| return this.container.serialize(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Serialization implies a compatibility contract against the outputted serialized form, e.g. if the customer serializes to a string, saves that somewhere, updates to a newer version of Fluid, then tries to use that serialized form to load -- probably needs to work within some support window.
We should at least document the lifespan/expectation of compat that we're giving as we expose this API, if not include more programmatic safeguards like timebomb/version checks. This might merit some discussion, definitely also get @anthony-murphy 's opinion as it also includes the serialized form from getPendingLocalState.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this PR is exposing it only through ODSP's FluidContainer, so it's Beta, but let me know if I missed something. I agree the timing window is tricky. For the current usecase, they are basically serializing a "guest" user, logging in, then pretty immediately loading from that serialized state via localStorage. I would think we could, for now, possibly say "only compatible with current version and tree schema" then improve that compatibility over time, rather than spending a lot of effort right now to meet some arbitrary goal. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,11 @@ export interface IOdspFluidContainer< | |
| * @returns A promise which resolves when the attach is complete, with the string identifier of the container. | ||
| */ | ||
| attach(props?: ContainerAttachProps<OdspContainerAttachProps>): Promise<string>; | ||
|
|
||
| /** | ||
| * Serialize the container to a string representation. This can be saved for later rehydration. | ||
| */ | ||
| serialize(): string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Serializing isn't service specific, so I'd expect to find it on IFluidContainer (even if AzureClient doesn't have a method to rehydrate).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is on IFluidContainer (internal version), but this is a way to expose some functionality of IFluidContainer with |
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple thoughts:
Brainstorming some options:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thank you for the naming context. I'm liking the direction of
serializeDetachedContainer/loadFromSerialized. MaybeserializeDetachedContainer/createFromSerializedContainer?