azure-kusto-ingest 5.2.3 → 6.0.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.
Files changed (55) hide show
  1. package/dist-esm/src/abstractKustoClient.js +33 -0
  2. package/dist-esm/src/abstractKustoClient.js.map +1 -1
  3. package/dist-esm/src/descriptors.js +5 -1
  4. package/dist-esm/src/descriptors.js.map +1 -1
  5. package/dist-esm/src/fileDescriptor.browser.js +5 -2
  6. package/dist-esm/src/fileDescriptor.browser.js.map +1 -1
  7. package/dist-esm/src/fileDescriptor.js +5 -2
  8. package/dist-esm/src/fileDescriptor.js.map +1 -1
  9. package/dist-esm/src/index.js +4 -1
  10. package/dist-esm/src/index.js.map +1 -1
  11. package/dist-esm/src/ingestClient.browser.js +8 -11
  12. package/dist-esm/src/ingestClient.browser.js.map +1 -1
  13. package/dist-esm/src/ingestClient.js +8 -13
  14. package/dist-esm/src/ingestClient.js.map +1 -1
  15. package/dist-esm/src/ingestClientBase.js +93 -9
  16. package/dist-esm/src/ingestClientBase.js.map +1 -1
  17. package/dist-esm/src/ingestionBlobInfo.js +6 -1
  18. package/dist-esm/src/ingestionBlobInfo.js.map +1 -1
  19. package/dist-esm/src/ingestionProperties.js +15 -1
  20. package/dist-esm/src/ingestionProperties.js.map +1 -1
  21. package/dist-esm/src/ingestionResult.js +60 -0
  22. package/dist-esm/src/ingestionResult.js.map +1 -0
  23. package/dist-esm/src/managedStreamingIngestClient.js +4 -4
  24. package/dist-esm/src/managedStreamingIngestClient.js.map +1 -1
  25. package/dist-esm/src/rankedStorageAccount.js +73 -0
  26. package/dist-esm/src/rankedStorageAccount.js.map +1 -0
  27. package/dist-esm/src/rankedStorageAccountSet.js +61 -0
  28. package/dist-esm/src/rankedStorageAccountSet.js.map +1 -0
  29. package/dist-esm/src/resourceManager.js +108 -16
  30. package/dist-esm/src/resourceManager.js.map +1 -1
  31. package/dist-esm/src/streamingIngestClient.browser.js +2 -2
  32. package/dist-esm/src/streamingIngestClient.browser.js.map +1 -1
  33. package/dist-esm/src/streamingIngestClient.js +2 -2
  34. package/dist-esm/src/streamingIngestClient.js.map +1 -1
  35. package/dist-esm/src/streamingIngestClientBase.js +7 -1
  36. package/dist-esm/src/streamingIngestClientBase.js.map +1 -1
  37. package/package.json +7 -4
  38. package/types/src/abstractKustoClient.d.ts +3 -0
  39. package/types/src/descriptors.d.ts +1 -0
  40. package/types/src/fileDescriptor.browser.d.ts +3 -1
  41. package/types/src/fileDescriptor.d.ts +3 -1
  42. package/types/src/index.d.ts +2 -1
  43. package/types/src/ingestClient.browser.d.ts +4 -4
  44. package/types/src/ingestClient.d.ts +4 -4
  45. package/types/src/ingestClientBase.d.ts +10 -4
  46. package/types/src/ingestionBlobInfo.d.ts +5 -1
  47. package/types/src/ingestionProperties.d.ts +1 -0
  48. package/types/src/ingestionResult.d.ts +41 -0
  49. package/types/src/managedStreamingIngestClient.d.ts +5 -5
  50. package/types/src/rankedStorageAccount.d.ts +15 -0
  51. package/types/src/rankedStorageAccountSet.d.ts +18 -0
  52. package/types/src/resourceManager.d.ts +21 -4
  53. package/types/src/streamingIngestClient.browser.d.ts +1 -1
  54. package/types/src/streamingIngestClient.d.ts +1 -1
  55. package/types/src/streamingIngestClientBase.d.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ingestionBlobInfo.js","sourceRoot":"","sources":["../../src/ingestionBlobInfo.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,+BAAoC;AAIpC,MAAa,iBAAiB;IAc1B,YAAY,cAA8B,EAAE,mBAAwC,EAAE,cAA6B,IAAI;;QACnH,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC;QACpC,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,MAAA,mBAAmB,CAAC,QAAQ,mCAAI,IAAI,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,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C;QAED,IAAI,mBAAmB,CAAC,iBAAiB,EAAE;YACvC,oBAAoB,CAAC,iBAAiB,GAAG,mBAAmB,CAAC,iBAAiB,CAAC;SAClF;QAED,IAAI,mBAAmB,CAAC,uBAAuB,IAAI,mBAAmB,CAAC,uBAAuB,CAAC,MAAM,GAAG,CAAC,EAAE;YACvG,0BAA0B;YAC1B,oBAAoB,CAAC,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;SACpI;QAED,IAAI,mBAAmB,CAAC,yBAAyB,EAAE;YAC/C,oBAAoB,CAAC,yBAAyB,GAAG,mBAAmB,CAAC,yBAAyB,CAAC;SAClG;QAED,IAAI,mBAAmB,CAAC,oBAAoB,EAAE;YAC1C,oBAAoB,CAAC,oBAAoB,GAAG,mBAAmB,CAAC,oBAAoB,CAAC;SACxF;QAED,IAAI,mBAAmB,CAAC,gBAAgB,EAAE;YACtC,oBAAoB,CAAC,gBAAgB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC;SAChF;QAED,IAAI,mBAAmB,CAAC,MAAM,EAAE;YAC5B,oBAAoB,CAAC,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC;SAC5D;QACD,IAAI,mBAAmB,CAAC,iBAAiB,EAAE;YACvC,oBAAoB,CAAC,iBAAiB,GAAG,mBAAmB,CAAC,iBAAiB,CAAC;SAClF;QAED,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IACrD,CAAC;CACJ;AA3ED,8CA2EC;AAED,kBAAe,iBAAiB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { v4 as uuidv4 } from \"uuid\";\nimport { BlobDescriptor } from \"./descriptors\";\nimport IngestionProperties, { ReportLevel, ReportMethod } from \"./ingestionProperties\";\n\nexport class IngestionBlobInfo {\n BlobPath: string;\n RawDataSize: number | null;\n DatabaseName: string | null;\n TableName: string | null;\n RetainBlobOnSuccess: boolean;\n FlushImmediately: boolean;\n IgnoreSizeLimit: boolean;\n ReportLevel: ReportLevel | null;\n ReportMethod: ReportMethod | null;\n SourceMessageCreationTime: Date;\n Id: string;\n AdditionalProperties: { [additional: string]: any };\n\n constructor(blobDescriptor: BlobDescriptor, ingestionProperties: IngestionProperties, authContext: string | null = null) {\n this.BlobPath = blobDescriptor.path;\n this.RawDataSize = blobDescriptor.size;\n this.DatabaseName = ingestionProperties.database ?? null;\n this.TableName = ingestionProperties.table ?? null;\n this.RetainBlobOnSuccess = true;\n this.FlushImmediately = ingestionProperties.flushImmediately ?? false;\n this.IgnoreSizeLimit = false;\n this.ReportLevel = ingestionProperties.reportLevel ?? null;\n this.ReportMethod = ingestionProperties.reportMethod ?? null;\n this.SourceMessageCreationTime = new Date();\n this.Id = blobDescriptor.sourceId || uuidv4();\n\n const additionalProperties = ingestionProperties.additionalProperties || {};\n additionalProperties.authorizationContext = authContext;\n\n const tags: string[] = [];\n if (ingestionProperties.additionalTags) {\n tags.concat(ingestionProperties.additionalTags);\n }\n if (ingestionProperties.dropByTags) {\n tags.concat(ingestionProperties.dropByTags.map((t) => \"drop-by:\" + t));\n }\n if (ingestionProperties.ingestByTags) {\n tags.concat(ingestionProperties.ingestByTags.map((t) => \"ingest-by:\" + t));\n }\n\n if (tags && tags.length > 0) {\n additionalProperties.tags = tags;\n }\n\n if (ingestionProperties.ingestIfNotExists) {\n additionalProperties.ingestIfNotExists = ingestionProperties.ingestIfNotExists;\n }\n\n if (ingestionProperties.ingestionMappingColumns && ingestionProperties.ingestionMappingColumns.length > 0) {\n // server expects a string\n additionalProperties.ingestionMapping = JSON.stringify(ingestionProperties.ingestionMappingColumns.map((m) => m.toApiMapping()));\n }\n\n if (ingestionProperties.ingestionMappingReference) {\n additionalProperties.ingestionMappingReference = ingestionProperties.ingestionMappingReference;\n }\n\n if (ingestionProperties.ingestionMappingKind) {\n additionalProperties.ingestionMappingType = ingestionProperties.ingestionMappingKind;\n }\n\n if (ingestionProperties.validationPolicy) {\n additionalProperties.ValidationPolicy = ingestionProperties.validationPolicy;\n }\n\n if (ingestionProperties.format) {\n additionalProperties.format = ingestionProperties.format;\n }\n if (ingestionProperties.ignoreFirstRecord) {\n additionalProperties.ignoreFirstRecord = ingestionProperties.ignoreFirstRecord;\n }\n\n this.AdditionalProperties = additionalProperties;\n }\n}\n\nexport default IngestionBlobInfo;\n"]}
