@fluidframework/odsp-driver 1.1.0 → 1.2.0-77818

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 (108) hide show
  1. package/dist/contractsPublic.d.ts +1 -0
  2. package/dist/contractsPublic.d.ts.map +1 -1
  3. package/dist/contractsPublic.js.map +1 -1
  4. package/dist/localOdspDriver/localOdspDocumentService.d.ts +26 -0
  5. package/dist/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
  6. package/dist/localOdspDriver/localOdspDocumentService.js +39 -0
  7. package/dist/localOdspDriver/localOdspDocumentService.js.map +1 -0
  8. package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
  9. package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
  10. package/dist/localOdspDriver/localOdspDocumentServiceFactory.js +45 -0
  11. package/dist/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
  12. package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
  13. package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
  14. package/dist/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
  15. package/dist/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
  16. package/dist/odspDeltaStorageService.js.map +1 -1
  17. package/dist/odspDocumentService.d.ts.map +1 -1
  18. package/dist/odspDocumentService.js.map +1 -1
  19. package/dist/odspDocumentServiceFactory.d.ts +2 -1
  20. package/dist/odspDocumentServiceFactory.d.ts.map +1 -1
  21. package/dist/odspDocumentServiceFactory.js +7 -1
  22. package/dist/odspDocumentServiceFactory.js.map +1 -1
  23. package/dist/odspDocumentServiceFactoryCore.d.ts +3 -1
  24. package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
  25. package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
  26. package/dist/odspDocumentStorageManager.d.ts +5 -23
  27. package/dist/odspDocumentStorageManager.d.ts.map +1 -1
  28. package/dist/odspDocumentStorageManager.js +52 -245
  29. package/dist/odspDocumentStorageManager.js.map +1 -1
  30. package/dist/odspDocumentStorageServiceBase.d.ts +58 -0
  31. package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -0
  32. package/dist/odspDocumentStorageServiceBase.js +216 -0
  33. package/dist/odspDocumentStorageServiceBase.js.map +1 -0
  34. package/dist/odspDriverUrlResolver.js +1 -1
  35. package/dist/odspDriverUrlResolver.js.map +1 -1
  36. package/dist/odspDriverUrlResolverForShareLink.d.ts +8 -2
  37. package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  38. package/dist/odspDriverUrlResolverForShareLink.js +11 -3
  39. package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
  40. package/dist/odspFluidFileLink.d.ts.map +1 -1
  41. package/dist/odspFluidFileLink.js +27 -21
  42. package/dist/odspFluidFileLink.js.map +1 -1
  43. package/dist/packageVersion.d.ts +1 -1
  44. package/dist/packageVersion.d.ts.map +1 -1
  45. package/dist/packageVersion.js +1 -1
  46. package/dist/packageVersion.js.map +1 -1
  47. package/lib/contractsPublic.d.ts +1 -0
  48. package/lib/contractsPublic.d.ts.map +1 -1
  49. package/lib/contractsPublic.js.map +1 -1
  50. package/lib/localOdspDriver/localOdspDocumentService.d.ts +26 -0
  51. package/lib/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
  52. package/lib/localOdspDriver/localOdspDocumentService.js +35 -0
  53. package/lib/localOdspDriver/localOdspDocumentService.js.map +1 -0
  54. package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
  55. package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
  56. package/lib/localOdspDriver/localOdspDocumentServiceFactory.js +41 -0
  57. package/lib/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
  58. package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
  59. package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
  60. package/lib/localOdspDriver/localOdspDocumentStorageManager.js +62 -0
  61. package/lib/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
  62. package/lib/odspDeltaStorageService.js.map +1 -1
  63. package/lib/odspDocumentService.d.ts.map +1 -1
  64. package/lib/odspDocumentService.js +1 -1
  65. package/lib/odspDocumentService.js.map +1 -1
  66. package/lib/odspDocumentServiceFactory.d.ts +2 -1
  67. package/lib/odspDocumentServiceFactory.d.ts.map +1 -1
  68. package/lib/odspDocumentServiceFactory.js +5 -0
  69. package/lib/odspDocumentServiceFactory.js.map +1 -1
  70. package/lib/odspDocumentServiceFactoryCore.d.ts +3 -1
  71. package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
  72. package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
  73. package/lib/odspDocumentStorageManager.d.ts +5 -23
  74. package/lib/odspDocumentStorageManager.d.ts.map +1 -1
  75. package/lib/odspDocumentStorageManager.js +53 -246
  76. package/lib/odspDocumentStorageManager.js.map +1 -1
  77. package/lib/odspDocumentStorageServiceBase.d.ts +58 -0
  78. package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -0
  79. package/lib/odspDocumentStorageServiceBase.js +212 -0
  80. package/lib/odspDocumentStorageServiceBase.js.map +1 -0
  81. package/lib/odspDriverUrlResolver.js +1 -1
  82. package/lib/odspDriverUrlResolver.js.map +1 -1
  83. package/lib/odspDriverUrlResolverForShareLink.d.ts +8 -2
  84. package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  85. package/lib/odspDriverUrlResolverForShareLink.js +11 -3
  86. package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
  87. package/lib/odspFluidFileLink.d.ts.map +1 -1
  88. package/lib/odspFluidFileLink.js +27 -21
  89. package/lib/odspFluidFileLink.js.map +1 -1
  90. package/lib/packageVersion.d.ts +1 -1
  91. package/lib/packageVersion.d.ts.map +1 -1
  92. package/lib/packageVersion.js +1 -1
  93. package/lib/packageVersion.js.map +1 -1
  94. package/package.json +11 -11
  95. package/src/contractsPublic.ts +1 -0
  96. package/src/localOdspDriver/localOdspDocumentService.ts +54 -0
  97. package/src/localOdspDriver/localOdspDocumentServiceFactory.ts +67 -0
  98. package/src/localOdspDriver/localOdspDocumentStorageManager.ts +83 -0
  99. package/src/odspDeltaStorageService.ts +1 -1
  100. package/src/odspDocumentService.ts +5 -1
  101. package/src/odspDocumentServiceFactory.ts +7 -3
  102. package/src/odspDocumentServiceFactoryCore.ts +1 -1
  103. package/src/odspDocumentStorageManager.ts +81 -312
  104. package/src/odspDocumentStorageServiceBase.ts +268 -0
  105. package/src/odspDriverUrlResolver.ts +1 -1
  106. package/src/odspDriverUrlResolverForShareLink.ts +13 -1
  107. package/src/odspFluidFileLink.ts +26 -22
  108. package/src/packageVersion.ts +1 -1
@@ -8,6 +8,7 @@ export interface OdspFluidDataStoreLocator extends IOdspUrlParts {
8
8
  appName?: string;
9
9
  containerPackageName?: string;
10
10
  fileVersion?: string;
11
+ context?: string;
11
12
  }
