couchbase 4.2.10 → 4.2.11

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 (79) hide show
  1. package/deps/couchbase-cxx-client/CMakeLists.txt +1 -0
  2. package/deps/couchbase-cxx-client/cmake/ThirdPartyDependencies.cmake +2 -0
  3. package/deps/couchbase-cxx-client/core/bucket.cxx +25 -10
  4. package/deps/couchbase-cxx-client/core/bucket.hxx +1 -0
  5. package/deps/couchbase-cxx-client/core/cluster.cxx +29 -3
  6. package/deps/couchbase-cxx-client/core/impl/collection.cxx +2 -2
  7. package/deps/couchbase-cxx-client/core/impl/query_index_manager.cxx +6 -6
  8. package/deps/couchbase-cxx-client/core/io/http_session_manager.hxx +7 -1
  9. package/deps/couchbase-cxx-client/core/io/mcbp_command.hxx +10 -0
  10. package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +35 -1
  11. package/deps/couchbase-cxx-client/core/io/mcbp_session.hxx +2 -0
  12. package/deps/couchbase-cxx-client/core/management/design_document.hxx +1 -1
  13. package/deps/couchbase-cxx-client/core/meta/features.hxx +16 -1
  14. package/deps/couchbase-cxx-client/core/operations/document_lookup_in_all_replicas.hxx +1 -1
  15. package/deps/couchbase-cxx-client/core/operations/document_lookup_in_any_replica.hxx +1 -1
  16. package/deps/couchbase-cxx-client/core/operations/document_query.cxx +2 -2
  17. package/deps/couchbase-cxx-client/core/operations/document_search.cxx +10 -10
  18. package/deps/couchbase-cxx-client/core/operations/document_view.cxx +3 -0
  19. package/deps/couchbase-cxx-client/core/operations/document_view.hxx +1 -0
  20. package/deps/couchbase-cxx-client/core/operations/management/query_index_create.cxx +24 -13
  21. package/deps/couchbase-cxx-client/core/operations/management/query_index_create.hxx +1 -1
  22. package/deps/couchbase-cxx-client/core/origin.cxx +14 -0
  23. package/deps/couchbase-cxx-client/core/origin.hxx +6 -0
  24. package/deps/couchbase-cxx-client/core/protocol/status.cxx +2 -0
  25. package/deps/couchbase-cxx-client/core/protocol/status.hxx +1 -0
  26. package/deps/couchbase-cxx-client/core/range_scan_load_balancer.cxx +141 -0
  27. package/deps/couchbase-cxx-client/core/range_scan_load_balancer.hxx +64 -0
  28. package/deps/couchbase-cxx-client/core/range_scan_orchestrator.cxx +224 -336
  29. package/deps/couchbase-cxx-client/core/range_scan_orchestrator.hxx +5 -6
  30. package/deps/couchbase-cxx-client/core/range_scan_orchestrator_options.hxx +6 -4
  31. package/deps/couchbase-cxx-client/core/scan_result.hxx +1 -11
  32. package/deps/couchbase-cxx-client/core/topology/capabilities.hxx +70 -1
  33. package/deps/couchbase-cxx-client/core/topology/capabilities_fmt.hxx +30 -2
  34. package/deps/couchbase-cxx-client/core/topology/configuration.hxx +1 -34
  35. package/deps/couchbase-cxx-client/core/topology/configuration_fmt.hxx +2 -2
  36. package/deps/couchbase-cxx-client/core/topology/configuration_json.hxx +43 -20
  37. package/deps/couchbase-cxx-client/core/transactions/internal/exceptions_internal.hxx +5 -0
  38. package/deps/couchbase-cxx-client/couchbase/bucket.hxx +2 -2
  39. package/deps/couchbase-cxx-client/couchbase/cluster.hxx +1 -1
  40. package/deps/couchbase-cxx-client/couchbase/collection.hxx +1 -0
  41. package/deps/couchbase-cxx-client/couchbase/collection_query_index_manager.hxx +80 -11
  42. package/deps/couchbase-cxx-client/couchbase/error_context.hxx +1 -0
  43. package/deps/couchbase-cxx-client/couchbase/fmt/key_value_status_code.hxx +3 -1
  44. package/deps/couchbase-cxx-client/couchbase/get_links_analytics_options.hxx +2 -2
  45. package/deps/couchbase-cxx-client/couchbase/key_value_status_code.hxx +1 -0
  46. package/deps/couchbase-cxx-client/couchbase/query_index_manager.hxx +6 -8
  47. package/deps/couchbase-cxx-client/couchbase/scope.hxx +1 -1
  48. package/deps/couchbase-cxx-client/couchbase/search_options.hxx +2 -2
  49. package/deps/couchbase-cxx-client/couchbase/search_result.hxx +1 -1
  50. package/deps/couchbase-cxx-client/couchbase/subdocument_error_context.hxx +1 -0
  51. package/deps/couchbase-cxx-client/couchbase/transactions/transaction_options.hxx +1 -1
  52. package/deps/couchbase-cxx-client/couchbase-sdk-cxx-black-duck-manifest.yaml +1 -0
  53. package/dist/binding.d.ts +24 -2
  54. package/dist/bindingutilities.d.ts +11 -3
  55. package/dist/bindingutilities.js +33 -7
  56. package/dist/couchbase.d.ts +1 -0
  57. package/dist/couchbase.js +1 -0
  58. package/dist/queryindexmanager.d.ts +4 -4
  59. package/dist/queryindexmanager.js +7 -7
  60. package/dist/scope.d.ts +21 -0
  61. package/dist/scope.js +34 -0
  62. package/dist/scopesearchindexmanager.d.ts +116 -0
  63. package/dist/scopesearchindexmanager.js +406 -0
  64. package/dist/sdspecs.js +10 -9
  65. package/dist/sdutils.d.ts +1 -0
  66. package/dist/sdutils.js +4 -0
  67. package/dist/searchexecutor.d.ts +3 -1
  68. package/dist/searchexecutor.js +9 -2
  69. package/dist/searchindexmanager.d.ts +58 -3
  70. package/dist/searchindexmanager.js +188 -104
  71. package/dist/viewexecutor.js +13 -9
  72. package/dist/viewindexmanager.d.ts +70 -7
  73. package/dist/viewindexmanager.js +236 -103
  74. package/dist/viewtypes.d.ts +26 -0
  75. package/dist/viewtypes.js +17 -1
  76. package/package.json +7 -7
  77. package/src/constants.cpp +1 -0
  78. package/src/jstocbpp_autogen.hpp +89 -7
  79. package/deps/couchbase-cxx-client/core/scan_options.hxx +0 -44
