@fluidframework/odsp-driver 1.3.0 → 2.0.0-dev.1.4.5.105745

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) 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 +93 -33
  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 +22 -16
  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.map +1 -1
  37. package/dist/fetchSnapshot.js +14 -19
  38. package/dist/fetchSnapshot.js.map +1 -1
  39. package/dist/getFileLink.d.ts +3 -6
  40. package/dist/getFileLink.d.ts.map +1 -1
  41. package/dist/getFileLink.js +11 -14
  42. package/dist/getFileLink.js.map +1 -1
  43. package/dist/index.d.ts +1 -2
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +3 -3
  46. package/dist/index.js.map +1 -1
  47. package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -1
  48. package/dist/localOdspDriver/localOdspDocumentStorageManager.js +1 -2
  49. package/dist/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -1
  50. package/dist/odspDeltaStorageService.d.ts +1 -1
  51. package/dist/odspDeltaStorageService.d.ts.map +1 -1
  52. package/dist/odspDeltaStorageService.js +4 -8
  53. package/dist/odspDeltaStorageService.js.map +1 -1
  54. package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
  55. package/dist/odspDocumentDeltaConnection.js +3 -6
  56. package/dist/odspDocumentDeltaConnection.js.map +1 -1
  57. package/dist/odspDocumentService.d.ts +1 -0
  58. package/dist/odspDocumentService.d.ts.map +1 -1
  59. package/dist/odspDocumentService.js +10 -5
  60. package/dist/odspDocumentService.js.map +1 -1
  61. package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
  62. package/dist/odspDocumentServiceFactoryCore.js +29 -6
  63. package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
  64. package/dist/odspDocumentStorageManager.d.ts +4 -3
  65. package/dist/odspDocumentStorageManager.d.ts.map +1 -1
  66. package/dist/odspDocumentStorageManager.js +73 -64
  67. package/dist/odspDocumentStorageManager.js.map +1 -1
  68. package/dist/odspDocumentStorageServiceBase.d.ts +1 -1
  69. package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -1
  70. package/dist/odspDocumentStorageServiceBase.js +4 -2
  71. package/dist/odspDocumentStorageServiceBase.js.map +1 -1
  72. package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  73. package/dist/odspDriverUrlResolverForShareLink.js +4 -4
  74. package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
  75. package/dist/odspFluidFileLink.js +1 -1
  76. package/dist/odspFluidFileLink.js.map +1 -1
  77. package/dist/odspLocationRedirection.d.ts +14 -0
  78. package/dist/odspLocationRedirection.d.ts.map +1 -0
  79. package/dist/odspLocationRedirection.js +24 -0
  80. package/dist/odspLocationRedirection.js.map +1 -0
  81. package/dist/odspSnapshotParser.d.ts.map +1 -1
  82. package/dist/odspSnapshotParser.js +1 -2
  83. package/dist/odspSnapshotParser.js.map +1 -1
  84. package/dist/odspSummaryUploadManager.d.ts +6 -3
  85. package/dist/odspSummaryUploadManager.d.ts.map +1 -1
  86. package/dist/odspSummaryUploadManager.js +18 -16
  87. package/dist/odspSummaryUploadManager.js.map +1 -1
  88. package/dist/odspUrlHelper.js +2 -1
  89. package/dist/odspUrlHelper.js.map +1 -1
  90. package/dist/odspUtils.d.ts +11 -2
  91. package/dist/odspUtils.d.ts.map +1 -1
  92. package/dist/odspUtils.js +32 -5
  93. package/dist/odspUtils.js.map +1 -1
  94. package/dist/opsCaching.d.ts.map +1 -1
  95. package/dist/opsCaching.js +3 -2
  96. package/dist/opsCaching.js.map +1 -1
  97. package/dist/packageVersion.d.ts +1 -1
  98. package/dist/packageVersion.d.ts.map +1 -1
  99. package/dist/packageVersion.js +1 -1
  100. package/dist/packageVersion.js.map +1 -1
  101. package/dist/prefetchLatestSnapshot.d.ts +6 -4
  102. package/dist/prefetchLatestSnapshot.d.ts.map +1 -1
  103. package/dist/prefetchLatestSnapshot.js +6 -4
  104. package/dist/prefetchLatestSnapshot.js.map +1 -1
  105. package/dist/retryUtils.d.ts.map +1 -1
  106. package/dist/retryUtils.js +8 -4
  107. package/dist/retryUtils.js.map +1 -1
  108. package/dist/zipItDataRepresentationUtils.d.ts +30 -18
  109. package/dist/zipItDataRepresentationUtils.d.ts.map +1 -1
  110. package/dist/zipItDataRepresentationUtils.js +170 -76
  111. package/dist/zipItDataRepresentationUtils.js.map +1 -1
  112. package/lib/ReadBufferUtils.d.ts.map +1 -1
  113. package/lib/ReadBufferUtils.js +1 -0
  114. package/lib/ReadBufferUtils.js.map +1 -1
  115. package/lib/WriteBufferUtils.d.ts +3 -5
  116. package/lib/WriteBufferUtils.d.ts.map +1 -1
  117. package/lib/WriteBufferUtils.js +61 -57
  118. package/lib/WriteBufferUtils.js.map +1 -1
  119. package/lib/compactSnapshotParser.d.ts +2 -2
  120. package/lib/compactSnapshotParser.d.ts.map +1 -1
  121. package/lib/compactSnapshotParser.js +94 -34
  122. package/lib/compactSnapshotParser.js.map +1 -1
  123. package/lib/compactSnapshotWriter.d.ts +1 -2
  124. package/lib/compactSnapshotWriter.d.ts.map +1 -1
  125. package/lib/compactSnapshotWriter.js +23 -17
  126. package/lib/compactSnapshotWriter.js.map +1 -1
  127. package/lib/contracts.d.ts +1 -18
  128. package/lib/contracts.d.ts.map +1 -1
  129. package/lib/contracts.js.map +1 -1
  130. package/lib/createFile.d.ts +1 -1
  131. package/lib/createFile.d.ts.map +1 -1
  132. package/lib/createFile.js +54 -17
  133. package/lib/createFile.js.map +1 -1
  134. package/lib/createNewUtils.d.ts.map +1 -1
  135. package/lib/createNewUtils.js +0 -1
  136. package/lib/createNewUtils.js.map +1 -1
  137. package/lib/createOdspCreateContainerRequest.d.ts +4 -3
  138. package/lib/createOdspCreateContainerRequest.d.ts.map +1 -1
  139. package/lib/createOdspCreateContainerRequest.js +6 -3
  140. package/lib/createOdspCreateContainerRequest.js.map +1 -1
  141. package/lib/epochTracker.d.ts +1 -0
  142. package/lib/epochTracker.d.ts.map +1 -1
  143. package/lib/epochTracker.js +26 -7
  144. package/lib/epochTracker.js.map +1 -1
  145. package/lib/fetchSnapshot.d.ts.map +1 -1
  146. package/lib/fetchSnapshot.js +14 -19
  147. package/lib/fetchSnapshot.js.map +1 -1
  148. package/lib/getFileLink.d.ts +3 -6
  149. package/lib/getFileLink.d.ts.map +1 -1
  150. package/lib/getFileLink.js +11 -14
  151. package/lib/getFileLink.js.map +1 -1
  152. package/lib/index.d.ts +1 -2
  153. package/lib/index.d.ts.map +1 -1
  154. package/lib/index.js +1 -3
  155. package/lib/index.js.map +1 -1
  156. package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -1
  157. package/lib/localOdspDriver/localOdspDocumentStorageManager.js +1 -2
  158. package/lib/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -1
  159. package/lib/odspDeltaStorageService.d.ts +1 -1
  160. package/lib/odspDeltaStorageService.d.ts.map +1 -1
  161. package/lib/odspDeltaStorageService.js +4 -8
  162. package/lib/odspDeltaStorageService.js.map +1 -1
  163. package/lib/odspDocumentDeltaConnection.d.ts.map +1 -1
  164. package/lib/odspDocumentDeltaConnection.js +3 -6
  165. package/lib/odspDocumentDeltaConnection.js.map +1 -1
  166. package/lib/odspDocumentService.d.ts +1 -0
  167. package/lib/odspDocumentService.d.ts.map +1 -1
  168. package/lib/odspDocumentService.js +11 -6
  169. package/lib/odspDocumentService.js.map +1 -1
  170. package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
  171. package/lib/odspDocumentServiceFactoryCore.js +29 -6
  172. package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
  173. package/lib/odspDocumentStorageManager.d.ts +4 -3
  174. package/lib/odspDocumentStorageManager.d.ts.map +1 -1
  175. package/lib/odspDocumentStorageManager.js +74 -65
  176. package/lib/odspDocumentStorageManager.js.map +1 -1
  177. package/lib/odspDocumentStorageServiceBase.d.ts +1 -1
  178. package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -1
  179. package/lib/odspDocumentStorageServiceBase.js +4 -2
  180. package/lib/odspDocumentStorageServiceBase.js.map +1 -1
  181. package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  182. package/lib/odspDriverUrlResolverForShareLink.js +4 -4
  183. package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
  184. package/lib/odspFluidFileLink.js +1 -1
  185. package/lib/odspFluidFileLink.js.map +1 -1
  186. package/lib/odspLocationRedirection.d.ts +14 -0
  187. package/lib/odspLocationRedirection.d.ts.map +1 -0
  188. package/lib/odspLocationRedirection.js +20 -0
  189. package/lib/odspLocationRedirection.js.map +1 -0
  190. package/lib/odspSnapshotParser.d.ts.map +1 -1
  191. package/lib/odspSnapshotParser.js +1 -2
  192. package/lib/odspSnapshotParser.js.map +1 -1
  193. package/lib/odspSummaryUploadManager.d.ts +6 -3
  194. package/lib/odspSummaryUploadManager.d.ts.map +1 -1
  195. package/lib/odspSummaryUploadManager.js +18 -16
  196. package/lib/odspSummaryUploadManager.js.map +1 -1
  197. package/lib/odspUrlHelper.js +2 -1
  198. package/lib/odspUrlHelper.js.map +1 -1
  199. package/lib/odspUtils.d.ts +11 -2
  200. package/lib/odspUtils.d.ts.map +1 -1
  201. package/lib/odspUtils.js +31 -5
  202. package/lib/odspUtils.js.map +1 -1
  203. package/lib/opsCaching.d.ts.map +1 -1
  204. package/lib/opsCaching.js +3 -2
  205. package/lib/opsCaching.js.map +1 -1
  206. package/lib/packageVersion.d.ts +1 -1
  207. package/lib/packageVersion.d.ts.map +1 -1
  208. package/lib/packageVersion.js +1 -1
  209. package/lib/packageVersion.js.map +1 -1
  210. package/lib/prefetchLatestSnapshot.d.ts +6 -4
  211. package/lib/prefetchLatestSnapshot.d.ts.map +1 -1
  212. package/lib/prefetchLatestSnapshot.js +6 -4
  213. package/lib/prefetchLatestSnapshot.js.map +1 -1
  214. package/lib/retryUtils.d.ts.map +1 -1
  215. package/lib/retryUtils.js +9 -5
  216. package/lib/retryUtils.js.map +1 -1
  217. package/lib/zipItDataRepresentationUtils.d.ts +30 -18
  218. package/lib/zipItDataRepresentationUtils.d.ts.map +1 -1
  219. package/lib/zipItDataRepresentationUtils.js +166 -75
  220. package/lib/zipItDataRepresentationUtils.js.map +1 -1
  221. package/package.json +33 -20
  222. package/src/ReadBufferUtils.ts +1 -0
  223. package/src/WriteBufferUtils.ts +67 -58
  224. package/src/compactSnapshotParser.ts +103 -39
  225. package/src/compactSnapshotWriter.ts +30 -19
  226. package/src/contracts.ts +2 -14
  227. package/src/createFile.ts +75 -15
  228. package/src/createNewUtils.ts +2 -4
  229. package/src/createOdspCreateContainerRequest.ts +7 -4
  230. package/src/epochTracker.ts +47 -7
  231. package/src/fetchSnapshot.ts +19 -19
  232. package/src/getFileLink.ts +12 -22
  233. package/src/index.ts +1 -3
  234. package/src/localOdspDriver/localOdspDocumentStorageManager.ts +2 -2
  235. package/src/odspDeltaStorageService.ts +4 -7
  236. package/src/odspDocumentDeltaConnection.ts +3 -5
  237. package/src/odspDocumentService.ts +13 -11
  238. package/src/odspDocumentServiceFactoryCore.ts +40 -4
  239. package/src/odspDocumentStorageManager.ts +55 -45
  240. package/src/odspDocumentStorageServiceBase.ts +4 -2
  241. package/src/odspDriverUrlResolverForShareLink.ts +2 -5
  242. package/src/odspFluidFileLink.ts +1 -1
  243. package/src/odspLocationRedirection.ts +23 -0
  244. package/src/odspSnapshotParser.ts +3 -4
  245. package/src/odspSummaryUploadManager.ts +14 -10
  246. package/src/odspUrlHelper.ts +1 -1
  247. package/src/odspUtils.ts +40 -7
  248. package/src/opsCaching.ts +3 -2
  249. package/src/packageVersion.ts +1 -1
  250. package/src/prefetchLatestSnapshot.ts +6 -4
  251. package/src/retryUtils.ts +8 -5
  252. package/src/zipItDataRepresentationUtils.ts +198 -75
