@fluidframework/local-driver 2.0.0-dev.1.3.0.96595 → 2.0.0-dev.1.4.5.105745

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.
@@ -2,18 +2,18 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IDocumentDeltaStorageService, IStream } from "@fluidframework/driver-definitions";
5
+ import * as api from "@fluidframework/driver-definitions";
6
6
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
7
  import { IDatabaseManager } from "@fluidframework/server-services-core";
8
8
  /**
9
9
  * Provides access to the underlying delta storage on the server for local driver.
10
10
  */
11
- export declare class LocalDeltaStorageService implements IDocumentDeltaStorageService {
11
+ export declare class LocalDeltaStorageService implements api.IDocumentDeltaStorageService {
12
12
  private readonly tenantId;
13
13
  private readonly id;
14
14
  private readonly databaseManager;
15
15
  constructor(tenantId: string, id: string, databaseManager: IDatabaseManager);
16
- fetchMessages(from: number, to: number | undefined, abortSignal?: AbortSignal, cachedOnly?: boolean): IStream<ISequencedDocumentMessage[]>;
16
+ fetchMessages(from: number, to: number | undefined, abortSignal?: AbortSignal, cachedOnly?: boolean): api.IStream<ISequencedDocumentMessage[]>;
17
17
  private getCore;
18
18
  }
19
19
  //# sourceMappingURL=localDeltaStorageService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localDeltaStorageService.d.ts","sourceRoot":"","sources":["../src/localDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,4BAA4B,EAC5B,OAAO,EACV,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAGxE;;GAEG;AACH,qBAAa,wBAAyB,YAAW,4BAA4B;IAErE,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAFf,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,EACV,eAAe,EAAE,gBAAgB;IAG/C,aAAa,CAChB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,WAAW,CAAC,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,OAAO,GACrB,OAAO,CAAC,yBAAyB,EAAE,CAAC;YAIzB,OAAO;CAcxB"}
1
+ {"version":3,"file":"localDeltaStorageService.d.ts","sourceRoot":"","sources":["../src/localDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAGxE;;GAEG;AACH,qBAAa,wBAAyB,YAAW,GAAG,CAAC,4BAA4B;IAEzE,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAFf,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,EACV,eAAe,EAAE,gBAAgB;IAG/C,aAAa,CAChB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,WAAW,CAAC,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,OAAO,GACrB,GAAG,CAAC,OAAO,CAAC,yBAAyB,EAAE,CAAC;YAI7B,OAAO;CAcxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"localDeltaStorageService.js","sourceRoot":"","sources":["../src/localDeltaStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,+DAAkE;AAElE;;GAEG;AACH,MAAa,wBAAwB;IACjC,YACqB,QAAgB,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import {\n IDocumentDeltaStorageService,\n IStream,\n} from \"@fluidframework/driver-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { IDatabaseManager } from \"@fluidframework/server-services-core\";\nimport { streamFromMessages } from \"@fluidframework/driver-utils\";\n\n/**\n * Provides access to the underlying delta storage on the server for local driver.\n */\nexport class LocalDeltaStorageService implements IDocumentDeltaStorageService {\n constructor(\n private readonly tenantId: string,\n private readonly id: string,\n private readonly databaseManager: IDatabaseManager) {\n }\n\n public fetchMessages(\n from: number,\n to: number | undefined,\n abortSignal?: AbortSignal,\n cachedOnly?: boolean,\n ): IStream<ISequencedDocumentMessage[]> {\n return streamFromMessages(this.getCore(from, to));\n }\n\n private async getCore(from: number, to?: number) {\n const query = { documentId: this.id, tenantId: this.tenantId };\n query[\"operation.sequenceNumber\"] = {};\n query[\"operation.sequenceNumber\"].$gt = from - 1; // from is inclusive\n\n // This looks like a bug. It used to work without setting $lt key. Now it does not\n // Need follow up\n query[\"operation.sequenceNumber\"].$lt = to ?? Number.MAX_SAFE_INTEGER;\n\n const allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);\n const dbDeltas = await allDeltas.find(query, { \"operation.sequenceNumber\": 1 });\n const messages = dbDeltas.map((delta) => delta.operation);\n return messages;\n }\n}\n"]}
1
+ {"version":3,"file":"localDeltaStorageService.js","sourceRoot":"","sources":["../src/localDeltaStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,+DAAkE;AAElE;;GAEG;AACH,MAAa,wBAAwB;IACjC,YACqB,QAAgB,EAChB,EAAU,EACV,eAAiC;QAFjC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,OAAE,GAAF,EAAE,CAAQ;QACV,oBAAe,GAAf,eAAe,CAAkB;IACtD,CAAC;IAEM,aAAa,CAChB,IAAY,EACZ,EAAsB,EACtB,WAAyB,EACzB,UAAoB;QAEhB,OAAO,IAAA,iCAAkB,EAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,EAAW;QAC3C,MAAM,KAAK,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC/D,KAAK,CAAC,0BAA0B,CAAC,GAAG,EAAE,CAAC;QACvC,KAAK,CAAC,0BAA0B,CAAC,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,oBAAoB;QAEtE,kFAAkF;QAClF,iBAAiB;QACjB,KAAK,CAAC,0BAA0B,CAAC,CAAC,GAAG,GAAG,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,MAAM,CAAC,gBAAgB,CAAC;QAEtE,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QACxF,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,0BAA0B,EAAE,CAAC,EAAE,CAAC,CAAC;QAChF,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC1D,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AA9BD,4DA8BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as api from \"@fluidframework/driver-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { IDatabaseManager } from \"@fluidframework/server-services-core\";\nimport { streamFromMessages } from \"@fluidframework/driver-utils\";\n\n/**\n * Provides access to the underlying delta storage on the server for local driver.\n */\nexport class LocalDeltaStorageService implements api.IDocumentDeltaStorageService {\n constructor(\n private readonly tenantId: string,\n private readonly id: string,\n private readonly databaseManager: IDatabaseManager) {\n }\n\n public fetchMessages(\n from: number,\n to: number | undefined,\n abortSignal?: AbortSignal,\n cachedOnly?: boolean,\n ): api.IStream<ISequencedDocumentMessage[]> {\n return streamFromMessages(this.getCore(from, to));\n }\n\n private async getCore(from: number, to?: number) {\n const query = { documentId: this.id, tenantId: this.tenantId };\n query[\"operation.sequenceNumber\"] = {};\n query[\"operation.sequenceNumber\"].$gt = from - 1; // from is inclusive\n\n // This looks like a bug. It used to work without setting $lt key. Now it does not\n // Need follow up\n query[\"operation.sequenceNumber\"].$lt = to ?? Number.MAX_SAFE_INTEGER;\n\n const allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);\n const dbDeltas = await allDeltas.find(query, { \"operation.sequenceNumber\": 1 });\n const messages = dbDeltas.map((delta) => delta.operation);\n return messages;\n }\n}\n"]}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { DocumentDeltaConnection } from "@fluidframework/driver-base";
6
6
  import { IClient, IDocumentMessage, NackErrorType } from "@fluidframework/protocol-definitions";
7
- import { IWebSocketServer } from "@fluidframework/server-services-core";
7
+ import * as core from "@fluidframework/server-services-core";
8
8
  import type { Socket } from "socket.io-client";
9
9
  /**
10
10
  * Represents a connection to a stream of delta updates
@@ -20,7 +20,7 @@ export declare class LocalDocumentDeltaConnection extends DocumentDeltaConnectio
20
20
  * @param client - information about the client
21
21
  * @param webSocketServer - web socket server to create connection
22
22
  */
23
- static create(tenantId: string, id: string, token: string, client: IClient, webSocketServer: IWebSocketServer, timeoutMs?: number): Promise<LocalDocumentDeltaConnection>;
23
+ static create(tenantId: string, id: string, token: string, client: IClient, webSocketServer: core.IWebSocketServer, timeoutMs?: number): Promise<LocalDocumentDeltaConnection>;
24
24
  constructor(socket: Socket, documentId: string);
25
25
  protected submitCore(type: string, messages: IDocumentMessage[]): void;
26
26
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"localDocumentDeltaConnection.d.ts","sourceRoot":"","sources":["../src/localDocumentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EACH,OAAO,EAEP,gBAAgB,EAChB,aAAa,EAChB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI/C;;GAEG;AACH,qBAAa,4BAA6B,SAAQ,uBAAuB;IACrE;;;;;;;;;OASG;WACiB,MAAM,CACtB,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EACf,eAAe,EAAE,gBAAgB,EACjC,SAAS,SAAQ,GAClB,OAAO,CAAC,4BAA4B,CAAC;gBAqB5B,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAI9C,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE;IAI/D;;OAEG;IACI,MAAM,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,IAAI;IAQjD;;OAEG;IACI,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAIvC;;;OAGG;IACI,gBAAgB,CAAC,gBAAgB,EAAE,MAAM;IAIhD;;;;;OAKG;IACI,UAAU,CAAC,IAAI,oBAAc,EAAE,IAAI,2BAA+C,EAAE,OAAO,EAAE,GAAG;CAY1G"}
1
+ {"version":3,"file":"localDocumentDeltaConnection.d.ts","sourceRoot":"","sources":["../src/localDocumentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EACH,OAAO,EAEP,gBAAgB,EAChB,aAAa,EAChB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,KAAK,IAAI,MA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MAAM,WAAW,GAAG;YAChB,SAAS,EAAE,SAAS;YACpB,cAAc,EAAE,CAAC,CAAC;YAClB,OAAO,EAAE;gBACL,IAAI;gBACJ,IAAI;gBACJ,OAAO;aACV;SACJ,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ;AA3FD,oEA2FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TelemetryNullLogger } from \"@fluidframework/common-utils\";\nimport { DocumentDeltaConnection } from \"@fluidframework/driver-base\";\nimport {\n IClient,\n IConnect,\n IDocumentMessage,\n NackErrorType,\n} from \"@fluidframework/protocol-definitions\";\nimport { LocalWebSocketServer } from \"@fluidframework/server-local-server\";\nimport { IWebSocketServer } from \"@fluidframework/server-services-core\";\nimport type { Socket } from \"socket.io-client\";\n\nconst testProtocolVersions = [\"^0.3.0\", \"^0.2.0\", \"^0.1.0\"];\n\n/**\n * Represents a connection to a stream of delta updates\n */\nexport class LocalDocumentDeltaConnection extends DocumentDeltaConnection {\n /**\n * Create a LocalDocumentDeltaConnection\n * Handle initial messages, contents or signals if they were in queue\n *\n * @param tenantId - the ID of the tenant\n * @param id - document ID\n * @param token - authorization token for storage service\n * @param client - information about the client\n * @param webSocketServer - web socket server to create connection\n */\n public static async create(\n tenantId: string,\n id: string,\n token: string,\n client: IClient,\n webSocketServer: IWebSocketServer,\n timeoutMs = 60000,\n ): Promise<LocalDocumentDeltaConnection> {\n const socket = (webSocketServer as LocalWebSocketServer).createConnection();\n\n // Cast LocalWebSocket to SocketIOClient.Socket which is the socket that the base class needs. This is hacky\n // but should be fine because this delta connection is for local use only.\n const socketWithListener = socket as unknown as Socket;\n\n const deltaConnection = new LocalDocumentDeltaConnection(socketWithListener, id);\n\n const connectMessage: IConnect = {\n client,\n id,\n mode: client.mode,\n tenantId,\n token, // Token is going to indicate tenant level information, etc...\n versions: testProtocolVersions,\n };\n await deltaConnection.initialize(connectMessage, timeoutMs);\n return deltaConnection;\n }\n\n constructor(socket: Socket, documentId: string) {\n super(socket, documentId, new TelemetryNullLogger());\n }\n\n protected submitCore(type: string, messages: IDocumentMessage[]) {\n this.emitMessages(type, [messages]);\n }\n\n /**\n * Submits a new delta operation to the server\n */\n public submit(messages: IDocumentMessage[]): void {\n // We use a promise resolve to force a turn break given message processing is sync\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.resolve().then(() => {\n this.submitCore(\"submitOp\", messages);\n });\n }\n\n /**\n * Submits a new signal to the server\n */\n public submitSignal(message: any): void {\n this.submitCore(\"submitSignal\", [message]);\n }\n\n /**\n * Send a \"disconnect\" message on the socket.\n * @param disconnectReason - The reason of the disconnection.\n */\n public disconnectClient(disconnectReason: string) {\n this.socket.emit(\"disconnect\", disconnectReason);\n }\n\n /**\n * * Sends a \"nack\" message on the socket.\n * @param code - An error code number that represents the error. It will be a valid HTTP error code.\n * @param type - Type of the Nack.\n * @param message - A message about the nack for debugging/logging/telemetry purposes.\n */\n public nackClient(code: number = 400, type: NackErrorType = NackErrorType.ThrottlingError, message: any) {\n const nackMessage = {\n operation: undefined,\n sequenceNumber: -1,\n content: {\n code,\n type,\n message,\n },\n };\n this.socket.emit(\"nack\", \"\", [nackMessage]);\n }\n}\n"]}
1
+ {"version":3,"file":"localDocumentDeltaConnection.js","sourceRoot":"","sources":["../src/localDocumentDeltaConnection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAmE;AACnE,6DAAsE;AACtE,+EAK8C;AAK9C,MAAM,oBAAoB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE5D;;GAEG;AACH,MAAa,4BAA6B,SAAQ,qCAAuB;IACrE;;;;;;;;;OASG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CACtB,QAAgB,EAChB,EAAU,EACV,KAAa,EACb,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ACI,UAAU,CAAC,OAAe,GAAG,EAAE,OAAsB,oCAAa,CAAC,eAAe,EAAE,OAAY;QACnG,MAAM,WAAW,GAAG;YAChB,SAAS,EAAE,SAAS;YACpB,cAAc,EAAE,CAAC,CAAC;YAClB,OAAO,EAAE;gBACL,IAAI;gBACJ,IAAI;gBACJ,OAAO;aACV;SACJ,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ;AA3FD,oEA2FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TelemetryNullLogger } from \"@fluidframework/common-utils\";\nimport { DocumentDeltaConnection } from \"@fluidframework/driver-base\";\nimport {\n IClient,\n IConnect,\n IDocumentMessage,\n NackErrorType,\n} from \"@fluidframework/protocol-definitions\";\nimport { LocalWebSocketServer } from \"@fluidframework/server-local-server\";\nimport * as core from \"@fluidframework/server-services-core\";\nimport type { Socket } from \"socket.io-client\";\n\nconst testProtocolVersions = [\"^0.3.0\", \"^0.2.0\", \"^0.1.0\"];\n\n/**\n * Represents a connection to a stream of delta updates\n */\nexport class LocalDocumentDeltaConnection extends DocumentDeltaConnection {\n /**\n * Create a LocalDocumentDeltaConnection\n * Handle initial messages, contents or signals if they were in queue\n *\n * @param tenantId - the ID of the tenant\n * @param id - document ID\n * @param token - authorization token for storage service\n * @param client - information about the client\n * @param webSocketServer - web socket server to create connection\n */\n public static async create(\n tenantId: string,\n id: string,\n token: string,\n client: IClient,\n webSocketServer: core.IWebSocketServer,\n timeoutMs = 60000,\n ): Promise<LocalDocumentDeltaConnection> {\n const socket = (webSocketServer as LocalWebSocketServer).createConnection();\n\n // Cast LocalWebSocket to SocketIOClient.Socket which is the socket that the base class needs. This is hacky\n // but should be fine because this delta connection is for local use only.\n const socketWithListener = socket as unknown as Socket;\n\n const deltaConnection = new LocalDocumentDeltaConnection(socketWithListener, id);\n\n const connectMessage: IConnect = {\n client,\n id,\n mode: client.mode,\n tenantId,\n token, // Token is going to indicate tenant level information, etc...\n versions: testProtocolVersions,\n };\n await deltaConnection.initialize(connectMessage, timeoutMs);\n return deltaConnection;\n }\n\n constructor(socket: Socket, documentId: string) {\n super(socket, documentId, new TelemetryNullLogger());\n }\n\n protected submitCore(type: string, messages: IDocumentMessage[]) {\n this.emitMessages(type, [messages]);\n }\n\n /**\n * Submits a new delta operation to the server\n */\n public submit(messages: IDocumentMessage[]): void {\n // We use a promise resolve to force a turn break given message processing is sync\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.resolve().then(() => {\n this.submitCore(\"submitOp\", messages);\n });\n }\n\n /**\n * Submits a new signal to the server\n */\n public submitSignal(message: any): void {\n this.submitCore(\"submitSignal\", [message]);\n }\n\n /**\n * Send a \"disconnect\" message on the socket.\n * @param disconnectReason - The reason of the disconnection.\n */\n public disconnectClient(disconnectReason: string) {\n this.socket.emit(\"disconnect\", disconnectReason);\n }\n\n /**\n * * Sends a \"nack\" message on the socket.\n * @param code - An error code number that represents the error. It will be a valid HTTP error code.\n * @param type - Type of the Nack.\n * @param message - A message about the nack for debugging/logging/telemetry purposes.\n */\n public nackClient(code: number = 400, type: NackErrorType = NackErrorType.ThrottlingError, message: any) {\n const nackMessage = {\n operation: undefined,\n sequenceNumber: -1,\n content: {\n code,\n type,\n message,\n },\n };\n this.socket.emit(\"nack\", \"\", [nackMessage]);\n }\n}\n"]}
@@ -2,22 +2,22 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IDocumentDeltaConnection, IDocumentDeltaStorageService, IDocumentService, IDocumentServicePolicies, IDocumentStorageService, IResolvedUrl } from "@fluidframework/driver-definitions";
5
+ import * as api from "@fluidframework/driver-definitions";
6
6
  import { IClient } from "@fluidframework/protocol-definitions";
