cbl-ionic 0.2.5 → 1.0.0
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/CblIonic.podspec +1 -1
- package/README.md +12 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/cbl/js/kotiln/DatabaseManager.kt +19 -6
- package/android/src/main/java/com/couchbase/ionic/CblIonicPluginPlugin.kt +27 -17
- package/android/src/main/java/com/couchbase/ionic/ReplicatorHelper.kt +8 -4
- package/dist/esm/cblite-js/cblite/core-types.d.ts +5 -1
- package/dist/esm/cblite-js/cblite/src/collection.js +17 -17
- package/dist/esm/cblite-js/cblite/src/collection.js.map +1 -1
- package/dist/esm/cblite-js/cblite/src/database-logging.js +1 -1
- package/dist/esm/cblite-js/cblite/src/database-logging.js.map +1 -1
- package/dist/esm/cblite-js/cblite/src/database.d.ts +13 -2
- package/dist/esm/cblite-js/cblite/src/database.js +65 -40
- package/dist/esm/cblite-js/cblite/src/database.js.map +1 -1
- package/dist/esm/cblite-js/cblite/src/document.js +1 -1
- package/dist/esm/cblite-js/cblite/src/document.js.map +1 -1
- package/dist/esm/cblite-js/cblite/src/mutable-document.js +6 -1
- package/dist/esm/cblite-js/cblite/src/mutable-document.js.map +1 -1
- package/dist/esm/cblite-js/cblite/src/query.js +4 -4
- package/dist/esm/cblite-js/cblite/src/query.js.map +1 -1
- package/dist/esm/cblite-js/cblite/src/replicated-document.js +2 -2
- package/dist/esm/cblite-js/cblite/src/replicated-document.js.map +1 -1
- package/dist/esm/cblite-js/cblite/src/replicator-configuration.d.ts +1 -1
- package/dist/esm/cblite-js/cblite/src/replicator-configuration.js +9 -3
- package/dist/esm/cblite-js/cblite/src/replicator-configuration.js.map +1 -1
- package/dist/esm/cblite-js/cblite/src/replicator.js +6 -3
- package/dist/esm/cblite-js/cblite/src/replicator.js.map +1 -1
- package/dist/esm/cblite-js/cblite/src/scope.js +2 -2
- package/dist/esm/cblite-js/cblite/src/scope.js.map +1 -1
- package/dist/esm/couchbase-lite/capacitor-engine.d.ts +4 -1
- package/dist/esm/couchbase-lite/capacitor-engine.js.map +1 -1
- package/dist/plugin.cjs.js +113 -74
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +113 -74
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CblIonicPlugin.swift +5 -3
- package/ios/Plugin/cbl-js-swift/CollectionManager.swift +2 -3
- package/ios/Plugin/cbl-js-swift/DatabaseManager.swift +29 -13
- package/ios/Plugin/cbl-js-swift/FileSystemHelper.swift +0 -2
- package/ios/Plugin/cbl-js-swift/IndexHelper.swift +0 -2
- package/ios/Plugin/cbl-js-swift/LoggingManager.swift +0 -2
- package/ios/Plugin/cbl-js-swift/MapHelper.swift +0 -2
- package/ios/Plugin/cbl-js-swift/QueryHelper.swift +0 -2
- package/ios/Plugin/cbl-js-swift/README.md +12 -0
- package/ios/Plugin/cbl-js-swift/ReplicatorHelper.swift +0 -2
- package/ios/Plugin/cbl-js-swift/ReplicatorManager.swift +0 -2
- package/package.json +2 -2
package/dist/plugin.cjs.js
CHANGED
|
@@ -77,7 +77,13 @@ class ReplicatorConfiguration {
|
|
|
77
77
|
this.headers = undefined;
|
|
78
78
|
this.pinnedServerCertificate = undefined;
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Add a collection used for the replication with an optional collection configuration. If the collection has
|
|
82
|
+
* been added before, the previous added and its configuration if specified will be replaced. If the config is omitted or a null or undefined configuration is specified, a default empty configuration will be applied.
|
|
83
|
+
*
|
|
84
|
+
* @function
|
|
85
|
+
*/
|
|
86
|
+
// eslint-disable-next-line
|
|
81
87
|
addCollection(collection, config) {
|
|
82
88
|
const cols = [];
|
|
83
89
|
cols.push(collection);
|
|
@@ -530,10 +536,10 @@ class ReplicatorConfiguration {
|
|
|
530
536
|
for (const [collections, _] of this.collections) {
|
|
531
537
|
for (const collection of collections) {
|
|
532
538
|
if (databaseName === null && scopeName === null) {
|
|
533
|
-
databaseName = collection.database.
|
|
539
|
+
databaseName = collection.database.getUniqueName();
|
|
534
540
|
scopeName = collection.scope.name;
|
|
535
541
|
}
|
|
536
|
-
else if (collection.database.
|
|
542
|
+
else if (collection.database.getUniqueName() !== databaseName ||
|
|
537
543
|
collection.scope.name !== scopeName) {
|
|
538
544
|
return false;
|
|
539
545
|
}
|
|
@@ -834,7 +840,7 @@ class Scope {
|
|
|
834
840
|
*/
|
|
835
841
|
async collections() {
|
|
836
842
|
const results = await this._engine.collection_GetCollections({
|
|
837
|
-
name: this.database.
|
|
843
|
+
name: this.database.getUniqueName(),
|
|
838
844
|
scopeName: this.name,
|
|
839
845
|
});
|
|
840
846
|
return results.collections;
|
|
@@ -847,7 +853,7 @@ class Scope {
|
|
|
847
853
|
*/
|
|
848
854
|
async collection(collectionName) {
|
|
849
855
|
return this._engine.collection_GetCollection({
|
|
850
|
-
name: this.database.
|
|
856
|
+
name: this.database.getUniqueName(),
|
|
851
857
|
collectionName: collectionName,
|
|
852
858
|
scopeName: this.name,
|
|
853
859
|
});
|
|
@@ -944,7 +950,7 @@ class Document {
|
|
|
944
950
|
key: key,
|
|
945
951
|
collectionName: this.collection.name,
|
|
946
952
|
scopeName: this.collection.scope.name,
|
|
947
|
-
name: this.collection.scope.database.
|
|
953
|
+
name: this.collection.scope.database.getUniqueName(),
|
|
948
954
|
});
|
|
949
955
|
return data.data;
|
|
950
956
|
}
|
|
@@ -1212,7 +1218,7 @@ class Collection {
|
|
|
1212
1218
|
const token = this.uuid();
|
|
1213
1219
|
if (!this._didStartListener) {
|
|
1214
1220
|
await this._engine.collection_AddChangeListener({
|
|
1215
|
-
name: this.scope.database.
|
|
1221
|
+
name: this.scope.database.getUniqueName(),
|
|
1216
1222
|
scopeName: this.scope.name,
|
|
1217
1223
|
collectionName: this.name,
|
|
1218
1224
|
changeListenerToken: token,
|
|
@@ -1239,7 +1245,7 @@ class Collection {
|
|
|
1239
1245
|
if (!this._didStartDocumentListener.has(documentId) &&
|
|
1240
1246
|
!this._documentChangeListener[documentId]) {
|
|
1241
1247
|
await this._engine.collection_AddDocumentChangeListener({
|
|
1242
|
-
name: this.scope.database.
|
|
1248
|
+
name: this.scope.database.getUniqueName(),
|
|
1243
1249
|
scopeName: this.scope.name,
|
|
1244
1250
|
collectionName: this.name,
|
|
1245
1251
|
changeListenerToken: token,
|
|
@@ -1265,7 +1271,7 @@ class Collection {
|
|
|
1265
1271
|
*/
|
|
1266
1272
|
count() {
|
|
1267
1273
|
return this._engine.collection_GetCount({
|
|
1268
|
-
name: this.scope.database.
|
|
1274
|
+
name: this.scope.database.getUniqueName(),
|
|
1269
1275
|
scopeName: this.scope.name,
|
|
1270
1276
|
collectionName: this.name,
|
|
1271
1277
|
});
|
|
@@ -1277,7 +1283,7 @@ class Collection {
|
|
|
1277
1283
|
*/
|
|
1278
1284
|
createIndex(indexName, index) {
|
|
1279
1285
|
return this._engine.collection_CreateIndex({
|
|
1280
|
-
name: this.scope.database.
|
|
1286
|
+
name: this.scope.database.getUniqueName(),
|
|
1281
1287
|
scopeName: this.scope.name,
|
|
1282
1288
|
collectionName: this.name,
|
|
1283
1289
|
indexName: indexName,
|
|
@@ -1300,7 +1306,7 @@ class Collection {
|
|
|
1300
1306
|
deleteDocument(document, concurrencyControl = null) {
|
|
1301
1307
|
const id = document.getId();
|
|
1302
1308
|
return this._engine.collection_DeleteDocument({
|
|
1303
|
-
name: this.scope.database.
|
|
1309
|
+
name: this.scope.database.getUniqueName(),
|
|
1304
1310
|
scopeName: this.scope.name,
|
|
1305
1311
|
collectionName: this.name,
|
|
1306
1312
|
docId: id,
|
|
@@ -1314,7 +1320,7 @@ class Collection {
|
|
|
1314
1320
|
*/
|
|
1315
1321
|
deleteIndex(indexName) {
|
|
1316
1322
|
return this._engine.collection_DeleteIndex({
|
|
1317
|
-
name: this.scope.database.
|
|
1323
|
+
name: this.scope.database.getUniqueName(),
|
|
1318
1324
|
scopeName: this.scope.name,
|
|
1319
1325
|
collectionName: this.name,
|
|
1320
1326
|
indexName: indexName,
|
|
@@ -1330,7 +1336,7 @@ class Collection {
|
|
|
1330
1336
|
async document(id) {
|
|
1331
1337
|
const docJson = await this._engine.collection_GetDocument({
|
|
1332
1338
|
docId: id,
|
|
1333
|
-
name: this.scope.database.
|
|
1339
|
+
name: this.scope.database.getUniqueName(),
|
|
1334
1340
|
scopeName: this.scope.name,
|
|
1335
1341
|
collectionName: this.name,
|
|
1336
1342
|
});
|
|
@@ -1370,11 +1376,11 @@ class Collection {
|
|
|
1370
1376
|
async getDocumentExpiration(id) {
|
|
1371
1377
|
const date = await this._engine.collection_GetDocumentExpiration({
|
|
1372
1378
|
docId: id,
|
|
1373
|
-
name: this.scope.database.
|
|
1379
|
+
name: this.scope.database.getUniqueName(),
|
|
1374
1380
|
scopeName: this.scope.name,
|
|
1375
1381
|
collectionName: this.name,
|
|
1376
1382
|
});
|
|
1377
|
-
if (date
|
|
1383
|
+
if (!!date && date?.date) {
|
|
1378
1384
|
return date.date;
|
|
1379
1385
|
}
|
|
1380
1386
|
else {
|
|
@@ -1396,7 +1402,7 @@ class Collection {
|
|
|
1396
1402
|
*/
|
|
1397
1403
|
async indexes() {
|
|
1398
1404
|
const indexes = await this._engine.collection_GetIndexes({
|
|
1399
|
-
name: this.scope.database.
|
|
1405
|
+
name: this.scope.database.getUniqueName(),
|
|
1400
1406
|
scopeName: this.scope.name,
|
|
1401
1407
|
collectionName: this.name,
|
|
1402
1408
|
});
|
|
@@ -1434,7 +1440,7 @@ class Collection {
|
|
|
1434
1440
|
*/
|
|
1435
1441
|
purge(document) {
|
|
1436
1442
|
return this._engine.collection_PurgeDocument({
|
|
1437
|
-
name: this.database.
|
|
1443
|
+
name: this.database.getUniqueName(),
|
|
1438
1444
|
scopeName: this.scope.name,
|
|
1439
1445
|
collectionName: this.name,
|
|
1440
1446
|
docId: document.getId(),
|
|
@@ -1450,7 +1456,7 @@ class Collection {
|
|
|
1450
1456
|
*/
|
|
1451
1457
|
purgeById(documentId) {
|
|
1452
1458
|
return this._engine.collection_PurgeDocument({
|
|
1453
|
-
name: this.database.
|
|
1459
|
+
name: this.database.getUniqueName(),
|
|
1454
1460
|
scopeName: this.scope.name,
|
|
1455
1461
|
collectionName: this.name,
|
|
1456
1462
|
docId: documentId,
|
|
@@ -1465,7 +1471,7 @@ class Collection {
|
|
|
1465
1471
|
*/
|
|
1466
1472
|
async removeChangeListener(token) {
|
|
1467
1473
|
await this._engine.collection_RemoveChangeListener({
|
|
1468
|
-
name: this.database.
|
|
1474
|
+
name: this.database.getUniqueName(),
|
|
1469
1475
|
scopeName: this.scope.name,
|
|
1470
1476
|
collectionName: this.name,
|
|
1471
1477
|
changeListenerToken: token,
|
|
@@ -1480,7 +1486,7 @@ class Collection {
|
|
|
1480
1486
|
*/
|
|
1481
1487
|
async removeDocumentChangeListener(token) {
|
|
1482
1488
|
await this._engine.collection_RemoveDocumentChangeListener({
|
|
1483
|
-
name: this.database.
|
|
1489
|
+
name: this.database.getUniqueName(),
|
|
1484
1490
|
scopeName: this.scope.name,
|
|
1485
1491
|
collectionName: this.name,
|
|
1486
1492
|
changeListenerToken: token,
|
|
@@ -1506,7 +1512,7 @@ class Collection {
|
|
|
1506
1512
|
document: documentString,
|
|
1507
1513
|
blobs: blobString,
|
|
1508
1514
|
concurrencyControl: concurrencyControl,
|
|
1509
|
-
name: this.scope.database.
|
|
1515
|
+
name: this.scope.database.getUniqueName(),
|
|
1510
1516
|
scopeName: this.scope.name,
|
|
1511
1517
|
collectionName: this.name,
|
|
1512
1518
|
});
|
|
@@ -1518,7 +1524,7 @@ class Collection {
|
|
|
1518
1524
|
async setDocumentExpiration(id, expiration) {
|
|
1519
1525
|
await this._engine.collection_SetDocumentExpiration({
|
|
1520
1526
|
docId: id,
|
|
1521
|
-
name: this.database.
|
|
1527
|
+
name: this.database.getUniqueName(),
|
|
1522
1528
|
scopeName: this.scope.name,
|
|
1523
1529
|
collectionName: this.name,
|
|
1524
1530
|
expiration: expiration,
|
|
@@ -1528,7 +1534,7 @@ class Collection {
|
|
|
1528
1534
|
return {
|
|
1529
1535
|
name: this.name,
|
|
1530
1536
|
scopeName: this.scope.name,
|
|
1531
|
-
databaseName: this.database.
|
|
1537
|
+
databaseName: this.database.getUniqueName(),
|
|
1532
1538
|
};
|
|
1533
1539
|
}
|
|
1534
1540
|
uuid() {
|
|
@@ -1641,7 +1647,7 @@ class DatabaseLogging {
|
|
|
1641
1647
|
}
|
|
1642
1648
|
setFileConfig(config) {
|
|
1643
1649
|
return this.database.getEngine().database_SetFileLoggingConfig({
|
|
1644
|
-
name: this.database.
|
|
1650
|
+
name: this.database.getUniqueName(),
|
|
1645
1651
|
config: config,
|
|
1646
1652
|
});
|
|
1647
1653
|
}
|
|
@@ -1767,7 +1773,7 @@ class Query {
|
|
|
1767
1773
|
const token = this._engine.getUUID();
|
|
1768
1774
|
if (!this._didStartQueryListener) {
|
|
1769
1775
|
await this._engine.query_AddChangeListener({
|
|
1770
|
-
name: this._database.
|
|
1776
|
+
name: this._database.getUniqueName(),
|
|
1771
1777
|
query: this._queryString,
|
|
1772
1778
|
parameters: this.parameters,
|
|
1773
1779
|
changeListenerToken: token,
|
|
@@ -1804,7 +1810,7 @@ class Query {
|
|
|
1804
1810
|
this.parameters = new Parameters();
|
|
1805
1811
|
}
|
|
1806
1812
|
const queryResults = await this._database.getEngine().query_Execute({
|
|
1807
|
-
name: this._database.
|
|
1813
|
+
name: this._database.getUniqueName(),
|
|
1808
1814
|
query: this._queryString,
|
|
1809
1815
|
parameters: this.parameters.get(),
|
|
1810
1816
|
});
|
|
@@ -1827,7 +1833,7 @@ class Query {
|
|
|
1827
1833
|
this.parameters = new Parameters();
|
|
1828
1834
|
}
|
|
1829
1835
|
const queryResults = await this._database.getEngine().query_Explain({
|
|
1830
|
-
name: this._database.
|
|
1836
|
+
name: this._database.getUniqueName(),
|
|
1831
1837
|
query: this._queryString,
|
|
1832
1838
|
parameters: this.parameters.get(),
|
|
1833
1839
|
});
|
|
@@ -1867,7 +1873,7 @@ class Query {
|
|
|
1867
1873
|
async removeChangeListener(token) {
|
|
1868
1874
|
await this._database.getEngine().query_RemoveChangeListener({
|
|
1869
1875
|
changeListenerToken: token,
|
|
1870
|
-
name: this._database.
|
|
1876
|
+
name: this._database.getUniqueName(),
|
|
1871
1877
|
});
|
|
1872
1878
|
}
|
|
1873
1879
|
setDatabase(database) {
|
|
@@ -1938,9 +1944,12 @@ class Database {
|
|
|
1938
1944
|
// eslint-disable-next-line
|
|
1939
1945
|
_databaseName,
|
|
1940
1946
|
// eslint-disable-next-line
|
|
1941
|
-
_databaseConfig = null
|
|
1947
|
+
_databaseConfig = null,
|
|
1948
|
+
// eslint-disable-next-line
|
|
1949
|
+
_databaseUniqueName = null) {
|
|
1942
1950
|
this._databaseName = _databaseName;
|
|
1943
1951
|
this._databaseConfig = _databaseConfig;
|
|
1952
|
+
this._databaseUniqueName = _databaseUniqueName;
|
|
1944
1953
|
this._isClosed = false;
|
|
1945
1954
|
this._engine = EngineLocator.getEngine(EngineLocator.key);
|
|
1946
1955
|
this.log = new DatabaseLogging(this);
|
|
@@ -1950,16 +1959,19 @@ class Database {
|
|
|
1950
1959
|
}
|
|
1951
1960
|
/**
|
|
1952
1961
|
* Open a database with the given name and configuration.
|
|
1962
|
+
* Returns the unique internal name of the database which consists of the provided name and nanoId.
|
|
1963
|
+
* The unique name is used to allow multiple instances of the same database to be opened at the same time.
|
|
1953
1964
|
*
|
|
1954
1965
|
* @function
|
|
1955
1966
|
*/
|
|
1956
|
-
open() {
|
|
1957
|
-
const
|
|
1967
|
+
async open() {
|
|
1968
|
+
const { databaseUniqueName } = await this._engine.database_Open({
|
|
1958
1969
|
name: this._databaseName,
|
|
1959
1970
|
config: this._databaseConfig,
|
|
1960
1971
|
});
|
|
1972
|
+
this._databaseUniqueName = databaseUniqueName;
|
|
1961
1973
|
this._isClosed = false;
|
|
1962
|
-
return
|
|
1974
|
+
return databaseUniqueName;
|
|
1963
1975
|
}
|
|
1964
1976
|
/**
|
|
1965
1977
|
* Changes the database’s encryption key, or removes
|
|
@@ -1969,7 +1981,7 @@ class Database {
|
|
|
1969
1981
|
*/
|
|
1970
1982
|
async changeEncryptionKey(newKey) {
|
|
1971
1983
|
await this._engine.database_ChangeEncryptionKey({
|
|
1972
|
-
name: this.
|
|
1984
|
+
name: this._databaseUniqueName,
|
|
1973
1985
|
newKey: newKey,
|
|
1974
1986
|
});
|
|
1975
1987
|
this._databaseConfig.setEncryptionKey(newKey);
|
|
@@ -1980,7 +1992,7 @@ class Database {
|
|
|
1980
1992
|
* @function
|
|
1981
1993
|
*/
|
|
1982
1994
|
close() {
|
|
1983
|
-
const result = this._engine.database_Close({ name: this.
|
|
1995
|
+
const result = this._engine.database_Close({ name: this._databaseUniqueName });
|
|
1984
1996
|
this._isClosed = true;
|
|
1985
1997
|
return result;
|
|
1986
1998
|
}
|
|
@@ -1991,7 +2003,7 @@ class Database {
|
|
|
1991
2003
|
*/
|
|
1992
2004
|
compact() {
|
|
1993
2005
|
const args = {
|
|
1994
|
-
name: this.
|
|
2006
|
+
name: this._databaseUniqueName,
|
|
1995
2007
|
maintenanceType: exports.MaintenanceType.COMPACT,
|
|
1996
2008
|
};
|
|
1997
2009
|
return this._engine.database_PerformMaintenance(args);
|
|
@@ -2002,7 +2014,7 @@ class Database {
|
|
|
2002
2014
|
* @function
|
|
2003
2015
|
*/
|
|
2004
2016
|
performMaintenance(maintenanceType) {
|
|
2005
|
-
const args = { name: this.
|
|
2017
|
+
const args = { name: this._databaseUniqueName, maintenanceType: maintenanceType };
|
|
2006
2018
|
return this._engine.database_PerformMaintenance(args);
|
|
2007
2019
|
}
|
|
2008
2020
|
/**
|
|
@@ -2012,7 +2024,7 @@ class Database {
|
|
|
2012
2024
|
*/
|
|
2013
2025
|
copy(path, name, config) {
|
|
2014
2026
|
return this._engine.database_Copy({
|
|
2015
|
-
name: this.
|
|
2027
|
+
name: this._databaseUniqueName,
|
|
2016
2028
|
path: path,
|
|
2017
2029
|
newName: name,
|
|
2018
2030
|
config: config,
|
|
@@ -2027,7 +2039,7 @@ class Database {
|
|
|
2027
2039
|
if (this._isClosed) {
|
|
2028
2040
|
throw new Error('Cannot delete a closed database using this API. Open the database first.');
|
|
2029
2041
|
}
|
|
2030
|
-
return this._engine.database_Delete({ name: this.
|
|
2042
|
+
return this._engine.database_Delete({ name: this._databaseUniqueName });
|
|
2031
2043
|
}
|
|
2032
2044
|
/**
|
|
2033
2045
|
* Deletes a database.
|
|
@@ -2048,7 +2060,7 @@ class Database {
|
|
|
2048
2060
|
* @function
|
|
2049
2061
|
*/
|
|
2050
2062
|
async getPath() {
|
|
2051
|
-
return (await this._engine.database_GetPath({ name: this.
|
|
2063
|
+
return (await this._engine.database_GetPath({ name: this._databaseUniqueName }))
|
|
2052
2064
|
.path;
|
|
2053
2065
|
}
|
|
2054
2066
|
/**
|
|
@@ -2073,6 +2085,16 @@ class Database {
|
|
|
2073
2085
|
getName() {
|
|
2074
2086
|
return this._databaseName;
|
|
2075
2087
|
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Return the database unique name.
|
|
2090
|
+
* Unique name is generated by adding a nanoId to the database name.
|
|
2091
|
+
* This is used to allow multiple instances of the same database to be opened at the same time.
|
|
2092
|
+
*
|
|
2093
|
+
* @function
|
|
2094
|
+
*/
|
|
2095
|
+
getUniqueName() {
|
|
2096
|
+
return this._databaseUniqueName;
|
|
2097
|
+
}
|
|
2076
2098
|
/**
|
|
2077
2099
|
* Returns a READONLY config object which will throw a runtime exception when any setter methods are called.
|
|
2078
2100
|
*
|
|
@@ -2118,7 +2140,7 @@ class Database {
|
|
|
2118
2140
|
*/
|
|
2119
2141
|
async defaultScope() {
|
|
2120
2142
|
const scope = await this._engine.scope_GetDefault({
|
|
2121
|
-
name: this.
|
|
2143
|
+
name: this._databaseUniqueName,
|
|
2122
2144
|
});
|
|
2123
2145
|
return new Scope(scope.name, this);
|
|
2124
2146
|
}
|
|
@@ -2130,7 +2152,7 @@ class Database {
|
|
|
2130
2152
|
async scope(scopeName) {
|
|
2131
2153
|
try {
|
|
2132
2154
|
const scope = await this._engine.scope_GetScope({
|
|
2133
|
-
name: this.
|
|
2155
|
+
name: this._databaseUniqueName,
|
|
2134
2156
|
scopeName: scopeName,
|
|
2135
2157
|
});
|
|
2136
2158
|
return new Scope(scope.name, this);
|
|
@@ -2146,7 +2168,7 @@ class Database {
|
|
|
2146
2168
|
*/
|
|
2147
2169
|
async scopes() {
|
|
2148
2170
|
const results = await this._engine.scope_GetScopes({
|
|
2149
|
-
name: this.
|
|
2171
|
+
name: this._databaseUniqueName,
|
|
2150
2172
|
});
|
|
2151
2173
|
const scopes = [];
|
|
2152
2174
|
for (const scope of results.scopes) {
|
|
@@ -2161,7 +2183,7 @@ class Database {
|
|
|
2161
2183
|
*/
|
|
2162
2184
|
async defaultCollection() {
|
|
2163
2185
|
const col = await this._engine.collection_GetDefault({
|
|
2164
|
-
name: this.
|
|
2186
|
+
name: this._databaseUniqueName,
|
|
2165
2187
|
});
|
|
2166
2188
|
const scope = new Scope(col.scope.name, this);
|
|
2167
2189
|
return new Collection(col.name, scope, this);
|
|
@@ -2171,21 +2193,21 @@ class Database {
|
|
|
2171
2193
|
let col;
|
|
2172
2194
|
if (typeof scopeOrName === 'string') {
|
|
2173
2195
|
col = await this._engine.collection_GetCollection({
|
|
2174
|
-
name: this.
|
|
2196
|
+
name: this._databaseUniqueName,
|
|
2175
2197
|
collectionName: collectionName,
|
|
2176
2198
|
scopeName: scopeOrName,
|
|
2177
2199
|
});
|
|
2178
2200
|
}
|
|
2179
2201
|
else if (scopeOrName instanceof Scope) {
|
|
2180
2202
|
col = await this._engine.collection_GetCollection({
|
|
2181
|
-
name: this.
|
|
2203
|
+
name: this._databaseUniqueName,
|
|
2182
2204
|
collectionName: collectionName,
|
|
2183
2205
|
scopeName: scopeOrName.name,
|
|
2184
2206
|
});
|
|
2185
2207
|
}
|
|
2186
2208
|
else {
|
|
2187
2209
|
col = await this._engine.collection_GetCollection({
|
|
2188
|
-
name: this.
|
|
2210
|
+
name: this._databaseUniqueName,
|
|
2189
2211
|
collectionName: collectionName,
|
|
2190
2212
|
scopeName: Database.defaultScopeName,
|
|
2191
2213
|
});
|
|
@@ -2199,19 +2221,19 @@ class Database {
|
|
|
2199
2221
|
let colResults;
|
|
2200
2222
|
if (typeof scopeOrName === 'string') {
|
|
2201
2223
|
colResults = await this._engine.collection_GetCollections({
|
|
2202
|
-
name: this.
|
|
2224
|
+
name: this._databaseUniqueName,
|
|
2203
2225
|
scopeName: scopeOrName,
|
|
2204
2226
|
});
|
|
2205
2227
|
}
|
|
2206
2228
|
else if (scopeOrName instanceof Scope) {
|
|
2207
2229
|
colResults = await this._engine.collection_GetCollections({
|
|
2208
|
-
name: this.
|
|
2230
|
+
name: this._databaseUniqueName,
|
|
2209
2231
|
scopeName: scopeOrName.name,
|
|
2210
2232
|
});
|
|
2211
2233
|
}
|
|
2212
2234
|
else {
|
|
2213
2235
|
colResults = await this._engine.collection_GetCollections({
|
|
2214
|
-
name: this.
|
|
2236
|
+
name: this._databaseUniqueName,
|
|
2215
2237
|
scopeName: Database.defaultScopeName,
|
|
2216
2238
|
});
|
|
2217
2239
|
}
|
|
@@ -2226,21 +2248,21 @@ class Database {
|
|
|
2226
2248
|
let col;
|
|
2227
2249
|
if (typeof scopeOrName === 'string') {
|
|
2228
2250
|
col = await this._engine.collection_CreateCollection({
|
|
2229
|
-
name: this.
|
|
2251
|
+
name: this._databaseUniqueName,
|
|
2230
2252
|
collectionName: collectionName,
|
|
2231
2253
|
scopeName: scopeOrName,
|
|
2232
2254
|
});
|
|
2233
2255
|
}
|
|
2234
2256
|
else if (scopeOrName instanceof Scope) {
|
|
2235
2257
|
col = await this._engine.collection_CreateCollection({
|
|
2236
|
-
name: this.
|
|
2258
|
+
name: this._databaseUniqueName,
|
|
2237
2259
|
collectionName: collectionName,
|
|
2238
2260
|
scopeName: scopeOrName.name,
|
|
2239
2261
|
});
|
|
2240
2262
|
}
|
|
2241
2263
|
else {
|
|
2242
2264
|
col = await this._engine.collection_CreateCollection({
|
|
2243
|
-
name: this.
|
|
2265
|
+
name: this._databaseUniqueName,
|
|
2244
2266
|
collectionName: collectionName,
|
|
2245
2267
|
scopeName: Database.defaultScopeName,
|
|
2246
2268
|
});
|
|
@@ -2252,14 +2274,14 @@ class Database {
|
|
|
2252
2274
|
deleteCollection(collectionOrName, scopeName) {
|
|
2253
2275
|
if (typeof collectionOrName === 'string' && scopeName !== undefined) {
|
|
2254
2276
|
return this._engine.collection_DeleteCollection({
|
|
2255
|
-
name: this.
|
|
2277
|
+
name: this._databaseUniqueName,
|
|
2256
2278
|
collectionName: collectionOrName,
|
|
2257
2279
|
scopeName: scopeName,
|
|
2258
2280
|
});
|
|
2259
2281
|
}
|
|
2260
2282
|
else if (collectionOrName instanceof Collection) {
|
|
2261
2283
|
return this._engine.collection_DeleteCollection({
|
|
2262
|
-
name: this.
|
|
2284
|
+
name: this._databaseUniqueName,
|
|
2263
2285
|
collectionName: collectionOrName.name,
|
|
2264
2286
|
scopeName: collectionOrName.scope.name,
|
|
2265
2287
|
});
|
|
@@ -2276,7 +2298,7 @@ class Database {
|
|
|
2276
2298
|
deleteDocument(document, concurrencyControl = null) {
|
|
2277
2299
|
const id = document.getId();
|
|
2278
2300
|
return this._engine.database_DeleteDocument({
|
|
2279
|
-
name: this.
|
|
2301
|
+
name: this._databaseUniqueName,
|
|
2280
2302
|
docId: id,
|
|
2281
2303
|
concurrencyControl: concurrencyControl,
|
|
2282
2304
|
});
|
|
@@ -2288,7 +2310,7 @@ class Database {
|
|
|
2288
2310
|
*/
|
|
2289
2311
|
purgeDocument(document) {
|
|
2290
2312
|
return this._engine.database_PurgeDocument({
|
|
2291
|
-
name: this.
|
|
2313
|
+
name: this._databaseUniqueName,
|
|
2292
2314
|
docId: document.getId(),
|
|
2293
2315
|
});
|
|
2294
2316
|
}
|
|
@@ -2299,7 +2321,7 @@ class Database {
|
|
|
2299
2321
|
*/
|
|
2300
2322
|
async getCount() {
|
|
2301
2323
|
const count = await this._engine.database_GetCount({
|
|
2302
|
-
name: this.
|
|
2324
|
+
name: this._databaseUniqueName,
|
|
2303
2325
|
});
|
|
2304
2326
|
return Promise.resolve(count.count);
|
|
2305
2327
|
}
|
|
@@ -2309,18 +2331,24 @@ class Database {
|
|
|
2309
2331
|
* @function
|
|
2310
2332
|
*/
|
|
2311
2333
|
async getDocument(id) {
|
|
2312
|
-
const docJson = await this._engine.
|
|
2313
|
-
name: this._databaseName,
|
|
2334
|
+
const docJson = await this._engine.collection_GetDocument({
|
|
2314
2335
|
docId: id,
|
|
2336
|
+
name: this._databaseUniqueName,
|
|
2337
|
+
scopeName: "_default",
|
|
2338
|
+
collectionName: "_default",
|
|
2315
2339
|
});
|
|
2316
|
-
|
|
2340
|
+
const collection = await this.defaultCollection();
|
|
2341
|
+
// @ts-expect-error - _id is used in getId()
|
|
2342
|
+
if (docJson && docJson._id) {
|
|
2317
2343
|
// @ts-expect-error - _data is used in getData()
|
|
2318
2344
|
const data = docJson._data;
|
|
2319
2345
|
// @ts-expect-error - _sequence is used in getSequence()
|
|
2320
2346
|
const sequence = docJson._sequence;
|
|
2321
2347
|
// @ts-expect-error _id exists in documents
|
|
2322
2348
|
const retId = docJson._id;
|
|
2323
|
-
|
|
2349
|
+
// @ts-expect-error - _revId is used in getRevisionID()
|
|
2350
|
+
const revisionID = docJson._revId;
|
|
2351
|
+
return Promise.resolve(new Document(retId, sequence, revisionID, collection, data));
|
|
2324
2352
|
}
|
|
2325
2353
|
else {
|
|
2326
2354
|
return Promise.resolve(null);
|
|
@@ -2332,15 +2360,18 @@ class Database {
|
|
|
2332
2360
|
* @function
|
|
2333
2361
|
*/
|
|
2334
2362
|
async save(document, concurrencyControl = null) {
|
|
2335
|
-
const ret = await this._engine.
|
|
2336
|
-
name: this._databaseName,
|
|
2363
|
+
const ret = await this._engine.collection_Save({
|
|
2337
2364
|
id: document.getId(),
|
|
2338
2365
|
document: document.toJsonString(),
|
|
2339
2366
|
blobs: document.blobsToJsonString(),
|
|
2340
2367
|
concurrencyControl: concurrencyControl,
|
|
2368
|
+
name: this._databaseUniqueName,
|
|
2369
|
+
scopeName: "_default",
|
|
2370
|
+
collectionName: "_default",
|
|
2341
2371
|
});
|
|
2342
|
-
|
|
2343
|
-
document.
|
|
2372
|
+
document.setId(ret._id);
|
|
2373
|
+
document.setRevisionID(ret._revId);
|
|
2374
|
+
document.setSequence(ret._sequence);
|
|
2344
2375
|
}
|
|
2345
2376
|
/**
|
|
2346
2377
|
* @deprecated createIndex is deprecated. Use Collection createIndex instead.
|
|
@@ -2349,7 +2380,7 @@ class Database {
|
|
|
2349
2380
|
*/
|
|
2350
2381
|
createIndex(indexName, index) {
|
|
2351
2382
|
return this._engine.database_CreateIndex({
|
|
2352
|
-
name: this.
|
|
2383
|
+
name: this._databaseUniqueName,
|
|
2353
2384
|
indexName: indexName,
|
|
2354
2385
|
index: index.toJson(),
|
|
2355
2386
|
});
|
|
@@ -2361,7 +2392,7 @@ class Database {
|
|
|
2361
2392
|
*/
|
|
2362
2393
|
async getIndexes() {
|
|
2363
2394
|
return (await this._engine.database_GetIndexes({
|
|
2364
|
-
name: this.
|
|
2395
|
+
name: this._databaseUniqueName,
|
|
2365
2396
|
})).indexes;
|
|
2366
2397
|
}
|
|
2367
2398
|
/**
|
|
@@ -2371,7 +2402,7 @@ class Database {
|
|
|
2371
2402
|
*/
|
|
2372
2403
|
deleteIndex(indexName) {
|
|
2373
2404
|
return this._engine.database_DeleteIndex({
|
|
2374
|
-
name: this.
|
|
2405
|
+
name: this._databaseUniqueName,
|
|
2375
2406
|
indexName: indexName,
|
|
2376
2407
|
});
|
|
2377
2408
|
}
|
|
@@ -2435,8 +2466,8 @@ function isReplicatedDocumentRepresentation(obj) {
|
|
|
2435
2466
|
if (object.id === null) {
|
|
2436
2467
|
throw 'document id cannot be null';
|
|
2437
2468
|
}
|
|
2438
|
-
if (object.error
|
|
2439
|
-
if (object.error.message
|
|
2469
|
+
if (object.error) {
|
|
2470
|
+
if (!object.error.message) {
|
|
2440
2471
|
throw 'document error is incomplete';
|
|
2441
2472
|
}
|
|
2442
2473
|
}
|
|
@@ -3099,7 +3130,12 @@ class MutableDocument extends Document {
|
|
|
3099
3130
|
}
|
|
3100
3131
|
else if (arguments.length === 1) {
|
|
3101
3132
|
// Just ID
|
|
3102
|
-
|
|
3133
|
+
if (id === null || id.length === 0) {
|
|
3134
|
+
super(null, null, null, null, {});
|
|
3135
|
+
}
|
|
3136
|
+
else {
|
|
3137
|
+
super(id, null, null, null, {});
|
|
3138
|
+
}
|
|
3103
3139
|
}
|
|
3104
3140
|
else if (arguments.length === 2 && typeof sequenceNoOrData === 'object') {
|
|
3105
3141
|
// ID and data
|
|
@@ -3691,7 +3727,7 @@ class Replicator {
|
|
|
3691
3727
|
}
|
|
3692
3728
|
}
|
|
3693
3729
|
async addDocumentChangeListener(listener) {
|
|
3694
|
-
const token = this._engine.getUUID();
|
|
3730
|
+
const token = this._engine.getUUID() + "_doc";
|
|
3695
3731
|
this._documentChangeListener.set(token, listener);
|
|
3696
3732
|
await this._engine.replicator_AddDocumentChangeListener({
|
|
3697
3733
|
replicatorId: this._replicatorId,
|
|
@@ -3778,7 +3814,7 @@ class Replicator {
|
|
|
3778
3814
|
replicatorId: this._replicatorId,
|
|
3779
3815
|
collectionName: collection.name,
|
|
3780
3816
|
scopeName: collection.scope.name,
|
|
3781
|
-
name: collection.database.
|
|
3817
|
+
name: collection.database.getUniqueName(),
|
|
3782
3818
|
});
|
|
3783
3819
|
}
|
|
3784
3820
|
/**
|
|
@@ -3796,7 +3832,7 @@ class Replicator {
|
|
|
3796
3832
|
documentId: documentId,
|
|
3797
3833
|
collectionName: collection.name,
|
|
3798
3834
|
scopeName: collection.scope.name,
|
|
3799
|
-
name: collection.database.
|
|
3835
|
+
name: collection.database.getUniqueName(),
|
|
3800
3836
|
});
|
|
3801
3837
|
}
|
|
3802
3838
|
notifyDocumentChange(data, token) {
|
|
@@ -3831,6 +3867,9 @@ class Replicator {
|
|
|
3831
3867
|
* @function
|
|
3832
3868
|
*/
|
|
3833
3869
|
async removeChangeListener(token) {
|
|
3870
|
+
if (this._documentChangeListener.has(token)) {
|
|
3871
|
+
this._documentChangeListener.delete(token);
|
|
3872
|
+
}
|
|
3834
3873
|
await this._engine.replicator_RemoveChangeListener({
|
|
3835
3874
|
replicatorId: this._replicatorId,
|
|
3836
3875
|
changeListenerToken: token,
|