@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
84 lines (83 loc) • 3.37 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var OrderByEndpointComponent_exports = {};
__export(OrderByEndpointComponent_exports, {
OrderByEndpointComponent: () => OrderByEndpointComponent
});
module.exports = __toCommonJS(OrderByEndpointComponent_exports);
var import_parallelQueryResult = require("../parallelQueryResult.js");
class OrderByEndpointComponent {
/**
* Represents an endpoint in handling an order by query. For each processed orderby
* result it returns 'payload' item of the result
*
* @param executionContext - Underlying Execution Context
* @param emitRawOrderByPayload - Whether to emit raw order by payload
* @hidden
*/
constructor(executionContext, emitRawOrderByPayload = false) {
this.executionContext = executionContext;
this.emitRawOrderByPayload = emitRawOrderByPayload;
}
/**
* Determine if there are still remaining resources to processs.
* @returns true if there is other elements to process in the OrderByEndpointComponent.
*/
hasMoreResults() {
return this.executionContext.hasMoreResults();
}
async fetchMore(diagnosticNode) {
const buffer = [];
const orderByItemsArray = [];
const response = await this.executionContext.fetchMore(diagnosticNode);
if (!response || !response.result || !Array.isArray(response.result.buffer) || response.result.buffer.length === 0) {
const originalResult = response?.result;
const result2 = (0, import_parallelQueryResult.createParallelQueryResult)(
[],
originalResult?.partitionKeyRangeMap || /* @__PURE__ */ new Map(),
originalResult?.updatedContinuationRanges || {},
[]
);
return { result: result2, headers: response?.headers };
}
const parallelResult = response.result;
const rawBuffer = parallelResult.buffer;
const partitionKeyRangeMap = parallelResult.partitionKeyRangeMap;
const updatedContinuationRanges = parallelResult.updatedContinuationRanges;
for (let i = 0; i < rawBuffer.length; i++) {
const item = rawBuffer[i];
if (this.emitRawOrderByPayload) {
buffer.push(item);
} else {
buffer.push(item.payload);
}
orderByItemsArray.push({ orderByItems: item.orderByItems, _rid: item._rid });
}
const result = (0, import_parallelQueryResult.createParallelQueryResult)(
buffer,
partitionKeyRangeMap,
updatedContinuationRanges,
orderByItemsArray
);
return { result, headers: response.headers };
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
OrderByEndpointComponent
});