@fluidframework/local-driver 2.115.0 → 2.116.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 CHANGED
@@ -1,5 +1,66 @@
1
1
  # @fluidframework/local-driver
2
2
 
3
+ ## 2.116.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Rename minVersionForCollab to oldestSupportedClient ([#27806](https://github.com/microsoft/FluidFramework/pull/27806)) [86b912170c](https://github.com/microsoft/FluidFramework/commit/86b912170c0e12ebeb481c5201f923c72bf94498)
8
+
9
+ The cross-client compatibility parameter has new names:
10
+ - The
11
+ [`MinimumVersionForCollab`](https://fluidframework.com/docs/api/runtime-definitions/minimumversionforcollab-typealias)
12
+ type is now
13
+ [`OldestSupportedClientVersion`](https://fluidframework.com/docs/api/runtime-definitions/oldestsupportedclientversion-typealias).
14
+ - [`LoadContainerRuntimeParams.minVersionForCollab`](https://fluidframework.com/docs/api/container-runtime/loadcontainerruntimeparams-interface#minversionforcollab-propertysignature)
15
+ is now
16
+ [`LoadContainerRuntimeParams.oldestSupportedClient`](https://fluidframework.com/docs/api/container-runtime/loadcontainerruntimeparams-interface#oldestsupportedclient-propertysignature).
17
+ - [`BaseContainerRuntimeFactoryProps.minVersionForCollab`](https://fluidframework.com/docs/api/aqueduct/basecontainerruntimefactoryprops-interface#minversionforcollab-propertysignature)
18
+ is now
19
+ [`BaseContainerRuntimeFactoryProps.oldestSupportedClient`](https://fluidframework.com/docs/api/aqueduct/basecontainerruntimefactoryprops-interface#oldestsupportedclient-propertysignature).
20
+ - [`createTreeContainerRuntimeFactory`](https://fluidframework.com/docs/api/fluid-static/#createtreecontainerruntimefactory-function)
21
+ now accepts `oldestSupportedClient`.
22
+ `minVersionForCollaboration` remains available as a deprecated overload.
23
+ - `@fluidframework/driver-definitions` now exports its minor-only version type as
24
+ [`OldestSupportedServiceClientVersion`](https://fluidframework.com/docs/api/driver-definitions/oldestsupportedserviceclientversion-typealias),
25
+ and
26
+ [`ServiceOptions.oldestSupportedClient`](https://fluidframework.com/docs/api/driver-definitions/serviceoptions-interface#oldestsupportedclient-propertysignature)
27
+ is available.
28
+ - [`AzureClient`](https://fluidframework.com/docs/api/azure-client/azureclient-class),
29
+ [`OdspClient`](https://fluidframework.com/docs/api/odsp-client/odspclient-class),
30
+ and
31
+ [`TinyliciousClient`](https://fluidframework.com/docs/api/tinylicious-client/tinyliciousclient-class)
32
+ methods now use `oldestSupportedClient` and
33
+ [`OldestSupportedClientVersion`](https://fluidframework.com/docs/api/runtime-definitions/oldestsupportedclientversion-typealias)
34
+ in their signatures.
35
+
36
+ The previous property and type names in `@fluidframework/runtime-definitions`,
37
+ `@fluidframework/container-runtime`, `@fluidframework/aqueduct`, and
38
+ `@fluidframework/fluid-static` are deprecated and will be removed in future
39
+ releases. Where both old and new property names remain available, specifying both
40
+ is an error. The alpha `MinimumVersionForCollaboration` type and
41
+ `ServiceOptions.minVersionForCollaboration` property are replaced directly rather
42
+ than retained as aliases.
43
+
44
+ ```typescript
45
+ // Before
46
+ const runtime = await loadContainerRuntime({
47
+ context,
48
+ registryEntries,
49
+ provideEntryPoint,
50
+ minVersionForCollab: "2.40.0",
51
+ });
52
+
53
+ // After
54
+ const runtime = await loadContainerRuntime({
55
+ context,
56
+ registryEntries,
57
+ provideEntryPoint,
58
+ oldestSupportedClient: "2.40.0",
59
+ });
60
+ ```
61
+
62
+ Telemetry property names are unchanged.
63
+
3
64
  ## 2.115.0
4
65
 
5
66
  ### Minor Changes
package/README.md CHANGED
@@ -101,7 +101,7 @@ There are many ways to [contribute](https://github.com/microsoft/FluidFramework/
101
101
  - Review the [source code changes](https://github.com/microsoft/FluidFramework/pulls).
102
102
  - [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
103
103
 
104
- Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/wiki).
104
+ Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Home.md).
105
105
 
106
106
  This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
107
107
  For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
@@ -112,9 +112,11 @@ Use of Microsoft trademarks or logos in modified versions of this project must n
112
112
 
113
113
  ## Help
114
114
 
115
- Not finding what you're looking for in this README? Check out [fluidframework.com](https://fluidframework.com/docs/).
115
+ Not finding what you're looking for in this README?
116
+ Check out [fluidframework.com](https://fluidframework.com/docs/).
116
117
 
117
- Still not finding what you're looking for? Please [file an issue](https://github.com/microsoft/FluidFramework/wiki/Submitting-Bugs-and-Feature-Requests).
118
+ Still not finding what you're looking for?
119
+ Please [file an issue](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Contributing/Submitting-Bugs-and-Feature-Requests.md).
118
120
 
119
121
  Thank you!
120
122
 
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import type { IRequest } from "@fluidframework/core-interfaces";
6
6
  import { type ErasedBaseType } from "@fluidframework/core-interfaces/internal";
7
- import type { DataStoreKind, DataStoreRegistry, FluidContainerAttached, FluidContainerWithService, ServiceClient, ServiceOptions } from "@fluidframework/driver-definitions/internal";
7
+ import { type DataStoreKind, type DataStoreRegistry, type FluidContainerAttached, type FluidContainerWithService, type OldestSupportedServiceClientVersion, type ServiceClient, type ServiceOptions } from "@fluidframework/driver-definitions/internal";
8
8
  import { ServiceContainerBase } from "@fluidframework/runtime-utils/internal";
9
9
  /**
10
10
  * Starts and returns a new {@link EphemeralService}.
@@ -40,6 +40,10 @@ export declare function getDefaultEphemeralService(): EphemeralService;
40
40
  * @internal
41
41
  */
42
42
  export interface EphemeralServiceOptions extends ServiceOptions {
43
+ /**
44
+ * {@inheritdoc @fluidframework/driver-definitions#ServiceOptions.oldestSupportedClient}
45
+ */
46
+ readonly oldestSupportedClient: OldestSupportedServiceClientVersion;
43
47
  /**
44
48
  * The service instance to connect to.
45
49
  */
@@ -61,7 +65,7 @@ export interface EphemeralServiceOptions extends ServiceOptions {
61
65
  * This is separated out from the actual {@link @fluidframework/driver-definitions#ServiceClient} object so that it's possible to create multiple service clients
62
66
  * connected to the same service.
63
67
  * Doing so is rarely necessary, but would be needed to test multiple clients collaborating on the same
64
- * document with different minVersionForCollaboration values.
68
+ * document with different `oldestSupportedClient` values.
65
69
  * This also exposes a place to put APIs for preloading and exporting document contents in the future.
66
70
  *
67
71
  * This is an erased type: its only implementation is the module-private {@link EphemeralServiceImplementation}, which holds
@@ -114,8 +118,8 @@ export interface EphemeralService extends ErasedBaseType<readonly ["EphemeralSer
114
118
  /**
115
119
  * Creates and returns a {@link EphemeralServiceClient} for an in-memory, ephemeral Fluid service.
116
120
  *
117
- * @param options - Options for the client. `minVersionForCollaboration` may be omitted (since all collaborators
118
- * are in the same process, it defaults to the current version). `service` may be omitted to allocate a new
121
+ * @param options - Options for the client. `oldestSupportedClient` may be omitted because all
122
+ * clients are in the same process, so it defaults to the current version. `service` may be omitted to allocate a new
119
123
  * {@link EphemeralService} dedicated to this client, or provided to connect the client to an existing service instance.
120
124
  *
121
125
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"ephemeralService.d.ts","sourceRoot":"","sources":["../src/ephemeralService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAEN,KAAK,cAAc,EACnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EACX,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,yBAAyB,EAEzB,aAAa,EACb,cAAc,EACd,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAMN,oBAAoB,EACpB,MAAM,wCAAwC,CAAC;AAWhD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,UAAO,GAAG,gBAAgB,CA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,7 +94,7 @@ class EphemeralServiceImplementation extends internal_4.ErasedTypeImplementation
94
94
  }
95
95
  newClient(options) {
96
96
  const finalOptions = {
97
- minVersionForCollaboration: options?.minVersionForCollaboration ?? (0, internal_6.featureVersion)(packageVersion_js_1.pkgVersion),
97
+ oldestSupportedClient: options?.oldestSupportedClient ?? (0, internal_6.featureVersion)(packageVersion_js_1.pkgVersion),
98
98
  service: this,
99
99
  };
100
100
  return new EphemeralServiceClientImplementation(finalOptions);
@@ -258,7 +258,7 @@ class EphemeralServiceContainer extends internal_7.ServiceContainerBase {
258
258
  codeDetails: { package: "1.0" },
259
259
  urlResolver,
260
260
  documentServiceFactory: options.service.getDocumentServiceFactory(),
261
- codeLoader: (0, internal_7.makeCodeLoader)(registry, options.minVersionForCollaboration, containerRuntimeLoader, root),
261
+ codeLoader: (0, internal_7.makeCodeLoader)(registry, options.oldestSupportedClient, containerRuntimeLoader, root),
262
262
  });
263
263
  return new EphemeralServiceContainer(registry, options, container, (await container.getEntryPoint()), undefined);
264
264
  }
@@ -268,7 +268,7 @@ class EphemeralServiceContainer extends internal_7.ServiceContainerBase {
268
268
  request: createLoadExistingRequest(id),
269
269
  urlResolver,
270
270
  documentServiceFactory: options.service.getDocumentServiceFactory(),
271
- codeLoader: (0, internal_7.makeCodeLoader)(registry, options.minVersionForCollaboration, containerRuntimeLoader),
271
+ codeLoader: (0, internal_7.makeCodeLoader)(registry, options.oldestSupportedClient, containerRuntimeLoader),
272
272
  });
273
273
  const container = new EphemeralServiceContainer(registry, options, containerInner, (await containerInner.getEntryPoint()), id);
274
274
  (0, internal_5.assert)(container.id !== undefined, 0xd14 /* id should be defined when loading a container */);
@@ -1 +1 @@
1
- {"version":3,"file":"ephemeralService.js","sourceRoot":"","sources":["../src/ephemeralService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6EAGwD;AACxD,wEAGmD;AACnD,yEAA8E;AAE9E,uEAGkD;AAClD,kEAA6D;AAU7D,0EAA6E;AAC7E,qE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A8C,CAAC;IACvD,CAAC;IAED,YACC,QAAiD,EACjD,OAAgC,EAChC,SAAqB,EACrB,IAAW,EACX,EAAsB;QAEtB,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,8BAA8B,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAEe,KAAK;QACpB,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,8EAA8E;QAC9E,8BAA8B,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAES,mBAAmB;QAC5B,MAAM,UAAU,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QACpD,OAAO,IAAA,sDAAmC,EAAC,UAAU,CAAC,CAAC;IACxD,CAAC;CACD;AAxFD,8DAwFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tConnectionState,\n\ttype IContainer,\n} from \"@fluidframework/container-definitions/internal\";\nimport {\n\tcreateDetachedContainer,\n\tloadExistingContainer,\n} from \"@fluidframework/container-loader/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tErasedTypeImplementation,\n\ttype ErasedBaseType,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tDataStoreKind,\n\tDataStoreRegistry,\n\tFluidContainerAttached,\n\tFluidContainerWithService,\n\tRegistry,\n\tServiceClient,\n\tServiceOptions,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { featureVersion } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype ContainerRuntimeLoader,\n\ttype ContainerRuntimeLoaderParams,\n\tmakeCodeLoader,\n\trootDataStoreId,\n\tServiceClientImplementation,\n\tServiceContainerBase,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tLocalDeltaConnectionServer,\n\ttype ILocalDeltaConnectionServer,\n} from \"@fluidframework/server-local-server\";\nimport { UsageError } from \"@fluidframework/driver-utils/internal\";\n\nimport { LocalDocumentServiceFactory } from \"./localDocumentServiceFactory.js\";\nimport { createLocalResolverCreateNewRequest, LocalResolver } from \"./localResolver.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * Starts and returns a new {@link EphemeralService}.\n * @param isDefault - Whether this service should saved as the default service for {@link cleanupEphemeralService} to cleanup.\n * Defaults to true.\n * @remarks\n * The returned service owns an in-memory server and holds the documents created through clients connected to it.\n * {@link cleanupEphemeralService} can be used to ensure the service is properly cleaned up (a no-op if stopped/closed already).\n *\n * As a service, it may start timers which may require an explicit `close` to fully free.\n * @alpha\n */\nexport function startEphemeralService(isDefault = true): EphemeralService {\n\tif (isDefault && defaultEphemeralService) {\n\t\tthrow new UsageError(\"A default EphemeralService is already running\");\n\t}\n\n\tconst service = new EphemeralServiceImplementation();\n\tif (isDefault) {\n\t\tdefaultEphemeralService = service;\n\t}\n\treturn service;\n}\n\n/**\n * Cleans up the service passed in {@link startEphemeralService}, or the {@link getDefaultEphemeralService|default} if none is passed.\n * @remarks\n * This closes the service, and all its containers.\n * This is a good way to ensure the service and its containers leave no lingering timers\n * which could leak memory, trigger asynchronous work or prevent a clean process exit.\n * @alpha\n */\nexport async function cleanupEphemeralService(service?: EphemeralService): Promise<void> {\n\tconst toCleanup = service ?? defaultEphemeralService;\n\tif (toCleanup) {\n\t\t// TODO: we may want to make closing of containers a separate operation which is done here.\n\t\tawait toCleanup.close();\n\t}\n\tif (toCleanup === defaultEphemeralService) {\n\t\tdefaultEphemeralService = undefined;\n\t}\n}\n\n/**\n * Get the default {@link EphemeralService} if one has been {@link startEphemeralService|started}.\n * @throws If no default service is running.\n * @alpha\n */\nexport function getDefaultEphemeralService(): EphemeralService {\n\tif (defaultEphemeralService) {\n\t\treturn defaultEphemeralService;\n\t}\n\tthrow new UsageError(\"No default EphemeralService is running\");\n}\n\n/**\n * Internal Options for creating an {@link EphemeralServiceClient}, extending {@link @fluidframework/driver-definitions#ServiceOptions}\n * with the {@link EphemeralService} the client should connect to.\n * @input\n * @internal\n */\nexport interface EphemeralServiceOptions extends ServiceOptions {\n\t/**\n\t * The service instance to connect to.\n\t */\n\treadonly service: EphemeralService;\n}\n\n/**\n * An in-memory Fluid service that can produce connected {@link EphemeralServiceClient}s.\n * @remarks\n * All documents created through clients connected to a given `EphemeralService` are held in-memory by that service.\n * Closing the service (via {@link EphemeralService.close} or {@link cleanupEphemeralService}) closes the connections\n * to any remaining open containers, and cleans up the service's timers.\n *\n * Create one with {@link startEphemeralService}.\n *\n * Most {@link @fluidframework/driver-definitions#ServiceClient} implementations would take in a URL and credentials to connect to a service,\n * but that is not needed for the ephemeral in-memory service.\n * Instead this object representing the actual service instance is provided.\n * @privateRemarks\n * This is separated out from the actual {@link @fluidframework/driver-definitions#ServiceClient} object so that it's possible to create multiple service clients\n * connected to the same service.\n * Doing so is rarely necessary, but would be needed to test multiple clients collaborating on the same\n * document with different minVersionForCollaboration values.\n * This also exposes a place to put APIs for preloading and exporting document contents in the future.\n *\n * This is an erased type: its only implementation is the module-private {@link EphemeralServiceImplementation}, which holds\n * the mutable server and container state so it does not appear on this public type.\n *\n * TODO: formalize this lifecycle with an interface which documents these stages.\n * Lifecycle:\n * The intended lifecycle of an {@link EphemeralService} follows roughly the same pattern as containers:\n *\n * 1. Open: accepts connections from {@link EphemeralServiceClient}s, which can create and load containers.\n * Might have timers and event registrations which can trigger asynchronous work, and retain the object in memory.\n *\n * 2. Closing: asynchronous transition from open to closed. New use should behave as it closed, but may be cleaning up or saving resources asynchronously.\n * Timers and event registrations may still be active, but should be cleaned up by the time the transition to closed completes.\n *\n * 3. Closed: no longer accepts connections from {@link EphemeralServiceClient}s, and all containers connected to it are closed.\n * Should have no subscriptions to events or timers which could retain it in memory or trigger asynchronous work.\n * The object can still be used in a limited capacity (typically just to inspect its status (e.g. `isClosed`), and to view (but not edit) the final state of any containers which were connected to it before it closed.)\n *\n * Events or errors can cause an open to closing transition. Any nonfunctional state, including error states, should be considered as closed (or closing which will transition to closed),\n * and meet the requirements of closed with regards to timers and events.\n *\n * @alpha @sealed\n */\nexport interface EphemeralService extends ErasedBaseType<readonly [\"EphemeralService\"]> {\n\t/**\n\t * Close this service, which closes all containers connected to it and releases its resources.\n\t * @remarks\n\t * All documents held by this service are discarded, and any timers it (or its containers) were keeping alive\n\t * are cleaned up.\n\t * The returned promise resolves once all asynchronous cleanup (including shutting down the in-memory server)\n\t * has completed.\n\t * Closing is idempotent: calling it again after the service is closed resolves without doing anything.\n\t */\n\tclose(): Promise<void>;\n\n\t/**\n\t * Drives all containers connected to this service toward convergence, processing pending operations and\n\t * waiting for all dirty containers to save.\n\t *\n\t * @param timeoutMilliseconds - The maximum time to wait for containers to quiesce, in milliseconds. Defaults to 30_000.\n\t *\n\t * @privateRemarks\n\t * This is a best-effort implementation simplified from `LoaderContainerTracker.ensureSynchronized`.\n\t * Currently it does not perform receiver-side sequence-number quiescence or wait for join/leave (audience) ops.\n\t * See `LoaderContainerTracker.ensureSynchronized` for the fuller version this is based on.\n\t * For the currently exposed API surface, this should be sufficient,\n\t * but users down casting to internal types might run into some limitations.\n\t */\n\tsynchronize(timeoutMilliseconds?: number): Promise<void>;\n\n\t/**\n\t * Creates and returns a {@link EphemeralServiceClient} for an in-memory, ephemeral Fluid service.\n\t *\n\t * @param options - Options for the client. `minVersionForCollaboration` may be omitted (since all collaborators\n\t * are in the same process, it defaults to the current version). `service` may be omitted to allocate a new\n\t * {@link EphemeralService} dedicated to this client, or provided to connect the client to an existing service instance.\n\t *\n\t * @remarks\n\t * The service is ephemeral and in-memory: all documents are held by the {@link EphemeralService} the client is\n\t * connected to, and live for as long as that service is open — independent of whether any container for them is open.\n\t * A document created and attached (obtaining an `id`) can be loaded by `id` for as long as its service remains open,\n\t * even after every container for it has been closed.\n\t * Closing the service (via {@link EphemeralService.close} or {@link cleanupEphemeralService}) discards all of its\n\t * documents and releases its resources; afterwards those `id`s can no longer be loaded.\n\t *\n\t * When no `service` is provided, a new one is allocated for this client (accessible via {@link EphemeralServiceClient.service}).\n\t * Provide the same {@link EphemeralService} to multiple clients (via `options.service`) to have them collaborate on the\n\t * same documents, and control that service's lifetime explicitly.\n\t *\n\t * Since a service holds timers while open, tests should close the services they use (e.g. via\n\t * {@link cleanupEphemeralService} in an `afterEach`) to avoid lingering timers that can hang test runners.\n\t *\n\t * @privateRemarks\n\t * TODO: We should provide a way to extract (for potential serialization as test data) and load documents into a service.\n\t * This is needed to use this API surface for testing reference documents.\n\t * Ideally we would provide a service agnostic way to do the export, but likely only support loading them into the local service.\n\t * This can be done via an API on FluidContainer (or a free function taking one) to do the export, then adding a\n\t * service specific API (on {@link EphemeralService}) to load from the export format and return the ID of the loaded document.\n\t */\n\tnewClient(options: ServiceOptions): EphemeralServiceClient;\n\n\t/**\n\t * A client connected to this service using the default options.\n\t */\n\treadonly defaultClient: EphemeralServiceClient;\n}\n\n/**\n * The {@link defaultEphemeralService} if one has been {@link startEphemeralService|started}.\n */\nlet defaultEphemeralService: EphemeralServiceImplementation | undefined;\n\n/**\n * The concrete implementation of {@link EphemeralService}.\n * @remarks\n * Kept module-private so its mutable state and internal helpers are not part of the public API.\n * Narrow an {@link EphemeralService} to it with `EphemeralServiceImplementation.narrow`.\n */\nclass EphemeralServiceImplementation\n\textends ErasedTypeImplementation<EphemeralService>\n\timplements EphemeralService\n{\n\t// A single server is shared by all containers connected to this service so they can communicate with each other.\n\tprivate readonly server: ILocalDeltaConnectionServer =\n\t\tLocalDeltaConnectionServer.create(\n\t\t\t// new LocalSessionStorageDbFactory(),\n\t\t);\n\tprivate readonly documentServiceFactory = new LocalDocumentServiceFactory(this.server);\n\tprivate readonly containers = new Set<EphemeralServiceContainer<unknown>>();\n\tprivate closed = false;\n\n\tpublic constructor() {\n\t\tsuper();\n\t\tthis.defaultClient = this.newClient();\n\t}\n\tpublic newClient(options?: Partial<ServiceOptions>): EphemeralServiceClient {\n\t\tconst finalOptions: EphemeralServiceOptions = {\n\t\t\tminVersionForCollaboration:\n\t\t\t\toptions?.minVersionForCollaboration ?? featureVersion(pkgVersion),\n\t\t\tservice: this,\n\t\t};\n\t\treturn new EphemeralServiceClientImplementation(finalOptions);\n\t}\n\tpublic readonly defaultClient: EphemeralServiceClient;\n\n\tpublic async close(): Promise<void> {\n\t\tif (this.closed) {\n\t\t\treturn;\n\t\t}\n\t\tthis.closed = true;\n\n\t\t// Close every open container via the same public close() path a user would use.\n\t\t// We might want to remove this.\n\t\tconst toClose = [...this.containers];\n\t\tthis.containers.clear();\n\t\tfor (const c of toClose) {\n\t\t\tc.close();\n\t\t}\n\n\t\t// Shut down the in-memory server. Its timers (e.g. the Deli read-client idle `setInterval`) belong to the\n\t\t// server rather than any container, so closing containers alone would leave them running.\n\t\tawait this.server.close();\n\t}\n\n\tpublic async synchronize(timeoutMilliseconds = 30_000): Promise<void> {\n\t\t// Timeout to allow for better errors in the case of hangs.\n\t\tlet timedOut = false;\n\t\tlet deadlineTimer: ReturnType<typeof setTimeout> | undefined;\n\t\tconst deadline = new Promise<true>((resolve) => {\n\t\t\tdeadlineTimer = setTimeout(() => {\n\t\t\t\ttimedOut = true;\n\t\t\t\tresolve(true);\n\t\t\t}, timeoutMilliseconds);\n\t\t});\n\n\t\ttry {\n\t\t\t// Require two consecutive quiescent passes (no dirty containers and no pending server work),\n\t\t\t// each separated by a macrotask turn, to give late side effects a chance to surface.\n\t\t\tlet clean = 0;\n\t\t\twhile (clean < 2) {\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`EphemeralService.synchronize timed out after ${timeoutMilliseconds}ms waiting for local containers to quiesce.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Yield a macrotask turn *first*, so the local server's scheduled broadcast send and each\n\t\t\t\t// container's inbound op processing can run before we sample their state below. Sampling\n\t\t\t\t// hasPendingWork() in a tight `while (await ...)` loop instead would starve that scheduled\n\t\t\t\t// send (it is a macrotask, while the await resolves on the microtask queue) and could hang.\n\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\tsetTimeout(resolve, 0);\n\t\t\t\t});\n\n\t\t\t\t// Prune any containers that have closed since the last pass.\n\t\t\t\tfor (const container of [...this.containers]) {\n\t\t\t\t\tif (container.container.closed) {\n\t\t\t\t\t\tthis.containers.delete(container);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst containersToApply = [...this.containers].map((container) => container.container);\n\n\t\t\t\t// Ignore readonly/disconnected dirty containers: they can't send ops, so nothing can be done about them being dirty here.\n\t\t\t\t// Neither state is reachable through the ephemeral service API today, but the checks are cheap and keep this robust to future changes.\n\t\t\t\tconst dirtyContainers = containersToApply.filter((c) => {\n\t\t\t\t\tconst { deltaManager, isDirty, connectionState } = c;\n\t\t\t\t\treturn (\n\t\t\t\t\t\tconnectionState !== ConnectionState.Disconnected &&\n\t\t\t\t\t\tdeltaManager.readOnlyInfo.readonly !== true &&\n\t\t\t\t\t\tisDirty\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tif (dirtyContainers.length > 0) {\n\t\t\t\t\t// Bound this wait by the shared deadline: a container that never saves (and never\n\t\t\t\t\t// closes) must not block past the overall timeout, since the top-of-loop check can't\n\t\t\t\t\t// run while we are awaiting here.\n\t\t\t\t\tawait Promise.race([\n\t\t\t\t\t\tPromise.all(\n\t\t\t\t\t\t\tdirtyContainers.map(async (c) =>\n\t\t\t\t\t\t\t\tPromise.race([\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => c.once(\"saved\", resolve)),\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => c.once(\"closed\", resolve)),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdeadline,\n\t\t\t\t\t]);\n\n\t\t\t\t\tclean = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Sample pending server work once per pass (the macrotask yield above gave the broadcaster's\n\t\t\t\t// scheduled send a chance to run first).\n\t\t\t\tif (await Promise.race([this.server.hasPendingWork(), deadline])) {\n\t\t\t\t\tclean = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tclean++;\n\t\t\t}\n\t\t} finally {\n\t\t\tclearTimeout(deadlineTimer);\n\t\t}\n\t}\n\n\t/**\n\t * The document service factory for this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic getDocumentServiceFactory(): LocalDocumentServiceFactory {\n\t\tassert(\n\t\t\t!this.closed,\n\t\t\t0xd11 /* Cannot create or load containers on a closed EphemeralService */,\n\t\t);\n\t\treturn this.documentServiceFactory;\n\t}\n\n\t/**\n\t * Registers a newly created container as connected to this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic addContainer(container: EphemeralServiceContainer<unknown>): void {\n\t\tthis.containers.add(container);\n\t}\n\n\t/**\n\t * Removes a now-closed container from this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic removeContainer(container: EphemeralServiceContainer<unknown>): void {\n\t\tthis.containers.delete(container);\n\t}\n}\n\n/**\n * A {@link @fluidframework/driver-definitions#ServiceClient} connected to a specific {@link EphemeralService}.\n * @alpha @sealed\n */\nexport interface EphemeralServiceClient extends ServiceClient {\n\t/**\n\t * The service instance this client is connected to.\n\t */\n\treadonly service: EphemeralService;\n}\n\nclass EphemeralServiceClientImplementation\n\textends ServiceClientImplementation<EphemeralServiceOptions>\n\timplements EphemeralServiceClient\n{\n\tpublic readonly service: EphemeralService;\n\n\tpublic constructor(options: EphemeralServiceOptions) {\n\t\tsuper(options, EphemeralServiceContainer);\n\t\tthis.service = options.service;\n\t}\n}\n\nconst containerRuntimeLoader: ContainerRuntimeLoader = async (\n\tparameters: ContainerRuntimeLoaderParams,\n) => {\n\tconst { runtime } = await ContainerRuntime.loadRuntime2({\n\t\tcontext: parameters.context,\n\t\tregistry: parameters.registry,\n\t\tprovideEntryPoint: parameters.provideEntryPoint,\n\t\texisting: parameters.existing,\n\t\tminVersionForCollab: parameters.minVersionForCollab,\n\t\truntimeOptions: { enableRuntimeIdCompressor: \"on\" },\n\t});\n\tif (!parameters.existing) {\n\t\tassert(\n\t\t\tparameters.newContainerRootType !== undefined,\n\t\t\t0xd12 /* Root data store kind must be provided for new containers */,\n\t\t);\n\t\tconst dataStore = await runtime.createDataStore(parameters.newContainerRootType);\n\t\tconst aliasResult = await dataStore.trySetAlias(rootDataStoreId);\n\t\tassert(\n\t\t\taliasResult === \"Success\",\n\t\t\t0xd13 /* Should be able to set alias on new data store */,\n\t\t);\n\t}\n\treturn runtime;\n};\n\nconst urlResolver = new LocalResolver();\n/**\n * Create a request to open an existing document.\n *\n * @param documentId - the existing document to open.\n * @privateRemarks\n * Like createLocalResolverCreateNewRequest, but without the option to create a new document.\n * TODO: At some point we should avoid specifying the URL in so many places, but the current APIs don't accommodate it yet.\n */\nconst createLoadExistingRequest = (documentId: string): IRequest => {\n\treturn { url: `http://localhost:3000/${documentId}` };\n};\n\nlet documentIdCounter = 0;\n\n/**\n * A Fluid container backed by an ephemeral (in-memory) local service, implementing\n * {@link @fluidframework/driver-definitions#FluidContainerWithService}.\n *\n * @remarks\n * Data is stored in-memory by the {@link EphemeralService} the container's client is connected to (see\n * {@link EphemeralServiceContainer.service}), enabling side-by-side collaboration testing without a real server.\n *\n * @internal\n */\nexport class EphemeralServiceContainer<TData>\n\textends ServiceContainerBase<TData, EphemeralServiceOptions>\n\timplements FluidContainerWithService<TData>\n{\n\tpublic readonly service: EphemeralService;\n\n\tpublic static async createDetached<T>(\n\t\tregistry: DataStoreRegistry<T>,\n\t\toptions: EphemeralServiceOptions,\n\t\troot: DataStoreKind<T>,\n\t): Promise<EphemeralServiceContainer<T>> {\n\t\tEphemeralServiceImplementation.narrow(options.service);\n\t\tconst container: IContainer = await createDetachedContainer({\n\t\t\tcodeDetails: { package: \"1.0\" },\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory: options.service.getDocumentServiceFactory(),\n\t\t\tcodeLoader: makeCodeLoader(\n\t\t\t\tregistry,\n\t\t\t\toptions.minVersionForCollaboration,\n\t\t\t\tcontainerRuntimeLoader,\n\t\t\t\troot,\n\t\t\t),\n\t\t});\n\n\t\treturn new EphemeralServiceContainer<T>(\n\t\t\tregistry,\n\t\t\toptions,\n\t\t\tcontainer,\n\t\t\t(await container.getEntryPoint()) as T,\n\t\t\tundefined,\n\t\t);\n\t}\n\n\tpublic static async load<T>(\n\t\tregistry: DataStoreRegistry<T>,\n\t\toptions: EphemeralServiceOptions,\n\t\tid: string,\n\t): Promise<EphemeralServiceContainer<T> & FluidContainerAttached<T>> {\n\t\tEphemeralServiceImplementation.narrow(options.service);\n\t\tconst containerInner = await loadExistingContainer({\n\t\t\trequest: createLoadExistingRequest(id),\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory: options.service.getDocumentServiceFactory(),\n\t\t\tcodeLoader: makeCodeLoader(\n\t\t\t\tregistry,\n\t\t\t\toptions.minVersionForCollaboration,\n\t\t\t\tcontainerRuntimeLoader,\n\t\t\t),\n\t\t});\n\n\t\tconst container = new EphemeralServiceContainer<T>(\n\t\t\tregistry,\n\t\t\toptions,\n\t\t\tcontainerInner,\n\t\t\t(await containerInner.getEntryPoint()) as T,\n\t\t\tid,\n\t\t);\n\t\tassert(\n\t\t\tcontainer.id !== undefined,\n\t\t\t0xd14 /* id should be defined when loading a container */,\n\t\t);\n\t\treturn container as typeof container & { id: string };\n\t}\n\n\tprivate constructor(\n\t\tregistry: Registry<Promise<DataStoreKind<TData>>>,\n\t\toptions: EphemeralServiceOptions,\n\t\tcontainer: IContainer,\n\t\tdata: TData,\n\t\tid: string | undefined,\n\t) {\n\t\tsuper(registry, options, container, data, id);\n\t\tthis.service = options.service;\n\t\tEphemeralServiceImplementation.narrow(this.service);\n\t\tthis.service.addContainer(this);\n\t}\n\n\tpublic override close(): void {\n\t\tsuper.close();\n\t\t// Remove this now-closed container from its service's set of open containers.\n\t\tEphemeralServiceImplementation.narrow(this.service);\n\t\tthis.service.removeContainer(this);\n\t}\n\n\tprotected createAttachRequest(): IRequest {\n\t\tconst documentId = (documentIdCounter++).toString();\n\t\treturn createLocalResolverCreateNewRequest(documentId);\n\t}\n}\n"]}
1
+ {"version":3,"file":"ephemeralService.js","sourceRoot":"","sources":["../src/ephemeralService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6EAGwD;AACxD,wEAGmD;AACnD,yEAA8E;AAE9E,uEAGkD;AAClD,kEAA6D;AAC7D,0EAUqD;AACrD,qEAOgD;AAChD,6EAG6C;AAC7C,oEAAmE;AAEnE,qFAA+E;AAC/E,yDAAwF;AACxF,2DAAiD;AAEjD;;;;;;;;;;GAUG;AACH,SAAgB,qBAAqB,CAAC,SAAS,GAAG,IAAI;IACrD,IAAI,SAAS,IAAI,uBAAuB,EAAE,CAAC;QAC1C,MAAM,IAAI,qBAAU,CAAC,+CAA+C,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,8BAA8B,EAAE,CAAC;IACrD,IAAI,SAAS,EAAE,CAAC;QACf,uBAAuB,GAAG,OAAO,CAAC;IACnC,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AAVD,sDAUC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,uBAAuB,CAAC,OAA0B;IACvE,MAAM,SAAS,GAAG,OAAO,IAAI,u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,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAES,mBAAmB;QAC5B,MAAM,UAAU,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QACpD,OAAO,IAAA,sDAAmC,EAAC,UAAU,CAAC,CAAC;IACxD,CAAC;CACD;AAxFD,8DAwFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tConnectionState,\n\ttype IContainer,\n} from \"@fluidframework/container-definitions/internal\";\nimport {\n\tcreateDetachedContainer,\n\tloadExistingContainer,\n} from \"@fluidframework/container-loader/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tErasedTypeImplementation,\n\ttype ErasedBaseType,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tfeatureVersion,\n\ttype DataStoreKind,\n\ttype DataStoreRegistry,\n\ttype FluidContainerAttached,\n\ttype FluidContainerWithService,\n\ttype OldestSupportedServiceClientVersion,\n\ttype Registry,\n\ttype ServiceClient,\n\ttype ServiceOptions,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype ContainerRuntimeLoader,\n\ttype ContainerRuntimeLoaderParams,\n\tmakeCodeLoader,\n\trootDataStoreId,\n\tServiceClientImplementation,\n\tServiceContainerBase,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tLocalDeltaConnectionServer,\n\ttype ILocalDeltaConnectionServer,\n} from \"@fluidframework/server-local-server\";\nimport { UsageError } from \"@fluidframework/driver-utils/internal\";\n\nimport { LocalDocumentServiceFactory } from \"./localDocumentServiceFactory.js\";\nimport { createLocalResolverCreateNewRequest, LocalResolver } from \"./localResolver.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * Starts and returns a new {@link EphemeralService}.\n * @param isDefault - Whether this service should saved as the default service for {@link cleanupEphemeralService} to cleanup.\n * Defaults to true.\n * @remarks\n * The returned service owns an in-memory server and holds the documents created through clients connected to it.\n * {@link cleanupEphemeralService} can be used to ensure the service is properly cleaned up (a no-op if stopped/closed already).\n *\n * As a service, it may start timers which may require an explicit `close` to fully free.\n * @alpha\n */\nexport function startEphemeralService(isDefault = true): EphemeralService {\n\tif (isDefault && defaultEphemeralService) {\n\t\tthrow new UsageError(\"A default EphemeralService is already running\");\n\t}\n\n\tconst service = new EphemeralServiceImplementation();\n\tif (isDefault) {\n\t\tdefaultEphemeralService = service;\n\t}\n\treturn service;\n}\n\n/**\n * Cleans up the service passed in {@link startEphemeralService}, or the {@link getDefaultEphemeralService|default} if none is passed.\n * @remarks\n * This closes the service, and all its containers.\n * This is a good way to ensure the service and its containers leave no lingering timers\n * which could leak memory, trigger asynchronous work or prevent a clean process exit.\n * @alpha\n */\nexport async function cleanupEphemeralService(service?: EphemeralService): Promise<void> {\n\tconst toCleanup = service ?? defaultEphemeralService;\n\tif (toCleanup) {\n\t\t// TODO: we may want to make closing of containers a separate operation which is done here.\n\t\tawait toCleanup.close();\n\t}\n\tif (toCleanup === defaultEphemeralService) {\n\t\tdefaultEphemeralService = undefined;\n\t}\n}\n\n/**\n * Get the default {@link EphemeralService} if one has been {@link startEphemeralService|started}.\n * @throws If no default service is running.\n * @alpha\n */\nexport function getDefaultEphemeralService(): EphemeralService {\n\tif (defaultEphemeralService) {\n\t\treturn defaultEphemeralService;\n\t}\n\tthrow new UsageError(\"No default EphemeralService is running\");\n}\n\n/**\n * Internal Options for creating an {@link EphemeralServiceClient}, extending {@link @fluidframework/driver-definitions#ServiceOptions}\n * with the {@link EphemeralService} the client should connect to.\n * @input\n * @internal\n */\nexport interface EphemeralServiceOptions extends ServiceOptions {\n\t/**\n\t * {@inheritdoc @fluidframework/driver-definitions#ServiceOptions.oldestSupportedClient}\n\t */\n\treadonly oldestSupportedClient: OldestSupportedServiceClientVersion;\n\t/**\n\t * The service instance to connect to.\n\t */\n\treadonly service: EphemeralService;\n}\n\n/**\n * An in-memory Fluid service that can produce connected {@link EphemeralServiceClient}s.\n * @remarks\n * All documents created through clients connected to a given `EphemeralService` are held in-memory by that service.\n * Closing the service (via {@link EphemeralService.close} or {@link cleanupEphemeralService}) closes the connections\n * to any remaining open containers, and cleans up the service's timers.\n *\n * Create one with {@link startEphemeralService}.\n *\n * Most {@link @fluidframework/driver-definitions#ServiceClient} implementations would take in a URL and credentials to connect to a service,\n * but that is not needed for the ephemeral in-memory service.\n * Instead this object representing the actual service instance is provided.\n * @privateRemarks\n * This is separated out from the actual {@link @fluidframework/driver-definitions#ServiceClient} object so that it's possible to create multiple service clients\n * connected to the same service.\n * Doing so is rarely necessary, but would be needed to test multiple clients collaborating on the same\n * document with different `oldestSupportedClient` values.\n * This also exposes a place to put APIs for preloading and exporting document contents in the future.\n *\n * This is an erased type: its only implementation is the module-private {@link EphemeralServiceImplementation}, which holds\n * the mutable server and container state so it does not appear on this public type.\n *\n * TODO: formalize this lifecycle with an interface which documents these stages.\n * Lifecycle:\n * The intended lifecycle of an {@link EphemeralService} follows roughly the same pattern as containers:\n *\n * 1. Open: accepts connections from {@link EphemeralServiceClient}s, which can create and load containers.\n * Might have timers and event registrations which can trigger asynchronous work, and retain the object in memory.\n *\n * 2. Closing: asynchronous transition from open to closed. New use should behave as it closed, but may be cleaning up or saving resources asynchronously.\n * Timers and event registrations may still be active, but should be cleaned up by the time the transition to closed completes.\n *\n * 3. Closed: no longer accepts connections from {@link EphemeralServiceClient}s, and all containers connected to it are closed.\n * Should have no subscriptions to events or timers which could retain it in memory or trigger asynchronous work.\n * The object can still be used in a limited capacity (typically just to inspect its status (e.g. `isClosed`), and to view (but not edit) the final state of any containers which were connected to it before it closed.)\n *\n * Events or errors can cause an open to closing transition. Any nonfunctional state, including error states, should be considered as closed (or closing which will transition to closed),\n * and meet the requirements of closed with regards to timers and events.\n *\n * @alpha @sealed\n */\nexport interface EphemeralService extends ErasedBaseType<readonly [\"EphemeralService\"]> {\n\t/**\n\t * Close this service, which closes all containers connected to it and releases its resources.\n\t * @remarks\n\t * All documents held by this service are discarded, and any timers it (or its containers) were keeping alive\n\t * are cleaned up.\n\t * The returned promise resolves once all asynchronous cleanup (including shutting down the in-memory server)\n\t * has completed.\n\t * Closing is idempotent: calling it again after the service is closed resolves without doing anything.\n\t */\n\tclose(): Promise<void>;\n\n\t/**\n\t * Drives all containers connected to this service toward convergence, processing pending operations and\n\t * waiting for all dirty containers to save.\n\t *\n\t * @param timeoutMilliseconds - The maximum time to wait for containers to quiesce, in milliseconds. Defaults to 30_000.\n\t *\n\t * @privateRemarks\n\t * This is a best-effort implementation simplified from `LoaderContainerTracker.ensureSynchronized`.\n\t * Currently it does not perform receiver-side sequence-number quiescence or wait for join/leave (audience) ops.\n\t * See `LoaderContainerTracker.ensureSynchronized` for the fuller version this is based on.\n\t * For the currently exposed API surface, this should be sufficient,\n\t * but users down casting to internal types might run into some limitations.\n\t */\n\tsynchronize(timeoutMilliseconds?: number): Promise<void>;\n\n\t/**\n\t * Creates and returns a {@link EphemeralServiceClient} for an in-memory, ephemeral Fluid service.\n\t *\n\t * @param options - Options for the client. `oldestSupportedClient` may be omitted because all\n\t * clients are in the same process, so it defaults to the current version. `service` may be omitted to allocate a new\n\t * {@link EphemeralService} dedicated to this client, or provided to connect the client to an existing service instance.\n\t *\n\t * @remarks\n\t * The service is ephemeral and in-memory: all documents are held by the {@link EphemeralService} the client is\n\t * connected to, and live for as long as that service is open — independent of whether any container for them is open.\n\t * A document created and attached (obtaining an `id`) can be loaded by `id` for as long as its service remains open,\n\t * even after every container for it has been closed.\n\t * Closing the service (via {@link EphemeralService.close} or {@link cleanupEphemeralService}) discards all of its\n\t * documents and releases its resources; afterwards those `id`s can no longer be loaded.\n\t *\n\t * When no `service` is provided, a new one is allocated for this client (accessible via {@link EphemeralServiceClient.service}).\n\t * Provide the same {@link EphemeralService} to multiple clients (via `options.service`) to have them collaborate on the\n\t * same documents, and control that service's lifetime explicitly.\n\t *\n\t * Since a service holds timers while open, tests should close the services they use (e.g. via\n\t * {@link cleanupEphemeralService} in an `afterEach`) to avoid lingering timers that can hang test runners.\n\t *\n\t * @privateRemarks\n\t * TODO: We should provide a way to extract (for potential serialization as test data) and load documents into a service.\n\t * This is needed to use this API surface for testing reference documents.\n\t * Ideally we would provide a service agnostic way to do the export, but likely only support loading them into the local service.\n\t * This can be done via an API on FluidContainer (or a free function taking one) to do the export, then adding a\n\t * service specific API (on {@link EphemeralService}) to load from the export format and return the ID of the loaded document.\n\t */\n\tnewClient(options: ServiceOptions): EphemeralServiceClient;\n\n\t/**\n\t * A client connected to this service using the default options.\n\t */\n\treadonly defaultClient: EphemeralServiceClient;\n}\n\n/**\n * The {@link defaultEphemeralService} if one has been {@link startEphemeralService|started}.\n */\nlet defaultEphemeralService: EphemeralServiceImplementation | undefined;\n\n/**\n * The concrete implementation of {@link EphemeralService}.\n * @remarks\n * Kept module-private so its mutable state and internal helpers are not part of the public API.\n * Narrow an {@link EphemeralService} to it with `EphemeralServiceImplementation.narrow`.\n */\nclass EphemeralServiceImplementation\n\textends ErasedTypeImplementation<EphemeralService>\n\timplements EphemeralService\n{\n\t// A single server is shared by all containers connected to this service so they can communicate with each other.\n\tprivate readonly server: ILocalDeltaConnectionServer =\n\t\tLocalDeltaConnectionServer.create(\n\t\t\t// new LocalSessionStorageDbFactory(),\n\t\t);\n\tprivate readonly documentServiceFactory = new LocalDocumentServiceFactory(this.server);\n\tprivate readonly containers = new Set<EphemeralServiceContainer<unknown>>();\n\tprivate closed = false;\n\n\tpublic constructor() {\n\t\tsuper();\n\t\tthis.defaultClient = this.newClient();\n\t}\n\tpublic newClient(options?: Partial<ServiceOptions>): EphemeralServiceClient {\n\t\tconst finalOptions: EphemeralServiceOptions = {\n\t\t\toldestSupportedClient: options?.oldestSupportedClient ?? featureVersion(pkgVersion),\n\t\t\tservice: this,\n\t\t};\n\t\treturn new EphemeralServiceClientImplementation(finalOptions);\n\t}\n\tpublic readonly defaultClient: EphemeralServiceClient;\n\n\tpublic async close(): Promise<void> {\n\t\tif (this.closed) {\n\t\t\treturn;\n\t\t}\n\t\tthis.closed = true;\n\n\t\t// Close every open container via the same public close() path a user would use.\n\t\t// We might want to remove this.\n\t\tconst toClose = [...this.containers];\n\t\tthis.containers.clear();\n\t\tfor (const c of toClose) {\n\t\t\tc.close();\n\t\t}\n\n\t\t// Shut down the in-memory server. Its timers (e.g. the Deli read-client idle `setInterval`) belong to the\n\t\t// server rather than any container, so closing containers alone would leave them running.\n\t\tawait this.server.close();\n\t}\n\n\tpublic async synchronize(timeoutMilliseconds = 30_000): Promise<void> {\n\t\t// Timeout to allow for better errors in the case of hangs.\n\t\tlet timedOut = false;\n\t\tlet deadlineTimer: ReturnType<typeof setTimeout> | undefined;\n\t\tconst deadline = new Promise<true>((resolve) => {\n\t\t\tdeadlineTimer = setTimeout(() => {\n\t\t\t\ttimedOut = true;\n\t\t\t\tresolve(true);\n\t\t\t}, timeoutMilliseconds);\n\t\t});\n\n\t\ttry {\n\t\t\t// Require two consecutive quiescent passes (no dirty containers and no pending server work),\n\t\t\t// each separated by a macrotask turn, to give late side effects a chance to surface.\n\t\t\tlet clean = 0;\n\t\t\twhile (clean < 2) {\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`EphemeralService.synchronize timed out after ${timeoutMilliseconds}ms waiting for local containers to quiesce.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Yield a macrotask turn *first*, so the local server's scheduled broadcast send and each\n\t\t\t\t// container's inbound op processing can run before we sample their state below. Sampling\n\t\t\t\t// hasPendingWork() in a tight `while (await ...)` loop instead would starve that scheduled\n\t\t\t\t// send (it is a macrotask, while the await resolves on the microtask queue) and could hang.\n\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\tsetTimeout(resolve, 0);\n\t\t\t\t});\n\n\t\t\t\t// Prune any containers that have closed since the last pass.\n\t\t\t\tfor (const container of [...this.containers]) {\n\t\t\t\t\tif (container.container.closed) {\n\t\t\t\t\t\tthis.containers.delete(container);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst containersToApply = [...this.containers].map((container) => container.container);\n\n\t\t\t\t// Ignore readonly/disconnected dirty containers: they can't send ops, so nothing can be done about them being dirty here.\n\t\t\t\t// Neither state is reachable through the ephemeral service API today, but the checks are cheap and keep this robust to future changes.\n\t\t\t\tconst dirtyContainers = containersToApply.filter((c) => {\n\t\t\t\t\tconst { deltaManager, isDirty, connectionState } = c;\n\t\t\t\t\treturn (\n\t\t\t\t\t\tconnectionState !== ConnectionState.Disconnected &&\n\t\t\t\t\t\tdeltaManager.readOnlyInfo.readonly !== true &&\n\t\t\t\t\t\tisDirty\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tif (dirtyContainers.length > 0) {\n\t\t\t\t\t// Bound this wait by the shared deadline: a container that never saves (and never\n\t\t\t\t\t// closes) must not block past the overall timeout, since the top-of-loop check can't\n\t\t\t\t\t// run while we are awaiting here.\n\t\t\t\t\tawait Promise.race([\n\t\t\t\t\t\tPromise.all(\n\t\t\t\t\t\t\tdirtyContainers.map(async (c) =>\n\t\t\t\t\t\t\t\tPromise.race([\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => c.once(\"saved\", resolve)),\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => c.once(\"closed\", resolve)),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdeadline,\n\t\t\t\t\t]);\n\n\t\t\t\t\tclean = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Sample pending server work once per pass (the macrotask yield above gave the broadcaster's\n\t\t\t\t// scheduled send a chance to run first).\n\t\t\t\tif (await Promise.race([this.server.hasPendingWork(), deadline])) {\n\t\t\t\t\tclean = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tclean++;\n\t\t\t}\n\t\t} finally {\n\t\t\tclearTimeout(deadlineTimer);\n\t\t}\n\t}\n\n\t/**\n\t * The document service factory for this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic getDocumentServiceFactory(): LocalDocumentServiceFactory {\n\t\tassert(\n\t\t\t!this.closed,\n\t\t\t0xd11 /* Cannot create or load containers on a closed EphemeralService */,\n\t\t);\n\t\treturn this.documentServiceFactory;\n\t}\n\n\t/**\n\t * Registers a newly created container as connected to this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic addContainer(container: EphemeralServiceContainer<unknown>): void {\n\t\tthis.containers.add(container);\n\t}\n\n\t/**\n\t * Removes a now-closed container from this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic removeContainer(container: EphemeralServiceContainer<unknown>): void {\n\t\tthis.containers.delete(container);\n\t}\n}\n\n/**\n * A {@link @fluidframework/driver-definitions#ServiceClient} connected to a specific {@link EphemeralService}.\n * @alpha @sealed\n */\nexport interface EphemeralServiceClient extends ServiceClient {\n\t/**\n\t * The service instance this client is connected to.\n\t */\n\treadonly service: EphemeralService;\n}\n\nclass EphemeralServiceClientImplementation\n\textends ServiceClientImplementation<EphemeralServiceOptions>\n\timplements EphemeralServiceClient\n{\n\tpublic readonly service: EphemeralService;\n\n\tpublic constructor(options: EphemeralServiceOptions) {\n\t\tsuper(options, EphemeralServiceContainer);\n\t\tthis.service = options.service;\n\t}\n}\n\nconst containerRuntimeLoader: ContainerRuntimeLoader = async (\n\tparameters: ContainerRuntimeLoaderParams,\n) => {\n\tconst { runtime } = await ContainerRuntime.loadRuntime2({\n\t\tcontext: parameters.context,\n\t\tregistry: parameters.registry,\n\t\tprovideEntryPoint: parameters.provideEntryPoint,\n\t\texisting: parameters.existing,\n\t\tminVersionForCollab: parameters.minVersionForCollab,\n\t\truntimeOptions: { enableRuntimeIdCompressor: \"on\" },\n\t});\n\tif (!parameters.existing) {\n\t\tassert(\n\t\t\tparameters.newContainerRootType !== undefined,\n\t\t\t0xd12 /* Root data store kind must be provided for new containers */,\n\t\t);\n\t\tconst dataStore = await runtime.createDataStore(parameters.newContainerRootType);\n\t\tconst aliasResult = await dataStore.trySetAlias(rootDataStoreId);\n\t\tassert(\n\t\t\taliasResult === \"Success\",\n\t\t\t0xd13 /* Should be able to set alias on new data store */,\n\t\t);\n\t}\n\treturn runtime;\n};\n\nconst urlResolver = new LocalResolver();\n/**\n * Create a request to open an existing document.\n *\n * @param documentId - the existing document to open.\n * @privateRemarks\n * Like createLocalResolverCreateNewRequest, but without the option to create a new document.\n * TODO: At some point we should avoid specifying the URL in so many places, but the current APIs don't accommodate it yet.\n */\nconst createLoadExistingRequest = (documentId: string): IRequest => {\n\treturn { url: `http://localhost:3000/${documentId}` };\n};\n\nlet documentIdCounter = 0;\n\n/**\n * A Fluid container backed by an ephemeral (in-memory) local service, implementing\n * {@link @fluidframework/driver-definitions#FluidContainerWithService}.\n *\n * @remarks\n * Data is stored in-memory by the {@link EphemeralService} the container's client is connected to (see\n * {@link EphemeralServiceContainer.service}), enabling side-by-side collaboration testing without a real server.\n *\n * @internal\n */\nexport class EphemeralServiceContainer<TData>\n\textends ServiceContainerBase<TData, EphemeralServiceOptions>\n\timplements FluidContainerWithService<TData>\n{\n\tpublic readonly service: EphemeralService;\n\n\tpublic static async createDetached<T>(\n\t\tregistry: DataStoreRegistry<T>,\n\t\toptions: EphemeralServiceOptions,\n\t\troot: DataStoreKind<T>,\n\t): Promise<EphemeralServiceContainer<T>> {\n\t\tEphemeralServiceImplementation.narrow(options.service);\n\t\tconst container: IContainer = await createDetachedContainer({\n\t\t\tcodeDetails: { package: \"1.0\" },\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory: options.service.getDocumentServiceFactory(),\n\t\t\tcodeLoader: makeCodeLoader(\n\t\t\t\tregistry,\n\t\t\t\toptions.oldestSupportedClient,\n\t\t\t\tcontainerRuntimeLoader,\n\t\t\t\troot,\n\t\t\t),\n\t\t});\n\n\t\treturn new EphemeralServiceContainer<T>(\n\t\t\tregistry,\n\t\t\toptions,\n\t\t\tcontainer,\n\t\t\t(await container.getEntryPoint()) as T,\n\t\t\tundefined,\n\t\t);\n\t}\n\n\tpublic static async load<T>(\n\t\tregistry: DataStoreRegistry<T>,\n\t\toptions: EphemeralServiceOptions,\n\t\tid: string,\n\t): Promise<EphemeralServiceContainer<T> & FluidContainerAttached<T>> {\n\t\tEphemeralServiceImplementation.narrow(options.service);\n\t\tconst containerInner = await loadExistingContainer({\n\t\t\trequest: createLoadExistingRequest(id),\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory: options.service.getDocumentServiceFactory(),\n\t\t\tcodeLoader: makeCodeLoader(\n\t\t\t\tregistry,\n\t\t\t\toptions.oldestSupportedClient,\n\t\t\t\tcontainerRuntimeLoader,\n\t\t\t),\n\t\t});\n\n\t\tconst container = new EphemeralServiceContainer<T>(\n\t\t\tregistry,\n\t\t\toptions,\n\t\t\tcontainerInner,\n\t\t\t(await containerInner.getEntryPoint()) as T,\n\t\t\tid,\n\t\t);\n\t\tassert(\n\t\t\tcontainer.id !== undefined,\n\t\t\t0xd14 /* id should be defined when loading a container */,\n\t\t);\n\t\treturn container as typeof container & { id: string };\n\t}\n\n\tprivate constructor(\n\t\tregistry: Registry<Promise<DataStoreKind<TData>>>,\n\t\toptions: EphemeralServiceOptions,\n\t\tcontainer: IContainer,\n\t\tdata: TData,\n\t\tid: string | undefined,\n\t) {\n\t\tsuper(registry, options, container, data, id);\n\t\tthis.service = options.service;\n\t\tEphemeralServiceImplementation.narrow(this.service);\n\t\tthis.service.addContainer(this);\n\t}\n\n\tpublic override close(): void {\n\t\tsuper.close();\n\t\t// Remove this now-closed container from its service's set of open containers.\n\t\tEphemeralServiceImplementation.narrow(this.service);\n\t\tthis.service.removeContainer(this);\n\t}\n\n\tprotected createAttachRequest(): IRequest {\n\t\tconst documentId = (documentIdCounter++).toString();\n\t\treturn createLocalResolverCreateNewRequest(documentId);\n\t}\n}\n"]}
@@ -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/local-driver";
8
- export declare const pkgVersion = "2.115.0";
8
+ export declare const pkgVersion = "2.116.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -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/local-driver";
11
- exports.pkgVersion = "2.115.0";
11
+ exports.pkgVersion = "2.116.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,8BAA8B,CAAC;AACzC,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/local-driver\";\nexport const pkgVersion = \"2.115.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,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/local-driver\";\nexport const pkgVersion = \"2.116.0\";\n"]}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import type { IRequest } from "@fluidframework/core-interfaces";
6
6
  import { type ErasedBaseType } from "@fluidframework/core-interfaces/internal";
7
- import type { DataStoreKind, DataStoreRegistry, FluidContainerAttached, FluidContainerWithService, ServiceClient, ServiceOptions } from "@fluidframework/driver-definitions/internal";
7
+ import { type DataStoreKind, type DataStoreRegistry, type FluidContainerAttached, type FluidContainerWithService, type OldestSupportedServiceClientVersion, type ServiceClient, type ServiceOptions } from "@fluidframework/driver-definitions/internal";
8
8
  import { ServiceContainerBase } from "@fluidframework/runtime-utils/internal";
9
9
  /**
10
10
  * Starts and returns a new {@link EphemeralService}.
@@ -40,6 +40,10 @@ export declare function getDefaultEphemeralService(): EphemeralService;
40
40
  * @internal
41
41
  */
42
42
  export interface EphemeralServiceOptions extends ServiceOptions {
43
+ /**
44
+ * {@inheritdoc @fluidframework/driver-definitions#ServiceOptions.oldestSupportedClient}
45
+ */
46
+ readonly oldestSupportedClient: OldestSupportedServiceClientVersion;
43
47
  /**
44
48
  * The service instance to connect to.
45
49
  */
@@ -61,7 +65,7 @@ export interface EphemeralServiceOptions extends ServiceOptions {
61
65
  * This is separated out from the actual {@link @fluidframework/driver-definitions#ServiceClient} object so that it's possible to create multiple service clients
62
66
  * connected to the same service.
63
67
  * Doing so is rarely necessary, but would be needed to test multiple clients collaborating on the same
64
- * document with different minVersionForCollaboration values.
68
+ * document with different `oldestSupportedClient` values.
65
69
  * This also exposes a place to put APIs for preloading and exporting document contents in the future.
66
70
  *
67
71
  * This is an erased type: its only implementation is the module-private {@link EphemeralServiceImplementation}, which holds
@@ -114,8 +118,8 @@ export interface EphemeralService extends ErasedBaseType<readonly ["EphemeralSer
114
118
  /**
115
119
  * Creates and returns a {@link EphemeralServiceClient} for an in-memory, ephemeral Fluid service.
116
120
  *
117
- * @param options - Options for the client. `minVersionForCollaboration` may be omitted (since all collaborators
118
- * are in the same process, it defaults to the current version). `service` may be omitted to allocate a new
121
+ * @param options - Options for the client. `oldestSupportedClient` may be omitted because all
122
+ * clients are in the same process, so it defaults to the current version. `service` may be omitted to allocate a new
119
123
  * {@link EphemeralService} dedicated to this client, or provided to connect the client to an existing service instance.
120
124
  *
121
125
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"ephemeralService.d.ts","sourceRoot":"","sources":["../src/ephemeralService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAEN,KAAK,cAAc,EACnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EACX,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,yBAAyB,EAEzB,aAAa,EACb,cAAc,EACd,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAMN,oBAAoB,EACpB,MAAM,wCAAwC,CAAC;AAWhD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,UAAO,GAAG,gBAAgB,CAUxE;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CASvF;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,IAAI,gBAAgB,CAK7D;AAED;;;;;GAKG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC9D;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,WAAW,gBAAiB,SAAQ,cAAc,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IACtF;;;;;;;;OAQG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE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,KAAK,CAC3C,SAAQ,oBAAoB,CAAC,KAAK,EAAE,uBAAuB,CAC3D,YAAW,yBAAyB,CAAC,KAAK,CAAC;IAE3C,SAAgB,OAAO,EAAE,gBAAgB,CAAC;WAEtB,cAAc,CAAC,CAAC,EACnC,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC9B,OAAO,EAAE,uBAAuB,EAChC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GACpB,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC;WAuBpB,IAAI,CAAC,CAAC,EACzB,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC9B,OAAO,EAAE,uBAAuB,EAChC,EAAE,EAAE,MAAM,GACR,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;IA2BpE,OAAO;IAaS,KAAK,IAAI,IAAI;IAO7B,SAAS,CAAC,mBAAmB,IAAI,QAAQ;CAIzC"}
@@ -7,7 +7,7 @@ import { createDetachedContainer, loadExistingContainer, } from "@fluidframework
7
7
  import { ContainerRuntime } from "@fluidframework/container-runtime/internal";
8
8
  import { ErasedTypeImplementation, } from "@fluidframework/core-interfaces/internal";
9
9
  import { assert } from "@fluidframework/core-utils/internal";
10
- import { featureVersion } from "@fluidframework/driver-definitions/internal";
10
+ import { featureVersion, } from "@fluidframework/driver-definitions/internal";
11
11
  import { makeCodeLoader, rootDataStoreId, ServiceClientImplementation, ServiceContainerBase, } from "@fluidframework/runtime-utils/internal";
12
12
  import { LocalDeltaConnectionServer, } from "@fluidframework/server-local-server";
13
13
  import { UsageError } from "@fluidframework/driver-utils/internal";
@@ -88,7 +88,7 @@ class EphemeralServiceImplementation extends ErasedTypeImplementation {
88
88
  }
89
89
  newClient(options) {
90
90
  const finalOptions = {
91
- minVersionForCollaboration: options?.minVersionForCollaboration ?? featureVersion(pkgVersion),
91
+ oldestSupportedClient: options?.oldestSupportedClient ?? featureVersion(pkgVersion),
92
92
  service: this,
93
93
  };
94
94
  return new EphemeralServiceClientImplementation(finalOptions);
@@ -252,7 +252,7 @@ export class EphemeralServiceContainer extends ServiceContainerBase {
252
252
  codeDetails: { package: "1.0" },
253
253
  urlResolver,
254
254
  documentServiceFactory: options.service.getDocumentServiceFactory(),
255
- codeLoader: makeCodeLoader(registry, options.minVersionForCollaboration, containerRuntimeLoader, root),
255
+ codeLoader: makeCodeLoader(registry, options.oldestSupportedClient, containerRuntimeLoader, root),
256
256
  });
257
257
  return new EphemeralServiceContainer(registry, options, container, (await container.getEntryPoint()), undefined);
258
258
  }
@@ -262,7 +262,7 @@ export class EphemeralServiceContainer extends ServiceContainerBase {
262
262
  request: createLoadExistingRequest(id),
263
263
  urlResolver,
264
264
  documentServiceFactory: options.service.getDocumentServiceFactory(),
265
- codeLoader: makeCodeLoader(registry, options.minVersionForCollaboration, containerRuntimeLoader),
265
+ codeLoader: makeCodeLoader(registry, options.oldestSupportedClient, containerRuntimeLoader),
266
266
  });
267
267
  const container = new EphemeralServiceContainer(registry, options, containerInner, (await containerInner.getEntryPoint()), id);
268
268
  assert(container.id !== undefined, 0xd14 /* id should be defined when loading a container */);
@@ -1 +1 @@
1
- {"version":3,"file":"ephemeralService.js","sourceRoot":"","sources":["../src/ephemeralService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,eAAe,GAEf,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACN,uBAAuB,EACvB,qBAAqB,GACrB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,OAAO,EACN,wBAAwB,GAExB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAU7D,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,EAGN,cAAc,EACd,eAAe,EACf,2BAA2B,EAC3B,oBAAoB,GACpB,MAA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E,CAAM,EAC3C,EAAE,CACF,CAAC;QACF,MAAM,CACL,SAAS,CAAC,EAAE,KAAK,SAAS,EAC1B,KAAK,CAAC,mDAAmD,CACzD,CAAC;QACF,OAAO,SAA8C,CAAC;IACvD,CAAC;IAED,YACC,QAAiD,EACjD,OAAgC,EAChC,SAAqB,EACrB,IAAW,EACX,EAAsB;QAEtB,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,8BAA8B,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAEe,KAAK;QACpB,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,8EAA8E;QAC9E,8BAA8B,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAES,mBAAmB;QAC5B,MAAM,UAAU,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QACpD,OAAO,mCAAmC,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tConnectionState,\n\ttype IContainer,\n} from \"@fluidframework/container-definitions/internal\";\nimport {\n\tcreateDetachedContainer,\n\tloadExistingContainer,\n} from \"@fluidframework/container-loader/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tErasedTypeImplementation,\n\ttype ErasedBaseType,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tDataStoreKind,\n\tDataStoreRegistry,\n\tFluidContainerAttached,\n\tFluidContainerWithService,\n\tRegistry,\n\tServiceClient,\n\tServiceOptions,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { featureVersion } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype ContainerRuntimeLoader,\n\ttype ContainerRuntimeLoaderParams,\n\tmakeCodeLoader,\n\trootDataStoreId,\n\tServiceClientImplementation,\n\tServiceContainerBase,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tLocalDeltaConnectionServer,\n\ttype ILocalDeltaConnectionServer,\n} from \"@fluidframework/server-local-server\";\nimport { UsageError } from \"@fluidframework/driver-utils/internal\";\n\nimport { LocalDocumentServiceFactory } from \"./localDocumentServiceFactory.js\";\nimport { createLocalResolverCreateNewRequest, LocalResolver } from \"./localResolver.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * Starts and returns a new {@link EphemeralService}.\n * @param isDefault - Whether this service should saved as the default service for {@link cleanupEphemeralService} to cleanup.\n * Defaults to true.\n * @remarks\n * The returned service owns an in-memory server and holds the documents created through clients connected to it.\n * {@link cleanupEphemeralService} can be used to ensure the service is properly cleaned up (a no-op if stopped/closed already).\n *\n * As a service, it may start timers which may require an explicit `close` to fully free.\n * @alpha\n */\nexport function startEphemeralService(isDefault = true): EphemeralService {\n\tif (isDefault && defaultEphemeralService) {\n\t\tthrow new UsageError(\"A default EphemeralService is already running\");\n\t}\n\n\tconst service = new EphemeralServiceImplementation();\n\tif (isDefault) {\n\t\tdefaultEphemeralService = service;\n\t}\n\treturn service;\n}\n\n/**\n * Cleans up the service passed in {@link startEphemeralService}, or the {@link getDefaultEphemeralService|default} if none is passed.\n * @remarks\n * This closes the service, and all its containers.\n * This is a good way to ensure the service and its containers leave no lingering timers\n * which could leak memory, trigger asynchronous work or prevent a clean process exit.\n * @alpha\n */\nexport async function cleanupEphemeralService(service?: EphemeralService): Promise<void> {\n\tconst toCleanup = service ?? defaultEphemeralService;\n\tif (toCleanup) {\n\t\t// TODO: we may want to make closing of containers a separate operation which is done here.\n\t\tawait toCleanup.close();\n\t}\n\tif (toCleanup === defaultEphemeralService) {\n\t\tdefaultEphemeralService = undefined;\n\t}\n}\n\n/**\n * Get the default {@link EphemeralService} if one has been {@link startEphemeralService|started}.\n * @throws If no default service is running.\n * @alpha\n */\nexport function getDefaultEphemeralService(): EphemeralService {\n\tif (defaultEphemeralService) {\n\t\treturn defaultEphemeralService;\n\t}\n\tthrow new UsageError(\"No default EphemeralService is running\");\n}\n\n/**\n * Internal Options for creating an {@link EphemeralServiceClient}, extending {@link @fluidframework/driver-definitions#ServiceOptions}\n * with the {@link EphemeralService} the client should connect to.\n * @input\n * @internal\n */\nexport interface EphemeralServiceOptions extends ServiceOptions {\n\t/**\n\t * The service instance to connect to.\n\t */\n\treadonly service: EphemeralService;\n}\n\n/**\n * An in-memory Fluid service that can produce connected {@link EphemeralServiceClient}s.\n * @remarks\n * All documents created through clients connected to a given `EphemeralService` are held in-memory by that service.\n * Closing the service (via {@link EphemeralService.close} or {@link cleanupEphemeralService}) closes the connections\n * to any remaining open containers, and cleans up the service's timers.\n *\n * Create one with {@link startEphemeralService}.\n *\n * Most {@link @fluidframework/driver-definitions#ServiceClient} implementations would take in a URL and credentials to connect to a service,\n * but that is not needed for the ephemeral in-memory service.\n * Instead this object representing the actual service instance is provided.\n * @privateRemarks\n * This is separated out from the actual {@link @fluidframework/driver-definitions#ServiceClient} object so that it's possible to create multiple service clients\n * connected to the same service.\n * Doing so is rarely necessary, but would be needed to test multiple clients collaborating on the same\n * document with different minVersionForCollaboration values.\n * This also exposes a place to put APIs for preloading and exporting document contents in the future.\n *\n * This is an erased type: its only implementation is the module-private {@link EphemeralServiceImplementation}, which holds\n * the mutable server and container state so it does not appear on this public type.\n *\n * TODO: formalize this lifecycle with an interface which documents these stages.\n * Lifecycle:\n * The intended lifecycle of an {@link EphemeralService} follows roughly the same pattern as containers:\n *\n * 1. Open: accepts connections from {@link EphemeralServiceClient}s, which can create and load containers.\n * Might have timers and event registrations which can trigger asynchronous work, and retain the object in memory.\n *\n * 2. Closing: asynchronous transition from open to closed. New use should behave as it closed, but may be cleaning up or saving resources asynchronously.\n * Timers and event registrations may still be active, but should be cleaned up by the time the transition to closed completes.\n *\n * 3. Closed: no longer accepts connections from {@link EphemeralServiceClient}s, and all containers connected to it are closed.\n * Should have no subscriptions to events or timers which could retain it in memory or trigger asynchronous work.\n * The object can still be used in a limited capacity (typically just to inspect its status (e.g. `isClosed`), and to view (but not edit) the final state of any containers which were connected to it before it closed.)\n *\n * Events or errors can cause an open to closing transition. Any nonfunctional state, including error states, should be considered as closed (or closing which will transition to closed),\n * and meet the requirements of closed with regards to timers and events.\n *\n * @alpha @sealed\n */\nexport interface EphemeralService extends ErasedBaseType<readonly [\"EphemeralService\"]> {\n\t/**\n\t * Close this service, which closes all containers connected to it and releases its resources.\n\t * @remarks\n\t * All documents held by this service are discarded, and any timers it (or its containers) were keeping alive\n\t * are cleaned up.\n\t * The returned promise resolves once all asynchronous cleanup (including shutting down the in-memory server)\n\t * has completed.\n\t * Closing is idempotent: calling it again after the service is closed resolves without doing anything.\n\t */\n\tclose(): Promise<void>;\n\n\t/**\n\t * Drives all containers connected to this service toward convergence, processing pending operations and\n\t * waiting for all dirty containers to save.\n\t *\n\t * @param timeoutMilliseconds - The maximum time to wait for containers to quiesce, in milliseconds. Defaults to 30_000.\n\t *\n\t * @privateRemarks\n\t * This is a best-effort implementation simplified from `LoaderContainerTracker.ensureSynchronized`.\n\t * Currently it does not perform receiver-side sequence-number quiescence or wait for join/leave (audience) ops.\n\t * See `LoaderContainerTracker.ensureSynchronized` for the fuller version this is based on.\n\t * For the currently exposed API surface, this should be sufficient,\n\t * but users down casting to internal types might run into some limitations.\n\t */\n\tsynchronize(timeoutMilliseconds?: number): Promise<void>;\n\n\t/**\n\t * Creates and returns a {@link EphemeralServiceClient} for an in-memory, ephemeral Fluid service.\n\t *\n\t * @param options - Options for the client. `minVersionForCollaboration` may be omitted (since all collaborators\n\t * are in the same process, it defaults to the current version). `service` may be omitted to allocate a new\n\t * {@link EphemeralService} dedicated to this client, or provided to connect the client to an existing service instance.\n\t *\n\t * @remarks\n\t * The service is ephemeral and in-memory: all documents are held by the {@link EphemeralService} the client is\n\t * connected to, and live for as long as that service is open — independent of whether any container for them is open.\n\t * A document created and attached (obtaining an `id`) can be loaded by `id` for as long as its service remains open,\n\t * even after every container for it has been closed.\n\t * Closing the service (via {@link EphemeralService.close} or {@link cleanupEphemeralService}) discards all of its\n\t * documents and releases its resources; afterwards those `id`s can no longer be loaded.\n\t *\n\t * When no `service` is provided, a new one is allocated for this client (accessible via {@link EphemeralServiceClient.service}).\n\t * Provide the same {@link EphemeralService} to multiple clients (via `options.service`) to have them collaborate on the\n\t * same documents, and control that service's lifetime explicitly.\n\t *\n\t * Since a service holds timers while open, tests should close the services they use (e.g. via\n\t * {@link cleanupEphemeralService} in an `afterEach`) to avoid lingering timers that can hang test runners.\n\t *\n\t * @privateRemarks\n\t * TODO: We should provide a way to extract (for potential serialization as test data) and load documents into a service.\n\t * This is needed to use this API surface for testing reference documents.\n\t * Ideally we would provide a service agnostic way to do the export, but likely only support loading them into the local service.\n\t * This can be done via an API on FluidContainer (or a free function taking one) to do the export, then adding a\n\t * service specific API (on {@link EphemeralService}) to load from the export format and return the ID of the loaded document.\n\t */\n\tnewClient(options: ServiceOptions): EphemeralServiceClient;\n\n\t/**\n\t * A client connected to this service using the default options.\n\t */\n\treadonly defaultClient: EphemeralServiceClient;\n}\n\n/**\n * The {@link defaultEphemeralService} if one has been {@link startEphemeralService|started}.\n */\nlet defaultEphemeralService: EphemeralServiceImplementation | undefined;\n\n/**\n * The concrete implementation of {@link EphemeralService}.\n * @remarks\n * Kept module-private so its mutable state and internal helpers are not part of the public API.\n * Narrow an {@link EphemeralService} to it with `EphemeralServiceImplementation.narrow`.\n */\nclass EphemeralServiceImplementation\n\textends ErasedTypeImplementation<EphemeralService>\n\timplements EphemeralService\n{\n\t// A single server is shared by all containers connected to this service so they can communicate with each other.\n\tprivate readonly server: ILocalDeltaConnectionServer =\n\t\tLocalDeltaConnectionServer.create(\n\t\t\t// new LocalSessionStorageDbFactory(),\n\t\t);\n\tprivate readonly documentServiceFactory = new LocalDocumentServiceFactory(this.server);\n\tprivate readonly containers = new Set<EphemeralServiceContainer<unknown>>();\n\tprivate closed = false;\n\n\tpublic constructor() {\n\t\tsuper();\n\t\tthis.defaultClient = this.newClient();\n\t}\n\tpublic newClient(options?: Partial<ServiceOptions>): EphemeralServiceClient {\n\t\tconst finalOptions: EphemeralServiceOptions = {\n\t\t\tminVersionForCollaboration:\n\t\t\t\toptions?.minVersionForCollaboration ?? featureVersion(pkgVersion),\n\t\t\tservice: this,\n\t\t};\n\t\treturn new EphemeralServiceClientImplementation(finalOptions);\n\t}\n\tpublic readonly defaultClient: EphemeralServiceClient;\n\n\tpublic async close(): Promise<void> {\n\t\tif (this.closed) {\n\t\t\treturn;\n\t\t}\n\t\tthis.closed = true;\n\n\t\t// Close every open container via the same public close() path a user would use.\n\t\t// We might want to remove this.\n\t\tconst toClose = [...this.containers];\n\t\tthis.containers.clear();\n\t\tfor (const c of toClose) {\n\t\t\tc.close();\n\t\t}\n\n\t\t// Shut down the in-memory server. Its timers (e.g. the Deli read-client idle `setInterval`) belong to the\n\t\t// server rather than any container, so closing containers alone would leave them running.\n\t\tawait this.server.close();\n\t}\n\n\tpublic async synchronize(timeoutMilliseconds = 30_000): Promise<void> {\n\t\t// Timeout to allow for better errors in the case of hangs.\n\t\tlet timedOut = false;\n\t\tlet deadlineTimer: ReturnType<typeof setTimeout> | undefined;\n\t\tconst deadline = new Promise<true>((resolve) => {\n\t\t\tdeadlineTimer = setTimeout(() => {\n\t\t\t\ttimedOut = true;\n\t\t\t\tresolve(true);\n\t\t\t}, timeoutMilliseconds);\n\t\t});\n\n\t\ttry {\n\t\t\t// Require two consecutive quiescent passes (no dirty containers and no pending server work),\n\t\t\t// each separated by a macrotask turn, to give late side effects a chance to surface.\n\t\t\tlet clean = 0;\n\t\t\twhile (clean < 2) {\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`EphemeralService.synchronize timed out after ${timeoutMilliseconds}ms waiting for local containers to quiesce.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Yield a macrotask turn *first*, so the local server's scheduled broadcast send and each\n\t\t\t\t// container's inbound op processing can run before we sample their state below. Sampling\n\t\t\t\t// hasPendingWork() in a tight `while (await ...)` loop instead would starve that scheduled\n\t\t\t\t// send (it is a macrotask, while the await resolves on the microtask queue) and could hang.\n\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\tsetTimeout(resolve, 0);\n\t\t\t\t});\n\n\t\t\t\t// Prune any containers that have closed since the last pass.\n\t\t\t\tfor (const container of [...this.containers]) {\n\t\t\t\t\tif (container.container.closed) {\n\t\t\t\t\t\tthis.containers.delete(container);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst containersToApply = [...this.containers].map((container) => container.container);\n\n\t\t\t\t// Ignore readonly/disconnected dirty containers: they can't send ops, so nothing can be done about them being dirty here.\n\t\t\t\t// Neither state is reachable through the ephemeral service API today, but the checks are cheap and keep this robust to future changes.\n\t\t\t\tconst dirtyContainers = containersToApply.filter((c) => {\n\t\t\t\t\tconst { deltaManager, isDirty, connectionState } = c;\n\t\t\t\t\treturn (\n\t\t\t\t\t\tconnectionState !== ConnectionState.Disconnected &&\n\t\t\t\t\t\tdeltaManager.readOnlyInfo.readonly !== true &&\n\t\t\t\t\t\tisDirty\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tif (dirtyContainers.length > 0) {\n\t\t\t\t\t// Bound this wait by the shared deadline: a container that never saves (and never\n\t\t\t\t\t// closes) must not block past the overall timeout, since the top-of-loop check can't\n\t\t\t\t\t// run while we are awaiting here.\n\t\t\t\t\tawait Promise.race([\n\t\t\t\t\t\tPromise.all(\n\t\t\t\t\t\t\tdirtyContainers.map(async (c) =>\n\t\t\t\t\t\t\t\tPromise.race([\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => c.once(\"saved\", resolve)),\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => c.once(\"closed\", resolve)),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdeadline,\n\t\t\t\t\t]);\n\n\t\t\t\t\tclean = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Sample pending server work once per pass (the macrotask yield above gave the broadcaster's\n\t\t\t\t// scheduled send a chance to run first).\n\t\t\t\tif (await Promise.race([this.server.hasPendingWork(), deadline])) {\n\t\t\t\t\tclean = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tclean++;\n\t\t\t}\n\t\t} finally {\n\t\t\tclearTimeout(deadlineTimer);\n\t\t}\n\t}\n\n\t/**\n\t * The document service factory for this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic getDocumentServiceFactory(): LocalDocumentServiceFactory {\n\t\tassert(\n\t\t\t!this.closed,\n\t\t\t0xd11 /* Cannot create or load containers on a closed EphemeralService */,\n\t\t);\n\t\treturn this.documentServiceFactory;\n\t}\n\n\t/**\n\t * Registers a newly created container as connected to this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic addContainer(container: EphemeralServiceContainer<unknown>): void {\n\t\tthis.containers.add(container);\n\t}\n\n\t/**\n\t * Removes a now-closed container from this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic removeContainer(container: EphemeralServiceContainer<unknown>): void {\n\t\tthis.containers.delete(container);\n\t}\n}\n\n/**\n * A {@link @fluidframework/driver-definitions#ServiceClient} connected to a specific {@link EphemeralService}.\n * @alpha @sealed\n */\nexport interface EphemeralServiceClient extends ServiceClient {\n\t/**\n\t * The service instance this client is connected to.\n\t */\n\treadonly service: EphemeralService;\n}\n\nclass EphemeralServiceClientImplementation\n\textends ServiceClientImplementation<EphemeralServiceOptions>\n\timplements EphemeralServiceClient\n{\n\tpublic readonly service: EphemeralService;\n\n\tpublic constructor(options: EphemeralServiceOptions) {\n\t\tsuper(options, EphemeralServiceContainer);\n\t\tthis.service = options.service;\n\t}\n}\n\nconst containerRuntimeLoader: ContainerRuntimeLoader = async (\n\tparameters: ContainerRuntimeLoaderParams,\n) => {\n\tconst { runtime } = await ContainerRuntime.loadRuntime2({\n\t\tcontext: parameters.context,\n\t\tregistry: parameters.registry,\n\t\tprovideEntryPoint: parameters.provideEntryPoint,\n\t\texisting: parameters.existing,\n\t\tminVersionForCollab: parameters.minVersionForCollab,\n\t\truntimeOptions: { enableRuntimeIdCompressor: \"on\" },\n\t});\n\tif (!parameters.existing) {\n\t\tassert(\n\t\t\tparameters.newContainerRootType !== undefined,\n\t\t\t0xd12 /* Root data store kind must be provided for new containers */,\n\t\t);\n\t\tconst dataStore = await runtime.createDataStore(parameters.newContainerRootType);\n\t\tconst aliasResult = await dataStore.trySetAlias(rootDataStoreId);\n\t\tassert(\n\t\t\taliasResult === \"Success\",\n\t\t\t0xd13 /* Should be able to set alias on new data store */,\n\t\t);\n\t}\n\treturn runtime;\n};\n\nconst urlResolver = new LocalResolver();\n/**\n * Create a request to open an existing document.\n *\n * @param documentId - the existing document to open.\n * @privateRemarks\n * Like createLocalResolverCreateNewRequest, but without the option to create a new document.\n * TODO: At some point we should avoid specifying the URL in so many places, but the current APIs don't accommodate it yet.\n */\nconst createLoadExistingRequest = (documentId: string): IRequest => {\n\treturn { url: `http://localhost:3000/${documentId}` };\n};\n\nlet documentIdCounter = 0;\n\n/**\n * A Fluid container backed by an ephemeral (in-memory) local service, implementing\n * {@link @fluidframework/driver-definitions#FluidContainerWithService}.\n *\n * @remarks\n * Data is stored in-memory by the {@link EphemeralService} the container's client is connected to (see\n * {@link EphemeralServiceContainer.service}), enabling side-by-side collaboration testing without a real server.\n *\n * @internal\n */\nexport class EphemeralServiceContainer<TData>\n\textends ServiceContainerBase<TData, EphemeralServiceOptions>\n\timplements FluidContainerWithService<TData>\n{\n\tpublic readonly service: EphemeralService;\n\n\tpublic static async createDetached<T>(\n\t\tregistry: DataStoreRegistry<T>,\n\t\toptions: EphemeralServiceOptions,\n\t\troot: DataStoreKind<T>,\n\t): Promise<EphemeralServiceContainer<T>> {\n\t\tEphemeralServiceImplementation.narrow(options.service);\n\t\tconst container: IContainer = await createDetachedContainer({\n\t\t\tcodeDetails: { package: \"1.0\" },\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory: options.service.getDocumentServiceFactory(),\n\t\t\tcodeLoader: makeCodeLoader(\n\t\t\t\tregistry,\n\t\t\t\toptions.minVersionForCollaboration,\n\t\t\t\tcontainerRuntimeLoader,\n\t\t\t\troot,\n\t\t\t),\n\t\t});\n\n\t\treturn new EphemeralServiceContainer<T>(\n\t\t\tregistry,\n\t\t\toptions,\n\t\t\tcontainer,\n\t\t\t(await container.getEntryPoint()) as T,\n\t\t\tundefined,\n\t\t);\n\t}\n\n\tpublic static async load<T>(\n\t\tregistry: DataStoreRegistry<T>,\n\t\toptions: EphemeralServiceOptions,\n\t\tid: string,\n\t): Promise<EphemeralServiceContainer<T> & FluidContainerAttached<T>> {\n\t\tEphemeralServiceImplementation.narrow(options.service);\n\t\tconst containerInner = await loadExistingContainer({\n\t\t\trequest: createLoadExistingRequest(id),\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory: options.service.getDocumentServiceFactory(),\n\t\t\tcodeLoader: makeCodeLoader(\n\t\t\t\tregistry,\n\t\t\t\toptions.minVersionForCollaboration,\n\t\t\t\tcontainerRuntimeLoader,\n\t\t\t),\n\t\t});\n\n\t\tconst container = new EphemeralServiceContainer<T>(\n\t\t\tregistry,\n\t\t\toptions,\n\t\t\tcontainerInner,\n\t\t\t(await containerInner.getEntryPoint()) as T,\n\t\t\tid,\n\t\t);\n\t\tassert(\n\t\t\tcontainer.id !== undefined,\n\t\t\t0xd14 /* id should be defined when loading a container */,\n\t\t);\n\t\treturn container as typeof container & { id: string };\n\t}\n\n\tprivate constructor(\n\t\tregistry: Registry<Promise<DataStoreKind<TData>>>,\n\t\toptions: EphemeralServiceOptions,\n\t\tcontainer: IContainer,\n\t\tdata: TData,\n\t\tid: string | undefined,\n\t) {\n\t\tsuper(registry, options, container, data, id);\n\t\tthis.service = options.service;\n\t\tEphemeralServiceImplementation.narrow(this.service);\n\t\tthis.service.addContainer(this);\n\t}\n\n\tpublic override close(): void {\n\t\tsuper.close();\n\t\t// Remove this now-closed container from its service's set of open containers.\n\t\tEphemeralServiceImplementation.narrow(this.service);\n\t\tthis.service.removeContainer(this);\n\t}\n\n\tprotected createAttachRequest(): IRequest {\n\t\tconst documentId = (documentIdCounter++).toString();\n\t\treturn createLocalResolverCreateNewRequest(documentId);\n\t}\n}\n"]}
1
+ {"version":3,"file":"ephemeralService.js","sourceRoot":"","sources":["../src/ephemeralService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,eAAe,GAEf,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACN,uBAAuB,EACvB,qBAAqB,GACrB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,OAAO,EACN,wBAAwB,GAExB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EACN,cAAc,GASd,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAGN,cAAc,EACd,eAAe,EACf,2BAA2B,EAC3B,oBAAoB,GACpB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACN,0BAA0B,GAE1B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC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QACF,OAAO,SAA8C,CAAC;IACvD,CAAC;IAED,YACC,QAAiD,EACjD,OAAgC,EAChC,SAAqB,EACrB,IAAW,EACX,EAAsB;QAEtB,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,8BAA8B,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAEe,KAAK;QACpB,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,8EAA8E;QAC9E,8BAA8B,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAES,mBAAmB;QAC5B,MAAM,UAAU,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QACpD,OAAO,mCAAmC,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tConnectionState,\n\ttype IContainer,\n} from \"@fluidframework/container-definitions/internal\";\nimport {\n\tcreateDetachedContainer,\n\tloadExistingContainer,\n} from \"@fluidframework/container-loader/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tErasedTypeImplementation,\n\ttype ErasedBaseType,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tfeatureVersion,\n\ttype DataStoreKind,\n\ttype DataStoreRegistry,\n\ttype FluidContainerAttached,\n\ttype FluidContainerWithService,\n\ttype OldestSupportedServiceClientVersion,\n\ttype Registry,\n\ttype ServiceClient,\n\ttype ServiceOptions,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype ContainerRuntimeLoader,\n\ttype ContainerRuntimeLoaderParams,\n\tmakeCodeLoader,\n\trootDataStoreId,\n\tServiceClientImplementation,\n\tServiceContainerBase,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tLocalDeltaConnectionServer,\n\ttype ILocalDeltaConnectionServer,\n} from \"@fluidframework/server-local-server\";\nimport { UsageError } from \"@fluidframework/driver-utils/internal\";\n\nimport { LocalDocumentServiceFactory } from \"./localDocumentServiceFactory.js\";\nimport { createLocalResolverCreateNewRequest, LocalResolver } from \"./localResolver.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * Starts and returns a new {@link EphemeralService}.\n * @param isDefault - Whether this service should saved as the default service for {@link cleanupEphemeralService} to cleanup.\n * Defaults to true.\n * @remarks\n * The returned service owns an in-memory server and holds the documents created through clients connected to it.\n * {@link cleanupEphemeralService} can be used to ensure the service is properly cleaned up (a no-op if stopped/closed already).\n *\n * As a service, it may start timers which may require an explicit `close` to fully free.\n * @alpha\n */\nexport function startEphemeralService(isDefault = true): EphemeralService {\n\tif (isDefault && defaultEphemeralService) {\n\t\tthrow new UsageError(\"A default EphemeralService is already running\");\n\t}\n\n\tconst service = new EphemeralServiceImplementation();\n\tif (isDefault) {\n\t\tdefaultEphemeralService = service;\n\t}\n\treturn service;\n}\n\n/**\n * Cleans up the service passed in {@link startEphemeralService}, or the {@link getDefaultEphemeralService|default} if none is passed.\n * @remarks\n * This closes the service, and all its containers.\n * This is a good way to ensure the service and its containers leave no lingering timers\n * which could leak memory, trigger asynchronous work or prevent a clean process exit.\n * @alpha\n */\nexport async function cleanupEphemeralService(service?: EphemeralService): Promise<void> {\n\tconst toCleanup = service ?? defaultEphemeralService;\n\tif (toCleanup) {\n\t\t// TODO: we may want to make closing of containers a separate operation which is done here.\n\t\tawait toCleanup.close();\n\t}\n\tif (toCleanup === defaultEphemeralService) {\n\t\tdefaultEphemeralService = undefined;\n\t}\n}\n\n/**\n * Get the default {@link EphemeralService} if one has been {@link startEphemeralService|started}.\n * @throws If no default service is running.\n * @alpha\n */\nexport function getDefaultEphemeralService(): EphemeralService {\n\tif (defaultEphemeralService) {\n\t\treturn defaultEphemeralService;\n\t}\n\tthrow new UsageError(\"No default EphemeralService is running\");\n}\n\n/**\n * Internal Options for creating an {@link EphemeralServiceClient}, extending {@link @fluidframework/driver-definitions#ServiceOptions}\n * with the {@link EphemeralService} the client should connect to.\n * @input\n * @internal\n */\nexport interface EphemeralServiceOptions extends ServiceOptions {\n\t/**\n\t * {@inheritdoc @fluidframework/driver-definitions#ServiceOptions.oldestSupportedClient}\n\t */\n\treadonly oldestSupportedClient: OldestSupportedServiceClientVersion;\n\t/**\n\t * The service instance to connect to.\n\t */\n\treadonly service: EphemeralService;\n}\n\n/**\n * An in-memory Fluid service that can produce connected {@link EphemeralServiceClient}s.\n * @remarks\n * All documents created through clients connected to a given `EphemeralService` are held in-memory by that service.\n * Closing the service (via {@link EphemeralService.close} or {@link cleanupEphemeralService}) closes the connections\n * to any remaining open containers, and cleans up the service's timers.\n *\n * Create one with {@link startEphemeralService}.\n *\n * Most {@link @fluidframework/driver-definitions#ServiceClient} implementations would take in a URL and credentials to connect to a service,\n * but that is not needed for the ephemeral in-memory service.\n * Instead this object representing the actual service instance is provided.\n * @privateRemarks\n * This is separated out from the actual {@link @fluidframework/driver-definitions#ServiceClient} object so that it's possible to create multiple service clients\n * connected to the same service.\n * Doing so is rarely necessary, but would be needed to test multiple clients collaborating on the same\n * document with different `oldestSupportedClient` values.\n * This also exposes a place to put APIs for preloading and exporting document contents in the future.\n *\n * This is an erased type: its only implementation is the module-private {@link EphemeralServiceImplementation}, which holds\n * the mutable server and container state so it does not appear on this public type.\n *\n * TODO: formalize this lifecycle with an interface which documents these stages.\n * Lifecycle:\n * The intended lifecycle of an {@link EphemeralService} follows roughly the same pattern as containers:\n *\n * 1. Open: accepts connections from {@link EphemeralServiceClient}s, which can create and load containers.\n * Might have timers and event registrations which can trigger asynchronous work, and retain the object in memory.\n *\n * 2. Closing: asynchronous transition from open to closed. New use should behave as it closed, but may be cleaning up or saving resources asynchronously.\n * Timers and event registrations may still be active, but should be cleaned up by the time the transition to closed completes.\n *\n * 3. Closed: no longer accepts connections from {@link EphemeralServiceClient}s, and all containers connected to it are closed.\n * Should have no subscriptions to events or timers which could retain it in memory or trigger asynchronous work.\n * The object can still be used in a limited capacity (typically just to inspect its status (e.g. `isClosed`), and to view (but not edit) the final state of any containers which were connected to it before it closed.)\n *\n * Events or errors can cause an open to closing transition. Any nonfunctional state, including error states, should be considered as closed (or closing which will transition to closed),\n * and meet the requirements of closed with regards to timers and events.\n *\n * @alpha @sealed\n */\nexport interface EphemeralService extends ErasedBaseType<readonly [\"EphemeralService\"]> {\n\t/**\n\t * Close this service, which closes all containers connected to it and releases its resources.\n\t * @remarks\n\t * All documents held by this service are discarded, and any timers it (or its containers) were keeping alive\n\t * are cleaned up.\n\t * The returned promise resolves once all asynchronous cleanup (including shutting down the in-memory server)\n\t * has completed.\n\t * Closing is idempotent: calling it again after the service is closed resolves without doing anything.\n\t */\n\tclose(): Promise<void>;\n\n\t/**\n\t * Drives all containers connected to this service toward convergence, processing pending operations and\n\t * waiting for all dirty containers to save.\n\t *\n\t * @param timeoutMilliseconds - The maximum time to wait for containers to quiesce, in milliseconds. Defaults to 30_000.\n\t *\n\t * @privateRemarks\n\t * This is a best-effort implementation simplified from `LoaderContainerTracker.ensureSynchronized`.\n\t * Currently it does not perform receiver-side sequence-number quiescence or wait for join/leave (audience) ops.\n\t * See `LoaderContainerTracker.ensureSynchronized` for the fuller version this is based on.\n\t * For the currently exposed API surface, this should be sufficient,\n\t * but users down casting to internal types might run into some limitations.\n\t */\n\tsynchronize(timeoutMilliseconds?: number): Promise<void>;\n\n\t/**\n\t * Creates and returns a {@link EphemeralServiceClient} for an in-memory, ephemeral Fluid service.\n\t *\n\t * @param options - Options for the client. `oldestSupportedClient` may be omitted because all\n\t * clients are in the same process, so it defaults to the current version. `service` may be omitted to allocate a new\n\t * {@link EphemeralService} dedicated to this client, or provided to connect the client to an existing service instance.\n\t *\n\t * @remarks\n\t * The service is ephemeral and in-memory: all documents are held by the {@link EphemeralService} the client is\n\t * connected to, and live for as long as that service is open — independent of whether any container for them is open.\n\t * A document created and attached (obtaining an `id`) can be loaded by `id` for as long as its service remains open,\n\t * even after every container for it has been closed.\n\t * Closing the service (via {@link EphemeralService.close} or {@link cleanupEphemeralService}) discards all of its\n\t * documents and releases its resources; afterwards those `id`s can no longer be loaded.\n\t *\n\t * When no `service` is provided, a new one is allocated for this client (accessible via {@link EphemeralServiceClient.service}).\n\t * Provide the same {@link EphemeralService} to multiple clients (via `options.service`) to have them collaborate on the\n\t * same documents, and control that service's lifetime explicitly.\n\t *\n\t * Since a service holds timers while open, tests should close the services they use (e.g. via\n\t * {@link cleanupEphemeralService} in an `afterEach`) to avoid lingering timers that can hang test runners.\n\t *\n\t * @privateRemarks\n\t * TODO: We should provide a way to extract (for potential serialization as test data) and load documents into a service.\n\t * This is needed to use this API surface for testing reference documents.\n\t * Ideally we would provide a service agnostic way to do the export, but likely only support loading them into the local service.\n\t * This can be done via an API on FluidContainer (or a free function taking one) to do the export, then adding a\n\t * service specific API (on {@link EphemeralService}) to load from the export format and return the ID of the loaded document.\n\t */\n\tnewClient(options: ServiceOptions): EphemeralServiceClient;\n\n\t/**\n\t * A client connected to this service using the default options.\n\t */\n\treadonly defaultClient: EphemeralServiceClient;\n}\n\n/**\n * The {@link defaultEphemeralService} if one has been {@link startEphemeralService|started}.\n */\nlet defaultEphemeralService: EphemeralServiceImplementation | undefined;\n\n/**\n * The concrete implementation of {@link EphemeralService}.\n * @remarks\n * Kept module-private so its mutable state and internal helpers are not part of the public API.\n * Narrow an {@link EphemeralService} to it with `EphemeralServiceImplementation.narrow`.\n */\nclass EphemeralServiceImplementation\n\textends ErasedTypeImplementation<EphemeralService>\n\timplements EphemeralService\n{\n\t// A single server is shared by all containers connected to this service so they can communicate with each other.\n\tprivate readonly server: ILocalDeltaConnectionServer =\n\t\tLocalDeltaConnectionServer.create(\n\t\t\t// new LocalSessionStorageDbFactory(),\n\t\t);\n\tprivate readonly documentServiceFactory = new LocalDocumentServiceFactory(this.server);\n\tprivate readonly containers = new Set<EphemeralServiceContainer<unknown>>();\n\tprivate closed = false;\n\n\tpublic constructor() {\n\t\tsuper();\n\t\tthis.defaultClient = this.newClient();\n\t}\n\tpublic newClient(options?: Partial<ServiceOptions>): EphemeralServiceClient {\n\t\tconst finalOptions: EphemeralServiceOptions = {\n\t\t\toldestSupportedClient: options?.oldestSupportedClient ?? featureVersion(pkgVersion),\n\t\t\tservice: this,\n\t\t};\n\t\treturn new EphemeralServiceClientImplementation(finalOptions);\n\t}\n\tpublic readonly defaultClient: EphemeralServiceClient;\n\n\tpublic async close(): Promise<void> {\n\t\tif (this.closed) {\n\t\t\treturn;\n\t\t}\n\t\tthis.closed = true;\n\n\t\t// Close every open container via the same public close() path a user would use.\n\t\t// We might want to remove this.\n\t\tconst toClose = [...this.containers];\n\t\tthis.containers.clear();\n\t\tfor (const c of toClose) {\n\t\t\tc.close();\n\t\t}\n\n\t\t// Shut down the in-memory server. Its timers (e.g. the Deli read-client idle `setInterval`) belong to the\n\t\t// server rather than any container, so closing containers alone would leave them running.\n\t\tawait this.server.close();\n\t}\n\n\tpublic async synchronize(timeoutMilliseconds = 30_000): Promise<void> {\n\t\t// Timeout to allow for better errors in the case of hangs.\n\t\tlet timedOut = false;\n\t\tlet deadlineTimer: ReturnType<typeof setTimeout> | undefined;\n\t\tconst deadline = new Promise<true>((resolve) => {\n\t\t\tdeadlineTimer = setTimeout(() => {\n\t\t\t\ttimedOut = true;\n\t\t\t\tresolve(true);\n\t\t\t}, timeoutMilliseconds);\n\t\t});\n\n\t\ttry {\n\t\t\t// Require two consecutive quiescent passes (no dirty containers and no pending server work),\n\t\t\t// each separated by a macrotask turn, to give late side effects a chance to surface.\n\t\t\tlet clean = 0;\n\t\t\twhile (clean < 2) {\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`EphemeralService.synchronize timed out after ${timeoutMilliseconds}ms waiting for local containers to quiesce.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Yield a macrotask turn *first*, so the local server's scheduled broadcast send and each\n\t\t\t\t// container's inbound op processing can run before we sample their state below. Sampling\n\t\t\t\t// hasPendingWork() in a tight `while (await ...)` loop instead would starve that scheduled\n\t\t\t\t// send (it is a macrotask, while the await resolves on the microtask queue) and could hang.\n\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\tsetTimeout(resolve, 0);\n\t\t\t\t});\n\n\t\t\t\t// Prune any containers that have closed since the last pass.\n\t\t\t\tfor (const container of [...this.containers]) {\n\t\t\t\t\tif (container.container.closed) {\n\t\t\t\t\t\tthis.containers.delete(container);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst containersToApply = [...this.containers].map((container) => container.container);\n\n\t\t\t\t// Ignore readonly/disconnected dirty containers: they can't send ops, so nothing can be done about them being dirty here.\n\t\t\t\t// Neither state is reachable through the ephemeral service API today, but the checks are cheap and keep this robust to future changes.\n\t\t\t\tconst dirtyContainers = containersToApply.filter((c) => {\n\t\t\t\t\tconst { deltaManager, isDirty, connectionState } = c;\n\t\t\t\t\treturn (\n\t\t\t\t\t\tconnectionState !== ConnectionState.Disconnected &&\n\t\t\t\t\t\tdeltaManager.readOnlyInfo.readonly !== true &&\n\t\t\t\t\t\tisDirty\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tif (dirtyContainers.length > 0) {\n\t\t\t\t\t// Bound this wait by the shared deadline: a container that never saves (and never\n\t\t\t\t\t// closes) must not block past the overall timeout, since the top-of-loop check can't\n\t\t\t\t\t// run while we are awaiting here.\n\t\t\t\t\tawait Promise.race([\n\t\t\t\t\t\tPromise.all(\n\t\t\t\t\t\t\tdirtyContainers.map(async (c) =>\n\t\t\t\t\t\t\t\tPromise.race([\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => c.once(\"saved\", resolve)),\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => c.once(\"closed\", resolve)),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdeadline,\n\t\t\t\t\t]);\n\n\t\t\t\t\tclean = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Sample pending server work once per pass (the macrotask yield above gave the broadcaster's\n\t\t\t\t// scheduled send a chance to run first).\n\t\t\t\tif (await Promise.race([this.server.hasPendingWork(), deadline])) {\n\t\t\t\t\tclean = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tclean++;\n\t\t\t}\n\t\t} finally {\n\t\t\tclearTimeout(deadlineTimer);\n\t\t}\n\t}\n\n\t/**\n\t * The document service factory for this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic getDocumentServiceFactory(): LocalDocumentServiceFactory {\n\t\tassert(\n\t\t\t!this.closed,\n\t\t\t0xd11 /* Cannot create or load containers on a closed EphemeralService */,\n\t\t);\n\t\treturn this.documentServiceFactory;\n\t}\n\n\t/**\n\t * Registers a newly created container as connected to this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic addContainer(container: EphemeralServiceContainer<unknown>): void {\n\t\tthis.containers.add(container);\n\t}\n\n\t/**\n\t * Removes a now-closed container from this service.\n\t * @remarks Internal helper for {@link EphemeralServiceContainer}; not part of the public {@link EphemeralService} API.\n\t */\n\tpublic removeContainer(container: EphemeralServiceContainer<unknown>): void {\n\t\tthis.containers.delete(container);\n\t}\n}\n\n/**\n * A {@link @fluidframework/driver-definitions#ServiceClient} connected to a specific {@link EphemeralService}.\n * @alpha @sealed\n */\nexport interface EphemeralServiceClient extends ServiceClient {\n\t/**\n\t * The service instance this client is connected to.\n\t */\n\treadonly service: EphemeralService;\n}\n\nclass EphemeralServiceClientImplementation\n\textends ServiceClientImplementation<EphemeralServiceOptions>\n\timplements EphemeralServiceClient\n{\n\tpublic readonly service: EphemeralService;\n\n\tpublic constructor(options: EphemeralServiceOptions) {\n\t\tsuper(options, EphemeralServiceContainer);\n\t\tthis.service = options.service;\n\t}\n}\n\nconst containerRuntimeLoader: ContainerRuntimeLoader = async (\n\tparameters: ContainerRuntimeLoaderParams,\n) => {\n\tconst { runtime } = await ContainerRuntime.loadRuntime2({\n\t\tcontext: parameters.context,\n\t\tregistry: parameters.registry,\n\t\tprovideEntryPoint: parameters.provideEntryPoint,\n\t\texisting: parameters.existing,\n\t\tminVersionForCollab: parameters.minVersionForCollab,\n\t\truntimeOptions: { enableRuntimeIdCompressor: \"on\" },\n\t});\n\tif (!parameters.existing) {\n\t\tassert(\n\t\t\tparameters.newContainerRootType !== undefined,\n\t\t\t0xd12 /* Root data store kind must be provided for new containers */,\n\t\t);\n\t\tconst dataStore = await runtime.createDataStore(parameters.newContainerRootType);\n\t\tconst aliasResult = await dataStore.trySetAlias(rootDataStoreId);\n\t\tassert(\n\t\t\taliasResult === \"Success\",\n\t\t\t0xd13 /* Should be able to set alias on new data store */,\n\t\t);\n\t}\n\treturn runtime;\n};\n\nconst urlResolver = new LocalResolver();\n/**\n * Create a request to open an existing document.\n *\n * @param documentId - the existing document to open.\n * @privateRemarks\n * Like createLocalResolverCreateNewRequest, but without the option to create a new document.\n * TODO: At some point we should avoid specifying the URL in so many places, but the current APIs don't accommodate it yet.\n */\nconst createLoadExistingRequest = (documentId: string): IRequest => {\n\treturn { url: `http://localhost:3000/${documentId}` };\n};\n\nlet documentIdCounter = 0;\n\n/**\n * A Fluid container backed by an ephemeral (in-memory) local service, implementing\n * {@link @fluidframework/driver-definitions#FluidContainerWithService}.\n *\n * @remarks\n * Data is stored in-memory by the {@link EphemeralService} the container's client is connected to (see\n * {@link EphemeralServiceContainer.service}), enabling side-by-side collaboration testing without a real server.\n *\n * @internal\n */\nexport class EphemeralServiceContainer<TData>\n\textends ServiceContainerBase<TData, EphemeralServiceOptions>\n\timplements FluidContainerWithService<TData>\n{\n\tpublic readonly service: EphemeralService;\n\n\tpublic static async createDetached<T>(\n\t\tregistry: DataStoreRegistry<T>,\n\t\toptions: EphemeralServiceOptions,\n\t\troot: DataStoreKind<T>,\n\t): Promise<EphemeralServiceContainer<T>> {\n\t\tEphemeralServiceImplementation.narrow(options.service);\n\t\tconst container: IContainer = await createDetachedContainer({\n\t\t\tcodeDetails: { package: \"1.0\" },\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory: options.service.getDocumentServiceFactory(),\n\t\t\tcodeLoader: makeCodeLoader(\n\t\t\t\tregistry,\n\t\t\t\toptions.oldestSupportedClient,\n\t\t\t\tcontainerRuntimeLoader,\n\t\t\t\troot,\n\t\t\t),\n\t\t});\n\n\t\treturn new EphemeralServiceContainer<T>(\n\t\t\tregistry,\n\t\t\toptions,\n\t\t\tcontainer,\n\t\t\t(await container.getEntryPoint()) as T,\n\t\t\tundefined,\n\t\t);\n\t}\n\n\tpublic static async load<T>(\n\t\tregistry: DataStoreRegistry<T>,\n\t\toptions: EphemeralServiceOptions,\n\t\tid: string,\n\t): Promise<EphemeralServiceContainer<T> & FluidContainerAttached<T>> {\n\t\tEphemeralServiceImplementation.narrow(options.service);\n\t\tconst containerInner = await loadExistingContainer({\n\t\t\trequest: createLoadExistingRequest(id),\n\t\t\turlResolver,\n\t\t\tdocumentServiceFactory: options.service.getDocumentServiceFactory(),\n\t\t\tcodeLoader: makeCodeLoader(\n\t\t\t\tregistry,\n\t\t\t\toptions.oldestSupportedClient,\n\t\t\t\tcontainerRuntimeLoader,\n\t\t\t),\n\t\t});\n\n\t\tconst container = new EphemeralServiceContainer<T>(\n\t\t\tregistry,\n\t\t\toptions,\n\t\t\tcontainerInner,\n\t\t\t(await containerInner.getEntryPoint()) as T,\n\t\t\tid,\n\t\t);\n\t\tassert(\n\t\t\tcontainer.id !== undefined,\n\t\t\t0xd14 /* id should be defined when loading a container */,\n\t\t);\n\t\treturn container as typeof container & { id: string };\n\t}\n\n\tprivate constructor(\n\t\tregistry: Registry<Promise<DataStoreKind<TData>>>,\n\t\toptions: EphemeralServiceOptions,\n\t\tcontainer: IContainer,\n\t\tdata: TData,\n\t\tid: string | undefined,\n\t) {\n\t\tsuper(registry, options, container, data, id);\n\t\tthis.service = options.service;\n\t\tEphemeralServiceImplementation.narrow(this.service);\n\t\tthis.service.addContainer(this);\n\t}\n\n\tpublic override close(): void {\n\t\tsuper.close();\n\t\t// Remove this now-closed container from its service's set of open containers.\n\t\tEphemeralServiceImplementation.narrow(this.service);\n\t\tthis.service.removeContainer(this);\n\t}\n\n\tprotected createAttachRequest(): IRequest {\n\t\tconst documentId = (documentIdCounter++).toString();\n\t\treturn createLocalResolverCreateNewRequest(documentId);\n\t}\n}\n"]}
@@ -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/local-driver";
8
- export declare const pkgVersion = "2.115.0";
8
+ export declare const pkgVersion = "2.116.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/local-driver";
8
- export const pkgVersion = "2.115.0";
8
+ export const pkgVersion = "2.116.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,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/local-driver\";\nexport const pkgVersion = \"2.115.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,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/local-driver\";\nexport const pkgVersion = \"2.116.0\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/local-driver",
3
- "version": "2.115.0",
3
+ "version": "2.116.0",
4
4
  "description": "Fluid local driver",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -78,37 +78,37 @@
78
78
  "temp-directory": "nyc/.nyc_output"
79
79
  },
80
80
  "dependencies": {
81
- "@fluid-internal/client-utils": "~2.115.0",
82
- "@fluidframework/container-definitions": "~2.115.0",
83
- "@fluidframework/container-loader": "~2.115.0",
84
- "@fluidframework/container-runtime": "~2.115.0",
85
- "@fluidframework/container-runtime-definitions": "~2.115.0",
86
- "@fluidframework/core-interfaces": "~2.115.0",
87
- "@fluidframework/core-utils": "~2.115.0",
88
- "@fluidframework/driver-base": "~2.115.0",
89
- "@fluidframework/driver-definitions": "~2.115.0",
90
- "@fluidframework/driver-utils": "~2.115.0",
81
+ "@fluid-internal/client-utils": "~2.116.0",
82
+ "@fluidframework/container-definitions": "~2.116.0",
83
+ "@fluidframework/container-loader": "~2.116.0",
84
+ "@fluidframework/container-runtime": "~2.116.0",
85
+ "@fluidframework/container-runtime-definitions": "~2.116.0",
86
+ "@fluidframework/core-interfaces": "~2.116.0",
87
+ "@fluidframework/core-utils": "~2.116.0",
88
+ "@fluidframework/driver-base": "~2.116.0",
89
+ "@fluidframework/driver-definitions": "~2.116.0",
90
+ "@fluidframework/driver-utils": "~2.116.0",
91
91
  "@fluidframework/protocol-base": "^7.0.1",
92
- "@fluidframework/routerlicious-driver": "~2.115.0",
93
- "@fluidframework/runtime-utils": "~2.115.0",
92
+ "@fluidframework/routerlicious-driver": "~2.116.0",
93
+ "@fluidframework/runtime-utils": "~2.116.0",
94
94
  "@fluidframework/server-local-server": "^7.0.1",
95
95
  "@fluidframework/server-services-client": "^7.0.1",
96
96
  "@fluidframework/server-services-core": "^7.0.1",
97
97
  "@fluidframework/server-test-utils": "^7.0.1",
98
- "@fluidframework/telemetry-utils": "~2.115.0",
98
+ "@fluidframework/telemetry-utils": "~2.116.0",
99
99
  "jsrsasign": "^11.1.1",
100
100
  "uuid": "^11.1.0"
101
101
  },
102
102
  "devDependencies": {
103
- "@arethetypeswrong/cli": "^0.18.2",
103
+ "@arethetypeswrong/cli": "^0.18.5",
104
104
  "@biomejs/biome": "~2.4.5",
105
- "@fluid-internal/mocha-test-setup": "~2.115.0",
106
- "@fluid-tools/build-cli": "^0.65.0",
105
+ "@fluid-internal/mocha-test-setup": "~2.116.0",
106
+ "@fluid-tools/build-cli": "^0.67.0",
107
107
  "@fluidframework/build-common": "^2.0.3",
108
- "@fluidframework/build-tools": "^0.65.0",
109
- "@fluidframework/eslint-config-fluid": "^13.0.0",
110
- "@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@2.112.0",
111
- "@fluidframework/shared-object-base": "~2.115.0",
108
+ "@fluidframework/build-tools": "^0.67.0",
109
+ "@fluidframework/eslint-config-fluid": "^14.0.0",
110
+ "@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@2.114.0",
111
+ "@fluidframework/shared-object-base": "~2.116.0",
112
112
  "@microsoft/api-extractor": "7.58.1",
113
113
  "@types/jsrsasign": "^10.5.12",
114
114
  "@types/mocha": "^10.0.10",
@@ -18,16 +18,17 @@ import {
18
18
  type ErasedBaseType,
19
19
  } from "@fluidframework/core-interfaces/internal";
20
20
  import { assert } from "@fluidframework/core-utils/internal";
21
- import type {
22
- DataStoreKind,
23
- DataStoreRegistry,
24
- FluidContainerAttached,
25
- FluidContainerWithService,
26
- Registry,
27
- ServiceClient,
28
- ServiceOptions,
21
+ import {
22
+ featureVersion,
23
+ type DataStoreKind,
24
+ type DataStoreRegistry,
25
+ type FluidContainerAttached,
26
+ type FluidContainerWithService,
27
+ type OldestSupportedServiceClientVersion,
28
+ type Registry,
29
+ type ServiceClient,
30
+ type ServiceOptions,
29
31
  } from "@fluidframework/driver-definitions/internal";
30
- import { featureVersion } from "@fluidframework/driver-definitions/internal";
31
32
  import {
32
33
  type ContainerRuntimeLoader,
33
34
  type ContainerRuntimeLoaderParams,
@@ -107,6 +108,10 @@ export function getDefaultEphemeralService(): EphemeralService {
107
108
  * @internal
108
109
  */
109
110
  export interface EphemeralServiceOptions extends ServiceOptions {
111
+ /**
112
+ * {@inheritdoc @fluidframework/driver-definitions#ServiceOptions.oldestSupportedClient}
113
+ */
114
+ readonly oldestSupportedClient: OldestSupportedServiceClientVersion;
110
115
  /**
111
116
  * The service instance to connect to.
112
117
  */
@@ -129,7 +134,7 @@ export interface EphemeralServiceOptions extends ServiceOptions {
129
134
  * This is separated out from the actual {@link @fluidframework/driver-definitions#ServiceClient} object so that it's possible to create multiple service clients
130
135
  * connected to the same service.
131
136
  * Doing so is rarely necessary, but would be needed to test multiple clients collaborating on the same
132
- * document with different minVersionForCollaboration values.
137
+ * document with different `oldestSupportedClient` values.
133
138
  * This also exposes a place to put APIs for preloading and exporting document contents in the future.
134
139
  *
135
140
  * This is an erased type: its only implementation is the module-private {@link EphemeralServiceImplementation}, which holds
@@ -184,8 +189,8 @@ export interface EphemeralService extends ErasedBaseType<readonly ["EphemeralSer
184
189
  /**
185
190
  * Creates and returns a {@link EphemeralServiceClient} for an in-memory, ephemeral Fluid service.
186
191
  *
187
- * @param options - Options for the client. `minVersionForCollaboration` may be omitted (since all collaborators
188
- * are in the same process, it defaults to the current version). `service` may be omitted to allocate a new
192
+ * @param options - Options for the client. `oldestSupportedClient` may be omitted because all
193
+ * clients are in the same process, so it defaults to the current version. `service` may be omitted to allocate a new
189
194
  * {@link EphemeralService} dedicated to this client, or provided to connect the client to an existing service instance.
190
195
  *
191
196
  * @remarks
@@ -248,8 +253,7 @@ class EphemeralServiceImplementation
248
253
  }
249
254
  public newClient(options?: Partial<ServiceOptions>): EphemeralServiceClient {
250
255
  const finalOptions: EphemeralServiceOptions = {
251
- minVersionForCollaboration:
252
- options?.minVersionForCollaboration ?? featureVersion(pkgVersion),
256
+ oldestSupportedClient: options?.oldestSupportedClient ?? featureVersion(pkgVersion),
253
257
  service: this,
254
258
  };
255
259
  return new EphemeralServiceClientImplementation(finalOptions);
@@ -478,7 +482,7 @@ export class EphemeralServiceContainer<TData>
478
482
  documentServiceFactory: options.service.getDocumentServiceFactory(),
479
483
  codeLoader: makeCodeLoader(
480
484
  registry,
481
- options.minVersionForCollaboration,
485
+ options.oldestSupportedClient,
482
486
  containerRuntimeLoader,
483
487
  root,
484
488
  ),
@@ -505,7 +509,7 @@ export class EphemeralServiceContainer<TData>
505
509
  documentServiceFactory: options.service.getDocumentServiceFactory(),
506
510
  codeLoader: makeCodeLoader(
507
511
  registry,
508
- options.minVersionForCollaboration,
512
+ options.oldestSupportedClient,
509
513
  containerRuntimeLoader,
510
514
  ),
511
515
  });
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/local-driver";
9
- export const pkgVersion = "2.115.0";
9
+ export const pkgVersion = "2.116.0";