@fluidframework/routerlicious-driver 2.0.0-dev.4.1.0.148229 → 2.0.0-dev.4.2.0.153917

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 (145) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +38 -0
  3. package/dist/deltaStorageService.d.ts +1 -1
  4. package/dist/deltaStorageService.d.ts.map +1 -1
  5. package/dist/deltaStorageService.js +7 -4
  6. package/dist/deltaStorageService.js.map +1 -1
  7. package/dist/documentService.d.ts +4 -2
  8. package/dist/documentService.d.ts.map +1 -1
  9. package/dist/documentService.js +11 -9
  10. package/dist/documentService.js.map +1 -1
  11. package/dist/documentServiceFactory.d.ts +2 -1
  12. package/dist/documentServiceFactory.d.ts.map +1 -1
  13. package/dist/documentServiceFactory.js +18 -8
  14. package/dist/documentServiceFactory.js.map +1 -1
  15. package/dist/documentStorageService.d.ts +3 -2
  16. package/dist/documentStorageService.d.ts.map +1 -1
  17. package/dist/documentStorageService.js +4 -4
  18. package/dist/documentStorageService.js.map +1 -1
  19. package/dist/gitManager.d.ts +30 -0
  20. package/dist/gitManager.d.ts.map +1 -0
  21. package/dist/gitManager.js +89 -0
  22. package/dist/gitManager.js.map +1 -0
  23. package/dist/historian.d.ts +33 -0
  24. package/dist/historian.d.ts.map +1 -0
  25. package/dist/historian.js +65 -0
  26. package/dist/historian.js.map +1 -0
  27. package/dist/packageVersion.d.ts +1 -1
  28. package/dist/packageVersion.js +1 -1
  29. package/dist/packageVersion.js.map +1 -1
  30. package/dist/restWrapper.d.ts +21 -8
  31. package/dist/restWrapper.d.ts.map +1 -1
  32. package/dist/restWrapper.js +93 -25
  33. package/dist/restWrapper.js.map +1 -1
  34. package/dist/restWrapperBase.d.ts +26 -0
  35. package/dist/restWrapperBase.d.ts.map +1 -0
  36. package/dist/restWrapperBase.js +55 -0
  37. package/dist/restWrapperBase.js.map +1 -0
  38. package/dist/retriableGitManager.d.ts +10 -21
  39. package/dist/retriableGitManager.d.ts.map +1 -1
  40. package/dist/retriableGitManager.js +0 -36
  41. package/dist/retriableGitManager.js.map +1 -1
  42. package/dist/shreddedSummaryDocumentStorageService.d.ts +1 -1
  43. package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
  44. package/dist/shreddedSummaryDocumentStorageService.js +6 -6
  45. package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
  46. package/dist/storageContracts.d.ts +44 -0
  47. package/dist/storageContracts.d.ts.map +1 -0
  48. package/dist/storageContracts.js +7 -0
  49. package/dist/storageContracts.js.map +1 -0
  50. package/dist/summaryTreeUploadManager.d.ts +23 -0
  51. package/dist/summaryTreeUploadManager.d.ts.map +1 -0
  52. package/dist/summaryTreeUploadManager.js +110 -0
  53. package/dist/summaryTreeUploadManager.js.map +1 -0
  54. package/dist/treeUtils.d.ts +7 -0
  55. package/dist/treeUtils.d.ts.map +1 -1
  56. package/dist/treeUtils.js +23 -1
  57. package/dist/treeUtils.js.map +1 -1
  58. package/dist/wholeSummaryDocumentStorageService.d.ts +5 -4
  59. package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
  60. package/dist/wholeSummaryDocumentStorageService.js +68 -35
  61. package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
  62. package/dist/wholeSummaryUploadManager.d.ts +16 -0
  63. package/dist/wholeSummaryUploadManager.d.ts.map +1 -0
  64. package/dist/wholeSummaryUploadManager.js +38 -0
  65. package/dist/wholeSummaryUploadManager.js.map +1 -0
  66. package/lib/deltaStorageService.d.ts +1 -1
  67. package/lib/deltaStorageService.d.ts.map +1 -1
  68. package/lib/deltaStorageService.js +7 -4
  69. package/lib/deltaStorageService.js.map +1 -1
  70. package/lib/documentService.d.ts +4 -2
  71. package/lib/documentService.d.ts.map +1 -1
  72. package/lib/documentService.js +9 -7
  73. package/lib/documentService.js.map +1 -1
  74. package/lib/documentServiceFactory.d.ts +2 -1
  75. package/lib/documentServiceFactory.d.ts.map +1 -1
  76. package/lib/documentServiceFactory.js +18 -8
  77. package/lib/documentServiceFactory.js.map +1 -1
  78. package/lib/documentStorageService.d.ts +3 -2
  79. package/lib/documentStorageService.d.ts.map +1 -1
  80. package/lib/documentStorageService.js +4 -4
  81. package/lib/documentStorageService.js.map +1 -1
  82. package/lib/gitManager.d.ts +30 -0
  83. package/lib/gitManager.d.ts.map +1 -0
  84. package/lib/gitManager.js +85 -0
  85. package/lib/gitManager.js.map +1 -0
  86. package/lib/historian.d.ts +33 -0
  87. package/lib/historian.d.ts.map +1 -0
  88. package/lib/historian.js +60 -0
  89. package/lib/historian.js.map +1 -0
  90. package/lib/packageVersion.d.ts +1 -1
  91. package/lib/packageVersion.js +1 -1
  92. package/lib/packageVersion.js.map +1 -1
  93. package/lib/restWrapper.d.ts +21 -8
  94. package/lib/restWrapper.d.ts.map +1 -1
  95. package/lib/restWrapper.js +92 -26
  96. package/lib/restWrapper.js.map +1 -1
  97. package/lib/restWrapperBase.d.ts +26 -0
  98. package/lib/restWrapperBase.d.ts.map +1 -0
  99. package/lib/restWrapperBase.js +50 -0
  100. package/lib/restWrapperBase.js.map +1 -0
  101. package/lib/retriableGitManager.d.ts +10 -21
  102. package/lib/retriableGitManager.d.ts.map +1 -1
  103. package/lib/retriableGitManager.js +0 -36
  104. package/lib/retriableGitManager.js.map +1 -1
  105. package/lib/shreddedSummaryDocumentStorageService.d.ts +1 -1
  106. package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
  107. package/lib/shreddedSummaryDocumentStorageService.js +5 -5
  108. package/lib/shreddedSummaryDocumentStorageService.js.map +1 -1
  109. package/lib/storageContracts.d.ts +44 -0
  110. package/lib/storageContracts.d.ts.map +1 -0
  111. package/lib/storageContracts.js +6 -0
  112. package/lib/storageContracts.js.map +1 -0
  113. package/lib/summaryTreeUploadManager.d.ts +23 -0
  114. package/lib/summaryTreeUploadManager.d.ts.map +1 -0
  115. package/lib/summaryTreeUploadManager.js +106 -0
  116. package/lib/summaryTreeUploadManager.js.map +1 -0
  117. package/lib/treeUtils.d.ts +7 -0
  118. package/lib/treeUtils.d.ts.map +1 -1
  119. package/lib/treeUtils.js +20 -0
  120. package/lib/treeUtils.js.map +1 -1
  121. package/lib/wholeSummaryDocumentStorageService.d.ts +5 -4
  122. package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
  123. package/lib/wholeSummaryDocumentStorageService.js +70 -37
  124. package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
  125. package/lib/wholeSummaryUploadManager.d.ts +16 -0
  126. package/lib/wholeSummaryUploadManager.d.ts.map +1 -0
  127. package/lib/wholeSummaryUploadManager.js +34 -0
  128. package/lib/wholeSummaryUploadManager.js.map +1 -0
  129. package/package.json +8 -9
  130. package/src/deltaStorageService.ts +11 -3
  131. package/src/documentService.ts +11 -11
  132. package/src/documentServiceFactory.ts +35 -17
  133. package/src/documentStorageService.ts +8 -4
  134. package/src/gitManager.ts +116 -0
  135. package/src/historian.ts +121 -0
  136. package/src/packageVersion.ts +1 -1
  137. package/src/restWrapper.ts +114 -38
  138. package/src/restWrapperBase.ts +146 -0
  139. package/src/retriableGitManager.ts +17 -95
  140. package/src/shreddedSummaryDocumentStorageService.ts +7 -9
  141. package/src/storageContracts.ts +63 -0
  142. package/src/summaryTreeUploadManager.ts +160 -0
  143. package/src/treeUtils.ts +30 -0
  144. package/src/wholeSummaryDocumentStorageService.ts +118 -48
  145. package/src/wholeSummaryUploadManager.ts +64 -0
