couchbase
Version:
The official Couchbase Node.js Client Library.
401 lines (400 loc) • 16.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScopeEventingFunctionManager = void 0;
const utilities_1 = require("./utilities");
const eventingfunctionmanager_1 = require("./eventingfunctionmanager");
const observability_1 = require("./observability");
const observabilityhandler_1 = require("./observabilityhandler");
const observabilitytypes_1 = require("./observabilitytypes");
/**
* ScopeEventingFunctionManager provides an interface for managing the
* eventing functions on the scope.
* Uncommitted: This API is subject to change in the future.
*
* @category Management
*/
class ScopeEventingFunctionManager {
/**
* @internal
*/
constructor(cluster, bucketName, scopeName) {
this._cluster = cluster;
this._bucketName = bucketName;
this._scopeName = scopeName;
}
/**
* @internal
*/
get observabilityInstruments() {
return this._cluster.observabilityInstruments;
}
/**
* Creates or updates an eventing function.
*
* @param functionDefinition The description of the eventing function to upsert.
* @param options Optional parameters for this operation.
* @param callback A node-style callback to be invoked after execution.
*/
async upsertFunction(functionDefinition, options, callback) {
if (options instanceof Function) {
callback = arguments[1];
options = undefined;
}
if (!options) {
options = {};
}
const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.EventingFunctionMgmtOp.EventingUpsertFunction, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
obsReqHandler.setRequestHttpAttributes({
bucketName: this._bucketName,
scopeName: this._scopeName,
});
try {
const timeout = options.timeout || this._cluster.managementTimeout;
return utilities_1.PromiseHelper.wrapAsync(async () => {
const [err, _] = await (0, observability_1.wrapObservableBindingCall)(this._cluster.conn.managementEventingUpsertFunction.bind(this._cluster.conn), {
function: eventingfunctionmanager_1.EventingFunction._toCppData(functionDefinition),
bucket_name: this._bucketName,
scope_name: this._scopeName,
timeout: timeout,
}, obsReqHandler);
if (err) {
obsReqHandler.endWithError(err);
throw err;
}
obsReqHandler.end();
}, callback);
}
catch (err) {
obsReqHandler.endWithError(err);
throw err;
}
}
/**
* Deletes an eventing function.
*
* @param name The name of the eventing function to delete.
* @param options Optional parameters for this operation.
* @param callback A node-style callback to be invoked after execution.
*/
async dropFunction(name, options, callback) {
if (options instanceof Function) {
callback = arguments[1];
options = undefined;
}
if (!options) {
options = {};
}
const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.EventingFunctionMgmtOp.EventingDropFunction, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
obsReqHandler.setRequestHttpAttributes({
bucketName: this._bucketName,
scopeName: this._scopeName,
});
try {
const timeout = options.timeout || this._cluster.managementTimeout;
return utilities_1.PromiseHelper.wrapAsync(async () => {
const [err, _] = await (0, observability_1.wrapObservableBindingCall)(this._cluster.conn.managementEventingDropFunction.bind(this._cluster.conn), {
name: name,
bucket_name: this._bucketName,
scope_name: this._scopeName,
timeout: timeout,
}, obsReqHandler);
if (err) {
obsReqHandler.endWithError(err);
throw err;
}
obsReqHandler.end();
}, callback);
}
catch (err) {
obsReqHandler.endWithError(err);
throw err;
}
}
/**
* Fetches all eventing functions.
*
* @param options Optional parameters for this operation.
* @param callback A node-style callback to be invoked after execution.
*/
async getAllFunctions(options, callback) {
if (options instanceof Function) {
callback = arguments[0];
options = undefined;
}
if (!options) {
options = {};
}
const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.EventingFunctionMgmtOp.EventingGetAllFunctions, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
obsReqHandler.setRequestHttpAttributes({
bucketName: this._bucketName,
scopeName: this._scopeName,
});
try {
const timeout = options.timeout || this._cluster.managementTimeout;
return utilities_1.PromiseHelper.wrapAsync(async () => {
const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._cluster.conn.managementEventingGetAllFunctions.bind(this._cluster.conn), {
bucket_name: this._bucketName,
scope_name: this._scopeName,
timeout: timeout,
}, obsReqHandler);
if (err) {
obsReqHandler.endWithError(err);
throw err;
}
obsReqHandler.end();
return resp.functions.map((functionData) => eventingfunctionmanager_1.EventingFunction._fromCppData(functionData));
}, callback);
}
catch (err) {
obsReqHandler.endWithError(err);
throw err;
}
}
/**
* Fetches a specific eventing function.
*
* @param name The name of the eventing function to fetch.
* @param options Optional parameters for this operation.
* @param callback A node-style callback to be invoked after execution.
*/
async getFunction(name, options, callback) {
if (options instanceof Function) {
callback = arguments[1];
options = undefined;
}
if (!options) {
options = {};
}
const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.EventingFunctionMgmtOp.EventingGetFunction, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
obsReqHandler.setRequestHttpAttributes({
bucketName: this._bucketName,
scopeName: this._scopeName,
});
try {
const timeout = options.timeout || this._cluster.managementTimeout;
return utilities_1.PromiseHelper.wrapAsync(async () => {
const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._cluster.conn.managementEventingGetFunction.bind(this._cluster.conn), {
name: name,
bucket_name: this._bucketName,
scope_name: this._scopeName,
timeout: timeout,
}, obsReqHandler);
if (err) {
obsReqHandler.endWithError(err);
throw err;
}
obsReqHandler.end();
return eventingfunctionmanager_1.EventingFunction._fromCppData(resp.function);
}, callback);
}
catch (err) {
obsReqHandler.endWithError(err);
throw err;
}
}
/**
* Deploys an eventing function.
*
* @param name The name of the eventing function to deploy.
* @param options Optional parameters for this operation.
* @param callback A node-style callback to be invoked after execution.
*/
async deployFunction(name, options, callback) {
if (options instanceof Function) {
callback = arguments[1];
options = undefined;
}
if (!options) {
options = {};
}
const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.EventingFunctionMgmtOp.EventingDeployFunction, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
obsReqHandler.setRequestHttpAttributes({
bucketName: this._bucketName,
scopeName: this._scopeName,
});
try {
const timeout = options.timeout || this._cluster.managementTimeout;
return utilities_1.PromiseHelper.wrapAsync(async () => {
const [err, _] = await (0, observability_1.wrapObservableBindingCall)(this._cluster.conn.managementEventingDeployFunction.bind(this._cluster.conn), {
name: name,
bucket_name: this._bucketName,
scope_name: this._scopeName,
timeout: timeout,
}, obsReqHandler);
if (err) {
obsReqHandler.endWithError(err);
throw err;
}
obsReqHandler.end();
}, callback);
}
catch (err) {
obsReqHandler.endWithError(err);
throw err;
}
}
/**
* Undeploys an eventing function.
*
* @param name The name of the eventing function to undeploy.
* @param options Optional parameters for this operation.
* @param callback A node-style callback to be invoked after execution.
*/
async undeployFunction(name, options, callback) {
if (options instanceof Function) {
callback = arguments[1];
options = undefined;
}
if (!options) {
options = {};
}
const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.EventingFunctionMgmtOp.EventingUndeployFunction, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
obsReqHandler.setRequestHttpAttributes({
bucketName: this._bucketName,
scopeName: this._scopeName,
});
try {
const timeout = options.timeout || this._cluster.managementTimeout;
return utilities_1.PromiseHelper.wrapAsync(async () => {
const [err, _] = await (0, observability_1.wrapObservableBindingCall)(this._cluster.conn.managementEventingUndeployFunction.bind(this._cluster.conn), {
name: name,
bucket_name: this._bucketName,
scope_name: this._scopeName,
timeout: timeout,
}, obsReqHandler);
if (err) {
obsReqHandler.endWithError(err);
throw err;
}
obsReqHandler.end();
}, callback);
}
catch (err) {
obsReqHandler.endWithError(err);
throw err;
}
}
/**
* Pauses an eventing function.
*
* @param name The name of the eventing function to pause.
* @param options Optional parameters for this operation.
* @param callback A node-style callback to be invoked after execution.
*/
async pauseFunction(name, options, callback) {
if (options instanceof Function) {
callback = arguments[1];
options = undefined;
}
if (!options) {
options = {};
}
const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.EventingFunctionMgmtOp.EventingPauseFunction, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
obsReqHandler.setRequestHttpAttributes({
bucketName: this._bucketName,
scopeName: this._scopeName,
});
try {
const timeout = options.timeout || this._cluster.managementTimeout;
return utilities_1.PromiseHelper.wrapAsync(async () => {
const [err, _] = await (0, observability_1.wrapObservableBindingCall)(this._cluster.conn.managementEventingPauseFunction.bind(this._cluster.conn), {
name: name,
bucket_name: this._bucketName,
scope_name: this._scopeName,
timeout: timeout,
}, obsReqHandler);
if (err) {
obsReqHandler.endWithError(err);
throw err;
}
obsReqHandler.end();
}, callback);
}
catch (err) {
obsReqHandler.endWithError(err);
throw err;
}
}
/**
* Resumes an eventing function.
*
* @param name The name of the eventing function to resume.
* @param options Optional parameters for this operation.
* @param callback A node-style callback to be invoked after execution.
*/
async resumeFunction(name, options, callback) {
if (options instanceof Function) {
callback = arguments[1];
options = undefined;
}
if (!options) {
options = {};
}
const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.EventingFunctionMgmtOp.EventingResumeFunction, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
obsReqHandler.setRequestHttpAttributes({
bucketName: this._bucketName,
scopeName: this._scopeName,
});
try {
const timeout = options.timeout || this._cluster.managementTimeout;
return utilities_1.PromiseHelper.wrapAsync(async () => {
const [err, _] = await (0, observability_1.wrapObservableBindingCall)(this._cluster.conn.managementEventingResumeFunction.bind(this._cluster.conn), {
name: name,
bucket_name: this._bucketName,
scope_name: this._scopeName,
timeout: timeout,
}, obsReqHandler);
if (err) {
obsReqHandler.endWithError(err);
throw err;
}
obsReqHandler.end();
}, callback);
}
catch (err) {
obsReqHandler.endWithError(err);
throw err;
}
}
/**
* Fetches the status of all eventing functions.
*
* @param options Optional parameters for this operation.
* @param callback A node-style callback to be invoked after execution.
*/
async functionsStatus(options, callback) {
if (options instanceof Function) {
callback = arguments[0];
options = undefined;
}
if (!options) {
options = {};
}
const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.EventingFunctionMgmtOp.EventingGetStatus, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
obsReqHandler.setRequestHttpAttributes({
bucketName: this._bucketName,
scopeName: this._scopeName,
});
try {
const timeout = options.timeout || this._cluster.managementTimeout;
return utilities_1.PromiseHelper.wrapAsync(async () => {
const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._cluster.conn.managementEventingGetStatus.bind(this._cluster.conn), {
bucket_name: this._bucketName,
scope_name: this._scopeName,
timeout: timeout,
}, obsReqHandler);
if (err) {
obsReqHandler.endWithError(err);
throw err;
}
obsReqHandler.end();
return eventingfunctionmanager_1.EventingState._fromCppData(resp.status);
}, callback);
}
catch (err) {
obsReqHandler.endWithError(err);
throw err;
}
}
}
exports.ScopeEventingFunctionManager = ScopeEventingFunctionManager;