Skip to content

Commit 109f74d

Browse files
committed
Various 2.0 cleanups/tweaks (#83)
* more intuitive naming for events/logging stuff * formatting + timestamps for log messages * dropIndex ifExists * sourceModel * createindex options resturcuting * split filter & update types * remove cql from datatypes names * timeout for cursor.toArray() & coll.distinct() * added class names for admin event name sourcse * remove "spawn" from spawn type names
1 parent 9b33203 commit 109f74d

File tree

84 files changed

+1848
-1527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1848
-1527
lines changed

etc/astra-db-ts.api.md

Lines changed: 622 additions & 550 deletions
Large diffs are not rendered by default.

scripts/repl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sh scripts/build.sh -light || exit 2
1717
while [ $# -gt 0 ]; do
1818
case "$1" in
1919
"-local")
20-
export CLIENT_DB_ENVIRONMENT='dse'
20+
export CLIENT_DB_ENVIRONMENT='hcd'
2121
export CLIENT_DB_TOKEN='Cassandra:Y2Fzc2FuZHJh:Y2Fzc2FuZHJh'
2222
export CLIENT_DB_URL='http://localhost:8181'
2323
;;

src/administration/astra-admin.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { parseAdminSpawnOpts } from '@/src/client/parsers/spawn-admin';
2929
import { InternalRootClientOpts } from '@/src/client/types/internal';
3030
import { buildAstraEndpoint } from '@/src/lib/utils';
3131
import { Logger } from '@/src/lib/logging/logger';
32-
import { AdminSpawnOptions, DbSpawnOptions } from '@/src/client';
32+
import { AdminOptions, DbOptions } from '@/src/client';
3333
import { $CustomInspect } from '@/src/lib/constants';
3434
import { SomeDoc } from '@/src/documents';
3535
import { Timeouts } from '@/src/lib/api/timeouts';
@@ -71,7 +71,7 @@ export class AstraAdmin {
7171
*
7272
* @internal
7373
*/
74-
constructor(rootOpts: InternalRootClientOpts, rawAdminOpts?: AdminSpawnOptions) {
74+
constructor(rootOpts: InternalRootClientOpts, rawAdminOpts?: AdminOptions) {
7575
const adminOpts = parseAdminSpawnOpts(rawAdminOpts, 'options');
7676

7777
const token = TokenProvider.parseToken([adminOpts?.adminToken, rootOpts.adminOptions.adminToken], 'admin token');
@@ -142,7 +142,7 @@ export class AstraAdmin {
142142
*
143143
* @returns A new {@link Db} instance.
144144
*/
145-
public db(endpoint: string, options?: DbSpawnOptions): Db;
145+
public db(endpoint: string, options?: DbOptions): Db;
146146

147147
/**
148148
* Spawns a new {@link Db} instance using a direct endpoint and given options.
@@ -176,9 +176,9 @@ export class AstraAdmin {
176176
*
177177
* @returns A new {@link Db} instance.
178178
*/
179-
public db(id: string, region: string, options?: DbSpawnOptions): Db;
179+
public db(id: string, region: string, options?: DbOptions): Db;
180180

181-
public db(endpointOrId: string, regionOrOptions?: string | DbSpawnOptions, maybeOptions?: DbSpawnOptions): Db {
181+
public db(endpointOrId: string, regionOrOptions?: string | DbOptions, maybeOptions?: DbOptions): Db {
182182
const dbOpts = (typeof regionOrOptions === 'string')
183183
? maybeOptions
184184
: regionOrOptions;
@@ -229,7 +229,7 @@ export class AstraAdmin {
229229
*
230230
* @returns A new {@link Db} instance.
231231
*/
232-
public dbAdmin(endpoint: string, options?: DbSpawnOptions): AstraDbAdmin;
232+
public dbAdmin(endpoint: string, options?: DbOptions): AstraDbAdmin;
233233

234234
/**
235235
* Spawns a new {@link Db} instance using a direct endpoint and given options.
@@ -266,9 +266,9 @@ export class AstraAdmin {
266266
*
267267
* @returns A new {@link Db} instance.
268268
*/
269-
public dbAdmin(id: string, region: string, options?: DbSpawnOptions): AstraDbAdmin;
269+
public dbAdmin(id: string, region: string, options?: DbOptions): AstraDbAdmin;
270270

271-
public dbAdmin(endpointOrId: string, regionOrOptions?: string | DbSpawnOptions, maybeOptions?: DbSpawnOptions): AstraDbAdmin {
271+
public dbAdmin(endpointOrId: string, regionOrOptions?: string | DbOptions, maybeOptions?: DbOptions): AstraDbAdmin {
272272
/* @ts-expect-error - calls internal representation of method */
273273
return this.db(endpointOrId, regionOrOptions, maybeOptions).admin(this.#defaultOpts.adminOptions);
274274
}
@@ -291,6 +291,7 @@ export class AstraAdmin {
291291
const resp = await this.#httpClient.request({
292292
method: HttpMethods.Get,
293293
path: `/databases/${id}`,
294+
methodName: 'admin.dbInfo',
294295
}, tm);
295296

296297
return buildAstraDatabaseAdminInfo(resp.data!, this.#environment);
@@ -347,6 +348,7 @@ export class AstraAdmin {
347348
method: HttpMethods.Get,
348349
path: `/databases`,
349350
params: params,
351+
methodName: 'admin.listDatabases',
350352
}, tm);
351353

352354
return resp.data!.map((d: SomeDoc) => buildAstraDatabaseAdminInfo(d, this.#environment));
@@ -419,6 +421,7 @@ export class AstraAdmin {
419421
method: HttpMethods.Post,
420422
path: '/databases',
421423
data: definition,
424+
methodName: 'admin.createDatabase',
422425
}, {
423426
id: (resp) => resp.headers.location,
424427
target: 'ACTIVE',
@@ -466,6 +469,7 @@ export class AstraAdmin {
466469
await this.#httpClient.requestLongRunning({
467470
method: HttpMethods.Post,
468471
path: `/databases/${id}/terminate`,
472+
methodName: 'admin.dropDatabase',
469473
}, {
470474
id: id,
471475
target: 'TERMINATED',

src/administration/astra-db-admin.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import { $CustomInspect } from '@/src/lib/constants';
3232
import { AstraDbAdminInfo } from '@/src/administration/types/admin/database-info';
3333
import { Logger } from '@/src/lib/logging/logger';
3434
import { TimeoutManager, Timeouts } from '@/src/lib/api/timeouts';
35-
import { AdminSpawnOptions } from '@/src/client';
35+
import { AdminOptions } from '@/src/client';
36+
import { DataAPIHttpClient } from '@/src/lib/api/clients';
3637

3738
/**
3839
* An administrative class for managing Astra databases, including creating, listing, and deleting keyspaces.
@@ -69,6 +70,7 @@ import { AdminSpawnOptions } from '@/src/client';
6970
*/
7071
export class AstraDbAdmin extends DbAdmin {
7172
readonly #httpClient: DevOpsAPIHttpClient;
73+
readonly #dataApiHttpClient: DataAPIHttpClient<'admin'>;
7274
readonly #db: Db;
7375
readonly #environment: 'dev' | 'test' | 'prod';
7476

@@ -77,7 +79,7 @@ export class AstraDbAdmin extends DbAdmin {
7779
*
7880
* @internal
7981
*/
80-
constructor(db: Db, rootOpts: InternalRootClientOpts, rawAdminOpts: AdminSpawnOptions | undefined, dbToken: TokenProvider | undefined, endpoint: string) {
82+
constructor(db: Db, rootOpts: InternalRootClientOpts, rawAdminOpts: AdminOptions | undefined, dbToken: TokenProvider | undefined, endpoint: string) {
8183
super();
8284

8385
const adminOpts = parseAdminSpawnOpts(rawAdminOpts, 'options');
@@ -101,6 +103,7 @@ export class AstraDbAdmin extends DbAdmin {
101103
timeoutDefaults: Timeouts.merge(rootOpts.adminOptions.timeoutDefaults, adminOpts?.timeoutDefaults),
102104
});
103105

106+
this.#dataApiHttpClient = db._httpClient.forDbAdmin(adminOpts);
104107
this.#db = db;
105108

106109
Object.defineProperty(this, $CustomInspect, {
@@ -155,8 +158,9 @@ export class AstraDbAdmin extends DbAdmin {
155158
* @returns The available embedding providers.
156159
*/
157160
public override async findEmbeddingProviders(options?: WithTimeout<'databaseAdminTimeoutMs'>): Promise<FindEmbeddingProvidersResult> {
158-
const resp = await this.#db._httpClient.executeCommand({ findEmbeddingProviders: {} }, {
161+
const resp = await this.#dataApiHttpClient.executeCommand({ findEmbeddingProviders: {} }, {
159162
timeoutManager: this.#httpClient.tm.single('databaseAdminTimeoutMs', options),
163+
methodName: 'dbAdmin.findEmbeddingProviders',
160164
keyspace: null,
161165
});
162166
return resp.status as FindEmbeddingProvidersResult;
@@ -179,7 +183,7 @@ export class AstraDbAdmin extends DbAdmin {
179183
*/
180184
public async info(options?: WithTimeout<'databaseAdminTimeoutMs'>): Promise<AstraDbAdminInfo> {
181185
const tm = this.#httpClient.tm.single('databaseAdminTimeoutMs', options);
182-
return this.#info(tm);
186+
return this.#info('dbAdmin.info', tm);
183187
}
184188

185189
/**
@@ -200,7 +204,7 @@ export class AstraDbAdmin extends DbAdmin {
200204
*/
201205
public override async listKeyspaces(options?: WithTimeout<'keyspaceAdminTimeoutMs'>): Promise<string[]> {
202206
const tm = this.#httpClient.tm.single('keyspaceAdminTimeoutMs', options);
203-
return this.#info(tm).then(i => i.keyspaces);
207+
return this.#info('dbAdmin.listKeyspaces', tm).then(i => i.keyspaces);
204208
}
205209

206210
/**
@@ -243,6 +247,7 @@ export class AstraDbAdmin extends DbAdmin {
243247
await this.#httpClient.requestLongRunning({
244248
method: HttpMethods.Post,
245249
path: `/databases/${this.#db.id}/keyspaces/${keyspace}`,
250+
methodName: 'dmAdmin.createKeyspace',
246251
}, {
247252
id: this.#db.id,
248253
target: 'ACTIVE',
@@ -290,6 +295,7 @@ export class AstraDbAdmin extends DbAdmin {
290295
await this.#httpClient.requestLongRunning({
291296
method: HttpMethods.Delete,
292297
path: `/databases/${this.#db.id}/keyspaces/${keyspace}`,
298+
methodName: 'dbAdmin.dropKeyspace',
293299
}, {
294300
id: this.#db.id,
295301
target: 'ACTIVE',
@@ -327,6 +333,7 @@ export class AstraDbAdmin extends DbAdmin {
327333
await this.#httpClient.requestLongRunning({
328334
method: HttpMethods.Post,
329335
path: `/databases/${this.#db.id}/terminate`,
336+
methodName: 'dbAdmin.drop',
330337
}, {
331338
id: this.#db.id,
332339
target: 'TERMINATED',
@@ -341,10 +348,11 @@ export class AstraDbAdmin extends DbAdmin {
341348
return this.#httpClient;
342349
}
343350

344-
async #info(tm: TimeoutManager): Promise<AstraDbAdminInfo> {
351+
async #info(methodName: string, tm: TimeoutManager): Promise<AstraDbAdminInfo> {
345352
const resp = await this.#httpClient.request({
346353
method: HttpMethods.Get,
347354
path: `/databases/${this.#db.id}`,
355+
methodName,
348356
}, tm);
349357

350358
return buildAstraDatabaseAdminInfo(resp.data!, this.#environment);

src/administration/data-api-db-admin.ts

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

16-
import { LocalCreateKeyspaceOptions } from '@/src/administration/types';
16+
import { DataAPICreateKeyspaceOptions } from '@/src/administration/types';
1717
import { DbAdmin } from '@/src/administration/db-admin';
1818
import type { WithTimeout } from '@/src/lib';
1919
import { FindEmbeddingProvidersResult } from '@/src/administration/types/db-admin/find-embedding-providers';
2020
import { DataAPIHttpClient } from '@/src/lib/api/clients/data-api-http-client';
2121
import { Db } from '@/src/db';
2222
import { parseAdminSpawnOpts } from '@/src/client/parsers/spawn-admin';
2323
import { $CustomInspect } from '@/src/lib/constants';
24-
import { AdminSpawnOptions } from '@/src/client';
24+
import { AdminOptions } from '@/src/client';
2525

2626
/**
2727
* An administrative class for managing non-Astra databases, including creating, listing, and deleting keyspaces.
@@ -57,15 +57,15 @@ import { AdminSpawnOptions } from '@/src/client';
5757
* @public
5858
*/
5959
export class DataAPIDbAdmin extends DbAdmin {
60-
readonly #httpClient: DataAPIHttpClient;
60+
readonly #httpClient: DataAPIHttpClient<'admin'>;
6161
readonly #db: Db;
6262

6363
/**
6464
* Use {@link Db.admin} to obtain an instance of this class.
6565
*
6666
* @internal
6767
*/
68-
constructor(db: Db, httpClient: DataAPIHttpClient, rawAdminOpts?: AdminSpawnOptions) {
68+
constructor(db: Db, httpClient: DataAPIHttpClient, rawAdminOpts?: AdminOptions) {
6969
super();
7070
const adminOpts = parseAdminSpawnOpts(rawAdminOpts, 'options');
7171
this.#httpClient = httpClient.forDbAdmin(adminOpts);
@@ -116,6 +116,7 @@ export class DataAPIDbAdmin extends DbAdmin {
116116
public override async findEmbeddingProviders(options?: WithTimeout<'databaseAdminTimeoutMs'>): Promise<FindEmbeddingProvidersResult> {
117117
const resp = await this.#httpClient.executeCommand({ findEmbeddingProviders: {} }, {
118118
timeoutManager: this.#httpClient.tm.single('databaseAdminTimeoutMs', options),
119+
methodName: 'dbAdmin.findEmbeddingProviders',
119120
keyspace: null,
120121
});
121122
return resp.status as FindEmbeddingProvidersResult;
@@ -140,6 +141,7 @@ export class DataAPIDbAdmin extends DbAdmin {
140141
public override async listKeyspaces(options?: WithTimeout<'keyspaceAdminTimeoutMs'>): Promise<string[]> {
141142
const resp = await this.#httpClient.executeCommand({ findKeyspaces: {} }, {
142143
timeoutManager: this.#httpClient.tm.single('keyspaceAdminTimeoutMs', options),
144+
methodName: 'dbAdmin.listKeyspaces',
143145
keyspace: null,
144146
});
145147
return resp.status!.keyspaces;
@@ -175,7 +177,7 @@ export class DataAPIDbAdmin extends DbAdmin {
175177
*
176178
* @returns A promise that resolves when the operation completes.
177179
*/
178-
public override async createKeyspace(keyspace: string, options?: LocalCreateKeyspaceOptions): Promise<void> {
180+
public override async createKeyspace(keyspace: string, options?: DataAPICreateKeyspaceOptions): Promise<void> {
179181
if (options?.updateDbKeyspace) {
180182
this.#db.useKeyspace(keyspace);
181183
}
@@ -187,6 +189,7 @@ export class DataAPIDbAdmin extends DbAdmin {
187189

188190
await this.#httpClient.executeCommand({ createKeyspace: { name: keyspace, options: { replication } } }, {
189191
timeoutManager: this.#httpClient.tm.single('keyspaceAdminTimeoutMs', options),
192+
methodName: 'dbAdmin.createKeyspace',
190193
keyspace: null,
191194
});
192195
}
@@ -215,6 +218,7 @@ export class DataAPIDbAdmin extends DbAdmin {
215218
public override async dropKeyspace(keyspace: string, options?: WithTimeout<'keyspaceAdminTimeoutMs'>): Promise<void> {
216219
await this.#httpClient.executeCommand({ dropKeyspace: { name: keyspace } }, {
217220
timeoutManager: this.#httpClient.tm.single('keyspaceAdminTimeoutMs', options),
221+
methodName: 'dbAdmin.dropKeyspace',
218222
keyspace: null,
219223
});
220224
}

0 commit comments

Comments
 (0)