diff --git a/package.json b/package.json index 928471a..8025e99 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,17 @@ "name": "@elastic/elasticsearch-serverless", "version": "0.6.0+20231031", "description": "The official Node.js Elastic client for the Elasticsearch Serverless service.", - "main": "index.js", + "main": "./index.js", "types": "index.d.ts", - "type": "commonjs", + "exports": { + "require": "./index.js" + }, "scripts": { "lint": "ts-standard src", "lint:fix": "ts-standard --fix src", "license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause;0BSD'", "prebuild": "npm run clean-build && npm run lint", - "build": "tsc", + "build": "tsc && rm lib/package.json && mv lib/src/* lib/ && rm -rf lib/src", "clean-build": "rimraf ./lib && mkdir lib", "prepublishOnly": "npm run build", "test": "npm run build && npm run lint && tap test/unit/{*,**/*}.test.ts", diff --git a/src/client.ts b/src/client.ts index d8113ae..1983e49 100644 --- a/src/client.ts +++ b/src/client.ts @@ -17,10 +17,11 @@ * under the License. */ -import { ConnectionOptions as TlsConnectionOptions } from 'tls' -import { URL } from 'url' -import buffer from 'buffer' -import os from 'os' +import process from 'node:process' +import { ConnectionOptions as TlsConnectionOptions } from 'node:tls' +import { URL } from 'node:url' +import buffer from 'node:buffer' +import os from 'node:os' import { Transport, UndiciConnection, @@ -44,17 +45,19 @@ import { RedactionOptions } from '@elastic/transport/lib/Transport' import BaseConnection, { prepareHeaders } from '@elastic/transport/lib/connection/BaseConnection' import Helpers from './helpers' import API from './api' +import packageJson from '../package.json' +import transportPackageJson from '@elastic/transport/package.json' const kChild = Symbol('elasticsearchjs-child') const kInitialOptions = Symbol('elasticsearchjs-initial-options') -let clientVersion: string = require('../package.json').version // eslint-disable-line +let clientVersion: string = packageJson.version /* istanbul ignore next */ if (clientVersion.includes('-')) { // clean prerelease clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p' } const [clientVersionNoMeta, apiVersion] = clientVersion.split('+') -let transportVersion: string = require('@elastic/transport/package.json').version // eslint-disable-line +let transportVersion: string = transportPackageJson.version /* istanbul ignore next */ if (transportVersion.includes('-')) { // clean prerelease diff --git a/src/helpers.ts b/src/helpers.ts index a099543..739ddef 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -21,9 +21,9 @@ /* eslint-disable @typescript-eslint/promise-function-async */ /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ -import assert from 'assert' -import { promisify } from 'util' -import { Readable } from 'stream' +import assert from 'node:assert' +import * as timersPromises from 'node:timers/promises' +import { Readable } from 'node:stream' import { errors, TransportResult, TransportRequestOptions, TransportRequestOptionsWithMeta } from '@elastic/transport' import Client from './client' import * as T from './api/types' @@ -162,8 +162,8 @@ export interface EsqlToRecords { } const { ResponseError, ConfigurationError } = errors -const sleep = promisify(setTimeout) -const pImmediate = promisify(setImmediate) +const sleep = timersPromises.setTimeout +const pImmediate = timersPromises.setImmediate /* istanbul ignore next */ const noop = (): void => {} const kClient = Symbol('elasticsearch-client') diff --git a/test/integration/helper.js b/test/integration/helper.js index d582525..fe4e0b4 100644 --- a/test/integration/helper.js +++ b/test/integration/helper.js @@ -19,7 +19,7 @@ 'use strict' -const assert = require('assert') +const assert = require('node:assert') const fetch = require('node-fetch') function runInParallel (client, operation, options, clientOptions) { diff --git a/test/integration/helpers/bulk.test.js b/test/integration/helpers/bulk.test.js index 011f524..a1b2be1 100644 --- a/test/integration/helpers/bulk.test.js +++ b/test/integration/helpers/bulk.test.js @@ -19,8 +19,8 @@ 'use strict' -const { createReadStream } = require('fs') -const { join } = require('path') +const { createReadStream } = require('node:fs') +const { join } = require('node:path') const split = require('split2') const { test, beforeEach, afterEach } = require('tap') const { waitCluster } = require('../../utils') diff --git a/test/integration/helpers/msearch.test.js b/test/integration/helpers/msearch.test.js index c9c726e..fb317b0 100644 --- a/test/integration/helpers/msearch.test.js +++ b/test/integration/helpers/msearch.test.js @@ -19,8 +19,8 @@ 'use strict' -const { createReadStream } = require('fs') -const { join } = require('path') +const { createReadStream } = require('node:fs') +const { join } = require('node:path') const split = require('split2') const { test, beforeEach, afterEach } = require('tap') const { waitCluster } = require('../../utils') diff --git a/test/integration/helpers/scroll.test.js b/test/integration/helpers/scroll.test.js index e197ce2..36f3b85 100644 --- a/test/integration/helpers/scroll.test.js +++ b/test/integration/helpers/scroll.test.js @@ -19,8 +19,8 @@ 'use strict' -const { createReadStream } = require('fs') -const { join } = require('path') +const { createReadStream } = require('node:fs') +const { join } = require('node:path') const split = require('split2') const { test, beforeEach, afterEach } = require('tap') const { waitCluster } = require('../../utils') diff --git a/test/integration/helpers/search.test.js b/test/integration/helpers/search.test.js index d4aa57c..7a6946a 100644 --- a/test/integration/helpers/search.test.js +++ b/test/integration/helpers/search.test.js @@ -19,8 +19,8 @@ 'use strict' -const { createReadStream } = require('fs') -const { join } = require('path') +const { createReadStream } = require('node:fs') +const { join } = require('node:path') const split = require('split2') const { test, beforeEach, afterEach } = require('tap') const { waitCluster } = require('../../utils') diff --git a/test/integration/reporter.js b/test/integration/reporter.js index 5db288b..d94e09b 100644 --- a/test/integration/reporter.js +++ b/test/integration/reporter.js @@ -1,6 +1,6 @@ 'use strict' -const assert = require('assert') +const assert = require('node:assert') const { create } = require('xmlbuilder2') function createJunitReporter () { diff --git a/test/unit/helpers/bulk.test.ts b/test/unit/helpers/bulk.test.ts index 2f776c7..db86280 100644 --- a/test/unit/helpers/bulk.test.ts +++ b/test/unit/helpers/bulk.test.ts @@ -18,12 +18,12 @@ */ import FakeTimers from '@sinonjs/fake-timers' -import { AssertionError } from 'assert' -import { createReadStream } from 'fs' -import * as http from 'http' -import { join } from 'path' +import { AssertionError } from 'node:assert' +import { createReadStream } from 'node:fs' +import * as http from 'node:http' +import { join } from 'node:path' import split from 'split2' -import { Readable } from 'stream' +import { Readable } from 'node:stream' import { test } from 'tap' import { Client, errors } from '../../../' import { buildServer, connection } from '../../utils' @@ -956,11 +956,11 @@ test('bulk index', t => { onDocument (doc) { t.type(doc.user, 'string') // testing that doc is type of Document return [ - { - index: { - _index: 'test' - } - }, + { + index: { + _index: 'test' + } + }, { ...doc, updatedAt } ] }, @@ -1064,7 +1064,7 @@ test('bulk create', t => { _index: 'test', _id: String(id++) } - }, + }, { ...doc, updatedAt } ] }, diff --git a/test/unit/helpers/search.test.ts b/test/unit/helpers/search.test.ts index 697237e..9ed4605 100644 --- a/test/unit/helpers/search.test.ts +++ b/test/unit/helpers/search.test.ts @@ -108,4 +108,5 @@ test('Merge filter paths (snake_case)', async t => { { two: 'two' }, { three: 'three' } ]) -}) \ No newline at end of file +}) + diff --git a/test/utils/buildCluster.ts b/test/utils/buildCluster.ts index 31299b3..266ebef 100644 --- a/test/utils/buildCluster.ts +++ b/test/utils/buildCluster.ts @@ -18,7 +18,7 @@ */ import Debug from 'debug' -import * as http from 'http' +import * as http from 'node:http' import buildServer, { ServerHandler } from './buildServer' import { StoppableServer } from 'stoppable'