Skip to content

Commit 00dd0d3

Browse files
author
Paul Korzhyk
committed
2 parents 1c3546f + 25a1cb9 commit 00dd0d3

9 files changed

+46
-5276
lines changed

lib/client.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DgraphClientStub } from "./clientStub";
22
import { Txn } from "./txn";
3-
import { Operation, Payload, UiKeywords, TxnOptions, Response } from "./types";
3+
import { Operation, Payload, Response, TxnOptions, UiKeywords } from "./types";
44
export declare class DgraphClient {
55
private readonly clients;
66
private debugMode;

lib/client.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,14 @@ var DgraphClient = (function () {
9696
if (all === void 0) { all = true; }
9797
return __awaiter(this, void 0, void 0, function () {
9898
return __generator(this, function (_a) {
99-
switch (_a.label) {
100-
case 0: return [4, this.anyClient().getHealth(all)];
101-
case 1: return [2, _a.sent()];
102-
}
99+
return [2, this.anyClient().getHealth(all)];
103100
});
104101
});
105102
};
106103
DgraphClient.prototype.getState = function () {
107104
return __awaiter(this, void 0, void 0, function () {
108105
return __generator(this, function (_a) {
109-
switch (_a.label) {
110-
case 0: return [4, this.anyClient().getState()];
111-
case 1: return [2, _a.sent()];
112-
}
106+
return [2, this.anyClient().getState()];
113107
});
114108
});
115109
};

lib/clientStub.d.ts

-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ export declare class DgraphClientStub {
1414
mutate(mu: Mutation): Promise<Assigned>;
1515
commit(ctx: TxnContext): Promise<TxnContext>;
1616
abort(ctx: TxnContext): Promise<TxnContext>;
17-
health(): Promise<{
18-
health: string;
19-
version: string;
20-
instance?: string;
21-
uptime?: number;
22-
}>;
2317
login(userid?: string, password?: string, refreshToken?: string): Promise<boolean>;
2418
logout(): void;
2519
getAuthTokens(): {

lib/clientStub.js

+8-58
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
"use strict";
2-
var __assign = (this && this.__assign) || function () {
3-
__assign = Object.assign || function(t) {
4-
for (var s, i = 1, n = arguments.length; i < n; i++) {
5-
s = arguments[i];
6-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7-
t[p] = s[p];
8-
}
9-
return t;
10-
};
11-
return __assign.apply(this, arguments);
12-
};
132
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
143
return new (P || (P = Promise))(function (resolve, reject) {
154
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -62,14 +51,15 @@ var DgraphClientStub = (function () {
6251
}
6352
DgraphClientStub.prototype.detectApiVersion = function () {
6453
return __awaiter(this, void 0, void 0, function () {
65-
var health;
54+
var health, version;
6655
return __generator(this, function (_a) {
6756
switch (_a.label) {
68-
case 0: return [4, this.health()];
57+
case 0: return [4, this.getHealth()];
6958
case 1:
7059
health = _a.sent();
71-
this.legacyApi = health.version.startsWith("1.0.");
72-
return [2, health.version];
60+
version = health["version"] || health[0].version;
61+
this.legacyApi = version.startsWith("1.0.");
62+
return [2, version];
7363
}
7464
});
7565
});
@@ -248,33 +238,6 @@ var DgraphClientStub = (function () {
248238
: "/abort/" + ctx.start_ts;
249239
return this.callAPI(url, { method: "POST" });
250240
};
251-
DgraphClientStub.prototype.health = function () {
252-
return __awaiter(this, void 0, void 0, function () {
253-
var response, text;
254-
return __generator(this, function (_a) {
255-
switch (_a.label) {
256-
case 0: return [4, fetch(this.getURL("health"), {
257-
method: "GET",
258-
})];
259-
case 1:
260-
response = _a.sent();
261-
if (response.status >= 300 || response.status < 200) {
262-
throw new Error("Invalid status code = " + response.status);
263-
}
264-
return [4, response.text()];
265-
case 2:
266-
text = _a.sent();
267-
if (text === "OK") {
268-
return [2, {
269-
health: text,
270-
version: "1.0.x",
271-
}];
272-
}
273-
return [2, __assign({}, JSON.parse(text), { health: "OK" })];
274-
}
275-
});
276-
});
277-
};
278241
DgraphClientStub.prototype.login = function (userid, password, refreshToken) {
279242
return __awaiter(this, void 0, void 0, function () {
280243
var body, res;
@@ -329,28 +292,15 @@ var DgraphClientStub = (function () {
329292
DgraphClientStub.prototype.getHealth = function (all) {
330293
if (all === void 0) { all = false; }
331294
return __awaiter(this, void 0, void 0, function () {
332-
var url;
333295
return __generator(this, function (_a) {
334-
switch (_a.label) {
335-
case 0:
336-
url = "health" + (all ? "?all" : "");
337-
return [4, this.callAPI(url, {
338-
method: "GET",
339-
})];
340-
case 1: return [2, _a.sent()];
341-
}
296+
return [2, this.callAPI("health" + (all ? "?all" : ""), {})];
342297
});
343298
});
344299
};
345300
DgraphClientStub.prototype.getState = function () {
346301
return __awaiter(this, void 0, void 0, function () {
347302
return __generator(this, function (_a) {
348-
switch (_a.label) {
349-
case 0: return [4, this.callAPI("state", {
350-
method: "GET",
351-
})];
352-
case 1: return [2, _a.sent()];
353-
}
303+
return [2, this.callAPI("state", {})];
354304
});
355305
});
356306
};
@@ -375,7 +325,7 @@ var DgraphClientStub = (function () {
375325
this.cancelRefreshTimer();
376326
var timeToWait = Math.max(2000, jwt.decode(accessToken).exp * 1000 - Date.now()
377327
- AUTO_REFRESH_PREFETCH_TIME);
378-
this.autoRefreshTimer = setTimeout(function () { return _this.refreshToken && _this.login(); }, timeToWait);
328+
this.autoRefreshTimer = setTimeout(function () { return _this.refreshToken !== undefined ? _this.login() : 0; }, timeToWait);
379329
};
380330
DgraphClientStub.prototype.callAPI = function (path, config) {
381331
return __awaiter(this, void 0, void 0, function () {

lib/txn.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@ var errors_1 = require("./errors");
3939
var util_1 = require("./util");
4040
var Txn = (function () {
4141
function Txn(dc, options) {
42+
if (options === void 0) { options = {}; }
4243
this.finished = false;
4344
this.mutated = false;
4445
this.dc = dc;
45-
if (options && options.bestEffort && !options.readOnly) {
46-
this.dc.debug('Client attempted to query using best-effort without setting the transaction to read-only');
46+
if (options.bestEffort && !options.readOnly) {
47+
this.dc.debug("Client attempted to query using best-effort without setting the transaction to read-only");
4748
throw errors_1.ERR_BEST_EFFORT_REQUIRED_READ_ONLY;
4849
}
4950
this.ctx = {
5051
start_ts: 0,
5152
keys: [],
5253
preds: [],
53-
readOnly: options && options.readOnly,
54-
bestEffort: options && options.bestEffort,
54+
readOnly: options.readOnly,
55+
bestEffort: options.bestEffort,
5556
};
5657
}
5758
Txn.prototype.query = function (q, options) {
@@ -74,7 +75,7 @@ var Txn = (function () {
7475
timeout: this.dc.getQueryTimeout(),
7576
debug: options.debug,
7677
readOnly: this.ctx.readOnly,
77-
bestEffort: this.ctx.bestEffort
78+
bestEffort: this.ctx.bestEffort,
7879
};
7980
if (vars !== undefined) {
8081
varsObj_1 = {};

0 commit comments

Comments
 (0)