@@ -1,5 +1,7 @@
1
1
  import { Bucket } from './bucket';
2
2
  import { NodeCallback } from './utilities';
3
+ import { DesignDocumentNamespace } from './viewtypes';
4
+ import { CppManagementViewsDesignDocument, CppManagementViewsDesignDocumentView } from './binding';
3
5
  /**
4
6
  * Contains information about a view in a design document.
5
7
  *
@@ -9,19 +11,27 @@ export declare class DesignDocumentView {
9
11
  /**
10
12
  * The mapping function to use for this view.
11
13
  */
12
- map: string;
14
+ map: string | undefined;
13
15
  /**
14
16
  * The reduction function to use for this view.
15
17
  */
16
18
  reduce: string | undefined;
17
19
  constructor(data: {
18
- map: string;
20
+ map?: string;
19
21
  reduce?: string;
20
22
  });
21
23
  /**
22
24
  * @deprecated
23
25
  */
24
- constructor(map: string, reduce?: string);
26
+ constructor(map?: string, reduce?: string);
27
+ /**
28
+ * @internal
29
+ */
30
+ static _toCppData(name: string, data: DesignDocumentView): CppManagementViewsDesignDocumentView;
31
+ /**
32
+ * @internal
33
+ */
34
+ static _fromCppData(data: CppManagementViewsDesignDocumentView): DesignDocumentView;
25
35
  }
26
36
  /**
27
37
  * Contains information about a design document.
@@ -45,11 +55,21 @@ export declare class DesignDocument {
45
55
  views: {
46
56
  [viewName: string]: DesignDocumentView;
47
57
  };
58
+ /**
59
+ * The namespace for this design document.
60
+ */
61
+ namespace: DesignDocumentNamespace;
62
+ /**
63
+ * The revision of the design document.
64
+ */
65
+ rev: string | undefined;
48
66
  constructor(data: {
49
67
  name: string;
50
68
  views?: {
51
69
  [viewName: string]: DesignDocumentView;
52
70
  };
71
+ namespace?: DesignDocumentNamespace;
72
+ rev?: string;
53
73
  });