12
13
  export declare enum SharingLinkHeader {
13
14
  isSharingLinkToRedeem = "isSharingLinkToRedeem"
@@ -1 +1 @@
1
- {"version":3,"file":"contractsPublic.d.ts","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,yBAA0B,SAAQ,aAAa;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,oBAAY,iBAAiB;IAGzB,qBAAqB,0BAA0B;CAClD;AAED,MAAM,WAAW,kBAAkB;IAC/B,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,oBAAY,qBAAqB;IAG7B,iBAAiB,wBAAwB;CAC5C;AAED,MAAM,WAAW,sBAAsB;IACnC,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,OAAO,QAAQ,iCAAiC,CAAC;IAE7C,UAAiB,cAAe,SAAQ,OAAO,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC;KAAI;CAC3G"}
1
+ {"version":3,"file":"contractsPublic.d.ts","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,yBAA0B,SAAQ,aAAa;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,oBAAY,iBAAiB;IAGzB,qBAAqB,0BAA0B;CAClD;AAED,MAAM,WAAW,kBAAkB;IAC/B,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,oBAAY,qBAAqB;IAG7B,iBAAiB,wBAAwB;CAC5C;AAED,MAAM,WAAW,sBAAsB;IACnC,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,OAAO,QAAQ,iCAAiC,CAAC;IAE7C,UAAiB,cAAe,SAAQ,OAAO,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC;KAAI;CAC3G"}
@@ -1 +1 @@
1
- {"version":3,"file":"contractsPublic.js","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAWH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IACzB,yGAAyG;IACzG,sDAAsD;IACtD,oEAA+C,CAAA;AACnD,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B;AAMD,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC7B,oGAAoG;IACpG,wGAAwG;IACxG,kEAAyC,CAAA;AAC7C,CAAC,EAJW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAIhC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IOdspUrlParts } from \"@fluidframework/odsp-driver-definitions\";\n\nexport interface OdspFluidDataStoreLocator extends IOdspUrlParts {\n dataStorePath: string;\n appName?: string;\n containerPackageName?: string;\n fileVersion?: string;\n}\n\nexport enum SharingLinkHeader {\n // Can be used in request made to resolver, to tell the resolver that the passed in URL is a sharing link\n // which can be redeemed at server to get permissions.\n isSharingLinkToRedeem = \"isSharingLinkToRedeem\",\n}\n\nexport interface ISharingLinkHeader {\n [SharingLinkHeader.isSharingLinkToRedeem]: boolean;\n}\n\nexport enum ClpCompliantAppHeader {\n // Can be used in request made to resolver, to tell the resolver that the host app is CLP compliant.\n // Odsp will not return Classified, labeled, or protected documents if the host app cannot support them.\n isClpCompliantApp = \"X-CLP-Compliant-App\",\n}\n\nexport interface IClpCompliantAppHeader {\n [ClpCompliantAppHeader.isClpCompliantApp]: boolean;\n}\n\ndeclare module \"@fluidframework/core-interfaces\" {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n export interface IRequestHeader extends Partial<ISharingLinkHeader>, Partial<IClpCompliantAppHeader> { }\n}\n"]}
1
+ {"version":3,"file":"contractsPublic.js","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAYH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IACzB,yGAAyG;IACzG,sDAAsD;IACtD,oEAA+C,CAAA;AACnD,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B;AAMD,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC7B,oGAAoG;IACpG,wGAAwG;IACxG,kEAAyC,CAAA;AAC7C,CAAC,EAJW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAIhC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IOdspUrlParts } from \"@fluidframework/odsp-driver-definitions\";\n\nexport interface OdspFluidDataStoreLocator extends IOdspUrlParts {\n dataStorePath: string;\n appName?: string;\n containerPackageName?: string;\n fileVersion?: string;\n context?: string;\n}\n\nexport enum SharingLinkHeader {\n // Can be used in request made to resolver, to tell the resolver that the passed in URL is a sharing link\n // which can be redeemed at server to get permissions.\n isSharingLinkToRedeem = \"isSharingLinkToRedeem\",\n}\n\nexport interface ISharingLinkHeader {\n [SharingLinkHeader.isSharingLinkToRedeem]: boolean;\n}\n\nexport enum ClpCompliantAppHeader {\n // Can be used in request made to resolver, to tell the resolver that the host app is CLP compliant.\n // Odsp will not return Classified, labeled, or protected documents if the host app cannot support them.\n isClpCompliantApp = \"X-CLP-Compliant-App\",\n}\n\nexport interface IClpCompliantAppHeader {\n [ClpCompliantAppHeader.isClpCompliantApp]: boolean;\n}\n\ndeclare module \"@fluidframework/core-interfaces\" {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n export interface IRequestHeader extends Partial<ISharingLinkHeader>, Partial<IClpCompliantAppHeader> { }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ITelemetryLogger } from "@fluidframework/common-definitions";
6
+ import { IDocumentDeltaStorageService, IDocumentService, IDocumentStorageService, IResolvedUrl } from "@fluidframework/driver-definitions";
7
+ import { IOdspResolvedUrl } from "@fluidframework/odsp-driver-definitions";
8
+ import { IClient } from "@fluidframework/protocol-definitions";
9
+ /**
10
+ * IDocumentService implementation that provides explicit snapshot to the document storage service.
11
+ */
12
+ export declare class LocalOdspDocumentService implements IDocumentService {
13
+ private readonly odspResolvedUrl;
14
+ private readonly logger;
15
+ private readonly localSnapshot;
16
+ policies: {
17
+ storageOnly: boolean;
18
+ };
19
+ constructor(odspResolvedUrl: IOdspResolvedUrl, logger: ITelemetryLogger, localSnapshot: Uint8Array | string);
20
+ get resolvedUrl(): IResolvedUrl;
21
+ connectToStorage(): Promise<IDocumentStorageService>;
22
+ connectToDeltaStorage(): Promise<IDocumentDeltaStorageService>;
23
+ connectToDeltaStream(_client: IClient): never;
24
+ dispose(_error?: any): void;
25
+ }
26
+ //# sourceMappingURL=localOdspDocumentService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localOdspDocumentService.d.ts","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EACH,4BAA4B,EAC5B,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,EACf,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAG/D;;GAEG;AACH,qBAAa,wBAAyB,YAAW,gBAAgB;IAIzD,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAL3B,QAAQ;;MAAyB;gBAGnB,eAAe,EAAE,gBAAgB,EACjC,MAAM,EAAE,gBAAgB,EACxB,aAAa,EAAE,UAAU,GAAG,MAAM;IAGvD,IAAW,WAAW,IAAI,YAAY,CAErC;IAEY,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAOpD,qBAAqB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IAIpE,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,KAAK;IAM7C,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,IAAI;CAGrC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.LocalOdspDocumentService = void 0;
8
+ const driver_utils_1 = require("@fluidframework/driver-utils");
9
+ const localOdspDocumentStorageManager_1 = require("./localOdspDocumentStorageManager");
10
+ /**
11
+ * IDocumentService implementation that provides explicit snapshot to the document storage service.
12
+ */
13
+ class LocalOdspDocumentService {
14
+ constructor(odspResolvedUrl, logger, localSnapshot) {
15
+ this.odspResolvedUrl = odspResolvedUrl;
16
+ this.logger = logger;
17
+ this.localSnapshot = localSnapshot;
18
+ this.policies = { storageOnly: true };
19
+ }
20
+ get resolvedUrl() {
21
+ return this.odspResolvedUrl;
22
+ }
23
+ async connectToStorage() {
24
+ return new localOdspDocumentStorageManager_1.LocalOdspDocumentStorageService(this.logger, this.localSnapshot);
25
+ }
26
+ async connectToDeltaStorage() {
27
+ return new driver_utils_1.EmptyDocumentDeltaStorageService();
28
+ }
29
+ connectToDeltaStream(_client) {
30
+ const toThrow = new driver_utils_1.UsageError("\"connectToDeltaStream\" is not supported by LocalOdspDocumentService");
31
+ this.logger.sendErrorEvent({ eventName: "UnsupportedUsage" }, toThrow);
32
+ throw toThrow;
33
+ }
34
+ dispose(_error) {
35
+ // Do nothing
36
+ }
37
+ }
38
+ exports.LocalOdspDocumentService = LocalOdspDocumentService;
39
+ //# sourceMappingURL=localOdspDocumentService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localOdspDocumentService.js","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,+DAA4F;AAG5F,uFAAoF;AAEpF;;GAEG;AACH,MAAa,wBAAwB;IAGjC,YACqB,eAAiC,EACjC,MAAwB,EACxB,aAAkC;QAFlC,oBAAe,GAAf,eAAe,CAAkB;QACjC,WAAM,GAAN,MAAM,CAAkB;QACxB,kBAAa,GAAb,aAAa,CAAqB;QALhD,aAAQ,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAMpC,CAAC;IAEL,IAAW,WAAW;QAClB,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAEM,KAAK,CAAC,gBAAgB;QACzB,OAAO,IAAI,iEAA+B,CACtC,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,aAAa,CACrB,CAAC;IACN,CAAC;IAEM,KAAK,CAAC,qBAAqB;QAC9B,OAAO,IAAI,+CAAgC,EAAE,CAAC;IAClD,CAAC;IAEM,oBAAoB,CAAC,OAAgB;QACxC,MAAM,OAAO,GAAG,IAAI,yBAAU,CAAC,uEAAuE,CAAC,CAAC;QACxG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,OAAO,CAAC,CAAC;QACvE,MAAM,OAAO,CAAC;IAClB,CAAC;IAEM,OAAO,CAAC,MAAY;QACvB,aAAa;IACjB,CAAC;CACJ;AAjCD,4DAiCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n IDocumentDeltaStorageService,\n IDocumentService,\n IDocumentStorageService,\n IResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { UsageError, EmptyDocumentDeltaStorageService } from \"@fluidframework/driver-utils\";\nimport { IOdspResolvedUrl } from \"@fluidframework/odsp-driver-definitions\";\nimport { IClient } from \"@fluidframework/protocol-definitions\";\nimport { LocalOdspDocumentStorageService } from \"./localOdspDocumentStorageManager\";\n\n/**\n * IDocumentService implementation that provides explicit snapshot to the document storage service.\n */\nexport class LocalOdspDocumentService implements IDocumentService {\n public policies = { storageOnly: true };\n\n constructor(\n private readonly odspResolvedUrl: IOdspResolvedUrl,\n private readonly logger: ITelemetryLogger,\n private readonly localSnapshot: Uint8Array | string,\n ) { }\n\n public get resolvedUrl(): IResolvedUrl {\n return this.odspResolvedUrl;\n }\n\n public async connectToStorage(): Promise<IDocumentStorageService> {\n return new LocalOdspDocumentStorageService(\n this.logger,\n this.localSnapshot,\n );\n }\n\n public async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {\n return new EmptyDocumentDeltaStorageService();\n }\n\n public connectToDeltaStream(_client: IClient): never {\n const toThrow = new UsageError(\"\\\"connectToDeltaStream\\\" is not supported by LocalOdspDocumentService\");\n this.logger.sendErrorEvent({ eventName: \"UnsupportedUsage\" }, toThrow);\n throw toThrow;\n }\n\n public dispose(_error?: any): void {\n // Do nothing\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IDocumentService, IResolvedUrl } from "@fluidframework/driver-definitions";
6
+ import { TelemetryLogger } from "@fluidframework/telemetry-utils";
7
+ import { ISummaryTree } from "@fluidframework/protocol-definitions";
8
+ import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
9
+ import { ICacheAndTracker } from "../epochTracker";
10
+ import { OdspDocumentServiceFactoryCore } from "../odspDocumentServiceFactoryCore";
11
+ /**
12
+ * Factory for creating sharepoint document service with a provided snapshot.
13
+ * Use if you don't want to connect to any kind of external/internal storages and want to provide
14
+ * content directly.
15
+ */
16
+ export declare class LocalOdspDocumentServiceFactory extends OdspDocumentServiceFactoryCore {
17
+ private readonly localSnapshot;
18
+ private logger;
19
+ constructor(localSnapshot: Uint8Array | string);
20
+ private throwUnsupportedUsageError;
21
+ createContainer(_createNewSummary: ISummaryTree | undefined, _createNewResolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, _clientIsSummarizer?: boolean): never;
22
+ protected createDocumentServiceCore(resolvedUrl: IResolvedUrl, odspLogger: TelemetryLogger, _cacheAndTrackerArg?: ICacheAndTracker, _clientIsSummarizer?: boolean): Promise<IDocumentService>;
23
+ }
24
+ //# sourceMappingURL=localOdspDocumentServiceFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localOdspDocumentServiceFactory.d.ts","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEpF,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AAGnF;;;;GAIG;AACH,qBAAa,+BAAgC,SAAQ,8BAA8B;IAI3E,OAAO,CAAC,QAAQ,CAAC,aAAa;IAHlC,OAAO,CAAC,MAAM,CAA8B;gBAGvB,aAAa,EAAE,UAAU,GAAG,MAAM;IASvD,OAAO,CAAC,0BAA0B;IAO3B,eAAe,CAClB,iBAAiB,EAAE,YAAY,GAAG,SAAS,EAC3C,qBAAqB,EAAE,YAAY,EACnC,MAAM,CAAC,EAAE,oBAAoB,EAC7B,mBAAmB,CAAC,EAAE,OAAO,GAC9B,KAAK;cAMQ,yBAAyB,CACrC,WAAW,EAAE,YAAY,EACzB,UAAU,EAAE,eAAe,EAC3B,mBAAmB,CAAC,EAAE,gBAAgB,EACtC,mBAAmB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAAC,gBAAgB,CAAC;CAU/B"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.LocalOdspDocumentServiceFactory = void 0;
8
+ const driver_utils_1 = require("@fluidframework/driver-utils");
9
+ const odspUtils_1 = require("../odspUtils");
10
+ const odspDocumentServiceFactoryCore_1 = require("../odspDocumentServiceFactoryCore");
11
+ const localOdspDocumentService_1 = require("./localOdspDocumentService");
12
+ /**
13
+ * Factory for creating sharepoint document service with a provided snapshot.
14
+ * Use if you don't want to connect to any kind of external/internal storages and want to provide
15
+ * content directly.
16
+ */
17
+ class LocalOdspDocumentServiceFactory extends odspDocumentServiceFactoryCore_1.OdspDocumentServiceFactoryCore {
18
+ constructor(localSnapshot) {
19
+ super((_options) => this.throwUnsupportedUsageError("Getting storage token"), (_options) => this.throwUnsupportedUsageError("Getting websocket token"), () => this.throwUnsupportedUsageError("Getting SocketIO Client"));
20
+ this.localSnapshot = localSnapshot;
21
+ }
22
+ throwUnsupportedUsageError(unsupportedFuncName) {
23
+ var _a;
24
+ const toThrow = new driver_utils_1.UsageError(`${unsupportedFuncName} is not supported by LocalOdspDocumentServiceFactory`);
25
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.sendErrorEvent({ eventName: "UnsupportedUsage" }, toThrow);
26
+ throw toThrow;
27
+ }
28
+ createContainer(_createNewSummary, _createNewResolvedUrl, logger, _clientIsSummarizer) {
29
+ const toThrow = new driver_utils_1.UsageError("\"createContainer\" is not supported by LocalOdspDocumentServiceFactory");
30
+ (0, odspUtils_1.createOdspLogger)(logger).sendErrorEvent({ eventName: "UnsupportedUsage" }, toThrow);
31
+ throw toThrow;
32
+ }
33
+ async createDocumentServiceCore(resolvedUrl, odspLogger, _cacheAndTrackerArg, _clientIsSummarizer) {
34
+ if (_cacheAndTrackerArg !== undefined) {
35
+ throw new driver_utils_1.UsageError("Invalid usage. \"_cacheAndTrackerArg\" should not be provided");
36
+ }
37
+ if (_clientIsSummarizer) {
38
+ throw new driver_utils_1.UsageError("Invalid usage. \"_clientIsSummarizer\" should not be provided");
39
+ }
40
+ this.logger = odspLogger;
41
+ return new localOdspDocumentService_1.LocalOdspDocumentService((0, odspUtils_1.getOdspResolvedUrl)(resolvedUrl), odspLogger, this.localSnapshot);
42
+ }
43
+ }
44
+ exports.LocalOdspDocumentServiceFactory = LocalOdspDocumentServiceFactory;
45
+ //# sourceMappingURL=localOdspDocumentServiceFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localOdspDocumentServiceFactory.js","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentServiceFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAA0D;AAI1D,4CAAoE;AAEpE,sFAAmF;AACnF,yEAAsE;AAEtE;;;;GAIG;AACH,MAAa,+BAAgC,SAAQ,+DAA8B;IAG/E,YACqB,aAAkC;QAEnD,KAAK,CACD,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,uBAAuB,CAAC,EACtE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,EACxE,GAAG,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,CACnE,CAAC;QANe,kBAAa,GAAb,aAAa,CAAqB;IAOvD,CAAC;IAEO,0BAA0B,CAAC,mBAA2B;;QAC1D,MAAM,OAAO,GAAG,IAAI,yBAAU,CAC1B,GAAG,mBAAmB,sDAAsD,CAAC,CAAC;QAClF,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,OAAO,CAAC,CAAC;QACxE,MAAM,OAAO,CAAC;IAClB,CAAC;IAEM,eAAe,CAClB,iBAA2C,EAC3C,qBAAmC,EACnC,MAA6B,EAC7B,mBAA6B;QAE7B,MAAM,OAAO,GAAG,IAAI,yBAAU,CAAC,yEAAyE,CAAC,CAAC;QAC1G,IAAA,4BAAgB,EAAC,MAAM,CAAC,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,OAAO,CAAC,CAAC;QACpF,MAAM,OAAO,CAAC;IAClB,CAAC;IAES,KAAK,CAAC,yBAAyB,CACrC,WAAyB,EACzB,UAA2B,EAC3B,mBAAsC,EACtC,mBAA6B;QAE7B,IAAI,mBAAmB,KAAK,SAAS,EAAE;YACnC,MAAM,IAAI,yBAAU,CAAC,+DAA+D,CAAC,CAAC;SACzF;QACD,IAAI,mBAAmB,EAAE;YACrB,MAAM,IAAI,yBAAU,CAAC,+DAA+D,CAAC,CAAC;SACzF;QACD,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC;QACzB,OAAO,IAAI,mDAAwB,CAAC,IAAA,8BAAkB,EAAC,WAAW,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACzG,CAAC;CACJ;AA9CD,0EA8CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDocumentService, IResolvedUrl } from \"@fluidframework/driver-definitions\";\nimport { UsageError } from \"@fluidframework/driver-utils\";\nimport { TelemetryLogger } from \"@fluidframework/telemetry-utils\";\nimport { ISummaryTree } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { createOdspLogger, getOdspResolvedUrl } from \"../odspUtils\";\nimport { ICacheAndTracker } from \"../epochTracker\";\nimport { OdspDocumentServiceFactoryCore } from \"../odspDocumentServiceFactoryCore\";\nimport { LocalOdspDocumentService } from \"./localOdspDocumentService\";\n\n/**\n * Factory for creating sharepoint document service with a provided snapshot.\n * Use if you don't want to connect to any kind of external/internal storages and want to provide\n * content directly.\n */\nexport class LocalOdspDocumentServiceFactory extends OdspDocumentServiceFactoryCore {\n private logger: TelemetryLogger | undefined;\n\n constructor(\n private readonly localSnapshot: Uint8Array | string,\n ) {\n super(\n (_options) => this.throwUnsupportedUsageError(\"Getting storage token\"),\n (_options) => this.throwUnsupportedUsageError(\"Getting websocket token\"),\n () => this.throwUnsupportedUsageError(\"Getting SocketIO Client\"),\n );\n }\n\n private throwUnsupportedUsageError(unsupportedFuncName: string): never {\n const toThrow = new UsageError(\n `${unsupportedFuncName} is not supported by LocalOdspDocumentServiceFactory`);\n this.logger?.sendErrorEvent({ eventName: \"UnsupportedUsage\" }, toThrow);\n throw toThrow;\n }\n\n public createContainer(\n _createNewSummary: ISummaryTree | undefined,\n _createNewResolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n _clientIsSummarizer?: boolean,\n ): never {\n const toThrow = new UsageError(\"\\\"createContainer\\\" is not supported by LocalOdspDocumentServiceFactory\");\n createOdspLogger(logger).sendErrorEvent({ eventName: \"UnsupportedUsage\" }, toThrow);\n throw toThrow;\n }\n\n protected async createDocumentServiceCore(\n resolvedUrl: IResolvedUrl,\n odspLogger: TelemetryLogger,\n _cacheAndTrackerArg?: ICacheAndTracker,\n _clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n if (_cacheAndTrackerArg !== undefined) {\n throw new UsageError(\"Invalid usage. \\\"_cacheAndTrackerArg\\\" should not be provided\");\n }\n if (_clientIsSummarizer) {\n throw new UsageError(\"Invalid usage. \\\"_clientIsSummarizer\\\" should not be provided\");\n }\n this.logger = odspLogger;\n return new LocalOdspDocumentService(getOdspResolvedUrl(resolvedUrl), odspLogger, this.localSnapshot);\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ITelemetryLogger } from "@fluidframework/common-definitions";
6
+ import { ISummaryContext } from "@fluidframework/driver-definitions";
7
+ import * as api from "@fluidframework/protocol-definitions";
8
+ import { OdspDocumentStorageServiceBase } from "../odspDocumentStorageServiceBase";
9
+ /**
10
+ * ODSP document storage service that works on a provided snapshot for all its processing.
11
+ * Attempting to use unsupported actions/methods will result in errors being thrown.
12
+ */
13
+ export declare class LocalOdspDocumentStorageService extends OdspDocumentStorageServiceBase {
14
+ private readonly logger;
15
+ private readonly localSnapshot;
16
+ private snapshotTreeId;
17
+ constructor(logger: ITelemetryLogger, localSnapshot: Uint8Array | string);
18
+ private calledGetVersions;
19
+ getVersions(blobid: string | null, count: number, _scenarioName?: string): Promise<api.IVersion[]>;
20
+ private getSnapshotVersion;
21
+ protected fetchTreeFromSnapshot(_id: string, _scenarioName?: string): never;
22
+ protected fetchBlobFromStorage(_blobId: string, _evicted: boolean): never;
23
+ uploadSummaryWithContext(_summary: api.ISummaryTree, _context: ISummaryContext): never;
24
+ createBlob(_file: ArrayBufferLike): never;
25
+ private throwUsageError;
26
+ }
27
+ //# sourceMappingURL=localOdspDocumentStorageManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localOdspDocumentStorageManager.d.ts","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentStorageManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,OAAO,KAAK,GAAG,MAAM,sCAAsC,CAAC;AAC5D,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AAOnF;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,8BAA8B;IAI3E,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAJlC,OAAO,CAAC,cAAc,CAAqB;gBAGtB,MAAM,EAAE,gBAAgB,EACxB,aAAa,EAAE,UAAU,GAAG,MAAM;IAKvD,OAAO,CAAC,iBAAiB,CAAS;IAErB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAwB/G,OAAO,CAAC,kBAAkB;IAI1B,SAAS,CAAC,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK;IAI3E,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,KAAK;IAIlE,wBAAwB,CAAC,QAAQ,EAAE,GAAG,CAAC,YAAY,EAAE,QAAQ,EAAE,eAAe,GAAG,KAAK;IAItF,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK;IAIhD,OAAO,CAAC,eAAe;CAK1B"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.LocalOdspDocumentStorageService = void 0;
8
+ const common_utils_1 = require("@fluidframework/common-utils");
9
+ const driver_utils_1 = require("@fluidframework/driver-utils");
10
+ const odspDocumentStorageServiceBase_1 = require("../odspDocumentStorageServiceBase");
11
+ const odspSnapshotParser_1 = require("../odspSnapshotParser");
12
+ const compactSnapshotParser_1 = require("../compactSnapshotParser");
13
+ const ReadBufferUtils_1 = require("../ReadBufferUtils");
14
+ /**
15
+ * ODSP document storage service that works on a provided snapshot for all its processing.
16
+ * Attempting to use unsupported actions/methods will result in errors being thrown.
17
+ */
18
+ class LocalOdspDocumentStorageService extends odspDocumentStorageServiceBase_1.OdspDocumentStorageServiceBase {
19
+ constructor(logger, localSnapshot) {
20
+ super();
21
+ this.logger = logger;
22
+ this.localSnapshot = localSnapshot;
23
+ this.calledGetVersions = false;
24
+ }
25
+ async getVersions(blobid, count, _scenarioName) {
26
+ (0, common_utils_1.assert)(blobid === null, "Invalid usage. \"blobid\" should always be null");
27
+ (0, common_utils_1.assert)(count === 1, "Invalid usage. \"count\" should always be 1");
28
+ // No reason to re-parse the data since it will never change
29
+ if (this.calledGetVersions) {
30
+ return this.getSnapshotVersion();
31
+ }
32
+ this.calledGetVersions = true;
33
+ let snapshotContents;
34
+ if (typeof this.localSnapshot === "string") {
35
+ const content = JSON.parse(this.localSnapshot);
36
+ snapshotContents = (0, odspSnapshotParser_1.convertOdspSnapshotToSnapshotTreeAndBlobs)(content);
37
+ }
38
+ else {
39
+ snapshotContents = (0, compactSnapshotParser_1.parseCompactSnapshotResponse)(new ReadBufferUtils_1.ReadBuffer(this.localSnapshot));
40
+ }
41
+ this.snapshotTreeId = this.initializeFromSnapshot(snapshotContents);
42
+ return this.getSnapshotVersion();
43
+ }
44
+ getSnapshotVersion() {
45
+ return this.snapshotTreeId ? [{ id: this.snapshotTreeId, treeId: undefined }] : [];
46
+ }
47
+ fetchTreeFromSnapshot(_id, _scenarioName) {
48
+ this.throwUsageError("fetchTreeFromSnapshot");
49
+ }
50
+ fetchBlobFromStorage(_blobId, _evicted) {
51
+ this.throwUsageError("fetchBlobFromStorage");
52
+ }
53
+ uploadSummaryWithContext(_summary, _context) {
54
+ this.throwUsageError("uploadSummaryWithContext");
55
+ }
56
+ createBlob(_file) {
57
+ this.throwUsageError("createBlob");
58
+ }
59
+ throwUsageError(methodName) {
60
+ const toThrow = new driver_utils_1.UsageError(`"${methodName}" is not supported by LocalOdspDocumentStorageService`);
61
+ this.logger.sendErrorEvent({ eventName: "UnsupportedUsage" }, toThrow);
62
+ throw toThrow;
63
+ }
64
+ }
65
+ exports.LocalOdspDocumentStorageService = LocalOdspDocumentStorageService;
66
+ //# sourceMappingURL=localOdspDocumentStorageManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localOdspDocumentStorageManager.js","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentStorageManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAGtD,+DAA0D;AAE1D,sFAAmF;AAGnF,8DAAkF;AAClF,oEAAwE;AACxE,wDAAgD;AAEhD;;;GAGG;AACH,MAAa,+BAAgC,SAAQ,+DAA8B;IAG/E,YACqB,MAAwB,EACxB,aA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AAC;IAClD,CAAC;IAES,oBAAoB,CAAC,OAAe,EAAE,QAAiB;QAC7D,IAAI,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;IAEM,wBAAwB,CAAC,QAA0B,EAAE,QAAyB;QACjF,IAAI,CAAC,eAAe,CAAC,0BAA0B,CAAC,CAAC;IACrD,CAAC;IAEM,UAAU,CAAC,KAAsB;QACpC,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IAEO,eAAe,CAAC,UAAkB;QACtC,MAAM,OAAO,GAAG,IAAI,yBAAU,CAAC,IAAI,UAAU,uDAAuD,CAAC,CAAC;QACtG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,OAAO,CAAC,CAAC;QACvE,MAAM,OAAO,CAAC;IAClB,CAAC;CACJ;AA7DD,0EA6DC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ISummaryContext } from \"@fluidframework/driver-definitions\";\nimport { UsageError } from \"@fluidframework/driver-utils\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { OdspDocumentStorageServiceBase } from \"../odspDocumentStorageServiceBase\";\nimport { ISnapshotContents } from \"../odspPublicUtils\";\nimport { IOdspSnapshot } from \"../contracts\";\nimport { convertOdspSnapshotToSnapshotTreeAndBlobs } from \"../odspSnapshotParser\";\nimport { parseCompactSnapshotResponse } from \"../compactSnapshotParser\";\nimport { ReadBuffer } from \"../ReadBufferUtils\";\n\n/**\n * ODSP document storage service that works on a provided snapshot for all its processing.\n * Attempting to use unsupported actions/methods will result in errors being thrown.\n */\nexport class LocalOdspDocumentStorageService extends OdspDocumentStorageServiceBase {\n private snapshotTreeId: string | undefined;\n\n constructor(\n private readonly logger: ITelemetryLogger,\n private readonly localSnapshot: Uint8Array | string,\n ) {\n super();\n }\n\n private calledGetVersions = false;\n\n public async getVersions(blobid: string | null, count: number, _scenarioName?: string): Promise<api.IVersion[]> {\n assert(blobid === null, \"Invalid usage. \\\"blobid\\\" should always be null\");\n assert(count === 1, \"Invalid usage. \\\"count\\\" should always be 1\");\n\n // No reason to re-parse the data since it will never change\n if (this.calledGetVersions) {\n return this.getSnapshotVersion();\n }\n this.calledGetVersions = true;\n\n let snapshotContents: ISnapshotContents;\n\n if (typeof this.localSnapshot === \"string\") {\n const content: IOdspSnapshot = JSON.parse(this.localSnapshot);\n snapshotContents = convertOdspSnapshotToSnapshotTreeAndBlobs(content);\n } else {\n snapshotContents = parseCompactSnapshotResponse(\n new ReadBuffer(this.localSnapshot));\n }\n\n this.snapshotTreeId = this.initializeFromSnapshot(snapshotContents);\n return this.getSnapshotVersion();\n }\n\n private getSnapshotVersion(): api.IVersion[] {\n return this.snapshotTreeId ? [{ id: this.snapshotTreeId, treeId: undefined! }] : [];\n }\n\n protected fetchTreeFromSnapshot(_id: string, _scenarioName?: string): never {\n this.throwUsageError(\"fetchTreeFromSnapshot\");\n }\n\n protected fetchBlobFromStorage(_blobId: string, _evicted: boolean): never {\n this.throwUsageError(\"fetchBlobFromStorage\");\n }\n\n public uploadSummaryWithContext(_summary: api.ISummaryTree, _context: ISummaryContext): never {\n this.throwUsageError(\"uploadSummaryWithContext\");\n }\n\n public createBlob(_file: ArrayBufferLike): never {\n this.throwUsageError(\"createBlob\");\n }\n\n private throwUsageError(methodName: string): never {\n const toThrow = new UsageError(`\"${methodName}\" is not supported by LocalOdspDocumentStorageService`);\n this.logger.sendErrorEvent({ eventName: \"UnsupportedUsage\" }, toThrow);\n throw toThrow;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"odspDeltaStorageService.js","sourceRoot":"","sources":["../src/odspDeltaStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,wEAA8D;AAC9D,+BAAkC;AAElC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OAAO,GAAG,CAAC;QACf,CAAC,CAAC;QAEF,MAAM,MAAM,GAAG,IAAA,yBAAU,EACrB,KAAK,EAAE,IAAY,EAAE,EAAU,EAAE,cAAoC,EAAE,EAAE;YACrE,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,cAAc,CAAC,CAAC;YAC/D,+BAA+B;YAC/B,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC1D,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,uEAAuE;QACvE,0DAA0D;QAC1D,IAAI,CAAC,WAAW,EAChB,SAAS,EAAE,YAAY;QACvB,OAAO,EAAE,YAAY;QACrB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,MAAM,EACX,WAAW,EACX,WAAW,CACd,CAAC;QAEF,OAAO,IAAA,6BAAc,EAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACrC,IAAI,MAAM,CAAC,IAAI,IAAI,eAAe,GAAG,YAAY,GAAG,cAAc,KAAK,CAAC,EAAE;gBACtE,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;oBAC7B,SAAS,EAAE,mBAAmB;oBAC9B,eAAe;oBACf,YAAY;oBACZ,cAAc;iBACjB,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACX,CAAC;CACA;AA3HD,8DA2HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { default as AbortController } from \"abort-controller\";\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger, ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport { IDeltasFetchResult, IDocumentDeltaStorageService } from \"@fluidframework/driver-definitions\";\nimport {\n requestOps,\n streamObserver,\n} from \"@fluidframework/driver-utils\";\nimport { IDeltaStorageGetResponse, ISequencedDeltaOpMessage } from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils\";\n\n/**\n * Provides access to the underlying delta storage on the server for sharepoint driver.\n */\nexport class OdspDeltaStorageService {\n constructor(\n private readonly deltaFeedUrl: string,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n private readonly epochTracker: EpochTracker,\n private readonly logger: ITelemetryLogger,\n ) {\n }\n\n /**\n * Retrieves ops from cache\n * @param from - inclusive\n * @param to - exclusive\n * @param telemetryProps - properties to add when issuing telemetry events\n * @returns ops retrieved & info if result was partial (i.e. more is available)\n */\n public async get(\n from: number,\n to: number,\n telemetryProps: ITelemetryProperties,\n fetchReason?: string,\n ): Promise<IDeltasFetchResult> {\n return getWithRetryForTokenRefresh(async (options) => {\n // Note - this call ends up in getSocketStorageDiscovery() and can refresh token\n // Thus it needs to be done before we call getStorageToken() to reduce extra calls\n const baseUrl = this.buildUrl(from, to);\n const storageToken = await this.getStorageToken(options, \"DeltaStorage\");\n\n const formBoundary = uuid();\n let postBody = `--${formBoundary}\\r\\n`;\n postBody += `Authorization: Bearer ${storageToken}\\r\\n`;\n postBody += `X-HTTP-Method-Override: GET\\r\\n`;\n\n postBody += `_post: 1\\r\\n`;\n postBody += `\\r\\n--${formBoundary}--`;\n const headers: { [index: string]: any; } = {\n \"Content-Type\": `multipart/form-data;boundary=${formBoundary}`,\n };\n\n // Some request take a long time (1-2 minutes) to complete, where telemetry shows very small amount\n // of time spent on server, and usually small payload sizes. I.e. all the time is spent somewhere in\n // networking. Even bigger problem - a lot of requests timeout (based on cursory look - after 1-2 minutes)\n // So adding some timeout to ensure we retry again in hope of faster success.\n // Please see https://github.com/microsoft/FluidFramework/issues/6997 for details.\n const abort = new AbortController();\n const timer = setTimeout(() => abort.abort(), 30000);\n\n const response = await this.epochTracker.fetchAndParseAsJSON<IDeltaStorageGetResponse>(\n baseUrl,\n {\n headers,\n body: postBody,\n method: \"POST\",\n signal: abort.signal,\n },\n \"ops\",\n true,\n fetchReason,\n );\n clearTimeout(timer);\n const deltaStorageResponse = response.content;\n let messages: ISequencedDocumentMessage[];\n if (deltaStorageResponse.value.length > 0 && \"op\" in deltaStorageResponse.value[0]) {\n messages = (deltaStorageResponse.value as ISequencedDeltaOpMessage[]).map((operation) => operation.op);\n } else {\n messages = deltaStorageResponse.value as ISequencedDocumentMessage[];\n }\n\n this.logger.sendPerformanceEvent({\n eventName: \"OpsFetch\",\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n length: messages.length,\n duration: response.duration, // this duration for single attempt!\n ...response.propsToLog,\n attempts: options.refresh ? 2 : 1,\n from,\n to,\n ...telemetryProps,\n });\n\n // It is assumed that server always returns all the ops that it has in the range that was requested.\n // This may change in the future, if so, we need to adjust and receive \"end\" value from server in such case.\n return { messages, partialResult: false };\n });\n }\n\n public buildUrl(from: number, to: number) {\n const filter = encodeURIComponent(`sequenceNumber ge ${from} and sequenceNumber le ${to - 1}`);\n const queryString = `?ump=1&filter=${filter}`;\n return `${this.deltaFeedUrl}${queryString}`;\n }\n}\n\nexport class OdspDeltaStorageWithCache implements IDocumentDeltaStorageService {\n private firstCacheMiss = Number.MAX_SAFE_INTEGER;\n\n public constructor(\n private snapshotOps: ISequencedDocumentMessage[] | undefined,\n private readonly logger: ITelemetryLogger,\n private readonly batchSize: number,\n private readonly concurrency: number,\n private readonly getFromStorage: (\n from: number,\n to: number,\n telemetryProps: ITelemetryProperties,\n fetchReason?: string) => Promise<IDeltasFetchResult>,\n private readonly getCached: (from: number, to: number) => Promise<ISequencedDocumentMessage[]>,\n private readonly requestFromSocket: (from: number, to: number) => void,\n private readonly opsReceived: (ops: ISequencedDocumentMessage[]) => void,\n ) {\n }\n\n protected validateMessages(reason: string, messages: ISequencedDocumentMessage[], from: number) {\n if (messages.length !== 0) {\n const start = messages[0].sequenceNumber;\n const length = messages.length;\n const last = messages[length - 1].sequenceNumber;\n if (start !== from) {\n this.logger.sendErrorEvent({ eventName: \"OpsFetchViolation\", reason, from, start, last, length });\n messages.length = 0;\n }\n if (last + 1 !== from + length) {\n this.logger.sendErrorEvent({ eventName: \"OpsFetchViolation\", reason, from, start, last, length });\n // we can do better here by finding consecutive sub-block and return it\n messages.length = 0;\n }\n }\n }\n\n public fetchMessages(\n fromTotal: number,\n toTotal: number | undefined,\n abortSignal?: AbortSignal,\n cachedOnly?: boolean,\n fetchReason?: string) {\n // We do not control what's in the cache. Current API assumes that fetchMessages() keeps banging on\n // storage / cache until it gets ops it needs. This would result in deadlock if fixed range is asked from\n // cache and it's not there.\n // Better implementation would be to return only what we have in cache, but that also breaks API\n assert(!cachedOnly || toTotal === undefined, 0x1e3);\n\n let opsFromSnapshot = 0;\n let opsFromCache = 0;\n let opsFromStorage = 0;\n\n const requestCallback = async (from: number, to: number, telemetryProps: ITelemetryProperties) => {\n if (this.snapshotOps !== undefined && this.snapshotOps.length !== 0) {\n const messages = this.snapshotOps.filter((op) =>\n op.sequenceNumber >= from && op.sequenceNumber < to);\n this.validateMessages(\"cached\", messages, from);\n if (messages.length > 0 && messages[0].sequenceNumber === from) {\n this.snapshotOps = this.snapshotOps.filter((op) => op.sequenceNumber >= to);\n opsFromSnapshot = messages.length;\n return { messages, partialResult: true };\n }\n this.snapshotOps = undefined;\n }\n\n // Kick out request to PUSH for ops if it has them\n this.requestFromSocket(from, to);\n\n // Cache in normal flow is continuous. Once there is a miss, stop consulting cache.\n // This saves a bit of processing time\n if (from < this.firstCacheMiss) {\n const messagesFromCache = await this.getCached(from, to);\n this.validateMessages(\"cached\", messagesFromCache, from);\n if (messagesFromCache.length !== 0) {\n opsFromCache += messagesFromCache.length;\n return {\n messages: messagesFromCache,\n partialResult: true,\n };\n }\n this.firstCacheMiss = Math.min(this.firstCacheMiss, from);\n }\n\n if (cachedOnly) {\n return { messages: [], partialResult: false };\n }\n\n const ops = await this.getFromStorage(from, to, telemetryProps, fetchReason);\n this.validateMessages(\"storage\", ops.messages, from);\n opsFromStorage += ops.messages.length;\n this.opsReceived(ops.messages);\n return ops;\n };\n\n const stream = requestOps(\n async (from: number, to: number, telemetryProps: ITelemetryProperties) => {\n const result = await requestCallback(from, to, telemetryProps);\n // Catch all case, just in case\n this.validateMessages(\"catch all\", result.messages, from);\n return result;\n },\n // Staging: starting with no concurrency, listening for feedback first.\n // In future releases we will switch to actual concurrency\n this.concurrency,\n fromTotal, // inclusive\n toTotal, // exclusive\n this.batchSize,\n this.logger,\n abortSignal,\n fetchReason,\n );\n\n return streamObserver(stream, (result) => {\n if (result.done && opsFromSnapshot + opsFromCache + opsFromStorage !== 0) {\n this.logger.sendPerformanceEvent({\n eventName: \"CacheOpsRetrieved\",\n opsFromSnapshot,\n opsFromCache,\n opsFromStorage,\n });\n }\n });\n}\n}\n"]}
1
+ {"version":3,"file":"odspDeltaStorageService.js","sourceRoot":"","sources":["../src/odspDeltaStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,wEAA8D;AAC9D,+BAAkC;AAElC,+DAAsD;AAItD,+DAGsC;AAGtC,2CAA0D;AAE1D;;GAEG;AACH,MAAa,uBAAuB;IAChC,YACqB,YAAoB,EACpB,eAAgD,EAChD,YAA0B,EAC1B,MAAwB;QAHxB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,oBAAe,GAAf,eAAe,CAAiC;QAChD,iBAAY,GAAZ,YAAY,CAAc;QAC1B,WAAM,GAAN,MAAM,CAAkB;IAE7C,CAAC;IAED;;;;;;OAMG;IACK,KAAK,CAAC,GAAG,CACb,IAAY,EACZ,EAAU,EACV,cAAoC,EACpC,WAAoB;QAEpB,OAAO,IAAA,uCAA2B,EAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YACjD,gFAAgF;YAChF,kFAAkF;YAClF,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAA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ACd,CAAC;QAEF,OAAO,IAAA,6BAAc,EAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACrC,IAAI,MAAM,CAAC,IAAI,IAAI,eAAe,GAAG,YAAY,GAAG,cAAc,KAAK,CAAC,EAAE;gBACtE,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;oBAC7B,SAAS,EAAE,mBAAmB;oBAC9B,eAAe;oBACf,YAAY;oBACZ,cAAc;iBACjB,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA3HD,8DA2HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { default as AbortController } from \"abort-controller\";\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger, ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport { IDeltasFetchResult, IDocumentDeltaStorageService } from \"@fluidframework/driver-definitions\";\nimport {\n requestOps,\n streamObserver,\n} from \"@fluidframework/driver-utils\";\nimport { IDeltaStorageGetResponse, ISequencedDeltaOpMessage } from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils\";\n\n/**\n * Provides access to the underlying delta storage on the server for sharepoint driver.\n */\nexport class OdspDeltaStorageService {\n constructor(\n private readonly deltaFeedUrl: string,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n private readonly epochTracker: EpochTracker,\n private readonly logger: ITelemetryLogger,\n ) {\n }\n\n /**\n * Retrieves ops from cache\n * @param from - inclusive\n * @param to - exclusive\n * @param telemetryProps - properties to add when issuing telemetry events\n * @returns ops retrieved & info if result was partial (i.e. more is available)\n */\n public async get(\n from: number,\n to: number,\n telemetryProps: ITelemetryProperties,\n fetchReason?: string,\n ): Promise<IDeltasFetchResult> {\n return getWithRetryForTokenRefresh(async (options) => {\n // Note - this call ends up in getSocketStorageDiscovery() and can refresh token\n // Thus it needs to be done before we call getStorageToken() to reduce extra calls\n const baseUrl = this.buildUrl(from, to);\n const storageToken = await this.getStorageToken(options, \"DeltaStorage\");\n\n const formBoundary = uuid();\n let postBody = `--${formBoundary}\\r\\n`;\n postBody += `Authorization: Bearer ${storageToken}\\r\\n`;\n postBody += `X-HTTP-Method-Override: GET\\r\\n`;\n\n postBody += `_post: 1\\r\\n`;\n postBody += `\\r\\n--${formBoundary}--`;\n const headers: { [index: string]: any; } = {\n \"Content-Type\": `multipart/form-data;boundary=${formBoundary}`,\n };\n\n // Some request take a long time (1-2 minutes) to complete, where telemetry shows very small amount\n // of time spent on server, and usually small payload sizes. I.e. all the time is spent somewhere in\n // networking. Even bigger problem - a lot of requests timeout (based on cursory look - after 1-2 minutes)\n // So adding some timeout to ensure we retry again in hope of faster success.\n // Please see https://github.com/microsoft/FluidFramework/issues/6997 for details.\n const abort = new AbortController();\n const timer = setTimeout(() => abort.abort(), 30000);\n\n const response = await this.epochTracker.fetchAndParseAsJSON<IDeltaStorageGetResponse>(\n baseUrl,\n {\n headers,\n body: postBody,\n method: \"POST\",\n signal: abort.signal,\n },\n \"ops\",\n true,\n fetchReason,\n );\n clearTimeout(timer);\n const deltaStorageResponse = response.content;\n let messages: ISequencedDocumentMessage[];\n if (deltaStorageResponse.value.length > 0 && \"op\" in deltaStorageResponse.value[0]) {\n messages = (deltaStorageResponse.value as ISequencedDeltaOpMessage[]).map((operation) => operation.op);\n } else {\n messages = deltaStorageResponse.value as ISequencedDocumentMessage[];\n }\n\n this.logger.sendPerformanceEvent({\n eventName: \"OpsFetch\",\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n length: messages.length,\n duration: response.duration, // this duration for single attempt!\n ...response.propsToLog,\n attempts: options.refresh ? 2 : 1,\n from,\n to,\n ...telemetryProps,\n });\n\n // It is assumed that server always returns all the ops that it has in the range that was requested.\n // This may change in the future, if so, we need to adjust and receive \"end\" value from server in such case.\n return { messages, partialResult: false };\n });\n }\n\n public buildUrl(from: number, to: number) {\n const filter = encodeURIComponent(`sequenceNumber ge ${from} and sequenceNumber le ${to - 1}`);\n const queryString = `?ump=1&filter=${filter}`;\n return `${this.deltaFeedUrl}${queryString}`;\n }\n}\n\nexport class OdspDeltaStorageWithCache implements IDocumentDeltaStorageService {\n private firstCacheMiss = Number.MAX_SAFE_INTEGER;\n\n public constructor(\n private snapshotOps: ISequencedDocumentMessage[] | undefined,\n private readonly logger: ITelemetryLogger,\n private readonly batchSize: number,\n private readonly concurrency: number,\n private readonly getFromStorage: (\n from: number,\n to: number,\n telemetryProps: ITelemetryProperties,\n fetchReason?: string) => Promise<IDeltasFetchResult>,\n private readonly getCached: (from: number, to: number) => Promise<ISequencedDocumentMessage[]>,\n private readonly requestFromSocket: (from: number, to: number) => void,\n private readonly opsReceived: (ops: ISequencedDocumentMessage[]) => void,\n ) {\n }\n\n protected validateMessages(reason: string, messages: ISequencedDocumentMessage[], from: number) {\n if (messages.length !== 0) {\n const start = messages[0].sequenceNumber;\n const length = messages.length;\n const last = messages[length - 1].sequenceNumber;\n if (start !== from) {\n this.logger.sendErrorEvent({ eventName: \"OpsFetchViolation\", reason, from, start, last, length });\n messages.length = 0;\n }\n if (last + 1 !== from + length) {\n this.logger.sendErrorEvent({ eventName: \"OpsFetchViolation\", reason, from, start, last, length });\n // we can do better here by finding consecutive sub-block and return it\n messages.length = 0;\n }\n }\n }\n\n public fetchMessages(\n fromTotal: number,\n toTotal: number | undefined,\n abortSignal?: AbortSignal,\n cachedOnly?: boolean,\n fetchReason?: string) {\n // We do not control what's in the cache. Current API assumes that fetchMessages() keeps banging on\n // storage / cache until it gets ops it needs. This would result in deadlock if fixed range is asked from\n // cache and it's not there.\n // Better implementation would be to return only what we have in cache, but that also breaks API\n assert(!cachedOnly || toTotal === undefined, 0x1e3);\n\n let opsFromSnapshot = 0;\n let opsFromCache = 0;\n let opsFromStorage = 0;\n\n const requestCallback = async (from: number, to: number, telemetryProps: ITelemetryProperties) => {\n if (this.snapshotOps !== undefined && this.snapshotOps.length !== 0) {\n const messages = this.snapshotOps.filter((op) =>\n op.sequenceNumber >= from && op.sequenceNumber < to);\n this.validateMessages(\"cached\", messages, from);\n if (messages.length > 0 && messages[0].sequenceNumber === from) {\n this.snapshotOps = this.snapshotOps.filter((op) => op.sequenceNumber >= to);\n opsFromSnapshot = messages.length;\n return { messages, partialResult: true };\n }\n this.snapshotOps = undefined;\n }\n\n // Kick out request to PUSH for ops if it has them\n this.requestFromSocket(from, to);\n\n // Cache in normal flow is continuous. Once there is a miss, stop consulting cache.\n // This saves a bit of processing time\n if (from < this.firstCacheMiss) {\n const messagesFromCache = await this.getCached(from, to);\n this.validateMessages(\"cached\", messagesFromCache, from);\n if (messagesFromCache.length !== 0) {\n opsFromCache += messagesFromCache.length;\n return {\n messages: messagesFromCache,\n partialResult: true,\n };\n }\n this.firstCacheMiss = Math.min(this.firstCacheMiss, from);\n }\n\n if (cachedOnly) {\n return { messages: [], partialResult: false };\n }\n\n const ops = await this.getFromStorage(from, to, telemetryProps, fetchReason);\n this.validateMessages(\"storage\", ops.messages, from);\n opsFromStorage += ops.messages.length;\n this.opsReceived(ops.messages);\n return ops;\n };\n\n const stream = requestOps(\n async (from: number, to: number, telemetryProps: ITelemetryProperties) => {\n const result = await requestCallback(from, to, telemetryProps);\n // Catch all case, just in case\n this.validateMessages(\"catch all\", result.messages, from);\n return result;\n },\n // Staging: starting with no concurrency, listening for feedback first.\n // In future releases we will switch to actual concurrency\n this.concurrency,\n fromTotal, // inclusive\n toTotal, // exclusive\n this.batchSize,\n this.logger,\n abortSignal,\n fetchReason,\n );\n\n return streamObserver(stream, (result) => {\n if (result.done && opsFromSnapshot + opsFromCache + opsFromStorage !== 0) {\n this.logger.sendPerformanceEvent({\n eventName: \"CacheOpsRetrieved\",\n opsFromSnapshot,\n opsFromCache,\n op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OAAe,EAAE,EAAE;gBAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,iCAAM,MAAM,KAAE,GAAG,KAAI,OAAO,CAAC,CAAC;YACtE,CAAC;YACD,IAAI,EAAE,KAAK,EAAE,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,iCAAM,MAAM,KAAE,GAAG,IAAG;YAC9E,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/E,EACD,SAAS,EACT,MAAA,MAAA,IAAI,CAAC,UAAU,CAAC,UAAU,0CAAE,gBAAgB,mCAAI,IAAI,EACpD,MAAA,MAAA,IAAI,CAAC,UAAU,CAAC,UAAU,0CAAE,eAAe,mCAAI,IAAI,CACtD,CAAC;QACF,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,mHAAmH;IACnH,8EAA8E;IACpE,WAAW,CAAC,GAAgC;;QAClD,2CAA2C;QAC3C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE;YACrD,OAAO;SACV;QAED,MAAA,IAAI,CAAC,QAAQ,0CAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACJ;AAxeD,kDAweC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { performance } from \"@fluidframework/common-utils\";\nimport {\n ChildLogger,\n IFluidErrorBase,\n loggerToMonitoringContext,\n MonitoringContext,\n normalizeError,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n IDocumentDeltaConnection,\n IDocumentDeltaStorageService,\n IDocumentService,\n IResolvedUrl,\n IDocumentStorageService,\n IDocumentServicePolicies,\n DriverErrorType,\n} from \"@fluidframework/driver-definitions\";\nimport { canRetryOnError, DeltaStreamConnectionForbiddenError, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { IFacetCodes } from \"@fluidframework/odsp-doclib-utils\";\nimport {\n IClient,\n ISequencedDocumentMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n IOdspResolvedUrl,\n TokenFetchOptions,\n IEntry,\n HostStoragePolicy,\n InstrumentedStorageTokenFetcher,\n OdspErrorType,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport type { io as SocketIOClientStatic } from \"socket.io-client\";\nimport { HostStoragePolicyInternal, ISocketStorageDiscovery } from \"./contracts\";\nimport { IOdspCache } from \"./odspCache\";\nimport { OdspDeltaStorageService, OdspDeltaStorageWithCache } from \"./odspDeltaStorageService\";\nimport { OdspDocumentDeltaConnection } from \"./odspDocumentDeltaConnection\";\nimport { OdspDocumentStorageService } from \"./odspDocumentStorageManager\";\nimport { getWithRetryForTokenRefresh, getOdspResolvedUrl, TokenFetchOptionsEx } from \"./odspUtils\";\nimport { fetchJoinSession } from \"./vroom\";\nimport { isOdcOrigin } from \"./odspUrlHelper\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { OpsCache } from \"./opsCaching\";\nimport { RetryErrorsStorageAdapter } from \"./retryErrorsStorageAdapter\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\n\n/**\n * The DocumentService manages the Socket.IO connection and manages routing requests to connected\n * clients\n */\nexport class OdspDocumentService implements IDocumentService {\n private _policies: IDocumentServicePolicies;\n // Timer which runs and executes the join session call after intervals.\n private joinSessionRefreshTimer: ReturnType<typeof setTimeout> | undefined;\n /**\n * @param resolvedUrl - resolved url identifying document that will be managed by returned service instance.\n * @param getStorageToken - function that can provide the storage token. This is is also referred to as\n * the \"Vroom\" token in SPO.\n * @param getWebsocketToken - function that can provide a token for accessing the web socket. This is also referred\n * to as the \"Push\" token in SPO. If undefined then websocket token is expected to be returned with joinSession\n * response payload.\n * @param logger - a logger that can capture performance and diagnostic information\n * @param socketIoClientFactory - A factory that returns a promise to the socket io library required by the driver\n * @param cache - This caches response for joinSession.\n * @param hostPolicy - This host constructed policy which customizes service behavior.\n * @param epochTracker - This helper class which adds epoch to backend calls made by returned service instance.\n * @param socketReferenceKeyPrefix - (optional) prefix to isolate socket reuse cache\n */\n public static async create(\n resolvedUrl: IResolvedUrl,\n getStorageToken: InstrumentedStorageTokenFetcher,\n getWebsocketToken: ((options: TokenFetchOptions) => Promise<string | null>) | undefined,\n logger: ITelemetryLogger,\n socketIoClientFactory: () => Promise<typeof SocketIOClientStatic>,\n cache: IOdspCache,\n hostPolicy: HostStoragePolicy,\n epochTracker: EpochTracker,\n socketReferenceKeyPrefix?: string,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n return new OdspDocumentService(\n getOdspResolvedUrl(resolvedUrl),\n getStorageToken,\n getWebsocketToken,\n logger,\n socketIoClientFactory,\n cache,\n hostPolicy,\n epochTracker,\n socketReferenceKeyPrefix,\n clientIsSummarizer,\n );\n }\n\n private storageManager?: OdspDocumentStorageService;\n\n private readonly mc: MonitoringContext;\n\n private readonly joinSessionKey: string;\n\n private readonly hostPolicy: HostStoragePolicyInternal;\n\n private _opsCache?: OpsCache;\n\n private currentConnection?: OdspDocumentDeltaConnection;\n\n /**\n * @param odspResolvedUrl - resolved url identifying document that will be managed by this service instance.\n * @param getStorageToken - function that can provide the storage token. This is is also referred to as\n * the \"Vroom\" token in SPO.\n * @param getWebsocketToken - function that can provide a token for accessing the web socket. This is also referred\n * to as the \"Push\" token in SPO. If undefined then websocket token is expected to be returned with joinSession\n * response payload.\n * @param logger - a logger that can capture performance and diagnostic information\n * @param socketIoClientFactory - A factory that returns a promise to the socket io library required by the driver\n * @param cache - This caches response for joinSession.\n * @param hostPolicy - host constructed policy which customizes service behavior.\n * @param epochTracker - This helper class which adds epoch to backend calls made by this service instance.\n * @param socketReferenceKeyPrefix - (optional) prefix to isolate socket reuse cache\n */\n private constructor(\n public readonly odspResolvedUrl: IOdspResolvedUrl,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n private readonly getWebsocketToken: ((options: TokenFetchOptions) => Promise<string | null>) | undefined,\n logger: ITelemetryLogger,\n private readonly socketIoClientFactory: () => Promise<typeof SocketIOClientStatic>,\n private readonly cache: IOdspCache,\n hostPolicy: HostStoragePolicy,\n private readonly epochTracker: EpochTracker,\n private readonly socketReferenceKeyPrefix?: string,\n private readonly clientIsSummarizer?: boolean,\n ) {\n this._policies = {\n // load in storage-only mode if a file version is specified\n storageOnly: odspResolvedUrl.fileVersion !== undefined,\n };\n\n this.joinSessionKey = `${this.odspResolvedUrl.hashedDocumentId}/joinsession`;\n this.mc = loggerToMonitoringContext(\n ChildLogger.create(logger,\n undefined,\n {\n all: {\n odc: isOdcOrigin(new URL(this.odspResolvedUrl.endpoints.snapshotStorageUrl).origin),\n },\n }));\n\n this.hostPolicy = hostPolicy;\n if (this.clientIsSummarizer) {\n this.hostPolicy = { ...this.hostPolicy, summarizerClient: true };\n }\n }\n\n public get resolvedUrl(): IResolvedUrl {\n return this.odspResolvedUrl;\n }\n public get policies() {\n return this._policies;\n }\n\n /**\n * Connects to a storage endpoint for snapshot service.\n *\n * @returns returns the document storage service for sharepoint driver.\n */\n public async connectToStorage(): Promise<IDocumentStorageService> {\n if (!this.storageManager) {\n this.storageManager = new OdspDocumentStorageService(\n this.odspResolvedUrl,\n this.getStorageToken,\n this.mc.logger,\n true,\n this.cache,\n this.hostPolicy,\n this.epochTracker,\n // flushCallback\n async () => {\n if (this.currentConnection !== undefined && !this.currentConnection.disposed) {\n return this.currentConnection.flush();\n }\n throw new Error(\"Disconnected while uploading summary (attempt to perform flush())\");\n },\n this.mc.config.getNumber(\"Fluid.Driver.Odsp.snapshotFormatFetchType\"),\n );\n }\n\n return new RetryErrorsStorageAdapter(this.storageManager, this.mc.logger);\n }\n\n /**\n * Connects to a delta storage endpoint for getting ops between a range.\n *\n * @returns returns the document delta storage service for sharepoint driver.\n */\n public async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {\n const snapshotOps = this.storageManager?.ops ?? [];\n const service = new OdspDeltaStorageService(\n this.odspResolvedUrl.endpoints.deltaStorageUrl,\n this.getStorageToken,\n this.epochTracker,\n this.mc.logger,\n );\n\n // batch size, please see issue #5211 for data around batch sizing\n const batchSize = this.hostPolicy.opsBatchSize ?? 5000;\n const concurrency = this.hostPolicy.concurrentOpsBatches ?? 1;\n return new OdspDeltaStorageWithCache(\n snapshotOps,\n this.mc.logger,\n batchSize,\n concurrency,\n async (from, to, telemetryProps, fetchReason) => service.get(from, to, telemetryProps, fetchReason),\n async (from, to) => {\n const res = await this.opsCache?.get(from, to);\n return res as ISequencedDocumentMessage[] ?? [];\n },\n (from, to) => {\n if (this.currentConnection !== undefined && !this.currentConnection.disposed) {\n this.currentConnection.requestOps(from, to);\n }\n },\n (ops: ISequencedDocumentMessage[]) => this.opsReceived(ops),\n );\n }\n\n /** Annotate the given error indicating which connection step failed */\n private annotateConnectionError(\n error: any,\n failedConnectionStep: string,\n separateTokenRequest: boolean,\n ): IFluidErrorBase {\n return normalizeError(error, { props: {\n failedConnectionStep,\n separateTokenRequest,\n } });\n }\n\n /**\n * Connects to a delta stream endpoint for emitting ops.\n *\n * @returns returns the document delta stream service for onedrive/sharepoint driver.\n */\n public async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {\n // Attempt to connect twice, in case we used expired token.\n return getWithRetryForTokenRefresh<IDocumentDeltaConnection>(async (options) => {\n // Presence of getWebsocketToken callback dictates whether callback is used for fetching\n // websocket token or whether it is returned with joinSession response payload\n const requestWebsocketTokenFromJoinSession = this.getWebsocketToken === undefined;\n const websocketTokenPromise = requestWebsocketTokenFromJoinSession\n ? Promise.resolve(null)\n : this.getWebsocketToken!(options);\n\n const annotateAndRethrowConnectionError = (step: string) => (error: any) => {\n throw this.annotateConnectionError(error, step, !requestWebsocketTokenFromJoinSession);\n };\n\n const joinSessionPromise = this.joinSession(requestWebsocketTokenFromJoinSession, options);\n const [websocketEndpoint, websocketToken, io] =\n await Promise.all([\n joinSessionPromise.catch(annotateAndRethrowConnectionError(\"joinSession\")),\n websocketTokenPromise.catch(annotateAndRethrowConnectionError(\"getWebsocketToken\")),\n this.socketIoClientFactory().catch(annotateAndRethrowConnectionError(\"socketIoClientFactory\")),\n ]);\n\n const finalWebsocketToken = websocketToken ?? (websocketEndpoint.socketToken || null);\n if (finalWebsocketToken === null) {\n throw this.annotateConnectionError(\n new NonRetryableError(\n \"Websocket token is null\",\n OdspErrorType.fetchTokenError,\n { driverVersion },\n ),\n \"getWebsocketToken\",\n !requestWebsocketTokenFromJoinSession);\n }\n try {\n const connection = await this.createDeltaConnection(\n websocketEndpoint.tenantId,\n websocketEndpoint.id,\n finalWebsocketToken,\n io,\n client,\n websocketEndpoint.deltaStreamSocketUrl);\n connection.on(\"op\", (documentId, ops: ISequencedDocumentMessage[]) => {\n this.opsReceived(ops);\n });\n // On disconnect with 401/403 error code, we can just clear the joinSession cache as we will again\n // get the auth error on reconnecting and face latency.\n connection.on(\"disconnect\", (error: any) => {\n // Clear the join session refresh timer so that it can be restarted on reconnection.\n this.clearJoinSessionTimer();\n if (typeof error === \"object\" && error !== null\n && error.errorType === DriverErrorType.authorizationError) {\n this.cache.sessionJoinCache.remove(this.joinSessionKey);\n }\n });\n this.currentConnection = connection;\n return connection;\n } catch (error) {\n this.cache.sessionJoinCache.remove(this.joinSessionKey);\n\n const normalizedError = this.annotateConnectionError(\n error,\n \"createDeltaConnection\",\n !requestWebsocketTokenFromJoinSession);\n if (typeof error === \"object\" && error !== null) {\n normalizedError.addTelemetryProperties({ socketDocumentId: websocketEndpoint.id });\n }\n throw normalizedError;\n }\n });\n }\n\n private clearJoinSessionTimer() {\n if (this.joinSessionRefreshTimer !== undefined) {\n clearTimeout(this.joinSessionRefreshTimer);\n this.joinSessionRefreshTimer = undefined;\n }\n }\n\n private async scheduleJoinSessionRefresh(delta: number) {\n await new Promise<void>((resolve, reject) => {\n this.joinSessionRefreshTimer = setTimeout(() => {\n getWithRetryForTokenRefresh(async (options) => {\n await this.joinSession(false, options);\n resolve();\n }).catch((error) => {\n reject(error);\n });\n }, delta);\n });\n }\n\n private async joinSession(\n requestSocketToken: boolean,\n options: TokenFetchOptionsEx,\n ) {\n return this.joinSessionCore(requestSocketToken, options).catch((e) => {\n const likelyFacetCodes = e as IFacetCodes;\n if (Array.isArray(likelyFacetCodes.facetCodes)) {\n for (const code of likelyFacetCodes.facetCodes) {\n switch (code) {\n case \"sessionForbiddenOnPreservedFiles\":\n case \"sessionForbiddenOnModerationEnabledLibrary\":\n case \"sessionForbiddenOnRequireCheckout\":\n // This document can only be opened in storage-only mode.\n // DeltaManager will recognize this error\n // and load without a delta stream connection.\n this._policies = { ...this._policies, storageOnly: true };\n throw new DeltaStreamConnectionForbiddenError(code, { driverVersion });\n default:\n continue;\n }\n }\n }\n throw e;\n });\n }\n\n private async joinSessionCore(\n requestSocketToken: boolean,\n options: TokenFetchOptionsEx,\n ): Promise<ISocketStorageDiscovery> {\n const disableJoinSessionRefresh = this.mc.config.getBoolean(\"Fluid.Driver.Odsp.disableJoinSessionRefresh\");\n const executeFetch = async () => {\n const joinSessionResponse = await fetchJoinSession(\n this.odspResolvedUrl,\n \"opStream/joinSession\",\n \"POST\",\n this.mc.logger,\n this.getStorageToken,\n this.epochTracker,\n requestSocketToken,\n options,\n disableJoinSessionRefresh,\n this.hostPolicy.sessionOptions?.unauthenticatedUserDisplayName,\n );\n return {\n entryTime: Date.now(),\n joinSessionResponse,\n };\n };\n\n const getResponseAndRefreshAfterDeltaMs = async () => {\n const _response = await this.cache.sessionJoinCache.addOrGet(this.joinSessionKey, executeFetch);\n // If the response does not contain refreshSessionDurationSeconds, then treat it as old flow and let the\n // cache entry to be treated as expired after 1 hour.\n _response.joinSessionResponse.refreshSessionDurationSeconds =\n _response.joinSessionResponse.refreshSessionDurationSeconds ?? 3600;\n return {\n ..._response,\n refreshAfterDeltaMs: this.calculateJoinSessionRefreshDelta(\n _response.entryTime, _response.joinSessionResponse.refreshSessionDurationSeconds),\n };\n };\n let response = await getResponseAndRefreshAfterDeltaMs();\n // This means that the cached entry has expired(This should not be possible if the response is fetched\n // from the network call). In this case we remove the cached entry and fetch the new response.\n if (response.refreshAfterDeltaMs <= 0) {\n this.cache.sessionJoinCache.remove(this.joinSessionKey);\n response = await getResponseAndRefreshAfterDeltaMs();\n }\n if (!disableJoinSessionRefresh) {\n const props = {\n entryTime: response.entryTime,\n refreshSessionDurationSeconds:\n response.joinSessionResponse.refreshSessionDurationSeconds,\n refreshAfterDeltaMs: response.refreshAfterDeltaMs,\n };\n if (response.refreshAfterDeltaMs > 0) {\n this.scheduleJoinSessionRefresh(response.refreshAfterDeltaMs)\n .catch((error) => {\n const canRetry = canRetryOnError(error);\n // Only record error event in case it is non retriable.\n if (!canRetry) {\n this.mc.logger.sendErrorEvent({\n eventName: \"JoinSessionRefreshError\",\n details: JSON.stringify(props),\n },\n error,\n );\n }\n });\n } else {\n // Logging just for informational purposes to help with debugging as this is a new feature.\n this.mc.logger.sendTelemetryEvent({\n eventName: \"JoinSessionRefreshNotScheduled\",\n details: JSON.stringify(props),\n });\n }\n }\n return response.joinSessionResponse;\n }\n\n private calculateJoinSessionRefreshDelta(responseFetchTime: number, refreshSessionDurationSeconds: number) {\n // 30 seconds is buffer time to refresh the session.\n return responseFetchTime + ((refreshSessionDurationSeconds * 1000) - 30000) - Date.now();\n }\n\n /**\n * Creats a connection to the given delta stream endpoint\n *\n * @param tenantId - the ID of the tenant\n * @param documentId - document ID\n * @param token - authorization token for delta service\n * @param io - websocket library\n * @param client - information about the client\n * @param webSocketUrl - websocket URL\n */\n private async createDeltaConnection(\n tenantId: string,\n documentId: string,\n token: string | null,\n io: typeof SocketIOClientStatic,\n client: IClient,\n webSocketUrl: string,\n ): Promise<OdspDocumentDeltaConnection> {\n const startTime = performance.now();\n const connection = await OdspDocumentDeltaConnection.create(\n tenantId,\n documentId,\n token,\n io,\n client,\n webSocketUrl,\n this.mc.logger,\n 60000,\n this.epochTracker,\n this.socketReferenceKeyPrefix,\n );\n const duration = performance.now() - startTime;\n // This event happens rather often, so it adds up to cost of telemetry.\n // Given that most reconnects result in reusing socket and happen very quickly,\n // report event only if it took longer than threshold.\n if (duration >= 2000) {\n this.mc.logger.sendPerformanceEvent({\n eventName: \"ConnectionSuccess\",\n duration,\n });\n }\n return connection;\n }\n\n public dispose(error?: any) {\n // Error might indicate mismatch between client & server knowlege about file\n // (DriverErrorType.fileOverwrittenInStorage).\n // For example, file might have been overwritten in storage without generating new epoch\n // In such case client cached info is stale and has to be removed.\n if (error !== undefined) {\n this.epochTracker.removeEntries().catch(() => {});\n } else {\n this._opsCache?.flushOps();\n }\n this._opsCache?.dispose();\n }\n\n protected get opsCache() {\n if (this._opsCache) {\n return this._opsCache;\n }\n\n const seqNumber = this.storageManager?.snapshotSequenceNumber;\n const batchSize = this.hostPolicy.opsCaching?.batchSize ?? 100;\n if (seqNumber === undefined || batchSize < 1) {\n return;\n }\n\n const opsKey: Omit<IEntry, \"key\"> = {\n type: \"ops\",\n };\n this._opsCache = new OpsCache(\n seqNumber,\n this.mc.logger,\n // ICache\n {\n write: async (key: string, opsData: string) => {\n return this.cache.persistedCache.put({ ...opsKey, key }, opsData);\n },\n read: async (key: string) => this.cache.persistedCache.get({ ...opsKey, key }),\n remove: () => { this.cache.persistedCache.removeEntries().catch(() => {}); },\n },\n batchSize,\n this.hostPolicy.opsCaching?.timerGranularity ?? 5000,\n this.hostPolicy.opsCaching?.totalOpsToCache ?? 5000,\n );\n return this._opsCache;\n }\n\n // Called whenever re receive ops through any channel for this document (snapshot, delta connection, delta storage)\n // We use it to notify caching layer of how stale is snapshot stored in cache.\n protected opsReceived(ops: ISequencedDocumentMessage[]) {\n // No need for two clients to save same ops\n if (ops.length === 0 || this.odspResolvedUrl.summarizer) {\n return;\n }\n\n this.opsCache?.addOps(ops);\n }\n}\n"]}
1
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E,EAAE;gBAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,iCAAM,MAAM,KAAE,GAAG,KAAI,OAAO,CAAC,CAAC;YACtE,CAAC;YACD,IAAI,EAAE,KAAK,EAAE,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,iCAAM,MAAM,KAAE,GAAG,IAAG;YAC9E,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/E,EACD,SAAS,EACT,MAAA,MAAA,IAAI,CAAC,UAAU,CAAC,UAAU,0CAAE,gBAAgB,mCAAI,IAAI,EACpD,MAAA,MAAA,IAAI,CAAC,UAAU,CAAC,UAAU,0CAAE,eAAe,mCAAI,IAAI,CACtD,CAAC;QACF,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,mHAAmH;IACnH,8EAA8E;IACpE,WAAW,CAAC,GAAgC;;QAClD,2CAA2C;QAC3C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE;YACrD,OAAO;SACV;QAED,MAAA,IAAI,CAAC,QAAQ,0CAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACJ;AAxeD,kDAweC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { performance } from \"@fluidframework/common-utils\";\nimport {\n ChildLogger,\n IFluidErrorBase,\n loggerToMonitoringContext,\n MonitoringContext,\n normalizeError,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n IDocumentDeltaConnection,\n IDocumentDeltaStorageService,\n IDocumentService,\n IResolvedUrl,\n IDocumentStorageService,\n IDocumentServicePolicies,\n DriverErrorType,\n} from \"@fluidframework/driver-definitions\";\nimport {\n canRetryOnError,\n DeltaStreamConnectionForbiddenError,\n NonRetryableError,\n} from \"@fluidframework/driver-utils\";\nimport { IFacetCodes } from \"@fluidframework/odsp-doclib-utils\";\nimport {\n IClient,\n ISequencedDocumentMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n IOdspResolvedUrl,\n TokenFetchOptions,\n IEntry,\n HostStoragePolicy,\n InstrumentedStorageTokenFetcher,\n OdspErrorType,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport type { io as SocketIOClientStatic } from \"socket.io-client\";\nimport { HostStoragePolicyInternal, ISocketStorageDiscovery } from \"./contracts\";\nimport { IOdspCache } from \"./odspCache\";\nimport { OdspDeltaStorageService, OdspDeltaStorageWithCache } from \"./odspDeltaStorageService\";\nimport { OdspDocumentDeltaConnection } from \"./odspDocumentDeltaConnection\";\nimport { OdspDocumentStorageService } from \"./odspDocumentStorageManager\";\nimport { getWithRetryForTokenRefresh, getOdspResolvedUrl, TokenFetchOptionsEx } from \"./odspUtils\";\nimport { fetchJoinSession } from \"./vroom\";\nimport { isOdcOrigin } from \"./odspUrlHelper\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { OpsCache } from \"./opsCaching\";\nimport { RetryErrorsStorageAdapter } from \"./retryErrorsStorageAdapter\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\n\n/**\n * The DocumentService manages the Socket.IO connection and manages routing requests to connected\n * clients\n */\nexport class OdspDocumentService implements IDocumentService {\n private _policies: IDocumentServicePolicies;\n // Timer which runs and executes the join session call after intervals.\n private joinSessionRefreshTimer: ReturnType<typeof setTimeout> | undefined;\n /**\n * @param resolvedUrl - resolved url identifying document that will be managed by returned service instance.\n * @param getStorageToken - function that can provide the storage token. This is is also referred to as\n * the \"Vroom\" token in SPO.\n * @param getWebsocketToken - function that can provide a token for accessing the web socket. This is also referred\n * to as the \"Push\" token in SPO. If undefined then websocket token is expected to be returned with joinSession\n * response payload.\n * @param logger - a logger that can capture performance and diagnostic information\n * @param socketIoClientFactory - A factory that returns a promise to the socket io library required by the driver\n * @param cache - This caches response for joinSession.\n * @param hostPolicy - This host constructed policy which customizes service behavior.\n * @param epochTracker - This helper class which adds epoch to backend calls made by returned service instance.\n * @param socketReferenceKeyPrefix - (optional) prefix to isolate socket reuse cache\n */\n public static async create(\n resolvedUrl: IResolvedUrl,\n getStorageToken: InstrumentedStorageTokenFetcher,\n getWebsocketToken: ((options: TokenFetchOptions) => Promise<string | null>) | undefined,\n logger: ITelemetryLogger,\n socketIoClientFactory: () => Promise<typeof SocketIOClientStatic>,\n cache: IOdspCache,\n hostPolicy: HostStoragePolicy,\n epochTracker: EpochTracker,\n socketReferenceKeyPrefix?: string,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n return new OdspDocumentService(\n getOdspResolvedUrl(resolvedUrl),\n getStorageToken,\n getWebsocketToken,\n logger,\n socketIoClientFactory,\n cache,\n hostPolicy,\n epochTracker,\n socketReferenceKeyPrefix,\n clientIsSummarizer,\n );\n }\n\n private storageManager?: OdspDocumentStorageService;\n\n private readonly mc: MonitoringContext;\n\n private readonly joinSessionKey: string;\n\n private readonly hostPolicy: HostStoragePolicyInternal;\n\n private _opsCache?: OpsCache;\n\n private currentConnection?: OdspDocumentDeltaConnection;\n\n /**\n * @param odspResolvedUrl - resolved url identifying document that will be managed by this service instance.\n * @param getStorageToken - function that can provide the storage token. This is is also referred to as\n * the \"Vroom\" token in SPO.\n * @param getWebsocketToken - function that can provide a token for accessing the web socket. This is also referred\n * to as the \"Push\" token in SPO. If undefined then websocket token is expected to be returned with joinSession\n * response payload.\n * @param logger - a logger that can capture performance and diagnostic information\n * @param socketIoClientFactory - A factory that returns a promise to the socket io library required by the driver\n * @param cache - This caches response for joinSession.\n * @param hostPolicy - host constructed policy which customizes service behavior.\n * @param epochTracker - This helper class which adds epoch to backend calls made by this service instance.\n * @param socketReferenceKeyPrefix - (optional) prefix to isolate socket reuse cache\n */\n private constructor(\n public readonly odspResolvedUrl: IOdspResolvedUrl,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n private readonly getWebsocketToken: ((options: TokenFetchOptions) => Promise<string | null>) | undefined,\n logger: ITelemetryLogger,\n private readonly socketIoClientFactory: () => Promise<typeof SocketIOClientStatic>,\n private readonly cache: IOdspCache,\n hostPolicy: HostStoragePolicy,\n private readonly epochTracker: EpochTracker,\n private readonly socketReferenceKeyPrefix?: string,\n private readonly clientIsSummarizer?: boolean,\n ) {\n this._policies = {\n // load in storage-only mode if a file version is specified\n storageOnly: odspResolvedUrl.fileVersion !== undefined,\n };\n\n this.joinSessionKey = `${this.odspResolvedUrl.hashedDocumentId}/joinsession`;\n this.mc = loggerToMonitoringContext(\n ChildLogger.create(logger,\n undefined,\n {\n all: {\n odc: isOdcOrigin(new URL(this.odspResolvedUrl.endpoints.snapshotStorageUrl).origin),\n },\n }));\n\n this.hostPolicy = hostPolicy;\n if (this.clientIsSummarizer) {\n this.hostPolicy = { ...this.hostPolicy, summarizerClient: true };\n }\n }\n\n public get resolvedUrl(): IResolvedUrl {\n return this.odspResolvedUrl;\n }\n public get policies() {\n return this._policies;\n }\n\n /**\n * Connects to a storage endpoint for snapshot service.\n *\n * @returns returns the document storage service for sharepoint driver.\n */\n public async connectToStorage(): Promise<IDocumentStorageService> {\n if (!this.storageManager) {\n this.storageManager = new OdspDocumentStorageService(\n this.odspResolvedUrl,\n this.getStorageToken,\n this.mc.logger,\n true,\n this.cache,\n this.hostPolicy,\n this.epochTracker,\n // flushCallback\n async () => {\n if (this.currentConnection !== undefined && !this.currentConnection.disposed) {\n return this.currentConnection.flush();\n }\n throw new Error(\"Disconnected while uploading summary (attempt to perform flush())\");\n },\n this.mc.config.getNumber(\"Fluid.Driver.Odsp.snapshotFormatFetchType\"),\n );\n }\n\n return new RetryErrorsStorageAdapter(this.storageManager, this.mc.logger);\n }\n\n /**\n * Connects to a delta storage endpoint for getting ops between a range.\n *\n * @returns returns the document delta storage service for sharepoint driver.\n */\n public async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {\n const snapshotOps = this.storageManager?.ops ?? [];\n const service = new OdspDeltaStorageService(\n this.odspResolvedUrl.endpoints.deltaStorageUrl,\n this.getStorageToken,\n this.epochTracker,\n this.mc.logger,\n );\n\n // batch size, please see issue #5211 for data around batch sizing\n const batchSize = this.hostPolicy.opsBatchSize ?? 5000;\n const concurrency = this.hostPolicy.concurrentOpsBatches ?? 1;\n return new OdspDeltaStorageWithCache(\n snapshotOps,\n this.mc.logger,\n batchSize,\n concurrency,\n async (from, to, telemetryProps, fetchReason) => service.get(from, to, telemetryProps, fetchReason),\n async (from, to) => {\n const res = await this.opsCache?.get(from, to);\n return res as ISequencedDocumentMessage[] ?? [];\n },\n (from, to) => {\n if (this.currentConnection !== undefined && !this.currentConnection.disposed) {\n this.currentConnection.requestOps(from, to);\n }\n },\n (ops: ISequencedDocumentMessage[]) => this.opsReceived(ops),\n );\n }\n\n /** Annotate the given error indicating which connection step failed */\n private annotateConnectionError(\n error: any,\n failedConnectionStep: string,\n separateTokenRequest: boolean,\n ): IFluidErrorBase {\n return normalizeError(error, { props: {\n failedConnectionStep,\n separateTokenRequest,\n } });\n }\n\n /**\n * Connects to a delta stream endpoint for emitting ops.\n *\n * @returns returns the document delta stream service for onedrive/sharepoint driver.\n */\n public async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {\n // Attempt to connect twice, in case we used expired token.\n return getWithRetryForTokenRefresh<IDocumentDeltaConnection>(async (options) => {\n // Presence of getWebsocketToken callback dictates whether callback is used for fetching\n // websocket token or whether it is returned with joinSession response payload\n const requestWebsocketTokenFromJoinSession = this.getWebsocketToken === undefined;\n const websocketTokenPromise = requestWebsocketTokenFromJoinSession\n ? Promise.resolve(null)\n : this.getWebsocketToken!(options);\n\n const annotateAndRethrowConnectionError = (step: string) => (error: any) => {\n throw this.annotateConnectionError(error, step, !requestWebsocketTokenFromJoinSession);\n };\n\n const joinSessionPromise = this.joinSession(requestWebsocketTokenFromJoinSession, options);\n const [websocketEndpoint, websocketToken, io] =\n await Promise.all([\n joinSessionPromise.catch(annotateAndRethrowConnectionError(\"joinSession\")),\n websocketTokenPromise.catch(annotateAndRethrowConnectionError(\"getWebsocketToken\")),\n this.socketIoClientFactory().catch(annotateAndRethrowConnectionError(\"socketIoClientFactory\")),\n ]);\n\n const finalWebsocketToken = websocketToken ?? (websocketEndpoint.socketToken || null);\n if (finalWebsocketToken === null) {\n throw this.annotateConnectionError(\n new NonRetryableError(\n \"Websocket token is null\",\n OdspErrorType.fetchTokenError,\n { driverVersion },\n ),\n \"getWebsocketToken\",\n !requestWebsocketTokenFromJoinSession);\n }\n try {\n const connection = await this.createDeltaConnection(\n websocketEndpoint.tenantId,\n websocketEndpoint.id,\n finalWebsocketToken,\n io,\n client,\n websocketEndpoint.deltaStreamSocketUrl);\n connection.on(\"op\", (documentId, ops: ISequencedDocumentMessage[]) => {\n this.opsReceived(ops);\n });\n // On disconnect with 401/403 error code, we can just clear the joinSession cache as we will again\n // get the auth error on reconnecting and face latency.\n connection.on(\"disconnect\", (error: any) => {\n // Clear the join session refresh timer so that it can be restarted on reconnection.\n this.clearJoinSessionTimer();\n if (typeof error === \"object\" && error !== null\n && error.errorType === DriverErrorType.authorizationError) {\n this.cache.sessionJoinCache.remove(this.joinSessionKey);\n }\n });\n this.currentConnection = connection;\n return connection;\n } catch (error) {\n this.cache.sessionJoinCache.remove(this.joinSessionKey);\n\n const normalizedError = this.annotateConnectionError(\n error,\n \"createDeltaConnection\",\n !requestWebsocketTokenFromJoinSession);\n if (typeof error === \"object\" && error !== null) {\n normalizedError.addTelemetryProperties({ socketDocumentId: websocketEndpoint.id });\n }\n throw normalizedError;\n }\n });\n }\n\n private clearJoinSessionTimer() {\n if (this.joinSessionRefreshTimer !== undefined) {\n clearTimeout(this.joinSessionRefreshTimer);\n this.joinSessionRefreshTimer = undefined;\n }\n }\n\n private async scheduleJoinSessionRefresh(delta: number) {\n await new Promise<void>((resolve, reject) => {\n this.joinSessionRefreshTimer = setTimeout(() => {\n getWithRetryForTokenRefresh(async (options) => {\n await this.joinSession(false, options);\n resolve();\n }).catch((error) => {\n reject(error);\n });\n }, delta);\n });\n }\n\n private async joinSession(\n requestSocketToken: boolean,\n options: TokenFetchOptionsEx,\n ) {\n return this.joinSessionCore(requestSocketToken, options).catch((e) => {\n const likelyFacetCodes = e as IFacetCodes;\n if (Array.isArray(likelyFacetCodes.facetCodes)) {\n for (const code of likelyFacetCodes.facetCodes) {\n switch (code) {\n case \"sessionForbiddenOnPreservedFiles\":\n case \"sessionForbiddenOnModerationEnabledLibrary\":\n case \"sessionForbiddenOnRequireCheckout\":\n // This document can only be opened in storage-only mode.\n // DeltaManager will recognize this error\n // and load without a delta stream connection.\n this._policies = { ...this._policies, storageOnly: true };\n throw new DeltaStreamConnectionForbiddenError(code, { driverVersion });\n default:\n continue;\n }\n }\n }\n throw e;\n });\n }\n\n private async joinSessionCore(\n requestSocketToken: boolean,\n options: TokenFetchOptionsEx,\n ): Promise<ISocketStorageDiscovery> {\n const disableJoinSessionRefresh = this.mc.config.getBoolean(\"Fluid.Driver.Odsp.disableJoinSessionRefresh\");\n const executeFetch = async () => {\n const joinSessionResponse = await fetchJoinSession(\n this.odspResolvedUrl,\n \"opStream/joinSession\",\n \"POST\",\n this.mc.logger,\n this.getStorageToken,\n this.epochTracker,\n requestSocketToken,\n options,\n disableJoinSessionRefresh,\n this.hostPolicy.sessionOptions?.unauthenticatedUserDisplayName,\n );\n return {\n entryTime: Date.now(),\n joinSessionResponse,\n };\n };\n\n const getResponseAndRefreshAfterDeltaMs = async () => {\n const _response = await this.cache.sessionJoinCache.addOrGet(this.joinSessionKey, executeFetch);\n // If the response does not contain refreshSessionDurationSeconds, then treat it as old flow and let the\n // cache entry to be treated as expired after 1 hour.\n _response.joinSessionResponse.refreshSessionDurationSeconds =\n _response.joinSessionResponse.refreshSessionDurationSeconds ?? 3600;\n return {\n ..._response,\n refreshAfterDeltaMs: this.calculateJoinSessionRefreshDelta(\n _response.entryTime, _response.joinSessionResponse.refreshSessionDurationSeconds),\n };\n };\n let response = await getResponseAndRefreshAfterDeltaMs();\n // This means that the cached entry has expired(This should not be possible if the response is fetched\n // from the network call). In this case we remove the cached entry and fetch the new response.\n if (response.refreshAfterDeltaMs <= 0) {\n this.cache.sessionJoinCache.remove(this.joinSessionKey);\n response = await getResponseAndRefreshAfterDeltaMs();\n }\n if (!disableJoinSessionRefresh) {\n const props = {\n entryTime: response.entryTime,\n refreshSessionDurationSeconds:\n response.joinSessionResponse.refreshSessionDurationSeconds,\n refreshAfterDeltaMs: response.refreshAfterDeltaMs,\n };\n if (response.refreshAfterDeltaMs > 0) {\n this.scheduleJoinSessionRefresh(response.refreshAfterDeltaMs)\n .catch((error) => {\n const canRetry = canRetryOnError(error);\n // Only record error event in case it is non retriable.\n if (!canRetry) {\n this.mc.logger.sendErrorEvent({\n eventName: \"JoinSessionRefreshError\",\n details: JSON.stringify(props),\n },\n error,\n );\n }\n });\n } else {\n // Logging just for informational purposes to help with debugging as this is a new feature.\n this.mc.logger.sendTelemetryEvent({\n eventName: \"JoinSessionRefreshNotScheduled\",\n details: JSON.stringify(props),\n });\n }\n }\n return response.joinSessionResponse;\n }\n\n private calculateJoinSessionRefreshDelta(responseFetchTime: number, refreshSessionDurationSeconds: number) {\n // 30 seconds is buffer time to refresh the session.\n return responseFetchTime + ((refreshSessionDurationSeconds * 1000) - 30000) - Date.now();\n }\n\n /**\n * Creats a connection to the given delta stream endpoint\n *\n * @param tenantId - the ID of the tenant\n * @param documentId - document ID\n * @param token - authorization token for delta service\n * @param io - websocket library\n * @param client - information about the client\n * @param webSocketUrl - websocket URL\n */\n private async createDeltaConnection(\n tenantId: string,\n documentId: string,\n token: string | null,\n io: typeof SocketIOClientStatic,\n client: IClient,\n webSocketUrl: string,\n ): Promise<OdspDocumentDeltaConnection> {\n const startTime = performance.now();\n const connection = await OdspDocumentDeltaConnection.create(\n tenantId,\n documentId,\n token,\n io,\n client,\n webSocketUrl,\n this.mc.logger,\n 60000,\n this.epochTracker,\n this.socketReferenceKeyPrefix,\n );\n const duration = performance.now() - startTime;\n // This event happens rather often, so it adds up to cost of telemetry.\n // Given that most reconnects result in reusing socket and happen very quickly,\n // report event only if it took longer than threshold.\n if (duration >= 2000) {\n this.mc.logger.sendPerformanceEvent({\n eventName: \"ConnectionSuccess\",\n duration,\n });\n }\n return connection;\n }\n\n public dispose(error?: any) {\n // Error might indicate mismatch between client & server knowlege about file\n // (DriverErrorType.fileOverwrittenInStorage).\n // For example, file might have been overwritten in storage without generating new epoch\n // In such case client cached info is stale and has to be removed.\n if (error !== undefined) {\n this.epochTracker.removeEntries().catch(() => {});\n } else {\n this._opsCache?.flushOps();\n }\n this._opsCache?.dispose();\n }\n\n protected get opsCache() {\n if (this._opsCache) {\n return this._opsCache;\n }\n\n const seqNumber = this.storageManager?.snapshotSequenceNumber;\n const batchSize = this.hostPolicy.opsCaching?.batchSize ?? 100;\n if (seqNumber === undefined || batchSize < 1) {\n return;\n }\n\n const opsKey: Omit<IEntry, \"key\"> = {\n type: \"ops\",\n };\n this._opsCache = new OpsCache(\n seqNumber,\n this.mc.logger,\n // ICache\n {\n write: async (key: string, opsData: string) => {\n return this.cache.persistedCache.put({ ...opsKey, key }, opsData);\n },\n read: async (key: string) => this.cache.persistedCache.get({ ...opsKey, key }),\n remove: () => { this.cache.persistedCache.removeEntries().catch(() => {}); },\n },\n batchSize,\n this.hostPolicy.opsCaching?.timerGranularity ?? 5000,\n this.hostPolicy.opsCaching?.totalOpsToCache ?? 5000,\n );\n return this._opsCache;\n }\n\n // Called whenever re receive ops through any channel for this document (snapshot, delta connection, delta storage)\n // We use it to notify caching layer of how stale is snapshot stored in cache.\n protected opsReceived(ops: ISequencedDocumentMessage[]) {\n // No need for two clients to save same ops\n if (ops.length === 0 || this.odspResolvedUrl.summarizer) {\n return;\n }\n\n this.opsCache?.addOps(ops);\n }\n}\n"]}
@@ -9,7 +9,8 @@ import { OdspDocumentServiceFactoryCore } from "./odspDocumentServiceFactoryCore
9
9
  * Factory for creating the sharepoint document service. Use this if you want to
