UNPKG

35.7 kBJavaScriptView Raw
1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 var desc = Object.getOwnPropertyDescriptor(m, k);
5 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6 desc = { enumerable: true, get: function() { return m[k]; } };
7 }
8 Object.defineProperty(o, k2, desc);
9}) : (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 o[k2] = m[k];
12}));
13var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14 Object.defineProperty(o, "default", { enumerable: true, value: v });
15}) : function(o, v) {
16 o["default"] = v;
17});
18var __importStar = (this && this.__importStar) || function (mod) {
19 if (mod && mod.__esModule) return mod;
20 var result = {};
21 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22 __setModuleDefault(result, mod);
23 return result;
24};
25Object.defineProperty(exports, "__esModule", { value: true });
26exports.EventingFunctionManager = exports.EventingState = exports.EventingFunctionState = exports.EventingFunction = exports.EventingFunctionSettings = exports.EventingFunctionConstantBinding = exports.EventingFunctionUrlBinding = exports.EventingFunctionUrlAuthBearer = exports.EventingFunctionUrlAuthDigest = exports.EventingFunctionUrlAuthBasic = exports.EventingFunctionBucketBinding = exports.EventingFunctionKeyspace = exports.EventingFunctionUrlAuthMethod = exports.EventingFunctionBucketAccess = exports.EventingFunctionLogLevel = exports.EventingFunctionLanguageCompatibility = exports.EventingFunctionStatus = exports.EventingFunctionProcessingStatus = exports.EventingFunctionDeploymentStatus = exports.EventingFunctionDcpBoundary = void 0;
27const utilities_1 = require("./utilities");
28const bindingutilities_1 = require("./bindingutilities");
29const errs = __importStar(require("./errors"));
30/**
31 * Represents the various dcp boundary options for eventing functions.
32 *
33 * @category Management
34 */
35var EventingFunctionDcpBoundary;
36(function (EventingFunctionDcpBoundary) {
37 /**
38 * Indicates all documents should be processed by the function.
39 */
40 EventingFunctionDcpBoundary["Everything"] = "everything";
41 /**
42 * Indicates that only documents modified after a function is created
43 * should be processed by the function.
44 */
45 EventingFunctionDcpBoundary["FromNow"] = "from_now";
46})(EventingFunctionDcpBoundary || (exports.EventingFunctionDcpBoundary = EventingFunctionDcpBoundary = {}));
47/**
48 * Represents the various possible deployment statuses for an eventing function.
49 *
50 * @category Management
51 */
52var EventingFunctionDeploymentStatus;
53(function (EventingFunctionDeploymentStatus) {
54 /**
55 * Indicates that the function is deployed.
56 */
57 EventingFunctionDeploymentStatus["Deployed"] = "deployed";
58 /**
59 * Indicates that the function has not yet been deployed.
60 */
61 EventingFunctionDeploymentStatus["Undeployed"] = "undeployed";
62})(EventingFunctionDeploymentStatus || (exports.EventingFunctionDeploymentStatus = EventingFunctionDeploymentStatus = {}));
63/**
64 * Represents the various possible processing statuses for an eventing function.
65 *
66 * @category Management
67 */
68var EventingFunctionProcessingStatus;
69(function (EventingFunctionProcessingStatus) {
70 /**
71 * Indicates that the eventing function is currently running.
72 */
73 EventingFunctionProcessingStatus["Running"] = "running";
74 /**
75 * Indicates that the eventing function is currently paused.
76 */
77 EventingFunctionProcessingStatus["Paused"] = "paused";
78})(EventingFunctionProcessingStatus || (exports.EventingFunctionProcessingStatus = EventingFunctionProcessingStatus = {}));
79/**
80 * Represents the authentication method to use for a URL binding.
81 *
82 * @category Management
83 */
84var EventingFunctionStatus;
85(function (EventingFunctionStatus) {
86 /**
87 * Indicates that the eventing function is undeployed.
88 */
89 EventingFunctionStatus["Undeployed"] = "undeployed";
90 /**
91 * Indicates that the eventing function is deploying.
92 */
93 EventingFunctionStatus["Deploying"] = "deploying";
94 /**
95 * Indicates that the eventing function is deployed.
96 */
97 EventingFunctionStatus["Deployed"] = "deployed";
98 /**
99 * Indicates that the eventing function is undeploying.
100 */
101 EventingFunctionStatus["Undeploying"] = "undeploying";
102 /**
103 * Indicates that the eventing function is paused.
104 */
105 EventingFunctionStatus["Paused"] = "paused";
106 /**
107 * Indicates that the eventing function is pausing.
108 */
109 EventingFunctionStatus["Pausing"] = "pausing";
110})(EventingFunctionStatus || (exports.EventingFunctionStatus = EventingFunctionStatus = {}));
111/**
112 * Represents the language compatibility levels of an eventing function.
113 *
114 * @category Management
115 */
116var EventingFunctionLanguageCompatibility;
117(function (EventingFunctionLanguageCompatibility) {
118 /**
119 * Indicates that the function should run with compatibility with
120 * Couchbase Server 6.0.0.
121 */
122 EventingFunctionLanguageCompatibility["Version_6_0_0"] = "6.0.0";
123 /**
124 * Indicates that the function should run with compatibility with
125 * Couchbase Server 6.5.0.
126 */
127 EventingFunctionLanguageCompatibility["Version_6_5_0"] = "6.5.0";
128 /**
129 * Indicates that the function should run with compatibility with
130 * Couchbase Server 6.6.2.
131 */
132 EventingFunctionLanguageCompatibility["Version_6_6_2"] = "6.6.2";
133 /**
134 * Indicates that the function should run with compatibility with
135 * Couchbase Server 7.2.0.
136 */
137 EventingFunctionLanguageCompatibility["Version_7_2_0"] = "7.2.0";
138})(EventingFunctionLanguageCompatibility || (exports.EventingFunctionLanguageCompatibility = EventingFunctionLanguageCompatibility = {}));
139/**
140 * Represents the various log levels for an eventing function.
141 *
142 * @category Management
143 */
144var EventingFunctionLogLevel;
145(function (EventingFunctionLogLevel) {
146 /**
147 * Indicates to use INFO level logging.
148 */
149 EventingFunctionLogLevel["Info"] = "INFO";
150 /**
151 * Indicates to use ERROR level logging.
152 */
153 EventingFunctionLogLevel["Error"] = "ERROR";
154 /**
155 * Indicates to use WARNING level logging.
156 */
157 EventingFunctionLogLevel["Warning"] = "WARNING";
158 /**
159 * Indicates to use DEBUG level logging.
160 */
161 EventingFunctionLogLevel["Debug"] = "DEBUG";
162 /**
163 * Indicates to use TRACE level logging.
164 */
165 EventingFunctionLogLevel["Trace"] = "TRACE";
166})(EventingFunctionLogLevel || (exports.EventingFunctionLogLevel = EventingFunctionLogLevel = {}));
167/**
168 * Represents the various bucket access levels for an eventing function.
169 *
170 * @category Management
171 */
172var EventingFunctionBucketAccess;
173(function (EventingFunctionBucketAccess) {
174 /**
175 * Indicates that the function can only read the associated bucket.
176 */
177 EventingFunctionBucketAccess["ReadOnly"] = "r";
178 /**
179 * Indicates that the function can both read and write the associated bucket.
180 */
181 EventingFunctionBucketAccess["ReadWrite"] = "rw";
182})(EventingFunctionBucketAccess || (exports.EventingFunctionBucketAccess = EventingFunctionBucketAccess = {}));
183/**
184 * Represents the authentication method to use for a URL binding.
185 *
186 * @category Management
187 */
188var EventingFunctionUrlAuthMethod;
189(function (EventingFunctionUrlAuthMethod) {
190 /**
191 * Indicates that no authentication should be used.
192 */
193 EventingFunctionUrlAuthMethod["None"] = "no-auth";
194 /**
195 * Indicates that Basic should be used.
196 */
197 EventingFunctionUrlAuthMethod["Basic"] = "basic";
198 /**
199 * Indicates that Digest should be used.
200 */
201 EventingFunctionUrlAuthMethod["Digest"] = "digest";
202 /**
203 * Indicates that Bearer should be used.
204 */
205 EventingFunctionUrlAuthMethod["Bearer"] = "bearer";
206})(EventingFunctionUrlAuthMethod || (exports.EventingFunctionUrlAuthMethod = EventingFunctionUrlAuthMethod = {}));
207/**
208 * Specifies the bucket/scope/collection used by an eventing function.
209 *
210 * @category Management
211 */
212class EventingFunctionKeyspace {
213 constructor(v) {
214 this.bucket = v.bucket;
215 this.scope = v.scope;
216 this.collection = v.collection;
217 }
218}
219exports.EventingFunctionKeyspace = EventingFunctionKeyspace;
220/**
221 * Specifies a bucket binding for an eventing function.
222 *
223 * @category Management
224 */
225class EventingFunctionBucketBinding {
226 constructor(v) {
227 this.alias = v.alias;
228 this.name = v.name;
229 this.access = v.access;
230 }
231 /**
232 * @internal
233 */
234 static _fromCppData(data) {
235 return new EventingFunctionBucketBinding({
236 alias: data.alias,
237 name: new EventingFunctionKeyspace({
238 bucket: data.name.bucket,
239 scope: data.name.scope,
240 collection: data.name.collection,
241 }),
242 access: (0, bindingutilities_1.eventingBucketBindingAccessFromCpp)(data.access),
243 });
244 }
245 /**
246 * @internal
247 */
248 static _toCppData(data) {
249 return {
250 alias: data.alias,
251 name: {
252 bucket: data.name.bucket,
253 scope: data.name.scope,
254 collection: data.name.collection,
255 },
256 access: (0, bindingutilities_1.eventingBucketBindingAccessToCpp)(data.access),
257 };
258 }
259}
260exports.EventingFunctionBucketBinding = EventingFunctionBucketBinding;
261/**
262 * Specifies that Basic authentication should be used for the URL.
263 *
264 * @category Management
265 */
266class EventingFunctionUrlAuthBasic {
267 constructor(v) {
268 /**
269 * Sets the auth method to Basic.
270 */
271 this.method = EventingFunctionUrlAuthMethod.Basic;
272 this.username = v.username;
273 this.password = v.password;
274 }
275}
276exports.EventingFunctionUrlAuthBasic = EventingFunctionUrlAuthBasic;
277/**
278 * Specifies that Digest authentication should be used for the URL.
279 *
280 * @category Management
281 */
282class EventingFunctionUrlAuthDigest {
283 constructor(v) {
284 /**
285 * Sets the auth method to Digest.
286 */
287 this.method = EventingFunctionUrlAuthMethod.Digest;
288 this.username = v.username;
289 this.password = v.password;
290 }
291}
292exports.EventingFunctionUrlAuthDigest = EventingFunctionUrlAuthDigest;
293/**
294 * Specifies that Bearer authentication should be used for the URL.
295 *
296 * @category Management
297 */
298class EventingFunctionUrlAuthBearer {
299 constructor(v) {
300 /**
301 * Sets the auth method to Bearer.
302 */
303 this.method = EventingFunctionUrlAuthMethod.Bearer;
304 this.key = v.key;
305 }
306}
307exports.EventingFunctionUrlAuthBearer = EventingFunctionUrlAuthBearer;
308/**
309 * Specifies a url binding for an eventing function.
310 *
311 * @category Management
312 */
313class EventingFunctionUrlBinding {
314 constructor(v) {
315 this.hostname = v.hostname;
316 this.alias = v.alias;
317 this.auth = v.auth;
318 this.allowCookies = v.allowCookies;
319 this.validateSslCertificate = v.validateSslCertificate;
320 }
321 /**
322 * @internal
323 */
324 static _fromCppData(data) {
325 let authObj;
326 if (data.auth_name === 'function_url_no_auth') {
327 authObj = undefined;
328 }
329 else if (data.auth_name === 'function_url_auth_basic') {
330 authObj = new EventingFunctionUrlAuthBasic({
331 username: data.auth_value
332 .username,
333 password: data.auth_value
334 .password,
335 });
336 }
337 else if (data.auth_name === 'function_url_auth_digest') {
338 authObj = new EventingFunctionUrlAuthDigest({
339 username: data.auth_value.username,
340 password: data.auth_value.password,
341 });
342 }
343 else if (data.auth_name === 'function_url_auth_bearer') {
344 authObj = new EventingFunctionUrlAuthBearer({
345 key: data.auth_value
346 .key,
347 });
348 }
349 else {
350 throw new errs.InvalidArgumentError(new Error('Unrecognized EventingFunctionUrlBinding: ' + data.auth_name));
351 }
352 return {
353 hostname: data.hostname,
354 alias: data.alias,
355 allowCookies: data.allow_cookies,
356 validateSslCertificate: data.validate_ssl_certificate,
357 auth: authObj,
358 };
359 }
360 /**
361 * @internal
362 */
363 static _toCppData(data) {
364 let authObj;
365 let auth_name;
366 if (!data.auth || data.auth.method === EventingFunctionUrlAuthMethod.None) {
367 authObj = {};
368 auth_name = 'function_url_no_auth';
369 }
370 else if (data.auth.method === EventingFunctionUrlAuthMethod.Basic) {
371 authObj = {
372 username: data.auth.username,
373 password: data.auth.password,
374 };
375 auth_name = 'function_url_auth_basic';
376 }
377 else if (data.auth.method === EventingFunctionUrlAuthMethod.Digest) {
378 authObj = {
379 username: data.auth.username,
380 password: data.auth.password,
381 };
382 auth_name = 'function_url_auth_digest';
383 }
384 else if (data.auth.method === EventingFunctionUrlAuthMethod.Bearer) {
385 authObj = {
386 key: data.auth.key,
387 };
388 auth_name = 'function_url_auth_bearer';
389 }
390 else {
391 throw new errs.InvalidArgumentError(new Error('Unrecognized EventingFunctionUrlBinding'));
392 }
393 return {
394 alias: data.alias,
395 hostname: data.hostname,
396 allow_cookies: data.allowCookies,
397 validate_ssl_certificate: data.validateSslCertificate,
398 auth_name: auth_name,
399 auth_value: authObj,
400 };
401 }
402}
403exports.EventingFunctionUrlBinding = EventingFunctionUrlBinding;
404/**
405 * Specifies a constant binding for an eventing function.
406 *
407 * @category Management
408 */
409class EventingFunctionConstantBinding {
410 constructor(v) {
411 this.alias = v.alias;
412 this.literal = v.literal;
413 }
414 /**
415 * @internal
416 */
417 static _fromCppData(data) {
418 return new EventingFunctionConstantBinding({
419 alias: data.alias,
420 literal: data.literal,
421 });
422 }
423 /**
424 * @internal
425 */
426 static _toCppData(data) {
427 return {
428 alias: data.alias,
429 literal: data.literal,
430 };
431 }
432}
433exports.EventingFunctionConstantBinding = EventingFunctionConstantBinding;
434/**
435 * Specifies a number of options which can be used when updating or creating
436 * a eventing function.
437 *
438 * @category Management
439 */
440class EventingFunctionSettings {
441 constructor(v) {
442 this.cppWorkerThreadCount = v.cppWorkerThreadCount;
443 this.dcpStreamBoundary = v.dcpStreamBoundary;
444 this.description = v.description;
445 this.deploymentStatus = v.deploymentStatus;
446 this.processingStatus = v.processingStatus;
447 this.languageCompatibility = v.languageCompatibility;
448 this.logLevel = v.logLevel;
449 this.executionTimeout = v.executionTimeout;
450 this.lcbInstCapacity = v.lcbInstCapacity;
451 this.lcbRetryCount = v.lcbRetryCount;
452 this.lcbTimeout = v.lcbTimeout;
453 this.queryConsistency = v.queryConsistency;
454 this.numTimerPartitions = v.numTimerPartitions;
455 this.sockBatchSize = v.sockBatchSize;
456 this.tickDuration = v.tickDuration;
457 this.timerContextSize = v.timerContextSize;
458 this.userPrefix = v.userPrefix;
459 this.bucketCacheSize = v.bucketCacheSize;
460 this.bucketCacheAge = v.bucketCacheAge;
461 this.curlMaxAllowedRespSize = v.curlMaxAllowedRespSize;
462 this.queryPrepareAll = v.queryPrepareAll;
463 this.workerCount = v.workerCount;
464 this.handlerHeaders = v.handlerHeaders;
465 this.handlerFooters = v.handlerFooters;
466 this.enableAppLogRotation = v.enableAppLogRotation;
467 this.appLogDir = v.appLogDir;
468 this.appLogMaxSize = v.appLogMaxSize;
469 this.appLogMaxFiles = v.appLogMaxFiles;
470 this.checkpointInterval = v.checkpointInterval;
471 }
472 /**
473 * @internal
474 */
475 static _fromCppData(data) {
476 return new EventingFunctionSettings({
477 cppWorkerThreadCount: data.cpp_worker_count,
478 dcpStreamBoundary: (0, bindingutilities_1.eventingFunctionDcpBoundaryFromCpp)(data.dcp_stream_boundary),
479 description: data.description,
480 deploymentStatus: (0, bindingutilities_1.eventingFunctionDeploymentStatusFromCpp)(data.deployment_status),
481 processingStatus: (0, bindingutilities_1.eventingFunctionProcessingStatusFromCpp)(data.processing_status),
482 logLevel: (0, bindingutilities_1.eventingFunctionLogLevelFromCpp)(data.log_level),
483 languageCompatibility: (0, bindingutilities_1.eventingFunctionLanguageCompatibilityFromCpp)(data.language_compatibility),
484 executionTimeout: data.execution_timeout,
485 lcbInstCapacity: data.lcb_inst_capacity,
486 lcbRetryCount: data.lcb_retry_count,
487 lcbTimeout: data.lcb_timeout,
488 queryConsistency: (0, bindingutilities_1.queryScanConsistencyFromCpp)(data.query_consistency),
489 numTimerPartitions: data.num_timer_partitions,
490 sockBatchSize: data.sock_batch_size,
491 tickDuration: data.tick_duration,
492 timerContextSize: data.timer_context_size,
493 userPrefix: data.user_prefix,
494 bucketCacheSize: data.bucket_cache_size,
495 bucketCacheAge: data.bucket_cache_age,
496 curlMaxAllowedRespSize: data.curl_max_allowed_resp_size,
497 queryPrepareAll: data.query_prepare_all,
498 workerCount: data.worker_count,
499 handlerHeaders: data.handler_headers,
500 handlerFooters: data.handler_footers,
501 enableAppLogRotation: data.enable_app_log_rotation,
502 appLogDir: data.app_log_dir,
503 appLogMaxSize: data.app_log_max_size,
504 appLogMaxFiles: data.app_log_max_files,
505 checkpointInterval: data.checkpoint_interval,
506 });
507 }
508 /**
509 * @internal
510 */
511 static _toCppData(data) {
512 var _a, _b;
513 if (!data) {
514 return {
515 handler_headers: [],
516 handler_footers: [],
517 };
518 }
519 return {
520 cpp_worker_count: data.cppWorkerThreadCount,
521 dcp_stream_boundary: (0, bindingutilities_1.eventingFunctionDcpBoundaryToCpp)(data.dcpStreamBoundary),
522 description: data.description,
523 deployment_status: (0, bindingutilities_1.eventingFunctionDeploymentStatusToCpp)(data.deploymentStatus),
524 processing_status: (0, bindingutilities_1.eventingFunctionProcessingStatusToCpp)(data.processingStatus),
525 log_level: (0, bindingutilities_1.eventingFunctionLogLevelToCpp)(data.logLevel),
526 language_compatibility: (0, bindingutilities_1.eventingFunctionLanguageCompatibilityToCpp)(data.languageCompatibility),
527 execution_timeout: data.executionTimeout,
528 lcb_inst_capacity: data.lcbInstCapacity,
529 lcb_retry_count: data.lcbRetryCount,
530 lcb_timeout: data.lcbTimeout,
531 query_consistency: (0, bindingutilities_1.queryScanConsistencyToCpp)(data.queryConsistency),
532 num_timer_partitions: data.numTimerPartitions,
533 sock_batch_size: data.sockBatchSize,
534 tick_duration: data.tickDuration,
535 timer_context_size: data.timerContextSize,
536 user_prefix: data.userPrefix,
537 bucket_cache_size: data.bucketCacheSize,
538 bucket_cache_age: data.bucketCacheAge,
539 curl_max_allowed_resp_size: data.curlMaxAllowedRespSize,
540 query_prepare_all: data.queryPrepareAll,
541 worker_count: data.workerCount,
542 handler_headers: (_a = data.handlerHeaders) !== null && _a !== void 0 ? _a : [],
543 handler_footers: (_b = data.handlerFooters) !== null && _b !== void 0 ? _b : [],
544 enable_app_log_rotation: data.enableAppLogRotation,
545 app_log_dir: data.appLogDir,
546 app_log_max_size: data.appLogMaxSize,
547 app_log_max_files: data.appLogMaxFiles,
548 checkpoint_interval: data.checkpointInterval,
549 };
550 }
551}
552exports.EventingFunctionSettings = EventingFunctionSettings;
553/**
554 * Describes an eventing function.
555 *
556 * @category Management
557 */
558class EventingFunction {
559 constructor(v) {
560 this.name = v.name;
561 this.code = v.code;
562 this.version = v.version;
563 this.enforceSchema = v.enforceSchema;
564 this.handlerUuid = v.handlerUuid;
565 this.functionInstanceId = v.functionInstanceId;
566 this.metadataKeyspace = v.metadataKeyspace;
567 this.sourceKeyspace = v.sourceKeyspace;
568 this.bucketBindings = v.bucketBindings;
569 this.urlBindings = v.urlBindings;
570 this.constantBindings = v.constantBindings;
571 this.settings = v.settings;
572 }
573 /**
574 * @internal
575 */
576 static _fromCppData(data) {
577 return new EventingFunction({
578 name: data.name,
579 code: data.code,
580 metadataKeyspace: new EventingFunctionKeyspace({
581 bucket: data.metadata_keyspace.bucket,
582 scope: data.metadata_keyspace.scope,
583 collection: data.metadata_keyspace.collection,
584 }),
585 sourceKeyspace: new EventingFunctionKeyspace({
586 bucket: data.source_keyspace.bucket,
587 scope: data.source_keyspace.scope,
588 collection: data.source_keyspace.collection,
589 }),
590 version: data.version,
591 enforceSchema: data.enforce_schema,
592 handlerUuid: data.handler_uuid,
593 functionInstanceId: data.function_instance_id,
594 bucketBindings: data.bucket_bindings.map((bindingData) => EventingFunctionBucketBinding._fromCppData(bindingData)),
595 urlBindings: data.url_bindings.map((bindingData) => EventingFunctionUrlBinding._fromCppData(bindingData)),
596 constantBindings: data.constant_bindings.map((bindingData) => EventingFunctionConstantBinding._fromCppData(bindingData)),
597 settings: EventingFunctionSettings._fromCppData(data.settings),
598 });
599 }
600 /**
601 * @internal
602 */
603 static _toCppData(data) {
604 return {
605 name: data.name,
606 code: data.code,
607 metadata_keyspace: {
608 bucket: data.metadataKeyspace.bucket,
609 scope: data.metadataKeyspace.scope,
610 collection: data.metadataKeyspace.collection,
611 },
612 source_keyspace: {
613 bucket: data.sourceKeyspace.bucket,
614 scope: data.sourceKeyspace.scope,
615 collection: data.sourceKeyspace.collection,
616 },
617 version: data.version,
618 enforce_schema: data.enforceSchema,
619 handler_uuid: data.handlerUuid,
620 function_instance_id: data.functionInstanceId,
621 bucket_bindings: data.bucketBindings.map((binding) => EventingFunctionBucketBinding._toCppData(binding)),
622 url_bindings: data.urlBindings.map((binding) => EventingFunctionUrlBinding._toCppData(binding)),
623 constant_bindings: data.constantBindings.map((binding) => EventingFunctionConstantBinding._toCppData(binding)),
624 settings: EventingFunctionSettings._toCppData(data.settings),
625 };
626 }
627}
628exports.EventingFunction = EventingFunction;
629/**
630 * Describes the current state of an eventing function.
631 *
632 * @category Management
633 */
634class EventingFunctionState {
635 constructor(v) {
636 this.name = v.name;
637 this.status = v.status;
638 this.numBootstrappingNodes = v.numBootstrappingNodes;
639 this.numDeployedNodes = v.numDeployedNodes;
640 this.deploymentStatus = v.deploymentStatus;
641 this.processingStatus = v.processingStatus;
642 }
643 /**
644 * @internal
645 */
646 static _fromCppData(data) {
647 return new EventingFunctionState({
648 name: data.name,
649 status: (0, bindingutilities_1.eventingFunctionStatusFromCpp)(data.status),
650 numBootstrappingNodes: data.num_bootstrapping_nodes,
651 numDeployedNodes: data.num_deployed_nodes,
652 // deploymentStatus & processingStatus are required in the EventingFunctionState, and always set in the c++ interface, so asserting the type here.
653 deploymentStatus: (0, bindingutilities_1.eventingFunctionDeploymentStatusFromCpp)(data.deployment_status),
654 processingStatus: (0, bindingutilities_1.eventingFunctionProcessingStatusFromCpp)(data.processing_status),
655 });
656 }
657}
658exports.EventingFunctionState = EventingFunctionState;
659/**
660 * Describes the current state of all eventing function.
661 *
662 * @category Management
663 */
664class EventingState {
665 constructor(v) {
666 this.numEventingNodes = v.numEventingNodes;
667 this.functions = v.functions;
668 }
669 /**
670 * @internal
671 */
672 static _fromCppData(data) {
673 return new EventingState({
674 numEventingNodes: data.num_eventing_nodes,
675 functions: data.functions.map((functionData) => EventingFunctionState._fromCppData(functionData)),
676 });
677 }
678}
679exports.EventingState = EventingState;
680/**
681 * EventingFunctionManager provides an interface for managing the
682 * eventing functions on the cluster.
683 * Uncommitted: This API is subject to change in the future.
684 *
685 * @category Management
686 */
687class EventingFunctionManager {
688 /**
689 * @internal
690 */
691 constructor(cluster) {
692 this._cluster = cluster;
693 }
694 /**
695 * Creates or updates an eventing function.
696 *
697 * @param functionDefinition The description of the eventing function to upsert.
698 * @param options Optional parameters for this operation.
699 * @param callback A node-style callback to be invoked after execution.
700 */
701 async upsertFunction(functionDefinition, options, callback) {
702 if (options instanceof Function) {
703 callback = arguments[1];
704 options = undefined;
705 }
706 if (!options) {
707 options = {};
708 }
709 const timeout = options.timeout || this._cluster.managementTimeout;
710 return utilities_1.PromiseHelper.wrap((wrapCallback) => {
711 this._cluster.conn.managementEventingUpsertFunction({
712 function: EventingFunction._toCppData(functionDefinition),
713 timeout: timeout,
714 }, (cppErr) => {
715 const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
716 if (err) {
717 return wrapCallback(err, null);
718 }
719 wrapCallback(err);
720 });
721 }, callback);
722 }
723 /**
724 * Deletes an eventing function.
725 *
726 * @param name The name of the eventing function to delete.
727 * @param options Optional parameters for this operation.
728 * @param callback A node-style callback to be invoked after execution.
729 */
730 async dropFunction(name, options, callback) {
731 if (options instanceof Function) {
732 callback = arguments[1];
733 options = undefined;
734 }
735 if (!options) {
736 options = {};
737 }
738 const timeout = options.timeout || this._cluster.managementTimeout;
739 return utilities_1.PromiseHelper.wrap((wrapCallback) => {
740 this._cluster.conn.managementEventingDropFunction({
741 name: name,
742 timeout: timeout,
743 }, (cppErr) => {
744 const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
745 if (err) {
746 return wrapCallback(err, null);
747 }
748 wrapCallback(err);
749 });
750 }, callback);
751 }
752 /**
753 * Fetches all eventing functions.
754 *
755 * @param options Optional parameters for this operation.
756 * @param callback A node-style callback to be invoked after execution.
757 */
758 async getAllFunctions(options, callback) {
759 if (options instanceof Function) {
760 callback = arguments[0];
761 options = undefined;
762 }
763 if (!options) {
764 options = {};
765 }
766 const timeout = options.timeout || this._cluster.managementTimeout;
767 return utilities_1.PromiseHelper.wrap((wrapCallback) => {
768 this._cluster.conn.managementEventingGetAllFunctions({
769 timeout: timeout,
770 }, (cppErr, resp) => {
771 const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
772 if (err) {
773 return wrapCallback(err, null);
774 }
775 const functions = resp.functions.map((functionData) => EventingFunction._fromCppData(functionData));
776 wrapCallback(null, functions);
777 });
778 }, callback);
779 }
780 /**
781 * Fetches a specific eventing function.
782 *
783 * @param name The name of the eventing function to fetch.
784 * @param options Optional parameters for this operation.
785 * @param callback A node-style callback to be invoked after execution.
786 */
787 async getFunction(name, options, callback) {
788 if (options instanceof Function) {
789 callback = arguments[1];
790 options = undefined;
791 }
792 if (!options) {
793 options = {};
794 }
795 const timeout = options.timeout || this._cluster.managementTimeout;
796 return utilities_1.PromiseHelper.wrap((wrapCallback) => {
797 this._cluster.conn.managementEventingGetFunction({
798 name: name,
799 timeout: timeout,
800 }, (cppErr, resp) => {
801 const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
802 if (err) {
803 return wrapCallback(err, null);
804 }
805 const eventingFunction = EventingFunction._fromCppData(resp.function);
806 wrapCallback(null, eventingFunction);
807 });
808 }, callback);
809 }
810 /**
811 * Deploys an eventing function.
812 *
813 * @param name The name of the eventing function to deploy.
814 * @param options Optional parameters for this operation.
815 * @param callback A node-style callback to be invoked after execution.
816 */
817 async deployFunction(name, options, callback) {
818 if (options instanceof Function) {
819 callback = arguments[1];
820 options = undefined;
821 }
822 if (!options) {
823 options = {};
824 }
825 const timeout = options.timeout || this._cluster.managementTimeout;
826 return utilities_1.PromiseHelper.wrap((wrapCallback) => {
827 this._cluster.conn.managementEventingDeployFunction({
828 name: name,
829 timeout: timeout,
830 }, (cppErr) => {
831 const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
832 if (err) {
833 return wrapCallback(err, null);
834 }
835 wrapCallback(err);
836 });
837 }, callback);
838 }
839 /**
840 * Undeploys an eventing function.
841 *
842 * @param name The name of the eventing function to undeploy.
843 * @param options Optional parameters for this operation.
844 * @param callback A node-style callback to be invoked after execution.
845 */
846 async undeployFunction(name, options, callback) {
847 if (options instanceof Function) {
848 callback = arguments[1];
849 options = undefined;
850 }
851 if (!options) {
852 options = {};
853 }
854 const timeout = options.timeout || this._cluster.managementTimeout;
855 return utilities_1.PromiseHelper.wrap((wrapCallback) => {
856 this._cluster.conn.managementEventingUndeployFunction({
857 name: name,
858 timeout: timeout,
859 }, (cppErr) => {
860 const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
861 if (err) {
862 return wrapCallback(err, null);
863 }
864 wrapCallback(err);
865 });
866 }, callback);
867 }
868 /**
869 * Pauses an eventing function.
870 *
871 * @param name The name of the eventing function to pause.
872 * @param options Optional parameters for this operation.
873 * @param callback A node-style callback to be invoked after execution.
874 */
875 async pauseFunction(name, options, callback) {
876 if (options instanceof Function) {
877 callback = arguments[1];
878 options = undefined;
879 }
880 if (!options) {
881 options = {};
882 }
883 const timeout = options.timeout || this._cluster.managementTimeout;
884 return utilities_1.PromiseHelper.wrap((wrapCallback) => {
885 this._cluster.conn.managementEventingPauseFunction({
886 name: name,
887 timeout: timeout,
888 }, (cppErr) => {
889 const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
890 if (err) {
891 return wrapCallback(err, null);
892 }
893 wrapCallback(err);
894 });
895 }, callback);
896 }
897 /**
898 * Resumes an eventing function.
899 *
900 * @param name The name of the eventing function to resume.
901 * @param options Optional parameters for this operation.
902 * @param callback A node-style callback to be invoked after execution.
903 */
904 async resumeFunction(name, options, callback) {
905 if (options instanceof Function) {
906 callback = arguments[1];
907 options = undefined;
908 }
909 if (!options) {
910 options = {};
911 }
912 const timeout = options.timeout || this._cluster.managementTimeout;
913 return utilities_1.PromiseHelper.wrap((wrapCallback) => {
914 this._cluster.conn.managementEventingResumeFunction({
915 name: name,
916 timeout: timeout,
917 }, (cppErr) => {
918 const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
919 if (err) {
920 return wrapCallback(err, null);
921 }
922 wrapCallback(err);
923 });
924 }, callback);
925 }
926 /**
927 * Fetches the status of all eventing functions.
928 *
929 * @param options Optional parameters for this operation.
930 * @param callback A node-style callback to be invoked after execution.
931 */
932 async functionsStatus(options, callback) {
933 if (options instanceof Function) {
934 callback = arguments[0];
935 options = undefined;
936 }
937 if (!options) {
938 options = {};
939 }
940 const timeout = options.timeout || this._cluster.managementTimeout;
941 return utilities_1.PromiseHelper.wrap((wrapCallback) => {
942 this._cluster.conn.managementEventingGetStatus({
943 timeout: timeout,
944 }, (cppErr, resp) => {
945 const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
946 if (err) {
947 return wrapCallback(err, null);
948 }
949 const state = EventingState._fromCppData(resp.status);
950 wrapCallback(null, state);
951 });
952 }, callback);
953 }
954}
955exports.EventingFunctionManager = EventingFunctionManager;