Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update typescript to v5.7.3 #1341

Merged
merged 13 commits into from
Jan 16, 2025
6 changes: 3 additions & 3 deletions asset/src/elasticsearch_reader_api/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ConvictSchema, AnyObject, ValidatedJobConfig,
toNumber, isString, isNumber, getTypeOf,
isNotNil, has
isNotNil, has, isKey
} from '@terascope/job-components';
import elasticAPI from '@terascope/elasticsearch-api';
import moment from 'moment';
Expand Down Expand Up @@ -151,7 +151,7 @@ export const schema = {
ms: 'ms'
};
if (!isString(val)) throw new Error(`Invalid parameter time_resolution, it must be of type string, was given ${getTypeOf(val)}`);
if (!obj[val]) throw new Error('Invalid time_resolution, must be set in either "s"[seconds] or "ms"[milliseconds]');
if (!isKey(obj, val)) throw new Error('Invalid time_resolution, must be set in either "s"[seconds] or "ms"[milliseconds]');

return obj[val];
}
Expand Down Expand Up @@ -193,7 +193,7 @@ export const schema = {
if (val) {
const options = { asc: true, desc: true };
if (typeof val !== 'string') throw new Error('Invalid geo_sort_order parameter, must be a string IF specified');
if (!options[val]) throw new Error('If geo_sort_order is specified it must be either "asc" or "desc"');
if (!isKey(options, val)) throw new Error('If geo_sort_order is specified it must be either "asc" or "desc"');
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"node-notifier": "~10.0.1",
"teraslice-test-harness": "~1.3.1",
"ts-jest": "~29.2.5",
"typescript": "~5.2.2"
"typescript": "~5.7.3"
},
"engines": {
"node": ">=18.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import elasticAPI from '@terascope/elasticsearch-api';
import { isNil, isPlainObject, isString } from '@terascope/utils';
import { isKey, isNil, isPlainObject, isString } from '@terascope/utils';
import { ElasticsearchBulkSender } from './ElasticsearchBulkSender.js';
import { ElasticsearchSenderConfig } from './interfaces.js';

Expand Down Expand Up @@ -33,7 +33,7 @@ function validateConfig(input: unknown): ElasticsearchSenderConfig {
const actionSet = new Set();
// only one of these should be set to true at a time
['delete', 'create', 'update', 'index', 'upsert'].forEach((key: string) => {
if (config[key] === true) actionSet.add(key);
if (isKey(config, key) && config[key] === true) actionSet.add(key);
if (actionSet.size > 1) {
const actions = Array.from(actionSet).join(', ');
const msg = `Invalid parameters, only one of "${actions}" may be set at a time`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import {
getTypeOf, Logger, isSimpleObject,
isNumber, isValidDate, isFunction,
isString, isWildCardString, matchWildcard,
pRetry, toIntegerOrThrow,
pRetry, toIntegerOrThrow, isKey,
} from '@terascope/utils';
import { ClientParams, ClientResponse } from '@terascope/types';
import {
ClientParams, ClientResponse,
IndicesIndexSettings,
IndicesIndexStatePrefixedSettings
} from '@terascope/types';
import { DataFrame } from '@terascope/data-mate';
import { DataTypeConfig } from '@terascope/data-types';
import moment from 'moment';
Expand Down Expand Up @@ -663,7 +667,7 @@ export class ElasticsearchReaderAPI {
// we have a date, parse and return it
if (date) return parseDate(date);
// we are in auto, so we determine each part
const sortObj = {};
const sortObj: Record<string, { order: 'asc' | 'desc' }> = {};
const sortOrder = order === 'start' ? 'asc' : 'desc';

sortObj[this.config.date_field_name] = { order: sortOrder };
Expand Down Expand Up @@ -710,22 +714,50 @@ export class ElasticsearchReaderAPI {
return this.client.getSettings(index);
}

/**
* Typeguard to differentiate IndicesIndexSettings
* from IndicesIndexStatePrefixedSettings
*/
private _isIndicesIndexStatePrefixedSettings(
input: unknown
): input is IndicesIndexStatePrefixedSettings {
if (!isObject(input)) return false;
if (isKey(input as object, 'index')) return true;

return false;
}

private _getMaxResultWindowFromSettings(
settings: IndicesIndexSettings | IndicesIndexStatePrefixedSettings | undefined
) {
const window = 'index.max_result_window';
let windowSize;
if (settings) {
if (!this._isIndicesIndexStatePrefixedSettings(settings)) {
windowSize = settings[window];
} else {
windowSize = settings.index[window];
}
}
return windowSize;
}

/**
* This used verify the index.max_result_window size
* will be big enough to fix the within the requested
* slice size
*/
async getWindowSize(): Promise<number> {
const window = 'index.max_result_window';
const { index } = this.config;

const settings = await this.getSettings(index);
const matcher = indexMatcher(index);

for (const [key, configs] of Object.entries(settings)) {
if (matcher(key)) {
const defaultPath = configs.defaults![window];
const configPath = configs.settings![window];
const defaultPath = this._getMaxResultWindowFromSettings(configs.defaults);
const configPath = this._getMaxResultWindowFromSettings(configs.settings);

// config goes first as it overrides an defaults
if (configPath) return toIntegerOrThrow(configPath);
if (defaultPath) return toIntegerOrThrow(defaultPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import tls from 'tls';
import {
Logger, TSError, get, isNil,
AnyObject, withoutNil, DataEntity,
isKey,
} from '@terascope/utils';
import { ClientParams, ClientResponse } from '@terascope/types';
import { DataTypeConfig } from '@terascope/data-types';
Expand Down Expand Up @@ -159,9 +160,9 @@ export class SpacesReaderClient implements ReaderClient {
if (mustArray) {
mustArray.forEach((queryAction) => {
for (const [key, qConfig] of Object.entries(queryAction)) {
const queryFn = queryOptions[key];
if (queryFn) {
let queryStr = queryFn(qConfig);
if (isKey(queryOptions, key) && queryOptions[key]) {
const queryFn = queryOptions[key];
let queryStr = queryFn(qConfig as Record<string, string>);
if (key !== 'range') queryStr = `(${queryStr})`;

if (luceneQuery.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class WindowState {

if (allDone) {
for (const key of Object.keys(this._windowState)) {
this._windowState[key].canRestart = true;
this._windowState[key].hasCalled = false;
this._windowState[Number(key)].canRestart = true;
this._windowState[Number(key)].hasCalled = false;
jsnoble marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { times, toIntegerOrThrow } from '@terascope/utils';
import { isKey, times, toIntegerOrThrow } from '@terascope/utils';
import moment from 'moment';
import fs from 'node:fs';
// @ts-expect-error
Expand All @@ -11,7 +11,7 @@ import {
} from '../interfaces.js';

export function dateOptions(value: string): moment.unitOfTime.Base {
const options = {
const options: Record<string, moment.unitOfTime.Base> = {
year: 'y',
years: 'y',
y: 'y',
Expand Down Expand Up @@ -46,7 +46,7 @@ export function dateOptions(value: string): moment.unitOfTime.Base {
ms: 'ms'
};

if (options[value]) {
if (isKey(options, value)) {
return options[value];
}

Expand Down Expand Up @@ -120,7 +120,7 @@ export function existsSync(filename: string): boolean {
}
}

export function getMilliseconds(interval: any[]): number {
export function getMilliseconds(interval: [number, string]): number {
const conversions = {
d: 86400000,
h: 3600000,
Expand All @@ -129,7 +129,7 @@ export function getMilliseconds(interval: any[]): number {
ms: 1
};

return interval[0] * conversions[interval[1]];
return interval[0] * conversions[interval[1] as keyof typeof conversions];
}

export function parseDate(date: string): moment.Moment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { AnyObject, DataEntity, Logger } from '@terascope/utils';
import type { EventEmitter } from 'node:events';
import type {
DataTypeConfig, xLuceneVariables, ClientParams,
ClientResponse
ClientResponse, GeoPoint
} from '@terascope/types';
import type { WindowState } from './WindowState.js';

Expand Down Expand Up @@ -378,3 +378,19 @@ export interface SlicerDateConfig extends DateSegments {
end: moment.Moment;
holes?: readonly DateConfig[];
}

export interface GeoBoundingBoxQuery {
geo_bounding_box: {
busma13 marked this conversation as resolved.
Show resolved Hide resolved
[key: string]: {
top_left: GeoPoint;
bottom_right: GeoPoint;
};
};
}

export interface GeoDistanceQuery {
geo_distance: {
distance: string;
[key: string]: GeoPoint | string;
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { AnyObject, GeoPoint, ClientParams } from '@terascope/types';
import { isString, parseGeoPoint } from '@terascope/utils';
import { ESReaderOptions, ReaderSlice } from './interfaces.js';
import {
ESReaderOptions, GeoBoundingBoxQuery,
GeoDistanceQuery, ReaderSlice
} from './interfaces.js';

/**
* Build the elasticsearch DSL query
Expand Down Expand Up @@ -36,7 +39,7 @@ function _buildRangeQuery(
};
// is a range type query
if (params.start && params.end) {
const dateObj = {};
const dateObj: Record<string, { gte: string; lt: string }> = {};
const { date_field_name: dateFieldName } = opConfig;
dateObj[dateFieldName] = {
gte: params.start,
Expand Down Expand Up @@ -155,8 +158,8 @@ export function geoSearch(opConfig: ESReaderOptions): AnyObject {
function createGeoSortQuery(location: GeoPoint) {
const sortedSearch: AnyObject = { _geo_distance: {} };
sortedSearch._geo_distance[opConfig.geo_field as string] = {
lat: location[0],
lon: location[1],
lat: location.lat,
lon: location.lon,
};
sortedSearch._geo_distance.order = geoSortOrder;
sortedSearch._geo_distance.unit = geoSortUnit;
Expand All @@ -174,18 +177,18 @@ export function geoSearch(opConfig: ESReaderOptions): AnyObject {
const topLeft = parseGeoPoint(geoBoxTopLeft);
const bottomRight = parseGeoPoint(geoBoxBottomRight as string);

const searchQuery = {
const searchQuery: GeoBoundingBoxQuery = {
geo_bounding_box: {},
};

searchQuery.geo_bounding_box[opConfig.geo_field as string] = {
top_left: {
lat: topLeft[0],
lon: topLeft[1],
lat: topLeft.lat,
lon: topLeft.lon,
},
bottom_right: {
lat: bottomRight[0],
lon: bottomRight[1],
lat: bottomRight.lat,
lon: bottomRight.lon,
},
};

Expand All @@ -200,15 +203,15 @@ export function geoSearch(opConfig: ESReaderOptions): AnyObject {

if (geoDistance) {
const location = parseGeoPoint(geoPoint as string);
const searchQuery = {
const searchQuery: GeoDistanceQuery = {
geo_distance: {
distance: geoDistance,
},
};

searchQuery.geo_distance[opConfig.geo_field as string] = {
lat: location[0],
lon: location[1],
lat: location.lat,
lon: location.lon,
};

queryResults.query = searchQuery;
Expand Down
6 changes: 0 additions & 6 deletions packages/elasticsearch-asset-apis/test/bulk-send-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'jest-extended';
import { debugLogger, AnyObject, DataEntity } from '@terascope/utils';
import { WorkerTestHarness } from 'teraslice-test-harness';
import { isOpensearch2, isElasticsearch8 } from 'elasticsearch-store';
import elasticAPI from '@terascope/elasticsearch-api';
import {
Expand All @@ -15,7 +14,6 @@ describe('elasticsearch bulk sender module', () => {
const senderIndex = `${TEST_INDEX_PREFIX}_sender_api_`;

let apiClient: elasticAPI.Client;
let harness: WorkerTestHarness;
let client: any;
let type: string | undefined;

Expand All @@ -40,10 +38,6 @@ describe('elasticsearch bulk sender module', () => {
await cleanupIndex(client, `${senderIndex}*`);
});

afterEach(async () => {
if (harness) await harness.shutdown();
});

function createSender(config: AnyObject = {}) {
const senderConfig = Object.assign(
{},
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"suppressImplicitAnyIndexErrors": true,
"composite": true,
"declaration": true,
"declarationMap": true,
Expand Down
26 changes: 3 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3476,7 +3476,7 @@ __metadata:
node-notifier: "npm:~10.0.1"
teraslice-test-harness: "npm:~1.3.1"
ts-jest: "npm:~29.2.5"
typescript: "npm:~5.2.2"
typescript: "npm:~5.7.3"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -9093,17 +9093,7 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:~5.2.2":
version: 5.2.2
resolution: "typescript@npm:5.2.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/91ae3e6193d0ddb8656d4c418a033f0f75dec5e077ebbc2bd6d76439b93f35683936ee1bdc0e9cf94ec76863aa49f27159b5788219b50e1cd0cd6d110aa34b07
languageName: node
linkType: hard

"typescript@npm:~5.7.2":
"typescript@npm:~5.7.2, typescript@npm:~5.7.3":
version: 5.7.3
resolution: "typescript@npm:5.7.3"
bin:
Expand All @@ -9113,17 +9103,7 @@ __metadata:
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A~5.2.2#optional!builtin<compat/typescript>":
version: 5.2.2
resolution: "typescript@patch:typescript@npm%3A5.2.2#optional!builtin<compat/typescript>::version=5.2.2&hash=f3b441"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/062c1cee1990e6b9419ce8a55162b8dc917eb87f807e4de0327dbc1c2fa4e5f61bc0dd4e034d38ff541d1ed0479b53bcee8e4de3a4075c51a1724eb6216cb6f5
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A~5.7.2#optional!builtin<compat/typescript>":
"typescript@patch:typescript@npm%3A~5.7.2#optional!builtin<compat/typescript>, typescript@patch:typescript@npm%3A~5.7.3#optional!builtin<compat/typescript>":
version: 5.7.3
resolution: "typescript@patch:typescript@npm%3A5.7.3#optional!builtin<compat/typescript>::version=5.7.3&hash=5786d5"
bin:
Expand Down
Loading