@fluidframework/debugger 2.0.0-internal.3.0.1 → 2.0.0-internal.3.1.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.
- package/.eslintrc.js +9 -12
- package/README.md +33 -33
- package/api-extractor.json +2 -2
- package/dist/fluidDebugger.d.ts.map +1 -1
- package/dist/fluidDebugger.js.map +1 -1
- package/dist/fluidDebuggerController.d.ts.map +1 -1
- package/dist/fluidDebuggerController.js +5 -2
- package/dist/fluidDebuggerController.js.map +1 -1
- package/dist/fluidDebuggerUi.d.ts.map +1 -1
- package/dist/fluidDebuggerUi.js +11 -5
- package/dist/fluidDebuggerUi.js.map +1 -1
- package/dist/messageSchema.js.map +1 -1
- package/dist/sanitize.js.map +1 -1
- package/dist/sanitizer.d.ts.map +1 -1
- package/dist/sanitizer.js +9 -5
- package/dist/sanitizer.js.map +1 -1
- package/lib/fluidDebugger.d.ts.map +1 -1
- package/lib/fluidDebugger.js.map +1 -1
- package/lib/fluidDebuggerController.d.ts.map +1 -1
- package/lib/fluidDebuggerController.js +5 -2
- package/lib/fluidDebuggerController.js.map +1 -1
- package/lib/fluidDebuggerUi.d.ts.map +1 -1
- package/lib/fluidDebuggerUi.js +11 -5
- package/lib/fluidDebuggerUi.js.map +1 -1
- package/lib/messageSchema.js.map +1 -1
- package/lib/sanitize.js.map +1 -1
- package/lib/sanitizer.d.ts.map +1 -1
- package/lib/sanitizer.js +9 -5
- package/lib/sanitizer.js.map +1 -1
- package/package.json +68 -67
- package/prettier.config.cjs +1 -1
- package/src/fluidDebugger.ts +30 -30
- package/src/fluidDebuggerController.ts +348 -322
- package/src/fluidDebuggerUi.ts +306 -281
- package/src/messageSchema.ts +367 -367
- package/src/sanitize.ts +29 -29
- package/src/sanitizer.ts +699 -638
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +10 -15
package/src/sanitizer.ts
CHANGED
|
@@ -20,35 +20,35 @@
|
|
|
20
20
|
|
|
21
21
|
import * as Validator from "jsonschema";
|
|
22
22
|
import { assert } from "@fluidframework/common-utils";
|
|
23
|
+
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
23
24
|
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
opContentsMergeTreeGroupOpSchema,
|
|
35
|
-
opContentsRegisterCollectionSchema,
|
|
36
|
-
proposeContentsSchema,
|
|
25
|
+
attachContentsSchema,
|
|
26
|
+
chunkedOpContentsSchema,
|
|
27
|
+
joinContentsSchema,
|
|
28
|
+
joinDataSchema,
|
|
29
|
+
opContentsMapSchema,
|
|
30
|
+
opContentsSchema,
|
|
31
|
+
opContentsMergeTreeDeltaOpSchema,
|
|
32
|
+
opContentsMergeTreeGroupOpSchema,
|
|
33
|
+
opContentsRegisterCollectionSchema,
|
|
34
|
+
proposeContentsSchema,
|
|
37
35
|
} from "./messageSchema";
|
|
38
36
|
|
|
39
37
|
enum TextType {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
Generic,
|
|
39
|
+
Email,
|
|
40
|
+
Name,
|
|
41
|
+
FluidObject,
|
|
42
|
+
MapKey,
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
// Workaround to jsonschema package not supporting "false" as a schema
|
|
48
46
|
// that matches nothing
|
|
49
47
|
const falseResult = {
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
valid: false,
|
|
49
|
+
toString: () => {
|
|
50
|
+
return "Unmatched format";
|
|
51
|
+
},
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -58,625 +58,686 @@ const falseResult = {
|
|
|
58
58
|
* size to the original message.
|
|
59
59
|
*/
|
|
60
60
|
class ChunkedOpProcessor {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Message references so we can replace their contents in-place. These can
|
|
63
|
+
* be top-level chunkedOp messages, or top-level op messages with a chunkedOp
|
|
64
|
+
* within the contents
|
|
65
|
+
*/
|
|
66
|
+
private messages = new Array<any>();
|
|
67
|
+
/**
|
|
68
|
+
* The messages' parsed contents for processing. Should parallel the
|
|
69
|
+
* messages member
|
|
70
|
+
*/
|
|
71
|
+
private parsedMessageContents = new Array<any>();
|
|
72
|
+
private writtenBack = false;
|
|
73
|
+
/**
|
|
74
|
+
* keep track of the total starting length to make sure we don't somehow end
|
|
75
|
+
* up with more content than we started with (meaning we may not be able to
|
|
76
|
+
* write it back)
|
|
77
|
+
*/
|
|
78
|
+
private concatenatedLength = 0;
|
|
79
|
+
|
|
80
|
+
constructor(
|
|
81
|
+
readonly validateSchemaFn: (object: any, schema: any) => boolean,
|
|
82
|
+
readonly debug: boolean,
|
|
83
|
+
) {}
|
|
84
|
+
|
|
85
|
+
debugMsg(msg: any) {
|
|
86
|
+
if (this.debug) {
|
|
87
|
+
console.error(msg);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
addMessage(message: any): void {
|
|
92
|
+
this.messages.push(message);
|
|
93
|
+
|
|
94
|
+
let parsed;
|
|
95
|
+
try {
|
|
96
|
+
parsed = JSON.parse(message.contents);
|
|
97
|
+
if (message.type === "op") {
|
|
98
|
+
// nested within a regular op
|
|
99
|
+
// need to go deeper to get the desired contents
|
|
100
|
+
parsed = parsed.contents;
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {
|
|
103
|
+
this.debugMsg(e);
|
|
104
|
+
this.debugMsg(message.contents);
|
|
105
|
+
}
|
|
106
|
+
this.validateSchemaFn(parsed, chunkedOpContentsSchema);
|
|
107
|
+
this.parsedMessageContents.push(parsed);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
hasAllMessages(): boolean {
|
|
111
|
+
const lastMsgContents = this.parsedMessageContents[this.parsedMessageContents.length - 1];
|
|
112
|
+
return (
|
|
113
|
+
lastMsgContents.chunkId !== undefined &&
|
|
114
|
+
lastMsgContents.chunkId === lastMsgContents.totalChunks
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @returns The concatenated contents of all the messages parsed as json
|
|
120
|
+
*/
|
|
121
|
+
getConcatenatedContents(): any {
|
|
122
|
+
const contentsString = this.parsedMessageContents.reduce(
|
|
123
|
+
(previousValue: string, currentValue: any) => {
|
|
124
|
+
return previousValue + (currentValue.contents as string);
|
|
125
|
+
},
|
|
126
|
+
"",
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
this.concatenatedLength = contentsString.length;
|
|
130
|
+
try {
|
|
131
|
+
return JSON.parse(contentsString);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
this.debugMsg(contentsString);
|
|
134
|
+
this.debugMsg(e);
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Write back sanitized contents into the messages. The contents are
|
|
141
|
+
* stringified, split up, and written in place to the messages that
|
|
142
|
+
* were added earlier. The number of messages is preserved.
|
|
143
|
+
* @param contents - Sanitized contents to write back
|
|
144
|
+
*/
|
|
145
|
+
writeSanitizedContents(contents: any): void {
|
|
146
|
+
// Write back a chunk size equal to the original
|
|
147
|
+
const chunkSize = this.parsedMessageContents[0].contents.length;
|
|
148
|
+
|
|
149
|
+
let stringified: string;
|
|
150
|
+
try {
|
|
151
|
+
stringified = JSON.stringify(contents);
|
|
152
|
+
assert(
|
|
153
|
+
stringified.length <= this.concatenatedLength,
|
|
154
|
+
0x089 /* "Stringified length of chunk contents > total starting length" */,
|
|
155
|
+
);
|
|
156
|
+
} catch (e) {
|
|
157
|
+
this.debugMsg(e);
|
|
158
|
+
throw e;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
for (let i = 0; i < this.messages.length; i++) {
|
|
162
|
+
const substring = stringified.substring(i * chunkSize, (i + 1) * chunkSize);
|
|
163
|
+
|
|
164
|
+
const parsedContents = this.parsedMessageContents[i];
|
|
165
|
+
parsedContents.contents = substring;
|
|
166
|
+
const message = this.messages[i];
|
|
167
|
+
|
|
168
|
+
let stringifiedParsedContents;
|
|
169
|
+
try {
|
|
170
|
+
// for nested chunkedOps, we need to recreate the extra nesting layer
|
|
171
|
+
// we removed earlier when adding the message
|
|
172
|
+
if (message.type === "op") {
|
|
173
|
+
const nestingLayer = {
|
|
174
|
+
type: "chunkedOp",
|
|
175
|
+
contents: parsedContents,
|
|
176
|
+
};
|
|
177
|
+
stringifiedParsedContents = JSON.stringify(nestingLayer);
|
|
178
|
+
} else {
|
|
179
|
+
stringifiedParsedContents = JSON.stringify(parsedContents);
|
|
180
|
+
}
|
|
181
|
+
} catch (e) {
|
|
182
|
+
this.debugMsg(e);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
message.contents = stringifiedParsedContents;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.writtenBack = true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
reset(): void {
|
|
192
|
+
assert(
|
|
193
|
+
this.writtenBack,
|
|
194
|
+
0x08a /* "resetting ChunkedOpProcessor that never wrote back its contents" */,
|
|
195
|
+
);
|
|
196
|
+
this.messages = new Array<any>();
|
|
197
|
+
this.parsedMessageContents = new Array<any>();
|
|
198
|
+
this.writtenBack = false;
|
|
199
|
+
this.concatenatedLength = 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
isPendingProcessing(): boolean {
|
|
203
|
+
return this.messages.length !== 0;
|
|
204
|
+
}
|
|
194
205
|
}
|
|
195
206
|
|
|
196
207
|
export class Sanitizer {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
208
|
+
readonly validator = new Validator.Validator();
|
|
209
|
+
// Represents the keys used to store Fluid object identifiers, snapshot info,
|
|
210
|
+
// and other string fields that should not be replaced in contents blobs to
|
|
211
|
+
// ensure the messages are still usable
|
|
212
|
+
readonly defaultExcludedKeys = new Set<string>();
|
|
213
|
+
// Represents the keys used by merge-tree ops their "seg" property, where other
|
|
214
|
+
// keys represent user information
|
|
215
|
+
readonly mergeTreeExcludedKeys = new Set<string>();
|
|
216
|
+
// Map of user information to what it was replaced with. Used to ensure the same
|
|
217
|
+
// data have the same replacements
|
|
218
|
+
readonly replacementMap = new Map<string, string>();
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Validate that the provided message matches the provided schema.
|
|
222
|
+
* For a full scrub, warn and continue (scrubber should fully sanitize unexpected
|
|
223
|
+
* fields for ops), otherwise throw an error because we cannot be sure user
|
|
224
|
+
* information is being sufficiently sanitized.
|
|
225
|
+
*/
|
|
226
|
+
objectMatchesSchema = (object: any, schema: any): boolean => {
|
|
227
|
+
const result = schema === false ? falseResult : this.validator.validate(object, schema);
|
|
228
|
+
if (!result.valid) {
|
|
229
|
+
const errorMsg = `Bad msg fmt:\n${result.toString()}\n${JSON.stringify(
|
|
230
|
+
object,
|
|
231
|
+
undefined,
|
|
232
|
+
2,
|
|
233
|
+
)}`;
|
|
234
|
+
|
|
235
|
+
if (this.fullScrub || this.noBail) {
|
|
236
|
+
this.debugMsg(errorMsg);
|
|
237
|
+
} else {
|
|
238
|
+
throw new Error(errorMsg);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return result.valid;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
readonly chunkProcessor = new ChunkedOpProcessor(this.objectMatchesSchema, this.debug);
|
|
245
|
+
|
|
246
|
+
constructor(
|
|
247
|
+
readonly messages: ISequencedDocumentMessage[],
|
|
248
|
+
readonly fullScrub: boolean,
|
|
249
|
+
readonly noBail: boolean,
|
|
250
|
+
readonly debug: boolean = false,
|
|
251
|
+
) {
|
|
252
|
+
this.defaultExcludedKeys.add("type");
|
|
253
|
+
this.defaultExcludedKeys.add("id");
|
|
254
|
+
this.defaultExcludedKeys.add("pkg");
|
|
255
|
+
this.defaultExcludedKeys.add("snapshotFormatVersion");
|
|
256
|
+
this.defaultExcludedKeys.add("packageVersion");
|
|
257
|
+
this.mergeTreeExcludedKeys.add("nodeType");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
debugMsg(msg: any) {
|
|
261
|
+
if (this.debug) {
|
|
262
|
+
console.error(msg);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
isFluidObjectKey(key: string): boolean {
|
|
267
|
+
return key === "type" || key === "id";
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
getRandomText(len: number): string {
|
|
271
|
+
let str = "";
|
|
272
|
+
while (str.length < len) {
|
|
273
|
+
str = str + Math.random().toString(36).substring(2);
|
|
274
|
+
}
|
|
275
|
+
return str.substr(0, len);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
readonly wordTokenRegex = /\S+/g;
|
|
279
|
+
|
|
280
|
+
readonly replaceRandomTextFn = (match: string): string => {
|
|
281
|
+
if (this.replacementMap.has(match)) {
|
|
282
|
+
return this.replacementMap.get(match)!;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const replacement = this.getRandomText(match.length);
|
|
286
|
+
this.replacementMap.set(match, replacement);
|
|
287
|
+
return replacement;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Replace text with garbage. FluidObject types are not replaced when not under
|
|
292
|
+
* full scrub mode. All other text is replaced consistently.
|
|
293
|
+
*/
|
|
294
|
+
replaceText(input?: string, type: TextType = TextType.Generic): string | undefined {
|
|
295
|
+
if (input === undefined) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (type === TextType.FluidObject) {
|
|
300
|
+
if (this.replacementMap.has(input)) {
|
|
301
|
+
return this.replacementMap.get(input)!;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const replacement = this.fullScrub ? this.getRandomText(input.length) : input;
|
|
305
|
+
|
|
306
|
+
this.replacementMap.set(input, replacement);
|
|
307
|
+
return replacement;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return input.replace(this.wordTokenRegex, this.replaceRandomTextFn);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
replaceArray(input: any[]): any[] {
|
|
314
|
+
for (let i = 0; i < input.length; i++) {
|
|
315
|
+
const value = input[i];
|
|
316
|
+
if (typeof value === "string") {
|
|
317
|
+
input[i] = this.replaceText(value);
|
|
318
|
+
} else if (Array.isArray(value)) {
|
|
319
|
+
input[i] = this.replaceArray(value);
|
|
320
|
+
} else if (typeof value === "object") {
|
|
321
|
+
input[i] = this.replaceObject(value);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return input;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* (sort of) recurses down the values of a JSON object to sanitize all its strings
|
|
329
|
+
* (only checks strings, arrays, and objects)
|
|
330
|
+
* @param input - The object to sanitize
|
|
331
|
+
* @param excludedKeys - object keys for which to skip replacement when not in fullScrub
|
|
332
|
+
*/
|
|
333
|
+
replaceObject(
|
|
334
|
+
input: object | null,
|
|
335
|
+
excludedKeys: Set<string> = this.defaultExcludedKeys,
|
|
336
|
+
): object | null {
|
|
337
|
+
// File might contain actual nulls
|
|
338
|
+
if (input === null || input === undefined) {
|
|
339
|
+
return input;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const keys = Object.keys(input);
|
|
343
|
+
keys.forEach((key) => {
|
|
344
|
+
if (this.fullScrub || !excludedKeys.has(key)) {
|
|
345
|
+
const value = input[key];
|
|
346
|
+
if (typeof value === "string") {
|
|
347
|
+
input[key] = this.replaceText(
|
|
348
|
+
value,
|
|
349
|
+
this.isFluidObjectKey(key) ? TextType.FluidObject : TextType.Generic,
|
|
350
|
+
);
|
|
351
|
+
} else if (Array.isArray(value)) {
|
|
352
|
+
input[key] = this.replaceArray(value);
|
|
353
|
+
} else if (typeof value === "object") {
|
|
354
|
+
input[key] = this.replaceObject(value, excludedKeys);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
return input;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Replacement on an unknown type or a parsed root level object
|
|
363
|
+
* without a key
|
|
364
|
+
* @param input - The object to sanitize
|
|
365
|
+
* @param excludedKeys - object keys for which to skip replacement when not in fullScrub
|
|
366
|
+
*/
|
|
367
|
+
replaceAny(input: any, excludedKeys: Set<string> = this.defaultExcludedKeys): any {
|
|
368
|
+
if (input === null || input === undefined) {
|
|
369
|
+
return input;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (typeof input === "string") {
|
|
373
|
+
return this.replaceText(input);
|
|
374
|
+
} else if (Array.isArray(input)) {
|
|
375
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
376
|
+
return this.replaceArray(input);
|
|
377
|
+
} else if (typeof input === "object") {
|
|
378
|
+
return this.replaceObject(input, excludedKeys);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Don't run replacement on any other types
|
|
382
|
+
return input;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
fixJoin(message: any) {
|
|
386
|
+
if (!this.objectMatchesSchema(message.contents, joinContentsSchema)) {
|
|
387
|
+
message.contents = this.replaceAny(message.contents);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
try {
|
|
391
|
+
let data = JSON.parse(message.data);
|
|
392
|
+
if (!this.objectMatchesSchema(data, joinDataSchema)) {
|
|
393
|
+
data = this.replaceAny(data);
|
|
394
|
+
} else {
|
|
395
|
+
const user = data.detail.user;
|
|
396
|
+
user.id = this.replaceText(user.id, TextType.Email);
|
|
397
|
+
user.email = this.replaceText(user.email, TextType.Email);
|
|
398
|
+
user.name = this.replaceText(user.name, TextType.Name);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
message.data = JSON.stringify(data);
|
|
402
|
+
} catch (e) {
|
|
403
|
+
this.debugMsg(e);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
fixPropose(message: any) {
|
|
408
|
+
if (!this.objectMatchesSchema(message.contents, proposeContentsSchema)) {
|
|
409
|
+
message.contents = this.replaceAny(message.contents);
|
|
410
|
+
} else {
|
|
411
|
+
if (typeof message.contents === "string") {
|
|
412
|
+
try {
|
|
413
|
+
const data = JSON.parse(message.contents);
|
|
414
|
+
if (this.fullScrub) {
|
|
415
|
+
const pkg = data.value?.package;
|
|
416
|
+
if (pkg?.name) {
|
|
417
|
+
pkg.name = this.replaceText(pkg.name, TextType.FluidObject);
|
|
418
|
+
}
|
|
419
|
+
if (Array.isArray(pkg?.fluid?.browser?.umd?.files)) {
|
|
420
|
+
pkg.fluid.browser.umd.files = this.replaceArray(
|
|
421
|
+
pkg.fluid.browser.umd.files,
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
} catch (e) {
|
|
426
|
+
this.debugMsg(e);
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
if (this.fullScrub) {
|
|
430
|
+
message.contents.value = this.replaceText(
|
|
431
|
+
message.contents.value,
|
|
432
|
+
TextType.FluidObject,
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
fixAttachEntries(entries: any[]) {
|
|
440
|
+
entries.forEach((element) => {
|
|
441
|
+
// Tree type
|
|
442
|
+
if (element.value.entries) {
|
|
443
|
+
this.fixAttachEntries(element.value.entries);
|
|
444
|
+
} else {
|
|
445
|
+
// Blob (leaf) type
|
|
446
|
+
try {
|
|
447
|
+
if (typeof element.value.contents === "string") {
|
|
448
|
+
let data = JSON.parse(element.value.contents);
|
|
449
|
+
data = this.replaceObject(data);
|
|
450
|
+
element.value.contents = JSON.stringify(data);
|
|
451
|
+
}
|
|
452
|
+
} catch (e) {
|
|
453
|
+
this.debugMsg(e);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Fix the content of an attach in place
|
|
461
|
+
* @param contents - contents object to fix
|
|
462
|
+
*/
|
|
463
|
+
fixAttachContents(contents: any): any {
|
|
464
|
+
assert(
|
|
465
|
+
typeof contents === "object",
|
|
466
|
+
0x08b /* "Unexpected type on contents for fix of an attach!" */,
|
|
467
|
+
);
|
|
468
|
+
if (!this.objectMatchesSchema(contents, attachContentsSchema)) {
|
|
469
|
+
this.replaceObject(contents);
|
|
470
|
+
} else {
|
|
471
|
+
if (this.fullScrub) {
|
|
472
|
+
contents.id = this.replaceText(contents.id, TextType.FluidObject);
|
|
473
|
+
contents.type = this.replaceText(contents.type, TextType.FluidObject);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
this.fixAttachEntries(contents.snapshot.entries);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Fix an attach message at the root level or a ContainerMessageType attach. Attach
|
|
482
|
+
* messages found within an op message should instead have their contents parsed out
|
|
483
|
+
* and sent to fixAttachContents.
|
|
484
|
+
* @param message - The attach message to fix
|
|
485
|
+
* @param withinOp - If the message is from within an op message (as opposed to being
|
|
486
|
+
* an attach message at the root level). Root level attach messages have "snapshot"
|
|
487
|
+
* under a "contents" key, whereas attach messages from within an op message have it
|
|
488
|
+
* under a "content" key
|
|
489
|
+
*/
|
|
490
|
+
fixAttach(message: any) {
|
|
491
|
+
// Handle case where contents is stringified json
|
|
492
|
+
if (typeof message.contents === "string") {
|
|
493
|
+
try {
|
|
494
|
+
const data = JSON.parse(message.contents);
|
|
495
|
+
this.fixAttachContents(data);
|
|
496
|
+
message.contents = JSON.stringify(data);
|
|
497
|
+
} catch (e) {
|
|
498
|
+
this.debugMsg(e);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
} else {
|
|
502
|
+
this.fixAttachContents(message.contents);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
fixDeltaOp(deltaOp: any) {
|
|
507
|
+
deltaOp.seg =
|
|
508
|
+
typeof deltaOp.seg === "string"
|
|
509
|
+
? this.replaceText(deltaOp.seg)
|
|
510
|
+
: this.replaceObject(deltaOp.seg, this.mergeTreeExcludedKeys);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Fix the contents object for an op message. Does not do extra type handling. Does
|
|
515
|
+
* not handle special container message types like "attach", "component", and
|
|
516
|
+
* "chunkedOp" (these should be handled by the caller)
|
|
517
|
+
* @param contents - The contents object for an op message. If it was a string in the
|
|
518
|
+
* message, it must have been converted to an object first
|
|
519
|
+
*/
|
|
520
|
+
fixOpContentsObject(contents: any) {
|
|
521
|
+
// do replacement
|
|
522
|
+
if (!this.objectMatchesSchema(contents, opContentsSchema)) {
|
|
523
|
+
this.replaceAny(contents);
|
|
524
|
+
} else {
|
|
525
|
+
if (this.fullScrub) {
|
|
526
|
+
contents.address = this.replaceText(contents.address, TextType.FluidObject);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const innerContent = contents.contents.content;
|
|
530
|
+
assert(
|
|
531
|
+
innerContent !== undefined,
|
|
532
|
+
0x08c /* "innerContent for fixing op contents is undefined!" */,
|
|
533
|
+
);
|
|
534
|
+
if (contents.contents.type === "attach") {
|
|
535
|
+
// attach op
|
|
536
|
+
// handle case where inner content is stringified json
|
|
537
|
+
if (typeof contents.contents.content === "string") {
|
|
538
|
+
try {
|
|
539
|
+
const data = JSON.parse(contents.contents.content);
|
|
540
|
+
this.fixAttachContents(data);
|
|
541
|
+
contents.contents.content = JSON.stringify(data);
|
|
542
|
+
} catch (e) {
|
|
543
|
+
this.debugMsg(e);
|
|
544
|
+
}
|
|
545
|
+
} else {
|
|
546
|
+
this.fixAttachContents(contents.contents.content);
|
|
547
|
+
}
|
|
548
|
+
} else if (this.validator.validate(innerContent, opContentsMapSchema).valid) {
|
|
549
|
+
// map op
|
|
550
|
+
if (this.fullScrub) {
|
|
551
|
+
innerContent.address = this.replaceText(
|
|
552
|
+
innerContent.address,
|
|
553
|
+
TextType.FluidObject,
|
|
554
|
+
);
|
|
555
|
+
innerContent.contents.key = this.replaceText(
|
|
556
|
+
innerContent.contents.key,
|
|
557
|
+
TextType.MapKey,
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
if (innerContent.contents.value !== undefined) {
|
|
561
|
+
innerContent.contents.value.value = this.replaceAny(
|
|
562
|
+
innerContent.contents.value.value,
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
} else if (
|
|
566
|
+
this.validator.validate(innerContent, opContentsMergeTreeGroupOpSchema).valid
|
|
567
|
+
) {
|
|
568
|
+
// merge tree group op
|
|
569
|
+
if (this.fullScrub) {
|
|
570
|
+
innerContent.address = this.replaceText(
|
|
571
|
+
innerContent.address,
|
|
572
|
+
TextType.FluidObject,
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
innerContent.contents.ops.forEach((deltaOp) => {
|
|
576
|
+
this.fixDeltaOp(deltaOp);
|
|
577
|
+
});
|
|
578
|
+
} else if (
|
|
579
|
+
this.validator.validate(innerContent, opContentsMergeTreeDeltaOpSchema).valid
|
|
580
|
+
) {
|
|
581
|
+
// merge tree delta op
|
|
582
|
+
if (this.fullScrub) {
|
|
583
|
+
innerContent.address = this.replaceText(
|
|
584
|
+
innerContent.address,
|
|
585
|
+
TextType.FluidObject,
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
this.fixDeltaOp(innerContent.contents);
|
|
589
|
+
} else if (
|
|
590
|
+
this.validator.validate(innerContent, opContentsRegisterCollectionSchema).valid
|
|
591
|
+
) {
|
|
592
|
+
// register collection op
|
|
593
|
+
if (this.fullScrub) {
|
|
594
|
+
innerContent.address = this.replaceText(
|
|
595
|
+
innerContent.address,
|
|
596
|
+
TextType.FluidObject,
|
|
597
|
+
);
|
|
598
|
+
innerContent.contents.key = this.replaceText(
|
|
599
|
+
innerContent.contents.key,
|
|
600
|
+
TextType.MapKey,
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
if (innerContent.contents.value !== undefined) {
|
|
604
|
+
innerContent.contents.value.value = this.replaceAny(
|
|
605
|
+
innerContent.contents.value.value,
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
} else {
|
|
609
|
+
// message contents don't match any known op format
|
|
610
|
+
this.objectMatchesSchema(contents, false);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
fixOp(message: any) {
|
|
616
|
+
// handle case where contents is stringified json
|
|
617
|
+
let msgContents;
|
|
618
|
+
if (typeof message.contents === "string") {
|
|
619
|
+
try {
|
|
620
|
+
msgContents = JSON.parse(message.contents);
|
|
621
|
+
} catch (e) {
|
|
622
|
+
this.debugMsg(e);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
} else {
|
|
626
|
+
msgContents = message.contents;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// handle container message types
|
|
630
|
+
switch (msgContents.type) {
|
|
631
|
+
case "attach": {
|
|
632
|
+
// this one is like a regular attach op, except its contents aren't nested as deep
|
|
633
|
+
// run fixAttach directly and return
|
|
634
|
+
this.fixAttach(msgContents);
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
case "component": {
|
|
638
|
+
// this one functionally nests its contents one layer deeper
|
|
639
|
+
// bring up the contents object and continue as usual
|
|
640
|
+
this.fixOpContentsObject(msgContents.contents);
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
case "chunkedOp": {
|
|
644
|
+
// this is a (regular?) op split into multiple parts due to size, e.g. because it
|
|
645
|
+
// has an attached image, and where the chunkedOp is within the top-level op's contents
|
|
646
|
+
// (as opposed to being at the top-level). The contents of the chunks need to be
|
|
647
|
+
// concatenated to form the complete stringified json object
|
|
648
|
+
// Early return here to skip re-stringify because no changes are made until the last
|
|
649
|
+
// chunk, and the ChunkedOpProcessor will handle everything at that point
|
|
650
|
+
return this.fixChunkedOp(message);
|
|
651
|
+
}
|
|
652
|
+
case "blobAttach": {
|
|
653
|
+
// TODO: handle this properly once blob api is used
|
|
654
|
+
this.debugMsg("TODO: blobAttach ops are skipped/unhandled");
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
default: {
|
|
658
|
+
// A regular op
|
|
659
|
+
this.fixOpContentsObject(msgContents);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// re-stringify the json if needed
|
|
664
|
+
if (typeof message.contents === "string") {
|
|
665
|
+
try {
|
|
666
|
+
message.contents = JSON.stringify(msgContents);
|
|
667
|
+
} catch (e) {
|
|
668
|
+
this.debugMsg(e);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* @param message - The top-level chunkedOp message or a top-level op message
|
|
676
|
+
* with a chunkedOp inside its contents
|
|
677
|
+
*/
|
|
678
|
+
fixChunkedOp(message: any) {
|
|
679
|
+
this.chunkProcessor.addMessage(message);
|
|
680
|
+
if (!this.chunkProcessor.hasAllMessages()) {
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const contents = this.chunkProcessor.getConcatenatedContents();
|
|
685
|
+
this.fixOpContentsObject(contents);
|
|
686
|
+
|
|
687
|
+
this.chunkProcessor.writeSanitizedContents(contents);
|
|
688
|
+
this.chunkProcessor.reset();
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
sanitize(): ISequencedDocumentMessage[] {
|
|
692
|
+
let seq = 0;
|
|
693
|
+
|
|
694
|
+
try {
|
|
695
|
+
this.messages.map((message) => {
|
|
696
|
+
seq = message.sequenceNumber;
|
|
697
|
+
// message types from protocol-definitions' protocol.ts
|
|
698
|
+
switch (message.type) {
|
|
699
|
+
case "join": {
|
|
700
|
+
this.fixJoin(message);
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
case "propose": {
|
|
704
|
+
this.fixPropose(message);
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
case "attach": {
|
|
708
|
+
this.fixAttach(message);
|
|
709
|
+
break;
|
|
710
|
+
}
|
|
711
|
+
case "op": {
|
|
712
|
+
this.fixOp(message);
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
case "chunkedOp": {
|
|
716
|
+
this.fixChunkedOp(message);
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
case "noop":
|
|
720
|
+
case "leave":
|
|
721
|
+
case "noClient":
|
|
722
|
+
case "summarize":
|
|
723
|
+
case "summaryAck":
|
|
724
|
+
case "summaryNack":
|
|
725
|
+
break;
|
|
726
|
+
default:
|
|
727
|
+
this.debugMsg(`Unexpected op type ${message.type}`);
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
// make sure we don't miss an incomplete chunked op at the end
|
|
732
|
+
assert(
|
|
733
|
+
!this.chunkProcessor.isPendingProcessing(),
|
|
734
|
+
0x08d /* "After sanitize, pending incomplete ops!" */,
|
|
735
|
+
);
|
|
736
|
+
} catch (error) {
|
|
737
|
+
this.debugMsg(`Error while processing sequenceNumber ${seq}`);
|
|
738
|
+
throw error;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
return this.messages;
|
|
742
|
+
}
|
|
682
743
|
}
|