@fluidframework/fluid-static 2.0.0-internal.3.0.1 → 2.0.0-internal.3.1.0

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 (45) hide show
  1. package/.eslintrc.js +8 -10
  2. package/.mocharc.js +2 -2
  3. package/CHANGELOG.md +48 -51
  4. package/api-extractor.json +2 -2
  5. package/dist/fluidContainer.d.ts.map +1 -1
  6. package/dist/fluidContainer.js.map +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/rootDataObject.d.ts.map +1 -1
  11. package/dist/rootDataObject.js +3 -1
  12. package/dist/rootDataObject.js.map +1 -1
  13. package/dist/serviceAudience.d.ts.map +1 -1
  14. package/dist/serviceAudience.js.map +1 -1
  15. package/dist/types.d.ts.map +1 -1
  16. package/dist/types.js.map +1 -1
  17. package/dist/utils.d.ts.map +1 -1
  18. package/dist/utils.js +1 -4
  19. package/dist/utils.js.map +1 -1
  20. package/lib/fluidContainer.d.ts.map +1 -1
  21. package/lib/fluidContainer.js.map +1 -1
  22. package/lib/index.d.ts +1 -1
  23. package/lib/index.d.ts.map +1 -1
  24. package/lib/index.js +1 -1
  25. package/lib/index.js.map +1 -1
  26. package/lib/rootDataObject.d.ts.map +1 -1
  27. package/lib/rootDataObject.js +3 -1
  28. package/lib/rootDataObject.js.map +1 -1
  29. package/lib/serviceAudience.d.ts.map +1 -1
  30. package/lib/serviceAudience.js.map +1 -1
  31. package/lib/types.d.ts.map +1 -1
  32. package/lib/types.js.map +1 -1
  33. package/lib/utils.d.ts.map +1 -1
  34. package/lib/utils.js +1 -4
  35. package/lib/utils.js.map +1 -1
  36. package/package.json +105 -104
  37. package/prettier.config.cjs +1 -1
  38. package/src/fluidContainer.ts +264 -260
  39. package/src/index.ts +6 -2
  40. package/src/rootDataObject.ts +152 -148
  41. package/src/serviceAudience.ts +137 -134
  42. package/src/types.ts +105 -101
  43. package/src/utils.ts +30 -42
  44. package/tsconfig.esnext.json +5 -5
  45. package/tsconfig.json +10 -16
package/src/types.ts CHANGED
@@ -24,7 +24,9 @@ export type LoadableObjectClassRecord = Record<string, LoadableObjectClass<any>>
24
24
  *
25
25
  * @typeParam T - The class of the `DataObject` or `SharedObject`.
26
26
  */
27
- export type LoadableObjectClass<T extends IFluidLoadable> = DataObjectClass<T> | SharedObjectClass<T>;
27
+ export type LoadableObjectClass<T extends IFluidLoadable> =
28
+ | DataObjectClass<T>
29
+ | SharedObjectClass<T>;
28
30
 
29
31
  /**
30
32
  * A class that has a factory that can create a `DataObject` and a
@@ -32,8 +34,9 @@ export type LoadableObjectClass<T extends IFluidLoadable> = DataObjectClass<T> |
32
34
  *
33
35
  * @typeParam T - The class of the `DataObject`.
34
36
  */
35
- export type DataObjectClass<T extends IFluidLoadable>
36
- = { readonly factory: IFluidDataStoreFactory; } & LoadableObjectCtor<T>;
37
+ export type DataObjectClass<T extends IFluidLoadable> = {
38
+ readonly factory: IFluidDataStoreFactory;
39
+ } & LoadableObjectCtor<T>;
37
40
 
38
41
  /**
39
42
  * A class that has a factory that can create a DDSes (`SharedObject`s) and a
@@ -41,15 +44,16 @@ export type DataObjectClass<T extends IFluidLoadable>
41
44
  *
42
45
  * @typeParam T - The class of the `SharedObject`.
43
46
  */
44
- export type SharedObjectClass<T extends IFluidLoadable>
45
- = { readonly getFactory: () => IChannelFactory; } & LoadableObjectCtor<T>;
47
+ export type SharedObjectClass<T extends IFluidLoadable> = {
48
+ readonly getFactory: () => IChannelFactory;
49
+ } & LoadableObjectCtor<T>;
46
50
 
47
51
  /**
48
52
  * An object with a constructor that will return an {@link @fluidframework/core-interfaces#IFluidLoadable}.
49
53
  *
50
54
  * @typeParam T - The class of the loadable object.
51
55
  */
