spice-couchbase 2.0.31 → 2.0.32
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 +59 -16
- package/package.json +2 -2
- package/src/index.js +42 -20
package/build/index.js
CHANGED
|
@@ -45,6 +45,8 @@ module.exports = class Database {
|
|
|
45
45
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
46
46
|
|
|
47
47
|
if (connection) {
|
|
48
|
+
var _spice, _spice$db;
|
|
49
|
+
|
|
48
50
|
this.connection_name = connection;
|
|
49
51
|
this.connection = spice.database.connections[connection];
|
|
50
52
|
this.query_scope = query_scope;
|
|
@@ -69,6 +71,11 @@ module.exports = class Database {
|
|
|
69
71
|
this.collection = this.scope.collection(this.collection_name);
|
|
70
72
|
this.userManager = this.getUserManager(connection);
|
|
71
73
|
|
|
74
|
+
if (!((_spice = spice) === null || _spice === void 0 ? void 0 : (_spice$db = _spice.db) === null || _spice$db === void 0 ? void 0 : _spice$db.collections)) {
|
|
75
|
+
spice.db = spice.db || {};
|
|
76
|
+
spice.db.collections = new Set();
|
|
77
|
+
}
|
|
78
|
+
|
|
72
79
|
if (this.auto_create_collection) {
|
|
73
80
|
this.upsertCollection();
|
|
74
81
|
}
|
|
@@ -170,9 +177,9 @@ module.exports = class Database {
|
|
|
170
177
|
|
|
171
178
|
if (!_this3.checkGlobelConnectionObject(_this3.collection_name)) {
|
|
172
179
|
if (!collection_exists) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
/* await this.createCollection(this.collection_name, this.scope_name);
|
|
181
|
+
await this.wait(2000);
|
|
182
|
+
await this.createPrimaryIndex(this.scope_name, this.collection_name); */
|
|
176
183
|
}
|
|
177
184
|
}
|
|
178
185
|
} catch (e) {
|
|
@@ -186,20 +193,56 @@ module.exports = class Database {
|
|
|
186
193
|
|
|
187
194
|
return _asyncToGenerator(function* () {
|
|
188
195
|
try {
|
|
189
|
-
var
|
|
196
|
+
var _spice2, _spice2$db, _spice2$db$collection;
|
|
190
197
|
|
|
191
|
-
var
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
var that = _this4;
|
|
199
|
+
|
|
200
|
+
function loadAllCollections() {
|
|
201
|
+
return _loadAllCollections.apply(this, arguments);
|
|
202
|
+
}
|
|
203
|
+
/* console.log("================================");
|
|
204
|
+
console.log(
|
|
205
|
+
"Collection Set",
|
|
206
|
+
spice?.db?.collections?.has(collection_name),
|
|
207
|
+
collection_name
|
|
208
|
+
); */
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
function _loadAllCollections() {
|
|
212
|
+
_loadAllCollections = _asyncToGenerator(function* () {
|
|
213
|
+
var all_scopes = yield axios.get("".concat(that.getCouchbaseHost(), "/pools/default/buckets/").concat(that.db_config.bucket, "/scopes"), {
|
|
214
|
+
auth: {
|
|
215
|
+
username: that.db_config.username,
|
|
216
|
+
password: that.db_config.password
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
var scope = _.find(all_scopes.data.scopes, {
|
|
221
|
+
name: scope_name
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
var collectionSet = new Set();
|
|
225
|
+
|
|
226
|
+
_.each(scope.collections, collection => {
|
|
227
|
+
collectionSet.add(collection.name);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
return collectionSet;
|
|
231
|
+
});
|
|
232
|
+
return _loadAllCollections.apply(this, arguments);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
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)) {
|
|
236
|
+
//console.log("Using Internal Collection Set", true);
|
|
237
|
+
return true;
|
|
238
|
+
} else {
|
|
239
|
+
var _spice3, _spice3$db, _spice3$db$collection;
|
|
240
|
+
|
|
241
|
+
//console.log("Using Internal Collection Set", false);
|
|
242
|
+
spice.db.collections = yield loadAllCollections(); //console.log("Collection Set", spice.db.collections.entries());
|
|
243
|
+
|
|
244
|
+
return (_spice3 = spice) === null || _spice3 === void 0 ? void 0 : (_spice3$db = _spice3.db) === null || _spice3$db === void 0 ? void 0 : (_spice3$db$collection = _spice3$db.collections) === null || _spice3$db$collection === void 0 ? void 0 : _spice3$db$collection.has(collection_name);
|
|
245
|
+
}
|
|
203
246
|
} catch (e) {
|
|
204
247
|
console.log("Exists error happened", e);
|
|
205
248
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spice-couchbase",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"axios": "^0.26.1",
|
|
13
|
-
"couchbase": "4.2.
|
|
13
|
+
"couchbase": "^4.2.7",
|
|
14
14
|
"lodash": "^4.17.15",
|
|
15
15
|
"qs": "^6.10.3"
|
|
16
16
|
},
|
package/src/index.js
CHANGED
|
@@ -76,6 +76,10 @@ module.exports = class Database {
|
|
|
76
76
|
this.SearchQuery = couchbase.SearchQuery;
|
|
77
77
|
this.collection = this.scope.collection(this.collection_name);
|
|
78
78
|
this.userManager = this.getUserManager(connection);
|
|
79
|
+
if (!spice?.db?.collections) {
|
|
80
|
+
spice.db = spice.db || {};
|
|
81
|
+
spice.db.collections = new Set();
|
|
82
|
+
}
|
|
79
83
|
if (this.auto_create_collection) {
|
|
80
84
|
this.upsertCollection();
|
|
81
85
|
}
|
|
@@ -174,9 +178,9 @@ module.exports = class Database {
|
|
|
174
178
|
);
|
|
175
179
|
if (!this.checkGlobelConnectionObject(this.collection_name)) {
|
|
176
180
|
if (!collection_exists) {
|
|
177
|
-
await this.createCollection(this.collection_name, this.scope_name);
|
|
181
|
+
/* await this.createCollection(this.collection_name, this.scope_name);
|
|
178
182
|
await this.wait(2000);
|
|
179
|
-
await this.createPrimaryIndex(this.scope_name, this.collection_name);
|
|
183
|
+
await this.createPrimaryIndex(this.scope_name, this.collection_name); */
|
|
180
184
|
}
|
|
181
185
|
}
|
|
182
186
|
} catch (e) {
|
|
@@ -186,24 +190,42 @@ module.exports = class Database {
|
|
|
186
190
|
|
|
187
191
|
async collectionExists(collection_name, scope_name) {
|
|
188
192
|
try {
|
|
189
|
-
let
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
193
|
+
let that = this;
|
|
194
|
+
async function loadAllCollections() {
|
|
195
|
+
let all_scopes = await axios.get(
|
|
196
|
+
`${that.getCouchbaseHost()}/pools/default/buckets/${
|
|
197
|
+
that.db_config.bucket
|
|
198
|
+
}/scopes`,
|
|
199
|
+
{
|
|
200
|
+
auth: {
|
|
201
|
+
username: that.db_config.username,
|
|
202
|
+
password: that.db_config.password,
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
let scope = _.find(all_scopes.data.scopes, { name: scope_name });
|
|
207
|
+
let collectionSet = new Set();
|
|
208
|
+
_.each(scope.collections, (collection) => {
|
|
209
|
+
collectionSet.add(collection.name);
|
|
210
|
+
});
|
|
211
|
+
return collectionSet;
|
|
212
|
+
}
|
|
213
|
+
/* console.log("================================");
|
|
214
|
+
console.log(
|
|
215
|
+
"Collection Set",
|
|
216
|
+
spice?.db?.collections?.has(collection_name),
|
|
217
|
+
collection_name
|
|
218
|
+
); */
|
|
219
|
+
if (spice?.db?.collections?.has(collection_name)) {
|
|
220
|
+
//console.log("Using Internal Collection Set", true);
|
|
221
|
+
return true;
|
|
222
|
+
} else {
|
|
223
|
+
//console.log("Using Internal Collection Set", false);
|
|
224
|
+
|
|
225
|
+
spice.db.collections = await loadAllCollections();
|
|
226
|
+
//console.log("Collection Set", spice.db.collections.entries());
|
|
227
|
+
return spice?.db?.collections?.has(collection_name);
|
|
228
|
+
}
|
|
207
229
|
} catch (e) {
|
|
208
230
|
console.log("Exists error happened", e);
|
|
209
231
|
}
|