Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright Elasticsearch B.V. and contributors
* SPDX-License-Identifier: Apache-2.0
*/

// we import the base configuration from Neostandard (a modern ESLint preset)
// and also its internal plugins
import neostandard, { plugins } from 'neostandard'
import { defineConfig } from 'eslint/config'

// we export the ESLint configuration
export default defineConfig([
...neostandard({
// enable support for TypeScript
ts: true,
// external dependencies (never lint them)
ignores: [
'node_modules/**',
// generated code (CommonJS build) It regenerates automatically, linting makes no sense
'lib/**',
// generated code (ESM build) Same as lib, it is overwritten in each build
'esm/**',
// coverage reports (not source code)
'coverage/**'
]
}),

// style rules applied to the important project files
// applies to:
// src: source code
// test: tests
// scripts: internal tools
{
files: ['src/**/*.js', 'src/**/*.ts', 'test/**/*.js', 'test/**/*.ts', 'scripts/**/*.js'],
plugins: {
// plugin that controls formatting (indentation, spaces, and other syntax rules)
'@stylistic': plugins['@stylistic']
},
rules: {
// requires a space after comments
'@stylistic/spaced-comment': ['error', 'always', {
// allows exceptions like //#region
exceptions: ['#', '/'],
markers: ['/']
}],
// prohibits the use of semicolon ;
'@stylistic/semi': ['error', 'never'],
// force 2-space indentation
'@stylistic/indent': ['error', 2],
// forces a new line or line break at the end of the file
'@stylistic/eol-last': ['error', 'always'],
// requires space before parentheses in functions () {}
'@stylistic/space-before-function-paren': ['error', 'always'],
// disables the requirement for lines between class methods
'@stylistic/lines-between-class-members': 'off'
}
},

// relaxed rules for code generated inside src
{
files: ['src/**/*.ts'],
// this is code generated as an API client
rules: {
// snake_case
camelcase: 'off',
// generator uses void expressions
'no-void': 'off',
// the generated regexes may seem incorrect but they are not
'no-useless-escape': 'off',
// the generated code can use let even though it could be const, to be more permissive
'prefer-const': 'off',
// side effects in some expressions
'no-unused-expressions': 'off',
// allows use of comma operator in generated code
'no-sequences': 'off',
// variables can exist even if they are not being used
'no-unused-vars': 'off',
// variables in TS that are not being used
'@typescript-eslint/no-unused-vars': 'off',
// allows automatically generated lowercase constructors
'new-cap': 'off'
}
},

// ci .buildkite, scripts exceptions
{
files: ['.buildkite/**/*.mjs'],
rules: {
// scripts can have unused variables (args)
'no-unused-vars': 'off',
// regex in scripts may require special escapes
'no-useless-escape': 'off'
}
},

// rules for the tests
{
files: ['test/**/*.js', 'test/**/*.ts', 'test/**/*.mjs'],
rules: {
// tests may use snake_case data
camelcase: 'off',
// tests often declare unused helpers
'no-unused-vars': 'off',
// tests often declare unused helpers or variable of ts
'@typescript-eslint/no-unused-vars': 'off',
// regex in tests may seem unnecessary
'no-useless-escape': 'off'
}
}
])
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"test:coverage-ui": "npm run build && tap --coverage --coverage-report=html",
"test:integration-build": "npm run build && node test/integration/index.js",
"test:integration": "npm run test:integration-build && env tap run --jobs=1 --reporter=junit --reporter-file=report-junit.xml generated-tests/",
"lint": "ts-standard src",
"lint:fix": "ts-standard --fix src",
"lint": "eslint",
"lint:fix": "eslint . --fix ",
"license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause;0BSD'",
"license-header": "./scripts/check-spdx",
"prebuild": "npm run clean-build && npm run lint",
Expand Down Expand Up @@ -70,11 +70,14 @@
"chai": "5.2.1",
"cross-zip": "4.0.1",
"desm": "1.3.1",
"eslint": "^9.39.3",
"into-stream": "8.0.1",
"js-yaml": "4.1.0",
"inly": "5.0.1",
"js-yaml": "4.1.1",
"license-checker": "25.0.1",
"minimist": "1.2.8",
"ms": "2.1.3",
"neostandard": "^0.13.0",
"node-abort-controller": "3.1.1",
"node-fetch": "2.7.0",
"ora": "5.4.1",
Expand All @@ -85,8 +88,8 @@
"stoppable": "1.1.0",
"tap": "21.1.0",
"ts-node": "10.9.2",
"ts-standard": "12.0.2",
"typescript": "5.9.2",
"tsc-esm-fix": "3.1.2",
"typescript": "5.9.3",
"workq": "3.0.0",
"xmlbuilder2": "3.1.1",
"zx": "8.8.0"
Expand Down
53 changes: 53 additions & 0 deletions scripts/fix-esm-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright Elasticsearch B.V. and contributors
* SPDX-License-Identifier: Apache-2.0
*/

