@azure/storage-blob-changefeed 12.0.0-alpha.20220413.1 → 12.0.0-alpha.20220419.3

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 (47) hide show
  1. package/CHANGELOG.md +4 -1
  2. package/dist/index.js +147 -73
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/storage-blob-changefeed/src/ChangeFeed.js.map +1 -1
  5. package/dist-esm/storage-blob-changefeed/src/ChangeFeedFactory.js.map +1 -1
  6. package/dist-esm/storage-blob-changefeed/src/Chunk.js +2 -8
  7. package/dist-esm/storage-blob-changefeed/src/Chunk.js.map +1 -1
  8. package/dist-esm/storage-blob-changefeed/src/LazyLoadingBlobStream.js.map +1 -1
  9. package/dist-esm/storage-blob-changefeed/src/Segment.js.map +1 -1
  10. package/dist-esm/storage-blob-changefeed/src/SegmentFactory.js.map +1 -1
  11. package/dist-esm/storage-blob-changefeed/src/Shard.js.map +1 -1
  12. package/dist-esm/storage-blob-changefeed/src/ShardFactory.js.map +1 -1
  13. package/dist-esm/storage-blob-changefeed/src/models/BlobChangeFeedEvent.js.map +1 -1
  14. package/dist-esm/storage-blob-changefeed/src/utils/utils.common.js +81 -0
  15. package/dist-esm/storage-blob-changefeed/src/utils/utils.common.js.map +1 -1
  16. package/dist-esm/storage-internal-avro/src/AvroParser.js +38 -40
  17. package/dist-esm/storage-internal-avro/src/AvroParser.js.map +1 -1
  18. package/dist-esm/storage-internal-avro/src/AvroReadableFromBlob.js +4 -4
  19. package/dist-esm/storage-internal-avro/src/AvroReadableFromBlob.js.map +1 -1
  20. package/dist-esm/storage-internal-avro/src/AvroReadableFromStream.js +7 -5
  21. package/dist-esm/storage-internal-avro/src/AvroReadableFromStream.js.map +1 -1
  22. package/dist-esm/storage-internal-avro/src/AvroReader.js +8 -6
  23. package/dist-esm/storage-internal-avro/src/AvroReader.js.map +1 -1
  24. package/dist-esm/storage-internal-avro/src/utils/utils.common.js +2 -1
  25. package/dist-esm/storage-internal-avro/src/utils/utils.common.js.map +1 -1
  26. package/package.json +2 -2
  27. package/types/3.1/storage-blob-changefeed/src/models/BlobChangeFeedEvent.d.ts +140 -1
  28. package/types/3.1/storage-blob-changefeed/src/utils/utils.common.d.ts +2 -0
  29. package/types/3.1/storage-blob-changefeed/test/utils/testutils.common.d.ts +9 -1
  30. package/types/3.1/storage-blob-changefeed.d.ts +140 -1
  31. package/types/3.1/storage-internal-avro/src/AvroParser.d.ts +1 -1
  32. package/types/3.1/storage-internal-avro/src/AvroReader.d.ts +1 -1
  33. package/types/latest/storage-blob-changefeed/src/Chunk.d.ts.map +1 -1
  34. package/types/latest/storage-blob-changefeed/src/models/BlobChangeFeedEvent.d.ts +140 -1
  35. package/types/latest/storage-blob-changefeed/src/models/BlobChangeFeedEvent.d.ts.map +1 -1
  36. package/types/latest/storage-blob-changefeed/src/utils/utils.common.d.ts +2 -0
  37. package/types/latest/storage-blob-changefeed/src/utils/utils.common.d.ts.map +1 -1
  38. package/types/latest/storage-blob-changefeed/test/utils/testutils.common.d.ts +9 -1
  39. package/types/latest/storage-blob-changefeed/test/utils/testutils.common.d.ts.map +1 -1
  40. package/types/latest/storage-blob-changefeed.d.ts +146 -1
  41. package/types/latest/storage-internal-avro/src/AvroParser.d.ts +1 -1
  42. package/types/latest/storage-internal-avro/src/AvroParser.d.ts.map +1 -1
  43. package/types/latest/storage-internal-avro/src/AvroReadableFromBlob.d.ts.map +1 -1
  44. package/types/latest/storage-internal-avro/src/AvroReadableFromStream.d.ts.map +1 -1
  45. package/types/latest/storage-internal-avro/src/AvroReader.d.ts +1 -1
  46. package/types/latest/storage-internal-avro/src/AvroReader.d.ts.map +1 -1
  47. package/types/latest/storage-internal-avro/src/utils/utils.common.d.ts.map +1 -1
