fix(core): Resolve TypeScript strict mode and ES client API compatibility issues for v3.0.0
- Fix ES client v8+ API: use document/doc instead of body for index/update operations - Add type assertions (as any) for ES client ILM, template, and search APIs - Fix strict null checks with proper undefined handling (nullish coalescing) - Fix MetricsCollector interface to match required method signatures - Fix Logger.error signature compatibility in plugins - Resolve TermsQuery type index signature conflict - Remove sourceMap from tsconfig (handled by tsbuild with inlineSourceMap)
This commit is contained in:
@@ -274,12 +274,16 @@ export class AggregationBuilder {
|
||||
/**
|
||||
* Add a sub-aggregation to the last defined aggregation
|
||||
*/
|
||||
subAggregation(name: string, configure: (builder: AggregationBuilder) => void): this {
|
||||
subAggregation(_name: string, configure: (builder: AggregationBuilder) => void): this {
|
||||
if (!this.currentAggName) {
|
||||
throw new Error('Cannot add sub-aggregation: no parent aggregation defined');
|
||||
}
|
||||
|
||||
const parentAgg = this.aggregations[this.currentAggName];
|
||||
if (!parentAgg) {
|
||||
throw new Error('Parent aggregation not found');
|
||||
}
|
||||
|
||||
const subBuilder = new AggregationBuilder();
|
||||
configure(subBuilder);
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ import type { AggregationBuilder } from './aggregation-builder.js';
|
||||
import { createAggregationBuilder } from './aggregation-builder.js';
|
||||
import { ElasticsearchConnectionManager } from '../../core/connection/connection-manager.js';
|
||||
import { defaultLogger } from '../../core/observability/logger.js';
|
||||
import { defaultMetrics } from '../../core/observability/metrics.js';
|
||||
import { defaultTracing } from '../../core/observability/tracing.js';
|
||||
import { defaultMetricsCollector } from '../../core/observability/metrics.js';
|
||||
import { defaultTracer } from '../../core/observability/tracing.js';
|
||||
|
||||
/**
|
||||
* Fluent query builder for type-safe Elasticsearch queries
|
||||
@@ -522,7 +522,7 @@ export class QueryBuilder<T = unknown> {
|
||||
* Execute the query and return results
|
||||
*/
|
||||
async execute(): Promise<SearchResult<T>> {
|
||||
const span = defaultTracing.createSpan('query.execute', {
|
||||
const span = defaultTracer.startSpan('query.execute', {
|
||||
'db.system': 'elasticsearch',
|
||||
'db.operation': 'search',
|
||||
'db.elasticsearch.index': this.index,
|
||||
@@ -545,13 +545,13 @@ export class QueryBuilder<T = unknown> {
|
||||
const result = await client.search<T>({
|
||||
index: this.index,
|
||||
...searchOptions,
|
||||
});
|
||||
} as any);
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
|
||||
// Record metrics
|
||||
defaultMetrics.requestsTotal.inc({ operation: 'search', index: this.index });
|
||||
defaultMetrics.requestDuration.observe({ operation: 'search', index: this.index }, duration);
|
||||
defaultMetricsCollector.requestsTotal.inc({ operation: 'search', index: this.index });
|
||||
defaultMetricsCollector.requestDuration.observe(duration / 1000, { operation: 'search', index: this.index });
|
||||
|
||||
defaultLogger.info('Query executed successfully', {
|
||||
index: this.index,
|
||||
@@ -568,7 +568,7 @@ export class QueryBuilder<T = unknown> {
|
||||
|
||||
return result as SearchResult<T>;
|
||||
} catch (error) {
|
||||
defaultMetrics.requestErrors.inc({ operation: 'search', index: this.index });
|
||||
defaultMetricsCollector.requestErrors.inc({ operation: 'search', index: this.index });
|
||||
defaultLogger.error('Query execution failed', { index: this.index, error: error instanceof Error ? error.message : String(error) });
|
||||
span.recordException(error as Error);
|
||||
span.end();
|
||||
@@ -596,7 +596,7 @@ export class QueryBuilder<T = unknown> {
|
||||
* Count documents matching the query
|
||||
*/
|
||||
async count(): Promise<number> {
|
||||
const span = defaultTracing.createSpan('query.count', {
|
||||
const span = defaultTracer.startSpan('query.count', {
|
||||
'db.system': 'elasticsearch',
|
||||
'db.operation': 'count',
|
||||
'db.elasticsearch.index': this.index,
|
||||
@@ -609,7 +609,7 @@ export class QueryBuilder<T = unknown> {
|
||||
const result = await client.count({
|
||||
index: this.index,
|
||||
...(searchOptions.query && { query: searchOptions.query }),
|
||||
});
|
||||
} as any);
|
||||
|
||||
span.end();
|
||||
return result.count;
|
||||
|
||||
@@ -116,8 +116,7 @@ export interface TermQuery {
|
||||
*/
|
||||
export interface TermsQuery {
|
||||
terms: {
|
||||
[field: string]: Array<string | number | boolean>;
|
||||
boost?: number;
|
||||
[field: string]: Array<string | number | boolean> | number | undefined;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user