spice-couchbase 2.0.52 → 2.0.53
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.
- package/build/index.js +10 -5
- package/package.json +1 -1
- package/src/index.js +18 -7
package/build/index.js
CHANGED
|
@@ -177,6 +177,13 @@ module.exports = class Database {
|
|
|
177
177
|
return "default:".concat(this.quoteIdentifier(this.db_config.bucket), ".").concat(this.quoteIdentifier(scope_name), ".").concat(this.quoteIdentifier(collection_name));
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
isCollectionAlreadyExistsError(error) {
|
|
181
|
+
var _error$cause, _error$cause2, _error$context, _error$context2;
|
|
182
|
+
|
|
183
|
+
var message = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : (_error$cause = error.cause) === null || _error$cause === void 0 ? void 0 : _error$cause.first_error_message) || (error === null || error === void 0 ? void 0 : (_error$context = error.context) === null || _error$context === void 0 ? void 0 : _error$context.first_error_message) || (error === null || error === void 0 ? void 0 : (_error$context2 = error.context) === null || _error$context2 === void 0 ? void 0 : _error$context2.http_response_body) || "";
|
|
184
|
+
return error instanceof couchbase.CollectionExistsError || (error === null || error === void 0 ? void 0 : (_error$cause2 = error.cause) === null || _error$cause2 === void 0 ? void 0 : _error$cause2.first_error_code) === 12003 || (error === null || error === void 0 ? void 0 : (_error$cause2 = error.cause) === null || _error$cause2 === void 0 ? void 0 : _error$cause2.first_error_code) === 12027 || /collection .*already exists|already exists/i.test(message);
|
|
185
|
+
}
|
|
186
|
+
|
|
180
187
|
upsertCollection() {
|
|
181
188
|
var _this3 = this;
|
|
182
189
|
|
|
@@ -207,7 +214,7 @@ module.exports = class Database {
|
|
|
207
214
|
if ((_spice2 = spice) === null || _spice2 === void 0 ? void 0 : (_spice2$db = _spice2.db) === null || _spice2$db === void 0 ? void 0 : (_spice2$db$collection = _spice2$db.collections) === null || _spice2$db$collection === void 0 ? void 0 : _spice2$db$collection.has(collection_name)) {
|
|
208
215
|
return true;
|
|
209
216
|
} else {
|
|
210
|
-
var response = yield _this4.cluster.query("SELECT RAW
|
|
217
|
+
var response = yield _this4.cluster.query("SELECT RAW keyspace_id\n FROM system:keyspaces\n WHERE bucket_id = ?\n AND scope_id = ?\n AND keyspace_id = ?\n LIMIT 1", {
|
|
211
218
|
parameters: [_this4.db_config.bucket, scope_name, collection_name],
|
|
212
219
|
scanConsistency: QueryScanConsistency.RequestPlus
|
|
213
220
|
});
|
|
@@ -237,9 +244,7 @@ module.exports = class Database {
|
|
|
237
244
|
spice.db.collections.add(connection_name);
|
|
238
245
|
return response;
|
|
239
246
|
} catch (e) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (e instanceof couchbase.CollectionExistsError || (e === null || e === void 0 ? void 0 : (_e$cause = e.cause) === null || _e$cause === void 0 ? void 0 : _e$cause.first_error_code) === 12003 || /collection .*already exists|already exists/i.test((e === null || e === void 0 ? void 0 : e.message) || (e === null || e === void 0 ? void 0 : (_e$cause2 = e.cause) === null || _e$cause2 === void 0 ? void 0 : _e$cause2.first_error_message) || "")) {
|
|
247
|
+
if (_this5.isCollectionAlreadyExistsError(e)) {
|
|
243
248
|
spice.db.collections.add(connection_name);
|
|
244
249
|
return;
|
|
245
250
|
}
|
|
@@ -873,4 +878,4 @@ module.exports = class Database {
|
|
|
873
878
|
})();
|
|
874
879
|
}
|
|
875
880
|
|
|
876
|
-
};
|
|
881
|
+
};
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -176,6 +176,21 @@ module.exports = class Database {
|
|
|
176
176
|
)}.${this.quoteIdentifier(collection_name)}`;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
isCollectionAlreadyExistsError(error) {
|
|
180
|
+
const message =
|
|
181
|
+
error?.message ||
|
|
182
|
+
error?.cause?.first_error_message ||
|
|
183
|
+
error?.context?.first_error_message ||
|
|
184
|
+
error?.context?.http_response_body ||
|
|
185
|
+
"";
|
|
186
|
+
return (
|
|
187
|
+
error instanceof couchbase.CollectionExistsError ||
|
|
188
|
+
error?.cause?.first_error_code === 12003 ||
|
|
189
|
+
error?.cause?.first_error_code === 12027 ||
|
|
190
|
+
/collection .*already exists|already exists/i.test(message)
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
179
194
|
async upsertCollection() {
|
|
180
195
|
try {
|
|
181
196
|
if (!this.checkGlobelConnectionObject(this.collection_name)) {
|
|
@@ -200,11 +215,11 @@ module.exports = class Database {
|
|
|
200
215
|
return true;
|
|
201
216
|
} else {
|
|
202
217
|
let response = await this.cluster.query(
|
|
203
|
-
`SELECT RAW
|
|
218
|
+
`SELECT RAW keyspace_id
|
|
204
219
|
FROM system:keyspaces
|
|
205
220
|
WHERE bucket_id = ?
|
|
206
221
|
AND scope_id = ?
|
|
207
|
-
AND
|
|
222
|
+
AND keyspace_id = ?
|
|
208
223
|
LIMIT 1`,
|
|
209
224
|
{
|
|
210
225
|
parameters: [this.db_config.bucket, scope_name, collection_name],
|
|
@@ -235,11 +250,7 @@ module.exports = class Database {
|
|
|
235
250
|
return response;
|
|
236
251
|
} catch (e) {
|
|
237
252
|
if (
|
|
238
|
-
e
|
|
239
|
-
e?.cause?.first_error_code === 12003 ||
|
|
240
|
-
/collection .*already exists|already exists/i.test(
|
|
241
|
-
e?.message || e?.cause?.first_error_message || "",
|
|
242
|
-
)
|
|
253
|
+
this.isCollectionAlreadyExistsError(e)
|
|
243
254
|
) {
|
|
244
255
|
spice.db.collections.add(connection_name);
|
|
245
256
|
return;
|