@datastax/astra-db-ts
Version:
Data API TypeScript client
82 lines (81 loc) • 3.04 kB
JavaScript
"use strict";
// Copyright Datastax, Inc
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.FindCursor = void 0;
const abstract_cursor_js_1 = require("../../documents/cursors/abstract-cursor.js");
const constants_js_1 = require("../../lib/constants.js");
const flc_internal_js_1 = require("../../documents/cursors/flc-internal.js");
class FindCursor extends abstract_cursor_js_1.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 flc_internal_js_1.FLCInternal(this, parent, serdes, filter, options);
this._currentPage = initialPage;
}
[constants_js_1.$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', structuredClone(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;
}
}
exports.FindCursor = FindCursor;
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,
}),
}
});