@azure/storage-blob-changefeed 12.0.0-alpha.20220512.4 → 12.0.0-alpha.20220614.1

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/dist/index.js CHANGED
@@ -1182,18 +1182,19 @@ class Chunk {
1182
1182
 
1183
1183
  // Copyright (c) Microsoft Corporation.
1184
1184
  class ChunkFactory {
1185
- constructor(avroReaderFactory, lazyLoadingBlobStreamFactory) {
1185
+ constructor(avroReaderFactory, lazyLoadingBlobStreamFactory, maxTransferSize) {
1186
1186
  this.avroReaderFactory = avroReaderFactory;
1187
1187
  this.lazyLoadingBlobStreamFactory = lazyLoadingBlobStreamFactory;
1188
+ this.maxTransferSize = maxTransferSize;
1188
1189
  }
1189
1190
  async create(containerClient, chunkPath, blockOffset, eventIndex, options = {}) {
1190
1191
  const blobClient = containerClient.getBlobClient(chunkPath);
1191
1192
  blockOffset = blockOffset || 0;
1192
1193
  eventIndex = eventIndex || 0;
1193
- const dataStream = streamToAvroReadable(this.lazyLoadingBlobStreamFactory.create(blobClient, blockOffset, CHANGE_FEED_CHUNK_BLOCK_DOWNLOAD_SIZE, options));
1194
+ const dataStream = streamToAvroReadable(this.lazyLoadingBlobStreamFactory.create(blobClient, blockOffset, this.maxTransferSize ? this.maxTransferSize : CHANGE_FEED_CHUNK_BLOCK_DOWNLOAD_SIZE, options));
1194
1195
  let avroReader;
1195
1196
  if (blockOffset !== 0) {
1196
- const headerStream = streamToAvroReadable(this.lazyLoadingBlobStreamFactory.create(blobClient, 0, CHANGE_FEED_CHUNK_BLOCK_DOWNLOAD_SIZE, options));
1197
+ const headerStream = streamToAvroReadable(this.lazyLoadingBlobStreamFactory.create(blobClient, 0, this.maxTransferSize ? this.maxTransferSize : CHANGE_FEED_CHUNK_BLOCK_DOWNLOAD_SIZE, options));
1197
1198
  avroReader = this.avroReaderFactory.create(dataStream, headerStream, blockOffset, eventIndex);
1198
1199
  }
1199
1200
  else {
@@ -1328,12 +1329,21 @@ class LazyLoadingBlobStreamFactory {
1328
1329
 
1329
1330
  // Copyright (c) Microsoft Corporation.
1330
1331
  class ChangeFeedFactory {
1331
- constructor(segmentFactory) {
1332
+ constructor(segmentFactoryOrMaxTransferSize) {
1333
+ let segmentFactory;
1334
+ if (segmentFactoryOrMaxTransferSize) {
1335
+ if (Number.isFinite(segmentFactoryOrMaxTransferSize)) {
1336
+ this.maxTransferSize = segmentFactoryOrMaxTransferSize;
1337
+ }
1338
+ else if (segmentFactoryOrMaxTransferSize instanceof SegmentFactory) {
1339
+ segmentFactory = segmentFactoryOrMaxTransferSize;
1340
+ }
1341
+ }
1332
1342
  if (segmentFactory) {
1333
1343
  this.segmentFactory = segmentFactory;
1334
1344
  }
1335
1345
  else {
1336
- this.segmentFactory = new SegmentFactory(new ShardFactory(new ChunkFactory(new AvroReaderFactory(), new LazyLoadingBlobStreamFactory())));
1346
+ this.segmentFactory = new SegmentFactory(new ShardFactory(new ChunkFactory(new AvroReaderFactory(), new LazyLoadingBlobStreamFactory(), this.maxTransferSize)));
1337
1347
  }
1338
1348
  }
1339
1349
  static validateCursor(containerClient, cursor) {
@@ -1374,10 +1384,21 @@ class ChangeFeedFactory {
1374
1384
  }
1375
1385
  // Get last consumable.
1376
1386
  const blobClient = containerClient.getBlobClient(CHANGE_FEED_META_SEGMENT_PATH);
1377
- const blobDownloadRes = await blobClient.download(undefined, undefined, {
1378
- abortSignal: options.abortSignal,
1379
- tracingOptions: updatedOptions.tracingOptions,
1380
- });
1387
+ let blobDownloadRes;
1388
+ try {
1389
+ blobDownloadRes = await blobClient.download(undefined, undefined, {
1390
+ abortSignal: options.abortSignal,
1391
+ tracingOptions: updatedOptions.tracingOptions,
1392
+ });
1393
+ }
1394
+ catch (err) {
1395
+ if (err.statusCode === 404) {
1396
+ return new ChangeFeed();
1397
+ }
1398
+ else {
1399
+ throw err;
1400
+ }
1401
+ }
1381
1402
  const lastConsumable = new Date(JSON.parse(await bodyToString(blobDownloadRes)).lastConsumable);
1382
1403
  // Get year paths
1383
1404
  const years = await getYearsPaths(containerClient, {
@@ -1467,8 +1488,9 @@ class BlobChangeFeedClient {
1467
1488
  constructor(urlOrClient, credentialOrPipeline,
1468
1489
  // Legacy, no way to fix the eslint error without breaking. Disable the rule for this line.
1469
1490
  /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options */
1470
- options) {
1471
- this.changeFeedFactory = new ChangeFeedFactory();
1491
+ options, changeFeedClientOptions) {
1492
+ this.changeFeedClientOptions = changeFeedClientOptions || {};
1493
+ this.changeFeedFactory = new ChangeFeedFactory(this.changeFeedClientOptions.maximumTransferSize);
1472
1494
  if (credentialOrPipeline instanceof storageBlob.Pipeline) {
1473
1495
  this.blobServiceClient = new storageBlob.BlobServiceClient(urlOrClient, credentialOrPipeline);
1474
1496
  }
@@ -1491,9 +1513,12 @@ class BlobChangeFeedClient {
1491
1513
  static fromConnectionString(connectionString,
1492
1514
  // Legacy, no way to fix the eslint error without breaking. Disable the rule for this line.
1493
1515
  /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options */
1494
- options) {
1516
+ options,
1517
+ // Static method to construct an object, the option is for the object not for the method.
1518
+ /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options */
1519
+ changeFeedClientOptions) {
1495
1520
  const blobServiceClient = storageBlob.BlobServiceClient.fromConnectionString(connectionString, options);
1496
- return new BlobChangeFeedClient(blobServiceClient.url, blobServiceClient.credential, appendUserAgentPrefix(options));
1521
+ return new BlobChangeFeedClient(blobServiceClient.url, blobServiceClient.credential, appendUserAgentPrefix(options), changeFeedClientOptions);
1497
1522
  }
1498
1523
  getChange(options = {}) {
1499
1524
  return tslib.__asyncGenerator(this, arguments, function* getChange_1() {