@fluidframework/odsp-driver 1.2.7 → 2.0.0-dev.1.3.0.96595

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 (254) hide show
  1. package/.mocharc.js +12 -0
  2. package/README.md +19 -0
  3. package/dist/ReadBufferUtils.d.ts.map +1 -1
  4. package/dist/ReadBufferUtils.js +1 -0
  5. package/dist/ReadBufferUtils.js.map +1 -1
  6. package/dist/WriteBufferUtils.d.ts +3 -5
  7. package/dist/WriteBufferUtils.d.ts.map +1 -1
  8. package/dist/WriteBufferUtils.js +59 -55
  9. package/dist/WriteBufferUtils.js.map +1 -1
  10. package/dist/compactSnapshotParser.d.ts +2 -2
  11. package/dist/compactSnapshotParser.d.ts.map +1 -1
  12. package/dist/compactSnapshotParser.js +91 -34
  13. package/dist/compactSnapshotParser.js.map +1 -1
  14. package/dist/compactSnapshotWriter.d.ts +1 -2
  15. package/dist/compactSnapshotWriter.d.ts.map +1 -1
  16. package/dist/compactSnapshotWriter.js +17 -14
  17. package/dist/compactSnapshotWriter.js.map +1 -1
  18. package/dist/contracts.d.ts +1 -18
  19. package/dist/contracts.d.ts.map +1 -1
  20. package/dist/contracts.js.map +1 -1
  21. package/dist/createFile.d.ts +1 -1
  22. package/dist/createFile.d.ts.map +1 -1
  23. package/dist/createFile.js +53 -16
  24. package/dist/createFile.js.map +1 -1
  25. package/dist/createNewUtils.d.ts.map +1 -1
  26. package/dist/createNewUtils.js +0 -1
  27. package/dist/createNewUtils.js.map +1 -1
  28. package/dist/createOdspCreateContainerRequest.d.ts +4 -3
  29. package/dist/createOdspCreateContainerRequest.d.ts.map +1 -1
  30. package/dist/createOdspCreateContainerRequest.js +6 -3
  31. package/dist/createOdspCreateContainerRequest.js.map +1 -1
  32. package/dist/epochTracker.d.ts +1 -0
  33. package/dist/epochTracker.d.ts.map +1 -1
  34. package/dist/epochTracker.js +24 -5
  35. package/dist/epochTracker.js.map +1 -1
  36. package/dist/fetchSnapshot.d.ts +1 -2
  37. package/dist/fetchSnapshot.d.ts.map +1 -1
  38. package/dist/fetchSnapshot.js +22 -27
  39. package/dist/fetchSnapshot.js.map +1 -1
  40. package/dist/getFileLink.d.ts +3 -6
  41. package/dist/getFileLink.d.ts.map +1 -1
  42. package/dist/getFileLink.js +22 -33
  43. package/dist/getFileLink.js.map +1 -1
  44. package/dist/index.d.ts +1 -2
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +3 -3
  47. package/dist/index.js.map +1 -1
  48. package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -1
  49. package/dist/localOdspDriver/localOdspDocumentStorageManager.js +1 -2
  50. package/dist/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -1
  51. package/dist/odspDeltaStorageService.d.ts +3 -2
  52. package/dist/odspDeltaStorageService.d.ts.map +1 -1
  53. package/dist/odspDeltaStorageService.js +9 -12
  54. package/dist/odspDeltaStorageService.js.map +1 -1
  55. package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
  56. package/dist/odspDocumentDeltaConnection.js +3 -6
  57. package/dist/odspDocumentDeltaConnection.js.map +1 -1
  58. package/dist/odspDocumentService.d.ts +1 -0
  59. package/dist/odspDocumentService.d.ts.map +1 -1
  60. package/dist/odspDocumentService.js +12 -6
  61. package/dist/odspDocumentService.js.map +1 -1
  62. package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
  63. package/dist/odspDocumentServiceFactoryCore.js +29 -6
  64. package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
  65. package/dist/odspDocumentStorageManager.d.ts +4 -4
  66. package/dist/odspDocumentStorageManager.d.ts.map +1 -1
  67. package/dist/odspDocumentStorageManager.js +82 -64
  68. package/dist/odspDocumentStorageManager.js.map +1 -1
  69. package/dist/odspDocumentStorageServiceBase.d.ts +1 -1
  70. package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -1
  71. package/dist/odspDocumentStorageServiceBase.js +4 -2
  72. package/dist/odspDocumentStorageServiceBase.js.map +1 -1
  73. package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  74. package/dist/odspDriverUrlResolverForShareLink.js +4 -4
  75. package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
  76. package/dist/odspFluidFileLink.js +1 -1
  77. package/dist/odspFluidFileLink.js.map +1 -1
  78. package/dist/odspLocationRedirection.d.ts +14 -0
  79. package/dist/odspLocationRedirection.d.ts.map +1 -0
  80. package/dist/odspLocationRedirection.js +24 -0
  81. package/dist/odspLocationRedirection.js.map +1 -0
  82. package/dist/odspSnapshotParser.d.ts.map +1 -1
  83. package/dist/odspSnapshotParser.js +1 -2
  84. package/dist/odspSnapshotParser.js.map +1 -1
  85. package/dist/odspSummaryUploadManager.d.ts +6 -3
  86. package/dist/odspSummaryUploadManager.d.ts.map +1 -1
  87. package/dist/odspSummaryUploadManager.js +14 -17
  88. package/dist/odspSummaryUploadManager.js.map +1 -1
  89. package/dist/odspUrlHelper.js +2 -1
  90. package/dist/odspUrlHelper.js.map +1 -1
  91. package/dist/odspUtils.d.ts +11 -2
  92. package/dist/odspUtils.d.ts.map +1 -1
  93. package/dist/odspUtils.js +32 -5
  94. package/dist/odspUtils.js.map +1 -1
  95. package/dist/opsCaching.d.ts.map +1 -1
  96. package/dist/opsCaching.js +3 -2
  97. package/dist/opsCaching.js.map +1 -1
  98. package/dist/packageVersion.d.ts +1 -1
  99. package/dist/packageVersion.d.ts.map +1 -1
  100. package/dist/packageVersion.js +1 -1
  101. package/dist/packageVersion.js.map +1 -1
  102. package/dist/prefetchLatestSnapshot.d.ts +6 -4
  103. package/dist/prefetchLatestSnapshot.d.ts.map +1 -1
  104. package/dist/prefetchLatestSnapshot.js +6 -4
  105. package/dist/prefetchLatestSnapshot.js.map +1 -1
  106. package/dist/retryUtils.d.ts.map +1 -1
  107. package/dist/retryUtils.js +8 -4
  108. package/dist/retryUtils.js.map +1 -1
  109. package/dist/zipItDataRepresentationUtils.d.ts +30 -18
  110. package/dist/zipItDataRepresentationUtils.d.ts.map +1 -1
  111. package/dist/zipItDataRepresentationUtils.js +170 -76
  112. package/dist/zipItDataRepresentationUtils.js.map +1 -1
  113. package/lib/ReadBufferUtils.d.ts.map +1 -1
  114. package/lib/ReadBufferUtils.js +1 -0
  115. package/lib/ReadBufferUtils.js.map +1 -1
  116. package/lib/WriteBufferUtils.d.ts +3 -5
  117. package/lib/WriteBufferUtils.d.ts.map +1 -1
  118. package/lib/WriteBufferUtils.js +61 -57
  119. package/lib/WriteBufferUtils.js.map +1 -1
  120. package/lib/compactSnapshotParser.d.ts +2 -2
  121. package/lib/compactSnapshotParser.d.ts.map +1 -1
  122. package/lib/compactSnapshotParser.js +92 -35
  123. package/lib/compactSnapshotParser.js.map +1 -1
  124. package/lib/compactSnapshotWriter.d.ts +1 -2
  125. package/lib/compactSnapshotWriter.d.ts.map +1 -1
  126. package/lib/compactSnapshotWriter.js +18 -15
  127. package/lib/compactSnapshotWriter.js.map +1 -1
  128. package/lib/contracts.d.ts +1 -18
  129. package/lib/contracts.d.ts.map +1 -1
  130. package/lib/contracts.js.map +1 -1
  131. package/lib/createFile.d.ts +1 -1
  132. package/lib/createFile.d.ts.map +1 -1
  133. package/lib/createFile.js +54 -17
  134. package/lib/createFile.js.map +1 -1
  135. package/lib/createNewUtils.d.ts.map +1 -1
  136. package/lib/createNewUtils.js +0 -1
  137. package/lib/createNewUtils.js.map +1 -1
  138. package/lib/createOdspCreateContainerRequest.d.ts +4 -3
  139. package/lib/createOdspCreateContainerRequest.d.ts.map +1 -1
  140. package/lib/createOdspCreateContainerRequest.js +6 -3
  141. package/lib/createOdspCreateContainerRequest.js.map +1 -1
  142. package/lib/epochTracker.d.ts +1 -0
  143. package/lib/epochTracker.d.ts.map +1 -1
  144. package/lib/epochTracker.js +26 -7
  145. package/lib/epochTracker.js.map +1 -1
  146. package/lib/fetchSnapshot.d.ts +1 -2
  147. package/lib/fetchSnapshot.d.ts.map +1 -1
  148. package/lib/fetchSnapshot.js +22 -27
  149. package/lib/fetchSnapshot.js.map +1 -1
  150. package/lib/getFileLink.d.ts +3 -6
  151. package/lib/getFileLink.d.ts.map +1 -1
  152. package/lib/getFileLink.js +24 -35
  153. package/lib/getFileLink.js.map +1 -1
  154. package/lib/index.d.ts +1 -2
  155. package/lib/index.d.ts.map +1 -1
  156. package/lib/index.js +1 -3
  157. package/lib/index.js.map +1 -1
  158. package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -1
  159. package/lib/localOdspDriver/localOdspDocumentStorageManager.js +1 -2
  160. package/lib/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -1
  161. package/lib/odspDeltaStorageService.d.ts +3 -2
  162. package/lib/odspDeltaStorageService.d.ts.map +1 -1
  163. package/lib/odspDeltaStorageService.js +9 -12
  164. package/lib/odspDeltaStorageService.js.map +1 -1
  165. package/lib/odspDocumentDeltaConnection.d.ts.map +1 -1
  166. package/lib/odspDocumentDeltaConnection.js +3 -6
  167. package/lib/odspDocumentDeltaConnection.js.map +1 -1
  168. package/lib/odspDocumentService.d.ts +1 -0
  169. package/lib/odspDocumentService.d.ts.map +1 -1
  170. package/lib/odspDocumentService.js +14 -8
  171. package/lib/odspDocumentService.js.map +1 -1
  172. package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
  173. package/lib/odspDocumentServiceFactoryCore.js +29 -6
  174. package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
  175. package/lib/odspDocumentStorageManager.d.ts +4 -4
  176. package/lib/odspDocumentStorageManager.d.ts.map +1 -1
  177. package/lib/odspDocumentStorageManager.js +83 -65
  178. package/lib/odspDocumentStorageManager.js.map +1 -1
  179. package/lib/odspDocumentStorageServiceBase.d.ts +1 -1
  180. package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -1
  181. package/lib/odspDocumentStorageServiceBase.js +4 -2
  182. package/lib/odspDocumentStorageServiceBase.js.map +1 -1
  183. package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  184. package/lib/odspDriverUrlResolverForShareLink.js +4 -4
  185. package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
  186. package/lib/odspFluidFileLink.js +1 -1
  187. package/lib/odspFluidFileLink.js.map +1 -1
  188. package/lib/odspLocationRedirection.d.ts +14 -0
  189. package/lib/odspLocationRedirection.d.ts.map +1 -0
  190. package/lib/odspLocationRedirection.js +20 -0
  191. package/lib/odspLocationRedirection.js.map +1 -0
  192. package/lib/odspSnapshotParser.d.ts.map +1 -1
  193. package/lib/odspSnapshotParser.js +1 -2
  194. package/lib/odspSnapshotParser.js.map +1 -1
  195. package/lib/odspSummaryUploadManager.d.ts +6 -3
  196. package/lib/odspSummaryUploadManager.d.ts.map +1 -1
  197. package/lib/odspSummaryUploadManager.js +14 -17
  198. package/lib/odspSummaryUploadManager.js.map +1 -1
  199. package/lib/odspUrlHelper.js +2 -1
  200. package/lib/odspUrlHelper.js.map +1 -1
  201. package/lib/odspUtils.d.ts +11 -2
  202. package/lib/odspUtils.d.ts.map +1 -1
  203. package/lib/odspUtils.js +31 -5
  204. package/lib/odspUtils.js.map +1 -1
  205. package/lib/opsCaching.d.ts.map +1 -1
  206. package/lib/opsCaching.js +3 -2
  207. package/lib/opsCaching.js.map +1 -1
  208. package/lib/packageVersion.d.ts +1 -1
  209. package/lib/packageVersion.d.ts.map +1 -1
  210. package/lib/packageVersion.js +1 -1
  211. package/lib/packageVersion.js.map +1 -1
  212. package/lib/prefetchLatestSnapshot.d.ts +6 -4
  213. package/lib/prefetchLatestSnapshot.d.ts.map +1 -1
  214. package/lib/prefetchLatestSnapshot.js +6 -4
  215. package/lib/prefetchLatestSnapshot.js.map +1 -1
  216. package/lib/retryUtils.d.ts.map +1 -1
  217. package/lib/retryUtils.js +9 -5
  218. package/lib/retryUtils.js.map +1 -1
  219. package/lib/zipItDataRepresentationUtils.d.ts +30 -18
  220. package/lib/zipItDataRepresentationUtils.d.ts.map +1 -1
  221. package/lib/zipItDataRepresentationUtils.js +166 -75
  222. package/lib/zipItDataRepresentationUtils.js.map +1 -1
  223. package/package.json +33 -20
  224. package/src/ReadBufferUtils.ts +1 -0
  225. package/src/WriteBufferUtils.ts +67 -58
  226. package/src/compactSnapshotParser.ts +102 -40
  227. package/src/compactSnapshotWriter.ts +25 -17
  228. package/src/contracts.ts +2 -14
  229. package/src/createFile.ts +75 -15
  230. package/src/createNewUtils.ts +2 -4
  231. package/src/createOdspCreateContainerRequest.ts +7 -4
  232. package/src/epochTracker.ts +47 -7
  233. package/src/fetchSnapshot.ts +35 -31
  234. package/src/getFileLink.ts +26 -39
  235. package/src/index.ts +1 -3
  236. package/src/localOdspDriver/localOdspDocumentStorageManager.ts +2 -2
  237. package/src/odspDeltaStorageService.ts +8 -9
  238. package/src/odspDocumentDeltaConnection.ts +3 -5
  239. package/src/odspDocumentService.ts +16 -13
  240. package/src/odspDocumentServiceFactoryCore.ts +40 -4
  241. package/src/odspDocumentStorageManager.ts +64 -50
  242. package/src/odspDocumentStorageServiceBase.ts +4 -2
  243. package/src/odspDriverUrlResolverForShareLink.ts +2 -5
  244. package/src/odspFluidFileLink.ts +1 -1
  245. package/src/odspLocationRedirection.ts +23 -0
  246. package/src/odspSnapshotParser.ts +3 -4
  247. package/src/odspSummaryUploadManager.ts +10 -11
  248. package/src/odspUrlHelper.ts +1 -1
  249. package/src/odspUtils.ts +40 -7
  250. package/src/opsCaching.ts +3 -2
  251. package/src/packageVersion.ts +1 -1
  252. package/src/prefetchLatestSnapshot.ts +6 -4
  253. package/src/retryUtils.ts +8 -5
  254. package/src/zipItDataRepresentationUtils.ts +198 -75
