Skip to content

Commit 8f485a6

Browse files
author
Paul Korzhyk
committed
What if we remove all nulls?
1 parent e836dcd commit 8f485a6

File tree

4 files changed

+46
-36
lines changed

4 files changed

+46
-36
lines changed

lib/clientStub.d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { Assigned, Mutation, Operation, Options, Payload, Request, Response, Txn
22
export declare class DgraphClientStub {
33
private readonly addr;
44
private readonly options;
5+
private readonly jsonParser;
56
private legacyApi;
67
private accessToken;
78
private refreshToken;
89
private autoRefresh;
910
private autoRefreshTimer?;
10-
constructor(addr?: string, legacyApi?: boolean, options?: Options);
11+
constructor(addr?: string, stubConfig?: {
12+
legacyApi?: boolean;
13+
jsonParser?(text: string): any;
14+
}, options?: Options);
1115
detectApiVersion(): Promise<string>;
1216
alter(op: Operation): Promise<Payload>;
1317
query(req: Request): Promise<Response>;

lib/clientStub.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ var jwt = require("jsonwebtoken");
5252
var errors_1 = require("./errors");
5353
var AUTO_REFRESH_PREFETCH_TIME = 5000;
5454
var DgraphClientStub = (function () {
55-
function DgraphClientStub(addr, legacyApi, options) {
55+
function DgraphClientStub(addr, stubConfig, options) {
56+
if (stubConfig === void 0) { stubConfig = {}; }
5657
if (addr === undefined) {
5758
this.addr = "http://localhost:8080";
5859
}
@@ -65,7 +66,12 @@ var DgraphClientStub = (function () {
6566
else {
6667
this.options = options;
6768
}
68-
this.legacyApi = !!legacyApi;
69+
this.legacyApi = !!stubConfig.legacyApi;
70+
this.jsonParser =
71+
stubConfig.jsonParser !== undefined
72+
? stubConfig.jsonParser
73+
:
74+
JSON.parse.bind(JSON);
6975
}
7076
DgraphClientStub.prototype.detectApiVersion = function () {
7177
return __awaiter(this, void 0, void 0, function () {
@@ -368,7 +374,7 @@ var DgraphClientStub = (function () {
368374
case 2:
369375
responseText = _a.sent();
370376
try {
371-
json = JSON.parse(responseText);
377+
json = this.jsonParser(responseText);
372378
}
373379
catch (e) {
374380
if (config.acceptRawText) {

lib/types.d.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/// <reference types="node" />
22
import * as https from "https";
33
export interface Operation {
4-
schema?: string | null;
5-
dropAttr?: string | null;
6-
dropAll?: boolean | null;
4+
schema?: string;
5+
dropAttr?: string;
6+
dropAll?: boolean;
77
}
88
export interface Payload {
99
data: {};
@@ -12,7 +12,7 @@ export interface Request {
1212
query: string;
1313
vars?: {
1414
[k: string]: string;
15-
} | null;
15+
};
1616
startTs?: number;
1717
timeout?: number;
1818
debug?: boolean;
@@ -36,13 +36,13 @@ export interface LoginResponse {
3636
};
3737
}
3838
export interface Mutation {
39-
setJson?: object | null;
40-
deleteJson?: object | null;
41-
setNquads?: string | null;
42-
deleteNquads?: string | null;
39+
setJson?: object;
40+
deleteJson?: object;
41+
setNquads?: string;
42+
deleteNquads?: string;
4343
startTs?: number;
44-
commitNow?: boolean | null;
45-
mutation?: string | null;
44+
commitNow?: boolean;
45+
mutation?: string;
4646
isJsonString?: boolean;
4747
}
4848
export interface Assigned {
@@ -60,16 +60,16 @@ export interface Extensions {
6060
}
6161
export interface TxnContext {
6262
start_ts: number;
63-
aborted?: boolean | null;
64-
keys?: string[] | null;
65-
preds?: string[] | null;
63+
aborted?: boolean;
64+
keys?: string[];
65+
preds?: string[];
6666
readOnly: boolean;
6767
bestEffort: boolean;
6868
}
6969
export interface Latency {
70-
parsing_ns?: number | null;
71-
processing_ns?: number | null;
72-
encoding_ns?: number | null;
70+
parsing_ns?: number;
71+
processing_ns?: number;
72+
encoding_ns?: number;
7373
}
7474
export interface TxnOptions {
7575
readOnly?: boolean;

src/types.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as https from "https";
22

33
export interface Operation {
4-
schema?: string | null;
5-
dropAttr?: string | null;
6-
dropAll?: boolean | null;
4+
schema?: string;
5+
dropAttr?: string;
6+
dropAll?: boolean;
77
}
88

99
export interface Payload {
@@ -12,7 +12,7 @@ export interface Payload {
1212

1313
export interface Request {
1414
query: string;
15-
vars?: { [k: string]: string } | null;
15+
vars?: { [k: string]: string };
1616
startTs?: number;
1717
timeout?: number;
1818
debug?: boolean;
@@ -38,14 +38,14 @@ export interface LoginResponse {
3838
}
3939

4040
export interface Mutation {
41-
setJson?: object | null;
42-
deleteJson?: object | null;
43-
setNquads?: string | null;
44-
deleteNquads?: string | null;
41+
setJson?: object;
42+
deleteJson?: object;
43+
setNquads?: string;
44+
deleteNquads?: string;
4545
startTs?: number;
46-
commitNow?: boolean | null;
46+
commitNow?: boolean;
4747
// Raw mutation text to send;
48-
mutation?: string | null;
48+
mutation?: string;
4949
// Set to true if `mutation` field (above) contains a JSON mutation.
5050
isJsonString?: boolean;
5151
}
@@ -66,17 +66,17 @@ export interface Extensions {
6666

6767
export interface TxnContext {
6868
start_ts: number;
69-
aborted?: boolean | null;
70-
keys?: string[] | null;
71-
preds?: string[] | null;
69+
aborted?: boolean;
70+
keys?: string[];
71+
preds?: string[];
7272
readOnly: boolean;
7373
bestEffort: boolean;
7474
}
7575

7676
export interface Latency {
77-
parsing_ns?: number | null;
78-
processing_ns?: number | null;
79-
encoding_ns?: number | null;
77+
parsing_ns?: number;
78+
processing_ns?: number;
79+
encoding_ns?: number;
8080
}
8181

8282
export interface TxnOptions {

0 commit comments

Comments
 (0)