couchbase 3.2.0 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +24 -18
  2. package/binding.gyp +88 -85
  3. package/deps/lcb/CMakeLists.txt +1 -1
  4. package/deps/lcb/CONTRIBUTING.md +1 -1
  5. package/deps/lcb/README.markdown +2 -2
  6. package/deps/lcb/RELEASE_NOTES.markdown +99 -14
  7. package/deps/lcb/cmake/Modules/GetVersionInfo.cmake +1 -1
  8. package/deps/lcb/contrib/cbsasl/src/scram-sha/scram_utils.cc +22 -26
  9. package/deps/lcb/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +20 -7
  10. package/deps/lcb/doc/Doxyfile +1 -1
  11. package/deps/lcb/example/CMakeLists.txt +4 -4
  12. package/deps/lcb/example/libuvdirect/main.c +39 -12
  13. package/deps/lcb/example/minimal/durability.cc +149 -0
  14. package/deps/lcb/example/minimal/query.c +11 -9
  15. package/deps/lcb/gyp_config/common/libcouchbase/configuration.h +3 -3
  16. package/deps/lcb/gyp_config/linux/arm64/config.h +243 -0
  17. package/deps/lcb/include/libcouchbase/couchbase.h +80 -5
  18. package/deps/lcb/include/libcouchbase/error.h +2 -0
  19. package/deps/lcb/include/libcouchbase/ixmgmt.h +15 -10
  20. package/deps/lcb/include/libcouchbase/tracing.h +2 -2
  21. package/deps/lcb/include/memcached/protocol_binary.h +21 -0
  22. package/deps/lcb/libcouchbase.gyp +347 -349
  23. package/deps/lcb/packaging/deb/control +1 -1
  24. package/deps/lcb/src/analytics/analytics_handle.cc +13 -5
  25. package/deps/lcb/src/analytics/analytics_handle.hh +29 -0
  26. package/deps/lcb/src/bootstrap.cc +6 -3
  27. package/deps/lcb/src/capi/cmd_analytics.cc +12 -1
  28. package/deps/lcb/src/capi/cmd_analytics.hh +30 -0
  29. package/deps/lcb/src/capi/cmd_counter.hh +23 -0
  30. package/deps/lcb/src/capi/cmd_exists.hh +24 -1
  31. package/deps/lcb/src/capi/cmd_get.hh +22 -0
  32. package/deps/lcb/src/capi/cmd_get_replica.hh +23 -0
  33. package/deps/lcb/src/capi/cmd_http.hh +7 -0
  34. package/deps/lcb/src/capi/cmd_query.cc +11 -1
  35. package/deps/lcb/src/capi/cmd_query.hh +31 -0
  36. package/deps/lcb/src/capi/cmd_remove.hh +23 -0
  37. package/deps/lcb/src/capi/cmd_search.cc +6 -0
  38. package/deps/lcb/src/capi/cmd_search.hh +23 -0
  39. package/deps/lcb/src/capi/cmd_store.hh +33 -21
  40. package/deps/lcb/src/capi/cmd_subdoc.hh +35 -0
  41. package/deps/lcb/src/capi/cmd_touch.hh +23 -0
  42. package/deps/lcb/src/capi/cmd_unlock.hh +23 -0
  43. package/deps/lcb/src/capi/cmd_view.hh +6 -0
  44. package/deps/lcb/src/capi/collection_qualifier.hh +2 -2
  45. package/deps/lcb/src/cntl.cc +45 -11
  46. package/deps/lcb/src/crypto.cc +2 -2
  47. package/deps/lcb/src/dns-srv.cc +5 -3
  48. package/deps/lcb/src/errmap.cc +5 -9
  49. package/deps/lcb/src/errmap.h +7 -3
  50. package/deps/lcb/src/handler.cc +24 -18
  51. package/deps/lcb/src/hostlist.h +2 -2
  52. package/deps/lcb/src/http/http-priv.h +2 -2
  53. package/deps/lcb/src/http/http.cc +5 -2
  54. package/deps/lcb/src/instance.cc +20 -11
  55. package/deps/lcb/src/internal.h +9 -0
  56. package/deps/lcb/src/lcbio/connect.cc +14 -2
  57. package/deps/lcb/src/lcbio/connect.h +2 -2
  58. package/deps/lcb/src/lcbio/ctx.cc +4 -2
  59. package/deps/lcb/src/lcbio/ioutils.cc +9 -10
  60. package/deps/lcb/src/lcbio/manager.cc +1 -1
  61. package/deps/lcb/src/mcserver/mcserver.cc +9 -6
  62. package/deps/lcb/src/mcserver/negotiate.cc +39 -17
  63. package/deps/lcb/src/n1ql/ixmgmt.cc +1 -2
  64. package/deps/lcb/src/n1ql/query_handle.cc +41 -19
  65. package/deps/lcb/src/n1ql/query_handle.hh +28 -1
  66. package/deps/lcb/src/operations/counter.cc +18 -5
  67. package/deps/lcb/src/operations/exists.cc +25 -4
  68. package/deps/lcb/src/operations/get.cc +39 -19
  69. package/deps/lcb/src/operations/get_replica.cc +28 -8
  70. package/deps/lcb/src/operations/observe.cc +1 -1
  71. package/deps/lcb/src/operations/ping.cc +8 -8
  72. package/deps/lcb/src/operations/pktfwd.cc +2 -1
  73. package/deps/lcb/src/operations/remove.cc +39 -22
  74. package/deps/lcb/src/operations/store.cc +18 -5
  75. package/deps/lcb/src/operations/subdoc.cc +18 -6
  76. package/deps/lcb/src/operations/touch.cc +34 -16
  77. package/deps/lcb/src/operations/unlock.cc +24 -5
  78. package/deps/lcb/src/packetutils.h +3 -2
  79. package/deps/lcb/src/retryq.cc +24 -5
  80. package/deps/lcb/src/search/search.cc +1 -0
  81. package/deps/lcb/src/search/search_handle.cc +30 -8
  82. package/deps/lcb/src/search/search_handle.hh +29 -0
  83. package/deps/lcb/src/settings.cc +1 -1
  84. package/deps/lcb/src/ssl/ssl_common.c +6 -7
  85. package/deps/lcb/src/tracing/span.cc +47 -14
  86. package/deps/lcb/src/tracing/tracer.cc +11 -2
  87. package/deps/lcb/src/tracing/tracing-internal.h +105 -93
  88. package/deps/lcb/src/utilities.cc +43 -0
  89. package/deps/lcb/src/utilities.h +53 -0
  90. package/deps/lcb/src/vbucket/vbucket.c +34 -33
  91. package/deps/lcb/src/views/view_handle.cc +13 -5
  92. package/deps/lcb/src/views/view_handle.hh +29 -0
  93. package/deps/lcb/tests/CMakeLists.txt +21 -0
  94. package/deps/lcb/tests/basic/t_ctlcodes.cc +24 -3
  95. package/deps/lcb/tests/basic/t_jsparse.cc +8 -0
  96. package/deps/lcb/tests/basic/t_n1qlstrings.cc +73 -0
  97. package/deps/lcb/tests/iotests/mock-environment.cc +30 -1
  98. package/deps/lcb/tests/iotests/mock-environment.h +49 -0
  99. package/deps/lcb/tests/iotests/mock-unit-test.cc +104 -6
  100. package/deps/lcb/tests/iotests/mock-unit-test.h +34 -0
  101. package/deps/lcb/tests/iotests/t_collections.cc +1 -1
  102. package/deps/lcb/tests/iotests/t_confmon.cc +4 -2
  103. package/deps/lcb/tests/iotests/t_get.cc +109 -7
  104. package/deps/lcb/tests/iotests/t_http.cc +9 -4
  105. package/deps/lcb/tests/iotests/t_lock.cc +18 -0
  106. package/deps/lcb/tests/iotests/t_mutate.cc +157 -63
  107. package/deps/lcb/tests/iotests/t_n1ql.cc +330 -33
  108. package/deps/lcb/tests/iotests/t_views.cc +1 -0
  109. package/deps/lcb/tests/iotests/testutil.cc +168 -0
  110. package/deps/lcb/tests/iotests/testutil.h +116 -0
  111. package/deps/lcb/tests/mocksupport/procutil.c +32 -28
  112. package/deps/lcb/tests/mocksupport/server.c +0 -1
  113. package/deps/lcb/tests/mocksupport/timeout.c +2 -2
  114. package/deps/lcb/tools/cbc.cc +7 -0
  115. package/dist/analyticsindexmanager.js +512 -524
  116. package/dist/binding.d.ts +3 -0
  117. package/dist/bindingutilities.js +4 -0
  118. package/dist/bucket.js +1 -1
  119. package/dist/bucketmanager.d.ts +31 -1
  120. package/dist/bucketmanager.js +194 -186
  121. package/dist/cluster.d.ts +7 -0
  122. package/dist/cluster.js +48 -38
  123. package/dist/collection.js +11 -17
  124. package/dist/collectionmanager.js +181 -197
  125. package/dist/connection.d.ts +3 -1
  126. package/dist/connection.js +27 -16
  127. package/dist/couchbase.d.ts +1 -0
  128. package/dist/couchbase.js +3 -13
  129. package/dist/datastructures.js +239 -310
  130. package/dist/diagnosticsexecutor.js +70 -85
  131. package/dist/errors.d.ts +70 -0
  132. package/dist/errors.js +96 -2
  133. package/dist/eventingfunctionmanager.d.ts +804 -0
  134. package/dist/eventingfunctionmanager.js +993 -0
  135. package/dist/httpexecutor.d.ts +2 -1
  136. package/dist/httpexecutor.js +30 -37
  137. package/dist/queryindexmanager.js +240 -266
  138. package/dist/scope.js +10 -4
  139. package/dist/sdspecs.d.ts +1 -1
  140. package/dist/searchexecutor.js +3 -0
  141. package/dist/searchindexmanager.js +240 -271
  142. package/dist/searchquery.d.ts +17 -0
  143. package/dist/searchquery.js +22 -1
  144. package/dist/searchtypes.d.ts +7 -2
  145. package/dist/searchtypes.js +2 -2
  146. package/dist/usermanager.js +251 -264
  147. package/dist/utilities.d.ts +2 -0
  148. package/dist/utilities.js +7 -2
  149. package/dist/viewexecutor.js +1 -1
  150. package/dist/viewindexmanager.js +131 -150
  151. package/package.json +1 -1
  152. package/src/addondata.cpp +58 -0
  153. package/src/addondata.h +40 -0
  154. package/src/binding.cpp +3 -1
  155. package/src/cas.h +2 -2
  156. package/src/connection.cpp +25 -178
  157. package/src/connection.h +8 -65
  158. package/src/connection_ops.cpp +57 -34
  159. package/src/constants.cpp +3 -0
  160. package/src/instance.cpp +235 -0
  161. package/src/instance.h +102 -0
  162. package/src/{connection_callbacks.cpp → instance_callbacks.cpp} +34 -34
  163. package/src/logger.cpp +11 -1
  164. package/src/logger.h +3 -0
  165. package/src/metrics.cpp +10 -0
  166. package/src/metrics.h +3 -0
  167. package/src/mutationtoken.h +2 -2
  168. package/src/opbuilder.h +13 -15
  169. package/src/respreader.cpp +1 -0
  170. package/src/respreader.h +6 -4
  171. package/src/tracespan.h +11 -11
  172. package/src/tracing.cpp +11 -0
  173. package/src/tracing.h +3 -0
  174. package/src/valueparser.h +5 -0
  175. package/deps/lcb/example/observe/durability.c +0 -110