@@ -8,7 +8,7 @@ import * as api from "@fluidframework/driver-definitions";
8
8
  import { DriverErrorType } from "@fluidframework/driver-definitions";
9
9
  import { RateLimiter, NetworkErrorBasic, canRetryOnError } from "@fluidframework/driver-utils";
10
10
  import { IClient } from "@fluidframework/protocol-definitions";
11
- import { GitManager, Historian, RestWrapper } from "@fluidframework/server-services-client";
11
+ import { INormalizedWholeSummary } from "@fluidframework/server-services-client";
12
12
  import io from "socket.io-client";
13
13
  import { PerformanceEvent, wrapError } from "@fluidframework/telemetry-utils";
14
14
  import { ITelemetryLogger } from "@fluidframework/common-definitions";
@@ -22,6 +22,9 @@ import { IRouterliciousDriverPolicies } from "./policies";
22
22
  import { ICache } from "./cache";
23
23
  import { ISnapshotTreeVersion } from "./definitions";
24
24
  import { pkgVersion as driverVersion } from "./packageVersion";
25
+ import { GitManager } from "./gitManager";
26
+ import { Historian } from "./historian";
27
+ import { RestWrapper } from "./restWrapperBase";
25
28
 
26
29
  /**
27
30
  * Amount of time between discoveries within which we don't need to rediscover on re-connect.
@@ -61,7 +64,8 @@ export class DocumentService implements api.IDocumentService {
61
64
  private readonly documentStorageServicePolicies: api.IDocumentStorageServicePolicies,
62
65
  private readonly driverPolicies: IRouterliciousDriverPolicies,
63
66
  private readonly blobCache: ICache<ArrayBufferLike>,
64
- private readonly snapshotTreeCache: ICache<ISnapshotTreeVersion>,
67
+ private readonly wholeSnapshotTreeCache: ICache<INormalizedWholeSummary>,
68
+ private readonly shreddedSummaryTreeCache: ICache<ISnapshotTreeVersion>,
65
69
  private readonly discoverFluidResolvedUrl: () => Promise<api.IFluidResolvedUrl>,
66
70
  ) {}
67
71
 
@@ -105,14 +109,9 @@ export class DocumentService implements api.IDocumentService {
105
109
  this.driverPolicies.enableRestLess,
106
110
  this.storageUrl,
107
111
  );
108
- const historian = new Historian(this.storageUrl, true, false, storageRestWrapper);
112
+ const historian = new Historian(true, false, storageRestWrapper);
109
113
  this.storageManager = new GitManager(historian);
110
- const noCacheHistorian = new Historian(
111
- this.storageUrl,
112
- true,
113
- true,
114
- storageRestWrapper,
115
- );
114
+ const noCacheHistorian = new Historian(true, true, storageRestWrapper);
116
115
  this.noCacheStorageManager = new GitManager(noCacheHistorian);
117
116
  }
118
117
 
@@ -128,7 +127,8 @@ export class DocumentService implements api.IDocumentService {
128
127
  this.documentStorageServicePolicies,
129
128
  this.driverPolicies,
130
129
  this.blobCache,
131
- this.snapshotTreeCache,
130
+ this.wholeSnapshotTreeCache,
131
+ this.shreddedSummaryTreeCache,
132
132
  noCacheStorageManager,
133
133
  getStorageManager,
134
134
  );
@@ -187,7 +187,7 @@ export class DocumentService implements api.IDocumentService {
187
187
  */
