@fluidframework/local-driver 3.1.0 → 3.2.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 +34 -0
- package/api-report/local-driver.alpha.api.md +21 -7
- package/dist/alpha.d.ts +4 -1
- package/dist/ephemeralService.d.ts +126 -74
- package/dist/ephemeralService.d.ts.map +1 -1
- package/dist/ephemeralService.js +125 -19
- package/dist/ephemeralService.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/localSessionStorageDb.d.ts.map +1 -1
- package/dist/localSessionStorageDb.js +19 -8
- package/dist/localSessionStorageDb.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/alpha.d.ts +4 -1
- package/lib/ephemeralService.d.ts +126 -74
- package/lib/ephemeralService.d.ts.map +1 -1
- package/lib/ephemeralService.js +123 -19
- package/lib/ephemeralService.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/localSessionStorageDb.d.ts.map +1 -1
- package/lib/localSessionStorageDb.js +19 -8
- package/lib/localSessionStorageDb.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +17 -17
- package/src/ephemeralService.ts +278 -109
- package/src/index.ts +5 -1
- package/src/localSessionStorageDb.ts +23 -7
- package/src/packageVersion.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ephemeralService.js","sourceRoot":"","sources":["../src/ephemeralService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAyDH,sDAUC;AAUD,0DASC;AAOD,gEAKC;AAhGD,6EAGwD;AACxD,wEAGmD;AACnD,y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EACL,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,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\toldestSupportedClient: 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"]}
|
|
1
|
+
{"version":3,"file":"ephemeralService.js","sourceRoot":"","sources":["../src/ephemeralService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA2DH,sDAUC;AAaD,8CAOC;AAGD,sEAGC;AAUD,0DASC;AAOD,gEAKC;AA5HD,6EAGwD;AACxD,wEAGmD;AACnD,yEAA8E;AAE9E,uEAGkD;AAClD,kEAA6D;AAC7D,0EASqD;AACrD,qEAOgD;AAChD,6EAG6C;AAE7C,oEAAmE;AACnE,+BAAkC;AAElC,qFAA+E;AAC/E,yDAAwF;AACxF,yEAA0E;AAC1E,2DAAiD;AAEjD;;;;;;;;;;GAUG;AACH,SAAgB,qBAAqB,CAAC,SAAS,GAAG,IAAI;IACrD,IAAI,SAAS,IAAI,uBAAuB,EAAE,CAAC;QAC1C,MAAM,IAAI,qBAAU,CAAC,+C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CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAEe,KAAK;QACpB,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,8EAA8E;QAC9E,0BAA0B,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAES,mBAAmB;QAC5B,OAAO,IAAA,sDAAmC,EAAC,IAAA,SAAI,GAAE,CAAC,CAAC;IACpD,CAAC;CACD;AAzFD,8DAyFC","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 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 type { ITestDbFactory } from \"@fluidframework/server-test-utils\";\nimport { UsageError } from \"@fluidframework/driver-utils/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport { LocalDocumentServiceFactory } from \"./localDocumentServiceFactory.js\";\nimport { createLocalResolverCreateNewRequest, LocalResolver } from \"./localResolver.js\";\nimport { LocalSessionStorageDbFactory } from \"./localSessionStorageDb.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 LocalServiceImplementation();\n\tif (isDefault) {\n\t\tdefaultEphemeralService = service;\n\t}\n\treturn service;\n}\n\n/**\n * Gets the session-storage-backed local Fluid service for the current JavaScript realm, creating it on first use.\n *\n * @remarks\n * Attached documents remain available after a page reload within the same browser tab. Repeated calls return\n * the same service instance within the current JavaScript realm.\n *\n * This service is only available in browser environments that provide `sessionStorage`.\n * @returns A local service backed by browser session storage.\n * @alpha\n */\nexport function getSessionService(): SessionService {\n\tif (typeof sessionStorage === \"undefined\") {\n\t\tthrow new UsageError(\"SessionService requires browser session storage\");\n\t}\n\treturn (sessionService ??= new LocalServiceImplementation(\n\t\tnew LocalSessionStorageDbFactory(),\n\t));\n}\n\n/** Closes and clears the current session service for test isolation. */\nexport async function resetSessionServiceForTesting(): Promise<void> {\n\tawait sessionService?.close();\n\tsessionService = undefined;\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 a local service client, extending\n * {@link @fluidframework/driver-definitions#ServiceOptions} with the service the client should connect to.\n * @input\n * @internal\n */\nexport interface LocalServiceOptions<TService extends LocalService = LocalService>\n\textends ServiceOptions {\n\t/**\n\t * The service instance to connect to.\n\t */\n\treadonly service: TService;\n}\n\n/**\n * Internal options for creating a {@link LocalServiceClient} connected to an {@link EphemeralService}.\n * @input\n * @internal\n */\nexport interface EphemeralServiceOptions extends LocalServiceOptions<EphemeralService> {}\n\n/**\n * A local Fluid service with an explicitly managed lifecycle.\n * @remarks\n * There are two implementations of this interface with different document lifetimes:\n * {@link EphemeralService} and {@link SessionService}.\n *\n * @typeParam TClient - The type of client this service creates.\n * @alpha @sealed\n */\nexport interface LocalService<out TClient extends ServiceClient = LocalServiceClient>\n\textends ErasedBaseType<readonly [\"LocalService\", TClient]> {\n\t/**\n\t * Lists the IDs of documents currently stored by this service.\n\t */\n\tlistDocumentIds(): Promise<readonly string[]>;\n\n\t/**\n\t * Deletes a stored document.\n\t *\n\t * @remarks\n\t * Deletion is only allowed when this service has no open containers because resetting the local\n\t * server invalidates all of its active connections. Content-addressed summary data shared with other\n\t * documents may be retained until {@link LocalService.deleteAllDocuments} is called.\n\t * Only one call to {@link LocalService.deleteDocument} or {@link LocalService.deleteAllDocuments}\n\t * may be in progress at a time.\n\t *\n\t * @param id - The ID of the document to delete.\n\t * @throws A `UsageError` if the service is closed, another document deletion is in progress, or the\n\t * service has open containers.\n\t */\n\tdeleteDocument(id: string): Promise<void>;\n\n\t/**\n\t * Deletes all documents stored by this service.\n\t *\n\t * @remarks\n\t * Deletion is only allowed when this service has no open containers because resetting the local\n\t * server invalidates all of its active connections.\n\t * Only one call to {@link LocalService.deleteDocument} or {@link LocalService.deleteAllDocuments}\n\t * may be in progress at a time.\n\t * @throws A `UsageError` if the service is closed, another document deletion is in progress, or the\n\t * service has open containers.\n\t */\n\tdeleteAllDocuments(): 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 * @throws A `UsageError` if the containers do not quiesce before the timeout expires.\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 */\n\tsynchronize(timeoutMilliseconds?: number): Promise<void>;\n\n\t/**\n\t * Creates a client connected to this service.\n\t *\n\t * @param options - Collaboration options for the client.\n\t */\n\tnewClient(options: ServiceOptions): TClient;\n\n\t/**\n\t * A client connected to this service using the default options.\n\t */\n\treadonly defaultClient: TClient;\n}\n\n/**\n * An in-memory Fluid service that can produce connected {@link LocalServiceClient}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 `LocalServiceImplementation`, 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 LocalServiceClient}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 LocalServiceClient}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 LocalService<LocalServiceClient<EphemeralService>> {\n\t/**\n\t * Closes all containers connected to this service and releases its active resources.\n\t *\n\t * @remarks\n\t * Closing is idempotent. Closing an ephemeral service permanently discards all documents it holds,\n\t * so their IDs can no longer be loaded.\n\t */\n\tclose(): Promise<void>;\n}\n\n/**\n * A browser-local Fluid service that persists documents in session storage.\n *\n * @remarks\n * Its attached documents remain available after a page reload within the same browser tab. The service is\n * shared within the current JavaScript realm and intentionally has no close operation: its active resources\n * live until the realm is unloaded.\n *\n * Session storage is shared more broadly than JavaScript module state. Separate same-origin realms, such as\n * same-origin frames, or applications that load separate copies of this package can access the same stored\n * documents while running independent local servers. Concurrently editing the same document from such realms\n * is unsupported and may produce inconsistent stored state.\n *\n * Create one with {@link getSessionService}.\n * @alpha @sealed\n */\nexport interface SessionService extends LocalService<LocalServiceClient<SessionService>> {}\n\n/**\n * The {@link defaultEphemeralService} if one has been {@link startEphemeralService|started}.\n */\nlet defaultEphemeralService: LocalServiceImplementation | undefined;\n\n/**\n * The lazily created session service for this JavaScript realm.\n */\nlet sessionService: LocalServiceImplementation | undefined;\n\n/**\n * The concrete implementation of local services.\n * @remarks\n * Kept module-private so its mutable state and internal helpers are not part of the public API.\n * Narrow a {@link LocalService} to it with `LocalServiceImplementation.narrow`.\n */\nclass LocalServiceImplementation\n\textends ErasedTypeImplementation<\n\t\tLocalService<LocalServiceClientImplementation<LocalServiceImplementation>>\n\t>\n\timplements LocalService<LocalServiceClientImplementation<LocalServiceImplementation>>\n{\n\t/**\n\t * The active in-memory server shared by this service's containers so they can communicate.\n\t * Replaced after document maintenance resets the server.\n\t */\n\tprivate server: ILocalDeltaConnectionServer;\n\t/** The document service factory bound to the active {@link LocalServiceImplementation.server}. */\n\tprivate documentServiceFactory: LocalDocumentServiceFactory;\n\t/** The persistent database factory retained when the active server is replaced. */\n\tprivate readonly databaseFactory: ITestDbFactory;\n\t/** The open containers connected to this service. */\n\tprivate readonly containers = new Set<EphemeralServiceContainer<unknown>>();\n\t/** Whether this service has been permanently closed. */\n\tprivate closed = false;\n\t/** Whether document deletion is temporarily preventing other service operations. */\n\tprivate maintenanceInProgress = false;\n\n\tpublic constructor(databaseFactory?: ITestDbFactory) {\n\t\tsuper();\n\t\tthis.server = LocalDeltaConnectionServer.create(databaseFactory);\n\t\tthis.databaseFactory = this.server.testDbFactory;\n\t\tthis.documentServiceFactory = new LocalDocumentServiceFactory(this.server);\n\t\tthis.defaultClient = this.newClient();\n\t}\n\tpublic newClient(\n\t\toptions?: Partial<ServiceOptions>,\n\t): LocalServiceClientImplementation<LocalServiceImplementation> {\n\t\tconst finalOptions: LocalServiceOptions<LocalServiceImplementation> = {\n\t\t\t...options,\n\t\t\toldestSupportedClient: options?.oldestSupportedClient ?? featureVersion(pkgVersion),\n\t\t\tservice: this,\n\t\t};\n\t\treturn new LocalServiceClientImplementation(finalOptions);\n\t}\n\tpublic readonly defaultClient: LocalServiceClientImplementation<LocalServiceImplementation>;\n\n\tpublic async listDocumentIds(): Promise<readonly string[]> {\n\t\tthis.ensureAvailable();\n\t\tconst documentCollection = await this.server.databaseManager.getDocumentCollection();\n\t\tconst documents = await documentCollection.findAll();\n\t\treturn documents.map((document) => document.documentId);\n\t}\n\n\tpublic async deleteDocument(id: string): Promise<void> {\n\t\tawait this.deleteDocuments(id);\n\t}\n\n\tpublic async deleteAllDocuments(): Promise<void> {\n\t\tawait this.deleteDocuments();\n\t}\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\tprivate ensureAvailable(): void {\n\t\tif (this.closed) {\n\t\t\tthrow new UsageError(\"Local service is closed\");\n\t\t}\n\t\tif (this.maintenanceInProgress) {\n\t\t\tthrow new UsageError(\"Local service document maintenance is already in progress\");\n\t\t}\n\t}\n\n\t/**\n\t * Delete all documents unless `id` is specified, in which case only that document is deleted.\n\t */\n\tprivate async deleteDocuments(id?: string): Promise<void> {\n\t\tthis.ensureAvailable();\n\t\tif (this.containers.size > 0) {\n\t\t\tthrow new UsageError(\"Close all containers before deleting local service documents\");\n\t\t}\n\n\t\tthis.maintenanceInProgress = true;\n\t\tlet serverClosed = false;\n\t\ttry {\n\t\t\tawait this.server.close();\n\t\t\tserverClosed = true;\n\t\t\tconst databaseManager = this.server.databaseManager;\n\t\t\tconst filter = id === undefined ? {} : { documentId: id };\n\t\t\tconst historianDatabase = this.databaseFactory.testDatabase;\n\t\t\tconst documentCollection = await databaseManager.getDocumentCollection();\n\t\t\tconst checkpointCollection = await databaseManager.getCheckpointCollection();\n\t\t\tconst deltaCollection = await databaseManager.getDeltaCollection(undefined, id);\n\t\t\tconst scribeDeltaCollection = await databaseManager.getScribeDeltaCollection(\n\t\t\t\tundefined,\n\t\t\t\tid,\n\t\t\t);\n\t\t\tconst deletions = [\n\t\t\t\tdocumentCollection.deleteMany(filter),\n\t\t\t\tcheckpointCollection.deleteMany(filter),\n\t\t\t\tdeltaCollection.deleteMany(filter),\n\t\t\t\tscribeDeltaCollection.deleteMany(filter),\n\t\t\t\thistorianDatabase\n\t\t\t\t\t.collection(\"refs\")\n\t\t\t\t\t.deleteMany(id === undefined ? {} : { _id: `heads/${id}` }),\n\t\t\t];\n\t\t\tif (id === undefined) {\n\t\t\t\tconst nodeCollection = await databaseManager.getNodeCollection();\n\t\t\t\tdeletions.push(\n\t\t\t\t\tnodeCollection.deleteMany({}),\n\t\t\t\t\thistorianDatabase.collection(\"blobs\").deleteMany({}),\n\t\t\t\t\thistorianDatabase.collection(\"commits\").deleteMany({}),\n\t\t\t\t\thistorianDatabase.collection(\"trees\").deleteMany({}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait Promise.all(deletions);\n\t\t} finally {\n\t\t\tif (serverClosed) {\n\t\t\t\tthis.server = LocalDeltaConnectionServer.create(this.databaseFactory);\n\t\t\t\tthis.documentServiceFactory = new LocalDocumentServiceFactory(this.server);\n\t\t\t}\n\t\t\tthis.maintenanceInProgress = false;\n\t\t}\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\tthis.ensureAvailable();\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 LocalService}.\n *\n * @typeParam TService - The type of local service this client is connected to.\n * @alpha @sealed\n */\nexport interface LocalServiceClient<\n\tout TService extends LocalService<ServiceClient> = LocalService<ServiceClient>,\n> extends ServiceClient {\n\t/**\n\t * The service instance this client is connected to.\n\t */\n\treadonly service: TService;\n}\n\nclass LocalServiceClientImplementation<TService extends LocalService>\n\textends ServiceClientImplementation<LocalServiceOptions<TService>>\n\timplements LocalServiceClient\n{\n\tpublic readonly service: TService;\n\n\tpublic constructor(options: LocalServiceOptions<TService>) {\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\toldestSupportedClient: 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\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, LocalServiceOptions>\n\timplements FluidContainerWithService<TData>\n{\n\tpublic readonly service: LocalService;\n\n\tpublic static async createDetached<T>(\n\t\tregistry: DataStoreRegistry<T>,\n\t\toptions: LocalServiceOptions,\n\t\troot: DataStoreKind<T>,\n\t): Promise<EphemeralServiceContainer<T>> {\n\t\tLocalServiceImplementation.narrow(options.service);\n\t\tconst container: IContainer = await createDetachedContainer({\n\t\t\tcodeDetails: { package: \"1.0\" },\n\t\t\tlogger: options.logger,\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: LocalServiceOptions,\n\t\tid: string,\n\t): Promise<EphemeralServiceContainer<T> & FluidContainerAttached<T>> {\n\t\tLocalServiceImplementation.narrow(options.service);\n\t\tconst containerInner = await loadExistingContainer({\n\t\t\trequest: createLoadExistingRequest(id),\n\t\t\tlogger: options.logger,\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: LocalServiceOptions,\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\tLocalServiceImplementation.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\tLocalServiceImplementation.narrow(this.service);\n\t\tthis.service.removeContainer(this);\n\t}\n\n\tprotected createAttachRequest(): IRequest {\n\t\treturn createLocalResolverCreateNewRequest(uuid());\n\t}\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export { LocalDocumentStorageService } from "./localDocumentStorageService.js";
|
|
|
10
10
|
export { createLocalResolverCreateNewRequest, LocalResolver } from "./localResolver.js";
|
|
11
11
|
export { localDriverCompatDetailsForLoader, localDriverCompatRequirementsForLoader, } from "./localLayerCompatState.js";
|
|
12
12
|
export { LocalSessionStorageDbFactory } from "./localSessionStorageDb.js";
|
|
13
|
-
export type { EphemeralService,
|
|
14
|
-
export { startEphemeralService, cleanupEphemeralService, getDefaultEphemeralService, } from "./ephemeralService.js";
|
|
13
|
+
export type { EphemeralService, EphemeralServiceOptions, LocalService, LocalServiceClient, LocalServiceOptions, SessionService, } from "./ephemeralService.js";
|
|
14
|
+
export { startEphemeralService, getSessionService, cleanupEphemeralService, getDefaultEphemeralService, } from "./ephemeralService.js";
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,mCAAmC,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EACN,iCAAiC,EACjC,sCAAsC,GACtC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC1E,YAAY,EACX,gBAAgB,EAChB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,mCAAmC,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EACN,iCAAiC,EACjC,sCAAsC,GACtC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC1E,YAAY,EACX,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,0BAA0B,GAC1B,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.getDefaultEphemeralService = exports.cleanupEphemeralService = exports.startEphemeralService = exports.LocalSessionStorageDbFactory = exports.localDriverCompatRequirementsForLoader = exports.localDriverCompatDetailsForLoader = exports.LocalResolver = exports.createLocalResolverCreateNewRequest = exports.LocalDocumentStorageService = exports.LocalDocumentServiceFactory = exports.LocalDocumentService = exports.createLocalDocumentService = exports.LocalDocumentDeltaConnection = exports.LocalDeltaStorageService = void 0;
|
|
7
|
+
exports.getDefaultEphemeralService = exports.cleanupEphemeralService = exports.getSessionService = exports.startEphemeralService = exports.LocalSessionStorageDbFactory = exports.localDriverCompatRequirementsForLoader = exports.localDriverCompatDetailsForLoader = exports.LocalResolver = exports.createLocalResolverCreateNewRequest = exports.LocalDocumentStorageService = exports.LocalDocumentServiceFactory = exports.LocalDocumentService = exports.createLocalDocumentService = exports.LocalDocumentDeltaConnection = exports.LocalDeltaStorageService = void 0;
|
|
8
8
|
var localDeltaStorageService_js_1 = require("./localDeltaStorageService.js");
|
|
9
9
|
Object.defineProperty(exports, "LocalDeltaStorageService", { enumerable: true, get: function () { return localDeltaStorageService_js_1.LocalDeltaStorageService; } });
|
|
10
10
|
var localDocumentDeltaConnection_js_1 = require("./localDocumentDeltaConnection.js");
|
|
@@ -26,6 +26,7 @@ var localSessionStorageDb_js_1 = require("./localSessionStorageDb.js");
|
|
|
26
26
|
Object.defineProperty(exports, "LocalSessionStorageDbFactory", { enumerable: true, get: function () { return localSessionStorageDb_js_1.LocalSessionStorageDbFactory; } });
|
|
27
27
|
var ephemeralService_js_1 = require("./ephemeralService.js");
|
|
28
28
|
Object.defineProperty(exports, "startEphemeralService", { enumerable: true, get: function () { return ephemeralService_js_1.startEphemeralService; } });
|
|
29
|
+
Object.defineProperty(exports, "getSessionService", { enumerable: true, get: function () { return ephemeralService_js_1.getSessionService; } });
|
|
29
30
|
Object.defineProperty(exports, "cleanupEphemeralService", { enumerable: true, get: function () { return ephemeralService_js_1.cleanupEphemeralService; } });
|
|
30
31
|
Object.defineProperty(exports, "getDefaultEphemeralService", { enumerable: true, get: function () { return ephemeralService_js_1.getDefaultEphemeralService; } });
|
|
31
32
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6EAAyE;AAAhE,uIAAA,wBAAwB,OAAA;AACjC,qFAAiF;AAAxE,+IAAA,4BAA4B,OAAA;AACrC,qEAA6F;AAApF,qIAAA,0BAA0B,OAAA;AAAE,+HAAA,oBAAoB,OAAA;AACzD,mFAA+E;AAAtE,6IAAA,2BAA2B,OAAA;AACpC,mFAA+E;AAAtE,6IAAA,2BAA2B,OAAA;AACpC,uDAAwF;AAA/E,uIAAA,mCAAmC,OAAA;AAAE,iHAAA,aAAa,OAAA;AAC3D,uEAGoC;AAFnC,6IAAA,iCAAiC,OAAA;AACjC,kJAAA,sCAAsC,OAAA;AAEvC,uEAA0E;AAAjE,wIAAA,4BAA4B,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6EAAyE;AAAhE,uIAAA,wBAAwB,OAAA;AACjC,qFAAiF;AAAxE,+IAAA,4BAA4B,OAAA;AACrC,qEAA6F;AAApF,qIAAA,0BAA0B,OAAA;AAAE,+HAAA,oBAAoB,OAAA;AACzD,mFAA+E;AAAtE,6IAAA,2BAA2B,OAAA;AACpC,mFAA+E;AAAtE,6IAAA,2BAA2B,OAAA;AACpC,uDAAwF;AAA/E,uIAAA,mCAAmC,OAAA;AAAE,iHAAA,aAAa,OAAA;AAC3D,uEAGoC;AAFnC,6IAAA,iCAAiC,OAAA;AACjC,kJAAA,sCAAsC,OAAA;AAEvC,uEAA0E;AAAjE,wIAAA,4BAA4B,OAAA;AASrC,6DAK+B;AAJ9B,4HAAA,qBAAqB,OAAA;AACrB,wHAAA,iBAAiB,OAAA;AACjB,8HAAA,uBAAuB,OAAA;AACvB,iIAAA,0BAA0B,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { LocalDeltaStorageService } from \"./localDeltaStorageService.js\";\nexport { LocalDocumentDeltaConnection } from \"./localDocumentDeltaConnection.js\";\nexport { createLocalDocumentService, LocalDocumentService } from \"./localDocumentService.js\";\nexport { LocalDocumentServiceFactory } from \"./localDocumentServiceFactory.js\";\nexport { LocalDocumentStorageService } from \"./localDocumentStorageService.js\";\nexport { createLocalResolverCreateNewRequest, LocalResolver } from \"./localResolver.js\";\nexport {\n\tlocalDriverCompatDetailsForLoader,\n\tlocalDriverCompatRequirementsForLoader,\n} from \"./localLayerCompatState.js\";\nexport { LocalSessionStorageDbFactory } from \"./localSessionStorageDb.js\";\nexport type {\n\tEphemeralService,\n\tEphemeralServiceOptions,\n\tLocalService,\n\tLocalServiceClient,\n\tLocalServiceOptions,\n\tSessionService,\n} from \"./ephemeralService.js\";\nexport {\n\tstartEphemeralService,\n\tgetSessionService,\n\tcleanupEphemeralService,\n\tgetDefaultEphemeralService,\n} from \"./ephemeralService.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AA8TxE;;;GAGG;AACH,qBAAa,4BAA6B,YAAW,cAAc;IAClE,SAAgB,YAAY,EAAE,GAAG,CAA+B;IACnD,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGpC"}
|
|
@@ -7,17 +7,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.LocalSessionStorageDbFactory = void 0;
|
|
8
8
|
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
9
9
|
const uuid_1 = require("uuid");
|
|
10
|
+
/** Namespace for all session-storage records owned by local-driver. */
|
|
11
|
+
const sessionStorageKeyPrefix = "@fluidframework/local-driver:";
|
|
10
12
|
/**
|
|
11
13
|
* A collection for local session storage, where data is stored in the browser
|
|
12
14
|
* Functions include database operations such as queries, insertion and update.
|
|
13
15
|
*/
|
|
14
16
|
class LocalSessionStorageCollection {
|
|
15
|
-
|
|
17
|
+
/** Prefix that scopes session-storage records to this collection. */
|
|
18
|
+
storageKeyPrefix;
|
|
16
19
|
/**
|
|
17
20
|
* @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.
|
|
18
21
|
*/
|
|
19
22
|
constructor(collectionName) {
|
|
20
|
-
this.
|
|
23
|
+
this.storageKeyPrefix = `${sessionStorageKeyPrefix}${collectionName}-`;
|
|
21
24
|
}
|
|
22
25
|
aggregate(pipeline, options) {
|
|
23
26
|
throw new Error("Method Not Implemented");
|
|
@@ -175,13 +178,21 @@ class LocalSessionStorageCollection {
|
|
|
175
178
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}
|
|
176
179
|
*/
|
|
177
180
|
async deleteOne(query) {
|
|
178
|
-
|
|
181
|
+
const value = this.findOneInternal(query);
|
|
182
|
+
if (value !== null) {
|
|
183
|
+
sessionStorage.removeItem(`${this.storageKeyPrefix}${value._id}`);
|
|
184
|
+
}
|
|
185
|
+
return value;
|
|
179
186
|
}
|
|
180
187
|
/**
|
|
181
188
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}
|
|
182
189
|
*/
|
|
183
190
|
async deleteMany(query) {
|
|
184
|
-
|
|
191
|
+
const values = await this.find(query, undefined);
|
|
192
|
+
for (const value of values) {
|
|
193
|
+
sessionStorage.removeItem(`${this.storageKeyPrefix}${value._id}`);
|
|
194
|
+
}
|
|
195
|
+
return values;
|
|
185
196
|
}
|
|
186
197
|
/**
|
|
187
198
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}
|
|
@@ -197,7 +208,7 @@ class LocalSessionStorageCollection {
|
|
|
197
208
|
for (let i = 0; i < sessionStorage.length; i++) {
|
|
198
209
|
const key = sessionStorage.key(i);
|
|
199
210
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
200
|
-
if (key.startsWith(this.
|
|
211
|
+
if (key.startsWith(this.storageKeyPrefix)) {
|
|
201
212
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
202
213
|
values.push(JSON.parse(sessionStorage.getItem(key)));
|
|
203
214
|
}
|
|
@@ -217,7 +228,7 @@ class LocalSessionStorageCollection {
|
|
|
217
228
|
if (!value._id) {
|
|
218
229
|
value._id = (0, uuid_1.v4)();
|
|
219
230
|
}
|
|
220
|
-
sessionStorage.setItem(`${this.
|
|
231
|
+
sessionStorage.setItem(`${this.storageKeyPrefix}${value._id}`, JSON.stringify(value));
|
|
221
232
|
}
|
|
222
233
|
}
|
|
223
234
|
}
|
|
@@ -230,7 +241,7 @@ class LocalSessionStorageCollection {
|
|
|
230
241
|
*/
|
|
231
242
|
findOneInternal(query) {
|
|
232
243
|
if (query._id) {
|
|
233
|
-
const json = sessionStorage.getItem(`${this.
|
|
244
|
+
const json = sessionStorage.getItem(`${this.storageKeyPrefix}${query._id}`);
|
|
234
245
|
if (json) {
|
|
235
246
|
return JSON.parse(json);
|
|
236
247
|
}
|
|
@@ -240,7 +251,7 @@ class LocalSessionStorageCollection {
|
|
|
240
251
|
for (let i = 0; i < sessionStorage.length; i++) {
|
|
241
252
|
const ssKey = sessionStorage.key(i);
|
|
242
253
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
243
|
-
if (!ssKey.startsWith(this.
|
|
254
|
+
if (!ssKey.startsWith(this.storageKeyPrefix)) {
|
|
244
255
|
continue;
|
|
245
256
|
}
|
|
246
257
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA4D;AAG5D,+BAAkC;AAElC;;;GAGG;AACH,MAAM,6BAA6B;IAIL;IAH7B;;OAEG;IACH,YAA6B,cAAsB;QAAtB,mBAAc,GAAd,cAAc,CAAQ;IAAG,CAAC;IAEhD,SAAS,CAAC,QAAa,EAAE,OAAa;QAC5C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAW,EAAE,GAAQ,EAAE,QAAa;QAC3D,MAA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AAC,IAAY;QACvC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED;;;GAGG;AACH,MAAa,4BAA4B;IACxB,YAAY,GAAQ,IAAI,qBAAqB,EAAE,CAAC;IACzD,KAAK,CAAC,OAAO;QACnB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;CACD;AALD,oEAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\nimport type { ICollection, IDb } from \"@fluidframework/server-services-core\";\nimport type { ITestDbFactory } from \"@fluidframework/server-test-utils\";\nimport { v4 as uuid } from \"uuid\";\n\n/**\n * A collection for local session storage, where data is stored in the browser\n * Functions include database operations such as queries, insertion and update.\n */\nclass LocalSessionStorageCollection<T> implements ICollection<T> {\n\t/**\n\t * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.\n\t */\n\tconstructor(private readonly collectionName: string) {}\n\n\tpublic aggregate(pipeline: any, options?: any): any {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\n\tpublic async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async distinct(key: any, query: any): Promise<any> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async findAndUpdate(query: any, value: T): Promise<{ value: T; existing: boolean }> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n\t */\n\t/*\n\t * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n\t * The hierarchical syntax allows finding nested key patterns.\n\t */\n\tpublic async find(query: any, sort: any): Promise<any[]> {\n\t\t// split the keys and get the corresponding value\n\t\tfunction getValueByKey(propertyBag, key: string): any {\n\t\t\tconst keys = key.split(\".\");\n\t\t\tlet value = propertyBag;\n\t\t\tfor (const splitKey of keys) {\n\t\t\t\tvalue = value[splitKey];\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\n\t\t// getting keys of the query we are trying to find\n\t\tconst queryKeys = Object.keys(query);\n\t\tlet filteredCollection = this.getAllInternal();\n\t\tfor (const key of queryKeys) {\n\t\t\tif (!query[key]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (query[key].$gt > 0 || query[key].$lt > 0) {\n\t\t\t\tif (query[key].$gt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) > query[key].$gt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (query[key].$lt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) < query[key].$lt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t(value) => getValueByKey(value, key) === query[key],\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (sort && Object.keys(sort).length === 1) {\n\t\t\tfunction compare(a, b): number {\n\t\t\t\t// Non null asserting here because of the length check above\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst sortKey = Object.keys(sort)[0]!;\n\t\t\t\treturn sort[sortKey] === 1\n\t\t\t\t\t? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n\t\t\t\t\t: getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n\t\t\t}\n\n\t\t\tfilteredCollection = filteredCollection.sort(compare);\n\t\t}\n\t\treturn filteredCollection;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n\t */\n\tpublic async findAll(): Promise<any[]> {\n\t\treturn this.getAllInternal();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async findOne(query: any): Promise<any> {\n\t\treturn this.findOneInternal(query);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async update(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (value) {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t} else {\n\t\t\tthrow new Error(\"Not found\");\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async upsert(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (value) {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t} else {\n\t\t\tthis.insertInternal(set);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n\t */\n\t/*\n\t * Value is expected to have a member \"_id\" which is a string used to search in the database.\n\t */\n\tpublic async insertOne(value: any): Promise<any> {\n\t\tconst presentVal = this.findOneInternal(value);\n\t\t// Only raise error when the object is present and the value is not equal.\n\t\tif (presentVal) {\n\t\t\tif (JSON.stringify(presentVal) === JSON.stringify(value)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Error(\"Existing Object!!\");\n\t\t}\n\n\t\treturn this.insertInternal(value);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n\t */\n\t/*\n\t * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n\t */\n\tpublic async findOrCreate(\n\t\tquery: any,\n\t\tvalue: any,\n\t): Promise<{ value: any; existing: boolean }> {\n\t\tconst existing = this.findOneInternal(query);\n\t\tif (existing) {\n\t\t\treturn { value: existing, existing: true };\n\t\t}\n\t\tthis.insertInternal(value);\n\t\treturn { value, existing: false };\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n\t */\n\t/*\n\t * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n\t */\n\tpublic async insertMany(values: any[], ordered: boolean): Promise<void> {\n\t\tthis.insertInternal(...values);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n\t */\n\tpublic async deleteOne(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n\t */\n\tpublic async deleteMany(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n\t */\n\tpublic async createIndex(index: any, unique: boolean): Promise<void> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * Return all values in the database\n\t */\n\tprivate getAllInternal(): any[] {\n\t\tconst values: string[] = [];\n\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\tconst key = sessionStorage.key(i);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (key!.startsWith(this.collectionName)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tvalues.push(JSON.parse(sessionStorage.getItem(key!)!));\n\t\t\t}\n\t\t}\n\t\treturn values;\n\t}\n\n\t/**\n\t * Inserts values into the session storge.\n\t * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n\t *\n\t * @param values - data to insert to the database\n\t */\n\tprivate insertInternal(...values: any[]): void {\n\t\tfor (const value of values) {\n\t\t\tif (value) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\t\t\tif (!value._id) {\n\t\t\t\t\tvalue._id = uuid();\n\t\t\t\t}\n\t\t\t\tsessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the query in session storage and returns its value.\n\t * Returns null if query is not found.\n\t * Query is expected to have a member \"_id\" which is a unique id.\n\t *\n\t * @param query - what to find in the database\n\t */\n\tprivate findOneInternal(query: any): any {\n\t\tif (query._id) {\n\t\t\tconst json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n\t\t\tif (json) {\n\t\t\t\treturn JSON.parse(json);\n\t\t\t}\n\t\t} else {\n\t\t\tconst queryKeys = Object.keys(query);\n\t\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\t\tconst ssKey = sessionStorage.key(i);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tif (!ssKey!.startsWith(this.collectionName)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n\t\t\t\tlet foundMismatch = false;\n\t\t\t\tfor (const qk of queryKeys) {\n\t\t\t\t\tif (value[qk] !== query[qk]) {\n\t\t\t\t\t\tfoundMismatch = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!foundMismatch) {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n\tprivate readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n\tpublic async close(): Promise<void> {}\n\tpublic collection<T>(name: string): ICollection<T> {\n\t\tif (!this.collections.has(name)) {\n\t\t\tthis.collections.set(name, new LocalSessionStorageCollection<T>(name));\n\t\t}\n\t\treturn this.collections.get(name) as LocalSessionStorageCollection<T>;\n\t}\n\n\tpublic async dropCollection(name: string): Promise<boolean> {\n\t\tif (!this.collections.has(name)) {\n\t\t\treturn true;\n\t\t}\n\t\tthis.collections.delete(name);\n\t\treturn true;\n\t}\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n * @internal\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n\tpublic readonly testDatabase: IDb = new LocalSessionStorageDb();\n\tpublic async connect(): Promise<IDb> {\n\t\treturn this.testDatabase;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA4D;AAG5D,+BAAkC;AAElC,uEAAuE;AACvE,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAEhE;;;GAGG;AACH,MAAM,6BAA6B;IAClC,qEAAqE;IACpD,gBAAgB,CAAS;IAE1C;;OAEG;IACH,YAAY,cAAsB;QACjC,IAAI,CAAC,gBAAgB,GAAG,GAAG,uBAAuB,GAAG,cAAc,GAAG,CAAC;IACxE,CAAC;IAEM,SAAS,CAAC,QAAa,EAAE,OAAa;QAC5C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAW,EAAE,GAAQ,EAAE,QAAa;QAC3D,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IACM,KAAK,CAAC,QAAQ,CAAC,GAAQ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,CAAC;IAC/B,UAAU,CAAI,IAAY;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,6BAA6B,CAAI,IAAI,CAAC,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAqC,CAAC;IACvE,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,IAAY;QACvC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED;;;GAGG;AACH,MAAa,4BAA4B;IACxB,YAAY,GAAQ,IAAI,qBAAqB,EAAE,CAAC;IACzD,KAAK,CAAC,OAAO;QACnB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;CACD;AALD,oEAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"@fluid-internal/client-utils\";\nimport type { ICollection, IDb } from \"@fluidframework/server-services-core\";\nimport type { ITestDbFactory } from \"@fluidframework/server-test-utils\";\nimport { v4 as uuid } from \"uuid\";\n\n/** Namespace for all session-storage records owned by local-driver. */\nconst sessionStorageKeyPrefix = \"@fluidframework/local-driver:\";\n\n/**\n * A collection for local session storage, where data is stored in the browser\n * Functions include database operations such as queries, insertion and update.\n */\nclass LocalSessionStorageCollection<T> implements ICollection<T> {\n\t/** Prefix that scopes session-storage records to this collection. */\n\tprivate readonly storageKeyPrefix: string;\n\n\t/**\n\t * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.\n\t */\n\tconstructor(collectionName: string) {\n\t\tthis.storageKeyPrefix = `${sessionStorageKeyPrefix}${collectionName}-`;\n\t}\n\n\tpublic aggregate(pipeline: any, options?: any): any {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\n\tpublic async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async distinct(key: any, query: any): Promise<any> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async findAndUpdate(query: any, value: T): Promise<{ value: T; existing: boolean }> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n\t */\n\t/*\n\t * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n\t * The hierarchical syntax allows finding nested key patterns.\n\t */\n\tpublic async find(query: any, sort: any): Promise<any[]> {\n\t\t// split the keys and get the corresponding value\n\t\tfunction getValueByKey(propertyBag, key: string): any {\n\t\t\tconst keys = key.split(\".\");\n\t\t\tlet value = propertyBag;\n\t\t\tfor (const splitKey of keys) {\n\t\t\t\tvalue = value[splitKey];\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\n\t\t// getting keys of the query we are trying to find\n\t\tconst queryKeys = Object.keys(query);\n\t\tlet filteredCollection = this.getAllInternal();\n\t\tfor (const key of queryKeys) {\n\t\t\tif (!query[key]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (query[key].$gt > 0 || query[key].$lt > 0) {\n\t\t\t\tif (query[key].$gt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) > query[key].$gt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (query[key].$lt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) < query[key].$lt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t(value) => getValueByKey(value, key) === query[key],\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (sort && Object.keys(sort).length === 1) {\n\t\t\tfunction compare(a, b): number {\n\t\t\t\t// Non null asserting here because of the length check above\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst sortKey = Object.keys(sort)[0]!;\n\t\t\t\treturn sort[sortKey] === 1\n\t\t\t\t\t? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n\t\t\t\t\t: getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n\t\t\t}\n\n\t\t\tfilteredCollection = filteredCollection.sort(compare);\n\t\t}\n\t\treturn filteredCollection;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n\t */\n\tpublic async findAll(): Promise<any[]> {\n\t\treturn this.getAllInternal();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async findOne(query: any): Promise<any> {\n\t\treturn this.findOneInternal(query);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async update(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (value) {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t} else {\n\t\t\tthrow new Error(\"Not found\");\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async upsert(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (value) {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t} else {\n\t\t\tthis.insertInternal(set);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n\t */\n\t/*\n\t * Value is expected to have a member \"_id\" which is a string used to search in the database.\n\t */\n\tpublic async insertOne(value: any): Promise<any> {\n\t\tconst presentVal = this.findOneInternal(value);\n\t\t// Only raise error when the object is present and the value is not equal.\n\t\tif (presentVal) {\n\t\t\tif (JSON.stringify(presentVal) === JSON.stringify(value)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Error(\"Existing Object!!\");\n\t\t}\n\n\t\treturn this.insertInternal(value);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n\t */\n\t/*\n\t * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n\t */\n\tpublic async findOrCreate(\n\t\tquery: any,\n\t\tvalue: any,\n\t): Promise<{ value: any; existing: boolean }> {\n\t\tconst existing = this.findOneInternal(query);\n\t\tif (existing) {\n\t\t\treturn { value: existing, existing: true };\n\t\t}\n\t\tthis.insertInternal(value);\n\t\treturn { value, existing: false };\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n\t */\n\t/*\n\t * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n\t */\n\tpublic async insertMany(values: any[], ordered: boolean): Promise<void> {\n\t\tthis.insertInternal(...values);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n\t */\n\tpublic async deleteOne(query: any): Promise<any> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (value !== null) {\n\t\t\tsessionStorage.removeItem(`${this.storageKeyPrefix}${value._id}`);\n\t\t}\n\t\treturn value;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n\t */\n\tpublic async deleteMany(query: any): Promise<any> {\n\t\tconst values = await this.find(query, undefined);\n\t\tfor (const value of values) {\n\t\t\tsessionStorage.removeItem(`${this.storageKeyPrefix}${value._id}`);\n\t\t}\n\t\treturn values;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n\t */\n\tpublic async createIndex(index: any, unique: boolean): Promise<void> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * Return all values in the database\n\t */\n\tprivate getAllInternal(): any[] {\n\t\tconst values: string[] = [];\n\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\tconst key = sessionStorage.key(i);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (key!.startsWith(this.storageKeyPrefix)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tvalues.push(JSON.parse(sessionStorage.getItem(key!)!));\n\t\t\t}\n\t\t}\n\t\treturn values;\n\t}\n\n\t/**\n\t * Inserts values into the session storge.\n\t * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n\t *\n\t * @param values - data to insert to the database\n\t */\n\tprivate insertInternal(...values: any[]): void {\n\t\tfor (const value of values) {\n\t\t\tif (value) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if value is falsy\n\t\t\t\tif (!value._id) {\n\t\t\t\t\tvalue._id = uuid();\n\t\t\t\t}\n\t\t\t\tsessionStorage.setItem(`${this.storageKeyPrefix}${value._id}`, JSON.stringify(value));\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the query in session storage and returns its value.\n\t * Returns null if query is not found.\n\t * Query is expected to have a member \"_id\" which is a unique id.\n\t *\n\t * @param query - what to find in the database\n\t */\n\tprivate findOneInternal(query: any): any {\n\t\tif (query._id) {\n\t\t\tconst json = sessionStorage.getItem(`${this.storageKeyPrefix}${query._id}`);\n\t\t\tif (json) {\n\t\t\t\treturn JSON.parse(json);\n\t\t\t}\n\t\t} else {\n\t\t\tconst queryKeys = Object.keys(query);\n\t\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\t\tconst ssKey = sessionStorage.key(i);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tif (!ssKey!.startsWith(this.storageKeyPrefix)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n\t\t\t\tlet foundMismatch = false;\n\t\t\t\tfor (const qk of queryKeys) {\n\t\t\t\t\tif (value[qk] !== query[qk]) {\n\t\t\t\t\t\tfoundMismatch = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!foundMismatch) {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n\tprivate readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n\tpublic async close(): Promise<void> {}\n\tpublic collection<T>(name: string): ICollection<T> {\n\t\tif (!this.collections.has(name)) {\n\t\t\tthis.collections.set(name, new LocalSessionStorageCollection<T>(name));\n\t\t}\n\t\treturn this.collections.get(name) as LocalSessionStorageCollection<T>;\n\t}\n\n\tpublic async dropCollection(name: string): Promise<boolean> {\n\t\tif (!this.collections.has(name)) {\n\t\t\treturn true;\n\t\t}\n\t\tthis.collections.delete(name);\n\t\treturn true;\n\t}\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n * @internal\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n\tpublic readonly testDatabase: IDb = new LocalSessionStorageDb();\n\tpublic async connect(): Promise<IDb> {\n\t\treturn this.testDatabase;\n\t}\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/local-driver";
|
|
8
|
-
export declare const pkgVersion = "3.
|
|
8
|
+
export declare const pkgVersion = "3.2.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/local-driver";
|
|
11
|
-
exports.pkgVersion = "3.
|
|
11
|
+
exports.pkgVersion = "3.2.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,OAAO,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 = \"3.
|
|
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,OAAO,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 = \"3.2.0\";\n"]}
|
package/lib/alpha.d.ts
CHANGED
|
@@ -11,9 +11,12 @@
|
|
|
11
11
|
export {
|
|
12
12
|
// #region @alpha APIs
|
|
13
13
|
EphemeralService,
|
|
14
|
-
|
|
14
|
+
LocalService,
|
|
15
|
+
LocalServiceClient,
|
|
16
|
+
SessionService,
|
|
15
17
|
cleanupEphemeralService,
|
|
16
18
|
getDefaultEphemeralService,
|
|
19
|
+
getSessionService,
|
|
17
20
|
startEphemeralService
|
|
18
21
|
// #endregion
|
|
19
22
|
} from "./index.js";
|