@fluidframework/fluid-static 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.224419

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 (100) hide show
  1. package/.eslintrc.js +8 -10
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +225 -53
  4. package/README.md +38 -0
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +2 -2
  7. package/api-report/fluid-static.api.md +141 -0
  8. package/dist/fluid-static-alpha.d.ts +408 -0
  9. package/dist/fluid-static-beta.d.ts +412 -0
  10. package/dist/fluid-static-public.d.ts +412 -0
  11. package/dist/fluid-static-untrimmed.d.ts +452 -0
  12. package/dist/{fluidContainer.js → fluidContainer.cjs} +39 -12
  13. package/dist/fluidContainer.cjs.map +1 -0
  14. package/dist/fluidContainer.d.ts +95 -142
  15. package/dist/fluidContainer.d.ts.map +1 -1
  16. package/dist/index.cjs +19 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.ts +4 -4
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/{rootDataObject.js → rootDataObject.cjs} +59 -23
  21. package/dist/rootDataObject.cjs.map +1 -0
  22. package/dist/rootDataObject.d.ts +9 -59
  23. package/dist/rootDataObject.d.ts.map +1 -1
  24. package/dist/{serviceAudience.js → serviceAudience.cjs} +44 -20
  25. package/dist/serviceAudience.cjs.map +1 -0
  26. package/dist/serviceAudience.d.ts +7 -54
  27. package/dist/serviceAudience.d.ts.map +1 -1
  28. package/dist/tsdoc-metadata.json +11 -0
  29. package/dist/{types.js → types.cjs} +1 -1
  30. package/dist/types.cjs.map +1 -0
  31. package/dist/types.d.ts +130 -80
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/{utils.js → utils.cjs} +7 -9
  34. package/dist/utils.cjs.map +1 -0
  35. package/dist/utils.d.ts +10 -2
  36. package/dist/utils.d.ts.map +1 -1
  37. package/lib/fluid-static-alpha.d.mts +408 -0
  38. package/lib/fluid-static-beta.d.mts +412 -0
  39. package/lib/fluid-static-public.d.mts +412 -0
  40. package/lib/fluid-static-untrimmed.d.mts +452 -0
  41. package/lib/fluidContainer.d.mts +188 -0
  42. package/lib/fluidContainer.d.mts.map +1 -0
  43. package/lib/{fluidContainer.js → fluidContainer.mjs} +36 -13
  44. package/lib/fluidContainer.mjs.map +1 -0
  45. package/lib/index.d.mts +9 -0
  46. package/lib/index.d.mts.map +1 -0
  47. package/lib/index.mjs +8 -0
  48. package/lib/index.mjs.map +1 -0
  49. package/lib/rootDataObject.d.mts +20 -0
  50. package/lib/rootDataObject.d.mts.map +1 -0
  51. package/lib/{rootDataObject.js → rootDataObject.mjs} +61 -28
  52. package/lib/rootDataObject.mjs.map +1 -0
  53. package/lib/serviceAudience.d.mts +15 -0
  54. package/lib/serviceAudience.d.mts.map +1 -0
  55. package/lib/{serviceAudience.js → serviceAudience.mjs} +42 -18
  56. package/lib/serviceAudience.mjs.map +1 -0
  57. package/lib/types.d.mts +223 -0
  58. package/lib/types.d.mts.map +1 -0
  59. package/lib/{types.js → types.mjs} +1 -1
  60. package/lib/types.mjs.map +1 -0
  61. package/lib/{utils.d.ts → utils.d.mts} +11 -3
  62. package/lib/utils.d.mts.map +1 -0
  63. package/lib/{utils.js → utils.mjs} +7 -9
  64. package/lib/utils.mjs.map +1 -0
  65. package/package.json +130 -61
  66. package/prettier.config.cjs +8 -0
  67. package/src/fluidContainer.ts +316 -250
  68. package/src/index.ts +25 -4
  69. package/src/rootDataObject.ts +203 -157
  70. package/src/serviceAudience.ts +152 -124
  71. package/src/types.ts +190 -132
  72. package/src/utils.ts +44 -39
  73. package/tsc-multi.test.json +4 -0
  74. package/tsconfig.json +12 -16
  75. package/dist/fluidContainer.js.map +0 -1
  76. package/dist/index.js +0 -26
  77. package/dist/index.js.map +0 -1
  78. package/dist/rootDataObject.js.map +0 -1
  79. package/dist/serviceAudience.js.map +0 -1
  80. package/dist/types.js.map +0 -1
  81. package/dist/utils.js.map +0 -1
  82. package/lib/fluidContainer.d.ts +0 -235
  83. package/lib/fluidContainer.d.ts.map +0 -1
  84. package/lib/fluidContainer.js.map +0 -1
  85. package/lib/index.d.ts +0 -14
  86. package/lib/index.d.ts.map +0 -1
  87. package/lib/index.js +0 -14
  88. package/lib/index.js.map +0 -1
  89. package/lib/rootDataObject.d.ts +0 -70
  90. package/lib/rootDataObject.d.ts.map +0 -1
  91. package/lib/rootDataObject.js.map +0 -1
  92. package/lib/serviceAudience.d.ts +0 -62
  93. package/lib/serviceAudience.d.ts.map +0 -1
  94. package/lib/serviceAudience.js.map +0 -1
  95. package/lib/types.d.ts +0 -173
  96. package/lib/types.d.ts.map +0 -1
  97. package/lib/types.js.map +0 -1
  98. package/lib/utils.d.ts.map +0 -1
  99. package/lib/utils.js.map +0 -1
  100. package/tsconfig.esnext.json +0 -7
package/src/types.ts CHANGED
@@ -3,184 +3,242 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { IEvent, IEventProvider } from "@fluidframework/common-definitions";
7
- import { IFluidLoadable } from "@fluidframework/core-interfaces";
6
+ import { IEvent, IEventProvider, IFluidLoadable } from "@fluidframework/core-interfaces";
8
7
  import { IChannelFactory } from "@fluidframework/datastore-definitions";
9
- import { IFluidDataStoreFactory } from "@fluidframework/runtime-definitions";
10
8
 
11
9
  /**
12
- * A mapping of string identifiers to instantiated DataObjects or SharedObjects.
10
+ * A mapping of string identifiers to instantiated `DataObject`s or `SharedObject`s.
11
+ * @internal
13
12
  */
14
13
  export type LoadableObjectRecord = Record<string, IFluidLoadable>;