54
74
  /**
55
75
  * @deprecated
@@ -61,6 +81,14 @@ export declare class DesignDocument {
61
81
  * @internal
62
82
  */
63
83
  static _fromNsData(ddocName: string, ddocData: any): DesignDocument;
84
+ /**
85
+ * @internal
86
+ */
87
+ static _toCppData(data: DesignDocument, namespace: DesignDocumentNamespace): CppManagementViewsDesignDocument;
88
+ /**
89
+ * @internal
90
+ */
91
+ static _fromCppData(ddoc: CppManagementViewsDesignDocument): DesignDocument;
64
92
  }
65
93
  /**
66
94
  * @category Management
@@ -119,10 +147,6 @@ export declare class ViewIndexManager {
119
147
  * @internal
120
148
  */
121
149
  constructor(bucket: Bucket);
122
- /**
123
- * @internal
124
- */
125
- private get _http();
126
150
  /**
127
151
  * @internal
128
152
  */
@@ -132,32 +156,71 @@ export declare class ViewIndexManager {
132
156
  *
133
157
  * @param options Optional parameters for this operation.
134
158
  * @param callback A node-style callback to be invoked after execution.
159
+ * @deprecated
135
160
  */
136
161
  getAllDesignDocuments(options?: GetAllDesignDocumentOptions, callback?: NodeCallback<DesignDocument[]>): Promise<DesignDocument[]>;
162
+ /**
163
+ * Returns a list of all the design documents in this bucket.
164
+ *
165
+ * @param namespace The DesignDocument namespace.
166
+ * @param options Optional parameters for this operation.
167
+ * @param callback A node-style callback to be invoked after execution.
168
+ */
169
+ getAllDesignDocuments(namespace: DesignDocumentNamespace, options?: GetAllDesignDocumentOptions, callback?: NodeCallback<DesignDocument[]>): Promise<DesignDocument[]>;
137
170
  /**
138
171
  * Returns the specified design document.
139
172
  *
140
173
  * @param designDocName The name of the design document to fetch.
141
174
  * @param options Optional parameters for this operation.
142
175
  * @param callback A node-style callback to be invoked after execution.
176
+ * @deprecated
143
177
  */
144
178
  getDesignDocument(designDocName: string, options?: GetDesignDocumentOptions, callback?: NodeCallback<DesignDocument>): Promise<DesignDocument>;
179
+ /**
180
+ * Returns the specified design document.
181
+ *
182
+ * @param designDocName The name of the design document to fetch.
183
+ * @param namespace The DesignDocument namespace.
184
+ * @param options Optional parameters for this operation.
185
+ * @param callback A node-style callback to be invoked after execution.
186
+ */
187
+ getDesignDocument(designDocName: string, namespace: DesignDocumentNamespace, options?: GetDesignDocumentOptions, callback?: NodeCallback<DesignDocument>): Promise<DesignDocument>;
145
188
  /**
146
189
  * Creates or updates a design document.
147
190
  *
148
191
  * @param designDoc The DesignDocument to upsert.
149
192
  * @param options Optional parameters for this operation.
150
193
  * @param callback A node-style callback to be invoked after execution.
194
+ * @deprecated
151
195
  */
152
196
  upsertDesignDocument(designDoc: DesignDocument, options?: UpsertDesignDocumentOptions, callback?: NodeCallback<void>): Promise<void>;
197
+ /**
198
+ * Creates or updates a design document.
199
+ *
200
+ * @param designDoc The DesignDocument to upsert.
201
+ * @param namespace The DesignDocument namespace.
202
+ * @param options Optional parameters for this operation.
203
+ * @param callback A node-style callback to be invoked after execution.
204
+ */
205
+ upsertDesignDocument(designDoc: DesignDocument, namespace?: DesignDocumentNamespace, options?: UpsertDesignDocumentOptions, callback?: NodeCallback<void>): Promise<void>;
153
206
  /**
154
207
  * Drops an existing design document.
155
208
  *
156
209
  * @param designDocName The name of the design document to drop.
157
210
  * @param options Optional parameters for this operation.
158
211
  * @param callback A node-style callback to be invoked after execution.
212
+ * @deprecated
159
213
  */
160
214
  dropDesignDocument(designDocName: string, options?: DropDesignDocumentOptions, callback?: NodeCallback<void>): Promise<void>;
215
+ /**
216
+ * Drops an existing design document.
217
+ *
218
+ * @param designDocName The name of the design document to drop.
219
+ * @param namespace The DesignDocument namespace.
220
+ * @param options Optional parameters for this operation.
221
+ * @param callback A node-style callback to be invoked after execution.
222
+ */
223
+ dropDesignDocument(designDocName: string, namespace: DesignDocumentNamespace, options?: DropDesignDocumentOptions, callback?: NodeCallback<void>): Promise<void>;
161
224
  /**
162
225
  * Publishes a development design document to be a production design document.
163
226
  * It does this by fetching the design document by the passed name with `dev_`
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ViewIndexManager = exports.DesignDocument = exports.DesignDocumentView = void 0;
4
- const errors_1 = require("./errors");
5
- const httpexecutor_1 = require("./httpexecutor");
6
4
  const utilities_1 = require("./utilities");
5
+ const viewtypes_1 = require("./viewtypes");
6
+ const bindingutilities_1 = require("./bindingutilities");
7
7
  /**
8
8
  * Contains information about a view in a design document.
9
9
  *
@@ -27,6 +27,25 @@ class DesignDocumentView {
27
27
  this.map = data.map;
28
28
  this.reduce = data.reduce;
29
29
  }
30
+ /**
31
+ * @internal
32
+ */
33
+ static _toCppData(name, data) {
34
+ return {
35
+ name: name,
36
+ map: data.map,
37
+ reduce: data.reduce,
38
+ };
39
+ }
40
+ /**
41
+ * @internal
42
+ */
43
+ static _fromCppData(data) {
44
+ return new DesignDocumentView({
45
+ map: data.map,
46
+ reduce: data.reduce,
47
+ });
48
+ }
30
49
  }