52
- export type LoadableObjectCtor<T extends IFluidLoadable> = new(...args: any[]) => T;
56
+ export type LoadableObjectCtor<T extends IFluidLoadable> = new (...args: any[]) => T;
53
57
 
54
58
  /**
55
59
  * Declares the Fluid objects that will be available in the {@link IFluidContainer | Container}.
@@ -60,37 +64,37 @@ export type LoadableObjectCtor<T extends IFluidLoadable> = new(...args: any[]) =
60
64
  * as the types of objects that may be dynamically created throughout the lifetime of the `Container`.
61
65
  */
62
66
  export interface ContainerSchema {
63
- /**
64
- * Defines loadable objects that will be created when the {@link IFluidContainer | Container} is first created.
65
- *
66
- * @remarks It uses the key as the id and the value as the loadable object to create.
67
- *
68
- * @example
69
- *
70
- * In the example below two objects will be created when the `Container` is first
71
- * created. One with id "map1" that will return a `SharedMap` and the other with
72
- * id "pair1" that will return a `KeyValueDataObject`.
73
- *
74
- * ```typescript
75
- * {
76
- * map1: SharedMap,
77
- * pair1: KeyValueDataObject,
78
- * }
79
- * ```
80
- */
81
- initialObjects: LoadableObjectClassRecord;
82
-
83
- /**
84
- * Loadable objects that can be created after the initial {@link IFluidContainer | Container} creation.
85
- *
86
- * @remarks
87
- *
88
- * Types defined in `initialObjects` will always be available and are not required to be provided here.
89
- *
90
- * For best practice it's recommended to define all the dynamic types you create even if they are
91
- * included via initialObjects.
92
- */
93
- dynamicObjectTypes?: LoadableObjectClass<any>[];
67
+ /**
68
+ * Defines loadable objects that will be created when the {@link IFluidContainer | Container} is first created.
69
+ *
70
+ * @remarks It uses the key as the id and the value as the loadable object to create.
71
+ *
72
+ * @example
73
+ *
74
+ * In the example below two objects will be created when the `Container` is first
75
+ * created. One with id "map1" that will return a `SharedMap` and the other with
76
+ * id "pair1" that will return a `KeyValueDataObject`.
77
+ *
78
+ * ```typescript
79
+ * {
80
+ * map1: SharedMap,
81
+ * pair1: KeyValueDataObject,
82
+ * }
83
+ * ```
84
+ */
85
+ initialObjects: LoadableObjectClassRecord;
86
+
87
+ /**
88
+ * Loadable objects that can be created after the initial {@link IFluidContainer | Container} creation.
89
+ *
90
+ * @remarks
91
+ *
92
+ * Types defined in `initialObjects` will always be available and are not required to be provided here.
93
+ *
94
+ * For best practice it's recommended to define all the dynamic types you create even if they are
95
+ * included via initialObjects.
96
+ */
97
+ dynamicObjectTypes?: LoadableObjectClass<any>[];
94
98
  }
95
99
 
96
100
  /**
@@ -98,19 +102,19 @@ export interface ContainerSchema {
98
102
  * to dynamically create further objects during usage.
99
103
  */
100
104
  export interface IRootDataObject {
101
- /**
102
- * Provides a record of the initial objects defined on creation.
103
- */
104
- readonly initialObjects: LoadableObjectRecord;
105
-
106
- /**
107
- * Dynamically creates a new detached collaborative object (DDS/DataObject).
108
- *
109
- * @param objectClass - Type of the collaborative object to be created.
110
- *
111
- * @typeParam T - The class of the `DataObject` or `SharedObject`.
112
- */
113
- create<T extends IFluidLoadable>(objectClass: LoadableObjectClass<T>): Promise<T>;
105
+ /**
106
+ * Provides a record of the initial objects defined on creation.
107
+ */
108
+ readonly initialObjects: LoadableObjectRecord;
109
+
110
+ /**
111
+ * Dynamically creates a new detached collaborative object (DDS/DataObject).
112
+ *
113
+ * @param objectClass - Type of the collaborative object to be created.
114
+ *
115
+ * @typeParam T - The class of the `DataObject` or `SharedObject`.
116
+ */
117
+ create<T extends IFluidLoadable>(objectClass: LoadableObjectClass<T>): Promise<T>;
114
118
  }
115
119
 