15
14
 
16
15
  /**
17
- * A mapping of string identifiers to classes that will later be used to instantiate a corresponding DataObject
18
- * or SharedObject in a LoadableObjectRecord.
16
+ * A mapping of string identifiers to classes that will later be used to instantiate a corresponding `DataObject`
17
+ * or `SharedObject` in a {@link LoadableObjectRecord}.
18
+ * @public
19
19
  */
20
20
  export type LoadableObjectClassRecord = Record<string, LoadableObjectClass<any>>;
21
21
 
22
22
  /**
23
- * A LoadableObjectClass is an class object of DataObject or SharedObject
24
- * @typeParam T - The class of the DataObject or SharedObject
23
+ * A class object of `DataObject` or `SharedObject`.
24
+ *
25
+ * @typeParam T - The class of the `DataObject` or `SharedObject`.
26
+ * @public
25
27
  */
26
- export type LoadableObjectClass<T extends IFluidLoadable> = DataObjectClass<T> | SharedObjectClass<T>;
28
+ export type LoadableObjectClass<T extends IFluidLoadable> =
29
+ | DataObjectClass<T>
30
+ | SharedObjectClass<T>;
27
31
 
28
32
  /**
29
- * A DataObjectClass is a class that has a factory that can create a DataObject and a
30
- * constructor that will return the type of the DataObject.
31
- * @typeParam T - The class of the DataObject
33
+ * A class that has a factory that can create a `DataObject` and a
34
+ * constructor that will return the type of the `DataObject`.
35
+ *
36
+ * @typeParam T - The class of the `DataObject`.
37
+ * @public
32
38
  */
33
- export type DataObjectClass<T extends IFluidLoadable>
34
- = { readonly factory: IFluidDataStoreFactory; } & LoadableObjectCtor<T>;
39
+ export type DataObjectClass<T extends IFluidLoadable> = {
40
+ readonly factory: { IFluidDataStoreFactory: DataObjectClass<T>["factory"] };
41
+ } & LoadableObjectCtor<T>;
35
42
 
36
43
  /**
37
- * A SharedObjectClass is a class that has a factory that can create a DDS (SharedObject) and a
38
- * constructor that will return the type of the DataObject.
39
- * @typeParam T - The class of the SharedObject
44
+ * A class that has a factory that can create a DDSes (`SharedObject`s) and a
45
+ * constructor that will return the type of the `DataObject`.
46
+ *
47
+ * @typeParam T - The class of the `SharedObject`.
48
+ * @public
40
49
  */
41
- export type SharedObjectClass<T extends IFluidLoadable>
42
- = { readonly getFactory: () => IChannelFactory; } & LoadableObjectCtor<T>;
50
+ export type SharedObjectClass<T extends IFluidLoadable> = {
51
+ readonly getFactory: () => IChannelFactory;
52
+ } & LoadableObjectCtor<T>;
43
53
 
44
54
  /**
45
- * An object with a constructor that will return an `IFluidLoadable`.
46
- * @typeParam T - The class of the loadable object
55
+ * An object with a constructor that will return an {@link @fluidframework/core-interfaces#IFluidLoadable}.
56
+ *
57
+ * @typeParam T - The class of the loadable object.
58
+ * @public
47
59
  */
48
- export type LoadableObjectCtor<T extends IFluidLoadable> = new(...args: any[]) => T;
60
+ export type LoadableObjectCtor<T extends IFluidLoadable> = new (...args: any[]) => T;
49
61
 
50
62
  /**
51
- * The ContainerSchema declares the Fluid objects that will be available in the container. It includes both the
52
- * instances of objects that are initially available upon container creation, as well as the types of objects that may
53
- * be dynamically created throughout the lifetime of the container.
63
+ * Declares the Fluid objects that will be available in the {@link IFluidContainer | Container}.
64
+ *
65
+ * @remarks
66
+ *
67
+ * It includes both the instances of objects that are initially available upon `Container` creation, as well
68
+ * as the types of objects that may be dynamically created throughout the lifetime of the `Container`.
69
+ * @public
54
70
  */
55
71
  export interface ContainerSchema {
56
- /**
57
- * Defines loadable objects that will be created when the `Container` is first created.
58
- * It uses the key as the id and the value as the loadable object to create.
59
- *
60
- * @example
61
- * In the example below two objects will be created when the Container is first
62
- * created. One with id "map1" that will return a `SharedMap` and the other with
63
- * id "pair1" that will return a `KeyValueDataObject`.
64
- *
65
- * ```
66
- * {
67
- * map1: SharedMap,
68
- * pair1: KeyValueDataObject,
69
- * }
70
- * ```
71
- */
72
- initialObjects: LoadableObjectClassRecord;
73
-
74
- /**
75
- * Dynamic objects are Loadable objects that can be created after the initial Container creation.
76
- *
77
- * Types defined in `initialObjects` will always be available and are not required to be provided here.
78
- *
79
- * For best practice it's recommended to define all the dynamic types you create even if they are
80
- * included via initialObjects.
81
- */
82
- dynamicObjectTypes?: LoadableObjectClass<any>[];
72
+ /**
73
+ * Defines loadable objects that will be created when the {@link IFluidContainer | Container} is first created.
74
+ *
75
+ * @remarks It uses the key as the id and the value as the loadable object to create.
76
+ *
77
+ * @example
78
+ *
79
+ * In the example below two objects will be created when the `Container` is first
80
+ * created. One with id "map1" that will return a `SharedMap` and the other with
81
+ * id "pair1" that will return a `KeyValueDataObject`.
82
+ *
83
+ * ```typescript
84
+ * {
85
+ * map1: SharedMap,
86
+ * pair1: KeyValueDataObject,
87
+ * }
88
+ * ```
89
+ */
90
+ initialObjects: LoadableObjectClassRecord;
91
+
92
+ /**
93
+ * Loadable objects that can be created after the initial {@link IFluidContainer | Container} creation.
94
+ *
95
+ * @remarks
96
+ *
97
+ * Types defined in `initialObjects` will always be available and are not required to be provided here.
98
+ *
99
+ * For best practice it's recommended to define all the dynamic types you create even if they are
100
+ * included via initialObjects.
101
+ */
102
+ dynamicObjectTypes?: LoadableObjectClass<any>[];
83
103
  }
84
104
 