package/CHANGELOG.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Release History
2
2
 
3
- ## 12.0.0-preview.3 (Unreleased)
3
+ ## 12.0.0-preview.3 (2022-04-19)
4
4
 
5
+ ### Features Added
6
+
7
+ -Added support for event schema V3, V4, and V5.
5
8
 
6
9
  ## 12.0.0-preview.2 (2020-09-08)
7
10
 
package/dist/index.js CHANGED
@@ -159,6 +159,87 @@ function minDate(dateA, dateB) {
159
159
  }
160
160
  return dateA;
161
161
  }
162
+ function rawEventToBlobChangeFeedEvent(rawEvent) {
163
+ if (rawEvent.eventTime) {
164
+ rawEvent.eventTime = new Date(rawEvent.eventTime);
165
+ }
166
+ if (rawEvent.eTag) {
167
+ rawEvent.etag = rawEvent.eTag;
168
+ delete rawEvent.eTag;
169
+ }
170
+ if (rawEvent.data) {
171
+ if (rawEvent.data.recursive !== undefined) {
172
+ rawEvent.data.isRecursive = rawEvent.data.recursive;
173
+ delete rawEvent.data.recursive;
174
+ }
175
+ if (rawEvent.data.previousInfo) {
176
+ const previousInfo = rawEvent.data.previousInfo;
177
+ if (previousInfo.SoftDeleteSnapshot) {
178
+ previousInfo.softDeleteSnapshot = previousInfo.SoftDeleteSnapshot;
179
+ delete previousInfo.SoftDeleteSnapshot;
180
+ }
181
+ if (previousInfo.WasBlobSoftDeleted) {
182
+ previousInfo.isBlobSoftDeleted = previousInfo.WasBlobSoftDeleted === "true";
183
+ delete previousInfo.WasBlobSoftDeleted;
184
+ }
185
+ if (previousInfo.BlobVersion) {
186
+ previousInfo.newBlobVersion = previousInfo.BlobVersion;
187
+ delete previousInfo.BlobVersion;
188
+ }
189
+ if (previousInfo.LastVersion) {
190
+ previousInfo.oldBlobVersion = previousInfo.LastVersion;
191
+ delete previousInfo.LastVersion;
192
+ }
193
+ if (previousInfo.PreviousTier) {
194
+ previousInfo.previousTier = previousInfo.PreviousTier;
195
+ delete previousInfo.PreviousTier;
196
+ }
197
+ rawEvent.data.previousInfo = previousInfo;
198
+ }
199
+ if (rawEvent.data.blobPropertiesUpdated) {
200
+ const updatedBlobProperties = {};
201
+ Object.entries(rawEvent.data.blobPropertiesUpdated).map((item) => {
202
+ const blobPropertyChange = {
203
+ propertyName: item[0],
204
+ oldValue: item[1].previous,
205
+ newValue: item[1].current,
206
+ };
207
+ updatedBlobProperties[item[0]] = blobPropertyChange;
208
+ });
209
+ rawEvent.data.updatedBlobProperties = updatedBlobProperties;
210
+ delete rawEvent.data.blobPropertiesUpdated;
211
+ }
212
+ if (rawEvent.data.asyncOperationInfo) {
213
+ const longRunningOperationInfo = rawEvent.data.asyncOperationInfo;
214
+ if (longRunningOperationInfo.DestinationTier) {
215
+ longRunningOperationInfo.destinationAccessTier = longRunningOperationInfo.DestinationTier;
216
+ delete longRunningOperationInfo.DestinationTier;
217
+ }
218
+ if ("WasAsyncOperation" in longRunningOperationInfo) {
219
+ longRunningOperationInfo.isAsync = longRunningOperationInfo.WasAsyncOperation === "true";
220
+ delete longRunningOperationInfo.WasAsyncOperation;
221
+ }
222
+ if (longRunningOperationInfo.CopyId) {
223
+ longRunningOperationInfo.copyId = longRunningOperationInfo.CopyId;
224
+ delete longRunningOperationInfo.CopyId;
225
+ }
226
+ rawEvent.data.longRunningOperationInfo = longRunningOperationInfo;
227
+ delete rawEvent.data.asyncOperationInfo;
228
+ }
229
+ if (rawEvent.data.blobTagsUpdated) {
230
+ rawEvent.data.updatedBlobTags = {
231
+ newTags: rawEvent.data.blobTagsUpdated.current,
232
+ oldTags: rawEvent.data.blobTagsUpdated.previous,
233
+ };
234
+ delete rawEvent.data.blobTagsUpdated;
235
+ }
236
+ if (rawEvent.data.blobTier) {
237
+ rawEvent.data.blobAccessTier = rawEvent.data.blobTier;
238
+ delete rawEvent.data.blobTier;
239
+ }
240
+ }
241
+ return rawEvent;
242
+ }
162
243
 
