couchbase 3.2.0 → 3.2.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +24 -18
- package/binding.gyp +88 -85
- package/deps/lcb/CMakeLists.txt +1 -1
- package/deps/lcb/CONTRIBUTING.md +1 -1
- package/deps/lcb/README.markdown +2 -2
- package/deps/lcb/RELEASE_NOTES.markdown +99 -14
- package/deps/lcb/cmake/Modules/GetVersionInfo.cmake +1 -1
- package/deps/lcb/contrib/cbsasl/src/scram-sha/scram_utils.cc +22 -26
- package/deps/lcb/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +20 -7
- package/deps/lcb/doc/Doxyfile +1 -1
- package/deps/lcb/example/CMakeLists.txt +4 -4
- package/deps/lcb/example/libuvdirect/main.c +39 -12
- package/deps/lcb/example/minimal/durability.cc +149 -0
- package/deps/lcb/example/minimal/query.c +11 -9
- package/deps/lcb/gyp_config/common/libcouchbase/configuration.h +3 -3
- package/deps/lcb/gyp_config/linux/arm64/config.h +243 -0
- package/deps/lcb/include/libcouchbase/couchbase.h +80 -5
- package/deps/lcb/include/libcouchbase/error.h +2 -0
- package/deps/lcb/include/libcouchbase/ixmgmt.h +15 -10
- package/deps/lcb/include/libcouchbase/tracing.h +2 -2
- package/deps/lcb/include/memcached/protocol_binary.h +21 -0
- package/deps/lcb/libcouchbase.gyp +347 -349
- package/deps/lcb/packaging/deb/control +1 -1
- package/deps/lcb/src/analytics/analytics_handle.cc +13 -5
- package/deps/lcb/src/analytics/analytics_handle.hh +29 -0
- package/deps/lcb/src/bootstrap.cc +6 -3
- package/deps/lcb/src/capi/cmd_analytics.cc +12 -1
- package/deps/lcb/src/capi/cmd_analytics.hh +30 -0
- package/deps/lcb/src/capi/cmd_counter.hh +23 -0
- package/deps/lcb/src/capi/cmd_exists.hh +24 -1
- package/deps/lcb/src/capi/cmd_get.hh +22 -0
- package/deps/lcb/src/capi/cmd_get_replica.hh +23 -0
- package/deps/lcb/src/capi/cmd_http.hh +7 -0
- package/deps/lcb/src/capi/cmd_query.cc +11 -1
- package/deps/lcb/src/capi/cmd_query.hh +31 -0
- package/deps/lcb/src/capi/cmd_remove.hh +23 -0
- package/deps/lcb/src/capi/cmd_search.cc +6 -0
- package/deps/lcb/src/capi/cmd_search.hh +23 -0
- package/deps/lcb/src/capi/cmd_store.hh +33 -21
- package/deps/lcb/src/capi/cmd_subdoc.hh +35 -0
- package/deps/lcb/src/capi/cmd_touch.hh +23 -0
- package/deps/lcb/src/capi/cmd_unlock.hh +23 -0
- package/deps/lcb/src/capi/cmd_view.hh +6 -0
- package/deps/lcb/src/capi/collection_qualifier.hh +2 -2
- package/deps/lcb/src/cntl.cc +45 -11
- package/deps/lcb/src/crypto.cc +2 -2
- package/deps/lcb/src/dns-srv.cc +5 -3
- package/deps/lcb/src/errmap.cc +5 -9
- package/deps/lcb/src/errmap.h +7 -3
- package/deps/lcb/src/handler.cc +24 -18
- package/deps/lcb/src/hostlist.h +2 -2
- package/deps/lcb/src/http/http-priv.h +2 -2
- package/deps/lcb/src/http/http.cc +5 -2
- package/deps/lcb/src/instance.cc +20 -11
- package/deps/lcb/src/internal.h +9 -0
- package/deps/lcb/src/lcbio/connect.cc +14 -2
- package/deps/lcb/src/lcbio/connect.h +2 -2
- package/deps/lcb/src/lcbio/ctx.cc +4 -2
- package/deps/lcb/src/lcbio/ioutils.cc +9 -10
- package/deps/lcb/src/lcbio/manager.cc +1 -1
- package/deps/lcb/src/mcserver/mcserver.cc +9 -6
- package/deps/lcb/src/mcserver/negotiate.cc +39 -17
- package/deps/lcb/src/n1ql/ixmgmt.cc +1 -2
- package/deps/lcb/src/n1ql/query_handle.cc +41 -19
- package/deps/lcb/src/n1ql/query_handle.hh +28 -1
- package/deps/lcb/src/operations/counter.cc +18 -5
- package/deps/lcb/src/operations/exists.cc +25 -4
- package/deps/lcb/src/operations/get.cc +39 -19
- package/deps/lcb/src/operations/get_replica.cc +28 -8
- package/deps/lcb/src/operations/observe.cc +1 -1
- package/deps/lcb/src/operations/ping.cc +8 -8
- package/deps/lcb/src/operations/pktfwd.cc +2 -1
- package/deps/lcb/src/operations/remove.cc +39 -22
- package/deps/lcb/src/operations/store.cc +18 -5
- package/deps/lcb/src/operations/subdoc.cc +18 -6
- package/deps/lcb/src/operations/touch.cc +34 -16
- package/deps/lcb/src/operations/unlock.cc +24 -5
- package/deps/lcb/src/packetutils.h +3 -2
- package/deps/lcb/src/retryq.cc +24 -5
- package/deps/lcb/src/search/search.cc +1 -0
- package/deps/lcb/src/search/search_handle.cc +30 -8
- package/deps/lcb/src/search/search_handle.hh +29 -0
- package/deps/lcb/src/settings.cc +1 -1
- package/deps/lcb/src/ssl/ssl_common.c +6 -7
- package/deps/lcb/src/tracing/span.cc +47 -14
- package/deps/lcb/src/tracing/tracer.cc +11 -2
- package/deps/lcb/src/tracing/tracing-internal.h +105 -93
- package/deps/lcb/src/utilities.cc +43 -0
- package/deps/lcb/src/utilities.h +53 -0
- package/deps/lcb/src/vbucket/vbucket.c +34 -33
- package/deps/lcb/src/views/view_handle.cc +13 -5
- package/deps/lcb/src/views/view_handle.hh +29 -0
- package/deps/lcb/tests/CMakeLists.txt +21 -0
- package/deps/lcb/tests/basic/t_ctlcodes.cc +24 -3
- package/deps/lcb/tests/basic/t_jsparse.cc +8 -0
- package/deps/lcb/tests/basic/t_n1qlstrings.cc +73 -0
- package/deps/lcb/tests/iotests/mock-environment.cc +30 -1
- package/deps/lcb/tests/iotests/mock-environment.h +49 -0
- package/deps/lcb/tests/iotests/mock-unit-test.cc +104 -6
- package/deps/lcb/tests/iotests/mock-unit-test.h +34 -0
- package/deps/lcb/tests/iotests/t_collections.cc +1 -1
- package/deps/lcb/tests/iotests/t_confmon.cc +4 -2
- package/deps/lcb/tests/iotests/t_get.cc +109 -7
- package/deps/lcb/tests/iotests/t_http.cc +9 -4
- package/deps/lcb/tests/iotests/t_lock.cc +18 -0
- package/deps/lcb/tests/iotests/t_mutate.cc +157 -63
- package/deps/lcb/tests/iotests/t_n1ql.cc +330 -33
- package/deps/lcb/tests/iotests/t_views.cc +1 -0
- package/deps/lcb/tests/iotests/testutil.cc +168 -0
- package/deps/lcb/tests/iotests/testutil.h +116 -0
- package/deps/lcb/tests/mocksupport/procutil.c +32 -28
- package/deps/lcb/tests/mocksupport/server.c +0 -1
- package/deps/lcb/tests/mocksupport/timeout.c +2 -2
- package/deps/lcb/tools/cbc.cc +7 -0
- package/dist/analyticsindexmanager.js +512 -524
- package/dist/binding.d.ts +3 -0
- package/dist/bindingutilities.js +4 -0
- package/dist/bucket.js +1 -1
- package/dist/bucketmanager.d.ts +31 -1
- package/dist/bucketmanager.js +194 -186
- package/dist/cluster.d.ts +7 -0
- package/dist/cluster.js +48 -38
- package/dist/collection.js +11 -17
- package/dist/collectionmanager.js +181 -197
- package/dist/connection.d.ts +3 -1
- package/dist/connection.js +27 -16
- package/dist/couchbase.d.ts +1 -0
- package/dist/couchbase.js +3 -13
- package/dist/datastructures.js +239 -310
- package/dist/diagnosticsexecutor.js +70 -85
- package/dist/errors.d.ts +70 -0
- package/dist/errors.js +96 -2
- package/dist/eventingfunctionmanager.d.ts +804 -0
- package/dist/eventingfunctionmanager.js +993 -0
- package/dist/httpexecutor.d.ts +2 -1
- package/dist/httpexecutor.js +30 -37
- package/dist/queryindexmanager.js +240 -266
- package/dist/scope.js +10 -4
- package/dist/sdspecs.d.ts +1 -1
- package/dist/searchexecutor.js +3 -0
- package/dist/searchindexmanager.js +240 -271
- package/dist/searchquery.d.ts +17 -0
- package/dist/searchquery.js +22 -1
- package/dist/searchtypes.d.ts +7 -2
- package/dist/searchtypes.js +2 -2
- package/dist/usermanager.js +251 -264
- package/dist/utilities.d.ts +2 -0
- package/dist/utilities.js +7 -2
- package/dist/viewexecutor.js +1 -1
- package/dist/viewindexmanager.js +131 -150
- package/package.json +1 -1
- package/src/addondata.cpp +58 -0
- package/src/addondata.h +40 -0
- package/src/binding.cpp +3 -1
- package/src/cas.h +2 -2
- package/src/connection.cpp +25 -178
- package/src/connection.h +8 -65
- package/src/connection_ops.cpp +57 -34
- package/src/constants.cpp +3 -0
- package/src/instance.cpp +235 -0
- package/src/instance.h +102 -0
- package/src/{connection_callbacks.cpp → instance_callbacks.cpp} +34 -34
- package/src/logger.cpp +11 -1
- package/src/logger.h +3 -0
- package/src/metrics.cpp +10 -0
- package/src/metrics.h +3 -0
- package/src/mutationtoken.h +2 -2
- package/src/opbuilder.h +13 -15
- package/src/respreader.cpp +1 -0
- package/src/respreader.h +6 -4
- package/src/tracespan.h +11 -11
- package/src/tracing.cpp +11 -0
- package/src/tracing.h +3 -0
- package/src/valueparser.h +5 -0
- package/deps/lcb/example/observe/durability.c +0 -110
package/dist/datastructures.js
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
3
|
exports.CouchbaseSet = exports.CouchbaseQueue = exports.CouchbaseMap = exports.CouchbaseList = void 0;
|
13
4
|
const errors_1 = require("./errors");
|
@@ -29,26 +20,22 @@ class CouchbaseList {
|
|
29
20
|
this._coll = collection;
|
30
21
|
this._key = key;
|
31
22
|
}
|
32
|
-
_get() {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
return doc.content;
|
39
|
-
});
|
23
|
+
async _get() {
|
24
|
+
const doc = await this._coll.get(this._key);
|
25
|
+
if (!(doc.content instanceof Array)) {
|
26
|
+
throw new errors_1.CouchbaseError('expected document of array type');
|
27
|
+
}
|
28
|
+
return doc.content;
|
40
29
|
}
|
41
30
|
/**
|
42
31
|
* Returns the entire list of items in this list.
|
43
32
|
*
|
44
33
|
* @param callback A node-style callback to be invoked after execution.
|
45
34
|
*/
|
46
|
-
getAll(callback) {
|
47
|
-
return
|
48
|
-
return
|
49
|
-
|
50
|
-
}), callback);
|
51
|
-
});
|
35
|
+
async getAll(callback) {
|
36
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
37
|
+
return await this._get();
|
38
|
+
}, callback);
|
52
39
|
}
|
53
40
|
/**
|
54
41
|
* Iterates each item in the list.
|
@@ -56,36 +43,32 @@ class CouchbaseList {
|
|
56
43
|
* @param rowCallback A callback invoked for each item in the list.
|
57
44
|
* @param callback A node-style callback to be invoked after execution.
|
58
45
|
*/
|
59
|
-
forEach(rowCallback, callback) {
|
60
|
-
return
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
}), callback);
|
67
|
-
});
|
46
|
+
async forEach(rowCallback, callback) {
|
47
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
48
|
+
const values = await this._get();
|
49
|
+
for (let i = 0; i < values.length; ++i) {
|
50
|
+
rowCallback(values[i], i, this);
|
51
|
+
}
|
52
|
+
}, callback);
|
68
53
|
}
|
69
54
|
/**
|
70
55
|
* Provides the ability to async-for loop this object.
|
71
56
|
*/
|
72
57
|
[Symbol.asyncIterator]() {
|
73
|
-
const getNext = () =>
|
58
|
+
const getNext = async () => this._get();
|
74
59
|
return {
|
75
60
|
data: null,
|
76
61
|
index: -1,
|
77
|
-
next() {
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
return { done: true };
|
88
|
-
});
|
62
|
+
async next() {
|
63
|
+
if (this.index < 0) {
|
64
|
+
this.data = await getNext();
|
65
|
+
this.index = 0;
|
66
|
+
}
|
67
|
+
const data = this.data;
|
68
|
+
if (this.index < data.length) {
|
69
|
+
return { done: false, value: data[this.index++] };
|
70
|
+
}
|
71
|
+
return { done: true };
|
89
72
|
},
|
90
73
|
};
|
91
74
|
}
|
@@ -95,19 +78,17 @@ class CouchbaseList {
|
|
95
78
|
* @param index The index to retrieve.
|
96
79
|
* @param callback A node-style callback to be invoked after execution.
|
97
80
|
*/
|
98
|
-
getAt(index, callback) {
|
99
|
-
return
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}), callback);
|
110
|
-
});
|
81
|
+
async getAt(index, callback) {
|
82
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
83
|
+
const res = await this._coll.lookupIn(this._key, [
|
84
|
+
sdspecs_1.LookupInSpec.get('[' + index + ']'),
|
85
|
+
]);
|
86
|
+
const itemRes = res.content[0];
|
87
|
+
if (itemRes.error) {
|
88
|
+
throw itemRes.error;
|
89
|
+
}
|
90
|
+
return itemRes.value;
|
91
|
+
}, callback);
|
111
92
|
}
|
112
93
|
/**
|
113
94
|
* Removes an item at a specific index from the list.
|
@@ -115,14 +96,12 @@ class CouchbaseList {
|
|
115
96
|
* @param index The index to remove.
|
116
97
|
* @param callback A node-style callback to be invoked after execution.
|
117
98
|
*/
|
118
|
-
removeAt(index, callback) {
|
119
|
-
return
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
}), callback);
|
125
|
-
});
|
99
|
+
async removeAt(index, callback) {
|
100
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
101
|
+
await this._coll.mutateIn(this._key, [
|
102
|
+
sdspecs_1.MutateInSpec.remove('[' + index + ']'),
|
103
|
+
]);
|
104
|
+
}, callback);
|
126
105
|
}
|
127
106
|
/**
|
128
107
|
* Returns the index of a specific value from the list.
|
@@ -130,31 +109,27 @@ class CouchbaseList {
|
|
130
109
|
* @param value The value to search for.
|
131
110
|
* @param callback A node-style callback to be invoked after execution.
|
132
111
|
*/
|
133
|
-
indexOf(value, callback) {
|
134
|
-
return
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
return i;
|
140
|
-
}
|
112
|
+
async indexOf(value, callback) {
|
113
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
114
|
+
const items = await this._get();
|
115
|
+
for (let i = 0; i < items.length; ++i) {
|
116
|
+
if (items[i] === value) {
|
117
|
+
return i;
|
141
118
|
}
|
142
|
-
|
143
|
-
|
144
|
-
});
|
119
|
+
}
|
120
|
+
return -1;
|
121
|
+
}, callback);
|
145
122
|
}
|
146
123
|
/**
|
147
124
|
* Returns the number of items in the list.
|
148
125
|
*
|
149
126
|
* @param callback A node-style callback to be invoked after execution.
|
150
127
|
*/
|
151
|
-
size(callback) {
|
152
|
-
return
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
}), callback);
|
157
|
-
});
|
128
|
+
async size(callback) {
|
129
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
130
|
+
const res = await this._coll.lookupIn(this._key, [sdspecs_1.LookupInSpec.count('')]);
|
131
|
+
return res.content[0].value;
|
132
|
+
}, callback);
|
158
133
|
}
|
159
134
|
/**
|
160
135
|
* Adds a new item to the end of the list.
|
@@ -162,14 +137,12 @@ class CouchbaseList {
|
|
162
137
|
* @param value The value to add.
|
163
138
|
* @param callback A node-style callback to be invoked after execution.
|
164
139
|
*/
|
165
|
-
push(value, callback) {
|
166
|
-
return
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
}), callback);
|
172
|
-
});
|
140
|
+
async push(value, callback) {
|
141
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
142
|
+
await this._coll.mutateIn(this._key, [sdspecs_1.MutateInSpec.arrayAppend('', value)], {
|
143
|
+
storeSemantics: generaltypes_1.StoreSemantics.Upsert,
|
144
|
+
});
|
145
|
+
}, callback);
|
173
146
|
}
|
174
147
|
/**
|
175
148
|
* Adds a new item to the beginning of the list.
|
@@ -177,14 +150,12 @@ class CouchbaseList {
|
|
177
150
|
* @param value The value to add.
|
178
151
|
* @param callback A node-style callback to be invoked after execution.
|
179
152
|
*/
|
180
|
-
unshift(value, callback) {
|
181
|
-
return
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
}), callback);
|
187
|
-
});
|
153
|
+
async unshift(value, callback) {
|
154
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
155
|
+
await this._coll.mutateIn(this._key, [sdspecs_1.MutateInSpec.arrayPrepend('', value)], {
|
156
|
+
storeSemantics: generaltypes_1.StoreSemantics.Upsert,
|
157
|
+
});
|
158
|
+
}, callback);
|
188
159
|
}
|
189
160
|
}
|
190
161
|
exports.CouchbaseList = CouchbaseList;
|
@@ -203,26 +174,22 @@ class CouchbaseMap {
|
|
203
174
|
this._coll = collection;
|
204
175
|
this._key = key;
|
205
176
|
}
|
206
|
-
_get() {
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
return doc.content;
|
213
|
-
});
|
177
|
+
async _get() {
|
178
|
+
const doc = await this._coll.get(this._key);
|
179
|
+
if (!(doc.content instanceof Object)) {
|
180
|
+
throw new errors_1.CouchbaseError('expected document of object type');
|
181
|
+
}
|
182
|
+
return doc.content;
|
214
183
|
}
|
215
184
|
/**
|
216
185
|
* Returns an object representing all items in the map.
|
217
186
|
*
|
218
187
|
* @param callback A node-style callback to be invoked after execution.
|
219
188
|
*/
|
220
|
-
getAll(callback) {
|
221
|
-
return
|
222
|
-
return
|
223
|
-
|
224
|
-
}), callback);
|
225
|
-
});
|
189
|
+
async getAll(callback) {
|
190
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
191
|
+
return await this._get();
|
192
|
+
}, callback);
|
226
193
|
}
|
227
194
|
/**
|
228
195
|
* Iterates through every item in the map.
|
@@ -230,40 +197,36 @@ class CouchbaseMap {
|
|
230
197
|
* @param rowCallback A callback invoked for each item in the list.
|
231
198
|
* @param callback A node-style callback to be invoked after execution.
|
232
199
|
*/
|
233
|
-
forEach(rowCallback, callback) {
|
234
|
-
return
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
}), callback);
|
241
|
-
});
|
200
|
+
async forEach(rowCallback, callback) {
|
201
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
202
|
+
const values = await this._get();
|
203
|
+
for (const i in values) {
|
204
|
+
rowCallback(values[i], i, this);
|
205
|
+
}
|
206
|
+
}, callback);
|
242
207
|
}
|
243
208
|
/**
|
244
209
|
* Provides the ability to async-for loop this object.
|
245
210
|
*/
|
246
211
|
[Symbol.asyncIterator]() {
|
247
|
-
const getNext = () =>
|
212
|
+
const getNext = async () => this._get();
|
248
213
|
return {
|
249
214
|
data: null,
|
250
215
|
keys: null,
|
251
216
|
index: -1,
|
252
|
-
next() {
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
return { done: true, value: undefined };
|
266
|
-
});
|
217
|
+
async next() {
|
218
|
+
if (this.index < 0) {
|
219
|
+
this.data = await getNext();
|
220
|
+
this.keys = Object.keys(this.data);
|
221
|
+
this.index = 0;
|
222
|
+
}
|
223
|
+
const keys = this.keys;
|
224
|
+
const data = this.data;
|
225
|
+
if (this.index < keys.length) {
|
226
|
+
const key = keys[this.index++];
|
227
|
+
return { done: false, value: [data[key], key] };
|
228
|
+
}
|
229
|
+
return { done: true, value: undefined };
|
267
230
|
},
|
268
231
|
};
|
269
232
|
}
|
@@ -274,14 +237,12 @@ class CouchbaseMap {
|
|
274
237
|
* @param value The new value to set.
|
275
238
|
* @param callback A node-style callback to be invoked after execution.
|
276
239
|
*/
|
277
|
-
set(item, value, callback) {
|
278
|
-
return
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
}), callback);
|
284
|
-
});
|
240
|
+
async set(item, value, callback) {
|
241
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
242
|
+
await this._coll.mutateIn(this._key, [sdspecs_1.MutateInSpec.upsert(item, value)], {
|
243
|
+
storeSemantics: generaltypes_1.StoreSemantics.Upsert,
|
244
|
+
});
|
245
|
+
}, callback);
|
285
246
|
}
|
286
247
|
/**
|
287
248
|
* Fetches a specific key from the map.
|
@@ -289,17 +250,15 @@ class CouchbaseMap {
|
|
289
250
|
* @param item The key in the map to retrieve.
|
290
251
|
* @param callback A node-style callback to be invoked after execution.
|
291
252
|
*/
|
292
|
-
get(item, callback) {
|
293
|
-
return
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
}), callback);
|
302
|
-
});
|
253
|
+
async get(item, callback) {
|
254
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
255
|
+
const res = await this._coll.lookupIn(this._key, [sdspecs_1.LookupInSpec.get(item)]);
|
256
|
+
const itemRes = res.content[0];
|
257
|
+
if (itemRes.error) {
|
258
|
+
throw itemRes.error;
|
259
|
+
}
|
260
|
+
return itemRes.value;
|
261
|
+
}, callback);
|
303
262
|
}
|
304
263
|
/**
|
305
264
|
* Removes a specific key from the map.
|
@@ -307,12 +266,10 @@ class CouchbaseMap {
|
|
307
266
|
* @param item The key in the map to remove.
|
308
267
|
* @param callback A node-style callback to be invoked after execution.
|
309
268
|
*/
|
310
|
-
remove(item, callback) {
|
311
|
-
return
|
312
|
-
|
313
|
-
|
314
|
-
}), callback);
|
315
|
-
});
|
269
|
+
async remove(item, callback) {
|
270
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
271
|
+
await this._coll.mutateIn(this._key, [sdspecs_1.MutateInSpec.remove(item)]);
|
272
|
+
}, callback);
|
316
273
|
}
|
317
274
|
/**
|
318
275
|
* Checks whether a specific key exists in the map.
|
@@ -320,55 +277,47 @@ class CouchbaseMap {
|
|
320
277
|
* @param item The key in the map to search for.
|
321
278
|
* @param callback A node-style callback to be invoked after execution.
|
322
279
|
*/
|
323
|
-
exists(item, callback) {
|
324
|
-
return
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
}), callback);
|
332
|
-
});
|
280
|
+
async exists(item, callback) {
|
281
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
282
|
+
const res = await this._coll.lookupIn(this._key, [
|
283
|
+
sdspecs_1.LookupInSpec.exists(item),
|
284
|
+
]);
|
285
|
+
const itemRes = res.content[0];
|
286
|
+
return itemRes.value;
|
287
|
+
}, callback);
|
333
288
|
}
|
334
289
|
/**
|
335
290
|
* Returns a list of all the keys which exist in the map.
|
336
291
|
*
|
337
292
|
* @param callback A node-style callback to be invoked after execution.
|
338
293
|
*/
|
339
|
-
keys(callback) {
|
340
|
-
return
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
}), callback);
|
345
|
-
});
|
294
|
+
async keys(callback) {
|
295
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
296
|
+
const values = await this._get();
|
297
|
+
return Object.keys(values);
|
298
|
+
}, callback);
|
346
299
|
}
|
347
300
|
/**
|
348
301
|
* Returns a list of all the values which exist in the map.
|
349
302
|
*
|
350
303
|
* @param callback A node-style callback to be invoked after execution.
|
351
304
|
*/
|
352
|
-
values(callback) {
|
353
|
-
return
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
}), callback);
|
358
|
-
});
|
305
|
+
async values(callback) {
|
306
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
307
|
+
const values = await this._get();
|
308
|
+
return Object.values(values);
|
309
|
+
}, callback);
|
359
310
|
}
|
360
311
|
/**
|
361
312
|
* Returns the number of items that exist in the map.
|
362
313
|
*
|
363
314
|
* @param callback A node-style callback to be invoked after execution.
|
364
315
|
*/
|
365
|
-
size(callback) {
|
366
|
-
return
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
}), callback);
|
371
|
-
});
|
316
|
+
async size(callback) {
|
317
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
318
|
+
const res = await this._coll.lookupIn(this._key, [sdspecs_1.LookupInSpec.count('')]);
|
319
|
+
return res.content[0].value;
|
320
|
+
}, callback);
|
372
321
|
}
|
373
322
|
}
|
374
323
|
exports.CouchbaseMap = CouchbaseMap;
|
@@ -387,27 +336,23 @@ class CouchbaseQueue {
|
|
387
336
|
this._coll = collection;
|
388
337
|
this._key = key;
|
389
338
|
}
|
390
|
-
_get() {
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
return doc.content;
|
397
|
-
});
|
339
|
+
async _get() {
|
340
|
+
const doc = await this._coll.get(this._key);
|
341
|
+
if (!(doc.content instanceof Array)) {
|
342
|
+
throw new errors_1.CouchbaseError('expected document of array type');
|
343
|
+
}
|
344
|
+
return doc.content;
|
398
345
|
}
|
399
346
|
/**
|
400
347
|
* Returns the number of items in the queue.
|
401
348
|
*
|
402
349
|
* @param callback A node-style callback to be invoked after execution.
|
403
350
|
*/
|
404
|
-
size(callback) {
|
405
|
-
return
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
}), callback);
|
410
|
-
});
|
351
|
+
async size(callback) {
|
352
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
353
|
+
const res = await this._coll.lookupIn(this._key, [sdspecs_1.LookupInSpec.count('')]);
|
354
|
+
return res.content[0].value;
|
355
|
+
}, callback);
|
411
356
|
}
|
412
357
|
/**
|
413
358
|
* Adds a new item to the back of the queue.
|
@@ -415,44 +360,40 @@ class CouchbaseQueue {
|
|
415
360
|
* @param value The value to add.
|
416
361
|
* @param callback A node-style callback to be invoked after execution.
|
417
362
|
*/
|
418
|
-
push(value, callback) {
|
419
|
-
return
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
}), callback);
|
425
|
-
});
|
363
|
+
async push(value, callback) {
|
364
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
365
|
+
await this._coll.mutateIn(this._key, [sdspecs_1.MutateInSpec.arrayPrepend('', value)], {
|
366
|
+
storeSemantics: generaltypes_1.StoreSemantics.Upsert,
|
367
|
+
});
|
368
|
+
}, callback);
|
426
369
|
}
|
427
370
|
/**
|
428
371
|
* Removes an item from the front of the queue.
|
429
372
|
*
|
430
373
|
* @param callback A node-style callback to be invoked after execution.
|
431
374
|
*/
|
432
|
-
pop(callback) {
|
433
|
-
return
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
throw new errors_1.CouchbaseError('no items available in list');
|
449
|
-
}
|
450
|
-
// continue and retry
|
375
|
+
async pop(callback) {
|
376
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
377
|
+
for (let i = 0; i < 16; ++i) {
|
378
|
+
try {
|
379
|
+
const res = await this._coll.lookupIn(this._key, [
|
380
|
+
sdspecs_1.LookupInSpec.get('[-1]'),
|
381
|
+
]);
|
382
|
+
const value = res.content[0].value;
|
383
|
+
await this._coll.mutateIn(this._key, [sdspecs_1.MutateInSpec.remove('[-1]')], {
|
384
|
+
cas: res.cas,
|
385
|
+
});
|
386
|
+
return value;
|
387
|
+
}
|
388
|
+
catch (e) {
|
389
|
+
if (e instanceof errors_1.PathInvalidError) {
|
390
|
+
throw new errors_1.CouchbaseError('no items available in list');
|
451
391
|
}
|
392
|
+
// continue and retry
|
452
393
|
}
|
453
|
-
|
454
|
-
|
455
|
-
});
|
394
|
+
}
|
395
|
+
throw new errors_1.CouchbaseError('no items available to pop');
|
396
|
+
}, callback);
|
456
397
|
}
|
457
398
|
}
|
458
399
|
exports.CouchbaseQueue = CouchbaseQueue;
|
@@ -471,14 +412,12 @@ class CouchbaseSet {
|
|
471
412
|
this._coll = collection;
|
472
413
|
this._key = key;
|
473
414
|
}
|
474
|
-
_get() {
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
return doc.content;
|
481
|
-
});
|
415
|
+
async _get() {
|
416
|
+
const doc = await this._coll.get(this._key);
|
417
|
+
if (!(doc.content instanceof Array)) {
|
418
|
+
throw new errors_1.CouchbaseError('expected document of array type');
|
419
|
+
}
|
420
|
+
return doc.content;
|
482
421
|
}
|
483
422
|
/**
|
484
423
|
* Adds a new item to the set. Returning whether the item already existed
|
@@ -487,23 +426,21 @@ class CouchbaseSet {
|
|
487
426
|
* @param item The item to add.
|
488
427
|
* @param callback A node-style callback to be invoked after execution.
|
489
428
|
*/
|
490
|
-
add(item, callback) {
|
491
|
-
return
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
return false;
|
501
|
-
}
|
502
|
-
throw e;
|
429
|
+
async add(item, callback) {
|
430
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
431
|
+
try {
|
432
|
+
await this._coll.mutateIn(this._key, [sdspecs_1.MutateInSpec.arrayAddUnique('', item)], {
|
433
|
+
storeSemantics: generaltypes_1.StoreSemantics.Upsert,
|
434
|
+
});
|
435
|
+
}
|
436
|
+
catch (e) {
|
437
|
+
if (e instanceof errors_1.PathExistsError) {
|
438
|
+
return false;
|
503
439
|
}
|
504
|
-
|
505
|
-
}
|
506
|
-
|
440
|
+
throw e;
|
441
|
+
}
|
442
|
+
return true;
|
443
|
+
}, callback);
|
507
444
|
}
|
508
445
|
/**
|
509
446
|
* Returns whether a specific value already exists in the set.
|
@@ -511,18 +448,16 @@ class CouchbaseSet {
|
|
511
448
|
* @param item The value to search for.
|
512
449
|
* @param callback A node-style callback to be invoked after execution.
|
513
450
|
*/
|
514
|
-
contains(item, callback) {
|
515
|
-
return
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
return true;
|
521
|
-
}
|
451
|
+
async contains(item, callback) {
|
452
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
453
|
+
const values = await this._get();
|
454
|
+
for (let i = 0; i < values.length; ++i) {
|
455
|
+
if (values[i] === item) {
|
456
|
+
return true;
|
522
457
|
}
|
523
|
-
|
524
|
-
|
525
|
-
});
|
458
|
+
}
|
459
|
+
return false;
|
460
|
+
}, callback);
|
526
461
|
}
|
527
462
|
/**
|
528
463
|
* Removes a specific value from the set.
|
@@ -530,56 +465,50 @@ class CouchbaseSet {
|
|
530
465
|
* @param item The value to remove.
|
531
466
|
* @param callback A node-style callback to be invoked after execution.
|
532
467
|
*/
|
533
|
-
remove(item, callback) {
|
534
|
-
return
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
throw new errors_1.CouchbaseError('expected document of array type');
|
541
|
-
}
|
542
|
-
const itemIdx = res.content.indexOf(item);
|
543
|
-
if (itemIdx === -1) {
|
544
|
-
throw new Error('item was not found in set');
|
545
|
-
}
|
546
|
-
yield this._coll.mutateIn(this._key, [sdspecs_1.MutateInSpec.remove('[' + itemIdx + ']')], {
|
547
|
-
cas: res.cas,
|
548
|
-
});
|
549
|
-
return;
|
468
|
+
async remove(item, callback) {
|
469
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
470
|
+
for (let i = 0; i < 16; ++i) {
|
471
|
+
try {
|
472
|
+
const res = await this._coll.get(this._key);
|
473
|
+
if (!(res.content instanceof Array)) {
|
474
|
+
throw new errors_1.CouchbaseError('expected document of array type');
|
550
475
|
}
|
551
|
-
|
552
|
-
|
476
|
+
const itemIdx = res.content.indexOf(item);
|
477
|
+
if (itemIdx === -1) {
|
478
|
+
throw new Error('item was not found in set');
|
553
479
|
}
|
480
|
+
await this._coll.mutateIn(this._key, [sdspecs_1.MutateInSpec.remove('[' + itemIdx + ']')], {
|
481
|
+
cas: res.cas,
|
482
|
+
});
|
483
|
+
return;
|
554
484
|
}
|
555
|
-
|
556
|
-
|
557
|
-
|
485
|
+
catch (e) {
|
486
|
+
// continue and retry
|
487
|
+
}
|
488
|
+
}
|
489
|
+
throw new errors_1.CouchbaseError('no items available to pop');
|
490
|
+
}, callback);
|
558
491
|
}
|
559
492
|
/**
|
560
493
|
* Returns a list of all values in the set.
|
561
494
|
*
|
562
495
|
* @param callback A node-style callback to be invoked after execution.
|
563
496
|
*/
|
564
|
-
values(callback) {
|
565
|
-
return
|
566
|
-
return
|
567
|
-
|
568
|
-
}), callback);
|
569
|
-
});
|
497
|
+
async values(callback) {
|
498
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
499
|
+
return await this._get();
|
500
|
+
}, callback);
|
570
501
|
}
|
571
502
|
/**
|
572
503
|
* Returns the number of elements in this set.
|
573
504
|
*
|
574
505
|
* @param callback A node-style callback to be invoked after execution.
|
575
506
|
*/
|
576
|
-
size(callback) {
|
577
|
-
return
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
}), callback);
|
582
|
-
});
|
507
|
+
async size(callback) {
|
508
|
+
return utilities_1.PromiseHelper.wrapAsync(async () => {
|
509
|
+
const res = await this._coll.lookupIn(this._key, [sdspecs_1.LookupInSpec.count('')]);
|
510
|
+
return res.content[0].value;
|
511
|
+
}, callback);
|
583
512
|
}
|
584
513
|
}
|
585
514
|
exports.CouchbaseSet = CouchbaseSet;
|