116
120
  /**
@@ -134,26 +138,26 @@ export type MemberChangedListener<M extends IMember> = (clientId: string, member
134
138
  * @typeParam M - A service-specific {@link IMember} implementation.
135
139
  */
136
140
  export interface IServiceAudienceEvents<M extends IMember> extends IEvent {
137
- /**
138
- * Emitted when a {@link IMember | member}(s) are either added or removed.
139
- *
140
- * @eventProperty
141
- */
142
- (event: "membersChanged", listener: () => void): void;
143
-
144
- /**
145
- * Emitted when a {@link IMember | member} joins the audience.
146
- *
147
- * @eventProperty
148
- */
149
- (event: "memberAdded", listener: MemberChangedListener<M>): void;
150
-
151
- /**
152
- * Emitted when a {@link IMember | member} leaves the audience.
153
- *
154
- * @eventProperty
155
- */
156
- (event: "memberRemoved", listener: MemberChangedListener<M>): void;
141
+ /**
142
+ * Emitted when a {@link IMember | member}(s) are either added or removed.
143
+ *
144
+ * @eventProperty
145
+ */
146
+ (event: "membersChanged", listener: () => void): void;
147
+
148
+ /**
149
+ * Emitted when a {@link IMember | member} joins the audience.
150
+ *
151
+ * @eventProperty
152
+ */
153
+ (event: "memberAdded", listener: MemberChangedListener<M>): void;
154
+
155
+ /**
156
+ * Emitted when a {@link IMember | member} leaves the audience.
157
+ *
158
+ * @eventProperty
159
+ */
160
+ (event: "memberRemoved", listener: MemberChangedListener<M>): void;
157
161
  }
158
162
 
159
163
  /**
@@ -167,18 +171,18 @@ export interface IServiceAudienceEvents<M extends IMember> extends IEvent {
167
171
  * @typeParam M - A service-specific {@link IMember} type.
168
172
  */
169
173
  export interface IServiceAudience<M extends IMember>
