@fluidframework/fluid-static 1.4.0-115997 → 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
@@ -3,180 +3,226 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import {
6
- BaseContainerRuntimeFactory,
7
- DataObject,
8
- DataObjectFactory,
9
- defaultRouteRequestHandler,
6
+ BaseContainerRuntimeFactory,
7
+ DataObject,
8
+ DataObjectFactory,
10
9
  } from "@fluidframework/aqueduct";
11
10
  import { IContainerRuntime } from "@fluidframework/container-runtime-definitions";
12
- import { IFluidLoadable } from "@fluidframework/core-interfaces";
11
+ import { IFluidLoadable, IRequest } from "@fluidframework/core-interfaces";
13
12
  import { FlushMode } from "@fluidframework/runtime-definitions";
14
- import { requestFluidObject } from "@fluidframework/runtime-utils";
13
+ import { IRuntimeFactory } from "@fluidframework/container-definitions";
14
+ import { RequestParser } from "@fluidframework/runtime-utils";
15
+ import { ContainerRuntime } from "@fluidframework/container-runtime";
15
16
  import {
16
- ContainerSchema,
17
- DataObjectClass,
18
- LoadableObjectClass,
19
- LoadableObjectClassRecord,
20
- LoadableObjectRecord,
21
- SharedObjectClass,
17
+ ContainerSchema,
18
+ IRootDataObject,
19
+ LoadableObjectClass,
20
+ LoadableObjectClassRecord,
21
+ LoadableObjectRecord,
22
+ SharedObjectClass,
22
23
  } from "./types";
23
- import { isDataObjectClass, isSharedObjectClass, parseDataObjectsFromSharedObjects } from "./utils";
24
+ import {
25
+ InternalDataObjectClass,
26
+ isDataObjectClass,
27
+ isSharedObjectClass,
28
+ parseDataObjectsFromSharedObjects,
29
+ } from "./utils";
24
30
 
25
31
  /**
26
- * Input props for {@link RootDataObject.initializingFirstTime}
32
+ * Input props for {@link RootDataObject.initializingFirstTime}.
27
33
  */
28
34
  export interface RootDataObjectProps {
29
- /**
30
- * Initial object structure with which the {@link RootDataObject} will be first-time initialized.
31
- * See {@link RootDataObject.initializingFirstTime}
32
- */
33
- initialObjects: LoadableObjectClassRecord;
35
+ /**
36
+ * Initial object structure with which the {@link RootDataObject} will be first-time initialized.
37
+ *
38
+ * @see {@link RootDataObject.initializingFirstTime}
39
+ */
40
+ initialObjects: LoadableObjectClassRecord;
34
41
  }
35
42
 
36
43
  /**
37
- * The entry-point/root collaborative object of the Fluid Container.
38
- * This class abstracts the dynamic code required to build a Fluid Container into a static representation
39
- * for end customers.
44
+ * The entry-point/root collaborative object of the {@link IFluidContainer | Fluid Container}.
45
+ * Abstracts the dynamic code required to build a Fluid Container into a static representation for end customers.
40
46
  */
