@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
134 lines (133 loc) • 5.49 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 EncryptionItemQueryIterator_exports = {};
__export(EncryptionItemQueryIterator_exports, {
EncryptionItemQueryIterator: () => EncryptionItemQueryIterator
});
module.exports = __toCommonJS(EncryptionItemQueryIterator_exports);
var import_constants = require("../common/constants.js");
var import_DiagnosticNodeInternal = require("../diagnostics/DiagnosticNodeInternal.js");
var import_queryIterator = require("../queryIterator.js");
var import_diagnostics = require("../utils/diagnostics.js");
class EncryptionItemQueryIterator extends import_queryIterator.QueryIterator {
container;
encryptionClientContext;
encryptionOptions;
constructor(clientContext, query, options, fetchFunctions, container) {
super(clientContext, query, options, fetchFunctions, container.url, import_constants.ResourceType.item);
this.container = container;
this.encryptionClientContext = clientContext;
this.encryptionOptions = options;
}
/**
* Gets an async iterator that will yield results until completion.
*/
async *getAsyncIterator() {
let response;
const diagnosticNode = new import_DiagnosticNodeInternal.DiagnosticNodeInternal(
this.encryptionClientContext.diagnosticLevel,
import_DiagnosticNodeInternal.DiagnosticNodeType.CLIENT_REQUEST_NODE,
null
);
try {
response = yield* import_queryIterator.QueryIterator.prototype.getAsyncIteratorInternal.call(this, diagnosticNode);
} catch (error) {
await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);
}
if (response?.resources?.length > 0) {
let count = 0;
diagnosticNode.beginEncryptionDiagnostics(import_constants.Constants.Encryption.DiagnosticsDecryptOperation);
for (let resource of response.resources) {
const { body, propertiesDecryptedCount } = await this.container.encryptionProcessor.decrypt(resource);
resource = body;
count += propertiesDecryptedCount;
}
diagnosticNode.endEncryptionDiagnostics(
import_constants.Constants.Encryption.DiagnosticsDecryptOperation,
count
);
}
yield response;
}
/**
* Fetch all pages for the query and return a single FeedResponse.
*/
async fetchAll() {
return (0, import_diagnostics.withDiagnostics)(async (diagnosticNode) => {
let response;
try {
response = await import_queryIterator.QueryIterator.prototype.fetchAllInternal.call(this, diagnosticNode);
} catch (error) {
await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);
}
if (response?.resources?.length > 0) {
let count = 0;
diagnosticNode.beginEncryptionDiagnostics(import_constants.Constants.Encryption.DiagnosticsDecryptOperation);
for (let resource of response.resources) {
const { body, propertiesDecryptedCount } = await this.container.encryptionProcessor.decrypt(resource);
resource = body;
count += propertiesDecryptedCount;
}
diagnosticNode.endEncryptionDiagnostics(
import_constants.Constants.Encryption.DiagnosticsDecryptOperation,
count
);
}
return response;
}, this.encryptionClientContext);
}
/**
* Retrieve the next batch from the feed.
*/
async fetchNext() {
return (0, import_diagnostics.withDiagnostics)(async (diagnosticNode) => {
let response;
try {
response = await import_queryIterator.QueryIterator.prototype.fetchNextInternal.call(this, diagnosticNode);
} catch (error) {
await this.container.throwIfRequestNeedsARetryPostPolicyRefresh(error);
}
if (response?.resources?.length > 0) {
let count = 0;
diagnosticNode.beginEncryptionDiagnostics(import_constants.Constants.Encryption.DiagnosticsDecryptOperation);
for (let resource of response.resources) {
const { body, propertiesDecryptedCount } = await this.container.encryptionProcessor.decrypt(resource);
resource = body;
count += propertiesDecryptedCount;
}
diagnosticNode.endEncryptionDiagnostics(
import_constants.Constants.Encryption.DiagnosticsDecryptOperation,
count
);
}
return response;
}, this.encryptionClientContext);
}
/**
* @internal
*/
async init(diagnosticNode) {
await this.container.checkAndInitializeEncryption();
this.encryptionOptions.containerRid = this.container._rid;
await import_queryIterator.QueryIterator.prototype.init.call(this, diagnosticNode);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
EncryptionItemQueryIterator
});