@@ -2,6 +2,7 @@
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 { ReadBuffer } from "./ReadBufferUtils";
6
7
  /**
7
8
  * Control codes used by tree serialization / decentralization code. Same as on server. These can be found on
@@ -80,7 +81,7 @@ export declare const codeToBytesMap: {
80
81
  export declare function getValueSafely(map: {
81
82
  [index: number]: number;
82
83
  }, key: number): number;
83
- export declare function getAndValidateNodeProps(node: NodeCore, props: string[], enforceAllProps?: boolean): Record<string, NodeTypes>;
84
+ export declare function getNodeProps(node: NodeCore): Record<string, NodeTypes>;
84
85
  export declare function iteratePairs<T>(it: IterableIterator<T>): IterableIterator<[T, T]>;
85
86
  /**
86
87
  * Helper function that returns iterator from an object
@@ -95,24 +96,19 @@ export declare function iterate<T>(obj: {
95
96
  * Note: concrete implementations (derived classes) are not exposed from this module
96
97
  */
97
98
  export declare abstract class BlobCore {
98
- readonly constString: boolean;
99
- readonly useUtf8Code: boolean;
100
99
  abstract get buffer(): Uint8Array;
101
- get arrayBuffer(): ArrayBufferLike;
100
+ abstract get arrayBuffer(): ArrayBufferLike;
102
101
  /**
103
102
  * Represents a blob.
104
- * @param constString - Whether it contains const string declaration.
105
- * @param useUtf8Code - Represents if the utf8 string marker code should be used when representing.
106
103
  */
107
- constructor(constString: boolean, useUtf8Code?: boolean);
108
- toString(): string;
104
+ constructor();
109
105
  }