85
105
  /**
86
- * Events that trigger when the roster of members in the Fluid session change.
87
- * Only changes that would be reflected in the returned map of {@link IServiceAudience}'s
88
- * {@link IServiceAudience.getMembers} method will emit events.
89
- *
90
- * @remarks
91
- *
92
- * The following is the list of events emitted.
93
- *
94
- * ### "membersChanged"
95
- *
96
- * The "membersChanged" event is emitted when a member is either added or removed.
97
- *
98
- * #### Listener signature
99
- *
100
- * ```typescript
101
- * () => void;
102
- * ```
103
- *
104
- * ### "memberAdded"
105
- *
106
- * The "memberAdded" event is emitted when a member joins the audience.
107
- *
108
- * #### Listener signature
109
- *
110
- * ```typescript
111
- * (clientId: string, member: M) => void;
112
- * ```
113
- * - `clientId` - A unique identifier for the client
114
- *
115
- * - `member` - The service-specific member object for the client
106
+ * @internal
107
+ */
108
+ export interface IProvideRootDataObject {
109
+ readonly IRootDataObject: IRootDataObject;
110
+ }
111
+
112
+ /**
113
+ * Holds the collection of objects that the container was initially created with, as well as provides the ability
114
+ * to dynamically create further objects during usage.
115
+ * @internal
116
+ */
117
+ export interface IRootDataObject extends IProvideRootDataObject {
118
+ /**
119
+ * Provides a record of the initial objects defined on creation.
120
+ */
121
+ readonly initialObjects: LoadableObjectRecord;
122
+
123
+ /**
124
+ * Dynamically creates a new detached collaborative object (DDS/DataObject).
125
+ *
126
+ * @param objectClass - Type of the collaborative object to be created.
127
+ *
128
+ * @typeParam T - The class of the `DataObject` or `SharedObject`.
129
+ */
130
+ create<T extends IFluidLoadable>(objectClass: LoadableObjectClass<T>): Promise<T>;
131
+ }
132
+
133
+ /**
134
+ * Signature for {@link IMember} change events.
116
135
  *
117
- * ### "memberRemoved"
136
+ * @param clientId - A unique identifier for the client.
137
+ * @param member - The service-specific member object for the client.
118
138
  *
119
- * The "memberRemoved" event is emitted when a member leaves the audience.
139
+ * @see See {@link IServiceAudienceEvents} for usage details.
140
+ * @public
141
+ */
142
+ export type MemberChangedListener<M extends IMember> = (clientId: string, member: M) => void;
143
+
144
+ /**
145
+ * Events that trigger when the roster of members in the Fluid session change.
120
146
  *
121
- * #### Listener signature
147
+ * @remarks
122
148
  *
123
- * ```typescript
124
- * (clientId: string, member: M) => void;
125
- * ```
126
- * - `clientId` - A unique identifier for the client
149
+ * Only changes that would be reflected in the returned map of {@link IServiceAudience}'s
150
+ * {@link IServiceAudience.getMembers} method will emit events.
127
151
  *
128
- * - `member` - The service-specific member object for the client
129
- * @typeParam M - A service-specific member type.
152
+ * @typeParam M - A service-specific {@link IMember} implementation.
153
+ * @public
130
154
  */
131
155
  export interface IServiceAudienceEvents<M extends IMember> extends IEvent {
132
- (event: "membersChanged", listener: () => void): void;
133
- (event: "memberAdded" | "memberRemoved", listener: (clientId: string, member: M) => void): void;
156
+ /**
157
+ * Emitted when a {@link IMember | member}(s) are either added or removed.
158
+ *
159
+ * @eventProperty
160
+ */
161
+ (event: "membersChanged", listener: () => void): void;
162
+
163
+ /**
164
+ * Emitted when a {@link IMember | member} joins the audience.
165
+ *
166
+ * @eventProperty
167
+ */
168
+ (event: "memberAdded", listener: MemberChangedListener<M>): void;
169
+
170
+ /**
171
+ * Emitted when a {@link IMember | member} leaves the audience.
172
+ *
173
+ * @eventProperty
174
+ */
175
+ (event: "memberRemoved", listener: MemberChangedListener<M>): void;
134
176
  }
135
177
 
