UNPKG

@azure/cosmos

Version:
130 lines (129 loc) 4.86 kB
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 Conflict_exports = {}; __export(Conflict_exports, { Conflict: () => Conflict }); module.exports = __toCommonJS(Conflict_exports); var import_common = require("../../common/index.js"); var import_ConflictResponse = require("./ConflictResponse.js"); var import_extractPartitionKey = require("../../extractPartitionKey.js"); var import_ClientUtils = require("../ClientUtils.js"); var import_diagnostics = require("../../utils/diagnostics.js"); class Conflict { /** * @hidden * @param container - The parent {@link Container}. * @param id - The id of the given {@link Conflict}. */ constructor(container, id, clientContext, partitionKey) { this.container = container; this.id = id; this.clientContext = clientContext; this.partitionKey = partitionKey; this.partitionKey = partitionKey; } /** * Returns a reference URL to the resource. Used for linking in Permissions. */ get url() { return `/${this.container.url}/${import_common.Constants.Path.ConflictsPathSegment}/${this.id}`; } /** * Read the {@link ConflictDefinition} for the given {@link Conflict}. * @example * ```ts snippet:ConflictRead * 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 { database } = await client.databases.createIfNotExists({ id: "Test Database" }); * const container = database.container("Test Container"); * * const { resource: conflict } = await container.conflict("<conflict-id>").read(); * ``` */ async read(options) { return (0, import_diagnostics.withDiagnostics)(async (diagnosticNode) => { const path = (0, import_common.getPathFromLink)(this.url, import_common.ResourceType.conflicts); const id = (0, import_common.getIdFromLink)(this.url); const response = await this.clientContext.read({ path, resourceType: import_common.ResourceType.user, resourceId: id, options, diagnosticNode }); return new import_ConflictResponse.ConflictResponse( response.result, response.headers, response.code, this, (0, import_diagnostics.getEmptyCosmosDiagnostics)() ); }, this.clientContext); } /** * Delete the given {@link ConflictDefinition}. * @example * ```ts snippet:ConflictDelete * 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 { database } = await client.databases.createIfNotExists({ id: "Test Database" }); * const container = database.container("Test Container"); * * await container.conflict("<conflict-id>").delete(); * ``` */ async delete(options) { return (0, import_diagnostics.withDiagnostics)(async (diagnosticNode) => { if (this.partitionKey === void 0) { const partitionKeyDefinition = await (0, import_ClientUtils.readPartitionKeyDefinition)( diagnosticNode, this.container ); this.partitionKey = (0, import_extractPartitionKey.undefinedPartitionKey)(partitionKeyDefinition); } const path = (0, import_common.getPathFromLink)(this.url); const id = (0, import_common.getIdFromLink)(this.url); const response = await this.clientContext.delete({ path, resourceType: import_common.ResourceType.conflicts, resourceId: id, options, partitionKey: this.partitionKey, diagnosticNode }); return new import_ConflictResponse.ConflictResponse( response.result, response.headers, response.code, this, (0, import_diagnostics.getEmptyCosmosDiagnostics)() ); }, this.clientContext); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Conflict });