110
106
  /**
111
107
  * Shallow copy blob, keeps a reference to portion of ReadBuffer
112
108
  * it was constructed from. It takes much less memory compared to BlobDeepCopy
113
109
  */
114
110
  export declare class BlobShallowCopy extends BlobCore {
115
- protected data: ReadBuffer;
111
+ protected data: Uint8Array;
116
112
  protected start: number;
117
113
  protected end: number;
118
114
  /**
@@ -120,15 +116,26 @@ export declare class BlobShallowCopy extends BlobCore {
120
116
  * @param data - Data array of the blob
121
117
  * @param start - Start point of the blob in the buffer.
122
118
  * @param end - End point of the blob in the buffer.
123
- * @param constString - Whether it contains const string declaration.
124
119
  */
125
- constructor(data: ReadBuffer, start: number, end: number, constString: boolean);
120
+ constructor(data: Uint8Array, start: number, end: number);
126
121
  get buffer(): Uint8Array;
127
- static read(buffer: ReadBuffer, lengthLen: number, constString: boolean): BlobCore;
122
+ get arrayBuffer(): ArrayBufferLike;
123
+ static read(buffer: ReadBuffer, lengthLen: number): BlobCore;
128
124
  }
129
- export declare const addStringProperty: (node: NodeCore, a: string, b: string, encodeValAsConstString?: boolean) => void;
125
+ export declare const addStringProperty: (node: NodeCore, a: string, b: string) => void;
126
+ export declare const addDictionaryStringProperty: (node: NodeCore, a: string, b: string) => void;
130
127
  export declare const addNumberProperty: (node: NodeCore, a: string, b: number) => void;
