@fluidframework/fluid-static 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.225277
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +8 -10
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +225 -53
- package/README.md +38 -0
- package/api-extractor-esm.json +4 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +2 -2
- package/api-report/fluid-static.api.md +141 -0
- package/dist/fluid-static-alpha.d.ts +408 -0
- package/dist/fluid-static-beta.d.ts +412 -0
- package/dist/fluid-static-public.d.ts +412 -0
- package/dist/fluid-static-untrimmed.d.ts +452 -0
- package/dist/{fluidContainer.js → fluidContainer.cjs} +39 -12
- package/dist/fluidContainer.cjs.map +1 -0
- package/dist/fluidContainer.d.ts +95 -142
- package/dist/fluidContainer.d.ts.map +1 -1
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/{rootDataObject.js → rootDataObject.cjs} +59 -23
- package/dist/rootDataObject.cjs.map +1 -0
- package/dist/rootDataObject.d.ts +9 -59
- package/dist/rootDataObject.d.ts.map +1 -1
- package/dist/{serviceAudience.js → serviceAudience.cjs} +44 -20
- package/dist/serviceAudience.cjs.map +1 -0
- package/dist/serviceAudience.d.ts +7 -54
- package/dist/serviceAudience.d.ts.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/{types.js → types.cjs} +1 -1
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +130 -80
- package/dist/types.d.ts.map +1 -1
- package/dist/{utils.js → utils.cjs} +7 -9
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +10 -2
- package/dist/utils.d.ts.map +1 -1
- package/lib/fluid-static-alpha.d.mts +402 -0
- package/lib/fluid-static-beta.d.mts +406 -0
- package/lib/fluid-static-public.d.mts +406 -0
- package/lib/fluid-static-untrimmed.d.mts +446 -0
- package/lib/fluidContainer.d.mts +188 -0
- package/lib/fluidContainer.d.mts.map +1 -0
- package/lib/{fluidContainer.js → fluidContainer.mjs} +36 -13
- package/lib/fluidContainer.mjs.map +1 -0
- package/lib/index.d.mts +9 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +8 -0
- package/lib/index.mjs.map +1 -0
- package/lib/rootDataObject.d.mts +20 -0
- package/lib/rootDataObject.d.mts.map +1 -0
- package/lib/{rootDataObject.js → rootDataObject.mjs} +61 -28
- package/lib/rootDataObject.mjs.map +1 -0
- package/lib/serviceAudience.d.mts +15 -0
- package/lib/serviceAudience.d.mts.map +1 -0
- package/lib/{serviceAudience.js → serviceAudience.mjs} +42 -18
- package/lib/serviceAudience.mjs.map +1 -0
- package/lib/types.d.mts +223 -0
- package/lib/types.d.mts.map +1 -0
- package/lib/{types.js → types.mjs} +1 -1
- package/lib/types.mjs.map +1 -0
- package/lib/{utils.d.ts → utils.d.mts} +12 -4
- package/lib/utils.d.mts.map +1 -0
- package/lib/{utils.js → utils.mjs} +7 -9
- package/lib/utils.mjs.map +1 -0
- package/package.json +151 -60
- package/prettier.config.cjs +8 -0
- package/src/fluidContainer.ts +316 -250
- package/src/index.ts +25 -4
- package/src/rootDataObject.ts +203 -157
- package/src/serviceAudience.ts +152 -124
- package/src/types.ts +190 -132
- package/src/utils.ts +44 -39
- package/tsc-multi.test.json +4 -0
- package/tsconfig.json +12 -16
- package/dist/fluidContainer.js.map +0 -1
- package/dist/index.js +0 -26
- package/dist/index.js.map +0 -1
- package/dist/rootDataObject.js.map +0 -1
- package/dist/serviceAudience.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.js.map +0 -1
- package/lib/fluidContainer.d.ts +0 -235
- package/lib/fluidContainer.d.ts.map +0 -1
- package/lib/fluidContainer.js.map +0 -1
- package/lib/index.d.ts +0 -14
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -14
- package/lib/index.js.map +0 -1
- package/lib/rootDataObject.d.ts +0 -70
- package/lib/rootDataObject.d.ts.map +0 -1
- package/lib/rootDataObject.js.map +0 -1
- package/lib/serviceAudience.d.ts +0 -62
- package/lib/serviceAudience.d.ts.map +0 -1
- package/lib/serviceAudience.js.map +0 -1
- package/lib/types.d.ts +0 -173
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
- package/tsconfig.esnext.json +0 -7
package/src/rootDataObject.ts
CHANGED
|
@@ -3,180 +3,226 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 {
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
ContainerSchema,
|
|
18
|
+
IRootDataObject,
|
|
19
|
+
LoadableObjectClass,
|
|
20
|
+
LoadableObjectClassRecord,
|
|
21
|
+
LoadableObjectRecord,
|
|
22
|
+
SharedObjectClass,
|
|
22
23
|
} from "./types";
|
|
23
|
-
import {
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
*
|
|
141
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
}
|