@fluid-experimental/property-dds 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeflatedPropertyTreeFactory = void 0;
4
+ /*!
5
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
6
+ * Licensed under the MIT License.
7
+ */
8
+ const pako_1 = require("pako");
9
+ const common_utils_1 = require("@fluidframework/common-utils");
10
+ const propertyTreeExt_1 = require("./propertyTreeExt");
11
+ function encodeSummary(snapshotSummary) {
12
+ const summaryStr = JSON.stringify(snapshotSummary);
13
+ const unzipped = new TextEncoder().encode(summaryStr);
14
+ const serializedSummary = (0, pako_1.deflate)(unzipped);
15
+ return serializedSummary;
16
+ }
17
+ function decodeSummary(serializedSummary) {
18
+ const unzipped = (0, pako_1.inflate)(serializedSummary);
19
+ const summaryStr = new TextDecoder().decode(unzipped);
20
+ const snapshotSummary = JSON.parse(summaryStr);
21
+ return snapshotSummary;
22
+ }
23
+ function encodeMessage(change) {
24
+ const changeSetStr = JSON.stringify(change.changeSet);
25
+ const unzipped = new TextEncoder().encode(changeSetStr);
26
+ const zipped = (0, pako_1.deflate)(unzipped);
27
+ const zippedStr = (0, common_utils_1.bufferToString)(zipped, "base64");
28
+ if (zippedStr.length < changeSetStr.length) {
29
+ // eslint-disable-next-line @typescript-eslint/dot-notation
30
+ change["isZipped"] = "1";
31
+ change.changeSet = zippedStr;
32
+ }
33
+ return change;
34
+ }
35
+ function decodeMessage(transferChange) {
36
+ // eslint-disable-next-line @typescript-eslint/dot-notation
37
+ if (transferChange["isZipped"]) {
38
+ const zipped = (0, common_utils_1.stringToBuffer)(transferChange.changeSet, "base64");
39
+ const unzipped = (0, pako_1.inflate)(zipped);
40
+ const changeSetStr = new TextDecoder().decode(unzipped);
41
+ transferChange.changeSet = JSON.parse(changeSetStr);
42
+ }
43
+ return transferChange;
44
+ }
45
+ const encDec = {
46
+ messageEncoder: {
47
+ encode: encodeMessage,
48
+ decode: decodeMessage,
49
+ },
50
+ summaryEncoder: {
51
+ encode: encodeSummary,
52
+ decode: decodeSummary,
53
+ },
54
+ };
55
+ class DeflatedPropertyTreeFactory {
56
+ get type() {
57
+ return DeflatedPropertyTreeFactory.Type;
58
+ }
59
+ get attributes() {
60
+ return DeflatedPropertyTreeFactory.Attributes;
61
+ }
62
+ async load(runtime, id, services, attributes, url) {
63
+ const options = {};
64
+ const instance = new propertyTreeExt_1.DeflatedPropertyTree(id, runtime, attributes, options, { encDec });
65
+ await instance.load(services);
66
+ return instance;
67
+ }
68
+ create(document, id, requestUrl) {
69
+ const options = {};
70
+ const cell = new propertyTreeExt_1.DeflatedPropertyTree(id, document, this.attributes, options, { encDec });
71
+ cell.initializeLocal();
72
+ return cell;
73
+ }
74
+ }
75
+ exports.DeflatedPropertyTreeFactory = DeflatedPropertyTreeFactory;
76
+ DeflatedPropertyTreeFactory.Type = "DeflatedPropertyTree:84534a0fe613522101f6";
77
+ DeflatedPropertyTreeFactory.Attributes = {
78
+ type: DeflatedPropertyTreeFactory.Type,
79
+ snapshotFormatVersion: "0.1",
80
+ packageVersion: "0.0.1",
81
+ };
82
+ //# sourceMappingURL=propertyTreeExtFactories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propertyTreeExtFactories.js","sourceRoot":"","sources":["../src/propertyTreeExtFactories.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,+BAAwC;AACxC,+DAA8E;AAS9E,uDAAyD;AAEzD,SAAS,aAAa,CAAC,eAAiC;IACpD,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACtD,MAAM,iBAAiB,GAAW,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC;IACpD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ft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { deflate, inflate } from \"pako\";\nimport { bufferToString, stringToBuffer } from \"@fluidframework/common-utils\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelServices,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { IPropertyTreeMessage, ISharedPropertyTreeEncDec, ISnapshotSummary, SharedPropertyTreeOptions }\nfrom \"./propertyTree\";\nimport { DeflatedPropertyTree } from \"./propertyTreeExt\";\n\nfunction encodeSummary(snapshotSummary: ISnapshotSummary) {\n const summaryStr = JSON.stringify(snapshotSummary);\n const unzipped = new TextEncoder().encode(summaryStr);\n const serializedSummary: Buffer = deflate(unzipped);\n return serializedSummary;\n}\n\nfunction decodeSummary(serializedSummary): ISnapshotSummary {\n const unzipped = inflate(serializedSummary);\n const summaryStr = new TextDecoder().decode(unzipped);\n const snapshotSummary: ISnapshotSummary = JSON.parse(summaryStr);\n return snapshotSummary;\n}\n\nfunction encodeMessage(change: IPropertyTreeMessage) {\n const changeSetStr = JSON.stringify(change.changeSet);\n const unzipped = new TextEncoder().encode(changeSetStr);\n const zipped: Buffer = deflate(unzipped);\n const zippedStr = bufferToString(zipped, \"base64\");\n if (zippedStr.length < changeSetStr.length) {\n // eslint-disable-next-line @typescript-eslint/dot-notation\n change[\"isZipped\"] = \"1\";\n change.changeSet = zippedStr;\n }\n return change;\n}\n\nfunction decodeMessage(transferChange: IPropertyTreeMessage) {\n // eslint-disable-next-line @typescript-eslint/dot-notation\n if (transferChange[\"isZipped\"]) {\n const zipped = stringToBuffer(transferChange.changeSet, \"base64\");\n const unzipped = inflate(zipped);\n const changeSetStr = new TextDecoder().decode(unzipped);\n transferChange.changeSet = JSON.parse(changeSetStr);\n }\n return transferChange;\n}\n\nconst encDec: ISharedPropertyTreeEncDec = {\n messageEncoder: {\n encode: encodeMessage,\n decode: decodeMessage,\n },\n summaryEncoder: {\n encode: encodeSummary,\n decode: decodeSummary,\n },\n};\n\nexport class DeflatedPropertyTreeFactory implements IChannelFactory {\n public static readonly Type = \"DeflatedPropertyTree:84534a0fe613522101f6\";\n\n public static readonly Attributes: IChannelAttributes = {\n type: DeflatedPropertyTreeFactory.Type,\n snapshotFormatVersion: \"0.1\",\n packageVersion: \"0.0.1\",\n };\n\n public get type() {\n return DeflatedPropertyTreeFactory.Type;\n }\n\n public get attributes() {\n return DeflatedPropertyTreeFactory.Attributes;\n }\n\n public async load(\n runtime: IFluidDataStoreRuntime,\n id: string,\n services: IChannelServices,\n attributes: IChannelAttributes,\n url?: string,\n ): Promise<DeflatedPropertyTree> {\n const options = {};\n const instance = new DeflatedPropertyTree(id, runtime, attributes, options as SharedPropertyTreeOptions\n , { encDec });\n await instance.load(services);\n return instance;\n }\n\n public create(document: IFluidDataStoreRuntime, id: string, requestUrl?: string): DeflatedPropertyTree {\n const options = {};\n const cell = new DeflatedPropertyTree(id, document,\n this.attributes, options as SharedPropertyTreeOptions, { encDec });\n cell.initializeLocal();\n return cell;\n }\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -4,4 +4,6 @@
4
4
  */
