@fluidframework/local-driver 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.eslintrc.js +19 -22
  2. package/.mocharc.js +2 -2
  3. package/dist/auth.d.ts.map +1 -1
  4. package/dist/auth.js +2 -2
  5. package/dist/auth.js.map +1 -1
  6. package/dist/localDeltaStorageService.d.ts.map +1 -1
  7. package/dist/localDeltaStorageService.js.map +1 -1
  8. package/dist/localDocumentDeltaConnection.d.ts.map +1 -1
  9. package/dist/localDocumentDeltaConnection.js.map +1 -1
  10. package/dist/localDocumentService.d.ts.map +1 -1
  11. package/dist/localDocumentService.js.map +1 -1
  12. package/dist/localDocumentServiceFactory.d.ts.map +1 -1
  13. package/dist/localDocumentServiceFactory.js +3 -2
  14. package/dist/localDocumentServiceFactory.js.map +1 -1
  15. package/dist/localDocumentStorageService.d.ts.map +1 -1
  16. package/dist/localDocumentStorageService.js +4 -3
  17. package/dist/localDocumentStorageService.js.map +1 -1
  18. package/dist/localResolver.d.ts.map +1 -1
  19. package/dist/localResolver.js.map +1 -1
  20. package/dist/localSessionStorageDb.d.ts.map +1 -1
  21. package/dist/localSessionStorageDb.js.map +1 -1
  22. package/dist/packageVersion.d.ts +1 -1
  23. package/dist/packageVersion.js +1 -1
  24. package/dist/packageVersion.js.map +1 -1
  25. package/package.json +37 -36
  26. package/prettier.config.cjs +1 -1
  27. package/src/auth.ts +35 -29
  28. package/src/localDeltaStorageService.ts +26 -29
  29. package/src/localDocumentDeltaConnection.ts +89 -85
  30. package/src/localDocumentService.ts +106 -98
  31. package/src/localDocumentServiceFactory.ts +126 -117
  32. package/src/localDocumentStorageService.ts +17 -10
  33. package/src/localResolver.ts +55 -55
  34. package/src/localSessionStorageDb.ts +267 -261
  35. package/src/packageVersion.ts +1 -1
  36. package/tsconfig.json +9 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/local-driver",
3
- "version": "2.0.0-internal.3.0.2",
3
+ "version": "2.0.0-internal.3.2.0",
4
4
  "description": "Fluid local driver",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -15,27 +15,6 @@
15
15
  "moniker": "@fluidframework/server-services-client/dist/generateNames.js"
16
16
  },
17
17
  "types": "dist/index.d.ts",
18
- "scripts": {
19
- "build": "npm run build:genver && concurrently npm:build:compile npm:lint",
20
- "build:compile": "npm run tsc && npm run build:test",
21
- "build:full": "npm run build",
22
- "build:full:compile": "npm run build:compile",
23
- "build:genver": "gen-version",
24
- "build:test": "tsc --project ./src/test/tsconfig.json",
25
- "clean": "rimraf dist lib *.tsbuildinfo *.build.log",
26
- "eslint": "eslint --format stylish src",
27
- "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
28
- "format": "npm run prettier:fix",
29
- "lint": "npm run eslint",
30
- "lint:fix": "npm run eslint:fix",
31
- "prettier": "prettier --check . --ignore-path ../../../.prettierignore",
32
- "prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
33
- "test": "npm run test:mocha",
34
- "test:coverage": "nyc npm test -- --reporter xunit --reporter-option output=nyc/junit-report.xml",
35
- "test:mocha": "mocha --ignore 'dist/test/types/*' --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup --unhandled-rejections=strict",
36
- "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
37
- "tsc": "tsc"
38
- },
39
18
  "nyc": {
40
19
  "all": true,
41
20
  "cache-dir": "nyc/.cache",
@@ -58,30 +37,30 @@
58
37
  },