package/.mocharc.js ADDED
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ const getFluidTestMochaConfig = require('@fluidframework/mocha-test-setup/mocharc-common');
9
+
10
+ const packageDir = __dirname;
11
+ const config = getFluidTestMochaConfig(packageDir);
12
+ module.exports = config;
package/README.md CHANGED
@@ -6,3 +6,22 @@ the client and the ODSP server to retrieve Fluid content and connect to the Flui
6
6
  The ODSP Fluid service is not a publicly available service, and currently it is not possible to use this driver
7
7
  to connect to it. This driver is present as an illustration of a different Fluid driver implementation.
8
8
  Developers should not depend on this driver for their own solutions.
9
+
10
+
11
+ ## ODSP APIs
12
+
13
+ Documenting some basics about opds-driver specific apis that are relevant for creation or loading of a Fluid file from ODSP.
14
+
15
+ ### /snapshot API
16
+
17
+ - Creates a new Fluid file with the contents as the summary provided in the request body.
18
+ - The creation of file along with the summary is done in a single api call to reduce the number of round trips during new file creation.
19
+ - Also supports creation of sharing link for the file if appropriate request headers are provided in the api call. This feature was introduced to save the number of round trips that a host app makes while creating a file and then creating a sharing link.
20
+ 1. Earlier only `&createLinkType=csl` parameter was supported which could create organizational scoped sharing links. Feature is gated by `enableShareLinkWithCreate` provided via `HostStoragePolicy`. (createLinkType is now deprecated, so prefer using option 2 below)
21
+ 1. Now, providing appropriate values for `&createLinkScope` and `&createLinkRole` request parameters will let you create sharing links with various permission scopes. See `resolvedUrl` definition for more details. Feature is gated by `enableSingleRequestForShareLinkWithCreate ` provided via `HostStoragePolicy`.
22
+
23
+ ### /trees/latest API
24
+
25
+ - Fetches the snapshot of an existing Fluid file.
26
+ - Earlier, application needed to redeem the sharing link of the file before a /trees/latest fetch could be made. To reduce the number of round trips made to ODSP, redemption of the share link now happens along with fetching latest snapshot in the same api request by passing share link in `&sl` request parameter.
27
+ - This api is also preflight-less, which means it is not preceded by an OPTIONS call in the browsers to reduce the network trips to the server.
@@ -1 +1 @@
1
- {"version":3,"file":"ReadBufferUtils.d.ts","sourceRoot":"","sources":["../src/ReadBufferUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,qBAAa,UAAU;IAOP,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU;IAN/C,SAAS,CAAC,KAAK,SAAK;IAEpB,IAAW,MAAM,eAEhB;gBAE8B,IAAI,EAAE,UAAU;IAO/C,IAAW,GAAG,YAA8C;IAC5D,IAAW,GAAG,WAAyB;IACvC,IAAW,MAAM,WAA+B;IAEzC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAIhC,KAAK;IAIL,IAAI,CAAC,SAAS,SAAI,GAAG,MAAM;IAc3B,IAAI,CAAC,MAAM,EAAE,MAAM;CAI7B"}
1
+ {"version":3,"file":"ReadBufferUtils.d.ts","sourceRoot":"","sources":["../src/ReadBufferUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,qBAAa,UAAU;IAOP,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU;IAN/C,SAAS,CAAC,KAAK,SAAK;IAEpB,IAAW,MAAM,eAEhB;gBAE8B,IAAI,EAAE,UAAU;IAO/C,IAAW,GAAG,YAA8C;IAC5D,IAAW,GAAG,WAAyB;IACvC,IAAW,MAAM,WAA+B;IAEzC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAIhC,KAAK;IAIL,IAAI,CAAC,SAAS,SAAI,GAAG,MAAM;IAc3B,IAAI,CAAC,MAAM,EAAE,MAAM;CAK7B"}
@@ -47,6 +47,7 @@ class ReadBuffer {
47
47
  skip(length) {
48
48
  (0, common_utils_1.assert)(length >= 0, 0x224 /* "Skip length should be positive" */);
49
49
  this.index += length;
50
+ (0, common_utils_1.assert)(this.index <= this.data.length, 0x3dc /* skipping past size of buffer */);
50
51
  }
51
52
  }
52
53
  exports.ReadBuffer = ReadBuffer;
@@ -1 +1 @@
1
- {"version":3,"file":"ReadBufferUtils.js","sourceRoot":"","sources":["../src/ReadBufferUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAEtD;;;GAGG;AACH,MAAa,UAAU;IAOnB,YAA+B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;QANrC,UAAK,GAAG,CAAC,CAAC;QA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K,IAAI,MAAM,CAAC;IACzB,CAAC;CACJ;AA5CD,gCA4CC","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\";\n\n/**\n * Buffer class, used to sequentially read data.\n * Used by tree code to reconstruct a tree from binary representation.\n */\nexport class ReadBuffer {\n protected index = 0;\n\n public get buffer() {\n return this.data;\n }\n\n constructor(protected readonly data: Uint8Array) {\n // BlobShallowCopy will return to users parts of this array.\n // We need to ensure that nobody can change it, as it will have\n // catastrophic result and will be really hard to investigate.\n Object.freeze(data.buffer);\n }\n\n public get eof() { return this.index === this.data.length; }\n public get pos() { return this.index; }\n public get length() { return this.data.length; }\n\n public slice(start: number, end: number) {\n return this.data.slice(start, end);\n }\n\n public reset() {\n this.index = 0;\n }\n\n public read(lengthArg = 1): number {\n let res = 0;\n let multiplier = 1;\n let length = lengthArg;\n while (length > 0) {\n assert(!this.eof, 0x223 /* \"unexpected end of buffer\" */);\n res += this.data[this.index] * multiplier;\n this.index++;\n multiplier *= 256;\n length--;\n }\n return res;\n }\n\n public skip(length: number) {\n assert(length >= 0, 0x224 /* \"Skip length should be positive\" */);\n this.index += length;\n }\n}\n"]}
1
+ {"version":3,"file":"ReadBufferUtils.js","sourceRoot":"","sources":["../src/ReadBufferUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAEtD;;;GAGG;AACH,MAAa,UAAU;IAOnB,YAA+B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;QANrC,UAAK,GAAG,CAAC,CAAC;QAOhB,4DAA4D;QAC5D,+DAA+D;QAC/D,8DAA8D;QAC9D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IATD,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IASD,IAAW,GAAG,KAAK,OAAO,IAAI,CAAC,KAAK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ensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\n\n/**\n * Buffer class, used to sequentially read data.\n * Used by tree code to reconstruct a tree from binary representation.\n */\nexport class ReadBuffer {\n protected index = 0;\n\n public get buffer() {\n return this.data;\n }\n\n constructor(protected readonly data: Uint8Array) {\n // BlobShallowCopy will return to users parts of this array.\n // We need to ensure that nobody can change it, as it will have\n // catastrophic result and will be really hard to investigate.\n Object.freeze(data.buffer);\n }\n\n public get eof() { return this.index === this.data.length; }\n public get pos() { return this.index; }\n public get length() { return this.data.length; }\n\n public slice(start: number, end: number) {\n return this.data.slice(start, end);\n }\n\n public reset() {\n this.index = 0;\n }\n\n public read(lengthArg = 1): number {\n let res = 0;\n let multiplier = 1;\n let length = lengthArg;\n while (length > 0) {\n assert(!this.eof, 0x223 /* \"unexpected end of buffer\" */);\n res += this.data[this.index] * multiplier;\n this.index++;\n multiplier *= 256;\n length--;\n }\n return res;\n }\n\n public skip(length: number) {\n assert(length >= 0, 0x224 /* \"Skip length should be positive\" */);\n this.index += length;\n assert(this.index <= this.data.length, 0x3dc /* skipping past size of buffer */);\n }\n}\n"]}
@@ -2,8 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ReadBuffer } from "./ReadBufferUtils";
6
- import { NodeCore, TreeBuilder } from "./zipItDataRepresentationUtils";
5
+ import { NodeCore } from "./zipItDataRepresentationUtils";
7
6
  /**
8
7
  * Buffer class, used to sequentially writ data.
9
8
  * Used by tree code to serialize tree into binary representation.
@@ -13,7 +12,7 @@ export declare class WriteBuffer {
13
12
  protected index: number;
14
13
  protected push(code: number): void;
15
14
  write(codeArg: number, lengthArg?: number): void;
16
- done(): ReadBuffer;
15
+ done(): Uint8Array;
17
16
  }
18
17
  /**
19
18
  * Calculate how many bytes are required to encode an integer. This is always power of 2.
@@ -28,8 +27,7 @@ declare class NodeCoreSerializer extends NodeCore {
28
27
  }
29
28
  export declare class TreeBuilderSerializer extends NodeCoreSerializer {
30
29
  constructor();
31
- static load(buffer: ReadBuffer): TreeBuilder;
32
- serialize(): ReadBuffer;
30
+ serialize(): Uint8Array;
33
31
  }
34
32
  export {};
35
33
  //# sourceMappingURL=WriteBufferUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WriteBufferUtils.d.ts","sourceRoot":"","sources":["../src/WriteBufferUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAOH,QAAQ,EACR,WAAW,EACd,MAAM,gCAAgC,CAAC;AAExC;;;GAGG;AACH,qBAAa,WAAW;IACpB,SAAS,CAAC,IAAI,CAAC,EAAE,UAAU,CAAwB;IACnD,SAAS,CAAC,KAAK,SAAK;IAEpB,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM;IAiBpB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI;IAWpC,IAAI,IAAI,UAAU;CAQ5B;AAyDD;;;;;GAKG;AACF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,UAezC;AA+FD,cAAM,kBAAmB,SAAQ,QAAQ;;IAK9B,SAAS,CAAC,MAAM,EAAE,WAAW;CAGvC;AAED,qBAAa,qBAAsB,SAAQ,kBAAkB;;IAKzD,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW;IAIrC,SAAS,IAAI,UAAU;CAKjC"}
1
+ {"version":3,"file":"WriteBufferUtils.d.ts","sourceRoot":"","sources":["../src/WriteBufferUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAOH,QAAQ,EACX,MAAM,gCAAgC,CAAC;AAExC;;;GAGG;AACH,qBAAa,WAAW;IACpB,SAAS,CAAC,IAAI,CAAC,EAAE,UAAU,CAAwB;IACnD,SAAS,CAAC,KAAK,SAAK;IAEpB,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM;IAiBpB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI;IAWpC,IAAI,IAAI,UAAU;CAQ5B;AAyDD;;;;;GAKG;AACF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,UAezC;AA8GD,cAAM,kBAAmB,SAAQ,QAAQ;;IAK9B,SAAS,CAAC,MAAM,EAAE,WAAW;CAGvC;AAED,qBAAa,qBAAsB,SAAQ,kBAAkB;;IAKlD,SAAS,IAAI,UAAU;CAKjC"}
@@ -6,7 +6,6 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.TreeBuilderSerializer = exports.calcLength = exports.WriteBuffer = void 0;
8
8
  const common_utils_1 = require("@fluidframework/common-utils");
9
- const ReadBufferUtils_1 = require("./ReadBufferUtils");
10
9
  const zipItDataRepresentationUtils_1 = require("./zipItDataRepresentationUtils");
11
10
  /**
12
11
  * Buffer class, used to sequentially writ data.
@@ -47,7 +46,7 @@ class WriteBuffer {
47
46
  (0, common_utils_1.assert)(this.data !== undefined, 0x227 /* "Data should be there" */);