10
10
  * use the sharepoint implementation.
11
11
  */
12
- export declare class OdspDocumentServiceFactory extends OdspDocumentServiceFactoryCore implements IDocumentServiceFactory {
12
+ export declare class OdspDocumentServiceFactory extends OdspDocumentServiceFactoryCore {
13
13
  constructor(getStorageToken: TokenFetcher<OdspResourceTokenFetchOptions>, getWebsocketToken: TokenFetcher<OdspResourceTokenFetchOptions> | undefined, persistedCache?: IPersistedCache, hostPolicy?: HostStoragePolicy);
14
14
  }
15
+ export declare function createLocalOdspDocumentServiceFactory(localSnapshot: Uint8Array | string): IDocumentServiceFactory;
15
16
  //# sourceMappingURL=odspDocumentServiceFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"odspDocumentServiceFactory.d.ts","sourceRoot":"","sources":["../src/odspDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EACH,6BAA6B,EAC7B,YAAY,EACZ,eAAe,EACf,iBAAiB,EACpB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAGlF;;;GAGG;AACH,qBAAa,0BACT,SAAQ,8BACR,YAAW,uBAAuB;gBAE9B,eAAe,EAAE,YAAY,CAAC,6BAA6B,CAAC,EAC5D,iBAAiB,EAAE,YAAY,CAAC,6BAA6B,CAAC,GAAG,SAAS,EAC1E,cAAc,CAAC,EAAE,eAAe,EAChC,UAAU,CAAC,EAAE,iBAAiB;CAUrC"}
1
+ {"version":3,"file":"odspDocumentServiceFactory.d.ts","sourceRoot":"","sources":["../src/odspDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EACH,6BAA6B,EAC7B,YAAY,EACZ,eAAe,EACf,iBAAiB,EACpB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAKlF;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,8BAA8B;gBAEtE,eAAe,EAAE,YAAY,CAAC,6BAA6B,CAAC,EAC5D,iBAAiB,EAAE,YAAY,CAAC,6BAA6B,CAAC,GAAG,SAAS,EAC1E,cAAc,CAAC,EAAE,eAAe,EAChC,UAAU,CAAC,EAAE,iBAAiB;CAUrC;AAED,wBAAgB,qCAAqC,CAAC,aAAa,EAAE,UAAU,GAAG,MAAM,GAAG,uBAAuB,CAEjH"}