/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { IFluidLoadable } from "@fluidframework/core-interfaces"; import { type Registry, type DataStoreKind } from "@fluidframework/driver-definitions/internal"; import type { SharedObjectKey, SharedObjectKindAlpha } from "./sharedObject.js"; /** * This file provides the implementation of {@link @fluidframework/driver-definitions#DataStoreKind} * and is therefore a key part of the implementation of the {@link @fluidframework/driver-definitions#ServiceClient} API surface. * * Note that much of the API surface beyond {@link defineDataStore} could be removed/deduplicated * if the unification noted in the TODOs in {@link SharedObjectRegistry} is implemented. */ /** * A {@link @fluidframework/driver-definitions#Registry} of shared object kinds that can be created or loaded within a data store. * @remarks * Supports lazy code loading in a limited way (a single lazy load per registry). * @privateRemarks * TODO: The framework provided SharedObjects should be exposed in a way indistinguishable from custom sub-data stores. * This can be done by unifying the DataStoreKind and SharedObjectKindAlpha types. * For now, this would mean having DataStoreKind extend SharedObjectKindAlpha, since we can allow a data store in all places SharedObjects are allowed, * but do not allow SharedObjects at the root. * Fixing this, and allowing shared objects at the root (maybe use a trivial wrapper data store) could simplify things, allowing data stores and Containers to share some types (like how they create detached contents, have registries, have a root etc). * * Part of this unification could be to relax the output from the factories / registries. Allowing the output to be an arbitrary type, which might be a promise, and might not be one could help. * Removal of the IFluidLoadable requirement, and allowing the returned type to expose handles to itself however it wants (or not at all) might be viable and simplify typing and allow for strongly typed handles at creation time at least). * Maybe when Registry(type) gives a promise, it could instead give a factory which outputs a promise wrapped type? The check that the provided creation key is valid for that factory can be deferred until the promise resolves. * * Idea: creation key can have an interface that subsets the factory / SharedObjectKindAlpha / DataStoreKind so they can be used, or some branded key (string, and/or object with stronger identity what knows the type string) can be used. * Have Key interface contain validation function to check that the factory used (or maybe the value produced from it) is valid for that key. * During load, validation would simply check the factory's type string matches the key's type string. * When using SharedObjectKindAlpha or DataStoreKind, validation can check factory object identity against key. * * Goal: Mostly unify container, data store and shared object abstractions. * Maybe unify a bit with service client since it also has a way to create detached things with an initialized root then attach them. * SharedObjects are just built in leaf data stores. * * @input * @alpha */ export type SharedObjectRegistry = () => Promise>>; /** * Creates a {@link SharedObjectRegistry} from an iterable of {@link SharedObjectKindAlpha}s or async getters for them. * @alpha */ export declare function sharedObjectRegistryFromIterable(entries: Iterable | { type: string; kind: () => Promise>; }>): SharedObjectRegistry; /** * Options which define how to construct a particular {@link @fluidframework/driver-definitions#DataStoreKind}. * @remarks * Use {@link defineDataStore} to create a {@link @fluidframework/driver-definitions#DataStoreKind} from these options. * @input * @alpha */ export interface DataStoreOptions { /** * The type identifier for the data object factory. * @remarks * Persisted identifier which specifies which {@link @fluidframework/driver-definitions#DataStoreKind} to use when loading it. * @privateRemarks * Equivalent to `DataObjectFactoryProps.type`. */ readonly type: string; /** * The registry of shared object kinds (including other data stores) that can be loaded or created within this data store. * * TODO: actually allow this to contain data stores. */ readonly registry: SharedObjectRegistry; /** * Create the initial content of the data store, and return the root shared object. * @privateRemarks * TODO: * This requires the caller to produce a single root shared object (which is keyed by {@link rootSharedObjectId}). * This should be fine for new code, but code migrated from legacy APIs might need more flexibility. * Such use-cases could be accommodated providing a legacy alternative to `defineDataStore` where `instantiateFirstTime` and `view` directly expose access to named root shared objects. * This should be easy to implement, but is currently not included. */ instantiateFirstTime(rootCreator: SharedObjectCreator, context: DataStoreContext): Promise; /** * Construct a view of the data store's root shared object. * * @param root - The root shared object of the data store, created by `instantiateFirstTime` (though possibly created by another client and loaded by this one). * @param context - A {@link DataStoreContext} that can be used to create additional shared objects. */ view(root: TRoot, context: DataStoreContext): Promise; } /** * Creates a {@link @fluidframework/driver-definitions#DataStoreKind} from {@link DataStoreOptions}. * @alpha */ export declare function defineDataStore(options: DataStoreOptions): DataStoreKind; /** * Creates instances of SharedObjectKinds. * @privateRemarks * See IFluidContainer.create. * @sealed * @alpha */ export interface SharedObjectCreator { /** * Create an instance of `kind`, which must be registered in the registry of the surrounding data store. */ createSharedObject(kind: SharedObjectKey): Promise; } /** * Contextual information about a data store which is provided when instantiating or loading it. * @privateRemarks * TODO: this can expose more contextual information about the data store as needed. * @sealed * @alpha */ export interface DataStoreContext extends SharedObjectCreator { } //# sourceMappingURL=dataStoreKind.d.ts.map