Repository: node-influx/node-influx
Pull request #418 (2019-06-28 08:15:28)

feat: add function dropShard
Fixes #

## Proposed Changes

  - Add function dropShard
  -
  -

## 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 7b88740..4348c8c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1714,9 +1714,9 @@
           }
         },
         "graceful-fs": {
-          "version": "4.1.15",
-          "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz",
-          "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==",
+          "version": "4.2.0",
+          "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.0.tgz",
+          "integrity": "sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==",
           "dev": true
         },
         "lru-cache": {
@@ -2838,9 +2838,9 @@
       "dev": true
     },
     "elliptic": {
-      "version": "6.4.1",
-      "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz",
-      "integrity": "sha512-BsXLz5sqX8OHcsh7CqBMztyXARmGQ3LWPtGjJi6DiJHq5C/qvi9P3OqgswKSDftbu8+IoI/QDTAm2fFnQ9SZSQ==",
+      "version": "6.5.0",
+      "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.0.tgz",
+      "integrity": "sha512-eFOJTMyCYb7xtE/caJ6JJu+bhi67WCYNbkGSknu20pmM8Ke/bqOfdnZWxyoGN26JgfxTbXrsCkEw4KheCT/KGg==",
       "dev": true,
       "requires": {
         "bn.js": "^4.4.0",
@@ -13656,9 +13656,9 @@
       "dev": true
     },
     "terser": {
-      "version": "4.0.0",
-      "resolved": "https://registry.npmjs.org/terser/-/terser-4.0.0.tgz",
-      "integrity": "sha512-dOapGTU0hETFl1tCo4t56FN+2jffoKyER9qBGoUFyZ6y7WLoKT0bF+lAYi6B6YsILcGF3q1C2FBh8QcKSCgkgA==",
+      "version": "4.0.2",
+      "resolved": "https://registry.npmjs.org/terser/-/terser-4.0.2.tgz",
+      "integrity": "sha512-IWLuJqTvx97KP3uTYkFVn93cXO+EtlzJu8TdJylq+H0VBDlPMIfQA9MBS5Vc5t3xTEUG1q0hIfHMpAP2R+gWTw==",
       "dev": true,
       "requires": {
         "commander": "^2.19.0",
@@ -14294,9 +14294,9 @@
       "optional": true
     },
     "webpack": {
-      "version": "4.35.0",
-      "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.35.0.tgz",
-      "integrity": "sha512-M5hL3qpVvtr8d4YaJANbAQBc4uT01G33eDpl/psRTBCfjxFTihdhin1NtAKB1ruDwzeVdcsHHV3NX+QsAgOosw==",
+      "version": "4.35.2",
+      "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.35.2.tgz",
+      "integrity": "sha512-TZAmorNymV4q66gAM/h90cEjG+N3627Q2MnkSgKlX/z3DlNVKUtqy57lz1WmZU2+FUZwzM+qm7cGaO95PyrX5A==",
       "dev": true,
       "requires": {
         "@webassemblyjs/ast": "1.8.5",
diff --git a/package.json b/package.json
index 7c778aa..1c87c6a 100644
--- a/package.json
+++ b/package.json
@@ -78,7 +78,7 @@
     "stream-http": "github:node-influx/stream-http",
     "ts-node": "8.3.0",
     "typescript": "3.5.2",
-    "webpack": "4.35.0",
+    "webpack": "4.35.2",
     "semantic-release": "15.13.18"
   },
   "eslintConfig": {
diff --git a/src/index.ts b/src/index.ts
index f3596ad..0bf5597 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1122,6 +1122,27 @@ export class InfluxDB {
 			);
 	}
 
+	/**
+   * Drops a shard with the provided number.
+   * @param shard_id
+   * @return
+   * @example
+   * influx.dropShard(3)
+   */
+	public dropShard(shard_id: number): Promise<void> {
+		return this._pool
+			.json(
+				this._getQueryOpts(
+					{
+						q: `drop shard ${shard_id}`
+					},
+					'POST',
+				),
+			)
+			.then(assertNoErrors)
+			.then(() => undefined);
+	}
+
 	/**
    * 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/integrate/data.test.ts b/test/integrate/data.test.ts
index 220745e..80263f5 100644
--- a/test/integrate/data.test.ts
+++ b/test/integrate/data.test.ts
@@ -58,6 +58,17 @@ describe('data operations', () => {
 			.then(() => db.getSeries())
 			.then(res => expect(res).to.not.contain('h2o_quality,location=coyote_creek,randtag=1'));
 	});
+	it('drops shard', () => {
+		let first_shard_number = 0;
+		return db
+			.showShards('influx_test_db')
+			.then(res => {
+				first_shard_number = res[0].id;
+			})
+			.then(() => db.dropShard(first_shard_number))
+			.then(() => db.showShards('influx_test_db'))
+			.then(res => expect(res[0].id).to.not.equal(first_shard_number));
+	});
 
 	it('gets measurements', () => {
 		return db.getMeasurements().then(res => expect(res).to.deep.equal(['h2o_feet', 'h2o_quality']));
diff --git a/test/unit/influx.test.ts b/test/unit/influx.test.ts
index 5494e4b..01319f3 100644
--- a/test/unit/influx.test.ts
+++ b/test/unit/influx.test.ts
@@ -228,6 +228,11 @@ describe('influxdb', () => {
 			influx.dropDatabase('f"oo');
 		});
 
+		it('.dropShard()', () => {
+			expectQuery('json', 'drop shard 1');
+			influx.dropShard(1);
+		});
+
 		it('.getDatabaseNames()', () => {
 			expectQuery('json', 'show databases', 'GET', dbFixture('showDatabases'));
 			return influx.getDatabaseNames().then(names => {