1
+ {"version":3,"file":"ingestionBlobInfo.js","sourceRoot":"","sources":["../../src/ingestionBlobInfo.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,+BAAoC;AAKpC,MAAa,iBAAiB;IAiB1B,YACI,cAA8B,EAC9B,mBAAwC,EACxC,cAA6B,IAAI,EACjC,wBAAuC,IAAI,EAC3C,0BAAyC,IAAI;;QATjD,2BAAsB,GAA6C,IAAI,CAAC;QACxE,0BAAqB,GAAmB,IAAI,CAAC;QAC7C,4BAAuB,GAAmB,IAAI,CAAC;QAS3C,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC;QACpC,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,MAAA,mBAAmB,CAAC,QAAQ,mCAAI,IAAI,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,MAAA,mBAAmB,CAAC,KAAK,mCAAI,IAAI,CAAC;QACnD,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,MAAA,mBAAmB,CAAC,gBAAgB,mCAAI,KAAK,CAAC;QACtE,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,MAAA,mBAAmB,CAAC,WAAW,mCAAI,IAAI,CAAC;QAC3D,IAAI,CAAC,YAAY,GAAG,MAAA,mBAAmB,CAAC,YAAY,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G,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;SACpI;QAED,IAAI,mBAAmB,CAAC,yBAAyB,EAAE;YAC/C,oBAAoB,CAAC,yBAAyB,GAAG,mBAAmB,CAAC,yBAAyB,CAAC;SAClG;QAED,IAAI,mBAAmB,CAAC,oBAAoB,EAAE;YAC1C,oBAAoB,CAAC,oBAAoB,GAAG,mBAAmB,CAAC,oBAAoB,CAAC;SACxF;QAED,IAAI,mBAAmB,CAAC,gBAAgB,EAAE;YACtC,oBAAoB,CAAC,gBAAgB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC;SAChF;QAED,IAAI,mBAAmB,CAAC,MAAM,EAAE;YAC5B,oBAAoB,CAAC,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC;SAC5D;QACD,IAAI,mBAAmB,CAAC,iBAAiB,EAAE;YACvC,oBAAoB,CAAC,iBAAiB,GAAG,mBAAmB,CAAC,iBAAiB,CAAC;SAClF;QAED,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IACrD,CAAC;CACJ;AAtFD,8CAsFC;AAED,kBAAe,iBAAiB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { v4 as uuidv4 } from \"uuid\";\nimport { BlobDescriptor } from \"./descriptors\";\nimport IngestionProperties, { ReportLevel, ReportMethod } from \"./ingestionProperties\";\nimport { IngestionStatusInTableDescription } from \"./ingestionResult\";\n\nexport class IngestionBlobInfo {\n BlobPath: string;\n RawDataSize: number | null;\n DatabaseName: string | null;\n TableName: string | null;\n RetainBlobOnSuccess: boolean;\n FlushImmediately: boolean;\n IgnoreSizeLimit: boolean;\n ReportLevel: ReportLevel | null;\n ReportMethod: ReportMethod | null;\n SourceMessageCreationTime: Date;\n Id: string;\n AdditionalProperties: { [additional: string]: any };\n IngestionStatusInTable: IngestionStatusInTableDescription | null = null;\n ApplicationForTracing?: string | null = null;\n ClientVersionForTracing?: string | null = null;\n\n constructor(\n blobDescriptor: BlobDescriptor,\n ingestionProperties: IngestionProperties,\n authContext: string | null = null,\n applicationForTracing: string | null = null,\n clientVersionForTracing: string | null = null\n ) {\n this.BlobPath = blobDescriptor.path;\n this.RawDataSize = blobDescriptor.size;\n this.DatabaseName = ingestionProperties.database ?? null;\n this.TableName = ingestionProperties.table ?? null;\n this.RetainBlobOnSuccess = true;\n this.FlushImmediately = ingestionProperties.flushImmediately ?? false;\n this.IgnoreSizeLimit = false;\n this.ReportLevel = ingestionProperties.reportLevel ?? null;\n this.ReportMethod = ingestionProperties.reportMethod ?? null;\n this.SourceMessageCreationTime = new Date();\n this.Id = blobDescriptor.sourceId || uuidv4();\n this.ApplicationForTracing = applicationForTracing;\n this.ClientVersionForTracing = clientVersionForTracing;\n\n const additionalProperties = ingestionProperties.additionalProperties || {};\n additionalProperties.authorizationContext = authContext;\n\n const tags: string[] = [];\n if (ingestionProperties.additionalTags) {\n tags.concat(ingestionProperties.additionalTags);\n }\n if (ingestionProperties.dropByTags) {\n tags.concat(ingestionProperties.dropByTags.map((t) => \"drop-by:\" + t));\n }\n if (ingestionProperties.ingestByTags) {\n tags.concat(ingestionProperties.ingestByTags.map((t) => \"ingest-by:\" + t));\n }\n\n if (tags && tags.length > 0) {\n additionalProperties.tags = tags;\n }\n\n if (ingestionProperties.ingestIfNotExists) {\n additionalProperties.ingestIfNotExists = ingestionProperties.ingestIfNotExists;\n }\n\n if (ingestionProperties.ingestionMappingColumns && ingestionProperties.ingestionMappingColumns.length > 0) {\n // server expects a string\n additionalProperties.ingestionMapping = JSON.stringify(ingestionProperties.ingestionMappingColumns.map((m) => m.toApiMapping()));\n }\n\n if (ingestionProperties.ingestionMappingReference) {\n additionalProperties.ingestionMappingReference = ingestionProperties.ingestionMappingReference;\n }\n\n if (ingestionProperties.ingestionMappingKind) {\n additionalProperties.ingestionMappingType = ingestionProperties.ingestionMappingKind;\n }\n\n if (ingestionProperties.validationPolicy) {\n additionalProperties.ValidationPolicy = ingestionProperties.validationPolicy;\n }\n\n if (ingestionProperties.format) {\n additionalProperties.format = ingestionProperties.format;\n }\n if (ingestionProperties.ignoreFirstRecord) {\n additionalProperties.ignoreFirstRecord = ingestionProperties.ignoreFirstRecord;\n }\n\n this.AdditionalProperties = additionalProperties;\n }\n}\n\nexport default IngestionBlobInfo;\n"]}
@@ -2,7 +2,7 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.IngestionProperties = exports.ReportMethod = exports.ReportLevel = exports.ValidationPolicy = exports.ValidationImplications = exports.ValidationOptions = exports.dataFormatMappingKind = exports.IngestionMappingKind = exports.DataFormat = void 0;
5
+ exports.shouldCompressFileByFormat = exports.IngestionProperties = exports.ReportMethod = exports.ReportLevel = exports.ValidationPolicy = exports.ValidationImplications = exports.ValidationOptions = exports.dataFormatMappingKind = exports.IngestionMappingKind = exports.DataFormat = void 0;
6
6
  const errors_1 = require("./errors");
