Skip to content

Commit 5c03077

Browse files
committed
More docs + renaming for client uniformity
1 parent 5f8e325 commit 5c03077

35 files changed

+463
-223
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ Get the *API endpoint* and your *applicaton token* for your Astra DB instance @
1515
Try the following code after setting the following environment variables:
1616

1717
```typescript
18-
import { DataApiClient, VectorDoc, UUID, ObjectId } from '@datastax/astra-db-ts';
18+
import { DataAPIClient, VectorDoc, UUID, ObjectId } from '@datastax/astra-db-ts';
1919

2020
// Schema for the collection (VectorDoc adds the $vector field)
2121
interface Idea extends VectorDoc {
2222
idea: string,
2323
}
2424

2525
// Connect to the db
26-
const client = new DataApiClient('AstraCS:...');
27-
const db = client.db('https://<db_id>-<region>.apps.astra.datastax.com');
26+
const client = new DataAPIClient('*TOKEN*');
27+
const db = client.db('*ENDPOINT*', { namespace: '*NAMESPACE*' });
2828

2929
(async () => {
3030
// Creates collection, or gets it if it already exists with same options
@@ -86,7 +86,7 @@ const db = client.db('https://<db_id>-<region>.apps.astra.datastax.com');
8686
Next steps:
8787
- More info and usage patterns are given in the ts-doc of classes and methods
8888
- [TS client reference](https://docs.datastax.com/en/astra/astra-db-vector/clients/typescript.html)
89-
- [Data API refernce](https://docs.datastax.com/en/astra/astra-db-vector/api-reference/data-api-commands.html)
89+
- [Data API reference](https://docs.datastax.com/en/astra/astra-db-vector/api-reference/data-api-commands.html)
9090
- Package on [npm](https://www.npmjs.com/package/@datastax/astra-db-ts)
9191

9292
## astra-db-ts's API
@@ -100,9 +100,10 @@ astra-db-ts's abstractions for working at the data and admin layers are structur
100100
Here's a small admin-oriented example:
101101

102102
```typescript
103-
import { DataApiClient } from '@datastax/astra-db-ts';
103+
import { DataAPIClient } from '@datastax/astra-db-ts';
104104

105-
const client = new DataApiClient('AstraCS:...');
105+
// Spawn an admin
106+
const client = new DataAPIClient('*TOKEN*');
106107
const admin = client.admin();
107108

