Repository: node-influx/node-influx
Pull request #415 (2019-06-24 18:54:30)

feat: add function showShards
Fixes #

## Proposed Changes

  - Add function showShards
  -
  -

## Checklist

- [x] A test has been added if appropriate
- [x] `npm test` completes successfully
- [x] Commit messages are in [semantic format](https://seesparkbox.com/foundry/semantic_commit_messages)


Patch:
diff --git a/package-lock.json b/package-lock.json
index cfcd9ba..c40c9ba 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -84,12 +84,12 @@
       "dev": true
     },
     "@octokit/endpoint": {
-      "version": "5.1.5",
-      "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-5.1.5.tgz",
-      "integrity": "sha512-Es0Qj6ynp0mznTnayCX8veXev43/fGjwVvctynwgzcnW+KIK6nrHdqQXUnAA1Az0DsRgbGsh9fDHjP/3Ybfyyw==",
+      "version": "5.2.0",
+      "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-5.2.0.tgz",
+      "integrity": "sha512-g4r1MKr8GJ8qubJQp3HP3JrxDY+ZeVqjYBTgtu1lPEDLhfQDY6rOhyZOoHKOw+gaIF6aAcmuvPPNZUro2OwmOg==",
       "dev": true,
       "requires": {
-        "deepmerge": "3.2.0",
+        "deepmerge": "3.3.0",
         "is-plain-object": "^3.0.0",
         "universal-user-agent": "^2.1.0",
         "url-template": "^2.0.8"
@@ -113,9 +113,9 @@
       }
     },
     "@octokit/request": {
-      "version": "4.1.0",
-      "resolved": "https://registry.npmjs.org/@octokit/request/-/request-4.1.0.tgz",
-      "integrity": "sha512-RvpQAba4i+BNH0z8i0gPRc1ShlHidj4puQjI/Tno6s+Q3/Mzb0XRSHJiOhpeFrZ22V7Mwjq1E7QS27P5CgpWYA==",
+      "version": "4.1.1",
+      "resolved": "https://registry.npmjs.org/@octokit/request/-/request-4.1.1.tgz",
+      "integrity": "sha512-LOyL0i3oxRo418EXRSJNk/3Q4I0/NKawTn6H/CQp+wnrG1UFLGu080gSsgnWobhPo5BpUNgSQ5BRk5FOOJhD1Q==",
       "dev": true,
       "requires": {
         "@octokit/endpoint": "^5.1.0",
@@ -145,9 +145,9 @@
       }
     },
     "@octokit/request-error": {
-      "version": "1.0.2",
-      "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-1.0.2.tgz",
-      "integrity": "sha512-T9swMS/Vc4QlfWrvyeSyp/GjhXtYaBzCcibjGywV4k4D2qVrQKfEMPy8OxMDEj7zkIIdpHwqdpVbKCvnUPqkXw==",
+      "version": "1.0.4",
+      "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-1.0.4.tgz",
+      "integrity": "sha512-L4JaJDXn8SGT+5G0uX79rZLv0MNJmfGa4vb4vy1NnpjSnWDLJRy6m90udGwvMmavwsStgbv2QNkPzzTCMmL+ig==",
       "dev": true,
       "requires": {
         "deprecation": "^2.0.0",
@@ -155,9 +155,9 @@
       }
     },
     "@octokit/rest": {
-      "version": "16.28.1",
-      "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.28.1.tgz",
-      "integrity": "sha512-9H/5F0f2bSVhk78ypu/A9dkK5GCH/aI8CxRJ0L8JU/XEYNIYozxqD6HVC7shsofrCfR61YORfjTE+GxfZ/wasQ==",
+      "version": "16.28.2",
+      "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.28.2.tgz",
+      "integrity": "sha512-csuYiHvJ1P/GFDadVn0QhwO83R1+YREjcwCY7ZIezB6aJTRIEidJZj+R7gAkUhT687cqYb4cXTZsDVu9F+Fmug==",
       "dev": true,
       "requires": {
         "@octokit/request": "^4.0.1",
@@ -272,9 +272,9 @@
       }
     },
     "@semantic-release/npm": {
-      "version": "5.1.9",
-      "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-5.1.9.tgz",
-      "integrity": "sha512-Hcwhiu7zC0hD0ZPTkEE5bsK9l0z7Ou+N/mcSpYT1kq96ETMQtyZee0gjxXiAGaIHJ7wlMuUhHbYp7iAaI1965w==",
+      "version": "5.1.13",
+      "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-5.1.13.tgz",
+      "integrity": "sha512-pONvpoEtGH1nd6Wj3SryACNJ/YXXsvSSekE9Pdk6mnaRv7lGhXdaeJJr6Lr4L8WK98oZv4aJOr68vTac2Oc+dA==",
       "dev": true,
       "requires": {
         "@semantic-release/error": "^2.2.0",
@@ -287,7 +287,7 @@
         "npm": "^6.8.0",
         "rc": "^1.2.8",
         "read-pkg": "^5.0.0",
-        "registry-auth-token": "^3.3.1"
+        "registry-auth-token": "^4.0.0"
       },
       "dependencies": {
         "fs-extra": {
@@ -326,9 +326,9 @@
           }
         },
         "resolve": {
-          "version": "1.11.0",
-          "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.0.tgz",
-          "integrity": "sha512-WL2pBDjqT6pGUNSUzMw00o4T7If+z4H2x3Gz893WoUQ5KW8Vr9txp00ykiP16VBaZF5+j/OcXJHZ9+PCvdiDKw==",
+          "version": "1.11.1",
+          "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz",
+          "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==",
           "dev": true,
           "requires": {
             "path-parse": "^1.0.6"
@@ -2604,9 +2604,9 @@
       "dev": true
     },
     "deepmerge": {
-      "version": "3.2.0",
-      "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-3.2.0.tgz",
-      "integrity": "sha512-6+LuZGU7QCNUnAJyX8cIrlzoEgggTM6B7mm+znKOX4t5ltluT9KLjN6g61ECMS0LTsLW7yDpNoxhix5FZcrIow==",
+      "version": "3.3.0",
+      "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-3.3.0.tgz",
+      "integrity": "sha512-GRQOafGHwMHpjPx9iCvTgpu9NojZ49q794EEL94JVEw6VaeA8XTUyBKvAkOOjBX9oJNiV6G3P+T+tihFjo2TqA==",
       "dev": true
     },
     "define-properties": {
@@ -2673,9 +2673,9 @@
       "dev": true
     },
     "deprecation": {
-      "version": "2.0.0",
-      "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.0.0.tgz",
-      "integrity": "sha512-lbQN037mB3VfA2JFuguM5GCJ+zPinMeCrFe+AfSZ6eqrnJA/Fs+EYMnd6Nb2mn9lf2jO9xwEd9o9lic+D4vkcw==",
+      "version": "2.3.1",
+      "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz",
+      "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==",
       "dev": true
     },
     "des.js": {
@@ -12161,12 +12161,13 @@
       },
       "dependencies": {
         "find-up": {
-          "version": "4.0.0",
-          "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.0.0.tgz",
-          "integrity": "sha512-zoH7ZWPkRdgwYCDVoQTzqjG8JSPANhtvLhh4KVUHyKnaUJJrNeFmWIkTcNuJmR3GLMEmGYEf2S2bjgx26JTF+Q==",
+          "version": "4.1.0",
+          "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
+          "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==",
           "dev": true,
           "requires": {
-            "locate-path": "^5.0.0"
+            "locate-path": "^5.0.0",
+            "path-exists": "^4.0.0"
           }
         },
         "locate-path": {
@@ -12214,6 +12215,12 @@
           "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
           "dev": true
         },
+        "path-exists": {
+          "version": "4.0.0",
+          "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
+          "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
+          "dev": true
+        },
         "read-pkg": {
           "version": "5.1.1",
           "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.1.1.tgz",
@@ -12235,9 +12242,9 @@
           }
         },
         "resolve": {
-          "version": "1.11.0",
-          "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.0.tgz",
-          "integrity": "sha512-WL2pBDjqT6pGUNSUzMw00o4T7If+z4H2x3Gz893WoUQ5KW8Vr9txp00ykiP16VBaZF5+j/OcXJHZ9+PCvdiDKw==",
+          "version": "1.11.1",
+          "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz",
+          "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==",
           "dev": true,
           "requires": {
             "path-parse": "^1.0.6"
@@ -12327,12 +12334,12 @@
       "dev": true
     },
     "registry-auth-token": {
-      "version": "3.4.0",
-      "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-3.4.0.tgz",
-      "integrity": "sha512-4LM6Fw8eBQdwMYcES4yTnn2TqIasbXuwDx3um+QRs7S55aMKCBKBxvPXl2RiUjHwuJLTyYfxSpmfSAjQpcuP+A==",
+      "version": "4.0.0",
+      "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-4.0.0.tgz",
+      "integrity": "sha512-lpQkHxd9UL6tb3k/aHAVfnVtn+Bcs9ob5InuFLLEDqSqeq+AljB8GZW9xY0x7F+xYwEcjKe07nyoxzEYz6yvkw==",
       "dev": true,
       "requires": {
-        "rc": "^1.1.6",
+        "rc": "^1.2.8",
         "safe-buffer": "^5.0.1"
       }
     },
@@ -12618,9 +12625,9 @@
       }
     },
     "semantic-release": {
-      "version": "15.13.16",
-      "resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-15.13.16.tgz",
-      "integrity": "sha512-N/KsJyoABnq17h4WhfJW2lJRuDChulD5zMm8qxRx6mN9oQ49DfvzGKmQlTFj2VF6qwG1TEe723SxIYaGD7IDzA==",
+      "version": "15.13.18",
+      "resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-15.13.18.tgz",
+      "integrity": "sha512-JtfdrhF1zRm91nJH/Rg3taftbWGwktJqqrJJdbmZGKYx63cfC4PoaS0jxRifGJUdmmgW/Kxz8f5bhtB+p1bu8A==",
       "dev": true,
       "requires": {
         "@semantic-release/commit-analyzer": "^6.1.0",
@@ -12718,9 +12725,9 @@
           "dev": true
         },
         "semver": {
-          "version": "6.1.1",
-          "resolved": "https://registry.npmjs.org/semver/-/semver-6.1.1.tgz",
-          "integrity": "sha512-rWYq2e5iYW+fFe/oPPtYJxYgjBm8sC4rmoGdUOgBB7VnwKt6HrL793l2voH1UlsyYZpJ4g0wfjnTEO1s1NP2eQ==",
+          "version": "6.1.2",
+          "resolved": "https://registry.npmjs.org/semver/-/semver-6.1.2.tgz",
+          "integrity": "sha512-z4PqiCpomGtWj8633oeAdXm1Kn1W++3T8epkZYnwiVgIYIJ0QHszhInYSJTYxebByQH7KVCEAn8R9duzZW2PhQ==",
           "dev": true
         }
       }
diff --git a/package.json b/package.json
index 91f3a23..6fd93f1 100644
--- a/package.json
+++ b/package.json
@@ -79,7 +79,7 @@
     "ts-node": "8.3.0",
     "typescript": "3.5.2",
     "webpack": "4.35.0",
-    "semantic-release": "15.13.16"
+    "semantic-release": "15.13.18"
   },
   "eslintConfig": {
     "extends": [
diff --git a/src/index.ts b/src/index.ts
index 0c25eb1..f3596ad 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1065,6 +1065,63 @@ export class InfluxDB {
 			);
 	}
 
+	/**
+   * Shows shards on the database
+   *
+   * @param [database] The database to list policies on, uses the
+   *     default database if not provided.
+   * @return
+   * @example
+   * influx.showShards().then(shards => {
+	*   expect(shards.slice()).to.deep.equal([
+	*     {
+	*		id: 1
+	*		database: 'database',
+	*		retention_policy: 'autogen',
+	*		shard_group: 1,
+	*		start_time: '2019-05-06T00:00:00Z',
+	*		end_time: '2019-05-13T00:00:00Z',
+	*		expiry_time: '2019-05-13T00:00:00Z',
+	*		owners: null,
+	*     },
+	*   ])
+	* })
+  */
+	public showShards(database: string = this._defaultDB()): Promise<Array<{
+		id: number;
+		database: string;
+		retention_policy: string;
+		shard_group: number;
+		start_time: string;
+		end_time: string;
+		expiry_time: string;
+		owners: string;
+	}>> {
+		return this._pool
+			.json(
+				this._getQueryOpts(
+					{
+						q: 'show shards '
+					},
+					'GET',
+				),
+			)
+			.then(result =>
+				parseSingle<{
+					id: number;
+					database: string;
+					retention_policy: string;
+					shard_group: number;
+					start_time: string;
+					end_time: string;
+					expiry_time: string;
+					owners: string;
+				}>(result).filter(function (i) {
+					return i.database === database;
+				})
+			);
+	}
+
 	/**
    * WritePoints sends a list of points together in a batch to InfluxDB. In
    * each point you must specify the measurement name to write into as well


Test patch:
diff --git a/test/create-fixtures.js b/test/create-fixtures.js
index 6e07c70..d9385f8 100644
--- a/test/create-fixtures.js
+++ b/test/create-fixtures.js
@@ -45,6 +45,8 @@ const queries = [
   update(`create retention policy "7d" on "${db}" duration 7d replication 1`),
   fixture('showRetentionPolicies', `show retention policies on "${db}"`),
 
+  fixture('showShards', 'show shards'),
+  
   update(`drop user john`),
   update(`drop user steve`),
   update(`drop database "${db}"`)
diff --git a/test/fixture/v1.0.0/showShards.json b/test/fixture/v1.0.0/showShards.json
new file mode 100644
index 0000000..d3f6a9f
--- /dev/null
+++ b/test/fixture/v1.0.0/showShards.json
@@ -0,0 +1,47 @@
+{
+  "results": [
+    {
+      "statement_id": 0,
+      "series": [
+        {
+          "name": "_internal",
+          "columns": [
+            "id",
+            "database",
+            "retention_policy",
+            "shard_group",
+            "start_time",
+            "end_time",
+            "expiry_time",
+            "owners"
+          ],
+          "values": [
+            [
+              1,
+              "_internal",
+              "monitor",
+              1,
+              "2019-06-13T00:00:00Z",
+              "2019-06-14T00:00:00Z",
+              "2019-06-21T00:00:00Z",
+              ""
+            ]
+          ]
+        },
+        {
+          "name": "influx_test_gen",
+          "columns": [
+            "id",
+            "database",
+            "retention_policy",
+            "shard_group",
+            "start_time",
+            "end_time",
+            "expiry_time",
+            "owners"
+          ]
+        }
+      ]
+    }
+  ]
+}
\ No newline at end of file
diff --git a/test/integrate/data.test.ts b/test/integrate/data.test.ts
index b00f7f1..220745e 100644
--- a/test/integrate/data.test.ts
+++ b/test/integrate/data.test.ts
@@ -20,6 +20,12 @@ describe('data operations', () => {
 		return db.getDatabaseNames().then(res => expect(res).contain('influx_test_db'));
 	});
 
+	it('shows shards', () => {
+		return db
+			.showShards('influx_test_db')
+			.then(res => expect(res[0]).to.have.property('database', 'influx_test_db'));
+	});
+
 	it('writes complex values (issue #242)', () => {
 		const original = JSON.stringify({a: JSON.stringify({b: 'c c'})});
 		return db.writeMeasurement('complex_value_series', [{fields: {msg: original}}]);
diff --git a/test/unit/helpers.ts b/test/unit/helpers.ts
index d783d3d..a3d06a7 100644
--- a/test/unit/helpers.ts
+++ b/test/unit/helpers.ts
@@ -18,6 +18,7 @@ const fixtures: { [version: string]: { [fixture: string]: object } } = {
 		showDatabases: require('../fixture/v1.0.0/showDatabases.json'),
 		showMeasurements: require('../fixture/v1.0.0/showMeasurements.json'),
 		showRetentionPolicies: require('../fixture/v1.0.0/showRetentionPolicies.json'),
+		showShards: require('../fixture/v1.0.0/showShards.json'),
 		showSeries: require('../fixture/v1.0.0/showSeries.json'),
 		showSeriesFromOne: require('../fixture/v1.0.0/showSeriesFromOne.json'),
 		showUsers: require('../fixture/v1.0.0/showUsers.json')
diff --git a/test/unit/influx.test.ts b/test/unit/influx.test.ts
index 614300c..5494e4b 100644
--- a/test/unit/influx.test.ts
+++ b/test/unit/influx.test.ts
@@ -913,5 +913,24 @@ describe('influxdb', () => {
 				]);
 			});
 		});
+
+		it('shows shards', () => {
+			setDefaultDB('_internal');
+			expectQuery('json', 'show shards ', 'GET', dbFixture('showShards'));
+			return influx.showShards().then(res => {
+				expect(res.slice()).to.deep.equal([
+					{
+						id: 1,
+						database: '_internal',
+						retention_policy: 'monitor',
+						shard_group: 1,
+						start_time: '2019-06-13T00:00:00Z',
+						end_time: '2019-06-14T00:00:00Z',
+						expiry_time: '2019-06-21T00:00:00Z',
+						owners: ''
+					}
+				]);
+			});
+		});
 	});
 });