31
50
  exports.DesignDocumentView = DesignDocumentView;
32
51
  /**
@@ -59,6 +78,8 @@ class DesignDocument {
59
78
  }
60
79
  this.name = data.name;
61
80
  this.views = data.views || {};
81
+ this.namespace = data.namespace || viewtypes_1.DesignDocumentNamespace.Production;
82
+ this.rev = data.rev;
62
83
  }
63
84
  /**
64
85
  * @internal
@@ -74,6 +95,36 @@ class DesignDocument {
74
95
  }
75
96
  return new DesignDocument({ name: ddocName, views: views });
76
97
  }
98
+ /**
99
+ * @internal
100
+ */
101
+ static _toCppData(data, namespace) {
102
+ const cppView = {};
103
+ for (const [k, v] of Object.entries(data.views)) {
104
+ cppView[k] = DesignDocumentView._toCppData(k, v);
105
+ }
106
+ return {
107
+ rev: data.rev,
108
+ name: data.name,
109
+ ns: (0, bindingutilities_1.designDocumentNamespaceToCpp)(namespace),
110
+ views: cppView,
111
+ };
112
+ }
113
+ /**
114
+ * @internal
115
+ */
116
+ static _fromCppData(ddoc) {
117
+ const views = {};
118
+ for (const [viewName, viewData] of Object.entries(ddoc.views)) {
119
+ views[viewName] = DesignDocumentView._fromCppData(viewData);
120
+ }
121
+ return new DesignDocument({
122
+ name: ddoc.name,
123
+ views: views,
124
+ namespace: (0, bindingutilities_1.designDocumentNamespaceFromCpp)(ddoc.ns),
125
+ rev: ddoc.rev,
126
+ });
127
+ }
77
128
  }
78
129
  exports.DesignDocument = DesignDocument;
79
130
  /**
@@ -89,12 +140,6 @@ class ViewIndexManager {
89
140
  constructor(bucket) {
90
141
  this._bucket = bucket;
91
142
  }
92
- /**
93
- * @internal
94
- */
95
- get _http() {
96
- return new httpexecutor_1.HttpExecutor(this._bucket.conn);
97
- }
98
143
  /**
99
144
  * @internal
100
145
  */
@@ -102,142 +147,232 @@ class ViewIndexManager {
102
147
  return this._bucket.cluster;
103
148
  }