136
178
  /**
137
- * Base interface to be implemented to fetch each service's audience. The generic M allows consumers to further
138
- * extend the client object with service-specific details about the connecting client, such as device information,
139
- * environment, or a username.
140
- * @typeParam M - A service-specific member type.
141
- */
142
- export interface IServiceAudience<M extends IMember> extends IEventProvider<IServiceAudienceEvents<M>> {
143
- /**
144
- * Returns an map of all users currently in the Fluid session where key is the userId and the value is the
145
- * member object. The implementation may choose to exclude certain connections from the returned map.
146
- * E.g. ServiceAudience excludes non-interactive connections to represent only the roster of live users.
147
- */
148
- getMembers(): Map<string, M>;
149
-
150
- /**
151
- * Returns the current active user on this client once they are connected. Otherwise, returns undefined.
152
- */
153
- getMyself(): M | undefined;
179
+ * Base interface to be implemented to fetch each service's audience.
180
+ *
181
+ * @remarks
182
+ *
183
+ * The type parameter `M` allows consumers to further extend the client object with service-specific
184
+ * details about the connecting client, such as device information, environment, or a username.
185
+ *
186
+ * @typeParam M - A service-specific {@link IMember} type.
187
+ * @public
188
+ */
189
+ export interface IServiceAudience<M extends IMember>
190
+ extends IEventProvider<IServiceAudienceEvents<M>> {
191
+ /**
192
+ * Returns an map of all users currently in the Fluid session where key is the userId and the value is the
193
+ * member object. The implementation may choose to exclude certain connections from the returned map.
194
+ * E.g. ServiceAudience excludes non-interactive connections to represent only the roster of live users.
195
+ */
196
+ getMembers(): Map<string, M>;
197
+
198
+ /**
199
+ * Returns the current active user on this client once they are connected. Otherwise, returns undefined.
200
+ */
201
+ getMyself(): Myself<M> | undefined;
154
202
  }
155
203
 
156
204
  /**
157
- * Base interface for information for each connection made to the Fluid session. This interface can be extended
158
- * to provide additional information specific to each service.
205
+ * Base interface for information for each connection made to the Fluid session.
206
+ *
207
+ * @remarks This interface can be extended to provide additional information specific to each service.
208
+ * @public
159
209
  */
160
210
  export interface IConnection {
161
- /**
162
- * A unique ID for the connection. A single user may have multiple connections, each with a different ID.
163
- */
164
- id: string;
165
-
166
- /**
167
- * Whether the connection is in read or read/write mode.
168
- */
169
- mode: "write" | "read";
211
+ /**
212
+ * A unique ID for the connection. A single user may have multiple connections, each with a different ID.
213
+ */
214
+ id: string;
215
+
216
+ /**
217
+ * Whether the connection is in read or read/write mode.
218
+ */
219
+ mode: "write" | "read";
170
220
  }
171
221
 
172
222
  /**
173
- * Base interface to be implemented to fetch each service's member. This interface can be extended by each service
174
- * to provide additional service-specific user metadata.
223
+ * Base interface to be implemented to fetch each service's member.
224
+ *
225
+ * @remarks This interface can be extended by each service to provide additional service-specific user metadata.
226
+ * @public
175
227
  */
176
228
  export interface IMember {
177
- /**
178
- * An ID for the user, unique among each individual user connecting to the session.
179
- */
180
- userId: string;
181
-
182
- /**
183
- * The set of connections the user has made, e.g. from multiple tabs or devices.
184
- */
185
- connections: IConnection[];
229
+ /**
230
+ * An ID for the user, unique among each individual user connecting to the session.
231
+ */
232
+ userId: string;
233
+
234
+ /**
235
+ * The set of connections the user has made, e.g. from multiple tabs or devices.
236
+ */
237
+ connections: IConnection[];
186
238
  }
239
+
240
+ /**
241
+ * An extended member object that includes currentConnection
242
+ * @public
243
+ */
244
+ export type Myself<M extends IMember = IMember> = M & { currentConnection: string };
package/src/utils.ts CHANGED
@@ -4,28 +4,38 @@
4
4
  */
5
5
 
6
6
  import { IChannelFactory } from "@fluidframework/datastore-definitions";
7
- import { NamedFluidDataStoreRegistryEntry } from "@fluidframework/runtime-definitions";
8
7
  import {
9
- ContainerSchema,
10
- DataObjectClass,
11
- LoadableObjectClass,
12
- SharedObjectClass,
13
- } from "./types";
8
+ IFluidDataStoreFactory,
9
+ NamedFluidDataStoreRegistryEntry,
10
+ } from "@fluidframework/runtime-definitions";
11
+ import { IFluidLoadable } from "@fluidframework/core-interfaces";
12
+ import { ContainerSchema, DataObjectClass, LoadableObjectClass, SharedObjectClass } from "./types";
13
+
14
+ /**
15
+ * An internal type used by the internal type guard isDataObjectClass to cast a
16
+ * DataObjectClass to a type that is strongly coupled to IFluidDataStoreFactory.
17
+ * Unlike the external and exported type DataObjectClass which is
18
+ * weakly coupled to the IFluidDataStoreFactory to prevent leaking internals.
19
+ */
20
+ export type InternalDataObjectClass<T extends IFluidLoadable> = DataObjectClass<T> &
21
+ Record<"factory", IFluidDataStoreFactory>;
14
22
 
15
23
  /**
16
24
  * Runtime check to determine if a class is a DataObject type
17
25
  */
