azure-kusto-ingest 5.0.3 → 5.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.
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.generateBlobName = exports.BlobDescriptor = exports.StreamDescriptor = exports.getSourceId = exports.CompressionType = void 0;
8
+ exports.generateBlobName = exports.BlobDescriptor = exports.StreamDescriptor = exports.AbstractDescriptor = exports.getSourceId = exports.CompressionType = void 0;
9
9
  const uuid_1 = require("uuid");
10
10
  const uuid_validate_1 = __importDefault(require("uuid-validate"));
11
+ const storage_blob_1 = require("@azure/storage-blob");
11
12
  var CompressionType;
12
13
  (function (CompressionType) {
13
14
  CompressionType["ZIP"] = ".zip";
@@ -24,15 +25,22 @@ const getSourceId = (sourceId) => {
24
25
  return (0, uuid_1.v4)();
25
26
  };
26
27
  exports.getSourceId = getSourceId;
27
- class StreamDescriptor {
28
+ class AbstractDescriptor {
29
+ constructor(sourceId = null, size = null) {
30
+ this.sourceId = sourceId;
31
+ this.size = size;
32
+ this.sourceId = (0, exports.getSourceId)(sourceId);
33
+ }
34
+ }
35
+ exports.AbstractDescriptor = AbstractDescriptor;
36
+ class StreamDescriptor extends AbstractDescriptor {
28
37
  /**
29
38
  * Use Readable for Node.js and ArrayBuffer in browser
30
39
  */
31
- constructor(stream, sourceId = null, compressionType = CompressionType.None) {
40
+ constructor(stream, sourceId = null, compressionType = CompressionType.None, size = null) {
41
+ super(sourceId, size);
32
42
  this.stream = stream;
33
- this.size = null;
34
43
  this.compressionType = compressionType;
35
- this.sourceId = (0, exports.getSourceId)(sourceId);
36
44
  }
37
45
  merge(other) {
38
46
  this.size = other.size;
@@ -46,11 +54,23 @@ class StreamDescriptor {
46
54
  }
47
55
  }
48
56
  exports.StreamDescriptor = StreamDescriptor;
49
- class BlobDescriptor {
57
+ class BlobDescriptor extends AbstractDescriptor {
50
58
  constructor(path, size = null, sourceId = null) {
59
+ super(sourceId, size);
51
60
  this.path = path;
52
- this.size = size;
53
- this.sourceId = (0, exports.getSourceId)(sourceId);
61
+ }
62
+ async fillSize() {
63
+ if (!this.size) {
64
+ const blobClient = new storage_blob_1.BlobClient(this.path);
65
+ const blobProps = await blobClient.getProperties();
66
+ const length = blobProps.contentLength;
67
+ if (length !== undefined) {
68
+ if (length === 0) {
69
+ throw new Error("Empty blob.");
70
+ }
71
+ this.size = length;
72
+ }
73
+ }
54
74
  }
55
75
  }
56
76
  exports.BlobDescriptor = BlobDescriptor;
@@ -8,13 +8,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.FileDescriptor = void 0;
9
9
  const pako_1 = __importDefault(require("pako"));
10
10
  const descriptors_1 = require("./descriptors");
11
- class FileDescriptor {
11
+ class FileDescriptor extends descriptors_1.AbstractDescriptor {
12
12
  constructor(file, sourceId = null, size = null, compressionType = descriptors_1.CompressionType.None, extension, name) {
13
+ super(sourceId);
13
14
  this.file = file;
14
- this.sourceId = sourceId;
15
15
  this.extension = extension;
16
16
  this.name = name;
17
- this.sourceId = (0, descriptors_1.getSourceId)(sourceId);
18
17
  this.compressionType = compressionType;
19
18
  this.size = size || file.size;
20
19
  this.zipped = compressionType !== descriptors_1.CompressionType.None || this.extension === ".gz" || this.extension === ".zip";
@@ -15,7 +15,7 @@ const descriptors_1 = require("./descriptors");
15
15
  /**
16
16
  * Describes a file to be ingested. Use string to describe a local path in Node.JS and Blob object in browsers
17
17
  */
18
- class FileDescriptor {
18
+ class FileDescriptor extends descriptors_1.AbstractDescriptor {
19
19
  constructor(
20
20
  /**
21
21
  * Use string in Node.JS and Blob in browser
@@ -23,14 +23,13 @@ class FileDescriptor {
23
23
  file, sourceId = null, size = null, compressionType = descriptors_1.CompressionType.None, extension, // Extracted from file name by default
24
24
  name // Extracted from file name by default
25
25
  ) {
26
+ super(sourceId, size);
26
27
  this.file = file;
27
28
  this.extension = extension;
28
29
  this.name = name;
29
- this.sourceId = (0, descriptors_1.getSourceId)(sourceId);
30
30
  this.compressionType = compressionType;
31
31
  this.name = name ? name : path_1.default.basename(this.file);
32
32
  this.extension = extension ? extension : path_1.default.extname(this.file).toLowerCase();
33
- this.size = size;
34
33
  this.zipped = compressionType !== descriptors_1.CompressionType.None || this.extension === ".gz" || this.extension === ".zip";
35
34
  }
36
35
  async _gzip() {
@@ -5,11 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.IngestionPropertiesValidationError = exports.IngestionPropertiesEnums = exports.ColumnMapping = exports.FieldTransformation = exports.ConstantTransformation = exports.SStreamColumnMapping = exports.ApacheAvroColumnMapping = exports.CompressionType = exports.IngestionMappingKind = exports.DataFormat = exports.ValidationOptions = exports.ValidationImplications = exports.ReportMethod = exports.ReportLevel = exports.ValidationPolicy = exports.W3CLogFileMapping = exports.OrcColumnMapping = exports.ParquetColumnMapping = exports.AvroColumnMapping = exports.CsvColumnMapping = exports.JsonColumnMapping = exports.IngestionDescriptors = exports.IngestionProperties = exports.IngestStatusQueues = exports.ManagedStreamingIngestClient = exports.StreamingIngestClient = exports.IngestClient = void 0;
8
+ exports.IngestionPropertiesValidationError = exports.IngestionPropertiesEnums = exports.StreamDescriptor = exports.BlobDescriptor = exports.ColumnMapping = exports.FieldTransformation = exports.ConstantTransformation = exports.SStreamColumnMapping = exports.ApacheAvroColumnMapping = exports.CompressionType = exports.IngestionMappingKind = exports.DataFormat = exports.ValidationOptions = exports.ValidationImplications = exports.ReportMethod = exports.ReportLevel = exports.ValidationPolicy = exports.W3CLogFileMapping = exports.OrcColumnMapping = exports.ParquetColumnMapping = exports.AvroColumnMapping = exports.CsvColumnMapping = exports.JsonColumnMapping = exports.IngestionDescriptors = exports.IngestionProperties = exports.IngestStatusQueues = exports.ManagedStreamingIngestClient = exports.StreamingIngestClient = exports.IngestClient = void 0;
9
9
  const ingestClient_1 = __importDefault(require("./ingestClient"));
10
+ exports.IngestClient = ingestClient_1.default;
10
11
  const streamingIngestClient_1 = __importDefault(require("./streamingIngestClient"));
12
+ exports.StreamingIngestClient = streamingIngestClient_1.default;
11
13
  const managedStreamingIngestClient_1 = __importDefault(require("./managedStreamingIngestClient"));
14
+ exports.ManagedStreamingIngestClient = managedStreamingIngestClient_1.default;
12
15
  const status_1 = __importDefault(require("./status"));
16
+ exports.IngestStatusQueues = status_1.default;
13
17
  const ingestionProperties_1 = require("./ingestionProperties");
14
18
  Object.defineProperty(exports, "DataFormat", { enumerable: true, get: function () { return ingestionProperties_1.DataFormat; } });
15
19
  Object.defineProperty(exports, "IngestionMappingKind", { enumerable: true, get: function () { return ingestionProperties_1.IngestionMappingKind; } });
@@ -19,7 +23,9 @@ Object.defineProperty(exports, "ValidationImplications", { enumerable: true, get
19
23
  Object.defineProperty(exports, "ValidationOptions", { enumerable: true, get: function () { return ingestionProperties_1.ValidationOptions; } });
20
24
  Object.defineProperty(exports, "ValidationPolicy", { enumerable: true, get: function () { return ingestionProperties_1.ValidationPolicy; } });
21
25
  const descriptors_1 = require("./descriptors");
26
+ Object.defineProperty(exports, "BlobDescriptor", { enumerable: true, get: function () { return descriptors_1.BlobDescriptor; } });
22
27
  Object.defineProperty(exports, "CompressionType", { enumerable: true, get: function () { return descriptors_1.CompressionType; } });
28
+ Object.defineProperty(exports, "StreamDescriptor", { enumerable: true, get: function () { return descriptors_1.StreamDescriptor; } });
23
29
  const fileDescriptor_1 = require("./fileDescriptor");
24
30
  const columnMappings_1 = require("./columnMappings");
25
31
  Object.defineProperty(exports, "ApacheAvroColumnMapping", { enumerable: true, get: function () { return columnMappings_1.ApacheAvroColumnMapping; } });
@@ -33,12 +39,11 @@ Object.defineProperty(exports, "OrcColumnMapping", { enumerable: true, get: func
33
39
  Object.defineProperty(exports, "ParquetColumnMapping", { enumerable: true, get: function () { return columnMappings_1.ParquetColumnMapping; } });
34
40
  Object.defineProperty(exports, "SStreamColumnMapping", { enumerable: true, get: function () { return columnMappings_1.SStreamColumnMapping; } });
35
41
  Object.defineProperty(exports, "W3CLogFileMapping", { enumerable: true, get: function () { return columnMappings_1.W3CLogFileMapping; } });
36
- exports.IngestClient = ingestClient_1.default;
37
- exports.StreamingIngestClient = streamingIngestClient_1.default;
38
- exports.ManagedStreamingIngestClient = managedStreamingIngestClient_1.default;
39
- exports.IngestStatusQueues = status_1.default;
40
42
  var ingestionProperties_2 = require("./ingestionProperties");
41
43
  Object.defineProperty(exports, "IngestionProperties", { enumerable: true, get: function () { return ingestionProperties_2.IngestionProperties; } });
44
+ /**
45
+ * @deprecated - import directly instead. Export const is not exporting type.
46
+ */
42
47
  exports.IngestionDescriptors = {
43
48
  BlobDescriptor: descriptors_1.BlobDescriptor,
44
49
  FileDescriptor: fileDescriptor_1.FileDescriptor,
@@ -36,7 +36,12 @@ class KustoIngestClient extends ingestClientBase_1.KustoIngestClientBase {
36
36
  const descriptor = stream instanceof descriptors_1.StreamDescriptor ? stream : new descriptors_1.StreamDescriptor(stream);
37
37
  const blobName = (0, descriptors_1.generateBlobName)(descriptor, props);
38
38
  const blockBlobClient = await this.resourceManager.getBlockBlobClient(blobName);
39
- await blockBlobClient.uploadStream(descriptor.stream);
39
+ if (descriptor.stream instanceof Buffer) {
40
+ await blockBlobClient.uploadData(descriptor.stream);
41
+ }
42
+ else {
43
+ await blockBlobClient.uploadStream(descriptor.stream);
44
+ }
40
45
  return this.ingestFromBlob(new descriptors_1.BlobDescriptor(blockBlobClient.url), props); // descriptor.size?
41
46
  }
42
47
  }
@@ -52,6 +52,9 @@ class IngestionBlobInfo {
52
52
  if (ingestionProperties.format) {
53
53
  additionalProperties.format = ingestionProperties.format;
54
54
  }
55
+ if (ingestionProperties.ignoreFirstRecord) {
56
+ additionalProperties.ignoreFirstRecord = ingestionProperties.ignoreFirstRecord;
57
+ }
55
58
  this.AdditionalProperties = additionalProperties;
56
59
  }
57
60
  }
@@ -67,20 +67,53 @@ class KustoManagedStreamingIngestClient extends abstractKustoClient_1.AbstractKu
67
67
  /**
68
68
  * Use Readable for Node.js and ArrayBuffer in browser
69
69
  */
70
- async ingestFromStream(stream, ingestionProperties) {
70
+ async ingestFromStream(stream, ingestionProperties, clientRequestId) {
71
+ var _a;
71
72
  this.ensureOpen();
72
73
  const props = this._getMergedProps(ingestionProperties);
73
- const descriptor = stream instanceof descriptors_1.StreamDescriptor ? stream : new descriptors_1.StreamDescriptor(stream);
74
+ let descriptor = stream instanceof descriptors_1.StreamDescriptor ? stream : new descriptors_1.StreamDescriptor(stream);
74
75
  let result = core_util_1.isNode ? await (0, streamUtils_1.tryStreamToArray)(descriptor.stream, maxStreamSize) : descriptor.stream;
75
- if ((core_util_1.isNode && result instanceof Buffer) || (!core_util_1.isNode && descriptor.stream.byteLength < maxStreamSize)) {
76
+ descriptor = new descriptors_1.StreamDescriptor(result).merge(descriptor);
77
+ let streamingResult = null;
78
+ // tryStreamToArray returns a Buffer in NodeJS impl if stream size is small enouph
79
+ if ((core_util_1.isNode && result instanceof Buffer) || !core_util_1.isNode) {
80
+ streamingResult = await this.streamWithRetries(core_util_1.isNode ? (_a = descriptor.size) !== null && _a !== void 0 ? _a : 0 : descriptor.stream.byteLength, descriptor, props, clientRequestId, result);
81
+ result = core_util_1.isNode ? (0, stream_array_1.default)([result]) : descriptor.stream;
82
+ }
83
+ return streamingResult !== null && streamingResult !== void 0 ? streamingResult : this.queuedIngestClient.ingestFromStream(new descriptors_1.StreamDescriptor(result).merge(descriptor), props);
84
+ }
85
+ /**
86
+ * Use string for Node.js and Blob in browser
87
+ */
88
+ async ingestFromFile(file, ingestionProperties) {
89
+ this.ensureOpen();
90
+ const stream = file instanceof fileDescriptor_1.FileDescriptor ? await (0, streamUtils_1.tryFileToBuffer)(file) : await (0, streamUtils_1.tryFileToBuffer)(new fileDescriptor_1.FileDescriptor(file));
91
+ return await this.ingestFromStream(stream, ingestionProperties);
92
+ }
93
+ async ingestFromBlob(blob, ingestionProperties, clientRequestId) {
94
+ var _a;
95
+ const props = this._getMergedProps(ingestionProperties);
96
+ const descriptor = blob instanceof descriptors_1.BlobDescriptor ? blob : new descriptors_1.BlobDescriptor(blob);
97
+ // No need to check blob size if it was given to us that it's not empty
98
+ await descriptor.fillSize();
99
+ const streamingResult = await this.streamWithRetries((_a = descriptor.size) !== null && _a !== void 0 ? _a : 0, descriptor, props, clientRequestId);
100
+ return streamingResult !== null && streamingResult !== void 0 ? streamingResult : this.queuedIngestClient.ingestFromBlob(descriptor, props);
101
+ }
102
+ async streamWithRetries(length, descriptor, props, clientRequestId, stream) {
103
+ const isBlob = descriptor instanceof descriptors_1.BlobDescriptor;
104
+ if (length <= maxStreamSize) {
76
105
  // If we get buffer that means it was less than the max size, so we can do streamingIngestion
77
106
  const retry = new retry_1.ExponentialRetry(attemptCount, this.baseSleepTimeSecs, this.baseJitterSecs);
78
107
  while (retry.shouldTry()) {
79
108
  try {
80
- const sourceId = `KNC.executeManagedStreamingIngest;${descriptor.sourceId};${retry.currentAttempt}`;
81
- return core_util_1.isNode
82
- ? await this.streamingIngestClient.ingestFromStream(new descriptors_1.StreamDescriptor((0, stream_array_1.default)([result])).merge(descriptor), props, sourceId)
83
- : await this.streamingIngestClient.ingestFromStream(descriptor, props, sourceId);
109
+ const sourceId = clientRequestId !== null && clientRequestId !== void 0 ? clientRequestId : `KNC.executeManagedStreamingIngest${isBlob ? "FromBlob" : "FromStream"};${descriptor.sourceId};${retry.currentAttempt}`;
110
+ if (isBlob) {
111
+ return this.streamingIngestClient.ingestFromBlob(descriptor, props, sourceId);
112
+ }
113
+ if (core_util_1.isNode) {
114
+ return await this.streamingIngestClient.ingestFromStream(new descriptors_1.StreamDescriptor((0, stream_array_1.default)([stream])).merge(descriptor), props, sourceId);
115
+ }
116
+ return await this.streamingIngestClient.ingestFromStream(descriptor, props, sourceId);
84
117
  }
85
118
  catch (err) {
86
119
  const oneApiError = err;
@@ -90,17 +123,9 @@ class KustoManagedStreamingIngestClient extends abstractKustoClient_1.AbstractKu
90
123
  await retry.backoff();
91
124
  }
92
125
  }
93
- result = core_util_1.isNode ? (0, stream_array_1.default)([result]) : descriptor.stream;
126
+ stream = isBlob ? undefined : core_util_1.isNode ? (0, stream_array_1.default)([stream]) : descriptor.stream;
94
127
  }
95
- return await this.queuedIngestClient.ingestFromStream(new descriptors_1.StreamDescriptor(result).merge(descriptor), ingestionProperties);
96
- }
97
- /**
98
- * Use string for Node.js and Blob in browser
99
- */
100
- async ingestFromFile(file, ingestionProperties) {
101
- this.ensureOpen();
102
- const stream = file instanceof fileDescriptor_1.FileDescriptor ? await (0, streamUtils_1.tryFileToBuffer)(file) : await (0, streamUtils_1.tryFileToBuffer)(new fileDescriptor_1.FileDescriptor(file));
103
- return await this.ingestFromStream(stream, ingestionProperties);
128
+ return null;
104
129
  }
105
130
  close() {
106
131
  if (!this._isClosed) {
@@ -33,19 +33,16 @@ class ResourceManager {
33
33
  this.baseSleepTimeSecs = 1;
34
34
  this.baseJitterSecs = 1;
35
35
  this.refreshPeriod = azure_kusto_data_1.TimeUtils.toMilliseconds(1, 0, 0);
36
+ this.refreshPeriodOnError = azure_kusto_data_1.TimeUtils.toMilliseconds(0, 10, 0);
36
37
  this.ingestClientResources = null;
37
38
  this.ingestClientResourcesLastUpdate = null;
38
39
  this.authorizationContext = null;
39
40
  this.authorizationContextLastUpdate = null;
40
41
  }
41
42
  async refreshIngestClientResources() {
42
- const now = Date.now();
43
- if (!this.ingestClientResources ||
44
- !this.ingestClientResourcesLastUpdate ||
45
- this.ingestClientResourcesLastUpdate + this.refreshPeriod <= now ||
46
- !this.ingestClientResources.valid()) {
47
- this.ingestClientResources = await this.getIngestClientResourcesFromService();
48
- this.ingestClientResourcesLastUpdate = now;
43
+ const error = await this.tryRefresh(false);
44
+ if (!this.ingestClientResources) {
45
+ throw new Error(`Failed to fetch ingestion resources from service. ${error === null || error === void 0 ? void 0 : error.message}.\n ${error === null || error === void 0 ? void 0 : error.stack}`);
49
46
  }
50
47
  return this.ingestClientResources;
51
48
  }
@@ -56,7 +53,11 @@ class ResourceManager {
56
53
  const cmd = `.get ingestion resources ${this.isBrowser ? `with (EnableBlobCors='true', EnableQueueCors='true', EnableTableCors='true')` : ""}`;
57
54
  const response = await this.kustoClient.execute("NetDefaultDB", cmd);
58
55
  const table = response.primaryResults[0];
59
- return new IngestClientResources(this.getResourceByName(table, "SecuredReadyForAggregationQueue"), this.getResourceByName(table, "FailedIngestionsQueue"), this.getResourceByName(table, "SuccessfulIngestionsQueue"), this.getResourceByName(table, "TempStorage"));
56
+ const resoures = new IngestClientResources(this.getResourceByName(table, "SecuredReadyForAggregationQueue"), this.getResourceByName(table, "FailedIngestionsQueue"), this.getResourceByName(table, "SuccessfulIngestionsQueue"), this.getResourceByName(table, "TempStorage"));
57
+ if (!resoures.valid()) {
58
+ throw new Error("Unexpected error occured - fetched data returned missing resource");
59
+ }
60
+ return resoures;
60
61
  }
61
62
  catch (error) {
62
63
  if (!(error instanceof azure_kusto_data_1.KustoDataErrors.ThrottlingError)) {
@@ -78,16 +79,34 @@ class ResourceManager {
78
79
  return result;
79
80
  }
80
81
  async refreshAuthorizationContext() {
82
+ const error = await this.tryRefresh(true);
83
+ if (this.authorizationContext == null) {
84
+ throw new Error(`Failed to fetch Authorization context from service. ${error === null || error === void 0 ? void 0 : error.message}.\n ${error === null || error === void 0 ? void 0 : error.stack}`);
85
+ }
86
+ return this.authorizationContext;
87
+ }
88
+ async tryRefresh(isAuthContextFetch) {
81
89
  var _a;
90
+ const resource = isAuthContextFetch ? (_a = this.authorizationContext) === null || _a === void 0 ? void 0 : _a.trim() : this.ingestClientResources;
91
+ const lastRefresh = isAuthContextFetch ? this.authorizationContextLastUpdate : this.ingestClientResourcesLastUpdate;
82
92
  const now = Date.now();
83
- if (!((_a = this.authorizationContext) === null || _a === void 0 ? void 0 : _a.trim()) || !this.authorizationContextLastUpdate || this.authorizationContextLastUpdate + this.refreshPeriod <= now) {
84
- this.authorizationContext = await this.getAuthorizationContextFromService();
85
- this.authorizationContextLastUpdate = now;
86
- if (this.authorizationContext == null) {
87
- throw new Error("Authorization context can't be null");
93
+ let error = null;
94
+ if (!resource || !lastRefresh || lastRefresh + this.refreshPeriod <= now) {
95
+ try {
96
+ if (isAuthContextFetch) {
97
+ this.authorizationContext = await this.getAuthorizationContextFromService();
98
+ this.authorizationContextLastUpdate = now;
99
+ }
100
+ else {
101
+ this.ingestClientResources = await this.getIngestClientResourcesFromService();
102
+ this.ingestClientResourcesLastUpdate = now;
103
+ }
104
+ }
105
+ catch (e) {
106
+ error = e;
88
107
  }
89
108
  }
90
- return this.authorizationContext;
109
+ return error;
91
110
  }
92
111
  async getAuthorizationContextFromService() {
93
112
  const retry = new retry_1.ExponentialRetry(ATTEMPT_COUNT, this.baseSleepTimeSecs, this.baseJitterSecs);
@@ -4,14 +4,11 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  const descriptors_1 = require("./descriptors");
6
6
  const fileDescriptor_browser_1 = require("./fileDescriptor.browser");
7
- const abstractKustoClient_1 = require("./abstractKustoClient");
8
- const azure_kusto_data_1 = require("azure-kusto-data");
9
7
  const streamUtils_browser_1 = require("./streamUtils.browser");
10
- class KustoStreamingIngestClient extends abstractKustoClient_1.AbstractKustoClient {
8
+ const streamingIngestClientBase_1 = require("./streamingIngestClientBase");
9
+ class KustoStreamingIngestClient extends streamingIngestClientBase_1.KustoStreamingIngestClientBase {
11
10
  constructor(kcsb, defaultProps) {
12
- super(defaultProps);
13
- this.kustoClient = new azure_kusto_data_1.Client(kcsb);
14
- this.defaultDatabase = this.kustoClient.defaultDatabase;
11
+ super(kcsb, defaultProps);
15
12
  }
16
13
  /**
17
14
  * Use Readable for Node.js and ArrayBuffer in browser
@@ -31,12 +28,6 @@ class KustoStreamingIngestClient extends abstractKustoClient_1.AbstractKustoClie
31
28
  const descriptor = file instanceof fileDescriptor_browser_1.FileDescriptor ? file : new fileDescriptor_browser_1.FileDescriptor(file);
32
29
  return this.ingestFromStream(await (0, streamUtils_browser_1.tryFileToBuffer)(descriptor), ingestionProperties);
33
30
  }
34
- close() {
35
- if (!this._isClosed) {
36
- this.kustoClient.close();
37
- }
38
- super.close();
39
- }
40
31
  }
41
32
  exports.default = KustoStreamingIngestClient;
42
33
  //# sourceMappingURL=streamingIngestClient.browser.js.map
@@ -8,14 +8,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  const descriptors_1 = require("./descriptors");
9
9
  const fileDescriptor_1 = require("./fileDescriptor");
10
10
  const zlib_1 = __importDefault(require("zlib"));
11
- const abstractKustoClient_1 = require("./abstractKustoClient");
12
- const azure_kusto_data_1 = require("azure-kusto-data");
13
11
  const streamUtils_1 = require("./streamUtils");
14
- class KustoStreamingIngestClient extends abstractKustoClient_1.AbstractKustoClient {
12
+ const streamingIngestClientBase_1 = require("./streamingIngestClientBase");
13
+ class KustoStreamingIngestClient extends streamingIngestClientBase_1.KustoStreamingIngestClientBase {
15
14
  constructor(kcsb, defaultProps) {
16
- super(defaultProps);
17
- this.kustoClient = new azure_kusto_data_1.Client(kcsb);
18
- this.defaultDatabase = this.kustoClient.defaultDatabase;
15
+ super(kcsb, defaultProps);
19
16
  }
20
17
  /**
21
18
  * Use Readable for Node.js and ArrayBuffer in browser
@@ -40,12 +37,6 @@ class KustoStreamingIngestClient extends abstractKustoClient_1.AbstractKustoClie
40
37
  const descriptor = file instanceof fileDescriptor_1.FileDescriptor ? file : new fileDescriptor_1.FileDescriptor(file);
41
38
  return this.ingestFromStream(await (0, streamUtils_1.fileToStream)(descriptor), ingestionProperties);
42
39
  }
43
- close() {
44
- if (!this._isClosed) {
45
- this.kustoClient.close();
46
- }
47
- super.close();
48
- }
49
40
  }
50
41
  exports.default = KustoStreamingIngestClient;
51
42
  //# sourceMappingURL=streamingIngestClient.js.map
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.KustoStreamingIngestClientBase = void 0;
6
+ const descriptors_1 = require("./descriptors");
7
+ const abstractKustoClient_1 = require("./abstractKustoClient");
8
+ const azure_kusto_data_1 = require("azure-kusto-data");
9
+ class KustoStreamingIngestClientBase extends abstractKustoClient_1.AbstractKustoClient {
10
+ constructor(kcsb, defaultProps) {
11
+ super(defaultProps);
12
+ this.kustoClient = new azure_kusto_data_1.Client(kcsb);
13
+ this.defaultDatabase = this.kustoClient.defaultDatabase;
14
+ }
15
+ async ingestFromBlob(blob, ingestionProperties, clientRequestId) {
16
+ var _a;
17
+ const props = this._getMergedProps(ingestionProperties);
18
+ const descriptor = blob instanceof descriptors_1.BlobDescriptor ? blob : new descriptors_1.BlobDescriptor(blob);
19
+ // No need to check blob size if it was given to us that it's not empty
20
+ await descriptor.fillSize();
21
+ return await this.kustoClient.executeStreamingIngest(props.database, props.table, undefined, props.format, (_a = props.ingestionMappingReference) !== null && _a !== void 0 ? _a : null, descriptor.path, clientRequestId);
22
+ }
23
+ close() {
24
+ if (!this._isClosed) {
25
+ this.kustoClient.close();
26
+ }
27
+ super.close();
28
+ }
29
+ }
30
+ exports.KustoStreamingIngestClientBase = KustoStreamingIngestClientBase;
31
+ //# sourceMappingURL=streamingIngestClientBase.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azure-kusto-ingest",
3
- "version": "5.0.3",
3
+ "version": "5.1.0",
4
4
  "description": "Azure Data Explorer Ingestion SDK",
5
5
  "module": "dist-esm/src/index.js",
6
6
  "types": "./types/src/index.d.ts",
@@ -61,7 +61,7 @@
61
61
  "@types/tmp": "^0.2.3",
62
62
  "@types/uuid": "^8.3.4",
63
63
  "@types/uuid-validate": "0.0.1",
64
- "azure-kusto-data": "^5.0.3",
64
+ "azure-kusto-data": "^5.1.0",
65
65
  "browserify-zlib": "0.2.0",
66
66
  "stream-array": "^1.1.2",
67
67
  "stream-browserify": "3.0.0",
@@ -74,5 +74,5 @@
74
74
  "@types/sinon": "^10.0.13",
75
75
  "assert": "^2.0.0"
76
76
  },
77
- "gitHead": "f8bf719744dfee126942678185a2315511ca0dfa"
77
+ "gitHead": "120a8d91fde4b0e520225e09895a28b085b85a7e"
78
78
  }
@@ -1,5 +1,5 @@
1
1
  import { IngestionProperties, IngestionPropertiesInput } from "./ingestionProperties";
2
- import { StreamDescriptor, FileDescriptorBase } from "./descriptors";
2
+ import { StreamDescriptor, FileDescriptorBase, BlobDescriptor } from "./descriptors";
3
3
  export declare abstract class AbstractKustoClient {
4
4
  defaultProps: IngestionProperties;
5
5
  defaultDatabase?: string;
@@ -8,6 +8,7 @@ export declare abstract class AbstractKustoClient {
8
8
  _getMergedProps(newProperties?: IngestionPropertiesInput): IngestionProperties;
9
9
  abstract ingestFromStream(stream: StreamDescriptor, ingestionProperties: IngestionPropertiesInput): Promise<any>;
10
10
  abstract ingestFromFile(file: FileDescriptorBase | string | Blob, ingestionProperties: IngestionPropertiesInput): Promise<any>;
11
+ abstract ingestFromBlob(blob: string | BlobDescriptor, ingestionProperties?: IngestionPropertiesInput): Promise<any>;
11
12
  close(): void;
12
13
  protected ensureOpen(): void;
13
14
  }
@@ -7,23 +7,25 @@ export declare enum CompressionType {
7
7
  None = ""
8
8
  }
9
9
  export declare const getSourceId: (sourceId: string | null) => string;
10
- export declare class StreamDescriptor {
11
- readonly stream: Readable | ArrayBuffer;
10
+ export declare abstract class AbstractDescriptor {
11
+ sourceId: string | null;
12
12
  size: number | null;
13
+ constructor(sourceId?: string | null, size?: number | null);
14
+ }
15
+ export declare class StreamDescriptor extends AbstractDescriptor {
16
+ readonly stream: Readable | ArrayBuffer;
13
17
  compressionType: CompressionType;
14
- sourceId: string;
15
18
  /**
16
19
  * Use Readable for Node.js and ArrayBuffer in browser
17
20
  */
18
- constructor(stream: Readable | ArrayBuffer, sourceId?: string | null, compressionType?: CompressionType);
21
+ constructor(stream: Readable | ArrayBuffer, sourceId?: string | null, compressionType?: CompressionType, size?: number | null);
19
22
  merge(other: StreamDescriptor): this;
20
23
  getCompressionSuffix(): string;
21
24
  }
22
- export declare class BlobDescriptor {
25
+ export declare class BlobDescriptor extends AbstractDescriptor {
23
26
  readonly path: string;
24
- size: number | null;
25
- sourceId: string;
26
27
  constructor(path: string, size?: number | null, sourceId?: string | null);
28
+ fillSize(): Promise<void>;
27
29
  }
28
30
  export interface FileDescriptorBase {
29
31
  size: number | null;
@@ -1,7 +1,6 @@
1
- import { CompressionType, FileDescriptorBase } from "./descriptors";
2
- export declare class FileDescriptor implements FileDescriptorBase {
1
+ import { AbstractDescriptor, CompressionType, FileDescriptorBase } from "./descriptors";
2
+ export declare class FileDescriptor extends AbstractDescriptor implements FileDescriptorBase {
3
3
  readonly file: Blob;
4
- readonly sourceId: string | null;
5
4
  readonly extension?: string | undefined;
6
5
  readonly name?: string | undefined;
7
6
  size: number | null;
@@ -1,19 +1,17 @@
1
- import { CompressionType, FileDescriptorBase } from "./descriptors";
1
+ import { AbstractDescriptor, CompressionType, FileDescriptorBase } from "./descriptors";
2
2
  /**
3
3
  * Describes a file to be ingested. Use string to describe a local path in Node.JS and Blob object in browsers
4
4
  */
5
- export declare class FileDescriptor implements FileDescriptorBase {
5
+ export declare class FileDescriptor extends AbstractDescriptor implements FileDescriptorBase {
6
6
  /**
7
7
  * Use string in Node.JS and Blob in browser
8
8
  */
9
9
  readonly file: string | Blob;
10
10
  readonly extension?: string | undefined;
11
11
  readonly name?: string | undefined;
12
- size: number | null;
13
12
  zipped: boolean;
14
13
  compressionType: CompressionType;
15
14
  cleanupTmp?: () => Promise<void>;
16
- sourceId: string;
17
15
  constructor(
18
16
  /**
19
17
  * Use string in Node.JS and Blob in browser
@@ -7,17 +7,20 @@ import { BlobDescriptor, CompressionType, StreamDescriptor } from "./descriptors
7
7
  import { FileDescriptor } from "./fileDescriptor";
8
8
  import { ApacheAvroColumnMapping, AvroColumnMapping, ColumnMapping, ConstantTransformation, CsvColumnMapping, FieldTransformation, JsonColumnMapping, OrcColumnMapping, ParquetColumnMapping, SStreamColumnMapping, W3CLogFileMapping } from "./columnMappings";
9
9
  export { Transformation as ColumnMappingTransformation } from "./columnMappings";
10
- export declare const IngestClient: typeof KustoIngestClient;
11
- export declare const StreamingIngestClient: typeof streamingIngestClient;
12
- export declare const ManagedStreamingIngestClient: typeof managedStreamingIngestClient;
13
- export declare const IngestStatusQueues: typeof KustoIngestStatusQueues;
10
+ export { KustoIngestClient as IngestClient };
11
+ export { streamingIngestClient as StreamingIngestClient };
12
+ export { managedStreamingIngestClient as ManagedStreamingIngestClient };
13
+ export { KustoIngestStatusQueues as IngestStatusQueues };
14
14
  export { IngestionProperties } from "./ingestionProperties";
15
+ /**
16
+ * @deprecated - import directly instead. Export const is not exporting type.
17
+ */
15
18
  export declare const IngestionDescriptors: {
16
19
  BlobDescriptor: typeof BlobDescriptor;
17
20
  FileDescriptor: typeof FileDescriptor;
18
21
  StreamDescriptor: typeof StreamDescriptor;
19
22
  };
20
- export { JsonColumnMapping, CsvColumnMapping, AvroColumnMapping, ParquetColumnMapping, OrcColumnMapping, W3CLogFileMapping, ValidationPolicy, ReportLevel, ReportMethod, ValidationImplications, ValidationOptions, DataFormat, IngestionMappingKind, CompressionType, ApacheAvroColumnMapping, SStreamColumnMapping, ConstantTransformation, FieldTransformation, ColumnMapping, };
23
+ export { JsonColumnMapping, CsvColumnMapping, AvroColumnMapping, ParquetColumnMapping, OrcColumnMapping, W3CLogFileMapping, ValidationPolicy, ReportLevel, ReportMethod, ValidationImplications, ValidationOptions, DataFormat, IngestionMappingKind, CompressionType, ApacheAvroColumnMapping, SStreamColumnMapping, ConstantTransformation, FieldTransformation, ColumnMapping, BlobDescriptor, StreamDescriptor, };
21
24
  /**
22
25
  * @deprecated - import directly instead
23
26
  */
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { IngestionPropertiesInput } from "./ingestionProperties";
3
- import { StreamDescriptor } from "./descriptors";
3
+ import { AbstractDescriptor, BlobDescriptor, StreamDescriptor } from "./descriptors";
4
4
  import { FileDescriptor } from "./fileDescriptor";
5
5
  import { AbstractKustoClient } from "./abstractKustoClient";
6
6
  import { KustoConnectionStringBuilder } from "azure-kusto-data";
@@ -34,11 +34,13 @@ declare class KustoManagedStreamingIngestClient extends AbstractKustoClient {
34
34
  /**
35
35
  * Use Readable for Node.js and ArrayBuffer in browser
36
36
  */
37
- ingestFromStream(stream: StreamDescriptor | Readable | ArrayBuffer, ingestionProperties?: IngestionPropertiesInput): Promise<any>;
37
+ ingestFromStream(stream: StreamDescriptor | Readable | ArrayBuffer, ingestionProperties?: IngestionPropertiesInput, clientRequestId?: string): Promise<any>;
38
38
  /**
39
39
  * Use string for Node.js and Blob in browser
40
40
  */
41
41
  ingestFromFile(file: FileDescriptor | string | Blob, ingestionProperties?: IngestionPropertiesInput): Promise<KustoResponseDataSet | QueueSendMessageResponse>;
42
+ ingestFromBlob(blob: string | BlobDescriptor, ingestionProperties?: IngestionPropertiesInput, clientRequestId?: string): Promise<any>;
43
+ streamWithRetries(length: number, descriptor: AbstractDescriptor, props?: IngestionPropertiesInput, clientRequestId?: string, stream?: Readable | ArrayBuffer): Promise<any>;
42
44
  close(): void;
43
45
  }
44
46
  export default KustoManagedStreamingIngestClient;
@@ -15,6 +15,7 @@ export declare class ResourceManager {
15
15
  readonly kustoClient: Client;
16
16
  readonly isBrowser: boolean;
17
17
  readonly refreshPeriod: number;
18
+ refreshPeriodOnError: number;
18
19
  ingestClientResources: IngestClientResources | null;
19
20
  ingestClientResourcesLastUpdate: number | null;
20
21
  authorizationContext: string | null;
@@ -28,6 +29,7 @@ export declare class ResourceManager {
28
29
  rows: () => any;
29
30
  }, resourceName: string): ResourceURI[];
30
31
  refreshAuthorizationContext(): Promise<string>;
32
+ tryRefresh(isAuthContextFetch: boolean): Promise<Error | null>;
31
33
  getAuthorizationContextFromService(): Promise<string>;
32
34
  getIngestionQueues(): Promise<ResourceURI[] | null>;
33
35
  getFailedIngestionsQueues(): Promise<ResourceURI[] | null>;
@@ -1,11 +1,10 @@
1
1
  import { IngestionPropertiesInput } from "./ingestionProperties";
2
2
  import { StreamDescriptor } from "./descriptors";
3
3
  import { FileDescriptor } from "./fileDescriptor.browser";
4
- import { AbstractKustoClient } from "./abstractKustoClient";
5
4
  import { KustoConnectionStringBuilder } from "azure-kusto-data";
6
5
  import { KustoResponseDataSet } from "azure-kusto-data/src/response";
7
- declare class KustoStreamingIngestClient extends AbstractKustoClient {
8
- private kustoClient;
6
+ import { KustoStreamingIngestClientBase } from "./streamingIngestClientBase";
7
+ declare class KustoStreamingIngestClient extends KustoStreamingIngestClientBase {
9
8
  constructor(kcsb: string | KustoConnectionStringBuilder, defaultProps?: IngestionPropertiesInput);
10
9
  /**
11
10
  * Use Readable for Node.js and ArrayBuffer in browser
@@ -15,7 +14,6 @@ declare class KustoStreamingIngestClient extends AbstractKustoClient {
15
14
  * Use string for Node.js and Blob in browser
16
15
  */
17
16
  ingestFromFile(file: FileDescriptor | Blob, ingestionProperties?: IngestionPropertiesInput): Promise<KustoResponseDataSet>;
18
- close(): void;
19
17
  }
20
18
  export default KustoStreamingIngestClient;
21
19
  //# sourceMappingURL=streamingIngestClient.browser.d.ts.map
@@ -2,12 +2,11 @@
2
2
  import { IngestionPropertiesInput } from "./ingestionProperties";
3
3
  import { StreamDescriptor } from "./descriptors";
4
4
  import { FileDescriptor } from "./fileDescriptor";
5
- import { AbstractKustoClient } from "./abstractKustoClient";
6
5
  import { KustoConnectionStringBuilder } from "azure-kusto-data";
7
6
  import { KustoResponseDataSet } from "azure-kusto-data/src/response";
8
7
  import { Readable } from "stream";
9
- declare class KustoStreamingIngestClient extends AbstractKustoClient {
10
- private kustoClient;
8
+ import { KustoStreamingIngestClientBase } from "./streamingIngestClientBase";
9
+ declare class KustoStreamingIngestClient extends KustoStreamingIngestClientBase {
11
10
  constructor(kcsb: string | KustoConnectionStringBuilder, defaultProps?: IngestionPropertiesInput);
12
11
  /**
13
12
  * Use Readable for Node.js and ArrayBuffer in browser
@@ -17,7 +16,6 @@ declare class KustoStreamingIngestClient extends AbstractKustoClient {
17
16
  * Use string for Node.js and Blob in browser
18
17
  */
19
18
  ingestFromFile(file: FileDescriptor | string | Blob, ingestionProperties?: IngestionPropertiesInput): Promise<KustoResponseDataSet>;
20
- close(): void;
21
19
  }
22
20
  export default KustoStreamingIngestClient;
23
21
  //# sourceMappingURL=streamingIngestClient.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { IngestionPropertiesInput } from "./ingestionProperties";
2
+ import { BlobDescriptor } from "./descriptors";
3
+ import { AbstractKustoClient } from "./abstractKustoClient";
4
+ import { Client as KustoClient, KustoConnectionStringBuilder } from "azure-kusto-data";
5
+ export declare abstract class KustoStreamingIngestClientBase extends AbstractKustoClient {
6
+ protected kustoClient: KustoClient;
7
+ constructor(kcsb: string | KustoConnectionStringBuilder, defaultProps?: IngestionPropertiesInput);
8
+ ingestFromBlob(blob: string | BlobDescriptor, ingestionProperties?: IngestionPropertiesInput, clientRequestId?: string): Promise<any>;
9
+ close(): void;
10
+ }
11
+ //# sourceMappingURL=streamingIngestClientBase.d.ts.map