104
149
  /**
105
- * Returns a list of all the design documents in this bucket.
106
- *
107
- * @param options Optional parameters for this operation.
108
- * @param callback A node-style callback to be invoked after execution.
150
+ * @internal
109
151
  */
110
- async getAllDesignDocuments(options, callback) {
111
- if (options instanceof Function) {
112
- callback = arguments[0];
152
+ async getAllDesignDocuments() {
153
+ let namespace;
154
+ let options;
155
+ let callback;
156
+ // deprecated path: options and maybe callback passed in
157
+ if (typeof arguments[0] === 'object') {
158
+ namespace = undefined;
159
+ options = arguments[0];
160
+ callback = arguments[1];
161
+ }
162
+ else if (arguments[0] instanceof Function) {
163
+ // deprecated path: no options, only callback passed in
164
+ namespace = undefined;
113
165
  options = undefined;
166
+ callback = arguments[0];
167
+ }
168
+ else {
169
+ // either no args passed in or desired path (namespace is 1st arg)
170
+ namespace = arguments[0];
171
+ // still need to handle possible no options, but callback passed in
172
+ if (arguments[1] instanceof Function) {
173
+ callback = arguments[1];
174
+ options = undefined;
175
+ }
176
+ else {
177
+ options = arguments[1];
178
+ callback = arguments[2];
179
+ }
114
180
  }
115
181
  if (!options) {
116
182
  options = {};
117
183
  }
118
184
  const timeout = options.timeout || this._cluster.managementTimeout;
119
- return utilities_1.PromiseHelper.wrapAsync(async () => {
120
- const bucketName = this._bucket.name;
121
- const res = await this._http.request({
122
- type: httpexecutor_1.HttpServiceType.Management,
123
- method: httpexecutor_1.HttpMethod.Get,
124
- path: `/pools/default/buckets/${bucketName}/ddocs`,
185
+ const ns = namespace !== null && namespace !== void 0 ? namespace : viewtypes_1.DesignDocumentNamespace.Production;
186
+ return utilities_1.PromiseHelper.wrap((wrapCallback) => {
187
+ this._cluster.conn.managementViewIndexGetAll({
188
+ bucket_name: this._bucket.name,
189
+ ns: (0, bindingutilities_1.designDocumentNamespaceToCpp)(ns),
125
190
  timeout: timeout,
191
+ }, (cppErr, resp) => {
192
+ const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
193
+ if (err) {
194
+ return wrapCallback(err, null);
195
+ }
196
+ const ddocs = [];
197
+ for (const ddoc of resp.design_documents) {
198
+ ddocs.push(DesignDocument._fromCppData(ddoc));
199
+ }
200
+ wrapCallback(null, ddocs);
126
201
  });
127
- if (res.statusCode !== 200) {
128
- const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
129
- throw new errors_1.CouchbaseError('failed to get design documents', undefined, errCtx);
130
- }
131
- const ddocsData = JSON.parse(res.body.toString());
132
- const ddocs = ddocsData.rows.map((ddocData) => {
133
- const ddocName = ddocData.doc.meta.id.substr(8);
134
- return DesignDocument._fromNsData(ddocName, ddocData.doc.json);
135
- });
136
- return ddocs;
137
202
  }, callback);
138
203
  }
139
204
  /**
140
- * Returns the specified design document.
141
- *
142
- * @param designDocName The name of the design document to fetch.
143
- * @param options Optional parameters for this operation.
144
- * @param callback A node-style callback to be invoked after execution.
205
+ * @internal
145
206
  */
146
- async getDesignDocument(designDocName, options, callback) {
147
- if (options instanceof Function) {
148
- callback = arguments[1];
207
+ async getDesignDocument() {
208
+ let designDocName = arguments[0];
209
+ let namespace;
210
+ let options;
211
+ let callback;
212
+ // deprecated path: options and maybe callback passed in
213
+ if (typeof arguments[1] === 'object') {
214
+ namespace = undefined;
215
+ options = arguments[1];
216
+ callback = arguments[2];
217
+ }
218
+ else if (arguments[1] instanceof Function) {
219
+ // deprecated path: no options, only callback passed in
220
+ namespace = undefined;
149
221
  options = undefined;
222
+ callback = arguments[1];
223
+ }
224
+ else {
225
+ // either no other args passed in or desired path (namespace is 2nd arg)
226
+ namespace = arguments[1];
227
+ // still need to handle possible no options, but callback passed in
228
+ if (arguments[2] instanceof Function) {
229
+ callback = arguments[2];
230
+ options = undefined;
231
+ }
232
+ else {
233
+ options = arguments[2];
234
+ callback = arguments[3];
235
+ }
150
236
  }
151
237
  if (!options) {
152
238
  options = {};
153
239
  }
154
240
  const timeout = options.timeout || this._cluster.managementTimeout;
155
- return utilities_1.PromiseHelper.wrapAsync(async () => {
156
- const bucketName = this._bucket.name;
157
- const res = await this._http.request({
158
- type: httpexecutor_1.HttpServiceType.Views,
159
- method: httpexecutor_1.HttpMethod.Get,
160
- path: `/${bucketName}/_design/${designDocName}`,
241
+ // for compatibility with older SDK versions (i.e. deprecated getDesignDocument())
242
+ if (designDocName.startsWith('dev_')) {
243
+ namespace = viewtypes_1.DesignDocumentNamespace.Development;
244
+ designDocName = designDocName.substring(4);
245
+ }
246
+ const ns = namespace !== null && namespace !== void 0 ? namespace : viewtypes_1.DesignDocumentNamespace.Production;
247
+ return utilities_1.PromiseHelper.wrap((wrapCallback) => {
248
+ this._cluster.conn.managementViewIndexGet({
249
+ bucket_name: this._bucket.name,
250
+ document_name: designDocName,
251
+ ns: (0, bindingutilities_1.designDocumentNamespaceToCpp)(ns),
161
252
  timeout: timeout,
162
- });
163
- if (res.statusCode !== 200) {
164
- const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
165
- if (res.statusCode === 404) {
166
- throw new errors_1.DesignDocumentNotFoundError(undefined, errCtx);
253
+ }, (cppErr, resp) => {
254
+ const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
255
+ if (err) {
256
+ return wrapCallback(err, null);
167
257
  }
168
- throw new errors_1.CouchbaseError('failed to get the design document', undefined, errCtx);
169
- }
170
- const ddocData = JSON.parse(res.body.toString());
171
- return DesignDocument._fromNsData(designDocName, ddocData);
258
+ const ddoc = DesignDocument._fromCppData(resp.document);
259
+ wrapCallback(null, ddoc);
260
+ });
172
261
  }, callback);
173
262
  }
174
263
  /**
175
- * Creates or updates a design document.
176
- *
177
- * @param designDoc The DesignDocument to upsert.
178
- * @param options Optional parameters for this operation.
179
- * @param callback A node-style callback to be invoked after execution.
264
+ * @internal
180
265
  */
181
- async upsertDesignDocument(designDoc, options, callback) {
182
- if (options instanceof Function) {
183
- callback = arguments[1];
266
+ async upsertDesignDocument() {
267
+ const designDoc = arguments[0];
268
+ let namespace;
269
+ let options;
270
+ let callback;
271
+ // deprecated path: options and maybe callback passed in
272
+ if (typeof arguments[1] === 'object') {
273
+ namespace = undefined;
274
+ options = arguments[1];
275
+ callback = arguments[2];
276
+ }
277
+ else if (arguments[1] instanceof Function) {
278
+ // deprecated path: no options, only callback passed in
279
+ namespace = undefined;
184
280
  options = undefined;
281
+ callback = arguments[1];
282
+ }
283
+ else {
284
+ // either no other args passed in or desired path (namespace is 2nd arg)
285
+ namespace = arguments[1];
286
+ // still need to handle possible no options, but callback passed in
287
+ if (arguments[2] instanceof Function) {
288
+ callback = arguments[2];
289
+ options = undefined;
290
+ }
291
+ else {
292
+ options = arguments[2];
293
+ callback = arguments[3];
294
+ }
185
295
  }
186
296
  if (!options) {
187
297
  options = {};
188
298
  }
189
299
  const timeout = options.timeout || this._cluster.managementTimeout;
190
- return utilities_1.PromiseHelper.wrapAsync(async () => {
191
- const bucketName = this._bucket.name;
192
- const designDocData = {
193
- views: designDoc.views,
194
- };
195
- const encodedData = JSON.stringify(designDocData);
196
- const res = await this._http.request({
197
- type: httpexecutor_1.HttpServiceType.Views,
198
- method: httpexecutor_1.HttpMethod.Put,
199
- path: `/${bucketName}/_design/${designDoc.name}`,
200
- contentType: 'application/json',
201
- body: encodedData,
300
+ // for compatibility with older SDK versions (i.e. deprecated upsertDesignDocument())
301
+ if (designDoc.name.startsWith('dev_')) {
302
+ namespace = viewtypes_1.DesignDocumentNamespace.Development;
303
+ designDoc.name = designDoc.name.substring(4);
304
+ }
305
+ const ns = namespace !== null && namespace !== void 0 ? namespace : viewtypes_1.DesignDocumentNamespace.Production;
306
+ return utilities_1.PromiseHelper.wrap((wrapCallback) => {
307
+ this._cluster.conn.managementViewIndexUpsert({
308
+ bucket_name: this._bucket.name,
309
+ document: DesignDocument._toCppData(designDoc, ns),
202
310
  timeout: timeout,
311
+ }, (cppErr) => {
312
+ const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
313
+ if (err) {
314
+ return wrapCallback(err, null);
315
+ }
316
+ wrapCallback(err);
203
317
  });
204
- if (res.statusCode !== 201) {
205
- const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
206
- throw new errors_1.CouchbaseError('failed to upsert the design document', undefined, errCtx);
207
- }
208
318
  }, callback);
209
319
  }
210
320
  /**
211
- * Drops an existing design document.
212
- *
213
- * @param designDocName The name of the design document to drop.
214
- * @param options Optional parameters for this operation.
215
- * @param callback A node-style callback to be invoked after execution.
321
+ * @internal
216
322
  */
217
- async dropDesignDocument(designDocName, options, callback) {
218
- if (options instanceof Function) {
219
- callback = arguments[1];
323
+ async dropDesignDocument() {
324
+ let designDocName = arguments[0];
325
+ let namespace;
326
+ let options;
327
+ let callback;
328
+ // deprecated path: options and maybe callback passed in
329
+ if (typeof arguments[1] === 'object') {
330
+ namespace = undefined;
331
+ options = arguments[1];
332
+ callback = arguments[2];
333
+ }
334
+ else if (arguments[1] instanceof Function) {
335
+ // deprecated path: no options, only callback passed in
336
+ namespace = undefined;
220
337
  options = undefined;
338
+ callback = arguments[1];
339
+ }
340
+ else {
341
+ // either no other args passed in or desired path (namespace is 2nd arg)
342
+ namespace = arguments[1];
343
+ // still need to handle possible no options, but callback passed in
344
+ if (arguments[2] instanceof Function) {
345
+ callback = arguments[2];
346
+ options = undefined;
347
+ }
348
+ else {
349
+ options = arguments[2];
350
+ callback = arguments[3];
351
+ }
221
352
  }
222
353
  if (!options) {
223
354
  options = {};
224
355
  }
225
356
  const timeout = options.timeout || this._cluster.managementTimeout;
226
- return utilities_1.PromiseHelper.wrapAsync(async () => {
227
- const bucketName = this._bucket.name;
228
- const res = await this._http.request({
229
- type: httpexecutor_1.HttpServiceType.Views,
230
- method: httpexecutor_1.HttpMethod.Delete,
231
- path: `/${bucketName}/_design/${designDocName}`,
357
+ // for compatibility with older SDK versions (i.e. deprecated dropDesignDocument())
358
+ if (designDocName.startsWith('dev_')) {
359
+ namespace = viewtypes_1.DesignDocumentNamespace.Development;
360
+ designDocName = designDocName.substring(4);
361
+ }
362
+ const ns = namespace !== null && namespace !== void 0 ? namespace : viewtypes_1.DesignDocumentNamespace.Production;
363
+ return utilities_1.PromiseHelper.wrap((wrapCallback) => {
364
+ this._cluster.conn.managementViewIndexDrop({
365
+ bucket_name: this._bucket.name,
366
+ document_name: designDocName,
367
+ ns: (0, bindingutilities_1.designDocumentNamespaceToCpp)(ns),
232
368
  timeout: timeout,
233
- });
234
- if (res.statusCode !== 200) {
235
- const errCtx = httpexecutor_1.HttpExecutor.errorContextFromResponse(res);
236
- if (res.statusCode === 404) {
237
- throw new errors_1.DesignDocumentNotFoundError(undefined, errCtx);
369
+ }, (cppErr) => {
370
+ const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
371
+ if (err) {
372
+ return wrapCallback(err, null);
238
373
  }
239
- throw new errors_1.CouchbaseError('failed to drop the design document', undefined, errCtx);
240
- }
374
+ wrapCallback(err);
375
+ });
241
376
  }, callback);
242
377
  }
243
378
  /**
@@ -261,12 +396,10 @@ class ViewIndexManager {
261
396
  const timeout = options.timeout || this._cluster.managementTimeout;
262
397
  const timer = new utilities_1.CompoundTimeout(timeout);
263
398
  return utilities_1.PromiseHelper.wrapAsync(async () => {
264
- const designDoc = await this.getDesignDocument(`dev_${designDocName}`, {
399
+ const designDoc = await this.getDesignDocument(designDocName, viewtypes_1.DesignDocumentNamespace.Development, {
265
400
  timeout: timer.left(),
266
401
  });
267
- // Replace the name without the `dev_` prefix on it.
268
- designDoc.name = designDocName;
269
- await this.upsertDesignDocument(designDoc, {
402
+ await this.upsertDesignDocument(designDoc, viewtypes_1.DesignDocumentNamespace.Production, {
270
403
  timeout: timer.left(),
271
404
  });
272
405
  }, callback);
@@ -69,6 +69,21 @@ export declare class ViewRow<TValue = any, TKey = any> {
69
69
  */
70
70
  constructor(data: ViewRow);
71
71
  }
72
+ /**
73
+ * Specifies the namespace for the associated Design Document.
74
+ *
75
+ * @category Views
76
+ */
77
+ export declare enum DesignDocumentNamespace {
78
+ /**
79
+ * Indicates that the Design Document namespace is within the development environment.
80
+ */
81
+ Development = "development",
82
+ /**
83
+ * Indicates that the Design Document namespace is within the producion environment.
84
+ */
85
+ Production = "production"
86
+ }
72
87
  /**
73
88
  * Represents the various scan consistency options that are available when
74
89
  * querying against the views service.
@@ -270,4 +285,15 @@ export interface ViewQueryOptions {
270
285
  * @deprecated Use {@link ViewQueryOptions.onError} instead.
271
286
  */
272
287
  on_error?: ViewErrorMode;
288
+ /**
289
+ * Specifies any additional parameters which should be passed to the view engine
290
+ * when executing the view query.
291
+ */
292
+ raw?: {
293
+ [key: string]: string;
294
+ };
295
+ /**
296
+ * Specifies the design document namespace to use when executing the view query.
297
+ */
298
+ namespace?: DesignDocumentNamespace;
273
299
  }
package/dist/viewtypes.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ViewErrorMode = exports.ViewOrdering = exports.ViewScanConsistency = exports.ViewRow = exports.ViewMetaData = exports.ViewResult = void 0;
3
+ exports.ViewErrorMode = exports.ViewOrdering = exports.ViewScanConsistency = exports.DesignDocumentNamespace = exports.ViewRow = exports.ViewMetaData = exports.ViewResult = void 0;
4
4
  /**
5
5
  * Contains the results of a view query.
6
6
  *
@@ -56,6 +56,22 @@ class ViewRow {
56
56
  }
57
57
  }
58
58
  exports.ViewRow = ViewRow;
59
+ /**
60
+ * Specifies the namespace for the associated Design Document.
61
+ *
62
+ * @category Views
63
+ */
64
+ var DesignDocumentNamespace;
65
+ (function (DesignDocumentNamespace) {
66
+ /**
67
+ * Indicates that the Design Document namespace is within the development environment.
68
+ */
69
+ DesignDocumentNamespace["Development"] = "development";
70
+ /**
71
+ * Indicates that the Design Document namespace is within the producion environment.
72
+ */
73
+ DesignDocumentNamespace["Production"] = "production";
74
+ })(DesignDocumentNamespace || (exports.DesignDocumentNamespace = DesignDocumentNamespace = {}));
59
75
  /**
60
76
  * Represents the various scan consistency options that are available when
61
77
  * querying against the views service.