48
47
  // We can slice it to have smaller memory representation.
49
48
  // But it will be way more expensive in terms of CPU cycles!
50
- const buffer = new ReadBufferUtils_1.ReadBuffer(this.data.subarray(0, this.index));
49
+ const buffer = this.data.subarray(0, this.index);
51
50
  this.data = undefined;
52
51
  return buffer;
53
52
  }
@@ -128,59 +127,61 @@ exports.calcLength = calcLength;
128
127
  /**
129
128
  * Implementation of serialization of blobs in buffer with Marker Codes etc.
130
129
  * @param buffer - Buffer to serialize to.
131
- * @param blob - blob to be serialized.
130
+ * @param content - string to be serialized.
132
131
  * @param dictionary - Const strings dictionary to be used while serializing.
133
132
  */
134
- function serializeBlob(buffer, blob, dictionary) {
135
- const data = blob.buffer;
136
- const lengthOfDataLen = calcLength(data.length);
137
- if (blob.constString) {
138
- const content = blob.toString();
139
- let id = dictionary.get(content);
140
- let idLength;
141
- if (id === undefined) {
142
- id = dictionary.size + 1;
143
- idLength = calcLength(id);
144
- dictionary.set(content, id);
145
- let code;
146
- if (lengthOfDataLen > 1 || idLength > 1) {
147
- code = zipItDataRepresentationUtils_1.MarkerCodes.ConstStringDeclareBig;
148
- }
149
- else {
150
- code = zipItDataRepresentationUtils_1.MarkerCodes.ConstStringDeclare;
151
- }
152
- // Write marker code for const string.
153
- buffer.write(code);
154
- const bytes = (0, zipItDataRepresentationUtils_1.getValueSafely)(zipItDataRepresentationUtils_1.codeToBytesMap, code);
155
- (0, common_utils_1.assert)(bytes >= lengthOfDataLen, 0x283 /* "Length of data len should fit in the bytes from the map" */);
156
- (0, common_utils_1.assert)(bytes >= idLength, 0x284 /* "Length of id should fit in the bytes from the map" */);
157
- // Assign and write id for const string.
158
- buffer.write(id, bytes);
159
- // Write length of const string.
160
- buffer.write(data.length, bytes);
161
- // Write const string data.
162
- for (const element of data) {
163
- buffer.write(element);
164
- }
133
+ function serializeDictionaryString(buffer, content, dictionary) {
134
+ let id = dictionary.get(content);
135
+ let idLength;
136
+ if (id === undefined) {
137
+ const data = common_utils_1.IsoBuffer.from(content, "utf8");
138
+ const lengthOfDataLen = calcLength(data.length);
139
+ id = dictionary.size + 1;
140
+ idLength = calcLength(id);
141
+ dictionary.set(content, id);
142
+ const code = lengthOfDataLen > 1 || idLength > 1
143
+ ? zipItDataRepresentationUtils_1.MarkerCodes.ConstStringDeclareBig
144
+ : zipItDataRepresentationUtils_1.MarkerCodes.ConstStringDeclare;
145
+ // Write marker code for const string.
146
+ buffer.write(code);
147
+ const bytes = (0, zipItDataRepresentationUtils_1.getValueSafely)(zipItDataRepresentationUtils_1.codeToBytesMap, code);
148
+ (0, common_utils_1.assert)(bytes >= lengthOfDataLen, 0x283 /* "Length of data len should fit in the bytes from the map" */);
149
+ (0, common_utils_1.assert)(bytes >= idLength, 0x284 /* "Length of id should fit in the bytes from the map" */);
150
+ // Assign and write id for const string.
151
+ buffer.write(id, bytes);
152
+ // Write length of const string.
153
+ buffer.write(data.length, bytes);
154
+ // Write const string data.
155
+ for (const element of data) {
156
+ buffer.write(element);
165
157
  }
166
- else {
167
- idLength = calcLength(id);
168
- }
169
- // Write Marker Code
170
- buffer.write((0, zipItDataRepresentationUtils_1.getValueSafely)(constStringBytesToCodeMap, idLength));
171
- // Write id of const string
172
- buffer.write(id, idLength);
173
158
  }
174
159
  else {
175
- // Write Marker code.
176
- buffer.write(blob.useUtf8Code ? (0, zipItDataRepresentationUtils_1.getValueSafely)(utf8StringBytesToCodeMap, lengthOfDataLen)
177
- : (0, zipItDataRepresentationUtils_1.getValueSafely)(binaryBytesToCodeMap, lengthOfDataLen));
178
- // Write actual data if length greater than 0, otherwise Marker Code is enough.
179
- if (lengthOfDataLen > 0) {
180
- buffer.write(data.length, lengthOfDataLen);
181
- for (const element of data) {
182
- buffer.write(element);
183
- }
160
+ idLength = calcLength(id);
161
+ }
162
+ // Write Marker Code
163
+ buffer.write((0, zipItDataRepresentationUtils_1.getValueSafely)(constStringBytesToCodeMap, idLength));
164
+ // Write id of const string
165
+ buffer.write(id, idLength);
166
+ }
167
+ function serializeString(buffer, content, codeMap = binaryBytesToCodeMap) {
168
+ serializeBlob(buffer, common_utils_1.IsoBuffer.from(content, "utf8"), utf8StringBytesToCodeMap);
169
+ }
170
+ /**
171
+ * Implementation of serialization of blobs in buffer with Marker Codes etc.
172
+ * @param buffer - Buffer to serialize to.
173
+ * @param blob - blob to be serialized.
174
+ * @param dictionary - Const strings dictionary to be used while serializing.
175
+ */
176
+ function serializeBlob(buffer, data, codeMap = binaryBytesToCodeMap) {
177
+ const lengthOfDataLen = calcLength(data.length);
178
+ // Write Marker code.
179
+ buffer.write((0, zipItDataRepresentationUtils_1.getValueSafely)(codeMap, lengthOfDataLen));
180
+ // Write actual data if length greater than 0, otherwise Marker Code is enough.
181
+ if (lengthOfDataLen > 0) {
182
+ buffer.write(data.length, lengthOfDataLen);
183
+ for (const element of data) {
184
+ buffer.write(element);
184
185
  }
185
186
  }
186
187
  }
@@ -203,7 +204,7 @@ function serializeNodeCore(buffer, nodeCore, dictionary) {
203
204
  buffer.write(endCode);
204
205
  }
205
206
  else if (child instanceof zipItDataRepresentationUtils_1.BlobCore) {
206
- serializeBlob(buffer, child, dictionary);
207
+ serializeBlob(buffer, child.buffer);
207
208
  }
208
209
  else if (typeof child === "number") {
209
210
  // Calculate length in which integer will be stored
@@ -219,7 +220,13 @@ function serializeNodeCore(buffer, nodeCore, dictionary) {
219
220
  buffer.write(boolToCodeMap[child ? 1 : 0]);
220
221
  }
221
222
  else {
222
- (0, common_utils_1.unreachableCase)(child, "Unsupported node type");
223
+ (0, common_utils_1.assert)(child._stringElement, 0x3dd /* Unsupported node type */);
224
+ if (child.dictionary) {
225
+ serializeDictionaryString(buffer, child.content, dictionary);
226
+ }
227
+ else {
228
+ serializeString(buffer, child.content);
229
+ }
223
230
  }
224
231
  }
225
232
  }
@@ -235,9 +242,6 @@ class TreeBuilderSerializer extends NodeCoreSerializer {
235
242
  constructor() {
236
243
  super();
237
244
  }
238
- static load(buffer) {
239
- return zipItDataRepresentationUtils_1.TreeBuilder.load(buffer);
240
- }
241
245
  serialize() {
242
246
  const buffer = new WriteBuffer();
243
247
  super.serialize(buffer);
@@ -1 +1 @@
1
- {"version":3,"file":"WriteBufferUtils.js","sourceRoot":"","sources":["../src/WriteBufferUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAuE;AACvE,uDAA+C;AAC/C,iFASwC;AAExC;;;GAGG;AACH,MAAa,WAAW;IAAxB;QACc,SAAI,GAAgB,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QACzC,UAAK,GAAG,CAAC,CAAC;IAsCxB,CAAC;IApCa,IAAI,CAAC,IAAY;QACvB,IAAA,qBAAM,EAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,KAAK,CAAC,4BAA4B,CAAC,CAAC;QACpE,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QAChC,IAAI,IAAI,CAAC,KAA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Z,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,MAAkB;QAC1B,OAAO,0CAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAEM,SAAS;QACZ,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QACjC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;CACJ;AAdD,sDAcC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ReadBuffer } from \"./ReadBufferUtils\";\nimport {\n BlobCore,\n codeToBytesMap,\n getValueSafely,\n MarkerCodes,\n MarkerCodesEnd,\n MarkerCodesStart,\n NodeCore,\n TreeBuilder,\n} from \"./zipItDataRepresentationUtils\";\n\n/**\n * Buffer class, used to sequentially writ data.\n * Used by tree code to serialize tree into binary representation.\n */\nexport class WriteBuffer {\n protected data?: Uint8Array = new Uint8Array(4096);\n protected index = 0;\n\n protected push(code: number) {\n assert(this.data !== undefined, 0x225 /* \"Data should be there\" */);\n const length = this.data.length;\n if (this.index === length) {\n const newData = new Uint8Array(length * 1.2 + 4096);\n let index = 0;\n const oldData = this.data;\n while (index < length) {\n newData[index] = oldData[index];\n index++;\n }\n this.data = newData;\n }\n this.data[this.index] = code % 256;\n this.index++;\n }\n\n public write(codeArg: number, lengthArg = 1) {\n let code = codeArg;\n let length = lengthArg;\n while (length > 0) {\n this.push(code % 256);\n code = Math.floor(code / 256);\n length--;\n }\n assert(code === 0, 0x226 /* Should write complete data */);\n }\n\n public done(): ReadBuffer {\n assert(this.data !== undefined, 0x227 /* \"Data should be there\" */);\n // We can slice it to have smaller memory representation.\n // But it will be way more expensive in terms of CPU cycles!\n const buffer = new ReadBuffer(this.data.subarray(0, this.index));\n this.data = undefined;\n return buffer;\n }\n}\n\n// This list of maps below is reverse mapping of Marker Codes specified in zipItDataRepresentationUtils.ts file.\n// We can also found them on server filestore code.\n// eslint-disable-next-line max-len\n// https://onedrive.visualstudio.com/SharePoint%20Online/_git/SPO?path=/cobalt/Base/Property/BinaryEncodedPropertyReader.cs&version=GBmaster&_a=contents\n\n/**\n * This contains mapping of number of bytes representing the corresponding string length to Marker Codes.\n*/\nconst utf8StringBytesToCodeMap = {\n 0: 13,\n 1: 14,\n 2: 15,\n 4: 16,\n};\n\n/**\n * This contains mapping of number of bytes representing the corresponding length in which actual data(base64 string)\n * will be stored to Marker Codes.\n*/\nconst binaryBytesToCodeMap = {\n 0: 32,\n 1: 33,\n 2: 34,\n 4: 35,\n 8: 16,\n};\n\n/**\n * This contains mapping of number of bytes representing the corresponding const string id to Marker Codes.\n*/\nconst constStringBytesToCodeMap = {\n 1: 17,\n 2: 18,\n 4: 19,\n};\n\n/**\n * This contains mapping of number of bytes to Marker Codes representing the corresponding Integer.\n*/\nconst integerBytesToCodeMap = {\n 0: 1,\n 1: 3,\n 2: 5,\n 4: 7,\n 8: 9,\n};\n\n/**\n * This contains mapping of boolean to Marker Codes representing the corresponding bool value.\n*/\nconst boolToCodeMap = [\n 12, // false\n 11, // true\n];\n\n/**\n * Calculate how many bytes are required to encode an integer. This is always power of 2.\n * So if 6 bytes are required to store an integer than it will return 8. 0 is a special case for which we\n * return 0 as it is usually just represented by marker code and we don't store the actual data.\n * @param num - number to encode.\n */\n export function calcLength(numArg: number) {\n if (numArg === 0) {\n return 0;\n }\n let num = numArg;\n let lengthLen = 0;\n while (num > 0) {\n num = Math.floor(num / 256);\n lengthLen++;\n }\n let res = 1;\n while (res < lengthLen) {\n res *= 2;\n }\n return res;\n}\n\n/**\n * Implementation of serialization of blobs in buffer with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param blob - blob to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\nfunction serializeBlob(buffer: WriteBuffer, blob: BlobCore, dictionary: Map<string, number>) {\n const data = blob.buffer;\n const lengthOfDataLen = calcLength(data.length);\n if (blob.constString) {\n const content = blob.toString();\n let id = dictionary.get(content);\n let idLength: number;\n if (id === undefined) {\n id = dictionary.size + 1;\n idLength = calcLength(id);\n dictionary.set(content, id);\n let code: number;\n if (lengthOfDataLen > 1 || idLength > 1) {\n code = MarkerCodes.ConstStringDeclareBig;\n } else {\n code = MarkerCodes.ConstStringDeclare;\n }\n // Write marker code for const string.\n buffer.write(code);\n const bytes = getValueSafely(codeToBytesMap, code);\n assert(bytes >= lengthOfDataLen, 0x283 /* \"Length of data len should fit in the bytes from the map\" */);\n assert(bytes >= idLength, 0x284 /* \"Length of id should fit in the bytes from the map\" */);\n // Assign and write id for const string.\n buffer.write(id, bytes);\n // Write length of const string.\n buffer.write(data.length, bytes);\n // Write const string data.\n for (const element of data) {\n buffer.write(element);\n }\n } else {\n idLength = calcLength(id);\n }\n // Write Marker Code\n buffer.write(getValueSafely(constStringBytesToCodeMap, idLength));\n // Write id of const string\n buffer.write(id, idLength);\n } else {\n // Write Marker code.\n buffer.write(blob.useUtf8Code ? getValueSafely(utf8StringBytesToCodeMap, lengthOfDataLen)\n : getValueSafely(binaryBytesToCodeMap, lengthOfDataLen));\n // Write actual data if length greater than 0, otherwise Marker Code is enough.\n if (lengthOfDataLen > 0) {\n buffer.write(data.length, lengthOfDataLen);\n for (const element of data) {\n buffer.write(element);\n }\n }\n }\n}\n\n/**\n * Implementation of serialization of nodes with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param nodeCore - Node to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\nfunction serializeNodeCore(buffer: WriteBuffer, nodeCore: NodeCore, dictionary: Map<string, number>) {\n for (const child of nodeCore.nodes) {\n if (child instanceof NodeCore) {\n // For a tree node start and end with set/list start and end marker codes.\n const startCode = MarkerCodesStart[child.type];\n const endCode = MarkerCodesEnd[child.type];\n assert(startCode !== undefined, 0x285 /* \"Start code should not undefined\" */);\n assert(endCode !== undefined, 0x286 /* \"End code should not undefined\" */);\n buffer.write(startCode);\n serializeNodeCore(buffer, child, dictionary);\n buffer.write(endCode);\n } else if (child instanceof BlobCore) {\n serializeBlob(buffer, child, dictionary);\n } else if (typeof child === \"number\") {\n // Calculate length in which integer will be stored\n const len = calcLength(child);\n // Write corresponding Marker code for length of integer.\n buffer.write(getValueSafely(integerBytesToCodeMap, len));\n // Write actual number if greater than 0, otherwise Marker Code is enough.\n if (len > 0) {\n buffer.write(child, len);\n }\n } else if (typeof child === \"boolean\") {\n buffer.write(boolToCodeMap[child ? 1 : 0]);\n } else {\n unreachableCase(child, \"Unsupported node type\");\n }\n }\n}\n\nclass NodeCoreSerializer extends NodeCore {\n constructor() {\n super();\n }\n\n public serialize(buffer: WriteBuffer) {\n serializeNodeCore(buffer, this, new Map<string, number>());\n }\n}\n\nexport class TreeBuilderSerializer extends NodeCoreSerializer {\n constructor() {\n super();\n }\n\n static load(buffer: ReadBuffer): TreeBuilder {\n return TreeBuilder.load(buffer);\n }\n\n public serialize(): ReadBuffer {\n const buffer = new WriteBuffer();\n super.serialize(buffer);\n return buffer.done();\n }\n}\n"]}
1
+ {"version":3,"file":"WriteBufferUtils.js","sourceRoot":"","sources":["../src/WriteBufferUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,iFAQwC;AAExC;;;GAGG;AACH,MAAa,WAAW;IAAxB;QACc,SAAI,GAAgB,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QACzC,UAAK,GAAG,CAAC,CAAC;IAsCxB,CAAC;IApCa,IAAI,CAAC,IAAY;QACvB,IAAA,qBAAM,EAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,KAAK,CAAC,4BAA4B,CAAC,CAAC;QACpE,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QAChC,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,EAAE;YACvB,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,MA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AmB,SAAQ,uCAAQ;IACrC;QACI,KAAK,EAAE,CAAC;IACZ,CAAC;IAEM,SAAS,CAAC,MAAmB;QAChC,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,EAAkB,CAAC,CAAC;IAC/D,CAAC;CACJ;AAED,MAAa,qBAAsB,SAAQ,kBAAkB;IACzD;QACI,KAAK,EAAE,CAAC;IACZ,CAAC;IAEM,SAAS;QACZ,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QACjC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;CACJ;AAVD,sDAUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, IsoBuffer } from \"@fluidframework/common-utils\";\nimport {\n BlobCore,\n codeToBytesMap,\n getValueSafely,\n MarkerCodes,\n MarkerCodesEnd,\n MarkerCodesStart,\n NodeCore,\n} from \"./zipItDataRepresentationUtils\";\n\n/**\n * Buffer class, used to sequentially writ data.\n * Used by tree code to serialize tree into binary representation.\n */\nexport class WriteBuffer {\n protected data?: Uint8Array = new Uint8Array(4096);\n protected index = 0;\n\n protected push(code: number) {\n assert(this.data !== undefined, 0x225 /* \"Data should be there\" */);\n const length = this.data.length;\n if (this.index === length) {\n const newData = new Uint8Array(length * 1.2 + 4096);\n let index = 0;\n const oldData = this.data;\n while (index < length) {\n newData[index] = oldData[index];\n index++;\n }\n this.data = newData;\n }\n this.data[this.index] = code % 256;\n this.index++;\n }\n\n public write(codeArg: number, lengthArg = 1) {\n let code = codeArg;\n let length = lengthArg;\n while (length > 0) {\n this.push(code % 256);\n code = Math.floor(code / 256);\n length--;\n }\n assert(code === 0, 0x226 /* Should write complete data */);\n }\n\n public done(): Uint8Array {\n assert(this.data !== undefined, 0x227 /* \"Data should be there\" */);\n // We can slice it to have smaller memory representation.\n // But it will be way more expensive in terms of CPU cycles!\n const buffer = this.data.subarray(0, this.index);\n this.data = undefined;\n return buffer;\n }\n}\n\n// This list of maps below is reverse mapping of Marker Codes specified in zipItDataRepresentationUtils.ts file.\n// We can also found them on server filestore code.\n// eslint-disable-next-line max-len\n// https://onedrive.visualstudio.com/SharePoint%20Online/_git/SPO?path=/cobalt/Base/Property/BinaryEncodedPropertyReader.cs&version=GBmaster&_a=contents\n\n/**\n * This contains mapping of number of bytes representing the corresponding string length to Marker Codes.\n*/\nconst utf8StringBytesToCodeMap = {\n 0: 13,\n 1: 14,\n 2: 15,\n 4: 16,\n};\n\n/**\n * This contains mapping of number of bytes representing the corresponding length in which actual data(base64 string)\n * will be stored to Marker Codes.\n*/\nconst binaryBytesToCodeMap = {\n 0: 32,\n 1: 33,\n 2: 34,\n 4: 35,\n 8: 16,\n};\n\n/**\n * This contains mapping of number of bytes representing the corresponding const string id to Marker Codes.\n*/\nconst constStringBytesToCodeMap = {\n 1: 17,\n 2: 18,\n 4: 19,\n};\n\n/**\n * This contains mapping of number of bytes to Marker Codes representing the corresponding Integer.\n*/\nconst integerBytesToCodeMap = {\n 0: 1,\n 1: 3,\n 2: 5,\n 4: 7,\n 8: 9,\n};\n\n/**\n * This contains mapping of boolean to Marker Codes representing the corresponding bool value.\n*/\nconst boolToCodeMap = [\n 12, // false\n 11, // true\n];\n\n/**\n * Calculate how many bytes are required to encode an integer. This is always power of 2.\n * So if 6 bytes are required to store an integer than it will return 8. 0 is a special case for which we\n * return 0 as it is usually just represented by marker code and we don't store the actual data.\n * @param num - number to encode.\n */\n export function calcLength(numArg: number) {\n if (numArg === 0) {\n return 0;\n }\n let num = numArg;\n let lengthLen = 0;\n while (num > 0) {\n num = Math.floor(num / 256);\n lengthLen++;\n }\n let res = 1;\n while (res < lengthLen) {\n res *= 2;\n }\n return res;\n}\n\n/**\n * Implementation of serialization of blobs in buffer with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param content - string to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\n function serializeDictionaryString(buffer: WriteBuffer, content: string, dictionary: Map<string, number>) {\n let id = dictionary.get(content);\n let idLength: number;\n if (id === undefined) {\n const data = IsoBuffer.from(content, \"utf8\");\n const lengthOfDataLen = calcLength(data.length);\n\n id = dictionary.size + 1;\n idLength = calcLength(id);\n dictionary.set(content, id);\n const code = lengthOfDataLen > 1 || idLength > 1\n ? MarkerCodes.ConstStringDeclareBig\n : MarkerCodes.ConstStringDeclare;\n // Write marker code for const string.\n buffer.write(code);\n const bytes = getValueSafely(codeToBytesMap, code);\n assert(bytes >= lengthOfDataLen, 0x283 /* \"Length of data len should fit in the bytes from the map\" */);\n assert(bytes >= idLength, 0x284 /* \"Length of id should fit in the bytes from the map\" */);\n // Assign and write id for const string.\n buffer.write(id, bytes);\n // Write length of const string.\n buffer.write(data.length, bytes);\n // Write const string data.\n for (const element of data) {\n buffer.write(element);\n }\n } else {\n idLength = calcLength(id);\n }\n // Write Marker Code\n buffer.write(getValueSafely(constStringBytesToCodeMap, idLength));\n // Write id of const string\n buffer.write(id, idLength);\n}\n\nfunction serializeString(buffer: WriteBuffer, content: string, codeMap = binaryBytesToCodeMap) {\n serializeBlob(\n buffer,\n IsoBuffer.from(content, \"utf8\"),\n utf8StringBytesToCodeMap);\n}\n\n/**\n * Implementation of serialization of blobs in buffer with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param blob - blob to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\nfunction serializeBlob(buffer: WriteBuffer, data: Uint8Array, codeMap: Record<number, number> = binaryBytesToCodeMap) {\n const lengthOfDataLen = calcLength(data.length);\n // Write Marker code.\n buffer.write(getValueSafely(codeMap, lengthOfDataLen));\n // Write actual data if length greater than 0, otherwise Marker Code is enough.\n if (lengthOfDataLen > 0) {\n buffer.write(data.length, lengthOfDataLen);\n for (const element of data) {\n buffer.write(element);\n }\n }\n}\n\n/**\n * Implementation of serialization of nodes with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param nodeCore - Node to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\nfunction serializeNodeCore(buffer: WriteBuffer, nodeCore: NodeCore, dictionary: Map<string, number>) {\n for (const child of nodeCore.nodes) {\n if (child instanceof NodeCore) {\n // For a tree node start and end with set/list start and end marker codes.\n const startCode = MarkerCodesStart[child.type];\n const endCode = MarkerCodesEnd[child.type];\n assert(startCode !== undefined, 0x285 /* \"Start code should not undefined\" */);\n assert(endCode !== undefined, 0x286 /* \"End code should not undefined\" */);\n buffer.write(startCode);\n serializeNodeCore(buffer, child, dictionary);\n buffer.write(endCode);\n } else if (child instanceof BlobCore) {\n serializeBlob(buffer, child.buffer);\n } else if (typeof child === \"number\") {\n // Calculate length in which integer will be stored\n const len = calcLength(child);\n // Write corresponding Marker code for length of integer.\n buffer.write(getValueSafely(integerBytesToCodeMap, len));\n // Write actual number if greater than 0, otherwise Marker Code is enough.\n if (len > 0) {\n buffer.write(child, len);\n }\n } else if (typeof child === \"boolean\") {\n buffer.write(boolToCodeMap[child ? 1 : 0]);\n } else {\n assert(child._stringElement, 0x3dd /* Unsupported node type */);\n if (child.dictionary) {\n serializeDictionaryString(buffer, child.content, dictionary);\n } else {\n serializeString(buffer, child.content);\n }\n }\n }\n}\n\nclass NodeCoreSerializer extends NodeCore {\n constructor() {\n super();\n }\n\n public serialize(buffer: WriteBuffer) {\n serializeNodeCore(buffer, this, new Map<string, number>());\n }\n}\n\nexport class TreeBuilderSerializer extends NodeCoreSerializer {\n constructor() {\n super();\n }\n\n public serialize(): Uint8Array {\n const buffer = new WriteBuffer();\n super.serialize(buffer);\n return buffer.done();\n }\n}\n"]}
@@ -2,8 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { ITelemetryLogger } from "@fluidframework/common-definitions";
5
6
  import { ISnapshotContents } from "./odspPublicUtils";
6
- import { ReadBuffer } from "./ReadBufferUtils";
7
7
  export declare const snapshotMinReadVersion = "1.0";
8
8
  export declare const currentReadVersion = "1.0";
9
9
  /**
@@ -11,5 +11,5 @@ export declare const currentReadVersion = "1.0";
11
11
  * @param buffer - Compact snapshot to be parsed into tree/blobs/ops.
12
12
  * @returns - tree, blobs and ops from the snapshot.
13
13
  */
14
- export declare function parseCompactSnapshotResponse(buffer: ReadBuffer): ISnapshotContents;
14
+ export declare function parseCompactSnapshotResponse(buffer: Uint8Array, logger: ITelemetryLogger): ISnapshotContents;
15
15
  //# sourceMappingURL=compactSnapshotParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compactSnapshotParser.d.ts","sourceRoot":"","sources":["../src/compactSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAa/C,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAkGxC;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,UAAU,GAAG,iBAAiB,CA2BlF"}
1
+ {"version":3,"file":"compactSnapshotParser.d.ts","sourceRoot":"","sources":["../src/compactSnapshotParser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AActD,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAgKxC;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CA0B5G"}
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.parseCompactSnapshotResponse = exports.currentReadVersion = exports.snapshotMinReadVersion = void 0;
8
8
  const common_utils_1 = require("@fluidframework/common-utils");
9
+ const ReadBufferUtils_1 = require("./ReadBufferUtils");
9
10
  const zipItDataRepresentationUtils_1 = require("./zipItDataRepresentationUtils");
10
11
  exports.snapshotMinReadVersion = "1.0";
11
12
  exports.currentReadVersion = "1.0";
@@ -16,12 +17,26 @@ exports.currentReadVersion = "1.0";
16
17
  function readBlobSection(node) {
17
18
  (0, zipItDataRepresentationUtils_1.assertNodeCoreInstance)(node, "TreeBlobs should be of type NodeCore");
18
19
  const blobs = new Map();
19
- for (let count = 0; count < node.length; ++count) {
20
- const blob = node.getNode(count);
21
- const records = (0, zipItDataRepresentationUtils_1.getAndValidateNodeProps)(blob, ["id", "data"]);
20
+ for (const blob of node) {
21
+ (0, zipItDataRepresentationUtils_1.assertNodeCoreInstance)(blob, "blob should be node");
22
+ /**
23
+ * Perf optimization - the most common cases!
24
+ * This is essentially unrolling code below for faster processing
25
+ * It speeds up tree parsing by 2-3x times!
26
+ */
27
+ if (blob.length === 4 && blob.getMaybeString(0) === "id" && blob.getMaybeString(2) === "data") {
28
+ // "id": <node name>
29
+ // "data": <blob>
30
+ blobs.set(blob.getString(1), blob.getBlob(3).arrayBuffer);
31
+ continue;
32
+ }
33
+ /**
34
+ * More generalized workflow
35
+ */
36
+ const records = (0, zipItDataRepresentationUtils_1.getNodeProps)(blob);
22
37
  (0, zipItDataRepresentationUtils_1.assertBlobCoreInstance)(records.data, "data should be of BlobCore type");
23
- (0, zipItDataRepresentationUtils_1.assertBlobCoreInstance)(records.id, "blob id should be of BlobCore type");
24
- blobs.set(records.id.toString(), records.data.arrayBuffer);
38
+ const id = (0, zipItDataRepresentationUtils_1.getStringInstance)(records.id, "blob id should be string");
39
+ blobs.set(id, records.data.arrayBuffer);
25
40
  }
26
41
  return blobs;
27
42
  }
@@ -32,7 +47,7 @@ function readBlobSection(node) {
32
47
  function readOpsSection(node) {
33
48
  (0, zipItDataRepresentationUtils_1.assertNodeCoreInstance)(node, "Deltas should be of type NodeCore");
34
49
  const ops = [];
35
- const records = (0, zipItDataRepresentationUtils_1.getAndValidateNodeProps)(node, ["firstSequenceNumber", "deltas"]);
50
+ const records = (0, zipItDataRepresentationUtils_1.getNodeProps)(node);
36
51
  (0, zipItDataRepresentationUtils_1.assertNumberInstance)(records.firstSequenceNumber, "Seq number should be a number");
37
52
  (0, zipItDataRepresentationUtils_1.assertNodeCoreInstance)(records.deltas, "Deltas should be a Node");
38
53
  for (let i = 0; i < records.deltas.length; ++i) {
@@ -46,32 +61,75 @@ function readOpsSection(node) {
46
61
  * @param node - tree node to de-serialize from
47
62
  */
48
63
  function readTreeSection(node) {
64
+ const trees = {};
49
65
  const snapshotTree = {
50
66
  blobs: {},
51
- commits: {},
52
- trees: {},
67
+ trees,
53
68
  };
54
- for (let count = 0; count < node.length; count++) {
55
- const treeNode = node.getNode(count);
56
- const records = (0, zipItDataRepresentationUtils_1.getAndValidateNodeProps)(treeNode, ["name", "value", "children", "unreferenced"], false);
57
- (0, zipItDataRepresentationUtils_1.assertBlobCoreInstance)(records.name, "Path should be of BlobCore");
58
- const path = records.name.toString();
69
+ for (const treeNode of node) {
70
+ (0, zipItDataRepresentationUtils_1.assertNodeCoreInstance)(treeNode, "tree nodes should be nodes");
71
+ /**
72
+ * Perf optimization - the most common cases!
73
+ * This is essentially unrolling code below for faster processing
74
+ * It speeds up tree parsing by 2-3x times!
75
+ */
76
+ const length = treeNode.length;
77
+ if (length > 0 && treeNode.getMaybeString(0) === "name") {
78
+ if (length === 4) {
79
+ const content = treeNode.getMaybeString(2);
80
+ // "name": <node name>
81
+ // "children": <blob id>
82
+ if (content === "children") {
83
+ trees[treeNode.getString(1)] = readTreeSection(treeNode.getNode(3));
84
+ continue;
85
+ }
86
+ // "name": <node name>
87
+ // "value": <blob id>
88
+ if (content === "value") {
89
+ snapshotTree.blobs[treeNode.getString(1)] = treeNode.getString(3);
90
+ continue;
91
+ }
92
+ }
93
+ // "name": <node name>
94
+ // "nodeType": 3
95
+ // "value": <blob id>
96
+ if (length === 6 &&
97
+ treeNode.getMaybeString(2) === "nodeType" &&
98
+ treeNode.getMaybeString(4) === "value") {
99
+ snapshotTree.blobs[treeNode.getString(1)] = treeNode.getString(5);
100
+ continue;
101
+ }
102
+ // "name": <node name>
103
+ // "unreferenced": true
104
+ // "children": <blob id>
105
+ if (length === 6 &&
106
+ treeNode.getMaybeString(2) === "unreferenced" &&
107
+ treeNode.getMaybeString(4) === "children") {
108
+ trees[treeNode.getString(1)] = readTreeSection(treeNode.getNode(5));
109
+ (0, common_utils_1.assert)(treeNode.getBool(3), 0x3db /* Unreferenced if present should be true */);
110
+ snapshotTree.unreferenced = true;
111
+ continue;
112
+ }
113
+ }
114
+ /**
115
+ * More generalized workflow
116
+ */
117
+ const records = (0, zipItDataRepresentationUtils_1.getNodeProps)(treeNode);
118
+ if (records.unreferenced !== undefined) {
119
+ (0, zipItDataRepresentationUtils_1.assertBoolInstance)(records.unreferenced, "Unreferenced flag should be bool");
120
+ (0, common_utils_1.assert)(records.unreferenced, 0x281 /* "Unreferenced if present should be true" */);
121
+ snapshotTree.unreferenced = true;
122
+ }
123
+ const path = (0, zipItDataRepresentationUtils_1.getStringInstance)(records.name, "Path name should be string");
59
124
  if (records.value !== undefined) {
60
- (0, zipItDataRepresentationUtils_1.assertBlobCoreInstance)(records.value, "Blob value should be BlobCore");
61
- snapshotTree.blobs[path] = records.value.toString();
125
+ snapshotTree.blobs[path] = (0, zipItDataRepresentationUtils_1.getStringInstance)(records.value, "Blob value should be string");
62
126
  }
63
127
  else if (records.children !== undefined) {
64
128
  (0, zipItDataRepresentationUtils_1.assertNodeCoreInstance)(records.children, "Trees should be of type NodeCore");
65
- snapshotTree.trees[path] = readTreeSection(records.children);
129
+ trees[path] = readTreeSection(records.children);
66
130
  }
67
131
  else {
68
- snapshotTree.trees[path] = { blobs: {}, commits: {}, trees: {} };
69
- }
70
- if (records.unreferenced !== undefined) {
71
- (0, zipItDataRepresentationUtils_1.assertBoolInstance)(records.unreferenced, "Unreferenced flag should be bool");
72
- const unreferenced = records.unreferenced.valueOf();
73
- (0, common_utils_1.assert)(unreferenced, 0x281 /* "Unreferenced if present should be true" */);
74
- snapshotTree.unreferenced = unreferenced;
132
+ trees[path] = { blobs: {}, trees: {} };
75
133
  }
76
134
  }
77
135
  return snapshotTree;
@@ -82,12 +140,11 @@ function readTreeSection(node) {
82
140
  */
83
141
  function readSnapshotSection(node) {
84
142
  (0, zipItDataRepresentationUtils_1.assertNodeCoreInstance)(node, "Snapshot should be of type NodeCore");
85
- const records = (0, zipItDataRepresentationUtils_1.getAndValidateNodeProps)(node, ["id", "sequenceNumber", "treeNodes"]);
143
+ const records = (0, zipItDataRepresentationUtils_1.getNodeProps)(node);
86
144
  (0, zipItDataRepresentationUtils_1.assertNodeCoreInstance)(records.treeNodes, "TreeNodes should be of type NodeCore");
87
145
  (0, zipItDataRepresentationUtils_1.assertNumberInstance)(records.sequenceNumber, "sequenceNumber should be of type number");
88
- (0, zipItDataRepresentationUtils_1.assertBlobCoreInstance)(records.id, "snapshotId should be BlobCore");
89
146
  const snapshotTree = readTreeSection(records.treeNodes);
90
- snapshotTree.id = records.id.toString();
147
+ snapshotTree.id = (0, zipItDataRepresentationUtils_1.getStringInstance)(records.id, "snapshotId should be string");
91
148
  const sequenceNumber = records.sequenceNumber.valueOf();
92
149
  return {
93
150
  sequenceNumber,
@@ -99,19 +156,19 @@ function readSnapshotSection(node) {
99
156
  * @param buffer - Compact snapshot to be parsed into tree/blobs/ops.
100
157
  * @returns - tree, blobs and ops from the snapshot.
101
158
  */
102
- function parseCompactSnapshotResponse(buffer) {
103
- const builder = zipItDataRepresentationUtils_1.TreeBuilder.load(buffer);
159
+ function parseCompactSnapshotResponse(buffer, logger) {
160
+ const builder = zipItDataRepresentationUtils_1.TreeBuilder.load(new ReadBufferUtils_1.ReadBuffer(buffer), logger);
104
161
  (0, common_utils_1.assert)(builder.length === 1, 0x219 /* "1 root should be there" */);
105
162
  const root = builder.getNode(0);
106
- const records = (0, zipItDataRepresentationUtils_1.getAndValidateNodeProps)(root, ["mrv", "cv", "lsn", "snapshot", "blobs", "deltas"], false);
107
- (0, zipItDataRepresentationUtils_1.assertBlobCoreInstance)(records.mrv, "minReadVersion should be of BlobCore type");
108
- (0, zipItDataRepresentationUtils_1.assertBlobCoreInstance)(records.cv, "createVersion should be of BlobCore type");
163
+ const records = (0, zipItDataRepresentationUtils_1.getNodeProps)(root);
164
+ const mrv = (0, zipItDataRepresentationUtils_1.getStringInstance)(records.mrv, "minReadVersion should be string");
165
+ const cv = (0, zipItDataRepresentationUtils_1.getStringInstance)(records.cv, "createVersion should be string");
109
166
  if (records.lsn !== undefined) {
110
167
  (0, zipItDataRepresentationUtils_1.assertNumberInstance)(records.lsn, "lsn should be a number");
111
168
  }
112
- (0, common_utils_1.assert)(parseFloat(exports.snapshotMinReadVersion) >= parseFloat(records.mrv.toString()), 0x20f /* "Driver min read version should >= to server minReadVersion" */);
113
- (0, common_utils_1.assert)(parseFloat(records.cv.toString()) >= parseFloat(exports.snapshotMinReadVersion), 0x210 /* "Snapshot should be created with minReadVersion or above" */);
114
- (0, common_utils_1.assert)(exports.currentReadVersion === records.cv.toString(), 0x2c2 /* "Create Version should be equal to currentReadVersion" */);
169
+ (0, common_utils_1.assert)(parseFloat(exports.snapshotMinReadVersion) >= parseFloat(mrv), 0x20f /* "Driver min read version should >= to server minReadVersion" */);
170
+ (0, common_utils_1.assert)(parseFloat(cv) >= parseFloat(exports.snapshotMinReadVersion), 0x210 /* "Snapshot should be created with minReadVersion or above" */);
171
+ (0, common_utils_1.assert)(exports.currentReadVersion === cv, 0x2c2 /* "Create Version should be equal to currentReadVersion" */);
115
172
  return Object.assign(Object.assign({}, readSnapshotSection(records.snapshot)), { blobs: readBlobSection(records.blobs), ops: records.deltas !== undefined ? readOpsSection(records.deltas) : [], latestSequenceNumber: records.lsn });
116
173
  }
117
174
  exports.parseCompactSnapshotResponse = parseComp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CAAC,EAC1E,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAC3E,IAAA,qBAAM,EAAC,0BAAkB,KAAK,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,EAC/C,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAExE,uCACO,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,KACxC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,EACrC,GAAG,EAAE,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EACvE,oBAAoB,EAAE,OAAO,CAAC,GAAG,IACnC;AACN,CAAC;AA3BD,oEA2BC","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 { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ISnapshotContents } from \"./odspPublicUtils\";\nimport { ReadBuffer } from \"./ReadBufferUtils\";\nimport { ISnapshotTreeEx } from \"./contracts\";\nimport {\n assertBlobCoreInstance,\n assertBoolInstance,\n assertNodeCoreInstance,\n assertNumberInstance,\n getAndValidateNodeProps,\n NodeCore,\n NodeTypes,\n TreeBuilder,\n} from \"./zipItDataRepresentationUtils\";\n\nexport const snapshotMinReadVersion = \"1.0\";\nexport const currentReadVersion = \"1.0\";\n\ninterface ISnapshotSection {\n snapshotTree: ISnapshotTree;\n sequenceNumber: number;\n}\n\n/**\n * Recreates blobs section of the tree.\n * @param node - tree node to read blob section from\n */\nfunction readBlobSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"TreeBlobs should be of type NodeCore\");\n const blobs: Map<string, ArrayBuffer> = new Map();\n for (let count = 0; count < node.length; ++count) {\n const blob = node.getNode(count);\n const records = getAndValidateNodeProps(blob, [\"id\", \"data\"]);\n assertBlobCoreInstance(records.data, \"data should be of BlobCore type\");\n assertBlobCoreInstance(records.id, \"blob id should be of BlobCore type\");\n blobs.set(records.id.toString(), records.data.arrayBuffer);\n }\n return blobs;\n}\n\n/**\n * Recreates ops section of the tree.\n * @param node - tree node to read ops section from\n */\nfunction readOpsSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"Deltas should be of type NodeCore\");\n const ops: ISequencedDocumentMessage[] = [];\n const records = getAndValidateNodeProps(node, [\"firstSequenceNumber\", \"deltas\"]);\n assertNumberInstance(records.firstSequenceNumber, \"Seq number should be a number\");\n assertNodeCoreInstance(records.deltas, \"Deltas should be a Node\");\n for (let i = 0; i < records.deltas.length; ++i) {\n ops.push(JSON.parse(records.deltas.getString(i)));\n }\n assert(records.firstSequenceNumber.valueOf() === ops[0].sequenceNumber,\n 0x280 /* \"Validate first op seq number\" */);\n return ops;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readTreeSection(node: NodeCore) {\n const snapshotTree: ISnapshotTreeEx = {\n blobs: {},\n commits: {},\n trees: {},\n };\n for (let count = 0; count < node.length; count++) {\n const treeNode = node.getNode(count);\n const records = getAndValidateNodeProps(treeNode,\n [\"name\", \"value\", \"children\", \"unreferenced\"], false);\n assertBlobCoreInstance(records.name, \"Path should be of BlobCore\");\n const path = records.name.toString();\n if (records.value !== undefined) {\n assertBlobCoreInstance(records.value, \"Blob value should be BlobCore\");\n snapshotTree.blobs[path] = records.value.toString();\n } else if (records.children !== undefined) {\n assertNodeCoreInstance(records.children, \"Trees should be of type NodeCore\");\n snapshotTree.trees[path] = readTreeSection(records.children);\n } else {\n snapshotTree.trees[path] = { blobs: {}, commits: {}, trees: {} };\n }\n if (records.unreferenced !== undefined) {\n assertBoolInstance(records.unreferenced, \"Unreferenced flag should be bool\");\n const unreferenced = records.unreferenced.valueOf();\n assert(unreferenced, 0x281 /* \"Unreferenced if present should be true\" */);\n snapshotTree.unreferenced = unreferenced;\n }\n }\n return snapshotTree;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readSnapshotSection(node: NodeTypes): ISnapshotSection {\n assertNodeCoreInstance(node, \"Snapshot should be of type NodeCore\");\n const records = getAndValidateNodeProps(node,\n [\"id\", \"sequenceNumber\", \"treeNodes\"]);\n\n assertNodeCoreInstance(records.treeNodes, \"TreeNodes should be of type NodeCore\");\n assertNumberInstance(records.sequenceNumber, \"sequenceNumber should be of type number\");\n assertBlobCoreInstance(records.id, \"snapshotId should be BlobCore\");\n const snapshotTree: ISnapshotTree = readTreeSection(records.treeNodes);\n snapshotTree.id = records.id.toString();\n const sequenceNumber = records.sequenceNumber.valueOf();\n return {\n sequenceNumber,\n snapshotTree,\n };\n}\n\n/**\n * Converts snapshot from binary compact representation to tree/blobs/ops.\n * @param buffer - Compact snapshot to be parsed into tree/blobs/ops.\n * @returns - tree, blobs and ops from the snapshot.\n */\nexport function parseCompactSnapshotResponse(buffer: ReadBuffer): ISnapshotContents {\n const builder = TreeBuilder.load(buffer);\n assert(builder.length === 1, 0x219 /* \"1 root should be there\" */);\n const root = builder.getNode(0);\n\n const records = getAndValidateNodeProps(root,\n [\"mrv\", \"cv\", \"lsn\", \"snapshot\", \"blobs\", \"deltas\"], false);\n\n assertBlobCoreInstance(records.mrv, \"minReadVersion should be of BlobCore type\");\n assertBlobCoreInstance(records.cv, \"createVersion should be of BlobCore type\");\n if (records.lsn !== undefined) {\n assertNumberInstance(records.lsn, \"lsn should be a number\");\n }\n\n assert(parseFloat(snapshotMinReadVersion) >= parseFloat(records.mrv.toString()),\n 0x20f /* \"Driver min read version should >= to server minReadVersion\" */);\n assert(parseFloat(records.cv.toString()) >= parseFloat(snapshotMinReadVersion),\n 0x210 /* \"Snapshot should be created with minReadVersion or above\" */);\n assert(currentReadVersion === records.cv.toString(),\n 0x2c2 /* \"Create Version should be equal to currentReadVersion\" */);\n\n return {\n ...readSnapshotSection(records.snapshot),\n blobs: readBlobSection(records.blobs),\n ops: records.deltas !== undefined ? readOpsSection(records.deltas) : [],\n latestSequenceNumber: records.lsn,\n };\n}\n"]}
1
+ {"version":3,"file":"compactSnapshotParser.js","sourceRoot":"","sources":["../src/compactSnapshotParser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAItD,uDAA+C;AAC/C,iFAUwC;AAE3B,QAAA,sBAAsB,GAAG,KAAK,CAAC;AAC/B,QAAA,kBAAkB,GAAG,KAAK,CAAC;AAOxC;;;GAGG;AACH,SAAS,eAAe,CAAC,IAAe;IACpC,IAAA,qDAAsB,EAAC,IAAI,EAAE,sCAAsC,CAAC,CAAC;IACrE,MAAM,KAAK,GAA6B,IAAI,GAAG,EAAE,CAAC;IAClD,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;QACrB,IAAA,qDAAsB,EAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;QAEpD;;;;WAIG;QACH,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE;YAC3F,oBAAoB;YACpB,iBAAiB;YACjB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;YAC1D,SAAS;SACZ;QAED;;WAEG;QACH,MAAM,OAAO,GAAG,IAAA,2CAAY,EAAC,IAAI,CAAC,CAAC;QACnC,IAAA,qDAAsB,EAAC,OAAO,CAAC,IAAI,EAAE,iCAAiC,CAAC,CAAC;QACxE,MAAM,EAAE,GAAG,IAAA,gDAAiB,EAAC,OAAO,CAAC,EAAE,EAAE,0BAA0B,CAAC,CAAC;QACrE,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;KAC3C;IACD,O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A,qBAAM,EAAC,UAAU,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,8BAAsB,CAAC,EACvD,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAC3E,IAAA,qBAAM,EAAC,0BAAkB,KAAK,EAAE,EAC5B,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAExE,uCACO,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,KACxC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,EACrC,GAAG,EAAE,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EACvE,oBAAoB,EAAE,OAAO,CAAC,GAAG,IACnC;AACN,CAAC;AA1BD,oEA0BC","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 { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ISnapshotContents } from \"./odspPublicUtils\";\nimport { ReadBuffer } from \"./ReadBufferUtils\";\nimport {\n assertBlobCoreInstance,\n getStringInstance,\n assertBoolInstance,\n assertNodeCoreInstance,\n assertNumberInstance,\n getNodeProps,\n NodeCore,\n NodeTypes,\n TreeBuilder,\n} from \"./zipItDataRepresentationUtils\";\n\nexport const snapshotMinReadVersion = \"1.0\";\nexport const currentReadVersion = \"1.0\";\n\ninterface ISnapshotSection {\n snapshotTree: ISnapshotTree;\n sequenceNumber: number;\n}\n\n/**\n * Recreates blobs section of the tree.\n * @param node - tree node to read blob section from\n */\nfunction readBlobSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"TreeBlobs should be of type NodeCore\");\n const blobs: Map<string, ArrayBuffer> = new Map();\n for (const blob of node) {\n assertNodeCoreInstance(blob, \"blob should be node\");\n\n /**\n * Perf optimization - the most common cases!\n * This is essentially unrolling code below for faster processing\n * It speeds up tree parsing by 2-3x times!\n */\n if (blob.length === 4 && blob.getMaybeString(0) === \"id\" && blob.getMaybeString(2) === \"data\") {\n // \"id\": <node name>\n // \"data\": <blob>\n blobs.set(blob.getString(1), blob.getBlob(3).arrayBuffer);\n continue;\n }\n\n /**\n * More generalized workflow\n */\n const records = getNodeProps(blob);\n assertBlobCoreInstance(records.data, \"data should be of BlobCore type\");\n const id = getStringInstance(records.id, \"blob id should be string\");\n blobs.set(id, records.data.arrayBuffer);\n }\n return blobs;\n}\n\n/**\n * Recreates ops section of the tree.\n * @param node - tree node to read ops section from\n */\nfunction readOpsSection(node: NodeTypes) {\n assertNodeCoreInstance(node, \"Deltas should be of type NodeCore\");\n const ops: ISequencedDocumentMessage[] = [];\n const records = getNodeProps(node);\n assertNumberInstance(records.firstSequenceNumber, \"Seq number should be a number\");\n assertNodeCoreInstance(records.deltas, \"Deltas should be a Node\");\n for (let i = 0; i < records.deltas.length; ++i) {\n ops.push(JSON.parse(records.deltas.getString(i)));\n }\n assert(records.firstSequenceNumber.valueOf() === ops[0].sequenceNumber,\n 0x280 /* \"Validate first op seq number\" */);\n return ops;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readTreeSection(node: NodeCore) {\n const trees = {};\n const snapshotTree: ISnapshotTree = {\n blobs: {},\n trees,\n };\n for (const treeNode of node) {\n assertNodeCoreInstance(treeNode, \"tree nodes should be nodes\");\n\n /**\n * Perf optimization - the most common cases!\n * This is essentially unrolling code below for faster processing\n * It speeds up tree parsing by 2-3x times!\n */\n const length = treeNode.length;\n if (length > 0 && treeNode.getMaybeString(0) === \"name\") {\n if (length === 4) {\n const content = treeNode.getMaybeString(2);\n // \"name\": <node name>\n // \"children\": <blob id>\n if (content === \"children\") {\n trees[treeNode.getString(1)] = readTreeSection(treeNode.getNode(3));\n continue;\n }\n // \"name\": <node name>\n // \"value\": <blob id>\n if (content === \"value\") {\n snapshotTree.blobs[treeNode.getString(1)] = treeNode.getString(3);\n continue;\n }\n }\n\n // \"name\": <node name>\n // \"nodeType\": 3\n // \"value\": <blob id>\n if (length === 6 &&\n treeNode.getMaybeString(2) === \"nodeType\" &&\n treeNode.getMaybeString(4) === \"value\") {\n snapshotTree.blobs[treeNode.getString(1)] = treeNode.getString(5);\n continue;\n }\n\n // \"name\": <node name>\n // \"unreferenced\": true\n // \"children\": <blob id>\n if (length === 6 &&\n treeNode.getMaybeString(2) === \"unreferenced\" &&\n treeNode.getMaybeString(4) === \"children\") {\n trees[treeNode.getString(1)] = readTreeSection(treeNode.getNode(5));\n assert(treeNode.getBool(3), 0x3db /* Unreferenced if present should be true */);\n snapshotTree.unreferenced = true;\n continue;\n }\n }\n\n /**\n * More generalized workflow\n */\n const records = getNodeProps(treeNode);\n\n if (records.unreferenced !== undefined) {\n assertBoolInstance(records.unreferenced, \"Unreferenced flag should be bool\");\n assert(records.unreferenced, 0x281 /* \"Unreferenced if present should be true\" */);\n snapshotTree.unreferenced = true;\n }\n\n const path = getStringInstance(records.name, \"Path name should be string\");\n if (records.value !== undefined) {\n snapshotTree.blobs[path] = getStringInstance(records.value, \"Blob value should be string\");\n } else if (records.children !== undefined) {\n assertNodeCoreInstance(records.children, \"Trees should be of type NodeCore\");\n trees[path] = readTreeSection(records.children);\n } else {\n trees[path] = { blobs: {}, trees: {} };\n }\n }\n return snapshotTree;\n}\n\n/**\n * Recreates snapshot tree out of tree representation.\n * @param node - tree node to de-serialize from\n */\nfunction readSnapshotSection(node: NodeTypes): ISnapshotSection {\n assertNodeCoreInstance(node, \"Snapshot should be of type NodeCore\");\n const records = getNodeProps(node);\n\n assertNodeCoreInstance(records.treeNodes, \"TreeNodes should be of type NodeCore\");\n assertNumberInstance(records.sequenceNumber, \"sequenceNumber should be of type number\");\n const snapshotTree: ISnapshotTree = readTreeSection(records.treeNodes);\n snapshotTree.id = getStringInstance(records.id, \"snapshotId should be string\");\n const sequenceNumber = records.sequenceNumber.valueOf();\n return {\n sequenceNumber,\n snapshotTree,\n };\n}\n\n/**\n * Converts snapshot from binary compact representation to tree/blobs/ops.\n * @param buffer - Compact snapshot to be parsed into tree/blobs/ops.\n * @returns - tree, blobs and ops from the snapshot.\n */\nexport function parseCompactSnapshotResponse(buffer: Uint8Array, logger: ITelemetryLogger): ISnapshotContents {\n const builder = TreeBuilder.load(new ReadBuffer(buffer), logger);\n assert(builder.length === 1, 0x219 /* \"1 root should be there\" */);\n const root = builder.getNode(0);\n\n const records = getNodeProps(root);\n\n const mrv = getStringInstance(records.mrv, \"minReadVersion should be string\");\n const cv = getStringInstance(records.cv, \"createVersion should be string\");\n if (records.lsn !== undefined) {\n assertNumberInstance(records.lsn, \"lsn should be a number\");\n }\n\n assert(parseFloat(snapshotMinReadVersion) >= parseFloat(mrv),\n 0x20f /* \"Driver min read version should >= to server minReadVersion\" */);\n assert(parseFloat(cv) >= parseFloat(snapshotMinReadVersion),\n 0x210 /* \"Snapshot should be created with minReadVersion or above\" */);\n assert(currentReadVersion === cv,\n 0x2c2 /* \"Create Version should be equal to currentReadVersion\" */);\n\n return {\n ...readSnapshotSection(records.snapshot),\n blobs: readBlobSection(records.blobs),\n ops: records.deltas !== undefined ? readOpsSection(records.deltas) : [],\n latestSequenceNumber: records.lsn,\n };\n}\n"]}