59
38
  "dependencies": {
60
39
  "@fluidframework/common-definitions": "^0.20.1",
61
- "@fluidframework/common-utils": "^1.0.0",
62
- "@fluidframework/core-interfaces": ">=2.0.0-internal.3.0.2 <2.0.0-internal.4.0.0",
63
- "@fluidframework/driver-base": ">=2.0.0-internal.3.0.2 <2.0.0-internal.4.0.0",
64
- "@fluidframework/driver-definitions": ">=2.0.0-internal.3.0.2 <2.0.0-internal.4.0.0",
65
- "@fluidframework/driver-utils": ">=2.0.0-internal.3.0.2 <2.0.0-internal.4.0.0",
40
+ "@fluidframework/common-utils": "^1.1.1",
41
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.3.2.0 <2.0.0-internal.4.0.0",
42
+ "@fluidframework/driver-base": ">=2.0.0-internal.3.2.0 <2.0.0-internal.4.0.0",
43
+ "@fluidframework/driver-definitions": ">=2.0.0-internal.3.2.0 <2.0.0-internal.4.0.0",
44
+ "@fluidframework/driver-utils": ">=2.0.0-internal.3.2.0 <2.0.0-internal.4.0.0",
66
45
  "@fluidframework/protocol-base": "^0.1038.2000",
67
46
  "@fluidframework/protocol-definitions": "^1.1.0",
68
- "@fluidframework/routerlicious-driver": ">=2.0.0-internal.3.0.2 <2.0.0-internal.4.0.0",
47
+ "@fluidframework/routerlicious-driver": ">=2.0.0-internal.3.2.0 <2.0.0-internal.4.0.0",
69
48
  "@fluidframework/server-local-server": "^0.1038.2000",
70
49
  "@fluidframework/server-services-client": "^0.1038.2000",
71
50
  "@fluidframework/server-services-core": "^0.1038.2000",
72
51
  "@fluidframework/server-test-utils": "^0.1038.2000",
73
- "@fluidframework/telemetry-utils": ">=2.0.0-internal.3.0.2 <2.0.0-internal.4.0.0",
52
+ "@fluidframework/telemetry-utils": ">=2.0.0-internal.3.2.0 <2.0.0-internal.4.0.0",
74
53
  "events": "^3.1.0",
75
54
  "jsrsasign": "^10.5.25",
76
55
  "url": "^0.11.0",
77
56
  "uuid": "^8.3.1"
78
57
  },
79
58
  "devDependencies": {
80
- "@fluid-tools/build-cli": "^0.8.0",
59
+ "@fluid-tools/build-cli": "^0.10.0",
81
60
  "@fluidframework/build-common": "^1.1.0",
82
61
  "@fluidframework/eslint-config-fluid": "^2.0.0",
83
- "@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@2.0.0-internal.3.0.0",
84
- "@fluidframework/mocha-test-setup": ">=2.0.0-internal.3.0.2 <2.0.0-internal.4.0.0",
62
+ "@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@2.0.0-internal.3.1.0",
63
+ "@fluidframework/mocha-test-setup": ">=2.0.0-internal.3.2.0 <2.0.0-internal.4.0.0",
85
64
  "@rushstack/eslint-config": "^2.5.1",
86
65
  "@types/jsrsasign": "^8.0.8",
87
66
  "@types/mocha": "^9.1.1",
@@ -97,9 +76,31 @@
97
76
  "typescript": "~4.5.5"
98
77
  },
99
78
  "typeValidation": {
100
- "version": "2.0.0-internal.3.0.1",
101
- "previousVersionStyle": "previousPatch",
102
- "baselineRange": "2.0.0-internal.3.0.0",
79
+ "version": "2.0.0-internal.3.2.0",
80
+ "previousVersionStyle": "~previousMinor",
81
+ "baselineRange": ">=2.0.0-internal.3.1.0 <2.0.0-internal.3.2.0",
82
+ "baselineVersion": "2.0.0-internal.3.1.0",
103
83
  "broken": {}
84
+ },
85
+ "scripts": {
86
+ "build": "npm run build:genver && concurrently npm:build:compile npm:lint",
87
+ "build:compile": "npm run tsc && npm run build:test",
88
+ "build:full": "npm run build",
89
+ "build:full:compile": "npm run build:compile",
90
+ "build:genver": "gen-version",
91
+ "build:test": "tsc --project ./src/test/tsconfig.json",
92
+ "clean": "rimraf dist lib *.tsbuildinfo *.build.log",
93
+ "eslint": "eslint --format stylish src",
94
+ "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
95
+ "format": "npm run prettier:fix",
96
+ "lint": "npm run prettier && npm run eslint",
97
+ "lint:fix": "npm run prettier:fix && npm run eslint:fix",
98
+ "prettier": "prettier --check . --ignore-path ../../../.prettierignore",
99
+ "prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
100
+ "test": "npm run test:mocha",
101
+ "test:coverage": "nyc npm test -- --reporter xunit --reporter-option output=nyc/junit-report.xml",
102
+ "test:mocha": "mocha --ignore 'dist/test/types/*' --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup --unhandled-rejections=strict",
103
+ "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
104
+ "tsc": "tsc"
104
105
  }