163
244
  // Copyright (c) Microsoft Corporation.
164
245
  class ChangeFeed {
@@ -279,22 +360,6 @@ const AVRO_INIT_BYTES = new Uint8Array([79, 98, 106, 1]);
279
360
  const AVRO_CODEC_KEY = "avro.codec";
280
361
  const AVRO_SCHEMA_KEY = "avro.schema";
281
362
 
282
- // Copyright (c) Microsoft Corporation.
283
- // Licensed under the MIT license.
284
- function arraysEqual(a, b) {
285
- if (a === b)
286
- return true;
287
- if (a == null || b == null)
288
- return false;
289
- if (a.length != b.length)
290
- return false;
291
- for (let i = 0; i < a.length; ++i) {
292
- if (a[i] !== b[i])
293
- return false;
294
- }
295
- return true;
296
- }
297
-
298
363
  // Copyright (c) Microsoft Corporation.
299
364
  // Licensed under the MIT license.
300
365
  class AvroParser {
@@ -307,7 +372,7 @@ class AvroParser {
307
372
  */
308
373
  static async readFixedBytes(stream, length, options = {}) {
309
374
  const bytes = await stream.read(length, { abortSignal: options.abortSignal });
310
- if (bytes.length != length) {
375
+ if (bytes.length !== length) {
311
376
  throw new Error("Hit stream end.");
312
377
  }
313
378
  return bytes;
@@ -337,6 +402,7 @@ class AvroParser {
337
402
  } while (haveMoreByte && significanceInBit < 28); // bitwise operation only works for 32-bit integers
338
403
  if (haveMoreByte) {
339
404
  // Switch to float arithmetic
405
+ // eslint-disable-next-line no-self-assign
340
406
  zigZagEncoded = zigZagEncoded;
341
407
  significanceInFloat = 268435456; // 2 ** 28.
342
408
  do {
@@ -363,10 +429,10 @@ class AvroParser {
363
429
  }
364
430
  static async readBoolean(stream, options = {}) {
365
431
  const b = await AvroParser.readByte(stream, options);
366
- if (b == 1) {
432
+ if (b === 1) {
367
433
  return true;
368
434
  }
369
- else if (b == 0) {
435
+ else if (b === 0) {
370
436
  return false;
371
437
  }
372
438
  else {
@@ -388,16 +454,10 @@ class AvroParser {
388
454
  if (size < 0) {
389
455
  throw new Error("Bytes size was negative.");
390
456
  }
391
- return await stream.read(size, { abortSignal: options.abortSignal });
457
+ return stream.read(size, { abortSignal: options.abortSignal });
392
458
  }
393
459
  static async readString(stream, options = {}) {
394
460
  const u8arr = await AvroParser.readBytes(stream, options);
395
- // polyfill TextDecoder to be backward compatible with older
396
- // nodejs that doesn't expose TextDecoder as a global variable
397
- if (typeof TextDecoder === "undefined" && typeof require !== "undefined") {
398
- global.TextDecoder = require("util").TextDecoder;
399
- }
400
- // FUTURE: need TextDecoder polyfill for IE
401
461
  const utf8decoder = new TextDecoder();
402
462
  return utf8decoder.decode(u8arr);
403
463
  }
@@ -408,8 +468,8 @@ class AvroParser {
408
468
  return { key, value };
409
469
  }
410
470
  static async readMap(stream, readItemMethod, options = {}) {
411
- const readPairMethod = async (stream, options = {}) => {
412
- return await AvroParser.readMapPair(stream, readItemMethod, options);
471
+ const readPairMethod = (s, opts = {}) => {
472
+ return AvroParser.readMapPair(s, readItemMethod, opts);
413
473
  };
414
474
  const pairs = await AvroParser.readArray(stream, readPairMethod, options);
415
475
  const dict = {};
@@ -420,7 +480,7 @@ class AvroParser {
420
480
  }
421
481
  static async readArray(stream, readItemMethod, options = {}) {
422
482
  const items = [];
423
- for (let count = await AvroParser.readLong(stream, options); count != 0; count = await AvroParser.readLong(stream, options)) {
483
+ for (let count = await AvroParser.readLong(stream, options); count !== 0; count = await AvroParser.readLong(stream, options)) {
424
484
  if (count < 0) {
425
485
  // Ignore block sizes
426
486
  await AvroParser.readLong(stream, options);
@@ -443,6 +503,17 @@ var AvroComplex;
443
503
  AvroComplex["UNION"] = "union";
444
504
  AvroComplex["FIXED"] = "fixed";
445
505
  })(AvroComplex || (AvroComplex = {}));
506
+ var AvroPrimitive;
507
+ (function (AvroPrimitive) {
508
+ AvroPrimitive["NULL"] = "null";
509
+ AvroPrimitive["BOOLEAN"] = "boolean";
510
+ AvroPrimitive["INT"] = "int";
511
+ AvroPrimitive["LONG"] = "long";
512
+ AvroPrimitive["FLOAT"] = "float";
513
+ AvroPrimitive["DOUBLE"] = "double";
514
+ AvroPrimitive["BYTES"] = "bytes";
515
+ AvroPrimitive["STRING"] = "string";
516
+ })(AvroPrimitive || (AvroPrimitive = {}));
446
517
  class AvroType {
447
518
  /**
448
519
  * Determines the AvroType from the Avro Schema.
@@ -482,7 +553,9 @@ class AvroType {
482
553
  try {
483
554
  return AvroType.fromStringSchema(type);
484
555
  }
485
- catch (err) { }
556
+ catch (err) {
557
+ // eslint-disable-line no-empty
558
+ }
486
559
  switch (type) {
487
560
  case AvroComplex.RECORD:
488
561
  if (schema.aliases) {
@@ -491,6 +564,7 @@ class AvroType {
491
564
  if (!schema.name) {
492
565
  throw new Error(`Required attribute 'name' doesn't exist on schema: ${schema}`);
493
566
  }
567
+ // eslint-disable-next-line no-case-declarations
494
568
  const fields = {};
495
569
  if (!schema.fields) {
496
570
  throw new Error(`Required attribute 'fields' doesn't exist on schema: ${schema}`);
@@ -519,40 +593,29 @@ class AvroType {
519
593
  }
520
594
  }
521
595
  }
522
- var AvroPrimitive;
523
- (function (AvroPrimitive) {
524
- AvroPrimitive["NULL"] = "null";
525
- AvroPrimitive["BOOLEAN"] = "boolean";
526
- AvroPrimitive["INT"] = "int";
527
- AvroPrimitive["LONG"] = "long";
528
- AvroPrimitive["FLOAT"] = "float";
529
- AvroPrimitive["DOUBLE"] = "double";
530
- AvroPrimitive["BYTES"] = "bytes";
531
- AvroPrimitive["STRING"] = "string";
532
- })(AvroPrimitive || (AvroPrimitive = {}));
533
596
  class AvroPrimitiveType extends AvroType {
534
597
  constructor(primitive) {
535
598
  super();
536
599
  this._primitive = primitive;
537
600
  }
538
- async read(stream, options = {}) {
601
+ read(stream, options = {}) {
539
602
  switch (this._primitive) {
540
603
  case AvroPrimitive.NULL:
541
- return await AvroParser.readNull();
604
+ return AvroParser.readNull();
542
605
  case AvroPrimitive.BOOLEAN:
543
- return await AvroParser.readBoolean(stream, options);
606
+ return AvroParser.readBoolean(stream, options);
544
607
  case AvroPrimitive.INT:
545
- return await AvroParser.readInt(stream, options);
608
+ return AvroParser.readInt(stream, options);
546
609
  case AvroPrimitive.LONG:
547
- return await AvroParser.readLong(stream, options);
610
+ return AvroParser.readLong(stream, options);
548
611
  case AvroPrimitive.FLOAT:
549
- return await AvroParser.readFloat(stream, options);
612
+ return AvroParser.readFloat(stream, options);
550
613
  case AvroPrimitive.DOUBLE:
551
- return await AvroParser.readDouble(stream, options);
614
+ return AvroParser.readDouble(stream, options);
552
615
  case AvroPrimitive.BYTES:
553
- return await AvroParser.readBytes(stream, options);
616
+ return AvroParser.readBytes(stream, options);
554
617
  case AvroPrimitive.STRING:
555
- return await AvroParser.readString(stream, options);
618
+ return AvroParser.readString(stream, options);
556
619
  default:
557
620
  throw new Error("Unknown Avro Primitive");
558
621
  }
@@ -575,7 +638,7 @@ class AvroUnionType extends AvroType {
575
638
  }
576
639
  async read(stream, options = {}) {
577
640
  const typeIndex = await AvroParser.readInt(stream, options);
578
- return await this._types[typeIndex].read(stream, options);
641
+ return this._types[typeIndex].read(stream, options);
579
642
  }
580
643
  }
581
644
  class AvroMapType extends AvroType {
@@ -583,11 +646,11 @@ class AvroMapType extends AvroType {
583
646
  super();
584
647
  this._itemType = itemType;
585
648
  }
586
- async read(stream, options = {}) {
587
- const readItemMethod = async (s, options) => {
588
- return await this._itemType.read(s, options);
649
+ read(stream, options = {}) {
650
+ const readItemMethod = (s, opts) => {
651
+ return this._itemType.read(s, opts);
589
652
  };
590
- return await AvroParser.readMap(stream, readItemMethod, options);
653
+ return AvroParser.readMap(stream, readItemMethod, options);
591
654
  }
592
655
  }
593
656
  class AvroRecordType extends AvroType {
@@ -600,7 +663,7 @@ class AvroRecordType extends AvroType {
600
663
  const record = {};
601
664
  record["$schema"] = this._name;
602
665
  for (const key in this._fields) {
603
- if (this._fields.hasOwnProperty(key)) {
666
+ if (Object.prototype.hasOwnProperty.call(this._fields, key)) {
604
667
  record[key] = await this._fields[key].read(stream, options);
605
668
  }
606
669
  }
@@ -608,6 +671,23 @@ class AvroRecordType extends AvroType {
608
671
  }
609
672
  }
610
673
 
674
+ // Copyright (c) Microsoft Corporation.
675
+ // Licensed under the MIT license.
676
+ function arraysEqual(a, b) {
677
+ if (a === b)
678
+ return true;
679
+ // eslint-disable-next-line eqeqeq
680
+ if (a == null || b == null)
681
+ return false;
682
+ if (a.length !== b.length)
683
+ return false;
684
+ for (let i = 0; i < a.length; ++i) {
685
+ if (a[i] !== b[i])
686
+ return false;
687
+ }
688
+ return true;
689
+ }
690
+
611
691
  // Copyright (c) Microsoft Corporation.
612
692
  class AvroReader {
613
693
  constructor(dataStream, headerStream, currentBlockOffset, indexWithinCurrentBlock) {
@@ -638,7 +718,7 @@ class AvroReader {
638
718
  });
639
719
  // Validate codec
640
720
  const codec = this._metadata[AVRO_CODEC_KEY];
641
- if (!(codec == undefined || codec == "null")) {
721
+ if (!(codec === undefined || codec === null || codec === "null")) {
642
722
  throw new Error("Codecs are not supported");
643
723
  }
644
724
  // The 16-byte, randomly-generated sync marker for this file.
@@ -648,7 +728,7 @@ class AvroReader {
648
728
  // Parse the schema
649
729
  const schema = JSON.parse(this._metadata[AVRO_SCHEMA_KEY]);
650
730
  this._itemType = AvroType.fromSchema(schema);
651
- if (this._blockOffset == 0) {
731
+ if (this._blockOffset === 0) {
652
732
  this._blockOffset = this._initialBlockOffset + this._dataStream.position;
653
733
  }
654
734
  this._itemsRemainingInBlock = await AvroParser.readLong(this._dataStream, {
@@ -678,7 +758,7 @@ class AvroReader {
678
758
  }));
679
759
  this._itemsRemainingInBlock--;
680
760
  this._objectIndex++;
681
- if (this._itemsRemainingInBlock == 0) {
761
+ if (this._itemsRemainingInBlock === 0) {
682
762
  const marker = yield tslib.__await(AvroParser.readFixedBytes(this._dataStream, AVRO_SYNC_MARKER_SIZE, {
683
763
  abortSignal: options.abortSignal,
684
764
  }));
@@ -753,6 +833,7 @@ class AvroReadableFromStream extends AvroReadable {
753
833
  else {
754
834
  // register callback to wait for enough data to read
755
835
  return new Promise((resolve, reject) => {
836
+ /* eslint-disable @typescript-eslint/no-use-before-define */
756
837
  const cleanUp = () => {
757
838
  this._readable.removeListener("readable", readableCallback);
758
839
  this._readable.removeListener("error", rejectCallback);
@@ -763,12 +844,12 @@ class AvroReadableFromStream extends AvroReadable {
763
844
  }
764
845
  };
765
846
  const readableCallback = () => {
766
- const chunk = this._readable.read(size);
767
- if (chunk) {
768
- this._position += chunk.length;
847
+ const callbackChunk = this._readable.read(size);
848
+ if (callbackChunk) {
849
+ this._position += callbackChunk.length;
769
850
  cleanUp();
770
- // chunk.length maybe less than desired size if the stream ends.
771
- resolve(this.toUint8Array(chunk));
851
+ // callbackChunk.length maybe less than desired size if the stream ends.
852
+ resolve(this.toUint8Array(callbackChunk));
772
853
  }
773
854
  };
774
855
  const rejectCallback = () => {
@@ -786,6 +867,7 @@ class AvroReadableFromStream extends AvroReadable {
786
867
  if (options.abortSignal) {
787
868
  options.abortSignal.addEventListener("abort", abortHandler);
788
869
  }
870
+ /* eslint-enable @typescript-eslint/no-use-before-define */
789
871
  });
790
872
  }
791
873
  }
@@ -1061,7 +1143,6 @@ class ShardFactory {
1061
1143
  }
1062
1144
 
1063
1145
  // Copyright (c) Microsoft Corporation.
1064
- // Licensed under the MIT license.
1065
1146
  class Chunk {
1066
1147
  constructor(avroReader, blockOffset, eventIndex, chunkPath, avroOptions = {}) {
1067
1148
  this.chunkPath = chunkPath;
@@ -1094,14 +1175,7 @@ class Chunk {
1094
1175
  if (eventRaw === null) {
1095
1176
  return undefined;
1096
1177
  }
1097
- if (eventRaw.eventTime) {
1098
- eventRaw.eventTime = new Date(eventRaw.eventTime);
1099
- }
1100
- if (eventRaw.eTag) {
1101
- eventRaw.etag = eventRaw.eTag;
1102
- delete eventRaw.eTag;
1103
- }
1104
- return eventRaw;
1178
+ return rawEventToBlobChangeFeedEvent(eventRaw);
1105
1179
  }
1106
1180
  }
1107
1181
  }