azure-kusto-ingest 6.0.2 → 7.0.0-alpha.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 (71) hide show
  1. package/dist-esm/src/abstractKustoClient.js +8 -15
  2. package/dist-esm/src/abstractKustoClient.js.map +1 -1
  3. package/dist-esm/src/columnMappings.js +22 -34
  4. package/dist-esm/src/columnMappings.js.map +1 -1
  5. package/dist-esm/src/descriptors.js +15 -27
  6. package/dist-esm/src/descriptors.js.map +1 -1
  7. package/dist-esm/src/errors.js +1 -5
  8. package/dist-esm/src/errors.js.map +1 -1
  9. package/dist-esm/src/fileDescriptor.browser.js +9 -16
  10. package/dist-esm/src/fileDescriptor.browser.js.map +1 -1
  11. package/dist-esm/src/fileDescriptor.js +20 -28
  12. package/dist-esm/src/fileDescriptor.js.map +1 -1
  13. package/dist-esm/src/index.js +38 -73
  14. package/dist-esm/src/index.js.map +1 -1
  15. package/dist-esm/src/ingestClient.browser.js +11 -15
  16. package/dist-esm/src/ingestClient.browser.js.map +1 -1
  17. package/dist-esm/src/ingestClient.js +11 -15
  18. package/dist-esm/src/ingestClient.js.map +1 -1
  19. package/dist-esm/src/ingestClientBase.js +25 -32
  20. package/dist-esm/src/ingestClientBase.js.map +1 -1
  21. package/dist-esm/src/ingestionBlobInfo.js +4 -8
  22. package/dist-esm/src/ingestionBlobInfo.js.map +1 -1
  23. package/dist-esm/src/ingestionProperties.js +29 -36
  24. package/dist-esm/src/ingestionProperties.js.map +1 -1
  25. package/dist-esm/src/ingestionResult.js +10 -17
  26. package/dist-esm/src/ingestionResult.js.map +1 -1
  27. package/dist-esm/src/managedStreamingIngestClient.js +29 -34
  28. package/dist-esm/src/managedStreamingIngestClient.js.map +1 -1
  29. package/dist-esm/src/rankedStorageAccount.js +1 -5
  30. package/dist-esm/src/rankedStorageAccount.js.map +1 -1
  31. package/dist-esm/src/rankedStorageAccountSet.js +3 -7
  32. package/dist-esm/src/rankedStorageAccountSet.js.map +1 -1
  33. package/dist-esm/src/resourceManager.js +24 -31
  34. package/dist-esm/src/resourceManager.js.map +1 -1
  35. package/dist-esm/src/retry.js +3 -8
  36. package/dist-esm/src/retry.js.map +1 -1
  37. package/dist-esm/src/status.js +6 -11
  38. package/dist-esm/src/status.js.map +1 -1
  39. package/dist-esm/src/statusQ.js +3 -7
  40. package/dist-esm/src/statusQ.js.map +1 -1
  41. package/dist-esm/src/streamUtils.browser.js +8 -15
  42. package/dist-esm/src/streamUtils.browser.js.map +1 -1
  43. package/dist-esm/src/streamUtils.js +18 -28
  44. package/dist-esm/src/streamUtils.js.map +1 -1
  45. package/dist-esm/src/streamingIngestClient.browser.js +9 -11
  46. package/dist-esm/src/streamingIngestClient.browser.js.map +1 -1
  47. package/dist-esm/src/streamingIngestClient.js +12 -17
  48. package/dist-esm/src/streamingIngestClient.js.map +1 -1
  49. package/dist-esm/src/streamingIngestClientBase.js +7 -11
  50. package/dist-esm/src/streamingIngestClientBase.js.map +1 -1
  51. package/package.json +11 -6
  52. package/types/src/abstractKustoClient.d.ts +2 -2
  53. package/types/src/columnMappings.d.ts +1 -1
  54. package/types/src/descriptors.d.ts +1 -2
  55. package/types/src/fileDescriptor.browser.d.ts +2 -2
  56. package/types/src/fileDescriptor.d.ts +2 -2
  57. package/types/src/index.d.ts +13 -13
  58. package/types/src/ingestClient.browser.d.ts +5 -5
  59. package/types/src/ingestClient.d.ts +5 -6
  60. package/types/src/ingestClientBase.d.ts +5 -5
  61. package/types/src/ingestionBlobInfo.d.ts +3 -3
  62. package/types/src/ingestionProperties.d.ts +1 -1
  63. package/types/src/managedStreamingIngestClient.d.ts +5 -6
  64. package/types/src/rankedStorageAccountSet.d.ts +1 -1
  65. package/types/src/status.d.ts +2 -2
  66. package/types/src/statusQ.d.ts +2 -2
  67. package/types/src/streamUtils.browser.d.ts +2 -3
  68. package/types/src/streamUtils.d.ts +2 -3
  69. package/types/src/streamingIngestClient.browser.d.ts +4 -4
  70. package/types/src/streamingIngestClient.d.ts +4 -5
  71. package/types/src/streamingIngestClientBase.d.ts +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"managedStreamingIngestClient.js","sourceRoot":"","sources":["../../src/managedStreamingIngestClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;;AAIlC,gDAA0C;AAC1C,uDAAsF;AAEtF,+DAA4D;AAC5D,+CAAqF;AACrF,qDAAkD;AAClD,kEAA0C;AAC1C,mCAA2C;AAC3C,+CAAoF;AACpF,oFAA4D;AAG5D,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;IAM/D;;;;;;;OAOG;IACH,MAAM,CAAC,sBAAsB,CACzB,kBAAgD,EAChD,YAAuC;;QAEvC,IAAI,kBAAkB,CAAC,UAAU,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;YAClG,MAAM,IAAI,KAAK,CAAC,iDAAiD,YAAY,GAAG,CAAC,CAAC;SACrF;QAED,MAAM,sBAAsB,GAAG,+CAA4B,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;QAC7F,sBAAsB,CAAC,UAAU,GAAG,MAAA,sBAAsB,CAAC,UAAU,0CAAE,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QAEzG,OAAO,IAAI,iCAAiC,CAAC,sBAAsB,EAAE,kBAAkB,EAAE,YAAY,CAAC,CAAC;IAC3G,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,0BAA0B,CAC7B,sBAAoD,EACpD,YAAuC;;QAEvC,IAAI,sBAAsB,CAAC,UAAU,IAAI,IAAI,IAAI,sBAAsB,CAAC,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;YACzG,MAAM,IAA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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"]}