7
- import { ITokenProvider } from "@fluidframework/routerlicious-driver";
7
+ import * as socketStorage from "@fluidframework/routerlicious-driver";
8
8
  import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
9
9
  import { LocalDocumentDeltaConnection } from ".";
10
10
  /**
11
11
  * Basic implementation of a document service for local use.
12
12
  */
13
- export declare class LocalDocumentService implements IDocumentService {
14
- readonly resolvedUrl: IResolvedUrl;
13
+ export declare class LocalDocumentService implements api.IDocumentService {
14
+ readonly resolvedUrl: api.IResolvedUrl;
15
15
  private readonly localDeltaConnectionServer;
16
16
  private readonly tokenProvider;
17
17
  private readonly tenantId;
18
18
  private readonly documentId;
19
19
  private readonly documentDeltaConnectionsMap;
20
- readonly policies: IDocumentServicePolicies;
20
+ readonly policies: api.IDocumentServicePolicies;
21
21
  private readonly innerDocumentService?;
22
22
  /**
23
23
  * @param localDeltaConnectionServer - delta connection server for ops
@@ -25,21 +25,21 @@ export declare class LocalDocumentService implements IDocumentService {
25
25
  * @param tenantId - ID of tenant
26
26
  * @param documentId - ID of document
27
27
  */
28
- constructor(resolvedUrl: IResolvedUrl, localDeltaConnectionServer: ILocalDeltaConnectionServer, tokenProvider: ITokenProvider, tenantId: string, documentId: string, documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>, policies?: IDocumentServicePolicies, innerDocumentService?: IDocumentService | undefined);
28
+ constructor(resolvedUrl: api.IResolvedUrl, localDeltaConnectionServer: ILocalDeltaConnectionServer, tokenProvider: socketStorage.ITokenProvider, tenantId: string, documentId: string, documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>, policies?: api.IDocumentServicePolicies, innerDocumentService?: api.IDocumentService | undefined);
29
29
  dispose(): void;
30
30
  /**
31
31
  * Creates and returns a document storage service for local use.
32
32
  */
33
- connectToStorage(): Promise<IDocumentStorageService>;
33
+ connectToStorage(): Promise<api.IDocumentStorageService>;
34
34
  /**
35
35
  * Creates and returns a delta storage service for local use.
36
36
  */
37
- connectToDeltaStorage(): Promise<IDocumentDeltaStorageService>;
37
+ connectToDeltaStorage(): Promise<api.IDocumentDeltaStorageService>;
38
38
  /**
39
39
  * Creates and returns a delta stream for local use.
40
40
  * @param client - client data
41
41
  */
42
- connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection>;
42
+ connectToDeltaStream(client: IClient): Promise<api.IDocumentDeltaConnection>;
43
43
  }
44
44
  /**
45
45
  * Creates and returns a document service for local use.
@@ -48,5 +48,5 @@ export declare class LocalDocumentService implements IDocumentService {
48
48
  * @param tenantId - ID of tenant
49
49
  * @param documentId - ID of document
50
50
  */
51
- export declare function createLocalDocumentService(resolvedUrl: IResolvedUrl, localDeltaConnectionServer: ILocalDeltaConnectionServer, tokenProvider: ITokenProvider, tenantId: string, documentId: string, documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>, policies?: IDocumentServicePolicies, innerDocumentService?: IDocumentService): IDocumentService;
51
+ export declare function createLocalDocumentService(resolvedUrl: api.IResolvedUrl, localDeltaConnectionServer: ILocalDeltaConnectionServer, tokenProvider: socketStorage.ITokenProvider, tenantId: string, documentId: string, documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>, policies?: api.IDocumentServicePolicies, innerDocumentService?: api.IDocumentService): api.IDocumentService;
52
52
  //# sourceMappingURL=localDocumentService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localDocumentService.d.ts","sourceRoot":"","sources":["../src/localDocumentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,wBAAwB,EACxB,4BAA4B,EAC5B,gBAAgB,EAChB,wBAAwB,EACxB,uBAAuB,EACvB,YAAY,EACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAEH,cAAc,EACjB,MAAM,sCAAsC,CAAC;AAG9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAElF,OAAO,EAA4B,4BAA4B,EAAE,MAAM,GAAG,CAAC;AAE3E;;GAEG;AACH,qBAAa,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AAE,GAAG,CAAC,YAAY,EAC7B,0BAA0B,EAAE,2BAA2B,EACvD,aAAa,EAAE,aAAa,CAAC,cAAc,EAC3C,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,4BAA4B,CAAC,EACtE,QAAQ,CAAC,EAAE,GAAG,CAAC,wBAAwB,EACvC,oBAAoB,CAAC,EAAE,GAAG,CAAC,gBAAgB,GAAG,GAAG,CAAC,gBAAgB,CAWrE"}
@@ -3,9 +3,28 @@
3
3
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
4
  * Licensed under the MIT License.
5
5
  */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
6
25
  Object.defineProperty(exports, "__esModule", { value: true });
7
26
  exports.createLocalDocumentService = exports.LocalDocumentService = void 0;
8
- const routerlicious_driver_1 = require("@fluidframework/routerlicious-driver");
27
+ const socketStorage = __importStar(require("@fluidframework/routerlicious-driver"));
9
28
  const server_services_client_1 = require("@fluidframework/server-services-client");
10
29
  const server_test_utils_1 = require("@fluidframework/server-test-utils");
11
30
  const common_utils_1 = require("@fluidframework/common-utils");
@@ -35,7 +54,7 @@ class LocalDocumentService {
35
54
  * Creates and returns a document storage service for local use.
36
55
  */
37
56
  async connectToStorage() {
38
- return new routerlicious_driver_1.DocumentStorageService(this.documentId, new server_services_client_1.GitManager(new server_test_utils_1.TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)), new common_utils_1.TelemetryNullLogger(), { minBlobSize: 2048 }, // Test blob aggregation.
57
+ return new socketStorage.DocumentStorageService(this.documentId, new server_services_client_1.GitManager(new server_test_utils_1.TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)), new common_utils_1.TelemetryNullLogger(), { minBlobSize: 2048 }, // Test blob aggregation.
39
58
  undefined, undefined, undefined, new server_services_client_1.GitManager(new server_test_utils_1.TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)));
40
59
  }