131
128
  export declare const addBoolProperty: (node: NodeCore, a: string, b: boolean) => void;
129
+ export interface IStringElement {
130
+ content: string;
131
+ dictionary: boolean;
132
+ _stringElement: true;
133
+ }
134
+ export interface IStringElementInternal extends Omit<IStringElement, "content"> {
135
+ content?: string;
136
+ startPos: number;
137
+ endPos: number;
138
+ }
132
139
  /**
133
140
  * Three leaf types supported by tree:
134
141
  * 1. Node (sub-tree)
@@ -136,7 +143,7 @@ export declare const addBoolProperty: (node: NodeCore, a: string, b: boolean) =>
136
143
  * 3. integer
137
144
  * 4. boolean
138
145
  */
139
- export declare type NodeTypes = NodeCore | BlobCore | number | boolean;
146
+ export declare type NodeTypes = NodeCore | BlobCore | number | boolean | IStringElement;
140
147
  export declare type NodeCoreTypes = "list" | "set";
141
148
  /**
142
149
  * Node - node in the tree (non-leaf element of the tree)
@@ -151,28 +158,33 @@ export declare class NodeCore {
151
158
  get length(): number;
152
159
  get(index: number): NodeTypes;
153
160
  getString(index: number): string;
161
+ getMaybeString(index: number): string | undefined;
154
162
  getBlob(index: number): BlobCore;
155
163
  getNode(index: number): NodeCore;
156
164
  getNumber(index: number): number;
157
165
  getBool(index: number): boolean;
158
166
  addNode(type?: NodeCoreTypes): NodeCore;
159
- addBlob(blob: Uint8Array, constString: boolean, useUtf8Code?: boolean): void;
160
- addString(payload: string, constString: boolean): void;
167
+ addBlob(blob: Uint8Array): void;
168
+ addDictionaryString(payload: string): void;
169
+ addString(payload: string): void;
161
170
  addNumber(payload: number | undefined): void;
162
171
  addBool(payload: boolean): void;
172
+ private static readString;
163
173
  /**
164
174
  * Load and parse the buffer into a tree.
165
175
  * @param buffer - buffer to read from.
166
176
  */
167
- protected load(buffer: ReadBuffer, dictionary: BlobCore[]): void;
177
+ protected load(buffer: ReadBuffer, logger: ITelemetryLogger): void;
168
178
  }
169
179
  /**
170
180
  * TreeBuilder - Root of the tree.
171
181
  * Provides loading and serialization capabilities.
172
182
  */
173
183
  export declare class TreeBuilder extends NodeCore {
174
- static load(buffer: ReadBuffer): TreeBuilder;
184
+ static load(buffer: ReadBuffer, logger: ITelemetryLogger): TreeBuilder;
175
185
  }
186
+ export declare function getMaybeStringInstance(node: NodeTypes): string | undefined;
187
+ export declare function getStringInstance(node: NodeTypes, message: string): string;
176
188
  export declare function assertBlobCoreInstance(node: NodeTypes, message: string): asserts node is BlobCore;
177
189
  export declare function assertNodeCoreInstance(node: NodeTypes, message: string): asserts node is NodeCore;
178
190
  export declare function assertNumberInstance(node: NodeTypes, message: string): asserts node is number;