188
188
  public async connectToDeltaStream(client: IClient): Promise<api.IDocumentDeltaConnection> {
189
189
  const connect = async (refreshToken?: boolean) => {
190
- let ordererToken = this.ordererRestWrapper.getToken();
190
+ let ordererToken = await this.ordererRestWrapper.getToken();
191
191
  if (this.shouldUpdateDiscoveredSessionInfo()) {
192
192
  await this.refreshDiscovery();
193
193
  }
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import { assert } from "@fluidframework/common-utils";
7
+ import { getW3CData } from "@fluidframework/driver-base";
7
8
  import {
8
9
  FiveDaysMs,
9
10
  IDocumentService,
@@ -23,7 +24,7 @@ import {
23
24
  RateLimiter,
24
25
  } from "@fluidframework/driver-utils";
25
26
  import { ChildLogger, PerformanceEvent } from "@fluidframework/telemetry-utils";
26
- import { ISession } from "@fluidframework/server-services-client";
27
+ import { INormalizedWholeSummary, ISession } from "@fluidframework/server-services-client";
27
28
  import { DocumentService } from "./documentService";
28
29
  import { IRouterliciousDriverPolicies } from "./policies";
29
30
  import { ITokenProvider } from "./tokens";
@@ -54,7 +55,8 @@ const defaultRouterliciousDriverPolicies: IRouterliciousDriverPolicies = {
54
55
  export class RouterliciousDocumentServiceFactory implements IDocumentServiceFactory {
55
56
  private readonly driverPolicies: IRouterliciousDriverPolicies;
56
57
  private readonly blobCache: ICache<ArrayBufferLike>;
57
- private readonly snapshotTreeCache: ICache<ISnapshotTreeVersion>;
58
+ private readonly wholeSnapshotTreeCache: ICache<INormalizedWholeSummary> = new NullCache();
59
+ private readonly shreddedSummaryTreeCache: ICache<ISnapshotTreeVersion> = new NullCache();
58
60
 
59
61
  constructor(
60
62
  private readonly tokenProvider: ITokenProvider,
@@ -68,9 +70,17 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
68
70
  ...driverPolicies,
69
71
  };
70
72
  this.blobCache = new InMemoryCache<ArrayBufferLike>();
71
- this.snapshotTreeCache = this.driverPolicies.enableInternalSummaryCaching
72
- ? new InMemoryCache<ISnapshotTreeVersion>(snapshotCacheExpiryMs)
73
- : new NullCache<ISnapshotTreeVersion>();
73
+ if (this.driverPolicies.enableInternalSummaryCaching) {
74
+ if (this.driverPolicies.enableWholeSummaryUpload) {
75
+ this.wholeSnapshotTreeCache = new InMemoryCache<INormalizedWholeSummary>(
76
+ snapshotCacheExpiryMs,
77
+ );
78
+ } else {
79
+ this.shreddedSummaryTreeCache = new InMemoryCache<ISnapshotTreeVersion>(
80
+ snapshotCacheExpiryMs,
81
+ );
82
+ }
83
+ }
74
84
  }
75
85
 
76
86
  /**
@@ -128,15 +138,17 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
128
138
  },
129
139
  async (event) => {
130
140
  // @TODO: Remove returned "string" type when removing back-compat code
131
- const postRes = await ordererRestWrapper.post<
132
- { id: string; token?: string; session?: ISession } | string
133
- >(`/documents/${tenantId}`, {
134
- summary: convertSummaryToCreateNewSummary(appSummary),
135
- sequenceNumber: documentAttributes.sequenceNumber,
136
- values: quorumValues,
137
- enableDiscovery: this.driverPolicies.enableDiscovery,
138
- generateToken: this.tokenProvider.documentPostCreateCallback !== undefined,
139
- });
141
+ const postRes = (
142
+ await ordererRestWrapper.post<
143
+ { id: string; token?: string; session?: ISession } | string
144
+ >(`/documents/${tenantId}`, {
145
+ summary: convertSummaryToCreateNewSummary(appSummary),
146
+ sequenceNumber: documentAttributes.sequenceNumber,
147
+ values: quorumValues,
148
+ enableDiscovery: this.driverPolicies.enableDiscovery,
149
+ generateToken: this.tokenProvider.documentPostCreateCallback !== undefined,
150
+ })
151
+ ).content;
140
152
 
141
153
  event.end({
142
154
  docId: typeof postRes === "string" ? postRes : postRes.id,
@@ -253,11 +265,16 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
253
265
  eventName: "DiscoverSession",
254
266
  docId: documentId,
255
267
  },
256
- async () => {
268
+ async (event) => {
257
269
  // The service responds with the current document session associated with the container.
258
- return ordererRestWrapper.get<ISession>(
270
+ const response = await ordererRestWrapper.get<ISession>(
259
271
  `${resolvedUrl.endpoints.ordererUrl}/documents/${tenantId}/session/${documentId}`,
260
272
  );
273
+ event.end({
274
+ ...response.propsToLog,
275
+ ...getW3CData(response.requestUrl, "xmlhttprequest"),
276
+ });
277
+ return response.content;
261
278
  },
262
279
  );
263
280
  return getDiscoveredFluidResolvedUrl(resolvedUrl, discoveredSession);
@@ -299,7 +316,8 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
299
316
  documentStorageServicePolicies,
300
317
  this.driverPolicies,
301
318
  this.blobCache,
302
- this.snapshotTreeCache,
319
+ this.wholeSnapshotTreeCache,
320
+ this.shreddedSummaryTreeCache,
303
321
  discoverFluidResolvedUrl,
304
322
  );
305
323
  }
@@ -10,15 +10,16 @@ import {
10
10
  LoaderCachingPolicy,
11
11
  } from "@fluidframework/driver-definitions";
12
12
  import { ISnapshotTree, IVersion } from "@fluidframework/protocol-definitions";
13
- import { GitManager } from "@fluidframework/server-services-client";
14
13
  import {
15
14
  DocumentStorageServiceProxy,
16
15
  PrefetchDocumentStorageService,
17
16
  } from "@fluidframework/driver-utils";
17
+ import { INormalizedWholeSummary } from "@fluidframework/server-services-client";
18
18
  import { IRouterliciousDriverPolicies } from "./policies";
19
19
  import { ICache } from "./cache";
20
20
  import { WholeSummaryDocumentStorageService } from "./wholeSummaryDocumentStorageService";
21
21
  import { ShreddedSummaryDocumentStorageService } from "./shreddedSummaryDocumentStorageService";
22
+ import { GitManager } from "./gitManager";
22
23
  import { ISnapshotTreeVersion } from "./definitions";
23
24
 
24
25
  export class DocumentStorageService extends DocumentStorageServiceProxy {
@@ -35,7 +36,8 @@ export class DocumentStorageService extends DocumentStorageServiceProxy {
35
36
  policies: IDocumentStorageServicePolicies,
36
37
  driverPolicies?: IRouterliciousDriverPolicies,
37
38
  blobCache?: ICache<ArrayBufferLike>,
38
- snapshotTreeCache?: ICache<ISnapshotTreeVersion>,
39
+ snapshotTreeCache?: ICache<INormalizedWholeSummary>,
40
+ shreddedSummaryTreeCache?: ICache<ISnapshotTreeVersion>,
39
41
  noCacheGitManager?: GitManager,
40
42
  getStorageManager?: (disableCache?: boolean) => Promise<GitManager>,
41
43
  ): IDocumentStorageService {
@@ -58,7 +60,7 @@ export class DocumentStorageService extends DocumentStorageServiceProxy {
58
60
  policies,
59
61
  driverPolicies,
60
62
  blobCache,
61
- snapshotTreeCache,
63
+ shreddedSummaryTreeCache,
62
64
  getStorageManager,
63
65
  );
64
66
  // TODO: worth prefetching latest summary making version + snapshot call with WholeSummary storage?
@@ -78,7 +80,8 @@ export class DocumentStorageService extends DocumentStorageServiceProxy {
78
80
  policies: IDocumentStorageServicePolicies,
79
81
  driverPolicies?: IRouterliciousDriverPolicies,
80
82
  blobCache?: ICache<ArrayBufferLike>,
81
- snapshotTreeCache?: ICache<ISnapshotTreeVersion>,
83
+ snapshotTreeCache?: ICache<INormalizedWholeSummary>,
84
+ shreddedSummaryTreeCache?: ICache<ISnapshotTreeVersion>,
82
85
  public noCacheGitManager?: GitManager,
83
86
  getStorageManager?: (disableCache?: boolean) => Promise<GitManager>,
84
87
  ) {
@@ -91,6 +94,7 @@ export class DocumentStorageService extends DocumentStorageServiceProxy {
91
94
  driverPolicies,
92
95
  blobCache,
93
96
  snapshotTreeCache,
97
+ shreddedSummaryTreeCache,
94
98
  noCacheGitManager,
95
99
  getStorageManager,
96
100
  ),
@@ -0,0 +1,116 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import * as resources from "@fluidframework/gitresources";
7
+ import {
8
+ IWholeFlatSummary,
9
+ IWholeSummaryPayload,
10
+ IWriteSummaryResponse,
11
+ } from "@fluidframework/server-services-client";
12
+ import { IGitManager, IHistorian } from "./storageContracts";
13
+ import { IR11sResponse, createR11sResponseFromContent } from "./restWrapper";
14
+
15
+ export class GitManager implements IGitManager {
16
+ private readonly blobCache = new Map<string, resources.IBlob>();
17
+ private readonly commitCache = new Map<string, resources.ICommit>();
18
+ private readonly treeCache = new Map<string, resources.ITree>();
19
+ private readonly refCache = new Map<string, string>();
20
+
21
+ constructor(private readonly historian: IHistorian) {}
22
+
23
+ /**
24
+ * Reads the object with the given ID. We defer to the client implementation to do the actual read.
25
+ */
26
+ public async getCommits(
27
+ shaOrRef: string,
28
+ count: number,
29
+ ): Promise<IR11sResponse<resources.ICommitDetails[]>> {
30
+ let sha: string | undefined = shaOrRef;
31
+
32
+ // See if the sha is really a ref and convert
33
+ if (this.refCache.has(shaOrRef)) {
34
+ sha = this.refCache.get(shaOrRef);
35
+
36
+ // Delete refcache after first use
37
+ this.refCache.delete(shaOrRef);
38
+
39
+ // If null is stored for the ref then there are no commits - return an empty array
40
+ if (!sha) {
41
+ return createR11sResponseFromContent([]);
42
+ }
43
+ }
44
+
45
+ // See if the commit sha is hashed and return it if so
46
+ const commit = this.commitCache.get(sha);
47
+ if (commit !== undefined) {
48
+ return createR11sResponseFromContent([
49
+ {
50
+ commit: {
51
+ author: commit.author,
52
+ committer: commit.committer,
53
+ message: commit.message,
54
+ tree: commit.tree,
55
+ url: commit.url,
56
+ },
57
+ parents: commit.parents,
58
+ sha: commit.sha,
59
+ url: commit.url,
60
+ },
61
+ ]);
62
+ }
63
+
64
+ // Otherwise fall back to the historian
65
+ return this.historian.getCommits(sha, count);
66
+ }
67
+
68
+ /**
69
+ * Reads the object with the given ID. We defer to the client implementation to do the actual read.
70
+ */
71
+ public async getTree(root: string, recursive = true): Promise<IR11sResponse<resources.ITree>> {
72
+ const tree = this.treeCache.get(root);
73
+ if (tree !== undefined) {
74
+ return createR11sResponseFromContent(tree);
75
+ }
76
+
77
+ return this.historian.getTree(root, recursive);
78
+ }
79
+
80
+ public async getBlob(sha: string): Promise<IR11sResponse<resources.IBlob>> {
81
+ const blob = this.blobCache.get(sha);
82
+ if (blob !== undefined) {
83
+ return createR11sResponseFromContent(blob);
84
+ }
85
+ return this.historian.getBlob(sha);
86
+ }
87
+
88
+ public async createBlob(
89
+ content: string,
90
+ encoding: "utf-8" | "base64",
91
+ ): Promise<IR11sResponse<resources.ICreateBlobResponse>> {
92
+ const blob: resources.ICreateBlobParams = {
93
+ content,
94
+ encoding,
95
+ };
96
+ return this.historian.createBlob(blob);
97
+ }
98
+
99
+ public async createGitTree(
100
+ params: resources.ICreateTreeParams,
101
+ ): Promise<IR11sResponse<resources.ITree>> {
102
+ const treeP = this.historian.createTree(params);
103
+ return treeP;
104
+ }
105
+
106
+ public async createSummary(
107
+ summary: IWholeSummaryPayload,
108
+ initial: boolean = false,
109
+ ): Promise<IR11sResponse<IWriteSummaryResponse>> {
110
+ return this.historian.createSummary(summary, initial);
111
+ }
112
+
113
+ public async getSummary(sha: string): Promise<IR11sResponse<IWholeFlatSummary>> {
114
+ return this.historian.getSummary(sha);
115
+ }
116
+ }
@@ -0,0 +1,121 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { fromUtf8ToBase64 } from "@fluidframework/common-utils";
7
+ import * as git from "@fluidframework/gitresources";
8
+ import {
9
+ IWholeFlatSummary,
10
+ IWholeSummaryPayload,
11
+ IWriteSummaryResponse,
12
+ } from "@fluidframework/server-services-client";
13
+ import { QueryStringType, RestWrapper } from "./restWrapperBase";
14
+ import { IR11sResponse } from "./restWrapper";
15
+ import { IHistorian } from "./storageContracts";
16
+
17
+ export interface ICredentials {
18
+ user: string;
19
+ password: string;
20
+ }
21
+
22
+ export const getAuthorizationTokenFromCredentials = (credentials: ICredentials): string =>
23
+ `Basic ${fromUtf8ToBase64(`${credentials.user}:${credentials.password}`)}`;
24
+
25
+ /**
26
+ * Implementation of the IHistorian interface that calls out to a REST interface
27
+ */
28
+ export class Historian implements IHistorian {
29
+ private readonly defaultQueryString: QueryStringType = {};
30
+ private readonly cacheBust: boolean;
31
+
32
+ constructor(
33
+ private readonly historianApi: boolean,
34
+ disableCache: boolean,
35
+ private readonly restWrapper: RestWrapper,
36
+ ) {
37
+ if (disableCache && this.historianApi) {
38
+ this.defaultQueryString.disableCache = disableCache;
39
+ this.cacheBust = false;
40
+ } else {
41
+ this.cacheBust = disableCache;
42
+ }
43
+ }
44
+
45
+ public async getBlob(sha: string): Promise<IR11sResponse<git.IBlob>> {
46
+ return this.restWrapper.get<git.IBlob>(
47
+ `/git/blobs/${encodeURIComponent(sha)}`,
48
+ this.getQueryString(),
49
+ );
50
+ }
51
+
52
+ public async createBlob(
53
+ blob: git.ICreateBlobParams,
54
+ ): Promise<IR11sResponse<git.ICreateBlobResponse>> {
55
+ return this.restWrapper.post<git.ICreateBlobResponse>(
56
+ `/git/blobs`,
57
+ blob,
58
+ this.getQueryString(),
59
+ );
60
+ }
61
+
62
+ public async getCommits(
63
+ sha: string,
64
+ count: number,
65
+ ): Promise<IR11sResponse<git.ICommitDetails[]>> {
66
+ return this.restWrapper
67
+ .get<git.ICommitDetails[]>(`/commits`, this.getQueryString({ count, sha }))
68
+ .catch((error) =>
69
+ error.statusCode === 400 || error.statusCode === 404
70
+ ? {
71
+ content: [],
72
+ headers: new Map(),
73
+ propsToLog: {},
74
+ requestUrl: "",
75
+ }
76
+ : Promise.reject<IR11sResponse<git.ICommitDetails[]>>(error),
77
+ );
78
+ }
79
+
80
+ public async createTree(tree: git.ICreateTreeParams): Promise<IR11sResponse<git.ITree>> {
81
+ return this.restWrapper.post<git.ITree>(`/git/trees`, tree, this.getQueryString());
82
+ }
83
+
84
+ public async getTree(sha: string, recursive: boolean): Promise<IR11sResponse<git.ITree>> {
85
+ return this.restWrapper.get<git.ITree>(
86
+ `/git/trees/${encodeURIComponent(sha)}`,
87
+ this.getQueryString({ recursive: recursive ? 1 : 0 }),
88
+ );
89
+ }
90
+ public async createSummary(
91
+ summary: IWholeSummaryPayload,
92
+ initial?: boolean,
93
+ ): Promise<IR11sResponse<IWriteSummaryResponse>> {
94
+ return this.restWrapper.post<IWriteSummaryResponse>(
95
+ `/git/summaries`,
96
+ summary,
97
+ this.getQueryString(initial !== undefined ? { initial } : undefined),
98
+ );
99
+ }
100
+
101
+ public async getSummary(sha: string): Promise<IR11sResponse<IWholeFlatSummary>> {
102
+ return this.restWrapper.get<IWholeFlatSummary>(
103
+ `/git/summaries/${sha}`,
104
+ this.getQueryString(),
105
+ );
106
+ }
107
+
108
+ private getQueryString(queryString?: QueryStringType): QueryStringType {
109
+ if (this.cacheBust) {
110
+ return {
111
+ cacheBust: Date.now(),
112
+ ...this.defaultQueryString,
113
+ ...queryString,
114
+ };
115
+ }
116
+ return {
117
+ ...this.defaultQueryString,
118
+ ...queryString,
119
+ };
120
+ }
121
+ }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/routerlicious-driver";
9
- export const pkgVersion = "2.0.0-dev.4.1.0.148229";
9
+ export const pkgVersion = "2.0.0-dev.4.2.0.153917";