105
- }
106
+ }
@@ -4,5 +4,5 @@
4
4
  */
5
5
 
6
6
  module.exports = {
7
- ...require("@fluidframework/build-common/prettier.config.cjs"),
7
+ ...require("@fluidframework/build-common/prettier.config.cjs"),
8
8
  };
package/src/auth.ts CHANGED
@@ -13,40 +13,46 @@ import { getRandomName } from "@fluidframework/server-services-client";
13
13
  * services-client since it cannot run in the browser without polyfills.
14
14
  */
15
15
  export function generateToken(
16
- tenantId: string,
17
- documentId: string,
18
- key: string,
19
- scopes: ScopeType[],
20
- user?: IUser,
21
- lifetime: number = 60 * 60,
22
- ver: string = "1.0"): string {
23
- let userClaim = (user) ? user : generateUser();
24
- if (userClaim.id === "" || userClaim.id === undefined) {
25
- userClaim = generateUser();
26
- }
16
+ tenantId: string,
17
+ documentId: string,
18
+ key: string,
19
+ scopes: ScopeType[],
20
+ user?: IUser,
21
+ lifetime: number = 60 * 60,
22
+ ver: string = "1.0",
23
+ ): string {
24
+ let userClaim = user ? user : generateUser();
25
+ if (userClaim.id === "" || userClaim.id === undefined) {
26
+ userClaim = generateUser();
27
+ }
27
28
 
28
- // Current time in seconds
29
- const now = Math.round((new Date()).getTime() / 1000);
29
+ // Current time in seconds
30
+ const now = Math.round(new Date().getTime() / 1000);
30
31
 
31
- const claims: ITokenClaims = {
32
- documentId,
33
- scopes,
34
- tenantId,
35
- user: userClaim,
36
- iat: now,
37
- exp: now + lifetime,
38
- ver,
39
- };
32
+ const claims: ITokenClaims = {
33
+ documentId,
34
+ scopes,
35
+ tenantId,
36
+ user: userClaim,
37
+ iat: now,
38
+ exp: now + lifetime,
39
+ ver,
40
+ };
40
41
 
41
- const utf8Key = { utf8: key };
42
- return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg: "HS256", typ: "JWT" }), claims, utf8Key);
42
+ const utf8Key = { utf8: key };
43
+ return jsrsasign.jws.JWS.sign(
44
+ null,
45
+ JSON.stringify({ alg: "HS256", typ: "JWT" }),
46
+ claims,
47
+ utf8Key,
48
+ );
43
49
  }
44
50
 
45
51
  export function generateUser(): IUser {
46
- const randomUser = {
47
- id: uuid(),
48
- name: getRandomName(" ", true),
49
- };
52
+ const randomUser = {
53
+ id: uuid(),
54
+ name: getRandomName(" ", true),
55
+ };
50
56
 
51
- return randomUser;
57
+ return randomUser;
52
58
  }
@@ -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 { IDocumentDeltaStorageService, IStream } 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";
@@ -15,33 +12,33 @@ import { streamFromMessages } from "@fluidframework/driver-utils";
15
12
  * Provides access to the underlying delta storage on the server for local driver.
16
13
  */
