Skip to content

Commit f716d06

Browse files
committed
some reworking of types
1 parent b005140 commit f716d06

22 files changed

+82
-76
lines changed

etc/astra-db-ts.api.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ export class CursorAlreadyInitializedError extends DataAPIError {
300300

301301
// @public
302302
export class DataAPIClient extends DataAPIClientEventEmitterBase {
303-
constructor(token: string, options?: RootClientOptions | null);
303+
constructor(token: string, options?: DataAPIClientOptions | null);
304304
admin(options?: AdminSpawnOptions): AstraAdmin;
305305
db(endpoint: string, options?: DbSpawnOptions): Db;
306306
db(id: string, region: string, options?: DbSpawnOptions): Db;
@@ -312,6 +312,13 @@ export const DataAPIClientEventEmitterBase: new () => TypedEmitter<DataAPIClient
312312
// @public (undocumented)
313313
export type DataAPIClientEvents = DataAPICommandEvents & AdminCommandEvents;
314314

315+
// @public
316+
export interface DataAPIClientOptions {
317+
adminOptions?: AdminSpawnOptions;
318+
caller?: Caller | Caller[];
319+
dbOptions?: DbSpawnOptions;
320+
}
321+
315322
// @public
316323
export type DataAPICommandEvents = {
317324
commandStarted: (event: CommandStartedEvent) => void;
@@ -938,13 +945,6 @@ export interface ReplaceOneOptions extends WithTimeout {
938945
// @public
939946
export type ReplaceOneResult<Schema extends SomeDoc> = InternalUpdateResult<Schema, 0 | 1>;
940947

941-
// @public
942-
export interface RootClientOptions {
943-
adminOptions?: AdminSpawnOptions;
944-
caller?: Caller | Caller[];
945-
dbOptions?: DbSpawnOptions;
946-
}
947-
948948
// @public
949949
export interface RunCommandOptions extends WithNamespace, WithTimeout {
950950
collection?: string;
@@ -1056,7 +1056,7 @@ export type TypeErr<S> = unknown & {
10561056

10571057
// @public (undocumented)
10581058
export type Unset<Schema> = {
1059-
[K in keyof Schema]?: '';
1059+
[K in keyof Schema]?: '' | true | 1;
10601060
};
10611061

10621062
// @public
@@ -1076,7 +1076,7 @@ export interface UpdateFilter<Schema extends SomeDoc> {
10761076
$rename?: Record<string, string>;
10771077
$set?: Partial<Schema> & SomeDoc;
10781078
$setOnInsert?: Partial<Schema> & SomeDoc;
1079-
$unset?: Record<string, ''>;
1079+
$unset?: Record<string, '' | true | 1>;
10801080
}
10811081

10821082
// @public

src/client/data-api-client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
Caller,
2020
DbSpawnOptions,
2121
InternalRootClientOpts,
22-
RootClientOptions,
22+
DataAPIClientOptions,
2323
} from '@/src/client/types';
2424
import TypedEmitter from 'typed-emitter';
2525
import EventEmitter from 'events';
@@ -47,7 +47,7 @@ export const DataAPIClientEventEmitterBase = EventEmitter as (new () => TypedEmi
4747
* The client takes in a default token, which can be overridden by a stronger/weaker token when spawning a new
4848
* {@link Db} or {@link AstraAdmin} instance.
4949
*
50-
* It also takes in a set of default options (see {@link RootClientOptions}) that may also be overridden as necessary.
50+
* It also takes in a set of default options (see {@link DataAPIClientOptions}) that may also be overridden as necessary.
5151
*
5252
* @example
5353
* ```typescript
@@ -76,7 +76,7 @@ export class DataAPIClient extends DataAPIClientEventEmitterBase {
7676
* @param token - The default token to use when spawning new instances of {@link Db} or {@link AstraAdmin}.
7777
* @param options - The default options to use when spawning new instances of {@link Db} or {@link AstraAdmin}.
7878
*/
79-
constructor(token: string, options?: RootClientOptions | null) {
79+
constructor(token: string, options?: DataAPIClientOptions | null) {
8080
super();
8181

8282
if (!token || typeof token as any !== 'string') {
@@ -200,7 +200,7 @@ export class DataAPIClient extends DataAPIClientEventEmitterBase {
200200
}
201201
}
202202

203-
function validateRootOpts(opts: RootClientOptions | undefined | null) {
203+
function validateRootOpts(opts: DataAPIClientOptions | undefined | null) {
204204
validateOption('root client options', opts, 'object');
205205

206206
if (!opts) {

src/client/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export type Caller = [name: string, version?: string];
4141
*
4242
* @public
4343
*/
44-
export interface RootClientOptions {
44+
export interface DataAPIClientOptions {
4545
/**
4646
* The caller information to send with requests, of the form `[name, version?]`, or an array of such.
4747
*

src/data-api/collection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ export class Collection<Schema extends SomeDoc = SomeDoc> {
794794
*
795795
* @see StrictFilter
796796
*/
797-
find<GetSim extends boolean = false>(filter: Filter<Schema>, options?: FindOptions<GetSim>): FindCursor<FoundDoc<Schema, GetSim>, FoundDoc<Schema, GetSim>> {
797+
find(filter: Filter<Schema>, options?: FindOptions): FindCursor<FoundDoc<Schema>, FoundDoc<Schema>> {
798798
return new FindCursor(this.namespace, this._httpClient, filter as any, coalesceVectorSpecialsIntoSort(options)) as any;
799799
}
800800

@@ -856,11 +856,11 @@ export class Collection<Schema extends SomeDoc = SomeDoc> {
856856
*
857857
* @see StrictFilter
858858
*/
859-
public async distinct<Key extends string, GetSim extends boolean = false>(key: Key, filter: Filter<Schema> = {}): Promise<Flatten<(SomeDoc & ToDotNotation<FoundDoc<Schema, GetSim>>)[Key]>[]> {
859+
public async distinct<Key extends string>(key: Key, filter: Filter<Schema> = {}): Promise<Flatten<(SomeDoc & ToDotNotation<FoundDoc<Schema>>)[Key]>[]> {
860860
assertPathSafe4Distinct(key);
861861

862862
const projection = pullSafeProjection4Distinct(key);
863-
const cursor = this.find<GetSim>(filter, { projection: { _id: 0, [projection]: 1 } });
863+
const cursor = this.find(filter, { projection: { _id: 0, [projection]: 1 } });
864864

865865
const seen = new Set<unknown>();
866866
const ret = [];
@@ -932,7 +932,7 @@ export class Collection<Schema extends SomeDoc = SomeDoc> {
932932
*
933933
* @see StrictFilter
934934
*/
935-
public async findOne<GetSim extends boolean = false>(filter: Filter<Schema>, options?: FindOneOptions<GetSim>): Promise<FoundDoc<Schema, GetSim> | null> {
935+
public async findOne(filter: Filter<Schema>, options?: FindOneOptions): Promise<FoundDoc<Schema> | null> {
936936
options = coalesceVectorSpecialsIntoSort(options);
937937

938938
const command: FindOneCommand = {

src/data-api/cursor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const enum CursorStatus {
7676
export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
7777
private readonly _namespace: string;
7878
private readonly _httpClient: DataAPIHttpClient;
79-
private readonly _options: FindOptions<boolean>;
79+
private readonly _options: FindOptions;
8080
private _filter: Filter<SomeDoc>;
8181
private _mapping?: (doc: unknown) => T;
8282

@@ -89,7 +89,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
8989
*
9090
* @internal
9191
*/
92-
constructor(namespace: string, httpClient: DataAPIHttpClient, filter: Filter<SomeDoc>, options?: FindOptions<boolean>) {
92+
constructor(namespace: string, httpClient: DataAPIHttpClient, filter: Filter<SomeDoc>, options?: FindOptions) {
9393
this._namespace = namespace;
9494
this._httpClient = httpClient;
9595
this._filter = filter;

src/data-api/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ export class Db implements Disposable {
398398
* @example
399399
* ```typescript
400400
* // [{ name: "users" }, { name: "posts" }]
401-
* console.log(await db.listCollections());
401+
* console.log(await db.listCollections({ nameOnly: true }));
402402
* ```
403403
*
404404
* @param options - Options for this operation.
@@ -419,7 +419,7 @@ export class Db implements Disposable {
419419
* @example
420420
* ```typescript
421421
* // [{ name: "users" }, { name: "posts", options: { ... } }]
422-
* console.log(await db.listCollections({ nameOnly: false }));
422+
* console.log(await db.listCollections());
423423
* ```
424424
*
425425
* @param options - Options for this operation.

src/data-api/types/common.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import type { ToDotNotation } from '@/src/data-api/types';
2020
*/
2121
export type SomeId = string | number | bigint | boolean | Date | UUID | ObjectId;
2222

23+
/**
24+
* @public
25+
*/
26+
export type SortDirection = 1 | -1;
27+
2328
/**
2429
* Specifies the sort criteria for selecting documents.
2530
*
@@ -46,7 +51,7 @@ export type SomeId = string | number | bigint | boolean | Date | UUID | ObjectId
4651
* @public
4752
*/
4853
export type Sort =
49-
| Record<string, 1 | -1>
54+
| Record<string, SortDirection>
5055
| { $vector: number[] }
5156
| { $vectorize: string };
5257

src/data-api/types/find/find-one.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface FindOneCommand {
3737
*
3838
* @public
3939
*/
40-
export interface FindOneOptions<GetSim extends boolean> extends WithTimeout {
40+
export interface FindOneOptions extends WithTimeout {
4141
/**
4242
* The order in which to apply the update if the filter selects multiple documents.
4343
*
@@ -119,5 +119,5 @@ export interface FindOneOptions<GetSim extends boolean> extends WithTimeout {
119119
* console.log(doc?.$similarity);
120120
* ```
121121
*/
122-
includeSimilarity?: GetSim,
122+
includeSimilarity?: boolean,
123123
}

src/data-api/types/find/find.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type { Projection, Sort } from '@/src/data-api/types';
2828
*
2929
* @public
3030
*/
31-
export interface FindOptions<GetSim extends boolean> {
31+
export interface FindOptions {
3232
/**
3333
* The order in which to apply the update if the filter selects multiple documents.
3434
*
@@ -122,7 +122,7 @@ export interface FindOptions<GetSim extends boolean> {
122122
* console.log(doc?.$similarity);
123123
* ```
124124
*/
125-
includeSimilarity?: GetSim;
125+
includeSimilarity?: boolean;
126126
}
127127

128128
/** @internal */

src/data-api/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ export * from './common';
3737
export * from './dot-notation';
3838
export * from './filter';
3939
export * from './update-filter';
40-
export { WithId, MaybeId, WithSim, FoundDoc, NoId, Flatten, IdOf } from './utils';
40+
export { WithId, MaybeId, FoundDoc, NoId, Flatten, IdOf } from './utils';

0 commit comments

Comments
 (0)