7
7
  /**
8
8
  * Data formats supported for Kusto ingestion.
@@ -209,6 +209,9 @@ class IngestionProperties {
209
209
  }
210
210
  }
211
211
  }
212
+ if (this.reportMethod !== ReportMethod.Queue && this.reportLevel === ReportLevel.FailuresOnly) {
213
+ throw new errors_1.IngestionPropertiesValidationError("ReportLevel.FailuresOnly is not supported with ReportMethod.Table");
214
+ }
212
215
  }
213
216
  merge(extraProps) {
214
217
  const merged = new IngestionProperties(this);
@@ -238,5 +241,16 @@ class IngestionProperties {
238
241
  }
239
242
  }
240
243
  exports.IngestionProperties = IngestionProperties;
244
+ function shouldCompressFileByFormat(ingestionProperties) {
245
+ if (!ingestionProperties) {
246
+ ingestionProperties = {};
247
+ }
248
+ return !(ingestionProperties.format === "avro" ||
249
+ ingestionProperties.format === "parquet" ||
250
+ ingestionProperties.format === "orc" ||
251
+ ingestionProperties.format === "apacheavro" ||
252
+ ingestionProperties.format === "sstream");
253
+ }
254
+ exports.shouldCompressFileByFormat = shouldCompressFileByFormat;
241
255
  exports.default = IngestionProperties;
242
256
  //# sourceMappingURL=ingestionProperties.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ingestionProperties.js","sourceRoot":"","sources":["../../src/ingestionProperties.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,qCAA8D;AAG9D;;GAEG;AACH,IAAY,UAqEX;AArED,WAAY,UAAU;IAClB;;OAEG;IACH,yBAAW,CAAA;IACX;;OAEG;IACH,yBAAW,CAAA;IACX;;OAEG;IACH,2BAAa,CAAA;IACb;;OAEG;IACH,6BAAe,CAAA;IACf;;OAEG;IACH,yBAAW,CAAA;IACX;;OAEG;IACH,yBAAW,CAAA;IACX;;OAEG;IACH,yBAAW,CAAA;IACX;;OAEG;IACH,2BAAa,CAAA;IACb;;OAEG;IACH,2BAAa,CAAA;IACb;;OAEG;IACH,uCAAyB,CAAA;IACzB;;OAEG;IACH,qCAAuB,CAAA;IACvB;;OAEG;IACH,2BAAa,CAAA;IACb;;OAEG;IACH,iCAAmB,CAAA;IACnB;;OAEG;IACH,iCAAmB,CAAA;IACnB;;OAEG;IACH,yBAAW,CAAA;IACX;;OAEG;IACH,uCAAyB,CAAA;IACzB;;OAEG;IACH,uCAAyB,CAAA;AAC7B,CAAC,EArEW,UAAU,0BAAV,UAAU,QAqErB;AAED,IAAY,oBASX;AATD,WAAY,oBAAoB;IAC5B,mCAAW,CAAA;IACX,qCAAa,CAAA;IACb,qCAAa,CAAA;IACb,2CAAmB,CAAA;IACnB,2CAAmB,CAAA;IACnB,mCAAW,CAAA;IACX,iDAAyB,CAAA;IACzB,iDAAyB,CAAA;AAC7B,CAAC,EATW,oBAAoB,oCAApB,oBAAoB,QAS/B;AAEM,MAAM,qBAAqB,GAAG,CAAC,UAAsB,EAAwB,EAAE;IAClF,QAAQ,UAAU,EAAE;QAChB,KAA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ourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { IngestionPropertiesValidationError } from \"./errors\";\nimport { ColumnMapping } from \"./columnMappings\";\n\n/**\n * Data formats supported for Kusto ingestion.\n */\nexport enum DataFormat {\n /**\n * Comma-separated value.\n */\n CSV = \"csv\",\n /**\n * Tab-separated value.\n */\n TSV = \"tsv\",\n /**\n * Semicolon-separated value (the unique Azure Storage log format).\n */\n SCSV = \"scsv\",\n /**\n * Start-Of-Header (CTRL-A)-separated value.\n */\n SOHSV = \"sohsv\",\n /**\n * Pipeline-separated value (used by Cosmos).\n */\n PSV = \"psv\",\n /**\n * Each record is a line and has just one field.\n */\n TXT = \"txt\",\n /**\n * Whole stream is a single record with a single field.\n */\n RAW = \"raw\",\n /**\n * Tab-separated value with '\\' escaping character.\n */\n TSVE = \"tsve\",\n /**\n * Data is in a JSON format, each line is record with a single JSON value.\n */\n JSON = \"json\",\n /**\n * Data stream holds a single JSON value -- newlines are regular whitespace.\n */\n SINGLEJSON = \"singlejson\",\n /**\n * The data stream is a concatenation of JSON documents (property bags all).\n */\n MULTIJSON = \"multijson\",\n /**\n * Avro format.\n */\n AVRO = \"avro\",\n /**\n * Parquet format.\n */\n PARQUET = \"parquet\",\n /**\n * Microsoft Cosmos structured streams format\n */\n SSTREAM = \"sstream\",\n /**\n * The Optimized Row Columnar (ORC)\n */\n ORC = \"orc\",\n /**\n * Avro format for ingesting through avro2json.\n */\n APACHEAVRO = \"apacheavro\",\n /**\n * W3C Extended Log File format.\n */\n W3CLogFile = \"w3clogfile\",\n}\n\nexport enum IngestionMappingKind {\n CSV = \"Csv\",\n JSON = \"Json\",\n AVRO = \"Avro\",\n PARQUET = \"Parquet\",\n SSTREAM = \"SStream\",\n ORC = \"orc\",\n APACHEAVRO = \"ApacheAvro\",\n W3CLOGFILE = \"W3CLogFile\",\n}\n\nexport const dataFormatMappingKind = (dataFormat: DataFormat): IngestionMappingKind => {\n switch (dataFormat) {\n case DataFormat.CSV:\n return IngestionMappingKind.CSV;\n case DataFormat.TSV:\n return IngestionMappingKind.CSV;\n case DataFormat.SCSV:\n return IngestionMappingKind.CSV;\n case DataFormat.SOHSV:\n return IngestionMappingKind.CSV;\n case DataFormat.PSV:\n return IngestionMappingKind.CSV;\n case DataFormat.TXT:\n return IngestionMappingKind.CSV;\n case DataFormat.RAW:\n return IngestionMappingKind.CSV;\n case DataFormat.TSVE:\n return IngestionMappingKind.CSV;\n case DataFormat.JSON:\n return IngestionMappingKind.JSON;\n case DataFormat.SINGLEJSON:\n return IngestionMappingKind.JSON;\n case DataFormat.MULTIJSON:\n return IngestionMappingKind.JSON;\n case DataFormat.AVRO:\n return IngestionMappingKind.AVRO;\n case DataFormat.PARQUET:\n return IngestionMappingKind.PARQUET;\n case DataFormat.SSTREAM:\n return IngestionMappingKind.SSTREAM;\n case DataFormat.ORC:\n return IngestionMappingKind.ORC;\n case DataFormat.APACHEAVRO:\n return IngestionMappingKind.APACHEAVRO;\n case DataFormat.W3CLogFile:\n return IngestionMappingKind.W3CLOGFILE;\n default:\n throw new IngestionPropertiesValidationError(`Unsupported data format: ${dataFormat}`);\n }\n};\n\nexport enum ValidationOptions {\n DoNotValidate = 0,\n ValidateCsvInputConstantColumns = 1,\n ValidateCsvInputColumnLevelOnly = 2,\n}\n\nexport enum ValidationImplications {\n Fail = 0,\n BestEffort = 1,\n}\n\nexport class ValidationPolicy {\n constructor(\n readonly validationOptions: ValidationOptions = ValidationOptions.DoNotValidate,\n readonly validationImplications: ValidationImplications = ValidationImplications.BestEffort\n ) {}\n\n toJSON(): Record<string, number> {\n return {\n ValidationOptions: this.validationOptions,\n ValidationImplications: this.validationImplications,\n };\n }\n}\n\nexport enum ReportLevel {\n FailuresOnly = 0,\n DoNotReport = 1,\n FailuresAndSuccesses = 2,\n}\n\nexport enum ReportMethod {\n Queue = 0,\n Table,\n QueueAndTable,\n}\n\nexport interface IngestionPropertiesFields {\n database?: string;\n table?: string;\n format?: DataFormat;\n /**\n * @deprecated. Use ingestionMappingColumns instead.\n */\n ingestionMapping?: ColumnMapping[];\n ingestionMappingColumns?: ColumnMapping[];\n ingestionMappingReference?: string;\n /**\n * @deprecated. Use ingestionMappingKind instead.\n */\n ingestionMappingType?: IngestionMappingKind;\n ingestionMappingKind?: IngestionMappingKind;\n additionalTags?: string;\n ingestIfNotExists?: string;\n ingestByTags?: string[];\n dropByTags?: string[];\n flushImmediately?: boolean;\n ignoreFirstRecord?: boolean;\n reportLevel?: ReportLevel;\n reportMethod?: ReportMethod;\n validationPolicy?: ValidationPolicy;\n additionalProperties?: { [additional: string]: any } | null;\n}\n\n// This trick lets us avoid duplicating all the properties from the interface. See https://github.com/microsoft/TypeScript/issues/3407\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface IngestionProperties extends IngestionPropertiesFields {}\n\n// eslint-disable-next-line no-redeclare\nexport class IngestionProperties {\n constructor(data: Partial<IngestionPropertiesFields>) {\n Object.assign(this, data);\n }\n\n validate() {\n if (!this.database) throw new IngestionPropertiesValidationError(\"Must define a target database\");\n if (!this.table) throw new IngestionPropertiesValidationError(\"Must define a target table\");\n if (!this.format) throw new IngestionPropertiesValidationError(\"Must define a data format\");\n\n if (this.ingestionMappingType && !this.ingestionMappingKind) {\n this.ingestionMappingKind = this.ingestionMappingType;\n }\n\n if (this.ingestionMapping && !this.ingestionMappingColumns) {\n this.ingestionMappingColumns = this.ingestionMapping;\n }\n\n if (!this.ingestionMappingColumns && !this.ingestionMappingReference) {\n if (this.ingestionMappingKind) {\n throw new IngestionPropertiesValidationError(\n \"Cannot define ingestionMappingKind without either ingestionMappingColumns or\" + \" ingestionMappingReference\"\n );\n }\n } else {\n const mappingKind = dataFormatMappingKind(this.format);\n if (this.ingestionMappingKind && this.ingestionMappingKind !== mappingKind) {\n throw new IngestionPropertiesValidationError(\n `Mapping kind '${this.ingestionMappingKind}' does not match format '${this.format}' (should be '${mappingKind}')`\n );\n }\n if (this.ingestionMappingColumns) {\n if (this.ingestionMappingReference) {\n throw new IngestionPropertiesValidationError(\"Cannot define both ingestionMappingColumns and ingestionMappingReference\");\n }\n\n if (this.ingestionMappingColumns.length === 0) {\n throw new IngestionPropertiesValidationError(\"Must define at least one column mapping\");\n }\n\n const wrongMappings = this.ingestionMappingColumns\n .filter((m) => m.mappingKind !== mappingKind)\n .map(\n (m) => `Mapping kind mismatch for column '${m.columnName}' - expected data format kind - '${mappingKind}', but was '${m.mappingKind}'`\n );\n if (wrongMappings.length > 0) {\n throw new IngestionPropertiesValidationError(`Invalid columns:\\n${wrongMappings.join(\"\\n\")}`);\n }\n }\n }\n }\n\n merge(extraProps: IngestionPropertiesInput) {\n const merged = new IngestionProperties(this);\n\n if (!extraProps) {\n return merged;\n }\n\n const assign = <K extends keyof IngestionPropertiesFields, V extends IngestionPropertiesFields[K]>(\n obj: IngestionPropertiesFields,\n prop: K,\n value: V\n ) => {\n obj[prop] = value;\n };\n\n for (const key of Object.keys(extraProps) as (keyof IngestionPropertiesFields)[]) {\n if (extraProps[key]) {\n assign(merged, key, extraProps[key]);\n }\n }\n\n return merged;\n }\n\n setDefaults() {\n if (!this.format) {\n this.format = DataFormat.CSV;\n }\n if (!this.reportLevel) {\n this.reportLevel = ReportLevel.FailuresOnly;\n }\n if (!this.reportMethod) {\n this.reportMethod = ReportMethod.Queue;\n }\n }\n}\n\nexport type IngestionPropertiesInput = IngestionProperties | IngestionPropertiesFields | null | undefined;\n\nexport default IngestionProperties;\n"]}