17
14
  export class LocalDeltaStorageService implements IDocumentDeltaStorageService {
18
- constructor(
19
- private readonly tenantId: string,
20
- private readonly id: string,
21
- private readonly databaseManager: IDatabaseManager) {
22
- }
15
+ constructor(
16
+ private readonly tenantId: string,
17
+ private readonly id: string,
18
+ private readonly databaseManager: IDatabaseManager,
19
+ ) {}
23
20
 
24
- public fetchMessages(
25
- from: number,
26
- to: number | undefined,
27
- abortSignal?: AbortSignal,
28
- cachedOnly?: boolean,
29
- ): IStream<ISequencedDocumentMessage[]> {
30
- return streamFromMessages(this.getCore(from, to));
31
- }
21
+ public fetchMessages(
22
+ from: number,
23
+ to: number | undefined,
24
+ abortSignal?: AbortSignal,
25
+ cachedOnly?: boolean,
26
+ ): IStream<ISequencedDocumentMessage[]> {
27
+ return streamFromMessages(this.getCore(from, to));
28
+ }
32
29
 
33
- private async getCore(from: number, to?: number) {
34
- const query = { documentId: this.id, tenantId: this.tenantId };
35
- query["operation.sequenceNumber"] = {};
36
- query["operation.sequenceNumber"].$gt = from - 1; // from is inclusive
30
+ private async getCore(from: number, to?: number) {
31
+ const query = { documentId: this.id, tenantId: this.tenantId };
32
+ query["operation.sequenceNumber"] = {};
33
+ query["operation.sequenceNumber"].$gt = from - 1; // from is inclusive
37
34
 
38
- // This looks like a bug. It used to work without setting $lt key. Now it does not
39
- // Need follow up
40
- query["operation.sequenceNumber"].$lt = to ?? Number.MAX_SAFE_INTEGER;
35
+ // This looks like a bug. It used to work without setting $lt key. Now it does not
36
+ // Need follow up
37
+ query["operation.sequenceNumber"].$lt = to ?? Number.MAX_SAFE_INTEGER;
41
38
 
42
- const allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);
43
- const dbDeltas = await allDeltas.find(query, { "operation.sequenceNumber": 1 });
44
- const messages = dbDeltas.map((delta) => delta.operation);
45
- return messages;
46
- }
39
+ const allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);
40
+ const dbDeltas = await allDeltas.find(query, { "operation.sequenceNumber": 1 });
41
+ const messages = dbDeltas.map((delta) => delta.operation);
42
+ return messages;
43
+ }
47
44
  }
@@ -5,10 +5,10 @@
5
5
 
6
6
  import { DocumentDeltaConnection } from "@fluidframework/driver-base";
7
7
  import {
8
- IClient,
9
- IConnect,
10
- IDocumentMessage,
11
- NackErrorType,
8
+ IClient,
9
+ IConnect,
10
+ IDocumentMessage,
11
+ NackErrorType,
12
12
  } from "@fluidframework/protocol-definitions";
13
13
  import { TelemetryNullLogger } from "@fluidframework/telemetry-utils";
14
14
  import { LocalWebSocketServer } from "@fluidframework/server-local-server";
@@ -21,94 +21,98 @@ const testProtocolVersions = ["^0.3.0", "^0.2.0", "^0.1.0"];
21
21
  * Represents a connection to a stream of delta updates
22
22
  */
