Skip to content

Commit a00596a

Browse files
committed
bit more cleanup
1 parent ad305dc commit a00596a

File tree

15 files changed

+43
-58
lines changed

15 files changed

+43
-58
lines changed

src/administration/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import type { DevOpsAPIRequestInfo } from '@/src/lib/api/clients/devops-api-http-client';
1717
import type { DataAPIErrorDescriptor } from '@/src/documents';
18-
import { DataAPIClientEvent } from '@/src/lib/logging/events';
18+
import { BaseDataAPIClientEvent } from '@/src/lib/logging/events';
1919
import { TimeoutDescriptor } from '@/src/lib/api/timeouts/timeouts';
2020

2121
/**
@@ -52,7 +52,7 @@ export type AdminCommandEventMap = {
5252
*
5353
* @public
5454
*/
55-
export abstract class AdminCommandEvent extends DataAPIClientEvent {
55+
export abstract class AdminCommandEvent extends BaseDataAPIClientEvent {
5656
/**
5757
* The path for the request, not including the Base URL.
5858
*/

src/client/opts-handlers/admin-opts-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { DecoderType, MonoidalOptionsHandler, OptionsHandlerTypes, Parsed, Unparse } from '@/src/lib/opts-handler';
15+
import { MonoidalOptionsHandler, OptionsHandlerTypes, Parsed, Unparse } from '@/src/lib/opts-handler';
1616
import { AdminOptions } from '@/src/client';
1717
import { TokenProvider } from '@/src/lib';
18-
import { object, oneOf, optional, record, string } from 'decoders';
18+
import { DecoderType, object, oneOf, optional, record, string } from 'decoders';
1919
import { Timeouts } from '@/src/lib/api/timeouts/timeouts';
2020
import { Logger } from '@/src/lib/logging/logger';
2121

src/client/opts-handlers/db-opts-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { DecoderType, MonoidalOptionsHandler, OptionsHandlerTypes, Parsed, Unparse } from '@/src/lib/opts-handler';
15+
import { MonoidalOptionsHandler, OptionsHandlerTypes, Parsed, Unparse } from '@/src/lib/opts-handler';
1616
import { DbOptions } from '@/src/client';
1717
import { TokenProvider } from '@/src/lib';
18-
import { Decoder, nullish, object, oneOf, optional, record, regex, string, unknown } from 'decoders';
18+
import { Decoder, DecoderType, nullish, object, oneOf, optional, record, regex, string, unknown } from 'decoders';
1919
import { Timeouts } from '@/src/lib/api/timeouts/timeouts';
2020
import { Logger } from '@/src/lib/logging/logger';
2121
import { TableSerDes } from '@/src/documents/tables/ser-des/ser-des';

src/client/opts-handlers/http-opts-handler.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { boolean, constant, either, inexact, object, optional, positiveInteger, taggedUnion } from 'decoders';
15+
import {
16+
boolean,
17+
constant,
18+
DecoderType,
19+
either,
20+
inexact,
21+
object,
22+
optional,
23+
positiveInteger,
24+
taggedUnion,
25+
} from 'decoders';
1626
import { function_, isNullish } from '@/src/lib/utils';
17-
import { DecoderType, OptionsHandler, OptionsHandlerTypes, Parsed } from '@/src/lib/opts-handler';
27+
import { OptionsHandler, OptionsHandlerTypes, Parsed } from '@/src/lib/opts-handler';
1828
import { DataAPIHttpOptions } from '@/src/client';
1929
import type { FetchCtx, Fetcher } from '@/src/lib/api/fetch/types';
2030
import { FetchH2, FetchNative } from '@/src/lib';

src/client/opts-handlers/root-opts-handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { DecoderType, OptionsHandler, OptionsHandlerTypes, Parsed } from '@/src/lib/opts-handler';
16-
import { DataAPIClientOptions, DataAPIClient } from '@/src/client';
15+
import { OptionsHandler, OptionsHandlerTypes, Parsed } from '@/src/lib/opts-handler';
16+
import { DataAPIClient, DataAPIClientOptions } from '@/src/client';
1717
import { type DataAPIClientEventMap, TokenProvider } from '@/src/lib';
18-
import { object, optional } from 'decoders';
18+
import { DecoderType, object, optional } from 'decoders';
1919
import { Timeouts } from '@/src/lib/api/timeouts/timeouts';
2020
import { Logger } from '@/src/lib/logging/logger';
2121
import { EnvironmentCfgHandler } from '@/src/client/opts-handlers/environment-cfg-handler';

src/db/db.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { CreateCollectionOptions } from '@/src/db/types/collections/create-colle
2323
import { TokenProvider } from '@/src/lib';
2424
import { DataAPIHttpClient, EmissionStrategy } from '@/src/lib/api/clients/data-api-http-client';
2525
import { KeyspaceRef } from '@/src/lib/api/clients/types';
26-
import { validateDataAPIEnv } from '@/src/lib/utils';
2726
import { EmbeddingHeadersProvider, FoundRow, SomeRow, Table, TableDropIndexOptions } from '@/src/documents';
2827
import { DEFAULT_DATA_API_PATHS } from '@/src/lib/api/constants';
2928
import { CollectionOptions } from '@/src/db/types/collections/collection-options';
@@ -44,6 +43,7 @@ import { TableSerDes } from '@/src/documents/tables/ser-des/ser-des';
4443
import { AdminOptsHandler } from '@/src/client/opts-handlers/admin-opts-handler';
4544
import { DbOptsHandler, ParsedDbOptions } from '@/src/client/opts-handlers/db-opts-handler';
4645
import { ParsedRootClientOpts } from '@/src/client/opts-handlers/root-opts-handler';
46+
import { EnvironmentCfgHandler } from '@/src/client/opts-handlers/environment-cfg-handler';
4747

4848
/**
4949
* #### Overview
@@ -369,9 +369,7 @@ export class Db {
369369
public admin(options: AdminOptions & { environment: Exclude<DataAPIEnvironment, 'astra'> }): DataAPIDbAdmin
370370

371371
public admin(options?: AdminOptions & { environment?: DataAPIEnvironment }): DbAdmin {
372-
const environment = options?.environment ?? 'astra';
373-
374-
validateDataAPIEnv(environment);
372+
const environment = EnvironmentCfgHandler.parseWithin(options, 'environment');
375373

376374
if (this.#defaultOpts.environment !== environment) {
377375
throw new InvalidEnvironmentError('db.admin()', environment, [this.#defaultOpts.environment], 'environment option is not the same as set in the DataAPIClient');
@@ -1200,6 +1198,9 @@ export class Db {
12001198
});
12011199
}
12021200

1201+
/**
1202+
* Backdoor to the HTTP client for if it's absolutely necessary. Which it almost never (if even ever) is.
1203+
*/
12031204
public get _httpClient(): OpaqueHttpClient {
12041205
return this.#httpClient;
12051206
}

src/documents/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import { DEFAULT_KEYSPACE, type RawDataAPIResponse } from '@/src/lib';
1616
// import { DataAPIClientEvent } from '@/src/lib/logging/events'; needs to be like this or it errors
17-
import { DataAPIClientEvent } from '@/src/lib/logging/events';
17+
import { BaseDataAPIClientEvent } from '@/src/lib/logging/events';
1818
import type { DataAPIRequestInfo } from '@/src/lib/api/clients/data-api-http-client';
1919
import type { DataAPIErrorDescriptor } from '@/src/documents/errors';
2020
import { TimeoutDescriptor } from '@/src/lib/api/timeouts/timeouts';
@@ -55,7 +55,7 @@ export type CommandEventMap = {
5555
*
5656
* @public
5757
*/
58-
export abstract class CommandEvent extends DataAPIClientEvent {
58+
export abstract class CommandEvent extends BaseDataAPIClientEvent {
5959
/**
6060
* The command object. Equal to the response body of the HTTP request.
6161
*

src/lib/logging/cfg-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { DecoderType, MonoidalOptionsHandler, OptionsHandlerTypes, Parsed } from '@/src/lib/opts-handler';
15+
import { MonoidalOptionsHandler, OptionsHandlerTypes, Parsed } from '@/src/lib/opts-handler';
1616
import { DataAPILoggingConfig, DataAPILoggingEvent, DataAPILoggingOutput } from '@/src/lib';
17-
import { array, either, nonEmptyArray, object, oneOf, optional } from 'decoders';
17+
import { array, DecoderType, either, nonEmptyArray, object, oneOf, optional } from 'decoders';
1818
import {
1919
LoggingDefaultOutputs,
2020
LoggingDefaults,

src/lib/logging/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @public
2222
*/
23-
export abstract class DataAPIClientEvent {
23+
export abstract class BaseDataAPIClientEvent {
2424
/**
2525
* The name of the event.
2626
*/
@@ -39,7 +39,7 @@ export abstract class DataAPIClientEvent {
3939
* Returns the event in a formatted string, as it would be logged to stdout/stderr (if enabled).
4040
*/
4141
public formatted(): string {
42-
return `${DataAPIClientEvent.formattedPrefix()}[${this.name}]`;
42+
return `${BaseDataAPIClientEvent.formattedPrefix()}[${this.name}]`;
4343
}
4444

4545
/**

src/lib/logging/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type {
3030
import { EmptyInternalLoggingConfig, EventConstructors } from '@/src/lib/logging/constants';
3131
import { buildOutputsMap } from '@/src/lib/logging/util';
3232
import type TypedEventEmitter from 'typed-emitter';
33-
import type { DataAPIClientEvent } from '@/src/lib';
33+
import type { BaseDataAPIClientEvent } from '@/src/lib';
3434
import { LoggingCfgHandler, ParsedLoggingConfig } from '@/src/lib/logging/cfg-handler';
3535

3636
/**
@@ -69,7 +69,7 @@ export class Logger implements Partial<Record<keyof DataAPIClientEventMap, unkno
6969
const event = _event as keyof DataAPIClientEventMap;
7070

7171
this[event] = (...args: any[]) => {
72-
const eventClass = new (<any>EventConstructors[event])(...args) as DataAPIClientEvent;
72+
const eventClass = new (<any>EventConstructors[event])(...args) as BaseDataAPIClientEvent;
7373

7474
if (outputs.event) {
7575
this.emitter.emit(event, <any>eventClass);

0 commit comments

Comments
 (0)