Skip to content

Commit

Permalink
Merge pull request #1255 from terascope/fix-eslint
Browse files Browse the repository at this point in the history
fix lint, normalize code style
  • Loading branch information
jsnoble authored Sep 30, 2024
2 parents 31320ea + 0f52863 commit eb65fa8
Show file tree
Hide file tree
Showing 36 changed files with 727 additions and 504 deletions.
2 changes: 1 addition & 1 deletion asset/src/__lib/DateReaderAPISlicer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class DateReaderAPISlicer extends ParallelSlicer<ESDateConfig> {
protected api!: ElasticsearchReaderAPI;
protected hasUpdated = false;
protected startTime = moment().toISOString();
slicerRanges!: DateSlicerRanges|undefined;
slicerRanges!: DateSlicerRanges | undefined;

async initialize(recoveryData: SlicerRecoveryData[]): Promise<void> {
// NOTE ORDER MATTERS
Expand Down
4 changes: 2 additions & 2 deletions asset/src/elasticsearch_bulk/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DEFAULT_API_NAME } from '../elasticsearch_sender_api/interfaces.js';
export const schema: AnyObject = {
size: {
doc: 'the maximum number of docs it will take at a time, anything past it will be split up and sent'
+ 'note that the value should be even, the first doc will be the index data and then the next is the data',
+ 'note that the value should be even, the first doc will be the index data and then the next is the data',
default: 500,
format(val: unknown): void {
if (!isNumber(val)) throw new Error(`Invalid parameter size, it must be of type number, was given ${getTypeOf(val)}`);
Expand Down Expand Up @@ -59,7 +59,7 @@ export const schema: AnyObject = {
},
update_fields: {
doc: 'if you are updating the documents, you can specify fields to update here (it should be an array '
+ 'containing all the field names you want updated), it defaults to sending the entire document',
+ 'containing all the field names you want updated), it defaults to sending the entire document',
default: [],
format: Array
},
Expand Down
4 changes: 2 additions & 2 deletions asset/src/elasticsearch_reader_api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@terascope/elasticsearch-asset-apis';

export default class ElasticsearchReaderAPIFactory extends APIFactory<
ElasticsearchReaderAPI, Partial<ESReaderOptions>
ElasticsearchReaderAPI, Partial<ESReaderOptions>
> {
// TODO: this needs more validation
validateConfig(config: unknown): ESReaderOptions {
Expand All @@ -30,7 +30,7 @@ ElasticsearchReaderAPI, Partial<ESReaderOptions>

async create(
_name: string, overrideConfigs: Partial<ESReaderOptions>
): Promise<{ client: ElasticsearchReaderAPI, config: AnyObject }> {
): Promise<{ client: ElasticsearchReaderAPI; config: AnyObject }> {
const config = this.validateConfig(Object.assign({}, this.apiConfig, overrideConfigs));
const { connection } = config;
const { client: esClient } = await this.context.apis.foundation.createClient({
Expand Down
4 changes: 2 additions & 2 deletions asset/src/elasticsearch_reader_api/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { ESReaderOptions, ElasticsearchReaderAPI } from '@terascope/elasticsearc
export const DEFAULT_API_NAME = 'elasticsearch_reader_api';
export interface ElasticsearchReaderAPIConfig extends ESReaderOptions, APIConfig {}
export type ElasticReaderFactoryAPI = APIFactoryRegistry<
ElasticsearchReaderAPI, ElasticsearchReaderAPIConfig
>
ElasticsearchReaderAPI, ElasticsearchReaderAPIConfig
>;
6 changes: 3 additions & 3 deletions asset/src/elasticsearch_reader_api/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export default class Schema extends ConvictSchema<ElasticsearchReaderAPIConfig>
}
}

function geoPointValidation(point: string | null):void {
function geoPointValidation(point: string | null): void {
if (!point) return;

if (typeof point !== 'string') throw new Error('Invalid geo_point, must be a string IF specified');
Expand All @@ -317,7 +317,7 @@ function geoPointValidation(point: string | null):void {
if (longitude > 180 || longitude < -180) throw new Error(`Invalid longitude parameter, was given ${longitude}, should be >= -180 and <= 180`);
}

function checkUnits(unit: string | null):void {
function checkUnits(unit: string | null): void {
if (!unit) return;
if (!isString(unit)) throw new Error('Invalid parameter, must be a string IF specified');

Expand All @@ -332,7 +332,7 @@ function checkUnits(unit: string | null):void {
if (!has(unitOptions, unit)) throw new Error('Invalid unit type, did not have a proper unit of measurement (ie m, km, yd, ft)');
}

function validGeoDistance(distance: string | null):void {
function validGeoDistance(distance: string | null): void {
if (!distance) return;

if (typeof distance !== 'string') throw new Error('Invalid geo_distance parameter, must be a string IF specified');
Expand Down
2 changes: 1 addition & 1 deletion asset/src/elasticsearch_sender_api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class ElasticsearchSenderAPI extends APIFactory

async create(
_name: string, overrideConfig: Partial<ElasticsearchAPISenderConfig>
): Promise<{ client: ElasticsearchBulkSender, config: ElasticsearchAPISenderConfig }> {
): Promise<{ client: ElasticsearchBulkSender; config: ElasticsearchAPISenderConfig }> {
const apiConfig = this.validateConfig(Object.assign({}, this.apiConfig, overrideConfig));
const { api_name, ...config } = apiConfig;

Expand Down
8 changes: 4 additions & 4 deletions asset/src/elasticsearch_sender_api/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { APIConfig, APIFactoryRegistry, AnyObject } from '@terascope/job-components';
import { ElasticsearchBulkSender, ElasticsearchSenderConfig } from '@terascope/elasticsearch-asset-apis';

export type ElasticSenderAPI = APIFactoryRegistry<ElasticsearchBulkSender, AnyObject>
export type ElasticSenderAPI = APIFactoryRegistry<ElasticsearchBulkSender, AnyObject>;

export const DEFAULT_API_NAME = 'elasticsearch_sender_api';

export interface SenderConfig extends APIConfig {
connection: string
connection: string;
index?: string;
size?: number;
}

export interface ValidSenderConfig extends APIConfig {
connection: string
connection: string;
size: number;
index?: string;
}
Expand All @@ -32,7 +32,7 @@ export interface ElasticsearchAPISenderConfig {
script_file?: string;
script?: string;
script_params: AnyObject;
_key?: string
_key?: string;
}

export interface ElasticsearchSenderAPI extends ElasticsearchSenderConfig, APIConfig {}
6 changes: 4 additions & 2 deletions asset/src/elasticsearch_sender_api/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const newSchema: AnyObject = cloneDeep(schema);

newSchema.size = {
doc: 'the maximum number of docs it will take at a time, anything past it will be split up and sent'
+ 'note that the value should be even, the first doc will be the index data and then the next is the data',
+ 'note that the value should be even, the first doc will be the index data and then the next is the data',
default: 500,
format(val: any) {
if (isNaN(val)) {
Expand Down Expand Up @@ -56,7 +56,9 @@ export default class Schema extends ConvictSchema<ElasticsearchAPISenderConfig>
job.operations.forEach((op) => {
if (op._op === 'routed_sender') {
apiConfigs.filter((config) => config._name === op.api_name && config.connection === 'default')
.forEach((config) => { [config.connection] = Object.values(op.routing); });
.forEach((config) => {
[config.connection] = Object.values(op.routing);
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion asset/src/spaces_reader_api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class SpacesReaderAPI extends APIFactory<ElasticsearchReaderAPI,

async create(
_name: string, overrideConfigs: Partial<SpacesAPIConfig>
): Promise<{ client: ElasticsearchReaderAPI, config: SpacesAPIConfig }> {
): Promise<{ client: ElasticsearchReaderAPI; config: SpacesAPIConfig }> {
const config = this.validateConfig(Object.assign({}, this.apiConfig, overrideConfigs));
const emitter = this.context.apis.foundation.getSystemEvents();
const spacesArgs = { config, logger: this.logger, emitter };
Expand Down
5 changes: 1 addition & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import eslintConfig from '@terascope/eslint-config';
// need to probably put this in original eslint-config
// don't lint the dist folder
eslintConfig[0].ignores.push('dist/', '**/dist/**');

export default eslintConfig
export default eslintConfig;
15 changes: 8 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export default {
preset: 'ts-jest',
extensionsToTreatAsEsm: ['.ts'],
transform: {
'\\.[jt]sx?$': ['ts-jest', {
isolatedModules: true,
tsconfig: './tsconfig.json',
diagnostics: true,
pretty: true,
useESM: true
}]
'\\.[jt]sx?$': ['ts-jest',
{
isolatedModules: true,
tsconfig: './tsconfig.json',
diagnostics: true,
pretty: true,
useESM: true
}]
},
globals: {
ignoreDirectories: ['dist'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@terascope/data-types": "^1.1.0",
"@terascope/elasticsearch-api": "^4.1.0",
"@terascope/elasticsearch-asset-apis": "^1.0.3",
"@terascope/eslint-config": "^1.0.0",
"@terascope/eslint-config": "^1.1.0",
"@terascope/job-components": "^1.3.1",
"@terascope/scripts": "1.1.2",
"@terascope/teraslice-state-storage": "^1.1.0",
Expand Down
15 changes: 8 additions & 7 deletions packages/elasticsearch-asset-apis/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ export default {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'\\.[jt]sx?$': ['ts-jest', {
isolatedModules: true,
tsconfig: './tsconfig.json',
diagnostics: true,
pretty: true,
useESM: true
}]
'\\.[jt]sx?$': ['ts-jest',
{
isolatedModules: true,
tsconfig: './tsconfig.json',
diagnostics: true,
pretty: true,
useESM: true
}]
},
testTimeout: 60 * 1000
};
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export class ElasticsearchBulkSender implements RouteSenderAPI {
return meta;
}

update(meta: Partial<elasticAPI.BulkActionMetadata>, record: DataEntity):elasticAPI.BulkRecord {
update(
meta: Partial<elasticAPI.BulkActionMetadata>,
record: DataEntity
): elasticAPI.BulkRecord {
const data = this.addUpdateMethod(record);

if (this.config.upsert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export * from './ElasticsearchBulkSender.js';
export * from './interfaces.js';

interface BulkAPIArgs {
config: ElasticsearchSenderConfig,
config: ElasticsearchSenderConfig;
client: elasticAPI.Client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ElasticsearchSenderConfig {
script_file?: string;
script?: string;
script_params?: AnyObject;
_key?: string
_key?: string;
}

export interface ScriptConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ElasticsearchReaderAPI {
* we should expose this because in some cases
* it might be an optimization to set this externally
*/
windowSize: number|undefined = undefined;
windowSize: number | undefined = undefined;
protected readonly dateFormat: string;
protected readonly emitter: EventEmitter;
recordsFetched = 0;
Expand Down Expand Up @@ -95,7 +95,7 @@ export class ElasticsearchReaderAPI {
* slow ES queries down significantly, refs:
* https://github.com/terascope/elasticsearch-assets/issues/948
*/
async fetch(queryParams: ReaderSlice = {}): Promise<DataEntity[]|DataFrame|Buffer> {
async fetch(queryParams: ReaderSlice = {}): Promise<DataEntity[] | DataFrame | Buffer> {
if (this.config.useSimpleFetch) {
return this.simpleFetch(queryParams);
}
Expand All @@ -120,7 +120,7 @@ export class ElasticsearchReaderAPI {
}

const _fetch = async ():
Promise<DataEntity[]|DataFrame|Buffer> => {
Promise<DataEntity[] | DataFrame | Buffer> => {
const query = buildQuery(this.config, {
...queryParams, count: querySize
});
Expand Down Expand Up @@ -169,7 +169,7 @@ export class ElasticsearchReaderAPI {
return result;
}

async simpleFetch(queryParams: ReaderSlice = {}): Promise<DataEntity[]|DataFrame|Buffer> {
async simpleFetch(queryParams: ReaderSlice = {}): Promise<DataEntity[] | DataFrame | Buffer> {
// attempt to get window if not set
if (!this.windowSize) await this.setWindowSize();

Expand All @@ -190,7 +190,7 @@ export class ElasticsearchReaderAPI {
* @param result the object returned that contains the search results
* @returns the number of records returned by the search
*/
_getResultSize(result: DataEntity[]|DataFrame|Buffer): number {
_getResultSize(result: DataEntity[] | DataFrame | Buffer): number {
let resultSize;
if (Buffer.isBuffer(result)) {
const json = result.toJSON();
Expand All @@ -207,7 +207,7 @@ export class ElasticsearchReaderAPI {
_searchRequest(query: ClientParams.SearchParams, fullResponse: true): Promise<unknown>;
async _searchRequest(
query: ClientParams.SearchParams, fullResponse?: boolean
): Promise<DataEntity[]|unknown> {
): Promise<DataEntity[] | unknown> {
return this.client._searchRequest(
query,
fullResponse
Expand Down Expand Up @@ -409,8 +409,8 @@ export class ElasticsearchReaderAPI {
if (recoveryData && recoveryData.length > 0) {
// TODO: verify what retryData is
// real retry of executionContext here, need to reformat retry data
const parsedRetry: (string|undefined)[] = recoveryData.map((obj) => {
const slice = (obj.lastSlice as ReaderSlice|undefined);
const parsedRetry: (string | undefined)[] = recoveryData.map((obj) => {
const slice = obj.lastSlice as ReaderSlice | undefined;
// when we get here there should only be one key
if (slice?.keys?.length === 1) {
return slice.keys[0];
Expand Down Expand Up @@ -459,7 +459,7 @@ export class ElasticsearchReaderAPI {
* slicer instance, then each "range" should be passed into
* {@link ElasticsearchReaderAPI.makeDateSlicerFromRange}
*/
async makeDateSlicerRanges(config: Omit<DateSlicerArgs, 'slicerID'|'windowState'>): Promise<DateSlicerRanges|undefined> {
async makeDateSlicerRanges(config: Omit<DateSlicerArgs, 'slicerID' | 'windowState'>): Promise<DateSlicerRanges | undefined> {
this.validateDateSlicerConfig(config);
const {
lifecycle,
Expand All @@ -472,7 +472,7 @@ export class ElasticsearchReaderAPI {

const recoveryData = config.recoveryData?.map(
(slice) => slice.lastSlice
).filter(Boolean) as ReaderSlice[]|undefined || [];
).filter(Boolean) as ReaderSlice[] | undefined || [];

if (isPersistent) {
// we need to interval to get starting dates
Expand Down Expand Up @@ -613,7 +613,7 @@ export class ElasticsearchReaderAPI {
};

if (isPersistent) {
const windowState = config.windowState as WindowState|undefined;
const windowState = config.windowState as WindowState | undefined;
if (!windowState || !windowState.checkin) {
throw new Error(`Invalid parameter windowState, must provide a valid windowState in "persistent" mode, got ${getTypeOf(windowState)}`);
}
Expand Down Expand Up @@ -651,15 +651,15 @@ export class ElasticsearchReaderAPI {
});
}

async determineDateRanges(): Promise<{ start: FetchDate; limit: FetchDate; }> {
async determineDateRanges(): Promise<{ start: FetchDate; limit: FetchDate }> {
const [start, limit] = await Promise.all([
this.getIndexDate(this.config.start, 'start'),
this.getIndexDate(this.config.end, 'end')
]);
return { start, limit };
}

private async getIndexDate(date: string|null|undefined, order: string): Promise<FetchDate> {
private async getIndexDate(date: string | null | undefined, order: string): Promise<FetchDate> {
// we have a date, parse and return it
if (date) return parseDate(date);
// we are in auto, so we determine each part
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class ElasticsearchReaderClient implements ReaderClient {
constructor(
elasticsearchClient: Client,
clientConfig: {
connection?: string
index: string
connection?: string;
index: string;
},
logger: Logger,
) {
Expand Down Expand Up @@ -56,7 +56,7 @@ export class ElasticsearchReaderClient implements ReaderClient {
query: ClientParams.SearchParams,
responseType: FetchResponseType,
typeConfig?: DataTypeConfig
): Promise<DataEntity[]|DataFrame|Buffer> {
): Promise<DataEntity[] | DataFrame | Buffer> {
if (responseType === FetchResponseType.data_entities) {
return this._searchRequest(query, false);
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export class ElasticsearchReaderClient implements ReaderClient {
async _searchRequest(
query: ClientParams.SearchParams,
fullResponse?: boolean
): Promise<DataEntity[]|ClientResponse.SearchResponse<AnyObject>> {
): Promise<DataEntity[] | ClientResponse.SearchResponse<AnyObject>> {
if (fullResponse) {
return this.fullResponseClient.search(
query as any
Expand Down
Loading

0 comments on commit eb65fa8

Please sign in to comment.