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

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
@@ -20,7 +20,7 @@ npm install @adobe/aio-lib-db
20
20
 
21
21
  **aio-lib-db** is intended to be used by AIO Runtime Actions and the DB Plugin for the AIO CLI, and these are always executed within a specific runtime namespace. Before use, a Workspace Database must be provisioned. (See [Provisioning a Workspace Database](https://developer.adobe.com/app-builder/docs/guides/app_builder_guides/storage/database#provisioning-a-workspace-database) in the [Getting Started with Database Storage](https://developer.adobe.com/app-builder/docs/guides/app_builder_guides/storage/database) guide for details.)
22
22
 
23
- **aio-lib-db** must always be initialized in a specific region. This region is normally defined in the `app.config.yaml` application manifest. If it is not, it will default to the `amer` region. Another option is to pass `{ region: '<region>' }` to the `libDb.init()` method to override the default.
23
+ **aio-lib-db** must be initialized in the region the workspace database was provisioned. Otherwise, the connection will fail. To explicitly initialize the library in a specific region, pass the `{region: "<region>"}` argument to the `libDb.init()` method. Called with no arguments, `libDb.init()` will initialize the library either in the default `amer` region or in the region defined in the `AIO_DB_REGION` environment variable.
24
24
 
25
25
  ### Basic Usage
26
26
 
@@ -30,8 +30,12 @@ const libDb = require('@adobe/aio-lib-db');
30
30
  async function main() {
31
31
  let client;
32
32
  try {
33
- // initialize library in region is defined in app.config.yaml and defaults to amer
33
+ // initialize library with the default amer region or what is defined in AIO_DB_REGION
34
34
  const db = await libDb.init();
35
+
36
+ // initialize library with an explicit region
37
+ // const db = await libDb.init({region: "emea"});
38
+
35
39
  // connect to the database
36
40
  client = await db.connect();
37
41
 
@@ -53,7 +57,6 @@ async function main() {
53
57
  }
54
58
  }
55
59
  ```
56
-
57
60
  ---
58
61
 
59
62
  ## Collection Operations
@@ -272,6 +275,24 @@ const cursor = collection.aggregate()
272
275
 
273
276
  ## Advanced Features
274
277
 
278
+ ### Storage Statics
279
+
280
+ ```javascript
281
+ // Get storage statistics for the database
282
+ const dbStats = client.dbStats()
283
+ ```
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 |
295
+
275
296
  ### Indexing
276
297
 
277
298
  ```javascript
@@ -353,12 +374,10 @@ const cursor = collection.find({ status: 'active' })
353
374
  ## Error Handling
354
375
 
355
376
  ```javascript
356
- const { DbError } = require('@adobe/aio-lib-db');
357
-
358
377
  try {
359
378
  await collection.insertOne({ email: 'invalid-email' });
360
379
  } catch (error) {
361
- if (error instanceof DbError) {
380
+ if (error.name == 'DbError') {
362
381
  console.error('Database error:', error.message);
363
382
  } else {
364
383
  console.error('Unexpected error:', error);
package/lib/DbBase.js CHANGED
@@ -81,7 +81,7 @@ class DbBase {
81
81
  * @param {Object=} config
82
82
  * @param {string=} config.namespace required here or as __OW_API_NAMESPACE in .env
83
83
  * @param {string=} config.apikey required here or as __OW_API_KEY in .env
84
- * @param {string=} config.region optional, default is 'amer'. Allowed prod values are 'amer', 'emea', 'apac'
84
+ * @param {string=} config.region optional, default is 'amer'. Allowed prod values are 'amer', 'emea', 'apac', 'aus'
85
85
  * @returns {Promise<DbBase>} a new DbBase instance
86
86
  * @memberof DbBase
87
87
  */
@@ -89,7 +89,7 @@ class DbBase {
89
89
  const namespace = config.namespace || process.env.__OW_NAMESPACE
90
90
  const apikey = config.apikey || process.env.__OW_API_KEY
91
91
  let aioAppRegion = null
92
-
92
+
93
93
  try {
94
94
  aioAppRegion = getRegionFromAppConfig(process.cwd())
95
95
  } catch (e) {
package/lib/constants.js CHANGED
@@ -21,7 +21,7 @@ const STAGE_ENV = 'stage'
21
21
 
22
22
  const ALLOWED_REGIONS = {
23
23
  // First region in an environment's array is the default
24
- [PROD_ENV]: ['amer', 'emea', 'apac'],
24
+ [PROD_ENV]: ['amer', 'emea', 'apac', 'aus'],
25
25
  [STAGE_ENV]: ['amer', 'amer2']
26
26
  }
27
27
 
package/lib/init.js CHANGED
@@ -21,7 +21,7 @@ require('dotenv/config')
21
21
  * `__OW_NAMESPACE` and `__OW_API_KEY`.
22
22
  *
23
23
  * @param {Object=} [config] used to init the sdk
24
- * @param {('amer'|'apac'|'emea')=} [config.region] optional region to use, default: `amer`
24
+ * @param {('amer'|'apac'|'emea'|'aus')=} [config.region] optional region to use, default: `amer`
25
25
  * @param {Object=} [config.ow] Set those if you want to use ootb credentials to access the database service
26
26
  * @param {string=} [config.ow.namespace]
27
27
  * @param {string=} [config.ow.auth]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-lib-db",
3
- "version": "0.1.0-beta.5",
3
+ "version": "0.1.0-beta.6",
4
4
  "description": "An abstraction on top of Document DB storage",
5
5
  "main": "index.js",
6
6
  "scripts": {