@@ -0,0 +1,993 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.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;
4
+ const errors_1 = require("./errors");
5
+ const httpexecutor_1 = require("./httpexecutor");
6
+ const utilities_1 = require("./utilities");
7
+ /**
8
+ * Represents the various dcp boundary options for eventing functions.
9
+ *
10
+ * @category Management
11
+ */
12
+ var EventingFunctionDcpBoundary;
13
+ (function (EventingFunctionDcpBoundary) {
14
+ /**
15
+ * Indicates all documents should be processed by the function.
16
+ */
17
+ EventingFunctionDcpBoundary["Everything"] = "everything";
18
+ /**
19
+ * Indicates that only documents modified after a function is created
20
+ * should be processed by the function.
21
+ */
22
+ EventingFunctionDcpBoundary["FromNow"] = "from_now";
23
+ })(EventingFunctionDcpBoundary = exports.EventingFunctionDcpBoundary || (exports.EventingFunctionDcpBoundary = {}));
24
+ /**
25
+ * Represents the various possible deployment statuses for an eventing function.
26
+ *
27
+ * @category Management
28
+ */
29
+ var EventingFunctionDeploymentStatus;
30
+ (function (EventingFunctionDeploymentStatus) {
31
+ /**
32
+ * Indicates that the function is deployed.
33
+ */
34
+ EventingFunctionDeploymentStatus["Deployed"] = "deployed";
35
+ /**
36
+ * Indicates that the function has not yet been deployed.
37
+ */
38
+ EventingFunctionDeploymentStatus["Undeployed"] = "undeployed";
39
+ })(EventingFunctionDeploymentStatus = exports.EventingFunctionDeploymentStatus || (exports.EventingFunctionDeploymentStatus = {}));
40
+ /**
41
+ * Represents the various possible processing statuses for an eventing function.
42
+ *
43
+ * @category Management
44
+ */
45
+ var EventingFunctionProcessingStatus;
46
+ (function (EventingFunctionProcessingStatus) {
47
+ /**
48
+ * Indicates that the eventing function is currently running.
49
+ */
50
+ EventingFunctionProcessingStatus["Running"] = "running";
51
+ /**
52
+ * Indicates that the eventing function is currently paused.
53
+ */
54
+ EventingFunctionProcessingStatus["Paused"] = "paused";
55
+ })(EventingFunctionProcessingStatus = exports.EventingFunctionProcessingStatus || (exports.EventingFunctionProcessingStatus = {}));
56
+ /**
57
+ * Represents the authentication method to use for a URL binding.
58
+ *
59
+ * @category Management
60
+ */
61
+ var EventingFunctionStatus;
62
+ (function (EventingFunctionStatus) {
63
+ /**
64
+ * Indicates that the eventing function is undeployed.
65
+ */
66
+ EventingFunctionStatus["Undeployed"] = "undeployed";
67
+ /**
68
+ * Indicates that the eventing function is deploying.
69
+ */
70
+ EventingFunctionStatus["Deploying"] = "deploying";
71
+ /**
72
+ * Indicates that the eventing function is deployed.
73
+ */
74
+ EventingFunctionStatus["Deployed"] = "deployed";
75
+ /**
76
+ * Indicates that the eventing function is undeploying.
77
+ */
78
+ EventingFunctionStatus["Undeploying"] = "undeploying";
79
+ /**
80
+ * Indicates that the eventing function is paused.
81
+ */
82
+ EventingFunctionStatus["Paused"] = "paused";
83
+ /**
84
+ * Indicates that the eventing function is pausing.
85
+ */
86
+ EventingFunctionStatus["Pausing"] = "pausing";
87
+ })(EventingFunctionStatus = exports.EventingFunctionStatus || (exports.EventingFunctionStatus = {}));
88
+ /**
89
+ * Represents the language compatibility levels of an eventing function.
90
+ *
91
+ * @category Management
92
+ */
93
+ var EventingFunctionLanguageCompatibility;
94
+ (function (EventingFunctionLanguageCompatibility) {
95
+ /**
96
+ * Indicates that the function should run with compatibility with
97
+ * Couchbase Server 6.0.0.
98
+ */
99
+ EventingFunctionLanguageCompatibility["Version_6_0_0"] = "6.0.0";
100
+ /**
101
+ * Indicates that the function should run with compatibility with
102
+ * Couchbase Server 6.5.0.
103
+ */
104
+ EventingFunctionLanguageCompatibility["Version_6_5_0"] = "6.5.0";
105
+ /**
106
+ * Indicates that the function should run with compatibility with
107
+ * Couchbase Server 6.6.2.
108
+ */
109
+ EventingFunctionLanguageCompatibility["Version_6_6_2"] = "6.6.2";
110
+ })(EventingFunctionLanguageCompatibility = exports.EventingFunctionLanguageCompatibility || (exports.EventingFunctionLanguageCompatibility = {}));
111
+ /**
112
+ * Represents the various log levels for an eventing function.
113
+ *
114
+ * @category Management
115
+ */
116
+ var EventingFunctionLogLevel;
117
+ (function (EventingFunctionLogLevel) {
118
+ /**
119
+ * Indicates to use INFO level logging.
120
+ */
121
+ EventingFunctionLogLevel["Info"] = "INFO";
122
+ /**
123
+ * Indicates to use ERROR level logging.
124
+ */
125
+ EventingFunctionLogLevel["Error"] = "ERROR";
126
+ /**
127
+ * Indicates to use WARNING level logging.
128
+ */
129
+ EventingFunctionLogLevel["Warning"] = "WARNING";
130
+ /**
131
+ * Indicates to use DEBUG level logging.
132
+ */
133
+ EventingFunctionLogLevel["Debug"] = "DEBUG";
134
+ /**
135
+ * Indicates to use TRACE level logging.
136
+ */
137
+ EventingFunctionLogLevel["Trace"] = "TRACE";
138
+ })(EventingFunctionLogLevel = exports.EventingFunctionLogLevel || (exports.EventingFunctionLogLevel = {}));
139
+ /**
140
+ * Represents the various bucket access levels for an eventing function.
141
+ *
142
+ * @category Management
143
+ */
144
+ var EventingFunctionBucketAccess;
145
+ (function (EventingFunctionBucketAccess) {
146
+ /**
147
+ * Indicates that the function can only read the associated bucket.
148
+ */
149
+ EventingFunctionBucketAccess["ReadOnly"] = "r";
150
+ /**
151
+ * Indicates that the function can both read and write the associated bucket.
152
+ */
153
+ EventingFunctionBucketAccess["ReadWrite"] = "rw";
154
+ })(EventingFunctionBucketAccess = exports.EventingFunctionBucketAccess || (exports.EventingFunctionBucketAccess = {}));
155
+ /**
156
+ * Represents the authentication method to use for a URL binding.
157
+ *
158
+ * @category Management
159
+ */
160
+ var EventingFunctionUrlAuthMethod;
161
+ (function (EventingFunctionUrlAuthMethod) {
162
+ /**
163
+ * Indicates that no authentication should be used.
164
+ */
165
+ EventingFunctionUrlAuthMethod["None"] = "no-auth";
166
+ /**
167
+ * Indicates that Basic should be used.
168
+ */
169
+ EventingFunctionUrlAuthMethod["Basic"] = "basic";
170
+ /**
171
+ * Indicates that Digest should be used.
172
+ */
173
+ EventingFunctionUrlAuthMethod["Digest"] = "digest";
174
+ /**
175
+ * Indicates that Bearer should be used.
176
+ */
177
+ EventingFunctionUrlAuthMethod["Bearer"] = "bearer";
178
+ })(EventingFunctionUrlAuthMethod = exports.EventingFunctionUrlAuthMethod || (exports.EventingFunctionUrlAuthMethod = {}));
179
+ /**
180
+ * Specifies the bucket/scope/collection used by an eventing function.
181
+ *
182
+ * @category Management
183
+ */
184
+ class EventingFunctionKeyspace {
185
+ constructor(v) {
186
+ this.bucket = v.bucket;
187
+ this.scope = v.scope;
188
+ this.collection = v.collection;
189
+ }
190
+ }
191
+ exports.EventingFunctionKeyspace = EventingFunctionKeyspace;
192
+ /**
193
+ * Specifies a bucket binding for an eventing function.
194
+ *
195
+ * @category Management
196
+ */
197
+ class EventingFunctionBucketBinding {
198
+ constructor(v) {
199
+ this.alias = v.alias;
200
+ this.name = v.name;
201
+ this.access = v.access;
202
+ }
203
+ /**
204
+ * @internal
205
+ */
206
+ static _fromEvtData(data) {
207
+ return new EventingFunctionBucketBinding({
208
+ name: new EventingFunctionKeyspace({
209
+ bucket: data.bucket_name,
210
+ scope: data.scope_name,
211
+ collection: data.collection_name,
212
+ }),
213
+ alias: data.alias,
214
+ access: data.access,
215
+ });
216
+ }
217
+ /**
218
+ * @internal
219
+ */
220
+ static _toEvtData(data) {
221
+ return {
222
+ bucket_name: data.name.bucket,
223
+ scope_name: data.name.scope,
224
+ collection_name: data.name.collection,
225
+ alias: data.alias,
226
+ access: data.access,
227
+ };
228
+ }
229
+ }
230
+ exports.EventingFunctionBucketBinding = EventingFunctionBucketBinding;
231
+ /**
232
+ * Specifies that Basic authentication should be used for the URL.
233
+ *
234
+ * @category Management
235
+ */
236
+ class EventingFunctionUrlAuthBasic {
237
+ constructor(v) {
238
+ /**
239
+ * Sets the auth method to Basic.
240
+ */
241
+ this.method = EventingFunctionUrlAuthMethod.Basic;
242
+ this.username = v.username;
243
+ this.password = v.password;
244
+ }
245
+ }
246
+ exports.EventingFunctionUrlAuthBasic = EventingFunctionUrlAuthBasic;
247
+ /**
248
+ * Specifies that Digest authentication should be used for the URL.
249
+ *
250
+ * @category Management
251
+ */
252
+ class EventingFunctionUrlAuthDigest {
253
+ constructor(v) {
254
+ /**
255
+ * Sets the auth method to Digest.
256
+ */
257
+ this.method = EventingFunctionUrlAuthMethod.Digest;
258
+ this.username = v.username;
259
+ this.password = v.password;
260
+ }
261
+ }
262
+ exports.EventingFunctionUrlAuthDigest = EventingFunctionUrlAuthDigest;
263
+ /**
264
+ * Specifies that Bearer authentication should be used for the URL.
265
+ *
266
+ * @category Management
267
+ */
268
+ class EventingFunctionUrlAuthBearer {
269
+ constructor(v) {
270
+ /**
271
+ * Sets the auth method to Bearer.
272
+ */
273
+ this.method = EventingFunctionUrlAuthMethod.Bearer;
274
+ this.key = v.key;
275
+ }
276
+ }
277
+ exports.EventingFunctionUrlAuthBearer = EventingFunctionUrlAuthBearer;
278
+ /**
279
+ * Specifies a url binding for an eventing function.
280
+ *
281
+ * @category Management
282
+ */
283
+ class EventingFunctionUrlBinding {
284
+ constructor(v) {
285
+ this.hostname = v.hostname;
286
+ this.alias = v.alias;
287
+ this.auth = v.auth;
288
+ this.allowCookies = v.allowCookies;
289
+ this.validateSslCertificate = v.validateSslCertificate;
290
+ }
291
+ /**
292
+ * @internal
293
+ */
294
+ static _fromEvtData(data) {
295
+ let authObj;
296
+ if (data.auth_type === EventingFunctionUrlAuthMethod.None) {
297
+ authObj = undefined;
298
+ }
299
+ else if (data.auth_type === EventingFunctionUrlAuthMethod.Basic) {
300
+ authObj = new EventingFunctionUrlAuthBasic({
301
+ username: data.username,
302
+ password: data.password,
303
+ });
304
+ }
305
+ else if (data.auth_type === EventingFunctionUrlAuthMethod.Digest) {
306
+ authObj = new EventingFunctionUrlAuthDigest({
307
+ username: data.username,
308
+ password: data.password,
309
+ });
310
+ }
311
+ else if (data.auth_type === EventingFunctionUrlAuthMethod.Bearer) {
312
+ authObj = new EventingFunctionUrlAuthBearer({
313
+ key: data.bearer_key,
314
+ });
315
+ }
316
+ else {
317
+ throw new Error('invalid auth type specified');
318
+ }
319
+ return {
320
+ hostname: data.hostname,
321
+ alias: data.value,
322
+ allowCookies: data.allow_cookies,
323
+ validateSslCertificate: data.validate_ssl_certificate,
324
+ auth: authObj,
325
+ };
326
+ }
327
+ /**
328
+ * @internal
329
+ */
330
+ static _toEvtData(data) {
331
+ return {
332
+ hostname: data.hostname,
333
+ value: data.alias,
334
+ allow_cookies: data.allowCookies,
335
+ validate_ssl_certificate: data.validateSslCertificate,
336
+ auth_type: data.auth
337
+ ? data.auth.method
338
+ : EventingFunctionUrlAuthMethod.None,
339
+ username: data.username,
340
+ password: data.password,
341
+ bearer_key: data.key,
342
+ };
343
+ }
344
+ }
345
+ exports.EventingFunctionUrlBinding = EventingFunctionUrlBinding;
346
+ /**
347
+ * Specifies a constant binding for an eventing function.
348
+ *
349
+ * @category Management
350
+ */
351
+ class EventingFunctionConstantBinding {
352
+ constructor(v) {
353
+ this.alias = v.alias;
354
+ this.literal = v.literal;
355
+ }
356
+ /**
357
+ * @internal
358
+ */
359
+ static _fromEvtData(data) {
360
+ return new EventingFunctionConstantBinding({
361
+ alias: data.value,
362
+ literal: data.literal,
363
+ });
364
+ }
365
+ /**
366
+ * @internal
367
+ */
368
+ static _toEvtData(data) {
369
+ return {
370
+ value: data.alias,
371
+ literal: data.literal,
372
+ };
373
+ }
374
+ }
375
+ exports.EventingFunctionConstantBinding = EventingFunctionConstantBinding;
376
+ /**
377
+ * Specifies a number of options which can be used when updating or creating
378
+ * a eventing function.
379
+ *
380
+ * @category Management
381
+ */
382
+ class EventingFunctionSettings {
383
+ constructor(v) {
384
+ this.cppWorkerThreadCount = v.cppWorkerThreadCount;
385
+ this.dcpStreamBoundary = v.dcpStreamBoundary;
386
+ this.description = v.description;
387
+ this.deploymentStatus = v.deploymentStatus;
388
+ this.processingStatus = v.processingStatus;
389
+ this.languageCompatibility = v.languageCompatibility;
390
+ this.logLevel = v.logLevel;
391
+ this.executionTimeout = v.executionTimeout;
392
+ this.lcbInstCapacity = v.lcbInstCapacity;
393
+ this.lcbRetryCount = v.lcbRetryCount;
394
+ this.lcbTimeout = v.lcbTimeout;
395
+ this.queryConsistency = v.queryConsistency;
396
+ this.numTimerPartitions = v.numTimerPartitions;
397
+ this.sockBatchSize = v.sockBatchSize;
398
+ this.tickDuration = v.tickDuration;
399
+ this.timerContextSize = v.timerContextSize;
400
+ this.userPrefix = v.userPrefix;
401
+ this.bucketCacheSize = v.bucketCacheSize;
402
+ this.bucketCacheAge = v.bucketCacheAge;
403
+ this.curlMaxAllowedRespSize = v.curlMaxAllowedRespSize;
404
+ this.queryPrepareAll = v.queryPrepareAll;
405
+ this.workerCount = v.workerCount;
406
+ this.handlerHeaders = v.handlerHeaders;
407
+ this.handlerFooters = v.handlerFooters;
408
+ this.enableAppLogRotation = v.enableAppLogRotation;
409
+ this.appLogDir = v.appLogDir;
410
+ this.appLogMaxSize = v.appLogMaxSize;
411
+ this.appLogMaxFiles = v.appLogMaxFiles;
412
+ this.checkpointInterval = v.checkpointInterval;
413
+ }
414
+ /**
415
+ * @internal
416
+ */
417
+ static _fromEvtData(data) {
418
+ return new EventingFunctionSettings({
419
+ cppWorkerThreadCount: data.cpp_worker_thread_count,
420
+ dcpStreamBoundary: data.dcp_stream_boundary,
421
+ description: data.description,
422
+ logLevel: data.log_level,
423
+ languageCompatibility: data.language_compatibility,
424
+ executionTimeout: data.execution_timeout,
425
+ lcbInstCapacity: data.lcb_inst_capacity,
426
+ lcbRetryCount: data.lcb_retry_count,
427
+ lcbTimeout: data.lcb_timeout,
428
+ queryConsistency: data.n1ql_consistency,
429
+ numTimerPartitions: data.num_timer_partitions,
430
+ sockBatchSize: data.sock_batch_size,
431
+ tickDuration: data.tick_duration,
432
+ timerContextSize: data.timer_context_size,
433
+ userPrefix: data.user_prefix,
434
+ bucketCacheSize: data.bucket_cache_size,
435
+ bucketCacheAge: data.bucket_cache_age,
436
+ curlMaxAllowedRespSize: data.curl_max_allowed_resp_size,
437
+ workerCount: data.worker_count,
438
+ queryPrepareAll: data.n1ql_prepare_all,
439
+ handlerHeaders: data.handler_headers,
440
+ handlerFooters: data.handler_footers,
441
+ enableAppLogRotation: data.enable_applog_rotation,
442
+ appLogDir: data.app_log_dir,
443
+ appLogMaxSize: data.app_log_max_size,
444
+ appLogMaxFiles: data.app_log_max_files,
445
+ checkpointInterval: data.checkpoint_interval,
446
+ deploymentStatus: data.deployment_status
447
+ ? EventingFunctionDeploymentStatus.Deployed
448
+ : EventingFunctionDeploymentStatus.Undeployed,
449
+ processingStatus: data.processing_status
450
+ ? EventingFunctionProcessingStatus.Running
451
+ : EventingFunctionProcessingStatus.Paused,
452
+ });
453
+ }
454
+ /**
455
+ * @internal
456
+ */
457
+ static _toEvtData(data) {
458
+ if (!data) {
459
+ return {
460
+ deployment_status: false,
461
+ };
462
+ }
463
+ return {
464
+ cpp_worker_thread_count: data.cppWorkerThreadCount,
465
+ dcp_stream_boundary: data.dcpStreamBoundary,
466
+ description: data.description,
467
+ log_level: data.logLevel,
468
+ language_compatibility: data.languageCompatibility,
469
+ execution_timeout: data.executionTimeout,
470
+ lcb_inst_capacity: data.lcbInstCapacity,
471
+ lcb_retry_count: data.lcbRetryCount,
472
+ lcb_timeout: data.lcbTimeout,
473
+ n1ql_consistency: data.queryConsistency,
474
+ num_timer_partitions: data.numTimerPartitions,
475
+ sock_batch_size: data.sockBatchSize,
476
+ tick_duration: data.tickDuration,
477
+ timer_context_size: data.timerContextSize,
478
+ user_prefix: data.userPrefix,
479
+ bucket_cache_size: data.bucketCacheSize,
480
+ bucket_cache_age: data.bucketCacheAge,
481
+ curl_max_allowed_resp_size: data.curlMaxAllowedRespSize,
482
+ worker_count: data.workerCount,
483
+ n1ql_prepare_all: data.queryPrepareAll,
484
+ handler_headers: data.handlerHeaders,
485
+ handler_footers: data.handlerFooters,
486
+ enable_applog_rotation: data.enableAppLogRotation,
487
+ app_log_dir: data.appLogDir,
488
+ app_log_max_size: data.appLogMaxSize,
489
+ app_log_max_files: data.appLogMaxFiles,
490
+ checkpoint_interval: data.checkpointInterval,
491
+ deployment_status: data.deploymentStatus === EventingFunctionDeploymentStatus.Deployed
492
+ ? true
493
+ : false,
494
+ processing_status: data.processingStatus === EventingFunctionProcessingStatus.Running
495
+ ? true
496
+ : false,
497
+ };
498
+ }
499
+ }
500
+ exports.EventingFunctionSettings = EventingFunctionSettings;
501
+ /**
502
+ * Describes an eventing function.
503
+ *
504
+ * @category Management
505
+ */
506
+ class EventingFunction {
507
+ constructor(v) {
508
+ this.name = v.name;
509
+ this.code = v.code;
510
+ this.version = v.version;
511
+ this.enforceSchema = v.enforceSchema;
512
+ this.handlerUuid = v.handlerUuid;
513
+ this.functionInstanceId = v.functionInstanceId;
514
+ this.metadataKeyspace = v.metadataKeyspace;
515
+ this.sourceKeyspace = v.sourceKeyspace;
516
+ this.bucketBindings = v.bucketBindings;
517
+ this.urlBindings = v.urlBindings;
518
+ this.constantBindings = v.constantBindings;
519
+ this.settings = v.settings;
520
+ }
521
+ /**
522
+ * @internal
523
+ */
524
+ static _fromEvtData(data) {
525
+ return new EventingFunction({
526
+ name: data.appname,
527
+ code: data.appcode,
528
+ settings: EventingFunctionSettings._fromEvtData(data.settings),
529
+ version: data.version,
530
+ enforceSchema: data.enforce_schema,
531
+ handlerUuid: data.handleruuid,
532
+ functionInstanceId: data.function_instance_id,
533
+ metadataKeyspace: new EventingFunctionKeyspace({
534
+ bucket: data.depcfg.metadata_bucket,
535
+ scope: data.depcfg.metadata_scope,
536
+ collection: data.depcfg.metadata_collection,
537
+ }),
538
+ sourceKeyspace: new EventingFunctionKeyspace({
539
+ bucket: data.depcfg.source_bucket,
540
+ scope: data.depcfg.source_scope,
541
+ collection: data.depcfg.source_collection,
542
+ }),
543
+ constantBindings: data.depcfg.constants.map((bindingData) => EventingFunctionConstantBinding._fromEvtData(bindingData)),
544
+ bucketBindings: data.depcfg.buckets.map((bindingData) => EventingFunctionBucketBinding._fromEvtData(bindingData)),
545
+ urlBindings: data.depcfg.curl.map((bindingData) => EventingFunctionUrlBinding._fromEvtData(bindingData)),
546
+ });
547
+ }
548
+ /**
549
+ * @internal
550
+ */
551
+ static _toEvtData(data) {
552
+ return {
553
+ appname: data.name,
554
+ appcode: data.code,
555
+ settings: EventingFunctionSettings._toEvtData(data.settings),
556
+ version: data.version,
557
+ enforce_schema: data.enforceSchema,
558
+ handleruuid: data.handlerUuid,
559
+ function_instance_id: data.functionInstanceId,
560
+ depcfg: {
561
+ metadata_bucket: data.metadataKeyspace.bucket,
562
+ metadata_scope: data.metadataKeyspace.scope,
563
+ metadata_collection: data.metadataKeyspace.collection,
564
+ source_bucket: data.sourceKeyspace.bucket,
565
+ source_scope: data.sourceKeyspace.scope,
566
+ source_collection: data.sourceKeyspace.collection,
567
+ constants: data.constantBindings.map((binding) => EventingFunctionConstantBinding._toEvtData(binding)),
568
+ buckets: data.bucketBindings.map((binding) => EventingFunctionBucketBinding._toEvtData(binding)),
569
+ curl: data.urlBindings.map((binding) => EventingFunctionUrlBinding._toEvtData(binding)),
570
+ },
571
+ };
572
+ }
573
+ }
574
+ exports.EventingFunction = EventingFunction;
575
+ /**
576
+ * Describes the current state of an eventing function.
577
+ *
578
+ * @category Management
579
+ */
580
+ class EventingFunctionState {
581
+ constructor(v) {
582
+ this.name = v.name;
583
+ this.status = v.status;
584
+ this.numBootstrappingNodes = v.numBootstrappingNodes;
585
+ this.numDeployedNodes = v.numDeployedNodes;
586
+ this.deploymentStatus = v.deploymentStatus;
587
+ this.processingStatus = v.processingStatus;
588
+ }
589
+ /**
590
+ * @internal
591
+ */
592
+ static _fromEvtData(data) {
593
+ return new EventingFunctionState({
594
+ name: data.name,
595
+ status: data.composite_status,
596
+ numBootstrappingNodes: data.num_bootstrapping_nodes,
597
+ numDeployedNodes: data.num_deployed_nodes,
598
+ deploymentStatus: data.deployment_status
599
+ ? EventingFunctionDeploymentStatus.Deployed
600
+ : EventingFunctionDeploymentStatus.Undeployed,
601
+ processingStatus: data.processing_status
602
+ ? EventingFunctionProcessingStatus.Running
603
+ : EventingFunctionProcessingStatus.Paused,
604
+ });
605
+ }
606
+ }
607
+ exports.EventingFunctionState = EventingFunctionState;
608
+ /**
609
+ * Describes the current state of all eventing function.
610
+ *
611
+ * @category Management
612
+ */
613
+ class EventingState {
614
+ constructor(v) {
615
+ this.numEventingNodes = v.numEventingNodes;
616
+ this.functions = v.functions;
617
+ }
618
+ /**
619
+ * @internal
620
+ */
621
+ static _fromEvtData(data) {
622
+ return new EventingState({
623
+ numEventingNodes: data.num_eventing_nodes,
624
+ functions: data.apps.map((functionData) => EventingFunctionState._fromEvtData(functionData)),
625
+ });
626
+ }
627
+ }
628
+ exports.EventingState = EventingState;
629
+ /**
630
+ * EventingFunctionManager provides an interface for managing the
631
+ * eventing functions on the cluster.
632
+ * Volatile: This API is subject to change at any time.
633
+ *
634
+ * @category Management
635
+ */
636
+ class EventingFunctionManager {
637
+ /**
638
+ * @internal
639
+ */
640
+ constructor(cluster) {
641
+ this._cluster = cluster;
642
+ }
643
+ get _http() {
644
+ return new httpexecutor_1.HttpExecutor(this._cluster._getClusterConn());
645
+ }
646
+ /**
647
+ * Creates or updates an eventing function.
648
+ *
649
+ * @param functionDefinition The description of the eventing function to upsert.
650
+ * @param options Optional parameters for this operation.
651
+ * @param callback A node-style callback to be invoked after execution.
652
+ */
653
+ async upsertFunction(functionDefinition, options, callback) {
654
+ if (options instanceof Function) {
655
+ callback = arguments[1];
656
+ options = undefined;
657
+ }
658
+ if (!options) {
659
+ options = {};
660
+ }
661
+ const functionName = functionDefinition.name;
662
+ const parentSpan = options.parentSpan;
663
+ const timeout = options.timeout;
664
+ return utilities_1.PromiseHelper.wrapAsync(async () => {
665
+ const encodedData = EventingFunction._toEvtData(functionDefinition);
666
+ const res = await this._http.request({
667
+ type: httpexecutor_1.HttpServiceType.Eventing,
668
+ method: httpexecutor_1.HttpMethod.Post,
669
+ path: `/api/v1/functions/${functionName}`,
670
+ contentType: 'application/json',
671
+ body: JSON.stringify(encodedData),
672
+ parentSpan: parentSpan,
673
+ timeout: timeout,
674
+ });
675
+ if (res.statusCode !== 200) {
676
+ const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
677
+ const errText = res.body.toString().toLowerCase();
678
+ if (errText.includes('err_collection_missing')) {
679
+ throw new errors_1.CollectionNotFoundError(undefined, errCtx);
680
+ }
681
+ if (errText.includes('err_src_mb_same')) {
682
+ throw new errors_1.EventingFunctionIdenticalKeyspaceError(undefined, errCtx);
683
+ }
684
+ if (errText.includes('err_handler_compilation')) {
685
+ throw new errors_1.EventingFunctionCompilationFailureError(undefined, errCtx);
686
+ }
687
+ throw new errors_1.CouchbaseError('failed to upsert function', undefined, errCtx);
688
+ }
689
+ }, callback);
690
+ }
691
+ /**
692
+ * Deletes an eventing function.
693
+ *
694
+ * @param name The name of the eventing function to delete.
695
+ * @param options Optional parameters for this operation.
696
+ * @param callback A node-style callback to be invoked after execution.
697
+ */
698
+ async dropFunction(name, options, callback) {
699
+ if (options instanceof Function) {
700
+ callback = arguments[1];
701
+ options = undefined;
702
+ }
703
+ if (!options) {
704
+ options = {};
705
+ }
706
+ const functionName = name;
707
+ const parentSpan = options.parentSpan;
708
+ const timeout = options.timeout;
709
+ return utilities_1.PromiseHelper.wrapAsync(async () => {
710
+ const res = await this._http.request({
711
+ type: httpexecutor_1.HttpServiceType.Eventing,
712
+ method: httpexecutor_1.HttpMethod.Delete,
713
+ path: `/api/v1/functions/${functionName}`,
714
+ parentSpan: parentSpan,
715
+ timeout: timeout,
716
+ });
717
+ if (res.statusCode !== 200) {
718
+ const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
719
+ const errText = res.body.toString().toLowerCase();
720
+ if (errText.includes('err_app_not_found_ts')) {
721
+ throw new errors_1.EventingFunctionNotFoundError(undefined, errCtx);
722
+ }
723
+ if (errText.includes('err_app_not_deployed')) {
724
+ throw new errors_1.EventingFunctionNotDeployedError(undefined, errCtx);
725
+ }
726
+ if (errText.includes('err_app_not_undeployed')) {
727
+ throw new errors_1.EventingFunctionDeployedError(undefined, errCtx);
728
+ }
729
+ throw new errors_1.CouchbaseError('failed to drop function', undefined, errCtx);
730
+ }
731
+ }, callback);
732
+ }
733
+ /**
734
+ * Fetches all eventing functions.
735
+ *
736
+ * @param options Optional parameters for this operation.
737
+ * @param callback A node-style callback to be invoked after execution.
738
+ */
739
+ async getAllFunctions(options, callback) {
740
+ if (options instanceof Function) {
741
+ callback = arguments[0];
742
+ options = undefined;
743
+ }
744
+ if (!options) {
745
+ options = {};
746
+ }
747
+ const parentSpan = options.parentSpan;
748
+ const timeout = options.timeout;
749
+ return utilities_1.PromiseHelper.wrapAsync(async () => {
750
+ const res = await this._http.request({
751
+ type: httpexecutor_1.HttpServiceType.Eventing,
752
+ method: httpexecutor_1.HttpMethod.Get,
753
+ path: `/api/v1/functions`,
754
+ parentSpan: parentSpan,
755
+ timeout: timeout,
756
+ });
757
+ if (res.statusCode !== 200) {
758
+ const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
759
+ throw new errors_1.CouchbaseError('failed to get functions', undefined, errCtx);
760
+ }
761
+ const functionsData = JSON.parse(res.body.toString());
762
+ const functions = functionsData.map((functionData) => EventingFunction._fromEvtData(functionData));
763
+ return functions;
764
+ }, callback);
765
+ }
766
+ /**
767
+ * Fetches a specific eventing function.
768
+ *
769
+ * @param name The name of the eventing function to fetch.
770
+ * @param options Optional parameters for this operation.
771
+ * @param callback A node-style callback to be invoked after execution.
772
+ */
773
+ async getFunction(name, options, callback) {
774
+ if (options instanceof Function) {
775
+ callback = arguments[1];
776
+ options = undefined;
777
+ }
778
+ if (!options) {
779
+ options = {};
780
+ }
781
+ const functionName = name;
782
+ const parentSpan = options.parentSpan;
783
+ const timeout = options.timeout;
784
+ return utilities_1.PromiseHelper.wrapAsync(async () => {
785
+ const res = await this._http.request({
786
+ type: httpexecutor_1.HttpServiceType.Eventing,
787
+ method: httpexecutor_1.HttpMethod.Get,
788
+ path: `/api/v1/functions/${functionName}`,
789
+ parentSpan: parentSpan,
790
+ timeout: timeout,
791
+ });
792
+ if (res.statusCode !== 200) {
793
+ const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
794
+ const errText = res.body.toString().toLowerCase();
795
+ if (errText.includes('err_app_not_found_ts')) {
796
+ throw new errors_1.EventingFunctionNotFoundError(undefined, errCtx);
797
+ }
798
+ throw new errors_1.CouchbaseError('failed to get function', undefined, errCtx);
799
+ }
800
+ const functionData = JSON.parse(res.body.toString());
801
+ return EventingFunction._fromEvtData(functionData);
802
+ }, callback);
803
+ }
804
+ /**
805
+ * Deploys an eventing function.
806
+ *
807
+ * @param name The name of the eventing function to deploy.
808
+ * @param options Optional parameters for this operation.
809
+ * @param callback A node-style callback to be invoked after execution.
810
+ */
811
+ async deployFunction(name, options, callback) {
812
+ if (options instanceof Function) {
813
+ callback = arguments[1];
814
+ options = undefined;
815
+ }
816
+ if (!options) {
817
+ options = {};
818
+ }
819
+ const functionName = name;
820
+ const parentSpan = options.parentSpan;
821
+ const timeout = options.timeout;
822
+ return utilities_1.PromiseHelper.wrapAsync(async () => {
823
+ const res = await this._http.request({
824
+ type: httpexecutor_1.HttpServiceType.Eventing,
825
+ method: httpexecutor_1.HttpMethod.Post,
826
+ path: `/api/v1/functions/${functionName}/deploy`,
827
+ parentSpan: parentSpan,
828
+ timeout: timeout,
829
+ });
830
+ if (res.statusCode !== 200) {
831
+ const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
832
+ const errText = res.body.toString().toLowerCase();
833
+ if (errText.includes('err_app_not_found_ts')) {
834
+ throw new errors_1.EventingFunctionNotFoundError(undefined, errCtx);
835
+ }
836
+ if (errText.includes('err_app_not_bootstrapped')) {
837
+ throw new errors_1.EventingFunctionNotBootstrappedError(undefined, errCtx);
838
+ }
839
+ throw new errors_1.CouchbaseError('failed to deploy function', undefined, errCtx);
840
+ }
841
+ }, callback);
842
+ }
843
+ /**
844
+ * Undeploys an eventing function.
845
+ *
846
+ * @param name The name of the eventing function to undeploy.
847
+ * @param options Optional parameters for this operation.
848
+ * @param callback A node-style callback to be invoked after execution.
849
+ */
850
+ async undeployFunction(name, options, callback) {
851
+ if (options instanceof Function) {
852
+ callback = arguments[1];
853
+ options = undefined;
854
+ }
855
+ if (!options) {
856
+ options = {};
857
+ }
858
+ const functionName = name;
859
+ const parentSpan = options.parentSpan;
860
+ const timeout = options.timeout;
861
+ return utilities_1.PromiseHelper.wrapAsync(async () => {
862
+ const res = await this._http.request({
863
+ type: httpexecutor_1.HttpServiceType.Eventing,
864
+ method: httpexecutor_1.HttpMethod.Post,
865
+ path: `/api/v1/functions/${functionName}/undeploy`,
866
+ parentSpan: parentSpan,
867
+ timeout: timeout,
868
+ });
869
+ if (res.statusCode !== 200) {
870
+ const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
871
+ const errText = res.body.toString().toLowerCase();
872
+ if (errText.includes('err_app_not_found_ts')) {
873
+ throw new errors_1.EventingFunctionNotFoundError(undefined, errCtx);
874
+ }
875
+ if (errText.includes('err_app_not_deployed')) {
876
+ throw new errors_1.EventingFunctionNotDeployedError(undefined, errCtx);
877
+ }
878
+ throw new errors_1.CouchbaseError('failed to undeploy function', undefined, errCtx);
879
+ }
880
+ }, callback);
881
+ }
882
+ /**
883
+ * Pauses an eventing function.
884
+ *
885
+ * @param name The name of the eventing function to pause.
886
+ * @param options Optional parameters for this operation.
887
+ * @param callback A node-style callback to be invoked after execution.
888
+ */
889
+ async pauseFunction(name, options, callback) {
890
+ if (options instanceof Function) {
891
+ callback = arguments[1];
892
+ options = undefined;
893
+ }
894
+ if (!options) {
895
+ options = {};
896
+ }
897
+ const functionName = name;
898
+ const parentSpan = options.parentSpan;
899
+ const timeout = options.timeout;
900
+ return utilities_1.PromiseHelper.wrapAsync(async () => {
901
+ const res = await this._http.request({
902
+ type: httpexecutor_1.HttpServiceType.Eventing,
903
+ method: httpexecutor_1.HttpMethod.Post,
904
+ path: `/api/v1/functions/${functionName}/pause`,
905
+ parentSpan: parentSpan,
906
+ timeout: timeout,
907
+ });
908
+ if (res.statusCode !== 200) {
909
+ const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
910
+ const errText = res.body.toString().toLowerCase();
911
+ if (errText.includes('err_app_not_found_ts')) {
912
+ throw new errors_1.EventingFunctionNotFoundError(undefined, errCtx);
913
+ }
914
+ if (errText.includes('err_app_not_bootstrapped')) {
915
+ throw new errors_1.EventingFunctionNotBootstrappedError(undefined, errCtx);
916
+ }
917
+ throw new errors_1.CouchbaseError('failed to pause function', undefined, errCtx);
918
+ }
919
+ }, callback);
920
+ }
921
+ /**
922
+ * Resumes an eventing function.
923
+ *
924
+ * @param name The name of the eventing function to resume.
925
+ * @param options Optional parameters for this operation.
926
+ * @param callback A node-style callback to be invoked after execution.
927
+ */
928
+ async resumeFunction(name, options, callback) {
929
+ if (options instanceof Function) {
930
+ callback = arguments[1];
931
+ options = undefined;
932
+ }
933
+ if (!options) {
934
+ options = {};
935
+ }
936
+ const functionName = name;
937
+ const parentSpan = options.parentSpan;
938
+ const timeout = options.timeout;
939
+ return utilities_1.PromiseHelper.wrapAsync(async () => {
940
+ const res = await this._http.request({
941
+ type: httpexecutor_1.HttpServiceType.Eventing,
942
+ method: httpexecutor_1.HttpMethod.Post,
943
+ path: `/api/v1/functions/${functionName}/resume`,
944
+ parentSpan: parentSpan,
945
+ timeout: timeout,
946
+ });
947
+ if (res.statusCode !== 200) {
948
+ const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
949
+ const errText = res.body.toString().toLowerCase();
950
+ if (errText.includes('err_app_not_found_ts')) {
951
+ throw new errors_1.EventingFunctionNotFoundError(undefined, errCtx);
952
+ }
953
+ if (errText.includes('err_app_not_deployed')) {
954
+ throw new errors_1.EventingFunctionNotDeployedError(undefined, errCtx);
955
+ }
956
+ throw new errors_1.CouchbaseError('failed to resume function', undefined, errCtx);
957
+ }
958
+ }, callback);
959
+ }
960
+ /**
961
+ * Fetches the status of all eventing functions.
962
+ *
963
+ * @param options Optional parameters for this operation.
964
+ * @param callback A node-style callback to be invoked after execution.
965
+ */
966
+ async functionsStatus(options, callback) {
967
+ if (options instanceof Function) {
968
+ callback = arguments[0];
969
+ options = undefined;
970
+ }
971
+ if (!options) {
972
+ options = {};
973
+ }
974
+ const parentSpan = options.parentSpan;
975
+ const timeout = options.timeout;
976
+ return utilities_1.PromiseHelper.wrapAsync(async () => {
977
+ const res = await this._http.request({
978
+ type: httpexecutor_1.HttpServiceType.Eventing,
979
+ method: httpexecutor_1.HttpMethod.Get,
980
+ path: `/api/v1/status`,
981
+ parentSpan: parentSpan,
982
+ timeout: timeout,
983
+ });
984
+ if (res.statusCode !== 200) {
985
+ const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
986
+ throw new errors_1.CouchbaseError('failed to fetch functions status', undefined, errCtx);
987
+ }
988
+ const statusData = JSON.parse(res.body.toString());
989
+ return EventingState._fromEvtData(statusData);
990
+ }, callback);
991
+ }
992
+ }
993
+ exports.EventingFunctionManager = EventingFunctionManager;