Skip to content

Commit 4cca38f

Browse files
authored
Cursor refactors & alignment (#76)
* various cursor tweaks & fixes * minor typing tweaks * fixed bug with filter being potentially muitable * made cursors immutable * some tests not all idk
1 parent 432c807 commit 4cca38f

File tree

16 files changed

+481
-874
lines changed

16 files changed

+481
-874
lines changed

src/db/types/collections/collections-common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,3 @@ export interface DefaultIdOptions {
192192
*/
193193
type: 'uuid' | 'uuidv6' | 'uuidv7' | 'objectId';
194194
}
195-

src/documents/commands/command-impls.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ export class CommandImpls<ID> {
190190
}
191191

192192
public find<Schema extends SomeDoc>(keyspace: string, filter: SomeDoc, options?: GenericFindOptions): FindCursor<Schema, Schema> {
193-
return new FindCursor(keyspace, this.#httpClient, filter, options);
193+
if (options?.sort) {
194+
options.sort = normalizedSort(options.sort);
195+
}
196+
return new FindCursor(keyspace, this.#httpClient, structuredClone(filter), structuredClone(options));
194197
}
195198

196199
public async findOne<Schema>(filter: SomeDoc, options?: GenericFindOneOptions): Promise<Schema | null> {

src/documents/cursor.ts

Lines changed: 233 additions & 236 deletions
Large diffs are not rendered by default.

src/documents/errors.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -240,40 +240,6 @@ export class TooManyDocumentsToCountError extends DataAPIError {
240240
}
241241
}
242242

243-
/**
244-
* Caused by trying to perform an operation on an already-initialized {@link FindCursor} that requires it to be
245-
* uninitialized.
246-
*
247-
* If you run into this error, and you really do need to change an option on the cursor, you can rewind the cursor
248-
* using {@link FindCursor.rewind}, or clone it using {@link FindCursor.clone}.
249-
*
250-
* @example
251-
* ```typescript
252-
* await collections.find({}).toArray();
253-
*
254-
* try {
255-
*   await cursor.limit(10);
256-
* } catch (e) {
257-
*   if (e instanceof CursorIsStartedError) {
258-
*   console.log(e.message); // "Cursor is already initialized..."
259-
*   }
260-
* }
261-
* ```
262-
*
263-
* @public
264-
*/
265-
export class CursorIsStartedError extends DataAPIError {
266-
/**
267-
* Should not be instantiated by the user.
268-
*
269-
* @internal
270-
*/
271-
constructor(message: string) {
272-
super(message);
273-
this.name = 'CursorIsStartedError';
274-
}
275-
}
276-
277243
/**
278244
* An error representing the *complete* errors for an operation. This is a cohesive error that represents all the
279245
* errors that occurred during a single operation, and should not be thought of as *always* 1:1 with the number of

src/documents/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export {
2727
DataAPIHttpError,
2828
DataAPITimeoutError,
2929
CumulativeDataAPIError,
30-
CursorIsStartedError,
3130
DataAPIDetailedErrorDescriptor,
3231
DataAPIError,
3332
DataAPIErrorDescriptor,

src/documents/tables/test.ts

Lines changed: 0 additions & 242 deletions
This file was deleted.

src/lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
export * from './api';
1616
export * from './token-providers';
1717
export { DataAPIEnvironments } from './constants';
18-
export type { nullish, WithTimeout, DataAPIEnvironment } from './types';
18+
export type { nullish, WithTimeout, DataAPIEnvironment, DeepPartial } from './types';

src/lib/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,12 @@ export type Ref<T> = { ref: T }
5151

5252
// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- Used for when intersection w/ {} is a "noop"
5353
export type EmptyObj = {};
54+
55+
/**
56+
* Recursively makes all properties of a type optional.
57+
*
58+
* @public
59+
*/
60+
export type DeepPartial<T> = T extends object ? {
61+
[P in keyof T]?: DeepPartial<T[P]>;
62+
} : T;

tests/integration/documents/collections/delete-many.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ parallel('integration.documents.collections.delete-many', { truncateColls: 'both
6161
} catch (e) {
6262
assert.ok(e instanceof Error);
6363
assert.ok(!(e instanceof DataAPIError));
64-
assert.strictEqual(e.message, 'test');
64+
assert.strictEqual(e.message, 'failing_client');
6565
}
6666
});
6767
});

tests/integration/documents/collections/insert-many.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ parallel('integration.documents.collections.insert-many', { truncateColls: 'defa
153153
} catch (e) {
154154
assert.ok(e instanceof Error);
155155
assert.ok(!(e instanceof DataAPIError));
156-
assert.strictEqual(e.message, 'test');
156+
assert.strictEqual(e.message, 'failing_client');
157157
}
158158
});
159159

@@ -165,7 +165,7 @@ parallel('integration.documents.collections.insert-many', { truncateColls: 'defa
165165
} catch (e) {
166166
assert.ok(e instanceof Error);
167167
assert.ok(!(e instanceof DataAPIError));
168-
assert.strictEqual(e.message, 'test');
168+
assert.strictEqual(e.message, 'failing_client');
169169
}
170170
});
171171

tests/integration/documents/collections/update-many.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ parallel('integration.documents.collections.update-many', { truncateColls: 'defa
790790
} catch (e) {
791791
assert.ok(e instanceof Error);
792792
assert.ok(!(e instanceof DataAPIError));
793-
assert.strictEqual(e.message, 'test');
793+
assert.strictEqual(e.message, 'failing_client');
794794
}
795795
});
796796
});

0 commit comments

Comments
 (0)