41
60
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"localDocumentService.js","sourceRoot":"","sources":["../src/localDocumentService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAWH,+EAG8C;AAC9C,mFAAoE;AACpE,yEAAkE;AAElE,+DAAmE;AACnE,wBAA2E;AAE3E;;GAEG;AACH,MAAa,oBAAoB;IAC7B;;;;;OAKG;IACH,YACoB,WAAyB,EACxB,0BAAuD,EACvD,aAA6B,EAC7B,QAAgB,EAChB,UAAkB,EAClB,2BAAsE,EACvE,WAAqC,EAAE,EACtC,oBAAuC;QAPxC,gBAAW,GAAX,WAAW,CAAc;QACxB,+BAA0B,GAA1B,0BAA0B,CAA6B;QACvD,kBAAa,GAAb,aAAa,CAAgB;QAC7B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,eAAU,GAAV,UAAU,CAAQ;QAClB,gCAA2B,GAA3B,2BAA2B,CAA2C;QACvE,aAAQ,GAAR,QAAQ,CAA+B;QACtC,yBAAoB,GAApB,oBAAoB,CAAmB;IACxD,CAAC;IAEE,OAAO,KAAK,CAAC;IAEpB;;OAEG;IACI,KAAK,CAAC,gBAAgB;QACzB,OAAO,IAAI,6CAAsB,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;QACF,MAAM,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,CAAC;QAElD,8EAA8E;QAC9E,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAC;QAExE,kFAAkF;QAClF,uBAAuB,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;YAC1C,IAAI,CAAC,2BAA2B,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,OAAO,uBAAuB,CAAC;IACnC,CAAC;CACJ;AAlFD,oDAkFC;AAED;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACtC,WAAyB,EACzB,0BAAuD,EACvD,aAA6B,EAC7B,QAAgB,EAChB,UAAkB,EAClB,2BAAsE,EACtE,QAAmC,EACnC,oBAAuC;IACvC,OAAO,IAAI,oBAAoB,CAC3B,WAAW,EACX,0BAA0B,EAC1B,aAAa,EACb,QAAQ,EACR,UAAU,EACV,2BAA2B,EAC3B,QAAQ,EACR,oBAAoB,CACvB,CAAC;AACN,CAAC;AAnBD,gEAmBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IDocumentDeltaConnection,\n IDocumentDeltaStorageService,\n IDocumentService,\n IDocumentServicePolicies,\n IDocumentStorageService,\n IResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { IClient } from \"@fluidframework/protocol-definitions\";\nimport {\n DocumentStorageService,\n ITokenProvider,\n} from \"@fluidframework/routerlicious-driver\";\nimport { GitManager } from \"@fluidframework/server-services-client\";\nimport { TestHistorian } from \"@fluidframework/server-test-utils\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport { TelemetryNullLogger } from \"@fluidframework/common-utils\";\nimport { LocalDeltaStorageService, LocalDocumentDeltaConnection } from \".\";\n\n/**\n * Basic implementation of a document service for local use.\n */\nexport class LocalDocumentService implements IDocumentService {\n /**\n * @param localDeltaConnectionServer - delta connection server for ops\n * @param tokenProvider - token provider\n * @param tenantId - ID of tenant\n * @param documentId - ID of document\n */\n constructor(\n public readonly resolvedUrl: IResolvedUrl,\n private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,\n private readonly tokenProvider: ITokenProvider,\n private readonly tenantId: string,\n private readonly documentId: string,\n private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,\n public readonly policies: IDocumentServicePolicies = {},\n private readonly innerDocumentService?: IDocumentService,\n ) { }\n\n public dispose() { }\n\n /**\n * Creates and returns a document storage service for local use.\n */\n public async connectToStorage(): Promise<IDocumentStorageService> {\n return new DocumentStorageService(\n this.documentId,\n new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)),\n new TelemetryNullLogger(),\n { minBlobSize: 2048 }, // Test blob aggregation.\n undefined,\n undefined,\n undefined,\n new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)));\n }\n\n /**\n * Creates and returns a delta storage service for local use.\n */\n public async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {\n if (this.innerDocumentService) {\n return this.innerDocumentService.connectToDeltaStorage();\n }\n return new LocalDeltaStorageService(\n this.tenantId,\n this.documentId,\n this.localDeltaConnectionServer.databaseManager);\n }\n\n /**\n * Creates and returns a delta stream for local use.\n * @param client - client data\n */\n public async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {\n if (this.policies.storageOnly === true) {\n throw new Error(\"can't connect to delta stream in storage-only mode\");\n }\n if (this.innerDocumentService) {\n return this.innerDocumentService.connectToDeltaStream(client);\n }\n const ordererToken = await this.tokenProvider.fetchOrdererToken(\n this.tenantId,\n this.documentId,\n );\n const documentDeltaConnection = await LocalDocumentDeltaConnection.create(\n this.tenantId,\n this.documentId,\n ordererToken.jwt,\n client,\n this.localDeltaConnectionServer.webSocketServer,\n );\n const clientId = documentDeltaConnection.clientId;\n\n // Add this document service for the clientId in the document service factory.\n this.documentDeltaConnectionsMap.set(clientId, documentDeltaConnection);\n\n // Add a listener to remove this document service when the client is disconnected.\n documentDeltaConnection.on(\"disconnect\", () => {\n this.documentDeltaConnectionsMap.delete(clientId);\n });\n\n return documentDeltaConnection;\n }\n}\n\n/**\n * Creates and returns a document service for local use.\n * @param localDeltaConnectionServer - delta connection server for ops\n * @param tokenProvider - token provider with a single token\n * @param tenantId - ID of tenant\n * @param documentId - ID of document\n */\nexport function createLocalDocumentService(\n resolvedUrl: IResolvedUrl,\n localDeltaConnectionServer: ILocalDeltaConnectionServer,\n tokenProvider: ITokenProvider,\n tenantId: string,\n documentId: string,\n documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,\n policies?: IDocumentServicePolicies,\n innerDocumentService?: IDocumentService): IDocumentService {\n return new LocalDocumentService(\n resolvedUrl,\n localDeltaConnectionServer,\n tokenProvider,\n tenantId,\n documentId,\n documentDeltaConnectionsMap,\n policies,\n innerDocumentService,\n );\n}\n"]}
1
+ {"version":3,"file":"localDocumentService.js","sourceRoot":"","sources":["../src/localDocumentService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;AAIH,oFAAsE;AACtE,mFAAoE;AACpE,yEAAkE;AAElE,+DAAmE;AACnE,wBAA2E;AAE3E;;GAEG;AACH,MAAa,oBAAoB;IAC7B;;;;;OAKG;IACH,YACoB,WAA6B,EAC5B,0BAAuD,EACvD,aAA2C,EAC3C,QAAgB,EAChB,UAAkB,EAClB,2BAAsE,EACvE,WAAyC,EAAE,EAC1C,oBAA2C;QAP5C,gBAAW,GAAX,WAAW,CAAkB;QAC5B,+BAA0B,GAA1B,0BAA0B,CAA6B;QACvD,kBAAa,GAAb,aAAa,CAA8B;QAC3C,aAAQ,GAAR,QAAQ,CAAQ;QAChB,eAAU,GAAV,UAAU,CAAQ;QAClB,gCAA2B,GAA3B,2BAA2B,CAA2C;QACvE,aAAQ,GAAR,QAAQ,CAAmC;QAC1C,yBAAoB,GAApB,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CACrE,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,UAAU,EACf,YAAY,CAAC,GAAG,EAChB,MAAM,EACN,IAAI,CAAC,0BAA0B,CAAC,eAAe,CAClD,CAAC;QACF,MAAM,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,CAAC;QAElD,8EAA8E;QAC9E,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAC;QAExE,kFAAkF;QAClF,uBAAuB,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;YAC1C,IAAI,CAAC,2BAA2B,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,OAAO,uBAAuB,CAAC;IACnC,CAAC;CACJ;AAlFD,oDAkFC;AAED;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACtC,WAA6B,EAC7B,0BAAuD,EACvD,aAA2C,EAC3C,QAAgB,EAChB,UAAkB,EAClB,2BAAsE,EACtE,QAAuC,EACvC,oBAA2C;IAC3C,OAAO,IAAI,oBAAoB,CAC3B,WAAW,EACX,0BAA0B,EAC1B,aAAa,EACb,QAAQ,EACR,UAAU,EACV,2BAA2B,EAC3B,QAAQ,EACR,oBAAoB,CACvB,CAAC;AACN,CAAC;AAnBD,gEAmBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as api from \"@fluidframework/driver-definitions\";\nimport { IClient } from \"@fluidframework/protocol-definitions\";\nimport * as socketStorage from \"@fluidframework/routerlicious-driver\";\nimport { GitManager } from \"@fluidframework/server-services-client\";\nimport { TestHistorian } from \"@fluidframework/server-test-utils\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport { TelemetryNullLogger } from \"@fluidframework/common-utils\";\nimport { LocalDeltaStorageService, LocalDocumentDeltaConnection } from \".\";\n\n/**\n * Basic implementation of a document service for local use.\n */\nexport class LocalDocumentService implements api.IDocumentService {\n /**\n * @param localDeltaConnectionServer - delta connection server for ops\n * @param tokenProvider - token provider\n * @param tenantId - ID of tenant\n * @param documentId - ID of document\n */\n constructor(\n public readonly resolvedUrl: api.IResolvedUrl,\n private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,\n private readonly tokenProvider: socketStorage.ITokenProvider,\n private readonly tenantId: string,\n private readonly documentId: string,\n private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,\n public readonly policies: api.IDocumentServicePolicies = {},\n private readonly innerDocumentService?: api.IDocumentService,\n ) { }\n\n public dispose() { }\n\n /**\n * Creates and returns a document storage service for local use.\n */\n public async connectToStorage(): Promise<api.IDocumentStorageService> {\n return new socketStorage.DocumentStorageService(\n this.documentId,\n new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)),\n new TelemetryNullLogger(),\n { minBlobSize: 2048 }, // Test blob aggregation.\n undefined,\n undefined,\n undefined,\n new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)));\n }\n\n /**\n * Creates and returns a delta storage service for local use.\n */\n public async connectToDeltaStorage(): Promise<api.IDocumentDeltaStorageService> {\n if (this.innerDocumentService) {\n return this.innerDocumentService.connectToDeltaStorage();\n }\n return new LocalDeltaStorageService(\n this.tenantId,\n this.documentId,\n this.localDeltaConnectionServer.databaseManager);\n }\n\n /**\n * Creates and returns a delta stream for local use.\n * @param client - client data\n */\n public async connectToDeltaStream(client: IClient): Promise<api.IDocumentDeltaConnection> {\n if (this.policies.storageOnly === true) {\n throw new Error(\"can't connect to delta stream in storage-only mode\");\n }\n if (this.innerDocumentService) {\n return this.innerDocumentService.connectToDeltaStream(client);\n }\n const ordererToken = await this.tokenProvider.fetchOrdererToken(\n this.tenantId,\n this.documentId,\n );\n const documentDeltaConnection = await LocalDocumentDeltaConnection.create(\n this.tenantId,\n this.documentId,\n ordererToken.jwt,\n client,\n this.localDeltaConnectionServer.webSocketServer,\n );\n const clientId = documentDeltaConnection.clientId;\n\n // Add this document service for the clientId in the document service factory.\n this.documentDeltaConnectionsMap.set(clientId, documentDeltaConnection);\n\n // Add a listener to remove this document service when the client is disconnected.\n documentDeltaConnection.on(\"disconnect\", () => {\n this.documentDeltaConnectionsMap.delete(clientId);\n });\n\n return documentDeltaConnection;\n }\n}\n\n/**\n * Creates and returns a document service for local use.\n * @param localDeltaConnectionServer - delta connection server for ops\n * @param tokenProvider - token provider with a single token\n * @param tenantId - ID of tenant\n * @param documentId - ID of document\n */\nexport function createLocalDocumentService(\n resolvedUrl: api.IResolvedUrl,\n localDeltaConnectionServer: ILocalDeltaConnectionServer,\n tokenProvider: socketStorage.ITokenProvider,\n tenantId: string,\n documentId: string,\n documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,\n policies?: api.IDocumentServicePolicies,\n innerDocumentService?: api.IDocumentService): api.IDocumentService {\n return new LocalDocumentService(\n resolvedUrl,\n localDeltaConnectionServer,\n tokenProvider,\n tenantId,\n documentId,\n documentDeltaConnectionsMap,\n policies,\n innerDocumentService,\n );\n}\n"]}
@@ -76,11 +76,11 @@ class LocalDocumentServiceFactory {
76
76
  * @param disconnectReason - The reason of the disconnection.
77
77
  */
78
78
  disconnectClient(clientId, disconnectReason) {
79
- const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
80
- if (documentDeltaConnection === undefined) {
79
+ if (!this.documentDeltaConnectionsMap.has(clientId)) {
81
80
  throw new Error(`No client with the id: ${clientId}`);
82
81
  }
83
- documentDeltaConnection.disconnectClient(disconnectReason);
82
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
83
+ this.documentDeltaConnectionsMap.get(clientId).disconnectClient(disconnectReason);
84
84
  }
85
85
  /**
86
86
  * Gets the document delta connection for the clientId and asks it to nack the client.
@@ -90,11 +90,11 @@ class LocalDocumentServiceFactory {
90
90
  * @param message - A message about the nack for debugging/logging/telemetry purposes.
91
91
  */
92
92
  nackClient(clientId, code, type, message) {
93
- const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
94
- if (documentDeltaConnection === undefined) {
93
+ if (!this.documentDeltaConnectionsMap.has(clientId)) {
95
94
  throw new Error(`No client with the id: ${clientId}`);
96
95
  }
97
- documentDeltaConnection.nackClient(code, type, message);
96
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
97
+ this.documentDeltaConnectionsMap.get(clientId).nackClient(code, type, message);
98
98
  }
99
99
  }
100
100
  exports.LocalDocumentServiceFactory = LocalDocumentServiceFactory;
@@ -1 +1 @@
1
- {"version":3,"file":"localDocumentServiceFactory.js","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAA4B;AAQ5B,+EAA4E;AAE5E,+DAIsC;AAEtC,mFAAqE;AAErE,iEAAoE;AAEpE;;GAEG;AACH,MAAa,2BAA2B;IAMpC;;OAEG;IACH,YACqB,0BAAuD,EACvD,QAAmC,EACnC,oBAAuC;QAFvC,+BAA0B,GAA1B,0BAA0B,CAA6B;QACvD,aAAQ,GAAR,QAAQ,CAA2B;QACnC,yBAAoB,GAApB,oBAAoB,CAAmB;QAX5C,iBAAY,GAAG,aAAa,CAAC;QAE7C,6CAA6C;QAC5B,gCAA2B,GAA8C,IAAI,GAAG,EAAE,CAAC;IAQpC,CAAC;IAE1D,KAAK,CAAC,eAAe,CACxB,gBAA0C,EAC1C,WAAyB,EACzB,MAA6B,EAC7B,kBAA4B;;QAE5B,IAAA,qCAAsB,EAAC,WAAW,CAAC,CAAC;QACpC,IAAI,gBAAgB,KAAK,SAAS,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;SAClF;QACD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;QACnD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,QAAQ,GAAG,OAAO,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AAuB,GAAG,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/E,IAAI,uBAAuB,KAAK,SAAS,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;SACzD;QACD,uBAAuB,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;CACJ;AAxHD,kEAwHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { parse } from \"url\";\nimport {\n IDocumentService,\n IDocumentServiceFactory,\n IDocumentServicePolicies,\n IResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { DefaultTokenProvider } from \"@fluidframework/routerlicious-driver\";\nimport { ILocalDeltaConnectionServer, LocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n ensureFluidResolvedUrl,\n getDocAttributesFromProtocolSummary,\n getQuorumValuesFromProtocolSummary,\n} from \"@fluidframework/driver-utils\";\nimport { ISummaryTree, NackErrorType } from \"@fluidframework/protocol-definitions\";\nimport { defaultHash } from \"@fluidframework/server-services-client\";\nimport { LocalDocumentDeltaConnection } from \"./localDocumentDeltaConnection\";\nimport { createLocalDocumentService } from \"./localDocumentService\";\n\n/**\n * Implementation of document service factory for local use.\n */\nexport class LocalDocumentServiceFactory implements IDocumentServiceFactory {\n public readonly protocolName = \"fluid-test:\";\n\n // A map of clientId to LocalDocumentService.\n private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection> = new Map();\n\n /**\n * @param localDeltaConnectionServer - delta connection server for ops\n */\n constructor(\n private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,\n private readonly policies?: IDocumentServicePolicies,\n private readonly innerDocumentService?: IDocumentService) { }\n\n public async createContainer(\n createNewSummary: ISummaryTree | undefined,\n resolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n ensureFluidResolvedUrl(resolvedUrl);\n if (createNewSummary === undefined) {\n throw new Error(\"Empty file summary creation isn't supported in this driver.\");\n }\n const pathName = new URL(resolvedUrl.url).pathname;\n const pathArr = pathName.split(\"/\");\n const tenantId = pathArr[pathArr.length - 2];\n const id = pathArr[pathArr.length - 1];\n if (!this.localDeltaConnectionServer) {\n throw new Error(\"Provide the localDeltaConnectionServer!!\");\n }\n const documentStorage = (this.localDeltaConnectionServer as LocalDeltaConnectionServer).documentStorage;\n\n const protocolSummary = createNewSummary.tree[\".protocol\"] as ISummaryTree;\n const appSummary = createNewSummary.tree[\".app\"] as ISummaryTree;\n if (!(protocolSummary && appSummary)) {\n throw new Error(\"Protocol and App Summary required in the full summary\");\n }\n const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);\n const quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);\n const sequenceNumber = documentAttributes.sequenceNumber;\n await documentStorage.createDocument(\n tenantId,\n id,\n appSummary,\n sequenceNumber,\n documentAttributes.term ?? 1,\n defaultHash,\n resolvedUrl.endpoints.ordererUrl ?? \"\",\n resolvedUrl.endpoints.storageUrl ?? \"\",\n quorumValues,\n false, /* enableDiscovery */\n );\n return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);\n }\n\n /**\n * Creates and returns a document service for testing using the given resolved\n * URL for the tenant ID, document ID, and token.\n * @param resolvedUrl - resolved URL of document\n */\n public async createDocumentService(\n resolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n ensureFluidResolvedUrl(resolvedUrl);\n\n const parsedUrl = parse(resolvedUrl.url);\n const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split(\"/\") : [];\n if (!documentId || !tenantId) {\n throw new Error(`Couldn't parse resolved url. [documentId:${documentId}][tenantId:${tenantId}]`);\n }\n\n const fluidResolvedUrl = resolvedUrl;\n const jwtToken = fluidResolvedUrl.tokens.jwt;\n if (!jwtToken) {\n throw new Error(`Token was not provided.`);\n }\n\n const tokenProvider = new DefaultTokenProvider(jwtToken);\n\n return createLocalDocumentService(\n resolvedUrl,\n this.localDeltaConnectionServer,\n tokenProvider,\n tenantId,\n documentId,\n this.documentDeltaConnectionsMap,\n this.policies,\n this.innerDocumentService);\n }\n\n /**\n * Gets the document delta connection for the clientId and asks it to disconnect the client.\n * @param clientId - The ID of the client to be disconnected.\n * @param disconnectReason - The reason of the disconnection.\n */\n public disconnectClient(clientId: string, disconnectReason: string) {\n const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);\n if (documentDeltaConnection === undefined) {\n throw new Error(`No client with the id: ${clientId}`);\n }\n documentDeltaConnection.disconnectClient(disconnectReason);\n }\n\n /**\n * Gets the document delta connection for the clientId and asks it to nack the client.\n * @param clientId - The ID of the client to be Nack'd.\n * @param code - An error code number that represents the error. It will be a valid HTTP error code.\n * @param type - Type of the Nack.\n * @param message - A message about the nack for debugging/logging/telemetry purposes.\n */\n public nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any) {\n const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);\n if (documentDeltaConnection === undefined) {\n throw new Error(`No client with the id: ${clientId}`);\n }\n documentDeltaConnection.nackClient(code, type, message);\n }\n}\n"]}
1
+ {"version":3,"file":"localDocumentServiceFactory.js","sourceRoot":"","sources":["../src/localDocumentServiceFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6BAA4B;AAQ5B,+EAA4E;AAE5E,+DAIsC;AAEtC,mFAAqE;AAErE,iEAAoE;AAEpE;;GAEG;AACH,MAAa,2BAA2B;IAMpC;;OAEG;IACH,YACqB,0BAAuD,EACvD,QAAmC,EACnC,oBAAuC;QAFvC,+BAA0B,GAA1B,0BAA0B,CAA6B;QACvD,aAAQ,GAAR,QAAQ,CAA2B;QACnC,yBAAoB,GA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Aa,EACb,QAAQ,EACR,UAAU,EACV,IAAI,CAAC,2BAA2B,EAChC,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAC,QAAgB,EAAE,gBAAwB;QAC9D,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YACjD,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;SACzD;QACD,oEAAoE;QACpE,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACvF,CAAC;IAED;;;;;;OAMG;IACI,UAAU,CAAC,QAAgB,EAAE,IAAa,EAAE,IAAoB,EAAE,OAAa;QAClF,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YACjD,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;SACzD;QACD,oEAAoE;QACpE,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACpF,CAAC;CACJ;AAxHD,kEAwHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { parse } from \"url\";\nimport {\n IDocumentService,\n IDocumentServiceFactory,\n IDocumentServicePolicies,\n IResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { DefaultTokenProvider } from \"@fluidframework/routerlicious-driver\";\nimport { ILocalDeltaConnectionServer, LocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport {\n ensureFluidResolvedUrl,\n getDocAttributesFromProtocolSummary,\n getQuorumValuesFromProtocolSummary,\n} from \"@fluidframework/driver-utils\";\nimport { ISummaryTree, NackErrorType } from \"@fluidframework/protocol-definitions\";\nimport { defaultHash } from \"@fluidframework/server-services-client\";\nimport { LocalDocumentDeltaConnection } from \"./localDocumentDeltaConnection\";\nimport { createLocalDocumentService } from \"./localDocumentService\";\n\n/**\n * Implementation of document service factory for local use.\n */\nexport class LocalDocumentServiceFactory implements IDocumentServiceFactory {\n public readonly protocolName = \"fluid-test:\";\n\n // A map of clientId to LocalDocumentService.\n private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection> = new Map();\n\n /**\n * @param localDeltaConnectionServer - delta connection server for ops\n */\n constructor(\n private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,\n private readonly policies?: IDocumentServicePolicies,\n private readonly innerDocumentService?: IDocumentService) { }\n\n public async createContainer(\n createNewSummary: ISummaryTree | undefined,\n resolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n ensureFluidResolvedUrl(resolvedUrl);\n if (createNewSummary === undefined) {\n throw new Error(\"Empty file summary creation isn't supported in this driver.\");\n }\n const pathName = new URL(resolvedUrl.url).pathname;\n const pathArr = pathName.split(\"/\");\n const tenantId = pathArr[pathArr.length - 2];\n const id = pathArr[pathArr.length - 1];\n if (!this.localDeltaConnectionServer) {\n throw new Error(\"Provide the localDeltaConnectionServer!!\");\n }\n const documentStorage = (this.localDeltaConnectionServer as LocalDeltaConnectionServer).documentStorage;\n\n const protocolSummary = createNewSummary.tree[\".protocol\"] as ISummaryTree;\n const appSummary = createNewSummary.tree[\".app\"] as ISummaryTree;\n if (!(protocolSummary && appSummary)) {\n throw new Error(\"Protocol and App Summary required in the full summary\");\n }\n const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);\n const quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);\n const sequenceNumber = documentAttributes.sequenceNumber;\n await documentStorage.createDocument(\n tenantId,\n id,\n appSummary,\n sequenceNumber,\n documentAttributes.term ?? 1,\n defaultHash,\n resolvedUrl.endpoints.ordererUrl ?? \"\",\n resolvedUrl.endpoints.storageUrl ?? \"\",\n quorumValues,\n false, /* enableDiscovery */\n );\n return this.createDocumentService(resolvedUrl, logger, clientIsSummarizer);\n }\n\n /**\n * Creates and returns a document service for testing using the given resolved\n * URL for the tenant ID, document ID, and token.\n * @param resolvedUrl - resolved URL of document\n */\n public async createDocumentService(\n resolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n ensureFluidResolvedUrl(resolvedUrl);\n\n const parsedUrl = parse(resolvedUrl.url);\n const [, tenantId, documentId] = parsedUrl.path ? parsedUrl.path.split(\"/\") : [];\n if (!documentId || !tenantId) {\n throw new Error(`Couldn't parse resolved url. [documentId:${documentId}][tenantId:${tenantId}]`);\n }\n\n const fluidResolvedUrl = resolvedUrl;\n const jwtToken = fluidResolvedUrl.tokens.jwt;\n if (!jwtToken) {\n throw new Error(`Token was not provided.`);\n }\n\n const tokenProvider = new DefaultTokenProvider(jwtToken);\n\n return createLocalDocumentService(\n resolvedUrl,\n this.localDeltaConnectionServer,\n tokenProvider,\n tenantId,\n documentId,\n this.documentDeltaConnectionsMap,\n this.policies,\n this.innerDocumentService);\n }\n\n /**\n * Gets the document delta connection for the clientId and asks it to disconnect the client.\n * @param clientId - The ID of the client to be disconnected.\n * @param disconnectReason - The reason of the disconnection.\n */\n public disconnectClient(clientId: string, disconnectReason: string) {\n if (!this.documentDeltaConnectionsMap.has(clientId)) {\n throw new Error(`No client with the id: ${clientId}`);\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.documentDeltaConnectionsMap.get(clientId)!.disconnectClient(disconnectReason);\n }\n\n /**\n * Gets the document delta connection for the clientId and asks it to nack the client.\n * @param clientId - The ID of the client to be Nack'd.\n * @param code - An error code number that represents the error. It will be a valid HTTP error code.\n * @param type - Type of the Nack.\n * @param message - A message about the nack for debugging/logging/telemetry purposes.\n */\n public nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any) {\n if (!this.documentDeltaConnectionsMap.has(clientId)) {\n throw new Error(`No client with the id: ${clientId}`);\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.documentDeltaConnectionsMap.get(clientId)!.nackClient(code, type, message);\n }\n}\n"]}
@@ -5,6 +5,7 @@ import { ITestDbFactory } from "@fluidframework/server-test-utils";
5
5
  */
6
6
  export declare class LocalSessionStorageDbFactory implements ITestDbFactory {
7
7
  readonly testDatabase: IDb;
8
+ constructor(namespace: string);
8
9
  connect(): Promise<IDb>;
9
10
  }
10
11
  //# sourceMappingURL=localSessionStorageDb.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAySnE;;GAEG;AACH,qBAAa,4BAA6B,YAAW,cAAc;IAC/D,SAAgB,YAAY,EAAE,GAAG,CAA+B;IACnD,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGvC"}
1
+ {"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AA4SnE;;GAEG;AACH,qBAAa,4BAA6B,YAAW,cAAc;IAC/D,SAAgB,YAAY,EAAE,GAAG,CAAC;gBACtB,SAAS,EAAE,MAAM;IAGhB,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGvC"}
@@ -12,11 +12,8 @@ const uuid_1 = require("uuid");
12
12
  * Functions include database operations such as queries, insertion and update.
13
13
  */
14
14
  class LocalSessionStorageCollection {
15
- /**
16
- * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.
17
- */
18
- constructor(collectionName) {
19
- this.collectionName = collectionName;
15
+ constructor(namespace, name) {
16
+ this.collectionName = `${namespace}-${name}`;
20
17
  }
21
18
  aggregate(pipeline, options) {
22
19
  throw new Error("Method Not Implemented");
@@ -81,8 +78,7 @@ class LocalSessionStorageCollection {
81
78
  * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}
82
79
  */
83
80
  async findAll() {
84
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
85
- return this.getAllInternal();
81
+ return Promise.resolve(this.getAllInternal());
86
82
  }
87
83
  /**
88
84
  * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}
@@ -91,8 +87,7 @@ class LocalSessionStorageCollection {
91
87
  * Query is expected to have a member "_id" which is a string used to find value in the database.
92
88
  */
93
89
  async findOne(query) {
94
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
95
- return this.findOneInternal(query);
90
+ return Promise.resolve(this.findOneInternal(query));
96
91
  }
97
92
  /**
98
93
  * {@inheritDoc @fluidframework/server-services-core#ICollection.update}
@@ -264,14 +259,17 @@ class LocalSessionStorageCollection {
264
259
  * A database for testing that stores data in the browsers session storage
265
260
  */
266
261
  class LocalSessionStorageDb extends events_1.EventEmitter {
267
- constructor() {
268
- super(...arguments);
262
+ constructor(namespace) {
263
+ super();
264
+ this.namespace = namespace;
269
265
  this.collections = new Map();
270
266
  }
271
- async close() { }
267
+ async close() {
268
+ return Promise.resolve();
269
+ }
272
270
  collection(name) {
273
271
  if (!this.collections.has(name)) {
274
- this.collections.set(name, new LocalSessionStorageCollection(name));
272
+ this.collections.set(name, new LocalSessionStorageCollection(`${this.namespace}-db`, name));
275
273
  }
276
274
  return this.collections.get(name);
277
275
  }
@@ -287,8 +285,8 @@ class LocalSessionStorageDb extends events_1.EventEmitter {
287
285
  * A database factory for testing that stores data in the browsers session storage
288
286
  */
289
287
  class LocalSessionStorageDbFactory {
290
- constructor() {
291
- this.testDatabase = new LocalSessionStorageDb();
288
+ constructor(namespace) {
289
+ this.testDatabase = new LocalSessionStorageDb(namespace);
292
290
  }
293
291
  async connect() {
294
292
  return this.testDatabase;
@@ -1 +1 @@
1
- {"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAAsC;AAGtC,+BAAkC;AAElC;;;GAGG;AACH,MAAM,6BAA6B;IAC/B;;OAEG;IACH,YAA6B,cAAsB;QAAtB,mBAAc,GAAd,cAAc,CAAQ;IAAI,CAAC;IAEjD,SAAS,CAAC,QAAa,EAAE,OAAa;QACzC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAW,EAAE,GAAQ,EAAE,QAAa;QACxD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IACM,KAAK,CAAC,QAAQ,CAAC,GAAQ,EAAE,KAAU;QACtC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH;;;OAGG;IACI,KAAK,CAAC,IAAI,CAAC,KAAU,EAAE,IAAS;QACnC,iDAAiD;QACjD,SAAS,aAAa,CAAC,WAAW,EAAE,GAAW;YAC3C,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,KAAK,GAAG,WAAW,CAAC;YACxB,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACtB,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YACH,+DAA+D;YAC/D,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,kDAAkD;QAClD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAA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,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,6BAA6B,CAAI,IAAI,CAAC,CAAC,CAAC;SAC1E;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAqC,CAAC;IAC1E,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,IAAY;QACpC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC7B,OAAO,IAAI,CAAC;SACf;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAED;;GAEG;AACH,MAAa,4BAA4B;IAAzC;QACoB,iBAAY,GAAQ,IAAI,qBAAqB,EAAE,CAAC;IAIpE,CAAC;IAHU,KAAK,CAAC,OAAO;QAChB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ;AALD,oEAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { ICollection, IDb } from \"@fluidframework/server-services-core\";\nimport { 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 /**\n * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.\n */\n constructor(private readonly collectionName: string) { }\n\n public aggregate(pipeline: any, options?: any): any {\n throw new Error(\"Method Not Implemented\");\n }\n\n public async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n throw new Error(\"Method Not Implemented\");\n }\n public async distinct(key: any, query: any): Promise<any> {\n throw new Error(\"Method Not Implemented\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n */\n /*\n * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n * The hierarchical syntax allows finding nested key patterns.\n */\n public async find(query: any, sort: any): Promise<any[]> {\n // split the keys and get the corresponding value\n function getValueByKey(propertyBag, key: string) {\n const keys = key.split(\".\");\n let value = propertyBag;\n keys.forEach((splitKey) => {\n value = value[splitKey];\n });\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n\n // getting keys of the query we are trying to find\n const queryKeys = Object.keys(query);\n let filteredCollection = this.getAllInternal();\n queryKeys.forEach((key) => {\n if (!query[key]) {\n return;\n }\n if (query[key].$gt > 0 || query[key].$lt > 0) {\n if (query[key].$gt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) > query[key].$gt);\n }\n if (query[key].$lt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) < query[key].$lt);\n }\n } else {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) === query[key]);\n }\n });\n\n if (sort && Object.keys(sort).length === 1) {\n // eslint-disable-next-line no-inner-declarations\n function compare(a, b) {\n const sortKey = Object.keys(sort)[0];\n return sort[sortKey] === 1\n ? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n : getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n }\n\n filteredCollection = filteredCollection.sort(compare);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return filteredCollection;\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n */\n public async findAll(): Promise<any[]> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.getAllInternal();\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async findOne(query: any): Promise<any> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.findOneInternal(query);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async update(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n throw new Error(\"Not found\");\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async upsert(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n this.insertInternal(set);\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n */\n /*\n * Value is expected to have a member \"_id\" which is a string used to search in the database.\n */\n public async insertOne(value: any): Promise<any> {\n const presentVal = this.findOneInternal(value);\n // Only raise error when the object is present and the value is not equal.\n if (presentVal) {\n if (JSON.stringify(presentVal) === JSON.stringify(value)) {\n return;\n }\n throw new Error(\"Existing Object!!\");\n }\n\n return this.insertInternal(value);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n */\n /*\n * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n */\n public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean; }> {\n const existing = this.findOneInternal(query);\n if (existing) {\n return { value: existing, existing: true };\n }\n this.insertInternal(value);\n return { value, existing: false };\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n */\n /*\n * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n */\n public async insertMany(values: any[], ordered: boolean): Promise<void> {\n this.insertInternal(...values);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n */\n public async deleteOne(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n */\n public async deleteMany(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n */\n public async createIndex(index: any, unique: boolean): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Return all values in the database\n */\n private getAllInternal(): any[] {\n const values: string[] = [];\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (key!.startsWith(this.collectionName)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n values.push(JSON.parse(sessionStorage.getItem(key!)!));\n }\n }\n return values;\n }\n\n /**\n * Inserts values into the session storge.\n * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n *\n * @param values - data to insert to the database\n */\n private insertInternal(...values: any[]) {\n for (const value of values) {\n if (value) {\n if (!value._id) {\n value._id = uuid();\n }\n sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n }\n }\n }\n\n /**\n * Finds the query in session storage and returns its value.\n * Returns null if query is not found.\n * Query is expected to have a member \"_id\" which is a unique id.\n *\n * @param query - what to find in the database\n */\n private findOneInternal(query: any): any {\n if (query._id) {\n const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n if (json) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(json);\n }\n } else {\n const queryKeys = Object.keys(query);\n for (let i = 0; i < sessionStorage.length; i++) {\n const ssKey = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (!ssKey!.startsWith(this.collectionName)) {\n continue;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n let foundMismatch = false;\n for (const qk of queryKeys) {\n if (value[qk] !== query[qk]) {\n foundMismatch = true;\n break;\n }\n }\n\n if (!foundMismatch) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n }\n }\n return null;\n }\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n public async close(): Promise<void> { }\n public collection<T>(name: string): ICollection<T> {\n if (!this.collections.has(name)) {\n this.collections.set(name, new LocalSessionStorageCollection<T>(name));\n }\n return this.collections.get(name) as LocalSessionStorageCollection<T>;\n }\n\n public async dropCollection(name: string): Promise<boolean> {\n if (!this.collections.has(name)) {\n return true;\n }\n this.collections.delete(name);\n return true;\n }\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n public readonly testDatabase: IDb = new LocalSessionStorageDb();\n public async connect(): Promise<IDb> {\n return this.testDatabase;\n }\n}\n"]}
1
+ {"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAAsC;AAGtC,+BAAkC;AAElC;;;GAGG;AACH,MAAM,6BAA6B;IAE/B,YAAY,SAAS,EAAE,IAAI;QACvB,IAAI,CAAC,cAAc,GAAG,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;IACjD,CAAC;IAEM,SAAS,CAAC,QAAa,EAAE,OAAa;QACzC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAW,EAAE,GAAQ,EAAE,QAAa;QACxD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IACM,KAAK,CAAC,QAAQ,CAAC,GAAQ,EAAE,KAAU;QACtC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH;;;OAGG;IACI,KAAK,CAAC,IAAI,CAAC,KAA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,OAAO;QAChB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ;AARD,oEAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { ICollection, IDb } from \"@fluidframework/server-services-core\";\nimport { 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 private readonly collectionName: string;\n constructor(namespace, name) {\n this.collectionName = `${namespace}-${name}`;\n }\n\n public aggregate(pipeline: any, options?: any): any {\n throw new Error(\"Method Not Implemented\");\n }\n\n public async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n throw new Error(\"Method Not Implemented\");\n }\n public async distinct(key: any, query: any): Promise<any> {\n throw new Error(\"Method Not Implemented\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n */\n /*\n * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n * The hierarchical syntax allows finding nested key patterns.\n */\n public async find(query: any, sort: any): Promise<any[]> {\n // split the keys and get the corresponding value\n function getValueByKey(propertyBag, key: string) {\n const keys = key.split(\".\");\n let value = propertyBag;\n keys.forEach((splitKey) => {\n value = value[splitKey];\n });\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n\n // getting keys of the query we are trying to find\n const queryKeys = Object.keys(query);\n let filteredCollection = this.getAllInternal();\n queryKeys.forEach((key) => {\n if (!query[key]) {\n return;\n }\n if (query[key].$gt > 0 || query[key].$lt > 0) {\n if (query[key].$gt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) > query[key].$gt);\n }\n if (query[key].$lt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) < query[key].$lt);\n }\n } else {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) === query[key]);\n }\n });\n\n if (sort && Object.keys(sort).length === 1) {\n // eslint-disable-next-line no-inner-declarations\n function compare(a, b) {\n const sortKey = Object.keys(sort)[0];\n return sort[sortKey] === 1\n ? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n : getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n }\n\n filteredCollection = filteredCollection.sort(compare);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return filteredCollection;\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n */\n public async findAll(): Promise<any[]> {\n return Promise.resolve(this.getAllInternal());\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async findOne(query: any): Promise<any> {\n return Promise.resolve(this.findOneInternal(query));\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async update(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n throw new Error(\"Not found\");\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async upsert(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n this.insertInternal(set);\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n */\n /*\n * Value is expected to have a member \"_id\" which is a string used to search in the database.\n */\n public async insertOne(value: any): Promise<any> {\n const presentVal = this.findOneInternal(value);\n // Only raise error when the object is present and the value is not equal.\n if (presentVal) {\n if (JSON.stringify(presentVal) === JSON.stringify(value)) {\n return;\n }\n throw new Error(\"Existing Object!!\");\n }\n\n return this.insertInternal(value);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n */\n /*\n * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n */\n public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean; }> {\n const existing = this.findOneInternal(query);\n if (existing) {\n return { value: existing, existing: true };\n }\n this.insertInternal(value);\n return { value, existing: false };\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n */\n /*\n * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n */\n public async insertMany(values: any[], ordered: boolean): Promise<void> {\n this.insertInternal(...values);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n */\n public async deleteOne(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n */\n public async deleteMany(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n */\n public async createIndex(index: any, unique: boolean): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Return all values in the database\n */\n private getAllInternal(): any[] {\n const values: string[] = [];\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (key!.startsWith(this.collectionName)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n values.push(JSON.parse(sessionStorage.getItem(key!)!));\n }\n }\n return values;\n }\n\n /**\n * Inserts values into the session storge.\n * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n *\n * @param values - data to insert to the database\n */\n private insertInternal(...values: any[]) {\n for (const value of values) {\n if (value) {\n if (!value._id) {\n value._id = uuid();\n }\n sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n }\n }\n }\n\n /**\n * Finds the query in session storage and returns its value.\n * Returns null if query is not found.\n * Query is expected to have a member \"_id\" which is a unique id.\n *\n * @param query - what to find in the database\n */\n private findOneInternal(query: any): any {\n if (query._id) {\n const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n if (json) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(json);\n }\n } else {\n const queryKeys = Object.keys(query);\n for (let i = 0; i < sessionStorage.length; i++) {\n const ssKey = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (!ssKey!.startsWith(this.collectionName)) {\n continue;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n let foundMismatch = false;\n for (const qk of queryKeys) {\n if (value[qk] !== query[qk]) {\n foundMismatch = true;\n break;\n }\n }\n\n if (!foundMismatch) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n }\n }\n return null;\n }\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n constructor(private readonly namespace) {\n super();\n }\n public async close(): Promise<void> {\n return Promise.resolve();\n }\n public collection<T>(name: string): ICollection<T> {\n if (!this.collections.has(name)) {\n this.collections.set(name, new LocalSessionStorageCollection<T>(`${this.namespace}-db`, name));\n }\n return this.collections.get(name) as LocalSessionStorageCollection<T>;\n }\n\n public async dropCollection(name: string): Promise<boolean> {\n if (!this.collections.has(name)) {\n return true;\n }\n this.collections.delete(name);\n return true;\n }\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n public readonly testDatabase: IDb;\n constructor(namespace: string) {\n this.testDatabase = new LocalSessionStorageDb(namespace);\n }\n public async connect(): Promise<IDb> {\n return this.testDatabase;\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/local-driver";
8
- export declare const pkgVersion = "2.0.0-dev.1.3.0.96595";
8
+ export declare const pkgVersion = "2.0.0-dev.1.4.5.105745";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,0BAA0B,CAAC"}
1
+ {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,2BAA2B,CAAC"}
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/local-driver";
11
- exports.pkgVersion = "2.0.0-dev.1.3.0.96595";
11
+ exports.pkgVersion = "2.0.0-dev.1.4.5.105745";
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,uBAAuB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/local-driver\";\nexport const pkgVersion = \"2.0.0-dev.1.3.0.96595\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,wBAAwB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/local-driver\";\nexport const pkgVersion = \"2.0.0-dev.1.4.5.105745\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/local-driver",
3
- "version": "2.0.0-dev.1.3.0.96595",
3
+ "version": "2.0.0-dev.1.4.5.105745",
4
4
  "description": "Fluid local driver",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -58,12 +58,12 @@
58
58
  "dependencies": {
59
59
  "@fluidframework/common-definitions": "^0.20.1",
60
60
  "@fluidframework/common-utils": "^1.0.0",
61
- "@fluidframework/core-interfaces": "2.0.0-dev.1.3.0.96595",
62
- "@fluidframework/driver-base": "2.0.0-dev.1.3.0.96595",
63
- "@fluidframework/driver-definitions": "2.0.0-dev.1.3.0.96595",
64
- "@fluidframework/driver-utils": "2.0.0-dev.1.3.0.96595",
61
+ "@fluidframework/core-interfaces": "2.0.0-dev.1.4.5.105745",
62
+ "@fluidframework/driver-base": "2.0.0-dev.1.4.5.105745",
63
+ "@fluidframework/driver-definitions": "2.0.0-dev.1.4.5.105745",
64
+ "@fluidframework/driver-utils": "2.0.0-dev.1.4.5.105745",
65
65
  "@fluidframework/protocol-definitions": "^1.0.0",
66
- "@fluidframework/routerlicious-driver": "2.0.0-dev.1.3.0.96595",
66
+ "@fluidframework/routerlicious-driver": "2.0.0-dev.1.4.5.105745",
67
67
  "@fluidframework/server-local-server": "^0.1037.2001",
68
68
  "@fluidframework/server-services-client": "^0.1037.2001",
69
69
  "@fluidframework/server-services-core": "^0.1037.2001",
@@ -75,7 +75,7 @@
75
75
  "@fluidframework/build-common": "^1.0.0",
76
76
  "@fluidframework/eslint-config-fluid": "^1.0.0",
77
77
  "@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@^1.0.0",
78
- "@fluidframework/mocha-test-setup": "2.0.0-dev.1.3.0.96595",
78
+ "@fluidframework/mocha-test-setup": "2.0.0-dev.1.4.5.105745",
79
79
  "@rushstack/eslint-config": "^2.5.1",
80
80
  "@types/jsrsasign": "^8.0.8",
81
81
  "@types/mocha": "^9.1.1",
@@ -3,10 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import {
7
- IDocumentDeltaStorageService,
8
- IStream,
9
- } from "@fluidframework/driver-definitions";
6
+ import * as api from "@fluidframework/driver-definitions";
10
7
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
11
8
  import { IDatabaseManager } from "@fluidframework/server-services-core";
12
9
  import { streamFromMessages } from "@fluidframework/driver-utils";
@@ -14,7 +11,7 @@ import { streamFromMessages } from "@fluidframework/driver-utils";
14
11
  /**
15
12
  * Provides access to the underlying delta storage on the server for local driver.
16
13
  */
17
- export class LocalDeltaStorageService implements IDocumentDeltaStorageService {
14
+ export class LocalDeltaStorageService implements api.IDocumentDeltaStorageService {
18
15
  constructor(
19
16
  private readonly tenantId: string,
20
17
  private readonly id: string,
@@ -26,7 +23,7 @@ export class LocalDeltaStorageService implements IDocumentDeltaStorageService {
26
23
  to: number | undefined,
27
24
  abortSignal?: AbortSignal,
28
25
  cachedOnly?: boolean,
29
- ): IStream<ISequencedDocumentMessage[]> {
26
+ ): api.IStream<ISequencedDocumentMessage[]> {
30
27
  return streamFromMessages(this.getCore(from, to));
31
28
  }
32
29
 
@@ -12,7 +12,7 @@ import {
12
12
  NackErrorType,
13
13
  } from "@fluidframework/protocol-definitions";
14
14
  import { LocalWebSocketServer } from "@fluidframework/server-local-server";
15
- import { IWebSocketServer } from "@fluidframework/server-services-core";
15
+ import * as core from "@fluidframework/server-services-core";
16
16
  import type { Socket } from "socket.io-client";
17
17
 
18
18
  const testProtocolVersions = ["^0.3.0", "^0.2.0", "^0.1.0"];
@@ -36,7 +36,7 @@ export class LocalDocumentDeltaConnection extends DocumentDeltaConnection {
36
36
  id: string,
37
37
  token: string,
38
38
  client: IClient,
39
- webSocketServer: IWebSocketServer,
39
+ webSocketServer: core.IWebSocketServer,
40
40
  timeoutMs = 60000,
41
41
  ): Promise<LocalDocumentDeltaConnection> {
42
42
  const socket = (webSocketServer as LocalWebSocketServer).createConnection();
@@ -3,19 +3,9 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import {
7
- IDocumentDeltaConnection,
8
- IDocumentDeltaStorageService,
9
- IDocumentService,
10
- IDocumentServicePolicies,
11
- IDocumentStorageService,
12
- IResolvedUrl,
13
- } from "@fluidframework/driver-definitions";
6
+ import * as api from "@fluidframework/driver-definitions";
14
7
  import { IClient } from "@fluidframework/protocol-definitions";
15
- import {
16
- DocumentStorageService,
17
- ITokenProvider,
18
- } from "@fluidframework/routerlicious-driver";
8
+ import * as socketStorage from "@fluidframework/routerlicious-driver";
19
9
  import { GitManager } from "@fluidframework/server-services-client";
20
10
  import { TestHistorian } from "@fluidframework/server-test-utils";
21
11
  import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
@@ -25,7 +15,7 @@ import { LocalDeltaStorageService, LocalDocumentDeltaConnection } from ".";
25
15
  /**
26
16
  * Basic implementation of a document service for local use.
27
17
  */
28
- export class LocalDocumentService implements IDocumentService {
18
+ export class LocalDocumentService implements api.IDocumentService {
29
19
  /**
30
20
  * @param localDeltaConnectionServer - delta connection server for ops
31
21
  * @param tokenProvider - token provider
@@ -33,14 +23,14 @@ export class LocalDocumentService implements IDocumentService {
33
23
  * @param documentId - ID of document
34
24
  */
35
25
  constructor(
36
- public readonly resolvedUrl: IResolvedUrl,
26
+ public readonly resolvedUrl: api.IResolvedUrl,
37
27
  private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,
38
- private readonly tokenProvider: ITokenProvider,
28
+ private readonly tokenProvider: socketStorage.ITokenProvider,
39
29
  private readonly tenantId: string,
40
30
  private readonly documentId: string,
41
31
  private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,
42
- public readonly policies: IDocumentServicePolicies = {},
43
- private readonly innerDocumentService?: IDocumentService,
32
+ public readonly policies: api.IDocumentServicePolicies = {},
33
+ private readonly innerDocumentService?: api.IDocumentService,
44
34
  ) { }
45
35
 
46
36
  public dispose() { }
@@ -48,8 +38,8 @@ export class LocalDocumentService implements IDocumentService {
48
38
  /**
49
39
  * Creates and returns a document storage service for local use.
50
40
  */
51
- public async connectToStorage(): Promise<IDocumentStorageService> {
52
- return new DocumentStorageService(
41
+ public async connectToStorage(): Promise<api.IDocumentStorageService> {
42
+ return new socketStorage.DocumentStorageService(
53
43
  this.documentId,
54
44
  new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)),
55
45
  new TelemetryNullLogger(),
@@ -63,7 +53,7 @@ export class LocalDocumentService implements IDocumentService {
63
53
  /**
64
54
  * Creates and returns a delta storage service for local use.
65
55
  */
66
- public async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {
56
+ public async connectToDeltaStorage(): Promise<api.IDocumentDeltaStorageService> {
67
57
  if (this.innerDocumentService) {
68
58
  return this.innerDocumentService.connectToDeltaStorage();
69
59
  }
@@ -77,7 +67,7 @@ export class LocalDocumentService implements IDocumentService {
77
67
  * Creates and returns a delta stream for local use.
78
68
  * @param client - client data
79
69
  */
80
- public async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {
70
+ public async connectToDeltaStream(client: IClient): Promise<api.IDocumentDeltaConnection> {
81
71
  if (this.policies.storageOnly === true) {
82
72
  throw new Error("can't connect to delta stream in storage-only mode");
83
73
  }
@@ -117,14 +107,14 @@ export class LocalDocumentService implements IDocumentService {
117
107
  * @param documentId - ID of document
118
108
  */
119
109
  export function createLocalDocumentService(
120
- resolvedUrl: IResolvedUrl,
110
+ resolvedUrl: api.IResolvedUrl,
121
111
  localDeltaConnectionServer: ILocalDeltaConnectionServer,
122
- tokenProvider: ITokenProvider,
112
+ tokenProvider: socketStorage.ITokenProvider,
123
113
  tenantId: string,
124
114
  documentId: string,
125
115
  documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,
126
- policies?: IDocumentServicePolicies,
127
- innerDocumentService?: IDocumentService): IDocumentService {
116
+ policies?: api.IDocumentServicePolicies,
117
+ innerDocumentService?: api.IDocumentService): api.IDocumentService {
128
118
  return new LocalDocumentService(
129
119
  resolvedUrl,
130
120
  localDeltaConnectionServer,
@@ -125,11 +125,11 @@ export class LocalDocumentServiceFactory implements IDocumentServiceFactory {
125
125
  * @param disconnectReason - The reason of the disconnection.
126
126
  */
127
127
  public disconnectClient(clientId: string, disconnectReason: string) {
128
- const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
129
- if (documentDeltaConnection === undefined) {
128
+ if (!this.documentDeltaConnectionsMap.has(clientId)) {
130
129
  throw new Error(`No client with the id: ${clientId}`);
131
130
  }
132
- documentDeltaConnection.disconnectClient(disconnectReason);
131
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
132
+ this.documentDeltaConnectionsMap.get(clientId)!.disconnectClient(disconnectReason);
133
133
  }
134
134
 
135
135
  /**
@@ -140,10 +140,10 @@ export class LocalDocumentServiceFactory implements IDocumentServiceFactory {
140
140
  * @param message - A message about the nack for debugging/logging/telemetry purposes.
141
141
  */
142
142
  public nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any) {
143
- const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
144
- if (documentDeltaConnection === undefined) {
143
+ if (!this.documentDeltaConnectionsMap.has(clientId)) {
145
144
  throw new Error(`No client with the id: ${clientId}`);
146
145
  }
147
- documentDeltaConnection.nackClient(code, type, message);
146
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
147
+ this.documentDeltaConnectionsMap.get(clientId)!.nackClient(code, type, message);
148
148
  }
149
149
  }
@@ -12,10 +12,10 @@ import { v4 as uuid } from "uuid";
12
12
  * Functions include database operations such as queries, insertion and update.
13
13
  */
14
14
  class LocalSessionStorageCollection<T> implements ICollection<T> {
15
- /**
16
- * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.
17
- */
18
- constructor(private readonly collectionName: string) { }
15
+ private readonly collectionName: string;
16
+ constructor(namespace, name) {
17
+ this.collectionName = `${namespace}-${name}`;
18
+ }
19
19
 
20
20
  public aggregate(pipeline: any, options?: any): any {
21
21
  throw new Error("Method Not Implemented");
@@ -88,8 +88,7 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
88
88
  * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}
89
89
  */
90
90
  public async findAll(): Promise<any[]> {
91
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
92
- return this.getAllInternal();
91
+ return Promise.resolve(this.getAllInternal());
93
92
  }
94
93
 
95
94
  /**
@@ -99,8 +98,7 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
99
98
  * Query is expected to have a member "_id" which is a string used to find value in the database.
100
99
  */
101
100
  public async findOne(query: any): Promise<any> {
102
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
103
- return this.findOneInternal(query);
101
+ return Promise.resolve(this.findOneInternal(query));
104
102
  }
105
103
 
106
104
  /**
@@ -284,10 +282,15 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
284
282
  */
285
283
  class LocalSessionStorageDb extends EventEmitter implements IDb {
286
284
  private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();
287
- public async close(): Promise<void> { }
285
+ constructor(private readonly namespace) {
286
+ super();
287
+ }
288
+ public async close(): Promise<void> {
289
+ return Promise.resolve();
290
+ }
288
291
  public collection<T>(name: string): ICollection<T> {
289
292
  if (!this.collections.has(name)) {
290
- this.collections.set(name, new LocalSessionStorageCollection<T>(name));
293
+ this.collections.set(name, new LocalSessionStorageCollection<T>(`${this.namespace}-db`, name));
291
294
  }
292
295
  return this.collections.get(name) as LocalSessionStorageCollection<T>;
293
296
  }
@@ -305,7 +308,10 @@ class LocalSessionStorageDb extends EventEmitter implements IDb {
305
308
  * A database factory for testing that stores data in the browsers session storage
306
309
  */
307
310
  export class LocalSessionStorageDbFactory implements ITestDbFactory {
308
- public readonly testDatabase: IDb = new LocalSessionStorageDb();
311
+ public readonly testDatabase: IDb;
312
+ constructor(namespace: string) {
313
+ this.testDatabase = new LocalSessionStorageDb(namespace);
314
+ }
309
315
  public async connect(): Promise<IDb> {
310
316
  return this.testDatabase;
311
317
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/local-driver";
9
- export const pkgVersion = "2.0.0-dev.1.3.0.96595";
9
+ export const pkgVersion = "2.0.0-dev.1.4.5.105745";