170
- extends IEventProvider<IServiceAudienceEvents<M>> {
171
- /**
172
- * Returns an map of all users currently in the Fluid session where key is the userId and the value is the
173
- * member object. The implementation may choose to exclude certain connections from the returned map.
174
- * E.g. ServiceAudience excludes non-interactive connections to represent only the roster of live users.
175
- */
176
- getMembers(): Map<string, M>;
177
-
178
- /**
179
- * Returns the current active user on this client once they are connected. Otherwise, returns undefined.
180
- */
181
- getMyself(): Myself<M> | undefined;
174
+ extends IEventProvider<IServiceAudienceEvents<M>> {
175
+ /**
176
+ * Returns an map of all users currently in the Fluid session where key is the userId and the value is the
177
+ * member object. The implementation may choose to exclude certain connections from the returned map.
178
+ * E.g. ServiceAudience excludes non-interactive connections to represent only the roster of live users.
179
+ */
180
+ getMembers(): Map<string, M>;
181
+
182
+ /**
183
+ * Returns the current active user on this client once they are connected. Otherwise, returns undefined.
184
+ */
185
+ getMyself(): Myself<M> | undefined;
182
186
  }
183
187
 
184
188
  /**
@@ -187,15 +191,15 @@ export interface IServiceAudience<M extends IMember>
187
191
  * @remarks This interface can be extended to provide additional information specific to each service.
188
192
  */
189
193
  export interface IConnection {
190
- /**
191
- * A unique ID for the connection. A single user may have multiple connections, each with a different ID.
192
- */
193
- id: string;
194
-
195
- /**
196
- * Whether the connection is in read or read/write mode.
197
- */
198
- mode: "write" | "read";
194
+ /**
195
+ * A unique ID for the connection. A single user may have multiple connections, each with a different ID.
196
+ */
197
+ id: string;
198
+
199
+ /**
200
+ * Whether the connection is in read or read/write mode.
201
+ */
202
+ mode: "write" | "read";
199
203
  }
200
204
 
201
205
  /**
@@ -204,18 +208,18 @@ export interface IConnection {
204
208
  * @remarks This interface can be extended by each service to provide additional service-specific user metadata.
205
209
  */
206
210
  export interface IMember {
207
- /**
208
- * An ID for the user, unique among each individual user connecting to the session.
209
- */
210
- userId: string;
211
-
212
- /**
213
- * The set of connections the user has made, e.g. from multiple tabs or devices.
214
- */
215
- connections: IConnection[];
211
+ /**
212
+ * An ID for the user, unique among each individual user connecting to the session.
213
+ */
214
+ userId: string;
215
+
216
+ /**
217
+ * The set of connections the user has made, e.g. from multiple tabs or devices.
218
+ */
219
+ connections: IConnection[];
216
220
  }
217
221
 
218
222
  /**
219
223
  * An extended member object that includes currentConnection
220
224
  */
221
- export type Myself<M extends IMember = IMember> = M & { currentConnection: string; };
225
+ export type Myself<M extends IMember = IMember> = M & { currentConnection: string };
package/src/utils.ts CHANGED
@@ -5,27 +5,20 @@
5
5
 
6
6
  import { IChannelFactory } from "@fluidframework/datastore-definitions";
7
7
  import { NamedFluidDataStoreRegistryEntry } from "@fluidframework/runtime-definitions";
8
- import {
9
- ContainerSchema,
10
- DataObjectClass,
11
- LoadableObjectClass,
12
- SharedObjectClass,
13
- } from "./types";
8
+ import { ContainerSchema, DataObjectClass, LoadableObjectClass, SharedObjectClass } from "./types";
14
9
 
15
10
  /**
16
11
  * Runtime check to determine if a class is a DataObject type
17
12
  */
18
13
  export const isDataObjectClass = (obj: any): obj is DataObjectClass<any> => {
19
- return obj?.factory !== undefined;
14
+ return obj?.factory !== undefined;
20
15
  };
21
16
 
22
17
  /**
23
18
  * Runtime check to determine if a class is a SharedObject type
24
19
  */
25
- export const isSharedObjectClass = (
26
- obj: any,
27
- ): obj is SharedObjectClass<any> => {
28
- return obj?.getFactory !== undefined;
20
+ export const isSharedObjectClass = (obj: any): obj is SharedObjectClass<any> => {
21
+ return obj?.getFactory !== undefined;
29
22
  };
30
23
 
31
24
  /**
@@ -34,36 +27,31 @@ export const isSharedObjectClass = (
34
27
  * of DataObject types and an array of SharedObjects.
35
28
  */
36
29
  export const parseDataObjectsFromSharedObjects = (
37
- schema: ContainerSchema,
30
+ schema: ContainerSchema,
38
31
  ): [NamedFluidDataStoreRegistryEntry[], IChannelFactory[]] => {
39
- const registryEntries: Set<NamedFluidDataStoreRegistryEntry> = new Set();
40
- const sharedObjects: Set<IChannelFactory> = new Set();
41
-
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
- };
54
-
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);
61
-
62
- if (registryEntries.size === 0 && sharedObjects.size === 0) {
63
- throw new Error(
64
- "Container cannot be initialized without any DataTypes",
65
- );
66
- }
67
-
68
- return [Array.from(registryEntries), Array.from(sharedObjects)];
32
+ const registryEntries: Set<NamedFluidDataStoreRegistryEntry> = new Set();
33
+ const sharedObjects: Set<IChannelFactory> = new Set();
34
+
35
+ const tryAddObject = (obj: LoadableObjectClass<any>) => {
36
+ if (isSharedObjectClass(obj)) {
37
+ sharedObjects.add(obj.getFactory());
38
+ } else if (isDataObjectClass(obj)) {
39
+ registryEntries.add([obj.factory.type, Promise.resolve(obj.factory)]);
40
+ } else {
41
+ throw new Error(`Entry is neither a DataObject or a SharedObject`);
42
+ }
43
+ };
44
+
45
+ // Add the object types that will be initialized
46
+ const dedupedObjects = new Set([
47
+ ...Object.values(schema.initialObjects),
48
+ ...(schema.dynamicObjectTypes ?? []),
49
+ ]);
50
+ dedupedObjects.forEach(tryAddObject);
51
+
52
+ if (registryEntries.size === 0 && sharedObjects.size === 0) {
53
+ throw new Error("Container cannot be initialized without any DataTypes");
54
+ }
55
+
56
+ return [Array.from(registryEntries), Array.from(sharedObjects)];
69
57
  };
@@ -1,7 +1,7 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext"
6
- },
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "module": "esnext",
6
+ },
7
7
  }
package/tsconfig.json CHANGED
@@ -1,17 +1,11 @@
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": "@fluidframework/build-common/ts-common-config.json",
3
+ "exclude": ["src/test/**/*"],
4
+ "compilerOptions": {
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+ "composite": true,
8
+ "types": ["node"],
9
+ },
10
+ "include": ["src/**/*"],
11
+ }