@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
118 lines (117 loc) • 4.06 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 Offer_exports = {};
__export(Offer_exports, {
Offer: () => Offer
});
module.exports = __toCommonJS(Offer_exports);
var import_common = require("../../common/index.js");
var import_diagnostics = require("../../utils/diagnostics.js");
var import_OfferResponse = require("./OfferResponse.js");
class Offer {
/**
* @hidden
* @param client - The parent {@link CosmosClient} for the Database Account.
* @param id - The id of the given {@link Offer}.
*/
constructor(client, id, clientContext) {
this.client = client;
this.id = id;
this.clientContext = clientContext;
}
/**
* Returns a reference URL to the resource. Used for linking in Permissions.
*/
get url() {
return `/${import_common.Constants.Path.OffersPathSegment}/${this.id}`;
}
/**
* Read the {@link OfferDefinition} for the given {@link Offer}.
* @example
* ```ts snippet:OfferRead
* import { CosmosClient } from "@azure/cosmos";
*
* const endpoint = "https://your-account.documents.azure.com";
* const key = "<database account masterkey>";
* const client = new CosmosClient({ endpoint, key });
*
* const { resource: offer } = await client.offer("<offer-id>").read();
* ```
*/
async read(options) {
return (0, import_diagnostics.withDiagnostics)(async (diagnosticNode) => {
const response = await this.clientContext.read({
path: this.url,
resourceType: import_common.ResourceType.offer,
resourceId: this.id,
options,
diagnosticNode
});
return new import_OfferResponse.OfferResponse(
response.result,
response.headers,
response.code,
(0, import_diagnostics.getEmptyCosmosDiagnostics)(),
this
);
}, this.clientContext);
}
/**
* Replace the given {@link Offer} with the specified {@link OfferDefinition}.
* @param body - The specified {@link OfferDefinition}
* @example replace offer with a new offer definition with updated throughput
* ```ts snippet:OfferReplace
* import { CosmosClient } from "@azure/cosmos";
*
* const endpoint = "https://your-account.documents.azure.com";
* const key = "<database account masterkey>";
* const client = new CosmosClient({ endpoint, key });
* const { resource: offer } = await client.offer("<offer-id>").read();
* // @ts-preservewhitespace
* offer.content.offerThroughput = 1000;
* await client.offer("<offer-id>").replace(offer);
* ```
*/
async replace(body, options) {
return (0, import_diagnostics.withDiagnostics)(async (diagnosticNode) => {
const err = {};
if (!(0, import_common.isResourceValid)(body, err)) {
throw err;
}
const response = await this.clientContext.replace({
body,
path: this.url,
resourceType: import_common.ResourceType.offer,
resourceId: this.id,
options,
diagnosticNode
});
return new import_OfferResponse.OfferResponse(
response.result,
response.headers,
response.code,
(0, import_diagnostics.getEmptyCosmosDiagnostics)(),
this
);
}, this.clientContext);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Offer
});