41
- export class RootDataObject extends DataObject<{ InitialState: RootDataObjectProps; }> {
42
- private readonly initialObjectsDirKey = "initial-objects-key";
43
- private readonly _initialObjects: LoadableObjectRecord = {};
44
-
45
- private get initialObjectsDir() {
46
- const dir = this.root.getSubDirectory(this.initialObjectsDirKey);
47
- if (dir === undefined) {
48
- throw new Error("InitialObjects sub-directory was not initialized");
49
- }
50
- return dir;
51
- }
52
-
53
- /**
54
- * The first time this object is initialized, creates each object identified in
55
- * {@link RootDataObjectProps.initialObjects} and stores them as unique values in the root directory.
56
- *
57
- * See {@link @fluidframework/aqueduct#PureDataObject.initializingFirstTime}
58
- */
59
- protected async initializingFirstTime(props: RootDataObjectProps) {
60
- this.root.createSubDirectory(this.initialObjectsDirKey);
61
-
62
- // Create initial objects provided by the developer
63
- const initialObjectsP: Promise<void>[] = [];
64
- Object.entries(props.initialObjects).forEach(([id, objectClass]) => {
65
- const createObject = async () => {
66
- const obj = await this.create(objectClass);
67
- this.initialObjectsDir.set(id, obj.handle);
68
- };
69
- initialObjectsP.push(createObject());
70
- });
71
-
72
- await Promise.all(initialObjectsP);
73
- }
74
-
75
- /**
76
- * Every time an instance is initialized, loads all of the initial objects in the root directory so they can be
77
- * accessed immediately.
78
- *
79
- * See {@link @fluidframework/aqueduct#PureDataObject.hasInitialized}
80
- */
81
- protected async hasInitialized() {
82
- // We will always load the initial objects so they are available to the developer
83
- const loadInitialObjectsP: Promise<void>[] = [];
84
- for (const [key, value] of Array.from(this.initialObjectsDir.entries())) {
85
- const loadDir = async () => {
86
- const obj = await value.get();
87
- Object.assign(this._initialObjects, { [key]: obj });
88
- };
89
- loadInitialObjectsP.push(loadDir());
90
- }
91
-
92
- await Promise.all(loadInitialObjectsP);
93
- }
94
-
95
- /**
96
- * Provides a record of the initial objects defined on creation.
97
- * See {@link RootDataObject.initializingFirstTime}
98
- */
99
- public get initialObjects(): LoadableObjectRecord {
100
- if (Object.keys(this._initialObjects).length === 0) {
101
- throw new Error("Initial Objects were not correctly initialized");
102
- }
103
- return this._initialObjects;
104
- }
105
-
106
- /**
107
- * Dynamically creates a new detached collaborative object (DDS/DataObject).
108
- * @param objectClass - Type of the collaborative object to be created.
109
- */
110
- public async create<T extends IFluidLoadable>(
111
- objectClass: LoadableObjectClass<T>,
112
- ): Promise<T> {
113
- if (isDataObjectClass(objectClass)) {
114
- return this.createDataObject<T>(objectClass);
115
- } else if (isSharedObjectClass(objectClass)) {
116
- return this.createSharedObject<T>(objectClass);
117
- }
118
- throw new Error("Could not create new Fluid object because an unknown object was passed");
119
- }
120
-
121
- private async createDataObject<T extends IFluidLoadable>(dataObjectClass: DataObjectClass<T>): Promise<T> {
122
- const factory = dataObjectClass.factory;
123
- const packagePath = [...this.context.packagePath, factory.type];
124
- const router = await this.context.containerRuntime.createDataStore(packagePath);
125
- return requestFluidObject<T>(router, "/");
126
- }
127
-
128
- private createSharedObject<T extends IFluidLoadable>(
129
- sharedObjectClass: SharedObjectClass<T>,
130
- ): T {
131
- const factory = sharedObjectClass.getFactory();
132
- const obj = this.runtime.createChannel(undefined, factory.type);
133
- return obj as unknown as T;
134
- }
47
+ class RootDataObject
48
+ extends DataObject<{ InitialState: RootDataObjectProps }>
49
+ implements IRootDataObject
50
+ {
51
+ private readonly initialObjectsDirKey = "initial-objects-key";
52
+ private readonly _initialObjects: LoadableObjectRecord = {};
53
+ public get IRootDataObject() {
54
+ return this;
55
+ }
56
+
57
+ private get initialObjectsDir() {
58
+ const dir = this.root.getSubDirectory(this.initialObjectsDirKey);
59
+ if (dir === undefined) {
60
+ throw new Error("InitialObjects sub-directory was not initialized");
61
+ }
62
+ return dir;
63
+ }
64
+
65
+ /**
66
+ * The first time this object is initialized, creates each object identified in
67
+ * {@link RootDataObjectProps.initialObjects} and stores them as unique values in the root directory.
68
+ *
69
+ * @see {@link @fluidframework/aqueduct#PureDataObject.initializingFirstTime}
70
+ */
71
+ protected async initializingFirstTime(props: RootDataObjectProps) {
72
+ this.root.createSubDirectory(this.initialObjectsDirKey);
73
+
74
+ // Create initial objects provided by the developer
75
+ const initialObjectsP: Promise<void>[] = [];
76
+ Object.entries(props.initialObjects).forEach(([id, objectClass]) => {
77
+ const createObject = async () => {
78
+ const obj = await this.create(objectClass);
79
+ this.initialObjectsDir.set(id, obj.handle);
80
+ };
81
+ initialObjectsP.push(createObject());
82
+ });
83
+
84
+ await Promise.all(initialObjectsP);
85
+ }
86
+
87
+ /**
88
+ * Every time an instance is initialized, loads all of the initial objects in the root directory so they can be
89
+ * accessed immediately.
90
+ *
91
+ * @see {@link @fluidframework/aqueduct#PureDataObject.hasInitialized}
92
+ */
93
+ protected async hasInitialized() {
94
+ // We will always load the initial objects so they are available to the developer
95
+ const loadInitialObjectsP: Promise<void>[] = [];
96
+ for (const [key, value] of Array.from(this.initialObjectsDir.entries())) {
97
+ const loadDir = async () => {
98
+ const obj = await value.get();
99
+ Object.assign(this._initialObjects, { [key]: obj });
100
+ };
101
+ loadInitialObjectsP.push(loadDir());
102
+ }
103
+
104
+ await Promise.all(loadInitialObjectsP);
105
+ }
106
+
107
+ /**
108
+ * {@inheritDoc IRootDataObject.initialObjects}
109
+ */
110
+ public get initialObjects(): LoadableObjectRecord {
111
+ if (Object.keys(this._initialObjects).length === 0) {
112
+ throw new Error("Initial Objects were not correctly initialized");
113
+ }
114
+ return this._initialObjects;
115
+ }
116
+
117
+ /**
118
+ * {@inheritDoc IRootDataObject.create}
119
+ */
120
+ public async create<T extends IFluidLoadable>(objectClass: LoadableObjectClass<T>): Promise<T> {
121
+ if (isDataObjectClass(objectClass)) {
122
+ return this.createDataObject<T>(objectClass);
123
+ } else if (isSharedObjectClass(objectClass)) {
124
+ return this.createSharedObject<T>(objectClass);
125
+ }
126
+ throw new Error("Could not create new Fluid object because an unknown object was passed");
127
+ }
128
+
129
+ private async createDataObject<T extends IFluidLoadable>(
130
+ dataObjectClass: InternalDataObjectClass<T>,
131
+ ): Promise<T> {
132
+ const factory = dataObjectClass.factory;
133
+ const packagePath = [...this.context.packagePath, factory.type];
134
+ const dataStore = await this.context.containerRuntime.createDataStore(packagePath);
135
+ const entryPoint = await dataStore.entryPoint.get();
136
+ return entryPoint as unknown as T;
137
+ }
138
+
139
+ private createSharedObject<T extends IFluidLoadable>(
140
+ sharedObjectClass: SharedObjectClass<T>,
141
+ ): T {
142
+ const factory = sharedObjectClass.getFactory();
143
+ const obj = this.runtime.createChannel(undefined, factory.type);
144
+ return obj as unknown as T;
145
+ }
135
146
  }
136
147
 
137
148
  const rootDataStoreId = "rootDOId";
138
149
 
139
150
  /**
140
- * Container code that provides a single {@link RootDataObject}. This data object is
141
- * dynamically customized (registry and initial objects) based on the schema provided to the container runtime factory.
151
+ * @internal
152
+ */
153
+ export function createDOProviderContainerRuntimeFactory(props: {
154
+ schema: ContainerSchema;
155
+ }): IRuntimeFactory {
156
+ return new DOProviderContainerRuntimeFactory(props.schema);
157
+ }
158
+
159
+ /**
160
+ * Container code that provides a single {@link IRootDataObject}.
161
+ *
162
+ * @remarks
163
+ *
164
+ * This data object is dynamically customized (registry and initial objects) based on the schema provided.
165
+ * to the container runtime factory.
166
+ *
167
+ * @internal
142
168
  */
143
- export class DOProviderContainerRuntimeFactory extends BaseContainerRuntimeFactory {
144
- private readonly rootDataObjectFactory: DataObjectFactory<RootDataObject, {
145
- InitialState: RootDataObjectProps;
146
- }>;
147
-
148
- private readonly initialObjects: LoadableObjectClassRecord;
149
-
150
- constructor(schema: ContainerSchema) {
151
- const [registryEntries, sharedObjects] = parseDataObjectsFromSharedObjects(schema);
152
- const rootDataObjectFactory =
153
- new DataObjectFactory(
154
- "rootDO",
155
- RootDataObject,
156
- sharedObjects,
157
- {},
158
- registryEntries,
159
- );
160
- super(
161
- [rootDataObjectFactory.registryEntry],
162
- undefined,
163
- [defaultRouteRequestHandler(rootDataStoreId)],
164
- // temporary workaround to disable message batching until the message batch size issue is resolved
165
- // resolution progress is tracked by the Feature 465 work item in AzDO
166
- { flushMode: FlushMode.Immediate },
167
- );
168
- this.rootDataObjectFactory = rootDataObjectFactory;
169
- this.initialObjects = schema.initialObjects;
170
- }
171
-
172
- /**
173
- * {@inheritDoc @fluidframework/aqueduct#BaseContainerRuntimeFactory.containerInitializingFirstTime}
174
- */
175
- protected async containerInitializingFirstTime(runtime: IContainerRuntime) {
176
- // The first time we create the container we create the RootDataObject
177
- await this.rootDataObjectFactory.createRootInstance(
178
- rootDataStoreId,
179
- runtime,
180
- { initialObjects: this.initialObjects });
181
- }
169
+ class DOProviderContainerRuntimeFactory extends BaseContainerRuntimeFactory {
170
+ private readonly rootDataObjectFactory: DataObjectFactory<
171
+ RootDataObject,
172
+ {
173
+ InitialState: RootDataObjectProps;
174
+ }
175
+ >;
176
+
177
+ private readonly initialObjects: LoadableObjectClassRecord;
178
+
179
+ constructor(schema: ContainerSchema) {
180
+ const [registryEntries, sharedObjects] = parseDataObjectsFromSharedObjects(schema);
181
+ const rootDataObjectFactory = new DataObjectFactory(
182
+ "rootDO",
183
+ RootDataObject,
184
+ sharedObjects,
185
+ {},
186
+ registryEntries,
187
+ );
188
+ const provideEntryPoint = async (containerRuntime: IContainerRuntime) => {
189
+ const entryPoint =
190
+ await containerRuntime.getAliasedDataStoreEntryPoint(rootDataStoreId);
191
+ if (entryPoint === undefined) {
192
+ throw new Error(`default dataStore [${rootDataStoreId}] must exist`);
193
+ }
194
+ return entryPoint.get();
195
+ };
196
+ const getDefaultObject = async (request: IRequest, runtime: IContainerRuntime) => {
197
+ const parser = RequestParser.create(request);
198
+ if (parser.pathParts.length === 0) {
199
+ // This cast is safe as ContainerRuntime.loadRuntime is called in the base class
200
+ return (runtime as ContainerRuntime).resolveHandle({
201
+ url: `/${rootDataStoreId}${parser.query}`,
202
+ headers: request.headers,
203
+ });
204
+ }
205
+ return undefined; // continue search
206
+ };
207
+ super({
208
+ registryEntries: [rootDataObjectFactory.registryEntry],
209
+ requestHandlers: [getDefaultObject],
210
+ // temporary workaround to disable message batching until the message batch size issue is resolved
211
+ // resolution progress is tracked by the Feature 465 work item in AzDO
212
+ runtimeOptions: { flushMode: FlushMode.Immediate },
213
+ provideEntryPoint,
214
+ });
215
+ this.rootDataObjectFactory = rootDataObjectFactory;
216
+ this.initialObjects = schema.initialObjects;
217
+ }
218
+
219
+ /**
220
+ * {@inheritDoc @fluidframework/aqueduct#BaseContainerRuntimeFactory.containerInitializingFirstTime}
221
+ */
222
+ protected async containerInitializingFirstTime(runtime: IContainerRuntime) {
223
+ // The first time we create the container we create the RootDataObject
224
+ await this.rootDataObjectFactory.createRootInstance(rootDataStoreId, runtime, {
225
+ initialObjects: this.initialObjects,
226
+ });
227
+ }
182
228
  }