Skip to content

Commit 1faa131

Browse files
authored
Expose cursor page state (#110)
* Remove reset2idle in .getSortVector() as it breaks "no mutating options after first fetch" promise * Update a large amount of cursor documentation * major refactor of cursors to consolidate duplicate logic; added properly exposed page state via initalPageState and fetchNextPage() * add documentation regarding the page state constructs * add tests for page state exposure
1 parent a031b21 commit 1faa131

File tree

39 files changed

+1947
-750
lines changed

39 files changed

+1947
-750
lines changed

etc/astra-db-ts.api.md

Lines changed: 58 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,36 @@ export abstract class AbstractCursor<T, TRaw extends SomeDoc = SomeDoc> {
3636
buffered(): number;
3737
// @deprecated
3838
bufferedCount: 'ERROR: `.bufferedCount()` has been renamed to be simply `.buffered()`';
39-
// (undocumented)
4039
abstract clone(): this;
4140
close(): void;
4241
consumeBuffer(max?: number): TRaw[];
4342
consumed(): number;
43+
// @internal (undocumented)
44+
protected _currentPage?: {
45+
result: TRaw[];
46+
};
47+
// Warning: (ae-forgotten-export) The symbol "TimeoutManager" needs to be exported by the entry point index.d.ts
48+
//
49+
// @internal (undocumented)
50+
protected abstract _fetchNextPage(extra: Record<string, unknown>, tm: TimeoutManager | undefined): Promise<[page: typeof AbstractCursor._currentPage, isNextPage: boolean]>;
4451
forEach(consumer: ((doc: T) => boolean | Promise<boolean>) | ((doc: T) => void | Promise<void>)): Promise<void>;
4552
hasNext(): Promise<boolean>;
46-
// (undocumented)
4753
abstract map<R>(map: (doc: T) => R): AbstractCursor<R, TRaw>;
4854
// @internal (undocumented)
4955
readonly _mapping?: (doc: any) => T;
5056
next(): Promise<T | null>;
5157
// @internal (undocumented)
52-
protected _next(peek: true, method: string, tm?: TimeoutManager): Promise<boolean>;
53-
// @internal (undocumented)
54-
protected _next(peek: false, method: string, tm?: TimeoutManager): Promise<T | null>;
55-
// Warning: (ae-forgotten-export) The symbol "TimeoutManager" needs to be exported by the entry point index.d.ts
56-
//
57-
// @internal (undocumented)
58-
protected abstract _nextPage(extra: Record<string, unknown>, tm: TimeoutManager | undefined): Promise<TRaw[]>;
59-
// Warning: (ae-forgotten-export) The symbol "QueryState" needs to be exported by the entry point index.d.ts
60-
//
58+
_next(peek: true, method: string, tm?: TimeoutManager): Promise<true | null>;
6159
// @internal (undocumented)
62-
protected _nextPageState: QueryState<string>;
63-
// @internal (undocumented)
64-
readonly _options: WithTimeout<'generalMethodTimeoutMs'>;
60+
_next(peek: false, method: string, tm?: TimeoutManager): Promise<T | null>;
6561
// @deprecated
6662
readBufferedDocuments: 'ERROR: `.readBufferedDocuments()` has been renamed to be `.consumeBuffer()`';
6763
rewind(): void;
6864
get state(): CursorState;
6965
// @internal (undocumented)
7066
protected _state: CursorState;
67+
// @internal (undocumented)
68+
readonly _timeoutOptions: WithTimeout<'generalMethodTimeoutMs'>;
7169
// Warning: (ae-forgotten-export) The symbol "Timeouts" needs to be exported by the entry point index.d.ts
7270
//
7371
// @internal (undocumented)
@@ -457,7 +455,7 @@ export class Collection<WSchema extends SomeDoc = SomeDoc, RSchema extends WithI
457455
findOne<TRaw extends SomeDoc = WithSim<RSchema>>(filter: CollectionFilter<WSchema>, options?: CollectionFindOneOptions): Promise<TRaw | null>;
458456
findOneAndDelete<TRaw extends SomeDoc = RSchema>(filter: CollectionFilter<WSchema>, options?: CollectionFindOneAndDeleteOptions): Promise<TRaw | null>;
459457
findOneAndReplace<TRaw extends SomeDoc = RSchema>(filter: CollectionFilter<WSchema>, replacement: NoId<WSchema>, options?: CollectionFindOneAndReplaceOptions): Promise<TRaw | null>;
460-
findOneAndUpdate(filter: CollectionFilter<WSchema>, update: CollectionUpdateFilter<WSchema>, options?: CollectionFindOneAndUpdateOptions): Promise<RSchema | null>;
458+
findOneAndUpdate<TRaw extends SomeDoc = RSchema>(filter: CollectionFilter<WSchema>, update: CollectionUpdateFilter<WSchema>, options?: CollectionFindOneAndUpdateOptions): Promise<TRaw | null>;
461459
get _httpClient(): OpaqueHttpClient;
462460
insertMany(documents: readonly MaybeId<WSchema>[], options?: CollectionInsertManyOptions): Promise<CollectionInsertManyResult<RSchema>>;
463461
insertOne(document: MaybeId<WSchema>, options?: CollectionInsertOneOptions): Promise<CollectionInsertOneResult<RSchema>>;
@@ -616,9 +614,7 @@ export type CollectionFilterOps<Elem> = {
616614
export class CollectionFindAndRerankCursor<T, TRaw extends SomeDoc = SomeDoc> extends FindAndRerankCursor<T, TRaw> {
617615
get dataSource(): Collection;
618616
filter(filter: CollectionFilter<TRaw>): this;
619-
// (undocumented)
620617
map: <R>(map: (doc: T) => R) => CollectionFindAndRerankCursor<R, TRaw>;
621-
// (undocumented)
622618
project: <RRaw extends SomeDoc = Partial<TRaw>>(projection: Projection) => CollectionFindAndRerankCursor<RerankedResult<RRaw>, RRaw>;
623619
}
624620

@@ -629,11 +625,8 @@ export type CollectionFindAndRerankOptions = GenericFindAndRerankOptions;
629625
export class CollectionFindCursor<T, TRaw extends SomeDoc = SomeDoc> extends FindCursor<T, TRaw> {
630626
get dataSource(): Collection;
631627
filter(filter: CollectionFilter<TRaw>): this;
632-
// (undocumented)
633628
includeSimilarity: (includeSimilarity?: boolean) => CollectionFindCursor<WithSim<TRaw>, WithSim<TRaw>>;
634-
// (undocumented)
635629
map: <R>(map: (doc: T) => R) => CollectionFindCursor<R, TRaw>;
636-
// (undocumented)
637630
project: <RRaw extends SomeDoc = Partial<TRaw>>(projection: Projection) => CollectionFindCursor<RRaw, RRaw>;
638631
}
639632

@@ -1651,66 +1644,70 @@ export type Filter = Record<string, any>;
16511644
export abstract class FindAndRerankCursor<T, TRaw extends SomeDoc = SomeDoc> extends AbstractCursor<T, RerankedResult<TRaw>> {
16521645
// @internal
16531646
[$CustomInspect](): string;
1647+
// Warning: (ae-forgotten-export) The symbol "SerDes" needs to be exported by the entry point index.d.ts
1648+
// Warning: (ae-forgotten-export) The symbol "SerializedFilter" needs to be exported by the entry point index.d.ts
1649+
//
16541650
// @internal
1655-
constructor(parent: Table<SomeRow> | Collection, serdes: SerDes, filter: SerializedFilter, options?: GenericFindAndRerankOptions, mapping?: (doc: TRaw) => T);
1651+
constructor(parent: Table<SomeRow> | Collection, serdes: SerDes, filter: SerializedFilter, options?: GenericFindAndRerankOptions, mapping?: (doc: TRaw) => T, initialPage?: FindAndRerankPage<RerankedResult<TRaw>>);
16561652
clone(): this;
1653+
// (undocumented)
1654+
_currentPage?: FindAndRerankPage<RerankedResult<TRaw>>;
16571655
abstract get dataSource(): Table<SomeRow> | Collection;
1658-
filter(filter: Filter): this;
1659-
// Warning: (ae-forgotten-export) The symbol "SerializedFilter" needs to be exported by the entry point index.d.ts
1660-
//
1656+
fetchNextPage(): Promise<FindAndRerankPage<T>>;
16611657
// @internal (undocumented)
1662-
readonly _filter: SerializedFilter;
1658+
protected _fetchNextPage(extra: Record<string, unknown>, tm: TimeoutManager | undefined): Promise<[FindAndRerankPage<RerankedResult<TRaw>>, boolean]>;
1659+
filter(filter: Filter): this;
16631660
getSortVector(): Promise<DataAPIVector | null>;
16641661
hybridLimits(hybridLimits: number | Record<string, number>): this;
16651662
includeScores(includeScores?: boolean): this;
16661663
includeSortVector(includeSortVector?: boolean): this;
1664+
initialPageState(initialPageState?: string): this;
1665+
// Warning: (ae-forgotten-export) The symbol "FLCInternal" needs to be exported by the entry point index.d.ts
1666+
//
1667+
// @internal (undocumented)
1668+
readonly _internal: FLCInternal<RerankedResult<TRaw>, FindAndRerankPage<RerankedResult<TRaw>>, GenericFindAndRerankOptions>;
16671669
limit(limit: number): this;
16681670
map<R>(map: (doc: T) => R): FindAndRerankCursor<R, TRaw>;
1669-
// @internal (undocumented)
1670-
protected _nextPage(extra: Record<string, unknown>, tm: TimeoutManager | undefined): Promise<RerankedResult<TRaw>[]>;
1671-
// @internal (undocumented)
1672-
readonly _options: GenericFindAndRerankOptions;
1673-
// @internal (undocumented)
1674-
readonly _parent: Table<SomeRow> | Collection;
16751671
project<RRaw extends SomeDoc = Partial<TRaw>>(projection: Projection): FindAndRerankCursor<RerankedResult<RRaw>, RRaw>;
16761672
rerankOn(rerankOn: string): this;
16771673
rerankQuery(rerankQuery: string): this;
1678-
// Warning: (ae-forgotten-export) The symbol "SerDes" needs to be exported by the entry point index.d.ts
1679-
//
1680-
// @internal (undocumented)
1681-
readonly _serdes: SerDes;
16821674
sort(sort: HybridSort): this;
16831675
// @internal (undocumented)
16841676
protected _tm(): Timeouts;
16851677
}
16861678

1679+
// @public
1680+
export interface FindAndRerankPage<T> {
1681+
nextPageState: string | null;
1682+
result: T[];
1683+
sortVector?: DataAPIVector;
1684+
}
1685+
16871686
// @public
16881687
export abstract class FindCursor<T, TRaw extends SomeDoc = SomeDoc> extends AbstractCursor<T, TRaw> {
16891688
// @internal
16901689
[$CustomInspect](): string;
16911690
// @internal
1692-
constructor(parent: Table<SomeRow> | Collection, serdes: SerDes, filter: SerializedFilter, options?: GenericFindOptions, mapping?: (doc: TRaw) => T);
1691+
constructor(parent: Table<SomeRow> | Collection, serdes: SerDes, filter: SerializedFilter, options?: GenericFindOptions, mapping?: (doc: TRaw) => T, initialPage?: FindPage<TRaw>);
16931692
clone(): this;
1693+
// @internal (undocumented)
1694+
_currentPage?: FindPage<TRaw>;
16941695
abstract get dataSource(): Table<SomeRow> | Collection;
1695-
filter(filter: Filter): this;
1696+
fetchNextPage(): Promise<FindPage<T>>;
16961697
// @internal (undocumented)
1697-
readonly _filter: SerializedFilter;
1698+
protected _fetchNextPage(extra: Record<string, unknown>, tm: TimeoutManager | undefined): Promise<[FindPage<TRaw>, boolean]>;
1699+
filter(filter?: Filter): this;
16981700
getSortVector(): Promise<DataAPIVector | null>;
16991701
includeSimilarity(includeSimilarity?: boolean): FindCursor<WithSim<TRaw>, WithSim<TRaw>>;
17001702
includeSortVector(includeSortVector?: boolean): this;
1701-
limit(limit: number): this;
1702-
map<R>(map: (doc: T) => R): FindCursor<R, TRaw>;
1703-
// @internal (undocumented)
1704-
protected _nextPage(extra: Record<string, unknown>, tm: TimeoutManager | undefined): Promise<TRaw[]>;
1703+
initialPageState(initialPageState?: string): this;
17051704
// @internal (undocumented)
1706-
readonly _options: GenericFindOptions;
1707-
// @internal (undocumented)
1708-
readonly _parent: Table<SomeRow> | Collection;
1705+
readonly _internal: FLCInternal<TRaw, FindPage<TRaw>, GenericFindOptions>;
1706+
limit(limit?: number): this;
1707+
map<R>(map: (doc: T) => R): FindCursor<R, TRaw>;
17091708
project<RRaw extends SomeDoc = Partial<TRaw>>(projection: Projection): FindCursor<RRaw, RRaw>;
1710-
// @internal (undocumented)
1711-
readonly _serdes: SerDes;
1712-
skip(skip: number): this;
1713-
sort(sort: Sort): this;
1709+
skip(skip?: number): this;
1710+
sort(sort?: Sort): this;
17141711
// @internal (undocumented)
17151712
protected _tm(): Timeouts;
17161713
}
@@ -1720,6 +1717,13 @@ export interface FindEmbeddingProvidersResult {
17201717
embeddingProviders: Record<string, EmbeddingProviderInfo>;
17211718
}
17221719

1720+
// @public
1721+
export interface FindPage<T> {
1722+
nextPageState: string | null;
1723+
result: T[];
1724+
sortVector?: DataAPIVector;
1725+
}
1726+
17231727
// @public
17241728
export interface FindRerankingProvidersResult {
17251729
rerankingProviders: Record<string, any>;
@@ -1781,17 +1785,12 @@ export type GenericEstimatedCountOptions = WithTimeout<'generalMethodTimeoutMs'>
17811785

17821786
// @public
17831787
export interface GenericFindAndRerankOptions extends WithTimeout<'generalMethodTimeoutMs'> {
1784-
// (undocumented)
17851788
hybridLimits?: number | Record<string, number>;
1786-
// (undocumented)
17871789
includeScores?: boolean;
1788-
// (undocumented)
17891790
includeSortVector?: boolean;
17901791
limit?: number;
17911792
projection?: Projection;
1792-
// (undocumented)
17931793
rerankOn?: string;
1794-
// (undocumented)
17951794
rerankQuery?: string;
17961795
sort?: HybridSort;
17971796
}
@@ -1845,6 +1844,7 @@ export interface GenericFindOneOptions extends WithTimeout<'generalMethodTimeout
18451844
export interface GenericFindOptions extends WithTimeout<'generalMethodTimeoutMs'> {
18461845
includeSimilarity?: boolean;
18471846
includeSortVector?: boolean;
1847+
initialPageState?: string | null;
18481848
limit?: number;
18491849
projection?: Projection;
18501850
skip?: number;
@@ -1971,17 +1971,16 @@ export type HttpOptions = FetchH2HttpClientOptions | FetchHttpClientOptions | Cu
19711971
};
19721972

19731973
// @public (undocumented)
1974-
export type HybridSort = Record<string, SortDirection | string | number[] | DataAPIVector | HybridSortObject> & {
1974+
export interface HybridSort {
1975+
// (undocumented)
19751976
$hybrid: string | HybridSortObject;
1976-
};
1977+
}
19771978

19781979
// @public (undocumented)
19791980
export interface HybridSortObject {
19801981
// (undocumented)
19811982
$lexical?: string;
19821983
// (undocumented)
1983-
$vector?: number[] | DataAPIVector;
1984-
// (undocumented)
19851984
$vectorize?: string;
19861985
// (undocumented)
19871986
[col: string]: string | number[] | DataAPIVector | undefined;
@@ -2049,7 +2048,7 @@ export interface LexicalDoc {
20492048
export const LIB_NAME = "astra-db-ts";
20502049

20512050
// @public
2052-
export const LIB_VERSION = "2.0.0";
2051+
export const LIB_VERSION = "2.0.1";
20532052

20542053
// @public
20552054
export interface ListAstraDatabasesOptions extends WithTimeout<'databaseAdminTimeoutMs'> {
@@ -2582,11 +2581,8 @@ export type TableFindAndRerankOptions = GenericFindAndRerankOptions;
25822581
export class TableFindCursor<T, TRaw extends SomeRow = SomeRow> extends FindCursor<T, TRaw> {
25832582
get dataSource(): Table<SomeRow>;
25842583
filter(filter: TableFilter<TRaw>): this;
2585-
// (undocumented)
25862584
includeSimilarity: (includeSimilarity?: boolean) => TableFindCursor<WithSim<TRaw>, WithSim<TRaw>>;
2587-
// (undocumented)
25882585
map: <R>(map: (doc: T) => R) => TableFindCursor<R, TRaw>;
2589-
// (undocumented)
25902586
project: <RRaw extends SomeRow = Partial<TRaw>>(projection: Projection) => TableFindCursor<RRaw, RRaw>;
25912587
}
25922588

examples/astra-db-ts.tgz

5.36 KB
Binary file not shown.

examples/browser/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cloudflare-workers/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/customize-http/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/logging/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nextjs/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)