@fluidframework/test-utils 2.31.1 → 2.33.0-333010

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +3 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/packageVersion.d.ts +1 -1
  7. package/dist/packageVersion.d.ts.map +1 -1
  8. package/dist/packageVersion.js +1 -1
  9. package/dist/packageVersion.js.map +1 -1
  10. package/dist/testFluidObject.d.ts +23 -10
  11. package/dist/testFluidObject.d.ts.map +1 -1
  12. package/dist/testFluidObject.js +22 -19
  13. package/dist/testFluidObject.js.map +1 -1
  14. package/dist/testFluidObjectInternal.d.ts +50 -0
  15. package/dist/testFluidObjectInternal.d.ts.map +1 -0
  16. package/dist/testFluidObjectInternal.js +78 -0
  17. package/dist/testFluidObjectInternal.js.map +1 -0
  18. package/lib/index.d.ts +2 -1
  19. package/lib/index.d.ts.map +1 -1
  20. package/lib/index.js +1 -0
  21. package/lib/index.js.map +1 -1
  22. package/lib/packageVersion.d.ts +1 -1
  23. package/lib/packageVersion.d.ts.map +1 -1
  24. package/lib/packageVersion.js +1 -1
  25. package/lib/packageVersion.js.map +1 -1
  26. package/lib/testFluidObject.d.ts +23 -10
  27. package/lib/testFluidObject.d.ts.map +1 -1
  28. package/lib/testFluidObject.js +22 -19
  29. package/lib/testFluidObject.js.map +1 -1
  30. package/lib/testFluidObjectInternal.d.ts +50 -0
  31. package/lib/testFluidObjectInternal.d.ts.map +1 -0
  32. package/lib/testFluidObjectInternal.js +74 -0
  33. package/lib/testFluidObjectInternal.js.map +1 -0
  34. package/package.json +24 -23
  35. package/src/index.ts +3 -0
  36. package/src/packageVersion.ts +1 -1
  37. package/src/testFluidObject.ts +61 -28
  38. package/src/testFluidObjectInternal.ts +110 -0
@@ -2,37 +2,41 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IFluidHandle, IRequest, IResponse } from "@fluidframework/core-interfaces";
5
+ import { IFluidHandle, IRequest, IResponse, type IFluidLoadable } from "@fluidframework/core-interfaces";
6
6
  import { FluidDataStoreRuntime } from "@fluidframework/datastore/internal";