108109
(async () => {
@@ -122,16 +123,17 @@ const admin = client.admin();
122123
astra-db-ts exports an `ObjectId` and `UUID` class for working with these types in the database. Here's an example:
123124

124125
```typescript
125-
import { DataApiClient, ObjectId, UUID } from '@datastax/astra-db-ts';
126+
import { DataAPIClient, ObjectId, UUID } from '@datastax/astra-db-ts';
126127

127128
interface Person {
128129
_id: ObjectId | UUID,
129130
name: string,
130131
friendId?: string,
131132
}
132133

133-
const client = new DataApiClient('AstraCS:...');
134-
const db = client.db('https://<db_id>-<region>.apps.astra.datastax.com');
134+
// Connect to the db
135+
const client = new DataAPIClient('*TOKEN*');
136+
const db = client.db('*ENDPOINT*', { namespace: '*NAMESPACE*' });
135137

136138
(async () => {
137139
// Create a collection with a UUIDv7 as the default ID

src/api/data-api-http-client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
// limitations under the License.
1414
// noinspection ExceptionCaughtLocallyJS
1515

16-
import { DEFAULT_NAMESPACE, DEFAULT_TIMEOUT, hrTimeMs, HttpClient, HttpMethods, RawDataApiResponse } from '@/src/api';
16+
import { DEFAULT_NAMESPACE, DEFAULT_TIMEOUT, hrTimeMs, HttpClient, HttpMethods, RawDataAPIResponse } from '@/src/api';
1717
import { DataAPIResponseError, DataAPITimeout, mkRespErrorFromResponse, ObjectId, UUID } from '@/src/data-api';
1818
import { MkTimeoutError, TimeoutManager, TimeoutOptions } from '@/src/api/timeout-managers';
1919
import { CommandFailedEvent, CommandStartedEvent, CommandSucceededEvent } from '@/src/data-api/events';
2020

2121
/**
2222
* @internal
2323
*/
24-
export interface DataApiRequestInfo {
24+
export interface DataAPIRequestInfo {
2525
url: string;
2626
collection?: string;
2727
namespace?: string;
@@ -37,7 +37,7 @@ type ExecuteCommandOptions = TimeoutOptions & {
3737
/**
3838
* @internal
3939
*/
40-
export class DataApiHttpClient extends HttpClient {
40+
export class DataAPIHttpClient extends HttpClient {
4141
public collection?: string;
4242
public namespace?: string;
4343

@@ -48,7 +48,7 @@ export class DataApiHttpClient extends HttpClient {
4848
public async executeCommand(command: Record<string, any>, options: ExecuteCommandOptions | undefined) {
4949
const timeoutManager = options?.timeoutManager ?? mkTimeoutManager(options?.maxTimeMS);
5050

51-
return await this._requestDataApi({
51+
return await this._requestDataAPI({
5252
url: this.baseUrl,
5353
timeoutManager: timeoutManager,
5454
collection: options?.collection,
@@ -57,7 +57,7 @@ export class DataApiHttpClient extends HttpClient {
5757
});
5858
}
5959

60-
private async _requestDataApi(info: DataApiRequestInfo): Promise<RawDataApiResponse> {
60+
private async _requestDataAPI(info: DataAPIRequestInfo): Promise<RawDataAPIResponse> {
6161
let started = 0;
6262

6363
try {
@@ -124,7 +124,7 @@ const mkTimeoutErrorMaker = (timeout: number): MkTimeoutError => {
124124
return () => new DataAPITimeout(timeout);
125125
}
126126

127-
const mkFauxErroredResponse = (message: string): RawDataApiResponse => {
127+
const mkFauxErroredResponse = (message: string): RawDataAPIResponse => {
128128
return { errors: [{ message }] };
129129
}
130130

src/api/devops-api-http-client.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { hrTimeMs, HttpClient } from '@/src/api/http-client';
1616
import { AxiosError, AxiosResponse } from 'axios';
1717
import { HTTPClientOptions, HttpMethodStrings } from '@/src/api/types';
1818
import { HTTP1AuthHeaderFactories, HTTP1Strategy } from '@/src/api/http1';
19-
import { DevopsApiResponseError, DevopsApiTimeout, DevopsUnexpectedStateError } from '@/src/devops/errors';
19+
import { DevOpsAPIResponseError, DevOpsAPITimeout, DevOpsUnexpectedStateError } from '@/src/devops/errors';
2020
import { AdminBlockingOptions } from '@/src/devops/types';
2121
import { MkTimeoutError, TimeoutManager, TimeoutOptions } from '@/src/api/timeout-managers';
2222
import { HttpMethods } from '@/src/api/constants';
@@ -30,7 +30,7 @@ import {
3030
/**
3131
* @internal
3232
*/
33-
export interface DevopsApiRequestInfo {
33+
export interface DevOpsAPIRequestInfo {
3434
path: string,
3535
method: HttpMethodStrings,
3636
data?: Record<string, any>,
@@ -51,13 +51,13 @@ export interface LongRunningRequestInfo {
5151
/**
5252
* @internal
5353
*/
54-
export class DevopsApiHttpClient extends HttpClient {
54+
export class DevOpsAPIHttpClient extends HttpClient {
5555
constructor(props: HTTPClientOptions) {
5656
super(props);
57-
this.requestStrategy = new HTTP1Strategy(HTTP1AuthHeaderFactories.DevopsApi);
57+
this.requestStrategy = new HTTP1Strategy(HTTP1AuthHeaderFactories.DevOpsAPI);
5858
}
5959

60-
public async request(req: DevopsApiRequestInfo, options: TimeoutOptions | undefined, started: number = 0): Promise<AxiosResponse> {
60+
public async request(req: DevOpsAPIRequestInfo, options: TimeoutOptions | undefined, started: number = 0): Promise<AxiosResponse> {
6161
const isLongRunning = started !== 0;
6262

6363
try {
@@ -95,11 +95,11 @@ export class DevopsApiHttpClient extends HttpClient {
9595
if (!(e instanceof AxiosError)) {
9696
throw e;
9797
}
98-
throw new DevopsApiResponseError(e);
98+
throw new DevOpsAPIResponseError(e);
9999
}
100100
}
101101

102-
public async requestLongRunning(req: DevopsApiRequestInfo, info: LongRunningRequestInfo): Promise<AxiosResponse> {
102+
public async requestLongRunning(req: DevOpsAPIRequestInfo, info: LongRunningRequestInfo): Promise<AxiosResponse> {
103103
const timeoutManager = mkTimeoutManager(info.options?.maxTimeMS);
104104
const isLongRunning = info?.options?.blocking !== false;
105105

@@ -123,7 +123,7 @@ export class DevopsApiHttpClient extends HttpClient {
123123
return resp;
124124
}
125125

126-
private async _awaitStatus(id: string, req: DevopsApiRequestInfo, info: LongRunningRequestInfo, timeoutManager: TimeoutManager, started: number): Promise<void> {
126+
private async _awaitStatus(id: string, req: DevOpsAPIRequestInfo, info: LongRunningRequestInfo, timeoutManager: TimeoutManager, started: number): Promise<void> {
127127
if (info.options?.blocking === false) {
128128
return;
129129
}
@@ -153,7 +153,7 @@ export class DevopsApiHttpClient extends HttpClient {
153153
}
154154

155155
if (!info.legalStates.includes(resp.data?.status)) {
156-
const error = new DevopsUnexpectedStateError(`Created database is not in any legal state [${[info.target, ...info.legalStates].join(',')}]`, resp);
156+
const error = new DevOpsUnexpectedStateError(`Created database is not in any legal state [${[info.target, ...info.legalStates].join(',')}]`, resp);
157157

158158
if (this.monitorCommands) {
159159
this.emitter.emit('adminCommandFailed', new AdminCommandFailedEvent(req, true, error, started));
@@ -178,5 +178,5 @@ const mkTimeoutManager = (maxMs: number | undefined) => {
178178
}
179179

180180
const mkTimeoutErrorMaker = (timeout: number): MkTimeoutError => {
181-
return (info) => new DevopsApiTimeout(info.url, timeout);
181+
return (info) => new DevOpsAPITimeout(info.url, timeout);
182182
}

src/api/http-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { GuaranteedAPIResponse, HTTPClientOptions, HTTPRequestInfo, HTTPRequestS
1717
import { HTTP1AuthHeaderFactories, HTTP1Strategy } from '@/src/api/http1';
1818
import { HTTP2Strategy } from '@/src/api/http2';
1919
import { Mutable } from '@/src/data-api/types/utils';
20-
import { Caller, DataApiClientEvents } from '@/src/client';
20+
import { Caller, DataAPIClientEvents } from '@/src/client';
2121
import TypedEmitter from 'typed-emitter';
2222

2323
/**
@@ -27,7 +27,7 @@ export class HttpClient {
2727
public readonly baseUrl: string;
2828
public readonly userAgent: string;
2929
public requestStrategy: HTTPRequestStrategy;
30-
public emitter: TypedEmitter<DataApiClientEvents>;
30+
public emitter: TypedEmitter<DataAPIClientEvents>;
3131
public monitorCommands: boolean;
3232
#applicationToken: string;
3333

@@ -42,7 +42,7 @@ export class HttpClient {
4242
? options.requestStrategy :
4343
(options.useHttp2 !== false)
4444
? new HTTP2Strategy(this.baseUrl)
45-
: new HTTP1Strategy(HTTP1AuthHeaderFactories.DataApi);
45+
: new HTTP1Strategy(HTTP1AuthHeaderFactories.DataAPI);
4646

4747
if (options.baseApiPath) {
4848
this.baseUrl += '/' + options.baseApiPath;

src/api/http1.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const axiosAgent = axios.create({
3333
* @internal
3434
*/
3535
export const HTTP1AuthHeaderFactories = {
36-
DataApi(token: string) {
36+
DataAPI(token: string) {
3737
return { [DEFAULT_DATA_API_AUTH_HEADER]: token };
3838
},
39-
DevopsApi(token: string) {
39+
DevOpsAPI(token: string) {
4040
return { [DEFAULT_DEVOPS_API_AUTH_HEADER]: `Bearer ${token}` };
4141
},
4242
}

src/api/timeout-managers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type TimeoutOptions = {
3535
* @example
3636
* ```typescript
3737
* const mkTimeoutError: MkTimeoutError = (info) => {
38-
*   return new DevopsApiTimeout(info.url, timeout);
38+
*   return new DevOpsAPITimeout(info.url, timeout);
3939
* }
4040
* ```
4141
*

src/api/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Caller } from '@/src/client';
1616
import { TimeoutManager } from '@/src/api/timeout-managers';
1717
import { HttpMethods } from '@/src/api/constants';
1818
import TypedEmitter from 'typed-emitter';
19-
import { DataApiCommandEvents } from '@/src/data-api/events';
19+
import { DataAPICommandEvents } from '@/src/data-api/events';
2020

2121
/**
2222
* @internal
@@ -29,11 +29,11 @@ export interface HTTPClientOptions {
2929
useHttp2?: boolean;
3030
requestStrategy?: HTTPRequestStrategy;
3131
userAgent?: string;
32-
emitter: TypedEmitter<DataApiCommandEvents>;
32+
emitter: TypedEmitter<DataAPICommandEvents>;
3333
monitorCommands: boolean;
3434
}
3535

36-
export interface RawDataApiResponse {
36+
export interface RawDataAPIResponse {
3737
status?: Record<string, any>;
3838
errors?: any[];
3939
data?: Record<string, any>;

src/client/data-api-client.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import { AstraAdmin, mkAdmin } from '@/src/devops/astra-admin';
1717
import { AdminSpawnOptions, DbSpawnOptions, InternalRootClientOpts, RootClientOptions } from '@/src/client/types';
1818
import TypedEmitter from 'typed-emitter';
1919
import EventEmitter from 'events';
20-
import { DataApiCommandEvents } from '@/src/data-api/events';
20+
import { DataAPICommandEvents } from '@/src/data-api/events';
2121
import { AdminCommandEvents } from '@/src/devops';
2222

23-
export type DataApiClientEvents =
24-
& DataApiCommandEvents
23+
export type DataAPIClientEvents =
24+
& DataAPICommandEvents
2525
& AdminCommandEvents
2626

2727
/**
@@ -50,11 +50,11 @@ export type DataApiClientEvents =
5050
* console.log(await admin1.listDatabases());
5151
* ```
5252
*/
53-
export class DataApiClient extends (EventEmitter as new () => TypedEmitter<DataApiClientEvents>) {
53+
export class DataAPIClient extends (EventEmitter as new () => TypedEmitter<DataAPIClientEvents>) {
5454
readonly #options: InternalRootClientOpts;
5555

5656
/**
57-
* Constructs a new instance of the {@link DataApiClient}.
57+
* Constructs a new instance of the {@link DataAPIClient}.
5858
*
5959
* @param token - The default token to use when spawning new instances of {@link Db} or {@link AstraAdmin}.
6060
* @param options - The default options to use when spawning new instances of {@link Db} or {@link AstraAdmin}.
@@ -63,15 +63,15 @@ export class DataApiClient extends (EventEmitter as new () => TypedEmitter<DataA
6363
super();
6464

6565
if (!token || typeof token as any !== 'string') {
66-
throw new Error('A valid token is required to use the DataApiClient');
66+
throw new Error('A valid token is required to use the DataAPIClient');
6767
}
6868

6969
this.#options = {
7070
...options,
71-
dataApiOptions: {
71+
dbOptions: {
7272
monitorCommands: false,
7373
token: token,
74-
...options?.dataApiOptions,
74+
...options?.dbOptions,
7575
},
7676
adminOptions: {
7777
monitorCommands: false,
@@ -91,7 +91,7 @@ export class DataApiClient extends (EventEmitter as new () => TypedEmitter<DataA
9191
* `https://<db_id>-<region>.apps.astra.datastax.com`, but it can be used with DSE or any other Data-API-compatible
9292
* endpoint.
9393
*
94-
* The given options will override any default options set when creating the {@link DataApiClient} through
94+
* The given options will override any default options set when creating the {@link DataAPIClient} through
9595
* a deep merge (i.e. unset properties in the options object will just default to the default options).
9696
*
9797
* @example
@@ -110,7 +110,7 @@ export class DataApiClient extends (EventEmitter as new () => TypedEmitter<DataA
110110
* instead.
111111
*
112112
* @param endpoint - The direct endpoint to use.
113-
* @param options - Any options to override the default options set when creating the {@link DataApiClient}.
113+
* @param options - Any options to override the default options set when creating the {@link DataAPIClient}.
114114
*
115115
* @returns A new {@link Db} instance.
116116
*/
@@ -124,7 +124,7 @@ export class DataApiClient extends (EventEmitter as new () => TypedEmitter<DataA
124124
* This overload is purely for user convenience, but it **only supports using Astra as the underlying database**. For
125125
* DSE or any other Data-API-compatible endpoint, use the other overload instead.
126126
*
127-
* The given options will override any default options set when creating the {@link DataApiClient} through
127+
* The given options will override any default options set when creating the {@link DataAPIClient} through
128128
* a deep merge (i.e. unset properties in the options object will just default to the default options).
129129
*
130130
* @example
@@ -144,7 +144,7 @@ export class DataApiClient extends (EventEmitter as new () => TypedEmitter<DataA
144144
*
145145
* @param id - The database ID to use.
146146
* @param region - The region to use.
147-
* @param options - Any options to override the default options set when creating the {@link DataApiClient}.
147+
* @param options - Any options to override the default options set when creating the {@link DataAPIClient}.
148148
*
149149
* @returns A new {@link Db} instance.
150150
*/
@@ -160,7 +160,7 @@ export class DataApiClient extends (EventEmitter as new () => TypedEmitter<DataA
160160
*
161161
* **NB. This method is only available for Astra databases.**
162162
*
163-
* The given options will override any default options set when creating the {@link DataApiClient} through
163+
* The given options will override any default options set when creating the {@link DataAPIClient} through
164164
* a deep merge (i.e. unset properties in the options object will just default to the default options).
165165
*
166166
* @example
@@ -172,7 +172,7 @@ export class DataApiClient extends (EventEmitter as new () => TypedEmitter<DataA
172172
* console.log(dbs);
173173
* ```
174174
*
175-
* @param options - Any options to override the default options set when creating the {@link DataApiClient}.
175+
* @param options - Any options to override the default options set when creating the {@link DataAPIClient}.
176176
*
177177
* @returns A new {@link AstraAdmin} instance.
178178
*/

0 commit comments

Comments
 (0)