1
+ {"version":3,"file":"managedStreamingIngestClient.js","sourceRoot":"","sources":["../../src/managedStreamingIngestClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAwB,MAAM,kBAAkB,CAAC;AAEtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAsB,cAAc,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAG/D,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC;AACtC,MAAM,YAAY,GAA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CAAC,UAA8B,CAAC,EACrF,KAAK,EACL,QAAQ,CACX,CAAC;oBACN,CAAC;oBAED,OAAO,MAAM,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,UAA8B,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;gBAC9G,CAAC;gBAAC,OAAO,GAAY,EAAE,CAAC;oBACpB,MAAM,WAAW,GAAG,GAAiC,CAAC;oBACtD,IAAI,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;wBAC5B,MAAM,GAAG,CAAC;oBACd,CAAC;oBACD,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;gBAC1B,CAAC;YACL,CAAC;YAED,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,UAA+B,CAAC,MAAM,CAAC;QACxH,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK;QACD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAClB,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;YACnC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QACpC,CAAC;QACD,KAAK,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;CACJ;AAED,eAAe,iCAAiC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { IngestionPropertiesInput } from \"./ingestionProperties.js\";\n\nimport { isNode } from \"@azure/core-util\";\nimport { KustoConnectionStringBuilder, KustoResponseDataSet } from \"azure-kusto-data\";\nimport { Readable } from \"stream\";\nimport { AbstractKustoClient } from \"./abstractKustoClient.js\";\nimport { AbstractDescriptor, BlobDescriptor, StreamDescriptor } from \"./descriptors.js\";\nimport { FileDescriptor } from \"./fileDescriptor.js\";\nimport IngestClient from \"./ingestClient.js\";\nimport { ExponentialRetry } from \"./retry.js\";\nimport { readableToStream, tryFileToBuffer, tryStreamToArray } from \"./streamUtils.js\";\nimport StreamingIngestClient from \"./streamingIngestClient.js\";\nimport { IngestionResult } from \"./ingestionResult.js\";\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"]}
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RankedStorageAccount = void 0;
4
1
  // Copyright (c) Microsoft Corporation.
5
2
  // Licensed under the MIT License.
6
3
  class StorageAccountStats {
@@ -19,7 +16,7 @@ class StorageAccountStats {
19
16
  this.totalCount = 0;
20
17
  }
21
18
  }