const fs = require('fs')
const path = require('path')

// Fix the package.json require in client.js for ESM
const clientPath = path.join(__dirname, '..', 'esm', 'client.js')
const helpersPath = path.join(__dirname, '..', 'esm', 'helpers.js')

// Fix client.js
if (fs.existsSync(clientPath)) {
let content = fs.readFileSync(clientPath, 'utf8')

// Check if we need to add createRequire
const hasPackageRequire = content.includes('require(\'../package.json\')') ||
content.includes('require(\'@elastic/transport/package.json\')')

if (!content.includes('createRequire') && hasPackageRequire) {
// Find the last import statement
const lastImportIndex = content.lastIndexOf('import ')
const newlineAfterImport = content.indexOf('\n', lastImportIndex)

if (newlineAfterImport !== -1) {
const beforeImport = content.substring(0, newlineAfterImport + 1)
const afterImport = content.substring(newlineAfterImport + 1)

content = beforeImport + 'import { createRequire } from \'node:module\';\nconst require = createRequire(import.meta.url);\n' + afterImport
}

fs.writeFileSync(clientPath, content, 'utf8')
console.log(`Fixed package.json loading in ${clientPath}`)
}
} else {
console.log('client.js not found, skipping fix')
}

// Fix helpers.js - remove incorrect .js extension from apache-arrow import
if (fs.existsSync(helpersPath)) {
let content = fs.readFileSync(helpersPath, 'utf8')

// Fix the apache-arrow import that tsc-esm-fix incorrectly modified
const originalApacheImport = 'import { tableFromIPC, AsyncRecordBatchStreamReader } from \'apache-arrow/Arrow.node.js\';'
const fixedApacheImport = 'import { tableFromIPC, AsyncRecordBatchStreamReader } from \'apache-arrow/Arrow.node\';'

if (content.includes(originalApacheImport)) {
content = content.replace(originalApacheImport, fixedApacheImport)
fs.writeFileSync(helpersPath, content, 'utf8')
console.log(`Fixed apache-arrow import in ${helpersPath}`)
}
}
33 changes: 33 additions & 0 deletions scripts/generate-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and contributors
* SPDX-License-Identifier: Apache-2.0
*/

const fs = require('fs')
const path = require('path')

const rootDir = path.join(__dirname, '..')
const clientPkg = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json'), 'utf8'))
let transportVersion = '0.0.0'
try {
const transportPkgPath = require.resolve('@elastic/transport/package.json', { paths: [rootDir] })
const transportPkg = JSON.parse(fs.readFileSync(transportPkgPath, 'utf8'))
transportVersion = transportPkg.version
} catch (_) {
// @elastic/transport not installed (e.g. pre-install); use placeholder 0.0.0
}

const outPath = path.join(rootDir, 'src', 'version.generated.ts')
const content = `/*
* Copyright Elasticsearch B.V. and contributors
* SPDX-License-Identifier: Apache-2.0
*
* Generated by scripts/generate-version.js - do not edit manually.
*/

export const clientVersion: string = '${clientPkg.version}'
export const transportVersion: string = '${transportVersion}'
`

fs.writeFileSync(outPath, content, 'utf8')
console.log(`Generated ${outPath} (client: ${clientPkg.version}, transport: ${transportVersion})`)
7 changes: 1 addition & 6 deletions src/api/api/async_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down Expand Up @@ -333,7 +328,7 @@ export default class AsyncSearch {
for (const key in params) {
if (acceptedBody.includes(key)) {
body = body ?? {}
if (key === 'sort' && typeof params[key] === 'string' && params[key].includes(':')) { // eslint-disable-line
if (key === 'sort' && typeof params[key] === 'string' && params[key].includes(':')) {
querystring[key] = params[key]
} else {
// @ts-expect-error
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/autoscaling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/ccr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/clear_scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/close_point_in_time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
5 changes: 0 additions & 5 deletions src/api/api/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-misused-new */
/* eslint-disable @typescript-eslint/no-extraneous-class */
/* eslint-disable @typescript-eslint/no-unused-vars */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.
Expand Down
Loading
Loading