@adobe/aio-lib-db 0.1.0-beta.6 → 0.1.0-beta.8

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/README.md CHANGED
@@ -277,21 +277,54 @@ const cursor = collection.aggregate()
277
277
 
278
278
  ### Storage Statics
279
279
 
280
+ #### Individual database statistics:
281
+
280
282
  ```javascript
281
- // Get storage statistics for the database
283
+ // Get storage statistics for the database with the default scale factor (bytes)
282
284
  const dbStats = client.dbStats()
285
+
286
+ // Get storage statistics for the database with a scale factor (e.g. KB)
287
+ const dbStatsKb = client.dbStats({ scale: 1024 })
288
+ ```
289
+ | field returned | description |
290
+ |----------------|-------------------------------------------------------------------------------------------------|
291
+ | collections | the number of collections |
292
+ | objects | the number of objects/documents |
293
+ | views | the number of views (not currently supported) |
294
+ | indexes | the number of indexes |
295
+ | dataSize | the actual amount of storage used (default bytes) |
296
+ | storageSize | space allocated for storage (default bytes) |
297
+ | indexSize | space allocated for indexes (default bytes) |
298
+ | ok | whether the request was successful |
299
+ | scaleFactor | the scale factor used for the size fields, ex: 1024 for kilobyte-scale (default is 1 for bytes) |
300
+ | lastUpdated | when the statistics were last updated |
301
+
302
+ #### Organization storage statistics:
303
+
304
+ ```javascript
305
+ // Get combined storage statistics across databases in the organization with the default scale factor (bytes)
306
+ const orgStats = client.orgStats()
307
+
308
+ // Get combined storage statistics across databases in the organization with a scale factor (e.g. MB)
309
+ const orgStatsMb = client.orgStats({ scale: 1024 * 1024 })
283
310
  ```
284
- | field returned | description |
285
- |----------------|-----------------------------------------------|
286
- | collections | the number of collections |
287
- | objects | the number of objects/documents |
288
- | views | the number of views (not currently supported) |
289
- | indexes | the number of indexes |
290
- | dataSize | the actual amount of storage used in bytes |
291
- | storageSize | space allocated for storage in bytes |
292
- | indexSize | space allocated for indexes in bytes |
293
- | ok | whether the request was successful |
294
- | lastUpdated | when the statistics where last updated |
311
+ | field returned | description |
312
+ |---------------------------|----------------------------------------------------------------------------------------------------------------------------|
313
+ | ok | whether the request was successful |
314
+ | databases | the number of databases in the organization |
315
+ | collections | the total number of collections across databases |
316
+ | dataSize | the total actual amount of storage used across databases (default bytes) |
317
+ | storageSize | space allocated for storage (default bytes) |
318
+ | indexSize | space allocated for indexes (default bytes) |
319
+ | scaleFactor | the scale factor used for the size fields, ex: 1024 for kilobyte-scale (default is 1 for bytes) |
320
+ | databaseStats | an array of statistics for individual databases in the organization |
321
+ | databaseStats.namespace | the runtime namespace the database corresponds to |
322
+ | databaseStats.dataSize | the actual amount of storage used by the database (default bytes) |
323
+ | databaseStats.storageSize | space allocated for storage for the database (default bytes) |
324
+ | databaseStats.indexSize | space allocated for indexes for the database (default bytes) |
325
+ | databaseStats.collections | the number of collections in the database |
326
+ | databaseStats.scaleFactor | the scale factor used for the size fields in the databaseStats array, ex: 1024 for kilobyte-scale (default is 1 for bytes) |
327
+ | databaseStats.lastUpdated | when the database statistics were last updated |
295
328
 
296
329
  ### Indexing
297
330
 
package/lib/DbClient.js CHANGED
@@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- const { dbStatsApi, listCollectionsApi, createCollectionApi } = require('./api/client')
12
+ const { dbStatsApi, listCollectionsApi, createCollectionApi, orgStatsApi } = require('./api/client')
13
13
  const DbCollection = require('./DbCollection')
14
14
 
15
15
  class DbClient {
@@ -37,11 +37,23 @@ class DbClient {
37
37
  /**
38
38
  * Get the statistics for the scoped database
39
39
  *
40
+ * @param {Object=} options
41
+ * @returns {Promise<Object>}
42
+ * @throws {DbError}
43
+ */
44
+ async dbStats(options = {}) {
45
+ return dbStatsApi(this.db, options)
46
+ }
47
+
48
+ /**
49
+ * Gets the combined statistics for all databases that fall under the same organization as the scoped database
50
+ *
51
+ * @param {Object=} options
40
52
  * @returns {Promise<Object>}
41
53
  * @throws {DbError}
42
54
  */
43
- async dbStats() {
44
- return dbStatsApi(this.db)
55
+ async orgStats(options = {}) {
56
+ return orgStatsApi(this.db, options)
45
57
  }
46
58
 
47
59
  /**
package/lib/api/client.js CHANGED
@@ -43,11 +43,24 @@ async function getClientApi(db, endpoint) {
43
43
  * Gets the statistics for the scoped database
44
44
  *
45
45
  * @param {DbBase} db
46
+ * @param {Object=} options
47
+ * @returns {Promise<Object>}
48
+ * @throws {DbError}
49
+ */
50
+ async function dbStats(db, options = {}) {
51
+ return await postClientApi(db, 'dbStats', undefined, options)
52
+ }
53
+
54
+ /**
55
+ * Gets the combined statistics for all databases that fall under the same organization as the scoped database
56
+ *
57
+ * @param {DbBase} db
58
+ * @param {Object=} options
46
59
  * @returns {Promise<Object>}
47
60
  * @throws {DbError}
48
61
  */
49
- async function dbStats(db) {
50
- return await getClientApi(db, 'dbStats')
62
+ async function orgStats(db, options = {}) {
63
+ return await postClientApi(db, 'orgStats', undefined, options)
51
64
  }
52
65
 
53
66
  /**
@@ -90,6 +103,7 @@ async function close(db, axiosClient) {
90
103
 
91
104
  module.exports = {
92
105
  dbStatsApi: dbStats,
106
+ orgStatsApi: orgStats,
93
107
  closeApi: close,
94
108
  createCollectionApi: createCollection,
95
109
  listCollectionsApi: listCollections
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-lib-db",
3
- "version": "0.1.0-beta.6",
3
+ "version": "0.1.0-beta.8",
4
4
  "description": "An abstraction on top of Document DB storage",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,7 +26,7 @@
26
26
  "tough-cookie": "^5.1.2"
27
27
  },
28
28
  "devDependencies": {
29
- "jest": "^29.7.0",
29
+ "jest": "^30.2.0",
30
30
  "uuid": "^11.1.0"
31
31
  },
32
32
  "keywords": [