@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.
Files changed (52) hide show
  1. package/api-report/fluid-static.alpha.api.md +17 -0
  2. package/dist/fluidContainer.d.ts +1 -1
  3. package/dist/fluidContainer.d.ts.map +1 -1
  4. package/dist/fluidContainer.js.map +1 -1
  5. package/dist/index.d.ts +3 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/rootDataObject.d.ts +6 -3
  10. package/dist/rootDataObject.d.ts.map +1 -1
  11. package/dist/rootDataObject.js +27 -44
  12. package/dist/rootDataObject.js.map +1 -1
  13. package/dist/treeRootDataObject.d.ts +47 -0
  14. package/dist/treeRootDataObject.d.ts.map +1 -0
  15. package/dist/treeRootDataObject.js +157 -0
  16. package/dist/treeRootDataObject.js.map +1 -0
  17. package/dist/types.d.ts +23 -8
  18. package/dist/types.d.ts.map +1 -1
  19. package/dist/types.js.map +1 -1
  20. package/dist/utils.d.ts +29 -4
  21. package/dist/utils.d.ts.map +1 -1
  22. package/dist/utils.js +62 -3
  23. package/dist/utils.js.map +1 -1
  24. package/lib/fluidContainer.d.ts +1 -1
  25. package/lib/fluidContainer.d.ts.map +1 -1
  26. package/lib/fluidContainer.js.map +1 -1
  27. package/lib/index.d.ts +3 -1
  28. package/lib/index.d.ts.map +1 -1
  29. package/lib/index.js +2 -0
  30. package/lib/index.js.map +1 -1
  31. package/lib/rootDataObject.d.ts +6 -3
  32. package/lib/rootDataObject.d.ts.map +1 -1
  33. package/lib/rootDataObject.js +25 -42
  34. package/lib/rootDataObject.js.map +1 -1
  35. package/lib/treeRootDataObject.d.ts +47 -0
  36. package/lib/treeRootDataObject.d.ts.map +1 -0
  37. package/lib/treeRootDataObject.js +153 -0
  38. package/lib/treeRootDataObject.js.map +1 -0
  39. package/lib/types.d.ts +23 -8
  40. package/lib/types.d.ts.map +1 -1
  41. package/lib/types.js.map +1 -1
  42. package/lib/utils.d.ts +29 -4
  43. package/lib/utils.d.ts.map +1 -1
  44. package/lib/utils.js +55 -0
  45. package/lib/utils.js.map +1 -1
  46. package/package.json +21 -20
  47. package/src/fluidContainer.ts +1 -1
  48. package/src/index.ts +3 -0
  49. package/src/rootDataObject.ts +46 -69
  50. package/src/treeRootDataObject.ts +249 -0
  51. package/src/types.ts +30 -9
  52. 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 { IFluidLoadable } from "@fluidframework/core-interfaces";
8
- import type { IChannelFactory } from "@fluidframework/datastore-definitions/internal";
9
- import type { NamedFluidDataStoreRegistryEntry } from "@fluidframework/runtime-definitions/internal";
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 { ContainerSchema, LoadableObjectKind } from "./types.js";
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
+ }