7
7
  import { IChannelFactory, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions/internal";
8
8
  import { ISharedMap } from "@fluidframework/map/internal";
9
9
  import { IFluidDataStoreChannel, IFluidDataStoreContext, IFluidDataStoreFactory } from "@fluidframework/runtime-definitions/internal";
10
+ import type { ISharedObject } from "@fluidframework/shared-object-base/internal";
10
11
  import { ITestFluidObject } from "./interfaces.js";
11
12
  /**
12
- * A test Fluid object that will create a shared object for each key-value pair in the factoryEntries passed to load.
13
+ * A test Fluid object that will create a shared object for each key-value pair in the initialSharedObjectsFactories passed to load.
13
14
  * The shared objects can be retrieved by passing the key of the entry to getSharedObject.
14
15
  * It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.
16
+ * @privateRemarks
17
+ * TODO:
18
+ * Usage of this outside this repo (via ITestFluidObject) should probably be phased out.
19
+ * Once thats done, ITestFluidObject can be made internal and this class can be replaced with the simplified TestFluidObjectInternal.
15
20
  * @internal
16
21
  */
17
22
  export declare class TestFluidObject implements ITestFluidObject {
18
23
  readonly runtime: IFluidDataStoreRuntime;
19
24
  readonly channel: IFluidDataStoreChannel;
20
25
  readonly context: IFluidDataStoreContext;
21
- private readonly factoryEntriesMap;
26
+ private readonly initialSharedObjectsFactories;
22
27
  get ITestFluidObject(): this;
23
28
  get IFluidLoadable(): this;
24
- get handle(): IFluidHandle<this>;
29
+ readonly handle: IFluidHandle<this>;
25
30
  root: ISharedMap;
26
- private readonly innerHandle;
27
31
  private initializationPromise;
28
32
  /**
29
33
  * Creates a new TestFluidObject.
30
34
  * @param runtime - The data store runtime.
31
35
  * @param context - The data store context.
32
- * @param factoryEntries - A list of id to IChannelFactory mapping. For each item in the list,
36
+ * @param initialSharedObjectsFactories - A list of id to IChannelFactory mapping. For each item in the list,
33
37
  * a shared object is created which can be retrieved by calling getSharedObject() with the id;
34
38
  */
35
- constructor(runtime: IFluidDataStoreRuntime, channel: IFluidDataStoreChannel, context: IFluidDataStoreContext, factoryEntriesMap: Map<string, IChannelFactory>);
39
+ constructor(runtime: IFluidDataStoreRuntime, channel: IFluidDataStoreChannel, context: IFluidDataStoreContext, initialSharedObjectsFactories: ReadonlyMap<string, IChannelFactory<ISharedObject>>);
36
40
  /**
37
41
  * Retrieves a shared object with the given id.
38
42
  * @param id - The id of the shared object to retrieve.
@@ -46,6 +50,14 @@ export declare class TestFluidObject implements ITestFluidObject {
46
50
  * @internal
47
51
  */
48
52
  export type ChannelFactoryRegistry = Iterable<[string | undefined, IChannelFactory]>;
53
+ /**
54
+ * Kind of test data object which {@link TestFluidObjectFactory} can create.
55
+ * @internal
56
+ */
57
+ export type TestDataObjectKind = new (runtime: IFluidDataStoreRuntime, channel: IFluidDataStoreChannel, context: IFluidDataStoreContext, initialSharedObjectsFactories: ReadonlyMap<string, IChannelFactory<ISharedObject>>) => IFluidLoadable & {
58
+ request(request: IRequest): Promise<IResponse>;
59
+ initialize(existing: boolean): Promise<void>;
60
+ };
49
61
  /**
50
62
  * Creates a factory for a TestFluidObject with the given object factory entries. It creates a data store runtime
51
63
  * with the object factories in the entry list. All the entries with an id other than undefined are passed to the
@@ -78,16 +90,17 @@ export type ChannelFactoryRegistry = Iterable<[string | undefined, IChannelFacto
78
90
  * @internal
79
91
  */
80
92
  export declare class TestFluidObjectFactory implements IFluidDataStoreFactory {
81
- private readonly factoryEntries;
93
+ private readonly initialSharedObjectsFactories;
82
94
  readonly type: string;
95
+ private readonly dataObjectKind;
83
96
  get IFluidDataStoreFactory(): this;
84
97
  /**
85
98
  * Creates a new TestFluidObjectFactory.
86
- * @param factoryEntries - A list of id to IChannelFactory mapping. It creates a data store runtime with each
99
+ * @param initialSharedObjectsFactories - A list of id to IChannelFactory mapping. It creates a data store runtime with each
87
100
  * IChannelFactory. Entries with string ids are passed to the Fluid object so that it can create a shared object
88
101
  * for it.
89
102
  */
90
- constructor(factoryEntries: ChannelFactoryRegistry, type?: string);
103
+ constructor(initialSharedObjectsFactories: ChannelFactoryRegistry, type?: string, dataObjectKind?: TestDataObjectKind);
91
104
  instantiateDataStore(context: IFluidDataStoreContext, existing: boolean): Promise<FluidDataStoreRuntime>;
92
105
  }
93
106
  //# sourceMappingURL=testFluidObject.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testFluidObject.d.ts","sourceRoot":"","sources":["../src/testFluidObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEpF,OAAO,EACN,qBAAqB,EAGrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,UAAU,EAAa,MAAM,8BAA8B,CAAC;AACrE,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,8CAA8C,CAAC;AAGtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,gBAAgB;aAyBtC,OAAO,EAAE,sBAAsB;aAC/B,OAAO,EAAE,sBAAsB;aAC/B,OAAO,EAAE,sBAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IA3BnC,IAAW,gBAAgB,SAE1B;IAED,IAAW,cAAc,SAExB;IAED,IAAW,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,CAEtC;IAEM,IAAI,EAAG,UAAU,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,qBAAqB,CAA4B;IAEzD;;;;;;OAMG;gBAEc,O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,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/C,UAAU,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,sBAAuB,YAAW,sBAAsB;IAYnE,OAAO,CAAC,QAAQ,CAAC,6BAA6B;aAC9B,IAAI;IACpB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAbhC,IAAW,sBAAsB,SAEhC;IAED;;;;;OAKG;gBAEe,6BAA6B,EAAE,sBAAsB,EACtD,IAAI,SAA2B,EAC9B,cAAc,GAAE,kBAAoC;IAGzD,oBAAoB,CAChC,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,OAAO,GACf,OAAO,CAAC,qBAAqB,CAAC;CAyDjC"}
@@ -7,9 +7,13 @@ import { FluidObjectHandle, mixinRequestHandler, } from "@fluidframework/datasto
7
7
  import { SharedMap } from "@fluidframework/map/internal";
8
8
  import { create404Response } from "@fluidframework/runtime-utils/internal";
9
9
  /**
10
- * A test Fluid object that will create a shared object for each key-value pair in the factoryEntries passed to load.
10
+ * A test Fluid object that will create a shared object for each key-value pair in the initialSharedObjectsFactories passed to load.
11
11
  * The shared objects can be retrieved by passing the key of the entry to getSharedObject.
12
12
  * It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.
13
+ * @privateRemarks
14
+ * TODO:
15
+ * Usage of this outside this repo (via ITestFluidObject) should probably be phased out.
16
+ * Once thats done, ITestFluidObject can be made internal and this class can be replaced with the simplified TestFluidObjectInternal.
13
17
  * @internal
14
18
  */
15
19
  export class TestFluidObject {
@@ -19,35 +23,32 @@ export class TestFluidObject {
19
23
  get IFluidLoadable() {
20
24
  return this;
21
25
  }
22
- get handle() {
23
- return this.innerHandle;
24
- }
25
26
  /**
26
27
  * Creates a new TestFluidObject.
27
28
  * @param runtime - The data store runtime.
28
29
  * @param context - The data store context.
29
- * @param factoryEntries - A list of id to IChannelFactory mapping. For each item in the list,
30
+ * @param initialSharedObjectsFactories - A list of id to IChannelFactory mapping. For each item in the list,
30
31
  * a shared object is created which can be retrieved by calling getSharedObject() with the id;
31
32
  */
32
- constructor(runtime, channel, context, factoryEntriesMap) {
33
+ constructor(runtime, channel, context, initialSharedObjectsFactories) {
33
34
  this.runtime = runtime;
34
35
  this.channel = channel;
35
36
  this.context = context;
36
- this.factoryEntriesMap = factoryEntriesMap;
37
- this.innerHandle = new FluidObjectHandle(this, "", runtime.objectsRoutingContext);
37
+ this.initialSharedObjectsFactories = initialSharedObjectsFactories;
38
+ this.handle = new FluidObjectHandle(this, "", runtime.objectsRoutingContext);
38
39
  }
39
40
  /**
40
41
  * Retrieves a shared object with the given id.
41
42
  * @param id - The id of the shared object to retrieve.
42
43
  */
43
44
  async getSharedObject(id) {
44
- if (this.factoryEntriesMap === undefined) {
45
+ if (this.initialSharedObjectsFactories === undefined) {
45
46
  throw new Error("Shared objects were not provided during creation.");
46
47
  }
47
- if (this.factoryEntriesMap.has(id)) {
48
+ if (this.initialSharedObjectsFactories.has(id)) {
48
49
  const handle = this.root.get(id);
49
50
  if (handle === undefined) {
50
- throw new Error(`Shared object with id '${id}' is in factoryEntriesMap but not found under root.`);
51
+ throw new Error(`Shared object with id '${id}' is in initialSharedObjectsFactories but not found under root.`);
51
52
  }
52
53
  return handle.get();
53
54
  }
@@ -62,7 +63,7 @@ export class TestFluidObject {
62
63
  const doInitialization = async () => {
63
64
  if (!existing) {
64
65
  this.root = SharedMap.create(this.runtime, "root");
65
- this.factoryEntriesMap.forEach((sharedObjectFactory, key) => {
66
+ this.initialSharedObjectsFactories.forEach((sharedObjectFactory, key) => {
66
67
  const sharedObject = this.runtime.createChannel(key, sharedObjectFactory.type);
67
68
  this.root.set(key, sharedObject.handle);
68
69
  });
@@ -111,13 +112,14 @@ export class TestFluidObjectFactory {
111
112
  }
112
113
  /**
113
114
  * Creates a new TestFluidObjectFactory.
114
- * @param factoryEntries - A list of id to IChannelFactory mapping. It creates a data store runtime with each
115
+ * @param initialSharedObjectsFactories - A list of id to IChannelFactory mapping. It creates a data store runtime with each
115
116
  * IChannelFactory. Entries with string ids are passed to the Fluid object so that it can create a shared object
116
117
  * for it.
117
118
  */
118
- constructor(factoryEntries, type = "TestFluidObjectFactory") {
119
- this.factoryEntries = factoryEntries;
119
+ constructor(initialSharedObjectsFactories, type = "TestFluidObjectFactory", dataObjectKind = TestFluidObject) {
120
+ this.initialSharedObjectsFactories = initialSharedObjectsFactories;
120
121
  this.type = type;
122
+ this.dataObjectKind = dataObjectKind;
121
123
  }
122
124
  async instantiateDataStore(context, existing) {
123
125
  const dataTypes = new Map();
@@ -125,28 +127,29 @@ export class TestFluidObjectFactory {
125
127
  const sharedMapFactory = SharedMap.getFactory();
126
128
  dataTypes.set(sharedMapFactory.type, sharedMapFactory);
127
129
  // Add the object factories to the list to be sent to data store runtime.
128
- for (const [, factory] of this.factoryEntries) {
130
+ for (const [, factory] of this.initialSharedObjectsFactories) {
129
131
  dataTypes.set(factory.type, factory);
130
132
  }
131
133
  // Create a map from the factory entries with entries that don't have the id as undefined. This will be
132
134
  // passed to the Fluid object.
133
135
  const factoryEntriesMapForObject = new Map();
134
- for (const [id, factory] of this.factoryEntries) {
136
+ for (const [id, factory] of this.initialSharedObjectsFactories) {
135
137
  if (id !== undefined) {
138
+ // Here we assume the factory produces an ISharedObject.
136
139
  factoryEntriesMapForObject.set(id, factory);
137
140
  }
138
141
  }
139
142
  const runtimeClass = mixinRequestHandler(async (request, rt) => {
140
143
  // The provideEntryPoint callback below always returns TestFluidObject.
141
144
  const dataObject = await rt.entryPoint.get();
142
- assert(dataObject instanceof TestFluidObject, "entryPoint should have been initialized by now");
145
+ assert(dataObject instanceof this.dataObjectKind, "entryPoint should have been initialized by now");
143
146
  return dataObject.request(request);
144
147
  });
145
148
  const runtime = new runtimeClass(context, dataTypes, existing, async () => {
146
149
  await instance.initialize(true);
147
150
  return instance;
148
151
  });
149
- const instance = new TestFluidObject(runtime, // runtime
152
+ const instance = new this.dataObjectKind(runtime, // runtime
150
153
  runtime, // channel
151
154
  context, factoryEntriesMapForObject);
152
155
  if (!existing) {
@@ -1 +1 @@
1
- {"version":3,"file":"testFluidObject.js","sourceRoot":"","sources":["../src/testFluidObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAEN,iBAAiB,EACjB,mBAAmB,GACnB,MAAM,oCAAoC,CAAC;AAK5C,OAAO,EAAc,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAMrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAI3E;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAC3B,IAAW,gBAAgB;QAC1B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAW,cAAc;QACxB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAMD;;;;;;OAMG;IACH,YACiB,OAA+B,EAC/B,OAA+B,EAC/B,OAA+B,EAC9B,iBAA+C;QAHhD,YAAO,GAAP,OAAO,CAAwB;QAC/B,YAAO,GAAP,OAAO,CAAwB;QAC/B,YAAO,GAAP,OAAO,CAAwB;QAC9B,sBAAiB,GAAjB,iBAAiB,CAA8B;QAEhE,IAAI,CAAC,WAAW,GAAG,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACnF,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,eAAe,CAAU,EAAU;QAC/C,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,C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,MAAM,YAAY,GAAG,mBAAmB,CACvC,KAAK,EAAE,OAAiB,EAAE,EAAyB,EAAE,EAAE;YACtD,uEAAuE;YACvE,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;YAC7C,MAAM,CACL,UAAU,YAAY,eAAe,EACrC,gDAAgD,CAChD,CAAC;YACF,OAAO,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC,CACD,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,IAAI,EAAE;YACzE,MAAM,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAChC,OAAO,QAAQ,CAAC;QACjB,CAAC,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAoB,IAAI,eAAe,CACpD,OAAO,EAAE,UAAU;QACnB,OAAO,EAAE,UAAU;QACnB,OAAO,EACP,0BAA0B,CAC1B,CAAC;QAEF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle, IRequest, IResponse } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tFluidDataStoreRuntime,\n\tFluidObjectHandle,\n\tmixinRequestHandler,\n} from \"@fluidframework/datastore/internal\";\nimport {\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISharedMap, SharedMap } from \"@fluidframework/map/internal\";\nimport {\n\tIFluidDataStoreChannel,\n\tIFluidDataStoreContext,\n\tIFluidDataStoreFactory,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { create404Response } from \"@fluidframework/runtime-utils/internal\";\n\nimport { ITestFluidObject } from \"./interfaces.js\";\n\n/**\n * A test Fluid object that will create a shared object for each key-value pair in the factoryEntries passed to load.\n * The shared objects can be retrieved by passing the key of the entry to getSharedObject.\n * It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.\n * @internal\n */\nexport class TestFluidObject implements ITestFluidObject {\n\tpublic get ITestFluidObject() {\n\t\treturn this;\n\t}\n\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tpublic get handle(): IFluidHandle<this> {\n\t\treturn this.innerHandle;\n\t}\n\n\tpublic root!: ISharedMap;\n\tprivate readonly innerHandle: IFluidHandle<this>;\n\tprivate initializationPromise: Promise<void> | undefined;\n\n\t/**\n\t * Creates a new TestFluidObject.\n\t * @param runtime - The data store runtime.\n\t * @param context - The data store context.\n\t * @param factoryEntries - A list of id to IChannelFactory mapping. For each item in the list,\n\t * a shared object is created which can be retrieved by calling getSharedObject() with the id;\n\t */\n\tconstructor(\n\t\tpublic readonly runtime: IFluidDataStoreRuntime,\n\t\tpublic readonly channel: IFluidDataStoreChannel,\n\t\tpublic readonly context: IFluidDataStoreContext,\n\t\tprivate readonly factoryEntriesMap: Map<string, IChannelFactory>,\n\t) {\n\t\tthis.innerHandle = new FluidObjectHandle(this, \"\", runtime.objectsRoutingContext);\n\t}\n\n\t/**\n\t * Retrieves a shared object with the given id.\n\t * @param id - The id of the shared object to retrieve.\n\t */\n\tpublic async getSharedObject<T = any>(id: string): Promise<T> {\n\t\tif (this.factoryEntriesMap === undefined) {\n\t\t\tthrow new Error(\"Shared objects were not provided during creation.\");\n\t\t}\n\n\t\tif (this.factoryEntriesMap.has(id)) {\n\t\t\tconst handle = this.root.get<IFluidHandle<T>>(id);\n\t\t\tif (handle === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Shared object with id '${id}' is in factoryEntriesMap but not found under root.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn handle.get();\n\t\t}\n\n\t\tthrow new Error(`Shared object with id ${id} not found.`);\n\t}\n\n\tpublic async request(request: IRequest): Promise<IResponse> {\n\t\treturn request.url === \"\" || request.url === \"/\" || request.url.startsWith(\"/?\")\n\t\t\t? { mimeType: \"fluid/object\", status: 200, value: this }\n\t\t\t: create404Response(request);\n\t}\n\n\tpublic async initialize(existing: boolean) {\n\t\tconst doInitialization = async () => {\n\t\t\tif (!existing) {\n\t\t\t\tthis.root = SharedMap.create(this.runtime, \"root\");\n\n\t\t\t\tthis.factoryEntriesMap.forEach((sharedObjectFactory: IChannelFactory, key: string) => {\n\t\t\t\t\tconst sharedObject = this.runtime.createChannel(key, sharedObjectFactory.type);\n\t\t\t\t\tthis.root.set(key, sharedObject.handle);\n\t\t\t\t});\n\n\t\t\t\tthis.root.bindToContext();\n\t\t\t}\n\n\t\t\tthis.root = (await this.runtime.getChannel(\"root\")) as ISharedMap;\n\t\t};\n\n\t\tthis.initializationPromise ??= doInitialization();\n\t\treturn this.initializationPromise;\n\t}\n}\n\n/**\n * Iterable\\<[ChannelId, IChannelFactory]\\>.\n * @internal\n */\nexport type ChannelFactoryRegistry = Iterable<[string | undefined, IChannelFactory]>;\n\n/**\n * Creates a factory for a TestFluidObject with the given object factory entries. It creates a data store runtime\n * with the object factories in the entry list. All the entries with an id other than undefined are passed to the\n * Fluid object so that it can create a shared object for each.\n *\n * @example\n *\n * The following will create a Fluid object that creates and loads a SharedString and SharedDirectory.\n * It will add SparseMatrix to the data store's factory so that it can be created later.\n *\n * ```typescript\n * new TestFluidObjectFactory([\n * [ \"sharedString\", SharedString.getFactory() ],\n * [ \"sharedDirectory\", SharedDirectory.getFactory() ],\n * [ undefined, SparseMatrix.getFactory() ],\n * ]);\n * ```\n *\n * The SharedString and SharedDirectory can be retrieved via getSharedObject() on the TestFluidObject as follows:\n *\n * ```typescript\n * sharedString = testFluidObject.getSharedObject<SharedString>(\"sharedString\");\n * sharedDir = testFluidObject.getSharedObject<SharedDirectory>(\"sharedDirectory\");\n * ```\n *\n * @privateRemarks Beware that using this class generally forfeits some compatibility coverage\n * `describeCompat` aims to provide:\n * `SharedMap`s always reference the current version of SharedMap.\n * AB#4670 tracks improving this situation.\n * @internal\n */\nexport class TestFluidObjectFactory implements IFluidDataStoreFactory {\n\tpublic get IFluidDataStoreFactory() {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates a new TestFluidObjectFactory.\n\t * @param factoryEntries - A list of id to IChannelFactory mapping. It creates a data store runtime with each\n\t * IChannelFactory. Entries with string ids are passed to the Fluid object so that it can create a shared object\n\t * for it.\n\t */\n\tconstructor(\n\t\tprivate readonly factoryEntries: ChannelFactoryRegistry,\n\t\tpublic readonly type = \"TestFluidObjectFactory\",\n\t) {}\n\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<FluidDataStoreRuntime> {\n\t\tconst dataTypes = new Map<string, IChannelFactory>();\n\n\t\t// Add SharedMap's factory which will be used to create the root map.\n\t\tconst sharedMapFactory = SharedMap.getFactory();\n\t\tdataTypes.set(sharedMapFactory.type, sharedMapFactory);\n\n\t\t// Add the object factories to the list to be sent to data store runtime.\n\t\tfor (const [, factory] of this.factoryEntries) {\n\t\t\tdataTypes.set(factory.type, factory);\n\t\t}\n\n\t\t// Create a map from the factory entries with entries that don't have the id as undefined. This will be\n\t\t// passed to the Fluid object.\n\t\tconst factoryEntriesMapForObject = new Map<string, IChannelFactory>();\n\t\tfor (const [id, factory] of this.factoryEntries) {\n\t\t\tif (id !== undefined) {\n\t\t\t\tfactoryEntriesMapForObject.set(id, factory);\n\t\t\t}\n\t\t}\n\n\t\tconst runtimeClass = mixinRequestHandler(\n\t\t\tasync (request: IRequest, rt: FluidDataStoreRuntime) => {\n\t\t\t\t// The provideEntryPoint callback below always returns TestFluidObject.\n\t\t\t\tconst dataObject = await rt.entryPoint.get();\n\t\t\t\tassert(\n\t\t\t\t\tdataObject instanceof TestFluidObject,\n\t\t\t\t\t\"entryPoint should have been initialized by now\",\n\t\t\t\t);\n\t\t\t\treturn dataObject.request(request);\n\t\t\t},\n\t\t);\n\n\t\tconst runtime = new runtimeClass(context, dataTypes, existing, async () => {\n\t\t\tawait instance.initialize(true);\n\t\t\treturn instance;\n\t\t});\n\n\t\tconst instance: TestFluidObject = new TestFluidObject(\n\t\t\truntime, // runtime\n\t\t\truntime, // channel\n\t\t\tcontext,\n\t\t\tfactoryEntriesMapForObject,\n\t\t);\n\n\t\tif (!existing) {\n\t\t\tawait instance.initialize(false);\n\t\t}\n\n\t\treturn runtime;\n\t}\n}\n"]}
1
+ {"version":3,"file":"testFluidObject.js","sourceRoot":"","sources":["../src/testFluidObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAEN,iBAAiB,EACjB,mBAAmB,GACnB,MAAM,oCAAoC,CAAC;AAK5C,OAAO,EAAc,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAMrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAK3E;;;;;;;;;GASG;AACH,MAAM,OAAO,eAAe;IAC3B,IAAW,gBAAgB;QAC1B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAW,cAAc;QACxB,OAAO,IAAI,CAAC;IACb,CAAC;IAOD;;;;;;OAMG;IACH,YACiB,OAA+B,EAC/B,OAA+B,EAC/B,OAA+B,EAC9B,6BAGhB;QANe,YAAO,GAAP,OAAO,CAAwB;QAC/B,YAAO,GAAP,OAAO,CAAwB;QAC/B,YAAO,GAAP,OAAO,CAAwB;QAC9B,kCAA6B,GAA7B,6BAA6B,CAG7C;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC9E,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,eAAe,CAAU,EAAU;QAC/C,IAAI,IAAI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AG,EAA0C,CAAC;QACrF,KAAK,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,6BAA6B,EAAE,CAAC;YAChE,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;gBACtB,wDAAwD;gBACxD,0BAA0B,CAAC,GAAG,CAAC,EAAE,EAAE,OAAyC,CAAC,CAAC;YAC/E,CAAC;QACF,CAAC;QAED,MAAM,YAAY,GAAG,mBAAmB,CACvC,KAAK,EAAE,OAAiB,EAAE,EAAyB,EAAE,EAAE;YACtD,uEAAuE;YACvE,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;YAC7C,MAAM,CACL,UAAU,YAAY,IAAI,CAAC,cAAc,EACzC,gDAAgD,CAChD,CAAC;YACF,OAAO,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC,CACD,CAAC;QAEF,MAAM,OAAO,GAA0B,IAAI,YAAY,CACtD,OAAO,EACP,SAAS,EACT,QAAQ,EACR,KAAK,IAAI,EAAE;YACV,MAAM,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAChC,OAAO,QAAQ,CAAC;QACjB,CAAC,CACD,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,cAAc,CACvC,OAAO,EAAE,UAAU;QACnB,OAAO,EAAE,UAAU;QACnB,OAAO,EACP,0BAA0B,CAC1B,CAAC;QAEF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIFluidHandle,\n\tIRequest,\n\tIResponse,\n\ttype IFluidLoadable,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tFluidDataStoreRuntime,\n\tFluidObjectHandle,\n\tmixinRequestHandler,\n} from \"@fluidframework/datastore/internal\";\nimport {\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISharedMap, SharedMap } from \"@fluidframework/map/internal\";\nimport {\n\tIFluidDataStoreChannel,\n\tIFluidDataStoreContext,\n\tIFluidDataStoreFactory,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { create404Response } from \"@fluidframework/runtime-utils/internal\";\nimport type { ISharedObject } from \"@fluidframework/shared-object-base/internal\";\n\nimport { ITestFluidObject } from \"./interfaces.js\";\n\n/**\n * A test Fluid object that will create a shared object for each key-value pair in the initialSharedObjectsFactories passed to load.\n * The shared objects can be retrieved by passing the key of the entry to getSharedObject.\n * It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.\n * @privateRemarks\n * TODO:\n * Usage of this outside this repo (via ITestFluidObject) should probably be phased out.\n * Once thats done, ITestFluidObject can be made internal and this class can be replaced with the simplified TestFluidObjectInternal.\n * @internal\n */\nexport class TestFluidObject implements ITestFluidObject {\n\tpublic get ITestFluidObject() {\n\t\treturn this;\n\t}\n\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tpublic readonly handle: IFluidHandle<this>;\n\n\tpublic root!: ISharedMap;\n\tprivate initializationPromise: Promise<void> | undefined;\n\n\t/**\n\t * Creates a new TestFluidObject.\n\t * @param runtime - The data store runtime.\n\t * @param context - The data store context.\n\t * @param initialSharedObjectsFactories - A list of id to IChannelFactory mapping. For each item in the list,\n\t * a shared object is created which can be retrieved by calling getSharedObject() with the id;\n\t */\n\tconstructor(\n\t\tpublic readonly runtime: IFluidDataStoreRuntime,\n\t\tpublic readonly channel: IFluidDataStoreChannel,\n\t\tpublic readonly context: IFluidDataStoreContext,\n\t\tprivate readonly initialSharedObjectsFactories: ReadonlyMap<\n\t\t\tstring,\n\t\t\tIChannelFactory<ISharedObject>\n\t\t>,\n\t) {\n\t\tthis.handle = new FluidObjectHandle(this, \"\", runtime.objectsRoutingContext);\n\t}\n\n\t/**\n\t * Retrieves a shared object with the given id.\n\t * @param id - The id of the shared object to retrieve.\n\t */\n\tpublic async getSharedObject<T = any>(id: string): Promise<T> {\n\t\tif (this.initialSharedObjectsFactories === undefined) {\n\t\t\tthrow new Error(\"Shared objects were not provided during creation.\");\n\t\t}\n\n\t\tif (this.initialSharedObjectsFactories.has(id)) {\n\t\t\tconst handle = this.root.get<IFluidHandle<T>>(id);\n\t\t\tif (handle === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Shared object with id '${id}' is in initialSharedObjectsFactories but not found under root.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn handle.get();\n\t\t}\n\n\t\tthrow new Error(`Shared object with id ${id} not found.`);\n\t}\n\n\tpublic async request(request: IRequest): Promise<IResponse> {\n\t\treturn request.url === \"\" || request.url === \"/\" || request.url.startsWith(\"/?\")\n\t\t\t? { mimeType: \"fluid/object\", status: 200, value: this }\n\t\t\t: create404Response(request);\n\t}\n\n\tpublic async initialize(existing: boolean) {\n\t\tconst doInitialization = async () => {\n\t\t\tif (!existing) {\n\t\t\t\tthis.root = SharedMap.create(this.runtime, \"root\");\n\n\t\t\t\tthis.initialSharedObjectsFactories.forEach(\n\t\t\t\t\t(sharedObjectFactory: IChannelFactory, key: string) => {\n\t\t\t\t\t\tconst sharedObject = this.runtime.createChannel(key, sharedObjectFactory.type);\n\t\t\t\t\t\tthis.root.set(key, sharedObject.handle);\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tthis.root.bindToContext();\n\t\t\t}\n\n\t\t\tthis.root = (await this.runtime.getChannel(\"root\")) as ISharedMap;\n\t\t};\n\n\t\tthis.initializationPromise ??= doInitialization();\n\t\treturn this.initializationPromise;\n\t}\n}\n\n/**\n * Iterable\\<[ChannelId, IChannelFactory]\\>.\n * @internal\n */\nexport type ChannelFactoryRegistry = Iterable<[string | undefined, IChannelFactory]>;\n\n/**\n * Kind of test data object which {@link TestFluidObjectFactory} can create.\n * @internal\n */\nexport type TestDataObjectKind = new (\n\truntime: IFluidDataStoreRuntime,\n\tchannel: IFluidDataStoreChannel,\n\tcontext: IFluidDataStoreContext,\n\tinitialSharedObjectsFactories: ReadonlyMap<string, IChannelFactory<ISharedObject>>,\n) => IFluidLoadable & {\n\trequest(request: IRequest): Promise<IResponse>;\n\tinitialize(existing: boolean): Promise<void>;\n};\n\n/**\n * Creates a factory for a TestFluidObject with the given object factory entries. It creates a data store runtime\n * with the object factories in the entry list. All the entries with an id other than undefined are passed to the\n * Fluid object so that it can create a shared object for each.\n *\n * @example\n *\n * The following will create a Fluid object that creates and loads a SharedString and SharedDirectory.\n * It will add SparseMatrix to the data store's factory so that it can be created later.\n *\n * ```typescript\n * new TestFluidObjectFactory([\n * [ \"sharedString\", SharedString.getFactory() ],\n * [ \"sharedDirectory\", SharedDirectory.getFactory() ],\n * [ undefined, SparseMatrix.getFactory() ],\n * ]);\n * ```\n *\n * The SharedString and SharedDirectory can be retrieved via getSharedObject() on the TestFluidObject as follows:\n *\n * ```typescript\n * sharedString = testFluidObject.getSharedObject<SharedString>(\"sharedString\");\n * sharedDir = testFluidObject.getSharedObject<SharedDirectory>(\"sharedDirectory\");\n * ```\n *\n * @privateRemarks Beware that using this class generally forfeits some compatibility coverage\n * `describeCompat` aims to provide:\n * `SharedMap`s always reference the current version of SharedMap.\n * AB#4670 tracks improving this situation.\n * @internal\n */\nexport class TestFluidObjectFactory implements IFluidDataStoreFactory {\n\tpublic get IFluidDataStoreFactory() {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates a new TestFluidObjectFactory.\n\t * @param initialSharedObjectsFactories - A list of id to IChannelFactory mapping. It creates a data store runtime with each\n\t * IChannelFactory. Entries with string ids are passed to the Fluid object so that it can create a shared object\n\t * for it.\n\t */\n\tconstructor(\n\t\tprivate readonly initialSharedObjectsFactories: ChannelFactoryRegistry,\n\t\tpublic readonly type = \"TestFluidObjectFactory\",\n\t\tprivate readonly dataObjectKind: TestDataObjectKind = TestFluidObject,\n\t) {}\n\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<FluidDataStoreRuntime> {\n\t\tconst dataTypes = new Map<string, IChannelFactory>();\n\n\t\t// Add SharedMap's factory which will be used to create the root map.\n\t\tconst sharedMapFactory = SharedMap.getFactory();\n\t\tdataTypes.set(sharedMapFactory.type, sharedMapFactory);\n\n\t\t// Add the object factories to the list to be sent to data store runtime.\n\t\tfor (const [, factory] of this.initialSharedObjectsFactories) {\n\t\t\tdataTypes.set(factory.type, factory);\n\t\t}\n\n\t\t// Create a map from the factory entries with entries that don't have the id as undefined. This will be\n\t\t// passed to the Fluid object.\n\t\tconst factoryEntriesMapForObject = new Map<string, IChannelFactory<ISharedObject>>();\n\t\tfor (const [id, factory] of this.initialSharedObjectsFactories) {\n\t\t\tif (id !== undefined) {\n\t\t\t\t// Here we assume the factory produces an ISharedObject.\n\t\t\t\tfactoryEntriesMapForObject.set(id, factory as IChannelFactory<ISharedObject>);\n\t\t\t}\n\t\t}\n\n\t\tconst runtimeClass = mixinRequestHandler(\n\t\t\tasync (request: IRequest, rt: FluidDataStoreRuntime) => {\n\t\t\t\t// The provideEntryPoint callback below always returns TestFluidObject.\n\t\t\t\tconst dataObject = await rt.entryPoint.get();\n\t\t\t\tassert(\n\t\t\t\t\tdataObject instanceof this.dataObjectKind,\n\t\t\t\t\t\"entryPoint should have been initialized by now\",\n\t\t\t\t);\n\t\t\t\treturn dataObject.request(request);\n\t\t\t},\n\t\t);\n\n\t\tconst runtime: FluidDataStoreRuntime = new runtimeClass(\n\t\t\tcontext,\n\t\t\tdataTypes,\n\t\t\texisting,\n\t\t\tasync () => {\n\t\t\t\tawait instance.initialize(true);\n\t\t\t\treturn instance;\n\t\t\t},\n\t\t);\n\n\t\tconst instance = new this.dataObjectKind(\n\t\t\truntime, // runtime\n\t\t\truntime, // channel\n\t\t\tcontext,\n\t\t\tfactoryEntriesMapForObject,\n\t\t);\n\n\t\tif (!existing) {\n\t\t\tawait instance.initialize(false);\n\t\t}\n\n\t\treturn runtime;\n\t}\n}\n"]}
@@ -0,0 +1,50 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IFluidHandle, IRequest, IResponse, type IFluidLoadable } from "@fluidframework/core-interfaces";
6
+ import { IChannelFactory, IFluidDataStoreRuntime, type IChannel } from "@fluidframework/datastore-definitions/internal";
7
+ import { IFluidDataStoreChannel, IFluidDataStoreContext } from "@fluidframework/runtime-definitions/internal";
8
+ import type { ISharedObject, SharedObjectKind } from "@fluidframework/shared-object-base/internal";
9
+ /**
10
+ * A test Fluid object that will create a shared object for each key-value pair in the factoryEntries passed to load.
11
+ * The shared objects can be retrieved by passing the key of the entry to {@link TestFluidObjectInternal.getInitialSharedObject}.
12
+ * It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.
13
+ * @remarks
14
+ * This is a simplified (does not use SharedMap) alternative to {@link TestFluidObject} which does not implement the external facing {@link ITestFluidObject} interface.
15
+ * @internal
16
+ */
17
+ export declare class TestFluidObjectInternal implements IFluidLoadable {
18
+ readonly runtime: IFluidDataStoreRuntime;
19
+ readonly channel: IFluidDataStoreChannel;
20
+ readonly context: IFluidDataStoreContext;
21
+ private readonly initialSharedObjectsFactories;
22
+ get IFluidLoadable(): this;
23
+ readonly handle: IFluidHandle<this>;
24
+ private initializationPromise;
25
+ /**
26
+ * Creates a new TestFluidObjectInternal.
27
+ * @param runtime - The data store runtime.
28
+ * @param context - The data store context.
29
+ * @param factoryEntries - A list of id to IChannelFactory mapping. For each item in the list,
30
+ * a shared object is created which can be retrieved by calling {@link TestFluidObjectInternal.getInitialSharedObject} with the id;
31
+ * @param initialSharedObjectsFactories - A collection of ids (which can be passed to {@link TestFluidObjectInternal.getInitialSharedObject})
32
+ * and the corresponding factories to use to create the shared objects during initialization.
33
+ */
34
+ constructor(runtime: IFluidDataStoreRuntime, channel: IFluidDataStoreChannel, context: IFluidDataStoreContext, initialSharedObjectsFactories: ReadonlyMap<string, IChannelFactory<ISharedObject>>);
35
+ /**
36
+ * Retrieves the shared object with the given id:
37
+ * this id must have been a key included in the initialSharedObjectsFactories map passed to the constructor.
38
+ * @param id - The id of the shared object to retrieve.
39
+ */
40
+ getInitialSharedObject(id: string): Promise<IChannel>;
41
+ /**
42
+ * Retrieves a shared object with the given id.
43
+ * @param kind - The kind of object to retrieve.
44
+ * @param id - The id of the shared object to retrieve.
45
+ */
46
+ getInitialSharedObjectTyped<T>(kind: SharedObjectKind<T>, id: string): Promise<IChannel & T>;
47
+ request(request: IRequest): Promise<IResponse>;
48
+ initialize(existing: boolean): Promise<void>;
49
+ }
50
+ //# sourceMappingURL=testFluidObjectInternal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testFluidObjectInternal.d.ts","sourceRoot":"","sources":["../src/testFluidObjectInternal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,KAAK,cAAc,EACnB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EACN,eAAe,EACf,sBAAsB,EACtB,KAAK,QAAQ,EACb,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,KAAK,EACX,aAAa,EACb,gBAAgB,EAChB,MAAM,6CAA6C,CAAC;AAErD;;;;;;;GAOG;AACH,qBAAa,uBAAwB,YAAW,cAAc;aAkB5C,OAAO,EAAE,sBAAsB;aAC/B,OAAO,EAAE,sBAAsB;aAC/B,OAAO,EAAE,sBAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAC,6BAA6B;IApB/C,IAAW,cAAc,SAExB;IAED,SAAgB,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,CAAC,qBAAqB,CAA4B;IAEzD;;;;;;;;OAQG;gBAEc,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,sBAAsB,EAC9B,6BAA6B,EAAE,WAAW,CAC1D,MAAM,EACN,eAAe,CAAC,aAAa,CAAC,CAC9B;IAKF;;;;OAIG;IACU,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIlE;;;;OAIG;IACU,2BAA2B,CAAC,CAAC,EACzC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,EAAE,EAAE,MAAM,GACR,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IAQX,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAM9C,UAAU,CAAC,QAAQ,EAAE,OAAO;CAazC"}
@@ -0,0 +1,74 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { fail } from "@fluidframework/core-utils/internal";
6
+ import { FluidObjectHandle } from "@fluidframework/datastore/internal";
7
+ import { create404Response } from "@fluidframework/runtime-utils/internal";
8
+ /**
9
+ * A test Fluid object that will create a shared object for each key-value pair in the factoryEntries passed to load.
10
+ * The shared objects can be retrieved by passing the key of the entry to {@link TestFluidObjectInternal.getInitialSharedObject}.
11
+ * It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.
12
+ * @remarks
13
+ * This is a simplified (does not use SharedMap) alternative to {@link TestFluidObject} which does not implement the external facing {@link ITestFluidObject} interface.
14
+ * @internal
15
+ */
16
+ export class TestFluidObjectInternal {
17
+ get IFluidLoadable() {
18
+ return this;
19
+ }
20
+ /**
21
+ * Creates a new TestFluidObjectInternal.
22
+ * @param runtime - The data store runtime.
23
+ * @param context - The data store context.
24
+ * @param factoryEntries - A list of id to IChannelFactory mapping. For each item in the list,
25
+ * a shared object is created which can be retrieved by calling {@link TestFluidObjectInternal.getInitialSharedObject} with the id;
26
+ * @param initialSharedObjectsFactories - A collection of ids (which can be passed to {@link TestFluidObjectInternal.getInitialSharedObject})
27
+ * and the corresponding factories to use to create the shared objects during initialization.
28
+ */
29
+ constructor(runtime, channel, context, initialSharedObjectsFactories) {
30
+ this.runtime = runtime;
31
+ this.channel = channel;
32
+ this.context = context;
33
+ this.initialSharedObjectsFactories = initialSharedObjectsFactories;
34
+ this.handle = new FluidObjectHandle(this, "", runtime.objectsRoutingContext);
35
+ }
36
+ /**
37
+ * Retrieves the shared object with the given id:
38
+ * this id must have been a key included in the initialSharedObjectsFactories map passed to the constructor.
39
+ * @param id - The id of the shared object to retrieve.
40
+ */
41
+ async getInitialSharedObject(id) {
42
+ return (await this.runtime.getChannel(id)) ?? fail("Shared object not found");
43
+ }
44
+ /**
45
+ * Retrieves a shared object with the given id.
46
+ * @param kind - The kind of object to retrieve.
47
+ * @param id - The id of the shared object to retrieve.
48
+ */
49
+ async getInitialSharedObjectTyped(kind, id) {
50
+ const result = (await this.runtime.getChannel(id)) ?? fail("Shared object not found");
51
+ if (kind.is(result)) {
52
+ return result;
53
+ }
54
+ return fail("Wrong kind of shared object");
55
+ }
56
+ async request(request) {
57
+ return request.url === "" || request.url === "/" || request.url.startsWith("/?")
58
+ ? { mimeType: "fluid/object", status: 200, value: this }
59
+ : create404Response(request);
60
+ }
61
+ async initialize(existing) {
62
+ const doInitialization = async () => {
63
+ if (!existing) {
64
+ for (const [key, sharedObjectFactory] of this.initialSharedObjectsFactories) {
65
+ const channel = this.runtime.createChannel(key, sharedObjectFactory.type);
66
+ channel.bindToContext();
67
+ }
68
+ }
69
+ };
70
+ this.initializationPromise ??= doInitialization();
71
+ return this.initializationPromise;
72
+ }
73
+ }
74
+ //# sourceMappingURL=testFluidObjectInternal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testFluidObjectInternal.js","sourceRoot":"","sources":["../src/testFluidObjectInternal.ts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AAI,OAAO,CAAC,GAAG,KAAK,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;YAC/E,CAAC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE;YACxD,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,QAAiB;QACxC,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;YACnC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACf,KAAK,MAAM,CAAC,GAAG,EAAE,mBAAmB,CAAC,IAAI,IAAI,CAAC,6BAA6B,EAAE,CAAC;oBAC7E,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;oBACzE,OAAyB,CAAC,aAAa,EAAE,CAAC;gBAC5C,CAAC;YACF,CAAC;QACF,CAAC,CAAC;QAEF,IAAI,CAAC,qBAAqB,KAAK,gBAAgB,EAAE,CAAC;QAClD,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACnC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tIFluidHandle,\n\tIRequest,\n\tIResponse,\n\ttype IFluidLoadable,\n} from \"@fluidframework/core-interfaces\";\nimport { fail } from \"@fluidframework/core-utils/internal\";\nimport { FluidObjectHandle } from \"@fluidframework/datastore/internal\";\nimport {\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\ttype IChannel,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tIFluidDataStoreChannel,\n\tIFluidDataStoreContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { create404Response } from \"@fluidframework/runtime-utils/internal\";\nimport type {\n\tISharedObject,\n\tSharedObjectKind,\n} from \"@fluidframework/shared-object-base/internal\";\n\n/**\n * A test Fluid object that will create a shared object for each key-value pair in the factoryEntries passed to load.\n * The shared objects can be retrieved by passing the key of the entry to {@link TestFluidObjectInternal.getInitialSharedObject}.\n * It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.\n * @remarks\n * This is a simplified (does not use SharedMap) alternative to {@link TestFluidObject} which does not implement the external facing {@link ITestFluidObject} interface.\n * @internal\n */\nexport class TestFluidObjectInternal implements IFluidLoadable {\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tpublic readonly handle: IFluidHandle<this>;\n\tprivate initializationPromise: Promise<void> | undefined;\n\n\t/**\n\t * Creates a new TestFluidObjectInternal.\n\t * @param runtime - The data store runtime.\n\t * @param context - The data store context.\n\t * @param factoryEntries - A list of id to IChannelFactory mapping. For each item in the list,\n\t * a shared object is created which can be retrieved by calling {@link TestFluidObjectInternal.getInitialSharedObject} with the id;\n\t * @param initialSharedObjectsFactories - A collection of ids (which can be passed to {@link TestFluidObjectInternal.getInitialSharedObject})\n\t * and the corresponding factories to use to create the shared objects during initialization.\n\t */\n\tconstructor(\n\t\tpublic readonly runtime: IFluidDataStoreRuntime,\n\t\tpublic readonly channel: IFluidDataStoreChannel,\n\t\tpublic readonly context: IFluidDataStoreContext,\n\t\tprivate readonly initialSharedObjectsFactories: ReadonlyMap<\n\t\t\tstring,\n\t\t\tIChannelFactory<ISharedObject>\n\t\t>,\n\t) {\n\t\tthis.handle = new FluidObjectHandle(this, \"\", runtime.objectsRoutingContext);\n\t}\n\n\t/**\n\t * Retrieves the shared object with the given id:\n\t * this id must have been a key included in the initialSharedObjectsFactories map passed to the constructor.\n\t * @param id - The id of the shared object to retrieve.\n\t */\n\tpublic async getInitialSharedObject(id: string): Promise<IChannel> {\n\t\treturn (await this.runtime.getChannel(id)) ?? fail(\"Shared object not found\");\n\t}\n\n\t/**\n\t * Retrieves a shared object with the given id.\n\t * @param kind - The kind of object to retrieve.\n\t * @param id - The id of the shared object to retrieve.\n\t */\n\tpublic async getInitialSharedObjectTyped<T>(\n\t\tkind: SharedObjectKind<T>,\n\t\tid: string,\n\t): Promise<IChannel & T> {\n\t\tconst result = (await this.runtime.getChannel(id)) ?? fail(\"Shared object not found\");\n\t\tif (kind.is(result)) {\n\t\t\treturn result;\n\t\t}\n\t\treturn fail(\"Wrong kind of shared object\");\n\t}\n\n\tpublic async request(request: IRequest): Promise<IResponse> {\n\t\treturn request.url === \"\" || request.url === \"/\" || request.url.startsWith(\"/?\")\n\t\t\t? { mimeType: \"fluid/object\", status: 200, value: this }\n\t\t\t: create404Response(request);\n\t}\n\n\tpublic async initialize(existing: boolean) {\n\t\tconst doInitialization = async () => {\n\t\t\tif (!existing) {\n\t\t\t\tfor (const [key, sharedObjectFactory] of this.initialSharedObjectsFactories) {\n\t\t\t\t\tconst channel = this.runtime.createChannel(key, sharedObjectFactory.type);\n\t\t\t\t\t(channel as ISharedObject).bindToContext();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tthis.initializationPromise ??= doInitialization();\n\t\treturn this.initializationPromise;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/test-utils",
3
- "version": "2.31.1",
3
+ "version": "2.33.0-333010",
4
4
  "description": "Utilities for Fluid tests",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -67,25 +67,26 @@
67
67
  "temp-directory": "nyc/.nyc_output"
68
68
  },
69
69
  "dependencies": {
70
- "@fluid-internal/test-driver-definitions": "~2.31.1",
71
- "@fluidframework/container-definitions": "~2.31.1",
72
- "@fluidframework/container-loader": "~2.31.1",
73
- "@fluidframework/container-runtime": "~2.31.1",
74
- "@fluidframework/container-runtime-definitions": "~2.31.1",
75
- "@fluidframework/core-interfaces": "~2.31.1",
76
- "@fluidframework/core-utils": "~2.31.1",
77
- "@fluidframework/datastore": "~2.31.1",
78
- "@fluidframework/datastore-definitions": "~2.31.1",
79
- "@fluidframework/driver-definitions": "~2.31.1",
80
- "@fluidframework/driver-utils": "~2.31.1",
81
- "@fluidframework/local-driver": "~2.31.1",
82
- "@fluidframework/map": "~2.31.1",
83
- "@fluidframework/odsp-driver": "~2.31.1",
84
- "@fluidframework/request-handler": "~2.31.1",
85
- "@fluidframework/routerlicious-driver": "~2.31.1",
86
- "@fluidframework/runtime-definitions": "~2.31.1",
87
- "@fluidframework/runtime-utils": "~2.31.1",
88
- "@fluidframework/telemetry-utils": "~2.31.1",
70
+ "@fluid-internal/test-driver-definitions": "2.33.0-333010",
71
+ "@fluidframework/container-definitions": "2.33.0-333010",
72
+ "@fluidframework/container-loader": "2.33.0-333010",
73
+ "@fluidframework/container-runtime": "2.33.0-333010",
74
+ "@fluidframework/container-runtime-definitions": "2.33.0-333010",
75
+ "@fluidframework/core-interfaces": "2.33.0-333010",
76
+ "@fluidframework/core-utils": "2.33.0-333010",
77
+ "@fluidframework/datastore": "2.33.0-333010",
78
+ "@fluidframework/datastore-definitions": "2.33.0-333010",
79
+ "@fluidframework/driver-definitions": "2.33.0-333010",
80
+ "@fluidframework/driver-utils": "2.33.0-333010",
81
+ "@fluidframework/local-driver": "2.33.0-333010",
82
+ "@fluidframework/map": "2.33.0-333010",
83
+ "@fluidframework/odsp-driver": "2.33.0-333010",
84
+ "@fluidframework/request-handler": "2.33.0-333010",
85
+ "@fluidframework/routerlicious-driver": "2.33.0-333010",
86
+ "@fluidframework/runtime-definitions": "2.33.0-333010",
87
+ "@fluidframework/runtime-utils": "2.33.0-333010",
88
+ "@fluidframework/shared-object-base": "2.33.0-333010",
89
+ "@fluidframework/telemetry-utils": "2.33.0-333010",
89
90
  "best-random": "^1.0.0",
90
91
  "debug": "^4.3.4",
91
92
  "mocha": "^10.8.2",
@@ -94,10 +95,10 @@
94
95
  "devDependencies": {
95
96
  "@arethetypeswrong/cli": "^0.17.1",
96
97
  "@biomejs/biome": "~1.9.3",
97
- "@fluid-internal/mocha-test-setup": "~2.31.1",
98
- "@fluid-tools/build-cli": "^0.54.0",
98
+ "@fluid-internal/mocha-test-setup": "2.33.0-333010",
99
+ "@fluid-tools/build-cli": "^0.55.0",
99
100
  "@fluidframework/build-common": "^2.0.3",
100
- "@fluidframework/build-tools": "^0.54.0",
101
+ "@fluidframework/build-tools": "^0.55.0",
101
102
  "@fluidframework/eslint-config-fluid": "^5.7.3",
102
103
  "@fluidframework/test-utils-previous": "npm:@fluidframework/test-utils@2.31.0",
103
104
  "@microsoft/api-extractor": "7.50.1",
package/src/index.ts CHANGED
@@ -26,6 +26,7 @@ export {
26
26
  ChannelFactoryRegistry,
27
27
  TestFluidObject,
28
28
  TestFluidObjectFactory,
29
+ TestDataObjectKind,
29
30
  } from "./testFluidObject.js";
30
31
  export {
31
32
  createDocumentId,
@@ -65,3 +66,5 @@ export {
65
66
  type ContainerRuntimeFactoryWithDefaultDataStoreProps,
66
67
  createContainerRuntimeFactoryWithDefaultDataStore,
67
68
  } from "./testContainerRuntimeFactoryWithDefaultDataStore.js";
69
+
70
+ export { TestFluidObjectInternal } from "./testFluidObjectInternal.js";
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/test-utils";
9
- export const pkgVersion = "2.31.1";
9
+ export const pkgVersion = "2.33.0-333010";