@fluidframework/fluid-static 2.50.0 → 2.51.0-347100
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/api-report/fluid-static.alpha.api.md +17 -0
- package/dist/fluidContainer.d.ts +1 -1
- package/dist/fluidContainer.d.ts.map +1 -1
- package/dist/fluidContainer.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/rootDataObject.d.ts +6 -3
- package/dist/rootDataObject.d.ts.map +1 -1
- package/dist/rootDataObject.js +27 -44
- package/dist/rootDataObject.js.map +1 -1
- package/dist/treeRootDataObject.d.ts +47 -0
- package/dist/treeRootDataObject.d.ts.map +1 -0
- package/dist/treeRootDataObject.js +157 -0
- package/dist/treeRootDataObject.js.map +1 -0
- package/dist/types.d.ts +23 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +29 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +62 -3
- package/dist/utils.js.map +1 -1
- package/lib/fluidContainer.d.ts +1 -1
- package/lib/fluidContainer.d.ts.map +1 -1
- package/lib/fluidContainer.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/rootDataObject.d.ts +6 -3
- package/lib/rootDataObject.d.ts.map +1 -1
- package/lib/rootDataObject.js +25 -42
- package/lib/rootDataObject.js.map +1 -1
- package/lib/treeRootDataObject.d.ts +47 -0
- package/lib/treeRootDataObject.d.ts.map +1 -0
- package/lib/treeRootDataObject.js +153 -0
- package/lib/treeRootDataObject.js.map +1 -0
- package/lib/types.d.ts +23 -8
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils.d.ts +29 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +55 -0
- package/lib/utils.js.map +1 -1
- package/package.json +21 -20
- package/src/fluidContainer.ts +1 -1
- package/src/index.ts +3 -0
- package/src/rootDataObject.ts +46 -69
- package/src/treeRootDataObject.ts +249 -0
- package/src/types.ts +30 -9
- package/src/utils.ts +90 -4
package/src/utils.ts
CHANGED
|
@@ -4,13 +4,27 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { DataObjectKind } from "@fluidframework/aqueduct/internal";
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import
|
|
7
|
+
import type { MinimumVersionForCollab } from "@fluidframework/container-runtime/internal";
|
|
8
|
+
import type { FluidObjectKeys, IFluidLoadable } from "@fluidframework/core-interfaces";
|
|
9
|
+
import { oob } from "@fluidframework/core-utils/internal";
|
|
10
|
+
import type {
|
|
11
|
+
IChannelFactory,
|
|
12
|
+
IFluidDataStoreRuntime,
|
|
13
|
+
} from "@fluidframework/datastore-definitions/internal";
|
|
14
|
+
import type {
|
|
15
|
+
IFluidDataStoreContext,
|
|
16
|
+
NamedFluidDataStoreRegistryEntry,
|
|
17
|
+
} from "@fluidframework/runtime-definitions/internal";
|
|
10
18
|
import type { ISharedObjectKind } from "@fluidframework/shared-object-base/internal";
|
|
11
19
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
20
|
+
import { SharedTreeFactoryType } from "@fluidframework/tree/internal";
|
|
12
21
|
|
|
13
|
-
import type {
|
|
22
|
+
import type {
|
|
23
|
+
CompatibilityMode,
|
|
24
|
+
ContainerSchema,
|
|
25
|
+
LoadableObjectKind,
|
|
26
|
+
TreeContainerSchema,
|
|
27
|
+
} from "./types.js";
|
|
14
28
|
|
|
15
29
|
/**
|
|
16
30
|
* Runtime check to determine if an object is a {@link DataObjectKind}.
|
|
@@ -94,3 +108,75 @@ export const parseDataObjectsFromSharedObjects = (
|
|
|
94
108
|
|
|
95
109
|
return [[...registryEntries], [...sharedObjects]];
|
|
96
110
|
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Creates a new data object of the specified type.
|
|
114
|
+
*/
|
|
115
|
+
export async function createDataObject<T extends IFluidLoadable>(
|
|
116
|
+
dataObjectClass: DataObjectKind<T>,
|
|
117
|
+
context: IFluidDataStoreContext,
|
|
118
|
+
): Promise<T> {
|
|
119
|
+
const factory = dataObjectClass.factory;
|
|
120
|
+
const packagePath = [...context.packagePath, factory.type];
|
|
121
|
+
const dataStore = await context.containerRuntime.createDataStore(packagePath);
|
|
122
|
+
const entryPoint = await dataStore.entryPoint.get();
|
|
123
|
+
return entryPoint as T;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Creates a new shared object of the specified type.
|
|
128
|
+
*/
|
|
129
|
+
export function createSharedObject<T extends IFluidLoadable>(
|
|
130
|
+
sharedObjectClass: ISharedObjectKind<T>,
|
|
131
|
+
runtime: IFluidDataStoreRuntime,
|
|
132
|
+
): T {
|
|
133
|
+
const factory = sharedObjectClass.getFactory();
|
|
134
|
+
const obj = runtime.createChannel(undefined, factory.type);
|
|
135
|
+
return obj as unknown as T;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Creates a Fluid object that has a property with the key `providerKey` that points to itself.
|
|
140
|
+
* @remarks This is useful for creating objects that need to reference themselves, such as DataObjects.
|
|
141
|
+
*/
|
|
142
|
+
export function makeFluidObject<
|
|
143
|
+
T extends object,
|
|
144
|
+
K extends FluidObjectKeys<T> = FluidObjectKeys<T>,
|
|
145
|
+
>(object: Omit<T, K>, providerKey: K): T {
|
|
146
|
+
return Object.defineProperty(object, providerKey, { value: object }) as T;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Maps CompatibilityMode to a semver valid string that can be passed to the container runtime.
|
|
151
|
+
*/
|
|
152
|
+
export const compatibilityModeToMinVersionForCollab = {
|
|
153
|
+
"1": "1.0.0",
|
|
154
|
+
"2": "2.0.0",
|
|
155
|
+
} as const satisfies Record<CompatibilityMode, MinimumVersionForCollab>;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Determines if the provided schema is a valid tree-based container schema.
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
export function isTreeContainerSchema(schema: ContainerSchema): schema is TreeContainerSchema {
|
|
162
|
+
const schemaEntries = Object.entries(schema.initialObjects);
|
|
163
|
+
if (schemaEntries.length !== 1) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const entry = schemaEntries[0] ?? oob();
|
|
168
|
+
const key = entry[0];
|
|
169
|
+
if (key !== "tree") {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const objectKind = entry[1] as unknown as LoadableObjectKind;
|
|
174
|
+
if (
|
|
175
|
+
isSharedObjectKind(objectKind) &&
|
|
176
|
+
objectKind.getFactory().type === SharedTreeFactoryType
|
|
177
|
+
) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return false;
|
|
182
|
+
}
|