1
+ {"version":3,"file":"ingestionProperties.js","sourceRoot":"","sources":["../../src/ingestionProperties.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,qCAA8D;AAG9D;;GAEG;AACH,IAAY,UAqEX;AArED,WAAY,UAAU;IAClB;;OAEG;IACH,yBAAW,CAAA;IACX;;OAEG;IACH,yBAAW,CAAA;IACX;;OAEG;IACH,2BAAa,CAAA;IACb;;OAEG;IACH,6BAAe,CAAA;IACf;;OAEG;IACH,yBAAW,CAAA;IACX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gEAWC;AAED,kBAAe,mBAAmB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { IngestionPropertiesValidationError } from \"./errors\";\nimport { ColumnMapping } from \"./columnMappings\";\n\n/**\n * Data formats supported for Kusto ingestion.\n */\nexport enum DataFormat {\n /**\n * Comma-separated value.\n */\n CSV = \"csv\",\n /**\n * Tab-separated value.\n */\n TSV = \"tsv\",\n /**\n * Semicolon-separated value (the unique Azure Storage log format).\n */\n SCSV = \"scsv\",\n /**\n * Start-Of-Header (CTRL-A)-separated value.\n */\n SOHSV = \"sohsv\",\n /**\n * Pipeline-separated value (used by Cosmos).\n */\n PSV = \"psv\",\n /**\n * Each record is a line and has just one field.\n */\n TXT = \"txt\",\n /**\n * Whole stream is a single record with a single field.\n */\n RAW = \"raw\",\n /**\n * Tab-separated value with '\\' escaping character.\n */\n TSVE = \"tsve\",\n /**\n * Data is in a JSON format, each line is record with a single JSON value.\n */\n JSON = \"json\",\n /**\n * Data stream holds a single JSON value -- newlines are regular whitespace.\n */\n SINGLEJSON = \"singlejson\",\n /**\n * The data stream is a concatenation of JSON documents (property bags all).\n */\n MULTIJSON = \"multijson\",\n /**\n * Avro format.\n */\n AVRO = \"avro\",\n /**\n * Parquet format.\n */\n PARQUET = \"parquet\",\n /**\n * Microsoft Cosmos structured streams format\n */\n SSTREAM = \"sstream\",\n /**\n * The Optimized Row Columnar (ORC)\n */\n ORC = \"orc\",\n /**\n * Avro format for ingesting through avro2json.\n */\n APACHEAVRO = \"apacheavro\",\n /**\n * W3C Extended Log File format.\n */\n W3CLogFile = \"w3clogfile\",\n}\n\nexport enum IngestionMappingKind {\n CSV = \"Csv\",\n JSON = \"Json\",\n AVRO = \"Avro\",\n PARQUET = \"Parquet\",\n SSTREAM = \"SStream\",\n ORC = \"orc\",\n APACHEAVRO = \"ApacheAvro\",\n W3CLOGFILE = \"W3CLogFile\",\n}\n\nexport const dataFormatMappingKind = (dataFormat: DataFormat): IngestionMappingKind => {\n switch (dataFormat) {\n case DataFormat.CSV:\n return IngestionMappingKind.CSV;\n case DataFormat.TSV:\n return IngestionMappingKind.CSV;\n case DataFormat.SCSV:\n return IngestionMappingKind.CSV;\n case DataFormat.SOHSV:\n return IngestionMappingKind.CSV;\n case DataFormat.PSV:\n return IngestionMappingKind.CSV;\n case DataFormat.TXT:\n return IngestionMappingKind.CSV;\n case DataFormat.RAW:\n return IngestionMappingKind.CSV;\n case DataFormat.TSVE:\n return IngestionMappingKind.CSV;\n case DataFormat.JSON:\n return IngestionMappingKind.JSON;\n case DataFormat.SINGLEJSON:\n return IngestionMappingKind.JSON;\n case DataFormat.MULTIJSON:\n return IngestionMappingKind.JSON;\n case DataFormat.AVRO:\n return IngestionMappingKind.AVRO;\n case DataFormat.PARQUET:\n return IngestionMappingKind.PARQUET;\n case DataFormat.SSTREAM:\n return IngestionMappingKind.SSTREAM;\n case DataFormat.ORC:\n return IngestionMappingKind.ORC;\n case DataFormat.APACHEAVRO:\n return IngestionMappingKind.APACHEAVRO;\n case DataFormat.W3CLogFile:\n return IngestionMappingKind.W3CLOGFILE;\n default:\n throw new IngestionPropertiesValidationError(`Unsupported data format: ${dataFormat}`);\n }\n};\n\nexport enum ValidationOptions {\n DoNotValidate = 0,\n ValidateCsvInputConstantColumns = 1,\n ValidateCsvInputColumnLevelOnly = 2,\n}\n\nexport enum ValidationImplications {\n Fail = 0,\n BestEffort = 1,\n}\n\nexport class ValidationPolicy {\n constructor(\n readonly validationOptions: ValidationOptions = ValidationOptions.DoNotValidate,\n readonly validationImplications: ValidationImplications = ValidationImplications.BestEffort\n ) {}\n\n toJSON(): Record<string, number> {\n return {\n ValidationOptions: this.validationOptions,\n ValidationImplications: this.validationImplications,\n };\n }\n}\n\nexport enum ReportLevel {\n FailuresOnly = 0,\n DoNotReport = 1,\n FailuresAndSuccesses = 2,\n}\n\nexport enum ReportMethod {\n Queue = 0,\n Table,\n QueueAndTable,\n}\n\nexport interface IngestionPropertiesFields {\n database?: string;\n table?: string;\n format?: DataFormat;\n /**\n * @deprecated. Use ingestionMappingColumns instead.\n */\n ingestionMapping?: ColumnMapping[];\n ingestionMappingColumns?: ColumnMapping[];\n ingestionMappingReference?: string;\n /**\n * @deprecated. Use ingestionMappingKind instead.\n */\n ingestionMappingType?: IngestionMappingKind;\n ingestionMappingKind?: IngestionMappingKind;\n additionalTags?: string;\n ingestIfNotExists?: string;\n ingestByTags?: string[];\n dropByTags?: string[];\n flushImmediately?: boolean;\n ignoreFirstRecord?: boolean;\n reportLevel?: ReportLevel;\n reportMethod?: ReportMethod;\n validationPolicy?: ValidationPolicy;\n additionalProperties?: { [additional: string]: any } | null;\n}\n\n// This trick lets us avoid duplicating all the properties from the interface. See https://github.com/microsoft/TypeScript/issues/3407\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface IngestionProperties extends IngestionPropertiesFields {}\n\n// eslint-disable-next-line no-redeclare\nexport class IngestionProperties {\n constructor(data: Partial<IngestionPropertiesFields>) {\n Object.assign(this, data);\n }\n\n validate() {\n if (!this.database) throw new IngestionPropertiesValidationError(\"Must define a target database\");\n if (!this.table) throw new IngestionPropertiesValidationError(\"Must define a target table\");\n if (!this.format) throw new IngestionPropertiesValidationError(\"Must define a data format\");\n\n if (this.ingestionMappingType && !this.ingestionMappingKind) {\n this.ingestionMappingKind = this.ingestionMappingType;\n }\n\n if (this.ingestionMapping && !this.ingestionMappingColumns) {\n this.ingestionMappingColumns = this.ingestionMapping;\n }\n\n if (!this.ingestionMappingColumns && !this.ingestionMappingReference) {\n if (this.ingestionMappingKind) {\n throw new IngestionPropertiesValidationError(\n \"Cannot define ingestionMappingKind without either ingestionMappingColumns or\" + \" ingestionMappingReference\"\n );\n }\n } else {\n const mappingKind = dataFormatMappingKind(this.format);\n if (this.ingestionMappingKind && this.ingestionMappingKind !== mappingKind) {\n throw new IngestionPropertiesValidationError(\n `Mapping kind '${this.ingestionMappingKind}' does not match format '${this.format}' (should be '${mappingKind}')`\n );\n }\n if (this.ingestionMappingColumns) {\n if (this.ingestionMappingReference) {\n throw new IngestionPropertiesValidationError(\"Cannot define both ingestionMappingColumns and ingestionMappingReference\");\n }\n\n if (this.ingestionMappingColumns.length === 0) {\n throw new IngestionPropertiesValidationError(\"Must define at least one column mapping\");\n }\n\n const wrongMappings = this.ingestionMappingColumns\n .filter((m) => m.mappingKind !== mappingKind)\n .map(\n (m) => `Mapping kind mismatch for column '${m.columnName}' - expected data format kind - '${mappingKind}', but was '${m.mappingKind}'`\n );\n if (wrongMappings.length > 0) {\n throw new IngestionPropertiesValidationError(`Invalid columns:\\n${wrongMappings.join(\"\\n\")}`);\n }\n }\n }\n\n if (this.reportMethod !== ReportMethod.Queue && this.reportLevel === ReportLevel.FailuresOnly) {\n throw new IngestionPropertiesValidationError(\"ReportLevel.FailuresOnly is not supported with ReportMethod.Table\");\n }\n }\n\n merge(extraProps: IngestionPropertiesInput) {\n const merged = new IngestionProperties(this);\n\n if (!extraProps) {\n return merged;\n }\n\n const assign = <K extends keyof IngestionPropertiesFields, V extends IngestionPropertiesFields[K]>(\n obj: IngestionPropertiesFields,\n prop: K,\n value: V\n ) => {\n obj[prop] = value;\n };\n\n for (const key of Object.keys(extraProps) as (keyof IngestionPropertiesFields)[]) {\n if (extraProps[key]) {\n assign(merged, key, extraProps[key]);\n }\n }\n\n return merged;\n }\n\n setDefaults() {\n if (!this.format) {\n this.format = DataFormat.CSV;\n }\n if (!this.reportLevel) {\n this.reportLevel = ReportLevel.FailuresOnly;\n }\n if (!this.reportMethod) {\n this.reportMethod = ReportMethod.Queue;\n }\n }\n}\n\nexport type IngestionPropertiesInput = IngestionProperties | IngestionPropertiesFields | null | undefined;\n\nexport function shouldCompressFileByFormat(ingestionProperties?: IngestionPropertiesInput): boolean {\n if (!ingestionProperties) {\n ingestionProperties = {};\n }\n return !(\n ingestionProperties.format === \"avro\" ||\n ingestionProperties.format === \"parquet\" ||\n ingestionProperties.format === \"orc\" ||\n ingestionProperties.format === \"apacheavro\" ||\n ingestionProperties.format === \"sstream\"\n );\n}\n\nexport default IngestionProperties;\n"]}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.IngestionStatusInTableDescription = exports.IngestionStatusResult = exports.TableReportIngestionResult = exports.OperationStatus = exports.putRecordInTable = void 0;
6
+ const retry_1 = require("./retry");
7
+ const resourceManager_1 = require("./resourceManager");
8
+ const putRecordInTable = async (tableClient, entity) => {
9
+ const retry = new retry_1.ExponentialRetry(3, 1, 1);
10
+ while (retry.shouldTry()) {
11
+ try {
12
+ await tableClient.createEntity(entity);
13
+ }
14
+ catch (ex) {
15
+ await retry.backoff();
16
+ }
17
+ }
18
+ };
19
+ exports.putRecordInTable = putRecordInTable;
20
+ var OperationStatus;
21
+ (function (OperationStatus) {
22
+ OperationStatus["Pending"] = "Pending";
23
+ OperationStatus["Succeede"] = "Succeeded";
24
+ OperationStatus["Failed"] = "Failed";
25
+ OperationStatus["Queued"] = "Queued";
26
+ OperationStatus["Skipped"] = "Skipped";
27
+ OperationStatus["PartiallySucceeded"] = "PartiallySucceeded";
28
+ })(OperationStatus || (exports.OperationStatus = OperationStatus = {}));
29
+ class TableReportIngestionResult {
30
+ constructor(ingestionStatusInTableDescription, tableClient = null) {
31
+ this.ingestionStatusInTableDescription = ingestionStatusInTableDescription;
32
+ this.tableClient = tableClient;
33
+ }
34
+ async getIngestionStatusCollection() {
35
+ if (!this.tableClient) {
36
+ this.tableClient = (0, resourceManager_1.createStatusTableClient)(this.ingestionStatusInTableDescription.tableConnectionString);
37
+ }
38
+ return await this.tableClient.getEntity(this.ingestionStatusInTableDescription.partitionKey, this.ingestionStatusInTableDescription.rowKey);
39
+ }
40
+ }
41
+ exports.TableReportIngestionResult = TableReportIngestionResult;
42
+ class IngestionStatusResult {
43
+ constructor(ingestionStatus) {
44
+ this.ingestionStatus = ingestionStatus;
45
+ this.ingestionStatus = ingestionStatus;
46
+ }
47
+ getIngestionStatusCollection() {
48
+ return Promise.resolve(this.ingestionStatus);
49
+ }
50
+ }
51
+ exports.IngestionStatusResult = IngestionStatusResult;
52
+ class IngestionStatusInTableDescription {
53
+ constructor(tableConnectionString, partitionKey, rowKey) {
54
+ this.tableConnectionString = tableConnectionString;
55
+ this.partitionKey = partitionKey;
56
+ this.rowKey = rowKey;
57
+ }
58
+ }
59
+ exports.IngestionStatusInTableDescription = IngestionStatusInTableDescription;
60
+ //# sourceMappingURL=ingestionResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingestionResult.js","sourceRoot":"","sources":["../../src/ingestionResult.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,mCAA2C;AAC3C,uDAA4D;AASrD,MAAM,gBAAgB,GAAG,KAAK,EAAE,WAAwB,EAAE,MAAoC,EAAiB,EAAE;IACpH,MAAM,KAAK,GAAG,IAAI,wBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,OAAO,KAAK,CAAC,SAAS,EAAE,EAAE;QACtB,IAAI;YACA,MAAM,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;SAC1C;QAAC,OAAO,EAAE,EAAE;YACT,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;SACzB;KACJ;AACL,CAAC,CAAC;AATW,QAAA,gBAAgB,oBAS3B;AAEF,IAAY,eAOX;AAPD,WAAY,eAAe;IACvB,sCAAmB,CAAA;IACnB,yCAAsB,CAAA;IACtB,oCAAiB,CAAA;IACjB,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;IACnB,4DAAyC,CAAA;AAC7C,CAAC,EAPW,eAAe,+BAAf,eAAe,QAO1B;AAED,MAAa,0BAA0B;IACnC,YAA2B,iCAAoE,EAAS,cAAkC,IAAI;QAAnH,sCAAiC,GAAjC,iCAAiC,CAAmC;QAAS,gBAAW,GAAX,WAAW,CAA2B;IAAG,CAAC;IAE3I,KAAK,CAAC,4BAA4B;QACrC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACnB,IAAI,CAAC,WAAW,GAAG,IAAA,yCAAuB,EAAC,IAAI,CAAC,iCAAiC,CAAC,qBAAqB,CAAC,CAAC;SAC5G;QAED,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CACnC,IAAI,CAAC,iCAAiC,CAAC,YAAY,EACnD,IAAI,CAAC,iCAAiC,CAAC,MAAM,CAChD,CAAC;IACN,CAAC;CACJ;AAbD,gEAaC;AAED,MAAa,qBAAqB;IAC9B,YAAoB,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;QAChD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IAEM,4BAA4B;QAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACjD,CAAC;CACJ;AARD,sDAQC;AAED,MAAa,iCAAiC;IAC1C,YAAmB,qBAA6B,EAAS,YAAoB,EAAS,MAAc;QAAjF,0BAAqB,GAArB,qBAAqB,CAAQ;QAAS,iBAAY,GAAZ,YAAY,CAAQ;QAAS,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;CAC3G;AAFD,8EAEC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { TableClient, TableEntity } from \"@azure/data-tables\";\nimport { ExponentialRetry } from \"./retry\";\nimport { createStatusTableClient } from \"./resourceManager\";\nexport interface IngestionResult {\n /// <summary>\n /// Retrieves the detailed ingestion status of\n /// all data ingestion operations into Kusto associated with this IKustoIngestionResult instance.\n /// </summary>\n getIngestionStatusCollection(): Promise<IngestionStatus>;\n}\n\nexport const putRecordInTable = async (tableClient: TableClient, entity: TableEntity<IngestionStatus>): Promise<void> => {\n const retry = new ExponentialRetry(3, 1, 1);\n while (retry.shouldTry()) {\n try {\n await tableClient.createEntity(entity);\n } catch (ex) {\n await retry.backoff();\n }\n }\n};\n\nexport enum OperationStatus {\n Pending = \"Pending\",\n Succeede = \"Succeeded\",\n Failed = \"Failed\",\n Queued = \"Queued\",\n Skipped = \"Skipped\",\n PartiallySucceeded = \"PartiallySucceeded\",\n}\n\nexport class TableReportIngestionResult implements IngestionResult {\n public constructor(private ingestionStatusInTableDescription: IngestionStatusInTableDescription, public tableClient: TableClient | null = null) {}\n\n public async getIngestionStatusCollection(): Promise<IngestionStatus> {\n if (!this.tableClient) {\n this.tableClient = createStatusTableClient(this.ingestionStatusInTableDescription.tableConnectionString);\n }\n\n return await this.tableClient.getEntity<IngestionStatus>(\n this.ingestionStatusInTableDescription.partitionKey,\n this.ingestionStatusInTableDescription.rowKey\n );\n }\n}\n\nexport class IngestionStatusResult implements IngestionResult {\n constructor(private ingestionStatus: IngestionStatus) {\n this.ingestionStatus = ingestionStatus;\n }\n\n public getIngestionStatusCollection(): Promise<IngestionStatus> {\n return Promise.resolve(this.ingestionStatus);\n }\n}\n\nexport class IngestionStatusInTableDescription {\n constructor(public tableConnectionString: string, public partitionKey: string, public rowKey: string) {}\n}\n\nexport interface IngestionStatus {\n Timestamp: string;\n Status: OperationStatus;\n IngestionSourceId: string;\n IngestionSourcePath: string;\n Database: string;\n Table: string;\n UpdatedOn: string;\n Details: string;\n}\n"]}
@@ -52,12 +52,12 @@ class KustoManagedStreamingIngestClient extends abstractKustoClient_1.AbstractKu
52
52
  dmConnectionString.dataSource = (_a = dmConnectionString.dataSource) === null || _a === void 0 ? void 0 : _a.replace("https://", ingestPrefix);
