From ca7c18c9afae9b72fc828bd4c711064076898b8d Mon Sep 17 00:00:00 2001 From: toptobes <96998732+toptobes@users.noreply.github.com> Date: Fri, 31 May 2024 00:34:23 -0500 Subject: [PATCH] Minor changes for the 1.2.1 releases (#46) * minor doc updates * added forgotten export + minor devguide update * update build report * fixed a couple of tests --- DEVGUIDE.md | 4 ++-- etc/astra-db-ts.api.md | 11 ++++++--- src/api/fetch/fetch-h2.ts | 2 +- src/api/fetch/types.ts | 8 ++++--- src/client/data-api-client.ts | 24 ++++++++++---------- src/client/index.ts | 1 + tests/integration/data-api/vectorize.test.ts | 12 ++++++---- tests/integration/devops/lifecycle.test.ts | 3 ++- 8 files changed, 38 insertions(+), 27 deletions(-) diff --git a/DEVGUIDE.md b/DEVGUIDE.md index 91d5c84b..f698f6ce 100644 --- a/DEVGUIDE.md +++ b/DEVGUIDE.md @@ -7,7 +7,7 @@ ## Running the tests Prerequisites: - A JS package manager (npm, bun, etc.) -- A clean Astra instance with two keyspaces—`default_keyspace` and `other_keyspace` +- A clean AstraDB instance with two keyspaces—`default_keyspace` and `other_keyspace` - Copy the `.env.example` file and create a new `.env` file following the example template ```shell @@ -124,5 +124,5 @@ To build it, just run `npm run build`, which does the following: - Deletes any extraneous `.d.ts` files ## Publishing -I heavily recommend using [np](https://github.com/sindresorhus/np) to publish the package. Running it will involve running `test:all`, and the +I heavily recommend using [np](https://github.com/sindresorhus/np) to publish the package. Running it will involve running `test:prerelease`, and the versioning step will update the api report + update the version in `src/version.ts`. diff --git a/etc/astra-db-ts.api.md b/etc/astra-db-ts.api.md index f06e45cd..5312f5a5 100644 --- a/etc/astra-db-ts.api.md +++ b/etc/astra-db-ts.api.md @@ -323,6 +323,13 @@ export class CursorIsStartedError extends DataAPIError { constructor(message: string); } +// @public +export interface CustomHttpClientOptions { + client: 'custom'; + fetcher: Fetcher; + maxTimeMS?: number; +} + // @public export class DataAPIClient extends DataAPIClientEventEmitterBase { [Symbol.asyncDispose]: () => Promise; @@ -374,8 +381,6 @@ export interface DataAPIErrorDescriptor { readonly message?: string; } -// Warning: (ae-forgotten-export) The symbol "CustomHttpClientOptions" needs to be exported by the entry point index.d.ts -// // @public export type DataAPIHttpOptions = DefaultHttpClientOptions | FetchHttpClientOptions | CustomHttpClientOptions; @@ -638,7 +643,7 @@ export interface FetcherRequestInfo { export interface FetcherResponseInfo { additionalAttributes?: Record; body?: string; - headers: Record; + headers: Record; httpVersion: 1 | 2; status: number; statusText: string; diff --git a/src/api/fetch/fetch-h2.ts b/src/api/fetch/fetch-h2.ts index c0b5d537..ad43acff 100644 --- a/src/api/fetch/fetch-h2.ts +++ b/src/api/fetch/fetch-h2.ts @@ -37,7 +37,7 @@ export class FetchH2 implements Fetcher { maxSockets: options?.http1?.maxSockets, maxFreeSockets: options?.http1?.maxFreeSockets, }, - httpsProtocols: ['http1'], + httpsProtocols: ['http1'], }); this._preferred = (preferHttp2) diff --git a/src/api/fetch/types.ts b/src/api/fetch/types.ts index 1d520e73..397171c2 100644 --- a/src/api/fetch/types.ts +++ b/src/api/fetch/types.ts @@ -77,7 +77,7 @@ export interface FetcherRequestInfo { } /** - * Response object from an API call. + * Response object from an API call made by a {@link Fetcher}. * * @public */ @@ -89,7 +89,7 @@ export interface FetcherResponseInfo { /** * The headers of the response. */ - headers: Record, + headers: Record, /** * The HTTP status code of the response. */ @@ -106,8 +106,10 @@ export interface FetcherResponseInfo { * The status text for the response. */ statusText: string, -/** + /** * Any additional attributes that may be included in the response (for use w/ custom {@link Fetcher} implementations). + * + * This is mainly for any potential logging or debugging information that may be useful for the user. */ additionalAttributes?: Record, } diff --git a/src/client/data-api-client.ts b/src/client/data-api-client.ts index 840c483c..75932206 100644 --- a/src/client/data-api-client.ts +++ b/src/client/data-api-client.ts @@ -333,7 +333,7 @@ function getDeprecatedPrefersHttp2(opts: DataAPIClientOptions | undefined | null } function validateRootOpts(opts: DataAPIClientOptions | undefined | null) { - validateOption('root client options', opts, 'object'); + validateOption('DataAPIClientOptions', opts, 'object'); if (!opts) { return; @@ -348,32 +348,32 @@ function validateRootOpts(opts: DataAPIClientOptions | undefined | null) { } function validateHttpOpts(opts: DataAPIHttpOptions | undefined | null) { - validateOption('http options', opts, 'object'); + validateOption('httpOptions', opts, 'object'); if (!opts) { return; } - validateOption('client option', opts.client, 'string', false, (client) => { + validateOption('httpOptions.client', opts.client, 'string', false, (client) => { if (client !== 'fetch' && client !== 'default' && client !== 'custom') { - throw new Error('Invalid httpOptions.client; expected \'fetch\' or \'default\''); + throw new Error('Invalid httpOptions.client; expected \'fetch\', \'default\', \'custom\', or undefined'); } }); - validateOption('maxTimeMS option', opts.maxTimeMS, 'number'); + validateOption('httpOptions.maxTimeMS', opts.maxTimeMS, 'number'); if (opts.client === 'default' || opts.client === undefined) { - validateOption('preferHttp2 option', opts.preferHttp2, 'boolean'); + validateOption('httpOptions.preferHttp2', opts.preferHttp2, 'boolean'); - validateOption('http1 options', opts.http1, 'object', false, (http1) => { - validateOption('http1.keepAlive option', http1.keepAlive, 'boolean'); - validateOption('http1.keepAliveMS option', http1.keepAliveMS, 'number'); - validateOption('http1.maxSockets option', http1.maxSockets, 'number'); - validateOption('http1.maxFreeSockets option', http1.maxFreeSockets, 'number'); + validateOption('httpOptions.http1 options', opts.http1, 'object', false, (http1) => { + validateOption('http1.keepAlive', http1.keepAlive, 'boolean'); + validateOption('http1.keepAliveMS', http1.keepAliveMS, 'number'); + validateOption('http1.maxSockets', http1.maxSockets, 'number'); + validateOption('http1.maxFreeSockets', http1.maxFreeSockets, 'number'); }); } if (opts.client === 'custom') { - validateOption('fetcher option', opts.fetcher, 'object', true, (fetcher) => { + validateOption('httpOptions.fetcher option', opts.fetcher, 'object', true, (fetcher) => { validateOption('fetcher.fetch option', fetcher.fetch, 'function', true); validateOption('fetcher.close option', fetcher.close, 'function'); }); diff --git a/src/client/index.ts b/src/client/index.ts index 94f056e0..f02d7a87 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -24,4 +24,5 @@ export { Http1Options, DataAPIHttpOptions, FetchHttpClientOptions, + CustomHttpClientOptions, } from './types'; diff --git a/tests/integration/data-api/vectorize.test.ts b/tests/integration/data-api/vectorize.test.ts index 04a140c9..679634dc 100644 --- a/tests/integration/data-api/vectorize.test.ts +++ b/tests/integration/data-api/vectorize.test.ts @@ -59,7 +59,7 @@ describe('integration.data-api.vectorize', () => { createVectorizeProvidersTest(db, test, name) if (i === 0) { - createVectorizeParamTests(db, name); + createVectorizeParamTests(db, test, name); } after(async () => { @@ -121,15 +121,17 @@ async function initVectorTests() { }); } -function createVectorizeParamTests(db: Db, name: string) { +function createVectorizeParamTests(db: Db, test: VectorizeTest, name: string) { describe('[vectorize] [dev] $vectorize/vectorize params', () => { - const collection = db.collection(name); + const collection = db.collection(name, { + embeddingApiKey: test.header, + }); before(async function () { - if (!await db.listCollections({ nameOnly: true }).then(cs => cs.every((c) => c !== name))) { + if (!await db.listCollections({ nameOnly: true }).then(cs => cs.some((c) => c === name))) { this.skip(); } - }) + }); beforeEach(async () => { await collection.deleteAll(); diff --git a/tests/integration/devops/lifecycle.test.ts b/tests/integration/devops/lifecycle.test.ts index f939abe6..b5cdc9b7 100644 --- a/tests/integration/devops/lifecycle.test.ts +++ b/tests/integration/devops/lifecycle.test.ts @@ -64,7 +64,8 @@ describe('integration.devops.lifecycle', async () => { assert.strictEqual(dbInfo1.info.keyspace, 'my_namespace'); const dbInfo2 = await admin.dbInfo(asyncDb.id); - assert.deepStrictEqual(dbInfo1.info, dbInfo2.info); + assert.deepStrictEqual(dbInfo1.info.name, dbInfo2.info.name); + assert.deepStrictEqual(dbInfo1.info.keyspaces, dbInfo2.info.keyspaces); assert.ok(['PENDING', 'INITIALIZING'].includes(dbInfo2.status)); }