5
5
  export * from "./propertyTree";
6
6
  export * from "./propertyTreeFactory";
7
+ export * from "./propertyTreeExt";
8
+ export * from "./propertyTreeExtFactories";
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC"}
package/lib/index.js CHANGED
@@ -4,4 +4,6 @@
4
4
  */
5
5
  export * from "./propertyTree";
6
6
  export * from "./propertyTreeFactory";
7
+ export * from "./propertyTreeExt";
8
+ export * from "./propertyTreeExtFactories";
7
9
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./propertyTree\";\nexport * from \"./propertyTreeFactory\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./propertyTree\";\nexport * from \"./propertyTreeFactory\";\nexport * from \"./propertyTreeExt\";\nexport * from \"./propertyTreeExtFactories\";\n"]}
@@ -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
+ /// <reference types="node" />
5
6
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
6
7
  import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService, IChannelFactory } from "@fluidframework/datastore-definitions";
7
8
  import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
@@ -26,11 +27,29 @@ export interface IPropertyTreeMessage {
26
27
  export interface IRemotePropertyTreeMessage extends IPropertyTreeMessage {
27
28
  sequenceNumber: number;
28
29
  }
30
+ export interface ISnapshotSummary {
31
+ remoteTipView?: SerializedChangeSet;
32
+ remoteChanges?: IPropertyTreeMessage[];
33
+ unrebasedRemoteChanges?: Record<string, IRemotePropertyTreeMessage>;
34
+ }
29
35
  export interface SharedPropertyTreeOptions {
30
36
  paths?: string[];
31
37
  clientFiltering?: boolean;
32
38
  useMH?: boolean;
33
39
  }
40
+ export interface ISharedPropertyTreeEncDec {
41
+ messageEncoder: {
42
+ encode: (IPropertyTreeMessage: any) => IPropertyTreeMessage;
43
+ decode: (IPropertyTreeMessage: any) => IPropertyTreeMessage;
44
+ };
45
+ summaryEncoder: {
46
+ encode: (ISnapshotSummary: any) => Buffer;
47
+ decode: (Buffer: any) => ISnapshotSummary;
48
+ };
49
+ }
50
+ export interface IPropertyTreeConfig {
51
+ encDec: ISharedPropertyTreeEncDec;
52
+ }
34
53
  /**
35
54
  * Silly DDS example that models a six sided die.
36
55
  *
@@ -57,7 +76,8 @@ export declare class SharedPropertyTree extends SharedObject {
57
76
  skipSequenceNumber: number;
58
77
  headCommitGuid: string;
59
78
  useMH: boolean;
60
- constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, options: SharedPropertyTreeOptions);
79
+ propertyTreeConfig: IPropertyTreeConfig;
80
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, options: SharedPropertyTreeOptions, propertyTreeConfig?: IPropertyTreeConfig);
61
81
  /**
62
82
  * Create a new shared cell
63
83
  *
@@ -82,6 +102,16 @@ export declare class SharedPropertyTree extends SharedObject {
82
102
  get activeCommit(): IPropertyTreeMessage;
83
103
  get root(): NodeProperty;
84
104
  commit(metadata?: Metadata, submitEmptyChange?: boolean): void;
105
+ /**
106
+ * This method encodes the given message to the transfer form
107
+ * @param change - The message to be encoded.
108
+ */
109
+ private encodeMessage;
110
+ /**
111
+ * This method decodes message from the transfer form.
112
+ * @param transferChange - The message to be decoded.
113
+ */
114
+ private decodeMessage;
85
115
  private applyChangeSet;
86
116
  stopTransmission(stop: boolean): void;
87
117
  /**
@@ -109,6 +139,38 @@ export declare class SharedPropertyTree extends SharedObject {
109
139
  prunedCount: number;
110
140
  };
111
141
  pruneHistory(): void;
142
+ /**
143
+ * This method encodes the local summary (snapshot) object into the serialized form.
144
+ * @param summary - The local summary (snapshot)representation.
145
+ * @returns The serialized summary representation.
146
+ */
147
+ private encodeSummary;
148
+ /**
149
+ * This method decodes the serialized form of the summary into the local summary (snapshot) object.
150
+ * @param serializedSummary - The serialized summary representation.
151
+ * @returns The local summary (snapshot)representation.
152
+ */
153
+ private decodeSummary;
154
+ /**
155
+ * This method writes the log message if the logging is enabled in the extended DDS.
156
+ * The logging is not enabled in the default Property DDS
157
+ * @param message - The message to be logged.
158
+ */
159
+ protected logIfEnabled(message: any): void;
160
+ /**
161
+ * This method encodes the binary representation of the
162
+ * blob.
163
+ * @param blob - The binary representation of the blob.
164
+ * @returns The encoded representation of the blob.
165
+ */
166
+ private encodeSummaryBlob;
167
+ /**
168
+ * This method decodes the encoded representation of the
169
+ * blob.
170
+ * @param blob - The encoded representation of the blob.
171
+ * @returns The binary representation of the blob.
172
+ */
173
+ private decodeSummaryBlob;
112
174
  summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
113
175
  protected loadCore(storage: IChannelStorageService): Promise<void>;
114
176
  protected onDisconnect(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"propertyTree.d.ts","sourceRoot":"","sources":["../src/propertyTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AASpF,OAAO,EAAiC,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAMtG,oBAAY,mBAAmB,GAAG,GAAG,CAAC;AAEtC,oBAAY,QAAQ,GAAG,GAAG,CAAC;AAK3B,0BAAkB,M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AC,qBAAqB;IAsC7B,kBAAkB,CAAC,IAAI,EAAE,MAAM;IAI/B,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IASrD,OAAO,CAAC,kBAAkB;IAwE1B,SAAS,CAAC,cAAc;CAGxB"}
@@ -18,6 +18,22 @@ import { PropertyFactory, BaseProperty } from "@fluid-experimental/property-prop
18
18
  import { v4 as uuidv4 } from "uuid";
19
19
  import axios from "axios";
20
20
  import { PropertyTreeFactory } from "./propertyTreeFactory";
21
+ const defaultEncDec = {
22
+ messageEncoder: { encode: (msg) => msg,
23
+ decode: (msg) => msg },
24
+ summaryEncoder: {
25
+ encode: (summary) => {
26
+ const packr = new Packr();
27
+ const serializedSummary = packr.pack(summary);
28
+ return serializedSummary;
29
+ },
30
+ decode: (serializedSummary) => {
31
+ const packr = new Packr();
32
+ const snapshotSummary = packr.unpack(serializedSummary);
33
+ return snapshotSummary;
34
+ },
35
+ },
36
+ };
21
37
  /**
22
38
  * Silly DDS example that models a six sided die.
23
39
  *
@@ -31,7 +47,7 @@ import { PropertyTreeFactory } from "./propertyTreeFactory";
31
47
  * in the total order)
32
48
  */
33
49
  export class SharedPropertyTree extends SharedObject {
34
- constructor(id, runtime, attributes, options) {
50
+ constructor(id, runtime, attributes, options, propertyTreeConfig = { encDec: defaultEncDec }) {
35
51
  var _a;
36
52
  super(id, runtime, attributes, "fluid_propertyTree_");
37
53
  this.tipView = {};
@@ -51,6 +67,7 @@ export class SharedPropertyTree extends SharedObject {
51
67
  this._root._tree = this;
52
68
  // By default, we currently don't use the MH
53
69
  this.useMH = (_a = options.useMH) !== null && _a !== void 0 ? _a : false;
70
+ this.propertyTreeConfig = propertyTreeConfig;
54
71
  }
55
72
  /**
56
73
  * Create a new shared cell
@@ -121,6 +138,20 @@ export class SharedPropertyTree extends SharedObject {
121
138
  this.root.cleanDirty();
122
139
  }
123
140
  }
141
+ /**
142
+ * This method encodes the given message to the transfer form
143
+ * @param change - The message to be encoded.
144
+ */
145
+ encodeMessage(change) {
146
+ return this.propertyTreeConfig.encDec.messageEncoder.encode(change);
147
+ }
148
+ /**
149
+ * This method decodes message from the transfer form.
150
+ * @param transferChange - The message to be decoded.
151
+ */
152
+ decodeMessage(transferChange) {
153
+ return this.propertyTreeConfig.encDec.messageEncoder.decode(transferChange);
154
+ }
124
155
  applyChangeSet(changeSet, metadata) {
125
156
  const _changeSet = new ChangeSet(changeSet);
126
157
  _changeSet._toReversibleChangeSet(this.tipView);
@@ -139,11 +170,12 @@ export class SharedPropertyTree extends SharedObject {
139
170
  };
140
171
  this._applyLocalChangeSet(change);
141
172
  // Queue the op for transmission to the Fluid service.
173
+ const transferChange = this.encodeMessage(cloneDeep(change));
142
174
  if (this.transmissionsHaveBeenStopped) {
143
- this.enqueuedMessages.push(cloneDeep(change));
175
+ this.enqueuedMessages.push(transferChange);
144
176
  }
145
177
  else {
146
- this.submitLocalMessage(cloneDeep(change));
178
+ this.submitLocalMessage(transferChange);
147
179
  }
148
180
  }
149
181
  stopTransmission(stop) {
@@ -188,7 +220,8 @@ export class SharedPropertyTree extends SharedObject {
188
220
  */
189
221
  processCore(message, local, localOpMetadata) {
190
222
  if (message.type === MessageType.Operation && message.sequenceNumber > this.skipSequenceNumber) {
191
- const content = Object.assign(Object.assign({}, message.contents), { sequenceNumber: message.sequenceNumber });
223
+ const change = this.decodeMessage(cloneDeep(message.contents));
224
+ const content = Object.assign(Object.assign({}, change), { sequenceNumber: message.sequenceNumber });
192
225
  switch (content.op) {
193
226
  case 0 /* ChangeSet */:
194
227
  // If the op originated locally from this client, we've already accounted for it
@@ -272,6 +305,47 @@ export class SharedPropertyTree extends SharedObject {
272
305
  this.remoteChanges = remoteChanges;
273
306
  this.unrebasedRemoteChanges = unrebasedRemoteChanges;
274
307
  }
308
+ /**
309
+ * This method encodes the local summary (snapshot) object into the serialized form.
310
+ * @param summary - The local summary (snapshot)representation.
311
+ * @returns The serialized summary representation.
312
+ */
313
+ encodeSummary(summary) {
314
+ return this.propertyTreeConfig.encDec.summaryEncoder.encode(summary);
315
+ }
316
+ /**
317
+ * This method decodes the serialized form of the summary into the local summary (snapshot) object.
318
+ * @param serializedSummary - The serialized summary representation.
319
+ * @returns The local summary (snapshot)representation.
320
+ */
321
+ decodeSummary(serializedSummary) {
322
+ return this.propertyTreeConfig.encDec.summaryEncoder.decode(serializedSummary);
323
+ }
324
+ /**
325
+ * This method writes the log message if the logging is enabled in the extended DDS.
326
+ * The logging is not enabled in the default Property DDS
327
+ * @param message - The message to be logged.
328
+ */
329
+ logIfEnabled(message) { }
330
+ /**
331
+ * This method encodes the binary representation of the
332
+ * blob.
333
+ * @param blob - The binary representation of the blob.
334
+ * @returns The encoded representation of the blob.
335
+ */
336
+ encodeSummaryBlob(blob) {
337
+ return bufferToString(blob, "base64");
338
+ }
339
+ /**
340
+ * This method decodes the encoded representation of the
341
+ * blob.
342
+ * @param blob - The encoded representation of the blob.
343
+ * @returns The binary representation of the blob.
344
+ */
345
+ decodeSummaryBlob(encoded) {
346
+ const buffer = bufferToString(encoded, "utf8");
347
+ return stringToBuffer(buffer, "base64");
348
+ }
275
349
  summarizeCore(serializer) {
276
350
  this.pruneHistory();
277
351
  const snapshot = {
@@ -290,12 +364,16 @@ export class SharedPropertyTree extends SharedObject {
290
364
  unrebasedRemoteChanges: this.unrebasedRemoteChanges,
291
365
  };
292
366
  const chunkSize = 5000 * 1024; // Default limit seems to be 5MB
293
- const packr = new Packr();
294
- const serializedSummary = packr.pack(summary);
367
+ let totalBlobsSize = 0;
368
+ const serializedSummary = this.encodeSummary(summary);
295
369
  for (let pos = 0, i = 0; pos < serializedSummary.length; pos += chunkSize, i++) {
296
- builder.addBlob(`summaryChunk_${i}`, bufferToString(serializedSummary.slice(pos, pos + chunkSize), "base64"));
370
+ const summaryBlob = this.encodeSummaryBlob(serializedSummary.slice(pos, pos + chunkSize));
371
+ // eslint-disable-next-line @typescript-eslint/dot-notation
372
+ totalBlobsSize += summaryBlob["length"];
373
+ builder.addBlob(`summaryChunk_${i}`, summaryBlob);
297
374
  snapshot.numChunks++;
298
375
  }
376
+ this.logIfEnabled(`Total blobs transfer size: ${totalBlobsSize}`);
299
377
  }
300
378
  builder.addBlob("properties", serializer !== undefined
301
379
  ? serializer.stringify(snapshot, this.handle)
@@ -312,8 +390,7 @@ export class SharedPropertyTree extends SharedObject {
312
390
  if (!snapshot.useMH) {
313
391
  // We load all chunks
314
392
  const chunks = await Promise.all(range(snapshot.numChunks).map(async (i) => {
315
- const buffer = bufferToString(await storage.readBlob(`summaryChunk_${i}`), "utf8");
316
- return stringToBuffer(buffer, "base64");
393
+ return this.decodeSummaryBlob(await storage.readBlob(`summaryChunk_${i}`));
317
394
  }));
318
395
  const totalLength = chunks.reduce((a, b) => a + b.byteLength, 0);
319
396
  const serializedSummary = new Uint8Array(totalLength);
@@ -321,8 +398,7 @@ export class SharedPropertyTree extends SharedObject {
321
398
  serializedSummary.set(new Uint8Array(chunk), offset);
322
399
  return offset + chunk.byteLength;
323
400
  }, 0);
324
- const packr = new Packr();
325
- const snapshotSummary = packr.unpack(serializedSummary);
401
+ const snapshotSummary = this.decodeSummary(serializedSummary);
326
402
  if (snapshotSummary.remoteChanges === undefined ||
327
403
  snapshotSummary.remoteTipView === undefined ||
328
404
  snapshotSummary.unrebasedRemoteChanges === undefined) {