UNPKG

@datastax/astra-db-ts

Version:
168 lines (167 loc) 6.56 kB
"use strict"; // Copyright Datastax, Inc // SPDX-License-Identifier: Apache-2.0 // import { DataAPIClientEvent } from '@/src/lib/logging/events'; needs to be like this or it errors Object.defineProperty(exports, "__esModule", { value: true }); exports.AdminCommandWarningsEvent = exports.AdminCommandFailedEvent = exports.AdminCommandSucceededEvent = exports.AdminCommandPollingEvent = exports.AdminCommandStartedEvent = exports.AdminCommandEvent = void 0; const base_event_js_1 = require("../lib/logging/base-event.js"); class AdminCommandEvent extends base_event_js_1.BaseClientEvent { constructor(name, requestId, baseUrl, info, longRunning) { super(name, requestId, undefined); Object.defineProperty(this, "url", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "requestMethod", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "requestBody", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "requestParams", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "isLongRunning", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "invokingMethod", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.url = baseUrl + info.path; this.requestMethod = info.method; this.requestBody = info.data; this.requestParams = info.params; this.isLongRunning = longRunning; this.invokingMethod = info.methodName; } getMessagePrefix() { return `(${this.invokingMethod}) ${this.requestMethod} ${this.url}${this.requestParams ? '?' : ''}${new URLSearchParams(this.requestParams).toString()}`; } _modifyEventForFormatVerbose() { } } exports.AdminCommandEvent = AdminCommandEvent; class AdminCommandStartedEvent extends AdminCommandEvent { constructor(requestId, baseUrl, info, longRunning, timeout) { super('AdminCommandStarted', requestId, baseUrl, info, longRunning); Object.defineProperty(this, "timeout", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.timeout = timeout; } getMessage() { return `${this.isLongRunning ? '(blocking) ' : ''}${this.requestBody ? `${JSON.stringify(this.requestBody)}` : ''}`; } } exports.AdminCommandStartedEvent = AdminCommandStartedEvent; class AdminCommandPollingEvent extends AdminCommandEvent { constructor(requestId, baseUrl, info, started, interval, pollCount) { super('AdminCommandPolling', requestId, baseUrl, info, true); Object.defineProperty(this, "elapsed", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "pollInterval", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "pollCount", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.elapsed = performance.now() - started; this.pollInterval = interval; this.pollCount = pollCount; } getMessage() { return `(poll #${this.pollCount}; ${~~this.elapsed}ms elapsed)`; } } exports.AdminCommandPollingEvent = AdminCommandPollingEvent; class AdminCommandSucceededEvent extends AdminCommandEvent { constructor(requestId, baseUrl, info, longRunning, data, started) { super('AdminCommandSucceeded', requestId, baseUrl, info, longRunning); Object.defineProperty(this, "duration", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "responseBody", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.duration = performance.now() - started; this.responseBody = data || undefined; } getMessage() { return `${this.requestBody ? `${JSON.stringify(this.requestBody)} ` : ''}(${~~this.duration}ms)`; } } exports.AdminCommandSucceededEvent = AdminCommandSucceededEvent; class AdminCommandFailedEvent extends AdminCommandEvent { constructor(requestId, baseUrl, info, longRunning, error, started) { super('AdminCommandFailed', requestId, baseUrl, info, longRunning); Object.defineProperty(this, "duration", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "error", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.duration = performance.now() - started; this.error = error; } getMessage() { return `${this.requestBody ? `${JSON.stringify(this.requestBody)} ` : ''}(${~~this.duration}ms) ERROR: ${JSON.stringify(this.error.message)}`; } } exports.AdminCommandFailedEvent = AdminCommandFailedEvent; class AdminCommandWarningsEvent extends AdminCommandEvent { constructor(requestId, baseUrl, info, longRunning, warnings) { super('AdminCommandWarnings', requestId, baseUrl, info, longRunning); Object.defineProperty(this, "warnings", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.warnings = warnings; } getMessage() { return `${this.requestBody ? `${JSON.stringify(this.requestBody)} ` : ''}WARNINGS: ${this.warnings.map(w => JSON.stringify(w.message)).join(', ')}`; } } exports.AdminCommandWarningsEvent = AdminCommandWarningsEvent;