@@ -1 +1 @@
1
- {"version":3,"file":"zipItDataRepresentationUtils.d.ts","sourceRoot":"","sources":["../src/zipItDataRepresentationUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAK/C;;;GAGG;AACH,oBAAY,WAAW;IACnB,QAAQ,KAAK;IACb,SAAS,KAAK;IAEd,WAAW,KAAK;IAChB,aAAa,KAAK;IAClB,cAAc,KAAK;IACnB,cAAc,KAAK;IAEnB,cAAc,KAAK;IACnB,eAAe,KAAK;IACpB,eAAe,KAAK;IACpB,kBAAkB,KAAK;IACvB,qBAAqB,KAAK;IAE1B,IAAI,IAAI;IACR,KAAK,IAAI;IACT,MAAM,IAAI;IACV,MAAM,IAAI;IACV,MAAM,IAAI;IACV,IAAI,IAAI;IACR,KAAK,IAAI;IACT,KAAK,IAAI;IACT,KAAK,IAAI;IAET,WAAW,KAAK;IAChB,aAAa,KAAK;IAClB,cAAc,KAAK;IACnB,cAAc,KAAK;IACnB,cAAc,KAAK;CACtB;AAED;;GAEG;AACH,oBAAY,gBAAgB;IACxB,MAAM,KAAK;IACX,KAAK,KAAK;CACb;AAED;;GAEG;AACH,oBAAY,cAAc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O,CAAC,IAAI,IAAI,OAAO,CAKzB"}
@@ -4,7 +4,7 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.assertBoolInstance = exports.assertNumberInstance = exports.assertNodeCoreInstance = exports.assertBlobCoreInstance = exports.TreeBuilder = exports.NodeCore = exports.addBoolProperty = exports.addNumberProperty = exports.addStringProperty = exports.BlobShallowCopy = exports.BlobCore = exports.iterate = exports.iteratePairs = exports.getAndValidateNodeProps = exports.getValueSafely = exports.codeToBytesMap = exports.MarkerCodesEnd = exports.MarkerCodesStart = exports.MarkerCodes = void 0;
7
+ exports.assertBoolInstance = exports.assertNumberInstance = exports.assertNodeCoreInstance = exports.assertBlobCoreInstance = exports.getStringInstance = exports.getMaybeStringInstance = exports.TreeBuilder = exports.NodeCore = exports.addBoolProperty = exports.addNumberProperty = exports.addDictionaryStringProperty = exports.addStringProperty = exports.BlobShallowCopy = exports.BlobCore = exports.iterate = exports.iteratePairs = exports.getNodeProps = exports.getValueSafely = exports.codeToBytesMap = exports.MarkerCodesEnd = exports.MarkerCodesStart = exports.MarkerCodes = void 0;
8
8
  /**
9
9
  * Data representation which is followed(zipIt Protocol) here is described in this document:
10
10
  * https://microsoft.sharepoint-df.com/:w:/t/ODSPFileStore/ER06b64K_XdDjEyAKl-UT60BJiId39SCVkYSyo_2pvH9gQ?e=KYQ0c5
@@ -101,23 +101,15 @@ function getValueSafely(map, key) {
101
101
  return val;
102
102
  }
103
103
  exports.getValueSafely = getValueSafely;
104
- function getAndValidateNodeProps(node, props, enforceAllProps = true) {
105
- const propSet = new Set(props);
104
+ function getNodeProps(node) {
106
105
  const res = {};
107
106
  for (const [keyNode, valueNode] of node.iteratePairs()) {
108
- assertBlobCoreInstance(keyNode, "keynode should be a blob");
109
- const keyStr = keyNode.toString();
110
- if (propSet.has(keyStr)) {
111
- propSet.delete(keyStr);
112
- res[keyStr] = valueNode;
113
- }
114
- }
115
- if (enforceAllProps) {
116
- (0, common_utils_1.assert)(propSet.size === 0, 0x288 /* All properties should exist */);
107
+ const id = getStringInstance(keyNode, "keynode should be a string");
108
+ res[id] = valueNode;
117
109
  }
118
110
  return res;
119
111
  }
