@fluidframework/aqueduct 2.33.2 → 2.40.0-336023
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-object-factories/pureDataObjectFactory.d.ts +1 -4
- package/dist/data-object-factories/pureDataObjectFactory.d.ts.map +1 -1
- package/dist/data-object-factories/pureDataObjectFactory.js +26 -12
- package/dist/data-object-factories/pureDataObjectFactory.js.map +1 -1
- package/lib/data-object-factories/pureDataObjectFactory.d.ts +1 -4
- package/lib/data-object-factories/pureDataObjectFactory.d.ts.map +1 -1
- package/lib/data-object-factories/pureDataObjectFactory.js +26 -12
- package/lib/data-object-factories/pureDataObjectFactory.js.map +1 -1
- package/package.json +18 -18
- package/src/data-object-factories/pureDataObjectFactory.ts +43 -43
|
@@ -23,11 +23,8 @@ export declare class PureDataObjectFactory<TObj extends PureDataObject<I>, I ext
|
|
|
23
23
|
* {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory."type"}
|
|
24
24
|
*/
|
|
25
25
|
readonly type: string;
|
|
26
|
-
private readonly ctor;
|
|
27
|
-
private readonly optionalProviders;
|
|
28
|
-
private readonly runtimeClass;
|
|
29
|
-
private readonly sharedObjectRegistry;
|
|
30
26
|
private readonly registry;
|
|
27
|
+
private readonly createProps;
|
|
31
28
|
constructor(
|
|
32
29
|
/**
|
|
33
30
|
* {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory."type"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pureDataObjectFactory.d.ts","sourceRoot":"","sources":["../../src/data-object-factories/pureDataObjectFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAGhG,OAAO,EACN,qBAAqB,EAGrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACX,eAAe,EAEf,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EACX,qBAAqB,EACrB,UAAU,EACV,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,EAC9B,sBAAsB,EACtB,uBAAuB,EACvB,8BAA8B,EAC9B,kCAAkC,EAClC,gCAAgC,EAChC,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAEX,yBAAyB,EAEzB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,KAAK,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"pureDataObjectFactory.d.ts","sourceRoot":"","sources":["../../src/data-object-factories/pureDataObjectFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAGhG,OAAO,EACN,qBAAqB,EAGrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACX,eAAe,EAEf,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EACX,qBAAqB,EACrB,UAAU,EACV,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,EAC9B,sBAAsB,EACtB,uBAAuB,EACvB,8BAA8B,EAC9B,kCAAkC,EAClC,gCAAgC,EAChC,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAEX,yBAAyB,EAEzB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,KAAK,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,MAAM,0BAA0B,CAAC;AAiGlC;;;;;;;;;GASG;AACH,qBAAa,qBAAqB,CACjC,IAAI,SAAS,cAAc,CAAC,CAAC,CAAC,EAC9B,CAAC,SAAS,eAAe,GAAG,eAAe,CAC1C,YAAW,sBAAsB,EAAE,OAAO,CAAC,8BAA8B,CAAC;IAM1E;;OAEG;aACa,IAAI,EAAE,MAAM;IAP7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAC/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+D;;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,MAAM,EAAE,CAAC,EAChC,cAAc,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAgB9B;;;;;;;;;;;;OAYG;IACU,kBAAkB,CAC9B,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,iBAAiB,EAC1B,YAAY,CAAC,EAAE,CAAC,CAAC,cAAc,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;cAkBA,yBAAyB,CACxC,gBAAgB,EAAE,qBAAqB,EACvC,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,EAC/B,YAAY,CAAC,EAAE,CAAC,CAAC,cAAc,CAAC,EAChC,cAAc,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC;cAKA,kBAAkB,CACjC,OAAO,EAAE,8BAA8B,EACvC,YAAY,CAAC,EAAE,CAAC,CAAC,cAAc,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;CAYhB"}
|
|
@@ -12,7 +12,7 @@ const internal_3 = require("@fluidframework/datastore/internal");
|
|
|
12
12
|
* Proxy over PureDataObject
|
|
13
13
|
* Does delayed creation & initialization of PureDataObject
|
|
14
14
|
*/
|
|
15
|
-
async function createDataObject(ctor, context, sharedObjectRegistry, optionalProviders, runtimeClassArg, existing, initProps) {
|
|
15
|
+
async function createDataObject({ ctor, context, sharedObjectRegistry, optionalProviders, runtimeClassArg, existing, initialState: initProps, }) {
|
|
16
16
|
// base
|
|
17
17
|
let runtimeClass = runtimeClassArg;
|
|
18
18
|
// request mixin in
|
|
@@ -76,16 +76,18 @@ class PureDataObjectFactory {
|
|
|
76
76
|
*/
|
|
77
77
|
type, ctor, sharedObjects, optionalProviders, registryEntries, runtimeClass = internal_3.FluidDataStoreRuntime) {
|
|
78
78
|
this.type = type;
|
|
79
|
-
this.ctor = ctor;
|
|
80
|
-
this.optionalProviders = optionalProviders;
|
|
81
|
-
this.runtimeClass = runtimeClass;
|
|
82
79
|
if (this.type === "") {
|
|
83
80
|
throw new Error("undefined type member");
|
|
84
81
|
}
|
|
82
|
+
this.createProps = {
|
|
83
|
+
ctor,
|
|
84
|
+
optionalProviders,
|
|
85
|
+
sharedObjectRegistry: new Map(sharedObjects.map((ext) => [ext.type, ext])),
|
|
86
|
+
runtimeClassArg: runtimeClass,
|
|
87
|
+
};
|
|
85
88
|
if (registryEntries !== undefined) {
|
|
86
89
|
this.registry = new internal_1.FluidDataStoreRegistry(registryEntries);
|
|
87
90
|
}
|
|
88
|
-
this.sharedObjectRegistry = new Map(sharedObjects.map((ext) => [ext.type, ext]));
|
|
89
91
|
}
|
|
90
92
|
/**
|
|
91
93
|
* {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreFactory.IFluidDataStoreFactory}
|
|
@@ -112,7 +114,7 @@ class PureDataObjectFactory {
|
|
|
112
114
|
* {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.instantiateDataStore}
|
|
113
115
|
*/
|
|
114
116
|
async instantiateDataStore(context, existing) {
|
|
115
|
-
const { runtime } = await createDataObject(this.
|
|
117
|
+
const { runtime } = await createDataObject({ ...this.createProps, context, existing });
|
|
116
118
|
return runtime;
|
|
117
119
|
}
|
|
118
120
|
/**
|
|
@@ -172,8 +174,12 @@ class PureDataObjectFactory {
|
|
|
172
174
|
*/
|
|
173
175
|
async createInstanceWithDataStore(containerRuntime, initialState, packagePath, loadingGroupId) {
|
|
174
176
|
const context = containerRuntime.createDetachedDataStore(packagePath ?? [this.type], loadingGroupId);
|
|
175
|
-
const { instance, runtime } = await createDataObject(
|
|
176
|
-
|
|
177
|
+
const { instance, runtime } = await createDataObject({
|
|
178
|
+
...this.createProps,
|
|
179
|
+
context,
|
|
180
|
+
existing: false,
|
|
181
|
+
initialState,
|
|
182
|
+
});
|
|
177
183
|
const dataStore = await context.attachRuntime(this, runtime);
|
|
178
184
|
return [instance, dataStore];
|
|
179
185
|
}
|
|
@@ -192,8 +198,12 @@ class PureDataObjectFactory {
|
|
|
192
198
|
*/
|
|
193
199
|
async createRootInstance(rootDataStoreId, runtime, initialState) {
|
|
194
200
|
const context = runtime.createDetachedDataStore([this.type]);
|
|
195
|
-
const { instance, runtime: dataStoreRuntime } = await createDataObject(
|
|
196
|
-
|
|
201
|
+
const { instance, runtime: dataStoreRuntime } = await createDataObject({
|
|
202
|
+
...this.createProps,
|
|
203
|
+
context,
|
|
204
|
+
existing: false,
|
|
205
|
+
initialState,
|
|
206
|
+
});
|
|
197
207
|
const dataStore = await context.attachRuntime(this, dataStoreRuntime);
|
|
198
208
|
const result = await dataStore.trySetAlias(rootDataStoreId);
|
|
199
209
|
if (result !== "Success") {
|
|
@@ -208,8 +218,12 @@ class PureDataObjectFactory {
|
|
|
208
218
|
return this.createInstanceCore(context, initialState);
|
|
209
219
|
}
|
|
210
220
|
async createInstanceCore(context, initialState) {
|
|
211
|
-
const { instance, runtime } = await createDataObject(
|
|
212
|
-
|
|
221
|
+
const { instance, runtime } = await createDataObject({
|
|
222
|
+
...this.createProps,
|
|
223
|
+
context,
|
|
224
|
+
existing: false,
|
|
225
|
+
initialState,
|
|
226
|
+
});
|
|
213
227
|
await context.attachRuntime(this, runtime);
|
|
214
228
|
return instance;
|
|
215
229
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pureDataObjectFactory.js","sourceRoot":"","sources":["../../src/data-object-factories/pureDataObjectFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yEAAoF;AAGpF,kEAA6D;AAC7D,iEAI4C;AA6B5C;;;GAGG;AACH,KAAK,UAAU,gBAAgB,CAI9B,IAA8C,EAC9C,OAA+B,EAC/B,oBAA2C,EAC3C,iBAAoE,EACpE,eAA6C,EAC7C,QAAiB,EACjB,SAA6B;IAK7B,OAAO;IACP,IAAI,YAAY,GAAG,eAAe,CAAC;IAEnC,mBAAmB;IACnB,YAAY,GAAG,IAAA,8BAAmB,EACjC,KAAK,EAAE,OAAiB,EAAE,UAAiC,EAAE,E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AAgB,CAAC,uBAAuB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QACtF,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACvD,CAAC;IAES,KAAK,CAAC,kBAAkB,CACjC,OAAuC,EACvC,YAAgC;QAEhC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,gBAAgB,CACnD,IAAI,CAAC,IAAI,EACT,OAAO,EACP,IAAI,CAAC,oBAAoB,EACzB,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,YAAY,EACjB,KAAK,EAAE,WAAW;QAClB,YAAY,CACZ,CAAC;QAEF,MAAM,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE3C,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD;AAjPD,sDAiPC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { FluidDataStoreRegistry } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { FluidObject, IRequest } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tFluidDataStoreRuntime,\n\ttype ISharedObjectRegistry,\n\tmixinRequestHandler,\n} from \"@fluidframework/datastore/internal\";\nimport type {\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type {\n\tIContainerRuntimeBase,\n\tIDataStore,\n\tIFluidDataStoreChannel,\n\tIFluidDataStoreContext,\n\tIFluidDataStoreContextDetached,\n\tIFluidDataStoreFactory,\n\tIFluidDataStoreRegistry,\n\tIProvideFluidDataStoreRegistry,\n\tNamedFluidDataStoreRegistryEntries,\n\tNamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type {\n\tAsyncFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n\tIFluidDependencySynthesizer,\n} from \"@fluidframework/synthesize/internal\";\n\nimport type {\n\tDataObjectTypes,\n\tIDataObjectProps,\n\tPureDataObject,\n} from \"../data-objects/index.js\";\n\n/**\n * Proxy over PureDataObject\n * Does delayed creation & initialization of PureDataObject\n */\nasync function createDataObject<\n\tTObj extends PureDataObject,\n\tI extends DataObjectTypes = DataObjectTypes,\n>(\n\tctor: new (props: IDataObjectProps<I>) => TObj,\n\tcontext: IFluidDataStoreContext,\n\tsharedObjectRegistry: ISharedObjectRegistry,\n\toptionalProviders: FluidObjectSymbolProvider<I[\"OptionalProviders\"]>,\n\truntimeClassArg: typeof FluidDataStoreRuntime,\n\texisting: boolean,\n\tinitProps?: I[\"InitialState\"],\n): Promise<{\n\tinstance: TObj;\n\truntime: FluidDataStoreRuntime;\n}> {\n\t// base\n\tlet runtimeClass = runtimeClassArg;\n\n\t// request mixin in\n\truntimeClass = mixinRequestHandler(\n\t\tasync (request: IRequest, runtimeArg: FluidDataStoreRuntime) => {\n\t\t\t// The provideEntryPoint callback below always returns TObj, so this cast is safe\n\t\t\tconst dataObject = (await runtimeArg.entryPoint.get()) as TObj;\n\t\t\tassert(\n\t\t\t\tdataObject.request !== undefined,\n\t\t\t\t0x795 /* Data store runtime entryPoint does not have request */,\n\t\t\t);\n\t\t\treturn dataObject.request(request);\n\t\t},\n\t\truntimeClass,\n\t);\n\n\t// Create a new runtime for our data store, as if via new FluidDataStoreRuntime,\n\t// but using the runtimeClass that's been augmented with mixins\n\t// The runtime is what Fluid uses to create DDS' and route to your data store\n\tconst runtime: FluidDataStoreRuntime = new runtimeClass(\n\t\t// calls new FluidDataStoreRuntime(...)\n\t\tcontext,\n\t\tsharedObjectRegistry,\n\t\texisting,\n\t\tasync (rt: IFluidDataStoreRuntime) => {\n\t\t\tassert(instance !== undefined, 0x46a /* entryPoint is undefined */);\n\t\t\t// Calling finishInitialization here like PureDataObject.getDataObject did, to keep the same behavior,\n\t\t\t// since accessing the runtime's entryPoint is how we want the data object to be retrieved going forward.\n\t\t\t// Without this I ran into issues with the load-existing flow not working correctly.\n\t\t\tawait instance.finishInitialization(true);\n\t\t\treturn instance;\n\t\t} /* provideEntryPoint */,\n\t);\n\n\t// Create object right away.\n\t// This allows object to register various callbacks with runtime before runtime\n\t// becomes globally available. But it's not full initialization - constructor can't\n\t// access DDSes or other services of runtime as objects are not fully initialized.\n\t// In order to use object, we need to go through full initialization by calling finishInitialization().\n\tconst scope: FluidObject<IFluidDependencySynthesizer> = context.scope;\n\tconst providers =\n\t\tscope.IFluidDependencySynthesizer?.synthesize<I[\"OptionalProviders\"]>(\n\t\t\toptionalProviders,\n\t\t\t{},\n\t\t) ??\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t({} as AsyncFluidObjectProvider<never>);\n\n\tconst instance = new ctor({ runtime, context, providers, initProps });\n\n\t// if it's a newly created object, we need to wait for it to finish initialization\n\t// as that results in creation of DDSes, before it gets attached, providing atomic\n\t// guarantee of creation.\n\t// WARNING: we can't do the same (yet) for already existing PureDataObject!\n\t// This will result in deadlock, as it tries to resolve internal handles, but any\n\t// handle resolution goes through root (container runtime), which can't route it back\n\t// to this data store, as it's still not initialized and not known to container runtime yet.\n\t// In the future, we should address it by using relative paths for handles and be able to resolve\n\t// local DDSes while data store is not fully initialized.\n\tif (!existing) {\n\t\tawait instance.finishInitialization(existing);\n\t}\n\n\treturn { instance, runtime };\n}\n\n/**\n * PureDataObjectFactory is a bare-bones IFluidDataStoreFactory for use with PureDataObject.\n * Consumers should typically use DataObjectFactory instead unless creating\n * another base data store factory.\n *\n * @typeParam TObj - DataObject (concrete type)\n * @typeParam I - The input types for the DataObject\n * @legacy\n * @alpha\n */\nexport class PureDataObjectFactory<\n\tTObj extends PureDataObject<I>,\n\tI extends DataObjectTypes = DataObjectTypes,\n> implements IFluidDataStoreFactory, Partial<IProvideFluidDataStoreRegistry>\n{\n\tprivate readonly sharedObjectRegistry: ISharedObjectRegistry;\n\tprivate readonly registry: IFluidDataStoreRegistry | undefined;\n\n\tpublic constructor(\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.\"type\"}\n\t\t */\n\t\tpublic readonly type: string,\n\t\tprivate readonly ctor: new (props: IDataObjectProps<I>) => TObj,\n\t\tsharedObjects: readonly IChannelFactory[],\n\t\tprivate readonly optionalProviders: FluidObjectSymbolProvider<I[\"OptionalProviders\"]>,\n\t\tregistryEntries?: NamedFluidDataStoreRegistryEntries,\n\t\tprivate readonly runtimeClass: typeof FluidDataStoreRuntime = FluidDataStoreRuntime,\n\t) {\n\t\tif (this.type === \"\") {\n\t\t\tthrow new Error(\"undefined type member\");\n\t\t}\n\t\tif (registryEntries !== undefined) {\n\t\t\tthis.registry = new FluidDataStoreRegistry(registryEntries);\n\t\t}\n\t\tthis.sharedObjectRegistry = new Map(sharedObjects.map((ext) => [ext.type, ext]));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreFactory.IFluidDataStoreFactory}\n\t */\n\tpublic get IFluidDataStoreFactory(): this {\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreRegistry.IFluidDataStoreRegistry}\n\t */\n\tpublic get IFluidDataStoreRegistry(): IFluidDataStoreRegistry | undefined {\n\t\treturn this.registry;\n\t}\n\n\t/**\n\t * Convenience helper to get the data store's/factory's data store registry entry.\n\t * The return type hides the factory's generics, easing grouping of registry\n\t * entries that differ only in this way into the same array.\n\t * @returns The NamedFluidDataStoreRegistryEntry\n\t */\n\tpublic get registryEntry(): NamedFluidDataStoreRegistryEntry {\n\t\treturn [this.type, Promise.resolve(this)];\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.instantiateDataStore}\n\t */\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<IFluidDataStoreChannel> {\n\t\tconst { runtime } = await createDataObject(\n\t\t\tthis.ctor,\n\t\t\tcontext,\n\t\t\tthis.sharedObjectRegistry,\n\t\t\tthis.optionalProviders,\n\t\t\tthis.runtimeClass,\n\t\t\texisting,\n\t\t);\n\n\t\treturn runtime;\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses parent context's registry to build package path to this factory.\n\t * In other words, registry of context passed in has to contain this factory, with the name that matches\n\t * this factory's type.\n\t * It is intended to be used by data store objects that create sub-objects.\n\t * @param context - The context being used to create the runtime\n\t * (the created object will have its own new context created as well)\n\t * @param initialState - The initial state to provide to the created data store.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createChildInstance(\n\t\tparentContext: IFluidDataStoreContext,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(\n\t\t\tparentContext.containerRuntime,\n\t\t\t[...parentContext.packagePath, this.type],\n\t\t\tinitialState,\n\t\t\tloadingGroupId,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses peer context's registry and its package path to identify this factory.\n\t * In other words, registry of context passed in has to have this factory.\n\t * Intended to be used by data store objects that need to create peers (similar) instances of existing objects.\n\t * @param context - The component context being used to create the object\n\t * (the created object will have its own new context created as well)\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createPeerInstance(\n\t\tpeerContext: IFluidDataStoreContext,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string, // DO NOT USE, this is an experimental feature\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(\n\t\t\tpeerContext.containerRuntime,\n\t\t\tpeerContext.packagePath,\n\t\t\tinitialState,\n\t\t\tloadingGroupId,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses container's registry to find this factory.\n\t * It's expected that only container owners would use this functionality, as only such developers\n\t * have knowledge of entries in container registry.\n\t * The name in this registry for such record should match type of this factory.\n\t * @param runtime - container runtime. It's registry is used to create an object.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createInstance(\n\t\truntime: IContainerRuntimeBase,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(runtime, [this.type], initialState, loadingGroupId);\n\t}\n\n\t/**\n\t * Creates a new instance of the object with a datastore which exposes the aliasing api.\n\t * @param runtime - container runtime. It is the runtime that will be used to create the object. It will produce\n\t * the underlying infrastructure to get the data object to operate.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param packagePath - The path to the data store factory to use to create the data object.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an array containing the object created by this factory and an IDataStore object that enables users to\n\t * alias the data object.\n\t * The data object is attached only when it is attached to the handle graph that connects to an aliased object or\n\t * when the data object is aliased.\n\t */\n\tpublic async createInstanceWithDataStore(\n\t\tcontainerRuntime: IContainerRuntimeBase,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tpackagePath?: Readonly<string[]>,\n\t\tloadingGroupId?: string,\n\t): Promise<[TObj, IDataStore]> {\n\t\tconst context = containerRuntime.createDetachedDataStore(\n\t\t\tpackagePath ?? [this.type],\n\t\t\tloadingGroupId,\n\t\t);\n\t\tconst { instance, runtime } = await createDataObject(\n\t\t\tthis.ctor,\n\t\t\tcontext,\n\t\t\tthis.sharedObjectRegistry,\n\t\t\tthis.optionalProviders,\n\t\t\tthis.runtimeClass,\n\t\t\tfalse, // existing\n\t\t\tinitialState,\n\t\t);\n\t\tconst dataStore = await context.attachRuntime(this, runtime);\n\n\t\treturn [instance, dataStore];\n\t}\n\n\t/**\n\t * Creates a new root instance of the object. Uses container's registry to find this factory.\n\t * It's expected that only container owners would use this functionality, as only such developers\n\t * have knowledge of entries in container registry.\n\t * The name in this registry for such record should match type of this factory.\n\t * @param runtime - container runtime. It's registry is used to create an object.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t *\n\t * @deprecated - the issue is that it does not allow the customer to decide the conflict resolution policy when an\n\t * aliasing conflict occurs. Use {@link PureDataObjectFactory.createInstanceWithDataStore} instead.\n\t */\n\tpublic async createRootInstance(\n\t\trootDataStoreId: string,\n\t\truntime: IContainerRuntime,\n\t\tinitialState?: I[\"InitialState\"],\n\t): Promise<TObj> {\n\t\tconst context = runtime.createDetachedDataStore([this.type]);\n\t\tconst { instance, runtime: dataStoreRuntime } = await createDataObject(\n\t\t\tthis.ctor,\n\t\t\tcontext,\n\t\t\tthis.sharedObjectRegistry,\n\t\t\tthis.optionalProviders,\n\t\t\tthis.runtimeClass,\n\t\t\tfalse, // existing\n\t\t\tinitialState,\n\t\t);\n\t\tconst dataStore = await context.attachRuntime(this, dataStoreRuntime);\n\t\tconst result = await dataStore.trySetAlias(rootDataStoreId);\n\t\tif (result !== \"Success\") {\n\t\t\tconst handle = await runtime.getAliasedDataStoreEntryPoint(rootDataStoreId);\n\t\t\tassert(handle !== undefined, 0x8e1 /* Should have retrieved aliased handle */);\n\t\t\treturn (await handle.get()) as TObj;\n\t\t}\n\t\treturn instance;\n\t}\n\n\tprotected async createNonRootInstanceCore(\n\t\tcontainerRuntime: IContainerRuntimeBase,\n\t\tpackagePath: Readonly<string[]>,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\tconst context = containerRuntime.createDetachedDataStore(packagePath, loadingGroupId);\n\t\treturn this.createInstanceCore(context, initialState);\n\t}\n\n\tprotected async createInstanceCore(\n\t\tcontext: IFluidDataStoreContextDetached,\n\t\tinitialState?: I[\"InitialState\"],\n\t): Promise<TObj> {\n\t\tconst { instance, runtime } = await createDataObject(\n\t\t\tthis.ctor,\n\t\t\tcontext,\n\t\t\tthis.sharedObjectRegistry,\n\t\t\tthis.optionalProviders,\n\t\t\tthis.runtimeClass,\n\t\t\tfalse, // existing\n\t\t\tinitialState,\n\t\t);\n\n\t\tawait context.attachRuntime(this, runtime);\n\n\t\treturn instance;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pureDataObjectFactory.js","sourceRoot":"","sources":["../../src/data-object-factories/pureDataObjectFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yEAAoF;AAGpF,kEAA6D;AAC7D,iEAI4C;AAsC5C;;;GAGG;AACH,KAAK,UAAU,gBAAgB,CAG7B,EACD,IAAI,EACJ,OAAO,EACP,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,QAAQ,EACR,YAAY,EAAE,SAAS,GACS;IAIhC,OAAO;IACP,IAAI,YAAY,GAAG,eAAe,CAAC;IAEnC,mBAAmB;IACnB,YAAY,GAAG,IAAA,8BAAmB,EACjC,KAAK,EAAE,OAAiB,EAAE,UAAiC,EAAE,EAAE;QAC9D,iFAAiF;QACjF,MAAM,UAAU,GAAG,CAAC,MA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AAgB,CAAC;YACpD,GAAG,IAAI,CAAC,WAAW;YACnB,OAAO;YACP,QAAQ,EAAE,KAAK;YACf,YAAY;SACZ,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE3C,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD;AAxOD,sDAwOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { FluidDataStoreRegistry } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { FluidObject, IRequest } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tFluidDataStoreRuntime,\n\ttype ISharedObjectRegistry,\n\tmixinRequestHandler,\n} from \"@fluidframework/datastore/internal\";\nimport type {\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type {\n\tIContainerRuntimeBase,\n\tIDataStore,\n\tIFluidDataStoreChannel,\n\tIFluidDataStoreContext,\n\tIFluidDataStoreContextDetached,\n\tIFluidDataStoreFactory,\n\tIFluidDataStoreRegistry,\n\tIProvideFluidDataStoreRegistry,\n\tNamedFluidDataStoreRegistryEntries,\n\tNamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type {\n\tAsyncFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n\tIFluidDependencySynthesizer,\n} from \"@fluidframework/synthesize/internal\";\n\nimport type {\n\tDataObjectTypes,\n\tIDataObjectProps,\n\tPureDataObject,\n} from \"../data-objects/index.js\";\n\ninterface CreateDataObjectProps<TObj extends PureDataObject, I extends DataObjectTypes> {\n\tctor: new (props: IDataObjectProps<I>) => TObj;\n\tcontext: IFluidDataStoreContext;\n\tsharedObjectRegistry: ISharedObjectRegistry;\n\toptionalProviders: FluidObjectSymbolProvider<I[\"OptionalProviders\"]>;\n\truntimeClassArg: typeof FluidDataStoreRuntime;\n\texisting: boolean;\n\tinitialState?: I[\"InitialState\"];\n}\n/**\n * Proxy over PureDataObject\n * Does delayed creation & initialization of PureDataObject\n */\nasync function createDataObject<\n\tTObj extends PureDataObject,\n\tI extends DataObjectTypes = DataObjectTypes,\n>({\n\tctor,\n\tcontext,\n\tsharedObjectRegistry,\n\toptionalProviders,\n\truntimeClassArg,\n\texisting,\n\tinitialState: initProps,\n}: CreateDataObjectProps<TObj, I>): Promise<{\n\tinstance: TObj;\n\truntime: FluidDataStoreRuntime;\n}> {\n\t// base\n\tlet runtimeClass = runtimeClassArg;\n\n\t// request mixin in\n\truntimeClass = mixinRequestHandler(\n\t\tasync (request: IRequest, runtimeArg: FluidDataStoreRuntime) => {\n\t\t\t// The provideEntryPoint callback below always returns TObj, so this cast is safe\n\t\t\tconst dataObject = (await runtimeArg.entryPoint.get()) as TObj;\n\t\t\tassert(\n\t\t\t\tdataObject.request !== undefined,\n\t\t\t\t0x795 /* Data store runtime entryPoint does not have request */,\n\t\t\t);\n\t\t\treturn dataObject.request(request);\n\t\t},\n\t\truntimeClass,\n\t);\n\n\t// Create a new runtime for our data store, as if via new FluidDataStoreRuntime,\n\t// but using the runtimeClass that's been augmented with mixins\n\t// The runtime is what Fluid uses to create DDS' and route to your data store\n\tconst runtime: FluidDataStoreRuntime = new runtimeClass(\n\t\t// calls new FluidDataStoreRuntime(...)\n\t\tcontext,\n\t\tsharedObjectRegistry,\n\t\texisting,\n\t\tasync (rt: IFluidDataStoreRuntime) => {\n\t\t\tassert(instance !== undefined, 0x46a /* entryPoint is undefined */);\n\t\t\t// Calling finishInitialization here like PureDataObject.getDataObject did, to keep the same behavior,\n\t\t\t// since accessing the runtime's entryPoint is how we want the data object to be retrieved going forward.\n\t\t\t// Without this I ran into issues with the load-existing flow not working correctly.\n\t\t\tawait instance.finishInitialization(true);\n\t\t\treturn instance;\n\t\t} /* provideEntryPoint */,\n\t);\n\n\t// Create object right away.\n\t// This allows object to register various callbacks with runtime before runtime\n\t// becomes globally available. But it's not full initialization - constructor can't\n\t// access DDSes or other services of runtime as objects are not fully initialized.\n\t// In order to use object, we need to go through full initialization by calling finishInitialization().\n\tconst scope: FluidObject<IFluidDependencySynthesizer> = context.scope;\n\tconst providers =\n\t\tscope.IFluidDependencySynthesizer?.synthesize<I[\"OptionalProviders\"]>(\n\t\t\toptionalProviders,\n\t\t\t{},\n\t\t) ??\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t({} as AsyncFluidObjectProvider<never>);\n\n\tconst instance = new ctor({ runtime, context, providers, initProps });\n\n\t// if it's a newly created object, we need to wait for it to finish initialization\n\t// as that results in creation of DDSes, before it gets attached, providing atomic\n\t// guarantee of creation.\n\t// WARNING: we can't do the same (yet) for already existing PureDataObject!\n\t// This will result in deadlock, as it tries to resolve internal handles, but any\n\t// handle resolution goes through root (container runtime), which can't route it back\n\t// to this data store, as it's still not initialized and not known to container runtime yet.\n\t// In the future, we should address it by using relative paths for handles and be able to resolve\n\t// local DDSes while data store is not fully initialized.\n\tif (!existing) {\n\t\tawait instance.finishInitialization(existing);\n\t}\n\n\treturn { instance, runtime };\n}\n\n/**\n * PureDataObjectFactory is a bare-bones IFluidDataStoreFactory for use with PureDataObject.\n * Consumers should typically use DataObjectFactory instead unless creating\n * another base data store factory.\n *\n * @typeParam TObj - DataObject (concrete type)\n * @typeParam I - The input types for the DataObject\n * @legacy\n * @alpha\n */\nexport class PureDataObjectFactory<\n\tTObj extends PureDataObject<I>,\n\tI extends DataObjectTypes = DataObjectTypes,\n> implements IFluidDataStoreFactory, Partial<IProvideFluidDataStoreRegistry>\n{\n\tprivate readonly registry: IFluidDataStoreRegistry | undefined;\n\tprivate readonly createProps: Omit<CreateDataObjectProps<TObj, I>, \"existing\" | \"context\">;\n\n\tpublic constructor(\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.\"type\"}\n\t\t */\n\t\tpublic readonly type: string,\n\t\tctor: new (props: IDataObjectProps<I>) => TObj,\n\t\tsharedObjects: readonly IChannelFactory[],\n\t\toptionalProviders: FluidObjectSymbolProvider<I[\"OptionalProviders\"]>,\n\t\tregistryEntries?: NamedFluidDataStoreRegistryEntries,\n\t\truntimeClass: typeof FluidDataStoreRuntime = FluidDataStoreRuntime,\n\t) {\n\t\tif (this.type === \"\") {\n\t\t\tthrow new Error(\"undefined type member\");\n\t\t}\n\n\t\tthis.createProps = {\n\t\t\tctor,\n\t\t\toptionalProviders,\n\t\t\tsharedObjectRegistry: new Map(sharedObjects.map((ext) => [ext.type, ext])),\n\t\t\truntimeClassArg: runtimeClass,\n\t\t};\n\n\t\tif (registryEntries !== undefined) {\n\t\t\tthis.registry = new FluidDataStoreRegistry(registryEntries);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreFactory.IFluidDataStoreFactory}\n\t */\n\tpublic get IFluidDataStoreFactory(): this {\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreRegistry.IFluidDataStoreRegistry}\n\t */\n\tpublic get IFluidDataStoreRegistry(): IFluidDataStoreRegistry | undefined {\n\t\treturn this.registry;\n\t}\n\n\t/**\n\t * Convenience helper to get the data store's/factory's data store registry entry.\n\t * The return type hides the factory's generics, easing grouping of registry\n\t * entries that differ only in this way into the same array.\n\t * @returns The NamedFluidDataStoreRegistryEntry\n\t */\n\tpublic get registryEntry(): NamedFluidDataStoreRegistryEntry {\n\t\treturn [this.type, Promise.resolve(this)];\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.instantiateDataStore}\n\t */\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<IFluidDataStoreChannel> {\n\t\tconst { runtime } = await createDataObject({ ...this.createProps, context, existing });\n\n\t\treturn runtime;\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses parent context's registry to build package path to this factory.\n\t * In other words, registry of context passed in has to contain this factory, with the name that matches\n\t * this factory's type.\n\t * It is intended to be used by data store objects that create sub-objects.\n\t * @param context - The context being used to create the runtime\n\t * (the created object will have its own new context created as well)\n\t * @param initialState - The initial state to provide to the created data store.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createChildInstance(\n\t\tparentContext: IFluidDataStoreContext,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(\n\t\t\tparentContext.containerRuntime,\n\t\t\t[...parentContext.packagePath, this.type],\n\t\t\tinitialState,\n\t\t\tloadingGroupId,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses peer context's registry and its package path to identify this factory.\n\t * In other words, registry of context passed in has to have this factory.\n\t * Intended to be used by data store objects that need to create peers (similar) instances of existing objects.\n\t * @param context - The component context being used to create the object\n\t * (the created object will have its own new context created as well)\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createPeerInstance(\n\t\tpeerContext: IFluidDataStoreContext,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string, // DO NOT USE, this is an experimental feature\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(\n\t\t\tpeerContext.containerRuntime,\n\t\t\tpeerContext.packagePath,\n\t\t\tinitialState,\n\t\t\tloadingGroupId,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses container's registry to find this factory.\n\t * It's expected that only container owners would use this functionality, as only such developers\n\t * have knowledge of entries in container registry.\n\t * The name in this registry for such record should match type of this factory.\n\t * @param runtime - container runtime. It's registry is used to create an object.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createInstance(\n\t\truntime: IContainerRuntimeBase,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(runtime, [this.type], initialState, loadingGroupId);\n\t}\n\n\t/**\n\t * Creates a new instance of the object with a datastore which exposes the aliasing api.\n\t * @param runtime - container runtime. It is the runtime that will be used to create the object. It will produce\n\t * the underlying infrastructure to get the data object to operate.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param packagePath - The path to the data store factory to use to create the data object.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an array containing the object created by this factory and an IDataStore object that enables users to\n\t * alias the data object.\n\t * The data object is attached only when it is attached to the handle graph that connects to an aliased object or\n\t * when the data object is aliased.\n\t */\n\tpublic async createInstanceWithDataStore(\n\t\tcontainerRuntime: IContainerRuntimeBase,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tpackagePath?: Readonly<string[]>,\n\t\tloadingGroupId?: string,\n\t): Promise<[TObj, IDataStore]> {\n\t\tconst context = containerRuntime.createDetachedDataStore(\n\t\t\tpackagePath ?? [this.type],\n\t\t\tloadingGroupId,\n\t\t);\n\t\tconst { instance, runtime } = await createDataObject({\n\t\t\t...this.createProps,\n\t\t\tcontext,\n\t\t\texisting: false,\n\t\t\tinitialState,\n\t\t});\n\t\tconst dataStore = await context.attachRuntime(this, runtime);\n\n\t\treturn [instance, dataStore];\n\t}\n\n\t/**\n\t * Creates a new root instance of the object. Uses container's registry to find this factory.\n\t * It's expected that only container owners would use this functionality, as only such developers\n\t * have knowledge of entries in container registry.\n\t * The name in this registry for such record should match type of this factory.\n\t * @param runtime - container runtime. It's registry is used to create an object.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t *\n\t * @deprecated - the issue is that it does not allow the customer to decide the conflict resolution policy when an\n\t * aliasing conflict occurs. Use {@link PureDataObjectFactory.createInstanceWithDataStore} instead.\n\t */\n\tpublic async createRootInstance(\n\t\trootDataStoreId: string,\n\t\truntime: IContainerRuntime,\n\t\tinitialState?: I[\"InitialState\"],\n\t): Promise<TObj> {\n\t\tconst context = runtime.createDetachedDataStore([this.type]);\n\t\tconst { instance, runtime: dataStoreRuntime } = await createDataObject({\n\t\t\t...this.createProps,\n\t\t\tcontext,\n\t\t\texisting: false,\n\t\t\tinitialState,\n\t\t});\n\t\tconst dataStore = await context.attachRuntime(this, dataStoreRuntime);\n\t\tconst result = await dataStore.trySetAlias(rootDataStoreId);\n\t\tif (result !== \"Success\") {\n\t\t\tconst handle = await runtime.getAliasedDataStoreEntryPoint(rootDataStoreId);\n\t\t\tassert(handle !== undefined, 0x8e1 /* Should have retrieved aliased handle */);\n\t\t\treturn (await handle.get()) as TObj;\n\t\t}\n\t\treturn instance;\n\t}\n\n\tprotected async createNonRootInstanceCore(\n\t\tcontainerRuntime: IContainerRuntimeBase,\n\t\tpackagePath: Readonly<string[]>,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\tconst context = containerRuntime.createDetachedDataStore(packagePath, loadingGroupId);\n\t\treturn this.createInstanceCore(context, initialState);\n\t}\n\n\tprotected async createInstanceCore(\n\t\tcontext: IFluidDataStoreContextDetached,\n\t\tinitialState?: I[\"InitialState\"],\n\t): Promise<TObj> {\n\t\tconst { instance, runtime } = await createDataObject({\n\t\t\t...this.createProps,\n\t\t\tcontext,\n\t\t\texisting: false,\n\t\t\tinitialState,\n\t\t});\n\n\t\tawait context.attachRuntime(this, runtime);\n\n\t\treturn instance;\n\t}\n}\n"]}
|
|
@@ -23,11 +23,8 @@ export declare class PureDataObjectFactory<TObj extends PureDataObject<I>, I ext
|
|
|
23
23
|
* {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory."type"}
|
|
24
24
|
*/
|
|
25
25
|
readonly type: string;
|
|
26
|
-
private readonly ctor;
|
|
27
|
-
private readonly optionalProviders;
|
|
28
|
-
private readonly runtimeClass;
|
|
29
|
-
private readonly sharedObjectRegistry;
|
|
30
26
|
private readonly registry;
|
|
27
|
+
private readonly createProps;
|
|
31
28
|
constructor(
|
|
32
29
|
/**
|
|
33
30
|
* {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory."type"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pureDataObjectFactory.d.ts","sourceRoot":"","sources":["../../src/data-object-factories/pureDataObjectFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAGhG,OAAO,EACN,qBAAqB,EAGrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACX,eAAe,EAEf,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EACX,qBAAqB,EACrB,UAAU,EACV,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,EAC9B,sBAAsB,EACtB,uBAAuB,EACvB,8BAA8B,EAC9B,kCAAkC,EAClC,gCAAgC,EAChC,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAEX,yBAAyB,EAEzB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,KAAK,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"pureDataObjectFactory.d.ts","sourceRoot":"","sources":["../../src/data-object-factories/pureDataObjectFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAGhG,OAAO,EACN,qBAAqB,EAGrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACX,eAAe,EAEf,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EACX,qBAAqB,EACrB,UAAU,EACV,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,EAC9B,sBAAsB,EACtB,uBAAuB,EACvB,8BAA8B,EAC9B,kCAAkC,EAClC,gCAAgC,EAChC,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAEX,yBAAyB,EAEzB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,KAAK,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,MAAM,0BAA0B,CAAC;AAiGlC;;;;;;;;;GASG;AACH,qBAAa,qBAAqB,CACjC,IAAI,SAAS,cAAc,CAAC,CAAC,CAAC,EAC9B,CAAC,SAAS,eAAe,GAAG,eAAe,CAC1C,YAAW,sBAAsB,EAAE,OAAO,CAAC,8BAA8B,CAAC;IAM1E;;OAEG;aACa,IAAI,EAAE,MAAM;IAP7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAC/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+D;;IAG1F;;OAEG;IACa,IAAI,EAAE,MAAM,EAC5B,IAAI,EAAE,KAAK,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,EAC9C,aAAa,EAAE,SAAS,eAAe,EAAE,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,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,iBAAiB,EAC1B,YAAY,CAAC,EAAE,CAAC,CAAC,cAAc,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;cAkBA,yBAAyB,CACxC,gBAAgB,EAAE,qBAAqB,EACvC,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,EAC/B,YAAY,CAAC,EAAE,CAAC,CAAC,cAAc,CAAC,EAChC,cAAc,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC;cAKA,kBAAkB,CACjC,OAAO,EAAE,8BAA8B,EACvC,YAAY,CAAC,EAAE,CAAC,CAAC,cAAc,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;CAYhB"}
|
|
@@ -9,7 +9,7 @@ import { FluidDataStoreRuntime, mixinRequestHandler, } from "@fluidframework/dat
|
|
|
9
9
|
* Proxy over PureDataObject
|
|
10
10
|
* Does delayed creation & initialization of PureDataObject
|
|
11
11
|
*/
|
|
12
|
-
async function createDataObject(ctor, context, sharedObjectRegistry, optionalProviders, runtimeClassArg, existing, initProps) {
|
|
12
|
+
async function createDataObject({ ctor, context, sharedObjectRegistry, optionalProviders, runtimeClassArg, existing, initialState: initProps, }) {
|
|
13
13
|
// base
|
|
14
14
|
let runtimeClass = runtimeClassArg;
|
|
15
15
|
// request mixin in
|
|
@@ -73,16 +73,18 @@ export class PureDataObjectFactory {
|
|
|
73
73
|
*/
|
|
74
74
|
type, ctor, sharedObjects, optionalProviders, registryEntries, runtimeClass = FluidDataStoreRuntime) {
|
|
75
75
|
this.type = type;
|
|
76
|
-
this.ctor = ctor;
|
|
77
|
-
this.optionalProviders = optionalProviders;
|
|
78
|
-
this.runtimeClass = runtimeClass;
|
|
79
76
|
if (this.type === "") {
|
|
80
77
|
throw new Error("undefined type member");
|
|
81
78
|
}
|
|
79
|
+
this.createProps = {
|
|
80
|
+
ctor,
|
|
81
|
+
optionalProviders,
|
|
82
|
+
sharedObjectRegistry: new Map(sharedObjects.map((ext) => [ext.type, ext])),
|
|
83
|
+
runtimeClassArg: runtimeClass,
|
|
84
|
+
};
|
|
82
85
|
if (registryEntries !== undefined) {
|
|
83
86
|
this.registry = new FluidDataStoreRegistry(registryEntries);
|
|
84
87
|
}
|
|
85
|
-
this.sharedObjectRegistry = new Map(sharedObjects.map((ext) => [ext.type, ext]));
|
|
86
88
|
}
|
|
87
89
|
/**
|
|
88
90
|
* {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreFactory.IFluidDataStoreFactory}
|
|
@@ -109,7 +111,7 @@ export class PureDataObjectFactory {
|
|
|
109
111
|
* {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.instantiateDataStore}
|
|
110
112
|
*/
|
|
111
113
|
async instantiateDataStore(context, existing) {
|
|
112
|
-
const { runtime } = await createDataObject(this.
|
|
114
|
+
const { runtime } = await createDataObject({ ...this.createProps, context, existing });
|
|
113
115
|
return runtime;
|
|
114
116
|
}
|
|
115
117
|
/**
|
|
@@ -169,8 +171,12 @@ export class PureDataObjectFactory {
|
|
|
169
171
|
*/
|
|
170
172
|
async createInstanceWithDataStore(containerRuntime, initialState, packagePath, loadingGroupId) {
|
|
171
173
|
const context = containerRuntime.createDetachedDataStore(packagePath ?? [this.type], loadingGroupId);
|
|
172
|
-
const { instance, runtime } = await createDataObject(
|
|
173
|
-
|
|
174
|
+
const { instance, runtime } = await createDataObject({
|
|
175
|
+
...this.createProps,
|
|
176
|
+
context,
|
|
177
|
+
existing: false,
|
|
178
|
+
initialState,
|
|
179
|
+
});
|
|
174
180
|
const dataStore = await context.attachRuntime(this, runtime);
|
|
175
181
|
return [instance, dataStore];
|
|
176
182
|
}
|
|
@@ -189,8 +195,12 @@ export class PureDataObjectFactory {
|
|
|
189
195
|
*/
|
|
190
196
|
async createRootInstance(rootDataStoreId, runtime, initialState) {
|
|
191
197
|
const context = runtime.createDetachedDataStore([this.type]);
|
|
192
|
-
const { instance, runtime: dataStoreRuntime } = await createDataObject(
|
|
193
|
-
|
|
198
|
+
const { instance, runtime: dataStoreRuntime } = await createDataObject({
|
|
199
|
+
...this.createProps,
|
|
200
|
+
context,
|
|
201
|
+
existing: false,
|
|
202
|
+
initialState,
|
|
203
|
+
});
|
|
194
204
|
const dataStore = await context.attachRuntime(this, dataStoreRuntime);
|
|
195
205
|
const result = await dataStore.trySetAlias(rootDataStoreId);
|
|
196
206
|
if (result !== "Success") {
|
|
@@ -205,8 +215,12 @@ export class PureDataObjectFactory {
|
|
|
205
215
|
return this.createInstanceCore(context, initialState);
|
|
206
216
|
}
|
|
207
217
|
async createInstanceCore(context, initialState) {
|
|
208
|
-
const { instance, runtime } = await createDataObject(
|
|
209
|
-
|
|
218
|
+
const { instance, runtime } = await createDataObject({
|
|
219
|
+
...this.createProps,
|
|
220
|
+
context,
|
|
221
|
+
existing: false,
|
|
222
|
+
initialState,
|
|
223
|
+
});
|
|
210
224
|
await context.attachRuntime(this, runtime);
|
|
211
225
|
return instance;
|
|
212
226
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pureDataObjectFactory.js","sourceRoot":"","sources":["../../src/data-object-factories/pureDataObjectFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAGpF,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EACN,qBAAqB,EAErB,mBAAmB,GACnB,MAAM,oCAAoC,CAAC;AA6B5C;;;GAGG;AACH,KAAK,UAAU,gBAAgB,CAI9B,IAA8C,EAC9C,OAA+B,EAC/B,oBAA2C,EAC3C,iBAAoE,EACpE,eAA6C,EAC7C,QAAiB,EACjB,SAA6B;IAK7B,OAAO;IACP,IAAI,YAAY,GAAG,eAAe,CAAC;IAEnC,mBAAmB;IACnB,YAAY,GAAG,mBAAmB,CACjC,KAAK,EAAE,OAAiB,EAAE,UAAiC,EAAE,EAAE;QAC9D,iFAAiF;Q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,cAAc,CAAC,CAAC;QACtF,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACvD,CAAC;IAES,KAAK,CAAC,kBAAkB,CACjC,OAAuC,EACvC,YAAgC;QAEhC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,gBAAgB,CACnD,IAAI,CAAC,IAAI,EACT,OAAO,EACP,IAAI,CAAC,oBAAoB,EACzB,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,YAAY,EACjB,KAAK,EAAE,WAAW;QAClB,YAAY,CACZ,CAAC;QAEF,MAAM,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE3C,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { FluidDataStoreRegistry } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { FluidObject, IRequest } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tFluidDataStoreRuntime,\n\ttype ISharedObjectRegistry,\n\tmixinRequestHandler,\n} from \"@fluidframework/datastore/internal\";\nimport type {\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type {\n\tIContainerRuntimeBase,\n\tIDataStore,\n\tIFluidDataStoreChannel,\n\tIFluidDataStoreContext,\n\tIFluidDataStoreContextDetached,\n\tIFluidDataStoreFactory,\n\tIFluidDataStoreRegistry,\n\tIProvideFluidDataStoreRegistry,\n\tNamedFluidDataStoreRegistryEntries,\n\tNamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type {\n\tAsyncFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n\tIFluidDependencySynthesizer,\n} from \"@fluidframework/synthesize/internal\";\n\nimport type {\n\tDataObjectTypes,\n\tIDataObjectProps,\n\tPureDataObject,\n} from \"../data-objects/index.js\";\n\n/**\n * Proxy over PureDataObject\n * Does delayed creation & initialization of PureDataObject\n */\nasync function createDataObject<\n\tTObj extends PureDataObject,\n\tI extends DataObjectTypes = DataObjectTypes,\n>(\n\tctor: new (props: IDataObjectProps<I>) => TObj,\n\tcontext: IFluidDataStoreContext,\n\tsharedObjectRegistry: ISharedObjectRegistry,\n\toptionalProviders: FluidObjectSymbolProvider<I[\"OptionalProviders\"]>,\n\truntimeClassArg: typeof FluidDataStoreRuntime,\n\texisting: boolean,\n\tinitProps?: I[\"InitialState\"],\n): Promise<{\n\tinstance: TObj;\n\truntime: FluidDataStoreRuntime;\n}> {\n\t// base\n\tlet runtimeClass = runtimeClassArg;\n\n\t// request mixin in\n\truntimeClass = mixinRequestHandler(\n\t\tasync (request: IRequest, runtimeArg: FluidDataStoreRuntime) => {\n\t\t\t// The provideEntryPoint callback below always returns TObj, so this cast is safe\n\t\t\tconst dataObject = (await runtimeArg.entryPoint.get()) as TObj;\n\t\t\tassert(\n\t\t\t\tdataObject.request !== undefined,\n\t\t\t\t0x795 /* Data store runtime entryPoint does not have request */,\n\t\t\t);\n\t\t\treturn dataObject.request(request);\n\t\t},\n\t\truntimeClass,\n\t);\n\n\t// Create a new runtime for our data store, as if via new FluidDataStoreRuntime,\n\t// but using the runtimeClass that's been augmented with mixins\n\t// The runtime is what Fluid uses to create DDS' and route to your data store\n\tconst runtime: FluidDataStoreRuntime = new runtimeClass(\n\t\t// calls new FluidDataStoreRuntime(...)\n\t\tcontext,\n\t\tsharedObjectRegistry,\n\t\texisting,\n\t\tasync (rt: IFluidDataStoreRuntime) => {\n\t\t\tassert(instance !== undefined, 0x46a /* entryPoint is undefined */);\n\t\t\t// Calling finishInitialization here like PureDataObject.getDataObject did, to keep the same behavior,\n\t\t\t// since accessing the runtime's entryPoint is how we want the data object to be retrieved going forward.\n\t\t\t// Without this I ran into issues with the load-existing flow not working correctly.\n\t\t\tawait instance.finishInitialization(true);\n\t\t\treturn instance;\n\t\t} /* provideEntryPoint */,\n\t);\n\n\t// Create object right away.\n\t// This allows object to register various callbacks with runtime before runtime\n\t// becomes globally available. But it's not full initialization - constructor can't\n\t// access DDSes or other services of runtime as objects are not fully initialized.\n\t// In order to use object, we need to go through full initialization by calling finishInitialization().\n\tconst scope: FluidObject<IFluidDependencySynthesizer> = context.scope;\n\tconst providers =\n\t\tscope.IFluidDependencySynthesizer?.synthesize<I[\"OptionalProviders\"]>(\n\t\t\toptionalProviders,\n\t\t\t{},\n\t\t) ??\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t({} as AsyncFluidObjectProvider<never>);\n\n\tconst instance = new ctor({ runtime, context, providers, initProps });\n\n\t// if it's a newly created object, we need to wait for it to finish initialization\n\t// as that results in creation of DDSes, before it gets attached, providing atomic\n\t// guarantee of creation.\n\t// WARNING: we can't do the same (yet) for already existing PureDataObject!\n\t// This will result in deadlock, as it tries to resolve internal handles, but any\n\t// handle resolution goes through root (container runtime), which can't route it back\n\t// to this data store, as it's still not initialized and not known to container runtime yet.\n\t// In the future, we should address it by using relative paths for handles and be able to resolve\n\t// local DDSes while data store is not fully initialized.\n\tif (!existing) {\n\t\tawait instance.finishInitialization(existing);\n\t}\n\n\treturn { instance, runtime };\n}\n\n/**\n * PureDataObjectFactory is a bare-bones IFluidDataStoreFactory for use with PureDataObject.\n * Consumers should typically use DataObjectFactory instead unless creating\n * another base data store factory.\n *\n * @typeParam TObj - DataObject (concrete type)\n * @typeParam I - The input types for the DataObject\n * @legacy\n * @alpha\n */\nexport class PureDataObjectFactory<\n\tTObj extends PureDataObject<I>,\n\tI extends DataObjectTypes = DataObjectTypes,\n> implements IFluidDataStoreFactory, Partial<IProvideFluidDataStoreRegistry>\n{\n\tprivate readonly sharedObjectRegistry: ISharedObjectRegistry;\n\tprivate readonly registry: IFluidDataStoreRegistry | undefined;\n\n\tpublic constructor(\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.\"type\"}\n\t\t */\n\t\tpublic readonly type: string,\n\t\tprivate readonly ctor: new (props: IDataObjectProps<I>) => TObj,\n\t\tsharedObjects: readonly IChannelFactory[],\n\t\tprivate readonly optionalProviders: FluidObjectSymbolProvider<I[\"OptionalProviders\"]>,\n\t\tregistryEntries?: NamedFluidDataStoreRegistryEntries,\n\t\tprivate readonly runtimeClass: typeof FluidDataStoreRuntime = FluidDataStoreRuntime,\n\t) {\n\t\tif (this.type === \"\") {\n\t\t\tthrow new Error(\"undefined type member\");\n\t\t}\n\t\tif (registryEntries !== undefined) {\n\t\t\tthis.registry = new FluidDataStoreRegistry(registryEntries);\n\t\t}\n\t\tthis.sharedObjectRegistry = new Map(sharedObjects.map((ext) => [ext.type, ext]));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreFactory.IFluidDataStoreFactory}\n\t */\n\tpublic get IFluidDataStoreFactory(): this {\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreRegistry.IFluidDataStoreRegistry}\n\t */\n\tpublic get IFluidDataStoreRegistry(): IFluidDataStoreRegistry | undefined {\n\t\treturn this.registry;\n\t}\n\n\t/**\n\t * Convenience helper to get the data store's/factory's data store registry entry.\n\t * The return type hides the factory's generics, easing grouping of registry\n\t * entries that differ only in this way into the same array.\n\t * @returns The NamedFluidDataStoreRegistryEntry\n\t */\n\tpublic get registryEntry(): NamedFluidDataStoreRegistryEntry {\n\t\treturn [this.type, Promise.resolve(this)];\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.instantiateDataStore}\n\t */\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<IFluidDataStoreChannel> {\n\t\tconst { runtime } = await createDataObject(\n\t\t\tthis.ctor,\n\t\t\tcontext,\n\t\t\tthis.sharedObjectRegistry,\n\t\t\tthis.optionalProviders,\n\t\t\tthis.runtimeClass,\n\t\t\texisting,\n\t\t);\n\n\t\treturn runtime;\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses parent context's registry to build package path to this factory.\n\t * In other words, registry of context passed in has to contain this factory, with the name that matches\n\t * this factory's type.\n\t * It is intended to be used by data store objects that create sub-objects.\n\t * @param context - The context being used to create the runtime\n\t * (the created object will have its own new context created as well)\n\t * @param initialState - The initial state to provide to the created data store.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createChildInstance(\n\t\tparentContext: IFluidDataStoreContext,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(\n\t\t\tparentContext.containerRuntime,\n\t\t\t[...parentContext.packagePath, this.type],\n\t\t\tinitialState,\n\t\t\tloadingGroupId,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses peer context's registry and its package path to identify this factory.\n\t * In other words, registry of context passed in has to have this factory.\n\t * Intended to be used by data store objects that need to create peers (similar) instances of existing objects.\n\t * @param context - The component context being used to create the object\n\t * (the created object will have its own new context created as well)\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createPeerInstance(\n\t\tpeerContext: IFluidDataStoreContext,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string, // DO NOT USE, this is an experimental feature\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(\n\t\t\tpeerContext.containerRuntime,\n\t\t\tpeerContext.packagePath,\n\t\t\tinitialState,\n\t\t\tloadingGroupId,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses container's registry to find this factory.\n\t * It's expected that only container owners would use this functionality, as only such developers\n\t * have knowledge of entries in container registry.\n\t * The name in this registry for such record should match type of this factory.\n\t * @param runtime - container runtime. It's registry is used to create an object.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createInstance(\n\t\truntime: IContainerRuntimeBase,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(runtime, [this.type], initialState, loadingGroupId);\n\t}\n\n\t/**\n\t * Creates a new instance of the object with a datastore which exposes the aliasing api.\n\t * @param runtime - container runtime. It is the runtime that will be used to create the object. It will produce\n\t * the underlying infrastructure to get the data object to operate.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param packagePath - The path to the data store factory to use to create the data object.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an array containing the object created by this factory and an IDataStore object that enables users to\n\t * alias the data object.\n\t * The data object is attached only when it is attached to the handle graph that connects to an aliased object or\n\t * when the data object is aliased.\n\t */\n\tpublic async createInstanceWithDataStore(\n\t\tcontainerRuntime: IContainerRuntimeBase,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tpackagePath?: Readonly<string[]>,\n\t\tloadingGroupId?: string,\n\t): Promise<[TObj, IDataStore]> {\n\t\tconst context = containerRuntime.createDetachedDataStore(\n\t\t\tpackagePath ?? [this.type],\n\t\t\tloadingGroupId,\n\t\t);\n\t\tconst { instance, runtime } = await createDataObject(\n\t\t\tthis.ctor,\n\t\t\tcontext,\n\t\t\tthis.sharedObjectRegistry,\n\t\t\tthis.optionalProviders,\n\t\t\tthis.runtimeClass,\n\t\t\tfalse, // existing\n\t\t\tinitialState,\n\t\t);\n\t\tconst dataStore = await context.attachRuntime(this, runtime);\n\n\t\treturn [instance, dataStore];\n\t}\n\n\t/**\n\t * Creates a new root instance of the object. Uses container's registry to find this factory.\n\t * It's expected that only container owners would use this functionality, as only such developers\n\t * have knowledge of entries in container registry.\n\t * The name in this registry for such record should match type of this factory.\n\t * @param runtime - container runtime. It's registry is used to create an object.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t *\n\t * @deprecated - the issue is that it does not allow the customer to decide the conflict resolution policy when an\n\t * aliasing conflict occurs. Use {@link PureDataObjectFactory.createInstanceWithDataStore} instead.\n\t */\n\tpublic async createRootInstance(\n\t\trootDataStoreId: string,\n\t\truntime: IContainerRuntime,\n\t\tinitialState?: I[\"InitialState\"],\n\t): Promise<TObj> {\n\t\tconst context = runtime.createDetachedDataStore([this.type]);\n\t\tconst { instance, runtime: dataStoreRuntime } = await createDataObject(\n\t\t\tthis.ctor,\n\t\t\tcontext,\n\t\t\tthis.sharedObjectRegistry,\n\t\t\tthis.optionalProviders,\n\t\t\tthis.runtimeClass,\n\t\t\tfalse, // existing\n\t\t\tinitialState,\n\t\t);\n\t\tconst dataStore = await context.attachRuntime(this, dataStoreRuntime);\n\t\tconst result = await dataStore.trySetAlias(rootDataStoreId);\n\t\tif (result !== \"Success\") {\n\t\t\tconst handle = await runtime.getAliasedDataStoreEntryPoint(rootDataStoreId);\n\t\t\tassert(handle !== undefined, 0x8e1 /* Should have retrieved aliased handle */);\n\t\t\treturn (await handle.get()) as TObj;\n\t\t}\n\t\treturn instance;\n\t}\n\n\tprotected async createNonRootInstanceCore(\n\t\tcontainerRuntime: IContainerRuntimeBase,\n\t\tpackagePath: Readonly<string[]>,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\tconst context = containerRuntime.createDetachedDataStore(packagePath, loadingGroupId);\n\t\treturn this.createInstanceCore(context, initialState);\n\t}\n\n\tprotected async createInstanceCore(\n\t\tcontext: IFluidDataStoreContextDetached,\n\t\tinitialState?: I[\"InitialState\"],\n\t): Promise<TObj> {\n\t\tconst { instance, runtime } = await createDataObject(\n\t\t\tthis.ctor,\n\t\t\tcontext,\n\t\t\tthis.sharedObjectRegistry,\n\t\t\tthis.optionalProviders,\n\t\t\tthis.runtimeClass,\n\t\t\tfalse, // existing\n\t\t\tinitialState,\n\t\t);\n\n\t\tawait context.attachRuntime(this, runtime);\n\n\t\treturn instance;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pureDataObjectFactory.js","sourceRoot":"","sources":["../../src/data-object-factories/pureDataObjectFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAGpF,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EACN,qBAAqB,EAErB,mBAAmB,GACnB,MAAM,oCAAoC,CAAC;AAsC5C;;;GAGG;AACH,KAAK,UAAU,gBAAgB,CAG7B,EACD,IAAI,EACJ,OAAO,EACP,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,QAAQ,EACR,YAAY,EAAE,SAAS,GACS;IAIhC,OAAO;IACP,IAAI,YAAY,GAAG,eAAe,CAAC;IAEnC,mBAAmB;IACnB,YAAY,GAAG,mBAAmB,CACjC,KAAK,EAAE,OAAiB,EAAE,UA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AM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,gBAAgB,CAAC;YACpD,GAAG,IAAI,CAAC,WAAW;YACnB,OAAO;YACP,QAAQ,EAAE,KAAK;YACf,YAAY;SACZ,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE3C,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { FluidDataStoreRegistry } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { FluidObject, IRequest } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tFluidDataStoreRuntime,\n\ttype ISharedObjectRegistry,\n\tmixinRequestHandler,\n} from \"@fluidframework/datastore/internal\";\nimport type {\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type {\n\tIContainerRuntimeBase,\n\tIDataStore,\n\tIFluidDataStoreChannel,\n\tIFluidDataStoreContext,\n\tIFluidDataStoreContextDetached,\n\tIFluidDataStoreFactory,\n\tIFluidDataStoreRegistry,\n\tIProvideFluidDataStoreRegistry,\n\tNamedFluidDataStoreRegistryEntries,\n\tNamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport type {\n\tAsyncFluidObjectProvider,\n\tFluidObjectSymbolProvider,\n\tIFluidDependencySynthesizer,\n} from \"@fluidframework/synthesize/internal\";\n\nimport type {\n\tDataObjectTypes,\n\tIDataObjectProps,\n\tPureDataObject,\n} from \"../data-objects/index.js\";\n\ninterface CreateDataObjectProps<TObj extends PureDataObject, I extends DataObjectTypes> {\n\tctor: new (props: IDataObjectProps<I>) => TObj;\n\tcontext: IFluidDataStoreContext;\n\tsharedObjectRegistry: ISharedObjectRegistry;\n\toptionalProviders: FluidObjectSymbolProvider<I[\"OptionalProviders\"]>;\n\truntimeClassArg: typeof FluidDataStoreRuntime;\n\texisting: boolean;\n\tinitialState?: I[\"InitialState\"];\n}\n/**\n * Proxy over PureDataObject\n * Does delayed creation & initialization of PureDataObject\n */\nasync function createDataObject<\n\tTObj extends PureDataObject,\n\tI extends DataObjectTypes = DataObjectTypes,\n>({\n\tctor,\n\tcontext,\n\tsharedObjectRegistry,\n\toptionalProviders,\n\truntimeClassArg,\n\texisting,\n\tinitialState: initProps,\n}: CreateDataObjectProps<TObj, I>): Promise<{\n\tinstance: TObj;\n\truntime: FluidDataStoreRuntime;\n}> {\n\t// base\n\tlet runtimeClass = runtimeClassArg;\n\n\t// request mixin in\n\truntimeClass = mixinRequestHandler(\n\t\tasync (request: IRequest, runtimeArg: FluidDataStoreRuntime) => {\n\t\t\t// The provideEntryPoint callback below always returns TObj, so this cast is safe\n\t\t\tconst dataObject = (await runtimeArg.entryPoint.get()) as TObj;\n\t\t\tassert(\n\t\t\t\tdataObject.request !== undefined,\n\t\t\t\t0x795 /* Data store runtime entryPoint does not have request */,\n\t\t\t);\n\t\t\treturn dataObject.request(request);\n\t\t},\n\t\truntimeClass,\n\t);\n\n\t// Create a new runtime for our data store, as if via new FluidDataStoreRuntime,\n\t// but using the runtimeClass that's been augmented with mixins\n\t// The runtime is what Fluid uses to create DDS' and route to your data store\n\tconst runtime: FluidDataStoreRuntime = new runtimeClass(\n\t\t// calls new FluidDataStoreRuntime(...)\n\t\tcontext,\n\t\tsharedObjectRegistry,\n\t\texisting,\n\t\tasync (rt: IFluidDataStoreRuntime) => {\n\t\t\tassert(instance !== undefined, 0x46a /* entryPoint is undefined */);\n\t\t\t// Calling finishInitialization here like PureDataObject.getDataObject did, to keep the same behavior,\n\t\t\t// since accessing the runtime's entryPoint is how we want the data object to be retrieved going forward.\n\t\t\t// Without this I ran into issues with the load-existing flow not working correctly.\n\t\t\tawait instance.finishInitialization(true);\n\t\t\treturn instance;\n\t\t} /* provideEntryPoint */,\n\t);\n\n\t// Create object right away.\n\t// This allows object to register various callbacks with runtime before runtime\n\t// becomes globally available. But it's not full initialization - constructor can't\n\t// access DDSes or other services of runtime as objects are not fully initialized.\n\t// In order to use object, we need to go through full initialization by calling finishInitialization().\n\tconst scope: FluidObject<IFluidDependencySynthesizer> = context.scope;\n\tconst providers =\n\t\tscope.IFluidDependencySynthesizer?.synthesize<I[\"OptionalProviders\"]>(\n\t\t\toptionalProviders,\n\t\t\t{},\n\t\t) ??\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t({} as AsyncFluidObjectProvider<never>);\n\n\tconst instance = new ctor({ runtime, context, providers, initProps });\n\n\t// if it's a newly created object, we need to wait for it to finish initialization\n\t// as that results in creation of DDSes, before it gets attached, providing atomic\n\t// guarantee of creation.\n\t// WARNING: we can't do the same (yet) for already existing PureDataObject!\n\t// This will result in deadlock, as it tries to resolve internal handles, but any\n\t// handle resolution goes through root (container runtime), which can't route it back\n\t// to this data store, as it's still not initialized and not known to container runtime yet.\n\t// In the future, we should address it by using relative paths for handles and be able to resolve\n\t// local DDSes while data store is not fully initialized.\n\tif (!existing) {\n\t\tawait instance.finishInitialization(existing);\n\t}\n\n\treturn { instance, runtime };\n}\n\n/**\n * PureDataObjectFactory is a bare-bones IFluidDataStoreFactory for use with PureDataObject.\n * Consumers should typically use DataObjectFactory instead unless creating\n * another base data store factory.\n *\n * @typeParam TObj - DataObject (concrete type)\n * @typeParam I - The input types for the DataObject\n * @legacy\n * @alpha\n */\nexport class PureDataObjectFactory<\n\tTObj extends PureDataObject<I>,\n\tI extends DataObjectTypes = DataObjectTypes,\n> implements IFluidDataStoreFactory, Partial<IProvideFluidDataStoreRegistry>\n{\n\tprivate readonly registry: IFluidDataStoreRegistry | undefined;\n\tprivate readonly createProps: Omit<CreateDataObjectProps<TObj, I>, \"existing\" | \"context\">;\n\n\tpublic constructor(\n\t\t/**\n\t\t * {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.\"type\"}\n\t\t */\n\t\tpublic readonly type: string,\n\t\tctor: new (props: IDataObjectProps<I>) => TObj,\n\t\tsharedObjects: readonly IChannelFactory[],\n\t\toptionalProviders: FluidObjectSymbolProvider<I[\"OptionalProviders\"]>,\n\t\tregistryEntries?: NamedFluidDataStoreRegistryEntries,\n\t\truntimeClass: typeof FluidDataStoreRuntime = FluidDataStoreRuntime,\n\t) {\n\t\tif (this.type === \"\") {\n\t\t\tthrow new Error(\"undefined type member\");\n\t\t}\n\n\t\tthis.createProps = {\n\t\t\tctor,\n\t\t\toptionalProviders,\n\t\t\tsharedObjectRegistry: new Map(sharedObjects.map((ext) => [ext.type, ext])),\n\t\t\truntimeClassArg: runtimeClass,\n\t\t};\n\n\t\tif (registryEntries !== undefined) {\n\t\t\tthis.registry = new FluidDataStoreRegistry(registryEntries);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreFactory.IFluidDataStoreFactory}\n\t */\n\tpublic get IFluidDataStoreFactory(): this {\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IProvideFluidDataStoreRegistry.IFluidDataStoreRegistry}\n\t */\n\tpublic get IFluidDataStoreRegistry(): IFluidDataStoreRegistry | undefined {\n\t\treturn this.registry;\n\t}\n\n\t/**\n\t * Convenience helper to get the data store's/factory's data store registry entry.\n\t * The return type hides the factory's generics, easing grouping of registry\n\t * entries that differ only in this way into the same array.\n\t * @returns The NamedFluidDataStoreRegistryEntry\n\t */\n\tpublic get registryEntry(): NamedFluidDataStoreRegistryEntry {\n\t\treturn [this.type, Promise.resolve(this)];\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory.instantiateDataStore}\n\t */\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<IFluidDataStoreChannel> {\n\t\tconst { runtime } = await createDataObject({ ...this.createProps, context, existing });\n\n\t\treturn runtime;\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses parent context's registry to build package path to this factory.\n\t * In other words, registry of context passed in has to contain this factory, with the name that matches\n\t * this factory's type.\n\t * It is intended to be used by data store objects that create sub-objects.\n\t * @param context - The context being used to create the runtime\n\t * (the created object will have its own new context created as well)\n\t * @param initialState - The initial state to provide to the created data store.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createChildInstance(\n\t\tparentContext: IFluidDataStoreContext,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(\n\t\t\tparentContext.containerRuntime,\n\t\t\t[...parentContext.packagePath, this.type],\n\t\t\tinitialState,\n\t\t\tloadingGroupId,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses peer context's registry and its package path to identify this factory.\n\t * In other words, registry of context passed in has to have this factory.\n\t * Intended to be used by data store objects that need to create peers (similar) instances of existing objects.\n\t * @param context - The component context being used to create the object\n\t * (the created object will have its own new context created as well)\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createPeerInstance(\n\t\tpeerContext: IFluidDataStoreContext,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string, // DO NOT USE, this is an experimental feature\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(\n\t\t\tpeerContext.containerRuntime,\n\t\t\tpeerContext.packagePath,\n\t\t\tinitialState,\n\t\t\tloadingGroupId,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a new instance of the object. Uses container's registry to find this factory.\n\t * It's expected that only container owners would use this functionality, as only such developers\n\t * have knowledge of entries in container registry.\n\t * The name in this registry for such record should match type of this factory.\n\t * @param runtime - container runtime. It's registry is used to create an object.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t */\n\tpublic async createInstance(\n\t\truntime: IContainerRuntimeBase,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\treturn this.createNonRootInstanceCore(runtime, [this.type], initialState, loadingGroupId);\n\t}\n\n\t/**\n\t * Creates a new instance of the object with a datastore which exposes the aliasing api.\n\t * @param runtime - container runtime. It is the runtime that will be used to create the object. It will produce\n\t * the underlying infrastructure to get the data object to operate.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @param packagePath - The path to the data store factory to use to create the data object.\n\t * @param loadingGroupId - NOT production ready, EXPERIMENTAL, please read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/README.md | README}. The service needs to support this feature, does not work for most services\n\t * @returns an array containing the object created by this factory and an IDataStore object that enables users to\n\t * alias the data object.\n\t * The data object is attached only when it is attached to the handle graph that connects to an aliased object or\n\t * when the data object is aliased.\n\t */\n\tpublic async createInstanceWithDataStore(\n\t\tcontainerRuntime: IContainerRuntimeBase,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tpackagePath?: Readonly<string[]>,\n\t\tloadingGroupId?: string,\n\t): Promise<[TObj, IDataStore]> {\n\t\tconst context = containerRuntime.createDetachedDataStore(\n\t\t\tpackagePath ?? [this.type],\n\t\t\tloadingGroupId,\n\t\t);\n\t\tconst { instance, runtime } = await createDataObject({\n\t\t\t...this.createProps,\n\t\t\tcontext,\n\t\t\texisting: false,\n\t\t\tinitialState,\n\t\t});\n\t\tconst dataStore = await context.attachRuntime(this, runtime);\n\n\t\treturn [instance, dataStore];\n\t}\n\n\t/**\n\t * Creates a new root instance of the object. Uses container's registry to find this factory.\n\t * It's expected that only container owners would use this functionality, as only such developers\n\t * have knowledge of entries in container registry.\n\t * The name in this registry for such record should match type of this factory.\n\t * @param runtime - container runtime. It's registry is used to create an object.\n\t * @param initialState - The initial state to provide to the created component.\n\t * @returns an object created by this factory. Data store and objects created are not attached to container.\n\t * They get attached only when a handle to one of them is attached to already attached objects.\n\t *\n\t * @deprecated - the issue is that it does not allow the customer to decide the conflict resolution policy when an\n\t * aliasing conflict occurs. Use {@link PureDataObjectFactory.createInstanceWithDataStore} instead.\n\t */\n\tpublic async createRootInstance(\n\t\trootDataStoreId: string,\n\t\truntime: IContainerRuntime,\n\t\tinitialState?: I[\"InitialState\"],\n\t): Promise<TObj> {\n\t\tconst context = runtime.createDetachedDataStore([this.type]);\n\t\tconst { instance, runtime: dataStoreRuntime } = await createDataObject({\n\t\t\t...this.createProps,\n\t\t\tcontext,\n\t\t\texisting: false,\n\t\t\tinitialState,\n\t\t});\n\t\tconst dataStore = await context.attachRuntime(this, dataStoreRuntime);\n\t\tconst result = await dataStore.trySetAlias(rootDataStoreId);\n\t\tif (result !== \"Success\") {\n\t\t\tconst handle = await runtime.getAliasedDataStoreEntryPoint(rootDataStoreId);\n\t\t\tassert(handle !== undefined, 0x8e1 /* Should have retrieved aliased handle */);\n\t\t\treturn (await handle.get()) as TObj;\n\t\t}\n\t\treturn instance;\n\t}\n\n\tprotected async createNonRootInstanceCore(\n\t\tcontainerRuntime: IContainerRuntimeBase,\n\t\tpackagePath: Readonly<string[]>,\n\t\tinitialState?: I[\"InitialState\"],\n\t\tloadingGroupId?: string,\n\t): Promise<TObj> {\n\t\tconst context = containerRuntime.createDetachedDataStore(packagePath, loadingGroupId);\n\t\treturn this.createInstanceCore(context, initialState);\n\t}\n\n\tprotected async createInstanceCore(\n\t\tcontext: IFluidDataStoreContextDetached,\n\t\tinitialState?: I[\"InitialState\"],\n\t): Promise<TObj> {\n\t\tconst { instance, runtime } = await createDataObject({\n\t\t\t...this.createProps,\n\t\t\tcontext,\n\t\t\texisting: false,\n\t\t\tinitialState,\n\t\t});\n\n\t\tawait context.attachRuntime(this, runtime);\n\n\t\treturn instance;\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/aqueduct",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.40.0-336023",
|
|
4
4
|
"description": "A set of implementations for Fluid Framework interfaces.",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,27 +69,27 @@
|
|
|
69
69
|
"temp-directory": "nyc/.nyc_output"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fluid-internal/client-utils": "
|
|
73
|
-
"@fluidframework/container-definitions": "
|
|
74
|
-
"@fluidframework/container-runtime": "
|
|
75
|
-
"@fluidframework/container-runtime-definitions": "
|
|
76
|
-
"@fluidframework/core-interfaces": "
|
|
77
|
-
"@fluidframework/core-utils": "
|
|
78
|
-
"@fluidframework/datastore": "
|
|
79
|
-
"@fluidframework/datastore-definitions": "
|
|
80
|
-
"@fluidframework/map": "
|
|
81
|
-
"@fluidframework/request-handler": "
|
|
82
|
-
"@fluidframework/runtime-definitions": "
|
|
83
|
-
"@fluidframework/runtime-utils": "
|
|
84
|
-
"@fluidframework/shared-object-base": "
|
|
85
|
-
"@fluidframework/synthesize": "
|
|
86
|
-
"@fluidframework/telemetry-utils": "
|
|
87
|
-
"@fluidframework/tree": "
|
|
72
|
+
"@fluid-internal/client-utils": "2.40.0-336023",
|
|
73
|
+
"@fluidframework/container-definitions": "2.40.0-336023",
|
|
74
|
+
"@fluidframework/container-runtime": "2.40.0-336023",
|
|
75
|
+
"@fluidframework/container-runtime-definitions": "2.40.0-336023",
|
|
76
|
+
"@fluidframework/core-interfaces": "2.40.0-336023",
|
|
77
|
+
"@fluidframework/core-utils": "2.40.0-336023",
|
|
78
|
+
"@fluidframework/datastore": "2.40.0-336023",
|
|
79
|
+
"@fluidframework/datastore-definitions": "2.40.0-336023",
|
|
80
|
+
"@fluidframework/map": "2.40.0-336023",
|
|
81
|
+
"@fluidframework/request-handler": "2.40.0-336023",
|
|
82
|
+
"@fluidframework/runtime-definitions": "2.40.0-336023",
|
|
83
|
+
"@fluidframework/runtime-utils": "2.40.0-336023",
|
|
84
|
+
"@fluidframework/shared-object-base": "2.40.0-336023",
|
|
85
|
+
"@fluidframework/synthesize": "2.40.0-336023",
|
|
86
|
+
"@fluidframework/telemetry-utils": "2.40.0-336023",
|
|
87
|
+
"@fluidframework/tree": "2.40.0-336023"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
91
91
|
"@biomejs/biome": "~1.9.3",
|
|
92
|
-
"@fluid-internal/mocha-test-setup": "
|
|
92
|
+
"@fluid-internal/mocha-test-setup": "2.40.0-336023",
|
|
93
93
|
"@fluid-tools/build-cli": "^0.55.0",
|
|
94
94
|
"@fluidframework/aqueduct-previous": "npm:@fluidframework/aqueduct@2.33.0",
|
|
95
95
|
"@fluidframework/build-common": "^2.0.3",
|
|
@@ -40,6 +40,15 @@ import type {
|
|
|
40
40
|
PureDataObject,
|
|
41
41
|
} from "../data-objects/index.js";
|
|
42
42
|
|
|
43
|
+
interface CreateDataObjectProps<TObj extends PureDataObject, I extends DataObjectTypes> {
|
|
44
|
+
ctor: new (props: IDataObjectProps<I>) => TObj;
|
|
45
|
+
context: IFluidDataStoreContext;
|
|
46
|
+
sharedObjectRegistry: ISharedObjectRegistry;
|
|
47
|
+
optionalProviders: FluidObjectSymbolProvider<I["OptionalProviders"]>;
|
|
48
|
+
runtimeClassArg: typeof FluidDataStoreRuntime;
|
|
49
|
+
existing: boolean;
|
|
50
|
+
initialState?: I["InitialState"];
|
|
51
|
+
}
|
|
43
52
|
/**
|
|
44
53
|
* Proxy over PureDataObject
|
|
45
54
|
* Does delayed creation & initialization of PureDataObject
|
|
@@ -47,15 +56,15 @@ import type {
|
|
|
47
56
|
async function createDataObject<
|
|
48
57
|
TObj extends PureDataObject,
|
|
49
58
|
I extends DataObjectTypes = DataObjectTypes,
|
|
50
|
-
>(
|
|
51
|
-
ctor
|
|
52
|
-
context
|
|
53
|
-
sharedObjectRegistry
|
|
54
|
-
optionalProviders
|
|
55
|
-
runtimeClassArg
|
|
56
|
-
existing
|
|
57
|
-
initProps
|
|
58
|
-
): Promise<{
|
|
59
|
+
>({
|
|
60
|
+
ctor,
|
|
61
|
+
context,
|
|
62
|
+
sharedObjectRegistry,
|
|
63
|
+
optionalProviders,
|
|
64
|
+
runtimeClassArg,
|
|
65
|
+
existing,
|
|
66
|
+
initialState: initProps,
|
|
67
|
+
}: CreateDataObjectProps<TObj, I>): Promise<{
|
|
59
68
|
instance: TObj;
|
|
60
69
|
runtime: FluidDataStoreRuntime;
|
|
61
70
|
}> {
|
|
@@ -141,27 +150,34 @@ export class PureDataObjectFactory<
|
|
|
141
150
|
I extends DataObjectTypes = DataObjectTypes,
|
|
142
151
|
> implements IFluidDataStoreFactory, Partial<IProvideFluidDataStoreRegistry>
|
|
143
152
|
{
|
|
144
|
-
private readonly sharedObjectRegistry: ISharedObjectRegistry;
|
|
145
153
|
private readonly registry: IFluidDataStoreRegistry | undefined;
|
|
154
|
+
private readonly createProps: Omit<CreateDataObjectProps<TObj, I>, "existing" | "context">;
|
|
146
155
|
|
|
147
156
|
public constructor(
|
|
148
157
|
/**
|
|
149
158
|
* {@inheritDoc @fluidframework/runtime-definitions#IFluidDataStoreFactory."type"}
|
|
150
159
|
*/
|
|
151
160
|
public readonly type: string,
|
|
152
|
-
|
|
161
|
+
ctor: new (props: IDataObjectProps<I>) => TObj,
|
|
153
162
|
sharedObjects: readonly IChannelFactory[],
|
|
154
|
-
|
|
163
|
+
optionalProviders: FluidObjectSymbolProvider<I["OptionalProviders"]>,
|
|
155
164
|
registryEntries?: NamedFluidDataStoreRegistryEntries,
|
|
156
|
-
|
|
165
|
+
runtimeClass: typeof FluidDataStoreRuntime = FluidDataStoreRuntime,
|
|
157
166
|
) {
|
|
158
167
|
if (this.type === "") {
|
|
159
168
|
throw new Error("undefined type member");
|
|
160
169
|
}
|
|
170
|
+
|
|
171
|
+
this.createProps = {
|
|
172
|
+
ctor,
|
|
173
|
+
optionalProviders,
|
|
174
|
+
sharedObjectRegistry: new Map(sharedObjects.map((ext) => [ext.type, ext])),
|
|
175
|
+
runtimeClassArg: runtimeClass,
|
|
176
|
+
};
|
|
177
|
+
|
|
161
178
|
if (registryEntries !== undefined) {
|
|
162
179
|
this.registry = new FluidDataStoreRegistry(registryEntries);
|
|
163
180
|
}
|
|
164
|
-
this.sharedObjectRegistry = new Map(sharedObjects.map((ext) => [ext.type, ext]));
|
|
165
181
|
}
|
|
166
182
|
|
|
167
183
|
/**
|
|
@@ -195,14 +211,7 @@ export class PureDataObjectFactory<
|
|
|
195
211
|
context: IFluidDataStoreContext,
|
|
196
212
|
existing: boolean,
|
|
197
213
|
): Promise<IFluidDataStoreChannel> {
|
|
198
|
-
const { runtime } = await createDataObject(
|
|
199
|
-
this.ctor,
|
|
200
|
-
context,
|
|
201
|
-
this.sharedObjectRegistry,
|
|
202
|
-
this.optionalProviders,
|
|
203
|
-
this.runtimeClass,
|
|
204
|
-
existing,
|
|
205
|
-
);
|
|
214
|
+
const { runtime } = await createDataObject({ ...this.createProps, context, existing });
|
|
206
215
|
|
|
207
216
|
return runtime;
|
|
208
217
|
}
|
|
@@ -297,15 +306,12 @@ export class PureDataObjectFactory<
|
|
|
297
306
|
packagePath ?? [this.type],
|
|
298
307
|
loadingGroupId,
|
|
299
308
|
);
|
|
300
|
-
const { instance, runtime } = await createDataObject(
|
|
301
|
-
this.
|
|
309
|
+
const { instance, runtime } = await createDataObject({
|
|
310
|
+
...this.createProps,
|
|
302
311
|
context,
|
|
303
|
-
|
|
304
|
-
this.optionalProviders,
|
|
305
|
-
this.runtimeClass,
|
|
306
|
-
false, // existing
|
|
312
|
+
existing: false,
|
|
307
313
|
initialState,
|
|
308
|
-
);
|
|
314
|
+
});
|
|
309
315
|
const dataStore = await context.attachRuntime(this, runtime);
|
|
310
316
|
|
|
311
317
|
return [instance, dataStore];
|
|
@@ -330,15 +336,12 @@ export class PureDataObjectFactory<
|
|
|
330
336
|
initialState?: I["InitialState"],
|
|
331
337
|
): Promise<TObj> {
|
|
332
338
|
const context = runtime.createDetachedDataStore([this.type]);
|
|
333
|
-
const { instance, runtime: dataStoreRuntime } = await createDataObject(
|
|
334
|
-
this.
|
|
339
|
+
const { instance, runtime: dataStoreRuntime } = await createDataObject({
|
|
340
|
+
...this.createProps,
|
|
335
341
|
context,
|
|
336
|
-
|
|
337
|
-
this.optionalProviders,
|
|
338
|
-
this.runtimeClass,
|
|
339
|
-
false, // existing
|
|
342
|
+
existing: false,
|
|
340
343
|
initialState,
|
|
341
|
-
);
|
|
344
|
+
});
|
|
342
345
|
const dataStore = await context.attachRuntime(this, dataStoreRuntime);
|
|
343
346
|
const result = await dataStore.trySetAlias(rootDataStoreId);
|
|
344
347
|
if (result !== "Success") {
|
|
@@ -363,15 +366,12 @@ export class PureDataObjectFactory<
|
|
|
363
366
|
context: IFluidDataStoreContextDetached,
|
|
364
367
|
initialState?: I["InitialState"],
|
|
365
368
|
): Promise<TObj> {
|
|
366
|
-
const { instance, runtime } = await createDataObject(
|
|
367
|
-
this.
|
|
369
|
+
const { instance, runtime } = await createDataObject({
|
|
370
|
+
...this.createProps,
|
|
368
371
|
context,
|
|
369
|
-
|
|
370
|
-
this.optionalProviders,
|
|
371
|
-
this.runtimeClass,
|
|
372
|
-
false, // existing
|
|
372
|
+
existing: false,
|
|
373
373
|
initialState,
|
|
374
|
-
);
|
|
374
|
+
});
|
|
375
375
|
|
|
376
376
|
await context.attachRuntime(this, runtime);
|
|
377
377
|
|