18
- export const isDataObjectClass = (obj: any): obj is DataObjectClass<any> => {
19
- return obj?.factory !== undefined;
26
+ export const isDataObjectClass = (obj: any): obj is InternalDataObjectClass<IFluidLoadable> => {
27
+ const maybe: Partial<InternalDataObjectClass<IFluidLoadable>> | undefined = obj;
28
+ return (
29
+ maybe?.factory?.IFluidDataStoreFactory !== undefined &&
30
+ maybe?.factory?.IFluidDataStoreFactory === maybe?.factory
31
+ );
20
32
  };
21
33
 
22
34
  /**
23
35
  * Runtime check to determine if a class is a SharedObject type
24
36
  */
25
- export const isSharedObjectClass = (
26
- obj: any,
27
- ): obj is SharedObjectClass<any> => {
28
- return obj?.getFactory !== undefined;
37
+ export const isSharedObjectClass = (obj: any): obj is SharedObjectClass<any> => {
38
+ return obj?.getFactory !== undefined;
29
39
  };
30
40
 
31
41
  /**
@@ -34,36 +44,31 @@ export const isSharedObjectClass = (
34
44
  * of DataObject types and an array of SharedObjects.
35
45
  */
36
46
  export const parseDataObjectsFromSharedObjects = (
37
- schema: ContainerSchema,
47
+ schema: ContainerSchema,
38
48
  ): [NamedFluidDataStoreRegistryEntry[], IChannelFactory[]] => {
39
- const registryEntries: Set<NamedFluidDataStoreRegistryEntry> = new Set();
40
- const sharedObjects: Set<IChannelFactory> = new Set();
49
+ const registryEntries = new Set<NamedFluidDataStoreRegistryEntry>();
50
+ const sharedObjects = new Set<IChannelFactory>();
41
51
 
42
- const tryAddObject = (obj: LoadableObjectClass<any>) => {
43
- if (isSharedObjectClass(obj)) {
44
- sharedObjects.add(obj.getFactory());
45
- } else if (isDataObjectClass(obj)) {
46
- registryEntries.add([
47
- obj.factory.type,
48
- Promise.resolve(obj.factory),
49
- ]);
50
- } else {
51
- throw new Error(`Entry is neither a DataObject or a SharedObject`);
52
- }
53
- };
52
+ const tryAddObject = (obj: LoadableObjectClass<any>) => {
53
+ if (isSharedObjectClass(obj)) {
54
+ sharedObjects.add(obj.getFactory());
55
+ } else if (isDataObjectClass(obj)) {
56
+ registryEntries.add([obj.factory.type, Promise.resolve(obj.factory)]);
57
+ } else {
58
+ throw new Error(`Entry is neither a DataObject or a SharedObject`);
59
+ }
60
+ };
54
61
 
55
- // Add the object types that will be initialized
56
- const dedupedObjects = new Set([
57
- ...Object.values(schema.initialObjects),
58
- ...(schema.dynamicObjectTypes ?? []),
59
- ]);
60
- dedupedObjects.forEach(tryAddObject);
62
+ // Add the object types that will be initialized
63
+ const dedupedObjects = new Set([
64
+ ...Object.values(schema.initialObjects),
65
+ ...(schema.dynamicObjectTypes ?? []),
66
+ ]);
67
+ dedupedObjects.forEach(tryAddObject);
61
68
 
62
- if (registryEntries.size === 0 && sharedObjects.size === 0) {
63
- throw new Error(
64
- "Container cannot be initialized without any DataTypes",
65
- );
66
- }
69
+ if (registryEntries.size === 0 && sharedObjects.size === 0) {
70
+ throw new Error("Container cannot be initialized without any DataTypes");
71
+ }
67
72
 
68
- return [Array.from(registryEntries), Array.from(sharedObjects)];
73
+ return [Array.from(registryEntries), Array.from(sharedObjects)];
69
74
  };
@@ -0,0 +1,4 @@
1
+ {
2
+ "targets": [{ "extname": ".cjs", "module": "CommonJS", "moduleResolution": "Node10" }],
3
+ "projects": ["./tsconfig.json", "./src/test/tsconfig.json"]
4
+ }
package/tsconfig.json CHANGED
@@ -1,17 +1,13 @@
1
1
  {
2
- "extends": "@fluidframework/build-common/ts-common-config.json",
3
- "exclude": [
4
- "src/test/**/*"
5
- ],
6
- "compilerOptions": {
7
- "rootDir": "./src",
8
- "outDir": "./dist",
9
- "composite": true,
10
- "types": [
11
- "node"
12
- ]
13
- },
14
- "include": [
15
- "src/**/*"
16
- ]
17
- }
2
+ "extends": [
3
+ "../../../common/build/build-common/tsconfig.base.json",
4
+ "../../../common/build/build-common/tsconfig.cjs.json",
5
+ ],
6
+ "include": ["src/**/*"],
7
+ "exclude": ["src/test/**/*"],
8
+ "compilerOptions": {
9
+ "rootDir": "./src",
10
+ "outDir": "./dist",
11
+ "types": ["node"],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,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;CACJ;AAnGD,wCAmGC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IFluidLoadable } from \"@fluidframework/core-interfaces\";\nimport { IEvent, IEventProvider } from \"@fluidframework/common-definitions\";\nimport {\n AttachState,\n ConnectionState,\n IContainer,\n ICriticalContainerError,\n} from \"@fluidframework/container-definitions\";\nimport { LoadableObjectClass, LoadableObjectRecord } from \"./types\";\nimport { RootDataObject } from \"./rootDataObject\";\n\n/**\n * Events emitted from {@link IFluidContainer}.\n *\n * @remarks\n *\n * The following is the list of events emitted.\n *\n * ### \"connected\"\n *\n * The \"connected\" event is emitted when the `IFluidContainer` completes connecting to the Fluid service.\n *\n * #### Listener signature\n *\n * ```typescript\n * () => void;\n * ```\n *\n * ### \"disposed\"\n *\n * The \"disposed\" event is emitted when the `IFluidContainer` is disposed, which permanently disables it.\n *\n * #### Listener signature\n *\n * ```typescript\n * () => void;\n * ```\n *\n * ### \"disconnected\"\n *\n * The \"disconnected\" event is emitted when the `IFluidContainer` becomes disconnected from the Fluid service.\n *\n * #### Listener signature\n *\n * ```typescript\n * () => void;\n * ```\n *\n * ### \"saved\"\n *\n * The \"saved\" event is emitted when the `IFluidContainer` has local changes acknowledged by the service.\n *\n * #### Listener signature\n *\n * ```typescript\n * () => void\n * ```\n *\n * ### \"dirty\"\n *\n * The \"dirty\" event is emitted when the `IFluidContainer` has local changes that have not yet\n * been acknowledged by the service.\n *\n * #### Listener signature\n *\n * ```typescript\n * () => void\n * ```\n */\nexport interface IFluidContainerEvents extends IEvent {\n /**\n * **connected** & **disconnected** events reflect connection state changes against the (delta)\n * service acknowledging ops/edits.\n */\n (event: \"connected\" | \"disconnected\", listener: () => void): void;\n /**\n * **saved** event is raised when all local changes/edits have been acknowledged by the service.\n * **dirty** event is raised when first local change has been made, following a \"saved\" state.\n */\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n (event: \"saved\" | \"dirty\", listener: () => void): void;\n /**\n * Disposed event is raised when container is closed. If container was closed due to error\n * (vs explicit **dispose** action), optional argument contains further details about the error.\n */\n (event: \"disposed\", listener: (error?: ICriticalContainerError) => void);\n}\n\n/**\n * Provides an entrypoint into the client side of collaborative Fluid data.\n * Provides access to the data as well as status on the collaboration session.\n */\nexport interface IFluidContainer extends IEventProvider<IFluidContainerEvents> {\n /**\n * Provides the current connected state of the container\n */\n readonly connectionState: ConnectionState;\n\n /**\n * A container is considered **dirty** if it has local changes that have not yet been acknowledged by the service.\n * You should always check the `isDirty` flag before closing the container or navigating away from the page.\n * Closing the container while `isDirty === true` may result in the loss of operations that have not yet been\n * acknowledged by the service.\n *\n * A container is considered dirty in the following cases:\n *\n * 1. The container has been created in the detached state, and either it has not been attached yet or it is\n * in the process of being attached (container is in `attaching` state). If container is closed prior to being\n * attached, host may never know if the file was created or not.\n *\n * 2. The container was attached, but it has local changes that have not yet been saved to service endpoint.\n * This occurs as part of normal op flow where pending operation (changes) are awaiting acknowledgement from the\n * service. In some cases this can be due to lack of network connection. If the network connection is down,\n * it needs to be restored for the pending changes to be acknowledged.\n */\n readonly isDirty: boolean;\n\n /**\n * Whether the container is disposed, which permanently disables it.\n */\n readonly disposed: boolean;\n\n /**\n * The collection of data objects and Distributed Data Stores (DDSes) that were specified by the schema.\n * These data objects and DDSes exist for the lifetime of the container.\n */\n readonly initialObjects: LoadableObjectRecord;\n\n /**\n * The current attachment state of the container. Once a container has been attached, it remains attached.\n * When loading an existing container, it will already be attached.\n */\n readonly attachState: AttachState;\n\n /**\n * A newly created container starts detached from the collaborative service.\n * Calling `attach()` uploads the new container to the service and connects to the collaborative service.\n *\n * @remarks This should only be called when the container is in the\n * {@link @fluidframework/container-definitions#AttachState.Detatched} state.\n *\n * This can be determined by observing {@link IFluidContainer.attachState}.\n *\n * @returns A promise which resolves when the attach is complete, with the string identifier of the container.\n */\n attach(): Promise<string>;\n\n /**\n * Attempts to connect the container to the delta stream and process operations.\n * Will throw an error if unsuccessful.\n *\n * @remarks This should only be called when the container is in the\n * {@link @fluidframework/container-definitions#ConnectionState.Disconnected} state.\n *\n * This can be determined by observing {@link IFluidContainer.connectionState}.\n */\n connect(): void;\n\n /**\n * Disconnects the container from the delta stream and stops processing operations.\n *\n * @remarks This should only be called when the container is in the\n * {@link @fluidframework/container-definitions#ConnectionState.Connected} state.\n *\n * This can be determined by observing {@link IFluidContainer.connectionState}.\n */\n disconnect(): void;\n\n /**\n * Create a new data object or Distributed Data Store (DDS) of the specified type.\n *\n * @remarks In order to share the data object or DDS with other\n * collaborators and retrieve it later, store its handle in a collection like a SharedDirectory from your\n * initialObjects.\n *\n * @param objectClass - The class of data object or DDS to create\n */\n create<T extends IFluidLoadable>(objectClass: LoadableObjectClass<T>): Promise<T>;\n\n /**\n * Dispose of the container instance, permanently disabling it.\n */\n dispose(): void;\n}\n\n/**\n * Base {@link IFluidContainer} implementation.\n *\n * @remarks Note: this implementation is not complete. Consumers who rely on {@link IFluidContainer.attach}\n * will need to utilize or provide a service-specific implementation of this type that implements that method.\n */\nexport class FluidContainer extends TypedEventEmitter<IFluidContainerEvents> implements IFluidContainer {\n private readonly connectedHandler = () => this.emit(\"connected\");\n private readonly disconnectedHandler = () => this.emit(\"disconnected\");\n private readonly disposedHandler = (error?: ICriticalContainerError) => this.emit(\"disposed\", error);\n private readonly savedHandler = () => this.emit(\"saved\");\n private readonly dirtyHandler = () => this.emit(\"dirty\");\n\n public constructor(\n private readonly container: IContainer,\n private readonly rootDataObject: RootDataObject,\n ) {\n super();\n container.on(\"connected\", this.connectedHandler);\n container.on(\"closed\", this.disposedHandler);\n container.on(\"disconnected\", this.disconnectedHandler);\n container.on(\"saved\", this.savedHandler);\n container.on(\"dirty\", this.dirtyHandler);\n }\n\n /**\n * {@inheritDoc IFluidContainer.isDirty}\n */\n public get isDirty(): boolean {\n return this.container.isDirty;\n }\n\n /**\n * {@inheritDoc IFluidContainer.attachState}\n */\n public get attachState(): AttachState {\n return this.container.attachState;\n }\n\n /**\n * {@inheritDoc IFluidContainer.disposed}\n */\n public get disposed() {\n return this.container.closed;\n }\n\n /**\n * {@inheritDoc IFluidContainer.connectionState}\n */\n public get connectionState(): ConnectionState {\n return this.container.connectionState;\n }\n\n /**\n * {@inheritDoc IFluidContainer.initialObjects}\n */\n public get initialObjects() {\n return this.rootDataObject.initialObjects;\n }\n\n /**\n * Incomplete base implementation of {@link IFluidContainer.attach}.\n * @remarks Note: this implementation will unconditionally throw.\n * Consumers who rely on this will need to utilize or provide a service specific implementation of this base type\n * that provides an implementation of this method.\n *\n * The reason is because externally we are presenting a separation between the service and the `FluidContainer`,\n * but internally this separation is not there.\n */\n public async attach(): Promise<string> {\n throw new Error(\"Cannot attach container. Container is not in detached state\");\n }\n\n /**\n * {@inheritDoc IFluidContainer.connect}\n */\n public async connect(): Promise<void> {\n this.container.connect?.();\n }\n\n /**\n * {@inheritDoc IFluidContainer.connect}\n */\n public async disconnect(): Promise<void> {\n this.container.disconnect?.();\n }\n\n /**\n * {@inheritDoc IFluidContainer.create}\n */\n public async create<T extends IFluidLoadable>(objectClass: LoadableObjectClass<T>): Promise<T> {\n return this.rootDataObject.create(objectClass);\n }\n\n /**\n * {@inheritDoc IFluidContainer.dispose}\n */\n public dispose() {\n this.container.close();\n this.container.off(\"connected\", this.connectedHandler);\n this.container.off(\"closed\", this.disposedHandler);\n this.container.off(\"disconnected\", this.disconnectedHandler);\n this.container.off(\"saved\", this.savedHandler);\n this.container.off(\"dirty\", this.dirtyHandler);\n }\n}\n"]}
package/dist/index.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- /**
18
- * Provides a simple and powerful way to consume collaborative Fluid data.
19
- *
20
- * @packageDocumentation
21
- */
22
- __exportStar(require("./fluidContainer"), exports);
23
- __exportStar(require("./rootDataObject"), exports);
24
- __exportStar(require("./serviceAudience"), exports);
25
- __exportStar(require("./types"), exports);
26
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH;;;;GAIG;AAEH,mDAAiC;AACjC,mDAAiC;AACjC,oDAAkC;AAClC,0CAAwB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Provides a simple and powerful way to consume collaborative Fluid data.\n *\n * @packageDocumentation\n */\n\nexport * from \"./fluidContainer\";\nexport * from \"./rootDataObject\";\nexport * from \"./serviceAudience\";\nexport * from \"./types\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"rootDataObject.js","sourceRoot":"","sources":["../src/rootDataObject.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uDAKkC;AAGlC,6EAAgE;AAChE,iEAAmE;AASnE,mCAAoG;AAapG;;;;GAIG;AACH,MAAa,cAAe,SAAQ,qBAAkD;IAAtF;;QACqB,yBAAoB,GAAG,qBAAqB,CAAC;QAC7C,oBAAe,GAAyB,EAAE,CAAC;IA4FhE,CAAC;IA1FG,IAAY,iBAAiB;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,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MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAChE,OAAO,GAAmB,CAAC;IAC/B,CAAC;CACJ;AA9FD,wCA8FC;AAED,MAAM,eAAe,GAAG,UAAU,CAAC;AAEnC;;;GAGG;AACH,MAAa,iCAAkC,SAAQ,sCAA2B;IAO9E,YAAY,MAAuB;QAC/B,MAAM,CAAC,eAAe,EAAE,aAAa,CAAC,GAAG,IAAA,yCAAiC,EAAC,MAAM,CAAC,CAAC;QACnF,MAAM,qBAAqB,GACvB,IAAI,4BAAiB,CACjB,QAAQ,EACR,cAAc,EACd,aAAa,EACb,EAAE,EACF,eAAe,CAClB,CAAC;QACN,KAAK,CACD,CAAC,qBAAqB,CAAC,aAAa,CAAC,EACrC,SAAS,EACT,CAAC,IAAA,qCAA0B,EAAC,eAAe,CAAC,CAAC;QAC7C,kGAAkG;QAClG,sEAAsE;QACtE,EAAE,SAAS,EAAE,+BAAS,CAAC,SAAS,EAAE,CACrC,CAAC;QACF,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;IAChD,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,8BAA8B,CAAC,OAA0B;QACrE,sEAAsE;QACtE,MAAM,IAAI,CAAC,qBAAqB,CAAC,kBAAkB,CAC/C,eAAe,EACf,OAAO,EACP,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IACjD,CAAC;CACJ;AAvCD,8EAuCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport {\n BaseContainerRuntimeFactory,\n DataObject,\n DataObjectFactory,\n defaultRouteRequestHandler,\n} from \"@fluidframework/aqueduct\";\nimport { IContainerRuntime } from \"@fluidframework/container-runtime-definitions\";\nimport { IFluidLoadable } from \"@fluidframework/core-interfaces\";\nimport { FlushMode } from \"@fluidframework/runtime-definitions\";\nimport { requestFluidObject } from \"@fluidframework/runtime-utils\";\nimport {\n ContainerSchema,\n DataObjectClass,\n LoadableObjectClass,\n LoadableObjectClassRecord,\n LoadableObjectRecord,\n SharedObjectClass,\n} from \"./types\";\nimport { isDataObjectClass, isSharedObjectClass, parseDataObjectsFromSharedObjects } from \"./utils\";\n\n/**\n * Input props for {@link RootDataObject.initializingFirstTime}\n */\nexport interface RootDataObjectProps {\n /**\n * Initial object structure with which the {@link RootDataObject} will be first-time initialized.\n * See {@link RootDataObject.initializingFirstTime}\n */\n initialObjects: LoadableObjectClassRecord;\n}\n\n/**\n * The entry-point/root collaborative object of the Fluid Container.\n * This class abstracts the dynamic code required to build a Fluid Container into a static representation\n * for end customers.\n */\nexport class RootDataObject extends DataObject<{ InitialState: RootDataObjectProps; }> {\n private readonly initialObjectsDirKey = \"initial-objects-key\";\n private readonly _initialObjects: LoadableObjectRecord = {};\n\n private get initialObjectsDir() {\n const dir = this.root.getSubDirectory(this.initialObjectsDirKey);\n if (dir === undefined) {\n throw new Error(\"InitialObjects sub-directory was not initialized\");\n }\n return dir;\n }\n\n /**\n * The first time this object is initialized, creates each object identified in\n * {@link RootDataObjectProps.initialObjects} and stores them as unique values in the root directory.\n *\n * See {@link @fluidframework/aqueduct#PureDataObject.initializingFirstTime}\n */\n protected async initializingFirstTime(props: RootDataObjectProps) {\n this.root.createSubDirectory(this.initialObjectsDirKey);\n\n // Create initial objects provided by the developer\n const initialObjectsP: Promise<void>[] = [];\n Object.entries(props.initialObjects).forEach(([id, objectClass]) => {\n const createObject = async () => {\n const obj = await this.create(objectClass);\n this.initialObjectsDir.set(id, obj.handle);\n };\n initialObjectsP.push(createObject());\n });\n\n await Promise.all(initialObjectsP);\n }\n\n /**\n * Every time an instance is initialized, loads all of the initial objects in the root directory so they can be\n * accessed immediately.\n *\n * See {@link @fluidframework/aqueduct#PureDataObject.hasInitialized}\n */\n protected async hasInitialized() {\n // We will always load the initial objects so they are available to the developer\n const loadInitialObjectsP: Promise<void>[] = [];\n for (const [key, value] of Array.from(this.initialObjectsDir.entries())) {\n const loadDir = async () => {\n const obj = await value.get();\n Object.assign(this._initialObjects, { [key]: obj });\n };\n loadInitialObjectsP.push(loadDir());\n }\n\n await Promise.all(loadInitialObjectsP);\n }\n\n /**\n * Provides a record of the initial objects defined on creation.\n * See {@link RootDataObject.initializingFirstTime}\n */\n public get initialObjects(): LoadableObjectRecord {\n if (Object.keys(this._initialObjects).length === 0) {\n throw new Error(\"Initial Objects were not correctly initialized\");\n }\n return this._initialObjects;\n }\n\n /**\n * Dynamically creates a new detached collaborative object (DDS/DataObject).\n * @param objectClass - Type of the collaborative object to be created.\n */\n public async create<T extends IFluidLoadable>(\n objectClass: LoadableObjectClass<T>,\n ): Promise<T> {\n if (isDataObjectClass(objectClass)) {\n return this.createDataObject<T>(objectClass);\n } else if (isSharedObjectClass(objectClass)) {\n return this.createSharedObject<T>(objectClass);\n }\n throw new Error(\"Could not create new Fluid object because an unknown object was passed\");\n }\n\n private async createDataObject<T extends IFluidLoadable>(dataObjectClass: DataObjectClass<T>): Promise<T> {\n const factory = dataObjectClass.factory;\n const packagePath = [...this.context.packagePath, factory.type];\n const router = await this.context.containerRuntime.createDataStore(packagePath);\n return requestFluidObject<T>(router, \"/\");\n }\n\n private createSharedObject<T extends IFluidLoadable>(\n sharedObjectClass: SharedObjectClass<T>,\n ): T {\n const factory = sharedObjectClass.getFactory();\n const obj = this.runtime.createChannel(undefined, factory.type);\n return obj as unknown as T;\n }\n}\n\nconst rootDataStoreId = \"rootDOId\";\n\n/**\n * Container code that provides a single {@link RootDataObject}. This data object is\n * dynamically customized (registry and initial objects) based on the schema provided to the container runtime factory.\n */\nexport class DOProviderContainerRuntimeFactory extends BaseContainerRuntimeFactory {\n private readonly rootDataObjectFactory: DataObjectFactory<RootDataObject, {\n InitialState: RootDataObjectProps;\n }>;\n\n private readonly initialObjects: LoadableObjectClassRecord;\n\n constructor(schema: ContainerSchema) {\n const [registryEntries, sharedObjects] = parseDataObjectsFromSharedObjects(schema);\n const rootDataObjectFactory =\n new DataObjectFactory(\n \"rootDO\",\n RootDataObject,\n sharedObjects,\n {},\n registryEntries,\n );\n super(\n [rootDataObjectFactory.registryEntry],\n undefined,\n [defaultRouteRequestHandler(rootDataStoreId)],\n // temporary workaround to disable message batching until the message batch size issue is resolved\n // resolution progress is tracked by the Feature 465 work item in AzDO\n { flushMode: FlushMode.Immediate },\n );\n this.rootDataObjectFactory = rootDataObjectFactory;\n this.initialObjects = schema.initialObjects;\n }\n\n /**\n * {@inheritDoc @fluidframework/aqueduct#BaseContainerRuntimeFactory.containerInitializingFirstTime}\n */\n protected async containerInitializingFirstTime(runtime: IContainerRuntime) {\n // The first time we create the container we create the RootDataObject\n await this.rootDataObjectFactory.createRootInstance(\n rootDataStoreId,\n runtime,\n { initialObjects: this.initialObjects });\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"serviceAudience.js","sourceRoot":"","sources":["../src/serviceAudience.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AAKjE;;;;;GAKG;AACH,MAAsB,eACpB,SAAQ,gCAA4C;IAoBpD;IACE;;OAEG;IACgB,SAAqB;QAExC,KAAK,EAAE,CAAC;QAFW,cAAS,GAAT,SAAS,CAAY;QAjB1C;;;;;;;;;;WAUG;QACO,gBAAW,GAAmB,IAAI,GAAG,EAAE,CAAC;QAShD,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QAEnC,iFAAiF;QACjF,+EAA+E;QAC/E,IAAI,CAAC,UAAU,EAAE,CAAC;QAElB,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,QAAgB,EAAE,OAAgB,EAAE,EAAE;YACnE,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAE;gBACvC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,C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AuHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IAudience, IContainer } from \"@fluidframework/container-definitions\";\nimport { IClient } from \"@fluidframework/protocol-definitions\";\nimport { IServiceAudience, IServiceAudienceEvents, IMember } from \"./types\";\n\n/**\n * Base class for providing audience information for sessions interacting with FluidContainer\n * This can be extended by different service-specific client packages to additional parameters to\n * the user and client details returned in IMember\n * @typeParam M - A service-specific member type.\n */\nexport abstract class ServiceAudience<M extends IMember = IMember>\n extends TypedEventEmitter<IServiceAudienceEvents<M>>\n implements IServiceAudience<M> {\n /**\n * Audience object which includes all the existing members of the container.\n */\n protected readonly audience: IAudience;\n\n /**\n * Retain the most recent member list. This is so we have more information about a member\n * leaving the audience in the removeMember event. It allows us to match the behavior of the\n * addMember event where it only fires on a change to the members this class exposes (and would\n * actually produce a change in what getMembers returns). It also allows us to provide the\n * client details in the event which makes it easier to find that client connection in a map\n * keyed on the userId and not clientId.\n * This map will always be up-to-date in a removeMember event because it is set once at\n * construction and in every addMember event.\n * It is mapped clientId to M to be better work with what the IAudience event provides\n */\n protected lastMembers: Map<string, M> = new Map();\n\n constructor(\n /**\n * Fluid Container to read the audience from.\n */\n protected readonly container: IContainer,\n ) {\n super();\n this.audience = container.audience;\n\n // getMembers will assign lastMembers so the removeMember event has what it needs\n // in case it would fire before getMembers otherwise gets called the first time\n this.getMembers();\n\n this.audience.on(\"addMember\", (clientId: string, details: IClient) => {\n if (this.shouldIncludeAsMember(details)) {\n const member = this.getMember(clientId);\n this.emit(\"memberAdded\", clientId, member);\n this.emit(\"membersChanged\");\n }\n });\n\n this.audience.on(\"removeMember\", (clientId: string) => {\n if (this.lastMembers.has(clientId)) {\n this.emit(\"memberRemoved\", clientId, this.lastMembers.get(clientId));\n this.emit(\"membersChanged\");\n }\n });\n\n this.container.on(\"connected\", () => this.emit(\"membersChanged\"));\n }\n\n /**\n * Provides ability for inheriting class to modify/extend the audience object.\n * @param audienceMember - Record of a specific audience member.\n */\n protected abstract createServiceMember(audienceMember: IClient): M;\n\n /**\n * {@inheritDoc IServiceAudience.getMembers}\n */\n public getMembers(): Map<string, M> {\n const users = new Map<string, M>();\n const clientMemberMap = new Map<string, M>();\n // Iterate through the members and get the user specifics.\n this.audience.getMembers().forEach((member: IClient, clientId: string) => {\n if (this.shouldIncludeAsMember(member)) {\n const userId = member.user.id;\n // Ensure we're tracking the user\n let user = users.get(userId);\n if (user === undefined) {\n user = this.createServiceMember(member);\n users.set(userId, user);\n }\n\n // Add this connection to their collection\n user.connections.push({ id: clientId, mode: member.mode });\n clientMemberMap.set(clientId, user);\n }\n });\n this.lastMembers = clientMemberMap;\n return users;\n }\n\n /**\n * {@inheritDoc IServiceAudience.getMyself}\n */\n public getMyself(): M | undefined {\n const clientId = this.container.clientId;\n if (clientId === undefined) {\n return undefined;\n }\n return this.getMember(clientId);\n }\n\n private getMember(clientId: string): M | undefined {\n // Fetch the user ID assoicated with this client ID from the runtime\n const internalAudienceMember = this.audience.getMember(clientId);\n if (internalAudienceMember === undefined) {\n return undefined;\n }\n // Return the member object with any other clients associated for this user\n const allMembers = this.getMembers();\n const member = allMembers.get(internalAudienceMember?.user.id);\n if (member === undefined) {\n throw Error(`Attempted to fetch client ${clientId} that is not part of the current member list`);\n }\n return member;\n }\n\n /**\n * Provides ability for the inheriting class to include/omit specific members.\n * An example use case is omitting the summarizer client.\n * @param member - Member to be included/omitted.\n */\n protected shouldIncludeAsMember(member: IClient): boolean {\n // Include only human members\n return member.details.capabilities.interactive;\n }\n}\n"]}