120
- exports.getAndValidateNodeProps = getAndValidateNodeProps;
112
+ exports.getNodeProps = getNodeProps;
121
113
  function iteratePairs(it) {
122
114
  const res = {
123
115
  next: () => {
@@ -150,19 +142,8 @@ exports.iterate = iterate;
150
142
  class BlobCore {
151
143
  /**
152
144
  * Represents a blob.
153
- * @param constString - Whether it contains const string declaration.
154
- * @param useUtf8Code - Represents if the utf8 string marker code should be used when representing.
155
145
  */
156
- constructor(constString, useUtf8Code = false) {
157
- this.constString = constString;
158
- this.useUtf8Code = useUtf8Code;
159
- }
160
- get arrayBuffer() {
161
- return (0, common_utils_1.Uint8ArrayToArrayBuffer)(this.buffer);
162
- }
163
- toString() {
164
- return (0, common_utils_1.Uint8ArrayToString)(this.buffer, "utf-8");
165
- }
146
+ constructor() { }
166
147
  }
167
148
  exports.BlobCore = BlobCore;
168
149
  /**
@@ -174,23 +155,24 @@ class BlobDeepCopy extends BlobCore {
174
155
  /**
175
156
  * Represents a deep copy of the blob.
176
157
  * @param data - Data array of the blob
177
- * @param constString - Whether it contains const string declaration.
178
- * @param useUtf8Code - Represents if the utf8 string marker code should be used when representing.
179
158
  */
180
- constructor(data, constString, useUtf8Code = false) {
181
- super(constString, useUtf8Code);
159
+ constructor(data) {
160
+ super();
182
161
  this.data = data;
183
162
  }
184
163
  get buffer() {
185
164
  return this.data;
186
165
  }
187
- static read(buffer, lengthLen, constString) {
166
+ get arrayBuffer() {
167
+ return (0, common_utils_1.Uint8ArrayToArrayBuffer)(this.buffer);
168
+ }
169
+ static read(buffer, lengthLen) {
188
170
  const length = buffer.read(lengthLen);
189
171
  const data = new Uint8Array(length);
190
172
  for (let counter = 0; counter < length; counter++) {
191
173
  data[counter] = buffer.read();
192
174
  }
193
- return new BlobDeepCopy(data, constString);
175
+ return new BlobDeepCopy(data);
194
176
  }
195
177
  }
196
178
  /**
@@ -203,37 +185,46 @@ class BlobShallowCopy extends BlobCore {
203
185
  * @param data - Data array of the blob
204
186
  * @param start - Start point of the blob in the buffer.
205
187
  * @param end - End point of the blob in the buffer.
206
- * @param constString - Whether it contains const string declaration.
207
188
  */
208
- constructor(data, start, end, constString) {
209
- super(constString);
189
+ constructor(data, start, end) {
190
+ super();
210
191
  this.data = data;
211
192
  this.start = start;
212
193
  this.end = end;
213
194
  }
214
195
  get buffer() {
215
- return this.data.buffer.subarray(this.start, this.end);
196
+ return this.data.subarray(this.start, this.end);
197
+ }
198
+ // Equivalent to Uint8ArrayToArrayBuffer(this.buffer)
199
+ get arrayBuffer() {
200
+ const offset = this.data.byteOffset;
201
+ return this.data.buffer.slice(this.start + offset, this.end + offset);
216
202
  }
217
- static read(buffer, lengthLen, constString) {
203
+ static read(buffer, lengthLen) {
218
204
  const length = buffer.read(lengthLen);
219
205
  const pos = buffer.pos;
220
206
  buffer.skip(length);
221
- return new BlobShallowCopy(buffer, pos, pos + length, constString);
207
+ return new BlobShallowCopy(buffer.buffer, pos, pos + length);
222
208
  }
223
209
  }
224
210
  exports.BlobShallowCopy = BlobShallowCopy;
225
- const addStringProperty = (node, a, b, encodeValAsConstString = false) => {
226
- node.addString(a, true);
227
- node.addString(b, encodeValAsConstString);
211
+ const addStringProperty = (node, a, b) => {
212
+ node.addDictionaryString(a);
213
+ node.addString(b);
228
214
  };
229
215
  exports.addStringProperty = addStringProperty;
216
+ const addDictionaryStringProperty = (node, a, b) => {
217
+ node.addDictionaryString(a);
218
+ node.addString(b);
219
+ };
220
+ exports.addDictionaryStringProperty = addDictionaryStringProperty;
230
221
  const addNumberProperty = (node, a, b) => {
231
- node.addString(a, true);
222
+ node.addDictionaryString(a);
232
223
  node.addNumber(b);
233
224
  };
234
225
  exports.addNumberProperty = addNumberProperty;
235
226
  const addBoolProperty = (node, a, b) => {
236
- node.addString(a, true);
227
+ node.addDictionaryString(a);
237
228
  node.addBool(b);
238
229
  };
239
230
  exports.addBoolProperty = addBoolProperty;
@@ -260,8 +251,11 @@ class NodeCore {
260
251
  get(index) { return this.children[index]; }
261
252
  getString(index) {
262
253
  const node = this.children[index];
263
- assertBlobCoreInstance(node, "getString should return stringblob");
264
- return node.toString();
254
+ return getStringInstance(node, "getString should return string");
255
+ }
256
+ getMaybeString(index) {
257
+ const node = this.children[index];
258
+ return getMaybeStringInstance(node);
265
259
  }
266
260
  getBlob(index) {
267
261
  const node = this.children[index];
@@ -288,11 +282,22 @@ class NodeCore {
288
282
  this.children.push(node);
289
283
  return node;
290
284
  }
291
- addBlob(blob, constString, useUtf8Code = false) {
292
- this.children.push(new BlobDeepCopy(blob, constString, useUtf8Code));
285
+ addBlob(blob) {
286
+ this.children.push(new BlobDeepCopy(blob));
293
287
  }
294
- addString(payload, constString) {
295
- this.addBlob(common_utils_1.IsoBuffer.from(payload, "utf-8"), constString, true);
288
+ addDictionaryString(payload) {
289
+ this.children.push({
290
+ content: payload,
291
+ dictionary: true,
292
+ _stringElement: true,
293
+ });
294
+ }
295
+ addString(payload) {
296
+ this.children.push({
297
+ content: payload,
298
+ dictionary: false,
299
+ _stringElement: true,
300
+ });
296
301
  }
297
302
  addNumber(payload) {
298
303
  (0, common_utils_1.assert)(Number.isInteger(payload), 0x231 /* "Number should be an integer" */);
@@ -302,59 +307,88 @@ class NodeCore {
302
307
  addBool(payload) {
303
308
  this.children.push(payload);
304
309
  }
310
+ // Can we do more efficiently here, without extra objects somehow??
311
+ static readString(buffer, code, dictionary) {
312
+ const lengthLen = getValueSafely(exports.codeToBytesMap, code);
313
+ const length = buffer.read(lengthLen);
314
+ const startPos = buffer.pos;
315
+ buffer.skip(length);
316
+ const result = {
317
+ // Note: Setting here property 'content: undefined' makes code substantially slower!
318
+ dictionary,
319
+ _stringElement: true,
320
+ startPos,
321
+ endPos: buffer.pos,
322
+ };
323
+ // We are lying here in terms of presence of `content` property.
324
+ // This will be addressed at the bottom of NodeCore.load() by resolving all strings at once!
325
+ // It's equivalent (but much slower!) to do it here via
326
+ // result.content = Uint8ArrayToString(buffer.buffer.subarray(startPos, buffer.pos), "utf-8");
327
+ return result;
328
+ }
305
329
  /**
306
330
  * Load and parse the buffer into a tree.
307
331
  * @param buffer - buffer to read from.
308
332
  */
309
- load(buffer, dictionary) {
333
+ load(buffer, logger) {
334
+ const stack = [];
335
+ const stringsToResolve = [];
336
+ const dictionary = [];
337
+ let children = this.children;
310
338
  for (; !buffer.eof;) {
311
- let childValue;
312
339
  const code = buffer.read();
313
340
  switch (code) {
314
341
  case MarkerCodesStart.list:
315
342
  case MarkerCodesStart.set: {
316
- childValue = new NodeCore(code === MarkerCodesStart.set ? "set" : "list");
317
- this.children.push(childValue);
318
- childValue.load(buffer, dictionary);
319
- break;
343
+ const childValue = new NodeCore(code === MarkerCodesStart.set ? "set" : "list");
344
+ children.push(childValue);
345
+ stack.push(children);
346
+ children = childValue.children;
347
+ continue;
320
348
  }
321
349
  case MarkerCodes.ConstStringDeclare:
322
350
  case MarkerCodes.ConstStringDeclareBig:
323
351
  {
324
352
  const stringId = buffer.read(getValueSafely(exports.codeToBytesMap, code));
325
- const constString = BlobShallowCopy.read(buffer, getValueSafely(exports.codeToBytesMap, code), true);
353
+ const constString = NodeCore.readString(buffer, code, true /* dictionary */);
354
+ stringsToResolve.push(constString);
326
355
  dictionary[stringId] = constString;
327
- break;
356
+ continue;
328
357
  }
329
358
  case MarkerCodes.ConstString8Id:
330
359
  case MarkerCodes.ConstString16Id:
331
360
  case MarkerCodes.ConstString32Id:
332
361
  {
333
362
  const stringId = buffer.read(getValueSafely(exports.codeToBytesMap, code));
334
- childValue = dictionary[stringId];
335
- this.children.push(childValue);
336
- break;
363
+ const content = dictionary[stringId];
364
+ (0, common_utils_1.assert)(content !== undefined, 0x3de /* const string not found */);
365
+ children.push(content);
366
+ continue;
337
367
  }
338
368
  case MarkerCodes.StringEmpty:
339
369
  case MarkerCodes.String8Length:
340
370
  case MarkerCodes.String16Length:
341
371
  case MarkerCodes.String32Length:
372
+ {
373
+ const str = NodeCore.readString(buffer, code, false /* dictionary */);
374
+ stringsToResolve.push(str);
375
+ children.push(str);
376
+ continue;
377
+ }
342
378
  case MarkerCodes.BinaryEmpty:
343
379
  case MarkerCodes.BinarySingle8:
344
380
  case MarkerCodes.BinarySingle16:
345
381
  case MarkerCodes.BinarySingle32:
346
382
  case MarkerCodes.BinarySingle64:
347
383
  {
348
- childValue = BlobShallowCopy.read(buffer, getValueSafely(exports.codeToBytesMap, code), false);
349
- this.children.push(childValue);
350
- break;
384
+ children.push(BlobShallowCopy.read(buffer, getValueSafely(exports.codeToBytesMap, code)));
385
+ continue;
351
386
  }
352
387
  // If integer is 0.
353
388
  case MarkerCodes.Int0:
354
389
  {
355
- childValue = 0;
356
- this.children.push(childValue);
357
- break;
390
+ children.push(0);
391
+ continue;
358
392
  }
359
393
  case MarkerCodes.UInt8:
360
394
  case MarkerCodes.UInt16:
@@ -365,23 +399,66 @@ class NodeCore {
365
399
  case MarkerCodes.Int32:
366
400
  case MarkerCodes.Int64:
367
401
  {
368
- childValue = buffer.read(getValueSafely(exports.codeToBytesMap, code));
369
- this.children.push(childValue);
370
- break;
402
+ children.push(buffer.read(getValueSafely(exports.codeToBytesMap, code)));
403
+ continue;
371
404
  }
372
405
  case MarkerCodes.BoolTrue:
373
- this.children.push(true);
374
- break;
406
+ children.push(true);
407
+ continue;
375
408
  case MarkerCodes.BoolFalse:
376
- this.children.push(false);
377
- break;
409
+ children.push(false);
410
+ continue;
378
411
  case MarkerCodesEnd.list:
379
412
  case MarkerCodesEnd.set:
380
- return;
413
+ // Note: We are not checking that end marker matches start marker.
414
+ // I.e. that we do not have a case where we start a 'list' but end with a 'set'
415
+ // Checking it would require more state tracking that seems not very useful, given
416
+ // our code does not care.
417
+ children = stack.pop();
418
+ // To my surprise, checking children !== undefined adds measurable cost!
419
+ // We will rely on children.push() crashing in case of mismatch, and check below
420
+ // (outside of the loop)
421
+ continue;
381
422
  default:
382
423
  throw new Error(`Invalid code: ${code}`);
383
424
  }
384
425
  }
426
+ // This also ensures that stack.length === 0.
427
+ (0, common_utils_1.assert)(children === this.children, 0x3e7 /* Unpaired start/end list/set markers! */);
428
+ /**
429
+ * Process all the strings at once!
430
+ */
431
+ let length = 0;
432
+ for (const el of stringsToResolve) {
433
+ length += el.endPos - el.startPos + 1;
434
+ }
435
+ const stringBuffer = new Uint8Array(length);
436
+ length = 0;
437
+ const input = buffer.buffer;
438
+ (0, common_utils_1.assert)(input.byteOffset === 0, 0x3e8 /* code below assumes no offset */);
439
+ for (const el of stringsToResolve) {
440
+ for (let it = el.startPos; it < el.endPos; it++) {
441
+ stringBuffer[length] = input[it];
442
+ length++;
443
+ }
444
+ stringBuffer[length] = 0;
445
+ length++;
446
+ }
447
+ if (length === stringBuffer.length) {
448
+ // All is good, we expect all the cases to get here
449
+ const result = (0, common_utils_1.Uint8ArrayToString)(stringBuffer, "utf-8").split(String.fromCharCode(0));
450
+ (0, common_utils_1.assert)(result.length === stringsToResolve.length + 1, 0x3e9 /* String content has \0 chars! */);
451
+ for (let i = 0; i < stringsToResolve.length; i++) {
452
+ stringsToResolve[i].content = result[i];
453
+ }
454
+ }
455
+ else {
456
+ // Recovery code
457
+ logger.sendErrorEvent({ eventName: "StringParsingError" });
458
+ for (const el of stringsToResolve) {
459
+ (0, common_utils_1.assert)(el.content === (0, common_utils_1.Uint8ArrayToString)(input.subarray(el.startPos, el.endPos), "utf-8"), 0x3ea /* test */);
460
+ }
461
+ }
385
462
  }
386
463
  }
387
464
  exports.NodeCore = NodeCore;
@@ -390,15 +467,29 @@ exports.NodeCore = NodeCore;
390
467
  * Provides loading and serialization capabilities.
391
468
  */
392
469
  class TreeBuilder extends NodeCore {
393
- static load(buffer) {
470
+ static load(buffer, logger) {
394
471
  const builder = new TreeBuilder();
395
- const dictionary = new Array();
396
- builder.load(buffer, dictionary);
472
+ builder.load(buffer, logger);
397
473
  (0, common_utils_1.assert)(buffer.eof, 0x233 /* "Unexpected data at the end of buffer" */);
398
474
  return builder;
399
475
  }
400
476
  }
401
477
  exports.TreeBuilder = TreeBuilder;
478
+ function getMaybeStringInstance(node) {
479
+ const maybeString = node;
480
+ if (maybeString._stringElement) {
481
+ return maybeString.content;
482
+ }
483
+ }
484
+ exports.getMaybeStringInstance = getMaybeStringInstance;
485
+ function getStringInstance(node, message) {
486
+ const maybeString = node;
487
+ if (maybeString._stringElement) {
488
+ return maybeString.content;
489
+ }
490
+ throwBufferParseException(node, "BlobCore", message);
491
+ }
492
+ exports.getStringInstance = getStringInstance;
402
493
  function assertBlobCoreInstance(node, message) {
403
494
  if (node instanceof BlobCore) {
404
495
  return;
@@ -447,6 +538,9 @@ function getNodeType(value) {
447
538
  else if (typeof value === "boolean") {
448
539
  return "Boolean";
449
540
  }
541
+ else if (value._stringElement) {
542
+ return "String";
543
+ }
450
544
  return "UnknownType";
451
545
  }
452
546
  //# sourceMappingURL=zipItDataRepresentationUtils.js.map