23
23
  export class LocalDocumentDeltaConnection extends DocumentDeltaConnection {
24
- /**
25
- * Create a LocalDocumentDeltaConnection
26
- * Handle initial messages, contents or signals if they were in queue
27
- *
28
- * @param tenantId - the ID of the tenant
29
- * @param id - document ID
30
- * @param token - authorization token for storage service
31
- * @param client - information about the client
32
- * @param webSocketServer - web socket server to create connection
33
- */
34
- public static async create(
35
- tenantId: string,
36
- id: string,
37
- token: string,
38
- client: IClient,
39
- webSocketServer: IWebSocketServer,
40
- timeoutMs = 60000,
41
- ): Promise<LocalDocumentDeltaConnection> {
42
- const socket = (webSocketServer as LocalWebSocketServer).createConnection();
24
+ /**
25
+ * Create a LocalDocumentDeltaConnection
26
+ * Handle initial messages, contents or signals if they were in queue
27
+ *
28
+ * @param tenantId - the ID of the tenant
29
+ * @param id - document ID
30
+ * @param token - authorization token for storage service
31
+ * @param client - information about the client
32
+ * @param webSocketServer - web socket server to create connection
33
+ */
34
+ public static async create(
35
+ tenantId: string,
36
+ id: string,
37
+ token: string,
38
+ client: IClient,
39
+ webSocketServer: IWebSocketServer,
40
+ timeoutMs = 60000,
41
+ ): Promise<LocalDocumentDeltaConnection> {
42
+ const socket = (webSocketServer as LocalWebSocketServer).createConnection();
43
43
 
44
- // Cast LocalWebSocket to SocketIOClient.Socket which is the socket that the base class needs. This is hacky
45
- // but should be fine because this delta connection is for local use only.
46
- const socketWithListener = socket as unknown as Socket;
44
+ // Cast LocalWebSocket to SocketIOClient.Socket which is the socket that the base class needs. This is hacky
45
+ // but should be fine because this delta connection is for local use only.
46
+ const socketWithListener = socket as unknown as Socket;
47
47
 
48
- const deltaConnection = new LocalDocumentDeltaConnection(socketWithListener, id);
48
+ const deltaConnection = new LocalDocumentDeltaConnection(socketWithListener, id);
49
49
 
50
- const connectMessage: IConnect = {
51
- client,
52
- id,
53
- mode: client.mode,
54
- tenantId,
55
- token, // Token is going to indicate tenant level information, etc...
56
- versions: testProtocolVersions,
57
- };
58
- await deltaConnection.initialize(connectMessage, timeoutMs);
59
- return deltaConnection;
60
- }
50
+ const connectMessage: IConnect = {
51
+ client,
52
+ id,
53
+ mode: client.mode,
54
+ tenantId,
55
+ token, // Token is going to indicate tenant level information, etc...
56
+ versions: testProtocolVersions,
57
+ };
58
+ await deltaConnection.initialize(connectMessage, timeoutMs);
59
+ return deltaConnection;
60
+ }
61
61
 
62
- constructor(socket: Socket, documentId: string) {
63
- super(socket, documentId, new TelemetryNullLogger());
64
- }
62
+ constructor(socket: Socket, documentId: string) {
63
+ super(socket, documentId, new TelemetryNullLogger());
64
+ }
65
65
 
66
- protected submitCore(type: string, messages: IDocumentMessage[]) {
67
- this.emitMessages(type, [messages]);
68
- }
66
+ protected submitCore(type: string, messages: IDocumentMessage[]) {
67
+ this.emitMessages(type, [messages]);
68
+ }
69
69
 
70
- /**
71
- * Submits a new delta operation to the server
72
- */
73
- public submit(messages: IDocumentMessage[]): void {
74
- // We use a promise resolve to force a turn break given message processing is sync
75
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
76
- Promise.resolve().then(() => {
77
- this.submitCore("submitOp", messages);
78
- });
79
- }
70
+ /**
71
+ * Submits a new delta operation to the server
72
+ */
73
+ public submit(messages: IDocumentMessage[]): void {
74
+ // We use a promise resolve to force a turn break given message processing is sync
75
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
76
+ Promise.resolve().then(() => {
77
+ this.submitCore("submitOp", messages);
78
+ });
79
+ }
80
80
 
81
- /**
82
- * Submits a new signal to the server
83
- */
84
- public submitSignal(message: any): void {
85
- this.submitCore("submitSignal", [message]);
86
- }
81
+ /**
82
+ * Submits a new signal to the server
83
+ */
84
+ public submitSignal(message: any): void {
85
+ this.submitCore("submitSignal", [message]);
86
+ }
87
87
 
88
- /**
89
- * Send a "disconnect" message on the socket.
90
- * @param disconnectReason - The reason of the disconnection.
91
- */
92
- public disconnectClient(disconnectReason: string) {
93
- this.socket.emit("disconnect", disconnectReason);
94
- }
88
+ /**
89
+ * Send a "disconnect" message on the socket.
90
+ * @param disconnectReason - The reason of the disconnection.
91
+ */
92
+ public disconnectClient(disconnectReason: string) {
93
+ this.socket.emit("disconnect", disconnectReason);
94
+ }
95
95
 
96
- /**
97
- * * Sends a "nack" message on the socket.
98
- * @param code - An error code number that represents the error. It will be a valid HTTP error code.
99
- * @param type - Type of the Nack.
100
- * @param message - A message about the nack for debugging/logging/telemetry purposes.
101
- */
102
- public nackClient(code: number = 400, type: NackErrorType = NackErrorType.ThrottlingError, message: any) {
103
- const nackMessage = {
104
- operation: undefined,
105
- sequenceNumber: -1,
106
- content: {
107
- code,
108
- type,
109
- message,
110
- },
111
- };
112
- this.socket.emit("nack", "", [nackMessage]);
113
- }
96
+ /**
97
+ * * Sends a "nack" message on the socket.
98
+ * @param code - An error code number that represents the error. It will be a valid HTTP error code.
99
+ * @param type - Type of the Nack.
100
+ * @param message - A message about the nack for debugging/logging/telemetry purposes.
101
+ */
102
+ public nackClient(
103
+ code: number = 400,
104
+ type: NackErrorType = NackErrorType.ThrottlingError,
105
+ message: any,
106
+ ) {
107
+ const nackMessage = {
108
+ operation: undefined,
109
+ sequenceNumber: -1,
110
+ content: {
111
+ code,
112
+ type,
113
+ message,
114
+ },
115
+ };
116
+ this.socket.emit("nack", "", [nackMessage]);
117
+ }
114
118
  }