UNPKG

@datastax/astra-db-ts

Version:
78 lines (77 loc) 2.88 kB
// Copyright Datastax, Inc // SPDX-License-Identifier: Apache-2.0 import { AbstractCursor } from '../../documents/cursors/abstract-cursor.js'; import { $CustomInspect } from '../../lib/constants.js'; import { FLCInternal } from '../../documents/cursors/flc-internal.js'; export class FindCursor extends AbstractCursor { constructor(parent, serdes, filter, options, mapping, initialPage) { super(options ?? {}, mapping); Object.defineProperty(this, "_internal", { enumerable: true, configurable: true, writable: true, value: void 0 }); this._internal = new FLCInternal(this, parent, serdes, filter, options); this._currentPage = initialPage ?? this._internal.mkInitialPage(options?.initialPageState); } [$CustomInspect]() { return `${this.constructor.name}(source="${this.dataSource.keyspace}.${this.dataSource.name}",state="${this._state}",consumed=${this.consumed()},buffered=${this.buffered()})`; } filter(filter) { return this._internal.withFilter(filter); } sort(sort) { return this._internal.withSort(sort); } limit(limit) { return this._internal.withOption('limit', limit || undefined); } skip(skip) { return this._internal.withOption('skip', skip); } includeSortVector(includeSortVector) { return this._internal.withOption('includeSortVector', includeSortVector ?? true); } project(projection) { return this._internal.withPreMapOption('projection', projection); } includeSimilarity(includeSimilarity) { return this._internal.withPreMapOption('includeSimilarity', includeSimilarity ?? true); } initialPageState(initialPageState) { return this._internal.withInitialPageState(initialPageState); } map(map) { return this._internal.withMap(map); } async getSortVector() { return this._internal.getSortVector(); } clone() { return this._internal.freshClone(); } async fetchNextPage() { return this._internal.fetchNextPageMapped(FindCursor.InternalNextPageOptions); } async _fetchNextPage(extra, tm) { return this._internal.fetchNextPageRaw(extra, tm, FindCursor.InternalNextPageOptions); } _tm() { return this._internal._httpClient.tm; } } Object.defineProperty(FindCursor, "InternalNextPageOptions", { enumerable: true, configurable: true, writable: true, value: { commandName: 'find', commandOptions: ['limit', 'skip', 'includeSortVector', 'includeSimilarity'], mapPage: (page) => ({ sortVector: page.sortVector, nextPageState: page.nextPageState, result: page.result, }), } });