@fluidframework/shared-object-base 2.113.0-411909 → 2.114.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.
- package/CHANGELOG.md +73 -0
- package/dist/dataStoreKind.d.ts +118 -0
- package/dist/dataStoreKind.d.ts.map +1 -0
- package/dist/dataStoreKind.js +137 -0
- package/dist/dataStoreKind.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sharedObject.d.ts +35 -1
- package/dist/sharedObject.d.ts.map +1 -1
- package/dist/sharedObject.js +27 -3
- package/dist/sharedObject.js.map +1 -1
- package/dist/sharedObjectKernel.d.ts +2 -2
- package/dist/sharedObjectKernel.d.ts.map +1 -1
- package/dist/sharedObjectKernel.js +1 -1
- package/dist/sharedObjectKernel.js.map +1 -1
- package/dist/stubSharedObject.d.ts +13 -0
- package/dist/stubSharedObject.d.ts.map +1 -0
- package/dist/stubSharedObject.js +58 -0
- package/dist/stubSharedObject.js.map +1 -0
- package/lib/dataStoreKind.d.ts +118 -0
- package/lib/dataStoreKind.d.ts.map +1 -0
- package/lib/dataStoreKind.js +132 -0
- package/lib/dataStoreKind.js.map +1 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/sharedObject.d.ts +35 -1
- package/lib/sharedObject.d.ts.map +1 -1
- package/lib/sharedObject.js +25 -2
- package/lib/sharedObject.js.map +1 -1
- package/lib/sharedObjectKernel.d.ts +2 -2
- package/lib/sharedObjectKernel.d.ts.map +1 -1
- package/lib/sharedObjectKernel.js +2 -2
- package/lib/sharedObjectKernel.js.map +1 -1
- package/lib/stubSharedObject.d.ts +13 -0
- package/lib/stubSharedObject.d.ts.map +1 -0
- package/lib/stubSharedObject.js +54 -0
- package/lib/stubSharedObject.js.map +1 -0
- package/package.json +20 -20
- package/src/dataStoreKind.ts +301 -0
- package/src/index.ts +11 -0
- package/src/packageVersion.ts +1 -1
- package/src/sharedObject.ts +60 -2
- package/src/sharedObjectKernel.ts +4 -4
- package/src/stubSharedObject.ts +66 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,78 @@
|
|
|
1
1
|
# @fluidframework/shared-object-base
|
|
2
2
|
|
|
3
|
+
## 2.114.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add new @alpha ServiceClient API for creating and loading Fluid containers ([#27693](https://github.com/microsoft/FluidFramework/pull/27693)) [ee47192d4a](https://github.com/microsoft/FluidFramework/commit/ee47192d4ae91bc28f9154c4d1ead2acad762f3c)
|
|
8
|
+
|
|
9
|
+
This introduces an experimental (`@alpha`), service-agnostic API for working with Fluid containers whose root is an arbitrary data store, along with an in-memory implementation for testing.
|
|
10
|
+
|
|
11
|
+
The new surface is made up of:
|
|
12
|
+
- `ServiceClient` (`@fluidframework/driver-definitions`): the entry point for creating and loading containers. Along with it come the supporting container types (`FluidContainer`, `FluidContainerWithService`, `FluidContainerAttached`), the data store model (`DataStoreKind`, `DataStoreKey`, `DataStoreRegistry`, `DataStoreCreator`), and the generic registry primitives (`Registry`, `RegistryKey`, `lookupInRegistry`, `createBasicRegistryKey`).
|
|
13
|
+
- `defineDataStore` and `sharedObjectRegistryFromIterable` (`@fluidframework/shared-object-base`): build a `DataStoreKind` from a root shared object and a registry of shared object kinds.
|
|
14
|
+
- `defineTreeDataStore` and `instantiateTreeFirstTime` (`@fluidframework/tree`): a SharedTree-specific convenience wrapper that produces a `DataStoreKind` backed by a `TreeView`.
|
|
15
|
+
- `startEphemeralService` (`@fluidframework/local-driver`): starts an in-memory `EphemeralService` for tests. The service owns the lifetime of the in-memory documents and resources, and produces `ServiceClient`s connected to it (via `EphemeralService.newClient` or `EphemeralService.defaultClient`). The helpers `cleanupEphemeralService` and `getDefaultEphemeralService` manage an optional default service instance.
|
|
16
|
+
|
|
17
|
+
Apart from the `@fluidframework/local-driver` helpers (which come from `@fluidframework/local-driver/alpha`), these APIs are also re-exported from `fluid-framework`. None reference any `@legacy` types.
|
|
18
|
+
|
|
19
|
+
Example:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { startEphemeralService } from "@fluidframework/local-driver/alpha";
|
|
23
|
+
import {
|
|
24
|
+
ServiceClient,
|
|
25
|
+
defineTreeDataStore,
|
|
26
|
+
TreeViewConfiguration,
|
|
27
|
+
SchemaFactory,
|
|
28
|
+
} from "fluid-framework/alpha";
|
|
29
|
+
import { strict as assert } from "node:assert";
|
|
30
|
+
|
|
31
|
+
// Start an ephemeral in-memory service and get a ServiceClient connected to it.
|
|
32
|
+
const service = startEphemeralService();
|
|
33
|
+
const client: ServiceClient = service.defaultClient;
|
|
34
|
+
// Define a DataStoreKind which uses a SharedTree.
|
|
35
|
+
// In this case the schema is for a single number with an initializer that starts the it at 1.
|
|
36
|
+
// This schema is captures in the type allowing for strongly typed access to the data in the tree,
|
|
37
|
+
// where the type matches the schema based runtime enforcement of the schema.
|
|
38
|
+
const numberStore = defineTreeDataStore({
|
|
39
|
+
type: "my-app-root",
|
|
40
|
+
config: new TreeViewConfiguration({ schema: SchemaFactory.number }),
|
|
41
|
+
initializer: () => 1,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Create a container in the service with the above DataStoreKind.
|
|
45
|
+
// Ideally this creation would use a service independent API, and only the attach call would be service dependent,
|
|
46
|
+
// but that is not supported yet.
|
|
47
|
+
const detachedContainer1 = await client.createContainer(numberStore);
|
|
48
|
+
const container1 = await detachedContainer1.attach();
|
|
49
|
+
|
|
50
|
+
// We now have easy and type safe access to the data in the tree, which will be synced over the service.
|
|
51
|
+
assert.equal(container1.data.root, 1);
|
|
52
|
+
|
|
53
|
+
// A second client can load the same container from the service, and will see the same data.
|
|
54
|
+
const container2 = await client.loadContainer(container1.id, numberStore);
|
|
55
|
+
assert.equal(container2.data.root, 1);
|
|
56
|
+
|
|
57
|
+
// Both clients can modify the data, and the changes will be synced over the service.
|
|
58
|
+
container2.data.root = 2;
|
|
59
|
+
// Since we are using an ephemeral service, we can await the synchronization using service.synchronize.
|
|
60
|
+
await service.synchronize();
|
|
61
|
+
|
|
62
|
+
// And now the changes are visible for all clients.
|
|
63
|
+
assert.equal(container1.data.root, 2);
|
|
64
|
+
assert.equal(container2.data.root, 2);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Note that this example does a couple of things which are difficult to do with the other API surfaces:
|
|
68
|
+
1. It creates a container, then loads a second copy of it, allowing for collaboration. There is currently no non-legacy API surface which allows this without spawning a server process. This is also cleaner than the exacting legacy API options, and can replace the test specific APIs for this as well.
|
|
69
|
+
2. It creates a container which has a SharedTree at the root, and nothing else. This avoids depending on legacy DDS implementations, which is great for long-term document support and bundle size. This is currently impossible using `fluid-static`, which forces a special root data store. It is also impossible if using `aqueduct`, which forces a root directory in every data store. It can be done using the low level legacy APIs directly, but this new API for it is much simpler.
|
|
70
|
+
3. There is a common interface all services implement (`ServiceClient`), making the container creation part of the code work for any service implementation.
|
|
71
|
+
|
|
72
|
+
## 2.113.0
|
|
73
|
+
|
|
74
|
+
Dependency updates only.
|
|
75
|
+
|
|
3
76
|
## 2.112.0
|
|
4
77
|
|
|
5
78
|
Dependency updates only.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { IFluidLoadable } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { type Registry, type DataStoreKind } from "@fluidframework/driver-definitions/internal";
|
|
7
|
+
import type { SharedObjectKey, SharedObjectKindAlpha } from "./sharedObject.js";
|
|
8
|
+
/**
|
|
9
|
+
* This file provides the implementation of {@link @fluidframework/driver-definitions#DataStoreKind}
|
|
10
|
+
* and is therefore a key part of the implementation of the {@link @fluidframework/driver-definitions#ServiceClient} API surface.
|
|
11
|
+
*
|
|
12
|
+
* Note that much of the API surface beyond {@link defineDataStore} could be removed/deduplicated
|
|
13
|
+
* if the unification noted in the TODOs in {@link SharedObjectRegistry} is implemented.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* A {@link @fluidframework/driver-definitions#Registry} of shared object kinds that can be created or loaded within a data store.
|
|
17
|
+
* @remarks
|
|
18
|
+
* Supports lazy code loading in a limited way (a single lazy load per registry).
|
|
19
|
+
* @privateRemarks
|
|
20
|
+
* TODO: The framework provided SharedObjects should be exposed in a way indistinguishable from custom sub-data stores.
|
|
21
|
+
* This can be done by unifying the DataStoreKind and SharedObjectKindAlpha types.
|
|
22
|
+
* For now, this would mean having DataStoreKind extend SharedObjectKindAlpha, since we can allow a data store in all places SharedObjects are allowed,
|
|
23
|
+
* but do not allow SharedObjects at the root.
|
|
24
|
+
* Fixing this, and allowing shared objects at the root (maybe use a trivial wrapper data store) could simplify things, allowing data stores and Containers to share some types (like how they create detached contents, have registries, have a root etc).
|
|
25
|
+
*
|
|
26
|
+
* Part of this unification could be to relax the output from the factories / registries. Allowing the output to be an arbitrary type, which might be a promise, and might not be one could help.
|
|
27
|
+
* Removal of the IFluidLoadable requirement, and allowing the returned type to expose handles to itself however it wants (or not at all) might be viable and simplify typing and allow for strongly typed handles at creation time at least).
|
|
28
|
+
* Maybe when Registry(type) gives a promise, it could instead give a factory which outputs a promise wrapped type? The check that the provided creation key is valid for that factory can be deferred until the promise resolves.
|
|
29
|
+
*
|
|
30
|
+
* Idea: creation key can have an interface that subsets the factory / SharedObjectKindAlpha / DataStoreKind so they can be used, or some branded key (string, and/or object with stronger identity what knows the type string) can be used.
|
|
31
|
+
* Have Key interface contain validation function to check that the factory used (or maybe the value produced from it) is valid for that key.
|
|
32
|
+
* During load, validation would simply check the factory's type string matches the key's type string.
|
|
33
|
+
* When using SharedObjectKindAlpha or DataStoreKind, validation can check factory object identity against key.
|
|
34
|
+
*
|
|
35
|
+
* Goal: Mostly unify container, data store and shared object abstractions.
|
|
36
|
+
* Maybe unify a bit with service client since it also has a way to create detached things with an initialized root then attach them.
|
|
37
|
+
* SharedObjects are just built in leaf data stores.
|
|
38
|
+
*
|
|
39
|
+
* @input
|
|
40
|
+
* @alpha
|
|
41
|
+
*/
|
|
42
|
+
export type SharedObjectRegistry = () => Promise<Registry<SharedObjectKindAlpha<IFluidLoadable>>>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a {@link SharedObjectRegistry} from an iterable of {@link SharedObjectKindAlpha}s or async getters for them.
|
|
45
|
+
* @alpha
|
|
46
|
+
*/
|
|
47
|
+
export declare function sharedObjectRegistryFromIterable(entries: Iterable<SharedObjectKindAlpha<IFluidLoadable> | {
|
|
48
|
+
type: string;
|
|
49
|
+
kind: () => Promise<SharedObjectKindAlpha<IFluidLoadable>>;
|
|
50
|
+
}>): SharedObjectRegistry;
|
|
51
|
+
/**
|
|
52
|
+
* Options which define how to construct a particular {@link @fluidframework/driver-definitions#DataStoreKind}.
|
|
53
|
+
* @remarks
|
|
54
|
+
* Use {@link defineDataStore} to create a {@link @fluidframework/driver-definitions#DataStoreKind} from these options.
|
|
55
|
+
* @input
|
|
56
|
+
* @alpha
|
|
57
|
+
*/
|
|
58
|
+
export interface DataStoreOptions<in out TRoot extends IFluidLoadable, out TOutput> {
|
|
59
|
+
/**
|
|
60
|
+
* The type identifier for the data object factory.
|
|
61
|
+
* @remarks
|
|
62
|
+
* Persisted identifier which specifies which {@link @fluidframework/driver-definitions#DataStoreKind} to use when loading it.
|
|
63
|
+
* @privateRemarks
|
|
64
|
+
* Equivalent to `DataObjectFactoryProps.type`.
|
|
65
|
+
*/
|
|
66
|
+
readonly type: string;
|
|
67
|
+
/**
|
|
68
|
+
* The registry of shared object kinds (including other data stores) that can be loaded or created within this data store.
|
|
69
|
+
*
|
|
70
|
+
* TODO: actually allow this to contain data stores.
|
|
71
|
+
*/
|
|
72
|
+
readonly registry: SharedObjectRegistry;
|
|
73
|
+
/**
|
|
74
|
+
* Create the initial content of the data store, and return the root shared object.
|
|
75
|
+
* @privateRemarks
|
|
76
|
+
* TODO:
|
|
77
|
+
* This requires the caller to produce a single root shared object (which is keyed by {@link rootSharedObjectId}).
|
|
78
|
+
* This should be fine for new code, but code migrated from legacy APIs might need more flexibility.
|
|
79
|
+
* Such use-cases could be accommodated providing a legacy alternative to `defineDataStore` where `instantiateFirstTime` and `view` directly expose access to named root shared objects.
|
|
80
|
+
* This should be easy to implement, but is currently not included.
|
|
81
|
+
*/
|
|
82
|
+
instantiateFirstTime(rootCreator: SharedObjectCreator<TRoot>, context: DataStoreContext): Promise<TRoot>;
|
|
83
|
+
/**
|
|
84
|
+
* Construct a view of the data store's root shared object.
|
|
85
|
+
*
|
|
86
|
+
* @param root - The root shared object of the data store, created by `instantiateFirstTime` (though possibly created by another client and loaded by this one).
|
|
87
|
+
* @param context - A {@link DataStoreContext} that can be used to create additional shared objects.
|
|
88
|
+
*/
|
|
89
|
+
view(root: TRoot, context: DataStoreContext): Promise<TOutput>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Creates a {@link @fluidframework/driver-definitions#DataStoreKind} from {@link DataStoreOptions}.
|
|
93
|
+
* @alpha
|
|
94
|
+
*/
|
|
95
|
+
export declare function defineDataStore<T, TRoot extends IFluidLoadable>(options: DataStoreOptions<TRoot, T>): DataStoreKind<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Creates instances of SharedObjectKinds.
|
|
98
|
+
* @privateRemarks
|
|
99
|
+
* See IFluidContainer.create.
|
|
100
|
+
* @sealed
|
|
101
|
+
* @alpha
|
|
102
|
+
*/
|
|
103
|
+
export interface SharedObjectCreator<TConstraint = IFluidLoadable> {
|
|
104
|
+
/**
|
|
105
|
+
* Create an instance of `kind`, which must be registered in the registry of the surrounding data store.
|
|
106
|
+
*/
|
|
107
|
+
createSharedObject<T extends TConstraint>(kind: SharedObjectKey<T>): Promise<T>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Contextual information about a data store which is provided when instantiating or loading it.
|
|
111
|
+
* @privateRemarks
|
|
112
|
+
* TODO: this can expose more contextual information about the data store as needed.
|
|
113
|
+
* @sealed
|
|
114
|
+
* @alpha
|
|
115
|
+
*/
|
|
116
|
+
export interface DataStoreContext extends SharedObjectCreator {
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=dataStoreKind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataStoreKind.d.ts","sourceRoot":"","sources":["../src/dataStoreKind.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,iCAAiC,CAAC;AAMnF,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,aAAa,EAElB,MAAM,6CAA6C,CAAC;AAQrD,OAAO,KAAK,EAEX,eAAe,EACf,qBAAqB,EACrB,MAAM,mBAAmB,CAAC;AAG3B;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,OAAO,CAC/C,QAAQ,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC,CAC/C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gCAAgC,CAC/C,OAAO,EAAE,QAAQ,CACd,qBAAqB,CAAC,cAAc,CAAC,GACrC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC,CAAA;CAAE,CAC9E,GACC,oBAAoB,CAkBtB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,SAAS,cAAc,EAAE,GAAG,CAAC,OAAO;IACjF;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IAExC;;;;;;;;OAQG;IACH,oBAAoB,CACnB,WAAW,EAAE,mBAAmB,CAAC,KAAK,CAAC,EACvC,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,KAAK,CAAC,CAAC;IAElB;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,SAAS,cAAc,EAC9D,OAAO,EAAE,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC,GACjC,aAAa,CAAC,CAAC,CAAC,CAUlB;AAsHD;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB,CAAC,WAAW,GAAG,cAAc;IAChE;;OAEG;IACH,kBAAkB,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAChF;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB;CAAG"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.defineDataStore = exports.sharedObjectRegistryFromIterable = void 0;
|
|
8
|
+
const internal_1 = require("@fluidframework/datastore/internal");
|
|
9
|
+
const internal_2 = require("@fluidframework/driver-definitions/internal");
|
|
10
|
+
const internal_3 = require("@fluidframework/runtime-utils/internal");
|
|
11
|
+
const internal_4 = require("@fluidframework/telemetry-utils/internal");
|
|
12
|
+
/**
|
|
13
|
+
* Creates a {@link SharedObjectRegistry} from an iterable of {@link SharedObjectKindAlpha}s or async getters for them.
|
|
14
|
+
* @alpha
|
|
15
|
+
*/
|
|
16
|
+
function sharedObjectRegistryFromIterable(entries) {
|
|
17
|
+
return async () => {
|
|
18
|
+
const map = new Map();
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
if ("kind" in entry) {
|
|
21
|
+
map.set(entry.type, await entry.kind());
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
map.set(asSharedObjectKind(entry).getFactory().type, entry);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return (type) => {
|
|
28
|
+
const entry = map.get(type);
|
|
29
|
+
if (entry === undefined) {
|
|
30
|
+
throw new internal_4.UsageError(`Unknown shared object type: ${type}`);
|
|
31
|
+
}
|
|
32
|
+
return entry;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.sharedObjectRegistryFromIterable = sharedObjectRegistryFromIterable;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a {@link @fluidframework/driver-definitions#DataStoreKind} from {@link DataStoreOptions}.
|
|
39
|
+
* @alpha
|
|
40
|
+
*/
|
|
41
|
+
function defineDataStore(options) {
|
|
42
|
+
return new internal_3.DataStoreKindImplementation({
|
|
43
|
+
type: options.type,
|
|
44
|
+
async instantiateDataStore(context, existing) {
|
|
45
|
+
return createDataStore(context, existing, options);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.defineDataStore = defineDataStore;
|
|
50
|
+
/**
|
|
51
|
+
* Casts a {@link SharedObjectKindAlpha} to its encapsulated {@link ISharedObjectKind} view.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* {@link SharedObjectKindAlpha} is a sealed type,
|
|
55
|
+
* so we can assume it implements {@link ISharedObjectKind} and down cast to it.
|
|
56
|
+
*/
|
|
57
|
+
function asSharedObjectKind(kind) {
|
|
58
|
+
const candidate = kind;
|
|
59
|
+
// Sanity check to help catch misuse since SharedObjectKindAlpha is typed structurally and seems implementable.
|
|
60
|
+
if (typeof candidate.getFactory !== "function" || typeof candidate.create !== "function") {
|
|
61
|
+
throw new internal_4.UsageError("Invalid SharedObjectKindAlpha: this type is sealed and may not have custom implementations.");
|
|
62
|
+
}
|
|
63
|
+
return candidate;
|
|
64
|
+
}
|
|
65
|
+
function convertRegistry(lookup) {
|
|
66
|
+
return {
|
|
67
|
+
get: (type) => {
|
|
68
|
+
const entry = lookup(type);
|
|
69
|
+
return asSharedObjectKind(entry).getFactory();
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Data stores keep their shared objects inside channels which get names.
|
|
75
|
+
* This is the name of the channel which we conventionally use for the root shared object of a data store in most cases.
|
|
76
|
+
* @remarks
|
|
77
|
+
* There can be other named channels, or the root could use a different name, but we are trying to migrate away from such patterns.
|
|
78
|
+
* Currently the DataStoreKind pattern used in this file follows and requires this convention,
|
|
79
|
+
* but we may relax that in the future for interop with legacy data if necessary.
|
|
80
|
+
*/
|
|
81
|
+
const rootSharedObjectId = "root";
|
|
82
|
+
/**
|
|
83
|
+
* Creates a data store channel.
|
|
84
|
+
* @param context - The data store context.
|
|
85
|
+
* @param existing - Whether the data store already exists. When true, this loads it, when false a new one is created.
|
|
86
|
+
* @param options - The data store options.
|
|
87
|
+
* @returns A promise that resolves to the created data store channel.
|
|
88
|
+
* @remarks
|
|
89
|
+
* Currently this is limited to data stores which have a single named channel,
|
|
90
|
+
* which must have the {@link rootSharedObjectId} and is attached at creation time.
|
|
91
|
+
* This limitation may be relaxed in the future.
|
|
92
|
+
*/
|
|
93
|
+
async function createDataStore(context, existing, options) {
|
|
94
|
+
const sharedObjectRegistry = await options.registry();
|
|
95
|
+
const runtime = new internal_1.FluidDataStoreRuntime(context, convertRegistry(sharedObjectRegistry), existing, async (runtimeInner) => {
|
|
96
|
+
const innerContext = {
|
|
97
|
+
async createSharedObject(key) {
|
|
98
|
+
const kind = (0, internal_2.lookupInRegistry)(sharedObjectRegistry, key);
|
|
99
|
+
// Create detached channel.
|
|
100
|
+
return asSharedObjectKind(kind).create(runtimeInner);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
let createdRoot;
|
|
104
|
+
const rootCreator = {
|
|
105
|
+
async createSharedObject(key) {
|
|
106
|
+
// Create named channel under the root id.
|
|
107
|
+
// Error if called twice.
|
|
108
|
+
if (createdRoot !== undefined) {
|
|
109
|
+
throw new internal_4.UsageError("Root shared object already created");
|
|
110
|
+
}
|
|
111
|
+
const kind = (0, internal_2.lookupInRegistry)(sharedObjectRegistry, key);
|
|
112
|
+
const result = asSharedObjectKind(kind).create(runtimeInner, rootSharedObjectId);
|
|
113
|
+
// Every shared object is also an ISharedObject;
|
|
114
|
+
const rootSharedObject = result;
|
|
115
|
+
// bind the newly created root so it becomes part of this data store.
|
|
116
|
+
rootSharedObject.bindToContext();
|
|
117
|
+
createdRoot = result;
|
|
118
|
+
return result;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
let root;
|
|
122
|
+
if (existing) {
|
|
123
|
+
// getChannel returns the type-erased IChannel; the registered root kind guarantees it is a TRoot.
|
|
124
|
+
root = (await runtimeInner.getChannel(rootSharedObjectId));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
root = await options.instantiateFirstTime(rootCreator, innerContext);
|
|
128
|
+
if (root !== createdRoot) {
|
|
129
|
+
throw new internal_4.UsageError("instantiateFirstTime did not return root created with rootCreator");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// view returns the data store's output type; the runtime only needs it as an opaque FluidObject entry point.
|
|
133
|
+
return (await options.view(root, innerContext));
|
|
134
|
+
});
|
|
135
|
+
return runtime;
|
|
136
|
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I,WAA8B,CAAC;QAEnC,MAAM,WAAW,GAA+B;YAC/C,KAAK,CAAC,kBAAkB,CAAmB,GAAwB;gBAClE,0CAA0C;gBAC1C,yBAAyB;gBACzB,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;oBAC/B,MAAM,IAAI,qBAAU,CAAC,oCAAoC,CAAC,CAAC;gBAC5D,CAAC;gBACD,MAAM,IAAI,GAAG,IAAA,2BAAgB,EAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;gBACzD,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;gBAEjF,gDAAgD;gBAChD,MAAM,gBAAgB,GAAG,MAAyC,CAAC;gBACnE,qEAAqE;gBACrE,gBAAgB,CAAC,aAAa,EAAE,CAAC;gBAEjC,WAAW,GAAG,MAAM,CAAC;gBACrB,OAAO,MAAM,CAAC;YACf,CAAC;SACD,CAAC;QAEF,IAAI,IAAuB,CAAC;QAC5B,IAAI,QAAQ,EAAE,CAAC;YACd,kGAAkG;YAClG,IAAI,GAAG,CAAC,MAAM,YAAY,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAA4B,CAAC;QACvF,CAAC;aAAM,CAAC;YACP,IAAI,GAAG,MAAM,OAAO,CAAC,oBAAoB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;YACrE,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;gBAC1B,MAAM,IAAI,qBAAU,CACnB,mEAAmE,CACnE,CAAC;YACH,CAAC;QACF,CAAC;QAED,6GAA6G;QAC7G,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAA2B,CAAC;IAC3E,CAAC,CACD,CAAC;IAEF,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidLoadable, FluidObject } from \"@fluidframework/core-interfaces\";\nimport {\n\ttype ISharedObjectRegistry,\n\tFluidDataStoreRuntime,\n} from \"@fluidframework/datastore/internal\";\nimport type { IFluidDataStoreRuntime } from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\ttype Registry,\n\ttype DataStoreKind,\n\tlookupInRegistry,\n} from \"@fluidframework/driver-definitions/internal\";\nimport type {\n\tIFluidDataStoreContext,\n\tIFluidDataStoreChannel,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { DataStoreKindImplementation } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type {\n\tISharedObjectKind,\n\tSharedObjectKey,\n\tSharedObjectKindAlpha,\n} from \"./sharedObject.js\";\nimport type { ISharedObject } from \"./types.js\";\n\n/**\n * This file provides the implementation of {@link @fluidframework/driver-definitions#DataStoreKind}\n * and is therefore a key part of the implementation of the {@link @fluidframework/driver-definitions#ServiceClient} API surface.\n *\n * Note that much of the API surface beyond {@link defineDataStore} could be removed/deduplicated\n * if the unification noted in the TODOs in {@link SharedObjectRegistry} is implemented.\n */\n\n/**\n * A {@link @fluidframework/driver-definitions#Registry} of shared object kinds that can be created or loaded within a data store.\n * @remarks\n * Supports lazy code loading in a limited way (a single lazy load per registry).\n * @privateRemarks\n * TODO: The framework provided SharedObjects should be exposed in a way indistinguishable from custom sub-data stores.\n * This can be done by unifying the DataStoreKind and SharedObjectKindAlpha types.\n * For now, this would mean having DataStoreKind extend SharedObjectKindAlpha, since we can allow a data store in all places SharedObjects are allowed,\n * but do not allow SharedObjects at the root.\n * Fixing this, and allowing shared objects at the root (maybe use a trivial wrapper data store) could simplify things, allowing data stores and Containers to share some types (like how they create detached contents, have registries, have a root etc).\n *\n * Part of this unification could be to relax the output from the factories / registries. Allowing the output to be an arbitrary type, which might be a promise, and might not be one could help.\n * Removal of the IFluidLoadable requirement, and allowing the returned type to expose handles to itself however it wants (or not at all) might be viable and simplify typing and allow for strongly typed handles at creation time at least).\n * Maybe when Registry(type) gives a promise, it could instead give a factory which outputs a promise wrapped type? The check that the provided creation key is valid for that factory can be deferred until the promise resolves.\n *\n * Idea: creation key can have an interface that subsets the factory / SharedObjectKindAlpha / DataStoreKind so they can be used, or some branded key (string, and/or object with stronger identity what knows the type string) can be used.\n * Have Key interface contain validation function to check that the factory used (or maybe the value produced from it) is valid for that key.\n * During load, validation would simply check the factory's type string matches the key's type string.\n * When using SharedObjectKindAlpha or DataStoreKind, validation can check factory object identity against key.\n *\n * Goal: Mostly unify container, data store and shared object abstractions.\n * Maybe unify a bit with service client since it also has a way to create detached things with an initialized root then attach them.\n * SharedObjects are just built in leaf data stores.\n *\n * @input\n * @alpha\n */\nexport type SharedObjectRegistry = () => Promise<\n\tRegistry<SharedObjectKindAlpha<IFluidLoadable>>\n>;\n\n/**\n * Creates a {@link SharedObjectRegistry} from an iterable of {@link SharedObjectKindAlpha}s or async getters for them.\n * @alpha\n */\nexport function sharedObjectRegistryFromIterable(\n\tentries: Iterable<\n\t\t| SharedObjectKindAlpha<IFluidLoadable>\n\t\t| { type: string; kind: () => Promise<SharedObjectKindAlpha<IFluidLoadable>> }\n\t>,\n): SharedObjectRegistry {\n\treturn async () => {\n\t\tconst map = new Map<string, SharedObjectKindAlpha<IFluidLoadable>>();\n\t\tfor (const entry of entries) {\n\t\t\tif (\"kind\" in entry) {\n\t\t\t\tmap.set(entry.type, await entry.kind());\n\t\t\t} else {\n\t\t\t\tmap.set(asSharedObjectKind(entry).getFactory().type, entry);\n\t\t\t}\n\t\t}\n\t\treturn (type: string) => {\n\t\t\tconst entry = map.get(type);\n\t\t\tif (entry === undefined) {\n\t\t\t\tthrow new UsageError(`Unknown shared object type: ${type}`);\n\t\t\t}\n\t\t\treturn entry;\n\t\t};\n\t};\n}\n\n/**\n * Options which define how to construct a particular {@link @fluidframework/driver-definitions#DataStoreKind}.\n * @remarks\n * Use {@link defineDataStore} to create a {@link @fluidframework/driver-definitions#DataStoreKind} from these options.\n * @input\n * @alpha\n */\nexport interface DataStoreOptions<in out TRoot extends IFluidLoadable, out TOutput> {\n\t/**\n\t * The type identifier for the data object factory.\n\t * @remarks\n\t * Persisted identifier which specifies which {@link @fluidframework/driver-definitions#DataStoreKind} to use when loading it.\n\t * @privateRemarks\n\t * Equivalent to `DataObjectFactoryProps.type`.\n\t */\n\treadonly type: string;\n\n\t/**\n\t * The registry of shared object kinds (including other data stores) that can be loaded or created within this data store.\n\t *\n\t * TODO: actually allow this to contain data stores.\n\t */\n\treadonly registry: SharedObjectRegistry;\n\n\t/**\n\t * Create the initial content of the data store, and return the root shared object.\n\t * @privateRemarks\n\t * TODO:\n\t * This requires the caller to produce a single root shared object (which is keyed by {@link rootSharedObjectId}).\n\t * This should be fine for new code, but code migrated from legacy APIs might need more flexibility.\n\t * Such use-cases could be accommodated providing a legacy alternative to `defineDataStore` where `instantiateFirstTime` and `view` directly expose access to named root shared objects.\n\t * This should be easy to implement, but is currently not included.\n\t */\n\tinstantiateFirstTime(\n\t\trootCreator: SharedObjectCreator<TRoot>,\n\t\tcontext: DataStoreContext,\n\t): Promise<TRoot>;\n\n\t/**\n\t * Construct a view of the data store's root shared object.\n\t *\n\t * @param root - The root shared object of the data store, created by `instantiateFirstTime` (though possibly created by another client and loaded by this one).\n\t * @param context - A {@link DataStoreContext} that can be used to create additional shared objects.\n\t */\n\tview(root: TRoot, context: DataStoreContext): Promise<TOutput>;\n}\n\n/**\n * Creates a {@link @fluidframework/driver-definitions#DataStoreKind} from {@link DataStoreOptions}.\n * @alpha\n */\nexport function defineDataStore<T, TRoot extends IFluidLoadable>(\n\toptions: DataStoreOptions<TRoot, T>,\n): DataStoreKind<T> {\n\treturn new DataStoreKindImplementation<T>({\n\t\ttype: options.type,\n\t\tasync instantiateDataStore(\n\t\t\tcontext: IFluidDataStoreContext,\n\t\t\texisting: boolean,\n\t\t): Promise<IFluidDataStoreChannel> {\n\t\t\treturn createDataStore(context, existing, options);\n\t\t},\n\t});\n}\n\n/**\n * Casts a {@link SharedObjectKindAlpha} to its encapsulated {@link ISharedObjectKind} view.\n *\n * @remarks\n * {@link SharedObjectKindAlpha} is a sealed type,\n * so we can assume it implements {@link ISharedObjectKind} and down cast to it.\n */\nfunction asSharedObjectKind<T extends IFluidLoadable>(\n\tkind: SharedObjectKindAlpha<T>,\n): ISharedObjectKind<T> {\n\tconst candidate = kind as unknown as Partial<ISharedObjectKind<T>>;\n\t// Sanity check to help catch misuse since SharedObjectKindAlpha is typed structurally and seems implementable.\n\tif (typeof candidate.getFactory !== \"function\" || typeof candidate.create !== \"function\") {\n\t\tthrow new UsageError(\n\t\t\t\"Invalid SharedObjectKindAlpha: this type is sealed and may not have custom implementations.\",\n\t\t);\n\t}\n\treturn candidate as ISharedObjectKind<T>;\n}\n\nfunction convertRegistry(\n\tlookup: Registry<SharedObjectKindAlpha<IFluidLoadable>>,\n): ISharedObjectRegistry {\n\treturn {\n\t\tget: (type: string) => {\n\t\t\tconst entry = lookup(type);\n\t\t\treturn asSharedObjectKind(entry).getFactory();\n\t\t},\n\t};\n}\n\n/**\n * Data stores keep their shared objects inside channels which get names.\n * This is the name of the channel which we conventionally use for the root shared object of a data store in most cases.\n * @remarks\n * There can be other named channels, or the root could use a different name, but we are trying to migrate away from such patterns.\n * Currently the DataStoreKind pattern used in this file follows and requires this convention,\n * but we may relax that in the future for interop with legacy data if necessary.\n */\nconst rootSharedObjectId = \"root\";\n\n/**\n * Creates a data store channel.\n * @param context - The data store context.\n * @param existing - Whether the data store already exists. When true, this loads it, when false a new one is created.\n * @param options - The data store options.\n * @returns A promise that resolves to the created data store channel.\n * @remarks\n * Currently this is limited to data stores which have a single named channel,\n * which must have the {@link rootSharedObjectId} and is attached at creation time.\n * This limitation may be relaxed in the future.\n */\nasync function createDataStore<T, TRoot extends IFluidLoadable>(\n\tcontext: IFluidDataStoreContext,\n\texisting: boolean,\n\toptions: DataStoreOptions<TRoot, T>,\n): Promise<IFluidDataStoreChannel> {\n\tconst sharedObjectRegistry = await options.registry();\n\tconst runtime: FluidDataStoreRuntime = new FluidDataStoreRuntime(\n\t\tcontext,\n\t\tconvertRegistry(sharedObjectRegistry),\n\t\texisting,\n\t\tasync (runtimeInner: IFluidDataStoreRuntime) => {\n\t\t\tconst innerContext: DataStoreContext = {\n\t\t\t\tasync createSharedObject<T2 extends IFluidLoadable>(\n\t\t\t\t\tkey: SharedObjectKey<T2>,\n\t\t\t\t): Promise<T2> {\n\t\t\t\t\tconst kind = lookupInRegistry(sharedObjectRegistry, key);\n\t\t\t\t\t// Create detached channel.\n\t\t\t\t\treturn asSharedObjectKind(kind).create(runtimeInner);\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tlet createdRoot: TRoot | undefined;\n\n\t\t\tconst rootCreator: SharedObjectCreator<TRoot> = {\n\t\t\t\tasync createSharedObject<T2 extends TRoot>(key: SharedObjectKey<T2>): Promise<T2> {\n\t\t\t\t\t// Create named channel under the root id.\n\t\t\t\t\t// Error if called twice.\n\t\t\t\t\tif (createdRoot !== undefined) {\n\t\t\t\t\t\tthrow new UsageError(\"Root shared object already created\");\n\t\t\t\t\t}\n\t\t\t\t\tconst kind = lookupInRegistry(sharedObjectRegistry, key);\n\t\t\t\t\tconst result = asSharedObjectKind(kind).create(runtimeInner, rootSharedObjectId);\n\n\t\t\t\t\t// Every shared object is also an ISharedObject;\n\t\t\t\t\tconst rootSharedObject = result as IFluidLoadable as ISharedObject;\n\t\t\t\t\t// bind the newly created root so it becomes part of this data store.\n\t\t\t\t\trootSharedObject.bindToContext();\n\n\t\t\t\t\tcreatedRoot = result;\n\t\t\t\t\treturn result;\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tlet root: TRoot | undefined;\n\t\t\tif (existing) {\n\t\t\t\t// getChannel returns the type-erased IChannel; the registered root kind guarantees it is a TRoot.\n\t\t\t\troot = (await runtimeInner.getChannel(rootSharedObjectId)) as IFluidLoadable as TRoot;\n\t\t\t} else {\n\t\t\t\troot = await options.instantiateFirstTime(rootCreator, innerContext);\n\t\t\t\tif (root !== createdRoot) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"instantiateFirstTime did not return root created with rootCreator\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// view returns the data store's output type; the runtime only needs it as an opaque FluidObject entry point.\n\t\t\treturn (await options.view(root, innerContext)) as unknown as FluidObject;\n\t\t},\n\t);\n\n\treturn runtime;\n}\n\n/**\n * Creates instances of SharedObjectKinds.\n * @privateRemarks\n * See IFluidContainer.create.\n * @sealed\n * @alpha\n */\nexport interface SharedObjectCreator<TConstraint = IFluidLoadable> {\n\t/**\n\t * Create an instance of `kind`, which must be registered in the registry of the surrounding data store.\n\t */\n\tcreateSharedObject<T extends TConstraint>(kind: SharedObjectKey<T>): Promise<T>;\n}\n\n/**\n * Contextual information about a data store which is provided when instantiating or loading it.\n * @privateRemarks\n * TODO: this can expose more contextual information about the data store as needed.\n * @sealed\n * @alpha\n */\nexport interface DataStoreContext extends SharedObjectCreator {}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { type ISharedObjectHandle, isISharedObjectHandle } from "./handle.js";
|
|
6
6
|
export { FluidSerializer, type IFluidSerializer } from "./serializer.js";
|
|
7
|
-
export { SharedObject, SharedObjectCore, type ISharedObjectKind, type SharedObjectKind, createSharedObjectKind, } from "./sharedObject.js";
|
|
7
|
+
export { SharedObject, SharedObjectCore, type ISharedObjectKind, type SharedObjectKind, type SharedObjectKindAlpha, createSharedObjectKind, createSharedObjectKindAlpha, type SharedObjectKey, } from "./sharedObject.js";
|
|
8
8
|
export type { ISharedObject, ISharedObjectEvents } from "./types.js";
|
|
9
9
|
export { createSingleBlobSummary, makeHandlesSerializable, parseHandles, serializeHandles, bindHandles, type IChannelView, } from "./utils.js";
|
|
10
10
|
export { ValueType } from "./valueType.js";
|
|
11
11
|
export { type SharedKernel, thisWrap, type KernelArgs, makeSharedObjectKind, type SharedKernelFactory, type FactoryOut, type SharedObjectOptions, mergeAPIs, } from "./sharedObjectKernel.js";
|
|
12
|
+
export { defineDataStore, sharedObjectRegistryFromIterable } from "./dataStoreKind.js";
|
|
13
|
+
export { makeStubDataStoreKind } from "./stubSharedObject.js";
|
|
14
|
+
export type { DataStoreOptions, SharedObjectCreator, SharedObjectRegistry, DataStoreContext, } from "./dataStoreKind.js";
|
|
12
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EACN,YAAY,EACZ,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EACN,YAAY,EACZ,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,sBAAsB,EACtB,2BAA2B,EAC3B,KAAK,eAAe,GACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,KAAK,YAAY,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACN,KAAK,YAAY,EACjB,QAAQ,EACR,KAAK,UAAU,EACf,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,SAAS,GACT,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,YAAY,EACX,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.mergeAPIs = exports.makeSharedObjectKind = exports.thisWrap = exports.ValueType = exports.bindHandles = exports.serializeHandles = exports.parseHandles = exports.makeHandlesSerializable = exports.createSingleBlobSummary = exports.createSharedObjectKind = exports.SharedObjectCore = exports.SharedObject = exports.FluidSerializer = exports.isISharedObjectHandle = void 0;
|
|
7
|
+
exports.makeStubDataStoreKind = exports.sharedObjectRegistryFromIterable = exports.defineDataStore = exports.mergeAPIs = exports.makeSharedObjectKind = exports.thisWrap = exports.ValueType = exports.bindHandles = exports.serializeHandles = exports.parseHandles = exports.makeHandlesSerializable = exports.createSingleBlobSummary = exports.createSharedObjectKindAlpha = exports.createSharedObjectKind = exports.SharedObjectCore = exports.SharedObject = exports.FluidSerializer = exports.isISharedObjectHandle = void 0;
|
|
8
8
|
var handle_js_1 = require("./handle.js");
|
|
9
9
|
Object.defineProperty(exports, "isISharedObjectHandle", { enumerable: true, get: function () { return handle_js_1.isISharedObjectHandle; } });
|
|
10
10
|
var serializer_js_1 = require("./serializer.js");
|
|
@@ -13,6 +13,7 @@ var sharedObject_js_1 = require("./sharedObject.js");
|
|
|
13
13
|
Object.defineProperty(exports, "SharedObject", { enumerable: true, get: function () { return sharedObject_js_1.SharedObject; } });
|
|
14
14
|
Object.defineProperty(exports, "SharedObjectCore", { enumerable: true, get: function () { return sharedObject_js_1.SharedObjectCore; } });
|
|
15
15
|
Object.defineProperty(exports, "createSharedObjectKind", { enumerable: true, get: function () { return sharedObject_js_1.createSharedObjectKind; } });
|
|
16
|
+
Object.defineProperty(exports, "createSharedObjectKindAlpha", { enumerable: true, get: function () { return sharedObject_js_1.createSharedObjectKindAlpha; } });
|
|
16
17
|
var utils_js_1 = require("./utils.js");
|
|
17
18
|
Object.defineProperty(exports, "createSingleBlobSummary", { enumerable: true, get: function () { return utils_js_1.createSingleBlobSummary; } });
|
|
18
19
|
Object.defineProperty(exports, "makeHandlesSerializable", { enumerable: true, get: function () { return utils_js_1.makeHandlesSerializable; } });
|
|
@@ -25,4 +26,9 @@ var sharedObjectKernel_js_1 = require("./sharedObjectKernel.js");
|
|
|
25
26
|
Object.defineProperty(exports, "thisWrap", { enumerable: true, get: function () { return sharedObjectKernel_js_1.thisWrap; } });
|
|
26
27
|
Object.defineProperty(exports, "makeSharedObjectKind", { enumerable: true, get: function () { return sharedObjectKernel_js_1.makeSharedObjectKind; } });
|
|
27
28
|
Object.defineProperty(exports, "mergeAPIs", { enumerable: true, get: function () { return sharedObjectKernel_js_1.mergeAPIs; } });
|
|
29
|
+
var dataStoreKind_js_1 = require("./dataStoreKind.js");
|
|
30
|
+
Object.defineProperty(exports, "defineDataStore", { enumerable: true, get: function () { return dataStoreKind_js_1.defineDataStore; } });
|
|
31
|
+
Object.defineProperty(exports, "sharedObjectRegistryFromIterable", { enumerable: true, get: function () { return dataStoreKind_js_1.sharedObjectRegistryFromIterable; } });
|
|
32
|
+
var stubSharedObject_js_1 = require("./stubSharedObject.js");
|
|
33
|
+
Object.defineProperty(exports, "makeStubDataStoreKind", { enumerable: true, get: function () { return stubSharedObject_js_1.makeStubDataStoreKind; } });
|
|
28
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yCAA8E;AAA3C,kHAAA,qBAAqB,OAAA;AACxD,iDAAyE;AAAhE,gHAAA,eAAe,OAAA;AACxB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yCAA8E;AAA3C,kHAAA,qBAAqB,OAAA;AACxD,iDAAyE;AAAhE,gHAAA,eAAe,OAAA;AACxB,qDAS2B;AAR1B,+GAAA,YAAY,OAAA;AACZ,mHAAA,gBAAgB,OAAA;AAIhB,yHAAA,sBAAsB,OAAA;AACtB,8HAAA,2BAA2B,OAAA;AAI5B,uCAOoB;AANnB,mHAAA,uBAAuB,OAAA;AACvB,mHAAA,uBAAuB,OAAA;AACvB,wGAAA,YAAY,OAAA;AACZ,4GAAA,gBAAgB,OAAA;AAChB,uGAAA,WAAW,OAAA;AAGZ,+CAA2C;AAAlC,yGAAA,SAAS,OAAA;AAClB,iEASiC;AAPhC,iHAAA,QAAQ,OAAA;AAER,6HAAA,oBAAoB,OAAA;AAIpB,kHAAA,SAAS,OAAA;AAEV,uDAAuF;AAA9E,mHAAA,eAAe,OAAA;AAAE,oIAAA,gCAAgC,OAAA;AAC1D,6DAA8D;AAArD,4HAAA,qBAAqB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { type ISharedObjectHandle, isISharedObjectHandle } from \"./handle.js\";\nexport { FluidSerializer, type IFluidSerializer } from \"./serializer.js\";\nexport {\n\tSharedObject,\n\tSharedObjectCore,\n\ttype ISharedObjectKind,\n\ttype SharedObjectKind,\n\ttype SharedObjectKindAlpha,\n\tcreateSharedObjectKind,\n\tcreateSharedObjectKindAlpha,\n\ttype SharedObjectKey,\n} from \"./sharedObject.js\";\nexport type { ISharedObject, ISharedObjectEvents } from \"./types.js\";\nexport {\n\tcreateSingleBlobSummary,\n\tmakeHandlesSerializable,\n\tparseHandles,\n\tserializeHandles,\n\tbindHandles,\n\ttype IChannelView,\n} from \"./utils.js\";\nexport { ValueType } from \"./valueType.js\";\nexport {\n\ttype SharedKernel,\n\tthisWrap,\n\ttype KernelArgs,\n\tmakeSharedObjectKind,\n\ttype SharedKernelFactory,\n\ttype FactoryOut,\n\ttype SharedObjectOptions,\n\tmergeAPIs,\n} from \"./sharedObjectKernel.js\";\nexport { defineDataStore, sharedObjectRegistryFromIterable } from \"./dataStoreKind.js\";\nexport { makeStubDataStoreKind } from \"./stubSharedObject.js\";\nexport type {\n\tDataStoreOptions,\n\tSharedObjectCreator,\n\tSharedObjectRegistry,\n\tDataStoreContext,\n} from \"./dataStoreKind.js\";\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/shared-object-base";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.114.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,YAAY,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/shared-object-base";
|
|
11
|
-
exports.pkgVersion = "2.
|
|
11
|
+
exports.pkgVersion = "2.114.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,SAAS,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.114.0\";\n"]}
|
package/dist/sharedObject.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { IDeltaManager } from "@fluidframework/container-definitions/intern
|
|
|
7
7
|
import type { ErasedType } from "@fluidframework/core-interfaces";
|
|
8
8
|
import type { IFluidHandleInternal, IFluidLoadable } from "@fluidframework/core-interfaces/internal";
|
|
9
9
|
import type { IChannelServices, IChannelStorageService, IChannelAttributes, IChannelFactory, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions/internal";
|
|
10
|
-
import type { IDocumentMessage, ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
|
|
10
|
+
import type { IDocumentMessage, ISequencedDocumentMessage, RegistryKey } from "@fluidframework/driver-definitions/internal";
|
|
11
11
|
import { type IExperimentalIncrementalSummaryContext, type ISummaryTreeWithStats, type ITelemetryContext, type IGarbageCollectionData, type IRuntimeMessageCollection } from "@fluidframework/runtime-definitions/internal";
|
|
12
12
|
import { EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils/internal";
|
|
13
13
|
import type { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/legacy";
|
|
@@ -431,6 +431,28 @@ export interface SharedObjectKind<out TSharedObject = unknown> extends ErasedTyp
|
|
|
431
431
|
*/
|
|
432
432
|
is(value: IFluidLoadable): value is IFluidLoadable & TSharedObject;
|
|
433
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* A {@link @fluidframework/driver-definitions#RegistryKey} for a {@link SharedObjectKind}.
|
|
436
|
+
* @remarks
|
|
437
|
+
* This is implemented by {@link SharedObjectKind}, but alternative implementations can be used if needed.
|
|
438
|
+
*
|
|
439
|
+
* If you want lazy loading and need a key that does not eagerly load the {@link SharedObjectKind}, an alternative {@link SharedObjectKey} can be implemented.
|
|
440
|
+
* @privateRemarks
|
|
441
|
+
* TODO: A built in common pattern for the lazy key case should be provided.
|
|
442
|
+
* TODO: things probably break if "adapt" does anything except throw or return the result from the input promise.
|
|
443
|
+
* @input
|
|
444
|
+
* @alpha
|
|
445
|
+
*/
|
|
446
|
+
export type SharedObjectKey<T> = RegistryKey<SharedObjectKindAlpha<T>, SharedObjectKindAlpha>;
|
|
447
|
+
/**
|
|
448
|
+
* A {@link SharedObjectKind} that also implements {@link SharedObjectKey}.
|
|
449
|
+
* @privateRemarks
|
|
450
|
+
* All concrete shared object kinds (produced by {@link createSharedObjectKind}) implement this interface.
|
|
451
|
+
* @sealed
|
|
452
|
+
* @alpha
|
|
453
|
+
*/
|
|
454
|
+
export interface SharedObjectKindAlpha<out TSharedObject = unknown> extends SharedObjectKind<TSharedObject>, SharedObjectKey<TSharedObject> {
|
|
455
|
+
}
|
|
434
456
|
/**
|
|
435
457
|
* Utility for creating ISharedObjectKind instances.
|
|
436
458
|
* @remarks
|
|
@@ -443,4 +465,16 @@ export interface SharedObjectKind<out TSharedObject = unknown> extends ErasedTyp
|
|
|
443
465
|
export declare function createSharedObjectKind<TSharedObject>(factory: (new () => IChannelFactory<TSharedObject>) & {
|
|
444
466
|
readonly Type: string;
|
|
445
467
|
}): ISharedObjectKind<TSharedObject> & SharedObjectKind<TSharedObject>;
|
|
468
|
+
/**
|
|
469
|
+
* Utility for creating ISharedObjectKind instances.
|
|
470
|
+
* @remarks
|
|
471
|
+
* This takes in a class which implements IChannelFactory,
|
|
472
|
+
* and uses it to return a single value which is intended to be used as the API entry point for the corresponding shared object type.
|
|
473
|
+
* The returned value implements {@link ISharedObjectKind} for use in the encapsulated API, as well as the type erased {@link SharedObjectKind} used by the declarative API.
|
|
474
|
+
* See {@link @fluidframework/fluid-static#ContainerSchema} for how this is used in the declarative API.
|
|
475
|
+
* @internal
|
|
476
|
+
*/
|
|
477
|
+
export declare function createSharedObjectKindAlpha<TSharedObject>(factory: (new () => IChannelFactory<TSharedObject>) & {
|
|
478
|
+
readonly Type: string;
|
|
479
|
+
}): ISharedObjectKind<TSharedObject> & SharedObjectKindAlpha<TSharedObject>;
|
|
446
480
|
//# sourceMappingURL=sharedObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedObject.d.ts","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AACpF,OAAO,KAAK,EAA4B,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,KAAK,EACX,oBAAoB,EACpB,cAAc,EACd,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EACX,gBAAgB,EAChB,sBAAsB,EAEtB,kBAAkB,E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G;AACH,MAAM,WAAW,gBAAgB,CAAC,GAAG,CAAC,aAAa,GAAG,OAAO,CAC5D,SAAQ,UAAU,CAAC,SAAS,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;IAChE;;;OAGG;IACH,EAAE,CAAC,KAAK,EAAE,cAAc,GAAG,KAAK,IAAI,cAAc,GAAG,aAAa,CAAC;CACnE;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,WAAW,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;AAE9F;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB,CAAC,GAAG,CAAC,aAAa,GAAG,OAAO,CACjE,SAAQ,gBAAgB,CAAC,aAAa,CAAC,EACtC,eAAe,CAAC,aAAa,CAAC;CAAG;AAEnC;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EACnD,OAAO,EAAE,CAAC,UAAU,eAAe,CAAC,aAAa,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7E,iBAAiB,CAAC,aAAa,CAAC,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAEpE;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,aAAa,EACxD,OAAO,EAAE,CAAC,UAAU,eAAe,CAAC,aAAa,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7E,iBAAiB,CAAC,aAAa,CAAC,GAAG,qBAAqB,CAAC,aAAa,CAAC,CAiCzE"}
|
package/dist/sharedObject.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.createSharedObjectKind = exports.SharedObject = exports.SharedObjectCore = void 0;
|
|
7
|
+
exports.createSharedObjectKindAlpha = exports.createSharedObjectKind = exports.SharedObject = exports.SharedObjectCore = void 0;
|
|
8
8
|
const container_definitions_1 = require("@fluidframework/container-definitions");
|
|
9
9
|
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
10
10
|
const internal_2 = require("@fluidframework/runtime-definitions/internal");
|
|
@@ -594,6 +594,19 @@ exports.SharedObject = SharedObject;
|
|
|
594
594
|
* @internal
|
|
595
595
|
*/
|
|
596
596
|
function createSharedObjectKind(factory) {
|
|
597
|
+
return createSharedObjectKindAlpha(factory);
|
|
598
|
+
}
|
|
599
|
+
exports.createSharedObjectKind = createSharedObjectKind;
|
|
600
|
+
/**
|
|
601
|
+
* Utility for creating ISharedObjectKind instances.
|
|
602
|
+
* @remarks
|
|
603
|
+
* This takes in a class which implements IChannelFactory,
|
|
604
|
+
* and uses it to return a single value which is intended to be used as the API entry point for the corresponding shared object type.
|
|
605
|
+
* The returned value implements {@link ISharedObjectKind} for use in the encapsulated API, as well as the type erased {@link SharedObjectKind} used by the declarative API.
|
|
606
|
+
* See {@link @fluidframework/fluid-static#ContainerSchema} for how this is used in the declarative API.
|
|
607
|
+
* @internal
|
|
608
|
+
*/
|
|
609
|
+
function createSharedObjectKindAlpha(factory) {
|
|
597
610
|
const result = {
|
|
598
611
|
getFactory() {
|
|
599
612
|
return new factory();
|
|
@@ -604,10 +617,21 @@ function createSharedObjectKind(factory) {
|
|
|
604
617
|
is(value) {
|
|
605
618
|
return isChannel(value) && value.attributes.type === factory.Type;
|
|
606
619
|
},
|
|
620
|
+
type: factory.Type,
|
|
621
|
+
adapt: (value) => {
|
|
622
|
+
if (value === resultFinal) {
|
|
623
|
+
return resultFinal;
|
|
624
|
+
}
|
|
625
|
+
if (value.type === result.type) {
|
|
626
|
+
throw new internal_4.UsageError(`Conflicting SharedObjectKinds with same type: ${result.type}`);
|
|
627
|
+
}
|
|
628
|
+
throw new internal_4.UsageError(`Mismatched SharedObjectKind type. Expected: ${result.type}, got: ${value.type}`);
|
|
629
|
+
},
|
|
607
630
|
};
|
|
608
|
-
|
|
631
|
+
const resultFinal = result;
|
|
632
|
+
return resultFinal;
|
|
609
633
|
}
|
|
610
|
-
exports.
|
|
634
|
+
exports.createSharedObjectKindAlpha = createSharedObjectKindAlpha;
|
|
611
635
|
function isChannel(loadable) {
|
|
612
636
|
// This assumes no other IFluidLoadable has an `attributes` field, and thus may not be fully robust.
|
|
613
637
|
return loadable.attributes !== undefined;
|