22
- class RankedStorageAccount {
19
+ export class RankedStorageAccount {
23
20
  constructor(accountName, numberOfBuckets, bucketDuration, timeProvider) {
24
21
  this.accountName = accountName;
25
22
  this.numberOfBuckets = numberOfBuckets;
@@ -69,5 +66,4 @@ class RankedStorageAccount {
69
66
  return rank / totalWeight;
70
67
  }
71
68
  }
72
- exports.RankedStorageAccount = RankedStorageAccount;
73
69
  //# sourceMappingURL=rankedStorageAccount.js.map
@@ -1 +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,C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C,EAAE,CAAC,GAAG,WAAW,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;gBACtC,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,kBAAkB,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"]}
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,I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ED,IAAI,WAAW,KAAK,CAAC,EAAE,CAAC;YACpB,OAAO,CAAC,CAAC;QACb,CAAC;QACD,OAAO,IAAI,GAAG,WAAW,CAAC;IAC9B,CAAC;CACJ","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(\n private accountName: string,\n private numberOfBuckets: number,\n private bucketDuration: number,\n private timeProvider: () => number,\n ) {\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"]}
@@ -1,10 +1,7 @@
1
- "use strict";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // 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 {
3
+ import { RankedStorageAccount } from "./rankedStorageAccount.js";
4
+ export class RankedStorageAccountSet {
8
5
  constructor(numberOfBuckets = RankedStorageAccountSet.DefaultNumberOfBuckets, bucketDuration = RankedStorageAccountSet.DefaultBucketDurationInSeconds, tiers = RankedStorageAccountSet.DefaultTiers, timeProvider = RankedStorageAccountSet.DefaultTimeProviderInSeconds) {
9
6
  this.numberOfBuckets = numberOfBuckets;
10
7
  this.bucketDuration = bucketDuration;
@@ -23,7 +20,7 @@ class RankedStorageAccountSet {
23
20
  if (this.accounts.has(accountName)) {
24
21
  return;
25
22
  }
26
- this.accounts.set(accountName, new rankedStorageAccount_1.RankedStorageAccount(accountName, this.numberOfBuckets, this.bucketDuration, this.timeProvider));
23
+ this.accounts.set(accountName, new RankedStorageAccount(accountName, this.numberOfBuckets, this.bucketDuration, this.timeProvider));
27
24
  }
28
25
  getStorageAccount(accountName) {
29
26
  const account = this.accounts.get(accountName);
@@ -51,7 +48,6 @@ class RankedStorageAccountSet {
51
48
  return accountsByTier.flat();
52
49
  }
53
50
  }
54
- exports.RankedStorageAccountSet = RankedStorageAccountSet;
55
51
  RankedStorageAccountSet.DefaultNumberOfBuckets = 6;
56
52
  RankedStorageAccountSet.DefaultBucketDurationInSeconds = 10;
57
53
  RankedStorageAccountSet.DefaultTiers = [90, 70, 30, 0];
@@ -1 +1 @@
1
- {"version":3,"file":"rankedStorageAccountSet.js","sourceRoot":"","sources":["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ed 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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ACzC,oDAA4B,GAAiB,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.js\";\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"]}
@@ -1,30 +1,26 @@
1
- "use strict";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.createStatusTableClient = exports.ResourceManager = exports.IngestClientResources = exports.ResourceURI = exports.ResourceType = void 0;
6
- const azure_kusto_data_1 = require("azure-kusto-data");
7
- const retry_1 = require("./retry");
8
- const storage_blob_1 = require("@azure/storage-blob");
9
- const data_tables_1 = require("@azure/data-tables");
10
- const rankedStorageAccountSet_1 = require("./rankedStorageAccountSet");
11
- const storage_queue_1 = require("@azure/storage-queue");
3
+ import { KustoDataErrors, TimeUtils } from "azure-kusto-data";
4
+ import { ExponentialRetry } from "./retry.js";
5
+ import { ContainerClient } from "@azure/storage-blob";
6
+ import { TableClient } from "@azure/data-tables";
7
+ import { RankedStorageAccountSet } from "./rankedStorageAccountSet.js";
8
+ import { QueueClient } from "@azure/storage-queue";
12
9
  const ATTEMPT_COUNT = 4;
13
- var ResourceType;
10
+ export var ResourceType;
14
11
  (function (ResourceType) {
15
12
  ResourceType[ResourceType["Queue"] = 0] = "Queue";
16
13
  ResourceType[ResourceType["Container"] = 1] = "Container";
17
14
  ResourceType[ResourceType["Table"] = 2] = "Table";
18
- })(ResourceType || (exports.ResourceType = ResourceType = {}));
19
- class ResourceURI {
15
+ })(ResourceType || (ResourceType = {}));
16
+ export class ResourceURI {
20
17
  constructor(uri, accountName, resourceType) {
21
18
  this.uri = uri;
22
19
  this.accountName = accountName;
23
20
  this.resourceType = resourceType;
24
21
  }
25
22
  }
26
- exports.ResourceURI = ResourceURI;
27
- class IngestClientResources {
23
+ export class IngestClientResources {
28
24
  constructor(securedReadyForAggregationQueues = null, failedIngestionsQueues = null, successfulIngestionsQueues = null, containers = null, statusTables = null) {
29
25
  this.securedReadyForAggregationQueues = securedReadyForAggregationQueues;
30
26
  this.failedIngestionsQueues = failedIngestionsQueues;
@@ -37,20 +33,19 @@ class IngestClientResources {
37
33
  return resources.reduce((prev, current) => !!(prev && current), true);
38
34
  }
39
35
  }
40
- exports.IngestClientResources = IngestClientResources;
41
- class ResourceManager {
36
+ export class ResourceManager {
42
37
  constructor(kustoClient, isBrowser = false) {
43
38
  this.kustoClient = kustoClient;
44
39
  this.isBrowser = isBrowser;
45
40
  this.baseSleepTimeSecs = 1;
46
41
  this.baseJitterSecs = 1;
47
- this.refreshPeriod = azure_kusto_data_1.TimeUtils.toMilliseconds(1, 0, 0);
48
- this.refreshPeriodOnError = azure_kusto_data_1.TimeUtils.toMilliseconds(0, 10, 0);
42
+ this.refreshPeriod = TimeUtils.toMilliseconds(1, 0, 0);
43
+ this.refreshPeriodOnError = TimeUtils.toMilliseconds(0, 10, 0);
49
44
  this.ingestClientResources = null;
50
45
  this.ingestClientResourcesLastUpdate = null;
51
46
  this.authorizationContext = null;
52
47
  this.authorizationContextLastUpdate = null;
53
- this.rankedStorageAccountSet = new rankedStorageAccountSet_1.RankedStorageAccountSet();
48
+ this.rankedStorageAccountSet = new RankedStorageAccountSet();
54
49
  }
55
50
  async refreshIngestClientResources() {
56
51
  const error = await this.tryRefresh(false);
@@ -60,7 +55,7 @@ class ResourceManager {
60
55
  return this.ingestClientResources;
61
56
  }
62
57
  async getIngestClientResourcesFromService() {
63
- const retry = new retry_1.ExponentialRetry(ATTEMPT_COUNT, this.baseSleepTimeSecs, this.baseJitterSecs);
58
+ const retry = new ExponentialRetry(ATTEMPT_COUNT, this.baseSleepTimeSecs, this.baseJitterSecs);
64
59
  while (retry.shouldTry()) {
65
60
  try {
66
61
  const cmd = `.get ingestion resources ${this.isBrowser ? `with (EnableBlobCors='true', EnableQueueCors='true', EnableTableCors='true')` : ""}`;
@@ -73,7 +68,7 @@ class ResourceManager {
73
68
  return resoures;
74
69
  }
75
70
  catch (error) {
76
- if (!(error instanceof azure_kusto_data_1.KustoDataErrors.ThrottlingError)) {
71
+ if (!(error instanceof KustoDataErrors.ThrottlingError)) {
77
72
  throw error;
78
73
  }
79
74
  await retry.backoff();
@@ -88,10 +83,10 @@ class ResourceManager {
88
83
  if (typedRow.ResourceTypeName === resourceName) {
89
84
  let accountName = "";
90
85
  if (resourceType === ResourceType.Queue) {
91
- accountName = new storage_queue_1.QueueClient(typedRow.StorageRoot).accountName;
86
+ accountName = new QueueClient(typedRow.StorageRoot).accountName;
92
87
  }
93
88
  else if (resourceType === ResourceType.Container) {
94
- accountName = new storage_blob_1.ContainerClient(typedRow.StorageRoot).accountName;
89
+ accountName = new ContainerClient(typedRow.StorageRoot).accountName;
95
90
  }
96
91
  result.push(new ResourceURI(typedRow.StorageRoot, accountName, resourceType));
97
92
  }
@@ -187,7 +182,7 @@ class ResourceManager {
187
182
  return error;
188
183
  }
189
184
  async getAuthorizationContextFromService() {
190
- const retry = new retry_1.ExponentialRetry(ATTEMPT_COUNT, this.baseSleepTimeSecs, this.baseJitterSecs);
185
+ const retry = new ExponentialRetry(ATTEMPT_COUNT, this.baseSleepTimeSecs, this.baseJitterSecs);
191
186
  while (retry.shouldTry()) {
192
187
  try {
193
188
  const response = await this.kustoClient.execute("NetDefaultDB", ".get kusto identity token");
@@ -198,7 +193,7 @@ class ResourceManager {
198
193
  return next.value.toJSON().AuthorizationContext;
199
194
  }
200
195
  catch (error) {
201
- if (!(error instanceof azure_kusto_data_1.KustoDataErrors.ThrottlingError)) {
196
+ if (!(error instanceof KustoDataErrors.ThrottlingError)) {
202
197
  throw error;
203
198
  }
204
199
  await retry.backoff();
@@ -231,7 +226,7 @@ class ResourceManager {
231
226
  if (!statusTables) {
232
227
  throw new Error("Failed to get status table");
233
228
  }
234
- return (0, exports.createStatusTableClient)(statusTables[0].uri);
229
+ return createStatusTableClient(statusTables[0].uri);
235
230
  }
236
231
  close() {
237
232
  this.kustoClient.close();
@@ -240,14 +235,12 @@ class ResourceManager {
240
235
  this.rankedStorageAccountSet.logResultToAccount(accountName, success);
241
236
  }
242
237
  }
243
- exports.ResourceManager = ResourceManager;
244
- const createStatusTableClient = (uri) => {
238
+ export const createStatusTableClient = (uri) => {
245
239
  const tableUrl = new URL(uri);
246
240
  const origin = tableUrl.origin;
247
241
  const sasToken = tableUrl.search;
248
242
  const tableName = tableUrl.pathname.replace("/", "");
249
- return new data_tables_1.TableClient(origin + sasToken, tableName);
243
+ return new TableClient(origin + sasToken, tableName);
250
244
  };
251
- exports.createStatusTableClient = createStatusTableClient;
252
- exports.default = ResourceManager;
245
+ export default ResourceManager;
253
246
  //# sourceMappingURL=resourceManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resourceManager.js","sourceRoot":"","sources":["../../src/resourceManager.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,uDAAsE;AACtE,mCAA2C;AAC3C,sDAAsD;AACtD,oDAAiD;AACjD,uEAAoE;AACpE,wDAAmD;AAEnD,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,IAAY,YAIX;AAJD,WAAY,YAAY;IACpB,iDAAK,CAAA;IACL,yDAAS,CAAA;IACT,iDAAK,CAAA;AACT,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB;AAED,MAAa,WAAW;IACpB,YAAqB,GAAW,EAAW,WAAmB,EAAW,YAA0B;QAA9E,QAAG,GAAH,GAAG,CAAQ;QAAW,gBAAW,GAAX,WAAW,CAAQ;QAAW,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;CAC1G;AAFD,kCAEC;AAED,MAAa,qBAAqB;IAC9B,YACa,mCAAyD,IAAI,EAC7D,yBAA+C,IAAI,EACnD,6BAAmD,IAAI,EACvD,aAAmC,IAAI,EACvC,eAAqC,IAAI;QAJzC,qCAAgC,GAAhC,gCAAgC,CAA6B;QAC7D,2BAAsB,GAAtB,sBAAsB,CAA6B;QACnD,+B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AAK,CAAC,iBAAiB;QACnB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAClD,IAAI,CAAC,YAAY,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SACjD;QAED,OAAO,IAAA,+BAAuB,EAAC,YAAa,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACzD,CAAC;IAED,KAAK;QACD,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,yBAAyB,CAAC,WAAmB,EAAE,OAAgB;QAC3D,IAAI,CAAC,uBAAuB,CAAC,kBAAkB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;CACJ;AAjPD,0CAiPC;AAEM,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAe,EAAE;IAChE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC/B,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC;IACjC,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACrD,OAAO,IAAI,yBAAW,CAAC,MAAM,GAAG,QAAQ,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC,CAAC;AANW,QAAA,uBAAuB,2BAMlC;AAEF,kBAAe,eAAe,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { Client, KustoDataErrors, TimeUtils } from \"azure-kusto-data\";\nimport { ExponentialRetry } from \"./retry\";\nimport { ContainerClient } from \"@azure/storage-blob\";\nimport { TableClient } from \"@azure/data-tables\";\nimport { RankedStorageAccountSet } from \"./rankedStorageAccountSet\";\nimport { QueueClient } from \"@azure/storage-queue\";\n\nconst ATTEMPT_COUNT = 4;\n\nexport enum ResourceType {\n Queue,\n Container,\n Table,\n}\n\nexport class ResourceURI {\n constructor(readonly uri: string, readonly accountName: string, readonly resourceType: ResourceType) {}\n}\n\nexport class IngestClientResources {\n constructor(\n readonly securedReadyForAggregationQueues: ResourceURI[] | null = null,\n readonly failedIngestionsQueues: ResourceURI[] | null = null,\n readonly successfulIngestionsQueues: ResourceURI[] | null = null,\n readonly containers: ResourceURI[] | null = null,\n readonly statusTables: ResourceURI[] | null = null\n ) {}\n\n valid() {\n const resources = [this.securedReadyForAggregationQueues, this.failedIngestionsQueues, this.failedIngestionsQueues, this.containers, this.statusTables];\n return resources.reduce((prev, current) => !!(prev && current), true);\n }\n}\n\nexport class ResourceManager {\n public readonly refreshPeriod: number;\n public refreshPeriodOnError: number;\n public ingestClientResources: IngestClientResources | null;\n public ingestClientResourcesLastUpdate: number | null;\n public authorizationContext: string | null;\n public authorizationContextLastUpdate: number | null;\n\n private baseSleepTimeSecs = 1;\n private baseJitterSecs = 1;\n private rankedStorageAccountSet: RankedStorageAccountSet;\n\n constructor(readonly kustoClient: Client, readonly isBrowser: boolean = false) {\n this.refreshPeriod = TimeUtils.toMilliseconds(1, 0, 0);\n this.refreshPeriodOnError = TimeUtils.toMilliseconds(0, 10, 0);\n\n this.ingestClientResources = null;\n this.ingestClientResourcesLastUpdate = null;\n\n this.authorizationContext = null;\n this.authorizationContextLastUpdate = null;\n\n this.rankedStorageAccountSet = new RankedStorageAccountSet();\n }\n\n async refreshIngestClientResources(): Promise<IngestClientResources> {\n const error = await this.tryRefresh(false);\n if (!this.ingestClientResources) {\n throw new Error(`Failed to fetch ingestion resources from service. ${error?.message}.\\n ${error?.stack}`);\n }\n\n return this.ingestClientResources;\n }\n\n async getIngestClientResourcesFromService(): Promise<IngestClientResources> {\n const retry = new ExponentialRetry(ATTEMPT_COUNT, this.baseSleepTimeSecs, this.baseJitterSecs);\n while (retry.shouldTry()) {\n try {\n const cmd = `.get ingestion resources ${this.isBrowser ? `with (EnableBlobCors='true', EnableQueueCors='true', EnableTableCors='true')` : \"\"}`;\n const response = await this.kustoClient.execute(\"NetDefaultDB\", cmd);\n const table = response.primaryResults[0];\n const resoures = new IngestClientResources(\n this.getResourceByName(table, \"SecuredReadyForAggregationQueue\", ResourceType.Queue),\n this.getResourceByName(table, \"FailedIngestionsQueue\", ResourceType.Queue),\n this.getResourceByName(table, \"SuccessfulIngestionsQueue\", ResourceType.Queue),\n this.getResourceByName(table, \"TempStorage\", ResourceType.Container),\n this.getResourceByName(table, \"IngestionsStatusTable\", ResourceType.Table)\n );\n\n if (!resoures.valid()) {\n throw new Error(\"Unexpected error occured - fetched data returned missing resource\");\n }\n\n return resoures;\n } catch (error: unknown) {\n if (!(error instanceof KustoDataErrors.ThrottlingError)) {\n throw error;\n }\n await retry.backoff();\n }\n }\n throw new Error(`Failed to get ingestion resources from server - the request was throttled ${ATTEMPT_COUNT} times.`);\n }\n\n getResourceByName(table: { rows: () => any }, resourceName: string, resourceType: ResourceType): ResourceURI[] {\n const result: ResourceURI[] = [];\n for (const row of table.rows()) {\n const typedRow = row as {\n ResourceTypeName: string;\n StorageRoot: string;\n };\n if (typedRow.ResourceTypeName === resourceName) {\n let accountName = \"\";\n if (resourceType === ResourceType.Queue) {\n accountName = new QueueClient(typedRow.StorageRoot).accountName;\n } else if (resourceType === ResourceType.Container) {\n accountName = new ContainerClient(typedRow.StorageRoot).accountName;\n }\n result.push(new ResourceURI(typedRow.StorageRoot, accountName, resourceType));\n }\n }\n return result;\n }\n\n pupulateStorageAccounts(): void {\n if (this.ingestClientResources == null) {\n return;\n }\n\n // containers\n const accounts = new Set<string>();\n if (this.ingestClientResources.containers != null) {\n for (const container of this.ingestClientResources.containers) {\n accounts.add(container.accountName);\n }\n }\n // queues\n if (this.ingestClientResources.securedReadyForAggregationQueues != null) {\n for (const queue of this.ingestClientResources.securedReadyForAggregationQueues) {\n accounts.add(queue.accountName);\n }\n }\n\n for (const account of accounts) {\n this.rankedStorageAccountSet.registerStorageAccount(account);\n }\n }\n\n groupResourcesByStorageAccount(resources: ResourceURI[]): Map<string, ResourceURI[]> {\n const result = new Map<string, ResourceURI[]>();\n for (const resource of resources) {\n if (!result.has(resource.accountName)) {\n result.set(resource.accountName, []);\n }\n result.get(resource.accountName)?.push(resource);\n }\n return result;\n }\n\n getRankedAndShuffledStorageAccounts(resources: ResourceURI[]): ResourceURI[][] {\n const resourcesByAccount = this.groupResourcesByStorageAccount(resources);\n const rankedStorageAccounts = this.rankedStorageAccountSet.getRankedShuffledAccounts();\n const result = new Array<ResourceURI[]>();\n for (const account of rankedStorageAccounts) {\n const accountName = account.getAccountName();\n if (resourcesByAccount.has(accountName)) {\n result.push(resourcesByAccount.get(accountName) as ResourceURI[]);\n }\n }\n return result;\n }\n\n getRoundRobinRankedAndShuffledResources(resources: ResourceURI[]): ResourceURI[] {\n const rankedAccounts = this.getRankedAndShuffledStorageAccounts(resources);\n const result = new Array<ResourceURI>();\n let index = 0;\n while (result.length < resources.length) {\n const account = rankedAccounts[index % rankedAccounts.length];\n if (account.length > 0) {\n result.push(account.shift() as ResourceURI);\n }\n index++;\n }\n return result;\n }\n\n async refreshAuthorizationContext(): Promise<string> {\n const error = await this.tryRefresh(true);\n\n if (this.authorizationContext == null) {\n throw new Error(`Failed to fetch Authorization context from service. ${error?.message}.\\n ${error?.stack}`);\n }\n\n return this.authorizationContext;\n }\n\n async tryRefresh(isAuthContextFetch: boolean): Promise<Error | null> {\n const resource = isAuthContextFetch ? this.authorizationContext?.trim() : this.ingestClientResources;\n const lastRefresh = isAuthContextFetch ? this.authorizationContextLastUpdate : this.ingestClientResourcesLastUpdate;\n const now = Date.now();\n let error: Error | null = null;\n if (!resource || !lastRefresh || lastRefresh + this.refreshPeriod <= now) {\n try {\n if (isAuthContextFetch) {\n this.authorizationContext = await this.getAuthorizationContextFromService();\n this.authorizationContextLastUpdate = now;\n } else {\n this.ingestClientResources = await this.getIngestClientResourcesFromService();\n this.ingestClientResourcesLastUpdate = now;\n this.pupulateStorageAccounts();\n }\n } catch (e) {\n error = e as Error;\n }\n }\n\n return error;\n }\n\n async getAuthorizationContextFromService() {\n const retry = new ExponentialRetry(ATTEMPT_COUNT, this.baseSleepTimeSecs, this.baseJitterSecs);\n while (retry.shouldTry()) {\n try {\n const response = await this.kustoClient.execute(\"NetDefaultDB\", \".get kusto identity token\");\n const next = response.primaryResults[0].rows().next();\n if (next.done) {\n throw new Error(\"Failed to get authorization context - got empty results\");\n }\n return next.value.toJSON<{ AuthorizationContext: string }>().AuthorizationContext;\n } catch (error: unknown) {\n if (!(error instanceof KustoDataErrors.ThrottlingError)) {\n throw error;\n }\n await retry.backoff();\n }\n }\n throw new Error(`Failed to get identity token from server - the request was throttled ${ATTEMPT_COUNT} times.`);\n }\n\n async getIngestionQueues(): Promise<ResourceURI[] | null> {\n const queues = (await this.refreshIngestClientResources()).securedReadyForAggregationQueues;\n return queues ? this.getRoundRobinRankedAndShuffledResources(queues) : null;\n }\n\n async getFailedIngestionsQueues(): Promise<ResourceURI[] | null> {\n return (await this.refreshIngestClientResources()).failedIngestionsQueues;\n }\n\n async getSuccessfulIngestionsQueues(): Promise<ResourceURI[] | null> {\n return (await this.refreshIngestClientResources()).successfulIngestionsQueues;\n }\n\n async getContainers(): Promise<ResourceURI[] | null> {\n const containers = (await this.refreshIngestClientResources()).containers;\n return containers ? this.getRoundRobinRankedAndShuffledResources(containers) : null;\n }\n\n async getAuthorizationContext(): Promise<string> {\n return this.refreshAuthorizationContext();\n }\n\n async getStatusTables(): Promise<ResourceURI[] | null> {\n return (await this.refreshIngestClientResources()).statusTables;\n }\n\n async createStatusTable() {\n const statusTables = await this.getStatusTables();\n if (!statusTables) {\n throw new Error(\"Failed to get status table\");\n }\n\n return createStatusTableClient(statusTables![0].uri);\n }\n\n close(): void {\n this.kustoClient.close();\n }\n\n reportResourceUsageResult(accountName: string, success: boolean): void {\n this.rankedStorageAccountSet.logResultToAccount(accountName, success);\n }\n}\n\nexport const createStatusTableClient = (uri: string): TableClient => {\n const tableUrl = new URL(uri);\n const origin = tableUrl.origin;\n const sasToken = tableUrl.search;\n const tableName = tableUrl.pathname.replace(\"/\", \"\");\n return new TableClient(origin + sasToken, tableName);\n};\n\nexport default ResourceManager;\n"]}
1
+ {"version":3,"file":"resourceManager.js","sourceRoot":"","sources":["../../src/resourceManager.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAU,eAAe,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACpB,iDAAK,CAAA;IACL,yDAAS,CAAA;IACT,iDAAK,CAAA;AACT,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED,MAAM,OAAO,WAAW;IACpB,YACa,GAAW,EACX,WAAmB,EACnB,YAA0B;QAF1B,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAQ;QACnB,iBAAY,GAAZ,YAAY,CAAc;IACpC,CAAC;CACP;AAED,MAAM,OAAO,qBAAqB;IAC9B,YACa,mCAAyD,IAAI,EAC7D,yBAA+C,IAAI,EACnD,6BAAmD,IAAI,EACvD,aAAmC,IAAI,EACvC,eAAqC,IAAI;QAJzC,qCAAgC,GAAhC,gCAAgC,CAA6B;QAC7D,2BAAsB,GAAtB,sBAAsB,CAA6B;QACnD,+BAA0B,GAA1B,0BAA0B,CAA6B;QACvD,eAAU,GAAV,UAAU,CAA6B;QACvC,iBAAY,GAAZ,YAAY,CAA6B;IACnD,CAA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import { Client, KustoDataErrors, TimeUtils } from \"azure-kusto-data\";\nimport { ExponentialRetry } from \"./retry.js\";\nimport { ContainerClient } from \"@azure/storage-blob\";\nimport { TableClient } from \"@azure/data-tables\";\nimport { RankedStorageAccountSet } from \"./rankedStorageAccountSet.js\";\nimport { QueueClient } from \"@azure/storage-queue\";\n\nconst ATTEMPT_COUNT = 4;\n\nexport enum ResourceType {\n Queue,\n Container,\n Table,\n}\n\nexport class ResourceURI {\n constructor(\n readonly uri: string,\n readonly accountName: string,\n readonly resourceType: ResourceType,\n ) {}\n}\n\nexport class IngestClientResources {\n constructor(\n readonly securedReadyForAggregationQueues: ResourceURI[] | null = null,\n readonly failedIngestionsQueues: ResourceURI[] | null = null,\n readonly successfulIngestionsQueues: ResourceURI[] | null = null,\n readonly containers: ResourceURI[] | null = null,\n readonly statusTables: ResourceURI[] | null = null,\n ) {}\n\n valid() {\n const resources = [this.securedReadyForAggregationQueues, this.failedIngestionsQueues, this.failedIngestionsQueues, this.containers, this.statusTables];\n return resources.reduce((prev, current) => !!(prev && current), true);\n }\n}\n\nexport class ResourceManager {\n public readonly refreshPeriod: number;\n public refreshPeriodOnError: number;\n public ingestClientResources: IngestClientResources | null;\n public ingestClientResourcesLastUpdate: number | null;\n public authorizationContext: string | null;\n public authorizationContextLastUpdate: number | null;\n\n private baseSleepTimeSecs = 1;\n private baseJitterSecs = 1;\n private rankedStorageAccountSet: RankedStorageAccountSet;\n\n constructor(\n readonly kustoClient: Client,\n readonly isBrowser: boolean = false,\n ) {\n this.refreshPeriod = TimeUtils.toMilliseconds(1, 0, 0);\n this.refreshPeriodOnError = TimeUtils.toMilliseconds(0, 10, 0);\n\n this.ingestClientResources = null;\n this.ingestClientResourcesLastUpdate = null;\n\n this.authorizationContext = null;\n this.authorizationContextLastUpdate = null;\n\n this.rankedStorageAccountSet = new RankedStorageAccountSet();\n }\n\n async refreshIngestClientResources(): Promise<IngestClientResources> {\n const error = await this.tryRefresh(false);\n if (!this.ingestClientResources) {\n throw new Error(`Failed to fetch ingestion resources from service. ${error?.message}.\\n ${error?.stack}`);\n }\n\n return this.ingestClientResources;\n }\n\n async getIngestClientResourcesFromService(): Promise<IngestClientResources> {\n const retry = new ExponentialRetry(ATTEMPT_COUNT, this.baseSleepTimeSecs, this.baseJitterSecs);\n while (retry.shouldTry()) {\n try {\n const cmd = `.get ingestion resources ${this.isBrowser ? `with (EnableBlobCors='true', EnableQueueCors='true', EnableTableCors='true')` : \"\"}`;\n const response = await this.kustoClient.execute(\"NetDefaultDB\", cmd);\n const table = response.primaryResults[0];\n const resoures = new IngestClientResources(\n this.getResourceByName(table, \"SecuredReadyForAggregationQueue\", ResourceType.Queue),\n this.getResourceByName(table, \"FailedIngestionsQueue\", ResourceType.Queue),\n this.getResourceByName(table, \"SuccessfulIngestionsQueue\", ResourceType.Queue),\n this.getResourceByName(table, \"TempStorage\", ResourceType.Container),\n this.getResourceByName(table, \"IngestionsStatusTable\", ResourceType.Table),\n );\n\n if (!resoures.valid()) {\n throw new Error(\"Unexpected error occured - fetched data returned missing resource\");\n }\n\n return resoures;\n } catch (error: unknown) {\n if (!(error instanceof KustoDataErrors.ThrottlingError)) {\n throw error;\n }\n await retry.backoff();\n }\n }\n throw new Error(`Failed to get ingestion resources from server - the request was throttled ${ATTEMPT_COUNT} times.`);\n }\n\n getResourceByName(table: { rows: () => any }, resourceName: string, resourceType: ResourceType): ResourceURI[] {\n const result: ResourceURI[] = [];\n for (const row of table.rows()) {\n const typedRow = row as {\n ResourceTypeName: string;\n StorageRoot: string;\n };\n if (typedRow.ResourceTypeName === resourceName) {\n let accountName = \"\";\n if (resourceType === ResourceType.Queue) {\n accountName = new QueueClient(typedRow.StorageRoot).accountName;\n } else if (resourceType === ResourceType.Container) {\n accountName = new ContainerClient(typedRow.StorageRoot).accountName;\n }\n result.push(new ResourceURI(typedRow.StorageRoot, accountName, resourceType));\n }\n }\n return result;\n }\n\n pupulateStorageAccounts(): void {\n if (this.ingestClientResources == null) {\n return;\n }\n\n // containers\n const accounts = new Set<string>();\n if (this.ingestClientResources.containers != null) {\n for (const container of this.ingestClientResources.containers) {\n accounts.add(container.accountName);\n }\n }\n // queues\n if (this.ingestClientResources.securedReadyForAggregationQueues != null) {\n for (const queue of this.ingestClientResources.securedReadyForAggregationQueues) {\n accounts.add(queue.accountName);\n }\n }\n\n for (const account of accounts) {\n this.rankedStorageAccountSet.registerStorageAccount(account);\n }\n }\n\n groupResourcesByStorageAccount(resources: ResourceURI[]): Map<string, ResourceURI[]> {\n const result = new Map<string, ResourceURI[]>();\n for (const resource of resources) {\n if (!result.has(resource.accountName)) {\n result.set(resource.accountName, []);\n }\n result.get(resource.accountName)?.push(resource);\n }\n return result;\n }\n\n getRankedAndShuffledStorageAccounts(resources: ResourceURI[]): ResourceURI[][] {\n const resourcesByAccount = this.groupResourcesByStorageAccount(resources);\n const rankedStorageAccounts = this.rankedStorageAccountSet.getRankedShuffledAccounts();\n const result = new Array<ResourceURI[]>();\n for (const account of rankedStorageAccounts) {\n const accountName = account.getAccountName();\n if (resourcesByAccount.has(accountName)) {\n result.push(resourcesByAccount.get(accountName) as ResourceURI[]);\n }\n }\n return result;\n }\n\n getRoundRobinRankedAndShuffledResources(resources: ResourceURI[]): ResourceURI[] {\n const rankedAccounts = this.getRankedAndShuffledStorageAccounts(resources);\n const result = new Array<ResourceURI>();\n let index = 0;\n while (result.length < resources.length) {\n const account = rankedAccounts[index % rankedAccounts.length];\n if (account.length > 0) {\n result.push(account.shift() as ResourceURI);\n }\n index++;\n }\n return result;\n }\n\n async refreshAuthorizationContext(): Promise<string> {\n const error = await this.tryRefresh(true);\n\n if (this.authorizationContext == null) {\n throw new Error(`Failed to fetch Authorization context from service. ${error?.message}.\\n ${error?.stack}`);\n }\n\n return this.authorizationContext;\n }\n\n async tryRefresh(isAuthContextFetch: boolean): Promise<Error | null> {\n const resource = isAuthContextFetch ? this.authorizationContext?.trim() : this.ingestClientResources;\n const lastRefresh = isAuthContextFetch ? this.authorizationContextLastUpdate : this.ingestClientResourcesLastUpdate;\n const now = Date.now();\n let error: Error | null = null;\n if (!resource || !lastRefresh || lastRefresh + this.refreshPeriod <= now) {\n try {\n if (isAuthContextFetch) {\n this.authorizationContext = await this.getAuthorizationContextFromService();\n this.authorizationContextLastUpdate = now;\n } else {\n this.ingestClientResources = await this.getIngestClientResourcesFromService();\n this.ingestClientResourcesLastUpdate = now;\n this.pupulateStorageAccounts();\n }\n } catch (e) {\n error = e as Error;\n }\n }\n\n return error;\n }\n\n async getAuthorizationContextFromService() {\n const retry = new ExponentialRetry(ATTEMPT_COUNT, this.baseSleepTimeSecs, this.baseJitterSecs);\n while (retry.shouldTry()) {\n try {\n const response = await this.kustoClient.execute(\"NetDefaultDB\", \".get kusto identity token\");\n const next = response.primaryResults[0].rows().next();\n if (next.done) {\n throw new Error(\"Failed to get authorization context - got empty results\");\n }\n return next.value.toJSON<{ AuthorizationContext: string }>().AuthorizationContext;\n } catch (error: unknown) {\n if (!(error instanceof KustoDataErrors.ThrottlingError)) {\n throw error;\n }\n await retry.backoff();\n }\n }\n throw new Error(`Failed to get identity token from server - the request was throttled ${ATTEMPT_COUNT} times.`);\n }\n\n async getIngestionQueues(): Promise<ResourceURI[] | null> {\n const queues = (await this.refreshIngestClientResources()).securedReadyForAggregationQueues;\n return queues ? this.getRoundRobinRankedAndShuffledResources(queues) : null;\n }\n\n async getFailedIngestionsQueues(): Promise<ResourceURI[] | null> {\n return (await this.refreshIngestClientResources()).failedIngestionsQueues;\n }\n\n async getSuccessfulIngestionsQueues(): Promise<ResourceURI[] | null> {\n return (await this.refreshIngestClientResources()).successfulIngestionsQueues;\n }\n\n async getContainers(): Promise<ResourceURI[] | null> {\n const containers = (await this.refreshIngestClientResources()).containers;\n return containers ? this.getRoundRobinRankedAndShuffledResources(containers) : null;\n }\n\n async getAuthorizationContext(): Promise<string> {\n return this.refreshAuthorizationContext();\n }\n\n async getStatusTables(): Promise<ResourceURI[] | null> {\n return (await this.refreshIngestClientResources()).statusTables;\n }\n\n async createStatusTable() {\n const statusTables = await this.getStatusTables();\n if (!statusTables) {\n throw new Error(\"Failed to get status table\");\n }\n\n return createStatusTableClient(statusTables![0].uri);\n }\n\n close(): void {\n this.kustoClient.close();\n }\n\n reportResourceUsageResult(accountName: string, success: boolean): void {\n this.rankedStorageAccountSet.logResultToAccount(accountName, success);\n }\n}\n\nexport const createStatusTableClient = (uri: string): TableClient => {\n const tableUrl = new URL(uri);\n const origin = tableUrl.origin;\n const sasToken = tableUrl.search;\n const tableName = tableUrl.pathname.replace(\"/\", \"\");\n return new TableClient(origin + sasToken, tableName);\n};\n\nexport default ResourceManager;\n"]}
@@ -1,15 +1,11 @@
1
- "use strict";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.ExponentialRetry = exports.sleep = void 0;
6
- const sleep = (ms) => {
3
+ export const sleep = (ms) => {
7
4
  return new Promise((resolve) => {
8
5
  setTimeout(resolve, ms);
9
6
  });
10
7
  };
11
- exports.sleep = sleep;
12
- class ExponentialRetry {
8
+ export class ExponentialRetry {
13
9
  constructor(attemptCount, sleepBaseSecs, maxJitterSecs) {
14
10
  this.attemptCount = attemptCount;
15
11
  this.sleepBaseSecs = sleepBaseSecs;
@@ -27,11 +23,10 @@ class ExponentialRetry {
27
23
  }
28
24
  const base = this.sleepBaseSecs * Math.pow(2, this.currentAttempt - 1);
29
25
  const jitter = Math.floor(this.maxJitterSecs * Math.random());
30
- await (0, exports.sleep)(1000 * (base + jitter));
26
+ await sleep(1000 * (base + jitter));
31
27
  }
32
28
  shouldTry() {
33
29
  return this.currentAttempt < this.attemptCount;
34
30
  }
35
31
  }
36
- exports.ExponentialRetry = ExponentialRetry;
37
32
  //# sourceMappingURL=retry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAE3B,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE;IAC/C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAJW,QAAA,KAAK,SAIhB;AAEF,MAAa,gBAAgB;IAGzB,YAAmB,YAAoB,EAAS,aAAqB,EAAS,aAAqB;QAAhF,iBAAY,GAAZ,YAAY,CAAQ;QAAS,kBAAa,GAAb,aAAa,CAAQ;QAAS,kBAAa,GAAb,aAAa,CAAQ;QAC/F,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,OAAO;QAChB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;SAC3C;QAED,IAAI,CAAC,cAAc,EAAE,CAAC;QAEtB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE;YACnB,6CAA6C;YAC7C,OAAO;SACV;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;QACvE,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAC9D,MAAM,IAAA,aAAK,EAAC,IAAI,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;IACxC,CAAC;IAEM,SAAS;QACZ,OAAO,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC;IACnD,CAAC;CACJ;AA3BD,4CA2BC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport const sleep = (ms: number): Promise<void> => {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n};\n\nexport class ExponentialRetry {\n public currentAttempt: number;\n\n constructor(public attemptCount: number, public sleepBaseSecs: number, public maxJitterSecs: number) {\n this.currentAttempt = 0;\n }\n\n public async backoff(): Promise<void> {\n if (!this.shouldTry()) {\n throw new Error(\"Max retries exceeded\");\n }\n\n this.currentAttempt++;\n\n if (!this.shouldTry()) {\n // This was the last retry - no need to sleep\n return;\n }\n\n const base = this.sleepBaseSecs * Math.pow(2, this.currentAttempt - 1);\n const jitter = Math.floor(this.maxJitterSecs * Math.random());\n await sleep(1000 * (base + jitter));\n }\n\n public shouldTry(): boolean {\n return this.currentAttempt < this.attemptCount;\n }\n}\n"]}
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE;IAC/C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,MAAM,OAAO,gBAAgB;IAGzB,YACW,YAAoB,EACpB,aAAqB,EACrB,aAAqB;QAFrB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,kBAAa,GAAb,aAAa,CAAQ;QACrB,kBAAa,GAAb,aAAa,CAAQ;QAE5B,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,OAAO;QAChB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,CAAC,cAAc,EAAE,CAAC;QAEtB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;YACpB,6CAA6C;YAC7C,OAAO;QACX,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;QACvE,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAC9D,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;IACxC,CAAC;IAEM,SAAS;QACZ,OAAO,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC;IACnD,CAAC;CACJ","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport const sleep = (ms: number): Promise<void> => {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n};\n\nexport class ExponentialRetry {\n public currentAttempt: number;\n\n constructor(\n public attemptCount: number,\n public sleepBaseSecs: number,\n public maxJitterSecs: number,\n ) {\n this.currentAttempt = 0;\n }\n\n public async backoff(): Promise<void> {\n if (!this.shouldTry()) {\n throw new Error(\"Max retries exceeded\");\n }\n\n this.currentAttempt++;\n\n if (!this.shouldTry()) {\n // This was the last retry - no need to sleep\n return;\n }\n\n const base = this.sleepBaseSecs * Math.pow(2, this.currentAttempt - 1);\n const jitter = Math.floor(this.maxJitterSecs * Math.random());\n await sleep(1000 * (base + jitter));\n }\n\n public shouldTry(): boolean {\n return this.currentAttempt < this.attemptCount;\n }\n}\n"]}
@@ -1,10 +1,7 @@
1
- "use strict";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.KustoIngestStatusQueues = exports.StatusMessage = void 0;
6
- const statusQ_1 = require("./statusQ");
7
- class StatusMessage {
3
+ import { StatusQueue } from "./statusQ.js";
4
+ export class StatusMessage {
8
5
  constructor(raw, obj, extraProps) {
9
6
  let props = ["OperationId", "Database", "Table", "IngestionSourceId", "IngestionSourcePath", "RootActivityId"];
10
7
  if (extraProps && extraProps.length > 0) {
@@ -16,7 +13,6 @@ class StatusMessage {
16
13
  }
17
14
  }
18
15
  }
19
- exports.StatusMessage = StatusMessage;
20
16
  class SuccessMessage extends StatusMessage {
21
17
  constructor(raw, obj) {
22
18
  super(raw, obj, ["SucceededOn"]);
@@ -27,12 +23,11 @@ class FailureMessage extends StatusMessage {
27
23
  super(raw, obj, ["FailedOn", "Details", "ErrorCode", "FailureStatus", "OriginatesFromUpdatePolicy", "ShouldRetry"]);
28
24
  }
29
25
  }
30
- class KustoIngestStatusQueues {
26
+ export class KustoIngestStatusQueues {
31
27
  constructor(kustoIngestClient) {
32
- this.success = new statusQ_1.StatusQueue(() => kustoIngestClient.resourceManager.getSuccessfulIngestionsQueues().then((r) => r), SuccessMessage);
33
- this.failure = new statusQ_1.StatusQueue(() => kustoIngestClient.resourceManager.getFailedIngestionsQueues().then((r) => r), FailureMessage);
28
+ this.success = new StatusQueue(() => kustoIngestClient.resourceManager.getSuccessfulIngestionsQueues().then((r) => r), SuccessMessage);
29
+ this.failure = new StatusQueue(() => kustoIngestClient.resourceManager.getFailedIngestionsQueues().then((r) => r), FailureMessage);
34
30
  }
35
31
  }
36
- exports.KustoIngestStatusQueues = KustoIngestStatusQueues;
37
- exports.default = KustoIngestStatusQueues;
32
+ export default KustoIngestStatusQueues;
38
33
  //# sourceMappingURL=status.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/status.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,uCAAwC;AAIxC,MAAa,aAAa;IAStB,YAAY,GAAQ,EAAE,GAAQ,EAAE,UAA2B;QACvD,IAAI,KAAK,GAAa,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;QAEzH,IAAI,UAAU,IAAI,UAAU,CAAC,MAA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yright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { StatusQueue } from \"./statusQ\";\nimport KustoIngestClient from \"./ingestClient\";\nimport { ResourceURI } from \"./resourceManager\";\n\nexport class StatusMessage {\n OperationId?: string;\n Database?: string;\n Table?: string;\n IngestionSourceId?: string;\n IngestionSourcePath?: string;\n RootActivityId?: string;\n\n [other: string]: any;\n constructor(raw: any, obj: any, extraProps: string[] | null) {\n let props: string[] = [\"OperationId\", \"Database\", \"Table\", \"IngestionSourceId\", \"IngestionSourcePath\", \"RootActivityId\"];\n\n if (extraProps && extraProps.length > 0) {\n props = props.concat(extraProps);\n }\n\n const _obj: Record<string, any> = obj || JSON.parse(raw || JSON.stringify(raw));\n\n for (const prop of props) {\n this[prop] = _obj[prop];\n }\n }\n}\n\nclass SuccessMessage extends StatusMessage {\n SucceededOn?: string;\n\n constructor(raw: any, obj: any) {\n super(raw, obj, [\"SucceededOn\"]);\n }\n}\n\nclass FailureMessage extends StatusMessage {\n FailedOn?: string;\n Details?: string;\n ErrorCode?: string;\n FailureStatus?: string;\n OriginatesFromUpdatePolicy?: string;\n ShouldRetry?: string;\n constructor(raw: any, obj: any) {\n super(raw, obj, [\"FailedOn\", \"Details\", \"ErrorCode\", \"FailureStatus\", \"OriginatesFromUpdatePolicy\", \"ShouldRetry\"]);\n }\n}\n\nexport class KustoIngestStatusQueues {\n success: StatusQueue;\n failure: StatusQueue;\n constructor(kustoIngestClient: KustoIngestClient) {\n this.success = new StatusQueue(() => kustoIngestClient.resourceManager.getSuccessfulIngestionsQueues().then((r) => r as ResourceURI[]), SuccessMessage);\n this.failure = new StatusQueue(() => kustoIngestClient.resourceManager.getFailedIngestionsQueues().then((r) => r as ResourceURI[]), FailureMessage);\n }\n}\n\nexport default KustoIngestStatusQueues;\n"]}
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/status.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,WAAW,EAAE,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AAI,CAAC,OAAO,GAAG,IAAI,WAAW,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC,yBAAyB,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAkB,CAAC,EAAE,cAAc,CAAC,CAAC;IACxJ,CAAC;CACJ;AAED,eAAe,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { StatusQueue } from \"./statusQ.js\";\nimport KustoIngestClient from \"./ingestClient.js\";\nimport { ResourceURI } from \"./resourceManager.js\";\n\nexport class StatusMessage {\n OperationId?: string;\n Database?: string;\n Table?: string;\n IngestionSourceId?: string;\n IngestionSourcePath?: string;\n RootActivityId?: string;\n\n [other: string]: any;\n constructor(raw: any, obj: any, extraProps: string[] | null) {\n let props: string[] = [\"OperationId\", \"Database\", \"Table\", \"IngestionSourceId\", \"IngestionSourcePath\", \"RootActivityId\"];\n\n if (extraProps && extraProps.length > 0) {\n props = props.concat(extraProps);\n }\n\n const _obj: Record<string, any> = obj || JSON.parse(raw || JSON.stringify(raw));\n\n for (const prop of props) {\n this[prop] = _obj[prop];\n }\n }\n}\n\nclass SuccessMessage extends StatusMessage {\n SucceededOn?: string;\n\n constructor(raw: any, obj: any) {\n super(raw, obj, [\"SucceededOn\"]);\n }\n}\n\nclass FailureMessage extends StatusMessage {\n FailedOn?: string;\n Details?: string;\n ErrorCode?: string;\n FailureStatus?: string;\n OriginatesFromUpdatePolicy?: string;\n ShouldRetry?: string;\n constructor(raw: any, obj: any) {\n super(raw, obj, [\"FailedOn\", \"Details\", \"ErrorCode\", \"FailureStatus\", \"OriginatesFromUpdatePolicy\", \"ShouldRetry\"]);\n }\n}\n\nexport class KustoIngestStatusQueues {\n success: StatusQueue;\n failure: StatusQueue;\n constructor(kustoIngestClient: KustoIngestClient) {\n this.success = new StatusQueue(() => kustoIngestClient.resourceManager.getSuccessfulIngestionsQueues().then((r) => r as ResourceURI[]), SuccessMessage);\n this.failure = new StatusQueue(() => kustoIngestClient.resourceManager.getFailedIngestionsQueues().then((r) => r as ResourceURI[]), FailureMessage);\n }\n}\n\nexport default KustoIngestStatusQueues;\n"]}
@@ -1,9 +1,6 @@
1
- "use strict";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.StatusQueue = void 0;
6
- const storage_queue_1 = require("@azure/storage-queue");
3
+ import { QueueClient } from "@azure/storage-queue";
7
4
  class QueueDetails {
8
5
  constructor(name, service) {
9
6
  this.name = name;
@@ -19,7 +16,7 @@ const shuffle = (a) => {
19
16
  }
20
17
  return a;
21
18
  };
22
- class StatusQueue {
19
+ export class StatusQueue {
23
20
  constructor(getQueuesFunc, messageCls) {
24
21
  this.getQueuesFunc = getQueuesFunc;
25
22
  this.messageCls = messageCls;
@@ -33,7 +30,7 @@ class StatusQueue {
33
30
  // chop off sas
34
31
  const indexOfSas = q.uri.indexOf("?");
35
32
  const name = indexOfSas > 0 ? q.uri.substring(0, indexOfSas) : q.uri;
36
- return new QueueDetails(name, new storage_queue_1.QueueClient(fullUri));
33
+ return new QueueDetails(name, new QueueClient(fullUri));
37
34
  });
38
35
  }
39
36
  async isEmpty() {
@@ -115,5 +112,4 @@ class StatusQueue {
115
112
  return partial.result.concat(final.result);
116
113
  }
117
114
  }
118
- exports.StatusQueue = StatusQueue;
119
115
  //# sourceMappingURL=statusQ.js.map