UNPKG

ottoman

Version:
44 lines 1.98 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.store = void 0; /** * Stores a Document: Updates a document if CAS value is defined, otherwise it inserts a new document. * CAS is a value representing the current state of an item/document in the Couchbase Server. Each modification of the document changes it's CAS value. */ const store = (key, data, options, collection) => __awaiter(void 0, void 0, void 0, function* () { let storePromise; const { transactionContext } = options || {}; if (options.maxExpiry !== undefined) { options.expiry = options.maxExpiry; delete options.maxExpiry; } if (options.cas) { if (transactionContext) { const doc = yield transactionContext.get(collection, key); storePromise = transactionContext.replace(doc, data); } else { storePromise = collection.replace(key, data, options); } } else { if (options.transactionContext) { storePromise = options.transactionContext.insert(collection, key, data); } else { storePromise = collection.insert(key, data, options); } } return storePromise; }); exports.store = store; //# sourceMappingURL=store.js.map