53
53
  return new KustoManagedStreamingIngestClient(engineConnectionString, dmConnectionString, defaultProps);
54
54
  }
55
- constructor(engineKcsb, dmKcsb, defaultProps) {
55
+ constructor(engineKcsb, dmKcsb, defaultProps, autoCorrectEndpoint = true) {
56
56
  super(defaultProps);
57
57
  this.baseSleepTimeSecs = 1;
58
58
  this.baseJitterSecs = 1;
59
- this.streamingIngestClient = new streamingIngestClient_1.default(engineKcsb, defaultProps);
60
- this.queuedIngestClient = new ingestClient_1.default(dmKcsb, defaultProps);
59
+ this.streamingIngestClient = new streamingIngestClient_1.default(engineKcsb, defaultProps, autoCorrectEndpoint);
60
+ this.queuedIngestClient = new ingestClient_1.default(dmKcsb, defaultProps, autoCorrectEndpoint);
61
61
  if (this.streamingIngestClient.defaultDatabase && this.streamingIngestClient.defaultDatabase !== this.queuedIngestClient.defaultDatabase) {
62
62
  throw new Error(`Default database for streaming ingest client (${this.streamingIngestClient.defaultDatabase}) must match default database for queued ingest client (${this.queuedIngestClient.defaultDatabase})`);
63
63
  }
@@ -107,7 +107,7 @@ class KustoManagedStreamingIngestClient extends abstractKustoClient_1.AbstractKu
107
107
  try {
108
108
  const sourceId = clientRequestId !== null && clientRequestId !== void 0 ? clientRequestId : `KNC.executeManagedStreamingIngest${isBlob ? "FromBlob" : "FromStream"};${descriptor.sourceId};${retry.currentAttempt}`;
109
109
  if (isBlob) {
110
- return this.streamingIngestClient.ingestFromBlob(descriptor, props, sourceId);
110
+ return await this.streamingIngestClient.ingestFromBlob(descriptor, props, sourceId);
111
111
  }
112
112
  if (core_util_1.isNode) {
113
113
  return await this.streamingIngestClient.ingestFromStream(new descriptors_1.StreamDescriptor((0, streamUtils_1.readableToStream)(stream)).merge(descriptor), props, sourceId);
@@ -1 +1 @@
1
- {"version":3,"file":"managedStreamingIngestClient.js","sourceRoot":"","sources":["../../src/managedStreamingIngestClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;;AAIlC,gDAA0C;AAE1C,uDAAsF;AAEtF,+DAA4D;AAC5D,+CAAqF;AACrF,qDAAkD;AAClD,kEAA0C;AAC1C,mCAA2C;AAC3C,+CAAoF;AACpF,oFAA4D;AAE5D,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC;AACtC,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC,MAAM,iCAAkC,SAAQ,yCAAmB;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ACnB,MAAM,WAAW,GAAG,GAAiC,CAAC;oBACtD,IAAI,WAAW,CAAC,YAAY,CAAC,EAAE;wBAC3B,MAAM,GAAG,CAAC;qBACb;oBACD,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;iBACzB;aACJ;YAED,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAM,IAAI,MAAM,CAAC,CAAC,CAAC,IAAA,8BAAgB,EAAC,MAAM,CAAC,CAAC,CAAC,CAAE,UAA+B,CAAC,MAAM,CAAC;SACvH;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK;QACD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACjB,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;YACnC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;SACnC;QACD,KAAK,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;CACJ;AAED,kBAAe,iCAAiC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { IngestionPropertiesInput } from \"./ingestionProperties\";\n\nimport { isNode } from \"@azure/core-util\";\nimport { QueueSendMessageResponse } from \"@azure/storage-queue\";\nimport { KustoConnectionStringBuilder, KustoResponseDataSet } from \"azure-kusto-data\";\nimport { Readable } from \"stream\";\nimport { AbstractKustoClient } from \"./abstractKustoClient\";\nimport { AbstractDescriptor, BlobDescriptor, StreamDescriptor } from \"./descriptors\";\nimport { FileDescriptor } from \"./fileDescriptor\";\nimport IngestClient from \"./ingestClient\";\nimport { ExponentialRetry } from \"./retry\";\nimport { readableToStream, tryFileToBuffer, tryStreamToArray } from \"./streamUtils\";\nimport StreamingIngestClient from \"./streamingIngestClient\";\n\nconst maxStreamSize = 1024 * 1024 * 4;\nconst attemptCount = 3;\nconst ingestPrefix = \"https://ingest-\";\n\nclass KustoManagedStreamingIngestClient extends AbstractKustoClient {\n private streamingIngestClient: StreamingIngestClient;\n private queuedIngestClient: IngestClient;\n private baseSleepTimeSecs = 1;\n private baseJitterSecs = 1;\n\n /**\n * Creates a KustoManagedStreamingIngestClient from a DM connection string.\n * This method infers the engine connection string.\n * For advanced usage, use the constructor that takes a DM connection string and an engine connection string.\n *\n * @param dmConnectionString The DM connection string.\n * @param defaultProps The default ingestion properties.\n */\n static fromDmConnectionString(\n dmConnectionString: KustoConnectionStringBuilder,\n defaultProps?: IngestionPropertiesInput\n ): KustoManagedStreamingIngestClient {\n if (dmConnectionString.dataSource == null || !dmConnectionString.dataSource.startsWith(ingestPrefix)) {\n throw new Error(`DM connection string must include the prefix '${ingestPrefix}'`);\n }\n\n const engineConnectionString = KustoConnectionStringBuilder.fromExisting(dmConnectionString);\n engineConnectionString.dataSource = engineConnectionString.dataSource?.replace(ingestPrefix, \"https://\");\n\n return new KustoManagedStreamingIngestClient(engineConnectionString, dmConnectionString, defaultProps);\n }\n\n /**\n * Creates a KustoManagedStreamingIngestClient from a engine connection string.\n * This method infers the engine connection string.\n * For advanced usage, use the constructor that takes an engine connection string and an engine connection string.\n *\n * @param engineConnectionString The engine connection string.\n * @param defaultProps The default ingestion properties.\n */\n static fromEngineConnectionString(\n engineConnectionString: KustoConnectionStringBuilder,\n defaultProps?: IngestionPropertiesInput\n ): KustoManagedStreamingIngestClient {\n if (engineConnectionString.dataSource == null || engineConnectionString.dataSource.startsWith(ingestPrefix)) {\n throw new Error(`Engine connection string must not include the prefix '${ingestPrefix}'`);\n }\n\n const dmConnectionString = KustoConnectionStringBuilder.fromExisting(engineConnectionString);\n dmConnectionString.dataSource = dmConnectionString.dataSource?.replace(\"https://\", ingestPrefix);\n\n return new KustoManagedStreamingIngestClient(engineConnectionString, dmConnectionString, defaultProps);\n }\n\n constructor(engineKcsb: string | KustoConnectionStringBuilder, dmKcsb: string | KustoConnectionStringBuilder, defaultProps?: IngestionPropertiesInput) {\n super(defaultProps);\n this.streamingIngestClient = new StreamingIngestClient(engineKcsb, defaultProps);\n this.queuedIngestClient = new IngestClient(dmKcsb, defaultProps);\n\n if (this.streamingIngestClient.defaultDatabase && this.streamingIngestClient.defaultDatabase !== this.queuedIngestClient.defaultDatabase) {\n throw new Error(\n `Default database for streaming ingest client (${this.streamingIngestClient.defaultDatabase}) must match default database for queued ingest client (${this.queuedIngestClient.defaultDatabase})`\n );\n }\n\n this.defaultDatabase = this.streamingIngestClient.defaultDatabase;\n }\n\n /**\n * Use Readable for Node.js and ArrayBuffer in browser\n */\n async ingestFromStream(\n stream: StreamDescriptor | Readable | ArrayBuffer,\n ingestionProperties?: IngestionPropertiesInput,\n clientRequestId?: string\n ): Promise<any> {\n this.ensureOpen();\n const props = this._getMergedProps(ingestionProperties);\n let descriptor = stream instanceof StreamDescriptor ? stream : new StreamDescriptor(stream);\n let result = isNode ? await tryStreamToArray(descriptor.stream as Readable, maxStreamSize) : descriptor.stream;\n descriptor = new StreamDescriptor(result).merge(descriptor);\n let streamingResult: Promise<any> | null = null;\n // tryStreamToArray returns a Buffer in NodeJS impl if stream size is small enouph\n if ((isNode && result instanceof Buffer) || !isNode) {\n streamingResult = await this.streamWithRetries(\n isNode ? descriptor.size ?? 0 : (descriptor.stream as ArrayBuffer).byteLength,\n descriptor,\n props,\n clientRequestId,\n result\n );\n\n result = isNode ? readableToStream(result) : descriptor.stream;\n }\n\n return streamingResult ?? this.queuedIngestClient.ingestFromStream(new StreamDescriptor(result).merge(descriptor), props);\n }\n\n /**\n * Use string for Node.js and Blob in browser\n */\n async ingestFromFile(\n file: FileDescriptor | string | Blob,\n ingestionProperties?: IngestionPropertiesInput\n ): Promise<KustoResponseDataSet | QueueSendMessageResponse> {\n this.ensureOpen();\n\n const stream = file instanceof FileDescriptor ? await tryFileToBuffer(file) : await tryFileToBuffer(new FileDescriptor(file));\n return await this.ingestFromStream(stream, ingestionProperties);\n }\n\n async ingestFromBlob(blob: string | BlobDescriptor, ingestionProperties?: IngestionPropertiesInput, clientRequestId?: string): Promise<any> {\n const props = this._getMergedProps(ingestionProperties);\n const descriptor = blob instanceof BlobDescriptor ? blob : new BlobDescriptor(blob);\n // No need to check blob size if it was given to us that it's not empty\n await descriptor.fillSize();\n\n const streamingResult = await this.streamWithRetries(descriptor.size ?? 0, descriptor, props, clientRequestId);\n return streamingResult ?? this.queuedIngestClient.ingestFromBlob(descriptor, props);\n }\n\n async streamWithRetries(\n length: number,\n descriptor: AbstractDescriptor,\n props?: IngestionPropertiesInput,\n clientRequestId?: string,\n stream?: Readable | ArrayBuffer\n ): Promise<any> {\n const isBlob = descriptor instanceof BlobDescriptor;\n if (length <= maxStreamSize) {\n // If we get buffer that means it was less than the max size, so we can do streamingIngestion\n const retry = new ExponentialRetry(attemptCount, this.baseSleepTimeSecs, this.baseJitterSecs);\n while (retry.shouldTry()) {\n try {\n const sourceId =\n clientRequestId ??\n `KNC.executeManagedStreamingIngest${isBlob ? \"FromBlob\" : \"FromStream\"};${descriptor.sourceId};${retry.currentAttempt}`;\n if (isBlob) {\n return this.streamingIngestClient.ingestFromBlob(descriptor as BlobDescriptor, props, sourceId);\n }\n\n if (isNode) {\n return await this.streamingIngestClient.ingestFromStream(\n new StreamDescriptor(readableToStream(stream!)).merge(descriptor as StreamDescriptor),\n props,\n sourceId\n );\n }\n\n return await this.streamingIngestClient.ingestFromStream(descriptor as StreamDescriptor, props, sourceId);\n } catch (err: unknown) {\n const oneApiError = err as { \"@permanent\"?: boolean };\n if (oneApiError[\"@permanent\"]) {\n throw err;\n }\n await retry.backoff();\n }\n }\n\n stream = isBlob ? undefined : isNode && stream ? readableToStream(stream) : (descriptor as StreamDescriptor).stream;\n }\n\n return null;\n }\n\n close() {\n if (!this._isClosed) {\n this.streamingIngestClient.close();\n this.queuedIngestClient.close();\n }\n super.close();\n }\n}\n\nexport default KustoManagedStreamingIngestClient;\n"]}
1
+ {"version":3,"file":"managedStreamingIngestClient.js","sourceRoot":"","sources":["../../src/managedStreamingIngestClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;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AC,CAAC;qBACzG;oBAED,IAAI,kBAAM,EAAE;wBACR,OAAO,MAAM,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CACpD,IAAI,8BAAgB,CAAC,IAAA,8BAAgB,EAAC,MAAO,CAAC,CAAC,CAAC,KAAK,CAAC,UAA8B,CAAC,EACrF,KAAK,EACL,QAAQ,CACX,CAAC;qBACL;oBAED,OAAO,MAAM,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,UAA8B,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;iBAC7G;gBAAC,OAAO,GAAY,EAAE;oBACnB,MAAM,WAAW,GAAG,GAAiC,CAAC;oBACtD,IAAI,WAAW,CAAC,YAAY,CAAC,EAAE;wBAC3B,MAAM,GAAG,CAAC;qBACb;oBACD,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;iBACzB;aACJ;YAED,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAM,IAAI,MAAM,CAAC,CAAC,CAAC,IAAA,8BAAgB,EAAC,MAAM,CAAC,CAAC,CAAC,CAAE,UAA+B,CAAC,MAAM,CAAC;SACvH;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK;QACD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACjB,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;YACnC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;SACnC;QACD,KAAK,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;CACJ;AAED,kBAAe,iCAAiC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { IngestionPropertiesInput } from \"./ingestionProperties\";\n\nimport { isNode } from \"@azure/core-util\";\nimport { KustoConnectionStringBuilder, KustoResponseDataSet } from \"azure-kusto-data\";\nimport { Readable } from \"stream\";\nimport { AbstractKustoClient } from \"./abstractKustoClient\";\nimport { AbstractDescriptor, BlobDescriptor, StreamDescriptor } from \"./descriptors\";\nimport { FileDescriptor } from \"./fileDescriptor\";\nimport IngestClient from \"./ingestClient\";\nimport { ExponentialRetry } from \"./retry\";\nimport { readableToStream, tryFileToBuffer, tryStreamToArray } from \"./streamUtils\";\nimport StreamingIngestClient from \"./streamingIngestClient\";\nimport { IngestionResult } from \"./ingestionResult\";\n\nconst maxStreamSize = 1024 * 1024 * 4;\nconst attemptCount = 3;\nconst ingestPrefix = \"https://ingest-\";\n\nclass KustoManagedStreamingIngestClient extends AbstractKustoClient {\n private streamingIngestClient: StreamingIngestClient;\n private queuedIngestClient: IngestClient;\n private baseSleepTimeSecs = 1;\n private baseJitterSecs = 1;\n\n /**\n * Creates a KustoManagedStreamingIngestClient from a DM connection string.\n * This method infers the engine connection string.\n * For advanced usage, use the constructor that takes a DM connection string and an engine connection string.\n *\n * @param dmConnectionString The DM connection string.\n * @param defaultProps The default ingestion properties.\n */\n static fromDmConnectionString(\n dmConnectionString: KustoConnectionStringBuilder,\n defaultProps?: IngestionPropertiesInput\n ): KustoManagedStreamingIngestClient {\n if (dmConnectionString.dataSource == null || !dmConnectionString.dataSource.startsWith(ingestPrefix)) {\n throw new Error(`DM connection string must include the prefix '${ingestPrefix}'`);\n }\n\n const engineConnectionString = KustoConnectionStringBuilder.fromExisting(dmConnectionString);\n engineConnectionString.dataSource = engineConnectionString.dataSource?.replace(ingestPrefix, \"https://\");\n\n return new KustoManagedStreamingIngestClient(engineConnectionString, dmConnectionString, defaultProps);\n }\n\n /**\n * Creates a KustoManagedStreamingIngestClient from a engine connection string.\n * This method infers the engine connection string.\n * For advanced usage, use the constructor that takes an engine connection string and an engine connection string.\n *\n * @param engineConnectionString The engine connection string.\n * @param defaultProps The default ingestion properties.\n */\n static fromEngineConnectionString(\n engineConnectionString: KustoConnectionStringBuilder,\n defaultProps?: IngestionPropertiesInput\n ): KustoManagedStreamingIngestClient {\n if (engineConnectionString.dataSource == null || engineConnectionString.dataSource.startsWith(ingestPrefix)) {\n throw new Error(`Engine connection string must not include the prefix '${ingestPrefix}'`);\n }\n\n const dmConnectionString = KustoConnectionStringBuilder.fromExisting(engineConnectionString);\n dmConnectionString.dataSource = dmConnectionString.dataSource?.replace(\"https://\", ingestPrefix);\n\n return new KustoManagedStreamingIngestClient(engineConnectionString, dmConnectionString, defaultProps);\n }\n\n constructor(\n engineKcsb: string | KustoConnectionStringBuilder,\n dmKcsb: string | KustoConnectionStringBuilder,\n defaultProps?: IngestionPropertiesInput,\n autoCorrectEndpoint: boolean = true\n ) {\n super(defaultProps);\n this.streamingIngestClient = new StreamingIngestClient(engineKcsb, defaultProps, autoCorrectEndpoint);\n this.queuedIngestClient = new IngestClient(dmKcsb, defaultProps, autoCorrectEndpoint);\n\n if (this.streamingIngestClient.defaultDatabase && this.streamingIngestClient.defaultDatabase !== this.queuedIngestClient.defaultDatabase) {\n throw new Error(\n `Default database for streaming ingest client (${this.streamingIngestClient.defaultDatabase}) must match default database for queued ingest client (${this.queuedIngestClient.defaultDatabase})`\n );\n }\n\n this.defaultDatabase = this.streamingIngestClient.defaultDatabase;\n }\n\n /**\n * Use Readable for Node.js and ArrayBuffer in browser\n */\n async ingestFromStream(\n stream: StreamDescriptor | Readable | ArrayBuffer,\n ingestionProperties?: IngestionPropertiesInput,\n clientRequestId?: string\n ): Promise<KustoResponseDataSet | IngestionResult> {\n this.ensureOpen();\n const props = this._getMergedProps(ingestionProperties);\n let descriptor = stream instanceof StreamDescriptor ? stream : new StreamDescriptor(stream);\n let result = isNode ? await tryStreamToArray(descriptor.stream as Readable, maxStreamSize) : descriptor.stream;\n descriptor = new StreamDescriptor(result).merge(descriptor);\n let streamingResult: Promise<any> | null = null;\n // tryStreamToArray returns a Buffer in NodeJS impl if stream size is small enouph\n if ((isNode && result instanceof Buffer) || !isNode) {\n streamingResult = await this.streamWithRetries(\n isNode ? descriptor.size ?? 0 : (descriptor.stream as ArrayBuffer).byteLength,\n descriptor,\n props,\n clientRequestId,\n result\n );\n\n result = isNode ? readableToStream(result) : descriptor.stream;\n }\n\n return streamingResult ?? this.queuedIngestClient.ingestFromStream(new StreamDescriptor(result).merge(descriptor), props);\n }\n\n /**\n * Use string for Node.js and Blob in browser\n */\n async ingestFromFile(\n file: FileDescriptor | string | Blob,\n ingestionProperties?: IngestionPropertiesInput\n ): Promise<KustoResponseDataSet | IngestionResult> {\n this.ensureOpen();\n\n const stream = file instanceof FileDescriptor ? await tryFileToBuffer(file) : await tryFileToBuffer(new FileDescriptor(file));\n return await this.ingestFromStream(stream, ingestionProperties);\n }\n\n async ingestFromBlob(\n blob: string | BlobDescriptor,\n ingestionProperties?: IngestionPropertiesInput,\n clientRequestId?: string\n ): Promise<KustoResponseDataSet | IngestionResult> {\n const props = this._getMergedProps(ingestionProperties);\n const descriptor = blob instanceof BlobDescriptor ? blob : new BlobDescriptor(blob);\n // No need to check blob size if it was given to us that it's not empty\n await descriptor.fillSize();\n\n const streamingResult = await this.streamWithRetries(descriptor.size ?? 0, descriptor, props, clientRequestId);\n return streamingResult ?? this.queuedIngestClient.ingestFromBlob(descriptor, props);\n }\n\n async streamWithRetries(\n length: number,\n descriptor: AbstractDescriptor,\n props?: IngestionPropertiesInput,\n clientRequestId?: string,\n stream?: Readable | ArrayBuffer\n ): Promise<any> {\n const isBlob = descriptor instanceof BlobDescriptor;\n if (length <= maxStreamSize) {\n // If we get buffer that means it was less than the max size, so we can do streamingIngestion\n const retry = new ExponentialRetry(attemptCount, this.baseSleepTimeSecs, this.baseJitterSecs);\n while (retry.shouldTry()) {\n try {\n const sourceId =\n clientRequestId ??\n `KNC.executeManagedStreamingIngest${isBlob ? \"FromBlob\" : \"FromStream\"};${descriptor.sourceId};${retry.currentAttempt}`;\n if (isBlob) {\n return await this.streamingIngestClient.ingestFromBlob(descriptor as BlobDescriptor, props, sourceId);\n }\n\n if (isNode) {\n return await this.streamingIngestClient.ingestFromStream(\n new StreamDescriptor(readableToStream(stream!)).merge(descriptor as StreamDescriptor),\n props,\n sourceId\n );\n }\n\n return await this.streamingIngestClient.ingestFromStream(descriptor as StreamDescriptor, props, sourceId);\n } catch (err: unknown) {\n const oneApiError = err as { \"@permanent\"?: boolean };\n if (oneApiError[\"@permanent\"]) {\n throw err;\n }\n await retry.backoff();\n }\n }\n\n stream = isBlob ? undefined : isNode && stream ? readableToStream(stream) : (descriptor as StreamDescriptor).stream;\n }\n\n return null;\n }\n\n close() {\n if (!this._isClosed) {\n this.streamingIngestClient.close();\n this.queuedIngestClient.close();\n }\n super.close();\n }\n}\n\nexport default KustoManagedStreamingIngestClient;\n"]}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RankedStorageAccount = void 0;
4
+ // Copyright (c) Microsoft Corporation.
5
+ // Licensed under the MIT License.
6
+ class StorageAccountStats {
7
+ constructor() {
8
+ this.successCount = 0;
9
+ this.totalCount = 0;
10
+ }
11
+ logResult(success) {
12
+ this.totalCount += 1;
13
+ if (success) {
14
+ this.successCount += 1;
15
+ }
16
+ }
17
+ reset() {
18
+ this.successCount = 0;
19
+ this.totalCount = 0;
20
+ }
21
+ }
22
+ class RankedStorageAccount {
23
+ constructor(accountName, numberOfBuckets, bucketDuration, timeProvider) {
24
+ this.accountName = accountName;
25
+ this.numberOfBuckets = numberOfBuckets;
26
+ this.bucketDuration = bucketDuration;
27
+ this.timeProvider = timeProvider;
28
+ this.buckets = new Array(numberOfBuckets).fill(new StorageAccountStats()).map(() => new StorageAccountStats());
29
+ this.lastUpdateTime = this.timeProvider();
30
+ this.currentBucketIndex = 0;
31
+ }
32
+ logResult(success) {
33
+ this.currentBucketIndex = this.adjustForTimePassed();
34
+ this.buckets[this.currentBucketIndex].logResult(success);
35
+ }
36
+ getAccountName() {
37
+ return this.accountName;
38
+ }
39
+ adjustForTimePassed() {
40
+ const currentTime = this.timeProvider();
41
+ const timeDelta = currentTime - this.lastUpdateTime;
42
+ let window_size = 0;
43
+ if (timeDelta >= this.bucketDuration) {
44
+ this.lastUpdateTime = currentTime;
45
+ window_size = Math.min(Math.floor(timeDelta / this.bucketDuration), this.numberOfBuckets);
46
+ for (let i = 1; i < window_size + 1; i++) {
47
+ const indexToReset = (this.currentBucketIndex + i) % this.numberOfBuckets;
48
+ this.buckets[indexToReset].reset();
49
+ }
50
+ }
51
+ return (this.currentBucketIndex + window_size) % this.numberOfBuckets;
52
+ }
53
+ getRank() {
54
+ let rank = 0;
55
+ let totalWeight = 0;
56
+ for (let i = 1; i <= this.numberOfBuckets; i++) {
57
+ const bucketIndex = (this.currentBucketIndex + i) % this.numberOfBuckets;
58
+ const bucket = this.buckets[bucketIndex];
59
+ if (bucket.totalCount === 0) {
60
+ continue;
61
+ }
62
+ const successRate = bucket.successCount / bucket.totalCount;
63
+ rank += successRate * i;
64
+ totalWeight += i;
65
+ }
66
+ if (totalWeight === 0) {
67
+ return 1;
68
+ }
69
+ return rank / totalWeight;
70
+ }
71
+ }
72
+ exports.RankedStorageAccount = RankedStorageAccount;
73
+ //# sourceMappingURL=rankedStorageAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rankedStorageAccount.js","sourceRoot":"","sources":["../../src/rankedStorageAccount.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,MAAM,mBAAmB;IAIrB;QACI,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,SAAS,CAAC,OAAgB;QACtB,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC;QACrB,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC;SAC1B;IACL,CAAC;IAED,KAAK;QACD,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;IACxB,CAAC;CACJ;AAED,MAAa,oBAAoB;IAK7B,YAAoB,WAAmB,EAAU,eAAuB,EAAU,cAAsB,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GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC;gBAC1E,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,CAAC;aACtC;SACJ;QAED,OAAO,CAAC,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC;IAC1E,CAAC;IAED,OAAO;QACH,IAAI,IAAI,GAAW,CAAC,CAAC;QACrB,IAAI,WAAW,GAAW,CAAC,CAAC;QAE5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE;YAC5C,MAAM,WAAW,GAAW,CAAC,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC;YACjF,MAAM,MAAM,GAAwB,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAC9D,IAAI,MAAM,CAAC,UAAU,KAAK,CAAC,EAAE;gBACzB,SAAS;aACZ;YACD,MAAM,WAAW,GAAW,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC;YACpE,IAAI,IAAI,WAAW,GAAG,CAAC,CAAC;YACxB,WAAW,IAAI,CAAC,CAAC;SACpB;QAED,IAAI,WAAW,KAAK,CAAC,EAAE;YACnB,OAAO,CAAC,CAAC;SACZ;QACD,OAAO,IAAI,GAAG,WAAW,CAAC;IAC9B,CAAC;CACJ;AAzDD,oDAyDC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nclass StorageAccountStats {\n public successCount: number;\n public totalCount: number;\n\n constructor() {\n this.successCount = 0;\n this.totalCount = 0;\n }\n\n logResult(success: boolean): void {\n this.totalCount += 1;\n if (success) {\n this.successCount += 1;\n }\n }\n\n reset(): void {\n this.successCount = 0;\n this.totalCount = 0;\n }\n}\n\nexport class RankedStorageAccount {\n private buckets: StorageAccountStats[];\n private lastUpdateTime: number;\n private currentBucketIndex: number;\n\n constructor(private accountName: string, private numberOfBuckets: number, private bucketDuration: number, private timeProvider: () => number) {\n this.buckets = new Array<StorageAccountStats>(numberOfBuckets).fill(new StorageAccountStats()).map(() => new StorageAccountStats());\n this.lastUpdateTime = this.timeProvider();\n this.currentBucketIndex = 0;\n }\n\n logResult(success: boolean): void {\n this.currentBucketIndex = this.adjustForTimePassed();\n this.buckets[this.currentBucketIndex].logResult(success);\n }\n\n getAccountName(): string {\n return this.accountName;\n }\n\n adjustForTimePassed(): number {\n const currentTime = this.timeProvider();\n const timeDelta = currentTime - this.lastUpdateTime;\n let window_size = 0;\n\n if (timeDelta >= this.bucketDuration) {\n this.lastUpdateTime = currentTime;\n window_size = Math.min(Math.floor(timeDelta / this.bucketDuration), this.numberOfBuckets);\n for (let i = 1; i < window_size + 1; i++) {\n const indexToReset = (this.currentBucketIndex + i) % this.numberOfBuckets;\n this.buckets[indexToReset].reset();\n }\n }\n\n return (this.currentBucketIndex + window_size) % this.numberOfBuckets;\n }\n\n getRank(): number {\n let rank: number = 0;\n let totalWeight: number = 0;\n\n for (let i = 1; i <= this.numberOfBuckets; i++) {\n const bucketIndex: number = (this.currentBucketIndex + i) % this.numberOfBuckets;\n const bucket: StorageAccountStats = this.buckets[bucketIndex];\n if (bucket.totalCount === 0) {\n continue;\n }\n const successRate: number = bucket.successCount / bucket.totalCount;\n rank += successRate * i;\n totalWeight += i;\n }\n\n if (totalWeight === 0) {\n return 1;\n }\n return rank / totalWeight;\n }\n}\n"]}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.RankedStorageAccountSet = void 0;
6
+ const rankedStorageAccount_1 = require("./rankedStorageAccount");
7
+ class RankedStorageAccountSet {
8
+ constructor(numberOfBuckets = RankedStorageAccountSet.DefaultNumberOfBuckets, bucketDuration = RankedStorageAccountSet.DefaultBucketDurationInSeconds, tiers = RankedStorageAccountSet.DefaultTiers, timeProvider = RankedStorageAccountSet.DefaultTimeProviderInSeconds) {
9
+ this.numberOfBuckets = numberOfBuckets;
10
+ this.bucketDuration = bucketDuration;
11
+ this.tiers = tiers;
12
+ this.timeProvider = timeProvider;
13
+ this.accounts = new Map();
14
+ }
15
+ logResultToAccount(accountName, result) {
16
+ var _a;
17
+ if (!this.accounts.has(accountName)) {
18
+ throw new Error("Storage account name is not part of the set.");
19
+ }
20
+ (_a = this.accounts.get(accountName)) === null || _a === void 0 ? void 0 : _a.logResult(result);
21
+ }
22
+ registerStorageAccount(accountName) {
23
+ if (this.accounts.has(accountName)) {
24
+ return;
25
+ }
26
+ this.accounts.set(accountName, new rankedStorageAccount_1.RankedStorageAccount(accountName, this.numberOfBuckets, this.bucketDuration, this.timeProvider));
27
+ }
28
+ getStorageAccount(accountName) {
29
+ const account = this.accounts.get(accountName);
30
+ if (account) {
31
+ return account;
32
+ }
33
+ throw new Error("Storage account name is not part of the set.");
34
+ }
35
+ getRankedShuffledAccounts() {
36
+ const accountsByTier = new Array(this.tiers.length);
37
+ // Group accounts by tier and rank
38
+ for (const account of this.accounts.values()) {
39
+ const rank = account.getRank() * 100;
40
+ const tierInedx = this.tiers.findIndex((tier) => rank >= tier);
41
+ accountsByTier[tierInedx] = accountsByTier[tierInedx] || [];
42
+ accountsByTier[tierInedx].push(account);
43
+ }
44
+ // Shuffle each tier
45
+ for (let i = 0; i < this.tiers.length; i++) {
46
+ if (accountsByTier[i]) {
47
+ accountsByTier[i].sort(() => Math.random() - 0.5);
48
+ }
49
+ }
50
+ // Flatten the array
51
+ return accountsByTier.flat();
52
+ }
53
+ }
54
+ exports.RankedStorageAccountSet = RankedStorageAccountSet;
55
+ RankedStorageAccountSet.DefaultNumberOfBuckets = 6;
56
+ RankedStorageAccountSet.DefaultBucketDurationInSeconds = 10;
57
+ RankedStorageAccountSet.DefaultTiers = [90, 70, 30, 0];
58
+ RankedStorageAccountSet.DefaultTimeProviderInSeconds = () => {
59
+ return new Date().getTime() / 1000;
60
+ };
61
+ //# sourceMappingURL=rankedStorageAccountSet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rankedStorageAccountSet.js","sourceRoot":"","sources":["../../src/rankedStorageAccountSet.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,iEAA8D;AAE9D,MAAa,uBAAuB;IAUhC,YACY,kBAA0B,uBAAuB,CAAC,sBAAsB,EACxE,iBAAyB,uBAAuB,CAAC,8BAA8B,EAC/E,QAAkB,uBAAuB,CAAC,YAAY,EACtD,eAA6B,uBAAuB,CAAC,4BAA4B;QAHjF,oBAAe,GAAf,eAAe,CAAyD;QACxE,mBAAc,GAAd,cAAc,CAAiE;QAC/E,UAAK,GAAL,KAAK,CAAiD;QACtD,iBAAY,GAAZ,YAAY,CAAqE;QAEzF,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAgC,CAAC;IAC5D,CAAC;IAED,kBAAkB,CAAC,WAAmB,EAAE,MAAe;;QACnD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;SACnE;QACD,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,0CAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACtD,CAAC;IAED,sBAAsB,CAAC,WAAmB;QACtC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;YAChC,OAAO;SACV;QACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,2CAAoB,CAAC,WAAW,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACxI,CAAC;IAED,iBAAiB,CAAC,WAAmB;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC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iB,GAAG,EAAE;IACrE,OAAO,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;AACvC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { RankedStorageAccount } from \"./rankedStorageAccount\";\n\nexport class RankedStorageAccountSet {\n public static readonly DefaultNumberOfBuckets: number = 6;\n public static readonly DefaultBucketDurationInSeconds: number = 10;\n public static readonly DefaultTiers: number[] = [90, 70, 30, 0];\n public static readonly DefaultTimeProviderInSeconds: () => number = () => {\n return new Date().getTime() / 1000;\n };\n\n private accounts: Map<string, RankedStorageAccount>;\n\n constructor(\n private numberOfBuckets: number = RankedStorageAccountSet.DefaultNumberOfBuckets,\n private bucketDuration: number = RankedStorageAccountSet.DefaultBucketDurationInSeconds,\n private tiers: number[] = RankedStorageAccountSet.DefaultTiers,\n private timeProvider: () => number = RankedStorageAccountSet.DefaultTimeProviderInSeconds\n ) {\n this.accounts = new Map<string, RankedStorageAccount>();\n }\n\n logResultToAccount(accountName: string, result: boolean) {\n if (!this.accounts.has(accountName)) {\n throw new Error(\"Storage account name is not part of the set.\");\n }\n this.accounts.get(accountName)?.logResult(result);\n }\n\n registerStorageAccount(accountName: string) {\n if (this.accounts.has(accountName)) {\n return;\n }\n this.accounts.set(accountName, new RankedStorageAccount(accountName, this.numberOfBuckets, this.bucketDuration, this.timeProvider));\n }\n\n getStorageAccount(accountName: string): RankedStorageAccount {\n const account = this.accounts.get(accountName);\n if (account) {\n return account;\n }\n throw new Error(\"Storage account name is not part of the set.\");\n }\n\n getRankedShuffledAccounts(): RankedStorageAccount[] {\n const accountsByTier: RankedStorageAccount[][] = new Array<RankedStorageAccount[]>(this.tiers.length);\n\n // Group accounts by tier and rank\n for (const account of this.accounts.values()) {\n const rank = account.getRank() * 100;\n const tierInedx = this.tiers.findIndex((tier) => rank >= tier);\n accountsByTier[tierInedx] = accountsByTier[tierInedx] || [];\n accountsByTier[tierInedx].push(account);\n }\n\n // Shuffle each tier\n for (let i = 0; i < this.tiers.length; i++) {\n if (accountsByTier[i]) {\n accountsByTier[i].sort(() => Math.random() - 0.5);\n }\n }\n\n // Flatten the array\n return accountsByTier.flat();\n }\n}\n"]}